1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        common/framecmn.cpp 
   3 // Purpose:     common (for all platforms) wxFrame functions 
   4 // Author:      Julian Smart, Vadim Zeitlin 
   7 // Copyright:   (c) 1998 Robert Roebling, Julian Smart and Markus Holzem 
   8 // Licence:     wxWindows licence 
   9 ///////////////////////////////////////////////////////////////////////////// 
  11 // ============================================================================ 
  13 // ============================================================================ 
  15 // ---------------------------------------------------------------------------- 
  17 // ---------------------------------------------------------------------------- 
  20     #pragma implementation "framebase.h" 
  23 // For compilers that support precompilation, includes "wx.h". 
  24 #include "wx/wxprec.h" 
  33     #include "wx/menuitem.h" 
  34     #include "wx/dcclient.h" 
  38     #include "wx/toolbar.h" 
  41     #include "wx/statusbr.h" 
  44 // FIXME - temporary hack in absence of wxTLW in all ports! 
  45 #ifndef wxTopLevelWindowNative 
  46     #define wxTopLevelWindow wxTopLevelWindowBase 
  49 // ---------------------------------------------------------------------------- 
  51 // ---------------------------------------------------------------------------- 
  53 BEGIN_EVENT_TABLE(wxFrameBase
, wxTopLevelWindow
) 
  54     EVT_IDLE(wxFrameBase::OnIdle
) 
  55     EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight
) 
  58 // ============================================================================ 
  60 // ============================================================================ 
  62 // ---------------------------------------------------------------------------- 
  63 // construction/destruction 
  64 // ---------------------------------------------------------------------------- 
  66 wxFrameBase::wxFrameBase() 
  69     m_frameMenuBar 
= NULL
; 
  73     m_frameToolBar 
= NULL
; 
  74 #endif // wxUSE_TOOLBAR 
  77     m_frameStatusBar 
= NULL
; 
  78 #endif // wxUSE_STATUSBAR 
  81 wxFrameBase::~wxFrameBase() 
  83     // this destructor is required for Darwin 
  86 wxFrame 
*wxFrameBase::New(wxWindow 
*parent
, 
  88                           const wxString
& title
, 
  94     return new wxFrame(parent
, id
, title
, pos
, size
, style
, name
); 
  97 void wxFrameBase::DeleteAllBars() 
 100     if ( m_frameMenuBar 
) 
 102         delete m_frameMenuBar
; 
 103         m_frameMenuBar 
= (wxMenuBar 
*) NULL
; 
 105 #endif // wxUSE_MENUS 
 108     if ( m_frameStatusBar 
) 
 110         delete m_frameStatusBar
; 
 111         m_frameStatusBar 
= (wxStatusBar 
*) NULL
; 
 113 #endif // wxUSE_STATUSBAR 
 116     if ( m_frameToolBar 
) 
 118         delete m_frameToolBar
; 
 119         m_frameToolBar 
= (wxToolBar 
*) NULL
; 
 121 #endif // wxUSE_TOOLBAR 
 124 bool wxFrameBase::IsOneOfBars(const wxWindow 
*win
) const 
 127     if ( win 
== GetMenuBar() ) 
 129 #endif // wxUSE_MENUS 
 132     if ( win 
== GetStatusBar() ) 
 134 #endif // wxUSE_STATUSBAR 
 137     if ( win 
== GetToolBar() ) 
 139 #endif // wxUSE_TOOLBAR 
 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 
 148 // ---------------------------------------------------------------------------- 
 150 // get the origin of the client area in the client coordinates 
 151 wxPoint 
wxFrameBase::GetClientAreaOrigin() const 
 153     wxPoint pt 
= wxTopLevelWindow::GetClientAreaOrigin(); 
 155 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) 
 156     wxToolBar 
*toolbar 
= GetToolBar(); 
 157     if ( toolbar 
&& toolbar
->IsShown() ) 
 160         toolbar
->GetSize(&w
, &h
); 
 162         if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL 
) 
 171 #endif // wxUSE_TOOLBAR 
 176 // ---------------------------------------------------------------------------- 
 178 // ---------------------------------------------------------------------------- 
 180 bool wxFrameBase::ProcessCommand(int id
) 
 183     wxMenuBar 
*bar 
= GetMenuBar(); 
 187     wxCommandEvent 
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
); 
 188     commandEvent
.SetEventObject(this); 
 190     wxMenuItem 
*item 
= bar
->FindItem(id
); 
 193         if (!item
->IsEnabled()) 
 196         if (item
->IsCheckable()) 
 201             commandEvent
.SetInt(item
->IsChecked()); 
 205     return GetEventHandler()->ProcessEvent(commandEvent
); 
 206 #else // !wxUSE_MENUS 
 208 #endif // wxUSE_MENUS/!wxUSE_MENUS 
 211 // ---------------------------------------------------------------------------- 
 213 // ---------------------------------------------------------------------------- 
 215 void wxFrameBase::OnMenuHighlight(wxMenuEvent
& event
) 
 218     (void)ShowMenuHelp(GetStatusBar(), event
.GetMenuId()); 
 219 #endif // wxUSE_STATUSBAR 
 222 void wxFrameBase::OnIdle(wxIdleEvent
& WXUNUSED(event
) ) 
 226 #endif // wxUSE_MENUS 
 229 // ---------------------------------------------------------------------------- 
 231 // ---------------------------------------------------------------------------- 
 235 wxStatusBar
* wxFrameBase::CreateStatusBar(int number
, 
 238                                           const wxString
& name
) 
 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") ); 
 245     m_frameStatusBar 
= OnCreateStatusBar( number
, style
, id
, name 
); 
 246     if ( m_frameStatusBar 
) 
 249     return m_frameStatusBar
; 
 252 wxStatusBar 
*wxFrameBase::OnCreateStatusBar(int number
, 
 255                                             const wxString
& name
) 
 257     wxStatusBar 
*statusBar 
= new wxStatusBar(this, id
, style
, name
); 
 259     statusBar
->SetFieldsCount(number
); 
 264 void wxFrameBase::SetStatusText(const wxString
& text
, int number
) 
 266     wxCHECK_RET( m_frameStatusBar 
!= NULL
, wxT("no statusbar to set text for") ); 
 268     m_frameStatusBar
->SetStatusText(text
, number
); 
 271 void wxFrameBase::SetStatusWidths(int n
, const int widths_field
[] ) 
 273     wxCHECK_RET( m_frameStatusBar 
!= NULL
, wxT("no statusbar to set widths for") ); 
 275     m_frameStatusBar
->SetStatusWidths(n
, widths_field
); 
 280 bool wxFrameBase::ShowMenuHelp(wxStatusBar 
*statbar
, int menuId
) 
 286     // if no help string found, we will clear the status bar text 
 289     if ( menuId 
!= wxID_SEPARATOR 
&& menuId 
!= -2 /* wxID_TITLE */ ) 
 291         wxMenuBar 
*menuBar 
= GetMenuBar(); 
 294             // it's ok if we don't find the item because it might belong 
 296             wxMenuItem 
*item 
= menuBar
->FindItem(menuId
); 
 298                 helpString 
= item
->GetHelp(); 
 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
); 
 306     return !helpString
.IsEmpty(); 
 307 #else // !wxUSE_MENUS 
 309 #endif // wxUSE_MENUS/!wxUSE_MENUS 
 312 #endif // wxUSE_STATUSBAR 
 314 // ---------------------------------------------------------------------------- 
 316 // ---------------------------------------------------------------------------- 
 320 wxToolBar
* wxFrameBase::CreateToolBar(long style
, 
 322                                       const wxString
& name
) 
 324     // the main toolbar can't be recreated (unless it was explicitly deeleted 
 326     wxCHECK_MSG( !m_frameToolBar
, (wxToolBar 
*)NULL
, 
 327                  wxT("recreating toolbar in wxFrame") ); 
 329     m_frameToolBar 
= OnCreateToolBar(style
, id
, name
); 
 331     return m_frameToolBar
; 
 334 wxToolBar
* wxFrameBase::OnCreateToolBar(long style
, 
 336                                         const wxString
& name
) 
 338     return new wxToolBar(this, id
, 
 339                          wxDefaultPosition
, wxDefaultSize
, 
 343 #endif // wxUSE_TOOLBAR 
 345 // ---------------------------------------------------------------------------- 
 347 // ---------------------------------------------------------------------------- 
 352 void wxFrameBase::DoMenuUpdates() 
 354     wxMenuBar
* bar 
= GetMenuBar(); 
 357     wxWindow
* focusWin 
= wxFindFocusDescendant((wxWindow
*) this); 
 359     wxWindow
* focusWin 
= (wxWindow
*) NULL
; 
 363         int nCount 
= bar
->GetMenuCount(); 
 364         for (int n 
= 0; n 
< nCount
; n
++) 
 365             DoMenuUpdates(bar
->GetMenu(n
), focusWin
); 
 369 // update a menu and all submenus recursively 
 370 void wxFrameBase::DoMenuUpdates(wxMenu
* menu
, wxWindow
* focusWin
) 
 372     wxEvtHandler
* evtHandler 
= focusWin 
? focusWin
->GetEventHandler() : GetEventHandler(); 
 373     wxMenuItemList::Node
* node 
= menu
->GetMenuItems().GetFirst(); 
 376         wxMenuItem
* item 
= node
->GetData(); 
 377         if ( !item
->IsSeparator() ) 
 379             wxWindowID id 
= item
->GetId(); 
 380             wxUpdateUIEvent 
event(id
); 
 381             event
.SetEventObject( this ); 
 383             if (evtHandler
->ProcessEvent(event
)) 
 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()); 
 393             if (item
->GetSubMenu()) 
 394                 DoMenuUpdates(item
->GetSubMenu(), (wxWindow
*) NULL
); 
 396         node 
= node
->GetNext(); 
 400 void wxFrameBase::DetachMenuBar() 
 402     if ( m_frameMenuBar 
) 
 404         m_frameMenuBar
->Detach(); 
 405         m_frameMenuBar 
= NULL
; 
 409 void wxFrameBase::AttachMenuBar(wxMenuBar 
*menubar
) 
 413         menubar
->Attach((wxFrame 
*)this); 
 414         m_frameMenuBar 
= menubar
; 
 418 void wxFrameBase::SetMenuBar(wxMenuBar 
*menubar
) 
 420     if ( menubar 
== GetMenuBar() ) 
 428     AttachMenuBar(menubar
); 
 431 #endif // wxUSE_MENUS