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_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;
47 static const int IDM_WINDOWPREV
= 4006;
49 // This range gives a maximum of 500 MDI children. Should be enough :-)
50 static const int wxFIRST_MDI_CHILD
= 4100;
51 static const int wxLAST_MDI_CHILD
= 4600;
53 // Status border dimensions
54 static const int wxTHICK_LINE_BORDER
= 3;
58 wxMDIParentFrame::wxMDIParentFrame()
60 m_clientWindow
= NULL
;
61 m_currentChild
= NULL
;
62 m_windowMenu
= (wxMenu
*) NULL
;
63 m_parentFrameActive
= TRUE
;
66 bool wxMDIParentFrame::Create(wxWindow
*parent
,
68 const wxString
& title
,
74 m_clientWindow
= NULL
;
75 m_currentChild
= NULL
;
77 // this style can be used to prevent a window from having the standard MDI
79 if ( style
& wxFRAME_NO_WINDOW_MENU
)
81 m_windowMenu
= (wxMenu
*)NULL
;
82 style
-= wxFRAME_NO_WINDOW_MENU
;
84 else // normal case: we have the window menu, so construct it
86 m_windowMenu
= new wxMenu
;
88 m_windowMenu
->Append(IDM_WINDOWCASCADE
, wxT("&Cascade"));
89 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, wxT("Tile &Horizontally"));
90 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, wxT("Tile &Vertically"));
91 m_windowMenu
->AppendSeparator();
92 m_windowMenu
->Append(IDM_WINDOWICONS
, wxT("&Arrange Icons"));
93 m_windowMenu
->Append(IDM_WINDOWNEXT
, wxT("&Next"));
96 wxFrame::Create( parent
, id
, title
, wxPoint( 2000 , 2000 ) , size
, style
, name
) ;
97 m_parentFrameActive
= TRUE
;
104 wxMDIParentFrame::~wxMDIParentFrame()
107 // already delete by DestroyChildren()
108 m_frameToolBar
= NULL
;
109 m_frameStatusBar
= NULL
;
110 m_clientWindow
= NULL
;
115 m_windowMenu
= (wxMenu
*) NULL
;
118 if ( m_clientWindow
)
120 delete m_clientWindow
;
121 m_clientWindow
= NULL
;
126 // Get size *available for subwindows* i.e. excluding menu bar.
127 void wxMDIParentFrame::DoGetClientSize(int *x
, int *y
) const
129 wxDisplaySize( x
, y
) ;
132 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
134 wxFrame::SetMenuBar( menu_bar
) ;
137 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
139 #if wxUSE_CONSTRAINTS
146 GetClientSize(&width
, &height
);
148 if ( GetClientWindow() )
149 GetClientWindow()->SetSize(x
, y
, width
, height
);
152 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
154 if ( m_currentChild
&& event
.GetActive() )
156 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
157 event
.SetEventObject( m_currentChild
);
158 m_currentChild
->GetEventHandler()->ProcessEvent(event
) ;
160 else if ( event
.GetActive() )
162 if ( m_frameMenuBar
!= NULL
)
164 m_frameMenuBar
->MacInstallMenuBar() ;
170 // Returns the active MDI child window
171 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
173 return m_currentChild
;
176 // Create the client window class (don't Create the window,
177 // just return a new class)
178 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
180 m_clientWindow
= new wxMDIClientWindow( this );
181 return m_clientWindow
;
184 // Responds to colour changes, and passes event on to children.
185 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
189 // Propagate the event to the non-top-level children
190 wxFrame::OnSysColourChanged(event
);
194 void wxMDIParentFrame::Cascade()
199 void wxMDIParentFrame::Tile()
204 void wxMDIParentFrame::ArrangeIcons()
209 void wxMDIParentFrame::ActivateNext()
214 void wxMDIParentFrame::ActivatePrevious()
221 wxMDIChildFrame::wxMDIChildFrame()
225 void wxMDIChildFrame::Init()
229 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
231 const wxString
& title
,
235 const wxString
& name
)
242 m_windowId
= (int)NewControlId();
244 if (parent
) parent
->AddChild(this);
246 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
248 m_macWindowBackgroundTheme
= kThemeBrushDocumentWindowBackground
;
249 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macWindowBackgroundTheme
, false ) ;
251 wxModelessWindows
.Append(this);
255 wxMDIChildFrame::~wxMDIChildFrame()
258 // already delete by DestroyChildren()
259 m_frameToolBar
= NULL
;
260 m_frameStatusBar
= NULL
;
263 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menu_bar
)
265 return wxFrame::SetMenuBar( menu_bar
) ;
269 void wxMDIChildFrame::Maximize()
271 wxFrame::Maximize() ;
274 void wxMDIChildFrame::Restore()
279 void wxMDIChildFrame::Activate()
283 //-----------------------------------------------------------------------------
285 //-----------------------------------------------------------------------------
287 wxMDIClientWindow::wxMDIClientWindow()
291 wxMDIClientWindow::~wxMDIClientWindow()
296 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
299 m_windowId
= (int)NewControlId();
303 parent
->AddChild(this);
305 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
307 wxModelessWindows
.Append(this);
311 // Explicitly call default scroll behaviour
312 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)