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