d3dx9: Implement ID3DXBaseEffect::GetAnnotation().
[wine/multimedia.git] / dlls / shell32 / autocomplete.c
blob8db542ac0ad901f2bcfc5b4fc6be0e4770310c52
1 /*
2 * AutoComplete interfaces implementation.
4 * Copyright 2004 Maxime Bellengé <maxime.bellenge@laposte.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 Implemented:
23 - ACO_AUTOAPPEND style
24 - ACO_AUTOSUGGEST style
25 - ACO_UPDOWNKEYDROPSLIST style
27 - Handle pwzsRegKeyPath and pwszQuickComplete in Init
29 TODO:
30 - implement ACO_SEARCH style
31 - implement ACO_FILTERPREFIXES style
32 - implement ACO_USETAB style
33 - implement ACO_RTLREADING style
34 - implement ResetEnumerator
35 - string compares should be case-insensitive, the content of the list should be sorted
38 #include "config.h"
40 #include <stdarg.h>
41 #include <stdlib.h>
42 #include <string.h>
44 #define COBJMACROS
46 #include "wine/debug.h"
47 #include "windef.h"
48 #include "winbase.h"
49 #include "winreg.h"
50 #include "undocshell.h"
51 #include "shlwapi.h"
52 #include "winerror.h"
53 #include "objbase.h"
55 #include "pidl.h"
56 #include "shlobj.h"
57 #include "shldisp.h"
58 #include "debughlp.h"
59 #include "shell32_main.h"
61 #include "wine/unicode.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(shell);
65 typedef struct
67 const IAutoComplete2Vtbl *lpVtbl;
68 const IAutoCompleteDropDownVtbl *lpDropDownVtbl;
69 LONG ref;
70 BOOL initialized;
71 BOOL enabled;
72 HWND hwndEdit;
73 HWND hwndListBox;
74 WNDPROC wpOrigEditProc;
75 WNDPROC wpOrigLBoxProc;
76 WCHAR *txtbackup;
77 WCHAR *quickComplete;
78 IEnumString *enumstr;
79 AUTOCOMPLETEOPTIONS options;
80 } IAutoCompleteImpl;
82 static const IAutoComplete2Vtbl acvt;
83 static const IAutoCompleteDropDownVtbl acdropdownvt;
85 static const WCHAR autocomplete_propertyW[] = {'W','i','n','e',' ','A','u','t','o',
86 'c','o','m','p','l','e','t','e',' ',
87 'c','o','n','t','r','o','l',0};
89 converts This to an interface pointer
91 #define _IUnknown_(This) ((IUnknown*)&(This)->lpVtbl)
92 #define _IAutoComplete2_(This) ((IAutoComplete2*)&(This)->lpVtbl)
93 #define _IAutoCompleteDropDown_(This) (&(This)->lpDropDownVtbl)
95 static inline IAutoCompleteImpl *impl_from_IAutoCompleteDropDown(IAutoCompleteDropDown *iface)
97 return (IAutoCompleteImpl *)((char *)iface - FIELD_OFFSET(IAutoCompleteImpl, lpDropDownVtbl));
100 static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
101 static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
103 static void create_listbox(IAutoCompleteImpl *This)
105 HWND hwndParent;
107 hwndParent = GetParent(This->hwndEdit);
109 /* FIXME : The listbox should be resizable with the mouse. WS_THICKFRAME looks ugly */
110 This->hwndListBox = CreateWindowExW(0, WC_LISTBOXW, NULL,
111 WS_BORDER | WS_CHILD | WS_VSCROLL | LBS_HASSTRINGS | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT,
112 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
113 hwndParent, NULL, shell32_hInstance, NULL );
115 if (This->hwndListBox) {
116 This->wpOrigLBoxProc = (WNDPROC) SetWindowLongPtrW( This->hwndListBox, GWLP_WNDPROC, (LONG_PTR) ACLBoxSubclassProc);
117 SetWindowLongPtrW( This->hwndListBox, GWLP_USERDATA, (LONG_PTR)This);
121 /**************************************************************************
122 * IAutoComplete_Constructor
124 HRESULT WINAPI IAutoComplete_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
126 IAutoCompleteImpl *lpac;
127 HRESULT hr;
129 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
130 return CLASS_E_NOAGGREGATION;
132 lpac = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAutoCompleteImpl));
133 if (!lpac)
134 return E_OUTOFMEMORY;
136 lpac->ref = 1;
137 lpac->lpVtbl = &acvt;
138 lpac->lpDropDownVtbl = &acdropdownvt;
139 lpac->enabled = TRUE;
140 lpac->options = ACO_AUTOAPPEND;
142 hr = IUnknown_QueryInterface(_IUnknown_ (lpac), riid, ppv);
143 IUnknown_Release(_IUnknown_ (lpac));
145 TRACE("-- (%p)->\n",lpac);
147 return hr;
150 /**************************************************************************
151 * AutoComplete_QueryInterface
153 static HRESULT WINAPI IAutoComplete2_fnQueryInterface(
154 IAutoComplete2 * iface,
155 REFIID riid,
156 LPVOID *ppvObj)
158 IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
160 TRACE("(%p)->(IID:%s,%p)\n", This, shdebugstr_guid(riid), ppvObj);
161 *ppvObj = NULL;
163 if (IsEqualIID(riid, &IID_IUnknown) ||
164 IsEqualIID(riid, &IID_IAutoComplete) ||
165 IsEqualIID(riid, &IID_IAutoComplete2))
167 *ppvObj = This;
169 else if (IsEqualIID(riid, &IID_IAutoCompleteDropDown))
171 *ppvObj = _IAutoCompleteDropDown_(This);
174 if (*ppvObj)
176 IUnknown_AddRef((IUnknown*)*ppvObj);
177 TRACE("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
178 return S_OK;
180 WARN("unsupported interface: %s\n", debugstr_guid(riid));
181 return E_NOINTERFACE;
184 /******************************************************************************
185 * IAutoComplete2_fnAddRef
187 static ULONG WINAPI IAutoComplete2_fnAddRef(
188 IAutoComplete2 * iface)
190 IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
191 ULONG refCount = InterlockedIncrement(&This->ref);
193 TRACE("(%p)->(%u)\n", This, refCount - 1);
195 return refCount;
198 /******************************************************************************
199 * IAutoComplete2_fnRelease
201 static ULONG WINAPI IAutoComplete2_fnRelease(
202 IAutoComplete2 * iface)
204 IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
205 ULONG refCount = InterlockedDecrement(&This->ref);
207 TRACE("(%p)->(%u)\n", This, refCount + 1);
209 if (!refCount) {
210 TRACE("destroying IAutoComplete(%p)\n", This);
211 HeapFree(GetProcessHeap(), 0, This->quickComplete);
212 HeapFree(GetProcessHeap(), 0, This->txtbackup);
213 if (This->enumstr)
214 IEnumString_Release(This->enumstr);
215 HeapFree(GetProcessHeap(), 0, This);
217 return refCount;
220 /******************************************************************************
221 * IAutoComplete2_fnEnable
223 static HRESULT WINAPI IAutoComplete2_fnEnable(
224 IAutoComplete2 * iface,
225 BOOL fEnable)
227 IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
229 HRESULT hr = S_OK;
231 TRACE("(%p)->(%s)\n", This, (fEnable)?"true":"false");
233 This->enabled = fEnable;
235 return hr;
238 /******************************************************************************
239 * IAutoComplete2_fnInit
241 static HRESULT WINAPI IAutoComplete2_fnInit(
242 IAutoComplete2 * iface,
243 HWND hwndEdit,
244 IUnknown *punkACL,
245 LPCOLESTR pwzsRegKeyPath,
246 LPCOLESTR pwszQuickComplete)
248 IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
250 TRACE("(%p)->(%p, %p, %s, %s)\n",
251 This, hwndEdit, punkACL, debugstr_w(pwzsRegKeyPath), debugstr_w(pwszQuickComplete));
253 if (This->options & ACO_SEARCH) FIXME(" ACO_SEARCH not supported\n");
254 if (This->options & ACO_FILTERPREFIXES) FIXME(" ACO_FILTERPREFIXES not supported\n");
255 if (This->options & ACO_USETAB) FIXME(" ACO_USETAB not supported\n");
256 if (This->options & ACO_RTLREADING) FIXME(" ACO_RTLREADING not supported\n");
258 if (!hwndEdit || !punkACL)
259 return E_INVALIDARG;
261 if (This->initialized)
263 WARN("Autocompletion object is already initialized\n");
264 /* This->hwndEdit is set to NULL when the edit window is destroyed. */
265 return This->hwndEdit ? E_FAIL : E_UNEXPECTED;
268 if (FAILED (IUnknown_QueryInterface (punkACL, &IID_IEnumString, (LPVOID*)&This->enumstr))) {
269 WARN("No IEnumString interface\n");
270 return E_NOINTERFACE;
273 This->initialized = TRUE;
274 This->hwndEdit = hwndEdit;
275 This->wpOrigEditProc = (WNDPROC) SetWindowLongPtrW( hwndEdit, GWLP_WNDPROC, (LONG_PTR) ACEditSubclassProc);
276 /* Keep at least one reference to the object until the edit window is destroyed. */
277 IAutoComplete2_AddRef((IAutoComplete2 *)This);
278 SetPropW( hwndEdit, autocomplete_propertyW, This );
280 if (This->options & ACO_AUTOSUGGEST)
281 create_listbox(This);
283 if (pwzsRegKeyPath) {
284 WCHAR *key;
285 WCHAR result[MAX_PATH];
286 WCHAR *value;
287 HKEY hKey = 0;
288 LONG res;
289 LONG len;
291 /* pwszRegKeyPath contains the key as well as the value, so we split */
292 key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwzsRegKeyPath)+1)*sizeof(WCHAR));
293 strcpyW(key, pwzsRegKeyPath);
294 value = strrchrW(key, '\\');
295 *value = 0;
296 value++;
297 /* Now value contains the value and buffer the key */
298 res = RegOpenKeyExW(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey);
299 if (res != ERROR_SUCCESS) {
300 /* if the key is not found, MSDN states we must seek in HKEY_LOCAL_MACHINE */
301 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hKey);
303 if (res == ERROR_SUCCESS) {
304 res = RegQueryValueW(hKey, value, result, &len);
305 if (res == ERROR_SUCCESS) {
306 This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR));
307 strcpyW(This->quickComplete, result);
309 RegCloseKey(hKey);
311 HeapFree(GetProcessHeap(), 0, key);
314 if ((pwszQuickComplete) && (!This->quickComplete)) {
315 This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwszQuickComplete)+1)*sizeof(WCHAR));
316 lstrcpyW(This->quickComplete, pwszQuickComplete);
319 return S_OK;
322 /**************************************************************************
323 * IAutoComplete2_fnGetOptions
325 static HRESULT WINAPI IAutoComplete2_fnGetOptions(
326 IAutoComplete2 * iface,
327 DWORD *pdwFlag)
329 HRESULT hr = S_OK;
331 IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
333 TRACE("(%p) -> (%p)\n", This, pdwFlag);
335 *pdwFlag = This->options;
337 return hr;
340 /**************************************************************************
341 * IAutoComplete2_fnSetOptions
343 static HRESULT WINAPI IAutoComplete2_fnSetOptions(
344 IAutoComplete2 * iface,
345 DWORD dwFlag)
347 HRESULT hr = S_OK;
349 IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
351 TRACE("(%p) -> (0x%x)\n", This, dwFlag);
353 This->options = dwFlag;
355 if ((This->options & ACO_AUTOSUGGEST) && This->hwndEdit && !This->hwndListBox)
356 create_listbox(This);
358 return hr;
361 /**************************************************************************
362 * IAutoCompleteDropDown_fnGetDropDownStatus
364 static HRESULT WINAPI IAutoCompleteDropDown_fnGetDropDownStatus(
365 IAutoCompleteDropDown *iface,
366 DWORD *pdwFlags,
367 LPWSTR *ppwszString)
369 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
370 BOOL dropped;
372 TRACE("(%p) -> (%p, %p)\n", This, pdwFlags, ppwszString);
374 dropped = IsWindowVisible(This->hwndListBox);
376 if (pdwFlags)
377 *pdwFlags = (dropped ? ACDD_VISIBLE : 0);
379 if (ppwszString) {
380 if (dropped) {
381 int sel;
383 sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
384 if (sel >= 0)
386 DWORD len;
388 len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
389 *ppwszString = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
390 SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)*ppwszString);
392 else
393 *ppwszString = NULL;
395 else
396 *ppwszString = NULL;
399 return S_OK;
402 /**************************************************************************
403 * IAutoCompleteDropDown_fnResetEnumarator
405 static HRESULT WINAPI IAutoCompleteDropDown_fnResetEnumerator(
406 IAutoCompleteDropDown *iface)
408 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
410 FIXME("(%p): stub\n", This);
412 return E_NOTIMPL;
417 /**************************************************************************
418 * IAutoComplete2 VTable
420 static const IAutoComplete2Vtbl acvt =
422 IAutoComplete2_fnQueryInterface,
423 IAutoComplete2_fnAddRef,
424 IAutoComplete2_fnRelease,
425 IAutoComplete2_fnInit,
426 IAutoComplete2_fnEnable,
427 /* IAutoComplete2 */
428 IAutoComplete2_fnSetOptions,
429 IAutoComplete2_fnGetOptions,
433 static HRESULT WINAPI IAutoCompleteDropDown_fnQueryInterface(IAutoCompleteDropDown *iface,
434 REFIID riid, LPVOID *ppvObj)
436 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
437 return IAutoComplete2_fnQueryInterface(_IAutoComplete2_(This), riid, ppvObj);
440 static ULONG WINAPI IAutoCompleteDropDown_fnAddRef(IAutoCompleteDropDown *iface)
442 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
443 return IAutoComplete2_fnAddRef(_IAutoComplete2_(This));
446 static ULONG WINAPI IAutoCompleteDropDown_fnRelease(IAutoCompleteDropDown *iface)
448 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
449 return IAutoComplete2_fnRelease(_IAutoComplete2_(This));
452 /**************************************************************************
453 * IAutoCompleteDropDown VTable
455 static const IAutoCompleteDropDownVtbl acdropdownvt =
457 IAutoCompleteDropDown_fnQueryInterface,
458 IAutoCompleteDropDown_fnAddRef,
459 IAutoCompleteDropDown_fnRelease,
460 IAutoCompleteDropDown_fnGetDropDownStatus,
461 IAutoCompleteDropDown_fnResetEnumerator,
465 Window procedure for autocompletion
467 static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
469 IAutoCompleteImpl *This = GetPropW(hwnd, autocomplete_propertyW);
470 LPOLESTR strs;
471 HRESULT hr;
472 WCHAR hwndText[255];
473 WCHAR *hwndQCText;
474 RECT r;
475 BOOL control, filled, displayall = FALSE;
476 int cpt, height, sel;
478 if (!This->enabled) return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
480 switch (uMsg)
482 case CB_SHOWDROPDOWN:
483 ShowWindow(This->hwndListBox, SW_HIDE);
484 break;
485 case WM_KILLFOCUS:
486 if ((This->options & ACO_AUTOSUGGEST) &&
487 ((HWND)wParam != This->hwndListBox))
489 ShowWindow(This->hwndListBox, SW_HIDE);
491 return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
492 case WM_KEYUP:
493 GetWindowTextW( hwnd, hwndText, 255);
495 switch(wParam) {
496 case VK_RETURN:
497 /* If quickComplete is set and control is pressed, replace the string */
498 control = GetKeyState(VK_CONTROL) & 0x8000;
499 if (control && This->quickComplete) {
500 hwndQCText = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
501 (lstrlenW(This->quickComplete)+lstrlenW(hwndText))*sizeof(WCHAR));
502 sel = sprintfW(hwndQCText, This->quickComplete, hwndText);
503 SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)hwndQCText);
504 SendMessageW(hwnd, EM_SETSEL, 0, sel);
505 HeapFree(GetProcessHeap(), 0, hwndQCText);
508 ShowWindow(This->hwndListBox, SW_HIDE);
509 return 0;
510 case VK_LEFT:
511 case VK_RIGHT:
512 return 0;
513 case VK_UP:
514 case VK_DOWN:
515 /* Two cases here :
516 - if the listbox is not visible, displays it
517 with all the entries if the style ACO_UPDOWNKEYDROPSLIST
518 is present but does not select anything.
519 - if the listbox is visible, change the selection
521 if ( (This->options & (ACO_AUTOSUGGEST | ACO_UPDOWNKEYDROPSLIST))
522 && (!IsWindowVisible(This->hwndListBox) && (! *hwndText)) )
524 /* We must display all the entries */
525 displayall = TRUE;
526 } else {
527 if (IsWindowVisible(This->hwndListBox)) {
528 int count;
530 count = SendMessageW(This->hwndListBox, LB_GETCOUNT, 0, 0);
531 /* Change the selection */
532 sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
533 if (wParam == VK_UP)
534 sel = ((sel-1)<0)?count-1:sel-1;
535 else
536 sel = ((sel+1)>= count)?-1:sel+1;
537 SendMessageW(This->hwndListBox, LB_SETCURSEL, sel, 0);
538 if (sel != -1) {
539 WCHAR *msg;
540 int len;
542 len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
543 msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
544 SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
545 SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)msg);
546 SendMessageW(hwnd, EM_SETSEL, lstrlenW(msg), lstrlenW(msg));
547 HeapFree(GetProcessHeap(), 0, msg);
548 } else {
549 SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)This->txtbackup);
550 SendMessageW(hwnd, EM_SETSEL, lstrlenW(This->txtbackup), lstrlenW(This->txtbackup));
553 return 0;
555 break;
556 case VK_BACK:
557 case VK_DELETE:
558 if ((! *hwndText) && (This->options & ACO_AUTOSUGGEST)) {
559 ShowWindow(This->hwndListBox, SW_HIDE);
560 return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
562 if (This->options & ACO_AUTOAPPEND) {
563 DWORD b;
564 SendMessageW(hwnd, EM_GETSEL, (WPARAM)&b, 0);
565 if (b>1) {
566 hwndText[b-1] = '\0';
567 } else {
568 hwndText[0] = '\0';
569 SetWindowTextW(hwnd, hwndText);
572 break;
573 default:
577 SendMessageW(This->hwndListBox, LB_RESETCONTENT, 0, 0);
579 HeapFree(GetProcessHeap(), 0, This->txtbackup);
580 This->txtbackup = HeapAlloc(GetProcessHeap(),
581 HEAP_ZERO_MEMORY, (lstrlenW(hwndText)+1)*sizeof(WCHAR));
582 lstrcpyW(This->txtbackup, hwndText);
584 /* Returns if there is no text to search and we doesn't want to display all the entries */
585 if ((!displayall) && (! *hwndText) )
586 break;
588 IEnumString_Reset(This->enumstr);
589 filled = FALSE;
590 for(cpt = 0;;) {
591 ULONG fetched;
592 hr = IEnumString_Next(This->enumstr, 1, &strs, &fetched);
593 if (hr != S_OK)
594 break;
596 if (strstrW(strs, hwndText) == strs) {
597 if (!filled && (This->options & ACO_AUTOAPPEND)) {
598 SetWindowTextW(hwnd, strs);
599 SendMessageW(hwnd, EM_SETSEL, lstrlenW(hwndText), lstrlenW(strs));
600 if (!(This->options & ACO_AUTOSUGGEST))
601 break;
604 if (This->options & ACO_AUTOSUGGEST) {
605 SendMessageW(This->hwndListBox, LB_ADDSTRING, 0, (LPARAM)strs);
606 cpt++;
609 filled = TRUE;
613 if (This->options & ACO_AUTOSUGGEST) {
614 if (filled) {
615 height = SendMessageW(This->hwndListBox, LB_GETITEMHEIGHT, 0, 0);
616 SendMessageW(This->hwndListBox, LB_CARETOFF, 0, 0);
617 GetWindowRect(hwnd, &r);
618 SetParent(This->hwndListBox, HWND_DESKTOP);
619 /* It seems that Windows XP displays 7 lines at most
620 and otherwise displays a vertical scroll bar */
621 SetWindowPos(This->hwndListBox, HWND_TOP,
622 r.left, r.bottom + 1, r.right - r.left, min(height * 7, height*(cpt+1)),
623 SWP_SHOWWINDOW );
624 } else {
625 ShowWindow(This->hwndListBox, SW_HIDE);
629 break;
630 case WM_DESTROY:
632 WNDPROC proc = This->wpOrigEditProc;
634 RemovePropW(hwnd, autocomplete_propertyW);
635 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)proc);
636 This->hwndEdit = NULL;
637 if (This->hwndListBox)
638 DestroyWindow(This->hwndListBox);
639 IAutoComplete2_Release((IAutoComplete2 *)This);
640 return CallWindowProcW(proc, hwnd, uMsg, wParam, lParam);
642 default:
643 return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
647 return 0;
650 static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
652 IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
653 WCHAR *msg;
654 int sel, len;
656 switch (uMsg) {
657 case WM_MOUSEMOVE:
658 sel = SendMessageW(hwnd, LB_ITEMFROMPOINT, 0, lParam);
659 SendMessageW(hwnd, LB_SETCURSEL, sel, 0);
660 break;
661 case WM_LBUTTONDOWN:
662 sel = SendMessageW(hwnd, LB_GETCURSEL, 0, 0);
663 if (sel < 0)
664 break;
665 len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
666 msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
667 SendMessageW(hwnd, LB_GETTEXT, sel, (LPARAM)msg);
668 SendMessageW(This->hwndEdit, WM_SETTEXT, 0, (LPARAM)msg);
669 SendMessageW(This->hwndEdit, EM_SETSEL, 0, lstrlenW(msg));
670 ShowWindow(hwnd, SW_HIDE);
671 HeapFree(GetProcessHeap(), 0, msg);
672 break;
673 default:
674 return CallWindowProcW(This->wpOrigLBoxProc, hwnd, uMsg, wParam, lParam);
676 return 0;