From 085e4c354aa82994cd15bb8f8a30394b7462df25 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Jun 2018 16:32:00 +0200 Subject: [PATCH] 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. --- samples/widgets/textctrl.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index c89ba6ca93..96e5074954 100644 --- a/samples/widgets/textctrl.cpp +++ b/samples/widgets/textctrl.cpp @@ -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);