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