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