]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/mdi.cpp
Removed unused event table entries
[wxWidgets.git] / src / mac / carbon / mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mdi.cpp
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 #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"
19 #include "wx/log.h"
20
21 #include "wx/mac/private.h"
22 #include "wx/mac/uma.h"
23
24 extern wxWindowList wxModelessWindows;
25
26 #if !USE_SHARED_LIBRARY
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)
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
40 #endif
41
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;
48 static const int IDM_WINDOWPREV = 4006;
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
57 // Parent frame
58
59 wxMDIParentFrame::wxMDIParentFrame()
60 {
61 m_clientWindow = NULL;
62 m_currentChild = NULL;
63 m_windowMenu = (wxMenu*) NULL;
64 m_parentFrameActive = TRUE;
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 {
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;
88
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
97 wxFrame::Create( parent , id , title , pos , size , style , name ) ;
98 m_parentFrameActive = TRUE;
99
100 OnCreateClient();
101
102 return TRUE;
103 }
104
105 wxMDIParentFrame::~wxMDIParentFrame()
106 {
107 DestroyChildren();
108 // already delete by DestroyChildren()
109 #if wxUSE_TOOLBAR
110 m_frameToolBar = NULL;
111 #endif
112 #if wxUSE_STATUSBAR
113 m_frameStatusBar = NULL;
114 #endif
115 m_clientWindow = NULL ;
116
117 if (m_windowMenu)
118 {
119 delete m_windowMenu;
120 m_windowMenu = (wxMenu*) NULL;
121 }
122
123 if ( m_clientWindow )
124 {
125 delete m_clientWindow;
126 m_clientWindow = NULL ;
127 }
128 }
129
130
131 void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
132 {
133 wxFrame::SetMenuBar( menu_bar ) ;
134 }
135
136 void wxMDIParentFrame::MacActivate(long timestamp, bool activating)
137 {
138 wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
139 if(activating)
140 {
141 if(s_macDeactivateWindow && s_macDeactivateWindow->GetParent()==this)
142 {
143 wxLogDebug(wxT("child had been scheduled for deactivation, rehighlighting"));
144 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
145 wxLogDebug(wxT("done highliting child"));
146 s_macDeactivateWindow = NULL;
147 }
148 else if(s_macDeactivateWindow == this)
149 {
150 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"), this);
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 }
161 }
162 else
163 {
164 // We were scheduled for deactivation, and now we do it.
165 if(s_macDeactivateWindow==this)
166 {
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)
175 wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
176 wxLogDebug(wxT("Scheduling delayed MDI Parent deactivation"));
177 s_macDeactivateWindow = this;
178 }
179 }
180 }
181
182 void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
183 {
184 event.Skip();
185 }
186
187 // Returns the active MDI child window
188 wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
189 {
190 return m_currentChild ;
191 }
192
193 // Create the client window class (don't Create the window,
194 // just return a new class)
195 wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
196 {
197 m_clientWindow = new wxMDIClientWindow( this );
198 return m_clientWindow;
199 }
200
201 // Responds to colour changes, and passes event on to children.
202 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
203 {
204 // TODO
205
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
236 // Child frame
237
238 wxMDIChildFrame::wxMDIChildFrame()
239 {
240 Init() ;
241 }
242 void wxMDIChildFrame::Init()
243 {
244 }
245
246 bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
247 wxWindowID id,
248 const wxString& title,
249 const wxPoint& pos,
250 const wxSize& size,
251 long style,
252 const wxString& name)
253 {
254 SetName(name);
255
256 if ( id > -1 )
257 m_windowId = id;
258 else
259 m_windowId = (int)NewControlId();
260
261 if (parent) parent->AddChild(this);
262
263 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
264
265 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
266
267 wxModelessWindows.Append(this);
268 return FALSE;
269 }
270
271 wxMDIChildFrame::~wxMDIChildFrame()
272 {
273 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
274 wxASSERT(mdiparent);
275 if(mdiparent->m_currentChild == this)
276 mdiparent->m_currentChild = NULL;
277 DestroyChildren();
278 // already delete by DestroyChildren()
279 #if wxUSE_TOOLBAR
280 m_frameToolBar = NULL;
281 #endif
282 #if wxUSE_STATUSBAR
283 m_frameStatusBar = NULL;
284 #endif
285 }
286
287 void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
288 {
289 return wxFrame::SetMenuBar( menu_bar ) ;
290 }
291
292 void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
293 {
294 wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
295 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
296 wxASSERT(mdiparent);
297 if(activating)
298 {
299 if(s_macDeactivateWindow == m_parent)
300 {
301 wxLogDebug(wxT("parent had been scheduled for deactivation, rehighlighting"));
302 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
303 wxLogDebug(wxT("done highliting parent"));
304 s_macDeactivateWindow = NULL;
305 }
306 else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow)
307 mdiparent->wxFrame::MacActivate(timestamp,activating);
308
309 if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this)
310 mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false);
311 mdiparent->m_currentChild = this;
312
313 if(s_macDeactivateWindow==this)
314 {
315 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this);
316 s_macDeactivateWindow=NULL;
317 }
318 else
319 wxFrame::MacActivate(timestamp, activating);
320 }
321 else
322 {
323 // We were scheduled for deactivation, and now we do it.
324 if(s_macDeactivateWindow==this)
325 {
326 s_macDeactivateWindow = NULL;
327 wxFrame::MacActivate(timestamp,activating);
328 if(mdiparent->m_currentChild==this)
329 mdiparent->wxFrame::MacActivate(timestamp,activating);
330 }
331 else // schedule ourselves for deactivation
332 {
333 if(s_macDeactivateWindow)
334 wxLogDebug(wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
335 wxLogDebug(wxT("Scheduling delayed deactivation"));
336 s_macDeactivateWindow = this;
337 }
338 }
339 }
340
341 // MDI operations
342 void wxMDIChildFrame::Maximize()
343 {
344 wxFrame::Maximize() ;
345 }
346
347 void wxMDIChildFrame::Restore()
348 {
349 wxFrame::Restore() ;
350 }
351
352 void wxMDIChildFrame::Activate()
353 {
354 }
355
356 //-----------------------------------------------------------------------------
357 // wxMDIClientWindow
358 //-----------------------------------------------------------------------------
359
360 wxMDIClientWindow::wxMDIClientWindow()
361 {
362 }
363
364 wxMDIClientWindow::~wxMDIClientWindow()
365 {
366 DestroyChildren();
367 }
368
369 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
370 {
371 if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style))
372 return FALSE;
373
374 wxModelessWindows.Append(this);
375 return TRUE;
376 }
377
378 // Get size *available for subwindows* i.e. excluding menu bar.
379 void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
380 {
381 wxDisplaySize( x , y ) ;
382 }
383
384 // Explicitly call default scroll behaviour
385 void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
386 {
387 }
388