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