shell32: Pass an object instead of an iface to a helper function.
[wine/multimedia.git] / dlls / shell32 / autocomplete.c
blob684e990a6513663a9b06a355a69a24a0c7d73662
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 IAutoComplete2 IAutoComplete2_iface;
68 IAutoCompleteDropDown IAutoCompleteDropDown_iface;
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 static inline IAutoCompleteImpl *impl_from_IAutoComplete2(IAutoComplete2 *iface)
91 return CONTAINING_RECORD(iface, IAutoCompleteImpl, IAutoComplete2_iface);
94 static inline IAutoCompleteImpl *impl_from_IAutoCompleteDropDown(IAutoCompleteDropDown *iface)
96 return CONTAINING_RECORD(iface, IAutoCompleteImpl, IAutoCompleteDropDown_iface);
99 static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
100 static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
102 static void create_listbox(IAutoCompleteImpl *This)
104 HWND hwndParent;
106 hwndParent = GetParent(This->hwndEdit);
108 /* FIXME : The listbox should be resizable with the mouse. WS_THICKFRAME looks ugly */
109 This->hwndListBox = CreateWindowExW(0, WC_LISTBOXW, NULL,
110 WS_BORDER | WS_CHILD | WS_VSCROLL | LBS_HASSTRINGS | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT,
111 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
112 hwndParent, NULL, shell32_hInstance, NULL );
114 if (This->hwndListBox) {
115 This->wpOrigLBoxProc = (WNDPROC) SetWindowLongPtrW( This->hwndListBox, GWLP_WNDPROC, (LONG_PTR) ACLBoxSubclassProc);
116 SetWindowLongPtrW( This->hwndListBox, GWLP_USERDATA, (LONG_PTR)This);
120 /**************************************************************************
121 * IAutoComplete_Constructor
123 HRESULT WINAPI IAutoComplete_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
125 IAutoCompleteImpl *lpac;
126 HRESULT hr;
128 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
129 return CLASS_E_NOAGGREGATION;
131 lpac = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAutoCompleteImpl));
132 if (!lpac)
133 return E_OUTOFMEMORY;
135 lpac->ref = 1;
136 lpac->IAutoComplete2_iface.lpVtbl = &acvt;
137 lpac->IAutoCompleteDropDown_iface.lpVtbl = &acdropdownvt;
138 lpac->enabled = TRUE;
139 lpac->options = ACO_AUTOAPPEND;
141 hr = IAutoComplete2_QueryInterface(&lpac->IAutoComplete2_iface, riid, ppv);
142 IAutoComplete2_Release(&lpac->IAutoComplete2_iface);
144 TRACE("-- (%p)->\n",lpac);
146 return hr;
149 /**************************************************************************
150 * AutoComplete_QueryInterface
152 static HRESULT WINAPI IAutoComplete2_fnQueryInterface(
153 IAutoComplete2 * iface,
154 REFIID riid,
155 LPVOID *ppvObj)
157 IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
159 TRACE("(%p)->(IID:%s,%p)\n", This, shdebugstr_guid(riid), ppvObj);
160 *ppvObj = NULL;
162 if (IsEqualIID(riid, &IID_IUnknown) ||
163 IsEqualIID(riid, &IID_IAutoComplete) ||
164 IsEqualIID(riid, &IID_IAutoComplete2))
166 *ppvObj = This;
168 else if (IsEqualIID(riid, &IID_IAutoCompleteDropDown))
170 *ppvObj = &This->IAutoCompleteDropDown_iface;
173 if (*ppvObj)
175 IUnknown_AddRef((IUnknown*)*ppvObj);
176 TRACE("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
177 return S_OK;
179 WARN("unsupported interface: %s\n", debugstr_guid(riid));
180 return E_NOINTERFACE;
183 /******************************************************************************
184 * IAutoComplete2_fnAddRef
186 static ULONG WINAPI IAutoComplete2_fnAddRef(
187 IAutoComplete2 * iface)
189 IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
190 ULONG refCount = InterlockedIncrement(&This->ref);
192 TRACE("(%p)->(%u)\n", This, refCount - 1);
194 return refCount;
197 /******************************************************************************
198 * IAutoComplete2_fnRelease
200 static ULONG WINAPI IAutoComplete2_fnRelease(
201 IAutoComplete2 * iface)
203 IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
204 ULONG refCount = InterlockedDecrement(&This->ref);
206 TRACE("(%p)->(%u)\n", This, refCount + 1);
208 if (!refCount) {
209 TRACE("destroying IAutoComplete(%p)\n", This);
210 HeapFree(GetProcessHeap(), 0, This->quickComplete);
211 HeapFree(GetProcessHeap(), 0, This->txtbackup);
212 if (This->enumstr)
213 IEnumString_Release(This->enumstr);
214 HeapFree(GetProcessHeap(), 0, This);
216 return refCount;
219 /******************************************************************************
220 * IAutoComplete2_fnEnable
222 static HRESULT WINAPI IAutoComplete2_fnEnable(
223 IAutoComplete2 * iface,
224 BOOL fEnable)
226 IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
227 HRESULT hr = S_OK;
229 TRACE("(%p)->(%s)\n", This, (fEnable)?"true":"false");
231 This->enabled = fEnable;
233 return hr;
236 /******************************************************************************
237 * IAutoComplete2_fnInit
239 static HRESULT WINAPI IAutoComplete2_fnInit(
240 IAutoComplete2 * iface,
241 HWND hwndEdit,
242 IUnknown *punkACL,
243 LPCOLESTR pwzsRegKeyPath,
244 LPCOLESTR pwszQuickComplete)
246 IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
248 TRACE("(%p)->(%p, %p, %s, %s)\n",
249 This, hwndEdit, punkACL, debugstr_w(pwzsRegKeyPath), debugstr_w(pwszQuickComplete));
251 if (This->options & ACO_SEARCH) FIXME(" ACO_SEARCH not supported\n");
252 if (This->options & ACO_FILTERPREFIXES) FIXME(" ACO_FILTERPREFIXES not supported\n");
253 if (This->options & ACO_USETAB) FIXME(" ACO_USETAB not supported\n");
254 if (This->options & ACO_RTLREADING) FIXME(" ACO_RTLREADING not supported\n");
256 if (!hwndEdit || !punkACL)
257 return E_INVALIDARG;
259 if (This->initialized)
261 WARN("Autocompletion object is already initialized\n");
262 /* This->hwndEdit is set to NULL when the edit window is destroyed. */
263 return This->hwndEdit ? E_FAIL : E_UNEXPECTED;
266 if (FAILED (IUnknown_QueryInterface (punkACL, &IID_IEnumString, (LPVOID*)&This->enumstr))) {
267 WARN("No IEnumString interface\n");
268 return E_NOINTERFACE;
271 This->initialized = TRUE;
272 This->hwndEdit = hwndEdit;
273 This->wpOrigEditProc = (WNDPROC) SetWindowLongPtrW( hwndEdit, GWLP_WNDPROC, (LONG_PTR) ACEditSubclassProc);
274 /* Keep at least one reference to the object until the edit window is destroyed. */
275 IAutoComplete2_AddRef(&This->IAutoComplete2_iface);
276 SetPropW( hwndEdit, autocomplete_propertyW, This );
278 if (This->options & ACO_AUTOSUGGEST)
279 create_listbox(This);
281 if (pwzsRegKeyPath) {
282 WCHAR *key;
283 WCHAR result[MAX_PATH];
284 WCHAR *value;
285 HKEY hKey = 0;
286 LONG res;
287 LONG len;
289 /* pwszRegKeyPath contains the key as well as the value, so we split */
290 key = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(pwzsRegKeyPath)+1)*sizeof(WCHAR));
291 strcpyW(key, pwzsRegKeyPath);
292 value = strrchrW(key, '\\');
293 *value = 0;
294 value++;
295 /* Now value contains the value and buffer the key */
296 res = RegOpenKeyExW(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey);
297 if (res != ERROR_SUCCESS) {
298 /* if the key is not found, MSDN states we must seek in HKEY_LOCAL_MACHINE */
299 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hKey);
301 if (res == ERROR_SUCCESS) {
302 res = RegQueryValueW(hKey, value, result, &len);
303 if (res == ERROR_SUCCESS) {
304 This->quickComplete = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
305 strcpyW(This->quickComplete, result);
307 RegCloseKey(hKey);
309 HeapFree(GetProcessHeap(), 0, key);
312 if ((pwszQuickComplete) && (!This->quickComplete)) {
313 This->quickComplete = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(pwszQuickComplete)+1)*sizeof(WCHAR));
314 lstrcpyW(This->quickComplete, pwszQuickComplete);
317 return S_OK;
320 /**************************************************************************
321 * IAutoComplete2_fnGetOptions
323 static HRESULT WINAPI IAutoComplete2_fnGetOptions(
324 IAutoComplete2 * iface,
325 DWORD *pdwFlag)
327 IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
328 HRESULT hr = S_OK;
330 TRACE("(%p) -> (%p)\n", This, pdwFlag);
332 *pdwFlag = This->options;
334 return hr;
337 /**************************************************************************
338 * IAutoComplete2_fnSetOptions
340 static HRESULT WINAPI IAutoComplete2_fnSetOptions(
341 IAutoComplete2 * iface,
342 DWORD dwFlag)
344 IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
345 HRESULT hr = S_OK;
347 TRACE("(%p) -> (0x%x)\n", This, dwFlag);
349 This->options = dwFlag;
351 if ((This->options & ACO_AUTOSUGGEST) && This->hwndEdit && !This->hwndListBox)
352 create_listbox(This);
354 return hr;
357 /**************************************************************************
358 * IAutoCompleteDropDown_fnGetDropDownStatus
360 static HRESULT WINAPI IAutoCompleteDropDown_fnGetDropDownStatus(
361 IAutoCompleteDropDown *iface,
362 DWORD *pdwFlags,
363 LPWSTR *ppwszString)
365 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
366 BOOL dropped;
368 TRACE("(%p) -> (%p, %p)\n", This, pdwFlags, ppwszString);
370 dropped = IsWindowVisible(This->hwndListBox);
372 if (pdwFlags)
373 *pdwFlags = (dropped ? ACDD_VISIBLE : 0);
375 if (ppwszString) {
376 if (dropped) {
377 int sel;
379 sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
380 if (sel >= 0)
382 DWORD len;
384 len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
385 *ppwszString = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
386 SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)*ppwszString);
388 else
389 *ppwszString = NULL;
391 else
392 *ppwszString = NULL;
395 return S_OK;
398 /**************************************************************************
399 * IAutoCompleteDropDown_fnResetEnumarator
401 static HRESULT WINAPI IAutoCompleteDropDown_fnResetEnumerator(
402 IAutoCompleteDropDown *iface)
404 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
406 FIXME("(%p): stub\n", This);
408 return E_NOTIMPL;
413 /**************************************************************************
414 * IAutoComplete2 VTable
416 static const IAutoComplete2Vtbl acvt =
418 IAutoComplete2_fnQueryInterface,
419 IAutoComplete2_fnAddRef,
420 IAutoComplete2_fnRelease,
421 IAutoComplete2_fnInit,
422 IAutoComplete2_fnEnable,
423 /* IAutoComplete2 */
424 IAutoComplete2_fnSetOptions,
425 IAutoComplete2_fnGetOptions,
429 static HRESULT WINAPI IAutoCompleteDropDown_fnQueryInterface(IAutoCompleteDropDown *iface,
430 REFIID riid, LPVOID *ppvObj)
432 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
433 return IAutoComplete2_fnQueryInterface(&This->IAutoComplete2_iface, riid, ppvObj);
436 static ULONG WINAPI IAutoCompleteDropDown_fnAddRef(IAutoCompleteDropDown *iface)
438 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
439 return IAutoComplete2_fnAddRef(&This->IAutoComplete2_iface);
442 static ULONG WINAPI IAutoCompleteDropDown_fnRelease(IAutoCompleteDropDown *iface)
444 IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
445 return IAutoComplete2_fnRelease(&This->IAutoComplete2_iface);
448 /**************************************************************************
449 * IAutoCompleteDropDown VTable
451 static const IAutoCompleteDropDownVtbl acdropdownvt =
453 IAutoCompleteDropDown_fnQueryInterface,
454 IAutoCompleteDropDown_fnAddRef,
455 IAutoCompleteDropDown_fnRelease,
456 IAutoCompleteDropDown_fnGetDropDownStatus,
457 IAutoCompleteDropDown_fnResetEnumerator,
461 Window procedure for autocompletion
463 static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
465 IAutoCompleteImpl *This = GetPropW(hwnd, autocomplete_propertyW);
466 LPOLESTR strs;
467 HRESULT hr;
468 WCHAR hwndText[255];
469 WCHAR *hwndQCText;
470 RECT r;
471 BOOL control, filled, displayall = FALSE;
472 int cpt, height, sel;
474 if (!This->enabled) return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
476 switch (uMsg)
478 case CB_SHOWDROPDOWN:
479 ShowWindow(This->hwndListBox, SW_HIDE);
480 break;
481 case WM_KILLFOCUS:
482 if ((This->options & ACO_AUTOSUGGEST) &&
483 ((HWND)wParam != This->hwndListBox))
485 ShowWindow(This->hwndListBox, SW_HIDE);
487 return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
488 case WM_KEYUP:
489 GetWindowTextW( hwnd, hwndText, sizeof(hwndText)/sizeof(WCHAR));
491 switch(wParam) {
492 case VK_RETURN:
493 /* If quickComplete is set and control is pressed, replace the string */
494 control = GetKeyState(VK_CONTROL) & 0x8000;
495 if (control && This->quickComplete) {
496 hwndQCText = HeapAlloc(GetProcessHeap(), 0,
497 (lstrlenW(This->quickComplete)+lstrlenW(hwndText))*sizeof(WCHAR));
498 sel = sprintfW(hwndQCText, This->quickComplete, hwndText);
499 SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)hwndQCText);
500 SendMessageW(hwnd, EM_SETSEL, 0, sel);
501 HeapFree(GetProcessHeap(), 0, hwndQCText);
504 ShowWindow(This->hwndListBox, SW_HIDE);
505 return 0;
506 case VK_LEFT:
507 case VK_RIGHT:
508 return 0;
509 case VK_UP:
510 case VK_DOWN:
511 /* Two cases here :
512 - if the listbox is not visible, displays it
513 with all the entries if the style ACO_UPDOWNKEYDROPSLIST
514 is present but does not select anything.
515 - if the listbox is visible, change the selection
517 if ( (This->options & (ACO_AUTOSUGGEST | ACO_UPDOWNKEYDROPSLIST))
518 && (!IsWindowVisible(This->hwndListBox) && (! *hwndText)) )
520 /* We must display all the entries */
521 displayall = TRUE;
522 } else {
523 if (IsWindowVisible(This->hwndListBox)) {
524 int count;
526 count = SendMessageW(This->hwndListBox, LB_GETCOUNT, 0, 0);
527 /* Change the selection */
528 sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
529 if (wParam == VK_UP)
530 sel = ((sel-1)<0)?count-1:sel-1;
531 else
532 sel = ((sel+1)>= count)?-1:sel+1;
533 SendMessageW(This->hwndListBox, LB_SETCURSEL, sel, 0);
534 if (sel != -1) {
535 WCHAR *msg;
536 int len;
538 len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
539 msg = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
540 SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
541 SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)msg);
542 SendMessageW(hwnd, EM_SETSEL, lstrlenW(msg), lstrlenW(msg));
543 HeapFree(GetProcessHeap(), 0, msg);
544 } else {
545 SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)This->txtbackup);
546 SendMessageW(hwnd, EM_SETSEL, lstrlenW(This->txtbackup), lstrlenW(This->txtbackup));
549 return 0;
551 break;
552 case VK_BACK:
553 case VK_DELETE:
554 if ((! *hwndText) && (This->options & ACO_AUTOSUGGEST)) {
555 ShowWindow(This->hwndListBox, SW_HIDE);
556 return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
558 if (This->options & ACO_AUTOAPPEND) {
559 DWORD b;
560 SendMessageW(hwnd, EM_GETSEL, (WPARAM)&b, 0);
561 if (b>1) {
562 hwndText[b-1] = '\0';
563 } else {
564 hwndText[0] = '\0';
565 SetWindowTextW(hwnd, hwndText);
568 break;
569 default:
573 SendMessageW(This->hwndListBox, LB_RESETCONTENT, 0, 0);
575 HeapFree(GetProcessHeap(), 0, This->txtbackup);
576 This->txtbackup = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(hwndText)+1)*sizeof(WCHAR));
577 lstrcpyW(This->txtbackup, hwndText);
579 /* Returns if there is no text to search and we doesn't want to display all the entries */
580 if ((!displayall) && (! *hwndText) )
581 break;
583 IEnumString_Reset(This->enumstr);
584 filled = FALSE;
585 for(cpt = 0;;) {
586 ULONG fetched;
587 hr = IEnumString_Next(This->enumstr, 1, &strs, &fetched);
588 if (hr != S_OK)
589 break;
591 if (StrStrIW(strs, hwndText) == strs) {
592 if (!filled && (This->options & ACO_AUTOAPPEND)) {
593 INT typed_length = strlenW(hwndText);
594 WCHAR buffW[255];
596 strcpyW(buffW, hwndText);
597 strcatW(buffW, &strs[typed_length]);
598 SetWindowTextW(hwnd, buffW);
599 SendMessageW(hwnd, EM_SETSEL, typed_length, strlenW(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(&This->IAutoComplete2_iface);
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(), 0, (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;