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