]> git.saurik.com Git - wxWidgets.git/blame - src/common/framecmn.cpp
Warning fixes for wxUSE_STL=1.
[wxWidgets.git] / src / common / framecmn.cpp
CommitLineData
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 48BEGIN_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
53END_EVENT_TABLE()
54
55// ============================================================================
56// implementation
57// ============================================================================
58
59// ----------------------------------------------------------------------------
60// construction/destruction
61// ----------------------------------------------------------------------------
62
63wxFrameBase::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
80wxFrameBase::~wxFrameBase()
81{
82 // this destructor is required for Darwin
83}
84
7c0ea335
VZ
85wxFrame *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
96void 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
123bool 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
150wxPoint 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
179bool 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.
214void 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
243void 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)
251void 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
259void 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
272wxStatusBar* 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
289wxStatusBar *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
301void 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
308void 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 317void 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
324void 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
331bool 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
361void 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
380wxToolBar* 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
f9dae779
VZ
389 if ( style == -1 )
390 {
391 // use default style
392 //
393 // NB: we don't specify the default value in the method declaration
394 // because
395 // a) this allows us to have different defaults for different
396 // platforms (even if we don't have them right now)
397 // b) we don't need to include wx/toolbar.h in the header then
398 style = wxBORDER_NONE | wxTB_HORIZONTAL | wxTB_FLAT;
399 }
400
7c0ea335
VZ
401 m_frameToolBar = OnCreateToolBar(style, id, name);
402
403 return m_frameToolBar;
404}
405
406wxToolBar* wxFrameBase::OnCreateToolBar(long style,
407 wxWindowID id,
408 const wxString& name)
409{
410 return new wxToolBar(this, id,
411 wxDefaultPosition, wxDefaultSize,
412 style, name);
413}
414
415#endif // wxUSE_TOOLBAR
416
417// ----------------------------------------------------------------------------
6522713c 418// menus
7c0ea335
VZ
419// ----------------------------------------------------------------------------
420
1e6feb95
VZ
421#if wxUSE_MENUS
422
63fec618 423// update all menus
7c0ea335 424void wxFrameBase::DoMenuUpdates()
63fec618 425{
54517652 426 wxMenuBar* bar = GetMenuBar();
e702ff0f 427
7c0ea335 428 if ( bar != NULL )
54517652 429 {
18afa2ac 430 wxEvtHandler* source = GetEventHandler();
54517652
RR
431 int nCount = bar->GetMenuCount();
432 for (int n = 0; n < nCount; n++)
18afa2ac 433 bar->GetMenu(n)->UpdateUI(source);
63fec618 434 }
63fec618 435}
1e6feb95 436
6522713c
VZ
437void wxFrameBase::DetachMenuBar()
438{
439 if ( m_frameMenuBar )
440 {
441 m_frameMenuBar->Detach();
442 m_frameMenuBar = NULL;
443 }
444}
445
446void wxFrameBase::AttachMenuBar(wxMenuBar *menubar)
447{
448 if ( menubar )
449 {
6522713c 450 menubar->Attach((wxFrame *)this);
3dbe38c3 451 m_frameMenuBar = menubar;
6522713c
VZ
452 }
453}
454
455void wxFrameBase::SetMenuBar(wxMenuBar *menubar)
456{
457 if ( menubar == GetMenuBar() )
458 {
459 // nothing to do
460 return;
461 }
462
463 DetachMenuBar();
464
465 AttachMenuBar(menubar);
466}
467
1e6feb95 468#endif // wxUSE_MENUS