1 enum {
2 IDEXIT = 9999
3 };
4
5 class TopWindow : public Ctrl {
6 public:
7 virtual Size GetMinSize() const;
8 virtual Size GetStdSize() const;
9 virtual void Activate();
10 virtual void Deactivate();
11 virtual bool Accept();
12 virtual void Reject();
13 virtual void Paint(Draw& w);
14 virtual bool IsShowEnabled() const;
15 virtual bool Key(dword key, int count);
16 virtual void Close();
17 virtual String GetDesc() const;
18 virtual void ChildGotFocus();
19 virtual void SetMinSize(Size sz);
20
21 public:
22 struct TopStyle : ChStyle<TopStyle> {
23 Value background;
24 };
25
26 protected:
27 enum {
28 TIMEID_DEFSYNCTITLE = Ctrl::TIMEID_COUNT,
29 TIMEID_COUNT,
30 };
31
32 private:
33 struct Abreak : Pte<Abreak> {
34 int ID;
35 TopWindow *dlg;
36
AcceptAbreak37 void Accept() { dlg->AcceptBreak(ID); }
RejectAbreak38 void Reject() { dlg->RejectBreak(ID); }
BreakAbreak39 void Break() { dlg->Break(ID); }
40 };
41
42 Array<Abreak> action;
43 Ptr<Ctrl> activefocus;
44 String backup;
45 PaintRect background;
46 Size minsize;
47 bool dokeys;
48 bool fullscreen;
49
50 byte center:2;
51
52 void PlaceFocus();
53 void ActiveFocus0(Ctrl& ctrl);
54 Abreak *FindAddAction(int ID);
55 Abreak *FindAction(int ID);
56
57 Rect overlapped;
58
59 void SyncSizeHints();
60 void SyncTitle();
61 void SyncCaption();
62
63 void SetupRect(Ctrl *owner);
64
65 void FixIcons();
66
67 void DefaultBreak();
68
69 enum { MINIMIZED, MAXIMIZED, OVERLAPPED };
70
71 WString title;
72 bool minimizebox:1;
73 bool maximizebox:1;
74 bool noclosebox:1;
75 bool sizeable:1;
76 bool tool:1;
77 bool frameless:1;
78 bool urgent:1;
79 bool close_rejects:1;
80 byte state;
81 Image icon, largeicon;
82
83 const TopStyle *st;
84
85 void GuiPlatformConstruct();
86 void GuiPlatformDestruct();
87
88 #ifdef GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE
89 #include GUIPLATFORM_TOPWINDOW_DECLS_INCLUDE
90 #else
91 GUIPLATFORM_TOPWINDOW_DECLS
92 #endif
93
94 public:
95 virtual void ShutdownWindow();
96
97 Event<> WhenClose;
98
99 void Backup();
100 void Restore();
101
102 void Break(int ID = IDEXIT);
103 bool AcceptBreak(int ID);
104 void RejectBreak(int ID);
105
106 void WorkAreaTrim();
107
108 Callback Breaker(int ID = IDEXIT);
109 Callback Acceptor(int ID);
110 Callback Rejector(int ID);
111
112 TopWindow& Breaker(Ctrl& m, int ID = -1);
113 TopWindow& Acceptor(Ctrl& m, int ID);
114 TopWindow& Rejector(Ctrl& m, int ID);
115
NoCenter()116 TopWindow& NoCenter() { center = 0; return *this; }
CenterOwner()117 TopWindow& CenterOwner() { center = 1; return *this; }
CenterScreen()118 TopWindow& CenterScreen() { center = 2; return *this; }
119
120 void Open(Ctrl *owner);
121 void Open();
122 void OpenMain();
123 int Run(bool appmodal = false);
RunAppModal()124 int RunAppModal() { return Run(true); }
125 int Execute();
ExecuteOK()126 bool ExecuteOK() { return Execute() == IDOK; }
ExecuteCancel()127 bool ExecuteCancel() { return Execute() == IDCANCEL; }
128
129 void Minimize(bool effect = false);
130 void Maximize(bool effect = false);
131 void Overlap(bool effect = false);
132
IsMaximized()133 bool IsMaximized() const { return state == MAXIMIZED; }
IsMinimized()134 bool IsMinimized() const { return state == MINIMIZED; }
IsOverlapped()135 bool IsOverlapped() const { return state == OVERLAPPED; }
136
ActiveFocus(Ctrl & ctrl)137 TopWindow& ActiveFocus(Ctrl& ctrl) { ActiveFocus0(ctrl); return *this; }
138
139 TopWindow& Title(const WString& _title);
140 TopWindow& Title(const char *s);
GetTitle()141 const WString& GetTitle() const { return title; }
142 TopWindow& Sizeable(bool b = true);
NoSizeable()143 TopWindow& NoSizeable() { return Sizeable(false); }
IsSizeable()144 bool IsSizeable() const { return sizeable; }
145 TopWindow& MinimizeBox(bool b = true);
146 TopWindow& MaximizeBox(bool b = true);
147 TopWindow& Zoomable(bool b = true) { MinimizeBox(b); return MaximizeBox(b); }
NoZoomable()148 TopWindow& NoZoomable() { return Zoomable(false); }
IsZoomable()149 bool IsZoomable() const { return maximizebox; }
150 TopWindow& Background(const PaintRect& prect);
GetBackground()151 const PaintRect& GetBackground() const { return background; }
152 TopWindow& ToolWindow(bool b = true);
NoToolWindow()153 TopWindow& NoToolWindow() { return ToolWindow(false); }
IsToolWindow()154 bool IsToolWindow() const { return tool; }
155 TopWindow& TopMost(bool b = true, bool stay_top = true);
NoTopMost()156 TopWindow& NoTopMost() { return TopMost(false); }
157 bool IsTopMost() const;
158 TopWindow& FullScreen(bool b = true);
IsFullScreen()159 bool IsFullScreen() const { return fullscreen; }
160 TopWindow& FrameLess(bool b = true);
IsFrameLess()161 bool IsFrameLess() const { return frameless; }
162 TopWindow& Urgent(bool b = true);
IsUrgent()163 bool IsUrgent() const { return urgent; }
NoAccessKeysDistribution()164 TopWindow& NoAccessKeysDistribution() { dokeys = false; return *this; }
165 TopWindow& NoCloseBox(bool b = true) { noclosebox = b; return *this; }
166 TopWindow& CloseBoxRejects(bool b = true) { close_rejects = b; return *this; }
167
168 TopWindow& Icon(const Image& m);
169 TopWindow& LargeIcon(const Image& m);
170 TopWindow& Icon(const Image& smallicon, const Image& largeicon);
171
172 static const TopStyle& StyleDefault();
173 TopWindow& SetStyle(const TopStyle& s);
174
GetIcon()175 Image GetIcon() const { return icon; }
GetLargeIcon()176 Image GetLargeIcon() const { return largeicon; }
177
178 void SerializePlacement(Stream& s, bool reminimize = false);
179
180 static void ShutdownWindows();
181
182 typedef TopWindow CLASSNAME;
183
184 TopWindow();
185 ~TopWindow();
186 };
187
188 void Maxisize(TopWindow& win, int screencxmax);
189
190 void ArrangeOKCancel(Ctrl& ok, Ctrl& cancel);
191
192 int SwapOKCancel();
193 void SwapOKCancel_Write(int b);
194
195 void SetLayout_Size(Ctrl& ctrl, Size sz);
196 void SetLayout_Size(Ctrl& ctrl, int cx, int cy);
197
198 template <class L>
InitLayout(Ctrl & ctrl,L & layout)199 void InitLayout(Ctrl& ctrl, L& layout)
200 {
201 InitLayout(ctrl, layout, layout, layout);
202 }
203
204 template <class T>
CtrlLayout(T & ctrl)205 void CtrlLayout(T& ctrl) {
206 InitLayout(ctrl, ctrl, ctrl, ctrl);
207 Size sz = T::GetLayoutSize();
208 SetLayout_Size(ctrl, sz);
209 ctrl.SetRect(sz);
210 }
211
212 template <class T>
CtrlLayout(T & ctrl,const char * title)213 void CtrlLayout(T& ctrl, const char *title) {
214 CtrlLayout(ctrl);
215 ctrl.Title(title);
216 }
217
218 template <class T>
CtrlLayoutOK(T & ctrl,const char * title)219 void CtrlLayoutOK(T& ctrl, const char *title) {
220 CtrlLayout(ctrl, title);
221 ctrl.Acceptor(ctrl.ok, IDOK);
222 ctrl.ok.Ok();
223 }
224
225 template <class T>
CtrlLayoutCancel(T & ctrl,const char * title)226 void CtrlLayoutCancel(T& ctrl, const char *title) {
227 CtrlLayout(ctrl, title);
228 ctrl.Rejector(ctrl.cancel, IDCANCEL);
229 ctrl.cancel.Cancel();
230 }
231
232 template <class T>
CtrlLayoutOKCancel(T & ctrl,const char * title)233 void CtrlLayoutOKCancel(T& ctrl, const char *title) {
234 CtrlLayoutOK(ctrl, title);
235 ctrl.Rejector(ctrl.cancel, IDCANCEL);
236 ctrl.cancel.Cancel();
237 ArrangeOKCancel(ctrl.ok, ctrl.cancel);
238 }
239
240 template <class T>
CtrlLayoutExit(T & ctrl,const char * title)241 void CtrlLayoutExit(T& ctrl, const char *title) {
242 CtrlLayout(ctrl, title);
243 ctrl.Acceptor(ctrl.exit, IDEXIT);
244 ctrl.exit.Exit();
245 }
246