]>
Commit | Line | Data |
---|---|---|
ec4f95c4 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/toplevel.h | |
3 | // Purpose: declares wxTopLevelWindow class, the base class for all | |
4 | // top level windows (such as frames and dialogs) | |
7d9f12f3 | 5 | // Author: Vadim Zeitlin, Vaclav Slavik |
ec4f95c4 VZ |
6 | // Modified by: |
7 | // Created: 06.08.01 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
77ffb593 | 10 | // Vaclav Slavik <vaclav@wxwidgets.org> |
65571936 | 11 | // Licence: wxWindows licence |
ec4f95c4 VZ |
12 | /////////////////////////////////////////////////////////////////////////////// |
13 | ||
7d9f12f3 VS |
14 | #ifndef _WX_TOPLEVEL_BASE_H_ |
15 | #define _WX_TOPLEVEL_BASE_H_ | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
18 | // headers | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
42b0d8b9 | 21 | #include "wx/nonownedwnd.h" |
f618020a | 22 | #include "wx/iconbndl.h" |
049908c5 | 23 | #include "wx/containr.h" |
7d9f12f3 | 24 | |
63ec432b | 25 | // the default names for various classes |
53a2db12 | 26 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFrameNameStr[]; |
7d9f12f3 | 27 | |
b5dbe15d | 28 | class WXDLLIMPEXP_FWD_CORE wxTopLevelWindowBase; |
7d9f12f3 | 29 | |
b22d16ad VS |
30 | // ---------------------------------------------------------------------------- |
31 | // constants | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
8b5ef6cf VZ |
34 | // style common to both wxFrame and wxDialog |
35 | #define wxSTAY_ON_TOP 0x8000 | |
36 | #define wxICONIZE 0x4000 | |
37 | #define wxMINIMIZE wxICONIZE | |
38 | #define wxMAXIMIZE 0x2000 | |
39 | #define wxCLOSE_BOX 0x1000 | |
40 | ||
41 | #define wxSYSTEM_MENU 0x0800 | |
42 | #define wxMINIMIZE_BOX 0x0400 | |
43 | #define wxMAXIMIZE_BOX 0x0200 | |
44 | #define wxTINY_CAPTION_HORIZ 0x0100 | |
45 | #define wxTINY_CAPTION_VERT 0x0080 | |
46 | #define wxRESIZE_BORDER 0x0040 | |
47 | ||
1c067fe3 WS |
48 | #if WXWIN_COMPATIBILITY_2_6 |
49 | ||
50 | // deprecated versions defined for compatibility reasons | |
51 | #define wxRESIZE_BOX wxMAXIMIZE_BOX | |
52 | #define wxTHICK_FRAME wxRESIZE_BORDER | |
53 | ||
54 | // obsolete styles, unused any more | |
55 | #define wxDIALOG_MODAL 0 | |
56 | #define wxDIALOG_MODELESS 0 | |
57 | #define wxNO_3D 0 | |
58 | #define wxUSER_COLOURS 0 | |
59 | ||
60 | #endif // WXWIN_COMPATIBILITY_2_6 | |
8b5ef6cf VZ |
61 | |
62 | // default style | |
63 | // | |
64 | // under Windows CE (at least when compiling with eVC 4) we should create | |
65 | // top level windows without any styles at all for them to appear | |
66 | // "correctly", i.e. as full screen windows with a "hide" button (same as | |
67 | // "close" but round instead of squared and just hides the applications | |
68 | // instead of closing it) in the title bar | |
a9928e9d | 69 | #if defined(__WXWINCE__) |
cb719f2e WS |
70 | #if defined(__SMARTPHONE__) |
71 | #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE) | |
a9928e9d | 72 | #elif defined(__WINCE_STANDARDSDK__) |
cb719f2e WS |
73 | #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE|wxCLOSE_BOX) |
74 | #else | |
30dfe2ff | 75 | #define wxDEFAULT_FRAME_STYLE (wxNO_BORDER) |
cb719f2e | 76 | #endif |
8b5ef6cf VZ |
77 | #else // !__WXWINCE__ |
78 | #define wxDEFAULT_FRAME_STYLE \ | |
79 | (wxSYSTEM_MENU | \ | |
80 | wxRESIZE_BORDER | \ | |
81 | wxMINIMIZE_BOX | \ | |
82 | wxMAXIMIZE_BOX | \ | |
83 | wxCLOSE_BOX | \ | |
84 | wxCAPTION | \ | |
85 | wxCLIP_CHILDREN) | |
86 | #endif | |
87 | ||
88 | ||
7d9f12f3 | 89 | // Dialogs are created in a special way |
21f4383a | 90 | #define wxTOPLEVEL_EX_DIALOG 0x00000008 |
7d9f12f3 VS |
91 | |
92 | // Styles for ShowFullScreen | |
93 | // (note that wxTopLevelWindow only handles wxFULLSCREEN_NOBORDER and | |
94 | // wxFULLSCREEN_NOCAPTION; the rest is handled by wxTopLevelWindow) | |
b22d16ad VS |
95 | enum |
96 | { | |
97 | wxFULLSCREEN_NOMENUBAR = 0x0001, | |
98 | wxFULLSCREEN_NOTOOLBAR = 0x0002, | |
99 | wxFULLSCREEN_NOSTATUSBAR = 0x0004, | |
100 | wxFULLSCREEN_NOBORDER = 0x0008, | |
101 | wxFULLSCREEN_NOCAPTION = 0x0010, | |
d4597e13 VZ |
102 | |
103 | wxFULLSCREEN_ALL = wxFULLSCREEN_NOMENUBAR | wxFULLSCREEN_NOTOOLBAR | | |
104 | wxFULLSCREEN_NOSTATUSBAR | wxFULLSCREEN_NOBORDER | | |
b22d16ad VS |
105 | wxFULLSCREEN_NOCAPTION |
106 | }; | |
107 | ||
dc92adaf VZ |
108 | // Styles for RequestUserAttention |
109 | enum | |
110 | { | |
111 | wxUSER_ATTENTION_INFO = 1, | |
112 | wxUSER_ATTENTION_ERROR = 2 | |
113 | }; | |
114 | ||
ec4f95c4 VZ |
115 | // ---------------------------------------------------------------------------- |
116 | // wxTopLevelWindow: a top level (as opposed to child) window | |
117 | // ---------------------------------------------------------------------------- | |
118 | ||
53a2db12 | 119 | class WXDLLIMPEXP_CORE wxTopLevelWindowBase : public wxNonOwnedWindow |
ec4f95c4 VZ |
120 | { |
121 | public: | |
7d9f12f3 VS |
122 | // construction |
123 | wxTopLevelWindowBase(); | |
799ea011 | 124 | virtual ~wxTopLevelWindowBase(); |
b22d16ad | 125 | |
7d9f12f3 VS |
126 | // top level wnd state |
127 | // -------------------- | |
128 | ||
cb719f2e WS |
129 | // maximize = true => maximize, otherwise - restore |
130 | virtual void Maximize(bool maximize = true) = 0; | |
7d9f12f3 VS |
131 | |
132 | // undo Maximize() or Iconize() | |
133 | virtual void Restore() = 0; | |
134 | ||
cb719f2e WS |
135 | // iconize = true => iconize, otherwise - restore |
136 | virtual void Iconize(bool iconize = true) = 0; | |
7d9f12f3 | 137 | |
cb719f2e | 138 | // return true if the frame is maximized |
7d9f12f3 VS |
139 | virtual bool IsMaximized() const = 0; |
140 | ||
979a0320 WS |
141 | // return true if the frame is always maximized |
142 | // due to native guidelines or current policy | |
143 | virtual bool IsAlwaysMaximized() const; | |
144 | ||
cb719f2e | 145 | // return true if the frame is iconized |
7d9f12f3 VS |
146 | virtual bool IsIconized() const = 0; |
147 | ||
148 | // get the frame icon | |
ea098413 | 149 | wxIcon GetIcon() const; |
f618020a MB |
150 | |
151 | // get the frame icons | |
152 | const wxIconBundle& GetIcons() const { return m_icons; } | |
7d9f12f3 | 153 | |
ea098413 VZ |
154 | // set the frame icon: implemented in terms of SetIcons() |
155 | void SetIcon(const wxIcon& icon); | |
f618020a MB |
156 | |
157 | // set the frame icons | |
ea098413 | 158 | virtual void SetIcons(const wxIconBundle& icons) { m_icons = icons; } |
7d9f12f3 | 159 | |
c8e8ae85 VS |
160 | // maximize the window to cover entire screen |
161 | virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) = 0; | |
d4597e13 | 162 | |
cb719f2e | 163 | // return true if the frame is in fullscreen mode |
c8e8ae85 VS |
164 | virtual bool IsFullScreen() const = 0; |
165 | ||
ffd84c94 WS |
166 | // the title of the top level window: the text which the |
167 | // window shows usually at the top of the frame/dialog in dedicated bar | |
7d9f12f3 | 168 | virtual void SetTitle(const wxString& title) = 0; |
ec4f95c4 | 169 | virtual wxString GetTitle() const = 0; |
7d9f12f3 | 170 | |
a43ec16b RR |
171 | // enable/disable close button [x] |
172 | virtual bool EnableCloseButton(bool WXUNUSED(enable) ) { return false; } | |
173 | ||
1542ea39 | 174 | // Set the shape of the window to the given region. |
cb719f2e | 175 | // Returns true if the platform supports this feature (and the |
1542ea39 | 176 | // operation is successful.) |
cb719f2e | 177 | virtual bool SetShape(const wxRegion& WXUNUSED(region)) { return false; } |
1542ea39 | 178 | |
dc92adaf VZ |
179 | // Attracts the users attention to this window if the application is |
180 | // inactive (should be called when a background event occurs) | |
181 | virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO); | |
9b141468 | 182 | |
35ff90a0 | 183 | // Is this the active frame (highlighted in the taskbar)? |
171a1afe VZ |
184 | virtual bool IsActive() { return wxGetTopLevelParent(FindFocus()) == this; } |
185 | ||
186 | // this function may be overridden to return false to allow closing the | |
187 | // application even when this top level window is still open | |
188 | // | |
189 | // notice that the window is still closed prior to the application exit and | |
190 | // so it can still veto it even if it returns false from here | |
191 | virtual bool ShouldPreventAppExit() const { return true; } | |
192 | ||
dc92adaf | 193 | |
9b141468 WS |
194 | #if defined(__SMARTPHONE__) |
195 | virtual void SetLeftMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL) = 0; | |
196 | virtual void SetRightMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL) = 0; | |
197 | #endif // __SMARTPHONE__ | |
198 | ||
1f464296 VZ |
199 | // centre the window on screen: this is just a shortcut |
200 | void CentreOnScreen(int dir = wxBOTH) { DoCentre(dir | wxCENTRE_ON_SCREEN); } | |
201 | void CenterOnScreen(int dir = wxBOTH) { CentreOnScreen(dir); } | |
202 | ||
6c20e8f8 VZ |
203 | |
204 | // default item access: we have a permanent default item which is the one | |
205 | // set by the user code but we may also have a temporary default item which | |
206 | // would be chosen if the user pressed "Enter" now but the default action | |
207 | // reverts to the "permanent" default as soon as this temporary default | |
208 | // item loses focus | |
209 | ||
6c20e8f8 VZ |
210 | // get the default item, temporary or permanent |
211 | wxWindow *GetDefaultItem() const | |
212 | { return m_winTmpDefault ? m_winTmpDefault : m_winDefault; } | |
213 | ||
214 | // set the permanent default item, return the old default | |
215 | wxWindow *SetDefaultItem(wxWindow *win) | |
216 | { wxWindow *old = GetDefaultItem(); m_winDefault = win; return old; } | |
217 | ||
218 | // return the temporary default item, can be NULL | |
219 | wxWindow *GetTmpDefaultItem() const { return m_winTmpDefault; } | |
220 | ||
221 | // set a temporary default item, SetTmpDefaultItem(NULL) should be called | |
222 | // soon after a call to SetTmpDefaultItem(window), return the old default | |
223 | wxWindow *SetTmpDefaultItem(wxWindow *win) | |
224 | { wxWindow *old = GetDefaultItem(); m_winTmpDefault = win; return old; } | |
225 | ||
226 | ||
7d9f12f3 VS |
227 | // implementation only from now on |
228 | // ------------------------------- | |
229 | ||
230 | // override some base class virtuals | |
231 | virtual bool Destroy(); | |
cb719f2e | 232 | virtual bool IsTopLevel() const { return true; } |
9c72cf76 | 233 | virtual bool IsVisible() const { return IsShown(); } |
7d9f12f3 VS |
234 | |
235 | // event handlers | |
236 | void OnCloseWindow(wxCloseEvent& event); | |
5e62d4a5 | 237 | void OnSize(wxSizeEvent& WXUNUSED(event)) { DoLayout(); } |
7d9f12f3 | 238 | |
0bba37f5 DE |
239 | // Get rect to be used to center top-level children |
240 | virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h); | |
241 | ||
7d9f12f3 VS |
242 | // this should go away, but for now it's called from docview.cpp, |
243 | // so should be there for all platforms | |
244 | void OnActivate(wxActivateEvent &WXUNUSED(event)) { } | |
245 | ||
e39af974 JS |
246 | // do the window-specific processing after processing the update event |
247 | virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ; | |
248 | ||
cda5834e RR |
249 | // a different API for SetSizeHints |
250 | virtual void SetMinSize(const wxSize& minSize); | |
251 | virtual void SetMaxSize(const wxSize& maxSize); | |
252 | ||
3498362e | 253 | protected: |
7d9f12f3 VS |
254 | // the frame client to screen translation should take account of the |
255 | // toolbar which may shift the origin of the client area | |
256 | virtual void DoClientToScreen(int *x, int *y) const; | |
257 | virtual void DoScreenToClient(int *x, int *y) const; | |
258 | ||
1f464296 VZ |
259 | // add support for wxCENTRE_ON_SCREEN |
260 | virtual void DoCentre(int dir); | |
261 | ||
3c81c9aa VZ |
262 | // no need to do client to screen translation to get our position in screen |
263 | // coordinates: this is already the case | |
264 | virtual void DoGetScreenPosition(int *x, int *y) const | |
265 | { | |
74af7bcf | 266 | DoGetPosition(x, y); |
3c81c9aa | 267 | } |
1f464296 | 268 | |
1cbee0b4 VZ |
269 | // test whether this window makes part of the frame |
270 | // (menubar, toolbar and statusbar are excluded from automatic layout) | |
271 | virtual bool IsOneOfBars(const wxWindow *WXUNUSED(win)) const | |
cb719f2e | 272 | { return false; } |
1cbee0b4 | 273 | |
65afac3f | 274 | // check if we should exit the program after deleting this window |
5c363878 | 275 | bool IsLastBeforeExit() const; |
1cbee0b4 | 276 | |
cb719f2e WS |
277 | // send the iconize event, return true if processed |
278 | bool SendIconizeEvent(bool iconized = true); | |
7d9f12f3 | 279 | |
5e62d4a5 VZ |
280 | // do TLW-specific layout: we resize our unique child to fill the entire |
281 | // client area | |
282 | void DoLayout(); | |
283 | ||
66202a7e RD |
284 | // Get the default size for the new window if no explicit size given. If |
285 | // there are better default sizes then these can be changed, just as long | |
0c089c08 VZ |
286 | // as they are not too small for TLWs (and not larger than screen). |
287 | static wxSize GetDefaultSize(); | |
cb719f2e WS |
288 | static int WidthDefault(int w) { return w == wxDefaultCoord ? GetDefaultSize().x : w; } |
289 | static int HeightDefault(int h) { return h == wxDefaultCoord ? GetDefaultSize().y : h; } | |
66202a7e | 290 | |
f8ab85ae VZ |
291 | // reset m_winDefault and m_winTmpDefault if they point to the window being |
292 | // destroyed | |
293 | void OnChildDestroy(wxWindowDestroyEvent& event); | |
294 | ||
295 | ||
7d9f12f3 | 296 | // the frame icon |
f618020a | 297 | wxIconBundle m_icons; |
7d9f12f3 | 298 | |
6c20e8f8 VZ |
299 | // a default window (usually a button) or NULL |
300 | wxWindow *m_winDefault; | |
301 | ||
302 | // a temporary override of m_winDefault, use the latter if NULL | |
303 | wxWindow *m_winTmpDefault; | |
304 | ||
fc7a2a60 | 305 | DECLARE_NO_COPY_CLASS(wxTopLevelWindowBase) |
7d9f12f3 | 306 | DECLARE_EVENT_TABLE() |
049908c5 | 307 | WX_DECLARE_CONTROL_CONTAINER(); |
ec4f95c4 VZ |
308 | }; |
309 | ||
7d9f12f3 VS |
310 | |
311 | // include the real class declaration | |
4055ed82 | 312 | #if defined(__WXPALMOS__) |
ffecfa5a JS |
313 | #include "wx/palmos/toplevel.h" |
314 | #define wxTopLevelWindowNative wxTopLevelWindowPalm | |
315 | #elif defined(__WXMSW__) | |
82c9f85c VZ |
316 | #include "wx/msw/toplevel.h" |
317 | #define wxTopLevelWindowNative wxTopLevelWindowMSW | |
1be7a35c | 318 | #elif defined(__WXGTK20__) |
7d9f12f3 VS |
319 | #include "wx/gtk/toplevel.h" |
320 | #define wxTopLevelWindowNative wxTopLevelWindowGTK | |
1be7a35c MR |
321 | #elif defined(__WXGTK__) |
322 | #include "wx/gtk1/toplevel.h" | |
323 | #define wxTopLevelWindowNative wxTopLevelWindowGTK | |
83df96d6 JS |
324 | #elif defined(__WXX11__) |
325 | #include "wx/x11/toplevel.h" | |
326 | #define wxTopLevelWindowNative wxTopLevelWindowX11 | |
7d9f12f3 VS |
327 | #elif defined(__WXMGL__) |
328 | #include "wx/mgl/toplevel.h" | |
329 | #define wxTopLevelWindowNative wxTopLevelWindowMGL | |
b3c86150 VS |
330 | #elif defined(__WXDFB__) |
331 | #include "wx/dfb/toplevel.h" | |
332 | #define wxTopLevelWindowNative wxTopLevelWindowDFB | |
93b4dc4b SC |
333 | #elif defined(__WXMAC__) |
334 | #include "wx/mac/toplevel.h" | |
335 | #define wxTopLevelWindowNative wxTopLevelWindowMac | |
e64df9bc DE |
336 | #elif defined(__WXCOCOA__) |
337 | #include "wx/cocoa/toplevel.h" | |
338 | #define wxTopLevelWindowNative wxTopLevelWindowCocoa | |
c9782ca3 DW |
339 | #elif defined(__WXPM__) |
340 | #include "wx/os2/toplevel.h" | |
341 | #define wxTopLevelWindowNative wxTopLevelWindowOS2 | |
798a4529 MB |
342 | #elif defined(__WXMOTIF__) |
343 | #include "wx/motif/toplevel.h" | |
344 | #define wxTopLevelWindowNative wxTopLevelWindowMotif | |
7d9f12f3 VS |
345 | #endif |
346 | ||
347 | #ifdef __WXUNIVERSAL__ | |
348 | #include "wx/univ/toplevel.h" | |
349 | #else // !__WXUNIVERSAL__ | |
350 | #ifdef wxTopLevelWindowNative | |
53a2db12 | 351 | class WXDLLIMPEXP_CORE wxTopLevelWindow : public wxTopLevelWindowNative |
7d9f12f3 VS |
352 | { |
353 | public: | |
354 | // construction | |
355 | wxTopLevelWindow() { Init(); } | |
356 | wxTopLevelWindow(wxWindow *parent, | |
d9e2e4c2 | 357 | wxWindowID winid, |
7d9f12f3 VS |
358 | const wxString& title, |
359 | const wxPoint& pos = wxDefaultPosition, | |
360 | const wxSize& size = wxDefaultSize, | |
361 | long style = wxDEFAULT_FRAME_STYLE, | |
362 | const wxString& name = wxFrameNameStr) | |
363 | { | |
364 | Init(); | |
d9e2e4c2 | 365 | Create(parent, winid, title, pos, size, style, name); |
7d9f12f3 VS |
366 | } |
367 | ||
fc7a2a60 | 368 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxTopLevelWindow) |
7d9f12f3 VS |
369 | }; |
370 | #endif // wxTopLevelWindowNative | |
371 | #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__ | |
372 | ||
373 | ||
374 | #endif // _WX_TOPLEVEL_BASE_H_ |