]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 649599 ] Fixes bug 610850: Inserting a menu
authorJulian Smart <julian@anthemion.co.uk>
Wed, 18 Dec 2002 21:23:25 +0000 (21:23 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Wed, 18 Dec 2002 21:23:25 +0000 (21:23 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18333 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/gtk/menu.cpp
src/gtk1/menu.cpp

index 7c6c222099fc8e9fa060435a0f09b15397d7679d..90fa8d1030a1a88ff1930e50c04a80d5b573eba2 100644 (file)
@@ -15,6 +15,10 @@ Unix:
 
 - fixed compilation on systems with zlib installed but < 1.1.3 version
 
+wxGTK:
+
+- fixed wxMenu::Remove (John Skiff and Benjamin Williams)
+
 All:
 
 - Implemented GetEditControl for wxGenericTreeCtrl (Peter
index 01e00de077a9b968dd1f6f3d75712dabc5cf3750..af7bc81726915262303304e8ccf597c1d874aede 100644 (file)
@@ -448,6 +448,36 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
     return menuOld;
 }
 
+static wxMenu *CopyMenu (wxMenu *menu)
+{
+    wxMenu *menucopy = new wxMenu ();
+    wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
+    while (node)
+    {
+        wxMenuItem *item = node->GetData();
+        int itemid = item->GetId();
+        wxString text = item->GetText();
+        text.Replace(wxT("_"), wxT("&"));
+        wxMenu *submenu = item->GetSubMenu();
+        if (!submenu)
+        {
+            wxMenuItem* itemcopy = new wxMenuItem(menucopy,
+                                        itemid, text,
+                                        menu->GetHelpString(itemid));
+            itemcopy->SetBitmap(item->GetBitmap());
+            itemcopy->SetCheckable(item->IsCheckable());
+            menucopy->Append(itemcopy);
+        }
+        else
+          menucopy->Append (itemid, text, CopyMenu(submenu),
+                            menu->GetHelpString(itemid));
+    
+        node = node->GetNext();
+    }
+  
+    return menucopy;
+}
+
 wxMenu *wxMenuBar::Remove(size_t pos)
 {
     wxMenu *menu = wxMenuBarBase::Remove(pos);
@@ -461,13 +491,17 @@ wxMenu *wxMenuBar::Remove(size_t pos)
     printf( "menu shell entries before %d\n", (int)g_list_length( menu_shell->children ) );
 */
 
+    wxMenu *menucopy = CopyMenu( menu );
+
     // unparent calls unref() and that would delete the widget so we raise
     // the ref count to 2 artificially before invoking unparent.
     gtk_widget_ref( menu->m_menu );
     gtk_widget_unparent( menu->m_menu );
 
     gtk_widget_destroy( menu->m_owner );
+    delete menu;
 
+    menu = menucopy;
 /*
     printf( "factory entries after %d\n", (int)g_slist_length(m_factory->items) );
     printf( "menu shell entries after %d\n", (int)g_list_length( menu_shell->children ) );
index 01e00de077a9b968dd1f6f3d75712dabc5cf3750..af7bc81726915262303304e8ccf597c1d874aede 100644 (file)
@@ -448,6 +448,36 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
     return menuOld;
 }
 
+static wxMenu *CopyMenu (wxMenu *menu)
+{
+    wxMenu *menucopy = new wxMenu ();
+    wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
+    while (node)
+    {
+        wxMenuItem *item = node->GetData();
+        int itemid = item->GetId();
+        wxString text = item->GetText();
+        text.Replace(wxT("_"), wxT("&"));
+        wxMenu *submenu = item->GetSubMenu();
+        if (!submenu)
+        {
+            wxMenuItem* itemcopy = new wxMenuItem(menucopy,
+                                        itemid, text,
+                                        menu->GetHelpString(itemid));
+            itemcopy->SetBitmap(item->GetBitmap());
+            itemcopy->SetCheckable(item->IsCheckable());
+            menucopy->Append(itemcopy);
+        }
+        else
+          menucopy->Append (itemid, text, CopyMenu(submenu),
+                            menu->GetHelpString(itemid));
+    
+        node = node->GetNext();
+    }
+  
+    return menucopy;
+}
+
 wxMenu *wxMenuBar::Remove(size_t pos)
 {
     wxMenu *menu = wxMenuBarBase::Remove(pos);
@@ -461,13 +491,17 @@ wxMenu *wxMenuBar::Remove(size_t pos)
     printf( "menu shell entries before %d\n", (int)g_list_length( menu_shell->children ) );
 */
 
+    wxMenu *menucopy = CopyMenu( menu );
+
     // unparent calls unref() and that would delete the widget so we raise
     // the ref count to 2 artificially before invoking unparent.
     gtk_widget_ref( menu->m_menu );
     gtk_widget_unparent( menu->m_menu );
 
     gtk_widget_destroy( menu->m_owner );
+    delete menu;
 
+    menu = menucopy;
 /*
     printf( "factory entries after %d\n", (int)g_slist_length(m_factory->items) );
     printf( "menu shell entries after %d\n", (int)g_list_length( menu_shell->children ) );