]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menu.cpp
more fixes to radio menu items: fixed Check() for them; allow separators inside the...
[wxWidgets.git] / src / os2 / menu.cpp
index e960818b45d16caef40f1236fc81aebf401ea9bd..2ed0039e5a644fc6a10026dbdb5fbfc6430a3436 100644 (file)
@@ -73,7 +73,7 @@ static wxString TextToLabel(const wxString& rTitle)
 {
     wxString Title;
     const wxChar *pc;
-    for (pc = rTitle; *pc != wxT('\0'); pc++ )
+    for (pc = rTitle.c_str(); *pc != wxT('\0'); pc++ )
     {
         if (*pc == wxT('&') )
         {
@@ -85,10 +85,6 @@ static wxString TextToLabel(const wxString& rTitle)
             else
                 Title << wxT('~');
         }
-//         else if (*pc == wxT('/'))
-//         {
-//             Title << wxT('\\');
-//         }
         else
         {
             if ( *pc == wxT('~') )
@@ -402,8 +398,64 @@ bool wxMenu::DoAppend(
   wxMenuItem*                       pItem
 )
 {
-    return wxMenuBase::DoAppend(pItem) && DoInsertOrAppend(pItem);
-}
+    wxCHECK_MSG( pItem, FALSE, _T("NULL item in wxMenu::DoAppend") );
+
+    bool                            bCheck = FALSE;
+
+    if (pItem->GetKind() == wxITEM_RADIO)
+    {
+        int                         nCount = GetMenuItemCount();
+
+        if (m_lStartRadioGroup == -1)
+        {
+            //
+            // Start a new radio group
+            //
+            m_lStartRadioGroup = lCount;
+
+            //
+            // For now it has just one element
+            //
+            pItem->SetAsRadioGroupStart();
+            pItem->SetRadioGroupEnd(m_startRadioGroup);
+
+            //
+            // Ensure that we have a checked item in the radio group
+            //
+            bCheck = TRUE;
+        }
+        else // extend the current radio group
+        {
+            //
+            // We need to update its end item
+            //
+            pItem->SetRadioGroupStart(m_lStartRadioGroup);
+            wxMenuItemList::Node *node = GetMenuItems().Item(m_startRadioGroup);
+
+            if (node)
+            {
+                node->GetData()->SetRadioGroupEnd(count);
+            }
+            else
+            {
+                wxFAIL_MSG( _T("where is the radio group start item?") );
+            }
+        }
+    }
+    else // not a radio item
+    {
+        EndRadioGroup();
+    }
+    if (!wxMenuBase::DoAppend(pItem) || !DoInsertOrAppend(pItem))
+    {
+        return FALSE;
+    }
+    if (bCheck)
+    {
+        pItem->Check(TRUE);
+    }
+    return TRUE;
+} // end of wxMenu::DoInsert
 
 bool wxMenu::DoInsert(
   size_t                            nPos
@@ -609,7 +661,12 @@ wxMenuItem* wxMenu::FindItem(
         }
         else if ( pItem->IsSubMenu() )
         {
-            pItem = pItem->GetSubMenu()->FindItem(nItemId, hItem, ppItemMenu);
+            pItem = pItem->GetSubMenu()->FindItem( nItemId
+                                                  ,hItem
+                                                  ,ppItemMenu
+                                                 );
+            if (pItem)
+                break;
         }
         else
         {
@@ -627,7 +684,7 @@ wxMenuItem* wxMenu::FindItem(
 void wxMenuBar::Init()
 {
     m_eventHandler = this;
-    m_pMenuBarFrame = NULL;
+    m_menuBarFrame = NULL;
     m_hMenu = 0;
 } // end of wxMenuBar::Init
 
@@ -672,7 +729,7 @@ void wxMenuBar::Refresh()
 {
     wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
 
-    WinSendMsg(GetWinHwnd(m_pMenuBarFrame), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
+    WinSendMsg(GetWinHwnd(m_menuBarFrame), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
 } // end of wxMenuBar::Refresh
 
 WXHMENU wxMenuBar::Create()
@@ -688,8 +745,8 @@ WXHMENU wxMenuBar::Create()
     //
     // Menubars should be associated with a frame otherwise they are popups
     //
-    if (m_pMenuBarFrame != NULL)
-        hFrame = GetWinHwnd(m_pMenuBarFrame);
+    if (m_menuBarFrame != NULL)
+        hFrame = GetWinHwnd(m_menuBarFrame);
     else
         hFrame = HWND_DESKTOP;
     //
@@ -899,8 +956,6 @@ bool wxMenuBar::Insert(
                     ,nPos
                    );
 
-    pMenu->Attach(this);
-
     if (IsAttached())
     {
         ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)Title.c_str());
@@ -968,7 +1023,6 @@ wxMenu* wxMenuBar::Remove(
     if (IsAttached())
     {
         ::WinSendMsg((HWND)GetHmenu(), MM_REMOVEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0);
-        pMenu->Detach();
 
 #if wxUSE_ACCEL
         if (pMenu->HasAccels())
@@ -1024,7 +1078,6 @@ void wxMenuBar::Attach(
 )
 {
     wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
-    m_pMenuBarFrame = pFrame;
 
 #if wxUSE_ACCEL
     RebuildAccelTable();
@@ -1043,7 +1096,7 @@ void wxMenuBar::Detach()
 {
     ::WinDestroyWindow((HWND)m_hMenu);
     m_hMenu = (WXHMENU)NULL;
-    m_pMenuBarFrame = NULL;
+    m_menuBarFrame = NULL;
 } // end of wxMenuBar::Detach
 
 // ---------------------------------------------------------------------------