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