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
This commit is contained in:
Vadim Zeitlin 2006-09-04 23:56:56 +00:00
parent e81b607b43
commit 90527a50d7
13 changed files with 71 additions and 39 deletions

View File

@ -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

View File

@ -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
// ----------------------------------------------------------------------------

View File

@ -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)

View File

@ -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()))
{

View File

@ -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;
}

View File

@ -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:

View File

@ -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:

View File

@ -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 ) ;

View File

@ -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 ;
}

View File

@ -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 )
{

View File

@ -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 ;
}

View File

@ -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();

View File

@ -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();