]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/mdi.cpp
move wxGridCellRenderer::Draw before other derived classes implementations (no real...
[wxWidgets.git] / src / osx / carbon / mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/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 #include "wx/wxprec.h"
13
14 #if wxUSE_MDI
15
16 #include "wx/mdi.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/log.h"
20 #include "wx/menu.h"
21 #include "wx/settings.h"
22 #include "wx/statusbr.h"
23 #endif
24
25 #include "wx/osx/private.h"
26 #include "wx/osx/uma.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
29 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
30 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
31
32 BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
33 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
34 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
35 END_EVENT_TABLE()
36
37 #define TRACE_MDI "mdi"
38
39 static const int IDM_WINDOWTILEHOR = 4001;
40 static const int IDM_WINDOWCASCADE = 4002;
41 static const int IDM_WINDOWICONS = 4003;
42 static const int IDM_WINDOWNEXT = 4004;
43 static const int IDM_WINDOWTILEVERT = 4005;
44
45 // others
46
47 void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
48 {
49 #if wxOSX_USE_CARBON // TODO REMOVE
50 if ( inWindowRef )
51 {
52 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
53 // if ( inActivate != isHighlighted )
54 #ifndef __LP64__
55 GrafPtr port ;
56 GetPort( &port ) ;
57 SetPortWindowPort( inWindowRef ) ;
58 #endif
59 HiliteWindow( inWindowRef , inActivate ) ;
60 ControlRef control = NULL ;
61 ::GetRootControl( inWindowRef , &control ) ;
62 if ( control )
63 {
64 if ( inActivate )
65 ::ActivateControl( control ) ;
66 else
67 ::DeactivateControl( control ) ;
68 }
69 #ifndef __LP64__
70 SetPort( port ) ;
71 #endif
72 }
73 #elif defined(wxOSX_USE_COCOA)
74 // TODO: implement me!
75 #endif
76 }
77
78 // ----------------------------------------------------------------------------
79 // Parent frame
80 // ----------------------------------------------------------------------------
81
82 void wxMDIParentFrame::Init()
83 {
84 m_parentFrameActive = true;
85 m_shouldBeShown = false;
86 }
87
88 bool wxMDIParentFrame::Create(wxWindow *parent,
89 wxWindowID id,
90 const wxString& title,
91 const wxPoint& pos,
92 const wxSize& size,
93 long style,
94 const wxString& name)
95 {
96 // this style can be used to prevent a window from having the standard MDI
97 // "Window" menu
98 if ( style & wxFRAME_NO_WINDOW_MENU )
99 {
100 m_windowMenu = NULL;
101 style -= wxFRAME_NO_WINDOW_MENU ;
102 }
103 else // normal case: we have the window menu, so construct it
104 {
105 m_windowMenu = new wxMenu;
106
107 m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade"));
108 m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally"));
109 m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically"));
110 m_windowMenu->AppendSeparator();
111 m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons"));
112 m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next"));
113 }
114
115 if ( !wxFrame::Create( parent , id , title , pos , size , style , name ) )
116 return false;
117
118 m_parentFrameActive = true;
119
120 m_clientWindow = OnCreateClient();
121 if ( !m_clientWindow || !m_clientWindow->CreateClient(this, style) )
122 return false;
123
124 return true;
125 }
126
127 wxMDIParentFrame::~wxMDIParentFrame()
128 {
129 DestroyChildren();
130
131 // already deleted by DestroyChildren()
132 m_clientWindow = NULL ;
133 }
134
135 void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
136 {
137 wxFrame::SetMenuBar( menu_bar ) ;
138 }
139
140 void wxMDIParentFrame::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h)
141 {
142 if (x)
143 *x = 0;
144 if (y)
145 *y = 0;
146
147 wxDisplaySize(w, h);
148 }
149
150 void wxMDIParentFrame::AddChild(wxWindowBase *child)
151 {
152 // moved this to front, so that we don't run into unset m_parent problems later
153 wxFrame::AddChild(child);
154
155 if ( !m_currentChild )
156 {
157 m_currentChild = wxDynamicCast(child, wxMDIChildFrame);
158
159 if ( m_currentChild && IsShown() && !ShouldBeVisible() )
160 {
161 // we shouldn't remain visible any more
162 wxFrame::Show(false);
163 m_shouldBeShown = true;
164 }
165 }
166 }
167
168 void wxMDIParentFrame::RemoveChild(wxWindowBase *child)
169 {
170 if ( child == m_currentChild )
171 {
172 // the current child isn't active any more, try to find another one
173 m_currentChild = NULL;
174
175 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
176 node;
177 node = node->GetNext() )
178 {
179 wxMDIChildFrame *
180 childCur = wxDynamicCast(node->GetData(), wxMDIChildFrame);
181 if ( childCur != child )
182 {
183 m_currentChild = childCur;
184 break;
185 }
186 }
187 }
188
189 wxFrame::RemoveChild(child);
190
191 // if there are no more children left we need to show the frame if we
192 // hadn't shown it before because there were active children and it was
193 // useless (note that we have to do it after fully removing the child, i.e.
194 // after calling the base class RemoveChild() as otherwise we risk to touch
195 // pointer to the child being deleted)
196 if ( !m_currentChild && m_shouldBeShown && !IsShown() )
197 {
198 // we have to show it, but at least move it out of sight and make it of
199 // smallest possible size (unfortunately (0, 0) doesn't work so that it
200 // doesn't appear in expose
201 SetSize(-10000, -10000, 1, 1);
202 Show();
203 }
204 }
205
206 void wxMDIParentFrame::MacActivate(long timestamp, bool activating)
207 {
208 wxLogTrace(TRACE_MDI, wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"), this, timestamp, activating ? wxT("ACTIV") : wxT("deact"));
209
210 if (activating)
211 {
212 if (s_macDeactivateWindow && s_macDeactivateWindow->GetParent() == this)
213 {
214 wxLogTrace(TRACE_MDI, wxT("child had been scheduled for deactivation, rehighlighting"));
215
216 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->GetWXWindow(), true);
217
218 wxLogTrace(TRACE_MDI, wxT("finished highliting child"));
219
220 s_macDeactivateWindow = NULL;
221 }
222 else if (s_macDeactivateWindow == this)
223 {
224 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this);
225
226 s_macDeactivateWindow = NULL;
227 }
228 else // window to deactivate is NULL or is not us or one of our kids
229 {
230 // activate kid instead
231 if (m_currentChild)
232 m_currentChild->MacActivate(timestamp, activating);
233 else
234 wxFrame::MacActivate(timestamp, activating);
235 }
236 }
237 else
238 {
239 // We were scheduled for deactivation, and now we do it.
240 if (s_macDeactivateWindow == this)
241 {
242 s_macDeactivateWindow = NULL;
243 if (m_currentChild)
244 m_currentChild->MacActivate(timestamp, activating);
245 wxFrame::MacActivate(timestamp, activating);
246 }
247 else // schedule ourselves for deactivation
248 {
249 if (s_macDeactivateWindow)
250 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"), s_macDeactivateWindow);
251 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed MDI Parent deactivation"));
252
253 s_macDeactivateWindow = this;
254 }
255 }
256 }
257
258 void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
259 {
260 event.Skip();
261 }
262
263 // Responds to colour changes, and passes event on to children.
264 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
265 {
266 // TODO
267
268 // Propagate the event to the non-top-level children
269 wxFrame::OnSysColourChanged(event);
270 }
271
272 bool wxMDIParentFrame::ShouldBeVisible() const
273 {
274 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
275 node;
276 node = node->GetNext() )
277 {
278 wxWindow *win = node->GetData();
279
280 if ( win->IsShown()
281 && !wxDynamicCast(win, wxMDIChildFrame)
282 #if wxUSE_STATUSBAR
283 && win != (wxWindow*) GetStatusBar()
284 #endif
285 && win != GetClientWindow() )
286 {
287 // if we have a non-MDI child, do remain visible so that it could
288 // be used
289 return true;
290 }
291 }
292
293 return false;
294 }
295
296 bool wxMDIParentFrame::Show( bool show )
297 {
298 m_shouldBeShown = false;
299
300 // don't really show the MDI frame unless it has any children other than
301 // MDI children as it is pretty useless in this case
302
303 if ( show )
304 {
305 if ( !ShouldBeVisible() && m_currentChild )
306 {
307 // don't make the window visible now but remember that we should
308 // have had done it
309 m_shouldBeShown = true;
310
311 return false;
312 }
313 }
314
315 return wxFrame::Show(show);
316 }
317
318 // ----------------------------------------------------------------------------
319 // Child frame
320 // ----------------------------------------------------------------------------
321
322 void wxMDIChildFrame::Init()
323 {
324 }
325
326 bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
327 wxWindowID id,
328 const wxString& title,
329 const wxPoint& pos,
330 const wxSize& size,
331 long style,
332 const wxString& name)
333 {
334 m_mdiParent = parent;
335
336 SetName(name);
337
338 if ( id == wxID_ANY )
339 id = (int)NewControlId();
340
341 wxNonOwnedWindow::Create( parent, id, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
342
343 SetTitle( title );
344
345 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
346
347 return true;
348 }
349
350 wxMDIChildFrame::~wxMDIChildFrame()
351 {
352 DestroyChildren();
353 }
354
355 void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
356 {
357 wxLogTrace(TRACE_MDI, wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this, timestamp, activating ? wxT("ACTIV") : wxT("deact"));
358
359 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
360 wxASSERT(mdiparent);
361
362 if (activating)
363 {
364 if (s_macDeactivateWindow == m_parent)
365 {
366 wxLogTrace(TRACE_MDI, wxT("parent had been scheduled for deactivation, rehighlighting"));
367
368 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->GetWXWindow(), true);
369
370 wxLogTrace(TRACE_MDI, wxT("finished highliting parent"));
371
372 s_macDeactivateWindow = NULL;
373 }
374 else if ((mdiparent->m_currentChild == this) || !s_macDeactivateWindow)
375 mdiparent->wxFrame::MacActivate(timestamp, activating);
376
377 if (mdiparent->m_currentChild && mdiparent->m_currentChild != this)
378 mdiparent->m_currentChild->wxFrame::MacActivate(timestamp, false);
379 mdiparent->m_currentChild = this;
380
381 if (s_macDeactivateWindow == this)
382 {
383 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this);
384
385 s_macDeactivateWindow = NULL;
386 }
387 else
388 wxFrame::MacActivate(timestamp, activating);
389 }
390 else
391 {
392 // We were scheduled for deactivation, and now we do it.
393 if (s_macDeactivateWindow == this)
394 {
395 s_macDeactivateWindow = NULL;
396 wxFrame::MacActivate(timestamp, activating);
397 if (mdiparent->m_currentChild == this)
398 mdiparent->wxFrame::MacActivate(timestamp, activating);
399 }
400 else // schedule ourselves for deactivation
401 {
402 if (s_macDeactivateWindow)
403 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"), s_macDeactivateWindow);
404 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed deactivation"));
405
406 s_macDeactivateWindow = this;
407 }
408 }
409 }
410
411 // MDI operations
412 void wxMDIChildFrame::Activate()
413 {
414 Raise ();
415 }
416
417 //-----------------------------------------------------------------------------
418 // wxMDIClientWindow
419 //-----------------------------------------------------------------------------
420
421 wxMDIClientWindow::~wxMDIClientWindow()
422 {
423 DestroyChildren();
424 }
425
426 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
427 {
428 if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style) )
429 return false;
430
431 return true;
432 }
433
434 void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
435 {
436 wxDisplaySize( x , y ) ;
437 }
438
439 #endif // wxUSE_MDI