Mercurial > dwindows
annotate win/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 | 360bc6a5f1c9 |
rev | line source |
---|---|
3 | 1 /* |
2 * Dynamic Windows: | |
3 * A GTK like implementation of the Win32 GUI | |
4 * | |
5 * (C) 2000,2001 Brian Smith <dbsoft@technologist.com> | |
6 * | |
7 */ | |
8 #define _WIN32_IE 0x0500 | |
9 #define WINVER 0x400 | |
10 #include <windows.h> | |
11 #include <windowsx.h> | |
12 #include <commctrl.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
15 #include <stdio.h> | |
16 #include <process.h> | |
17 #include "dw.h" | |
18 | |
19 /* this is the callback handle for the window procedure */ | |
20 /* make sure you always match the calling convention! */ | |
21 int (*filterfunc)(HWND, UINT, WPARAM, LPARAM) = 0L; | |
22 | |
23 HWND hwndBubble = (HWND)NULL, hwndBubbleLast, DW_HWND_OBJECT = (HWND)NULL; | |
24 | |
25 HINSTANCE DWInstance = NULL; | |
26 | |
27 DWORD dwVersion = 0; | |
28 | |
29 /* I should probably check the actual file version, but this will do for now */ | |
30 #define IS_WIN98PLUS (LOBYTE(LOWORD(dwVersion)) > 4 || \ | |
31 (LOBYTE(LOWORD(dwVersion)) == 4 && HIBYTE(LOWORD(dwVersion)) > 0)) | |
32 | |
33 char monthlist[][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", | |
34 "Sep", "Oct", "Nov", "Dec" }; | |
35 | |
36 int main(int argc, char *argv[]); | |
37 | |
38 #define ICON_INDEX_LIMIT 200 | |
39 HICON lookup[200]; | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
40 HIMAGELIST hSmall = 0, hLarge = 0; |
3 | 41 |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
42 #define THREAD_LIMIT 128 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
43 COLORREF _foreground[THREAD_LIMIT]; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
44 COLORREF _background[THREAD_LIMIT]; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
45 HPEN _hPen[THREAD_LIMIT]; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
46 HBRUSH _hBrush[THREAD_LIMIT]; |
3 | 47 |
48 #ifdef DWDEBUG | |
49 FILE *f; | |
50 | |
51 void reopen(void) | |
52 { | |
53 fclose(f); | |
54 f = fopen("dw.log", "at"); | |
55 } | |
56 #endif | |
57 | |
58 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77, | |
59 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 }; | |
60 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77, | |
61 0x00, 0xff, 0xee, 0x00, 0x00, 0xee, 0xff, 0xaa, 0x00 }; | |
62 BYTE _blue[] = { 0x00, 0x00, 0x00, 0x00, 0xcc, 0xbb, 0xbb, 0xaa, 0x77, | |
63 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0xff, 0xaa, 0x00}; | |
64 | |
65 HBRUSH _colors[18]; | |
66 | |
67 static LONG lColor[SPLITBAR_WIDTH] = | |
68 { | |
69 DW_CLR_BLACK, | |
70 DW_CLR_PALEGRAY, | |
71 DW_CLR_WHITE | |
72 }; | |
73 | |
74 void _resize_notebook_page(HWND handle, int pageid); | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
75 int _lookup_icon(HWND handle, HICON hicon, int type); |
3 | 76 |
77 #ifdef NO_SIGNALS | |
78 #define USE_FILTER | |
79 #else | |
80 typedef struct _sighandler | |
81 { | |
82 struct _sighandler *next; | |
83 ULONG message; | |
84 HWND window; | |
85 void *signalfunction; | |
86 void *data; | |
87 | |
88 } SignalHandler; | |
89 | |
90 SignalHandler *Root = NULL; | |
91 int _index; | |
92 | |
93 typedef struct | |
94 { | |
95 ULONG message; | |
96 char name[30]; | |
97 | |
98 } SignalList; | |
99 | |
100 /* List of signals and their equivilent Win32 message */ | |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
101 #define SIGNALMAX 13 |
3 | 102 |
103 SignalList SignalTranslate[SIGNALMAX] = { | |
104 { WM_SIZE, "configure_event" }, | |
105 { WM_CHAR, "key_press_event" }, | |
106 { WM_LBUTTONDOWN, "button_press_event" }, | |
107 { WM_LBUTTONUP, "button_release_event" }, | |
108 { WM_MOUSEMOVE, "motion_notify_event" }, | |
109 { WM_CLOSE, "delete_event" }, | |
110 { WM_PAINT, "expose_event" }, | |
111 { WM_COMMAND, "clicked" }, | |
112 { NM_DBLCLK, "container-select" }, | |
113 { NM_RCLICK, "container-context" }, | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
114 { LBN_SELCHANGE, "item-select" }, |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
115 { TVN_SELCHANGED, "tree-select" }, |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
116 { WM_SETFOCUS, "set-focus" } |
3 | 117 }; |
118 | |
119 #ifdef BUILD_DLL | |
120 void Win32_Set_Instance(HINSTANCE hInstance) | |
121 { | |
122 DWInstance = hInstance; | |
123 } | |
124 #else | |
125 char **_convertargs(int *count, char *start) | |
126 { | |
127 char *tmp, *argstart, **argv; | |
128 int loc = 0, inquotes = 0; | |
129 | |
130 (*count) = 1; | |
131 | |
132 tmp = start; | |
133 | |
134 /* Count the number of entries */ | |
135 if(*start) | |
136 { | |
137 (*count)++; | |
138 | |
139 while(*tmp) | |
140 { | |
141 if(*tmp == '"' && inquotes) | |
142 inquotes = 0; | |
143 else if(*tmp == '"' && !inquotes) | |
144 inquotes = 1; | |
145 else if(*tmp == ' ' && !inquotes) | |
146 { | |
147 /* Push past any white space */ | |
148 while(*(tmp+1) == ' ') | |
149 tmp++; | |
150 /* If we aren't at the end of the command | |
151 * line increment the count. | |
152 */ | |
153 if(*(tmp+1)) | |
154 (*count)++; | |
155 } | |
156 tmp++; | |
157 } | |
158 } | |
159 | |
160 argv = (char **)malloc(sizeof(char *) * ((*count)+1)); | |
161 argv[0] = malloc(260); | |
162 GetModuleFileName(DWInstance, argv[0], 260); | |
163 | |
164 argstart = tmp = start; | |
165 | |
166 if(*start) | |
167 { | |
168 loc = 1; | |
169 | |
170 while(*tmp) | |
171 { | |
172 if(*tmp == '"' && inquotes) | |
173 { | |
174 *tmp = 0; | |
175 inquotes = 0; | |
176 } | |
177 else if(*tmp == '"' && !inquotes) | |
178 { | |
179 argstart = tmp+1; | |
180 inquotes = 1; | |
181 } | |
182 else if(*tmp == ' ' && !inquotes) | |
183 { | |
184 *tmp = 0; | |
185 argv[loc] = strdup(argstart); | |
186 | |
187 /* Push past any white space */ | |
188 while(*(tmp+1) == ' ') | |
189 tmp++; | |
190 | |
191 /* Move the start pointer */ | |
192 argstart = tmp+1; | |
193 | |
194 /* If we aren't at the end of the command | |
195 * line increment the count. | |
196 */ | |
197 if(*(tmp+1)) | |
198 loc++; | |
199 } | |
200 tmp++; | |
201 } | |
202 if(*argstart) | |
203 argv[loc] = strdup(argstart); | |
204 } | |
205 argv[loc+1] = NULL; | |
206 return argv; | |
207 } | |
208 | |
209 /* Ok this is a really big hack but what the hell ;) */ | |
210 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |
211 { | |
212 char **argv; | |
213 int argc; | |
214 | |
215 DWInstance = hInstance; | |
216 | |
217 argv = _convertargs(&argc, lpCmdLine); | |
218 | |
219 return main(argc, argv); | |
220 } | |
221 #endif | |
222 | |
223 /* This function adds a signal handler callback into the linked list. | |
224 */ | |
225 void _new_signal(ULONG message, HWND window, void *signalfunction, void *data) | |
226 { | |
227 SignalHandler *new = malloc(sizeof(SignalHandler)); | |
228 | |
229 new->message = message; | |
230 new->window = window; | |
231 new->signalfunction = signalfunction; | |
232 new->data = data; | |
233 new->next = NULL; | |
234 | |
235 if (!Root) | |
236 Root = new; | |
237 else | |
238 { | |
239 SignalHandler *prev = NULL, *tmp = Root; | |
240 while(tmp) | |
241 { | |
242 prev = tmp; | |
243 tmp = tmp->next; | |
244 } | |
245 if(prev) | |
246 prev->next = new; | |
247 else | |
248 Root = new; | |
249 } | |
250 } | |
251 | |
252 /* Finds the message number for a given signal name */ | |
253 ULONG _findsigmessage(char *signame) | |
254 { | |
255 int z; | |
256 | |
257 for(z=0;z<SIGNALMAX;z++) | |
258 { | |
259 if(stricmp(signame, SignalTranslate[z].name) == 0) | |
260 return SignalTranslate[z].message; | |
261 } | |
262 return 0L; | |
263 } | |
264 #endif | |
265 | |
266 /* This function removes and handlers on windows and frees | |
267 * the user memory allocated to it. | |
268 */ | |
269 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam) | |
270 { | |
271 void *ptr = (void *)GetWindowLong(handle, GWL_USERDATA); | |
272 | |
273 #ifndef NO_SIGNALS | |
274 dw_signal_disconnect_by_window(handle); | |
275 #endif | |
276 | |
277 if(ptr) | |
278 { | |
279 SetWindowLong(handle, GWL_USERDATA, 0); | |
280 free(ptr); | |
281 } | |
282 return TRUE; | |
283 } | |
284 | |
285 /* This function returns 1 if the window (widget) handle | |
286 * passed to it is a valid window that can gain input focus. | |
287 */ | |
288 int _validate_focus(HWND handle) | |
289 { | |
290 char tmpbuf[100]; | |
291 | |
292 if(!handle) | |
293 return 0; | |
294 | |
295 GetClassName(handle, tmpbuf, 99); | |
296 | |
297 /* These are the window classes which can | |
298 * obtain input focus. | |
299 */ | |
300 if(strnicmp(tmpbuf, EDITCLASSNAME, strlen(EDITCLASSNAME))==0 || /* Entryfield */ | |
301 strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME))==0 || /* Button */ | |
302 strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0 || /* Combobox */ | |
303 strnicmp(tmpbuf, LISTBOXCLASSNAME, strlen(LISTBOXCLASSNAME))==0 || /* List box */ | |
304 strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0 || /* Spinbutton */ | |
305 strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW))== 0) /* Container */ | |
306 return 1; | |
307 return 0; | |
308 } | |
309 | |
310 HWND _normalize_handle(HWND handle) | |
311 { | |
312 char tmpbuf[100] = ""; | |
313 | |
314 GetClassName(handle, tmpbuf, 99); | |
315 if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0) /* Spinner */ | |
316 { | |
317 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); | |
318 | |
319 if(cinfo && cinfo->buddy) | |
320 return cinfo->buddy; | |
321 } | |
322 return handle; | |
323 } | |
324 | |
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
|
325 int _focus_check_box(Box *box, HWND handle, int start, HWND defaultitem) |
3 | 326 { |
327 int z; | |
328 static HWND lasthwnd, firsthwnd; | |
329 static int finish_searching; | |
330 | |
331 /* Start is 2 when we have cycled completely and | |
332 * need to set the focus to the last widget we found | |
333 * that was valid. | |
334 */ | |
335 if(start == 2) | |
336 { | |
337 if(lasthwnd) | |
338 SetFocus(lasthwnd); | |
339 return 0; | |
340 } | |
341 | |
342 /* Start is 1 when we are entering the function | |
343 * for the first time, it is zero when entering | |
344 * the function recursively. | |
345 */ | |
346 if(start == 1) | |
347 { | |
348 lasthwnd = handle; | |
349 finish_searching = 0; | |
350 firsthwnd = 0; | |
351 } | |
352 | |
353 for(z=box->count-1;z>-1;z--) | |
354 { | |
355 if(box->items[z].type == TYPEBOX) | |
356 { | |
357 Box *thisbox = (Box *)GetWindowLong(box->items[z].hwnd, GWL_USERDATA); | |
358 | |
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
|
359 if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) |
3 | 360 return 1; |
361 } | |
362 else | |
363 { | |
364 if(box->items[z].hwnd == handle) | |
365 { | |
366 if(lasthwnd == handle && firsthwnd) | |
367 SetFocus(firsthwnd); | |
368 else if(lasthwnd == handle && !firsthwnd) | |
369 finish_searching = 1; | |
370 else | |
371 SetFocus(lasthwnd); | |
372 | |
373 /* If we aren't looking for the last handle, | |
374 * return immediately. | |
375 */ | |
376 if(!finish_searching) | |
377 return 1; | |
378 } | |
379 if(_validate_focus(box->items[z].hwnd)) | |
380 { | |
381 /* Start is 3 when we are looking for the | |
382 * first valid item in the layout. | |
383 */ | |
384 if(start == 3) | |
385 { | |
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
|
386 if(!defaultitem || (defaultitem && box->items[z].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
|
387 { |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
388 SetFocus(_normalize_handle(box->items[z].hwnd)); |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
389 return 1; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
390 } |
3 | 391 } |
392 | |
393 if(!firsthwnd) | |
394 firsthwnd = _normalize_handle(box->items[z].hwnd); | |
395 | |
396 lasthwnd = _normalize_handle(box->items[z].hwnd); | |
397 } | |
398 else | |
399 { | |
400 char tmpbuf[100] = ""; | |
401 | |
402 GetClassName(box->items[z].hwnd, tmpbuf, 99); | |
403 | |
404 if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) /* Notebook */ | |
405 { | |
406 NotebookPage **array = (NotebookPage **)GetWindowLong(box->items[z].hwnd, GWL_USERDATA); | |
407 int pageid = TabCtrl_GetCurSel(box->items[z].hwnd); | |
408 | |
409 if(pageid > -1 && array && array[pageid]) | |
410 { | |
411 Box *notebox; | |
412 | |
413 if(array[pageid]->hwnd) | |
414 { | |
415 notebox = (Box *)GetWindowLong(array[pageid]->hwnd, GWL_USERDATA); | |
416 | |
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
|
417 if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0, defaultitem)) |
3 | 418 return 1; |
419 } | |
420 } | |
421 } | |
422 } | |
423 } | |
424 } | |
425 return 0; | |
426 } | |
427 | |
428 /* This function finds the first widget in the | |
429 * layout and moves the current focus to it. | |
430 */ | |
431 void _initial_focus(HWND handle) | |
432 { | |
433 Box *thisbox; | |
434 | |
435 if(handle) | |
436 thisbox = (Box *)GetWindowLong(handle, GWL_USERDATA); | |
437 | |
438 if(thisbox) | |
439 { | |
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
|
440 _focus_check_box(thisbox, handle, 3, thisbox->defaultitem); |
3 | 441 } |
442 } | |
443 | |
444 /* This function finds the current widget in the | |
445 * layout and moves the current focus to the next item. | |
446 */ | |
447 void _shift_focus(HWND handle) | |
448 { | |
449 Box *thisbox; | |
450 | |
451 HWND box, lastbox = GetParent(handle); | |
452 | |
453 /* Find the toplevel window */ | |
454 while((box = GetParent(lastbox))) | |
455 { | |
456 lastbox = box; | |
457 } | |
458 | |
459 thisbox = (Box *)GetWindowLong(lastbox, GWL_USERDATA); | |
460 if(thisbox) | |
461 { | |
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
|
462 if(_focus_check_box(thisbox, handle, 1, 0) == 0) |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
463 _focus_check_box(thisbox, handle, 2, 0); |
3 | 464 } |
465 } | |
466 | |
467 /* ResetWindow: | |
468 * Resizes window to the exact same size to trigger | |
469 * recalculation of frame. | |
470 */ | |
471 void _ResetWindow(HWND hwndFrame) | |
472 { | |
473 RECT rcl; | |
474 | |
475 GetWindowRect(hwndFrame, &rcl); | |
476 SetWindowPos(hwndFrame, HWND_TOP, 0, 0, rcl.right - rcl.left, | |
477 rcl.bottom - rcl.top - 1, SWP_NOMOVE | SWP_NOZORDER); | |
478 SetWindowPos(hwndFrame, HWND_TOP, 0, 0, rcl.right - rcl.left, | |
479 rcl.bottom - rcl.top, SWP_NOMOVE | SWP_NOZORDER); | |
480 } | |
481 | |
482 /* Function: TrackRectangle | |
483 * Abstract: Tracks given rectangle. | |
484 * | |
485 * If rclBounds is NULL, then track rectangle on entire desktop. | |
486 * rclTrack is in window coorditates and will be mapped to | |
487 * desktop. | |
488 */ | |
489 | |
490 BOOL _TrackRectangle(HWND hwndBase, RECTL* rclTrack, RECTL* rclBounds) | |
491 { | |
492 ULONG rc = 0; | |
493 #if 0 | |
494 TRACKINFO track; | |
495 | |
496 track.cxBorder = 1; | |
497 track.cyBorder = 1; | |
498 track.cxGrid = 1; | |
499 track.cyGrid = 1; | |
500 track.cxKeyboard = 8; | |
501 track.cyKeyboard = 8; | |
502 | |
503 if(!rclTrack) | |
504 return FALSE; | |
505 | |
506 if(rclBounds) | |
507 { | |
508 track.rclBoundary = *rclBounds; | |
509 } | |
510 else | |
511 { | |
512 track.rclBoundary.yTop = | |
513 track.rclBoundary.xRight = 3000; | |
514 track.rclBoundary.yBottom = | |
515 track.rclBoundary.xLeft = -3000; | |
516 } | |
517 | |
518 track.rclTrack = *rclTrack; | |
519 | |
520 MapWindowPoints(hwndBase, | |
521 HWND_DESKTOP, | |
522 (PPOINT)&track.rclTrack, | |
523 2); | |
524 | |
525 track.ptlMinTrackSize.x = track.rclTrack.xRight | |
526 - track.rclTrack.xLeft; | |
527 track.ptlMinTrackSize.y = track.rclTrack.yTop | |
528 - track.rclTrack.yBottom; | |
529 track.ptlMaxTrackSize.x = track.rclTrack.xRight | |
530 - track.rclTrack.xLeft; | |
531 track.ptlMaxTrackSize.y = track.rclTrack.yTop | |
532 - track.rclTrack.yBottom; | |
533 | |
534 track.fs = TF_MOVE | TF_ALLINBOUNDARY; | |
535 | |
536 rc = WinTrackRect(HWND_DESKTOP, 0, &track); | |
537 | |
538 if(rc) | |
539 *rclTrack = track.rclTrack; | |
540 | |
541 #endif | |
542 return rc; | |
543 } | |
544 | |
545 /* This function calculates how much space the widgets and boxes require | |
546 * and does expansion as necessary. | |
547 */ | |
548 int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, | |
549 int pass, int *usedpadx, int *usedpady) | |
550 { | |
551 int z, currentx = 0, currenty = 0; | |
552 int uymax = 0, uxmax = 0; | |
553 int upymax = 0, upxmax = 0; | |
554 /* Used for the SIZEEXPAND */ | |
555 int nux = *usedx, nuy = *usedy; | |
556 int nupx = *usedpadx, nupy = *usedpady; | |
557 | |
558 (*usedx) += (thisbox->pad * 2); | |
559 (*usedy) += (thisbox->pad * 2); | |
560 | |
561 for(z=0;z<thisbox->count;z++) | |
562 { | |
563 if(thisbox->items[z].type == TYPEBOX) | |
564 { | |
565 int initialx, initialy; | |
566 Box *tmp = (Box *)GetWindowLong(thisbox->items[z].hwnd, GWL_USERDATA); | |
567 | |
568 initialx = x - (*usedx); | |
569 initialy = y - (*usedy); | |
570 | |
571 if(tmp) | |
572 { | |
573 int newx, newy; | |
574 int nux = *usedx, nuy = *usedy; | |
575 int upx = *usedpadx + (tmp->pad*2), upy = *usedpady + (tmp->pad*2); | |
576 | |
577 /* On the second pass we know how big the box needs to be and how | |
578 * much space we have, so we can calculate a ratio for the new box. | |
579 */ | |
580 if(pass == 2) | |
581 { | |
582 int deep = *depth + 1; | |
583 | |
584 _resize_box(tmp, &deep, x, y, &nux, &nuy, 1, &upx, &upy); | |
585 | |
586 tmp->upx = upx - *usedpadx; | |
587 tmp->upy = upy - *usedpady; | |
588 | |
589 newx = x - nux; | |
590 newy = y - nuy; | |
591 | |
592 tmp->width = thisbox->items[z].width = initialx - newx; | |
593 tmp->height = thisbox->items[z].height = initialy - newy; | |
594 | |
595 tmp->parentxratio = thisbox->xratio; | |
596 tmp->parentyratio = thisbox->yratio; | |
597 | |
598 tmp->parentpad = tmp->pad; | |
599 | |
600 /* Just in case */ | |
601 tmp->xratio = thisbox->xratio; | |
602 tmp->yratio = thisbox->yratio; | |
603 | |
604 #ifdef DWDEBUG | |
605 if(pass > 1) | |
606 { | |
607 fprintf(f, "FARK! depth %d\r\nwidth = %d, height = %d, nux = %d, nuy = %d, upx = %d, upy = %d xratio = %f, yratio = %f\r\n\r\n", | |
608 *depth, thisbox->items[z].width, thisbox->items[z].height, nux, nuy, tmp->upx, tmp->upy, tmp->xratio, tmp->yratio); | |
609 reopen(); | |
610 } | |
611 #endif | |
612 if(thisbox->type == BOXVERT) | |
613 { | |
614 if((thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0) | |
615 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(tmp->pad*2))))/((float)(thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))); | |
616 } | |
617 else | |
618 { | |
619 if((thisbox->items[z].width-tmp->upx)!=0) | |
620 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx))/((float)(thisbox->items[z].width-tmp->upx)); | |
621 } | |
622 if(thisbox->type == BOXHORZ) | |
623 { | |
624 if((thisbox->items[z].height-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0) | |
625 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(tmp->pad*2))))/((float)(thisbox->items[z].height-((thisbox->items[z].pad*2)+(tmp->pad*2)))); | |
626 } | |
627 else | |
628 { | |
629 if((thisbox->items[z].height-tmp->upy)!=0) | |
630 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(thisbox->items[z].height-tmp->upy)); | |
631 } | |
632 | |
633 nux = *usedx; nuy = *usedy; | |
634 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); | |
635 } | |
636 | |
637 (*depth)++; | |
638 | |
639 #ifdef DWDEBUG | |
640 if(pass > 1) | |
641 { | |
642 fprintf(f, "Before Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f\r\n\r\n", | |
643 *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio); | |
644 reopen(); | |
645 } | |
646 #endif | |
647 | |
648 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); | |
649 | |
650 (*depth)--; | |
651 | |
652 newx = x - nux; | |
653 newy = y - nuy; | |
654 | |
655 tmp->minwidth = thisbox->items[z].width = initialx - newx; | |
656 tmp->minheight = thisbox->items[z].height = initialy - newy; | |
657 | |
658 #ifdef DWDEBUG | |
659 if(pass > 1) | |
660 { | |
661 fprintf(f, "After Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d width = %d, height = %d\r\n\r\n", | |
662 *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, thisbox->items[z].width, thisbox->items[z].height); | |
663 reopen(); | |
664 } | |
665 #endif | |
666 } | |
667 } | |
668 | |
669 if(pass > 1 && *depth > 0) | |
670 { | |
671 if(thisbox->type == BOXVERT) | |
672 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minwidth-((thisbox->items[z].pad*2)+(thisbox->parentpad*2)))); | |
673 else | |
674 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-thisbox->upx))/((float)(thisbox->minwidth-thisbox->upx)); | |
675 | |
676 if(thisbox->type == BOXHORZ) | |
677 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minheight-((thisbox->items[z].pad*2)+(thisbox->parentpad*2)))); | |
678 else | |
679 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
680 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
681 if(thisbox->items[z].type == TYPEBOX) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
682 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
683 Box *tmp = (Box *)GetWindowLong(thisbox->items[z].hwnd, GWL_USERDATA); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
684 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
685 if(tmp) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
686 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
687 tmp->parentxratio = thisbox->items[z].xratio; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
688 tmp->parentyratio = thisbox->items[z].yratio; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
689 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
690 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
691 |
3 | 692 #ifdef DWDEBUG |
693 fprintf(f, "RATIO- xratio = %f, yratio = %f, width = %d, height = %d, pad = %d, box xratio = %f, box yratio = %f, parent xratio = %f, parent yratio = %f, minwidth = %d, minheight = %d, width = %d, height = %d, upx = %d, upy = %d\r\n\r\n", | |
694 thisbox->items[z].xratio, thisbox->items[z].yratio, thisbox->items[z].width, thisbox->items[z].height, thisbox->items[z].pad, thisbox->xratio, thisbox->yratio, thisbox->parentxratio, thisbox->parentyratio, thisbox->minwidth, thisbox->minheight, thisbox->width, thisbox->height, thisbox->upx, thisbox->upy); | |
695 reopen(); | |
696 #endif | |
697 } | |
698 else | |
699 { | |
700 thisbox->items[z].xratio = thisbox->xratio; | |
701 thisbox->items[z].yratio = thisbox->yratio; | |
702 } | |
703 | |
704 if(thisbox->type == BOXVERT) | |
705 { | |
706 if((thisbox->items[z].width + (thisbox->items[z].pad*2)) > uxmax) | |
707 uxmax = (thisbox->items[z].width + (thisbox->items[z].pad*2)); | |
708 if(thisbox->items[z].hsize != SIZEEXPAND) | |
709 { | |
710 if(((thisbox->items[z].pad*2) + thisbox->items[z].width) > upxmax) | |
711 upxmax = (thisbox->items[z].pad*2) + thisbox->items[z].width; | |
712 } | |
713 else | |
714 { | |
715 if(thisbox->items[z].pad*2 > upxmax) | |
716 upxmax = thisbox->items[z].pad*2; | |
717 } | |
718 } | |
719 else | |
720 { | |
721 if(thisbox->items[z].width == -1) | |
722 { | |
723 /* figure out how much space this item requires */ | |
724 /* thisbox->items[z].width = */ | |
725 } | |
726 else | |
727 { | |
728 (*usedx) += thisbox->items[z].width + (thisbox->items[z].pad*2); | |
729 if(thisbox->items[z].hsize != SIZEEXPAND) | |
730 (*usedpadx) += (thisbox->items[z].pad*2) + thisbox->items[z].width; | |
731 else | |
732 (*usedpadx) += thisbox->items[z].pad*2; | |
733 } | |
734 } | |
735 if(thisbox->type == BOXHORZ) | |
736 { | |
737 if((thisbox->items[z].height + (thisbox->items[z].pad*2)) > uymax) | |
738 uymax = (thisbox->items[z].height + (thisbox->items[z].pad*2)); | |
739 if(thisbox->items[z].vsize != SIZEEXPAND) | |
740 { | |
741 if(((thisbox->items[z].pad*2) + thisbox->items[z].height) > upymax) | |
742 upymax = (thisbox->items[z].pad*2) + thisbox->items[z].height; | |
743 } | |
744 else | |
745 { | |
746 if(thisbox->items[z].pad*2 > upymax) | |
747 upymax = thisbox->items[z].pad*2; | |
748 } | |
749 } | |
750 else | |
751 { | |
752 if(thisbox->items[z].height == -1) | |
753 { | |
754 /* figure out how much space this item requires */ | |
755 /* thisbox->items[z].height = */ | |
756 } | |
757 else | |
758 { | |
759 (*usedy) += thisbox->items[z].height + (thisbox->items[z].pad*2); | |
760 if(thisbox->items[z].vsize != SIZEEXPAND) | |
761 (*usedpady) += (thisbox->items[z].pad*2) + thisbox->items[z].height; | |
762 else | |
763 (*usedpady) += thisbox->items[z].pad*2; | |
764 } | |
765 } | |
766 } | |
767 | |
768 (*usedx) += uxmax; | |
769 (*usedy) += uymax; | |
770 (*usedpadx) += upxmax; | |
771 (*usedpady) += upymax; | |
772 | |
773 currentx += thisbox->pad; | |
774 currenty += thisbox->pad; | |
775 | |
776 #ifdef DWDEBUG | |
777 fprintf(f, "Done Calc depth %d\r\nusedx = %d, usedy = %d, usedpadx = %d, usedpady = %d, currentx = %d, currenty = %d, uxmax = %d, uymax = %d\r\n\r\n", | |
778 *depth, *usedx, *usedy, *usedpadx, *usedpady, currentx, currenty, uxmax, uymax); | |
779 reopen(); | |
780 #endif | |
781 | |
782 /* The second pass is for expansion and actual placement. */ | |
783 if(pass > 1) | |
784 { | |
785 /* Any SIZEEXPAND items should be set to uxmax/uymax */ | |
786 for(z=0;z<thisbox->count;z++) | |
787 { | |
788 if(thisbox->items[z].hsize == SIZEEXPAND && thisbox->type == BOXVERT) | |
789 thisbox->items[z].width = uxmax-(thisbox->items[z].pad*2); | |
790 if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == BOXHORZ) | |
791 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2); | |
792 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */ | |
793 if(thisbox->items[z].type == TYPEBOX) | |
794 { | |
795 Box *tmp = (Box *)GetWindowLong(thisbox->items[z].hwnd, GWL_USERDATA); | |
796 | |
797 if(tmp) | |
798 { | |
799 if(*depth > 0) | |
800 { | |
801 if(thisbox->type == BOXVERT) | |
802 { | |
803 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/((float)(tmp->minwidth-((thisbox->items[z].pad*2)+(thisbox->pad*2)))); | |
804 tmp->width = thisbox->items[z].width; | |
805 } | |
806 if(thisbox->type == BOXHORZ) | |
807 { | |
808 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/((float)(tmp->minheight-((thisbox->items[z].pad*2)+(thisbox->pad*2)))); | |
809 tmp->height = thisbox->items[z].height; | |
810 } | |
811 } | |
812 | |
813 (*depth)++; | |
814 | |
815 /*tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx) )/((float)(tmp->minwidth-tmp->upx)); | |
816 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(tmp->minheight-tmp->upy));*/ | |
817 | |
818 #ifdef DWDEBUG | |
819 fprintf(f, "2- Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f,\r\nupx = %d, upy = %d, width = %d, height = %d, minwidth = %d, minheight = %d, box xratio = %f, box yratio = %f\r\n\r\n", | |
820 *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio, tmp->upx, tmp->upy, thisbox->items[z].width, thisbox->items[z].height, tmp->minwidth, tmp->minheight, thisbox->xratio, thisbox->yratio); | |
821 reopen(); | |
822 #endif | |
823 | |
824 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); | |
825 | |
826 (*depth)--; | |
827 | |
828 } | |
829 } | |
830 } | |
831 | |
832 for(z=0;z<(thisbox->count);z++) | |
833 { | |
834 int height = thisbox->items[z].height; | |
835 int width = thisbox->items[z].width; | |
836 int pad = thisbox->items[z].pad; | |
837 HWND handle = thisbox->items[z].hwnd; | |
838 int vectorx, vectory; | |
839 | |
840 /* When upxmax != pad*2 then ratios are incorrect. */ | |
841 vectorx = (int)((width*thisbox->items[z].xratio)-width); | |
842 vectory = (int)((height*thisbox->items[z].yratio)-height); | |
843 | |
844 if(width > 0 && height > 0) | |
845 { | |
846 char tmpbuf[100]; | |
847 /* This is a hack to fix rounding of the sizing */ | |
848 if(*depth == 0) | |
849 { | |
850 vectorx++; | |
851 vectory++; | |
852 } | |
853 | |
854 /* If this item isn't going to expand... reset the vectors to 0 */ | |
855 if(thisbox->items[z].vsize != SIZEEXPAND) | |
856 vectory = 0; | |
857 if(thisbox->items[z].hsize != SIZEEXPAND) | |
858 vectorx = 0; | |
859 | |
860 GetClassName(handle, tmpbuf, 99); | |
861 | |
862 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0) | |
863 { | |
864 /* Handle special case Combobox */ | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
865 MoveWindow(handle, currentx + pad, currenty + pad, |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
866 width + vectorx, (height + vectory) + 400, TRUE); |
3 | 867 } |
868 else if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0) | |
869 { | |
870 /* Handle special case Spinbutton */ | |
871 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); | |
872 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
873 MoveWindow(handle, currentx + pad + ((width + vectorx) - 20), currenty + pad, |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
874 20, height + vectory, TRUE); |
3 | 875 |
876 if(cinfo) | |
877 { | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
878 MoveWindow(cinfo->buddy, currentx + pad, currenty + pad, |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
879 (width + vectorx) - 20, height + vectory, TRUE); |
3 | 880 } |
881 } | |
882 else | |
883 { | |
884 /* Everything else */ | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
885 MoveWindow(handle, currentx + pad, currenty + pad, |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
886 width + vectorx, height + vectory, TRUE); |
3 | 887 if(thisbox->items[z].type == TYPEBOX) |
888 { | |
889 Box *boxinfo = (Box *)GetWindowLong(handle, GWL_USERDATA); | |
890 | |
891 if(boxinfo && boxinfo->grouphwnd) | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
892 MoveWindow(boxinfo->grouphwnd, 0, 0, |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
893 width + vectorx, height + vectory, TRUE); |
3 | 894 |
895 } | |
896 } | |
897 | |
898 /* Notebook dialog requires additional processing */ | |
899 if(strncmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) | |
900 { | |
901 RECT rect; | |
902 NotebookPage **array = (NotebookPage **)GetWindowLong(handle, GWL_USERDATA); | |
903 int pageid = TabCtrl_GetCurSel(handle); | |
904 | |
905 if(pageid > -1 && array && array[pageid]) | |
906 { | |
907 GetClientRect(handle,&rect); | |
908 TabCtrl_AdjustRect(handle,FALSE,&rect); | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
909 MoveWindow(array[pageid]->hwnd, rect.left, rect.top, |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
910 rect.right - rect.left, rect.bottom-rect.top, TRUE); |
3 | 911 } |
912 } | |
913 | |
914 #ifdef DWDEBUG | |
915 fprintf(f, "Window Pos depth %d\r\ncurrentx = %d, currenty = %d, pad = %d, width = %d, height = %d, vectorx = %d, vectory = %d, Box type = %s\r\n\r\n", | |
916 *depth, currentx, currenty, pad, width, height, vectorx, vectory,thisbox->type == BOXHORZ ? "Horizontal" : "Vertical"); | |
917 reopen(); | |
918 #endif | |
919 | |
920 if(thisbox->type == BOXHORZ) | |
921 currentx += width + vectorx + (pad * 2); | |
922 if(thisbox->type == BOXVERT) | |
923 currenty += height + vectory + (pad * 2); | |
924 } | |
925 } | |
926 } | |
927 return 0; | |
928 } | |
929 | |
930 void _do_resize(Box *thisbox, int x, int y) | |
931 { | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
932 if(x != 0 && y != 0) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
933 { |
3 | 934 if(thisbox) |
935 { | |
936 int usedx = 0, usedy = 0, depth = 0, usedpadx = 0, usedpady = 0; | |
937 | |
938 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady); | |
939 | |
940 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx)); | |
941 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady)); | |
942 | |
943 #ifdef DWDEBUG | |
944 fprintf(f, "WM_SIZE Resize Box Pass 1\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f\r\n\r\n", | |
945 x, y, usedx, usedy, usedpadx, usedpady, thisbox->xratio, thisbox->yratio); | |
946 reopen(); | |
947 #endif | |
948 | |
949 usedpadx = usedpady = usedx = usedy = depth = 0; | |
950 | |
951 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
952 |
3 | 953 #ifdef DWDEBUG |
954 fprintf(f, "WM_SIZE Resize Box Pass 2\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d\r\n", | |
955 x, y, usedx, usedy, usedpadx, usedpady); | |
956 reopen(); | |
957 #endif | |
958 } | |
959 } | |
960 } | |
961 | |
962 /* The main window procedure for Dynamic Windows, all the resizing code is done here. */ | |
963 BOOL CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | |
964 { | |
965 int result = -1; | |
966 static int command_active = 0; | |
967 #ifndef NO_SIGNALS | |
968 SignalHandler *tmp = Root; | |
969 #endif | |
970 void (* windowfunc)(PVOID); | |
971 ULONG origmsg = msg; | |
972 | |
973 if(msg == WM_RBUTTONDOWN || msg == WM_MBUTTONDOWN) | |
974 msg = WM_LBUTTONDOWN; | |
975 if(msg == WM_RBUTTONUP || msg == WM_MBUTTONUP) | |
976 msg = WM_LBUTTONUP; | |
977 | |
978 if(filterfunc) | |
979 result = filterfunc(hWnd, msg, mp1, mp2); | |
980 | |
981 #ifndef NO_SIGNALS | |
982 if(result == -1) | |
983 { | |
984 /* Avoid infinite recursion */ | |
985 command_active = 1; | |
986 | |
987 /* Find any callbacks for this function */ | |
988 while(tmp) | |
989 { | |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
990 if(tmp->message == msg || msg == WM_COMMAND || msg == WM_NOTIFY) |
3 | 991 { |
992 switch(msg) | |
993 { | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
994 case WM_SETFOCUS: |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
995 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
996 int (*setfocusfunc)(HWND, void *) = (int (*)(HWND, void *))tmp->signalfunction; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
997 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
998 if(hWnd == tmp->window) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
999 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1000 result = setfocusfunc(tmp->window, tmp->data); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1001 tmp = NULL; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1002 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1003 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
1004 break; |
3 | 1005 case WM_SIZE: |
1006 { | |
1007 int (*sizefunc)(HWND, int, int, void *) = tmp->signalfunction; | |
1008 | |
1009 if(hWnd == tmp->window) | |
1010 { | |
1011 result = sizefunc(tmp->window, LOWORD(mp2), HIWORD(mp2), tmp->data); | |
1012 tmp = NULL; | |
1013 } | |
1014 } | |
1015 break; | |
1016 case WM_LBUTTONDOWN: | |
1017 { | |
1018 POINTS pts = MAKEPOINTS(mp2); | |
1019 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; | |
1020 | |
1021 if(hWnd == tmp->window) | |
1022 { | |
1023 int button; | |
1024 | |
1025 switch(origmsg) | |
1026 { | |
1027 case WM_LBUTTONDOWN: | |
1028 button = 1; | |
1029 break; | |
1030 case WM_RBUTTONDOWN: | |
1031 button = 2; | |
1032 break; | |
1033 case WM_MBUTTONDOWN: | |
1034 button = 3; | |
1035 break; | |
1036 } | |
1037 result = buttonfunc(tmp->window, pts.x, pts.y, button, tmp->data); | |
1038 tmp = NULL; | |
1039 } | |
1040 } | |
1041 break; | |
1042 case WM_LBUTTONUP: | |
1043 { | |
1044 POINTS pts = MAKEPOINTS(mp2); | |
1045 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; | |
1046 | |
1047 if(hWnd == tmp->window) | |
1048 { | |
1049 int button; | |
1050 | |
1051 switch(origmsg) | |
1052 { | |
1053 case WM_LBUTTONUP: | |
1054 button = 1; | |
1055 break; | |
1056 case WM_RBUTTONUP: | |
1057 button = 2; | |
1058 break; | |
1059 case WM_MBUTTONUP: | |
1060 button = 3; | |
1061 break; | |
1062 } | |
1063 result = buttonfunc(tmp->window, pts.x, pts.y, button, tmp->data); | |
1064 tmp = NULL; | |
1065 } | |
1066 } | |
1067 break; | |
1068 case WM_MOUSEMOVE: | |
1069 { | |
1070 POINTS pts = MAKEPOINTS(mp2); | |
1071 int (*motionfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; | |
1072 | |
1073 if(hWnd == tmp->window) | |
1074 { | |
1075 int keys = 0; | |
1076 | |
1077 if (mp1 & MK_LBUTTON) | |
1078 keys = DW_BUTTON1_MASK; | |
1079 if (mp1 & MK_RBUTTON) | |
1080 keys |= DW_BUTTON2_MASK; | |
1081 if (mp1 & MK_MBUTTON) | |
1082 keys |= DW_BUTTON3_MASK; | |
1083 | |
1084 result = motionfunc(tmp->window, pts.x, pts.y, keys, tmp->data); | |
1085 tmp = NULL; | |
1086 } | |
1087 } | |
1088 break; | |
1089 case WM_CHAR: | |
1090 { | |
1091 int (*keypressfunc)(HWND, int, void *) = tmp->signalfunction; | |
1092 | |
1093 if(hWnd == tmp->window) | |
1094 { | |
1095 result = keypressfunc(tmp->window, LOWORD(mp2), tmp->data); | |
1096 tmp = NULL; | |
1097 } | |
1098 } | |
1099 break; | |
1100 case WM_CLOSE: | |
1101 { | |
1102 int (*closefunc)(HWND, void *) = tmp->signalfunction; | |
1103 | |
1104 if(hWnd == tmp->window) | |
1105 { | |
1106 result = closefunc(tmp->window, tmp->data); | |
1107 tmp = NULL; | |
1108 } | |
1109 } | |
1110 break; | |
1111 case WM_PAINT: | |
1112 { | |
1113 PAINTSTRUCT ps; | |
1114 DWExpose exp; | |
1115 int (*exposefunc)(HWND, DWExpose *, void *) = tmp->signalfunction; | |
1116 | |
1117 if(hWnd == tmp->window) | |
1118 { | |
1119 BeginPaint(hWnd, &ps); | |
1120 exp.x = ps.rcPaint.left; | |
1121 exp.y = ps.rcPaint.top; | |
1122 exp.width = ps.rcPaint.right - ps.rcPaint.left; | |
1123 exp.height = ps.rcPaint.bottom - ps.rcPaint.top; | |
1124 result = exposefunc(hWnd, &exp, tmp->data); | |
1125 EndPaint(hWnd, &ps); | |
1126 } | |
1127 } | |
1128 break; | |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1129 case WM_NOTIFY: |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1130 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1131 if(tmp->message == TVN_SELCHANGED) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1132 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1133 NMTREEVIEW FAR *tem=(NMTREEVIEW FAR *)mp2; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1134 char tmpbuf[100]; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1135 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1136 GetClassName(tem->hdr.hwndFrom, tmpbuf, 99); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1137 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1138 if(strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW))==0) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1139 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1140 if(tem->hdr.code == TVN_SELCHANGED) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1141 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1142 if(tmp->window == tem->hdr.hwndFrom) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1143 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1144 int (*treeselectfunc)(HWND, HWND, char *, void *) = tmp->signalfunction; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1145 TVITEM tvi; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1146 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1147 tvi.mask = TVIF_HANDLE; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1148 tvi.hItem = tem->itemNew.hItem; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1149 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1150 TreeView_GetItem(tmp->window, &tvi); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1151 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1152 result = treeselectfunc(tmp->window, (HWND)tem->itemNew.hItem, (char *)tvi.lParam, tmp->data); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1153 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1154 tmp = NULL; |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1155 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1156 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1157 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1158 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1159 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
1160 break; |
3 | 1161 case WM_COMMAND: |
1162 { | |
1163 int (*clickfunc)(HWND, void *) = tmp->signalfunction; | |
1164 HWND command; | |
1165 ULONG passthru = (ULONG)LOWORD(mp1); | |
1166 ULONG message = HIWORD(mp1); | |
1167 | |
1168 command = (HWND)passthru; | |
1169 | |
1170 if(message == LBN_SELCHANGE || message == CBN_SELCHANGE) | |
1171 { | |
1172 int (*listboxselectfunc)(HWND, int, void *) = tmp->signalfunction; | |
1173 | |
1174 if(tmp->message == LBN_SELCHANGE && tmp->window == (HWND)mp2) | |
1175 { | |
1176 result = listboxselectfunc(tmp->window, dw_listbox_selected(tmp->window), tmp->data); | |
1177 tmp = NULL; | |
1178 } | |
1179 } /* Make sure it's the right window, and the right ID */ | |
1180 else if(tmp->window < (HWND)65536 && command == tmp->window) | |
1181 { | |
1182 result = clickfunc(tmp->window, tmp->data); | |
1183 tmp = NULL; | |
1184 } | |
1185 } | |
1186 break; | |
1187 } | |
1188 } | |
1189 if(tmp) | |
1190 tmp = tmp->next; | |
1191 } | |
1192 command_active = 0; | |
1193 } | |
1194 #endif | |
1195 | |
1196 /* Now that any handlers are done... do normal processing */ | |
1197 switch( msg ) | |
1198 { | |
1199 case WM_PAINT: | |
1200 { | |
1201 PAINTSTRUCT ps; | |
1202 | |
1203 BeginPaint(hWnd, &ps); | |
1204 EndPaint(hWnd, &ps); | |
1205 } | |
1206 break; | |
1207 case WM_SIZE: | |
1208 { | |
1209 static int lastx = -1, lasty = -1; | |
1210 static HWND lasthwnd = 0; | |
1211 | |
1212 if(lastx != LOWORD(mp2) || lasty != HIWORD(mp2) || lasthwnd != hWnd) | |
1213 { | |
1214 Box *mybox = (Box *)GetWindowLong(hWnd, GWL_USERDATA); | |
1215 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1216 if(mybox && mybox->count) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1217 { |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1218 lastx = LOWORD(mp2); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1219 lasty = HIWORD(mp2); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1220 lasthwnd = hWnd; |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1221 |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1222 ShowWindow(mybox->items[0].hwnd, SW_HIDE); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1223 _do_resize(mybox,LOWORD(mp2),HIWORD(mp2)); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1224 ShowWindow(mybox->items[0].hwnd, SW_SHOW); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1225 return 0; |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1226 } |
3 | 1227 } |
1228 } | |
1229 break; | |
1230 case WM_CHAR: | |
1231 if(LOWORD(mp1) == '\t') | |
1232 { | |
1233 _shift_focus(hWnd); | |
1234 return TRUE; | |
1235 } | |
1236 break; | |
1237 case WM_USER: | |
1238 windowfunc = (void *)mp1; | |
1239 | |
1240 if(windowfunc) | |
1241 windowfunc((void *)mp2); | |
1242 break; | |
1243 case WM_NOTIFY: | |
1244 { | |
1245 NMHDR FAR *tem=(NMHDR FAR *)mp2; | |
1246 | |
1247 if(tem->code == TCN_SELCHANGING) | |
1248 { | |
1249 int num=TabCtrl_GetCurSel(tem->hwndFrom); | |
1250 NotebookPage **array = (NotebookPage **)GetWindowLong(tem->hwndFrom, GWL_USERDATA); | |
1251 | |
1252 if(num > -1 && array && array[num]) | |
1253 SetParent(array[num]->hwnd, DW_HWND_OBJECT); | |
1254 | |
1255 } | |
1256 else if(tem->code == TCN_SELCHANGE) | |
1257 { | |
1258 int num=TabCtrl_GetCurSel(tem->hwndFrom); | |
1259 NotebookPage **array = (NotebookPage **)GetWindowLong(tem->hwndFrom, GWL_USERDATA); | |
1260 | |
1261 if(num > -1 && array && array[num]) | |
1262 SetParent(array[num]->hwnd, tem->hwndFrom); | |
1263 | |
1264 _resize_notebook_page(tem->hwndFrom, num); | |
1265 } | |
1266 } | |
1267 break; | |
1268 case WM_GETMINMAXINFO: | |
1269 { | |
1270 MINMAXINFO *info = (MINMAXINFO *)mp2; | |
1271 info->ptMinTrackSize.x = 8; | |
1272 info->ptMinTrackSize.y = 8; | |
1273 return 0; | |
1274 } | |
1275 break; | |
1276 case WM_DESTROY: | |
1277 /* Free memory before destroying */ | |
1278 #if 0 | |
1279 /* Is this the right message? I seem to be | |
1280 * getting WM_DESTROY on windows that aren't | |
1281 * being destroyed. | |
1282 */ | |
1283 _free_window_memory(hWnd, 0); | |
1284 EnumChildWindows(hWnd, _free_window_memory, 0); | |
1285 #endif | |
1286 break; | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1287 case WM_CTLCOLORSTATIC: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1288 case WM_CTLCOLORLISTBOX: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1289 case WM_CTLCOLORBTN: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1290 case WM_CTLCOLOREDIT: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1291 case WM_CTLCOLORMSGBOX: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1292 case WM_CTLCOLORSCROLLBAR: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1293 case WM_CTLCOLORDLG: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1294 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1295 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLong((HWND)mp2, GWL_USERDATA); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1296 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1297 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1298 if(thiscinfo->fore > -1 && thiscinfo->back > -1 && |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1299 thiscinfo->fore < 18 && thiscinfo->back < 18) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1300 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1301 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1302 _green[thiscinfo->fore], |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1303 _blue[thiscinfo->fore])); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1304 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1305 _green[thiscinfo->back], |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1306 _blue[thiscinfo->back])); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1307 DeleteObject(thiscinfo->hbrush); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1308 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1309 _green[thiscinfo->back], |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1310 _blue[thiscinfo->back])); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1311 SelectObject((HDC)mp1, thiscinfo->hbrush); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1312 return (LONG)thiscinfo->hbrush; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1313 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1314 if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR && (thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1315 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1316 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1317 DW_GREEN_VALUE(thiscinfo->fore), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1318 DW_BLUE_VALUE(thiscinfo->fore))); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1319 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1320 DW_GREEN_VALUE(thiscinfo->back), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1321 DW_BLUE_VALUE(thiscinfo->back))); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1322 DeleteObject(thiscinfo->hbrush); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1323 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1324 DW_GREEN_VALUE(thiscinfo->back), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1325 DW_BLUE_VALUE(thiscinfo->back))); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1326 SelectObject((HDC)mp1, thiscinfo->hbrush); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1327 return (LONG)thiscinfo->hbrush; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1328 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1329 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1330 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1331 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1332 break; |
3 | 1333 } |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1334 if(result != -1) |
3 | 1335 return result; |
1336 else | |
1337 return DefWindowProc(hWnd, msg, mp1, mp2); | |
1338 } | |
1339 | |
1340 BOOL CALLBACK _framewndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | |
1341 { | |
1342 switch( msg ) | |
1343 { | |
1344 case WM_LBUTTONDOWN: | |
1345 case WM_MBUTTONDOWN: | |
1346 case WM_RBUTTONDOWN: | |
1347 SetActiveWindow(hWnd); | |
1348 break; | |
1349 case WM_COMMAND: | |
1350 case WM_NOTIFY: | |
1351 _wndproc(hWnd, msg, mp1, mp2); | |
1352 break; | |
1353 } | |
1354 return DefWindowProc(hWnd, msg, mp1, mp2); | |
1355 } | |
1356 | |
1357 BOOL CALLBACK _rendwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | |
1358 { | |
1359 switch( msg ) | |
1360 { | |
1361 case WM_LBUTTONDOWN: | |
1362 case WM_MBUTTONDOWN: | |
1363 case WM_RBUTTONDOWN: | |
1364 SetActiveWindow(hWnd); | |
1365 _wndproc(hWnd, msg, mp1, mp2); | |
1366 break; | |
1367 case WM_LBUTTONUP: | |
1368 case WM_MBUTTONUP: | |
1369 case WM_RBUTTONUP: | |
1370 case WM_MOUSEMOVE: | |
1371 case WM_PAINT: | |
1372 case WM_SIZE: | |
1373 case WM_COMMAND: | |
1374 _wndproc(hWnd, msg, mp1, mp2); | |
1375 break; | |
1376 } | |
1377 return DefWindowProc(hWnd, msg, mp1, mp2); | |
1378 } | |
1379 | |
1380 BOOL CALLBACK _spinnerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | |
1381 { | |
1382 ColorInfo *cinfo; | |
1383 | |
1384 cinfo = (ColorInfo *)GetWindowLong(hWnd, GWL_USERDATA); | |
1385 | |
1386 if(cinfo) | |
1387 { | |
1388 switch( msg ) | |
1389 { | |
1390 case WM_LBUTTONDOWN: | |
1391 case WM_MBUTTONDOWN: | |
1392 case WM_RBUTTONDOWN: | |
1393 case WM_CHAR: | |
1394 { | |
1395 BOOL ret; | |
1396 | |
1397 if(!cinfo || !cinfo->pOldProc) | |
1398 ret = DefWindowProc(hWnd, msg, mp1, mp2); | |
1399 ret = CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | |
1400 | |
1401 /* Tell the edit control that a buttonpress has | |
1402 * occured and to update it's window title. | |
1403 */ | |
1404 if(cinfo->buddy) | |
1405 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); | |
1406 | |
1407 return ret; | |
1408 } | |
1409 break; | |
1410 case WM_USER+10: | |
1411 { | |
1412 if(cinfo->buddy) | |
1413 { | |
1414 char tempbuf[100] = ""; | |
1415 long position; | |
1416 | |
1417 GetWindowText(cinfo->buddy, tempbuf, 99); | |
1418 | |
1419 position = atol(tempbuf); | |
1420 | |
1421 if(IS_WIN98PLUS) | |
1422 SendMessage(hWnd, UDM_SETPOS32, 0, (LPARAM)position); | |
1423 else | |
1424 SendMessage(hWnd, UDM_SETPOS, 0, (LPARAM)MAKELONG((short)position, 0)); | |
1425 } | |
1426 } | |
1427 break; | |
1428 } | |
1429 } | |
1430 | |
1431 if(!cinfo || !cinfo->pOldProc) | |
1432 return DefWindowProc(hWnd, msg, mp1, mp2); | |
1433 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | |
1434 } | |
1435 | |
1436 BOOL CALLBACK _colorwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | |
1437 { | |
1438 ColorInfo *cinfo; | |
1439 char tmpbuf[100]; | |
1440 | |
1441 cinfo = (ColorInfo *)GetWindowLong(hWnd, GWL_USERDATA); | |
1442 | |
1443 GetClassName(hWnd, tmpbuf, 99); | |
1444 if(strcmp(tmpbuf, FRAMECLASSNAME) == 0) | |
1445 cinfo = &(((Box *)cinfo)->cinfo); | |
1446 | |
1447 if(cinfo) | |
1448 { | |
1449 switch( msg ) | |
1450 { | |
1451 case WM_CHAR: | |
1452 if(LOWORD(mp1) == '\t') | |
1453 { | |
1454 if(cinfo->buddy) | |
1455 _shift_focus(cinfo->buddy); | |
1456 else | |
1457 _shift_focus(hWnd); | |
1458 return FALSE; | |
1459 } | |
1460 /* Tell the spinner control that a keypress has | |
1461 * occured and to update it's internal value. | |
1462 */ | |
1463 if(cinfo->buddy) | |
1464 SendMessage(cinfo->buddy, WM_USER+10, 0, 0); | |
1465 break; | |
1466 case WM_USER+10: | |
1467 { | |
1468 if(cinfo->buddy) | |
1469 { | |
1470 long val, position; | |
1471 char tmpbuf[100] = ""; | |
1472 | |
1473 GetWindowText(cinfo->buddy, tmpbuf, 99); | |
1474 | |
1475 position = atol(tmpbuf); | |
1476 | |
1477 if(IS_WIN98PLUS) | |
1478 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS32, 0, 0); | |
1479 else | |
1480 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS, 0, 0); | |
1481 | |
1482 if(val != position) | |
1483 { | |
1484 sprintf(tmpbuf, "%d", val); | |
1485 SetWindowText(hWnd, tmpbuf); | |
1486 } | |
1487 } | |
1488 } | |
1489 break; | |
1490 case WM_KEYUP: | |
1491 { | |
1492 if(mp1 == VK_UP || mp1 == VK_DOWN) | |
1493 { | |
1494 if(cinfo->buddy) | |
1495 PostMessage(hWnd, WM_USER+10, 0, 0); | |
1496 } | |
1497 } | |
1498 break; | |
1499 case WM_CTLCOLORSTATIC: | |
1500 case WM_CTLCOLORLISTBOX: | |
1501 case WM_CTLCOLORBTN: | |
1502 case WM_CTLCOLOREDIT: | |
1503 case WM_CTLCOLORMSGBOX: | |
1504 case WM_CTLCOLORSCROLLBAR: | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1505 case WM_CTLCOLORDLG: |
3 | 1506 { |
1507 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLong((HWND)mp2, GWL_USERDATA); | |
1508 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) | |
1509 { | |
1510 if(thiscinfo->fore > -1 && thiscinfo->back > -1 && | |
1511 thiscinfo->fore < 18 && thiscinfo->back < 18) | |
1512 { | |
1513 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], | |
1514 _green[thiscinfo->fore], | |
1515 _blue[thiscinfo->fore])); | |
1516 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], | |
1517 _green[thiscinfo->back], | |
1518 _blue[thiscinfo->back])); | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1519 DeleteObject(thiscinfo->hbrush); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1520 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1521 _green[thiscinfo->back], |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1522 _blue[thiscinfo->back])); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1523 SelectObject((HDC)mp1, thiscinfo->hbrush); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1524 return (LONG)thiscinfo->hbrush; |
3 | 1525 } |
1526 if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR && (thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) | |
1527 { | |
1528 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), | |
1529 DW_GREEN_VALUE(thiscinfo->fore), | |
1530 DW_BLUE_VALUE(thiscinfo->fore))); | |
1531 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), | |
1532 DW_GREEN_VALUE(thiscinfo->back), | |
1533 DW_BLUE_VALUE(thiscinfo->back))); | |
1534 DeleteObject(thiscinfo->hbrush); | |
1535 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), | |
1536 DW_GREEN_VALUE(thiscinfo->back), | |
1537 DW_BLUE_VALUE(thiscinfo->back))); | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1538 SelectObject((HDC)mp1, thiscinfo->hbrush); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
1539 return (LONG)thiscinfo->hbrush; |
3 | 1540 } |
1541 } | |
1542 | |
1543 } | |
1544 break; | |
1545 } | |
1546 } | |
1547 | |
1548 if(!cinfo || !cinfo->pOldProc) | |
1549 return DefWindowProc(hWnd, msg, mp1, mp2); | |
1550 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | |
1551 } | |
1552 | |
1553 BOOL CALLBACK _containerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | |
1554 { | |
1555 ContainerInfo *cinfo; | |
1556 | |
1557 cinfo = (ContainerInfo *)GetWindowLong(hWnd, GWL_USERDATA); | |
1558 | |
1559 switch( msg ) | |
1560 { | |
1561 case WM_COMMAND: | |
1562 case WM_NOTIFY: | |
1563 _wndproc(hWnd, msg, mp1, mp2); | |
1564 break; | |
1565 #ifndef NO_SIGNALS | |
1566 case WM_LBUTTONDBLCLK: | |
1567 case WM_CHAR: | |
1568 { | |
1569 LV_ITEM lvi; | |
1570 int iItem; | |
1571 | |
1572 if(LOWORD(mp1) == '\t') | |
1573 { | |
1574 _shift_focus(hWnd); | |
1575 return FALSE; | |
1576 } | |
1577 | |
1578 if(msg == WM_CHAR && (char)mp1 != '\r') | |
1579 break; | |
1580 | |
1581 iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); | |
1582 | |
1583 if(iItem > -1) | |
1584 { | |
1585 lvi.iItem = iItem; | |
1586 lvi.mask = LVIF_PARAM; | |
1587 | |
1588 ListView_GetItem(hWnd, &lvi); | |
1589 } | |
1590 else | |
1591 lvi.lParam = (LPARAM)NULL; | |
1592 | |
1593 { | |
1594 SignalHandler *tmp = Root; | |
1595 | |
1596 while(tmp) | |
1597 { | |
1598 if(tmp->message == NM_DBLCLK && tmp->window == hWnd) | |
1599 { | |
1600 int (*containerselectfunc)(HWND, char *, void *) = tmp->signalfunction; | |
1601 | |
1602 /* Seems to be having lParam as 1 which really sucks */ | |
1603 if(lvi.lParam < 100) | |
1604 lvi.lParam = 0; | |
1605 | |
1606 containerselectfunc(tmp->window, (char *)lvi.lParam, tmp->data); | |
1607 tmp = NULL; | |
1608 } | |
1609 if(tmp) | |
1610 tmp = tmp->next; | |
1611 } | |
1612 } | |
1613 } | |
1614 break; | |
1615 case WM_CONTEXTMENU: | |
1616 { | |
1617 LONG x,y; | |
1618 LV_ITEM lvi; | |
1619 int iItem; | |
1620 | |
1621 iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); | |
1622 | |
1623 if(iItem > -1) | |
1624 { | |
1625 lvi.iItem = iItem; | |
1626 lvi.mask = LVIF_PARAM; | |
1627 | |
1628 ListView_GetItem(hWnd, &lvi); | |
1629 } | |
1630 else | |
1631 lvi.lParam = (LPARAM)NULL; | |
1632 | |
1633 dw_pointer_query_pos(&x, &y); | |
1634 | |
1635 { | |
1636 SignalHandler *tmp = Root; | |
1637 | |
1638 while(tmp) | |
1639 { | |
1640 if(tmp->message == NM_RCLICK && tmp->window == hWnd) | |
1641 { | |
1642 int (*containercontextfunc)(HWND, char *, int, int, void *) = tmp->signalfunction; | |
1643 | |
1644 /* Seems to be having lParam as 1 which really sucks */ | |
1645 if(lvi.lParam < 100) | |
1646 lvi.lParam = 0; | |
1647 | |
1648 containercontextfunc(tmp->window, (char *)lvi.lParam, x, y, tmp->data); | |
1649 tmp = NULL; | |
1650 } | |
1651 if(tmp) | |
1652 tmp = tmp->next; | |
1653 } | |
1654 } | |
1655 } | |
1656 break; | |
1657 #else | |
1658 case WM_CHAR: | |
1659 if(LOWORD(mp1) == '\t') | |
1660 { | |
1661 _shift_focus(hWnd); | |
1662 return FALSE; | |
1663 } | |
1664 break; | |
1665 #endif | |
1666 } | |
1667 | |
1668 if(!cinfo || !cinfo->pOldProc) | |
1669 return DefWindowProc(hWnd, msg, mp1, mp2); | |
1670 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); | |
1671 } | |
1672 | |
1673 void _changebox(Box *thisbox, int percent, int type) | |
1674 { | |
1675 int z; | |
1676 | |
1677 for(z=0;z<thisbox->count;z++) | |
1678 { | |
1679 if(thisbox->items[z].type == TYPEBOX) | |
1680 { | |
1681 Box *tmp = (Box*)GetWindowLong(thisbox->items[z].hwnd, GWL_USERDATA); | |
1682 _changebox(tmp, percent, type); | |
1683 } | |
1684 else | |
1685 { | |
1686 if(type == BOXHORZ) | |
1687 { | |
1688 if(thisbox->items[z].hsize == SIZEEXPAND) | |
1689 thisbox->items[z].width = (int)(((float)thisbox->items[z].origwidth) * (((float)percent)/((float)100.0))); | |
1690 } | |
1691 else | |
1692 { | |
1693 if(thisbox->items[z].vsize == SIZEEXPAND) | |
1694 thisbox->items[z].height = (int)(((float)thisbox->items[z].origheight) * (((float)percent)/((float)100.0))); | |
1695 } | |
1696 } | |
1697 } | |
1698 } | |
1699 | |
1700 /* This handles any activity on the splitbars (sizers) */ | |
1701 BOOL CALLBACK _splitwndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) | |
1702 { | |
1703 HWND hwndFrame = 0; | |
1704 Box *thisbox = 0; | |
1705 | |
1706 hwndFrame = GetParent(hwnd); | |
1707 if(hwndFrame) | |
1708 thisbox = (Box *)GetWindowLong(hwndFrame, GWL_USERDATA); | |
1709 | |
1710 switch (msg) | |
1711 { | |
1712 case WM_ACTIVATE: | |
1713 case WM_SETFOCUS: | |
1714 return FALSE; | |
1715 | |
1716 case WM_PAINT: | |
1717 { | |
1718 HDC hdcPaint; | |
1719 PAINTSTRUCT ps; | |
1720 POINT ptlStart[SPLITBAR_WIDTH]; | |
1721 POINT ptlEnd[SPLITBAR_WIDTH]; | |
1722 RECT rcPaint; | |
1723 USHORT i; | |
1724 | |
1725 hdcPaint = BeginPaint(hwnd, &ps); | |
1726 GetWindowRect(hwnd, &rcPaint); | |
1727 | |
1728 if(thisbox->type == BOXHORZ) | |
1729 { | |
1730 for(i = 0; i < SPLITBAR_WIDTH; i++) | |
1731 { | |
1732 ptlStart[i].x = i; | |
1733 ptlStart[i].y = 0; | |
1734 | |
1735 ptlEnd[i].x = i; | |
1736 ptlEnd[i].y = rcPaint.bottom - rcPaint.top; | |
1737 } | |
1738 } | |
1739 else | |
1740 { | |
1741 for(i = 0; i < SPLITBAR_WIDTH; i++) | |
1742 { | |
1743 ptlStart[i].x = 0; | |
1744 ptlStart[i].y = i; | |
1745 | |
1746 ptlEnd[i].x = rcPaint.right - rcPaint.left; | |
1747 ptlEnd[i].y = i; | |
1748 } | |
1749 } | |
1750 | |
1751 for(i = 0; i < SPLITBAR_WIDTH; i++) | |
1752 { | |
1753 HPEN hPen; | |
1754 HPEN hOldPen; | |
1755 | |
1756 hPen = CreatePen(PS_SOLID, 1, RGB (_red[lColor[i]], _green[lColor[i]], _blue[lColor[i]])); | |
1757 hOldPen = (HPEN)SelectObject(hdcPaint, hPen); | |
1758 MoveToEx(hdcPaint, ptlStart[i].x, ptlStart[i].y, NULL); | |
1759 LineTo(hdcPaint, ptlEnd[i].x, ptlEnd[i].y); | |
1760 SelectObject(hdcPaint, hOldPen); | |
1761 DeleteObject(hPen); | |
1762 } | |
1763 EndPaint(hwnd, &ps); | |
1764 } | |
1765 return FALSE; | |
1766 case WM_MOUSEMOVE: | |
1767 { | |
1768 if(thisbox->type == BOXHORZ) | |
1769 SetCursor(LoadCursor(NULL, IDC_SIZEWE)); | |
1770 else | |
1771 SetCursor(LoadCursor(NULL, IDC_SIZENS)); | |
1772 } | |
1773 return FALSE; | |
1774 #if 0 | |
1775 case WM_BUTTON1DOWN: | |
1776 { | |
1777 ULONG rc; | |
1778 RECTL rclFrame; | |
1779 RECTL rclBounds; | |
1780 RECTL rclStart; | |
1781 USHORT startSize, orig, actual; | |
1782 | |
1783 GetWindowRect(hwnd, &rclFrame); | |
1784 GetWindowRect(hwnd, &rclStart); | |
1785 | |
1786 GetWindowRect(hwndFrame, &rclBounds); | |
1787 | |
1788 WinMapWindowPoints(hwndFrame, HWND_DESKTOP, | |
1789 (PPOINTL)&rclBounds, 2); | |
1790 WinMapWindowPoints(hwnd, HWND_DESKTOP, | |
1791 (PPOINTL)&rclStart, 2); | |
1792 | |
1793 if(thisbox->type == BOXHORZ) | |
1794 { | |
1795 orig = thisbox->items[0].origwidth; | |
1796 actual = thisbox->items[0].width; | |
1797 | |
1798 startSize = (rclStart.xLeft - rclBounds.xLeft) | |
1799 * (((float)orig)/((float)actual)); | |
1800 } | |
1801 else | |
1802 { | |
1803 orig = thisbox->items[0].origheight; | |
1804 actual = thisbox->items[0].height; | |
1805 | |
1806 startSize = (rclStart.yBottom - rclBounds.yBottom) | |
1807 * (((float)actual)/((float)orig)); | |
1808 } | |
1809 | |
1810 rc = _TrackRectangle(hwnd, &rclFrame, &rclBounds); | |
1811 | |
1812 if(rc == TRUE) | |
1813 { | |
1814 USHORT usNewRB; | |
1815 USHORT usSize; | |
1816 USHORT percent; | |
1817 int z; | |
1818 | |
1819 if(thisbox->type == BOXHORZ) | |
1820 { | |
1821 usNewRB = rclFrame.xLeft | |
1822 - rclBounds.xLeft; | |
1823 usSize = rclBounds.xRight | |
1824 - rclBounds.xLeft; | |
1825 } | |
1826 else | |
1827 { | |
1828 usNewRB = rclFrame.yBottom | |
1829 - rclBounds.yBottom; | |
1830 usSize = rclBounds.yTop | |
1831 - rclBounds.yBottom; | |
1832 } | |
1833 | |
1834 percent = (usNewRB*100)/startSize; | |
1835 | |
1836 for(z=0;z<thisbox->count;z++) | |
1837 { | |
1838 if(thisbox->items[z].type == TYPEBOX) | |
1839 { | |
1840 Box *tmp = (Box *)GetWindowLong(thisbox->items[z].hwnd, GWL_USERDATA); | |
1841 _changebox(tmp, percent, thisbox->type); | |
1842 } | |
1843 else | |
1844 { | |
1845 if(thisbox->items[z].hwnd == hwnd) | |
1846 percent = (startSize*100)/usNewRB; | |
1847 | |
1848 if(thisbox->type == BOXHORZ) | |
1849 { | |
1850 if(thisbox->items[z].hsize == SIZEEXPAND) | |
1851 thisbox->items[z].width = (int)(((float)thisbox->items[z].origwidth) * (((float)percent)/((float)100.0))); | |
1852 } | |
1853 else | |
1854 { | |
1855 if(thisbox->items[z].vsize == SIZEEXPAND) | |
1856 thisbox->items[z].height = (int)(((float)thisbox->items[z].origheight) * (((float)percent)/((float)100.0))); | |
1857 } | |
1858 } | |
1859 } | |
1860 | |
1861 _ResetWindow(GetWindow(hwnd, GW_OWNER)); | |
1862 } | |
1863 } | |
1864 return MRFROMSHORT(FALSE); | |
1865 #endif | |
1866 } | |
1867 return DefWindowProc(hwnd, msg, mp1, mp2); | |
1868 } | |
1869 | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1870 /* This handles drawing the status text areas */ |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1871 BOOL CALLBACK _statuswndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1872 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1873 switch (msg) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1874 { |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1875 case WM_SETTEXT: |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1876 { |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1877 /* Make sure the control redraws when there is a text change */ |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1878 int ret = (int)DefWindowProc(hwnd, msg, mp1, mp2); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1879 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1880 InvalidateRgn(hwnd, NULL, TRUE); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1881 return ret; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1882 } |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1883 case WM_PAINT: |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1884 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1885 HDC hdcPaint; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1886 PAINTSTRUCT ps; |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1887 RECT rc; |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1888 HFONT hFont; |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1889 HBRUSH oldBrush; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1890 HPEN oldPen; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1891 unsigned long cx, cy; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1892 int threadid = dw_thread_id(); |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1893 char tempbuf[1024] = ""; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1894 |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1895 if(threadid < 0 || threadid >= THREAD_LIMIT) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1896 threadid = 0; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1897 |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1898 hdcPaint = BeginPaint(hwnd, &ps); |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1899 EndPaint(hwnd, &ps); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1900 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1901 hdcPaint = GetDC(hwnd); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1902 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1903 oldBrush = _hBrush[threadid]; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1904 oldPen = _hPen[threadid]; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1905 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1906 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1907 |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1908 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1909 _hBrush[threadid] = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1910 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1911 dw_draw_rect(hwnd, 0, TRUE, 0, 0, cx, cy); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1912 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1913 _hPen[threadid] = CreatePen(PS_SOLID, 1, RGB(_red[DW_CLR_DARKGRAY], |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1914 _green[DW_CLR_DARKGRAY], |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1915 _blue[DW_CLR_DARKGRAY])); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1916 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1917 dw_draw_line(hwnd, 0, 0, 0, cx, 0); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1918 dw_draw_line(hwnd, 0, 0, 0, 0, cy); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1919 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1920 DeleteObject(_hPen[threadid]); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1921 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1922 _hPen[threadid] = GetStockObject(WHITE_PEN); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1923 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1924 dw_draw_line(hwnd, 0, cx - 1, cy - 1, cx - 1, 0); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1925 dw_draw_line(hwnd, 0, cx - 1, cy - 1, 0, cy - 1); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1926 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1927 rc.left = 3; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1928 rc.top = 1; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1929 rc.bottom = cy - 1; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1930 rc.right = cx - 1; |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1931 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1932 GetWindowText(hwnd, tempbuf, 1024); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1933 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1934 hFont = (HFONT)SelectObject(hdcPaint, GetStockObject(DEFAULT_GUI_FONT)); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1935 |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1936 SetTextColor(hdcPaint, RGB(0,0,0)); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1937 SetBkMode(hdcPaint, TRANSPARENT); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1938 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1939 ExtTextOut(hdcPaint, 3, 1, ETO_CLIPPED, &rc, tempbuf, strlen(tempbuf), NULL); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1940 |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1941 SelectObject(hdcPaint, hFont); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1942 |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
1943 DeleteObject(_hBrush[threadid]); |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1944 _hBrush[threadid] = oldBrush; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1945 _hPen[threadid] = oldPen; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
1946 ReleaseDC(hwnd, hdcPaint); |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1947 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1948 return FALSE; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1949 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1950 return DefWindowProc(hwnd, msg, mp1, mp2); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1951 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
1952 |
3 | 1953 /* Function: _BtProc |
1954 * Abstract: Subclass procedure for buttons | |
1955 */ | |
1956 | |
1957 BOOL CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) | |
1958 { | |
1959 BubbleButton *bubble; | |
1960 static int bMouseOver = 0; | |
1961 POINT point; | |
1962 RECT rect; | |
1963 | |
1964 bubble = (BubbleButton *)GetWindowLong(hwnd, GWL_USERDATA); | |
1965 | |
1966 if(!bubble) | |
1967 return DefWindowProc(hwnd, msg, mp1, mp2); | |
1968 | |
1969 switch(msg) | |
1970 { | |
1971 #ifndef NO_SIGNALS | |
1972 case WM_LBUTTONUP: | |
1973 { | |
1974 SignalHandler *tmp = Root; | |
1975 | |
1976 /* Find any callbacks for this function */ | |
1977 while(tmp) | |
1978 { | |
1979 if(tmp->message == WM_COMMAND) | |
1980 { | |
1981 int (*clickfunc)(HWND, void *) = tmp->signalfunction; | |
1982 | |
1983 /* Make sure it's the right window, and the right ID */ | |
1984 if(tmp->window == hwnd) | |
1985 { | |
1986 clickfunc(tmp->window, tmp->data); | |
1987 tmp = NULL; | |
1988 } | |
1989 } | |
1990 if(tmp) | |
1991 tmp= tmp->next; | |
1992 } | |
1993 } | |
1994 break; | |
1995 #endif | |
1996 case WM_CHAR: | |
1997 { | |
1998 #ifndef NO_SIGNALS | |
1999 /* A button press should also occur for an ENTER or SPACE press | |
2000 * while the button has the active input focus. | |
2001 */ | |
2002 if(LOWORD(mp1) == '\r' || LOWORD(mp1) == ' ') | |
2003 { | |
2004 SignalHandler *tmp = Root; | |
2005 | |
2006 /* Find any callbacks for this function */ | |
2007 while(tmp) | |
2008 { | |
2009 if(tmp->message == WM_COMMAND) | |
2010 { | |
2011 int (*clickfunc)(HWND, void *) = tmp->signalfunction; | |
2012 | |
2013 /* Make sure it's the right window, and the right ID */ | |
2014 if(tmp->window == hwnd) | |
2015 { | |
2016 clickfunc(tmp->window, tmp->data); | |
2017 tmp = NULL; | |
2018 } | |
2019 } | |
2020 if(tmp) | |
2021 tmp= tmp->next; | |
2022 } | |
2023 } | |
2024 #endif | |
2025 if(LOWORD(mp1) == '\t') | |
2026 { | |
2027 _shift_focus(hwnd); | |
2028 return FALSE; | |
2029 } | |
2030 } | |
2031 break; | |
2032 case WM_TIMER: | |
2033 if (hwndBubble) | |
2034 { | |
2035 DestroyWindow(hwndBubble); | |
2036 hwndBubble = 0; | |
2037 KillTimer(hwnd, 1); | |
2038 } | |
2039 break; | |
2040 | |
2041 case WM_MOUSEMOVE: | |
2042 GetCursorPos(&point); | |
2043 GetWindowRect(hwnd, &rect); | |
2044 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2045 if(PtInRect(&rect, point)) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2046 { |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2047 if(hwnd != GetCapture()) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2048 { |
3 | 2049 SetCapture(hwnd); |
2050 } | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2051 if(!bMouseOver) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2052 { |
3 | 2053 bMouseOver = 1; |
2054 if(!*bubble->bubbletext) | |
2055 break; | |
2056 | |
2057 if(hwndBubble) | |
2058 { | |
2059 DestroyWindow(hwndBubble); | |
2060 hwndBubble = 0; | |
2061 KillTimer(hwndBubbleLast, 1); | |
2062 } | |
2063 | |
2064 if(!hwndBubble) | |
2065 { | |
2066 POINTL ptlWork = {0,0}; | |
2067 ULONG ulColor = DW_CLR_YELLOW; | |
2068 SIZE size; | |
2069 HDC hdc; | |
2070 RECT rect; | |
2071 void *oldproc; | |
2072 | |
2073 /* Use the WS_EX_TOOLWINDOW extended style | |
2074 * so the window doesn't get listed in the | |
2075 * taskbar. | |
2076 */ | |
2077 hwndBubble = CreateWindowEx(WS_EX_TOOLWINDOW, | |
2078 STATICCLASSNAME, | |
2079 bubble->bubbletext, | |
2080 BS_TEXT | WS_POPUP | | |
2081 WS_BORDER | | |
2082 SS_CENTER, | |
2083 0,0,50,20, | |
2084 HWND_DESKTOP, | |
2085 NULL, | |
2086 NULL, | |
2087 NULL); | |
2088 | |
2089 dw_window_set_font(hwndBubble, DefaultFont); | |
2090 dw_window_set_color(hwndBubble, DW_CLR_BLACK, DW_CLR_YELLOW); | |
2091 | |
2092 hwndBubbleLast = hwnd; | |
2093 | |
2094 SetTimer(hwnd, 1, 3000, NULL); | |
2095 | |
2096 hdc = GetDC(hwndBubble); | |
2097 | |
2098 GetTextExtentPoint(hdc, bubble->bubbletext, strlen(bubble->bubbletext), &size); | |
2099 | |
2100 MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)&ptlWork, 1); | |
2101 | |
2102 GetWindowRect(hwnd, &rect); | |
2103 | |
2104 SetWindowPos(hwndBubble, | |
2105 HWND_TOP, | |
2106 ptlWork.x, | |
2107 ptlWork.y + (rect.bottom-rect.top) + 1, | |
2108 size.cx + 2, | |
2109 size.cy + 2, | |
2110 SWP_NOACTIVATE | SWP_SHOWWINDOW); | |
2111 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2112 ReleaseDC(hwndBubble, hdc); |
3 | 2113 } |
2114 } | |
2115 } | |
2116 else{ | |
2117 /* Calling ReleaseCapture in Win95 also causes WM_CAPTURECHANGED | |
2118 * to be sent. Be sure to account for that. | |
2119 */ | |
2120 ReleaseCapture(); | |
2121 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2122 if(bMouseOver) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2123 { |
3 | 2124 bMouseOver = 0; |
2125 DestroyWindow(hwndBubble); | |
2126 hwndBubble = 0; | |
2127 KillTimer(hwndBubbleLast, 1); | |
2128 } | |
2129 } | |
2130 break; | |
2131 case WM_CAPTURECHANGED: | |
2132 /* This message means we are losing the capture for some reason | |
2133 * Either because we intentionally lost it or another window | |
2134 * stole it | |
2135 */ | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2136 if(bMouseOver) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2137 { |
3 | 2138 bMouseOver = 0; |
2139 DestroyWindow(hwndBubble); | |
2140 hwndBubble = 0; | |
2141 KillTimer(hwndBubbleLast, 1); | |
2142 } | |
2143 break; | |
2144 } | |
2145 | |
2146 if(!bubble->pOldProc) | |
2147 return DefWindowProc(hwnd, msg, mp1, mp2); | |
2148 return CallWindowProc(bubble->pOldProc, hwnd, msg, mp1, mp2); | |
2149 } | |
2150 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2151 /* This function recalculates a notebook page for example |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2152 * during switching of notebook pages. |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2153 */ |
3 | 2154 void _resize_notebook_page(HWND handle, int pageid) |
2155 { | |
2156 RECT rect; | |
2157 NotebookPage **array = (NotebookPage **)GetWindowLong(handle, GWL_USERDATA); | |
2158 | |
2159 if(array && array[pageid]) | |
2160 { | |
2161 Box *box = (Box *)GetWindowLong(array[pageid]->hwnd, GWL_USERDATA); | |
2162 | |
2163 GetClientRect(handle,&rect); | |
2164 TabCtrl_AdjustRect(handle,FALSE,&rect); | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2165 MoveWindow(array[pageid]->hwnd, rect.left, rect.top, |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2166 rect.right - rect.left, rect.bottom-rect.top, TRUE); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2167 if(box && box->count) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2168 { |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2169 ShowWindow(box->items[0].hwnd, SW_HIDE); |
3 | 2170 _do_resize(box, rect.right - rect.left, rect.bottom - rect.top); |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2171 ShowWindow(box->items[0].hwnd, SW_SHOW); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2172 } |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2173 |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2174 ShowWindow(array[pageid]->hwnd, SW_SHOWNORMAL); |
3 | 2175 } |
2176 } | |
2177 | |
2178 /* | |
2179 * Initializes the Dynamic Windows engine. | |
2180 * Parameters: | |
2181 * newthread: True if this is the only thread. | |
2182 * False if there is already a message loop running. | |
2183 */ | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2184 int dw_init(int newthread, int argc, char *argv[]) |
3 | 2185 { |
2186 WNDCLASS wc; | |
2187 int z; | |
2188 INITCOMMONCONTROLSEX icc; | |
2189 | |
2190 icc.dwSize = sizeof(INITCOMMONCONTROLSEX); | |
2191 icc.dwICC = ICC_WIN95_CLASSES; | |
2192 | |
2193 InitCommonControlsEx(&icc); | |
2194 | |
2195 memset(lookup, 0, sizeof(HICON) * ICON_INDEX_LIMIT); | |
2196 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2197 /* Register the generic Dynamic Windows class */ |
3 | 2198 memset(&wc, 0, sizeof(WNDCLASS)); |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2199 wc.style = CS_DBLCLKS; |
3 | 2200 wc.lpfnWndProc = (WNDPROC)_wndproc; |
2201 wc.cbClsExtra = 0; | |
2202 wc.cbWndExtra = 32; | |
2203 wc.hbrBackground = NULL; | |
2204 wc.lpszMenuName = NULL; | |
2205 wc.lpszClassName = ClassName; | |
2206 | |
2207 RegisterClass(&wc); | |
2208 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2209 /* Register the splitbar control */ |
3 | 2210 memset(&wc, 0, sizeof(WNDCLASS)); |
2211 wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; | |
2212 wc.lpfnWndProc = (WNDPROC)_splitwndproc; | |
2213 wc.cbClsExtra = 0; | |
2214 wc.cbWndExtra = 0; | |
2215 wc.hbrBackground = NULL; | |
2216 wc.lpszMenuName = NULL; | |
2217 wc.lpszClassName = SplitbarClassName; | |
2218 | |
2219 RegisterClass(&wc); | |
2220 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2221 /* Register a frame control like on OS/2 */ |
3 | 2222 memset(&wc, 0, sizeof(WNDCLASS)); |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2223 wc.style = CS_DBLCLKS; |
3 | 2224 wc.lpfnWndProc = (WNDPROC)_framewndproc; |
2225 wc.cbClsExtra = 0; | |
2226 wc.cbWndExtra = 32; | |
2227 wc.hbrBackground = (HBRUSH)COLOR_WINDOW; | |
2228 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
2229 wc.lpszMenuName = NULL; | |
2230 wc.lpszClassName = FRAMECLASSNAME; | |
2231 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2232 RegisterClass(&wc); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2233 |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2234 /* Create a set of brushes using the default OS/2 and DOS colors */ |
3 | 2235 for(z=0;z<18;z++) |
2236 _colors[z] = CreateSolidBrush(RGB(_red[z],_green[z],_blue[z])); | |
2237 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2238 /* Register an Object Windows class like OS/2 and Win2k+ |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2239 * so similar functionality can be used on earlier releases |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2240 * of Windows. |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2241 */ |
3 | 2242 memset(&wc, 0, sizeof(WNDCLASS)); |
2243 wc.style = 0; | |
2244 wc.lpfnWndProc = (WNDPROC)_wndproc; | |
2245 wc.cbClsExtra = 0; | |
2246 wc.cbWndExtra = 0; | |
2247 wc.hbrBackground = NULL; | |
2248 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
2249 wc.lpszMenuName = NULL; | |
2250 wc.lpszClassName = ObjectClassName; | |
2251 | |
2252 RegisterClass(&wc); | |
2253 | |
2254 /* Since Windows 95/98/NT don't have a HWND_OBJECT class | |
2255 * also known as a input only window, I will create a | |
2256 * temporary window that isn't visible and really does nothing | |
2257 * except temporarily hold the child windows before they are | |
2258 * packed into their correct parent. | |
2259 */ | |
2260 | |
2261 DW_HWND_OBJECT = CreateWindow(ObjectClassName, "", 0, 0, 0, | |
2262 0, 0, HWND_DESKTOP, NULL, NULL, NULL); | |
2263 | |
2264 if(!DW_HWND_OBJECT) | |
2265 { | |
2266 dw_messagebox("Dynamic Windows", "Could not initialize the object window. error code %d", GetLastError()); | |
2267 exit(1); | |
2268 } | |
2269 | |
2270 #ifdef DWDEBUG | |
2271 f = fopen("dw.log", "wt"); | |
2272 #endif | |
2273 /* We need the version to check capability like up-down controls */ | |
2274 dwVersion = GetVersion(); | |
2275 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2276 for(z=0;z<THREAD_LIMIT;z++) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2277 { |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2278 _foreground[z] = RGB(128,128,128); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2279 _background[z] = 0; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2280 _hPen[z] = CreatePen(PS_SOLID, 1, _foreground[z]); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2281 _hBrush[z] = CreateSolidBrush(_foreground[z]); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2282 } |
3 | 2283 |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2284 #if 0 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2285 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2286 DWORD dwResult = GetSysColor(COLOR_3DFACE); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2287 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2288 dw_messagebox("DW", |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2289 "Window color: {%x, %x, %x}", |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2290 GetRValue(dwResult), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2291 GetGValue(dwResult), |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2292 GetBValue(dwResult)); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2293 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2294 #endif |
3 | 2295 return 0; |
2296 } | |
2297 | |
2298 /* | |
2299 * Runs a message loop for Dynamic Windows. | |
2300 * Parameters: | |
2301 * currenthab: The handle to the current anchor block | |
2302 * or NULL if this DW is handling the message loop. | |
2303 * func: Function pointer to the message filter function. | |
2304 */ | |
2305 void dw_main(HAB currenthab, void *func) | |
2306 { | |
2307 MSG msg; | |
2308 | |
2309 /* Setup the filter function */ | |
2310 filterfunc = func; | |
2311 | |
2312 while (GetMessage(&msg,NULL,0,0)) { | |
2313 TranslateMessage(&msg); | |
2314 DispatchMessage(&msg); | |
2315 } | |
2316 | |
2317 #ifdef DWDEBUG | |
2318 fclose(f); | |
2319 #endif | |
2320 } | |
2321 | |
2322 /* | |
2323 * Free's memory allocated by dynamic windows. | |
2324 * Parameters: | |
2325 * ptr: Pointer to dynamic windows allocated | |
2326 * memory to be free()'d. | |
2327 */ | |
2328 void dw_free(void *ptr) | |
2329 { | |
2330 free(ptr); | |
2331 } | |
2332 | |
2333 /* | |
2334 * Allocates and initializes a dialog struct. | |
2335 * Parameters: | |
2336 * data: User defined data to be passed to functions. | |
2337 */ | |
2338 DWDialog *dw_dialog_new(void *data) | |
2339 { | |
2340 DWDialog *tmp = malloc(sizeof(DWDialog)); | |
2341 | |
2342 tmp->eve = dw_event_new(); | |
2343 dw_event_reset(tmp->eve); | |
2344 tmp->data = data; | |
2345 tmp->done = FALSE; | |
2346 tmp->result = NULL; | |
2347 | |
2348 return tmp; | |
2349 } | |
2350 | |
2351 /* | |
2352 * Accepts a dialog struct and returns the given data to the | |
2353 * initial called of dw_dialog_wait(). | |
2354 * Parameters: | |
2355 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | |
2356 * result: Data to be returned by dw_dialog_wait(). | |
2357 */ | |
2358 int dw_dialog_dismiss(DWDialog *dialog, void *result) | |
2359 { | |
2360 dialog->result = result; | |
2361 dw_event_post(dialog->eve); | |
2362 dialog->done = TRUE; | |
2363 return 0; | |
2364 } | |
2365 | |
2366 /* | |
2367 * Accepts a dialog struct waits for dw_dialog_dismiss() to be | |
2368 * called by a signal handler with the given dialog struct. | |
2369 * Parameters: | |
2370 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). | |
2371 */ | |
2372 void *dw_dialog_wait(DWDialog *dialog) | |
2373 { | |
2374 MSG msg; | |
2375 void *tmp; | |
2376 | |
2377 while (GetMessage(&msg,NULL,0,0)) | |
2378 { | |
2379 TranslateMessage(&msg); | |
2380 DispatchMessage(&msg); | |
2381 if(dialog->done) | |
2382 break; | |
2383 } | |
2384 dw_event_close(&dialog->eve); | |
2385 tmp = dialog->result; | |
2386 free(dialog); | |
2387 return tmp; | |
2388 } | |
2389 | |
2390 /* | |
2391 * Displays a Message Box with given text and title.. | |
2392 * Parameters: | |
2393 * title: The title of the message box. | |
2394 * format: printf style format string. | |
2395 * ...: Additional variables for use in the format. | |
2396 */ | |
2397 int dw_messagebox(char *title, char *format, ...) | |
2398 { | |
2399 va_list args; | |
2400 char outbuf[256]; | |
2401 | |
2402 va_start(args, format); | |
2403 vsprintf(outbuf, format, args); | |
2404 va_end(args); | |
2405 | |
2406 MessageBox(HWND_DESKTOP, outbuf, title, MB_OK); | |
2407 | |
2408 return strlen(outbuf); | |
2409 } | |
2410 | |
2411 /* | |
2412 * Displays a Message Box with given text and title.. | |
2413 * Parameters: | |
2414 * title: The title of the message box. | |
2415 * text: The text to display in the box. | |
2416 * Returns: | |
2417 * True if YES False of NO. | |
2418 */ | |
2419 int dw_yesno(char *title, char *text) | |
2420 { | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2421 if(MessageBox(HWND_DESKTOP, text, title, MB_YESNO) == IDYES) |
3 | 2422 return TRUE; |
2423 return FALSE; | |
2424 } | |
2425 | |
2426 /* | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2427 * 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
|
2428 * Parameters: |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2429 * handle: The window handle to minimize. |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2430 */ |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2431 int dw_window_minimize(HWND handle) |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2432 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2433 return ShowWindow(handle, SW_MINIMIZE); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2434 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2435 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2436 /* |
3 | 2437 * Makes the window visible. |
2438 * Parameters: | |
2439 * handle: The window handle to make visible. | |
2440 */ | |
2441 int dw_window_show(HWND handle) | |
2442 { | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2443 int rc = ShowWindow(handle, SW_SHOW); |
3 | 2444 SetFocus(handle); |
2445 _initial_focus(handle); | |
2446 return rc; | |
2447 } | |
2448 | |
2449 /* | |
2450 * Makes the window invisible. | |
2451 * Parameters: | |
2452 * handle: The window handle to make visible. | |
2453 */ | |
2454 int dw_window_hide(HWND handle) | |
2455 { | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
2456 return ShowWindow(handle, SW_HIDE); |
3 | 2457 } |
2458 | |
2459 /* | |
2460 * Destroys a window and all of it's children. | |
2461 * Parameters: | |
2462 * handle: The window handle to destroy. | |
2463 */ | |
2464 int dw_window_destroy(HWND handle) | |
2465 { | |
2466 return DestroyWindow(handle); | |
2467 } | |
2468 | |
2469 /* | |
2470 * Changes a window's parent to newparent. | |
2471 * Parameters: | |
2472 * handle: The window handle to destroy. | |
2473 * newparent: The window's new parent window. | |
2474 */ | |
2475 void dw_window_reparent(HWND handle, HWND newparent) | |
2476 { | |
2477 SetParent(handle, newparent); | |
2478 } | |
2479 | |
2480 HFONT _aquire_font(char *fontname) | |
2481 { | |
2482 HFONT hfont; | |
2483 int z, size = 9; | |
2484 LOGFONT lf; | |
2485 | |
2486 if(fontname == DefaultFont) | |
2487 hfont = GetStockObject(DEFAULT_GUI_FONT); | |
2488 else | |
2489 { | |
2490 for(z=0;z<strlen(fontname);z++) | |
2491 { | |
2492 if(fontname[z]=='.') | |
2493 break; | |
2494 } | |
2495 size = atoi(fontname) + 5; | |
2496 | |
2497 lf.lfHeight = size; | |
2498 lf.lfWidth = 0; | |
2499 lf.lfEscapement = 0; | |
2500 lf.lfOrientation = 0; | |
2501 lf.lfItalic = 0; | |
2502 lf.lfUnderline = 0; | |
2503 lf.lfStrikeOut = 0; | |
2504 lf.lfWeight = FW_NORMAL; | |
2505 lf.lfCharSet = DEFAULT_CHARSET; | |
2506 lf.lfOutPrecision = 0; | |
2507 lf.lfClipPrecision = 0; | |
2508 lf.lfQuality = DEFAULT_QUALITY; | |
2509 lf.lfPitchAndFamily = DEFAULT_PITCH | FW_DONTCARE; | |
2510 strcpy(lf.lfFaceName, &fontname[z+1]); | |
2511 | |
2512 hfont = CreateFontIndirect(&lf); | |
2513 } | |
2514 return hfont; | |
2515 } | |
2516 | |
2517 /* | |
2518 * Sets the font used by a specified window (widget) handle. | |
2519 * Parameters: | |
2520 * handle: The window (widget) handle. | |
2521 * fontname: Name and size of the font in the form "size.fontname" | |
2522 */ | |
2523 int dw_window_set_font(HWND handle, char *fontname) | |
2524 { | |
2525 HFONT hfont = _aquire_font(fontname); | |
2526 ColorInfo *cinfo; | |
2527 | |
2528 cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); | |
2529 | |
2530 if(fontname) | |
2531 { | |
2532 if(cinfo) | |
2533 { | |
2534 strcpy(cinfo->fontname, fontname); | |
2535 } | |
2536 else | |
2537 { | |
2538 cinfo = calloc(1, sizeof(ColorInfo)); | |
2539 cinfo->fore = cinfo->back = -1; | |
2540 cinfo->buddy = 0; | |
2541 | |
2542 strcpy(cinfo->fontname, fontname); | |
2543 | |
2544 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); | |
2545 SetWindowLong(handle, GWL_USERDATA, (ULONG)cinfo); | |
2546 } | |
2547 } | |
2548 SendMessage(handle, WM_SETFONT, (WPARAM)hfont, FALSE); | |
2549 return 0; | |
2550 } | |
2551 | |
2552 /* | |
2553 * Sets the colors used by a specified window (widget) handle. | |
2554 * Parameters: | |
2555 * handle: The window (widget) handle. | |
2556 * fore: Foreground color in RGB format. | |
2557 * back: Background color in RGB format. | |
2558 */ | |
2559 int dw_window_set_color(HWND handle, ULONG fore, ULONG back) | |
2560 { | |
2561 ColorInfo *cinfo; | |
2562 char tmpbuf[100]; | |
2563 | |
2564 cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); | |
2565 | |
2566 GetClassName(handle, tmpbuf, 99); | |
2567 | |
2568 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME))==0) | |
2569 return FALSE; | |
2570 | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2571 if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW))==0) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2572 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2573 ListView_SetTextColor(handle, RGB(DW_RED_VALUE(fore), |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2574 DW_GREEN_VALUE(fore), |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2575 DW_BLUE_VALUE(fore))); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2576 ListView_SetTextBkColor(handle, RGB(DW_RED_VALUE(back), |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2577 DW_GREEN_VALUE(back), |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2578 DW_BLUE_VALUE(back))); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2579 ListView_SetBkColor(handle, RGB(DW_RED_VALUE(back), |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2580 DW_GREEN_VALUE(back), |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2581 DW_BLUE_VALUE(back))); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2582 InvalidateRgn(handle, NULL, TRUE); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2583 return TRUE; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2584 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2585 |
3 | 2586 if(cinfo) |
2587 { | |
2588 cinfo->fore = fore; | |
2589 cinfo->back = back; | |
2590 } | |
2591 else | |
2592 { | |
2593 cinfo = calloc(1, sizeof(ColorInfo)); | |
2594 | |
2595 cinfo->fore = fore; | |
2596 cinfo->back = back; | |
2597 cinfo->buddy = 0; | |
2598 | |
2599 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); | |
2600 SetWindowLong(handle, GWL_USERDATA, (ULONG)cinfo); | |
2601 } | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
2602 InvalidateRgn(handle, NULL, TRUE); |
3 | 2603 return TRUE; |
2604 } | |
2605 | |
2606 /* | |
2607 * Sets the font used by a specified window (widget) handle. | |
2608 * Parameters: | |
2609 * handle: The window (widget) handle. | |
2610 * border: Size of the window border in pixels. | |
2611 */ | |
2612 int dw_window_set_border(HWND handle, int border) | |
2613 { | |
2614 return 0; | |
2615 } | |
2616 | |
2617 /* | |
2618 * Captures the mouse input to this window. | |
2619 * Parameters: | |
2620 * handle: Handle to receive mouse input. | |
2621 */ | |
2622 void dw_window_capture(HWND handle) | |
2623 { | |
2624 SetCapture(handle); | |
2625 } | |
2626 | |
2627 /* | |
2628 * Releases previous mouse capture. | |
2629 */ | |
2630 void dw_window_release(void) | |
2631 { | |
2632 ReleaseCapture(); | |
2633 } | |
2634 | |
2635 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2636 * 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:
17
diff
changeset
|
2637 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2638 * 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:
17
diff
changeset
|
2639 * 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:
17
diff
changeset
|
2640 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2641 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:
17
diff
changeset
|
2642 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2643 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(pointertype))); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2644 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2645 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
2646 /* |
3 | 2647 * Create a new Window Frame. |
2648 * Parameters: | |
2649 * owner: The Owner's window handle or HWND_DESKTOP. | |
2650 * title: The Window title. | |
2651 * flStyle: Style flags, see the DW reference. | |
2652 */ | |
2653 HWND dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) | |
2654 { | |
2655 HWND hwndframe; | |
2656 Box *newbox = malloc(sizeof(Box)); | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2657 ULONG flStyleEx = 0; |
3 | 2658 |
2659 newbox->pad = 0; | |
2660 newbox->type = BOXVERT; | |
2661 newbox->count = 0; | |
2662 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2663 if(hwndOwner) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2664 flStyleEx |= WS_EX_MDICHILD; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2665 |
3 | 2666 if(!(flStyle & WS_CAPTION)) |
2667 flStyle |= WS_POPUPWINDOW; | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2668 |
3 | 2669 if(flStyle & DW_FCF_TASKLIST) |
2670 { | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2671 ULONG newflags = (flStyle | WS_CLIPCHILDREN) & ~DW_FCF_TASKLIST; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2672 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2673 hwndframe = CreateWindowEx(flStyleEx, ClassName, title, newflags, CW_USEDEFAULT, CW_USEDEFAULT, |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2674 CW_USEDEFAULT, CW_USEDEFAULT, hwndOwner, NULL, NULL, NULL); |
3 | 2675 } |
2676 else | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2677 { |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2678 flStyleEx |= WS_EX_TOOLWINDOW; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2679 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2680 hwndframe = CreateWindowEx(flStyleEx, ClassName, title, flStyle | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, |
3 | 2681 CW_USEDEFAULT, CW_USEDEFAULT, hwndOwner, NULL, NULL, NULL); |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2682 } |
3 | 2683 SetWindowLong(hwndframe, GWL_USERDATA, (ULONG)newbox); |
2684 | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2685 #if 0 |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2686 if(hwndOwner) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2687 SetParent(hwndframe, hwndOwner); |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2688 #endif |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2689 |
3 | 2690 return hwndframe; |
2691 } | |
2692 | |
2693 /* | |
2694 * Create a new Box to be packed. | |
2695 * Parameters: | |
2696 * type: Either BOXVERT (vertical) or BOXHORZ (horizontal). | |
2697 * pad: Number of pixels to pad around the box. | |
2698 */ | |
2699 HWND dw_box_new(int type, int pad) | |
2700 { | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2701 Box *newbox = malloc(sizeof(Box)); |
3 | 2702 HWND hwndframe; |
2703 | |
2704 newbox->pad = pad; | |
2705 newbox->type = type; | |
2706 newbox->count = 0; | |
2707 newbox->grouphwnd = (HWND)NULL; | |
2708 | |
2709 hwndframe = CreateWindow(FRAMECLASSNAME, | |
2710 "", | |
2711 WS_CHILD | WS_CLIPCHILDREN, | |
2712 0,0,2000,1000, | |
2713 DW_HWND_OBJECT, | |
2714 NULL, | |
2715 NULL, | |
2716 NULL); | |
2717 | |
2718 newbox->cinfo.pOldProc = SubclassWindow(hwndframe, _colorwndproc); | |
2719 newbox->cinfo.fore = newbox->cinfo.back = -1; | |
2720 | |
2721 SetWindowLong(hwndframe, GWL_USERDATA, (ULONG)newbox); | |
2722 return hwndframe; | |
2723 } | |
2724 | |
2725 /* | |
2726 * Create a new Group Box to be packed. | |
2727 * Parameters: | |
2728 * type: Either BOXVERT (vertical) or BOXHORZ (horizontal). | |
2729 * pad: Number of pixels to pad around the box. | |
2730 * title: Text to be displayined in the group outline. | |
2731 */ | |
2732 HWND dw_groupbox_new(int type, int pad, char *title) | |
2733 { | |
2734 Box *newbox = malloc(sizeof(Box)); | |
2735 HWND hwndframe; | |
2736 | |
2737 newbox->pad = pad; | |
2738 newbox->type = type; | |
2739 newbox->count = 0; | |
2740 | |
2741 hwndframe = CreateWindow(FRAMECLASSNAME, | |
2742 "", | |
2743 WS_CHILD, | |
2744 0,0,2000,1000, | |
2745 DW_HWND_OBJECT, | |
2746 NULL, | |
2747 NULL, | |
2748 NULL); | |
2749 | |
2750 newbox->grouphwnd = CreateWindow(BUTTONCLASSNAME, | |
2751 title, | |
2752 WS_CHILD | BS_GROUPBOX | | |
2753 WS_VISIBLE | WS_CLIPCHILDREN, | |
2754 0,0,2000,1000, | |
2755 hwndframe, | |
2756 NULL, | |
2757 NULL, | |
2758 NULL); | |
2759 | |
2760 SetWindowLong(hwndframe, GWL_USERDATA, (ULONG)newbox); | |
2761 dw_window_set_font(newbox->grouphwnd, DefaultFont); | |
2762 return hwndframe; | |
2763 } | |
2764 | |
2765 /* | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2766 * 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
|
2767 * Parameters: |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2768 * 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
|
2769 */ |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2770 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
|
2771 { |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2772 CLIENTCREATESTRUCT ccs; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2773 HWND hwndframe; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2774 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2775 ccs.hWindowMenu = NULL; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2776 ccs.idFirstChild = 0; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2777 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2778 hwndframe = CreateWindow("MDICLIENT", |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2779 "", |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2780 WS_CHILD | WS_CLIPSIBLINGS, |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2781 0,0,2000,1000, |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2782 DW_HWND_OBJECT, |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2783 NULL, |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2784 DWInstance, |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2785 &ccs); |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2786 return hwndframe; |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2787 } |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2788 |
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2789 /* |
3 | 2790 * Create a bitmap object to be packed. |
2791 * Parameters: | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
2792 * id: An ID to be used with dw_window_from_id or 0L. |
3 | 2793 */ |
2794 HWND dw_bitmap_new(ULONG id) | |
2795 { | |
2796 return CreateWindow(STATICCLASSNAME, | |
2797 "", | |
2798 SS_BITMAP | WS_CHILD | WS_CLIPCHILDREN, | |
2799 0,0,2000,1000, | |
2800 DW_HWND_OBJECT, | |
2801 NULL, | |
2802 NULL, | |
2803 NULL); | |
2804 } | |
2805 | |
2806 /* | |
2807 * Create a notebook object to be packed. | |
2808 * Parameters: | |
2809 * id: An ID to be used for getting the resource from the | |
2810 * resource file. | |
2811 */ | |
2812 HWND dw_notebook_new(ULONG id, int top) | |
2813 { | |
2814 ULONG flags = 0; | |
2815 HWND tmp; | |
2816 NotebookPage **array = calloc(256, sizeof(NotebookPage *)); | |
2817 | |
2818 if(!top) | |
2819 flags = TCS_BOTTOM; | |
2820 | |
2821 tmp = CreateWindow(WC_TABCONTROL, | |
2822 "", | |
2823 WS_CHILD | WS_CLIPCHILDREN, | |
2824 0,0,2000,1000, | |
2825 DW_HWND_OBJECT, | |
2826 NULL, | |
2827 NULL, | |
2828 NULL); | |
2829 SetWindowLong(tmp, GWL_USERDATA, (ULONG)array); | |
2830 dw_window_set_font(tmp, DefaultFont); | |
2831 return tmp; | |
2832 } | |
2833 | |
2834 /* | |
2835 * Create a menu object to be popped up. | |
2836 * Parameters: | |
2837 * id: An ID to be used for getting the resource from the | |
2838 * resource file. | |
2839 */ | |
2840 HMENUI dw_menu_new(ULONG id) | |
2841 { | |
2842 HMENUI tmp = malloc(sizeof(struct _hmenui)); | |
2843 | |
2844 if(!tmp) | |
2845 return NULL; | |
2846 | |
2847 tmp->menu = CreatePopupMenu(); | |
2848 tmp->hwnd = NULL; | |
2849 return tmp; | |
2850 } | |
2851 | |
2852 /* | |
2853 * Create a menubar on a window. | |
2854 * Parameters: | |
2855 * location: Handle of a window frame to be attached to. | |
2856 */ | |
2857 HMENUI dw_menubar_new(HWND location) | |
2858 { | |
2859 HMENUI tmp = malloc(sizeof(struct _hmenui)); | |
2860 | |
2861 if(!tmp) | |
2862 return NULL; | |
2863 | |
2864 tmp->menu = CreateMenu(); | |
2865 tmp->hwnd = location; | |
2866 | |
2867 SetMenu(location, tmp->menu); | |
2868 return tmp; | |
2869 } | |
2870 | |
2871 /* | |
2872 * Destroys a menu created with dw_menubar_new or dw_menu_new. | |
2873 * Parameters: | |
2874 * menu: Handle of a menu. | |
2875 */ | |
2876 void dw_menu_destroy(HMENUI *menu) | |
2877 { | |
2878 if(menu && *menu) | |
2879 { | |
2880 DestroyMenu((*menu)->menu); | |
2881 free(*menu); | |
2882 *menu = NULL; | |
2883 } | |
2884 } | |
2885 | |
2886 /* | |
2887 * Adds a menuitem or submenu to an existing menu. | |
2888 * Parameters: | |
2889 * menu: The handle the the existing menu. | |
2890 * title: The title text on the menu item to be added. | |
2891 * id: An ID to be used for message passing. | |
2892 * end: If TRUE memu is positioned at the end of the menu. | |
2893 * check: If TRUE menu is "check"able. | |
2894 * flags: Extended attributes to set on the menu. | |
2895 * submenu: Handle to an existing menu to be a submenu or NULL. | |
2896 */ | |
2897 HWND dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) | |
2898 { | |
2899 MENUITEMINFO mii; | |
2900 HMENU menu; | |
2901 | |
2902 if(!menux) | |
2903 return NULL; | |
2904 | |
2905 menu = menux->menu; | |
2906 | |
2907 mii.cbSize = sizeof(MENUITEMINFO); | |
2908 mii.fMask = MIIM_ID | MIIM_SUBMENU | MIIM_TYPE; | |
2909 | |
2910 /* Convert from OS/2 style accellerators to Win32 style */ | |
2911 if(title) | |
2912 { | |
2913 char *tmp = title; | |
2914 | |
2915 while(*tmp) | |
2916 { | |
2917 if(*tmp == '~') | |
2918 *tmp = '&'; | |
2919 tmp++; | |
2920 } | |
2921 } | |
2922 | |
2923 if(title && *title) | |
2924 mii.fType = MFT_STRING; | |
2925 else | |
2926 mii.fType = MFT_SEPARATOR; | |
2927 | |
2928 mii.wID = id; | |
2929 mii.hSubMenu = submenu ? submenu->menu : 0; | |
2930 mii.dwTypeData = title; | |
2931 mii.cch = strlen(title); | |
2932 | |
2933 InsertMenuItem(menu, 65535, TRUE, &mii); | |
2934 if(menux->hwnd) | |
2935 DrawMenuBar(menux->hwnd); | |
2936 return (HWND)id; | |
2937 } | |
2938 | |
2939 /* | |
2940 * Sets the state of a menu item check. | |
2941 * Parameters: | |
2942 * menu: The handle the the existing menu. | |
2943 * id: Menuitem id. | |
2944 * check: TRUE for checked FALSE for not checked. | |
2945 */ | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
2946 void dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) |
3 | 2947 { |
2948 MENUITEMINFO mii; | |
2949 HMENU menu; | |
2950 | |
2951 if(!menux) | |
2952 return; | |
2953 | |
2954 menu = menux->menu; | |
2955 | |
2956 mii.cbSize = sizeof(MENUITEMINFO); | |
2957 mii.fMask = MIIM_STATE; | |
2958 if(check) | |
2959 mii.fState = MFS_CHECKED; | |
2960 else | |
2961 mii.fState = MFS_UNCHECKED; | |
2962 SetMenuItemInfo(menu, id, FALSE, &mii); | |
2963 } | |
2964 | |
2965 /* | |
2966 * Pops up a context menu at given x and y coordinates. | |
2967 * Parameters: | |
2968 * menu: The handle the the existing menu. | |
2969 * parent: Handle to the window initiating the popup. | |
2970 * x: X coordinate. | |
2971 * y: Y coordinate. | |
2972 */ | |
2973 void dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) | |
2974 { | |
2975 if(menu && *menu) | |
2976 { | |
2977 TrackPopupMenu((*menu)->menu, 0, x, y, 0, parent, NULL); | |
2978 free(*menu); | |
2979 *menu = NULL; | |
2980 } | |
2981 } | |
2982 | |
2983 | |
2984 /* | |
2985 * Create a container object to be packed. | |
2986 * Parameters: | |
2987 * id: An ID to be used for getting the resource from the | |
2988 * resource file. | |
2989 */ | |
2990 HWND dw_container_new(ULONG id) | |
2991 { | |
2992 HWND tmp = CreateWindow(WC_LISTVIEW, | |
2993 "", | |
2994 WS_CHILD | LVS_REPORT | | |
2995 LVS_SHAREIMAGELISTS | WS_BORDER | | |
2996 WS_CLIPCHILDREN, | |
2997 0,0,2000,1000, | |
2998 DW_HWND_OBJECT, | |
2999 (HMENU)id, | |
3000 NULL, | |
3001 NULL); | |
3002 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); | |
3003 | |
3004 if(!cinfo) | |
3005 { | |
3006 DestroyWindow(tmp); | |
3007 return NULL; | |
3008 } | |
3009 | |
3010 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); | |
3011 | |
3012 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3013 dw_window_set_font(tmp, DefaultFont); | |
3014 return tmp; | |
3015 } | |
3016 | |
3017 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3018 * 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:
17
diff
changeset
|
3019 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3020 * 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:
17
diff
changeset
|
3021 * resource file. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3022 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3023 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:
17
diff
changeset
|
3024 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3025 HWND tmp = CreateWindow(WC_TREEVIEW, |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3026 "", |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3027 WS_CHILD | TVS_HASLINES | |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3028 TVS_HASBUTTONS | TVS_LINESATROOT | |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3029 WS_BORDER | WS_CLIPCHILDREN, |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3030 0,0,2000,1000, |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3031 DW_HWND_OBJECT, |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3032 (HMENU)id, |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3033 NULL, |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3034 NULL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3035 TreeView_SetItemHeight(tmp, 16); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3036 dw_window_set_font(tmp, DefaultFont); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3037 return tmp; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3038 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3039 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3040 /* |
3 | 3041 * Returns the current X and Y coordinates of the mouse pointer. |
3042 * Parameters: | |
3043 * x: Pointer to variable to store X coordinate. | |
3044 * y: Pointer to variable to store Y coordinate. | |
3045 */ | |
3046 void dw_pointer_query_pos(long *x, long *y) | |
3047 { | |
3048 POINT ptl; | |
3049 | |
3050 GetCursorPos(&ptl); | |
3051 if(x && y) | |
3052 { | |
3053 *x = ptl.x; | |
3054 *y = ptl.y; | |
3055 } | |
3056 } | |
3057 | |
3058 /* | |
3059 * Sets the X and Y coordinates of the mouse pointer. | |
3060 * Parameters: | |
3061 * x: X coordinate. | |
3062 * y: Y coordinate. | |
3063 */ | |
3064 void dw_pointer_set_pos(long x, long y) | |
3065 { | |
3066 SetCursorPos(x, y); | |
3067 } | |
3068 | |
3069 /* | |
3070 * Create a new static text window (widget) to be packed. | |
3071 * Parameters: | |
3072 * text: The text to be display by the static text widget. | |
3073 * id: An ID to be used with WinWindowFromID() or 0L. | |
3074 */ | |
3075 HWND dw_text_new(char *text, ULONG id) | |
3076 { | |
3077 HWND tmp = CreateWindow(STATICCLASSNAME, | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3078 text, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3079 BS_TEXT | WS_CHILD | WS_CLIPCHILDREN, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3080 0,0,2000,1000, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3081 DW_HWND_OBJECT, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3082 (HMENU)id, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3083 NULL, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3084 NULL); |
3 | 3085 dw_window_set_font(tmp, DefaultFont); |
3086 return tmp; | |
3087 } | |
3088 | |
3089 /* | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3090 * 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
|
3091 * Parameters: |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3092 * 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
|
3093 * 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
|
3094 */ |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3095 HWND dw_status_text_new(char *text, ULONG id) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3096 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3097 HWND tmp = CreateWindow(STATICCLASSNAME, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3098 text, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3099 BS_TEXT | WS_CHILD | WS_CLIPCHILDREN, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3100 0,0,2000,1000, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3101 DW_HWND_OBJECT, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3102 (HMENU)id, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3103 NULL, |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3104 NULL); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3105 dw_window_set_font(tmp, DefaultFont); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3106 SubclassWindow(tmp, _statuswndproc); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3107 return tmp; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3108 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3109 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
3110 /* |
3 | 3111 * Create a new Multiline Editbox window (widget) to be packed. |
3112 * Parameters: | |
3113 * id: An ID to be used with WinWindowFromID() or 0L. | |
3114 */ | |
3115 HWND dw_mle_new(ULONG id) | |
3116 { | |
3117 | |
3118 HWND tmp = CreateWindow(EDITCLASSNAME, | |
3119 "", | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
3120 WS_BORDER | |
3 | 3121 WS_VSCROLL | ES_MULTILINE | |
3122 ES_WANTRETURN | WS_CHILD | | |
3123 WS_CLIPCHILDREN, | |
3124 0,0,2000,1000, | |
3125 DW_HWND_OBJECT, | |
3126 (HMENU)id, | |
3127 NULL, | |
3128 NULL); | |
3129 dw_window_set_font(tmp, DefaultFont); | |
3130 return tmp; | |
3131 } | |
3132 | |
3133 /* | |
3134 * Create a new Entryfield window (widget) to be packed. | |
3135 * Parameters: | |
3136 * text: The default text to be in the entryfield widget. | |
3137 * id: An ID to be used with WinWindowFromID() or 0L. | |
3138 */ | |
3139 HWND dw_entryfield_new(char *text, ULONG id) | |
3140 { | |
3141 HWND tmp = CreateWindow(EDITCLASSNAME, | |
3142 text, | |
3143 ES_WANTRETURN | WS_CHILD | | |
3144 WS_BORDER | ES_AUTOHSCROLL | | |
3145 WS_CLIPCHILDREN, | |
3146 0,0,2000,1000, | |
3147 DW_HWND_OBJECT, | |
3148 (HMENU)id, | |
3149 NULL, | |
3150 NULL); | |
3151 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | |
3152 | |
3153 cinfo->back = cinfo->fore = -1; | |
3154 cinfo->buddy = 0; | |
3155 | |
3156 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | |
3157 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3158 dw_window_set_font(tmp, DefaultFont); | |
3159 return tmp; | |
3160 } | |
3161 | |
3162 /* | |
3163 * Create a new Entryfield passwird window (widget) to be packed. | |
3164 * Parameters: | |
3165 * text: The default text to be in the entryfield widget. | |
3166 * id: An ID to be used with WinWindowFromID() or 0L. | |
3167 */ | |
3168 HWND dw_entryfield_password_new(char *text, ULONG id) | |
3169 { | |
3170 HWND tmp = CreateWindow(EDITCLASSNAME, | |
3171 text, | |
3172 ES_WANTRETURN | WS_CHILD | | |
3173 ES_PASSWORD | WS_BORDER | | |
3174 ES_AUTOHSCROLL | WS_CLIPCHILDREN, | |
3175 0,0,2000,1000, | |
3176 DW_HWND_OBJECT, | |
3177 (HMENU)id, | |
3178 NULL, | |
3179 NULL); | |
3180 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | |
3181 | |
3182 cinfo->back = cinfo->fore = -1; | |
3183 cinfo->buddy = 0; | |
3184 | |
3185 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | |
3186 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3187 dw_window_set_font(tmp, DefaultFont); | |
3188 return tmp; | |
3189 } | |
3190 | |
3191 /* | |
3192 * Create a new Combobox window (widget) to be packed. | |
3193 * Parameters: | |
3194 * text: The default text to be in the combpbox widget. | |
3195 * id: An ID to be used with WinWindowFromID() or 0L. | |
3196 */ | |
3197 HWND dw_combobox_new(char *text, ULONG id) | |
3198 { | |
3199 HWND tmp = CreateWindow(COMBOBOXCLASSNAME, | |
3200 "", | |
3201 WS_CHILD | CBS_DROPDOWN | WS_CLIPCHILDREN, | |
3202 0,0,2000,1000, | |
3203 DW_HWND_OBJECT, | |
3204 (HMENU)id, | |
3205 NULL, | |
3206 NULL); | |
3207 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); | |
3208 | |
3209 if(!cinfo) | |
3210 { | |
3211 DestroyWindow(tmp); | |
3212 return NULL; | |
3213 } | |
3214 | |
3215 cinfo->cinfo.fore = -1; | |
3216 cinfo->cinfo.back = -1; | |
3217 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); | |
3218 | |
3219 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3220 dw_window_set_font(tmp, DefaultFont); | |
3221 return tmp; | |
3222 } | |
3223 | |
3224 /* | |
3225 * Create a new button window (widget) to be packed. | |
3226 * Parameters: | |
3227 * text: The text to be display by the static text widget. | |
3228 * id: An ID to be used with WinWindowFromID() or 0L. | |
3229 */ | |
3230 HWND dw_button_new(char *text, ULONG id) | |
3231 { | |
3232 BubbleButton *bubble = malloc(sizeof(BubbleButton)); | |
3233 | |
3234 HWND tmp = CreateWindow(BUTTONCLASSNAME, | |
3235 text, | |
3236 WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN, | |
3237 0,0,2000,1000, | |
3238 DW_HWND_OBJECT, | |
3239 (HMENU)id, | |
3240 NULL, | |
3241 NULL); | |
3242 | |
3243 bubble->id = id; | |
3244 bubble->bubbletext[0] = '\0'; | |
3245 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | |
3246 | |
3247 SetWindowLong(tmp, GWL_USERDATA, (ULONG)bubble); | |
3248 dw_window_set_font(tmp, DefaultFont); | |
3249 return tmp; | |
3250 } | |
3251 | |
3252 /* | |
3253 * Create a new bitmap button window (widget) to be packed. | |
3254 * Parameters: | |
3255 * text: Bubble help text to be displayed. | |
3256 * id: An ID of a bitmap in the resource file. | |
3257 */ | |
3258 HWND dw_bitmapbutton_new(char *text, ULONG id) | |
3259 { | |
3260 HWND tmp; | |
3261 BubbleButton *bubble = malloc(sizeof(BubbleButton)); | |
3262 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | |
3263 | |
3264 tmp = CreateWindow(BUTTONCLASSNAME, | |
3265 "", | |
3266 WS_CHILD | BS_PUSHBUTTON | | |
3267 BS_BITMAP | WS_CLIPCHILDREN, | |
3268 0,0,2000,1000, | |
3269 DW_HWND_OBJECT, | |
3270 (HMENU)id, | |
3271 NULL, | |
3272 NULL); | |
3273 | |
3274 bubble->id = id; | |
3275 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); | |
3276 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; | |
3277 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | |
3278 | |
3279 SetWindowLong(tmp, GWL_USERDATA, (ULONG)bubble); | |
3280 | |
3281 SendMessage(tmp, BM_SETIMAGE, | |
3282 (WPARAM) IMAGE_BITMAP, | |
3283 (LPARAM) hbitmap); | |
3284 return tmp; | |
3285 } | |
3286 | |
3287 /* | |
3288 * Create a new spinbutton window (widget) to be packed. | |
3289 * Parameters: | |
3290 * text: The text to be display by the static text widget. | |
3291 * id: An ID to be used with WinWindowFromID() or 0L. | |
3292 */ | |
3293 HWND dw_spinbutton_new(char *text, ULONG id) | |
3294 { | |
3295 ULONG *data = malloc(sizeof(ULONG)); | |
3296 HWND buddy = CreateWindow(EDITCLASSNAME, | |
3297 text, | |
3298 WS_CHILD | WS_BORDER | | |
3299 ES_NUMBER | WS_CLIPCHILDREN, | |
3300 0,0,2000,1000, | |
3301 DW_HWND_OBJECT, | |
3302 NULL, | |
3303 NULL, | |
3304 NULL); | |
3305 HWND tmp = CreateUpDownControl( | |
3306 WS_CHILD | UDS_ALIGNRIGHT | | |
3307 UDS_ARROWKEYS | UDS_SETBUDDYINT | | |
3308 UDS_WRAP | UDS_NOTHOUSANDS, | |
3309 0, | |
3310 0, | |
3311 2000, | |
3312 1000, | |
3313 DW_HWND_OBJECT, | |
3314 id, | |
3315 DWInstance, | |
3316 buddy, | |
3317 0, | |
3318 100, | |
3319 0); | |
3320 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | |
3321 | |
3322 cinfo->back = cinfo->fore = -1; | |
3323 cinfo->buddy = tmp; | |
3324 | |
3325 cinfo->pOldProc = SubclassWindow(buddy, _colorwndproc); | |
3326 SetWindowLong(buddy, GWL_USERDATA, (ULONG)cinfo); | |
3327 | |
3328 cinfo = calloc(1, sizeof(ColorInfo)); | |
3329 cinfo->buddy = buddy; | |
3330 cinfo->pOldProc = SubclassWindow(tmp, _spinnerwndproc); | |
3331 | |
3332 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3333 dw_window_set_font(buddy, DefaultFont); | |
3334 return tmp; | |
3335 } | |
3336 | |
3337 /* | |
3338 * Create a new radiobutton window (widget) to be packed. | |
3339 * Parameters: | |
3340 * text: The text to be display by the static text widget. | |
3341 * id: An ID to be used with WinWindowFromID() or 0L. | |
3342 */ | |
3343 HWND dw_radiobutton_new(char *text, ULONG id) | |
3344 { | |
3345 HWND tmp = CreateWindow(BUTTONCLASSNAME, | |
3346 text, | |
3347 WS_CHILD | BS_AUTORADIOBUTTON | | |
3348 WS_CLIPCHILDREN, | |
3349 0,0,2000,1000, | |
3350 DW_HWND_OBJECT, | |
3351 (HMENU)id, | |
3352 NULL, | |
3353 NULL); | |
3354 | |
3355 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | |
3356 | |
3357 cinfo->back = cinfo->fore = -1; | |
3358 cinfo->buddy = 0; | |
3359 cinfo->user = 0; | |
3360 | |
3361 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | |
3362 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3363 dw_window_set_font(tmp, DefaultFont); | |
3364 return tmp; | |
3365 } | |
3366 | |
3367 | |
3368 /* | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
32
diff
changeset
|
3369 * Create a new percent bar window (widget) to be packed. |
3 | 3370 * Parameters: |
3371 * id: An ID to be used with WinWindowFromID() or 0L. | |
3372 */ | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
32
diff
changeset
|
3373 HWND dw_percent_new(ULONG id) |
3 | 3374 { |
3375 return CreateWindow(PROGRESS_CLASS, | |
3376 "", | |
3377 WS_CHILD | WS_CLIPCHILDREN, | |
3378 0,0,2000,1000, | |
3379 DW_HWND_OBJECT, | |
3380 NULL, | |
3381 NULL, | |
3382 NULL); | |
3383 } | |
3384 | |
3385 /* | |
3386 * Create a new checkbox window (widget) to be packed. | |
3387 * Parameters: | |
3388 * text: The text to be display by the static text widget. | |
3389 * id: An ID to be used with WinWindowFromID() or 0L. | |
3390 */ | |
3391 HWND dw_checkbox_new(char *text, ULONG id) | |
3392 { | |
3393 HWND tmp = CreateWindow(BUTTONCLASSNAME, | |
3394 text, | |
3395 WS_CHILD | BS_AUTOCHECKBOX | | |
3396 BS_TEXT | WS_CLIPCHILDREN, | |
3397 0,0,2000,1000, | |
3398 DW_HWND_OBJECT, | |
3399 NULL, | |
3400 NULL, | |
3401 NULL); | |
3402 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | |
3403 | |
3404 cinfo->back = cinfo->fore = -1; | |
3405 cinfo->buddy = 0; | |
3406 cinfo->user = 1; | |
3407 | |
3408 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | |
3409 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3410 dw_window_set_font(tmp, DefaultFont); | |
3411 return tmp; | |
3412 } | |
3413 | |
3414 /* | |
3415 * Create a new listbox window (widget) to be packed. | |
3416 * Parameters: | |
3417 * id: An ID to be used with WinWindowFromID() or 0L. | |
3418 * multi: Multiple select TRUE or FALSE. | |
3419 */ | |
3420 HWND dw_listbox_new(ULONG id, int multi) | |
3421 { | |
3422 HWND tmp = CreateWindow(LISTBOXCLASSNAME, | |
3423 "", | |
3424 LBS_NOINTEGRALHEIGHT | WS_CHILD | LBS_HASSTRINGS | | |
3425 LBS_NOTIFY | WS_BORDER | WS_CLIPCHILDREN | | |
3426 WS_VSCROLL | (multi ? LBS_EXTENDEDSEL : 0) , | |
3427 0,0,2000,1000, | |
3428 DW_HWND_OBJECT, | |
3429 NULL, | |
3430 NULL, | |
3431 NULL); | |
3432 ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo)); | |
3433 | |
3434 if(!cinfo) | |
3435 { | |
3436 DestroyWindow(tmp); | |
3437 return NULL; | |
3438 } | |
3439 | |
3440 cinfo->cinfo.fore = -1; | |
3441 cinfo->cinfo.back = -1; | |
3442 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); | |
3443 | |
3444 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3445 dw_window_set_font(tmp, DefaultFont); | |
3446 return tmp; | |
3447 } | |
3448 | |
3449 /* | |
3450 * Sets the icon used for a given window. | |
3451 * Parameters: | |
3452 * handle: Handle to the window. | |
3453 * id: An ID to be used to specify the icon. | |
3454 */ | |
3455 void dw_window_set_icon(HWND handle, ULONG id) | |
3456 { | |
3457 HICON hicon = LoadIcon(DWInstance, MAKEINTRESOURCE(id)); | |
3458 | |
3459 SendMessage(handle, WM_SETICON, | |
3460 (WPARAM) IMAGE_ICON, | |
3461 (LPARAM) hicon); | |
3462 } | |
3463 | |
3464 /* | |
3465 * Sets the bitmap used for a given static window. | |
3466 * Parameters: | |
3467 * handle: Handle to the window. | |
3468 * id: An ID to be used to specify the icon. | |
3469 */ | |
3470 void dw_window_set_bitmap(HWND handle, ULONG id) | |
3471 { | |
3472 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | |
3473 | |
3474 SendMessage(handle, STM_SETIMAGE, | |
3475 (WPARAM) IMAGE_BITMAP, | |
3476 (LPARAM) hbitmap); | |
3477 } | |
3478 | |
3479 /* | |
3480 * Sets the text used for a given window. | |
3481 * Parameters: | |
3482 * handle: Handle to the window. | |
3483 * text: The text associsated with a given window. | |
3484 */ | |
3485 void dw_window_set_text(HWND handle, char *text) | |
3486 { | |
3487 SetWindowText(handle, text); | |
3488 } | |
3489 | |
3490 /* | |
3491 * Gets the text used for a given window. | |
3492 * Parameters: | |
3493 * handle: Handle to the window. | |
3494 * Returns: | |
3495 * text: The text associsated with a given window. | |
3496 */ | |
3497 char *dw_window_get_text(HWND handle) | |
3498 { | |
3499 char tempbuf[4096] = ""; | |
3500 | |
3501 GetWindowText(handle, tempbuf, 4095); | |
3502 tempbuf[4095] = 0; | |
3503 | |
3504 return strdup(tempbuf); | |
3505 } | |
3506 | |
3507 /* | |
3508 * Disables given window (widget). | |
3509 * Parameters: | |
3510 * handle: Handle to the window. | |
3511 */ | |
3512 void dw_window_disable(HWND handle) | |
3513 { | |
3514 EnableWindow(handle, FALSE); | |
3515 } | |
3516 | |
3517 /* | |
3518 * Enables given window (widget). | |
3519 * Parameters: | |
3520 * handle: Handle to the window. | |
3521 */ | |
3522 void dw_window_enable(HWND handle) | |
3523 { | |
3524 EnableWindow(handle, TRUE); | |
3525 } | |
3526 | |
3527 /* | |
3528 * Gets the child window handle with specified ID. | |
3529 * Parameters: | |
3530 * handle: Handle to the parent window. | |
3531 * id: Integer ID of the child. | |
3532 */ | |
3533 HWND dw_window_from_id(HWND handle, int id) | |
3534 { | |
3535 return 0L; | |
3536 } | |
3537 /* | |
3538 * Pack windows (widgets) into a box from the start (or top). | |
3539 * Parameters: | |
3540 * box: Window handle of the box to be packed into. | |
3541 * item: Window handle of the item to be back. | |
3542 * width: Width in pixels of the item or -1 to be self determined. | |
3543 * height: Height in pixels of the item or -1 to be self determined. | |
3544 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | |
3545 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | |
3546 * pad: Number of pixels of padding around the item. | |
3547 */ | |
3548 void dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | |
3549 { | |
3550 Box *thisbox; | |
3551 | |
3552 thisbox = (Box *)GetWindowLong(box, GWL_USERDATA); | |
3553 if(thisbox) | |
3554 { | |
3555 int z; | |
3556 Item *tmpitem, *thisitem = thisbox->items; | |
3557 char tmpbuf[100]; | |
3558 | |
14
176cee043f1b
Lots of Windows and Unix bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
12
diff
changeset
|
3559 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
3 | 3560 |
3561 for(z=0;z<thisbox->count;z++) | |
3562 { | |
3563 tmpitem[z] = thisitem[z]; | |
3564 } | |
3565 | |
3566 GetClassName(item, tmpbuf, 99); | |
3567 | |
3568 if(strnicmp(tmpbuf, FRAMECLASSNAME, 2)==0) | |
3569 tmpitem[thisbox->count].type = TYPEBOX; | |
3570 else | |
3571 tmpitem[thisbox->count].type = TYPEITEM; | |
3572 | |
3573 tmpitem[thisbox->count].hwnd = item; | |
3574 tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width; | |
3575 tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height; | |
3576 tmpitem[thisbox->count].pad = pad; | |
3577 if(hsize) | |
3578 tmpitem[thisbox->count].hsize = SIZEEXPAND; | |
3579 else | |
3580 tmpitem[thisbox->count].hsize = SIZESTATIC; | |
3581 | |
3582 if(vsize) | |
3583 tmpitem[thisbox->count].vsize = SIZEEXPAND; | |
3584 else | |
3585 tmpitem[thisbox->count].vsize = SIZESTATIC; | |
3586 | |
3587 thisbox->items = tmpitem; | |
3588 | |
3589 if(thisbox->count) | |
3590 free(thisitem); | |
3591 | |
3592 thisbox->count++; | |
3593 | |
3594 SetParent(item, box); | |
3595 ShowWindow(item, SW_SHOW); | |
3596 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0) | |
3597 { | |
3598 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(item, GWL_USERDATA); | |
3599 | |
3600 if(cinfo) | |
3601 { | |
3602 SetParent(cinfo->buddy, box); | |
3603 ShowWindow(cinfo->buddy, SW_SHOW); | |
3604 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0); | |
3605 } | |
3606 } | |
3607 } | |
3608 } | |
3609 | |
3610 /* | |
3611 * Sets the size of a given window (widget). | |
3612 * Parameters: | |
3613 * handle: Window (widget) handle. | |
3614 * width: New width in pixels. | |
3615 * height: New height in pixels. | |
3616 */ | |
3617 void dw_window_set_usize(HWND handle, ULONG width, ULONG height) | |
3618 { | |
3619 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE); | |
3620 } | |
3621 | |
3622 /* | |
3623 * Returns the width of the screen. | |
3624 */ | |
3625 int dw_screen_width(void) | |
3626 { | |
3627 return GetSystemMetrics(SM_CXSCREEN); | |
3628 } | |
3629 | |
3630 /* | |
3631 * Returns the height of the screen. | |
3632 */ | |
3633 int dw_screen_height(void) | |
3634 { | |
3635 return GetSystemMetrics(SM_CYSCREEN); | |
3636 } | |
3637 | |
3638 /* This should return the current color depth */ | |
3639 unsigned long dw_color_depth(void) | |
3640 { | |
3641 int bpp; | |
3642 HDC hdc = GetDC(HWND_DESKTOP); | |
3643 | |
3644 bpp = GetDeviceCaps(hdc, BITSPIXEL); | |
3645 | |
3646 ReleaseDC(HWND_DESKTOP, hdc); | |
3647 | |
3648 return bpp; | |
3649 } | |
3650 | |
3651 | |
3652 /* | |
3653 * Sets the position of a given window (widget). | |
3654 * Parameters: | |
3655 * handle: Window (widget) handle. | |
3656 * x: X location from the bottom left. | |
3657 * y: Y location from the bottom left. | |
3658 */ | |
3659 void dw_window_set_pos(HWND handle, ULONG x, ULONG y) | |
3660 { | |
3661 SetWindowPos(handle, (HWND)NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); | |
3662 } | |
3663 | |
3664 /* | |
3665 * Sets the position and size of a given window (widget). | |
3666 * Parameters: | |
3667 * handle: Window (widget) handle. | |
3668 * x: X location from the bottom left. | |
3669 * y: Y location from the bottom left. | |
3670 * width: Width of the widget. | |
3671 * height: Height of the widget. | |
3672 */ | |
3673 void dw_window_set_pos_size(HWND handle, ULONG x, ULONG y, ULONG width, ULONG height) | |
3674 { | |
3675 SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW); | |
3676 } | |
3677 | |
3678 /* | |
3679 * Gets the position and size of a given window (widget). | |
3680 * Parameters: | |
3681 * handle: Window (widget) handle. | |
3682 * x: X location from the bottom left. | |
3683 * y: Y location from the bottom left. | |
3684 * width: Width of the widget. | |
3685 * height: Height of the widget. | |
3686 */ | |
3687 void dw_window_get_pos_size(HWND handle, ULONG *x, ULONG *y, ULONG *width, ULONG *height) | |
3688 { | |
3689 WINDOWPLACEMENT wp; | |
3690 | |
3691 wp.length = sizeof(WINDOWPLACEMENT); | |
3692 | |
3693 GetWindowPlacement(handle, &wp); | |
3694 if(x) | |
3695 *x = wp.rcNormalPosition.left; | |
3696 if(y) | |
3697 *y = wp.rcNormalPosition.top; | |
3698 if(width) | |
3699 *width = wp.rcNormalPosition.right - wp.rcNormalPosition.left; | |
3700 if(height) | |
3701 *height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; | |
3702 | |
3703 } | |
3704 | |
3705 /* | |
3706 * Sets the style of a given window (widget). | |
3707 * Parameters: | |
3708 * handle: Window (widget) handle. | |
3709 * width: New width in pixels. | |
3710 * height: New height in pixels. | |
3711 */ | |
3712 void dw_window_set_style(HWND handle, ULONG style, ULONG mask) | |
3713 { | |
3714 ULONG tmp, currentstyle = GetWindowLong(handle, GWL_STYLE); | |
3715 | |
3716 tmp = currentstyle | mask; | |
3717 tmp ^= mask; | |
3718 tmp |= style; | |
3719 | |
3720 SetWindowLong(handle, GWL_STYLE, tmp); | |
3721 } | |
3722 | |
3723 /* Finds the physical ID from the reference ID */ | |
3724 int _findnotebookid(NotebookPage **array, int pageid) | |
3725 { | |
3726 int z; | |
3727 | |
3728 for(z=0;z<256;z++) | |
3729 { | |
3730 if(array[z] && array[z]->realid == pageid) | |
3731 return z; | |
3732 } | |
3733 return -1; | |
3734 } | |
3735 | |
3736 /* | |
3737 * Adds a new page to specified notebook. | |
3738 * Parameters: | |
3739 * handle: Window (widget) handle. | |
3740 * flags: Any additional page creation flags. | |
3741 * front: If TRUE page is added at the beginning. | |
3742 */ | |
3743 ULONG dw_notebook_page_new(HWND handle, ULONG flags, int front) | |
3744 { | |
3745 NotebookPage **array = (NotebookPage **)GetWindowLong(handle, GWL_USERDATA); | |
3746 | |
3747 if(array) | |
3748 { | |
3749 int z, refid = -1; | |
3750 | |
3751 for(z=0;z<256;z++) | |
3752 { | |
3753 if(_findnotebookid(array, z) == -1) | |
3754 { | |
3755 refid = z; | |
3756 break; | |
3757 } | |
3758 } | |
3759 | |
3760 if(refid == -1) | |
3761 return -1; | |
3762 | |
3763 for(z=0;z<256;z++) | |
3764 { | |
3765 if(!array[z]) | |
3766 { | |
3767 int oldpage = TabCtrl_GetCurSel(handle); | |
3768 | |
3769 array[z] = calloc(1, sizeof(NotebookPage)); | |
3770 array[z]->realid = refid; | |
3771 array[z]->item.mask = TCIF_TEXT; | |
3772 array[z]->item.iImage = -1; | |
3773 array[z]->item.pszText = ""; | |
3774 TabCtrl_InsertItem(handle, z, &(array[z]->item)); | |
3775 | |
3776 if(oldpage > -1 && array[oldpage]) | |
3777 SetParent(array[oldpage]->hwnd, DW_HWND_OBJECT); | |
3778 | |
3779 TabCtrl_SetCurSel(handle, z); | |
3780 return refid; | |
3781 } | |
3782 } | |
3783 } | |
3784 return -1; | |
3785 } | |
3786 | |
3787 /* | |
3788 * Sets the text on the specified notebook tab. | |
3789 * Parameters: | |
3790 * handle: Notebook handle. | |
3791 * pageid: Page ID of the tab to set. | |
3792 * text: Pointer to the text to set. | |
3793 */ | |
3794 void dw_notebook_page_set_text(HWND handle, ULONG pageidx, char *text) | |
3795 { | |
3796 | |
3797 NotebookPage **array = (NotebookPage **)GetWindowLong(handle, GWL_USERDATA); | |
3798 int pageid; | |
3799 | |
3800 if(!array) | |
3801 return; | |
3802 | |
3803 pageid = _findnotebookid(array, pageidx); | |
3804 | |
3805 if(pageid > -1 && array[pageid]) | |
3806 { | |
3807 array[pageid]->item.mask = TCIF_TEXT; | |
3808 array[pageid]->item.pszText = text; | |
3809 TabCtrl_SetItem(handle, pageid, &(array[pageid]->item)); | |
3810 _resize_notebook_page(handle, pageid); | |
3811 } | |
3812 } | |
3813 | |
3814 /* | |
3815 * Sets the text on the specified notebook tab status area. | |
3816 * Parameters: | |
3817 * handle: Notebook handle. | |
3818 * pageid: Page ID of the tab to set. | |
3819 * text: Pointer to the text to set. | |
3820 */ | |
3821 void dw_notebook_page_set_status_text(HWND handle, ULONG pageid, char *text) | |
3822 { | |
3823 } | |
3824 | |
3825 /* | |
3826 * Packs the specified box into the notebook page. | |
3827 * Parameters: | |
3828 * handle: Handle to the notebook to be packed. | |
3829 * pageid: Page ID in the notebook which is being packed. | |
3830 * page: Box handle to be packed. | |
3831 */ | |
3832 void dw_notebook_pack(HWND handle, ULONG pageidx, HWND page) | |
3833 { | |
3834 NotebookPage **array = (NotebookPage **)GetWindowLong(handle, GWL_USERDATA); | |
3835 int pageid; | |
3836 | |
3837 if(!array) | |
3838 return; | |
3839 | |
3840 pageid = _findnotebookid(array, pageidx); | |
3841 | |
3842 if(pageid > -1 && array[pageid]) | |
3843 { | |
3844 HWND tmpbox = dw_box_new(BOXVERT, 0); | |
3845 | |
3846 dw_box_pack_start(tmpbox, page, 0, 0, TRUE, TRUE, 0); | |
3847 SubclassWindow(tmpbox, _wndproc); | |
3848 if(array[pageid]->hwnd) | |
3849 dw_window_destroy(array[pageid]->hwnd); | |
3850 array[pageid]->hwnd = tmpbox; | |
3851 if(pageidx == dw_notebook_page_query(handle)) | |
3852 { | |
3853 SetParent(tmpbox, handle); | |
3854 _resize_notebook_page(handle, pageid); | |
3855 } | |
3856 } | |
3857 } | |
3858 | |
3859 /* | |
3860 * Remove a page from a notebook. | |
3861 * Parameters: | |
3862 * handle: Handle to the notebook widget. | |
3863 * pageid: ID of the page to be destroyed. | |
3864 */ | |
3865 void dw_notebook_page_destroy(HWND handle, unsigned int pageidx) | |
3866 { | |
3867 NotebookPage **array = (NotebookPage **)GetWindowLong(handle, GWL_USERDATA); | |
3868 int newid = -1, z, pageid; | |
3869 | |
3870 if(!array) | |
3871 return; | |
3872 | |
3873 pageid = _findnotebookid(array, pageidx); | |
3874 | |
3875 if(pageid < 0) | |
3876 return; | |
3877 | |
3878 if(array[pageid]) | |
3879 { | |
3880 SetParent(array[pageid]->hwnd, DW_HWND_OBJECT); | |
3881 free(array[pageid]); | |
3882 array[pageid] = NULL; | |
3883 } | |
3884 | |
3885 TabCtrl_DeleteItem(handle, pageid); | |
3886 | |
3887 /* Shift the pages over 1 */ | |
3888 for(z=pageid;z<255;z++) | |
3889 array[z] = array[z+1]; | |
3890 array[255] = NULL; | |
3891 | |
3892 for(z=0;z<256;z++) | |
3893 { | |
3894 if(array[z]) | |
3895 { | |
3896 newid = z; | |
3897 break; | |
3898 } | |
3899 } | |
3900 if(newid > -1) | |
3901 { | |
3902 SetParent(array[newid]->hwnd, handle); | |
3903 _resize_notebook_page(handle, newid); | |
3904 dw_notebook_page_set(handle, array[newid]->realid); | |
3905 } | |
3906 } | |
3907 | |
3908 /* | |
3909 * Queries the currently visible page ID. | |
3910 * Parameters: | |
3911 * handle: Handle to the notebook widget. | |
3912 */ | |
3913 unsigned int dw_notebook_page_query(HWND handle) | |
3914 { | |
3915 NotebookPage **array = (NotebookPage **)GetWindowLong(handle, GWL_USERDATA); | |
3916 int physid = TabCtrl_GetCurSel(handle); | |
3917 | |
3918 if(physid > -1 && physid < 256 && array && array[physid]) | |
3919 return array[physid]->realid; | |
3920 return -1; | |
3921 } | |
3922 | |
3923 /* | |
3924 * Sets the currently visible page ID. | |
3925 * Parameters: | |
3926 * handle: Handle to the notebook widget. | |
3927 * pageid: ID of the page to be made visible. | |
3928 */ | |
3929 void dw_notebook_page_set(HWND handle, unsigned int pageidx) | |
3930 { | |
3931 NotebookPage **array = (NotebookPage **)GetWindowLong(handle, GWL_USERDATA); | |
3932 int pageid; | |
3933 | |
3934 if(!array) | |
3935 return; | |
3936 | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3937 pageid = _findnotebookid(array, pageidx); |
3 | 3938 |
3939 if(pageid > -1 && pageid < 256) | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3940 { |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3941 int oldpage = TabCtrl_GetCurSel(handle); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3942 |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3943 if(oldpage > -1 && array && array[oldpage]) |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3944 SetParent(array[oldpage]->hwnd, DW_HWND_OBJECT); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3945 |
3 | 3946 TabCtrl_SetCurSel(handle, pageid); |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3947 |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3948 SetParent(array[pageid]->hwnd, handle); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3949 _resize_notebook_page(handle, pageid); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
3950 } |
3 | 3951 } |
3952 | |
3953 /* | |
3954 * Appends the specified text to the listbox's (or combobox) entry list. | |
3955 * Parameters: | |
3956 * handle: Handle to the listbox to be appended to. | |
3957 * text: Text to append into listbox. | |
3958 */ | |
3959 void dw_listbox_append(HWND handle, char *text) | |
3960 { | |
3961 char tmpbuf[100]; | |
3962 | |
3963 GetClassName(handle, tmpbuf, 99); | |
3964 | |
3965 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0) | |
3966 SendMessage(handle, | |
3967 CB_ADDSTRING, | |
3968 0, (LPARAM)text); | |
3969 else | |
3970 SendMessage(handle, | |
3971 LB_ADDSTRING, | |
3972 0, (LPARAM)text); | |
3973 } | |
3974 | |
3975 /* | |
3976 * Clears the listbox's (or combobox) list of all entries. | |
3977 * Parameters: | |
3978 * handle: Handle to the listbox to be cleared. | |
3979 */ | |
3980 void dw_listbox_clear(HWND handle) | |
3981 { | |
3982 char tmpbuf[100]; | |
3983 | |
3984 GetClassName(handle, tmpbuf, 99); | |
3985 | |
3986 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0) | |
3987 { | |
3988 char *buf = dw_window_get_text(handle); | |
3989 | |
3990 SendMessage(handle, | |
3991 CB_RESETCONTENT, 0L, 0L); | |
3992 | |
3993 if(buf) | |
3994 { | |
3995 dw_window_set_text(handle, buf); | |
3996 free(buf); | |
3997 } | |
3998 } | |
3999 else | |
4000 SendMessage(handle, | |
4001 LB_RESETCONTENT, 0L, 0L); | |
4002 } | |
4003 | |
4004 /* | |
4005 * Sets the text of a given listbox entry. | |
4006 * Parameters: | |
4007 * handle: Handle to the listbox to be queried. | |
4008 * index: Index into the list to be queried. | |
4009 * buffer: Buffer where text will be copied. | |
4010 */ | |
4011 void dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) | |
4012 { | |
4013 unsigned int sel = (unsigned int)SendMessage(handle, LB_GETCURSEL, 0, 0); | |
4014 SendMessage(handle, LB_DELETESTRING, (WPARAM)index, 0); | |
4015 SendMessage(handle, LB_INSERTSTRING, (WPARAM)index, (LPARAM)buffer); | |
4016 SendMessage(handle, LB_SETCURSEL, (WPARAM)sel, 0); | |
4017 SendMessage(handle, LB_SETSEL, (WPARAM)TRUE, (LPARAM)sel); | |
4018 } | |
4019 | |
4020 /* | |
4021 * Copies the given index item's text into buffer. | |
4022 * Parameters: | |
4023 * handle: Handle to the listbox to be queried. | |
4024 * index: Index into the list to be queried. | |
4025 * buffer: Buffer where text will be copied. | |
4026 * length: Length of the buffer (including NULL). | |
4027 */ | |
4028 void dw_listbox_query_text(HWND handle, unsigned int index, char *buffer, unsigned int length) | |
4029 { | |
4030 SendMessage(handle, | |
4031 LB_GETTEXT, (WPARAM)index, (LPARAM)buffer); | |
4032 } | |
4033 | |
4034 /* | |
4035 * Returns the index to the item in the list currently selected. | |
4036 * Parameters: | |
4037 * handle: Handle to the listbox to be queried. | |
4038 */ | |
4039 unsigned int dw_listbox_selected(HWND handle) | |
4040 { | |
4041 char tmpbuf[100]; | |
4042 | |
4043 GetClassName(handle, tmpbuf, 99); | |
4044 | |
4045 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0) | |
4046 return (unsigned int)SendMessage(handle, | |
4047 CB_GETCURSEL, | |
4048 0, 0); | |
4049 | |
4050 return (unsigned int)SendMessage(handle, | |
4051 LB_GETCURSEL, | |
4052 0, 0); | |
4053 } | |
4054 | |
4055 /* | |
4056 * Returns the index to the current selected item or -1 when done. | |
4057 * Parameters: | |
4058 * handle: Handle to the listbox to be queried. | |
4059 * where: Either the previous return or -1 to restart. | |
4060 */ | |
4061 int dw_listbox_selected_multi(HWND handle, int where) | |
4062 { | |
4063 int *array, count, z; | |
4064 | |
4065 count = (int)SendMessage(handle, LB_GETSELCOUNT, 0, 0); | |
4066 if(count > 0) | |
4067 { | |
4068 array = malloc(sizeof(int)*count); | |
4069 SendMessage(handle, LB_GETSELITEMS, (WPARAM)count, (LPARAM)array); | |
4070 | |
4071 if(where == -1) | |
4072 { | |
4073 int ret = array[0]; | |
4074 free(array); | |
4075 return ret; | |
4076 } | |
4077 for(z=0;z<count;z++) | |
4078 { | |
4079 if(array[z] == where && (z+1) < count) | |
4080 { | |
4081 int ret = array[z+1]; | |
4082 free(array); | |
4083 return ret; | |
4084 } | |
4085 } | |
4086 free(array); | |
4087 } | |
4088 return -1; | |
4089 } | |
4090 | |
4091 /* | |
4092 * Sets the selection state of a given index. | |
4093 * Parameters: | |
4094 * handle: Handle to the listbox to be set. | |
4095 * index: Item index. | |
4096 * state: TRUE if selected FALSE if unselected. | |
4097 */ | |
4098 void dw_listbox_select(HWND handle, int index, int state) | |
4099 { | |
4100 char tmpbuf[100]; | |
4101 | |
4102 GetClassName(handle, tmpbuf, 99); | |
4103 | |
4104 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0) | |
4105 SendMessage(handle, CB_SETCURSEL, (WPARAM)index, 0); | |
4106 else | |
4107 { | |
4108 SendMessage(handle, LB_SETCURSEL, (WPARAM)index, 0); | |
4109 SendMessage(handle, LB_SETSEL, (WPARAM)state, (LPARAM)index); | |
4110 } | |
4111 _wndproc(handle, WM_COMMAND, (WPARAM)(LBN_SELCHANGE << 16), (LPARAM)handle); | |
4112 } | |
4113 | |
4114 /* | |
4115 * Deletes the item with given index from the list. | |
4116 * Parameters: | |
4117 * handle: Handle to the listbox to be set. | |
4118 * index: Item index. | |
4119 */ | |
4120 void dw_listbox_delete(HWND handle, int index) | |
4121 { | |
4122 SendMessage(handle, LB_DELETESTRING, (WPARAM)index, 0); | |
4123 } | |
4124 | |
4125 /* | |
4126 * Returns the listbox's item count. | |
4127 * Parameters: | |
4128 * handle: Handle to the listbox to be cleared. | |
4129 */ | |
4130 int dw_listbox_count(HWND handle) | |
4131 { | |
4132 char tmpbuf[100]; | |
4133 | |
4134 GetClassName(handle, tmpbuf, 99); | |
4135 | |
4136 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0) | |
4137 return (int)SendMessage(handle, | |
4138 CB_GETCOUNT,0L, 0L); | |
4139 | |
4140 return (int)SendMessage(handle, | |
4141 LB_GETCOUNT,0L, 0L); | |
4142 } | |
4143 | |
4144 /* | |
4145 * Sets the topmost item in the viewport. | |
4146 * Parameters: | |
4147 * handle: Handle to the listbox to be cleared. | |
4148 * top: Index to the top item. | |
4149 */ | |
4150 void dw_listbox_set_top(HWND handle, int top) | |
4151 { | |
4152 SendMessage(handle, LB_SETTOPINDEX, (WPARAM)top, 0); | |
4153 } | |
4154 | |
4155 #define MLE_MAX 200000 | |
4156 /* | |
4157 * Adds text to an MLE box and returns the current point. | |
4158 * Parameters: | |
4159 * handle: Handle to the MLE to be queried. | |
4160 * buffer: Text buffer to be imported. | |
4161 * startpoint: Point to start entering text. | |
4162 */ | |
4163 unsigned int dw_mle_import(HWND handle, char *buffer, int startpoint) | |
4164 { | |
4165 char *tmpbuf = malloc(MLE_MAX+1); | |
4166 int len; | |
4167 | |
4168 if(startpoint < 0) | |
4169 startpoint = 0; | |
4170 | |
4171 GetWindowText(handle, tmpbuf, MLE_MAX); | |
4172 tmpbuf[MLE_MAX] = 0; | |
4173 | |
4174 len = strlen(tmpbuf); | |
4175 if(len) | |
4176 memcpy(&tmpbuf[startpoint+strlen(buffer)], &tmpbuf[startpoint], (len-startpoint)); | |
4177 memcpy(&tmpbuf[startpoint], buffer, strlen(buffer)); | |
4178 | |
4179 tmpbuf[len+strlen(buffer)] = 0; | |
4180 | |
4181 SetWindowText(handle, tmpbuf); | |
4182 | |
4183 free(tmpbuf); | |
4184 return startpoint+strlen(buffer); | |
4185 } | |
4186 | |
4187 /* | |
4188 * Grabs text from an MLE box. | |
4189 * Parameters: | |
4190 * handle: Handle to the MLE to be queried. | |
4191 * buffer: Text buffer to be exported. | |
4192 * startpoint: Point to start grabbing text. | |
4193 * length: Amount of text to be grabbed. | |
4194 */ | |
4195 void dw_mle_export(HWND handle, char *buffer, int startpoint, int length) | |
4196 { | |
4197 char *tmpbuf = malloc(MLE_MAX+1); | |
4198 | |
4199 GetWindowText(handle, tmpbuf, MLE_MAX); | |
4200 tmpbuf[MLE_MAX] = 0; | |
4201 | |
4202 memcpy(buffer, &tmpbuf[startpoint], length); | |
4203 | |
4204 free(tmpbuf); | |
4205 } | |
4206 | |
4207 /* | |
4208 * Obtains information about an MLE box. | |
4209 * Parameters: | |
4210 * handle: Handle to the MLE to be queried. | |
4211 * bytes: A pointer to a variable to return the total bytes. | |
4212 * lines: A pointer to a variable to return the number of lines. | |
4213 */ | |
4214 void dw_mle_query(HWND handle, unsigned long *bytes, unsigned long *lines) | |
4215 { | |
4216 char *tmpbuf = malloc(MLE_MAX+1); | |
4217 | |
4218 GetWindowText(handle, tmpbuf, MLE_MAX); | |
4219 tmpbuf[MLE_MAX] = 0; | |
4220 | |
4221 if(bytes) | |
4222 *bytes = strlen(tmpbuf); | |
4223 if(lines) | |
4224 *lines = (unsigned long)SendMessage(handle, EM_GETLINECOUNT, 0, 0); | |
4225 | |
4226 free(tmpbuf); | |
4227 } | |
4228 | |
4229 /* | |
4230 * Deletes text from an MLE box. | |
4231 * Parameters: | |
4232 * handle: Handle to the MLE to be deleted from. | |
4233 * startpoint: Point to start deleting text. | |
4234 * length: Amount of text to be deleted. | |
4235 */ | |
4236 void dw_mle_delete(HWND handle, int startpoint, int length) | |
4237 { | |
4238 char *tmpbuf = malloc(MLE_MAX+1); | |
4239 int len; | |
4240 | |
4241 GetWindowText(handle, tmpbuf, MLE_MAX); | |
4242 tmpbuf[MLE_MAX] = 0; | |
4243 | |
4244 len = strlen(tmpbuf); | |
4245 | |
4246 strcpy(&tmpbuf[startpoint], &tmpbuf[startpoint+length]); | |
4247 | |
4248 SetWindowText(handle, tmpbuf); | |
4249 | |
4250 free(tmpbuf); | |
4251 } | |
4252 | |
4253 /* | |
4254 * Clears all text from an MLE box. | |
4255 * Parameters: | |
4256 * handle: Handle to the MLE to be cleared. | |
4257 */ | |
4258 void dw_mle_clear(HWND handle) | |
4259 { | |
4260 SetWindowText(handle, ""); | |
4261 } | |
4262 | |
4263 /* | |
4264 * Sets the visible line of an MLE box. | |
4265 * Parameters: | |
4266 * handle: Handle to the MLE. | |
4267 * line: Line to be visible. | |
4268 */ | |
4269 void dw_mle_set_visible(HWND handle, int line) | |
4270 { | |
4271 int point = (int)SendMessage(handle, EM_LINEINDEX, (WPARAM)line, 0); | |
4272 dw_mle_set(handle, point); | |
4273 } | |
4274 | |
4275 /* | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4276 * Sets the editablity of an MLE box. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4277 * Parameters: |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4278 * handle: Handle to the MLE. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4279 * 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
|
4280 */ |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4281 void dw_mle_set_editable(HWND handle, int state) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4282 { |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4283 SendMessage(handle, EM_SETREADONLY, (WPARAM)(state ? FALSE : TRUE), 0); |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4284 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4285 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4286 /* |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4287 * Sets the word wrap state of an MLE box. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4288 * Parameters: |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4289 * handle: Handle to the MLE. |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4290 * 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
|
4291 */ |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4292 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
|
4293 { |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4294 /* If ES_AUTOHSCROLL is not set and there is not |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4295 * horizontal scrollbar it word wraps. |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4296 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4297 if(state) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4298 dw_window_set_style(handle, 0, ES_AUTOHSCROLL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4299 else |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4300 dw_window_set_style(handle, ES_AUTOHSCROLL, ES_AUTOHSCROLL); |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4301 } |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4302 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4303 /* |
3 | 4304 * Sets the current cursor position of an MLE box. |
4305 * Parameters: | |
4306 * handle: Handle to the MLE to be positioned. | |
4307 * point: Point to position cursor. | |
4308 */ | |
4309 void dw_mle_set(HWND handle, int point) | |
4310 { | |
4311 SendMessage(handle, EM_SETSEL, (WPARAM)point, (LPARAM)point); | |
4312 SendMessage(handle, EM_SCROLLCARET, 0, 0); | |
4313 } | |
4314 | |
4315 /* | |
4316 * Finds text in an MLE box. | |
4317 * Parameters: | |
4318 * handle: Handle to the MLE to be cleared. | |
4319 * text: Text to search for. | |
4320 * point: Start point of search. | |
4321 * flags: Search specific flags. | |
4322 */ | |
4323 int dw_mle_search(HWND handle, char *text, int point, unsigned long flags) | |
4324 { | |
4325 char *tmpbuf = malloc(MLE_MAX+1); | |
4326 int z, len, textlen, retval = 0; | |
4327 | |
4328 GetWindowText(handle, tmpbuf, MLE_MAX); | |
4329 tmpbuf[MLE_MAX] = 0; | |
4330 | |
4331 len = strlen(tmpbuf); | |
4332 textlen = strlen(text); | |
4333 | |
4334 if(flags & DW_MLE_CASESENSITIVE) | |
4335 { | |
4336 for(z=point;z<(len-textlen) && !retval;z++) | |
4337 { | |
4338 if(strncmp(&tmpbuf[z], text, textlen) == 0) | |
4339 retval = z + textlen; | |
4340 } | |
4341 } | |
4342 else | |
4343 { | |
4344 for(z=point;z<(len-textlen) && !retval;z++) | |
4345 { | |
4346 if(strnicmp(&tmpbuf[z], text, textlen) == 0) | |
4347 retval = z + textlen; | |
4348 } | |
4349 } | |
4350 | |
4351 if(retval) | |
4352 { | |
4353 SendMessage(handle, EM_SETSEL, (WPARAM)retval - textlen, (LPARAM)retval); | |
4354 SendMessage(handle, EM_SCROLLCARET, 0, 0); | |
4355 } | |
4356 | |
4357 free(tmpbuf); | |
4358 | |
4359 return retval; | |
4360 } | |
4361 | |
4362 /* | |
4363 * Stops redrawing of an MLE box. | |
4364 * Parameters: | |
4365 * handle: Handle to the MLE to freeze. | |
4366 */ | |
4367 void dw_mle_freeze(HWND handle) | |
4368 { | |
4369 } | |
4370 | |
4371 /* | |
4372 * Resumes redrawing of an MLE box. | |
4373 * Parameters: | |
4374 * handle: Handle to the MLE to thaw. | |
4375 */ | |
4376 void dw_mle_thaw(HWND handle) | |
4377 { | |
4378 } | |
4379 | |
4380 /* | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
32
diff
changeset
|
4381 * Returns the range of the percent bar. |
3 | 4382 * Parameters: |
4383 * handle: Handle to the slider to be queried. | |
4384 */ | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
32
diff
changeset
|
4385 unsigned int dw_percent_query_range(HWND handle) |
3 | 4386 { |
4387 return (unsigned int)SendMessage(handle, PBM_GETRANGE, (WPARAM)FALSE, 0); | |
4388 } | |
4389 | |
4390 /* | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
32
diff
changeset
|
4391 * Sets the percent bar position. |
3 | 4392 * Parameters: |
4393 * handle: Handle to the slider to be set. | |
4394 * position: Position of the slider withing the range. | |
4395 */ | |
33
72675de7d229
Renamed slider class to percent class. Implemented my own percent widget
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
32
diff
changeset
|
4396 void dw_percent_set_pos(HWND handle, unsigned int position) |
3 | 4397 { |
4398 SendMessage(handle, PBM_SETPOS, (WPARAM)position, 0); | |
4399 } | |
4400 | |
4401 /* | |
4402 * Sets the spinbutton value. | |
4403 * Parameters: | |
4404 * handle: Handle to the spinbutton to be set. | |
4405 * position: Current value of the spinbutton. | |
4406 */ | |
4407 void dw_spinbutton_set_pos(HWND handle, long position) | |
4408 { | |
4409 char tmpbuf[100]; | |
4410 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); | |
4411 | |
4412 sprintf(tmpbuf, "%d", position); | |
4413 | |
4414 if(cinfo && cinfo->buddy) | |
4415 SetWindowText(cinfo->buddy, tmpbuf); | |
4416 | |
4417 if(IS_WIN98PLUS) | |
4418 SendMessage(handle, UDM_SETPOS32, 0, (LPARAM)position); | |
4419 else | |
4420 SendMessage(handle, UDM_SETPOS, 0, (LPARAM)MAKELONG((short)position, 0)); | |
4421 } | |
4422 | |
4423 /* | |
4424 * Sets the spinbutton limits. | |
4425 * Parameters: | |
4426 * handle: Handle to the spinbutton to be set. | |
4427 * position: Current value of the spinbutton. | |
4428 * position: Current value of the spinbutton. | |
4429 */ | |
4430 void dw_spinbutton_set_limits(HWND handle, long upper, long lower) | |
4431 { | |
4432 if(IS_WIN98PLUS) | |
4433 SendMessage(handle, UDM_SETRANGE32, (WPARAM)lower,(LPARAM)upper); | |
4434 else | |
4435 SendMessage(handle, UDM_SETRANGE32, (WPARAM)((short)lower), | |
4436 (LPARAM)((short)upper)); | |
4437 } | |
4438 | |
4439 /* | |
4440 * Sets the entryfield character limit. | |
4441 * Parameters: | |
4442 * handle: Handle to the spinbutton to be set. | |
4443 * limit: Number of characters the entryfield will take. | |
4444 */ | |
4445 void dw_entryfield_set_limit(HWND handle, ULONG limit) | |
4446 { | |
4447 SendMessage(handle, EM_SETLIMITTEXT, (WPARAM)limit, 0); | |
4448 } | |
4449 | |
4450 /* | |
4451 * Returns the current value of the spinbutton. | |
4452 * Parameters: | |
4453 * handle: Handle to the spinbutton to be queried. | |
4454 */ | |
4455 long dw_spinbutton_query(HWND handle) | |
4456 { | |
4457 if(IS_WIN98PLUS) | |
4458 return (long)SendMessage(handle, UDM_GETPOS32, 0, 0); | |
4459 else | |
4460 return (long)SendMessage(handle, UDM_GETPOS, 0, 0); | |
4461 } | |
4462 | |
4463 /* | |
4464 * Returns the state of the checkbox. | |
4465 * Parameters: | |
4466 * handle: Handle to the checkbox to be queried. | |
4467 */ | |
4468 int dw_checkbox_query(HWND handle) | |
4469 { | |
4470 if(SendMessage(handle, BM_GETCHECK, 0, 0) == BST_CHECKED) | |
4471 return TRUE; | |
4472 return FALSE; | |
4473 } | |
4474 | |
4475 /* | |
4476 * Sets the state of the checkbox. | |
4477 * Parameters: | |
4478 * handle: Handle to the checkbox to be queried. | |
4479 * value: TRUE for checked, FALSE for unchecked. | |
4480 */ | |
4481 void dw_checkbox_set(HWND handle, int value) | |
4482 { | |
4483 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); | |
4484 | |
4485 if(cinfo && !cinfo->user) | |
4486 SendMessage(handle, BM_CLICK, 0, 0); | |
4487 SendMessage(handle, BM_SETCHECK, (WPARAM)value, 0); | |
4488 } | |
4489 | |
4490 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4491 * 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:
17
diff
changeset
|
4492 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4493 * 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:
17
diff
changeset
|
4494 * 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:
17
diff
changeset
|
4495 * 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:
17
diff
changeset
|
4496 * 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:
17
diff
changeset
|
4497 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4498 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:
17
diff
changeset
|
4499 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4500 TVITEM tvi; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4501 TVINSERTSTRUCT tvins; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4502 HTREEITEM hti; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4503 |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4504 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4505 tvi.pszText = title; |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4506 tvi.lParam = (LONG)title; |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4507 tvi.cchTextMax = strlen(title); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4508 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4509 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4510 tvins.item = tvi; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4511 tvins.hParent = (HTREEITEM)parent; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4512 tvins.hInsertAfter = TVI_LAST; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4513 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4514 hti = TreeView_InsertItem(handle, &tvins); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4515 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4516 return (HWND)hti; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4517 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4518 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4519 /* |
30
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4520 * Removes all nodes from a tree. |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4521 * Parameters: |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4522 * 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
|
4523 */ |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4524 void dw_tree_clear(HWND handle) |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4525 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4526 TreeView_DeleteAllItems(handle); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4527 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4528 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4529 /* |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4530 * Removes a node from a tree. |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4531 * Parameters: |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4532 * 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
|
4533 * item: Handle to node to be deleted. |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4534 */ |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4535 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
|
4536 { |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4537 TreeView_DeleteItem(handle, (HTREEITEM)item); |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4538 } |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4539 |
b1d7e8a28dfa
Added tree view functions and signal.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
4540 /* |
3 | 4541 * Sets up the container columns. |
4542 * Parameters: | |
4543 * handle: Handle to the container to be configured. | |
4544 * flags: An array of unsigned longs with column flags. | |
4545 * titles: An array of strings with column text titles. | |
4546 * count: The number of columns (this should match the arrays). | |
4547 * separator: The column number that contains the main separator. | |
4548 * (only used on OS/2 but must be >= 0 on all) | |
4549 */ | |
4550 int dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator) | |
4551 { | |
4552 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLong(handle, GWL_USERDATA); | |
4553 int z, l = 0; | |
4554 unsigned long *tempflags = malloc(sizeof(unsigned long) * (count + 2)); | |
4555 LV_COLUMN lvc; | |
4556 | |
4557 if(separator == -1) | |
4558 l = 1; | |
4559 | |
4560 memcpy(&tempflags[l], flags, sizeof(unsigned long) * count); | |
4561 tempflags[count + l] = 0; | |
4562 cinfo->flags = tempflags; | |
4563 | |
4564 | |
4565 for(z=0;z<count;z++) | |
4566 { | |
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
|
4567 if(titles[z]) |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4568 { |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4569 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM /*| LVCF_FORMAT*/; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4570 lvc.pszText = titles[z]; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4571 lvc.cchTextMax = strlen(titles[z]); |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4572 lvc.fmt = flags[z]; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4573 lvc.cx = 75; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4574 lvc.iSubItem = count; |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4575 SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)z + l, (LPARAM)&lvc); |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4576 } |
3 | 4577 } |
4578 ListView_SetExtendedListViewStyle(handle, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); | |
4579 return TRUE; | |
4580 } | |
4581 | |
4582 /* | |
4583 * Sets up the filesystem columns, note: filesystem always has an icon/filename field. | |
4584 * Parameters: | |
4585 * handle: Handle to the container to be configured. | |
4586 * flags: An array of unsigned longs with column flags. | |
4587 * titles: An array of strings with column text titles. | |
4588 * count: The number of columns (this should match the arrays). | |
4589 */ | |
4590 int dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count) | |
4591 { | |
4592 LV_COLUMN lvc; | |
4593 | |
4594 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; | |
4595 lvc.pszText = "Filename"; | |
4596 lvc.cchTextMax = 8; | |
4597 lvc.fmt = 0; | |
4598 if(!count) | |
4599 lvc.cx = 300; | |
4600 else | |
4601 lvc.cx = 150; | |
4602 lvc.iSubItem = count; | |
4603 SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)0, (LPARAM)&lvc); | |
4604 dw_container_setup(handle, flags, titles, count, -1); | |
4605 return TRUE; | |
4606 } | |
4607 | |
4608 /* | |
4609 * Obtains an icon from a module (or header in GTK). | |
4610 * Parameters: | |
4611 * module: Handle to module (DLL) in OS/2 and Windows. | |
4612 * id: A unsigned long id int the resources on OS/2 and | |
4613 * Windows, on GTK this is converted to a pointer | |
4614 * to an embedded XPM. | |
4615 */ | |
4616 unsigned long dw_icon_load(unsigned long module, unsigned long id) | |
4617 { | |
4618 return (unsigned long)LoadIcon(DWInstance, MAKEINTRESOURCE(id)); | |
4619 } | |
4620 | |
4621 /* | |
4622 * Frees a loaded resource in OS/2 and Windows. | |
4623 * Parameters: | |
4624 * handle: Handle to icon returned by dw_icon_load(). | |
4625 */ | |
4626 void dw_icon_free(unsigned long handle) | |
4627 { | |
4628 DestroyIcon((HICON)handle); | |
4629 } | |
4630 | |
4631 /* | |
4632 * Allocates memory used to populate a container. | |
4633 * Parameters: | |
4634 * handle: Handle to the container window (widget). | |
4635 * rowcount: The number of items to be populated. | |
4636 */ | |
4637 void *dw_container_alloc(HWND handle, int rowcount) | |
4638 { | |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4639 LV_ITEM lvi; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4640 int z; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4641 |
32
f3bf96c2786d
Added missing exports, added new tree functions and signals, fixed Win32
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
30
diff
changeset
|
4642 lvi.mask = LVIF_DI_SETITEM | LVIF_TEXT | LVIF_IMAGE; |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4643 lvi.iSubItem = 0; |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4644 /* Insert at the end */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4645 lvi.iItem = 1000000; |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4646 lvi.pszText = ""; |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4647 lvi.cchTextMax = 1; |
32
f3bf96c2786d
Added missing exports, added new tree functions and signals, fixed Win32
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
30
diff
changeset
|
4648 lvi.iImage = -1; |
7
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4649 |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4650 for(z=0;z<rowcount;z++) |
005fa766e8c2
Updates to latest build.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
4651 ListView_InsertItem(handle, &lvi); |
3 | 4652 return (void *)handle; |
4653 } | |
4654 | |
4655 /* Finds a icon in the table, otherwise it adds it to the table | |
4656 * and returns the index in the table. | |
4657 */ | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4658 int _lookup_icon(HWND handle, HICON hicon, int type) |
3 | 4659 { |
4660 int z; | |
4661 static HWND lasthwnd = NULL; | |
4662 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4663 if(!hSmall || !hLarge) |
3 | 4664 { |
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
|
4665 hSmall = ImageList_Create(16, 16, ILC_COLOR16, ICON_INDEX_LIMIT, 0); |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
4666 hLarge = ImageList_Create(32, 32, ILC_COLOR16, ICON_INDEX_LIMIT, 0); |
3 | 4667 } |
4668 for(z=0;z<ICON_INDEX_LIMIT;z++) | |
4669 { | |
4670 if(!lookup[z]) | |
4671 { | |
4672 lookup[z] = hicon; | |
4673 ImageList_AddIcon(hSmall, hicon); | |
4674 ImageList_AddIcon(hLarge, hicon); | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4675 if(type) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4676 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4677 TreeView_SetImageList(handle, hSmall, TVSIL_NORMAL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4678 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4679 else |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4680 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4681 ListView_SetImageList(handle, hSmall, LVSIL_SMALL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4682 ListView_SetImageList(handle, hLarge, LVSIL_NORMAL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4683 } |
3 | 4684 lasthwnd = handle; |
4685 return z; | |
4686 } | |
4687 | |
4688 if(hicon == lookup[z]) | |
4689 { | |
4690 if(lasthwnd != handle) | |
4691 { | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4692 if(type) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4693 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4694 TreeView_SetImageList(handle, hSmall, TVSIL_NORMAL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4695 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4696 else |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4697 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4698 ListView_SetImageList(handle, hSmall, LVSIL_SMALL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4699 ListView_SetImageList(handle, hLarge, LVSIL_NORMAL); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4700 } |
3 | 4701 lasthwnd = handle; |
4702 } | |
4703 return z; | |
4704 } | |
4705 } | |
4706 return -1; | |
4707 } | |
4708 | |
4709 /* | |
4710 * Sets an item in specified row and column to the given data. | |
4711 * Parameters: | |
4712 * handle: Handle to the container window (widget). | |
4713 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
4714 * column: Zero based column of data being set. | |
4715 * row: Zero based row of data being set. | |
4716 * data: Pointer to the data to be added. | |
4717 */ | |
4718 void dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon) | |
4719 { | |
4720 LV_ITEM lvi; | |
4721 | |
4722 lvi.iItem = row; | |
4723 lvi.iSubItem = 0; | |
4724 lvi.mask = LVIF_DI_SETITEM | LVIF_IMAGE | LVIF_TEXT; | |
4725 lvi.pszText = filename; | |
4726 lvi.cchTextMax = strlen(filename); | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4727 lvi.iImage = _lookup_icon(handle, (HICON)icon, 0); |
3 | 4728 |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
4729 ListView_SetItem(handle, &lvi); |
3 | 4730 } |
4731 | |
4732 /* | |
4733 * Sets an item in specified row and column to the given data. | |
4734 * Parameters: | |
4735 * handle: Handle to the container window (widget). | |
4736 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
4737 * column: Zero based column of data being set. | |
4738 * row: Zero based row of data being set. | |
4739 * data: Pointer to the data to be added. | |
4740 */ | |
4741 void dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data) | |
4742 { | |
4743 dw_container_set_item(handle, pointer, column + 1, row, data); | |
4744 } | |
4745 | |
4746 /* | |
4747 * Sets an item in specified row and column to the given data. | |
4748 * Parameters: | |
4749 * handle: Handle to the container window (widget). | |
4750 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
4751 * column: Zero based column of data being set. | |
4752 * row: Zero based row of data being set. | |
4753 * data: Pointer to the data to be added. | |
4754 */ | |
4755 void dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) | |
4756 { | |
4757 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLong(handle, GWL_USERDATA); | |
4758 ULONG *flags; | |
4759 LV_ITEM lvi; | |
4760 char textbuffer[100], *destptr = textbuffer; | |
4761 | |
4762 if(!cinfo || !cinfo->flags || !data) | |
4763 return; | |
4764 | |
4765 flags = cinfo->flags; | |
4766 | |
4767 lvi.mask = LVIF_DI_SETITEM | LVIF_TEXT; | |
4768 lvi.iItem = row; | |
4769 lvi.iSubItem = column; | |
4770 | |
4771 if(flags[column] & DW_CFA_BITMAPORICON) | |
4772 { | |
4773 HICON hicon = *((HICON *)data); | |
4774 | |
4775 lvi.mask = LVIF_DI_SETITEM | LVIF_IMAGE; | |
4776 lvi.pszText = NULL; | |
4777 lvi.cchTextMax = 0; | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4778 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4779 lvi.iImage = _lookup_icon(handle, hicon, 0); |
3 | 4780 } |
4781 else if(flags[column] & DW_CFA_STRING) | |
4782 { | |
4783 char *tmp = *((char **)data); | |
4784 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4785 if(!tmp) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4786 tmp = ""; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4787 |
3 | 4788 lvi.pszText = tmp; |
4789 lvi.cchTextMax = strlen(tmp); | |
4790 destptr = tmp; | |
4791 } | |
4792 else if(flags[column] & DW_CFA_ULONG) | |
4793 { | |
4794 ULONG tmp = *((ULONG *)data); | |
4795 | |
4796 sprintf(textbuffer, "%lu", tmp); | |
4797 | |
4798 lvi.pszText = textbuffer; | |
4799 lvi.cchTextMax = strlen(textbuffer); | |
4800 } | |
4801 else if(flags[column] & DW_CFA_DATE) | |
4802 { | |
4803 CDATE fdate = *((CDATE *)data); | |
4804 | |
4805 sprintf(textbuffer, "%s %d, %d", monthlist[fdate.month], fdate.day, fdate.year); | |
4806 lvi.pszText = textbuffer; | |
4807 lvi.cchTextMax = strlen(textbuffer); | |
4808 } | |
4809 else if(flags[column] & DW_CFA_TIME) | |
4810 { | |
4811 CTIME ftime = *((CTIME *)data); | |
4812 | |
4813 if(ftime.hours > 12) | |
4814 sprintf(textbuffer, "%d:%s%dpm", ftime.hours - 12, (ftime.minutes < 10) ? "0" : "", ftime.minutes); | |
4815 else | |
4816 sprintf(textbuffer, "%d:%s%dam", ftime.hours ? ftime.hours : 12, (ftime.minutes < 10) ? "0" : "", ftime.minutes); | |
4817 lvi.pszText = textbuffer; | |
4818 lvi.cchTextMax = strlen(textbuffer); | |
4819 } | |
4820 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4821 ListView_SetItem(handle, &lvi); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4822 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4823 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4824 /* |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4825 * 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:
17
diff
changeset
|
4826 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4827 * 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:
17
diff
changeset
|
4828 * 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:
17
diff
changeset
|
4829 * 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:
17
diff
changeset
|
4830 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4831 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:
17
diff
changeset
|
4832 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4833 ListView_SetColumnWidth(handle, column, width); |
3 | 4834 } |
4835 | |
4836 /* | |
4837 * Sets the title of a row in the container. | |
4838 * Parameters: | |
4839 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
4840 * row: Zero based row of data being set. | |
4841 * title: String title of the item. | |
4842 */ | |
4843 void dw_container_set_row_title(void *pointer, int row, char *title) | |
4844 { | |
4845 LV_ITEM lvi; | |
4846 HWND container = (HWND)pointer; | |
4847 | |
4848 lvi.iItem = row; | |
4849 lvi.iSubItem = 0; | |
4850 lvi.mask = LVIF_PARAM; | |
4851 lvi.lParam = (LPARAM)title; | |
4852 | |
4853 if(!ListView_SetItem(container, &lvi) && lvi.lParam) | |
4854 lvi.lParam = 0; | |
4855 | |
4856 } | |
4857 | |
4858 /* | |
4859 * Sets the title of a row in the container. | |
4860 * Parameters: | |
4861 * handle: Handle to the container window (widget). | |
4862 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
4863 * rowcount: The number of rows to be inserted. | |
4864 */ | |
4865 void dw_container_insert(HWND handle, void *pointer, int rowcount) | |
4866 { | |
4867 /* This isn't a separate step in windows. */ | |
4868 } | |
4869 | |
4870 /* | |
4871 * Removes all rows from a container. | |
4872 * Parameters: | |
4873 * handle: Handle to the window (widget) to be cleared. | |
4874 */ | |
4875 void dw_container_clear(HWND handle) | |
4876 { | |
4877 ListView_DeleteAllItems(handle); | |
4878 } | |
4879 | |
4880 /* | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4881 * 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:
17
diff
changeset
|
4882 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4883 * 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:
17
diff
changeset
|
4884 * 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:
17
diff
changeset
|
4885 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4886 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:
17
diff
changeset
|
4887 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4888 int z; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4889 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4890 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:
17
diff
changeset
|
4891 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4892 ListView_DeleteItem(handle, 0); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4893 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4894 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4895 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4896 /* |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4897 * 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:
17
diff
changeset
|
4898 * Parameters: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4899 * 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:
17
diff
changeset
|
4900 * 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:
17
diff
changeset
|
4901 * 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:
17
diff
changeset
|
4902 * 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:
17
diff
changeset
|
4903 */ |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4904 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:
17
diff
changeset
|
4905 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4906 switch(direction) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4907 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4908 case DW_SCROLL_TOP: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4909 ListView_Scroll(handle, 0, -10000000); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4910 break; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4911 case DW_SCROLL_BOTTOM: |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4912 ListView_Scroll(handle, 0, 10000000); |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4913 break; |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4914 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4915 } |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4916 |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
17
diff
changeset
|
4917 /* |
3 | 4918 * Removes all rows from a container. |
4919 * Parameters: | |
4920 * handle: Handle to the window (widget) to be cleared. | |
4921 */ | |
4922 void dw_container_set_view(HWND handle, unsigned long flags, int iconwidth, int iconheight) | |
4923 { | |
4924 } | |
4925 | |
4926 /* | |
4927 * Starts a new query of a container. | |
4928 * Parameters: | |
4929 * handle: Handle to the window (widget) to be queried. | |
4930 * flags: If this parameter is DW_CRA_SELECTED it will only | |
4931 * return items that are currently selected. Otherwise | |
4932 * it will return all records in the container. | |
4933 */ | |
4934 char *dw_container_query_start(HWND handle, unsigned long flags) | |
4935 { | |
4936 LV_ITEM lvi; | |
4937 | |
4938 if(flags) | |
4939 _index = ListView_GetNextItem(handle, -1, LVNI_SELECTED); | |
4940 else | |
4941 _index = ListView_GetNextItem(handle, -1, LVNI_ALL); | |
4942 | |
4943 | |
4944 lvi.iItem = _index; | |
4945 lvi.mask = LVIF_PARAM; | |
4946 | |
4947 ListView_GetItem(handle, &lvi); | |
4948 | |
4949 return (char *)lvi.lParam; | |
4950 } | |
4951 | |
4952 /* | |
4953 * Continues an existing query of a container. | |
4954 * Parameters: | |
4955 * handle: Handle to the window (widget) to be queried. | |
4956 * flags: If this parameter is DW_CRA_SELECTED it will only | |
4957 * return items that are currently selected. Otherwise | |
4958 * it will return all records in the container. | |
4959 */ | |
4960 char *dw_container_query_next(HWND handle, unsigned long flags) | |
4961 { | |
4962 LV_ITEM lvi; | |
4963 | |
4964 if(flags) | |
4965 _index = ListView_GetNextItem(handle, _index, LVNI_SELECTED); | |
4966 else | |
4967 _index = ListView_GetNextItem(handle, _index, LVNI_ALL); | |
4968 | |
4969 if(_index == -1) | |
4970 return NULL; | |
4971 | |
4972 lvi.iItem = _index; | |
4973 lvi.mask = LVIF_PARAM; | |
4974 | |
4975 ListView_GetItem(handle, &lvi); | |
4976 | |
4977 return (char *)lvi.lParam; | |
4978 } | |
4979 | |
4980 /* | |
4981 * Creates a rendering context widget (window) to be packed. | |
4982 * Parameters: | |
4983 * id: An id to be used with dw_window_from_id. | |
4984 * Returns: | |
4985 * A handle to the widget or NULL on failure. | |
4986 */ | |
4987 HWND dw_render_new(unsigned long id) | |
4988 { | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
4989 Box *newbox = malloc(sizeof(Box)); |
3 | 4990 HWND tmp = CreateWindow(ObjectClassName, |
4991 "", | |
4992 WS_CHILD | WS_CLIPCHILDREN, | |
4993 0,0,2000,1000, | |
4994 DW_HWND_OBJECT, | |
4995 NULL, | |
4996 NULL, | |
4997 NULL); | |
17
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
4998 newbox->pad = 0; |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
4999 newbox->type = 0; |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
5000 newbox->count = 0; |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
5001 newbox->grouphwnd = (HWND)NULL; |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
5002 newbox->cinfo.pOldProc = SubclassWindow(tmp, _rendwndproc); |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
5003 newbox->cinfo.fore = newbox->cinfo.back = -1; |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
5004 |
f26eced21a30
Some more updates.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
15
diff
changeset
|
5005 SetWindowLong(tmp, GWL_USERDATA, (ULONG)newbox); |
3 | 5006 return tmp; |
5007 } | |
5008 | |
5009 /* Sets the current foreground drawing color. | |
5010 * Parameters: | |
5011 * red: red value. | |
5012 * green: green value. | |
5013 * blue: blue value. | |
5014 */ | |
5015 void dw_color_foreground_set(unsigned long value) | |
5016 { | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5017 int threadid = dw_thread_id(); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5018 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5019 if(threadid < 0 || threadid >= THREAD_LIMIT) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5020 threadid = 0; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5021 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5022 DeleteObject(_hPen[threadid]); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5023 DeleteObject(_hBrush[threadid]); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5024 _foreground[threadid] = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5025 _hPen[threadid] = CreatePen(PS_SOLID, 1, _foreground[threadid]); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5026 _hBrush[threadid] = CreateSolidBrush(_foreground[threadid]); |
3 | 5027 } |
5028 | |
5029 /* Sets the current background drawing color. | |
5030 * Parameters: | |
5031 * red: red value. | |
5032 * green: green value. | |
5033 * blue: blue value. | |
5034 */ | |
5035 void dw_color_background_set(unsigned long value) | |
5036 { | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5037 int threadid = dw_thread_id(); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5038 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5039 if(threadid < 0 || threadid >= THREAD_LIMIT) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5040 threadid = 0; |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5041 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5042 _background[threadid] = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); |
3 | 5043 } |
5044 | |
5045 /* Draw a point on a window (preferably a render window). | |
5046 * Parameters: | |
5047 * handle: Handle to the window. | |
5048 * pixmap: Handle to the pixmap. (choose only one of these) | |
5049 * x: X coordinate. | |
5050 * y: Y coordinate. | |
5051 */ | |
5052 void dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) | |
5053 { | |
5054 HDC hdcPaint; | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5055 int threadid = dw_thread_id(); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5056 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5057 if(threadid < 0 || threadid >= THREAD_LIMIT) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5058 threadid = 0; |
3 | 5059 |
5060 if(handle) | |
5061 hdcPaint = GetDC(handle); | |
5062 else if(pixmap) | |
5063 hdcPaint = pixmap->hdc; | |
5064 else | |
5065 return; | |
5066 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5067 SetPixel(hdcPaint, x, y, _foreground[threadid]); |
3 | 5068 if(!pixmap) |
5069 ReleaseDC(handle, hdcPaint); | |
5070 } | |
5071 | |
5072 /* Draw a line on a window (preferably a render window). | |
5073 * Parameters: | |
5074 * handle: Handle to the window. | |
5075 * pixmap: Handle to the pixmap. (choose only one of these) | |
5076 * x1: First X coordinate. | |
5077 * y1: First Y coordinate. | |
5078 * x2: Second X coordinate. | |
5079 * y2: Second Y coordinate. | |
5080 */ | |
5081 void dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) | |
5082 { | |
5083 HDC hdcPaint; | |
5084 HPEN oldPen; | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5085 int threadid = dw_thread_id(); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5086 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5087 if(threadid < 0 || threadid >= THREAD_LIMIT) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5088 threadid = 0; |
3 | 5089 |
5090 if(handle) | |
5091 hdcPaint = GetDC(handle); | |
5092 else if(pixmap) | |
5093 hdcPaint = pixmap->hdc; | |
5094 else | |
5095 return; | |
5096 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5097 oldPen = SelectObject(hdcPaint, _hPen[threadid]); |
3 | 5098 MoveToEx(hdcPaint, x1, y1, NULL); |
5099 LineTo(hdcPaint, x2, y2); | |
5100 SelectObject(hdcPaint, oldPen); | |
5101 /* For some reason Win98 (at least) fails | |
5102 * to draw the last pixel. So I do it myself. | |
5103 */ | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5104 SetPixel(hdcPaint, x2, y2, _foreground[threadid]); |
3 | 5105 if(!pixmap) |
5106 ReleaseDC(handle, hdcPaint); | |
5107 } | |
5108 | |
5109 /* Draw a rectangle on a window (preferably a render window). | |
5110 * Parameters: | |
5111 * handle: Handle to the window. | |
5112 * pixmap: Handle to the pixmap. (choose only one of these) | |
5113 * x: X coordinate. | |
5114 * y: Y coordinate. | |
5115 * width: Width of rectangle. | |
5116 * height: Height of rectangle. | |
5117 */ | |
5118 void dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) | |
5119 { | |
5120 HDC hdcPaint; | |
5121 HPEN oldPen; | |
5122 HBRUSH oldBrush; | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5123 int threadid = dw_thread_id(); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5124 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5125 if(threadid < 0 || threadid >= THREAD_LIMIT) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5126 threadid = 0; |
3 | 5127 |
5128 if(handle) | |
5129 hdcPaint = GetDC(handle); | |
5130 else if(pixmap) | |
5131 hdcPaint = pixmap->hdc; | |
5132 else | |
5133 return; | |
5134 | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5135 oldPen = SelectObject(hdcPaint, _hPen[threadid]); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5136 oldBrush = SelectObject(hdcPaint, _hBrush[threadid]); |
3 | 5137 Rectangle(hdcPaint, x, y, x + width, y + height); |
5138 SelectObject(hdcPaint, oldPen); | |
5139 SelectObject(hdcPaint, oldBrush); | |
5140 if(!pixmap) | |
5141 ReleaseDC(handle, hdcPaint); | |
5142 } | |
5143 | |
5144 /* Draw text on a window (preferably a render window). | |
5145 * Parameters: | |
5146 * handle: Handle to the window. | |
5147 * pixmap: Handle to the pixmap. (choose only one of these) | |
5148 * x: X coordinate. | |
5149 * y: Y coordinate. | |
5150 * text: Text to be displayed. | |
5151 */ | |
5152 void dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) | |
5153 { | |
5154 HDC hdc; | |
5155 int size = 9, z, mustdelete = 0; | |
5156 HFONT hFont, oldFont; | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5157 int threadid = dw_thread_id(); |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5158 |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5159 if(threadid < 0 || threadid >= THREAD_LIMIT) |
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5160 threadid = 0; |
3 | 5161 |
5162 if(handle) | |
5163 hdc = GetDC(handle); | |
5164 else if(pixmap) | |
5165 hdc = pixmap->hdc; | |
5166 else | |
5167 return; | |
5168 | |
5169 { | |
5170 ColorInfo *cinfo; | |
5171 | |
5172 if(handle) | |
5173 cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); | |
5174 else | |
5175 cinfo = (ColorInfo *)GetWindowLong(pixmap->handle, GWL_USERDATA); | |
5176 | |
5177 if(cinfo) | |
5178 { | |
5179 hFont = _aquire_font(cinfo->fontname); | |
5180 mustdelete = 1; | |
5181 } | |
5182 } | |
5183 oldFont = SelectObject(hdc, hFont); | |
12
26e2130135b9
Many Win32 and GTK fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
7
diff
changeset
|
5184 SetTextColor(hdc, _foreground[threadid]); |
3 | 5185 SetBkMode(hdc, TRANSPARENT); |
5186 TextOut(hdc, x, y, text, strlen(text)); | |
5187 SelectObject(hdc, oldFont); | |
5188 if(mustdelete) | |
5189 DeleteObject(hFont); | |
5190 if(!pixmap) | |
5191 ReleaseDC(handle, hdc); | |
5192 } | |
5193 | |
5194 /* Call this after drawing to the screen to make sure | |
5195 * anything you have drawn is visible. | |
5196 */ | |
5197 void dw_flush(void) | |
5198 { | |
5199 } | |
5200 | |
5201 /* | |
5202 * Creates a pixmap with given parameters. | |
5203 * Parameters: | |
5204 * handle: Window handle the pixmap is associated with. | |
5205 * width: Width of the pixmap in pixels. | |
5206 * height: Height of the pixmap in pixels. | |
5207 * depth: Color depth of the pixmap. | |
5208 * Returns: | |
5209 * A handle to a pixmap or NULL on failure. | |
5210 */ | |
5211 HPIXMAP dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) | |
5212 { | |
5213 HPIXMAP pixmap; | |
5214 BITMAP bm; | |
5215 HDC hdc; | |
5216 | |
5217 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
5218 return NULL; | |
5219 | |
5220 hdc = GetDC(handle); | |
5221 | |
5222 pixmap->width = width; pixmap->height = height; | |
5223 | |
5224 pixmap->handle = handle; | |
5225 pixmap->hbm = CreateCompatibleBitmap(hdc, width, height); | |
5226 pixmap->hdc = CreateCompatibleDC(hdc); | |
5227 | |
5228 SelectObject(pixmap->hdc, pixmap->hbm); | |
5229 | |
5230 ReleaseDC(handle, hdc); | |
5231 | |
5232 return pixmap; | |
5233 } | |
5234 | |
5235 /* | |
5236 * Creates a pixmap from internal resource graphic specified by id. | |
5237 * Parameters: | |
5238 * handle: Window handle the pixmap is associated with. | |
5239 * id: Resource ID associated with requested pixmap. | |
5240 * Returns: | |
5241 * A handle to a pixmap or NULL on failure. | |
5242 */ | |
5243 HPIXMAP dw_pixmap_grab(HWND handle, ULONG id) | |
5244 { | |
5245 HPIXMAP pixmap; | |
5246 BITMAP bm; | |
5247 HDC hdc; | |
5248 | |
5249 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | |
5250 return NULL; | |
5251 | |
5252 hdc = GetDC(handle); | |
5253 | |
5254 | |
5255 pixmap->hbm = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | |
5256 pixmap->hdc = CreateCompatibleDC(hdc); | |
5257 | |
5258 GetObject(pixmap->hbm, sizeof(BITMAP), (void *)&bm); | |
5259 | |
5260 pixmap->width = bm.bmWidth; pixmap->height = bm.bmHeight; | |
5261 | |
5262 SelectObject(pixmap->hdc, pixmap->hbm); | |
5263 | |
5264 ReleaseDC(handle, hdc); | |
5265 | |
5266 return pixmap; | |
5267 } | |
5268 | |
5269 /* | |
5270 * Destroys an allocated pixmap. | |
5271 * Parameters: | |
5272 * pixmap: Handle to a pixmap returned by | |
5273 * dw_pixmap_new.. | |
5274 */ | |
5275 void dw_pixmap_destroy(HPIXMAP pixmap) | |
5276 { | |
5277 if(pixmap) | |
5278 { | |
5279 DeleteDC(pixmap->hdc); | |
5280 DeleteObject(pixmap->hbm); | |
5281 free(pixmap); | |
5282 } | |
5283 } | |
5284 | |
5285 /* | |
5286 * Copies from one item to another. | |
5287 * Parameters: | |
5288 * dest: Destination window handle. | |
5289 * destp: Destination pixmap. (choose only one). | |
5290 * xdest: X coordinate of destination. | |
5291 * ydest: Y coordinate of destination. | |
5292 * width: Width of area to copy. | |
5293 * height: Height of area to copy. | |
5294 * src: Source window handle. | |
5295 * srcp: Source pixmap. (choose only one). | |
5296 * xsrc: X coordinate of source. | |
5297 * ysrc: Y coordinate of source. | |
5298 */ | |
5299 void dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) | |
5300 { | |
5301 HDC hdcdest; | |
5302 HDC hdcsrc; | |
5303 | |
5304 if(dest) | |
5305 hdcdest = GetDC(dest); | |
5306 else if(destp) | |
5307 hdcdest = destp->hdc; | |
5308 else | |
5309 return; | |
5310 | |
5311 if(src) | |
5312 hdcsrc = GetDC(src); | |
5313 else if(srcp) | |
5314 hdcsrc = srcp->hdc; | |
5315 else | |
5316 return; | |
5317 | |
5318 BitBlt(hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY); | |
5319 | |
5320 if(!destp) | |
5321 ReleaseDC(dest, hdcdest); | |
5322 if(!srcp) | |
5323 ReleaseDC(src, hdcsrc); | |
5324 } | |
5325 | |
5326 /* | |
5327 * Emits a beep. | |
5328 * Parameters: | |
5329 * freq: Frequency. | |
5330 * dur: Duration. | |
5331 */ | |
5332 void dw_beep(int freq, int dur) | |
5333 { | |
5334 Beep(freq, dur); | |
5335 } | |
5336 | |
5337 /* | |
5338 * Returns the handle to an unnamed mutex semaphore. | |
5339 */ | |
5340 HMTX dw_mutex_new(void) | |
5341 { | |
5342 return (HMTX)CreateMutex(NULL, FALSE, NULL); | |
5343 } | |
5344 | |
5345 /* | |
5346 * Closes a semaphore created by dw_mutex_new(). | |
5347 * Parameters: | |
5348 * mutex: The handle to the mutex returned by dw_mutex_new(). | |
5349 */ | |
5350 void dw_mutex_close(HMTX mutex) | |
5351 { | |
5352 CloseHandle((HANDLE)mutex); | |
5353 } | |
5354 | |
5355 /* | |
5356 * Tries to gain access to the semaphore, if it can't it blocks. | |
5357 * Parameters: | |
5358 * mutex: The handle to the mutex returned by dw_mutex_new(). | |
5359 */ | |
5360 void dw_mutex_lock(HMTX mutex) | |
5361 { | |
5362 WaitForSingleObject((HANDLE)mutex, INFINITE); | |
5363 } | |
5364 | |
5365 /* | |
5366 * Reliquishes the access to the semaphore. | |
5367 * Parameters: | |
5368 * mutex: The handle to the mutex returned by dw_mutex_new(). | |
5369 */ | |
5370 void dw_mutex_unlock(HMTX mutex) | |
5371 { | |
5372 ReleaseMutex((HANDLE)mutex); | |
5373 } | |
5374 | |
5375 /* | |
5376 * Returns the handle to an unnamed event semaphore. | |
5377 */ | |
5378 HEV dw_event_new(void) | |
5379 { | |
5380 return CreateEvent(NULL, TRUE, FALSE, NULL); | |
5381 } | |
5382 | |
5383 /* | |
5384 * Resets a semaphore created by dw_event_new(). | |
5385 * Parameters: | |
5386 * eve: The handle to the event returned by dw_event_new(). | |
5387 */ | |
5388 int dw_event_reset(HEV eve) | |
5389 { | |
5390 return ResetEvent(eve); | |
5391 } | |
5392 | |
5393 /* | |
5394 * Posts a semaphore created by dw_event_new(). Causing all threads | |
5395 * waiting on this event in dw_event_wait to continue. | |
5396 * Parameters: | |
5397 * eve: The handle to the event returned by dw_event_new(). | |
5398 */ | |
5399 int dw_event_post(HEV eve) | |
5400 { | |
5401 return SetEvent(eve); | |
5402 } | |
5403 | |
5404 /* | |
5405 * Waits on a semaphore created by dw_event_new(), until the | |
5406 * event gets posted or until the timeout expires. | |
5407 * Parameters: | |
5408 * eve: The handle to the event returned by dw_event_new(). | |
5409 */ | |
5410 int dw_event_wait(HEV eve, unsigned long timeout) | |
5411 { | |
5412 int rc; | |
5413 | |
5414 rc = WaitForSingleObject(eve, timeout); | |
5415 if(rc == WAIT_OBJECT_0) | |
5416 return 1; | |
5417 if(rc == WAIT_ABANDONED) | |
5418 return -1; | |
5419 return 0; | |
5420 } | |
5421 | |
5422 /* | |
5423 * Closes a semaphore created by dw_event_new(). | |
5424 * Parameters: | |
5425 * eve: The handle to the event returned by dw_event_new(). | |
5426 */ | |
5427 int dw_event_close(HEV *eve) | |
5428 { | |
5429 if(eve) | |
5430 return CloseHandle(*eve); | |
5431 return FALSE; | |
5432 } | |
5433 | |
5434 /* | |
5435 * Creates a new thread with a starting point of func. | |
5436 * Parameters: | |
5437 * func: Function which will be run in the new thread. | |
5438 * data: Parameter(s) passed to the function. | |
5439 * stack: Stack size of new thread (OS/2 and Windows only). | |
5440 */ | |
5441 DWTID dw_thread_new(void *func, void *data, int stack) | |
5442 { | |
5443 #if defined(__CYGWIN__) | |
5444 return 0; | |
5445 #else | |
5446 return (DWTID)_beginthread((void(*)(void *))func, stack, data); | |
5447 #endif | |
5448 } | |
5449 | |
5450 /* | |
5451 * Ends execution of current thread immediately. | |
5452 */ | |
5453 void dw_thread_end(void) | |
5454 { | |
5455 #if !defined(__CYGWIN__) | |
5456 _endthread(); | |
5457 #endif | |
5458 } | |
5459 | |
5460 /* | |
5461 * Returns the current thread's ID. | |
5462 */ | |
5463 DWTID dw_thread_id(void) | |
5464 { | |
5465 #if defined(__CYGWIN__) | |
5466 return 0; | |
5467 #else | |
5468 return (DWTID)GetCurrentThreadId(); | |
5469 #endif | |
5470 } | |
5471 | |
5472 /* | |
5473 * Cleanly terminates a DW session, should be signal handler safe. | |
5474 * Parameters: | |
5475 * exitcode: Exit code reported to the operating system. | |
5476 */ | |
5477 void dw_exit(int exitcode) | |
5478 { | |
5479 exit(exitcode); | |
5480 } | |
5481 | |
5482 /* | |
5483 * Pack a splitbar (sizer) into the specified box from the start. | |
5484 * Parameters: | |
5485 * box: Window handle of the box to be packed into. | |
5486 */ | |
5487 void dw_box_pack_splitbar_start(HWND box) | |
5488 { | |
5489 Box *thisbox = (Box *)GetWindowLong(box, GWL_USERDATA); | |
5490 | |
5491 if(thisbox) | |
5492 { | |
5493 HWND tmp = CreateWindow(SplitbarClassName, | |
5494 "", | |
5495 WS_CHILD | WS_CLIPCHILDREN, | |
5496 0,0,2000,1000, | |
5497 DW_HWND_OBJECT, | |
5498 NULL, | |
5499 NULL, | |
5500 NULL); | |
5501 if(thisbox->type == BOXVERT) | |
5502 dw_box_pack_start(box, tmp, 1, SPLITBAR_WIDTH, TRUE, FALSE, 0); | |
5503 else | |
5504 dw_box_pack_start(box, tmp, SPLITBAR_WIDTH, 1, FALSE, TRUE, 0); | |
5505 | |
5506 } | |
5507 } | |
5508 | |
5509 /* | |
5510 * Pack a splitbar (sizer) into the specified box from the end. | |
5511 * Parameters: | |
5512 * box: Window handle of the box to be packed into. | |
5513 */ | |
5514 void dw_box_pack_splitbar_end(HWND box) | |
5515 { | |
5516 Box *thisbox = (Box *)GetWindowLong(box, GWL_USERDATA); | |
5517 | |
5518 if(thisbox) | |
5519 { | |
5520 HWND tmp = CreateWindow(SplitbarClassName, | |
5521 "", | |
5522 WS_CHILD | WS_CLIPCHILDREN, | |
5523 0,0,2000,1000, | |
5524 DW_HWND_OBJECT, | |
5525 NULL, | |
5526 NULL, | |
5527 NULL); | |
5528 if(thisbox->type == BOXVERT) | |
5529 dw_box_pack_end(box, tmp, 1, SPLITBAR_WIDTH, TRUE, FALSE, 0); | |
5530 else | |
5531 dw_box_pack_end(box, tmp, SPLITBAR_WIDTH, 1, FALSE, TRUE, 0); | |
5532 | |
5533 } | |
5534 } | |
5535 | |
5536 /* | |
5537 * Pack windows (widgets) into a box from the end (or bottom). | |
5538 * Parameters: | |
5539 * box: Window handle of the box to be packed into. | |
5540 * item: Window handle of the item to be back. | |
5541 * width: Width in pixels of the item or -1 to be self determined. | |
5542 * height: Height in pixels of the item or -1 to be self determined. | |
5543 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | |
5544 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | |
5545 * pad: Number of pixels of padding around the item. | |
5546 */ | |
5547 void dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | |
5548 { | |
5549 Box *thisbox; | |
5550 | |
5551 thisbox = (Box *)GetWindowLong(box, GWL_USERDATA); | |
5552 if(thisbox) | |
5553 { | |
5554 int z; | |
5555 Item *tmpitem, *thisitem = thisbox->items; | |
5556 char tmpbuf[100]; | |
5557 | |
5558 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | |
5559 | |
5560 for(z=0;z<thisbox->count;z++) | |
5561 { | |
5562 tmpitem[z+1] = thisitem[z]; | |
5563 } | |
5564 | |
5565 GetClassName(item, tmpbuf, 99); | |
5566 | |
5567 if(strnicmp(tmpbuf, FRAMECLASSNAME, 2)==0) | |
5568 tmpitem[0].type = TYPEBOX; | |
5569 else | |
5570 tmpitem[0].type = TYPEITEM; | |
5571 | |
5572 tmpitem[0].hwnd = item; | |
5573 tmpitem[0].origwidth = tmpitem[0].width = width; | |
5574 tmpitem[0].origheight = tmpitem[0].height = height; | |
5575 tmpitem[0].pad = pad; | |
5576 if(hsize) | |
5577 tmpitem[0].hsize = SIZEEXPAND; | |
5578 else | |
5579 tmpitem[0].hsize = SIZESTATIC; | |
5580 | |
5581 if(vsize) | |
5582 tmpitem[0].vsize = SIZEEXPAND; | |
5583 else | |
5584 tmpitem[0].vsize = SIZESTATIC; | |
5585 | |
5586 thisbox->items = tmpitem; | |
5587 | |
5588 if(thisbox->count) | |
5589 free(thisitem); | |
5590 | |
5591 thisbox->count++; | |
5592 | |
5593 SetParent(item, box); | |
5594 ShowWindow(item, SW_SHOW); | |
5595 if(strncmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS))==0) | |
5596 { | |
5597 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(item, GWL_USERDATA); | |
5598 | |
5599 if(cinfo) | |
5600 { | |
5601 SetParent(cinfo->buddy, box); | |
5602 ShowWindow(cinfo->buddy, SW_SHOW); | |
5603 SendMessage(item, UDM_SETBUDDY, (WPARAM)cinfo->buddy, 0); | |
5604 } | |
5605 } | |
5606 } | |
5607 } | |
5608 | |
5609 /* | |
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
|
5610 * 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
|
5611 * 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
|
5612 * 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
|
5613 * 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
|
5614 */ |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
5615 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
|
5616 { |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
5617 Box *thisbox = (Box *)GetWindowLong(window, GWL_USERDATA); |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
5618 |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
5619 if(thisbox) |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
5620 thisbox->defaultitem = 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
|
5621 } |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
5622 |
b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
33
diff
changeset
|
5623 /* |
3 | 5624 * Returns some information about the current operating environment. |
5625 * Parameters: | |
5626 * env: Pointer to a DWEnv struct. | |
5627 */ | |
5628 void dw_environment_query(DWEnv *env) | |
5629 { | |
5630 if(!env) | |
5631 return; | |
5632 | |
5633 /* Get the Windows version. */ | |
5634 | |
5635 env->MajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); | |
5636 env->MinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); | |
5637 | |
5638 /* Get the build number for Windows NT/Windows 2000. */ | |
5639 | |
5640 env->MinorBuild = 0; | |
5641 | |
5642 if (dwVersion < 0x80000000) | |
5643 { | |
5644 if(env->MajorVersion == 5) | |
5645 strcpy(env->osName, "Windows 2000"); | |
5646 else | |
5647 strcpy(env->osName, "Windows NT"); | |
5648 | |
5649 env->MajorBuild = (DWORD)(HIWORD(dwVersion)); | |
5650 } | |
5651 else | |
5652 { | |
5653 strcpy(env->osName, "Windows 95/98/ME"); | |
5654 env->MajorBuild = 0; | |
5655 } | |
15
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
5656 |
81833f25b1aa
Added new Dynamic Windows build information to the DWEnv struct.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
14
diff
changeset
|
5657 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
|
5658 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
|
5659 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
|
5660 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
|
5661 env->DWSubVersion = DW_SUB_VERSION; |
3 | 5662 } |
5663 | |
5664 /* | |
5665 * Opens a file dialog and queries user selection. | |
5666 * Parameters: | |
5667 * title: Title bar text for dialog. | |
5668 * defpath: The default path of the open dialog. | |
5669 * ext: Default file extention. | |
5670 * flags: DW_FILE_OPEN or DW_FILE_SAVE. | |
5671 * Returns: | |
5672 * NULL on error. A malloced buffer containing | |
5673 * the file path on success. | |
5674 * | |
5675 */ | |
5676 char *dw_file_browse(char *title, char *defpath, char *ext, int flags) | |
5677 { | |
5678 OPENFILENAME of; | |
5679 char filenamebuf[1001] = ""; | |
5680 int rc; | |
5681 | |
5682 if(ext) | |
5683 { | |
5684 strcpy(filenamebuf, "*."); | |
5685 strcat(filenamebuf, ext); | |
5686 } | |
5687 | |
5688 memset(&of, 0, sizeof(OPENFILENAME)); | |
5689 | |
5690 of.lStructSize = sizeof(OPENFILENAME); | |
5691 of.hwndOwner = HWND_DESKTOP; | |
5692 of.hInstance = DWInstance; | |
5693 of.lpstrInitialDir = defpath; | |
5694 of.lpstrTitle = title; | |
5695 of.lpstrFile = filenamebuf; | |
5696 of.nMaxFile = 1000; | |
5697 of.lpstrDefExt = ext; | |
5698 of.Flags = 0; | |
5699 | |
5700 if(flags & DW_FILE_SAVE) | |
5701 rc = GetSaveFileName(&of); | |
5702 else | |
5703 rc = GetOpenFileName(&of); | |
5704 | |
5705 if(rc) | |
5706 return strdup(of.lpstrFile); | |
5707 | |
5708 return NULL; | |
5709 } | |
5710 | |
5711 /* | |
5712 * Execute and external program in a seperate session. | |
5713 * Parameters: | |
5714 * program: Program name with optional path. | |
5715 * type: Either DW_EXEC_CON or DW_EXEC_GUI. | |
5716 * params: An array of pointers to string arguements. | |
5717 * Returns: | |
5718 * -1 on error. | |
5719 */ | |
5720 int dw_exec(char *program, int type, char **params) | |
5721 { | |
5722 char **newparams; | |
5723 int retcode, count = 0, z; | |
5724 | |
5725 while(params[count]) | |
5726 { | |
5727 count++; | |
5728 } | |
5729 | |
5730 newparams = (char **)malloc(sizeof(char *) * (count+1)); | |
5731 | |
5732 for(z=0;z<count;z++) | |
5733 { | |
5734 newparams[z] = malloc(strlen(params[z])+3); | |
5735 strcpy(newparams[z], "\""); | |
5736 strcat(newparams[z], params[z]); | |
5737 strcat(newparams[z], "\""); | |
5738 } | |
5739 newparams[count] = NULL; | |
5740 | |
5741 retcode = spawnvp(P_NOWAIT, program, newparams); | |
5742 | |
5743 for(z=0;z<count;z++) | |
5744 { | |
5745 free(newparams[z]); | |
5746 } | |
5747 free(newparams); | |
5748 | |
5749 return retcode; | |
5750 } | |
5751 | |
5752 /* | |
5753 * Loads a web browser pointed at the given URL. | |
5754 * Parameters: | |
5755 * url: Uniform resource locator. | |
5756 */ | |
5757 int dw_browse(char *url) | |
5758 { | |
5759 char *browseurl = url; | |
5760 int retcode; | |
5761 | |
5762 if(strlen(url) > 7 && strncmp(url, "file://", 7) == 0) | |
5763 { | |
5764 int len, z; | |
5765 | |
5766 browseurl = &url[7]; | |
5767 len = strlen(browseurl); | |
5768 | |
5769 for(z=0;z<len;z++) | |
5770 { | |
5771 if(browseurl[z] == '|') | |
5772 browseurl[z] = ':'; | |
5773 if(browseurl[z] == '/') | |
5774 browseurl[z] = '\\'; | |
5775 } | |
5776 } | |
5777 | |
5778 retcode = (int)ShellExecute(NULL, "open", browseurl, NULL, NULL, SW_SHOWNORMAL); | |
5779 if(retcode<33 && retcode != 2) | |
5780 return -1; | |
5781 return 1; | |
5782 } | |
5783 | |
5784 /* | |
5785 * Returns a pointer to a static buffer which containes the | |
5786 * current user directory. Or the root directory (C:\ on | |
5787 * OS/2 and Windows). | |
5788 */ | |
5789 char *dw_user_dir(void) | |
5790 { | |
5791 static char _user_dir[1024] = ""; | |
5792 | |
5793 if(!_user_dir[0]) | |
5794 { | |
5795 /* Figure out how to do this the "Windows way" */ | |
5796 char *home = getenv("HOME"); | |
5797 | |
5798 if(home) | |
5799 strcpy(_user_dir, home); | |
5800 else | |
5801 strcpy(_user_dir, "C:\\"); | |
5802 } | |
5803 return _user_dir; | |
5804 } | |
5805 | |
5806 /* | |
5807 * Call a function from the window (widget)'s context. | |
5808 * Parameters: | |
5809 * handle: Window handle of the widget. | |
5810 * function: Function pointer to be called. | |
5811 * data: Pointer to the data to be passed to the function. | |
5812 */ | |
5813 void dw_window_function(HWND handle, void *function, void *data) | |
5814 { | |
5815 SendMessage(handle, WM_USER, (WPARAM)function, (LPARAM)data); | |
5816 } | |
5817 | |
5818 #ifndef NO_SIGNALS | |
5819 /* | |
5820 * Add a callback to a window event. | |
5821 * Parameters: | |
5822 * window: Window handle of signal to be called back. | |
5823 * signame: A string pointer identifying which signal to be hooked. | |
5824 * sigfunc: The pointer to the function to be used as the callback. | |
5825 * data: User data to be passed to the handler function. | |
5826 */ | |
5827 void dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) | |
5828 { | |
5829 ULONG message = 0L; | |
5830 | |
5831 if(window && signame && sigfunc) | |
5832 { | |
5833 if((message = _findsigmessage(signame)) != 0) | |
5834 _new_signal(message, window, sigfunc, data); | |
5835 } | |
5836 } | |
5837 | |
5838 /* | |
5839 * Removes callbacks for a given window with given name. | |
5840 * Parameters: | |
5841 * window: Window handle of callback to be removed. | |
5842 */ | |
5843 void dw_signal_disconnect_by_name(HWND window, char *signame) | |
5844 { | |
5845 SignalHandler *prev = NULL, *tmp = Root; | |
5846 ULONG message; | |
5847 | |
5848 if(!window || !signame || (message = _findsigmessage(signame)) == 0) | |
5849 return; | |
5850 | |
5851 while(tmp) | |
5852 { | |
5853 if(tmp->window == window && tmp->message == message) | |
5854 { | |
5855 if(prev) | |
5856 { | |
5857 prev->next = tmp->next; | |
5858 free(tmp); | |
5859 tmp = prev->next; | |
5860 } | |
5861 else | |
5862 { | |
5863 Root = tmp->next; | |
5864 free(tmp); | |
5865 tmp = Root; | |
5866 } | |
5867 } | |
5868 else | |
5869 { | |
5870 prev = tmp; | |
5871 tmp = tmp->next; | |
5872 } | |
5873 } | |
5874 } | |
5875 | |
5876 /* | |
5877 * Removes all callbacks for a given window. | |
5878 * Parameters: | |
5879 * window: Window handle of callback to be removed. | |
5880 */ | |
5881 void dw_signal_disconnect_by_window(HWND window) | |
5882 { | |
5883 SignalHandler *prev = NULL, *tmp = Root; | |
5884 | |
5885 while(tmp) | |
5886 { | |
5887 if(tmp->window == window) | |
5888 { | |
5889 if(prev) | |
5890 { | |
5891 prev->next = tmp->next; | |
5892 free(tmp); | |
5893 tmp = prev->next; | |
5894 } | |
5895 else | |
5896 { | |
5897 Root = tmp->next; | |
5898 free(tmp); | |
5899 tmp = Root; | |
5900 } | |
5901 } | |
5902 else | |
5903 { | |
5904 prev = tmp; | |
5905 tmp = tmp->next; | |
5906 } | |
5907 } | |
5908 } | |
5909 | |
5910 /* | |
5911 * Removes all callbacks for a given window with specified data. | |
5912 * Parameters: | |
5913 * window: Window handle of callback to be removed. | |
5914 * data: Pointer to the data to be compared against. | |
5915 */ | |
5916 void dw_signal_disconnect_by_data(HWND window, void *data) | |
5917 { | |
5918 SignalHandler *prev = NULL, *tmp = Root; | |
5919 | |
5920 while(tmp) | |
5921 { | |
5922 if(tmp->window == window && tmp->data == data) | |
5923 { | |
5924 if(prev) | |
5925 { | |
5926 prev->next = tmp->next; | |
5927 free(tmp); | |
5928 tmp = prev->next; | |
5929 } | |
5930 else | |
5931 { | |
5932 Root = tmp->next; | |
5933 free(tmp); | |
5934 tmp = Root; | |
5935 } | |
5936 } | |
5937 else | |
5938 { | |
5939 prev = tmp; | |
5940 tmp = tmp->next; | |
5941 } | |
5942 } | |
5943 } | |
5944 #endif | |
5945 | |
5946 #ifdef TEST | |
5947 HWND mainwindow, | |
5948 listbox, | |
5949 okbutton, | |
5950 cancelbutton, | |
5951 lbbox, | |
5952 stext, | |
5953 buttonbox, | |
5954 testwindow, | |
5955 testbox, | |
5956 testok, | |
5957 testcancel, | |
5958 testbox2, | |
5959 testok2, | |
5960 testcancel2, | |
5961 notebook; | |
5962 int count = 2; | |
5963 | |
5964 #ifdef USE_FILTER | |
5965 /* Do any handling you need in the filter function */ | |
5966 LONG testfilter(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | |
5967 { | |
5968 switch(msg) | |
5969 { | |
5970 case WM_COMMAND: | |
5971 switch (COMMANDMSG(&msg)->cmd) | |
5972 { | |
5973 case 1001L: | |
5974 case 1002L: | |
5975 dw_window_destroy(mainwindow);; | |
5976 count--; | |
5977 break; | |
5978 case 1003L: | |
5979 case 1004L: | |
5980 dw_window_destroy(testwindow);; | |
5981 count--; | |
5982 break; | |
5983 } | |
5984 if(!count) | |
5985 exit(0); | |
5986 break; | |
5987 } | |
5988 /* Return -1 to allow the default handlers to return. */ | |
5989 return TRUE; | |
5990 } | |
5991 #else | |
5992 int test_callback(HWND window, void *data) | |
5993 { | |
5994 dw_window_destroy((HWND)data); | |
5995 /* Return -1 to allow the default handlers to return. */ | |
5996 count--; | |
5997 if(!count) | |
5998 exit(0); | |
5999 return -1; | |
6000 } | |
6001 #endif | |
6002 | |
6003 /* | |
6004 * Let's demonstrate the functionality of this library. :) | |
6005 */ | |
6006 int WINAPI WinMain( | |
6007 HINSTANCE hInstance, | |
6008 HINSTANCE hPrevInstance, | |
6009 LPSTR lpCmdLine, | |
6010 int nCmdShow | |
6011 ) | |
6012 { | |
6013 ULONG flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR | | |
6014 DW_FCF_SHELLPOSITION | DW_FCF_TASKLIST | DW_FCF_DLGBORDER; | |
6015 int pageid; | |
6016 | |
6017 dw_init(TRUE); | |
6018 | |
6019 /* Try a little server dialog. :) */ | |
6020 mainwindow = dw_window_new(HWND_DESKTOP, "Server", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX); | |
6021 | |
6022 lbbox = dw_box_new(BOXVERT, 10); | |
6023 | |
6024 dw_box_pack_start(mainwindow, lbbox, 0, 0, TRUE, TRUE, 0); | |
6025 | |
6026 stext = dw_text_new("Choose a server:", 0); | |
6027 | |
6028 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); | |
6029 | |
6030 dw_box_pack_start(lbbox, stext, 130, 15, FALSE, FALSE, 10); | |
6031 | |
6032 listbox = dw_listbox_new(100L, FALSE); | |
6033 | |
6034 dw_box_pack_start(lbbox, listbox, 130, 200, TRUE, TRUE, 10); | |
6035 | |
6036 buttonbox = dw_box_new(BOXHORZ, 0); | |
6037 | |
6038 dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0); | |
6039 | |
6040 okbutton = dw_button_new("Ok", 1001L); | |
6041 | |
6042 dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, TRUE, 5); | |
6043 | |
6044 cancelbutton = dw_button_new("Cancel", 1002L); | |
6045 | |
6046 dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, TRUE, 5); | |
6047 | |
6048 /* Set some nice fonts and colors */ | |
6049 dw_window_set_color(lbbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
6050 dw_window_set_color(buttonbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
6051 dw_window_set_font(stext, "9.WarpSans"); | |
6052 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); | |
6053 dw_window_set_font(listbox, "9.WarpSans"); | |
6054 dw_window_set_font(okbutton, "9.WarpSans"); | |
6055 dw_window_set_font(cancelbutton, "9.WarpSans"); | |
6056 | |
6057 dw_window_show(mainwindow); | |
6058 | |
6059 dw_window_set_usize(mainwindow, 170, 340); | |
6060 | |
6061 /* Another small example */ | |
6062 flStyle |= DW_FCF_MINMAX | DW_FCF_SIZEBORDER; | |
6063 | |
6064 testwindow = dw_window_new(HWND_DESKTOP, "Wow a test dialog! :) yay!", flStyle); | |
6065 | |
6066 testbox = dw_box_new(BOXVERT, 0); | |
6067 | |
6068 dw_box_pack_start(testwindow, testbox, 0, 0, TRUE, TRUE, 0); | |
6069 | |
6070 notebook = dw_notebook_new(1010L, TRUE); | |
6071 | |
6072 dw_box_pack_start(testbox, notebook, 100, 100, TRUE, TRUE, 0); | |
6073 | |
6074 testbox = dw_box_new(BOXVERT, 10); | |
6075 | |
6076 pageid = dw_notebook_page_new(notebook, 0L, FALSE); | |
6077 | |
6078 dw_notebook_page_set_text(notebook, pageid, "Test page"); | |
6079 dw_notebook_page_set_status_text(notebook, pageid, "Test page"); | |
6080 | |
6081 dw_notebook_pack(notebook, pageid, testbox); | |
6082 | |
6083 testok = dw_button_new("Ok", 1003L); | |
6084 | |
6085 dw_box_pack_start(testbox, testok, 60, 40, TRUE, TRUE, 10); | |
6086 | |
6087 testcancel = dw_button_new("Cancel", 1004L); | |
6088 | |
6089 dw_box_pack_start(testbox, testcancel, 60, 40, TRUE, TRUE, 10); | |
6090 | |
6091 testbox2 = dw_box_new(BOXHORZ, 0); | |
6092 | |
6093 dw_box_pack_start(testbox, testbox2, 0, 0, TRUE, TRUE, 0); | |
6094 | |
6095 testok2 = dw_button_new("Ok", 1003L); | |
6096 | |
6097 dw_box_pack_start(testbox2, testok2, 60, 40, TRUE, TRUE, 10); | |
6098 | |
6099 dw_box_pack_splitbar_start(testbox2); | |
6100 | |
6101 testcancel2 = dw_button_new("Cancel", 1004L); | |
6102 | |
6103 dw_box_pack_start(testbox2, testcancel2, 60, 40, TRUE, TRUE, 10); | |
6104 | |
6105 /* Set some nice fonts and colors */ | |
6106 dw_window_set_color(testbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
6107 dw_window_set_color(testbox2, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
6108 dw_window_set_font(testok, "9.WarpSans"); | |
6109 dw_window_set_font(testcancel, "9.WarpSans"); | |
6110 dw_window_set_font(testok2, "9.WarpSans"); | |
6111 dw_window_set_font(testcancel2, "9.WarpSans"); | |
6112 | |
6113 dw_window_show(testwindow); | |
6114 | |
6115 #ifdef USE_FILTER | |
6116 | |
6117 dw_main(0L, (void *)testfilter); | |
6118 #else | |
6119 /* Setup the function callbacks */ | |
6120 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
6121 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
6122 dw_signal_connect(testok, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
6123 dw_signal_connect(testcancel, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
6124 dw_signal_connect(testok2, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
6125 dw_signal_connect(testcancel2, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
6126 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
6127 dw_signal_connect(testwindow, "delete_event", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
6128 | |
6129 dw_main(0L, NULL); | |
6130 #endif | |
6131 | |
6132 return 0; | |
6133 } | |
6134 #endif |