Don't call IAutoComplete::Init() twice for the same control as this leaks memory, just change the strings used for completion instead (closes #10968)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61493 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
a7f2b179fb
commit
68e6eb7d67
@ -18,7 +18,12 @@
|
|||||||
class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
|
class WXDLLIMPEXP_CORE wxTextEntry : public wxTextEntryBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxTextEntry() { }
|
wxTextEntry()
|
||||||
|
{
|
||||||
|
#if wxUSE_OLE
|
||||||
|
m_enumStrings = NULL;
|
||||||
|
#endif // wxUSE_OLE
|
||||||
|
}
|
||||||
|
|
||||||
// implement wxTextEntryBase pure virtual methods
|
// implement wxTextEntryBase pure virtual methods
|
||||||
virtual void WriteText(const wxString& text);
|
virtual void WriteText(const wxString& text);
|
||||||
@ -74,6 +79,11 @@ protected:
|
|||||||
private:
|
private:
|
||||||
// implement this to return the HWND of the EDIT control
|
// implement this to return the HWND of the EDIT control
|
||||||
virtual WXHWND GetEditHWND() const = 0;
|
virtual WXHWND GetEditHWND() const = 0;
|
||||||
|
|
||||||
|
#if wxUSE_OLE
|
||||||
|
// enumerator for strings currently used for auto-completion or NULL
|
||||||
|
class wxIEnumString *m_enumStrings;
|
||||||
|
#endif // wxUSE_OLE
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WX_MSW_TEXTENTRY_H_
|
#endif // _WX_MSW_TEXTENTRY_H_
|
||||||
|
@ -79,6 +79,12 @@ public:
|
|||||||
m_index = 0;
|
m_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChangeStrings(const wxArrayString& strings)
|
||||||
|
{
|
||||||
|
m_strings = strings;
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
DECLARE_IUNKNOWN_METHODS;
|
DECLARE_IUNKNOWN_METHODS;
|
||||||
|
|
||||||
virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt,
|
virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt,
|
||||||
@ -156,7 +162,7 @@ private:
|
|||||||
virtual ~wxIEnumString() { }
|
virtual ~wxIEnumString() { }
|
||||||
|
|
||||||
|
|
||||||
const wxArrayString m_strings;
|
wxArrayString m_strings;
|
||||||
unsigned m_index;
|
unsigned m_index;
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(wxIEnumString);
|
wxDECLARE_NO_COPY_CLASS(wxIEnumString);
|
||||||
@ -334,6 +340,14 @@ bool wxTextEntry::AutoCompleteFileNames()
|
|||||||
bool wxTextEntry::AutoComplete(const wxArrayString& choices)
|
bool wxTextEntry::AutoComplete(const wxArrayString& choices)
|
||||||
{
|
{
|
||||||
#ifdef HAS_AUTOCOMPLETE
|
#ifdef HAS_AUTOCOMPLETE
|
||||||
|
// if we had an old enumerator we must reuse it as IAutoComplete doesn't
|
||||||
|
// free it if we call Init() again (see #10968) -- and it's also simpler
|
||||||
|
if ( m_enumStrings )
|
||||||
|
{
|
||||||
|
m_enumStrings->ChangeStrings(choices);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// create an object exposing IAutoComplete interface (don't go for
|
// create an object exposing IAutoComplete interface (don't go for
|
||||||
// IAutoComplete2 immediately as, presumably, it might be not available on
|
// IAutoComplete2 immediately as, presumably, it might be not available on
|
||||||
// older systems as otherwise why do we have both -- although in practice I
|
// older systems as otherwise why do we have both -- although in practice I
|
||||||
@ -354,10 +368,10 @@ bool wxTextEntry::AutoComplete(const wxArrayString& choices)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// associate it with our strings
|
// associate it with our strings
|
||||||
wxIEnumString *pEnumString = new wxIEnumString(choices);
|
m_enumStrings = new wxIEnumString(choices);
|
||||||
pEnumString->AddRef();
|
m_enumStrings->AddRef();
|
||||||
hr = pAutoComplete->Init(GetEditHwnd(), pEnumString, NULL, NULL);
|
hr = pAutoComplete->Init(GetEditHwnd(), m_enumStrings, NULL, NULL);
|
||||||
pEnumString->Release();
|
m_enumStrings->Release();
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
{
|
{
|
||||||
wxLogApiError(_T("IAutoComplete::Init"), hr);
|
wxLogApiError(_T("IAutoComplete::Init"), hr);
|
||||||
|
Loading…
Reference in New Issue
Block a user