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