]> git.saurik.com Git - wxWidgets.git/commitdiff
Instead of having wxComboCtrl mimic wxTextEntry interface, make it actually inherit...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 16 Dec 2010 17:21:49 +0000 (17:21 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 16 Dec 2010 17:21:49 +0000 (17:21 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66385 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/combo.h
include/wx/generic/combo.h
include/wx/msw/combo.h
interface/wx/combo.h
src/common/combocmn.cpp
src/common/valtext.cpp
src/generic/combog.cpp
src/msw/combo.cpp

index 6a190e524aecdcd22590b285c8713f01f7db5653..f0c06eb48485694e28658dcb56f187d5ff6a4f96 100644 (file)
@@ -45,6 +45,7 @@
 #include "wx/control.h"
 #include "wx/renderer.h" // this is needed for wxCONTROL_XXX flags
 #include "wx/bitmap.h" // wxBitmap used by-value
+#include "wx/textentry.h"
 
 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
 class WXDLLIMPEXP_FWD_CORE wxComboPopup;
@@ -139,13 +140,14 @@ struct wxComboCtrlFeatures
 };
 
 
-class WXDLLIMPEXP_CORE wxComboCtrlBase : public wxControl
+class WXDLLIMPEXP_CORE wxComboCtrlBase : public wxControl,
+                                         public wxTextEntry
 {
     friend class wxComboPopup;
     friend class wxComboPopupEvtHandler;
 public:
     // ctors and such
-    wxComboCtrlBase() : wxControl() { Init(); }
+    wxComboCtrlBase() : wxControl(), wxTextEntry() { Init(); }
 
     bool Create(wxWindow *parent,
                 wxWindowID id,
@@ -196,26 +198,38 @@ public:
     virtual bool Enable(bool enable = true);
     virtual bool Show(bool show = true);
     virtual bool SetFont(const wxFont& font);
-#if wxUSE_VALIDATORS
-    virtual void SetValidator(const wxValidator &validator);
-    virtual wxValidator *GetValidator();
-#endif // wxUSE_VALIDATORS
 
     // wxTextCtrl methods - for readonly combo they should return
     // without errors.
-    virtual wxString GetValue() const;
     virtual void SetValue(const wxString& value);
+
+    // wxTextEntry methods - we basically need to override all of them
+    virtual void WriteText(const wxString& text);
+
+    virtual void Replace(long from, long to, const wxString& value);
+    virtual void Remove(long from, long to);
+
     virtual void Copy();
     virtual void Cut();
     virtual void Paste();
+
+    virtual void Undo();
+    virtual void Redo();
+    virtual bool CanUndo() const;
+    virtual bool CanRedo() const;
+
     virtual void SetInsertionPoint(long pos);
-    virtual void SetInsertionPointEnd();
     virtual long GetInsertionPoint() const;
     virtual long GetLastPosition() const;
-    virtual void Replace(long from, long to, const wxString& value);
-    virtual void Remove(long from, long to);
+
     virtual void SetSelection(long from, long to);
-    virtual void Undo();
+    virtual void GetSelection(long *from, long *to) const;
+
+    virtual bool IsEditable() const;
+    virtual void SetEditable(bool editable);
+
+    virtual bool SetHint(const wxString& hint);
+    virtual wxString GetHint() const;
 
     // This method sets the text without affecting list selection
     // (ie. wxComboPopup::SetStringValue doesn't get called).
@@ -387,21 +401,6 @@ public:
     const wxBitmap& GetBitmapHover() const { return m_bmpHover; }
     const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; }
 
-    // Hint functions mirrored from TextEntryBase
-    virtual bool SetHint(const wxString& hint);
-    virtual wxString GetHint() const;
-
-    // Margins functions mirrored from TextEntryBase
-    // (wxComboCtrl does not inherit from wxTextEntry, but may embed a
-    // wxTextCtrl, so we need these). Also note that these functions
-    // have replaced SetTextIndent() in wxWidgets 2.9.1 and later.
-    bool SetMargins(const wxPoint& pt)
-        { return DoSetMargins(pt); }
-    bool SetMargins(wxCoord left, wxCoord top = -1)
-        { return DoSetMargins(wxPoint(left, top)); }
-    wxPoint GetMargins() const
-        { return DoGetMargins(); }
-
     // Set custom style flags for embedded wxTextCtrl. Usually must be used
     // with two-step creation, before Create() call.
     void SetTextCtrlStyle( int style );
@@ -463,7 +462,7 @@ protected:
 
     // Creates wxTextCtrl.
     //   extraStyle: Extra style parameters
-    void CreateTextCtrl( int extraStyle, const wxValidator& validator );
+    void CreateTextCtrl( int extraStyle );
 
     // Installs standard input handler to combo (and optionally to the textctrl)
     void InstallInputHandlers();
@@ -558,6 +557,10 @@ protected:
     virtual void DoSetToolTip( wxToolTip *tip );
 #endif
 
+    // protected wxTextEntry methods
+    virtual wxString DoGetValue() const;
+    virtual wxWindow *GetEditableWindow() { return this; }
+
     // margins functions
     virtual bool DoSetMargins(const wxPoint& pt);
     virtual wxPoint DoGetMargins() const;
index 703e42fa3afa87545161e8717acdd55dec98a925..108c8cfeb51457115ccde330d108ade6655b4110 100644 (file)
@@ -80,6 +80,16 @@ public:
 
 protected:
 
+    // Dummies for platform-specific wxTextEntry implementations
+#if defined(__WXGTK__)
+    virtual GtkEditable *GetEditable() const { return NULL; }
+    virtual GtkEntry *GetEntry() const { return NULL; }
+#elif defined(__WXMAC__)
+    // Looks like there's nothing we need to override here
+#elif defined(__WXPM__)
+    virtual WXHWND GetEditHWND() const { return NULL; }
+#endif
+
     // Mandatory virtuals
     virtual void OnResize();
 
index be85dbcf41ea3e99074de92bf2a7cae2bf8d15cd..c5b27687d72b9ff5451e992cbfa062c82bb773b9 100644 (file)
@@ -83,6 +83,9 @@ protected:
 
 protected:
 
+    // Dummy method - we override all functions that call this
+    virtual WXHWND GetEditHWND() const { return NULL; }
+
     // customization
     virtual void OnResize();
     virtual wxCoord GetNativeTextIndent() const;
index a057ba000c12693b9a4fbfd71c3474d88c83527b..32afe45bd5efacbfb4885dddf4bfff8ba016cf05 100644 (file)
@@ -320,7 +320,8 @@ struct wxComboCtrlFeatures
     @see wxComboBox, wxChoice, wxOwnerDrawnComboBox, wxComboPopup,
          wxCommandEvent
 */
-class wxComboCtrl : public wxControl
+class wxComboCtrl : public wxControl,
+                    public wxTextEntry
 {
 public:
     /**
index e87b7df0d8aad5d3387c28d8f07362eb6501140f..0de8dd9d36af487c0767eb73f8f780c07e2d0e0e 100644 (file)
@@ -963,7 +963,7 @@ void wxComboCtrlBase::InstallInputHandlers()
 }
 
 void
-wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator)
+wxComboCtrlBase::CreateTextCtrl(int style)
 {
     if ( !(m_windowStyle & wxCB_READONLY) )
     {
@@ -990,7 +990,7 @@ wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator)
         m_text = new wxComboCtrlTextCtrl();
         m_text->Create(this, wxID_ANY, m_valueString,
                        wxDefaultPosition, wxSize(10,-1),
-                       style, validator);
+                       style);
         m_text->SetHint(m_hintText);
     }
 }
@@ -1391,25 +1391,6 @@ void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
 }
 #endif // wxUSE_TOOLTIPS
 
-#if wxUSE_VALIDATORS
-void wxComboCtrlBase::SetValidator(const wxValidator& validator)
-{
-    wxTextCtrl* textCtrl = GetTextCtrl();
-
-    if ( textCtrl )
-        textCtrl->SetValidator( validator );
-    else
-        wxControl::SetValidator( validator );
-}
-
-wxValidator* wxComboCtrlBase::GetValidator()
-{
-    wxTextCtrl* textCtrl = GetTextCtrl();
-
-    return textCtrl ? textCtrl->GetValidator() : wxControl::GetValidator();
-}
-#endif // wxUSE_VALIDATORS
-
 bool wxComboCtrlBase::SetForegroundColour(const wxColour& colour)
 {
     if ( wxControl::SetForegroundColour(colour) )
@@ -2564,10 +2545,10 @@ void wxComboCtrlBase::SetTextCtrlStyle( int style )
 }
 
 // ----------------------------------------------------------------------------
-// methods forwarded to wxTextCtrl
+// wxTextEntry interface
 // ----------------------------------------------------------------------------
 
-wxString wxComboCtrlBase::GetValue() const
+wxString wxComboCtrlBase::DoGetValue() const
 {
     if ( m_text )
         return m_text->GetValue();
@@ -2649,12 +2630,6 @@ void wxComboCtrlBase::SetInsertionPoint(long pos)
         m_text->SetInsertionPoint(pos);
 }
 
-void wxComboCtrlBase::SetInsertionPointEnd()
-{
-    if ( m_text )
-        m_text->SetInsertionPointEnd();
-}
-
 long wxComboCtrlBase::GetInsertionPoint() const
 {
     if ( m_text )
@@ -2677,6 +2652,14 @@ void wxComboCtrlBase::Replace(long from, long to, const wxString& value)
         m_text->Replace(from, to, value);
 }
 
+void wxComboCtrlBase::WriteText(const wxString& text)
+{
+    if ( m_text )
+        m_text->WriteText(text);
+    else
+        SetText(m_valueString + text);
+}
+
 void wxComboCtrlBase::Remove(long from, long to)
 {
     if ( m_text )
@@ -2689,12 +2672,60 @@ void wxComboCtrlBase::SetSelection(long from, long to)
         m_text->SetSelection(from, to);
 }
 
+void wxComboCtrlBase::GetSelection(long *from, long *to) const
+{
+    if ( m_text )
+    {
+        m_text->GetSelection(from, to);
+    }
+    else
+    {
+        *from = 0;
+        *to = 0;
+    }
+}
+
+bool wxComboCtrlBase::IsEditable() const
+{
+    if ( m_text )
+        return m_text->IsEditable();
+    return false;
+}
+
+void wxComboCtrlBase::SetEditable(bool editable)
+{
+    if ( m_text )
+        m_text->SetEditable(editable);
+}
+
 void wxComboCtrlBase::Undo()
 {
     if ( m_text )
         m_text->Undo();
 }
 
+void wxComboCtrlBase::Redo()
+{
+    if ( m_text )
+        m_text->Redo();
+}
+
+bool wxComboCtrlBase::CanUndo() const
+{
+    if ( m_text )
+        return m_text->CanUndo();
+
+    return false;
+}
+
+bool wxComboCtrlBase::CanRedo() const
+{
+    if ( m_text )
+        return m_text->CanRedo();
+
+    return false;
+}
+
 bool wxComboCtrlBase::SetHint(const wxString& hint)
 {
     m_hintText = hint;
index 795df492d61539104a94a4daa09b7d7821140e0d..43c87eb446842040c0011db68a5d8f401c06d9e2 100644 (file)
@@ -33,6 +33,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include "wx/combo.h"
+
 // ----------------------------------------------------------------------------
 // global helpers
 // ----------------------------------------------------------------------------
@@ -125,8 +127,16 @@ wxTextEntry *wxTextValidator::GetTextEntry()
     }
 #endif
 
+#if wxUSE_COMBOCTRL
+    if (m_validatorWindow->IsKindOf(CLASSINFO(wxComboCtrl)))
+    {
+        return (wxComboCtrl*)m_validatorWindow;
+    }
+#endif
+
     wxFAIL_MSG(
-        wxT("wxTextValidator can only be used with wxTextCtrl or wxComboBox")
+        "wxTextValidator can only be used with wxTextCtrl, wxComboBox, "
+        "or wxComboCtrl"
     );
 
     return NULL;
index ef4d47169edd647f1c461c6039bfa848504259ea..c70e9d405a4ea018c525f3b4252b9dc244bbdbc7 100644 (file)
@@ -191,12 +191,12 @@ bool wxGenericComboCtrl::Create(wxWindow *parent,
                                   pos,
                                   size,
                                   style | wxFULL_REPAINT_ON_RESIZE,
-                                  wxDefaultValidator,
+                                  validator,
                                   name) )
         return false;
 
     // Create textctrl, if necessary
-    CreateTextCtrl( tcBorder, validator );
+    CreateTextCtrl( tcBorder );
 
     // Add keyboard input handlers for main control and textctrl
     InstallInputHandlers();
@@ -408,19 +408,7 @@ void wxGenericComboCtrl::SetCustomPaintWidth( int width )
             tc->RemoveEventHandler(m_textEvtHandler);
             delete m_textEvtHandler;
 
-#if wxUSE_VALIDATORS
-            wxValidator* pValidator = tc->GetValidator();
-            if ( pValidator )
-            {
-                pValidator = (wxValidator*) pValidator->Clone();
-                CreateTextCtrl( tcCreateStyle, *pValidator );
-                delete pValidator;
-            }
-            else
-#endif
-            {
-                CreateTextCtrl( tcCreateStyle, wxDefaultValidator );
-            }
+            CreateTextCtrl( tcCreateStyle );
 
             InstallInputHandlers();
         }
index 109c74cbd344675235324d35c46037a5afc3a6cb..b85366b78c4a9aaaa69a88d8631a5e6fdbbfeace 100644 (file)
@@ -187,7 +187,7 @@ bool wxComboCtrl::Create(wxWindow *parent,
                            pos,
                            size,
                            style | wxFULL_REPAINT_ON_RESIZE,
-                           wxDefaultValidator,
+                           validator,
                            name) )
         return false;
 
@@ -203,7 +203,7 @@ bool wxComboCtrl::Create(wxWindow *parent,
         m_iFlags |= wxCC_POPUP_ON_MOUSE_UP;
 
     // Create textctrl, if necessary
-    CreateTextCtrl( wxNO_BORDER, validator );
+    CreateTextCtrl( wxNO_BORDER );
 
     // Add keyboard input handlers for main control and textctrl
     InstallInputHandlers();