remove empty dir
[reactos.git] / rosapps / lib / dflat32 / dialbox.c
1 /* ----------------- dialbox.c -------------- */
2
3 #include "dflat32/dflat.h"
4
5 static int inFocusCommand(DBOX *);
6 static void dbShortcutKeys(DBOX *, int);
7 static int ControlProc(DFWINDOW, DFMESSAGE, PARAM, PARAM);
8 static void FirstFocus(DBOX *db);
9 static void NextFocus(DBOX *db);
10 static void PrevFocus(DBOX *db);
11 static CTLWINDOW *AssociatedControl(DBOX *, enum commands);
12
13 static BOOL SysMenuOpen;
14
15 static DBOX **dbs = NULL;
16 static int dbct = 0;
17
18 /* --- clear all heap allocations to control text fields --- */
19 void ClearDialogBoxes(void)
20 {
21 int i;
22
23 for (i = 0; i < dbct; i++)
24 {
25 CTLWINDOW *ct = (*(dbs+i))->ctl;
26
27 while (ct->class)
28 {
29 if ((ct->class == EDITBOX ||
30 ct->class == 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 /* -------- CREATE_WINDOW Message --------- */
49 static int CreateWindowMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
50 {
51 DBOX *db = wnd->extension;
52 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(DBOX *) * (dbct+1));
61 *(dbs + dbct++) = db;
62 }
63 rtn = BaseWndProc(DIALOG, wnd, CREATE_WINDOW, p1, p2);
64 ct = db->ctl;
65 while (ct->class) {
66 int attrib = 0;
67 if (TestAttribute(wnd, NOCLIP))
68 attrib |= NOCLIP;
69 if (wnd->Modal)
70 attrib |= SAVESELF;
71 ct->setting = ct->isetting;
72 if (ct->class == EDITBOX && ct->dwnd.h > 1)
73 attrib |= (MULTILINE | HASBORDER);
74 else if ((ct->class == LISTBOX || ct->class == TEXTBOX) &&
75 ct->dwnd.h > 2)
76 attrib |= HASBORDER;
77 cwnd = DfCreateWindow(ct->class,
78 ct->dwnd.title,
79 ct->dwnd.x+GetClientLeft(wnd),
80 ct->dwnd.y+GetClientTop(wnd),
81 ct->dwnd.h,
82 ct->dwnd.w,
83 ct,
84 wnd,
85 ControlProc,
86 attrib);
87 if ((ct->class == EDITBOX ||
88 ct->class == COMBOBOX) &&
89 ct->itext != NULL)
90 DfSendMessage(cwnd, SETTEXT, (PARAM) ct->itext, 0);
91 ct++;
92 }
93 return rtn;
94 }
95
96 /* -------- LEFT_BUTTON Message --------- */
97 static BOOL LeftButtonMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
98 {
99 DBOX *db = wnd->extension;
100 CTLWINDOW *ct = db->ctl;
101 if (WindowSizing || WindowMoving)
102 return TRUE;
103 if (HitControlBox(wnd, p1-GetLeft(wnd), p2-GetTop(wnd))) {
104 DfPostMessage(wnd, KEYBOARD, ' ', ALTKEY);
105 return TRUE;
106 }
107 while (ct->class) {
108 DFWINDOW cwnd = ct->wnd;
109 if (ct->class == COMBOBOX) {
110 if (p2 == GetTop(cwnd)) {
111 if (p1 == GetRight(cwnd)+1) {
112 DfSendMessage(cwnd, LEFT_BUTTON, p1, p2);
113 return TRUE;
114 }
115 }
116 if (GetClass(inFocus) == LISTBOX)
117 DfSendMessage(wnd, SETFOCUS, TRUE, 0);
118 }
119 else if (ct->class == SPINBUTTON) {
120 if (p2 == GetTop(cwnd)) {
121 if (p1 == GetRight(cwnd)+1 ||
122 p1 == GetRight(cwnd)+2) {
123 DfSendMessage(cwnd, LEFT_BUTTON, p1, p2);
124 return TRUE;
125 }
126 }
127 }
128 ct++;
129 }
130 return FALSE;
131 }
132
133 /* -------- KEYBOARD Message --------- */
134 static BOOL KeyboardMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
135 {
136 DBOX *db = wnd->extension;
137 CTLWINDOW *ct;
138
139 if (WindowMoving || WindowSizing)
140 return FALSE;
141 switch ((int)p1) {
142 case F1:
143 ct = GetControl(inFocus);
144 if (ct != NULL)
145 if (DisplayHelp(wnd, ct->help))
146 return TRUE;
147 break;
148 case SHIFT_HT:
149 case BS:
150 case UP:
151 PrevFocus(db);
152 break;
153 case ALT_F6:
154 case '\t':
155 case FWD:
156 case DN:
157 NextFocus(db);
158 break;
159 case ' ':
160 if (((int)p2 & ALTKEY) &&
161 TestAttribute(wnd, CONTROLBOX)) {
162 SysMenuOpen = TRUE;
163 BuildSystemMenu(wnd);
164 }
165 break;
166 case CTRL_F4:
167 case ESC:
168 DfSendMessage(wnd, DFM_COMMAND, 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, PARAM p1, PARAM p2)
180 {
181 DBOX *db = wnd->extension;
182 switch ((int) p1) {
183 case ID_OK:
184 case ID_CANCEL:
185 if ((int)p2 != 0)
186 return TRUE;
187 wnd->ReturnCode = (int) p1;
188 if (wnd->Modal)
189 DfPostMessage(wnd, ENDDIALOG, 0, 0);
190 else
191 DfSendMessage(wnd, CLOSE_WINDOW, TRUE, 0);
192 return TRUE;
193 case ID_HELP:
194 if ((int)p2 != 0)
195 return TRUE;
196 return DisplayHelp(wnd, db->HelpName);
197 default:
198 break;
199 }
200 return FALSE;
201 }
202
203 /* ----- window-processing module, DIALOG window class ----- */
204 int DialogProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
205 {
206 int rtn;
207 DBOX *db = wnd->extension;
208
209 switch (msg) {
210 case CREATE_WINDOW:
211 return CreateWindowMsg(wnd, p1, p2);
212 case SHIFT_CHANGED:
213 if (wnd->Modal)
214 return TRUE;
215 break;
216 case LEFT_BUTTON:
217 if (LeftButtonMsg(wnd, p1, p2))
218 return TRUE;
219 break;
220 case KEYBOARD:
221 if (KeyboardMsg(wnd, p1, p2))
222 return TRUE;
223 break;
224 case CLOSE_POPDOWN:
225 SysMenuOpen = FALSE;
226 break;
227 case LB_SELECTION:
228 case 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 PAINT:
238 p2 = TRUE;
239 break;
240 case MOVE:
241 case DFM_SIZE:
242 rtn = BaseWndProc(DIALOG, wnd, msg, p1, p2);
243 if (wnd->dfocus != NULL)
244 DfSendMessage(wnd->dfocus, SETFOCUS, TRUE, 0);
245 return rtn;
246
247 case CLOSE_WINDOW:
248 if (!p1)
249 {
250 DfSendMessage(wnd, DFM_COMMAND, ID_CANCEL, 0);
251 return TRUE;
252 }
253 break;
254
255 default:
256 break;
257 }
258 return BaseWndProc(DIALOG, wnd, msg, p1, p2);
259 }
260
261 /* ------- create and execute a dialog box ---------- */
262 BOOL DfDialogBox(DFWINDOW wnd, DBOX *db, BOOL Modal,
263 int (*wndproc)(struct window *, enum messages, PARAM, 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 += GetLeft(wnd);
272 y += GetTop(wnd);
273 }
274 DialogWnd = DfCreateWindow(DIALOG,
275 db->dwnd.title,
276 x, y,
277 db->dwnd.h,
278 db->dwnd.w,
279 db,
280 wnd,
281 wndproc,
282 Modal ? SAVESELF : 0);
283 DialogWnd->Modal = Modal;
284 FirstFocus(db);
285 DfPostMessage(DialogWnd, INITIATE_DIALOG, 0, 0);
286 if (Modal)
287 {
288 DfSendMessage(DialogWnd, CAPTURE_MOUSE, 0, 0);
289 DfSendMessage(DialogWnd, CAPTURE_KEYBOARD, 0, 0);
290 while (DfDispatchMessage ())
291 ;
292 rtn = DialogWnd->ReturnCode == ID_OK;
293 DfSendMessage(DialogWnd, RELEASE_MOUSE, 0, 0);
294 DfSendMessage(DialogWnd, RELEASE_KEYBOARD, 0, 0);
295 DfSendMessage(DialogWnd, 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(DBOX *db)
303 {
304 CTLWINDOW *ct = db->ctl;
305 while (ct->class) {
306 if (ct->wnd == inFocus)
307 return ct->command;
308 ct++;
309 }
310 return -1;
311 }
312
313 /* -------- find a specified control structure ------- */
314 CTLWINDOW *FindCommand(DBOX *db, enum commands cmd, int class)
315 {
316 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 ControlWindow(DBOX *db, enum commands cmd)
329 {
330 CTLWINDOW *ct = db->ctl;
331 while (ct->class)
332 {
333 if (ct->class != 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 CTLWINDOW *WindowControl(DBOX *db, DFWINDOW wnd)
342 {
343 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 ON or OFF ----- */
354 void ControlSetting(DBOX *db, enum commands cmd,
355 int class, int setting)
356 {
357 CTLWINDOW *ct = FindCommand(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 *GetDlgTextString(DBOX *db,enum commands cmd,DFCLASS class)
367 {
368 CTLWINDOW *ct = FindCommand(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 SetDlgTextString(DBOX *db, enum commands cmd,
377 char *text, DFCLASS class)
378 {
379 CTLWINDOW *ct = FindCommand(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 PutItemText(DFWINDOW wnd, enum commands cmd, char *text)
388 {
389 CTLWINDOW *ct = FindCommand(wnd->extension, cmd, EDITBOX);
390
391 if (ct == NULL)
392 ct = FindCommand(wnd->extension, cmd, TEXTBOX);
393 if (ct == NULL)
394 ct = FindCommand(wnd->extension, cmd, COMBOBOX);
395 if (ct == NULL)
396 ct = FindCommand(wnd->extension, cmd, LISTBOX);
397 if (ct == NULL)
398 ct = FindCommand(wnd->extension, cmd, SPINBUTTON);
399 if (ct == NULL)
400 ct = FindCommand(wnd->extension, cmd, TEXT);
401 if (ct != NULL) {
402 DFWINDOW cwnd = (DFWINDOW) (ct->wnd);
403 switch (ct->class) {
404 case COMBOBOX:
405 case EDITBOX:
406 DfSendMessage(cwnd, CLEARTEXT, 0, 0);
407 DfSendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
408 if (!isMultiLine(cwnd))
409 DfSendMessage(cwnd, PAINT, 0, 0);
410 break;
411 case LISTBOX:
412 case TEXTBOX:
413 case SPINBUTTON:
414 DfSendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
415 break;
416 case TEXT: {
417 DfSendMessage(cwnd, CLEARTEXT, 0, 0);
418 DfSendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
419 DfSendMessage(cwnd, PAINT, 0, 0);
420 break;
421 }
422 default:
423 break;
424 }
425 }
426 }
427
428 /* ------- get the text of a control window ------ */
429 void GetItemText(DFWINDOW wnd, enum commands cmd,
430 char *text, int len)
431 {
432 CTLWINDOW *ct = FindCommand(wnd->extension, cmd, EDITBOX);
433 unsigned char *cp;
434
435 if (ct == NULL)
436 ct = FindCommand(wnd->extension, cmd, COMBOBOX);
437 if (ct == NULL)
438 ct = FindCommand(wnd->extension, cmd, TEXTBOX);
439 if (ct == NULL)
440 ct = FindCommand(wnd->extension, cmd, TEXT);
441 if (ct != NULL) {
442 DFWINDOW cwnd = (DFWINDOW) (ct->wnd);
443 if (cwnd != NULL) {
444 switch (ct->class) {
445 case TEXT:
446 if (GetText(cwnd) != NULL) {
447 cp = strchr(GetText(cwnd), '\n');
448 if (cp != NULL)
449 len = (int) (cp - GetText(cwnd));
450 strncpy(text, GetText(cwnd), len);
451 *(text+len) = '\0';
452 }
453 break;
454 case TEXTBOX:
455 if (GetText(cwnd) != NULL)
456 strncpy(text, GetText(cwnd), len);
457 break;
458 case COMBOBOX:
459 case EDITBOX:
460 DfSendMessage(cwnd,GETTEXT,(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 GetDlgListText(DFWINDOW wnd, char *text, enum commands cmd)
471 {
472 CTLWINDOW *ct = FindCommand(wnd->extension, cmd, LISTBOX);
473 int sel = DfSendMessage(ct->wnd, LB_CURRENTSELECTION, 0, 0);
474 DfSendMessage(ct->wnd, DFM_LB_GETTEXT, (PARAM) text, sel);
475 }
476
477 /* -- find control structure associated with text control -- */
478 static CTLWINDOW *AssociatedControl(DBOX *db,enum commands Tcmd)
479 {
480 CTLWINDOW *ct = db->ctl;
481 while (ct->class) {
482 if (ct->class != 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(DBOX *db, int ky)
492 {
493 CTLWINDOW *ct;
494 int ch = AltConvert(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 == SHORTCUTCHAR &&
502 tolower(*(cp+1)) == ch) {
503 if (ct->class == TEXT)
504 ct = AssociatedControl(db, ct->command);
505 if (ct->class == RADIOBUTTON)
506 SetRadioButton(db, ct);
507 else if (ct->class == CHECKBOX) {
508 ct->setting ^= ON;
509 DfSendMessage(ct->wnd, PAINT, 0, 0);
510 }
511 else if (ct->class) {
512 DfSendMessage(ct->wnd, SETFOCUS, TRUE, 0);
513 if (ct->class == BUTTON)
514 DfSendMessage(ct->wnd,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 SetScrollBars(DFWINDOW wnd)
528 {
529 int oldattr = GetAttribute(wnd);
530 if (wnd->wlines > ClientHeight(wnd))
531 AddAttribute(wnd, VSCROLLBAR);
532 else
533 ClearAttribute(wnd, VSCROLLBAR);
534 if (wnd->textwidth > ClientWidth(wnd))
535 AddAttribute(wnd, HSCROLLBAR);
536 else
537 ClearAttribute(wnd, HSCROLLBAR);
538 if (GetAttribute(wnd) != oldattr)
539 DfSendMessage(wnd, BORDER, 0, 0);
540 }
541
542 /* ------- CREATE_WINDOW Message (Control) ----- */
543 static void CtlCreateWindowMsg(DFWINDOW wnd)
544 {
545 CTLWINDOW *ct;
546 ct = wnd->ct = wnd->extension;
547 wnd->extension = NULL;
548 if (ct != NULL)
549 ct->wnd = wnd;
550 }
551
552 /* ------- KEYBOARD Message (Control) ----- */
553 static BOOL CtlKeyboardMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
554 {
555 CTLWINDOW *ct = GetControl(wnd);
556 switch ((int) p1) {
557 case F1:
558 if (WindowMoving || WindowSizing)
559 break;
560 if (!DisplayHelp(wnd, ct->help))
561 DfSendMessage(GetParent(wnd),DFM_COMMAND,ID_HELP,0);
562 return TRUE;
563 case ' ':
564 if (!((int)p2 & ALTKEY))
565 break;
566 case ALT_F6:
567 case CTRL_F4:
568 case ALT_F4:
569 DfPostMessage(GetParent(wnd), KEYBOARD, p1, p2);
570 return TRUE;
571 default:
572 break;
573 }
574 if (GetClass(wnd) == EDITBOX)
575 if (isMultiLine(wnd))
576 return FALSE;
577 switch ((int) p1) {
578 case UP:
579 if (!isDerivedFrom(wnd, LISTBOX)) {
580 p1 = CTRL_FIVE;
581 p2 = LEFTSHIFT;
582 }
583 break;
584 case BS:
585 if (!isDerivedFrom(wnd, EDITBOX)) {
586 p1 = CTRL_FIVE;
587 p2 = LEFTSHIFT;
588 }
589 break;
590 case DN:
591 if (!isDerivedFrom(wnd, LISTBOX) &&
592 !isDerivedFrom(wnd, COMBOBOX))
593 p1 = '\t';
594 break;
595 case FWD:
596 if (!isDerivedFrom(wnd, EDITBOX))
597 p1 = '\t';
598 break;
599 case '\r':
600 if (isDerivedFrom(wnd, EDITBOX))
601 if (isMultiLine(wnd))
602 break;
603 if (isDerivedFrom(wnd, BUTTON))
604 break;
605 DfSendMessage(GetParent(wnd), DFM_COMMAND, ID_OK, 0);
606 return TRUE;
607 default:
608 break;
609 }
610 return FALSE;
611 }
612
613 /* ------- CLOSE_WINDOW Message (Control) ----- */
614 static void CtlCloseWindowMsg(DFWINDOW wnd)
615 {
616 CTLWINDOW *ct = GetControl(wnd);
617 if (ct != NULL) {
618 ct->wnd = NULL;
619 if (GetParent(wnd)->ReturnCode == ID_OK) {
620 if (ct->class == EDITBOX || ct->class == COMBOBOX) {
621 if (wnd->TextChanged) {
622 ct->itext=DFrealloc(ct->itext,strlen(wnd->text)+1);
623 strcpy(ct->itext, wnd->text);
624 if (!isMultiLine(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 == RADIOBUTTON || ct->class == CHECKBOX)
632 ct->isetting = ct->setting;
633 }
634 }
635 }
636
637
638 static void FixColors(DFWINDOW wnd)
639 {
640 CTLWINDOW *ct = wnd->ct;
641
642 if (ct->class != BUTTON)
643 {
644 if (ct->class != SPINBUTTON && ct->class != COMBOBOX)
645 {
646 wnd->WindowColors[FRAME_COLOR][FG] =
647 GetParent(wnd)->WindowColors[FRAME_COLOR][FG];
648 wnd->WindowColors[FRAME_COLOR][BG] =
649 GetParent(wnd)->WindowColors[FRAME_COLOR][BG];
650 if (ct->class != EDITBOX && ct->class != LISTBOX)
651 {
652 wnd->WindowColors[STD_COLOR][FG] =
653 GetParent(wnd)->WindowColors[STD_COLOR][FG];
654 wnd->WindowColors[STD_COLOR][BG] =
655 GetParent(wnd)->WindowColors[STD_COLOR][BG];
656 }
657 }
658 }
659 }
660
661
662 /* -- generic window processor used by dialog box controls -- */
663 static int ControlProc(DFWINDOW wnd,DFMESSAGE msg,PARAM p1,PARAM p2)
664 {
665 DBOX *db;
666
667 if (wnd == NULL)
668 return FALSE;
669 db = GetParent(wnd) ? GetParent(wnd)->extension : NULL;
670
671 switch (msg) {
672 case CREATE_WINDOW:
673 CtlCreateWindowMsg(wnd);
674 break;
675 case KEYBOARD:
676 if (CtlKeyboardMsg(wnd, p1, p2))
677 return TRUE;
678 break;
679 case PAINT:
680 FixColors(wnd);
681 if (GetClass(wnd) == EDITBOX ||
682 GetClass(wnd) == LISTBOX ||
683 GetClass(wnd) == TEXTBOX)
684 SetScrollBars(wnd);
685 break;
686 case BORDER:
687 FixColors(wnd);
688 if (GetClass(wnd) == EDITBOX) {
689 DFWINDOW oldFocus = inFocus;
690 inFocus = NULL;
691 DefaultWndProc(wnd, msg, p1, p2);
692 inFocus = oldFocus;
693 return TRUE;
694 }
695 break;
696 case SETFOCUS: {
697 DFWINDOW pwnd = GetParent(wnd);
698 if (p1)
699 {
700 DefaultWndProc(wnd, msg, p1, p2);
701 if (pwnd != NULL)
702 {
703 pwnd->dfocus = wnd;
704 DfSendMessage(pwnd, DFM_COMMAND,
705 inFocusCommand(db), ENTERFOCUS);
706 }
707 return TRUE;
708 }
709 else
710 DfSendMessage(pwnd, DFM_COMMAND,
711 inFocusCommand(db), LEAVEFOCUS);
712 break;
713 }
714 case CLOSE_WINDOW:
715 CtlCloseWindowMsg(wnd);
716 break;
717 default:
718 break;
719 }
720 return DefaultWndProc(wnd, msg, p1, p2);
721 }
722
723 /* ---- change the focus to the first control --- */
724 static void FirstFocus(DBOX *db)
725 {
726 CTLWINDOW *ct = db->ctl;
727 if (ct != NULL)
728 {
729 while (ct->class == TEXT || ct->class == BOX) {
730 ct++;
731 if (ct->class == 0)
732 return;
733 }
734 DfSendMessage(ct->wnd, SETFOCUS, TRUE, 0);
735 }
736 }
737
738 /* ---- change the focus to the next control --- */
739 static void NextFocus(DBOX *db)
740 {
741 CTLWINDOW *ct = WindowControl(db, inFocus);
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 == TEXT || ct->class == BOX);
756 DfSendMessage(ct->wnd, SETFOCUS, TRUE, 0);
757 }
758 }
759
760 /* ---- change the focus to the previous control --- */
761 static void PrevFocus(DBOX *db)
762 {
763 CTLWINDOW *ct = WindowControl(db, inFocus);
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 == TEXT || ct->class == BOX);
779 DfSendMessage(ct->wnd, SETFOCUS, TRUE, 0);
780 }
781 }
782
783 void SetFocusCursor(DFWINDOW wnd)
784 {
785 if (wnd == inFocus)
786 {
787 DfSendMessage(NULL, SHOW_CURSOR, 0, 0);
788 DfSendMessage(wnd, KEYBOARD_CURSOR, 1, 0);
789 }
790 }
791
792 /* EOF */