toplevel.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: toplevel.h
  3. // Purpose: interface of wxTopLevelWindow
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Styles used with wxTopLevelWindow::RequestUserAttention().
  9. */
  10. enum
  11. {
  12. wxUSER_ATTENTION_INFO = 1, ///< Requests user attention,
  13. wxUSER_ATTENTION_ERROR = 2 ///< Results in a more drastic action.
  14. };
  15. /**
  16. Styles used with wxTopLevelWindow::ShowFullScreen().
  17. */
  18. enum
  19. {
  20. wxFULLSCREEN_NOMENUBAR = 0x0001, ///< Don't display the menu bar.
  21. wxFULLSCREEN_NOTOOLBAR = 0x0002, ///< Don't display toolbar bars.
  22. wxFULLSCREEN_NOSTATUSBAR = 0x0004, ///< Don't display the status bar.
  23. wxFULLSCREEN_NOBORDER = 0x0008, ///< Don't display any border.
  24. wxFULLSCREEN_NOCAPTION = 0x0010, ///< Don't display a caption.
  25. /**
  26. Combination of all above, will display the least possible.
  27. */
  28. wxFULLSCREEN_ALL = wxFULLSCREEN_NOMENUBAR | wxFULLSCREEN_NOTOOLBAR |
  29. wxFULLSCREEN_NOSTATUSBAR | wxFULLSCREEN_NOBORDER |
  30. wxFULLSCREEN_NOCAPTION
  31. };
  32. #define wxDEFAULT_FRAME_STYLE (wxSYSTEM_MENU | \
  33. wxRESIZE_BORDER | \
  34. wxMINIMIZE_BOX | \
  35. wxMAXIMIZE_BOX | \
  36. wxCLOSE_BOX | \
  37. wxCAPTION | \
  38. wxCLIP_CHILDREN)
  39. /**
  40. @class wxTopLevelWindow
  41. wxTopLevelWindow is a common base class for wxDialog and wxFrame. It is an
  42. abstract base class meaning that you never work with objects of this class
  43. directly, but all of its methods are also applicable for the two classes
  44. above.
  45. Note that the instances of wxTopLevelWindow are managed by wxWidgets in the
  46. internal top level window list.
  47. @beginEventEmissionTable
  48. @event{EVT_MAXIMIZE(id, func)}
  49. Process a @c wxEVT_MAXIMIZE event. See wxMaximizeEvent.
  50. @event{EVT_MOVE(func)}
  51. Process a @c wxEVT_MOVE event, which is generated when a window is moved.
  52. See wxMoveEvent.
  53. @event{EVT_MOVE_START(func)}
  54. Process a @c wxEVT_MOVE_START event, which is generated when the user starts
  55. to move or size a window. wxMSW only.
  56. See wxMoveEvent.
  57. @event{EVT_MOVE_END(func)}
  58. Process a @c wxEVT_MOVE_END event, which is generated when the user stops
  59. moving or sizing a window. wxMSW only.
  60. See wxMoveEvent.
  61. @event{EVT_SHOW(func)}
  62. Process a @c wxEVT_SHOW event. See wxShowEvent.
  63. @endEventTable
  64. @library{wxcore}
  65. @category{managedwnd}
  66. @see wxDialog, wxFrame
  67. */
  68. class wxTopLevelWindow : public wxNonOwnedWindow
  69. {
  70. public:
  71. /**
  72. Default ctor.
  73. */
  74. wxTopLevelWindow();
  75. /**
  76. Constructor creating the top level window.
  77. */
  78. wxTopLevelWindow(wxWindow *parent,
  79. wxWindowID id,
  80. const wxString& title,
  81. const wxPoint& pos = wxDefaultPosition,
  82. const wxSize& size = wxDefaultSize,
  83. long style = wxDEFAULT_FRAME_STYLE,
  84. const wxString& name = wxFrameNameStr);
  85. /**
  86. Destructor. Remember that wxTopLevelWindows do not get immediately
  87. destroyed when the user (or the app) closes them; they have a
  88. @b delayed destruction.
  89. See @ref overview_windowdeletion for more info.
  90. */
  91. virtual ~wxTopLevelWindow();
  92. /**
  93. Creates the top level window.
  94. */
  95. bool Create(wxWindow *parent,
  96. wxWindowID id,
  97. const wxString& title,
  98. const wxPoint& pos = wxDefaultPosition,
  99. const wxSize& size = wxDefaultSize,
  100. long style = wxDEFAULT_FRAME_STYLE,
  101. const wxString& name = wxFrameNameStr);
  102. /**
  103. Returns @true if the platform supports making the window translucent.
  104. @see SetTransparent()
  105. */
  106. virtual bool CanSetTransparent();
  107. /**
  108. A synonym for CentreOnScreen().
  109. */
  110. void CenterOnScreen(int direction = wxBOTH);
  111. /**
  112. Centres the window on screen.
  113. @param direction
  114. Specifies the direction for the centering. May be @c wxHORIZONTAL,
  115. @c wxVERTICAL or @c wxBOTH.
  116. @see wxWindow::CentreOnParent()
  117. */
  118. void CentreOnScreen(int direction = wxBOTH);
  119. /**
  120. Enables or disables the Close button (most often in the right upper
  121. corner of a dialog) and the Close entry of the system menu (most often
  122. in the left upper corner of the dialog).
  123. Currently only implemented for wxMSW and wxGTK.
  124. Returns @true if operation was successful. This may be wrong on X11
  125. (including GTK+) where the window manager may not support this operation
  126. and there is no way to find out.
  127. */
  128. virtual bool EnableCloseButton(bool enable = true);
  129. /**
  130. Returns a pointer to the button which is the default for this window, or
  131. @c @NULL. The default button is the one activated by pressing the Enter
  132. key.
  133. */
  134. wxWindow* GetDefaultItem() const;
  135. /**
  136. Get the default size for a new top level window.
  137. This is used internally by wxWidgets on some platforms to determine the
  138. default size for a window created using ::wxDefaultSize so it is not
  139. necessary to use it when creating a wxTopLevelWindow, however it may be
  140. useful if a rough estimation of the window size is needed for some
  141. other reason.
  142. @since 2.9.2
  143. */
  144. static wxSize GetDefaultSize();
  145. /**
  146. Returns the standard icon of the window. The icon will be invalid if it
  147. hadn't been previously set by SetIcon().
  148. @see GetIcons()
  149. */
  150. wxIcon GetIcon() const;
  151. /**
  152. Returns all icons associated with the window, there will be none of them
  153. if neither SetIcon() nor SetIcons() had been called before. Use
  154. GetIcon() to get the main icon of the window.
  155. @see wxIconBundle
  156. */
  157. const wxIconBundle& GetIcons() const;
  158. /**
  159. Gets a string containing the window title.
  160. @see SetTitle()
  161. */
  162. virtual wxString GetTitle() const;
  163. /**
  164. Unique to the wxWinCE port. Responds to showing/hiding SIP (soft input
  165. panel) area and resize window accordingly. Override this if you want to
  166. avoid resizing or do additional operations.
  167. */
  168. virtual bool HandleSettingChange(WXWPARAM wParam,
  169. WXLPARAM lParam);
  170. /**
  171. Iconizes or restores the window.
  172. @param iconize
  173. If @true, iconizes the window; if @false, shows and restores it.
  174. @see IsIconized(), Maximize(), wxIconizeEvent.
  175. */
  176. virtual void Iconize(bool iconize = true);
  177. /**
  178. Returns @true if this window is currently active, i.e.\ if the user is
  179. currently working with it.
  180. */
  181. virtual bool IsActive();
  182. /**
  183. Returns @true if this window is expected to be always maximized, either
  184. due to platform policy or due to local policy regarding particular
  185. class.
  186. */
  187. virtual bool IsAlwaysMaximized() const;
  188. /**
  189. Returns @true if the window is in fullscreen mode.
  190. @see ShowFullScreen()
  191. */
  192. virtual bool IsFullScreen() const;
  193. /**
  194. Returns @true if the window is iconized.
  195. */
  196. virtual bool IsIconized() const;
  197. /**
  198. Returns @true if the window is maximized.
  199. */
  200. virtual bool IsMaximized() const;
  201. /**
  202. This method is specific to wxUniversal port.
  203. Returns @true if this window is using native decorations, @false if we
  204. draw them ourselves.
  205. @see UseNativeDecorations(),
  206. UseNativeDecorationsByDefault()
  207. */
  208. bool IsUsingNativeDecorations() const;
  209. /**
  210. See wxWindow::SetAutoLayout(): when auto layout is on, this function gets
  211. called automatically when the window is resized.
  212. */
  213. virtual bool Layout();
  214. /**
  215. Maximizes or restores the window.
  216. @param maximize
  217. If @true, maximizes the window, otherwise it restores it.
  218. @see Iconize()
  219. */
  220. virtual void Maximize(bool maximize = true);
  221. /**
  222. MSW-specific function for accessing the system menu.
  223. Returns a wxMenu pointer representing the system menu of the window
  224. under MSW. The returned wxMenu may be used, if non-@c NULL, to add
  225. extra items to the system menu. The usual @c wxEVT_MENU
  226. events (that can be processed using @c EVT_MENU event table macro) will
  227. then be generated for them. All the other wxMenu methods may be used as
  228. well but notice that they won't allow you to access any standard system
  229. menu items (e.g. they can't be deleted or modified in any way
  230. currently).
  231. Notice that because of the native system limitations the identifiers of
  232. the items added to the system menu must be multiples of 16, otherwise
  233. no events will be generated for them.
  234. The returned pointer must @em not be deleted, it is owned by the window
  235. and will be only deleted when the window itself is destroyed.
  236. This function is not available in the other ports by design, any
  237. occurrences of it in the portable code must be guarded by
  238. @code #ifdef __WXMSW__ @endcode preprocessor guards.
  239. @since 2.9.3
  240. */
  241. wxMenu *MSWGetSystemMenu() const;
  242. /**
  243. Use a system-dependent way to attract users attention to the window when
  244. it is in background.
  245. @a flags may have the value of either @c ::wxUSER_ATTENTION_INFO
  246. (default) or @c ::wxUSER_ATTENTION_ERROR which results in a more drastic
  247. action. When in doubt, use the default value.
  248. @note This function should normally be only used when the application
  249. is not already in foreground.
  250. This function is currently implemented for Win32 where it flashes
  251. the window icon in the taskbar, and for wxGTK with task bars
  252. supporting it.
  253. */
  254. virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO);
  255. /**
  256. Changes the default item for the panel, usually @a win is a button.
  257. @see GetDefaultItem()
  258. */
  259. wxWindow* SetDefaultItem(wxWindow* win);
  260. wxWindow* SetTmpDefaultItem(wxWindow * win);
  261. wxWindow* GetTmpDefaultItem() const;
  262. /**
  263. Sets the icon for this window.
  264. @param icon
  265. The wxIcon to associate with this window.
  266. @remarks The window takes a 'copy' of @a icon, but since it uses
  267. reference counting, the copy is very quick. It is safe to
  268. delete @a icon after calling this function.
  269. @note In wxMSW, @a icon must be either 16x16 or 32x32 icon.
  270. @see wxIcon, SetIcons()
  271. */
  272. void SetIcon(const wxIcon& icon);
  273. /**
  274. Sets several icons of different sizes for this window: this allows to
  275. use different icons for different situations (e.g. task switching bar,
  276. taskbar, window title bar) instead of scaling, with possibly bad looking
  277. results, the only icon set by SetIcon().
  278. @param icons
  279. The icons to associate with this window.
  280. @note In wxMSW, @a icons must contain a 16x16 or 32x32 icon,
  281. preferably both.
  282. @see wxIconBundle
  283. */
  284. virtual void SetIcons(const wxIconBundle& icons);
  285. /**
  286. Sets action or menu activated by pressing left hardware button on the
  287. smart phones. Unavailable on full keyboard machines.
  288. @param id
  289. Identifier for this button.
  290. @param label
  291. Text to be displayed on the screen area dedicated to this hardware
  292. button.
  293. @param subMenu
  294. The menu to be opened after pressing this hardware button.
  295. @see SetRightMenu().
  296. */
  297. void SetLeftMenu(int id = wxID_ANY,
  298. const wxString& label = wxEmptyString,
  299. wxMenu* subMenu = NULL);
  300. /**
  301. A simpler interface for setting the size hints than SetSizeHints().
  302. */
  303. virtual void SetMaxSize(const wxSize& size);
  304. /**
  305. A simpler interface for setting the size hints than SetSizeHints().
  306. */
  307. virtual void SetMinSize(const wxSize& size);
  308. /**
  309. Sets action or menu activated by pressing right hardware button on the
  310. smart phones. Unavailable on full keyboard machines.
  311. @param id
  312. Identifier for this button.
  313. @param label
  314. Text to be displayed on the screen area dedicated to this hardware
  315. button.
  316. @param subMenu
  317. The menu to be opened after pressing this hardware button.
  318. @see SetLeftMenu().
  319. */
  320. void SetRightMenu(int id = wxID_ANY,
  321. const wxString& label = wxEmptyString,
  322. wxMenu* subMenu = NULL);
  323. /**
  324. Allows specification of minimum and maximum window sizes, and window
  325. size increments. If a pair of values is not set (or set to -1), no
  326. constraints will be used.
  327. @param minW
  328. The minimum width.
  329. @param minH
  330. The minimum height.
  331. @param maxW
  332. The maximum width.
  333. @param maxH
  334. The maximum height.
  335. @param incW
  336. Specifies the increment for sizing the width (GTK/Motif/Xt only).
  337. @param incH
  338. Specifies the increment for sizing the height (GTK/Motif/Xt only).
  339. @remarks Notice that this function not only prevents the user from
  340. resizing the window outside the given bounds but it also
  341. prevents the program itself from doing it using
  342. wxWindow::SetSize().
  343. */
  344. virtual void SetSizeHints(int minW, int minH,
  345. int maxW = -1, int maxH = -1,
  346. int incW = -1, int incH = -1);
  347. /**
  348. Allows specification of minimum and maximum window sizes, and window
  349. size increments. If a pair of values is not set (or set to -1), no
  350. constraints will be used.
  351. @param minSize
  352. The minimum size of the window.
  353. @param maxSize
  354. The maximum size of the window.
  355. @param incSize
  356. Increment size (only taken into account under X11-based ports such
  357. as wxGTK/wxMotif/wxX11).
  358. @remarks Notice that this function not only prevents the user from
  359. resizing the window outside the given bounds but it also
  360. prevents the program itself from doing it using
  361. wxWindow::SetSize().
  362. */
  363. void SetSizeHints(const wxSize& minSize,
  364. const wxSize& maxSize = wxDefaultSize,
  365. const wxSize& incSize = wxDefaultSize);
  366. /**
  367. Sets the window title.
  368. @param title
  369. The window title.
  370. @see GetTitle()
  371. */
  372. virtual void SetTitle(const wxString& title);
  373. /**
  374. If the platform supports it will set the window to be translucent.
  375. @param alpha
  376. Determines how opaque or transparent the window will be, if the
  377. platform supports the operation. A value of 0 sets the window to be
  378. fully transparent, and a value of 255 sets the window to be fully
  379. opaque.
  380. */
  381. virtual bool SetTransparent(wxByte alpha);
  382. /**
  383. This virtual function is not meant to be called directly but can be
  384. overridden to return @false (it returns @true by default) to allow the
  385. application to close even if this, presumably not very important, window
  386. is still opened. By default, the application stays alive as long as
  387. there are any open top level windows.
  388. */
  389. virtual bool ShouldPreventAppExit() const;
  390. /**
  391. This function sets the wxTopLevelWindow's modified state on OS X,
  392. which currently draws a black dot in the wxTopLevelWindow's close button.
  393. On other platforms, this method does nothing.
  394. @see OSXIsModified()
  395. */
  396. virtual void OSXSetModified(bool modified);
  397. /**
  398. Returns the current modified state of the wxTopLevelWindow on OS X.
  399. On other platforms, this method does nothing.
  400. @see OSXSetModified()
  401. */
  402. virtual bool OSXIsModified() const;
  403. /**
  404. Sets the file name represented by this wxTopLevelWindow.
  405. Under OS X, this file name is used to set the "proxy icon", which
  406. appears in the window title bar near its title, corresponding to this
  407. file name. Under other platforms it currently doesn't do anything but
  408. it is harmless to call it now and it might be implemented to do
  409. something useful in the future so you're encouraged to use it for any
  410. window representing a file-based document.
  411. @since 2.9.4
  412. */
  413. virtual void SetRepresentedFilename(const wxString& filename);
  414. /**
  415. Show the wxTopLevelWindow, but do not give it keyboard focus. This can be
  416. used for pop up or notification windows that should not steal the current
  417. focus.
  418. */
  419. virtual void ShowWithoutActivating();
  420. /**
  421. Depending on the value of @a show parameter the window is either shown
  422. full screen or restored to its normal state. @a style is a bit list
  423. containing some or all of the following values, which indicate what
  424. elements of the window to hide in full-screen mode:
  425. - @c ::wxFULLSCREEN_NOMENUBAR
  426. - @c ::wxFULLSCREEN_NOTOOLBAR
  427. - @c ::wxFULLSCREEN_NOSTATUSBAR
  428. - @c ::wxFULLSCREEN_NOBORDER
  429. - @c ::wxFULLSCREEN_NOCAPTION
  430. - @c ::wxFULLSCREEN_ALL (all of the above)
  431. This function has not been tested with MDI frames.
  432. @note Showing a window full screen also actually @ref wxWindow::Show()
  433. "Show()"s the window if it isn't shown.
  434. @see IsFullScreen()
  435. */
  436. virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL);
  437. /**
  438. This method is specific to wxUniversal port.
  439. Use native or custom-drawn decorations for this window only. Notice that
  440. to have any effect this method must be called before really creating the
  441. window, i.e. two step creation must be used:
  442. @code
  443. MyFrame *frame = new MyFrame; // use default ctor
  444. frame->UseNativeDecorations(false); // change from default "true"
  445. frame->Create(parent, title, ...); // really create the frame
  446. @endcode
  447. @see UseNativeDecorationsByDefault(),
  448. IsUsingNativeDecorations()
  449. */
  450. void UseNativeDecorations(bool native = true);
  451. /**
  452. This method is specific to wxUniversal port.
  453. Top level windows in wxUniversal port can use either system-provided
  454. window decorations (i.e. title bar and various icons, buttons and menus
  455. in it) or draw the decorations themselves. By default the system
  456. decorations are used if they are available, but this method can be
  457. called with @a native set to @false to change this for all windows
  458. created after this point.
  459. Also note that if @c WXDECOR environment variable is set, then custom
  460. decorations are used by default and so it may make sense to call this
  461. method with default argument if the application can't use custom
  462. decorations at all for some reason.
  463. @see UseNativeDecorations()
  464. */
  465. void UseNativeDecorationsByDefault(bool native = true);
  466. };