Sun, 11 May 2014 10:41:29 +0200
some fixes
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2014 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
34
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
31 | #include <unistd.h> |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
32 | #include <pthread.h> |
0 | 33 | |
34 | #include "toolkit.h" | |
3 | 35 | #include "toolbar.h" |
36 | #include "stock.h" | |
1
eb5269000bc8
added some document functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
0
diff
changeset
|
37 | #include "../common/document.h" |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
38 | #include "../common/properties.h" |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
39 | #include "../../ucx/buffer.h" |
0 | 40 | |
41 | static XtAppContext app; | |
42 | static Display *display; | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
43 | static Widget active_window; |
0 | 44 | static char *application_name; |
45 | ||
46 | static ui_callback appclose_fnc; | |
47 | static void *appclose_udata; | |
48 | ||
49 | static int is_toplevel_realized = 0; | |
50 | ||
34
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
51 | int event_pipe[2]; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
52 | |
0 | 53 | static String fallback[] = { |
54 | "*fontList: -dt-interface system-medium-r-normal-s*utf*:", | |
55 | NULL | |
56 | }; | |
57 | ||
34
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
58 | void input_proc(XtPointer data, int *source, XtInputId *iid) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
59 | void *ptr; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
60 | read(event_pipe[0], &ptr, sizeof(void*)); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
61 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
62 | |
0 | 63 | void ui_init(char *appname, int argc, char **argv) { |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
64 | application_name = appname; |
0 | 65 | |
66 | XtToolkitInitialize(); | |
67 | XtSetLanguageProc(NULL, NULL, NULL); | |
68 | app = XtCreateApplicationContext(); | |
69 | ||
70 | display = XtOpenDisplay(app, NULL, appname, appname, NULL, 0, &argc, argv); | |
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
71 | char **missing = NULL; |
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
72 | int nm = 0; |
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
73 | char *def = NULL; |
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
74 | XCreateFontSet(display, "-dt-interface system-medium-r-normal-s*utf*", &missing, &nm, &def); |
0 | 75 | |
76 | uic_docmgr_init(); | |
3 | 77 | ui_toolbar_init(); |
78 | ui_stock_init(); | |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
79 | |
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
80 | uic_load_app_properties(); |
34
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
81 | |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
82 | if(pipe(event_pipe)) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
83 | fprintf(stderr, "UiError: Cannot create event pipe\n"); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
84 | exit(-1); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
85 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
86 | XtAppAddInput(app, event_pipe[0], XtInputReadMask, input_proc, NULL); |
0 | 87 | } |
88 | ||
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
89 | char* ui_appname() { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
90 | return application_name; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
91 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
92 | |
0 | 93 | Display* ui_get_display() { |
94 | return display; | |
95 | } | |
96 | ||
97 | void ui_exitfunc(ui_callback f, void *udata) { | |
98 | appclose_fnc = f; | |
99 | appclose_udata = udata; | |
100 | } | |
101 | ||
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
102 | void ui_openfilefunc(ui_callback f, void *userdata) { |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
103 | // OS X only |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
104 | } |
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
105 | |
0 | 106 | void ui_main() { |
107 | XtAppMainLoop(app); | |
108 | if(appclose_fnc) { | |
109 | appclose_fnc(NULL, appclose_udata); | |
110 | } | |
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
111 | uic_store_app_properties(); |
0 | 112 | } |
113 | ||
28
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
114 | void ui_secondary_event_loop(int *loop) { |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
115 | while(*loop && !XtAppGetExitFlag(app)) { |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
116 | XEvent event; |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
117 | XtAppNextEvent(app, &event); |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
118 | XtDispatchEvent(&event); |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
119 | } |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
120 | } |
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
121 | |
0 | 122 | void ui_show(UiObject *obj) { |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
123 | uic_check_group_widgets(obj->ctx); |
0 | 124 | XtRealizeWidget(obj->widget); |
125 | } | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
126 | |
34
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
127 | void ui_close(UiObject *obj) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
128 | // TODO |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
129 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
130 | |
21
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
131 | void ui_set_enabled(UIWIDGET widget, int enabled) { |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
132 | XtSetSensitive(widget, enabled); |
012418e7dc90
added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
3
diff
changeset
|
133 | } |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
134 | |
34
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
135 | void ui_set_show_all(UIWIDGET widget, int value) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
136 | if(!value) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
137 | XtUnmanageChild(widget); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
138 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
139 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
140 | |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
141 | void ui_set_visible(UIWIDGET widget, int visible) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
142 | if(visible) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
143 | XtManageChild(widget); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
144 | } else { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
145 | XtUnmanageChild(widget); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
146 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
147 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
148 | |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
149 | static Boolean ui_job_finished(void *data) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
150 | printf("WorkProc\n"); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
151 | UiJob *job = data; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
152 | |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
153 | UiEvent event; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
154 | event.obj = job->obj; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
155 | event.window = job->obj->window; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
156 | event.document = job->obj->document; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
157 | event.intval = 0; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
158 | event.eventdata = NULL; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
159 | |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
160 | job->finish_callback(&event, job->finish_data); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
161 | free(job); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
162 | return TRUE; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
163 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
164 | |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
165 | static void* ui_jobthread(void *data) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
166 | UiJob *job = data; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
167 | int result = job->job_func(job->job_data); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
168 | if(!result) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
169 | printf("XtAppAddWorkProc\n"); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
170 | write(event_pipe[1], &job, sizeof(void*)); // hack |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
171 | XtAppAddWorkProc(app, ui_job_finished, job); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
172 | |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
173 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
174 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
175 | |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
176 | void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) { |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
177 | UiJob *job = malloc(sizeof(UiJob)); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
178 | job->obj = obj; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
179 | job->job_func = tf; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
180 | job->job_data = td; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
181 | job->finish_callback = f; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
182 | job->finish_data = fd; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
183 | pthread_t pid; |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
184 | pthread_create(&pid, NULL, ui_jobthread, job); |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
185 | } |
0ec8a5f17782
added listview and sidebar (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
186 | |
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
187 | void ui_clipboard_set(char *str) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
188 | printf("copy: {%s}\n", str); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
189 | int length = strlen(str) + 1; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
190 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
191 | Display *dp = XtDisplayOfObject(active_window); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
192 | Window window = XtWindowOfObject(active_window); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
193 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
194 | XmString label = XmStringCreateLocalized("toolkit_clipboard"); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
195 | long id = 0; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
196 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
197 | while(XmClipboardStartCopy( |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
198 | dp, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
199 | window, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
200 | label, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
201 | CurrentTime, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
202 | NULL, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
203 | NULL, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
204 | &id) == ClipboardLocked); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
205 | XmStringFree(label); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
206 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
207 | while(XmClipboardCopy( |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
208 | dp, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
209 | window, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
210 | id, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
211 | "STRING", |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
212 | str, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
213 | length, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
214 | 1, |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
215 | NULL) == ClipboardLocked); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
216 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
217 | while(XmClipboardEndCopy(dp, window, id) == ClipboardLocked); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
218 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
219 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
220 | char* ui_clipboard_get() { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
221 | Display *dp = XtDisplayOfObject(active_window); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
222 | Window window = XtWindowOfObject(active_window); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
223 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
224 | long id; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
225 | size_t size = 128; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
226 | char *buf = malloc(size); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
227 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
228 | int r; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
229 | for(;;) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
230 | r = XmClipboardRetrieve(dp, window, "STRING", buf, size, NULL, &id); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
231 | if(r == ClipboardSuccess) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
232 | break; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
233 | } else if(r == ClipboardTruncate) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
234 | size *= 2; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
235 | buf = realloc(buf, size); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
236 | } else if(r == ClipboardNoData) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
237 | free(buf); |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
238 | buf = NULL; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
239 | break; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
240 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
241 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
242 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
243 | return buf; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
244 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
245 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
246 | void ui_set_active_window(Widget w) { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
247 | active_window = w; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
248 | } |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
249 | |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
250 | Widget ui_get_active_window() { |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
251 | return active_window; |
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
252 | } |