]> git.saurik.com Git - wxWidgets.git/commitdiff
Fixed separator handling for menus.
authorStefan Neis <Stefan.Neis@t-online.de>
Sun, 15 Feb 2004 17:33:26 +0000 (17:33 +0000)
committerStefan Neis <Stefan.Neis@t-online.de>
Sun, 15 Feb 2004 17:33:26 +0000 (17:33 +0000)
Extracted common code for handling translation of labels containing
        accelerators from wxWindows representation to native representation.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25823 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/os2/accel.h
src/os2/accel.cpp
src/os2/menu.cpp
src/os2/menuitem.cpp

index f12542fd523b879922b58255c3615bd81c10f24c..0f842eeac24a158d02cfde7b0e4db668a20b8831 100644 (file)
@@ -63,5 +63,6 @@ public:
 
 WXDLLEXPORT_DATA(extern wxAcceleratorTable) wxNullAcceleratorTable;
 
+WXDLLEXPORT wxString wxPMTextToLabel(const wxString& rsTitle);
 #endif
     // _WX_ACCEL_H_
index 662e2c63f073f34ff7c6f3c747ac95d308c68e7e..e21a611fe03f6e979f0745f720e2a2c3e1121da5 100644 (file)
@@ -210,3 +210,45 @@ bool wxAcceleratorTable::Translate(
     return (Ok() && rc);
 } // end of wxAcceleratorTable::Translate
 
+// ---------------------------------------------------------------------------
+// function for translating labels
+// ---------------------------------------------------------------------------
+
+wxString wxPMTextToLabel(
+  const wxString&                   rsTitle
+)
+{
+    wxString                        sTitle;
+    const wxChar*                   zPc;
+
+    if (rsTitle.IsEmpty())
+        return(sTitle);
+
+    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 wxPMTextToLabel
+
index dff498d244d9357afdd7d14cc6c08617aa30dfd3..09b81199006ab1c1d721c3fb23ce04322541d983 100644 (file)
@@ -61,47 +61,6 @@ USHORT                              wxMenu::m_nextMenuId = 0;
     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;
-
-    if (rsTitle.IsEmpty())
-        return sTitle;
-    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
 // ============================================================================
@@ -304,16 +263,10 @@ bool wxMenu::DoInsertOrAppend(
         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
     //
-
     if (pSubmenu != NULL)
     {
         wxASSERT_MSG(pSubmenu->GetHMenu(), wxT("invalid submenu"));
@@ -344,8 +297,13 @@ bool wxMenu::DoInsertOrAppend(
         pItem->m_vMenuData.afStyle = rItem.afStyle;
         pItem->m_vMenuData.hItem   = rItem.hItem;
     }
-    else if (!pItem->IsSeparator())
+    else
 #endif
+    if (pItem->IsSeparator())
+    {
+        rItem.afStyle = MIS_SEPARATOR;
+    }
+    else
     {
         //
         // Menu is just a normal string (passed in data parameter)
@@ -942,7 +900,7 @@ wxMenu* wxMenuBar::Replace(
 )
 {
     SHORT                            nId;
-    wxString                         sTitle = TextToLabel(rTitle);
+    wxString                         sTitle = wxPMTextToLabel(rTitle);
     wxMenu*                          pMenuOld = wxMenuBarBase::Replace( nPos
                                                                        ,pMenu
                                                                        ,sTitle
@@ -983,7 +941,7 @@ bool wxMenuBar::Insert(
 , const wxString&                   rTitle
 )
 {
-    wxString                        sTitle = TextToLabel(rTitle);
+    wxString                        sTitle = wxPMTextToLabel(rTitle);
 
     if (!wxMenuBarBase::Insert( nPos
                                ,pMenu
@@ -1024,7 +982,7 @@ bool wxMenuBar::Append(
 
     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;
index 91c6e9d975be069bbc0a1a3b04e653796c569ca9..87bac21267eb7df29478a7431c1cb9ae3f803e2b 100644 (file)
     #define OWNER_DRAWN_ONLY( code )
 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
 
-// ----------------------------------------------------------------------------
-// static function for translating menu labels
-// ----------------------------------------------------------------------------
-
-static wxString TextToLabel(
-  const wxString&                   rsTitle
-)
-{
-    wxString                        sTitle;
-    const wxChar*                   zPc;
-
-    if (rsTitle.IsEmpty())
-        return(sTitle);
-
-    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
 // ============================================================================
@@ -123,13 +81,13 @@ wxMenuItem::wxMenuItem(
 )
 : wxMenuItemBase( pParentMenu
                  ,nId
-                 ,TextToLabel(rsText)
+                 ,wxPMTextToLabel(rsText)
                  ,rsHelp
                  ,eKind
                  ,pSubMenu
                 )
 #if wxUSE_OWNER_DRAWN
-,  wxOwnerDrawn( TextToLabel(rsText)
+,  wxOwnerDrawn( wxPMTextToLabel(rsText)
                 ,eKind == wxITEM_CHECK
                )
 #endif // owner drawn
@@ -151,13 +109,13 @@ wxMenuItem::wxMenuItem(
 )
 : wxMenuItemBase( pParentMenu
                  ,nId
-                 ,TextToLabel(rsText)
+                 ,wxPMTextToLabel(rsText)
                  ,rsHelp
                  ,bIsCheckable ? wxITEM_CHECK : wxITEM_NORMAL
                  ,pSubMenu
                 )
 #if wxUSE_OWNER_DRAWN
-,  wxOwnerDrawn( TextToLabel(rsText)
+,  wxOwnerDrawn( wxPMTextToLabel(rsText)
                 ,bIsCheckable
                )
 #endif // owner drawn
@@ -417,7 +375,7 @@ void wxMenuItem::SetText(
     // Don't do anything if label didn't change
     //
 
-    wxString                        sText = TextToLabel(rText);
+    wxString                        sText = wxPMTextToLabel(rText);
     if (m_text == sText)
         return;