1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/mdig.h
3 // Purpose: Generic MDI (Multiple Document Interface) classes
4 // Author: Hans Van Leemputten
5 // Modified by: 2008-10-31 Vadim Zeitlin: derive from the base classes
6 // Created: 29/07/2002
7 // Copyright: (c) 2002 Hans Van Leemputten
8 // (c) 2008 Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GENERIC_MDIG_H_
13 #define _WX_GENERIC_MDIG_H_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/panel.h"
20
21 class WXDLLIMPEXP_FWD_CORE wxBookCtrlBase;
22 class WXDLLIMPEXP_FWD_CORE wxBookCtrlEvent;
23 class WXDLLIMPEXP_FWD_CORE wxIcon;
24 class WXDLLIMPEXP_FWD_CORE wxIconBundle;
25 class WXDLLIMPEXP_FWD_CORE wxNotebook;
26
27 #if wxUSE_GENERIC_MDI_AS_NATIVE
28 #define wxGenericMDIParentFrame wxMDIParentFrame
29 #define wxGenericMDIChildFrame wxMDIChildFrame
30 #define wxGenericMDIClientWindow wxMDIClientWindow
31 #else // !wxUSE_GENERIC_MDI_AS_NATIVE
32 class WXDLLIMPEXP_FWD_CORE wxGenericMDIParentFrame;
33 class WXDLLIMPEXP_FWD_CORE wxGenericMDIChildFrame;
34 class WXDLLIMPEXP_FWD_CORE wxGenericMDIClientWindow;
35 #endif // wxUSE_GENERIC_MDI_AS_NATIVE/!wxUSE_GENERIC_MDI_AS_NATIVE
36
37 // ----------------------------------------------------------------------------
38 // wxGenericMDIParentFrame
39 // ----------------------------------------------------------------------------
40
41 class WXDLLIMPEXP_CORE wxGenericMDIParentFrame : public wxMDIParentFrameBase
42 {
43 public:
wxGenericMDIParentFrame()44 wxGenericMDIParentFrame() { Init(); }
45 wxGenericMDIParentFrame(wxWindow *parent,
46 wxWindowID winid,
47 const wxString& title,
48 const wxPoint& pos = wxDefaultPosition,
49 const wxSize& size = wxDefaultSize,
50 long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
51 const wxString& name = wxASCII_STR(wxFrameNameStr))
52 {
53 Init();
54
55 Create(parent, winid, title, pos, size, style, name);
56 }
57
58 bool Create(wxWindow *parent,
59 wxWindowID winid,
60 const wxString& title,
61 const wxPoint& pos = wxDefaultPosition,
62 const wxSize& size = wxDefaultSize,
63 long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
64 const wxString& name = wxASCII_STR(wxFrameNameStr));
65
66 virtual ~wxGenericMDIParentFrame();
67
68 // implement base class pure virtuals
IsTDI()69 static bool IsTDI() { return true; }
70
ActivateNext()71 virtual void ActivateNext() { AdvanceActive(true); }
ActivatePrevious()72 virtual void ActivatePrevious() { AdvanceActive(false); }
73
74 #if wxUSE_MENUS
75 virtual void SetWindowMenu(wxMenu* pMenu);
76
77 virtual void SetMenuBar(wxMenuBar *pMenuBar);
78 #endif // wxUSE_MENUS
79
80 virtual wxGenericMDIClientWindow *OnCreateGenericClient();
81
82
83 // implementation only from now on
84 void WXSetChildMenuBar(wxGenericMDIChildFrame *child);
85 void WXUpdateChildTitle(wxGenericMDIChildFrame *child);
86 void WXActivateChild(wxGenericMDIChildFrame *child);
87 void WXRemoveChild(wxGenericMDIChildFrame *child);
88 bool WXIsActiveChild(wxGenericMDIChildFrame *child) const;
89 bool WXIsInsideChildHandler(wxGenericMDIChildFrame *child) const;
90
91 // return the book control used by the client window to manage the pages
92 wxBookCtrlBase *GetBookCtrl() const;
93
94 protected:
95 #if wxUSE_MENUS
96 wxMenuBar *m_pMyMenuBar;
97 #endif // wxUSE_MENUS
98
99 // advance the activation forward or backwards
100 void AdvanceActive(bool forward);
101
102 private:
103 void Init();
104
105 #if wxUSE_MENUS
106 void RemoveWindowMenu(wxMenuBar *pMenuBar);
107 void AddWindowMenu(wxMenuBar *pMenuBar);
108
109 void OnWindowMenu(wxCommandEvent& event);
110 #endif // wxUSE_MENUS
111
112 virtual bool ProcessEvent(wxEvent& event);
113
114 void OnClose(wxCloseEvent& event);
115
116 // return the client window, may be NULL if we hadn't been created yet
117 wxGenericMDIClientWindow *GetGenericClientWindow() const;
118
119 // close all children, return false if any of them vetoed it
120 bool CloseAll();
121
122
123 // this pointer is non-NULL if we're currently inside our ProcessEvent()
124 // and we forwarded the event to this child (as we do with menu events)
125 wxMDIChildFrameBase *m_childHandler;
126
127 wxDECLARE_EVENT_TABLE();
128 wxDECLARE_DYNAMIC_CLASS(wxGenericMDIParentFrame);
129 };
130
131 // ----------------------------------------------------------------------------
132 // wxGenericMDIChildFrame
133 // ----------------------------------------------------------------------------
134
135 class WXDLLIMPEXP_CORE wxGenericMDIChildFrame : public wxTDIChildFrame
136 {
137 public:
wxGenericMDIChildFrame()138 wxGenericMDIChildFrame() { Init(); }
139 wxGenericMDIChildFrame(wxGenericMDIParentFrame *parent,
140 wxWindowID winid,
141 const wxString& title,
142 const wxPoint& pos = wxDefaultPosition,
143 const wxSize& size = wxDefaultSize,
144 long style = wxDEFAULT_FRAME_STYLE,
145 const wxString& name = wxASCII_STR(wxFrameNameStr))
146 {
147 Init();
148
149 Create(parent, winid, title, pos, size, style, name);
150 }
151
152 bool Create(wxGenericMDIParentFrame *parent,
153 wxWindowID winid,
154 const wxString& title,
155 const wxPoint& pos = wxDefaultPosition,
156 const wxSize& size = wxDefaultSize,
157 long style = wxDEFAULT_FRAME_STYLE,
158 const wxString& name = wxASCII_STR(wxFrameNameStr));
159
160 virtual ~wxGenericMDIChildFrame();
161
162 // implement MDI operations
163 virtual void Activate();
164
165
166 #if wxUSE_MENUS
167 virtual void SetMenuBar( wxMenuBar *menu_bar );
168 virtual wxMenuBar *GetMenuBar() const;
169 #endif // wxUSE_MENUS
170
GetTitle()171 virtual wxString GetTitle() const { return m_title; }
172 virtual void SetTitle(const wxString& title);
173
174 virtual bool TryAfter(wxEvent& event);
175
176 // implementation only from now on
177
GetGenericMDIParent()178 wxGenericMDIParentFrame* GetGenericMDIParent() const
179 {
180 #if wxUSE_GENERIC_MDI_AS_NATIVE
181 return GetMDIParent();
182 #else // generic != native
183 return m_mdiParentGeneric;
184 #endif
185 }
186
187 protected:
188 wxString m_title;
189
190 #if wxUSE_MENUS
191 wxMenuBar *m_pMenuBar;
192 #endif // wxUSE_MENUS
193
194 #if !wxUSE_GENERIC_MDI_AS_NATIVE
195 wxGenericMDIParentFrame *m_mdiParentGeneric;
196 #endif
197
198 protected:
199 void Init();
200
201 private:
202 #if wxUSE_MENUS
203 void OnMenuHighlight(wxMenuEvent& event);
204 #endif // wxUSE_MENUS
205 void OnClose(wxCloseEvent& event);
206
207 wxDECLARE_DYNAMIC_CLASS(wxGenericMDIChildFrame);
208 wxDECLARE_EVENT_TABLE();
209
210 friend class wxGenericMDIClientWindow;
211 };
212
213 // ----------------------------------------------------------------------------
214 // wxGenericMDIClientWindow
215 // ----------------------------------------------------------------------------
216
217 class WXDLLIMPEXP_CORE wxGenericMDIClientWindow : public wxMDIClientWindowBase
218 {
219 public:
wxGenericMDIClientWindow()220 wxGenericMDIClientWindow() { }
221
222 // unfortunately we need to provide our own version of CreateClient()
223 // because of the difference in the type of the first parameter and
224 // implement the base class pure virtual method in terms of it
225 // (CreateGenericClient() is virtual itself to allow customizing the client
226 // window creation by overriding it in the derived classes)
227 virtual bool CreateGenericClient(wxWindow *parent);
228 virtual bool CreateClient(wxMDIParentFrame *parent,
229 long WXUNUSED(style) = wxVSCROLL | wxHSCROLL)
230 {
231 return CreateGenericClient(parent);
232 }
233
234 // implementation only
235 wxBookCtrlBase *GetBookCtrl() const;
236 wxGenericMDIChildFrame *GetChild(size_t pos) const;
237 int FindChild(wxGenericMDIChildFrame *child) const;
238
239 private:
240 void PageChanged(int OldSelection, int newSelection);
241
242 void OnPageChanged(wxBookCtrlEvent& event);
243 void OnSize(wxSizeEvent& event);
244
245 // the notebook containing all MDI children as its pages
246 wxNotebook *m_notebook;
247
248 wxDECLARE_DYNAMIC_CLASS(wxGenericMDIClientWindow);
249 };
250
251 // ----------------------------------------------------------------------------
252 // inline functions implementation
253 // ----------------------------------------------------------------------------
254
255 inline bool
256 wxGenericMDIParentFrame::
WXIsInsideChildHandler(wxGenericMDIChildFrame * child)257 WXIsInsideChildHandler(wxGenericMDIChildFrame *child) const
258 {
259 return child == m_childHandler;
260 }
261
262 #endif // _WX_GENERIC_MDIG_H_
263