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