Show HitTest() result on left click in "Text" widgets sample page

Right clicking didn't work under wxGTK where it just showed the context
menu, so use left click handler instead and check whether "Alt" is
pressed.

Also add a note to make this test more discoverable.
This commit is contained in:
Vadim Zeitlin 2018-06-03 16:32:00 +02:00
parent 950b1a9d51
commit 085e4c354a

View File

@ -276,11 +276,17 @@ public:
int flags)
: wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize, flags)
{
Bind(wxEVT_LEFT_DOWN, &WidgetsTextCtrl::OnLeftClick, this);
}
protected:
void OnRightClick(wxMouseEvent& event)
private:
// Show the result of HitTest() at the mouse position if Alt is pressed.
void OnLeftClick(wxMouseEvent& event)
{
event.Skip();
if ( !event.AltDown() )
return;
wxString where;
wxTextCoord x, y;
switch ( HitTest(event.GetPosition(), &x, &y) )
@ -312,12 +318,7 @@ protected:
}
wxLogMessage(wxT("Mouse is %s (%ld, %ld)"), where.c_str(), x, y);
event.Skip();
}
private:
wxDECLARE_EVENT_TABLE();
};
// ----------------------------------------------------------------------------
@ -353,10 +354,6 @@ wxBEGIN_EVENT_TABLE(TextWidgetsPage, WidgetsPage)
EVT_RADIOBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
wxEND_EVENT_TABLE()
wxBEGIN_EVENT_TABLE(WidgetsTextCtrl, wxTextCtrl)
EVT_RIGHT_UP(WidgetsTextCtrl::OnRightClick)
wxEND_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
@ -593,6 +590,17 @@ void TextWidgetsPage::CreateContent()
0, wxALL, 5
);
sizerMiddleDown->Add
(
new wxStaticText
(
this,
wxID_ANY,
"Alt-click in the text to see HitTest() result"
),
wxSizerFlags().Border()
);
wxSizer *sizerMiddle = new wxBoxSizer(wxVERTICAL);
sizerMiddle->Add(sizerMiddleUp, 0, wxGROW);
sizerMiddle->Add(sizerMiddleDown, 1, wxGROW | wxTOP, 5);