]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/textctrl.cpp
demonstrate tab order
[wxWidgets.git] / samples / widgets / textctrl.cpp
index f20eaf5cb7b97d0ae6adbcf466412bf44b6f0bd7..31e3c9c15a6e55657678e2c80cc09136bb507e8e 100644 (file)
@@ -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
@@ -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
 // ============================================================================
@@ -552,10 +613,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 |