]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menu.cpp
A few tweaks and cleanups
[wxWidgets.git] / src / os2 / menu.cpp
index 2ed0039e5a644fc6a10026dbdb5fbfc6430a3436..5f4ba30bb47daf25c52bb280980860776790cde6 100644 (file)
@@ -113,6 +113,7 @@ static wxString TextToLabel(const wxString& rTitle)
 void wxMenu::Init()
 {
     m_bDoBreak = FALSE;
+    m_nStartRadioGroup = -1;
 
     //
     // Create the menu (to be used as a submenu or a popup)
@@ -174,9 +175,7 @@ wxMenu::~wxMenu()
     //
     // Delete accels
     //
-#if (!(defined(__VISAGECPP__) && (__IBMCPP__ < 400 || __IBMC__ < 400 )))
     WX_CLEAR_ARRAY(m_vAccels);
-#endif
 #endif // wxUSE_ACCEL
 } // end of wxMenu::~wxMenu
 
@@ -186,6 +185,14 @@ void wxMenu::Break()
     m_bDoBreak = TRUE;
 } // end of wxMenu::Break
 
+void wxMenu::Attach(
+  wxMenuBarBase*                    pMenubar
+)
+{
+    wxMenuBase::Attach(pMenubar);
+    EndRadioGroup();
+} // end of wxMenu::Break;
+
 #if wxUSE_ACCEL
 
 int wxMenu::FindAccel(
@@ -196,10 +203,8 @@ int wxMenu::FindAccel(
     size_t                          nCount = m_vAccels.GetCount();
 
     for (n = 0; n < nCount; n++)
-    {
         if (m_vAccels[n]->m_command == nId)
             return n;
-    }
     return wxNOT_FOUND;
 } // end of wxMenu::FindAccel
 
@@ -207,45 +212,58 @@ void wxMenu::UpdateAccel(
   wxMenuItem*                       pItem
 )
 {
-    //
-    // Find the (new) accel for this item
-    //
-    wxAcceleratorEntry*             pAccel = wxGetAccelFromString(pItem->GetText());
-
-    if (pAccel)
-        pAccel->m_command = pItem->GetId();
-
-    //
-    // Find the old one
-    //
-    int                             n = FindAccel(pItem->GetId());
+    if (pItem->IsSubMenu())
+    {
+        wxMenu*                     pSubmenu = pItem->GetSubMenu();
+        wxMenuItemList::Node*       pNode = pSubmenu->GetMenuItems().GetFirst();
 
-    if (n == wxNOT_FOUND)
+        while (pNode)
+        {
+            UpdateAccel(pNode->GetData());
+            pNode = pNode->GetNext();
+        }
+    }
+    else if (!pItem->IsSeparator())
     {
         //
-        // No old, add new if any
+        // Find the (new) accel for this item
         //
+        wxAcceleratorEntry*         pAccel = wxGetAccelFromString(pItem->GetText());
+
         if (pAccel)
-            m_vAccels.Add(pAccel);
-        else
-            return;     // skipping RebuildAccelTable() below
-    }
-    else
-    {
+            pAccel->m_command = pItem->GetId();
+
         //
-        // Replace old with new or just remove the old one if no new
+        // Find the old one
         //
-        delete                      m_vAccels[n];
+        size_t                      n = FindAccel(pItem->GetId());
 
-        if (pAccel)
-            m_vAccels[n] = pAccel;
+        if (n == wxNOT_FOUND)
+        {
+            //
+            // No old, add new if any
+            //
+            if (pAccel)
+                m_vAccels.Add(pAccel);
+            else
+                return;
+        }
         else
-            m_vAccels.RemoveAt(n);
-    }
+        {
+            //
+            // Replace old with new or just remove the old one if no new
+            //
+            delete m_vAccels[n];
+            if (pAccel)
+                m_vAccels[n] = pAccel;
+            else
+                m_vAccels.RemoveAt(n);
+        }
 
-    if (IsAttached())
-    {
-        m_menuBar->RebuildAccelTable();
+        if (IsAttached())
+        {
+            m_menuBar->RebuildAccelTable();
+        }
     }
 } // wxMenu::UpdateAccel
 
@@ -259,6 +277,10 @@ bool wxMenu::DoInsertOrAppend(
 , size_t                            nPos
 )
 {
+    wxMenu*                         pSubmenu = pItem->GetSubMenu();
+    MENUITEM&                       rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData:
+                                            pItem->m_vMenuData;
+
     ERRORID                         vError;
     wxString                        sError;
     char                            zMsg[128];
@@ -271,9 +293,6 @@ bool wxMenu::DoInsertOrAppend(
     // MENUITEM for submenus as required by ::MM_INSERTITEM message API
     //
 
-    wxMenu*                         pSubmenu = pItem->GetSubMenu();
-    MENUITEM&                       rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData:
-                                            pItem->m_vMenuData;
     if(pSubmenu != NULL)
     {
         wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
@@ -394,6 +413,14 @@ bool wxMenu::DoInsertOrAppend(
     return FALSE;
 } // end of wxMenu::DoInsertOrAppend
 
+void wxMenu::EndRadioGroup()
+{
+    //
+    // We're not inside a radio group any longer
+    //
+    m_nStartRadioGroup = -1;
+} // end of wxMenu::EndRadioGroup
+
 bool wxMenu::DoAppend(
   wxMenuItem*                       pItem
 )
@@ -406,18 +433,18 @@ bool wxMenu::DoAppend(
     {
         int                         nCount = GetMenuItemCount();
 
-        if (m_lStartRadioGroup == -1)
+        if (m_nStartRadioGroup == -1)
         {
             //
             // Start a new radio group
             //
-            m_lStartRadioGroup = lCount;
+            m_nStartRadioGroup = nCount;
 
             //
             // For now it has just one element
             //
             pItem->SetAsRadioGroupStart();
-            pItem->SetRadioGroupEnd(m_startRadioGroup);
+            pItem->SetRadioGroupEnd(m_nStartRadioGroup);
 
             //
             // Ensure that we have a checked item in the radio group
@@ -429,12 +456,13 @@ bool wxMenu::DoAppend(
             //
             // We need to update its end item
             //
-            pItem->SetRadioGroupStart(m_lStartRadioGroup);
-            wxMenuItemList::Node *node = GetMenuItems().Item(m_startRadioGroup);
+            pItem->SetRadioGroupStart(m_nStartRadioGroup);
+
+            wxMenuItemList::Node*   pNode = GetMenuItems().Item(m_nStartRadioGroup);
 
-            if (node)
+            if (pNode)
             {
-                node->GetData()->SetRadioGroupEnd(count);
+                pNode->GetData()->SetRadioGroupEnd(nCount);
             }
             else
             {
@@ -446,16 +474,20 @@ bool wxMenu::DoAppend(
     {
         EndRadioGroup();
     }
+
     if (!wxMenuBase::DoAppend(pItem) || !DoInsertOrAppend(pItem))
     {
         return FALSE;
     }
     if (bCheck)
     {
+        //
+        // Check the item initially
+        //
         pItem->Check(TRUE);
     }
     return TRUE;
-} // end of wxMenu::DoInsert
+} // end of wxMenu::DoAppend
 
 bool wxMenu::DoInsert(
   size_t                            nPos
@@ -466,7 +498,8 @@ bool wxMenu::DoInsert(
                                   ,pItem) &&
              DoInsertOrAppend( pItem
                               ,nPos
-                             ));
+                             )
+           );
 } // end of wxMenu::DoInsert
 
 wxMenuItem* wxMenu::DoRemove(
@@ -1077,7 +1110,7 @@ void wxMenuBar::Attach(
   wxFrame*                          pFrame
 )
 {
-    wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
+    wxMenuBarBase::Attach(pFrame);
 
 #if wxUSE_ACCEL
     RebuildAccelTable();
@@ -1085,8 +1118,8 @@ void wxMenuBar::Attach(
     // Ensure the accelerator table is set to the frame (not the client!)
     //
     if (!::WinSetAccelTable( vHabmain
-                            ,(HWND)pFrame->GetHWND()
                             ,m_vAccelTable.GetHACCEL()
+                            ,(HWND)pFrame->GetFrame()
                            ))
         wxLogLastError("WinSetAccelTable");
 #endif // wxUSE_ACCEL