]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menu.cpp
Patch 1173507 by Stas Sergeev. Allow FindFirst to work with patterns
[wxWidgets.git] / src / os2 / menu.cpp
index 5fa530170333c0496da226f44c5268fe3ae6b4ac..59307fbdc3dff3b655a6469e83c2ad36ddfda621 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     10/10/99
 // RCS-ID:      $Id$
 // Copyright:   (c) David Webster
 // Created:     10/10/99
 // RCS-ID:      $Id$
 // Copyright:   (c) David Webster
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
@@ -47,7 +47,7 @@ extern wxMenu*                      wxCurrentPopupMenu;
 //
 // The (popup) menu title has this special id
 //
 //
 // The (popup) menu title has this special id
 //
-static const int                    idMenuTitle = -2;
+static const int                    idMenuTitle = -3;
 
 //
 // The unique ID for Menus
 
 //
 // The unique ID for Menus
@@ -179,12 +179,12 @@ void wxMenu::UpdateAccel(
     if (pItem->IsSubMenu())
     {
         wxMenu*                     pSubmenu = pItem->GetSubMenu();
     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())
         }
     }
     else if (!pItem->IsSeparator())
@@ -280,7 +280,7 @@ bool wxMenu::DoInsertOrAppend(
         rItem.id = pItem->GetId();
     }
 
         rItem.id = pItem->GetId();
     }
 
-    BYTE*                           pData;
+    BYTE*                           pData=NULL;
 
 #if wxUSE_OWNER_DRAWN
     if (pItem->IsOwnerDrawn())
 
 #if wxUSE_OWNER_DRAWN
     if (pItem->IsOwnerDrawn())
@@ -304,10 +304,18 @@ bool wxMenu::DoInsertOrAppend(
     }
     else
     {
     }
     else
     {
-        //
-        // Menu is just a normal string (passed in data parameter)
-        //
-        rItem.afStyle |= MIS_TEXT;
+        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();
     }
 
         pData = (char*)pItem->GetText().c_str();
     }
 
@@ -408,11 +416,11 @@ wxMenuItem* wxMenu::DoAppend(
             //
             pItem->SetRadioGroupStart(m_nStartRadioGroup);
 
             //
             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
             {
             }
             else
             {
@@ -462,19 +470,19 @@ wxMenuItem* wxMenu::DoRemove(
     // We need to find the items position in the child list
     //
     size_t                          nPos;
     // 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;
             break;
-        pNode = pNode->GetNext();
+        node = node->GetNext();
     }
 
     //
     // DoRemove() (unlike Remove) can only be called for existing item!
     //
     }
 
     //
     // 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
     //
 
 #if wxUSE_ACCEL
     //
@@ -633,7 +641,7 @@ wxMenuItem* wxMenu::FindItem(
 
     wxMenuItem*                     pItem = NULL;
 
 
     wxMenuItem*                     pItem = NULL;
 
-    for ( wxMenuItemList::Node *node = m_items.GetFirst();
+    for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
           node && !pItem;
           node = node->GetNext() )
     {
           node && !pItem;
           node = node->GetNext() )
     {
@@ -689,6 +697,7 @@ wxMenuBar::wxMenuBar(
   int                               nCount
 , wxMenu*                           vMenus[]
 , const wxString                    sTitles[]
   int                               nCount
 , wxMenu*                           vMenus[]
 , const wxString                    sTitles[]
+, long                              WXUNUSED(lStyle)
 )
 {
     Init();
 )
 {
     Init();
@@ -764,9 +773,9 @@ WXHMENU wxMenuBar::Create()
     }
     else
     {
     }
     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;
         {
             APIRET                  rc;
             ERRORID                 vError;
@@ -776,8 +785,8 @@ WXHMENU wxMenuBar::Create()
             //
             // Set the parent and owner of the submenues to be the menubar, not the desktop
             //
             //
             // 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);
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
@@ -785,7 +794,7 @@ WXHMENU wxMenuBar::Create()
                 return NULLHANDLE;
             }
 
                 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);
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
@@ -793,9 +802,9 @@ WXHMENU wxMenuBar::Create()
                 return NULLHANDLE;
             }
 
                 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());
+            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);
             if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
             {
                 vError = ::WinGetLastError(vHabmain);
@@ -1043,7 +1052,7 @@ wxMenu* wxMenuBar::Remove(
 #endif // wxUSE_ACCEL
         Refresh();
     }
 #endif // wxUSE_ACCEL
         Refresh();
     }
-    m_titles.Remove(nPos);
+    m_titles.RemoveAt(nPos);
     return pMenu;
 } // end of wxMenuBar::Remove
 
     return pMenu;
 } // end of wxMenuBar::Remove
 
@@ -1057,10 +1066,10 @@ void wxMenuBar::RebuildAccelTable()
     size_t                          nAccelCount = 0;
     size_t                          i;
     size_t                          nCount = GetMenuCount();
     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)
     }
 
     if (nAccelCount)
@@ -1068,9 +1077,9 @@ void wxMenuBar::RebuildAccelTable()
         wxAcceleratorEntry*         pAccelEntries = new wxAcceleratorEntry[nAccelCount];
 
         nAccelCount = 0;
         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
         }
         m_vAccelTable = wxAcceleratorTable( nAccelCount
                                            ,pAccelEntries
@@ -1120,14 +1129,14 @@ int wxMenuBar::FindMenuItem(
 ) const
 {
     wxString                        sMenuLabel = wxStripMenuCodes(rMenuString);
 ) 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)
     {
         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
     }
     return wxNOT_FOUND;
 } // end of wxMenuBar::FindMenuItem
@@ -1141,13 +1150,13 @@ wxMenuItem* wxMenuBar::FindItem(
         *ppItemMenu = NULL;
 
     wxMenuItem*                     pItem = NULL;
         *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
     }
     return pItem;
 } // end of wxMenuBar::FindItem
@@ -1162,14 +1171,14 @@ wxMenuItem* wxMenuBar::FindItem(
         *ppItemMenu = NULL;
 
     wxMenuItem*                     pItem = NULL;
         *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
     }
     return pItem;
 } // end of wxMenuBar::FindItem