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 */
71 INT selected; /* index of selected item */
72 DWORD flags; /* WINE internal flags */
75 INT nb_items; /* Number of items */
76 BOOL unicode; /* TRUE if this window is Unicode */
77 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
78 CBE_ITEMDATA *edit; /* item data for edit item */
79 CBE_ITEMDATA *items; /* Array of items */
82 /* internal flags in the COMBOEX_INFO structure */
83 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
84 * CBEN_BEGINEDIT issued
85 * but CBEN_ENDEDIT{A|W}
87 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
88 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
89 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
90 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
91 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
93 #define ID_CB_EDIT 1001
97 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
98 * the ComboEx version of the Combo Window Proc so that when the
99 * WM_DRAWITEM message is then passed to ComboEx, we know that this
100 * particular WM_DRAWITEM message is for listbox only items. Any messasges
101 * without this flag is then for the Edit control field.
103 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
104 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
106 #define ODS_COMBOEXLBOX 0x4000
110 /* Height in pixels of control over the amount of the selected font */
113 /* Indent amount per MS documentation */
114 #define CBE_INDENT 10
116 /* Offset in pixels from left side for start of image or text */
117 #define CBE_STARTOFFSET 6
119 /* Offset between image and text */
122 #define COMBO_SUBCLASSID 1
123 #define EDIT_SUBCLASSID 2
125 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongPtrW (hwnd, 0))
127 static LRESULT CALLBACK COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
128 UINT_PTR uId, DWORD_PTR ref_data);
129 static LRESULT CALLBACK COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
130 UINT_PTR uId, DWORD_PTR ref_data);
131 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
132 typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
134 static inline BOOL is_textW(LPCWSTR str)
136 return str && str != LPSTR_TEXTCALLBACKW;
139 static inline BOOL is_textA(LPCSTR str)
141 return str && str != LPSTR_TEXTCALLBACKA;
144 static inline LPCSTR debugstr_txt(LPCWSTR str)
146 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
147 return debugstr_w(str);
150 static void COMBOEX_DumpItem (CBE_ITEMDATA const *item)
152 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
153 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
154 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
155 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
156 if (item->mask & CBEIF_TEXT)
157 TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
161 static void COMBOEX_DumpInput (COMBOBOXEXITEMW const *input)
163 TRACE("input - mask=%08x, iItem=%ld, pszText=%p, cchTM=%d, iImage=%d\n",
164 input->mask, input->iItem, input->pszText, input->cchTextMax,
166 if (input->mask & CBEIF_TEXT)
167 TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
168 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
169 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
173 static inline CBE_ITEMDATA *get_item_data(const COMBOEX_INFO *infoPtr, INT index)
175 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
179 static inline cmp_func_t get_cmp_func(COMBOEX_INFO const *infoPtr)
181 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
184 static INT COMBOEX_Notify (const COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
186 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
187 hdr->hwndFrom = infoPtr->hwndSelf;
189 if (infoPtr->NtfUnicode)
190 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
192 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
197 COMBOEX_NotifyItem (const COMBOEX_INFO *infoPtr, UINT code, NMCOMBOBOXEXW *hdr)
199 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
200 if (infoPtr->NtfUnicode)
201 return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
203 LPWSTR wstr = hdr->ceItem.pszText;
207 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
208 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
210 astr = Alloc ((len + 1)*sizeof(CHAR));
212 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
213 hdr->ceItem.pszText = (LPWSTR)astr;
217 if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
218 else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
219 else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
221 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
223 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
224 hdr->ceItem.pszText = wstr;
233 static INT COMBOEX_NotifyEndEdit (const COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
235 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
236 if (infoPtr->NtfUnicode) {
237 lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
238 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
242 neea.hdr = neew->hdr;
243 neea.fChanged = neew->fChanged;
244 neea.iNewSelection = neew->iNewSelection;
245 WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
246 neea.iWhy = neew->iWhy;
248 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
253 static void COMBOEX_NotifyDragBegin(const COMBOEX_INFO *infoPtr, LPCWSTR wstr)
255 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
256 if (infoPtr->NtfUnicode) {
257 NMCBEDRAGBEGINW ndbw;
260 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
261 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
263 NMCBEDRAGBEGINA ndba;
266 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
268 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
273 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
275 if (is_textW(item->pszText)) Free(item->pszText);
282 static INT COMBOEX_GetIndex(COMBOEX_INFO const *infoPtr, CBE_ITEMDATA const *item)
284 CBE_ITEMDATA const *moving;
287 moving = infoPtr->items;
288 index = infoPtr->nb_items - 1;
290 while (moving && (moving != item)) {
291 moving = moving->next;
294 if (!moving || (index < 0)) {
295 ERR("COMBOBOXEX item structures broken. Please report!\n");
302 static LPCWSTR COMBOEX_GetText(const COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
308 if (item->pszText != LPSTR_TEXTCALLBACKW)
309 return item->pszText;
311 ZeroMemory(&nmce, sizeof(nmce));
312 nmce.ceItem.mask = CBEIF_TEXT;
313 nmce.ceItem.lParam = item->lParam;
314 nmce.ceItem.iItem = COMBOEX_GetIndex(infoPtr, item);
315 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
317 if (is_textW(nmce.ceItem.pszText)) {
318 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
319 buf = Alloc ((len + 1)*sizeof(WCHAR));
321 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
322 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
323 COMBOEX_FreeText(item);
331 text = nmce.ceItem.pszText;
333 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
334 item->pszText = text;
339 static void COMBOEX_GetComboFontSize (const COMBOEX_INFO *infoPtr, SIZE *size)
341 static const WCHAR strA[] = { 'A', 0 };
345 mydc = GetDC (0); /* why the entire screen???? */
346 nfont = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
347 ofont = SelectObject (mydc, nfont);
348 GetTextExtentPointW (mydc, strA, 1, size);
349 SelectObject (mydc, ofont);
351 TRACE("selected font hwnd=%p, height=%d\n", nfont, size->cy);
355 static void COMBOEX_CopyItem (const CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
357 if (cit->mask & CBEIF_TEXT) {
359 * when given a text buffer actually use that buffer
362 if (is_textW(item->pszText))
363 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
367 cit->pszText = item->pszText;
368 cit->cchTextMax = item->cchTextMax;
371 if (cit->mask & CBEIF_IMAGE)
372 cit->iImage = item->iImage;
373 if (cit->mask & CBEIF_SELECTEDIMAGE)
374 cit->iSelectedImage = item->iSelectedImage;
375 if (cit->mask & CBEIF_OVERLAY)
376 cit->iOverlay = item->iOverlay;
377 if (cit->mask & CBEIF_INDENT)
378 cit->iIndent = item->iIndent;
379 if (cit->mask & CBEIF_LPARAM)
380 cit->lParam = item->lParam;
384 static void COMBOEX_AdjustEditPos (const COMBOEX_INFO *infoPtr)
387 INT x, y, w, h, xioff;
390 if (!infoPtr->hwndEdit) return;
392 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
394 iinfo.rcImage.left = iinfo.rcImage.right = 0;
395 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
396 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
399 GetClientRect (infoPtr->hwndCombo, &rect);
400 InflateRect (&rect, -2, -2);
401 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
403 /* reposition the Edit control based on whether icon exists */
404 COMBOEX_GetComboFontSize (infoPtr, &mysize);
405 TRACE("Combo font x=%d, y=%d\n", mysize.cx, mysize.cy);
406 x = xioff + CBE_STARTOFFSET + 1;
407 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
409 y = rect.bottom - h - 1;
411 TRACE("Combo client (%s), setting Edit to (%d,%d)-(%d,%d)\n",
412 wine_dbgstr_rect(&rect), x, y, x + w, y + h);
413 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
414 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
418 static void COMBOEX_ReSize (const COMBOEX_INFO *infoPtr)
424 COMBOEX_GetComboFontSize (infoPtr, &mysize);
425 cy = mysize.cy + CBE_EXTRA;
426 if (infoPtr->himl && ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo)) {
427 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
428 TRACE("upgraded height due to image: height=%d\n", cy);
430 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, -1, cy);
431 if (infoPtr->hwndCombo) {
432 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, 0, cy);
433 if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
435 if (GetWindowRect(infoPtr->hwndCombo, &comboRect)) {
437 if (GetWindowRect(infoPtr->hwndSelf, &ourRect)) {
438 if (comboRect.bottom > ourRect.bottom) {
439 POINT pt = { ourRect.left, ourRect.top };
440 if (ScreenToClient(infoPtr->hwndSelf, &pt))
441 MoveWindow( infoPtr->hwndSelf, pt.x, pt.y, ourRect.right - ourRect.left,
442 comboRect.bottom - comboRect.top, FALSE);
451 static void COMBOEX_SetEditText (const COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
453 if (!infoPtr->hwndEdit) return;
455 if (item->mask & CBEIF_TEXT) {
456 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
457 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
458 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
463 static CBE_ITEMDATA * COMBOEX_FindItem(const COMBOEX_INFO *infoPtr, INT_PTR index)
468 if ((index >= infoPtr->nb_items) || (index < -1))
471 return infoPtr->edit;
472 item = infoPtr->items;
473 i = infoPtr->nb_items - 1;
475 /* find the item in the list */
476 while (item && (i > index)) {
480 if (!item || (i != index)) {
481 ERR("COMBOBOXEX item structures broken. Please report!\n");
488 static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO const *infoPtr)
490 return infoPtr->hwndEdit ? TRUE : FALSE;
494 /* *** CBEM_xxx message support *** */
496 static UINT COMBOEX_GetListboxText(const COMBOEX_INFO *infoPtr, INT_PTR n, LPWSTR buf)
501 item = COMBOEX_FindItem(infoPtr, n);
505 str = COMBOEX_GetText(infoPtr, item);
510 if (infoPtr->unicode)
518 if (infoPtr->unicode)
522 return lstrlenW(str);
527 r = WideCharToMultiByte(CP_ACP, 0, str, -1, (LPSTR)buf, 0x40000000, NULL, NULL);
534 static INT COMBOEX_DeleteItem (const COMBOEX_INFO *infoPtr, INT_PTR index)
536 TRACE("(index=%ld)\n", index);
538 /* if item number requested does not exist then return failure */
539 if ((index >= infoPtr->nb_items) || (index < 0)) return CB_ERR;
540 if (!COMBOEX_FindItem(infoPtr, index)) return CB_ERR;
542 /* doing this will result in WM_DELETEITEM being issued */
543 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
545 return infoPtr->nb_items;
549 static BOOL COMBOEX_GetItemW (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
551 INT_PTR index = cit->iItem;
556 /* if item number requested does not exist then return failure */
557 if ((index >= infoPtr->nb_items) || (index < -1)) return FALSE;
559 /* if the item is the edit control and there is no edit control, skip */
560 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
562 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
564 COMBOEX_CopyItem (item, cit);
570 static BOOL COMBOEX_GetItemA (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
572 COMBOBOXEXITEMW tmpcit;
576 tmpcit.mask = cit->mask;
577 tmpcit.iItem = cit->iItem;
579 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
581 if (cit->mask & CBEIF_TEXT)
583 if (is_textW(tmpcit.pszText) && cit->pszText)
584 WideCharToMultiByte(CP_ACP, 0, tmpcit.pszText, -1,
585 cit->pszText, cit->cchTextMax, NULL, NULL);
586 else if (cit->pszText) cit->pszText[0] = 0;
587 else cit->pszText = (LPSTR)tmpcit.pszText;
590 if (cit->mask & CBEIF_IMAGE)
591 cit->iImage = tmpcit.iImage;
592 if (cit->mask & CBEIF_SELECTEDIMAGE)
593 cit->iSelectedImage = tmpcit.iSelectedImage;
594 if (cit->mask & CBEIF_OVERLAY)
595 cit->iOverlay = tmpcit.iOverlay;
596 if (cit->mask & CBEIF_INDENT)
597 cit->iIndent = tmpcit.iIndent;
598 if (cit->mask & CBEIF_LPARAM)
599 cit->lParam = tmpcit.lParam;
605 static inline BOOL COMBOEX_HasEditChanged (COMBOEX_INFO const *infoPtr)
607 return COMBOEX_HasEdit(infoPtr) &&
608 (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
612 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW const *cit)
620 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
622 /* get real index of item to insert */
624 if (index == -1) index = infoPtr->nb_items;
625 if (index > infoPtr->nb_items) return -1;
627 /* get zero-filled space and chain it in */
628 if(!(item = Alloc (sizeof(*item)))) return -1;
630 /* locate position to insert new item in */
631 if (index == infoPtr->nb_items) {
632 /* fast path for iItem = -1 */
633 item->next = infoPtr->items;
634 infoPtr->items = item;
637 INT i = infoPtr->nb_items-1;
638 CBE_ITEMDATA *moving = infoPtr->items;
640 while ((i > index) && moving) {
641 moving = moving->next;
645 ERR("COMBOBOXEX item structures broken. Please report!\n");
649 item->next = moving->next;
653 /* fill in our hidden item structure */
654 item->mask = cit->mask;
655 if (item->mask & CBEIF_TEXT) {
658 if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
660 item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
661 if (!item->pszText) {
665 strcpyW (item->pszText, cit->pszText);
667 else if (cit->pszText == LPSTR_TEXTCALLBACKW)
668 item->pszText = LPSTR_TEXTCALLBACKW;
669 item->cchTextMax = cit->cchTextMax;
671 if (item->mask & CBEIF_IMAGE)
672 item->iImage = cit->iImage;
673 if (item->mask & CBEIF_SELECTEDIMAGE)
674 item->iSelectedImage = cit->iSelectedImage;
675 if (item->mask & CBEIF_OVERLAY)
676 item->iOverlay = cit->iOverlay;
677 if (item->mask & CBEIF_INDENT)
678 item->iIndent = cit->iIndent;
679 if (item->mask & CBEIF_LPARAM)
680 item->lParam = cit->lParam;
683 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
685 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
686 (WPARAM)cit->iItem, (LPARAM)item);
688 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
689 COMBOEX_CopyItem (item, &nmcit.ceItem);
690 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
697 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA const *cit)
699 COMBOBOXEXITEMW citW;
703 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
704 if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
705 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
706 wstr = Alloc ((len + 1)*sizeof(WCHAR));
707 if (!wstr) return -1;
708 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
711 ret = COMBOEX_InsertItemW(infoPtr, &citW);
720 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
724 TRACE("(mask=x%08x, style=0x%08x)\n", mask, style);
726 dwTemp = infoPtr->dwExtStyle;
729 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
731 infoPtr->dwExtStyle = style;
733 /* see if we need to change the word break proc on the edit */
734 if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC)
735 SetPathWordBreakProc(infoPtr->hwndEdit,
736 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ? TRUE : FALSE);
738 /* test if the control's appearance has changed */
739 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
740 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
741 /* if state of EX_NOEDITIMAGE changes, invalidate all */
742 TRACE("EX_NOEDITIMAGE state changed to %d\n",
743 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
744 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
745 COMBOEX_AdjustEditPos (infoPtr);
746 if (infoPtr->hwndEdit)
747 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
754 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
756 HIMAGELIST himlTemp = infoPtr->himl;
760 infoPtr->himl = himl;
762 COMBOEX_ReSize (infoPtr);
763 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
765 /* reposition the Edit control based on whether icon exists */
766 COMBOEX_AdjustEditPos (infoPtr);
770 static BOOL COMBOEX_SetItemW (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
772 INT_PTR index = cit->iItem;
775 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
777 /* if item number requested does not exist then return failure */
778 if ((index >= infoPtr->nb_items) || (index < -1)) return FALSE;
780 /* if the item is the edit control and there is no edit control, skip */
781 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
783 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
785 /* add/change stuff to the internal item structure */
786 item->mask |= cit->mask;
787 if (cit->mask & CBEIF_TEXT) {
790 COMBOEX_FreeText(item);
791 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
793 item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
794 if (!item->pszText) return FALSE;
795 strcpyW(item->pszText, cit->pszText);
796 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
797 item->pszText = LPSTR_TEXTCALLBACKW;
798 item->cchTextMax = cit->cchTextMax;
800 if (cit->mask & CBEIF_IMAGE)
801 item->iImage = cit->iImage;
802 if (cit->mask & CBEIF_SELECTEDIMAGE)
803 item->iSelectedImage = cit->iSelectedImage;
804 if (cit->mask & CBEIF_OVERLAY)
805 item->iOverlay = cit->iOverlay;
806 if (cit->mask & CBEIF_INDENT)
807 item->iIndent = cit->iIndent;
808 if (cit->mask & CBEIF_LPARAM)
809 item->lParam = cit->lParam;
811 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
813 /* if original request was to update edit control, do some fast foot work */
814 if (cit->iItem == -1 && cit->mask & CBEIF_TEXT) {
815 COMBOEX_SetEditText (infoPtr, item);
816 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
821 static BOOL COMBOEX_SetItemA (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA const *cit)
823 COMBOBOXEXITEMW citW;
827 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
828 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
829 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
830 wstr = Alloc ((len + 1)*sizeof(WCHAR));
831 if (!wstr) return FALSE;
832 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
835 ret = COMBOEX_SetItemW(infoPtr, &citW);
843 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
845 BOOL bTemp = infoPtr->unicode;
847 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
849 infoPtr->unicode = value;
855 /* *** CB_xxx message support *** */
858 COMBOEX_FindStringExact (const COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
861 cmp_func_t cmptext = get_cmp_func(infoPtr);
862 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
864 /* now search from after starting loc and wrapping back to start */
865 for(i=start+1; i<count; i++) {
866 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
867 if ((LRESULT)item == CB_ERR) continue;
868 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
870 for(i=0; i<=start; i++) {
871 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
872 if ((LRESULT)item == CB_ERR) continue;
873 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
879 static DWORD_PTR COMBOEX_GetItemData (const COMBOEX_INFO *infoPtr, INT_PTR index)
881 CBE_ITEMDATA const *item1;
882 CBE_ITEMDATA const *item2;
885 item1 = get_item_data(infoPtr, index);
886 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
887 item2 = COMBOEX_FindItem (infoPtr, index);
888 if (item2 != item1) {
889 ERR("data structures damaged!\n");
892 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
893 TRACE("returning 0x%08lx\n", ret);
895 ret = (DWORD_PTR)item1;
896 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
902 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT_PTR index)
907 if (!(item = COMBOEX_FindItem(infoPtr, index)))
908 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
910 TRACE("selecting item %ld text=%s\n", index, debugstr_txt(item->pszText));
911 infoPtr->selected = index;
913 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
914 COMBOEX_SetEditText (infoPtr, item);
919 static DWORD_PTR COMBOEX_SetItemData (const COMBOEX_INFO *infoPtr, INT_PTR index, DWORD_PTR data)
922 CBE_ITEMDATA const *item2;
924 item1 = get_item_data(infoPtr, index);
925 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
926 item2 = COMBOEX_FindItem (infoPtr, index);
927 if (item2 != item1) {
928 ERR("data structures damaged!\n");
931 item1->mask |= CBEIF_LPARAM;
932 item1->lParam = data;
933 TRACE("setting lparam to 0x%08lx\n", data);
936 TRACE("non-valid result from combo %p\n", item1);
937 return (DWORD_PTR)item1;
941 static INT COMBOEX_SetItemHeight (COMBOEX_INFO const *infoPtr, INT index, UINT height)
943 RECT cb_wrect, cbx_wrect, cbx_crect;
945 /* First, lets forward the message to the normal combo control
946 just like Windows. */
947 if (infoPtr->hwndCombo)
948 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
949 index, height) == CB_ERR) return CB_ERR;
951 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
952 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
953 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
954 /* the height of comboex as height of the combo + comboex border */
955 height = cb_wrect.bottom-cb_wrect.top
956 + cbx_wrect.bottom-cbx_wrect.top
957 - (cbx_crect.bottom-cbx_crect.top);
958 TRACE("EX window=(%s), client=(%s)\n",
959 wine_dbgstr_rect(&cbx_wrect), wine_dbgstr_rect(&cbx_crect));
960 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
961 wine_dbgstr_rect(&cbx_wrect), cbx_wrect.right-cbx_wrect.left, height);
962 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
963 cbx_wrect.right-cbx_wrect.left, height,
964 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
970 /* *** WM_xxx message support *** */
973 static LRESULT COMBOEX_Create (HWND hwnd, CREATESTRUCTA const *cs)
975 static const WCHAR NIL[] = { 0 };
976 COMBOEX_INFO *infoPtr;
978 RECT wnrc1, clrc1, cmbwrc;
981 /* allocate memory for info structure */
982 infoPtr = Alloc (sizeof(COMBOEX_INFO));
983 if (!infoPtr) return -1;
985 /* initialize info structure */
986 /* note that infoPtr is allocated zero-filled */
988 infoPtr->hwndSelf = hwnd;
989 infoPtr->selected = -1;
991 infoPtr->unicode = IsWindowUnicode (hwnd);
992 infoPtr->hwndNotify = cs->hwndParent;
994 i = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
995 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
996 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
999 infoPtr->NtfUnicode = (i == NFR_UNICODE);
1001 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1003 /* create combo box */
1004 GetWindowRect(hwnd, &wnrc1);
1005 GetClientRect(hwnd, &clrc1);
1006 TRACE("EX window=(%s), client=(%s)\n",
1007 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1));
1009 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1010 /* specified. It then creates it's own version of the EDIT control */
1011 /* and makes the ComboBox the parent. This is because a normal */
1012 /* DROPDOWNLIST does not have an EDIT control, but we need one. */
1013 /* We also need to place the edit control at the proper location */
1014 /* (allow space for the icons). */
1016 infoPtr->hwndCombo = CreateWindowW (WC_COMBOBOXW, NIL,
1017 /* following line added to match native */
1018 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1019 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1020 /* was base and is necessary */
1021 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
1022 GetWindowLongW (hwnd, GWL_STYLE),
1023 cs->y, cs->x, cs->cx, cs->cy, hwnd,
1024 (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
1025 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
1028 * native does the following at this point according to trace:
1029 * GetWindowThreadProcessId(hwndCombo,0)
1030 * GetCurrentThreadId()
1031 * GetWindowThreadProcessId(hwndCombo, &???)
1032 * GetCurrentProcessId()
1035 SetWindowSubclass(infoPtr->hwndCombo, COMBOEX_ComboWndProc, COMBO_SUBCLASSID,
1037 infoPtr->font = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1040 * Now create our own EDIT control so we can position it.
1041 * It is created only for CBS_DROPDOWN style
1043 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1044 infoPtr->hwndEdit = CreateWindowExW (0, WC_EDITW, NIL,
1045 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1046 0, 0, 0, 0, /* will set later */
1048 (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
1049 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
1051 /* native does the following at this point according to trace:
1052 * GetWindowThreadProcessId(hwndEdit,0)
1053 * GetCurrentThreadId()
1054 * GetWindowThreadProcessId(hwndEdit, &???)
1055 * GetCurrentProcessId()
1057 SetWindowSubclass(infoPtr->hwndEdit, COMBOEX_EditWndProc, EDIT_SUBCLASSID,
1060 infoPtr->font = (HFONT)SendMessageW(infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1064 * Locate the default font if necessary and then set it in
1065 * all associated controls
1067 if (!infoPtr->font) {
1068 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1070 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1072 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1073 if (infoPtr->hwndEdit) {
1074 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1075 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1078 COMBOEX_ReSize (infoPtr);
1080 /* Above is fairly certain, below is much less certain. */
1082 GetWindowRect(hwnd, &wnrc1);
1083 GetClientRect(hwnd, &clrc1);
1084 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1085 TRACE("EX window=(%s) client=(%s) CB wnd=(%s)\n",
1086 wine_dbgstr_rect(&wnrc1), wine_dbgstr_rect(&clrc1),
1087 wine_dbgstr_rect(&cmbwrc));
1088 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1089 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1090 SWP_NOACTIVATE | SWP_NOREDRAW);
1092 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1093 TRACE("CB window=(%s)\n", wine_dbgstr_rect(&cmbwrc));
1094 SetWindowPos(hwnd, HWND_TOP,
1095 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1096 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1098 COMBOEX_AdjustEditPos (infoPtr);
1101 * Create an item structure to represent the data in the
1102 * EDIT control. It is allocated zero-filled.
1104 infoPtr->edit = Alloc (sizeof (CBE_ITEMDATA));
1105 if (!infoPtr->edit) {
1106 COMBOEX_Destroy(infoPtr);
1114 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam)
1117 INT command = HIWORD(wParam);
1118 CBE_ITEMDATA *item = 0;
1122 NMCBEENDEDITW cbeend;
1124 HWND parent = infoPtr->hwndNotify;
1126 TRACE("for command %d\n", command);
1131 SetFocus (infoPtr->hwndCombo);
1132 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1133 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1136 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1138 * from native trace of first dropdown after typing in URL in IE4
1139 * CB_GETCURSEL(Combo)
1140 * GetWindowText(Edit)
1141 * CB_GETCURSEL(Combo)
1142 * CB_GETCOUNT(Combo)
1143 * CB_GETITEMDATA(Combo, n)
1144 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1145 * CB_GETCURSEL(Combo)
1146 * CB_SETCURSEL(COMBOEX, n)
1148 * the rest is supposition
1150 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1151 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1152 if (infoPtr->hwndEdit) InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1153 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1155 cmp_func_t cmptext = get_cmp_func(infoPtr);
1156 /* find match from edit against those in Combobox */
1157 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1158 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1159 for (cursel = 0; cursel < n; cursel++){
1160 item = get_item_data(infoPtr, cursel);
1161 if ((INT_PTR)item == CB_ERR) break;
1162 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1164 if ((cursel == n) || ((INT_PTR)item == CB_ERR)) {
1165 TRACE("failed to find match??? item=%p cursel=%d\n",
1167 if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1172 item = get_item_data(infoPtr, cursel);
1173 if ((INT_PTR)item == CB_ERR) {
1174 TRACE("failed to find match??? item=%p cursel=%d\n",
1176 if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1181 /* Save flags for testing and reset them */
1182 oldflags = infoPtr->flags;
1183 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1185 if (oldflags & WCBE_ACTEDIT) {
1186 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1187 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1188 CB_GETCURSEL, 0, 0);
1189 cbeend.iWhy = CBENF_DROPDOWN;
1191 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1194 /* if selection has changed the set the new current selection */
1195 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1196 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1197 infoPtr->selected = cursel;
1198 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1199 SetFocus(infoPtr->hwndCombo);
1205 * CB_GETCURSEL(Combo)
1206 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1209 * WM_GETTEXTLENGTH(Edit)
1211 * EM_SETSEL(Edit, 0,0)
1212 * WM_GETTEXTLENGTH(Edit)
1214 * EM_SETSEL(Edit, 0,len)
1215 * return WM_COMMAND to parent
1217 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1218 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1219 ERR("item %ld not found. Problem!\n", oldItem);
1222 infoPtr->selected = oldItem;
1223 COMBOEX_SetEditText (infoPtr, item);
1224 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1227 case CBN_SELENDCANCEL:
1229 * We have to change the handle since we are the control
1230 * issuing the message. IE4 depends on this.
1232 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1236 * from native trace:
1239 * WM_GETTEXT(Edit, 104)
1240 * CB_GETCURSEL(Combo) rets -1
1241 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1242 * CB_GETCURSEL(Combo)
1243 * InvalidateRect(Combo, 0, 0)
1246 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1247 if (infoPtr->flags & WCBE_ACTEDIT) {
1248 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1249 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1250 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1251 CB_GETCURSEL, 0, 0);
1252 cbeend.iWhy = CBENF_KILLFOCUS;
1254 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1255 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1257 /* possible CB_GETCURSEL */
1258 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1262 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1266 * We have to change the handle since we are the control
1267 * issuing the message. IE4 depends on this.
1268 * We also need to set the focus back to the Edit control
1269 * after passing the command to the parent of the ComboEx.
1271 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1272 if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1279 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT const *dis)
1281 CBE_ITEMDATA *item, *olditem;
1282 NMCOMBOBOXEXW nmcit;
1285 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1286 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1288 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1290 olditem = infoPtr->items;
1291 i = infoPtr->nb_items - 1;
1293 if (i == dis->itemID) {
1294 infoPtr->items = infoPtr->items->next;
1300 /* find the prior item in the list */
1301 while (item->next && (i > dis->itemID)) {
1305 if (!item->next || (i != dis->itemID)) {
1306 ERR("COMBOBOXEX item structures broken. Please report!\n");
1309 olditem = item->next;
1310 item->next = item->next->next;
1312 infoPtr->nb_items--;
1314 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1315 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1316 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1318 COMBOEX_FreeText(olditem);
1325 static LRESULT COMBOEX_DrawItem (const COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT const *dis)
1327 static const WCHAR nil[] = { 0 };
1328 CBE_ITEMDATA *item = 0;
1334 COLORREF nbkc, ntxc, bkc, txc;
1335 int drawimage, drawstate, xioff;
1337 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1339 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1340 dis->CtlType, dis->CtlID);
1341 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1342 dis->itemID, dis->itemAction, dis->itemState);
1343 TRACE("hWnd=%p hDC=%p (%s) itemData=0x%08lx\n",
1344 dis->hwndItem, dis->hDC, wine_dbgstr_rect(&dis->rcItem), dis->itemData);
1347 /* "itemID - Specifies the menu item identifier for a menu */
1348 /* item or the index of the item in a list box or combo box. */
1349 /* For an empty list box or combo box, this member can be -1. */
1350 /* This allows the application to draw only the focus */
1351 /* rectangle at the coordinates specified by the rcItem */
1352 /* member even though there are no items in the control. */
1353 /* This indicates to the user whether the list box or combo */
1354 /* box has the focus. How the bits are set in the itemAction */
1355 /* member determines whether the rectangle is to be drawn as */
1356 /* though the list box or combo box has the focus. */
1357 if (dis->itemID == 0xffffffff) {
1358 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1359 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1361 TRACE("drawing item -1 special focus, rect=(%s)\n",
1362 wine_dbgstr_rect(&dis->rcItem));
1364 else if ((dis->CtlType == ODT_COMBOBOX) &&
1365 (dis->itemAction == ODA_DRAWENTIRE)) {
1366 /* draw of edit control data */
1370 RECT exrc, cbrc, edrc;
1371 GetWindowRect (infoPtr->hwndSelf, &exrc);
1372 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1373 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1374 if (infoPtr->hwndEdit) GetWindowRect (infoPtr->hwndEdit, &edrc);
1375 TRACE("window rects ex=(%s), cb=(%s), ed=(%s)\n",
1376 wine_dbgstr_rect(&exrc), wine_dbgstr_rect(&cbrc),
1377 wine_dbgstr_rect(&edrc));
1381 ERR("NOT drawing item -1 special focus, rect=(%s), action=%08x, state=%08x\n",
1382 wine_dbgstr_rect(&dis->rcItem),
1383 dis->itemAction, dis->itemState);
1388 /* If draw item is -1 (edit control) setup the item pointer */
1389 if (dis->itemID == 0xffffffff) {
1390 item = infoPtr->edit;
1392 if (infoPtr->hwndEdit) {
1395 /* free previous text of edit item */
1396 COMBOEX_FreeText(item);
1397 item->mask &= ~CBEIF_TEXT;
1398 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1399 item->mask |= CBEIF_TEXT;
1400 item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
1402 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1404 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1405 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1411 /* if the item pointer is not set, then get the data and locate it */
1413 item = get_item_data(infoPtr, dis->itemID);
1414 if (item == (CBE_ITEMDATA *)CB_ERR) {
1415 ERR("invalid item for id %d\n", dis->itemID);
1420 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1422 xbase = CBE_STARTOFFSET;
1423 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1424 INT indent = item->iIndent;
1425 if (indent == I_INDENTCALLBACK) {
1427 ZeroMemory(&nmce, sizeof(nmce));
1428 nmce.ceItem.mask = CBEIF_INDENT;
1429 nmce.ceItem.lParam = item->lParam;
1430 nmce.ceItem.iItem = dis->itemID;
1431 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1432 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1433 item->iIndent = nmce.ceItem.iIndent;
1434 indent = nmce.ceItem.iIndent;
1436 xbase += (indent * CBE_INDENT);
1440 drawstate = ILD_NORMAL;
1441 if (item->mask & CBEIF_IMAGE)
1442 drawimage = item->iImage;
1443 if (dis->itemState & ODS_COMBOEXLBOX) {
1444 /* drawing listbox entry */
1445 if (dis->itemState & ODS_SELECTED) {
1446 if (item->mask & CBEIF_SELECTEDIMAGE)
1447 drawimage = item->iSelectedImage;
1448 drawstate = ILD_SELECTED;
1451 /* drawing combo/edit entry */
1452 if (IsWindowVisible(infoPtr->hwndEdit)) {
1453 /* if we have an edit control, the slave the
1454 * selection state to the Edit focus state
1456 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1457 if (item->mask & CBEIF_SELECTEDIMAGE)
1458 drawimage = item->iSelectedImage;
1459 drawstate = ILD_SELECTED;
1462 /* if we don't have an edit control, use
1463 * the requested state.
1465 if (dis->itemState & ODS_SELECTED) {
1466 if (item->mask & CBEIF_SELECTEDIMAGE)
1467 drawimage = item->iSelectedImage;
1468 drawstate = ILD_SELECTED;
1473 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1475 iinfo.rcImage.left = iinfo.rcImage.right = 0;
1476 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1477 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1480 /* setup pointer to text to be drawn */
1481 str = COMBOEX_GetText(infoPtr, item);
1482 if (!str) str = nil;
1484 len = strlenW (str);
1485 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1487 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1488 int overlay = item->iOverlay;
1490 if (drawimage == I_IMAGECALLBACK) {
1492 ZeroMemory(&nmce, sizeof(nmce));
1493 nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
1494 nmce.ceItem.lParam = item->lParam;
1495 nmce.ceItem.iItem = dis->itemID;
1496 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1497 if (drawstate == ILD_NORMAL) {
1498 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1499 drawimage = nmce.ceItem.iImage;
1500 } else if (drawstate == ILD_SELECTED) {
1501 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1502 drawimage = nmce.ceItem.iSelectedImage;
1503 } else ERR("Bad draw state = %d\n", drawstate);
1506 if (overlay == I_IMAGECALLBACK) {
1508 ZeroMemory(&nmce, sizeof(nmce));
1509 nmce.ceItem.mask = CBEIF_OVERLAY;
1510 nmce.ceItem.lParam = item->lParam;
1511 nmce.ceItem.iItem = dis->itemID;
1512 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1513 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1514 item->iOverlay = nmce.ceItem.iOverlay;
1515 overlay = nmce.ceItem.iOverlay;
1518 if (drawimage >= 0 &&
1519 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1520 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1521 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1522 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1525 /* now draw the text */
1526 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1527 nbkc = (dis->itemState & ODS_SELECTED) ?
1528 comctl32_color.clrHighlight : comctl32_color.clrWindow;
1529 bkc = SetBkColor (dis->hDC, nbkc);
1530 ntxc = (dis->itemState & ODS_SELECTED) ?
1531 comctl32_color.clrHighlightText : comctl32_color.clrWindowText;
1532 txc = SetTextColor (dis->hDC, ntxc);
1534 y = dis->rcItem.top +
1535 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1537 rect.right = x + txtsize.cx;
1538 rect.top = dis->rcItem.top + 1;
1539 rect.bottom = dis->rcItem.bottom - 1;
1540 TRACE("drawing item %d text, rect=(%s)\n",
1541 dis->itemID, wine_dbgstr_rect(&rect));
1542 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1543 &rect, str, len, 0);
1544 SetBkColor (dis->hDC, bkc);
1545 SetTextColor (dis->hDC, txc);
1549 if (dis->itemAction & ODA_FOCUS) {
1550 rect.left = xbase + xioff - 1;
1551 rect.right = rect.left + txtsize.cx + 2;
1552 rect.top = dis->rcItem.top;
1553 rect.bottom = dis->rcItem.bottom;
1554 DrawFocusRect(dis->hDC, &rect);
1561 static void COMBOEX_ResetContent (COMBOEX_INFO *infoPtr)
1565 CBE_ITEMDATA *item, *next;
1567 item = infoPtr->items;
1570 COMBOEX_FreeText (item);
1577 infoPtr->selected = -1;
1578 infoPtr->nb_items = 0;
1582 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1584 if (infoPtr->hwndCombo)
1585 RemoveWindowSubclass(infoPtr->hwndCombo, COMBOEX_ComboWndProc, COMBO_SUBCLASSID);
1587 if (infoPtr->hwndEdit)
1588 RemoveWindowSubclass(infoPtr->hwndEdit, COMBOEX_EditWndProc, EDIT_SUBCLASSID);
1590 Free (infoPtr->edit);
1593 COMBOEX_ResetContent (infoPtr);
1595 if (infoPtr->defaultFont)
1596 DeleteObject (infoPtr->defaultFont);
1598 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1600 /* free comboex info data */
1607 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO const *infoPtr, MEASUREITEMSTRUCT *mis)
1609 static const WCHAR strW[] = { 'W', 0 };
1614 GetTextExtentPointW (hdc, strW, 1, &mysize);
1616 mis->itemHeight = mysize.cy + CBE_EXTRA;
1618 TRACE("adjusted height hwnd=%p, height=%d\n",
1619 infoPtr->hwndSelf, mis->itemHeight);
1625 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1627 /* WARNING: The COMBOEX_INFO structure is not yet created */
1628 DWORD oldstyle, newstyle;
1630 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1631 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL | WS_BORDER);
1632 if (newstyle != oldstyle) {
1633 TRACE("req style %08x, resetting style %08x\n",
1634 oldstyle, newstyle);
1635 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1641 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1643 if (lParam == NF_REQUERY) {
1644 INT i = SendMessageW(infoPtr->hwndNotify,
1645 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1646 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1648 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1652 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1654 TRACE("(width=%d, height=%d)\n", width, height);
1656 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1658 COMBOEX_AdjustEditPos (infoPtr);
1664 static LRESULT COMBOEX_SetRedraw(const COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1666 LRESULT ret = DefWindowProcW( infoPtr->hwndSelf, WM_SETREDRAW, wParam, lParam );
1667 if (wParam) RedrawWindow( infoPtr->hwndSelf, NULL, 0, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN );
1672 static LRESULT COMBOEX_WindowPosChanging (const COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1674 RECT cbx_wrect, cbx_crect, cb_wrect;
1677 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1678 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1679 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1681 /* width is winpos value + border width of comboex */
1683 + (cbx_wrect.right-cbx_wrect.left)
1684 - (cbx_crect.right-cbx_crect.left);
1686 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1687 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1688 TRACE("EX window=(%s), client=(%s)\n",
1689 wine_dbgstr_rect(&cbx_wrect), wine_dbgstr_rect(&cbx_crect));
1690 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
1691 wine_dbgstr_rect(&cbx_wrect), width, cb_wrect.bottom-cb_wrect.top);
1693 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1695 cb_wrect.bottom-cb_wrect.top,
1698 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1700 /* height is combo window height plus border width of comboex */
1701 height = (cb_wrect.bottom-cb_wrect.top)
1702 + (cbx_wrect.bottom-cbx_wrect.top)
1703 - (cbx_crect.bottom-cbx_crect.top);
1704 if (wp->cy < height) wp->cy = height;
1705 if (infoPtr->hwndEdit) {
1706 COMBOEX_AdjustEditPos (infoPtr);
1707 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1713 static LRESULT CALLBACK
1714 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
1715 UINT_PTR uId, DWORD_PTR ref_data)
1717 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr ((HWND)ref_data);
1718 NMCBEENDEDITW cbeend;
1719 WCHAR edit_text[260];
1725 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1726 hwnd, uMsg, wParam, lParam, infoPtr);
1728 if (!infoPtr) return 0;
1734 /* handle (ignore) the return character */
1735 if (wParam == VK_RETURN) return 0;
1736 /* all other characters pass into the real Edit */
1737 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1741 * The following was determined by traces of the native
1744 obkc = SetBkColor (hDC, comctl32_color.clrWindow);
1745 GetClientRect (hwnd, &rect);
1746 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect));
1747 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1748 SetBkColor (hDC, obkc);
1749 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1752 INT_PTR oldItem, selected, step = 1;
1755 switch ((INT)wParam)
1758 /* native version seems to do following for COMBOEX */
1760 * GetWindowTextW(Edit,&?, 0x104) x
1761 * CB_GETCURSEL to Combo rets -1 x
1762 * WM_NOTIFY to COMBOEX parent (rebar) x
1763 * (CBEN_ENDEDIT{A|W}
1764 * fChanged = FALSE x
1765 * inewSelection = -1 x
1768 * CB_GETCURSEL to Combo rets -1 x
1769 * InvalidateRect(Combo, 0) x
1770 * WM_SETTEXT to Edit x
1771 * EM_SETSEL to Edit (0,0) x
1772 * EM_SETSEL to Edit (0,-1) x
1773 * RedrawWindow(Combo, 0, 0, 5) x
1775 TRACE("special code for VK_ESCAPE\n");
1777 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1779 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1780 cbeend.fChanged = FALSE;
1781 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1782 CB_GETCURSEL, 0, 0);
1783 cbeend.iWhy = CBENF_ESCAPE;
1785 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1786 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1787 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1788 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1789 ERR("item %ld not found. Problem!\n", oldItem);
1792 infoPtr->selected = oldItem;
1793 COMBOEX_SetEditText (infoPtr, item);
1794 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1799 /* native version seems to do following for COMBOEX */
1801 * GetWindowTextW(Edit,&?, 0x104) x
1802 * CB_GETCURSEL to Combo rets -1 x
1803 * CB_GETCOUNT to Combo rets 0
1805 * CB_GETITEMDATA to match
1806 * *** above 3 lines simulated by FindItem x
1807 * WM_NOTIFY to COMBOEX parent (rebar) x
1808 * (CBEN_ENDEDIT{A|W} x
1809 * fChanged = TRUE (-1) x
1810 * iNewSelection = -1 or selected x
1812 * iWhy = 2 (CBENF_RETURN) x
1813 * CB_GETCURSEL to Combo rets -1 x
1814 * if -1 send CB_SETCURSEL to Combo -1 x
1815 * InvalidateRect(Combo, 0, 0) x
1817 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1820 TRACE("special code for VK_RETURN\n");
1822 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1824 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1825 selected = SendMessageW (infoPtr->hwndCombo,
1826 CB_GETCURSEL, 0, 0);
1828 if (selected != -1) {
1829 cmp_func_t cmptext = get_cmp_func(infoPtr);
1830 item = COMBOEX_FindItem (infoPtr, selected);
1831 TRACE("handling VK_RETURN, selected = %ld, selected_text=%s\n",
1832 selected, debugstr_txt(item->pszText));
1833 TRACE("handling VK_RETURN, edittext=%s\n",
1834 debugstr_w(edit_text));
1835 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1836 /* strings not equal -- indicate edit has changed */
1841 cbeend.iNewSelection = selected;
1842 cbeend.fChanged = TRUE;
1843 cbeend.iWhy = CBENF_RETURN;
1844 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1845 /* abort the change, restore previous */
1846 TRACE("Notify requested abort of change\n");
1847 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1848 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1852 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1853 if (oldItem != -1) {
1854 /* if something is selected, then deselect it */
1855 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1858 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1859 SetFocus(infoPtr->hwndEdit);
1865 /* by default, step is 1 */
1866 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1867 if (oldItem >= 0 && oldItem + step >= 0)
1868 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1871 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1877 /* remember the focus to set state of icon */
1878 lret = DefSubclassProc(hwnd, uMsg, wParam, lParam);
1879 infoPtr->flags |= WCBE_EDITFOCUSED;
1884 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1886 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1887 if (infoPtr->flags & WCBE_ACTEDIT) {
1888 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1890 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1891 cbeend.fChanged = FALSE;
1892 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1893 CB_GETCURSEL, 0, 0);
1894 cbeend.iWhy = CBENF_KILLFOCUS;
1896 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1901 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1906 static LRESULT CALLBACK
1907 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
1908 UINT_PTR uId, DWORD_PTR ref_data)
1910 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr ((HWND)ref_data);
1911 NMCBEENDEDITW cbeend;
1918 WCHAR edit_text[260];
1920 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1921 hwnd, uMsg, wParam, lParam, infoPtr);
1923 if (!infoPtr) return 0;
1930 * The only way this message should come is from the
1931 * child Listbox issuing the message. Flag this so
1932 * that ComboEx knows this is listbox.
1934 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1935 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1939 * The following was determined by traces of the native
1942 obkc = SetBkColor (hDC, comctl32_color.clrWindow);
1943 GetClientRect (hwnd, &rect);
1944 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect));
1945 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1946 SetBkColor (hDC, obkc);
1947 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1951 * WM_NOTIFY to comboex parent (rebar)
1952 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1953 * CallWindowProc (previous)
1955 nmmse.dwItemSpec = 0;
1956 nmmse.dwItemData = 0;
1959 nmmse.dwHitInfo = lParam;
1960 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1961 return DefSubclassProc(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 DefSubclassProc(hwnd, uMsg, wParam, lParam);
1973 infoPtr->flags |= WCBE_MOUSECAPTURED;
1978 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1979 return DefSubclassProc(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 DefSubclassProc(hwnd, uMsg, wParam, lParam);
2000 switch (HIWORD(wParam)) {
2003 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2012 * GetFocus() retns AA
2013 * GetWindowTextW(Edit)
2014 * CB_GETCURSEL(Combo) (got -1)
2015 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2016 * CB_GETCURSEL(Combo) (got -1)
2017 * InvalidateRect(Combo, 0, 0)
2018 * WM_KILLFOCUS(Combo, AA)
2021 focusedhwnd = GetFocus();
2022 if (infoPtr->flags & WCBE_ACTEDIT) {
2023 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2024 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2025 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2026 CB_GETCURSEL, 0, 0);
2027 cbeend.iWhy = CBENF_KILLFOCUS;
2029 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2030 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
2032 /* possible CB_GETCURSEL */
2033 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2035 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2036 (WPARAM)focusedhwnd, 0);
2041 * For EN_SETFOCUS this issues the same calls and messages
2042 * as the native seems to do.
2044 * for some cases however native does the following:
2045 * (noticed after SetFocus during LBUTTONDOWN on
2046 * on dropdown arrow)
2047 * WM_GETTEXTLENGTH (Edit);
2048 * WM_GETTEXT (Edit, len+1, str);
2049 * EM_SETSEL (Edit, 0, 0);
2050 * WM_GETTEXTLENGTH (Edit);
2051 * WM_GETTEXT (Edit, len+1, str);
2052 * EM_SETSEL (Edit, 0, len);
2053 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2057 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2058 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2059 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2060 infoPtr->flags |= WCBE_ACTEDIT;
2061 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2067 * For EN_CHANGE this issues the same calls and messages
2068 * as the native seems to do.
2070 WCHAR edit_text[260];
2072 cmp_func_t cmptext = get_cmp_func(infoPtr);
2074 INT_PTR selected = SendMessageW (infoPtr->hwndCombo,
2075 CB_GETCURSEL, 0, 0);
2077 /* lstrlenW( lastworkingURL ) */
2079 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2080 if (selected == -1) {
2081 lastwrk = infoPtr->edit->pszText;
2084 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2085 lastwrk = COMBOEX_GetText(infoPtr, item);
2088 TRACE("handling EN_CHANGE, selected = %ld, selected_text=%s\n",
2089 selected, debugstr_w(lastwrk));
2090 TRACE("handling EN_CHANGE, edittext=%s\n",
2091 debugstr_w(edit_text));
2093 /* cmptext is between lastworkingURL and GetWindowText */
2094 if (cmptext (lastwrk, edit_text)) {
2095 /* strings not equal -- indicate edit has changed */
2096 infoPtr->flags |= WCBE_EDITCHG;
2098 SendMessageW ( infoPtr->hwndNotify, WM_COMMAND,
2099 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2101 (LPARAM)infoPtr->hwndSelf);
2107 * Therefore from traces there is no additional code here
2111 * Using native COMCTL32 gets the following:
2112 * 1 == SHDOCVW.DLL issues call/message
2113 * 2 == COMCTL32.DLL issues call/message
2114 * 3 == WINE issues call/message
2117 * for LBN_SELCHANGE:
2118 * 1 CB_GETCURSEL(ComboEx)
2119 * 1 CB_GETDROPPEDSTATE(ComboEx)
2120 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2121 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2122 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2123 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2124 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2125 * 3 ShowWindow(ComboLB, SW_HIDE)
2126 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2127 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2129 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2130 * ? LB_GETCURSEL <==|
2132 * ? LB_GETTEXT | Needs to be added to
2133 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2134 * ? LB_GETITEMDATA |
2135 * ? WM_DRAWITEM(ComboEx) <==|
2141 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2147 static LRESULT WINAPI
2148 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2150 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2152 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2155 if (uMsg == WM_CREATE)
2156 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2157 if (uMsg == WM_NCCREATE)
2158 COMBOEX_NCCreate (hwnd);
2159 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2164 case CBEM_DELETEITEM:
2165 return COMBOEX_DeleteItem (infoPtr, wParam);
2167 case CBEM_GETCOMBOCONTROL:
2168 return (LRESULT)infoPtr->hwndCombo;
2170 case CBEM_GETEDITCONTROL:
2171 return (LRESULT)infoPtr->hwndEdit;
2173 case CBEM_GETEXTENDEDSTYLE:
2174 return infoPtr->dwExtStyle;
2176 case CBEM_GETIMAGELIST:
2177 return (LRESULT)infoPtr->himl;
2180 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2183 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2185 case CBEM_GETUNICODEFORMAT:
2186 return infoPtr->unicode;
2188 case CBEM_HASEDITCHANGED:
2189 return COMBOEX_HasEditChanged (infoPtr);
2191 case CBEM_INSERTITEMA:
2192 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2194 case CBEM_INSERTITEMW:
2195 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2197 case CBEM_SETEXSTYLE:
2198 case CBEM_SETEXTENDEDSTYLE:
2199 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2201 case CBEM_SETIMAGELIST:
2202 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2205 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2208 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2210 case CBEM_SETUNICODEFORMAT:
2211 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2213 /*case CBEM_SETWINDOWTHEME:
2214 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2218 case WM_GETTEXTLENGTH:
2219 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2222 return COMBOEX_GetListboxText(infoPtr, wParam, (LPWSTR)lParam);
2224 case CB_GETLBTEXTLEN:
2225 return COMBOEX_GetListboxText(infoPtr, wParam, NULL);
2227 case CB_RESETCONTENT:
2228 COMBOEX_ResetContent(infoPtr);
2231 /* Combo messages we are not sure if we need to process or just forward */
2232 case CB_GETDROPPEDCONTROLRECT:
2233 case CB_GETITEMHEIGHT:
2234 case CB_GETEXTENDEDUI:
2236 case CB_SELECTSTRING:
2238 /* Combo messages OK to just forward to the regular COMBO */
2241 case CB_GETDROPPEDSTATE:
2242 case CB_SETDROPPEDWIDTH:
2243 case CB_SETEXTENDEDUI:
2244 case CB_SHOWDROPDOWN:
2245 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2247 /* Combo messages we need to process specially */
2248 case CB_FINDSTRINGEXACT:
2249 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2251 case CB_GETITEMDATA:
2252 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2255 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2257 case CB_SETITEMDATA:
2258 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD_PTR)lParam);
2260 case CB_SETITEMHEIGHT:
2261 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2265 /* Window messages passed to parent */
2267 return COMBOEX_Command (infoPtr, wParam);
2270 if (infoPtr->NtfUnicode)
2271 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
2273 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
2276 /* Window messages we need to process */
2278 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2281 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2284 return COMBOEX_Destroy (infoPtr);
2286 case WM_MEASUREITEM:
2287 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2289 case WM_NOTIFYFORMAT:
2290 return COMBOEX_NotifyFormat (infoPtr, lParam);
2293 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2296 return COMBOEX_SetRedraw(infoPtr, wParam, lParam);
2298 case WM_WINDOWPOSCHANGING:
2299 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2302 SetFocus(infoPtr->hwndCombo);
2305 case WM_SYSCOLORCHANGE:
2306 COMCTL32_RefreshSysColors();
2310 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2311 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",uMsg,wParam,lParam);
2312 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2317 void COMBOEX_Register (void)
2321 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2322 wndClass.style = CS_GLOBALCLASS;
2323 wndClass.lpfnWndProc = COMBOEX_WindowProc;
2324 wndClass.cbClsExtra = 0;
2325 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2326 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2327 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2328 wndClass.lpszClassName = WC_COMBOBOXEXW;
2330 RegisterClassW (&wndClass);
2334 void COMBOEX_Unregister (void)
2336 UnregisterClassW (WC_COMBOBOXEXW, NULL);