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 belive this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
56 /* ComboBoxEx structure */
60 HWND hwndSelf; /* my own hwnd */
63 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
64 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
66 INT selected; /* index of selected item */
67 DWORD flags; /* WINE internal flags */
70 INT nb_items; /* Number of items */
71 BOOL unicode; /* TRUE if this window is Unicode */
72 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
73 CBE_ITEMDATA *edit; /* item data for edit item */
74 CBE_ITEMDATA *items; /* Array of items */
77 /* internal flags in the COMBOEX_INFO structure */
78 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
79 * CBEN_BEGINEDIT issued
80 * but CBEN_ENDEDIT{A|W}
82 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
83 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
84 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
85 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
86 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
88 #define ID_CB_EDIT 1001
92 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
93 * the ComboEx version of the Combo Window Proc so that when the
94 * WM_DRAWITEM message is then passed to ComboEx, we know that this
95 * particular WM_DRAWITEM message is for listbox only items. Any messasges
96 * without this flag is then for the Edit control field.
98 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
99 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
101 #define ODS_COMBOEXLBOX 0x4000
105 /* Height in pixels of control over the amount of the selected font */
108 /* Indent amount per MS documentation */
109 #define CBE_INDENT 10
111 /* Offset in pixels from left side for start of image or text */
112 #define CBE_STARTOFFSET 6
114 /* Offset between image and text */
117 #define COMBOEX_SUBCLASS_PROP "CCComboEx32SubclassInfo"
118 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongW (hwnd, 0))
121 /* Things common to the entire DLL */
122 static LRESULT WINAPI
123 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
124 static LRESULT WINAPI
125 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
127 COMBOEX_PathWordBreakProc(LPWSTR lpch, int ichCurrent, int cch, int code);
128 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
129 typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
131 inline static BOOL is_textW(LPCWSTR str)
133 return str && str != LPSTR_TEXTCALLBACKW;
136 inline static BOOL is_textA(LPCSTR str)
138 return str && str != LPSTR_TEXTCALLBACKA;
141 inline static LPCSTR debugstr_txt(LPCWSTR str)
143 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
144 return debugstr_w(str);
147 static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
149 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
150 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
151 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
152 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
153 if (item->mask & CBEIF_TEXT)
154 TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
158 static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
160 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
161 input->mask, input->iItem, input->pszText, input->cchTextMax,
163 if (input->mask & CBEIF_TEXT)
164 TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
165 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
166 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
170 inline static CBE_ITEMDATA *get_item_data(COMBOEX_INFO *infoPtr, INT index)
172 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
176 inline static cmp_func_t get_cmp_func(COMBOEX_INFO *infoPtr)
178 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
181 static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
183 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
184 hdr->hwndFrom = infoPtr->hwndSelf;
186 if (infoPtr->NtfUnicode)
187 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
190 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
196 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
198 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
199 if (infoPtr->NtfUnicode)
200 return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
202 LPWSTR wstr = hdr->ceItem.pszText;
206 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
207 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
209 astr = (LPSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
211 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
212 hdr->ceItem.pszText = (LPWSTR)astr;
216 if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
217 else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
218 else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
220 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
222 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
223 hdr->ceItem.pszText = wstr;
225 if (astr) COMCTL32_Free(astr);
232 static INT COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
234 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
235 if (infoPtr->NtfUnicode) {
236 lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
237 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
241 memcpy (&neea.hdr, &neew->hdr, sizeof(NMHDR));
242 neea.fChanged = neew->fChanged;
243 neea.iNewSelection = neew->iNewSelection;
244 WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
245 neea.iWhy = neew->iWhy;
247 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
252 static void COMBOEX_NotifyDragBegin(COMBOEX_INFO *infoPtr, LPCWSTR wstr)
254 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
255 if (infoPtr->NtfUnicode) {
256 NMCBEDRAGBEGINW ndbw;
259 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
260 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
262 NMCBEDRAGBEGINA ndba;
265 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
267 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
272 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
274 if (is_textW(item->pszText)) COMCTL32_Free(item->pszText);
276 if (item->pszTemp) COMCTL32_Free(item->pszTemp);
281 static LPCWSTR COMBOEX_GetText(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
287 if (item->pszText != LPSTR_TEXTCALLBACKW)
288 return item->pszText;
290 ZeroMemory(&nmce, sizeof(nmce));
291 nmce.ceItem.mask = CBEIF_TEXT;
292 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
294 if (is_textW(nmce.ceItem.pszText)) {
295 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
296 buf = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
298 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
299 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
300 COMBOEX_FreeText(item);
303 if (item->pszTemp) COMCTL32_Free(item->pszTemp);
308 text = nmce.ceItem.pszText;
310 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
311 item->pszText = text;
316 static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
321 mydc = GetDC (0); /* why the entire screen???? */
322 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
323 ofont = (HFONT) SelectObject (mydc, nfont);
324 GetTextExtentPointA (mydc, "A", 1, size);
325 SelectObject (mydc, ofont);
327 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
331 static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
333 if (cit->mask & CBEIF_TEXT) {
335 * when given a text buffer actually use that buffer
338 if (is_textW(item->pszText))
339 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
343 cit->pszText = item->pszText;
344 cit->cchTextMax = item->cchTextMax;
347 if (cit->mask & CBEIF_IMAGE)
348 cit->iImage = item->iImage;
349 if (cit->mask & CBEIF_SELECTEDIMAGE)
350 cit->iSelectedImage = item->iSelectedImage;
351 if (cit->mask & CBEIF_OVERLAY)
352 cit->iOverlay = item->iOverlay;
353 if (cit->mask & CBEIF_INDENT)
354 cit->iIndent = item->iIndent;
355 if (cit->mask & CBEIF_LPARAM)
356 cit->lParam = item->lParam;
360 static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
363 INT x, y, w, h, xioff;
366 if (!infoPtr->hwndEdit) return;
368 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
370 iinfo.rcImage.left = iinfo.rcImage.right = 0;
371 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
372 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
375 GetClientRect (infoPtr->hwndCombo, &rect);
376 InflateRect (&rect, -2, -2);
377 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
379 /* reposition the Edit control based on whether icon exists */
380 COMBOEX_GetComboFontSize (infoPtr, &mysize);
381 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
382 x = xioff + CBE_STARTOFFSET + 1;
383 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
385 y = rect.bottom - h - 1;
387 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
388 rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
389 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
390 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
394 static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
400 COMBOEX_GetComboFontSize (infoPtr, &mysize);
401 cy = mysize.cy + CBE_EXTRA;
403 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
404 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
405 TRACE("upgraded height due to image: height=%d\n", cy);
407 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)cy);
408 if (infoPtr->hwndCombo) {
409 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
410 (WPARAM) 0, (LPARAM) cy);
411 if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
413 if (GetWindowRect(infoPtr->hwndCombo, &comboRect)) {
415 if (GetWindowRect(infoPtr->hwndSelf, &ourRect)) {
416 if (comboRect.bottom > ourRect.bottom) {
417 POINT pt = { ourRect.left, ourRect.top };
418 if (ScreenToClient(infoPtr->hwndSelf, &pt))
419 MoveWindow( infoPtr->hwndSelf, pt.x, pt.y, ourRect.right - ourRect.left,
420 comboRect.bottom - comboRect.top, FALSE);
429 static void 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)COMBOEX_GetText(infoPtr, item));
438 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
439 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
444 static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
449 if ((index > infoPtr->nb_items) || (index < -1))
452 return infoPtr->edit;
453 item = infoPtr->items;
454 i = infoPtr->nb_items - 1;
456 /* find the item in the list */
457 while (item && (i > index)) {
458 item = (CBE_ITEMDATA *)item->next;
461 if (!item || (i != index)) {
462 ERR("COMBOBOXEX item structures broken. Please report!\n");
469 static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO *infoPtr)
471 return infoPtr->hwndEdit ? TRUE : FALSE;
475 /* *** CBEM_xxx message support *** */
478 static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
482 TRACE("(index=%d)\n", index);
484 /* if item number requested does not exist then return failure */
485 if ((index > infoPtr->nb_items) || (index < 0)) return CB_ERR;
486 if (!(item = COMBOEX_FindItem(infoPtr, index))) return CB_ERR;
488 /* doing this will result in WM_DELETEITEM being issued */
489 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
491 return infoPtr->nb_items;
495 static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
497 INT index = cit->iItem;
502 /* if item number requested does not exist then return failure */
503 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
505 /* if the item is the edit control and there is no edit control, skip */
506 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
508 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
510 COMBOEX_CopyItem (item, cit);
516 static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
518 COMBOBOXEXITEMW tmpcit;
522 tmpcit.mask = cit->mask;
523 tmpcit.iItem = cit->iItem;
525 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
527 if (is_textW(tmpcit.pszText) && cit->pszText)
528 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
529 cit->pszText, cit->cchTextMax, NULL, NULL);
530 else if (cit->pszText) cit->pszText[0] = 0;
531 else cit->pszText = (LPSTR)tmpcit.pszText;
533 cit->iImage = tmpcit.iImage;
534 cit->iSelectedImage = tmpcit.iSelectedImage;
535 cit->iOverlay = tmpcit.iOverlay;
536 cit->iIndent = tmpcit.iIndent;
537 cit->lParam = tmpcit.lParam;
543 inline static BOOL COMBOEX_HasEditChanged (COMBOEX_INFO *infoPtr)
545 return COMBOEX_HasEdit(infoPtr) &&
546 (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
550 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
558 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
560 /* get real index of item to insert */
562 if (index == -1) index = infoPtr->nb_items;
563 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
565 /* get zero-filled space and chain it in */
566 if(!(item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof(*item)))) return -1;
568 /* locate position to insert new item in */
569 if (index == infoPtr->nb_items) {
570 /* fast path for iItem = -1 */
571 item->next = infoPtr->items;
572 infoPtr->items = item;
575 INT i = infoPtr->nb_items-1;
576 CBE_ITEMDATA *moving = infoPtr->items;
578 while ((i > index) && moving) {
579 moving = (CBE_ITEMDATA *)moving->next;
583 ERR("COMBOBOXEX item structures broken. Please report!\n");
587 item->next = moving->next;
591 /* fill in our hidden item structure */
592 item->mask = cit->mask;
593 if (item->mask & CBEIF_TEXT) {
596 if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
598 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
599 if (!item->pszText) {
603 strcpyW (item->pszText, cit->pszText);
605 else if (cit->pszText == LPSTR_TEXTCALLBACKW)
606 item->pszText = LPSTR_TEXTCALLBACKW;
607 item->cchTextMax = cit->cchTextMax;
609 if (item->mask & CBEIF_IMAGE)
610 item->iImage = cit->iImage;
611 if (item->mask & CBEIF_SELECTEDIMAGE)
612 item->iSelectedImage = cit->iSelectedImage;
613 if (item->mask & CBEIF_OVERLAY)
614 item->iOverlay = cit->iOverlay;
615 if (item->mask & CBEIF_INDENT)
616 item->iIndent = cit->iIndent;
617 if (item->mask & CBEIF_LPARAM)
618 item->lParam = cit->lParam;
621 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
623 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
624 (WPARAM)cit->iItem, (LPARAM)item);
626 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
627 COMBOEX_CopyItem (item, &nmcit.ceItem);
628 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
635 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
637 COMBOBOXEXITEMW citW;
641 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
642 if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
643 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
644 wstr = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
645 if (!wstr) return -1;
646 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
649 ret = COMBOEX_InsertItemW(infoPtr, &citW);
651 if (wstr) COMCTL32_Free(wstr);
658 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
662 TRACE("(mask=x%08lx, style=0x%08lx)\n", mask, style);
664 dwTemp = infoPtr->dwExtStyle;
667 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
669 infoPtr->dwExtStyle = style;
671 /* see if we need to change the word break proc on the edit */
672 if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC) {
673 SendMessageW(infoPtr->hwndEdit, EM_SETWORDBREAKPROC, 0,
674 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ?
675 (LPARAM)COMBOEX_PathWordBreakProc : 0);
678 /* test if the control's appearance has changed */
679 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
680 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
681 /* if state of EX_NOEDITIMAGE changes, invalidate all */
682 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
683 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
684 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
685 COMBOEX_AdjustEditPos (infoPtr);
686 if (infoPtr->hwndEdit)
687 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
694 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
696 HIMAGELIST himlTemp = infoPtr->himl;
700 infoPtr->himl = himl;
702 COMBOEX_ReSize (infoPtr);
703 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
705 /* reposition the Edit control based on whether icon exists */
706 COMBOEX_AdjustEditPos (infoPtr);
710 static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
712 INT index = cit->iItem;
715 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
717 /* if item number requested does not exist then return failure */
718 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
720 /* if the item is the edit control and there is no edit control, skip */
721 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
723 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
725 /* add/change stuff to the internal item structure */
726 item->mask |= cit->mask;
727 if (cit->mask & CBEIF_TEXT) {
730 COMBOEX_FreeText(item);
731 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
733 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
734 if (!item->pszText) return FALSE;
735 strcpyW(item->pszText, cit->pszText);
736 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
737 item->pszText = LPSTR_TEXTCALLBACKW;
738 item->cchTextMax = cit->cchTextMax;
740 if (cit->mask & CBEIF_IMAGE)
741 item->iImage = cit->iImage;
742 if (cit->mask & CBEIF_SELECTEDIMAGE)
743 item->iSelectedImage = cit->iSelectedImage;
744 if (cit->mask & CBEIF_OVERLAY)
745 item->iOverlay = cit->iOverlay;
746 if (cit->mask & CBEIF_INDENT)
747 item->iIndent = cit->iIndent;
748 if (cit->mask & CBEIF_LPARAM)
749 cit->lParam = cit->lParam;
751 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
753 /* if original request was to update edit control, do some fast foot work */
754 if (cit->iItem == -1) {
755 COMBOEX_SetEditText (infoPtr, item);
756 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
761 static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
763 COMBOBOXEXITEMW citW;
767 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
768 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
769 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
770 wstr = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
771 if (!wstr) return FALSE;
772 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
775 ret = COMBOEX_SetItemW(infoPtr, &citW);
777 if (wstr) COMCTL32_Free(wstr);
783 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
785 BOOL bTemp = infoPtr->unicode;
787 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
789 infoPtr->unicode = value;
795 /* *** CB_xxx message support *** */
798 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
801 cmp_func_t cmptext = get_cmp_func(infoPtr);
802 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
804 /* now search from after starting loc and wrapping back to start */
805 for(i=start+1; i<count; i++) {
806 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
807 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
809 for(i=0; i<=start; i++) {
810 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
811 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
817 static DWORD COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
819 CBE_ITEMDATA *item1, *item2;
822 item1 = get_item_data(infoPtr, index);
823 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
824 item2 = COMBOEX_FindItem (infoPtr, index);
825 if (item2 != item1) {
826 ERR("data structures damaged!\n");
829 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
830 TRACE("returning 0x%08lx\n", ret);
833 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
839 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
844 if (!(item = COMBOEX_FindItem(infoPtr, index)))
845 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
847 TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
848 infoPtr->selected = index;
850 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
851 COMBOEX_SetEditText (infoPtr, item);
856 static DWORD COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD data)
858 CBE_ITEMDATA *item1, *item2;
860 item1 = get_item_data(infoPtr, index);
861 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
862 item2 = COMBOEX_FindItem (infoPtr, index);
863 if (item2 != item1) {
864 ERR("data structures damaged!\n");
867 item1->mask |= CBEIF_LPARAM;
868 item1->lParam = data;
869 TRACE("setting lparam to 0x%08lx\n", data);
872 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
873 return (LRESULT)item1;
877 static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
879 RECT cb_wrect, cbx_wrect, cbx_crect;
881 /* First, lets forward the message to the normal combo control
882 just like Windows. */
883 if (infoPtr->hwndCombo)
884 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
885 index, height) == CB_ERR) return CB_ERR;
887 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
888 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
889 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
890 /* the height of comboex as height of the combo + comboex border */
891 height = cb_wrect.bottom-cb_wrect.top
892 + cbx_wrect.bottom-cbx_wrect.top
893 - (cbx_crect.bottom-cbx_crect.top);
894 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
895 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
896 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
897 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
898 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
899 cbx_wrect.right-cbx_wrect.left, height);
900 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
901 cbx_wrect.right-cbx_wrect.left, height,
902 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
908 /* *** WM_xxx message support *** */
911 static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
913 WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
914 WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
916 COMBOEX_INFO *infoPtr;
918 RECT wnrc1, clrc1, cmbwrc;
921 /* allocate memory for info structure */
922 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
923 if (!infoPtr) return -1;
925 /* initialize info structure */
926 /* note that infoPtr is allocated zero-filled */
928 infoPtr->hwndSelf = hwnd;
929 infoPtr->selected = -1;
931 infoPtr->unicode = IsWindowUnicode (hwnd);
933 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
934 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
935 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
938 infoPtr->NtfUnicode = (i == NFR_UNICODE);
940 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
942 /* create combo box */
943 GetWindowRect(hwnd, &wnrc1);
944 GetClientRect(hwnd, &clrc1);
945 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
946 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
947 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
949 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
950 /* specified. It then creates it's own version of the EDIT control */
951 /* and makes the ComboBox the parent. This is because a normal */
952 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
953 /* We also need to place the edit control at the proper location */
954 /* (allow space for the icons). */
956 infoPtr->hwndCombo = CreateWindowW (COMBOBOX, NIL,
957 /* following line added to match native */
958 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
959 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
960 /* was base and is necessary */
961 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
962 GetWindowLongW (hwnd, GWL_STYLE),
963 cs->y, cs->x, cs->cx, cs->cy, hwnd,
964 (HMENU) GetWindowLongW (hwnd, GWL_ID),
965 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
968 * native does the following at this point according to trace:
969 * GetWindowThreadProcessId(hwndCombo,0)
970 * GetCurrentThreadId()
971 * GetWindowThreadProcessId(hwndCombo, &???)
972 * GetCurrentProcessId()
976 * Setup a property to hold the pointer to the COMBOBOXEX
979 SetPropA(infoPtr->hwndCombo, COMBOEX_SUBCLASS_PROP, hwnd);
980 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndCombo,
981 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
982 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
986 * Now create our own EDIT control so we can position it.
987 * It is created only for CBS_DROPDOWN style
989 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
990 infoPtr->hwndEdit = CreateWindowExW (0, EDIT, NIL,
991 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
992 0, 0, 0, 0, /* will set later */
994 (HMENU) GetWindowLongW (hwnd, GWL_ID),
995 GetWindowLongW (hwnd, GWL_HINSTANCE),
998 /* native does the following at this point according to trace:
999 * GetWindowThreadProcessId(hwndEdit,0)
1000 * GetCurrentThreadId()
1001 * GetWindowThreadProcessId(hwndEdit, &???)
1002 * GetCurrentProcessId()
1006 * Setup a property to hold the pointer to the COMBOBOXEX
1009 SetPropA(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
1010 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndEdit,
1011 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1012 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1016 * Locate the default font if necessary and then set it in
1017 * all associated controls
1019 if (!infoPtr->font) {
1020 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1022 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1024 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1025 if (infoPtr->hwndEdit) {
1026 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1027 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1030 COMBOEX_ReSize (infoPtr);
1032 /* Above is fairly certain, below is much less certain. */
1034 GetWindowRect(hwnd, &wnrc1);
1035 GetClientRect(hwnd, &clrc1);
1036 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1037 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1038 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1039 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1040 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1041 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1042 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1043 SWP_NOACTIVATE | SWP_NOREDRAW);
1045 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1046 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1047 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1048 SetWindowPos(hwnd, HWND_TOP,
1049 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1050 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1052 COMBOEX_AdjustEditPos (infoPtr);
1055 * Create an item structure to represent the data in the
1056 * EDIT control. It is allocated zero-filled.
1058 infoPtr->edit = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1059 if (!infoPtr->edit) {
1060 COMBOEX_Destroy(infoPtr);
1068 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1071 INT command = HIWORD(wParam);
1072 CBE_ITEMDATA *item = 0;
1074 INT cursel, n, oldItem;
1075 NMCBEENDEDITW cbeend;
1077 HWND parent = GetParent (infoPtr->hwndSelf);
1079 TRACE("for command %d\n", command);
1084 SetFocus (infoPtr->hwndCombo);
1085 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1086 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1089 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1091 * from native trace of first dropdown after typing in URL in IE4
1092 * CB_GETCURSEL(Combo)
1093 * GetWindowText(Edit)
1094 * CB_GETCURSEL(Combo)
1095 * CB_GETCOUNT(Combo)
1096 * CB_GETITEMDATA(Combo, n)
1097 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1098 * CB_GETCURSEL(Combo)
1099 * CB_SETCURSEL(COMBOEX, n)
1101 * the rest is supposition
1103 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1104 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1105 InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1106 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1108 cmp_func_t cmptext = get_cmp_func(infoPtr);
1109 /* find match from edit against those in Combobox */
1110 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1111 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1112 for (cursel = 0; cursel < n; cursel++){
1113 item = get_item_data(infoPtr, cursel);
1114 if ((INT)item == CB_ERR) break;
1115 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1117 if ((cursel == n) || ((INT)item == CB_ERR)) {
1118 TRACE("failed to find match??? item=%p cursel=%d\n",
1120 if (infoPtr->hwndEdit)
1121 SetFocus(infoPtr->hwndEdit);
1126 item = get_item_data(infoPtr, cursel);
1127 if ((INT)item == CB_ERR) {
1128 TRACE("failed to find match??? item=%p cursel=%d\n",
1130 if (infoPtr->hwndEdit)
1131 SetFocus(infoPtr->hwndEdit);
1136 /* Save flags for testing and reset them */
1137 oldflags = infoPtr->flags;
1138 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1140 if (oldflags & WCBE_ACTEDIT) {
1141 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1142 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1143 CB_GETCURSEL, 0, 0);
1144 cbeend.iWhy = CBENF_DROPDOWN;
1146 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1149 /* if selection has changed the set the new current selection */
1150 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1151 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1152 infoPtr->selected = cursel;
1153 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1154 SetFocus(infoPtr->hwndCombo);
1160 * CB_GETCURSEL(Combo)
1161 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1164 * WM_GETTEXTLENGTH(Edit)
1166 * EM_SETSEL(Edit, 0,0)
1167 * WM_GETTEXTLENGTH(Edit)
1169 * EM_SETSEL(Edit, 0,len)
1170 * return WM_COMMAND to parent
1172 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1173 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1174 ERR("item %d not found. Problem!\n", oldItem);
1177 infoPtr->selected = oldItem;
1178 COMBOEX_SetEditText (infoPtr, item);
1179 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1183 * We have to change the handle since we are the control
1184 * issuing the message. IE4 depends on this.
1186 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1190 * from native trace:
1193 * WM_GETTEXT(Edit, 104)
1194 * CB_GETCURSEL(Combo) rets -1
1195 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1196 * CB_GETCURSEL(Combo)
1197 * InvalidateRect(Combo, 0, 0)
1200 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1201 if (infoPtr->flags & WCBE_ACTEDIT) {
1202 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1203 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1204 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1205 CB_GETCURSEL, 0, 0);
1206 cbeend.iWhy = CBENF_KILLFOCUS;
1208 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1209 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1211 /* possible CB_GETCURSEL */
1212 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1217 * We have to change the handle since we are the control
1218 * issuing the message. IE4 depends on this.
1219 * We also need to set the focus back to the Edit control
1220 * after passing the command to the parent of the ComboEx.
1222 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1223 if (infoPtr->hwndEdit)
1224 SetFocus(infoPtr->hwndEdit);
1231 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
1233 CBE_ITEMDATA *item, *olditem;
1234 NMCOMBOBOXEXW nmcit;
1237 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1238 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1240 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1242 olditem = infoPtr->items;
1243 i = infoPtr->nb_items - 1;
1245 if (i == dis->itemID) {
1246 infoPtr->items = infoPtr->items->next;
1252 /* find the prior item in the list */
1253 while (item->next && (i > dis->itemID)) {
1254 item = (CBE_ITEMDATA *)item->next;
1257 if (!item->next || (i != dis->itemID)) {
1258 ERR("COMBOBOXEX item structures broken. Please report!\n");
1261 olditem = item->next;
1262 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1264 infoPtr->nb_items--;
1266 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1267 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1268 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1270 COMBOEX_FreeText(olditem);
1271 COMCTL32_Free(olditem);
1277 static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
1279 WCHAR nil[] = { 0 };
1280 CBE_ITEMDATA *item = 0;
1286 COLORREF nbkc, ntxc, bkc, txc;
1287 int drawimage, drawstate, xioff;
1289 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1291 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1292 dis->CtlType, dis->CtlID);
1293 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1294 dis->itemID, dis->itemAction, dis->itemState);
1295 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1296 dis->hwndItem, dis->hDC, dis->rcItem.left,
1297 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1301 /* "itemID - Specifies the menu item identifier for a menu */
1302 /* item or the index of the item in a list box or combo box. */
1303 /* For an empty list box or combo box, this member can be -1. */
1304 /* This allows the application to draw only the focus */
1305 /* rectangle at the coordinates specified by the rcItem */
1306 /* member even though there are no items in the control. */
1307 /* This indicates to the user whether the list box or combo */
1308 /* box has the focus. How the bits are set in the itemAction */
1309 /* member determines whether the rectangle is to be drawn as */
1310 /* though the list box or combo box has the focus. */
1311 if (dis->itemID == 0xffffffff) {
1312 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1313 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1315 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1316 dis->rcItem.left, dis->rcItem.top,
1317 dis->rcItem.right, dis->rcItem.bottom);
1319 else if ((dis->CtlType == ODT_COMBOBOX) &&
1320 (dis->itemAction == ODA_DRAWENTIRE)) {
1321 /* draw of edit control data */
1325 RECT exrc, cbrc, edrc;
1326 GetWindowRect (infoPtr->hwndSelf, &exrc);
1327 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1328 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1329 if (infoPtr->hwndEdit)
1330 GetWindowRect (infoPtr->hwndEdit, &edrc);
1331 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1332 exrc.left, exrc.top, exrc.right, exrc.bottom,
1333 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1334 edrc.left, edrc.top, edrc.right, edrc.bottom);
1338 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1339 dis->rcItem.left, dis->rcItem.top,
1340 dis->rcItem.right, dis->rcItem.bottom,
1341 dis->itemAction, dis->itemState);
1346 /* If draw item is -1 (edit control) setup the item pointer */
1347 if (dis->itemID == 0xffffffff) {
1348 item = infoPtr->edit;
1350 if (infoPtr->hwndEdit) {
1353 /* free previous text of edit item */
1354 COMBOEX_FreeText(item);
1355 item->mask &= ~CBEIF_TEXT;
1356 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1357 item->mask |= CBEIF_TEXT;
1358 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1360 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1362 TRACE("edit control hwndEdit=%0x, text len=%d str=%s\n",
1363 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1369 /* if the item pointer is not set, then get the data and locate it */
1371 item = get_item_data(infoPtr, dis->itemID);
1372 if (item == (CBE_ITEMDATA *)CB_ERR) {
1373 ERR("invalid item for id %d \n", dis->itemID);
1378 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1380 xbase = CBE_STARTOFFSET;
1381 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1382 INT indent = item->iIndent;
1383 if (indent == I_INDENTCALLBACK) {
1385 ZeroMemory(&nmce, sizeof(nmce));
1386 nmce.ceItem.mask = CBEIF_INDENT;
1387 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1388 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1389 item->iIndent = nmce.ceItem.iIndent;
1390 indent = nmce.ceItem.iIndent;
1392 xbase += (indent * CBE_INDENT);
1396 drawstate = ILD_NORMAL;
1397 if (item->mask & CBEIF_IMAGE)
1398 drawimage = item->iImage;
1399 if (dis->itemState & ODS_COMBOEXLBOX) {
1400 /* drawing listbox entry */
1401 if (dis->itemState & ODS_SELECTED) {
1402 if (item->mask & CBEIF_SELECTEDIMAGE)
1403 drawimage = item->iSelectedImage;
1404 drawstate = ILD_SELECTED;
1407 /* drawing combo/edit entry */
1408 if (IsWindowVisible(infoPtr->hwndEdit)) {
1409 /* if we have an edit control, the slave the
1410 * selection state to the Edit focus state
1412 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1413 if (item->mask & CBEIF_SELECTEDIMAGE)
1414 drawimage = item->iSelectedImage;
1415 drawstate = ILD_SELECTED;
1418 /* if we don't have an edit control, use
1419 * the requested state.
1421 if (dis->itemState & ODS_SELECTED) {
1422 if (item->mask & CBEIF_SELECTEDIMAGE)
1423 drawimage = item->iSelectedImage;
1424 drawstate = ILD_SELECTED;
1429 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1431 iinfo.rcImage.left = iinfo.rcImage.right = 0;
1432 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1433 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1436 /* setup pointer to text to be drawn */
1437 str = COMBOEX_GetText(infoPtr, item);
1438 if (!str) str = nil;
1440 len = strlenW (str);
1441 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1443 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1444 int overlay = item->iOverlay;
1446 if (drawimage == I_IMAGECALLBACK) {
1448 ZeroMemory(&nmce, sizeof(nmce));
1449 nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
1450 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1451 if (drawstate == ILD_NORMAL) {
1452 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1453 drawimage = nmce.ceItem.iImage;
1454 } else if (drawstate == ILD_SELECTED) {
1455 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1456 drawimage = nmce.ceItem.iSelectedImage;
1457 } else ERR("Bad draw state = %d\n", drawstate);
1460 if (overlay == I_IMAGECALLBACK) {
1462 ZeroMemory(&nmce, sizeof(nmce));
1463 nmce.ceItem.mask = CBEIF_OVERLAY;
1464 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1465 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1466 item->iOverlay = nmce.ceItem.iOverlay;
1467 overlay = nmce.ceItem.iOverlay;
1470 if (drawimage >= 0 &&
1471 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1472 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1473 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1474 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1477 /* now draw the text */
1478 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1479 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1480 COLOR_HIGHLIGHT : COLOR_WINDOW);
1481 bkc = SetBkColor (dis->hDC, nbkc);
1482 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1483 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1484 txc = SetTextColor (dis->hDC, ntxc);
1486 y = dis->rcItem.top +
1487 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1489 rect.right = x + txtsize.cx;
1490 rect.top = dis->rcItem.top + 1;
1491 rect.bottom = dis->rcItem.bottom - 1;
1492 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1493 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1494 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1495 &rect, str, len, 0);
1496 SetBkColor (dis->hDC, bkc);
1497 SetTextColor (dis->hDC, txc);
1501 if (dis->itemAction & ODA_FOCUS) {
1502 rect.left = xbase + xioff - 1;
1503 rect.right = rect.left + txtsize.cx + 2;
1504 rect.top = dis->rcItem.top;
1505 rect.bottom = dis->rcItem.bottom;
1506 DrawFocusRect(dis->hDC, &rect);
1513 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1515 if (infoPtr->hwndCombo)
1516 DestroyWindow (infoPtr->hwndCombo);
1518 if (infoPtr->edit) {
1519 COMCTL32_Free (infoPtr->edit);
1523 if (infoPtr->items) {
1524 CBE_ITEMDATA *item, *next;
1526 item = infoPtr->items;
1528 next = (CBE_ITEMDATA *)item->next;
1529 COMBOEX_FreeText (item);
1530 COMCTL32_Free (item);
1536 if (infoPtr->defaultFont)
1537 DeleteObject (infoPtr->defaultFont);
1539 /* free comboex info data */
1540 COMCTL32_Free (infoPtr);
1541 SetWindowLongW (infoPtr->hwndSelf, 0, 0);
1546 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
1552 GetTextExtentPointA (hdc, "W", 1, &mysize);
1554 mis->itemHeight = mysize.cy + CBE_EXTRA;
1556 TRACE("adjusted height hwnd=%08x, height=%d\n",
1557 infoPtr->hwndSelf, mis->itemHeight);
1563 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1565 /* WARNING: The COMBOEX_INFO structure is not yet created */
1566 DWORD oldstyle, newstyle;
1568 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1569 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1570 if (newstyle != oldstyle) {
1571 TRACE("req style %08lx, reseting style %08lx\n",
1572 oldstyle, newstyle);
1573 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1579 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1581 if (lParam == NF_REQUERY) {
1582 INT i = SendMessageW(GetParent (infoPtr->hwndSelf),
1583 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1584 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1586 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1590 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1592 TRACE("(width=%d, height=%d)\n", width, height);
1594 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1596 COMBOEX_AdjustEditPos (infoPtr);
1602 static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1604 RECT cbx_wrect, cbx_crect, cb_wrect;
1607 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1608 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1609 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1611 /* width is winpos value + border width of comboex */
1613 + (cbx_wrect.right-cbx_wrect.left)
1614 - (cbx_crect.right-cbx_crect.left);
1616 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1617 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1618 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1619 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1620 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1621 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1622 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1623 width, cb_wrect.bottom-cb_wrect.top);
1625 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1627 cb_wrect.bottom-cb_wrect.top,
1630 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1632 /* height is combo window height plus border width of comboex */
1633 height = (cb_wrect.bottom-cb_wrect.top)
1634 + (cbx_wrect.bottom-cbx_wrect.top)
1635 - (cbx_crect.bottom-cbx_crect.top);
1636 if (wp->cy < height) wp->cy = height;
1637 if (infoPtr->hwndEdit) {
1638 COMBOEX_AdjustEditPos (infoPtr);
1639 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1645 static inline int is_delimiter(WCHAR c)
1657 COMBOEX_PathWordBreakProc(LPWSTR lpch, int ichCurrent, int cch, int code)
1659 if (code == WB_ISDELIMITER) {
1660 return is_delimiter(lpch[ichCurrent]);
1662 int dir = (code == WB_LEFT) ? -1 : 1;
1663 for(; 0 <= ichCurrent && ichCurrent < cch; ichCurrent += dir)
1664 if (is_delimiter(lpch[ichCurrent])) return ichCurrent;
1669 static LRESULT WINAPI
1670 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1672 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1673 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1674 NMCBEENDEDITW cbeend;
1675 WCHAR edit_text[260];
1681 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1682 hwnd, uMsg, wParam, lParam, infoPtr);
1684 if (!infoPtr) return 0;
1690 /* handle (ignore) the return character */
1691 if (wParam == VK_RETURN) return 0;
1692 /* all other characters pass into the real Edit */
1693 return CallWindowProcW (infoPtr->prevEditWndProc,
1694 hwnd, uMsg, wParam, lParam);
1698 * The following was determined by traces of the native
1701 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1702 GetClientRect (hwnd, &rect);
1703 TRACE("erasing (%d,%d)-(%d,%d)\n",
1704 rect.left, rect.top, rect.right, rect.bottom);
1705 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1706 SetBkColor (hDC, obkc);
1707 return CallWindowProcW (infoPtr->prevEditWndProc,
1708 hwnd, uMsg, wParam, lParam);
1711 INT oldItem, selected, step = 1;
1714 switch ((INT)wParam)
1717 /* native version seems to do following for COMBOEX */
1719 * GetWindowTextA(Edit,&?, 0x104) x
1720 * CB_GETCURSEL to Combo rets -1 x
1721 * WM_NOTIFY to COMBOEX parent (rebar) x
1722 * (CBEN_ENDEDIT{A|W}
1723 * fChanged = FALSE x
1724 * inewSelection = -1 x
1727 * CB_GETCURSEL to Combo rets -1 x
1728 * InvalidateRect(Combo, 0) x
1729 * WM_SETTEXT to Edit x
1730 * EM_SETSEL to Edit (0,0) x
1731 * EM_SETSEL to Edit (0,-1) x
1732 * RedrawWindow(Combo, 0, 0, 5) x
1734 TRACE("special code for VK_ESCAPE\n");
1736 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1738 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1739 cbeend.fChanged = FALSE;
1740 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1741 CB_GETCURSEL, 0, 0);
1742 cbeend.iWhy = CBENF_ESCAPE;
1744 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1745 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1746 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1747 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1748 ERR("item %d not found. Problem!\n", oldItem);
1751 infoPtr->selected = oldItem;
1752 COMBOEX_SetEditText (infoPtr, item);
1753 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1758 /* native version seems to do following for COMBOEX */
1760 * GetWindowTextA(Edit,&?, 0x104) x
1761 * CB_GETCURSEL to Combo rets -1 x
1762 * CB_GETCOUNT to Combo rets 0
1764 * CB_GETITEMDATA to match
1765 * *** above 3 lines simulated by FindItem x
1766 * WM_NOTIFY to COMBOEX parent (rebar) x
1767 * (CBEN_ENDEDIT{A|W} x
1768 * fChanged = TRUE (-1) x
1769 * iNewSelection = -1 or selected x
1771 * iWhy = 2 (CBENF_RETURN) x
1772 * CB_GETCURSEL to Combo rets -1 x
1773 * if -1 send CB_SETCURSEL to Combo -1 x
1774 * InvalidateRect(Combo, 0, 0) x
1776 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1779 TRACE("special code for VK_RETURN\n");
1781 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1783 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1784 selected = SendMessageW (infoPtr->hwndCombo,
1785 CB_GETCURSEL, 0, 0);
1787 if (selected != -1) {
1788 cmp_func_t cmptext = get_cmp_func(infoPtr);
1789 item = COMBOEX_FindItem (infoPtr, selected);
1790 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1791 selected, debugstr_txt(item->pszText));
1792 TRACE("handling VK_RETURN, edittext=%s\n",
1793 debugstr_w(edit_text));
1794 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1795 /* strings not equal -- indicate edit has changed */
1800 cbeend.iNewSelection = selected;
1801 cbeend.fChanged = TRUE;
1802 cbeend.iWhy = CBENF_RETURN;
1803 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1804 /* abort the change, restore previous */
1805 TRACE("Notify requested abort of change\n");
1806 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1807 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1811 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1812 if (oldItem != -1) {
1813 /* if something is selected, then deselect it */
1814 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1817 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1818 SetFocus(infoPtr->hwndEdit);
1824 /* by default, step is 1 */
1825 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1826 if (oldItem >= 0 && oldItem + step >= 0)
1827 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1830 return CallWindowProcW (infoPtr->prevEditWndProc,
1831 hwnd, uMsg, wParam, lParam);
1837 /* remember the focus to set state of icon */
1838 lret = CallWindowProcW (infoPtr->prevEditWndProc,
1839 hwnd, uMsg, wParam, lParam);
1840 infoPtr->flags |= WCBE_EDITFOCUSED;
1845 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1847 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1848 if (infoPtr->flags & WCBE_ACTEDIT) {
1849 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1851 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1852 cbeend.fChanged = FALSE;
1853 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1854 CB_GETCURSEL, 0, 0);
1855 cbeend.iWhy = CBENF_KILLFOCUS;
1857 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1862 return CallWindowProcW (infoPtr->prevEditWndProc,
1863 hwnd, uMsg, wParam, lParam);
1869 static LRESULT WINAPI
1870 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1872 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1873 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1874 NMCBEENDEDITW cbeend;
1881 WCHAR edit_text[260];
1883 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1884 hwnd, uMsg, wParam, lParam, infoPtr);
1886 if (!infoPtr) return 0;
1893 * The only way this message should come is from the
1894 * child Listbox issuing the message. Flag this so
1895 * that ComboEx knows this is listbox.
1897 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1898 return CallWindowProcW (infoPtr->prevComboWndProc,
1899 hwnd, uMsg, wParam, lParam);
1903 * The following was determined by traces of the native
1906 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1907 GetClientRect (hwnd, &rect);
1908 TRACE("erasing (%d,%d)-(%d,%d)\n",
1909 rect.left, rect.top, rect.right, rect.bottom);
1910 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1911 SetBkColor (hDC, obkc);
1912 return CallWindowProcW (infoPtr->prevComboWndProc,
1913 hwnd, uMsg, wParam, lParam);
1917 * WM_NOTIFY to comboex parent (rebar)
1918 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1919 * CallWindowProc (previous)
1921 nmmse.dwItemSpec = 0;
1922 nmmse.dwItemData = 0;
1925 nmmse.dwHitInfo = lParam;
1926 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1927 return CallWindowProcW (infoPtr->prevComboWndProc,
1928 hwnd, uMsg, wParam, lParam);
1930 case WM_LBUTTONDOWN:
1931 GetClientRect (hwnd, &rect);
1932 rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1933 CB_GETITEMHEIGHT, -1, 0);
1934 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
1935 POINTSTOPOINT(pt, MAKEPOINTS(lParam));
1936 if (PtInRect(&rect, pt))
1937 return CallWindowProcW (infoPtr->prevComboWndProc,
1938 hwnd, uMsg, wParam, lParam);
1939 infoPtr->flags |= WCBE_MOUSECAPTURED;
1944 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1945 return CallWindowProcW (infoPtr->prevComboWndProc,
1946 hwnd, uMsg, wParam, lParam);
1948 infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1949 if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1950 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1952 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1957 if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1958 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
1959 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1960 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
1961 infoPtr->flags |= WCBE_MOUSEDRAGGED;
1963 return CallWindowProcW (infoPtr->prevComboWndProc,
1964 hwnd, uMsg, wParam, lParam);
1967 switch (HIWORD(wParam)) {
1970 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1979 * GetFocus() retns AA
1980 * GetWindowTextA(Edit)
1981 * CB_GETCURSEL(Combo) (got -1)
1982 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1983 * CB_GETCURSEL(Combo) (got -1)
1984 * InvalidateRect(Combo, 0, 0)
1985 * WM_KILLFOCUS(Combo, AA)
1988 focusedhwnd = GetFocus();
1989 if (infoPtr->flags & WCBE_ACTEDIT) {
1990 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1991 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1992 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1993 CB_GETCURSEL, 0, 0);
1994 cbeend.iWhy = CBENF_KILLFOCUS;
1996 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1997 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1999 /* possible CB_GETCURSEL */
2000 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2002 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2003 (WPARAM)focusedhwnd, 0);
2008 * For EN_SETFOCUS this issues the same calls and messages
2009 * as the native seems to do.
2011 * for some cases however native does the following:
2012 * (noticed after SetFocus during LBUTTONDOWN on
2013 * on dropdown arrow)
2014 * WM_GETTEXTLENGTH (Edit);
2015 * WM_GETTEXT (Edit, len+1, str);
2016 * EM_SETSEL (Edit, 0, 0);
2017 * WM_GETTEXTLENGTH (Edit);
2018 * WM_GETTEXT (Edit, len+1, str);
2019 * EM_SETSEL (Edit, 0, len);
2020 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2024 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2025 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2026 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2027 infoPtr->flags |= WCBE_ACTEDIT;
2028 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2034 * For EN_CHANGE this issues the same calls and messages
2035 * as the native seems to do.
2037 WCHAR edit_text[260];
2039 cmp_func_t cmptext = get_cmp_func(infoPtr);
2041 INT selected = SendMessageW (infoPtr->hwndCombo,
2042 CB_GETCURSEL, 0, 0);
2044 /* lstrlenA( lastworkingURL ) */
2046 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2047 if (selected == -1) {
2048 lastwrk = infoPtr->edit->pszText;
2051 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2052 lastwrk = COMBOEX_GetText(infoPtr, item);
2055 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2056 selected, debugstr_w(lastwrk));
2057 TRACE("handling EN_CHANGE, edittext=%s\n",
2058 debugstr_w(edit_text));
2060 /* cmptext is between lastworkingURL and GetWindowText */
2061 if (cmptext (lastwrk, edit_text)) {
2062 /* strings not equal -- indicate edit has changed */
2063 infoPtr->flags |= WCBE_EDITCHG;
2065 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2066 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2068 (LPARAM)infoPtr->hwndSelf);
2074 * Therefore from traces there is no additional code here
2078 * Using native COMCTL32 gets the following:
2079 * 1 == SHDOCVW.DLL issues call/message
2080 * 2 == COMCTL32.DLL issues call/message
2081 * 3 == WINE issues call/message
2084 * for LBN_SELCHANGE:
2085 * 1 CB_GETCURSEL(ComboEx)
2086 * 1 CB_GETDROPPEDSTATE(ComboEx)
2087 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2088 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2089 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2090 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2091 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2092 * 3 ShowWindow(ComboLB, SW_HIDE)
2093 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2094 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2096 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2097 * ? LB_GETCURSEL <==|
2099 * ? LB_GETTEXT | Needs to be added to
2100 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2101 * ? LB_GETITEMDATA |
2102 * ? WM_DRAWITEM(ComboEx) <==|
2108 return CallWindowProcW (infoPtr->prevComboWndProc,
2109 hwnd, uMsg, wParam, lParam);
2115 static LRESULT WINAPI
2116 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2118 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2120 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2123 if (uMsg == WM_CREATE)
2124 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2125 if (uMsg == WM_NCCREATE)
2126 COMBOEX_NCCreate (hwnd);
2127 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2132 case CBEM_DELETEITEM:
2133 return COMBOEX_DeleteItem (infoPtr, wParam);
2135 case CBEM_GETCOMBOCONTROL:
2136 return (LRESULT)infoPtr->hwndCombo;
2138 case CBEM_GETEDITCONTROL:
2139 return (LRESULT)infoPtr->hwndEdit;
2141 case CBEM_GETEXTENDEDSTYLE:
2142 return infoPtr->dwExtStyle;
2144 case CBEM_GETIMAGELIST:
2145 return (LRESULT)infoPtr->himl;
2148 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2151 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2153 case CBEM_GETUNICODEFORMAT:
2154 return infoPtr->unicode;
2156 case CBEM_HASEDITCHANGED:
2157 return COMBOEX_HasEditChanged (infoPtr);
2159 case CBEM_INSERTITEMA:
2160 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2162 case CBEM_INSERTITEMW:
2163 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2165 case CBEM_SETEXSTYLE:
2166 case CBEM_SETEXTENDEDSTYLE:
2167 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2169 case CBEM_SETIMAGELIST:
2170 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2173 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2176 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2178 case CBEM_SETUNICODEFORMAT:
2179 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2181 /*case CBEM_SETWINDOWTHEME:
2182 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2186 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2188 /* Combo messages we are not sure if we need to process or just forward */
2189 case CB_GETDROPPEDCONTROLRECT:
2190 case CB_GETITEMHEIGHT:
2192 case CB_GETLBTEXTLEN:
2193 case CB_GETEXTENDEDUI:
2195 case CB_RESETCONTENT:
2196 case CB_SELECTSTRING:
2198 /* Combo messages OK to just forward to the regular COMBO */
2201 case CB_GETDROPPEDSTATE:
2202 case CB_SETDROPPEDWIDTH:
2203 case CB_SETEXTENDEDUI:
2204 case CB_SHOWDROPDOWN:
2205 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2207 /* Combo messages we need to process specially */
2208 case CB_FINDSTRINGEXACT:
2209 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2211 case CB_GETITEMDATA:
2212 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2215 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2217 case CB_SETITEMDATA:
2218 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD)lParam);
2220 case CB_SETITEMHEIGHT:
2221 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2225 /* Window messages passed to parent */
2227 return COMBOEX_Command (infoPtr, wParam, lParam);
2230 if (infoPtr->NtfUnicode)
2231 return SendMessageW (GetParent (hwnd), uMsg, wParam, lParam);
2233 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
2236 /* Window messages we need to process */
2238 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2241 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2244 return COMBOEX_Destroy (infoPtr);
2246 case WM_MEASUREITEM:
2247 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2249 case WM_NOTIFYFORMAT:
2250 return COMBOEX_NotifyFormat (infoPtr, lParam);
2253 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2255 case WM_WINDOWPOSCHANGING:
2256 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2259 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2260 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
2261 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2267 void COMBOEX_Register (void)
2271 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2272 wndClass.style = CS_GLOBALCLASS;
2273 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2274 wndClass.cbClsExtra = 0;
2275 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2276 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
2277 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2278 wndClass.lpszClassName = WC_COMBOBOXEXW;
2280 RegisterClassW (&wndClass);
2284 void COMBOEX_Unregister (void)
2286 UnregisterClassW (WC_COMBOBOXEXW, (HINSTANCE)NULL);