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