]> git.saurik.com Git - wxWidgets.git/blob - include/wx/toplevel.h
Added wxAbort() which can also be used under Windows CE.
[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 /*
36 Summary of the bits used (some of them are defined in wx/frame.h and
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 | | | | | | | | | | | | | | | |
43 | | | | | | | | | | | | | | | \_ wxCENTRE
44 | | | | | | | | | | | | | | \____ wxFRAME_NO_TASKBAR
45 | | | | | | | | | | | | | \_______ wxFRAME_TOOL_WINDOW
46 | | | | | | | | | | | | \__________ wxFRAME_FLOAT_ON_PARENT
47 | | | | | | | | | | | \_____________ wxFRAME_SHAPED
48 | | | | | | | | | | \________________ wxDIALOG_NO_PARENT
49 | | | | | | | | | \___________________ wxRESIZE_BORDER
50 | | | | | | | | \______________________ wxTINY_CAPTION_VERT
51 | | | | | | | \_________________________
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.
65 Additionally, wxCENTRE can be used with frames also.
66 */
67
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 // == wxHELP so can't be used with it
74
75 #define wxSYSTEM_MENU 0x0800
76 #define wxMINIMIZE_BOX 0x0400
77 #define wxMAXIMIZE_BOX 0x0200
78
79 #define wxTINY_CAPTION 0x0080 // clashes with wxNO_DEFAULT
80 #define wxRESIZE_BORDER 0x0040 // == wxCLOSE
81
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
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
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
110 #if defined(__WXWINCE__)
111 #if defined(__SMARTPHONE__)
112 #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE)
113 #elif defined(__WINCE_STANDARDSDK__)
114 #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE|wxCLOSE_BOX)
115 #else
116 #define wxDEFAULT_FRAME_STYLE (wxNO_BORDER)
117 #endif
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
130 // Dialogs are created in a special way
131 #define wxTOPLEVEL_EX_DIALOG 0x00000008
132
133 // Styles for ShowFullScreen
134 // (note that wxTopLevelWindow only handles wxFULLSCREEN_NOBORDER and
135 // wxFULLSCREEN_NOCAPTION; the rest is handled by wxTopLevelWindow)
136 enum
137 {
138 wxFULLSCREEN_NOMENUBAR = 0x0001,
139 wxFULLSCREEN_NOTOOLBAR = 0x0002,
140 wxFULLSCREEN_NOSTATUSBAR = 0x0004,
141 wxFULLSCREEN_NOBORDER = 0x0008,
142 wxFULLSCREEN_NOCAPTION = 0x0010,
143
144 wxFULLSCREEN_ALL = wxFULLSCREEN_NOMENUBAR | wxFULLSCREEN_NOTOOLBAR |
145 wxFULLSCREEN_NOSTATUSBAR | wxFULLSCREEN_NOBORDER |
146 wxFULLSCREEN_NOCAPTION
147 };
148
149 // Styles for RequestUserAttention
150 enum
151 {
152 wxUSER_ATTENTION_INFO = 1,
153 wxUSER_ATTENTION_ERROR = 2
154 };
155
156 // ----------------------------------------------------------------------------
157 // wxTopLevelWindow: a top level (as opposed to child) window
158 // ----------------------------------------------------------------------------
159
160 class WXDLLIMPEXP_CORE wxTopLevelWindowBase :
161 public wxNavigationEnabled<wxNonOwnedWindow>
162 {
163 public:
164 // construction
165 wxTopLevelWindowBase();
166 virtual ~wxTopLevelWindowBase();
167
168 // top level wnd state
169 // --------------------
170
171 // maximize = true => maximize, otherwise - restore
172 virtual void Maximize(bool maximize = true) = 0;
173
174 // undo Maximize() or Iconize()
175 virtual void Restore() = 0;
176
177 // iconize = true => iconize, otherwise - restore
178 virtual void Iconize(bool iconize = true) = 0;
179
180 // return true if the frame is maximized
181 virtual bool IsMaximized() const = 0;
182
183 // return true if the frame is always maximized
184 // due to native guidelines or current policy
185 virtual bool IsAlwaysMaximized() const;
186
187 // return true if the frame is iconized
188 virtual bool IsIconized() const = 0;
189
190 // get the frame icon
191 wxIcon GetIcon() const;
192
193 // get the frame icons
194 const wxIconBundle& GetIcons() const { return m_icons; }
195
196 // set the frame icon: implemented in terms of SetIcons()
197 void SetIcon(const wxIcon& icon);
198
199 // set the frame icons
200 virtual void SetIcons(const wxIconBundle& icons) { m_icons = icons; }
201
202 // maximize the window to cover entire screen
203 virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) = 0;
204
205 // shows the window, but doesn't activate it. If the base code is being run,
206 // it means the port doesn't implement this method yet and so alert the user.
207 virtual void ShowWithoutActivating() {
208 wxFAIL_MSG("ShowWithoutActivating not implemented on this platform.");
209 }
210
211 // return true if the frame is in fullscreen mode
212 virtual bool IsFullScreen() const = 0;
213
214 // the title of the top level window: the text which the
215 // window shows usually at the top of the frame/dialog in dedicated bar
216 virtual void SetTitle(const wxString& title) = 0;
217 virtual wxString GetTitle() const = 0;
218
219 // enable/disable close button [x]
220 virtual bool EnableCloseButton(bool WXUNUSED(enable) ) { return false; }
221
222 // Attracts the users attention to this window if the application is
223 // inactive (should be called when a background event occurs)
224 virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO);
225
226 // Is this the active frame (highlighted in the taskbar)?
227 virtual bool IsActive() { return wxGetTopLevelParent(FindFocus()) == this; }
228
229 // this function may be overridden to return false to allow closing the
230 // application even when this top level window is still open
231 //
232 // notice that the window is still closed prior to the application exit and
233 // so it can still veto it even if it returns false from here
234 virtual bool ShouldPreventAppExit() const { return true; }
235
236
237 #if defined(__SMARTPHONE__)
238 virtual void SetLeftMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL) = 0;
239 virtual void SetRightMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL) = 0;
240 #endif // __SMARTPHONE__
241
242 // centre the window on screen: this is just a shortcut
243 void CentreOnScreen(int dir = wxBOTH) { DoCentre(dir | wxCENTRE_ON_SCREEN); }
244 void CenterOnScreen(int dir = wxBOTH) { CentreOnScreen(dir); }
245
246 // Get the default size for a new top level window. This is used when
247 // creating a wxTLW under some platforms if no explicit size given.
248 static wxSize GetDefaultSize();
249
250
251 // default item access: we have a permanent default item which is the one
252 // set by the user code but we may also have a temporary default item which
253 // would be chosen if the user pressed "Enter" now but the default action
254 // reverts to the "permanent" default as soon as this temporary default
255 // item loses focus
256
257 // get the default item, temporary or permanent
258 wxWindow *GetDefaultItem() const
259 { return m_winTmpDefault ? m_winTmpDefault : m_winDefault; }
260
261 // set the permanent default item, return the old default
262 wxWindow *SetDefaultItem(wxWindow *win)
263 { wxWindow *old = GetDefaultItem(); m_winDefault = win; return old; }
264
265 // return the temporary default item, can be NULL
266 wxWindow *GetTmpDefaultItem() const { return m_winTmpDefault; }
267
268 // set a temporary default item, SetTmpDefaultItem(NULL) should be called
269 // soon after a call to SetTmpDefaultItem(window), return the old default
270 wxWindow *SetTmpDefaultItem(wxWindow *win)
271 { wxWindow *old = GetDefaultItem(); m_winTmpDefault = win; return old; }
272
273
274 // implementation only from now on
275 // -------------------------------
276
277 // override some base class virtuals
278 virtual bool Destroy();
279 virtual bool IsTopLevel() const { return true; }
280 virtual bool IsTopNavigationDomain() const { return true; }
281 virtual bool IsVisible() const { return IsShown(); }
282
283 // event handlers
284 void OnCloseWindow(wxCloseEvent& event);
285 void OnSize(wxSizeEvent& WXUNUSED(event)) { DoLayout(); }
286
287 // Get rect to be used to center top-level children
288 virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h);
289
290 // this should go away, but for now it's called from docview.cpp,
291 // so should be there for all platforms
292 void OnActivate(wxActivateEvent &WXUNUSED(event)) { }
293
294 // do the window-specific processing after processing the update event
295 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
296
297 // a different API for SetSizeHints
298 virtual void SetMinSize(const wxSize& minSize);
299 virtual void SetMaxSize(const wxSize& maxSize);
300
301 virtual void OSXSetModified(bool modified) { m_modified = modified; }
302 virtual bool OSXIsModified() const { return m_modified; }
303
304 virtual void SetRepresentedFilename(const wxString& WXUNUSED(filename)) { }
305
306 protected:
307 // the frame client to screen translation should take account of the
308 // toolbar which may shift the origin of the client area
309 virtual void DoClientToScreen(int *x, int *y) const;
310 virtual void DoScreenToClient(int *x, int *y) const;
311
312 // add support for wxCENTRE_ON_SCREEN
313 virtual void DoCentre(int dir);
314
315 // no need to do client to screen translation to get our position in screen
316 // coordinates: this is already the case
317 virtual void DoGetScreenPosition(int *x, int *y) const
318 {
319 DoGetPosition(x, y);
320 }
321
322 // test whether this window makes part of the frame
323 // (menubar, toolbar and statusbar are excluded from automatic layout)
324 virtual bool IsOneOfBars(const wxWindow *WXUNUSED(win)) const
325 { return false; }
326
327 // check if we should exit the program after deleting this window
328 bool IsLastBeforeExit() const;
329
330 // send the iconize event, return true if processed
331 bool SendIconizeEvent(bool iconized = true);
332
333 // do TLW-specific layout: we resize our unique child to fill the entire
334 // client area
335 void DoLayout();
336
337 static int WidthDefault(int w) { return w == wxDefaultCoord ? GetDefaultSize().x : w; }
338 static int HeightDefault(int h) { return h == wxDefaultCoord ? GetDefaultSize().y : h; }
339
340
341 // the frame icon
342 wxIconBundle m_icons;
343
344 // a default window (usually a button) or NULL
345 wxWindowRef m_winDefault;
346
347 // a temporary override of m_winDefault, use the latter if NULL
348 wxWindowRef m_winTmpDefault;
349
350 bool m_modified;
351
352 wxDECLARE_NO_COPY_CLASS(wxTopLevelWindowBase);
353 DECLARE_EVENT_TABLE()
354 };
355
356
357 // include the real class declaration
358 #if defined(__WXPALMOS__)
359 #include "wx/palmos/toplevel.h"
360 #define wxTopLevelWindowNative wxTopLevelWindowPalm
361 #elif defined(__WXMSW__)
362 #include "wx/msw/toplevel.h"
363 #define wxTopLevelWindowNative wxTopLevelWindowMSW
364 #elif defined(__WXGTK20__)
365 #include "wx/gtk/toplevel.h"
366 #define wxTopLevelWindowNative wxTopLevelWindowGTK
367 #elif defined(__WXGTK__)
368 #include "wx/gtk1/toplevel.h"
369 #define wxTopLevelWindowNative wxTopLevelWindowGTK
370 #elif defined(__WXX11__)
371 #include "wx/x11/toplevel.h"
372 #define wxTopLevelWindowNative wxTopLevelWindowX11
373 #elif defined(__WXMGL__)
374 #include "wx/mgl/toplevel.h"
375 #define wxTopLevelWindowNative wxTopLevelWindowMGL
376 #elif defined(__WXDFB__)
377 #include "wx/dfb/toplevel.h"
378 #define wxTopLevelWindowNative wxTopLevelWindowDFB
379 #elif defined(__WXMAC__)
380 #include "wx/osx/toplevel.h"
381 #define wxTopLevelWindowNative wxTopLevelWindowMac
382 #elif defined(__WXCOCOA__)
383 #include "wx/cocoa/toplevel.h"
384 #define wxTopLevelWindowNative wxTopLevelWindowCocoa
385 #elif defined(__WXPM__)
386 #include "wx/os2/toplevel.h"
387 #define wxTopLevelWindowNative wxTopLevelWindowOS2
388 #elif defined(__WXMOTIF__)
389 #include "wx/motif/toplevel.h"
390 #define wxTopLevelWindowNative wxTopLevelWindowMotif
391 #endif
392
393 #ifdef __WXUNIVERSAL__
394 #include "wx/univ/toplevel.h"
395 #else // !__WXUNIVERSAL__
396 class WXDLLIMPEXP_CORE wxTopLevelWindow : public wxTopLevelWindowNative
397 {
398 public:
399 // construction
400 wxTopLevelWindow() { }
401 wxTopLevelWindow(wxWindow *parent,
402 wxWindowID winid,
403 const wxString& title,
404 const wxPoint& pos = wxDefaultPosition,
405 const wxSize& size = wxDefaultSize,
406 long style = wxDEFAULT_FRAME_STYLE,
407 const wxString& name = wxFrameNameStr)
408 : wxTopLevelWindowNative(parent, winid, title,
409 pos, size, style, name)
410 {
411 }
412
413 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTopLevelWindow)
414 };
415 #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__
416
417 #endif // _WX_TOPLEVEL_BASE_H_