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