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"
20 #include "wx/mac/private.h"
22 extern wxWindowList wxModelessWindows
;
24 #if !USE_SHARED_LIBRARY
25 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
26 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
27 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
29 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
30 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
31 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
34 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
35 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
40 static const int IDM_WINDOWTILE
= 4001;
41 static const int IDM_WINDOWTILEHOR
= 4001;
42 static const int IDM_WINDOWCASCADE
= 4002;
43 static const int IDM_WINDOWICONS
= 4003;
44 static const int IDM_WINDOWNEXT
= 4004;
45 static const int IDM_WINDOWTILEVERT
= 4005;
46 static const int IDM_WINDOWPREV
= 4006;
48 // This range gives a maximum of 500 MDI children. Should be enough :-)
49 static const int wxFIRST_MDI_CHILD
= 4100;
50 static const int wxLAST_MDI_CHILD
= 4600;
52 // Status border dimensions
53 static const int wxTHICK_LINE_BORDER
= 3;
57 wxMDIParentFrame::wxMDIParentFrame()
59 m_clientWindow
= NULL
;
60 m_currentChild
= NULL
;
61 m_windowMenu
= (wxMenu
*) NULL
;
62 m_parentFrameActive
= TRUE
;
65 bool wxMDIParentFrame::Create(wxWindow
*parent
,
67 const wxString
& title
,
73 m_clientWindow
= NULL
;
74 m_currentChild
= NULL
;
76 // this style can be used to prevent a window from having the standard MDI
78 if ( style
& wxFRAME_NO_WINDOW_MENU
)
80 m_windowMenu
= (wxMenu
*)NULL
;
81 style
-= wxFRAME_NO_WINDOW_MENU
;
83 else // normal case: we have the window menu, so construct it
85 m_windowMenu
= new wxMenu
;
87 m_windowMenu
->Append(IDM_WINDOWCASCADE
, wxT("&Cascade"));
88 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, wxT("Tile &Horizontally"));
89 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, wxT("Tile &Vertically"));
90 m_windowMenu
->AppendSeparator();
91 m_windowMenu
->Append(IDM_WINDOWICONS
, wxT("&Arrange Icons"));
92 m_windowMenu
->Append(IDM_WINDOWNEXT
, wxT("&Next"));
95 wxFrame::Create( parent
, id
, title
, wxPoint( 2000 , 2000 ) , size
, style
, name
) ;
96 m_parentFrameActive
= TRUE
;
103 wxMDIParentFrame::~wxMDIParentFrame()
106 // already delete by DestroyChildren()
107 m_frameToolBar
= NULL
;
108 m_frameStatusBar
= NULL
;
109 m_clientWindow
= NULL
;
114 m_windowMenu
= (wxMenu
*) NULL
;
117 if ( m_clientWindow
)
119 delete m_clientWindow
;
120 m_clientWindow
= NULL
;
125 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
127 wxFrame::SetMenuBar( menu_bar
) ;
130 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
132 if ( m_currentChild
&& event
.GetActive() )
134 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
135 event
.SetEventObject( m_currentChild
);
136 m_currentChild
->GetEventHandler()->ProcessEvent(event
) ;
138 else if ( event
.GetActive() )
140 if ( m_frameMenuBar
!= NULL
)
142 m_frameMenuBar
->MacInstallMenuBar() ;
148 // Returns the active MDI child window
149 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
151 return m_currentChild
;
154 // Create the client window class (don't Create the window,
155 // just return a new class)
156 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
158 m_clientWindow
= new wxMDIClientWindow( this );
159 return m_clientWindow
;
162 // Responds to colour changes, and passes event on to children.
163 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
167 // Propagate the event to the non-top-level children
168 wxFrame::OnSysColourChanged(event
);
172 void wxMDIParentFrame::Cascade()
177 void wxMDIParentFrame::Tile()
182 void wxMDIParentFrame::ArrangeIcons()
187 void wxMDIParentFrame::ActivateNext()
192 void wxMDIParentFrame::ActivatePrevious()
199 wxMDIChildFrame::wxMDIChildFrame()
203 void wxMDIChildFrame::Init()
207 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
209 const wxString
& title
,
213 const wxString
& name
)
220 m_windowId
= (int)NewControlId();
222 if (parent
) parent
->AddChild(this);
224 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
226 m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
227 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macWindowBackgroundTheme
, false ) ;
229 wxModelessWindows
.Append(this);
233 wxMDIChildFrame::~wxMDIChildFrame()
236 // already delete by DestroyChildren()
237 m_frameToolBar
= NULL
;
238 m_frameStatusBar
= NULL
;
241 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
243 return wxFrame::SetMenuBar( menu_bar
) ;
247 void wxMDIChildFrame::Maximize()
249 wxFrame::Maximize() ;
252 void wxMDIChildFrame::Restore()
257 void wxMDIChildFrame::Activate()
261 //-----------------------------------------------------------------------------
263 //-----------------------------------------------------------------------------
265 wxMDIClientWindow::wxMDIClientWindow()
269 wxMDIClientWindow::~wxMDIClientWindow()
274 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
277 m_windowId
= (int)NewControlId();
281 parent
->AddChild(this);
283 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
285 wxModelessWindows
.Append(this);
289 // Get size *available for subwindows* i.e. excluding menu bar.
290 void wxMDIClientWindow::DoGetClientSize(int *x
, int *y
) const
292 wxDisplaySize( x
, y
) ;
295 // Explicitly call default scroll behaviour
296 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)