#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;
};
-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,
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).
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 );
// 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();
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;
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();
protected:
+ // Dummy method - we override all functions that call this
+ virtual WXHWND GetEditHWND() const { return NULL; }
+
// customization
virtual void OnResize();
virtual wxCoord GetNativeTextIndent() const;
@see wxComboBox, wxChoice, wxOwnerDrawnComboBox, wxComboPopup,
wxCommandEvent
*/
-class wxComboCtrl : public wxControl
+class wxComboCtrl : public wxControl,
+ public wxTextEntry
{
public:
/**
}
void
-wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator)
+wxComboCtrlBase::CreateTextCtrl(int style)
{
if ( !(m_windowStyle & wxCB_READONLY) )
{
m_text = new wxComboCtrlTextCtrl();
m_text->Create(this, wxID_ANY, m_valueString,
wxDefaultPosition, wxSize(10,-1),
- style, validator);
+ style);
m_text->SetHint(m_hintText);
}
}
}
#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) )
}
// ----------------------------------------------------------------------------
-// methods forwarded to wxTextCtrl
+// wxTextEntry interface
// ----------------------------------------------------------------------------
-wxString wxComboCtrlBase::GetValue() const
+wxString wxComboCtrlBase::DoGetValue() const
{
if ( m_text )
return m_text->GetValue();
m_text->SetInsertionPoint(pos);
}
-void wxComboCtrlBase::SetInsertionPointEnd()
-{
- if ( m_text )
- m_text->SetInsertionPointEnd();
-}
-
long wxComboCtrlBase::GetInsertionPoint() const
{
if ( m_text )
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 )
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;
#include <string.h>
#include <stdlib.h>
+#include "wx/combo.h"
+
// ----------------------------------------------------------------------------
// global helpers
// ----------------------------------------------------------------------------
}
#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;
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();
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();
}
pos,
size,
style | wxFULL_REPAINT_ON_RESIZE,
- wxDefaultValidator,
+ validator,
name) )
return false;
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();