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