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 #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_SIZE(wxMDIParentFrame::OnSize
)
31 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
32 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
35 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
36 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
41 static const int IDM_WINDOWTILE
= 4001;
42 static const int IDM_WINDOWTILEHOR
= 4001;
43 static const int IDM_WINDOWCASCADE
= 4002;
44 static const int IDM_WINDOWICONS
= 4003;
45 static const int IDM_WINDOWNEXT
= 4004;
46 static const int IDM_WINDOWTILEVERT
= 4005;
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 // Get size *available for subwindows* i.e. excluding menu bar.
126 void wxMDIParentFrame::DoGetClientSize(int *x
, int *y
) const
128 wxDisplaySize( x
, y
) ;
131 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
133 wxFrame::SetMenuBar( menu_bar
) ;
136 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
138 #if wxUSE_CONSTRAINTS
145 GetClientSize(&width
, &height
);
147 if ( GetClientWindow() )
148 GetClientWindow()->SetSize(x
, y
, width
, height
);
151 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
153 if ( m_currentChild
&& event
.GetActive() )
155 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
156 event
.SetEventObject( m_currentChild
);
157 m_currentChild
->GetEventHandler()->ProcessEvent(event
) ;
159 else if ( event
.GetActive() )
161 if ( m_frameMenuBar
!= NULL
)
163 m_frameMenuBar
->MacInstallMenuBar() ;
169 // Returns the active MDI child window
170 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
172 return m_currentChild
;
175 // Create the client window class (don't Create the window,
176 // just return a new class)
177 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
179 m_clientWindow
= new wxMDIClientWindow( this );
180 return m_clientWindow
;
183 // Responds to colour changes, and passes event on to children.
184 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
188 // Propagate the event to the non-top-level children
189 wxFrame::OnSysColourChanged(event
);
193 void wxMDIParentFrame::Cascade()
198 void wxMDIParentFrame::Tile()
203 void wxMDIParentFrame::ArrangeIcons()
208 void wxMDIParentFrame::ActivateNext()
213 void wxMDIParentFrame::ActivatePrevious()
220 wxMDIChildFrame::wxMDIChildFrame()
224 void wxMDIChildFrame::Init()
228 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
230 const wxString
& title
,
234 const wxString
& name
)
241 m_windowId
= (int)NewControlId();
243 if (parent
) parent
->AddChild(this);
245 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
247 m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
248 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macWindowBackgroundTheme
, false ) ;
250 wxModelessWindows
.Append(this);
254 wxMDIChildFrame::~wxMDIChildFrame()
257 // already delete by DestroyChildren()
258 m_frameToolBar
= NULL
;
259 m_frameStatusBar
= NULL
;
262 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
264 return wxFrame::SetMenuBar( menu_bar
) ;
268 void wxMDIChildFrame::Maximize()
270 wxFrame::Maximize() ;
273 void wxMDIChildFrame::Restore()
278 void wxMDIChildFrame::Activate()
282 //-----------------------------------------------------------------------------
284 //-----------------------------------------------------------------------------
286 wxMDIClientWindow::wxMDIClientWindow()
290 wxMDIClientWindow::~wxMDIClientWindow()
295 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
298 m_windowId
= (int)NewControlId();
302 parent
->AddChild(this);
304 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
306 wxModelessWindows
.Append(this);
310 // Explicitly call default scroll behaviour
311 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)