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