, 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);
// 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
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
// ----------------------------------------------------------------------------
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 )
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;
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
// ----------------------------------------------------------------------------
wxAcceleratorEntry *wxMenuItemBase::GetAccel() const
{
- return wxGetAccelFromString(GetText());
+ return wxAcceleratorEntry::Create(GetText());
}
void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel)
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()))
{
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;
}
{
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
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
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:
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
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
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:
}
else
{
- wxAcceleratorEntry* entry = wxGetAccelFromString( item->GetText() ) ;
+ wxAcceleratorEntry*
+ entry = wxAcceleratorEntry::Create( item->GetText() ) ;
if ( item->GetId() == wxApp::s_macAboutMenuItemId )
{
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 ) ;
::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 ;
}
}
UMASetMenuItemText( mhandle , index , wxStripMenuCodes(text) , wxFont::GetDefaultEncoding() ) ;
- wxAcceleratorEntry *entry = wxGetAccelFromString( text ) ;
+ wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( text ) ;
UMASetMenuItemShortcut( mhandle , index , entry ) ;
delete entry ;
}
}
else
{
- wxAcceleratorEntry* entry = wxGetAccelFromString( item->GetText() ) ;
+ wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetText() ) ;
if ( item->GetId() == wxApp::s_macAboutMenuItemId )
{
::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 ;
}
}
UMASetMenuItemText( mhandle , index , text , wxFont::GetDefaultEncoding() ) ;
- wxAcceleratorEntry *entry = wxGetAccelFromString( text ) ;
+ wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( text ) ;
UMASetMenuItemShortcut( mhandle , index , entry ) ;
delete entry ;
}
}
// 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();
//
// 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();