1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mdi.h"
18 #include "wx/settings.h"
21 #include "wx/mac/private.h"
22 #include "wx/mac/uma.h"
24 extern wxWindowList wxModelessWindows
;
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
28 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
29 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
31 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
32 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
33 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
36 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
37 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
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;
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;
54 // Status border dimensions
55 static const int wxTHICK_LINE_BORDER
= 3;
59 wxMDIParentFrame::wxMDIParentFrame()
61 m_clientWindow
= NULL
;
62 m_currentChild
= NULL
;
63 m_windowMenu
= (wxMenu
*) NULL
;
64 m_parentFrameActive
= TRUE
;
67 bool wxMDIParentFrame::Create(wxWindow
*parent
,
69 const wxString
& title
,
75 m_clientWindow
= NULL
;
76 m_currentChild
= NULL
;
78 // this style can be used to prevent a window from having the standard MDI
80 if ( style
& wxFRAME_NO_WINDOW_MENU
)
82 m_windowMenu
= (wxMenu
*)NULL
;
83 style
-= wxFRAME_NO_WINDOW_MENU
;
85 else // normal case: we have the window menu, so construct it
87 m_windowMenu
= new wxMenu
;
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"));
97 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
) ;
98 m_parentFrameActive
= TRUE
;
105 wxMDIParentFrame::~wxMDIParentFrame()
108 // already deleted by DestroyChildren()
109 m_clientWindow
= NULL
;
115 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
117 wxFrame::SetMenuBar( menu_bar
) ;
120 void wxMDIParentFrame::GetRectForTopLevelChildren(int *x
, int *y
, int *w
, int *h
)
129 void wxMDIParentFrame::MacActivate(long timestamp
, bool activating
)
131 wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp
,activating
?wxT("ACTIV"):wxT("deact"));
134 if(s_macDeactivateWindow
&& s_macDeactivateWindow
->GetParent()==this)
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
;
141 else if(s_macDeactivateWindow
== this)
143 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"), this);
144 s_macDeactivateWindow
= NULL
;
146 else // window to deactivate is NULL or is not us or one of our kids
148 // activate kid instead
150 m_currentChild
->MacActivate(timestamp
,activating
);
152 wxFrame::MacActivate(timestamp
,activating
);
157 // We were scheduled for deactivation, and now we do it.
158 if(s_macDeactivateWindow
==this)
160 s_macDeactivateWindow
= NULL
;
162 m_currentChild
->MacActivate(timestamp
,activating
);
163 wxFrame::MacActivate(timestamp
,activating
);
165 else // schedule ourselves for deactivation
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;
175 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
180 // Returns the active MDI child window
181 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
183 return m_currentChild
;
186 // Create the client window class (don't Create the window,
187 // just return a new class)
188 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
190 m_clientWindow
= new wxMDIClientWindow( this );
191 return m_clientWindow
;
194 // Responds to colour changes, and passes event on to children.
195 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
199 // Propagate the event to the non-top-level children
200 wxFrame::OnSysColourChanged(event
);
204 void wxMDIParentFrame::Cascade()
209 void wxMDIParentFrame::Tile()
214 void wxMDIParentFrame::ArrangeIcons()
219 void wxMDIParentFrame::ActivateNext()
224 void wxMDIParentFrame::ActivatePrevious()
229 bool wxMDIParentFrame::Show( bool show
)
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
236 // TODO: check for other children
238 Move(-10000, -10000);
241 if ( !wxFrame::Show(show
) )
249 wxMDIChildFrame::wxMDIChildFrame()
253 void wxMDIChildFrame::Init()
257 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
259 const wxString
& title
,
263 const wxString
& name
)
270 m_windowId
= (int)NewControlId();
272 if (parent
) parent
->AddChild(this);
274 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
276 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
278 wxModelessWindows
.Append(this);
282 wxMDIChildFrame::~wxMDIChildFrame()
284 wxMDIParentFrame
*mdiparent
= wxDynamicCast(m_parent
, wxMDIParentFrame
);
286 if(mdiparent
->m_currentChild
== this)
287 mdiparent
->m_currentChild
= NULL
;
291 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
293 return wxFrame::SetMenuBar( menu_bar
) ;
296 void wxMDIChildFrame::MacActivate(long timestamp
, bool activating
)
298 wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp
,activating
?wxT("ACTIV"):wxT("deact"));
299 wxMDIParentFrame
*mdiparent
= wxDynamicCast(m_parent
, wxMDIParentFrame
);
303 if(s_macDeactivateWindow
== m_parent
)
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
;
310 else if((mdiparent
->m_currentChild
==this) || !s_macDeactivateWindow
)
311 mdiparent
->wxFrame::MacActivate(timestamp
,activating
);
313 if(mdiparent
->m_currentChild
&& mdiparent
->m_currentChild
!=this)
314 mdiparent
->m_currentChild
->wxFrame::MacActivate(timestamp
,false);
315 mdiparent
->m_currentChild
= this;
317 if(s_macDeactivateWindow
==this)
319 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this);
320 s_macDeactivateWindow
=NULL
;
323 wxFrame::MacActivate(timestamp
, activating
);
327 // We were scheduled for deactivation, and now we do it.
328 if(s_macDeactivateWindow
==this)
330 s_macDeactivateWindow
= NULL
;
331 wxFrame::MacActivate(timestamp
,activating
);
332 if(mdiparent
->m_currentChild
==this)
333 mdiparent
->wxFrame::MacActivate(timestamp
,activating
);
335 else // schedule ourselves for deactivation
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;
346 void wxMDIChildFrame::Maximize()
348 wxFrame::Maximize() ;
351 void wxMDIChildFrame::Restore()
356 void wxMDIChildFrame::Activate()
360 //-----------------------------------------------------------------------------
362 //-----------------------------------------------------------------------------
364 wxMDIClientWindow::wxMDIClientWindow()
368 wxMDIClientWindow::~wxMDIClientWindow()
373 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
375 if ( !wxWindow::Create(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
))
378 wxModelessWindows
.Append(this);
382 // Get size *available for subwindows* i.e. excluding menu bar.
383 void wxMDIClientWindow::DoGetClientSize(int *x
, int *y
) const
385 wxDisplaySize( x
, y
) ;
388 // Explicitly call default scroll behaviour
389 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)