4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2000, 2001, 2002 Guy Albertelli <galberte@neo.lrun.com>
6 * Copyright 2002 Dimitrie O. Paun
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.
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.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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.
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.
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
48 typedef struct _CBE_ITEMDATA
50 struct _CBE_ITEMDATA *next;
62 /* ComboBoxEx structure */
66 HWND hwndSelf; /* my own hwnd */
67 HWND hwndNotify; /* my parent hwnd */
70 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
71 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
73 INT selected; /* index of selected item */
74 DWORD flags; /* WINE internal flags */
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 */
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}
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 */
95 #define ID_CB_EDIT 1001
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.
105 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
106 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
108 #define ODS_COMBOEXLBOX 0x4000
112 /* Height in pixels of control over the amount of the selected font */
115 /* Indent amount per MS documentation */
116 #define CBE_INDENT 10
118 /* Offset in pixels from left side for start of image or text */
119 #define CBE_STARTOFFSET 6
121 /* Offset between image and text */
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
129 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongPtrW (hwnd, 0))
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);
138 inline static BOOL is_textW(LPCWSTR str)
140 return str && str != LPSTR_TEXTCALLBACKW;
143 inline static BOOL is_textA(LPCSTR str)
145 return str && str != LPSTR_TEXTCALLBACKA;
148 inline static LPCSTR debugstr_txt(LPCWSTR str)
150 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
151 return debugstr_w(str);
154 static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
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));
165 static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
167 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
168 input->mask, input->iItem, input->pszText, input->cchTextMax,
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);
177 inline static CBE_ITEMDATA *get_item_data(COMBOEX_INFO *infoPtr, INT index)
179 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
183 inline static cmp_func_t get_cmp_func(COMBOEX_INFO *infoPtr)
185 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
188 static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
190 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
191 hdr->hwndFrom = infoPtr->hwndSelf;
193 if (infoPtr->NtfUnicode)
194 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
196 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
201 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
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);
207 LPWSTR wstr = hdr->ceItem.pszText;
211 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
212 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
214 astr = (LPSTR)Alloc ((len + 1)*sizeof(CHAR));
216 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
217 hdr->ceItem.pszText = (LPWSTR)astr;
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;
225 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
227 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
228 hdr->ceItem.pszText = wstr;
237 static INT COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
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);
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;
252 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
257 static void COMBOEX_NotifyDragBegin(COMBOEX_INFO *infoPtr, LPCWSTR wstr)
259 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
260 if (infoPtr->NtfUnicode) {
261 NMCBEDRAGBEGINW ndbw;
264 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
265 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
267 NMCBEDRAGBEGINA ndba;
270 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
272 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
277 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
279 if (is_textW(item->pszText)) Free(item->pszText);
286 static INT COMBOEX_GetIndex(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
288 CBE_ITEMDATA *moving;
291 moving = infoPtr->items;
292 index = infoPtr->nb_items - 1;
294 while (moving && (moving != item)) {
295 moving = moving->next;
298 if (!moving || (index < 0)) {
299 ERR("COMBOBOXEX item structures broken. Please report!\n");
306 static LPCWSTR COMBOEX_GetText(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
312 if (item->pszText != LPSTR_TEXTCALLBACKW)
313 return item->pszText;
315 ZeroMemory(&nmce, sizeof(nmce));
316 nmce.ceItem.mask = CBEIF_TEXT;
317 nmce.ceItem.lParam = item->lParam;
318 nmce.ceItem.iItem = COMBOEX_GetIndex(infoPtr, item);
319 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
321 if (is_textW(nmce.ceItem.pszText)) {
322 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
323 buf = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
325 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
326 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
327 COMBOEX_FreeText(item);
335 text = nmce.ceItem.pszText;
337 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
338 item->pszText = text;
343 static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
345 static const WCHAR strA[] = { 'A', 0 };
349 mydc = GetDC (0); /* why the entire screen???? */
350 nfont = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
351 ofont = (HFONT) SelectObject (mydc, nfont);
352 GetTextExtentPointW (mydc, strA, 1, size);
353 SelectObject (mydc, ofont);
355 TRACE("selected font hwnd=%p, height=%d\n", nfont, size->cy);
359 static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
361 if (cit->mask & CBEIF_TEXT) {
363 * when given a text buffer actually use that buffer
366 if (is_textW(item->pszText))
367 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
371 cit->pszText = item->pszText;
372 cit->cchTextMax = item->cchTextMax;
375 if (cit->mask & CBEIF_IMAGE)
376 cit->iImage = item->iImage;
377 if (cit->mask & CBEIF_SELECTEDIMAGE)
378 cit->iSelectedImage = item->iSelectedImage;
379 if (cit->mask & CBEIF_OVERLAY)
380 cit->iOverlay = item->iOverlay;
381 if (cit->mask & CBEIF_INDENT)
382 cit->iIndent = item->iIndent;
383 if (cit->mask & CBEIF_LPARAM)
384 cit->lParam = item->lParam;
388 static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
391 INT x, y, w, h, xioff;
394 if (!infoPtr->hwndEdit) return;
396 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
398 iinfo.rcImage.left = iinfo.rcImage.right = 0;
399 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
400 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
403 GetClientRect (infoPtr->hwndCombo, &rect);
404 InflateRect (&rect, -2, -2);
405 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
407 /* reposition the Edit control based on whether icon exists */
408 COMBOEX_GetComboFontSize (infoPtr, &mysize);
409 TRACE("Combo font x=%d, y=%d\n", mysize.cx, mysize.cy);
410 x = xioff + CBE_STARTOFFSET + 1;
411 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
413 y = rect.bottom - h - 1;
415 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
416 rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
417 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
418 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
422 static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
428 COMBOEX_GetComboFontSize (infoPtr, &mysize);
429 cy = mysize.cy + CBE_EXTRA;
430 if (infoPtr->himl && ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo)) {
431 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
432 TRACE("upgraded height due to image: height=%d\n", cy);
434 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)cy);
435 if (infoPtr->hwndCombo) {
436 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
437 (WPARAM) 0, (LPARAM) cy);
438 if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
440 if (GetWindowRect(infoPtr->hwndCombo, &comboRect)) {
442 if (GetWindowRect(infoPtr->hwndSelf, &ourRect)) {
443 if (comboRect.bottom > ourRect.bottom) {
444 POINT pt = { ourRect.left, ourRect.top };
445 if (ScreenToClient(infoPtr->hwndSelf, &pt))
446 MoveWindow( infoPtr->hwndSelf, pt.x, pt.y, ourRect.right - ourRect.left,
447 comboRect.bottom - comboRect.top, FALSE);
456 static void COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
458 if (!infoPtr->hwndEdit) return;
459 /* native issues the following messages to the {Edit} control */
460 /* WM_SETTEXT (0,addr) */
461 /* EM_SETSEL32 (0,0) */
462 /* EM_SETSEL32 (0,-1) */
463 if (item->mask & CBEIF_TEXT) {
464 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
465 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
466 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
471 static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
476 if ((index >= infoPtr->nb_items) || (index < -1))
479 return infoPtr->edit;
480 item = infoPtr->items;
481 i = infoPtr->nb_items - 1;
483 /* find the item in the list */
484 while (item && (i > index)) {
488 if (!item || (i != index)) {
489 ERR("COMBOBOXEX item structures broken. Please report!\n");
496 static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO *infoPtr)
498 return infoPtr->hwndEdit ? TRUE : FALSE;
502 /* *** CBEM_xxx message support *** */
504 static UINT COMBOEX_GetListboxText(COMBOEX_INFO *infoPtr, int n, LPWSTR buf)
509 item = COMBOEX_FindItem(infoPtr, n);
513 str = COMBOEX_GetText(infoPtr, item);
515 if (infoPtr->unicode)
519 return lstrlenW(str);
524 r = WideCharToMultiByte(CP_ACP, 0, str, -1, (LPSTR)buf, 0x40000000, NULL, NULL);
531 static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
535 TRACE("(index=%d)\n", index);
537 /* if item number requested does not exist then return failure */
538 if ((index >= infoPtr->nb_items) || (index < 0)) return CB_ERR;
539 if (!(item = COMBOEX_FindItem(infoPtr, index))) return CB_ERR;
541 /* doing this will result in WM_DELETEITEM being issued */
542 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
544 return infoPtr->nb_items;
548 static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
550 INT index = cit->iItem;
555 /* if item number requested does not exist then return failure */
556 if ((index >= infoPtr->nb_items) || (index < -1)) return FALSE;
558 /* if the item is the edit control and there is no edit control, skip */
559 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
561 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
563 COMBOEX_CopyItem (item, cit);
569 static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
571 COMBOBOXEXITEMW tmpcit;
575 tmpcit.mask = cit->mask;
576 tmpcit.iItem = cit->iItem;
578 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
580 if (is_textW(tmpcit.pszText) && cit->pszText)
581 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
582 cit->pszText, cit->cchTextMax, NULL, NULL);
583 else if (cit->pszText) cit->pszText[0] = 0;
584 else cit->pszText = (LPSTR)tmpcit.pszText;
586 cit->iImage = tmpcit.iImage;
587 cit->iSelectedImage = tmpcit.iSelectedImage;
588 cit->iOverlay = tmpcit.iOverlay;
589 cit->iIndent = tmpcit.iIndent;
590 cit->lParam = tmpcit.lParam;
596 inline static BOOL COMBOEX_HasEditChanged (COMBOEX_INFO *infoPtr)
598 return COMBOEX_HasEdit(infoPtr) &&
599 (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
603 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
611 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
613 /* get real index of item to insert */
615 if (index == -1) index = infoPtr->nb_items;
616 if (index > infoPtr->nb_items) return -1;
618 /* get zero-filled space and chain it in */
619 if(!(item = (CBE_ITEMDATA *)Alloc (sizeof(*item)))) return -1;
621 /* locate position to insert new item in */
622 if (index == infoPtr->nb_items) {
623 /* fast path for iItem = -1 */
624 item->next = infoPtr->items;
625 infoPtr->items = item;
628 INT i = infoPtr->nb_items-1;
629 CBE_ITEMDATA *moving = infoPtr->items;
631 while ((i > index) && moving) {
632 moving = moving->next;
636 ERR("COMBOBOXEX item structures broken. Please report!\n");
640 item->next = moving->next;
644 /* fill in our hidden item structure */
645 item->mask = cit->mask;
646 if (item->mask & CBEIF_TEXT) {
649 if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
651 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
652 if (!item->pszText) {
656 strcpyW (item->pszText, cit->pszText);
658 else if (cit->pszText == LPSTR_TEXTCALLBACKW)
659 item->pszText = LPSTR_TEXTCALLBACKW;
660 item->cchTextMax = cit->cchTextMax;
662 if (item->mask & CBEIF_IMAGE)
663 item->iImage = cit->iImage;
664 if (item->mask & CBEIF_SELECTEDIMAGE)
665 item->iSelectedImage = cit->iSelectedImage;
666 if (item->mask & CBEIF_OVERLAY)
667 item->iOverlay = cit->iOverlay;
668 if (item->mask & CBEIF_INDENT)
669 item->iIndent = cit->iIndent;
670 if (item->mask & CBEIF_LPARAM)
671 item->lParam = cit->lParam;
674 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
676 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
677 (WPARAM)cit->iItem, (LPARAM)item);
679 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
680 COMBOEX_CopyItem (item, &nmcit.ceItem);
681 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
688 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
690 COMBOBOXEXITEMW citW;
694 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
695 if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
696 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
697 wstr = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
698 if (!wstr) return -1;
699 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
702 ret = COMBOEX_InsertItemW(infoPtr, &citW);
711 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
715 TRACE("(mask=x%08x, style=0x%08x)\n", mask, style);
717 dwTemp = infoPtr->dwExtStyle;
720 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
722 infoPtr->dwExtStyle = style;
724 /* see if we need to change the word break proc on the edit */
725 if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC)
726 SetPathWordBreakProc(infoPtr->hwndEdit,
727 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ? TRUE : FALSE);
729 /* test if the control's appearance has changed */
730 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
731 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
732 /* if state of EX_NOEDITIMAGE changes, invalidate all */
733 TRACE("EX_NOEDITIMAGE state changed to %d\n",
734 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
735 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
736 COMBOEX_AdjustEditPos (infoPtr);
737 if (infoPtr->hwndEdit)
738 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
745 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
747 HIMAGELIST himlTemp = infoPtr->himl;
751 infoPtr->himl = himl;
753 COMBOEX_ReSize (infoPtr);
754 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
756 /* reposition the Edit control based on whether icon exists */
757 COMBOEX_AdjustEditPos (infoPtr);
761 static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
763 INT index = cit->iItem;
766 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
768 /* if item number requested does not exist then return failure */
769 if ((index >= infoPtr->nb_items) || (index < -1)) return FALSE;
771 /* if the item is the edit control and there is no edit control, skip */
772 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
774 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
776 /* add/change stuff to the internal item structure */
777 item->mask |= cit->mask;
778 if (cit->mask & CBEIF_TEXT) {
781 COMBOEX_FreeText(item);
782 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
784 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
785 if (!item->pszText) return FALSE;
786 strcpyW(item->pszText, cit->pszText);
787 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
788 item->pszText = LPSTR_TEXTCALLBACKW;
789 item->cchTextMax = cit->cchTextMax;
791 if (cit->mask & CBEIF_IMAGE)
792 item->iImage = cit->iImage;
793 if (cit->mask & CBEIF_SELECTEDIMAGE)
794 item->iSelectedImage = cit->iSelectedImage;
795 if (cit->mask & CBEIF_OVERLAY)
796 item->iOverlay = cit->iOverlay;
797 if (cit->mask & CBEIF_INDENT)
798 item->iIndent = cit->iIndent;
799 if (cit->mask & CBEIF_LPARAM)
800 cit->lParam = cit->lParam;
802 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
804 /* if original request was to update edit control, do some fast foot work */
805 if (cit->iItem == -1) {
806 COMBOEX_SetEditText (infoPtr, item);
807 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
812 static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
814 COMBOBOXEXITEMW citW;
818 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
819 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
820 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
821 wstr = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
822 if (!wstr) return FALSE;
823 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
826 ret = COMBOEX_SetItemW(infoPtr, &citW);
834 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
836 BOOL bTemp = infoPtr->unicode;
838 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
840 infoPtr->unicode = value;
846 /* *** CB_xxx message support *** */
849 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
852 cmp_func_t cmptext = get_cmp_func(infoPtr);
853 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
855 /* now search from after starting loc and wrapping back to start */
856 for(i=start+1; i<count; i++) {
857 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
858 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
860 for(i=0; i<=start; i++) {
861 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
862 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
868 static DWORD_PTR COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
870 CBE_ITEMDATA *item1, *item2;
873 item1 = get_item_data(infoPtr, index);
874 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
875 item2 = COMBOEX_FindItem (infoPtr, index);
876 if (item2 != item1) {
877 ERR("data structures damaged!\n");
880 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
881 TRACE("returning 0x%08lx\n", ret);
883 ret = (DWORD_PTR)item1;
884 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
890 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
895 if (!(item = COMBOEX_FindItem(infoPtr, index)))
896 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
898 TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
899 infoPtr->selected = index;
901 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
902 COMBOEX_SetEditText (infoPtr, item);
907 static DWORD_PTR COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD_PTR data)
909 CBE_ITEMDATA *item1, *item2;
911 item1 = get_item_data(infoPtr, index);
912 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
913 item2 = COMBOEX_FindItem (infoPtr, index);
914 if (item2 != item1) {
915 ERR("data structures damaged!\n");
918 item1->mask |= CBEIF_LPARAM;
919 item1->lParam = data;
920 TRACE("setting lparam to 0x%08lx\n", data);
923 TRACE("non-valid result from combo %p\n", item1);
924 return (DWORD_PTR)item1;
928 static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
930 RECT cb_wrect, cbx_wrect, cbx_crect;
932 /* First, lets forward the message to the normal combo control
933 just like Windows. */
934 if (infoPtr->hwndCombo)
935 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
936 index, height) == CB_ERR) return CB_ERR;
938 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
939 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
940 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
941 /* the height of comboex as height of the combo + comboex border */
942 height = cb_wrect.bottom-cb_wrect.top
943 + cbx_wrect.bottom-cbx_wrect.top
944 - (cbx_crect.bottom-cbx_crect.top);
945 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
946 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
947 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
948 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
949 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
950 cbx_wrect.right-cbx_wrect.left, height);
951 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
952 cbx_wrect.right-cbx_wrect.left, height,
953 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
959 /* *** WM_xxx message support *** */
962 static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
964 static const WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
965 static const WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
966 static const WCHAR NIL[] = { 0 };
967 COMBOEX_INFO *infoPtr;
969 RECT wnrc1, clrc1, cmbwrc;
972 /* allocate memory for info structure */
973 infoPtr = (COMBOEX_INFO *)Alloc (sizeof(COMBOEX_INFO));
974 if (!infoPtr) return -1;
976 /* initialize info structure */
977 /* note that infoPtr is allocated zero-filled */
979 infoPtr->hwndSelf = hwnd;
980 infoPtr->selected = -1;
982 infoPtr->unicode = IsWindowUnicode (hwnd);
983 infoPtr->hwndNotify = cs->hwndParent;
985 i = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
986 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
987 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
990 infoPtr->NtfUnicode = (i == NFR_UNICODE);
992 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
994 /* create combo box */
995 GetWindowRect(hwnd, &wnrc1);
996 GetClientRect(hwnd, &clrc1);
997 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
998 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
999 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
1001 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1002 /* specified. It then creates it's own version of the EDIT control */
1003 /* and makes the ComboBox the parent. This is because a normal */
1004 /* DROPDOWNLIST does not have an EDIT control, but we need one. */
1005 /* We also need to place the edit control at the proper location */
1006 /* (allow space for the icons). */
1008 infoPtr->hwndCombo = CreateWindowW (COMBOBOX, NIL,
1009 /* following line added to match native */
1010 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1011 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1012 /* was base and is necessary */
1013 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
1014 GetWindowLongW (hwnd, GWL_STYLE),
1015 cs->y, cs->x, cs->cx, cs->cy, hwnd,
1016 (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
1017 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
1020 * native does the following at this point according to trace:
1021 * GetWindowThreadProcessId(hwndCombo,0)
1022 * GetCurrentThreadId()
1023 * GetWindowThreadProcessId(hwndCombo, &???)
1024 * GetCurrentProcessId()
1028 * Setup a property to hold the pointer to the COMBOBOXEX
1031 SetPropW(infoPtr->hwndCombo, COMBOEX_SUBCLASS_PROP, hwnd);
1032 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hwndCombo,
1033 GWLP_WNDPROC, (DWORD_PTR)COMBOEX_ComboWndProc);
1034 infoPtr->font = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1038 * Now create our own EDIT control so we can position it.
1039 * It is created only for CBS_DROPDOWN style
1041 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1042 infoPtr->hwndEdit = CreateWindowExW (0, EDIT, NIL,
1043 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1044 0, 0, 0, 0, /* will set later */
1046 (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
1047 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
1049 /* native does the following at this point according to trace:
1050 * GetWindowThreadProcessId(hwndEdit,0)
1051 * GetCurrentThreadId()
1052 * GetWindowThreadProcessId(hwndEdit, &???)
1053 * GetCurrentProcessId()
1057 * Setup a property to hold the pointer to the COMBOBOXEX
1060 SetPropW(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
1061 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hwndEdit,
1062 GWLP_WNDPROC, (DWORD_PTR)COMBOEX_EditWndProc);
1063 infoPtr->font = (HFONT)SendMessageW(infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1067 * Locate the default font if necessary and then set it in
1068 * all associated controls
1070 if (!infoPtr->font) {
1071 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1073 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1075 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1076 if (infoPtr->hwndEdit) {
1077 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1078 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1081 COMBOEX_ReSize (infoPtr);
1083 /* Above is fairly certain, below is much less certain. */
1085 GetWindowRect(hwnd, &wnrc1);
1086 GetClientRect(hwnd, &clrc1);
1087 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1088 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1089 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1090 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1091 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1092 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1093 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1094 SWP_NOACTIVATE | SWP_NOREDRAW);
1096 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1097 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1098 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1099 SetWindowPos(hwnd, HWND_TOP,
1100 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1101 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1103 COMBOEX_AdjustEditPos (infoPtr);
1106 * Create an item structure to represent the data in the
1107 * EDIT control. It is allocated zero-filled.
1109 infoPtr->edit = (CBE_ITEMDATA *)Alloc (sizeof (CBE_ITEMDATA));
1110 if (!infoPtr->edit) {
1111 COMBOEX_Destroy(infoPtr);
1119 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1122 INT command = HIWORD(wParam);
1123 CBE_ITEMDATA *item = 0;
1125 INT cursel, n, oldItem;
1126 NMCBEENDEDITW cbeend;
1128 HWND parent = infoPtr->hwndNotify;
1130 TRACE("for command %d\n", command);
1135 SetFocus (infoPtr->hwndCombo);
1136 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1137 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1140 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1142 * from native trace of first dropdown after typing in URL in IE4
1143 * CB_GETCURSEL(Combo)
1144 * GetWindowText(Edit)
1145 * CB_GETCURSEL(Combo)
1146 * CB_GETCOUNT(Combo)
1147 * CB_GETITEMDATA(Combo, n)
1148 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1149 * CB_GETCURSEL(Combo)
1150 * CB_SETCURSEL(COMBOEX, n)
1152 * the rest is supposition
1154 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1155 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1156 InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1157 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1159 cmp_func_t cmptext = get_cmp_func(infoPtr);
1160 /* find match from edit against those in Combobox */
1161 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1162 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1163 for (cursel = 0; cursel < n; cursel++){
1164 item = get_item_data(infoPtr, cursel);
1165 if ((INT_PTR)item == CB_ERR) break;
1166 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1168 if ((cursel == n) || ((INT_PTR)item == CB_ERR)) {
1169 TRACE("failed to find match??? item=%p cursel=%d\n",
1171 if (infoPtr->hwndEdit)
1172 SetFocus(infoPtr->hwndEdit);
1177 item = get_item_data(infoPtr, cursel);
1178 if ((INT_PTR)item == CB_ERR) {
1179 TRACE("failed to find match??? item=%p cursel=%d\n",
1181 if (infoPtr->hwndEdit)
1182 SetFocus(infoPtr->hwndEdit);
1187 /* Save flags for testing and reset them */
1188 oldflags = infoPtr->flags;
1189 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1191 if (oldflags & WCBE_ACTEDIT) {
1192 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1193 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1194 CB_GETCURSEL, 0, 0);
1195 cbeend.iWhy = CBENF_DROPDOWN;
1197 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1200 /* if selection has changed the set the new current selection */
1201 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1202 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1203 infoPtr->selected = cursel;
1204 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1205 SetFocus(infoPtr->hwndCombo);
1211 * CB_GETCURSEL(Combo)
1212 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1215 * WM_GETTEXTLENGTH(Edit)
1217 * EM_SETSEL(Edit, 0,0)
1218 * WM_GETTEXTLENGTH(Edit)
1220 * EM_SETSEL(Edit, 0,len)
1221 * return WM_COMMAND to parent
1223 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1224 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1225 ERR("item %d not found. Problem!\n", oldItem);
1228 infoPtr->selected = oldItem;
1229 COMBOEX_SetEditText (infoPtr, item);
1230 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1234 * We have to change the handle since we are the control
1235 * issuing the message. IE4 depends on this.
1237 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1241 * from native trace:
1244 * WM_GETTEXT(Edit, 104)
1245 * CB_GETCURSEL(Combo) rets -1
1246 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1247 * CB_GETCURSEL(Combo)
1248 * InvalidateRect(Combo, 0, 0)
1251 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1252 if (infoPtr->flags & WCBE_ACTEDIT) {
1253 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1254 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1255 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1256 CB_GETCURSEL, 0, 0);
1257 cbeend.iWhy = CBENF_KILLFOCUS;
1259 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1260 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1262 /* possible CB_GETCURSEL */
1263 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1268 * We have to change the handle since we are the control
1269 * issuing the message. IE4 depends on this.
1270 * We also need to set the focus back to the Edit control
1271 * after passing the command to the parent of the ComboEx.
1273 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1274 if (infoPtr->hwndEdit)
1275 SetFocus(infoPtr->hwndEdit);
1282 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
1284 CBE_ITEMDATA *item, *olditem;
1285 NMCOMBOBOXEXW nmcit;
1288 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1289 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1291 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1293 olditem = infoPtr->items;
1294 i = infoPtr->nb_items - 1;
1296 if (i == dis->itemID) {
1297 infoPtr->items = infoPtr->items->next;
1303 /* find the prior item in the list */
1304 while (item->next && (i > dis->itemID)) {
1308 if (!item->next || (i != dis->itemID)) {
1309 ERR("COMBOBOXEX item structures broken. Please report!\n");
1312 olditem = item->next;
1313 item->next = item->next->next;
1315 infoPtr->nb_items--;
1317 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1318 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1319 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1321 COMBOEX_FreeText(olditem);
1328 static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
1330 static const WCHAR nil[] = { 0 };
1331 CBE_ITEMDATA *item = 0;
1337 COLORREF nbkc, ntxc, bkc, txc;
1338 int drawimage, drawstate, xioff;
1340 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1342 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1343 dis->CtlType, dis->CtlID);
1344 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1345 dis->itemID, dis->itemAction, dis->itemState);
1346 TRACE("hWnd=%p hDC=%p (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1347 dis->hwndItem, dis->hDC, dis->rcItem.left,
1348 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1352 /* "itemID - Specifies the menu item identifier for a menu */
1353 /* item or the index of the item in a list box or combo box. */
1354 /* For an empty list box or combo box, this member can be -1. */
1355 /* This allows the application to draw only the focus */
1356 /* rectangle at the coordinates specified by the rcItem */
1357 /* member even though there are no items in the control. */
1358 /* This indicates to the user whether the list box or combo */
1359 /* box has the focus. How the bits are set in the itemAction */
1360 /* member determines whether the rectangle is to be drawn as */
1361 /* though the list box or combo box has the focus. */
1362 if (dis->itemID == 0xffffffff) {
1363 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1364 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1366 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1367 dis->rcItem.left, dis->rcItem.top,
1368 dis->rcItem.right, dis->rcItem.bottom);
1370 else if ((dis->CtlType == ODT_COMBOBOX) &&
1371 (dis->itemAction == ODA_DRAWENTIRE)) {
1372 /* draw of edit control data */
1376 RECT exrc, cbrc, edrc;
1377 GetWindowRect (infoPtr->hwndSelf, &exrc);
1378 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1379 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1380 if (infoPtr->hwndEdit)
1381 GetWindowRect (infoPtr->hwndEdit, &edrc);
1382 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1383 exrc.left, exrc.top, exrc.right, exrc.bottom,
1384 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1385 edrc.left, edrc.top, edrc.right, edrc.bottom);
1389 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1390 dis->rcItem.left, dis->rcItem.top,
1391 dis->rcItem.right, dis->rcItem.bottom,
1392 dis->itemAction, dis->itemState);
1397 /* If draw item is -1 (edit control) setup the item pointer */
1398 if (dis->itemID == 0xffffffff) {
1399 item = infoPtr->edit;
1401 if (infoPtr->hwndEdit) {
1404 /* free previous text of edit item */
1405 COMBOEX_FreeText(item);
1406 item->mask &= ~CBEIF_TEXT;
1407 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1408 item->mask |= CBEIF_TEXT;
1409 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
1411 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1413 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1414 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1420 /* if the item pointer is not set, then get the data and locate it */
1422 item = get_item_data(infoPtr, dis->itemID);
1423 if (item == (CBE_ITEMDATA *)CB_ERR) {
1424 ERR("invalid item for id %d\n", dis->itemID);
1429 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1431 xbase = CBE_STARTOFFSET;
1432 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1433 INT indent = item->iIndent;
1434 if (indent == I_INDENTCALLBACK) {
1436 ZeroMemory(&nmce, sizeof(nmce));
1437 nmce.ceItem.mask = CBEIF_INDENT;
1438 nmce.ceItem.lParam = item->lParam;
1439 nmce.ceItem.iItem = dis->itemID;
1440 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1441 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1442 item->iIndent = nmce.ceItem.iIndent;
1443 indent = nmce.ceItem.iIndent;
1445 xbase += (indent * CBE_INDENT);
1449 drawstate = ILD_NORMAL;
1450 if (item->mask & CBEIF_IMAGE)
1451 drawimage = item->iImage;
1452 if (dis->itemState & ODS_COMBOEXLBOX) {
1453 /* drawing listbox entry */
1454 if (dis->itemState & ODS_SELECTED) {
1455 if (item->mask & CBEIF_SELECTEDIMAGE)
1456 drawimage = item->iSelectedImage;
1457 drawstate = ILD_SELECTED;
1460 /* drawing combo/edit entry */
1461 if (IsWindowVisible(infoPtr->hwndEdit)) {
1462 /* if we have an edit control, the slave the
1463 * selection state to the Edit focus state
1465 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1466 if (item->mask & CBEIF_SELECTEDIMAGE)
1467 drawimage = item->iSelectedImage;
1468 drawstate = ILD_SELECTED;
1471 /* if we don't have an edit control, use
1472 * the requested state.
1474 if (dis->itemState & ODS_SELECTED) {
1475 if (item->mask & CBEIF_SELECTEDIMAGE)
1476 drawimage = item->iSelectedImage;
1477 drawstate = ILD_SELECTED;
1482 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1484 iinfo.rcImage.left = iinfo.rcImage.right = 0;
1485 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1486 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1489 /* setup pointer to text to be drawn */
1490 str = COMBOEX_GetText(infoPtr, item);
1491 if (!str) str = nil;
1493 len = strlenW (str);
1494 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1496 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1497 int overlay = item->iOverlay;
1499 if (drawimage == I_IMAGECALLBACK) {
1501 ZeroMemory(&nmce, sizeof(nmce));
1502 nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
1503 nmce.ceItem.lParam = item->lParam;
1504 nmce.ceItem.iItem = dis->itemID;
1505 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1506 if (drawstate == ILD_NORMAL) {
1507 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1508 drawimage = nmce.ceItem.iImage;
1509 } else if (drawstate == ILD_SELECTED) {
1510 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1511 drawimage = nmce.ceItem.iSelectedImage;
1512 } else ERR("Bad draw state = %d\n", drawstate);
1515 if (overlay == I_IMAGECALLBACK) {
1517 ZeroMemory(&nmce, sizeof(nmce));
1518 nmce.ceItem.mask = CBEIF_OVERLAY;
1519 nmce.ceItem.lParam = item->lParam;
1520 nmce.ceItem.iItem = dis->itemID;
1521 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1522 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1523 item->iOverlay = nmce.ceItem.iOverlay;
1524 overlay = nmce.ceItem.iOverlay;
1527 if (drawimage >= 0 &&
1528 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1529 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1530 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1531 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1534 /* now draw the text */
1535 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1536 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1537 COLOR_HIGHLIGHT : COLOR_WINDOW);
1538 bkc = SetBkColor (dis->hDC, nbkc);
1539 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1540 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1541 txc = SetTextColor (dis->hDC, ntxc);
1543 y = dis->rcItem.top +
1544 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1546 rect.right = x + txtsize.cx;
1547 rect.top = dis->rcItem.top + 1;
1548 rect.bottom = dis->rcItem.bottom - 1;
1549 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1550 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1551 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1552 &rect, str, len, 0);
1553 SetBkColor (dis->hDC, bkc);
1554 SetTextColor (dis->hDC, txc);
1558 if (dis->itemAction & ODA_FOCUS) {
1559 rect.left = xbase + xioff - 1;
1560 rect.right = rect.left + txtsize.cx + 2;
1561 rect.top = dis->rcItem.top;
1562 rect.bottom = dis->rcItem.bottom;
1563 DrawFocusRect(dis->hDC, &rect);
1570 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1572 if (infoPtr->hwndCombo)
1573 DestroyWindow (infoPtr->hwndCombo);
1575 if (infoPtr->edit) {
1576 Free (infoPtr->edit);
1580 if (infoPtr->items) {
1581 CBE_ITEMDATA *item, *next;
1583 item = infoPtr->items;
1586 COMBOEX_FreeText (item);
1593 if (infoPtr->defaultFont)
1594 DeleteObject (infoPtr->defaultFont);
1596 /* free comboex info data */
1598 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1603 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
1605 static const WCHAR strW[] = { 'W', 0 };
1610 GetTextExtentPointW (hdc, strW, 1, &mysize);
1612 mis->itemHeight = mysize.cy + CBE_EXTRA;
1614 TRACE("adjusted height hwnd=%p, height=%d\n",
1615 infoPtr->hwndSelf, mis->itemHeight);
1621 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1623 /* WARNING: The COMBOEX_INFO structure is not yet created */
1624 DWORD oldstyle, newstyle;
1626 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1627 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL | WS_BORDER);
1628 if (newstyle != oldstyle) {
1629 TRACE("req style %08x, reseting style %08x\n",
1630 oldstyle, newstyle);
1631 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1637 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1639 if (lParam == NF_REQUERY) {
1640 INT i = SendMessageW(infoPtr->hwndNotify,
1641 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1642 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1644 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1648 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1650 TRACE("(width=%d, height=%d)\n", width, height);
1652 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1654 COMBOEX_AdjustEditPos (infoPtr);
1660 static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1662 RECT cbx_wrect, cbx_crect, cb_wrect;
1665 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1666 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1667 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1669 /* width is winpos value + border width of comboex */
1671 + (cbx_wrect.right-cbx_wrect.left)
1672 - (cbx_crect.right-cbx_crect.left);
1674 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1675 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1676 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1677 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1678 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1679 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1680 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1681 width, cb_wrect.bottom-cb_wrect.top);
1683 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1685 cb_wrect.bottom-cb_wrect.top,
1688 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1690 /* height is combo window height plus border width of comboex */
1691 height = (cb_wrect.bottom-cb_wrect.top)
1692 + (cbx_wrect.bottom-cbx_wrect.top)
1693 - (cbx_crect.bottom-cbx_crect.top);
1694 if (wp->cy < height) wp->cy = height;
1695 if (infoPtr->hwndEdit) {
1696 COMBOEX_AdjustEditPos (infoPtr);
1697 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1703 static LRESULT WINAPI
1704 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1706 HWND hwndComboex = (HWND)GetPropW(hwnd, COMBOEX_SUBCLASS_PROP);
1707 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1708 NMCBEENDEDITW cbeend;
1709 WCHAR edit_text[260];
1715 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1716 hwnd, uMsg, wParam, lParam, infoPtr);
1718 if (!infoPtr) return 0;
1724 /* handle (ignore) the return character */
1725 if (wParam == VK_RETURN) return 0;
1726 /* all other characters pass into the real Edit */
1727 return CallWindowProcW (infoPtr->prevEditWndProc,
1728 hwnd, uMsg, wParam, lParam);
1732 * The following was determined by traces of the native
1735 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1736 GetClientRect (hwnd, &rect);
1737 TRACE("erasing (%d,%d)-(%d,%d)\n",
1738 rect.left, rect.top, rect.right, rect.bottom);
1739 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1740 SetBkColor (hDC, obkc);
1741 return CallWindowProcW (infoPtr->prevEditWndProc,
1742 hwnd, uMsg, wParam, lParam);
1745 INT oldItem, selected, step = 1;
1748 switch ((INT)wParam)
1751 /* native version seems to do following for COMBOEX */
1753 * GetWindowTextW(Edit,&?, 0x104) x
1754 * CB_GETCURSEL to Combo rets -1 x
1755 * WM_NOTIFY to COMBOEX parent (rebar) x
1756 * (CBEN_ENDEDIT{A|W}
1757 * fChanged = FALSE x
1758 * inewSelection = -1 x
1761 * CB_GETCURSEL to Combo rets -1 x
1762 * InvalidateRect(Combo, 0) x
1763 * WM_SETTEXT to Edit x
1764 * EM_SETSEL to Edit (0,0) x
1765 * EM_SETSEL to Edit (0,-1) x
1766 * RedrawWindow(Combo, 0, 0, 5) x
1768 TRACE("special code for VK_ESCAPE\n");
1770 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1772 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1773 cbeend.fChanged = FALSE;
1774 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1775 CB_GETCURSEL, 0, 0);
1776 cbeend.iWhy = CBENF_ESCAPE;
1778 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1779 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1780 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1781 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1782 ERR("item %d not found. Problem!\n", oldItem);
1785 infoPtr->selected = oldItem;
1786 COMBOEX_SetEditText (infoPtr, item);
1787 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1792 /* native version seems to do following for COMBOEX */
1794 * GetWindowTextW(Edit,&?, 0x104) x
1795 * CB_GETCURSEL to Combo rets -1 x
1796 * CB_GETCOUNT to Combo rets 0
1798 * CB_GETITEMDATA to match
1799 * *** above 3 lines simulated by FindItem x
1800 * WM_NOTIFY to COMBOEX parent (rebar) x
1801 * (CBEN_ENDEDIT{A|W} x
1802 * fChanged = TRUE (-1) x
1803 * iNewSelection = -1 or selected x
1805 * iWhy = 2 (CBENF_RETURN) x
1806 * CB_GETCURSEL to Combo rets -1 x
1807 * if -1 send CB_SETCURSEL to Combo -1 x
1808 * InvalidateRect(Combo, 0, 0) x
1810 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1813 TRACE("special code for VK_RETURN\n");
1815 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1817 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1818 selected = SendMessageW (infoPtr->hwndCombo,
1819 CB_GETCURSEL, 0, 0);
1821 if (selected != -1) {
1822 cmp_func_t cmptext = get_cmp_func(infoPtr);
1823 item = COMBOEX_FindItem (infoPtr, selected);
1824 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1825 selected, debugstr_txt(item->pszText));
1826 TRACE("handling VK_RETURN, edittext=%s\n",
1827 debugstr_w(edit_text));
1828 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1829 /* strings not equal -- indicate edit has changed */
1834 cbeend.iNewSelection = selected;
1835 cbeend.fChanged = TRUE;
1836 cbeend.iWhy = CBENF_RETURN;
1837 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1838 /* abort the change, restore previous */
1839 TRACE("Notify requested abort of change\n");
1840 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1841 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1845 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1846 if (oldItem != -1) {
1847 /* if something is selected, then deselect it */
1848 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1851 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1852 SetFocus(infoPtr->hwndEdit);
1858 /* by default, step is 1 */
1859 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1860 if (oldItem >= 0 && oldItem + step >= 0)
1861 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1864 return CallWindowProcW (infoPtr->prevEditWndProc,
1865 hwnd, uMsg, wParam, lParam);
1871 /* remember the focus to set state of icon */
1872 lret = CallWindowProcW (infoPtr->prevEditWndProc,
1873 hwnd, uMsg, wParam, lParam);
1874 infoPtr->flags |= WCBE_EDITFOCUSED;
1879 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1881 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1882 if (infoPtr->flags & WCBE_ACTEDIT) {
1883 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1885 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1886 cbeend.fChanged = FALSE;
1887 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1888 CB_GETCURSEL, 0, 0);
1889 cbeend.iWhy = CBENF_KILLFOCUS;
1891 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1896 return CallWindowProcW (infoPtr->prevEditWndProc,
1897 hwnd, uMsg, wParam, lParam);
1902 static LRESULT WINAPI
1903 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1905 HWND hwndComboex = (HWND)GetPropW(hwnd, COMBOEX_SUBCLASS_PROP);
1906 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1907 NMCBEENDEDITW cbeend;
1914 WCHAR edit_text[260];
1916 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1917 hwnd, uMsg, wParam, lParam, infoPtr);
1919 if (!infoPtr) return 0;
1926 * The only way this message should come is from the
1927 * child Listbox issuing the message. Flag this so
1928 * that ComboEx knows this is listbox.
1930 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1931 return CallWindowProcW (infoPtr->prevComboWndProc,
1932 hwnd, uMsg, wParam, lParam);
1936 * The following was determined by traces of the native
1939 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1940 GetClientRect (hwnd, &rect);
1941 TRACE("erasing (%d,%d)-(%d,%d)\n",
1942 rect.left, rect.top, rect.right, rect.bottom);
1943 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1944 SetBkColor (hDC, obkc);
1945 return CallWindowProcW (infoPtr->prevComboWndProc,
1946 hwnd, uMsg, wParam, lParam);
1950 * WM_NOTIFY to comboex parent (rebar)
1951 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1952 * CallWindowProc (previous)
1954 nmmse.dwItemSpec = 0;
1955 nmmse.dwItemData = 0;
1958 nmmse.dwHitInfo = lParam;
1959 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1960 return CallWindowProcW (infoPtr->prevComboWndProc,
1961 hwnd, uMsg, wParam, lParam);
1963 case WM_LBUTTONDOWN:
1964 GetClientRect (hwnd, &rect);
1965 rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1966 CB_GETITEMHEIGHT, -1, 0);
1967 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
1968 pt.x = (short)LOWORD(lParam);
1969 pt.y = (short)HIWORD(lParam);
1970 if (PtInRect(&rect, pt))
1971 return CallWindowProcW (infoPtr->prevComboWndProc,
1972 hwnd, uMsg, wParam, lParam);
1973 infoPtr->flags |= WCBE_MOUSECAPTURED;
1978 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1979 return CallWindowProcW (infoPtr->prevComboWndProc,
1980 hwnd, uMsg, wParam, lParam);
1982 infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1983 if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1984 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1986 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1991 if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1992 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
1993 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1994 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
1995 infoPtr->flags |= WCBE_MOUSEDRAGGED;
1997 return CallWindowProcW (infoPtr->prevComboWndProc,
1998 hwnd, uMsg, wParam, lParam);
2001 switch (HIWORD(wParam)) {
2004 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2013 * GetFocus() retns AA
2014 * GetWindowTextW(Edit)
2015 * CB_GETCURSEL(Combo) (got -1)
2016 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2017 * CB_GETCURSEL(Combo) (got -1)
2018 * InvalidateRect(Combo, 0, 0)
2019 * WM_KILLFOCUS(Combo, AA)
2022 focusedhwnd = GetFocus();
2023 if (infoPtr->flags & WCBE_ACTEDIT) {
2024 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2025 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2026 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2027 CB_GETCURSEL, 0, 0);
2028 cbeend.iWhy = CBENF_KILLFOCUS;
2030 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2031 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
2033 /* possible CB_GETCURSEL */
2034 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2036 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2037 (WPARAM)focusedhwnd, 0);
2042 * For EN_SETFOCUS this issues the same calls and messages
2043 * as the native seems to do.
2045 * for some cases however native does the following:
2046 * (noticed after SetFocus during LBUTTONDOWN on
2047 * on dropdown arrow)
2048 * WM_GETTEXTLENGTH (Edit);
2049 * WM_GETTEXT (Edit, len+1, str);
2050 * EM_SETSEL (Edit, 0, 0);
2051 * WM_GETTEXTLENGTH (Edit);
2052 * WM_GETTEXT (Edit, len+1, str);
2053 * EM_SETSEL (Edit, 0, len);
2054 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2058 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2059 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2060 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2061 infoPtr->flags |= WCBE_ACTEDIT;
2062 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2068 * For EN_CHANGE this issues the same calls and messages
2069 * as the native seems to do.
2071 WCHAR edit_text[260];
2073 cmp_func_t cmptext = get_cmp_func(infoPtr);
2075 INT selected = SendMessageW (infoPtr->hwndCombo,
2076 CB_GETCURSEL, 0, 0);
2078 /* lstrlenW( lastworkingURL ) */
2080 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2081 if (selected == -1) {
2082 lastwrk = infoPtr->edit->pszText;
2085 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2086 lastwrk = COMBOEX_GetText(infoPtr, item);
2089 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2090 selected, debugstr_w(lastwrk));
2091 TRACE("handling EN_CHANGE, edittext=%s\n",
2092 debugstr_w(edit_text));
2094 /* cmptext is between lastworkingURL and GetWindowText */
2095 if (cmptext (lastwrk, edit_text)) {
2096 /* strings not equal -- indicate edit has changed */
2097 infoPtr->flags |= WCBE_EDITCHG;
2099 SendMessageW ( infoPtr->hwndNotify, WM_COMMAND,
2100 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2102 (LPARAM)infoPtr->hwndSelf);
2108 * Therefore from traces there is no additional code here
2112 * Using native COMCTL32 gets the following:
2113 * 1 == SHDOCVW.DLL issues call/message
2114 * 2 == COMCTL32.DLL issues call/message
2115 * 3 == WINE issues call/message
2118 * for LBN_SELCHANGE:
2119 * 1 CB_GETCURSEL(ComboEx)
2120 * 1 CB_GETDROPPEDSTATE(ComboEx)
2121 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2122 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2123 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2124 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2125 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2126 * 3 ShowWindow(ComboLB, SW_HIDE)
2127 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2128 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2130 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2131 * ? LB_GETCURSEL <==|
2133 * ? LB_GETTEXT | Needs to be added to
2134 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2135 * ? LB_GETITEMDATA |
2136 * ? WM_DRAWITEM(ComboEx) <==|
2142 return CallWindowProcW (infoPtr->prevComboWndProc,
2143 hwnd, uMsg, wParam, lParam);
2149 static LRESULT WINAPI
2150 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2152 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2154 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2157 if (uMsg == WM_CREATE)
2158 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2159 if (uMsg == WM_NCCREATE)
2160 COMBOEX_NCCreate (hwnd);
2161 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2166 case CBEM_DELETEITEM:
2167 return COMBOEX_DeleteItem (infoPtr, wParam);
2169 case CBEM_GETCOMBOCONTROL:
2170 return (LRESULT)infoPtr->hwndCombo;
2172 case CBEM_GETEDITCONTROL:
2173 return (LRESULT)infoPtr->hwndEdit;
2175 case CBEM_GETEXTENDEDSTYLE:
2176 return infoPtr->dwExtStyle;
2178 case CBEM_GETIMAGELIST:
2179 return (LRESULT)infoPtr->himl;
2182 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2185 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2187 case CBEM_GETUNICODEFORMAT:
2188 return infoPtr->unicode;
2190 case CBEM_HASEDITCHANGED:
2191 return COMBOEX_HasEditChanged (infoPtr);
2193 case CBEM_INSERTITEMA:
2194 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2196 case CBEM_INSERTITEMW:
2197 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2199 case CBEM_SETEXSTYLE:
2200 case CBEM_SETEXTENDEDSTYLE:
2201 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2203 case CBEM_SETIMAGELIST:
2204 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2207 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2210 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2212 case CBEM_SETUNICODEFORMAT:
2213 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2215 /*case CBEM_SETWINDOWTHEME:
2216 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2220 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2223 return COMBOEX_GetListboxText(infoPtr, wParam, (LPWSTR)lParam);
2225 case CB_GETLBTEXTLEN:
2226 return COMBOEX_GetListboxText(infoPtr, wParam, NULL);
2228 /* Combo messages we are not sure if we need to process or just forward */
2229 case CB_GETDROPPEDCONTROLRECT:
2230 case CB_GETITEMHEIGHT:
2231 case CB_GETEXTENDEDUI:
2233 case CB_RESETCONTENT:
2234 case CB_SELECTSTRING:
2236 /* Combo messages OK to just forward to the regular COMBO */
2239 case CB_GETDROPPEDSTATE:
2240 case CB_SETDROPPEDWIDTH:
2241 case CB_SETEXTENDEDUI:
2242 case CB_SHOWDROPDOWN:
2243 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2245 /* Combo messages we need to process specially */
2246 case CB_FINDSTRINGEXACT:
2247 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2249 case CB_GETITEMDATA:
2250 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2253 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2255 case CB_SETITEMDATA:
2256 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD_PTR)lParam);
2258 case CB_SETITEMHEIGHT:
2259 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2263 /* Window messages passed to parent */
2265 return COMBOEX_Command (infoPtr, wParam, lParam);
2268 if (infoPtr->NtfUnicode)
2269 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
2271 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
2274 /* Window messages we need to process */
2276 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2279 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2282 return COMBOEX_Destroy (infoPtr);
2284 case WM_MEASUREITEM:
2285 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2287 case WM_NOTIFYFORMAT:
2288 return COMBOEX_NotifyFormat (infoPtr, lParam);
2291 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2293 case WM_WINDOWPOSCHANGING:
2294 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2297 SetFocus(infoPtr->hwndCombo);
2301 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2302 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
2303 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2308 void COMBOEX_Register (void)
2312 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2313 wndClass.style = CS_GLOBALCLASS;
2314 wndClass.lpfnWndProc = COMBOEX_WindowProc;
2315 wndClass.cbClsExtra = 0;
2316 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2317 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2318 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2319 wndClass.lpszClassName = WC_COMBOBOXEXW;
2321 RegisterClassW (&wndClass);
2325 void COMBOEX_Unregister (void)
2327 UnregisterClassW (WC_COMBOBOXEXW, NULL);