]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/menu.cpp
* Removed BASE_AND_GUI_MAC_SRC. At the moment DARWIN/MAC are identical
[wxWidgets.git] / src / msw / menu.cpp
index 659634d90a13020b54d1434fa0ec6072b0d77d57..761bd75da688df04f6affdaa9036af01433b52ba 100644 (file)
@@ -5,8 +5,8 @@
 // Modified by: Vadim Zeitlin
 // Created:     04/01/98
 // RCS-ID:      $Id$
-// Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:     wxWindows license
+// Copyright:   (c) Julian Smart
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ===========================================================================
@@ -163,7 +163,7 @@ void wxMenu::UpdateAccel(wxMenuItem *item)
     if ( item->IsSubMenu() )
     {
         wxMenu *submenu = item->GetSubMenu();
-        wxMenuItemList::Node *node = submenu->GetMenuItems().GetFirst();
+        wxMenuItemList::compatibility_iterator node = submenu->GetMenuItems().GetFirst();
         while ( node )
         {
             UpdateAccel(node->GetData());
@@ -329,7 +329,7 @@ bool wxMenu::DoAppend(wxMenuItem *item)
         {
             // we need to update its end item
             item->SetRadioGroupStart(m_startRadioGroup);
-            wxMenuItemList::Node *node = GetMenuItems().Item(m_startRadioGroup);
+            wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_startRadioGroup);
 
             if ( node )
             {
@@ -369,7 +369,7 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
 {
     // we need to find the items position in the child list
     size_t pos;
-    wxMenuItemList::Node *node = GetMenuItems().GetFirst();
+    wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
     for ( pos = 0; node; pos++ )
     {
         if ( node->GetData() == item )
@@ -557,6 +557,13 @@ wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[])
 
 wxMenuBar::~wxMenuBar()
 {
+    // we should free Windows resources only if Windows doesn't do it for us
+    // which happens if we're attached to a frame
+    if (m_hMenu && !IsAttached())
+    {
+        ::DestroyMenu((HMENU)m_hMenu);
+        m_hMenu = (WXHMENU)NULL;
+    }
 }
 
 // ---------------------------------------------------------------------------
@@ -583,11 +590,12 @@ WXHMENU wxMenuBar::Create()
     }
     else
     {
-        size_t count = GetMenuCount();
-        for ( size_t i = 0; i < count; i++ )
+        size_t count = GetMenuCount(), i;
+        wxMenuList::iterator it;
+        for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
         {
             if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING,
-                               (UINT)m_menus[i]->GetHMenu(),
+                               (UINT)(*it)->GetHMenu(),
                                m_titles[i]) )
             {
                 wxLogLastError(wxT("AppendMenu"));
@@ -673,7 +681,8 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
 {
     wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title);
     if ( !menuOld )
-        return FALSE;
+        return NULL;
+
     m_titles[pos] = title;
 
     if ( IsAttached() )
@@ -791,7 +800,7 @@ wxMenu *wxMenuBar::Remove(size_t pos)
         Refresh();
     }
 
-    m_titles.Remove(pos);
+    m_titles.RemoveAt(pos);
 
     return menu;
 }
@@ -803,9 +812,10 @@ void wxMenuBar::RebuildAccelTable()
     // merge the accelerators of all menus into one accel table
     size_t nAccelCount = 0;
     size_t i, count = GetMenuCount();
-    for ( i = 0; i < count; i++ )
+    wxMenuList::iterator it;
+    for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
     {
-        nAccelCount += m_menus[i]->GetAccelCount();
+        nAccelCount += (*it)->GetAccelCount();
     }
 
     if ( nAccelCount )
@@ -813,9 +823,9 @@ void wxMenuBar::RebuildAccelTable()
         wxAcceleratorEntry *accelEntries = new wxAcceleratorEntry[nAccelCount];
 
         nAccelCount = 0;
-        for ( i = 0; i < count; i++ )
+        for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
         {
-            nAccelCount += m_menus[i]->CopyAccels(&accelEntries[nAccelCount]);
+            nAccelCount += (*it)->CopyAccels(&accelEntries[nAccelCount]);
         }
 
         m_accelTable = wxAcceleratorTable(nAccelCount, accelEntries);
@@ -837,8 +847,6 @@ void wxMenuBar::Attach(wxFrame *frame)
 
 void wxMenuBar::Detach()
 {
-    m_hMenu = (WXHMENU)NULL;
-
     wxMenuBarBase::Detach();
 }