]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/menuitem.cpp
linking fixes
[wxWidgets.git] / src / os2 / menuitem.cpp
index da529a56339e435e30ac8dfec9c6c3e756d7e9d7..1d960c605b06481777659b18c361ac97594d075d 100644 (file)
     #define OWNER_DRAWN_ONLY( code )
 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
 
     #define OWNER_DRAWN_ONLY( code )
 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
 
+// ----------------------------------------------------------------------------
+// static function for translating menu labels
+// ----------------------------------------------------------------------------
+
+static wxString TextToLabel(const wxString& rTitle)
+{
+    wxString Title;
+    const wxChar *pc;
+    for (pc = rTitle; *pc != wxT('\0'); pc++ )
+    {
+        if (*pc == wxT('&') )
+        {
+            if (*(pc+1) == wxT('&'))
+            {
+                pc++;
+                Title << wxT('&');
+            }
+            else 
+                Title << wxT('~');
+        }
+//         else if (*pc == wxT('/'))
+//         {
+//             Title << wxT('\\');
+//         }
+        else
+        {
+            if ( *pc == wxT('~') )
+            {
+                // tildes must be doubled to prevent them from being
+                // interpreted as accelerator character prefix by PM ???
+                Title << *pc;
+            }
+            Title << *pc;
+        }
+    }
+    return Title;
+}
+
 // ============================================================================
 // implementation
 // ============================================================================
 // ============================================================================
 // implementation
 // ============================================================================
@@ -84,7 +122,7 @@ wxMenuItem::wxMenuItem(
 , wxMenu*                           pSubMenu
 )
 #if wxUSE_OWNER_DRAWN
 , wxMenu*                           pSubMenu
 )
 #if wxUSE_OWNER_DRAWN
-:  wxOwnerDrawn( rText
+:  wxOwnerDrawn( TextToLabel(rText)
                 ,bCheckable
                )
 #endif // owner drawn
                 ,bCheckable
                )
 #endif // owner drawn
@@ -114,9 +152,11 @@ wxMenuItem::wxMenuItem(
     m_isEnabled   = TRUE;
     m_isChecked   = FALSE;
     m_id          = nId;
     m_isEnabled   = TRUE;
     m_isChecked   = FALSE;
     m_id          = nId;
-    m_text        = rText;
+    m_text        = TextToLabel(rText);
     m_isCheckable = bCheckable;
     m_help        = rStrHelp;
     m_isCheckable = bCheckable;
     m_help        = rStrHelp;
+    memset(&m_vMenuData, '\0', sizeof(m_vMenuData));
+    m_vMenuData.id= nId;
 } // end of wxMenuItem::wxMenuItem
 
 wxMenuItem::~wxMenuItem()
 } // end of wxMenuItem::wxMenuItem
 
 wxMenuItem::~wxMenuItem()
@@ -153,7 +193,19 @@ wxString wxMenuItemBase::GetLabelFromText(
   const wxString&                   rText
 )
 {
   const wxString&                   rText
 )
 {
-    return wxStripMenuCodes(rText);
+    wxString label;
+    for ( const wxChar *pc = rText.c_str(); *pc; pc++ )
+    {
+        if ( *pc == wxT('~') || *pc == wxT('&') )
+        {
+            // '~' is the escape character for GTK+ and '&' is the one for
+            // wxWindows - skip both of them
+            continue;
+        }
+
+        label += *pc;
+    }
+    return label;
 }
 
 // accelerators
 }
 
 // accelerators
@@ -180,17 +232,17 @@ void wxMenuItem::Enable(
     if (m_isEnabled == bEnable)
         return;
     if (bEnable)
     if (m_isEnabled == bEnable)
         return;
     if (bEnable)
-        bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
-                           ,MM_SETITEMATTR
-                           ,MPFROM2SHORT(GetRealId(), TRUE)
-                           ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
-                          );
+        bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
+                                 ,MM_SETITEMATTR
+                                 ,MPFROM2SHORT(GetRealId(), TRUE)
+                                 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
+                                );
     else
     else
-        bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
-                           ,MM_SETITEMATTR
-                           ,MPFROM2SHORT(GetRealId(), TRUE)
-                           ,MPFROM2SHORT(MIA_DISABLED, FALSE)
-                          );
+        bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
+                                 ,MM_SETITEMATTR
+                                 ,MPFROM2SHORT(GetRealId(), TRUE)
+                                 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
+                                );
     if (!bOk)
     {
         wxLogLastError("EnableMenuItem");
     if (!bOk)
     {
         wxLogLastError("EnableMenuItem");
@@ -208,20 +260,20 @@ void wxMenuItem::Check(
     if (m_isChecked == bCheck)
         return;
     if (bCheck)
     if (m_isChecked == bCheck)
         return;
     if (bCheck)
-        bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
-                           ,MM_SETITEMATTR
-                           ,MPFROM2SHORT(GetRealId(), TRUE)
-                           ,MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)
-                          );
+        bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
+                                 ,MM_SETITEMATTR
+                                 ,MPFROM2SHORT(GetRealId(), TRUE)
+                                 ,MPFROM2SHORT(MIA_CHECKED, MIA_CHECKED)
+                                );
     else
     else
-        bOk = ::WinSendMsg( GetHMenuOf(m_parentMenu)
-                           ,MM_SETITEMATTR
-                           ,MPFROM2SHORT(GetRealId(), TRUE)
-                           ,MPFROM2SHORT(MIA_CHECKED, FALSE)
-                          );
+        bOk = (bool)::WinSendMsg( GetHMenuOf(m_parentMenu)
+                                 ,MM_SETITEMATTR
+                                 ,MPFROM2SHORT(GetRealId(), TRUE)
+                                 ,MPFROM2SHORT(MIA_CHECKED, FALSE)
+                                );
     if (!bOk)
     {
     if (!bOk)
     {
-        wxLogLastError("EnableMenuItem");
+        wxLogLastError("CheckMenuItem");
     }
     wxMenuItemBase::Check(bCheck);
 } // end of wxMenuItem::Check
     }
     wxMenuItemBase::Check(bCheck);
 } // end of wxMenuItem::Check
@@ -233,11 +285,13 @@ void wxMenuItem::SetText(
     //
     // Don't do anything if label didn't change
     //
     //
     // Don't do anything if label didn't change
     //
-    if (m_text == rText)
+
+    wxString Text = TextToLabel(rText);
+    if (m_text == Text)
         return;
 
         return;
 
-    wxMenuItemBase::SetText(rText);
-    OWNER_DRAWN_ONLY(wxOwnerDrawn::SetName(rText));
+    wxMenuItemBase::SetText(Text);
+    OWNER_DRAWN_ONLY(wxOwnerDrawn::SetName(Text));
 
     HWND                            hMenu = GetHMenuOf(m_parentMenu);
 
 
     HWND                            hMenu = GetHMenuOf(m_parentMenu);
 
@@ -250,7 +304,7 @@ void wxMenuItem::SetText(
     USHORT                          uId = GetRealId();
     MENUITEM                        vItem;
     USHORT                          uFlagsOld;
     USHORT                          uId = GetRealId();
     MENUITEM                        vItem;
     USHORT                          uFlagsOld;
-    
+
     if (!::WinSendMsg( hMenu
                       ,MM_QUERYITEM
                       ,MPFROM2SHORT(uId, TRUE)
     if (!::WinSendMsg( hMenu
                       ,MM_QUERYITEM
                       ,MPFROM2SHORT(uId, TRUE)
@@ -279,7 +333,7 @@ void wxMenuItem::SetText(
 #endif  //owner drawn
         {
             uFlagsOld |= MIS_TEXT;
 #endif  //owner drawn
         {
             uFlagsOld |= MIS_TEXT;
-            pData = (BYTE*)rText.c_str();
+            pData = (BYTE*)Text.c_str();
         }
 
         //
         }
 
         //