]>
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 | ||
e9576ca5 | 88 | |
0d53fc34 | 89 | bool wxFrame::Enable(bool enable) |
e9576ca5 | 90 | { |
2f1ae414 | 91 | if ( !wxWindow::Enable(enable) ) |
902725ee | 92 | return false; |
e9576ca5 | 93 | |
e40298d5 JS |
94 | if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) |
95 | { | |
902725ee | 96 | int iMaxMenu = m_frameMenuBar->GetMenuCount(); |
e40298d5 JS |
97 | for ( int i = 0 ; i < iMaxMenu ; ++ i ) |
98 | { | |
99 | m_frameMenuBar->EnableTop( i , enable ) ; | |
100 | } | |
101 | } | |
2f1ae414 | 102 | |
902725ee | 103 | return true; |
2f1ae414 | 104 | } |
e9576ca5 | 105 | |
0d53fc34 | 106 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, |
e9576ca5 SC |
107 | const wxString& name) |
108 | { | |
109 | wxStatusBar *statusBar = NULL; | |
110 | ||
5b781a67 SC |
111 | statusBar = new wxStatusBar(this, id, |
112 | style, name); | |
f80ffb32 | 113 | statusBar->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT ) ; |
e9576ca5 SC |
114 | statusBar->SetFieldsCount(number); |
115 | return statusBar; | |
116 | } | |
117 | ||
0d53fc34 | 118 | void wxFrame::PositionStatusBar() |
e9576ca5 | 119 | { |
f5d63a57 | 120 | if (m_frameStatusBar && m_frameStatusBar->IsShown() ) |
e40298d5 JS |
121 | { |
122 | int w, h; | |
123 | GetClientSize(&w, &h); | |
902725ee | 124 | |
e40298d5 JS |
125 | // Since we wish the status bar to be directly under the client area, |
126 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
f80ffb32 | 127 | m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT); |
e40298d5 | 128 | } |
e9576ca5 SC |
129 | } |
130 | ||
e9576ca5 | 131 | // Responds to colour changes, and passes event on to children. |
0d53fc34 | 132 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
e9576ca5 | 133 | { |
a756f210 | 134 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
e9576ca5 SC |
135 | Refresh(); |
136 | ||
137 | if ( m_frameStatusBar ) | |
138 | { | |
139 | wxSysColourChangedEvent event2; | |
140 | event2.SetEventObject( m_frameStatusBar ); | |
141 | m_frameStatusBar->ProcessEvent(event2); | |
142 | } | |
143 | ||
144 | // Propagate the event to the non-top-level children | |
145 | wxWindow::OnSysColourChanged(event); | |
146 | } | |
147 | ||
e9576ca5 SC |
148 | |
149 | // Default activation behaviour - set the focus for the first child | |
150 | // subwindow found. | |
0d53fc34 | 151 | void wxFrame::OnActivate(wxActivateEvent& event) |
e9576ca5 | 152 | { |
2f1ae414 | 153 | if ( !event.GetActive() ) |
e9576ca5 | 154 | { |
a15eb0a5 | 155 | // remember the last focused child if it is our child |
7810c95b | 156 | m_winLastFocused = FindFocus(); |
a15eb0a5 SC |
157 | |
158 | // so we NULL it out if it's a child from some other frame | |
159 | wxWindow *win = m_winLastFocused; | |
160 | while ( win ) | |
7810c95b | 161 | { |
a15eb0a5 SC |
162 | if ( win->IsTopLevel() ) |
163 | { | |
164 | if ( win != this ) | |
165 | { | |
166 | m_winLastFocused = NULL; | |
167 | } | |
168 | ||
7810c95b | 169 | break; |
a15eb0a5 | 170 | } |
7810c95b | 171 | |
a15eb0a5 | 172 | win = win->GetParent(); |
7810c95b SC |
173 | } |
174 | ||
2f1ae414 | 175 | event.Skip(); |
e9576ca5 | 176 | } |
e40298d5 JS |
177 | else |
178 | { | |
a15eb0a5 SC |
179 | // restore focus to the child which was last focused |
180 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() | |
181 | : NULL; | |
182 | if ( !parent ) | |
e9576ca5 | 183 | { |
a15eb0a5 | 184 | parent = this; |
e9576ca5 | 185 | } |
a15eb0a5 | 186 | |
e40298d5 | 187 | wxSetFocusToChild(parent, &m_winLastFocused); |
7810c95b | 188 | |
e40298d5 JS |
189 | if ( m_frameMenuBar != NULL ) |
190 | { | |
191 | m_frameMenuBar->MacInstallMenuBar() ; | |
192 | } | |
193 | else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame))) | |
2b5f62a0 VZ |
194 | { |
195 | // Trying toplevel frame menbar | |
196 | if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() ) | |
e40298d5 JS |
197 | ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar(); |
198 | } | |
199 | } | |
e9576ca5 SC |
200 | } |
201 | ||
2b5f62a0 VZ |
202 | void wxFrame::DetachMenuBar() |
203 | { | |
204 | if ( m_frameMenuBar ) | |
205 | { | |
206 | m_frameMenuBar->UnsetInvokingWindow(); | |
207 | } | |
208 | ||
209 | wxFrameBase::DetachMenuBar(); | |
210 | } | |
211 | ||
212 | void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) | |
213 | { | |
214 | wxFrameBase::AttachMenuBar(menuBar); | |
215 | ||
216 | if (m_frameMenuBar) | |
217 | { | |
218 | m_frameMenuBar->SetInvokingWindow( this ); | |
219 | } | |
220 | } | |
221 | ||
0d53fc34 | 222 | void wxFrame::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 223 | { |
facd6764 | 224 | wxTopLevelWindow::DoGetClientSize( x , y ) ; |
902725ee | 225 | |
2f1ae414 | 226 | #if wxUSE_STATUSBAR |
f5d63a57 | 227 | if ( GetStatusBar() && GetStatusBar()->IsShown() && y ) |
e40298d5 | 228 | { |
902725ee | 229 | *y -= WX_MAC_STATUSBAR_HEIGHT; |
e40298d5 | 230 | } |
2f1ae414 | 231 | #endif // wxUSE_STATUSBAR |
902725ee | 232 | |
facd6764 SC |
233 | #if wxUSE_TOOLBAR |
234 | wxToolBar *toolbar = GetToolBar(); | |
235 | if ( toolbar && toolbar->IsShown() ) | |
236 | { | |
237 | int w, h; | |
238 | toolbar->GetSize(&w, &h); | |
239 | ||
240 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
241 | { | |
242 | if ( x ) *x -= w; | |
243 | } | |
244 | else | |
245 | { | |
246 | if ( y ) *y -= h; | |
247 | } | |
248 | } | |
249 | #endif // wxUSE_TOOLBAR | |
e9576ca5 SC |
250 | } |
251 | ||
902725ee | 252 | bool wxFrame::MacIsChildOfClientArea( const wxWindow* child ) const |
e905b636 SC |
253 | { |
254 | #if wxUSE_STATUSBAR | |
255 | if ( child == GetStatusBar() ) | |
256 | return false ; | |
257 | #endif // wxUSE_STATUSBAR | |
258 | ||
259 | #if wxUSE_TOOLBAR | |
260 | if ( child == GetToolBar() ) | |
261 | return false ; | |
262 | #endif // wxUSE_TOOLBAR | |
263 | ||
264 | return wxFrameBase::MacIsChildOfClientArea( child ) ; | |
265 | } | |
266 | ||
0d53fc34 | 267 | void wxFrame::DoSetClientSize(int clientwidth, int clientheight) |
e9576ca5 | 268 | { |
e40298d5 JS |
269 | int currentclientwidth , currentclientheight ; |
270 | int currentwidth , currentheight ; | |
902725ee | 271 | |
e40298d5 | 272 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; |
facd6764 SC |
273 | if ( clientwidth == -1 ) |
274 | clientwidth = currentclientwidth ; | |
275 | if ( clientheight == -1 ) | |
276 | clientheight = currentclientheight ; | |
e40298d5 | 277 | GetSize( ¤twidth , ¤theight ) ; |
902725ee | 278 | |
e40298d5 | 279 | // find the current client size |
519cb848 SC |
280 | |
281 | // Find the difference between the entire window (title bar and all) | |
282 | // and the client area; add this to the new client size to move the | |
283 | // window | |
284 | ||
e40298d5 JS |
285 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , |
286 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
e9576ca5 SC |
287 | } |
288 | ||
519cb848 SC |
289 | |
290 | #if wxUSE_TOOLBAR | |
0d53fc34 | 291 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
e9576ca5 | 292 | { |
2f1ae414 | 293 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
e9576ca5 | 294 | { |
e9576ca5 | 295 | PositionToolBar(); |
e9576ca5 | 296 | } |
e9576ca5 | 297 | |
2f1ae414 | 298 | return m_frameToolBar; |
e9576ca5 SC |
299 | } |
300 | ||
0d53fc34 | 301 | void wxFrame::PositionToolBar() |
e9576ca5 SC |
302 | { |
303 | int cw, ch; | |
304 | ||
facd6764 | 305 | GetSize( &cw , &ch ) ; |
e9576ca5 | 306 | |
f5d63a57 | 307 | if ( GetStatusBar() && GetStatusBar()->IsShown()) |
e9576ca5 SC |
308 | { |
309 | int statusX, statusY; | |
310 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
311 | ch -= statusY; | |
312 | } | |
313 | ||
314 | if (GetToolBar()) | |
315 | { | |
facd6764 SC |
316 | int tx, ty, tw, th; |
317 | tx = ty = 0 ; | |
902725ee | 318 | |
e9576ca5 | 319 | GetToolBar()->GetSize(& tw, & th); |
e9576ca5 SC |
320 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) |
321 | { | |
322 | // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS | |
323 | // means, pretend we don't have toolbar/status bar, so we | |
324 | // have the original client size. | |
facd6764 | 325 | GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS ); |
e9576ca5 SC |
326 | } |
327 | else | |
328 | { | |
329 | // Use the 'real' position | |
facd6764 | 330 | GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS ); |
e9576ca5 SC |
331 | } |
332 | } | |
333 | } | |
519cb848 | 334 | #endif |