From 90527a50d74bed6ed6b4d163e8170ae8c3f5d869 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 4 Sep 2006 23:56:56 +0000 Subject: [PATCH] use (new) wxAcceleratorEntry::Create() instead of recently deprecated wxGetAccelFromString() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41013 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/accel.h | 10 ++++++++- include/wx/utils.h | 7 ++++-- src/common/menucmn.cpp | 42 +++++++++++++++++++++++------------- src/generic/accel.cpp | 4 ++-- src/gtk/dnd.cpp | 8 +++++++ src/gtk/menu.cpp | 10 ++++----- src/gtk1/menu.cpp | 9 ++++---- src/mac/carbon/menu.cpp | 6 ++++-- src/mac/carbon/menuitem.cpp | 4 ++-- src/mac/classic/menu.cpp | 2 +- src/mac/classic/menuitem.cpp | 4 ++-- src/msw/menu.cpp | 2 +- src/os2/menu.cpp | 2 +- 13 files changed, 71 insertions(+), 39 deletions(-) diff --git a/include/wx/accel.h b/include/wx/accel.h index 02135de643..80f35ede71 100644 --- a/include/wx/accel.h +++ b/include/wx/accel.h @@ -62,6 +62,10 @@ public: , m_item(entry.m_item) { } + // create accelerator corresponding to the specified string, return NULL if + // string couldn't be parsed or a pointer to be deleted by the caller + static wxAcceleratorEntry *Create(const wxString& str); + wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry) { Set(entry.m_flags, entry.m_keyCode, entry.m_command, entry.m_item); @@ -117,10 +121,14 @@ public: // returns true if the given string correctly initialized this object // (i.e. if IsOk() returns true after this call) - bool FromString(const wxString &str); + bool FromString(const wxString& str); private: + // common part of Create() and FromString() + static bool ParseAccel(const wxString& str, int *flags, int *keycode); + + int m_flags; // combination of wxACCEL_XXX constants int m_keyCode; // ASCII or virtual keycode int m_command; // Command id to generate diff --git a/include/wx/utils.h b/include/wx/utils.h index 75426eca32..499f2bad0f 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -558,20 +558,23 @@ enum WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str, int flags = wxStrip_All); -// obsolete and deprecated version, do not use #if WXWIN_COMPATIBILITY_2_6 +// obsolete and deprecated version, do not use, use the above overload instead wxDEPRECATED( WXDLLEXPORT wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = NULL) ); -#endif #if wxUSE_ACCEL class WXDLLEXPORT wxAcceleratorEntry; + +// use wxAcceleratorEntry::Create() or FromString() methods instead wxDEPRECATED( WXDLLEXPORT wxAcceleratorEntry *wxGetAccelFromString(const wxString& label) ); #endif // wxUSE_ACCEL +#endif // WXWIN_COMPATIBILITY_2_6 + // ---------------------------------------------------------------------------- // Window search // ---------------------------------------------------------------------------- diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 09251fcb4d..896c9e1e03 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -170,15 +170,13 @@ static int return prefixCode + num - first; } -bool wxAcceleratorEntry::FromString(const wxString& text) +/* static */ +bool +wxAcceleratorEntry::ParseAccel(const wxString& text, int *flagsOut, int *keyOut) { // the parser won't like leading/trailing spaces wxString label = text.Strip(wxString::both); - // set to invalid state: - m_flags = 0; - m_keyCode = 0; - // check for accelerators: they are given after '\t' int posTab = label.Find(wxT('\t')); if ( posTab == wxNOT_FOUND ) @@ -278,11 +276,30 @@ bool wxAcceleratorEntry::FromString(const wxString& text) wxASSERT_MSG( keyCode, _T("logic error: should have key code here") ); - m_flags = accelFlags; - m_keyCode = keyCode; + if ( flagsOut ) + *flagsOut = accelFlags; + if ( keyOut ) + *keyOut = keyCode; + return true; } +/* static */ +wxAcceleratorEntry *wxAcceleratorEntry::Create(const wxString& str) +{ + int flags, + keyCode; + if ( !ParseAccel(str, &flags, &keyCode) ) + return NULL; + + return new wxAcceleratorEntry(flags, keyCode); +} + +bool wxAcceleratorEntry::FromString(const wxString& str) +{ + return ParseAccel(str, &m_flags, &m_keyCode); +} + wxString wxAcceleratorEntry::ToString() const { wxString text; @@ -327,15 +344,10 @@ wxString wxAcceleratorEntry::ToString() const wxAcceleratorEntry *wxGetAccelFromString(const wxString& label) { - wxAcceleratorEntry *ret = new wxAcceleratorEntry(); - if (ret->FromString(label)) - return ret; - - wxDELETE(ret); - return NULL; + return wxAcceleratorEntry::Create(label); } -#endif // wxUSE_ACCEL +#endif // wxUSE_ACCEL // ---------------------------------------------------------------------------- @@ -374,7 +386,7 @@ wxMenuItemBase::~wxMenuItemBase() wxAcceleratorEntry *wxMenuItemBase::GetAccel() const { - return wxGetAccelFromString(GetText()); + return wxAcceleratorEntry::Create(GetText()); } void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel) diff --git a/src/generic/accel.cpp b/src/generic/accel.cpp index f31532caa6..b6ae238a75 100644 --- a/src/generic/accel.cpp +++ b/src/generic/accel.cpp @@ -138,8 +138,8 @@ void wxAcceleratorTable::Remove(const wxAcceleratorEntry& entry) const wxAcceleratorEntry *entryCur = node->GetData(); // given entry contains only the information of the accelerator key - // because it was set that way in wxGetAccelFromString() - // so do not perform full ( *entryCur == entry ) comparison + // because it was set that way during creation so do not use the + // comparison operator which also checks the command field if ((entryCur->GetKeyCode() == entry.GetKeyCode()) && (entryCur->GetFlags() == entry.GetFlags())) { diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index aadec6a638..7565e877ba 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -910,6 +910,14 @@ wxDragResult wxDropSource::DoDragDrop(int flags) UnregisterWindow(); + // this shouldn't be needed but somehow, sometimes, without this the cursor + // stays grabbed even when the DND operation ends and the application + // becomes unresponsive and has to be killed resulting in loss of all + // unsaved data, so while this fix is ugly it's still better than + // alternative + if ( gdk_pointer_is_grabbed() ) + gdk_pointer_ungrab(GDK_CURRENT_TIME); + return m_retValue; } diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 993c2881bd..caec716a87 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -920,7 +920,6 @@ void wxMenuItem::DoSetText( const wxString& str ) { m_text.Empty(); m_text = GTKProcessMenuItemLabel(str, &m_hotKey); - // wxPrintf( wxT("DoSetText(): str %s m_text %s hotkey %s\n"), str.c_str(), m_text.c_str(), m_hotKey.c_str() ); } #if wxUSE_ACCEL @@ -930,14 +929,15 @@ wxAcceleratorEntry *wxMenuItem::GetAccel() const if ( !GetHotKey() ) { // nothing - return (wxAcceleratorEntry *)NULL; + return NULL; } - // as wxGetAccelFromString() looks for TAB, insert a dummy one here + // accelerator parsing code looks for them after a TAB, so insert a dummy + // one here wxString label; label << wxT('\t') << GetHotKey(); - return wxGetAccelFromString(label); + return wxAcceleratorEntry::Create(label); } #endif // wxUSE_ACCEL @@ -1536,7 +1536,7 @@ static wxString GetGtkHotKey( const wxMenuItem& item ) hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1); break; */ - // if there are any other keys wxGetAccelFromString() may + // if there are any other keys wxAcceleratorEntry::Create() may // return, we should process them here default: diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index ab623d957b..10fee257c6 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -865,8 +865,6 @@ void wxMenuItem::DoSetText( const wxString& str ) pc++; m_hotKey = pc; } - - // wxPrintf( wxT("DoSetText(): str %s m_text %s hotkey %s\n"), str.c_str(), m_text.c_str(), m_hotKey.c_str() ); } #if wxUSE_ACCEL @@ -879,11 +877,12 @@ wxAcceleratorEntry *wxMenuItem::GetAccel() const return (wxAcceleratorEntry *)NULL; } - // as wxGetAccelFromString() looks for TAB, insert a dummy one here + // accelerator parsing code looks for them after a TAB, so insert a dummy + // one here wxString label; label << wxT('\t') << GetHotKey(); - return wxGetAccelFromString(label); + return wxAcceleratorEntry::Create(label); } #endif // wxUSE_ACCEL @@ -1423,7 +1422,7 @@ static wxString GetGtkHotKey( const wxMenuItem& item ) hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1); break; */ - // if there are any other keys wxGetAccelFromString() may + // if there are any other keys wxAcceleratorEntry::Create() may // return, we should process them here default: diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index 1b7571af3d..391e97b560 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -698,7 +698,8 @@ void wxMenuBar::MacInstallMenuBar() } else { - wxAcceleratorEntry* entry = wxGetAccelFromString( item->GetText() ) ; + wxAcceleratorEntry* + entry = wxAcceleratorEntry::Create( item->GetText() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { @@ -733,7 +734,8 @@ void wxMenuBar::MacInstallMenuBar() wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; if ( aboutMenuItem ) { - wxAcceleratorEntry* entry = wxGetAccelFromString( aboutMenuItem->GetText() ) ; + wxAcceleratorEntry* + entry = wxAcceleratorEntry::Create( aboutMenuItem->GetText() ) ; UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetText() ) , wxFont::GetDefaultEncoding() ); UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index de6298870b..7d6dc48db1 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -121,7 +121,7 @@ void wxMenuItem::UpdateItemStatus() ::SetItemMark( mhandle , index , 0 ) ; // no mark UMASetMenuItemText( mhandle , index , wxStripMenuCodes(m_text) , wxFont::GetDefaultEncoding() ) ; - wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ; + wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( m_text ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ; delete entry ; } @@ -145,7 +145,7 @@ void wxMenuItem::UpdateItemText() } UMASetMenuItemText( mhandle , index , wxStripMenuCodes(text) , wxFont::GetDefaultEncoding() ) ; - wxAcceleratorEntry *entry = wxGetAccelFromString( text ) ; + wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( text ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ; delete entry ; } diff --git a/src/mac/classic/menu.cpp b/src/mac/classic/menu.cpp index a075a91e7c..cb384236e0 100644 --- a/src/mac/classic/menu.cpp +++ b/src/mac/classic/menu.cpp @@ -574,7 +574,7 @@ void wxMenuBar::MacInstallMenuBar() } else { - wxAcceleratorEntry* entry = wxGetAccelFromString( item->GetText() ) ; + wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetText() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { diff --git a/src/mac/classic/menuitem.cpp b/src/mac/classic/menuitem.cpp index f541a795a2..51a8a3ca5a 100644 --- a/src/mac/classic/menuitem.cpp +++ b/src/mac/classic/menuitem.cpp @@ -135,7 +135,7 @@ void wxMenuItem::UpdateItemStatus() ::SetItemMark( mhandle , index , 0 ) ; // no mark UMASetMenuItemText( mhandle , index , m_text , wxFont::GetDefaultEncoding() ) ; - wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ; + wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( m_text ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ; delete entry ; } @@ -159,7 +159,7 @@ void wxMenuItem::UpdateItemText() } UMASetMenuItemText( mhandle , index , text , wxFont::GetDefaultEncoding() ) ; - wxAcceleratorEntry *entry = wxGetAccelFromString( text ) ; + wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( text ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ; delete entry ; } diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 156e4e4035..03c844447c 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -315,7 +315,7 @@ void wxMenu::UpdateAccel(wxMenuItem *item) } // find the (new) accel for this item - wxAcceleratorEntry *accel = wxGetAccelFromString(item->GetText()); + wxAcceleratorEntry *accel = wxAcceleratorEntry::Create(item->GetText()); if ( accel ) accel->m_command = item->GetId(); diff --git a/src/os2/menu.cpp b/src/os2/menu.cpp index 3f8db0640b..ae8c5db5fc 100644 --- a/src/os2/menu.cpp +++ b/src/os2/menu.cpp @@ -201,7 +201,7 @@ void wxMenu::UpdateAccel( // // Find the (new) accel for this item // - wxAcceleratorEntry* pAccel = wxGetAccelFromString(pItem->GetText()); + wxAcceleratorEntry* pAccel = wxAcceleratorEntry::Create(pItem->GetText()); if (pAccel) pAccel->m_command = pItem->GetId(); -- 2.47.2