]>
Commit | Line | Data |
---|---|---|
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 classs | |
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 | // deprecated versions defined for compatibility reasons | |
48 | #define wxRESIZE_BOX wxMAXIMIZE_BOX | |
49 | #define wxTHICK_FRAME wxRESIZE_BORDER | |
50 | ||
51 | // obsolete styles, unused any more | |
52 | #define wxDIALOG_MODAL 0 | |
53 | #define wxDIALOG_MODELESS 0 | |
54 | #define wxNO_3D 0 | |
55 | #define wxUSER_COLOURS 0 | |
56 | ||
57 | // default style | |
58 | // | |
59 | // under Windows CE (at least when compiling with eVC 4) we should create | |
60 | // top level windows without any styles at all for them to appear | |
61 | // "correctly", i.e. as full screen windows with a "hide" button (same as | |
62 | // "close" but round instead of squared and just hides the applications | |
63 | // instead of closing it) in the title bar | |
64 | #if defined(__WXWINCE__) | |
65 | #if defined(__SMARTPHONE__) | |
66 | #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE) | |
67 | #elif defined(__WINCE_STANDARDSDK__) | |
68 | #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE|wxCLOSE_BOX) | |
69 | #else | |
70 | #define wxDEFAULT_FRAME_STYLE (wxNO_BORDER) | |
71 | #endif | |
72 | #else // !__WXWINCE__ | |
73 | #define wxDEFAULT_FRAME_STYLE \ | |
74 | (wxSYSTEM_MENU | \ | |
75 | wxRESIZE_BORDER | \ | |
76 | wxMINIMIZE_BOX | \ | |
77 | wxMAXIMIZE_BOX | \ | |
78 | wxCLOSE_BOX | \ | |
79 | wxCAPTION | \ | |
80 | wxCLIP_CHILDREN) | |
81 | #endif | |
82 | ||
83 | ||
84 | // Dialogs are created in a special way | |
85 | #define wxTOPLEVEL_EX_DIALOG 0x00000008 | |
86 | ||
87 | // Styles for ShowFullScreen | |
88 | // (note that wxTopLevelWindow only handles wxFULLSCREEN_NOBORDER and | |
89 | // wxFULLSCREEN_NOCAPTION; the rest is handled by wxTopLevelWindow) | |
90 | enum | |
91 | { | |
92 | wxFULLSCREEN_NOMENUBAR = 0x0001, | |
93 | wxFULLSCREEN_NOTOOLBAR = 0x0002, | |
94 | wxFULLSCREEN_NOSTATUSBAR = 0x0004, | |
95 | wxFULLSCREEN_NOBORDER = 0x0008, | |
96 | wxFULLSCREEN_NOCAPTION = 0x0010, | |
97 | ||
98 | wxFULLSCREEN_ALL = wxFULLSCREEN_NOMENUBAR | wxFULLSCREEN_NOTOOLBAR | | |
99 | wxFULLSCREEN_NOSTATUSBAR | wxFULLSCREEN_NOBORDER | | |
100 | wxFULLSCREEN_NOCAPTION | |
101 | }; | |
102 | ||
103 | // Styles for RequestUserAttention | |
104 | enum | |
105 | { | |
106 | wxUSER_ATTENTION_INFO = 1, | |
107 | wxUSER_ATTENTION_ERROR = 2 | |
108 | }; | |
109 | ||
110 | // ---------------------------------------------------------------------------- | |
111 | // wxTopLevelWindow: a top level (as opposed to child) window | |
112 | // ---------------------------------------------------------------------------- | |
113 | ||
114 | class WXDLLEXPORT wxTopLevelWindowBase : public wxWindow | |
115 | { | |
116 | public: | |
117 | // construction | |
118 | wxTopLevelWindowBase(); | |
119 | virtual ~wxTopLevelWindowBase(); | |
120 | ||
121 | // top level wnd state | |
122 | // -------------------- | |
123 | ||
124 | // maximize = true => maximize, otherwise - restore | |
125 | virtual void Maximize(bool maximize = true) = 0; | |
126 | ||
127 | // undo Maximize() or Iconize() | |
128 | virtual void Restore() = 0; | |
129 | ||
130 | // iconize = true => iconize, otherwise - restore | |
131 | virtual void Iconize(bool iconize = true) = 0; | |
132 | ||
133 | // return true if the frame is maximized | |
134 | virtual bool IsMaximized() const = 0; | |
135 | ||
136 | // return true if the frame is iconized | |
137 | virtual bool IsIconized() const = 0; | |
138 | ||
139 | // get the frame icon | |
140 | const wxIcon& GetIcon() const { return m_icons.GetIcon( -1 ); } | |
141 | ||
142 | // get the frame icons | |
143 | const wxIconBundle& GetIcons() const { return m_icons; } | |
144 | ||
145 | // set the frame icon | |
146 | virtual void SetIcon(const wxIcon& icon) { m_icons = wxIconBundle( icon ); } | |
147 | ||
148 | // set the frame icons | |
149 | virtual void SetIcons(const wxIconBundle& icons ) { m_icons = icons; } | |
150 | ||
151 | // maximize the window to cover entire screen | |
152 | virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) = 0; | |
153 | ||
154 | // return true if the frame is in fullscreen mode | |
155 | virtual bool IsFullScreen() const = 0; | |
156 | ||
157 | /* | |
158 | for now we already have them in wxWindow, but this is wrong: these | |
159 | methods really only make sense for wxTopLevelWindow! | |
160 | ||
161 | virtual void SetTitle(const wxString& title) = 0; | |
162 | virtual wxString GetTitle() const = 0; | |
163 | */ | |
164 | ||
165 | // Set the shape of the window to the given region. | |
166 | // Returns true if the platform supports this feature (and the | |
167 | // operation is successful.) | |
168 | virtual bool SetShape(const wxRegion& WXUNUSED(region)) { return false; } | |
169 | ||
170 | // Attracts the users attention to this window if the application is | |
171 | // inactive (should be called when a background event occurs) | |
172 | virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO); | |
173 | ||
174 | // Is this the active frame (highlighted in the taskbar)? | |
175 | virtual bool IsActive() | |
176 | { return (wxGetTopLevelParent(FindFocus()) == this); } | |
177 | ||
178 | #if defined(__SMARTPHONE__) | |
179 | virtual void SetLeftMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL) = 0; | |
180 | virtual void SetRightMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL) = 0; | |
181 | #endif // __SMARTPHONE__ | |
182 | ||
183 | // implementation only from now on | |
184 | // ------------------------------- | |
185 | ||
186 | // override some base class virtuals | |
187 | virtual bool Destroy(); | |
188 | virtual bool IsTopLevel() const { return true; } | |
189 | virtual wxSize GetMaxSize() const; | |
190 | ||
191 | // event handlers | |
192 | void OnCloseWindow(wxCloseEvent& event); | |
193 | void OnSize(wxSizeEvent& WXUNUSED(event)) { DoLayout(); } | |
194 | ||
195 | // Get rect to be used to center top-level children | |
196 | virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h); | |
197 | ||
198 | // this should go away, but for now it's called from docview.cpp, | |
199 | // so should be there for all platforms | |
200 | void OnActivate(wxActivateEvent &WXUNUSED(event)) { } | |
201 | ||
202 | // do the window-specific processing after processing the update event | |
203 | virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ; | |
204 | ||
205 | // Reserved for future use | |
206 | virtual void ReservedTopLevelWindowFunc1() {} | |
207 | virtual void ReservedTopLevelWindowFunc2() {} | |
208 | virtual void ReservedTopLevelWindowFunc3() {} | |
209 | virtual void ReservedTopLevelWindowFunc4() {} | |
210 | virtual void ReservedTopLevelWindowFunc5() {} | |
211 | virtual void ReservedTopLevelWindowFunc6() {} | |
212 | virtual void ReservedTopLevelWindowFunc7() {} | |
213 | virtual void ReservedTopLevelWindowFunc8() {} | |
214 | virtual void ReservedTopLevelWindowFunc9() {} | |
215 | ||
216 | protected: | |
217 | // the frame client to screen translation should take account of the | |
218 | // toolbar which may shift the origin of the client area | |
219 | virtual void DoClientToScreen(int *x, int *y) const; | |
220 | virtual void DoScreenToClient(int *x, int *y) const; | |
221 | ||
222 | // test whether this window makes part of the frame | |
223 | // (menubar, toolbar and statusbar are excluded from automatic layout) | |
224 | virtual bool IsOneOfBars(const wxWindow *WXUNUSED(win)) const | |
225 | { return false; } | |
226 | ||
227 | // check if we should exit the program after deleting this top level | |
228 | // window (this is used in common dtor and wxMSW code) | |
229 | bool IsLastBeforeExit() const; | |
230 | ||
231 | // send the iconize event, return true if processed | |
232 | bool SendIconizeEvent(bool iconized = true); | |
233 | ||
234 | // do TLW-specific layout: we resize our unique child to fill the entire | |
235 | // client area | |
236 | void DoLayout(); | |
237 | ||
238 | // Get the default size for the new window if no explicit size given. If | |
239 | // there are better default sizes then these can be changed, just as long | |
240 | // as they are not too small for TLWs (and not larger than screen). | |
241 | static wxSize GetDefaultSize(); | |
242 | static int WidthDefault(int w) { return w == wxDefaultCoord ? GetDefaultSize().x : w; } | |
243 | static int HeightDefault(int h) { return h == wxDefaultCoord ? GetDefaultSize().y : h; } | |
244 | ||
245 | // the frame icon | |
246 | wxIconBundle m_icons; | |
247 | ||
248 | DECLARE_NO_COPY_CLASS(wxTopLevelWindowBase) | |
249 | DECLARE_EVENT_TABLE() | |
250 | }; | |
251 | ||
252 | ||
253 | // include the real class declaration | |
254 | #if defined(__WXPALMOS__) | |
255 | #include "wx/palmos/toplevel.h" | |
256 | #define wxTopLevelWindowNative wxTopLevelWindowPalm | |
257 | #elif defined(__WXMSW__) | |
258 | #include "wx/msw/toplevel.h" | |
259 | #define wxTopLevelWindowNative wxTopLevelWindowMSW | |
260 | #elif defined(__WXGTK__) | |
261 | #include "wx/gtk/toplevel.h" | |
262 | #define wxTopLevelWindowNative wxTopLevelWindowGTK | |
263 | #elif defined(__WXX11__) | |
264 | #include "wx/x11/toplevel.h" | |
265 | #define wxTopLevelWindowNative wxTopLevelWindowX11 | |
266 | #elif defined(__WXMGL__) | |
267 | #include "wx/mgl/toplevel.h" | |
268 | #define wxTopLevelWindowNative wxTopLevelWindowMGL | |
269 | #elif defined(__WXMAC__) | |
270 | #include "wx/mac/toplevel.h" | |
271 | #define wxTopLevelWindowNative wxTopLevelWindowMac | |
272 | #elif defined(__WXCOCOA__) | |
273 | #include "wx/cocoa/toplevel.h" | |
274 | #define wxTopLevelWindowNative wxTopLevelWindowCocoa | |
275 | #elif defined(__WXPM__) | |
276 | #include "wx/os2/toplevel.h" | |
277 | #define wxTopLevelWindowNative wxTopLevelWindowOS2 | |
278 | #elif defined(__WXMOTIF__) | |
279 | #include "wx/motif/toplevel.h" | |
280 | #define wxTopLevelWindowNative wxTopLevelWindowMotif | |
281 | #endif | |
282 | ||
283 | #ifdef __WXUNIVERSAL__ | |
284 | #include "wx/univ/toplevel.h" | |
285 | #else // !__WXUNIVERSAL__ | |
286 | #ifdef wxTopLevelWindowNative | |
287 | class WXDLLEXPORT wxTopLevelWindow : public wxTopLevelWindowNative | |
288 | { | |
289 | public: | |
290 | // construction | |
291 | wxTopLevelWindow() { Init(); } | |
292 | wxTopLevelWindow(wxWindow *parent, | |
293 | wxWindowID winid, | |
294 | const wxString& title, | |
295 | const wxPoint& pos = wxDefaultPosition, | |
296 | const wxSize& size = wxDefaultSize, | |
297 | long style = wxDEFAULT_FRAME_STYLE, | |
298 | const wxString& name = wxFrameNameStr) | |
299 | { | |
300 | Init(); | |
301 | Create(parent, winid, title, pos, size, style, name); | |
302 | } | |
303 | ||
304 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxTopLevelWindow) | |
305 | }; | |
306 | #endif // wxTopLevelWindowNative | |
307 | #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__ | |
308 | ||
309 | ||
310 | #endif // _WX_TOPLEVEL_BASE_H_ |