// headers
// ---------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "menu.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#if wxUSE_MENUS
+#include "wx/menu.h"
+
#ifndef WX_PRECOMP
#include "wx/frame.h"
- #include "wx/menu.h"
#include "wx/utils.h"
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/ownerdrw.h"
#endif
-// other standard headers
-#include <string.h>
-
+#include <Loader.h>
+#include <Form.h>
#include <Menu.h>
// ----------------------------------------------------------------------------
// implementation
// ============================================================================
-#include <wx/listimpl.cpp>
+#include "wx/listimpl.cpp"
-WX_DEFINE_LIST( wxMenuInfoList ) ;
+WX_DEFINE_LIST( wxMenuInfoList )
#if wxUSE_EXTENDED_RTTI
for( size_t i = 0 ; i < GetMenuCount() ; ++i )
{
wxMenuInfo* info = new wxMenuInfo() ;
- info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetLabelTop(i) ) ;
+ info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetMenuLabel(i) ) ;
list->Append( info ) ;
}
return m_menuInfos ;
{
}
-wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[])
+wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style))
{
}
// Palm OS does not have support for grayed or disabled items
}
-void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
+void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
{
wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
- m_titles[pos]=wxStripMenuCodes(label);
+ m_titles[pos] = label;
if ( !IsAttached() )
{
Refresh();
}
-wxString wxMenuBar::GetLabelTop(size_t pos) const
+wxString wxMenuBar::GetMenuLabel(size_t pos) const
{
wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
- wxT("invalid menu index in wxMenuBar::GetLabelTop") );
+ wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
- return wxMenuItem::GetLabelFromText(m_titles[pos]);
+ return m_titles[pos];
}
// ---------------------------------------------------------------------------
if ( !menuOld )
return NULL;
- m_titles[pos]=wxStripMenuCodes(title);
+ m_titles[pos] = title;
if ( IsAttached() )
{
if ( !wxMenuBarBase::Insert(pos, menu, title) )
return false;
- m_titles.Insert(wxStripMenuCodes(title), pos);
+ m_titles.Insert(title, pos);
if ( IsAttached() )
{
if ( !wxMenuBarBase::Append(menu, title) )
return false;
- m_titles.Add(wxStripMenuCodes(title));
+ m_titles.Add(title);
if(IsAttached())
{
void wxMenuBar::Attach(wxFrame *frame)
{
+ // before attaching preprocess menus to not include wxID_EXIT item
+ // as PalmOS guidelines suggest
+
+ wxMenuItem *item;
+ wxMenu *menu;
+ int i;
+
+ while( item = FindItem(wxID_EXIT) )
+ {
+ menu = item->GetMenu();
+ if( !menu ) break; // something broken ?
+
+ size_t count = menu->GetMenuItemCount();
+ if( count == 0 ) break; // something broken ?
+
+ // if EXIT is last item in menu
+ if( menu->FindItemByPosition( count - 1 ) == item )
+ {
+ menu->Destroy( item );
+
+ // was more than one item?
+ // was previous separator ?
+ if( count > 2 )
+ {
+ item = menu->FindItemByPosition( count - 2 );
+ if(item && item->IsSeparator())
+ menu->Destroy( item );
+ }
+ }
+
+ // if EXIT is first item in menu
+ else if( menu->FindItemByPosition( 0 ) == item )
+ {
+ menu->Destroy( item );
+
+ // was more than one item?
+ // was previous separator ?
+ if( count > 2 )
+ {
+ item = menu->FindItemByPosition( 0 );
+ if(item && item->IsSeparator())
+ menu->Destroy( item );
+ }
+ }
+
+ // if EXIT is in the middle but before and after are selectors
+ else
+ {
+ i = 1; // 0 case already done
+ while ( (i < count) && (menu->FindItemByPosition( 0 ) != item) )
+ {
+ i++;
+ }
+
+ if (i >= count) break;
+ if (menu->FindItemByPosition( i ) != item) break;
+ menu->Destroy( item );
+ item = menu->FindItemByPosition( i );
+ if ( item &&
+ item->IsSeparator() &&
+ menu->FindItemByPosition( i-1 )->IsSeparator() )
+ {
+ // noe need for two neighbouring separators
+ menu->Destroy( item );
+ }
+ }
+ }
+
+ // check if we received any empty menu!
+ i = 0;
+ while(i < GetMenuCount())
+ {
+ menu = GetMenu(i);
+
+ if( menu && (menu->GetMenuItemCount()==0) )
+ {
+ menu = Remove( i );
+ delete menu;
+ }
+ else
+ i++;
+ }
+
wxMenuBarBase::Attach(frame);
LoadMenu();