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