+// ----------------------------------------------------------------------------
+// wxIEnumString implements IEnumString interface
+// ----------------------------------------------------------------------------
+
+// standard VC6 SDK (WINVER == 0x0400) does not know about IAutoComplete
+#if wxUSE_OLE && (WINVER >= 0x0500)
+ #define HAS_AUTOCOMPLETE
+#endif
+
+#ifdef HAS_AUTOCOMPLETE
+
+#include "wx/msw/ole/oleutils.h"
+#include <shldisp.h>
+
+#if defined(__MINGW32__) || defined (__WATCOMC__)
+ // needed for IID_IAutoComplete, IID_IAutoComplete2 and ACO_AUTOSUGGEST
+ #include <shlguid.h>
+#endif
+
+#ifndef ACO_UPDOWNKEYDROPSLIST
+ #define ACO_UPDOWNKEYDROPSLIST 0x20
+#endif
+
+#ifndef SHACF_FILESYS_ONLY
+ #define SHACF_FILESYS_ONLY 0x00000010
+#endif
+
+DEFINE_GUID(CLSID_AutoComplete,
+ 0x00bb2763, 0x6a77, 0x11d0, 0xa5, 0x35, 0x00, 0xc0, 0x4f, 0xd7, 0xd0, 0x62);
+
+class wxIEnumString : public IEnumString
+{
+public:
+ wxIEnumString(const wxArrayString& strings) : m_strings(strings)
+ {
+ m_index = 0;
+ }
+
+ DECLARE_IUNKNOWN_METHODS;
+
+ virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt,
+ LPOLESTR *rgelt,
+ ULONG *pceltFetched)
+ {
+ if ( !rgelt || (!pceltFetched && celt > 1) )
+ return E_POINTER;
+
+ ULONG pceltFetchedDummy;
+ if ( !pceltFetched )
+ pceltFetched = &pceltFetchedDummy;
+
+ *pceltFetched = 0;
+
+ for ( const unsigned count = m_strings.size(); celt--; ++m_index )
+ {
+ if ( m_index == count )
+ return S_FALSE;
+
+ const wxWX2WCbuf wcbuf = m_strings[m_index].wc_str();
+ const size_t size = (wcslen(wcbuf) + 1)*sizeof(wchar_t);
+ void *olestr = CoTaskMemAlloc(size);
+ if ( !olestr )
+ return E_OUTOFMEMORY;
+
+ memcpy(olestr, wcbuf, size);
+
+ *rgelt++ = static_cast<LPOLESTR>(olestr);
+
+ ++(*pceltFetched);
+ }
+
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt)
+ {
+ m_index += celt;
+ if ( m_index > m_strings.size() )
+ {
+ m_index = m_strings.size();
+ return S_FALSE;
+ }
+
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Reset()
+ {
+ m_index = 0;
+
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Clone(IEnumString **ppEnum)
+ {
+ if ( !ppEnum )
+ return E_POINTER;
+
+ wxIEnumString *e = new wxIEnumString(m_strings);
+ e->m_index = m_index;
+
+ e->AddRef();
+ *ppEnum = e;
+
+ return S_OK;
+ }
+
+private:
+ // dtor doesn't have to be virtual as we're only ever deleted from our own
+ // Release() and are not meant to be derived form anyhow, but making it
+ // virtual silences gcc warnings; making it private makes it impossible to
+ // (mistakenly) delete us directly instead of calling Release()
+ virtual ~wxIEnumString() { }
+
+
+ const wxArrayString m_strings;
+ unsigned m_index;
+
+ wxDECLARE_NO_COPY_CLASS(wxIEnumString);
+};
+
+BEGIN_IID_TABLE(wxIEnumString)
+ ADD_IID(Unknown)
+ ADD_IID(EnumString)
+END_IID_TABLE;
+
+IMPLEMENT_IUNKNOWN_METHODS(wxIEnumString)
+
+#endif // HAS_AUTOCOMPLETE
+