X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/206d3a16caa7a4e626395ae52cc8f7e0225e202d..1ee3fb3846ae47c5292128a6f0bd4c8e38d7ba31:/samples/widgets/textctrl.cpp diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index f20eaf5cb7..aee45b0f9f 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 @@ -113,8 +113,10 @@ class TextWidgetsPage : public WidgetsPage { public: // ctor(s) and dtor - TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist); - virtual ~TextWidgetsPage(); + TextWidgetsPage(wxBookCtrl *book, wxImageList *imaglist); + virtual ~TextWidgetsPage(){}; + + virtual wxControl *GetWidget() const { return m_text; } protected: // create an info text contorl @@ -203,11 +205,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 +296,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 // ============================================================================ @@ -247,8 +310,8 @@ IMPLEMENT_WIDGETS_PAGE(TextWidgetsPage, _T("Text")); // TextWidgetsPage creation // ---------------------------------------------------------------------------- -TextWidgetsPage::TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist) - : WidgetsPage(notebook) +TextWidgetsPage::TextWidgetsPage(wxBookCtrl *book, wxImageList *imaglist) + : WidgetsPage(book) { imaglist->Add(wxBitmap(text_xpm)); @@ -438,10 +501,6 @@ TextWidgetsPage::TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist) sizerTop->Fit(this); } -TextWidgetsPage::~TextWidgetsPage() -{ -} - // ---------------------------------------------------------------------------- // creation helpers // ---------------------------------------------------------------------------- @@ -552,10 +611,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 | @@ -759,6 +815,7 @@ void TextWidgetsPage::OnText(wxCommandEvent& WXUNUSED(event)) void TextWidgetsPage::OnTextEnter(wxCommandEvent& event) { wxLogMessage(_T("Text entered: '%s'"), event.GetString().c_str()); + event.Skip(); } void TextWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))