X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/206d3a16caa7a4e626395ae52cc8f7e0225e202d..b6536d60cfe3fe995b30ad2b0e2edf978cadc17a:/samples/widgets/textctrl.cpp?ds=inline diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index f20eaf5cb7..6ad3bb6a2c 100644 --- a/samples/widgets/textctrl.cpp +++ b/samples/widgets/textctrl.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Program: wxWindows Widgets Sample +// Program: wxWidgets Widgets Sample // Name: textctrl.cpp // Purpose: part of the widgets sample showing wxTextCtrl // Author: Vadim Zeitlin @@ -114,7 +114,7 @@ class TextWidgetsPage : public WidgetsPage public: // ctor(s) and dtor TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); - virtual ~TextWidgetsPage(); + virtual ~TextWidgetsPage(){}; protected: // create an info text contorl @@ -203,11 +203,68 @@ protected: wxString m_range10_20; private: - // any class wishing to process wxWindows events must use this macro + // any class wishing to process wxWidgets events must use this macro DECLARE_EVENT_TABLE() DECLARE_WIDGETS_PAGE(TextWidgetsPage) }; +// ---------------------------------------------------------------------------- +// WidgetsTextCtrl +// ---------------------------------------------------------------------------- + +class WidgetsTextCtrl : public wxTextCtrl +{ +public: + WidgetsTextCtrl(wxWindow *parent, + wxWindowID id, + const wxString& value, + int flags) + : wxTextCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize, flags) + { + } + +protected: + void OnRightClick(wxMouseEvent& event) + { + wxString where; + wxTextCoord x, y; + switch ( HitTest(event.GetPosition(), &x, &y) ) + { + default: + wxFAIL_MSG( _T("unexpected HitTest() result") ); + // fall through + + case wxTE_HT_UNKNOWN: + x = y = -1; + where = _T("nowhere near"); + break; + + case wxTE_HT_BEFORE: + where = _T("before"); + break; + + case wxTE_HT_BELOW: + where = _T("below"); + break; + + case wxTE_HT_BEYOND: + where = _T("beyond"); + break; + + case wxTE_HT_ON_TEXT: + where = _T("at"); + break; + } + + wxLogMessage(_T("Mouse is %s (%ld, %ld)"), where.c_str(), x, y); + + event.Skip(); + } + +private: + DECLARE_EVENT_TABLE() +}; + // ---------------------------------------------------------------------------- // event tables // ---------------------------------------------------------------------------- @@ -237,6 +294,10 @@ BEGIN_EVENT_TABLE(TextWidgetsPage, WidgetsPage) EVT_RADIOBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox) END_EVENT_TABLE() +BEGIN_EVENT_TABLE(WidgetsTextCtrl, wxTextCtrl) + EVT_RIGHT_UP(WidgetsTextCtrl::OnRightClick) +END_EVENT_TABLE() + // ============================================================================ // implementation // ============================================================================ @@ -438,10 +499,6 @@ TextWidgetsPage::TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist) sizerTop->Fit(this); } -TextWidgetsPage::~TextWidgetsPage() -{ -} - // ---------------------------------------------------------------------------- // creation helpers // ---------------------------------------------------------------------------- @@ -552,10 +609,7 @@ void TextWidgetsPage::CreateText() valueOld = _T("Hello, Universe!"); } - m_text = new wxTextCtrl(this, TextPage_Textctrl, - valueOld, - wxDefaultPosition, wxDefaultSize, - flags); + m_text = new WidgetsTextCtrl(this, TextPage_Textctrl, valueOld, flags); // cast to int needed to silence gcc warning about different enums m_sizerText->Add(m_text, 1, wxALL |