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