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