toplevel.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. #ifndef _WX_TOPLEVEL_BASE_H_
  13. #define _WX_TOPLEVEL_BASE_H_
  14. // ----------------------------------------------------------------------------
  15. // headers
  16. // ----------------------------------------------------------------------------
  17. #include "wx/nonownedwnd.h"
  18. #include "wx/iconbndl.h"
  19. #include "wx/weakref.h"
  20. // the default names for various classes
  21. extern WXDLLIMPEXP_DATA_CORE(const char) wxFrameNameStr[];
  22. class WXDLLIMPEXP_FWD_CORE wxTopLevelWindowBase;
  23. // ----------------------------------------------------------------------------
  24. // constants
  25. // ----------------------------------------------------------------------------
  26. /*
  27. Summary of the bits used (some of them are defined in wx/frame.h and
  28. wx/dialog.h and not here):
  29. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  30. |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|
  31. +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  32. | | | | | | | | | | | | | | | |
  33. | | | | | | | | | | | | | | | \_ wxCENTRE
  34. | | | | | | | | | | | | | | \____ wxFRAME_NO_TASKBAR
  35. | | | | | | | | | | | | | \_______ wxFRAME_TOOL_WINDOW
  36. | | | | | | | | | | | | \__________ wxFRAME_FLOAT_ON_PARENT
  37. | | | | | | | | | | | \_____________ wxFRAME_SHAPED
  38. | | | | | | | | | | \________________ wxDIALOG_NO_PARENT
  39. | | | | | | | | | \___________________ wxRESIZE_BORDER
  40. | | | | | | | | \______________________ wxTINY_CAPTION_VERT
  41. | | | | | | | \_________________________
  42. | | | | | | \____________________________ wxMAXIMIZE_BOX
  43. | | | | | \_______________________________ wxMINIMIZE_BOX
  44. | | | | \__________________________________ wxSYSTEM_MENU
  45. | | | \_____________________________________ wxCLOSE_BOX
  46. | | \________________________________________ wxMAXIMIZE
  47. | \___________________________________________ wxMINIMIZE
  48. \______________________________________________ wxSTAY_ON_TOP
  49. Notice that the 8 lower bits overlap with wxCENTRE and the button selection
  50. bits (wxYES, wxOK wxNO, wxCANCEL, wxAPPLY, wxCLOSE and wxNO_DEFAULT) which
  51. can be combined with the dialog style for several standard dialogs and
  52. hence shouldn't overlap with any styles which can be used for the dialogs.
  53. Additionally, wxCENTRE can be used with frames also.
  54. */
  55. // style common to both wxFrame and wxDialog
  56. #define wxSTAY_ON_TOP 0x8000
  57. #define wxICONIZE 0x4000
  58. #define wxMINIMIZE wxICONIZE
  59. #define wxMAXIMIZE 0x2000
  60. #define wxCLOSE_BOX 0x1000 // == wxHELP so can't be used with it
  61. #define wxSYSTEM_MENU 0x0800
  62. #define wxMINIMIZE_BOX 0x0400
  63. #define wxMAXIMIZE_BOX 0x0200
  64. #define wxTINY_CAPTION 0x0080 // clashes with wxNO_DEFAULT
  65. #define wxRESIZE_BORDER 0x0040 // == wxCLOSE
  66. #if WXWIN_COMPATIBILITY_2_8
  67. // HORIZ and VERT styles are equivalent anyhow so don't use different names
  68. // for them
  69. #define wxTINY_CAPTION_HORIZ wxTINY_CAPTION
  70. #define wxTINY_CAPTION_VERT wxTINY_CAPTION
  71. #endif
  72. #if WXWIN_COMPATIBILITY_2_6
  73. // deprecated versions defined for compatibility reasons
  74. #define wxRESIZE_BOX wxMAXIMIZE_BOX
  75. #define wxTHICK_FRAME wxRESIZE_BORDER
  76. // obsolete styles, unused any more
  77. #define wxDIALOG_MODAL 0
  78. #define wxDIALOG_MODELESS 0
  79. #define wxNO_3D 0
  80. #define wxUSER_COLOURS 0
  81. #endif // WXWIN_COMPATIBILITY_2_6
  82. // default style
  83. //
  84. // under Windows CE (at least when compiling with eVC 4) we should create
  85. // top level windows without any styles at all for them to appear
  86. // "correctly", i.e. as full screen windows with a "hide" button (same as
  87. // "close" but round instead of squared and just hides the applications
  88. // instead of closing it) in the title bar
  89. #if defined(__WXWINCE__)
  90. #if defined(__SMARTPHONE__)
  91. #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE)
  92. #elif defined(__WINCE_STANDARDSDK__)
  93. #define wxDEFAULT_FRAME_STYLE (wxMAXIMIZE|wxCLOSE_BOX)
  94. #else
  95. #define wxDEFAULT_FRAME_STYLE (wxNO_BORDER)
  96. #endif
  97. #else // !__WXWINCE__
  98. #define wxDEFAULT_FRAME_STYLE \
  99. (wxSYSTEM_MENU | \
  100. wxRESIZE_BORDER | \
  101. wxMINIMIZE_BOX | \
  102. wxMAXIMIZE_BOX | \
  103. wxCLOSE_BOX | \
  104. wxCAPTION | \
  105. wxCLIP_CHILDREN)
  106. #endif
  107. // Dialogs are created in a special way
  108. #define wxTOPLEVEL_EX_DIALOG 0x00000008
  109. // Styles for ShowFullScreen
  110. // (note that wxTopLevelWindow only handles wxFULLSCREEN_NOBORDER and
  111. // wxFULLSCREEN_NOCAPTION; the rest is handled by wxTopLevelWindow)
  112. enum
  113. {
  114. wxFULLSCREEN_NOMENUBAR = 0x0001,
  115. wxFULLSCREEN_NOTOOLBAR = 0x0002,
  116. wxFULLSCREEN_NOSTATUSBAR = 0x0004,
  117. wxFULLSCREEN_NOBORDER = 0x0008,
  118. wxFULLSCREEN_NOCAPTION = 0x0010,
  119. wxFULLSCREEN_ALL = wxFULLSCREEN_NOMENUBAR | wxFULLSCREEN_NOTOOLBAR |
  120. wxFULLSCREEN_NOSTATUSBAR | wxFULLSCREEN_NOBORDER |
  121. wxFULLSCREEN_NOCAPTION
  122. };
  123. // Styles for RequestUserAttention
  124. enum
  125. {
  126. wxUSER_ATTENTION_INFO = 1,
  127. wxUSER_ATTENTION_ERROR = 2
  128. };
  129. // ----------------------------------------------------------------------------
  130. // wxTopLevelWindow: a top level (as opposed to child) window
  131. // ----------------------------------------------------------------------------
  132. class WXDLLIMPEXP_CORE wxTopLevelWindowBase : public wxNonOwnedWindow
  133. {
  134. public:
  135. // construction
  136. wxTopLevelWindowBase();
  137. virtual ~wxTopLevelWindowBase();
  138. // top level wnd state
  139. // --------------------
  140. // maximize = true => maximize, otherwise - restore
  141. virtual void Maximize(bool maximize = true) = 0;
  142. // undo Maximize() or Iconize()
  143. virtual void Restore() = 0;
  144. // iconize = true => iconize, otherwise - restore
  145. virtual void Iconize(bool iconize = true) = 0;
  146. // return true if the frame is maximized
  147. virtual bool IsMaximized() const = 0;
  148. // return true if the frame is always maximized
  149. // due to native guidelines or current policy
  150. virtual bool IsAlwaysMaximized() const;
  151. // return true if the frame is iconized
  152. virtual bool IsIconized() const = 0;
  153. // get the frame icon
  154. wxIcon GetIcon() const;
  155. // get the frame icons
  156. const wxIconBundle& GetIcons() const { return m_icons; }
  157. // set the frame icon: implemented in terms of SetIcons()
  158. void SetIcon(const wxIcon& icon);
  159. // set the frame icons
  160. virtual void SetIcons(const wxIconBundle& icons) { m_icons = icons; }
  161. // maximize the window to cover entire screen
  162. virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL) = 0;
  163. // shows the window, but doesn't activate it. If the base code is being run,
  164. // it means the port doesn't implement this method yet and so alert the user.
  165. virtual void ShowWithoutActivating() {
  166. wxFAIL_MSG("ShowWithoutActivating not implemented on this platform.");
  167. }
  168. // return true if the frame is in fullscreen mode
  169. virtual bool IsFullScreen() const = 0;
  170. // the title of the top level window: the text which the
  171. // window shows usually at the top of the frame/dialog in dedicated bar
  172. virtual void SetTitle(const wxString& title) = 0;
  173. virtual wxString GetTitle() const = 0;
  174. // enable/disable close button [x]
  175. virtual bool EnableCloseButton(bool WXUNUSED(enable) ) { return false; }
  176. // Attracts the users attention to this window if the application is
  177. // inactive (should be called when a background event occurs)
  178. virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO);
  179. // Is this the active frame (highlighted in the taskbar)?
  180. //
  181. // A TLW is active only if it contains the currently focused window.
  182. virtual bool IsActive() { return IsDescendant(FindFocus()); }
  183. // this function may be overridden to return false to allow closing the
  184. // application even when this top level window is still open
  185. //
  186. // notice that the window is still closed prior to the application exit and
  187. // so it can still veto it even if it returns false from here
  188. virtual bool ShouldPreventAppExit() const { return true; }
  189. #if defined(__SMARTPHONE__)
  190. virtual void SetLeftMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL) = 0;
  191. virtual void SetRightMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL) = 0;
  192. #endif // __SMARTPHONE__
  193. // centre the window on screen: this is just a shortcut
  194. void CentreOnScreen(int dir = wxBOTH) { DoCentre(dir | wxCENTRE_ON_SCREEN); }
  195. void CenterOnScreen(int dir = wxBOTH) { CentreOnScreen(dir); }
  196. // Get the default size for a new top level window. This is used when
  197. // creating a wxTLW under some platforms if no explicit size given.
  198. static wxSize GetDefaultSize();
  199. // default item access: we have a permanent default item which is the one
  200. // set by the user code but we may also have a temporary default item which
  201. // would be chosen if the user pressed "Enter" now but the default action
  202. // reverts to the "permanent" default as soon as this temporary default
  203. // item loses focus
  204. // get the default item, temporary or permanent
  205. wxWindow *GetDefaultItem() const
  206. { return m_winTmpDefault ? m_winTmpDefault : m_winDefault; }
  207. // set the permanent default item, return the old default
  208. wxWindow *SetDefaultItem(wxWindow *win)
  209. { wxWindow *old = GetDefaultItem(); m_winDefault = win; return old; }
  210. // return the temporary default item, can be NULL
  211. wxWindow *GetTmpDefaultItem() const { return m_winTmpDefault; }
  212. // set a temporary default item, SetTmpDefaultItem(NULL) should be called
  213. // soon after a call to SetTmpDefaultItem(window), return the old default
  214. wxWindow *SetTmpDefaultItem(wxWindow *win)
  215. { wxWindow *old = GetDefaultItem(); m_winTmpDefault = win; return old; }
  216. // implementation only from now on
  217. // -------------------------------
  218. // override some base class virtuals
  219. virtual bool Destroy();
  220. virtual bool IsTopLevel() const { return true; }
  221. virtual bool IsTopNavigationDomain() const { return true; }
  222. virtual bool IsVisible() const { return IsShown(); }
  223. // event handlers
  224. void OnCloseWindow(wxCloseEvent& event);
  225. void OnSize(wxSizeEvent& WXUNUSED(event)) { DoLayout(); }
  226. // Get rect to be used to center top-level children
  227. virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h);
  228. // this should go away, but for now it's called from docview.cpp,
  229. // so should be there for all platforms
  230. void OnActivate(wxActivateEvent &WXUNUSED(event)) { }
  231. // do the window-specific processing after processing the update event
  232. virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
  233. // a different API for SetSizeHints
  234. virtual void SetMinSize(const wxSize& minSize);
  235. virtual void SetMaxSize(const wxSize& maxSize);
  236. virtual void OSXSetModified(bool modified) { m_modified = modified; }
  237. virtual bool OSXIsModified() const { return m_modified; }
  238. virtual void SetRepresentedFilename(const wxString& WXUNUSED(filename)) { }
  239. #if wxUSE_MENUS || wxUSE_TOOLBAR
  240. // show help text for the currently selected menu or toolbar item
  241. // (typically in the status bar) or hide it and restore the status bar text
  242. // originally shown before the menu was opened if show == false
  243. virtual void DoGiveHelp(const wxString& WXUNUSED(text), bool WXUNUSED(show)) {}
  244. #endif
  245. protected:
  246. // the frame client to screen translation should take account of the
  247. // toolbar which may shift the origin of the client area
  248. virtual void DoClientToScreen(int *x, int *y) const;
  249. virtual void DoScreenToClient(int *x, int *y) const;
  250. // add support for wxCENTRE_ON_SCREEN
  251. virtual void DoCentre(int dir);
  252. // no need to do client to screen translation to get our position in screen
  253. // coordinates: this is already the case
  254. virtual void DoGetScreenPosition(int *x, int *y) const
  255. {
  256. DoGetPosition(x, y);
  257. }
  258. // test whether this window makes part of the frame
  259. // (menubar, toolbar and statusbar are excluded from automatic layout)
  260. virtual bool IsOneOfBars(const wxWindow *WXUNUSED(win)) const
  261. { return false; }
  262. // check if we should exit the program after deleting this window
  263. bool IsLastBeforeExit() const;
  264. // send the iconize event, return true if processed
  265. bool SendIconizeEvent(bool iconized = true);
  266. // do TLW-specific layout: we resize our unique child to fill the entire
  267. // client area
  268. void DoLayout();
  269. static int WidthDefault(int w) { return w == wxDefaultCoord ? GetDefaultSize().x : w; }
  270. static int HeightDefault(int h) { return h == wxDefaultCoord ? GetDefaultSize().y : h; }
  271. // the frame icon
  272. wxIconBundle m_icons;
  273. // a default window (usually a button) or NULL
  274. wxWindowRef m_winDefault;
  275. // a temporary override of m_winDefault, use the latter if NULL
  276. wxWindowRef m_winTmpDefault;
  277. bool m_modified;
  278. wxDECLARE_NO_COPY_CLASS(wxTopLevelWindowBase);
  279. DECLARE_EVENT_TABLE()
  280. };
  281. // include the real class declaration
  282. #if defined(__WXMSW__)
  283. #include "wx/msw/toplevel.h"
  284. #define wxTopLevelWindowNative wxTopLevelWindowMSW
  285. #elif defined(__WXGTK20__)
  286. #include "wx/gtk/toplevel.h"
  287. #define wxTopLevelWindowNative wxTopLevelWindowGTK
  288. #elif defined(__WXGTK__)
  289. #include "wx/gtk1/toplevel.h"
  290. #define wxTopLevelWindowNative wxTopLevelWindowGTK
  291. #elif defined(__WXX11__)
  292. #include "wx/x11/toplevel.h"
  293. #define wxTopLevelWindowNative wxTopLevelWindowX11
  294. #elif defined(__WXDFB__)
  295. #include "wx/dfb/toplevel.h"
  296. #define wxTopLevelWindowNative wxTopLevelWindowDFB
  297. #elif defined(__WXMAC__)
  298. #include "wx/osx/toplevel.h"
  299. #define wxTopLevelWindowNative wxTopLevelWindowMac
  300. #elif defined(__WXCOCOA__)
  301. #include "wx/cocoa/toplevel.h"
  302. #define wxTopLevelWindowNative wxTopLevelWindowCocoa
  303. #elif defined(__WXPM__)
  304. #include "wx/os2/toplevel.h"
  305. #define wxTopLevelWindowNative wxTopLevelWindowOS2
  306. #elif defined(__WXMOTIF__)
  307. #include "wx/motif/toplevel.h"
  308. #define wxTopLevelWindowNative wxTopLevelWindowMotif
  309. #endif
  310. #ifdef __WXUNIVERSAL__
  311. #include "wx/univ/toplevel.h"
  312. #else // !__WXUNIVERSAL__
  313. class WXDLLIMPEXP_CORE wxTopLevelWindow : public wxTopLevelWindowNative
  314. {
  315. public:
  316. // construction
  317. wxTopLevelWindow() { }
  318. wxTopLevelWindow(wxWindow *parent,
  319. wxWindowID winid,
  320. const wxString& title,
  321. const wxPoint& pos = wxDefaultPosition,
  322. const wxSize& size = wxDefaultSize,
  323. long style = wxDEFAULT_FRAME_STYLE,
  324. const wxString& name = wxFrameNameStr)
  325. : wxTopLevelWindowNative(parent, winid, title,
  326. pos, size, style, name)
  327. {
  328. }
  329. DECLARE_DYNAMIC_CLASS_NO_COPY(wxTopLevelWindow)
  330. };
  331. #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__
  332. #endif // _WX_TOPLEVEL_BASE_H_