]> git.saurik.com Git - wxWidgets.git/blob - include/wx/toplevel.h
regenerated after today's changes, it should now handle Sun CC under Linux correctly
[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
25 // the default names for various classes
26 extern WXDLLEXPORT_DATA(const wxChar) wxFrameNameStr[];
27
28 class WXDLLEXPORT wxTopLevelWindowBase;
29
30 // ----------------------------------------------------------------------------
31 // constants
32 // ----------------------------------------------------------------------------
33
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
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
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
69 #if defined(__WXWINCE__)
70 #if defined(__SMARTPHONE__)
71 #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE)
72 #elif defined(__WINCE_STANDARDSDK__)
73 #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE|wxCLOSE_BOX)
74 #else
75 #define wxDEFAULT_FRAME_STYLE (wxNO_BORDER)
76 #endif
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
89 // Dialogs are created in a special way
90 #define wxTOPLEVEL_EX_DIALOG 0x00000008
91
92 // Styles for ShowFullScreen
93 // (note that wxTopLevelWindow only handles wxFULLSCREEN_NOBORDER and
94 // wxFULLSCREEN_NOCAPTION; the rest is handled by wxTopLevelWindow)
95 enum
96 {
97 wxFULLSCREEN_NOMENUBAR = 0x0001,
98 wxFULLSCREEN_NOTOOLBAR = 0x0002,
99 wxFULLSCREEN_NOSTATUSBAR = 0x0004,
100 wxFULLSCREEN_NOBORDER = 0x0008,
101 wxFULLSCREEN_NOCAPTION = 0x0010,
102
103 wxFULLSCREEN_ALL = wxFULLSCREEN_NOMENUBAR | wxFULLSCREEN_NOTOOLBAR |
104 wxFULLSCREEN_NOSTATUSBAR | wxFULLSCREEN_NOBORDER |
105 wxFULLSCREEN_NOCAPTION
106 };
107
108 // Styles for RequestUserAttention
109 enum
110 {
111 wxUSER_ATTENTION_INFO = 1,
112 wxUSER_ATTENTION_ERROR = 2
113 };
114
115 // ----------------------------------------------------------------------------
116 // wxTopLevelWindow: a top level (as opposed to child) window
117 // ----------------------------------------------------------------------------
118
119 class WXDLLEXPORT wxTopLevelWindowBase : public wxNonOwnedWindow
120 {
121 public:
122 // construction
123 wxTopLevelWindowBase();
124 virtual ~wxTopLevelWindowBase();
125
126 // top level wnd state
127 // --------------------
128
129 // maximize = true => maximize, otherwise - restore
130 virtual void Maximize(bool maximize = true) = 0;
131
132 // undo Maximize() or Iconize()
133 virtual void Restore() = 0;
134
135 // iconize = true => iconize, otherwise - restore
136 virtual void Iconize(bool iconize = true) = 0;
137
138 // return true if the frame is maximized
139 virtual bool IsMaximized() const = 0;
140
141 // return true if the frame is always maximized
142 // due to native guidelines or current policy
143 virtual bool IsAlwaysMaximized() const;
144
145 // return true if the frame is iconized
146 virtual bool IsIconized() const = 0;
147
148 // get the frame icon
149 wxIcon GetIcon() const;
150
151 // get the frame icons
152 const wxIconBundle& GetIcons() const { return m_icons; }
153
154 // set the frame icon: implemented in terms of SetIcons()
155 void SetIcon(const wxIcon& icon);
156
157 // set the frame icons
158 virtual void SetIcons(const wxIconBundle& icons) { m_icons = icons; }
159
160 // maximize the window to cover entire screen
161 virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) = 0;
162
163 // return true if the frame is in fullscreen mode
164 virtual bool IsFullScreen() const = 0;
165
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
168 virtual void SetTitle(const wxString& title) = 0;
169 virtual wxString GetTitle() const = 0;
170
171 // enable/disable close button [x]
172 virtual bool EnableCloseButton(bool WXUNUSED(enable) ) { return false; }
173
174 // Set the shape of the window to the given region.
175 // Returns true if the platform supports this feature (and the
176 // operation is successful.)
177 virtual bool SetShape(const wxRegion& WXUNUSED(region)) { return false; }
178
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);
182
183 // Is this the active frame (highlighted in the taskbar)?
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
193
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
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
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
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
227 // implementation only from now on
228 // -------------------------------
229
230 // override some base class virtuals
231 virtual bool Destroy();
232 virtual bool IsTopLevel() const { return true; }
233 virtual bool IsVisible() const { return IsShown(); }
234
235 // event handlers
236 void OnCloseWindow(wxCloseEvent& event);
237 void OnSize(wxSizeEvent& WXUNUSED(event)) { DoLayout(); }
238
239 // Get rect to be used to center top-level children
240 virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h);
241
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
246 // do the window-specific processing after processing the update event
247 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
248
249 // a different API for SetSizeHints
250 virtual void SetMinSize(const wxSize& minSize);
251 virtual void SetMaxSize(const wxSize& maxSize);
252
253 protected:
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
259 // add support for wxCENTRE_ON_SCREEN
260 virtual void DoCentre(int dir);
261
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 {
266 DoGetPosition(x, y);
267 }
268
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
272 { return false; }
273
274 // check if we should exit the program after deleting this window
275 bool IsLastBeforeExit() const;
276
277 // send the iconize event, return true if processed
278 bool SendIconizeEvent(bool iconized = true);
279
280 // do TLW-specific layout: we resize our unique child to fill the entire
281 // client area
282 void DoLayout();
283
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
286 // as they are not too small for TLWs (and not larger than screen).
287 static wxSize GetDefaultSize();
288 static int WidthDefault(int w) { return w == wxDefaultCoord ? GetDefaultSize().x : w; }
289 static int HeightDefault(int h) { return h == wxDefaultCoord ? GetDefaultSize().y : h; }
290
291 // reset m_winDefault and m_winTmpDefault if they point to the window being
292 // destroyed
293 void OnChildDestroy(wxWindowDestroyEvent& event);
294
295
296 // the frame icon
297 wxIconBundle m_icons;
298
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
305 DECLARE_NO_COPY_CLASS(wxTopLevelWindowBase)
306 DECLARE_EVENT_TABLE()
307 WX_DECLARE_CONTROL_CONTAINER();
308 };
309
310
311 // include the real class declaration
312 #if defined(__WXPALMOS__)
313 #include "wx/palmos/toplevel.h"
314 #define wxTopLevelWindowNative wxTopLevelWindowPalm
315 #elif defined(__WXMSW__)
316 #include "wx/msw/toplevel.h"
317 #define wxTopLevelWindowNative wxTopLevelWindowMSW
318 #elif defined(__WXGTK20__)
319 #include "wx/gtk/toplevel.h"
320 #define wxTopLevelWindowNative wxTopLevelWindowGTK
321 #elif defined(__WXGTK__)
322 #include "wx/gtk1/toplevel.h"
323 #define wxTopLevelWindowNative wxTopLevelWindowGTK
324 #elif defined(__WXX11__)
325 #include "wx/x11/toplevel.h"
326 #define wxTopLevelWindowNative wxTopLevelWindowX11
327 #elif defined(__WXMGL__)
328 #include "wx/mgl/toplevel.h"
329 #define wxTopLevelWindowNative wxTopLevelWindowMGL
330 #elif defined(__WXDFB__)
331 #include "wx/dfb/toplevel.h"
332 #define wxTopLevelWindowNative wxTopLevelWindowDFB
333 #elif defined(__WXMAC__)
334 #include "wx/mac/toplevel.h"
335 #define wxTopLevelWindowNative wxTopLevelWindowMac
336 #elif defined(__WXCOCOA__)
337 #include "wx/cocoa/toplevel.h"
338 #define wxTopLevelWindowNative wxTopLevelWindowCocoa
339 #elif defined(__WXPM__)
340 #include "wx/os2/toplevel.h"
341 #define wxTopLevelWindowNative wxTopLevelWindowOS2
342 #elif defined(__WXMOTIF__)
343 #include "wx/motif/toplevel.h"
344 #define wxTopLevelWindowNative wxTopLevelWindowMotif
345 #endif
346
347 #ifdef __WXUNIVERSAL__
348 #include "wx/univ/toplevel.h"
349 #else // !__WXUNIVERSAL__
350 #ifdef wxTopLevelWindowNative
351 class WXDLLEXPORT wxTopLevelWindow : public wxTopLevelWindowNative
352 {
353 public:
354 // construction
355 wxTopLevelWindow() { Init(); }
356 wxTopLevelWindow(wxWindow *parent,
357 wxWindowID winid,
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();
365 Create(parent, winid, title, pos, size, style, name);
366 }
367
368 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTopLevelWindow)
369 };
370 #endif // wxTopLevelWindowNative
371 #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__
372
373
374 #endif // _WX_TOPLEVEL_BASE_H_