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