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