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

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