4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2000, 2001, 2002 Guy Albertelli <galberte@neo.lrun.com>
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 9, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
48 typedef struct _CBE_ITEMDATA
50 struct _CBE_ITEMDATA *next;
62 /* ComboBoxEx structure */
66 HWND hwndSelf; /* my own hwnd */
67 HWND hwndNotify; /* my parent hwnd */
70 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
71 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
73 INT selected; /* index of selected item */
74 DWORD flags; /* WINE internal flags */
77 INT nb_items; /* Number of items */
78 BOOL unicode; /* TRUE if this window is Unicode */
79 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
80 CBE_ITEMDATA *edit; /* item data for edit item */
81 CBE_ITEMDATA *items; /* Array of items */
84 /* internal flags in the COMBOEX_INFO structure */
85 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
86 * CBEN_BEGINEDIT issued
87 * but CBEN_ENDEDIT{A|W}
89 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
90 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
91 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
92 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
93 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
95 #define ID_CB_EDIT 1001
99 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
100 * the ComboEx version of the Combo Window Proc so that when the
101 * WM_DRAWITEM message is then passed to ComboEx, we know that this
102 * particular WM_DRAWITEM message is for listbox only items. Any messasges
103 * without this flag is then for the Edit control field.
105 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
106 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
108 #define ODS_COMBOEXLBOX 0x4000
112 /* Height in pixels of control over the amount of the selected font */
115 /* Indent amount per MS documentation */
116 #define CBE_INDENT 10
118 /* Offset in pixels from left side for start of image or text */
119 #define CBE_STARTOFFSET 6
121 /* Offset between image and text */
124 #define COMBOEX_SUBCLASS_PROP "CCComboEx32SubclassInfo"
125 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongPtrW (hwnd, 0))
128 /* Things common to the entire DLL */
129 static LRESULT WINAPI COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
130 static LRESULT WINAPI COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
131 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
132 typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
134 inline static BOOL is_textW(LPCWSTR str)
136 return str && str != LPSTR_TEXTCALLBACKW;
139 inline static BOOL is_textA(LPCSTR str)
141 return str && str != LPSTR_TEXTCALLBACKA;
144 inline static LPCSTR debugstr_txt(LPCWSTR str)
146 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
147 return debugstr_w(str);
150 static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
152 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
153 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
154 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
155 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
156 if (item->mask & CBEIF_TEXT)
157 TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
161 static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
163 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
164 input->mask, input->iItem, input->pszText, input->cchTextMax,
166 if (input->mask & CBEIF_TEXT)
167 TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
168 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
169 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
173 inline static CBE_ITEMDATA *get_item_data(COMBOEX_INFO *infoPtr, INT index)
175 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
179 inline static cmp_func_t get_cmp_func(COMBOEX_INFO *infoPtr)
181 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
184 static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
186 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
187 hdr->hwndFrom = infoPtr->hwndSelf;
189 if (infoPtr->NtfUnicode)
190 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
192 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
197 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
199 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
200 if (infoPtr->NtfUnicode)
201 return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
203 LPWSTR wstr = hdr->ceItem.pszText;
207 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
208 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
210 astr = (LPSTR)Alloc ((len + 1)*sizeof(CHAR));
212 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
213 hdr->ceItem.pszText = (LPWSTR)astr;
217 if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
218 else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
219 else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
221 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
223 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
224 hdr->ceItem.pszText = wstr;
226 if (astr) Free(astr);
233 static INT COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
235 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
236 if (infoPtr->NtfUnicode) {
237 lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
238 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
242 memcpy (&neea.hdr, &neew->hdr, sizeof(NMHDR));
243 neea.fChanged = neew->fChanged;
244 neea.iNewSelection = neew->iNewSelection;
245 WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
246 neea.iWhy = neew->iWhy;
248 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
253 static void COMBOEX_NotifyDragBegin(COMBOEX_INFO *infoPtr, LPCWSTR wstr)
255 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
256 if (infoPtr->NtfUnicode) {
257 NMCBEDRAGBEGINW ndbw;
260 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
261 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
263 NMCBEDRAGBEGINA ndba;
266 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
268 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
273 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
275 if (is_textW(item->pszText)) Free(item->pszText);
277 if (item->pszTemp) Free(item->pszTemp);
282 static LPCWSTR COMBOEX_GetText(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
288 if (item->pszText != LPSTR_TEXTCALLBACKW)
289 return item->pszText;
291 ZeroMemory(&nmce, sizeof(nmce));
292 nmce.ceItem.mask = CBEIF_TEXT;
293 nmce.ceItem.lParam = item->lParam;
294 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
296 if (is_textW(nmce.ceItem.pszText)) {
297 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
298 buf = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
300 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
301 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
302 COMBOEX_FreeText(item);
305 if (item->pszTemp) Free(item->pszTemp);
310 text = nmce.ceItem.pszText;
312 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
313 item->pszText = text;
318 static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
323 mydc = GetDC (0); /* why the entire screen???? */
324 nfont = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
325 ofont = (HFONT) SelectObject (mydc, nfont);
326 GetTextExtentPointA (mydc, "A", 1, size);
327 SelectObject (mydc, ofont);
329 TRACE("selected font hwnd=%p, height=%ld\n", nfont, size->cy);
333 static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
335 if (cit->mask & CBEIF_TEXT) {
337 * when given a text buffer actually use that buffer
340 if (is_textW(item->pszText))
341 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
345 cit->pszText = item->pszText;
346 cit->cchTextMax = item->cchTextMax;
349 if (cit->mask & CBEIF_IMAGE)
350 cit->iImage = item->iImage;
351 if (cit->mask & CBEIF_SELECTEDIMAGE)
352 cit->iSelectedImage = item->iSelectedImage;
353 if (cit->mask & CBEIF_OVERLAY)
354 cit->iOverlay = item->iOverlay;
355 if (cit->mask & CBEIF_INDENT)
356 cit->iIndent = item->iIndent;
357 if (cit->mask & CBEIF_LPARAM)
358 cit->lParam = item->lParam;
362 static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
365 INT x, y, w, h, xioff;
368 if (!infoPtr->hwndEdit) return;
370 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
372 iinfo.rcImage.left = iinfo.rcImage.right = 0;
373 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
374 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
377 GetClientRect (infoPtr->hwndCombo, &rect);
378 InflateRect (&rect, -2, -2);
379 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
381 /* reposition the Edit control based on whether icon exists */
382 COMBOEX_GetComboFontSize (infoPtr, &mysize);
383 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
384 x = xioff + CBE_STARTOFFSET + 1;
385 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
387 y = rect.bottom - h - 1;
389 TRACE("Combo client (%ld,%ld)-(%ld,%ld), setting Edit to (%d,%d)-(%d,%d)\n",
390 rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
391 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
392 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
396 static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
402 COMBOEX_GetComboFontSize (infoPtr, &mysize);
403 cy = mysize.cy + CBE_EXTRA;
404 if (infoPtr->himl && ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo)) {
405 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
406 TRACE("upgraded height due to image: height=%ld\n", cy);
408 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)cy);
409 if (infoPtr->hwndCombo) {
410 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
411 (WPARAM) 0, (LPARAM) cy);
412 if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
414 if (GetWindowRect(infoPtr->hwndCombo, &comboRect)) {
416 if (GetWindowRect(infoPtr->hwndSelf, &ourRect)) {
417 if (comboRect.bottom > ourRect.bottom) {
418 POINT pt = { ourRect.left, ourRect.top };
419 if (ScreenToClient(infoPtr->hwndSelf, &pt))
420 MoveWindow( infoPtr->hwndSelf, pt.x, pt.y, ourRect.right - ourRect.left,
421 comboRect.bottom - comboRect.top, FALSE);
430 static void COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
432 if (!infoPtr->hwndEdit) return;
433 /* native issues the following messages to the {Edit} control */
434 /* WM_SETTEXT (0,addr) */
435 /* EM_SETSEL32 (0,0) */
436 /* EM_SETSEL32 (0,-1) */
437 if (item->mask & CBEIF_TEXT) {
438 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
439 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
440 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
445 static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
450 if ((index > infoPtr->nb_items) || (index < -1))
453 return infoPtr->edit;
454 item = infoPtr->items;
455 i = infoPtr->nb_items - 1;
457 /* find the item in the list */
458 while (item && (i > index)) {
462 if (!item || (i != index)) {
463 ERR("COMBOBOXEX item structures broken. Please report!\n");
470 static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO *infoPtr)
472 return infoPtr->hwndEdit ? TRUE : FALSE;
476 /* *** CBEM_xxx message support *** */
479 static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
483 TRACE("(index=%d)\n", index);
485 /* if item number requested does not exist then return failure */
486 if ((index > infoPtr->nb_items) || (index < 0)) return CB_ERR;
487 if (!(item = COMBOEX_FindItem(infoPtr, index))) return CB_ERR;
489 /* doing this will result in WM_DELETEITEM being issued */
490 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
492 return infoPtr->nb_items;
496 static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
498 INT index = cit->iItem;
503 /* if item number requested does not exist then return failure */
504 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
506 /* if the item is the edit control and there is no edit control, skip */
507 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
509 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
511 COMBOEX_CopyItem (item, cit);
517 static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
519 COMBOBOXEXITEMW tmpcit;
523 tmpcit.mask = cit->mask;
524 tmpcit.iItem = cit->iItem;
526 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
528 if (is_textW(tmpcit.pszText) && cit->pszText)
529 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
530 cit->pszText, cit->cchTextMax, NULL, NULL);
531 else if (cit->pszText) cit->pszText[0] = 0;
532 else cit->pszText = (LPSTR)tmpcit.pszText;
534 cit->iImage = tmpcit.iImage;
535 cit->iSelectedImage = tmpcit.iSelectedImage;
536 cit->iOverlay = tmpcit.iOverlay;
537 cit->iIndent = tmpcit.iIndent;
538 cit->lParam = tmpcit.lParam;
544 inline static BOOL COMBOEX_HasEditChanged (COMBOEX_INFO *infoPtr)
546 return COMBOEX_HasEdit(infoPtr) &&
547 (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
551 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
559 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
561 /* get real index of item to insert */
563 if (index == -1) index = infoPtr->nb_items;
564 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
566 /* get zero-filled space and chain it in */
567 if(!(item = (CBE_ITEMDATA *)Alloc (sizeof(*item)))) return -1;
569 /* locate position to insert new item in */
570 if (index == infoPtr->nb_items) {
571 /* fast path for iItem = -1 */
572 item->next = infoPtr->items;
573 infoPtr->items = item;
576 INT i = infoPtr->nb_items-1;
577 CBE_ITEMDATA *moving = infoPtr->items;
579 while ((i > index) && moving) {
580 moving = moving->next;
584 ERR("COMBOBOXEX item structures broken. Please report!\n");
588 item->next = moving->next;
592 /* fill in our hidden item structure */
593 item->mask = cit->mask;
594 if (item->mask & CBEIF_TEXT) {
597 if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
599 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
600 if (!item->pszText) {
604 strcpyW (item->pszText, cit->pszText);
606 else if (cit->pszText == LPSTR_TEXTCALLBACKW)
607 item->pszText = LPSTR_TEXTCALLBACKW;
608 item->cchTextMax = cit->cchTextMax;
610 if (item->mask & CBEIF_IMAGE)
611 item->iImage = cit->iImage;
612 if (item->mask & CBEIF_SELECTEDIMAGE)
613 item->iSelectedImage = cit->iSelectedImage;
614 if (item->mask & CBEIF_OVERLAY)
615 item->iOverlay = cit->iOverlay;
616 if (item->mask & CBEIF_INDENT)
617 item->iIndent = cit->iIndent;
618 if (item->mask & CBEIF_LPARAM)
619 item->lParam = cit->lParam;
622 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
624 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
625 (WPARAM)cit->iItem, (LPARAM)item);
627 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
628 COMBOEX_CopyItem (item, &nmcit.ceItem);
629 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
636 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
638 COMBOBOXEXITEMW citW;
642 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
643 if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
644 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
645 wstr = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
646 if (!wstr) return -1;
647 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
650 ret = COMBOEX_InsertItemW(infoPtr, &citW);
652 if (wstr) Free(wstr);
659 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
663 TRACE("(mask=x%08lx, style=0x%08lx)\n", mask, style);
665 dwTemp = infoPtr->dwExtStyle;
668 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
670 infoPtr->dwExtStyle = style;
672 /* see if we need to change the word break proc on the edit */
673 if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC)
674 SetPathWordBreakProc(infoPtr->hwndEdit,
675 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ? TRUE : FALSE);
677 /* test if the control's appearance has changed */
678 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
679 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
680 /* if state of EX_NOEDITIMAGE changes, invalidate all */
681 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
682 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
683 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
684 COMBOEX_AdjustEditPos (infoPtr);
685 if (infoPtr->hwndEdit)
686 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
693 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
695 HIMAGELIST himlTemp = infoPtr->himl;
699 infoPtr->himl = himl;
701 COMBOEX_ReSize (infoPtr);
702 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
704 /* reposition the Edit control based on whether icon exists */
705 COMBOEX_AdjustEditPos (infoPtr);
709 static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
711 INT index = cit->iItem;
714 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
716 /* if item number requested does not exist then return failure */
717 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
719 /* if the item is the edit control and there is no edit control, skip */
720 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
722 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
724 /* add/change stuff to the internal item structure */
725 item->mask |= cit->mask;
726 if (cit->mask & CBEIF_TEXT) {
729 COMBOEX_FreeText(item);
730 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
732 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
733 if (!item->pszText) return FALSE;
734 strcpyW(item->pszText, cit->pszText);
735 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
736 item->pszText = LPSTR_TEXTCALLBACKW;
737 item->cchTextMax = cit->cchTextMax;
739 if (cit->mask & CBEIF_IMAGE)
740 item->iImage = cit->iImage;
741 if (cit->mask & CBEIF_SELECTEDIMAGE)
742 item->iSelectedImage = cit->iSelectedImage;
743 if (cit->mask & CBEIF_OVERLAY)
744 item->iOverlay = cit->iOverlay;
745 if (cit->mask & CBEIF_INDENT)
746 item->iIndent = cit->iIndent;
747 if (cit->mask & CBEIF_LPARAM)
748 cit->lParam = cit->lParam;
750 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
752 /* if original request was to update edit control, do some fast foot work */
753 if (cit->iItem == -1) {
754 COMBOEX_SetEditText (infoPtr, item);
755 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
760 static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
762 COMBOBOXEXITEMW citW;
766 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
767 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
768 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
769 wstr = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
770 if (!wstr) return FALSE;
771 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
774 ret = COMBOEX_SetItemW(infoPtr, &citW);
776 if (wstr) Free(wstr);
782 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
784 BOOL bTemp = infoPtr->unicode;
786 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
788 infoPtr->unicode = value;
794 /* *** CB_xxx message support *** */
797 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
800 cmp_func_t cmptext = get_cmp_func(infoPtr);
801 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
803 /* now search from after starting loc and wrapping back to start */
804 for(i=start+1; i<count; i++) {
805 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
806 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
808 for(i=0; i<=start; i++) {
809 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
810 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
816 static DWORD COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
818 CBE_ITEMDATA *item1, *item2;
821 item1 = get_item_data(infoPtr, index);
822 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
823 item2 = COMBOEX_FindItem (infoPtr, index);
824 if (item2 != item1) {
825 ERR("data structures damaged!\n");
828 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
829 TRACE("returning 0x%08lx\n", ret);
832 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
838 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
843 if (!(item = COMBOEX_FindItem(infoPtr, index)))
844 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
846 TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
847 infoPtr->selected = index;
849 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
850 COMBOEX_SetEditText (infoPtr, item);
855 static DWORD COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD data)
857 CBE_ITEMDATA *item1, *item2;
859 item1 = get_item_data(infoPtr, index);
860 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
861 item2 = COMBOEX_FindItem (infoPtr, index);
862 if (item2 != item1) {
863 ERR("data structures damaged!\n");
866 item1->mask |= CBEIF_LPARAM;
867 item1->lParam = data;
868 TRACE("setting lparam to 0x%08lx\n", data);
871 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
872 return (LRESULT)item1;
876 static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
878 RECT cb_wrect, cbx_wrect, cbx_crect;
880 /* First, lets forward the message to the normal combo control
881 just like Windows. */
882 if (infoPtr->hwndCombo)
883 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
884 index, height) == CB_ERR) return CB_ERR;
886 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
887 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
888 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
889 /* the height of comboex as height of the combo + comboex border */
890 height = cb_wrect.bottom-cb_wrect.top
891 + cbx_wrect.bottom-cbx_wrect.top
892 - (cbx_crect.bottom-cbx_crect.top);
893 TRACE("EX window=(%ld,%ld)-(%ld,%ld), client=(%ld,%ld)-(%ld,%ld)\n",
894 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
895 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
896 TRACE("CB window=(%ld,%ld)-(%ld,%ld), EX setting=(0,0)-(%ld,%d)\n",
897 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
898 cbx_wrect.right-cbx_wrect.left, height);
899 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
900 cbx_wrect.right-cbx_wrect.left, height,
901 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
907 /* *** WM_xxx message support *** */
910 static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
912 static const WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
913 static const WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
914 static const WCHAR NIL[] = { 0 };
915 COMBOEX_INFO *infoPtr;
917 RECT wnrc1, clrc1, cmbwrc;
920 /* allocate memory for info structure */
921 infoPtr = (COMBOEX_INFO *)Alloc (sizeof(COMBOEX_INFO));
922 if (!infoPtr) return -1;
924 /* initialize info structure */
925 /* note that infoPtr is allocated zero-filled */
927 infoPtr->hwndSelf = hwnd;
928 infoPtr->selected = -1;
930 infoPtr->unicode = IsWindowUnicode (hwnd);
931 infoPtr->hwndNotify = cs->hwndParent;
933 i = SendMessageW(infoPtr->hwndNotify, 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 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
942 /* create combo box */
943 GetWindowRect(hwnd, &wnrc1);
944 GetClientRect(hwnd, &clrc1);
945 TRACE("EX window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld)\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) GetWindowLongPtrW (hwnd, GWLP_ID),
965 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_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)SetWindowLongPtrW(infoPtr->hwndCombo,
981 GWLP_WNDPROC, (DWORD_PTR)COMBOEX_ComboWndProc);
982 infoPtr->font = (HFONT)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) GetWindowLongPtrW (hwnd, GWLP_ID),
995 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
997 /* native does the following at this point according to trace:
998 * GetWindowThreadProcessId(hwndEdit,0)
999 * GetCurrentThreadId()
1000 * GetWindowThreadProcessId(hwndEdit, &???)
1001 * GetCurrentProcessId()
1005 * Setup a property to hold the pointer to the COMBOBOXEX
1008 SetPropA(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
1009 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hwndEdit,
1010 GWLP_WNDPROC, (DWORD_PTR)COMBOEX_EditWndProc);
1011 infoPtr->font = (HFONT)SendMessageW(infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1015 * Locate the default font if necessary and then set it in
1016 * all associated controls
1018 if (!infoPtr->font) {
1019 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1021 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1023 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1024 if (infoPtr->hwndEdit) {
1025 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1026 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1029 COMBOEX_ReSize (infoPtr);
1031 /* Above is fairly certain, below is much less certain. */
1033 GetWindowRect(hwnd, &wnrc1);
1034 GetClientRect(hwnd, &clrc1);
1035 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1036 TRACE("EX window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld) CB wnd=(%ld,%ld)-(%ld,%ld)\n",
1037 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1038 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1039 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1040 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1041 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1042 SWP_NOACTIVATE | SWP_NOREDRAW);
1044 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1045 TRACE("CB window=(%ld,%ld)-(%ld,%ld)\n",
1046 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1047 SetWindowPos(hwnd, HWND_TOP,
1048 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1049 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1051 COMBOEX_AdjustEditPos (infoPtr);
1054 * Create an item structure to represent the data in the
1055 * EDIT control. It is allocated zero-filled.
1057 infoPtr->edit = (CBE_ITEMDATA *)Alloc (sizeof (CBE_ITEMDATA));
1058 if (!infoPtr->edit) {
1059 COMBOEX_Destroy(infoPtr);
1067 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1070 INT command = HIWORD(wParam);
1071 CBE_ITEMDATA *item = 0;
1073 INT cursel, n, oldItem;
1074 NMCBEENDEDITW cbeend;
1076 HWND parent = infoPtr->hwndNotify;
1078 TRACE("for command %d\n", command);
1083 SetFocus (infoPtr->hwndCombo);
1084 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1085 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1088 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1090 * from native trace of first dropdown after typing in URL in IE4
1091 * CB_GETCURSEL(Combo)
1092 * GetWindowText(Edit)
1093 * CB_GETCURSEL(Combo)
1094 * CB_GETCOUNT(Combo)
1095 * CB_GETITEMDATA(Combo, n)
1096 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1097 * CB_GETCURSEL(Combo)
1098 * CB_SETCURSEL(COMBOEX, n)
1100 * the rest is supposition
1102 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1103 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1104 InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1105 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1107 cmp_func_t cmptext = get_cmp_func(infoPtr);
1108 /* find match from edit against those in Combobox */
1109 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1110 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1111 for (cursel = 0; cursel < n; cursel++){
1112 item = get_item_data(infoPtr, cursel);
1113 if ((INT)item == CB_ERR) break;
1114 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1116 if ((cursel == n) || ((INT)item == CB_ERR)) {
1117 TRACE("failed to find match??? item=%p cursel=%d\n",
1119 if (infoPtr->hwndEdit)
1120 SetFocus(infoPtr->hwndEdit);
1125 item = get_item_data(infoPtr, cursel);
1126 if ((INT)item == CB_ERR) {
1127 TRACE("failed to find match??? item=%p cursel=%d\n",
1129 if (infoPtr->hwndEdit)
1130 SetFocus(infoPtr->hwndEdit);
1135 /* Save flags for testing and reset them */
1136 oldflags = infoPtr->flags;
1137 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1139 if (oldflags & WCBE_ACTEDIT) {
1140 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1141 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1142 CB_GETCURSEL, 0, 0);
1143 cbeend.iWhy = CBENF_DROPDOWN;
1145 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1148 /* if selection has changed the set the new current selection */
1149 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1150 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1151 infoPtr->selected = cursel;
1152 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1153 SetFocus(infoPtr->hwndCombo);
1159 * CB_GETCURSEL(Combo)
1160 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1163 * WM_GETTEXTLENGTH(Edit)
1165 * EM_SETSEL(Edit, 0,0)
1166 * WM_GETTEXTLENGTH(Edit)
1168 * EM_SETSEL(Edit, 0,len)
1169 * return WM_COMMAND to parent
1171 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1172 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1173 ERR("item %d not found. Problem!\n", oldItem);
1176 infoPtr->selected = oldItem;
1177 COMBOEX_SetEditText (infoPtr, item);
1178 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1182 * We have to change the handle since we are the control
1183 * issuing the message. IE4 depends on this.
1185 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1189 * from native trace:
1192 * WM_GETTEXT(Edit, 104)
1193 * CB_GETCURSEL(Combo) rets -1
1194 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1195 * CB_GETCURSEL(Combo)
1196 * InvalidateRect(Combo, 0, 0)
1199 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1200 if (infoPtr->flags & WCBE_ACTEDIT) {
1201 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1202 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1203 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1204 CB_GETCURSEL, 0, 0);
1205 cbeend.iWhy = CBENF_KILLFOCUS;
1207 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1208 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1210 /* possible CB_GETCURSEL */
1211 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1216 * We have to change the handle since we are the control
1217 * issuing the message. IE4 depends on this.
1218 * We also need to set the focus back to the Edit control
1219 * after passing the command to the parent of the ComboEx.
1221 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1222 if (infoPtr->hwndEdit)
1223 SetFocus(infoPtr->hwndEdit);
1230 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
1232 CBE_ITEMDATA *item, *olditem;
1233 NMCOMBOBOXEXW nmcit;
1236 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1237 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1239 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1241 olditem = infoPtr->items;
1242 i = infoPtr->nb_items - 1;
1244 if (i == dis->itemID) {
1245 infoPtr->items = infoPtr->items->next;
1251 /* find the prior item in the list */
1252 while (item->next && (i > dis->itemID)) {
1256 if (!item->next || (i != dis->itemID)) {
1257 ERR("COMBOBOXEX item structures broken. Please report!\n");
1260 olditem = item->next;
1261 item->next = item->next->next;
1263 infoPtr->nb_items--;
1265 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1266 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1267 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1269 COMBOEX_FreeText(olditem);
1276 static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
1278 static const WCHAR nil[] = { 0 };
1279 CBE_ITEMDATA *item = 0;
1285 COLORREF nbkc, ntxc, bkc, txc;
1286 int drawimage, drawstate, xioff;
1288 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1290 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1291 dis->CtlType, dis->CtlID);
1292 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1293 dis->itemID, dis->itemAction, dis->itemState);
1294 TRACE("hWnd=%p hDC=%p (%ld,%ld)-(%ld,%ld) itemData=0x%08lx\n",
1295 dis->hwndItem, dis->hDC, dis->rcItem.left,
1296 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1300 /* "itemID - Specifies the menu item identifier for a menu */
1301 /* item or the index of the item in a list box or combo box. */
1302 /* For an empty list box or combo box, this member can be -1. */
1303 /* This allows the application to draw only the focus */
1304 /* rectangle at the coordinates specified by the rcItem */
1305 /* member even though there are no items in the control. */
1306 /* This indicates to the user whether the list box or combo */
1307 /* box has the focus. How the bits are set in the itemAction */
1308 /* member determines whether the rectangle is to be drawn as */
1309 /* though the list box or combo box has the focus. */
1310 if (dis->itemID == 0xffffffff) {
1311 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1312 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1314 TRACE("drawing item -1 special focus, rect=(%ld,%ld)-(%ld,%ld)\n",
1315 dis->rcItem.left, dis->rcItem.top,
1316 dis->rcItem.right, dis->rcItem.bottom);
1318 else if ((dis->CtlType == ODT_COMBOBOX) &&
1319 (dis->itemAction == ODA_DRAWENTIRE)) {
1320 /* draw of edit control data */
1324 RECT exrc, cbrc, edrc;
1325 GetWindowRect (infoPtr->hwndSelf, &exrc);
1326 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1327 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1328 if (infoPtr->hwndEdit)
1329 GetWindowRect (infoPtr->hwndEdit, &edrc);
1330 TRACE("window rects ex=(%ld,%ld)-(%ld,%ld), cb=(%ld,%ld)-(%ld,%ld), ed=(%ld,%ld)-(%ld,%ld)\n",
1331 exrc.left, exrc.top, exrc.right, exrc.bottom,
1332 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1333 edrc.left, edrc.top, edrc.right, edrc.bottom);
1337 ERR("NOT drawing item -1 special focus, rect=(%ld,%ld)-(%ld,%ld), action=%08x, state=%08x\n",
1338 dis->rcItem.left, dis->rcItem.top,
1339 dis->rcItem.right, dis->rcItem.bottom,
1340 dis->itemAction, dis->itemState);
1345 /* If draw item is -1 (edit control) setup the item pointer */
1346 if (dis->itemID == 0xffffffff) {
1347 item = infoPtr->edit;
1349 if (infoPtr->hwndEdit) {
1352 /* free previous text of edit item */
1353 COMBOEX_FreeText(item);
1354 item->mask &= ~CBEIF_TEXT;
1355 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1356 item->mask |= CBEIF_TEXT;
1357 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
1359 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1361 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1362 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1368 /* if the item pointer is not set, then get the data and locate it */
1370 item = get_item_data(infoPtr, dis->itemID);
1371 if (item == (CBE_ITEMDATA *)CB_ERR) {
1372 ERR("invalid item for id %d \n", dis->itemID);
1377 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1379 xbase = CBE_STARTOFFSET;
1380 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1381 INT indent = item->iIndent;
1382 if (indent == I_INDENTCALLBACK) {
1384 ZeroMemory(&nmce, sizeof(nmce));
1385 nmce.ceItem.mask = CBEIF_INDENT;
1386 nmce.ceItem.lParam = item->lParam;
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 nmce.ceItem.lParam = item->lParam;
1451 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1452 if (drawstate == ILD_NORMAL) {
1453 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1454 drawimage = nmce.ceItem.iImage;
1455 } else if (drawstate == ILD_SELECTED) {
1456 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1457 drawimage = nmce.ceItem.iSelectedImage;
1458 } else ERR("Bad draw state = %d\n", drawstate);
1461 if (overlay == I_IMAGECALLBACK) {
1463 ZeroMemory(&nmce, sizeof(nmce));
1464 nmce.ceItem.mask = CBEIF_OVERLAY;
1465 nmce.ceItem.lParam = item->lParam;
1466 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1467 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1468 item->iOverlay = nmce.ceItem.iOverlay;
1469 overlay = nmce.ceItem.iOverlay;
1472 if (drawimage >= 0 &&
1473 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1474 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1475 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1476 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1479 /* now draw the text */
1480 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1481 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1482 COLOR_HIGHLIGHT : COLOR_WINDOW);
1483 bkc = SetBkColor (dis->hDC, nbkc);
1484 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1485 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1486 txc = SetTextColor (dis->hDC, ntxc);
1488 y = dis->rcItem.top +
1489 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1491 rect.right = x + txtsize.cx;
1492 rect.top = dis->rcItem.top + 1;
1493 rect.bottom = dis->rcItem.bottom - 1;
1494 TRACE("drawing item %d text, rect=(%ld,%ld)-(%ld,%ld)\n",
1495 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1496 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1497 &rect, str, len, 0);
1498 SetBkColor (dis->hDC, bkc);
1499 SetTextColor (dis->hDC, txc);
1503 if (dis->itemAction & ODA_FOCUS) {
1504 rect.left = xbase + xioff - 1;
1505 rect.right = rect.left + txtsize.cx + 2;
1506 rect.top = dis->rcItem.top;
1507 rect.bottom = dis->rcItem.bottom;
1508 DrawFocusRect(dis->hDC, &rect);
1515 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1517 if (infoPtr->hwndCombo)
1518 DestroyWindow (infoPtr->hwndCombo);
1520 if (infoPtr->edit) {
1521 Free (infoPtr->edit);
1525 if (infoPtr->items) {
1526 CBE_ITEMDATA *item, *next;
1528 item = infoPtr->items;
1531 COMBOEX_FreeText (item);
1538 if (infoPtr->defaultFont)
1539 DeleteObject (infoPtr->defaultFont);
1541 /* free comboex info data */
1543 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1548 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
1554 GetTextExtentPointA (hdc, "W", 1, &mysize);
1556 mis->itemHeight = mysize.cy + CBE_EXTRA;
1558 TRACE("adjusted height hwnd=%p, height=%d\n",
1559 infoPtr->hwndSelf, mis->itemHeight);
1565 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1567 /* WARNING: The COMBOEX_INFO structure is not yet created */
1568 DWORD oldstyle, newstyle;
1570 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1571 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL | WS_BORDER);
1572 if (newstyle != oldstyle) {
1573 TRACE("req style %08lx, reseting style %08lx\n",
1574 oldstyle, newstyle);
1575 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1581 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1583 if (lParam == NF_REQUERY) {
1584 INT i = SendMessageW(infoPtr->hwndNotify,
1585 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1586 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1588 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1592 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1594 TRACE("(width=%d, height=%d)\n", width, height);
1596 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1598 COMBOEX_AdjustEditPos (infoPtr);
1604 static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1606 RECT cbx_wrect, cbx_crect, cb_wrect;
1609 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1610 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1611 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1613 /* width is winpos value + border width of comboex */
1615 + (cbx_wrect.right-cbx_wrect.left)
1616 - (cbx_crect.right-cbx_crect.left);
1618 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1619 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1620 TRACE("EX window=(%ld,%ld)-(%ld,%ld), client=(%ld,%ld)-(%ld,%ld)\n",
1621 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1622 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1623 TRACE("CB window=(%ld,%ld)-(%ld,%ld), EX setting=(0,0)-(%d,%ld)\n",
1624 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1625 width, cb_wrect.bottom-cb_wrect.top);
1627 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1629 cb_wrect.bottom-cb_wrect.top,
1632 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1634 /* height is combo window height plus border width of comboex */
1635 height = (cb_wrect.bottom-cb_wrect.top)
1636 + (cbx_wrect.bottom-cbx_wrect.top)
1637 - (cbx_crect.bottom-cbx_crect.top);
1638 if (wp->cy < height) wp->cy = height;
1639 if (infoPtr->hwndEdit) {
1640 COMBOEX_AdjustEditPos (infoPtr);
1641 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1647 static LRESULT WINAPI
1648 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1650 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1651 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1652 NMCBEENDEDITW cbeend;
1653 WCHAR edit_text[260];
1659 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1660 hwnd, uMsg, wParam, lParam, infoPtr);
1662 if (!infoPtr) return 0;
1668 /* handle (ignore) the return character */
1669 if (wParam == VK_RETURN) return 0;
1670 /* all other characters pass into the real Edit */
1671 return CallWindowProcW (infoPtr->prevEditWndProc,
1672 hwnd, uMsg, wParam, lParam);
1676 * The following was determined by traces of the native
1679 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1680 GetClientRect (hwnd, &rect);
1681 TRACE("erasing (%ld,%ld)-(%ld,%ld)\n",
1682 rect.left, rect.top, rect.right, rect.bottom);
1683 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1684 SetBkColor (hDC, obkc);
1685 return CallWindowProcW (infoPtr->prevEditWndProc,
1686 hwnd, uMsg, wParam, lParam);
1689 INT oldItem, selected, step = 1;
1692 switch ((INT)wParam)
1695 /* native version seems to do following for COMBOEX */
1697 * GetWindowTextA(Edit,&?, 0x104) x
1698 * CB_GETCURSEL to Combo rets -1 x
1699 * WM_NOTIFY to COMBOEX parent (rebar) x
1700 * (CBEN_ENDEDIT{A|W}
1701 * fChanged = FALSE x
1702 * inewSelection = -1 x
1705 * CB_GETCURSEL to Combo rets -1 x
1706 * InvalidateRect(Combo, 0) x
1707 * WM_SETTEXT to Edit x
1708 * EM_SETSEL to Edit (0,0) x
1709 * EM_SETSEL to Edit (0,-1) x
1710 * RedrawWindow(Combo, 0, 0, 5) x
1712 TRACE("special code for VK_ESCAPE\n");
1714 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1716 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1717 cbeend.fChanged = FALSE;
1718 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1719 CB_GETCURSEL, 0, 0);
1720 cbeend.iWhy = CBENF_ESCAPE;
1722 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1723 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1724 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1725 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1726 ERR("item %d not found. Problem!\n", oldItem);
1729 infoPtr->selected = oldItem;
1730 COMBOEX_SetEditText (infoPtr, item);
1731 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1736 /* native version seems to do following for COMBOEX */
1738 * GetWindowTextA(Edit,&?, 0x104) x
1739 * CB_GETCURSEL to Combo rets -1 x
1740 * CB_GETCOUNT to Combo rets 0
1742 * CB_GETITEMDATA to match
1743 * *** above 3 lines simulated by FindItem x
1744 * WM_NOTIFY to COMBOEX parent (rebar) x
1745 * (CBEN_ENDEDIT{A|W} x
1746 * fChanged = TRUE (-1) x
1747 * iNewSelection = -1 or selected x
1749 * iWhy = 2 (CBENF_RETURN) x
1750 * CB_GETCURSEL to Combo rets -1 x
1751 * if -1 send CB_SETCURSEL to Combo -1 x
1752 * InvalidateRect(Combo, 0, 0) x
1754 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1757 TRACE("special code for VK_RETURN\n");
1759 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1761 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1762 selected = SendMessageW (infoPtr->hwndCombo,
1763 CB_GETCURSEL, 0, 0);
1765 if (selected != -1) {
1766 cmp_func_t cmptext = get_cmp_func(infoPtr);
1767 item = COMBOEX_FindItem (infoPtr, selected);
1768 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1769 selected, debugstr_txt(item->pszText));
1770 TRACE("handling VK_RETURN, edittext=%s\n",
1771 debugstr_w(edit_text));
1772 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1773 /* strings not equal -- indicate edit has changed */
1778 cbeend.iNewSelection = selected;
1779 cbeend.fChanged = TRUE;
1780 cbeend.iWhy = CBENF_RETURN;
1781 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1782 /* abort the change, restore previous */
1783 TRACE("Notify requested abort of change\n");
1784 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1785 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1789 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1790 if (oldItem != -1) {
1791 /* if something is selected, then deselect it */
1792 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1795 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1796 SetFocus(infoPtr->hwndEdit);
1802 /* by default, step is 1 */
1803 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1804 if (oldItem >= 0 && oldItem + step >= 0)
1805 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1808 return CallWindowProcW (infoPtr->prevEditWndProc,
1809 hwnd, uMsg, wParam, lParam);
1815 /* remember the focus to set state of icon */
1816 lret = CallWindowProcW (infoPtr->prevEditWndProc,
1817 hwnd, uMsg, wParam, lParam);
1818 infoPtr->flags |= WCBE_EDITFOCUSED;
1823 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1825 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1826 if (infoPtr->flags & WCBE_ACTEDIT) {
1827 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1829 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1830 cbeend.fChanged = FALSE;
1831 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1832 CB_GETCURSEL, 0, 0);
1833 cbeend.iWhy = CBENF_KILLFOCUS;
1835 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1840 return CallWindowProcW (infoPtr->prevEditWndProc,
1841 hwnd, uMsg, wParam, lParam);
1846 static LRESULT WINAPI
1847 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1849 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1850 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1851 NMCBEENDEDITW cbeend;
1858 WCHAR edit_text[260];
1860 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1861 hwnd, uMsg, wParam, lParam, infoPtr);
1863 if (!infoPtr) return 0;
1870 * The only way this message should come is from the
1871 * child Listbox issuing the message. Flag this so
1872 * that ComboEx knows this is listbox.
1874 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1875 return CallWindowProcW (infoPtr->prevComboWndProc,
1876 hwnd, uMsg, wParam, lParam);
1880 * The following was determined by traces of the native
1883 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1884 GetClientRect (hwnd, &rect);
1885 TRACE("erasing (%ld,%ld)-(%ld,%ld)\n",
1886 rect.left, rect.top, rect.right, rect.bottom);
1887 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1888 SetBkColor (hDC, obkc);
1889 return CallWindowProcW (infoPtr->prevComboWndProc,
1890 hwnd, uMsg, wParam, lParam);
1894 * WM_NOTIFY to comboex parent (rebar)
1895 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1896 * CallWindowProc (previous)
1898 nmmse.dwItemSpec = 0;
1899 nmmse.dwItemData = 0;
1902 nmmse.dwHitInfo = lParam;
1903 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1904 return CallWindowProcW (infoPtr->prevComboWndProc,
1905 hwnd, uMsg, wParam, lParam);
1907 case WM_LBUTTONDOWN:
1908 GetClientRect (hwnd, &rect);
1909 rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1910 CB_GETITEMHEIGHT, -1, 0);
1911 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
1912 pt.x = (short)LOWORD(lParam);
1913 pt.y = (short)HIWORD(lParam);
1914 if (PtInRect(&rect, pt))
1915 return CallWindowProcW (infoPtr->prevComboWndProc,
1916 hwnd, uMsg, wParam, lParam);
1917 infoPtr->flags |= WCBE_MOUSECAPTURED;
1922 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1923 return CallWindowProcW (infoPtr->prevComboWndProc,
1924 hwnd, uMsg, wParam, lParam);
1926 infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1927 if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1928 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1930 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1935 if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1936 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
1937 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1938 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
1939 infoPtr->flags |= WCBE_MOUSEDRAGGED;
1941 return CallWindowProcW (infoPtr->prevComboWndProc,
1942 hwnd, uMsg, wParam, lParam);
1945 switch (HIWORD(wParam)) {
1948 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1957 * GetFocus() retns AA
1958 * GetWindowTextA(Edit)
1959 * CB_GETCURSEL(Combo) (got -1)
1960 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1961 * CB_GETCURSEL(Combo) (got -1)
1962 * InvalidateRect(Combo, 0, 0)
1963 * WM_KILLFOCUS(Combo, AA)
1966 focusedhwnd = GetFocus();
1967 if (infoPtr->flags & WCBE_ACTEDIT) {
1968 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1969 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1970 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1971 CB_GETCURSEL, 0, 0);
1972 cbeend.iWhy = CBENF_KILLFOCUS;
1974 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1975 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1977 /* possible CB_GETCURSEL */
1978 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1980 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
1981 (WPARAM)focusedhwnd, 0);
1986 * For EN_SETFOCUS this issues the same calls and messages
1987 * as the native seems to do.
1989 * for some cases however native does the following:
1990 * (noticed after SetFocus during LBUTTONDOWN on
1991 * on dropdown arrow)
1992 * WM_GETTEXTLENGTH (Edit);
1993 * WM_GETTEXT (Edit, len+1, str);
1994 * EM_SETSEL (Edit, 0, 0);
1995 * WM_GETTEXTLENGTH (Edit);
1996 * WM_GETTEXT (Edit, len+1, str);
1997 * EM_SETSEL (Edit, 0, len);
1998 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2002 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2003 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2004 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2005 infoPtr->flags |= WCBE_ACTEDIT;
2006 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2012 * For EN_CHANGE this issues the same calls and messages
2013 * as the native seems to do.
2015 WCHAR edit_text[260];
2017 cmp_func_t cmptext = get_cmp_func(infoPtr);
2019 INT selected = SendMessageW (infoPtr->hwndCombo,
2020 CB_GETCURSEL, 0, 0);
2022 /* lstrlenA( lastworkingURL ) */
2024 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2025 if (selected == -1) {
2026 lastwrk = infoPtr->edit->pszText;
2029 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2030 lastwrk = COMBOEX_GetText(infoPtr, item);
2033 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2034 selected, debugstr_w(lastwrk));
2035 TRACE("handling EN_CHANGE, edittext=%s\n",
2036 debugstr_w(edit_text));
2038 /* cmptext is between lastworkingURL and GetWindowText */
2039 if (cmptext (lastwrk, edit_text)) {
2040 /* strings not equal -- indicate edit has changed */
2041 infoPtr->flags |= WCBE_EDITCHG;
2043 SendMessageW ( infoPtr->hwndNotify, WM_COMMAND,
2044 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2046 (LPARAM)infoPtr->hwndSelf);
2052 * Therefore from traces there is no additional code here
2056 * Using native COMCTL32 gets the following:
2057 * 1 == SHDOCVW.DLL issues call/message
2058 * 2 == COMCTL32.DLL issues call/message
2059 * 3 == WINE issues call/message
2062 * for LBN_SELCHANGE:
2063 * 1 CB_GETCURSEL(ComboEx)
2064 * 1 CB_GETDROPPEDSTATE(ComboEx)
2065 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2066 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2067 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2068 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2069 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2070 * 3 ShowWindow(ComboLB, SW_HIDE)
2071 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2072 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2074 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2075 * ? LB_GETCURSEL <==|
2077 * ? LB_GETTEXT | Needs to be added to
2078 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2079 * ? LB_GETITEMDATA |
2080 * ? WM_DRAWITEM(ComboEx) <==|
2086 return CallWindowProcW (infoPtr->prevComboWndProc,
2087 hwnd, uMsg, wParam, lParam);
2093 static LRESULT WINAPI
2094 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2096 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2098 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2101 if (uMsg == WM_CREATE)
2102 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2103 if (uMsg == WM_NCCREATE)
2104 COMBOEX_NCCreate (hwnd);
2105 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2110 case CBEM_DELETEITEM:
2111 return COMBOEX_DeleteItem (infoPtr, wParam);
2113 case CBEM_GETCOMBOCONTROL:
2114 return (LRESULT)infoPtr->hwndCombo;
2116 case CBEM_GETEDITCONTROL:
2117 return (LRESULT)infoPtr->hwndEdit;
2119 case CBEM_GETEXTENDEDSTYLE:
2120 return infoPtr->dwExtStyle;
2122 case CBEM_GETIMAGELIST:
2123 return (LRESULT)infoPtr->himl;
2126 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2129 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2131 case CBEM_GETUNICODEFORMAT:
2132 return infoPtr->unicode;
2134 case CBEM_HASEDITCHANGED:
2135 return COMBOEX_HasEditChanged (infoPtr);
2137 case CBEM_INSERTITEMA:
2138 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2140 case CBEM_INSERTITEMW:
2141 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2143 case CBEM_SETEXSTYLE:
2144 case CBEM_SETEXTENDEDSTYLE:
2145 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2147 case CBEM_SETIMAGELIST:
2148 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2151 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2154 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2156 case CBEM_SETUNICODEFORMAT:
2157 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2159 /*case CBEM_SETWINDOWTHEME:
2160 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2164 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2166 /* Combo messages we are not sure if we need to process or just forward */
2167 case CB_GETDROPPEDCONTROLRECT:
2168 case CB_GETITEMHEIGHT:
2170 case CB_GETLBTEXTLEN:
2171 case CB_GETEXTENDEDUI:
2173 case CB_RESETCONTENT:
2174 case CB_SELECTSTRING:
2176 /* Combo messages OK to just forward to the regular COMBO */
2179 case CB_GETDROPPEDSTATE:
2180 case CB_SETDROPPEDWIDTH:
2181 case CB_SETEXTENDEDUI:
2182 case CB_SHOWDROPDOWN:
2183 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2185 /* Combo messages we need to process specially */
2186 case CB_FINDSTRINGEXACT:
2187 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2189 case CB_GETITEMDATA:
2190 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2193 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2195 case CB_SETITEMDATA:
2196 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD)lParam);
2198 case CB_SETITEMHEIGHT:
2199 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2203 /* Window messages passed to parent */
2205 return COMBOEX_Command (infoPtr, wParam, lParam);
2208 if (infoPtr->NtfUnicode)
2209 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
2211 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
2214 /* Window messages we need to process */
2216 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2219 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2222 return COMBOEX_Destroy (infoPtr);
2224 case WM_MEASUREITEM:
2225 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2227 case WM_NOTIFYFORMAT:
2228 return COMBOEX_NotifyFormat (infoPtr, lParam);
2231 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2233 case WM_WINDOWPOSCHANGING:
2234 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2237 SetFocus(infoPtr->hwndCombo);
2241 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2242 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
2243 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2248 void COMBOEX_Register (void)
2252 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2253 wndClass.style = CS_GLOBALCLASS;
2254 wndClass.lpfnWndProc = COMBOEX_WindowProc;
2255 wndClass.cbClsExtra = 0;
2256 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2257 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2258 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2259 wndClass.lpszClassName = WC_COMBOBOXEXW;
2261 RegisterClassW (&wndClass);
2265 void COMBOEX_Unregister (void)
2267 UnregisterClassW (WC_COMBOBOXEXW, NULL);