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