]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menu.cpp
Build fixes.
[wxWidgets.git] / src / os2 / menu.cpp
index 1b8c4885c9baedca960767e480140ae9f3f33eb4..ccb4be42512ae2669bbadb1fb340756d15e2052f 100644 (file)
@@ -47,16 +47,12 @@ extern wxMenu*                      wxCurrentPopupMenu;
 //
 // The (popup) menu title has this special id
 //
-static const int                    idMenuTitle = -2;
+static const int                    idMenuTitle = -3;
 
 //
 // The unique ID for Menus
 //
-#ifdef __VISAGECPP__
 USHORT                              wxMenu::m_nextMenuId = 0;
-#else
-static USHORT                       wxMenu::m_nextMenuId = 0;
-#endif
 
 // ----------------------------------------------------------------------------
 // macros
@@ -65,47 +61,6 @@ static USHORT                       wxMenu::m_nextMenuId = 0;
     IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
     IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
 
-// ----------------------------------------------------------------------------
-// static function for translating menu labels
-// ----------------------------------------------------------------------------
-
-static wxString TextToLabel(
-  const wxString&                   rsTitle
-)
-{
-    wxString                        sTitle = "";
-    const wxChar*                   zPc;
-
-    if (rsTitle.IsEmpty())
-        return sTitle;
-    for (zPc = rsTitle.c_str(); *zPc != wxT('\0'); zPc++ )
-    {
-        if (*zPc == wxT('&') )
-        {
-            if (*(zPc + 1) == wxT('&'))
-            {
-                zPc++;
-                sTitle << wxT('&');
-            }
-            else
-                sTitle << wxT('~');
-        }
-        else
-        {
-            if ( *zPc == wxT('~') )
-            {
-                //
-                // Tildes must be doubled to prevent them from being
-                // interpreted as accelerator character prefix by PM ???
-                //
-                sTitle << *zPc;
-            }
-            sTitle << *zPc;
-        }
-    }
-    return sTitle;
-} // end of TextToLabel
-
 // ============================================================================
 // implementation
 // ============================================================================
@@ -224,12 +179,12 @@ void wxMenu::UpdateAccel(
     if (pItem->IsSubMenu())
     {
         wxMenu*                     pSubmenu = pItem->GetSubMenu();
-        wxMenuItemList::Node*       pNode = pSubmenu->GetMenuItems().GetFirst();
+        wxMenuItemList::compatibility_iterator node = pSubmenu->GetMenuItems().GetFirst();
 
-        while (pNode)
+        while (node)
         {
-            UpdateAccel(pNode->GetData());
-            pNode = pNode->GetNext();
+            UpdateAccel(node->GetData());
+            node = node->GetNext();
         }
     }
     else if (!pItem->IsSeparator())
@@ -247,7 +202,7 @@ void wxMenu::UpdateAccel(
         //
         size_t                      n = FindAccel(pItem->GetId());
 
-        if (n == wxNOT_FOUND)
+        if (n == (size_t)wxNOT_FOUND)
         {
             //
             // No old, add new if any
@@ -271,7 +226,7 @@ void wxMenu::UpdateAccel(
 
         if (IsAttached())
         {
-            m_menuBar->RebuildAccelTable();
+            GetMenuBar()->RebuildAccelTable();
         }
     }
 } // wxMenu::UpdateAccel
@@ -292,7 +247,6 @@ bool wxMenu::DoInsertOrAppend(
 
     ERRORID                         vError;
     wxString                        sError;
-    char                            zMsg[128];
 
 #if wxUSE_ACCEL
     UpdateAccel(pItem);
@@ -308,16 +262,10 @@ bool wxMenu::DoInsertOrAppend(
         m_bDoBreak = FALSE;
     }
 
-    if (pItem->IsSeparator())
-    {
-        rItem.afStyle |= MIS_SEPARATOR;
-    }
-
     //
     // Id is the numeric id for normal menu items and HMENU for submenus as
     // required by ::MM_INSERTITEM message API
     //
-
     if (pSubmenu != NULL)
     {
         wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
@@ -332,7 +280,7 @@ bool wxMenu::DoInsertOrAppend(
         rItem.id = pItem->GetId();
     }
 
-    BYTE*                           pData;
+    BYTE*                           pData=NULL;
 
 #if wxUSE_OWNER_DRAWN
     if (pItem->IsOwnerDrawn())
@@ -350,11 +298,24 @@ bool wxMenu::DoInsertOrAppend(
     }
     else
 #endif
+    if (pItem->IsSeparator())
     {
-        //
-        // Menu is just a normal string (passed in data parameter)
-        //
-        rItem.afStyle |= MIS_TEXT;
+        rItem.afStyle = MIS_SEPARATOR;
+    }
+    else
+    {
+        if (pItem->GetId() == idMenuTitle)
+        {
+            // Item is an unselectable title to be passed via pData
+            rItem.afStyle = MIS_STATIC;
+        }
+        else
+        {
+            //
+            // Menu is just a normal string (passed in data parameter)
+            //
+            rItem.afStyle |= MIS_TEXT;
+        }
         pData = (char*)pItem->GetText().c_str();
     }
 
@@ -377,7 +338,6 @@ bool wxMenu::DoInsertOrAppend(
 #if wxUSE_OWNER_DRAWN
     if (pItem->IsOwnerDrawn())
     {
-        BOOL                       rc;
         MENUITEM                   vMenuItem;
 
         ::WinSendMsg( GetHmenu()
@@ -389,7 +349,7 @@ bool wxMenu::DoInsertOrAppend(
                     );
     }
 #endif
-    if (rc == MIT_MEMERROR || rc == MIT_ERROR)
+    if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
     {
         vError = ::WinGetLastError(vHabmain);
         sError = wxPMErrorToStr(vError);
@@ -402,9 +362,9 @@ bool wxMenu::DoInsertOrAppend(
         //
         // If we're already attached to the menubar, we must update it
         //
-        if (IsAttached() && m_menuBar->IsAttached())
+        if (IsAttached() && GetMenuBar()->IsAttached())
         {
-            m_menuBar->Refresh();
+            GetMenuBar()->Refresh();
         }
         return TRUE;
     }
@@ -419,11 +379,11 @@ void wxMenu::EndRadioGroup()
     m_nStartRadioGroup = -1;
 } // end of wxMenu::EndRadioGroup
 
-bool wxMenu::DoAppend(
+wxMenuItem* wxMenu::DoAppend(
   wxMenuItem*                       pItem
 )
 {
-    wxCHECK_MSG( pItem, FALSE, _T("NULL item in wxMenu::DoAppend") );
+    wxCHECK_MSG( pItem, NULL, _T("NULL item in wxMenu::DoAppend") );
 
     bool                            bCheck = FALSE;
 
@@ -456,11 +416,11 @@ bool wxMenu::DoAppend(
             //
             pItem->SetRadioGroupStart(m_nStartRadioGroup);
 
-            wxMenuItemList::Node*   pNode = GetMenuItems().Item(m_nStartRadioGroup);
+            wxMenuItemList::compatibility_iterator node = GetMenuItems().Item(m_nStartRadioGroup);
 
-            if (pNode)
+            if (node)
             {
-                pNode->GetData()->SetRadioGroupEnd(nCount);
+                node->GetData()->SetRadioGroupEnd(nCount);
             }
             else
             {
@@ -475,7 +435,7 @@ bool wxMenu::DoAppend(
 
     if (!wxMenuBase::DoAppend(pItem) || !DoInsertOrAppend(pItem))
     {
-        return FALSE;
+        return NULL;
     }
     if (bCheck)
     {
@@ -484,20 +444,22 @@ bool wxMenu::DoAppend(
         //
         pItem->Check(TRUE);
     }
-    return TRUE;
+    return pItem;
 } // end of wxMenu::DoAppend
 
-bool wxMenu::DoInsert(
+wxMenuItem* wxMenu::DoInsert(
   size_t                            nPos
 , wxMenuItem*                       pItem
 )
 {
-    return ( wxMenuBase::DoInsert( nPos
-                                  ,pItem) &&
+    if ( wxMenuBase::DoInsert( nPos
+                               ,pItem) &&
              DoInsertOrAppend( pItem
                               ,nPos
-                             )
-           );
+                 ))
+         return pItem;
+    else
+        return NULL;
 } // end of wxMenu::DoInsert
 
 wxMenuItem* wxMenu::DoRemove(
@@ -508,19 +470,19 @@ wxMenuItem* wxMenu::DoRemove(
     // We need to find the items position in the child list
     //
     size_t                          nPos;
-    wxMenuItemList::Node*           pNode = GetMenuItems().GetFirst();
+    wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
 
-    for (nPos = 0; pNode; nPos++)
+    for (nPos = 0; node; nPos++)
     {
-        if (pNode->GetData() == pItem)
+        if (node->GetData() == pItem)
             break;
-        pNode = pNode->GetNext();
+        node = node->GetNext();
     }
 
     //
     // DoRemove() (unlike Remove) can only be called for existing item!
     //
-    wxCHECK_MSG(pNode, NULL, wxT("bug in wxMenu::Remove logic"));
+    wxCHECK_MSG(node, NULL, wxT("bug in wxMenu::Remove logic"));
 
 #if wxUSE_ACCEL
     //
@@ -543,12 +505,12 @@ wxMenuItem* wxMenu::DoRemove(
                  ,MPFROM2SHORT(pItem->GetId(), TRUE)
                  ,(MPARAM)0
                 );
-    if (IsAttached() && m_menuBar->IsAttached())
+    if (IsAttached() && GetMenuBar()->IsAttached())
     {
         //
         // Otherwise, the chane won't be visible
         //
-        m_menuBar->Refresh();
+        GetMenuBar()->Refresh();
     }
 
     //
@@ -645,7 +607,7 @@ bool wxMenu::OS2Command(
         SendEvent( vId
                   ,(int)::WinSendMsg( GetHmenu()
                                      ,MM_QUERYITEMATTR
-                                     ,(MPARAM)vId
+                                     ,MPFROMSHORT(vId)
                                      ,(MPARAM)MIA_CHECKED
                                     )
                  );
@@ -661,8 +623,8 @@ wxWindow* wxMenu::GetWindow() const
 {
     if (m_invokingWindow != NULL)
         return m_invokingWindow;
-    else if ( m_menuBar != NULL)
-        return m_menuBar->GetFrame();
+    else if ( GetMenuBar() != NULL)
+        return GetMenuBar()->GetFrame();
 
     return NULL;
 } // end of wxMenu::GetWindow
@@ -679,7 +641,7 @@ wxMenuItem* wxMenu::FindItem(
 
     wxMenuItem*                     pItem = NULL;
 
-    for ( wxMenuItemList::Node *node = m_items.GetFirst();
+    for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
           node && !pItem;
           node = node->GetNext() )
     {
@@ -774,7 +736,6 @@ void wxMenuBar::Refresh()
 
 WXHMENU wxMenuBar::Create()
 {
-    MENUITEM                        vItem;
     HWND                            hFrame;
 
     if (m_hMenu != 0 )
@@ -811,9 +772,9 @@ WXHMENU wxMenuBar::Create()
     }
     else
     {
-        size_t                      nCount = GetMenuCount();
-
-        for (size_t i = 0; i < nCount; i++)
+        size_t                      nCount = GetMenuCount(), i;
+       wxMenuList::iterator it;
+        for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
         {
             APIRET                  rc;
             ERRORID                 vError;
@@ -823,8 +784,8 @@ WXHMENU wxMenuBar::Create()
             //
             // Set the parent and owner of the submenues to be the menubar, not the desktop
             //
-            hSubMenu = m_menus[i]->m_vMenuData.hwndSubMenu;
-            if (!::WinSetParent(m_menus[i]->m_vMenuData.hwndSubMenu, m_hMenu, FALSE))
+            hSubMenu = (*it)->m_vMenuData.hwndSubMenu;
+            if (!::WinSetParent((*it)->m_vMenuData.hwndSubMenu, m_hMenu, FALSE))
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
@@ -832,7 +793,7 @@ WXHMENU wxMenuBar::Create()
                 return NULLHANDLE;
             }
 
-            if (!::WinSetOwner(m_menus[i]->m_vMenuData.hwndSubMenu, m_hMenu))
+            if (!::WinSetOwner((*it)->m_vMenuData.hwndSubMenu, m_hMenu))
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
@@ -840,10 +801,10 @@ WXHMENU wxMenuBar::Create()
                 return NULLHANDLE;
             }
 
-            m_menus[i]->m_vMenuData.iPosition = i;
+            (*it)->m_vMenuData.iPosition = i;
 
-            rc = (APIRET)::WinSendMsg(m_hMenu, MM_INSERTITEM, (MPARAM)&m_menus[i]->m_vMenuData, (MPARAM)m_titles[i].c_str());
-            if (rc == MIT_MEMERROR || rc == MIT_ERROR)
+            rc = (APIRET)::WinSendMsg(m_hMenu, MM_INSERTITEM, (MPARAM)&(*it)->m_vMenuData, (MPARAM)m_titles[i].c_str());
+            if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
@@ -944,7 +905,7 @@ wxMenu* wxMenuBar::Replace(
 )
 {
     SHORT                            nId;
-    wxString                         sTitle = TextToLabel(rTitle);
+    wxString                         sTitle = wxPMTextToLabel(rTitle);
     wxMenu*                          pMenuOld = wxMenuBarBase::Replace( nPos
                                                                        ,pMenu
                                                                        ,sTitle
@@ -985,7 +946,7 @@ bool wxMenuBar::Insert(
 , const wxString&                   rTitle
 )
 {
-    wxString                        sTitle = TextToLabel(rTitle);
+    wxString                        sTitle = wxPMTextToLabel(rTitle);
 
     if (!wxMenuBarBase::Insert( nPos
                                ,pMenu
@@ -1026,7 +987,7 @@ bool wxMenuBar::Append(
 
     wxCHECK_MSG(hSubmenu, FALSE, wxT("can't append invalid menu to menubar"));
 
-    wxString                        sTitle = TextToLabel(rsTitle);
+    wxString                        sTitle = wxPMTextToLabel(rsTitle);
 
     if (!wxMenuBarBase::Append(pMenu, sTitle))
         return FALSE;
@@ -1090,7 +1051,7 @@ wxMenu* wxMenuBar::Remove(
 #endif // wxUSE_ACCEL
         Refresh();
     }
-    m_titles.Remove(nPos);
+    m_titles.RemoveAt(nPos);
     return pMenu;
 } // end of wxMenuBar::Remove
 
@@ -1104,10 +1065,10 @@ void wxMenuBar::RebuildAccelTable()
     size_t                          nAccelCount = 0;
     size_t                          i;
     size_t                          nCount = GetMenuCount();
-
-    for (i = 0; i < nCount; i++)
+    wxMenuList::iterator it;
+    for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
     {
-        nAccelCount += m_menus[i]->GetAccelCount();
+        nAccelCount += (*it)->GetAccelCount();
     }
 
     if (nAccelCount)
@@ -1115,9 +1076,9 @@ void wxMenuBar::RebuildAccelTable()
         wxAcceleratorEntry*         pAccelEntries = new wxAcceleratorEntry[nAccelCount];
 
         nAccelCount = 0;
-        for (i = 0; i < nCount; i++)
+        for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
         {
-            nAccelCount += m_menus[i]->CopyAccels(&pAccelEntries[nAccelCount]);
+            nAccelCount += (*it)->CopyAccels(&pAccelEntries[nAccelCount]);
         }
         m_vAccelTable = wxAcceleratorTable( nAccelCount
                                            ,pAccelEntries
@@ -1167,14 +1128,14 @@ int wxMenuBar::FindMenuItem(
 ) const
 {
     wxString                        sMenuLabel = wxStripMenuCodes(rMenuString);
-    size_t                          nCount = GetMenuCount();
-
-    for (size_t i = 0; i < nCount; i++)
+    size_t                          nCount = GetMenuCount(), i;
+    wxMenuList::const_iterator it;
+    for (i = 0, it = m_menus.begin(); i < nCount; i++, it++)
     {
         wxString                    sTitle = wxStripMenuCodes(m_titles[i]);
 
         if (rMenuString == sTitle)
-            return m_menus[i]->FindItem(rItemString);
+            return (*it)->FindItem(rItemString);
     }
     return wxNOT_FOUND;
 } // end of wxMenuBar::FindMenuItem
@@ -1188,13 +1149,13 @@ wxMenuItem* wxMenuBar::FindItem(
         *ppItemMenu = NULL;
 
     wxMenuItem*                     pItem = NULL;
-    size_t                          nCount = GetMenuCount();
-
-    for (size_t i = 0; !pItem && (i < nCount); i++)
+    size_t                          nCount = GetMenuCount(), i;
+    wxMenuList::const_iterator it;
+    for (i = 0, it = m_menus.begin(); !pItem && (i < nCount); i++, it++)
     {
-        pItem = m_menus[i]->FindItem( nId
-                                     ,ppItemMenu
-                                    );
+        pItem = (*it)->FindItem( nId
+                                ,ppItemMenu
+                               );
     }
     return pItem;
 } // end of wxMenuBar::FindItem
@@ -1209,14 +1170,14 @@ wxMenuItem* wxMenuBar::FindItem(
         *ppItemMenu = NULL;
 
     wxMenuItem*                     pItem = NULL;
-    size_t                          nCount = GetMenuCount();
-
-    for (size_t i = 0; !pItem && (i < nCount); i++)
+    size_t                          nCount = GetMenuCount(), i;
+    wxMenuList::const_iterator it;
+    for (i = 0, it = m_menus.begin(); !pItem && (i < nCount); i++, it++)
     {
-        pItem = m_menus[i]->FindItem( nId
-                                     ,hItem
-                                     ,ppItemMenu
-                                    );
+        pItem = (*it)->FindItem( nId
+                                ,hItem
+                                ,ppItemMenu
+                               );
     }
     return pItem;
 } // end of wxMenuBar::FindItem