]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menu.cpp
compilation fixes - wxGTK compiles but not links
[wxWidgets.git] / src / os2 / menu.cpp
index 78293daafaeb6fbdc4975edbbe5bddaabd039e72..e307253b9130661983ea2edc3274112a4e6e6cb9 100644 (file)
@@ -265,6 +265,7 @@ bool wxMenu::DoInsertOrAppend(
 {
     ERRORID                         vError;
     wxString                        sError;
+    char                            zMsg[128];
 #if wxUSE_ACCEL
     UpdateAccel(pItem);
 #endif // wxUSE_ACCEL
@@ -275,7 +276,7 @@ bool wxMenu::DoInsertOrAppend(
     //
 
     wxMenu*                         pSubmenu = pItem->GetSubMenu();
-    MENUITEM   &rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData:
+    MENUITEM&                       rItem = (pSubmenu != NULL)?pSubmenu->m_vMenuData:
                                             pItem->m_vMenuData;
     if(pSubmenu != NULL)
     {
@@ -296,7 +297,7 @@ bool wxMenu::DoInsertOrAppend(
 
     if (pItem->IsSeparator())
     {
-        vItem.afStyle |= MIS_SEPARATOR;
+        rItem.afStyle |= MIS_SEPARATOR;
     }
 
     //
@@ -304,20 +305,18 @@ bool wxMenu::DoInsertOrAppend(
     // required by ::MM_INSERTITEM message API
     //
 
-    wxMenu*                         pSubmenu = pItem->GetSubMenu();
-
     if (pSubmenu != NULL)
     {
         wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
         pSubmenu->SetParent(this);
 
-        vItem.iPosition = 0; // submenus have a 0 position
-        vItem.id = (USHORT)pSubmenu->GetHMenu();
-        vItem.afStyle |= MIS_SUBMENU | MIS_TEXT;
+        rItem.iPosition = 0; // submenus have a 0 position
+        rItem.id = (USHORT)pSubmenu->GetHMenu();
+        rItem.afStyle |= MIS_SUBMENU | MIS_TEXT;
     }
     else
     {
-        vItem.id = pItem->GetId();
+        rItem.id = pItem->GetId();
     }
 
     BYTE*                           pData;
@@ -327,12 +326,14 @@ bool wxMenu::DoInsertOrAppend(
     {
         //
         // Want to get {Measure|Draw}Item messages?
-        // item draws itself, pass pointer to it in data parameter
+        // item draws itself, passing pointer to data doesn't work in OS/2
         // Will eventually need to set the image handle somewhere into vItem.hItem
         //
         rItem.afStyle |= MIS_OWNERDRAW;
-        pData = (BYTE*)pItem;
-        // vItem.hItem = ????
+        pData = (BYTE*)NULL;
+        rItem.hItem = (HBITMAP)pItem->GetBitmap().GetHBITMAP();
+        pItem->m_vMenuData.afStyle = rItem.afStyle;
+        pItem->m_vMenuData.hItem = rItem.hItem;
     }
     else
 #endif
@@ -340,7 +341,7 @@ bool wxMenu::DoInsertOrAppend(
         //
         // Menu is just a normal string (passed in data parameter)
         //
-        vItem.afStyle |= MIS_TEXT;
+        rItem.afStyle |= MIS_TEXT;
         pData = (char*)pItem->GetText().c_str();
     }
 
@@ -360,6 +361,21 @@ bool wxMenu::DoInsertOrAppend(
                               ,(MPARAM)&rItem
                               ,(MPARAM)pData
                              );
+#if wxUSE_OWNER_DRAWN
+    if (pItem->IsOwnerDrawn())
+    {
+        BOOL                       rc;
+        MENUITEM                   vMenuItem;
+
+        ::WinSendMsg( GetHmenu()
+                     ,MM_QUERYITEM
+                     ,MPFROM2SHORT( (USHORT)pItem->GetId()
+                                   ,(USHORT)(FALSE)
+                                  )
+                     ,&vMenuItem
+                    );
+    }
+#endif
     if (rc == MIT_MEMERROR || rc == MIT_ERROR)
     {
         vError = ::WinGetLastError(vHabmain);
@@ -373,7 +389,7 @@ bool wxMenu::DoInsertOrAppend(
         //
         // If we're already attached to the menubar, we must update it
         //
-        if (IsAttached())
+        if (IsAttached() && m_menuBar->IsAttached())
         {
             m_menuBar->Refresh();
         }
@@ -444,7 +460,7 @@ wxMenuItem* wxMenu::DoRemove(
                  ,MPFROM2SHORT(pItem->GetId(), TRUE)
                  ,(MPARAM)0
                 );
-    if (IsAttached())
+    if (IsAttached() && m_menuBar->IsAttached())
     {
         //
         // Otherwise, the chane won't be visible
@@ -620,6 +636,42 @@ wxWindow* wxMenu::GetWindow() const
     return NULL;
 } // end of wxMenu::GetWindow
 
+// recursive search for item by id
+wxMenuItem* wxMenu::FindItem(
+  int                               nItemId
+, ULONG                             hItem
+, wxMenu**                          ppItemMenu
+) const
+{
+    if ( ppItemMenu )
+        *ppItemMenu = NULL;
+
+    wxMenuItem*                     pItem = NULL;
+
+    for ( wxMenuItemList::Node *node = m_items.GetFirst();
+          node && !pItem;
+          node = node->GetNext() )
+    {
+        pItem = node->GetData();
+
+        if ( pItem->GetId() == nItemId && pItem->m_vMenuData.hItem == hItem)
+        {
+            if ( ppItemMenu )
+                *ppItemMenu = (wxMenu *)this;
+        }
+        else if ( pItem->IsSubMenu() )
+        {
+            pItem = pItem->GetSubMenu()->FindItem(nItemId, hItem, ppItemMenu);
+        }
+        else
+        {
+            // don't exit the loop
+            pItem = NULL;
+        }
+    }
+    return pItem;
+} // end of wxMenu::FindItem
+
 // ---------------------------------------------------------------------------
 // Menu Bar
 // ---------------------------------------------------------------------------
@@ -1033,7 +1085,7 @@ void wxMenuBar::Attach(
     // Ensure the accelerator table is set to the frame (not the client!)
     //
     if (!::WinSetAccelTable( vHabmain
-                            ,(HWND)pFrame->GetFrame()
+                            ,(HWND)pFrame->GetHWND()
                             ,m_vAccelTable.GetHACCEL()
                            ))
         wxLogLastError("WinSetAccelTable");
@@ -1092,4 +1144,25 @@ wxMenuItem* wxMenuBar::FindItem(
     return pItem;
 } // end of wxMenuBar::FindItem
 
+wxMenuItem* wxMenuBar::FindItem(
+  int                               nId
+, ULONG                             hItem
+, wxMenu**                          ppItemMenu
+) const
+{
+    if (ppItemMenu)
+        *ppItemMenu = NULL;
+
+    wxMenuItem*                     pItem = NULL;
+    size_t                          nCount = GetMenuCount();
+
+    for (size_t i = 0; !pItem && (i < nCount); i++)
+    {
+        pItem = m_menus[i]->FindItem( nId
+                                     ,hItem
+                                     ,ppItemMenu
+                                    );
+    }
+    return pItem;
+} // end of wxMenuBar::FindItem