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