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