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