]> git.saurik.com Git - wxWidgets.git/blame - src/common/framecmn.cpp
added wxEXEC_NOHIDE flag, modified wxExecute() to take a combination of bit flags...
[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$
63fec618
VZ
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
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
7d9f12f3
VS
44// FIXME - temporary hack in absence of wxTLW in all ports!
45#ifndef wxTopLevelWindowNative
46 #define wxTopLevelWindow wxTopLevelWindowBase
47#endif
48
7c0ea335
VZ
49// ----------------------------------------------------------------------------
50// event table
51// ----------------------------------------------------------------------------
52
7d9f12f3 53BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow)
7c0ea335 54 EVT_IDLE(wxFrameBase::OnIdle)
7c0ea335 55 EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight)
7c0ea335
VZ
56END_EVENT_TABLE()
57
58// ============================================================================
59// implementation
60// ============================================================================
61
62// ----------------------------------------------------------------------------
63// construction/destruction
64// ----------------------------------------------------------------------------
65
66wxFrameBase::wxFrameBase()
67{
1e6feb95 68#if wxUSE_MENUS
7c0ea335 69 m_frameMenuBar = NULL;
1e6feb95 70#endif // wxUSE_MENUS
7c0ea335
VZ
71
72#if wxUSE_TOOLBAR
73 m_frameToolBar = NULL;
74#endif // wxUSE_TOOLBAR
75
76#if wxUSE_STATUSBAR
77 m_frameStatusBar = NULL;
78#endif // wxUSE_STATUSBAR
79}
80
799ea011
GD
81wxFrameBase::~wxFrameBase()
82{
83 // this destructor is required for Darwin
84}
85
7c0ea335
VZ
86wxFrame *wxFrameBase::New(wxWindow *parent,
87 wxWindowID id,
88 const wxString& title,
89 const wxPoint& pos,
90 const wxSize& size,
91 long style,
92 const wxString& name)
93{
94 return new wxFrame(parent, id, title, pos, size, style, name);
95}
96
97void wxFrameBase::DeleteAllBars()
98{
1e6feb95 99#if wxUSE_MENUS
7c0ea335
VZ
100 if ( m_frameMenuBar )
101 {
102 delete m_frameMenuBar;
103 m_frameMenuBar = (wxMenuBar *) NULL;
104 }
1e6feb95 105#endif // wxUSE_MENUS
7c0ea335
VZ
106
107#if wxUSE_STATUSBAR
108 if ( m_frameStatusBar )
109 {
110 delete m_frameStatusBar;
111 m_frameStatusBar = (wxStatusBar *) NULL;
112 }
113#endif // wxUSE_STATUSBAR
114
115#if wxUSE_TOOLBAR
116 if ( m_frameToolBar )
117 {
118 delete m_frameToolBar;
119 m_frameToolBar = (wxToolBar *) NULL;
120 }
121#endif // wxUSE_TOOLBAR
122}
123
1e6feb95
VZ
124bool wxFrameBase::IsOneOfBars(const wxWindow *win) const
125{
126#if wxUSE_MENUS
127 if ( win == GetMenuBar() )
128 return TRUE;
129#endif // wxUSE_MENUS
130
131#if wxUSE_STATUSBAR
132 if ( win == GetStatusBar() )
133 return TRUE;
134#endif // wxUSE_STATUSBAR
135
136#if wxUSE_TOOLBAR
137 if ( win == GetToolBar() )
138 return TRUE;
139#endif // wxUSE_TOOLBAR
140
141 return FALSE;
142}
143
1c4f8f8d
VZ
144// ----------------------------------------------------------------------------
145// wxFrame size management: we exclude the areas taken by menu/status/toolbars
146// from the client area, so the client area is what's really available for the
147// frame contents
148// ----------------------------------------------------------------------------
149
150// get the origin of the client area in the client coordinates
151wxPoint wxFrameBase::GetClientAreaOrigin() const
152{
7d9f12f3 153 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
1c4f8f8d 154
16c9a425 155#if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
d4597e13
VZ
156 wxToolBar *toolbar = GetToolBar();
157 if ( toolbar && toolbar->IsShown() )
1c4f8f8d
VZ
158 {
159 int w, h;
d4597e13 160 toolbar->GetSize(&w, &h);
1c4f8f8d 161
d4597e13 162 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
1c4f8f8d
VZ
163 {
164 pt.x += w;
165 }
166 else
167 {
168 pt.y += h;
169 }
170 }
171#endif // wxUSE_TOOLBAR
172
173 return pt;
174}
175
7c0ea335
VZ
176// ----------------------------------------------------------------------------
177// misc
178// ----------------------------------------------------------------------------
179
7c0ea335
VZ
180bool wxFrameBase::ProcessCommand(int id)
181{
1e6feb95 182#if wxUSE_MENUS
7c0ea335
VZ
183 wxMenuBar *bar = GetMenuBar();
184 if ( !bar )
185 return FALSE;
186
3ca6a5f0
BP
187 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
188 commandEvent.SetEventObject(this);
189
7c0ea335 190 wxMenuItem *item = bar->FindItem(id);
84f7908b 191 if (item)
7c0ea335 192 {
84f7908b
RR
193 if (!item->IsEnabled())
194 return TRUE;
d4597e13 195
84f7908b
RR
196 if (item->IsCheckable())
197 {
198 item->Toggle();
0472ece7 199
84f7908b
RR
200 // use the new value
201 commandEvent.SetInt(item->IsChecked());
202 }
3ca6a5f0 203 }
7c0ea335
VZ
204
205 return GetEventHandler()->ProcessEvent(commandEvent);
1e6feb95
VZ
206#else // !wxUSE_MENUS
207 return FALSE;
208#endif // wxUSE_MENUS/!wxUSE_MENUS
7c0ea335
VZ
209}
210
211// ----------------------------------------------------------------------------
212// event handlers
213// ----------------------------------------------------------------------------
214
7c0ea335
VZ
215void wxFrameBase::OnMenuHighlight(wxMenuEvent& event)
216{
217#if wxUSE_STATUSBAR
f6bcfd97 218 (void)ShowMenuHelp(GetStatusBar(), event.GetMenuId());
7c0ea335
VZ
219#endif // wxUSE_STATUSBAR
220}
221
6522713c
VZ
222void wxFrameBase::OnIdle(wxIdleEvent& WXUNUSED(event) )
223{
224#if wxUSE_MENUS
225 DoMenuUpdates();
226#endif // wxUSE_MENUS
227}
228
7c0ea335
VZ
229// ----------------------------------------------------------------------------
230// status bar stuff
231// ----------------------------------------------------------------------------
232
233#if wxUSE_STATUSBAR
234
235wxStatusBar* wxFrameBase::CreateStatusBar(int number,
236 long style,
237 wxWindowID id,
238 const wxString& name)
239{
240 // the main status bar can only be created once (or else it should be
241 // deleted before calling CreateStatusBar() again)
242 wxCHECK_MSG( !m_frameStatusBar, (wxStatusBar *)NULL,
243 wxT("recreating status bar in wxFrame") );
244
245 m_frameStatusBar = OnCreateStatusBar( number, style, id, name );
246 if ( m_frameStatusBar )
247 PositionStatusBar();
248
249 return m_frameStatusBar;
250}
251
252wxStatusBar *wxFrameBase::OnCreateStatusBar(int number,
253 long style,
254 wxWindowID id,
255 const wxString& name)
256{
ed791986 257 wxStatusBar *statusBar = new wxStatusBar(this, id, style, name);
7c0ea335 258
7c0ea335
VZ
259 statusBar->SetFieldsCount(number);
260
261 return statusBar;
262}
263
264void wxFrameBase::SetStatusText(const wxString& text, int number)
265{
7c0ea335
VZ
266 wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
267
268 m_frameStatusBar->SetStatusText(text, number);
269}
270
271void wxFrameBase::SetStatusWidths(int n, const int widths_field[] )
272{
7c0ea335
VZ
273 wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") );
274
275 m_frameStatusBar->SetStatusWidths(n, widths_field);
276
277 PositionStatusBar();
278}
279
f6bcfd97
BP
280bool wxFrameBase::ShowMenuHelp(wxStatusBar *statbar, int menuId)
281{
3379ed37 282#if wxUSE_MENUS
f6bcfd97
BP
283 if ( !statbar )
284 return FALSE;
285
286 // if no help string found, we will clear the status bar text
287 wxString helpString;
288
289 if ( menuId != wxID_SEPARATOR && menuId != -2 /* wxID_TITLE */ )
290 {
291 wxMenuBar *menuBar = GetMenuBar();
292 if ( menuBar )
293 {
294 // it's ok if we don't find the item because it might belong
295 // to the popup menu
296 wxMenuItem *item = menuBar->FindItem(menuId);
297 if ( item )
298 helpString = item->GetHelp();
299 }
300 }
301
302 // set status text even if the string is empty - this will at least
303 // remove the string from the item which was previously selected
304 statbar->SetStatusText(helpString);
305
306 return !helpString.IsEmpty();
3379ed37
VZ
307#else // !wxUSE_MENUS
308 return FALSE;
309#endif // wxUSE_MENUS/!wxUSE_MENUS
f6bcfd97
BP
310}
311
7c0ea335
VZ
312#endif // wxUSE_STATUSBAR
313
314// ----------------------------------------------------------------------------
315// toolbar stuff
316// ----------------------------------------------------------------------------
317
318#if wxUSE_TOOLBAR
319
320wxToolBar* wxFrameBase::CreateToolBar(long style,
321 wxWindowID id,
322 const wxString& name)
323{
324 // the main toolbar can't be recreated (unless it was explicitly deeleted
325 // before)
326 wxCHECK_MSG( !m_frameToolBar, (wxToolBar *)NULL,
327 wxT("recreating toolbar in wxFrame") );
328
329 m_frameToolBar = OnCreateToolBar(style, id, name);
330
331 return m_frameToolBar;
332}
333
334wxToolBar* wxFrameBase::OnCreateToolBar(long style,
335 wxWindowID id,
336 const wxString& name)
337{
338 return new wxToolBar(this, id,
339 wxDefaultPosition, wxDefaultSize,
340 style, name);
341}
342
343#endif // wxUSE_TOOLBAR
344
345// ----------------------------------------------------------------------------
6522713c 346// menus
7c0ea335
VZ
347// ----------------------------------------------------------------------------
348
1e6feb95
VZ
349#if wxUSE_MENUS
350
63fec618 351// update all menus
7c0ea335 352void wxFrameBase::DoMenuUpdates()
63fec618 353{
54517652 354 wxMenuBar* bar = GetMenuBar();
e702ff0f 355
f0e9f0d3 356#ifdef __WXMSW__
e63fdcd6 357 wxWindow* focusWin = wxFindFocusDescendant((wxWindow*) this);
f0e9f0d3
JS
358#else
359 wxWindow* focusWin = (wxWindow*) NULL;
360#endif
7c0ea335 361 if ( bar != NULL )
54517652
RR
362 {
363 int nCount = bar->GetMenuCount();
364 for (int n = 0; n < nCount; n++)
e63fdcd6 365 DoMenuUpdates(bar->GetMenu(n), focusWin);
54517652 366 }
63fec618
VZ
367}
368
369// update a menu and all submenus recursively
e63fdcd6 370void wxFrameBase::DoMenuUpdates(wxMenu* menu, wxWindow* focusWin)
7c0ea335 371{
e63fdcd6 372 wxEvtHandler* evtHandler = focusWin ? focusWin->GetEventHandler() : GetEventHandler();
7c0ea335
VZ
373 wxMenuItemList::Node* node = menu->GetMenuItems().GetFirst();
374 while (node)
63fec618 375 {
7c0ea335
VZ
376 wxMenuItem* item = node->GetData();
377 if ( !item->IsSeparator() )
378 {
379 wxWindowID id = item->GetId();
380 wxUpdateUIEvent event(id);
381 event.SetEventObject( this );
382
383 if (evtHandler->ProcessEvent(event))
384 {
385 if (event.GetSetText())
386 menu->SetLabel(id, event.GetText());
387 if (event.GetSetChecked())
388 menu->Check(id, event.GetChecked());
389 if (event.GetSetEnabled())
390 menu->Enable(id, event.GetEnabled());
391 }
392
393 if (item->GetSubMenu())
394 DoMenuUpdates(item->GetSubMenu(), (wxWindow*) NULL);
395 }
396 node = node->GetNext();
63fec618 397 }
63fec618 398}
1e6feb95 399
6522713c
VZ
400void wxFrameBase::DetachMenuBar()
401{
402 if ( m_frameMenuBar )
403 {
404 m_frameMenuBar->Detach();
405 m_frameMenuBar = NULL;
406 }
407}
408
409void wxFrameBase::AttachMenuBar(wxMenuBar *menubar)
410{
411 if ( menubar )
412 {
6522713c 413 menubar->Attach((wxFrame *)this);
3dbe38c3 414 m_frameMenuBar = menubar;
6522713c
VZ
415 }
416}
417
418void wxFrameBase::SetMenuBar(wxMenuBar *menubar)
419{
420 if ( menubar == GetMenuBar() )
421 {
422 // nothing to do
423 return;
424 }
425
426 DetachMenuBar();
427
428 AttachMenuBar(menubar);
429}
430
1e6feb95 431#endif // wxUSE_MENUS