Sync to trunk HEAD (r43416)
[reactos.git] / rosapps / dflat32 / sysmenu.c
1 /* ------------- sysmenu.c ------------ */
2
3 #include "dflat.h"
4
5 int DfSystemMenuProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
6 {
7 int mx, my;
8 DFWINDOW wnd1;
9 switch (msg) {
10 case DFM_CREATE_WINDOW:
11 wnd->holdmenu = DfActiveMenuBar;
12 DfActiveMenuBar = &DfSystemMenu;
13 DfSystemMenu.PullDown[0].Selection = 0;
14 break;
15 case DFM_LEFT_BUTTON:
16 wnd1 = DfGetParent(wnd);
17 mx = (int) p1 - DfGetLeft(wnd1);
18 my = (int) p2 - DfGetTop(wnd1);
19 if (DfHitControlBox(wnd1, mx, my))
20 return TRUE;
21 break;
22 case DFM_LB_CHOOSE:
23 DfPostMessage(wnd, DFM_CLOSE_WINDOW, 0, 0);
24 break;
25 case DOUBLE_CLICK:
26 if (p2 == DfGetTop(DfGetParent(wnd))) {
27 DfPostMessage(DfGetParent(wnd), msg, p1, p2);
28 DfSendMessage(wnd, DFM_CLOSE_WINDOW, TRUE, 0);
29 }
30 return TRUE;
31 case DFM_SHIFT_CHANGED:
32 return TRUE;
33 case DFM_CLOSE_WINDOW:
34 DfActiveMenuBar = wnd->holdmenu;
35 break;
36 default:
37 break;
38 }
39 return DfDefaultWndProc(wnd, msg, p1, p2);
40 }
41
42 /* ------- Build a system menu -------- */
43 void DfBuildSystemMenu(DFWINDOW wnd)
44 {
45 int lf, tp, ht, wd;
46 DFWINDOW SystemMenuWnd;
47
48 DfSystemMenu.PullDown[0].Selections[6].Accelerator =
49 (DfGetClass(wnd) == DF_APPLICATION) ? DF_ALT_F4 : DF_CTRL_F4;
50
51 lf = DfGetLeft(wnd)+1;
52 tp = DfGetTop(wnd)+1;
53 ht = DfMenuHeight(DfSystemMenu.PullDown[0].Selections);
54 wd = DfMenuWidth(DfSystemMenu.PullDown[0].Selections);
55
56 if (lf+wd > DfGetScreenWidth()-1)
57 lf = (DfGetScreenWidth()-1) - wd;
58 if (tp+ht > DfGetScreenHeight()-2)
59 tp = (DfGetScreenHeight()-2) - ht;
60
61 SystemMenuWnd = DfDfCreateWindow(DF_POPDOWNMENU, NULL,
62 lf,tp,ht,wd,NULL,wnd,DfSystemMenuProc, 0);
63
64 #ifdef INCLUDE_RESTORE
65 if (wnd->condition == DF_SRESTORED)
66 DfDeactivateCommand(&DfSystemMenu, DF_ID_SYSRESTORE);
67 else
68 DfActivateCommand(&DfSystemMenu, DF_ID_SYSRESTORE);
69 #endif
70
71 if (DfTestAttribute(wnd, DF_MOVEABLE)
72 #ifdef INCLUDE_MAXIMIZE
73 && wnd->condition != DF_ISMAXIMIZED
74 #endif
75 )
76 DfActivateCommand(&DfSystemMenu, DF_ID_SYSMOVE);
77 else
78 DfDeactivateCommand(&DfSystemMenu, DF_ID_SYSMOVE);
79
80 if (wnd->condition != DF_SRESTORED ||
81 DfTestAttribute(wnd, DF_SIZEABLE) == FALSE)
82 DfDeactivateCommand(&DfSystemMenu, DF_ID_SYSSIZE);
83 else
84 DfActivateCommand(&DfSystemMenu, DF_ID_SYSSIZE);
85
86 #ifdef INCLUDE_MINIMIZE
87 if (wnd->condition == DF_ISMINIMIZED ||
88 DfTestAttribute(wnd, DF_MINMAXBOX) == FALSE)
89 DfDeactivateCommand(&DfSystemMenu, DF_ID_SYSMINIMIZE);
90 else
91 DfActivateCommand(&DfSystemMenu, DF_ID_SYSMINIMIZE);
92 #endif
93
94 #ifdef INCLUDE_MAXIMIZE
95 if (wnd->condition != DF_SRESTORED ||
96 DfTestAttribute(wnd, DF_MINMAXBOX) == FALSE)
97 DfDeactivateCommand(&DfSystemMenu, DF_ID_SYSMAXIMIZE);
98 else
99 DfActivateCommand(&DfSystemMenu, DF_ID_SYSMAXIMIZE);
100 #endif
101
102 DfSendMessage(SystemMenuWnd, DFM_BUILD_SELECTIONS,
103 (DF_PARAM) &DfSystemMenu.PullDown[0], 0);
104 DfSendMessage(SystemMenuWnd, DFM_SETFOCUS, TRUE, 0);
105 DfSendMessage(SystemMenuWnd, DFM_SHOW_WINDOW, 0, 0);
106 }
107
108 /* EOF */