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