]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mdi.cpp | |
3 | // Purpose: MDI classes | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 SC |
13 | #pragma implementation "mdi.h" |
14 | #endif | |
15 | ||
3d1a4878 SC |
16 | #include "wx/wxprec.h" |
17 | ||
e9576ca5 SC |
18 | #include "wx/mdi.h" |
19 | #include "wx/menu.h" | |
20 | #include "wx/settings.h" | |
70024cfb | 21 | #include "wx/log.h" |
e9576ca5 | 22 | |
76a5e5d2 | 23 | #include "wx/mac/private.h" |
70024cfb | 24 | #include "wx/mac/uma.h" |
76a5e5d2 | 25 | |
fe08e597 | 26 | extern wxWindowList wxModelessWindows; |
e9576ca5 | 27 | |
2f1ae414 | 28 | #if !USE_SHARED_LIBRARY |
e9576ca5 SC |
29 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) |
30 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) | |
31 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) | |
32 | ||
33 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) | |
e9576ca5 SC |
34 | EVT_ACTIVATE(wxMDIParentFrame::OnActivate) |
35 | EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) | |
36 | END_EVENT_TABLE() | |
37 | ||
38 | BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) | |
39 | EVT_SCROLL(wxMDIClientWindow::OnScroll) | |
40 | END_EVENT_TABLE() | |
41 | ||
2f1ae414 | 42 | #endif |
e9576ca5 | 43 | |
0a67a93b SC |
44 | static const int IDM_WINDOWTILE = 4001; |
45 | static const int IDM_WINDOWTILEHOR = 4001; | |
46 | static const int IDM_WINDOWCASCADE = 4002; | |
47 | static const int IDM_WINDOWICONS = 4003; | |
48 | static const int IDM_WINDOWNEXT = 4004; | |
49 | static const int IDM_WINDOWTILEVERT = 4005; | |
4f3b37fd | 50 | static const int IDM_WINDOWPREV = 4006; |
0a67a93b SC |
51 | |
52 | // This range gives a maximum of 500 MDI children. Should be enough :-) | |
53 | static const int wxFIRST_MDI_CHILD = 4100; | |
54 | static const int wxLAST_MDI_CHILD = 4600; | |
55 | ||
56 | // Status border dimensions | |
57 | static const int wxTHICK_LINE_BORDER = 3; | |
58 | ||
e9576ca5 SC |
59 | // Parent frame |
60 | ||
61 | wxMDIParentFrame::wxMDIParentFrame() | |
62 | { | |
0a67a93b SC |
63 | m_clientWindow = NULL; |
64 | m_currentChild = NULL; | |
65 | m_windowMenu = (wxMenu*) NULL; | |
66 | m_parentFrameActive = TRUE; | |
e9576ca5 SC |
67 | } |
68 | ||
69 | bool wxMDIParentFrame::Create(wxWindow *parent, | |
70 | wxWindowID id, | |
71 | const wxString& title, | |
72 | const wxPoint& pos, | |
73 | const wxSize& size, | |
74 | long style, | |
75 | const wxString& name) | |
76 | { | |
e40298d5 JS |
77 | m_clientWindow = NULL; |
78 | m_currentChild = NULL; | |
79 | ||
80 | // this style can be used to prevent a window from having the standard MDI | |
81 | // "Window" menu | |
82 | if ( style & wxFRAME_NO_WINDOW_MENU ) | |
83 | { | |
84 | m_windowMenu = (wxMenu *)NULL; | |
85 | style -= wxFRAME_NO_WINDOW_MENU ; | |
86 | } | |
87 | else // normal case: we have the window menu, so construct it | |
88 | { | |
89 | m_windowMenu = new wxMenu; | |
0a67a93b | 90 | |
e40298d5 JS |
91 | m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade")); |
92 | m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally")); | |
93 | m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically")); | |
94 | m_windowMenu->AppendSeparator(); | |
95 | m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons")); | |
96 | m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next")); | |
97 | } | |
98 | ||
70024cfb | 99 | wxFrame::Create( parent , id , title , pos , size , style , name ) ; |
e40298d5 JS |
100 | m_parentFrameActive = TRUE; |
101 | ||
102 | OnCreateClient(); | |
103 | ||
e9576ca5 SC |
104 | return TRUE; |
105 | } | |
106 | ||
107 | wxMDIParentFrame::~wxMDIParentFrame() | |
108 | { | |
0a67a93b | 109 | DestroyChildren(); |
ea3cdc4f | 110 | // already deleted by DestroyChildren() |
0a67a93b | 111 | m_clientWindow = NULL ; |
e40298d5 | 112 | |
ea3cdc4f | 113 | delete m_windowMenu; |
e9576ca5 SC |
114 | } |
115 | ||
0a67a93b | 116 | |
e9576ca5 SC |
117 | void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) |
118 | { | |
e40298d5 | 119 | wxFrame::SetMenuBar( menu_bar ) ; |
e9576ca5 SC |
120 | } |
121 | ||
0bba37f5 DE |
122 | void wxMDIParentFrame::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h) |
123 | { | |
124 | if(x) | |
125 | *x = 0; | |
126 | if(y) | |
127 | *y = 0; | |
128 | wxDisplaySize(w,h); | |
129 | } | |
130 | ||
70024cfb | 131 | void wxMDIParentFrame::MacActivate(long timestamp, bool activating) |
e9576ca5 | 132 | { |
7d671c08 | 133 | wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact")); |
70024cfb | 134 | if(activating) |
e40298d5 | 135 | { |
70024cfb DE |
136 | if(s_macDeactivateWindow && s_macDeactivateWindow->GetParent()==this) |
137 | { | |
7d671c08 | 138 | wxLogDebug(wxT("child had been scheduled for deactivation, rehighlighting")); |
70024cfb | 139 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true); |
7d671c08 | 140 | wxLogDebug(wxT("done highliting child")); |
70024cfb DE |
141 | s_macDeactivateWindow = NULL; |
142 | } | |
143 | else if(s_macDeactivateWindow == this) | |
144 | { | |
7d671c08 | 145 | wxLogDebug(wxT("Avoided deactivation/activation of this=%p"), this); |
70024cfb DE |
146 | s_macDeactivateWindow = NULL; |
147 | } | |
148 | else // window to deactivate is NULL or is not us or one of our kids | |
149 | { | |
150 | // activate kid instead | |
151 | if(m_currentChild) | |
152 | m_currentChild->MacActivate(timestamp,activating); | |
153 | else | |
154 | wxFrame::MacActivate(timestamp,activating); | |
155 | } | |
e40298d5 | 156 | } |
70024cfb | 157 | else |
e40298d5 | 158 | { |
70024cfb DE |
159 | // We were scheduled for deactivation, and now we do it. |
160 | if(s_macDeactivateWindow==this) | |
e40298d5 | 161 | { |
70024cfb DE |
162 | s_macDeactivateWindow = NULL; |
163 | if(m_currentChild) | |
164 | m_currentChild->MacActivate(timestamp,activating); | |
165 | wxFrame::MacActivate(timestamp,activating); | |
166 | } | |
167 | else // schedule ourselves for deactivation | |
168 | { | |
169 | if(s_macDeactivateWindow) | |
7d671c08 SC |
170 | wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow); |
171 | wxLogDebug(wxT("Scheduling delayed MDI Parent deactivation")); | |
70024cfb | 172 | s_macDeactivateWindow = this; |
e40298d5 | 173 | } |
e40298d5 | 174 | } |
e9576ca5 SC |
175 | } |
176 | ||
70024cfb DE |
177 | void wxMDIParentFrame::OnActivate(wxActivateEvent& event) |
178 | { | |
179 | event.Skip(); | |
180 | } | |
181 | ||
e9576ca5 SC |
182 | // Returns the active MDI child window |
183 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const | |
184 | { | |
e40298d5 | 185 | return m_currentChild ; |
e9576ca5 SC |
186 | } |
187 | ||
188 | // Create the client window class (don't Create the window, | |
189 | // just return a new class) | |
190 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient() | |
191 | { | |
0a67a93b SC |
192 | m_clientWindow = new wxMDIClientWindow( this ); |
193 | return m_clientWindow; | |
e9576ca5 SC |
194 | } |
195 | ||
196 | // Responds to colour changes, and passes event on to children. | |
197 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
198 | { | |
199 | // TODO | |
e40298d5 | 200 | |
e9576ca5 SC |
201 | // Propagate the event to the non-top-level children |
202 | wxFrame::OnSysColourChanged(event); | |
203 | } | |
204 | ||
205 | // MDI operations | |
206 | void wxMDIParentFrame::Cascade() | |
207 | { | |
208 | // TODO | |
209 | } | |
210 | ||
211 | void wxMDIParentFrame::Tile() | |
212 | { | |
213 | // TODO | |
214 | } | |
215 | ||
216 | void wxMDIParentFrame::ArrangeIcons() | |
217 | { | |
218 | // TODO | |
219 | } | |
220 | ||
221 | void wxMDIParentFrame::ActivateNext() | |
222 | { | |
223 | // TODO | |
224 | } | |
225 | ||
226 | void wxMDIParentFrame::ActivatePrevious() | |
227 | { | |
228 | // TODO | |
229 | } | |
230 | ||
29e92efb VZ |
231 | bool wxMDIParentFrame::Show( bool show ) |
232 | { | |
29e92efb VZ |
233 | // don't really show the MDI frame unless it has any children other than |
234 | // MDI children as it is pretty useless in this case | |
507ad426 | 235 | |
29e92efb VZ |
236 | if ( show ) |
237 | { | |
238 | // TODO: check for other children | |
7bf8eb78 DE |
239 | if(!GetToolBar()) |
240 | Move(-10000, -10000); | |
29e92efb VZ |
241 | } |
242 | ||
507ad426 SC |
243 | if ( !wxFrame::Show(show) ) |
244 | return false; | |
245 | ||
29e92efb VZ |
246 | return true; |
247 | } | |
248 | ||
e9576ca5 SC |
249 | // Child frame |
250 | ||
251 | wxMDIChildFrame::wxMDIChildFrame() | |
0a67a93b SC |
252 | { |
253 | Init() ; | |
254 | } | |
255 | void wxMDIChildFrame::Init() | |
e9576ca5 SC |
256 | { |
257 | } | |
258 | ||
259 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
e40298d5 JS |
260 | wxWindowID id, |
261 | const wxString& title, | |
262 | const wxPoint& pos, | |
263 | const wxSize& size, | |
264 | long style, | |
265 | const wxString& name) | |
e9576ca5 SC |
266 | { |
267 | SetName(name); | |
e40298d5 | 268 | |
e9576ca5 SC |
269 | if ( id > -1 ) |
270 | m_windowId = id; | |
271 | else | |
272 | m_windowId = (int)NewControlId(); | |
e40298d5 | 273 | |
e9576ca5 | 274 | if (parent) parent->AddChild(this); |
e40298d5 JS |
275 | |
276 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; | |
277 | ||
facd6764 SC |
278 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
279 | ||
e9576ca5 SC |
280 | wxModelessWindows.Append(this); |
281 | return FALSE; | |
282 | } | |
283 | ||
284 | wxMDIChildFrame::~wxMDIChildFrame() | |
285 | { | |
70024cfb DE |
286 | wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame); |
287 | wxASSERT(mdiparent); | |
288 | if(mdiparent->m_currentChild == this) | |
289 | mdiparent->m_currentChild = NULL; | |
0a67a93b | 290 | DestroyChildren(); |
e9576ca5 SC |
291 | } |
292 | ||
293 | void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar) | |
294 | { | |
e40298d5 | 295 | return wxFrame::SetMenuBar( menu_bar ) ; |
e9576ca5 SC |
296 | } |
297 | ||
70024cfb DE |
298 | void wxMDIChildFrame::MacActivate(long timestamp, bool activating) |
299 | { | |
7d671c08 | 300 | wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact")); |
70024cfb DE |
301 | wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame); |
302 | wxASSERT(mdiparent); | |
303 | if(activating) | |
304 | { | |
305 | if(s_macDeactivateWindow == m_parent) | |
306 | { | |
7d671c08 | 307 | wxLogDebug(wxT("parent had been scheduled for deactivation, rehighlighting")); |
70024cfb | 308 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true); |
7d671c08 | 309 | wxLogDebug(wxT("done highliting parent")); |
70024cfb DE |
310 | s_macDeactivateWindow = NULL; |
311 | } | |
312 | else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow) | |
313 | mdiparent->wxFrame::MacActivate(timestamp,activating); | |
314 | ||
315 | if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this) | |
316 | mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false); | |
317 | mdiparent->m_currentChild = this; | |
318 | ||
319 | if(s_macDeactivateWindow==this) | |
320 | { | |
7d671c08 | 321 | wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this); |
70024cfb DE |
322 | s_macDeactivateWindow=NULL; |
323 | } | |
324 | else | |
325 | wxFrame::MacActivate(timestamp, activating); | |
326 | } | |
327 | else | |
328 | { | |
329 | // We were scheduled for deactivation, and now we do it. | |
330 | if(s_macDeactivateWindow==this) | |
331 | { | |
332 | s_macDeactivateWindow = NULL; | |
333 | wxFrame::MacActivate(timestamp,activating); | |
334 | if(mdiparent->m_currentChild==this) | |
335 | mdiparent->wxFrame::MacActivate(timestamp,activating); | |
336 | } | |
337 | else // schedule ourselves for deactivation | |
338 | { | |
339 | if(s_macDeactivateWindow) | |
7d671c08 SC |
340 | wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow); |
341 | wxLogDebug(wxT("Scheduling delayed deactivation")); | |
70024cfb DE |
342 | s_macDeactivateWindow = this; |
343 | } | |
344 | } | |
345 | } | |
346 | ||
e9576ca5 SC |
347 | // MDI operations |
348 | void wxMDIChildFrame::Maximize() | |
349 | { | |
0a67a93b | 350 | wxFrame::Maximize() ; |
e9576ca5 SC |
351 | } |
352 | ||
353 | void wxMDIChildFrame::Restore() | |
354 | { | |
0a67a93b | 355 | wxFrame::Restore() ; |
e9576ca5 SC |
356 | } |
357 | ||
358 | void wxMDIChildFrame::Activate() | |
359 | { | |
e9576ca5 SC |
360 | } |
361 | ||
0a67a93b SC |
362 | //----------------------------------------------------------------------------- |
363 | // wxMDIClientWindow | |
364 | //----------------------------------------------------------------------------- | |
e9576ca5 SC |
365 | |
366 | wxMDIClientWindow::wxMDIClientWindow() | |
367 | { | |
368 | } | |
369 | ||
370 | wxMDIClientWindow::~wxMDIClientWindow() | |
371 | { | |
0a67a93b | 372 | DestroyChildren(); |
e9576ca5 SC |
373 | } |
374 | ||
375 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) | |
376 | { | |
84be293d KO |
377 | if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style)) |
378 | return FALSE; | |
e40298d5 | 379 | |
0a67a93b SC |
380 | wxModelessWindows.Append(this); |
381 | return TRUE; | |
e9576ca5 SC |
382 | } |
383 | ||
be7a1013 DE |
384 | // Get size *available for subwindows* i.e. excluding menu bar. |
385 | void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const | |
386 | { | |
387 | wxDisplaySize( x , y ) ; | |
388 | } | |
389 | ||
e9576ca5 SC |
390 | // Explicitly call default scroll behaviour |
391 | void wxMDIClientWindow::OnScroll(wxScrollEvent& event) | |
392 | { | |
e9576ca5 SC |
393 | } |
394 |