+// ----------------------------------------------------------------------------
+// wxIEnumString implements IEnumString interface
+// ----------------------------------------------------------------------------
+
+#if wxUSE_OLE
+
+#include "wx/msw/ole/oleutils.h"
+#include <shldisp.h>
+
+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++ = wx_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:
+ const wxArrayString m_strings;
+ unsigned m_index;
+
+ DECLARE_NO_COPY_CLASS(wxIEnumString)
+};
+
+BEGIN_IID_TABLE(wxIEnumString)
+ ADD_IID(Unknown)
+ ADD_IID(EnumString)
+END_IID_TABLE;
+
+IMPLEMENT_IUNKNOWN_METHODS(wxIEnumString)
+
+#endif // wxUSE_OLE
+