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