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