1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "mdi.h"
16 #include "wx/wxprec.h"
20 #include "wx/settings.h"
23 #include "wx/mac/private.h"
24 #include "wx/mac/uma.h"
26 extern wxWindowList wxModelessWindows
;
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
30 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
31 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
33 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
34 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
35 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
38 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
39 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
44 static const wxChar
*TRACE_MDI
= _T("mdi");
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;
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;
58 // Status border dimensions
59 static const int wxTHICK_LINE_BORDER
= 3;
63 wxMDIParentFrame::wxMDIParentFrame()
65 m_clientWindow
= NULL
;
66 m_currentChild
= NULL
;
67 m_windowMenu
= (wxMenu
*) NULL
;
68 m_parentFrameActive
= TRUE
;
71 bool wxMDIParentFrame::Create(wxWindow
*parent
,
73 const wxString
& title
,
79 m_clientWindow
= NULL
;
80 m_currentChild
= NULL
;
82 // this style can be used to prevent a window from having the standard MDI
84 if ( style
& wxFRAME_NO_WINDOW_MENU
)
86 m_windowMenu
= (wxMenu
*)NULL
;
87 style
-= wxFRAME_NO_WINDOW_MENU
;
89 else // normal case: we have the window menu, so construct it
91 m_windowMenu
= new wxMenu
;
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"));
101 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
) ;
102 m_parentFrameActive
= TRUE
;
109 wxMDIParentFrame::~wxMDIParentFrame()
112 // already deleted by DestroyChildren()
113 m_clientWindow
= NULL
;
119 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
121 wxFrame::SetMenuBar( menu_bar
) ;
124 void wxMDIParentFrame::GetRectForTopLevelChildren(int *x
, int *y
, int *w
, int *h
)
133 void wxMDIParentFrame::MacActivate(long timestamp
, bool activating
)
135 wxLogTrace(TRACE_MDI
, wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp
,activating
?wxT("ACTIV"):wxT("deact"));
138 if(s_macDeactivateWindow
&& s_macDeactivateWindow
->GetParent()==this)
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
;
145 else if(s_macDeactivateWindow
== this)
147 wxLogTrace(TRACE_MDI
, wxT("Avoided deactivation/activation of this=%p"), this);
148 s_macDeactivateWindow
= NULL
;
150 else // window to deactivate is NULL or is not us or one of our kids
152 // activate kid instead
154 m_currentChild
->MacActivate(timestamp
,activating
);
156 wxFrame::MacActivate(timestamp
,activating
);
161 // We were scheduled for deactivation, and now we do it.
162 if(s_macDeactivateWindow
==this)
164 s_macDeactivateWindow
= NULL
;
166 m_currentChild
->MacActivate(timestamp
,activating
);
167 wxFrame::MacActivate(timestamp
,activating
);
169 else // schedule ourselves for deactivation
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;
179 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
184 // Returns the active MDI child window
185 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
187 return m_currentChild
;
190 // Create the client window class (don't Create the window,
191 // just return a new class)
192 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
194 m_clientWindow
= new wxMDIClientWindow( this );
195 return m_clientWindow
;
198 // Responds to colour changes, and passes event on to children.
199 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
203 // Propagate the event to the non-top-level children
204 wxFrame::OnSysColourChanged(event
);
208 void wxMDIParentFrame::Cascade()
213 void wxMDIParentFrame::Tile()
218 void wxMDIParentFrame::ArrangeIcons()
223 void wxMDIParentFrame::ActivateNext()
228 void wxMDIParentFrame::ActivatePrevious()
233 bool wxMDIParentFrame::Show( bool show
)
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
240 // TODO: check for other children
242 Move(-10000, -10000);
245 if ( !wxFrame::Show(show
) )
253 wxMDIChildFrame::wxMDIChildFrame()
257 void wxMDIChildFrame::Init()
261 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
263 const wxString
& title
,
267 const wxString
& name
)
274 m_windowId
= (int)NewControlId();
276 if (parent
) parent
->AddChild(this);
278 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
280 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
282 wxModelessWindows
.Append(this);
286 wxMDIChildFrame::~wxMDIChildFrame()
288 wxMDIParentFrame
*mdiparent
= wxDynamicCast(m_parent
, wxMDIParentFrame
);
290 if(mdiparent
->m_currentChild
== this)
291 mdiparent
->m_currentChild
= NULL
;
295 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
297 return wxFrame::SetMenuBar( menu_bar
) ;
300 void wxMDIChildFrame::MacActivate(long timestamp
, bool activating
)
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
);
307 if(s_macDeactivateWindow
== m_parent
)
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
;
314 else if((mdiparent
->m_currentChild
==this) || !s_macDeactivateWindow
)
315 mdiparent
->wxFrame::MacActivate(timestamp
,activating
);
317 if(mdiparent
->m_currentChild
&& mdiparent
->m_currentChild
!=this)
318 mdiparent
->m_currentChild
->wxFrame::MacActivate(timestamp
,false);
319 mdiparent
->m_currentChild
= this;
321 if(s_macDeactivateWindow
==this)
323 wxLogTrace(TRACE_MDI
, wxT("Avoided deactivation/activation of this=%p"),this);
324 s_macDeactivateWindow
=NULL
;
327 wxFrame::MacActivate(timestamp
, activating
);
331 // We were scheduled for deactivation, and now we do it.
332 if(s_macDeactivateWindow
==this)
334 s_macDeactivateWindow
= NULL
;
335 wxFrame::MacActivate(timestamp
,activating
);
336 if(mdiparent
->m_currentChild
==this)
337 mdiparent
->wxFrame::MacActivate(timestamp
,activating
);
339 else // schedule ourselves for deactivation
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;
350 void wxMDIChildFrame::Maximize()
352 wxFrame::Maximize() ;
355 void wxMDIChildFrame::Restore()
360 void wxMDIChildFrame::Activate()
364 //-----------------------------------------------------------------------------
366 //-----------------------------------------------------------------------------
368 wxMDIClientWindow::wxMDIClientWindow()
372 wxMDIClientWindow::~wxMDIClientWindow()
377 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
379 if ( !wxWindow::Create(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
))
382 wxModelessWindows
.Append(this);
386 // Get size *available for subwindows* i.e. excluding menu bar.
387 void wxMDIClientWindow::DoGetClientSize(int *x
, int *y
) const
389 wxDisplaySize( x
, y
) ;
392 // Explicitly call default scroll behaviour
393 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)