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