]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/mdi.cpp
b79928d8f6effd058471e5e1780bd1fe53349560
[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 {
242 // call the base class version to just update the flag but don't
243 // really make the window visible
244 return wxFrameBase::Show();
245 }
246 }
247
248 if ( !wxFrame::Show(show) )
249 return false;
250
251 return true;
252 }
253
254 // Child frame
255
256 wxMDIChildFrame::wxMDIChildFrame()
257 {
258 Init() ;
259 }
260 void wxMDIChildFrame::Init()
261 {
262 }
263
264 bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
265 wxWindowID id,
266 const wxString& title,
267 const wxPoint& pos,
268 const wxSize& size,
269 long style,
270 const wxString& name)
271 {
272 SetName(name);
273
274 if ( id > -1 )
275 m_windowId = id;
276 else
277 m_windowId = (int)NewControlId();
278
279 if (parent) parent->AddChild(this);
280
281 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
282
283 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
284
285 wxModelessWindows.Append(this);
286 return FALSE;
287 }
288
289 wxMDIChildFrame::~wxMDIChildFrame()
290 {
291 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
292 wxASSERT(mdiparent);
293 if(mdiparent->m_currentChild == this)
294 mdiparent->m_currentChild = NULL;
295 DestroyChildren();
296 }
297
298 void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
299 {
300 return wxFrame::SetMenuBar( menu_bar ) ;
301 }
302
303 void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
304 {
305 wxLogTrace(TRACE_MDI, wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
306 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
307 wxASSERT(mdiparent);
308 if(activating)
309 {
310 if(s_macDeactivateWindow == m_parent)
311 {
312 wxLogTrace(TRACE_MDI, wxT("parent had been scheduled for deactivation, rehighlighting"));
313 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
314 wxLogTrace(TRACE_MDI, wxT("done highliting parent"));
315 s_macDeactivateWindow = NULL;
316 }
317 else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow)
318 mdiparent->wxFrame::MacActivate(timestamp,activating);
319
320 if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this)
321 mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false);
322 mdiparent->m_currentChild = this;
323
324 if(s_macDeactivateWindow==this)
325 {
326 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"),this);
327 s_macDeactivateWindow=NULL;
328 }
329 else
330 wxFrame::MacActivate(timestamp, activating);
331 }
332 else
333 {
334 // We were scheduled for deactivation, and now we do it.
335 if(s_macDeactivateWindow==this)
336 {
337 s_macDeactivateWindow = NULL;
338 wxFrame::MacActivate(timestamp,activating);
339 if(mdiparent->m_currentChild==this)
340 mdiparent->wxFrame::MacActivate(timestamp,activating);
341 }
342 else // schedule ourselves for deactivation
343 {
344 if(s_macDeactivateWindow)
345 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
346 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed deactivation"));
347 s_macDeactivateWindow = this;
348 }
349 }
350 }
351
352 // MDI operations
353 void wxMDIChildFrame::Maximize()
354 {
355 wxFrame::Maximize() ;
356 }
357
358 void wxMDIChildFrame::Restore()
359 {
360 wxFrame::Restore() ;
361 }
362
363 void wxMDIChildFrame::Activate()
364 {
365 }
366
367 //-----------------------------------------------------------------------------
368 // wxMDIClientWindow
369 //-----------------------------------------------------------------------------
370
371 wxMDIClientWindow::wxMDIClientWindow()
372 {
373 }
374
375 wxMDIClientWindow::~wxMDIClientWindow()
376 {
377 DestroyChildren();
378 }
379
380 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
381 {
382 if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style))
383 return FALSE;
384
385 wxModelessWindows.Append(this);
386 return TRUE;
387 }
388
389 // Get size *available for subwindows* i.e. excluding menu bar.
390 void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
391 {
392 wxDisplaySize( x , y ) ;
393 }
394
395 // Explicitly call default scroll behaviour
396 void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
397 {
398 }
399
400 #endif
401