mdig.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/mdig.h
  3. // Purpose: Generic MDI (Multiple Document Interface) classes
  4. // Author: Hans Van Leemputten
  5. // Modified by: 2008-10-31 Vadim Zeitlin: derive from the base classes
  6. // Created: 29/07/2002
  7. // Copyright: (c) 2002 Hans Van Leemputten
  8. // (c) 2008 Vadim Zeitlin
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_GENERIC_MDIG_H_
  12. #define _WX_GENERIC_MDIG_H_
  13. // ----------------------------------------------------------------------------
  14. // headers
  15. // ----------------------------------------------------------------------------
  16. #include "wx/panel.h"
  17. class WXDLLIMPEXP_FWD_CORE wxBookCtrlBase;
  18. class WXDLLIMPEXP_FWD_CORE wxBookCtrlEvent;
  19. class WXDLLIMPEXP_FWD_CORE wxIcon;
  20. class WXDLLIMPEXP_FWD_CORE wxIconBundle;
  21. class WXDLLIMPEXP_FWD_CORE wxNotebook;
  22. #if wxUSE_GENERIC_MDI_AS_NATIVE
  23. #define wxGenericMDIParentFrame wxMDIParentFrame
  24. #define wxGenericMDIChildFrame wxMDIChildFrame
  25. #define wxGenericMDIClientWindow wxMDIClientWindow
  26. #else // !wxUSE_GENERIC_MDI_AS_NATIVE
  27. class WXDLLIMPEXP_FWD_CORE wxGenericMDIParentFrame;
  28. class WXDLLIMPEXP_FWD_CORE wxGenericMDIChildFrame;
  29. class WXDLLIMPEXP_FWD_CORE wxGenericMDIClientWindow;
  30. #endif // wxUSE_GENERIC_MDI_AS_NATIVE/!wxUSE_GENERIC_MDI_AS_NATIVE
  31. // ----------------------------------------------------------------------------
  32. // wxGenericMDIParentFrame
  33. // ----------------------------------------------------------------------------
  34. class WXDLLIMPEXP_CORE wxGenericMDIParentFrame : public wxMDIParentFrameBase
  35. {
  36. public:
  37. wxGenericMDIParentFrame() { Init(); }
  38. wxGenericMDIParentFrame(wxWindow *parent,
  39. wxWindowID winid,
  40. const wxString& title,
  41. const wxPoint& pos = wxDefaultPosition,
  42. const wxSize& size = wxDefaultSize,
  43. long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
  44. const wxString& name = wxFrameNameStr)
  45. {
  46. Init();
  47. Create(parent, winid, title, pos, size, style, name);
  48. }
  49. bool Create(wxWindow *parent,
  50. wxWindowID winid,
  51. const wxString& title,
  52. const wxPoint& pos = wxDefaultPosition,
  53. const wxSize& size = wxDefaultSize,
  54. long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
  55. const wxString& name = wxFrameNameStr);
  56. virtual ~wxGenericMDIParentFrame();
  57. // implement base class pure virtuals
  58. static bool IsTDI() { return true; }
  59. virtual void ActivateNext() { AdvanceActive(true); }
  60. virtual void ActivatePrevious() { AdvanceActive(false); }
  61. #if wxUSE_MENUS
  62. virtual void SetWindowMenu(wxMenu* pMenu);
  63. virtual void SetMenuBar(wxMenuBar *pMenuBar);
  64. #endif // wxUSE_MENUS
  65. virtual wxGenericMDIClientWindow *OnCreateGenericClient();
  66. // implementation only from now on
  67. void WXSetChildMenuBar(wxGenericMDIChildFrame *child);
  68. void WXUpdateChildTitle(wxGenericMDIChildFrame *child);
  69. void WXActivateChild(wxGenericMDIChildFrame *child);
  70. void WXRemoveChild(wxGenericMDIChildFrame *child);
  71. bool WXIsActiveChild(wxGenericMDIChildFrame *child) const;
  72. bool WXIsInsideChildHandler(wxGenericMDIChildFrame *child) const;
  73. // return the book control used by the client window to manage the pages
  74. wxBookCtrlBase *GetBookCtrl() const;
  75. protected:
  76. #if wxUSE_MENUS
  77. wxMenuBar *m_pMyMenuBar;
  78. #endif // wxUSE_MENUS
  79. // advance the activation forward or backwards
  80. void AdvanceActive(bool forward);
  81. private:
  82. void Init();
  83. #if wxUSE_MENUS
  84. void RemoveWindowMenu(wxMenuBar *pMenuBar);
  85. void AddWindowMenu(wxMenuBar *pMenuBar);
  86. void OnWindowMenu(wxCommandEvent& event);
  87. #endif // wxUSE_MENUS
  88. virtual bool ProcessEvent(wxEvent& event);
  89. void OnClose(wxCloseEvent& event);
  90. // return the client window, may be NULL if we hadn't been created yet
  91. wxGenericMDIClientWindow *GetGenericClientWindow() const;
  92. // close all children, return false if any of them vetoed it
  93. bool CloseAll();
  94. // this pointer is non-NULL if we're currently inside our ProcessEvent()
  95. // and we forwarded the event to this child (as we do with menu events)
  96. wxMDIChildFrameBase *m_childHandler;
  97. DECLARE_EVENT_TABLE()
  98. DECLARE_DYNAMIC_CLASS(wxGenericMDIParentFrame)
  99. };
  100. // ----------------------------------------------------------------------------
  101. // wxGenericMDIChildFrame
  102. // ----------------------------------------------------------------------------
  103. class WXDLLIMPEXP_CORE wxGenericMDIChildFrame : public wxTDIChildFrame
  104. {
  105. public:
  106. wxGenericMDIChildFrame() { Init(); }
  107. wxGenericMDIChildFrame(wxGenericMDIParentFrame *parent,
  108. wxWindowID winid,
  109. const wxString& title,
  110. const wxPoint& pos = wxDefaultPosition,
  111. const wxSize& size = wxDefaultSize,
  112. long style = wxDEFAULT_FRAME_STYLE,
  113. const wxString& name = wxFrameNameStr)
  114. {
  115. Init();
  116. Create(parent, winid, title, pos, size, style, name);
  117. }
  118. bool Create(wxGenericMDIParentFrame *parent,
  119. wxWindowID winid,
  120. const wxString& title,
  121. const wxPoint& pos = wxDefaultPosition,
  122. const wxSize& size = wxDefaultSize,
  123. long style = wxDEFAULT_FRAME_STYLE,
  124. const wxString& name = wxFrameNameStr);
  125. virtual ~wxGenericMDIChildFrame();
  126. // implement MDI operations
  127. virtual void Activate();
  128. #if wxUSE_MENUS
  129. virtual void SetMenuBar( wxMenuBar *menu_bar );
  130. virtual wxMenuBar *GetMenuBar() const;
  131. #endif // wxUSE_MENUS
  132. virtual wxString GetTitle() const { return m_title; }
  133. virtual void SetTitle(const wxString& title);
  134. virtual bool TryAfter(wxEvent& event);
  135. // implementation only from now on
  136. wxGenericMDIParentFrame* GetGenericMDIParent() const
  137. {
  138. #if wxUSE_GENERIC_MDI_AS_NATIVE
  139. return GetMDIParent();
  140. #else // generic != native
  141. return m_mdiParentGeneric;
  142. #endif
  143. }
  144. protected:
  145. wxString m_title;
  146. #if wxUSE_MENUS
  147. wxMenuBar *m_pMenuBar;
  148. #endif // wxUSE_MENUS
  149. #if !wxUSE_GENERIC_MDI_AS_NATIVE
  150. wxGenericMDIParentFrame *m_mdiParentGeneric;
  151. #endif
  152. protected:
  153. void Init();
  154. private:
  155. void OnMenuHighlight(wxMenuEvent& event);
  156. void OnClose(wxCloseEvent& event);
  157. DECLARE_DYNAMIC_CLASS(wxGenericMDIChildFrame)
  158. DECLARE_EVENT_TABLE()
  159. friend class wxGenericMDIClientWindow;
  160. };
  161. // ----------------------------------------------------------------------------
  162. // wxGenericMDIClientWindow
  163. // ----------------------------------------------------------------------------
  164. class WXDLLIMPEXP_CORE wxGenericMDIClientWindow : public wxMDIClientWindowBase
  165. {
  166. public:
  167. wxGenericMDIClientWindow() { }
  168. // unfortunately we need to provide our own version of CreateClient()
  169. // because of the difference in the type of the first parameter and
  170. // implement the base class pure virtual method in terms of it
  171. // (CreateGenericClient() is virtual itself to allow customizing the client
  172. // window creation by overriding it in the derived classes)
  173. virtual bool CreateGenericClient(wxWindow *parent);
  174. virtual bool CreateClient(wxMDIParentFrame *parent,
  175. long WXUNUSED(style) = wxVSCROLL | wxHSCROLL)
  176. {
  177. return CreateGenericClient(parent);
  178. }
  179. // implementation only
  180. wxBookCtrlBase *GetBookCtrl() const;
  181. wxGenericMDIChildFrame *GetChild(size_t pos) const;
  182. int FindChild(wxGenericMDIChildFrame *child) const;
  183. private:
  184. void PageChanged(int OldSelection, int newSelection);
  185. void OnPageChanged(wxBookCtrlEvent& event);
  186. void OnSize(wxSizeEvent& event);
  187. // the notebook containing all MDI children as its pages
  188. wxNotebook *m_notebook;
  189. DECLARE_DYNAMIC_CLASS(wxGenericMDIClientWindow)
  190. };
  191. // ----------------------------------------------------------------------------
  192. // inline functions implementation
  193. // ----------------------------------------------------------------------------
  194. inline bool
  195. wxGenericMDIParentFrame::
  196. WXIsInsideChildHandler(wxGenericMDIChildFrame *child) const
  197. {
  198. return child == m_childHandler;
  199. }
  200. #endif // _WX_GENERIC_MDIG_H_