|
1
|
1 #include "stdafx.h"
|
|
|
2 #include "AutoComplete.h"
|
|
|
3 #include "pp-COM-macros.h"
|
|
|
4
|
|
|
5 #include <ShlGuid.h> // CLSID_AutoComplete
|
|
|
6
|
|
|
7 #include "CEnumString.h"
|
|
|
8 using PP::CEnumString;
|
|
|
9
|
|
|
10 HRESULT InitializeSimpleAC(HWND edit, IUnknown * vals, DWORD opts) {
|
|
|
11 pfc::com_ptr_t<IAutoComplete> ac;
|
|
|
12 HRESULT hr;
|
|
|
13 hr = CoCreateInstance(CLSID_AutoComplete, NULL, CLSCTX_ALL, IID_IAutoComplete, (void**)ac.receive_ptr());
|
|
|
14 if (FAILED(hr)) {
|
|
|
15 PFC_ASSERT(!"Should not get here - CoCreateInstance/IAutoComplete fail!"); return hr;
|
|
|
16 }
|
|
|
17 hr = ac->Init(edit, vals, NULL, NULL);
|
|
|
18 if (FAILED(hr)) {
|
|
|
19 PFC_ASSERT(!"Should not get here - ac->Init fail!"); return hr;
|
|
|
20 }
|
|
|
21
|
|
|
22 pfc::com_ptr_t<IAutoComplete2> ac2;
|
|
|
23 hr = ac->QueryInterface(ac2.receive_ptr());
|
|
|
24 if (FAILED(hr)) {
|
|
|
25 PFC_ASSERT(!"Should not get here - ac->QueryInterface fail!"); return hr;
|
|
|
26 }
|
|
|
27 hr = ac2->SetOptions(opts);
|
|
|
28 if (FAILED(hr)) {
|
|
|
29 PFC_ASSERT(!"Should not get here - ac2->SetOptions fail!"); return hr;
|
|
|
30 }
|
|
|
31 return S_OK;
|
|
|
32 }
|
|
|
33
|
|
|
34 pfc::com_ptr_t<IUnknown> CreateACList(pfc::const_iterator<pfc::string8> valueEnum) {
|
|
|
35 pfc::com_ptr_t<CEnumString> acl = new CEnumString::TImpl();
|
|
|
36 while (valueEnum.is_valid()) {
|
|
|
37 acl->AddStringU(*valueEnum); ++valueEnum;
|
|
|
38 }
|
|
|
39 return acl;
|
|
|
40 }
|
|
|
41 pfc::com_ptr_t<IUnknown> CreateACList(pfc::const_iterator<const char *> valueEnum) {
|
|
|
42 pfc::com_ptr_t<CEnumString> acl = new CEnumString::TImpl();
|
|
|
43 while (valueEnum.is_valid()) {
|
|
|
44 acl->AddStringU(*valueEnum); ++valueEnum;
|
|
|
45 }
|
|
|
46 return acl;
|
|
|
47 }
|
|
|
48
|
|
|
49 pfc::com_ptr_t<IUnknown> CreateACList() {
|
|
|
50 return new CEnumString::TImpl();
|
|
|
51 }
|
|
|
52
|
|
|
53 void CreateACList_AddItem(IUnknown * theList, const char * item) {
|
|
|
54 static_cast<CEnumString*>(theList)->AddStringU(item);
|
|
|
55 }
|
|
|
56
|
|
|
57 HRESULT InitializeEditAC(HWND edit, pfc::const_iterator<pfc::string8> valueEnum, DWORD opts) {
|
|
|
58 pfc::com_ptr_t<IUnknown> acl = CreateACList(valueEnum);
|
|
|
59 return InitializeSimpleAC(edit, acl.get_ptr(), opts);
|
|
|
60 }
|
|
|
61 HRESULT InitializeEditAC(HWND edit, const char * values, DWORD opts) {
|
|
|
62 pfc::com_ptr_t<CEnumString> acl = new CEnumString::TImpl();
|
|
|
63 for (const char * walk = values;;) {
|
|
|
64 const char * next = strchr(walk, '\n');
|
|
|
65 if (next == NULL) { acl->AddStringU(walk, SIZE_MAX); break; }
|
|
|
66 acl->AddStringU(walk, next - walk);
|
|
|
67 walk = next + 1;
|
|
|
68 }
|
|
|
69 return InitializeSimpleAC(edit, acl.get_ptr(), opts);
|
|
|
70 }
|