From 505928852c16c8ec68c8c3657fc0b8210c782261 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 26 Oct 1999 13:45:29 +0000 Subject: [PATCH] fix for items without accelerators git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4197 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/menu.cpp | 83 +++++++++++++++++++++++++---------------------- src/gtk1/menu.cpp | 83 +++++++++++++++++++++++++---------------------- 2 files changed, 88 insertions(+), 78 deletions(-) diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index d0b20891bb..bc156417a7 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -810,51 +810,56 @@ static wxString GetHotKey( const wxMenuItem& item ) // as wxGetAccelFromString() looks for TAB, insert a dummy one here wxString label; label << wxT('\t') << item.GetHotKey(); - wxAcceleratorEntry *accel = wxGetAccelFromString(label); - if ( accel ) + + // but if the hotkey is empty don't do anything + if ( label.length() > 1 ) { - int flags = accel->GetFlags(); - if ( flags & wxACCEL_ALT ) - hotkey += wxT(""); - if ( flags & wxACCEL_CTRL ) - hotkey += wxT(""); - if ( flags & wxACCEL_SHIFT ) - hotkey += wxT(""); - - int code = accel->GetKeyCode(); - switch ( code ) + wxAcceleratorEntry *accel = wxGetAccelFromString(label); + if ( accel ) { - case WXK_F1: - case WXK_F2: - case WXK_F3: - case WXK_F4: - case WXK_F5: - case WXK_F6: - case WXK_F7: - case WXK_F8: - case WXK_F9: - case WXK_F10: - case WXK_F11: - case WXK_F12: - hotkey << wxT('F') << code = WXK_F1 + 1; - break; - - // if there are any other keys wxGetAccelFromString() may return, - // we should process them here - - default: - if ( wxIsalnum(code) ) - { - hotkey << (wxChar)code; - + int flags = accel->GetFlags(); + if ( flags & wxACCEL_ALT ) + hotkey += wxT(""); + if ( flags & wxACCEL_CTRL ) + hotkey += wxT(""); + if ( flags & wxACCEL_SHIFT ) + hotkey += wxT(""); + + int code = accel->GetKeyCode(); + switch ( code ) + { + case WXK_F1: + case WXK_F2: + case WXK_F3: + case WXK_F4: + case WXK_F5: + case WXK_F6: + case WXK_F7: + case WXK_F8: + case WXK_F9: + case WXK_F10: + case WXK_F11: + case WXK_F12: + hotkey << wxT('F') << code = WXK_F1 + 1; break; - } - wxFAIL_MSG( wxT("unknown keyboard accel") ); + // if there are any other keys wxGetAccelFromString() may return, + // we should process them here + + default: + if ( wxIsalnum(code) ) + { + hotkey << (wxChar)code; + + break; + } + + wxFAIL_MSG( wxT("unknown keyboard accel") ); + } + + delete accel; } } - if (accel) - delete accel; return hotkey; } diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index d0b20891bb..bc156417a7 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -810,51 +810,56 @@ static wxString GetHotKey( const wxMenuItem& item ) // as wxGetAccelFromString() looks for TAB, insert a dummy one here wxString label; label << wxT('\t') << item.GetHotKey(); - wxAcceleratorEntry *accel = wxGetAccelFromString(label); - if ( accel ) + + // but if the hotkey is empty don't do anything + if ( label.length() > 1 ) { - int flags = accel->GetFlags(); - if ( flags & wxACCEL_ALT ) - hotkey += wxT(""); - if ( flags & wxACCEL_CTRL ) - hotkey += wxT(""); - if ( flags & wxACCEL_SHIFT ) - hotkey += wxT(""); - - int code = accel->GetKeyCode(); - switch ( code ) + wxAcceleratorEntry *accel = wxGetAccelFromString(label); + if ( accel ) { - case WXK_F1: - case WXK_F2: - case WXK_F3: - case WXK_F4: - case WXK_F5: - case WXK_F6: - case WXK_F7: - case WXK_F8: - case WXK_F9: - case WXK_F10: - case WXK_F11: - case WXK_F12: - hotkey << wxT('F') << code = WXK_F1 + 1; - break; - - // if there are any other keys wxGetAccelFromString() may return, - // we should process them here - - default: - if ( wxIsalnum(code) ) - { - hotkey << (wxChar)code; - + int flags = accel->GetFlags(); + if ( flags & wxACCEL_ALT ) + hotkey += wxT(""); + if ( flags & wxACCEL_CTRL ) + hotkey += wxT(""); + if ( flags & wxACCEL_SHIFT ) + hotkey += wxT(""); + + int code = accel->GetKeyCode(); + switch ( code ) + { + case WXK_F1: + case WXK_F2: + case WXK_F3: + case WXK_F4: + case WXK_F5: + case WXK_F6: + case WXK_F7: + case WXK_F8: + case WXK_F9: + case WXK_F10: + case WXK_F11: + case WXK_F12: + hotkey << wxT('F') << code = WXK_F1 + 1; break; - } - wxFAIL_MSG( wxT("unknown keyboard accel") ); + // if there are any other keys wxGetAccelFromString() may return, + // we should process them here + + default: + if ( wxIsalnum(code) ) + { + hotkey << (wxChar)code; + + break; + } + + wxFAIL_MSG( wxT("unknown keyboard accel") ); + } + + delete accel; } } - if (accel) - delete accel; return hotkey; } -- 2.45.2