]>
Commit | Line | Data |
---|---|---|
63fec618 | 1 | ///////////////////////////////////////////////////////////////////////////// |
7c0ea335 | 2 | // Name: common/framecmn.cpp |
63fec618 VZ |
3 | // Purpose: common (for all platforms) wxFrame functions |
4 | // Author: Julian Smart, Vadim Zeitlin | |
5 | // Created: 01/02/97 | |
439b3bf1 | 6 | // Id: $Id$ |
55d99c7a | 7 | // Copyright: (c) 1998 Robert Roebling and Julian Smart |
63fec618 VZ |
8 | // Licence: wxWindows licence |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
7c0ea335 VZ |
11 | // ============================================================================ |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | #ifdef __GNUG__ | |
20 | #pragma implementation "framebase.h" | |
21 | #endif | |
22 | ||
f701d7ab JS |
23 | // For compilers that support precompilation, includes "wx.h". |
24 | #include "wx/wxprec.h" | |
25 | ||
26 | #ifdef __BORLANDC__ | |
7c0ea335 | 27 | #pragma hdrstop |
f701d7ab JS |
28 | #endif |
29 | ||
1e6feb95 VZ |
30 | #ifndef WX_PRECOMP |
31 | #include "wx/frame.h" | |
32 | #include "wx/menu.h" | |
33 | #include "wx/menuitem.h" | |
34 | #include "wx/dcclient.h" | |
35 | #endif // WX_PRECOMP | |
7c0ea335 VZ |
36 | |
37 | #if wxUSE_TOOLBAR | |
38 | #include "wx/toolbar.h" | |
39 | #endif | |
40 | #if wxUSE_STATUSBAR | |
41 | #include "wx/statusbr.h" | |
42 | #endif | |
43 | ||
44 | // ---------------------------------------------------------------------------- | |
45 | // event table | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
7d9f12f3 | 48 | BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow) |
0b30bb0b JS |
49 | #if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES |
50 | EVT_MENU_OPEN(wxFrameBase::OnMenuOpen) | |
51 | #endif | |
7c0ea335 | 52 | EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight) |
7c0ea335 VZ |
53 | END_EVENT_TABLE() |
54 | ||
55 | // ============================================================================ | |
56 | // implementation | |
57 | // ============================================================================ | |
58 | ||
59 | // ---------------------------------------------------------------------------- | |
60 | // construction/destruction | |
61 | // ---------------------------------------------------------------------------- | |
62 | ||
63 | wxFrameBase::wxFrameBase() | |
64 | { | |
1e6feb95 | 65 | #if wxUSE_MENUS |
7c0ea335 | 66 | m_frameMenuBar = NULL; |
1e6feb95 | 67 | #endif // wxUSE_MENUS |
7c0ea335 VZ |
68 | |
69 | #if wxUSE_TOOLBAR | |
70 | m_frameToolBar = NULL; | |
71 | #endif // wxUSE_TOOLBAR | |
72 | ||
73 | #if wxUSE_STATUSBAR | |
74 | m_frameStatusBar = NULL; | |
75 | #endif // wxUSE_STATUSBAR | |
1f361cdd MB |
76 | |
77 | m_statusBarPane = 0; | |
7c0ea335 VZ |
78 | } |
79 | ||
799ea011 GD |
80 | wxFrameBase::~wxFrameBase() |
81 | { | |
82 | // this destructor is required for Darwin | |
83 | } | |
84 | ||
7c0ea335 VZ |
85 | wxFrame *wxFrameBase::New(wxWindow *parent, |
86 | wxWindowID id, | |
87 | const wxString& title, | |
88 | const wxPoint& pos, | |
89 | const wxSize& size, | |
90 | long style, | |
91 | const wxString& name) | |
92 | { | |
93 | return new wxFrame(parent, id, title, pos, size, style, name); | |
94 | } | |
95 | ||
96 | void wxFrameBase::DeleteAllBars() | |
97 | { | |
1e6feb95 | 98 | #if wxUSE_MENUS |
7c0ea335 VZ |
99 | if ( m_frameMenuBar ) |
100 | { | |
101 | delete m_frameMenuBar; | |
102 | m_frameMenuBar = (wxMenuBar *) NULL; | |
103 | } | |
1e6feb95 | 104 | #endif // wxUSE_MENUS |
7c0ea335 VZ |
105 | |
106 | #if wxUSE_STATUSBAR | |
107 | if ( m_frameStatusBar ) | |
108 | { | |
109 | delete m_frameStatusBar; | |
110 | m_frameStatusBar = (wxStatusBar *) NULL; | |
111 | } | |
112 | #endif // wxUSE_STATUSBAR | |
113 | ||
114 | #if wxUSE_TOOLBAR | |
115 | if ( m_frameToolBar ) | |
116 | { | |
117 | delete m_frameToolBar; | |
118 | m_frameToolBar = (wxToolBar *) NULL; | |
119 | } | |
120 | #endif // wxUSE_TOOLBAR | |
121 | } | |
122 | ||
1e6feb95 VZ |
123 | bool wxFrameBase::IsOneOfBars(const wxWindow *win) const |
124 | { | |
125 | #if wxUSE_MENUS | |
126 | if ( win == GetMenuBar() ) | |
127 | return TRUE; | |
128 | #endif // wxUSE_MENUS | |
129 | ||
130 | #if wxUSE_STATUSBAR | |
131 | if ( win == GetStatusBar() ) | |
132 | return TRUE; | |
133 | #endif // wxUSE_STATUSBAR | |
134 | ||
135 | #if wxUSE_TOOLBAR | |
136 | if ( win == GetToolBar() ) | |
137 | return TRUE; | |
138 | #endif // wxUSE_TOOLBAR | |
139 | ||
140 | return FALSE; | |
141 | } | |
142 | ||
1c4f8f8d VZ |
143 | // ---------------------------------------------------------------------------- |
144 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
145 | // from the client area, so the client area is what's really available for the | |
146 | // frame contents | |
147 | // ---------------------------------------------------------------------------- | |
148 | ||
149 | // get the origin of the client area in the client coordinates | |
150 | wxPoint wxFrameBase::GetClientAreaOrigin() const | |
151 | { | |
7d9f12f3 | 152 | wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin(); |
1c4f8f8d | 153 | |
16c9a425 | 154 | #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) |
d4597e13 VZ |
155 | wxToolBar *toolbar = GetToolBar(); |
156 | if ( toolbar && toolbar->IsShown() ) | |
1c4f8f8d VZ |
157 | { |
158 | int w, h; | |
d4597e13 | 159 | toolbar->GetSize(&w, &h); |
1c4f8f8d | 160 | |
d4597e13 | 161 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) |
1c4f8f8d VZ |
162 | { |
163 | pt.x += w; | |
164 | } | |
165 | else | |
166 | { | |
167 | pt.y += h; | |
168 | } | |
169 | } | |
170 | #endif // wxUSE_TOOLBAR | |
171 | ||
172 | return pt; | |
173 | } | |
174 | ||
7c0ea335 VZ |
175 | // ---------------------------------------------------------------------------- |
176 | // misc | |
177 | // ---------------------------------------------------------------------------- | |
178 | ||
7c0ea335 VZ |
179 | bool wxFrameBase::ProcessCommand(int id) |
180 | { | |
1e6feb95 | 181 | #if wxUSE_MENUS |
7c0ea335 VZ |
182 | wxMenuBar *bar = GetMenuBar(); |
183 | if ( !bar ) | |
184 | return FALSE; | |
185 | ||
3ca6a5f0 BP |
186 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); |
187 | commandEvent.SetEventObject(this); | |
188 | ||
7c0ea335 | 189 | wxMenuItem *item = bar->FindItem(id); |
84f7908b | 190 | if (item) |
7c0ea335 | 191 | { |
84f7908b RR |
192 | if (!item->IsEnabled()) |
193 | return TRUE; | |
d4597e13 | 194 | |
84f7908b RR |
195 | if (item->IsCheckable()) |
196 | { | |
197 | item->Toggle(); | |
0472ece7 | 198 | |
84f7908b RR |
199 | // use the new value |
200 | commandEvent.SetInt(item->IsChecked()); | |
201 | } | |
3ca6a5f0 | 202 | } |
7c0ea335 | 203 | |
a01fe3d6 RD |
204 | GetEventHandler()->ProcessEvent(commandEvent); |
205 | return TRUE; | |
1e6feb95 VZ |
206 | #else // !wxUSE_MENUS |
207 | return FALSE; | |
208 | #endif // wxUSE_MENUS/!wxUSE_MENUS | |
7c0ea335 VZ |
209 | } |
210 | ||
e39af974 JS |
211 | // Do the UI update processing for this window. This is |
212 | // provided for the application to call if it wants to | |
213 | // force a UI update, particularly for the menus and toolbar. | |
214 | void wxFrameBase::UpdateWindowUI(long flags) | |
215 | { | |
216 | wxWindowBase::UpdateWindowUI(flags); | |
217 | ||
218 | #if wxUSE_TOOLBAR | |
219 | if (GetToolBar()) | |
220 | GetToolBar()->UpdateWindowUI(flags); | |
221 | #endif | |
222 | ||
223 | #if wxUSE_MENUS | |
224 | if (GetMenuBar()) | |
225 | { | |
226 | if ((flags & wxUPDATE_UI_FROMIDLE) && !wxUSE_IDLEMENUUPDATES) | |
227 | { | |
228 | // If coming from an idle event, we only | |
229 | // want to update the menus if we're | |
230 | // in the wxUSE_IDLEMENUUPDATES configuration: | |
231 | // so if we're not, do nothing | |
232 | } | |
233 | else | |
234 | DoMenuUpdates(); | |
235 | } | |
236 | #endif | |
237 | } | |
238 | ||
7c0ea335 VZ |
239 | // ---------------------------------------------------------------------------- |
240 | // event handlers | |
241 | // ---------------------------------------------------------------------------- | |
242 | ||
7c0ea335 VZ |
243 | void wxFrameBase::OnMenuHighlight(wxMenuEvent& event) |
244 | { | |
245 | #if wxUSE_STATUSBAR | |
f6bcfd97 | 246 | (void)ShowMenuHelp(GetStatusBar(), event.GetMenuId()); |
7c0ea335 VZ |
247 | #endif // wxUSE_STATUSBAR |
248 | } | |
249 | ||
e39af974 JS |
250 | // Implement internal behaviour (menu updating on some platforms) |
251 | void wxFrameBase::OnInternalIdle() | |
6522713c | 252 | { |
0b30bb0b | 253 | #if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES |
e39af974 | 254 | if (wxUpdateUIEvent::CanUpdate(this)) |
0b30bb0b JS |
255 | DoMenuUpdates(); |
256 | #endif | |
257 | } | |
258 | ||
259 | void wxFrameBase::OnMenuOpen(wxMenuEvent& WXUNUSED(event)) | |
260 | { | |
261 | #if wxUSE_MENUS && !wxUSE_IDLEMENUUPDATES | |
6522713c | 262 | DoMenuUpdates(); |
0b30bb0b | 263 | #endif |
6522713c VZ |
264 | } |
265 | ||
7c0ea335 VZ |
266 | // ---------------------------------------------------------------------------- |
267 | // status bar stuff | |
268 | // ---------------------------------------------------------------------------- | |
269 | ||
270 | #if wxUSE_STATUSBAR | |
271 | ||
272 | wxStatusBar* wxFrameBase::CreateStatusBar(int number, | |
273 | long style, | |
274 | wxWindowID id, | |
275 | const wxString& name) | |
276 | { | |
277 | // the main status bar can only be created once (or else it should be | |
278 | // deleted before calling CreateStatusBar() again) | |
279 | wxCHECK_MSG( !m_frameStatusBar, (wxStatusBar *)NULL, | |
280 | wxT("recreating status bar in wxFrame") ); | |
281 | ||
282 | m_frameStatusBar = OnCreateStatusBar( number, style, id, name ); | |
283 | if ( m_frameStatusBar ) | |
284 | PositionStatusBar(); | |
285 | ||
286 | return m_frameStatusBar; | |
287 | } | |
288 | ||
289 | wxStatusBar *wxFrameBase::OnCreateStatusBar(int number, | |
290 | long style, | |
291 | wxWindowID id, | |
292 | const wxString& name) | |
293 | { | |
ed791986 | 294 | wxStatusBar *statusBar = new wxStatusBar(this, id, style, name); |
7c0ea335 | 295 | |
7c0ea335 VZ |
296 | statusBar->SetFieldsCount(number); |
297 | ||
298 | return statusBar; | |
299 | } | |
300 | ||
301 | void wxFrameBase::SetStatusText(const wxString& text, int number) | |
302 | { | |
7c0ea335 VZ |
303 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); |
304 | ||
305 | m_frameStatusBar->SetStatusText(text, number); | |
306 | } | |
307 | ||
308 | void wxFrameBase::SetStatusWidths(int n, const int widths_field[] ) | |
309 | { | |
7c0ea335 VZ |
310 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") ); |
311 | ||
312 | m_frameStatusBar->SetStatusWidths(n, widths_field); | |
313 | ||
314 | PositionStatusBar(); | |
315 | } | |
316 | ||
1f361cdd | 317 | void wxFrameBase::PushStatusText(const wxString& text, int number) |
f6bcfd97 | 318 | { |
1f361cdd MB |
319 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); |
320 | ||
321 | m_frameStatusBar->PushStatusText(text, number); | |
322 | } | |
f6bcfd97 | 323 | |
1f361cdd MB |
324 | void wxFrameBase::PopStatusText(int number) |
325 | { | |
326 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); | |
327 | ||
328 | m_frameStatusBar->PopStatusText(number); | |
329 | } | |
330 | ||
1f361cdd MB |
331 | bool wxFrameBase::ShowMenuHelp(wxStatusBar *WXUNUSED(statbar), int menuId) |
332 | { | |
333 | #if wxUSE_MENUS | |
f6bcfd97 BP |
334 | // if no help string found, we will clear the status bar text |
335 | wxString helpString; | |
1f361cdd | 336 | bool show = menuId != wxID_SEPARATOR && menuId != -2 /* wxID_TITLE */; |
f6bcfd97 | 337 | |
1f361cdd | 338 | if ( show ) |
f6bcfd97 BP |
339 | { |
340 | wxMenuBar *menuBar = GetMenuBar(); | |
341 | if ( menuBar ) | |
342 | { | |
343 | // it's ok if we don't find the item because it might belong | |
344 | // to the popup menu | |
345 | wxMenuItem *item = menuBar->FindItem(menuId); | |
346 | if ( item ) | |
347 | helpString = item->GetHelp(); | |
348 | } | |
349 | } | |
350 | ||
1f361cdd | 351 | DoGiveHelp(helpString, show); |
f6bcfd97 BP |
352 | |
353 | return !helpString.IsEmpty(); | |
3379ed37 VZ |
354 | #else // !wxUSE_MENUS |
355 | return FALSE; | |
356 | #endif // wxUSE_MENUS/!wxUSE_MENUS | |
f6bcfd97 BP |
357 | } |
358 | ||
7c0ea335 VZ |
359 | #endif // wxUSE_STATUSBAR |
360 | ||
c60a36d5 VZ |
361 | void wxFrameBase::DoGiveHelp(const wxString& text, bool show) |
362 | { | |
363 | #if wxUSE_STATUSBAR | |
364 | if ( m_statusBarPane < 0 ) return; | |
365 | wxStatusBar* statbar = GetStatusBar(); | |
366 | if ( !statbar ) return; | |
367 | ||
368 | wxString help = show ? text : wxString(); | |
369 | statbar->SetStatusText( help, m_statusBarPane ); | |
370 | #endif // wxUSE_STATUSBAR | |
371 | } | |
372 | ||
373 | ||
7c0ea335 VZ |
374 | // ---------------------------------------------------------------------------- |
375 | // toolbar stuff | |
376 | // ---------------------------------------------------------------------------- | |
377 | ||
378 | #if wxUSE_TOOLBAR | |
379 | ||
380 | wxToolBar* wxFrameBase::CreateToolBar(long style, | |
381 | wxWindowID id, | |
382 | const wxString& name) | |
383 | { | |
384 | // the main toolbar can't be recreated (unless it was explicitly deeleted | |
385 | // before) | |
386 | wxCHECK_MSG( !m_frameToolBar, (wxToolBar *)NULL, | |
387 | wxT("recreating toolbar in wxFrame") ); | |
388 | ||
389 | m_frameToolBar = OnCreateToolBar(style, id, name); | |
390 | ||
391 | return m_frameToolBar; | |
392 | } | |
393 | ||
394 | wxToolBar* wxFrameBase::OnCreateToolBar(long style, | |
395 | wxWindowID id, | |
396 | const wxString& name) | |
397 | { | |
398 | return new wxToolBar(this, id, | |
399 | wxDefaultPosition, wxDefaultSize, | |
400 | style, name); | |
401 | } | |
402 | ||
403 | #endif // wxUSE_TOOLBAR | |
404 | ||
405 | // ---------------------------------------------------------------------------- | |
6522713c | 406 | // menus |
7c0ea335 VZ |
407 | // ---------------------------------------------------------------------------- |
408 | ||
1e6feb95 VZ |
409 | #if wxUSE_MENUS |
410 | ||
63fec618 | 411 | // update all menus |
7c0ea335 | 412 | void wxFrameBase::DoMenuUpdates() |
63fec618 | 413 | { |
54517652 | 414 | wxMenuBar* bar = GetMenuBar(); |
e702ff0f | 415 | |
7c0ea335 | 416 | if ( bar != NULL ) |
54517652 | 417 | { |
18afa2ac | 418 | wxEvtHandler* source = GetEventHandler(); |
54517652 RR |
419 | int nCount = bar->GetMenuCount(); |
420 | for (int n = 0; n < nCount; n++) | |
18afa2ac | 421 | bar->GetMenu(n)->UpdateUI(source); |
63fec618 | 422 | } |
63fec618 | 423 | } |
1e6feb95 | 424 | |
6522713c VZ |
425 | void wxFrameBase::DetachMenuBar() |
426 | { | |
427 | if ( m_frameMenuBar ) | |
428 | { | |
429 | m_frameMenuBar->Detach(); | |
430 | m_frameMenuBar = NULL; | |
431 | } | |
432 | } | |
433 | ||
434 | void wxFrameBase::AttachMenuBar(wxMenuBar *menubar) | |
435 | { | |
436 | if ( menubar ) | |
437 | { | |
6522713c | 438 | menubar->Attach((wxFrame *)this); |
3dbe38c3 | 439 | m_frameMenuBar = menubar; |
6522713c VZ |
440 | } |
441 | } | |
442 | ||
443 | void wxFrameBase::SetMenuBar(wxMenuBar *menubar) | |
444 | { | |
445 | if ( menubar == GetMenuBar() ) | |
446 | { | |
447 | // nothing to do | |
448 | return; | |
449 | } | |
450 | ||
451 | DetachMenuBar(); | |
452 | ||
453 | AttachMenuBar(menubar); | |
454 | } | |
455 | ||
1e6feb95 | 456 | #endif // wxUSE_MENUS |