3 * 1. The following extended styles need to be implemented, use will
5 * CBES_EX_NOEDITIMAGEINDENT
6 * CBES_EX_PATHWORDBREAKPROC
8 * CBES_EX_CASESENSITIVE
9 * 2. None of the following callback items are implemented. Therefor
10 * no CBEN_GETDISPINFO notifies are issued. Use in either CBEM_INSERTITEM
11 * or CBEM_SETITEM will result in a FIXME:
15 * 3. No use is made of the iOverlay image.
16 * 4. Notify CBEN_DRAGBEGIN is not implemented.
21 * ComboBoxEx control v2 (mod6)
23 * Copyright 1998, 1999 Eric Kohl
26 * This is just a dummy control. An author is needed! Any volunteers?
27 * I will only improve this control once in a while.
28 * Eric <ekohl@abo.rhein-zeitung.de>
31 * Changes Guy Albertelli <galberte@neo.lrun.com>
32 * v1 Implemented messages: CB_SETITEMHEIGHT, WM_WINDOWPOSCHANGING,
33 * WM_DRAWITEM, and WM_MEASUREITEM. Fixed WM_CREATE. Fixed height
34 * of window rect reported fixing rebar control.
36 * 1. Rewrite of WM_Create for own created EDIT control. Also try to
37 * generate message sequence similar to native DLL.
38 * 2. Handle case where CBEM_SETITEM is called to display data in EDIT
40 * 3. Add override for WNDPROC for the EDIT control (reqed for VK_RETURN).
41 * 4. Dump input data for things using COMBOBOXEXITEM{A|W}.
42 * 5. Handle positioning EDIT control based on whether icon present.
43 * 6. Make InsertItemA use InsertItemW, and store all data in ..W form.
44 * 7. Implement CBEM_DELETEITEM, CBEM_GETITEM{A|W}, CB_SETCURSEL,
45 * CBEM_{GET|SET}UNICODEFORMAT.
46 * 8. Add override for WNDPROC for the COMBO control.
47 * 9. Support extended style CBES_EX_NOEDITIMAGE and warn others are not
49 * 10. Implement CB_FINDSTRINGEXACT in both the Combo and ComboEx window
50 * procs to match the items. This eliminates dup entries in the listbox.
53 * 1. Implemented CBN_SELCHANGE, CBN_KILLFOCUS, and CBN_SELENDOK.
54 * 2. Fix putting text in CBEN_ENDEDIT notifies for CBN_DROPDOWN case.
55 * 3. Lock image selected status to focus state of edit control if
56 * edit control exists. Mimics native actions.
57 * 4. Implemented WM_SETFOCUS in EditWndProc to track status of
59 * 5. The LBN_SELCHANGE is just for documentation purposes.
62 * 1. Add support for CB_GETITEMDATA to a Comboex. Returns the LPARAM
63 * passed during insert of item.
64 * 2. Remember selected item and don't issue CB_SETCURSEL unless needed.
65 * 3. Add initial support for WM_NCCREATE to remove unwanted window styles
66 * (Currently just WS_VSCROLL and WS_HSCROLL, but probably should be
68 * 4. Improve some traces.
69 * 5. Add support for CB_SETITEMDATA sets LPARAM value from item.
72 * 1. Add support for WM_NOTIFYFORMAT (both incoming and outgoing) and do
73 * WM_NOTIFY correctly based on results.
74 * 2. Fix memory leaks of text strings in COMBOEX_WM_DELETEITEM.
75 * 3. Add routines to handle special cases of NMCBEENDEDIT and NMCOMBOXEX
76 * so translation to ANSI is done correctly.
77 * 4. Fix some issues with COMBOEX_DrawItem.
79 * Test vehicals were the ControlSpy modules (rebar.exe and comboboxex.exe),
87 #include "debugtools.h"
88 #include "wine/unicode.h"
90 DEFAULT_DEBUG_CHANNEL(comboex);
92 * The following is necessary for the test done in COMBOEX_DrawItem
93 * to determine whether to dump out the DRAWITEM structure or not.
95 DECLARE_DEBUG_CHANNEL(message);
111 /* ComboBoxEx structure */
115 HWND hwndSelf; /* my own hwnd */
118 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
119 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
121 INT selected; /* index of selected item */
122 DWORD flags; /* WINE internal flags */
125 INT nb_items; /* Number of items */
126 BOOL bUnicode; /* TRUE if this window is Unicode */
127 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
128 CBE_ITEMDATA *edit; /* item data for edit item */
129 CBE_ITEMDATA *items; /* Array of items */
132 /* internal flags in the COMBOEX_INFO structure */
133 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
134 * CBEN_BEGINEDIT issued
135 * but CBEN_ENDEDIT{A|W}
137 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
138 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
141 #define ID_CB_EDIT 1001
145 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
146 * the ComboEx version of the Combo Window Proc so that when the
147 * WM_DRAWITEM message is then passed to ComboEx, we know that this
148 * particular WM_DRAWITEM message is for listbox only items. Any messasges
149 * without this flag is then for the Edit control field.
151 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
152 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
154 #define ODS_COMBOEXLBOX 0x4000
158 /* Height in pixels of control over the amount of the selected font */
161 /* Indent amount per MS documentation */
162 #define CBE_INDENT 10
164 /* Offset in pixels from left side for start of image or text */
165 #define CBE_STARTOFFSET 6
167 /* Offset between image and text */
170 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
173 /* Things common to the entire DLL */
174 static ATOM ComboExInfo;
175 static LRESULT WINAPI
176 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
177 static LRESULT WINAPI
178 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
181 COMBOEX_DumpItem (CBE_ITEMDATA *item)
183 if (TRACE_ON(comboex)){
184 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
185 item, item->mask, item->pszText, item->cchTextMax,
187 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
188 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
189 if ((item->mask & CBEIF_TEXT) && item->pszText)
190 TRACE("item %p - pszText=%s\n",
191 item, debugstr_w((const WCHAR *)item->pszText));
197 COMBOEX_DumpInput (COMBOBOXEXITEMA *input, BOOL true_for_w)
199 if (TRACE_ON(comboex)){
200 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
201 input->mask, input->iItem, input->pszText, input->cchTextMax,
203 if ((input->mask & CBEIF_TEXT) && input->pszText) {
205 TRACE("input - pszText=<%s>\n",
206 debugstr_w((const WCHAR *)input->pszText));
208 TRACE("input - pszText=<%s>\n",
209 debugstr_a((const char *)input->pszText));
211 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
212 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
217 inline static LRESULT
218 COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
220 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
222 if (infoPtr->hwndCombo)
223 return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
230 COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
233 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
234 hdr->hwndFrom = infoPtr->hwndSelf;
236 if (infoPtr->NtfUnicode)
237 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
240 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
246 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
249 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
251 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
252 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
253 hdr->hdr.code = code;
254 if (infoPtr->NtfUnicode)
255 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
258 LPWSTR str, ostr = NULL;
261 if (hdr->ceItem.mask & CBEIF_TEXT) {
262 ostr = hdr->ceItem.pszText;
264 if (!str) str = (LPWSTR)L"";
265 len = WideCharToMultiByte (CP_ACP, 0, str, -1, 0, 0, NULL, NULL);
267 hdr->ceItem.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
268 WideCharToMultiByte (CP_ACP, 0, str, -1, (LPSTR)hdr->ceItem.pszText,
273 ret = SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
275 if (hdr->ceItem.mask & CBEIF_TEXT) {
277 COMCTL32_Free (hdr->ceItem.pszText);
278 hdr->ceItem.pszText = ostr;
286 COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *hdr, LPWSTR itemText)
289 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
291 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
292 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
293 hdr->hdr.code = (infoPtr->NtfUnicode) ? CBEN_ENDEDITW : CBEN_ENDEDITA;
294 if (infoPtr->NtfUnicode)
295 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
300 memcpy (&ansi.hdr, &hdr->hdr, sizeof(NMHDR));
301 ansi.fChanged = hdr->fChanged;
302 ansi.iNewSelection = hdr->iNewSelection;
303 WideCharToMultiByte (CP_ACP, 0, itemText, -1,
304 (LPSTR)&ansi.szText, CBEMAXSTRLEN, NULL, NULL);
305 ansi.iWhy = hdr->iWhy;
306 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
313 COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
318 mydc = GetDC (0); /* why the entire screen???? */
319 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
320 ofont = (HFONT) SelectObject (mydc, nfont);
321 GetTextExtentPointA (mydc, "A", 1, size);
322 SelectObject (mydc, ofont);
324 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
329 COMBOEX_CopyItem (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
331 if (cit->mask & CBEIF_TEXT) {
333 * when given a text buffer actually use that buffer
337 lstrcpynW(cit->pszText,item->pszText,cit->cchTextMax);
341 cit->pszText = item->pszText;
342 cit->cchTextMax = item->cchTextMax;
345 if (cit->mask & CBEIF_IMAGE)
346 cit->iImage = item->iImage;
347 if (cit->mask & CBEIF_SELECTEDIMAGE)
348 cit->iSelectedImage = item->iSelectedImage;
349 if (cit->mask & CBEIF_OVERLAY)
350 cit->iOverlay = item->iOverlay;
351 if (cit->mask & CBEIF_INDENT)
352 cit->iIndent = item->iIndent;
353 if (cit->mask & CBEIF_LPARAM)
354 cit->lParam = item->lParam;
360 COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
364 INT x, y, w, h, xoff = 0;
367 if (!infoPtr->hwndEdit) return;
368 iinfo.rcImage.left = iinfo.rcImage.right = 0;
370 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
371 xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
373 GetClientRect (infoPtr->hwndCombo, &rect);
374 InflateRect (&rect, -2, -2);
375 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
377 /* reposition the Edit control based on whether icon exists */
378 COMBOEX_GetComboFontSize (infoPtr, &mysize);
379 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
380 x = xoff + CBE_STARTOFFSET + 1;
382 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
385 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
386 rect.left, rect.top, rect.right, rect.bottom,
388 SetWindowPos(infoPtr->hwndEdit, HWND_TOP,
391 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
396 COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
402 COMBOEX_GetComboFontSize (infoPtr, &mysize);
403 cy = mysize.cy + CBE_EXTRA;
405 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
406 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
407 TRACE("upgraded height due to image: height=%d\n", cy);
409 SendMessageW (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
410 if (infoPtr->hwndCombo)
411 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
412 (WPARAM) 0, (LPARAM) cy);
417 COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
419 if (!infoPtr->hwndEdit) return;
420 /* native issues the following messages to the {Edit} control */
421 /* WM_SETTEXT (0,addr) */
422 /* EM_SETSEL32 (0,0) */
423 /* EM_SETSEL32 (0,-1) */
424 if (item->mask & CBEIF_TEXT) {
425 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
426 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
427 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
432 static CBE_ITEMDATA *
433 COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
438 if ((index > infoPtr->nb_items) || (index < -1))
441 return infoPtr->edit;
442 item = infoPtr->items;
443 i = infoPtr->nb_items - 1;
445 /* find the item in the list */
446 while (item && (i > index)) {
447 item = (CBE_ITEMDATA *)item->next;
450 if (!item || (i != index)) {
451 FIXME("COMBOBOXEX item structures broken. Please report!\n");
459 COMBOEX_WarnCallBack (CBE_ITEMDATA *item)
461 if (item->pszText == LPSTR_TEXTCALLBACKW)
462 FIXME("Callback not implemented yet for pszText\n");
463 if (item->iImage == I_IMAGECALLBACK)
464 FIXME("Callback not implemented yet for iImage\n");
465 if (item->iSelectedImage == I_IMAGECALLBACK)
466 FIXME("Callback not implemented yet for iSelectedImage\n");
467 if (item->iOverlay == I_IMAGECALLBACK)
468 FIXME("Callback not implemented yet for iOverlay\n");
469 if (item->iIndent == I_INDENTCALLBACK)
470 FIXME("Callback not implemented yet for iIndent\n");
474 /* *** CBEM_xxx message support *** */
478 COMBOEX_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
480 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
481 INT index = (INT) wParam;
484 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
486 /* if item number requested does not exist then return failure */
487 if ((index > infoPtr->nb_items) || (index < 0)) {
488 ERR("attempt to delete item that does not exist\n");
492 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
493 ERR("attempt to delete item that was not found!\n");
497 /* doing this will result in WM_DELETEITEM being issued */
498 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
500 return infoPtr->nb_items;
504 inline static LRESULT
505 COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
507 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
511 return (LRESULT)infoPtr->hwndCombo;
515 inline static LRESULT
516 COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
518 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
520 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
523 TRACE("-- 0x%x\n", infoPtr->hwndEdit);
525 return (LRESULT)infoPtr->hwndEdit;
529 inline static LRESULT
530 COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
532 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
534 TRACE("-- 0x%08lx\n", infoPtr->dwExtStyle);
536 return (LRESULT)infoPtr->dwExtStyle;
540 inline static LRESULT
541 COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
543 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
545 TRACE("-- %p\n", infoPtr->himl);
547 return (LRESULT)infoPtr->himl;
552 COMBOEX_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
554 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
555 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
559 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
561 /* get real index of item to insert */
564 /* if item number requested does not exist then return failure */
565 if ((index > infoPtr->nb_items) || (index < -1)) {
566 ERR("attempt to get item that does not exist\n");
570 /* if the item is the edit control and there is no edit control, skip */
572 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
575 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
576 ERR("attempt to get item that was not found!\n");
580 COMBOEX_CopyItem (infoPtr, item, cit);
586 inline static LRESULT
587 COMBOEX_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
589 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
590 COMBOBOXEXITEMW tmpcit;
593 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
595 tmpcit.mask = cit->mask;
596 tmpcit.iItem = cit->iItem;
598 COMBOEX_GetItemW (hwnd, wParam, (LPARAM) &tmpcit);
600 len = WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1, 0, 0, NULL, NULL);
602 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
603 cit->pszText, cit->cchTextMax, NULL, NULL);
605 cit->iImage = tmpcit.iImage;
606 cit->iSelectedImage = tmpcit.iSelectedImage;
607 cit->iOverlay = tmpcit.iOverlay;
608 cit->iIndent = tmpcit.iIndent;
609 cit->lParam = tmpcit.lParam;
615 inline static LRESULT
616 COMBOEX_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
618 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
620 TRACE("%s hwnd=0x%x\n",
621 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
623 return infoPtr->bUnicode;
627 inline static LRESULT
628 COMBOEX_HasEditChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
630 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
632 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
634 if ((infoPtr->flags & (WCBE_ACTEDIT | WCBE_EDITCHG)) ==
635 (WCBE_ACTEDIT | WCBE_EDITCHG))
642 COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
644 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
645 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
652 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
654 /* get real index of item to insert */
656 if (index == -1) index = infoPtr->nb_items;
657 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
659 /* get space and chain it in */
660 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
662 item->pszText = NULL;
664 /* locate position to insert new item in */
665 if (index == infoPtr->nb_items) {
666 /* fast path for iItem = -1 */
667 item->next = infoPtr->items;
668 infoPtr->items = item;
671 INT i = infoPtr->nb_items-1;
672 CBE_ITEMDATA *moving = infoPtr->items;
674 while ((i > index) && moving) {
675 moving = (CBE_ITEMDATA *)moving->next;
679 FIXME("COMBOBOXEX item structures broken. Please report!\n");
683 item->next = moving->next;
687 /* fill in our hidden item structure */
688 item->mask = cit->mask;
689 if (item->mask & CBEIF_TEXT) {
694 if (!str) str = (LPWSTR) L"";
697 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
698 strcpyW (item->pszText, str);
701 item->pszText = NULL;
702 item->cchTextMax = cit->cchTextMax;
704 if (item->mask & CBEIF_IMAGE)
705 item->iImage = cit->iImage;
706 if (item->mask & CBEIF_SELECTEDIMAGE)
707 item->iSelectedImage = cit->iSelectedImage;
708 if (item->mask & CBEIF_OVERLAY)
709 item->iOverlay = cit->iOverlay;
710 if (item->mask & CBEIF_INDENT)
711 item->iIndent = cit->iIndent;
712 if (item->mask & CBEIF_LPARAM)
713 item->lParam = cit->lParam;
716 COMBOEX_WarnCallBack (item);
718 COMBOEX_DumpItem (item);
720 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
721 (WPARAM)cit->iItem, (LPARAM)item);
723 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
724 COMBOEX_CopyItem (infoPtr, item, &nmcit.ceItem);
725 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
733 COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
735 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
736 COMBOBOXEXITEMW citW;
739 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
740 if (cit->mask & CBEIF_TEXT) {
746 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
748 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
749 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
752 ret = COMBOEX_InsertItemW(hwnd,wParam,(LPARAM)&citW);;
754 if (cit->mask & CBEIF_TEXT)
755 COMCTL32_Free(citW.pszText);
761 COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
763 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
766 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
768 dwTemp = infoPtr->dwExtStyle;
770 if (lParam & (CBES_EX_NOEDITIMAGEINDENT |
771 CBES_EX_PATHWORDBREAKPROC |
772 CBES_EX_NOSIZELIMIT |
773 CBES_EX_CASESENSITIVE))
774 FIXME("Extended style not implemented %08lx\n", lParam);
777 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
780 infoPtr->dwExtStyle = (DWORD)lParam;
783 * native does this for CBES_EX_NOEDITIMAGE state change
785 if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
786 (dwTemp & CBES_EX_NOEDITIMAGE)) {
787 /* if state of EX_NOEDITIMAGE changes, invalidate all */
788 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
789 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
790 InvalidateRect (hwnd, NULL, TRUE);
791 COMBOEX_AdjustEditPos (infoPtr);
792 if (infoPtr->hwndEdit)
793 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
796 return (LRESULT)dwTemp;
800 inline static LRESULT
801 COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
803 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
806 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
808 himlTemp = infoPtr->himl;
809 infoPtr->himl = (HIMAGELIST)lParam;
811 COMBOEX_ReSize (hwnd, infoPtr);
812 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
814 /* reposition the Edit control based on whether icon exists */
815 COMBOEX_AdjustEditPos (infoPtr);
816 return (LRESULT)himlTemp;
820 COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
822 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
823 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
827 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
829 /* get real index of item to insert */
832 /* if item number requested does not exist then return failure */
833 if ((index > infoPtr->nb_items) || (index < -1)) {
834 ERR("attempt to set item that does not exist yet!\n");
838 /* if the item is the edit control and there is no edit control, skip */
840 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
843 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
844 ERR("attempt to set item that was not found!\n");
848 /* add/change stuff to the internal item structure */
849 item->mask |= cit->mask;
850 if (cit->mask & CBEIF_TEXT) {
853 WCHAR emptystr[1] = {0};
856 if (!str) str=emptystr;
859 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
860 strcpyW(item->pszText,str);
862 item->cchTextMax = cit->cchTextMax;
864 if (cit->mask & CBEIF_IMAGE)
865 item->iImage = cit->iImage;
866 if (cit->mask & CBEIF_SELECTEDIMAGE)
867 item->iSelectedImage = cit->iSelectedImage;
868 if (cit->mask & CBEIF_OVERLAY)
869 item->iOverlay = cit->iOverlay;
870 if (cit->mask & CBEIF_INDENT)
871 item->iIndent = cit->iIndent;
872 if (cit->mask & CBEIF_LPARAM)
873 cit->lParam = cit->lParam;
875 COMBOEX_WarnCallBack (item);
877 COMBOEX_DumpItem (item);
879 /* if original request was to update edit control, do some fast foot work */
880 if (cit->iItem == -1) {
881 COMBOEX_SetEditText (infoPtr, item);
882 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
888 COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
890 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
891 COMBOBOXEXITEMW citW;
894 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
895 if (cit->mask & CBEIF_TEXT) {
901 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
903 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
904 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
907 ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
909 if (cit->mask & CBEIF_TEXT)
910 COMCTL32_Free(citW.pszText);
915 inline static LRESULT
916 COMBOEX_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
918 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
919 BOOL bTemp = infoPtr->bUnicode;
921 TRACE("to %s hwnd=0x%04x, was %s\n",
922 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd,
923 (bTemp) ? "TRUE" : "FALSE");
925 infoPtr->bUnicode = (BOOL)wParam;
932 /* *** CB_xxx message support *** */
936 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
940 LPWSTR desired = NULL;
941 INT start = (INT) wParam;
943 i = MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
945 desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
946 MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, desired, i);
949 count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0 , 0);
951 /* now search from after starting loc and wrapping back to start */
952 for(i=start+1; i<count; i++) {
953 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
954 CB_GETITEMDATA, (WPARAM)i, 0);
955 TRACE("desired=%s, item=%s\n",
956 debugstr_w(desired), debugstr_w(item->pszText));
957 if (lstrcmpiW(item->pszText, desired) == 0) {
958 COMCTL32_Free (desired);
962 for(i=0; i<=start; i++) {
963 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
964 CB_GETITEMDATA, (WPARAM)i, 0);
965 TRACE("desired=%s, item=%s\n",
966 debugstr_w(desired), debugstr_w(item->pszText));
967 if (lstrcmpiW(item->pszText, desired) == 0) {
968 COMCTL32_Free (desired);
972 COMCTL32_Free(desired);
978 COMBOEX_GetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
981 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
982 CBE_ITEMDATA *item1, *item2;
985 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
987 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
988 item2 = COMBOEX_FindItem (infoPtr, index);
989 if (item2 != item1) {
990 ERR("data structures damaged!\n");
993 if (item1->mask & CBEIF_LPARAM)
994 lret = (LRESULT) item1->lParam;
995 TRACE("returning 0x%08lx\n", lret);
998 lret = (LRESULT)item1;
999 TRACE("non-valid result from combo, returning 0x%08lx\n", lret);
1005 COMBOEX_SetCursel (HWND hwnd, WPARAM wParam, LPARAM lParam)
1008 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1012 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
1013 /* FIXME: need to clear selection */
1017 TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
1018 debugstr_w(item->pszText) : "<null>");
1019 infoPtr->selected = index;
1021 lret = SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, wParam, lParam);
1022 COMBOEX_SetEditText (infoPtr, item);
1028 COMBOEX_SetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
1031 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1032 CBE_ITEMDATA *item1, *item2;
1034 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
1036 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
1037 item2 = COMBOEX_FindItem (infoPtr, index);
1038 if (item2 != item1) {
1039 ERR("data structures damaged!\n");
1042 item1->mask |= CBEIF_LPARAM;
1043 item1->lParam = lParam;
1044 TRACE("setting lparam to 0x%08lx\n", lParam);
1047 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
1048 return (LRESULT)item1;
1053 COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
1055 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1056 RECT cb_wrect, cbx_wrect, cbx_crect;
1060 /* First, lets forward the message to the normal combo control
1061 just like Windows. */
1062 if (infoPtr->hwndCombo)
1063 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
1065 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1066 GetWindowRect (hwnd, &cbx_wrect);
1067 GetClientRect (hwnd, &cbx_crect);
1068 /* the height of comboex as height of the combo + comboex border */
1069 height = cb_wrect.bottom-cb_wrect.top
1070 + cbx_wrect.bottom-cbx_wrect.top
1071 - (cbx_crect.bottom-cbx_crect.top);
1072 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1073 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1074 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1075 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1076 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1077 cbx_wrect.right-cbx_wrect.left, height);
1078 SetWindowPos (hwnd, HWND_TOP, 0, 0,
1079 cbx_wrect.right-cbx_wrect.left,
1081 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1087 /* *** WM_xxx message support *** */
1091 COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1093 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
1094 COMBOEX_INFO *infoPtr;
1098 RECT wnrc1, clrc1, cmbwrc;
1102 /* allocate memory for info structure */
1103 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
1104 if (infoPtr == NULL) {
1105 ERR("could not allocate info memory!\n");
1109 /* initialize info structure */
1111 infoPtr->items = NULL;
1112 infoPtr->nb_items = 0;
1113 infoPtr->hwndSelf = hwnd;
1114 infoPtr->selected = -1;
1116 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1118 i = SendMessageA(GetParent (hwnd),
1119 WM_NOTIFYFORMAT, hwnd, NF_QUERY);
1120 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1121 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1125 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1127 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1129 /* create combo box */
1130 dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
1131 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
1133 GetWindowRect(hwnd, &wnrc1);
1134 GetClientRect(hwnd, &clrc1);
1135 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1136 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1137 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
1138 TRACE("combo style=%08lx, adding style=%08lx\n", dwComboStyle,
1139 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1140 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1141 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED);
1143 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1144 /* specified. It then creates it's own version of the EDIT control */
1145 /* and makes the ComboBox the parent. This is because a normal */
1146 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
1147 /* We also need to place the edit control at the proper location */
1148 /* (allow space for the icons). */
1150 infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
1151 /* following line added to match native */
1152 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1153 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1154 /* was base and is necessary */
1155 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
1156 cs->y, cs->x, cs->cx, cs->cy, hwnd,
1157 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1158 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
1161 * native does the following at this point according to trace:
1162 * GetWindowThreadProcessId(hwndCombo,0)
1163 * GetCurrentThreadId()
1164 * GetWindowThreadProcessId(hwndCombo, &???)
1165 * GetCurrentProcessId()
1169 * Setup a property to hold the pointer to the COMBOBOXEX
1172 test = GetPropA(infoPtr->hwndCombo, (LPCSTR)(LONG)ComboExInfo);
1173 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1174 SetPropA(infoPtr->hwndCombo, "CC32SubclassInfo", (LONG)infoPtr);
1176 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndCombo,
1177 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
1178 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1182 * Now create our own EDIT control so we can position it.
1183 * It is created only for CBS_DROPDOWN style
1185 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1186 infoPtr->hwndEdit = CreateWindowExA (0, "EDIT", "",
1187 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1188 0, 0, 0, 0, /* will set later */
1190 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1191 GetWindowLongA (hwnd, GWL_HINSTANCE),
1194 /* native does the following at this point according to trace:
1195 * GetWindowThreadProcessId(hwndEdit,0)
1196 * GetCurrentThreadId()
1197 * GetWindowThreadProcessId(hwndEdit, &???)
1198 * GetCurrentProcessId()
1202 * Setup a property to hold the pointer to the COMBOBOXEX
1205 test = GetPropA(infoPtr->hwndEdit, (LPCSTR)(LONG)ComboExInfo);
1206 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1207 SetPropA(infoPtr->hwndEdit, "CC32SubclassInfo", (LONG)infoPtr);
1209 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndEdit,
1210 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1211 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1214 infoPtr->hwndEdit = 0;
1219 * Locate the default font if necessary and then set it in
1220 * all associated controls
1222 if (!infoPtr->font) {
1223 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1225 infoPtr->font = infoPtr->hDefaultFont = CreateFontIndirectA (&mylogfont);
1227 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1228 if (infoPtr->hwndEdit) {
1229 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1230 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1233 COMBOEX_ReSize (hwnd, infoPtr);
1235 /* Above is fairly certain, below is much less certain. */
1237 GetWindowRect(hwnd, &wnrc1);
1238 GetClientRect(hwnd, &clrc1);
1239 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1240 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1241 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1242 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1243 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1244 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1245 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1246 SWP_NOACTIVATE | SWP_NOREDRAW);
1248 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1249 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1250 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1251 SetWindowPos(hwnd, HWND_TOP,
1252 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1253 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1255 COMBOEX_AdjustEditPos (infoPtr);
1258 * Create an item structure to represent the data in the
1261 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1263 item->pszText = NULL;
1265 infoPtr->edit = item;
1271 inline static LRESULT
1272 COMBOEX_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
1275 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1276 INT command = HIWORD(wParam);
1277 CBE_ITEMDATA *item = 0;
1279 INT cursel, n, oldItem;
1280 NMCBEENDEDITW cbeend;
1283 TRACE("for command %d\n", command);
1288 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1291 * from native trace of first dropdown after typing in URL in IE4
1292 * CB_GETCURSEL(Combo)
1293 * GetWindowText(Edit)
1294 * CB_GETCURSEL(Combo)
1295 * CB_GETCOUNT(Combo)
1296 * CB_GETITEMDATA(Combo, n)
1297 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1298 * CB_GETCURSEL(Combo)
1299 * CB_SETCURSEL(COMBOEX, n)
1301 * the rest is supposition
1303 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1305 /* find match from edit against those in Combobox */
1306 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1307 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1308 for (cursel = 0; cursel < n; cursel++){
1309 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1312 if ((INT)item == CB_ERR) break;
1313 if (lstrcmpiW(item->pszText, wintext) == 0) break;
1315 if ((cursel == n) || ((INT)item == CB_ERR)) {
1316 TRACE("failed to find match??? item=%p cursel=%d\n",
1318 if (infoPtr->hwndEdit)
1319 SetFocus(infoPtr->hwndEdit);
1324 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1327 if ((INT)item == CB_ERR) {
1328 TRACE("failed to find match??? item=%p cursel=%d\n",
1330 if (infoPtr->hwndEdit)
1331 SetFocus(infoPtr->hwndEdit);
1336 /* Save flags for testing and reset them */
1337 oldflags = infoPtr->flags;
1338 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1340 if (oldflags & WCBE_ACTEDIT) {
1341 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1342 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1343 CB_GETCURSEL, 0, 0);
1344 cbeend.iWhy = CBENF_DROPDOWN;
1346 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, item->pszText)) {
1347 /* abort the change */
1348 TRACE("Notify requested abort of change\n");
1353 /* if selection has changed the set the new current selection */
1354 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1355 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1356 infoPtr->selected = cursel;
1357 SendMessageW (hwnd, CB_SETCURSEL, cursel, 0);
1358 SetFocus(infoPtr->hwndCombo);
1364 * CB_GETCURSEL(Combo)
1365 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1368 * WM_GETTEXTLENGTH(Edit)
1370 * EM_SETSEL(Edit, 0,0)
1371 * WM_GETTEXTLENGTH(Edit)
1373 * EM_SETSEL(Edit, 0,len)
1374 * return WM_COMMAND to parent
1376 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1377 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1378 ERR("item %d not found. Problem!\n", oldItem);
1381 infoPtr->selected = oldItem;
1382 COMBOEX_SetEditText (infoPtr, item);
1383 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1388 * We have to change the handle since we are the control
1389 * issuing the message. IE4 depends on this.
1391 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1396 * from native trace:
1399 * WM_GETTEXT(Edit, 104)
1400 * CB_GETCURSEL(Combo) rets -1
1401 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1402 * CB_GETCURSEL(Combo)
1403 * InvalidateRect(Combo, 0, 0)
1406 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1408 if (infoPtr->flags & WCBE_ACTEDIT) {
1409 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1410 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1411 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1412 CB_GETCURSEL, 0, 0);
1413 cbeend.iWhy = CBENF_KILLFOCUS;
1415 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1416 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) {
1417 /* abort the change */
1418 TRACE("Notify requested abort of change\n");
1422 /* possible CB_GETCURSEL */
1423 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1429 * We have to change the handle since we are the control
1430 * issuing the message. IE4 depends on this.
1431 * We also need to set the focus back to the Edit control
1432 * after passing the command to the parent of the ComboEx.
1434 lret = SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1436 if (infoPtr->hwndEdit)
1437 SetFocus(infoPtr->hwndEdit);
1444 inline static LRESULT
1445 COMBOEX_WM_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1447 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1448 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)lParam;
1449 CBE_ITEMDATA *item, *olditem;
1451 NMCOMBOBOXEXW nmcit;
1453 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1454 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1456 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1458 olditem = infoPtr->items;
1459 i = infoPtr->nb_items - 1;
1461 if (i == dis->itemID) {
1462 infoPtr->items = infoPtr->items->next;
1468 /* find the prior item in the list */
1469 while (item->next && (i > dis->itemID)) {
1470 item = (CBE_ITEMDATA *)item->next;
1473 if (!item->next || (i != dis->itemID)) {
1474 FIXME("COMBOBOXEX item structures broken. Please report!\n");
1477 olditem = item->next;
1478 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1480 infoPtr->nb_items--;
1482 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1483 COMBOEX_CopyItem (infoPtr, olditem, &nmcit.ceItem);
1484 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1486 if (olditem->pszText)
1487 COMCTL32_Free(olditem->pszText);
1488 COMCTL32_Free(olditem);
1495 inline static LRESULT
1496 COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1498 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1499 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
1500 CBE_ITEMDATA *item = 0;
1504 int drawimage, drawstate;
1506 UINT xioff = 0; /* size and spacer of image if any */
1509 COLORREF nbkc, ntxc;
1511 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1513 /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
1514 if (!TRACE_ON(message)) {
1515 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1516 dis->CtlType, dis->CtlID);
1517 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1518 dis->itemID, dis->itemAction, dis->itemState);
1519 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1520 dis->hwndItem, dis->hDC, dis->rcItem.left,
1521 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1526 /* "itemID - Specifies the menu item identifier for a menu */
1527 /* item or the index of the item in a list box or combo box. */
1528 /* For an empty list box or combo box, this member can be -1. */
1529 /* This allows the application to draw only the focus */
1530 /* rectangle at the coordinates specified by the rcItem */
1531 /* member even though there are no items in the control. */
1532 /* This indicates to the user whether the list box or combo */
1533 /* box has the focus. How the bits are set in the itemAction */
1534 /* member determines whether the rectangle is to be drawn as */
1535 /* though the list box or combo box has the focus. */
1536 if (dis->itemID == 0xffffffff) {
1537 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1538 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1540 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1541 dis->rcItem.left, dis->rcItem.top,
1542 dis->rcItem.right, dis->rcItem.bottom);
1544 else if ((dis->CtlType == ODT_COMBOBOX) &&
1545 (dis->itemAction == ODA_DRAWENTIRE)) {
1546 /* draw of edit control data */
1550 RECT exrc, cbrc, edrc;
1551 GetWindowRect (hwnd, &exrc);
1552 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1553 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1554 if (infoPtr->hwndEdit)
1555 GetWindowRect (infoPtr->hwndEdit, &edrc);
1556 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1557 exrc.left, exrc.top, exrc.right, exrc.bottom,
1558 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1559 edrc.left, edrc.top, edrc.right, edrc.bottom);
1563 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1564 dis->rcItem.left, dis->rcItem.top,
1565 dis->rcItem.right, dis->rcItem.bottom,
1566 dis->itemAction, dis->itemState);
1571 /* If draw item is -1 (edit control) setup the item pointer */
1572 if (dis->itemID == 0xffffffff) {
1576 item = infoPtr->edit;
1578 if (infoPtr->hwndEdit) {
1580 /* free previous text of edit item */
1581 if (item->pszText) {
1582 COMCTL32_Free(item->pszText);
1584 item->mask &= ~CBEIF_TEXT;
1586 alen = SendMessageA (infoPtr->hwndEdit, WM_GETTEXT, 260, (LPARAM)&str);
1587 TRACE("edit control hwndEdit=%0x, text len=%d str=<%s>\n",
1588 infoPtr->hwndEdit, alen, str);
1590 item->mask |= CBEIF_TEXT;
1591 wlen = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
1593 item->pszText = (LPWSTR)COMCTL32_Alloc ((wlen + 1)*sizeof(WCHAR));
1594 MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, wlen);
1600 /* if the item pointer is not set, then get the data and locate it */
1602 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1603 CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
1604 if (item == (CBE_ITEMDATA *)CB_ERR)
1606 FIXME("invalid item for id %d \n",dis->itemID);
1611 COMBOEX_DumpItem (item);
1613 xbase = CBE_STARTOFFSET;
1614 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
1615 xbase += (item->iIndent * CBE_INDENT);
1616 if (item->mask & CBEIF_IMAGE) {
1617 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
1618 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
1621 switch (dis->itemAction) {
1623 if (dis->itemState & ODS_SELECTED /*1*/) {
1624 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1627 len = strlenW (item->pszText);
1628 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1629 rect.left = xbase + xioff - 1;
1630 rect.right = rect.left + txtsize.cx + 2;
1631 rect.top = dis->rcItem.top;
1632 rect.bottom = dis->rcItem.bottom;
1633 GetClipBox (dis->hDC, &rect2);
1634 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
1635 dis->itemID, rect.left, rect.top,
1636 rect.right, rect.bottom);
1637 TRACE(" clip=(%d,%d)-(%d,%d)\n",
1638 rect2.left, rect2.top,
1639 rect2.right, rect2.bottom);
1641 DrawFocusRect(dis->hDC, &rect);
1644 FIXME("ODA_FOCUS and ODS_SELECTED but no text\n");
1648 FIXME("ODA_FOCUS but not ODS_SELECTED\n");
1652 case ODA_DRAWENTIRE:
1654 drawstate = ILD_NORMAL;
1655 if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
1656 if (item->mask & CBEIF_IMAGE)
1657 drawimage = item->iImage;
1658 if (dis->itemState & ODS_COMBOEXLBOX) {
1659 /* drawing listbox entry */
1660 if (dis->itemState & ODS_SELECTED) {
1661 if (item->mask & CBEIF_SELECTEDIMAGE)
1662 drawimage = item->iSelectedImage;
1663 drawstate = ILD_SELECTED;
1667 /* drawing combo/edit entry */
1668 if (infoPtr->hwndEdit) {
1669 /* if we have an edit control, the slave the
1670 * selection state to the Edit focus state
1672 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1673 if (item->mask & CBEIF_SELECTEDIMAGE)
1674 drawimage = item->iSelectedImage;
1675 drawstate = ILD_SELECTED;
1679 /* if we don't have an edit control, use
1680 * the requested state.
1682 if (dis->itemState & ODS_SELECTED) {
1683 if (item->mask & CBEIF_SELECTEDIMAGE)
1684 drawimage = item->iSelectedImage;
1685 drawstate = ILD_SELECTED;
1690 if (drawimage != -1) {
1691 TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
1692 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
1693 xbase, dis->rcItem.top, drawstate);
1696 /* setup pointer to text to be drawn */
1697 if ((item->mask & CBEIF_TEXT) && item->pszText)
1698 str = item->pszText;
1702 /* now draw the text */
1703 len = lstrlenW (str);
1704 GetTextExtentPointW (dis->hDC, str, len, &txtsize);
1705 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1706 COLOR_HIGHLIGHT : COLOR_WINDOW);
1707 SetBkColor (dis->hDC, nbkc);
1708 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1709 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1710 SetTextColor (dis->hDC, ntxc);
1712 y = dis->rcItem.top +
1713 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1715 rect.right = x + txtsize.cx;
1716 rect.top = dis->rcItem.top + 1;
1717 rect.bottom = dis->rcItem.bottom - 1;
1718 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1719 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1720 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1721 &rect, str, len, 0);
1722 if (dis->itemState & ODS_FOCUS) {
1727 TRACE("drawing item %d focus after text, rect=(%d,%d)-(%d,%d)\n",
1728 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1729 DrawFocusRect (dis->hDC, &rect);
1733 FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
1734 hwnd, wParam, lParam, dis->itemAction);
1742 COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1744 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1746 if (infoPtr->hwndCombo)
1747 DestroyWindow (infoPtr->hwndCombo);
1749 if (infoPtr->edit) {
1750 COMCTL32_Free (infoPtr->edit);
1754 if (infoPtr->items) {
1755 CBE_ITEMDATA *this, *next;
1757 this = infoPtr->items;
1759 next = (CBE_ITEMDATA *)this->next;
1760 if ((this->mask & CBEIF_TEXT) && this->pszText)
1761 COMCTL32_Free (this->pszText);
1762 COMCTL32_Free (this);
1767 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
1769 /* free comboex info data */
1770 COMCTL32_Free (infoPtr);
1771 SetWindowLongA (hwnd, 0, 0);
1777 COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1779 /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
1780 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
1785 GetTextExtentPointA (hdc, "W", 1, &mysize);
1787 mis->itemHeight = mysize.cy + CBE_EXTRA;
1789 TRACE("adjusted height hwnd=%08x, height=%d\n",
1790 hwnd, mis->itemHeight);
1797 COMBOEX_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1799 /* WARNING: The COMBOEX_INFO structure is not yet created */
1800 DWORD oldstyle, newstyle;
1802 oldstyle = (DWORD)GetWindowLongA (hwnd, GWL_STYLE);
1803 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1804 if (newstyle != oldstyle) {
1805 TRACE("req style %08lx, reseting style %08lx\n",
1806 oldstyle, newstyle);
1807 SetWindowLongA (hwnd, GWL_STYLE, newstyle);
1814 COMBOEX_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1816 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1819 if (lParam == NF_REQUERY) {
1820 i = SendMessageA(GetParent (hwnd),
1821 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
1822 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1823 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1827 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1830 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
1835 COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1837 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1840 GetWindowRect (hwnd, &rect);
1841 TRACE("my rect (%d,%d)-(%d,%d)\n",
1842 rect.left, rect.top, rect.right, rect.bottom);
1844 MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
1845 rect.bottom - rect.top, TRUE);
1847 COMBOEX_AdjustEditPos (infoPtr);
1854 COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
1856 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1857 RECT cbx_wrect, cbx_crect, cb_wrect;
1859 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1861 GetWindowRect (hwnd, &cbx_wrect);
1862 GetClientRect (hwnd, &cbx_crect);
1863 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1865 /* width is winpos value + border width of comboex */
1867 + (cbx_wrect.right-cbx_wrect.left)
1868 - (cbx_crect.right-cbx_crect.left);
1870 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1871 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1872 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1873 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1874 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1875 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1876 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1877 width, cb_wrect.bottom-cb_wrect.top);
1879 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1881 cb_wrect.bottom-cb_wrect.top,
1884 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1886 /* height is combo window height plus border width of comboex */
1887 height = (cb_wrect.bottom-cb_wrect.top)
1888 + (cbx_wrect.bottom-cbx_wrect.top)
1889 - (cbx_crect.bottom-cbx_crect.top);
1890 if (wp->cy < height) wp->cy = height;
1891 if (infoPtr->hwndEdit) {
1892 COMBOEX_AdjustEditPos (infoPtr);
1893 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1900 static LRESULT WINAPI
1901 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1903 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1904 NMCBEENDEDITW cbeend;
1905 WCHAR edit_text[260];
1906 COLORREF nbkc, obkc;
1911 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1912 hwnd, uMsg, wParam, lParam, infoPtr);
1914 if (!infoPtr) return 0;
1920 /* handle (ignore) the return character */
1921 if (wParam == VK_RETURN) return 0;
1922 /* all other characters pass into the real Edit */
1923 return CallWindowProcA (infoPtr->prevEditWndProc,
1924 hwnd, uMsg, wParam, lParam);
1928 * The following was determined by traces of the native
1931 nbkc = GetSysColor (COLOR_WINDOW);
1932 obkc = SetBkColor (hDC, nbkc);
1933 GetClientRect (hwnd, &rect);
1934 TRACE("erasing (%d,%d)-(%d,%d)\n",
1935 rect.left, rect.top, rect.right, rect.bottom);
1936 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1937 SetBkColor (hDC, obkc);
1938 return CallWindowProcA (infoPtr->prevEditWndProc,
1939 hwnd, uMsg, wParam, lParam);
1942 INT oldItem, selected;
1945 switch ((INT)wParam)
1948 /* native version seems to do following for COMBOEX */
1950 * GetWindowTextA(Edit,&?, 0x104) x
1951 * CB_GETCURSEL to Combo rets -1 x
1952 * WM_NOTIFY to COMBOEX parent (rebar) x
1953 * (CBEN_ENDEDIT{A|W}
1954 * fChanged = FALSE x
1955 * inewSelection = -1 x
1958 * CB_GETCURSEL to Combo rets -1 x
1959 * InvalidateRect(Combo, 0) x
1960 * WM_SETTEXT to Edit x
1961 * EM_SETSEL to Edit (0,0) x
1962 * EM_SETSEL to Edit (0,-1) x
1963 * RedrawWindow(Combo, 0, 0, 5) x
1965 TRACE("special code for VK_ESCAPE\n");
1967 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1969 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1970 cbeend.fChanged = FALSE;
1971 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1972 CB_GETCURSEL, 0, 0);
1973 cbeend.iWhy = CBENF_ESCAPE;
1975 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1976 /* abort the change */
1977 TRACE("Notify requested abort of change\n");
1980 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1981 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1982 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1983 ERR("item %d not found. Problem!\n", oldItem);
1986 infoPtr->selected = oldItem;
1987 COMBOEX_SetEditText (infoPtr, item);
1988 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1993 /* native version seems to do following for COMBOEX */
1995 * GetWindowTextA(Edit,&?, 0x104) x
1996 * CB_GETCURSEL to Combo rets -1 x
1997 * CB_GETCOUNT to Combo rets 0
1999 * CB_GETITEMDATA to match
2000 * *** above 3 lines simulated by FindItem x
2001 * WM_NOTIFY to COMBOEX parent (rebar) x
2002 * (CBEN_ENDEDIT{A|W} x
2003 * fChanged = TRUE (-1) x
2004 * iNewSelection = -1 or selected x
2006 * iWhy = 2 (CBENF_RETURN) x
2007 * CB_GETCURSEL to Combo rets -1 x
2008 * if -1 send CB_SETCURSEL to Combo -1 x
2009 * InvalidateRect(Combo, 0, 0) x
2011 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
2014 TRACE("special code for VK_RETURN\n");
2016 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2018 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2019 selected = SendMessageW (infoPtr->hwndCombo,
2020 CB_GETCURSEL, 0, 0);
2022 if (selected != -1) {
2023 item = COMBOEX_FindItem (infoPtr, selected);
2024 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
2025 selected, debugstr_w(item->pszText));
2026 TRACE("handling VK_RETURN, edittext=%s\n",
2027 debugstr_w(edit_text));
2028 if (lstrcmpiW (item->pszText, edit_text)) {
2029 /* strings not equal -- indicate edit has changed */
2034 cbeend.iNewSelection = selected;
2035 cbeend.fChanged = TRUE;
2036 cbeend.iWhy = CBENF_RETURN;
2037 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2038 /* abort the change, restore previous */
2039 TRACE("Notify requested abort of change\n");
2040 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
2041 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
2045 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
2046 if (oldItem != -1) {
2047 /* if something is selected, then deselect it */
2048 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
2051 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2052 SetFocus(infoPtr->hwndEdit);
2056 return CallWindowProcA (infoPtr->prevEditWndProc,
2057 hwnd, uMsg, wParam, lParam);
2063 /* remember the focus to set state of icon */
2064 lret = CallWindowProcA (infoPtr->prevEditWndProc,
2065 hwnd, uMsg, wParam, lParam);
2066 infoPtr->flags |= WCBE_EDITFOCUSED;
2071 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
2073 infoPtr->flags &= ~WCBE_EDITFOCUSED;
2074 if (infoPtr->flags & WCBE_ACTEDIT) {
2075 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2077 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2078 cbeend.fChanged = FALSE;
2079 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2080 CB_GETCURSEL, 0, 0);
2081 cbeend.iWhy = CBENF_KILLFOCUS;
2083 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
2088 return CallWindowProcA (infoPtr->prevEditWndProc,
2089 hwnd, uMsg, wParam, lParam);
2095 static LRESULT WINAPI
2096 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2098 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
2099 NMCBEENDEDITW cbeend;
2101 COLORREF nbkc, obkc;
2105 WCHAR edit_text[260];
2107 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
2108 hwnd, uMsg, wParam, lParam, infoPtr);
2110 if (!infoPtr) return 0;
2115 case CB_FINDSTRINGEXACT:
2116 return COMBOEX_FindStringExact (infoPtr, wParam, lParam);
2120 * The only way this message should come is from the
2121 * child Listbox issuing the message. Flag this so
2122 * that ComboEx knows this is listbox.
2124 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
2125 return CallWindowProcA (infoPtr->prevComboWndProc,
2126 hwnd, uMsg, wParam, lParam);
2130 * The following was determined by traces of the native
2133 nbkc = GetSysColor (COLOR_WINDOW);
2134 obkc = SetBkColor (hDC, nbkc);
2135 GetClientRect (hwnd, &rect);
2136 TRACE("erasing (%d,%d)-(%d,%d)\n",
2137 rect.left, rect.top, rect.right, rect.bottom);
2138 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
2139 SetBkColor (hDC, obkc);
2140 return CallWindowProcA (infoPtr->prevComboWndProc,
2141 hwnd, uMsg, wParam, lParam);
2145 * WM_NOTIFY to comboex parent (rebar)
2146 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
2147 * CallWindowProc (previous)
2149 nmmse.dwItemSpec = 0;
2150 nmmse.dwItemData = 0;
2153 nmmse.dwHitInfo = lParam;
2154 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
2155 return CallWindowProcA (infoPtr->prevComboWndProc,
2156 hwnd, uMsg, wParam, lParam);
2159 switch (HIWORD(wParam)) {
2162 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2171 * GetFocus() retns AA
2172 * GetWindowTextA(Edit)
2173 * CB_GETCURSEL(Combo) (got -1)
2174 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2175 * CB_GETCURSEL(Combo) (got -1)
2176 * InvalidateRect(Combo, 0, 0)
2177 * WM_KILLFOCUS(Combo, AA)
2180 focusedhwnd = GetFocus();
2181 if (infoPtr->flags & WCBE_ACTEDIT) {
2182 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2183 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2184 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2185 CB_GETCURSEL, 0, 0);
2186 cbeend.iWhy = CBENF_KILLFOCUS;
2188 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2189 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2190 /* abort the change */
2191 TRACE("Notify requested abort of change\n");
2195 /* possible CB_GETCURSEL */
2196 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2198 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2199 (WPARAM)focusedhwnd, 0);
2204 * For EN_SETFOCUS this issues the same calls and messages
2205 * as the native seems to do.
2207 * for some cases however native does the following:
2208 * (noticed after SetFocus during LBUTTONDOWN on
2209 * on dropdown arrow)
2210 * WM_GETTEXTLENGTH (Edit);
2211 * WM_GETTEXT (Edit, len+1, str);
2212 * EM_SETSEL (Edit, 0, 0);
2213 * WM_GETTEXTLENGTH (Edit);
2214 * WM_GETTEXT (Edit, len+1, str);
2215 * EM_SETSEL (Edit, 0, len);
2216 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2220 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2221 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2222 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2223 infoPtr->flags |= WCBE_ACTEDIT;
2224 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2230 * For EN_CHANGE this issues the same calls and messages
2231 * as the native seems to do.
2233 WCHAR edit_text[260];
2238 selected = SendMessageW (infoPtr->hwndCombo,
2239 CB_GETCURSEL, 0, 0);
2241 /* lstrlenA( lastworkingURL ) */
2243 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2244 if (selected == -1) {
2245 lastwrk = infoPtr->edit->pszText;
2246 cnt = lstrlenW (lastwrk);
2247 if (cnt >= 259) cnt = 259;
2250 item = COMBOEX_FindItem (infoPtr, selected);
2251 cnt = lstrlenW (item->pszText);
2252 lastwrk = item->pszText;
2253 if (cnt >= 259) cnt = 259;
2256 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2257 selected, debugstr_w(lastwrk));
2258 TRACE("handling EN_CHANGE, edittext=%s\n",
2259 debugstr_w(edit_text));
2261 /* lstrcmpiW is between lastworkingURL and GetWindowText */
2263 if (lstrcmpiW (lastwrk, edit_text)) {
2264 /* strings not equal -- indicate edit has changed */
2265 infoPtr->flags |= WCBE_EDITCHG;
2267 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2268 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2276 * Therefore from traces there is no additional code here
2280 * Using native COMCTL32 gets the following:
2281 * 1 == SHDOCVW.DLL issues call/message
2282 * 2 == COMCTL32.DLL issues call/message
2283 * 3 == WINE issues call/message
2286 * for LBN_SELCHANGE:
2287 * 1 CB_GETCURSEL(ComboEx)
2288 * 1 CB_GETDROPPEDSTATE(ComboEx)
2289 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2290 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2291 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2292 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2293 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2294 * 3 ShowWindow(ComboLB, SW_HIDE)
2295 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2296 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2298 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2299 * ? LB_GETCURSEL <==|
2301 * ? LB_GETTEXT | Needs to be added to
2302 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2303 * ? LB_GETITEMDATA |
2304 * ? WM_DRAWITEM(ComboEx) <==|
2310 return CallWindowProcA (infoPtr->prevComboWndProc,
2311 hwnd, uMsg, wParam, lParam);
2317 static LRESULT WINAPI
2318 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2320 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2322 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2324 if (!COMBOEX_GetInfoPtr (hwnd)) {
2325 if (uMsg == WM_CREATE)
2326 return COMBOEX_Create (hwnd, wParam, lParam);
2327 if (uMsg == WM_NCCREATE)
2328 COMBOEX_NCCreate (hwnd, wParam, lParam);
2329 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2334 case CBEM_DELETEITEM: /* maps to CB_DELETESTRING */
2335 return COMBOEX_DeleteItem (hwnd, wParam, lParam);
2337 case CBEM_GETCOMBOCONTROL:
2338 return COMBOEX_GetComboControl (hwnd, wParam, lParam);
2340 case CBEM_GETEDITCONTROL:
2341 return COMBOEX_GetEditControl (hwnd, wParam, lParam);
2343 case CBEM_GETEXTENDEDSTYLE:
2344 return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
2346 case CBEM_GETIMAGELIST:
2347 return COMBOEX_GetImageList (hwnd, wParam, lParam);
2350 return COMBOEX_GetItemA (hwnd, wParam, lParam);
2353 return COMBOEX_GetItemW (hwnd, wParam, lParam);
2355 case CBEM_GETUNICODEFORMAT:
2356 return COMBOEX_GetUnicodeFormat (hwnd, wParam, lParam);
2358 case CBEM_HASEDITCHANGED:
2359 return COMBOEX_HasEditChanged (hwnd, wParam, lParam);
2361 case CBEM_INSERTITEMA:
2362 return COMBOEX_InsertItemA (hwnd, wParam, lParam);
2364 case CBEM_INSERTITEMW:
2365 return COMBOEX_InsertItemW (hwnd, wParam, lParam);
2367 case CBEM_SETEXSTYLE: /* FIXME: obsoleted, should be the same as: */
2368 case CBEM_SETEXTENDEDSTYLE:
2369 return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
2371 case CBEM_SETIMAGELIST:
2372 return COMBOEX_SetImageList (hwnd, wParam, lParam);
2375 return COMBOEX_SetItemA (hwnd, wParam, lParam);
2378 return COMBOEX_SetItemW (hwnd, wParam, lParam);
2380 case CBEM_SETUNICODEFORMAT:
2381 return COMBOEX_SetUnicodeFormat (hwnd, wParam, lParam);
2384 /* Combo messages we are not sure if we need to process or just forward */
2385 case CB_GETDROPPEDCONTROLRECT:
2386 case CB_GETITEMHEIGHT:
2388 case CB_GETLBTEXTLEN:
2389 case CB_GETEXTENDEDUI:
2391 case CB_RESETCONTENT:
2392 case CB_SELECTSTRING:
2395 FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
2396 uMsg, wParam, lParam);
2397 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2399 /* Combo messages OK to just forward to the regular COMBO */
2402 case CB_GETDROPPEDSTATE:
2403 case CB_SETDROPPEDWIDTH:
2404 case CB_SETEXTENDEDUI:
2405 case CB_SHOWDROPDOWN:
2406 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2408 /* Combo messages we need to process specially */
2409 case CB_FINDSTRINGEXACT:
2410 return COMBOEX_FindStringExact (COMBOEX_GetInfoPtr (hwnd),
2413 case CB_GETITEMDATA:
2414 return COMBOEX_GetItemData (hwnd, wParam, lParam);
2417 return COMBOEX_SetCursel (hwnd, wParam, lParam);
2419 case CB_SETITEMDATA:
2420 return COMBOEX_SetItemData (hwnd, wParam, lParam);
2422 case CB_SETITEMHEIGHT:
2423 return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
2427 /* Window messages passed to parent */
2429 return COMBOEX_Command (hwnd, wParam, lParam);
2432 if (infoPtr->NtfUnicode)
2433 return SendMessageW (GetParent (hwnd),
2434 uMsg, wParam, lParam);
2436 return SendMessageA (GetParent (hwnd),
2437 uMsg, wParam, lParam);
2440 /* Window messages we need to process */
2442 return COMBOEX_WM_DeleteItem (hwnd, wParam, lParam);
2445 return COMBOEX_DrawItem (hwnd, wParam, lParam);
2448 return COMBOEX_Destroy (hwnd, wParam, lParam);
2450 case WM_MEASUREITEM:
2451 return COMBOEX_MeasureItem (hwnd, wParam, lParam);
2453 case WM_NOTIFYFORMAT:
2454 return COMBOEX_NotifyFormat (hwnd, wParam, lParam);
2457 return COMBOEX_Size (hwnd, wParam, lParam);
2459 case WM_WINDOWPOSCHANGING:
2460 return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
2463 if (uMsg >= WM_USER)
2464 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2465 uMsg, wParam, lParam);
2466 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2473 COMBOEX_Register (void)
2477 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2478 wndClass.style = CS_GLOBALCLASS;
2479 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2480 wndClass.cbClsExtra = 0;
2481 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2482 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2483 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2484 wndClass.lpszClassName = WC_COMBOBOXEXA;
2486 RegisterClassA (&wndClass);
2488 ComboExInfo = GlobalAddAtomA("CC32SubclassInfo");
2493 COMBOEX_Unregister (void)
2495 UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);