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