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