diff --git a/include/wx/msw/textentry.h b/include/wx/msw/textentry.h index 434ca9c3b8..b21078b15a 100644 --- a/include/wx/msw/textentry.h +++ b/include/wx/msw/textentry.h @@ -81,6 +81,9 @@ protected: virtual bool DoAutoCompleteCustom(wxTextCompleter *completer) wxOVERRIDE; #endif // wxUSE_OLE + // Returns true if this control uses standard file names completion. + bool MSWUsesStandardAutoComplete() const; + // Helper for wxTE_PROCESS_ENTER handling: activates the default button in // the dialog containing this control if any. bool ClickDefaultButtonIfPossible(); @@ -100,6 +103,10 @@ private: // be called and the default implementation asserts if this is not the case. virtual void MSWProcessSpecialKey(wxKeyEvent& event); + // Check if we really have auto-complete data. This is not the same as just + // checking if m_autoCompleteData is NULL, see the code for more details. + bool MSWHasAutoCompleteData() const; + // Check that we have auto-complete data, creating it if necessary. Returns // false if creating it failed. bool MSWEnsureHasAutoCompleteData(); diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index 771d842d83..4b009bd325 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -659,6 +659,10 @@ private: wxDECLARE_NO_COPY_CLASS(wxTextAutoCompleteData); }; +// Special pointer value which indicates that we're using SHAutoComplete(). +static wxTextAutoCompleteData* const wxDUMMY_SHAUTOCOMPLETE_DATA = + reinterpret_cast(-1); + #endif // HAS_AUTOCOMPLETE // ============================================================================ @@ -679,7 +683,8 @@ wxTextEntry::wxTextEntry() wxTextEntry::~wxTextEntry() { #ifdef HAS_AUTOCOMPLETE - delete m_autoCompleteData; + if ( MSWHasAutoCompleteData() ) + delete m_autoCompleteData; #endif // HAS_AUTOCOMPLETE } @@ -833,8 +838,11 @@ bool wxTextEntry::DoAutoCompleteFileNames(int flags) // Disable the other kinds of completion now that we use the built-in file // names completion. - if ( m_autoCompleteData ) - m_autoCompleteData->DisableCompletion(); + if ( MSWHasAutoCompleteData() ) + delete m_autoCompleteData; + + // Set it to the special value indicating that we're using SHAutoComplete(). + m_autoCompleteData = wxDUMMY_SHAUTOCOMPLETE_DATA; return true; } @@ -846,9 +854,23 @@ void wxTextEntry::MSWProcessSpecialKey(wxKeyEvent& WXUNUSED(event)) wxFAIL_MSG(wxS("Must be overridden if can be called")); } +bool wxTextEntry::MSWUsesStandardAutoComplete() const +{ + return m_autoCompleteData == wxDUMMY_SHAUTOCOMPLETE_DATA; +} + +bool wxTextEntry::MSWHasAutoCompleteData() const +{ + // We use special wxDUMMY_SHAUTOCOMPLETE_DATA for the pointer to indicate + // that we're using SHAutoComplete(), so we need to check for it too, and + // not just whether the pointer is non-NULL. + return m_autoCompleteData != NULL + && m_autoCompleteData != wxDUMMY_SHAUTOCOMPLETE_DATA; +} + bool wxTextEntry::MSWEnsureHasAutoCompleteData() { - if ( !m_autoCompleteData ) + if ( !MSWHasAutoCompleteData() ) { wxTextAutoCompleteData * const ac = new wxTextAutoCompleteData(this); if ( !ac->IsOk() ) @@ -878,7 +900,7 @@ bool wxTextEntry::DoAutoCompleteCustom(wxTextCompleter *completer) // First deal with the case when we just want to disable auto-completion. if ( !completer ) { - if ( m_autoCompleteData ) + if ( MSWHasAutoCompleteData() ) m_autoCompleteData->DisableCompletion(); //else: Nothing to do, we hadn't used auto-completion even before. }