1 ///////////////////////////////////////////////////////////////////////////////
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
9 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Vaclav Slavik <vaclav@wxwidgets.org>
11 // Licence: wxWindows licence
12 ///////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_TOPLEVEL_BASE_H_
15 #define _WX_TOPLEVEL_BASE_H_
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/nonownedwnd.h"
22 #include "wx/iconbndl.h"
23 #include "wx/containr.h"
25 // the default names for various classes
26 extern WXDLLIMPEXP_DATA_CORE(const char) wxFrameNameStr
[];
28 class WXDLLIMPEXP_FWD_CORE wxTopLevelWindowBase
;
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
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
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
48 #if WXWIN_COMPATIBILITY_2_6
50 // deprecated versions defined for compatibility reasons
51 #define wxRESIZE_BOX wxMAXIMIZE_BOX
52 #define wxTHICK_FRAME wxRESIZE_BORDER
54 // obsolete styles, unused any more
55 #define wxDIALOG_MODAL 0
56 #define wxDIALOG_MODELESS 0
58 #define wxUSER_COLOURS 0
60 #endif // WXWIN_COMPATIBILITY_2_6
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)
75 #define wxDEFAULT_FRAME_STYLE (wxNO_BORDER)
78 #define wxDEFAULT_FRAME_STYLE \
89 // Dialogs are created in a special way
90 #define wxTOPLEVEL_EX_DIALOG 0x00000008
92 // Styles for ShowFullScreen
93 // (note that wxTopLevelWindow only handles wxFULLSCREEN_NOBORDER and
94 // wxFULLSCREEN_NOCAPTION; the rest is handled by wxTopLevelWindow)
97 wxFULLSCREEN_NOMENUBAR
= 0x0001,
98 wxFULLSCREEN_NOTOOLBAR
= 0x0002,
99 wxFULLSCREEN_NOSTATUSBAR
= 0x0004,
100 wxFULLSCREEN_NOBORDER
= 0x0008,
101 wxFULLSCREEN_NOCAPTION
= 0x0010,
103 wxFULLSCREEN_ALL
= wxFULLSCREEN_NOMENUBAR
| wxFULLSCREEN_NOTOOLBAR
|
104 wxFULLSCREEN_NOSTATUSBAR
| wxFULLSCREEN_NOBORDER
|
105 wxFULLSCREEN_NOCAPTION
108 // Styles for RequestUserAttention
111 wxUSER_ATTENTION_INFO
= 1,
112 wxUSER_ATTENTION_ERROR
= 2
115 // ----------------------------------------------------------------------------
116 // wxTopLevelWindow: a top level (as opposed to child) window
117 // ----------------------------------------------------------------------------
119 class WXDLLIMPEXP_CORE wxTopLevelWindowBase
: public wxNonOwnedWindow
123 wxTopLevelWindowBase();
124 virtual ~wxTopLevelWindowBase();
126 // top level wnd state
127 // --------------------
129 // maximize = true => maximize, otherwise - restore
130 virtual void Maximize(bool maximize
= true) = 0;
132 // undo Maximize() or Iconize()
133 virtual void Restore() = 0;
135 // iconize = true => iconize, otherwise - restore
136 virtual void Iconize(bool iconize
= true) = 0;
138 // return true if the frame is maximized
139 virtual bool IsMaximized() const = 0;
141 // return true if the frame is always maximized
142 // due to native guidelines or current policy
143 virtual bool IsAlwaysMaximized() const;
145 // return true if the frame is iconized
146 virtual bool IsIconized() const = 0;
148 // get the frame icon
149 wxIcon
GetIcon() const;
151 // get the frame icons
152 const wxIconBundle
& GetIcons() const { return m_icons
; }
154 // set the frame icon: implemented in terms of SetIcons()
155 void SetIcon(const wxIcon
& icon
);
157 // set the frame icons
158 virtual void SetIcons(const wxIconBundle
& icons
) { m_icons
= icons
; }
160 // maximize the window to cover entire screen
161 virtual bool ShowFullScreen(bool show
, long style
= wxFULLSCREEN_ALL
) = 0;
163 // return true if the frame is in fullscreen mode
164 virtual bool IsFullScreen() const = 0;
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;
171 // enable/disable close button [x]
172 virtual bool EnableCloseButton(bool WXUNUSED(enable
) ) { return false; }
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; }
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
);
183 // Is this the active frame (highlighted in the taskbar)?
184 virtual bool IsActive() { return wxGetTopLevelParent(FindFocus()) == this; }
186 // this function may be overridden to return false to allow closing the
187 // application even when this top level window is still open
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; }
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__
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
); }
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
210 // get the default item, temporary or permanent
211 wxWindow
*GetDefaultItem() const
212 { return m_winTmpDefault
? m_winTmpDefault
: m_winDefault
; }
214 // set the permanent default item, return the old default
215 wxWindow
*SetDefaultItem(wxWindow
*win
)
216 { wxWindow
*old
= GetDefaultItem(); m_winDefault
= win
; return old
; }
218 // return the temporary default item, can be NULL
219 wxWindow
*GetTmpDefaultItem() const { return m_winTmpDefault
; }
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
; }
227 // implementation only from now on
228 // -------------------------------
230 // override some base class virtuals
231 virtual bool Destroy();
232 virtual bool IsTopLevel() const { return true; }
233 virtual bool IsVisible() const { return IsShown(); }
236 void OnCloseWindow(wxCloseEvent
& event
);
237 void OnSize(wxSizeEvent
& WXUNUSED(event
)) { DoLayout(); }
239 // Get rect to be used to center top-level children
240 virtual void GetRectForTopLevelChildren(int *x
, int *y
, int *w
, int *h
);
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
)) { }
246 // do the window-specific processing after processing the update event
247 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
) ;
249 // a different API for SetSizeHints
250 virtual void SetMinSize(const wxSize
& minSize
);
251 virtual void SetMaxSize(const wxSize
& maxSize
);
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;
259 // add support for wxCENTRE_ON_SCREEN
260 virtual void DoCentre(int dir
);
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
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
274 // check if we should exit the program after deleting this window
275 bool IsLastBeforeExit() const;
277 // send the iconize event, return true if processed
278 bool SendIconizeEvent(bool iconized
= true);
280 // do TLW-specific layout: we resize our unique child to fill the entire
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
; }
291 // reset m_winDefault and m_winTmpDefault if they point to the window being
293 void OnChildDestroy(wxWindowDestroyEvent
& event
);
297 wxIconBundle m_icons
;
299 // a default window (usually a button) or NULL
300 wxWindow
*m_winDefault
;
302 // a temporary override of m_winDefault, use the latter if NULL
303 wxWindow
*m_winTmpDefault
;
305 DECLARE_NO_COPY_CLASS(wxTopLevelWindowBase
)
306 DECLARE_EVENT_TABLE()
307 WX_DECLARE_CONTROL_CONTAINER();
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
347 #ifdef __WXUNIVERSAL__
348 #include "wx/univ/toplevel.h"
349 #else // !__WXUNIVERSAL__
350 #ifdef wxTopLevelWindowNative
351 class WXDLLIMPEXP_CORE wxTopLevelWindow
: public wxTopLevelWindowNative
355 wxTopLevelWindow() { Init(); }
356 wxTopLevelWindow(wxWindow
*parent
,
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
)
365 Create(parent
, winid
, title
, pos
, size
, style
, name
);
368 DECLARE_DYNAMIC_CLASS_NO_COPY(wxTopLevelWindow
)
370 #endif // wxTopLevelWindowNative
371 #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__
374 #endif // _WX_TOPLEVEL_BASE_H_