From 17131ffd751235d115e1ee3f1b38a88b5858d13e Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Thu, 10 Mar 2005 19:59:01 +0000 Subject: [PATCH] Disable wxID_EXIT on PalmOS with all consequences in content of menu (separators). Remove msw related code in wxPalmOS. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/palmos/menu.h | 10 ---- include/wx/palmos/menuitem.h | 5 -- src/palmos/menu.cpp | 88 ++++++++++++++++++++++++++++++++++-- src/palmos/menuitem.cpp | 8 +--- 4 files changed, 84 insertions(+), 27 deletions(-) diff --git a/include/wx/palmos/menu.h b/include/wx/palmos/menu.h index 99c09ff584..77ab82badc 100644 --- a/include/wx/palmos/menu.h +++ b/include/wx/palmos/menu.h @@ -76,8 +76,6 @@ public: // semi-private accessors // get the window which contains this menu wxWindow *GetWindow() const; - // get the menu handle - WXHMENU GetHMenu() const { return m_hMenu; } #if wxUSE_ACCEL // called by wxMenuBar to build its accel table from the accels of all menus @@ -108,9 +106,6 @@ private: // the position of the first item in the current radio group or -1 int m_startRadioGroup; - // the menu handle of this menu - WXHMENU m_hMenu; - #if wxUSE_ACCEL // the accelerators for our menu items wxAcceleratorArray m_accels; @@ -183,9 +178,6 @@ public: void RebuildAccelTable(); #endif // wxUSE_ACCEL - // get the menu handle - WXHMENU GetHMenu() const { return m_hMenu; } - // if the menubar is modified, the display is not updated automatically, // call this function to update it (m_menuBarFrame should be !NULL) void Refresh(); @@ -201,8 +193,6 @@ protected: wxArrayString m_titles ; wxMenuInfoList m_menuInfos; - WXHMENU m_hMenu; - // Return the Palm position for a wxMenu which is sometimes different from // the wxWidgets position. int PalmPositionForWxMenu(wxMenu *menu, int wxpos); diff --git a/include/wx/palmos/menuitem.h b/include/wx/palmos/menuitem.h index bf44cca90f..a2c617f18a 100644 --- a/include/wx/palmos/menuitem.h +++ b/include/wx/palmos/menuitem.h @@ -55,11 +55,6 @@ public: // wxMenuItemBase::IsCheckable() and wxOwnerDrawn::IsCheckable() bool IsCheckable() const { return wxMenuItemBase::IsCheckable(); } - // the id for a popup menu is really its menu handle (as required by - // ::AppendMenu() API), so this function will return either the id or the - // menu handle depending on what we're - int GetRealId() const; - // mark item as belonging to the given radio group void SetAsRadioGroupStart(); void SetRadioGroupStart(int start); diff --git a/src/palmos/menu.cpp b/src/palmos/menu.cpp index b519257812..de25c0492b 100644 --- a/src/palmos/menu.cpp +++ b/src/palmos/menu.cpp @@ -42,11 +42,6 @@ #include "wx/ownerdrw.h" #endif -// other standard headers -#include - -#include - // ---------------------------------------------------------------------------- // global variables // ---------------------------------------------------------------------------- @@ -654,6 +649,89 @@ void wxMenuBar::LoadMenu() 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(); diff --git a/src/palmos/menuitem.cpp b/src/palmos/menuitem.cpp index eefc86eddf..829cb94c1d 100644 --- a/src/palmos/menuitem.cpp +++ b/src/palmos/menuitem.cpp @@ -72,7 +72,7 @@ bool wxMenuItemStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & ) { const wxMenuItem * mitem = dynamic_cast(object) ; - if ( mitem->GetMenu() && !mitem->GetMenu()->GetTitle().IsEmpty() ) + if ( mitem->GetMenu() && !mitem->GetMenu()->GetTitle().empty() ) { // we don't stream out the first two items for menus with a title, they will be reconstructed if ( mitem->GetMenu()->FindItemByPosition(0) == mitem || mitem->GetMenu()->FindItemByPosition(1) == mitem ) @@ -155,12 +155,6 @@ wxMenuItem::~wxMenuItem() // misc // ---- -// return the id for calling Win32 API functions -int wxMenuItem::GetRealId() const -{ - return 0; -} - // get item state // -------------- -- 2.45.2