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