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