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 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;
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;
56 // Status border dimensions
57 static const int wxTHICK_LINE_BORDER
= 3;
61 wxMDIParentFrame::wxMDIParentFrame()
63 m_clientWindow
= NULL
;
64 m_currentChild
= NULL
;
65 m_windowMenu
= (wxMenu
*) NULL
;
66 m_parentFrameActive
= TRUE
;
69 bool wxMDIParentFrame::Create(wxWindow
*parent
,
71 const wxString
& title
,
77 m_clientWindow
= NULL
;
78 m_currentChild
= NULL
;
80 // this style can be used to prevent a window from having the standard MDI
82 if ( style
& wxFRAME_NO_WINDOW_MENU
)
84 m_windowMenu
= (wxMenu
*)NULL
;
85 style
-= wxFRAME_NO_WINDOW_MENU
;
87 else // normal case: we have the window menu, so construct it
89 m_windowMenu
= new wxMenu
;
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"));
99 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
) ;
100 m_parentFrameActive
= TRUE
;
107 wxMDIParentFrame::~wxMDIParentFrame()
110 // already deleted by DestroyChildren()
111 m_clientWindow
= NULL
;
117 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
119 wxFrame::SetMenuBar( menu_bar
) ;
122 void wxMDIParentFrame::GetRectForTopLevelChildren(int *x
, int *y
, int *w
, int *h
)
131 void wxMDIParentFrame::MacActivate(long timestamp
, bool activating
)
133 wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp
,activating
?wxT("ACTIV"):wxT("deact"));
136 if(s_macDeactivateWindow
&& s_macDeactivateWindow
->GetParent()==this)
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
;
143 else if(s_macDeactivateWindow
== this)
145 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"), this);
146 s_macDeactivateWindow
= NULL
;
148 else // window to deactivate is NULL or is not us or one of our kids
150 // activate kid instead
152 m_currentChild
->MacActivate(timestamp
,activating
);
154 wxFrame::MacActivate(timestamp
,activating
);
159 // We were scheduled for deactivation, and now we do it.
160 if(s_macDeactivateWindow
==this)
162 s_macDeactivateWindow
= NULL
;
164 m_currentChild
->MacActivate(timestamp
,activating
);
165 wxFrame::MacActivate(timestamp
,activating
);
167 else // schedule ourselves for deactivation
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;
177 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
182 // Returns the active MDI child window
183 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
185 return m_currentChild
;
188 // Create the client window class (don't Create the window,
189 // just return a new class)
190 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
192 m_clientWindow
= new wxMDIClientWindow( this );
193 return m_clientWindow
;
196 // Responds to colour changes, and passes event on to children.
197 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
201 // Propagate the event to the non-top-level children
202 wxFrame::OnSysColourChanged(event
);
206 void wxMDIParentFrame::Cascade()
211 void wxMDIParentFrame::Tile()
216 void wxMDIParentFrame::ArrangeIcons()
221 void wxMDIParentFrame::ActivateNext()
226 void wxMDIParentFrame::ActivatePrevious()
231 bool wxMDIParentFrame::Show( bool show
)
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
238 // TODO: check for other children
240 Move(-10000, -10000);
243 if ( !wxFrame::Show(show
) )
251 wxMDIChildFrame::wxMDIChildFrame()
255 void wxMDIChildFrame::Init()
259 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
261 const wxString
& title
,
265 const wxString
& name
)
272 m_windowId
= (int)NewControlId();
274 if (parent
) parent
->AddChild(this);
276 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
278 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
280 wxModelessWindows
.Append(this);
284 wxMDIChildFrame::~wxMDIChildFrame()
286 wxMDIParentFrame
*mdiparent
= wxDynamicCast(m_parent
, wxMDIParentFrame
);
288 if(mdiparent
->m_currentChild
== this)
289 mdiparent
->m_currentChild
= NULL
;
293 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
295 return wxFrame::SetMenuBar( menu_bar
) ;
298 void wxMDIChildFrame::MacActivate(long timestamp
, bool activating
)
300 wxLogDebug(wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp
,activating
?wxT("ACTIV"):wxT("deact"));
301 wxMDIParentFrame
*mdiparent
= wxDynamicCast(m_parent
, wxMDIParentFrame
);
305 if(s_macDeactivateWindow
== m_parent
)
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
;
312 else if((mdiparent
->m_currentChild
==this) || !s_macDeactivateWindow
)
313 mdiparent
->wxFrame::MacActivate(timestamp
,activating
);
315 if(mdiparent
->m_currentChild
&& mdiparent
->m_currentChild
!=this)
316 mdiparent
->m_currentChild
->wxFrame::MacActivate(timestamp
,false);
317 mdiparent
->m_currentChild
= this;
319 if(s_macDeactivateWindow
==this)
321 wxLogDebug(wxT("Avoided deactivation/activation of this=%p"),this);
322 s_macDeactivateWindow
=NULL
;
325 wxFrame::MacActivate(timestamp
, activating
);
329 // We were scheduled for deactivation, and now we do it.
330 if(s_macDeactivateWindow
==this)
332 s_macDeactivateWindow
= NULL
;
333 wxFrame::MacActivate(timestamp
,activating
);
334 if(mdiparent
->m_currentChild
==this)
335 mdiparent
->wxFrame::MacActivate(timestamp
,activating
);
337 else // schedule ourselves for deactivation
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;
348 void wxMDIChildFrame::Maximize()
350 wxFrame::Maximize() ;
353 void wxMDIChildFrame::Restore()
358 void wxMDIChildFrame::Activate()
362 //-----------------------------------------------------------------------------
364 //-----------------------------------------------------------------------------
366 wxMDIClientWindow::wxMDIClientWindow()
370 wxMDIClientWindow::~wxMDIClientWindow()
375 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
377 if ( !wxWindow::Create(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
))
380 wxModelessWindows
.Append(this);
384 // Get size *available for subwindows* i.e. excluding menu bar.
385 void wxMDIClientWindow::DoGetClientSize(int *x
, int *y
) const
387 wxDisplaySize( x
, y
) ;
390 // Explicitly call default scroll behaviour
391 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)