Add oleacc to build
[reactos.git] / rosapps / dflat32 / applicat.c
1 /* ------------- applicat.c ------------- */
2
3 #include "dflat.h"
4
5 static BOOL DisplayModified = FALSE;
6 DFWINDOW DfApplicationWindow;
7
8 extern DF_DBOX Display;
9 extern DF_DBOX Windows;
10
11 #ifdef INCLUDE_LOGGING
12 extern DF_DBOX Log;
13 #endif
14
15 #ifdef INCLUDE_SHELLDOS
16 static void ShellDOS(DFWINDOW);
17 #endif
18 static void DfCreateMenu(DFWINDOW);
19 static void CreateStatusBar(DFWINDOW);
20 static void SelectColors(DFWINDOW);
21
22 #ifdef INCLUDE_WINDOWOPTIONS
23 static void SelectTexture(void);
24 static void SelectBorder(DFWINDOW);
25 static void SelectTitle(DFWINDOW);
26 static void SelectStatusBar(DFWINDOW);
27 #endif
28
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);
34 static int WindowSel;
35 static char Menus[9][26] =
36 {
37 "~1. ",
38 "~2. ",
39 "~3. ",
40 "~4. ",
41 "~5. ",
42 "~6. ",
43 "~7. ",
44 "~8. ",
45 "~9. "
46 };
47 #endif
48
49 /* --------------- DFM_CREATE_WINDOW Message -------------- */
50 static int CreateWindowMsg(DFWINDOW wnd)
51 {
52 int rtn;
53
54 DfApplicationWindow = wnd;
55 #ifdef INCLUDE_WINDOWOPTIONS
56 if (DfCfg.Border)
57 DfSetCheckBox(&Display, DF_ID_BORDER);
58 if (DfCfg.Title)
59 DfSetCheckBox(&Display, DF_ID_TITLE);
60 if (DfCfg.StatusBar)
61 DfSetCheckBox(&Display, DF_ID_STATUSBAR);
62 if (DfCfg.Texture)
63 DfSetCheckBox(&Display, DF_ID_TEXTURE);
64 #endif
65 SelectColors(wnd);
66 #ifdef INCLUDE_WINDOWOPTIONS
67 SelectBorder(wnd);
68 SelectTitle(wnd);
69 SelectStatusBar(wnd);
70 #endif
71 rtn = DfBaseWndProc(DF_APPLICATION, wnd, DFM_CREATE_WINDOW, 0, 0);
72 if (wnd->extension != NULL)
73 DfCreateMenu(wnd);
74 CreateStatusBar(wnd);
75 return rtn;
76 }
77
78 /* --------- DFM_ADDSTATUS Message ---------- */
79 static void AddStatusMsg(DFWINDOW wnd, DF_PARAM p1)
80 {
81 if (wnd->StatusBar != NULL) {
82 if (p1 && *(char *)p1)
83 DfSendMessage(wnd->StatusBar, DFM_SETTEXT, p1, 0);
84 else
85 DfSendMessage(wnd->StatusBar, DFM_CLEARTEXT, 0, 0);
86 DfSendMessage(wnd->StatusBar, DFM_PAINT, 0, 0);
87 }
88 }
89
90 /* -------- DFM_SETFOCUS Message -------- */
91 static void SetFocusMsg(DFWINDOW wnd, BOOL p1)
92 {
93 if (p1)
94 DfSendMessage(DfInFocus, DFM_SETFOCUS, FALSE, 0);
95 DfInFocus = p1 ? wnd : NULL;
96 if (DfIsVisible(wnd))
97 DfSendMessage(wnd, DFM_BORDER, 0, 0);
98 else
99 DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
100 }
101
102 /* ------- SIZE Message -------- */
103 static void SizeMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
104 {
105 BOOL WasVisible;
106 WasVisible = DfIsVisible(wnd);
107 if (WasVisible)
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);
112 DfCreateMenu(wnd);
113 CreateStatusBar(wnd);
114 if (WasVisible)
115 DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
116 }
117
118 /* ----------- DFM_KEYBOARD Message ------------ */
119 static int KeyboardMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
120 {
121 if (DfWindowMoving || DfWindowSizing || (int) p1 == DF_F1)
122 return DfBaseWndProc(DF_APPLICATION, wnd, DFM_KEYBOARD, p1, p2);
123 switch ((int) p1) {
124 case DF_ALT_F4:
125 DfPostMessage(wnd, DFM_CLOSE_WINDOW, 0, 0);
126 return TRUE;
127 #ifdef INCLUDE_MULTI_WINDOWS
128 case DF_ALT_F6:
129 DfSetNextFocus();
130 return TRUE;
131 #endif
132 case DF_ALT_HYPHEN:
133 DfBuildSystemMenu(wnd);
134 return TRUE;
135 default:
136 break;
137 }
138 DfPostMessage(wnd->MenuBarWnd, DFM_KEYBOARD, p1, p2);
139 return TRUE;
140 }
141
142 /* --------- DFM_SHIFT_CHANGED Message -------- */
143 static void ShiftChangedMsg(DFWINDOW wnd, DF_PARAM p1)
144 {
145 extern BOOL AltDown;
146 if ((int)p1 & DF_ALTKEY)
147 AltDown = TRUE;
148 else if (AltDown) {
149 AltDown = FALSE;
150 if (wnd->MenuBarWnd != DfInFocus)
151 DfSendMessage(NULL, DFM_HIDE_CURSOR, 0, 0);
152 DfSendMessage(wnd->MenuBarWnd, DFM_KEYBOARD, DF_F10, 0);
153 }
154 }
155
156 /* -------- COMMAND Message ------- */
157 static void CommandMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
158 {
159 switch ((int)p1) {
160 case DF_ID_HELP:
161 DfDisplayHelp(wnd, DFlatApplication);
162 break;
163 case DF_ID_HELPHELP:
164 DfDisplayHelp(wnd, "HelpHelp");
165 break;
166 case DF_ID_EXTHELP:
167 DfDisplayHelp(wnd, "ExtHelp");
168 break;
169 case DF_ID_KEYSHELP:
170 DfDisplayHelp(wnd, "KeysHelp");
171 break;
172 case DF_ID_HELPINDEX:
173 DfDisplayHelp(wnd, "HelpIndex");
174 break;
175 #ifdef TESTING_DFLAT
176 case DF_ID_LOADHELP:
177 DfLoadHelpFile();
178 break;
179 #endif
180 #ifdef INCLUDE_LOGGING
181 case DF_ID_LOG:
182 DfMessageLog(wnd);
183 break;
184 #endif
185 #ifdef INCLUDE_SHELLDOS
186 case DF_ID_DOS:
187 ShellDOS(wnd);
188 break;
189 #endif
190 case DF_ID_EXIT:
191 case DF_ID_SYSCLOSE:
192 DfPostMessage(wnd, DFM_CLOSE_WINDOW, 0, 0);
193 break;
194 case DF_ID_DISPLAY:
195 if (DfDialogBox(wnd, &Display, TRUE, NULL)) {
196 if (DfInFocus == wnd->MenuBarWnd || DfInFocus == wnd->StatusBar)
197 oldFocus = DfApplicationWindow;
198 else
199 oldFocus = DfInFocus;
200 DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
201 SelectColors(wnd);
202 #ifdef INCLUDE_WINDOWOPTIONS
203 SelectBorder(wnd);
204 SelectTitle(wnd);
205 SelectStatusBar(wnd);
206 SelectTexture();
207 #endif
208 DfCreateMenu(wnd);
209 CreateStatusBar(wnd);
210 DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
211 DfSendMessage(oldFocus, DFM_SETFOCUS, TRUE, 0);
212 }
213 break;
214 case DF_ID_SAVEOPTIONS:
215 DfSaveConfig();
216 break;
217 #ifdef INCLUDE_MULTI_WINDOWS
218 case DF_ID_WINDOW:
219 ChooseWindow(wnd, (int)p2-2);
220 break;
221 case DF_ID_CLOSEALL:
222 CloseAll(wnd, FALSE);
223 break;
224 case DF_ID_MOREWINDOWS:
225 MoreWindows(wnd);
226 break;
227 #endif
228 #ifdef INCLUDE_RESTORE
229 case DF_ID_SYSRESTORE:
230 #endif
231 case DF_ID_SYSMOVE:
232 case DF_ID_SYSSIZE:
233 #ifdef INCLUDE_MINIMIZE
234 case DF_ID_SYSMINIMIZE:
235 #endif
236 #ifdef INCLUDE_MAXIMIZE
237 case DF_ID_SYSMAXIMIZE:
238 #endif
239 DfBaseWndProc(DF_APPLICATION, wnd, DFM_COMMAND, p1, p2);
240 break;
241 default:
242 if (DfInFocus != wnd->MenuBarWnd && DfInFocus != wnd)
243 DfPostMessage(DfInFocus, DFM_COMMAND, p1, p2);
244 break;
245 }
246 }
247
248 /* --------- DFM_CLOSE_WINDOW Message -------- */
249 static int CloseWindowMsg(DFWINDOW wnd)
250 {
251 int rtn;
252 #ifdef INCLUDE_MULTI_WINDOWS
253 CloseAll(wnd, TRUE);
254 WindowSel = 0;
255 #endif
256 DfPostMessage(NULL, DFM_STOP, 0, 0);
257 rtn = DfBaseWndProc(DF_APPLICATION, wnd, DFM_CLOSE_WINDOW, 0, 0);
258 DfUnLoadHelpFile();
259 DisplayModified = FALSE;
260 DfApplicationWindow = NULL;
261 return rtn;
262 }
263
264 /* --- DF_APPLICATION Window Class window processing module --- */
265 int DfApplicationProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
266 {
267 switch (msg)
268 {
269 case DFM_CREATE_WINDOW:
270 return CreateWindowMsg(wnd);
271 case DFM_HIDE_WINDOW:
272 if (wnd == DfInFocus)
273 DfInFocus = NULL;
274 break;
275 case DFM_ADDSTATUS:
276 AddStatusMsg(wnd, p1);
277 return TRUE;
278 case DFM_SETFOCUS:
279 if ((int)p1 == (DfInFocus != wnd)) {
280 SetFocusMsg(wnd, (BOOL) p1);
281 return TRUE;
282 }
283 break;
284 case DFM_DFM_SIZE:
285 SizeMsg(wnd, p1, p2);
286 return TRUE;
287 #ifdef INCLUDE_MINIMIZE
288 case DFM_MINIMIZE:
289 return TRUE;
290 #endif
291 case DFM_KEYBOARD:
292 return KeyboardMsg(wnd, p1, p2);
293 case DFM_SHIFT_CHANGED:
294 ShiftChangedMsg(wnd, p1);
295 return TRUE;
296 case DFM_PAINT:
297 if (DfIsVisible(wnd)) {
298 #ifdef INCLUDE_WINDOWOPTIONS
299 int cl = DfCfg.Texture ? DF_APPLCHAR : ' ';
300 #else
301 int cl = DF_APPLCHAR;
302 #endif
303 DfClearWindow(wnd, (DFRECT *)p1, cl);
304 }
305 return TRUE;
306 case DFM_COMMAND:
307 CommandMsg(wnd, p1, p2);
308 return TRUE;
309 case DFM_CLOSE_WINDOW:
310 return CloseWindowMsg(wnd);
311 default:
312 break;
313 }
314 return DfBaseWndProc(DF_APPLICATION, wnd, msg, p1, p2);
315 }
316
317 #ifdef INCLUDE_SHELLDOS
318 static void SwitchCursor(void)
319 {
320 DfSendMessage(NULL, DFM_SAVE_CURSOR, 0, 0);
321 DfSwapCursorStack();
322 DfSendMessage(NULL, DFM_RESTORE_CURSOR, 0, 0);
323 }
324
325 /* ------- Shell out to DOS ---------- */
326 static void ShellDOS(DFWINDOW wnd)
327 {
328 oldFocus = DfInFocus;
329 DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
330 SwitchCursor();
331 printf("To return to %s, execute the DOS exit command.",
332 DFlatApplication);
333 fflush(stdout);
334 _spawnl(P_WAIT, getenv("COMSPEC"), " ", NULL);
335 SwitchCursor();
336 DfSendMessage(wnd, DFM_SHOW_WINDOW, 0, 0);
337 DfSendMessage(oldFocus, DFM_SETFOCUS, TRUE, 0);
338 }
339 #endif
340
341 /* -------- Create the menu bar -------- */
342 static void DfCreateMenu(DFWINDOW wnd)
343 {
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,
348 NULL,
349 DfGetClientLeft(wnd),
350 DfGetClientTop(wnd)-1,
351 1,
352 DfClientWidth(wnd),
353 NULL,
354 wnd,
355 NULL,
356 0);
357 DfSendMessage(wnd->MenuBarWnd,DFM_BUILDMENU,
358 (DF_PARAM)wnd->extension,0);
359 DfAddAttribute(wnd->MenuBarWnd, DF_VISIBLE);
360 }
361
362 /* ----------- Create the status bar ------------- */
363 static void CreateStatusBar(DFWINDOW wnd)
364 {
365 if (wnd->StatusBar != NULL) {
366 DfSendMessage(wnd->StatusBar, DFM_CLOSE_WINDOW, 0, 0);
367 wnd->StatusBar = NULL;
368 }
369 if (DfTestAttribute(wnd, DF_HASSTATUSBAR)) {
370 wnd->StatusBar = DfDfCreateWindow(DF_STATUSBAR,
371 NULL,
372 DfGetClientLeft(wnd),
373 DfGetBottom(wnd),
374 1,
375 DfClientWidth(wnd),
376 NULL,
377 wnd,
378 NULL,
379 0);
380 DfAddAttribute(wnd->StatusBar, DF_VISIBLE);
381 }
382 }
383
384 #ifdef INCLUDE_MULTI_WINDOWS
385 /* -------- return the name of a document window ------- */
386 static char *WindowName(DFWINDOW wnd)
387 {
388 if (DfGetTitle(wnd) == NULL)
389 {
390 if (DfGetClass(wnd) == DF_DIALOG)
391 return ((DF_DBOX *)(wnd->extension))->HelpName;
392 else
393 return "Untitled";
394 }
395 else
396 return DfGetTitle(wnd);
397 }
398
399 /* ----------- Prepare the Window menu ------------ */
400 void DfPrepWindowMenu(void *w, struct DfMenu *mnu)
401 {
402 DFWINDOW wnd = w;
403 struct DfPopDown *p0 = mnu->Selections;
404 struct DfPopDown *pd = mnu->Selections + 2;
405 struct DfPopDown *ca = mnu->Selections + 13;
406 int MenuNo = 0;
407 DFWINDOW cwnd;
408
409 mnu->Selection = 0;
410 oldFocus = NULL;
411
412 if (DfGetClass(wnd) != DF_APPLICATION)
413 {
414 oldFocus = wnd;
415
416 /* point to the DF_APPLICATION window */
417 if (DfApplicationWindow == NULL)
418 return;
419
420 cwnd = DfFirstWindow(DfApplicationWindow);
421 /* get the first 9 document windows */
422 while (cwnd != NULL && MenuNo < 9)
423 {
424 if (DfGetClass(cwnd) != DF_MENUBAR &&
425 DfGetClass(cwnd) != DF_STATUSBAR)
426 {
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)
431 {
432 /* mark the current document */
433 pd->Attrib |= DF_CHECKED;
434 mnu->Selection = MenuNo+2;
435 }
436 else
437 pd->Attrib &= ~DF_CHECKED;
438 pd++;
439 MenuNo++;
440 }
441 cwnd = DfNextWindow(cwnd);
442 }
443 }
444
445 if (MenuNo)
446 p0->SelectionTitle = "~Close all";
447 else
448 p0->SelectionTitle = NULL;
449
450 if (MenuNo >= 9)
451 {
452 *pd++ = *ca;
453 if (mnu->Selection == 0)
454 mnu->Selection = 11;
455 }
456 pd->SelectionTitle = NULL;
457 }
458
459 /* window processing module for the More Windows dialog box */
460 static int WindowPrep(DFWINDOW wnd,DFMESSAGE msg,DF_PARAM p1,DF_PARAM p2)
461 {
462 switch (msg) {
463 case DFM_INITIATE_DIALOG: {
464 DFWINDOW wnd1;
465 DFWINDOW cwnd = DfControlWindow(&Windows,DF_ID_WINDOWLIST);
466 int sel = 0;
467 if (cwnd == NULL)
468 return FALSE;
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)
474 WindowSel = sel;
475 DfSendMessage(cwnd, DFM_ADDTEXT,
476 (DF_PARAM) WindowName(wnd1), 0);
477 sel++;
478 }
479 wnd1 = DfNextWindow(wnd1);
480 }
481 DfSendMessage(cwnd, DFM_LB_SETSELECTION, WindowSel, 0);
482 DfAddAttribute(cwnd, DF_VSCROLLBAR);
483 DfPostMessage(cwnd, DFM_SHOW_WINDOW, 0, 0);
484 break;
485 }
486 case DFM_COMMAND:
487 switch ((int) p1) {
488 case DF_ID_OK:
489 if ((int)p2 == 0)
490 WindowSel = DfSendMessage(
491 DfControlWindow(&Windows,
492 DF_ID_WINDOWLIST),
493 DFM_LB_CURRENTSELECTION, 0, 0);
494 break;
495 case DF_ID_WINDOWLIST:
496 if ((int) p2 == DFM_LB_CHOOSE)
497 DfSendMessage(wnd, DFM_COMMAND, DF_ID_OK, 0);
498 break;
499 default:
500 break;
501 }
502 break;
503 default:
504 break;
505 }
506 return DfDefaultWndProc(wnd, msg, p1, p2);
507 }
508
509 /* ---- the More Windows command on the Window menu ---- */
510 static void MoreWindows(DFWINDOW wnd)
511 {
512 if (DfDialogBox(wnd, &Windows, TRUE, WindowPrep))
513 ChooseWindow(wnd, WindowSel);
514 }
515
516 /* ----- user chose a window from the Window menu
517 or the More Window dialog box ----- */
518 static void ChooseWindow(DFWINDOW wnd, int WindowNo)
519 {
520 DFWINDOW cwnd = DfFirstWindow(wnd);
521 while (cwnd != NULL)
522 {
523 if (DfGetClass(cwnd) != DF_MENUBAR &&
524 DfGetClass(cwnd) != DF_STATUSBAR)
525 if (WindowNo-- == 0)
526 break;
527 cwnd = DfNextWindow(cwnd);
528 }
529 if (cwnd != NULL) {
530 DfSendMessage(cwnd, DFM_SETFOCUS, TRUE, 0);
531 if (cwnd->condition == DF_ISMINIMIZED)
532 DfSendMessage(cwnd, DFM_RESTORE, 0, 0);
533 }
534 }
535
536 /* ----- Close all document windows ----- */
537 static void CloseAll(DFWINDOW wnd, int closing)
538 {
539 DFWINDOW wnd1, wnd2;
540
541 DfSendMessage(wnd, DFM_SETFOCUS, TRUE, 0);
542 wnd1 = DfLastWindow(wnd);
543 while (wnd1 != NULL)
544 {
545 wnd2 = DfPrevWindow(wnd1);
546 if (DfGetClass(wnd1) != DF_MENUBAR && DfGetClass(wnd1) != DF_STATUSBAR)
547 {
548 DfClearVisible(wnd1);
549 DfSendMessage(wnd1, DFM_CLOSE_WINDOW, 0, 0);
550 }
551 wnd1 = wnd2;
552 }
553 if (!closing)
554 DfSendMessage(wnd, DFM_PAINT, 0, 0);
555 }
556
557 #endif /* #ifdef INCLUDE_MULTI_WINDOWS */
558
559 static void DoWindowColors(DFWINDOW wnd)
560 {
561 DFWINDOW cwnd;
562
563 DfInitWindowColors(wnd);
564 cwnd = DfFirstWindow(wnd);
565 while (cwnd != NULL)
566 {
567 DoWindowColors(cwnd);
568 if (DfGetClass(cwnd) == DF_TEXT && DfGetText(cwnd) != NULL)
569 DfSendMessage(cwnd, DFM_CLEARTEXT, 0, 0);
570 cwnd = DfNextWindow(cwnd);
571 }
572 }
573
574 /* set up colors for the application window */
575 static void SelectColors(DFWINDOW wnd)
576 {
577 memcpy(DfCfg.clr, DfColor, sizeof DfColor);
578 DoWindowColors(wnd);
579 }
580
581
582 #ifdef INCLUDE_WINDOWOPTIONS
583
584 /* ----- select the screen texture ----- */
585 static void SelectTexture(void)
586 {
587 DfCfg.Texture = DfCheckBoxSetting(&Display, DF_ID_TEXTURE);
588 }
589
590 /* -- select whether the application screen has a border -- */
591 static void SelectBorder(DFWINDOW wnd)
592 {
593 DfCfg.Border = DfCheckBoxSetting(&Display, DF_ID_BORDER);
594 if (DfCfg.Border)
595 DfAddAttribute(wnd, DF_HASBORDER);
596 else
597 DfClearAttribute(wnd, DF_HASBORDER);
598 }
599
600 /* select whether the application screen has a status bar */
601 static void SelectStatusBar(DFWINDOW wnd)
602 {
603 DfCfg.StatusBar = DfCheckBoxSetting(&Display, DF_ID_STATUSBAR);
604 if (DfCfg.StatusBar)
605 DfAddAttribute(wnd, DF_HASSTATUSBAR);
606 else
607 DfClearAttribute(wnd, DF_HASSTATUSBAR);
608 }
609
610 /* select whether the application screen has a title bar */
611 static void SelectTitle(DFWINDOW wnd)
612 {
613 DfCfg.Title = DfCheckBoxSetting(&Display, DF_ID_TITLE);
614 if (DfCfg.Title)
615 DfAddAttribute(wnd, DF_HASTITLEBAR);
616 else
617 DfClearAttribute(wnd, DF_HASTITLEBAR);
618 }
619
620 #endif
621
622 /* EOF */