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