]> git.saurik.com Git - wxWidgets.git/blob - 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
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/mdi.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/log.h"
18 #endif
19
20 #include "wx/menu.h"
21 #include "wx/settings.h"
22
23 #include "wx/mac/private.h"
24 #include "wx/mac/uma.h"
25
26 extern wxWindowList wxModelessWindows;
27
28 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
29 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
30 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
31
32 BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
33 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
34 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
35 END_EVENT_TABLE()
36
37 BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
38 EVT_SCROLL(wxMDIClientWindow::OnScroll)
39 END_EVENT_TABLE()
40
41 static const int IDM_WINDOWTILE = 4001;
42 static const int IDM_WINDOWTILEHOR = 4001;
43 static const int IDM_WINDOWCASCADE = 4002;
44 static const int IDM_WINDOWICONS = 4003;
45 static const int IDM_WINDOWNEXT = 4004;
46 static const int IDM_WINDOWTILEVERT = 4005;
47 static const int IDM_WINDOWPREV = 4006;
48
49 // This range gives a maximum of 500 MDI children. Should be enough :-)
50 static const int wxFIRST_MDI_CHILD = 4100;
51 static const int wxLAST_MDI_CHILD = 4600;
52
53 // Status border dimensions
54 static const int wxTHICK_LINE_BORDER = 3;
55
56 // Parent frame
57
58 wxMDIParentFrame::wxMDIParentFrame()
59 {
60 m_clientWindow = NULL;
61 m_currentChild = NULL;
62 m_windowMenu = (wxMenu*) NULL;
63 m_parentFrameActive = TRUE;
64 }
65
66 bool 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;
76
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;
87
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 }
95
96 wxFrame::Create( parent , id , title , pos , size , style , name ) ;
97 m_parentFrameActive = TRUE;
98
99 OnCreateClient();
100
101 return TRUE;
102 }
103
104 wxMDIParentFrame::~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;
113 #endif
114 m_clientWindow = NULL ;
115
116 if (m_windowMenu)
117 {
118 delete m_windowMenu;
119 m_windowMenu = (wxMenu*) NULL;
120 }
121
122 if ( m_clientWindow )
123 {
124 delete m_clientWindow;
125 m_clientWindow = NULL ;
126 }
127 }
128
129
130 void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
131 {
132 wxFrame::SetMenuBar( menu_bar ) ;
133 }
134
135 void 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
181 void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
182 {
183 event.Skip();
184 }
185
186 // Returns the active MDI child window
187 wxMDIChildFrame *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)
194 wxMDIClientWindow *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.
201 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
202 {
203 // TODO
204
205 // Propagate the event to the non-top-level children
206 wxFrame::OnSysColourChanged(event);
207 }
208
209 // MDI operations
210 void wxMDIParentFrame::Cascade()
211 {
212 // TODO
213 }
214
215 void wxMDIParentFrame::Tile(wxOrientation WXUNUSED(orient))
216 {
217 // TODO
218 }
219
220 void wxMDIParentFrame::ArrangeIcons()
221 {
222 // TODO
223 }
224
225 void wxMDIParentFrame::ActivateNext()
226 {
227 // TODO
228 }
229
230 void wxMDIParentFrame::ActivatePrevious()
231 {
232 // TODO
233 }
234
235 // Child frame
236
237 wxMDIChildFrame::wxMDIChildFrame()
238 {
239 Init() ;
240 }
241 void wxMDIChildFrame::Init()
242 {
243 }
244
245 bool 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);
254
255 if ( id > -1 )
256 m_windowId = id;
257 else
258 m_windowId = (int)NewControlId();
259
260 if (parent) parent->AddChild(this);
261
262 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
263
264 m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
265 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
266
267 wxModelessWindows.Append(this);
268 return FALSE;
269 }
270
271 wxMDIChildFrame::~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;
284 #endif
285 }
286
287 void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
288 {
289 return wxFrame::SetMenuBar( menu_bar ) ;
290 }
291
292 void 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);
308
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
342 void wxMDIChildFrame::Maximize()
343 {
344 wxFrame::Maximize() ;
345 }
346
347 void wxMDIChildFrame::Restore()
348 {
349 wxFrame::Restore() ;
350 }
351
352 void wxMDIChildFrame::Activate()
353 {
354 }
355
356 //-----------------------------------------------------------------------------
357 // wxMDIClientWindow
358 //-----------------------------------------------------------------------------
359
360 wxMDIClientWindow::wxMDIClientWindow()
361 {
362 }
363
364 wxMDIClientWindow::~wxMDIClientWindow()
365 {
366 DestroyChildren();
367 }
368
369 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
370 {
371
372 m_windowId = (int)NewControlId();
373
374 if ( parent )
375 {
376 parent->AddChild(this);
377 }
378 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
379
380 wxModelessWindows.Append(this);
381 return TRUE;
382 }
383
384 // Get size *available for subwindows* i.e. excluding menu bar.
385 void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
386 {
387 wxDisplaySize( x , y ) ;
388 }
389
390 // Explicitly call default scroll behaviour
391 void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
392 {
393 }