]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/mdi.cpp
cleanup - reformat; added (disabled) support for secondary highlight color
[wxWidgets.git] / src / mac / carbon / mdi.cpp
CommitLineData
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
SC
12#include "wx/wxprec.h"
13
179e085f
RN
14#if wxUSE_MDI
15
38c8fce8
DE
16#ifndef WX_PRECOMP
17 #include "wx/mdi.h"
18 #include "wx/log.h"
19 #include "wx/menu.h"
20 #include "wx/settings.h"
21 #include "wx/statusbr.h"
22#endif
e9576ca5 23
76a5e5d2 24#include "wx/mac/private.h"
70024cfb 25#include "wx/mac/uma.h"
76a5e5d2 26
fe08e597 27extern wxWindowList wxModelessWindows;
e9576ca5 28
e9576ca5
SC
29IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
30IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
31IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
32
33BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
e9576ca5
SC
34 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
35 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
36END_EVENT_TABLE()
37
38BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
39 EVT_SCROLL(wxMDIClientWindow::OnScroll)
40END_EVENT_TABLE()
41
fd8278bf
VZ
42static const wxChar *TRACE_MDI = _T("mdi");
43
0a67a93b
SC
44static const int IDM_WINDOWTILE = 4001;
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;
4f3b37fd 50static const int IDM_WINDOWPREV = 4006;
0a67a93b
SC
51
52// This range gives a maximum of 500 MDI children. Should be enough :-)
53static const int wxFIRST_MDI_CHILD = 4100;
54static const int wxLAST_MDI_CHILD = 4600;
55
56// Status border dimensions
57static const int wxTHICK_LINE_BORDER = 3;
58
a57ac1c4 59// ----------------------------------------------------------------------------
e9576ca5 60// Parent frame
a57ac1c4 61// ----------------------------------------------------------------------------
e9576ca5 62
a57ac1c4 63void wxMDIParentFrame::Init()
e9576ca5 64{
0a67a93b
SC
65 m_clientWindow = NULL;
66 m_currentChild = NULL;
67 m_windowMenu = (wxMenu*) NULL;
a57ac1c4
VZ
68 m_parentFrameActive = true;
69 m_shouldBeShown = false;
e9576ca5
SC
70}
71
72bool wxMDIParentFrame::Create(wxWindow *parent,
a57ac1c4
VZ
73 wxWindowID id,
74 const wxString& title,
75 const wxPoint& pos,
76 const wxSize& size,
77 long style,
78 const wxString& name)
e9576ca5 79{
e40298d5
JS
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 ) ;
a57ac1c4 100 m_parentFrameActive = true;
e40298d5
JS
101
102 OnCreateClient();
103
a57ac1c4 104 return true;
e9576ca5
SC
105}
106
107wxMDIParentFrame::~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
117void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
118{
e40298d5 119 wxFrame::SetMenuBar( menu_bar ) ;
e9576ca5
SC
120}
121
0bba37f5
DE
122void 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
a57ac1c4
VZ
131void wxMDIParentFrame::AddChild(wxWindowBase *child)
132{
133 if ( !m_currentChild )
134 {
135 m_currentChild = wxDynamicCast(child, wxMDIChildFrame);
136
3ee39f97 137 if ( m_currentChild && IsShown() && !ShouldBeVisible() )
a57ac1c4 138 {
3ee39f97
VZ
139 // we shouldn't remain visible any more
140 wxFrame::Show(false);
141 m_shouldBeShown = true;
a57ac1c4
VZ
142 }
143 }
144
145 wxFrame::AddChild(child);
146}
147
148void wxMDIParentFrame::RemoveChild(wxWindowBase *child)
149{
150 if ( child == m_currentChild )
151 {
152 // the current child isn't active any more, try to find another one
153 m_currentChild = NULL;
154
155 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
156 node;
157 node = node->GetNext() )
158 {
159 wxMDIChildFrame *
160 childCur = wxDynamicCast(node->GetData(), wxMDIChildFrame);
161 if ( childCur != child )
162 {
163 m_currentChild = childCur;
164 break;
165 }
166 }
167 }
168
169 wxFrame::RemoveChild(child);
170
171 // if there are no more children left we need to show the frame if we
172 // hadn't shown it before because there were active children and it was
173 // useless (note that we have to do it after fully removing the child, i.e.
174 // after calling the base class RemoveChild() as otherwise we risk to touch
175 // pointer to the child being deleted)
176 if ( !m_currentChild && m_shouldBeShown && !IsShown() )
177 {
178 // we have to show it, but at least move it out of sight and make it of
179 // smallest possible size (unfortunately (0, 0) doesn't work so that it
180 // doesn't appear in expose
181 SetSize(-10000, -10000, 1, 1);
182 Show();
183 }
184}
185
70024cfb 186void wxMDIParentFrame::MacActivate(long timestamp, bool activating)
e9576ca5 187{
fd8278bf 188 wxLogTrace(TRACE_MDI, wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
70024cfb 189 if(activating)
e40298d5 190 {
70024cfb
DE
191 if(s_macDeactivateWindow && s_macDeactivateWindow->GetParent()==this)
192 {
fd8278bf 193 wxLogTrace(TRACE_MDI, wxT("child had been scheduled for deactivation, rehighlighting"));
70024cfb 194 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
fd8278bf 195 wxLogTrace(TRACE_MDI, wxT("done highliting child"));
70024cfb
DE
196 s_macDeactivateWindow = NULL;
197 }
198 else if(s_macDeactivateWindow == this)
199 {
fd8278bf 200 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this);
70024cfb
DE
201 s_macDeactivateWindow = NULL;
202 }
203 else // window to deactivate is NULL or is not us or one of our kids
204 {
205 // activate kid instead
206 if(m_currentChild)
207 m_currentChild->MacActivate(timestamp,activating);
208 else
209 wxFrame::MacActivate(timestamp,activating);
210 }
e40298d5 211 }
70024cfb 212 else
e40298d5 213 {
70024cfb
DE
214 // We were scheduled for deactivation, and now we do it.
215 if(s_macDeactivateWindow==this)
e40298d5 216 {
70024cfb
DE
217 s_macDeactivateWindow = NULL;
218 if(m_currentChild)
219 m_currentChild->MacActivate(timestamp,activating);
220 wxFrame::MacActivate(timestamp,activating);
221 }
222 else // schedule ourselves for deactivation
223 {
224 if(s_macDeactivateWindow)
fd8278bf
VZ
225 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
226 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed MDI Parent deactivation"));
70024cfb 227 s_macDeactivateWindow = this;
e40298d5 228 }
e40298d5 229 }
e9576ca5
SC
230}
231
70024cfb
DE
232void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
233{
234 event.Skip();
235}
236
e9576ca5
SC
237// Returns the active MDI child window
238wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
239{
e40298d5 240 return m_currentChild ;
e9576ca5
SC
241}
242
243// Create the client window class (don't Create the window,
244// just return a new class)
245wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
246{
0a67a93b
SC
247 m_clientWindow = new wxMDIClientWindow( this );
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
e40298d5 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
49c48f81 297 && win != GetStatusBar()
a57ac1c4 298#endif // wxUSE_STATUSBAR
49c48f81 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;
324 return false;
4a60e3f0 325 }
29e92efb
VZ
326 }
327
a57ac1c4 328 return wxFrame::Show(show);
29e92efb
VZ
329}
330
a57ac1c4 331// ----------------------------------------------------------------------------
e9576ca5 332// Child frame
a57ac1c4 333// ----------------------------------------------------------------------------
e9576ca5
SC
334
335wxMDIChildFrame::wxMDIChildFrame()
0a67a93b
SC
336{
337 Init() ;
338}
339void wxMDIChildFrame::Init()
e9576ca5
SC
340{
341}
342
343bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
e40298d5
JS
344 wxWindowID id,
345 const wxString& title,
346 const wxPoint& pos,
347 const wxSize& size,
348 long style,
349 const wxString& name)
e9576ca5
SC
350{
351 SetName(name);
e40298d5 352
e9576ca5
SC
353 if ( id > -1 )
354 m_windowId = id;
355 else
356 m_windowId = (int)NewControlId();
e40298d5 357
e9576ca5 358 if (parent) parent->AddChild(this);
e40298d5
JS
359
360 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
361
facd6764
SC
362 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
363
e9576ca5 364 wxModelessWindows.Append(this);
a57ac1c4 365 return false;
e9576ca5
SC
366}
367
368wxMDIChildFrame::~wxMDIChildFrame()
369{
0a67a93b 370 DestroyChildren();
e9576ca5
SC
371}
372
373void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
374{
e40298d5 375 return wxFrame::SetMenuBar( menu_bar ) ;
e9576ca5
SC
376}
377
70024cfb
DE
378void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
379{
fd8278bf 380 wxLogTrace(TRACE_MDI, wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
70024cfb
DE
381 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
382 wxASSERT(mdiparent);
383 if(activating)
384 {
385 if(s_macDeactivateWindow == m_parent)
386 {
fd8278bf 387 wxLogTrace(TRACE_MDI, wxT("parent had been scheduled for deactivation, rehighlighting"));
70024cfb 388 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
fd8278bf 389 wxLogTrace(TRACE_MDI, wxT("done highliting parent"));
70024cfb
DE
390 s_macDeactivateWindow = NULL;
391 }
392 else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow)
393 mdiparent->wxFrame::MacActivate(timestamp,activating);
394
395 if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this)
396 mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false);
397 mdiparent->m_currentChild = this;
398
399 if(s_macDeactivateWindow==this)
400 {
fd8278bf 401 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"),this);
70024cfb
DE
402 s_macDeactivateWindow=NULL;
403 }
404 else
405 wxFrame::MacActivate(timestamp, activating);
406 }
407 else
408 {
409 // We were scheduled for deactivation, and now we do it.
410 if(s_macDeactivateWindow==this)
411 {
412 s_macDeactivateWindow = NULL;
413 wxFrame::MacActivate(timestamp,activating);
414 if(mdiparent->m_currentChild==this)
415 mdiparent->wxFrame::MacActivate(timestamp,activating);
416 }
417 else // schedule ourselves for deactivation
418 {
419 if(s_macDeactivateWindow)
fd8278bf
VZ
420 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
421 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed deactivation"));
70024cfb
DE
422 s_macDeactivateWindow = this;
423 }
424 }
425}
426
e9576ca5
SC
427// MDI operations
428void wxMDIChildFrame::Maximize()
429{
0a67a93b 430 wxFrame::Maximize() ;
e9576ca5
SC
431}
432
433void wxMDIChildFrame::Restore()
434{
0a67a93b 435 wxFrame::Restore() ;
e9576ca5
SC
436}
437
438void wxMDIChildFrame::Activate()
439{
e9576ca5
SC
440}
441
0a67a93b
SC
442//-----------------------------------------------------------------------------
443// wxMDIClientWindow
444//-----------------------------------------------------------------------------
e9576ca5
SC
445
446wxMDIClientWindow::wxMDIClientWindow()
447{
448}
449
450wxMDIClientWindow::~wxMDIClientWindow()
451{
0a67a93b 452 DestroyChildren();
e9576ca5
SC
453}
454
455bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
456{
84be293d 457 if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style))
a57ac1c4 458 return false;
e40298d5 459
0a67a93b 460 wxModelessWindows.Append(this);
a57ac1c4 461 return true;
e9576ca5
SC
462}
463
be7a1013
DE
464// Get size *available for subwindows* i.e. excluding menu bar.
465void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
466{
467 wxDisplaySize( x , y ) ;
468}
469
e9576ca5
SC
470// Explicitly call default scroll behaviour
471void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
472{
e9576ca5
SC
473}
474
a57ac1c4 475#endif // wxUSE_MDI
179e085f 476