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
27 #include "wine/debug.h"
28 #include "wine/unicode.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
47 /* ComboBoxEx structure */
51 HWND hwndSelf; /* my own hwnd */
54 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
55 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
57 INT selected; /* index of selected item */
58 DWORD flags; /* WINE internal flags */
61 INT nb_items; /* Number of items */
62 BOOL unicode; /* TRUE if this window is Unicode */
63 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
64 CBE_ITEMDATA *edit; /* item data for edit item */
65 CBE_ITEMDATA *items; /* Array of items */
68 /* internal flags in the COMBOEX_INFO structure */
69 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
70 * CBEN_BEGINEDIT issued
71 * but CBEN_ENDEDIT{A|W}
73 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
74 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
75 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
76 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
77 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
79 #define ID_CB_EDIT 1001
83 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
84 * the ComboEx version of the Combo Window Proc so that when the
85 * WM_DRAWITEM message is then passed to ComboEx, we know that this
86 * particular WM_DRAWITEM message is for listbox only items. Any messasges
87 * without this flag is then for the Edit control field.
89 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
90 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
92 #define ODS_COMBOEXLBOX 0x4000
96 /* Height in pixels of control over the amount of the selected font */
99 /* Indent amount per MS documentation */
100 #define CBE_INDENT 10
102 /* Offset in pixels from left side for start of image or text */
103 #define CBE_STARTOFFSET 6
105 /* Offset between image and text */
108 #define COMBOEX_SUBCLASS_PROP "CCComboEx32SubclassInfo"
109 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongW (hwnd, 0))
112 /* Things common to the entire DLL */
113 static LRESULT WINAPI
114 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
115 static LRESULT WINAPI
116 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
118 COMBOEX_PathWordBreakProc(LPWSTR lpch, int ichCurrent, int cch, int code);
119 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
120 typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
122 inline static BOOL is_textW(LPCWSTR str)
124 return str && str != LPSTR_TEXTCALLBACKW;
127 inline static BOOL is_textA(LPCSTR str)
129 return str && str != LPSTR_TEXTCALLBACKA;
132 inline static LPCSTR debugstr_txt(LPCWSTR str)
134 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
135 return debugstr_w(str);
138 static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
140 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
141 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
142 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
143 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
144 if (item->mask & CBEIF_TEXT)
145 TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
149 static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
151 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
152 input->mask, input->iItem, input->pszText, input->cchTextMax,
154 if (input->mask & CBEIF_TEXT)
155 TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
156 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
157 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
161 inline static CBE_ITEMDATA *get_item_data(COMBOEX_INFO *infoPtr, INT index)
163 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
167 inline static cmp_func_t get_cmp_func(COMBOEX_INFO *infoPtr)
169 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
172 static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
174 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
175 hdr->hwndFrom = infoPtr->hwndSelf;
177 if (infoPtr->NtfUnicode)
178 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
181 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
187 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
189 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
190 if (infoPtr->NtfUnicode)
191 return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
193 LPWSTR wstr = hdr->ceItem.pszText;
197 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
198 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
200 astr = (LPSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
202 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
203 hdr->ceItem.pszText = (LPWSTR)astr;
207 if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
208 else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
209 else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
211 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
213 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
214 hdr->ceItem.pszText = wstr;
216 if (astr) COMCTL32_Free(astr);
223 static INT COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
225 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
226 if (infoPtr->NtfUnicode) {
227 lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
228 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
232 memcpy (&neea.hdr, &neew->hdr, sizeof(NMHDR));
233 neea.fChanged = neew->fChanged;
234 neea.iNewSelection = neew->iNewSelection;
235 WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
236 neea.iWhy = neew->iWhy;
238 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
243 static void COMBOEX_NotifyDragBegin(COMBOEX_INFO *infoPtr, LPCWSTR wstr)
245 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
246 if (infoPtr->NtfUnicode) {
247 NMCBEDRAGBEGINW ndbw;
250 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
251 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
253 NMCBEDRAGBEGINA ndba;
256 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
258 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
263 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
265 if (is_textW(item->pszText)) COMCTL32_Free(item->pszText);
267 if (item->pszTemp) COMCTL32_Free(item->pszTemp);
272 static LPCWSTR COMBOEX_GetText(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
278 if (item->pszText != LPSTR_TEXTCALLBACKW)
279 return item->pszText;
281 ZeroMemory(&nmce, sizeof(nmce));
282 nmce.ceItem.mask = CBEIF_TEXT;
283 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
285 if (is_textW(nmce.ceItem.pszText)) {
286 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
287 buf = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
289 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
290 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
291 COMBOEX_FreeText(item);
294 if (item->pszTemp) COMCTL32_Free(item->pszTemp);
299 text = nmce.ceItem.pszText;
301 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
302 item->pszText = text;
307 static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
312 mydc = GetDC (0); /* why the entire screen???? */
313 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
314 ofont = (HFONT) SelectObject (mydc, nfont);
315 GetTextExtentPointA (mydc, "A", 1, size);
316 SelectObject (mydc, ofont);
318 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
322 static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
324 if (cit->mask & CBEIF_TEXT) {
326 * when given a text buffer actually use that buffer
329 if (is_textW(item->pszText))
330 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
334 cit->pszText = item->pszText;
335 cit->cchTextMax = item->cchTextMax;
338 if (cit->mask & CBEIF_IMAGE)
339 cit->iImage = item->iImage;
340 if (cit->mask & CBEIF_SELECTEDIMAGE)
341 cit->iSelectedImage = item->iSelectedImage;
342 if (cit->mask & CBEIF_OVERLAY)
343 cit->iOverlay = item->iOverlay;
344 if (cit->mask & CBEIF_INDENT)
345 cit->iIndent = item->iIndent;
346 if (cit->mask & CBEIF_LPARAM)
347 cit->lParam = item->lParam;
351 static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
354 INT x, y, w, h, xioff;
357 if (!infoPtr->hwndEdit) return;
359 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
361 iinfo.rcImage.left = iinfo.rcImage.right = 0;
362 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
363 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
366 GetClientRect (infoPtr->hwndCombo, &rect);
367 InflateRect (&rect, -2, -2);
368 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
370 /* reposition the Edit control based on whether icon exists */
371 COMBOEX_GetComboFontSize (infoPtr, &mysize);
372 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
373 x = xioff + CBE_STARTOFFSET + 1;
374 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
376 y = rect.bottom - h - 1;
378 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
379 rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
380 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
381 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
385 static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
391 COMBOEX_GetComboFontSize (infoPtr, &mysize);
392 cy = mysize.cy + CBE_EXTRA;
394 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
395 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
396 TRACE("upgraded height due to image: height=%d\n", cy);
398 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)cy);
399 if (infoPtr->hwndCombo) {
400 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
401 (WPARAM) 0, (LPARAM) cy);
402 if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
404 if (GetWindowRect(infoPtr->hwndCombo, &comboRect)) {
406 if (GetWindowRect(infoPtr->hwndSelf, &ourRect)) {
407 if (comboRect.bottom > ourRect.bottom) {
408 POINT pt = { ourRect.left, ourRect.top };
409 if (ScreenToClient(infoPtr->hwndSelf, &pt))
410 MoveWindow( infoPtr->hwndSelf, pt.x, pt.y, ourRect.right - ourRect.left,
411 comboRect.bottom - comboRect.top, FALSE);
420 static void COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
422 if (!infoPtr->hwndEdit) return;
423 /* native issues the following messages to the {Edit} control */
424 /* WM_SETTEXT (0,addr) */
425 /* EM_SETSEL32 (0,0) */
426 /* EM_SETSEL32 (0,-1) */
427 if (item->mask & CBEIF_TEXT) {
428 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
429 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
430 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
435 static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
440 if ((index > infoPtr->nb_items) || (index < -1))
443 return infoPtr->edit;
444 item = infoPtr->items;
445 i = infoPtr->nb_items - 1;
447 /* find the item in the list */
448 while (item && (i > index)) {
449 item = (CBE_ITEMDATA *)item->next;
452 if (!item || (i != index)) {
453 ERR("COMBOBOXEX item structures broken. Please report!\n");
460 static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO *infoPtr)
462 return infoPtr->hwndEdit;
466 /* *** CBEM_xxx message support *** */
469 static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
473 TRACE("(index=%d)\n", index);
475 /* if item number requested does not exist then return failure */
476 if ((index > infoPtr->nb_items) || (index < 0)) return CB_ERR;
477 if (!(item = COMBOEX_FindItem(infoPtr, index))) return CB_ERR;
479 /* doing this will result in WM_DELETEITEM being issued */
480 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
482 return infoPtr->nb_items;
486 static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
488 INT index = cit->iItem;
493 /* if item number requested does not exist then return failure */
494 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
496 /* if the item is the edit control and there is no edit control, skip */
497 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
499 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
501 COMBOEX_CopyItem (item, cit);
507 static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
509 COMBOBOXEXITEMW tmpcit;
513 tmpcit.mask = cit->mask;
514 tmpcit.iItem = cit->iItem;
516 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
518 if (is_textW(tmpcit.pszText) && cit->pszText)
519 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
520 cit->pszText, cit->cchTextMax, NULL, NULL);
521 else if (cit->pszText) cit->pszText[0] = 0;
522 else cit->pszText = (LPSTR)tmpcit.pszText;
524 cit->iImage = tmpcit.iImage;
525 cit->iSelectedImage = tmpcit.iSelectedImage;
526 cit->iOverlay = tmpcit.iOverlay;
527 cit->iIndent = tmpcit.iIndent;
528 cit->lParam = tmpcit.lParam;
534 inline static BOOL COMBOEX_HasEditChanged (COMBOEX_INFO *infoPtr)
536 return COMBOEX_HasEdit(infoPtr) &&
537 (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
541 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
549 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
551 /* get real index of item to insert */
553 if (index == -1) index = infoPtr->nb_items;
554 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
556 /* get zero-filled space and chain it in */
557 if(!(item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof(*item)))) return -1;
559 /* locate position to insert new item in */
560 if (index == infoPtr->nb_items) {
561 /* fast path for iItem = -1 */
562 item->next = infoPtr->items;
563 infoPtr->items = item;
566 INT i = infoPtr->nb_items-1;
567 CBE_ITEMDATA *moving = infoPtr->items;
569 while ((i > index) && moving) {
570 moving = (CBE_ITEMDATA *)moving->next;
574 ERR("COMBOBOXEX item structures broken. Please report!\n");
578 item->next = moving->next;
582 /* fill in our hidden item structure */
583 item->mask = cit->mask;
584 if (item->mask & CBEIF_TEXT) {
587 if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
589 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
590 if (!item->pszText) {
594 strcpyW (item->pszText, cit->pszText);
596 else if (cit->pszText == LPSTR_TEXTCALLBACKW)
597 item->pszText = LPSTR_TEXTCALLBACKW;
598 item->cchTextMax = cit->cchTextMax;
600 if (item->mask & CBEIF_IMAGE)
601 item->iImage = cit->iImage;
602 if (item->mask & CBEIF_SELECTEDIMAGE)
603 item->iSelectedImage = cit->iSelectedImage;
604 if (item->mask & CBEIF_OVERLAY)
605 item->iOverlay = cit->iOverlay;
606 if (item->mask & CBEIF_INDENT)
607 item->iIndent = cit->iIndent;
608 if (item->mask & CBEIF_LPARAM)
609 item->lParam = cit->lParam;
612 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
614 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
615 (WPARAM)cit->iItem, (LPARAM)item);
617 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
618 COMBOEX_CopyItem (item, &nmcit.ceItem);
619 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
626 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
628 COMBOBOXEXITEMW citW;
632 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
633 if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
634 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
635 wstr = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
636 if (!wstr) return -1;
637 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
640 ret = COMBOEX_InsertItemW(infoPtr, &citW);
642 if (wstr) COMCTL32_Free(wstr);
649 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
653 TRACE("(mask=x%08lx, style=0x%08lx)\n", mask, style);
655 dwTemp = infoPtr->dwExtStyle;
658 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
660 infoPtr->dwExtStyle = style;
662 /* see if we need to change the word break proc on the edit */
663 if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC) {
664 SendMessageW(infoPtr->hwndEdit, EM_SETWORDBREAKPROC, 0,
665 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ?
666 (LPARAM)COMBOEX_PathWordBreakProc : 0);
669 /* test if the control's appearance has changed */
670 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
671 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
672 /* if state of EX_NOEDITIMAGE changes, invalidate all */
673 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
674 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
675 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
676 COMBOEX_AdjustEditPos (infoPtr);
677 if (infoPtr->hwndEdit)
678 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
685 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
687 HIMAGELIST himlTemp = infoPtr->himl;
691 infoPtr->himl = himl;
693 COMBOEX_ReSize (infoPtr);
694 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
696 /* reposition the Edit control based on whether icon exists */
697 COMBOEX_AdjustEditPos (infoPtr);
701 static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
703 INT index = cit->iItem;
706 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
708 /* if item number requested does not exist then return failure */
709 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
711 /* if the item is the edit control and there is no edit control, skip */
712 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
714 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
716 /* add/change stuff to the internal item structure */
717 item->mask |= cit->mask;
718 if (cit->mask & CBEIF_TEXT) {
721 COMBOEX_FreeText(item);
722 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
724 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
725 if (!item->pszText) return FALSE;
726 strcpyW(item->pszText, cit->pszText);
727 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
728 item->pszText = LPSTR_TEXTCALLBACKW;
729 item->cchTextMax = cit->cchTextMax;
731 if (cit->mask & CBEIF_IMAGE)
732 item->iImage = cit->iImage;
733 if (cit->mask & CBEIF_SELECTEDIMAGE)
734 item->iSelectedImage = cit->iSelectedImage;
735 if (cit->mask & CBEIF_OVERLAY)
736 item->iOverlay = cit->iOverlay;
737 if (cit->mask & CBEIF_INDENT)
738 item->iIndent = cit->iIndent;
739 if (cit->mask & CBEIF_LPARAM)
740 cit->lParam = cit->lParam;
742 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
744 /* if original request was to update edit control, do some fast foot work */
745 if (cit->iItem == -1) {
746 COMBOEX_SetEditText (infoPtr, item);
747 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
752 static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
754 COMBOBOXEXITEMW citW;
758 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
759 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
760 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
761 wstr = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
762 if (!wstr) return FALSE;
763 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
766 ret = COMBOEX_SetItemW(infoPtr, &citW);
768 if (wstr) COMCTL32_Free(wstr);
774 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
776 BOOL bTemp = infoPtr->unicode;
778 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
780 infoPtr->unicode = value;
786 /* *** CB_xxx message support *** */
789 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
792 cmp_func_t cmptext = get_cmp_func(infoPtr);
793 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
795 /* now search from after starting loc and wrapping back to start */
796 for(i=start+1; i<count; i++) {
797 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
798 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
800 for(i=0; i<=start; i++) {
801 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
802 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
808 static DWORD COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
810 CBE_ITEMDATA *item1, *item2;
813 item1 = get_item_data(infoPtr, index);
814 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
815 item2 = COMBOEX_FindItem (infoPtr, index);
816 if (item2 != item1) {
817 ERR("data structures damaged!\n");
820 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
821 TRACE("returning 0x%08lx\n", ret);
824 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
830 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
835 if (!(item = COMBOEX_FindItem(infoPtr, index)))
836 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
838 TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
839 infoPtr->selected = index;
841 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
842 COMBOEX_SetEditText (infoPtr, item);
847 static DWORD COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD data)
849 CBE_ITEMDATA *item1, *item2;
851 item1 = get_item_data(infoPtr, index);
852 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
853 item2 = COMBOEX_FindItem (infoPtr, index);
854 if (item2 != item1) {
855 ERR("data structures damaged!\n");
858 item1->mask |= CBEIF_LPARAM;
859 item1->lParam = data;
860 TRACE("setting lparam to 0x%08lx\n", data);
863 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
864 return (LRESULT)item1;
868 static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
870 RECT cb_wrect, cbx_wrect, cbx_crect;
872 /* First, lets forward the message to the normal combo control
873 just like Windows. */
874 if (infoPtr->hwndCombo)
875 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
876 index, height) == CB_ERR) return CB_ERR;
878 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
879 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
880 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
881 /* the height of comboex as height of the combo + comboex border */
882 height = cb_wrect.bottom-cb_wrect.top
883 + cbx_wrect.bottom-cbx_wrect.top
884 - (cbx_crect.bottom-cbx_crect.top);
885 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
886 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
887 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
888 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
889 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
890 cbx_wrect.right-cbx_wrect.left, height);
891 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
892 cbx_wrect.right-cbx_wrect.left, height,
893 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
899 /* *** WM_xxx message support *** */
902 static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
904 WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
905 WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
907 COMBOEX_INFO *infoPtr;
909 RECT wnrc1, clrc1, cmbwrc;
912 /* allocate memory for info structure */
913 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
914 if (!infoPtr) return -1;
916 /* initialize info structure */
917 /* note that infoPtr is allocated zero-filled */
919 infoPtr->hwndSelf = hwnd;
920 infoPtr->selected = -1;
922 infoPtr->unicode = IsWindowUnicode (hwnd);
924 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, hwnd, NF_QUERY);
925 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
926 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
929 infoPtr->NtfUnicode = (i == NFR_UNICODE);
931 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
933 /* create combo box */
934 GetWindowRect(hwnd, &wnrc1);
935 GetClientRect(hwnd, &clrc1);
936 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
937 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
938 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
940 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
941 /* specified. It then creates it's own version of the EDIT control */
942 /* and makes the ComboBox the parent. This is because a normal */
943 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
944 /* We also need to place the edit control at the proper location */
945 /* (allow space for the icons). */
947 infoPtr->hwndCombo = CreateWindowW (COMBOBOX, NIL,
948 /* following line added to match native */
949 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
950 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
951 /* was base and is necessary */
952 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
953 GetWindowLongW (hwnd, GWL_STYLE),
954 cs->y, cs->x, cs->cx, cs->cy, hwnd,
955 (HMENU) GetWindowLongW (hwnd, GWL_ID),
956 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
959 * native does the following at this point according to trace:
960 * GetWindowThreadProcessId(hwndCombo,0)
961 * GetCurrentThreadId()
962 * GetWindowThreadProcessId(hwndCombo, &???)
963 * GetCurrentProcessId()
967 * Setup a property to hold the pointer to the COMBOBOXEX
970 SetPropA(infoPtr->hwndCombo, COMBOEX_SUBCLASS_PROP, hwnd);
971 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndCombo,
972 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
973 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
977 * Now create our own EDIT control so we can position it.
978 * It is created only for CBS_DROPDOWN style
980 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
981 infoPtr->hwndEdit = CreateWindowExW (0, EDIT, NIL,
982 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
983 0, 0, 0, 0, /* will set later */
985 (HMENU) GetWindowLongW (hwnd, GWL_ID),
986 GetWindowLongW (hwnd, GWL_HINSTANCE),
989 /* native does the following at this point according to trace:
990 * GetWindowThreadProcessId(hwndEdit,0)
991 * GetCurrentThreadId()
992 * GetWindowThreadProcessId(hwndEdit, &???)
993 * GetCurrentProcessId()
997 * Setup a property to hold the pointer to the COMBOBOXEX
1000 SetPropA(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
1001 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndEdit,
1002 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1003 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1007 * Locate the default font if necessary and then set it in
1008 * all associated controls
1010 if (!infoPtr->font) {
1011 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1013 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1015 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1016 if (infoPtr->hwndEdit) {
1017 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1018 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1021 COMBOEX_ReSize (infoPtr);
1023 /* Above is fairly certain, below is much less certain. */
1025 GetWindowRect(hwnd, &wnrc1);
1026 GetClientRect(hwnd, &clrc1);
1027 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1028 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1029 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1030 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1031 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1032 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1033 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1034 SWP_NOACTIVATE | SWP_NOREDRAW);
1036 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1037 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1038 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1039 SetWindowPos(hwnd, HWND_TOP,
1040 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1041 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1043 COMBOEX_AdjustEditPos (infoPtr);
1046 * Create an item structure to represent the data in the
1047 * EDIT control. It is allocated zero-filled.
1049 infoPtr->edit = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1050 if (!infoPtr->edit) {
1051 COMBOEX_Destroy(infoPtr);
1059 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1062 INT command = HIWORD(wParam);
1063 CBE_ITEMDATA *item = 0;
1065 INT cursel, n, oldItem;
1066 NMCBEENDEDITW cbeend;
1068 HWND parent = GetParent (infoPtr->hwndSelf);
1070 TRACE("for command %d\n", command);
1075 SetFocus (infoPtr->hwndCombo);
1076 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1077 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1080 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1082 * from native trace of first dropdown after typing in URL in IE4
1083 * CB_GETCURSEL(Combo)
1084 * GetWindowText(Edit)
1085 * CB_GETCURSEL(Combo)
1086 * CB_GETCOUNT(Combo)
1087 * CB_GETITEMDATA(Combo, n)
1088 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1089 * CB_GETCURSEL(Combo)
1090 * CB_SETCURSEL(COMBOEX, n)
1092 * the rest is supposition
1094 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1095 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1096 InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1097 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1099 cmp_func_t cmptext = get_cmp_func(infoPtr);
1100 /* find match from edit against those in Combobox */
1101 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1102 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1103 for (cursel = 0; cursel < n; cursel++){
1104 item = get_item_data(infoPtr, cursel);
1105 if ((INT)item == CB_ERR) break;
1106 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1108 if ((cursel == n) || ((INT)item == CB_ERR)) {
1109 TRACE("failed to find match??? item=%p cursel=%d\n",
1111 if (infoPtr->hwndEdit)
1112 SetFocus(infoPtr->hwndEdit);
1117 item = get_item_data(infoPtr, cursel);
1118 if ((INT)item == CB_ERR) {
1119 TRACE("failed to find match??? item=%p cursel=%d\n",
1121 if (infoPtr->hwndEdit)
1122 SetFocus(infoPtr->hwndEdit);
1127 /* Save flags for testing and reset them */
1128 oldflags = infoPtr->flags;
1129 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1131 if (oldflags & WCBE_ACTEDIT) {
1132 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1133 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1134 CB_GETCURSEL, 0, 0);
1135 cbeend.iWhy = CBENF_DROPDOWN;
1137 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1140 /* if selection has changed the set the new current selection */
1141 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1142 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1143 infoPtr->selected = cursel;
1144 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1145 SetFocus(infoPtr->hwndCombo);
1151 * CB_GETCURSEL(Combo)
1152 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1155 * WM_GETTEXTLENGTH(Edit)
1157 * EM_SETSEL(Edit, 0,0)
1158 * WM_GETTEXTLENGTH(Edit)
1160 * EM_SETSEL(Edit, 0,len)
1161 * return WM_COMMAND to parent
1163 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1164 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1165 ERR("item %d not found. Problem!\n", oldItem);
1168 infoPtr->selected = oldItem;
1169 COMBOEX_SetEditText (infoPtr, item);
1170 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1174 * We have to change the handle since we are the control
1175 * issuing the message. IE4 depends on this.
1177 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1181 * from native trace:
1184 * WM_GETTEXT(Edit, 104)
1185 * CB_GETCURSEL(Combo) rets -1
1186 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1187 * CB_GETCURSEL(Combo)
1188 * InvalidateRect(Combo, 0, 0)
1191 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1192 if (infoPtr->flags & WCBE_ACTEDIT) {
1193 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1194 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1195 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1196 CB_GETCURSEL, 0, 0);
1197 cbeend.iWhy = CBENF_KILLFOCUS;
1199 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1200 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1202 /* possible CB_GETCURSEL */
1203 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1208 * We have to change the handle since we are the control
1209 * issuing the message. IE4 depends on this.
1210 * We also need to set the focus back to the Edit control
1211 * after passing the command to the parent of the ComboEx.
1213 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1214 if (infoPtr->hwndEdit)
1215 SetFocus(infoPtr->hwndEdit);
1222 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
1224 CBE_ITEMDATA *item, *olditem;
1225 NMCOMBOBOXEXW nmcit;
1228 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1229 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1231 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1233 olditem = infoPtr->items;
1234 i = infoPtr->nb_items - 1;
1236 if (i == dis->itemID) {
1237 infoPtr->items = infoPtr->items->next;
1243 /* find the prior item in the list */
1244 while (item->next && (i > dis->itemID)) {
1245 item = (CBE_ITEMDATA *)item->next;
1248 if (!item->next || (i != dis->itemID)) {
1249 ERR("COMBOBOXEX item structures broken. Please report!\n");
1252 olditem = item->next;
1253 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1255 infoPtr->nb_items--;
1257 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1258 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1259 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1261 COMBOEX_FreeText(olditem);
1262 COMCTL32_Free(olditem);
1268 static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
1270 WCHAR nil[] = { 0 };
1271 CBE_ITEMDATA *item = 0;
1277 COLORREF nbkc, ntxc, bkc, txc;
1278 int drawimage, drawstate, xioff;
1280 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1282 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1283 dis->CtlType, dis->CtlID);
1284 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1285 dis->itemID, dis->itemAction, dis->itemState);
1286 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1287 dis->hwndItem, dis->hDC, dis->rcItem.left,
1288 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1292 /* "itemID - Specifies the menu item identifier for a menu */
1293 /* item or the index of the item in a list box or combo box. */
1294 /* For an empty list box or combo box, this member can be -1. */
1295 /* This allows the application to draw only the focus */
1296 /* rectangle at the coordinates specified by the rcItem */
1297 /* member even though there are no items in the control. */
1298 /* This indicates to the user whether the list box or combo */
1299 /* box has the focus. How the bits are set in the itemAction */
1300 /* member determines whether the rectangle is to be drawn as */
1301 /* though the list box or combo box has the focus. */
1302 if (dis->itemID == 0xffffffff) {
1303 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1304 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1306 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1307 dis->rcItem.left, dis->rcItem.top,
1308 dis->rcItem.right, dis->rcItem.bottom);
1310 else if ((dis->CtlType == ODT_COMBOBOX) &&
1311 (dis->itemAction == ODA_DRAWENTIRE)) {
1312 /* draw of edit control data */
1316 RECT exrc, cbrc, edrc;
1317 GetWindowRect (infoPtr->hwndSelf, &exrc);
1318 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1319 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1320 if (infoPtr->hwndEdit)
1321 GetWindowRect (infoPtr->hwndEdit, &edrc);
1322 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1323 exrc.left, exrc.top, exrc.right, exrc.bottom,
1324 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1325 edrc.left, edrc.top, edrc.right, edrc.bottom);
1329 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1330 dis->rcItem.left, dis->rcItem.top,
1331 dis->rcItem.right, dis->rcItem.bottom,
1332 dis->itemAction, dis->itemState);
1337 /* If draw item is -1 (edit control) setup the item pointer */
1338 if (dis->itemID == 0xffffffff) {
1339 item = infoPtr->edit;
1341 if (infoPtr->hwndEdit) {
1344 /* free previous text of edit item */
1345 COMBOEX_FreeText(item);
1346 item->mask &= ~CBEIF_TEXT;
1347 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1348 item->mask |= CBEIF_TEXT;
1349 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1351 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1353 TRACE("edit control hwndEdit=%0x, text len=%d str=%s\n",
1354 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1360 /* if the item pointer is not set, then get the data and locate it */
1362 item = get_item_data(infoPtr, dis->itemID);
1363 if (item == (CBE_ITEMDATA *)CB_ERR) {
1364 ERR("invalid item for id %d \n", dis->itemID);
1369 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1371 xbase = CBE_STARTOFFSET;
1372 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1373 INT indent = item->iIndent;
1374 if (indent == I_INDENTCALLBACK) {
1376 ZeroMemory(&nmce, sizeof(nmce));
1377 nmce.ceItem.mask = CBEIF_INDENT;
1378 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1379 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1380 item->iIndent = nmce.ceItem.iIndent;
1381 indent = nmce.ceItem.iIndent;
1383 xbase += (indent * CBE_INDENT);
1387 drawstate = ILD_NORMAL;
1388 if (item->mask & CBEIF_IMAGE)
1389 drawimage = item->iImage;
1390 if (dis->itemState & ODS_COMBOEXLBOX) {
1391 /* drawing listbox entry */
1392 if (dis->itemState & ODS_SELECTED) {
1393 if (item->mask & CBEIF_SELECTEDIMAGE)
1394 drawimage = item->iSelectedImage;
1395 drawstate = ILD_SELECTED;
1398 /* drawing combo/edit entry */
1399 if (IsWindowVisible(infoPtr->hwndEdit)) {
1400 /* if we have an edit control, the slave the
1401 * selection state to the Edit focus state
1403 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1404 if (item->mask & CBEIF_SELECTEDIMAGE)
1405 drawimage = item->iSelectedImage;
1406 drawstate = ILD_SELECTED;
1409 /* if we don't have an edit control, use
1410 * the requested state.
1412 if (dis->itemState & ODS_SELECTED) {
1413 if (item->mask & CBEIF_SELECTEDIMAGE)
1414 drawimage = item->iSelectedImage;
1415 drawstate = ILD_SELECTED;
1420 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1422 iinfo.rcImage.left = iinfo.rcImage.right = 0;
1423 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1424 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1427 /* setup pointer to text to be drawn */
1428 str = COMBOEX_GetText(infoPtr, item);
1429 if (!str) str = nil;
1431 len = strlenW (str);
1432 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1434 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1435 int overlay = item->iOverlay;
1437 if (drawimage == I_IMAGECALLBACK) {
1439 ZeroMemory(&nmce, sizeof(nmce));
1440 nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
1441 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1442 if (drawstate == ILD_NORMAL) {
1443 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1444 drawimage = nmce.ceItem.iImage;
1445 } else if (drawstate == ILD_SELECTED) {
1446 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1447 drawimage = nmce.ceItem.iSelectedImage;
1448 } else ERR("Bad draw state = %d\n", drawstate);
1451 if (overlay == I_IMAGECALLBACK) {
1453 ZeroMemory(&nmce, sizeof(nmce));
1454 nmce.ceItem.mask = CBEIF_OVERLAY;
1455 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1456 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1457 item->iOverlay = nmce.ceItem.iOverlay;
1458 overlay = nmce.ceItem.iOverlay;
1461 if (drawimage >= 0 &&
1462 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1463 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1464 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1465 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1468 /* now draw the text */
1469 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1470 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1471 COLOR_HIGHLIGHT : COLOR_WINDOW);
1472 bkc = SetBkColor (dis->hDC, nbkc);
1473 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1474 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1475 txc = SetTextColor (dis->hDC, ntxc);
1477 y = dis->rcItem.top +
1478 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1480 rect.right = x + txtsize.cx;
1481 rect.top = dis->rcItem.top + 1;
1482 rect.bottom = dis->rcItem.bottom - 1;
1483 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1484 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1485 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1486 &rect, str, len, 0);
1487 SetBkColor (dis->hDC, bkc);
1488 SetTextColor (dis->hDC, txc);
1492 if (dis->itemAction & ODA_FOCUS) {
1493 rect.left = xbase + xioff - 1;
1494 rect.right = rect.left + txtsize.cx + 2;
1495 rect.top = dis->rcItem.top;
1496 rect.bottom = dis->rcItem.bottom;
1497 DrawFocusRect(dis->hDC, &rect);
1504 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1506 if (infoPtr->hwndCombo)
1507 DestroyWindow (infoPtr->hwndCombo);
1509 if (infoPtr->edit) {
1510 COMCTL32_Free (infoPtr->edit);
1514 if (infoPtr->items) {
1515 CBE_ITEMDATA *item, *next;
1517 item = infoPtr->items;
1519 next = (CBE_ITEMDATA *)item->next;
1520 COMBOEX_FreeText (item);
1521 COMCTL32_Free (item);
1527 if (infoPtr->defaultFont)
1528 DeleteObject (infoPtr->defaultFont);
1530 /* free comboex info data */
1531 COMCTL32_Free (infoPtr);
1532 SetWindowLongW (infoPtr->hwndSelf, 0, 0);
1537 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
1543 GetTextExtentPointA (hdc, "W", 1, &mysize);
1545 mis->itemHeight = mysize.cy + CBE_EXTRA;
1547 TRACE("adjusted height hwnd=%08x, height=%d\n",
1548 infoPtr->hwndSelf, mis->itemHeight);
1554 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1556 /* WARNING: The COMBOEX_INFO structure is not yet created */
1557 DWORD oldstyle, newstyle;
1559 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1560 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1561 if (newstyle != oldstyle) {
1562 TRACE("req style %08lx, reseting style %08lx\n",
1563 oldstyle, newstyle);
1564 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1570 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1572 if (lParam == NF_REQUERY) {
1573 INT i = SendMessageW(GetParent (infoPtr->hwndSelf),
1574 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
1575 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1577 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1581 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1583 TRACE("(width=%d, height=%d)\n", width, height);
1585 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1587 COMBOEX_AdjustEditPos (infoPtr);
1593 static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1595 RECT cbx_wrect, cbx_crect, cb_wrect;
1598 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1599 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1600 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1602 /* width is winpos value + border width of comboex */
1604 + (cbx_wrect.right-cbx_wrect.left)
1605 - (cbx_crect.right-cbx_crect.left);
1607 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1608 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1609 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1610 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1611 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1612 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1613 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1614 width, cb_wrect.bottom-cb_wrect.top);
1616 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1618 cb_wrect.bottom-cb_wrect.top,
1621 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1623 /* height is combo window height plus border width of comboex */
1624 height = (cb_wrect.bottom-cb_wrect.top)
1625 + (cbx_wrect.bottom-cbx_wrect.top)
1626 - (cbx_crect.bottom-cbx_crect.top);
1627 if (wp->cy < height) wp->cy = height;
1628 if (infoPtr->hwndEdit) {
1629 COMBOEX_AdjustEditPos (infoPtr);
1630 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1636 static inline int is_delimiter(WCHAR c)
1648 COMBOEX_PathWordBreakProc(LPWSTR lpch, int ichCurrent, int cch, int code)
1650 if (code == WB_ISDELIMITER) {
1651 return is_delimiter(lpch[ichCurrent]);
1653 int dir = (code == WB_LEFT) ? -1 : 1;
1654 for(; 0 <= ichCurrent && ichCurrent < cch; ichCurrent += dir)
1655 if (is_delimiter(lpch[ichCurrent])) return ichCurrent;
1660 static LRESULT WINAPI
1661 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1663 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1664 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1665 NMCBEENDEDITW cbeend;
1666 WCHAR edit_text[260];
1672 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1673 hwnd, uMsg, wParam, lParam, infoPtr);
1675 if (!infoPtr) return 0;
1681 /* handle (ignore) the return character */
1682 if (wParam == VK_RETURN) return 0;
1683 /* all other characters pass into the real Edit */
1684 return CallWindowProcW (infoPtr->prevEditWndProc,
1685 hwnd, uMsg, wParam, lParam);
1689 * The following was determined by traces of the native
1692 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1693 GetClientRect (hwnd, &rect);
1694 TRACE("erasing (%d,%d)-(%d,%d)\n",
1695 rect.left, rect.top, rect.right, rect.bottom);
1696 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1697 SetBkColor (hDC, obkc);
1698 return CallWindowProcW (infoPtr->prevEditWndProc,
1699 hwnd, uMsg, wParam, lParam);
1702 INT oldItem, selected, step = 1;
1705 switch ((INT)wParam)
1708 /* native version seems to do following for COMBOEX */
1710 * GetWindowTextA(Edit,&?, 0x104) x
1711 * CB_GETCURSEL to Combo rets -1 x
1712 * WM_NOTIFY to COMBOEX parent (rebar) x
1713 * (CBEN_ENDEDIT{A|W}
1714 * fChanged = FALSE x
1715 * inewSelection = -1 x
1718 * CB_GETCURSEL to Combo rets -1 x
1719 * InvalidateRect(Combo, 0) x
1720 * WM_SETTEXT to Edit x
1721 * EM_SETSEL to Edit (0,0) x
1722 * EM_SETSEL to Edit (0,-1) x
1723 * RedrawWindow(Combo, 0, 0, 5) x
1725 TRACE("special code for VK_ESCAPE\n");
1727 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1729 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1730 cbeend.fChanged = FALSE;
1731 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1732 CB_GETCURSEL, 0, 0);
1733 cbeend.iWhy = CBENF_ESCAPE;
1735 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1736 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1737 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1738 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1739 ERR("item %d not found. Problem!\n", oldItem);
1742 infoPtr->selected = oldItem;
1743 COMBOEX_SetEditText (infoPtr, item);
1744 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1749 /* native version seems to do following for COMBOEX */
1751 * GetWindowTextA(Edit,&?, 0x104) x
1752 * CB_GETCURSEL to Combo rets -1 x
1753 * CB_GETCOUNT to Combo rets 0
1755 * CB_GETITEMDATA to match
1756 * *** above 3 lines simulated by FindItem x
1757 * WM_NOTIFY to COMBOEX parent (rebar) x
1758 * (CBEN_ENDEDIT{A|W} x
1759 * fChanged = TRUE (-1) x
1760 * iNewSelection = -1 or selected x
1762 * iWhy = 2 (CBENF_RETURN) x
1763 * CB_GETCURSEL to Combo rets -1 x
1764 * if -1 send CB_SETCURSEL to Combo -1 x
1765 * InvalidateRect(Combo, 0, 0) x
1767 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1770 TRACE("special code for VK_RETURN\n");
1772 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1774 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1775 selected = SendMessageW (infoPtr->hwndCombo,
1776 CB_GETCURSEL, 0, 0);
1778 if (selected != -1) {
1779 cmp_func_t cmptext = get_cmp_func(infoPtr);
1780 item = COMBOEX_FindItem (infoPtr, selected);
1781 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1782 selected, debugstr_txt(item->pszText));
1783 TRACE("handling VK_RETURN, edittext=%s\n",
1784 debugstr_w(edit_text));
1785 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1786 /* strings not equal -- indicate edit has changed */
1791 cbeend.iNewSelection = selected;
1792 cbeend.fChanged = TRUE;
1793 cbeend.iWhy = CBENF_RETURN;
1794 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1795 /* abort the change, restore previous */
1796 TRACE("Notify requested abort of change\n");
1797 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1798 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1802 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1803 if (oldItem != -1) {
1804 /* if something is selected, then deselect it */
1805 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1808 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1809 SetFocus(infoPtr->hwndEdit);
1815 /* by default, step is 1 */
1816 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1817 if (oldItem >= 0 && oldItem + step >= 0)
1818 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1821 return CallWindowProcW (infoPtr->prevEditWndProc,
1822 hwnd, uMsg, wParam, lParam);
1828 /* remember the focus to set state of icon */
1829 lret = CallWindowProcW (infoPtr->prevEditWndProc,
1830 hwnd, uMsg, wParam, lParam);
1831 infoPtr->flags |= WCBE_EDITFOCUSED;
1836 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1838 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1839 if (infoPtr->flags & WCBE_ACTEDIT) {
1840 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1842 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1843 cbeend.fChanged = FALSE;
1844 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1845 CB_GETCURSEL, 0, 0);
1846 cbeend.iWhy = CBENF_KILLFOCUS;
1848 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1853 return CallWindowProcW (infoPtr->prevEditWndProc,
1854 hwnd, uMsg, wParam, lParam);
1860 static LRESULT WINAPI
1861 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1863 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1864 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1865 NMCBEENDEDITW cbeend;
1872 WCHAR edit_text[260];
1874 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1875 hwnd, uMsg, wParam, lParam, infoPtr);
1877 if (!infoPtr) return 0;
1884 * The only way this message should come is from the
1885 * child Listbox issuing the message. Flag this so
1886 * that ComboEx knows this is listbox.
1888 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1889 return CallWindowProcW (infoPtr->prevComboWndProc,
1890 hwnd, uMsg, wParam, lParam);
1894 * The following was determined by traces of the native
1897 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1898 GetClientRect (hwnd, &rect);
1899 TRACE("erasing (%d,%d)-(%d,%d)\n",
1900 rect.left, rect.top, rect.right, rect.bottom);
1901 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1902 SetBkColor (hDC, obkc);
1903 return CallWindowProcW (infoPtr->prevComboWndProc,
1904 hwnd, uMsg, wParam, lParam);
1908 * WM_NOTIFY to comboex parent (rebar)
1909 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1910 * CallWindowProc (previous)
1912 nmmse.dwItemSpec = 0;
1913 nmmse.dwItemData = 0;
1916 nmmse.dwHitInfo = lParam;
1917 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1918 return CallWindowProcW (infoPtr->prevComboWndProc,
1919 hwnd, uMsg, wParam, lParam);
1921 case WM_LBUTTONDOWN:
1922 GetClientRect (hwnd, &rect);
1923 rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1924 CB_GETITEMHEIGHT, -1, 0);
1925 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
1926 pt.x = LOWORD(lParam);
1927 pt.y = HIWORD(lParam);
1928 if (PtInRect(&rect, pt))
1929 return CallWindowProcW (infoPtr->prevComboWndProc,
1930 hwnd, uMsg, wParam, lParam);
1931 infoPtr->flags |= WCBE_MOUSECAPTURED;
1936 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1937 return CallWindowProcW (infoPtr->prevComboWndProc,
1938 hwnd, uMsg, wParam, lParam);
1940 infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1941 if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1942 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1944 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1949 if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1950 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
1951 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1952 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
1953 infoPtr->flags |= WCBE_MOUSEDRAGGED;
1955 return CallWindowProcW (infoPtr->prevComboWndProc,
1956 hwnd, uMsg, wParam, lParam);
1959 switch (HIWORD(wParam)) {
1962 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1971 * GetFocus() retns AA
1972 * GetWindowTextA(Edit)
1973 * CB_GETCURSEL(Combo) (got -1)
1974 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1975 * CB_GETCURSEL(Combo) (got -1)
1976 * InvalidateRect(Combo, 0, 0)
1977 * WM_KILLFOCUS(Combo, AA)
1980 focusedhwnd = GetFocus();
1981 if (infoPtr->flags & WCBE_ACTEDIT) {
1982 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1983 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1984 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1985 CB_GETCURSEL, 0, 0);
1986 cbeend.iWhy = CBENF_KILLFOCUS;
1988 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1989 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1991 /* possible CB_GETCURSEL */
1992 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1994 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
1995 (WPARAM)focusedhwnd, 0);
2000 * For EN_SETFOCUS this issues the same calls and messages
2001 * as the native seems to do.
2003 * for some cases however native does the following:
2004 * (noticed after SetFocus during LBUTTONDOWN on
2005 * on dropdown arrow)
2006 * WM_GETTEXTLENGTH (Edit);
2007 * WM_GETTEXT (Edit, len+1, str);
2008 * EM_SETSEL (Edit, 0, 0);
2009 * WM_GETTEXTLENGTH (Edit);
2010 * WM_GETTEXT (Edit, len+1, str);
2011 * EM_SETSEL (Edit, 0, len);
2012 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2016 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2017 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2018 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2019 infoPtr->flags |= WCBE_ACTEDIT;
2020 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2026 * For EN_CHANGE this issues the same calls and messages
2027 * as the native seems to do.
2029 WCHAR edit_text[260];
2031 cmp_func_t cmptext = get_cmp_func(infoPtr);
2033 INT selected = SendMessageW (infoPtr->hwndCombo,
2034 CB_GETCURSEL, 0, 0);
2036 /* lstrlenA( lastworkingURL ) */
2038 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2039 if (selected == -1) {
2040 lastwrk = infoPtr->edit->pszText;
2043 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2044 lastwrk = COMBOEX_GetText(infoPtr, item);
2047 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2048 selected, debugstr_w(lastwrk));
2049 TRACE("handling EN_CHANGE, edittext=%s\n",
2050 debugstr_w(edit_text));
2052 /* cmptext is between lastworkingURL and GetWindowText */
2053 if (cmptext (lastwrk, edit_text)) {
2054 /* strings not equal -- indicate edit has changed */
2055 infoPtr->flags |= WCBE_EDITCHG;
2057 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2058 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2066 * Therefore from traces there is no additional code here
2070 * Using native COMCTL32 gets the following:
2071 * 1 == SHDOCVW.DLL issues call/message
2072 * 2 == COMCTL32.DLL issues call/message
2073 * 3 == WINE issues call/message
2076 * for LBN_SELCHANGE:
2077 * 1 CB_GETCURSEL(ComboEx)
2078 * 1 CB_GETDROPPEDSTATE(ComboEx)
2079 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2080 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2081 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2082 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2083 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2084 * 3 ShowWindow(ComboLB, SW_HIDE)
2085 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2086 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2088 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2089 * ? LB_GETCURSEL <==|
2091 * ? LB_GETTEXT | Needs to be added to
2092 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2093 * ? LB_GETITEMDATA |
2094 * ? WM_DRAWITEM(ComboEx) <==|
2100 return CallWindowProcW (infoPtr->prevComboWndProc,
2101 hwnd, uMsg, wParam, lParam);
2107 static LRESULT WINAPI
2108 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2110 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2112 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2115 if (uMsg == WM_CREATE)
2116 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2117 if (uMsg == WM_NCCREATE)
2118 COMBOEX_NCCreate (hwnd);
2119 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2124 case CBEM_DELETEITEM:
2125 return COMBOEX_DeleteItem (infoPtr, wParam);
2127 case CBEM_GETCOMBOCONTROL:
2128 return infoPtr->hwndCombo;
2130 case CBEM_GETEDITCONTROL:
2131 return infoPtr->hwndEdit;
2133 case CBEM_GETEXTENDEDSTYLE:
2134 return infoPtr->dwExtStyle;
2136 case CBEM_GETIMAGELIST:
2137 return (LRESULT)infoPtr->himl;
2140 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2143 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2145 case CBEM_GETUNICODEFORMAT:
2146 return infoPtr->unicode;
2148 case CBEM_HASEDITCHANGED:
2149 return COMBOEX_HasEditChanged (infoPtr);
2151 case CBEM_INSERTITEMA:
2152 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2154 case CBEM_INSERTITEMW:
2155 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2157 case CBEM_SETEXSTYLE:
2158 case CBEM_SETEXTENDEDSTYLE:
2159 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2161 case CBEM_SETIMAGELIST:
2162 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2165 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2168 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2170 case CBEM_SETUNICODEFORMAT:
2171 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2173 /*case CBEM_SETWINDOWTHEME:
2174 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2178 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2180 /* Combo messages we are not sure if we need to process or just forward */
2181 case CB_GETDROPPEDCONTROLRECT:
2182 case CB_GETITEMHEIGHT:
2184 case CB_GETLBTEXTLEN:
2185 case CB_GETEXTENDEDUI:
2187 case CB_RESETCONTENT:
2188 case CB_SELECTSTRING:
2190 /* Combo messages OK to just forward to the regular COMBO */
2193 case CB_GETDROPPEDSTATE:
2194 case CB_SETDROPPEDWIDTH:
2195 case CB_SETEXTENDEDUI:
2196 case CB_SHOWDROPDOWN:
2197 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2199 /* Combo messages we need to process specially */
2200 case CB_FINDSTRINGEXACT:
2201 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2203 case CB_GETITEMDATA:
2204 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2207 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2209 case CB_SETITEMDATA:
2210 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD)lParam);
2212 case CB_SETITEMHEIGHT:
2213 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2217 /* Window messages passed to parent */
2219 return COMBOEX_Command (infoPtr, wParam, lParam);
2222 if (infoPtr->NtfUnicode)
2223 return SendMessageW (GetParent (hwnd), uMsg, wParam, lParam);
2225 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
2228 /* Window messages we need to process */
2230 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2233 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2236 return COMBOEX_Destroy (infoPtr);
2238 case WM_MEASUREITEM:
2239 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2241 case WM_NOTIFYFORMAT:
2242 return COMBOEX_NotifyFormat (infoPtr, lParam);
2245 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2247 case WM_WINDOWPOSCHANGING:
2248 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2251 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2252 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
2253 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2259 void COMBOEX_Register (void)
2263 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2264 wndClass.style = CS_GLOBALCLASS;
2265 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2266 wndClass.cbClsExtra = 0;
2267 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2268 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
2269 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2270 wndClass.lpszClassName = WC_COMBOBOXEXW;
2272 RegisterClassW (&wndClass);
2276 void COMBOEX_Unregister (void)
2278 UnregisterClassW (WC_COMBOBOXEXW, (HINSTANCE)NULL);