]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/mdi.cpp
adding alpha to wxColour
[wxWidgets.git] / src / mac / carbon / mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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/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 // ----------------------------------------------------------------------------
61 // Parent frame
62 // ----------------------------------------------------------------------------
63
64 void wxMDIParentFrame::Init()
65 {
66 m_clientWindow = NULL;
67 m_currentChild = NULL;
68 m_windowMenu = (wxMenu*) NULL;
69 m_parentFrameActive = true;
70 m_shouldBeShown = false;
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 // 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
112 // already deleted by DestroyChildren()
113 m_clientWindow = NULL ;
114
115 delete m_windowMenu;
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
130 wxDisplaySize(w, h);
131 }
132
133 void wxMDIParentFrame::AddChild(wxWindowBase *child)
134 {
135 if ( !m_currentChild )
136 {
137 m_currentChild = wxDynamicCast(child, wxMDIChildFrame);
138
139 if ( m_currentChild && IsShown() && !ShouldBeVisible() )
140 {
141 // we shouldn't remain visible any more
142 wxFrame::Show(false);
143 m_shouldBeShown = true;
144 }
145 }
146
147 wxFrame::AddChild(child);
148 }
149
150 void wxMDIParentFrame::RemoveChild(wxWindowBase *child)
151 {
152 if ( child == m_currentChild )
153 {
154 // the current child isn't active any more, try to find another one
155 m_currentChild = NULL;
156
157 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
158 node;
159 node = node->GetNext() )
160 {
161 wxMDIChildFrame *
162 childCur = wxDynamicCast(node->GetData(), wxMDIChildFrame);
163 if ( childCur != child )
164 {
165 m_currentChild = childCur;
166 break;
167 }
168 }
169 }
170
171 wxFrame::RemoveChild(child);
172
173 // if there are no more children left we need to show the frame if we
174 // hadn't shown it before because there were active children and it was
175 // useless (note that we have to do it after fully removing the child, i.e.
176 // after calling the base class RemoveChild() as otherwise we risk to touch
177 // pointer to the child being deleted)
178 if ( !m_currentChild && m_shouldBeShown && !IsShown() )
179 {
180 // we have to show it, but at least move it out of sight and make it of
181 // smallest possible size (unfortunately (0, 0) doesn't work so that it
182 // doesn't appear in expose
183 SetSize(-10000, -10000, 1, 1);
184 Show();
185 }
186 }
187
188 void wxMDIParentFrame::MacActivate(long timestamp, bool activating)
189 {
190 wxLogTrace(TRACE_MDI, wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"), this, timestamp, activating ? wxT("ACTIV") : wxT("deact"));
191
192 if (activating)
193 {
194 if (s_macDeactivateWindow && s_macDeactivateWindow->GetParent() == this)
195 {
196 wxLogTrace(TRACE_MDI, wxT("child had been scheduled for deactivation, rehighlighting"));
197
198 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
199
200 wxLogTrace(TRACE_MDI, wxT("finished highliting child"));
201
202 s_macDeactivateWindow = NULL;
203 }
204 else if (s_macDeactivateWindow == this)
205 {
206 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this);
207
208 s_macDeactivateWindow = NULL;
209 }
210 else // window to deactivate is NULL or is not us or one of our kids
211 {
212 // activate kid instead
213 if (m_currentChild)
214 m_currentChild->MacActivate(timestamp, activating);
215 else
216 wxFrame::MacActivate(timestamp, activating);
217 }
218 }
219 else
220 {
221 // We were scheduled for deactivation, and now we do it.
222 if (s_macDeactivateWindow == this)
223 {
224 s_macDeactivateWindow = NULL;
225 if (m_currentChild)
226 m_currentChild->MacActivate(timestamp, activating);
227 wxFrame::MacActivate(timestamp, activating);
228 }
229 else // schedule ourselves for deactivation
230 {
231 if (s_macDeactivateWindow)
232 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"), s_macDeactivateWindow);
233 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed MDI Parent deactivation"));
234
235 s_macDeactivateWindow = this;
236 }
237 }
238 }
239
240 void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
241 {
242 event.Skip();
243 }
244
245 // Returns the active MDI child window
246 wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
247 {
248 return m_currentChild ;
249 }
250
251 // Create the client window class (don't Create the window,
252 // just return a new class)
253 wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
254 {
255 m_clientWindow = new wxMDIClientWindow( this );
256
257 return m_clientWindow;
258 }
259
260 // Responds to colour changes, and passes event on to children.
261 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
262 {
263 // TODO
264
265 // Propagate the event to the non-top-level children
266 wxFrame::OnSysColourChanged(event);
267 }
268
269 // MDI operations
270 void wxMDIParentFrame::Cascade()
271 {
272 // TODO
273 }
274
275 void wxMDIParentFrame::Tile(wxOrientation WXUNUSED(orient))
276 {
277 // TODO
278 }
279
280 void wxMDIParentFrame::ArrangeIcons()
281 {
282 // TODO
283 }
284
285 void wxMDIParentFrame::ActivateNext()
286 {
287 // TODO
288 }
289
290 void wxMDIParentFrame::ActivatePrevious()
291 {
292 // TODO
293 }
294
295 bool wxMDIParentFrame::ShouldBeVisible() const
296 {
297 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
298 node;
299 node = node->GetNext() )
300 {
301 wxWindow *win = node->GetData();
302
303 if ( win->IsShown()
304 && !wxDynamicCast(win, wxMDIChildFrame)
305 #if wxUSE_STATUSBAR
306 && win != (wxWindow*) GetStatusBar()
307 #endif
308 && win != GetClientWindow() )
309 {
310 // if we have a non-MDI child, do remain visible so that it could
311 // be used
312 return true;
313 }
314 }
315
316 return false;
317 }
318
319 bool wxMDIParentFrame::Show( bool show )
320 {
321 m_shouldBeShown = false;
322
323 // don't really show the MDI frame unless it has any children other than
324 // MDI children as it is pretty useless in this case
325
326 if ( show )
327 {
328 if ( !ShouldBeVisible() && m_currentChild )
329 {
330 // don't make the window visible now but remember that we should
331 // have had done it
332 m_shouldBeShown = true;
333
334 return false;
335 }
336 }
337
338 return wxFrame::Show(show);
339 }
340
341 // ----------------------------------------------------------------------------
342 // Child frame
343 // ----------------------------------------------------------------------------
344
345 wxMDIChildFrame::wxMDIChildFrame()
346 {
347 Init() ;
348 }
349 void wxMDIChildFrame::Init()
350 {
351 }
352
353 bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
354 wxWindowID id,
355 const wxString& title,
356 const wxPoint& pos,
357 const wxSize& size,
358 long style,
359 const wxString& name)
360 {
361 SetName(name);
362
363 if ( id == wxID_ANY )
364 m_windowId = (int)NewControlId();
365 else
366 m_windowId = id;
367
368 if (parent)
369 parent->AddChild(this);
370
371 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
372
373 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
374
375 wxModelessWindows.Append(this);
376
377 return false;
378 }
379
380 wxMDIChildFrame::~wxMDIChildFrame()
381 {
382 DestroyChildren();
383 }
384
385 void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
386 {
387 return wxFrame::SetMenuBar( menu_bar ) ;
388 }
389
390 void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
391 {
392 wxLogTrace(TRACE_MDI, wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this, timestamp, activating ? wxT("ACTIV") : wxT("deact"));
393
394 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
395 wxASSERT(mdiparent);
396
397 if (activating)
398 {
399 if (s_macDeactivateWindow == m_parent)
400 {
401 wxLogTrace(TRACE_MDI, wxT("parent had been scheduled for deactivation, rehighlighting"));
402
403 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
404
405 wxLogTrace(TRACE_MDI, wxT("finished highliting parent"));
406
407 s_macDeactivateWindow = NULL;
408 }
409 else if ((mdiparent->m_currentChild == this) || !s_macDeactivateWindow)
410 mdiparent->wxFrame::MacActivate(timestamp, activating);
411
412 if (mdiparent->m_currentChild && mdiparent->m_currentChild != this)
413 mdiparent->m_currentChild->wxFrame::MacActivate(timestamp, false);
414 mdiparent->m_currentChild = this;
415
416 if (s_macDeactivateWindow == this)
417 {
418 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this);
419
420 s_macDeactivateWindow = NULL;
421 }
422 else
423 wxFrame::MacActivate(timestamp, activating);
424 }
425 else
426 {
427 // We were scheduled for deactivation, and now we do it.
428 if (s_macDeactivateWindow == this)
429 {
430 s_macDeactivateWindow = NULL;
431 wxFrame::MacActivate(timestamp, activating);
432 if (mdiparent->m_currentChild == this)
433 mdiparent->wxFrame::MacActivate(timestamp, activating);
434 }
435 else // schedule ourselves for deactivation
436 {
437 if (s_macDeactivateWindow)
438 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"), s_macDeactivateWindow);
439 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed deactivation"));
440
441 s_macDeactivateWindow = this;
442 }
443 }
444 }
445
446 // MDI operations
447 void wxMDIChildFrame::Maximize()
448 {
449 wxFrame::Maximize() ;
450 }
451
452 void wxMDIChildFrame::Restore()
453 {
454 wxFrame::Restore() ;
455 }
456
457 void wxMDIChildFrame::Activate()
458 {
459 }
460
461 //-----------------------------------------------------------------------------
462 // wxMDIClientWindow
463 //-----------------------------------------------------------------------------
464
465 wxMDIClientWindow::wxMDIClientWindow()
466 {
467 }
468
469 wxMDIClientWindow::~wxMDIClientWindow()
470 {
471 DestroyChildren();
472 }
473
474 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
475 {
476 if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style) )
477 return false;
478
479 wxModelessWindows.Append(this);
480
481 return true;
482 }
483
484 // Get size *available for subwindows* i.e. excluding menu bar.
485 void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
486 {
487 wxDisplaySize( x , y ) ;
488 }
489
490 // Explicitly call default scroll behaviour
491 void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
492 {
493 }
494
495 #endif // wxUSE_MDI