4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2000, 2001, 2002 Guy Albertelli <galberte@neo.lrun.com>
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 9, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
62 /* ComboBoxEx structure */
66 HWND hwndSelf; /* my own hwnd */
67 HWND hwndNotify; /* my parent hwnd */
70 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
71 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
73 INT selected; /* index of selected item */
74 DWORD flags; /* WINE internal flags */
77 INT nb_items; /* Number of items */
78 BOOL unicode; /* TRUE if this window is Unicode */
79 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
80 CBE_ITEMDATA *edit; /* item data for edit item */
81 CBE_ITEMDATA *items; /* Array of items */
84 /* internal flags in the COMBOEX_INFO structure */
85 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
86 * CBEN_BEGINEDIT issued
87 * but CBEN_ENDEDIT{A|W}
89 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
90 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
91 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
92 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
93 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
95 #define ID_CB_EDIT 1001
99 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
100 * the ComboEx version of the Combo Window Proc so that when the
101 * WM_DRAWITEM message is then passed to ComboEx, we know that this
102 * particular WM_DRAWITEM message is for listbox only items. Any messasges
103 * without this flag is then for the Edit control field.
105 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
106 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
108 #define ODS_COMBOEXLBOX 0x4000
112 /* Height in pixels of control over the amount of the selected font */
115 /* Indent amount per MS documentation */
116 #define CBE_INDENT 10
118 /* Offset in pixels from left side for start of image or text */
119 #define CBE_STARTOFFSET 6
121 /* Offset between image and text */
124 #define COMBOEX_SUBCLASS_PROP "CCComboEx32SubclassInfo"
125 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongPtrW (hwnd, 0))
128 /* Things common to the entire DLL */
129 static LRESULT WINAPI
130 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
131 static LRESULT WINAPI
132 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
133 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
134 typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
136 inline static BOOL is_textW(LPCWSTR str)
138 return str && str != LPSTR_TEXTCALLBACKW;
141 inline static BOOL is_textA(LPCSTR str)
143 return str && str != LPSTR_TEXTCALLBACKA;
146 inline static LPCSTR debugstr_txt(LPCWSTR str)
148 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
149 return debugstr_w(str);
152 static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
154 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
155 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
156 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
157 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
158 if (item->mask & CBEIF_TEXT)
159 TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
163 static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
165 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
166 input->mask, input->iItem, input->pszText, input->cchTextMax,
168 if (input->mask & CBEIF_TEXT)
169 TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
170 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
171 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
175 inline static CBE_ITEMDATA *get_item_data(COMBOEX_INFO *infoPtr, INT index)
177 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
181 inline static cmp_func_t get_cmp_func(COMBOEX_INFO *infoPtr)
183 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
186 static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
188 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
189 hdr->hwndFrom = infoPtr->hwndSelf;
191 if (infoPtr->NtfUnicode)
192 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
194 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
199 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
201 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
202 if (infoPtr->NtfUnicode)
203 return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
205 LPWSTR wstr = hdr->ceItem.pszText;
209 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
210 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
212 astr = (LPSTR)Alloc ((len + 1)*sizeof(CHAR));
214 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
215 hdr->ceItem.pszText = (LPWSTR)astr;
219 if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
220 else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
221 else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
223 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
225 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
226 hdr->ceItem.pszText = wstr;
228 if (astr) Free(astr);
235 static INT COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
237 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
238 if (infoPtr->NtfUnicode) {
239 lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
240 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
244 memcpy (&neea.hdr, &neew->hdr, sizeof(NMHDR));
245 neea.fChanged = neew->fChanged;
246 neea.iNewSelection = neew->iNewSelection;
247 WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
248 neea.iWhy = neew->iWhy;
250 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
255 static void COMBOEX_NotifyDragBegin(COMBOEX_INFO *infoPtr, LPCWSTR wstr)
257 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
258 if (infoPtr->NtfUnicode) {
259 NMCBEDRAGBEGINW ndbw;
262 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
263 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
265 NMCBEDRAGBEGINA ndba;
268 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
270 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
275 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
277 if (is_textW(item->pszText)) Free(item->pszText);
279 if (item->pszTemp) Free(item->pszTemp);
284 static LPCWSTR COMBOEX_GetText(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
290 if (item->pszText != LPSTR_TEXTCALLBACKW)
291 return item->pszText;
293 ZeroMemory(&nmce, sizeof(nmce));
294 nmce.ceItem.mask = CBEIF_TEXT;
295 nmce.ceItem.lParam = item->lParam;
296 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
298 if (is_textW(nmce.ceItem.pszText)) {
299 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
300 buf = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
302 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
303 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
304 COMBOEX_FreeText(item);
307 if (item->pszTemp) Free(item->pszTemp);
312 text = nmce.ceItem.pszText;
314 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
315 item->pszText = text;
320 static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
325 mydc = GetDC (0); /* why the entire screen???? */
326 nfont = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
327 ofont = (HFONT) SelectObject (mydc, nfont);
328 GetTextExtentPointA (mydc, "A", 1, size);
329 SelectObject (mydc, ofont);
331 TRACE("selected font hwnd=%p, height=%ld\n", nfont, size->cy);
335 static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
337 if (cit->mask & CBEIF_TEXT) {
339 * when given a text buffer actually use that buffer
342 if (is_textW(item->pszText))
343 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
347 cit->pszText = item->pszText;
348 cit->cchTextMax = item->cchTextMax;
351 if (cit->mask & CBEIF_IMAGE)
352 cit->iImage = item->iImage;
353 if (cit->mask & CBEIF_SELECTEDIMAGE)
354 cit->iSelectedImage = item->iSelectedImage;
355 if (cit->mask & CBEIF_OVERLAY)
356 cit->iOverlay = item->iOverlay;
357 if (cit->mask & CBEIF_INDENT)
358 cit->iIndent = item->iIndent;
359 if (cit->mask & CBEIF_LPARAM)
360 cit->lParam = item->lParam;
364 static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
367 INT x, y, w, h, xioff;
370 if (!infoPtr->hwndEdit) return;
372 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
374 iinfo.rcImage.left = iinfo.rcImage.right = 0;
375 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
376 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
379 GetClientRect (infoPtr->hwndCombo, &rect);
380 InflateRect (&rect, -2, -2);
381 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
383 /* reposition the Edit control based on whether icon exists */
384 COMBOEX_GetComboFontSize (infoPtr, &mysize);
385 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
386 x = xioff + CBE_STARTOFFSET + 1;
387 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
389 y = rect.bottom - h - 1;
391 TRACE("Combo client (%ld,%ld)-(%ld,%ld), setting Edit to (%d,%d)-(%d,%d)\n",
392 rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
393 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
394 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
398 static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
404 COMBOEX_GetComboFontSize (infoPtr, &mysize);
405 cy = mysize.cy + CBE_EXTRA;
406 if (infoPtr->himl && ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo)) {
407 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
408 TRACE("upgraded height due to image: height=%ld\n", cy);
410 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)cy);
411 if (infoPtr->hwndCombo) {
412 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
413 (WPARAM) 0, (LPARAM) cy);
414 if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
416 if (GetWindowRect(infoPtr->hwndCombo, &comboRect)) {
418 if (GetWindowRect(infoPtr->hwndSelf, &ourRect)) {
419 if (comboRect.bottom > ourRect.bottom) {
420 POINT pt = { ourRect.left, ourRect.top };
421 if (ScreenToClient(infoPtr->hwndSelf, &pt))
422 MoveWindow( infoPtr->hwndSelf, pt.x, pt.y, ourRect.right - ourRect.left,
423 comboRect.bottom - comboRect.top, FALSE);
432 static void COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
434 if (!infoPtr->hwndEdit) return;
435 /* native issues the following messages to the {Edit} control */
436 /* WM_SETTEXT (0,addr) */
437 /* EM_SETSEL32 (0,0) */
438 /* EM_SETSEL32 (0,-1) */
439 if (item->mask & CBEIF_TEXT) {
440 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
441 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
442 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
447 static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
452 if ((index > infoPtr->nb_items) || (index < -1))
455 return infoPtr->edit;
456 item = infoPtr->items;
457 i = infoPtr->nb_items - 1;
459 /* find the item in the list */
460 while (item && (i > index)) {
461 item = (CBE_ITEMDATA *)item->next;
464 if (!item || (i != index)) {
465 ERR("COMBOBOXEX item structures broken. Please report!\n");
472 static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO *infoPtr)
474 return infoPtr->hwndEdit ? TRUE : FALSE;
478 /* *** CBEM_xxx message support *** */
481 static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
485 TRACE("(index=%d)\n", index);
487 /* if item number requested does not exist then return failure */
488 if ((index > infoPtr->nb_items) || (index < 0)) return CB_ERR;
489 if (!(item = COMBOEX_FindItem(infoPtr, index))) return CB_ERR;
491 /* doing this will result in WM_DELETEITEM being issued */
492 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
494 return infoPtr->nb_items;
498 static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
500 INT index = cit->iItem;
505 /* if item number requested does not exist then return failure */
506 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
508 /* if the item is the edit control and there is no edit control, skip */
509 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
511 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
513 COMBOEX_CopyItem (item, cit);
519 static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
521 COMBOBOXEXITEMW tmpcit;
525 tmpcit.mask = cit->mask;
526 tmpcit.iItem = cit->iItem;
528 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
530 if (is_textW(tmpcit.pszText) && cit->pszText)
531 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
532 cit->pszText, cit->cchTextMax, NULL, NULL);
533 else if (cit->pszText) cit->pszText[0] = 0;
534 else cit->pszText = (LPSTR)tmpcit.pszText;
536 cit->iImage = tmpcit.iImage;
537 cit->iSelectedImage = tmpcit.iSelectedImage;
538 cit->iOverlay = tmpcit.iOverlay;
539 cit->iIndent = tmpcit.iIndent;
540 cit->lParam = tmpcit.lParam;
546 inline static BOOL COMBOEX_HasEditChanged (COMBOEX_INFO *infoPtr)
548 return COMBOEX_HasEdit(infoPtr) &&
549 (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
553 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
561 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
563 /* get real index of item to insert */
565 if (index == -1) index = infoPtr->nb_items;
566 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
568 /* get zero-filled space and chain it in */
569 if(!(item = (CBE_ITEMDATA *)Alloc (sizeof(*item)))) return -1;
571 /* locate position to insert new item in */
572 if (index == infoPtr->nb_items) {
573 /* fast path for iItem = -1 */
574 item->next = infoPtr->items;
575 infoPtr->items = item;
578 INT i = infoPtr->nb_items-1;
579 CBE_ITEMDATA *moving = infoPtr->items;
581 while ((i > index) && moving) {
582 moving = (CBE_ITEMDATA *)moving->next;
586 ERR("COMBOBOXEX item structures broken. Please report!\n");
590 item->next = moving->next;
594 /* fill in our hidden item structure */
595 item->mask = cit->mask;
596 if (item->mask & CBEIF_TEXT) {
599 if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
601 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
602 if (!item->pszText) {
606 strcpyW (item->pszText, cit->pszText);
608 else if (cit->pszText == LPSTR_TEXTCALLBACKW)
609 item->pszText = LPSTR_TEXTCALLBACKW;
610 item->cchTextMax = cit->cchTextMax;
612 if (item->mask & CBEIF_IMAGE)
613 item->iImage = cit->iImage;
614 if (item->mask & CBEIF_SELECTEDIMAGE)
615 item->iSelectedImage = cit->iSelectedImage;
616 if (item->mask & CBEIF_OVERLAY)
617 item->iOverlay = cit->iOverlay;
618 if (item->mask & CBEIF_INDENT)
619 item->iIndent = cit->iIndent;
620 if (item->mask & CBEIF_LPARAM)
621 item->lParam = cit->lParam;
624 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
626 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
627 (WPARAM)cit->iItem, (LPARAM)item);
629 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
630 COMBOEX_CopyItem (item, &nmcit.ceItem);
631 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
638 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
640 COMBOBOXEXITEMW citW;
644 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
645 if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
646 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
647 wstr = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
648 if (!wstr) return -1;
649 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
652 ret = COMBOEX_InsertItemW(infoPtr, &citW);
654 if (wstr) Free(wstr);
661 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
665 TRACE("(mask=x%08lx, style=0x%08lx)\n", mask, style);
667 dwTemp = infoPtr->dwExtStyle;
670 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
672 infoPtr->dwExtStyle = style;
674 /* see if we need to change the word break proc on the edit */
675 if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC)
676 SetPathWordBreakProc(infoPtr->hwndEdit,
677 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ? TRUE : FALSE);
679 /* test if the control's appearance has changed */
680 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
681 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
682 /* if state of EX_NOEDITIMAGE changes, invalidate all */
683 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
684 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
685 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
686 COMBOEX_AdjustEditPos (infoPtr);
687 if (infoPtr->hwndEdit)
688 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
695 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
697 HIMAGELIST himlTemp = infoPtr->himl;
701 infoPtr->himl = himl;
703 COMBOEX_ReSize (infoPtr);
704 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
706 /* reposition the Edit control based on whether icon exists */
707 COMBOEX_AdjustEditPos (infoPtr);
711 static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
713 INT index = cit->iItem;
716 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
718 /* if item number requested does not exist then return failure */
719 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
721 /* if the item is the edit control and there is no edit control, skip */
722 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
724 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
726 /* add/change stuff to the internal item structure */
727 item->mask |= cit->mask;
728 if (cit->mask & CBEIF_TEXT) {
731 COMBOEX_FreeText(item);
732 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
734 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
735 if (!item->pszText) return FALSE;
736 strcpyW(item->pszText, cit->pszText);
737 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
738 item->pszText = LPSTR_TEXTCALLBACKW;
739 item->cchTextMax = cit->cchTextMax;
741 if (cit->mask & CBEIF_IMAGE)
742 item->iImage = cit->iImage;
743 if (cit->mask & CBEIF_SELECTEDIMAGE)
744 item->iSelectedImage = cit->iSelectedImage;
745 if (cit->mask & CBEIF_OVERLAY)
746 item->iOverlay = cit->iOverlay;
747 if (cit->mask & CBEIF_INDENT)
748 item->iIndent = cit->iIndent;
749 if (cit->mask & CBEIF_LPARAM)
750 cit->lParam = cit->lParam;
752 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
754 /* if original request was to update edit control, do some fast foot work */
755 if (cit->iItem == -1) {
756 COMBOEX_SetEditText (infoPtr, item);
757 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
762 static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
764 COMBOBOXEXITEMW citW;
768 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
769 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
770 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
771 wstr = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
772 if (!wstr) return FALSE;
773 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
776 ret = COMBOEX_SetItemW(infoPtr, &citW);
778 if (wstr) Free(wstr);
784 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
786 BOOL bTemp = infoPtr->unicode;
788 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
790 infoPtr->unicode = value;
796 /* *** CB_xxx message support *** */
799 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
802 cmp_func_t cmptext = get_cmp_func(infoPtr);
803 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
805 /* now search from after starting loc and wrapping back to start */
806 for(i=start+1; i<count; i++) {
807 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
808 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
810 for(i=0; i<=start; i++) {
811 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
812 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
818 static DWORD COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
820 CBE_ITEMDATA *item1, *item2;
823 item1 = get_item_data(infoPtr, index);
824 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
825 item2 = COMBOEX_FindItem (infoPtr, index);
826 if (item2 != item1) {
827 ERR("data structures damaged!\n");
830 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
831 TRACE("returning 0x%08lx\n", ret);
834 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
840 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
845 if (!(item = COMBOEX_FindItem(infoPtr, index)))
846 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
848 TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
849 infoPtr->selected = index;
851 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
852 COMBOEX_SetEditText (infoPtr, item);
857 static DWORD COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD data)
859 CBE_ITEMDATA *item1, *item2;
861 item1 = get_item_data(infoPtr, index);
862 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
863 item2 = COMBOEX_FindItem (infoPtr, index);
864 if (item2 != item1) {
865 ERR("data structures damaged!\n");
868 item1->mask |= CBEIF_LPARAM;
869 item1->lParam = data;
870 TRACE("setting lparam to 0x%08lx\n", data);
873 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
874 return (LRESULT)item1;
878 static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
880 RECT cb_wrect, cbx_wrect, cbx_crect;
882 /* First, lets forward the message to the normal combo control
883 just like Windows. */
884 if (infoPtr->hwndCombo)
885 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
886 index, height) == CB_ERR) return CB_ERR;
888 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
889 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
890 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
891 /* the height of comboex as height of the combo + comboex border */
892 height = cb_wrect.bottom-cb_wrect.top
893 + cbx_wrect.bottom-cbx_wrect.top
894 - (cbx_crect.bottom-cbx_crect.top);
895 TRACE("EX window=(%ld,%ld)-(%ld,%ld), client=(%ld,%ld)-(%ld,%ld)\n",
896 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
897 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
898 TRACE("CB window=(%ld,%ld)-(%ld,%ld), EX setting=(0,0)-(%ld,%d)\n",
899 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
900 cbx_wrect.right-cbx_wrect.left, height);
901 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
902 cbx_wrect.right-cbx_wrect.left, height,
903 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
909 /* *** WM_xxx message support *** */
912 static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
914 static const WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
915 static const WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
916 static const WCHAR NIL[] = { 0 };
917 COMBOEX_INFO *infoPtr;
919 RECT wnrc1, clrc1, cmbwrc;
922 /* allocate memory for info structure */
923 infoPtr = (COMBOEX_INFO *)Alloc (sizeof(COMBOEX_INFO));
924 if (!infoPtr) return -1;
926 /* initialize info structure */
927 /* note that infoPtr is allocated zero-filled */
929 infoPtr->hwndSelf = hwnd;
930 infoPtr->selected = -1;
932 infoPtr->unicode = IsWindowUnicode (hwnd);
933 infoPtr->hwndNotify = cs->hwndParent;
935 i = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
936 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
937 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
940 infoPtr->NtfUnicode = (i == NFR_UNICODE);
942 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
944 /* create combo box */
945 GetWindowRect(hwnd, &wnrc1);
946 GetClientRect(hwnd, &clrc1);
947 TRACE("EX window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld)\n",
948 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
949 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
951 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
952 /* specified. It then creates it's own version of the EDIT control */
953 /* and makes the ComboBox the parent. This is because a normal */
954 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
955 /* We also need to place the edit control at the proper location */
956 /* (allow space for the icons). */
958 infoPtr->hwndCombo = CreateWindowW (COMBOBOX, NIL,
959 /* following line added to match native */
960 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
961 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
962 /* was base and is necessary */
963 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
964 GetWindowLongW (hwnd, GWL_STYLE),
965 cs->y, cs->x, cs->cx, cs->cy, hwnd,
966 (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
967 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
970 * native does the following at this point according to trace:
971 * GetWindowThreadProcessId(hwndCombo,0)
972 * GetCurrentThreadId()
973 * GetWindowThreadProcessId(hwndCombo, &???)
974 * GetCurrentProcessId()
978 * Setup a property to hold the pointer to the COMBOBOXEX
981 SetPropA(infoPtr->hwndCombo, COMBOEX_SUBCLASS_PROP, hwnd);
982 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hwndCombo,
983 GWLP_WNDPROC, (DWORD_PTR)COMBOEX_ComboWndProc);
984 infoPtr->font = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
988 * Now create our own EDIT control so we can position it.
989 * It is created only for CBS_DROPDOWN style
991 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
992 infoPtr->hwndEdit = CreateWindowExW (0, EDIT, NIL,
993 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
994 0, 0, 0, 0, /* will set later */
996 (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
997 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
999 /* native does the following at this point according to trace:
1000 * GetWindowThreadProcessId(hwndEdit,0)
1001 * GetCurrentThreadId()
1002 * GetWindowThreadProcessId(hwndEdit, &???)
1003 * GetCurrentProcessId()
1007 * Setup a property to hold the pointer to the COMBOBOXEX
1010 SetPropA(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
1011 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hwndEdit,
1012 GWLP_WNDPROC, (DWORD_PTR)COMBOEX_EditWndProc);
1013 infoPtr->font = (HFONT)SendMessageW(infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1017 * Locate the default font if necessary and then set it in
1018 * all associated controls
1020 if (!infoPtr->font) {
1021 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1023 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1025 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1026 if (infoPtr->hwndEdit) {
1027 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1028 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1031 COMBOEX_ReSize (infoPtr);
1033 /* Above is fairly certain, below is much less certain. */
1035 GetWindowRect(hwnd, &wnrc1);
1036 GetClientRect(hwnd, &clrc1);
1037 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1038 TRACE("EX window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld) CB wnd=(%ld,%ld)-(%ld,%ld)\n",
1039 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1040 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1041 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1042 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1043 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1044 SWP_NOACTIVATE | SWP_NOREDRAW);
1046 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1047 TRACE("CB window=(%ld,%ld)-(%ld,%ld)\n",
1048 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1049 SetWindowPos(hwnd, HWND_TOP,
1050 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1051 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1053 COMBOEX_AdjustEditPos (infoPtr);
1056 * Create an item structure to represent the data in the
1057 * EDIT control. It is allocated zero-filled.
1059 infoPtr->edit = (CBE_ITEMDATA *)Alloc (sizeof (CBE_ITEMDATA));
1060 if (!infoPtr->edit) {
1061 COMBOEX_Destroy(infoPtr);
1069 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1072 INT command = HIWORD(wParam);
1073 CBE_ITEMDATA *item = 0;
1075 INT cursel, n, oldItem;
1076 NMCBEENDEDITW cbeend;
1078 HWND parent = infoPtr->hwndNotify;
1080 TRACE("for command %d\n", command);
1085 SetFocus (infoPtr->hwndCombo);
1086 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1087 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1090 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1092 * from native trace of first dropdown after typing in URL in IE4
1093 * CB_GETCURSEL(Combo)
1094 * GetWindowText(Edit)
1095 * CB_GETCURSEL(Combo)
1096 * CB_GETCOUNT(Combo)
1097 * CB_GETITEMDATA(Combo, n)
1098 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1099 * CB_GETCURSEL(Combo)
1100 * CB_SETCURSEL(COMBOEX, n)
1102 * the rest is supposition
1104 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1105 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1106 InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1107 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1109 cmp_func_t cmptext = get_cmp_func(infoPtr);
1110 /* find match from edit against those in Combobox */
1111 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1112 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1113 for (cursel = 0; cursel < n; cursel++){
1114 item = get_item_data(infoPtr, cursel);
1115 if ((INT)item == CB_ERR) break;
1116 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1118 if ((cursel == n) || ((INT)item == CB_ERR)) {
1119 TRACE("failed to find match??? item=%p cursel=%d\n",
1121 if (infoPtr->hwndEdit)
1122 SetFocus(infoPtr->hwndEdit);
1127 item = get_item_data(infoPtr, cursel);
1128 if ((INT)item == CB_ERR) {
1129 TRACE("failed to find match??? item=%p cursel=%d\n",
1131 if (infoPtr->hwndEdit)
1132 SetFocus(infoPtr->hwndEdit);
1137 /* Save flags for testing and reset them */
1138 oldflags = infoPtr->flags;
1139 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1141 if (oldflags & WCBE_ACTEDIT) {
1142 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1143 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1144 CB_GETCURSEL, 0, 0);
1145 cbeend.iWhy = CBENF_DROPDOWN;
1147 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1150 /* if selection has changed the set the new current selection */
1151 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1152 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1153 infoPtr->selected = cursel;
1154 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1155 SetFocus(infoPtr->hwndCombo);
1161 * CB_GETCURSEL(Combo)
1162 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1165 * WM_GETTEXTLENGTH(Edit)
1167 * EM_SETSEL(Edit, 0,0)
1168 * WM_GETTEXTLENGTH(Edit)
1170 * EM_SETSEL(Edit, 0,len)
1171 * return WM_COMMAND to parent
1173 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1174 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1175 ERR("item %d not found. Problem!\n", oldItem);
1178 infoPtr->selected = oldItem;
1179 COMBOEX_SetEditText (infoPtr, item);
1180 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1184 * We have to change the handle since we are the control
1185 * issuing the message. IE4 depends on this.
1187 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1191 * from native trace:
1194 * WM_GETTEXT(Edit, 104)
1195 * CB_GETCURSEL(Combo) rets -1
1196 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1197 * CB_GETCURSEL(Combo)
1198 * InvalidateRect(Combo, 0, 0)
1201 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1202 if (infoPtr->flags & WCBE_ACTEDIT) {
1203 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1204 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1205 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1206 CB_GETCURSEL, 0, 0);
1207 cbeend.iWhy = CBENF_KILLFOCUS;
1209 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1210 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1212 /* possible CB_GETCURSEL */
1213 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1218 * We have to change the handle since we are the control
1219 * issuing the message. IE4 depends on this.
1220 * We also need to set the focus back to the Edit control
1221 * after passing the command to the parent of the ComboEx.
1223 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1224 if (infoPtr->hwndEdit)
1225 SetFocus(infoPtr->hwndEdit);
1232 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
1234 CBE_ITEMDATA *item, *olditem;
1235 NMCOMBOBOXEXW nmcit;
1238 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1239 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1241 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1243 olditem = infoPtr->items;
1244 i = infoPtr->nb_items - 1;
1246 if (i == dis->itemID) {
1247 infoPtr->items = infoPtr->items->next;
1253 /* find the prior item in the list */
1254 while (item->next && (i > dis->itemID)) {
1255 item = (CBE_ITEMDATA *)item->next;
1258 if (!item->next || (i != dis->itemID)) {
1259 ERR("COMBOBOXEX item structures broken. Please report!\n");
1262 olditem = item->next;
1263 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1265 infoPtr->nb_items--;
1267 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1268 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1269 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1271 COMBOEX_FreeText(olditem);
1278 static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
1280 static const WCHAR nil[] = { 0 };
1281 CBE_ITEMDATA *item = 0;
1287 COLORREF nbkc, ntxc, bkc, txc;
1288 int drawimage, drawstate, xioff;
1290 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1292 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1293 dis->CtlType, dis->CtlID);
1294 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1295 dis->itemID, dis->itemAction, dis->itemState);
1296 TRACE("hWnd=%p hDC=%p (%ld,%ld)-(%ld,%ld) itemData=0x%08lx\n",
1297 dis->hwndItem, dis->hDC, dis->rcItem.left,
1298 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1302 /* "itemID - Specifies the menu item identifier for a menu */
1303 /* item or the index of the item in a list box or combo box. */
1304 /* For an empty list box or combo box, this member can be -1. */
1305 /* This allows the application to draw only the focus */
1306 /* rectangle at the coordinates specified by the rcItem */
1307 /* member even though there are no items in the control. */
1308 /* This indicates to the user whether the list box or combo */
1309 /* box has the focus. How the bits are set in the itemAction */
1310 /* member determines whether the rectangle is to be drawn as */
1311 /* though the list box or combo box has the focus. */
1312 if (dis->itemID == 0xffffffff) {
1313 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1314 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1316 TRACE("drawing item -1 special focus, rect=(%ld,%ld)-(%ld,%ld)\n",
1317 dis->rcItem.left, dis->rcItem.top,
1318 dis->rcItem.right, dis->rcItem.bottom);
1320 else if ((dis->CtlType == ODT_COMBOBOX) &&
1321 (dis->itemAction == ODA_DRAWENTIRE)) {
1322 /* draw of edit control data */
1326 RECT exrc, cbrc, edrc;
1327 GetWindowRect (infoPtr->hwndSelf, &exrc);
1328 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1329 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1330 if (infoPtr->hwndEdit)
1331 GetWindowRect (infoPtr->hwndEdit, &edrc);
1332 TRACE("window rects ex=(%ld,%ld)-(%ld,%ld), cb=(%ld,%ld)-(%ld,%ld), ed=(%ld,%ld)-(%ld,%ld)\n",
1333 exrc.left, exrc.top, exrc.right, exrc.bottom,
1334 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1335 edrc.left, edrc.top, edrc.right, edrc.bottom);
1339 ERR("NOT drawing item -1 special focus, rect=(%ld,%ld)-(%ld,%ld), action=%08x, state=%08x\n",
1340 dis->rcItem.left, dis->rcItem.top,
1341 dis->rcItem.right, dis->rcItem.bottom,
1342 dis->itemAction, dis->itemState);
1347 /* If draw item is -1 (edit control) setup the item pointer */
1348 if (dis->itemID == 0xffffffff) {
1349 item = infoPtr->edit;
1351 if (infoPtr->hwndEdit) {
1354 /* free previous text of edit item */
1355 COMBOEX_FreeText(item);
1356 item->mask &= ~CBEIF_TEXT;
1357 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1358 item->mask |= CBEIF_TEXT;
1359 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
1361 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1363 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1364 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1370 /* if the item pointer is not set, then get the data and locate it */
1372 item = get_item_data(infoPtr, dis->itemID);
1373 if (item == (CBE_ITEMDATA *)CB_ERR) {
1374 ERR("invalid item for id %d \n", dis->itemID);
1379 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1381 xbase = CBE_STARTOFFSET;
1382 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1383 INT indent = item->iIndent;
1384 if (indent == I_INDENTCALLBACK) {
1386 ZeroMemory(&nmce, sizeof(nmce));
1387 nmce.ceItem.mask = CBEIF_INDENT;
1388 nmce.ceItem.lParam = item->lParam;
1389 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1390 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1391 item->iIndent = nmce.ceItem.iIndent;
1392 indent = nmce.ceItem.iIndent;
1394 xbase += (indent * CBE_INDENT);
1398 drawstate = ILD_NORMAL;
1399 if (item->mask & CBEIF_IMAGE)
1400 drawimage = item->iImage;
1401 if (dis->itemState & ODS_COMBOEXLBOX) {
1402 /* drawing listbox entry */
1403 if (dis->itemState & ODS_SELECTED) {
1404 if (item->mask & CBEIF_SELECTEDIMAGE)
1405 drawimage = item->iSelectedImage;
1406 drawstate = ILD_SELECTED;
1409 /* drawing combo/edit entry */
1410 if (IsWindowVisible(infoPtr->hwndEdit)) {
1411 /* if we have an edit control, the slave the
1412 * selection state to the Edit focus state
1414 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1415 if (item->mask & CBEIF_SELECTEDIMAGE)
1416 drawimage = item->iSelectedImage;
1417 drawstate = ILD_SELECTED;
1420 /* if we don't have an edit control, use
1421 * the requested state.
1423 if (dis->itemState & ODS_SELECTED) {
1424 if (item->mask & CBEIF_SELECTEDIMAGE)
1425 drawimage = item->iSelectedImage;
1426 drawstate = ILD_SELECTED;
1431 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1433 iinfo.rcImage.left = iinfo.rcImage.right = 0;
1434 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1435 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1438 /* setup pointer to text to be drawn */
1439 str = COMBOEX_GetText(infoPtr, item);
1440 if (!str) str = nil;
1442 len = strlenW (str);
1443 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1445 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1446 int overlay = item->iOverlay;
1448 if (drawimage == I_IMAGECALLBACK) {
1450 ZeroMemory(&nmce, sizeof(nmce));
1451 nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
1452 nmce.ceItem.lParam = item->lParam;
1453 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1454 if (drawstate == ILD_NORMAL) {
1455 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1456 drawimage = nmce.ceItem.iImage;
1457 } else if (drawstate == ILD_SELECTED) {
1458 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1459 drawimage = nmce.ceItem.iSelectedImage;
1460 } else ERR("Bad draw state = %d\n", drawstate);
1463 if (overlay == I_IMAGECALLBACK) {
1465 ZeroMemory(&nmce, sizeof(nmce));
1466 nmce.ceItem.mask = CBEIF_OVERLAY;
1467 nmce.ceItem.lParam = item->lParam;
1468 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1469 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1470 item->iOverlay = nmce.ceItem.iOverlay;
1471 overlay = nmce.ceItem.iOverlay;
1474 if (drawimage >= 0 &&
1475 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1476 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1477 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1478 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1481 /* now draw the text */
1482 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1483 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1484 COLOR_HIGHLIGHT : COLOR_WINDOW);
1485 bkc = SetBkColor (dis->hDC, nbkc);
1486 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1487 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1488 txc = SetTextColor (dis->hDC, ntxc);
1490 y = dis->rcItem.top +
1491 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1493 rect.right = x + txtsize.cx;
1494 rect.top = dis->rcItem.top + 1;
1495 rect.bottom = dis->rcItem.bottom - 1;
1496 TRACE("drawing item %d text, rect=(%ld,%ld)-(%ld,%ld)\n",
1497 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1498 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1499 &rect, str, len, 0);
1500 SetBkColor (dis->hDC, bkc);
1501 SetTextColor (dis->hDC, txc);
1505 if (dis->itemAction & ODA_FOCUS) {
1506 rect.left = xbase + xioff - 1;
1507 rect.right = rect.left + txtsize.cx + 2;
1508 rect.top = dis->rcItem.top;
1509 rect.bottom = dis->rcItem.bottom;
1510 DrawFocusRect(dis->hDC, &rect);
1517 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1519 if (infoPtr->hwndCombo)
1520 DestroyWindow (infoPtr->hwndCombo);
1522 if (infoPtr->edit) {
1523 Free (infoPtr->edit);
1527 if (infoPtr->items) {
1528 CBE_ITEMDATA *item, *next;
1530 item = infoPtr->items;
1532 next = (CBE_ITEMDATA *)item->next;
1533 COMBOEX_FreeText (item);
1540 if (infoPtr->defaultFont)
1541 DeleteObject (infoPtr->defaultFont);
1543 /* free comboex info data */
1545 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1550 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
1556 GetTextExtentPointA (hdc, "W", 1, &mysize);
1558 mis->itemHeight = mysize.cy + CBE_EXTRA;
1560 TRACE("adjusted height hwnd=%p, height=%d\n",
1561 infoPtr->hwndSelf, mis->itemHeight);
1567 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1569 /* WARNING: The COMBOEX_INFO structure is not yet created */
1570 DWORD oldstyle, newstyle;
1572 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1573 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL | WS_BORDER);
1574 if (newstyle != oldstyle) {
1575 TRACE("req style %08lx, reseting style %08lx\n",
1576 oldstyle, newstyle);
1577 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1583 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1585 if (lParam == NF_REQUERY) {
1586 INT i = SendMessageW(infoPtr->hwndNotify,
1587 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1588 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1590 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1594 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1596 TRACE("(width=%d, height=%d)\n", width, height);
1598 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1600 COMBOEX_AdjustEditPos (infoPtr);
1606 static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1608 RECT cbx_wrect, cbx_crect, cb_wrect;
1611 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1612 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1613 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1615 /* width is winpos value + border width of comboex */
1617 + (cbx_wrect.right-cbx_wrect.left)
1618 - (cbx_crect.right-cbx_crect.left);
1620 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1621 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1622 TRACE("EX window=(%ld,%ld)-(%ld,%ld), client=(%ld,%ld)-(%ld,%ld)\n",
1623 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1624 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1625 TRACE("CB window=(%ld,%ld)-(%ld,%ld), EX setting=(0,0)-(%d,%ld)\n",
1626 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1627 width, cb_wrect.bottom-cb_wrect.top);
1629 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1631 cb_wrect.bottom-cb_wrect.top,
1634 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1636 /* height is combo window height plus border width of comboex */
1637 height = (cb_wrect.bottom-cb_wrect.top)
1638 + (cbx_wrect.bottom-cbx_wrect.top)
1639 - (cbx_crect.bottom-cbx_crect.top);
1640 if (wp->cy < height) wp->cy = height;
1641 if (infoPtr->hwndEdit) {
1642 COMBOEX_AdjustEditPos (infoPtr);
1643 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1649 static LRESULT WINAPI
1650 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1652 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1653 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1654 NMCBEENDEDITW cbeend;
1655 WCHAR edit_text[260];
1661 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1662 hwnd, uMsg, wParam, lParam, infoPtr);
1664 if (!infoPtr) return 0;
1670 /* handle (ignore) the return character */
1671 if (wParam == VK_RETURN) return 0;
1672 /* all other characters pass into the real Edit */
1673 return CallWindowProcW (infoPtr->prevEditWndProc,
1674 hwnd, uMsg, wParam, lParam);
1678 * The following was determined by traces of the native
1681 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1682 GetClientRect (hwnd, &rect);
1683 TRACE("erasing (%ld,%ld)-(%ld,%ld)\n",
1684 rect.left, rect.top, rect.right, rect.bottom);
1685 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1686 SetBkColor (hDC, obkc);
1687 return CallWindowProcW (infoPtr->prevEditWndProc,
1688 hwnd, uMsg, wParam, lParam);
1691 INT oldItem, selected, step = 1;
1694 switch ((INT)wParam)
1697 /* native version seems to do following for COMBOEX */
1699 * GetWindowTextA(Edit,&?, 0x104) x
1700 * CB_GETCURSEL to Combo rets -1 x
1701 * WM_NOTIFY to COMBOEX parent (rebar) x
1702 * (CBEN_ENDEDIT{A|W}
1703 * fChanged = FALSE x
1704 * inewSelection = -1 x
1707 * CB_GETCURSEL to Combo rets -1 x
1708 * InvalidateRect(Combo, 0) x
1709 * WM_SETTEXT to Edit x
1710 * EM_SETSEL to Edit (0,0) x
1711 * EM_SETSEL to Edit (0,-1) x
1712 * RedrawWindow(Combo, 0, 0, 5) x
1714 TRACE("special code for VK_ESCAPE\n");
1716 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1718 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1719 cbeend.fChanged = FALSE;
1720 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1721 CB_GETCURSEL, 0, 0);
1722 cbeend.iWhy = CBENF_ESCAPE;
1724 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1725 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1726 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1727 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1728 ERR("item %d not found. Problem!\n", oldItem);
1731 infoPtr->selected = oldItem;
1732 COMBOEX_SetEditText (infoPtr, item);
1733 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1738 /* native version seems to do following for COMBOEX */
1740 * GetWindowTextA(Edit,&?, 0x104) x
1741 * CB_GETCURSEL to Combo rets -1 x
1742 * CB_GETCOUNT to Combo rets 0
1744 * CB_GETITEMDATA to match
1745 * *** above 3 lines simulated by FindItem x
1746 * WM_NOTIFY to COMBOEX parent (rebar) x
1747 * (CBEN_ENDEDIT{A|W} x
1748 * fChanged = TRUE (-1) x
1749 * iNewSelection = -1 or selected x
1751 * iWhy = 2 (CBENF_RETURN) x
1752 * CB_GETCURSEL to Combo rets -1 x
1753 * if -1 send CB_SETCURSEL to Combo -1 x
1754 * InvalidateRect(Combo, 0, 0) x
1756 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1759 TRACE("special code for VK_RETURN\n");
1761 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1763 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1764 selected = SendMessageW (infoPtr->hwndCombo,
1765 CB_GETCURSEL, 0, 0);
1767 if (selected != -1) {
1768 cmp_func_t cmptext = get_cmp_func(infoPtr);
1769 item = COMBOEX_FindItem (infoPtr, selected);
1770 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1771 selected, debugstr_txt(item->pszText));
1772 TRACE("handling VK_RETURN, edittext=%s\n",
1773 debugstr_w(edit_text));
1774 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1775 /* strings not equal -- indicate edit has changed */
1780 cbeend.iNewSelection = selected;
1781 cbeend.fChanged = TRUE;
1782 cbeend.iWhy = CBENF_RETURN;
1783 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1784 /* abort the change, restore previous */
1785 TRACE("Notify requested abort of change\n");
1786 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1787 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1791 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1792 if (oldItem != -1) {
1793 /* if something is selected, then deselect it */
1794 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1797 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1798 SetFocus(infoPtr->hwndEdit);
1804 /* by default, step is 1 */
1805 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1806 if (oldItem >= 0 && oldItem + step >= 0)
1807 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1810 return CallWindowProcW (infoPtr->prevEditWndProc,
1811 hwnd, uMsg, wParam, lParam);
1817 /* remember the focus to set state of icon */
1818 lret = CallWindowProcW (infoPtr->prevEditWndProc,
1819 hwnd, uMsg, wParam, lParam);
1820 infoPtr->flags |= WCBE_EDITFOCUSED;
1825 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1827 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1828 if (infoPtr->flags & WCBE_ACTEDIT) {
1829 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1831 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1832 cbeend.fChanged = FALSE;
1833 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1834 CB_GETCURSEL, 0, 0);
1835 cbeend.iWhy = CBENF_KILLFOCUS;
1837 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1842 return CallWindowProcW (infoPtr->prevEditWndProc,
1843 hwnd, uMsg, wParam, lParam);
1849 static LRESULT WINAPI
1850 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1852 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1853 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1854 NMCBEENDEDITW cbeend;
1861 WCHAR edit_text[260];
1863 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1864 hwnd, uMsg, wParam, lParam, infoPtr);
1866 if (!infoPtr) return 0;
1873 * The only way this message should come is from the
1874 * child Listbox issuing the message. Flag this so
1875 * that ComboEx knows this is listbox.
1877 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1878 return CallWindowProcW (infoPtr->prevComboWndProc,
1879 hwnd, uMsg, wParam, lParam);
1883 * The following was determined by traces of the native
1886 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1887 GetClientRect (hwnd, &rect);
1888 TRACE("erasing (%ld,%ld)-(%ld,%ld)\n",
1889 rect.left, rect.top, rect.right, rect.bottom);
1890 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1891 SetBkColor (hDC, obkc);
1892 return CallWindowProcW (infoPtr->prevComboWndProc,
1893 hwnd, uMsg, wParam, lParam);
1897 * WM_NOTIFY to comboex parent (rebar)
1898 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1899 * CallWindowProc (previous)
1901 nmmse.dwItemSpec = 0;
1902 nmmse.dwItemData = 0;
1905 nmmse.dwHitInfo = lParam;
1906 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1907 return CallWindowProcW (infoPtr->prevComboWndProc,
1908 hwnd, uMsg, wParam, lParam);
1910 case WM_LBUTTONDOWN:
1911 GetClientRect (hwnd, &rect);
1912 rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1913 CB_GETITEMHEIGHT, -1, 0);
1914 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
1915 POINTSTOPOINT(pt, MAKEPOINTS(lParam));
1916 if (PtInRect(&rect, pt))
1917 return CallWindowProcW (infoPtr->prevComboWndProc,
1918 hwnd, uMsg, wParam, lParam);
1919 infoPtr->flags |= WCBE_MOUSECAPTURED;
1924 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1925 return CallWindowProcW (infoPtr->prevComboWndProc,
1926 hwnd, uMsg, wParam, lParam);
1928 infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1929 if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1930 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1932 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1937 if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1938 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
1939 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1940 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
1941 infoPtr->flags |= WCBE_MOUSEDRAGGED;
1943 return CallWindowProcW (infoPtr->prevComboWndProc,
1944 hwnd, uMsg, wParam, lParam);
1947 switch (HIWORD(wParam)) {
1950 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1959 * GetFocus() retns AA
1960 * GetWindowTextA(Edit)
1961 * CB_GETCURSEL(Combo) (got -1)
1962 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1963 * CB_GETCURSEL(Combo) (got -1)
1964 * InvalidateRect(Combo, 0, 0)
1965 * WM_KILLFOCUS(Combo, AA)
1968 focusedhwnd = GetFocus();
1969 if (infoPtr->flags & WCBE_ACTEDIT) {
1970 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1971 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1972 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1973 CB_GETCURSEL, 0, 0);
1974 cbeend.iWhy = CBENF_KILLFOCUS;
1976 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1977 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1979 /* possible CB_GETCURSEL */
1980 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1982 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
1983 (WPARAM)focusedhwnd, 0);
1988 * For EN_SETFOCUS this issues the same calls and messages
1989 * as the native seems to do.
1991 * for some cases however native does the following:
1992 * (noticed after SetFocus during LBUTTONDOWN on
1993 * on dropdown arrow)
1994 * WM_GETTEXTLENGTH (Edit);
1995 * WM_GETTEXT (Edit, len+1, str);
1996 * EM_SETSEL (Edit, 0, 0);
1997 * WM_GETTEXTLENGTH (Edit);
1998 * WM_GETTEXT (Edit, len+1, str);
1999 * EM_SETSEL (Edit, 0, len);
2000 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2004 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2005 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2006 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2007 infoPtr->flags |= WCBE_ACTEDIT;
2008 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2014 * For EN_CHANGE this issues the same calls and messages
2015 * as the native seems to do.
2017 WCHAR edit_text[260];
2019 cmp_func_t cmptext = get_cmp_func(infoPtr);
2021 INT selected = SendMessageW (infoPtr->hwndCombo,
2022 CB_GETCURSEL, 0, 0);
2024 /* lstrlenA( lastworkingURL ) */
2026 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2027 if (selected == -1) {
2028 lastwrk = infoPtr->edit->pszText;
2031 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2032 lastwrk = COMBOEX_GetText(infoPtr, item);
2035 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2036 selected, debugstr_w(lastwrk));
2037 TRACE("handling EN_CHANGE, edittext=%s\n",
2038 debugstr_w(edit_text));
2040 /* cmptext is between lastworkingURL and GetWindowText */
2041 if (cmptext (lastwrk, edit_text)) {
2042 /* strings not equal -- indicate edit has changed */
2043 infoPtr->flags |= WCBE_EDITCHG;
2045 SendMessageW ( infoPtr->hwndNotify, WM_COMMAND,
2046 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2048 (LPARAM)infoPtr->hwndSelf);
2054 * Therefore from traces there is no additional code here
2058 * Using native COMCTL32 gets the following:
2059 * 1 == SHDOCVW.DLL issues call/message
2060 * 2 == COMCTL32.DLL issues call/message
2061 * 3 == WINE issues call/message
2064 * for LBN_SELCHANGE:
2065 * 1 CB_GETCURSEL(ComboEx)
2066 * 1 CB_GETDROPPEDSTATE(ComboEx)
2067 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2068 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2069 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2070 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2071 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2072 * 3 ShowWindow(ComboLB, SW_HIDE)
2073 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2074 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2076 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2077 * ? LB_GETCURSEL <==|
2079 * ? LB_GETTEXT | Needs to be added to
2080 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2081 * ? LB_GETITEMDATA |
2082 * ? WM_DRAWITEM(ComboEx) <==|
2088 return CallWindowProcW (infoPtr->prevComboWndProc,
2089 hwnd, uMsg, wParam, lParam);
2095 static LRESULT WINAPI
2096 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2098 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2100 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2103 if (uMsg == WM_CREATE)
2104 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2105 if (uMsg == WM_NCCREATE)
2106 COMBOEX_NCCreate (hwnd);
2107 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2112 case CBEM_DELETEITEM:
2113 return COMBOEX_DeleteItem (infoPtr, wParam);
2115 case CBEM_GETCOMBOCONTROL:
2116 return (LRESULT)infoPtr->hwndCombo;
2118 case CBEM_GETEDITCONTROL:
2119 return (LRESULT)infoPtr->hwndEdit;
2121 case CBEM_GETEXTENDEDSTYLE:
2122 return infoPtr->dwExtStyle;
2124 case CBEM_GETIMAGELIST:
2125 return (LRESULT)infoPtr->himl;
2128 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2131 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2133 case CBEM_GETUNICODEFORMAT:
2134 return infoPtr->unicode;
2136 case CBEM_HASEDITCHANGED:
2137 return COMBOEX_HasEditChanged (infoPtr);
2139 case CBEM_INSERTITEMA:
2140 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2142 case CBEM_INSERTITEMW:
2143 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2145 case CBEM_SETEXSTYLE:
2146 case CBEM_SETEXTENDEDSTYLE:
2147 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2149 case CBEM_SETIMAGELIST:
2150 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2153 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2156 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2158 case CBEM_SETUNICODEFORMAT:
2159 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2161 /*case CBEM_SETWINDOWTHEME:
2162 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2166 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2168 /* Combo messages we are not sure if we need to process or just forward */
2169 case CB_GETDROPPEDCONTROLRECT:
2170 case CB_GETITEMHEIGHT:
2172 case CB_GETLBTEXTLEN:
2173 case CB_GETEXTENDEDUI:
2175 case CB_RESETCONTENT:
2176 case CB_SELECTSTRING:
2178 /* Combo messages OK to just forward to the regular COMBO */
2181 case CB_GETDROPPEDSTATE:
2182 case CB_SETDROPPEDWIDTH:
2183 case CB_SETEXTENDEDUI:
2184 case CB_SHOWDROPDOWN:
2185 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2187 /* Combo messages we need to process specially */
2188 case CB_FINDSTRINGEXACT:
2189 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2191 case CB_GETITEMDATA:
2192 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2195 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2197 case CB_SETITEMDATA:
2198 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD)lParam);
2200 case CB_SETITEMHEIGHT:
2201 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2205 /* Window messages passed to parent */
2207 return COMBOEX_Command (infoPtr, wParam, lParam);
2210 if (infoPtr->NtfUnicode)
2211 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
2213 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
2216 /* Window messages we need to process */
2218 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2221 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2224 return COMBOEX_Destroy (infoPtr);
2226 case WM_MEASUREITEM:
2227 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2229 case WM_NOTIFYFORMAT:
2230 return COMBOEX_NotifyFormat (infoPtr, lParam);
2233 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2235 case WM_WINDOWPOSCHANGING:
2236 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2239 SetFocus(infoPtr->hwndCombo);
2243 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2244 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
2245 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2251 void COMBOEX_Register (void)
2255 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2256 wndClass.style = CS_GLOBALCLASS;
2257 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2258 wndClass.cbClsExtra = 0;
2259 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2260 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2261 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2262 wndClass.lpszClassName = WC_COMBOBOXEXW;
2264 RegisterClassW (&wndClass);
2268 void COMBOEX_Unregister (void)
2270 UnregisterClassW (WC_COMBOBOXEXW, NULL);