]>
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 | 107 | DestroyChildren(); |
ea3cdc4f | 108 | // already deleted by DestroyChildren() |
0a67a93b | 109 | m_clientWindow = NULL ; |
e40298d5 | 110 | |
ea3cdc4f | 111 | delete m_windowMenu; |
e9576ca5 SC |
112 | } |
113 | ||
0a67a93b | 114 | |
e9576ca5 SC |
115 | void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) |
116 | { | |
e40298d5 | 117 | wxFrame::SetMenuBar( menu_bar ) ; |
e9576ca5 SC |
118 | } |
119 | ||
0bba37f5 DE |
120 | void wxMDIParentFrame::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h) |
121 | { | |
122 | if(x) | |
123 | *x = 0; | |
124 | if(y) | |
125 | *y = 0; | |
126 | wxDisplaySize(w,h); | |
127 | } | |
128 | ||
70024cfb | 129 | void wxMDIParentFrame::MacActivate(long timestamp, bool activating) |
e9576ca5 | 130 | { |
7d671c08 | 131 | wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact")); |
70024cfb | 132 | if(activating) |
e40298d5 | 133 | { |
70024cfb DE |
134 | if(s_macDeactivateWindow && s_macDeactivateWindow->GetParent()==this) |
135 | { | |
7d671c08 | 136 | wxLogDebug(wxT("child had been scheduled for deactivation, rehighlighting")); |
70024cfb | 137 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true); |
7d671c08 | 138 | wxLogDebug(wxT("done highliting child")); |
70024cfb DE |
139 | s_macDeactivateWindow = NULL; |
140 | } | |
141 | else if(s_macDeactivateWindow == this) | |
142 | { | |
7d671c08 | 143 | wxLogDebug(wxT("Avoided deactivation/activation of this=%p"), this); |
70024cfb DE |
144 | s_macDeactivateWindow = NULL; |
145 | } | |
146 | else // window to deactivate is NULL or is not us or one of our kids | |
147 | { | |
148 | // activate kid instead | |
149 | if(m_currentChild) | |
150 | m_currentChild->MacActivate(timestamp,activating); | |
151 | else | |
152 | wxFrame::MacActivate(timestamp,activating); | |
153 | } | |
e40298d5 | 154 | } |
70024cfb | 155 | else |
e40298d5 | 156 | { |
70024cfb DE |
157 | // We were scheduled for deactivation, and now we do it. |
158 | if(s_macDeactivateWindow==this) | |
e40298d5 | 159 | { |
70024cfb DE |
160 | s_macDeactivateWindow = NULL; |
161 | if(m_currentChild) | |
162 | m_currentChild->MacActivate(timestamp,activating); | |
163 | wxFrame::MacActivate(timestamp,activating); | |
164 | } | |
165 | else // schedule ourselves for deactivation | |
166 | { | |
167 | if(s_macDeactivateWindow) | |
7d671c08 SC |
168 | wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow); |
169 | wxLogDebug(wxT("Scheduling delayed MDI Parent deactivation")); | |
70024cfb | 170 | s_macDeactivateWindow = this; |
e40298d5 | 171 | } |
e40298d5 | 172 | } |
e9576ca5 SC |
173 | } |
174 | ||
70024cfb DE |
175 | void wxMDIParentFrame::OnActivate(wxActivateEvent& event) |
176 | { | |
177 | event.Skip(); | |
178 | } | |
179 | ||
e9576ca5 SC |
180 | // Returns the active MDI child window |
181 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const | |
182 | { | |
e40298d5 | 183 | return m_currentChild ; |
e9576ca5 SC |
184 | } |
185 | ||
186 | // Create the client window class (don't Create the window, | |
187 | // just return a new class) | |
188 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient() | |
189 | { | |
0a67a93b SC |
190 | m_clientWindow = new wxMDIClientWindow( this ); |
191 | return m_clientWindow; | |
e9576ca5 SC |
192 | } |
193 | ||
194 | // Responds to colour changes, and passes event on to children. | |
195 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
196 | { | |
197 | // TODO | |
e40298d5 | 198 | |
e9576ca5 SC |
199 | // Propagate the event to the non-top-level children |
200 | wxFrame::OnSysColourChanged(event); | |
201 | } | |
202 | ||
203 | // MDI operations | |
204 | void wxMDIParentFrame::Cascade() | |
205 | { | |
206 | // TODO | |
207 | } | |
208 | ||
209 | void wxMDIParentFrame::Tile() | |
210 | { | |
211 | // TODO | |
212 | } | |
213 | ||
214 | void wxMDIParentFrame::ArrangeIcons() | |
215 | { | |
216 | // TODO | |
217 | } | |
218 | ||
219 | void wxMDIParentFrame::ActivateNext() | |
220 | { | |
221 | // TODO | |
222 | } | |
223 | ||
224 | void wxMDIParentFrame::ActivatePrevious() | |
225 | { | |
226 | // TODO | |
227 | } | |
228 | ||
29e92efb VZ |
229 | bool wxMDIParentFrame::Show( bool show ) |
230 | { | |
29e92efb VZ |
231 | // don't really show the MDI frame unless it has any children other than |
232 | // MDI children as it is pretty useless in this case | |
507ad426 | 233 | |
29e92efb VZ |
234 | if ( show ) |
235 | { | |
236 | // TODO: check for other children | |
7bf8eb78 DE |
237 | if(!GetToolBar()) |
238 | Move(-10000, -10000); | |
29e92efb VZ |
239 | } |
240 | ||
507ad426 SC |
241 | if ( !wxFrame::Show(show) ) |
242 | return false; | |
243 | ||
29e92efb VZ |
244 | return true; |
245 | } | |
246 | ||
e9576ca5 SC |
247 | // Child frame |
248 | ||
249 | wxMDIChildFrame::wxMDIChildFrame() | |
0a67a93b SC |
250 | { |
251 | Init() ; | |
252 | } | |
253 | void wxMDIChildFrame::Init() | |
e9576ca5 SC |
254 | { |
255 | } | |
256 | ||
257 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
e40298d5 JS |
258 | wxWindowID id, |
259 | const wxString& title, | |
260 | const wxPoint& pos, | |
261 | const wxSize& size, | |
262 | long style, | |
263 | const wxString& name) | |
e9576ca5 SC |
264 | { |
265 | SetName(name); | |
e40298d5 | 266 | |
e9576ca5 SC |
267 | if ( id > -1 ) |
268 | m_windowId = id; | |
269 | else | |
270 | m_windowId = (int)NewControlId(); | |
e40298d5 | 271 | |
e9576ca5 | 272 | if (parent) parent->AddChild(this); |
e40298d5 JS |
273 | |
274 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; | |
275 | ||
facd6764 SC |
276 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
277 | ||
e9576ca5 SC |
278 | wxModelessWindows.Append(this); |
279 | return FALSE; | |
280 | } | |
281 | ||
282 | wxMDIChildFrame::~wxMDIChildFrame() | |
283 | { | |
70024cfb DE |
284 | wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame); |
285 | wxASSERT(mdiparent); | |
286 | if(mdiparent->m_currentChild == this) | |
287 | mdiparent->m_currentChild = NULL; | |
0a67a93b | 288 | DestroyChildren(); |
e9576ca5 SC |
289 | } |
290 | ||
291 | void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar) | |
292 | { | |
e40298d5 | 293 | return wxFrame::SetMenuBar( menu_bar ) ; |
e9576ca5 SC |
294 | } |
295 | ||
70024cfb DE |
296 | void wxMDIChildFrame::MacActivate(long timestamp, bool activating) |
297 | { | |
7d671c08 | 298 | wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact")); |
70024cfb DE |
299 | wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame); |
300 | wxASSERT(mdiparent); | |
301 | if(activating) | |
302 | { | |
303 | if(s_macDeactivateWindow == m_parent) | |
304 | { | |
7d671c08 | 305 | wxLogDebug(wxT("parent had been scheduled for deactivation, rehighlighting")); |
70024cfb | 306 | UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true); |
7d671c08 | 307 | wxLogDebug(wxT("done highliting parent")); |
70024cfb DE |
308 | s_macDeactivateWindow = NULL; |
309 | } | |
310 | else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow) | |
311 | mdiparent->wxFrame::MacActivate(timestamp,activating); | |
312 | ||
313 | if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this) | |
314 | mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false); | |
315 | mdiparent->m_currentChild = this; | |
316 | ||
317 | if(s_macDeactivateWindow==this) | |
318 | { | |
7d671c08 | 319 | wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this); |
70024cfb DE |
320 | s_macDeactivateWindow=NULL; |
321 | } | |
322 | else | |
323 | wxFrame::MacActivate(timestamp, activating); | |
324 | } | |
325 | else | |
326 | { | |
327 | // We were scheduled for deactivation, and now we do it. | |
328 | if(s_macDeactivateWindow==this) | |
329 | { | |
330 | s_macDeactivateWindow = NULL; | |
331 | wxFrame::MacActivate(timestamp,activating); | |
332 | if(mdiparent->m_currentChild==this) | |
333 | mdiparent->wxFrame::MacActivate(timestamp,activating); | |
334 | } | |
335 | else // schedule ourselves for deactivation | |
336 | { | |
337 | if(s_macDeactivateWindow) | |
7d671c08 SC |
338 | wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow); |
339 | wxLogDebug(wxT("Scheduling delayed deactivation")); | |
70024cfb DE |
340 | s_macDeactivateWindow = this; |
341 | } | |
342 | } | |
343 | } | |
344 | ||
e9576ca5 SC |
345 | // MDI operations |
346 | void wxMDIChildFrame::Maximize() | |
347 | { | |
0a67a93b | 348 | wxFrame::Maximize() ; |
e9576ca5 SC |
349 | } |
350 | ||
351 | void wxMDIChildFrame::Restore() | |
352 | { | |
0a67a93b | 353 | wxFrame::Restore() ; |
e9576ca5 SC |
354 | } |
355 | ||
356 | void wxMDIChildFrame::Activate() | |
357 | { | |
e9576ca5 SC |
358 | } |
359 | ||
0a67a93b SC |
360 | //----------------------------------------------------------------------------- |
361 | // wxMDIClientWindow | |
362 | //----------------------------------------------------------------------------- | |
e9576ca5 SC |
363 | |
364 | wxMDIClientWindow::wxMDIClientWindow() | |
365 | { | |
366 | } | |
367 | ||
368 | wxMDIClientWindow::~wxMDIClientWindow() | |
369 | { | |
0a67a93b | 370 | DestroyChildren(); |
e9576ca5 SC |
371 | } |
372 | ||
373 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) | |
374 | { | |
84be293d KO |
375 | if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style)) |
376 | return FALSE; | |
e40298d5 | 377 | |
0a67a93b SC |
378 | wxModelessWindows.Append(this); |
379 | return TRUE; | |
e9576ca5 SC |
380 | } |
381 | ||
be7a1013 DE |
382 | // Get size *available for subwindows* i.e. excluding menu bar. |
383 | void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const | |
384 | { | |
385 | wxDisplaySize( x , y ) ; | |
386 | } | |
387 | ||
e9576ca5 SC |
388 | // Explicitly call default scroll behaviour |
389 | void wxMDIClientWindow::OnScroll(wxScrollEvent& event) | |
390 | { | |
e9576ca5 SC |
391 | } |
392 |