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