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