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"
22 #include "wx/settings.h"
25 #include "wx/mac/private.h"
26 #include "wx/mac/uma.h"
28 extern wxWindowList wxModelessWindows
;
30 #if !USE_SHARED_LIBRARY
31 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
32 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
33 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
35 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
36 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
37 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
40 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
41 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
46 static const wxChar
*TRACE_MDI
= _T("mdi");
48 static const int IDM_WINDOWTILE
= 4001;
49 static const int IDM_WINDOWTILEHOR
= 4001;
50 static const int IDM_WINDOWCASCADE
= 4002;
51 static const int IDM_WINDOWICONS
= 4003;
52 static const int IDM_WINDOWNEXT
= 4004;
53 static const int IDM_WINDOWTILEVERT
= 4005;
54 static const int IDM_WINDOWPREV
= 4006;
56 // This range gives a maximum of 500 MDI children. Should be enough :-)
57 static const int wxFIRST_MDI_CHILD
= 4100;
58 static const int wxLAST_MDI_CHILD
= 4600;
60 // Status border dimensions
61 static const int wxTHICK_LINE_BORDER
= 3;
65 wxMDIParentFrame::wxMDIParentFrame()
67 m_clientWindow
= NULL
;
68 m_currentChild
= NULL
;
69 m_windowMenu
= (wxMenu
*) NULL
;
70 m_parentFrameActive
= TRUE
;
73 bool wxMDIParentFrame::Create(wxWindow
*parent
,
75 const wxString
& title
,
81 m_clientWindow
= NULL
;
82 m_currentChild
= NULL
;
84 // this style can be used to prevent a window from having the standard MDI
86 if ( style
& wxFRAME_NO_WINDOW_MENU
)
88 m_windowMenu
= (wxMenu
*)NULL
;
89 style
-= wxFRAME_NO_WINDOW_MENU
;
91 else // normal case: we have the window menu, so construct it
93 m_windowMenu
= new wxMenu
;
95 m_windowMenu
->Append(IDM_WINDOWCASCADE
, wxT("&Cascade"));
96 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, wxT("Tile &Horizontally"));
97 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, wxT("Tile &Vertically"));
98 m_windowMenu
->AppendSeparator();
99 m_windowMenu
->Append(IDM_WINDOWICONS
, wxT("&Arrange Icons"));
100 m_windowMenu
->Append(IDM_WINDOWNEXT
, wxT("&Next"));
103 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
) ;
104 m_parentFrameActive
= TRUE
;
111 wxMDIParentFrame::~wxMDIParentFrame()
114 // already deleted by DestroyChildren()
115 m_clientWindow
= NULL
;
121 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
123 wxFrame::SetMenuBar( menu_bar
) ;
126 void wxMDIParentFrame::GetRectForTopLevelChildren(int *x
, int *y
, int *w
, int *h
)
135 void wxMDIParentFrame::MacActivate(long timestamp
, bool activating
)
137 wxLogTrace(TRACE_MDI
, wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp
,activating
?wxT("ACTIV"):wxT("deact"));
140 if(s_macDeactivateWindow
&& s_macDeactivateWindow
->GetParent()==this)
142 wxLogTrace(TRACE_MDI
, wxT("child had been scheduled for deactivation, rehighlighting"));
143 UMAHighlightAndActivateWindow((WindowRef
)s_macDeactivateWindow
->MacGetWindowRef(), true);
144 wxLogTrace(TRACE_MDI
, wxT("done highliting child"));
145 s_macDeactivateWindow
= NULL
;
147 else if(s_macDeactivateWindow
== this)
149 wxLogTrace(TRACE_MDI
, wxT("Avoided deactivation/activation of this=%p"), this);
150 s_macDeactivateWindow
= NULL
;
152 else // window to deactivate is NULL or is not us or one of our kids
154 // activate kid instead
156 m_currentChild
->MacActivate(timestamp
,activating
);
158 wxFrame::MacActivate(timestamp
,activating
);
163 // We were scheduled for deactivation, and now we do it.
164 if(s_macDeactivateWindow
==this)
166 s_macDeactivateWindow
= NULL
;
168 m_currentChild
->MacActivate(timestamp
,activating
);
169 wxFrame::MacActivate(timestamp
,activating
);
171 else // schedule ourselves for deactivation
173 if(s_macDeactivateWindow
)
174 wxLogTrace(TRACE_MDI
, wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow
);
175 wxLogTrace(TRACE_MDI
, wxT("Scheduling delayed MDI Parent deactivation"));
176 s_macDeactivateWindow
= this;
181 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
186 // Returns the active MDI child window
187 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
189 return m_currentChild
;
192 // Create the client window class (don't Create the window,
193 // just return a new class)
194 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
196 m_clientWindow
= new wxMDIClientWindow( this );
197 return m_clientWindow
;
200 // Responds to colour changes, and passes event on to children.
201 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
205 // Propagate the event to the non-top-level children
206 wxFrame::OnSysColourChanged(event
);
210 void wxMDIParentFrame::Cascade()
215 void wxMDIParentFrame::Tile()
220 void wxMDIParentFrame::ArrangeIcons()
225 void wxMDIParentFrame::ActivateNext()
230 void wxMDIParentFrame::ActivatePrevious()
235 bool wxMDIParentFrame::Show( bool show
)
237 // don't really show the MDI frame unless it has any children other than
238 // MDI children as it is pretty useless in this case
242 // TODO: check for other children
244 Move(-10000, -10000);
247 if ( !wxFrame::Show(show
) )
255 wxMDIChildFrame::wxMDIChildFrame()
259 void wxMDIChildFrame::Init()
263 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
265 const wxString
& title
,
269 const wxString
& name
)
276 m_windowId
= (int)NewControlId();
278 if (parent
) parent
->AddChild(this);
280 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
282 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
284 wxModelessWindows
.Append(this);
288 wxMDIChildFrame::~wxMDIChildFrame()
290 wxMDIParentFrame
*mdiparent
= wxDynamicCast(m_parent
, wxMDIParentFrame
);
292 if(mdiparent
->m_currentChild
== this)
293 mdiparent
->m_currentChild
= NULL
;
297 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
299 return wxFrame::SetMenuBar( menu_bar
) ;
302 void wxMDIChildFrame::MacActivate(long timestamp
, bool activating
)
304 wxLogTrace(TRACE_MDI
, wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp
,activating
?wxT("ACTIV"):wxT("deact"));
305 wxMDIParentFrame
*mdiparent
= wxDynamicCast(m_parent
, wxMDIParentFrame
);
309 if(s_macDeactivateWindow
== m_parent
)
311 wxLogTrace(TRACE_MDI
, wxT("parent had been scheduled for deactivation, rehighlighting"));
312 UMAHighlightAndActivateWindow((WindowRef
)s_macDeactivateWindow
->MacGetWindowRef(), true);
313 wxLogTrace(TRACE_MDI
, wxT("done highliting parent"));
314 s_macDeactivateWindow
= NULL
;
316 else if((mdiparent
->m_currentChild
==this) || !s_macDeactivateWindow
)
317 mdiparent
->wxFrame::MacActivate(timestamp
,activating
);
319 if(mdiparent
->m_currentChild
&& mdiparent
->m_currentChild
!=this)
320 mdiparent
->m_currentChild
->wxFrame::MacActivate(timestamp
,false);
321 mdiparent
->m_currentChild
= this;
323 if(s_macDeactivateWindow
==this)
325 wxLogTrace(TRACE_MDI
, wxT("Avoided deactivation/activation of this=%p"),this);
326 s_macDeactivateWindow
=NULL
;
329 wxFrame::MacActivate(timestamp
, activating
);
333 // We were scheduled for deactivation, and now we do it.
334 if(s_macDeactivateWindow
==this)
336 s_macDeactivateWindow
= NULL
;
337 wxFrame::MacActivate(timestamp
,activating
);
338 if(mdiparent
->m_currentChild
==this)
339 mdiparent
->wxFrame::MacActivate(timestamp
,activating
);
341 else // schedule ourselves for deactivation
343 if(s_macDeactivateWindow
)
344 wxLogTrace(TRACE_MDI
, wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow
);
345 wxLogTrace(TRACE_MDI
, wxT("Scheduling delayed deactivation"));
346 s_macDeactivateWindow
= this;
352 void wxMDIChildFrame::Maximize()
354 wxFrame::Maximize() ;
357 void wxMDIChildFrame::Restore()
362 void wxMDIChildFrame::Activate()
366 //-----------------------------------------------------------------------------
368 //-----------------------------------------------------------------------------
370 wxMDIClientWindow::wxMDIClientWindow()
374 wxMDIClientWindow::~wxMDIClientWindow()
379 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
381 if ( !wxWindow::Create(parent
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, style
))
384 wxModelessWindows
.Append(this);
388 // Get size *available for subwindows* i.e. excluding menu bar.
389 void wxMDIClientWindow::DoGetClientSize(int *x
, int *y
) const
391 wxDisplaySize( x
, y
) ;
394 // Explicitly call default scroll behaviour
395 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)