1 /* ------------- applicat.c ------------- */
5 static BOOL DisplayModified
= FALSE
;
6 DFWINDOW DfApplicationWindow
;
8 extern DF_DBOX Display
;
9 extern DF_DBOX Windows
;
11 #ifdef INCLUDE_LOGGING
15 #ifdef INCLUDE_SHELLDOS
16 static void ShellDOS(DFWINDOW
);
18 static void DfCreateMenu(DFWINDOW
);
19 static void CreateStatusBar(DFWINDOW
);
20 static void SelectColors(DFWINDOW
);
22 #ifdef INCLUDE_WINDOWOPTIONS
23 static void SelectTexture(void);
24 static void SelectBorder(DFWINDOW
);
25 static void SelectTitle(DFWINDOW
);
26 static void SelectStatusBar(DFWINDOW
);
29 static DFWINDOW oldFocus
;
30 #ifdef INCLUDE_MULTI_WINDOWS
31 static void CloseAll(DFWINDOW
, int);
32 static void MoreWindows(DFWINDOW
);
33 static void ChooseWindow(DFWINDOW
, int);
35 static char Menus
[9][26] =
49 /* --------------- DFM_CREATE_WINDOW Message -------------- */
50 static int CreateWindowMsg(DFWINDOW wnd
)
54 DfApplicationWindow
= wnd
;
55 #ifdef INCLUDE_WINDOWOPTIONS
57 DfSetCheckBox(&Display
, DF_ID_BORDER
);
59 DfSetCheckBox(&Display
, DF_ID_TITLE
);
61 DfSetCheckBox(&Display
, DF_ID_STATUSBAR
);
63 DfSetCheckBox(&Display
, DF_ID_TEXTURE
);
66 #ifdef INCLUDE_WINDOWOPTIONS
71 rtn
= DfBaseWndProc(DF_APPLICATION
, wnd
, DFM_CREATE_WINDOW
, 0, 0);
72 if (wnd
->extension
!= NULL
)
78 /* --------- DFM_ADDSTATUS Message ---------- */
79 static void AddStatusMsg(DFWINDOW wnd
, DF_PARAM p1
)
81 if (wnd
->StatusBar
!= NULL
) {
82 if (p1
&& *(char *)p1
)
83 DfSendMessage(wnd
->StatusBar
, DFM_SETTEXT
, p1
, 0);
85 DfSendMessage(wnd
->StatusBar
, DFM_CLEARTEXT
, 0, 0);
86 DfSendMessage(wnd
->StatusBar
, DFM_PAINT
, 0, 0);
90 /* -------- DFM_SETFOCUS Message -------- */
91 static void SetFocusMsg(DFWINDOW wnd
, BOOL p1
)
94 DfSendMessage(DfInFocus
, DFM_SETFOCUS
, FALSE
, 0);
95 DfInFocus
= p1
? wnd
: NULL
;
97 DfSendMessage(wnd
, DFM_BORDER
, 0, 0);
99 DfSendMessage(wnd
, DFM_SHOW_WINDOW
, 0, 0);
102 /* ------- SIZE Message -------- */
103 static void SizeMsg(DFWINDOW wnd
, DF_PARAM p1
, DF_PARAM p2
)
106 WasVisible
= DfIsVisible(wnd
);
108 DfSendMessage(wnd
, DFM_HIDE_WINDOW
, 0, 0);
109 if (p1
-DfGetLeft(wnd
) < 30)
110 p1
= DfGetLeft(wnd
) + 30;
111 DfBaseWndProc(DF_APPLICATION
, wnd
, DFM_DFM_SIZE
, p1
, p2
);
113 CreateStatusBar(wnd
);
115 DfSendMessage(wnd
, DFM_SHOW_WINDOW
, 0, 0);
118 /* ----------- DFM_KEYBOARD Message ------------ */
119 static int KeyboardMsg(DFWINDOW wnd
, DF_PARAM p1
, DF_PARAM p2
)
121 if (DfWindowMoving
|| DfWindowSizing
|| (int) p1
== DF_F1
)
122 return DfBaseWndProc(DF_APPLICATION
, wnd
, DFM_KEYBOARD
, p1
, p2
);
125 DfPostMessage(wnd
, DFM_CLOSE_WINDOW
, 0, 0);
127 #ifdef INCLUDE_MULTI_WINDOWS
133 DfBuildSystemMenu(wnd
);
138 DfPostMessage(wnd
->MenuBarWnd
, DFM_KEYBOARD
, p1
, p2
);
142 /* --------- DFM_SHIFT_CHANGED Message -------- */
143 static void ShiftChangedMsg(DFWINDOW wnd
, DF_PARAM p1
)
146 if ((int)p1
& DF_ALTKEY
)
150 if (wnd
->MenuBarWnd
!= DfInFocus
)
151 DfSendMessage(NULL
, DFM_HIDE_CURSOR
, 0, 0);
152 DfSendMessage(wnd
->MenuBarWnd
, DFM_KEYBOARD
, DF_F10
, 0);
156 /* -------- COMMAND Message ------- */
157 static void CommandMsg(DFWINDOW wnd
, DF_PARAM p1
, DF_PARAM p2
)
161 DfDisplayHelp(wnd
, DFlatApplication
);
164 DfDisplayHelp(wnd
, "HelpHelp");
167 DfDisplayHelp(wnd
, "ExtHelp");
170 DfDisplayHelp(wnd
, "KeysHelp");
172 case DF_ID_HELPINDEX
:
173 DfDisplayHelp(wnd
, "HelpIndex");
180 #ifdef INCLUDE_LOGGING
185 #ifdef INCLUDE_SHELLDOS
192 DfPostMessage(wnd
, DFM_CLOSE_WINDOW
, 0, 0);
195 if (DfDialogBox(wnd
, &Display
, TRUE
, NULL
)) {
196 if (DfInFocus
== wnd
->MenuBarWnd
|| DfInFocus
== wnd
->StatusBar
)
197 oldFocus
= DfApplicationWindow
;
199 oldFocus
= DfInFocus
;
200 DfSendMessage(wnd
, DFM_HIDE_WINDOW
, 0, 0);
202 #ifdef INCLUDE_WINDOWOPTIONS
205 SelectStatusBar(wnd
);
209 CreateStatusBar(wnd
);
210 DfSendMessage(wnd
, DFM_SHOW_WINDOW
, 0, 0);
211 DfSendMessage(oldFocus
, DFM_SETFOCUS
, TRUE
, 0);
214 case DF_ID_SAVEOPTIONS
:
217 #ifdef INCLUDE_MULTI_WINDOWS
219 ChooseWindow(wnd
, (int)p2
-2);
222 CloseAll(wnd
, FALSE
);
224 case DF_ID_MOREWINDOWS
:
228 #ifdef INCLUDE_RESTORE
229 case DF_ID_SYSRESTORE
:
233 #ifdef INCLUDE_MINIMIZE
234 case DF_ID_SYSMINIMIZE
:
236 #ifdef INCLUDE_MAXIMIZE
237 case DF_ID_SYSMAXIMIZE
:
239 DfBaseWndProc(DF_APPLICATION
, wnd
, DFM_COMMAND
, p1
, p2
);
242 if (DfInFocus
!= wnd
->MenuBarWnd
&& DfInFocus
!= wnd
)
243 DfPostMessage(DfInFocus
, DFM_COMMAND
, p1
, p2
);
248 /* --------- DFM_CLOSE_WINDOW Message -------- */
249 static int CloseWindowMsg(DFWINDOW wnd
)
252 #ifdef INCLUDE_MULTI_WINDOWS
256 DfPostMessage(NULL
, DFM_STOP
, 0, 0);
257 rtn
= DfBaseWndProc(DF_APPLICATION
, wnd
, DFM_CLOSE_WINDOW
, 0, 0);
259 DisplayModified
= FALSE
;
260 DfApplicationWindow
= NULL
;
264 /* --- DF_APPLICATION Window Class window processing module --- */
265 int DfApplicationProc(DFWINDOW wnd
, DFMESSAGE msg
, DF_PARAM p1
, DF_PARAM p2
)
269 case DFM_CREATE_WINDOW
:
270 return CreateWindowMsg(wnd
);
271 case DFM_HIDE_WINDOW
:
272 if (wnd
== DfInFocus
)
276 AddStatusMsg(wnd
, p1
);
279 if ((int)p1
== (DfInFocus
!= wnd
)) {
280 SetFocusMsg(wnd
, (BOOL
) p1
);
285 SizeMsg(wnd
, p1
, p2
);
287 #ifdef INCLUDE_MINIMIZE
292 return KeyboardMsg(wnd
, p1
, p2
);
293 case DFM_SHIFT_CHANGED
:
294 ShiftChangedMsg(wnd
, p1
);
297 if (DfIsVisible(wnd
)) {
298 #ifdef INCLUDE_WINDOWOPTIONS
299 int cl
= DfCfg
.Texture
? DF_APPLCHAR
: ' ';
301 int cl
= DF_APPLCHAR
;
303 DfClearWindow(wnd
, (DFRECT
*)p1
, cl
);
307 CommandMsg(wnd
, p1
, p2
);
309 case DFM_CLOSE_WINDOW
:
310 return CloseWindowMsg(wnd
);
314 return DfBaseWndProc(DF_APPLICATION
, wnd
, msg
, p1
, p2
);
317 #ifdef INCLUDE_SHELLDOS
318 static void SwitchCursor(void)
320 DfSendMessage(NULL
, DFM_SAVE_CURSOR
, 0, 0);
322 DfSendMessage(NULL
, DFM_RESTORE_CURSOR
, 0, 0);
325 /* ------- Shell out to DOS ---------- */
326 static void ShellDOS(DFWINDOW wnd
)
328 oldFocus
= DfInFocus
;
329 DfSendMessage(wnd
, DFM_HIDE_WINDOW
, 0, 0);
331 printf("To return to %s, execute the DOS exit command.",
334 _spawnl(P_WAIT
, getenv("COMSPEC"), " ", NULL
);
336 DfSendMessage(wnd
, DFM_SHOW_WINDOW
, 0, 0);
337 DfSendMessage(oldFocus
, DFM_SETFOCUS
, TRUE
, 0);
341 /* -------- Create the menu bar -------- */
342 static void DfCreateMenu(DFWINDOW wnd
)
344 DfAddAttribute(wnd
, DF_HASMENUBAR
);
345 if (wnd
->MenuBarWnd
!= NULL
)
346 DfSendMessage(wnd
->MenuBarWnd
, DFM_CLOSE_WINDOW
, 0, 0);
347 wnd
->MenuBarWnd
= DfDfCreateWindow(DF_MENUBAR
,
349 DfGetClientLeft(wnd
),
350 DfGetClientTop(wnd
)-1,
357 DfSendMessage(wnd
->MenuBarWnd
,DFM_BUILDMENU
,
358 (DF_PARAM
)wnd
->extension
,0);
359 DfAddAttribute(wnd
->MenuBarWnd
, DF_VISIBLE
);
362 /* ----------- Create the status bar ------------- */
363 static void CreateStatusBar(DFWINDOW wnd
)
365 if (wnd
->StatusBar
!= NULL
) {
366 DfSendMessage(wnd
->StatusBar
, DFM_CLOSE_WINDOW
, 0, 0);
367 wnd
->StatusBar
= NULL
;
369 if (DfTestAttribute(wnd
, DF_HASSTATUSBAR
)) {
370 wnd
->StatusBar
= DfDfCreateWindow(DF_STATUSBAR
,
372 DfGetClientLeft(wnd
),
380 DfAddAttribute(wnd
->StatusBar
, DF_VISIBLE
);
384 #ifdef INCLUDE_MULTI_WINDOWS
385 /* -------- return the name of a document window ------- */
386 static char *WindowName(DFWINDOW wnd
)
388 if (DfGetTitle(wnd
) == NULL
)
390 if (DfGetClass(wnd
) == DF_DIALOG
)
391 return ((DF_DBOX
*)(wnd
->extension
))->HelpName
;
396 return DfGetTitle(wnd
);
399 /* ----------- Prepare the Window menu ------------ */
400 void DfPrepWindowMenu(void *w
, struct DfMenu
*mnu
)
403 struct DfPopDown
*p0
= mnu
->Selections
;
404 struct DfPopDown
*pd
= mnu
->Selections
+ 2;
405 struct DfPopDown
*ca
= mnu
->Selections
+ 13;
412 if (DfGetClass(wnd
) != DF_APPLICATION
)
416 /* point to the DF_APPLICATION window */
417 if (DfApplicationWindow
== NULL
)
420 cwnd
= DfFirstWindow(DfApplicationWindow
);
421 /* get the first 9 document windows */
422 while (cwnd
!= NULL
&& MenuNo
< 9)
424 if (DfGetClass(cwnd
) != DF_MENUBAR
&&
425 DfGetClass(cwnd
) != DF_STATUSBAR
)
427 /* add the document window to the menu */
428 strncpy (Menus
[MenuNo
]+4, WindowName(cwnd
), 20);
429 pd
->SelectionTitle
= Menus
[MenuNo
];
430 if (cwnd
== oldFocus
)
432 /* mark the current document */
433 pd
->Attrib
|= DF_CHECKED
;
434 mnu
->Selection
= MenuNo
+2;
437 pd
->Attrib
&= ~DF_CHECKED
;
441 cwnd
= DfNextWindow(cwnd
);
446 p0
->SelectionTitle
= "~Close all";
448 p0
->SelectionTitle
= NULL
;
453 if (mnu
->Selection
== 0)
456 pd
->SelectionTitle
= NULL
;
459 /* window processing module for the More Windows dialog box */
460 static int WindowPrep(DFWINDOW wnd
,DFMESSAGE msg
,DF_PARAM p1
,DF_PARAM p2
)
463 case DFM_INITIATE_DIALOG
: {
465 DFWINDOW cwnd
= DfControlWindow(&Windows
,DF_ID_WINDOWLIST
);
469 wnd1
= DfFirstWindow(DfApplicationWindow
);
470 while (wnd1
!= NULL
) {
471 if (wnd1
!= wnd
&& DfGetClass(wnd1
) != DF_MENUBAR
&&
472 DfGetClass(wnd1
) != DF_STATUSBAR
) {
473 if (wnd1
== oldFocus
)
475 DfSendMessage(cwnd
, DFM_ADDTEXT
,
476 (DF_PARAM
) WindowName(wnd1
), 0);
479 wnd1
= DfNextWindow(wnd1
);
481 DfSendMessage(cwnd
, DFM_LB_SETSELECTION
, WindowSel
, 0);
482 DfAddAttribute(cwnd
, DF_VSCROLLBAR
);
483 DfPostMessage(cwnd
, DFM_SHOW_WINDOW
, 0, 0);
490 WindowSel
= DfSendMessage(
491 DfControlWindow(&Windows
,
493 DFM_LB_CURRENTSELECTION
, 0, 0);
495 case DF_ID_WINDOWLIST
:
496 if ((int) p2
== DFM_LB_CHOOSE
)
497 DfSendMessage(wnd
, DFM_COMMAND
, DF_ID_OK
, 0);
506 return DfDefaultWndProc(wnd
, msg
, p1
, p2
);
509 /* ---- the More Windows command on the Window menu ---- */
510 static void MoreWindows(DFWINDOW wnd
)
512 if (DfDialogBox(wnd
, &Windows
, TRUE
, WindowPrep
))
513 ChooseWindow(wnd
, WindowSel
);
516 /* ----- user chose a window from the Window menu
517 or the More Window dialog box ----- */
518 static void ChooseWindow(DFWINDOW wnd
, int WindowNo
)
520 DFWINDOW cwnd
= DfFirstWindow(wnd
);
523 if (DfGetClass(cwnd
) != DF_MENUBAR
&&
524 DfGetClass(cwnd
) != DF_STATUSBAR
)
527 cwnd
= DfNextWindow(cwnd
);
530 DfSendMessage(cwnd
, DFM_SETFOCUS
, TRUE
, 0);
531 if (cwnd
->condition
== DF_ISMINIMIZED
)
532 DfSendMessage(cwnd
, DFM_RESTORE
, 0, 0);
536 /* ----- Close all document windows ----- */
537 static void CloseAll(DFWINDOW wnd
, int closing
)
541 DfSendMessage(wnd
, DFM_SETFOCUS
, TRUE
, 0);
542 wnd1
= DfLastWindow(wnd
);
545 wnd2
= DfPrevWindow(wnd1
);
546 if (DfGetClass(wnd1
) != DF_MENUBAR
&& DfGetClass(wnd1
) != DF_STATUSBAR
)
548 DfClearVisible(wnd1
);
549 DfSendMessage(wnd1
, DFM_CLOSE_WINDOW
, 0, 0);
554 DfSendMessage(wnd
, DFM_PAINT
, 0, 0);
557 #endif /* #ifdef INCLUDE_MULTI_WINDOWS */
559 static void DoWindowColors(DFWINDOW wnd
)
563 DfInitWindowColors(wnd
);
564 cwnd
= DfFirstWindow(wnd
);
567 DoWindowColors(cwnd
);
568 if (DfGetClass(cwnd
) == DF_TEXT
&& DfGetText(cwnd
) != NULL
)
569 DfSendMessage(cwnd
, DFM_CLEARTEXT
, 0, 0);
570 cwnd
= DfNextWindow(cwnd
);
574 /* set up colors for the application window */
575 static void SelectColors(DFWINDOW wnd
)
577 memcpy(DfCfg
.clr
, DfColor
, sizeof DfColor
);
582 #ifdef INCLUDE_WINDOWOPTIONS
584 /* ----- select the screen texture ----- */
585 static void SelectTexture(void)
587 DfCfg
.Texture
= DfCheckBoxSetting(&Display
, DF_ID_TEXTURE
);
590 /* -- select whether the application screen has a border -- */
591 static void SelectBorder(DFWINDOW wnd
)
593 DfCfg
.Border
= DfCheckBoxSetting(&Display
, DF_ID_BORDER
);
595 DfAddAttribute(wnd
, DF_HASBORDER
);
597 DfClearAttribute(wnd
, DF_HASBORDER
);
600 /* select whether the application screen has a status bar */
601 static void SelectStatusBar(DFWINDOW wnd
)
603 DfCfg
.StatusBar
= DfCheckBoxSetting(&Display
, DF_ID_STATUSBAR
);
605 DfAddAttribute(wnd
, DF_HASSTATUSBAR
);
607 DfClearAttribute(wnd
, DF_HASSTATUSBAR
);
610 /* select whether the application screen has a title bar */
611 static void SelectTitle(DFWINDOW wnd
)
613 DfCfg
.Title
= DfCheckBoxSetting(&Display
, DF_ID_TITLE
);
615 DfAddAttribute(wnd
, DF_HASTITLEBAR
);
617 DfClearAttribute(wnd
, DF_HASTITLEBAR
);