4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2000, 2001, 2002 Guy Albertelli <galberte@neo.lrun.com>
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 9, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we belive this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
56 /* ComboBoxEx structure */
60 HWND hwndSelf; /* my own hwnd */
63 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
64 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
66 INT selected; /* index of selected item */
67 DWORD flags; /* WINE internal flags */
70 INT nb_items; /* Number of items */
71 BOOL unicode; /* TRUE if this window is Unicode */
72 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
73 CBE_ITEMDATA *edit; /* item data for edit item */
74 CBE_ITEMDATA *items; /* Array of items */
77 /* internal flags in the COMBOEX_INFO structure */
78 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
79 * CBEN_BEGINEDIT issued
80 * but CBEN_ENDEDIT{A|W}
82 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
83 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
84 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
85 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
86 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
88 #define ID_CB_EDIT 1001
92 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
93 * the ComboEx version of the Combo Window Proc so that when the
94 * WM_DRAWITEM message is then passed to ComboEx, we know that this
95 * particular WM_DRAWITEM message is for listbox only items. Any messasges
96 * without this flag is then for the Edit control field.
98 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
99 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
101 #define ODS_COMBOEXLBOX 0x4000
105 /* Height in pixels of control over the amount of the selected font */
108 /* Indent amount per MS documentation */
109 #define CBE_INDENT 10
111 /* Offset in pixels from left side for start of image or text */
112 #define CBE_STARTOFFSET 6
114 /* Offset between image and text */
117 #define COMBOEX_SUBCLASS_PROP "CCComboEx32SubclassInfo"
118 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongW (hwnd, 0))
121 /* Things common to the entire DLL */
122 static LRESULT WINAPI
123 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
124 static LRESULT WINAPI
125 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
127 COMBOEX_PathWordBreakProc(LPWSTR lpch, int ichCurrent, int cch, int code);
128 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
129 typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
131 inline static BOOL is_textW(LPCWSTR str)
133 return str && str != LPSTR_TEXTCALLBACKW;
136 inline static BOOL is_textA(LPCSTR str)
138 return str && str != LPSTR_TEXTCALLBACKA;
141 inline static LPCSTR debugstr_txt(LPCWSTR str)
143 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
144 return debugstr_w(str);
147 static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
149 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
150 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
151 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
152 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
153 if (item->mask & CBEIF_TEXT)
154 TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
158 static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
160 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
161 input->mask, input->iItem, input->pszText, input->cchTextMax,
163 if (input->mask & CBEIF_TEXT)
164 TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
165 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
166 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
170 inline static CBE_ITEMDATA *get_item_data(COMBOEX_INFO *infoPtr, INT index)
172 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
176 inline static cmp_func_t get_cmp_func(COMBOEX_INFO *infoPtr)
178 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
181 static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
183 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
184 hdr->hwndFrom = infoPtr->hwndSelf;
186 if (infoPtr->NtfUnicode)
187 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
190 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
196 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
198 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
199 if (infoPtr->NtfUnicode)
200 return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
202 LPWSTR wstr = hdr->ceItem.pszText;
206 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
207 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
209 astr = (LPSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
211 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
212 hdr->ceItem.pszText = (LPWSTR)astr;
216 if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
217 else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
218 else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
220 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
222 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
223 hdr->ceItem.pszText = wstr;
225 if (astr) COMCTL32_Free(astr);
232 static INT COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
234 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
235 if (infoPtr->NtfUnicode) {
236 lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
237 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
241 memcpy (&neea.hdr, &neew->hdr, sizeof(NMHDR));
242 neea.fChanged = neew->fChanged;
243 neea.iNewSelection = neew->iNewSelection;
244 WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
245 neea.iWhy = neew->iWhy;
247 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
252 static void COMBOEX_NotifyDragBegin(COMBOEX_INFO *infoPtr, LPCWSTR wstr)
254 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
255 if (infoPtr->NtfUnicode) {
256 NMCBEDRAGBEGINW ndbw;
259 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
260 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
262 NMCBEDRAGBEGINA ndba;
265 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
267 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
272 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
274 if (is_textW(item->pszText)) COMCTL32_Free(item->pszText);
276 if (item->pszTemp) COMCTL32_Free(item->pszTemp);
281 static LPCWSTR COMBOEX_GetText(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
287 if (item->pszText != LPSTR_TEXTCALLBACKW)
288 return item->pszText;
290 ZeroMemory(&nmce, sizeof(nmce));
291 nmce.ceItem.mask = CBEIF_TEXT;
292 nmce.ceItem.lParam = item->lParam;
293 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
295 if (is_textW(nmce.ceItem.pszText)) {
296 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
297 buf = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
299 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
300 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
301 COMBOEX_FreeText(item);
304 if (item->pszTemp) COMCTL32_Free(item->pszTemp);
309 text = nmce.ceItem.pszText;
311 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
312 item->pszText = text;
317 static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
322 mydc = GetDC (0); /* why the entire screen???? */
323 nfont = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
324 ofont = (HFONT) SelectObject (mydc, nfont);
325 GetTextExtentPointA (mydc, "A", 1, size);
326 SelectObject (mydc, ofont);
328 TRACE("selected font hwnd=%p, height=%ld\n", nfont, size->cy);
332 static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
334 if (cit->mask & CBEIF_TEXT) {
336 * when given a text buffer actually use that buffer
339 if (is_textW(item->pszText))
340 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
344 cit->pszText = item->pszText;
345 cit->cchTextMax = item->cchTextMax;
348 if (cit->mask & CBEIF_IMAGE)
349 cit->iImage = item->iImage;
350 if (cit->mask & CBEIF_SELECTEDIMAGE)
351 cit->iSelectedImage = item->iSelectedImage;
352 if (cit->mask & CBEIF_OVERLAY)
353 cit->iOverlay = item->iOverlay;
354 if (cit->mask & CBEIF_INDENT)
355 cit->iIndent = item->iIndent;
356 if (cit->mask & CBEIF_LPARAM)
357 cit->lParam = item->lParam;
361 static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
364 INT x, y, w, h, xioff;
367 if (!infoPtr->hwndEdit) return;
369 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
371 iinfo.rcImage.left = iinfo.rcImage.right = 0;
372 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
373 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
376 GetClientRect (infoPtr->hwndCombo, &rect);
377 InflateRect (&rect, -2, -2);
378 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
380 /* reposition the Edit control based on whether icon exists */
381 COMBOEX_GetComboFontSize (infoPtr, &mysize);
382 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
383 x = xioff + CBE_STARTOFFSET + 1;
384 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
386 y = rect.bottom - h - 1;
388 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
389 rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
390 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
391 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
395 static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
401 COMBOEX_GetComboFontSize (infoPtr, &mysize);
402 cy = mysize.cy + CBE_EXTRA;
404 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
405 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
406 TRACE("upgraded height due to image: height=%d\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)) {
459 item = (CBE_ITEMDATA *)item->next;
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 *)COMCTL32_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 = (CBE_ITEMDATA *)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)COMCTL32_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)COMCTL32_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) COMCTL32_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 SendMessageW(infoPtr->hwndEdit, EM_SETWORDBREAKPROC, 0,
675 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ?
676 (LPARAM)COMBOEX_PathWordBreakProc : 0);
679 /* test if the control's appearance has changed */
680 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
681 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
682 /* if state of EX_NOEDITIMAGE changes, invalidate all */
683 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
684 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
685 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
686 COMBOEX_AdjustEditPos (infoPtr);
687 if (infoPtr->hwndEdit)
688 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
695 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
697 HIMAGELIST himlTemp = infoPtr->himl;
701 infoPtr->himl = himl;
703 COMBOEX_ReSize (infoPtr);
704 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
706 /* reposition the Edit control based on whether icon exists */
707 COMBOEX_AdjustEditPos (infoPtr);
711 static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
713 INT index = cit->iItem;
716 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
718 /* if item number requested does not exist then return failure */
719 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
721 /* if the item is the edit control and there is no edit control, skip */
722 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
724 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
726 /* add/change stuff to the internal item structure */
727 item->mask |= cit->mask;
728 if (cit->mask & CBEIF_TEXT) {
731 COMBOEX_FreeText(item);
732 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
734 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
735 if (!item->pszText) return FALSE;
736 strcpyW(item->pszText, cit->pszText);
737 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
738 item->pszText = LPSTR_TEXTCALLBACKW;
739 item->cchTextMax = cit->cchTextMax;
741 if (cit->mask & CBEIF_IMAGE)
742 item->iImage = cit->iImage;
743 if (cit->mask & CBEIF_SELECTEDIMAGE)
744 item->iSelectedImage = cit->iSelectedImage;
745 if (cit->mask & CBEIF_OVERLAY)
746 item->iOverlay = cit->iOverlay;
747 if (cit->mask & CBEIF_INDENT)
748 item->iIndent = cit->iIndent;
749 if (cit->mask & CBEIF_LPARAM)
750 cit->lParam = cit->lParam;
752 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
754 /* if original request was to update edit control, do some fast foot work */
755 if (cit->iItem == -1) {
756 COMBOEX_SetEditText (infoPtr, item);
757 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
762 static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
764 COMBOBOXEXITEMW citW;
768 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
769 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
770 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
771 wstr = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
772 if (!wstr) return FALSE;
773 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
776 ret = COMBOEX_SetItemW(infoPtr, &citW);
778 if (wstr) COMCTL32_Free(wstr);
784 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
786 BOOL bTemp = infoPtr->unicode;
788 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
790 infoPtr->unicode = value;
796 /* *** CB_xxx message support *** */
799 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
802 cmp_func_t cmptext = get_cmp_func(infoPtr);
803 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
805 /* now search from after starting loc and wrapping back to start */
806 for(i=start+1; i<count; i++) {
807 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
808 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
810 for(i=0; i<=start; i++) {
811 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
812 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
818 static DWORD COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
820 CBE_ITEMDATA *item1, *item2;
823 item1 = get_item_data(infoPtr, index);
824 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
825 item2 = COMBOEX_FindItem (infoPtr, index);
826 if (item2 != item1) {
827 ERR("data structures damaged!\n");
830 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
831 TRACE("returning 0x%08lx\n", ret);
834 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
840 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
845 if (!(item = COMBOEX_FindItem(infoPtr, index)))
846 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
848 TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
849 infoPtr->selected = index;
851 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
852 COMBOEX_SetEditText (infoPtr, item);
857 static DWORD COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD data)
859 CBE_ITEMDATA *item1, *item2;
861 item1 = get_item_data(infoPtr, index);
862 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
863 item2 = COMBOEX_FindItem (infoPtr, index);
864 if (item2 != item1) {
865 ERR("data structures damaged!\n");
868 item1->mask |= CBEIF_LPARAM;
869 item1->lParam = data;
870 TRACE("setting lparam to 0x%08lx\n", data);
873 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
874 return (LRESULT)item1;
878 static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
880 RECT cb_wrect, cbx_wrect, cbx_crect;
882 /* First, lets forward the message to the normal combo control
883 just like Windows. */
884 if (infoPtr->hwndCombo)
885 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
886 index, height) == CB_ERR) return CB_ERR;
888 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
889 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
890 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
891 /* the height of comboex as height of the combo + comboex border */
892 height = cb_wrect.bottom-cb_wrect.top
893 + cbx_wrect.bottom-cbx_wrect.top
894 - (cbx_crect.bottom-cbx_crect.top);
895 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
896 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
897 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
898 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
899 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
900 cbx_wrect.right-cbx_wrect.left, height);
901 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
902 cbx_wrect.right-cbx_wrect.left, height,
903 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
909 /* *** WM_xxx message support *** */
912 static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
914 WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
915 WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
917 COMBOEX_INFO *infoPtr;
919 RECT wnrc1, clrc1, cmbwrc;
922 /* allocate memory for info structure */
923 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
924 if (!infoPtr) return -1;
926 /* initialize info structure */
927 /* note that infoPtr is allocated zero-filled */
929 infoPtr->hwndSelf = hwnd;
930 infoPtr->selected = -1;
932 infoPtr->unicode = IsWindowUnicode (hwnd);
934 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
935 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
936 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
939 infoPtr->NtfUnicode = (i == NFR_UNICODE);
941 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
943 /* create combo box */
944 GetWindowRect(hwnd, &wnrc1);
945 GetClientRect(hwnd, &clrc1);
946 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
947 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
948 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
950 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
951 /* specified. It then creates it's own version of the EDIT control */
952 /* and makes the ComboBox the parent. This is because a normal */
953 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
954 /* We also need to place the edit control at the proper location */
955 /* (allow space for the icons). */
957 infoPtr->hwndCombo = CreateWindowW (COMBOBOX, NIL,
958 /* following line added to match native */
959 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
960 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
961 /* was base and is necessary */
962 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
963 GetWindowLongW (hwnd, GWL_STYLE),
964 cs->y, cs->x, cs->cx, cs->cy, hwnd,
965 (HMENU) GetWindowLongW (hwnd, GWL_ID),
966 (HINSTANCE)GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
969 * native does the following at this point according to trace:
970 * GetWindowThreadProcessId(hwndCombo,0)
971 * GetCurrentThreadId()
972 * GetWindowThreadProcessId(hwndCombo, &???)
973 * GetCurrentProcessId()
977 * Setup a property to hold the pointer to the COMBOBOXEX
980 SetPropA(infoPtr->hwndCombo, COMBOEX_SUBCLASS_PROP, hwnd);
981 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndCombo,
982 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
983 infoPtr->font = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
987 * Now create our own EDIT control so we can position it.
988 * It is created only for CBS_DROPDOWN style
990 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
991 infoPtr->hwndEdit = CreateWindowExW (0, EDIT, NIL,
992 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
993 0, 0, 0, 0, /* will set later */
995 (HMENU) GetWindowLongW (hwnd, GWL_ID),
996 (HINSTANCE)GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
998 /* native does the following at this point according to trace:
999 * GetWindowThreadProcessId(hwndEdit,0)
1000 * GetCurrentThreadId()
1001 * GetWindowThreadProcessId(hwndEdit, &???)
1002 * GetCurrentProcessId()
1006 * Setup a property to hold the pointer to the COMBOBOXEX
1009 SetPropA(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
1010 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndEdit,
1011 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1012 infoPtr->font = (HFONT)SendMessageW(infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1016 * Locate the default font if necessary and then set it in
1017 * all associated controls
1019 if (!infoPtr->font) {
1020 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1022 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1024 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1025 if (infoPtr->hwndEdit) {
1026 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1027 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1030 COMBOEX_ReSize (infoPtr);
1032 /* Above is fairly certain, below is much less certain. */
1034 GetWindowRect(hwnd, &wnrc1);
1035 GetClientRect(hwnd, &clrc1);
1036 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1037 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1038 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1039 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1040 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1041 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1042 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1043 SWP_NOACTIVATE | SWP_NOREDRAW);
1045 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1046 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1047 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1048 SetWindowPos(hwnd, HWND_TOP,
1049 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1050 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1052 COMBOEX_AdjustEditPos (infoPtr);
1055 * Create an item structure to represent the data in the
1056 * EDIT control. It is allocated zero-filled.
1058 infoPtr->edit = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1059 if (!infoPtr->edit) {
1060 COMBOEX_Destroy(infoPtr);
1068 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1071 INT command = HIWORD(wParam);
1072 CBE_ITEMDATA *item = 0;
1074 INT cursel, n, oldItem;
1075 NMCBEENDEDITW cbeend;
1077 HWND parent = GetParent (infoPtr->hwndSelf);
1079 TRACE("for command %d\n", command);
1084 SetFocus (infoPtr->hwndCombo);
1085 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1086 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1089 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1091 * from native trace of first dropdown after typing in URL in IE4
1092 * CB_GETCURSEL(Combo)
1093 * GetWindowText(Edit)
1094 * CB_GETCURSEL(Combo)
1095 * CB_GETCOUNT(Combo)
1096 * CB_GETITEMDATA(Combo, n)
1097 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1098 * CB_GETCURSEL(Combo)
1099 * CB_SETCURSEL(COMBOEX, n)
1101 * the rest is supposition
1103 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1104 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1105 InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1106 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1108 cmp_func_t cmptext = get_cmp_func(infoPtr);
1109 /* find match from edit against those in Combobox */
1110 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1111 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1112 for (cursel = 0; cursel < n; cursel++){
1113 item = get_item_data(infoPtr, cursel);
1114 if ((INT)item == CB_ERR) break;
1115 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1117 if ((cursel == n) || ((INT)item == CB_ERR)) {
1118 TRACE("failed to find match??? item=%p cursel=%d\n",
1120 if (infoPtr->hwndEdit)
1121 SetFocus(infoPtr->hwndEdit);
1126 item = get_item_data(infoPtr, cursel);
1127 if ((INT)item == CB_ERR) {
1128 TRACE("failed to find match??? item=%p cursel=%d\n",
1130 if (infoPtr->hwndEdit)
1131 SetFocus(infoPtr->hwndEdit);
1136 /* Save flags for testing and reset them */
1137 oldflags = infoPtr->flags;
1138 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1140 if (oldflags & WCBE_ACTEDIT) {
1141 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1142 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1143 CB_GETCURSEL, 0, 0);
1144 cbeend.iWhy = CBENF_DROPDOWN;
1146 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1149 /* if selection has changed the set the new current selection */
1150 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1151 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1152 infoPtr->selected = cursel;
1153 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1154 SetFocus(infoPtr->hwndCombo);
1160 * CB_GETCURSEL(Combo)
1161 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1164 * WM_GETTEXTLENGTH(Edit)
1166 * EM_SETSEL(Edit, 0,0)
1167 * WM_GETTEXTLENGTH(Edit)
1169 * EM_SETSEL(Edit, 0,len)
1170 * return WM_COMMAND to parent
1172 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1173 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1174 ERR("item %d not found. Problem!\n", oldItem);
1177 infoPtr->selected = oldItem;
1178 COMBOEX_SetEditText (infoPtr, item);
1179 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1183 * We have to change the handle since we are the control
1184 * issuing the message. IE4 depends on this.
1186 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1190 * from native trace:
1193 * WM_GETTEXT(Edit, 104)
1194 * CB_GETCURSEL(Combo) rets -1
1195 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1196 * CB_GETCURSEL(Combo)
1197 * InvalidateRect(Combo, 0, 0)
1200 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1201 if (infoPtr->flags & WCBE_ACTEDIT) {
1202 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1203 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1204 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1205 CB_GETCURSEL, 0, 0);
1206 cbeend.iWhy = CBENF_KILLFOCUS;
1208 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1209 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1211 /* possible CB_GETCURSEL */
1212 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1217 * We have to change the handle since we are the control
1218 * issuing the message. IE4 depends on this.
1219 * We also need to set the focus back to the Edit control
1220 * after passing the command to the parent of the ComboEx.
1222 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1223 if (infoPtr->hwndEdit)
1224 SetFocus(infoPtr->hwndEdit);
1231 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
1233 CBE_ITEMDATA *item, *olditem;
1234 NMCOMBOBOXEXW nmcit;
1237 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1238 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1240 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1242 olditem = infoPtr->items;
1243 i = infoPtr->nb_items - 1;
1245 if (i == dis->itemID) {
1246 infoPtr->items = infoPtr->items->next;
1252 /* find the prior item in the list */
1253 while (item->next && (i > dis->itemID)) {
1254 item = (CBE_ITEMDATA *)item->next;
1257 if (!item->next || (i != dis->itemID)) {
1258 ERR("COMBOBOXEX item structures broken. Please report!\n");
1261 olditem = item->next;
1262 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1264 infoPtr->nb_items--;
1266 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1267 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1268 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1270 COMBOEX_FreeText(olditem);
1271 COMCTL32_Free(olditem);
1277 static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
1279 WCHAR nil[] = { 0 };
1280 CBE_ITEMDATA *item = 0;
1286 COLORREF nbkc, ntxc, bkc, txc;
1287 int drawimage, drawstate, xioff;
1289 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1291 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1292 dis->CtlType, dis->CtlID);
1293 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1294 dis->itemID, dis->itemAction, dis->itemState);
1295 TRACE("hWnd=%p hDC=%p (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1296 dis->hwndItem, dis->hDC, dis->rcItem.left,
1297 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1301 /* "itemID - Specifies the menu item identifier for a menu */
1302 /* item or the index of the item in a list box or combo box. */
1303 /* For an empty list box or combo box, this member can be -1. */
1304 /* This allows the application to draw only the focus */
1305 /* rectangle at the coordinates specified by the rcItem */
1306 /* member even though there are no items in the control. */
1307 /* This indicates to the user whether the list box or combo */
1308 /* box has the focus. How the bits are set in the itemAction */
1309 /* member determines whether the rectangle is to be drawn as */
1310 /* though the list box or combo box has the focus. */
1311 if (dis->itemID == 0xffffffff) {
1312 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1313 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1315 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1316 dis->rcItem.left, dis->rcItem.top,
1317 dis->rcItem.right, dis->rcItem.bottom);
1319 else if ((dis->CtlType == ODT_COMBOBOX) &&
1320 (dis->itemAction == ODA_DRAWENTIRE)) {
1321 /* draw of edit control data */
1325 RECT exrc, cbrc, edrc;
1326 GetWindowRect (infoPtr->hwndSelf, &exrc);
1327 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1328 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1329 if (infoPtr->hwndEdit)
1330 GetWindowRect (infoPtr->hwndEdit, &edrc);
1331 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1332 exrc.left, exrc.top, exrc.right, exrc.bottom,
1333 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1334 edrc.left, edrc.top, edrc.right, edrc.bottom);
1338 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1339 dis->rcItem.left, dis->rcItem.top,
1340 dis->rcItem.right, dis->rcItem.bottom,
1341 dis->itemAction, dis->itemState);
1346 /* If draw item is -1 (edit control) setup the item pointer */
1347 if (dis->itemID == 0xffffffff) {
1348 item = infoPtr->edit;
1350 if (infoPtr->hwndEdit) {
1353 /* free previous text of edit item */
1354 COMBOEX_FreeText(item);
1355 item->mask &= ~CBEIF_TEXT;
1356 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1357 item->mask |= CBEIF_TEXT;
1358 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1360 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1362 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1363 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1369 /* if the item pointer is not set, then get the data and locate it */
1371 item = get_item_data(infoPtr, dis->itemID);
1372 if (item == (CBE_ITEMDATA *)CB_ERR) {
1373 ERR("invalid item for id %d \n", dis->itemID);
1378 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1380 xbase = CBE_STARTOFFSET;
1381 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1382 INT indent = item->iIndent;
1383 if (indent == I_INDENTCALLBACK) {
1385 ZeroMemory(&nmce, sizeof(nmce));
1386 nmce.ceItem.mask = CBEIF_INDENT;
1387 nmce.ceItem.lParam = item->lParam;
1388 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1389 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1390 item->iIndent = nmce.ceItem.iIndent;
1391 indent = nmce.ceItem.iIndent;
1393 xbase += (indent * CBE_INDENT);
1397 drawstate = ILD_NORMAL;
1398 if (item->mask & CBEIF_IMAGE)
1399 drawimage = item->iImage;
1400 if (dis->itemState & ODS_COMBOEXLBOX) {
1401 /* drawing listbox entry */
1402 if (dis->itemState & ODS_SELECTED) {
1403 if (item->mask & CBEIF_SELECTEDIMAGE)
1404 drawimage = item->iSelectedImage;
1405 drawstate = ILD_SELECTED;
1408 /* drawing combo/edit entry */
1409 if (IsWindowVisible(infoPtr->hwndEdit)) {
1410 /* if we have an edit control, the slave the
1411 * selection state to the Edit focus state
1413 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1414 if (item->mask & CBEIF_SELECTEDIMAGE)
1415 drawimage = item->iSelectedImage;
1416 drawstate = ILD_SELECTED;
1419 /* if we don't have an edit control, use
1420 * the requested state.
1422 if (dis->itemState & ODS_SELECTED) {
1423 if (item->mask & CBEIF_SELECTEDIMAGE)
1424 drawimage = item->iSelectedImage;
1425 drawstate = ILD_SELECTED;
1430 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1432 iinfo.rcImage.left = iinfo.rcImage.right = 0;
1433 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1434 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1437 /* setup pointer to text to be drawn */
1438 str = COMBOEX_GetText(infoPtr, item);
1439 if (!str) str = nil;
1441 len = strlenW (str);
1442 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1444 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1445 int overlay = item->iOverlay;
1447 if (drawimage == I_IMAGECALLBACK) {
1449 ZeroMemory(&nmce, sizeof(nmce));
1450 nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
1451 nmce.ceItem.lParam = item->lParam;
1452 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1453 if (drawstate == ILD_NORMAL) {
1454 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1455 drawimage = nmce.ceItem.iImage;
1456 } else if (drawstate == ILD_SELECTED) {
1457 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1458 drawimage = nmce.ceItem.iSelectedImage;
1459 } else ERR("Bad draw state = %d\n", drawstate);
1462 if (overlay == I_IMAGECALLBACK) {
1464 ZeroMemory(&nmce, sizeof(nmce));
1465 nmce.ceItem.mask = CBEIF_OVERLAY;
1466 nmce.ceItem.lParam = item->lParam;
1467 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1468 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1469 item->iOverlay = nmce.ceItem.iOverlay;
1470 overlay = nmce.ceItem.iOverlay;
1473 if (drawimage >= 0 &&
1474 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1475 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1476 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1477 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1480 /* now draw the text */
1481 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1482 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1483 COLOR_HIGHLIGHT : COLOR_WINDOW);
1484 bkc = SetBkColor (dis->hDC, nbkc);
1485 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1486 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1487 txc = SetTextColor (dis->hDC, ntxc);
1489 y = dis->rcItem.top +
1490 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1492 rect.right = x + txtsize.cx;
1493 rect.top = dis->rcItem.top + 1;
1494 rect.bottom = dis->rcItem.bottom - 1;
1495 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1496 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1497 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1498 &rect, str, len, 0);
1499 SetBkColor (dis->hDC, bkc);
1500 SetTextColor (dis->hDC, txc);
1504 if (dis->itemAction & ODA_FOCUS) {
1505 rect.left = xbase + xioff - 1;
1506 rect.right = rect.left + txtsize.cx + 2;
1507 rect.top = dis->rcItem.top;
1508 rect.bottom = dis->rcItem.bottom;
1509 DrawFocusRect(dis->hDC, &rect);
1516 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1518 if (infoPtr->hwndCombo)
1519 DestroyWindow (infoPtr->hwndCombo);
1521 if (infoPtr->edit) {
1522 COMCTL32_Free (infoPtr->edit);
1526 if (infoPtr->items) {
1527 CBE_ITEMDATA *item, *next;
1529 item = infoPtr->items;
1531 next = (CBE_ITEMDATA *)item->next;
1532 COMBOEX_FreeText (item);
1533 COMCTL32_Free (item);
1539 if (infoPtr->defaultFont)
1540 DeleteObject (infoPtr->defaultFont);
1542 /* free comboex info data */
1543 COMCTL32_Free (infoPtr);
1544 SetWindowLongW (infoPtr->hwndSelf, 0, 0);
1549 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
1555 GetTextExtentPointA (hdc, "W", 1, &mysize);
1557 mis->itemHeight = mysize.cy + CBE_EXTRA;
1559 TRACE("adjusted height hwnd=%p, height=%d\n",
1560 infoPtr->hwndSelf, mis->itemHeight);
1566 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1568 /* WARNING: The COMBOEX_INFO structure is not yet created */
1569 DWORD oldstyle, newstyle;
1571 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1572 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1573 if (newstyle != oldstyle) {
1574 TRACE("req style %08lx, reseting style %08lx\n",
1575 oldstyle, newstyle);
1576 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1582 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1584 if (lParam == NF_REQUERY) {
1585 INT i = SendMessageW(GetParent (infoPtr->hwndSelf),
1586 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1587 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1589 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1593 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1595 TRACE("(width=%d, height=%d)\n", width, height);
1597 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1599 COMBOEX_AdjustEditPos (infoPtr);
1605 static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1607 RECT cbx_wrect, cbx_crect, cb_wrect;
1610 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1611 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1612 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1614 /* width is winpos value + border width of comboex */
1616 + (cbx_wrect.right-cbx_wrect.left)
1617 - (cbx_crect.right-cbx_crect.left);
1619 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1620 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1621 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1622 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1623 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1624 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1625 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1626 width, cb_wrect.bottom-cb_wrect.top);
1628 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1630 cb_wrect.bottom-cb_wrect.top,
1633 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1635 /* height is combo window height plus border width of comboex */
1636 height = (cb_wrect.bottom-cb_wrect.top)
1637 + (cbx_wrect.bottom-cbx_wrect.top)
1638 - (cbx_crect.bottom-cbx_crect.top);
1639 if (wp->cy < height) wp->cy = height;
1640 if (infoPtr->hwndEdit) {
1641 COMBOEX_AdjustEditPos (infoPtr);
1642 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1648 static inline int is_delimiter(WCHAR c)
1660 COMBOEX_PathWordBreakProc(LPWSTR lpch, int ichCurrent, int cch, int code)
1662 if (code == WB_ISDELIMITER) {
1663 return is_delimiter(lpch[ichCurrent]);
1665 int dir = (code == WB_LEFT) ? -1 : 1;
1666 for(; 0 <= ichCurrent && ichCurrent < cch; ichCurrent += dir)
1667 if (is_delimiter(lpch[ichCurrent])) return ichCurrent;
1672 static LRESULT WINAPI
1673 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1675 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1676 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1677 NMCBEENDEDITW cbeend;
1678 WCHAR edit_text[260];
1684 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1685 hwnd, uMsg, wParam, lParam, infoPtr);
1687 if (!infoPtr) return 0;
1693 /* handle (ignore) the return character */
1694 if (wParam == VK_RETURN) return 0;
1695 /* all other characters pass into the real Edit */
1696 return CallWindowProcW (infoPtr->prevEditWndProc,
1697 hwnd, uMsg, wParam, lParam);
1701 * The following was determined by traces of the native
1704 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1705 GetClientRect (hwnd, &rect);
1706 TRACE("erasing (%d,%d)-(%d,%d)\n",
1707 rect.left, rect.top, rect.right, rect.bottom);
1708 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1709 SetBkColor (hDC, obkc);
1710 return CallWindowProcW (infoPtr->prevEditWndProc,
1711 hwnd, uMsg, wParam, lParam);
1714 INT oldItem, selected, step = 1;
1717 switch ((INT)wParam)
1720 /* native version seems to do following for COMBOEX */
1722 * GetWindowTextA(Edit,&?, 0x104) x
1723 * CB_GETCURSEL to Combo rets -1 x
1724 * WM_NOTIFY to COMBOEX parent (rebar) x
1725 * (CBEN_ENDEDIT{A|W}
1726 * fChanged = FALSE x
1727 * inewSelection = -1 x
1730 * CB_GETCURSEL to Combo rets -1 x
1731 * InvalidateRect(Combo, 0) x
1732 * WM_SETTEXT to Edit x
1733 * EM_SETSEL to Edit (0,0) x
1734 * EM_SETSEL to Edit (0,-1) x
1735 * RedrawWindow(Combo, 0, 0, 5) x
1737 TRACE("special code for VK_ESCAPE\n");
1739 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1741 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1742 cbeend.fChanged = FALSE;
1743 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1744 CB_GETCURSEL, 0, 0);
1745 cbeend.iWhy = CBENF_ESCAPE;
1747 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1748 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1749 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1750 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1751 ERR("item %d not found. Problem!\n", oldItem);
1754 infoPtr->selected = oldItem;
1755 COMBOEX_SetEditText (infoPtr, item);
1756 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1761 /* native version seems to do following for COMBOEX */
1763 * GetWindowTextA(Edit,&?, 0x104) x
1764 * CB_GETCURSEL to Combo rets -1 x
1765 * CB_GETCOUNT to Combo rets 0
1767 * CB_GETITEMDATA to match
1768 * *** above 3 lines simulated by FindItem x
1769 * WM_NOTIFY to COMBOEX parent (rebar) x
1770 * (CBEN_ENDEDIT{A|W} x
1771 * fChanged = TRUE (-1) x
1772 * iNewSelection = -1 or selected x
1774 * iWhy = 2 (CBENF_RETURN) x
1775 * CB_GETCURSEL to Combo rets -1 x
1776 * if -1 send CB_SETCURSEL to Combo -1 x
1777 * InvalidateRect(Combo, 0, 0) x
1779 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1782 TRACE("special code for VK_RETURN\n");
1784 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1786 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1787 selected = SendMessageW (infoPtr->hwndCombo,
1788 CB_GETCURSEL, 0, 0);
1790 if (selected != -1) {
1791 cmp_func_t cmptext = get_cmp_func(infoPtr);
1792 item = COMBOEX_FindItem (infoPtr, selected);
1793 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1794 selected, debugstr_txt(item->pszText));
1795 TRACE("handling VK_RETURN, edittext=%s\n",
1796 debugstr_w(edit_text));
1797 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1798 /* strings not equal -- indicate edit has changed */
1803 cbeend.iNewSelection = selected;
1804 cbeend.fChanged = TRUE;
1805 cbeend.iWhy = CBENF_RETURN;
1806 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1807 /* abort the change, restore previous */
1808 TRACE("Notify requested abort of change\n");
1809 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1810 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1814 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1815 if (oldItem != -1) {
1816 /* if something is selected, then deselect it */
1817 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1820 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1821 SetFocus(infoPtr->hwndEdit);
1827 /* by default, step is 1 */
1828 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1829 if (oldItem >= 0 && oldItem + step >= 0)
1830 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1833 return CallWindowProcW (infoPtr->prevEditWndProc,
1834 hwnd, uMsg, wParam, lParam);
1840 /* remember the focus to set state of icon */
1841 lret = CallWindowProcW (infoPtr->prevEditWndProc,
1842 hwnd, uMsg, wParam, lParam);
1843 infoPtr->flags |= WCBE_EDITFOCUSED;
1848 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1850 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1851 if (infoPtr->flags & WCBE_ACTEDIT) {
1852 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1854 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1855 cbeend.fChanged = FALSE;
1856 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1857 CB_GETCURSEL, 0, 0);
1858 cbeend.iWhy = CBENF_KILLFOCUS;
1860 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1865 return CallWindowProcW (infoPtr->prevEditWndProc,
1866 hwnd, uMsg, wParam, lParam);
1872 static LRESULT WINAPI
1873 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1875 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1876 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1877 NMCBEENDEDITW cbeend;
1884 WCHAR edit_text[260];
1886 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1887 hwnd, uMsg, wParam, lParam, infoPtr);
1889 if (!infoPtr) return 0;
1896 * The only way this message should come is from the
1897 * child Listbox issuing the message. Flag this so
1898 * that ComboEx knows this is listbox.
1900 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1901 return CallWindowProcW (infoPtr->prevComboWndProc,
1902 hwnd, uMsg, wParam, lParam);
1906 * The following was determined by traces of the native
1909 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1910 GetClientRect (hwnd, &rect);
1911 TRACE("erasing (%d,%d)-(%d,%d)\n",
1912 rect.left, rect.top, rect.right, rect.bottom);
1913 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1914 SetBkColor (hDC, obkc);
1915 return CallWindowProcW (infoPtr->prevComboWndProc,
1916 hwnd, uMsg, wParam, lParam);
1920 * WM_NOTIFY to comboex parent (rebar)
1921 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1922 * CallWindowProc (previous)
1924 nmmse.dwItemSpec = 0;
1925 nmmse.dwItemData = 0;
1928 nmmse.dwHitInfo = lParam;
1929 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1930 return CallWindowProcW (infoPtr->prevComboWndProc,
1931 hwnd, uMsg, wParam, lParam);
1933 case WM_LBUTTONDOWN:
1934 GetClientRect (hwnd, &rect);
1935 rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1936 CB_GETITEMHEIGHT, -1, 0);
1937 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
1938 POINTSTOPOINT(pt, MAKEPOINTS(lParam));
1939 if (PtInRect(&rect, pt))
1940 return CallWindowProcW (infoPtr->prevComboWndProc,
1941 hwnd, uMsg, wParam, lParam);
1942 infoPtr->flags |= WCBE_MOUSECAPTURED;
1947 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1948 return CallWindowProcW (infoPtr->prevComboWndProc,
1949 hwnd, uMsg, wParam, lParam);
1951 infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1952 if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1953 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1955 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1960 if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1961 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
1962 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1963 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
1964 infoPtr->flags |= WCBE_MOUSEDRAGGED;
1966 return CallWindowProcW (infoPtr->prevComboWndProc,
1967 hwnd, uMsg, wParam, lParam);
1970 switch (HIWORD(wParam)) {
1973 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1982 * GetFocus() retns AA
1983 * GetWindowTextA(Edit)
1984 * CB_GETCURSEL(Combo) (got -1)
1985 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1986 * CB_GETCURSEL(Combo) (got -1)
1987 * InvalidateRect(Combo, 0, 0)
1988 * WM_KILLFOCUS(Combo, AA)
1991 focusedhwnd = GetFocus();
1992 if (infoPtr->flags & WCBE_ACTEDIT) {
1993 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1994 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1995 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1996 CB_GETCURSEL, 0, 0);
1997 cbeend.iWhy = CBENF_KILLFOCUS;
1999 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2000 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
2002 /* possible CB_GETCURSEL */
2003 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2005 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2006 (WPARAM)focusedhwnd, 0);
2011 * For EN_SETFOCUS this issues the same calls and messages
2012 * as the native seems to do.
2014 * for some cases however native does the following:
2015 * (noticed after SetFocus during LBUTTONDOWN on
2016 * on dropdown arrow)
2017 * WM_GETTEXTLENGTH (Edit);
2018 * WM_GETTEXT (Edit, len+1, str);
2019 * EM_SETSEL (Edit, 0, 0);
2020 * WM_GETTEXTLENGTH (Edit);
2021 * WM_GETTEXT (Edit, len+1, str);
2022 * EM_SETSEL (Edit, 0, len);
2023 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2027 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2028 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2029 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2030 infoPtr->flags |= WCBE_ACTEDIT;
2031 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2037 * For EN_CHANGE this issues the same calls and messages
2038 * as the native seems to do.
2040 WCHAR edit_text[260];
2042 cmp_func_t cmptext = get_cmp_func(infoPtr);
2044 INT selected = SendMessageW (infoPtr->hwndCombo,
2045 CB_GETCURSEL, 0, 0);
2047 /* lstrlenA( lastworkingURL ) */
2049 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2050 if (selected == -1) {
2051 lastwrk = infoPtr->edit->pszText;
2054 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2055 lastwrk = COMBOEX_GetText(infoPtr, item);
2058 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2059 selected, debugstr_w(lastwrk));
2060 TRACE("handling EN_CHANGE, edittext=%s\n",
2061 debugstr_w(edit_text));
2063 /* cmptext is between lastworkingURL and GetWindowText */
2064 if (cmptext (lastwrk, edit_text)) {
2065 /* strings not equal -- indicate edit has changed */
2066 infoPtr->flags |= WCBE_EDITCHG;
2068 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2069 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2071 (LPARAM)infoPtr->hwndSelf);
2077 * Therefore from traces there is no additional code here
2081 * Using native COMCTL32 gets the following:
2082 * 1 == SHDOCVW.DLL issues call/message
2083 * 2 == COMCTL32.DLL issues call/message
2084 * 3 == WINE issues call/message
2087 * for LBN_SELCHANGE:
2088 * 1 CB_GETCURSEL(ComboEx)
2089 * 1 CB_GETDROPPEDSTATE(ComboEx)
2090 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2091 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2092 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2093 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2094 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2095 * 3 ShowWindow(ComboLB, SW_HIDE)
2096 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2097 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2099 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2100 * ? LB_GETCURSEL <==|
2102 * ? LB_GETTEXT | Needs to be added to
2103 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2104 * ? LB_GETITEMDATA |
2105 * ? WM_DRAWITEM(ComboEx) <==|
2111 return CallWindowProcW (infoPtr->prevComboWndProc,
2112 hwnd, uMsg, wParam, lParam);
2118 static LRESULT WINAPI
2119 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2121 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2123 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2126 if (uMsg == WM_CREATE)
2127 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2128 if (uMsg == WM_NCCREATE)
2129 COMBOEX_NCCreate (hwnd);
2130 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2135 case CBEM_DELETEITEM:
2136 return COMBOEX_DeleteItem (infoPtr, wParam);
2138 case CBEM_GETCOMBOCONTROL:
2139 return (LRESULT)infoPtr->hwndCombo;
2141 case CBEM_GETEDITCONTROL:
2142 return (LRESULT)infoPtr->hwndEdit;
2144 case CBEM_GETEXTENDEDSTYLE:
2145 return infoPtr->dwExtStyle;
2147 case CBEM_GETIMAGELIST:
2148 return (LRESULT)infoPtr->himl;
2151 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2154 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2156 case CBEM_GETUNICODEFORMAT:
2157 return infoPtr->unicode;
2159 case CBEM_HASEDITCHANGED:
2160 return COMBOEX_HasEditChanged (infoPtr);
2162 case CBEM_INSERTITEMA:
2163 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2165 case CBEM_INSERTITEMW:
2166 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2168 case CBEM_SETEXSTYLE:
2169 case CBEM_SETEXTENDEDSTYLE:
2170 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2172 case CBEM_SETIMAGELIST:
2173 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2176 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2179 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2181 case CBEM_SETUNICODEFORMAT:
2182 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2184 /*case CBEM_SETWINDOWTHEME:
2185 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2189 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2191 /* Combo messages we are not sure if we need to process or just forward */
2192 case CB_GETDROPPEDCONTROLRECT:
2193 case CB_GETITEMHEIGHT:
2195 case CB_GETLBTEXTLEN:
2196 case CB_GETEXTENDEDUI:
2198 case CB_RESETCONTENT:
2199 case CB_SELECTSTRING:
2201 /* Combo messages OK to just forward to the regular COMBO */
2204 case CB_GETDROPPEDSTATE:
2205 case CB_SETDROPPEDWIDTH:
2206 case CB_SETEXTENDEDUI:
2207 case CB_SHOWDROPDOWN:
2208 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2210 /* Combo messages we need to process specially */
2211 case CB_FINDSTRINGEXACT:
2212 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2214 case CB_GETITEMDATA:
2215 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2218 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2220 case CB_SETITEMDATA:
2221 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD)lParam);
2223 case CB_SETITEMHEIGHT:
2224 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2228 /* Window messages passed to parent */
2230 return COMBOEX_Command (infoPtr, wParam, lParam);
2233 if (infoPtr->NtfUnicode)
2234 return SendMessageW (GetParent (hwnd), uMsg, wParam, lParam);
2236 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
2239 /* Window messages we need to process */
2241 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2244 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2247 return COMBOEX_Destroy (infoPtr);
2249 case WM_MEASUREITEM:
2250 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2252 case WM_NOTIFYFORMAT:
2253 return COMBOEX_NotifyFormat (infoPtr, lParam);
2256 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2258 case WM_WINDOWPOSCHANGING:
2259 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2262 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
2263 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
2264 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2270 void COMBOEX_Register (void)
2274 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2275 wndClass.style = CS_GLOBALCLASS;
2276 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2277 wndClass.cbClsExtra = 0;
2278 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2279 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
2280 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2281 wndClass.lpszClassName = WC_COMBOBOXEXW;
2283 RegisterClassW (&wndClass);
2287 void COMBOEX_Unregister (void)
2289 UnregisterClassW (WC_COMBOBOXEXW, (HINSTANCE)NULL);