frame.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/frame.h
  3. // Purpose: wxFrame class interface
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 15.11.99
  7. // Copyright: (c) wxWidgets team
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_FRAME_H_BASE_
  11. #define _WX_FRAME_H_BASE_
  12. // ----------------------------------------------------------------------------
  13. // headers
  14. // ----------------------------------------------------------------------------
  15. #include "wx/toplevel.h" // the base class
  16. #include "wx/statusbr.h"
  17. // the default names for various classs
  18. extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusLineNameStr[];
  19. extern WXDLLIMPEXP_DATA_CORE(const char) wxToolBarNameStr[];
  20. class WXDLLIMPEXP_FWD_CORE wxFrame;
  21. class WXDLLIMPEXP_FWD_CORE wxMenuBar;
  22. class WXDLLIMPEXP_FWD_CORE wxMenuItem;
  23. class WXDLLIMPEXP_FWD_CORE wxStatusBar;
  24. class WXDLLIMPEXP_FWD_CORE wxToolBar;
  25. // ----------------------------------------------------------------------------
  26. // constants
  27. // ----------------------------------------------------------------------------
  28. // wxFrame-specific (i.e. not for wxDialog) styles
  29. //
  30. // Also see the bit summary table in wx/toplevel.h.
  31. #define wxFRAME_NO_TASKBAR 0x0002 // No taskbar button (MSW only)
  32. #define wxFRAME_TOOL_WINDOW 0x0004 // No taskbar button, no system menu
  33. #define wxFRAME_FLOAT_ON_PARENT 0x0008 // Always above its parent
  34. // ----------------------------------------------------------------------------
  35. // wxFrame is a top-level window with optional menubar, statusbar and toolbar
  36. //
  37. // For each of *bars, a frame may have several of them, but only one is
  38. // managed by the frame, i.e. resized/moved when the frame is and whose size
  39. // is accounted for in client size calculations - all others should be taken
  40. // care of manually. The CreateXXXBar() functions create this, main, XXXBar,
  41. // but the actual creation is done in OnCreateXXXBar() functions which may be
  42. // overridden to create custom objects instead of standard ones when
  43. // CreateXXXBar() is called.
  44. // ----------------------------------------------------------------------------
  45. class WXDLLIMPEXP_CORE wxFrameBase : public wxTopLevelWindow
  46. {
  47. public:
  48. // construction
  49. wxFrameBase();
  50. virtual ~wxFrameBase();
  51. wxFrame *New(wxWindow *parent,
  52. wxWindowID winid,
  53. const wxString& title,
  54. const wxPoint& pos = wxDefaultPosition,
  55. const wxSize& size = wxDefaultSize,
  56. long style = wxDEFAULT_FRAME_STYLE,
  57. const wxString& name = wxFrameNameStr);
  58. // frame state
  59. // -----------
  60. // get the origin of the client area (which may be different from (0, 0)
  61. // if the frame has a toolbar) in client coordinates
  62. virtual wxPoint GetClientAreaOrigin() const;
  63. // menu bar functions
  64. // ------------------
  65. #if wxUSE_MENUS
  66. virtual void SetMenuBar(wxMenuBar *menubar);
  67. virtual wxMenuBar *GetMenuBar() const { return m_frameMenuBar; }
  68. // find the item by id in the frame menu bar: this is an internal function
  69. // and exists mainly in order to be overridden in the MDI parent frame
  70. // which also looks at its active child menu bar
  71. virtual wxMenuItem *FindItemInMenuBar(int menuId) const;
  72. // generate menu command corresponding to the given menu item
  73. //
  74. // returns true if processed
  75. bool ProcessCommand(wxMenuItem *item);
  76. // generate menu command corresponding to the given menu command id
  77. //
  78. // returns true if processed
  79. bool ProcessCommand(int winid);
  80. #else
  81. bool ProcessCommand(int WXUNUSED(winid)) { return false; }
  82. #endif // wxUSE_MENUS
  83. // status bar functions
  84. // --------------------
  85. #if wxUSE_STATUSBAR
  86. // create the main status bar by calling OnCreateStatusBar()
  87. virtual wxStatusBar* CreateStatusBar(int number = 1,
  88. long style = wxSTB_DEFAULT_STYLE,
  89. wxWindowID winid = 0,
  90. const wxString& name = wxStatusLineNameStr);
  91. // return a new status bar
  92. virtual wxStatusBar *OnCreateStatusBar(int number,
  93. long style,
  94. wxWindowID winid,
  95. const wxString& name);
  96. // get the main status bar
  97. virtual wxStatusBar *GetStatusBar() const { return m_frameStatusBar; }
  98. // sets the main status bar
  99. virtual void SetStatusBar(wxStatusBar *statBar);
  100. // forward these to status bar
  101. virtual void SetStatusText(const wxString &text, int number = 0);
  102. virtual void SetStatusWidths(int n, const int widths_field[]);
  103. void PushStatusText(const wxString &text, int number = 0);
  104. void PopStatusText(int number = 0);
  105. // set the status bar pane the help will be shown in
  106. void SetStatusBarPane(int n) { m_statusBarPane = n; }
  107. int GetStatusBarPane() const { return m_statusBarPane; }
  108. #endif // wxUSE_STATUSBAR
  109. // toolbar functions
  110. // -----------------
  111. #if wxUSE_TOOLBAR
  112. // create main toolbar bycalling OnCreateToolBar()
  113. virtual wxToolBar* CreateToolBar(long style = -1,
  114. wxWindowID winid = wxID_ANY,
  115. const wxString& name = wxToolBarNameStr);
  116. // return a new toolbar
  117. virtual wxToolBar *OnCreateToolBar(long style,
  118. wxWindowID winid,
  119. const wxString& name );
  120. // get/set the main toolbar
  121. virtual wxToolBar *GetToolBar() const { return m_frameToolBar; }
  122. virtual void SetToolBar(wxToolBar *toolbar);
  123. #endif // wxUSE_TOOLBAR
  124. // implementation only from now on
  125. // -------------------------------
  126. // event handlers
  127. #if wxUSE_MENUS
  128. #if wxUSE_STATUSBAR
  129. void OnMenuOpen(wxMenuEvent& event);
  130. void OnMenuClose(wxMenuEvent& event);
  131. void OnMenuHighlight(wxMenuEvent& event);
  132. #endif // wxUSE_STATUSBAR
  133. // send wxUpdateUIEvents for all menu items in the menubar,
  134. // or just for menu if non-NULL
  135. virtual void DoMenuUpdates(wxMenu* menu = NULL);
  136. #endif // wxUSE_MENUS
  137. // do the UI update processing for this window
  138. virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
  139. // Implement internal behaviour (menu updating on some platforms)
  140. virtual void OnInternalIdle();
  141. #if wxUSE_MENUS || wxUSE_TOOLBAR
  142. // show help text for the currently selected menu or toolbar item
  143. // (typically in the status bar) or hide it and restore the status bar text
  144. // originally shown before the menu was opened if show == false
  145. virtual void DoGiveHelp(const wxString& text, bool show);
  146. #endif
  147. virtual bool IsClientAreaChild(const wxWindow *child) const
  148. {
  149. return !IsOneOfBars(child) && wxTopLevelWindow::IsClientAreaChild(child);
  150. }
  151. protected:
  152. // the frame main menu/status/tool bars
  153. // ------------------------------------
  154. // this (non virtual!) function should be called from dtor to delete the
  155. // main menubar, statusbar and toolbar (if any)
  156. void DeleteAllBars();
  157. // test whether this window makes part of the frame
  158. virtual bool IsOneOfBars(const wxWindow *win) const;
  159. #if wxUSE_MENUS
  160. // override to update menu bar position when the frame size changes
  161. virtual void PositionMenuBar() { }
  162. // override to do something special when the menu bar is being removed
  163. // from the frame
  164. virtual void DetachMenuBar();
  165. // override to do something special when the menu bar is attached to the
  166. // frame
  167. virtual void AttachMenuBar(wxMenuBar *menubar);
  168. // Return true if we should update the menu item state from idle event
  169. // handler or false if we should delay it until the menu is opened.
  170. static bool ShouldUpdateMenuFromIdle();
  171. wxMenuBar *m_frameMenuBar;
  172. #endif // wxUSE_MENUS
  173. #if wxUSE_STATUSBAR && (wxUSE_MENUS || wxUSE_TOOLBAR)
  174. // the saved status bar text overwritten by DoGiveHelp()
  175. wxString m_oldStatusText;
  176. // the last help string we have shown in the status bar
  177. wxString m_lastHelpShown;
  178. #endif
  179. #if wxUSE_STATUSBAR
  180. // override to update status bar position (or anything else) when
  181. // something changes
  182. virtual void PositionStatusBar() { }
  183. // show the help string for the given menu item using DoGiveHelp() if the
  184. // given item does have a help string (as determined by FindInMenuBar()),
  185. // return false if there is no help for such item
  186. bool ShowMenuHelp(int helpid);
  187. wxStatusBar *m_frameStatusBar;
  188. #endif // wxUSE_STATUSBAR
  189. int m_statusBarPane;
  190. #if wxUSE_TOOLBAR
  191. // override to update status bar position (or anything else) when
  192. // something changes
  193. virtual void PositionToolBar() { }
  194. wxToolBar *m_frameToolBar;
  195. #endif // wxUSE_TOOLBAR
  196. #if wxUSE_MENUS && wxUSE_STATUSBAR
  197. DECLARE_EVENT_TABLE()
  198. #endif // wxUSE_MENUS && wxUSE_STATUSBAR
  199. wxDECLARE_NO_COPY_CLASS(wxFrameBase);
  200. };
  201. // include the real class declaration
  202. #if defined(__WXUNIVERSAL__) // && !defined(__WXMICROWIN__)
  203. #include "wx/univ/frame.h"
  204. #else // !__WXUNIVERSAL__
  205. #if defined(__WXMSW__)
  206. #include "wx/msw/frame.h"
  207. #elif defined(__WXGTK20__)
  208. #include "wx/gtk/frame.h"
  209. #elif defined(__WXGTK__)
  210. #include "wx/gtk1/frame.h"
  211. #elif defined(__WXMOTIF__)
  212. #include "wx/motif/frame.h"
  213. #elif defined(__WXMAC__)
  214. #include "wx/osx/frame.h"
  215. #elif defined(__WXCOCOA__)
  216. #include "wx/cocoa/frame.h"
  217. #elif defined(__WXPM__)
  218. #include "wx/os2/frame.h"
  219. #endif
  220. #endif
  221. #endif
  222. // _WX_FRAME_H_BASE_