2 * ComboBoxEx control v2 (mod6)
4 * Copyright 1998, 1999 Eric Kohl
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * This is just a dummy control. An author is needed! Any volunteers?
22 * I will only improve this control once in a while.
23 * Eric <ekohl@abo.rhein-zeitung.de>
27 * 1. The following extended styles need to be implemented, use will
29 * CBES_EX_NOEDITIMAGEINDENT
30 * CBES_EX_PATHWORDBREAKPROC
32 * CBES_EX_CASESENSITIVE
33 * 2. None of the following callback items are implemented. Therefor
34 * no CBEN_GETDISPINFO notifies are issued. Use in either CBEM_INSERTITEM
35 * or CBEM_SETITEM will result in a FIXME:
39 * 3. No use is made of the iOverlay image.
40 * 4. Notify CBEN_DRAGBEGIN is not implemented.
43 * Changes Guy Albertelli <galberte@neo.lrun.com>
44 * v1 Implemented messages: CB_SETITEMHEIGHT, WM_WINDOWPOSCHANGING,
45 * WM_DRAWITEM, and WM_MEASUREITEM. Fixed WM_CREATE. Fixed height
46 * of window rect reported fixing rebar control.
48 * 1. Rewrite of WM_Create for own created EDIT control. Also try to
49 * generate message sequence similar to native DLL.
50 * 2. Handle case where CBEM_SETITEM is called to display data in EDIT
52 * 3. Add override for WNDPROC for the EDIT control (reqed for VK_RETURN).
53 * 4. Dump input data for things using COMBOBOXEXITEM{A|W}.
54 * 5. Handle positioning EDIT control based on whether icon present.
55 * 6. Make InsertItemA use InsertItemW, and store all data in ..W form.
56 * 7. Implement CBEM_DELETEITEM, CBEM_GETITEM{A|W}, CB_SETCURSEL,
57 * CBEM_{GET|SET}UNICODEFORMAT.
58 * 8. Add override for WNDPROC for the COMBO control.
59 * 9. Support extended style CBES_EX_NOEDITIMAGE and warn others are not
61 * 10. Implement CB_FINDSTRINGEXACT in both the Combo and ComboEx window
62 * procs to match the items. This eliminates dup entries in the listbox.
65 * 1. Implemented CBN_SELCHANGE, CBN_KILLFOCUS, and CBN_SELENDOK.
66 * 2. Fix putting text in CBEN_ENDEDIT notifies for CBN_DROPDOWN case.
67 * 3. Lock image selected status to focus state of edit control if
68 * edit control exists. Mimics native actions.
69 * 4. Implemented WM_SETFOCUS in EditWndProc to track status of
71 * 5. The LBN_SELCHANGE is just for documentation purposes.
74 * 1. Add support for CB_GETITEMDATA to a Comboex. Returns the LPARAM
75 * passed during insert of item.
76 * 2. Remember selected item and don't issue CB_SETCURSEL unless needed.
77 * 3. Add initial support for WM_NCCREATE to remove unwanted window styles
78 * (Currently just WS_VSCROLL and WS_HSCROLL, but probably should be
80 * 4. Improve some traces.
81 * 5. Add support for CB_SETITEMDATA sets LPARAM value from item.
84 * 1. Add support for WM_NOTIFYFORMAT (both incoming and outgoing) and do
85 * WM_NOTIFY correctly based on results.
86 * 2. Fix memory leaks of text strings in COMBOEX_WM_DELETEITEM.
87 * 3. Add routines to handle special cases of NMCBEENDEDIT and NMCOMBOXEX
88 * so translation to ANSI is done correctly.
89 * 4. Fix some issues with COMBOEX_DrawItem.
91 * Test vehicals were the ControlSpy modules (rebar.exe and comboboxex.exe),
99 #include "wine/debug.h"
100 #include "wine/unicode.h"
102 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
104 * The following is necessary for the test done in COMBOEX_DrawItem
105 * to determine whether to dump out the DRAWITEM structure or not.
107 WINE_DECLARE_DEBUG_CHANNEL(message);
123 /* ComboBoxEx structure */
127 HWND hwndSelf; /* my own hwnd */
130 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
131 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
133 INT selected; /* index of selected item */
134 DWORD flags; /* WINE internal flags */
137 INT nb_items; /* Number of items */
138 BOOL bUnicode; /* TRUE if this window is Unicode */
139 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
140 CBE_ITEMDATA *edit; /* item data for edit item */
141 CBE_ITEMDATA *items; /* Array of items */
144 /* internal flags in the COMBOEX_INFO structure */
145 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
146 * CBEN_BEGINEDIT issued
147 * but CBEN_ENDEDIT{A|W}
149 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
150 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
153 #define ID_CB_EDIT 1001
157 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
158 * the ComboEx version of the Combo Window Proc so that when the
159 * WM_DRAWITEM message is then passed to ComboEx, we know that this
160 * particular WM_DRAWITEM message is for listbox only items. Any messasges
161 * without this flag is then for the Edit control field.
163 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
164 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
166 #define ODS_COMBOEXLBOX 0x4000
170 /* Height in pixels of control over the amount of the selected font */
173 /* Indent amount per MS documentation */
174 #define CBE_INDENT 10
176 /* Offset in pixels from left side for start of image or text */
177 #define CBE_STARTOFFSET 6
179 /* Offset between image and text */
182 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
185 /* Things common to the entire DLL */
186 static ATOM ComboExInfo;
187 static LRESULT WINAPI
188 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
189 static LRESULT WINAPI
190 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
193 COMBOEX_DumpItem (CBE_ITEMDATA *item)
195 if (TRACE_ON(comboex)){
196 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
197 item, item->mask, item->pszText, item->cchTextMax,
199 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
200 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
201 if ((item->mask & CBEIF_TEXT) && item->pszText)
202 TRACE("item %p - pszText=%s\n",
203 item, debugstr_w((const WCHAR *)item->pszText));
209 COMBOEX_DumpInput (COMBOBOXEXITEMA *input, BOOL true_for_w)
211 if (TRACE_ON(comboex)){
212 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
213 input->mask, input->iItem, input->pszText, input->cchTextMax,
215 if ((input->mask & CBEIF_TEXT) && input->pszText) {
217 TRACE("input - pszText=<%s>\n",
218 debugstr_w((const WCHAR *)input->pszText));
220 TRACE("input - pszText=<%s>\n",
221 debugstr_a((const char *)input->pszText));
223 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
224 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
229 inline static LRESULT
230 COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
232 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
234 if (infoPtr->hwndCombo)
235 return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
242 COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
245 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
246 hdr->hwndFrom = infoPtr->hwndSelf;
248 if (infoPtr->NtfUnicode)
249 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
252 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
258 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
261 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
263 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
264 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
265 hdr->hdr.code = code;
266 if (infoPtr->NtfUnicode)
267 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
270 LPWSTR str, ostr = NULL;
273 if (hdr->ceItem.mask & CBEIF_TEXT) {
274 ostr = hdr->ceItem.pszText;
276 if (!str) str = (LPWSTR)L"";
277 len = WideCharToMultiByte (CP_ACP, 0, str, -1, 0, 0, NULL, NULL);
279 hdr->ceItem.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
280 WideCharToMultiByte (CP_ACP, 0, str, -1, (LPSTR)hdr->ceItem.pszText,
285 ret = SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
287 if (hdr->ceItem.mask & CBEIF_TEXT) {
289 COMCTL32_Free (hdr->ceItem.pszText);
290 hdr->ceItem.pszText = ostr;
298 COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *hdr, LPWSTR itemText)
301 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
303 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
304 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
305 hdr->hdr.code = (infoPtr->NtfUnicode) ? CBEN_ENDEDITW : CBEN_ENDEDITA;
306 if (infoPtr->NtfUnicode)
307 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
312 memcpy (&ansi.hdr, &hdr->hdr, sizeof(NMHDR));
313 ansi.fChanged = hdr->fChanged;
314 ansi.iNewSelection = hdr->iNewSelection;
315 WideCharToMultiByte (CP_ACP, 0, itemText, -1,
316 (LPSTR)&ansi.szText, CBEMAXSTRLEN, NULL, NULL);
317 ansi.iWhy = hdr->iWhy;
318 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
325 COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
330 mydc = GetDC (0); /* why the entire screen???? */
331 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
332 ofont = (HFONT) SelectObject (mydc, nfont);
333 GetTextExtentPointA (mydc, "A", 1, size);
334 SelectObject (mydc, ofont);
336 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
341 COMBOEX_CopyItem (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
343 if (cit->mask & CBEIF_TEXT) {
345 * when given a text buffer actually use that buffer
349 lstrcpynW(cit->pszText,item->pszText,cit->cchTextMax);
353 cit->pszText = item->pszText;
354 cit->cchTextMax = item->cchTextMax;
357 if (cit->mask & CBEIF_IMAGE)
358 cit->iImage = item->iImage;
359 if (cit->mask & CBEIF_SELECTEDIMAGE)
360 cit->iSelectedImage = item->iSelectedImage;
361 if (cit->mask & CBEIF_OVERLAY)
362 cit->iOverlay = item->iOverlay;
363 if (cit->mask & CBEIF_INDENT)
364 cit->iIndent = item->iIndent;
365 if (cit->mask & CBEIF_LPARAM)
366 cit->lParam = item->lParam;
372 COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
376 INT x, y, w, h, xoff = 0;
379 if (!infoPtr->hwndEdit) return;
380 iinfo.rcImage.left = iinfo.rcImage.right = 0;
382 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
383 xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
385 GetClientRect (infoPtr->hwndCombo, &rect);
386 InflateRect (&rect, -2, -2);
387 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
389 /* reposition the Edit control based on whether icon exists */
390 COMBOEX_GetComboFontSize (infoPtr, &mysize);
391 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
392 x = xoff + CBE_STARTOFFSET + 1;
394 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
397 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
398 rect.left, rect.top, rect.right, rect.bottom,
400 SetWindowPos(infoPtr->hwndEdit, HWND_TOP,
403 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
408 COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
414 COMBOEX_GetComboFontSize (infoPtr, &mysize);
415 cy = mysize.cy + CBE_EXTRA;
417 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
418 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
419 TRACE("upgraded height due to image: height=%d\n", cy);
421 SendMessageW (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
422 if (infoPtr->hwndCombo)
423 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
424 (WPARAM) 0, (LPARAM) cy);
429 COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
431 if (!infoPtr->hwndEdit) return;
432 /* native issues the following messages to the {Edit} control */
433 /* WM_SETTEXT (0,addr) */
434 /* EM_SETSEL32 (0,0) */
435 /* EM_SETSEL32 (0,-1) */
436 if (item->mask & CBEIF_TEXT) {
437 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
438 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
439 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
444 static CBE_ITEMDATA *
445 COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
450 if ((index > infoPtr->nb_items) || (index < -1))
453 return infoPtr->edit;
454 item = infoPtr->items;
455 i = infoPtr->nb_items - 1;
457 /* find the item in the list */
458 while (item && (i > index)) {
459 item = (CBE_ITEMDATA *)item->next;
462 if (!item || (i != index)) {
463 FIXME("COMBOBOXEX item structures broken. Please report!\n");
471 COMBOEX_WarnCallBack (CBE_ITEMDATA *item)
473 if (item->pszText == LPSTR_TEXTCALLBACKW)
474 FIXME("Callback not implemented yet for pszText\n");
475 if (item->iImage == I_IMAGECALLBACK)
476 FIXME("Callback not implemented yet for iImage\n");
477 if (item->iSelectedImage == I_IMAGECALLBACK)
478 FIXME("Callback not implemented yet for iSelectedImage\n");
479 if (item->iOverlay == I_IMAGECALLBACK)
480 FIXME("Callback not implemented yet for iOverlay\n");
481 if (item->iIndent == I_INDENTCALLBACK)
482 FIXME("Callback not implemented yet for iIndent\n");
486 /* *** CBEM_xxx message support *** */
490 COMBOEX_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
492 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
493 INT index = (INT) wParam;
496 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
498 /* if item number requested does not exist then return failure */
499 if ((index > infoPtr->nb_items) || (index < 0)) {
500 ERR("attempt to delete item that does not exist\n");
504 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
505 ERR("attempt to delete item that was not found!\n");
509 /* doing this will result in WM_DELETEITEM being issued */
510 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
512 return infoPtr->nb_items;
516 inline static LRESULT
517 COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
519 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
523 return (LRESULT)infoPtr->hwndCombo;
527 inline static LRESULT
528 COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
530 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
532 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
535 TRACE("-- 0x%x\n", infoPtr->hwndEdit);
537 return (LRESULT)infoPtr->hwndEdit;
541 inline static LRESULT
542 COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
544 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
546 TRACE("-- 0x%08lx\n", infoPtr->dwExtStyle);
548 return (LRESULT)infoPtr->dwExtStyle;
552 inline static LRESULT
553 COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
555 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
557 TRACE("-- %p\n", infoPtr->himl);
559 return (LRESULT)infoPtr->himl;
564 COMBOEX_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
566 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
567 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
571 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
573 /* get real index of item to insert */
576 /* if item number requested does not exist then return failure */
577 if ((index > infoPtr->nb_items) || (index < -1)) {
578 ERR("attempt to get item that does not exist\n");
582 /* if the item is the edit control and there is no edit control, skip */
584 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
587 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
588 ERR("attempt to get item that was not found!\n");
592 COMBOEX_CopyItem (infoPtr, item, cit);
598 inline static LRESULT
599 COMBOEX_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
601 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
602 COMBOBOXEXITEMW tmpcit;
605 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
607 tmpcit.mask = cit->mask;
608 tmpcit.iItem = cit->iItem;
610 COMBOEX_GetItemW (hwnd, wParam, (LPARAM) &tmpcit);
612 len = WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1, 0, 0, NULL, NULL);
614 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
615 cit->pszText, cit->cchTextMax, NULL, NULL);
617 cit->iImage = tmpcit.iImage;
618 cit->iSelectedImage = tmpcit.iSelectedImage;
619 cit->iOverlay = tmpcit.iOverlay;
620 cit->iIndent = tmpcit.iIndent;
621 cit->lParam = tmpcit.lParam;
627 inline static LRESULT
628 COMBOEX_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
630 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
632 TRACE("%s hwnd=0x%x\n",
633 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
635 return infoPtr->bUnicode;
639 inline static LRESULT
640 COMBOEX_HasEditChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
642 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
644 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
646 if ((infoPtr->flags & (WCBE_ACTEDIT | WCBE_EDITCHG)) ==
647 (WCBE_ACTEDIT | WCBE_EDITCHG))
654 COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
656 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
657 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
664 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
666 /* get real index of item to insert */
668 if (index == -1) index = infoPtr->nb_items;
669 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
671 /* get space and chain it in */
672 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
674 item->pszText = NULL;
676 /* locate position to insert new item in */
677 if (index == infoPtr->nb_items) {
678 /* fast path for iItem = -1 */
679 item->next = infoPtr->items;
680 infoPtr->items = item;
683 INT i = infoPtr->nb_items-1;
684 CBE_ITEMDATA *moving = infoPtr->items;
686 while ((i > index) && moving) {
687 moving = (CBE_ITEMDATA *)moving->next;
691 FIXME("COMBOBOXEX item structures broken. Please report!\n");
695 item->next = moving->next;
699 /* fill in our hidden item structure */
700 item->mask = cit->mask;
701 if (item->mask & CBEIF_TEXT) {
706 if (!str) str = (LPWSTR) L"";
709 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
710 strcpyW (item->pszText, str);
713 item->pszText = NULL;
714 item->cchTextMax = cit->cchTextMax;
716 if (item->mask & CBEIF_IMAGE)
717 item->iImage = cit->iImage;
718 if (item->mask & CBEIF_SELECTEDIMAGE)
719 item->iSelectedImage = cit->iSelectedImage;
720 if (item->mask & CBEIF_OVERLAY)
721 item->iOverlay = cit->iOverlay;
722 if (item->mask & CBEIF_INDENT)
723 item->iIndent = cit->iIndent;
724 if (item->mask & CBEIF_LPARAM)
725 item->lParam = cit->lParam;
728 COMBOEX_WarnCallBack (item);
730 COMBOEX_DumpItem (item);
732 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
733 (WPARAM)cit->iItem, (LPARAM)item);
735 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
736 COMBOEX_CopyItem (infoPtr, item, &nmcit.ceItem);
737 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
745 COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
747 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
748 COMBOBOXEXITEMW citW;
751 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
752 if (cit->mask & CBEIF_TEXT) {
758 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
760 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
761 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
764 ret = COMBOEX_InsertItemW(hwnd,wParam,(LPARAM)&citW);;
766 if (cit->mask & CBEIF_TEXT)
767 COMCTL32_Free(citW.pszText);
773 COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
775 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
778 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
780 dwTemp = infoPtr->dwExtStyle;
782 if (lParam & (CBES_EX_NOEDITIMAGEINDENT |
783 CBES_EX_PATHWORDBREAKPROC |
784 CBES_EX_NOSIZELIMIT |
785 CBES_EX_CASESENSITIVE))
786 FIXME("Extended style not implemented %08lx\n", lParam);
789 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
792 infoPtr->dwExtStyle = (DWORD)lParam;
795 * native does this for CBES_EX_NOEDITIMAGE state change
797 if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
798 (dwTemp & CBES_EX_NOEDITIMAGE)) {
799 /* if state of EX_NOEDITIMAGE changes, invalidate all */
800 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
801 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
802 InvalidateRect (hwnd, NULL, TRUE);
803 COMBOEX_AdjustEditPos (infoPtr);
804 if (infoPtr->hwndEdit)
805 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
808 return (LRESULT)dwTemp;
812 inline static LRESULT
813 COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
815 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
818 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
820 himlTemp = infoPtr->himl;
821 infoPtr->himl = (HIMAGELIST)lParam;
823 COMBOEX_ReSize (hwnd, infoPtr);
824 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
826 /* reposition the Edit control based on whether icon exists */
827 COMBOEX_AdjustEditPos (infoPtr);
828 return (LRESULT)himlTemp;
832 COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
834 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
835 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
839 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
841 /* get real index of item to insert */
844 /* if item number requested does not exist then return failure */
845 if ((index > infoPtr->nb_items) || (index < -1)) {
846 ERR("attempt to set item that does not exist yet!\n");
850 /* if the item is the edit control and there is no edit control, skip */
852 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
855 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
856 ERR("attempt to set item that was not found!\n");
860 /* add/change stuff to the internal item structure */
861 item->mask |= cit->mask;
862 if (cit->mask & CBEIF_TEXT) {
865 WCHAR emptystr[1] = {0};
868 if (!str) str=emptystr;
871 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
872 strcpyW(item->pszText,str);
874 item->cchTextMax = cit->cchTextMax;
876 if (cit->mask & CBEIF_IMAGE)
877 item->iImage = cit->iImage;
878 if (cit->mask & CBEIF_SELECTEDIMAGE)
879 item->iSelectedImage = cit->iSelectedImage;
880 if (cit->mask & CBEIF_OVERLAY)
881 item->iOverlay = cit->iOverlay;
882 if (cit->mask & CBEIF_INDENT)
883 item->iIndent = cit->iIndent;
884 if (cit->mask & CBEIF_LPARAM)
885 cit->lParam = cit->lParam;
887 COMBOEX_WarnCallBack (item);
889 COMBOEX_DumpItem (item);
891 /* if original request was to update edit control, do some fast foot work */
892 if (cit->iItem == -1) {
893 COMBOEX_SetEditText (infoPtr, item);
894 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
900 COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
902 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
903 COMBOBOXEXITEMW citW;
906 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
907 if (cit->mask & CBEIF_TEXT) {
913 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
915 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
916 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
919 ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
921 if (cit->mask & CBEIF_TEXT)
922 COMCTL32_Free(citW.pszText);
927 inline static LRESULT
928 COMBOEX_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
930 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
931 BOOL bTemp = infoPtr->bUnicode;
933 TRACE("to %s hwnd=0x%04x, was %s\n",
934 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd,
935 (bTemp) ? "TRUE" : "FALSE");
937 infoPtr->bUnicode = (BOOL)wParam;
944 /* *** CB_xxx message support *** */
948 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
952 LPWSTR desired = NULL;
953 INT start = (INT) wParam;
955 i = MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
957 desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
958 MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, desired, i);
961 count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0 , 0);
963 /* now search from after starting loc and wrapping back to start */
964 for(i=start+1; i<count; i++) {
965 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
966 CB_GETITEMDATA, (WPARAM)i, 0);
967 TRACE("desired=%s, item=%s\n",
968 debugstr_w(desired), debugstr_w(item->pszText));
969 if (lstrcmpiW(item->pszText, desired) == 0) {
970 COMCTL32_Free (desired);
974 for(i=0; i<=start; i++) {
975 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
976 CB_GETITEMDATA, (WPARAM)i, 0);
977 TRACE("desired=%s, item=%s\n",
978 debugstr_w(desired), debugstr_w(item->pszText));
979 if (lstrcmpiW(item->pszText, desired) == 0) {
980 COMCTL32_Free (desired);
984 COMCTL32_Free(desired);
990 COMBOEX_GetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
993 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
994 CBE_ITEMDATA *item1, *item2;
997 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
999 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
1000 item2 = COMBOEX_FindItem (infoPtr, index);
1001 if (item2 != item1) {
1002 ERR("data structures damaged!\n");
1005 if (item1->mask & CBEIF_LPARAM)
1006 lret = (LRESULT) item1->lParam;
1007 TRACE("returning 0x%08lx\n", lret);
1010 lret = (LRESULT)item1;
1011 TRACE("non-valid result from combo, returning 0x%08lx\n", lret);
1017 COMBOEX_SetCursel (HWND hwnd, WPARAM wParam, LPARAM lParam)
1020 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1024 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
1025 /* FIXME: need to clear selection */
1029 TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
1030 debugstr_w(item->pszText) : "<null>");
1031 infoPtr->selected = index;
1033 lret = SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, wParam, lParam);
1034 COMBOEX_SetEditText (infoPtr, item);
1040 COMBOEX_SetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
1043 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1044 CBE_ITEMDATA *item1, *item2;
1046 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
1048 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
1049 item2 = COMBOEX_FindItem (infoPtr, index);
1050 if (item2 != item1) {
1051 ERR("data structures damaged!\n");
1054 item1->mask |= CBEIF_LPARAM;
1055 item1->lParam = lParam;
1056 TRACE("setting lparam to 0x%08lx\n", lParam);
1059 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
1060 return (LRESULT)item1;
1065 COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
1067 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1068 RECT cb_wrect, cbx_wrect, cbx_crect;
1072 /* First, lets forward the message to the normal combo control
1073 just like Windows. */
1074 if (infoPtr->hwndCombo)
1075 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
1077 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1078 GetWindowRect (hwnd, &cbx_wrect);
1079 GetClientRect (hwnd, &cbx_crect);
1080 /* the height of comboex as height of the combo + comboex border */
1081 height = cb_wrect.bottom-cb_wrect.top
1082 + cbx_wrect.bottom-cbx_wrect.top
1083 - (cbx_crect.bottom-cbx_crect.top);
1084 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1085 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1086 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1087 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1088 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1089 cbx_wrect.right-cbx_wrect.left, height);
1090 SetWindowPos (hwnd, HWND_TOP, 0, 0,
1091 cbx_wrect.right-cbx_wrect.left,
1093 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1099 /* *** WM_xxx message support *** */
1103 COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1105 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
1106 COMBOEX_INFO *infoPtr;
1110 RECT wnrc1, clrc1, cmbwrc;
1114 /* allocate memory for info structure */
1115 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
1116 if (infoPtr == NULL) {
1117 ERR("could not allocate info memory!\n");
1121 /* initialize info structure */
1123 infoPtr->items = NULL;
1124 infoPtr->nb_items = 0;
1125 infoPtr->hwndSelf = hwnd;
1126 infoPtr->selected = -1;
1128 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1130 i = SendMessageA(GetParent (hwnd),
1131 WM_NOTIFYFORMAT, hwnd, NF_QUERY);
1132 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1133 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1137 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1139 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1141 /* create combo box */
1142 dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
1143 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
1145 GetWindowRect(hwnd, &wnrc1);
1146 GetClientRect(hwnd, &clrc1);
1147 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1148 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1149 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
1150 TRACE("combo style=%08lx, adding style=%08lx\n", dwComboStyle,
1151 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1152 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1153 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED);
1155 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1156 /* specified. It then creates it's own version of the EDIT control */
1157 /* and makes the ComboBox the parent. This is because a normal */
1158 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
1159 /* We also need to place the edit control at the proper location */
1160 /* (allow space for the icons). */
1162 infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
1163 /* following line added to match native */
1164 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1165 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1166 /* was base and is necessary */
1167 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
1168 cs->y, cs->x, cs->cx, cs->cy, hwnd,
1169 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1170 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
1173 * native does the following at this point according to trace:
1174 * GetWindowThreadProcessId(hwndCombo,0)
1175 * GetCurrentThreadId()
1176 * GetWindowThreadProcessId(hwndCombo, &???)
1177 * GetCurrentProcessId()
1181 * Setup a property to hold the pointer to the COMBOBOXEX
1184 test = GetPropA(infoPtr->hwndCombo, (LPCSTR)(LONG)ComboExInfo);
1185 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1186 SetPropA(infoPtr->hwndCombo, "CC32SubclassInfo", (LONG)infoPtr);
1188 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndCombo,
1189 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
1190 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1194 * Now create our own EDIT control so we can position it.
1195 * It is created only for CBS_DROPDOWN style
1197 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1198 infoPtr->hwndEdit = CreateWindowExA (0, "EDIT", "",
1199 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1200 0, 0, 0, 0, /* will set later */
1202 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1203 GetWindowLongA (hwnd, GWL_HINSTANCE),
1206 /* native does the following at this point according to trace:
1207 * GetWindowThreadProcessId(hwndEdit,0)
1208 * GetCurrentThreadId()
1209 * GetWindowThreadProcessId(hwndEdit, &???)
1210 * GetCurrentProcessId()
1214 * Setup a property to hold the pointer to the COMBOBOXEX
1217 test = GetPropA(infoPtr->hwndEdit, (LPCSTR)(LONG)ComboExInfo);
1218 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1219 SetPropA(infoPtr->hwndEdit, "CC32SubclassInfo", (LONG)infoPtr);
1221 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndEdit,
1222 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1223 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1226 infoPtr->hwndEdit = 0;
1231 * Locate the default font if necessary and then set it in
1232 * all associated controls
1234 if (!infoPtr->font) {
1235 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1237 infoPtr->font = infoPtr->hDefaultFont = CreateFontIndirectA (&mylogfont);
1239 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1240 if (infoPtr->hwndEdit) {
1241 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1242 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1245 COMBOEX_ReSize (hwnd, infoPtr);
1247 /* Above is fairly certain, below is much less certain. */
1249 GetWindowRect(hwnd, &wnrc1);
1250 GetClientRect(hwnd, &clrc1);
1251 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1252 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1253 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1254 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1255 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1256 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1257 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1258 SWP_NOACTIVATE | SWP_NOREDRAW);
1260 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1261 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1262 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1263 SetWindowPos(hwnd, HWND_TOP,
1264 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1265 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1267 COMBOEX_AdjustEditPos (infoPtr);
1270 * Create an item structure to represent the data in the
1273 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1275 item->pszText = NULL;
1277 infoPtr->edit = item;
1283 inline static LRESULT
1284 COMBOEX_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
1287 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1288 INT command = HIWORD(wParam);
1289 CBE_ITEMDATA *item = 0;
1291 INT cursel, n, oldItem;
1292 NMCBEENDEDITW cbeend;
1295 TRACE("for command %d\n", command);
1300 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1303 * from native trace of first dropdown after typing in URL in IE4
1304 * CB_GETCURSEL(Combo)
1305 * GetWindowText(Edit)
1306 * CB_GETCURSEL(Combo)
1307 * CB_GETCOUNT(Combo)
1308 * CB_GETITEMDATA(Combo, n)
1309 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1310 * CB_GETCURSEL(Combo)
1311 * CB_SETCURSEL(COMBOEX, n)
1313 * the rest is supposition
1315 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1317 /* find match from edit against those in Combobox */
1318 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1319 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1320 for (cursel = 0; cursel < n; cursel++){
1321 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1324 if ((INT)item == CB_ERR) break;
1325 if (lstrcmpiW(item->pszText, wintext) == 0) break;
1327 if ((cursel == n) || ((INT)item == CB_ERR)) {
1328 TRACE("failed to find match??? item=%p cursel=%d\n",
1330 if (infoPtr->hwndEdit)
1331 SetFocus(infoPtr->hwndEdit);
1336 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1339 if ((INT)item == CB_ERR) {
1340 TRACE("failed to find match??? item=%p cursel=%d\n",
1342 if (infoPtr->hwndEdit)
1343 SetFocus(infoPtr->hwndEdit);
1348 /* Save flags for testing and reset them */
1349 oldflags = infoPtr->flags;
1350 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1352 if (oldflags & WCBE_ACTEDIT) {
1353 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1354 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1355 CB_GETCURSEL, 0, 0);
1356 cbeend.iWhy = CBENF_DROPDOWN;
1358 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, item->pszText)) {
1359 /* abort the change */
1360 TRACE("Notify requested abort of change\n");
1365 /* if selection has changed the set the new current selection */
1366 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1367 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1368 infoPtr->selected = cursel;
1369 SendMessageW (hwnd, CB_SETCURSEL, cursel, 0);
1370 SetFocus(infoPtr->hwndCombo);
1376 * CB_GETCURSEL(Combo)
1377 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1380 * WM_GETTEXTLENGTH(Edit)
1382 * EM_SETSEL(Edit, 0,0)
1383 * WM_GETTEXTLENGTH(Edit)
1385 * EM_SETSEL(Edit, 0,len)
1386 * return WM_COMMAND to parent
1388 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1389 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1390 ERR("item %d not found. Problem!\n", oldItem);
1393 infoPtr->selected = oldItem;
1394 COMBOEX_SetEditText (infoPtr, item);
1395 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1400 * We have to change the handle since we are the control
1401 * issuing the message. IE4 depends on this.
1403 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1408 * from native trace:
1411 * WM_GETTEXT(Edit, 104)
1412 * CB_GETCURSEL(Combo) rets -1
1413 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1414 * CB_GETCURSEL(Combo)
1415 * InvalidateRect(Combo, 0, 0)
1418 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1420 if (infoPtr->flags & WCBE_ACTEDIT) {
1421 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1422 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1423 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1424 CB_GETCURSEL, 0, 0);
1425 cbeend.iWhy = CBENF_KILLFOCUS;
1427 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1428 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) {
1429 /* abort the change */
1430 TRACE("Notify requested abort of change\n");
1434 /* possible CB_GETCURSEL */
1435 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1441 * We have to change the handle since we are the control
1442 * issuing the message. IE4 depends on this.
1443 * We also need to set the focus back to the Edit control
1444 * after passing the command to the parent of the ComboEx.
1446 lret = SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1448 if (infoPtr->hwndEdit)
1449 SetFocus(infoPtr->hwndEdit);
1456 inline static LRESULT
1457 COMBOEX_WM_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1459 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1460 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)lParam;
1461 CBE_ITEMDATA *item, *olditem;
1463 NMCOMBOBOXEXW nmcit;
1465 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1466 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1468 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1470 olditem = infoPtr->items;
1471 i = infoPtr->nb_items - 1;
1473 if (i == dis->itemID) {
1474 infoPtr->items = infoPtr->items->next;
1480 /* find the prior item in the list */
1481 while (item->next && (i > dis->itemID)) {
1482 item = (CBE_ITEMDATA *)item->next;
1485 if (!item->next || (i != dis->itemID)) {
1486 FIXME("COMBOBOXEX item structures broken. Please report!\n");
1489 olditem = item->next;
1490 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1492 infoPtr->nb_items--;
1494 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1495 COMBOEX_CopyItem (infoPtr, olditem, &nmcit.ceItem);
1496 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1498 if (olditem->pszText)
1499 COMCTL32_Free(olditem->pszText);
1500 COMCTL32_Free(olditem);
1507 inline static LRESULT
1508 COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1510 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1511 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
1512 CBE_ITEMDATA *item = 0;
1516 int drawimage, drawstate;
1518 UINT xioff = 0; /* size and spacer of image if any */
1521 COLORREF nbkc, ntxc;
1523 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1525 /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
1526 if (!TRACE_ON(message)) {
1527 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1528 dis->CtlType, dis->CtlID);
1529 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1530 dis->itemID, dis->itemAction, dis->itemState);
1531 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1532 dis->hwndItem, dis->hDC, dis->rcItem.left,
1533 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1538 /* "itemID - Specifies the menu item identifier for a menu */
1539 /* item or the index of the item in a list box or combo box. */
1540 /* For an empty list box or combo box, this member can be -1. */
1541 /* This allows the application to draw only the focus */
1542 /* rectangle at the coordinates specified by the rcItem */
1543 /* member even though there are no items in the control. */
1544 /* This indicates to the user whether the list box or combo */
1545 /* box has the focus. How the bits are set in the itemAction */
1546 /* member determines whether the rectangle is to be drawn as */
1547 /* though the list box or combo box has the focus. */
1548 if (dis->itemID == 0xffffffff) {
1549 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1550 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1552 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1553 dis->rcItem.left, dis->rcItem.top,
1554 dis->rcItem.right, dis->rcItem.bottom);
1556 else if ((dis->CtlType == ODT_COMBOBOX) &&
1557 (dis->itemAction == ODA_DRAWENTIRE)) {
1558 /* draw of edit control data */
1562 RECT exrc, cbrc, edrc;
1563 GetWindowRect (hwnd, &exrc);
1564 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1565 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1566 if (infoPtr->hwndEdit)
1567 GetWindowRect (infoPtr->hwndEdit, &edrc);
1568 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1569 exrc.left, exrc.top, exrc.right, exrc.bottom,
1570 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1571 edrc.left, edrc.top, edrc.right, edrc.bottom);
1575 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1576 dis->rcItem.left, dis->rcItem.top,
1577 dis->rcItem.right, dis->rcItem.bottom,
1578 dis->itemAction, dis->itemState);
1583 /* If draw item is -1 (edit control) setup the item pointer */
1584 if (dis->itemID == 0xffffffff) {
1588 item = infoPtr->edit;
1590 if (infoPtr->hwndEdit) {
1592 /* free previous text of edit item */
1593 if (item->pszText) {
1594 COMCTL32_Free(item->pszText);
1596 item->mask &= ~CBEIF_TEXT;
1598 alen = SendMessageA (infoPtr->hwndEdit, WM_GETTEXT, 260, (LPARAM)&str);
1599 TRACE("edit control hwndEdit=%0x, text len=%d str=<%s>\n",
1600 infoPtr->hwndEdit, alen, str);
1602 item->mask |= CBEIF_TEXT;
1603 wlen = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
1605 item->pszText = (LPWSTR)COMCTL32_Alloc ((wlen + 1)*sizeof(WCHAR));
1606 MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, wlen);
1612 /* if the item pointer is not set, then get the data and locate it */
1614 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1615 CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
1616 if (item == (CBE_ITEMDATA *)CB_ERR)
1618 FIXME("invalid item for id %d \n",dis->itemID);
1623 COMBOEX_DumpItem (item);
1625 xbase = CBE_STARTOFFSET;
1626 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
1627 xbase += (item->iIndent * CBE_INDENT);
1628 if (item->mask & CBEIF_IMAGE) {
1629 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
1630 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
1633 switch (dis->itemAction) {
1635 if (dis->itemState & ODS_SELECTED /*1*/) {
1636 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1639 len = strlenW (item->pszText);
1640 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1641 rect.left = xbase + xioff - 1;
1642 rect.right = rect.left + txtsize.cx + 2;
1643 rect.top = dis->rcItem.top;
1644 rect.bottom = dis->rcItem.bottom;
1645 GetClipBox (dis->hDC, &rect2);
1646 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
1647 dis->itemID, rect.left, rect.top,
1648 rect.right, rect.bottom);
1649 TRACE(" clip=(%d,%d)-(%d,%d)\n",
1650 rect2.left, rect2.top,
1651 rect2.right, rect2.bottom);
1653 DrawFocusRect(dis->hDC, &rect);
1656 FIXME("ODA_FOCUS and ODS_SELECTED but no text\n");
1660 FIXME("ODA_FOCUS but not ODS_SELECTED\n");
1664 case ODA_DRAWENTIRE:
1666 drawstate = ILD_NORMAL;
1667 if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
1668 if (item->mask & CBEIF_IMAGE)
1669 drawimage = item->iImage;
1670 if (dis->itemState & ODS_COMBOEXLBOX) {
1671 /* drawing listbox entry */
1672 if (dis->itemState & ODS_SELECTED) {
1673 if (item->mask & CBEIF_SELECTEDIMAGE)
1674 drawimage = item->iSelectedImage;
1675 drawstate = ILD_SELECTED;
1679 /* drawing combo/edit entry */
1680 if (infoPtr->hwndEdit) {
1681 /* if we have an edit control, the slave the
1682 * selection state to the Edit focus state
1684 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1685 if (item->mask & CBEIF_SELECTEDIMAGE)
1686 drawimage = item->iSelectedImage;
1687 drawstate = ILD_SELECTED;
1691 /* if we don't have an edit control, use
1692 * the requested state.
1694 if (dis->itemState & ODS_SELECTED) {
1695 if (item->mask & CBEIF_SELECTEDIMAGE)
1696 drawimage = item->iSelectedImage;
1697 drawstate = ILD_SELECTED;
1702 if (drawimage != -1) {
1703 TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
1704 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
1705 xbase, dis->rcItem.top, drawstate);
1708 /* setup pointer to text to be drawn */
1709 if ((item->mask & CBEIF_TEXT) && item->pszText)
1710 str = item->pszText;
1714 /* now draw the text */
1715 len = lstrlenW (str);
1716 GetTextExtentPointW (dis->hDC, str, len, &txtsize);
1717 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1718 COLOR_HIGHLIGHT : COLOR_WINDOW);
1719 SetBkColor (dis->hDC, nbkc);
1720 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1721 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1722 SetTextColor (dis->hDC, ntxc);
1724 y = dis->rcItem.top +
1725 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1727 rect.right = x + txtsize.cx;
1728 rect.top = dis->rcItem.top + 1;
1729 rect.bottom = dis->rcItem.bottom - 1;
1730 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1731 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1732 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1733 &rect, str, len, 0);
1734 if (dis->itemState & ODS_FOCUS) {
1739 TRACE("drawing item %d focus after text, rect=(%d,%d)-(%d,%d)\n",
1740 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1741 DrawFocusRect (dis->hDC, &rect);
1745 FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
1746 hwnd, wParam, lParam, dis->itemAction);
1754 COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1756 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1758 if (infoPtr->hwndCombo)
1759 DestroyWindow (infoPtr->hwndCombo);
1761 if (infoPtr->edit) {
1762 COMCTL32_Free (infoPtr->edit);
1766 if (infoPtr->items) {
1767 CBE_ITEMDATA *this, *next;
1769 this = infoPtr->items;
1771 next = (CBE_ITEMDATA *)this->next;
1772 if ((this->mask & CBEIF_TEXT) && this->pszText)
1773 COMCTL32_Free (this->pszText);
1774 COMCTL32_Free (this);
1779 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
1781 /* free comboex info data */
1782 COMCTL32_Free (infoPtr);
1783 SetWindowLongA (hwnd, 0, 0);
1789 COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1791 /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
1792 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
1797 GetTextExtentPointA (hdc, "W", 1, &mysize);
1799 mis->itemHeight = mysize.cy + CBE_EXTRA;
1801 TRACE("adjusted height hwnd=%08x, height=%d\n",
1802 hwnd, mis->itemHeight);
1809 COMBOEX_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1811 /* WARNING: The COMBOEX_INFO structure is not yet created */
1812 DWORD oldstyle, newstyle;
1814 oldstyle = (DWORD)GetWindowLongA (hwnd, GWL_STYLE);
1815 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1816 if (newstyle != oldstyle) {
1817 TRACE("req style %08lx, reseting style %08lx\n",
1818 oldstyle, newstyle);
1819 SetWindowLongA (hwnd, GWL_STYLE, newstyle);
1826 COMBOEX_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1828 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1831 if (lParam == NF_REQUERY) {
1832 i = SendMessageA(GetParent (hwnd),
1833 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
1834 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1835 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1839 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1842 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
1847 COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1849 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1852 GetWindowRect (hwnd, &rect);
1853 TRACE("my rect (%d,%d)-(%d,%d)\n",
1854 rect.left, rect.top, rect.right, rect.bottom);
1856 MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
1857 rect.bottom - rect.top, TRUE);
1859 COMBOEX_AdjustEditPos (infoPtr);
1866 COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
1868 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1869 RECT cbx_wrect, cbx_crect, cb_wrect;
1871 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1873 GetWindowRect (hwnd, &cbx_wrect);
1874 GetClientRect (hwnd, &cbx_crect);
1875 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1877 /* width is winpos value + border width of comboex */
1879 + (cbx_wrect.right-cbx_wrect.left)
1880 - (cbx_crect.right-cbx_crect.left);
1882 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1883 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1884 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1885 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1886 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1887 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1888 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1889 width, cb_wrect.bottom-cb_wrect.top);
1891 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1893 cb_wrect.bottom-cb_wrect.top,
1896 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1898 /* height is combo window height plus border width of comboex */
1899 height = (cb_wrect.bottom-cb_wrect.top)
1900 + (cbx_wrect.bottom-cbx_wrect.top)
1901 - (cbx_crect.bottom-cbx_crect.top);
1902 if (wp->cy < height) wp->cy = height;
1903 if (infoPtr->hwndEdit) {
1904 COMBOEX_AdjustEditPos (infoPtr);
1905 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1912 static LRESULT WINAPI
1913 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1915 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1916 NMCBEENDEDITW cbeend;
1917 WCHAR edit_text[260];
1918 COLORREF nbkc, obkc;
1923 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1924 hwnd, uMsg, wParam, lParam, infoPtr);
1926 if (!infoPtr) return 0;
1932 /* handle (ignore) the return character */
1933 if (wParam == VK_RETURN) return 0;
1934 /* all other characters pass into the real Edit */
1935 return CallWindowProcA (infoPtr->prevEditWndProc,
1936 hwnd, uMsg, wParam, lParam);
1940 * The following was determined by traces of the native
1943 nbkc = GetSysColor (COLOR_WINDOW);
1944 obkc = SetBkColor (hDC, nbkc);
1945 GetClientRect (hwnd, &rect);
1946 TRACE("erasing (%d,%d)-(%d,%d)\n",
1947 rect.left, rect.top, rect.right, rect.bottom);
1948 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1949 SetBkColor (hDC, obkc);
1950 return CallWindowProcA (infoPtr->prevEditWndProc,
1951 hwnd, uMsg, wParam, lParam);
1954 INT oldItem, selected;
1957 switch ((INT)wParam)
1960 /* native version seems to do following for COMBOEX */
1962 * GetWindowTextA(Edit,&?, 0x104) x
1963 * CB_GETCURSEL to Combo rets -1 x
1964 * WM_NOTIFY to COMBOEX parent (rebar) x
1965 * (CBEN_ENDEDIT{A|W}
1966 * fChanged = FALSE x
1967 * inewSelection = -1 x
1970 * CB_GETCURSEL to Combo rets -1 x
1971 * InvalidateRect(Combo, 0) x
1972 * WM_SETTEXT to Edit x
1973 * EM_SETSEL to Edit (0,0) x
1974 * EM_SETSEL to Edit (0,-1) x
1975 * RedrawWindow(Combo, 0, 0, 5) x
1977 TRACE("special code for VK_ESCAPE\n");
1979 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1981 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1982 cbeend.fChanged = FALSE;
1983 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1984 CB_GETCURSEL, 0, 0);
1985 cbeend.iWhy = CBENF_ESCAPE;
1987 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1988 /* abort the change */
1989 TRACE("Notify requested abort of change\n");
1992 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1993 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1994 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1995 ERR("item %d not found. Problem!\n", oldItem);
1998 infoPtr->selected = oldItem;
1999 COMBOEX_SetEditText (infoPtr, item);
2000 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
2005 /* native version seems to do following for COMBOEX */
2007 * GetWindowTextA(Edit,&?, 0x104) x
2008 * CB_GETCURSEL to Combo rets -1 x
2009 * CB_GETCOUNT to Combo rets 0
2011 * CB_GETITEMDATA to match
2012 * *** above 3 lines simulated by FindItem x
2013 * WM_NOTIFY to COMBOEX parent (rebar) x
2014 * (CBEN_ENDEDIT{A|W} x
2015 * fChanged = TRUE (-1) x
2016 * iNewSelection = -1 or selected x
2018 * iWhy = 2 (CBENF_RETURN) x
2019 * CB_GETCURSEL to Combo rets -1 x
2020 * if -1 send CB_SETCURSEL to Combo -1 x
2021 * InvalidateRect(Combo, 0, 0) x
2023 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
2026 TRACE("special code for VK_RETURN\n");
2028 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2030 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2031 selected = SendMessageW (infoPtr->hwndCombo,
2032 CB_GETCURSEL, 0, 0);
2034 if (selected != -1) {
2035 item = COMBOEX_FindItem (infoPtr, selected);
2036 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
2037 selected, debugstr_w(item->pszText));
2038 TRACE("handling VK_RETURN, edittext=%s\n",
2039 debugstr_w(edit_text));
2040 if (lstrcmpiW (item->pszText, edit_text)) {
2041 /* strings not equal -- indicate edit has changed */
2046 cbeend.iNewSelection = selected;
2047 cbeend.fChanged = TRUE;
2048 cbeend.iWhy = CBENF_RETURN;
2049 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2050 /* abort the change, restore previous */
2051 TRACE("Notify requested abort of change\n");
2052 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
2053 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
2057 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
2058 if (oldItem != -1) {
2059 /* if something is selected, then deselect it */
2060 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
2063 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2064 SetFocus(infoPtr->hwndEdit);
2068 return CallWindowProcA (infoPtr->prevEditWndProc,
2069 hwnd, uMsg, wParam, lParam);
2075 /* remember the focus to set state of icon */
2076 lret = CallWindowProcA (infoPtr->prevEditWndProc,
2077 hwnd, uMsg, wParam, lParam);
2078 infoPtr->flags |= WCBE_EDITFOCUSED;
2083 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
2085 infoPtr->flags &= ~WCBE_EDITFOCUSED;
2086 if (infoPtr->flags & WCBE_ACTEDIT) {
2087 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2089 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2090 cbeend.fChanged = FALSE;
2091 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2092 CB_GETCURSEL, 0, 0);
2093 cbeend.iWhy = CBENF_KILLFOCUS;
2095 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
2100 return CallWindowProcA (infoPtr->prevEditWndProc,
2101 hwnd, uMsg, wParam, lParam);
2107 static LRESULT WINAPI
2108 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2110 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
2111 NMCBEENDEDITW cbeend;
2113 COLORREF nbkc, obkc;
2117 WCHAR edit_text[260];
2119 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
2120 hwnd, uMsg, wParam, lParam, infoPtr);
2122 if (!infoPtr) return 0;
2127 case CB_FINDSTRINGEXACT:
2128 return COMBOEX_FindStringExact (infoPtr, wParam, lParam);
2132 * The only way this message should come is from the
2133 * child Listbox issuing the message. Flag this so
2134 * that ComboEx knows this is listbox.
2136 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
2137 return CallWindowProcA (infoPtr->prevComboWndProc,
2138 hwnd, uMsg, wParam, lParam);
2142 * The following was determined by traces of the native
2145 nbkc = GetSysColor (COLOR_WINDOW);
2146 obkc = SetBkColor (hDC, nbkc);
2147 GetClientRect (hwnd, &rect);
2148 TRACE("erasing (%d,%d)-(%d,%d)\n",
2149 rect.left, rect.top, rect.right, rect.bottom);
2150 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
2151 SetBkColor (hDC, obkc);
2152 return CallWindowProcA (infoPtr->prevComboWndProc,
2153 hwnd, uMsg, wParam, lParam);
2157 * WM_NOTIFY to comboex parent (rebar)
2158 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
2159 * CallWindowProc (previous)
2161 nmmse.dwItemSpec = 0;
2162 nmmse.dwItemData = 0;
2165 nmmse.dwHitInfo = lParam;
2166 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
2167 return CallWindowProcA (infoPtr->prevComboWndProc,
2168 hwnd, uMsg, wParam, lParam);
2171 switch (HIWORD(wParam)) {
2174 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2183 * GetFocus() retns AA
2184 * GetWindowTextA(Edit)
2185 * CB_GETCURSEL(Combo) (got -1)
2186 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2187 * CB_GETCURSEL(Combo) (got -1)
2188 * InvalidateRect(Combo, 0, 0)
2189 * WM_KILLFOCUS(Combo, AA)
2192 focusedhwnd = GetFocus();
2193 if (infoPtr->flags & WCBE_ACTEDIT) {
2194 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2195 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2196 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2197 CB_GETCURSEL, 0, 0);
2198 cbeend.iWhy = CBENF_KILLFOCUS;
2200 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2201 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2202 /* abort the change */
2203 TRACE("Notify requested abort of change\n");
2207 /* possible CB_GETCURSEL */
2208 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2210 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2211 (WPARAM)focusedhwnd, 0);
2216 * For EN_SETFOCUS this issues the same calls and messages
2217 * as the native seems to do.
2219 * for some cases however native does the following:
2220 * (noticed after SetFocus during LBUTTONDOWN on
2221 * on dropdown arrow)
2222 * WM_GETTEXTLENGTH (Edit);
2223 * WM_GETTEXT (Edit, len+1, str);
2224 * EM_SETSEL (Edit, 0, 0);
2225 * WM_GETTEXTLENGTH (Edit);
2226 * WM_GETTEXT (Edit, len+1, str);
2227 * EM_SETSEL (Edit, 0, len);
2228 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2232 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2233 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2234 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2235 infoPtr->flags |= WCBE_ACTEDIT;
2236 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2242 * For EN_CHANGE this issues the same calls and messages
2243 * as the native seems to do.
2245 WCHAR edit_text[260];
2250 selected = SendMessageW (infoPtr->hwndCombo,
2251 CB_GETCURSEL, 0, 0);
2253 /* lstrlenA( lastworkingURL ) */
2255 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2256 if (selected == -1) {
2257 lastwrk = infoPtr->edit->pszText;
2258 cnt = lstrlenW (lastwrk);
2259 if (cnt >= 259) cnt = 259;
2262 item = COMBOEX_FindItem (infoPtr, selected);
2263 cnt = lstrlenW (item->pszText);
2264 lastwrk = item->pszText;
2265 if (cnt >= 259) cnt = 259;
2268 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2269 selected, debugstr_w(lastwrk));
2270 TRACE("handling EN_CHANGE, edittext=%s\n",
2271 debugstr_w(edit_text));
2273 /* lstrcmpiW is between lastworkingURL and GetWindowText */
2275 if (lstrcmpiW (lastwrk, edit_text)) {
2276 /* strings not equal -- indicate edit has changed */
2277 infoPtr->flags |= WCBE_EDITCHG;
2279 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2280 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2288 * Therefore from traces there is no additional code here
2292 * Using native COMCTL32 gets the following:
2293 * 1 == SHDOCVW.DLL issues call/message
2294 * 2 == COMCTL32.DLL issues call/message
2295 * 3 == WINE issues call/message
2298 * for LBN_SELCHANGE:
2299 * 1 CB_GETCURSEL(ComboEx)
2300 * 1 CB_GETDROPPEDSTATE(ComboEx)
2301 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2302 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2303 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2304 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2305 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2306 * 3 ShowWindow(ComboLB, SW_HIDE)
2307 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2308 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2310 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2311 * ? LB_GETCURSEL <==|
2313 * ? LB_GETTEXT | Needs to be added to
2314 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2315 * ? LB_GETITEMDATA |
2316 * ? WM_DRAWITEM(ComboEx) <==|
2322 return CallWindowProcA (infoPtr->prevComboWndProc,
2323 hwnd, uMsg, wParam, lParam);
2329 static LRESULT WINAPI
2330 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2332 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2334 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2336 if (!COMBOEX_GetInfoPtr (hwnd)) {
2337 if (uMsg == WM_CREATE)
2338 return COMBOEX_Create (hwnd, wParam, lParam);
2339 if (uMsg == WM_NCCREATE)
2340 COMBOEX_NCCreate (hwnd, wParam, lParam);
2341 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2346 case CBEM_DELETEITEM: /* maps to CB_DELETESTRING */
2347 return COMBOEX_DeleteItem (hwnd, wParam, lParam);
2349 case CBEM_GETCOMBOCONTROL:
2350 return COMBOEX_GetComboControl (hwnd, wParam, lParam);
2352 case CBEM_GETEDITCONTROL:
2353 return COMBOEX_GetEditControl (hwnd, wParam, lParam);
2355 case CBEM_GETEXTENDEDSTYLE:
2356 return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
2358 case CBEM_GETIMAGELIST:
2359 return COMBOEX_GetImageList (hwnd, wParam, lParam);
2362 return COMBOEX_GetItemA (hwnd, wParam, lParam);
2365 return COMBOEX_GetItemW (hwnd, wParam, lParam);
2367 case CBEM_GETUNICODEFORMAT:
2368 return COMBOEX_GetUnicodeFormat (hwnd, wParam, lParam);
2370 case CBEM_HASEDITCHANGED:
2371 return COMBOEX_HasEditChanged (hwnd, wParam, lParam);
2373 case CBEM_INSERTITEMA:
2374 return COMBOEX_InsertItemA (hwnd, wParam, lParam);
2376 case CBEM_INSERTITEMW:
2377 return COMBOEX_InsertItemW (hwnd, wParam, lParam);
2379 case CBEM_SETEXSTYLE: /* FIXME: obsoleted, should be the same as: */
2380 case CBEM_SETEXTENDEDSTYLE:
2381 return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
2383 case CBEM_SETIMAGELIST:
2384 return COMBOEX_SetImageList (hwnd, wParam, lParam);
2387 return COMBOEX_SetItemA (hwnd, wParam, lParam);
2390 return COMBOEX_SetItemW (hwnd, wParam, lParam);
2392 case CBEM_SETUNICODEFORMAT:
2393 return COMBOEX_SetUnicodeFormat (hwnd, wParam, lParam);
2396 /* Combo messages we are not sure if we need to process or just forward */
2397 case CB_GETDROPPEDCONTROLRECT:
2398 case CB_GETITEMHEIGHT:
2400 case CB_GETLBTEXTLEN:
2401 case CB_GETEXTENDEDUI:
2403 case CB_RESETCONTENT:
2404 case CB_SELECTSTRING:
2407 FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
2408 uMsg, wParam, lParam);
2409 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2411 /* Combo messages OK to just forward to the regular COMBO */
2414 case CB_GETDROPPEDSTATE:
2415 case CB_SETDROPPEDWIDTH:
2416 case CB_SETEXTENDEDUI:
2417 case CB_SHOWDROPDOWN:
2418 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2420 /* Combo messages we need to process specially */
2421 case CB_FINDSTRINGEXACT:
2422 return COMBOEX_FindStringExact (COMBOEX_GetInfoPtr (hwnd),
2425 case CB_GETITEMDATA:
2426 return COMBOEX_GetItemData (hwnd, wParam, lParam);
2429 return COMBOEX_SetCursel (hwnd, wParam, lParam);
2431 case CB_SETITEMDATA:
2432 return COMBOEX_SetItemData (hwnd, wParam, lParam);
2434 case CB_SETITEMHEIGHT:
2435 return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
2439 /* Window messages passed to parent */
2441 return COMBOEX_Command (hwnd, wParam, lParam);
2444 if (infoPtr->NtfUnicode)
2445 return SendMessageW (GetParent (hwnd),
2446 uMsg, wParam, lParam);
2448 return SendMessageA (GetParent (hwnd),
2449 uMsg, wParam, lParam);
2452 /* Window messages we need to process */
2454 return COMBOEX_WM_DeleteItem (hwnd, wParam, lParam);
2457 return COMBOEX_DrawItem (hwnd, wParam, lParam);
2460 return COMBOEX_Destroy (hwnd, wParam, lParam);
2462 case WM_MEASUREITEM:
2463 return COMBOEX_MeasureItem (hwnd, wParam, lParam);
2465 case WM_NOTIFYFORMAT:
2466 return COMBOEX_NotifyFormat (hwnd, wParam, lParam);
2469 return COMBOEX_Size (hwnd, wParam, lParam);
2471 case WM_WINDOWPOSCHANGING:
2472 return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
2475 if (uMsg >= WM_USER)
2476 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2477 uMsg, wParam, lParam);
2478 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2485 COMBOEX_Register (void)
2489 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2490 wndClass.style = CS_GLOBALCLASS;
2491 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2492 wndClass.cbClsExtra = 0;
2493 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2494 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2495 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2496 wndClass.lpszClassName = WC_COMBOBOXEXA;
2498 RegisterClassA (&wndClass);
2500 ComboExInfo = GlobalAddAtomA("CC32SubclassInfo");
2505 COMBOEX_Unregister (void)
2507 UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);