]> git.saurik.com Git - wxWidgets.git/blame - src/mac/mdi.cpp
compilation fix for Mac and reformatted the code
[wxWidgets.git] / src / mac / mdi.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: mdi.cpp
3// Purpose: MDI classes
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "mdi.h"
14#endif
15
16#include "wx/mdi.h"
17#include "wx/menu.h"
18#include "wx/settings.h"
19
76a5e5d2
SC
20#include "wx/mac/private.h"
21
fe08e597 22extern wxWindowList wxModelessWindows;
e9576ca5 23
2f1ae414 24#if !USE_SHARED_LIBRARY
e9576ca5
SC
25IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
26IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
27IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
28
29BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
30 EVT_SIZE(wxMDIParentFrame::OnSize)
31 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
32 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
33END_EVENT_TABLE()
34
35BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
36 EVT_SCROLL(wxMDIClientWindow::OnScroll)
37END_EVENT_TABLE()
38
2f1ae414 39#endif
e9576ca5 40
0a67a93b
SC
41static const int IDM_WINDOWTILE = 4001;
42static const int IDM_WINDOWTILEHOR = 4001;
43static const int IDM_WINDOWCASCADE = 4002;
44static const int IDM_WINDOWICONS = 4003;
45static const int IDM_WINDOWNEXT = 4004;
46static const int IDM_WINDOWTILEVERT = 4005;
4f3b37fd 47static const int IDM_WINDOWPREV = 4006;
0a67a93b
SC
48
49// This range gives a maximum of 500 MDI children. Should be enough :-)
50static const int wxFIRST_MDI_CHILD = 4100;
51static const int wxLAST_MDI_CHILD = 4600;
52
53// Status border dimensions
54static const int wxTHICK_LINE_BORDER = 3;
55
e9576ca5
SC
56// Parent frame
57
58wxMDIParentFrame::wxMDIParentFrame()
59{
0a67a93b
SC
60 m_clientWindow = NULL;
61 m_currentChild = NULL;
62 m_windowMenu = (wxMenu*) NULL;
63 m_parentFrameActive = TRUE;
e9576ca5
SC
64}
65
66bool wxMDIParentFrame::Create(wxWindow *parent,
67 wxWindowID id,
68 const wxString& title,
69 const wxPoint& pos,
70 const wxSize& size,
71 long style,
72 const wxString& name)
73{
e40298d5
JS
74 m_clientWindow = NULL;
75 m_currentChild = NULL;
76
77 // this style can be used to prevent a window from having the standard MDI
78 // "Window" menu
79 if ( style & wxFRAME_NO_WINDOW_MENU )
80 {
81 m_windowMenu = (wxMenu *)NULL;
82 style -= wxFRAME_NO_WINDOW_MENU ;
83 }
84 else // normal case: we have the window menu, so construct it
85 {
86 m_windowMenu = new wxMenu;
0a67a93b 87
e40298d5
JS
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"));
94 }
95
96 wxFrame::Create( parent , id , title , wxPoint( 2000 , 2000 ) , size , style , name ) ;
97 m_parentFrameActive = TRUE;
98
99 OnCreateClient();
100
e9576ca5
SC
101 return TRUE;
102}
103
104wxMDIParentFrame::~wxMDIParentFrame()
105{
0a67a93b
SC
106 DestroyChildren();
107 // already delete by DestroyChildren()
108 m_frameToolBar = NULL;
109 m_frameStatusBar = NULL;
110 m_clientWindow = NULL ;
e40298d5 111
0a67a93b
SC
112 if (m_windowMenu)
113 {
114 delete m_windowMenu;
115 m_windowMenu = (wxMenu*) NULL;
116 }
e40298d5 117
0a67a93b
SC
118 if ( m_clientWindow )
119 {
120 delete m_clientWindow;
121 m_clientWindow = NULL ;
122 }
e9576ca5
SC
123}
124
0a67a93b 125
e9576ca5 126// Get size *available for subwindows* i.e. excluding menu bar.
7c74e7fe 127void wxMDIParentFrame::DoGetClientSize(int *x, int *y) const
e9576ca5 128{
e40298d5 129 wxDisplaySize( x , y ) ;
e9576ca5
SC
130}
131
132void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
133{
e40298d5 134 wxFrame::SetMenuBar( menu_bar ) ;
e9576ca5
SC
135}
136
137void wxMDIParentFrame::OnSize(wxSizeEvent& event)
138{
139#if wxUSE_CONSTRAINTS
140 if (GetAutoLayout())
e40298d5 141 Layout();
e9576ca5
SC
142#endif
143 int x = 0;
144 int y = 0;
145 int width, height;
146 GetClientSize(&width, &height);
e40298d5 147
e9576ca5
SC
148 if ( GetClientWindow() )
149 GetClientWindow()->SetSize(x, y, width, height);
150}
151
152void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
153{
e40298d5
JS
154 if ( m_currentChild && event.GetActive() )
155 {
156 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId());
157 event.SetEventObject( m_currentChild );
158 m_currentChild->GetEventHandler()->ProcessEvent(event) ;
159 }
160 else if ( event.GetActive() )
161 {
162 if ( m_frameMenuBar != NULL )
163 {
164 m_frameMenuBar->MacInstallMenuBar() ;
165 }
166
167 }
e9576ca5
SC
168}
169
170// Returns the active MDI child window
171wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
172{
e40298d5 173 return m_currentChild ;
e9576ca5
SC
174}
175
176// Create the client window class (don't Create the window,
177// just return a new class)
178wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
179{
0a67a93b
SC
180 m_clientWindow = new wxMDIClientWindow( this );
181 return m_clientWindow;
e9576ca5
SC
182}
183
184// Responds to colour changes, and passes event on to children.
185void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
186{
187 // TODO
e40298d5 188
e9576ca5
SC
189 // Propagate the event to the non-top-level children
190 wxFrame::OnSysColourChanged(event);
191}
192
193// MDI operations
194void wxMDIParentFrame::Cascade()
195{
196 // TODO
197}
198
199void wxMDIParentFrame::Tile()
200{
201 // TODO
202}
203
204void wxMDIParentFrame::ArrangeIcons()
205{
206 // TODO
207}
208
209void wxMDIParentFrame::ActivateNext()
210{
211 // TODO
212}
213
214void wxMDIParentFrame::ActivatePrevious()
215{
216 // TODO
217}
218
219// Child frame
220
221wxMDIChildFrame::wxMDIChildFrame()
0a67a93b
SC
222{
223 Init() ;
224}
225void wxMDIChildFrame::Init()
e9576ca5
SC
226{
227}
228
229bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
e40298d5
JS
230 wxWindowID id,
231 const wxString& title,
232 const wxPoint& pos,
233 const wxSize& size,
234 long style,
235 const wxString& name)
e9576ca5
SC
236{
237 SetName(name);
e40298d5 238
e9576ca5
SC
239 if ( id > -1 )
240 m_windowId = id;
241 else
242 m_windowId = (int)NewControlId();
e40298d5 243
e9576ca5 244 if (parent) parent->AddChild(this);
e40298d5
JS
245
246 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
247
248 m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
249 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
250
e9576ca5
SC
251 wxModelessWindows.Append(this);
252 return FALSE;
253}
254
255wxMDIChildFrame::~wxMDIChildFrame()
256{
0a67a93b
SC
257 DestroyChildren();
258 // already delete by DestroyChildren()
259 m_frameToolBar = NULL;
260 m_frameStatusBar = NULL;
e9576ca5
SC
261}
262
263void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
264{
e40298d5 265 return wxFrame::SetMenuBar( menu_bar ) ;
e9576ca5
SC
266}
267
268// MDI operations
269void wxMDIChildFrame::Maximize()
270{
0a67a93b 271 wxFrame::Maximize() ;
e9576ca5
SC
272}
273
274void wxMDIChildFrame::Restore()
275{
0a67a93b 276 wxFrame::Restore() ;
e9576ca5
SC
277}
278
279void wxMDIChildFrame::Activate()
280{
e9576ca5
SC
281}
282
0a67a93b
SC
283//-----------------------------------------------------------------------------
284// wxMDIClientWindow
285//-----------------------------------------------------------------------------
e9576ca5
SC
286
287wxMDIClientWindow::wxMDIClientWindow()
288{
289}
290
291wxMDIClientWindow::~wxMDIClientWindow()
292{
0a67a93b 293 DestroyChildren();
e9576ca5
SC
294}
295
296bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
297{
e40298d5 298
0a67a93b 299 m_windowId = (int)NewControlId();
e40298d5 300
0a67a93b
SC
301 if ( parent )
302 {
e40298d5 303 parent->AddChild(this);
0a67a93b 304 }
a756f210 305 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
e40298d5 306
0a67a93b
SC
307 wxModelessWindows.Append(this);
308 return TRUE;
e9576ca5
SC
309}
310
311// Explicitly call default scroll behaviour
312void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
313{
e9576ca5
SC
314}
315