]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menu.cpp
Corrected wxFileSystemHandler::GetRightLocation for the case
[wxWidgets.git] / src / os2 / menu.cpp
index c63cfe2feaa4f019ed8626063387de657d42548c..89d968065d240da1ab429dcf14df738238c2e585 100644 (file)
@@ -52,11 +52,7 @@ static const int                    idMenuTitle = -2;
 //
 // The unique ID for Menus
 //
 //
 // The unique ID for Menus
 //
-#ifdef __VISAGECPP__
 USHORT                              wxMenu::m_nextMenuId = 0;
 USHORT                              wxMenu::m_nextMenuId = 0;
-#else
-static USHORT                       wxMenu::m_nextMenuId = 0;
-#endif
 
 // ----------------------------------------------------------------------------
 // macros
 
 // ----------------------------------------------------------------------------
 // macros
@@ -65,45 +61,6 @@ static USHORT                       wxMenu::m_nextMenuId = 0;
     IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
     IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
 
     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;
-
-    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
 // ============================================================================
 // ============================================================================
 // implementation
 // ============================================================================
@@ -245,7 +202,7 @@ void wxMenu::UpdateAccel(
         //
         size_t                      n = FindAccel(pItem->GetId());
 
         //
         size_t                      n = FindAccel(pItem->GetId());
 
-        if (n == wxNOT_FOUND)
+        if (n == (size_t)wxNOT_FOUND)
         {
             //
             // No old, add new if any
         {
             //
             // No old, add new if any
@@ -290,7 +247,7 @@ bool wxMenu::DoInsertOrAppend(
 
     ERRORID                         vError;
     wxString                        sError;
 
     ERRORID                         vError;
     wxString                        sError;
-    char                            zMsg[128];
+
 #if wxUSE_ACCEL
     UpdateAccel(pItem);
 #endif // wxUSE_ACCEL
 #if wxUSE_ACCEL
     UpdateAccel(pItem);
 #endif // wxUSE_ACCEL
@@ -305,16 +262,10 @@ bool wxMenu::DoInsertOrAppend(
         m_bDoBreak = FALSE;
     }
 
         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
     //
     //
     // 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"));
     if (pSubmenu != NULL)
     {
         wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
@@ -347,6 +298,11 @@ bool wxMenu::DoInsertOrAppend(
     }
     else
 #endif
     }
     else
 #endif
+    if (pItem->IsSeparator())
+    {
+        rItem.afStyle = MIS_SEPARATOR;
+    }
+    else
     {
         //
         // Menu is just a normal string (passed in data parameter)
     {
         //
         // Menu is just a normal string (passed in data parameter)
@@ -374,7 +330,6 @@ bool wxMenu::DoInsertOrAppend(
 #if wxUSE_OWNER_DRAWN
     if (pItem->IsOwnerDrawn())
     {
 #if wxUSE_OWNER_DRAWN
     if (pItem->IsOwnerDrawn())
     {
-        BOOL                       rc;
         MENUITEM                   vMenuItem;
 
         ::WinSendMsg( GetHmenu()
         MENUITEM                   vMenuItem;
 
         ::WinSendMsg( GetHmenu()
@@ -386,11 +341,11 @@ bool wxMenu::DoInsertOrAppend(
                     );
     }
 #endif
                     );
     }
 #endif
-    if (rc == MIT_MEMERROR || rc == MIT_ERROR)
+    if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
     {
         vError = ::WinGetLastError(vHabmain);
         sError = wxPMErrorToStr(vError);
     {
         vError = ::WinGetLastError(vHabmain);
         sError = wxPMErrorToStr(vError);
-        wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError);
+        wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError.c_str());
         wxLogLastError("Insert or AppendMenu");
         return FALSE;
     }
         wxLogLastError("Insert or AppendMenu");
         return FALSE;
     }
@@ -416,11 +371,11 @@ void wxMenu::EndRadioGroup()
     m_nStartRadioGroup = -1;
 } // end of wxMenu::EndRadioGroup
 
     m_nStartRadioGroup = -1;
 } // end of wxMenu::EndRadioGroup
 
-bool wxMenu::DoAppend(
+wxMenuItem* wxMenu::DoAppend(
   wxMenuItem*                       pItem
 )
 {
   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;
 
 
     bool                            bCheck = FALSE;
 
@@ -472,7 +427,7 @@ bool wxMenu::DoAppend(
 
     if (!wxMenuBase::DoAppend(pItem) || !DoInsertOrAppend(pItem))
     {
 
     if (!wxMenuBase::DoAppend(pItem) || !DoInsertOrAppend(pItem))
     {
-        return FALSE;
+        return NULL;
     }
     if (bCheck)
     {
     }
     if (bCheck)
     {
@@ -481,20 +436,22 @@ bool wxMenu::DoAppend(
         //
         pItem->Check(TRUE);
     }
         //
         pItem->Check(TRUE);
     }
-    return TRUE;
+    return pItem;
 } // end of wxMenu::DoAppend
 
 } // end of wxMenu::DoAppend
 
-bool wxMenu::DoInsert(
+wxMenuItem* wxMenu::DoInsert(
   size_t                            nPos
 , wxMenuItem*                       pItem
 )
 {
   size_t                            nPos
 , wxMenuItem*                       pItem
 )
 {
-    return ( wxMenuBase::DoInsert( nPos
-                                  ,pItem) &&
+    if ( wxMenuBase::DoInsert( nPos
+                               ,pItem) &&
              DoInsertOrAppend( pItem
                               ,nPos
              DoInsertOrAppend( pItem
                               ,nPos
-                             )
-           );
+                 ))
+         return pItem;
+    else
+        return NULL;
 } // end of wxMenu::DoInsert
 
 wxMenuItem* wxMenu::DoRemove(
 } // end of wxMenu::DoInsert
 
 wxMenuItem* wxMenu::DoRemove(
@@ -642,7 +599,7 @@ bool wxMenu::OS2Command(
         SendEvent( vId
                   ,(int)::WinSendMsg( GetHmenu()
                                      ,MM_QUERYITEMATTR
         SendEvent( vId
                   ,(int)::WinSendMsg( GetHmenu()
                                      ,MM_QUERYITEMATTR
-                                     ,(MPARAM)vId
+                                     ,MPFROMSHORT(vId)
                                      ,(MPARAM)MIA_CHECKED
                                     )
                  );
                                      ,(MPARAM)MIA_CHECKED
                                     )
                  );
@@ -747,6 +704,15 @@ wxMenuBar::wxMenuBar(
 
 wxMenuBar::~wxMenuBar()
 {
 
 wxMenuBar::~wxMenuBar()
 {
+    //
+    // We should free PM's resources only if PM doesn't do it for us
+    // which happens if we're attached to a frame
+    //
+    if (m_hMenu && !IsAttached())
+    {
+        ::WinDestroyWindow((HMENU)m_hMenu);
+        m_hMenu = (WXHMENU)NULL;
+    }
 } // end of wxMenuBar::~wxMenuBar
 
 // ---------------------------------------------------------------------------
 } // end of wxMenuBar::~wxMenuBar
 
 // ---------------------------------------------------------------------------
@@ -762,7 +728,6 @@ void wxMenuBar::Refresh()
 
 WXHMENU wxMenuBar::Create()
 {
 
 WXHMENU wxMenuBar::Create()
 {
-    MENUITEM                        vItem;
     HWND                            hFrame;
 
     if (m_hMenu != 0 )
     HWND                            hFrame;
 
     if (m_hMenu != 0 )
@@ -816,7 +781,7 @@ WXHMENU wxMenuBar::Create()
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
-                wxLogError("Error setting parent for submenu. Error: %s\n", sError);
+                wxLogError("Error setting parent for submenu. Error: %s\n", sError.c_str());
                 return NULLHANDLE;
             }
 
                 return NULLHANDLE;
             }
 
@@ -824,18 +789,18 @@ WXHMENU wxMenuBar::Create()
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
-                wxLogError("Error setting parent for submenu. Error: %s\n", sError);
+                wxLogError("Error setting parent for submenu. Error: %s\n", sError.c_str());
                 return NULLHANDLE;
             }
 
             m_menus[i]->m_vMenuData.iPosition = i;
 
             rc = (APIRET)::WinSendMsg(m_hMenu, MM_INSERTITEM, (MPARAM)&m_menus[i]->m_vMenuData, (MPARAM)m_titles[i].c_str());
                 return NULLHANDLE;
             }
 
             m_menus[i]->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)
+            if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
             {
                 vError = ::WinGetLastError(vHabmain);
                 sError = wxPMErrorToStr(vError);
-                wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError);
+                wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError.c_str());
                 return NULLHANDLE;
             }
         }
                 return NULLHANDLE;
             }
         }
@@ -932,7 +897,7 @@ wxMenu* wxMenuBar::Replace(
 )
 {
     SHORT                            nId;
 )
 {
     SHORT                            nId;
-    wxString                         sTitle = TextToLabel(rTitle);
+    wxString                         sTitle = wxPMTextToLabel(rTitle);
     wxMenu*                          pMenuOld = wxMenuBarBase::Replace( nPos
                                                                        ,pMenu
                                                                        ,sTitle
     wxMenu*                          pMenuOld = wxMenuBarBase::Replace( nPos
                                                                        ,pMenu
                                                                        ,sTitle
@@ -973,7 +938,7 @@ bool wxMenuBar::Insert(
 , const wxString&                   rTitle
 )
 {
 , const wxString&                   rTitle
 )
 {
-    wxString                        sTitle = TextToLabel(rTitle);
+    wxString                        sTitle = wxPMTextToLabel(rTitle);
 
     if (!wxMenuBarBase::Insert( nPos
                                ,pMenu
 
     if (!wxMenuBarBase::Insert( nPos
                                ,pMenu
@@ -1014,7 +979,7 @@ bool wxMenuBar::Append(
 
     wxCHECK_MSG(hSubmenu, FALSE, wxT("can't append invalid menu to menubar"));
 
 
     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;
 
     if (!wxMenuBarBase::Append(pMenu, sTitle))
         return FALSE;