]> git.saurik.com Git - wxWidgets.git/commitdiff
Added conversion of menu labels (&->~)
authorStefan Neis <Stefan.Neis@t-online.de>
Sat, 18 Mar 2000 17:39:14 +0000 (17:39 +0000)
committerStefan Neis <Stefan.Neis@t-online.de>
Sat, 18 Mar 2000 17:39:14 +0000 (17:39 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6826 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/os2/menu.cpp
src/os2/menuitem.cpp

index 2dc2789ceb35ae1aeb16485184180e97d0151b24..cfbb69829a38ac7302d2feca1c29d6d96851d0e4 100644 (file)
@@ -55,6 +55,44 @@ static const int                    idMenuTitle = -2;
     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& 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
 // ============================================================================
@@ -793,9 +831,10 @@ wxMenu* wxMenuBar::Replace(
 )
 {
     SHORT                            nId;
 )
 {
     SHORT                            nId;
+    wxString                         Title = TextToLabel(rTitle);
     wxMenu*                          pMenuOld = wxMenuBarBase::Replace( nPos
                                                                        ,pMenu
     wxMenu*                          pMenuOld = wxMenuBarBase::Replace( nPos
                                                                        ,pMenu
-                                                                       ,rTitle
+                                                                       ,Title
                                                                       );
 
 
                                                                       );
 
 
@@ -807,11 +846,11 @@ wxMenu* wxMenuBar::Replace(
     }
     if (!pMenuOld)
         return FALSE;
     }
     if (!pMenuOld)
         return FALSE;
-    m_titles[nPos] = rTitle;
+    m_titles[nPos] = Title;
     if (IsAttached())
     {
         ::WinSendMsg((HWND)m_hMenu, MM_DELETEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0);
     if (IsAttached())
     {
         ::WinSendMsg((HWND)m_hMenu, MM_DELETEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0);
-        ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)rTitle.c_str());
+        ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)Title.c_str());
 
 #if wxUSE_ACCEL
         if (pMenuOld->HasAccels() || pMenu->HasAccels())
 
 #if wxUSE_ACCEL
         if (pMenuOld->HasAccels() || pMenu->HasAccels())
@@ -833,13 +872,14 @@ bool wxMenuBar::Insert(
 , const wxString&                   rTitle
 )
 {
 , const wxString&                   rTitle
 )
 {
+    wxString Title = TextToLabel(rTitle);
     if (!wxMenuBarBase::Insert( nPos
                                ,pMenu
     if (!wxMenuBarBase::Insert( nPos
                                ,pMenu
-                               ,rTitle
+                               ,Title
                               ))
         return FALSE;
 
                               ))
         return FALSE;
 
-    m_titles.Insert( rTitle
+    m_titles.Insert( Title
                     ,nPos
                    );
 
                     ,nPos
                    );
 
@@ -847,7 +887,7 @@ bool wxMenuBar::Insert(
 
     if (IsAttached())
     {
 
     if (IsAttached())
     {
-        ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)rTitle.c_str());
+        ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)Title.c_str());
 #if wxUSE_ACCEL
         if (pMenu->HasAccels())
         {
 #if wxUSE_ACCEL
         if (pMenu->HasAccels())
         {
@@ -869,16 +909,17 @@ 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"));
 
-    if (!wxMenuBarBase::Append(pMenu, rTitle))
+    wxString Title = TextToLabel(rTitle);
+    if (!wxMenuBarBase::Append(pMenu, Title))
         return FALSE;
 
     pMenu->Attach(this);
         return FALSE;
 
     pMenu->Attach(this);
-    m_titles.Add(rTitle);
+    m_titles.Add(Title);
 
     if ( IsAttached() )
     {
         pMenu->m_vMenuData.iPosition = MIT_END;
 
     if ( IsAttached() )
     {
         pMenu->m_vMenuData.iPosition = MIT_END;
-        ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)rTitle.c_str());
+        ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)Title.c_str());
 #if wxUSE_ACCEL
         if (pMenu->HasAccels())
         {
 #if wxUSE_ACCEL
         if (pMenu->HasAccels())
         {
index 03ee6f9b5d3543d25d0093288b258159455e99cf..af97aab35a6613c776d1a4536afaa0c79e7e2052 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,7 +152,7 @@ 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;
 } // end of wxMenuItem::wxMenuItem
     m_isCheckable = bCheckable;
     m_help        = rStrHelp;
 } // end of wxMenuItem::wxMenuItem
@@ -153,7 +191,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
@@ -233,11 +283,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);
 
@@ -279,7 +331,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();
         }
 
         //
         }
 
         //