X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a7aeddacf9dfcb9dca64fccb5f65f387bcff0fb2..a4ea083bbdf710d3234dcbd2eafb5d0e078f8348:/src/common/textentrycmn.cpp?ds=sidebyside diff --git a/src/common/textentrycmn.cpp b/src/common/textentrycmn.cpp index 672eeb2807..b1480e322e 100644 --- a/src/common/textentrycmn.cpp +++ b/src/common/textentrycmn.cpp @@ -3,7 +3,6 @@ // Purpose: wxTextEntryBase implementation // Author: Vadim Zeitlin // Created: 2007-09-26 -// RCS-ID: $Id$ // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org> // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -31,6 +30,7 @@ #endif //WX_PRECOMP #include "wx/textentry.h" +#include "wx/textcompleter.h" #include "wx/clipbrd.h" // ---------------------------------------------------------------------------- @@ -49,7 +49,7 @@ public: wxTextEntryHintData::OnSetFocus, this); wxBIND_OR_CONNECT_HACK(win, wxEVT_KILL_FOCUS, wxFocusEventHandler, wxTextEntryHintData::OnKillFocus, this); - wxBIND_OR_CONNECT_HACK(win, wxEVT_COMMAND_TEXT_UPDATED, + wxBIND_OR_CONNECT_HACK(win, wxEVT_TEXT, wxCommandEventHandler, wxTextEntryHintData::OnTextChanged, this); } @@ -75,6 +75,20 @@ public: const wxString& GetHintString() const { return m_hint; } + // This is called whenever the text control contents changes. + // + // We call it ourselves when this change generates an event but it's also + // necessary to call it explicitly from wxTextEntry::ChangeValue() as it, + // by design, does not generate any events. + void HandleTextUpdate(const wxString& text) + { + m_text = text; + + // If we're called because of a call to Set or ChangeValue(), the + // control may still have the hint text colour, reset it in this case. + RestoreTextColourIfNecessary(); + } + private: // Show the hint in the window if we should do it, i.e. if the window // doesn't have any text of its own. @@ -133,11 +147,7 @@ private: // which uses it internally because this would just forward back to us // so go directly to the private method which returns the real control // contents. - m_text = m_entry->DoGetValue(); - - // If this event is generated because of calling SetValue(), the - // control may still have the hint text colour, reset it in this case. - RestoreTextColourIfNecessary(); + HandleTextUpdate(m_entry->DoGetValue()); event.Skip(); } @@ -195,6 +205,16 @@ wxString wxTextEntryBase::GetRange(long from, long to) const // text operations // ---------------------------------------------------------------------------- +void wxTextEntryBase::ChangeValue(const wxString& value) +{ + DoSetValue(value, SetValue_NoEvent); + + // As we didn't generate any events for wxTextEntryHintData to catch, + // notify it explicitly about our changed contents. + if ( m_hintData ) + m_hintData->HandleTextUpdate(value); +} + void wxTextEntryBase::AppendText(const wxString& text) { SetInsertionPointEnd(); @@ -203,12 +223,22 @@ void wxTextEntryBase::AppendText(const wxString& text) void wxTextEntryBase::DoSetValue(const wxString& value, int flags) { - EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent)); + if ( value != DoGetValue() ) + { + EventsSuppressor noeventsIf(this, !(flags & SetValue_SendEvent)); - SelectAll(); - WriteText(value); + SelectAll(); + WriteText(value); - SetInsertionPoint(0); + SetInsertionPoint(0); + } + else // Same value, no need to do anything. + { + // Except that we still need to generate the event for consistency with + // the normal case when the text does change. + if ( flags & SetValue_SendEvent ) + SendTextUpdatedEvent(GetEditableWindow()); + } } void wxTextEntryBase::Replace(long from, long to, const wxString& value) @@ -336,7 +366,7 @@ bool wxTextEntryBase::SendTextUpdatedEvent(wxWindow *win) { wxCHECK_MSG( win, false, "can't send an event without a window" ); - wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, win->GetId()); + wxCommandEvent event(wxEVT_TEXT, win->GetId()); // do not do this as it could be very inefficient if the text control // contains a lot of text and we're not using ref-counted wxString @@ -348,4 +378,39 @@ bool wxTextEntryBase::SendTextUpdatedEvent(wxWindow *win) return win->HandleWindowEvent(event); } +// ---------------------------------------------------------------------------- +// auto-completion stubs +// ---------------------------------------------------------------------------- + +wxTextCompleter::~wxTextCompleter() +{ +} + +bool wxTextCompleterSimple::Start(const wxString& prefix) +{ + m_index = 0; + m_completions.clear(); + GetCompletions(prefix, m_completions); + + return !m_completions.empty(); +} + +wxString wxTextCompleterSimple::GetNext() +{ + if ( m_index == m_completions.size() ) + return wxString(); + + return m_completions[m_index++]; +} + +bool wxTextEntryBase::DoAutoCompleteCustom(wxTextCompleter *completer) +{ + // We don't do anything here but we still need to delete the completer for + // consistency with the ports that do implement this method and take + // ownership of the pointer. + delete completer; + + return false; +} + #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX