mdi.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/mdi.h
  3. // Purpose: MDI (Multiple Document Interface) classes
  4. // Author: Julian Smart
  5. // Modified by: 2008-10-31 Vadim Zeitlin: derive from the base classes
  6. // Created: 01/02/97
  7. // Copyright: (c) 1997 Julian Smart
  8. // (c) 2008 Vadim Zeitlin
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_MSW_MDI_H_
  12. #define _WX_MSW_MDI_H_
  13. #include "wx/frame.h"
  14. class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable;
  15. // ---------------------------------------------------------------------------
  16. // wxMDIParentFrame
  17. // ---------------------------------------------------------------------------
  18. class WXDLLIMPEXP_CORE wxMDIParentFrame : public wxMDIParentFrameBase
  19. {
  20. public:
  21. wxMDIParentFrame() { Init(); }
  22. wxMDIParentFrame(wxWindow *parent,
  23. wxWindowID id,
  24. const wxString& title,
  25. const wxPoint& pos = wxDefaultPosition,
  26. const wxSize& size = wxDefaultSize,
  27. long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
  28. const wxString& name = wxFrameNameStr)
  29. {
  30. Init();
  31. Create(parent, id, title, pos, size, style, name);
  32. }
  33. virtual ~wxMDIParentFrame();
  34. bool Create(wxWindow *parent,
  35. wxWindowID id,
  36. const wxString& title,
  37. const wxPoint& pos = wxDefaultPosition,
  38. const wxSize& size = wxDefaultSize,
  39. long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
  40. const wxString& name = wxFrameNameStr);
  41. // override/implement base class [pure] virtual methods
  42. // ----------------------------------------------------
  43. static bool IsTDI() { return false; }
  44. // we don't store the active child in m_currentChild so override this
  45. // function to find it dynamically
  46. virtual wxMDIChildFrame *GetActiveChild() const;
  47. virtual void Cascade();
  48. virtual void Tile(wxOrientation orient = wxHORIZONTAL);
  49. virtual void ArrangeIcons();
  50. virtual void ActivateNext();
  51. virtual void ActivatePrevious();
  52. #if wxUSE_MENUS
  53. virtual void SetWindowMenu(wxMenu* menu);
  54. virtual void DoMenuUpdates(wxMenu* menu = NULL);
  55. // return the active child menu, if any
  56. virtual WXHMENU MSWGetActiveMenu() const;
  57. #endif // wxUSE_MENUS
  58. // implementation only from now on
  59. // MDI helpers
  60. // -----------
  61. #if wxUSE_MENUS
  62. // called by wxMDIChildFrame after it was successfully created
  63. virtual void AddMDIChild(wxMDIChildFrame *child);
  64. // called by wxMDIChildFrame just before it is destroyed
  65. virtual void RemoveMDIChild(wxMDIChildFrame *child);
  66. #endif // wxUSE_MENUS
  67. // handlers
  68. // --------
  69. // Responds to colour changes
  70. void OnSysColourChanged(wxSysColourChangedEvent& event);
  71. void OnSize(wxSizeEvent& event);
  72. void OnIconized(wxIconizeEvent& event);
  73. bool HandleActivate(int state, bool minimized, WXHWND activate);
  74. // override window proc for MDI-specific message processing
  75. virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
  76. virtual WXLRESULT MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM);
  77. virtual bool MSWTranslateMessage(WXMSG* msg);
  78. #if wxUSE_MENUS
  79. // override wxFrameBase function to also look in the active child menu bar
  80. // and the "Window" menu
  81. virtual wxMenuItem *FindItemInMenuBar(int menuId) const;
  82. #endif // wxUSE_MENUS
  83. protected:
  84. #if wxUSE_MENUS_NATIVE
  85. virtual void InternalSetMenuBar();
  86. #endif // wxUSE_MENUS_NATIVE
  87. virtual WXHICON GetDefaultIcon() const;
  88. // set the size of the MDI client window to match the frame size
  89. void UpdateClientSize();
  90. private:
  91. // common part of all ctors
  92. void Init();
  93. #if wxUSE_MENUS
  94. // "Window" menu commands event handlers
  95. void OnMDICommand(wxCommandEvent& event);
  96. void OnMDIChild(wxCommandEvent& event);
  97. // add/remove window menu if we have it (i.e. m_windowMenu != NULL)
  98. void AddWindowMenu();
  99. void RemoveWindowMenu();
  100. // update the window menu (if we have it) to enable or disable the commands
  101. // which only make sense when we have more than one child
  102. void UpdateWindowMenu(bool enable);
  103. #if wxUSE_ACCEL
  104. wxAcceleratorTable *m_accelWindowMenu;
  105. #endif // wxUSE_ACCEL
  106. #endif // wxUSE_MENUS
  107. // return the number of child frames we currently have (maybe 0)
  108. int GetChildFramesCount() const;
  109. friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame;
  110. DECLARE_EVENT_TABLE()
  111. DECLARE_DYNAMIC_CLASS(wxMDIParentFrame)
  112. wxDECLARE_NO_COPY_CLASS(wxMDIParentFrame);
  113. };
  114. // ---------------------------------------------------------------------------
  115. // wxMDIChildFrame
  116. // ---------------------------------------------------------------------------
  117. class WXDLLIMPEXP_CORE wxMDIChildFrame : public wxMDIChildFrameBase
  118. {
  119. public:
  120. wxMDIChildFrame() { Init(); }
  121. wxMDIChildFrame(wxMDIParentFrame *parent,
  122. wxWindowID id,
  123. const wxString& title,
  124. const wxPoint& pos = wxDefaultPosition,
  125. const wxSize& size = wxDefaultSize,
  126. long style = wxDEFAULT_FRAME_STYLE,
  127. const wxString& name = wxFrameNameStr)
  128. {
  129. Init();
  130. Create(parent, id, title, pos, size, style, name);
  131. }
  132. bool Create(wxMDIParentFrame *parent,
  133. wxWindowID id,
  134. const wxString& title,
  135. const wxPoint& pos = wxDefaultPosition,
  136. const wxSize& size = wxDefaultSize,
  137. long style = wxDEFAULT_FRAME_STYLE,
  138. const wxString& name = wxFrameNameStr);
  139. virtual ~wxMDIChildFrame();
  140. // implement MDI operations
  141. virtual void Activate();
  142. // Override some frame operations too
  143. virtual void Maximize(bool maximize = true);
  144. virtual void Restore();
  145. virtual bool Show(bool show = true);
  146. // Implementation only from now on
  147. // -------------------------------
  148. // Handlers
  149. bool HandleMDIActivate(long bActivate, WXHWND, WXHWND);
  150. bool HandleWindowPosChanging(void *lpPos);
  151. bool HandleGetMinMaxInfo(void *mmInfo);
  152. virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
  153. virtual WXLRESULT MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
  154. virtual bool MSWTranslateMessage(WXMSG *msg);
  155. virtual void MSWDestroyWindow();
  156. bool ResetWindowStyle(void *vrect);
  157. void OnIdle(wxIdleEvent& event);
  158. protected:
  159. virtual void DoGetScreenPosition(int *x, int *y) const;
  160. virtual void DoGetPosition(int *x, int *y) const;
  161. virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags);
  162. virtual void DoSetClientSize(int width, int height);
  163. virtual void InternalSetMenuBar();
  164. virtual bool IsMDIChild() const { return true; }
  165. virtual void DetachMenuBar();
  166. virtual WXHICON GetDefaultIcon() const;
  167. // common part of all ctors
  168. void Init();
  169. private:
  170. bool m_needsInitialShow; // Show must be called in idle time after Creation
  171. bool m_needsResize; // flag which tells us to artificially resize the frame
  172. DECLARE_EVENT_TABLE()
  173. DECLARE_DYNAMIC_CLASS_NO_COPY(wxMDIChildFrame)
  174. };
  175. // ---------------------------------------------------------------------------
  176. // wxMDIClientWindow
  177. // ---------------------------------------------------------------------------
  178. class WXDLLIMPEXP_CORE wxMDIClientWindow : public wxMDIClientWindowBase
  179. {
  180. public:
  181. wxMDIClientWindow() { Init(); }
  182. // Note: this is virtual, to allow overridden behaviour.
  183. virtual bool CreateClient(wxMDIParentFrame *parent,
  184. long style = wxVSCROLL | wxHSCROLL);
  185. // Explicitly call default scroll behaviour
  186. void OnScroll(wxScrollEvent& event);
  187. protected:
  188. virtual void DoSetSize(int x, int y,
  189. int width, int height,
  190. int sizeFlags = wxSIZE_AUTO);
  191. void Init() { m_scrollX = m_scrollY = 0; }
  192. int m_scrollX, m_scrollY;
  193. private:
  194. DECLARE_EVENT_TABLE()
  195. DECLARE_DYNAMIC_CLASS_NO_COPY(wxMDIClientWindow)
  196. };
  197. #endif // _WX_MSW_MDI_H_