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