]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/carbon/mdi.cpp |
489468fe SC |
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 | ||
1f0c8f31 SC |
25 | #include "wx/osx/private.h" |
26 | #include "wx/osx/uma.h" | |
489468fe SC |
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 | ||
489468fe SC |
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 | { | |
cfea8e61 | 49 | #if wxOSX_USE_CARBON // TODO REMOVE |
489468fe SC |
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 | } | |
cfea8e61 KO |
73 | #elif defined(wxOSX_USE_COCOA) |
74 | // TODO: implement me! | |
489468fe SC |
75 | #endif |
76 | } | |
77 | ||
78 | // ---------------------------------------------------------------------------- | |
79 | // Parent frame | |
80 | // ---------------------------------------------------------------------------- | |
81 | ||
82 | void wxMDIParentFrame::Init() | |
83 | { | |
489468fe SC |
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 | { | |
d2824cdb | 100 | m_windowMenu = NULL; |
489468fe SC |
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 | ||
122 | return m_clientWindow != NULL; | |
123 | } | |
124 | ||
125 | wxMDIParentFrame::~wxMDIParentFrame() | |
126 | { | |
127 | DestroyChildren(); | |
128 | ||
129 | // already deleted by DestroyChildren() | |
130 | m_clientWindow = NULL ; | |
489468fe SC |
131 | } |
132 | ||
133 | void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) | |
134 | { | |
135 | wxFrame::SetMenuBar( menu_bar ) ; | |
136 | } | |
137 | ||
138 | void wxMDIParentFrame::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h) | |
139 | { | |
140 | if (x) | |
141 | *x = 0; | |
142 | if (y) | |
143 | *y = 0; | |
144 | ||
145 | wxDisplaySize(w, h); | |
146 | } | |
147 | ||
148 | void wxMDIParentFrame::AddChild(wxWindowBase *child) | |
149 | { | |
150 | // moved this to front, so that we don't run into unset m_parent problems later | |
151 | wxFrame::AddChild(child); | |
152 | ||
153 | if ( !m_currentChild ) | |
154 | { | |
155 | m_currentChild = wxDynamicCast(child, wxMDIChildFrame); | |
156 | ||
157 | if ( m_currentChild && IsShown() && !ShouldBeVisible() ) | |
158 | { | |
159 | // we shouldn't remain visible any more | |
160 | wxFrame::Show(false); | |
161 | m_shouldBeShown = true; | |
162 | } | |
163 | } | |
164 | } | |
165 | ||
166 | void wxMDIParentFrame::RemoveChild(wxWindowBase *child) | |
167 | { | |
168 | if ( child == m_currentChild ) | |
169 | { | |
170 | // the current child isn't active any more, try to find another one | |
171 | m_currentChild = NULL; | |
172 | ||
173 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
174 | node; | |
175 | node = node->GetNext() ) | |
176 | { | |
177 | wxMDIChildFrame * | |
178 | childCur = wxDynamicCast(node->GetData(), wxMDIChildFrame); | |
179 | if ( childCur != child ) | |
180 | { | |
181 | m_currentChild = childCur; | |
182 | break; | |
183 | } | |
184 | } | |
185 | } | |
186 | ||
187 | wxFrame::RemoveChild(child); | |
188 | ||
189 | // if there are no more children left we need to show the frame if we | |
190 | // hadn't shown it before because there were active children and it was | |
191 | // useless (note that we have to do it after fully removing the child, i.e. | |
192 | // after calling the base class RemoveChild() as otherwise we risk to touch | |
193 | // pointer to the child being deleted) | |
194 | if ( !m_currentChild && m_shouldBeShown && !IsShown() ) | |
195 | { | |
196 | // we have to show it, but at least move it out of sight and make it of | |
197 | // smallest possible size (unfortunately (0, 0) doesn't work so that it | |
198 | // doesn't appear in expose | |
199 | SetSize(-10000, -10000, 1, 1); | |
200 | Show(); | |
201 | } | |
202 | } | |
203 | ||
204 | void wxMDIParentFrame::MacActivate(long timestamp, bool activating) | |
205 | { | |
206 | wxLogTrace(TRACE_MDI, wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"), this, timestamp, activating ? wxT("ACTIV") : wxT("deact")); | |
207 | ||
208 | if (activating) | |
209 | { | |
210 | if (s_macDeactivateWindow && s_macDeactivateWindow->GetParent() == this) | |
211 | { | |
212 | wxLogTrace(TRACE_MDI, wxT("child had been scheduled for deactivation, rehighlighting")); | |
213 | ||
b2680ced | 214 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->GetWXWindow(), true); |
489468fe SC |
215 | |
216 | wxLogTrace(TRACE_MDI, wxT("finished highliting child")); | |
217 | ||
218 | s_macDeactivateWindow = NULL; | |
219 | } | |
220 | else if (s_macDeactivateWindow == this) | |
221 | { | |
222 | wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this); | |
223 | ||
224 | s_macDeactivateWindow = NULL; | |
225 | } | |
226 | else // window to deactivate is NULL or is not us or one of our kids | |
227 | { | |
228 | // activate kid instead | |
229 | if (m_currentChild) | |
230 | m_currentChild->MacActivate(timestamp, activating); | |
231 | else | |
232 | wxFrame::MacActivate(timestamp, activating); | |
233 | } | |
234 | } | |
235 | else | |
236 | { | |
237 | // We were scheduled for deactivation, and now we do it. | |
238 | if (s_macDeactivateWindow == this) | |
239 | { | |
240 | s_macDeactivateWindow = NULL; | |
241 | if (m_currentChild) | |
242 | m_currentChild->MacActivate(timestamp, activating); | |
243 | wxFrame::MacActivate(timestamp, activating); | |
244 | } | |
245 | else // schedule ourselves for deactivation | |
246 | { | |
247 | if (s_macDeactivateWindow) | |
248 | wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"), s_macDeactivateWindow); | |
249 | wxLogTrace(TRACE_MDI, wxT("Scheduling delayed MDI Parent deactivation")); | |
250 | ||
251 | s_macDeactivateWindow = this; | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | void wxMDIParentFrame::OnActivate(wxActivateEvent& event) | |
257 | { | |
258 | event.Skip(); | |
259 | } | |
260 | ||
489468fe SC |
261 | // Responds to colour changes, and passes event on to children. |
262 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
263 | { | |
264 | // TODO | |
265 | ||
266 | // Propagate the event to the non-top-level children | |
267 | wxFrame::OnSysColourChanged(event); | |
268 | } | |
269 | ||
489468fe SC |
270 | bool wxMDIParentFrame::ShouldBeVisible() const |
271 | { | |
272 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
273 | node; | |
274 | node = node->GetNext() ) | |
275 | { | |
276 | wxWindow *win = node->GetData(); | |
277 | ||
278 | if ( win->IsShown() | |
279 | && !wxDynamicCast(win, wxMDIChildFrame) | |
280 | #if wxUSE_STATUSBAR | |
281 | && win != (wxWindow*) GetStatusBar() | |
282 | #endif | |
283 | && win != GetClientWindow() ) | |
284 | { | |
285 | // if we have a non-MDI child, do remain visible so that it could | |
286 | // be used | |
287 | return true; | |
288 | } | |
289 | } | |
290 | ||
291 | return false; | |
292 | } | |
293 | ||
294 | bool wxMDIParentFrame::Show( bool show ) | |
295 | { | |
296 | m_shouldBeShown = false; | |
297 | ||
298 | // don't really show the MDI frame unless it has any children other than | |
299 | // MDI children as it is pretty useless in this case | |
300 | ||
301 | if ( show ) | |
302 | { | |
303 | if ( !ShouldBeVisible() && m_currentChild ) | |
304 | { | |
305 | // don't make the window visible now but remember that we should | |
306 | // have had done it | |
307 | m_shouldBeShown = true; | |
308 | ||
309 | return false; | |
310 | } | |
311 | } | |
312 | ||
313 | return wxFrame::Show(show); | |
314 | } | |
315 | ||
316 | // ---------------------------------------------------------------------------- | |
317 | // Child frame | |
318 | // ---------------------------------------------------------------------------- | |
319 | ||
489468fe SC |
320 | void wxMDIChildFrame::Init() |
321 | { | |
322 | } | |
323 | ||
324 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
325 | wxWindowID id, | |
326 | const wxString& title, | |
327 | const wxPoint& pos, | |
328 | const wxSize& size, | |
329 | long style, | |
330 | const wxString& name) | |
331 | { | |
d2824cdb VZ |
332 | m_mdiParent = parent; |
333 | ||
489468fe SC |
334 | SetName(name); |
335 | ||
336 | if ( id == wxID_ANY ) | |
b2680ced | 337 | id = (int)NewControlId(); |
489468fe | 338 | |
b2680ced | 339 | wxNonOwnedWindow::Create( parent, id, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
d2824cdb | 340 | |
489468fe SC |
341 | SetTitle( title ); |
342 | ||
343 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
344 | ||
345 | return true; | |
346 | } | |
347 | ||
348 | wxMDIChildFrame::~wxMDIChildFrame() | |
349 | { | |
350 | DestroyChildren(); | |
351 | } | |
352 | ||
489468fe SC |
353 | void wxMDIChildFrame::MacActivate(long timestamp, bool activating) |
354 | { | |
355 | wxLogTrace(TRACE_MDI, wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this, timestamp, activating ? wxT("ACTIV") : wxT("deact")); | |
356 | ||
357 | wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame); | |
358 | wxASSERT(mdiparent); | |
359 | ||
360 | if (activating) | |
361 | { | |
362 | if (s_macDeactivateWindow == m_parent) | |
363 | { | |
364 | wxLogTrace(TRACE_MDI, wxT("parent had been scheduled for deactivation, rehighlighting")); | |
365 | ||
b2680ced | 366 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->GetWXWindow(), true); |
489468fe SC |
367 | |
368 | wxLogTrace(TRACE_MDI, wxT("finished highliting parent")); | |
369 | ||
370 | s_macDeactivateWindow = NULL; | |
371 | } | |
372 | else if ((mdiparent->m_currentChild == this) || !s_macDeactivateWindow) | |
373 | mdiparent->wxFrame::MacActivate(timestamp, activating); | |
374 | ||
375 | if (mdiparent->m_currentChild && mdiparent->m_currentChild != this) | |
376 | mdiparent->m_currentChild->wxFrame::MacActivate(timestamp, false); | |
377 | mdiparent->m_currentChild = this; | |
378 | ||
379 | if (s_macDeactivateWindow == this) | |
380 | { | |
381 | wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this); | |
382 | ||
383 | s_macDeactivateWindow = NULL; | |
384 | } | |
385 | else | |
386 | wxFrame::MacActivate(timestamp, activating); | |
387 | } | |
388 | else | |
389 | { | |
390 | // We were scheduled for deactivation, and now we do it. | |
391 | if (s_macDeactivateWindow == this) | |
392 | { | |
393 | s_macDeactivateWindow = NULL; | |
394 | wxFrame::MacActivate(timestamp, activating); | |
395 | if (mdiparent->m_currentChild == this) | |
396 | mdiparent->wxFrame::MacActivate(timestamp, activating); | |
397 | } | |
398 | else // schedule ourselves for deactivation | |
399 | { | |
400 | if (s_macDeactivateWindow) | |
401 | wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"), s_macDeactivateWindow); | |
402 | wxLogTrace(TRACE_MDI, wxT("Scheduling delayed deactivation")); | |
403 | ||
404 | s_macDeactivateWindow = this; | |
405 | } | |
406 | } | |
407 | } | |
408 | ||
409 | // MDI operations | |
489468fe SC |
410 | void wxMDIChildFrame::Activate() |
411 | { | |
412 | Raise (); | |
413 | } | |
414 | ||
415 | //----------------------------------------------------------------------------- | |
416 | // wxMDIClientWindow | |
417 | //----------------------------------------------------------------------------- | |
418 | ||
489468fe SC |
419 | wxMDIClientWindow::~wxMDIClientWindow() |
420 | { | |
421 | DestroyChildren(); | |
422 | } | |
423 | ||
424 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) | |
425 | { | |
426 | if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style) ) | |
427 | return false; | |
428 | ||
429 | return true; | |
430 | } | |
431 | ||
489468fe SC |
432 | void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const |
433 | { | |
434 | wxDisplaySize( x , y ) ; | |
435 | } | |
436 | ||
489468fe | 437 | #endif // wxUSE_MDI |