2 * ComboBoxEx control v2 (mod3)
4 * Copyright 1998, 1999 Eric Kohl
7 * This is just a dummy control. An author is needed! Any volunteers?
8 * I will only improve this control once in a while.
9 * Eric <ekohl@abo.rhein-zeitung.de>
13 * - All notifications.
16 * - should include "combo.h"
18 * Changes Guy Albertelli <galberte@neo.lrun.com>
19 * v1 Implemented messages: CB_SETITEMHEIGHT, WM_WINDOWPOSCHANGING,
20 * WM_DRAWITEM, and WM_MEASUREITEM. Fixed WM_CREATE. Fixed height
21 * of window rect reported fixing rebar control.
23 * 1. Rewrite of WM_Create for own created EDIT control. Also try to
24 * generate message sequence similar to native DLL.
25 * 2. Handle case where CBEM_SETITEM is called to display data in EDIT
27 * 3. Add override for WNDPROC for the EDIT control (reqed for VK_RETURN).
28 * 4. Dump input data for things using COMBOBOXEXITEM{A|W}.
29 * 5. Handle positioning EDIT control based on whether icon present.
30 * 6. Make InsertItemA use InsertItemW, and store all data in ..W form.
31 * 7. Implement CBEM_DELETEITEM, CBEM_GETITEM{A|W}, CB_SETCURSEL,
32 * CBEM_{GET|SET}UNICODEFORMAT.
33 * 8. Add override for WNDPROC for the COMBO control.
34 * 9. Support extended style CBES_EX_NOEDITIMAGE and warn others are not
36 * 10. Implement CB_FINDSTRINGEXACT in both the Combo and ComboEx window
37 * procs to match the items. This eliminates dup entries in the listbox.
39 * Test vehicals were the ControlSpy modules (rebar.exe and comboboxex.exe),
46 #include "debugtools.h"
47 #include "wine/unicode.h"
49 DEFAULT_DEBUG_CHANNEL(comboex);
51 * The following is necessary for the test done in COMBOEX_DrawItem
52 * to determine whether to dump out the DRAWITEM structure or not.
54 DECLARE_DEBUG_CHANNEL(message);
70 /* ComboBoxEx structure */
74 HWND hwndSelf; /* my own hwnd */
77 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
78 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
80 DWORD flags; /* WINE internal flags */
82 INT nb_items; /* Number of items */
83 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
84 CBE_ITEMDATA *edit; /* item data for edit item */
85 CBE_ITEMDATA *items; /* Array of items */
88 /* internal flags in the COMBOEX_INFO structure */
89 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
90 * CBEN_BEGINEDIT issued
91 * but CBEN_ENDEDIT{A|W}
93 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
96 #define ID_CB_EDIT 1001
100 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
101 * the ComboEx version of the Combo Window Proc so that when the
102 * WM_DRAWITEM message is then passed to ComboEx, we know that this
103 * particular WM_DRAWITEM message is for listbox only items. Any messasges
104 * without this flag is then for the Edit control field.
106 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
107 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
109 #define ODS_COMBOEXLBOX 0x4000
113 /* Height in pixels of control over the amount of the selected font */
116 /* Indent amount per MS documentation */
117 #define CBE_INDENT 10
119 /* Offset in pixels from left side for start of image or text */
120 #define CBE_STARTOFFSET 6
122 /* Offset between image and text */
125 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
128 /* Things common to the entire DLL */
129 static ATOM ComboExInfo;
130 static LRESULT WINAPI
131 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
132 static LRESULT WINAPI
133 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
136 COMBOEX_DumpItem (CBE_ITEMDATA *item)
138 if (TRACE_ON(comboex)){
139 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
140 item, item->mask, item->pszText, item->cchTextMax,
142 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
143 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
144 if ((item->mask & CBEIF_TEXT) && item->pszText)
145 TRACE("item %p - pszText=%s\n",
146 item, debugstr_w((const WCHAR *)item->pszText));
152 COMBOEX_DumpInput (COMBOBOXEXITEMA *input, BOOL true_for_w)
154 if (TRACE_ON(comboex)){
155 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
156 input->mask, input->iItem, input->pszText, input->cchTextMax,
158 if ((input->mask & CBEIF_TEXT) && input->pszText) {
160 TRACE("input - pszText=<%s>\n",
161 debugstr_w((const WCHAR *)input->pszText));
163 TRACE("input - pszText=<%s>\n",
164 debugstr_a((const char *)input->pszText));
166 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
167 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
172 inline static LRESULT
173 COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
175 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
177 if (infoPtr->hwndCombo)
178 return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
185 COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr, BOOL doW)
188 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
189 hdr->hwndFrom = infoPtr->hwndSelf;
192 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
195 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
201 COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
206 mydc = GetDC (0); /* why the entire screen???? */
207 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
208 ofont = (HFONT) SelectObject (mydc, nfont);
209 GetTextExtentPointA (mydc, "A", 1, size);
210 SelectObject (mydc, ofont);
212 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
217 COMBOEX_CopyItem (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
219 if (cit->mask & CBEIF_TEXT) {
220 cit->pszText = item->pszText;
221 cit->cchTextMax = item->cchTextMax;
223 if (cit->mask & CBEIF_IMAGE)
224 cit->iImage = item->iImage;
225 if (cit->mask & CBEIF_SELECTEDIMAGE)
226 cit->iSelectedImage = item->iSelectedImage;
227 if (cit->mask & CBEIF_OVERLAY)
228 cit->iOverlay = item->iOverlay;
229 if (cit->mask & CBEIF_INDENT)
230 cit->iIndent = item->iIndent;
231 if (cit->mask & CBEIF_LPARAM)
232 cit->lParam = item->lParam;
238 COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
242 INT x, y, w, h, xoff = 0;
245 if (!infoPtr->hwndEdit) return;
246 iinfo.rcImage.left = iinfo.rcImage.right = 0;
248 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
249 xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
251 GetClientRect (infoPtr->hwndCombo, &rect);
252 InflateRect (&rect, -2, -2);
253 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
255 /* reposition the Edit control based on whether icon exists */
256 COMBOEX_GetComboFontSize (infoPtr, &mysize);
257 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
258 x = xoff + CBE_STARTOFFSET + 1;
260 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
263 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
264 rect.left, rect.top, rect.right, rect.bottom,
266 SetWindowPos(infoPtr->hwndEdit, HWND_TOP,
269 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
274 COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
280 COMBOEX_GetComboFontSize (infoPtr, &mysize);
281 cy = mysize.cy + CBE_EXTRA;
283 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
284 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
285 TRACE("upgraded height due to image: height=%d\n", cy);
287 SendMessageW (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
288 if (infoPtr->hwndCombo)
289 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
290 (WPARAM) 0, (LPARAM) cy);
295 COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
297 if (!infoPtr->hwndEdit) return;
298 /* native issues the following messages to the {Edit} control */
299 /* WM_SETTEXT (0,addr) */
300 /* EM_SETSEL32 (0,0) */
301 /* EM_SETSEL32 (0,-1) */
302 if (item->mask & CBEIF_TEXT) {
303 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
304 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
305 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
310 static CBE_ITEMDATA *
311 COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
316 if ((index > infoPtr->nb_items) || (index < -1))
319 return infoPtr->edit;
320 item = infoPtr->items;
321 i = infoPtr->nb_items - 1;
323 /* find the item in the list */
324 while (item && (i > index)) {
325 item = (CBE_ITEMDATA *)item->next;
328 if (!item || (i != index)) {
329 FIXME("COMBOBOXEX item structures broken. Please report!\n");
336 /* *** CBEM_xxx message support *** */
340 COMBOEX_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
342 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
343 INT index = (INT) wParam;
346 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
348 /* if item number requested does not exist then return failure */
349 if ((index > infoPtr->nb_items) || (index < 0)) {
350 ERR("attempt to delete item that does not exist\n");
354 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
355 ERR("attempt to delete item that was not found!\n");
359 /* doing this will result in WM_DELETEITEM being issued */
360 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
362 return infoPtr->nb_items;
366 inline static LRESULT
367 COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
369 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
373 return (LRESULT)infoPtr->hwndCombo;
377 inline static LRESULT
378 COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
380 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
382 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
385 TRACE("-- 0x%x\n", infoPtr->hwndEdit);
387 return (LRESULT)infoPtr->hwndEdit;
391 inline static LRESULT
392 COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
394 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
396 return (LRESULT)infoPtr->dwExtStyle;
400 inline static LRESULT
401 COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
403 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
405 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
407 return (LRESULT)infoPtr->himl;
412 COMBOEX_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
414 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
415 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
419 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
421 /* get real index of item to insert */
424 /* if item number requested does not exist then return failure */
425 if ((index > infoPtr->nb_items) || (index < -1)) {
426 ERR("attempt to get item that does not exist\n");
430 /* if the item is the edit control and there is no edit control, skip */
432 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
435 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
436 ERR("attempt to get item that was not found!\n");
440 COMBOEX_CopyItem (infoPtr, item, cit);
446 inline static LRESULT
447 COMBOEX_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
449 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
450 COMBOBOXEXITEMW tmpcit;
453 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
455 tmpcit.mask = cit->mask;
456 tmpcit.iItem = cit->iItem;
457 COMBOEX_GetItemW (hwnd, wParam, (LPARAM) &tmpcit);
459 len = WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1, 0, 0, NULL, NULL);
461 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
462 cit->pszText, cit->cchTextMax, NULL, NULL);
464 cit->iImage = tmpcit.iImage;
465 cit->iSelectedImage = tmpcit.iSelectedImage;
466 cit->iOverlay = tmpcit.iOverlay;
467 cit->iIndent = tmpcit.iIndent;
468 cit->lParam = tmpcit.lParam;
474 inline static LRESULT
475 COMBOEX_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
477 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
479 TRACE("%s hwnd=0x%x stub!\n",
480 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
482 return infoPtr->bUnicode;
486 inline static LRESULT
487 COMBOEX_HasEditChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
489 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
491 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
493 if ((infoPtr->flags & (WCBE_ACTEDIT | WCBE_EDITCHG)) ==
494 (WCBE_ACTEDIT | WCBE_EDITCHG))
501 COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
503 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
504 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
511 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
513 /* get real index of item to insert */
515 if (index == -1) index = infoPtr->nb_items;
516 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
518 /* get space and chain it in */
519 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
521 item->pszText = NULL;
523 /* locate position to insert new item in */
524 if (index == infoPtr->nb_items) {
525 /* fast path for iItem = -1 */
526 item->next = infoPtr->items;
527 infoPtr->items = item;
530 INT i = infoPtr->nb_items-1;
531 CBE_ITEMDATA *moving = infoPtr->items;
533 while ((i > index) && moving) {
534 moving = (CBE_ITEMDATA *)moving->next;
538 FIXME("COMBOBOXEX item structures broken. Please report!\n");
542 item->next = moving->next;
546 /* fill in our hidden item structure */
547 item->mask = cit->mask;
548 if (item->mask & CBEIF_TEXT) {
553 if (!str) str = (LPWSTR) L"";
556 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
557 strcpyW (item->pszText, str);
559 item->cchTextMax = cit->cchTextMax;
561 if (item->mask & CBEIF_IMAGE)
562 item->iImage = cit->iImage;
563 if (item->mask & CBEIF_SELECTEDIMAGE)
564 item->iSelectedImage = cit->iSelectedImage;
565 if (item->mask & CBEIF_OVERLAY)
566 item->iOverlay = cit->iOverlay;
567 if (item->mask & CBEIF_INDENT)
568 item->iIndent = cit->iIndent;
569 if (item->mask & CBEIF_LPARAM)
570 item->lParam = cit->lParam;
573 COMBOEX_DumpItem (item);
575 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
576 (WPARAM)cit->iItem, (LPARAM)item);
578 COMBOEX_CopyItem (infoPtr, item, &nmcit.ceItem);
579 COMBOEX_Notify (infoPtr, CBEN_INSERTITEM, (NMHDR *)&nmcit, TRUE);
587 COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
589 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
590 COMBOBOXEXITEMW citW;
593 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
594 if (cit->mask & CBEIF_TEXT) {
600 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
602 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
603 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
606 ret = COMBOEX_InsertItemW(hwnd,wParam,(LPARAM)&citW);;
608 if (cit->mask & CBEIF_TEXT)
609 COMCTL32_Free(citW.pszText);
615 COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
617 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
620 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
622 dwTemp = infoPtr->dwExtStyle;
624 if (lParam & (CBES_EX_NOEDITIMAGEINDENT |
625 CBES_EX_PATHWORDBREAKPROC |
626 CBES_EX_NOSIZELIMIT |
627 CBES_EX_CASESENSITIVE))
628 FIXME("Extended style not implemented %08lx\n", lParam);
631 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
634 infoPtr->dwExtStyle = (DWORD)lParam;
637 * native does this for CBES_EX_NOEDITIMAGE state change
639 if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
640 (dwTemp & CBES_EX_NOEDITIMAGE)) {
641 /* if state of EX_NOEDITIMAGE changes, invalidate all */
642 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
643 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
644 InvalidateRect (hwnd, NULL, TRUE);
645 COMBOEX_AdjustEditPos (infoPtr);
646 if (infoPtr->hwndEdit)
647 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
650 return (LRESULT)dwTemp;
654 inline static LRESULT
655 COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
657 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
660 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
662 himlTemp = infoPtr->himl;
663 infoPtr->himl = (HIMAGELIST)lParam;
665 COMBOEX_ReSize (hwnd, infoPtr);
666 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
668 /* reposition the Edit control based on whether icon exists */
669 COMBOEX_AdjustEditPos (infoPtr);
670 return (LRESULT)himlTemp;
674 COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
676 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
677 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
681 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
683 /* get real index of item to insert */
686 /* if item number requested does not exist then return failure */
687 if ((index > infoPtr->nb_items) || (index < -1)) {
688 ERR("attempt to set item that does not exist yet!\n");
692 /* if the item is the edit control and there is no edit control, skip */
694 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
697 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
698 ERR("attempt to set item that was not found!\n");
702 /* add/change stuff to the internal item structure */
703 item->mask |= cit->mask;
704 if (cit->mask & CBEIF_TEXT) {
707 WCHAR emptystr[1] = {0};
710 if (!str) str=emptystr;
713 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
714 strcpyW(item->pszText,str);
716 item->cchTextMax = cit->cchTextMax;
718 if (cit->mask & CBEIF_IMAGE)
719 item->iImage = cit->iImage;
720 if (cit->mask & CBEIF_SELECTEDIMAGE)
721 item->iSelectedImage = cit->iSelectedImage;
722 if (cit->mask & CBEIF_OVERLAY)
723 item->iOverlay = cit->iOverlay;
724 if (cit->mask & CBEIF_INDENT)
725 item->iIndent = cit->iIndent;
726 if (cit->mask & CBEIF_LPARAM)
727 cit->lParam = cit->lParam;
729 COMBOEX_DumpItem (item);
731 /* if original request was to update edit control, do some fast foot work */
732 if (cit->iItem == -1) {
733 COMBOEX_SetEditText (infoPtr, item);
734 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
740 COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
742 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
743 COMBOBOXEXITEMW citW;
746 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
747 if (cit->mask & CBEIF_TEXT) {
753 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
755 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
756 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
759 ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
761 if (cit->mask & CBEIF_TEXT)
762 COMCTL32_Free(citW.pszText);
767 inline static LRESULT
768 COMBOEX_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
770 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
773 TRACE("%s hwnd=0x%04x stub!\n",
774 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
776 bTemp = infoPtr->bUnicode;
777 infoPtr->bUnicode = (BOOL)wParam;
784 /* *** CB_xxx message support *** */
788 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
792 LPWSTR desired = NULL;
793 INT start = (INT) wParam;
795 i = MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
797 desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
798 MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, desired, i);
801 count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0 , 0);
803 /* now search from after starting loc and wrapping back to start */
804 for(i=start+1; i<count; i++) {
805 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
806 CB_GETITEMDATA, (WPARAM)i, 0);
807 TRACE("desired=%s, item=%s\n",
808 debugstr_w(desired), debugstr_w(item->pszText));
809 if (lstrcmpiW(item->pszText, desired) == 0) {
810 COMCTL32_Free (desired);
814 for(i=0; i<=start; i++) {
815 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
816 CB_GETITEMDATA, (WPARAM)i, 0);
817 TRACE("desired=%s, item=%s\n",
818 debugstr_w(desired), debugstr_w(item->pszText));
819 if (lstrcmpiW(item->pszText, desired) == 0) {
820 COMCTL32_Free (desired);
824 COMCTL32_Free(desired);
830 COMBOEX_SetCursel (HWND hwnd, WPARAM wParam, LPARAM lParam)
833 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
837 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
838 /* FIXME: need to clear selection */
842 TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
843 debugstr_w(item->pszText) : "<null>");
845 lret = SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, wParam, lParam);
846 COMBOEX_SetEditText (infoPtr, item);
852 COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
854 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
855 RECT cb_wrect, cbx_wrect, cbx_crect;
859 /* First, lets forward the message to the normal combo control
860 just like Windows. */
861 if (infoPtr->hwndCombo)
862 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
864 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
865 GetWindowRect (hwnd, &cbx_wrect);
866 GetClientRect (hwnd, &cbx_crect);
867 /* the height of comboex as height of the combo + comboex border */
868 height = cb_wrect.bottom-cb_wrect.top
869 + cbx_wrect.bottom-cbx_wrect.top
870 - (cbx_crect.bottom-cbx_crect.top);
871 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
872 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
873 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
874 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
875 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
876 cbx_wrect.right-cbx_wrect.left, height);
877 SetWindowPos (hwnd, HWND_TOP, 0, 0,
878 cbx_wrect.right-cbx_wrect.left,
880 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
886 /* *** WM_xxx message support *** */
890 COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
892 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
893 COMBOEX_INFO *infoPtr;
897 RECT wnrc1, clrc1, cmbwrc;
900 /* allocate memory for info structure */
901 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
902 if (infoPtr == NULL) {
903 ERR("could not allocate info memory!\n");
907 /* initialize info structure */
909 infoPtr->items = NULL;
910 infoPtr->nb_items = 0;
911 infoPtr->hwndSelf = hwnd;
913 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
915 /* create combo box */
916 dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
917 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
919 TRACE("combo style=%08lx, additional style=%08lx\n", dwComboStyle,
920 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
921 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
922 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED);
924 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
925 /* specified. It then creates it's own version of the EDIT control */
926 /* and makes the ComboBox the parent. This is because a normal */
927 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
928 /* We also need to place the edit control at the proper location */
929 /* (allow space for the icons). */
931 infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
932 /* following line added to match native */
933 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
934 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
935 /* was base and is necessary */
936 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
937 cs->y, cs->x, cs->cx, cs->cy, hwnd,
938 (HMENU) GetWindowLongA (hwnd, GWL_ID),
939 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
942 * native does the following at this point according to trace:
943 * GetWindowThreadProcessId(hwndCombo,0)
944 * GetCurrentThreadId()
945 * GetWindowThreadProcessId(hwndCombo, &???)
946 * GetCurrentProcessId()
950 * Setup a property to hold the pointer to the COMBOBOXEX
953 test = GetPropA(infoPtr->hwndCombo, (LPCSTR)(LONG)ComboExInfo);
954 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
955 SetPropA(infoPtr->hwndCombo, "CC32SubclassInfo", (LONG)infoPtr);
957 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndCombo,
958 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
959 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
963 * Now create our own EDIT control so we can position it.
964 * It is created only for CBS_DROPDOWN style
966 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
967 infoPtr->hwndEdit = CreateWindowExA (0, "EDIT", "",
968 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
969 0, 0, 0, 0, /* will set later */
971 (HMENU) GetWindowLongA (hwnd, GWL_ID),
972 GetWindowLongA (hwnd, GWL_HINSTANCE),
975 /* native does the following at this point according to trace:
976 * GetWindowThreadProcessId(hwndEdit,0)
977 * GetCurrentThreadId()
978 * GetWindowThreadProcessId(hwndEdit, &???)
979 * GetCurrentProcessId()
983 * Setup a property to hold the pointer to the COMBOBOXEX
986 test = GetPropA(infoPtr->hwndEdit, (LPCSTR)(LONG)ComboExInfo);
987 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
988 SetPropA(infoPtr->hwndEdit, "CC32SubclassInfo", (LONG)infoPtr);
990 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndEdit,
991 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
992 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
995 infoPtr->hwndEdit = 0;
1000 * Locate the default font if necessary and then set it in
1001 * all associated controls
1003 if (!infoPtr->font) {
1004 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1006 infoPtr->font = CreateFontIndirectA (&mylogfont);
1008 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1009 if (infoPtr->hwndEdit) {
1010 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1011 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1014 COMBOEX_ReSize (hwnd, infoPtr);
1016 /* Above is fairly certain, below is much less certain. */
1018 GetWindowRect(hwnd, &wnrc1);
1019 GetClientRect(hwnd, &clrc1);
1020 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1021 TRACE("Ex wnd=(%d,%d)-(%d,%d) Ex clt=(%d,%d)-(%d,%d) Cb wnd=(%d,%d)-(%d,%d)\n",
1022 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1023 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1024 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1025 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1026 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1027 SWP_NOACTIVATE | SWP_NOREDRAW);
1029 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1030 TRACE("Ex wnd=(%d,%d)-(%d,%d)\n",
1031 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1032 SetWindowPos(hwnd, HWND_TOP,
1033 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1034 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1036 COMBOEX_AdjustEditPos (infoPtr);
1039 * Create an item structure to represent the data in the
1042 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1044 item->pszText = NULL;
1046 infoPtr->edit = item;
1052 inline static LRESULT
1053 COMBOEX_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
1056 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1057 INT command = HIWORD(wParam);
1058 CBE_ITEMDATA *item = 0;
1061 NMCBEENDEDITA cbeend;
1063 TRACE("for command %d\n", command);
1068 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1071 * from native trace of first dropdown after typing in URL in IE4
1072 * CB_GETCURSEL(Combo)
1073 * GetWindowText(Edit)
1074 * CB_GETCURSEL(Combo)
1075 * CB_GETCOUNT(Combo)
1076 * CB_GETITEMDATA(Combo, n)
1077 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1078 * CB_GETCURSEL(Combo)
1079 * CB_SETCURSEL(COMBOEX, n)
1081 * the rest is supposition
1083 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1085 /* find match from edit against those in Combobox */
1086 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1087 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1088 for (cursel = 0; cursel < n; cursel++){
1089 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1092 if ((INT)item == CB_ERR) break;
1093 if (lstrcmpiW(item->pszText, wintext) == 0) break;
1095 if ((cursel == n) || ((INT)item == CB_ERR)) {
1096 TRACE("failed to find match??? item=%p cursel=%d\n",
1098 if (infoPtr->hwndEdit)
1099 SetFocus(infoPtr->hwndEdit);
1103 if (infoPtr->flags & WCBE_ACTEDIT) {
1104 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1105 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1106 CB_GETCURSEL, 0, 0);
1107 cbeend.iWhy = CBENF_DROPDOWN;
1109 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1110 if (COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1111 (NMHDR *)&cbeend, FALSE)) {
1112 /* abort the change */
1113 TRACE("Notify requested abort of change\n");
1117 SendMessageW (hwnd, CB_SETCURSEL, cursel, 0);
1118 SetFocus(infoPtr->hwndCombo);
1123 * We have to change the handle since we are the control
1124 * issuing the message. IE4 depends on this.
1125 * We also need to set the focus back to the Edit control
1126 * after passing the command to the parent of the ComboEx.
1128 lret = SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1130 if (infoPtr->hwndEdit)
1131 SetFocus(infoPtr->hwndEdit);
1138 inline static LRESULT
1139 COMBOEX_WM_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1141 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1142 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)lParam;
1143 CBE_ITEMDATA *item, *olditem;
1145 NMCOMBOBOXEXW nmcit;
1147 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1148 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1150 if ((dis->itemID >= infoPtr->nb_items) || (dis->itemID < 0)) return FALSE;
1152 olditem = infoPtr->items;
1153 i = infoPtr->nb_items - 1;
1155 if (i == dis->itemID) {
1156 infoPtr->items = infoPtr->items->next;
1162 /* find the prior item in the list */
1163 while (item->next && (i > dis->itemID)) {
1164 item = (CBE_ITEMDATA *)item->next;
1167 if (!item->next || (i != dis->itemID)) {
1168 FIXME("COMBOBOXEX item structures broken. Please report!\n");
1171 olditem = item->next;
1172 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1174 infoPtr->nb_items--;
1176 COMBOEX_CopyItem (infoPtr, olditem, &nmcit.ceItem);
1177 COMBOEX_Notify (infoPtr, CBEN_DELETEITEM, (NMHDR *)&nmcit, TRUE);
1179 COMCTL32_Free(olditem);
1186 inline static LRESULT
1187 COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1189 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1190 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
1191 CBE_ITEMDATA *item = 0;
1196 UINT xioff = 0; /* size and spacer of image if any */
1200 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1203 /* "itemID - Specifies the menu item identifier for a menu */
1204 /* item or the index of the item in a list box or combo box. */
1205 /* For an empty list box or combo box, this member can be -1. */
1206 /* This allows the application to draw only the focus */
1207 /* rectangle at the coordinates specified by the rcItem */
1208 /* member even though there are no items in the control. */
1209 /* This indicates to the user whether the list box or combo */
1210 /* box has the focus. How the bits are set in the itemAction */
1211 /* member determines whether the rectangle is to be drawn as */
1212 /* though the list box or combo box has the focus. */
1213 if (dis->itemID == 0xffffffff) {
1214 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1215 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1217 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1218 dis->rcItem.left, dis->rcItem.top,
1219 dis->rcItem.right, dis->rcItem.bottom);
1221 else if ((dis->CtlType == ODT_COMBOBOX) &&
1222 (dis->itemAction == ODA_DRAWENTIRE)) {
1223 /* draw of edit control data */
1227 RECT exrc, cbrc, edrc;
1228 GetWindowRect (hwnd, &exrc);
1229 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1230 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1231 if (infoPtr->hwndEdit)
1232 GetWindowRect (infoPtr->hwndEdit, &edrc);
1233 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1234 exrc.left, exrc.top, exrc.right, exrc.bottom,
1235 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1236 edrc.left, edrc.top, edrc.right, edrc.bottom);
1240 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1241 dis->rcItem.left, dis->rcItem.top,
1242 dis->rcItem.right, dis->rcItem.bottom,
1243 dis->itemAction, dis->itemState);
1248 /* If draw item is -1 (edit control) setup the item pointer */
1249 if (dis->itemID == 0xffffffff) {
1253 if (!infoPtr->hwndEdit) {
1254 ERR("request to draw edit item, but no edit control exists!\n");
1258 item = infoPtr->edit;
1259 /* free previous text of edit item */
1260 if (item->pszText) {
1261 COMCTL32_Free(item->pszText);
1263 item->mask &= ~CBEIF_TEXT;
1265 alen = SendMessageA (infoPtr->hwndEdit, WM_GETTEXT, 260, (LPARAM)&str);
1266 TRACE("edit control hwndEdit=%0x, text len=%d str=<%s>\n",
1267 infoPtr->hwndEdit, alen, str);
1269 item->mask |= CBEIF_TEXT;
1270 wlen = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
1272 item->pszText = (LPWSTR)COMCTL32_Alloc ((wlen + 1)*sizeof(WCHAR));
1273 MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, wlen);
1278 /* if the item pointer is not set, then get the data and locate it */
1280 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1281 CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
1282 if (item == (CBE_ITEMDATA *)CB_ERR)
1284 FIXME("invalid item for id %d \n",dis->itemID);
1289 /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
1290 if (!TRACE_ON(message)) {
1291 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1292 dis->CtlType, dis->CtlID);
1293 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1294 dis->itemID, dis->itemAction, dis->itemState);
1295 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1296 dis->hwndItem, dis->hDC, dis->rcItem.left,
1297 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1300 COMBOEX_DumpItem (item);
1302 xbase = CBE_STARTOFFSET;
1303 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
1304 xbase += (item->iIndent * CBE_INDENT);
1305 if (item->mask & CBEIF_IMAGE) {
1306 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
1307 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
1310 switch (dis->itemAction) {
1312 if (dis->itemState & ODS_SELECTED /*1*/) {
1313 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1316 len = strlenW (item->pszText);
1317 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1318 rect.left = xbase + xioff - 1;
1319 rect.right = rect.left + txtsize.cx + 2;
1320 rect.top = dis->rcItem.top;
1321 rect.bottom = dis->rcItem.bottom;
1322 GetClipBox (dis->hDC, &rect2);
1323 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
1324 dis->itemID, rect.left, rect.top,
1325 rect.right, rect.bottom);
1326 TRACE(" clip=(%d,%d)-(%d,%d)\n",
1327 rect2.left, rect2.top,
1328 rect2.right, rect2.bottom);
1330 DrawFocusRect(dis->hDC, &rect);
1333 FIXME("ODA_FOCUS and ODS_SELECTED but no text\n");
1337 FIXME("ODA_FOCUS but not ODS_SELECTED\n");
1341 case ODA_DRAWENTIRE:
1343 if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
1344 if (item->mask & CBEIF_IMAGE) drawimage = item->iImage;
1345 if ((dis->itemState & ODS_SELECTED) &&
1346 (item->mask & CBEIF_SELECTEDIMAGE))
1347 drawimage = item->iSelectedImage;
1349 if (drawimage != -1) {
1350 TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
1351 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
1352 xbase, dis->rcItem.top,
1353 (dis->itemState & ODS_SELECTED) ?
1354 ILD_SELECTED : ILD_NORMAL);
1356 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1358 COLORREF nbkc, ntxc;
1360 len = lstrlenW (item->pszText);
1361 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1362 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1363 COLOR_HIGHLIGHT : COLOR_WINDOW);
1364 SetBkColor (dis->hDC, nbkc);
1365 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1366 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1367 SetTextColor (dis->hDC, ntxc);
1369 y = dis->rcItem.top +
1370 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1372 rect.right = x + txtsize.cx;
1373 rect.top = dis->rcItem.top + 1;
1374 rect.bottom = dis->rcItem.bottom - 1;
1375 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1376 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1377 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1378 &rect, item->pszText, len, 0);
1379 if (dis->itemState & ODS_FOCUS) {
1384 TRACE("drawing item %d focus after text, rect=(%d,%d)-(%d,%d)\n",
1385 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1386 DrawFocusRect (dis->hDC, &rect);
1391 FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
1392 hwnd, wParam, lParam, dis->itemAction);
1400 COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1402 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1404 if (infoPtr->hwndCombo)
1405 DestroyWindow (infoPtr->hwndCombo);
1407 if (infoPtr->edit) {
1408 COMCTL32_Free (infoPtr->edit);
1412 if (infoPtr->items) {
1413 CBE_ITEMDATA *this, *next;
1415 this = infoPtr->items;
1417 next = (CBE_ITEMDATA *)this->next;
1418 if ((this->mask & CBEIF_TEXT) && this->pszText)
1419 COMCTL32_Free (this->pszText);
1420 COMCTL32_Free (this);
1425 DeleteObject (infoPtr->font);
1427 /* free comboex info data */
1428 COMCTL32_Free (infoPtr);
1429 SetWindowLongA (hwnd, 0, 0);
1435 COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1437 /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
1438 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
1443 GetTextExtentPointA (hdc, "W", 1, &mysize);
1445 mis->itemHeight = mysize.cy + CBE_EXTRA;
1447 TRACE("adjusted height hwnd=%08x, height=%d\n",
1448 hwnd, mis->itemHeight);
1455 COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1457 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1460 GetWindowRect (hwnd, &rect);
1461 TRACE("my rect (%d,%d)-(%d,%d)\n",
1462 rect.left, rect.top, rect.right, rect.bottom);
1464 MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
1465 rect.bottom - rect.top, TRUE);
1467 COMBOEX_AdjustEditPos (infoPtr);
1474 COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
1476 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1478 RECT cbx_wrect, cbx_crect, cb_wrect;
1480 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1482 ret = DefWindowProcA (hwnd, WM_WINDOWPOSCHANGING, wParam, lParam);
1483 GetWindowRect (hwnd, &cbx_wrect);
1484 GetClientRect (hwnd, &cbx_crect);
1485 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1487 /* width is winpos value + border width of comboex */
1489 + cbx_wrect.right-cbx_wrect.left
1490 - (cbx_crect.right - cbx_crect.left);
1492 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1493 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1494 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1495 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1496 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1497 width, cb_wrect.bottom-cb_wrect.top);
1499 SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1501 cb_wrect.bottom-cb_wrect.top,
1504 COMBOEX_AdjustEditPos (infoPtr);
1510 static LRESULT WINAPI
1511 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1513 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1514 NMCBEENDEDITA cbeend;
1515 COLORREF nbkc, obkc;
1519 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1520 hwnd, uMsg, wParam, lParam, infoPtr);
1522 if (!infoPtr) return 0;
1528 /* handle (ignore) the return character */
1529 if (wParam == VK_RETURN) return 0;
1530 /* all other characters pass into the real Edit */
1531 return CallWindowProcA (infoPtr->prevEditWndProc,
1532 hwnd, uMsg, wParam, lParam);
1536 * The following was determined by traces of the native
1539 nbkc = GetSysColor (COLOR_WINDOW);
1540 obkc = SetBkColor (hDC, nbkc);
1541 GetClientRect (hwnd, &rect);
1542 TRACE("erasing (%d,%d)-(%d,%d)\n",
1543 rect.left, rect.top, rect.right, rect.bottom);
1544 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1545 SetBkColor (hDC, obkc);
1546 return CallWindowProcA (infoPtr->prevEditWndProc,
1547 hwnd, uMsg, wParam, lParam);
1550 INT oldItem, selected;
1552 WCHAR edit_text[260];
1554 switch ((INT)wParam)
1557 /* native version seems to do following for COMBOEX */
1559 * GetWindowTextA(Edit,&?, 0x104) x
1560 * CB_GETCURSEL to Combo rets -1 x
1561 * WM_NOTIFY to COMBOEX parent (rebar) x
1562 * (CBEN_ENDEDIT{A|W}
1563 * fChanged = FALSE x
1564 * inewSelection = -1 x
1567 * CB_GETCURSEL to Combo rets -1 x
1568 * InvalidateRect(Combo, 0) x
1569 * WM_SETTEXT to Edit x
1570 * EM_SETSEL to Edit (0,0) x
1571 * EM_SETSEL to Edit (0,-1) x
1572 * RedrawWindow(Combo, 0, 0, 5) x
1574 TRACE("special code for VK_ESCAPE\n");
1576 GetWindowTextA (infoPtr->hwndEdit, cbeend.szText, 260);
1578 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1579 cbeend.fChanged = FALSE;
1580 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1581 CB_GETCURSEL, 0, 0);
1582 cbeend.iWhy = CBENF_ESCAPE;
1584 if (COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1585 (NMHDR *)&cbeend, FALSE)) {
1586 /* abort the change */
1587 TRACE("Notify requested abort of change\n");
1590 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1591 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1592 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1593 ERR("item %d not found. Problem!\n", oldItem);
1597 COMBOEX_SetEditText (infoPtr, item);
1598 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1603 /* native version seems to do following for COMBOEX */
1605 * GetWindowTextA(Edit,&?, 0x104) x
1606 * CB_GETCURSEL to Combo rets -1 x
1607 * CB_GETCOUNT to Combo rets 0
1609 * CB_GETITEMDATA to match
1610 * *** above 3 lines simulated by FindItem x
1611 * WM_NOTIFY to COMBOEX parent (rebar) x
1612 * (CBEN_ENDEDIT{A|W} x
1613 * fChanged = TRUE (-1) x
1614 * iNewSelection = -1 or selected x
1616 * iWhy = 2 (CBENF_RETURN) x
1617 * CB_GETCURSEL to Combo rets -1 x
1618 * if -1 send CB_SETCURSEL to Combo -1 x
1619 * InvalidateRect(Combo, 0, 0) x
1621 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1624 TRACE("special code for VK_RETURN\n");
1626 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1628 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1629 selected = SendMessageW (infoPtr->hwndCombo,
1630 CB_GETCURSEL, 0, 0);
1632 if (selected != -1) {
1633 item = COMBOEX_FindItem (infoPtr, selected);
1634 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1635 selected, debugstr_w(item->pszText));
1636 TRACE("handling VK_RETURN, edittext=%s\n",
1637 debugstr_w(edit_text));
1638 if (lstrcmpiW (item->pszText, edit_text)) {
1639 /* strings not equal -- indicate edit has changed */
1644 cbeend.iNewSelection = selected;
1645 cbeend.fChanged = TRUE;
1646 cbeend.iWhy = CBENF_RETURN;
1647 WideCharToMultiByte (CP_ACP, 0, edit_text, -1,
1648 cbeend.szText, sizeof(cbeend.szText),
1651 if (COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1652 (NMHDR *)&cbeend, FALSE)) {
1653 /* abort the change, restore previous */
1654 TRACE("Notify requested abort of change\n");
1655 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1656 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1660 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1661 if (oldItem != -1) {
1662 /* if something is selected, then deselect it */
1663 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1666 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1667 SetFocus(infoPtr->hwndEdit);
1671 return CallWindowProcA (infoPtr->prevEditWndProc,
1672 hwnd, uMsg, wParam, lParam);
1679 * should do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1681 if (infoPtr->flags & WCBE_ACTEDIT) {
1682 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1683 cbeend.fChanged = FALSE;
1684 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1685 CB_GETCURSEL, 0, 0);
1686 cbeend.iWhy = CBENF_KILLFOCUS;
1688 COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1689 (NMHDR *)&cbeend, FALSE);
1694 return CallWindowProcA (infoPtr->prevEditWndProc,
1695 hwnd, uMsg, wParam, lParam);
1701 static LRESULT WINAPI
1702 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1704 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1706 COLORREF nbkc, obkc;
1710 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1711 hwnd, uMsg, wParam, lParam, infoPtr);
1713 if (!infoPtr) return 0;
1718 case CB_FINDSTRINGEXACT:
1719 return COMBOEX_FindStringExact (infoPtr, wParam, lParam);
1723 * The only way this message should come is from the
1724 * child Listbox issuing the message. Flag this so
1725 * that ComboEx knows this is listbox.
1727 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1728 return CallWindowProcA (infoPtr->prevComboWndProc,
1729 hwnd, uMsg, wParam, lParam);
1733 * The following was determined by traces of the native
1736 nbkc = GetSysColor (COLOR_WINDOW);
1737 obkc = SetBkColor (hDC, nbkc);
1738 GetClientRect (hwnd, &rect);
1739 TRACE("erasing (%d,%d)-(%d,%d)\n",
1740 rect.left, rect.top, rect.right, rect.bottom);
1741 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1742 SetBkColor (hDC, obkc);
1743 return CallWindowProcA (infoPtr->prevComboWndProc,
1744 hwnd, uMsg, wParam, lParam);
1748 * WM_NOTIFY to comboex parent (rebar)
1749 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1750 * CallWindowProc (previous)
1752 nmmse.dwItemSpec = 0;
1753 nmmse.dwItemData = 0;
1756 nmmse.dwHitInfo = lParam;
1757 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse, FALSE);
1758 return CallWindowProcA (infoPtr->prevComboWndProc,
1759 hwnd, uMsg, wParam, lParam);
1762 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1765 if (HIWORD(wParam) == EN_UPDATE) return 0;
1767 if (HIWORD(wParam) == EN_SETFOCUS) {
1769 * For EN_SETFOCUS this issues the same calls and messages
1770 * as the native seems to do.
1772 * for some cases however native does the following:
1773 * (noticed after SetFocus during LBUTTONDOWN on
1774 * on dropdown arrow)
1775 * WM_GETTEXTLENGTH (Edit);
1776 * WM_GETTEXT (Edit, len+1, str);
1777 * EM_SETSEL (Edit, 0, 0);
1778 * WM_GETTEXTLENGTH (Edit);
1779 * WM_GETTEXT (Edit, len+1, str);
1780 * EM_SETSEL (Edit, 0, len);
1781 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
1785 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
1786 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
1787 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr, FALSE);
1788 infoPtr->flags |= WCBE_ACTEDIT;
1789 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
1793 if (HIWORD(wParam) == EN_CHANGE) {
1795 * For EN_CHANGE this issues the same calls and messages
1796 * as the native seems to do.
1798 WCHAR edit_text[260];
1803 selected = SendMessageW (infoPtr->hwndCombo,
1804 CB_GETCURSEL, 0, 0);
1806 /* lstrlenA( lastworkingURL ) */
1808 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1809 if (selected == -1) {
1810 lastwrk = infoPtr->edit->pszText;
1811 cnt = lstrlenW (lastwrk);
1812 if (cnt >= 259) cnt = 259;
1815 item = COMBOEX_FindItem (infoPtr, selected);
1816 cnt = lstrlenW (item->pszText);
1817 lastwrk = item->pszText;
1818 if (cnt >= 259) cnt = 259;
1821 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
1822 selected, debugstr_w(lastwrk));
1823 TRACE("handling EN_CHANGE, edittext=%s\n",
1824 debugstr_w(edit_text));
1826 /* lstrcmpiW is between lastworkingURL and GetWindowText */
1828 if (lstrcmpiW (lastwrk, edit_text)) {
1829 /* strings not equal -- indicate edit has changed */
1830 infoPtr->flags |= WCBE_EDITCHG;
1832 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
1833 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
1842 return CallWindowProcA (infoPtr->prevComboWndProc,
1843 hwnd, uMsg, wParam, lParam);
1849 static LRESULT WINAPI
1850 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1852 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
1853 if (!COMBOEX_GetInfoPtr (hwnd) && (uMsg != WM_CREATE))
1854 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1858 case CBEM_DELETEITEM: /* maps to CB_DELETESTRING */
1859 return COMBOEX_DeleteItem (hwnd, wParam, lParam);
1861 case CBEM_GETCOMBOCONTROL:
1862 return COMBOEX_GetComboControl (hwnd, wParam, lParam);
1864 case CBEM_GETEDITCONTROL:
1865 return COMBOEX_GetEditControl (hwnd, wParam, lParam);
1867 case CBEM_GETEXTENDEDSTYLE:
1868 return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
1870 case CBEM_GETIMAGELIST:
1871 return COMBOEX_GetImageList (hwnd, wParam, lParam);
1874 return COMBOEX_GetItemA (hwnd, wParam, lParam);
1877 return COMBOEX_GetItemW (hwnd, wParam, lParam);
1879 case CBEM_GETUNICODEFORMAT:
1880 return COMBOEX_GetUnicodeFormat (hwnd, wParam, lParam);
1882 case CBEM_HASEDITCHANGED:
1883 return COMBOEX_HasEditChanged (hwnd, wParam, lParam);
1885 case CBEM_INSERTITEMA:
1886 return COMBOEX_InsertItemA (hwnd, wParam, lParam);
1888 case CBEM_INSERTITEMW:
1889 return COMBOEX_InsertItemW (hwnd, wParam, lParam);
1891 case CBEM_SETEXSTYLE: /* FIXME: obsoleted, should be the same as: */
1892 case CBEM_SETEXTENDEDSTYLE:
1893 return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
1895 case CBEM_SETIMAGELIST:
1896 return COMBOEX_SetImageList (hwnd, wParam, lParam);
1899 return COMBOEX_SetItemA (hwnd, wParam, lParam);
1902 return COMBOEX_SetItemW (hwnd, wParam, lParam);
1904 case CBEM_SETUNICODEFORMAT:
1905 return COMBOEX_SetUnicodeFormat (hwnd, wParam, lParam);
1908 /* Combo messages we are not sure if we need to process or just forward */
1909 case CB_GETDROPPEDCONTROLRECT:
1910 case CB_GETDROPPEDSTATE:
1911 case CB_GETITEMDATA:
1912 case CB_GETITEMHEIGHT:
1914 case CB_GETLBTEXTLEN:
1915 case CB_GETEXTENDEDUI:
1917 case CB_RESETCONTENT:
1918 case CB_SELECTSTRING:
1919 case CB_SETITEMDATA:
1922 FIXME("(0x%x 0x%x 0x%lx): possible missing fucntion\n",
1923 uMsg, wParam, lParam);
1924 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
1926 /* Combo messages OK to just forward to the regular COMBO */
1929 case CB_SETDROPPEDWIDTH:
1930 case CB_SETEXTENDEDUI:
1931 case CB_SHOWDROPDOWN:
1932 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
1934 /* Combo messages we need to process specially */
1935 case CB_FINDSTRINGEXACT:
1936 return COMBOEX_FindStringExact (COMBOEX_GetInfoPtr (hwnd),
1940 return COMBOEX_SetCursel (hwnd, wParam, lParam);
1942 case CB_SETITEMHEIGHT:
1943 return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
1947 /* Window messages passed to parent */
1949 return COMBOEX_Command (hwnd, wParam, lParam);
1952 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
1955 /* Window messages we need to process */
1957 return COMBOEX_Create (hwnd, wParam, lParam);
1960 return COMBOEX_WM_DeleteItem (hwnd, wParam, lParam);
1963 return COMBOEX_DrawItem (hwnd, wParam, lParam);
1966 return COMBOEX_Destroy (hwnd, wParam, lParam);
1968 case WM_MEASUREITEM:
1969 return COMBOEX_MeasureItem (hwnd, wParam, lParam);
1972 return COMBOEX_Size (hwnd, wParam, lParam);
1974 case WM_WINDOWPOSCHANGING:
1975 return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
1978 if (uMsg >= WM_USER)
1979 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
1980 uMsg, wParam, lParam);
1981 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1988 COMBOEX_Register (void)
1992 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1993 wndClass.style = CS_GLOBALCLASS;
1994 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
1995 wndClass.cbClsExtra = 0;
1996 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
1997 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1998 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1999 wndClass.lpszClassName = WC_COMBOBOXEXA;
2001 RegisterClassA (&wndClass);
2003 ComboExInfo = GlobalAddAtomA("CC32SubclassInfo");
2008 COMBOEX_Unregister (void)
2010 UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);