]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/carbon/mdi.cpp | |
3 | // Purpose: MDI classes | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_MDI | |
15 | ||
16 | #include "wx/mdi.h" | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/log.h" | |
20 | #include "wx/menu.h" | |
21 | #include "wx/settings.h" | |
22 | #include "wx/statusbr.h" | |
23 | #endif | |
24 | ||
25 | #include "wx/mac/private.h" | |
26 | #include "wx/mac/uma.h" | |
27 | ||
28 | extern wxWindowList wxModelessWindows; | |
29 | ||
30 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) | |
31 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) | |
32 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) | |
33 | ||
34 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) | |
35 | EVT_ACTIVATE(wxMDIParentFrame::OnActivate) | |
36 | EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) | |
37 | END_EVENT_TABLE() | |
38 | ||
39 | BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) | |
40 | EVT_SCROLL(wxMDIClientWindow::OnScroll) | |
41 | END_EVENT_TABLE() | |
42 | ||
43 | static const wxChar *TRACE_MDI = _T("mdi"); | |
44 | ||
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; | |
50 | ||
51 | // others | |
52 | ||
53 | void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) | |
54 | { | |
55 | #if 1 // TODO REMOVE | |
56 | if ( inWindowRef ) | |
57 | { | |
58 | // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; | |
59 | // if ( inActivate != isHighlighted ) | |
60 | #ifndef __LP64__ | |
61 | GrafPtr port ; | |
62 | GetPort( &port ) ; | |
63 | SetPortWindowPort( inWindowRef ) ; | |
64 | #endif | |
65 | HiliteWindow( inWindowRef , inActivate ) ; | |
66 | ControlRef control = NULL ; | |
67 | ::GetRootControl( inWindowRef , &control ) ; | |
68 | if ( control ) | |
69 | { | |
70 | if ( inActivate ) | |
71 | ::ActivateControl( control ) ; | |
72 | else | |
73 | ::DeactivateControl( control ) ; | |
74 | } | |
75 | #ifndef __LP64__ | |
76 | SetPort( port ) ; | |
77 | #endif | |
78 | } | |
79 | #endif | |
80 | } | |
81 | ||
82 | // ---------------------------------------------------------------------------- | |
83 | // Parent frame | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | void wxMDIParentFrame::Init() | |
87 | { | |
88 | m_clientWindow = NULL; | |
89 | m_currentChild = NULL; | |
90 | m_windowMenu = (wxMenu*) NULL; | |
91 | m_parentFrameActive = true; | |
92 | m_shouldBeShown = false; | |
93 | } | |
94 | ||
95 | bool wxMDIParentFrame::Create(wxWindow *parent, | |
96 | wxWindowID id, | |
97 | const wxString& title, | |
98 | const wxPoint& pos, | |
99 | const wxSize& size, | |
100 | long style, | |
101 | const wxString& name) | |
102 | { | |
103 | // this style can be used to prevent a window from having the standard MDI | |
104 | // "Window" menu | |
105 | if ( style & wxFRAME_NO_WINDOW_MENU ) | |
106 | { | |
107 | m_windowMenu = (wxMenu *)NULL; | |
108 | style -= wxFRAME_NO_WINDOW_MENU ; | |
109 | } | |
110 | else // normal case: we have the window menu, so construct it | |
111 | { | |
112 | m_windowMenu = new wxMenu; | |
113 | ||
114 | m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade")); | |
115 | m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally")); | |
116 | m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically")); | |
117 | m_windowMenu->AppendSeparator(); | |
118 | m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons")); | |
119 | m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next")); | |
120 | } | |
121 | ||
122 | wxFrame::Create( parent , id , title , pos , size , style , name ) ; | |
123 | m_parentFrameActive = true; | |
124 | ||
125 | OnCreateClient(); | |
126 | ||
127 | return true; | |
128 | } | |
129 | ||
130 | wxMDIParentFrame::~wxMDIParentFrame() | |
131 | { | |
132 | DestroyChildren(); | |
133 | ||
134 | // already deleted by DestroyChildren() | |
135 | m_clientWindow = NULL ; | |
136 | ||
137 | delete m_windowMenu; | |
138 | } | |
139 | ||
140 | void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) | |
141 | { | |
142 | wxFrame::SetMenuBar( menu_bar ) ; | |
143 | } | |
144 | ||
145 | void wxMDIParentFrame::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h) | |
146 | { | |
147 | if (x) | |
148 | *x = 0; | |
149 | if (y) | |
150 | *y = 0; | |
151 | ||
152 | wxDisplaySize(w, h); | |
153 | } | |
154 | ||
155 | void wxMDIParentFrame::AddChild(wxWindowBase *child) | |
156 | { | |
157 | // moved this to front, so that we don't run into unset m_parent problems later | |
158 | wxFrame::AddChild(child); | |
159 | ||
160 | if ( !m_currentChild ) | |
161 | { | |
162 | m_currentChild = wxDynamicCast(child, wxMDIChildFrame); | |
163 | ||
164 | if ( m_currentChild && IsShown() && !ShouldBeVisible() ) | |
165 | { | |
166 | // we shouldn't remain visible any more | |
167 | wxFrame::Show(false); | |
168 | m_shouldBeShown = true; | |
169 | } | |
170 | } | |
171 | } | |
172 | ||
173 | void wxMDIParentFrame::RemoveChild(wxWindowBase *child) | |
174 | { | |
175 | if ( child == m_currentChild ) | |
176 | { | |
177 | // the current child isn't active any more, try to find another one | |
178 | m_currentChild = NULL; | |
179 | ||
180 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
181 | node; | |
182 | node = node->GetNext() ) | |
183 | { | |
184 | wxMDIChildFrame * | |
185 | childCur = wxDynamicCast(node->GetData(), wxMDIChildFrame); | |
186 | if ( childCur != child ) | |
187 | { | |
188 | m_currentChild = childCur; | |
189 | break; | |
190 | } | |
191 | } | |
192 | } | |
193 | ||
194 | wxFrame::RemoveChild(child); | |
195 | ||
196 | // if there are no more children left we need to show the frame if we | |
197 | // hadn't shown it before because there were active children and it was | |
198 | // useless (note that we have to do it after fully removing the child, i.e. | |
199 | // after calling the base class RemoveChild() as otherwise we risk to touch | |
200 | // pointer to the child being deleted) | |
201 | if ( !m_currentChild && m_shouldBeShown && !IsShown() ) | |
202 | { | |
203 | // we have to show it, but at least move it out of sight and make it of | |
204 | // smallest possible size (unfortunately (0, 0) doesn't work so that it | |
205 | // doesn't appear in expose | |
206 | SetSize(-10000, -10000, 1, 1); | |
207 | Show(); | |
208 | } | |
209 | } | |
210 | ||
211 | void wxMDIParentFrame::MacActivate(long timestamp, bool activating) | |
212 | { | |
213 | wxLogTrace(TRACE_MDI, wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"), this, timestamp, activating ? wxT("ACTIV") : wxT("deact")); | |
214 | ||
215 | if (activating) | |
216 | { | |
217 | if (s_macDeactivateWindow && s_macDeactivateWindow->GetParent() == this) | |
218 | { | |
219 | wxLogTrace(TRACE_MDI, wxT("child had been scheduled for deactivation, rehighlighting")); | |
220 | ||
221 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true); | |
222 | ||
223 | wxLogTrace(TRACE_MDI, wxT("finished highliting child")); | |
224 | ||
225 | s_macDeactivateWindow = NULL; | |
226 | } | |
227 | else if (s_macDeactivateWindow == this) | |
228 | { | |
229 | wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this); | |
230 | ||
231 | s_macDeactivateWindow = NULL; | |
232 | } | |
233 | else // window to deactivate is NULL or is not us or one of our kids | |
234 | { | |
235 | // activate kid instead | |
236 | if (m_currentChild) | |
237 | m_currentChild->MacActivate(timestamp, activating); | |
238 | else | |
239 | wxFrame::MacActivate(timestamp, activating); | |
240 | } | |
241 | } | |
242 | else | |
243 | { | |
244 | // We were scheduled for deactivation, and now we do it. | |
245 | if (s_macDeactivateWindow == this) | |
246 | { | |
247 | s_macDeactivateWindow = NULL; | |
248 | if (m_currentChild) | |
249 | m_currentChild->MacActivate(timestamp, activating); | |
250 | wxFrame::MacActivate(timestamp, activating); | |
251 | } | |
252 | else // schedule ourselves for deactivation | |
253 | { | |
254 | if (s_macDeactivateWindow) | |
255 | wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"), s_macDeactivateWindow); | |
256 | wxLogTrace(TRACE_MDI, wxT("Scheduling delayed MDI Parent deactivation")); | |
257 | ||
258 | s_macDeactivateWindow = this; | |
259 | } | |
260 | } | |
261 | } | |
262 | ||
263 | void wxMDIParentFrame::OnActivate(wxActivateEvent& event) | |
264 | { | |
265 | event.Skip(); | |
266 | } | |
267 | ||
268 | // Returns the active MDI child window | |
269 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const | |
270 | { | |
271 | return m_currentChild ; | |
272 | } | |
273 | ||
274 | // Create the client window class (don't Create the window, | |
275 | // just return a new class) | |
276 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient() | |
277 | { | |
278 | m_clientWindow = new wxMDIClientWindow( this ); | |
279 | ||
280 | return m_clientWindow; | |
281 | } | |
282 | ||
283 | // Responds to colour changes, and passes event on to children. | |
284 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
285 | { | |
286 | // TODO | |
287 | ||
288 | // Propagate the event to the non-top-level children | |
289 | wxFrame::OnSysColourChanged(event); | |
290 | } | |
291 | ||
292 | // MDI operations | |
293 | void wxMDIParentFrame::Cascade() | |
294 | { | |
295 | // TODO | |
296 | } | |
297 | ||
298 | void wxMDIParentFrame::Tile(wxOrientation WXUNUSED(orient)) | |
299 | { | |
300 | // TODO | |
301 | } | |
302 | ||
303 | void wxMDIParentFrame::ArrangeIcons() | |
304 | { | |
305 | // TODO | |
306 | } | |
307 | ||
308 | void wxMDIParentFrame::ActivateNext() | |
309 | { | |
310 | // TODO | |
311 | } | |
312 | ||
313 | void wxMDIParentFrame::ActivatePrevious() | |
314 | { | |
315 | // TODO | |
316 | } | |
317 | ||
318 | bool wxMDIParentFrame::ShouldBeVisible() const | |
319 | { | |
320 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
321 | node; | |
322 | node = node->GetNext() ) | |
323 | { | |
324 | wxWindow *win = node->GetData(); | |
325 | ||
326 | if ( win->IsShown() | |
327 | && !wxDynamicCast(win, wxMDIChildFrame) | |
328 | #if wxUSE_STATUSBAR | |
329 | && win != (wxWindow*) GetStatusBar() | |
330 | #endif | |
331 | && win != GetClientWindow() ) | |
332 | { | |
333 | // if we have a non-MDI child, do remain visible so that it could | |
334 | // be used | |
335 | return true; | |
336 | } | |
337 | } | |
338 | ||
339 | return false; | |
340 | } | |
341 | ||
342 | bool wxMDIParentFrame::Show( bool show ) | |
343 | { | |
344 | m_shouldBeShown = false; | |
345 | ||
346 | // don't really show the MDI frame unless it has any children other than | |
347 | // MDI children as it is pretty useless in this case | |
348 | ||
349 | if ( show ) | |
350 | { | |
351 | if ( !ShouldBeVisible() && m_currentChild ) | |
352 | { | |
353 | // don't make the window visible now but remember that we should | |
354 | // have had done it | |
355 | m_shouldBeShown = true; | |
356 | ||
357 | return false; | |
358 | } | |
359 | } | |
360 | ||
361 | return wxFrame::Show(show); | |
362 | } | |
363 | ||
364 | // ---------------------------------------------------------------------------- | |
365 | // Child frame | |
366 | // ---------------------------------------------------------------------------- | |
367 | ||
368 | wxMDIChildFrame::wxMDIChildFrame() | |
369 | { | |
370 | Init() ; | |
371 | } | |
372 | void wxMDIChildFrame::Init() | |
373 | { | |
374 | } | |
375 | ||
376 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
377 | wxWindowID id, | |
378 | const wxString& title, | |
379 | const wxPoint& pos, | |
380 | const wxSize& size, | |
381 | long style, | |
382 | const wxString& name) | |
383 | { | |
384 | SetName(name); | |
385 | ||
386 | if ( id == wxID_ANY ) | |
387 | m_windowId = (int)NewControlId(); | |
388 | else | |
389 | m_windowId = id; | |
390 | ||
391 | if (parent) | |
392 | parent->AddChild(this); | |
393 | ||
394 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; | |
395 | ||
396 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
397 | ||
398 | wxModelessWindows.Append(this); | |
399 | ||
400 | return true; | |
401 | } | |
402 | ||
403 | wxMDIChildFrame::~wxMDIChildFrame() | |
404 | { | |
405 | DestroyChildren(); | |
406 | } | |
407 | ||
408 | void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar) | |
409 | { | |
410 | return wxFrame::SetMenuBar( menu_bar ) ; | |
411 | } | |
412 | ||
413 | void wxMDIChildFrame::MacActivate(long timestamp, bool activating) | |
414 | { | |
415 | wxLogTrace(TRACE_MDI, wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this, timestamp, activating ? wxT("ACTIV") : wxT("deact")); | |
416 | ||
417 | wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame); | |
418 | wxASSERT(mdiparent); | |
419 | ||
420 | if (activating) | |
421 | { | |
422 | if (s_macDeactivateWindow == m_parent) | |
423 | { | |
424 | wxLogTrace(TRACE_MDI, wxT("parent had been scheduled for deactivation, rehighlighting")); | |
425 | ||
426 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true); | |
427 | ||
428 | wxLogTrace(TRACE_MDI, wxT("finished highliting parent")); | |
429 | ||
430 | s_macDeactivateWindow = NULL; | |
431 | } | |
432 | else if ((mdiparent->m_currentChild == this) || !s_macDeactivateWindow) | |
433 | mdiparent->wxFrame::MacActivate(timestamp, activating); | |
434 | ||
435 | if (mdiparent->m_currentChild && mdiparent->m_currentChild != this) | |
436 | mdiparent->m_currentChild->wxFrame::MacActivate(timestamp, false); | |
437 | mdiparent->m_currentChild = this; | |
438 | ||
439 | if (s_macDeactivateWindow == this) | |
440 | { | |
441 | wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this); | |
442 | ||
443 | s_macDeactivateWindow = NULL; | |
444 | } | |
445 | else | |
446 | wxFrame::MacActivate(timestamp, activating); | |
447 | } | |
448 | else | |
449 | { | |
450 | // We were scheduled for deactivation, and now we do it. | |
451 | if (s_macDeactivateWindow == this) | |
452 | { | |
453 | s_macDeactivateWindow = NULL; | |
454 | wxFrame::MacActivate(timestamp, activating); | |
455 | if (mdiparent->m_currentChild == this) | |
456 | mdiparent->wxFrame::MacActivate(timestamp, activating); | |
457 | } | |
458 | else // schedule ourselves for deactivation | |
459 | { | |
460 | if (s_macDeactivateWindow) | |
461 | wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"), s_macDeactivateWindow); | |
462 | wxLogTrace(TRACE_MDI, wxT("Scheduling delayed deactivation")); | |
463 | ||
464 | s_macDeactivateWindow = this; | |
465 | } | |
466 | } | |
467 | } | |
468 | ||
469 | // MDI operations | |
470 | void wxMDIChildFrame::Maximize() | |
471 | { | |
472 | wxFrame::Maximize() ; | |
473 | } | |
474 | ||
475 | void wxMDIChildFrame::Restore() | |
476 | { | |
477 | wxFrame::Restore() ; | |
478 | } | |
479 | ||
480 | void wxMDIChildFrame::Activate() | |
481 | { | |
482 | } | |
483 | ||
484 | //----------------------------------------------------------------------------- | |
485 | // wxMDIClientWindow | |
486 | //----------------------------------------------------------------------------- | |
487 | ||
488 | wxMDIClientWindow::wxMDIClientWindow() | |
489 | { | |
490 | } | |
491 | ||
492 | wxMDIClientWindow::~wxMDIClientWindow() | |
493 | { | |
494 | DestroyChildren(); | |
495 | } | |
496 | ||
497 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) | |
498 | { | |
499 | if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style) ) | |
500 | return false; | |
501 | ||
502 | wxModelessWindows.Append(this); | |
503 | ||
504 | return true; | |
505 | } | |
506 | ||
507 | // Get size *available for subwindows* i.e. excluding menu bar. | |
508 | void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const | |
509 | { | |
510 | wxDisplaySize( x , y ) ; | |
511 | } | |
512 | ||
513 | // Explicitly call default scroll behaviour | |
514 | void wxMDIClientWindow::OnScroll(wxScrollEvent& WXUNUSED(event)) | |
515 | { | |
516 | } | |
517 | ||
518 | #endif // wxUSE_MDI |