]> git.saurik.com Git - wxWidgets.git/commitdiff
Disable wxID_EXIT on PalmOS with all consequences in content of menu (separators...
authorWłodzimierz Skiba <abx@abx.art.pl>
Thu, 10 Mar 2005 19:59:01 +0000 (19:59 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Thu, 10 Mar 2005 19:59:01 +0000 (19:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/palmos/menu.h
include/wx/palmos/menuitem.h
src/palmos/menu.cpp
src/palmos/menuitem.cpp

index 99c09ff58433bf2f93a5f468872247b53ca08224..77ab82badcc5906716ae7f24f63be0d139f8d038 100644 (file)
@@ -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);
index bf44cca90f730d97ca2dd7b0d990712c8ba1b60c..a2c617f18ae445c348fd443b4325be5bca1dd2fd 100644 (file)
@@ -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);
index b519257812ada79e634d66fb4e67972bc7c68c93..de25c0492b4979c2ee8b8ae30733b5d227e3dce2 100644 (file)
     #include "wx/ownerdrw.h"
 #endif
 
-// other standard headers
-#include <string.h>
-
-#include <Menu.h>
-
 // ----------------------------------------------------------------------------
 // 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();
index eefc86eddf058ae76fc37608a7e8fec97cac343e..829cb94c1dd2100a0831e132c1ae9f1bf2b6239a 100644 (file)
@@ -72,7 +72,7 @@
 bool wxMenuItemStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & )
 {
     const wxMenuItem * mitem = dynamic_cast<const wxMenuItem*>(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
 // --------------