comctl32/listview: Convert header notifications to ANSI in place.
[wine] / dlls / comctl32 / comboex.c
1 /*
2  * ComboBoxEx control
3  *
4  * Copyright 1998, 1999 Eric Kohl
5  * Copyright 2000, 2001, 2002 Guy Albertelli <galberte@neo.lrun.com>
6  * Copyright 2002 Dimitrie O. Paun
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  *
22  * NOTE
23  * 
24  * This code was audited for completeness against the documented features
25  * of Comctl32.dll version 6.0 on Sep. 9, 2002, by Dimitrie O. Paun.
26  * 
27  * Unless otherwise noted, we believe this code to be complete, as per
28  * the specification mentioned above.
29  * If you discover missing features, or bugs, please note them below.
30  * 
31  */
32
33 #include <stdarg.h>
34 #include <string.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38 #include "winuser.h"
39 #include "winnls.h"
40 #include "commctrl.h"
41 #include "comctl32.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
46
47 /* Item structure */
48 typedef struct _CBE_ITEMDATA
49 {
50     struct _CBE_ITEMDATA *next;
51     UINT         mask;
52     LPWSTR       pszText;
53     LPWSTR       pszTemp;
54     int          cchTextMax;
55     int          iImage;
56     int          iSelectedImage;
57     int          iOverlay;
58     int          iIndent;
59     LPARAM       lParam;
60 } CBE_ITEMDATA;
61
62 /* ComboBoxEx structure */
63 typedef struct
64 {
65     HIMAGELIST   himl;
66     HWND         hwndSelf;         /* my own hwnd */
67     HWND         hwndNotify;       /* my parent hwnd */
68     HWND         hwndCombo;
69     HWND         hwndEdit;
70     DWORD        dwExtStyle;
71     INT          selected;         /* index of selected item */
72     DWORD        flags;            /* WINE internal flags */
73     HFONT        defaultFont;
74     HFONT        font;
75     INT          nb_items;         /* Number of items */
76     BOOL         unicode;          /* TRUE if this window is Unicode   */
77     BOOL         NtfUnicode;       /* TRUE if parent wants notify in Unicode */
78     CBE_ITEMDATA *edit;            /* item data for edit item */
79     CBE_ITEMDATA *items;           /* Array of items */
80 } COMBOEX_INFO;
81
82 /* internal flags in the COMBOEX_INFO structure */
83 #define  WCBE_ACTEDIT           0x00000001  /* Edit active i.e.
84                                              * CBEN_BEGINEDIT issued
85                                              * but CBEN_ENDEDIT{A|W}
86                                              * not yet issued. */
87 #define  WCBE_EDITCHG           0x00000002  /* Edit issued EN_CHANGE */
88 #define  WCBE_EDITHASCHANGED    (WCBE_ACTEDIT | WCBE_EDITCHG)
89 #define  WCBE_EDITFOCUSED       0x00000004  /* Edit control has focus */
90 #define  WCBE_MOUSECAPTURED     0x00000008  /* Combo has captured mouse */
91 #define  WCBE_MOUSEDRAGGED      0x00000010  /* User has dragged in combo */
92
93 #define ID_CB_EDIT              1001
94
95
96 /*
97  * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
98  * the ComboEx version of the Combo Window Proc so that when the
99  * WM_DRAWITEM message is then passed to ComboEx, we know that this
100  * particular WM_DRAWITEM message is for listbox only items. Any message
101  * without this flag is then for the Edit control field.
102  *
103  * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
104  * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
105  */
106 #define ODS_COMBOEXLBOX         0x4000
107
108
109
110 /* Height in pixels of control over the amount of the selected font */
111 #define CBE_EXTRA               3
112
113 /* Indent amount per MS documentation */
114 #define CBE_INDENT              10
115
116 /* Offset in pixels from left side for start of image or text */
117 #define CBE_STARTOFFSET         6
118
119 /* Offset between image and text */
120 #define CBE_SEP                 4
121
122 #define COMBO_SUBCLASSID  1
123 #define EDIT_SUBCLASSID   2
124
125 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongPtrW (hwnd, 0))
126
127 static LRESULT CALLBACK COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
128                                              UINT_PTR uId, DWORD_PTR ref_data);
129 static LRESULT CALLBACK COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
130                                               UINT_PTR uId, DWORD_PTR ref_data);
131 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
132 typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
133
134 static inline BOOL is_textW(LPCWSTR str)
135 {
136     return str && str != LPSTR_TEXTCALLBACKW;
137 }
138
139 static inline BOOL is_textA(LPCSTR str)
140 {
141     return str && str != LPSTR_TEXTCALLBACKA;
142 }
143
144 static inline LPCSTR debugstr_txt(LPCWSTR str)
145 {
146     if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
147     return debugstr_w(str);
148 }
149
150 static void COMBOEX_DumpItem (CBE_ITEMDATA const *item)
151 {
152     TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
153           item, item->mask, item->pszText, item->cchTextMax, item->iImage);
154     TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
155           item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
156     if (item->mask & CBEIF_TEXT)
157         TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
158 }
159
160
161 static void COMBOEX_DumpInput (COMBOBOXEXITEMW const *input)
162 {
163     TRACE("input - mask=%08x, iItem=%ld, pszText=%p, cchTM=%d, iImage=%d\n",
164           input->mask, input->iItem, input->pszText, input->cchTextMax,
165           input->iImage);
166     if (input->mask & CBEIF_TEXT)
167         TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
168     TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
169           input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
170 }
171
172
173 static inline CBE_ITEMDATA *get_item_data(const COMBOEX_INFO *infoPtr, INT index)
174 {
175     return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
176                                          index, 0);
177 }
178
179 static inline cmp_func_t get_cmp_func(COMBOEX_INFO const *infoPtr)
180 {
181     return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
182 }
183
184 static INT COMBOEX_Notify (const COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
185 {
186     hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
187     hdr->hwndFrom = infoPtr->hwndSelf;
188     hdr->code = code;
189     if (infoPtr->NtfUnicode)
190         return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
191     else
192         return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
193 }
194
195
196 static INT
197 COMBOEX_NotifyItem (const COMBOEX_INFO *infoPtr, UINT code, NMCOMBOBOXEXW *hdr)
198 {
199     /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
200     if (infoPtr->NtfUnicode)
201         return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
202     else {
203         LPWSTR wstr = hdr->ceItem.pszText;
204         LPSTR astr = 0;
205         INT ret, len = 0;
206
207         if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
208             len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
209             if (len > 0) {
210                 astr = Alloc ((len + 1)*sizeof(CHAR));
211                 if (!astr) return 0;
212                 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
213                 hdr->ceItem.pszText = (LPWSTR)astr;
214             }
215         }
216
217         if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
218         else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
219         else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
220
221         ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
222
223         if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
224             hdr->ceItem.pszText = wstr;
225
226         Free(astr);
227
228         return ret;
229     }
230 }
231
232
233 static INT COMBOEX_NotifyEndEdit (const COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
234 {
235     /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
236     if (infoPtr->NtfUnicode) {
237         lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
238         return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
239     } else {
240         NMCBEENDEDITA neea;
241
242         neea.hdr = neew->hdr;
243         neea.fChanged = neew->fChanged;
244         neea.iNewSelection = neew->iNewSelection;
245         WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
246         neea.iWhy = neew->iWhy;
247
248         return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
249     }
250 }
251
252
253 static void COMBOEX_NotifyDragBegin(const COMBOEX_INFO *infoPtr, LPCWSTR wstr)
254 {
255     /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
256     if (infoPtr->NtfUnicode) {
257         NMCBEDRAGBEGINW ndbw;
258
259         ndbw.iItemid = -1;
260         lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
261         COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
262     } else {
263         NMCBEDRAGBEGINA ndba;
264
265         ndba.iItemid = -1;
266         WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
267
268         COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
269     }
270 }
271
272
273 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
274 {
275     if (is_textW(item->pszText)) Free(item->pszText);
276     item->pszText = 0;
277     Free(item->pszTemp);
278     item->pszTemp = 0;
279 }
280
281
282 static INT COMBOEX_GetIndex(COMBOEX_INFO const *infoPtr, CBE_ITEMDATA const *item)
283 {
284     CBE_ITEMDATA const *moving;
285     INT index;
286
287     moving = infoPtr->items;
288     index = infoPtr->nb_items - 1;
289
290     while (moving && (moving != item)) {
291         moving = moving->next;
292         index--;
293     }
294     if (!moving || (index < 0)) {
295         ERR("COMBOBOXEX item structures broken. Please report!\n");
296         return -1;
297     }
298     return index;
299 }
300
301
302 static LPCWSTR COMBOEX_GetText(const COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
303 {
304     NMCOMBOBOXEXW nmce;
305     LPWSTR text, buf;
306     INT len;
307
308     if (item->pszText != LPSTR_TEXTCALLBACKW)
309         return item->pszText;
310
311     ZeroMemory(&nmce, sizeof(nmce));
312     nmce.ceItem.mask = CBEIF_TEXT;
313     nmce.ceItem.lParam = item->lParam;
314     nmce.ceItem.iItem = COMBOEX_GetIndex(infoPtr, item);
315     COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
316
317     if (is_textW(nmce.ceItem.pszText)) {
318         len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
319         buf = Alloc ((len + 1)*sizeof(WCHAR));
320         if (buf)
321             MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
322         if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
323             COMBOEX_FreeText(item);
324             item->pszText = buf;
325         } else {
326             Free(item->pszTemp);
327             item->pszTemp = buf;
328         }
329         text = buf;
330     } else
331         text = nmce.ceItem.pszText;
332
333     if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
334         item->pszText = text;
335     return text;
336 }
337
338
339 static void COMBOEX_GetComboFontSize (const COMBOEX_INFO *infoPtr, SIZE *size)
340 {
341     static const WCHAR strA[] = { 'A', 0 };
342     HFONT nfont, ofont;
343     HDC mydc;
344
345     mydc = GetDC (0); /* why the entire screen???? */
346     nfont = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
347     ofont = SelectObject (mydc, nfont);
348     GetTextExtentPointW (mydc, strA, 1, size);
349     SelectObject (mydc, ofont);
350     ReleaseDC (0, mydc);
351     TRACE("selected font hwnd=%p, height=%d\n", nfont, size->cy);
352 }
353
354
355 static void COMBOEX_CopyItem (const CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
356 {
357     if (cit->mask & CBEIF_TEXT) {
358         /*
359          * when given a text buffer actually use that buffer
360          */
361         if (cit->pszText) {
362             if (is_textW(item->pszText))
363                 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
364             else
365                 cit->pszText[0] = 0;
366         } else {
367             cit->pszText        = item->pszText;
368             cit->cchTextMax     = item->cchTextMax;
369         }
370     }
371     if (cit->mask & CBEIF_IMAGE)
372         cit->iImage         = item->iImage;
373     if (cit->mask & CBEIF_SELECTEDIMAGE)
374         cit->iSelectedImage = item->iSelectedImage;
375     if (cit->mask & CBEIF_OVERLAY)
376         cit->iOverlay       = item->iOverlay;
377     if (cit->mask & CBEIF_INDENT)
378         cit->iIndent        = item->iIndent;
379     if (cit->mask & CBEIF_LPARAM)
380         cit->lParam         = item->lParam;
381 }
382
383
384 static void COMBOEX_AdjustEditPos (const COMBOEX_INFO *infoPtr)
385 {
386     SIZE mysize;
387     INT x, y, w, h, xioff;
388     RECT rect;
389
390     if (!infoPtr->hwndEdit) return;
391
392     if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
393         IMAGEINFO iinfo;
394         iinfo.rcImage.left = iinfo.rcImage.right = 0;
395         ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
396         xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
397     }  else xioff = 0;
398
399     GetClientRect (infoPtr->hwndCombo, &rect);
400     InflateRect (&rect, -2, -2);
401     InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
402
403     /* reposition the Edit control based on whether icon exists */
404     COMBOEX_GetComboFontSize (infoPtr, &mysize);
405     TRACE("Combo font x=%d, y=%d\n", mysize.cx, mysize.cy);
406     x = xioff + CBE_STARTOFFSET + 1;
407     w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
408     h = mysize.cy + 1;
409     y = rect.bottom - h - 1;
410
411     TRACE("Combo client (%s), setting Edit to (%d,%d)-(%d,%d)\n",
412           wine_dbgstr_rect(&rect), x, y, x + w, y + h);
413     SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
414                  SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
415 }
416
417
418 static void COMBOEX_ReSize (const COMBOEX_INFO *infoPtr)
419 {
420     SIZE mysize;
421     LONG cy;
422     IMAGEINFO iinfo;
423
424     COMBOEX_GetComboFontSize (infoPtr, &mysize);
425     cy = mysize.cy + CBE_EXTRA;
426     if (infoPtr->himl && ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo)) {
427         cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
428         TRACE("upgraded height due to image:  height=%d\n", cy);
429     }
430     SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, -1, cy);
431     if (infoPtr->hwndCombo) {
432         SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, 0, cy);
433         if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
434             RECT comboRect, ourRect;
435             GetWindowRect(infoPtr->hwndCombo, &comboRect);
436             GetWindowRect(infoPtr->hwndSelf, &ourRect);
437             if (comboRect.bottom > ourRect.bottom)
438                 SetWindowPos( infoPtr->hwndSelf, 0, 0, 0, ourRect.right - ourRect.left,
439                               comboRect.bottom - comboRect.top,
440                               SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW );
441         }
442     }
443 }
444
445
446 static void COMBOEX_SetEditText (const COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
447 {
448     if (!infoPtr->hwndEdit) return;
449
450     if (item->mask & CBEIF_TEXT) {
451         SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
452         SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
453         SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
454     }
455 }
456
457
458 static CBE_ITEMDATA * COMBOEX_FindItem(const COMBOEX_INFO *infoPtr, INT_PTR index)
459 {
460     CBE_ITEMDATA *item;
461     INT i;
462
463     if ((index >= infoPtr->nb_items) || (index < -1))
464         return 0;
465     if (index == -1)
466         return infoPtr->edit;
467     item = infoPtr->items;
468     i = infoPtr->nb_items - 1;
469
470     /* find the item in the list */
471     while (item && (i > index)) {
472         item = item->next;
473         i--;
474     }
475     if (!item || (i != index)) {
476         ERR("COMBOBOXEX item structures broken. Please report!\n");
477         return 0;
478     }
479     return item;
480 }
481
482 /* ***  CBEM_xxx message support  *** */
483
484 static UINT COMBOEX_GetListboxText(const COMBOEX_INFO *infoPtr, INT_PTR n, LPWSTR buf)
485 {
486     CBE_ITEMDATA *item;
487     LPCWSTR str;
488
489     item = COMBOEX_FindItem(infoPtr, n);
490     if (!item)
491         return 0;
492
493     str = COMBOEX_GetText(infoPtr, item);
494     if (!str)
495     {
496         if (buf)
497         {
498             if (infoPtr->unicode)
499                 buf[0] = 0;
500             else
501                 *((LPSTR)buf) = 0;
502         }
503         return 0;
504     }
505
506     if (infoPtr->unicode)
507     {
508         if (buf)
509             lstrcpyW(buf, str);
510         return lstrlenW(str);
511     }
512     else
513     {
514         UINT r;
515         r = WideCharToMultiByte(CP_ACP, 0, str, -1, (LPSTR)buf, 0x40000000, NULL, NULL);
516         if (r) r--;
517         return r;
518     }
519 }
520
521
522 static INT COMBOEX_DeleteItem (const COMBOEX_INFO *infoPtr, INT_PTR index)
523 {
524     TRACE("(index=%ld)\n", index);
525
526     /* if item number requested does not exist then return failure */
527     if ((index >= infoPtr->nb_items) || (index < 0)) return CB_ERR;
528     if (!COMBOEX_FindItem(infoPtr, index)) return CB_ERR;
529
530     /* doing this will result in WM_DELETEITEM being issued */
531     SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, index, 0);
532
533     return infoPtr->nb_items;
534 }
535
536
537 static BOOL COMBOEX_GetItemW (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
538 {
539     INT_PTR index = cit->iItem;
540     CBE_ITEMDATA *item;
541
542     TRACE("\n");
543
544     /* if item number requested does not exist then return failure */
545     if ((index >= infoPtr->nb_items) || (index < -1)) return FALSE;
546
547     /* if the item is the edit control and there is no edit control, skip */
548     if ((index == -1) && !infoPtr->hwndEdit) return FALSE;
549
550     if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
551
552     COMBOEX_CopyItem (item, cit);
553
554     return TRUE;
555 }
556
557
558 static BOOL COMBOEX_GetItemA (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
559 {
560     COMBOBOXEXITEMW tmpcit;
561
562     TRACE("\n");
563
564     tmpcit.mask = cit->mask;
565     tmpcit.iItem = cit->iItem;
566     tmpcit.pszText = 0;
567     if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
568
569     if (cit->mask & CBEIF_TEXT)
570     {
571         if (is_textW(tmpcit.pszText) && cit->pszText)
572             WideCharToMultiByte(CP_ACP, 0, tmpcit.pszText, -1,
573                                 cit->pszText, cit->cchTextMax, NULL, NULL);
574         else if (cit->pszText) cit->pszText[0] = 0;
575         else cit->pszText = (LPSTR)tmpcit.pszText;
576     }
577
578     if (cit->mask & CBEIF_IMAGE)
579         cit->iImage = tmpcit.iImage;
580     if (cit->mask & CBEIF_SELECTEDIMAGE)
581         cit->iSelectedImage = tmpcit.iSelectedImage;
582     if (cit->mask & CBEIF_OVERLAY)
583         cit->iOverlay = tmpcit.iOverlay;
584     if (cit->mask & CBEIF_INDENT)
585         cit->iIndent = tmpcit.iIndent;
586     if (cit->mask & CBEIF_LPARAM)
587         cit->lParam = tmpcit.lParam;
588
589     return TRUE;
590 }
591
592
593 static inline BOOL COMBOEX_HasEditChanged (COMBOEX_INFO const *infoPtr)
594 {
595     return infoPtr->hwndEdit && (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
596 }
597
598
599 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW const *cit)
600 {
601     INT_PTR index;
602     CBE_ITEMDATA *item;
603     NMCOMBOBOXEXW nmcit;
604
605     TRACE("\n");
606
607     if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
608
609     /* get real index of item to insert */
610     index = cit->iItem;
611     if (index == -1) index = infoPtr->nb_items;
612     if (index > infoPtr->nb_items) return -1;
613
614     /* get zero-filled space and chain it in */
615     if(!(item = Alloc (sizeof(*item)))) return -1;
616
617     /* locate position to insert new item in */
618     if (index == infoPtr->nb_items) {
619         /* fast path for iItem = -1 */
620         item->next = infoPtr->items;
621         infoPtr->items = item;
622     }
623     else {
624         INT i = infoPtr->nb_items-1;
625         CBE_ITEMDATA *moving = infoPtr->items;
626
627         while ((i > index) && moving) {
628             moving = moving->next;
629             i--;
630         }
631         if (!moving) {
632             ERR("COMBOBOXEX item structures broken. Please report!\n");
633             Free(item);
634             return -1;
635         }
636         item->next = moving->next;
637         moving->next = item;
638     }
639
640     /* fill in our hidden item structure */
641     item->mask = cit->mask;
642     if (item->mask & CBEIF_TEXT) {
643         INT len = 0;
644
645         if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
646         if (len > 0) {
647             item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
648             if (!item->pszText) {
649                 Free(item);
650                 return -1;
651             }
652             strcpyW (item->pszText, cit->pszText);
653         }
654         else if (cit->pszText == LPSTR_TEXTCALLBACKW)
655             item->pszText = LPSTR_TEXTCALLBACKW;
656         item->cchTextMax = cit->cchTextMax;
657     }
658     if (item->mask & CBEIF_IMAGE)
659         item->iImage = cit->iImage;
660     if (item->mask & CBEIF_SELECTEDIMAGE)
661         item->iSelectedImage = cit->iSelectedImage;
662     if (item->mask & CBEIF_OVERLAY)
663         item->iOverlay = cit->iOverlay;
664     if (item->mask & CBEIF_INDENT)
665         item->iIndent = cit->iIndent;
666     if (item->mask & CBEIF_LPARAM)
667         item->lParam = cit->lParam;
668     infoPtr->nb_items++;
669
670     if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
671
672     SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING, cit->iItem, (LPARAM)item);
673
674     memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
675     nmcit.ceItem.mask=~0;
676     COMBOEX_CopyItem (item, &nmcit.ceItem);
677     COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
678
679     return index;
680
681 }
682
683
684 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA const *cit)
685 {
686     COMBOBOXEXITEMW citW;
687     LPWSTR wstr = NULL;
688     INT ret;
689
690     memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
691     if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
692         INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
693         wstr = Alloc ((len + 1)*sizeof(WCHAR));
694         if (!wstr) return -1;
695         MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
696         citW.pszText = wstr;
697     }
698     ret = COMBOEX_InsertItemW(infoPtr, &citW);
699
700     Free(wstr);
701
702     return ret;
703 }
704
705
706 static DWORD
707 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
708 {
709     DWORD dwTemp;
710
711     TRACE("(mask=x%08x, style=0x%08x)\n", mask, style);
712
713     dwTemp = infoPtr->dwExtStyle;
714
715     if (mask)
716         infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
717     else
718         infoPtr->dwExtStyle = style;
719
720     /* see if we need to change the word break proc on the edit */
721     if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC)
722         SetPathWordBreakProc(infoPtr->hwndEdit, 
723             (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) != 0);
724
725     /* test if the control's appearance has changed */
726     mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
727     if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
728         /* if state of EX_NOEDITIMAGE changes, invalidate all */
729         TRACE("EX_NOEDITIMAGE state changed to %d\n",
730               infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
731         InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
732         COMBOEX_AdjustEditPos (infoPtr);
733         if (infoPtr->hwndEdit)
734             InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
735     }
736
737     return dwTemp;
738 }
739
740
741 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
742 {
743     HIMAGELIST himlTemp = infoPtr->himl;
744
745     TRACE("\n");
746
747     infoPtr->himl = himl;
748
749     COMBOEX_ReSize (infoPtr);
750     InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
751
752     /* reposition the Edit control based on whether icon exists */
753     COMBOEX_AdjustEditPos (infoPtr);
754     return himlTemp;
755 }
756
757 static BOOL COMBOEX_SetItemW (const COMBOEX_INFO *infoPtr, const COMBOBOXEXITEMW *cit)
758 {
759     INT_PTR index = cit->iItem;
760     CBE_ITEMDATA *item;
761
762     if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
763
764     /* if item number requested does not exist then return failure */
765     if ((index >= infoPtr->nb_items) || (index < -1)) return FALSE;
766
767     /* if the item is the edit control and there is no edit control, skip */
768     if ((index == -1) && !infoPtr->hwndEdit) return FALSE;
769
770     if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
771
772     /* add/change stuff to the internal item structure */
773     item->mask |= cit->mask;
774     if (cit->mask & CBEIF_TEXT) {
775         INT len = 0;
776
777         COMBOEX_FreeText(item);
778         if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
779         if (len > 0) {
780             item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
781             if (!item->pszText) return FALSE;
782             strcpyW(item->pszText, cit->pszText);
783         } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
784             item->pszText = LPSTR_TEXTCALLBACKW;
785         item->cchTextMax = cit->cchTextMax;
786     }
787     if (cit->mask & CBEIF_IMAGE)
788         item->iImage = cit->iImage;
789     if (cit->mask & CBEIF_SELECTEDIMAGE)
790         item->iSelectedImage = cit->iSelectedImage;
791     if (cit->mask & CBEIF_OVERLAY)
792         item->iOverlay = cit->iOverlay;
793     if (cit->mask & CBEIF_INDENT)
794         item->iIndent = cit->iIndent;
795     if (cit->mask & CBEIF_LPARAM)
796         item->lParam = cit->lParam;
797
798     if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
799
800     /* if original request was to update edit control, do some fast foot work */
801     if (cit->iItem == -1 && cit->mask & CBEIF_TEXT) {
802         COMBOEX_SetEditText (infoPtr, item);
803         RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
804     }
805     return TRUE;
806 }
807
808 static BOOL COMBOEX_SetItemA (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA const *cit)
809 {
810     COMBOBOXEXITEMW citW;
811     LPWSTR wstr = NULL;
812     BOOL ret;
813
814     memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
815     if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
816         INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
817         wstr = Alloc ((len + 1)*sizeof(WCHAR));
818         if (!wstr) return FALSE;
819         MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
820         citW.pszText = wstr;
821     }
822     ret = COMBOEX_SetItemW(infoPtr, &citW);
823
824     Free(wstr);
825
826     return ret;
827 }
828
829
830 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
831 {
832     BOOL bTemp = infoPtr->unicode;
833
834     TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
835
836     infoPtr->unicode = value;
837
838     return bTemp;
839 }
840
841
842 /* ***  CB_xxx message support  *** */
843
844 static INT
845 COMBOEX_FindStringExact (const COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
846 {
847     INT i;
848     cmp_func_t cmptext = get_cmp_func(infoPtr);
849     INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
850
851     /* now search from after starting loc and wrapping back to start */
852     for(i=start+1; i<count; i++) {
853         CBE_ITEMDATA *item = get_item_data(infoPtr, i);
854         if ((LRESULT)item == CB_ERR) continue;
855         if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
856     }
857     for(i=0; i<=start; i++) {
858         CBE_ITEMDATA *item = get_item_data(infoPtr, i);
859         if ((LRESULT)item == CB_ERR) continue;
860         if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
861     }
862     return CB_ERR;
863 }
864
865
866 static DWORD_PTR COMBOEX_GetItemData (const COMBOEX_INFO *infoPtr, INT_PTR index)
867 {
868     CBE_ITEMDATA const *item1;
869     CBE_ITEMDATA const *item2;
870     DWORD_PTR ret = 0;
871
872     item1 = get_item_data(infoPtr, index);
873     if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
874         item2 = COMBOEX_FindItem (infoPtr, index);
875         if (item2 != item1) {
876             ERR("data structures damaged!\n");
877             return CB_ERR;
878         }
879         if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
880         TRACE("returning 0x%08lx\n", ret);
881     } else {
882         ret = (DWORD_PTR)item1;
883         TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
884     }
885     return ret;
886 }
887
888
889 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT_PTR index)
890 {
891     CBE_ITEMDATA *item;
892     INT sel;
893
894     if (!(item = COMBOEX_FindItem(infoPtr, index)))
895         return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
896
897     TRACE("selecting item %ld text=%s\n", index, debugstr_txt(item->pszText));
898     infoPtr->selected = index;
899
900     sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
901     COMBOEX_SetEditText (infoPtr, item);
902     return sel;
903 }
904
905
906 static DWORD_PTR COMBOEX_SetItemData (const COMBOEX_INFO *infoPtr, INT_PTR index, DWORD_PTR data)
907 {
908     CBE_ITEMDATA *item1;
909     CBE_ITEMDATA const *item2;
910
911     item1 = get_item_data(infoPtr, index);
912     if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
913         item2 = COMBOEX_FindItem (infoPtr, index);
914         if (item2 != item1) {
915             ERR("data structures damaged!\n");
916             return CB_ERR;
917         }
918         item1->mask |= CBEIF_LPARAM;
919         item1->lParam = data;
920         TRACE("setting lparam to 0x%08lx\n", data);
921         return 0;
922     }
923     TRACE("non-valid result from combo %p\n", item1);
924     return (DWORD_PTR)item1;
925 }
926
927
928 static INT COMBOEX_SetItemHeight (COMBOEX_INFO const *infoPtr, INT index, UINT height)
929 {
930     RECT cb_wrect, cbx_wrect, cbx_crect;
931
932     /* First, lets forward the message to the normal combo control
933        just like Windows.     */
934     if (infoPtr->hwndCombo)
935        if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
936                          index, height) == CB_ERR) return CB_ERR;
937
938     GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
939     GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
940     GetClientRect (infoPtr->hwndSelf, &cbx_crect);
941     /* the height of comboex as height of the combo + comboex border */
942     height = cb_wrect.bottom-cb_wrect.top
943              + cbx_wrect.bottom-cbx_wrect.top
944              - (cbx_crect.bottom-cbx_crect.top);
945     TRACE("EX window=(%s), client=(%s)\n",
946           wine_dbgstr_rect(&cbx_wrect), wine_dbgstr_rect(&cbx_crect));
947     TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
948           wine_dbgstr_rect(&cbx_wrect), cbx_wrect.right-cbx_wrect.left, height);
949     SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
950                   cbx_wrect.right-cbx_wrect.left, height,
951                   SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
952
953     return 0;
954 }
955
956
957 /* ***  WM_xxx message support  *** */
958
959
960 static LRESULT COMBOEX_Create (HWND hwnd, CREATESTRUCTA const *cs)
961 {
962     static const WCHAR NIL[] = { 0 };
963     COMBOEX_INFO *infoPtr;
964     LOGFONTW mylogfont;
965     RECT win_rect;
966     INT i;
967
968     /* allocate memory for info structure */
969     infoPtr = Alloc (sizeof(COMBOEX_INFO));
970     if (!infoPtr) return -1;
971
972     /* initialize info structure */
973     /* note that infoPtr is allocated zero-filled */
974
975     infoPtr->hwndSelf = hwnd;
976     infoPtr->selected = -1;
977
978     infoPtr->unicode = IsWindowUnicode (hwnd);
979     infoPtr->hwndNotify = cs->hwndParent;
980
981     i = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
982     if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
983         WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
984         i = NFR_ANSI;
985     }
986     infoPtr->NtfUnicode = (i == NFR_UNICODE);
987
988     SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
989
990     if (TRACE_ON(comboex)) {
991         RECT client, rect;
992         GetWindowRect(hwnd, &rect);
993         GetClientRect(hwnd, &client);
994         TRACE("EX window=(%s), client=(%s)\n",
995                 wine_dbgstr_rect(&rect), wine_dbgstr_rect(&client));
996     }
997
998     /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
999     /* specified. It then creates it's own version of the EDIT control  */
1000     /* and makes the ComboBox the parent. This is because a normal      */
1001     /* DROPDOWNLIST does not have an EDIT control, but we need one.     */
1002     /* We also need to place the edit control at the proper location    */
1003     /* (allow space for the icons).                                     */
1004
1005     infoPtr->hwndCombo = CreateWindowW (WC_COMBOBOXW, NIL,
1006                          /* following line added to match native */
1007                          WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1008                          CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1009                          /* was base and is necessary */
1010                          WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
1011                          GetWindowLongW (hwnd, GWL_STYLE),
1012                          cs->y, cs->x, cs->cx, cs->cy, hwnd,
1013                          (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
1014                          (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
1015
1016     /*
1017      * native does the following at this point according to trace:
1018      *  GetWindowThreadProcessId(hwndCombo,0)
1019      *  GetCurrentThreadId()
1020      *  GetWindowThreadProcessId(hwndCombo, &???)
1021      *  GetCurrentProcessId()
1022      */
1023
1024     SetWindowSubclass(infoPtr->hwndCombo, COMBOEX_ComboWndProc, COMBO_SUBCLASSID,
1025                       (DWORD_PTR)hwnd);
1026     infoPtr->font = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1027
1028     /*
1029      * Now create our own EDIT control so we can position it.
1030      * It is created only for CBS_DROPDOWN style
1031      */
1032     if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1033         infoPtr->hwndEdit = CreateWindowExW (0, WC_EDITW, NIL,
1034                     WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1035                     0, 0, 0, 0,  /* will set later */
1036                     infoPtr->hwndCombo,
1037                     (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
1038                     (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
1039
1040         /* native does the following at this point according to trace:
1041          *  GetWindowThreadProcessId(hwndEdit,0)
1042          *  GetCurrentThreadId()
1043          *  GetWindowThreadProcessId(hwndEdit, &???)
1044          *  GetCurrentProcessId()
1045          */
1046         SetWindowSubclass(infoPtr->hwndEdit, COMBOEX_EditWndProc, EDIT_SUBCLASSID,
1047                           (DWORD_PTR)hwnd);
1048
1049         infoPtr->font = (HFONT)SendMessageW(infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1050     }
1051
1052     /*
1053      * Locate the default font if necessary and then set it in
1054      * all associated controls
1055      */
1056     if (!infoPtr->font) {
1057         SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1058                                &mylogfont, 0);
1059         infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1060     }
1061     SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1062     if (infoPtr->hwndEdit) {
1063         SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1064        SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, EC_USEFONTINFO, 0);
1065     }
1066
1067     COMBOEX_ReSize (infoPtr);
1068
1069     /* Above is fairly certain, below is much less certain. */
1070
1071     GetWindowRect(hwnd, &win_rect);
1072
1073     if (TRACE_ON(comboex)) {
1074         RECT client, rect;
1075         GetClientRect(hwnd, &client);
1076         GetWindowRect(infoPtr->hwndCombo, &rect);
1077         TRACE("EX window=(%s) client=(%s) CB wnd=(%s)\n",
1078                 wine_dbgstr_rect(&win_rect), wine_dbgstr_rect(&client),
1079                 wine_dbgstr_rect(&rect));
1080     }
1081     SetWindowPos(infoPtr->hwndCombo, HWND_TOP, 0, 0,
1082                  win_rect.right - win_rect.left, win_rect.bottom - win_rect.top,
1083                  SWP_NOACTIVATE | SWP_NOREDRAW);
1084
1085     GetWindowRect(infoPtr->hwndCombo, &win_rect);
1086     TRACE("CB window=(%s)\n", wine_dbgstr_rect(&win_rect));
1087     SetWindowPos(hwnd, HWND_TOP, 0, 0,
1088                  win_rect.right - win_rect.left, win_rect.bottom - win_rect.top,
1089                  SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1090
1091     COMBOEX_AdjustEditPos (infoPtr);
1092
1093     /*
1094      * Create an item structure to represent the data in the
1095      * EDIT control. It is allocated zero-filled.
1096      */
1097     infoPtr->edit = Alloc (sizeof (CBE_ITEMDATA));
1098     if (!infoPtr->edit) {
1099         COMBOEX_Destroy(infoPtr);
1100         return -1;
1101     }
1102
1103     return 0;
1104 }
1105
1106
1107 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam)
1108 {
1109     LRESULT lret;
1110     INT command = HIWORD(wParam);
1111     CBE_ITEMDATA *item = 0;
1112     WCHAR wintext[520];
1113     INT cursel, n;
1114     INT_PTR oldItem;
1115     NMCBEENDEDITW cbeend;
1116     DWORD oldflags;
1117     HWND parent = infoPtr->hwndNotify;
1118
1119     TRACE("for command %d\n", command);
1120
1121     switch (command)
1122     {
1123     case CBN_DROPDOWN:
1124         SetFocus (infoPtr->hwndCombo);
1125         ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1126         infoPtr->flags |= WCBE_ACTEDIT;
1127         return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1128     case CBN_CLOSEUP:
1129         SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1130         /*
1131          * from native trace of first dropdown after typing in URL in IE4
1132          *  CB_GETCURSEL(Combo)
1133          *  GetWindowText(Edit)
1134          *  CB_GETCURSEL(Combo)
1135          *  CB_GETCOUNT(Combo)
1136          *  CB_GETITEMDATA(Combo, n)
1137          *  WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1138          *  CB_GETCURSEL(Combo)
1139          *  CB_SETCURSEL(COMBOEX, n)
1140          *  SetFocus(Combo)
1141          * the rest is supposition
1142          */
1143         ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1144         InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1145         if (infoPtr->hwndEdit) InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1146         cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1147         if (cursel == -1) {
1148             cmp_func_t cmptext = get_cmp_func(infoPtr);
1149             /* find match from edit against those in Combobox */
1150             GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1151             n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1152             for (cursel = 0; cursel < n; cursel++){
1153                 item = get_item_data(infoPtr, cursel);
1154                 if ((INT_PTR)item == CB_ERR) break;
1155                 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1156             }
1157             if ((cursel == n) || ((INT_PTR)item == CB_ERR)) {
1158                 TRACE("failed to find match??? item=%p cursel=%d\n",
1159                       item, cursel);
1160                 if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1161                 return 0;
1162             }
1163         }
1164         else {
1165             item = get_item_data(infoPtr, cursel);
1166             if ((INT_PTR)item == CB_ERR) {
1167                 TRACE("failed to find match??? item=%p cursel=%d\n",
1168                       item, cursel);
1169                 if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1170                 return 0;
1171             }
1172         }
1173
1174         /* Save flags for testing and reset them */
1175         oldflags = infoPtr->flags;
1176         infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1177
1178         if (oldflags & WCBE_ACTEDIT) {
1179             cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1180             cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1181                                                  CB_GETCURSEL, 0, 0);
1182             cbeend.iWhy = CBENF_DROPDOWN;
1183
1184             if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1185         }
1186
1187         /* if selection has changed the set the new current selection */
1188         cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1189         if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1190             infoPtr->selected = cursel;
1191             SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1192             SetFocus(infoPtr->hwndCombo);
1193         }
1194         return 0;
1195
1196     case CBN_SELCHANGE:
1197         /*
1198          * CB_GETCURSEL(Combo)
1199          * CB_GETITEMDATA(Combo)   < simulated by COMBOEX_FindItem
1200          * lstrlenA
1201          * WM_SETTEXT(Edit)
1202          * WM_GETTEXTLENGTH(Edit)
1203          * WM_GETTEXT(Edit)
1204          * EM_SETSEL(Edit, 0,0)
1205          * WM_GETTEXTLENGTH(Edit)
1206          * WM_GETTEXT(Edit)
1207          * EM_SETSEL(Edit, 0,len)
1208          * return WM_COMMAND to parent
1209          */
1210         oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1211         if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1212             ERR("item %ld not found. Problem!\n", oldItem);
1213             break;
1214         }
1215         infoPtr->selected = oldItem;
1216         COMBOEX_SetEditText (infoPtr, item);
1217         return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1218
1219     case CBN_SELENDOK:
1220     case CBN_SELENDCANCEL:
1221         /*
1222          * We have to change the handle since we are the control
1223          * issuing the message. IE4 depends on this.
1224          */
1225         return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1226
1227     case CBN_KILLFOCUS:
1228         /*
1229          * from native trace:
1230          *
1231          *  pass to parent
1232          *  WM_GETTEXT(Edit, 104)
1233          *  CB_GETCURSEL(Combo) rets -1
1234          *  WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1235          *  CB_GETCURSEL(Combo)
1236          *  InvalidateRect(Combo, 0, 0)
1237          *  return 0
1238          */
1239         SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1240         if (infoPtr->flags & WCBE_ACTEDIT) {
1241             GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1242             cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1243             cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1244                                                  CB_GETCURSEL, 0, 0);
1245             cbeend.iWhy = CBENF_KILLFOCUS;
1246
1247             infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1248             if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1249         }
1250         /* possible CB_GETCURSEL */
1251         InvalidateRect (infoPtr->hwndCombo, 0, 0);
1252         return 0;
1253
1254     case CBN_SETFOCUS:
1255         return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1256
1257     default:
1258         /*
1259          * We have to change the handle since we are the control
1260          * issuing the message. IE4 depends on this.
1261          * We also need to set the focus back to the Edit control
1262          * after passing the command to the parent of the ComboEx.
1263          */
1264         lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1265         if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1266         return lret;
1267     }
1268     return 0;
1269 }
1270
1271
1272 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT const *dis)
1273 {
1274     CBE_ITEMDATA *item, *olditem;
1275     NMCOMBOBOXEXW nmcit;
1276     UINT i;
1277
1278     TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1279           dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1280
1281     if (dis->itemID >= infoPtr->nb_items) return FALSE;
1282
1283     olditem = infoPtr->items;
1284     i = infoPtr->nb_items - 1;
1285
1286     if (i == dis->itemID) {
1287         infoPtr->items = infoPtr->items->next;
1288     }
1289     else {
1290         item = olditem;
1291         i--;
1292
1293         /* find the prior item in the list */
1294         while (item->next && (i > dis->itemID)) {
1295             item = item->next;
1296             i--;
1297         }
1298         if (!item->next || (i != dis->itemID)) {
1299             ERR("COMBOBOXEX item structures broken. Please report!\n");
1300             return FALSE;
1301         }
1302         olditem = item->next;
1303         item->next = item->next->next;
1304     }
1305     infoPtr->nb_items--;
1306
1307     memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1308     nmcit.ceItem.mask=~0;
1309     COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1310     COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1311
1312     COMBOEX_FreeText(olditem);
1313     Free(olditem);
1314
1315     return TRUE;
1316 }
1317
1318
1319 static LRESULT COMBOEX_DrawItem (const COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT const *dis)
1320 {
1321     static const WCHAR nil[] = { 0 };
1322     CBE_ITEMDATA *item = 0;
1323     SIZE txtsize;
1324     RECT rect;
1325     LPCWSTR str = nil;
1326     UINT xbase, x, y;
1327     INT len;
1328     COLORREF nbkc, ntxc, bkc, txc;
1329     int drawimage, drawstate, xioff;
1330
1331     TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1332           dis->CtlType, dis->CtlID);
1333     TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1334           dis->itemID, dis->itemAction, dis->itemState);
1335     TRACE("hWnd=%p hDC=%p (%s) itemData=0x%08lx\n",
1336           dis->hwndItem, dis->hDC, wine_dbgstr_rect(&dis->rcItem), dis->itemData);
1337
1338     /* MSDN says:                                                       */
1339     /*     "itemID - Specifies the menu item identifier for a menu      */
1340     /*      item or the index of the item in a list box or combo box.   */
1341     /*      For an empty list box or combo box, this member can be -1.  */
1342     /*      This allows the application to draw only the focus          */
1343     /*      rectangle at the coordinates specified by the rcItem        */
1344     /*      member even though there are no items in the control.       */
1345     /*      This indicates to the user whether the list box or combo    */
1346     /*      box has the focus. How the bits are set in the itemAction   */
1347     /*      member determines whether the rectangle is to be drawn as   */
1348     /*      though the list box or combo box has the focus.             */
1349     if (dis->itemID == 0xffffffff) {
1350         if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1351              ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1352
1353             TRACE("drawing item -1 special focus, rect=(%s)\n",
1354                   wine_dbgstr_rect(&dis->rcItem));
1355         }
1356         else if ((dis->CtlType == ODT_COMBOBOX) &&
1357                  (dis->itemAction == ODA_DRAWENTIRE)) {
1358             /* draw of edit control data */
1359
1360             if (TRACE_ON(comboex)) {
1361                 RECT exrc, cbrc, edrc;
1362                 GetWindowRect (infoPtr->hwndSelf, &exrc);
1363                 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1364                 edrc.left = edrc.top = edrc.right = edrc.bottom = -1;
1365                 if (infoPtr->hwndEdit) GetWindowRect (infoPtr->hwndEdit, &edrc);
1366                 TRACE("window rects ex=(%s), cb=(%s), ed=(%s)\n",
1367                       wine_dbgstr_rect(&exrc), wine_dbgstr_rect(&cbrc),
1368                       wine_dbgstr_rect(&edrc));
1369             }
1370         }
1371         else {
1372             ERR("NOT drawing item  -1 special focus, rect=(%s), action=%08x, state=%08x\n",
1373                 wine_dbgstr_rect(&dis->rcItem),
1374                 dis->itemAction, dis->itemState);
1375             return 0;
1376         }
1377     }
1378
1379     /* If draw item is -1 (edit control) setup the item pointer */
1380     if (dis->itemID == 0xffffffff) {
1381         item = infoPtr->edit;
1382
1383         if (infoPtr->hwndEdit) {
1384             /* free previous text of edit item */
1385             COMBOEX_FreeText(item);
1386             item->mask &= ~CBEIF_TEXT;
1387             if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1388                 item->mask |= CBEIF_TEXT;
1389                 item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
1390                 if (item->pszText)
1391                     GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1392
1393                TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1394                      infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1395             }
1396         }
1397     }
1398
1399
1400     /* if the item pointer is not set, then get the data and locate it */
1401     if (!item) {
1402         item = get_item_data(infoPtr, dis->itemID);
1403         if (item == (CBE_ITEMDATA *)CB_ERR) {
1404             ERR("invalid item for id %d\n", dis->itemID);
1405             return 0;
1406         }
1407     }
1408
1409     if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1410
1411     xbase = CBE_STARTOFFSET;
1412     if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1413         INT indent = item->iIndent;
1414         if (indent == I_INDENTCALLBACK) {
1415             NMCOMBOBOXEXW nmce;
1416             ZeroMemory(&nmce, sizeof(nmce));
1417             nmce.ceItem.mask = CBEIF_INDENT;
1418             nmce.ceItem.lParam = item->lParam;
1419             nmce.ceItem.iItem = dis->itemID;
1420             COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1421             if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1422                 item->iIndent = nmce.ceItem.iIndent;
1423             indent = nmce.ceItem.iIndent;
1424         }
1425         xbase += (indent * CBE_INDENT);
1426     }
1427
1428     drawimage = -2;
1429     drawstate = ILD_NORMAL;
1430     if (item->mask & CBEIF_IMAGE)
1431         drawimage = item->iImage;
1432     if (dis->itemState & ODS_COMBOEXLBOX) {
1433         /* drawing listbox entry */
1434         if (dis->itemState & ODS_SELECTED) {
1435             if (item->mask & CBEIF_SELECTEDIMAGE)
1436                 drawimage = item->iSelectedImage;
1437             drawstate = ILD_SELECTED;
1438         }
1439     } else {
1440         /* drawing combo/edit entry */
1441         if (IsWindowVisible(infoPtr->hwndEdit)) {
1442             /* if we have an edit control, the slave the
1443              * selection state to the Edit focus state
1444              */
1445             if (infoPtr->flags & WCBE_EDITFOCUSED) {
1446                 if (item->mask & CBEIF_SELECTEDIMAGE)
1447                     drawimage = item->iSelectedImage;
1448                 drawstate = ILD_SELECTED;
1449             }
1450         } else {
1451             /* if we don't have an edit control, use
1452              * the requested state.
1453              */
1454             if (dis->itemState & ODS_SELECTED) {
1455                 if (item->mask & CBEIF_SELECTEDIMAGE)
1456                     drawimage = item->iSelectedImage;
1457                 drawstate = ILD_SELECTED;
1458             }
1459         }
1460     }
1461
1462     if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1463         IMAGEINFO iinfo;
1464         iinfo.rcImage.left = iinfo.rcImage.right = 0;
1465         ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1466         xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1467     }  else xioff = 0;
1468
1469     /* setup pointer to text to be drawn */
1470     str = COMBOEX_GetText(infoPtr, item);
1471     if (!str) str = nil;
1472
1473     len = strlenW (str);
1474     GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1475
1476     if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1477         int overlay = item->iOverlay;
1478
1479         if (drawimage == I_IMAGECALLBACK) {
1480             NMCOMBOBOXEXW nmce;
1481             ZeroMemory(&nmce, sizeof(nmce));
1482             nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
1483             nmce.ceItem.lParam = item->lParam;
1484             nmce.ceItem.iItem = dis->itemID;
1485             COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1486             if (drawstate == ILD_NORMAL) {
1487                 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1488                 drawimage = nmce.ceItem.iImage;
1489             } else if (drawstate == ILD_SELECTED) {
1490                 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1491                 drawimage =  nmce.ceItem.iSelectedImage;
1492             } else ERR("Bad draw state = %d\n", drawstate);
1493         }
1494
1495         if (overlay == I_IMAGECALLBACK) {
1496             NMCOMBOBOXEXW nmce;
1497             ZeroMemory(&nmce, sizeof(nmce));
1498             nmce.ceItem.mask = CBEIF_OVERLAY;
1499             nmce.ceItem.lParam = item->lParam;
1500             nmce.ceItem.iItem = dis->itemID;
1501             COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1502             if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1503                 item->iOverlay = nmce.ceItem.iOverlay;
1504             overlay = nmce.ceItem.iOverlay;
1505         }
1506
1507         if (drawimage >= 0 &&
1508             !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1509             if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1510             ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1511                             drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1512         }
1513
1514         /* now draw the text */
1515         if (!IsWindowVisible (infoPtr->hwndEdit)) {
1516             nbkc = (dis->itemState & ODS_SELECTED) ?
1517                     comctl32_color.clrHighlight : comctl32_color.clrWindow;
1518             bkc = SetBkColor (dis->hDC, nbkc);
1519             ntxc = (dis->itemState & ODS_SELECTED) ?
1520                     comctl32_color.clrHighlightText : comctl32_color.clrWindowText;
1521             txc = SetTextColor (dis->hDC, ntxc);
1522             x = xbase + xioff;
1523             y = dis->rcItem.top +
1524                 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1525             rect.left = x;
1526             rect.right = x + txtsize.cx;
1527             rect.top = dis->rcItem.top + 1;
1528             rect.bottom = dis->rcItem.bottom - 1;
1529             TRACE("drawing item %d text, rect=(%s)\n",
1530                   dis->itemID, wine_dbgstr_rect(&rect));
1531             ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1532                          &rect, str, len, 0);
1533             SetBkColor (dis->hDC, bkc);
1534             SetTextColor (dis->hDC, txc);
1535         }
1536     }
1537
1538     if (dis->itemAction & ODA_FOCUS) {
1539         rect.left = xbase + xioff - 1;
1540         rect.right = rect.left + txtsize.cx + 2;
1541         rect.top = dis->rcItem.top;
1542         rect.bottom = dis->rcItem.bottom;
1543         DrawFocusRect(dis->hDC, &rect);
1544     }
1545
1546     return 0;
1547 }
1548
1549
1550 static void COMBOEX_ResetContent (COMBOEX_INFO *infoPtr)
1551 {
1552     if (infoPtr->items)
1553     {
1554         CBE_ITEMDATA *item, *next;
1555
1556         item = infoPtr->items;
1557         while (item) {
1558             next = item->next;
1559             COMBOEX_FreeText (item);
1560             Free (item);
1561             item = next;
1562         }
1563         infoPtr->items = 0;
1564     }
1565
1566     infoPtr->selected = -1;
1567     infoPtr->nb_items = 0;
1568 }
1569
1570
1571 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1572 {
1573     if (infoPtr->hwndCombo)
1574         RemoveWindowSubclass(infoPtr->hwndCombo, COMBOEX_ComboWndProc, COMBO_SUBCLASSID);
1575
1576     if (infoPtr->hwndEdit)
1577         RemoveWindowSubclass(infoPtr->hwndEdit, COMBOEX_EditWndProc, EDIT_SUBCLASSID);
1578
1579     COMBOEX_FreeText (infoPtr->edit);
1580     Free (infoPtr->edit);
1581     infoPtr->edit = 0;
1582
1583     COMBOEX_ResetContent (infoPtr);
1584
1585     if (infoPtr->defaultFont)
1586         DeleteObject (infoPtr->defaultFont);
1587
1588     SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1589
1590     /* free comboex info data */
1591     Free (infoPtr);
1592
1593     return 0;
1594 }
1595
1596
1597 static LRESULT COMBOEX_Enable (COMBOEX_INFO *infoPtr, BOOL enable)
1598 {
1599     TRACE("hwnd=%p, enable=%s\n", infoPtr->hwndSelf, enable ? "TRUE":"FALSE");
1600
1601     if (infoPtr->hwndEdit)
1602        EnableWindow(infoPtr->hwndEdit, enable);
1603
1604     EnableWindow(infoPtr->hwndCombo, enable);
1605
1606     /* Force the control to repaint when the enabled state changes. */
1607     InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1608
1609     return 1;
1610 }
1611
1612
1613 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO const *infoPtr, MEASUREITEMSTRUCT *mis)
1614 {
1615     static const WCHAR strW[] = { 'W', 0 };
1616     SIZE mysize;
1617     HDC hdc;
1618
1619     hdc = GetDC (0);
1620     GetTextExtentPointW (hdc, strW, 1, &mysize);
1621     ReleaseDC (0, hdc);
1622     mis->itemHeight = mysize.cy + CBE_EXTRA;
1623
1624     TRACE("adjusted height hwnd=%p, height=%d\n",
1625           infoPtr->hwndSelf, mis->itemHeight);
1626
1627     return 0;
1628 }
1629
1630
1631 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1632 {
1633     /* WARNING: The COMBOEX_INFO structure is not yet created */
1634     DWORD oldstyle, newstyle;
1635
1636     oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1637     newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL | WS_BORDER);
1638     if (newstyle != oldstyle) {
1639         TRACE("req style %08x, resetting style %08x\n",
1640               oldstyle, newstyle);
1641         SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1642     }
1643     return 1;
1644 }
1645
1646
1647 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1648 {
1649     if (lParam == NF_REQUERY) {
1650         INT i = SendMessageW(infoPtr->hwndNotify,
1651                          WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1652         infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1653     }
1654     return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1655 }
1656
1657
1658 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1659 {
1660     TRACE("(width=%d, height=%d)\n", width, height);
1661
1662     MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1663
1664     COMBOEX_AdjustEditPos (infoPtr);
1665
1666     return 0;
1667 }
1668
1669
1670 static LRESULT COMBOEX_SetRedraw(const COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1671 {
1672     LRESULT ret = DefWindowProcW( infoPtr->hwndSelf, WM_SETREDRAW, wParam, lParam );
1673     if (wParam) RedrawWindow( infoPtr->hwndSelf, NULL, 0, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN );
1674     return ret;
1675 }
1676
1677
1678 static LRESULT COMBOEX_WindowPosChanging (const COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1679 {
1680     RECT cbx_wrect, cbx_crect, cb_wrect;
1681     INT width, height;
1682
1683     GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1684     GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1685     GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1686
1687     /* width is winpos value + border width of comboex */
1688     width = wp->cx
1689             + (cbx_wrect.right-cbx_wrect.left)
1690             - (cbx_crect.right-cbx_crect.left);
1691
1692     TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1693           wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1694     TRACE("EX window=(%s), client=(%s)\n",
1695           wine_dbgstr_rect(&cbx_wrect), wine_dbgstr_rect(&cbx_crect));
1696     TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
1697           wine_dbgstr_rect(&cbx_wrect), width, cb_wrect.bottom-cb_wrect.top);
1698
1699     if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1700                              width,
1701                              cb_wrect.bottom-cb_wrect.top,
1702                              SWP_NOACTIVATE);
1703
1704     GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1705
1706     /* height is combo window height plus border width of comboex */
1707     height =   (cb_wrect.bottom-cb_wrect.top)
1708              + (cbx_wrect.bottom-cbx_wrect.top)
1709              - (cbx_crect.bottom-cbx_crect.top);
1710     wp->cy = height;
1711     if (infoPtr->hwndEdit) {
1712         COMBOEX_AdjustEditPos (infoPtr);
1713         InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1714     }
1715
1716     return 0;
1717 }
1718
1719 static LRESULT CALLBACK
1720 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
1721                      UINT_PTR uId, DWORD_PTR ref_data)
1722 {
1723     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr ((HWND)ref_data);
1724     NMCBEENDEDITW cbeend;
1725     WCHAR edit_text[260];
1726     COLORREF obkc;
1727     HDC hDC;
1728     RECT rect;
1729     LRESULT lret;
1730
1731     TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1732           hwnd, uMsg, wParam, lParam, infoPtr);
1733
1734     if (!infoPtr) return 0;
1735
1736     switch (uMsg)
1737     {
1738
1739         case WM_CHAR:
1740             /* handle (ignore) the return character */
1741             if (wParam == VK_RETURN) return 0;
1742             /* all other characters pass into the real Edit */
1743             return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1744
1745         case WM_ERASEBKGND:
1746             /*
1747              * The following was determined by traces of the native
1748              */
1749             hDC = (HDC) wParam;
1750             obkc = SetBkColor (hDC, comctl32_color.clrWindow);
1751             GetClientRect (hwnd, &rect);
1752             TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect));
1753             ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1754             SetBkColor (hDC, obkc);
1755             return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1756
1757         case WM_KEYDOWN: {
1758             INT_PTR oldItem, selected;
1759             CBE_ITEMDATA *item;
1760
1761             switch ((INT)wParam)
1762             {
1763             case VK_ESCAPE:
1764                 /* native version seems to do following for COMBOEX */
1765                 /*
1766                  *   GetWindowTextW(Edit,&?, 0x104)             x
1767                  *   CB_GETCURSEL to Combo rets -1              x
1768                  *   WM_NOTIFY to COMBOEX parent (rebar)        x
1769                  *     (CBEN_ENDEDIT{A|W}
1770                  *      fChanged = FALSE                        x
1771                  *      inewSelection = -1                      x
1772                  *      txt="www.hoho"                          x
1773                  *      iWhy = 3                                x
1774                  *   CB_GETCURSEL to Combo rets -1              x
1775                  *   InvalidateRect(Combo, 0)                   x
1776                  *   WM_SETTEXT to Edit                         x
1777                  *   EM_SETSEL to Edit (0,0)                    x
1778                  *   EM_SETSEL to Edit (0,-1)                   x
1779                  *   RedrawWindow(Combo, 0, 0, 5)               x
1780                  */
1781                 TRACE("special code for VK_ESCAPE\n");
1782
1783                 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1784
1785                 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1786                 cbeend.fChanged = FALSE;
1787                 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1788                                                      CB_GETCURSEL, 0, 0);
1789                 cbeend.iWhy = CBENF_ESCAPE;
1790
1791                 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1792                 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1793                 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1794                 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1795                     ERR("item %ld not found. Problem!\n", oldItem);
1796                     break;
1797                 }
1798                 infoPtr->selected = oldItem;
1799                 COMBOEX_SetEditText (infoPtr, item);
1800                 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1801                               RDW_INVALIDATE);
1802                 break;
1803
1804             case VK_RETURN:
1805                 /* native version seems to do following for COMBOEX */
1806                 /*
1807                  *   GetWindowTextW(Edit,&?, 0x104)             x
1808                  *   CB_GETCURSEL to Combo  rets -1             x
1809                  *   CB_GETCOUNT to Combo  rets 0
1810                  *   if >0 loop
1811                  *       CB_GETITEMDATA to match
1812                  * *** above 3 lines simulated by FindItem      x
1813                  *   WM_NOTIFY to COMBOEX parent (rebar)        x
1814                  *     (CBEN_ENDEDIT{A|W}                       x
1815                  *        fChanged = TRUE (-1)                  x
1816                  *        iNewSelection = -1 or selected        x
1817                  *        txt=                                  x
1818                  *        iWhy = 2 (CBENF_RETURN)               x
1819                  *   CB_GETCURSEL to Combo  rets -1             x
1820                  *   if -1 send CB_SETCURSEL to Combo -1        x
1821                  *   InvalidateRect(Combo, 0, 0)                x
1822                  *   SetFocus(Edit)                             x
1823                  *   CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1824                  */
1825
1826                 TRACE("special code for VK_RETURN\n");
1827
1828                 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1829
1830                 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1831                 selected = SendMessageW (infoPtr->hwndCombo,
1832                                          CB_GETCURSEL, 0, 0);
1833
1834                 if (selected != -1) {
1835                     cmp_func_t cmptext = get_cmp_func(infoPtr);
1836                     item = COMBOEX_FindItem (infoPtr, selected);
1837                     TRACE("handling VK_RETURN, selected = %ld, selected_text=%s\n",
1838                           selected, debugstr_txt(item->pszText));
1839                     TRACE("handling VK_RETURN, edittext=%s\n",
1840                           debugstr_w(edit_text));
1841                     if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1842                         /* strings not equal -- indicate edit has changed */
1843                         selected = -1;
1844                     }
1845                 }
1846
1847                 cbeend.iNewSelection = selected;
1848                 cbeend.fChanged = TRUE;
1849                 cbeend.iWhy = CBENF_RETURN;
1850                 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1851                     /* abort the change, restore previous */
1852                     TRACE("Notify requested abort of change\n");
1853                     COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1854                     RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1855                                   RDW_INVALIDATE);
1856                     return 0;
1857                 }
1858                 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1859                 if (oldItem != -1) {
1860                     /* if something is selected, then deselect it */
1861                     SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, -1, 0);
1862                 }
1863                 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1864                 SetFocus(infoPtr->hwndEdit);
1865                 break;
1866
1867             case VK_UP:
1868             case VK_DOWN:
1869             {
1870                 INT step = wParam == VK_DOWN ? 1 : -1;
1871
1872                 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1873                 if (oldItem >= 0 && oldItem + step >= 0)
1874                     SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1875                 return 0;
1876             }
1877             default:
1878                 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1879             }
1880             return 0;
1881             }
1882
1883         case WM_SETFOCUS:
1884             /* remember the focus to set state of icon */
1885             lret = DefSubclassProc(hwnd, uMsg, wParam, lParam);
1886             infoPtr->flags |= WCBE_EDITFOCUSED;
1887             return lret;
1888
1889         case WM_KILLFOCUS:
1890             /*
1891              * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1892              */
1893             infoPtr->flags &= ~WCBE_EDITFOCUSED;
1894             if (infoPtr->flags & WCBE_ACTEDIT) {
1895                 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1896
1897                 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1898                 cbeend.fChanged = FALSE;
1899                 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1900                                                      CB_GETCURSEL, 0, 0);
1901                 cbeend.iWhy = CBENF_KILLFOCUS;
1902
1903                 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1904             }
1905             /* fall through */
1906
1907         default:
1908             return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1909     }
1910 }
1911
1912
1913 static LRESULT CALLBACK
1914 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
1915                       UINT_PTR uId, DWORD_PTR ref_data)
1916 {
1917     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr ((HWND)ref_data);
1918     NMCBEENDEDITW cbeend;
1919     NMMOUSE nmmse;
1920     COLORREF obkc;
1921     HDC hDC;
1922     HWND focusedhwnd;
1923     RECT rect;
1924     POINT pt;
1925     WCHAR edit_text[260];
1926
1927     TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1928           hwnd, uMsg, wParam, lParam, infoPtr);
1929
1930     if (!infoPtr) return 0;
1931
1932     switch (uMsg)
1933     {
1934
1935     case WM_DRAWITEM:
1936             /*
1937              * The only way this message should come is from the
1938              * child Listbox issuing the message. Flag this so
1939              * that ComboEx knows this is listbox.
1940              */
1941             ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1942             return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1943
1944     case WM_ERASEBKGND:
1945             /*
1946              * The following was determined by traces of the native
1947              */
1948             hDC = (HDC) wParam;
1949             obkc = SetBkColor (hDC, comctl32_color.clrWindow);
1950             GetClientRect (hwnd, &rect);
1951             TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect));
1952             ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1953             SetBkColor (hDC, obkc);
1954             return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1955
1956     case WM_SETCURSOR:
1957             /*
1958              *  WM_NOTIFY to comboex parent (rebar)
1959              *   with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1960              *  CallWindowProc (previous)
1961              */
1962             nmmse.dwItemSpec = 0;
1963             nmmse.dwItemData = 0;
1964             nmmse.pt.x = 0;
1965             nmmse.pt.y = 0;
1966             nmmse.dwHitInfo = lParam;
1967             COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1968             return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1969
1970     case WM_LBUTTONDOWN:
1971             GetClientRect (hwnd, &rect);
1972             rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1973                                                   CB_GETITEMHEIGHT, -1, 0);
1974             rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
1975             pt.x = (short)LOWORD(lParam);
1976             pt.y = (short)HIWORD(lParam);
1977             if (PtInRect(&rect, pt))
1978                 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1979
1980             infoPtr->flags |= WCBE_MOUSECAPTURED;
1981             SetCapture(hwnd);
1982             break;
1983
1984     case WM_LBUTTONUP:
1985             if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1986                 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1987
1988             ReleaseCapture();
1989             infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1990             if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1991                 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1992             } else {
1993                 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1994             }
1995             break;
1996
1997     case WM_MOUSEMOVE:
1998             if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1999                 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
2000                 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2001                 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
2002                 infoPtr->flags |= WCBE_MOUSEDRAGGED;
2003             }
2004             return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2005
2006     case WM_COMMAND:
2007             switch (HIWORD(wParam)) {
2008
2009             case EN_UPDATE:
2010                 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2011                  * on the EN_UPDATE
2012                  */
2013                 return 0;
2014
2015             case EN_KILLFOCUS:
2016                 /*
2017                  * Native does:
2018                  *
2019                  *  GetFocus() retns AA
2020                  *  GetWindowTextW(Edit)
2021                  *  CB_GETCURSEL(Combo) (got -1)
2022                  *  WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2023                  *  CB_GETCURSEL(Combo) (got -1)
2024                  *  InvalidateRect(Combo, 0, 0)
2025                  *  WM_KILLFOCUS(Combo, AA)
2026                  *  return 0;
2027                  */
2028                 focusedhwnd = GetFocus();
2029                 if (infoPtr->flags & WCBE_ACTEDIT) {
2030                     GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2031                     cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2032                     cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2033                                                          CB_GETCURSEL, 0, 0);
2034                     cbeend.iWhy = CBENF_KILLFOCUS;
2035
2036                     infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2037                     if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
2038                 }
2039                 /* possible CB_GETCURSEL */
2040                 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2041                 if (focusedhwnd)
2042                     SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2043                                   (WPARAM)focusedhwnd, 0);
2044                 return 0;
2045
2046             case EN_SETFOCUS: {
2047                 /*
2048                  * For EN_SETFOCUS this issues the same calls and messages
2049                  *  as the native seems to do.
2050                  *
2051                  * for some cases however native does the following:
2052                  *   (noticed after SetFocus during LBUTTONDOWN on
2053                  *    on dropdown arrow)
2054                  *  WM_GETTEXTLENGTH (Edit);
2055                  *  WM_GETTEXT (Edit, len+1, str);
2056                  *  EM_SETSEL (Edit, 0, 0);
2057                  *  WM_GETTEXTLENGTH (Edit);
2058                  *  WM_GETTEXT (Edit, len+1, str);
2059                  *  EM_SETSEL (Edit, 0, len);
2060                  *  WM_NOTIFY (parent, CBEN_BEGINEDIT)
2061                  */
2062                 NMHDR hdr;
2063
2064                 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2065                 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2066                 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2067                 infoPtr->flags |= WCBE_ACTEDIT;
2068                 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2069                 return 0;
2070                 }
2071
2072             case EN_CHANGE: {
2073                 /*
2074                  * For EN_CHANGE this issues the same calls and messages
2075                  *  as the native seems to do.
2076                  */
2077                 LPCWSTR lastwrk;
2078                 cmp_func_t cmptext = get_cmp_func(infoPtr);
2079
2080                 INT_PTR selected = SendMessageW (infoPtr->hwndCombo,
2081                                                  CB_GETCURSEL, 0, 0);
2082
2083                 /* lstrlenW( lastworkingURL ) */
2084
2085                 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2086                 if (selected == -1) {
2087                     lastwrk = infoPtr->edit->pszText;
2088                 }
2089                 else {
2090                     CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2091                     lastwrk = COMBOEX_GetText(infoPtr, item);
2092                 }
2093
2094                 TRACE("handling EN_CHANGE, selected = %ld, selected_text=%s\n",
2095                       selected, debugstr_w(lastwrk));
2096                 TRACE("handling EN_CHANGE, edittext=%s\n",
2097                       debugstr_w(edit_text));
2098
2099                 /* cmptext is between lastworkingURL and GetWindowText */
2100                 if (cmptext (lastwrk, edit_text)) {
2101                     /* strings not equal -- indicate edit has changed */
2102                     infoPtr->flags |= WCBE_EDITCHG;
2103                 }
2104                 SendMessageW ( infoPtr->hwndNotify, WM_COMMAND,
2105                                MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2106                                           CBN_EDITCHANGE),
2107                                (LPARAM)infoPtr->hwndSelf);
2108                 return 0;
2109                 }
2110
2111             case LBN_SELCHANGE:
2112                 /*
2113                  * Therefore from traces there is no additional code here
2114                  */
2115
2116                 /*
2117                  * Using native COMCTL32 gets the following:
2118                  *  1 == SHDOCVW.DLL  issues call/message
2119                  *  2 == COMCTL32.DLL  issues call/message
2120                  *  3 == WINE  issues call/message
2121                  *
2122                  *
2123                  * for LBN_SELCHANGE:
2124                  *    1  CB_GETCURSEL(ComboEx)
2125                  *    1  CB_GETDROPPEDSTATE(ComboEx)
2126                  *    1  CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2127                  *    2  CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2128                  **   call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2129                  *    3  WM_COMMAND(ComboEx, CBN_SELENDOK)
2130                  *      WM_USER+49(ComboLB, 1,0)  <=============!!!!!!!!!!!
2131                  *    3  ShowWindow(ComboLB, SW_HIDE)
2132                  *    3  RedrawWindow(Combo,  RDW_UPDATENOW)
2133                  *    3  WM_COMMAND(ComboEX, CBN_CLOSEUP)
2134                  **   end of CBRollUp
2135                  *    3  WM_COMMAND(ComboEx, CBN_SELCHANGE)  (echo to parent)
2136                  *    ?  LB_GETCURSEL              <==|
2137                  *    ?  LB_GETTEXTLEN                |
2138                  *    ?  LB_GETTEXT                   | Needs to be added to
2139                  *    ?  WM_CTLCOLOREDIT(ComboEx)     | Combo processing
2140                  *    ?  LB_GETITEMDATA               |
2141                  *    ?  WM_DRAWITEM(ComboEx)      <==|
2142                  */
2143             default:
2144                 break;
2145             }/* fall through */
2146     default:
2147             return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2148     }
2149     return 0;
2150 }
2151
2152
2153 static LRESULT WINAPI
2154 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2155 {
2156     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2157
2158     TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2159
2160     if (!infoPtr) {
2161         if (uMsg == WM_CREATE)
2162             return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2163         if (uMsg == WM_NCCREATE)
2164             COMBOEX_NCCreate (hwnd);
2165         return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2166     }
2167
2168     switch (uMsg)
2169     {
2170         case CBEM_DELETEITEM:
2171             return COMBOEX_DeleteItem (infoPtr, wParam);
2172
2173         case CBEM_GETCOMBOCONTROL:
2174             return (LRESULT)infoPtr->hwndCombo;
2175
2176         case CBEM_GETEDITCONTROL:
2177             return (LRESULT)infoPtr->hwndEdit;
2178
2179         case CBEM_GETEXTENDEDSTYLE:
2180             return infoPtr->dwExtStyle;
2181
2182         case CBEM_GETIMAGELIST:
2183             return (LRESULT)infoPtr->himl;
2184
2185         case CBEM_GETITEMA:
2186             return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2187
2188         case CBEM_GETITEMW:
2189             return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2190
2191         case CBEM_GETUNICODEFORMAT:
2192             return infoPtr->unicode;
2193
2194         case CBEM_HASEDITCHANGED:
2195             return COMBOEX_HasEditChanged (infoPtr);
2196
2197         case CBEM_INSERTITEMA:
2198             return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2199
2200         case CBEM_INSERTITEMW:
2201             return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2202
2203         case CBEM_SETEXSTYLE:
2204         case CBEM_SETEXTENDEDSTYLE:
2205             return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2206
2207         case CBEM_SETIMAGELIST:
2208             return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2209
2210         case CBEM_SETITEMA:
2211             return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2212
2213         case CBEM_SETITEMW:
2214             return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2215
2216         case CBEM_SETUNICODEFORMAT:
2217             return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2218
2219         /*case CBEM_SETWINDOWTHEME:
2220             FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2221
2222         case WM_SETTEXT:
2223         case WM_GETTEXT:
2224         case WM_GETTEXTLENGTH:
2225             return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2226
2227         case CB_GETLBTEXT:
2228             return COMBOEX_GetListboxText(infoPtr, wParam, (LPWSTR)lParam);
2229
2230         case CB_GETLBTEXTLEN:
2231             return COMBOEX_GetListboxText(infoPtr, wParam, NULL);
2232
2233         case CB_RESETCONTENT:
2234             COMBOEX_ResetContent(infoPtr);
2235             /* fall through */
2236
2237 /*   Combo messages we are not sure if we need to process or just forward */
2238         case CB_GETDROPPEDCONTROLRECT:
2239         case CB_GETITEMHEIGHT:
2240         case CB_GETEXTENDEDUI:
2241         case CB_LIMITTEXT:
2242         case CB_SELECTSTRING:
2243
2244 /*   Combo messages OK to just forward to the regular COMBO */
2245         case CB_GETCOUNT:
2246         case CB_GETCURSEL:
2247         case CB_GETDROPPEDSTATE:
2248         case CB_SETDROPPEDWIDTH:
2249         case CB_SETEXTENDEDUI:
2250         case CB_SHOWDROPDOWN:
2251             return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2252
2253 /*   Combo messages we need to process specially */
2254         case CB_FINDSTRINGEXACT:
2255             return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2256
2257         case CB_GETITEMDATA:
2258             return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2259
2260         case CB_SETCURSEL:
2261             return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2262
2263         case CB_SETITEMDATA:
2264             return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD_PTR)lParam);
2265
2266         case CB_SETITEMHEIGHT:
2267             return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2268
2269
2270
2271 /*   Window messages passed to parent */
2272         case WM_COMMAND:
2273             return COMBOEX_Command (infoPtr, wParam);
2274
2275         case WM_NOTIFY:
2276             if (infoPtr->NtfUnicode)
2277                 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
2278             else
2279                 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
2280
2281
2282 /*   Window messages we need to process */
2283         case WM_DELETEITEM:
2284             return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2285
2286         case WM_DRAWITEM:
2287             return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2288
2289         case WM_DESTROY:
2290             return COMBOEX_Destroy (infoPtr);
2291
2292         case WM_ENABLE:
2293             return COMBOEX_Enable (infoPtr, (BOOL)wParam);
2294
2295         case WM_MEASUREITEM:
2296             return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2297
2298         case WM_NOTIFYFORMAT:
2299             return COMBOEX_NotifyFormat (infoPtr, lParam);
2300
2301         case WM_SIZE:
2302             return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2303
2304         case WM_SETREDRAW:
2305             return COMBOEX_SetRedraw(infoPtr, wParam, lParam);
2306
2307         case WM_WINDOWPOSCHANGING:
2308             return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2309
2310         case WM_SETFOCUS:
2311             if (infoPtr->hwndEdit) SetFocus( infoPtr->hwndEdit );
2312             else SetFocus( infoPtr->hwndCombo );
2313             return 0;
2314
2315         case WM_SYSCOLORCHANGE:
2316             COMCTL32_RefreshSysColors();
2317             return 0;
2318
2319         default:
2320             if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2321                 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",uMsg,wParam,lParam);
2322             return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2323     }
2324 }
2325
2326
2327 void COMBOEX_Register (void)
2328 {
2329     WNDCLASSW wndClass;
2330
2331     ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2332     wndClass.style         = CS_GLOBALCLASS;
2333     wndClass.lpfnWndProc   = COMBOEX_WindowProc;
2334     wndClass.cbClsExtra    = 0;
2335     wndClass.cbWndExtra    = sizeof(COMBOEX_INFO *);
2336     wndClass.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2337     wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2338     wndClass.lpszClassName = WC_COMBOBOXEXW;
2339
2340     RegisterClassW (&wndClass);
2341 }
2342
2343
2344 void COMBOEX_Unregister (void)
2345 {
2346     UnregisterClassW (WC_COMBOBOXEXW, NULL);
2347 }