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