override TryValidator() in wxMDIParentFrame to implement forwarding of menu/toolbar...
[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
98 // override window proc for MDI-specific message processing
99 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
100
101 virtual WXLRESULT MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM);
102 virtual bool MSWTranslateMessage(WXMSG* msg);
103
104 #if wxUSE_MENUS
105 // override wxFrameBase function to also look in the active child menu bar
106 // and the "Window" menu
107 virtual wxMenuItem *FindItemInMenuBar(int menuId) const;
108 #endif // wxUSE_MENUS
109
110 protected:
111 // override to pass menu/toolbar events to the active child first
112 virtual bool TryValidator(wxEvent& event);
113
114 #if wxUSE_MENUS_NATIVE
115 virtual void InternalSetMenuBar();
116 #endif // wxUSE_MENUS_NATIVE
117
118 virtual WXHICON GetDefaultIcon() const;
119
120 // set the size of the MDI client window to match the frame size
121 void UpdateClientSize();
122
123 private:
124 #if wxUSE_MENUS
125 // "Window" menu commands event handlers
126 void OnMDICommand(wxCommandEvent& event);
127 void OnMDIChild(wxCommandEvent& event);
128
129
130 // add/remove window menu if we have it (i.e. m_windowMenu != NULL)
131 void AddWindowMenu();
132 void RemoveWindowMenu();
133
134 // update the window menu (if we have it) to enable or disable the commands
135 // which only make sense when we have more than one child
136 void UpdateWindowMenu(bool enable);
137
138 #if wxUSE_ACCEL
139 wxAcceleratorTable *m_accelWindowMenu;
140 #endif // wxUSE_ACCEL
141 #endif // wxUSE_MENUS
142
143 // return the number of child frames we currently have (maybe 0)
144 int GetChildFramesCount() const;
145
146
147 friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame;
148
149 DECLARE_EVENT_TABLE()
150 DECLARE_DYNAMIC_CLASS(wxMDIParentFrame)
151 wxDECLARE_NO_COPY_CLASS(wxMDIParentFrame);
152 };
153
154 // ---------------------------------------------------------------------------
155 // wxMDIChildFrame
156 // ---------------------------------------------------------------------------
157
158 class WXDLLIMPEXP_CORE wxMDIChildFrame : public wxMDIChildFrameBase
159 {
160 public:
161 wxMDIChildFrame() { Init(); }
162 wxMDIChildFrame(wxMDIParentFrame *parent,
163 wxWindowID id,
164 const wxString& title,
165 const wxPoint& pos = wxDefaultPosition,
166 const wxSize& size = wxDefaultSize,
167 long style = wxDEFAULT_FRAME_STYLE,
168 const wxString& name = wxFrameNameStr)
169 {
170 Init();
171
172 Create(parent, id, title, pos, size, style, name);
173 }
174
175 bool Create(wxMDIParentFrame *parent,
176 wxWindowID id,
177 const wxString& title,
178 const wxPoint& pos = wxDefaultPosition,
179 const wxSize& size = wxDefaultSize,
180 long style = wxDEFAULT_FRAME_STYLE,
181 const wxString& name = wxFrameNameStr);
182
183 virtual ~wxMDIChildFrame();
184
185 // implement MDI operations
186 virtual void Activate();
187
188 // Override some frame operations too
189 virtual void Maximize(bool maximize = true);
190 virtual void Restore();
191
192 virtual bool Show(bool show = true);
193
194 // Implementation only from now on
195 // -------------------------------
196
197 // Handlers
198 bool HandleMDIActivate(long bActivate, WXHWND, WXHWND);
199 bool HandleWindowPosChanging(void *lpPos);
200 bool HandleGetMinMaxInfo(void *mmInfo);
201
202 virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
203 virtual WXLRESULT MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
204 virtual bool MSWTranslateMessage(WXMSG *msg);
205
206 virtual void MSWDestroyWindow();
207
208 bool ResetWindowStyle(void *vrect);
209
210 void OnIdle(wxIdleEvent& event);
211
212 protected:
213 virtual void DoGetScreenPosition(int *x, int *y) const;
214 virtual void DoGetPosition(int *x, int *y) const;
215 virtual void DoSetClientSize(int width, int height);
216 virtual void InternalSetMenuBar();
217 virtual bool IsMDIChild() const { return true; }
218 virtual void DetachMenuBar();
219
220 virtual WXHICON GetDefaultIcon() const;
221
222 // common part of all ctors
223 void Init();
224
225 private:
226 bool m_needsInitialShow; // Show must be called in idle time after Creation
227 bool m_needsResize; // flag which tells us to artificially resize the frame
228
229 DECLARE_EVENT_TABLE()
230 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMDIChildFrame)
231 };
232
233 // ---------------------------------------------------------------------------
234 // wxMDIClientWindow
235 // ---------------------------------------------------------------------------
236
237 class WXDLLIMPEXP_CORE wxMDIClientWindow : public wxMDIClientWindowBase
238 {
239 public:
240 wxMDIClientWindow() { Init(); }
241
242 // Note: this is virtual, to allow overridden behaviour.
243 virtual bool CreateClient(wxMDIParentFrame *parent,
244 long style = wxVSCROLL | wxHSCROLL);
245
246 // Explicitly call default scroll behaviour
247 void OnScroll(wxScrollEvent& event);
248
249 protected:
250 virtual void DoSetSize(int x, int y,
251 int width, int height,
252 int sizeFlags = wxSIZE_AUTO);
253
254 void Init() { m_scrollX = m_scrollY = 0; }
255
256 int m_scrollX, m_scrollY;
257
258 private:
259 DECLARE_EVENT_TABLE()
260 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMDIClientWindow)
261 };
262
263 #endif // _WX_MSW_MDI_H_