ui/motif/toolkit.c

changeset 34
0ec8a5f17782
parent 30
34513f76d5a8
child 36
e4198fc2ead4
equal deleted inserted replaced
33:458831c574f4 34:0ec8a5f17782
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <pthread.h>
31 33
32 #include "toolkit.h" 34 #include "toolkit.h"
33 #include "toolbar.h" 35 #include "toolbar.h"
34 #include "stock.h" 36 #include "stock.h"
35 #include "../common/document.h" 37 #include "../common/document.h"
44 static ui_callback appclose_fnc; 46 static ui_callback appclose_fnc;
45 static void *appclose_udata; 47 static void *appclose_udata;
46 48
47 static int is_toplevel_realized = 0; 49 static int is_toplevel_realized = 0;
48 50
51 int event_pipe[2];
52
49 static String fallback[] = { 53 static String fallback[] = {
50 "*fontList: -dt-interface system-medium-r-normal-s*utf*:", 54 "*fontList: -dt-interface system-medium-r-normal-s*utf*:",
51 NULL 55 NULL
52 }; 56 };
57
58 void input_proc(XtPointer data, int *source, XtInputId *iid) {
59 void *ptr;
60 read(event_pipe[0], &ptr, sizeof(void*));
61 }
53 62
54 void ui_init(char *appname, int argc, char **argv) { 63 void ui_init(char *appname, int argc, char **argv) {
55 application_name = appname; 64 application_name = appname;
56 65
57 XtToolkitInitialize(); 66 XtToolkitInitialize();
67 uic_docmgr_init(); 76 uic_docmgr_init();
68 ui_toolbar_init(); 77 ui_toolbar_init();
69 ui_stock_init(); 78 ui_stock_init();
70 79
71 uic_load_app_properties(); 80 uic_load_app_properties();
81
82 if(pipe(event_pipe)) {
83 fprintf(stderr, "UiError: Cannot create event pipe\n");
84 exit(-1);
85 }
86 XtAppAddInput(app, event_pipe[0], XtInputReadMask, input_proc, NULL);
72 } 87 }
73 88
74 char* ui_appname() { 89 char* ui_appname() {
75 return application_name; 90 return application_name;
76 } 91 }
107 void ui_show(UiObject *obj) { 122 void ui_show(UiObject *obj) {
108 uic_check_group_widgets(obj->ctx); 123 uic_check_group_widgets(obj->ctx);
109 XtRealizeWidget(obj->widget); 124 XtRealizeWidget(obj->widget);
110 } 125 }
111 126
127 void ui_close(UiObject *obj) {
128 // TODO
129 }
130
112 void ui_set_enabled(UIWIDGET widget, int enabled) { 131 void ui_set_enabled(UIWIDGET widget, int enabled) {
113 XtSetSensitive(widget, enabled); 132 XtSetSensitive(widget, enabled);
133 }
134
135 void ui_set_show_all(UIWIDGET widget, int value) {
136 if(!value) {
137 XtUnmanageChild(widget);
138 }
139 }
140
141 void ui_set_visible(UIWIDGET widget, int visible) {
142 if(visible) {
143 XtManageChild(widget);
144 } else {
145 XtUnmanageChild(widget);
146 }
147 }
148
149 static Boolean ui_job_finished(void *data) {
150 printf("WorkProc\n");
151 UiJob *job = data;
152
153 UiEvent event;
154 event.obj = job->obj;
155 event.window = job->obj->window;
156 event.document = job->obj->document;
157 event.intval = 0;
158 event.eventdata = NULL;
159
160 job->finish_callback(&event, job->finish_data);
161 free(job);
162 return TRUE;
163 }
164
165 static void* ui_jobthread(void *data) {
166 UiJob *job = data;
167 int result = job->job_func(job->job_data);
168 if(!result) {
169 printf("XtAppAddWorkProc\n");
170 write(event_pipe[1], &job, sizeof(void*)); // hack
171 XtAppAddWorkProc(app, ui_job_finished, job);
172
173 }
174 }
175
176 void ui_job(UiObject *obj, ui_threadfunc tf, void *td, ui_callback f, void *fd) {
177 UiJob *job = malloc(sizeof(UiJob));
178 job->obj = obj;
179 job->job_func = tf;
180 job->job_data = td;
181 job->finish_callback = f;
182 job->finish_data = fd;
183 pthread_t pid;
184 pthread_create(&pid, NULL, ui_jobthread, job);
114 } 185 }
115 186
116 void ui_clipboard_set(char *str) { 187 void ui_clipboard_set(char *str) {
117 printf("copy: {%s}\n", str); 188 printf("copy: {%s}\n", str);
118 int length = strlen(str) + 1; 189 int length = strlen(str) + 1;

mercurial