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