]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mdi.cpp | |
3 | // Purpose: MDI classes | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "mdi.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/mdi.h" | |
17 | #include "wx/menu.h" | |
18 | #include "wx/settings.h" | |
70024cfb | 19 | #include "wx/log.h" |
e9576ca5 | 20 | |
76a5e5d2 | 21 | #include "wx/mac/private.h" |
70024cfb | 22 | #include "wx/mac/uma.h" |
76a5e5d2 | 23 | |
fe08e597 | 24 | extern wxWindowList wxModelessWindows; |
e9576ca5 | 25 | |
2f1ae414 | 26 | #if !USE_SHARED_LIBRARY |
e9576ca5 SC |
27 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) |
28 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) | |
29 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) | |
30 | ||
31 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) | |
e9576ca5 SC |
32 | EVT_ACTIVATE(wxMDIParentFrame::OnActivate) |
33 | EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) | |
34 | END_EVENT_TABLE() | |
35 | ||
36 | BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) | |
37 | EVT_SCROLL(wxMDIClientWindow::OnScroll) | |
38 | END_EVENT_TABLE() | |
39 | ||
2f1ae414 | 40 | #endif |
e9576ca5 | 41 | |
0a67a93b SC |
42 | static const int IDM_WINDOWTILE = 4001; |
43 | static const int IDM_WINDOWTILEHOR = 4001; | |
44 | static const int IDM_WINDOWCASCADE = 4002; | |
45 | static const int IDM_WINDOWICONS = 4003; | |
46 | static const int IDM_WINDOWNEXT = 4004; | |
47 | static const int IDM_WINDOWTILEVERT = 4005; | |
4f3b37fd | 48 | static const int IDM_WINDOWPREV = 4006; |
0a67a93b SC |
49 | |
50 | // This range gives a maximum of 500 MDI children. Should be enough :-) | |
51 | static const int wxFIRST_MDI_CHILD = 4100; | |
52 | static const int wxLAST_MDI_CHILD = 4600; | |
53 | ||
54 | // Status border dimensions | |
55 | static const int wxTHICK_LINE_BORDER = 3; | |
56 | ||
e9576ca5 SC |
57 | // Parent frame |
58 | ||
59 | wxMDIParentFrame::wxMDIParentFrame() | |
60 | { | |
0a67a93b SC |
61 | m_clientWindow = NULL; |
62 | m_currentChild = NULL; | |
63 | m_windowMenu = (wxMenu*) NULL; | |
64 | m_parentFrameActive = TRUE; | |
e9576ca5 SC |
65 | } |
66 | ||
67 | bool wxMDIParentFrame::Create(wxWindow *parent, | |
68 | wxWindowID id, | |
69 | const wxString& title, | |
70 | const wxPoint& pos, | |
71 | const wxSize& size, | |
72 | long style, | |
73 | const wxString& name) | |
74 | { | |
e40298d5 JS |
75 | m_clientWindow = NULL; |
76 | m_currentChild = NULL; | |
77 | ||
78 | // this style can be used to prevent a window from having the standard MDI | |
79 | // "Window" menu | |
80 | if ( style & wxFRAME_NO_WINDOW_MENU ) | |
81 | { | |
82 | m_windowMenu = (wxMenu *)NULL; | |
83 | style -= wxFRAME_NO_WINDOW_MENU ; | |
84 | } | |
85 | else // normal case: we have the window menu, so construct it | |
86 | { | |
87 | m_windowMenu = new wxMenu; | |
0a67a93b | 88 | |
e40298d5 JS |
89 | m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade")); |
90 | m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally")); | |
91 | m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically")); | |
92 | m_windowMenu->AppendSeparator(); | |
93 | m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons")); | |
94 | m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next")); | |
95 | } | |
96 | ||
70024cfb | 97 | wxFrame::Create( parent , id , title , pos , size , style , name ) ; |
e40298d5 JS |
98 | m_parentFrameActive = TRUE; |
99 | ||
100 | OnCreateClient(); | |
101 | ||
e9576ca5 SC |
102 | return TRUE; |
103 | } | |
104 | ||
105 | wxMDIParentFrame::~wxMDIParentFrame() | |
106 | { | |
0a67a93b SC |
107 | DestroyChildren(); |
108 | // already delete by DestroyChildren() | |
35eace3a | 109 | #if wxUSE_TOOLBAR |
0a67a93b | 110 | m_frameToolBar = NULL; |
35eace3a JS |
111 | #endif |
112 | #if wxUSE_STATUSBAR | |
0a67a93b | 113 | m_frameStatusBar = NULL; |
35eace3a | 114 | #endif |
0a67a93b | 115 | m_clientWindow = NULL ; |
e40298d5 | 116 | |
0a67a93b SC |
117 | if (m_windowMenu) |
118 | { | |
119 | delete m_windowMenu; | |
120 | m_windowMenu = (wxMenu*) NULL; | |
121 | } | |
e40298d5 | 122 | |
0a67a93b SC |
123 | if ( m_clientWindow ) |
124 | { | |
125 | delete m_clientWindow; | |
126 | m_clientWindow = NULL ; | |
127 | } | |
e9576ca5 SC |
128 | } |
129 | ||
0a67a93b | 130 | |
e9576ca5 SC |
131 | void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) |
132 | { | |
e40298d5 | 133 | wxFrame::SetMenuBar( menu_bar ) ; |
e9576ca5 SC |
134 | } |
135 | ||
70024cfb | 136 | void wxMDIParentFrame::MacActivate(long timestamp, bool activating) |
e9576ca5 | 137 | { |
7d671c08 | 138 | wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact")); |
70024cfb | 139 | if(activating) |
e40298d5 | 140 | { |
70024cfb DE |
141 | if(s_macDeactivateWindow && s_macDeactivateWindow->GetParent()==this) |
142 | { | |
7d671c08 | 143 | wxLogDebug(wxT("child had been scheduled for deactivation, rehighlighting")); |
70024cfb | 144 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true); |
7d671c08 | 145 | wxLogDebug(wxT("done highliting child")); |
70024cfb DE |
146 | s_macDeactivateWindow = NULL; |
147 | } | |
148 | else if(s_macDeactivateWindow == this) | |
149 | { | |
7d671c08 | 150 | wxLogDebug(wxT("Avoided deactivation/activation of this=%p"), this); |
70024cfb DE |
151 | s_macDeactivateWindow = NULL; |
152 | } | |
153 | else // window to deactivate is NULL or is not us or one of our kids | |
154 | { | |
155 | // activate kid instead | |
156 | if(m_currentChild) | |
157 | m_currentChild->MacActivate(timestamp,activating); | |
158 | else | |
159 | wxFrame::MacActivate(timestamp,activating); | |
160 | } | |
e40298d5 | 161 | } |
70024cfb | 162 | else |
e40298d5 | 163 | { |
70024cfb DE |
164 | // We were scheduled for deactivation, and now we do it. |
165 | if(s_macDeactivateWindow==this) | |
e40298d5 | 166 | { |
70024cfb DE |
167 | s_macDeactivateWindow = NULL; |
168 | if(m_currentChild) | |
169 | m_currentChild->MacActivate(timestamp,activating); | |
170 | wxFrame::MacActivate(timestamp,activating); | |
171 | } | |
172 | else // schedule ourselves for deactivation | |
173 | { | |
174 | if(s_macDeactivateWindow) | |
7d671c08 SC |
175 | wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow); |
176 | wxLogDebug(wxT("Scheduling delayed MDI Parent deactivation")); | |
70024cfb | 177 | s_macDeactivateWindow = this; |
e40298d5 | 178 | } |
e40298d5 | 179 | } |
e9576ca5 SC |
180 | } |
181 | ||
70024cfb DE |
182 | void wxMDIParentFrame::OnActivate(wxActivateEvent& event) |
183 | { | |
184 | event.Skip(); | |
185 | } | |
186 | ||
e9576ca5 SC |
187 | // Returns the active MDI child window |
188 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const | |
189 | { | |
e40298d5 | 190 | return m_currentChild ; |
e9576ca5 SC |
191 | } |
192 | ||
193 | // Create the client window class (don't Create the window, | |
194 | // just return a new class) | |
195 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient() | |
196 | { | |
0a67a93b SC |
197 | m_clientWindow = new wxMDIClientWindow( this ); |
198 | return m_clientWindow; | |
e9576ca5 SC |
199 | } |
200 | ||
201 | // Responds to colour changes, and passes event on to children. | |
202 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
203 | { | |
204 | // TODO | |
e40298d5 | 205 | |
e9576ca5 SC |
206 | // Propagate the event to the non-top-level children |
207 | wxFrame::OnSysColourChanged(event); | |
208 | } | |
209 | ||
210 | // MDI operations | |
211 | void wxMDIParentFrame::Cascade() | |
212 | { | |
213 | // TODO | |
214 | } | |
215 | ||
216 | void wxMDIParentFrame::Tile() | |
217 | { | |
218 | // TODO | |
219 | } | |
220 | ||
221 | void wxMDIParentFrame::ArrangeIcons() | |
222 | { | |
223 | // TODO | |
224 | } | |
225 | ||
226 | void wxMDIParentFrame::ActivateNext() | |
227 | { | |
228 | // TODO | |
229 | } | |
230 | ||
231 | void wxMDIParentFrame::ActivatePrevious() | |
232 | { | |
233 | // TODO | |
234 | } | |
235 | ||
29e92efb VZ |
236 | bool wxMDIParentFrame::Show( bool show ) |
237 | { | |
238 | if ( !wxFrame::Show(show) ) | |
239 | return false; | |
240 | ||
241 | // don't really show the MDI frame unless it has any children other than | |
242 | // MDI children as it is pretty useless in this case | |
243 | if ( show ) | |
244 | { | |
245 | // TODO: check for other children | |
246 | Move(-10000, -10000); | |
247 | } | |
248 | ||
249 | return true; | |
250 | } | |
251 | ||
e9576ca5 SC |
252 | // Child frame |
253 | ||
254 | wxMDIChildFrame::wxMDIChildFrame() | |
0a67a93b SC |
255 | { |
256 | Init() ; | |
257 | } | |
258 | void wxMDIChildFrame::Init() | |
e9576ca5 SC |
259 | { |
260 | } | |
261 | ||
262 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
e40298d5 JS |
263 | wxWindowID id, |
264 | const wxString& title, | |
265 | const wxPoint& pos, | |
266 | const wxSize& size, | |
267 | long style, | |
268 | const wxString& name) | |
e9576ca5 SC |
269 | { |
270 | SetName(name); | |
e40298d5 | 271 | |
e9576ca5 SC |
272 | if ( id > -1 ) |
273 | m_windowId = id; | |
274 | else | |
275 | m_windowId = (int)NewControlId(); | |
e40298d5 | 276 | |
e9576ca5 | 277 | if (parent) parent->AddChild(this); |
e40298d5 JS |
278 | |
279 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; | |
280 | ||
facd6764 SC |
281 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
282 | ||
e9576ca5 SC |
283 | wxModelessWindows.Append(this); |
284 | return FALSE; | |
285 | } | |
286 | ||
287 | wxMDIChildFrame::~wxMDIChildFrame() | |
288 | { | |
70024cfb DE |
289 | wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame); |
290 | wxASSERT(mdiparent); | |
291 | if(mdiparent->m_currentChild == this) | |
292 | mdiparent->m_currentChild = NULL; | |
0a67a93b SC |
293 | DestroyChildren(); |
294 | // already delete by DestroyChildren() | |
35eace3a | 295 | #if wxUSE_TOOLBAR |
0a67a93b | 296 | m_frameToolBar = NULL; |
35eace3a JS |
297 | #endif |
298 | #if wxUSE_STATUSBAR | |
0a67a93b | 299 | m_frameStatusBar = NULL; |
35eace3a | 300 | #endif |
e9576ca5 SC |
301 | } |
302 | ||
303 | void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar) | |
304 | { | |
e40298d5 | 305 | return wxFrame::SetMenuBar( menu_bar ) ; |
e9576ca5 SC |
306 | } |
307 | ||
70024cfb DE |
308 | void wxMDIChildFrame::MacActivate(long timestamp, bool activating) |
309 | { | |
7d671c08 | 310 | wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact")); |
70024cfb DE |
311 | wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame); |
312 | wxASSERT(mdiparent); | |
313 | if(activating) | |
314 | { | |
315 | if(s_macDeactivateWindow == m_parent) | |
316 | { | |
7d671c08 | 317 | wxLogDebug(wxT("parent had been scheduled for deactivation, rehighlighting")); |
70024cfb | 318 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true); |
7d671c08 | 319 | wxLogDebug(wxT("done highliting parent")); |
70024cfb DE |
320 | s_macDeactivateWindow = NULL; |
321 | } | |
322 | else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow) | |
323 | mdiparent->wxFrame::MacActivate(timestamp,activating); | |
324 | ||
325 | if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this) | |
326 | mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false); | |
327 | mdiparent->m_currentChild = this; | |
328 | ||
329 | if(s_macDeactivateWindow==this) | |
330 | { | |
7d671c08 | 331 | wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this); |
70024cfb DE |
332 | s_macDeactivateWindow=NULL; |
333 | } | |
334 | else | |
335 | wxFrame::MacActivate(timestamp, activating); | |
336 | } | |
337 | else | |
338 | { | |
339 | // We were scheduled for deactivation, and now we do it. | |
340 | if(s_macDeactivateWindow==this) | |
341 | { | |
342 | s_macDeactivateWindow = NULL; | |
343 | wxFrame::MacActivate(timestamp,activating); | |
344 | if(mdiparent->m_currentChild==this) | |
345 | mdiparent->wxFrame::MacActivate(timestamp,activating); | |
346 | } | |
347 | else // schedule ourselves for deactivation | |
348 | { | |
349 | if(s_macDeactivateWindow) | |
7d671c08 SC |
350 | wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow); |
351 | wxLogDebug(wxT("Scheduling delayed deactivation")); | |
70024cfb DE |
352 | s_macDeactivateWindow = this; |
353 | } | |
354 | } | |
355 | } | |
356 | ||
e9576ca5 SC |
357 | // MDI operations |
358 | void wxMDIChildFrame::Maximize() | |
359 | { | |
0a67a93b | 360 | wxFrame::Maximize() ; |
e9576ca5 SC |
361 | } |
362 | ||
363 | void wxMDIChildFrame::Restore() | |
364 | { | |
0a67a93b | 365 | wxFrame::Restore() ; |
e9576ca5 SC |
366 | } |
367 | ||
368 | void wxMDIChildFrame::Activate() | |
369 | { | |
e9576ca5 SC |
370 | } |
371 | ||
0a67a93b SC |
372 | //----------------------------------------------------------------------------- |
373 | // wxMDIClientWindow | |
374 | //----------------------------------------------------------------------------- | |
e9576ca5 SC |
375 | |
376 | wxMDIClientWindow::wxMDIClientWindow() | |
377 | { | |
378 | } | |
379 | ||
380 | wxMDIClientWindow::~wxMDIClientWindow() | |
381 | { | |
0a67a93b | 382 | DestroyChildren(); |
e9576ca5 SC |
383 | } |
384 | ||
385 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) | |
386 | { | |
84be293d KO |
387 | if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style)) |
388 | return FALSE; | |
e40298d5 | 389 | |
0a67a93b SC |
390 | wxModelessWindows.Append(this); |
391 | return TRUE; | |
e9576ca5 SC |
392 | } |
393 | ||
be7a1013 DE |
394 | // Get size *available for subwindows* i.e. excluding menu bar. |
395 | void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const | |
396 | { | |
397 | wxDisplaySize( x , y ) ; | |
398 | } | |
399 | ||
e9576ca5 SC |
400 | // Explicitly call default scroll behaviour |
401 | void wxMDIClientWindow::OnScroll(wxScrollEvent& event) | |
402 | { | |
e9576ca5 SC |
403 | } |
404 |