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