frame.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: frame.h
  3. // Purpose: interface of wxFrame
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Frame specific styles
  9. */
  10. #define wxFRAME_NO_TASKBAR 0x0002 // No taskbar button (MSW only)
  11. #define wxFRAME_TOOL_WINDOW 0x0004 // No taskbar button, no system menu
  12. #define wxFRAME_FLOAT_ON_PARENT 0x0008 // Always above its parent
  13. /**
  14. @class wxFrame
  15. A frame is a window whose size and position can (usually) be changed by the user.
  16. It usually has thick borders and a title bar, and can optionally contain a
  17. menu bar, toolbar and status bar. A frame can contain any window that is not
  18. a frame or dialog.
  19. A frame that has a status bar and toolbar, created via the CreateStatusBar() and
  20. CreateToolBar() functions, manages these windows and adjusts the value returned
  21. by GetClientSize() to reflect the remaining size available to application windows.
  22. @remarks An application should normally define an wxCloseEvent handler for the
  23. frame to respond to system close events, for example so that related
  24. data and subwindows can be cleaned up.
  25. @section frame_defaultevent Default event processing
  26. wxFrame processes the following events:
  27. @li @c wxEVT_SIZE: if the frame has exactly one child window, not counting the
  28. status and toolbar, this child is resized to take the entire frame client area.
  29. If two or more windows are present, they should be laid out explicitly either
  30. by manually handling @c wxEVT_SIZE or using sizers;
  31. @li @c wxEVT_MENU_HIGHLIGHT: the default implementation displays the help string
  32. associated with the selected item in the first pane of the status bar, if there is one.
  33. @beginStyleTable
  34. @style{wxDEFAULT_FRAME_STYLE}
  35. Defined as wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER |
  36. wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN.
  37. @style{wxICONIZE}
  38. Display the frame iconized (minimized). Windows only.
  39. @style{wxCAPTION}
  40. Puts a caption on the frame. Notice that this flag is required by
  41. wxMINIMIZE_BOX, wxMAXIMIZE_BOX and wxCLOSE_BOX on most systems as
  42. the corresponding buttons cannot be shown if the window has no title
  43. bar at all. I.e. if wxCAPTION is not specified those styles would be
  44. simply ignored.
  45. @style{wxMINIMIZE}
  46. Identical to wxICONIZE. Windows only.
  47. @style{wxMINIMIZE_BOX}
  48. Displays a minimize box on the frame.
  49. @style{wxMAXIMIZE}
  50. Displays the frame maximized. Windows and GTK+ only.
  51. @style{wxMAXIMIZE_BOX}
  52. Displays a maximize box on the frame. Notice that under wxGTK
  53. wxRESIZE_BORDER must be used as well or this style is ignored.
  54. @style{wxCLOSE_BOX}
  55. Displays a close box on the frame.
  56. @style{wxSTAY_ON_TOP}
  57. Stay on top of all other windows, see also wxFRAME_FLOAT_ON_PARENT.
  58. @style{wxSYSTEM_MENU}
  59. Displays a system menu containing the list of various windows
  60. commands in the window title bar. Unlike wxMINIMIZE_BOX,
  61. wxMAXIMIZE_BOX and wxCLOSE_BOX styles this style can be used without
  62. wxCAPTION, at least under Windows, and makes the system menu
  63. available without showing it on screen in this case. However it is
  64. recommended to only use it together with wxCAPTION for consistent
  65. behaviour under all platforms.
  66. @style{wxRESIZE_BORDER}
  67. Displays a resizable border around the window.
  68. @style{wxFRAME_TOOL_WINDOW}
  69. Causes a frame with a small title bar to be created; the frame does
  70. not appear in the taskbar under Windows or GTK+.
  71. @style{wxFRAME_NO_TASKBAR}
  72. Creates an otherwise normal frame but it does not appear in the
  73. taskbar under Windows or GTK+ (note that it will minimize to the
  74. desktop window under Windows which may seem strange to the users
  75. and thus it might be better to use this style only without
  76. wxMINIMIZE_BOX style). In wxGTK, the flag is respected only if the
  77. window manager supports _NET_WM_STATE_SKIP_TASKBAR hint.
  78. @style{wxFRAME_FLOAT_ON_PARENT}
  79. The frame will always be on top of its parent (unlike wxSTAY_ON_TOP).
  80. A frame created with this style must have a non-@NULL parent.
  81. @style{wxFRAME_SHAPED}
  82. Windows with this style are allowed to have their shape changed
  83. with the SetShape() method.
  84. @endStyleTable
  85. The default frame style is for normal, resizable frames.
  86. To create a frame which cannot be resized by user, you may use the following
  87. combination of styles:
  88. @code
  89. wxDEFAULT_FRAME_STYLE & ~(wxRESIZE_BORDER | wxMAXIMIZE_BOX)
  90. @endcode
  91. See also the @ref overview_windowstyles.
  92. @beginExtraStyleTable
  93. @style{wxFRAME_EX_CONTEXTHELP}
  94. Under Windows, puts a query button on the caption. When pressed,
  95. Windows will go into a context-sensitive help mode and wxWidgets
  96. will send a @c wxEVT_HELP event if the user clicked on an application
  97. window. Note that this is an extended style and must be set by
  98. calling SetExtraStyle before Create is called (two-step
  99. construction). You cannot use this style together with
  100. wxMAXIMIZE_BOX or wxMINIMIZE_BOX, so you should use
  101. wxDEFAULT_FRAME_STYLE ~ (wxMINIMIZE_BOX | wxMAXIMIZE_BOX) for the
  102. frames having this style (the dialogs don't have a minimize or a
  103. maximize box by default)
  104. @style{wxFRAME_EX_METAL}
  105. On Mac OS X, frames with this style will be shown with a metallic
  106. look. This is an extra style.
  107. @endExtraStyleTable
  108. @beginEventEmissionTable
  109. @event{EVT_CLOSE(func)}
  110. Process a @c wxEVT_CLOSE_WINDOW event when the frame is being
  111. closed by the user or programmatically (see wxWindow::Close).
  112. The user may generate this event clicking the close button
  113. (typically the 'X' on the top-right of the title bar) if it's present
  114. (see the @c wxCLOSE_BOX style). See wxCloseEvent.
  115. @event{EVT_ICONIZE(func)}
  116. Process a @c wxEVT_ICONIZE event. See wxIconizeEvent.
  117. @event{EVT_MENU_OPEN(func)}
  118. A menu is about to be opened. See wxMenuEvent.
  119. @event{EVT_MENU_CLOSE(func)}
  120. A menu has been just closed. See wxMenuEvent.
  121. @event{EVT_MENU_HIGHLIGHT(id, func)}
  122. The menu item with the specified id has been highlighted: used to show
  123. help prompts in the status bar by wxFrame. See wxMenuEvent.
  124. @event{EVT_MENU_HIGHLIGHT_ALL(func)}
  125. A menu item has been highlighted, i.e. the currently selected menu item has changed.
  126. See wxMenuEvent.
  127. @endEventTable
  128. @library{wxcore}
  129. @category{managedwnd}
  130. @see wxMDIParentFrame, wxMDIChildFrame, wxMiniFrame, wxDialog
  131. */
  132. class wxFrame : public wxTopLevelWindow
  133. {
  134. public:
  135. /**
  136. Default constructor.
  137. */
  138. wxFrame();
  139. /**
  140. Constructor, creating the window.
  141. @param parent
  142. The window parent. This may be @NULL. If it is non-@NULL, the frame will
  143. always be displayed on top of the parent window on Windows.
  144. @param id
  145. The window identifier. It may take a value of -1 to indicate a default value.
  146. @param title
  147. The caption to be displayed on the frame's title bar.
  148. @param pos
  149. The window position. The value wxDefaultPosition indicates a default position,
  150. chosen by either the windowing system or wxWidgets, depending on platform.
  151. @param size
  152. The window size. The value wxDefaultSize indicates a default size, chosen by
  153. either the windowing system or wxWidgets, depending on platform.
  154. @param style
  155. The window style. See wxFrame class description.
  156. @param name
  157. The name of the window. This parameter is used to associate a name with
  158. the item, allowing the application user to set Motif resource values for
  159. individual windows.
  160. @remarks For Motif, MWM (the Motif Window Manager) should be running for
  161. any window styles to work (otherwise all styles take effect).
  162. @see Create()
  163. */
  164. wxFrame(wxWindow* parent, wxWindowID id,
  165. const wxString& title,
  166. const wxPoint& pos = wxDefaultPosition,
  167. const wxSize& size = wxDefaultSize,
  168. long style = wxDEFAULT_FRAME_STYLE,
  169. const wxString& name = wxFrameNameStr);
  170. /**
  171. Destructor. Destroys all child windows and menu bar if present.
  172. See @ref overview_windowdeletion for more info.
  173. */
  174. virtual ~wxFrame();
  175. /**
  176. Centres the frame on the display.
  177. @param direction
  178. The parameter may be wxHORIZONTAL, wxVERTICAL or wxBOTH.
  179. */
  180. void Centre(int direction = wxBOTH);
  181. /**
  182. Used in two-step frame construction.
  183. See wxFrame() for further details.
  184. */
  185. bool Create(wxWindow* parent, wxWindowID id, const wxString& title,
  186. const wxPoint& pos = wxDefaultPosition,
  187. const wxSize& size = wxDefaultSize,
  188. long style = wxDEFAULT_FRAME_STYLE,
  189. const wxString& name = wxFrameNameStr);
  190. /**
  191. Creates a status bar at the bottom of the frame.
  192. @param number
  193. The number of fields to create. Specify a
  194. value greater than 1 to create a multi-field status bar.
  195. @param style
  196. The status bar style. See wxStatusBar for a list of valid styles.
  197. @param id
  198. The status bar window identifier. If -1, an identifier will be chosen
  199. by wxWidgets.
  200. @param name
  201. The status bar window name.
  202. @return A pointer to the status bar if it was created successfully, @NULL
  203. otherwise.
  204. @remarks The width of the status bar is the whole width of the frame
  205. (adjusted automatically when resizing), and the height
  206. and text size are chosen by the host windowing system.
  207. @see SetStatusText(), OnCreateStatusBar(), GetStatusBar()
  208. */
  209. virtual wxStatusBar* CreateStatusBar(int number = 1, long style = wxSTB_DEFAULT_STYLE,
  210. wxWindowID id = 0,
  211. const wxString& name = wxStatusBarNameStr);
  212. /**
  213. Creates a toolbar at the top or left of the frame.
  214. @param style
  215. The toolbar style. See wxToolBar for a list of valid styles.
  216. @param id
  217. The toolbar window identifier. If -1, an identifier will be chosen
  218. by wxWidgets.
  219. @param name
  220. The toolbar window name.
  221. @return A pointer to the toolbar if it was created successfully, @NULL
  222. otherwise.
  223. @remarks
  224. By default, the toolbar is an instance of wxToolBar.
  225. To use a different class, override OnCreateToolBar().
  226. When a toolbar has been created with this function, or made
  227. known to the frame with wxFrame::SetToolBar(), the frame will
  228. manage the toolbar position and adjust the return value from
  229. wxWindow::GetClientSize() to reflect the available space for
  230. application windows.
  231. Under Pocket PC, you should always use this function for creating
  232. the toolbar to be managed by the frame, so that wxWidgets can
  233. use a combined menubar and toolbar.
  234. Where you manage your own toolbars, create a wxToolBar as usual.
  235. @see CreateStatusBar(), OnCreateToolBar(), SetToolBar(), GetToolBar()
  236. */
  237. virtual wxToolBar* CreateToolBar(long style = wxTB_DEFAULT_STYLE,
  238. wxWindowID id = wxID_ANY,
  239. const wxString& name = wxToolBarNameStr);
  240. /**
  241. Returns the origin of the frame client area (in client coordinates).
  242. It may be different from (0, 0) if the frame has a toolbar.
  243. */
  244. virtual wxPoint GetClientAreaOrigin() const;
  245. /**
  246. Returns a pointer to the menubar currently associated with the frame (if any).
  247. @see SetMenuBar(), wxMenuBar, wxMenu
  248. */
  249. virtual wxMenuBar* GetMenuBar() const;
  250. /**
  251. Returns a pointer to the status bar currently associated with the frame
  252. (if any).
  253. @see CreateStatusBar(), wxStatusBar
  254. */
  255. virtual wxStatusBar* GetStatusBar() const;
  256. /**
  257. Returns the status bar pane used to display menu and toolbar help.
  258. @see SetStatusBarPane()
  259. */
  260. int GetStatusBarPane() const;
  261. /**
  262. Returns a pointer to the toolbar currently associated with the frame (if any).
  263. @see CreateToolBar(), wxToolBar, SetToolBar()
  264. */
  265. virtual wxToolBar* GetToolBar() const;
  266. /**
  267. Virtual function called when a status bar is requested by CreateStatusBar().
  268. @param number
  269. The number of fields to create.
  270. @param style
  271. The window style. See wxStatusBar for a list
  272. of valid styles.
  273. @param id
  274. The window identifier. If -1, an identifier will be chosen by
  275. wxWidgets.
  276. @param name
  277. The window name.
  278. @return A status bar object.
  279. @remarks An application can override this function to return a different
  280. kind of status bar. The default implementation returns
  281. an instance of wxStatusBar.
  282. @see CreateStatusBar(), wxStatusBar.
  283. */
  284. virtual wxStatusBar* OnCreateStatusBar(int number, long style,
  285. wxWindowID id,
  286. const wxString& name);
  287. /**
  288. Virtual function called when a toolbar is requested by CreateToolBar().
  289. @param style
  290. The toolbar style. See wxToolBar for a list
  291. of valid styles.
  292. @param id
  293. The toolbar window identifier. If -1, an identifier will be chosen by
  294. wxWidgets.
  295. @param name
  296. The toolbar window name.
  297. @return A toolbar object.
  298. @remarks An application can override this function to return a different
  299. kind of toolbar. The default implementation returns an
  300. instance of wxToolBar.
  301. @see CreateToolBar(), wxToolBar.
  302. */
  303. virtual wxToolBar* OnCreateToolBar(long style, wxWindowID id,
  304. const wxString& name);
  305. /**
  306. Simulate a menu command.
  307. @param id
  308. The identifier for a menu item.
  309. */
  310. bool ProcessCommand(int id);
  311. /**
  312. Tells the frame to show the given menu bar.
  313. @param menuBar
  314. The menu bar to associate with the frame.
  315. @remarks If the frame is destroyed, the menu bar and its menus will be
  316. destroyed also, so do not delete the menu bar
  317. explicitly (except by resetting the frame's menu bar to
  318. another frame or @NULL).
  319. Under Windows, a size event is generated, so be sure to
  320. initialize data members properly before calling SetMenuBar().
  321. Note that on some platforms, it is not possible to call this
  322. function twice for the same frame object.
  323. @see GetMenuBar(), wxMenuBar, wxMenu.
  324. */
  325. virtual void SetMenuBar(wxMenuBar* menuBar);
  326. /**
  327. Associates a status bar with the frame.
  328. If @a statusBar is @NULL, then the status bar, if present, is detached from
  329. the frame, but @e not deleted.
  330. @see CreateStatusBar(), wxStatusBar, GetStatusBar()
  331. */
  332. virtual void SetStatusBar(wxStatusBar* statusBar);
  333. /**
  334. Set the status bar pane used to display menu and toolbar help.
  335. Using -1 disables help display.
  336. */
  337. void SetStatusBarPane(int n);
  338. /**
  339. Sets the status bar text and redraws the status bar.
  340. @param text
  341. The text for the status field.
  342. @param number
  343. The status field (starting from zero).
  344. @remarks Use an empty string to clear the status bar.
  345. @see CreateStatusBar(), wxStatusBar
  346. */
  347. virtual void SetStatusText(const wxString& text, int number = 0);
  348. /**
  349. Sets the widths of the fields in the status bar.
  350. @param n
  351. The number of fields in the status bar. It must be the
  352. same used in CreateStatusBar.
  353. @param widths_field
  354. Must contain an array of n integers, each of which is a status field width
  355. in pixels. A value of -1 indicates that the field is variable width; at
  356. least one field must be -1. You should delete this array after calling
  357. SetStatusWidths().
  358. @remarks The widths of the variable fields are calculated from the total
  359. width of all fields, minus the sum of widths of the
  360. non-variable fields, divided by the number of variable fields.
  361. @beginWxPerlOnly
  362. In wxPerl this method takes the field widths as parameters.
  363. @endWxPerlOnly
  364. */
  365. virtual void SetStatusWidths(int n, const int* widths_field);
  366. /**
  367. Associates a toolbar with the frame.
  368. */
  369. virtual void SetToolBar(wxToolBar* toolBar);
  370. void PushStatusText(const wxString &text, int number = 0);
  371. void PopStatusText(int number = 0);
  372. };