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