No need to define __USE_W32API
[reactos.git] / rosapps / dflat32 / dialbox.c
1 /* ----------------- dialbox.c -------------- */
2
3 #include "dflat.h"
4
5 static int inFocusCommand(DF_DBOX *);
6 static void dbShortcutKeys(DF_DBOX *, int);
7 static int ControlProc(DFWINDOW, DFMESSAGE, DF_PARAM, DF_PARAM);
8 static void FirstFocus(DF_DBOX *db);
9 static void NextFocus(DF_DBOX *db);
10 static void PrevFocus(DF_DBOX *db);
11 static DF_CTLWINDOW *AssociatedControl(DF_DBOX *, enum DfCommands);
12
13 static BOOL SysMenuOpen;
14
15 static DF_DBOX **dbs = NULL;
16 static int dbct = 0;
17
18 /* --- clear all heap allocations to control text fields --- */
19 void DfClearDialogBoxes(void)
20 {
21 int i;
22
23 for (i = 0; i < dbct; i++)
24 {
25 DF_CTLWINDOW *ct = (*(dbs+i))->ctl;
26
27 while (ct->class)
28 {
29 if ((ct->class == DF_EDITBOX ||
30 ct->class == DF_COMBOBOX) &&
31 ct->itext != NULL)
32 {
33 free(ct->itext);
34 }
35 ct++;
36 }
37 }
38
39 if (dbs != NULL)
40 {
41 free(dbs);
42 dbs = NULL;
43 }
44 dbct = 0;
45 }
46
47
48 /* -------- DFM_CREATE_WINDOW Message --------- */
49 static int CreateWindowMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
50 {
51 DF_DBOX *db = wnd->extension;
52 DF_CTLWINDOW *ct = db->ctl;
53 DFWINDOW cwnd;
54 int rtn, i;
55 /* ---- build a table of processed dialog boxes ---- */
56 for (i = 0; i < dbct; i++)
57 if (db == dbs[i])
58 break;
59 if (i == dbct) {
60 dbs = DfRealloc(dbs, sizeof(DF_DBOX *) * (dbct+1));
61 *(dbs + dbct++) = db;
62 }
63 rtn = DfBaseWndProc(DF_DIALOG, wnd, DFM_CREATE_WINDOW, p1, p2);
64 ct = db->ctl;
65 while (ct->class) {
66 int attrib = 0;
67 if (DfTestAttribute(wnd, DF_NOCLIP))
68 attrib |= DF_NOCLIP;
69 if (wnd->Modal)
70 attrib |= DF_SAVESELF;
71 ct->setting = ct->isetting;
72 if (ct->class == DF_EDITBOX && ct->dwnd.h > 1)
73 attrib |= (DF_MULTILINE | DF_HASBORDER);
74 else if ((ct->class == DF_LISTBOX || ct->class == DF_TEXTBOX) &&
75 ct->dwnd.h > 2)
76 attrib |= DF_HASBORDER;
77 cwnd = DfDfCreateWindow(ct->class,
78 ct->dwnd.title,
79 ct->dwnd.x+DfGetClientLeft(wnd),
80 ct->dwnd.y+DfGetClientTop(wnd),
81 ct->dwnd.h,
82 ct->dwnd.w,
83 ct,
84 wnd,
85 ControlProc,
86 attrib);
87 if ((ct->class == DF_EDITBOX ||
88 ct->class == DF_COMBOBOX) &&
89 ct->itext != NULL)
90 DfSendMessage(cwnd, DFM_SETTEXT, (DF_PARAM) ct->itext, 0);
91 ct++;
92 }
93 return rtn;
94 }
95
96 /* -------- DFM_LEFT_BUTTON Message --------- */
97 static BOOL LeftButtonMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
98 {
99 DF_DBOX *db = wnd->extension;
100 DF_CTLWINDOW *ct = db->ctl;
101 if (DfWindowSizing || DfWindowMoving)
102 return TRUE;
103 if (DfHitControlBox(wnd, p1-DfGetLeft(wnd), p2-DfGetTop(wnd))) {
104 DfPostMessage(wnd, DFM_KEYBOARD, ' ', DF_ALTKEY);
105 return TRUE;
106 }
107 while (ct->class) {
108 DFWINDOW cwnd = ct->wnd;
109 if (ct->class == DF_COMBOBOX) {
110 if (p2 == DfGetTop(cwnd)) {
111 if (p1 == DfGetRight(cwnd)+1) {
112 DfSendMessage(cwnd, DFM_LEFT_BUTTON, p1, p2);
113 return TRUE;
114 }
115 }
116 if (DfGetClass(DfInFocus) == DF_LISTBOX)
117 DfSendMessage(wnd, DFM_SETFOCUS, TRUE, 0);
118 }
119 else if (ct->class == DF_SPINBUTTON) {
120 if (p2 == DfGetTop(cwnd)) {
121 if (p1 == DfGetRight(cwnd)+1 ||
122 p1 == DfGetRight(cwnd)+2) {
123 DfSendMessage(cwnd, DFM_LEFT_BUTTON, p1, p2);
124 return TRUE;
125 }
126 }
127 }
128 ct++;
129 }
130 return FALSE;
131 }
132
133 /* -------- DFM_KEYBOARD Message --------- */
134 static BOOL KeyboardMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
135 {
136 DF_DBOX *db = wnd->extension;
137 DF_CTLWINDOW *ct;
138
139 if (DfWindowMoving || DfWindowSizing)
140 return FALSE;
141 switch ((int)p1) {
142 case DF_F1:
143 ct = DfGetControl(DfInFocus);
144 if (ct != NULL)
145 if (DfDisplayHelp(wnd, ct->help))
146 return TRUE;
147 break;
148 case DF_SHIFT_HT:
149 case DF_BS:
150 case DF_UP:
151 PrevFocus(db);
152 break;
153 case DF_ALT_F6:
154 case '\t':
155 case DF_FWD:
156 case DF_DN:
157 NextFocus(db);
158 break;
159 case ' ':
160 if (((int)p2 & DF_ALTKEY) &&
161 DfTestAttribute(wnd, DF_CONTROLBOX)) {
162 SysMenuOpen = TRUE;
163 DfBuildSystemMenu(wnd);
164 }
165 break;
166 case DF_CTRL_F4:
167 case DF_ESC:
168 DfSendMessage(wnd, DFM_COMMAND, DF_ID_CANCEL, 0);
169 break;
170 default:
171 /* ------ search all the shortcut keys ----- */
172 dbShortcutKeys(db, (int) p1);
173 break;
174 }
175 return wnd->Modal;
176 }
177
178 /* -------- COMMAND Message --------- */
179 static BOOL CommandMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
180 {
181 DF_DBOX *db = wnd->extension;
182 switch ((int) p1) {
183 case DF_ID_OK:
184 case DF_ID_CANCEL:
185 if ((int)p2 != 0)
186 return TRUE;
187 wnd->ReturnCode = (int) p1;
188 if (wnd->Modal)
189 DfPostMessage(wnd, DFM_ENDDIALOG, 0, 0);
190 else
191 DfSendMessage(wnd, DFM_CLOSE_WINDOW, TRUE, 0);
192 return TRUE;
193 case DF_ID_HELP:
194 if ((int)p2 != 0)
195 return TRUE;
196 return DfDisplayHelp(wnd, db->HelpName);
197 default:
198 break;
199 }
200 return FALSE;
201 }
202
203 /* ----- window-processing module, DF_DIALOG window class ----- */
204 int DfDialogProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
205 {
206 int rtn;
207 DF_DBOX *db = wnd->extension;
208
209 switch (msg) {
210 case DFM_CREATE_WINDOW:
211 return CreateWindowMsg(wnd, p1, p2);
212 case DFM_SHIFT_CHANGED:
213 if (wnd->Modal)
214 return TRUE;
215 break;
216 case DFM_LEFT_BUTTON:
217 if (LeftButtonMsg(wnd, p1, p2))
218 return TRUE;
219 break;
220 case DFM_KEYBOARD:
221 if (KeyboardMsg(wnd, p1, p2))
222 return TRUE;
223 break;
224 case DFM_CLOSE_POPDOWN:
225 SysMenuOpen = FALSE;
226 break;
227 case DFM_LB_SELECTION:
228 case DFM_LB_CHOOSE:
229 if (SysMenuOpen)
230 return TRUE;
231 DfSendMessage(wnd, DFM_COMMAND, inFocusCommand(db), msg);
232 break;
233 case DFM_COMMAND:
234 if (CommandMsg(wnd, p1, p2))
235 return TRUE;
236 break;
237 case DFM_PAINT:
238 p2 = TRUE;
239 break;
240 case DFM_MOVE:
241 case DFM_DFM_SIZE:
242 rtn = DfBaseWndProc(DF_DIALOG, wnd, msg, p1, p2);
243 if (wnd->dfocus != NULL)
244 DfSendMessage(wnd->dfocus, DFM_SETFOCUS, TRUE, 0);
245 return rtn;
246
247 case DFM_CLOSE_WINDOW:
248 if (!p1)
249 {
250 DfSendMessage(wnd, DFM_COMMAND, DF_ID_CANCEL, 0);
251 return TRUE;
252 }
253 break;
254
255 default:
256 break;
257 }
258 return DfBaseWndProc(DF_DIALOG, wnd, msg, p1, p2);
259 }
260
261 /* ------- create and execute a dialog box ---------- */
262 BOOL DfDialogBox(DFWINDOW wnd, DF_DBOX *db, BOOL Modal,
263 int (*wndproc)(struct DfWindow *, enum DfMessages, DF_PARAM, DF_PARAM))
264 {
265 BOOL rtn;
266 int x = db->dwnd.x, y = db->dwnd.y;
267 DFWINDOW DialogWnd;
268
269 if (!Modal && wnd != NULL)
270 {
271 x += DfGetLeft(wnd);
272 y += DfGetTop(wnd);
273 }
274 DialogWnd = DfDfCreateWindow(DF_DIALOG,
275 db->dwnd.title,
276 x, y,
277 db->dwnd.h,
278 db->dwnd.w,
279 db,
280 wnd,
281 wndproc,
282 Modal ? DF_SAVESELF : 0);
283 DialogWnd->Modal = Modal;
284 FirstFocus(db);
285 DfPostMessage(DialogWnd, DFM_INITIATE_DIALOG, 0, 0);
286 if (Modal)
287 {
288 DfSendMessage(DialogWnd, DFM_CAPTURE_MOUSE, 0, 0);
289 DfSendMessage(DialogWnd, DFM_CAPTURE_KEYBOARD, 0, 0);
290 while (DfDispatchMessage ())
291 ;
292 rtn = DialogWnd->ReturnCode == DF_ID_OK;
293 DfSendMessage(DialogWnd, DFM_RELEASE_MOUSE, 0, 0);
294 DfSendMessage(DialogWnd, DFM_RELEASE_KEYBOARD, 0, 0);
295 DfSendMessage(DialogWnd, DFM_CLOSE_WINDOW, TRUE, 0);
296 return rtn;
297 }
298 return FALSE;
299 }
300
301 /* ----- return command code of in-focus control window ---- */
302 static int inFocusCommand(DF_DBOX *db)
303 {
304 DF_CTLWINDOW *ct = db->ctl;
305 while (ct->class) {
306 if (ct->wnd == DfInFocus)
307 return ct->command;
308 ct++;
309 }
310 return -1;
311 }
312
313 /* -------- find a specified control structure ------- */
314 DF_CTLWINDOW *DfFindCommand(DF_DBOX *db, enum DfCommands cmd, int class)
315 {
316 DF_CTLWINDOW *ct = db->ctl;
317 while (ct->class)
318 {
319 if (ct->class == class)
320 if (cmd == ct->command)
321 return ct;
322 ct++;
323 }
324 return NULL;
325 }
326
327 /* ---- return the window handle of a specified command ---- */
328 DFWINDOW DfControlWindow(DF_DBOX *db, enum DfCommands cmd)
329 {
330 DF_CTLWINDOW *ct = db->ctl;
331 while (ct->class)
332 {
333 if (ct->class != DF_TEXT && cmd == ct->command)
334 return ct->wnd;
335 ct++;
336 }
337 return NULL;
338 }
339
340 /* --- return a pointer to the control structure that matches a window --- */
341 DF_CTLWINDOW *WindowControl(DF_DBOX *db, DFWINDOW wnd)
342 {
343 DF_CTLWINDOW *ct = db->ctl;
344 while (ct->class)
345 {
346 if (ct->wnd == wnd)
347 return ct;
348 ct++;
349 }
350 return NULL;
351 }
352
353 /* ---- set a control DF_ON or DF_OFF ----- */
354 void DfControlSetting(DF_DBOX *db, enum DfCommands cmd,
355 int class, int setting)
356 {
357 DF_CTLWINDOW *ct = DfFindCommand(db, cmd, class);
358 if (ct != NULL) {
359 ct->isetting = setting;
360 if (ct->wnd != NULL)
361 ct->setting = setting;
362 }
363 }
364
365 /* ---- return pointer to the text of a control window ---- */
366 char *DfGetDlgTextString(DF_DBOX *db,enum DfCommands cmd,DFCLASS class)
367 {
368 DF_CTLWINDOW *ct = DfFindCommand(db, cmd, class);
369 if (ct != NULL)
370 return ct->itext;
371 else
372 return NULL;
373 }
374
375 /* ------- set the text of a control specification ------ */
376 void DfSetDlgTextString(DF_DBOX *db, enum DfCommands cmd,
377 char *text, DFCLASS class)
378 {
379 DF_CTLWINDOW *ct = DfFindCommand(db, cmd, class);
380 if (ct != NULL) {
381 ct->itext = DfRealloc(ct->itext, strlen(text)+1);
382 strcpy(ct->itext, text);
383 }
384 }
385
386 /* ------- set the text of a control window ------ */
387 void DfPutItemText(DFWINDOW wnd, enum DfCommands cmd, char *text)
388 {
389 DF_CTLWINDOW *ct = DfFindCommand(wnd->extension, cmd, DF_EDITBOX);
390
391 if (ct == NULL)
392 ct = DfFindCommand(wnd->extension, cmd, DF_TEXTBOX);
393 if (ct == NULL)
394 ct = DfFindCommand(wnd->extension, cmd, DF_COMBOBOX);
395 if (ct == NULL)
396 ct = DfFindCommand(wnd->extension, cmd, DF_LISTBOX);
397 if (ct == NULL)
398 ct = DfFindCommand(wnd->extension, cmd, DF_SPINBUTTON);
399 if (ct == NULL)
400 ct = DfFindCommand(wnd->extension, cmd, DF_TEXT);
401 if (ct != NULL) {
402 DFWINDOW cwnd = (DFWINDOW) (ct->wnd);
403 switch (ct->class) {
404 case DF_COMBOBOX:
405 case DF_EDITBOX:
406 DfSendMessage(cwnd, DFM_CLEARTEXT, 0, 0);
407 DfSendMessage(cwnd, DFM_ADDTEXT, (DF_PARAM) text, 0);
408 if (!DfIsMultiLine(cwnd))
409 DfSendMessage(cwnd, DFM_PAINT, 0, 0);
410 break;
411 case DF_LISTBOX:
412 case DF_TEXTBOX:
413 case DF_SPINBUTTON:
414 DfSendMessage(cwnd, DFM_ADDTEXT, (DF_PARAM) text, 0);
415 break;
416 case DF_TEXT: {
417 DfSendMessage(cwnd, DFM_CLEARTEXT, 0, 0);
418 DfSendMessage(cwnd, DFM_ADDTEXT, (DF_PARAM) text, 0);
419 DfSendMessage(cwnd, DFM_PAINT, 0, 0);
420 break;
421 }
422 default:
423 break;
424 }
425 }
426 }
427
428 /* ------- get the text of a control window ------ */
429 void DfGetItemText(DFWINDOW wnd, enum DfCommands cmd,
430 char *text, int len)
431 {
432 DF_CTLWINDOW *ct = DfFindCommand(wnd->extension, cmd, DF_EDITBOX);
433 char *cp;
434
435 if (ct == NULL)
436 ct = DfFindCommand(wnd->extension, cmd, DF_COMBOBOX);
437 if (ct == NULL)
438 ct = DfFindCommand(wnd->extension, cmd, DF_TEXTBOX);
439 if (ct == NULL)
440 ct = DfFindCommand(wnd->extension, cmd, DF_TEXT);
441 if (ct != NULL) {
442 DFWINDOW cwnd = (DFWINDOW) (ct->wnd);
443 if (cwnd != NULL) {
444 switch (ct->class) {
445 case DF_TEXT:
446 if (DfGetText(cwnd) != NULL) {
447 cp = strchr(DfGetText(cwnd), '\n');
448 if (cp != NULL)
449 len = (int) (cp - DfGetText(cwnd));
450 strncpy(text, DfGetText(cwnd), len);
451 *(text+len) = '\0';
452 }
453 break;
454 case DF_TEXTBOX:
455 if (DfGetText(cwnd) != NULL)
456 strncpy(text, DfGetText(cwnd), len);
457 break;
458 case DF_COMBOBOX:
459 case DF_EDITBOX:
460 DfSendMessage(cwnd,DFM_GETTEXT,(DF_PARAM)text,len);
461 break;
462 default:
463 break;
464 }
465 }
466 }
467 }
468
469 /* ------- set the text of a listbox control window ------ */
470 void DfGetDlgListText(DFWINDOW wnd, char *text, enum DfCommands cmd)
471 {
472 DF_CTLWINDOW *ct = DfFindCommand(wnd->extension, cmd, DF_LISTBOX);
473 int sel = DfSendMessage(ct->wnd, DFM_LB_CURRENTSELECTION, 0, 0);
474 DfSendMessage(ct->wnd, DFM_LB_GETTEXT, (DF_PARAM) text, sel);
475 }
476
477 /* -- find control structure associated with text control -- */
478 static DF_CTLWINDOW *AssociatedControl(DF_DBOX *db,enum DfCommands Tcmd)
479 {
480 DF_CTLWINDOW *ct = db->ctl;
481 while (ct->class) {
482 if (ct->class != DF_TEXT)
483 if (ct->command == Tcmd)
484 break;
485 ct++;
486 }
487 return ct;
488 }
489
490 /* --- process dialog box shortcut keys --- */
491 static void dbShortcutKeys(DF_DBOX *db, int ky)
492 {
493 DF_CTLWINDOW *ct;
494 int ch = DfAltConvert(ky);
495
496 if (ch != 0) {
497 ct = db->ctl;
498 while (ct->class) {
499 char *cp = ct->itext;
500 while (cp && *cp) {
501 if (*cp == DF_SHORTCUTCHAR &&
502 tolower(*(cp+1)) == ch) {
503 if (ct->class == DF_TEXT)
504 ct = AssociatedControl(db, ct->command);
505 if (ct->class == DF_RADIOBUTTON)
506 DfSetRadioButton(db, ct);
507 else if (ct->class == DF_CHECKBOX) {
508 ct->setting ^= DF_ON;
509 DfSendMessage(ct->wnd, DFM_PAINT, 0, 0);
510 }
511 else if (ct->class) {
512 DfSendMessage(ct->wnd, DFM_SETFOCUS, TRUE, 0);
513 if (ct->class == DF_BUTTON)
514 DfSendMessage(ct->wnd,DFM_KEYBOARD,'\r',0);
515 }
516 return;
517 }
518 cp++;
519 }
520 ct++;
521 }
522 }
523 }
524
525 /* --- dynamically add or remove scroll bars
526 from a control window ---- */
527 void DfSetScrollBars(DFWINDOW wnd)
528 {
529 int oldattr = DfGetAttribute(wnd);
530 if (wnd->wlines > DfClientHeight(wnd))
531 DfAddAttribute(wnd, DF_VSCROLLBAR);
532 else
533 DfClearAttribute(wnd, DF_VSCROLLBAR);
534 if (wnd->textwidth > DfClientWidth(wnd))
535 DfAddAttribute(wnd, DF_HSCROLLBAR);
536 else
537 DfClearAttribute(wnd, DF_HSCROLLBAR);
538 if (DfGetAttribute(wnd) != oldattr)
539 DfSendMessage(wnd, DFM_BORDER, 0, 0);
540 }
541
542 /* ------- DFM_CREATE_WINDOW Message (Control) ----- */
543 static void CtlCreateWindowMsg(DFWINDOW wnd)
544 {
545 DF_CTLWINDOW *ct;
546 ct = wnd->ct = wnd->extension;
547 wnd->extension = NULL;
548 if (ct != NULL)
549 ct->wnd = wnd;
550 }
551
552 /* ------- DFM_KEYBOARD Message (Control) ----- */
553 static BOOL CtlKeyboardMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
554 {
555 DF_CTLWINDOW *ct = DfGetControl(wnd);
556 switch ((int) p1) {
557 case DF_F1:
558 if (DfWindowMoving || DfWindowSizing)
559 break;
560 if (!DfDisplayHelp(wnd, ct->help))
561 DfSendMessage(DfGetParent(wnd),DFM_COMMAND,DF_ID_HELP,0);
562 return TRUE;
563 case ' ':
564 if (!((int)p2 & DF_ALTKEY))
565 break;
566 case DF_ALT_F6:
567 case DF_CTRL_F4:
568 case DF_ALT_F4:
569 DfPostMessage(DfGetParent(wnd), DFM_KEYBOARD, p1, p2);
570 return TRUE;
571 default:
572 break;
573 }
574 if (DfGetClass(wnd) == DF_EDITBOX)
575 if (DfIsMultiLine(wnd))
576 return FALSE;
577 switch ((int) p1) {
578 case DF_UP:
579 if (!DfIsDerivedFrom(wnd, DF_LISTBOX)) {
580 p1 = DF_CTRL_FIVE;
581 p2 = DF_LEFTSHIFT;
582 }
583 break;
584 case DF_BS:
585 if (!DfIsDerivedFrom(wnd, DF_EDITBOX)) {
586 p1 = DF_CTRL_FIVE;
587 p2 = DF_LEFTSHIFT;
588 }
589 break;
590 case DF_DN:
591 if (!DfIsDerivedFrom(wnd, DF_LISTBOX) &&
592 !DfIsDerivedFrom(wnd, DF_COMBOBOX))
593 p1 = '\t';
594 break;
595 case DF_FWD:
596 if (!DfIsDerivedFrom(wnd, DF_EDITBOX))
597 p1 = '\t';
598 break;
599 case '\r':
600 if (DfIsDerivedFrom(wnd, DF_EDITBOX))
601 if (DfIsMultiLine(wnd))
602 break;
603 if (DfIsDerivedFrom(wnd, DF_BUTTON))
604 break;
605 DfSendMessage(DfGetParent(wnd), DFM_COMMAND, DF_ID_OK, 0);
606 return TRUE;
607 default:
608 break;
609 }
610 return FALSE;
611 }
612
613 /* ------- DFM_CLOSE_WINDOW Message (Control) ----- */
614 static void CtlCloseWindowMsg(DFWINDOW wnd)
615 {
616 DF_CTLWINDOW *ct = DfGetControl(wnd);
617 if (ct != NULL) {
618 ct->wnd = NULL;
619 if (DfGetParent(wnd)->ReturnCode == DF_ID_OK) {
620 if (ct->class == DF_EDITBOX || ct->class == DF_COMBOBOX) {
621 if (wnd->TextChanged) {
622 ct->itext=DfRealloc(ct->itext,strlen(wnd->text)+1);
623 strcpy(ct->itext, wnd->text);
624 if (!DfIsMultiLine(wnd)) {
625 char *cp = ct->itext+strlen(ct->itext)-1;
626 if (*cp == '\n')
627 *cp = '\0';
628 }
629 }
630 }
631 else if (ct->class == DF_RADIOBUTTON || ct->class == DF_CHECKBOX)
632 ct->isetting = ct->setting;
633 }
634 }
635 }
636
637
638 static void FixColors(DFWINDOW wnd)
639 {
640 DF_CTLWINDOW *ct = wnd->ct;
641
642 if (ct->class != DF_BUTTON)
643 {
644 if (ct->class != DF_SPINBUTTON && ct->class != DF_COMBOBOX)
645 {
646 wnd->WindowColors[DF_FRAME_COLOR][DF_FG] =
647 DfGetParent(wnd)->WindowColors[DF_FRAME_COLOR][DF_FG];
648 wnd->WindowColors[DF_FRAME_COLOR][DF_BG] =
649 DfGetParent(wnd)->WindowColors[DF_FRAME_COLOR][DF_BG];
650 if (ct->class != DF_EDITBOX && ct->class != DF_LISTBOX)
651 {
652 wnd->WindowColors[DF_STD_COLOR][DF_FG] =
653 DfGetParent(wnd)->WindowColors[DF_STD_COLOR][DF_FG];
654 wnd->WindowColors[DF_STD_COLOR][DF_BG] =
655 DfGetParent(wnd)->WindowColors[DF_STD_COLOR][DF_BG];
656 }
657 }
658 }
659 }
660
661
662 /* -- generic window processor used by dialog box controls -- */
663 static int ControlProc(DFWINDOW wnd,DFMESSAGE msg,DF_PARAM p1,DF_PARAM p2)
664 {
665 DF_DBOX *db;
666
667 if (wnd == NULL)
668 return FALSE;
669 db = DfGetParent(wnd) ? DfGetParent(wnd)->extension : NULL;
670
671 switch (msg) {
672 case DFM_CREATE_WINDOW:
673 CtlCreateWindowMsg(wnd);
674 break;
675 case DFM_KEYBOARD:
676 if (CtlKeyboardMsg(wnd, p1, p2))
677 return TRUE;
678 break;
679 case DFM_PAINT:
680 FixColors(wnd);
681 if (DfGetClass(wnd) == DF_EDITBOX ||
682 DfGetClass(wnd) == DF_LISTBOX ||
683 DfGetClass(wnd) == DF_TEXTBOX)
684 DfSetScrollBars(wnd);
685 break;
686 case DFM_BORDER:
687 FixColors(wnd);
688 if (DfGetClass(wnd) == DF_EDITBOX) {
689 DFWINDOW oldFocus = DfInFocus;
690 DfInFocus = NULL;
691 DfDefaultWndProc(wnd, msg, p1, p2);
692 DfInFocus = oldFocus;
693 return TRUE;
694 }
695 break;
696 case DFM_SETFOCUS: {
697 DFWINDOW pwnd = DfGetParent(wnd);
698 if (p1)
699 {
700 DfDefaultWndProc(wnd, msg, p1, p2);
701 if (pwnd != NULL)
702 {
703 pwnd->dfocus = wnd;
704 DfSendMessage(pwnd, DFM_COMMAND,
705 inFocusCommand(db), DFM_ENTERFOCUS);
706 }
707 return TRUE;
708 }
709 else
710 DfSendMessage(pwnd, DFM_COMMAND,
711 inFocusCommand(db), DFM_LEAVEFOCUS);
712 break;
713 }
714 case DFM_CLOSE_WINDOW:
715 CtlCloseWindowMsg(wnd);
716 break;
717 default:
718 break;
719 }
720 return DfDefaultWndProc(wnd, msg, p1, p2);
721 }
722
723 /* ---- change the focus to the first control --- */
724 static void FirstFocus(DF_DBOX *db)
725 {
726 DF_CTLWINDOW *ct = db->ctl;
727 if (ct != NULL)
728 {
729 while (ct->class == DF_TEXT || ct->class == DF_BOX) {
730 ct++;
731 if (ct->class == 0)
732 return;
733 }
734 DfSendMessage(ct->wnd, DFM_SETFOCUS, TRUE, 0);
735 }
736 }
737
738 /* ---- change the focus to the next control --- */
739 static void NextFocus(DF_DBOX *db)
740 {
741 DF_CTLWINDOW *ct = WindowControl(db, DfInFocus);
742 int looped = 0;
743 if (ct != NULL)
744 {
745 do
746 {
747 ct++;
748 if (ct->class == 0)
749 {
750 if (looped)
751 return;
752 looped++;
753 ct = db->ctl;
754 }
755 } while (ct->class == DF_TEXT || ct->class == DF_BOX);
756 DfSendMessage(ct->wnd, DFM_SETFOCUS, TRUE, 0);
757 }
758 }
759
760 /* ---- change the focus to the previous control --- */
761 static void PrevFocus(DF_DBOX *db)
762 {
763 DF_CTLWINDOW *ct = WindowControl(db, DfInFocus);
764 int looped = 0;
765 if (ct != NULL)
766 {
767 do
768 {
769 if (ct == db->ctl)
770 {
771 if (looped)
772 return;
773 looped++;
774 while (ct->class)
775 ct++;
776 }
777 --ct;
778 } while (ct->class == DF_TEXT || ct->class == DF_BOX);
779 DfSendMessage(ct->wnd, DFM_SETFOCUS, TRUE, 0);
780 }
781 }
782
783 void DfSetFocusCursor(DFWINDOW wnd)
784 {
785 if (wnd == DfInFocus)
786 {
787 DfSendMessage(NULL, DFM_SHOW_CURSOR, 0, 0);
788 DfSendMessage(wnd, DFM_KEYBOARD_CURSOR, 1, 0);
789 }
790 }
791
792 /* EOF */