Mercurial > dwindows
annotate gtk/dw.c @ 34:b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
Also some fixes for containers on OS/2.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 03 Sep 2001 23:30:43 +0000 |
parents | 72675de7d229 |
children | cddb02f847e1 |
rev | line source |
---|---|
3 | 1 /* |
2 * Dynamic Windows: | |
3 * A GTK like implementation of the PM GUI | |
4 * GTK forwarder module for portabilty. | |
5 * | |
6 * (C) 2000,2001 Brian Smith <dbsoft@technologist.com> | |
7 * | |
8 */ | |
9 #include "dw.h" | |
10 #include <string.h> | |
11 #include <stdlib.h> | |
12 #include <sys/utsname.h> | |
13 #include <stdarg.h> | |
14 #include <stdio.h> | |
15 #include <unistd.h> | |
16 #include <errno.h> | |
17 #include <sys/time.h> | |
18 #include "config.h" | |
19 #ifdef USE_IMLIB | |
20 #include <gdk_imlib.h> | |
21 #endif | |
22 | |
23 /* These are used for resource management */ | |
24 #if defined(DW_RESOURCES) && !defined(BUILD_DLL) | |
25 extern DWResources _resources; | |
26 #endif | |
27 | |
28 char monthlist[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", | |
29 "Sep", "Oct", "Nov", "Dec" }; | |
30 GdkColor _colors[] = | |
31 { | |
32 { 0, 0x0000, 0x0000, 0x0000 }, /* 0 black */ | |
33 { 0, 0xbbbb, 0x0000, 0x0000 }, /* 1 red */ | |
34 { 0, 0x0000, 0xbbbb, 0x0000 }, /* 2 green */ | |
35 { 0, 0xaaaa, 0xaaaa, 0x0000 }, /* 3 yellow */ | |
36 { 0, 0x0000, 0x0000, 0xcccc }, /* 4 blue */ | |
37 { 0, 0xbbbb, 0x0000, 0xbbbb }, /* 5 magenta */ | |
38 { 0, 0x0000, 0xbbbb, 0xbbbb }, /* 6 cyan */ | |
39 { 0, 0xaaaa, 0xaaaa, 0xaaaa }, /* 7 white */ | |
40 { 0, 0x7777, 0x7777, 0x7777 }, /* 8 grey */ | |
41 { 0, 0xffff, 0x0000, 0x0000 }, /* 9 bright red */ | |
42 { 0, 0x0000, 0xffff, 0x0000 }, /* 10 bright green */ | |
43 { 0, 0xeeee, 0xeeee, 0x0000 }, /* 11 bright yellow */ | |
44 { 0, 0x0000, 0x0000, 0xffff }, /* 12 bright blue */ | |
45 { 0, 0xffff, 0x0000, 0xffff }, /* 13 bright magenta */ | |
46 { 0, 0x0000, 0xeeee, 0xeeee }, /* 14 bright cyan */ | |
47 { 0, 0xffff, 0xffff, 0xffff }, /* 15 bright white */ | |
48 }; | |
49 | |
50 GdkColor _foreground = { 0, 0x0000, 0x0000, 0x0000 }; | |
51 GdkColor _background = { 0, 0xaaaa, 0xaaaa, 0xaaaa }; | |
52 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
53 int _dw_file_active = 0, _dw_ignore_click = 0; |
3 | 54 pthread_t _dw_thread = (pthread_t)-1; |
55 int _dw_mutex_locked = FALSE; | |
56 | |
57 #define DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && _dw_mutex_locked == FALSE) { gdk_threads_enter(); _dw_mutex_locked = TRUE; _locked_by_me = TRUE; } } | |
58 #define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); _dw_mutex_locked = FALSE; _locked_by_me = FALSE; } } | |
59 | |
60 /* Currently the non Imlib method does not work */ | |
61 #ifndef USE_IMLIB | |
62 #define USE_IMLIB | |
63 #endif | |
64 | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
65 #define DEFAULT_SIZE_WIDTH 12 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
66 #define DEFAULT_SIZE_HEIGHT 6 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
67 #define DEFAULT_TITLEBAR_HEIGHT 22 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
68 |
3 | 69 GdkColormap *_dw_cmap = NULL; |
70 | |
71 /* Signal forwarder prototypes */ | |
72 gint _button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data); | |
73 gint _button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer data); | |
74 gint _motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data); | |
75 gint _delete_event(GtkWidget *widget, GdkEvent *event, gpointer data); | |
76 gint _key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data); | |
77 gint _generic_event(GtkWidget *widget, gpointer data); | |
78 gint _configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data); | |
79 void _activate_event(GtkWidget *widget, gpointer data); | |
80 void _container_select_event(GtkWidget *widget, GdkEventButton *event, gpointer data); | |
81 void _container_context_event(GtkWidget *widget, GdkEventButton *event, gpointer data); | |
82 void _item_select_event(GtkWidget *widget, GtkWidget *child, gpointer data); | |
83 void _expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
84 void _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data); |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
85 void _tree_select_event(GtkTree *tree, GtkWidget *child, gpointer data); |
3 | 86 |
87 typedef struct | |
88 { | |
89 void *func; | |
90 char name[30]; | |
91 | |
92 } SignalList; | |
93 | |
94 typedef struct | |
95 { | |
96 HWND window; | |
97 void *func; | |
98 gpointer data; | |
99 | |
100 } SignalHandler; | |
101 | |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
102 #define SIGNALMAX 14 |
3 | 103 |
104 /* A list of signal forwarders, to account for paramater differences. */ | |
105 SignalList SignalTranslate[SIGNALMAX] = { | |
106 { _configure_event, "configure_event" }, | |
107 { _key_press_event, "key_press_event" }, | |
108 { _button_press_event, "button_press_event" }, | |
109 { _button_release_event, "button_release_event" }, | |
110 { _motion_notify_event, "motion_notify_event" }, | |
111 { _delete_event, "delete_event" }, | |
112 { _expose_event, "expose_event" }, | |
113 { _activate_event, "activate" }, | |
114 { _generic_event, "clicked" }, | |
115 { _container_select_event, "container-select" }, | |
116 { _container_context_event, "container-context" }, | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
117 { _item_select_event, "item-select" }, |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
118 { _tree_select_event, "tree-select" }, |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
119 { _set_focus_event, "set-focus" } |
3 | 120 }; |
121 | |
122 /* Finds the translation function for a given signal name */ | |
123 void *_findsigfunc(char *signame) | |
124 { | |
125 int z; | |
126 | |
127 for(z=0;z<SIGNALMAX;z++) | |
128 { | |
129 if(strcasecmp(signame, SignalTranslate[z].name) == 0) | |
130 return SignalTranslate[z].func; | |
131 } | |
132 return NULL; | |
133 } | |
134 | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
135 void _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
136 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
137 SignalHandler *work = (SignalHandler *)data; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
138 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
139 if(work) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
140 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
141 int (*setfocusfunc)(HWND, void *) = work->func; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
142 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
143 setfocusfunc((HWND)window, work->data); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
144 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
145 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
146 |
3 | 147 gint _button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) |
148 { | |
149 SignalHandler *work = (SignalHandler *)data; | |
150 | |
151 if(work) | |
152 { | |
153 int (*buttonfunc)(HWND, int, int, int, void *) = work->func; | |
154 int mybutton = event->button; | |
155 | |
156 if(event->button == 3) | |
157 mybutton = 2; | |
158 else if(event->button == 2) | |
159 mybutton = 3; | |
160 | |
161 buttonfunc(widget, event->x, event->y, mybutton, work->data); | |
162 } | |
163 return TRUE; | |
164 } | |
165 | |
166 gint _button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer data) | |
167 { | |
168 SignalHandler *work = (SignalHandler *)data; | |
169 | |
170 if(work) | |
171 { | |
172 int (*buttonfunc)(HWND, int, int, int, void *) = work->func; | |
173 int mybutton = event->button; | |
174 | |
175 if(event->button == 3) | |
176 mybutton = 2; | |
177 else if(event->button == 2) | |
178 mybutton = 3; | |
179 | |
180 buttonfunc(widget, event->x, event->y, mybutton, work->data); | |
181 } | |
182 return TRUE; | |
183 } | |
184 | |
185 gint _motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) | |
186 { | |
187 SignalHandler *work = (SignalHandler *)data; | |
188 | |
189 if(work) | |
190 { | |
191 int (*motionfunc)(HWND, int, int, int, void *) = work->func; | |
192 int keys = 0, x, y; | |
193 GdkModifierType state; | |
194 | |
195 if (event->is_hint) | |
196 gdk_window_get_pointer (event->window, &x, &y, &state); | |
197 else | |
198 { | |
199 x = event->x; | |
200 y = event->y; | |
201 state = event->state; | |
202 } | |
203 | |
204 if (state & GDK_BUTTON1_MASK) | |
205 keys = DW_BUTTON1_MASK; | |
206 if (state & GDK_BUTTON3_MASK) | |
207 keys |= DW_BUTTON2_MASK; | |
208 if (state & GDK_BUTTON2_MASK) | |
209 keys |= DW_BUTTON3_MASK; | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
210 |
3 | 211 motionfunc(widget, x, y, keys, work->data); |
212 } | |
213 return TRUE; | |
214 } | |
215 | |
216 gint _delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) | |
217 { | |
218 SignalHandler *work = (SignalHandler *)data; | |
219 | |
220 if(work) | |
221 { | |
222 int (*closefunc)(HWND, void *) = work->func; | |
223 | |
224 closefunc(widget, data); | |
225 } | |
226 return TRUE; | |
227 } | |
228 | |
229 gint _key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
230 { | |
231 SignalHandler *work = (SignalHandler *)data; | |
232 | |
233 if(work) | |
234 { | |
235 int (*keypressfunc)(HWND, int, void *) = work->func; | |
236 | |
237 keypressfunc(widget, *event->string, work->data); | |
238 } | |
239 return TRUE; | |
240 } | |
241 | |
242 gint _generic_event(GtkWidget *widget, gpointer data) | |
243 { | |
244 SignalHandler *work = (SignalHandler *)data; | |
245 | |
246 if(work) | |
247 { | |
248 int (*genericfunc)(HWND, void *) = work->func; | |
249 | |
250 genericfunc(widget, work->data); | |
251 } | |
252 return TRUE; | |
253 } | |
254 | |
255 void _activate_event(GtkWidget *widget, gpointer data) | |
256 { | |
257 SignalHandler *work = (SignalHandler *)data; | |
258 | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
259 if(work && !_dw_ignore_click) |
3 | 260 { |
261 void (*activatefunc)(HWND, void *) = work->func; | |
262 | |
263 activatefunc(work->window, work->data); | |
264 } | |
265 return; | |
266 } | |
267 | |
268 gint _configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data) | |
269 { | |
270 SignalHandler *work = (SignalHandler *)data; | |
271 | |
272 if(work) | |
273 { | |
274 int (*sizefunc)(HWND, int, int, void *) = work->func; | |
275 | |
276 sizefunc(widget, event->width, event->height, work->data); | |
277 } | |
278 return TRUE; | |
279 } | |
280 | |
281 void _expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) | |
282 { | |
283 SignalHandler *work = (SignalHandler *)data; | |
284 | |
285 if(work) | |
286 { | |
287 DWExpose exp; | |
288 int (*exposefunc)(HWND, DWExpose *, void *) = work->func; | |
289 | |
290 exp.x = event->area.x; | |
291 exp.y = event->area.y; | |
292 exp.width = event->area.width; | |
293 exp.height = event->area.height; | |
294 exposefunc(widget, &exp, work->data); | |
295 } | |
296 } | |
297 | |
298 void _item_select_event(GtkWidget *widget, GtkWidget *child, gpointer data) | |
299 { | |
300 SignalHandler *work = (SignalHandler *)data; | |
301 | |
302 if(work) | |
303 { | |
304 int (*selectfunc)(HWND, int, void *) = work->func; | |
305 GList *list; | |
306 int item = 0; | |
307 | |
308 if(GTK_IS_COMBO(work->window)) | |
309 list = GTK_LIST(GTK_COMBO(work->window)->list)->children; | |
310 else if(GTK_IS_LIST(widget)) | |
311 list = GTK_LIST(widget)->children; | |
312 else | |
313 return; | |
314 | |
315 while(list) | |
316 { | |
317 if(list->data == (gpointer)child) | |
318 { | |
319 gtk_object_set_data(GTK_OBJECT(work->window), "item", (gpointer)item); | |
320 selectfunc(work->window, item, work->data); | |
321 break; | |
322 } | |
323 item++; | |
324 list = list->next; | |
325 } | |
326 } | |
327 } | |
328 | |
329 void _container_context_event(GtkWidget *widget, GdkEventButton *event, gpointer data) | |
330 { | |
331 SignalHandler *work = (SignalHandler *)data; | |
332 | |
333 if(work) | |
334 { | |
335 if(event->button == 3) | |
336 { | |
337 void (*contextfunc)(HWND, char *, int, int, void *) = work->func; | |
338 char *text; | |
339 int row, col; | |
340 | |
341 gtk_clist_get_selection_info(GTK_CLIST(widget), event->x, event->y, &row, &col); | |
342 | |
343 text = (char *)gtk_clist_get_row_data(GTK_CLIST(widget), row); | |
344 contextfunc(work->window, text, event->x, event->y, work->data); | |
345 } | |
346 } | |
347 } | |
348 | |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
349 void _tree_select_event(GtkTree *tree, GtkWidget *child, gpointer data) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
350 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
351 SignalHandler *work = (SignalHandler *)data; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
352 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
353 if(work) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
354 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
355 void (*treeselectfunc)(HWND, HWND, char *, void *) = work->func; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
356 char *text = (char *)gtk_object_get_data(GTK_OBJECT(child), "text"); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
357 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
358 treeselectfunc(work->window, child, text, work->data); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
359 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
360 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
361 |
3 | 362 void _container_select_event(GtkWidget *widget, GdkEventButton *event, gpointer data) |
363 { | |
364 SignalHandler *work = (SignalHandler *)data; | |
365 | |
366 if(work) | |
367 { | |
368 if(event->button == 1 && event->type == GDK_2BUTTON_PRESS) | |
369 { | |
370 void (*contextfunc)(HWND, char *, void *) = work->func; | |
371 char *text; | |
372 int row, col; | |
373 | |
374 gtk_clist_get_selection_info(GTK_CLIST(widget), event->x, event->y, &row, &col); | |
375 | |
376 text = (char *)gtk_clist_get_row_data(GTK_CLIST(widget), row); | |
377 contextfunc(work->window, text, work->data); | |
378 } | |
379 } | |
380 } | |
381 | |
382 void _select_row(GtkWidget *widget, gint row, gint column, GdkEventButton *event, gpointer data) | |
383 { | |
384 GList *tmp = (GList *)gtk_object_get_data(GTK_OBJECT(widget), "selectlist"); | |
385 char *rowdata = gtk_clist_get_row_data(GTK_CLIST(widget), row); | |
386 | |
387 if(rowdata) | |
388 { | |
389 tmp = g_list_append(tmp, rowdata); | |
390 gtk_object_set_data(GTK_OBJECT(widget), "selectlist", tmp); | |
391 } | |
392 | |
393 } | |
394 | |
395 void _unselect_row(GtkWidget *widget, gint row, gint column, GdkEventButton *event, gpointer data) | |
396 { | |
397 GList *tmp = (GList *)gtk_object_get_data(GTK_OBJECT(widget), "selectlist"); | |
398 char *rowdata = gtk_clist_get_row_data(GTK_CLIST(widget), row); | |
399 | |
400 if(rowdata) | |
401 { | |
402 g_list_remove(tmp, rowdata); | |
403 gtk_object_set_data(GTK_OBJECT(widget), "selectlist", tmp); | |
404 } | |
405 } | |
406 | |
407 GdkPixmap *_find_pixmap(GdkBitmap **bitmap, long id, HWND handle) | |
408 { | |
409 char *data = NULL; | |
410 int z; | |
411 | |
412 for(z=0;z<_resources.resource_max;z++) | |
413 { | |
414 if(_resources.resource_id[z] == id) | |
415 { | |
416 data = _resources.resource_data[z]; | |
417 break; | |
418 } | |
419 } | |
420 | |
421 if(data) | |
422 { | |
423 GdkPixmap *icon_pixmap = NULL; | |
424 #ifndef USE_IMLIB | |
425 GtkStyle *iconstyle; | |
426 | |
427 /* hmmm why do we need the handle here? */ | |
428 iconstyle = gtk_widget_get_style(handle); | |
429 if (!icon_pixmap) | |
430 icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, bitmap, &iconstyle->bg[GTK_STATE_NORMAL], &data); | |
431 #else | |
432 gdk_imlib_data_to_pixmap((char **)data, &icon_pixmap, bitmap); | |
433 #endif | |
434 return icon_pixmap; | |
435 } | |
436 return NULL; | |
437 } | |
438 | |
439 void _size_allocate(GtkWindow *window) | |
440 { | |
441 XSizeHints sizehints; | |
442 | |
443 sizehints.base_width = 1; | |
444 sizehints.base_height = 1; | |
445 sizehints.width_inc = 1; | |
446 sizehints.height_inc = 1; | |
447 sizehints.min_width = 8; | |
448 sizehints.min_height = 8; | |
449 | |
450 sizehints.flags = (PBaseSize|PMinSize|PResizeInc); | |
451 | |
452 XSetWMNormalHints (GDK_DISPLAY(), | |
453 GDK_WINDOW_XWINDOW (GTK_WIDGET (window)->window), | |
454 &sizehints); | |
455 gdk_flush (); | |
456 } | |
457 | |
458 /* | |
459 * Initializes the Dynamic Windows engine. | |
460 * Parameters: | |
461 * newthread: True if this is the only thread. | |
462 * False if there is already a message loop running. | |
463 */ | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
464 int dw_int_init(DWResources *res, int newthread, int argc, char *argv[]) |
3 | 465 { |
466 int z; | |
467 | |
468 if(res) | |
469 { | |
470 _resources.resource_max = res->resource_max; | |
471 _resources.resource_id = res->resource_id; | |
472 _resources.resource_data = res->resource_data; | |
473 } | |
474 gtk_set_locale(); | |
475 g_thread_init(NULL); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
476 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
477 gtk_init(&argc, &argv); |
3 | 478 #ifdef USE_IMLIB |
479 gdk_imlib_init(); | |
480 #endif | |
481 /* Add colors to the system colormap */ | |
482 _dw_cmap = gdk_colormap_get_system(); | |
483 for(z=0;z<16;z++) | |
484 gdk_color_alloc(_dw_cmap, &_colors[z]); | |
485 return TRUE; | |
486 } | |
487 | |
488 /* | |
489 * Runs a message loop for Dynamic Windows. | |
490 * Parameters: | |
491 * currenthab: The handle to the current anchor block | |
492 * or NULL if this DW is handling the message loop. | |
493 * func: Function pointer to the message filter function. | |
494 */ | |
495 void dw_main(HAB currenthab, void *func) | |
496 { | |
497 _dw_thread = pthread_self(); | |
498 gdk_threads_enter(); | |
499 gtk_main(); | |
500 gdk_threads_leave(); | |
501 } | |
502 | |
503 /* | |
504 * Free's memory allocated by dynamic windows. | |
505 * Parameters: | |
506 * ptr: Pointer to dynamic windows allocated | |
507 * memory to be free()'d. | |
508 */ | |
509 void dw_free(void *ptr) | |
510 { | |
511 free(ptr); | |
512 } | |
513 | |
514 /* | |
515 * Allocates and initializes a dialog struct. | |
516 * Parameters: | |
517 * data: User defined data to be passed to functions. | |
518 */ | |
519 DWDialog *dw_dialog_new(void *data) | |
520 { | |
521 DWDialog *tmp = malloc(sizeof(DWDialog)); | |
522 | |
523 tmp->eve = dw_event_new(); | |
524 dw_event_reset(tmp->eve); | |
525 tmp->data = data; | |
526 tmp->done = FALSE; | |
527 tmp->result = NULL; | |
528 | |
529 return tmp; | |
530 } | |
531 | |
532 /* | |
533 * Accepts a dialog struct and returns the given data to the | |
534 * initial called of dw_dialog_wait(). | |
535 * Parameters: | |
536 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | |
537 * result: Data to be returned by dw_dialog_wait(). | |
538 */ | |
539 int dw_dialog_dismiss(DWDialog *dialog, void *result) | |
540 { | |
541 dialog->result = result; | |
542 if(pthread_self() == _dw_thread) | |
543 gtk_main_quit(); | |
544 else | |
545 dw_event_post(dialog->eve); | |
546 dialog->done = TRUE; | |
547 return 0; | |
548 } | |
549 | |
550 /* | |
551 * Accepts a dialog struct waits for dw_dialog_dismiss() to be | |
552 * called by a signal handler with the given dialog struct. | |
553 * Parameters: | |
554 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | |
555 */ | |
556 void *dw_dialog_wait(DWDialog *dialog) | |
557 { | |
558 void *tmp; | |
559 | |
560 if(pthread_self() == _dw_thread) | |
561 gtk_main(); | |
562 else | |
563 dw_event_wait(dialog->eve, -1); | |
564 | |
565 dw_event_close(&dialog->eve); | |
566 tmp = dialog->result; | |
567 free(dialog); | |
568 return tmp; | |
569 } | |
570 | |
571 void _delete(GtkWidget *widget, GtkWidget *event, gpointer param) | |
572 { | |
573 gtk_widget_destroy(GTK_WIDGET(param)); | |
574 } | |
575 | |
576 void _delete2(GtkWidget *widget, gpointer param) | |
577 { | |
578 gtk_widget_destroy(GTK_WIDGET(param)); | |
579 } | |
580 | |
581 | |
582 /* | |
583 * Displays a Message Box with given text and title.. | |
584 * Parameters: | |
585 * title: The title of the message box. | |
586 * format: printf style format string. | |
587 * ...: Additional variables for use in the format. | |
588 */ | |
589 int dw_messagebox(char *title, char *format, ...) | |
590 { | |
591 va_list args; | |
592 char outbuf[256]; | |
593 GtkWidget *dialog, | |
594 *button, | |
595 *label; | |
596 int _locked_by_me = FALSE; | |
597 | |
598 DW_MUTEX_LOCK; | |
599 va_start(args, format); | |
600 vsprintf(outbuf, format, args); | |
601 va_end(args); | |
602 | |
603 dialog = gtk_dialog_new(); | |
604 | |
605 gtk_window_set_title(GTK_WINDOW(dialog), title); | |
606 | |
607 button = gtk_button_new_with_label("Ok"); | |
608 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, TRUE, TRUE, 0); | |
609 gtk_widget_show(button); | |
610 | |
611 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(_delete2), (gpointer)dialog); | |
612 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event", GTK_SIGNAL_FUNC(_delete), (gpointer)dialog); | |
613 | |
614 label = gtk_label_new(outbuf); | |
615 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 20); | |
616 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0); | |
617 gtk_widget_show(label); | |
618 | |
619 gtk_widget_show(dialog); | |
620 | |
621 DW_MUTEX_UNLOCK; | |
622 | |
623 return strlen(outbuf); | |
624 } | |
625 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
626 void _dw_yes_func(HWND window, void *data) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
627 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
628 DWDialog *dwwait = (DWDialog *)data; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
629 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
630 if(!dwwait) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
631 return; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
632 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
633 dw_window_destroy((HWND)dwwait->data); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
634 dw_dialog_dismiss((DWDialog *)data, (void *)1); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
635 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
636 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
637 void _dw_no_func(HWND window, void *data) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
638 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
639 DWDialog *dwwait = (DWDialog *)data; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
640 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
641 if(!dwwait) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
642 return; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
643 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
644 dw_window_destroy((HWND)dwwait->data); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
645 dw_dialog_dismiss((DWDialog *)data, (void *)0); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
646 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
647 |
3 | 648 /* |
649 * Displays a Message Box with given text and title.. | |
650 * Parameters: | |
651 * title: The title of the message box. | |
652 * text: The text to display in the box. | |
653 * Returns: | |
654 * True if YES False of NO. | |
655 */ | |
656 int dw_yesno(char *title, char *text) | |
657 { | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
658 HWND entrywindow, mainbox, nobutton, yesbutton, buttonbox, stext; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
659 ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
660 DWDialog *dwwait; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
661 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
662 entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
663 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
664 mainbox = dw_box_new(BOXVERT, 10); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
665 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
666 dw_box_pack_start(entrywindow, mainbox, 0, 0, TRUE, TRUE, 0); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
667 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
668 /* Archive Name */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
669 stext = dw_text_new(text, 0); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
670 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
671 dw_box_pack_start(mainbox, stext, 130, 20, TRUE, TRUE, 2); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
672 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
673 /* Buttons */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
674 buttonbox = dw_box_new(BOXHORZ, 10); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
675 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
676 dw_box_pack_start(mainbox, buttonbox, 0, 0, TRUE, TRUE, 0); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
677 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
678 yesbutton = dw_button_new("Yes", 1001L); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
679 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
680 dw_box_pack_start(buttonbox, yesbutton, 130, 30, TRUE, TRUE, 2); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
681 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
682 nobutton = dw_button_new("No", 1002L); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
683 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
684 dw_box_pack_start(buttonbox, nobutton, 130, 30, TRUE, TRUE, 2); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
685 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
686 dwwait = dw_dialog_new((void *)entrywindow); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
687 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
688 dw_signal_connect(yesbutton, "clicked", DW_SIGNAL_FUNC(_dw_yes_func), (void *)dwwait); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
689 dw_signal_connect(nobutton, "clicked", DW_SIGNAL_FUNC(_dw_no_func), (void *)dwwait); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
690 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
691 dw_window_set_usize(entrywindow, 340, 150); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
692 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
693 dw_window_show(entrywindow); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
694 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
695 return (int)dw_dialog_wait(dwwait);; |
3 | 696 } |
697 | |
698 /* | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
699 * Minimizes or Iconifies a top-level window. |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
700 * Parameters: |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
701 * handle: The window handle to minimize. |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
702 */ |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
703 int dw_window_minimize(HWND handle) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
704 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
705 int _locked_by_me = FALSE; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
706 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
707 if(!handle) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
708 return 0; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
709 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
710 DW_MUTEX_LOCK; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
711 XIconifyWindow(GDK_WINDOW_XDISPLAY(GTK_WIDGET(handle)->window), |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
712 GDK_WINDOW_XWINDOW(GTK_WIDGET(handle)->window), |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
713 DefaultScreen (GDK_DISPLAY ())); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
714 DW_MUTEX_UNLOCK; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
715 return 0; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
716 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
717 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
718 /* |
3 | 719 * Makes the window visible. |
720 * Parameters: | |
721 * handle: The window handle to make visible. | |
722 */ | |
723 int dw_window_show(HWND handle) | |
724 { | |
725 int _locked_by_me = FALSE; | |
34
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
726 GtkWidget *defaultitem; |
3 | 727 |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
728 if(!handle) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
729 return 0; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
730 |
3 | 731 DW_MUTEX_LOCK; |
732 gtk_widget_show(handle); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
733 gdk_window_raise(GTK_WIDGET(handle)->window); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
734 gdk_flush(); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
735 gdk_window_show(GTK_WIDGET(handle)->window); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
736 gdk_flush(); |
34
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
737 defaultitem = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "defaultitem"); |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
738 if(defaultitem) |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
739 gtk_widget_grab_focus(defaultitem); |
3 | 740 DW_MUTEX_UNLOCK; |
741 return 0; | |
742 } | |
743 | |
744 /* | |
745 * Makes the window invisible. | |
746 * Parameters: | |
747 * handle: The window handle to make visible. | |
748 */ | |
749 int dw_window_hide(HWND handle) | |
750 { | |
751 int _locked_by_me = FALSE; | |
752 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
753 if(!handle) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
754 return 0; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
755 |
3 | 756 DW_MUTEX_LOCK; |
757 gtk_widget_hide(handle); | |
758 DW_MUTEX_UNLOCK; | |
759 return 0; | |
760 } | |
761 | |
762 /* | |
763 * Destroys a window and all of it's children. | |
764 * Parameters: | |
765 * handle: The window handle to destroy. | |
766 */ | |
767 int dw_window_destroy(HWND handle) | |
768 { | |
769 int _locked_by_me = FALSE; | |
770 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
771 if(!handle) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
772 return 0; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
773 |
3 | 774 DW_MUTEX_LOCK; |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
775 if(GTK_IS_WIDGET(handle)) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
776 gtk_widget_destroy(handle); |
3 | 777 DW_MUTEX_UNLOCK; |
778 return 0; | |
779 } | |
780 | |
781 /* | |
782 * Changes a window's parent to newparent. | |
783 * Parameters: | |
784 * handle: The window handle to destroy. | |
785 * newparent: The window's new parent window. | |
786 */ | |
787 void dw_window_reparent(HWND handle, HWND newparent) | |
788 { | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
789 int _locked_by_me = FALSE; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
790 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
791 DW_MUTEX_LOCK; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
792 gdk_window_reparent(GTK_WIDGET(handle)->window, newparent ? GTK_WIDGET(newparent)->window : GDK_ROOT_PARENT(), 0, 0); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
793 DW_MUTEX_UNLOCK; |
3 | 794 } |
795 | |
796 int _set_font(HWND handle, char *fontname) | |
797 { | |
798 GtkStyle *style; | |
799 GdkFont *font = NULL; | |
800 int retval = FALSE; | |
801 | |
802 font = gdk_font_load(fontname); | |
803 | |
804 if(font) | |
805 { | |
806 style = gtk_widget_get_style(handle); | |
807 style->font = font; | |
808 gtk_widget_set_style(handle, style); | |
809 retval = TRUE; | |
810 } | |
811 return retval; | |
812 } | |
813 | |
814 /* | |
815 * Sets the font used by a specified window (widget) handle. | |
816 * Parameters: | |
817 * handle: The window (widget) handle. | |
818 * fontname: Name and size of the font in the form "size.fontname" | |
819 */ | |
820 int dw_window_set_font(HWND handle, char *fontname) | |
821 { | |
822 GtkWidget *handle2 = handle; | |
823 char *font; | |
824 int _locked_by_me = FALSE; | |
825 gpointer data; | |
826 | |
827 DW_MUTEX_LOCK; | |
828 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
829 { | |
830 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
831 if(tmp) | |
832 handle2 = tmp; | |
833 } | |
834 font = strdup(fontname); | |
835 | |
836 data = gtk_object_get_data(GTK_OBJECT(handle2), "fontname"); | |
837 if(data) | |
838 free(data); | |
839 | |
840 if(font) | |
841 gtk_object_set_data(GTK_OBJECT(handle2), "fontname", (gpointer)font); | |
842 | |
843 DW_MUTEX_UNLOCK; | |
844 return TRUE; | |
845 } | |
846 | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
847 void _free_gdk_colors(HWND handle) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
848 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
849 GdkColor *old = (GdkColor *)gtk_object_get_data(GTK_OBJECT(handle), "foregdk"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
850 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
851 if(old) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
852 free(old); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
853 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
854 old = (GdkColor *)gtk_object_get_data(GTK_OBJECT(handle), "backgdk"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
855 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
856 if(old) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
857 free(old); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
858 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
859 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
860 /* Free old color pointers and allocate new ones */ |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
861 void _save_gdk_colors(HWND handle, GdkColor fore, GdkColor back) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
862 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
863 GdkColor *foregdk = malloc(sizeof(GdkColor)); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
864 GdkColor *backgdk = malloc(sizeof(GdkColor)); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
865 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
866 _free_gdk_colors(handle); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
867 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
868 *foregdk = fore; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
869 *backgdk = back; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
870 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
871 gtk_object_set_data(GTK_OBJECT(handle), "foregdk", (gpointer)foregdk); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
872 gtk_object_set_data(GTK_OBJECT(handle), "backgdk", (gpointer)backgdk); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
873 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
874 |
3 | 875 int _set_color(HWND handle, unsigned long fore, unsigned long back) |
876 { | |
877 GtkStyle *style; | |
878 | |
879 if(fore & DW_RGB_COLOR || back & DW_RGB_COLOR) | |
880 { | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
881 /* Remember that each color component in X11 use 16 bit no matter |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
882 * what the destination display supports. (and thus GDK) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
883 */ |
3 | 884 GdkColor forecolor = { 0, DW_RED_VALUE(fore) << 8, DW_GREEN_VALUE(fore) << 8, DW_BLUE_VALUE(fore) << 8 }; |
885 GdkColor backcolor = { 0, DW_RED_VALUE(back) << 8, DW_GREEN_VALUE(back) << 8, DW_BLUE_VALUE(back) << 8 }; | |
886 | |
887 gdk_color_alloc(_dw_cmap, &forecolor); | |
888 gdk_color_alloc(_dw_cmap, &backcolor); | |
889 | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
890 style = gtk_style_copy(gtk_widget_get_style(handle)); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
891 style->text[0] = style->text[1] = style->fg[0] = style->fg[1] = forecolor; |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
892 style->base[0] = style->base[1] = style->bg[0] = style->bg[1] = backcolor; |
3 | 893 gtk_widget_set_style(handle, style); |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
894 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
895 _save_gdk_colors(handle, forecolor, backcolor); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
896 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
897 if(GTK_IS_CLIST(handle)) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
898 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
899 int z, rowcount = (int)gtk_object_get_data(GTK_OBJECT(handle), "rowcount"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
900 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
901 for(z=0;z<rowcount;z++) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
902 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
903 gtk_clist_set_foreground(GTK_CLIST(handle), z, &forecolor); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
904 gtk_clist_set_background(GTK_CLIST(handle), z, &backcolor); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
905 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
906 } |
3 | 907 } |
908 else | |
909 { | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
910 style = gtk_style_copy(gtk_widget_get_style(handle)); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
911 style->text[0] = style->text[1] = style->fg[0] = style->fg[1] = _colors[fore]; |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
912 style->base[0] = style->base[1] = style->bg[0] = style->bg[1] = _colors[back]; |
3 | 913 gtk_widget_set_style(handle, style); |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
914 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
915 _save_gdk_colors(handle, _colors[fore], _colors[back]); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
916 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
917 if(GTK_IS_CLIST(handle)) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
918 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
919 int z, rowcount = (int)gtk_object_get_data(GTK_OBJECT(handle), "rowcount"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
920 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
921 for(z=0;z<rowcount;z++) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
922 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
923 gtk_clist_set_foreground(GTK_CLIST(handle), z, &_colors[fore]); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
924 gtk_clist_set_background(GTK_CLIST(handle), z, &_colors[back]); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
925 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
926 } |
3 | 927 } |
928 | |
929 return TRUE; | |
930 } | |
931 /* | |
932 * Sets the colors used by a specified window (widget) handle. | |
933 * Parameters: | |
934 * handle: The window (widget) handle. | |
935 * fore: Foreground color in RGB format. | |
936 * back: Background color in RGB format. | |
937 */ | |
938 int dw_window_set_color(HWND handle, unsigned long fore, unsigned long back) | |
939 { | |
940 GtkWidget *handle2 = handle; | |
941 int _locked_by_me = FALSE; | |
942 | |
943 DW_MUTEX_LOCK; | |
944 | |
945 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
946 { | |
947 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
948 if(tmp) | |
949 handle2 = tmp; | |
950 } | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
951 else if(GTK_IS_BOX(handle)) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
952 { |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
953 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
954 if(tmp) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
955 handle2 = tmp; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
956 } |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
957 |
3 | 958 _set_color(handle2, fore, back); |
959 | |
960 DW_MUTEX_UNLOCK; | |
961 return TRUE; | |
962 } | |
963 | |
964 /* | |
965 * Sets the font used by a specified window (widget) handle. | |
966 * Parameters: | |
967 * handle: The window (widget) handle. | |
968 * border: Size of the window border in pixels. | |
969 */ | |
970 int dw_window_set_border(HWND handle, int border) | |
971 { | |
972 /* TODO */ | |
973 return 0; | |
974 } | |
975 | |
976 /* | |
977 * Captures the mouse input to this window. | |
978 * Parameters: | |
979 * handle: Handle to receive mouse input. | |
980 */ | |
981 void dw_window_capture(HWND handle) | |
982 { | |
983 int _locked_by_me = FALSE; | |
984 | |
985 DW_MUTEX_LOCK; | |
986 gdk_pointer_grab(handle->window, TRUE, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, GDK_CURRENT_TIME); | |
987 DW_MUTEX_UNLOCK; | |
988 } | |
989 | |
990 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
991 * Changes the appearance of the mouse pointer. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
992 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
993 * handle: Handle to widget for which to change. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
994 * cursortype: ID of the pointer you want. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
995 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
996 void dw_window_pointer(HWND handle, int pointertype) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
997 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
998 GdkCursor *cursor = gdk_cursor_new(pointertype); |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
999 if(handle && handle->window) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1000 gdk_window_set_cursor(handle->window, cursor); |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1001 gdk_cursor_destroy(cursor); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1002 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1003 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1004 /* |
3 | 1005 * Releases previous mouse capture. |
1006 */ | |
1007 void dw_window_release(void) | |
1008 { | |
1009 int _locked_by_me = FALSE; | |
1010 | |
1011 DW_MUTEX_LOCK; | |
1012 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
1013 DW_MUTEX_UNLOCK; | |
1014 } | |
1015 | |
1016 /* | |
1017 * Create a new Window Frame. | |
1018 * Parameters: | |
1019 * owner: The Owner's window handle or HWND_DESKTOP. | |
1020 * title: The Window title. | |
1021 * flStyle: Style flags, see the PM reference. | |
1022 */ | |
1023 HWND dw_window_new(HWND hwndOwner, char *title, unsigned long flStyle) | |
1024 { | |
1025 GtkWidget *tmp; | |
1026 int _locked_by_me = FALSE; | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1027 int flags = 0, cx = 0, cy = 0; |
3 | 1028 |
1029 DW_MUTEX_LOCK; | |
1030 tmp = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1031 | |
1032 gtk_window_set_title(GTK_WINDOW(tmp), title); | |
1033 if(!(flStyle & DW_FCF_SIZEBORDER)) | |
1034 gtk_window_set_policy(GTK_WINDOW(tmp), FALSE, FALSE, TRUE); | |
1035 | |
1036 gtk_widget_realize(tmp); | |
1037 | |
1038 if(flStyle & DW_FCF_TITLEBAR) | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1039 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1040 cy += DEFAULT_TITLEBAR_HEIGHT; |
3 | 1041 flags |= GDK_DECOR_TITLE; |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1042 } |
3 | 1043 |
1044 if(flStyle & DW_FCF_MINMAX) | |
1045 flags |= GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE; | |
1046 | |
1047 if(flStyle & DW_FCF_SIZEBORDER) | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1048 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1049 cy += DEFAULT_SIZE_HEIGHT; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1050 cx += DEFAULT_SIZE_WIDTH; |
3 | 1051 flags |= GDK_DECOR_RESIZEH; |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1052 } |
3 | 1053 |
1054 if(flStyle & DW_FCF_BORDER) | |
1055 flags |= GDK_DECOR_BORDER; | |
1056 | |
1057 gdk_window_set_decorations(tmp->window, flags); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1058 gtk_object_set_data(GTK_OBJECT(tmp), "cx", (gpointer)cx); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1059 gtk_object_set_data(GTK_OBJECT(tmp), "cy", (gpointer)cy); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1060 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1061 if(hwndOwner) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1062 gdk_window_reparent(GTK_WIDGET(tmp)->window, GTK_WIDGET(hwndOwner)->window, 0, 0); |
3 | 1063 |
1064 DW_MUTEX_UNLOCK; | |
1065 return tmp; | |
1066 } | |
1067 | |
1068 /* | |
1069 * Create a new Box to be packed. | |
1070 * Parameters: | |
1071 * type: Either BOXVERT (vertical) or BOXHORZ (horizontal). | |
1072 * pad: Number of pixels to pad around the box. | |
1073 */ | |
1074 HWND dw_box_new(int type, int pad) | |
1075 { | |
1076 GtkWidget *tmp; | |
1077 int _locked_by_me = FALSE; | |
1078 | |
1079 DW_MUTEX_LOCK; | |
1080 if(type == BOXVERT) | |
1081 tmp = gtk_vbox_new(FALSE, pad); | |
1082 else | |
1083 tmp = gtk_hbox_new(FALSE, pad); | |
1084 gtk_widget_show(tmp); | |
1085 DW_MUTEX_UNLOCK; | |
1086 return tmp; | |
1087 } | |
1088 | |
1089 /* | |
1090 * Create a new Group Box to be packed. | |
1091 * Parameters: | |
1092 * type: Either BOXVERT (vertical) or BOXHORZ (horizontal). | |
1093 * pad: Number of pixels to pad around the box. | |
1094 * title: Text to be displayined in the group outline. | |
1095 */ | |
1096 HWND dw_groupbox_new(int type, int pad, char *title) | |
1097 { | |
1098 return dw_box_new(type, pad); | |
1099 } | |
1100 | |
1101 /* | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1102 * Create a new MDI Frame to be packed. |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1103 * Parameters: |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1104 * id: An ID to be used with dw_window_from_id or 0L. |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1105 */ |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1106 HWND dw_mdi_new(unsigned long id) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1107 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1108 return gtk_vbox_new(FALSE, 0); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1109 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1110 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1111 /* |
3 | 1112 * Create a bitmap object to be packed. |
1113 * Parameters: | |
1114 * id: An ID to be used with WinWindowFromID() or 0L. | |
1115 */ | |
1116 HWND dw_bitmap_new(unsigned long id) | |
1117 { | |
1118 GdkPixmap *pixmap= NULL; | |
1119 GdkBitmap *bitmap; | |
1120 GtkWidget *tmp; | |
1121 char * test_xpm[] = { | |
1122 "1 1 1 1", | |
1123 " c None", | |
1124 " "}; | |
1125 int _locked_by_me = FALSE; | |
1126 | |
1127 DW_MUTEX_LOCK; | |
1128 #ifndef USE_IMLIB | |
1129 GtkStyle *iconstyle; | |
1130 | |
1131 /* hmmm why do we need the handle here? */ | |
1132 iconstyle = gtk_widget_get_style(handle); | |
1133 if (!pixmap) | |
1134 pixmap = gdk_pixmap_create_from_xpm_d(handle->window, &bitmap, &iconstyle->bg[GTK_STATE_NORMAL], &test_xpm); | |
1135 #else | |
1136 gdk_imlib_data_to_pixmap(test_xpm, &pixmap, &bitmap); | |
1137 #endif | |
1138 tmp = gtk_pixmap_new(pixmap, bitmap); | |
1139 gtk_widget_show(tmp); | |
1140 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1141 DW_MUTEX_UNLOCK; | |
1142 return tmp; | |
1143 } | |
1144 | |
1145 /* | |
1146 * Create a notebook object to be packed. | |
1147 * Parameters: | |
1148 * id: An ID to be used for getting the resource from the | |
1149 * resource file. | |
1150 */ | |
1151 HWND dw_notebook_new(unsigned long id, int top) | |
1152 { | |
1153 GtkWidget *tmp; | |
1154 int _locked_by_me = FALSE; | |
1155 | |
1156 DW_MUTEX_LOCK; | |
1157 tmp = gtk_notebook_new(); | |
1158 if(top) | |
1159 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tmp), GTK_POS_TOP); | |
1160 else | |
1161 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tmp), GTK_POS_BOTTOM); | |
1162 gtk_widget_show(tmp); | |
1163 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1164 DW_MUTEX_UNLOCK; | |
1165 return tmp; | |
1166 } | |
1167 | |
1168 /* | |
1169 * Create a menu object to be popped up. | |
1170 * Parameters: | |
1171 * id: An ID to be used for getting the resource from the | |
1172 * resource file. | |
1173 */ | |
1174 HMENUI dw_menu_new(unsigned long id) | |
1175 { | |
1176 int _locked_by_me = FALSE; | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1177 HMENUI tmp = malloc(sizeof(struct _hmenui)); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1178 GtkAccelGroup *accel_group; |
3 | 1179 |
1180 if(!tmp) | |
1181 return NULL; | |
1182 | |
1183 DW_MUTEX_LOCK; | |
1184 tmp->menu = gtk_menu_new(); | |
1185 gtk_widget_show(tmp->menu); | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1186 accel_group = gtk_accel_group_new(); |
3 | 1187 gtk_object_set_data(GTK_OBJECT(tmp->menu), "id", (gpointer)id); |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1188 gtk_object_set_data(GTK_OBJECT(tmp->menu), "accel", (gpointer)accel_group); |
3 | 1189 DW_MUTEX_UNLOCK; |
1190 return tmp; | |
1191 } | |
1192 | |
1193 /* | |
1194 * Create a menubar on a window. | |
1195 * Parameters: | |
1196 * location: Handle of a window frame to be attached to. | |
1197 */ | |
1198 HMENUI dw_menubar_new(HWND location) | |
1199 { | |
1200 GtkWidget *box; | |
1201 int _locked_by_me = FALSE; | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1202 HMENUI tmp = malloc(sizeof(struct _hmenui)); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1203 GtkAccelGroup *accel_group; |
3 | 1204 |
1205 if(!tmp) | |
1206 return NULL; | |
1207 | |
1208 DW_MUTEX_LOCK; | |
1209 tmp->menu = gtk_menu_bar_new(); | |
1210 box = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(location)); | |
1211 gtk_widget_show(tmp->menu); | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1212 accel_group = gtk_accel_group_new(); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1213 gtk_object_set_data(GTK_OBJECT(tmp->menu), "accel", (gpointer)accel_group); |
3 | 1214 |
1215 if(box) | |
1216 gtk_box_pack_end(GTK_BOX(box), tmp->menu, FALSE, FALSE, 0); | |
1217 | |
1218 DW_MUTEX_UNLOCK; | |
1219 return tmp; | |
1220 } | |
1221 | |
1222 /* | |
1223 * Destroys a menu created with dw_menubar_new or dw_menu_new. | |
1224 * Parameters: | |
1225 * menu: Handle of a menu. | |
1226 */ | |
1227 void dw_menu_destroy(HMENUI *menu) | |
1228 { | |
1229 if(menu && *menu) | |
1230 { | |
1231 int _locked_by_me = FALSE; | |
1232 | |
1233 DW_MUTEX_LOCK; | |
1234 gtk_widget_destroy((*menu)->menu); | |
1235 free(*menu); | |
1236 *menu = NULL; | |
1237 DW_MUTEX_UNLOCK; | |
1238 } | |
1239 } | |
1240 | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1241 char _removetilde(char *dest, char *src) |
3 | 1242 { |
1243 int z, cur=0; | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1244 char accel = '\0'; |
3 | 1245 |
1246 for(z=0;z<strlen(src);z++) | |
1247 { | |
1248 if(src[z] != '~') | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1249 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1250 dest[cur] = src[z]; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1251 cur++; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1252 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1253 else |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1254 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1255 dest[cur] = '_'; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1256 accel = src[z+1]; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1257 cur++; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1258 } |
3 | 1259 } |
1260 dest[cur] = 0; | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1261 return accel; |
3 | 1262 } |
1263 | |
1264 /* | |
1265 * Adds a menuitem or submenu to an existing menu. | |
1266 * Parameters: | |
1267 * menu: The handle the the existing menu. | |
1268 * title: The title text on the menu item to be added. | |
1269 * id: An ID to be used for message passing. | |
1270 * flags: Extended attributes to set on the menu. | |
1271 * end: If TRUE memu is positioned at the end of the menu. | |
1272 * check: If TRUE menu is "check"able. | |
1273 * submenu: Handle to an existing menu to be a submenu or NULL. | |
1274 */ | |
1275 HWND dw_menu_append_item(HMENUI menu, char *title, unsigned long id, unsigned long flags, int end, int check, HMENUI submenu) | |
1276 { | |
1277 GtkWidget *tmphandle; | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1278 char accel, *tempbuf = malloc(strlen(title)+1); |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1279 int _locked_by_me = FALSE, submenucount; |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1280 guint tmp_key; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1281 GtkAccelGroup *accel_group; |
3 | 1282 |
1283 if(!menu || !menu->menu) | |
1284 { | |
1285 free(tempbuf); | |
1286 return NULL; | |
1287 } | |
1288 | |
1289 DW_MUTEX_LOCK; | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1290 accel = _removetilde(tempbuf, title); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1291 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1292 accel_group = (GtkAccelGroup *)gtk_object_get_data(GTK_OBJECT(menu->menu), "accel"); |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1293 submenucount = (int)gtk_object_get_data(GTK_OBJECT(menu->menu), "submenucount"); |
3 | 1294 |
1295 if(strlen(tempbuf) == 0) | |
1296 tmphandle=gtk_menu_item_new(); | |
1297 else | |
1298 { | |
1299 if(check) | |
1300 { | |
1301 char numbuf[10]; | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1302 if(accel && accel_group) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1303 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1304 tmphandle=gtk_check_menu_item_new_with_label(""); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1305 tmp_key = gtk_label_parse_uline(GTK_LABEL(GTK_BIN(tmphandle)->child), tempbuf); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1306 gtk_widget_add_accelerator(tmphandle, "activate_item", accel_group, tmp_key, GDK_MOD1_MASK, 0); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1307 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1308 else |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1309 tmphandle=gtk_check_menu_item_new_with_label(tempbuf); |
3 | 1310 gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(tmphandle), TRUE); |
1311 sprintf(numbuf, "%lu", id); | |
1312 gtk_object_set_data(GTK_OBJECT(menu->menu), numbuf, (gpointer)tmphandle); | |
1313 } | |
1314 else | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1315 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1316 if(accel && accel_group) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1317 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1318 tmphandle=gtk_menu_item_new_with_label(""); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1319 tmp_key = gtk_label_parse_uline(GTK_LABEL(GTK_BIN(tmphandle)->child), tempbuf); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1320 gtk_widget_add_accelerator(tmphandle, "activate_item", accel_group, tmp_key, GDK_MOD1_MASK, 0); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1321 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1322 else |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1323 tmphandle=gtk_menu_item_new_with_label(tempbuf); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1324 } |
3 | 1325 } |
1326 | |
1327 gtk_widget_show(tmphandle); | |
1328 | |
1329 if(submenu) | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1330 { |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1331 char tempbuf[100]; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1332 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1333 sprintf(tempbuf, "submenu%d", submenucount); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1334 submenucount++; |
3 | 1335 gtk_menu_item_set_submenu(GTK_MENU_ITEM(tmphandle), submenu->menu); |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1336 gtk_object_set_data(GTK_OBJECT(menu->menu), tempbuf, (gpointer)submenu->menu); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1337 gtk_object_set_data(GTK_OBJECT(menu->menu), "submenucount", (gpointer)submenucount); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1338 } |
3 | 1339 |
1340 if(GTK_IS_MENU_BAR(menu->menu)) | |
1341 gtk_menu_bar_append(GTK_MENU_BAR(menu->menu), tmphandle); | |
1342 else | |
1343 gtk_menu_append(GTK_MENU(menu->menu), tmphandle); | |
1344 | |
1345 gtk_object_set_data(GTK_OBJECT(tmphandle), "id", (gpointer)id); | |
1346 free(tempbuf); | |
1347 DW_MUTEX_UNLOCK; | |
1348 return tmphandle; | |
1349 } | |
1350 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1351 GtkWidget *_find_submenu_id(GtkWidget *start, char *name) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1352 { |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1353 GtkWidget *tmp; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1354 int z, submenucount = (int)gtk_object_get_data(GTK_OBJECT(start), "submenucount"); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1355 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1356 if((tmp = gtk_object_get_data(GTK_OBJECT(start), name))) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1357 return tmp; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1358 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1359 for(z=0;z<submenucount;z++) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1360 { |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1361 char tempbuf[100]; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1362 GtkWidget *submenu, *menuitem; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1363 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1364 sprintf(tempbuf, "submenu%d", z); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1365 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1366 if((submenu = gtk_object_get_data(GTK_OBJECT(start), tempbuf))) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1367 { |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1368 if((menuitem = _find_submenu_id(submenu, name))) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1369 return menuitem; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1370 } |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1371 } |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1372 return NULL; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1373 } |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1374 |
3 | 1375 /* |
1376 * Sets the state of a menu item check. | |
1377 * Parameters: | |
1378 * menu: The handle the the existing menu. | |
1379 * id: Menuitem id. | |
1380 * check: TRUE for checked FALSE for not checked. | |
1381 */ | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1382 void dw_menu_item_set_check(HMENUI menu, unsigned long id, int check) |
3 | 1383 { |
1384 char numbuf[10]; | |
1385 GtkWidget *tmphandle; | |
1386 int _locked_by_me = FALSE; | |
1387 | |
1388 if(!menu || !menu->menu) | |
1389 return; | |
1390 | |
1391 DW_MUTEX_LOCK; | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1392 sprintf(numbuf, "%lu", id); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1393 tmphandle = _find_submenu_id(menu->menu, numbuf); |
3 | 1394 |
1395 if(tmphandle) | |
1396 { | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1397 _dw_ignore_click = 1; |
3 | 1398 if(GTK_CHECK_MENU_ITEM(tmphandle)->active != check) |
1399 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tmphandle), check); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1400 _dw_ignore_click = 0; |
3 | 1401 } |
1402 DW_MUTEX_UNLOCK; | |
1403 } | |
1404 | |
1405 /* | |
1406 * Pops up a context menu at given x and y coordinates. | |
1407 * Parameters: | |
1408 * menu: The handle the the existing menu. | |
1409 * parent: Handle to the window initiating the popup. | |
1410 * x: X coordinate. | |
1411 * y: Y coordinate. | |
1412 */ | |
1413 void dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) | |
1414 { | |
1415 int _locked_by_me = FALSE; | |
1416 | |
1417 if(!menu || !*menu) | |
1418 return; | |
1419 | |
1420 DW_MUTEX_LOCK; | |
1421 gtk_menu_popup(GTK_MENU((*menu)->menu), NULL, NULL, NULL, NULL, x, y); | |
1422 free(*menu); | |
1423 *menu = NULL; | |
1424 DW_MUTEX_UNLOCK; | |
1425 } | |
1426 | |
1427 | |
1428 /* | |
1429 * Returns the current X and Y coordinates of the mouse pointer. | |
1430 * Parameters: | |
1431 * x: Pointer to variable to store X coordinate. | |
1432 * y: Pointer to variable to store Y coordinate. | |
1433 */ | |
1434 void dw_pointer_query_pos(long *x, long *y) | |
1435 { | |
1436 GdkModifierType state; | |
1437 int gx, gy; | |
1438 | |
1439 gdk_window_get_pointer (GDK_ROOT_PARENT(), &gx, &gy, &state); | |
1440 *x = gx; | |
1441 *y = gy; | |
1442 } | |
1443 | |
1444 /* | |
1445 * Sets the X and Y coordinates of the mouse pointer. | |
1446 * Parameters: | |
1447 * x: X coordinate. | |
1448 * y: Y coordinate. | |
1449 */ | |
1450 void dw_pointer_set_pos(long x, long y) | |
1451 { | |
1452 XWarpPointer(GDK_DISPLAY(), None, GDK_ROOT_WINDOW(), 0,0,0,0, x, y); | |
1453 } | |
1454 | |
1455 /* | |
1456 * Create a container object to be packed. | |
1457 * Parameters: | |
1458 * id: An ID to be used for getting the resource from the | |
1459 * resource file. | |
1460 */ | |
1461 HWND dw_container_new(unsigned long id) | |
1462 { | |
1463 GtkWidget *tmp; | |
1464 int _locked_by_me = FALSE; | |
1465 | |
1466 DW_MUTEX_LOCK; | |
1467 tmp = gtk_scrolled_window_new (NULL, NULL); | |
1468 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (tmp), | |
1469 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1470 | |
1471 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1472 gtk_widget_show(tmp); | |
1473 | |
1474 DW_MUTEX_UNLOCK; | |
1475 return tmp; | |
1476 } | |
1477 | |
1478 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1479 * Create a tree object to be packed. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1480 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1481 * id: An ID to be used for getting the resource from the |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1482 * resource file. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1483 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1484 HWND dw_tree_new(ULONG id) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1485 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1486 GtkWidget *tmp, *tree; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1487 int _locked_by_me = FALSE; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1488 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1489 DW_MUTEX_LOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1490 tmp = gtk_scrolled_window_new(NULL, NULL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1491 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (tmp), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1492 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1493 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1494 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1495 gtk_widget_show(tmp); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1496 tree = gtk_tree_new(); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1497 if(!tree) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1498 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1499 gtk_widget_destroy(tmp); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1500 DW_MUTEX_UNLOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1501 return FALSE; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1502 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1503 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(tmp), tree); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1504 /* Set the selection mode */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1505 gtk_tree_set_selection_mode (GTK_TREE(tree), GTK_SELECTION_SINGLE); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1506 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1507 gtk_object_set_user_data(GTK_OBJECT(tmp), (gpointer)tree); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1508 gtk_widget_show(tree); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1509 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1510 DW_MUTEX_UNLOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1511 return tmp; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1512 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1513 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1514 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
1515 /* |
3 | 1516 * Create a new static text window (widget) to be packed. |
1517 * Parameters: | |
1518 * text: The text to be display by the static text widget. | |
1519 * id: An ID to be used with WinWindowFromID() or 0L. | |
1520 */ | |
1521 HWND dw_text_new(char *text, unsigned long id) | |
1522 { | |
1523 GtkWidget *tmp; | |
1524 int _locked_by_me = FALSE; | |
1525 | |
1526 DW_MUTEX_LOCK; | |
1527 tmp = gtk_label_new(text); | |
1528 gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT); | |
1529 gtk_widget_show(tmp); | |
1530 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1531 DW_MUTEX_UNLOCK; | |
1532 return tmp; | |
1533 } | |
1534 | |
1535 /* | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1536 * Create a new status text window (widget) to be packed. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1537 * Parameters: |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1538 * text: The text to be display by the static text widget. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1539 * id: An ID to be used with WinWindowFromID() or 0L. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1540 */ |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1541 HWND dw_status_text_new(char *text, ULONG id) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1542 { |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1543 GtkWidget *tmp, *frame; |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1544 int _locked_by_me = FALSE; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1545 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1546 DW_MUTEX_LOCK; |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1547 frame = gtk_frame_new(NULL); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1548 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1549 tmp = gtk_label_new(text); |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1550 gtk_container_add(GTK_CONTAINER(frame), tmp); |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1551 gtk_widget_show(tmp); |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1552 gtk_widget_show(frame); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1553 gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_LEFT); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1554 gtk_object_set_data(GTK_OBJECT(frame), "id", (gpointer)id); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1555 gtk_object_set_data(GTK_OBJECT(frame), "label", (gpointer)tmp); |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1556 DW_MUTEX_UNLOCK; |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1557 return frame; |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1558 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1559 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1560 /* |
3 | 1561 * Create a new Multiline Editbox window (widget) to be packed. |
1562 * Parameters: | |
1563 * id: An ID to be used with WinWindowFromID() or 0L. | |
1564 */ | |
1565 HWND dw_mle_new(unsigned long id) | |
1566 { | |
1567 GtkWidget *tmp, *tmpbox, *scroller; | |
1568 int _locked_by_me = FALSE; | |
1569 | |
1570 DW_MUTEX_LOCK; | |
1571 tmpbox = gtk_hbox_new(FALSE, 0); | |
1572 tmp = gtk_text_new(NULL, NULL); | |
1573 gtk_text_set_word_wrap(GTK_TEXT(tmp), FALSE); | |
1574 gtk_text_set_line_wrap(GTK_TEXT(tmp), FALSE); | |
1575 scroller = gtk_vscrollbar_new(GTK_TEXT(tmp)->vadj); | |
1576 GTK_WIDGET_UNSET_FLAGS(scroller, GTK_CAN_FOCUS); | |
1577 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1578 gtk_object_set_data(GTK_OBJECT(tmpbox), "mle", (gpointer)tmp); | |
1579 gtk_box_pack_start(GTK_BOX(tmpbox), tmp, TRUE, TRUE, 0); | |
1580 gtk_box_pack_start(GTK_BOX(tmpbox), scroller, FALSE, TRUE, 0); | |
1581 gtk_widget_show(tmp); | |
1582 gtk_widget_show(scroller); | |
1583 gtk_widget_show(tmpbox); | |
1584 DW_MUTEX_UNLOCK; | |
1585 return tmpbox; | |
1586 } | |
1587 | |
1588 /* | |
1589 * Create a new Entryfield window (widget) to be packed. | |
1590 * Parameters: | |
1591 * text: The default text to be in the entryfield widget. | |
1592 * id: An ID to be used with WinWindowFromID() or 0L. | |
1593 */ | |
1594 HWND dw_entryfield_new(char *text, unsigned long id) | |
1595 { | |
1596 GtkWidget *tmp; | |
1597 int _locked_by_me = FALSE; | |
1598 | |
1599 DW_MUTEX_LOCK; | |
1600 tmp = gtk_entry_new(); | |
1601 | |
1602 gtk_entry_set_text(GTK_ENTRY(tmp), text); | |
1603 | |
1604 gtk_widget_show(tmp); | |
1605 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1606 | |
1607 DW_MUTEX_UNLOCK; | |
1608 return tmp; | |
1609 } | |
1610 | |
1611 /* | |
1612 * Create a new Entryfield (password) window (widget) to be packed. | |
1613 * Parameters: | |
1614 * text: The default text to be in the entryfield widget. | |
1615 * id: An ID to be used with WinWindowFromID() or 0L. | |
1616 */ | |
1617 HWND dw_entryfield_password_new(char *text, ULONG id) | |
1618 { | |
1619 GtkWidget *tmp; | |
1620 int _locked_by_me = FALSE; | |
1621 | |
1622 DW_MUTEX_LOCK; | |
1623 tmp = gtk_entry_new(); | |
1624 | |
1625 gtk_entry_set_visibility(GTK_ENTRY(tmp), FALSE); | |
1626 gtk_entry_set_text(GTK_ENTRY(tmp), text); | |
1627 | |
1628 gtk_widget_show(tmp); | |
1629 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1630 | |
1631 DW_MUTEX_UNLOCK; | |
1632 return tmp; | |
1633 } | |
1634 | |
1635 /* | |
1636 * Create a new Combobox window (widget) to be packed. | |
1637 * Parameters: | |
1638 * text: The default text to be in the combpbox widget. | |
1639 * id: An ID to be used with WinWindowFromID() or 0L. | |
1640 */ | |
1641 HWND dw_combobox_new(char *text, unsigned long id) | |
1642 { | |
1643 GtkWidget *tmp; | |
1644 int _locked_by_me = FALSE; | |
1645 | |
1646 DW_MUTEX_LOCK; | |
1647 tmp = gtk_combo_new(); | |
1648 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(tmp)->entry), text); | |
1649 gtk_combo_set_use_arrows(GTK_COMBO(tmp), TRUE); | |
1650 gtk_object_set_user_data(GTK_OBJECT(tmp), NULL); | |
1651 gtk_widget_show(tmp); | |
1652 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1653 DW_MUTEX_UNLOCK; | |
1654 return tmp; | |
1655 } | |
1656 | |
1657 /* | |
1658 * Create a new button window (widget) to be packed. | |
1659 * Parameters: | |
1660 * text: The text to be display by the static text widget. | |
1661 * id: An ID to be used with WinWindowFromID() or 0L. | |
1662 */ | |
1663 HWND dw_button_new(char *text, unsigned long id) | |
1664 { | |
1665 GtkWidget *tmp; | |
1666 int _locked_by_me = FALSE; | |
1667 | |
1668 DW_MUTEX_LOCK; | |
1669 tmp = gtk_button_new_with_label(text); | |
1670 gtk_widget_show(tmp); | |
1671 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1672 DW_MUTEX_UNLOCK; | |
1673 return tmp; | |
1674 } | |
1675 | |
1676 /* | |
1677 * Create a new bitmap button window (widget) to be packed. | |
1678 * Parameters: | |
1679 * text: Bubble help text to be displayed. | |
1680 * id: An ID of a bitmap in the resource file. | |
1681 */ | |
1682 HWND dw_bitmapbutton_new(char *text, unsigned long id) | |
1683 { | |
1684 GtkWidget *tmp; | |
1685 GtkWidget *bitmap; | |
1686 GtkTooltips *tooltips; | |
1687 int _locked_by_me = FALSE; | |
1688 | |
1689 DW_MUTEX_LOCK; | |
1690 tmp = gtk_button_new(); | |
1691 bitmap = dw_bitmap_new(id); | |
1692 | |
1693 if(bitmap) | |
1694 { | |
1695 dw_window_set_bitmap(bitmap, id); | |
1696 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | |
1697 } | |
1698 gtk_widget_show(tmp); | |
1699 if(text) | |
1700 { | |
1701 tooltips = gtk_tooltips_new(); | |
1702 gtk_tooltips_set_colors(tooltips, &_colors[DW_CLR_BLACK], &_colors[DW_CLR_YELLOW]); | |
1703 gtk_tooltips_set_tip(tooltips, tmp, text, NULL); | |
1704 gtk_object_set_data(GTK_OBJECT(tmp), "tooltip", (gpointer)tooltips); | |
1705 } | |
1706 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1707 DW_MUTEX_UNLOCK; | |
1708 return tmp; | |
1709 } | |
1710 | |
1711 /* | |
1712 * Create a new spinbutton window (widget) to be packed. | |
1713 * Parameters: | |
1714 * text: The text to be display by the static text widget. | |
1715 * id: An ID to be used with WinWindowFromID() or 0L. | |
1716 */ | |
1717 HWND dw_spinbutton_new(char *text, unsigned long id) | |
1718 { | |
1719 GtkAdjustment *adj; | |
1720 GtkWidget *tmp; | |
1721 int _locked_by_me = FALSE; | |
1722 | |
1723 DW_MUTEX_LOCK; | |
1724 adj = (GtkAdjustment *)gtk_adjustment_new (1.0, 0.0, 100.0, 1.0, 5.0, 0.0); | |
1725 tmp = gtk_spin_button_new (adj, 0, 0); | |
1726 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(tmp), TRUE); | |
1727 gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(tmp), TRUE); | |
1728 gtk_widget_show(tmp); | |
1729 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1730 DW_MUTEX_UNLOCK; | |
1731 return tmp; | |
1732 } | |
1733 | |
1734 /* | |
1735 * Create a new radiobutton window (widget) to be packed. | |
1736 * Parameters: | |
1737 * text: The text to be display by the static text widget. | |
1738 * id: An ID to be used with WinWindowFromID() or 0L. | |
1739 */ | |
1740 HWND dw_radiobutton_new(char *text, ULONG id) | |
1741 { | |
1742 /* This will have to be fixed in the future. */ | |
1743 GtkWidget *tmp; | |
1744 int _locked_by_me = FALSE; | |
1745 | |
1746 DW_MUTEX_LOCK; | |
1747 tmp = gtk_radio_button_new_with_label(NULL, text); | |
1748 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1749 gtk_widget_show(tmp); | |
1750 | |
1751 DW_MUTEX_UNLOCK; | |
1752 return tmp; | |
1753 } | |
1754 | |
1755 /* | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
30
diff
changeset
|
1756 * Create a new percent bar window (widget) to be packed. |
3 | 1757 * Parameters: |
1758 * id: An ID to be used with WinWindowFromID() or 0L. | |
1759 */ | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
30
diff
changeset
|
1760 HWND dw_percent_new(unsigned long id) |
3 | 1761 { |
1762 GtkWidget *tmp; | |
1763 int _locked_by_me = FALSE; | |
1764 | |
1765 DW_MUTEX_LOCK; | |
1766 tmp = gtk_progress_bar_new(); | |
1767 gtk_widget_show(tmp); | |
1768 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1769 DW_MUTEX_UNLOCK; | |
1770 return tmp; | |
1771 } | |
1772 | |
1773 /* | |
1774 * Create a new checkbox window (widget) to be packed. | |
1775 * Parameters: | |
1776 * text: The text to be display by the static text widget. | |
1777 * id: An ID to be used with WinWindowFromID() or 0L. | |
1778 */ | |
1779 HWND dw_checkbox_new(char *text, unsigned long id) | |
1780 { | |
1781 GtkWidget *tmp; | |
1782 int _locked_by_me = FALSE; | |
1783 | |
1784 DW_MUTEX_LOCK; | |
1785 tmp = gtk_check_button_new_with_label(text); | |
1786 gtk_widget_show(tmp); | |
1787 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1788 DW_MUTEX_UNLOCK; | |
1789 return tmp; | |
1790 } | |
1791 | |
1792 /* | |
1793 * Create a new listbox window (widget) to be packed. | |
1794 * Parameters: | |
1795 * id: An ID to be used with WinWindowFromID() or 0L. | |
1796 * multi: Multiple select TRUE or FALSE. | |
1797 */ | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1798 HWND dw_listbox_new(unsigned long id, int multi) |
3 | 1799 { |
1800 GtkWidget *tmp, *list; | |
1801 int _locked_by_me = FALSE; | |
1802 | |
1803 DW_MUTEX_LOCK; | |
1804 tmp = gtk_scrolled_window_new(NULL, NULL); | |
1805 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (tmp), | |
1806 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1807 | |
1808 list = gtk_list_new(); | |
1809 gtk_list_set_selection_mode(GTK_LIST(list), multi ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE); | |
1810 | |
1811 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(tmp), | |
1812 list); | |
1813 gtk_object_set_user_data(GTK_OBJECT(tmp), list); | |
1814 gtk_widget_show(list); | |
1815 gtk_widget_show(tmp); | |
1816 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
1817 | |
1818 DW_MUTEX_UNLOCK; | |
1819 return tmp; | |
1820 } | |
1821 | |
1822 /* | |
1823 * Sets the icon used for a given window. | |
1824 * Parameters: | |
1825 * handle: Handle to the window. | |
1826 * id: An ID to be used to specify the icon. | |
1827 */ | |
1828 void dw_window_set_icon(HWND handle, unsigned long id) | |
1829 { | |
1830 GdkBitmap *bitmap; | |
1831 GdkPixmap *icon_pixmap; | |
1832 int _locked_by_me = FALSE; | |
1833 | |
1834 DW_MUTEX_LOCK; | |
1835 icon_pixmap = _find_pixmap(&bitmap, id, handle); | |
1836 | |
1837 if(handle->window && icon_pixmap) | |
1838 gdk_window_set_icon(handle->window, NULL, icon_pixmap, bitmap); | |
1839 | |
1840 DW_MUTEX_UNLOCK; | |
1841 } | |
1842 | |
1843 /* | |
1844 * Sets the bitmap used for a given static window. | |
1845 * Parameters: | |
1846 * handle: Handle to the window. | |
1847 * id: An ID to be used to specify the icon. | |
1848 */ | |
1849 void dw_window_set_bitmap(HWND handle, unsigned long id) | |
1850 { | |
1851 GdkBitmap *bitmap; | |
1852 GdkPixmap *tmp; | |
1853 int _locked_by_me = FALSE; | |
1854 | |
1855 DW_MUTEX_LOCK; | |
1856 tmp = _find_pixmap(&bitmap, id, handle); | |
1857 if(tmp) | |
1858 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); | |
1859 DW_MUTEX_UNLOCK; | |
1860 } | |
1861 | |
1862 /* | |
1863 * Sets the text used for a given window. | |
1864 * Parameters: | |
1865 * handle: Handle to the window. | |
1866 * text: The text associsated with a given window. | |
1867 */ | |
1868 void dw_window_set_text(HWND handle, char *text) | |
1869 { | |
1870 int _locked_by_me = FALSE; | |
1871 | |
1872 DW_MUTEX_LOCK; | |
1873 if(GTK_IS_ENTRY(handle)) | |
1874 gtk_entry_set_text(GTK_ENTRY(handle), text); | |
1875 else if(GTK_IS_COMBO(handle)) | |
1876 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(handle)->entry), text); | |
1877 else if(GTK_IS_LABEL(handle)) | |
1878 gtk_label_set_text(GTK_LABEL(handle), text); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1879 else if(GTK_IS_FRAME(handle)) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1880 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1881 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "label"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1882 if(tmp && GTK_IS_LABEL(tmp)) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1883 gtk_label_set_text(GTK_LABEL(tmp), text); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1884 } |
3 | 1885 DW_MUTEX_UNLOCK; |
1886 } | |
1887 | |
1888 /* | |
1889 * Gets the text used for a given window. | |
1890 * Parameters: | |
1891 * handle: Handle to the window. | |
1892 * Returns: | |
1893 * text: The text associsated with a given window. | |
1894 */ | |
1895 char *dw_window_get_text(HWND handle) | |
1896 { | |
1897 char *possible = ""; | |
1898 int _locked_by_me = FALSE; | |
1899 | |
1900 DW_MUTEX_LOCK; | |
1901 if(GTK_IS_ENTRY(handle)) | |
1902 possible = gtk_entry_get_text(GTK_ENTRY(handle)); | |
1903 else if(GTK_IS_COMBO(handle)) | |
1904 possible = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(handle)->entry)); | |
1905 | |
1906 DW_MUTEX_UNLOCK; | |
1907 return strdup(possible); | |
1908 } | |
1909 | |
1910 /* | |
1911 * Disables given window (widget). | |
1912 * Parameters: | |
1913 * handle: Handle to the window. | |
1914 */ | |
1915 void dw_window_disable(HWND handle) | |
1916 { | |
1917 int _locked_by_me = FALSE; | |
1918 | |
1919 DW_MUTEX_LOCK; | |
1920 gtk_widget_set_sensitive(handle, FALSE); | |
1921 DW_MUTEX_UNLOCK; | |
1922 } | |
1923 | |
1924 /* | |
1925 * Enables given window (widget). | |
1926 * Parameters: | |
1927 * handle: Handle to the window. | |
1928 */ | |
1929 void dw_window_enable(HWND handle) | |
1930 { | |
1931 int _locked_by_me = FALSE; | |
1932 | |
1933 DW_MUTEX_LOCK; | |
1934 gtk_widget_set_sensitive(handle, TRUE); | |
1935 DW_MUTEX_UNLOCK; | |
1936 } | |
1937 | |
1938 /* | |
1939 * Adds text to an MLE box and returns the current point. | |
1940 * Parameters: | |
1941 * handle: Handle to the MLE to be queried. | |
1942 * buffer: Text buffer to be imported. | |
1943 * startpoint: Point to start entering text. | |
1944 */ | |
1945 unsigned int dw_mle_import(HWND handle, char *buffer, int startpoint) | |
1946 { | |
1947 unsigned int tmppoint = startpoint; | |
1948 int _locked_by_me = FALSE; | |
1949 | |
1950 DW_MUTEX_LOCK; | |
1951 if(GTK_IS_BOX(handle)) | |
1952 { | |
1953 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
1954 | |
1955 if(tmp && GTK_IS_TEXT(tmp)) | |
1956 { | |
1957 gtk_text_set_point(GTK_TEXT(tmp), startpoint < 0 ? 0 : startpoint); | |
1958 gtk_text_insert(GTK_TEXT(tmp), NULL, NULL, NULL, buffer, -1); | |
1959 tmppoint = gtk_text_get_point(GTK_TEXT(tmp)); | |
1960 } | |
1961 } | |
1962 DW_MUTEX_UNLOCK; | |
1963 return tmppoint; | |
1964 } | |
1965 | |
1966 /* | |
1967 * Grabs text from an MLE box. | |
1968 * Parameters: | |
1969 * handle: Handle to the MLE to be queried. | |
1970 * buffer: Text buffer to be exported. | |
1971 * startpoint: Point to start grabbing text. | |
1972 * length: Amount of text to be grabbed. | |
1973 */ | |
1974 void dw_mle_export(HWND handle, char *buffer, int startpoint, int length) | |
1975 { | |
1976 int _locked_by_me = FALSE; | |
1977 gchar *text; | |
1978 | |
1979 DW_MUTEX_LOCK; | |
1980 if(GTK_IS_BOX(handle)) | |
1981 { | |
1982 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
1983 | |
1984 if(tmp && GTK_IS_TEXT(tmp)) | |
1985 { | |
1986 text = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), startpoint, startpoint + length); | |
1987 if(text) | |
1988 { | |
1989 strcpy(buffer, text); | |
1990 g_free(text); | |
1991 } | |
1992 } | |
1993 } | |
1994 DW_MUTEX_UNLOCK; | |
1995 } | |
1996 | |
1997 /* | |
1998 * Obtains information about an MLE box. | |
1999 * Parameters: | |
2000 * handle: Handle to the MLE to be queried. | |
2001 * bytes: A pointer to a variable to return the total bytes. | |
2002 * lines: A pointer to a variable to return the number of lines. | |
2003 */ | |
2004 void dw_mle_query(HWND handle, unsigned long *bytes, unsigned long *lines) | |
2005 { | |
2006 int _locked_by_me = FALSE; | |
2007 | |
2008 if(bytes) | |
2009 *bytes = 0; | |
2010 if(lines) | |
2011 *lines = 0; | |
2012 | |
2013 DW_MUTEX_LOCK; | |
2014 if(GTK_IS_BOX(handle)) | |
2015 { | |
2016 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
2017 | |
2018 if(tmp && GTK_IS_TEXT(tmp)) | |
2019 { | |
2020 if(bytes) | |
2021 *bytes = gtk_text_get_length(GTK_TEXT(tmp)); | |
2022 if(lines) | |
2023 { | |
2024 gchar *text; | |
2025 | |
2026 *lines = 0; | |
2027 text = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), 0, bytes ? *bytes : gtk_text_get_length(GTK_TEXT(tmp))); | |
2028 | |
2029 if(text) | |
2030 { | |
2031 int z, len = strlen(text); | |
2032 | |
2033 for(z=0;z<len;z++) | |
2034 { | |
2035 if(text[z] == '\n') | |
2036 (*lines)++; | |
2037 } | |
2038 g_free(text); | |
2039 } | |
2040 } | |
2041 } | |
2042 } | |
2043 DW_MUTEX_UNLOCK; | |
2044 } | |
2045 | |
2046 /* | |
2047 * Deletes text from an MLE box. | |
2048 * Parameters: | |
2049 * handle: Handle to the MLE to be deleted from. | |
2050 * startpoint: Point to start deleting text. | |
2051 * length: Amount of text to be deleted. | |
2052 */ | |
2053 void dw_mle_delete(HWND handle, int startpoint, int length) | |
2054 { | |
2055 int _locked_by_me = FALSE; | |
2056 | |
2057 DW_MUTEX_LOCK; | |
2058 if(GTK_IS_BOX(handle)) | |
2059 { | |
2060 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
2061 | |
2062 if(tmp && GTK_IS_TEXT(tmp)) | |
2063 { | |
2064 gtk_text_set_point(GTK_TEXT(tmp), startpoint); | |
2065 gtk_text_forward_delete(GTK_TEXT(tmp), length); | |
2066 } | |
2067 } | |
2068 DW_MUTEX_UNLOCK; | |
2069 } | |
2070 | |
2071 /* | |
2072 * Clears all text from an MLE box. | |
2073 * Parameters: | |
2074 * handle: Handle to the MLE to be cleared. | |
2075 */ | |
2076 void dw_mle_clear(HWND handle) | |
2077 { | |
2078 int length, _locked_by_me = FALSE; | |
2079 | |
2080 DW_MUTEX_LOCK; | |
2081 if(GTK_IS_BOX(handle)) | |
2082 { | |
2083 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
2084 | |
2085 if(tmp && GTK_IS_TEXT(tmp)) | |
2086 { | |
2087 length = gtk_text_get_length(GTK_TEXT(tmp)); | |
2088 gtk_text_set_point(GTK_TEXT(tmp), 0); | |
2089 gtk_text_forward_delete(GTK_TEXT(tmp), length); | |
2090 } | |
2091 } | |
2092 DW_MUTEX_UNLOCK; | |
2093 } | |
2094 | |
2095 /* | |
2096 * Sets the visible line of an MLE box. | |
2097 * Parameters: | |
2098 * handle: Handle to the MLE. | |
2099 * line: Line to be visible. | |
2100 */ | |
2101 void dw_mle_set_visible(HWND handle, int line) | |
2102 { | |
2103 int _locked_by_me = FALSE; | |
2104 | |
2105 DW_MUTEX_LOCK; | |
2106 if(GTK_IS_BOX(handle)) | |
2107 { | |
2108 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
2109 | |
2110 if(tmp && GTK_IS_TEXT(tmp)) | |
2111 { | |
2112 unsigned long lines; | |
2113 float pos, ratio; | |
2114 | |
2115 dw_mle_query(handle, NULL, &lines); | |
2116 | |
2117 if(lines) | |
2118 { | |
2119 ratio = (float)line/(float)lines; | |
2120 | |
2121 pos = (ratio * (float)(GTK_TEXT(tmp)->vadj->upper - GTK_TEXT(tmp)->vadj->lower)) + GTK_TEXT(tmp)->vadj->lower; | |
2122 | |
2123 gtk_adjustment_set_value(GTK_TEXT(tmp)->vadj, pos); | |
2124 } | |
2125 } | |
2126 } | |
2127 DW_MUTEX_UNLOCK; | |
2128 } | |
2129 | |
2130 /* | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2131 * Sets the editablity of an MLE box. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2132 * Parameters: |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2133 * handle: Handle to the MLE. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2134 * state: TRUE if it can be edited, FALSE for readonly. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2135 */ |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2136 void dw_mle_set_editable(HWND handle, int state) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2137 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2138 int _locked_by_me = FALSE; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2139 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2140 DW_MUTEX_LOCK; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2141 if(GTK_IS_BOX(handle)) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2142 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2143 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2144 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2145 if(tmp && GTK_IS_TEXT(tmp)) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2146 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2147 gtk_text_set_editable(GTK_TEXT(tmp), state); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2148 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2149 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2150 DW_MUTEX_UNLOCK; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2151 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2152 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2153 /* |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2154 * Sets the word wrap state of an MLE box. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2155 * Parameters: |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2156 * handle: Handle to the MLE. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2157 * state: TRUE if it wraps, FALSE if it doesn't. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2158 */ |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2159 void dw_mle_set_word_wrap(HWND handle, int state) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2160 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2161 int _locked_by_me = FALSE; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2162 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2163 DW_MUTEX_LOCK; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2164 if(GTK_IS_BOX(handle)) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2165 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2166 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2167 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2168 if(tmp && GTK_IS_TEXT(tmp)) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2169 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2170 gtk_text_set_word_wrap(GTK_TEXT(tmp), state); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2171 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2172 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2173 DW_MUTEX_UNLOCK; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2174 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2175 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2176 /* |
3 | 2177 * Sets the current cursor position of an MLE box. |
2178 * Parameters: | |
2179 * handle: Handle to the MLE to be positioned. | |
2180 * point: Point to position cursor. | |
2181 */ | |
2182 void dw_mle_set(HWND handle, int point) | |
2183 { | |
2184 int _locked_by_me = FALSE; | |
2185 | |
2186 DW_MUTEX_LOCK; | |
2187 if(GTK_IS_BOX(handle)) | |
2188 { | |
2189 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
2190 | |
2191 if(tmp && GTK_IS_TEXT(tmp)) | |
2192 { | |
2193 gtk_text_set_point(GTK_TEXT(tmp), point); | |
2194 } | |
2195 } | |
2196 DW_MUTEX_UNLOCK; | |
2197 } | |
2198 | |
2199 /* | |
2200 * Finds text in an MLE box. | |
2201 * Parameters: | |
2202 * handle: Handle to the MLE to be cleared. | |
2203 * text: Text to search for. | |
2204 * point: Start point of search. | |
2205 * flags: Search specific flags. | |
2206 */ | |
2207 int dw_mle_search(HWND handle, char *text, int point, unsigned long flags) | |
2208 { | |
2209 int _locked_by_me = FALSE, retval = 0; | |
2210 | |
2211 DW_MUTEX_LOCK; | |
2212 if(GTK_IS_BOX(handle)) | |
2213 { | |
2214 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
2215 | |
2216 if(tmp && GTK_IS_TEXT(tmp)) | |
2217 { | |
2218 int len = gtk_text_get_length(GTK_TEXT(tmp)); | |
2219 gchar *tmpbuf; | |
2220 | |
2221 tmpbuf = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), 0, len); | |
2222 if(tmpbuf) | |
2223 { | |
2224 int z, textlen; | |
2225 | |
2226 textlen = strlen(text); | |
2227 | |
2228 if(flags & DW_MLE_CASESENSITIVE) | |
2229 { | |
2230 for(z=point;z<(len-textlen) && !retval;z++) | |
2231 { | |
2232 if(strncmp(&tmpbuf[z], text, textlen) == 0) | |
2233 retval = z + textlen; | |
2234 } | |
2235 } | |
2236 else | |
2237 { | |
2238 for(z=point;z<(len-textlen) && !retval;z++) | |
2239 { | |
2240 if(strncasecmp(&tmpbuf[z], text, textlen) == 0) | |
2241 retval = z + textlen; | |
2242 } | |
2243 } | |
2244 | |
2245 if(retval) | |
2246 { | |
2247 gtk_text_set_point(GTK_TEXT(tmp), retval - textlen); | |
2248 gtk_editable_select_region(&(GTK_TEXT(tmp)->editable), retval - textlen, retval); | |
2249 } | |
2250 | |
2251 g_free(tmpbuf); | |
2252 } | |
2253 } | |
2254 } | |
2255 | |
2256 DW_MUTEX_UNLOCK; | |
2257 return retval; | |
2258 } | |
2259 | |
2260 /* | |
2261 * Stops redrawing of an MLE box. | |
2262 * Parameters: | |
2263 * handle: Handle to the MLE to freeze. | |
2264 */ | |
2265 void dw_mle_freeze(HWND handle) | |
2266 { | |
2267 int _locked_by_me = FALSE; | |
2268 | |
2269 DW_MUTEX_LOCK; | |
2270 if(GTK_IS_BOX(handle)) | |
2271 { | |
2272 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
2273 | |
2274 if(tmp && GTK_IS_TEXT(tmp)) | |
2275 { | |
2276 gtk_text_freeze(GTK_TEXT(tmp)); | |
2277 } | |
2278 } | |
2279 DW_MUTEX_UNLOCK; | |
2280 } | |
2281 | |
2282 /* | |
2283 * Resumes redrawing of an MLE box. | |
2284 * Parameters: | |
2285 * handle: Handle to the MLE to thaw. | |
2286 */ | |
2287 void dw_mle_thaw(HWND handle) | |
2288 { | |
2289 int _locked_by_me = FALSE; | |
2290 | |
2291 DW_MUTEX_LOCK; | |
2292 if(GTK_IS_BOX(handle)) | |
2293 { | |
2294 GtkWidget *tmp = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "mle"); | |
2295 | |
2296 if(tmp && GTK_IS_TEXT(tmp)) | |
2297 { | |
2298 gtk_text_thaw(GTK_TEXT(tmp)); | |
2299 } | |
2300 } | |
2301 DW_MUTEX_UNLOCK; | |
2302 } | |
2303 | |
2304 /* | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
30
diff
changeset
|
2305 * Returns the range of the percent bar. |
3 | 2306 * Parameters: |
2307 * handle: Handle to the slider to be queried. | |
2308 */ | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
30
diff
changeset
|
2309 unsigned int dw_percent_query_range(HWND handle) |
3 | 2310 { |
2311 return 100; | |
2312 } | |
2313 | |
2314 /* | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
30
diff
changeset
|
2315 * Sets the percent bar position. |
3 | 2316 * Parameters: |
2317 * handle: Handle to the slider to be set. | |
2318 * position: Position of the slider withing the range. | |
2319 */ | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
30
diff
changeset
|
2320 void dw_percent_set_pos(HWND handle, unsigned int position) |
3 | 2321 { |
2322 int _locked_by_me = FALSE; | |
2323 | |
2324 DW_MUTEX_LOCK; | |
2325 gtk_progress_bar_update(GTK_PROGRESS_BAR(handle), (gfloat)position/100); | |
2326 DW_MUTEX_UNLOCK; | |
2327 } | |
2328 | |
2329 /* | |
2330 * Sets the spinbutton value. | |
2331 * Parameters: | |
2332 * handle: Handle to the spinbutton to be set. | |
2333 * position: Current value of the spinbutton. | |
2334 */ | |
2335 void dw_spinbutton_set_pos(HWND handle, long position) | |
2336 { | |
2337 int _locked_by_me = FALSE; | |
2338 | |
2339 DW_MUTEX_LOCK; | |
2340 gtk_spin_button_set_value(GTK_SPIN_BUTTON(handle), (gfloat)position); | |
2341 DW_MUTEX_UNLOCK; | |
2342 } | |
2343 | |
2344 /* | |
2345 * Sets the spinbutton limits. | |
2346 * Parameters: | |
2347 * handle: Handle to the spinbutton to be set. | |
2348 * position: Current value of the spinbutton. | |
2349 * position: Current value of the spinbutton. | |
2350 */ | |
2351 void dw_spinbutton_set_limits(HWND handle, long upper, long lower) | |
2352 { | |
2353 long curval; | |
2354 GtkAdjustment *adj; | |
2355 int _locked_by_me = FALSE; | |
2356 | |
2357 curval = dw_spinbutton_query(handle); | |
2358 DW_MUTEX_LOCK; | |
2359 adj = (GtkAdjustment *)gtk_adjustment_new((gfloat)curval, (gfloat)lower, (gfloat)upper, 1.0, 5.0, 0.0); | |
2360 DW_MUTEX_UNLOCK; | |
2361 } | |
2362 | |
2363 /* | |
2364 * Sets the entryfield character limit. | |
2365 * Parameters: | |
2366 * handle: Handle to the spinbutton to be set. | |
2367 * limit: Number of characters the entryfield will take. | |
2368 */ | |
2369 void dw_entryfield_set_limit(HWND handle, ULONG limit) | |
2370 { | |
2371 /* TODO: can this be done after the fact? */ | |
2372 } | |
2373 | |
2374 /* | |
2375 * Returns the current value of the spinbutton. | |
2376 * Parameters: | |
2377 * handle: Handle to the spinbutton to be queried. | |
2378 */ | |
2379 long dw_spinbutton_query(HWND handle) | |
2380 { | |
2381 long retval; | |
2382 int _locked_by_me = FALSE; | |
2383 | |
2384 DW_MUTEX_LOCK; | |
2385 retval = (long)gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(handle)); | |
2386 DW_MUTEX_UNLOCK; | |
2387 | |
2388 return retval; | |
2389 } | |
2390 | |
2391 /* | |
2392 * Returns the state of the checkbox. | |
2393 * Parameters: | |
2394 * handle: Handle to the checkbox to be queried. | |
2395 */ | |
2396 int dw_checkbox_query(HWND handle) | |
2397 { | |
2398 int retval; | |
2399 int _locked_by_me = FALSE; | |
2400 | |
2401 DW_MUTEX_LOCK; | |
2402 retval = GTK_TOGGLE_BUTTON(handle)->active; | |
2403 DW_MUTEX_UNLOCK; | |
2404 | |
2405 return retval; | |
2406 } | |
2407 | |
2408 /* | |
2409 * Sets the state of the checkbox. | |
2410 * Parameters: | |
2411 * handle: Handle to the checkbox to be queried. | |
2412 * value: TRUE for checked, FALSE for unchecked. | |
2413 */ | |
2414 void dw_checkbox_set(HWND handle, int value) | |
2415 { | |
2416 int _locked_by_me = FALSE; | |
2417 | |
2418 DW_MUTEX_LOCK; | |
2419 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(handle), value); | |
2420 DW_MUTEX_UNLOCK; | |
2421 } | |
2422 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2423 /* |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2424 * Inserts an item into a tree window (widget). |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2425 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2426 * handle: Handle to the tree to be inserted. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2427 * title: The text title of the entry. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2428 * icon: Handle to coresponding icon. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2429 * parent: Parent handle or 0 if root. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2430 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2431 HWND dw_tree_insert(HWND handle, char *title, unsigned long icon, HWND parent) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2432 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2433 GtkWidget *item, *tree, *subtree, *label, *hbox, *pixmap; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2434 GdkPixmap *gdkpix; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2435 GdkBitmap *gdkbmp; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2436 int _locked_by_me = FALSE; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2437 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2438 DW_MUTEX_LOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2439 tree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2440 if(!tree || !GTK_IS_TREE(tree)) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2441 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2442 DW_MUTEX_UNLOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2443 return NULL; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2444 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2445 item = gtk_tree_item_new(); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2446 label = gtk_label_new(title); |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2447 gtk_object_set_data(GTK_OBJECT(item), "text", (gpointer)strdup(title)); |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2448 hbox = gtk_hbox_new(FALSE, 2); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2449 gdkpix = _find_pixmap(&gdkbmp, icon, hbox); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2450 pixmap = gtk_pixmap_new(gdkpix, gdkbmp); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2451 gtk_container_add(GTK_CONTAINER(item), hbox); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2452 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, TRUE, 0); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2453 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2454 gtk_widget_show(label); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2455 gtk_widget_show(pixmap); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2456 gtk_widget_show(hbox); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2457 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2458 if(parent) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2459 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2460 subtree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(parent)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2461 if(!subtree) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2462 { |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2463 void *thisfunc = (void *)gtk_object_get_data(GTK_OBJECT(tree), "select-child-func"); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2464 void *work = (void *)gtk_object_get_data(GTK_OBJECT(tree), "select-child-data"); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2465 |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2466 subtree = gtk_tree_new(); |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2467 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2468 if(thisfunc && work) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2469 gtk_signal_connect(GTK_OBJECT(subtree), "select-child", GTK_SIGNAL_FUNC(thisfunc), work); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2470 |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2471 gtk_object_set_user_data(GTK_OBJECT(parent), subtree); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2472 gtk_tree_set_selection_mode(GTK_TREE(subtree), GTK_SELECTION_SINGLE); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2473 gtk_tree_set_view_mode(GTK_TREE(subtree), GTK_TREE_VIEW_ITEM); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2474 gtk_tree_item_set_subtree(GTK_TREE_ITEM(parent), subtree); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2475 gtk_widget_show(subtree); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2476 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2477 gtk_tree_append(GTK_TREE(subtree), item); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2478 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2479 else |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2480 gtk_tree_append(GTK_TREE(tree), item); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2481 gtk_widget_show(item); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2482 DW_MUTEX_UNLOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2483 return item; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2484 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2485 |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2486 /* |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2487 * Removes all nodes from a tree. |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2488 * Parameters: |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2489 * handle: Handle to the window (widget) to be cleared. |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2490 */ |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2491 void dw_tree_clear(HWND handle) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2492 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2493 GtkWidget *tree; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2494 int _locked_by_me = FALSE; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2495 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2496 DW_MUTEX_LOCK; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2497 tree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2498 if(!tree || !GTK_IS_TREE(tree)) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2499 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2500 DW_MUTEX_UNLOCK; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2501 return; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2502 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2503 gtk_tree_clear_items(GTK_TREE(tree), 0, 1000000); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2504 DW_MUTEX_UNLOCK; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2505 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2506 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2507 /* |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2508 * Removes a node from a tree. |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2509 * Parameters: |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2510 * handle: Handle to the window (widget) to be cleared. |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2511 * item: Handle to node to be deleted. |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2512 */ |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2513 void dw_tree_delete(HWND handle, HWND item) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2514 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2515 GtkWidget *tree; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2516 int _locked_by_me = FALSE; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2517 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2518 DW_MUTEX_LOCK; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2519 tree = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2520 if(!tree || !GTK_IS_TREE(tree)) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2521 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2522 DW_MUTEX_UNLOCK; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2523 return; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2524 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2525 gtk_tree_remove_item(GTK_TREE(tree), item); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2526 DW_MUTEX_UNLOCK; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2527 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
2528 |
3 | 2529 int _dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator, int extra) |
2530 { | |
2531 GtkWidget *clist; | |
2532 char numbuf[10]; | |
2533 int z; | |
2534 int _locked_by_me = FALSE; | |
2535 | |
2536 DW_MUTEX_LOCK; | |
2537 clist = gtk_clist_new_with_titles(count, (gchar **)titles); | |
2538 if(!clist) | |
2539 { | |
2540 DW_MUTEX_UNLOCK; | |
2541 return FALSE; | |
2542 } | |
2543 | |
2544 gtk_signal_connect(GTK_OBJECT(clist), "select_row", GTK_SIGNAL_FUNC(_select_row), NULL); | |
2545 gtk_signal_connect(GTK_OBJECT(clist), "unselect_row", GTK_SIGNAL_FUNC(_unselect_row), NULL); | |
2546 | |
2547 gtk_clist_set_column_auto_resize(GTK_CLIST(clist), 0, TRUE); | |
2548 gtk_container_add(GTK_CONTAINER(handle), clist); | |
2549 gtk_object_set_user_data(GTK_OBJECT(handle), (gpointer)clist); | |
2550 gtk_widget_show(clist); | |
2551 gtk_object_set_data(GTK_OBJECT(clist), "colcount", (gpointer)count); | |
2552 | |
2553 if(extra) | |
2554 gtk_clist_set_column_width(GTK_CLIST(clist), 1, 120); | |
2555 | |
2556 for(z=0;z<count;z++) | |
2557 { | |
2558 if(!extra || z > 1) | |
2559 gtk_clist_set_column_width(GTK_CLIST(clist), z, 50); | |
2560 sprintf(numbuf, "%d", z); | |
2561 gtk_object_set_data(GTK_OBJECT(clist), numbuf, (gpointer)flags[z]); | |
2562 } | |
2563 | |
2564 DW_MUTEX_UNLOCK; | |
2565 return TRUE; | |
2566 } | |
2567 | |
2568 /* | |
2569 * Sets up the container columns. | |
2570 * Parameters: | |
2571 * handle: Handle to the container to be configured. | |
2572 * flags: An array of unsigned longs with column flags. | |
2573 * titles: An array of strings with column text titles. | |
2574 * count: The number of columns (this should match the arrays). | |
2575 * separator: The column number that contains the main separator. | |
2576 * (this item may only be used in OS/2) | |
2577 */ | |
2578 int dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) | |
2579 { | |
2580 return _dw_container_setup(handle, flags, titles, count, separator, 0); | |
2581 } | |
2582 | |
2583 /* | |
2584 * Sets up the filesystem columns, note: filesystem always has an icon/filename field. | |
2585 * Parameters: | |
2586 * handle: Handle to the container to be configured. | |
2587 * flags: An array of unsigned longs with column flags. | |
2588 * titles: An array of strings with column text titles. | |
2589 * count: The number of columns (this should match the arrays). | |
2590 */ | |
2591 int dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) | |
2592 { | |
2593 char **newtitles = malloc(sizeof(char *) * (count + 2)); | |
2594 unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 2)); | |
2595 | |
2596 newtitles[0] = "Icon"; | |
2597 newtitles[1] = "Filename"; | |
2598 | |
2599 newflags[0] = DW_CFA_BITMAPORICON | DW_CFA_CENTER | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR; | |
2600 newflags[1] = DW_CFA_STRING | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR; | |
2601 | |
2602 memcpy(&newtitles[2], titles, sizeof(char *) * count); | |
2603 memcpy(&newflags[2], flags, sizeof(unsigned long) * count); | |
2604 | |
2605 _dw_container_setup(handle, newflags, newtitles, count + 2, 2, 1); | |
2606 | |
2607 free(newtitles); | |
2608 free(newflags); | |
2609 return TRUE; | |
2610 } | |
2611 | |
2612 /* | |
2613 * Obtains an icon from a module (or header in GTK). | |
2614 * Parameters: | |
2615 * module: Handle to module (DLL) in OS/2 and Windows. | |
2616 * id: A unsigned long id int the resources on OS/2 and | |
2617 * Windows, on GTK this is converted to a pointer | |
2618 * to an embedded XPM. | |
2619 */ | |
2620 unsigned long dw_icon_load(unsigned long module, unsigned long id) | |
2621 { | |
2622 return id; | |
2623 } | |
2624 | |
2625 /* | |
2626 * Frees a loaded resource in OS/2 and Windows. | |
2627 * Parameters: | |
2628 * handle: Handle to icon returned by dw_icon_load(). | |
2629 */ | |
2630 void dw_icon_free(unsigned long handle) | |
2631 { | |
2632 } | |
2633 | |
2634 /* | |
2635 * Allocates memory used to populate a container. | |
2636 * Parameters: | |
2637 * handle: Handle to the container window (widget). | |
2638 * rowcount: The number of items to be populated. | |
2639 */ | |
2640 void *dw_container_alloc(HWND handle, int rowcount) | |
2641 { | |
2642 int z, count = 0; | |
2643 GtkWidget *clist; | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2644 GdkColor *fore, *back; |
3 | 2645 char **blah; |
2646 int _locked_by_me = FALSE; | |
2647 | |
2648 DW_MUTEX_LOCK; | |
2649 clist = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
2650 if(!clist) | |
2651 { | |
2652 DW_MUTEX_UNLOCK; | |
2653 return NULL; | |
2654 } | |
2655 | |
2656 count = (int)gtk_object_get_data(GTK_OBJECT(clist), "colcount"); | |
2657 | |
2658 if(!count) | |
2659 { | |
2660 DW_MUTEX_UNLOCK; | |
2661 return NULL; | |
2662 } | |
2663 | |
2664 blah = malloc(sizeof(char *) * count); | |
2665 memset(blah, 0, sizeof(char *) * count); | |
2666 | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2667 fore = (GdkColor *)gtk_object_get_data(GTK_OBJECT(clist), "foregdk"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2668 back = (GdkColor *)gtk_object_get_data(GTK_OBJECT(clist), "backgdk"); |
3 | 2669 gtk_clist_freeze(GTK_CLIST(clist)); |
2670 for(z=0;z<rowcount;z++) | |
2671 { | |
2672 gtk_clist_append(GTK_CLIST(clist), blah); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2673 if(fore) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2674 gtk_clist_set_foreground(GTK_CLIST(clist), z, fore); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2675 if(back) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2676 gtk_clist_set_background(GTK_CLIST(clist), z, back); |
3 | 2677 } |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2678 gtk_object_set_data(GTK_OBJECT(clist), "rowcount", (gpointer)rowcount); |
3 | 2679 free(blah); |
2680 DW_MUTEX_UNLOCK; | |
2681 return (void *)handle; | |
2682 } | |
2683 | |
2684 /* | |
2685 * Sets an item in specified row and column to the given data. | |
2686 * Parameters: | |
2687 * handle: Handle to the container window (widget). | |
2688 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
2689 * column: Zero based column of data being set. | |
2690 * row: Zero based row of data being set. | |
2691 * data: Pointer to the data to be added. | |
2692 */ | |
2693 void dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) | |
2694 { | |
2695 char numbuf[10], textbuffer[100]; | |
2696 int flag = 0; | |
2697 GtkWidget *clist; | |
2698 int _locked_by_me = FALSE; | |
2699 | |
2700 DW_MUTEX_LOCK; | |
2701 clist = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
2702 if(!clist) | |
2703 { | |
2704 DW_MUTEX_UNLOCK; | |
2705 return; | |
2706 } | |
2707 | |
2708 sprintf(numbuf, "%d", column); | |
2709 flag = (int)gtk_object_get_data(GTK_OBJECT(clist), numbuf); | |
2710 | |
2711 if(flag & DW_CFA_BITMAPORICON) | |
2712 { | |
2713 long hicon = *((long *)data); | |
2714 GdkBitmap *bitmap; | |
2715 GdkPixmap *pixmap = _find_pixmap(&bitmap, hicon, clist); | |
2716 | |
2717 if(pixmap) | |
2718 gtk_clist_set_pixmap(GTK_CLIST(clist), row, column, pixmap, bitmap); | |
2719 } | |
2720 else if(flag & DW_CFA_STRING) | |
2721 { | |
2722 char *tmp = *((char **)data); | |
2723 gtk_clist_set_text(GTK_CLIST(clist), row, column, tmp); | |
2724 } | |
2725 else if(flag & DW_CFA_ULONG) | |
2726 { | |
2727 ULONG tmp = *((ULONG *)data); | |
2728 | |
2729 sprintf(textbuffer, "%lu", tmp); | |
2730 | |
2731 gtk_clist_set_text(GTK_CLIST(clist), row, column, textbuffer); | |
2732 } | |
2733 else if(flag & DW_CFA_DATE) | |
2734 { | |
2735 CDATE fdate = *((CDATE *)data); | |
2736 | |
2737 sprintf(textbuffer, "%s %d, %d", monthlist[fdate.month], fdate.day, fdate.year); | |
2738 gtk_clist_set_text(GTK_CLIST(clist), row, column, textbuffer); | |
2739 } | |
2740 else if(flag & DW_CFA_TIME) | |
2741 { | |
2742 CTIME ftime = *((CTIME *)data); | |
2743 | |
2744 if(ftime.hours > 12) | |
2745 sprintf(textbuffer, "%d:%s%dpm", ftime.hours - 12, (ftime.minutes < 10) ? "0" : "", ftime.minutes); | |
2746 else | |
2747 sprintf(textbuffer, "%d:%s%dam", ftime.hours ? ftime.hours : 12, (ftime.minutes < 10) ? "0" : "", ftime.minutes); | |
2748 gtk_clist_set_text(GTK_CLIST(clist), row, column, textbuffer); | |
2749 } | |
2750 DW_MUTEX_UNLOCK; | |
2751 } | |
2752 | |
2753 /* | |
2754 * Sets an item in specified row and column to the given data. | |
2755 * Parameters: | |
2756 * handle: Handle to the container window (widget). | |
2757 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
2758 * column: Zero based column of data being set. | |
2759 * row: Zero based row of data being set. | |
2760 * data: Pointer to the data to be added. | |
2761 */ | |
2762 void dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) | |
2763 { | |
2764 dw_container_set_item(handle, pointer, 0, row, (void *)&icon); | |
2765 dw_container_set_item(handle, pointer, 1, row, (void *)&filename); | |
2766 } | |
2767 | |
2768 /* | |
2769 * Sets an item in specified row and column to the given data. | |
2770 * Parameters: | |
2771 * handle: Handle to the container window (widget). | |
2772 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
2773 * column: Zero based column of data being set. | |
2774 * row: Zero based row of data being set. | |
2775 * data: Pointer to the data to be added. | |
2776 */ | |
2777 void dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) | |
2778 { | |
2779 dw_container_set_item(handle, pointer, column + 2, row, data); | |
2780 } | |
2781 | |
2782 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2783 * Sets the width of a column in the container. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2784 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2785 * handle: Handle to window (widget) of container. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2786 * column: Zero based column of width being set. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2787 * width: Width of column in pixels. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2788 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2789 void dw_container_set_column_width(HWND handle, int column, int width) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2790 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2791 GtkWidget *clist; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2792 int _locked_by_me = FALSE; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2793 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2794 DW_MUTEX_LOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2795 clist = gtk_object_get_user_data(GTK_OBJECT(handle)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2796 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2797 if(clist && GTK_IS_CLIST(clist)) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2798 gtk_clist_set_column_width(GTK_CLIST(clist), column, width); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2799 DW_MUTEX_UNLOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2800 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2801 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2802 /* |
3 | 2803 * Sets the title of a row in the container. |
2804 * Parameters: | |
2805 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
2806 * row: Zero based row of data being set. | |
2807 * title: String title of the item. | |
2808 */ | |
2809 void dw_container_set_row_title(void *pointer, int row, char *title) | |
2810 { | |
2811 GtkWidget *clist; | |
2812 int _locked_by_me = FALSE; | |
2813 | |
2814 DW_MUTEX_LOCK; | |
2815 clist = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(pointer)); | |
2816 | |
2817 if(clist) | |
2818 gtk_clist_set_row_data(GTK_CLIST(clist), row, (gpointer)title); | |
2819 DW_MUTEX_UNLOCK; | |
2820 } | |
2821 | |
2822 /* | |
2823 * Sets the title of a row in the container. | |
2824 * Parameters: | |
2825 * handle: Handle to the container window (widget). | |
2826 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
2827 * rowcount: The number of rows to be inserted. | |
2828 */ | |
2829 void dw_container_insert(HWND handle, void *pointer, int rowcount) | |
2830 { | |
2831 GtkWidget *clist; | |
2832 int _locked_by_me = FALSE; | |
2833 | |
2834 DW_MUTEX_LOCK; | |
2835 clist = gtk_object_get_user_data(GTK_OBJECT(handle)); | |
2836 | |
2837 if(clist && GTK_IS_CLIST(clist)) | |
2838 gtk_clist_thaw(GTK_CLIST(clist)); | |
2839 DW_MUTEX_UNLOCK; | |
2840 } | |
2841 | |
2842 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2843 * Removes the first x rows from a container. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2844 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2845 * handle: Handle to the window (widget) to be deleted from. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2846 * rowcount: The number of rows to be deleted. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2847 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2848 void dw_container_delete(HWND handle, int rowcount) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2849 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2850 GtkWidget *clist; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2851 GList *list; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2852 int _locked_by_me = FALSE; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2853 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2854 DW_MUTEX_LOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2855 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2856 if(clist && GTK_IS_CLIST(clist)) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2857 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2858 int rows, z; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2859 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2860 list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "selectlist"); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2861 rows = (int)gtk_object_get_data(GTK_OBJECT(clist), "rowcount"); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2862 g_list_free(list); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2863 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2864 for(z=0;z<rowcount;z++) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2865 gtk_clist_remove(GTK_CLIST(clist), 0); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2866 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2867 if(rows - rowcount < 0) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2868 rows = 0; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2869 else |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2870 rows -= rowcount; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2871 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2872 gtk_object_set_data(GTK_OBJECT(clist), "selectlist", NULL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2873 gtk_object_set_data(GTK_OBJECT(clist), "rowcount", (gpointer)rows); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2874 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2875 DW_MUTEX_UNLOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2876 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2877 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2878 /* |
3 | 2879 * Removes all rows from a container. |
2880 * Parameters: | |
2881 * handle: Handle to the window (widget) to be cleared. | |
2882 */ | |
2883 void dw_container_clear(HWND handle) | |
2884 { | |
2885 GtkWidget *clist; | |
2886 GList *list; | |
2887 int _locked_by_me = FALSE; | |
2888 | |
2889 DW_MUTEX_LOCK; | |
2890 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
2891 if(clist && GTK_IS_CLIST(clist)) | |
2892 { | |
2893 list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "selectlist"); | |
2894 g_list_free(list); | |
2895 gtk_object_set_data(GTK_OBJECT(clist), "selectlist", NULL); | |
2896 gtk_clist_clear(GTK_CLIST(clist)); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2897 gtk_object_set_data(GTK_OBJECT(clist), "rowcount", (gpointer)0); |
3 | 2898 } |
2899 DW_MUTEX_UNLOCK; | |
2900 } | |
2901 | |
2902 /* | |
2903 * Removes all rows from a container. | |
2904 * Parameters: | |
2905 * handle: Handle to the window (widget) to be cleared. | |
2906 */ | |
2907 void dw_container_set_view(HWND handle, unsigned long flags, int iconwidth, int iconheight) | |
2908 { | |
2909 } | |
2910 | |
2911 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2912 * Scrolls container up or down. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2913 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2914 * handle: Handle to the window (widget) to be scrolled. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2915 * direction: DW_SCROLL_UP, DW_SCROLL_DOWN, DW_SCROLL_TOP or |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2916 * DW_SCROLL_BOTTOM. (rows is ignored for last two) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2917 * rows: The number of rows to be scrolled. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2918 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2919 void dw_container_scroll(HWND handle, int direction, long rows) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2920 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2921 GtkAdjustment *adj; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2922 GtkWidget *clist; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2923 int _locked_by_me = FALSE; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2924 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2925 DW_MUTEX_LOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2926 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2927 if(clist && GTK_IS_CLIST(clist)) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2928 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2929 adj = gtk_clist_get_vadjustment(GTK_CLIST(clist)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2930 if(adj) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2931 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2932 switch(direction) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2933 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2934 case DW_SCROLL_TOP: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2935 adj->value = adj->lower; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2936 break; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2937 case DW_SCROLL_BOTTOM: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2938 adj->value = adj->upper; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2939 break; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2940 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2941 gtk_clist_set_vadjustment(GTK_CLIST(clist), adj); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2942 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2943 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2944 DW_MUTEX_UNLOCK; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2945 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2946 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
2947 /* |
3 | 2948 * Starts a new query of a container. |
2949 * Parameters: | |
2950 * handle: Handle to the window (widget) to be queried. | |
2951 * flags: If this parameter is DW_CRA_SELECTED it will only | |
2952 * return items that are currently selected. Otherwise | |
2953 * it will return all records in the container. | |
2954 */ | |
2955 char *dw_container_query_start(HWND handle, unsigned long flags) | |
2956 { | |
2957 GtkWidget *clist; | |
2958 GList *list; | |
2959 char *retval = NULL; | |
2960 int _locked_by_me = FALSE; | |
2961 | |
2962 DW_MUTEX_LOCK; | |
2963 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
2964 | |
2965 if(!clist) | |
2966 { | |
2967 DW_MUTEX_UNLOCK; | |
2968 return NULL; | |
2969 } | |
2970 | |
2971 /* If there is an old query list, free it */ | |
2972 list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "querylist"); | |
2973 if(list) | |
2974 g_list_free(list); | |
2975 | |
2976 /* Move the current selection list to the query list, and remove the | |
2977 * current selection list. | |
2978 */ | |
2979 list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "selectlist"); | |
2980 gtk_object_set_data(GTK_OBJECT(clist), "selectlist", NULL); | |
2981 gtk_object_set_data(GTK_OBJECT(clist), "querylist", (gpointer)list); | |
2982 gtk_clist_unselect_all(GTK_CLIST(clist)); | |
2983 | |
2984 if(list) | |
2985 { | |
2986 gtk_object_set_data(GTK_OBJECT(clist), "querypos", (gpointer)1); | |
2987 if(list->data) | |
2988 retval = list->data; | |
2989 else | |
2990 retval = ""; | |
2991 } | |
2992 DW_MUTEX_UNLOCK; | |
2993 return retval; | |
2994 } | |
2995 | |
2996 /* | |
2997 * Continues an existing query of a container. | |
2998 * Parameters: | |
2999 * handle: Handle to the window (widget) to be queried. | |
3000 * flags: If this parameter is DW_CRA_SELECTED it will only | |
3001 * return items that are currently selected. Otherwise | |
3002 * it will return all records in the container. | |
3003 */ | |
3004 char *dw_container_query_next(HWND handle, unsigned long flags) | |
3005 { | |
3006 GtkWidget *clist; | |
3007 GList *list; | |
3008 char *retval = NULL; | |
3009 int _locked_by_me = FALSE; | |
3010 | |
3011 DW_MUTEX_LOCK; | |
3012 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
3013 | |
3014 if(!clist) | |
3015 { | |
3016 DW_MUTEX_UNLOCK; | |
3017 return NULL; | |
3018 } | |
3019 | |
3020 list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "querylist"); | |
3021 | |
3022 if(list) | |
3023 { | |
3024 int counter = 0, pos = (int)gtk_object_get_data(GTK_OBJECT(clist), "querypos"); | |
3025 gtk_object_set_data(GTK_OBJECT(clist), "querypos", (gpointer)pos+1); | |
3026 | |
3027 while(list && counter < pos) | |
3028 { | |
3029 list = list->next; | |
3030 counter++; | |
3031 } | |
3032 | |
3033 if(list && list->data) | |
3034 retval = list->data; | |
3035 else if(list && !list->data) | |
3036 retval = ""; | |
3037 } | |
3038 DW_MUTEX_UNLOCK; | |
3039 return retval; | |
3040 } | |
3041 | |
3042 /* | |
3043 * Creates a rendering context widget (window) to be packed. | |
3044 * Parameters: | |
3045 * id: An id to be used with dw_window_from_id. | |
3046 * Returns: | |
3047 * A handle to the widget or NULL on failure. | |
3048 */ | |
3049 HWND dw_render_new(unsigned long id) | |
3050 { | |
3051 int _locked_by_me = FALSE; | |
3052 GtkWidget *tmp; | |
3053 | |
3054 DW_MUTEX_LOCK; | |
3055 tmp = gtk_drawing_area_new(); | |
3056 gtk_widget_set_events(tmp, GDK_EXPOSURE_MASK | |
3057 | GDK_LEAVE_NOTIFY_MASK | |
3058 | GDK_BUTTON_PRESS_MASK | |
3059 | GDK_POINTER_MOTION_MASK | |
3060 | GDK_POINTER_MOTION_HINT_MASK); | |
3061 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); | |
3062 gtk_widget_show(tmp); | |
3063 DW_MUTEX_UNLOCK; | |
3064 return tmp; | |
3065 } | |
3066 | |
3067 /* Sets the current foreground drawing color. | |
3068 * Parameters: | |
3069 * red: red value. | |
3070 * green: green value. | |
3071 * blue: blue value. | |
3072 */ | |
3073 void dw_color_foreground_set(unsigned long value) | |
3074 { | |
3075 int _locked_by_me = FALSE; | |
3076 GdkColor color = { 0, DW_RED_VALUE(value) << 8, DW_GREEN_VALUE(value) << 8, DW_BLUE_VALUE(value) << 8 }; | |
3077 | |
3078 DW_MUTEX_LOCK; | |
3079 gdk_color_alloc(_dw_cmap, &color); | |
3080 _foreground = color; | |
3081 DW_MUTEX_UNLOCK; | |
3082 } | |
3083 | |
3084 /* Sets the current background drawing color. | |
3085 * Parameters: | |
3086 * red: red value. | |
3087 * green: green value. | |
3088 * blue: blue value. | |
3089 */ | |
3090 void dw_color_background_set(unsigned long value) | |
3091 { | |
3092 int _locked_by_me = FALSE; | |
3093 GdkColor color = { 0, DW_RED_VALUE(value) << 8, DW_GREEN_VALUE(value) << 8, DW_BLUE_VALUE(value) << 8 }; | |
3094 | |
3095 DW_MUTEX_LOCK; | |
3096 gdk_color_alloc(_dw_cmap, &color); | |
3097 _background = color; | |
3098 DW_MUTEX_UNLOCK; | |
3099 } | |
3100 | |
3101 GdkGC *_set_colors(GdkWindow *window) | |
3102 { | |
3103 GdkGC *gc; | |
3104 if(!window) | |
3105 return NULL; | |
3106 gc = gdk_gc_new(window); | |
3107 if(gc) | |
3108 { | |
3109 gdk_gc_set_foreground(gc, &_foreground); | |
3110 gdk_gc_set_background(gc, &_background); | |
3111 } | |
3112 return gc; | |
3113 } | |
3114 | |
3115 /* Draw a point on a window (preferably a render window). | |
3116 * Parameters: | |
3117 * handle: Handle to the window. | |
3118 * pixmap: Handle to the pixmap. (choose only one of these) | |
3119 * x: X coordinate. | |
3120 * y: Y coordinate. | |
3121 */ | |
3122 void dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) | |
3123 { | |
3124 int _locked_by_me = FALSE; | |
3125 GdkGC *gc = NULL; | |
3126 | |
3127 DW_MUTEX_LOCK; | |
3128 if(handle) | |
3129 gc = _set_colors(handle->window); | |
3130 else if(pixmap) | |
3131 gc = _set_colors(pixmap->pixmap); | |
3132 if(gc) | |
3133 { | |
3134 gdk_draw_point(handle ? handle->window : pixmap->pixmap, gc, x, y); | |
3135 gdk_gc_unref(gc); | |
3136 } | |
3137 DW_MUTEX_UNLOCK; | |
3138 } | |
3139 | |
3140 /* Draw a line on a window (preferably a render window). | |
3141 * Parameters: | |
3142 * handle: Handle to the window. | |
3143 * pixmap: Handle to the pixmap. (choose only one of these) | |
3144 * x1: First X coordinate. | |
3145 * y1: First Y coordinate. | |
3146 * x2: Second X coordinate. | |
3147 * y2: Second Y coordinate. | |
3148 */ | |
3149 void dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) | |
3150 { | |
3151 int _locked_by_me = FALSE; | |
3152 GdkGC *gc = NULL; | |
3153 | |
3154 DW_MUTEX_LOCK; | |
3155 if(handle) | |
3156 gc = _set_colors(handle->window); | |
3157 else if(pixmap) | |
3158 gc = _set_colors(pixmap->pixmap); | |
3159 if(gc) | |
3160 { | |
3161 gdk_draw_line(handle ? handle->window : pixmap->pixmap, gc, x1, y1, x2, y2); | |
3162 gdk_gc_unref(gc); | |
3163 } | |
3164 DW_MUTEX_UNLOCK; | |
3165 } | |
3166 | |
3167 /* Draw a rectangle on a window (preferably a render window). | |
3168 * Parameters: | |
3169 * handle: Handle to the window. | |
3170 * pixmap: Handle to the pixmap. (choose only one of these) | |
3171 * x: X coordinate. | |
3172 * y: Y coordinate. | |
3173 * width: Width of rectangle. | |
3174 * height: Height of rectangle. | |
3175 */ | |
3176 void dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) | |
3177 { | |
3178 int _locked_by_me = FALSE; | |
3179 GdkGC *gc = NULL; | |
3180 | |
3181 DW_MUTEX_LOCK; | |
3182 if(handle) | |
3183 gc = _set_colors(handle->window); | |
3184 else if(pixmap) | |
3185 gc = _set_colors(pixmap->pixmap); | |
3186 if(gc) | |
3187 { | |
3188 gdk_draw_rectangle(handle ? handle->window : pixmap->pixmap, gc, fill, x, y, width, height); | |
3189 gdk_gc_unref(gc); | |
3190 } | |
3191 DW_MUTEX_UNLOCK; | |
3192 } | |
3193 | |
3194 /* Draw text on a window (preferably a render window). | |
3195 * Parameters: | |
3196 * handle: Handle to the window. | |
3197 * pixmap: Handle to the pixmap. (choose only one of these) | |
3198 * x: X coordinate. | |
3199 * y: Y coordinate. | |
3200 * text: Text to be displayed. | |
3201 */ | |
3202 void dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) | |
3203 { | |
3204 int _locked_by_me = FALSE; | |
3205 GdkGC *gc = NULL; | |
3206 GdkFont *font; | |
3207 char *fontname = "fixed"; | |
3208 | |
3209 DW_MUTEX_LOCK; | |
3210 if(handle) | |
3211 { | |
3212 fontname = (char *)gtk_object_get_data(GTK_OBJECT(handle), "fontname"); | |
3213 gc = _set_colors(handle->window); | |
3214 } | |
3215 else if(pixmap) | |
3216 { | |
3217 fontname = (char *)gtk_object_get_data(GTK_OBJECT(pixmap->handle), "fontname"); | |
3218 gc = _set_colors(pixmap->pixmap); | |
3219 } | |
3220 if(gc) | |
3221 { | |
3222 font = gdk_font_load(fontname); | |
3223 if(font) | |
3224 { | |
3225 gint ascent; | |
3226 | |
3227 gdk_text_extents(font, text, strlen(text), NULL, NULL, NULL, &ascent, NULL); | |
3228 gdk_draw_text(handle ? handle->window : pixmap->pixmap, font, gc, x, y + ascent, text, strlen(text)); | |
3229 gdk_gc_unref(gc); | |
3230 gdk_font_unref(font); | |
3231 } | |
3232 } | |
3233 DW_MUTEX_UNLOCK; | |
3234 } | |
3235 | |
3236 /* | |
3237 * Creates a pixmap with given parameters. | |
3238 * Parameters: | |
3239 * handle: Window handle the pixmap is associated with. | |
3240 * width: Width of the pixmap in pixels. | |
3241 * height: Height of the pixmap in pixels. | |
3242 * depth: Color depth of the pixmap. | |
3243 * Returns: | |
3244 * A handle to a pixmap or NULL on failure. | |
3245 */ | |
3246 HPIXMAP dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) | |
3247 { | |
3248 int _locked_by_me = FALSE; | |
3249 HPIXMAP pixmap; | |
3250 | |
3251 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
3252 return NULL; | |
3253 | |
3254 if (!depth) | |
3255 depth = 24; | |
3256 | |
3257 pixmap->width = width; pixmap->height = height; | |
3258 | |
3259 | |
3260 DW_MUTEX_LOCK; | |
3261 pixmap->handle = handle; | |
3262 pixmap->pixmap = gdk_pixmap_new(handle->window, width, height, depth); | |
3263 DW_MUTEX_UNLOCK; | |
3264 return pixmap; | |
3265 } | |
3266 | |
3267 /* | |
3268 * Creates a pixmap from internal resource graphic specified by id. | |
3269 * Parameters: | |
3270 * handle: Window handle the pixmap is associated with. | |
3271 * id: Resource ID associated with requested pixmap. | |
3272 * Returns: | |
3273 * A handle to a pixmap or NULL on failure. | |
3274 */ | |
3275 HPIXMAP dw_pixmap_grab(HWND handle, ULONG id) | |
3276 { | |
3277 GdkBitmap *bitmap; | |
3278 HPIXMAP pixmap; | |
3279 int _locked_by_me = FALSE; | |
3280 | |
3281 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
3282 return NULL; | |
3283 | |
3284 | |
3285 DW_MUTEX_LOCK; | |
3286 pixmap->pixmap = _find_pixmap(&bitmap, id, handle); | |
3287 if(pixmap->pixmap) | |
3288 { | |
3289 GdkPixmapPrivate *pvt = (GdkPixmapPrivate *)pixmap->pixmap; | |
3290 pixmap->width = pvt->width; pixmap->height = pvt->height; | |
3291 } | |
3292 DW_MUTEX_UNLOCK; | |
3293 return pixmap; | |
3294 } | |
3295 | |
3296 /* Call this after drawing to the screen to make sure | |
3297 * anything you have drawn is visible. | |
3298 */ | |
3299 void dw_flush(void) | |
3300 { | |
3301 int _locked_by_me = FALSE; | |
3302 | |
3303 DW_MUTEX_LOCK; | |
3304 gdk_flush(); | |
3305 DW_MUTEX_UNLOCK; | |
3306 } | |
3307 | |
3308 /* | |
3309 * Destroys an allocated pixmap. | |
3310 * Parameters: | |
3311 * pixmap: Handle to a pixmap returned by | |
3312 * dw_pixmap_new.. | |
3313 */ | |
3314 void dw_pixmap_destroy(HPIXMAP pixmap) | |
3315 { | |
3316 int _locked_by_me = FALSE; | |
3317 | |
3318 DW_MUTEX_LOCK; | |
3319 gdk_pixmap_unref(pixmap->pixmap); | |
3320 free(pixmap); | |
3321 DW_MUTEX_UNLOCK; | |
3322 } | |
3323 | |
3324 /* | |
3325 * Copies from one item to another. | |
3326 * Parameters: | |
3327 * dest: Destination window handle. | |
3328 * destp: Destination pixmap. (choose only one). | |
3329 * xdest: X coordinate of destination. | |
3330 * ydest: Y coordinate of destination. | |
3331 * width: Width of area to copy. | |
3332 * height: Height of area to copy. | |
3333 * src: Source window handle. | |
3334 * srcp: Source pixmap. (choose only one). | |
3335 * xsrc: X coordinate of source. | |
3336 * ysrc: Y coordinate of source. | |
3337 */ | |
3338 void dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) | |
3339 { | |
3340 int _locked_by_me = FALSE; | |
3341 GdkGC *gc = NULL; | |
3342 | |
3343 if((!dest && !destp) || (!src && !srcp)) | |
3344 return; | |
3345 | |
3346 DW_MUTEX_LOCK; | |
3347 if(dest) | |
3348 gc = _set_colors(dest->window); | |
3349 else if(src) | |
3350 gc = _set_colors(src->window); | |
3351 else if(destp) | |
3352 gc = gdk_gc_new(destp->pixmap); | |
3353 else if(srcp) | |
3354 gc = gdk_gc_new(srcp->pixmap); | |
3355 | |
3356 if(gc) | |
3357 { | |
3358 gdk_draw_pixmap(dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height); | |
3359 gdk_gc_unref(gc); | |
3360 } | |
3361 DW_MUTEX_UNLOCK; | |
3362 } | |
3363 | |
3364 /* | |
3365 * Emits a beep. | |
3366 * Parameters: | |
3367 * freq: Frequency. | |
3368 * dur: Duration. | |
3369 */ | |
3370 void dw_beep(int freq, int dur) | |
3371 { | |
3372 int _locked_by_me = FALSE; | |
3373 | |
3374 DW_MUTEX_LOCK; | |
3375 gdk_beep(); | |
3376 DW_MUTEX_UNLOCK; | |
3377 } | |
3378 | |
3379 /* | |
3380 * Returns the handle to an unnamed mutex semaphore. | |
3381 */ | |
3382 HMTX dw_mutex_new(void) | |
3383 { | |
3384 HMTX mutex; | |
3385 | |
3386 pthread_mutex_init(&mutex, NULL); | |
3387 return mutex; | |
3388 } | |
3389 | |
3390 /* | |
3391 * Closes a semaphore created by dw_mutex_new(). | |
3392 * Parameters: | |
3393 * mutex: The handle to the mutex returned by dw_mutex_new(). | |
3394 */ | |
3395 void dw_mutex_close(HMTX mutex) | |
3396 { | |
3397 pthread_mutex_destroy(&mutex); | |
3398 } | |
3399 | |
3400 /* | |
3401 * Tries to gain access to the semaphore, if it can't it blocks. | |
3402 * Parameters: | |
3403 * mutex: The handle to the mutex returned by dw_mutex_new(). | |
3404 */ | |
3405 void dw_mutex_lock(HMTX mutex) | |
3406 { | |
3407 pthread_mutex_lock(&mutex); | |
3408 } | |
3409 | |
3410 /* | |
3411 * Reliquishes the access to the semaphore. | |
3412 * Parameters: | |
3413 * mutex: The handle to the mutex returned by dw_mutex_new(). | |
3414 */ | |
3415 void dw_mutex_unlock(HMTX mutex) | |
3416 { | |
3417 pthread_mutex_unlock(&mutex); | |
3418 } | |
3419 | |
3420 /* | |
3421 * Returns the handle to an unnamed event semaphore. | |
3422 */ | |
3423 HEV dw_event_new(void) | |
3424 { | |
3425 HEV eve = (HEV)malloc(sizeof(struct _dw_unix_event)); | |
3426 | |
3427 if(!eve) | |
3428 return NULL; | |
3429 | |
3430 /* We need to be careful here, mutexes on Linux are | |
3431 * FAST by default but are error checking on other | |
3432 * systems such as FreeBSD and OS/2, perhaps others. | |
3433 */ | |
3434 pthread_mutex_init (&(eve->mutex), NULL); | |
3435 pthread_mutex_lock (&(eve->mutex)); | |
3436 pthread_cond_init (&(eve->event), NULL); | |
3437 | |
3438 pthread_mutex_unlock (&(eve->mutex)); | |
3439 eve->alive = 1; | |
3440 eve->posted = 0; | |
3441 | |
3442 return eve; | |
3443 } | |
3444 | |
3445 /* | |
3446 * Resets a semaphore created by dw_event_new(). | |
3447 * Parameters: | |
3448 * eve: The handle to the event returned by dw_event_new(). | |
3449 */ | |
3450 int dw_event_reset (HEV eve) | |
3451 { | |
3452 if(!eve) | |
3453 return FALSE; | |
3454 | |
3455 pthread_mutex_lock (&(eve->mutex)); | |
3456 pthread_cond_broadcast (&(eve->event)); | |
3457 pthread_cond_init (&(eve->event), NULL); | |
3458 eve->posted = 0; | |
3459 pthread_mutex_unlock (&(eve->mutex)); | |
3460 return 0; | |
3461 } | |
3462 | |
3463 /* | |
3464 * Posts a semaphore created by dw_event_new(). Causing all threads | |
3465 * waiting on this event in dw_event_wait to continue. | |
3466 * Parameters: | |
3467 * eve: The handle to the event returned by dw_event_new(). | |
3468 */ | |
3469 int dw_event_post (HEV eve) | |
3470 { | |
3471 if(!eve) | |
3472 return FALSE; | |
3473 | |
3474 pthread_mutex_lock (&(eve->mutex)); | |
3475 pthread_cond_broadcast (&(eve->event)); | |
3476 eve->posted = 1; | |
3477 pthread_mutex_unlock (&(eve->mutex)); | |
3478 return 0; | |
3479 } | |
3480 | |
3481 /* | |
3482 * Waits on a semaphore created by dw_event_new(), until the | |
3483 * event gets posted or until the timeout expires. | |
3484 * Parameters: | |
3485 * eve: The handle to the event returned by dw_event_new(). | |
3486 */ | |
3487 int dw_event_wait(HEV eve, unsigned long timeout) | |
3488 { | |
3489 int rc; | |
3490 struct timeval now; | |
3491 struct timespec timeo; | |
3492 | |
3493 if(!eve) | |
3494 return FALSE; | |
3495 | |
3496 if(eve->posted) | |
3497 return 0; | |
3498 | |
3499 pthread_mutex_lock (&(eve->mutex)); | |
3500 gettimeofday(&now, 0); | |
3501 timeo.tv_sec = now.tv_sec + (timeout / 1000); | |
3502 timeo.tv_nsec = now.tv_usec * 1000; | |
3503 rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo); | |
3504 pthread_mutex_unlock (&(eve->mutex)); | |
3505 if(!rc) | |
3506 return 1; | |
3507 if(rc == ETIMEDOUT) | |
3508 return -1; | |
3509 return 0; | |
3510 } | |
3511 | |
3512 /* | |
3513 * Closes a semaphore created by dw_event_new(). | |
3514 * Parameters: | |
3515 * eve: The handle to the event returned by dw_event_new(). | |
3516 */ | |
3517 int dw_event_close(HEV *eve) | |
3518 { | |
3519 if(!eve || !(*eve)) | |
3520 return FALSE; | |
3521 | |
3522 pthread_mutex_lock (&((*eve)->mutex)); | |
3523 pthread_cond_destroy (&((*eve)->event)); | |
3524 pthread_mutex_unlock (&((*eve)->mutex)); | |
3525 pthread_mutex_destroy (&((*eve)->mutex)); | |
3526 free(*eve); | |
3527 *eve = NULL; | |
3528 | |
3529 return TRUE; | |
3530 } | |
3531 | |
3532 /* | |
3533 * Creates a new thread with a starting point of func. | |
3534 * Parameters: | |
3535 * func: Function which will be run in the new thread. | |
3536 * data: Parameter(s) passed to the function. | |
3537 * stack: Stack size of new thread (OS/2 and Windows only). | |
3538 */ | |
3539 DWTID dw_thread_new(void *func, void *data, int stack) | |
3540 { | |
3541 DWTID gtkthread; | |
3542 | |
3543 pthread_create(>kthread, NULL, func, data); | |
3544 return gtkthread; | |
3545 } | |
3546 | |
3547 /* | |
3548 * Ends execution of current thread immediately. | |
3549 */ | |
3550 void dw_thread_end(void) | |
3551 { | |
3552 pthread_exit(NULL); | |
3553 } | |
3554 | |
3555 /* | |
3556 * Cleanly terminates a DW session, should be signal handler safe. | |
3557 * Parameters: | |
3558 * exitcode: Exit code reported to the operating system. | |
3559 */ | |
3560 void dw_exit(int exitcode) | |
3561 { | |
3562 exit(exitcode); | |
3563 } | |
3564 | |
3565 /* | |
3566 * Pack windows (widgets) into a box from the end (or bottom). | |
3567 * Parameters: | |
3568 * box: Window handle of the box to be packed into. | |
3569 * item: Window handle of the item to be back. | |
3570 * width: Width in pixels of the item or -1 to be self determined. | |
3571 * height: Height in pixels of the item or -1 to be self determined. | |
3572 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | |
3573 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | |
3574 * pad: Number of pixels of padding around the item. | |
3575 */ | |
3576 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | |
3577 { | |
3578 int expand = (hsize == FALSE && vsize == FALSE) ? FALSE : TRUE; | |
3579 int _locked_by_me = FALSE; | |
3580 | |
3581 if(!box) | |
3582 return; | |
3583 | |
3584 DW_MUTEX_LOCK; | |
3585 | |
3586 if(!item) | |
3587 { | |
3588 item = gtk_label_new(""); | |
3589 gtk_widget_show(item); | |
3590 } | |
3591 | |
3592 if(GTK_IS_BOX(box)) | |
3593 { | |
3594 gtk_box_pack_end(GTK_BOX(box), item, expand, TRUE, pad); | |
3595 gtk_widget_set_usize(item, width, height); | |
3596 if(GTK_IS_RADIO_BUTTON(item)) | |
3597 { | |
3598 GSList *group; | |
3599 GtkWidget *groupstart = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(box), "group"); | |
3600 | |
3601 if(groupstart) | |
3602 { | |
3603 group = gtk_radio_button_group(GTK_RADIO_BUTTON(groupstart)); | |
3604 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group); | |
3605 } | |
3606 else | |
3607 gtk_object_set_data(GTK_OBJECT(box), "group", (gpointer)item); | |
3608 } | |
3609 } | |
3610 else | |
3611 { | |
3612 GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | |
3613 | |
3614 gtk_container_add(GTK_CONTAINER(box), vbox); | |
3615 gtk_box_pack_end(GTK_BOX(vbox), item, expand, TRUE, 0); | |
3616 gtk_widget_show(vbox); | |
3617 | |
3618 gtk_widget_set_usize(item, width, height); | |
3619 gtk_object_set_user_data(GTK_OBJECT(box), vbox); | |
3620 } | |
3621 DW_MUTEX_UNLOCK; | |
3622 } | |
3623 | |
3624 /* | |
3625 * Sets the size of a given window (widget). | |
3626 * Parameters: | |
3627 * handle: Window (widget) handle. | |
3628 * width: New width in pixels. | |
3629 * height: New height in pixels. | |
3630 */ | |
3631 void dw_window_set_usize(HWND handle, unsigned long width, unsigned long height) | |
3632 { | |
3633 int _locked_by_me = FALSE; | |
3634 | |
3635 DW_MUTEX_LOCK; | |
3636 if(GTK_IS_WINDOW(handle)) | |
3637 _size_allocate(GTK_WINDOW(handle)); | |
3638 #if 0 | |
3639 gtk_window_set_default_size(GTK_WINDOW(handle), width, height); | |
3640 else | |
3641 #endif | |
3642 gtk_widget_set_usize(handle, width, height); | |
3643 DW_MUTEX_UNLOCK; | |
3644 } | |
3645 | |
3646 /* | |
3647 * Returns the width of the screen. | |
3648 */ | |
3649 int dw_screen_width(void) | |
3650 { | |
3651 int retval; | |
3652 int _locked_by_me = FALSE; | |
3653 | |
3654 DW_MUTEX_LOCK; | |
3655 retval = gdk_screen_width(); | |
3656 DW_MUTEX_UNLOCK; | |
3657 return retval; | |
3658 } | |
3659 | |
3660 /* | |
3661 * Returns the height of the screen. | |
3662 */ | |
3663 int dw_screen_height(void) | |
3664 { | |
3665 int retval; | |
3666 int _locked_by_me = FALSE; | |
3667 | |
3668 DW_MUTEX_UNLOCK; | |
3669 retval = gdk_screen_height(); | |
3670 DW_MUTEX_UNLOCK; | |
3671 return retval; | |
3672 } | |
3673 | |
3674 /* This should return the current color depth */ | |
3675 unsigned long dw_color_depth(void) | |
3676 { | |
3677 int retval; | |
3678 int _locked_by_me = FALSE; | |
3679 | |
3680 DW_MUTEX_UNLOCK; | |
3681 retval = gdk_colormap_get_system_size(); | |
3682 DW_MUTEX_UNLOCK; | |
3683 return retval; | |
3684 } | |
3685 | |
3686 /* | |
3687 * Sets the position of a given window (widget). | |
3688 * Parameters: | |
3689 * handle: Window (widget) handle. | |
3690 * x: X location from the bottom left. | |
3691 * y: Y location from the bottom left. | |
3692 */ | |
3693 void dw_window_set_pos(HWND handle, unsigned long x, unsigned long y) | |
3694 { | |
3695 int _locked_by_me = FALSE; | |
3696 | |
3697 DW_MUTEX_LOCK; | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3698 if(handle && handle->window) |
3 | 3699 gdk_window_move(handle->window, x, y); |
3700 DW_MUTEX_UNLOCK; | |
3701 } | |
3702 | |
3703 /* | |
3704 * Sets the position and size of a given window (widget). | |
3705 * Parameters: | |
3706 * handle: Window (widget) handle. | |
3707 * x: X location from the bottom left. | |
3708 * y: Y location from the bottom left. | |
3709 * width: Width of the widget. | |
3710 * height: Height of the widget. | |
3711 */ | |
3712 void dw_window_set_pos_size(HWND handle, unsigned long x, unsigned long y, unsigned long width, unsigned long height) | |
3713 { | |
3714 int _locked_by_me = FALSE; | |
3715 | |
3716 DW_MUTEX_LOCK; | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3717 if(handle && GTK_IS_WINDOW(handle)) |
3 | 3718 { |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3719 int cx = (int)gtk_object_get_data(GTK_OBJECT(handle), "cx"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3720 int cy = (int)gtk_object_get_data(GTK_OBJECT(handle), "cy"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3721 |
3 | 3722 _size_allocate(GTK_WINDOW(handle)); |
15
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3723 |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3724 gtk_widget_set_uposition(handle, x, y); |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3725 gtk_window_set_default_size(GTK_WINDOW(handle), width - cx, height - cy); |
3 | 3726 } |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3727 else if(handle && handle->window) |
3 | 3728 { |
3729 gdk_window_resize(handle->window, width, height); | |
3730 gdk_window_move(handle->window, x, y); | |
3731 } | |
3732 DW_MUTEX_UNLOCK; | |
3733 } | |
3734 | |
3735 /* | |
3736 * Gets the position and size of a given window (widget). | |
3737 * Parameters: | |
3738 * handle: Window (widget) handle. | |
3739 * x: X location from the bottom left. | |
3740 * y: Y location from the bottom left. | |
3741 * width: Width of the widget. | |
3742 * height: Height of the widget. | |
3743 */ | |
3744 void dw_window_get_pos_size(HWND handle, ULONG *x, ULONG *y, ULONG *width, ULONG *height) | |
3745 { | |
3746 int _locked_by_me = FALSE; | |
3747 gint gx, gy, gwidth, gheight, gdepth; | |
3748 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
3749 if(handle && handle->window) |
3 | 3750 { |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3751 int cx, cy; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3752 |
3 | 3753 DW_MUTEX_LOCK; |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3754 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3755 cx = (int)gtk_object_get_data(GTK_OBJECT(handle), "cx"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3756 cy = (int)gtk_object_get_data(GTK_OBJECT(handle), "cy"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3757 |
3 | 3758 gdk_window_get_geometry(handle->window, &gx, &gy, &gwidth, &gheight, &gdepth); |
3759 gdk_window_get_root_origin(handle->window, &gx, &gy); | |
3760 if(x) | |
3761 *x = gx; | |
3762 if(y) | |
3763 *y = gy; | |
3764 if(width) | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3765 *width = gwidth - cx; |
3 | 3766 if(height) |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3767 *height = gheight - cy; |
3 | 3768 DW_MUTEX_UNLOCK; |
3769 } | |
3770 } | |
3771 | |
3772 /* | |
3773 * Sets the style of a given window (widget). | |
3774 * Parameters: | |
3775 * handle: Window (widget) handle. | |
3776 * width: New width in pixels. | |
3777 * height: New height in pixels. | |
3778 */ | |
3779 void dw_window_set_style(HWND handle, unsigned long style, unsigned long mask) | |
3780 { | |
3781 GtkWidget *handle2 = handle; | |
3782 int _locked_by_me = FALSE; | |
3783 | |
3784 DW_MUTEX_LOCK; | |
3785 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
3786 { | |
3787 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
3788 if(tmp) | |
3789 handle2 = tmp; | |
3790 } | |
3791 if(GTK_IS_CLIST(handle2)) | |
3792 { | |
3793 if(style & DW_CCS_EXTENDSEL) | |
3794 gtk_clist_set_selection_mode(GTK_CLIST(handle2), GTK_SELECTION_MULTIPLE); | |
3795 if(style & DW_CCS_SINGLESEL) | |
3796 gtk_clist_set_selection_mode(GTK_CLIST(handle2), GTK_SELECTION_SINGLE); | |
3797 } | |
3798 DW_MUTEX_UNLOCK; | |
3799 } | |
3800 | |
3801 /* | |
3802 * Adds a new page to specified notebook. | |
3803 * Parameters: | |
3804 * handle: Window (widget) handle. | |
3805 * flags: Any additional page creation flags. | |
3806 * front: If TRUE page is added at the beginning. | |
3807 */ | |
3808 unsigned long dw_notebook_page_new(HWND handle, unsigned long flags, int front) | |
3809 { | |
3810 int z; | |
3811 int _locked_by_me = FALSE; | |
3812 | |
3813 DW_MUTEX_LOCK; | |
3814 for(z=0;z<256;z++) | |
15
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3815 { |
3 | 3816 if(!gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), z)) |
3817 { | |
3818 DW_MUTEX_UNLOCK; | |
3819 return z; | |
3820 } | |
15
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3821 } |
3 | 3822 |
3823 DW_MUTEX_UNLOCK; | |
3824 | |
3825 /* Hopefully this won't happen. */ | |
3826 return 256; | |
3827 } | |
3828 | |
3829 /* | |
3830 * Remove a page from a notebook. | |
3831 * Parameters: | |
3832 * handle: Handle to the notebook widget. | |
3833 * pageid: ID of the page to be destroyed. | |
3834 */ | |
3835 void dw_notebook_page_destroy(HWND handle, unsigned int pageid) | |
3836 { | |
3837 int _locked_by_me = FALSE; | |
3838 | |
3839 DW_MUTEX_LOCK; | |
3840 gtk_notebook_remove_page(GTK_NOTEBOOK(handle), pageid); | |
3841 DW_MUTEX_UNLOCK; | |
3842 } | |
3843 | |
3844 /* | |
3845 * Queries the currently visible page ID. | |
3846 * Parameters: | |
3847 * handle: Handle to the notebook widget. | |
3848 */ | |
3849 unsigned int dw_notebook_page_query(HWND handle) | |
3850 { | |
3851 int retval; | |
3852 int _locked_by_me = FALSE; | |
3853 | |
3854 DW_MUTEX_LOCK; | |
3855 retval = gtk_notebook_get_current_page(GTK_NOTEBOOK(handle)); | |
3856 DW_MUTEX_UNLOCK; | |
3857 return retval; | |
3858 } | |
3859 | |
3860 /* | |
3861 * Sets the currently visibale page ID. | |
3862 * Parameters: | |
3863 * handle: Handle to the notebook widget. | |
3864 * pageid: ID of the page to be made visible. | |
3865 */ | |
3866 void dw_notebook_page_set(HWND handle, unsigned int pageid) | |
3867 { | |
3868 int _locked_by_me = FALSE; | |
3869 | |
3870 DW_MUTEX_LOCK; | |
3871 gtk_notebook_set_page(GTK_NOTEBOOK(handle), pageid); | |
3872 DW_MUTEX_UNLOCK; | |
3873 } | |
3874 | |
3875 | |
3876 /* | |
3877 * Sets the text on the specified notebook tab. | |
3878 * Parameters: | |
3879 * handle: Notebook handle. | |
3880 * pageid: Page ID of the tab to set. | |
3881 * text: Pointer to the text to set. | |
3882 */ | |
3883 void dw_notebook_page_set_text(HWND handle, unsigned long pageid, char *text) | |
3884 { | |
3885 GtkWidget *child; | |
3886 int _locked_by_me = FALSE; | |
3887 | |
3888 DW_MUTEX_LOCK; | |
3889 child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), pageid); | |
3890 if(child) | |
3891 gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(handle), child, text); | |
3892 DW_MUTEX_UNLOCK; | |
3893 } | |
3894 | |
3895 /* | |
3896 * Sets the text on the specified notebook tab status area. | |
3897 * Parameters: | |
3898 * handle: Notebook handle. | |
3899 * pageid: Page ID of the tab to set. | |
3900 * text: Pointer to the text to set. | |
3901 */ | |
3902 void dw_notebook_page_set_status_text(HWND handle, unsigned long pageid, char *text) | |
3903 { | |
3904 /* TODO (if possible) */ | |
3905 } | |
3906 | |
3907 /* | |
3908 * Packs the specified box into the notebook page. | |
3909 * Parameters: | |
3910 * handle: Handle to the notebook to be packed. | |
3911 * pageid: Page ID in the notebook which is being packed. | |
3912 * page: Box handle to be packed. | |
3913 */ | |
3914 void dw_notebook_pack(HWND handle, unsigned long pageid, HWND page) | |
3915 { | |
15
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3916 GtkWidget *label, *child, *oldlabel; |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3917 gchar *text = NULL; |
3 | 3918 int _locked_by_me = FALSE; |
3919 | |
3920 DW_MUTEX_LOCK; | |
15
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3921 child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), pageid); |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3922 if(child) |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3923 { |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3924 oldlabel = gtk_notebook_get_tab_label(GTK_NOTEBOOK(handle), child); |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3925 if(oldlabel) |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3926 gtk_label_get(GTK_LABEL(oldlabel), &text); |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3927 } |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3928 |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3929 label = gtk_label_new(text ? text : ""); |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3930 |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3931 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, pageid); |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3932 if(child) |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
3933 gtk_notebook_remove_page(GTK_NOTEBOOK(handle), pageid+1); |
3 | 3934 DW_MUTEX_UNLOCK; |
3935 } | |
3936 | |
3937 /* | |
3938 * Appends the specified text to the listbox's (or combobox) entry list. | |
3939 * Parameters: | |
3940 * handle: Handle to the listbox to be appended to. | |
3941 * text: Text to append into listbox. | |
3942 */ | |
3943 void dw_listbox_append(HWND handle, char *text) | |
3944 { | |
3945 GtkWidget *handle2 = handle; | |
3946 int _locked_by_me = FALSE; | |
3947 | |
3948 DW_MUTEX_LOCK; | |
3949 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
3950 { | |
3951 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
3952 if(tmp) | |
3953 handle2 = tmp; | |
3954 } | |
3955 if(GTK_IS_LIST(handle2)) | |
3956 { | |
3957 GtkWidget *list_item; | |
3958 GList *tmp; | |
3959 char *font = (char *)gtk_object_get_data(GTK_OBJECT(handle), "font"); | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3960 GdkColor *fore = (GdkColor *)gtk_object_get_data(GTK_OBJECT(handle2), "foregdk"); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3961 GdkColor *back = (GdkColor *)gtk_object_get_data(GTK_OBJECT(handle2), "backgdk"); |
3 | 3962 |
3963 list_item=gtk_list_item_new_with_label(text); | |
3964 | |
3965 if(font) | |
3966 _set_font(GTK_LIST_ITEM(list_item)->item.bin.child, font); | |
3967 if(fore && back) | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3968 _set_color(GTK_LIST_ITEM(list_item)->item.bin.child, |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3969 DW_RGB(fore->red, fore->green, fore->blue), |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3970 DW_RGB(back->red, back->green, back->blue)); |
3 | 3971 |
3972 tmp = g_list_append(NULL, list_item); | |
3973 gtk_widget_show(list_item); | |
3974 gtk_list_append_items(GTK_LIST(handle2),tmp); | |
3975 } | |
3976 else if(GTK_IS_COMBO(handle2)) | |
3977 { | |
3978 GList *tmp = (GList *)gtk_object_get_user_data(GTK_OBJECT(handle2)); | |
3979 char *addtext = strdup(text); | |
3980 | |
3981 if(addtext) | |
3982 { | |
3983 tmp = g_list_append(tmp, addtext); | |
3984 gtk_object_set_user_data(GTK_OBJECT(handle2), tmp); | |
3985 gtk_combo_set_popdown_strings(GTK_COMBO(handle2), tmp); | |
3986 } | |
3987 } | |
3988 DW_MUTEX_UNLOCK; | |
3989 } | |
3990 | |
3991 /* | |
3992 * Clears the listbox's (or combobox) list of all entries. | |
3993 * Parameters: | |
3994 * handle: Handle to the listbox to be cleared. | |
3995 */ | |
3996 void dw_listbox_clear(HWND handle) | |
3997 { | |
3998 GtkWidget *handle2 = handle; | |
3999 int _locked_by_me = FALSE; | |
4000 | |
4001 DW_MUTEX_LOCK; | |
4002 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
4003 { | |
4004 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
4005 if(tmp) | |
4006 handle2 = tmp; | |
4007 } | |
4008 if(GTK_IS_COMBO(handle2)) | |
4009 { | |
4010 GList *list, *tmp = (GList *)gtk_object_get_user_data(GTK_OBJECT(handle2)); | |
4011 | |
4012 if(tmp) | |
4013 { | |
4014 list = tmp; | |
4015 while(list) | |
4016 { | |
4017 if(list->data) | |
4018 free(list->data); | |
4019 list=list->next; | |
4020 } | |
4021 g_list_free(tmp); | |
4022 } | |
4023 gtk_object_set_user_data(GTK_OBJECT(handle2), NULL); | |
4024 } | |
4025 else if(GTK_IS_LIST(handle2)) | |
4026 { | |
4027 int count = dw_listbox_count(handle); | |
4028 | |
4029 gtk_list_clear_items(GTK_LIST(handle2), 0, count - 1); | |
4030 } | |
4031 DW_MUTEX_UNLOCK; | |
4032 } | |
4033 | |
4034 /* | |
4035 * Returns the listbox's item count. | |
4036 * Parameters: | |
4037 * handle: Handle to the listbox to be counted | |
4038 */ | |
4039 int dw_listbox_count(HWND handle) | |
4040 { | |
4041 GtkWidget *handle2 = handle; | |
4042 int retval = 0; | |
4043 int _locked_by_me = FALSE; | |
4044 | |
4045 DW_MUTEX_LOCK; | |
4046 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
4047 { | |
4048 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
4049 if(tmp) | |
4050 handle2 = tmp; | |
4051 } | |
4052 else if(GTK_IS_COMBO(handle)) | |
4053 { | |
4054 handle2 = GTK_COMBO(handle)->list; | |
4055 } | |
4056 if(GTK_IS_LIST(handle2)) | |
4057 { | |
4058 GList *list = GTK_LIST(handle2)->children; | |
4059 while(list) | |
4060 { | |
4061 list = list->next; | |
4062 retval++; | |
4063 } | |
4064 } | |
4065 DW_MUTEX_UNLOCK; | |
4066 return retval; | |
4067 } | |
4068 | |
4069 /* | |
4070 * Sets the topmost item in the viewport. | |
4071 * Parameters: | |
4072 * handle: Handle to the listbox to be cleared. | |
4073 * top: Index to the top item. | |
4074 */ | |
4075 void dw_listbox_set_top(HWND handle, int top) | |
4076 { | |
4077 GtkWidget *handle2 = handle; | |
4078 int _locked_by_me = FALSE; | |
4079 | |
4080 DW_MUTEX_LOCK; | |
4081 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
4082 { | |
4083 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
4084 if(tmp) | |
4085 handle2 = tmp; | |
4086 } | |
4087 if(GTK_IS_LIST(handle2)) | |
4088 { | |
4089 int count = dw_listbox_count(handle); | |
4090 GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(handle)); | |
4091 float pos, ratio; | |
4092 | |
4093 if(count) | |
4094 { | |
4095 ratio = (float)top/(float)count; | |
4096 | |
4097 pos = (ratio * (float)(adj->upper - adj->lower)) + adj->lower; | |
4098 | |
4099 gtk_adjustment_set_value(adj, pos); | |
4100 } | |
4101 } | |
4102 DW_MUTEX_UNLOCK; | |
4103 } | |
4104 | |
4105 /* | |
4106 * Copies the given index item's text into buffer. | |
4107 * Parameters: | |
4108 * handle: Handle to the listbox to be queried. | |
4109 * index: Index into the list to be queried. | |
4110 * buffer: Buffer where text will be copied. | |
4111 * length: Length of the buffer (including NULL). | |
4112 */ | |
4113 void dw_listbox_query_text(HWND handle, unsigned int index, char *buffer, unsigned int length) | |
4114 { | |
4115 GtkWidget *handle2 = handle; | |
4116 int _locked_by_me = FALSE; | |
4117 | |
4118 DW_MUTEX_LOCK; | |
4119 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
4120 { | |
4121 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
4122 if(tmp) | |
4123 handle2 = tmp; | |
4124 } | |
4125 else if(GTK_IS_COMBO(handle)) | |
4126 { | |
4127 handle2 = GTK_COMBO(handle)->list; | |
4128 } | |
4129 if(GTK_IS_LIST(handle2)) | |
4130 { | |
4131 int counter = 0; | |
4132 GList *list = GTK_LIST(handle2)->children; | |
4133 | |
4134 while(list) | |
4135 { | |
4136 if(counter == index) | |
4137 { | |
4138 gchar *text = ""; | |
4139 | |
4140 if(GTK_IS_LIST_ITEM(list->data)) | |
4141 { | |
4142 GtkListItem *li = GTK_LIST_ITEM(list->data); | |
4143 | |
4144 if(GTK_IS_ITEM(&(li->item))) | |
4145 { | |
4146 GtkItem *i = &(li->item); | |
4147 | |
4148 if(GTK_IS_BIN(&(i->bin))) | |
4149 { | |
4150 GtkBin *b = &(i->bin); | |
4151 | |
4152 if(GTK_IS_LABEL(b->child)) | |
4153 gtk_label_get(GTK_LABEL(b->child), &text); | |
4154 } | |
4155 } | |
4156 } | |
4157 else if(GTK_IS_COMBO(handle) && list->data) | |
4158 text = (gchar *)list->data; | |
4159 | |
4160 strncpy(buffer, (char *)text, length); | |
4161 break; | |
4162 } | |
4163 list = list->next; | |
4164 counter++; | |
4165 } | |
4166 } | |
4167 DW_MUTEX_UNLOCK; | |
4168 } | |
4169 | |
4170 /* | |
4171 * Sets the text of a given listbox entry. | |
4172 * Parameters: | |
4173 * handle: Handle to the listbox to be queried. | |
4174 * index: Index into the list to be queried. | |
4175 * buffer: Buffer where text will be copied. | |
4176 */ | |
4177 void dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) | |
4178 { | |
4179 GtkWidget *handle2 = handle; | |
4180 int _locked_by_me = FALSE; | |
4181 | |
4182 DW_MUTEX_LOCK; | |
4183 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
4184 { | |
4185 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
4186 if(tmp) | |
4187 handle2 = tmp; | |
4188 } | |
4189 else if(GTK_IS_COMBO(handle)) | |
4190 { | |
4191 handle2 = GTK_COMBO(handle)->list; | |
4192 } | |
4193 if(GTK_IS_LIST(handle2)) | |
4194 { | |
4195 int counter = 0; | |
4196 GList *list = GTK_LIST(handle2)->children; | |
4197 | |
4198 while(list) | |
4199 { | |
4200 if(counter == index) | |
4201 { | |
4202 | |
4203 if(GTK_IS_LIST_ITEM(list->data)) | |
4204 { | |
4205 GtkListItem *li = GTK_LIST_ITEM(list->data); | |
4206 | |
4207 if(GTK_IS_ITEM(&(li->item))) | |
4208 { | |
4209 GtkItem *i = &(li->item); | |
4210 | |
4211 if(GTK_IS_BIN(&(i->bin))) | |
4212 { | |
4213 GtkBin *b = &(i->bin); | |
4214 | |
4215 if(GTK_IS_LABEL(b->child)) | |
4216 gtk_label_set_text(GTK_LABEL(b->child), buffer); | |
4217 } | |
4218 } | |
4219 } | |
4220 else if(GTK_IS_COMBO(handle)) | |
4221 { | |
4222 if(list->data) | |
4223 g_free(list->data); | |
4224 list->data = g_strdup(buffer); | |
4225 } | |
4226 break; | |
4227 } | |
4228 list = list->next; | |
4229 counter++; | |
4230 } | |
4231 } | |
4232 DW_MUTEX_UNLOCK; | |
4233 } | |
4234 | |
4235 /* | |
4236 * Returns the index to the item in the list currently selected. | |
4237 * Parameters: | |
4238 * handle: Handle to the listbox to be queried. | |
4239 */ | |
4240 unsigned int dw_listbox_selected(HWND handle) | |
4241 { | |
4242 GtkWidget *handle2 = handle; | |
4243 int retval = DW_LIT_NONE; | |
4244 int _locked_by_me = FALSE; | |
4245 | |
4246 DW_MUTEX_LOCK; | |
4247 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
4248 { | |
4249 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
4250 if(tmp) | |
4251 handle2 = tmp; | |
4252 } | |
4253 else if(GTK_IS_COMBO(handle)) | |
4254 { | |
4255 retval = (unsigned int)gtk_object_get_data(GTK_OBJECT(handle), "item"); | |
4256 DW_MUTEX_UNLOCK; | |
4257 return retval; | |
4258 } | |
4259 if(GTK_IS_LIST(handle2)) | |
4260 { | |
4261 int counter = 0; | |
4262 GList *list = GTK_LIST(handle2)->children; | |
4263 while(list) | |
4264 { | |
19
3e5bff3e55ff
Fixed a problem in dw_listbox_selected().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4265 if(list->data == GTK_LIST(handle2)->selection->data) |
3 | 4266 { |
4267 retval = counter; | |
4268 break; | |
4269 } | |
4270 | |
4271 list = list->next; | |
4272 counter++; | |
4273 } | |
4274 } | |
4275 DW_MUTEX_UNLOCK; | |
4276 return retval; | |
4277 } | |
4278 | |
4279 /* | |
4280 * Sets the selection state of a given index. | |
4281 * Parameters: | |
4282 * handle: Handle to the listbox to be set. | |
4283 * index: Item index. | |
4284 * state: TRUE if selected FALSE if unselected. | |
4285 */ | |
4286 void dw_listbox_select(HWND handle, int index, int state) | |
4287 { | |
4288 GtkWidget *handle2 = handle; | |
4289 int _locked_by_me = FALSE; | |
4290 | |
4291 DW_MUTEX_LOCK; | |
4292 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
4293 { | |
4294 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
4295 if(tmp) | |
4296 handle2 = tmp; | |
4297 } | |
4298 else if(GTK_IS_COMBO(handle)) | |
4299 { | |
4300 handle2 = GTK_COMBO(handle)->list; | |
4301 } | |
4302 if(GTK_IS_LIST(handle2)) | |
4303 { | |
4304 if(state) | |
4305 gtk_list_select_item(GTK_LIST(handle2), index); | |
4306 else | |
4307 gtk_list_unselect_item(GTK_LIST(handle2), index); | |
4308 } | |
4309 DW_MUTEX_UNLOCK; | |
4310 } | |
4311 | |
4312 /* | |
4313 * Deletes the item with given index from the list. | |
4314 * Parameters: | |
4315 * handle: Handle to the listbox to be set. | |
4316 * index: Item index. | |
4317 */ | |
4318 void dw_listbox_delete(HWND handle, int index) | |
4319 { | |
4320 GtkWidget *handle2 = handle; | |
4321 int _locked_by_me = FALSE; | |
4322 | |
4323 DW_MUTEX_LOCK; | |
4324 if(GTK_IS_SCROLLED_WINDOW(handle)) | |
4325 { | |
4326 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); | |
4327 if(tmp) | |
4328 handle2 = tmp; | |
4329 } | |
4330 else if(GTK_IS_COMBO(handle)) | |
4331 { | |
4332 handle2 = GTK_COMBO(handle)->list; | |
4333 } | |
4334 if(GTK_IS_LIST(handle2)) | |
4335 gtk_list_clear_items(GTK_LIST(handle2), index, index); | |
4336 DW_MUTEX_UNLOCK; | |
4337 } | |
4338 | |
4339 | |
4340 /* | |
4341 * Pack a splitbar (sizer) into the specified box from the start. | |
4342 * Parameters: | |
4343 * box: Window handle of the box to be packed into. | |
4344 */ | |
4345 void dw_box_pack_splitbar_start(HWND box) | |
4346 { | |
4347 /* TODO */ | |
4348 } | |
4349 | |
4350 /* | |
4351 * Pack a splitbar (sizer) into the specified box from the end. | |
4352 * Parameters: | |
4353 * box: Window handle of the box to be packed into. | |
4354 */ | |
4355 void dw_box_pack_splitbar_end(HWND box) | |
4356 { | |
4357 /* TODO */ | |
4358 } | |
4359 | |
4360 /* | |
4361 * Pack windows (widgets) into a box from the start (or top). | |
4362 * Parameters: | |
4363 * box: Window handle of the box to be packed into. | |
4364 * item: Window handle of the item to be back. | |
4365 * width: Width in pixels of the item or -1 to be self determined. | |
4366 * height: Height in pixels of the item or -1 to be self determined. | |
4367 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | |
4368 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | |
4369 * pad: Number of pixels of padding around the item. | |
4370 */ | |
4371 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | |
4372 { | |
4373 int expand = (hsize == FALSE && vsize == FALSE) ? FALSE : TRUE; | |
4374 int _locked_by_me = FALSE; | |
4375 | |
4376 if(!box) | |
4377 return; | |
4378 | |
4379 DW_MUTEX_LOCK; | |
4380 | |
4381 if(!item) | |
4382 { | |
4383 item = gtk_label_new(""); | |
4384 gtk_widget_show(item); | |
4385 } | |
4386 | |
4387 if(GTK_IS_BOX(box)) | |
4388 { | |
4389 gtk_box_pack_start(GTK_BOX(box), item, expand, TRUE, pad); | |
4390 gtk_widget_set_usize(item, width, height); | |
4391 if(GTK_IS_RADIO_BUTTON(item)) | |
4392 { | |
4393 GSList *group; | |
4394 GtkWidget *groupstart = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(box), "group"); | |
4395 | |
4396 if(groupstart) | |
4397 { | |
4398 group = gtk_radio_button_group(GTK_RADIO_BUTTON(groupstart)); | |
4399 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group); | |
4400 } | |
4401 else | |
4402 gtk_object_set_data(GTK_OBJECT(box), "group", (gpointer)item); | |
4403 } | |
4404 } | |
4405 else | |
4406 { | |
4407 GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | |
4408 | |
4409 gtk_container_add(GTK_CONTAINER(box), vbox); | |
4410 gtk_box_pack_end(GTK_BOX(vbox), item, expand, TRUE, 0); | |
4411 gtk_widget_show(vbox); | |
4412 | |
4413 gtk_widget_set_usize(item, width, height); | |
4414 gtk_object_set_user_data(GTK_OBJECT(box), vbox); | |
4415 } | |
4416 DW_MUTEX_UNLOCK; | |
4417 } | |
4418 | |
4419 /* | |
34
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4420 * Sets the default focus item for a window/dialog. |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4421 * Parameters: |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4422 * window: Toplevel window or dialog. |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4423 * defaultitem: Handle to the dialog item to be default. |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4424 */ |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4425 void dw_window_default(HWND window, HWND defaultitem) |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4426 { |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4427 int _locked_by_me = FALSE; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4428 |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4429 if(!window) |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4430 return; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4431 |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4432 DW_MUTEX_LOCK; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4433 gtk_object_set_data(GTK_OBJECT(window), "defaultitem", (gpointer)defaultitem); |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4434 DW_MUTEX_UNLOCK; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4435 } |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4436 |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4437 /* |
3 | 4438 * Returns some information about the current operating environment. |
4439 * Parameters: | |
4440 * env: Pointer to a DWEnv struct. | |
4441 */ | |
4442 void dw_environment_query(DWEnv *env) | |
4443 { | |
4444 struct utsname name; | |
4445 char tempbuf[100]; | |
4446 int len, z; | |
4447 | |
4448 uname(&name); | |
4449 strcpy(env->osName, name.sysname); | |
4450 strcpy(tempbuf, name.release); | |
4451 | |
4452 env->MajorBuild = env->MinorBuild = 0; | |
4453 | |
4454 len = strlen(tempbuf); | |
4455 | |
15
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
4456 strcpy(env->buildDate, __DATE__); |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
4457 strcpy(env->buildTime, __TIME__); |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
4458 env->DWMajorVersion = DW_MAJOR_VERSION; |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
4459 env->DWMinorVersion = DW_MINOR_VERSION; |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
4460 env->DWSubVersion = DW_SUB_VERSION; |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
4461 |
3 | 4462 for(z=1;z<len;z++) |
4463 { | |
4464 if(tempbuf[z] == '.') | |
4465 { | |
4466 tempbuf[z] = '\0'; | |
4467 env->MajorVersion = atoi(&tempbuf[z-1]); | |
4468 env->MinorVersion = atoi(&tempbuf[z+1]); | |
4469 return; | |
4470 } | |
4471 } | |
4472 env->MajorVersion = atoi(tempbuf); | |
4473 env->MinorVersion = 0; | |
4474 } | |
4475 | |
4476 /* Internal function to handle the file OK press */ | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4477 void _gtk_file_ok(GtkWidget *widget, DWDialog *dwwait) |
3 | 4478 { |
4479 char *tmp; | |
4480 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4481 if(!dwwait) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4482 return; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4483 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4484 tmp = gtk_file_selection_get_filename(GTK_FILE_SELECTION(dwwait->data)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4485 gtk_widget_destroy(GTK_WIDGET(dwwait->data)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4486 _dw_file_active = 0; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4487 dw_dialog_dismiss(dwwait, (void *)(tmp ? strdup(tmp) : NULL)); |
3 | 4488 } |
4489 | |
4490 /* Internal function to handle the file Cancel press */ | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4491 void _gtk_file_cancel(GtkWidget *widget, DWDialog *dwwait) |
3 | 4492 { |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4493 if(!dwwait) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4494 return; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4495 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4496 gtk_widget_destroy(GTK_WIDGET(dwwait->data)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4497 _dw_file_active = 0; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4498 dw_dialog_dismiss(dwwait, NULL); |
3 | 4499 } |
4500 | |
4501 /* | |
4502 * Opens a file dialog and queries user selection. | |
4503 * Parameters: | |
4504 * title: Title bar text for dialog. | |
4505 * defpath: The default path of the open dialog. | |
4506 * ext: Default file extention. | |
4507 * flags: DW_FILE_OPEN or DW_FILE_SAVE. | |
4508 * Returns: | |
4509 * NULL on error. A malloced buffer containing | |
4510 * the file path on success. | |
4511 * | |
4512 */ | |
4513 char *dw_file_browse(char *title, char *defpath, char *ext, int flags) | |
4514 { | |
4515 GtkWidget *filew; | |
4516 int _locked_by_me = FALSE; | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4517 DWDialog *dwwait; |
3 | 4518 |
4519 DW_MUTEX_LOCK; | |
4520 | |
4521 /* The DW mutex should be sufficient for | |
4522 * insuring no thread changes this unknowingly. | |
4523 */ | |
4524 if(_dw_file_active) | |
4525 { | |
4526 DW_MUTEX_UNLOCK; | |
4527 return NULL; | |
4528 } | |
4529 | |
4530 _dw_file_active = 1; | |
4531 | |
4532 filew = gtk_file_selection_new(title); | |
4533 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4534 dwwait = dw_dialog_new((void *)filew); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4535 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4536 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filew)->ok_button), "clicked", (GtkSignalFunc) _gtk_file_ok, dwwait); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4537 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filew)->cancel_button), "clicked", (GtkSignalFunc) _gtk_file_cancel, dwwait); |
3 | 4538 |
4539 if(defpath) | |
4540 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filew), defpath); | |
4541 | |
4542 gtk_widget_show(filew); | |
4543 | |
4544 DW_MUTEX_UNLOCK; | |
4545 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
19
diff
changeset
|
4546 return (char *)dw_dialog_wait(dwwait); |
3 | 4547 } |
4548 | |
4549 | |
4550 /* | |
4551 * Execute and external program in a seperate session. | |
4552 * Parameters: | |
4553 * program: Program name with optional path. | |
4554 * type: Either DW_EXEC_CON or DW_EXEC_GUI. | |
4555 * params: An array of pointers to string arguements. | |
4556 * Returns: | |
4557 * -1 on error. | |
4558 */ | |
4559 int dw_exec(char *program, int type, char **params) | |
4560 { | |
4561 int ret = -1; | |
4562 | |
4563 if((ret = fork()) == 0) | |
4564 { | |
4565 int i; | |
4566 | |
4567 for (i = 3; i < 256; i++) | |
4568 close(i); | |
4569 setsid(); | |
4570 if(type == DW_EXEC_GUI) | |
4571 { | |
4572 execvp(program, params); | |
4573 } | |
4574 else if(type == DW_EXEC_CON) | |
4575 { | |
4576 char **tmpargs; | |
4577 | |
4578 if(!params) | |
4579 { | |
4580 tmpargs = malloc(sizeof(char *)); | |
4581 tmpargs[0] = NULL; | |
4582 } | |
4583 else | |
4584 { | |
4585 int z = 0; | |
4586 | |
4587 while(params[z]) | |
4588 { | |
4589 z++; | |
4590 } | |
4591 tmpargs = malloc(sizeof(char *)*(z+3)); | |
4592 z=0; | |
4593 tmpargs[0] = "xterm"; | |
4594 tmpargs[1] = "-e"; | |
4595 while(params[z]) | |
4596 { | |
4597 tmpargs[z+2] = params[z]; | |
4598 z++; | |
4599 } | |
4600 tmpargs[z+2] = NULL; | |
4601 } | |
4602 execvp("xterm", tmpargs); | |
4603 free(tmpargs); | |
4604 } | |
4605 /* If we got here exec failed */ | |
4606 _exit(-1); | |
4607 } | |
4608 return ret; | |
4609 } | |
4610 | |
4611 /* | |
4612 * Loads a web browser pointed at the given URL. | |
4613 * Parameters: | |
4614 * url: Uniform resource locator. | |
4615 */ | |
4616 int dw_browse(char *url) | |
4617 { | |
4618 /* Is there a way to find the webbrowser in Unix? */ | |
4619 char *execargs[3], *browser = "netscape"; | |
4620 | |
4621 execargs[0] = browser; | |
4622 execargs[1] = url; | |
4623 execargs[2] = NULL; | |
4624 | |
4625 return dw_exec(browser, DW_EXEC_GUI, execargs); | |
4626 } | |
4627 | |
4628 /* | |
4629 * Returns a pointer to a static buffer which containes the | |
4630 * current user directory. Or the root directory (C:\ on | |
4631 * OS/2 and Windows). | |
4632 */ | |
4633 char *dw_user_dir(void) | |
4634 { | |
4635 static char _user_dir[1024] = ""; | |
4636 | |
4637 if(!_user_dir[0]) | |
4638 { | |
4639 char *home = getenv("HOME"); | |
4640 | |
4641 if(home) | |
4642 strcpy(_user_dir, home); | |
4643 else | |
4644 strcpy(_user_dir, "/"); | |
4645 } | |
4646 return _user_dir; | |
4647 } | |
4648 | |
4649 /* | |
4650 * Call a function from the window (widget)'s context. | |
4651 * Parameters: | |
4652 * handle: Window handle of the widget. | |
4653 * function: Function pointer to be called. | |
4654 * data: Pointer to the data to be passed to the function. | |
4655 */ | |
4656 void dw_window_function(HWND handle, void *function, void *data) | |
4657 { | |
4658 /* TODO */ | |
4659 } | |
4660 | |
4661 #ifndef NO_SIGNALS | |
4662 /* | |
4663 * Add a callback to a window event. | |
4664 * Parameters: | |
4665 * window: Window handle of signal to be called back. | |
4666 * signame: A string pointer identifying which signal to be hooked. | |
4667 * sigfunc: The pointer to the function to be used as the callback. | |
4668 * data: User data to be passed to the handler function. | |
4669 */ | |
4670 void dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) | |
4671 { | |
4672 SignalHandler *work = malloc(sizeof(SignalHandler)); | |
4673 void *thisfunc = _findsigfunc(signame); | |
4674 char *thisname = signame; | |
4675 HWND thiswindow = window; | |
4676 int _locked_by_me = FALSE; | |
4677 | |
4678 DW_MUTEX_LOCK; | |
4679 if(GTK_IS_SCROLLED_WINDOW(thiswindow)) | |
4680 { | |
4681 thiswindow = (HWND)gtk_object_get_user_data(GTK_OBJECT(window)); | |
4682 } | |
4683 | |
4684 if(GTK_IS_MENU_ITEM(thiswindow) && strcmp(signame, "clicked") == 0) | |
4685 { | |
4686 thisname = "activate"; | |
4687 thisfunc = _findsigfunc(thisname); | |
4688 } | |
4689 else if(GTK_IS_CLIST(thiswindow) && strcmp(signame, "container-context") == 0) | |
4690 { | |
4691 thisname = "button_press_event"; | |
4692 thisfunc = _findsigfunc("container-context"); | |
4693 } | |
4694 else if(GTK_IS_CLIST(thiswindow) && strcmp(signame, "container-select") == 0) | |
4695 { | |
4696 thisname = "button_press_event"; | |
4697 thisfunc = _findsigfunc("container-select"); | |
4698 } | |
4699 else if(GTK_IS_COMBO(thiswindow) && strcmp(signame, "item-select") == 0) | |
4700 { | |
4701 thisname = "select_child"; | |
4702 thiswindow = GTK_COMBO(thiswindow)->list; | |
4703 } | |
4704 else if(GTK_IS_LIST(thiswindow) && strcmp(signame, "item-select") == 0) | |
4705 { | |
4706 thisname = "select_child"; | |
4707 } | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
4708 else if(GTK_IS_WINDOW(thiswindow) && strcmp(signame, "set-focus") == 0) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
4709 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
4710 thisname = "focus-in-event"; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
4711 } |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4712 else if(GTK_IS_TREE(thiswindow) && strcmp(signame, "tree-select") == 0) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4713 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4714 if(thisfunc) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4715 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4716 gtk_object_set_data(GTK_OBJECT(thiswindow), "select-child-func", (gpointer)thisfunc); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4717 gtk_object_set_data(GTK_OBJECT(thiswindow), "select-child-data", (gpointer)work); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4718 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4719 thisname = "select-child"; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4720 } |
3 | 4721 |
4722 if(!thisfunc || !thiswindow) | |
4723 { | |
4724 free(work); | |
4725 DW_MUTEX_UNLOCK; | |
4726 return; | |
4727 } | |
4728 | |
4729 work->window = window; | |
4730 work->data = data; | |
4731 work->func = sigfunc; | |
4732 | |
4733 gtk_signal_connect(GTK_OBJECT(thiswindow), thisname, GTK_SIGNAL_FUNC(thisfunc), work); | |
4734 DW_MUTEX_UNLOCK; | |
4735 } | |
4736 | |
4737 /* | |
4738 * Removes callbacks for a given window with given name. | |
4739 * Parameters: | |
4740 * window: Window handle of callback to be removed. | |
4741 */ | |
4742 void dw_signal_disconnect_by_name(HWND window, char *signame) | |
4743 { | |
4744 #if 0 | |
4745 gtk_signal_disconnect_by_name(window, signame); | |
4746 #endif | |
4747 } | |
4748 | |
4749 /* | |
4750 * Removes all callbacks for a given window. | |
4751 * Parameters: | |
4752 * window: Window handle of callback to be removed. | |
4753 */ | |
4754 void dw_signal_disconnect_by_window(HWND window) | |
4755 { | |
4756 #if 0 | |
4757 gtk_signal_disconnect_by_window(window); | |
4758 #endif | |
4759 } | |
4760 | |
4761 /* | |
4762 * Removes all callbacks for a given window with specified data. | |
4763 * Parameters: | |
4764 * window: Window handle of callback to be removed. | |
4765 * data: Pointer to the data to be compared against. | |
4766 */ | |
4767 void dw_signal_disconnect_by_data(HWND window, void *data) | |
4768 { | |
4769 dw_signal_disconnect_by_data(window, data); | |
4770 } | |
4771 #endif | |
4772 | |
4773 #ifdef TEST | |
4774 HWND mainwindow, | |
4775 listbox, | |
4776 okbutton, | |
4777 cancelbutton, | |
4778 lbbox, | |
4779 stext, | |
4780 buttonbox, | |
4781 testwindow, | |
4782 testbox, | |
4783 testok, | |
4784 testcancel, | |
4785 testbox2, | |
4786 testok2, | |
4787 testcancel2, | |
4788 notebook; | |
4789 int count = 2; | |
4790 | |
4791 int test_callback(HWND window, void *data) | |
4792 { | |
4793 dw_window_destroy((HWND)data); | |
4794 /* Return -1 to allow the default handlers to return. */ | |
4795 count--; | |
4796 if(!count) | |
4797 exit(0); | |
4798 return -1; | |
4799 } | |
4800 | |
4801 /* | |
4802 * Let's demonstrate the functionality of this library. :) | |
4803 */ | |
4804 int main(void) | |
4805 { | |
4806 unsigned long flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR | | |
4807 DW_FCF_SHELLPOSITION | DW_FCF_TASKLIST | DW_FCF_DLGBORDER; | |
4808 int pageid; | |
4809 | |
4810 dw_init(TRUE); | |
4811 | |
4812 /* Try a little server dialog. :) */ | |
4813 mainwindow = dw_window_new(DW_DESKTOP, "Server", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX); | |
4814 | |
4815 lbbox = dw_box_new(BOXVERT, 10); | |
4816 | |
4817 dw_box_pack_start(mainwindow, lbbox, 0, 0, TRUE, TRUE, 0); | |
4818 | |
4819 stext = dw_text_new("Choose a server:", 0); | |
4820 | |
4821 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); | |
4822 | |
4823 dw_box_pack_start(lbbox, stext, 130, 15, FALSE, FALSE, 10); | |
4824 | |
4825 listbox = dw_listbox_new(100L, FALSE); | |
4826 | |
4827 dw_box_pack_start(lbbox, listbox, 130, 200, TRUE, TRUE, 10); | |
4828 | |
4829 buttonbox = dw_box_new(BOXHORZ, 0); | |
4830 | |
4831 dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0); | |
4832 | |
4833 okbutton = dw_button_new("Ok", 1001L); | |
4834 | |
4835 dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, TRUE, 5); | |
4836 | |
4837 cancelbutton = dw_button_new("Cancel", 1002L); | |
4838 | |
4839 dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, TRUE, 5); | |
4840 | |
4841 /* Set some nice fonts and colors */ | |
4842 dw_window_set_color(lbbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
4843 dw_window_set_color(buttonbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
4844 dw_window_set_font(stext, "9.WarpSans"); | |
4845 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); | |
4846 dw_window_set_font(listbox, "9.WarpSans"); | |
4847 dw_window_set_font(okbutton, "9.WarpSans"); | |
4848 dw_window_set_font(cancelbutton, "9.WarpSans"); | |
4849 | |
4850 dw_window_show(mainwindow); | |
4851 | |
4852 dw_window_set_usize(mainwindow, 170, 340); | |
4853 | |
4854 /* Another small example */ | |
4855 flStyle |= DW_FCF_MINMAX | DW_FCF_SIZEBORDER; | |
4856 | |
4857 testwindow = dw_window_new(DW_DESKTOP, "Wow a test dialog! :) yay!", flStyle); | |
4858 | |
4859 testbox = dw_box_new(BOXVERT, 0); | |
4860 | |
4861 dw_box_pack_start(testwindow, testbox, 0, 0, TRUE, TRUE, 0); | |
4862 | |
4863 notebook = dw_notebook_new(1010L, TRUE); | |
4864 | |
4865 dw_box_pack_start(testbox, notebook, 100, 100, TRUE, TRUE, 0); | |
4866 | |
4867 testbox = dw_box_new(BOXVERT, 10); | |
4868 | |
4869 pageid = dw_notebook_page_new(notebook, 0L, FALSE); | |
4870 | |
4871 dw_notebook_pack(notebook, pageid, testbox); | |
4872 | |
4873 dw_notebook_page_set_text(notebook, pageid, "Test page"); | |
4874 dw_notebook_page_set_status_text(notebook, pageid, "Test page"); | |
4875 | |
4876 testok = dw_button_new("Ok", 1003L); | |
4877 | |
4878 dw_box_pack_start(testbox, testok, 60, 40, TRUE, TRUE, 10); | |
4879 | |
4880 testcancel = dw_button_new("Cancel", 1004L); | |
4881 | |
4882 dw_box_pack_start(testbox, testcancel, 60, 40, TRUE, TRUE, 10); | |
4883 | |
4884 testbox2 = dw_box_new(BOXHORZ, 0); | |
4885 | |
4886 dw_box_pack_start(testbox, testbox2, 0, 0, TRUE, TRUE, 0); | |
4887 | |
4888 testok2 = dw_button_new("Ok", 1003L); | |
4889 | |
4890 dw_box_pack_start(testbox2, testok2, 60, 40, TRUE, TRUE, 10); | |
4891 | |
4892 dw_box_pack_splitbar_start(testbox2); | |
4893 | |
4894 testcancel2 = dw_button_new("Cancel", 1004L); | |
4895 | |
4896 dw_box_pack_start(testbox2, testcancel2, 60, 40, TRUE, TRUE, 10); | |
4897 | |
4898 /* Set some nice fonts and colors */ | |
4899 dw_window_set_color(testbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
4900 dw_window_set_color(testbox2, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
4901 dw_window_set_font(testok, "9.WarpSans"); | |
4902 dw_window_set_font(testcancel, "9.WarpSans"); | |
4903 dw_window_set_font(testok2, "9.WarpSans"); | |
4904 dw_window_set_font(testcancel2, "9.WarpSans"); | |
4905 | |
4906 dw_window_show(testwindow); | |
4907 | |
4908 /* Setup the function callbacks */ | |
4909 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
4910 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
4911 dw_signal_connect(testok, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
4912 dw_signal_connect(testcancel, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
4913 dw_signal_connect(testok2, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
4914 dw_signal_connect(testcancel2, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
4915 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
4916 dw_signal_connect(testwindow, "delete_event", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
4917 | |
4918 dw_main(0L, NULL); | |
4919 | |
4920 return 0; | |
4921 } | |
4922 #endif |