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