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