]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
670f9935 | 2 | // Name: src/mac/carbon/frame.cpp |
0d53fc34 | 3 | // Purpose: wxFrame |
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 |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 | 14 | #include "wx/frame.h" |
670f9935 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/app.h" | |
ed4b0fdc | 18 | #include "wx/dcclient.h" |
3b3dc801 | 19 | #include "wx/menu.h" |
fdf565fe | 20 | #include "wx/dialog.h" |
9eddec69 | 21 | #include "wx/settings.h" |
4e3e485b | 22 | #include "wx/toolbar.h" |
3304646d | 23 | #include "wx/statusbr.h" |
670f9935 WS |
24 | #endif // WX_PRECOMP |
25 | ||
e9576ca5 | 26 | #include "wx/menuitem.h" |
e9576ca5 | 27 | |
d497dca4 | 28 | #include "wx/mac/uma.h" |
519cb848 | 29 | |
fe08e597 | 30 | extern wxWindowList wxModelessWindows; |
e9576ca5 | 31 | |
0d53fc34 VS |
32 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
33 | EVT_ACTIVATE(wxFrame::OnActivate) | |
34 | // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) | |
35 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
36 | // EVT_IDLE(wxFrame::OnIdle) | |
37 | // EVT_CLOSE(wxFrame::OnCloseWindow) | |
e9576ca5 SC |
38 | END_EVENT_TABLE() |
39 | ||
ac0fa9ef | 40 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
e9576ca5 | 41 | |
902725ee | 42 | #define WX_MAC_STATUSBAR_HEIGHT 18 |
7ad25aed | 43 | |
2f1ae414 SC |
44 | // ---------------------------------------------------------------------------- |
45 | // creation/destruction | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
0d53fc34 | 48 | void wxFrame::Init() |
e9576ca5 | 49 | { |
e40298d5 | 50 | m_frameMenuBar = NULL; |
7ad25aed DS |
51 | m_frameStatusBar = NULL; |
52 | m_winLastFocused = NULL; | |
902725ee | 53 | |
0a67a93b | 54 | #if wxUSE_TOOLBAR |
7ad25aed | 55 | m_frameToolBar = NULL; |
0a67a93b | 56 | #endif |
902725ee | 57 | |
2f1ae414 | 58 | #if wxUSE_TOOLTIPS |
7ad25aed DS |
59 | // NB: is this used anywhere? |
60 | m_hwndToolTip = NULL; | |
519cb848 | 61 | #endif |
7ad25aed DS |
62 | |
63 | m_iconized = false; | |
2f1ae414 | 64 | } |
e7549107 | 65 | |
0d53fc34 | 66 | bool wxFrame::Create(wxWindow *parent, |
e9576ca5 SC |
67 | wxWindowID id, |
68 | const wxString& title, | |
69 | const wxPoint& pos, | |
70 | const wxSize& size, | |
71 | long style, | |
72 | const wxString& name) | |
73 | { | |
902725ee | 74 | |
a15eb0a5 | 75 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
902725ee WS |
76 | return false; |
77 | ||
e40298d5 | 78 | wxModelessWindows.Append(this); |
902725ee WS |
79 | |
80 | return true; | |
e9576ca5 SC |
81 | } |
82 | ||
0d53fc34 | 83 | wxFrame::~wxFrame() |
e9576ca5 | 84 | { |
902725ee | 85 | m_isBeingDeleted = true; |
e40298d5 | 86 | DeleteAllBars(); |
e9576ca5 SC |
87 | } |
88 | ||
e56d2520 SC |
89 | // get the origin of the client area in the client coordinates |
90 | wxPoint wxFrame::GetClientAreaOrigin() const | |
91 | { | |
92 | wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin(); | |
7ad25aed | 93 | |
e56d2520 SC |
94 | #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) |
95 | wxToolBar *toolbar = GetToolBar(); | |
96 | if ( toolbar && toolbar->IsShown() ) | |
97 | { | |
98 | int w, h; | |
99 | toolbar->GetSize(&w, &h); | |
7ad25aed | 100 | |
e56d2520 SC |
101 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) |
102 | { | |
103 | pt.x += w; | |
104 | } | |
105 | else | |
106 | { | |
107 | #if !wxMAC_USE_NATIVE_TOOLBAR | |
108 | pt.y += h; | |
109 | #endif | |
110 | } | |
111 | } | |
7ad25aed | 112 | #endif |
be6068f6 | 113 | |
e56d2520 SC |
114 | return pt; |
115 | } | |
e9576ca5 | 116 | |
0d53fc34 | 117 | bool wxFrame::Enable(bool enable) |
e9576ca5 | 118 | { |
2f1ae414 | 119 | if ( !wxWindow::Enable(enable) ) |
902725ee | 120 | return false; |
e9576ca5 | 121 | |
e40298d5 JS |
122 | if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) |
123 | { | |
7ad25aed | 124 | int iMaxMenu = m_frameMenuBar->GetMenuCount(); |
e40298d5 JS |
125 | for ( int i = 0 ; i < iMaxMenu ; ++ i ) |
126 | { | |
127 | m_frameMenuBar->EnableTop( i , enable ) ; | |
128 | } | |
129 | } | |
2f1ae414 | 130 | |
902725ee | 131 | return true; |
2f1ae414 | 132 | } |
e9576ca5 | 133 | |
0d53fc34 | 134 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, |
e9576ca5 SC |
135 | const wxString& name) |
136 | { | |
7ad25aed | 137 | wxStatusBar *statusBar; |
e9576ca5 | 138 | |
7ad25aed | 139 | statusBar = new wxStatusBar(this, id, style, name); |
617bfeec | 140 | statusBar->SetSize(100, WX_MAC_STATUSBAR_HEIGHT); |
e9576ca5 | 141 | statusBar->SetFieldsCount(number); |
7ad25aed | 142 | |
e9576ca5 SC |
143 | return statusBar; |
144 | } | |
145 | ||
0d53fc34 | 146 | void wxFrame::PositionStatusBar() |
e9576ca5 | 147 | { |
f5d63a57 | 148 | if (m_frameStatusBar && m_frameStatusBar->IsShown() ) |
e40298d5 JS |
149 | { |
150 | int w, h; | |
151 | GetClientSize(&w, &h); | |
902725ee | 152 | |
e40298d5 JS |
153 | // Since we wish the status bar to be directly under the client area, |
154 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
f80ffb32 | 155 | m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT); |
e40298d5 | 156 | } |
e9576ca5 SC |
157 | } |
158 | ||
e9576ca5 | 159 | // Responds to colour changes, and passes event on to children. |
0d53fc34 | 160 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
e9576ca5 | 161 | { |
a756f210 | 162 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
e9576ca5 SC |
163 | Refresh(); |
164 | ||
165 | if ( m_frameStatusBar ) | |
166 | { | |
167 | wxSysColourChangedEvent event2; | |
7ad25aed | 168 | |
e9576ca5 SC |
169 | event2.SetEventObject( m_frameStatusBar ); |
170 | m_frameStatusBar->ProcessEvent(event2); | |
171 | } | |
172 | ||
173 | // Propagate the event to the non-top-level children | |
174 | wxWindow::OnSysColourChanged(event); | |
175 | } | |
176 | ||
e9576ca5 SC |
177 | // Default activation behaviour - set the focus for the first child |
178 | // subwindow found. | |
0d53fc34 | 179 | void wxFrame::OnActivate(wxActivateEvent& event) |
e9576ca5 | 180 | { |
2f1ae414 | 181 | if ( !event.GetActive() ) |
e9576ca5 | 182 | { |
a15eb0a5 | 183 | // remember the last focused child if it is our child |
7810c95b | 184 | m_winLastFocused = FindFocus(); |
a15eb0a5 SC |
185 | |
186 | // so we NULL it out if it's a child from some other frame | |
187 | wxWindow *win = m_winLastFocused; | |
188 | while ( win ) | |
7810c95b | 189 | { |
a15eb0a5 SC |
190 | if ( win->IsTopLevel() ) |
191 | { | |
192 | if ( win != this ) | |
a15eb0a5 | 193 | m_winLastFocused = NULL; |
a15eb0a5 | 194 | |
7810c95b | 195 | break; |
a15eb0a5 | 196 | } |
7810c95b | 197 | |
a15eb0a5 | 198 | win = win->GetParent(); |
7810c95b SC |
199 | } |
200 | ||
2f1ae414 | 201 | event.Skip(); |
e9576ca5 | 202 | } |
e40298d5 JS |
203 | else |
204 | { | |
a15eb0a5 | 205 | // restore focus to the child which was last focused |
7ad25aed DS |
206 | wxWindow *parent = m_winLastFocused |
207 | ? m_winLastFocused->GetParent() | |
208 | : NULL; | |
209 | ||
617bfeec | 210 | if (parent == NULL) |
a15eb0a5 | 211 | parent = this; |
a15eb0a5 | 212 | |
e40298d5 | 213 | wxSetFocusToChild(parent, &m_winLastFocused); |
7810c95b | 214 | |
7ad25aed | 215 | if (m_frameMenuBar != NULL) |
e40298d5 | 216 | { |
617bfeec | 217 | m_frameMenuBar->MacInstallMenuBar(); |
e40298d5 | 218 | } |
617bfeec | 219 | else |
2b5f62a0 | 220 | { |
617bfeec DS |
221 | wxFrame *tlf = wxDynamicCast( wxTheApp->GetTopWindow(), wxFrame ); |
222 | if (tlf != NULL) | |
223 | { | |
224 | // Trying top-level frame membar | |
225 | if (tlf->GetMenuBar()) | |
226 | tlf->GetMenuBar()->MacInstallMenuBar(); | |
227 | } | |
228 | } | |
e40298d5 | 229 | } |
e9576ca5 SC |
230 | } |
231 | ||
2b5f62a0 VZ |
232 | void wxFrame::DetachMenuBar() |
233 | { | |
234 | if ( m_frameMenuBar ) | |
2b5f62a0 | 235 | m_frameMenuBar->UnsetInvokingWindow(); |
2b5f62a0 VZ |
236 | |
237 | wxFrameBase::DetachMenuBar(); | |
238 | } | |
239 | ||
240 | void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) | |
241 | { | |
487eedb8 | 242 | wxFrame* tlf = wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame ); |
be6068f6 | 243 | bool makeCurrent = false; |
d059fe4a | 244 | |
d059fe4a | 245 | // if this is already the current menubar or we are the frontmost window |
487eedb8 | 246 | if ( (tlf == this) || (m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar()) ) |
be6068f6 DS |
247 | makeCurrent = true; |
248 | // or there is an app-level menubar like MDI | |
487eedb8 | 249 | else if ( tlf && (tlf->GetMenuBar() == NULL) && (((wxFrame*)wxTheApp->GetTopWindow()) == this) ) |
be6068f6 DS |
250 | makeCurrent = true; |
251 | ||
252 | wxFrameBase::AttachMenuBar( menuBar ); | |
2b5f62a0 VZ |
253 | |
254 | if (m_frameMenuBar) | |
d059fe4a | 255 | { |
2b5f62a0 | 256 | m_frameMenuBar->SetInvokingWindow( this ); |
d059fe4a | 257 | if (makeCurrent) |
be6068f6 | 258 | m_frameMenuBar->MacInstallMenuBar(); |
d059fe4a | 259 | } |
2b5f62a0 VZ |
260 | } |
261 | ||
0d53fc34 | 262 | void wxFrame::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 263 | { |
7ad25aed | 264 | wxTopLevelWindow::DoGetClientSize( x , y ); |
902725ee | 265 | |
2f1ae414 | 266 | #if wxUSE_STATUSBAR |
f5d63a57 | 267 | if ( GetStatusBar() && GetStatusBar()->IsShown() && y ) |
902725ee | 268 | *y -= WX_MAC_STATUSBAR_HEIGHT; |
7ad25aed | 269 | #endif |
902725ee | 270 | |
facd6764 SC |
271 | #if wxUSE_TOOLBAR |
272 | wxToolBar *toolbar = GetToolBar(); | |
273 | if ( toolbar && toolbar->IsShown() ) | |
274 | { | |
275 | int w, h; | |
276 | toolbar->GetSize(&w, &h); | |
277 | ||
278 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
279 | { | |
7ad25aed DS |
280 | if ( x ) |
281 | *x -= w; | |
facd6764 SC |
282 | } |
283 | else | |
284 | { | |
a85245b1 | 285 | #if !wxMAC_USE_NATIVE_TOOLBAR |
7ad25aed DS |
286 | if ( y ) |
287 | *y -= h; | |
a85245b1 | 288 | #endif |
facd6764 SC |
289 | } |
290 | } | |
7ad25aed | 291 | #endif |
e9576ca5 SC |
292 | } |
293 | ||
902725ee | 294 | bool wxFrame::MacIsChildOfClientArea( const wxWindow* child ) const |
e905b636 SC |
295 | { |
296 | #if wxUSE_STATUSBAR | |
297 | if ( child == GetStatusBar() ) | |
298 | return false ; | |
7ad25aed | 299 | #endif |
e905b636 SC |
300 | |
301 | #if wxUSE_TOOLBAR | |
302 | if ( child == GetToolBar() ) | |
303 | return false ; | |
7ad25aed | 304 | #endif |
e905b636 SC |
305 | |
306 | return wxFrameBase::MacIsChildOfClientArea( child ) ; | |
307 | } | |
308 | ||
0d53fc34 | 309 | void wxFrame::DoSetClientSize(int clientwidth, int clientheight) |
e9576ca5 | 310 | { |
e40298d5 JS |
311 | int currentclientwidth , currentclientheight ; |
312 | int currentwidth , currentheight ; | |
902725ee | 313 | |
e40298d5 | 314 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; |
facd6764 SC |
315 | if ( clientwidth == -1 ) |
316 | clientwidth = currentclientwidth ; | |
317 | if ( clientheight == -1 ) | |
318 | clientheight = currentclientheight ; | |
e40298d5 | 319 | GetSize( ¤twidth , ¤theight ) ; |
902725ee | 320 | |
e40298d5 | 321 | // find the current client size |
519cb848 | 322 | |
7ad25aed DS |
323 | // Find the difference between the entire window (title bar and all) and |
324 | // the client area; add this to the new client size to move the window | |
e40298d5 JS |
325 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , |
326 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
e9576ca5 SC |
327 | } |
328 | ||
519cb848 | 329 | #if wxUSE_TOOLBAR |
e56d2520 SC |
330 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
331 | { | |
332 | if ( m_frameToolBar == toolbar ) | |
333 | return ; | |
be6068f6 | 334 | |
e56d2520 SC |
335 | #if wxMAC_USE_NATIVE_TOOLBAR |
336 | if ( m_frameToolBar ) | |
7ad25aed | 337 | m_frameToolBar->MacInstallNativeToolbar( false ) ; |
e56d2520 | 338 | #endif |
7ad25aed | 339 | |
e56d2520 | 340 | m_frameToolBar = toolbar ; |
7ad25aed | 341 | |
e56d2520 SC |
342 | #if wxMAC_USE_NATIVE_TOOLBAR |
343 | if ( toolbar ) | |
344 | toolbar->MacInstallNativeToolbar( true ) ; | |
345 | #endif | |
346 | } | |
347 | ||
0d53fc34 | 348 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
e9576ca5 | 349 | { |
2f1ae414 | 350 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
e9576ca5 | 351 | PositionToolBar(); |
e9576ca5 | 352 | |
2f1ae414 | 353 | return m_frameToolBar; |
e9576ca5 SC |
354 | } |
355 | ||
0d53fc34 | 356 | void wxFrame::PositionToolBar() |
e9576ca5 SC |
357 | { |
358 | int cw, ch; | |
359 | ||
facd6764 | 360 | GetSize( &cw , &ch ) ; |
e9576ca5 | 361 | |
7ad25aed | 362 | if (GetStatusBar() && GetStatusBar()->IsShown()) |
e9576ca5 | 363 | { |
7ad25aed DS |
364 | int statusX, statusY; |
365 | ||
366 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
367 | ch -= statusY; | |
e9576ca5 SC |
368 | } |
369 | ||
370 | if (GetToolBar()) | |
371 | { | |
facd6764 | 372 | int tx, ty, tw, th; |
902725ee | 373 | |
7ad25aed DS |
374 | tx = ty = 0 ; |
375 | GetToolBar()->GetSize(&tw, &th); | |
e9576ca5 SC |
376 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) |
377 | { | |
378 | // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS | |
379 | // means, pretend we don't have toolbar/status bar, so we | |
380 | // have the original client size. | |
facd6764 | 381 | GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS ); |
e9576ca5 SC |
382 | } |
383 | else | |
384 | { | |
e56d2520 | 385 | #if !wxMAC_USE_NATIVE_TOOLBAR |
e9576ca5 | 386 | // Use the 'real' position |
facd6764 | 387 | GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS ); |
e56d2520 | 388 | #endif |
e9576ca5 SC |
389 | } |
390 | } | |
391 | } | |
6f02a879 VZ |
392 | |
393 | void wxFrame::PositionBars() | |
394 | { | |
395 | #if wxUSE_STATUSBAR | |
396 | PositionStatusBar(); | |
397 | #endif | |
398 | #if wxUSE_TOOLBAR | |
399 | PositionToolBar(); | |
400 | #endif | |
401 | } | |
402 | ||
519cb848 | 403 | #endif |