shell32/tests: Allow individual tests in check_lnk to be todo_wine'd.
[wine] / dlls / shell32 / autocomplete.c
1 /*
2  *      AutoComplete interfaces implementation.
3  *
4  *      Copyright 2004  Maxime Bellengé <maxime.bellenge@laposte.net>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 /*
22   Implemented:
23   - ACO_AUTOAPPEND style
24   - ACO_AUTOSUGGEST style
25   - ACO_UPDOWNKEYDROPSLIST style
26
27   - Handle pwzsRegKeyPath and pwszQuickComplete in Init
28
29   TODO:
30   - implement ACO_SEARCH style
31   - implement ACO_FILTERPREFIXES style
32   - implement ACO_USETAB style
33   - implement ACO_RTLREADING style
34   
35  */
36 #include "config.h"
37
38 #include <stdarg.h>
39 #include <stdlib.h>
40 #include <string.h>
41
42 #define COBJMACROS
43
44 #include "wine/debug.h"
45 #include "windef.h"
46 #include "winbase.h"
47 #include "winreg.h"
48 #include "undocshell.h"
49 #include "shlwapi.h"
50 #include "winerror.h"
51 #include "objbase.h"
52
53 #include "pidl.h"
54 #include "shlobj.h"
55 #include "shldisp.h"
56 #include "debughlp.h"
57
58 #include "wine/unicode.h"
59
60 WINE_DEFAULT_DEBUG_CHANNEL(shell);
61
62 typedef struct
63 {
64     const IAutoCompleteVtbl  *lpVtbl;
65     const IAutoComplete2Vtbl *lpvtblAutoComplete2;
66     LONG ref;
67     BOOL  enabled;
68     HWND hwndEdit;
69     HWND hwndListBox;
70     WNDPROC wpOrigEditProc;
71     WNDPROC wpOrigLBoxProc;
72     WCHAR *txtbackup;
73     WCHAR *quickComplete;
74     IEnumString *enumstr;
75     AUTOCOMPLETEOPTIONS options;
76 } IAutoCompleteImpl;
77
78 static const IAutoCompleteVtbl acvt;
79 static const IAutoComplete2Vtbl ac2vt;
80
81 static inline IAutoCompleteImpl *impl_from_IAutoComplete2( IAutoComplete2 *iface )
82 {
83     return (IAutoCompleteImpl *)((char*)iface - FIELD_OFFSET(IAutoCompleteImpl, lpvtblAutoComplete2));
84 }
85
86
87 /*
88   converts This to an interface pointer
89 */
90 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
91 #define _IAutoComplete2_(This)  (IAutoComplete2*)&(This->lpvtblAutoComplete2) 
92
93 static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
94 static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
95
96 /**************************************************************************
97  *  IAutoComplete_Constructor
98  */
99 HRESULT WINAPI IAutoComplete_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
100 {
101     IAutoCompleteImpl *lpac;
102
103     if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
104         return CLASS_E_NOAGGREGATION;
105
106     lpac = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAutoCompleteImpl));
107     if (!lpac) 
108         return E_OUTOFMEMORY;
109
110     lpac->ref = 1;
111     lpac->lpVtbl = &acvt;
112     lpac->lpvtblAutoComplete2 = &ac2vt;
113     lpac->enabled = TRUE;
114     lpac->enumstr = NULL;
115     lpac->options = ACO_AUTOAPPEND;
116     lpac->wpOrigEditProc = NULL;
117     lpac->hwndListBox = NULL;
118     lpac->txtbackup = NULL;
119     lpac->quickComplete = NULL;
120     
121     if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (lpac), riid, ppv))) {
122         IUnknown_Release (_IUnknown_ (lpac));
123         return E_NOINTERFACE;
124     }
125     
126     TRACE("-- (%p)->\n",lpac);
127
128     return S_OK;
129 }
130
131 /**************************************************************************
132  *  AutoComplete_QueryInterface
133  */
134 static HRESULT WINAPI IAutoComplete_fnQueryInterface(
135     IAutoComplete * iface,
136     REFIID riid,
137     LPVOID *ppvObj)
138 {
139     IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
140     
141     TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This, shdebugstr_guid(riid), ppvObj);
142     *ppvObj = NULL;
143
144     if(IsEqualIID(riid, &IID_IUnknown)) 
145     {
146         *ppvObj = This;
147     } 
148     else if(IsEqualIID(riid, &IID_IAutoComplete))
149     {
150         *ppvObj = (IAutoComplete*)This;
151     }
152     else if(IsEqualIID(riid, &IID_IAutoComplete2))
153     {
154         *ppvObj = _IAutoComplete2_ (This);
155     }
156
157     if (*ppvObj)
158     {
159         IAutoComplete_AddRef((IAutoComplete*)*ppvObj);
160         TRACE("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
161         return S_OK;
162     }
163     TRACE("-- Interface: E_NOINTERFACE\n");
164     return E_NOINTERFACE;       
165 }
166
167 /******************************************************************************
168  * IAutoComplete_fnAddRef
169  */
170 static ULONG WINAPI IAutoComplete_fnAddRef(
171         IAutoComplete * iface)
172 {
173     IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
174     ULONG refCount = InterlockedIncrement(&This->ref);
175     
176     TRACE("(%p)->(%u)\n", This, refCount - 1);
177
178     return refCount;
179 }
180
181 /******************************************************************************
182  * IAutoComplete_fnRelease
183  */
184 static ULONG WINAPI IAutoComplete_fnRelease(
185         IAutoComplete * iface)
186 {
187     IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
188     ULONG refCount = InterlockedDecrement(&This->ref);
189     
190     TRACE("(%p)->(%u)\n", This, refCount + 1);
191
192     if (!refCount) {
193         TRACE(" destroying IAutoComplete(%p)\n",This);
194         HeapFree(GetProcessHeap(), 0, This->quickComplete);
195         HeapFree(GetProcessHeap(), 0, This->txtbackup);
196         if (This->hwndListBox)
197             DestroyWindow(This->hwndListBox);
198         if (This->enumstr)
199             IEnumString_Release(This->enumstr);
200         HeapFree(GetProcessHeap(), 0, This);
201     }
202     return refCount;
203 }
204
205 /******************************************************************************
206  * IAutoComplete_fnEnable
207  */
208 static HRESULT WINAPI IAutoComplete_fnEnable(
209     IAutoComplete * iface,
210     BOOL fEnable)
211 {
212     IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
213
214     HRESULT hr = S_OK;
215
216     TRACE("(%p)->(%s)\n", This, (fEnable)?"true":"false");
217
218     This->enabled = fEnable;
219
220     return hr;
221 }
222
223 /******************************************************************************
224  * IAutoComplete_fnInit
225  */
226 static HRESULT WINAPI IAutoComplete_fnInit(
227     IAutoComplete * iface,
228     HWND hwndEdit,
229     IUnknown *punkACL,
230     LPCOLESTR pwzsRegKeyPath,
231     LPCOLESTR pwszQuickComplete)
232 {
233     IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
234     static const WCHAR lbName[] = {'L','i','s','t','B','o','x',0};
235
236     TRACE("(%p)->(0x%08lx, %p, %s, %s)\n", 
237           This, (long)hwndEdit, punkACL, debugstr_w(pwzsRegKeyPath), debugstr_w(pwszQuickComplete));
238
239     if (This->options & ACO_AUTOSUGGEST) TRACE(" ACO_AUTOSUGGEST\n");
240     if (This->options & ACO_AUTOAPPEND) TRACE(" ACO_AUTOAPPEND\n");
241     if (This->options & ACO_SEARCH) FIXME(" ACO_SEARCH not supported\n");
242     if (This->options & ACO_FILTERPREFIXES) FIXME(" ACO_FILTERPREFIXES not supported\n");
243     if (This->options & ACO_USETAB) FIXME(" ACO_USETAB not supported\n");
244     if (This->options & ACO_UPDOWNKEYDROPSLIST) TRACE(" ACO_UPDOWNKEYDROPSLIST\n");
245     if (This->options & ACO_RTLREADING) FIXME(" ACO_RTLREADING not supported\n");
246
247     This->hwndEdit = hwndEdit;
248
249     if (!SUCCEEDED (IUnknown_QueryInterface (punkACL, &IID_IEnumString, (LPVOID*)&This->enumstr))) {
250         TRACE("No IEnumString interface\n");
251         return  E_NOINTERFACE;
252     }
253
254     This->wpOrigEditProc = (WNDPROC) SetWindowLongPtrW( hwndEdit, GWLP_WNDPROC, (LONG_PTR) ACEditSubclassProc);
255     SetWindowLongPtrW( hwndEdit, GWLP_USERDATA, (LONG_PTR)This);
256
257     if (This->options & ACO_AUTOSUGGEST) {
258         HWND hwndParent;
259
260         hwndParent = GetParent(This->hwndEdit);
261         
262         /* FIXME : The listbox should be resizable with the mouse. WS_THICKFRAME looks ugly */
263         This->hwndListBox = CreateWindowExW(0, lbName, NULL, 
264                                             WS_BORDER | WS_CHILD | WS_VSCROLL | LBS_HASSTRINGS | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT, 
265                                             CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
266                                             hwndParent, NULL, 
267                                             (HINSTANCE)GetWindowLongPtrW( hwndParent, GWLP_HINSTANCE ), NULL);
268                                             
269         if (This->hwndListBox) {
270             This->wpOrigLBoxProc = (WNDPROC) SetWindowLongPtrW( This->hwndListBox, GWLP_WNDPROC, (LONG_PTR) ACLBoxSubclassProc);
271             SetWindowLongPtrW( This->hwndListBox, GWLP_USERDATA, (LONG_PTR)This);
272         }
273     }
274
275     if (pwzsRegKeyPath) {
276         WCHAR *key;
277         WCHAR result[MAX_PATH];
278         WCHAR *value;
279         HKEY hKey = 0;
280         LONG res;
281         LONG len;
282
283         /* pwszRegKeyPath contains the key as well as the value, so we split */
284         key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwzsRegKeyPath)+1)*sizeof(WCHAR));
285         strcpyW(key, pwzsRegKeyPath);
286         value = strrchrW(key, '\\');
287         *value = 0;
288         value++;
289         /* Now value contains the value and buffer the key */
290         res = RegOpenKeyExW(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey);
291         if (res != ERROR_SUCCESS) {
292             /* if the key is not found, MSDN states we must seek in HKEY_LOCAL_MACHINE */
293             res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hKey);  
294         }
295         if (res == ERROR_SUCCESS) {
296             res = RegQueryValueW(hKey, value, result, &len);
297             if (res == ERROR_SUCCESS) {
298                 This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR));
299                 strcpyW(This->quickComplete, result);
300             }
301             RegCloseKey(hKey);
302         }
303         HeapFree(GetProcessHeap(), 0, key);
304     }
305
306     if ((pwszQuickComplete) && (!This->quickComplete)) {
307         This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwszQuickComplete)+1)*sizeof(WCHAR));
308         lstrcpyW(This->quickComplete, pwszQuickComplete);
309     }
310
311     return S_OK;
312 }
313
314 /**************************************************************************
315  *  IAutoComplete_fnVTable
316  */
317 static const IAutoCompleteVtbl acvt =
318 {
319     IAutoComplete_fnQueryInterface,
320     IAutoComplete_fnAddRef,
321     IAutoComplete_fnRelease,
322     IAutoComplete_fnInit,
323     IAutoComplete_fnEnable,
324 };
325
326 /**************************************************************************
327  *  AutoComplete2_QueryInterface
328  */
329 static HRESULT WINAPI IAutoComplete2_fnQueryInterface(
330     IAutoComplete2 * iface,
331     REFIID riid,
332     LPVOID *ppvObj)
333 {
334     IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
335
336     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
337
338     return IAutoComplete_QueryInterface((IAutoComplete*)This, riid, ppvObj);
339 }
340
341 /******************************************************************************
342  * IAutoComplete2_fnAddRef
343  */
344 static ULONG WINAPI IAutoComplete2_fnAddRef(
345         IAutoComplete2 * iface)
346 {
347     IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
348
349     TRACE ("(%p)->(count=%u)\n", This, This->ref);
350
351     return IAutoComplete2_AddRef((IAutoComplete*)This);
352 }
353
354 /******************************************************************************
355  * IAutoComplete2_fnRelease
356  */
357 static ULONG WINAPI IAutoComplete2_fnRelease(
358         IAutoComplete2 * iface)
359 {
360     IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
361
362     TRACE ("(%p)->(count=%u)\n", This, This->ref);
363
364     return IAutoComplete_Release((IAutoComplete*)This);
365 }
366
367 /******************************************************************************
368  * IAutoComplete2_fnEnable
369  */
370 static HRESULT WINAPI IAutoComplete2_fnEnable(
371     IAutoComplete2 * iface,
372     BOOL fEnable)
373 {
374     IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
375
376     TRACE ("(%p)->(%s)\n", This, (fEnable)?"true":"false");
377
378     return IAutoComplete_Enable((IAutoComplete*)This, fEnable);
379 }
380
381 /******************************************************************************
382  * IAutoComplete2_fnInit
383  */
384 static HRESULT WINAPI IAutoComplete2_fnInit(
385     IAutoComplete2 * iface,
386     HWND hwndEdit,
387     IUnknown *punkACL,
388     LPCOLESTR pwzsRegKeyPath,
389     LPCOLESTR pwszQuickComplete)
390 {
391     IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
392
393     TRACE("(%p)\n", This);
394
395     return IAutoComplete_Init((IAutoComplete*)This, hwndEdit, punkACL, pwzsRegKeyPath, pwszQuickComplete);
396 }
397
398 /**************************************************************************
399  *  IAutoComplete_fnGetOptions
400  */
401 static HRESULT WINAPI IAutoComplete2_fnGetOptions(
402     IAutoComplete2 * iface,
403     DWORD *pdwFlag)
404 {
405     HRESULT hr = S_OK;
406
407     IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
408
409     TRACE("(%p) -> (%p)\n", This, pdwFlag);
410
411     *pdwFlag = This->options;
412
413     return hr;
414 }
415
416 /**************************************************************************
417  *  IAutoComplete_fnSetOptions
418  */
419 static HRESULT WINAPI IAutoComplete2_fnSetOptions(
420     IAutoComplete2 * iface,
421     DWORD dwFlag)
422 {
423     HRESULT hr = S_OK;
424
425     IAutoCompleteImpl *This = impl_from_IAutoComplete2(iface);
426
427     TRACE("(%p) -> (0x%x)\n", This, dwFlag);
428
429     This->options = dwFlag;
430
431     return hr;
432 }
433
434 /**************************************************************************
435  *  IAutoComplete2_fnVTable
436  */
437 static const IAutoComplete2Vtbl ac2vt =
438 {
439     IAutoComplete2_fnQueryInterface,
440     IAutoComplete2_fnAddRef,
441     IAutoComplete2_fnRelease,
442     IAutoComplete2_fnInit,
443     IAutoComplete2_fnEnable,
444     /* IAutoComplete2 */
445     IAutoComplete2_fnSetOptions,
446     IAutoComplete2_fnGetOptions,
447 };
448
449 /*
450   Window procedure for autocompletion
451  */
452 static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
453 {
454     IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
455     LPOLESTR strs;
456     HRESULT hr;
457     WCHAR hwndText[255];
458     WCHAR *hwndQCText;
459     RECT r;
460     BOOL control, filled, displayall = FALSE;
461     int cpt, height, sel;
462
463     if (!This->enabled) return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
464
465     switch (uMsg)
466     {
467         case CB_SHOWDROPDOWN:
468             ShowWindow(This->hwndListBox, SW_HIDE);
469             break;
470         case WM_KILLFOCUS:
471             if ((This->options && ACO_AUTOSUGGEST) && 
472                 ((HWND)wParam != This->hwndListBox))
473             {
474                 ShowWindow(This->hwndListBox, SW_HIDE);
475             }
476             break;
477         case WM_KEYUP:
478             
479             GetWindowTextW( hwnd, (LPWSTR)hwndText, 255);
480       
481             switch(wParam) {
482                 case VK_RETURN:
483                     /* If quickComplete is set and control is pressed, replace the string */
484                     control = GetKeyState(VK_CONTROL) & 0x8000;             
485                     if (control && This->quickComplete) {
486                         hwndQCText = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
487                                                        (lstrlenW(This->quickComplete)+lstrlenW(hwndText))*sizeof(WCHAR));
488                         sel = sprintfW(hwndQCText, This->quickComplete, hwndText);
489                         SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)hwndQCText);
490                         SendMessageW(hwnd, EM_SETSEL, 0, sel);
491                         HeapFree(GetProcessHeap(), 0, hwndQCText);
492                     }
493
494                     ShowWindow(This->hwndListBox, SW_HIDE);
495                     return 0;
496                 case VK_LEFT:
497                 case VK_RIGHT:
498                     return 0;
499                 case VK_UP:           
500                 case VK_DOWN:
501                     /* Two cases here : 
502                        - if the listbox is not visible, displays it 
503                        with all the entries if the style ACO_UPDOWNKEYDROPSLIST
504                        is present but does not select anything.
505                        - if the listbox is visible, change the selection
506                     */
507                     if ( (This->options & (ACO_AUTOSUGGEST | ACO_UPDOWNKEYDROPSLIST)) 
508                          && (!IsWindowVisible(This->hwndListBox) && (! *hwndText)) )
509                     {
510                          /* We must dispays all the entries */
511                          displayall = TRUE;
512                     } else {
513                         if (IsWindowVisible(This->hwndListBox)) {
514                             int count;
515
516                             count = SendMessageW(This->hwndListBox, LB_GETCOUNT, 0, 0);
517                             /* Change the selection */
518                             sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
519                             if (wParam == VK_UP)
520                                 sel = ((sel-1)<0)?count-1:sel-1;
521                             else
522                                 sel = ((sel+1)>= count)?-1:sel+1;
523                             SendMessageW(This->hwndListBox, LB_SETCURSEL, sel, 0);
524                             if (sel != -1) {
525                                 WCHAR *msg;
526                                 int len;
527                                 
528                                 len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, (LPARAM)NULL);
529                                 msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
530                                 SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
531                                 SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)msg);
532                                 SendMessageW(hwnd, EM_SETSEL, lstrlenW(msg), lstrlenW(msg));
533                                 HeapFree(GetProcessHeap(), 0, msg);
534                             } else {
535                                 SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)This->txtbackup);
536                                 SendMessageW(hwnd, EM_SETSEL, lstrlenW(This->txtbackup), lstrlenW(This->txtbackup));
537                             }                   
538                         }               
539                         return 0;
540                     }
541                     break;
542                 case VK_BACK:
543                 case VK_DELETE:
544                     if ((! *hwndText) && (This->options & ACO_AUTOSUGGEST)) {
545                         ShowWindow(This->hwndListBox, SW_HIDE);
546                         return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
547                     }
548                     if (This->options & ACO_AUTOAPPEND) {
549                         DWORD b;
550                         SendMessageW(hwnd, EM_GETSEL, (WPARAM)&b, (LPARAM)NULL);
551                         if (b>1) {
552                             hwndText[b-1] = '\0';
553                         } else {
554                             hwndText[0] = '\0';
555                             SetWindowTextW(hwnd, hwndText); 
556                         }                       
557                     }
558                     break;
559                 default:                    
560                     ;
561             }
562       
563             SendMessageW(This->hwndListBox, LB_RESETCONTENT, 0, 0);
564
565             HeapFree(GetProcessHeap(), 0, This->txtbackup);
566             This->txtbackup = HeapAlloc(GetProcessHeap(),
567                                                  HEAP_ZERO_MEMORY, (lstrlenW(hwndText)+1)*sizeof(WCHAR));                                                             
568             lstrcpyW(This->txtbackup, hwndText);
569
570             /* Returns if there is no text to search and we doesn't want to display all the entries */
571             if ((!displayall) && (! *hwndText) )
572                 break;
573             
574             IEnumString_Reset(This->enumstr);
575             filled = FALSE;
576             for(cpt = 0;;) {
577                 hr = IEnumString_Next(This->enumstr, 1, &strs, NULL);
578                 if (hr != S_OK)
579                     break;
580
581                 if ((LPWSTR)strstrW(strs, hwndText) == strs) {
582                     
583                     if (This->options & ACO_AUTOAPPEND) {
584                         SetWindowTextW(hwnd, strs);
585                         SendMessageW(hwnd, EM_SETSEL, lstrlenW(hwndText), lstrlenW(strs));
586                         break;
587                     }           
588
589                     if (This->options & ACO_AUTOSUGGEST) {
590                         SendMessageW(This->hwndListBox, LB_ADDSTRING, 0, (LPARAM)strs);
591                         filled = TRUE;
592                         cpt++;
593                     }
594                 }               
595             }
596             
597             if (This->options & ACO_AUTOSUGGEST) {
598                 if (filled) {
599                     height = SendMessageW(This->hwndListBox, LB_GETITEMHEIGHT, 0, 0);
600                     SendMessageW(This->hwndListBox, LB_CARETOFF, 0, 0);
601                     GetWindowRect(hwnd, &r);
602                     SetParent(This->hwndListBox, HWND_DESKTOP);
603                     /* It seems that Windows XP displays 7 lines at most 
604                        and otherwise displays a vertical scroll bar */
605                     SetWindowPos(This->hwndListBox, HWND_TOP, 
606                                  r.left, r.bottom + 1, r.right - r.left, min(height * 7, height*(cpt+1)), 
607                                  SWP_SHOWWINDOW );
608                 } else {
609                     ShowWindow(This->hwndListBox, SW_HIDE);
610                 }
611             }
612             
613             break; 
614         default:
615             return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
616             
617     }
618
619     return 0;
620 }
621
622 static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
623 {
624     IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
625     WCHAR *msg;
626     int sel, len;
627
628     switch (uMsg) {
629         case WM_MOUSEMOVE:
630             sel = SendMessageW(hwnd, LB_ITEMFROMPOINT, 0, lParam);
631             SendMessageW(hwnd, LB_SETCURSEL, (WPARAM)sel, (LPARAM)0);
632             break;
633         case WM_LBUTTONDOWN:
634             sel = SendMessageW(hwnd, LB_GETCURSEL, 0, 0);
635             if (sel < 0)
636                 break;
637             len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
638             msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
639             SendMessageW(hwnd, LB_GETTEXT, sel, (LPARAM)msg);
640             SendMessageW(This->hwndEdit, WM_SETTEXT, 0, (LPARAM)msg);
641             SendMessageW(This->hwndEdit, EM_SETSEL, 0, lstrlenW(msg));
642             ShowWindow(hwnd, SW_HIDE);
643             HeapFree(GetProcessHeap(), 0, msg);
644             break;
645         default:
646             return CallWindowProcW(This->wpOrigLBoxProc, hwnd, uMsg, wParam, lParam);
647     }
648     return 0;
649 }