]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
e766c8a9 | 3 | // Purpose: wxFrameMac |
e9576ca5 SC |
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 "frame.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/frame.h" | |
03e11df5 | 17 | #include "wx/statusbr.h" |
e9576ca5 SC |
18 | #include "wx/toolbar.h" |
19 | #include "wx/menuitem.h" | |
20 | #include "wx/menu.h" | |
21 | #include "wx/dcclient.h" | |
22 | #include "wx/dialog.h" | |
23 | #include "wx/settings.h" | |
24 | #include "wx/app.h" | |
25 | ||
519cb848 SC |
26 | #include <wx/mac/uma.h> |
27 | ||
e9576ca5 SC |
28 | extern wxList wxModelessWindows; |
29 | extern wxList wxPendingDelete; | |
30 | ||
2f1ae414 | 31 | #if !USE_SHARED_LIBRARY |
e766c8a9 SC |
32 | BEGIN_EVENT_TABLE(wxFrameMac, wxFrameBase) |
33 | // EVT_SIZE(wxFrameMac::OnSize) | |
34 | EVT_ACTIVATE(wxFrameMac::OnActivate) | |
35 | // EVT_MENU_HIGHLIGHT_ALL(wxFrameMac::OnMenuHighlight) | |
36 | EVT_SYS_COLOUR_CHANGED(wxFrameMac::OnSysColourChanged) | |
37 | // EVT_IDLE(wxFrameMac::OnIdle) | |
38 | // EVT_CLOSE(wxFrameMac::OnCloseWindow) | |
e9576ca5 SC |
39 | END_EVENT_TABLE() |
40 | ||
e766c8a9 SC |
41 | IMPLEMENT_DYNAMIC_CLASS(wxFrameMac, wxWindow) |
42 | #endif | |
43 | #ifndef __WXUNIVERSAL__ | |
44 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxFrameMac) | |
2f1ae414 | 45 | #endif |
e9576ca5 SC |
46 | |
47 | #if wxUSE_NATIVE_STATUSBAR | |
e766c8a9 | 48 | bool wxFrameMac::m_useNativeStatusBar = TRUE; |
e9576ca5 | 49 | #else |
e766c8a9 | 50 | bool wxFrameMac::m_useNativeStatusBar = FALSE; |
e9576ca5 SC |
51 | #endif |
52 | ||
2f1ae414 SC |
53 | #define WX_MAC_STATUSBAR_HEIGHT 15 |
54 | // ---------------------------------------------------------------------------- | |
55 | // creation/destruction | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
e766c8a9 | 58 | void wxFrameMac::Init() |
e9576ca5 | 59 | { |
0a67a93b SC |
60 | m_frameMenuBar = NULL; |
61 | ||
62 | #if wxUSE_TOOLBAR | |
63 | m_frameToolBar = NULL ; | |
64 | #endif | |
65 | m_frameStatusBar = NULL; | |
66 | m_winLastFocused = NULL ; | |
67 | ||
2f1ae414 SC |
68 | m_iconized = FALSE; |
69 | ||
70 | #if wxUSE_TOOLTIPS | |
71 | m_hwndToolTip = 0; | |
519cb848 | 72 | #endif |
2f1ae414 | 73 | } |
e7549107 | 74 | |
e766c8a9 | 75 | wxPoint wxFrameMac::GetClientAreaOrigin() const |
2f1ae414 SC |
76 | { |
77 | // on mac we are at position -1,-1 with the control | |
78 | wxPoint pt(0, 0); | |
79 | ||
80 | #if wxUSE_TOOLBAR | |
81 | if ( GetToolBar() ) | |
82 | { | |
83 | int w, h; | |
84 | GetToolBar()->GetSize(& w, & h); | |
85 | ||
86 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
87 | { | |
88 | pt.x += w - 1; | |
89 | } | |
90 | else | |
91 | { | |
92 | pt.y += h - 1 ; | |
93 | } | |
94 | } | |
95 | #endif // wxUSE_TOOLBAR | |
96 | ||
97 | return pt; | |
e9576ca5 SC |
98 | } |
99 | ||
e766c8a9 | 100 | bool wxFrameMac::Create(wxWindow *parent, |
e9576ca5 SC |
101 | wxWindowID id, |
102 | const wxString& title, | |
103 | const wxPoint& pos, | |
104 | const wxSize& size, | |
105 | long style, | |
106 | const wxString& name) | |
107 | { | |
e9576ca5 SC |
108 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); |
109 | ||
110 | if ( id > -1 ) | |
111 | m_windowId = id; | |
112 | else | |
113 | m_windowId = (int)NewControlId(); | |
114 | ||
115 | if (parent) parent->AddChild(this); | |
116 | ||
2f1ae414 SC |
117 | if (!parent) |
118 | wxTopLevelWindows.Append(this); | |
519cb848 | 119 | |
2f1ae414 SC |
120 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
121 | ||
122 | m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; | |
519cb848 | 123 | |
2f1ae414 | 124 | wxModelessWindows.Append(this); |
519cb848 | 125 | |
519cb848 | 126 | return TRUE; |
e9576ca5 SC |
127 | } |
128 | ||
e766c8a9 | 129 | wxFrameMac::~wxFrameMac() |
e9576ca5 | 130 | { |
2f1ae414 | 131 | m_isBeingDeleted = TRUE; |
e9576ca5 SC |
132 | wxTopLevelWindows.DeleteObject(this); |
133 | ||
2f1ae414 | 134 | DeleteAllBars(); |
e9576ca5 SC |
135 | |
136 | /* Check if it's the last top-level window */ | |
137 | ||
138 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
139 | { | |
140 | wxTheApp->SetTopWindow(NULL); | |
141 | ||
142 | if (wxTheApp->GetExitOnFrameDelete()) | |
143 | { | |
519cb848 | 144 | wxTheApp->ExitMainLoop() ; |
e9576ca5 SC |
145 | } |
146 | } | |
147 | ||
148 | wxModelessWindows.DeleteObject(this); | |
149 | } | |
150 | ||
e9576ca5 | 151 | |
e766c8a9 | 152 | bool wxFrameMac::Enable(bool enable) |
e9576ca5 | 153 | { |
2f1ae414 SC |
154 | if ( !wxWindow::Enable(enable) ) |
155 | return FALSE; | |
e9576ca5 | 156 | |
2f1ae414 SC |
157 | if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) |
158 | { | |
159 | for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i ) | |
160 | { | |
161 | m_frameMenuBar->EnableTop( i , enable ) ; | |
162 | } | |
163 | } | |
164 | ||
165 | return TRUE; | |
166 | } | |
e9576ca5 | 167 | // Equivalent to maximize/restore in Windows |
e766c8a9 | 168 | void wxFrameMac::Maximize(bool maximize) |
e9576ca5 SC |
169 | { |
170 | // TODO | |
171 | } | |
172 | ||
e766c8a9 | 173 | bool wxFrameMac::IsIconized() const |
e9576ca5 SC |
174 | { |
175 | // TODO | |
176 | return FALSE; | |
177 | } | |
178 | ||
e766c8a9 | 179 | void wxFrameMac::Iconize(bool iconize) |
2f1ae414 SC |
180 | { |
181 | // TODO | |
182 | } | |
183 | ||
e9576ca5 | 184 | // Is the frame maximized? |
e766c8a9 | 185 | bool wxFrameMac::IsMaximized(void) const |
e9576ca5 SC |
186 | { |
187 | // TODO | |
188 | return FALSE; | |
189 | } | |
190 | ||
e766c8a9 | 191 | void wxFrameMac::Restore() |
2f1ae414 SC |
192 | { |
193 | // TODO | |
194 | } | |
195 | ||
e766c8a9 | 196 | void wxFrameMac::SetIcon(const wxIcon& icon) |
e9576ca5 | 197 | { |
2f1ae414 | 198 | wxFrameBase::SetIcon(icon); |
e9576ca5 SC |
199 | } |
200 | ||
e766c8a9 | 201 | wxStatusBar *wxFrameMac::OnCreateStatusBar(int number, long style, wxWindowID id, |
e9576ca5 SC |
202 | const wxString& name) |
203 | { | |
204 | wxStatusBar *statusBar = NULL; | |
205 | ||
5b781a67 SC |
206 | statusBar = new wxStatusBar(this, id, |
207 | style, name); | |
208 | statusBar->SetSize( 100 , 15 ) ; | |
e9576ca5 SC |
209 | statusBar->SetFieldsCount(number); |
210 | return statusBar; | |
211 | } | |
212 | ||
e766c8a9 | 213 | void wxFrameMac::PositionStatusBar() |
e9576ca5 | 214 | { |
519cb848 SC |
215 | if (m_frameStatusBar ) |
216 | { | |
e9576ca5 SC |
217 | int w, h; |
218 | GetClientSize(&w, &h); | |
219 | int sw, sh; | |
220 | m_frameStatusBar->GetSize(&sw, &sh); | |
221 | ||
222 | // Since we wish the status bar to be directly under the client area, | |
223 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
5b781a67 | 224 | m_frameStatusBar->SetSize(0, h, w, sh); |
519cb848 | 225 | } |
e9576ca5 SC |
226 | } |
227 | ||
e766c8a9 | 228 | void wxFrameMac::SetMenuBar(wxMenuBar *menuBar) |
e9576ca5 SC |
229 | { |
230 | if (!menuBar) | |
231 | { | |
e9576ca5 SC |
232 | return; |
233 | } | |
234 | ||
235 | m_frameMenuBar = menuBar; | |
41f38f4d | 236 | // m_frameMenuBar->MacInstallMenuBar() ; |
e766c8a9 | 237 | m_frameMenuBar->Attach((wxFrame *)this); |
e9576ca5 SC |
238 | } |
239 | ||
e9576ca5 SC |
240 | |
241 | // Responds to colour changes, and passes event on to children. | |
e766c8a9 | 242 | void wxFrameMac::OnSysColourChanged(wxSysColourChangedEvent& event) |
e9576ca5 SC |
243 | { |
244 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
245 | Refresh(); | |
246 | ||
247 | if ( m_frameStatusBar ) | |
248 | { | |
249 | wxSysColourChangedEvent event2; | |
250 | event2.SetEventObject( m_frameStatusBar ); | |
251 | m_frameStatusBar->ProcessEvent(event2); | |
252 | } | |
253 | ||
254 | // Propagate the event to the non-top-level children | |
255 | wxWindow::OnSysColourChanged(event); | |
256 | } | |
257 | ||
e9576ca5 SC |
258 | |
259 | // Default activation behaviour - set the focus for the first child | |
260 | // subwindow found. | |
e766c8a9 | 261 | void wxFrameMac::OnActivate(wxActivateEvent& event) |
e9576ca5 | 262 | { |
2f1ae414 | 263 | if ( !event.GetActive() ) |
e9576ca5 | 264 | { |
7810c95b SC |
265 | // remember the last focused child |
266 | m_winLastFocused = FindFocus(); | |
267 | while ( m_winLastFocused ) | |
268 | { | |
269 | if ( GetChildren().Find(m_winLastFocused) ) | |
270 | break; | |
271 | ||
272 | m_winLastFocused = m_winLastFocused->GetParent(); | |
273 | } | |
274 | ||
2f1ae414 | 275 | event.Skip(); |
e9576ca5 | 276 | } |
7810c95b SC |
277 | else |
278 | { | |
279 | /* | |
2f1ae414 SC |
280 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
281 | node; | |
282 | node = node->GetNext() ) | |
e9576ca5 | 283 | { |
2f1ae414 SC |
284 | // FIXME all this is totally bogus - we need to do the same as wxPanel, |
285 | // but how to do it without duplicating the code? | |
e9576ca5 | 286 | |
2f1ae414 SC |
287 | // restore focus |
288 | wxWindow *child = node->GetData(); | |
e9576ca5 | 289 | |
7810c95b | 290 | if ( !child->IsTopLevel() && child->AcceptsFocus() |
519cb848 | 291 | #if wxUSE_TOOLBAR |
2f1ae414 SC |
292 | && !wxDynamicCast(child, wxToolBar) |
293 | #endif // wxUSE_TOOLBAR | |
294 | #if wxUSE_STATUSBAR | |
295 | && !wxDynamicCast(child, wxStatusBar) | |
296 | #endif // wxUSE_STATUSBAR | |
297 | ) | |
e9576ca5 | 298 | { |
2f1ae414 | 299 | child->SetFocus(); |
41f38f4d | 300 | break; |
e9576ca5 SC |
301 | } |
302 | } | |
7810c95b SC |
303 | */ |
304 | wxSetFocusToChild(this, &m_winLastFocused); | |
305 | ||
306 | if ( m_frameMenuBar != NULL ) | |
307 | { | |
308 | m_frameMenuBar->MacInstallMenuBar() ; | |
309 | } | |
310 | } | |
e9576ca5 SC |
311 | } |
312 | ||
e766c8a9 | 313 | void wxFrameMac::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 314 | { |
7c74e7fe | 315 | wxWindow::DoGetClientSize( x , y ) ; |
519cb848 | 316 | |
2f1ae414 | 317 | #if wxUSE_STATUSBAR |
519cb848 SC |
318 | if ( GetStatusBar() ) |
319 | { | |
320 | int statusX, statusY; | |
321 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
5b781a67 | 322 | *y -= statusY; |
519cb848 | 323 | } |
2f1ae414 | 324 | #endif // wxUSE_STATUSBAR |
519cb848 SC |
325 | |
326 | wxPoint pt(GetClientAreaOrigin()); | |
327 | *y -= pt.y; | |
328 | *x -= pt.x; | |
e9576ca5 SC |
329 | } |
330 | ||
e766c8a9 | 331 | void wxFrameMac::DoSetClientSize(int clientwidth, int clientheight) |
e9576ca5 | 332 | { |
519cb848 SC |
333 | int currentclientwidth , currentclientheight ; |
334 | int currentwidth , currentheight ; | |
335 | ||
336 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
337 | GetSize( ¤twidth , ¤theight ) ; | |
338 | ||
339 | // find the current client size | |
340 | ||
341 | // Find the difference between the entire window (title bar and all) | |
342 | // and the client area; add this to the new client size to move the | |
343 | // window | |
344 | ||
345 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , | |
346 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
e9576ca5 SC |
347 | } |
348 | ||
519cb848 SC |
349 | |
350 | #if wxUSE_TOOLBAR | |
e766c8a9 | 351 | wxToolBar* wxFrameMac::CreateToolBar(long style, wxWindowID id, const wxString& name) |
e9576ca5 | 352 | { |
2f1ae414 | 353 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
e9576ca5 | 354 | { |
e9576ca5 | 355 | PositionToolBar(); |
e9576ca5 | 356 | } |
e9576ca5 | 357 | |
2f1ae414 | 358 | return m_frameToolBar; |
e9576ca5 SC |
359 | } |
360 | ||
e766c8a9 | 361 | void wxFrameMac::PositionToolBar() |
e9576ca5 SC |
362 | { |
363 | int cw, ch; | |
364 | ||
2f1ae414 SC |
365 | cw = m_width ; |
366 | ch = m_height ; | |
e9576ca5 SC |
367 | |
368 | if ( GetStatusBar() ) | |
369 | { | |
370 | int statusX, statusY; | |
371 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
372 | ch -= statusY; | |
373 | } | |
374 | ||
375 | if (GetToolBar()) | |
376 | { | |
377 | int tw, th; | |
378 | GetToolBar()->GetSize(& tw, & th); | |
379 | ||
380 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
381 | { | |
382 | // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS | |
383 | // means, pretend we don't have toolbar/status bar, so we | |
384 | // have the original client size. | |
2f1ae414 | 385 | GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); |
e9576ca5 SC |
386 | } |
387 | else | |
388 | { | |
389 | // Use the 'real' position | |
2f1ae414 | 390 | GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); |
e9576ca5 SC |
391 | } |
392 | } | |
393 | } | |
519cb848 | 394 | #endif |