wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / msw / mdi.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/mdi.h
3 // Purpose: MDI (Multiple Document Interface) classes
4 // Author: Julian Smart
5 // Modified by: 2008-10-31 Vadim Zeitlin: derive from the base classes
6 // Created: 01/02/97
7 // Copyright: (c) 1997 Julian Smart
8 // (c) 2008 Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MSW_MDI_H_
13 #define _WX_MSW_MDI_H_
14
15 #include "wx/frame.h"
16
17 class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable;
18
19 // ---------------------------------------------------------------------------
20 // wxMDIParentFrame
21 // ---------------------------------------------------------------------------
22
23 class WXDLLIMPEXP_CORE wxMDIParentFrame : public wxMDIParentFrameBase
24 {
25 public:
26 wxMDIParentFrame() { Init(); }
27 wxMDIParentFrame(wxWindow *parent,
28 wxWindowID id,
29 const wxString& title,
30 const wxPoint& pos = wxDefaultPosition,
31 const wxSize& size = wxDefaultSize,
32 long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
33 const wxString& name = wxFrameNameStr)
34 {
35 Init();
36
37 Create(parent, id, title, pos, size, style, name);
38 }
39
40 virtual ~wxMDIParentFrame();
41
42 bool Create(wxWindow *parent,
43 wxWindowID id,
44 const wxString& title,
45 const wxPoint& pos = wxDefaultPosition,
46 const wxSize& size = wxDefaultSize,
47 long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
48 const wxString& name = wxFrameNameStr);
49
50 // override/implement base class [pure] virtual methods
51 // ----------------------------------------------------
52
53 static bool IsTDI() { return false; }
54
55 // we don't store the active child in m_currentChild so override this
56 // function to find it dynamically
57 virtual wxMDIChildFrame *GetActiveChild() const;
58
59 virtual void Cascade();
60 virtual void Tile(wxOrientation orient = wxHORIZONTAL);
61 virtual void ArrangeIcons();
62 virtual void ActivateNext();
63 virtual void ActivatePrevious();
64
65 #if wxUSE_MENUS
66 virtual void SetWindowMenu(wxMenu* menu);
67
68 virtual void DoMenuUpdates(wxMenu* menu = NULL);
69
70 // return the active child menu, if any
71 virtual WXHMENU MSWGetActiveMenu() const;
72 #endif // wxUSE_MENUS
73
74
75 // implementation only from now on
76
77 // MDI helpers
78 // -----------
79
80 #if wxUSE_MENUS
81 // called by wxMDIChildFrame after it was successfully created
82 virtual void AddMDIChild(wxMDIChildFrame *child);
83
84 // called by wxMDIChildFrame just before it is destroyed
85 virtual void RemoveMDIChild(wxMDIChildFrame *child);
86 #endif // wxUSE_MENUS
87
88 // handlers
89 // --------
90
91 // Responds to colour changes
92 void OnSysColourChanged(wxSysColourChangedEvent& event);
93
94 void OnSize(wxSizeEvent& event);
95 void OnIconized(wxIconizeEvent& event);
96
97 bool HandleActivate(int state, bool minimized, WXHWND activate);
98
99 // override window proc for MDI-specific message processing
100 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
101
102 virtual WXLRESULT MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM);
103 virtual bool MSWTranslateMessage(WXMSG* msg);
104
105 #if wxUSE_MENUS
106 // override wxFrameBase function to also look in the active child menu bar
107 // and the "Window" menu
108 virtual wxMenuItem *FindItemInMenuBar(int menuId) const;
109 #endif // wxUSE_MENUS
110
111 protected:
112 #if wxUSE_MENUS_NATIVE
113 virtual void InternalSetMenuBar();
114 #endif // wxUSE_MENUS_NATIVE
115
116 virtual WXHICON GetDefaultIcon() const;
117
118 // set the size of the MDI client window to match the frame size
119 void UpdateClientSize();
120
121 private:
122 // common part of all ctors
123 void Init();
124
125 #if wxUSE_MENUS
126 // "Window" menu commands event handlers
127 void OnMDICommand(wxCommandEvent& event);
128 void OnMDIChild(wxCommandEvent& event);
129
130
131 // add/remove window menu if we have it (i.e. m_windowMenu != NULL)
132 void AddWindowMenu();
133 void RemoveWindowMenu();
134
135 // update the window menu (if we have it) to enable or disable the commands
136 // which only make sense when we have more than one child
137 void UpdateWindowMenu(bool enable);
138
139 #if wxUSE_ACCEL
140 wxAcceleratorTable *m_accelWindowMenu;
141 #endif // wxUSE_ACCEL
142 #endif // wxUSE_MENUS
143
144 // return the number of child frames we currently have (maybe 0)
145 int GetChildFramesCount() const;
146
147
148 friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame;
149
150 DECLARE_EVENT_TABLE()
151 DECLARE_DYNAMIC_CLASS(wxMDIParentFrame)
152 wxDECLARE_NO_COPY_CLASS(wxMDIParentFrame);
153 };
154
155 // ---------------------------------------------------------------------------
156 // wxMDIChildFrame
157 // ---------------------------------------------------------------------------
158
159 class WXDLLIMPEXP_CORE wxMDIChildFrame : public wxMDIChildFrameBase
160 {
161 public:
162 wxMDIChildFrame() { Init(); }
163 wxMDIChildFrame(wxMDIParentFrame *parent,
164 wxWindowID id,
165 const wxString& title,
166 const wxPoint& pos = wxDefaultPosition,
167 const wxSize& size = wxDefaultSize,
168 long style = wxDEFAULT_FRAME_STYLE,
169 const wxString& name = wxFrameNameStr)
170 {
171 Init();
172
173 Create(parent, id, title, pos, size, style, name);
174 }
175
176 bool Create(wxMDIParentFrame *parent,
177 wxWindowID id,
178 const wxString& title,
179 const wxPoint& pos = wxDefaultPosition,
180 const wxSize& size = wxDefaultSize,
181 long style = wxDEFAULT_FRAME_STYLE,
182 const wxString& name = wxFrameNameStr);
183
184 virtual ~wxMDIChildFrame();
185
186 // implement MDI operations
187 virtual void Activate();
188
189 // Override some frame operations too
190 virtual void Maximize(bool maximize = true);
191 virtual void Restore();
192
193 virtual bool Show(bool show = true);
194
195 // Implementation only from now on
196 // -------------------------------
197
198 // Handlers
199 bool HandleMDIActivate(long bActivate, WXHWND, WXHWND);
200 bool HandleWindowPosChanging(void *lpPos);
201 bool HandleGetMinMaxInfo(void *mmInfo);
202
203 virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
204 virtual WXLRESULT MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
205 virtual bool MSWTranslateMessage(WXMSG *msg);
206
207 virtual void MSWDestroyWindow();
208
209 bool ResetWindowStyle(void *vrect);
210
211 void OnIdle(wxIdleEvent& event);
212
213 protected:
214 virtual void DoGetScreenPosition(int *x, int *y) const;
215 virtual void DoGetPosition(int *x, int *y) const;
216 virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags);
217 virtual void DoSetClientSize(int width, int height);
218 virtual void InternalSetMenuBar();
219 virtual bool IsMDIChild() const { return true; }
220 virtual void DetachMenuBar();
221
222 virtual WXHICON GetDefaultIcon() const;
223
224 // common part of all ctors
225 void Init();
226
227 private:
228 bool m_needsInitialShow; // Show must be called in idle time after Creation
229 bool m_needsResize; // flag which tells us to artificially resize the frame
230
231 DECLARE_EVENT_TABLE()
232 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMDIChildFrame)
233 };
234
235 // ---------------------------------------------------------------------------
236 // wxMDIClientWindow
237 // ---------------------------------------------------------------------------
238
239 class WXDLLIMPEXP_CORE wxMDIClientWindow : public wxMDIClientWindowBase
240 {
241 public:
242 wxMDIClientWindow() { Init(); }
243
244 // Note: this is virtual, to allow overridden behaviour.
245 virtual bool CreateClient(wxMDIParentFrame *parent,
246 long style = wxVSCROLL | wxHSCROLL);
247
248 // Explicitly call default scroll behaviour
249 void OnScroll(wxScrollEvent& event);
250
251 protected:
252 virtual void DoSetSize(int x, int y,
253 int width, int height,
254 int sizeFlags = wxSIZE_AUTO);
255
256 void Init() { m_scrollX = m_scrollY = 0; }
257
258 int m_scrollX, m_scrollY;
259
260 private:
261 DECLARE_EVENT_TABLE()
262 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMDIClientWindow)
263 };
264
265 #endif // _WX_MSW_MDI_H_