From 58f16ff09672f3e37156d0fc5e79e310b2c49c08 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 1 Apr 2011 12:18:49 +0100 Subject: add accelerators to Unix 'Ok'/'Cancel' dialog buttons --- vcl/source/control/button.cxx | 10 +++++++++- vcl/unx/gtk/app/gtksys.cxx | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index 7efaf732da34..7926ee339bc7 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 91d40f0e3b16..db90edf39b99 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++; } -- cgit v1.2.3