1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mdi.h"
18 #include "wx/settings.h"
20 extern wxList wxModelessWindows
;
22 #if !USE_SHARED_LIBRARY
23 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
24 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
25 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
27 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
28 EVT_SIZE(wxMDIParentFrame::OnSize
)
29 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
30 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
33 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
34 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
39 static const int IDM_WINDOWTILE
= 4001;
40 static const int IDM_WINDOWTILEHOR
= 4001;
41 static const int IDM_WINDOWCASCADE
= 4002;
42 static const int IDM_WINDOWICONS
= 4003;
43 static const int IDM_WINDOWNEXT
= 4004;
44 static const int IDM_WINDOWTILEVERT
= 4005;
46 // This range gives a maximum of 500 MDI children. Should be enough :-)
47 static const int wxFIRST_MDI_CHILD
= 4100;
48 static const int wxLAST_MDI_CHILD
= 4600;
50 // Status border dimensions
51 static const int wxTHICK_LINE_BORDER
= 3;
55 wxMDIParentFrame::wxMDIParentFrame()
57 m_clientWindow
= NULL
;
58 m_currentChild
= NULL
;
59 m_windowMenu
= (wxMenu
*) NULL
;
60 m_parentFrameActive
= TRUE
;
63 bool wxMDIParentFrame::Create(wxWindow
*parent
,
65 const wxString
& title
,
71 m_clientWindow
= NULL
;
72 m_currentChild
= NULL
;
74 // this style can be used to prevent a window from having the standard MDI
76 if ( style
& wxFRAME_NO_WINDOW_MENU
)
78 m_windowMenu
= (wxMenu
*)NULL
;
79 style
-= wxFRAME_NO_WINDOW_MENU
;
81 else // normal case: we have the window menu, so construct it
83 m_windowMenu
= new wxMenu
;
85 m_windowMenu
->Append(IDM_WINDOWCASCADE
, wxT("&Cascade"));
86 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, wxT("Tile &Horizontally"));
87 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, wxT("Tile &Vertically"));
88 m_windowMenu
->AppendSeparator();
89 m_windowMenu
->Append(IDM_WINDOWICONS
, wxT("&Arrange Icons"));
90 m_windowMenu
->Append(IDM_WINDOWNEXT
, wxT("&Next"));
93 wxFrame::Create( parent
, id
, title
, wxPoint( 2000 , 2000 ) , size
, style
, name
) ;
94 m_parentFrameActive
= TRUE
;
101 wxMDIParentFrame::~wxMDIParentFrame()
104 // already delete by DestroyChildren()
105 m_frameToolBar
= NULL
;
106 m_frameStatusBar
= NULL
;
107 m_clientWindow
= NULL
;
112 m_windowMenu
= (wxMenu
*) NULL
;
115 if ( m_clientWindow
)
117 delete m_clientWindow
;
118 m_clientWindow
= NULL
;
123 // Get size *available for subwindows* i.e. excluding menu bar.
124 void wxMDIParentFrame::DoGetClientSize(int *x
, int *y
) const
126 wxDisplaySize( x
, y
) ;
129 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
131 wxFrame::SetMenuBar( menu_bar
) ;
134 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
136 #if wxUSE_CONSTRAINTS
143 GetClientSize(&width
, &height
);
145 if ( GetClientWindow() )
146 GetClientWindow()->SetSize(x
, y
, width
, height
);
149 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
151 if ( m_currentChild
&& event
.GetActive() )
153 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
154 event
.SetEventObject( m_currentChild
);
155 m_currentChild
->GetEventHandler()->ProcessEvent(event
) ;
157 else if ( event
.GetActive() )
159 if ( m_frameMenuBar
!= NULL
)
161 m_frameMenuBar
->MacInstallMenuBar() ;
167 // Returns the active MDI child window
168 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
170 return m_currentChild
;
173 // Create the client window class (don't Create the window,
174 // just return a new class)
175 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
177 m_clientWindow
= new wxMDIClientWindow( this );
178 return m_clientWindow
;
181 // Responds to colour changes, and passes event on to children.
182 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
186 // Propagate the event to the non-top-level children
187 wxFrame::OnSysColourChanged(event
);
191 void wxMDIParentFrame::Cascade()
196 void wxMDIParentFrame::Tile()
201 void wxMDIParentFrame::ArrangeIcons()
206 void wxMDIParentFrame::ActivateNext()
211 void wxMDIParentFrame::ActivatePrevious()
218 wxMDIChildFrame::wxMDIChildFrame()
222 void wxMDIChildFrame::Init()
226 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
228 const wxString
& title
,
232 const wxString
& name
)
239 m_windowId
= (int)NewControlId();
241 if (parent
) parent
->AddChild(this);
243 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
245 m_macWindowData
->m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
247 wxModelessWindows
.Append(this);
251 wxMDIChildFrame::~wxMDIChildFrame()
254 // already delete by DestroyChildren()
255 m_frameToolBar
= NULL
;
256 m_frameStatusBar
= NULL
;
259 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
261 return wxFrame::SetMenuBar( menu_bar
) ;
265 void wxMDIChildFrame::Maximize()
267 wxFrame::Maximize() ;
270 void wxMDIChildFrame::Restore()
275 void wxMDIChildFrame::Activate()
279 //-----------------------------------------------------------------------------
281 //-----------------------------------------------------------------------------
283 wxMDIClientWindow::wxMDIClientWindow()
287 wxMDIClientWindow::~wxMDIClientWindow()
292 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
295 m_windowId
= (int)NewControlId();
299 parent
->AddChild(this);
301 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
303 wxModelessWindows
.Append(this);
307 // Explicitly call default scroll behaviour
308 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)