1 /* ------------- applicat.c ------------- */
3 #include "dflat32/dflat.h"
5 static BOOL DisplayModified
= FALSE
;
6 DFWINDOW ApplicationWindow
;
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 /* --------------- CREATE_WINDOW Message -------------- */
50 static int CreateWindowMsg(DFWINDOW wnd
)
54 ApplicationWindow
= wnd
;
55 #ifdef INCLUDE_WINDOWOPTIONS
57 SetCheckBox(&Display
, ID_BORDER
);
59 SetCheckBox(&Display
, ID_TITLE
);
61 SetCheckBox(&Display
, ID_STATUSBAR
);
63 SetCheckBox(&Display
, ID_TEXTURE
);
66 #ifdef INCLUDE_WINDOWOPTIONS
71 rtn
= BaseWndProc(APPLICATION
, wnd
, CREATE_WINDOW
, 0, 0);
72 if (wnd
->extension
!= NULL
)
78 /* --------- ADDSTATUS Message ---------- */
79 static void AddStatusMsg(DFWINDOW wnd
, PARAM p1
)
81 if (wnd
->StatusBar
!= NULL
) {
82 if (p1
&& *(char *)p1
)
83 DfSendMessage(wnd
->StatusBar
, SETTEXT
, p1
, 0);
85 DfSendMessage(wnd
->StatusBar
, CLEARTEXT
, 0, 0);
86 DfSendMessage(wnd
->StatusBar
, PAINT
, 0, 0);
90 /* -------- SETFOCUS Message -------- */
91 static void SetFocusMsg(DFWINDOW wnd
, BOOL p1
)
94 DfSendMessage(inFocus
, SETFOCUS
, FALSE
, 0);
95 inFocus
= p1
? wnd
: NULL
;
97 DfSendMessage(wnd
, BORDER
, 0, 0);
99 DfSendMessage(wnd
, SHOW_WINDOW
, 0, 0);
102 /* ------- SIZE Message -------- */
103 static void SizeMsg(DFWINDOW wnd
, PARAM p1
, PARAM p2
)
106 WasVisible
= isVisible(wnd
);
108 DfSendMessage(wnd
, DFM_HIDE_WINDOW
, 0, 0);
109 if (p1
-GetLeft(wnd
) < 30)
110 p1
= GetLeft(wnd
) + 30;
111 BaseWndProc(APPLICATION
, wnd
, DFM_SIZE
, p1
, p2
);
113 CreateStatusBar(wnd
);
115 DfSendMessage(wnd
, SHOW_WINDOW
, 0, 0);
118 /* ----------- KEYBOARD Message ------------ */
119 static int KeyboardMsg(DFWINDOW wnd
, PARAM p1
, PARAM p2
)
121 if (WindowMoving
|| WindowSizing
|| (int) p1
== F1
)
122 return BaseWndProc(APPLICATION
, wnd
, KEYBOARD
, p1
, p2
);
125 DfPostMessage(wnd
, CLOSE_WINDOW
, 0, 0);
127 #ifdef INCLUDE_MULTI_WINDOWS
133 BuildSystemMenu(wnd
);
138 DfPostMessage(wnd
->MenuBarWnd
, KEYBOARD
, p1
, p2
);
142 /* --------- SHIFT_CHANGED Message -------- */
143 static void ShiftChangedMsg(DFWINDOW wnd
, PARAM p1
)
146 if ((int)p1
& ALTKEY
)
150 if (wnd
->MenuBarWnd
!= inFocus
)
151 DfSendMessage(NULL
, HIDE_CURSOR
, 0, 0);
152 DfSendMessage(wnd
->MenuBarWnd
, KEYBOARD
, F10
, 0);
156 /* -------- COMMAND Message ------- */
157 static void CommandMsg(DFWINDOW wnd
, PARAM p1
, PARAM p2
)
161 DisplayHelp(wnd
, DFlatApplication
);
164 DisplayHelp(wnd
, "HelpHelp");
167 DisplayHelp(wnd
, "ExtHelp");
170 DisplayHelp(wnd
, "KeysHelp");
173 DisplayHelp(wnd
, "HelpIndex");
180 #ifdef INCLUDE_LOGGING
185 #ifdef INCLUDE_SHELLDOS
192 DfPostMessage(wnd
, CLOSE_WINDOW
, 0, 0);
195 if (DfDialogBox(wnd
, &Display
, TRUE
, NULL
)) {
196 if (inFocus
== wnd
->MenuBarWnd
|| inFocus
== wnd
->StatusBar
)
197 oldFocus
= ApplicationWindow
;
200 DfSendMessage(wnd
, DFM_HIDE_WINDOW
, 0, 0);
202 #ifdef INCLUDE_WINDOWOPTIONS
205 SelectStatusBar(wnd
);
209 CreateStatusBar(wnd
);
210 DfSendMessage(wnd
, SHOW_WINDOW
, 0, 0);
211 DfSendMessage(oldFocus
, SETFOCUS
, TRUE
, 0);
217 #ifdef INCLUDE_MULTI_WINDOWS
219 ChooseWindow(wnd
, (int)p2
-2);
222 CloseAll(wnd
, FALSE
);
228 #ifdef INCLUDE_RESTORE
233 #ifdef INCLUDE_MINIMIZE
236 #ifdef INCLUDE_MAXIMIZE
239 BaseWndProc(APPLICATION
, wnd
, DFM_COMMAND
, p1
, p2
);
242 if (inFocus
!= wnd
->MenuBarWnd
&& inFocus
!= wnd
)
243 DfPostMessage(inFocus
, DFM_COMMAND
, p1
, p2
);
248 /* --------- CLOSE_WINDOW Message -------- */
249 static int CloseWindowMsg(DFWINDOW wnd
)
252 #ifdef INCLUDE_MULTI_WINDOWS
256 DfPostMessage(NULL
, DFM_STOP
, 0, 0);
257 rtn
= BaseWndProc(APPLICATION
, wnd
, CLOSE_WINDOW
, 0, 0);
259 DisplayModified
= FALSE
;
260 ApplicationWindow
= NULL
;
264 /* --- APPLICATION Window Class window processing module --- */
265 int ApplicationProc(DFWINDOW wnd
, DFMESSAGE msg
, PARAM p1
, PARAM p2
)
270 return CreateWindowMsg(wnd
);
271 case DFM_HIDE_WINDOW
:
276 AddStatusMsg(wnd
, p1
);
279 if ((int)p1
== (inFocus
!= wnd
)) {
280 SetFocusMsg(wnd
, (BOOL
) p1
);
285 SizeMsg(wnd
, p1
, p2
);
287 #ifdef INCLUDE_MINIMIZE
292 return KeyboardMsg(wnd
, p1
, p2
);
294 ShiftChangedMsg(wnd
, p1
);
297 if (isVisible(wnd
)) {
298 #ifdef INCLUDE_WINDOWOPTIONS
299 int cl
= cfg
.Texture
? APPLCHAR
: ' ';
303 ClearWindow(wnd
, (DFRECT
*)p1
, cl
);
307 CommandMsg(wnd
, p1
, p2
);
310 return CloseWindowMsg(wnd
);
314 return BaseWndProc(APPLICATION
, wnd
, msg
, p1
, p2
);
317 #ifdef INCLUDE_SHELLDOS
318 static void SwitchCursor(void)
320 DfSendMessage(NULL
, SAVE_CURSOR
, 0, 0);
322 DfSendMessage(NULL
, RESTORE_CURSOR
, 0, 0);
325 /* ------- Shell out to DOS ---------- */
326 static void ShellDOS(DFWINDOW wnd
)
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
, SHOW_WINDOW
, 0, 0);
337 DfSendMessage(oldFocus
, SETFOCUS
, TRUE
, 0);
341 /* -------- Create the menu bar -------- */
342 static void DfCreateMenu(DFWINDOW wnd
)
344 AddAttribute(wnd
, HASMENUBAR
);
345 if (wnd
->MenuBarWnd
!= NULL
)
346 DfSendMessage(wnd
->MenuBarWnd
, CLOSE_WINDOW
, 0, 0);
347 wnd
->MenuBarWnd
= DfCreateWindow(MENUBAR
,
357 DfSendMessage(wnd
->MenuBarWnd
,BUILDMENU
,
358 (PARAM
)wnd
->extension
,0);
359 AddAttribute(wnd
->MenuBarWnd
, VISIBLE
);
362 /* ----------- Create the status bar ------------- */
363 static void CreateStatusBar(DFWINDOW wnd
)
365 if (wnd
->StatusBar
!= NULL
) {
366 DfSendMessage(wnd
->StatusBar
, CLOSE_WINDOW
, 0, 0);
367 wnd
->StatusBar
= NULL
;
369 if (TestAttribute(wnd
, HASSTATUSBAR
)) {
370 wnd
->StatusBar
= DfCreateWindow(STATUSBAR
,
380 AddAttribute(wnd
->StatusBar
, VISIBLE
);
384 #ifdef INCLUDE_MULTI_WINDOWS
385 /* -------- return the name of a document window ------- */
386 static char *WindowName(DFWINDOW wnd
)
388 if (GetTitle(wnd
) == NULL
)
390 if (GetClass(wnd
) == DIALOG
)
391 return ((DBOX
*)(wnd
->extension
))->HelpName
;
396 return GetTitle(wnd
);
399 /* ----------- Prepare the Window menu ------------ */
400 void PrepWindowMenu(void *w
, struct Menu
*mnu
)
403 struct PopDown
*p0
= mnu
->Selections
;
404 struct PopDown
*pd
= mnu
->Selections
+ 2;
405 struct PopDown
*ca
= mnu
->Selections
+ 13;
412 if (GetClass(wnd
) != APPLICATION
)
416 /* point to the APPLICATION window */
417 if (ApplicationWindow
== NULL
)
420 cwnd
= FirstWindow(ApplicationWindow
);
421 /* get the first 9 document windows */
422 while (cwnd
!= NULL
&& MenuNo
< 9)
424 if (GetClass(cwnd
) != MENUBAR
&&
425 GetClass(cwnd
) != 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
|= CHECKED
;
434 mnu
->Selection
= MenuNo
+2;
437 pd
->Attrib
&= ~CHECKED
;
441 cwnd
= NextWindow(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
,PARAM p1
,PARAM p2
)
463 case INITIATE_DIALOG
: {
465 DFWINDOW cwnd
= ControlWindow(&Windows
,ID_WINDOWLIST
);
469 wnd1
= FirstWindow(ApplicationWindow
);
470 while (wnd1
!= NULL
) {
471 if (wnd1
!= wnd
&& GetClass(wnd1
) != MENUBAR
&&
472 GetClass(wnd1
) != STATUSBAR
) {
473 if (wnd1
== oldFocus
)
475 DfSendMessage(cwnd
, ADDTEXT
,
476 (PARAM
) WindowName(wnd1
), 0);
479 wnd1
= NextWindow(wnd1
);
481 DfSendMessage(cwnd
, LB_SETSELECTION
, WindowSel
, 0);
482 AddAttribute(cwnd
, VSCROLLBAR
);
483 DfPostMessage(cwnd
, SHOW_WINDOW
, 0, 0);
490 WindowSel
= DfSendMessage(
491 ControlWindow(&Windows
,
493 LB_CURRENTSELECTION
, 0, 0);
496 if ((int) p2
== LB_CHOOSE
)
497 DfSendMessage(wnd
, DFM_COMMAND
, ID_OK
, 0);
506 return DefaultWndProc(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
= FirstWindow(wnd
);
523 if (GetClass(cwnd
) != MENUBAR
&&
524 GetClass(cwnd
) != STATUSBAR
)
527 cwnd
= NextWindow(cwnd
);
530 DfSendMessage(cwnd
, SETFOCUS
, TRUE
, 0);
531 if (cwnd
->condition
== ISMINIMIZED
)
532 DfSendMessage(cwnd
, RESTORE
, 0, 0);
536 /* ----- Close all document windows ----- */
537 static void CloseAll(DFWINDOW wnd
, int closing
)
541 DfSendMessage(wnd
, SETFOCUS
, TRUE
, 0);
542 wnd1
= LastWindow(wnd
);
545 wnd2
= PrevWindow(wnd1
);
546 if (GetClass(wnd1
) != MENUBAR
&& GetClass(wnd1
) != STATUSBAR
)
549 DfSendMessage(wnd1
, CLOSE_WINDOW
, 0, 0);
554 DfSendMessage(wnd
, PAINT
, 0, 0);
557 #endif /* #ifdef INCLUDE_MULTI_WINDOWS */
559 static void DoWindowColors(DFWINDOW wnd
)
563 InitWindowColors(wnd
);
564 cwnd
= FirstWindow(wnd
);
567 DoWindowColors(cwnd
);
568 if (GetClass(cwnd
) == TEXT
&& GetText(cwnd
) != NULL
)
569 DfSendMessage(cwnd
, CLEARTEXT
, 0, 0);
570 cwnd
= NextWindow(cwnd
);
574 /* set up colors for the application window */
575 static void SelectColors(DFWINDOW wnd
)
577 memcpy(cfg
.clr
, color
, sizeof color
);
582 #ifdef INCLUDE_WINDOWOPTIONS
584 /* ----- select the screen texture ----- */
585 static void SelectTexture(void)
587 cfg
.Texture
= CheckBoxSetting(&Display
, ID_TEXTURE
);
590 /* -- select whether the application screen has a border -- */
591 static void SelectBorder(DFWINDOW wnd
)
593 cfg
.Border
= CheckBoxSetting(&Display
, ID_BORDER
);
595 AddAttribute(wnd
, HASBORDER
);
597 ClearAttribute(wnd
, HASBORDER
);
600 /* select whether the application screen has a status bar */
601 static void SelectStatusBar(DFWINDOW wnd
)
603 cfg
.StatusBar
= CheckBoxSetting(&Display
, ID_STATUSBAR
);
605 AddAttribute(wnd
, HASSTATUSBAR
);
607 ClearAttribute(wnd
, HASSTATUSBAR
);
610 /* select whether the application screen has a title bar */
611 static void SelectTitle(DFWINDOW wnd
)
613 cfg
.Title
= CheckBoxSetting(&Display
, ID_TITLE
);
615 AddAttribute(wnd
, HASTITLEBAR
);
617 ClearAttribute(wnd
, HASTITLEBAR
);