]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/mdi.cpp
Fix centering of top-level children of wxMDIParentFrame on Mac
[wxWidgets.git] / src / mac / carbon / mdi.cpp
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
9 // Licence: wxWindows licence
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
24 extern wxWindowList wxModelessWindows;
25
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
28 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
29 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
30
31 BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
32 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
33 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
34 END_EVENT_TABLE()
35
36 BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
37 EVT_SCROLL(wxMDIClientWindow::OnScroll)
38 END_EVENT_TABLE()
39
40 #endif
41
42 static const int IDM_WINDOWTILE = 4001;
43 static const int IDM_WINDOWTILEHOR = 4001;
44 static const int IDM_WINDOWCASCADE = 4002;
45 static const int IDM_WINDOWICONS = 4003;
46 static const int IDM_WINDOWNEXT = 4004;
47 static const int IDM_WINDOWTILEVERT = 4005;
48 static const int IDM_WINDOWPREV = 4006;
49
50 // This range gives a maximum of 500 MDI children. Should be enough :-)
51 static const int wxFIRST_MDI_CHILD = 4100;
52 static const int wxLAST_MDI_CHILD = 4600;
53
54 // Status border dimensions
55 static const int wxTHICK_LINE_BORDER = 3;
56
57 // Parent frame
58
59 wxMDIParentFrame::wxMDIParentFrame()
60 {
61 m_clientWindow = NULL;
62 m_currentChild = NULL;
63 m_windowMenu = (wxMenu*) NULL;
64 m_parentFrameActive = TRUE;
65 }
66
67 bool wxMDIParentFrame::Create(wxWindow *parent,
68 wxWindowID id,
69 const wxString& title,
70 const wxPoint& pos,
71 const wxSize& size,
72 long style,
73 const wxString& name)
74 {
75 m_clientWindow = NULL;
76 m_currentChild = NULL;
77
78 // this style can be used to prevent a window from having the standard MDI
79 // "Window" menu
80 if ( style & wxFRAME_NO_WINDOW_MENU )
81 {
82 m_windowMenu = (wxMenu *)NULL;
83 style -= wxFRAME_NO_WINDOW_MENU ;
84 }
85 else // normal case: we have the window menu, so construct it
86 {
87 m_windowMenu = new wxMenu;
88
89 m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade"));
90 m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally"));
91 m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically"));
92 m_windowMenu->AppendSeparator();
93 m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons"));
94 m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next"));
95 }
96
97 wxFrame::Create( parent , id , title , pos , size , style , name ) ;
98 m_parentFrameActive = TRUE;
99
100 OnCreateClient();
101
102 return TRUE;
103 }
104
105 wxMDIParentFrame::~wxMDIParentFrame()
106 {
107 DestroyChildren();
108 // already deleted by DestroyChildren()
109 m_clientWindow = NULL ;
110
111 delete m_windowMenu;
112 }
113
114
115 void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
116 {
117 wxFrame::SetMenuBar( menu_bar ) ;
118 }
119
120 void wxMDIParentFrame::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h)
121 {
122 if(x)
123 *x = 0;
124 if(y)
125 *y = 0;
126 wxDisplaySize(w,h);
127 }
128
129 void 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
175 void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
176 {
177 event.Skip();
178 }
179
180 // Returns the active MDI child window
181 wxMDIChildFrame *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)
188 wxMDIClientWindow *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.
195 void 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
204 void wxMDIParentFrame::Cascade()
205 {
206 // TODO
207 }
208
209 void wxMDIParentFrame::Tile()
210 {
211 // TODO
212 }
213
214 void wxMDIParentFrame::ArrangeIcons()
215 {
216 // TODO
217 }
218
219 void wxMDIParentFrame::ActivateNext()
220 {
221 // TODO
222 }
223
224 void wxMDIParentFrame::ActivatePrevious()
225 {
226 // TODO
227 }
228
229 bool wxMDIParentFrame::Show( bool show )
230 {
231 // don't really show the MDI frame unless it has any children other than
232 // MDI children as it is pretty useless in this case
233
234 if ( show )
235 {
236 // TODO: check for other children
237 Move(-10000, -10000);
238 }
239
240 if ( !wxFrame::Show(show) )
241 return false;
242
243 return true;
244 }
245
246 // Child frame
247
248 wxMDIChildFrame::wxMDIChildFrame()
249 {
250 Init() ;
251 }
252 void wxMDIChildFrame::Init()
253 {
254 }
255
256 bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
257 wxWindowID id,
258 const wxString& title,
259 const wxPoint& pos,
260 const wxSize& size,
261 long style,
262 const wxString& name)
263 {
264 SetName(name);
265
266 if ( id > -1 )
267 m_windowId = id;
268 else
269 m_windowId = (int)NewControlId();
270
271 if (parent) parent->AddChild(this);
272
273 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
274
275 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
276
277 wxModelessWindows.Append(this);
278 return FALSE;
279 }
280
281 wxMDIChildFrame::~wxMDIChildFrame()
282 {
283 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
284 wxASSERT(mdiparent);
285 if(mdiparent->m_currentChild == this)
286 mdiparent->m_currentChild = NULL;
287 DestroyChildren();
288 }
289
290 void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
291 {
292 return wxFrame::SetMenuBar( menu_bar ) ;
293 }
294
295 void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
296 {
297 wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
298 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
299 wxASSERT(mdiparent);
300 if(activating)
301 {
302 if(s_macDeactivateWindow == m_parent)
303 {
304 wxLogDebug(wxT("parent had been scheduled for deactivation, rehighlighting"));
305 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
306 wxLogDebug(wxT("done highliting parent"));
307 s_macDeactivateWindow = NULL;
308 }
309 else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow)
310 mdiparent->wxFrame::MacActivate(timestamp,activating);
311
312 if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this)
313 mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false);
314 mdiparent->m_currentChild = this;
315
316 if(s_macDeactivateWindow==this)
317 {
318 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this);
319 s_macDeactivateWindow=NULL;
320 }
321 else
322 wxFrame::MacActivate(timestamp, activating);
323 }
324 else
325 {
326 // We were scheduled for deactivation, and now we do it.
327 if(s_macDeactivateWindow==this)
328 {
329 s_macDeactivateWindow = NULL;
330 wxFrame::MacActivate(timestamp,activating);
331 if(mdiparent->m_currentChild==this)
332 mdiparent->wxFrame::MacActivate(timestamp,activating);
333 }
334 else // schedule ourselves for deactivation
335 {
336 if(s_macDeactivateWindow)
337 wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
338 wxLogDebug(wxT("Scheduling delayed deactivation"));
339 s_macDeactivateWindow = this;
340 }
341 }
342 }
343
344 // MDI operations
345 void wxMDIChildFrame::Maximize()
346 {
347 wxFrame::Maximize() ;
348 }
349
350 void wxMDIChildFrame::Restore()
351 {
352 wxFrame::Restore() ;
353 }
354
355 void wxMDIChildFrame::Activate()
356 {
357 }
358
359 //-----------------------------------------------------------------------------
360 // wxMDIClientWindow
361 //-----------------------------------------------------------------------------
362
363 wxMDIClientWindow::wxMDIClientWindow()
364 {
365 }
366
367 wxMDIClientWindow::~wxMDIClientWindow()
368 {
369 DestroyChildren();
370 }
371
372 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
373 {
374 if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style))
375 return FALSE;
376
377 wxModelessWindows.Append(this);
378 return TRUE;
379 }
380
381 // Get size *available for subwindows* i.e. excluding menu bar.
382 void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
383 {
384 wxDisplaySize( x , y ) ;
385 }
386
387 // Explicitly call default scroll behaviour
388 void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
389 {
390 }
391