]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/mdi.cpp
fixing visibility checks for native toolbars
[wxWidgets.git] / src / mac / classic / mdi.cpp
CommitLineData
2646f485
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: mdi.cpp
3// Purpose: MDI classes
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "mdi.h"
14#endif
15
16#include "wx/mdi.h"
17#include "wx/menu.h"
18#include "wx/settings.h"
19#include "wx/log.h"
20
21#include "wx/mac/private.h"
22#include "wx/mac/uma.h"
23
24extern wxWindowList wxModelessWindows;
25
2646f485
SC
26IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
27IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
28IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
29
30BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
31 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
32 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
33END_EVENT_TABLE()
34
35BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
36 EVT_SCROLL(wxMDIClientWindow::OnScroll)
37END_EVENT_TABLE()
38
2646f485
SC
39static const int IDM_WINDOWTILE = 4001;
40static const int IDM_WINDOWTILEHOR = 4001;
41static const int IDM_WINDOWCASCADE = 4002;
42static const int IDM_WINDOWICONS = 4003;
43static const int IDM_WINDOWNEXT = 4004;
44static const int IDM_WINDOWTILEVERT = 4005;
45static const int IDM_WINDOWPREV = 4006;
46
47// This range gives a maximum of 500 MDI children. Should be enough :-)
48static const int wxFIRST_MDI_CHILD = 4100;
49static const int wxLAST_MDI_CHILD = 4600;
50
51// Status border dimensions
52static const int wxTHICK_LINE_BORDER = 3;
53
54// Parent frame
55
56wxMDIParentFrame::wxMDIParentFrame()
57{
58 m_clientWindow = NULL;
59 m_currentChild = NULL;
60 m_windowMenu = (wxMenu*) NULL;
61 m_parentFrameActive = TRUE;
62}
63
64bool wxMDIParentFrame::Create(wxWindow *parent,
65 wxWindowID id,
66 const wxString& title,
67 const wxPoint& pos,
68 const wxSize& size,
69 long style,
70 const wxString& name)
71{
72 m_clientWindow = NULL;
73 m_currentChild = NULL;
74
75 // this style can be used to prevent a window from having the standard MDI
76 // "Window" menu
77 if ( style & wxFRAME_NO_WINDOW_MENU )
78 {
79 m_windowMenu = (wxMenu *)NULL;
80 style -= wxFRAME_NO_WINDOW_MENU ;
81 }
82 else // normal case: we have the window menu, so construct it
83 {
84 m_windowMenu = new wxMenu;
85
86 m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade"));
87 m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally"));
88 m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically"));
89 m_windowMenu->AppendSeparator();
90 m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons"));
91 m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next"));
92 }
93
94 wxFrame::Create( parent , id , title , pos , size , style , name ) ;
95 m_parentFrameActive = TRUE;
96
97 OnCreateClient();
98
99 return TRUE;
100}
101
102wxMDIParentFrame::~wxMDIParentFrame()
103{
104 DestroyChildren();
105 // already delete by DestroyChildren()
106#if wxUSE_TOOLBAR
107 m_frameToolBar = NULL;
108#endif
109#if wxUSE_STATUSBAR
110 m_frameStatusBar = NULL;
111#endif
112 m_clientWindow = NULL ;
113
114 if (m_windowMenu)
115 {
116 delete m_windowMenu;
117 m_windowMenu = (wxMenu*) NULL;
118 }
119
120 if ( m_clientWindow )
121 {
122 delete m_clientWindow;
123 m_clientWindow = NULL ;
124 }
125}
126
127
128void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
129{
130 wxFrame::SetMenuBar( menu_bar ) ;
131}
132
133void wxMDIParentFrame::MacActivate(long timestamp, bool activating)
134{
135 wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
136 if(activating)
137 {
138 if(s_macDeactivateWindow && s_macDeactivateWindow->GetParent()==this)
139 {
140 wxLogDebug(wxT("child had been scheduled for deactivation, rehighlighting"));
141 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
142 wxLogDebug(wxT("done highliting child"));
143 s_macDeactivateWindow = NULL;
144 }
145 else if(s_macDeactivateWindow == this)
146 {
147 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"), this);
148 s_macDeactivateWindow = NULL;
149 }
150 else // window to deactivate is NULL or is not us or one of our kids
151 {
152 // activate kid instead
153 if(m_currentChild)
154 m_currentChild->MacActivate(timestamp,activating);
155 else
156 wxFrame::MacActivate(timestamp,activating);
157 }
158 }
159 else
160 {
161 // We were scheduled for deactivation, and now we do it.
162 if(s_macDeactivateWindow==this)
163 {
164 s_macDeactivateWindow = NULL;
165 if(m_currentChild)
166 m_currentChild->MacActivate(timestamp,activating);
167 wxFrame::MacActivate(timestamp,activating);
168 }
169 else // schedule ourselves for deactivation
170 {
171 if(s_macDeactivateWindow)
172 wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
173 wxLogDebug(wxT("Scheduling delayed MDI Parent deactivation"));
174 s_macDeactivateWindow = this;
175 }
176 }
177}
178
179void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
180{
181 event.Skip();
182}
183
184// Returns the active MDI child window
185wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
186{
187 return m_currentChild ;
188}
189
190// Create the client window class (don't Create the window,
191// just return a new class)
192wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
193{
194 m_clientWindow = new wxMDIClientWindow( this );
195 return m_clientWindow;
196}
197
198// Responds to colour changes, and passes event on to children.
199void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
200{
201 // TODO
202
203 // Propagate the event to the non-top-level children
204 wxFrame::OnSysColourChanged(event);
205}
206
207// MDI operations
208void wxMDIParentFrame::Cascade()
209{
210 // TODO
211}
212
0d97c090 213void wxMDIParentFrame::Tile(wxOrientation WXUNUSED(orient))
2646f485
SC
214{
215 // TODO
216}
217
218void wxMDIParentFrame::ArrangeIcons()
219{
220 // TODO
221}
222
223void wxMDIParentFrame::ActivateNext()
224{
225 // TODO
226}
227
228void wxMDIParentFrame::ActivatePrevious()
229{
230 // TODO
231}
232
233// Child frame
234
235wxMDIChildFrame::wxMDIChildFrame()
236{
237 Init() ;
238}
239void wxMDIChildFrame::Init()
240{
241}
242
243bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
244 wxWindowID id,
245 const wxString& title,
246 const wxPoint& pos,
247 const wxSize& size,
248 long style,
249 const wxString& name)
250{
251 SetName(name);
252
253 if ( id > -1 )
254 m_windowId = id;
255 else
256 m_windowId = (int)NewControlId();
257
258 if (parent) parent->AddChild(this);
259
260 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
261
262 m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
263 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
264
265 wxModelessWindows.Append(this);
266 return FALSE;
267}
268
269wxMDIChildFrame::~wxMDIChildFrame()
270{
271 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
272 wxASSERT(mdiparent);
273 if(mdiparent->m_currentChild == this)
274 mdiparent->m_currentChild = NULL;
275 DestroyChildren();
276 // already delete by DestroyChildren()
277#if wxUSE_TOOLBAR
278 m_frameToolBar = NULL;
279#endif
280#if wxUSE_STATUSBAR
281 m_frameStatusBar = NULL;
282#endif
283}
284
285void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
286{
287 return wxFrame::SetMenuBar( menu_bar ) ;
288}
289
290void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
291{
292 wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
293 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
294 wxASSERT(mdiparent);
295 if(activating)
296 {
297 if(s_macDeactivateWindow == m_parent)
298 {
299 wxLogDebug(wxT("parent had been scheduled for deactivation, rehighlighting"));
300 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
301 wxLogDebug(wxT("done highliting parent"));
302 s_macDeactivateWindow = NULL;
303 }
304 else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow)
305 mdiparent->wxFrame::MacActivate(timestamp,activating);
306
307 if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this)
308 mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false);
309 mdiparent->m_currentChild = this;
310
311 if(s_macDeactivateWindow==this)
312 {
313 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this);
314 s_macDeactivateWindow=NULL;
315 }
316 else
317 wxFrame::MacActivate(timestamp, activating);
318 }
319 else
320 {
321 // We were scheduled for deactivation, and now we do it.
322 if(s_macDeactivateWindow==this)
323 {
324 s_macDeactivateWindow = NULL;
325 wxFrame::MacActivate(timestamp,activating);
326 if(mdiparent->m_currentChild==this)
327 mdiparent->wxFrame::MacActivate(timestamp,activating);
328 }
329 else // schedule ourselves for deactivation
330 {
331 if(s_macDeactivateWindow)
332 wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
333 wxLogDebug(wxT("Scheduling delayed deactivation"));
334 s_macDeactivateWindow = this;
335 }
336 }
337}
338
339// MDI operations
340void wxMDIChildFrame::Maximize()
341{
342 wxFrame::Maximize() ;
343}
344
345void wxMDIChildFrame::Restore()
346{
347 wxFrame::Restore() ;
348}
349
350void wxMDIChildFrame::Activate()
351{
352}
353
354//-----------------------------------------------------------------------------
355// wxMDIClientWindow
356//-----------------------------------------------------------------------------
357
358wxMDIClientWindow::wxMDIClientWindow()
359{
360}
361
362wxMDIClientWindow::~wxMDIClientWindow()
363{
364 DestroyChildren();
365}
366
367bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
368{
369
370 m_windowId = (int)NewControlId();
371
372 if ( parent )
373 {
374 parent->AddChild(this);
375 }
376 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
377
378 wxModelessWindows.Append(this);
379 return TRUE;
380}
381
382// Get size *available for subwindows* i.e. excluding menu bar.
383void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
384{
385 wxDisplaySize( x , y ) ;
386}
387
388// Explicitly call default scroll behaviour
389void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
390{
391}
392