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 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> 9 // Vaclav Slavik <vaclav@wxwidgets.org> 10 // Licence: wxWindows licence 11 /////////////////////////////////////////////////////////////////////////////// 12 13 #ifndef _WX_TOPLEVEL_BASE_H_ 14 #define _WX_TOPLEVEL_BASE_H_ 15 16 // ---------------------------------------------------------------------------- 17 // headers 18 // ---------------------------------------------------------------------------- 19 20 #include "wx/nonownedwnd.h" 21 #include "wx/iconbndl.h" 22 #include "wx/weakref.h" 23 24 // the default names for various classes 25 extern WXDLLIMPEXP_DATA_CORE(const char) wxFrameNameStr[]; 26 27 // ---------------------------------------------------------------------------- 28 // constants 29 // ---------------------------------------------------------------------------- 30 31 /* 32 Summary of the bits used (some of them are defined in wx/frame.h and 33 wx/dialog.h and not here): 34 35 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 36 |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| 37 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 38 | | | | | | | | | | | | | | | | 39 | | | | | | | | | | | | | | | \_ wxCENTRE 40 | | | | | | | | | | | | | | \____ wxFRAME_NO_TASKBAR 41 | | | | | | | | | | | | | \_______ wxFRAME_TOOL_WINDOW 42 | | | | | | | | | | | | \__________ wxFRAME_FLOAT_ON_PARENT 43 | | | | | | | | | | | \_____________ wxFRAME_SHAPED 44 | | | | | | | | | | \________________ wxDIALOG_NO_PARENT 45 | | | | | | | | | \___________________ wxRESIZE_BORDER 46 | | | | | | | | \______________________ wxTINY_CAPTION_VERT 47 | | | | | | | \_________________________ 48 | | | | | | \____________________________ wxMAXIMIZE_BOX 49 | | | | | \_______________________________ wxMINIMIZE_BOX 50 | | | | \__________________________________ wxSYSTEM_MENU 51 | | | \_____________________________________ wxCLOSE_BOX 52 | | \________________________________________ wxMAXIMIZE 53 | \___________________________________________ wxMINIMIZE 54 \______________________________________________ wxSTAY_ON_TOP 55 56 57 Notice that the 8 lower bits overlap with wxCENTRE and the button selection 58 bits (wxYES, wxOK wxNO, wxCANCEL, wxAPPLY, wxCLOSE and wxNO_DEFAULT) which 59 can be combined with the dialog style for several standard dialogs and 60 hence shouldn't overlap with any styles which can be used for the dialogs. 61 Additionally, wxCENTRE can be used with frames also. 62 */ 63 64 // style common to both wxFrame and wxDialog 65 #define wxSTAY_ON_TOP 0x8000 66 #define wxICONIZE 0x4000 67 #define wxMINIMIZE wxICONIZE 68 #define wxMAXIMIZE 0x2000 69 #define wxCLOSE_BOX 0x1000 // == wxHELP so can't be used with it 70 71 #define wxSYSTEM_MENU 0x0800 72 #define wxMINIMIZE_BOX 0x0400 73 #define wxMAXIMIZE_BOX 0x0200 74 75 #define wxTINY_CAPTION 0x0080 // clashes with wxNO_DEFAULT 76 #define wxRESIZE_BORDER 0x0040 // == wxCLOSE 77 78 #if WXWIN_COMPATIBILITY_2_8 79 // HORIZ and VERT styles are equivalent anyhow so don't use different names 80 // for them 81 #define wxTINY_CAPTION_HORIZ wxTINY_CAPTION 82 #define wxTINY_CAPTION_VERT wxTINY_CAPTION 83 #endif 84 85 // default style 86 #define wxDEFAULT_FRAME_STYLE \ 87 (wxSYSTEM_MENU | \ 88 wxRESIZE_BORDER | \ 89 wxMINIMIZE_BOX | \ 90 wxMAXIMIZE_BOX | \ 91 wxCLOSE_BOX | \ 92 wxCAPTION | \ 93 wxCLIP_CHILDREN) 94 95 96 // Dialogs are created in a special way 97 #define wxTOPLEVEL_EX_DIALOG 0x00000008 98 99 // Styles for ShowFullScreen 100 // (note that wxTopLevelWindow only handles wxFULLSCREEN_NOBORDER and 101 // wxFULLSCREEN_NOCAPTION; the rest is handled by wxTopLevelWindow) 102 enum 103 { 104 wxFULLSCREEN_NOMENUBAR = 0x0001, 105 wxFULLSCREEN_NOTOOLBAR = 0x0002, 106 wxFULLSCREEN_NOSTATUSBAR = 0x0004, 107 wxFULLSCREEN_NOBORDER = 0x0008, 108 wxFULLSCREEN_NOCAPTION = 0x0010, 109 110 wxFULLSCREEN_ALL = wxFULLSCREEN_NOMENUBAR | wxFULLSCREEN_NOTOOLBAR | 111 wxFULLSCREEN_NOSTATUSBAR | wxFULLSCREEN_NOBORDER | 112 wxFULLSCREEN_NOCAPTION 113 }; 114 115 // Styles for RequestUserAttention 116 enum 117 { 118 wxUSER_ATTENTION_INFO = 1, 119 wxUSER_ATTENTION_ERROR = 2 120 }; 121 122 // ---------------------------------------------------------------------------- 123 // wxTopLevelWindow: a top level (as opposed to child) window 124 // ---------------------------------------------------------------------------- 125 126 class WXDLLIMPEXP_CORE wxTopLevelWindowBase : public wxNonOwnedWindow 127 { 128 public: 129 // construction 130 wxTopLevelWindowBase(); 131 virtual ~wxTopLevelWindowBase(); 132 133 // top level wnd state 134 // -------------------- 135 136 // maximize = true => maximize, otherwise - restore 137 virtual void Maximize(bool maximize = true) = 0; 138 139 // undo Maximize() or Iconize() 140 virtual void Restore() = 0; 141 142 // iconize = true => iconize, otherwise - restore 143 virtual void Iconize(bool iconize = true) = 0; 144 145 // return true if the frame is maximized 146 virtual bool IsMaximized() const = 0; 147 148 // return true if the frame is always maximized 149 // due to native guidelines or current policy 150 virtual bool IsAlwaysMaximized() const; 151 152 // return true if the frame is iconized 153 virtual bool IsIconized() const = 0; 154 155 // get the frame icon 156 wxIcon GetIcon() const; 157 158 // get the frame icons GetIcons()159 const wxIconBundle& GetIcons() const { return m_icons; } 160 161 // set the frame icon: implemented in terms of SetIcons() 162 void SetIcon(const wxIcon& icon); 163 164 // set the frame icons SetIcons(const wxIconBundle & icons)165 virtual void SetIcons(const wxIconBundle& icons) { m_icons = icons; } 166 WXUNUSED(enable)167 virtual bool EnableFullScreenView(bool WXUNUSED(enable) = true) 168 { 169 return false; 170 } 171 172 // maximize the window to cover entire screen 173 virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) = 0; 174 175 // shows the window, but doesn't activate it. If the base code is being run, 176 // it means the port doesn't implement this method yet and so alert the user. ShowWithoutActivating()177 virtual void ShowWithoutActivating() { 178 wxFAIL_MSG("ShowWithoutActivating not implemented on this platform."); 179 } 180 181 // return true if the frame is in fullscreen mode 182 virtual bool IsFullScreen() const = 0; 183 184 // the title of the top level window: the text which the 185 // window shows usually at the top of the frame/dialog in dedicated bar 186 virtual void SetTitle(const wxString& title) = 0; 187 virtual wxString GetTitle() const = 0; 188 189 // enable/disable close button [x] WXUNUSED(enable)190 virtual bool EnableCloseButton(bool WXUNUSED(enable) = true) { return false; } WXUNUSED(enable)191 virtual bool EnableMaximizeButton(bool WXUNUSED(enable) = true) { return false; } WXUNUSED(enable)192 virtual bool EnableMinimizeButton(bool WXUNUSED(enable) = true) { return false; } 193 194 // Attracts the users attention to this window if the application is 195 // inactive (should be called when a background event occurs) 196 virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO); 197 198 // Is this the active frame (highlighted in the taskbar)? 199 // 200 // A TLW is active only if it contains the currently focused window. IsActive()201 virtual bool IsActive() { return IsDescendant(FindFocus()); } 202 203 // this function may be overridden to return false to allow closing the 204 // application even when this top level window is still open 205 // 206 // notice that the window is still closed prior to the application exit and 207 // so it can still veto it even if it returns false from here ShouldPreventAppExit()208 virtual bool ShouldPreventAppExit() const { return true; } 209 210 // centre the window on screen: this is just a shortcut 211 void CentreOnScreen(int dir = wxBOTH) { DoCentre(dir | wxCENTRE_ON_SCREEN); } 212 void CenterOnScreen(int dir = wxBOTH) { CentreOnScreen(dir); } 213 214 // Get the default size for a new top level window. This is used when 215 // creating a wxTLW under some platforms if no explicit size given. 216 static wxSize GetDefaultSize(); 217 218 219 // default item access: we have a permanent default item which is the one 220 // set by the user code but we may also have a temporary default item which 221 // would be chosen if the user pressed "Enter" now but the default action 222 // reverts to the "permanent" default as soon as this temporary default 223 // item loses focus 224 225 // get the default item, temporary or permanent GetDefaultItem()226 wxWindow *GetDefaultItem() const 227 { return m_winTmpDefault ? m_winTmpDefault : m_winDefault; } 228 229 // set the permanent default item, return the old default SetDefaultItem(wxWindow * win)230 wxWindow *SetDefaultItem(wxWindow *win) 231 { wxWindow *old = GetDefaultItem(); m_winDefault = win; return old; } 232 233 // return the temporary default item, can be NULL GetTmpDefaultItem()234 wxWindow *GetTmpDefaultItem() const { return m_winTmpDefault; } 235 236 // set a temporary default item, SetTmpDefaultItem(NULL) should be called 237 // soon after a call to SetTmpDefaultItem(window), return the old default SetTmpDefaultItem(wxWindow * win)238 wxWindow *SetTmpDefaultItem(wxWindow *win) 239 { wxWindow *old = GetDefaultItem(); m_winTmpDefault = win; return old; } 240 241 242 // Class for saving/restoring fields describing the window geometry. 243 // 244 // This class is used by the functions below to allow saving the geometry 245 // of the window and restoring it later. The components describing geometry 246 // are platform-dependent, so there is no struct containing them and 247 // instead the methods of this class are used to save or [try to] restore 248 // whichever components are used under the current platform. 249 class GeometrySerializer 250 { 251 public: ~GeometrySerializer()252 virtual ~GeometrySerializer() {} 253 254 // If saving a field returns false, it's fatal error and SaveGeometry() 255 // will return false. 256 virtual bool SaveField(const wxString& name, int value) const = 0; 257 258 // If restoring a field returns false, it just means that the field is 259 // not present and RestoreToGeometry() still continues with restoring 260 // the other values. 261 virtual bool RestoreField(const wxString& name, int* value) = 0; 262 }; 263 264 // Save the current window geometry using the provided serializer and 265 // restore the window to the previously saved geometry. 266 bool SaveGeometry(const GeometrySerializer& ser) const; 267 bool RestoreToGeometry(GeometrySerializer& ser); 268 269 270 // implementation only from now on 271 // ------------------------------- 272 273 // override some base class virtuals 274 virtual bool Destroy() wxOVERRIDE; IsTopLevel()275 virtual bool IsTopLevel() const wxOVERRIDE { return true; } 276 virtual bool IsTopNavigationDomain(NavigationKind kind) const wxOVERRIDE; IsVisible()277 virtual bool IsVisible() const { return IsShown(); } 278 279 // override to do TLW-specific layout: we resize our unique child to fill 280 // the entire client area 281 virtual bool Layout() wxOVERRIDE; 282 283 // event handlers 284 void OnCloseWindow(wxCloseEvent& event); OnSize(wxSizeEvent & WXUNUSED (event))285 void OnSize(wxSizeEvent& WXUNUSED(event)) { Layout(); } 286 287 // Get rect to be used to center top-level children 288 virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h); 289 290 // this should go away, but for now it's called from docview.cpp, 291 // so should be there for all platforms OnActivate(wxActivateEvent & WXUNUSED (event))292 void OnActivate(wxActivateEvent &WXUNUSED(event)) { } 293 294 // do the window-specific processing after processing the update event 295 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) wxOVERRIDE ; 296 297 // a different API for SetSizeHints 298 virtual void SetMinSize(const wxSize& minSize) wxOVERRIDE; 299 virtual void SetMaxSize(const wxSize& maxSize) wxOVERRIDE; 300 OSXSetModified(bool modified)301 virtual void OSXSetModified(bool modified) { m_modified = modified; } OSXIsModified()302 virtual bool OSXIsModified() const { return m_modified; } 303 SetRepresentedFilename(const wxString & WXUNUSED (filename))304 virtual void SetRepresentedFilename(const wxString& WXUNUSED(filename)) { } 305 306 protected: 307 // the frame client to screen translation should take account of the 308 // toolbar which may shift the origin of the client area 309 virtual void DoClientToScreen(int *x, int *y) const wxOVERRIDE; 310 virtual void DoScreenToClient(int *x, int *y) const wxOVERRIDE; 311 312 // add support for wxCENTRE_ON_SCREEN 313 virtual void DoCentre(int dir) wxOVERRIDE; 314 315 // no need to do client to screen translation to get our position in screen 316 // coordinates: this is already the case DoGetScreenPosition(int * x,int * y)317 virtual void DoGetScreenPosition(int *x, int *y) const wxOVERRIDE 318 { 319 DoGetPosition(x, y); 320 } 321 322 // test whether this window makes part of the frame 323 // (menubar, toolbar and statusbar are excluded from automatic layout) IsOneOfBars(const wxWindow * WXUNUSED (win))324 virtual bool IsOneOfBars(const wxWindow *WXUNUSED(win)) const 325 { return false; } 326 327 // check if we should exit the program after deleting this window 328 bool IsLastBeforeExit() const; 329 330 // send the iconize event, return true if processed 331 bool SendIconizeEvent(bool iconized = true); 332 333 // this method is only kept for compatibility, call Layout() instead. DoLayout()334 void DoLayout() { Layout(); } 335 WidthDefault(int w)336 static int WidthDefault(int w) { return w == wxDefaultCoord ? GetDefaultSize().x : w; } HeightDefault(int h)337 static int HeightDefault(int h) { return h == wxDefaultCoord ? GetDefaultSize().y : h; } 338 339 340 // the frame icon 341 wxIconBundle m_icons; 342 343 // a default window (usually a button) or NULL 344 wxWindowRef m_winDefault; 345 346 // a temporary override of m_winDefault, use the latter if NULL 347 wxWindowRef m_winTmpDefault; 348 349 bool m_modified; 350 351 wxDECLARE_NO_COPY_CLASS(wxTopLevelWindowBase); 352 wxDECLARE_EVENT_TABLE(); 353 }; 354 355 356 // include the real class declaration 357 #if defined(__WXMSW__) 358 #include "wx/msw/toplevel.h" 359 #define wxTopLevelWindowNative wxTopLevelWindowMSW 360 #elif defined(__WXGTK20__) 361 #include "wx/gtk/toplevel.h" 362 #define wxTopLevelWindowNative wxTopLevelWindowGTK 363 #elif defined(__WXGTK__) 364 #include "wx/gtk1/toplevel.h" 365 #define wxTopLevelWindowNative wxTopLevelWindowGTK 366 #elif defined(__WXX11__) 367 #include "wx/x11/toplevel.h" 368 #define wxTopLevelWindowNative wxTopLevelWindowX11 369 #elif defined(__WXDFB__) 370 #include "wx/dfb/toplevel.h" 371 #define wxTopLevelWindowNative wxTopLevelWindowDFB 372 #elif defined(__WXMAC__) 373 #include "wx/osx/toplevel.h" 374 #define wxTopLevelWindowNative wxTopLevelWindowMac 375 #elif defined(__WXMOTIF__) 376 #include "wx/motif/toplevel.h" 377 #define wxTopLevelWindowNative wxTopLevelWindowMotif 378 #elif defined(__WXQT__) 379 #include "wx/qt/toplevel.h" 380 #define wxTopLevelWindowNative wxTopLevelWindowQt 381 #endif 382 383 #ifdef __WXUNIVERSAL__ 384 #include "wx/univ/toplevel.h" 385 #else // !__WXUNIVERSAL__ 386 class WXDLLIMPEXP_CORE wxTopLevelWindow : public wxTopLevelWindowNative 387 { 388 public: 389 // construction wxTopLevelWindow()390 wxTopLevelWindow() { } 391 wxTopLevelWindow(wxWindow *parent, 392 wxWindowID winid, 393 const wxString& title, 394 const wxPoint& pos = wxDefaultPosition, 395 const wxSize& size = wxDefaultSize, 396 long style = wxDEFAULT_FRAME_STYLE, 397 const wxString& name = wxASCII_STR(wxFrameNameStr)) wxTopLevelWindowNative(parent,winid,title,pos,size,style,name)398 : wxTopLevelWindowNative(parent, winid, title, 399 pos, size, style, name) 400 { 401 } 402 403 wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxTopLevelWindow); 404 }; 405 #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__ 406 407 #endif // _WX_TOPLEVEL_BASE_H_ 408