Review/simplify/cleanup MDI classes for all platforms and introduce base
[wxWidgets.git] / include / wx / mdi.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mdi.h
3 // Purpose: wxMDI base header
4 // Author: Julian Smart (original)
5 // Vadim Zeitlin (base MDI classes refactoring)
6 // Copyright: (c) 1998 Julian Smart
7 // (c) 2008 Vadim Zeitlin
8 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MDI_H_BASE_
13 #define _WX_MDI_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_MDI
18
19 #include "wx/frame.h"
20
21 // forward declarations
22 class WXDLLIMPEXP_FWD_CORE wxMDIParentFrame;
23 class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame;
24 class WXDLLIMPEXP_FWD_CORE wxMDIClientWindowBase;
25 class WXDLLIMPEXP_FWD_CORE wxMDIClientWindow;
26
27 // ----------------------------------------------------------------------------
28 // wxMDIParentFrameBase: base class for parent frame for MDI children
29 // ----------------------------------------------------------------------------
30
31 class WXDLLIMPEXP_CORE wxMDIParentFrameBase : public wxFrame
32 {
33 public:
34 wxMDIParentFrameBase()
35 {
36 m_clientWindow = NULL;
37 m_currentChild = NULL;
38 #if wxUSE_MENUS
39 m_windowMenu = NULL;
40 #endif // wxUSE_MENUS
41 }
42
43 /*
44 Derived classes should provide ctor and Create() with the following
45 declaration:
46
47 bool Create(wxWindow *parent,
48 wxWindowID winid,
49 const wxString& title,
50 const wxPoint& pos = wxDefaultPosition,
51 const wxSize& size = wxDefaultSize,
52 long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
53 const wxString& name = wxFrameNameStr);
54 */
55
56 #if wxUSE_MENUS
57 virtual ~wxMDIParentFrameBase()
58 {
59 delete m_windowMenu;
60 }
61 #endif // wxUSE_MENUS
62
63 // accessors
64 // ---------
65
66 // Get or change the active MDI child window
67 virtual wxMDIChildFrame *GetActiveChild() const
68 { return m_currentChild; }
69 virtual void SetActiveChild(wxMDIChildFrame *child)
70 { m_currentChild = child; }
71
72
73 // Get the client window
74 wxMDIClientWindowBase *GetClientWindow() const { return m_clientWindow; }
75
76
77 // MDI windows menu functions
78 // --------------------------
79
80 #if wxUSE_MENUS
81 // return the pointer to the current window menu or NULL if we don't have
82 // because of wxFRAME_NO_WINDOW_MENU style
83 wxMenu* GetWindowMenu() const { return m_windowMenu; };
84
85 // use the given menu instead of the default window menu
86 //
87 // menu can be NULL to disable the window menu completely
88 virtual void SetWindowMenu(wxMenu *menu)
89 {
90 delete m_windowMenu;
91 m_windowMenu = menu;
92 }
93 #endif // wxUSE_MENUS
94
95
96 // standard MDI window management functions
97 // ----------------------------------------
98
99 virtual void Cascade() { }
100 virtual void Tile(wxOrientation WXUNUSED(orient) = wxHORIZONTAL) { }
101 virtual void ArrangeIcons() { }
102 virtual void ActivateNext() = 0;
103 virtual void ActivatePrevious() = 0;
104
105 /*
106 Derived classes must provide the following function:
107
108 static bool IsTDI();
109 */
110
111 // Create the client window class (don't Create() the window here, just
112 // return a new object of a wxMDIClientWindow-derived class)
113 //
114 // Notice that if you override this method you should use the default
115 // constructor and Create() and not the constructor creating the window
116 // when creating the frame or your overridden version is not going to be
117 // called (as the call to a virtual function from ctor will be dispatched
118 // to this class version)
119 virtual wxMDIClientWindow *OnCreateClient();
120
121 protected:
122 // This is wxMDIClientWindow for all the native implementations but not for
123 // the generic MDI version which has its own wxGenericMDIClientWindow and
124 // so we store it as just a base class pointer because we don't need its
125 // exact type anyhow
126 wxMDIClientWindowBase *m_clientWindow;
127 wxMDIChildFrame *m_currentChild;
128
129 #if wxUSE_MENUS
130 // the current window menu or NULL if we are not using it
131 wxMenu *m_windowMenu;
132 #endif // wxUSE_MENUS
133 };
134
135 // ----------------------------------------------------------------------------
136 // wxMDIChildFrameBase: child frame managed by wxMDIParentFrame
137 // ----------------------------------------------------------------------------
138
139 class WXDLLIMPEXP_CORE wxMDIChildFrameBase : public wxFrame
140 {
141 public:
142 wxMDIChildFrameBase() { m_mdiParent = NULL; }
143
144 /*
145 Derived classes should provide Create() with the following signature:
146
147 bool Create(wxMDIParentFrame *parent,
148 wxWindowID id,
149 const wxString& title,
150 const wxPoint& pos = wxDefaultPosition,
151 const wxSize& size = wxDefaultSize,
152 long style = wxDEFAULT_FRAME_STYLE,
153 const wxString& name = wxFrameNameStr);
154
155 And setting m_mdiParent to parent parameter.
156 */
157
158 // MDI children specific methods
159 virtual void Activate() = 0;
160
161 // Return the MDI parent frame: notice that it may not be the same as
162 // GetParent() (our parent may be the client window or even its subwindow
163 // in some implementations)
164 wxMDIParentFrame *GetMDIParent() const { return m_mdiParent; }
165
166 // Synonym for GetMDIParent(), was used in some other ports
167 wxMDIParentFrame *GetMDIParentFrame() const { return GetMDIParent(); }
168
169
170 // in most ports MDI children frames are not really top-level, the only
171 // exception are the Mac ports in which MDI children are just normal top
172 // level windows too
173 virtual bool IsTopLevel() const { return false; }
174
175 protected:
176 wxMDIParentFrame *m_mdiParent;
177 };
178
179 // ----------------------------------------------------------------------------
180 // wxTDIChildFrame: child frame used by TDI implementations
181 // ----------------------------------------------------------------------------
182
183 class WXDLLIMPEXP_CORE wxTDIChildFrame : public wxMDIChildFrameBase
184 {
185 public:
186 // override wxFrame methods for this non top-level window
187
188 #if wxUSE_STATUSBAR
189 // no status bars
190 //
191 // TODO: MDI children should have their own status bars, why not?
192 virtual wxStatusBar* CreateStatusBar(int WXUNUSED(number) = 1,
193 long WXUNUSED(style) = 1,
194 wxWindowID WXUNUSED(id) = 1,
195 const wxString& WXUNUSED(name)
196 = wxEmptyString)
197 { return NULL; }
198
199 virtual wxStatusBar *GetStatusBar() const
200 { return NULL; }
201 virtual void SetStatusText(const wxString &WXUNUSED(text),
202 int WXUNUSED(number)=0)
203 { }
204 virtual void SetStatusWidths(int WXUNUSED(n),
205 const int WXUNUSED(widths)[])
206 { }
207 #endif // wxUSE_STATUSBAR
208
209 #if wxUSE_TOOLBAR
210 // no toolbar
211 //
212 // TODO: again, it should be possible to have tool bars
213 virtual wxToolBar *CreateToolBar(long WXUNUSED(style),
214 wxWindowID WXUNUSED(id),
215 const wxString& WXUNUSED(name))
216 { return NULL; }
217 virtual wxToolBar *GetToolBar() const { return NULL; }
218 #endif // wxUSE_TOOLBAR
219
220 // no icon
221 virtual void SetIcons(const wxIconBundle& WXUNUSED(icons)) { }
222
223 // title is used as the tab label
224 virtual wxString GetTitle() const { return m_title; }
225 virtual void SetTitle(const wxString& title) = 0;
226
227 // no maximize etc
228 virtual void Maximize(bool WXUNUSED(maximize) = true) { }
229 virtual bool IsMaximized() const { return true; }
230 virtual bool IsAlwaysMaximized() const { return true; }
231 virtual void Iconize(bool WXUNUSED(iconize) = true) { }
232 virtual bool IsIconized() const { return false; }
233 virtual void Restore() { }
234
235 virtual bool ShowFullScreen(bool WXUNUSED(show),
236 long WXUNUSED(style)) { return false; }
237 virtual bool IsFullScreen() const { return false; }
238
239
240 // we need to override these functions to ensure that a child window is
241 // created even though we derive from wxFrame -- basically we make it
242 // behave as just a wxWindow by short-circuiting wxTLW changes to the base
243 // class behaviour
244
245 virtual void AddChild(wxWindowBase *child) { wxWindow::AddChild(child); }
246
247 virtual bool Destroy() { return wxWindow::Destroy(); }
248
249 // extra platform-specific hacks
250 #ifdef __WXMSW__
251 virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const
252 {
253 return wxWindow::MSWGetStyle(flags, exstyle);
254 }
255
256 virtual WXHWND MSWGetParent() const
257 {
258 return wxWindow::MSWGetParent();
259 }
260
261 WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
262 {
263 return wxWindow::MSWWindowProc(message, wParam, lParam);
264 }
265 #endif // __WXMSW__
266
267 protected:
268 virtual void DoGetSize(int *width, int *height) const
269 {
270 wxWindow::DoGetSize(width, height);
271 }
272
273 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags)
274 {
275 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
276 }
277
278 virtual void DoGetClientSize(int *width, int *height) const
279 {
280 wxWindow::DoGetClientSize(width, height);
281 }
282
283 virtual void DoSetClientSize(int width, int height)
284 {
285 wxWindow::DoSetClientSize(width, height);
286 }
287
288 // no size hints
289 virtual void DoSetSizeHints(int WXUNUSED(minW), int WXUNUSED(minH),
290 int WXUNUSED(maxW), int WXUNUSED(maxH),
291 int WXUNUSED(incW), int WXUNUSED(incH)) { }
292
293 wxString m_title;
294 };
295
296 // ----------------------------------------------------------------------------
297 // wxMDIClientWindowBase: child of parent frame, parent of children frames
298 // ----------------------------------------------------------------------------
299
300 class WXDLLIMPEXP_CORE wxMDIClientWindowBase : public wxWindow
301 {
302 public:
303 /*
304 The derived class must provide the default ctor only (CreateClient()
305 will be called later).
306 */
307
308 // Can be overridden in the derived classes but the base class version must
309 // be usually called first to really create the client window.
310 virtual bool CreateClient(wxMDIParentFrame *parent,
311 long style = wxVSCROLL | wxHSCROLL) = 0;
312 };
313
314 // ----------------------------------------------------------------------------
315 // Include the port-specific implementation of the base classes defined above
316 // ----------------------------------------------------------------------------
317
318 // wxUSE_GENERIC_MDI_AS_NATIVE may be predefined to force the generic MDI
319 // implementation use even on the platforms which usually don't use it
320 //
321 // notice that generic MDI can still be used without this, but you would need
322 // to explicitly use wxGenericMDIXXX classes in your code (and currently also
323 // add src/generic/mdig.cpp to your build as it's not compiled in if generic
324 // MDI is not used by default -- but this may change later...)
325 #ifndef wxUSE_GENERIC_MDI_AS_NATIVE
326 // wxUniv always uses the generic MDI implementation and so do the ports
327 // without native version (although wxCocoa seems to have one -- but it's
328 // probably not functional?)
329 #if defined(__WXCOCOA__) || \
330 defined(__WXMOTIF__) || \
331 defined(__WXPM__) || \
332 defined(__WXUNIVERSAL__)
333 #define wxUSE_GENERIC_MDI_AS_NATIVE 1
334 #else
335 #define wxUSE_GENERIC_MDI_AS_NATIVE 0
336 #endif
337 #endif // wxUSE_GENERIC_MDI_AS_NATIVE
338
339 #if wxUSE_GENERIC_MDI_AS_NATIVE
340 #include "wx/generic/mdig.h"
341 #elif defined(__WXMSW__)
342 #include "wx/msw/mdi.h"
343 #elif defined(__WXGTK20__)
344 #include "wx/gtk/mdi.h"
345 #elif defined(__WXGTK__)
346 #include "wx/gtk1/mdi.h"
347 #elif defined(__WXMAC__)
348 #include "wx/osx/mdi.h"
349 #elif defined(__WXCOCOA__)
350 #include "wx/cocoa/mdi.h"
351 #endif
352
353 inline wxMDIClientWindow *wxMDIParentFrameBase::OnCreateClient()
354 {
355 return new wxMDIClientWindow;
356 }
357
358 #endif // wxUSE_MDI
359
360 #endif // _WX_MDI_H_BASE_