wxMessageBox off the main thread lost result code.
[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 // 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:
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 = 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 = wxFrameNameStr);
65
66 virtual ~wxGenericMDIParentFrame();
67
68 // implement base class pure virtuals
69 static bool IsTDI() { return true; }
70
71 virtual void ActivateNext() { AdvanceActive(true); }
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 DECLARE_EVENT_TABLE()
128 DECLARE_DYNAMIC_CLASS(wxGenericMDIParentFrame)
129 };
130
131 // ----------------------------------------------------------------------------
132 // wxGenericMDIChildFrame
133 // ----------------------------------------------------------------------------
134
135 class WXDLLIMPEXP_CORE wxGenericMDIChildFrame : public wxTDIChildFrame
136 {
137 public:
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 = 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 = 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
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
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 void OnMenuHighlight(wxMenuEvent& event);
203 void OnClose(wxCloseEvent& event);
204
205 DECLARE_DYNAMIC_CLASS(wxGenericMDIChildFrame)
206 DECLARE_EVENT_TABLE()
207
208 friend class wxGenericMDIClientWindow;
209 };
210
211 // ----------------------------------------------------------------------------
212 // wxGenericMDIClientWindow
213 // ----------------------------------------------------------------------------
214
215 class WXDLLIMPEXP_CORE wxGenericMDIClientWindow : public wxMDIClientWindowBase
216 {
217 public:
218 wxGenericMDIClientWindow() { }
219
220 // unfortunately we need to provide our own version of CreateClient()
221 // because of the difference in the type of the first parameter and
222 // implement the base class pure virtual method in terms of it
223 // (CreateGenericClient() is virtual itself to allow customizing the client
224 // window creation by overriding it in the derived classes)
225 virtual bool CreateGenericClient(wxWindow *parent);
226 virtual bool CreateClient(wxMDIParentFrame *parent,
227 long WXUNUSED(style) = wxVSCROLL | wxHSCROLL)
228 {
229 return CreateGenericClient(parent);
230 }
231
232 // implementation only
233 wxBookCtrlBase *GetBookCtrl() const;
234 wxGenericMDIChildFrame *GetChild(size_t pos) const;
235 int FindChild(wxGenericMDIChildFrame *child) const;
236
237 private:
238 void PageChanged(int OldSelection, int newSelection);
239
240 void OnPageChanged(wxBookCtrlEvent& event);
241 void OnSize(wxSizeEvent& event);
242
243 // the notebook containing all MDI children as its pages
244 wxNotebook *m_notebook;
245
246 DECLARE_DYNAMIC_CLASS(wxGenericMDIClientWindow)
247 };
248
249 // ----------------------------------------------------------------------------
250 // inline functions implementation
251 // ----------------------------------------------------------------------------
252
253 inline bool
254 wxGenericMDIParentFrame::
255 WXIsInsideChildHandler(wxGenericMDIChildFrame *child) const
256 {
257 return child == m_childHandler;
258 }
259
260 #endif // _WX_GENERIC_MDIG_H_