[Libreoffice-commits] .: vcl/source vcl/unx

Michael Meeks mmeeks at kemper.freedesktop.org
Fri Apr 1 04:20:01 PDT 2011


 vcl/source/control/button.cxx |   10 +++++++++-
 vcl/unx/gtk/app/gtksys.cxx    |   15 ++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

New commits:
commit 02a0d7453669e6d669f0ffa3dfd7b7c8031065cb
Author: Michael Meeks <michael.meeks at novell.com>
Date:   Fri Apr 1 12:18:49 2011 +0100

    add accelerators to Unix 'Ok'/'Cancel' dialog buttons

diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx
index d1006a7..c77d14a 100644
--- a/vcl/source/control/button.cxx
+++ b/vcl/source/control/button.cxx
@@ -180,8 +180,16 @@ XubString Button::GetStandardText( StandardButtonType eButton )
     ResMgr* pResMgr = ImplGetResMgr();
     if( pResMgr )
     {
-        ResId aResId( aResIdAry[(sal_uInt16)eButton].nResId, *pResMgr );
+        sal_uInt32 nResId = aResIdAry[(sal_uInt16)eButton].nResId;
+        ResId aResId( nResId, *pResMgr );
         aText = String( aResId );
+
+        // Windows (apparently) has some magic auto-accelerator evil around
+        // ok / cancel so add this only for Unix
+#ifdef UNX
+        if( nResId == SV_BUTTONTEXT_OK || nResId == SV_BUTTONTEXT_CANCEL )
+            aText.Insert( String::CreateFromAscii("~"), 0 );
+#endif
     }
     else
     {
diff --git a/vcl/unx/gtk/app/gtksys.cxx b/vcl/unx/gtk/app/gtksys.cxx
index 04dc126..65aac71 100644
--- a/vcl/unx/gtk/app/gtksys.cxx
+++ b/vcl/unx/gtk/app/gtksys.cxx
@@ -53,6 +53,14 @@ GtkSalSystem::~GtkSalSystem()
 {
 }
 
+// convert ~ to indicate mnemonic to '_'
+static ByteString MapToGtkAccelerator (const String &rStr)
+{
+    String aRet( rStr );
+    aRet.SearchAndReplaceAscii("~", String::CreateFromAscii("_"));
+    return ByteString( aRet, RTL_TEXTENCODING_UTF8 );
+}
+
 int GtkSalSystem::ShowNativeDialog( const String& rTitle,
                                     const String& rMessage,
                                     const std::list< String >& rButtons,
@@ -81,15 +89,16 @@ int GtkSalSystem::ShowNativeDialog( const String& rTitle,
     int nButton = 0;
     for( std::list< String >::const_iterator it = rButtons.begin(); it != rButtons.end(); ++it )
     {
-        ByteString aLabel( *it, RTL_TEXTENCODING_UTF8 );
-
         if( nButton == nDefButton )
         {
-            gtk_dialog_add_button( GTK_DIALOG( mainwin ), aLabel.GetBuffer(), nButtons );
+            gtk_dialog_add_button( GTK_DIALOG( mainwin ), MapToGtkAccelerator(*it).GetBuffer(), nButtons );
             gtk_dialog_set_default_response( GTK_DIALOG( mainwin ), nButtons );
         }
         else
+        {
+            ByteString aLabel( *it, RTL_TEXTENCODING_UTF8 );
             gtk_dialog_add_button( GTK_DIALOG( mainwin ), aLabel.GetBuffer(), nButtons );
+        }
         nButtons++;
     }
 


More information about the Libreoffice-commits mailing list