Override Ctrl-A accelerator when wxTextCtrl has focus in wxMSW
This key combination is used for selecting all text, while it's also relatively common to use it as an accelerator for some menu item. Resolve the conflict in favour of wxTextCtrl, i.e. let it have this key when it has focus, while still allowing to use it as an accelerator otherwise.
This commit is contained in:
@@ -2048,6 +2048,7 @@ bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* msg)
|
|||||||
{
|
{
|
||||||
switch ( vkey )
|
switch ( vkey )
|
||||||
{
|
{
|
||||||
|
case 'A':
|
||||||
case 'C':
|
case 'C':
|
||||||
case 'V':
|
case 'V':
|
||||||
case 'X':
|
case 'X':
|
||||||
|
@@ -36,6 +36,7 @@ namespace
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
MenuTestCase_Foo = 10000,
|
MenuTestCase_Foo = 10000,
|
||||||
|
MenuTestCase_SelectAll,
|
||||||
MenuTestCase_Bar,
|
MenuTestCase_Bar,
|
||||||
MenuTestCase_First
|
MenuTestCase_First
|
||||||
};
|
};
|
||||||
@@ -168,6 +169,9 @@ void MenuTestCase::CreateFrame()
|
|||||||
|
|
||||||
fileMenu->Append(MenuTestCase_Foo, "&Foo\tCtrl-F", "Test item to be found");
|
fileMenu->Append(MenuTestCase_Foo, "&Foo\tCtrl-F", "Test item to be found");
|
||||||
m_itemCount++;
|
m_itemCount++;
|
||||||
|
fileMenu->Append(MenuTestCase_SelectAll, "Select &all\tCtrl-A",
|
||||||
|
"Accelerator conflicting with wxTextCtrl");
|
||||||
|
m_itemCount++;
|
||||||
|
|
||||||
|
|
||||||
PopulateMenu(helpMenu, "Helpmenu item ", m_itemCount);
|
PopulateMenu(helpMenu, "Helpmenu item ", m_itemCount);
|
||||||
@@ -548,6 +552,11 @@ public:
|
|||||||
return *m_event;
|
return *m_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GotEvent() const
|
||||||
|
{
|
||||||
|
return m_gotEvent;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnMenu(wxCommandEvent& event)
|
void OnMenu(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
@@ -607,6 +616,24 @@ void MenuTestCase::Events()
|
|||||||
wxString(src->GetClassInfo()->GetClassName()) );
|
wxString(src->GetClassInfo()->GetClassName()) );
|
||||||
CPPUNIT_ASSERT_EQUAL( static_cast<wxObject*>(m_menuWithBar),
|
CPPUNIT_ASSERT_EQUAL( static_cast<wxObject*>(m_menuWithBar),
|
||||||
src );
|
src );
|
||||||
|
|
||||||
|
// Invoke another accelerator, it should also work.
|
||||||
|
sim.Char('A', wxMOD_CONTROL);
|
||||||
|
wxYield();
|
||||||
|
|
||||||
|
const wxCommandEvent& ev2 = handler.GetEvent();
|
||||||
|
CHECK( ev2.GetId() == MenuTestCase_SelectAll );
|
||||||
|
|
||||||
|
// Now create a text control which uses the same accelerator for itself and
|
||||||
|
// check that when the text control has focus, the accelerator does _not_
|
||||||
|
// work.
|
||||||
|
wxTextCtrl* const text = new wxTextCtrl(m_frame, wxID_ANY, "Testing");
|
||||||
|
text->SetFocus();
|
||||||
|
|
||||||
|
sim.Char('A', wxMOD_CONTROL);
|
||||||
|
wxYield();
|
||||||
|
|
||||||
|
CHECK( !handler.GotEvent() );
|
||||||
#endif // wxUSE_UIACTIONSIMULATOR
|
#endif // wxUSE_UIACTIONSIMULATOR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user