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
23 * 1. The following extended styles need to be implemented, use will
25 * CBES_EX_NOEDITIMAGEINDENT
26 * CBES_EX_PATHWORDBREAKPROC
28 * CBES_EX_CASESENSITIVE
29 * 2. None of the following callback items are implemented. Therefor
30 * no CBEN_GETDISPINFO notifies are issued. Use in either CBEM_INSERTITEM
31 * or CBEM_SETITEM will result in a FIXME:
35 * 3. No use is made of the iOverlay image.
36 * 4. Notify CBEN_DRAGBEGIN is not implemented.
43 #include "wine/debug.h"
44 #include "wine/unicode.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
48 * The following is necessary for the test done in COMBOEX_DrawItem
49 * to determine whether to dump out the DRAWITEM structure or not.
51 WINE_DECLARE_DEBUG_CHANNEL(message);
67 /* ComboBoxEx structure */
71 HWND hwndSelf; /* my own hwnd */
74 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
75 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
77 INT selected; /* index of selected item */
78 DWORD flags; /* WINE internal flags */
81 INT nb_items; /* Number of items */
82 BOOL unicode; /* TRUE if this window is Unicode */
83 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
84 CBE_ITEMDATA *edit; /* item data for edit item */
85 CBE_ITEMDATA *items; /* Array of items */
88 /* internal flags in the COMBOEX_INFO structure */
89 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
90 * CBEN_BEGINEDIT issued
91 * but CBEN_ENDEDIT{A|W}
93 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
94 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
95 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
98 #define ID_CB_EDIT 1001
102 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
103 * the ComboEx version of the Combo Window Proc so that when the
104 * WM_DRAWITEM message is then passed to ComboEx, we know that this
105 * particular WM_DRAWITEM message is for listbox only items. Any messasges
106 * without this flag is then for the Edit control field.
108 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
109 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
111 #define ODS_COMBOEXLBOX 0x4000
115 /* Height in pixels of control over the amount of the selected font */
118 /* Indent amount per MS documentation */
119 #define CBE_INDENT 10
121 /* Offset in pixels from left side for start of image or text */
122 #define CBE_STARTOFFSET 6
124 /* Offset between image and text */
127 #define COMBOEX_SUBCLASS_PROP "CCComboEx32SubclassInfo"
128 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongW (hwnd, 0))
131 /* Things common to the entire DLL */
132 static LRESULT WINAPI
133 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
134 static LRESULT WINAPI
135 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
137 static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
139 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
140 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
141 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
142 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
143 if ((item->mask & CBEIF_TEXT) && item->pszText)
144 TRACE("item %p - pszText=%s\n", item, debugstr_w(item->pszText));
148 static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
150 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
151 input->mask, input->iItem, input->pszText, input->cchTextMax,
153 if ((input->mask & CBEIF_TEXT) && input->pszText)
154 TRACE("input - pszText=<%s>\n", debugstr_w(input->pszText));
155 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
156 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
160 inline static LRESULT
161 COMBOEX_Forward (COMBOEX_INFO *infoPtr, UINT uMsg, WPARAM wParam, LPARAM lParam)
163 if (infoPtr->hwndCombo)
164 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
170 static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
172 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
173 hdr->hwndFrom = infoPtr->hwndSelf;
175 if (infoPtr->NtfUnicode)
176 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
179 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
185 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
188 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
190 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
191 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
192 hdr->hdr.code = code;
193 if (infoPtr->NtfUnicode)
194 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
197 LPWSTR str, ostr = NULL;
200 if (hdr->ceItem.mask & CBEIF_TEXT) {
201 ostr = hdr->ceItem.pszText;
203 if (!str) str = (LPWSTR)L"";
204 len = WideCharToMultiByte (CP_ACP, 0, str, -1, 0, 0, NULL, NULL);
206 hdr->ceItem.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
207 //FIXME: what if alloc failed?
208 WideCharToMultiByte (CP_ACP, 0, str, -1, (LPSTR)hdr->ceItem.pszText,
213 ret = SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
215 if (hdr->ceItem.mask & CBEIF_TEXT) {
217 COMCTL32_Free (hdr->ceItem.pszText);
218 hdr->ceItem.pszText = ostr;
226 COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *hdr, LPWSTR itemText)
229 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
231 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
232 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
233 hdr->hdr.code = (infoPtr->NtfUnicode) ? CBEN_ENDEDITW : CBEN_ENDEDITA;
234 if (infoPtr->NtfUnicode)
235 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
240 memcpy (&ansi.hdr, &hdr->hdr, sizeof(NMHDR));
241 ansi.fChanged = hdr->fChanged;
242 ansi.iNewSelection = hdr->iNewSelection;
243 WideCharToMultiByte (CP_ACP, 0, itemText, -1,
244 (LPSTR)&ansi.szText, CBEMAXSTRLEN, NULL, NULL);
245 ansi.iWhy = hdr->iWhy;
246 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
252 static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
257 mydc = GetDC (0); /* why the entire screen???? */
258 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
259 ofont = (HFONT) SelectObject (mydc, nfont);
260 GetTextExtentPointA (mydc, "A", 1, size);
261 SelectObject (mydc, ofont);
263 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
267 static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
269 if (cit->mask & CBEIF_TEXT) {
271 * when given a text buffer actually use that buffer
275 lstrcpynW(cit->pszText,item->pszText,cit->cchTextMax);
279 cit->pszText = item->pszText;
280 cit->cchTextMax = item->cchTextMax;
283 if (cit->mask & CBEIF_IMAGE)
284 cit->iImage = item->iImage;
285 if (cit->mask & CBEIF_SELECTEDIMAGE)
286 cit->iSelectedImage = item->iSelectedImage;
287 if (cit->mask & CBEIF_OVERLAY)
288 cit->iOverlay = item->iOverlay;
289 if (cit->mask & CBEIF_INDENT)
290 cit->iIndent = item->iIndent;
291 if (cit->mask & CBEIF_LPARAM)
292 cit->lParam = item->lParam;
296 static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
300 INT x, y, w, h, xoff = 0;
303 if (!infoPtr->hwndEdit) return;
305 iinfo.rcImage.left = iinfo.rcImage.right = 0;
307 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
308 xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
310 GetClientRect (infoPtr->hwndCombo, &rect);
311 InflateRect (&rect, -2, -2);
312 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
314 /* reposition the Edit control based on whether icon exists */
315 COMBOEX_GetComboFontSize (infoPtr, &mysize);
316 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
317 x = xoff + CBE_STARTOFFSET + 1;
318 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
320 y = rect.bottom - h - 1;
322 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
323 rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
324 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
325 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
329 static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
335 COMBOEX_GetComboFontSize (infoPtr, &mysize);
336 cy = mysize.cy + CBE_EXTRA;
338 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
339 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
340 TRACE("upgraded height due to image: height=%d\n", cy);
342 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)cy);
343 if (infoPtr->hwndCombo)
344 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
345 (WPARAM) 0, (LPARAM) cy);
349 static void COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
351 if (!infoPtr->hwndEdit) return;
352 /* native issues the following messages to the {Edit} control */
353 /* WM_SETTEXT (0,addr) */
354 /* EM_SETSEL32 (0,0) */
355 /* EM_SETSEL32 (0,-1) */
356 if (item->mask & CBEIF_TEXT) {
357 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
358 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
359 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
364 static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
369 if ((index > infoPtr->nb_items) || (index < -1))
372 return infoPtr->edit;
373 item = infoPtr->items;
374 i = infoPtr->nb_items - 1;
376 /* find the item in the list */
377 while (item && (i > index)) {
378 item = (CBE_ITEMDATA *)item->next;
381 if (!item || (i != index)) {
382 ERR("COMBOBOXEX item structures broken. Please report!\n");
389 static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO *infoPtr)
391 return infoPtr->hwndEdit;
395 static void COMBOEX_WarnCallBack (CBE_ITEMDATA *item)
397 if (item->pszText == LPSTR_TEXTCALLBACKW)
398 FIXME("Callback not implemented yet for pszText\n");
399 if (item->iImage == I_IMAGECALLBACK)
400 FIXME("Callback not implemented yet for iImage\n");
401 if (item->iSelectedImage == I_IMAGECALLBACK)
402 FIXME("Callback not implemented yet for iSelectedImage\n");
403 if (item->iOverlay == I_IMAGECALLBACK)
404 FIXME("Callback not implemented yet for iOverlay\n");
405 if (item->iIndent == I_INDENTCALLBACK)
406 FIXME("Callback not implemented yet for iIndent\n");
410 /* *** CBEM_xxx message support *** */
413 static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
417 TRACE("(index=%d)\n", index);
419 /* if item number requested does not exist then return failure */
420 if ((index > infoPtr->nb_items) || (index < 0)) return CB_ERR;
421 if (!(item = COMBOEX_FindItem(infoPtr, index))) return CB_ERR;
423 /* doing this will result in WM_DELETEITEM being issued */
424 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
426 return infoPtr->nb_items;
430 static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
432 INT index = cit->iItem;
437 /* if item number requested does not exist then return failure */
438 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
440 /* if the item is the edit control and there is no edit control, skip */
441 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
443 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
445 COMBOEX_CopyItem (item, cit);
451 static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
453 COMBOBOXEXITEMW tmpcit;
457 tmpcit.mask = cit->mask;
458 tmpcit.iItem = cit->iItem;
460 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
462 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
463 cit->pszText, cit->cchTextMax, NULL, NULL);
465 cit->iImage = tmpcit.iImage;
466 cit->iSelectedImage = tmpcit.iSelectedImage;
467 cit->iOverlay = tmpcit.iOverlay;
468 cit->iIndent = tmpcit.iIndent;
469 cit->lParam = tmpcit.lParam;
475 inline static BOOL COMBOEX_HasEditChanged (COMBOEX_INFO *infoPtr)
477 return COMBOEX_HasEdit(infoPtr) &&
478 (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
482 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
490 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
492 /* get real index of item to insert */
494 if (index == -1) index = infoPtr->nb_items;
495 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
497 /* get space and chain it in */
498 if(!(item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof(*item)))) return -1;
501 item->pszText = NULL;
503 /* locate position to insert new item in */
504 if (index == infoPtr->nb_items) {
505 /* fast path for iItem = -1 */
506 item->next = infoPtr->items;
507 infoPtr->items = item;
510 INT i = infoPtr->nb_items-1;
511 CBE_ITEMDATA *moving = infoPtr->items;
513 while ((i > index) && moving) {
514 moving = (CBE_ITEMDATA *)moving->next;
518 ERR("COMBOBOXEX item structures broken. Please report!\n");
522 item->next = moving->next;
526 /* fill in our hidden item structure */
527 item->mask = cit->mask;
528 if (item->mask & CBEIF_TEXT) {
533 if (!str) str = (LPWSTR) L"";
536 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
537 //FIXME: what if allocation fails?
538 strcpyW (item->pszText, str);
541 item->pszText = NULL;
542 item->cchTextMax = cit->cchTextMax;
544 if (item->mask & CBEIF_IMAGE)
545 item->iImage = cit->iImage;
546 if (item->mask & CBEIF_SELECTEDIMAGE)
547 item->iSelectedImage = cit->iSelectedImage;
548 if (item->mask & CBEIF_OVERLAY)
549 item->iOverlay = cit->iOverlay;
550 if (item->mask & CBEIF_INDENT)
551 item->iIndent = cit->iIndent;
552 if (item->mask & CBEIF_LPARAM)
553 item->lParam = cit->lParam;
556 COMBOEX_WarnCallBack (item);
558 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
560 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
561 (WPARAM)cit->iItem, (LPARAM)item);
563 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
564 COMBOEX_CopyItem (item, &nmcit.ceItem);
565 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
572 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
574 COMBOBOXEXITEMW citW;
577 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
578 if (cit->mask & CBEIF_TEXT) {
579 LPSTR str = cit->pszText;
582 if (str) len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
584 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
585 if (!citW.pszText) return -1;
586 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
589 ret = COMBOEX_InsertItemW(infoPtr, &citW);;
591 if (citW.pszText) COMCTL32_Free(citW.pszText);
598 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
602 TRACE("(mask=x%08lx, style=0x%08lx)\n", mask, style);
604 dwTemp = infoPtr->dwExtStyle;
606 if (style & (CBES_EX_NOEDITIMAGEINDENT |
607 CBES_EX_PATHWORDBREAKPROC |
608 CBES_EX_NOSIZELIMIT |
609 CBES_EX_CASESENSITIVE))
610 FIXME("Extended style not implemented %08lx\n", style);
613 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
615 infoPtr->dwExtStyle = style;
618 * native does this for CBES_EX_NOEDITIMAGE state change
620 if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
621 (dwTemp & CBES_EX_NOEDITIMAGE)) {
622 /* if state of EX_NOEDITIMAGE changes, invalidate all */
623 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
624 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
625 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
626 COMBOEX_AdjustEditPos (infoPtr);
627 if (infoPtr->hwndEdit)
628 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
635 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
637 HIMAGELIST himlTemp = infoPtr->himl;
641 infoPtr->himl = himl;
643 COMBOEX_ReSize (infoPtr);
644 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
646 /* reposition the Edit control based on whether icon exists */
647 COMBOEX_AdjustEditPos (infoPtr);
651 static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
653 INT index = cit->iItem;
656 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
658 /* if item number requested does not exist then return failure */
659 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
661 /* if the item is the edit control and there is no edit control, skip */
662 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
664 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
666 /* add/change stuff to the internal item structure */
667 item->mask |= cit->mask;
668 if (cit->mask & CBEIF_TEXT) {
669 LPWSTR str = cit->pszText;
672 if (str) len = strlenW(str);
674 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
675 if (!item->pszText) return FALSE;
676 strcpyW(item->pszText, str);
678 item->cchTextMax = cit->cchTextMax;
680 if (cit->mask & CBEIF_IMAGE)
681 item->iImage = cit->iImage;
682 if (cit->mask & CBEIF_SELECTEDIMAGE)
683 item->iSelectedImage = cit->iSelectedImage;
684 if (cit->mask & CBEIF_OVERLAY)
685 item->iOverlay = cit->iOverlay;
686 if (cit->mask & CBEIF_INDENT)
687 item->iIndent = cit->iIndent;
688 if (cit->mask & CBEIF_LPARAM)
689 cit->lParam = cit->lParam;
691 COMBOEX_WarnCallBack (item);
693 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
695 /* if original request was to update edit control, do some fast foot work */
696 if (cit->iItem == -1) {
697 COMBOEX_SetEditText (infoPtr, item);
698 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
703 static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
705 COMBOBOXEXITEMW citW;
708 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
709 if (cit->mask & CBEIF_TEXT) {
710 LPSTR str = cit->pszText;
714 if (str) len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
716 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
717 if (!citW.pszText) return FALSE;
718 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
721 ret = COMBOEX_SetItemW(infoPtr, &citW);;
723 if (citW.pszText) COMCTL32_Free(citW.pszText);
729 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
731 BOOL bTemp = infoPtr->unicode;
733 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
735 infoPtr->unicode = value;
741 /* *** CB_xxx message support *** */
744 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCSTR str)
748 LPWSTR desired = NULL;
750 i = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
752 desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
753 if (!desired) return CB_ERR;
754 MultiByteToWideChar (CP_ACP, 0, str, -1, desired, i);
757 count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
759 /* now search from after starting loc and wrapping back to start */
760 for(i=start+1; i<count; i++) {
761 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
762 CB_GETITEMDATA, (WPARAM)i, 0);
763 TRACE("desired=%s, item=%s\n",
764 debugstr_w(desired), debugstr_w(item->pszText));
765 if (lstrcmpiW(item->pszText, desired) == 0) {
766 COMCTL32_Free (desired);
770 for(i=0; i<=start; i++) {
771 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
772 CB_GETITEMDATA, (WPARAM)i, 0);
773 TRACE("desired=%s, item=%s\n",
774 debugstr_w(desired), debugstr_w(item->pszText));
775 if (lstrcmpiW(item->pszText, desired) == 0) {
776 COMCTL32_Free (desired);
780 COMCTL32_Free(desired);
785 static DWORD COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
787 CBE_ITEMDATA *item1, *item2;
790 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (infoPtr, CB_GETITEMDATA, index, 0);
791 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
792 item2 = COMBOEX_FindItem (infoPtr, index);
793 if (item2 != item1) {
794 ERR("data structures damaged!\n");
797 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
798 TRACE("returning 0x%08lx\n", ret);
801 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
807 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
812 if (!(item = COMBOEX_FindItem(infoPtr, index)))
813 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
815 TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
816 debugstr_w(item->pszText) : "<null>");
817 infoPtr->selected = index;
819 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
820 COMBOEX_SetEditText (infoPtr, item);
825 static DWORD COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD data)
827 CBE_ITEMDATA *item1, *item2;
829 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (infoPtr,CB_GETITEMDATA,index,data);
831 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
832 item2 = COMBOEX_FindItem (infoPtr, index);
833 if (item2 != item1) {
834 ERR("data structures damaged!\n");
837 item1->mask |= CBEIF_LPARAM;
838 item1->lParam = data;
839 TRACE("setting lparam to 0x%08lx\n", data);
842 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
843 return (LRESULT)item1;
847 static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
849 RECT cb_wrect, cbx_wrect, cbx_crect;
851 /* First, lets forward the message to the normal combo control
852 just like Windows. */
853 if (infoPtr->hwndCombo)
854 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
855 index, height) == CB_ERR) return CB_ERR;
857 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
858 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
859 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
860 /* the height of comboex as height of the combo + comboex border */
861 height = cb_wrect.bottom-cb_wrect.top
862 + cbx_wrect.bottom-cbx_wrect.top
863 - (cbx_crect.bottom-cbx_crect.top);
864 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
865 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
866 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
867 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
868 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
869 cbx_wrect.right-cbx_wrect.left, height);
870 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
871 cbx_wrect.right-cbx_wrect.left, height,
872 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
878 /* *** WM_xxx message support *** */
881 static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
883 WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
884 WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
886 COMBOEX_INFO *infoPtr;
889 RECT wnrc1, clrc1, cmbwrc;
892 /* allocate memory for info structure */
893 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
894 if (!infoPtr) return -1;
896 /* initialize info structure */
897 /* note that infoPtr is allocated zero-filled */
899 infoPtr->hwndSelf = hwnd;
900 infoPtr->selected = -1;
902 infoPtr->unicode = IsWindowUnicode (hwnd);
904 i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, hwnd, NF_QUERY);
905 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
906 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
909 infoPtr->NtfUnicode = (i == NFR_UNICODE);
911 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
913 /* create combo box */
914 dwComboStyle = GetWindowLongW (hwnd, GWL_STYLE) &
915 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
917 GetWindowRect(hwnd, &wnrc1);
918 GetClientRect(hwnd, &clrc1);
919 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
920 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
921 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
922 TRACE("combo style=%08lx, adding style=%08lx\n", dwComboStyle,
923 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
924 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
925 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED);
927 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
928 /* specified. It then creates it's own version of the EDIT control */
929 /* and makes the ComboBox the parent. This is because a normal */
930 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
931 /* We also need to place the edit control at the proper location */
932 /* (allow space for the icons). */
934 infoPtr->hwndCombo = CreateWindowW (COMBOBOX, NIL,
935 /* following line added to match native */
936 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
937 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
938 /* was base and is necessary */
939 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
940 cs->y, cs->x, cs->cx, cs->cy, hwnd,
941 (HMENU) GetWindowLongW (hwnd, GWL_ID),
942 GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
945 * native does the following at this point according to trace:
946 * GetWindowThreadProcessId(hwndCombo,0)
947 * GetCurrentThreadId()
948 * GetWindowThreadProcessId(hwndCombo, &???)
949 * GetCurrentProcessId()
953 * Setup a property to hold the pointer to the COMBOBOXEX
956 SetPropA(infoPtr->hwndCombo, COMBOEX_SUBCLASS_PROP, hwnd);
957 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndCombo,
958 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
959 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
963 * Now create our own EDIT control so we can position it.
964 * It is created only for CBS_DROPDOWN style
966 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
967 infoPtr->hwndEdit = CreateWindowExW (0, EDIT, NIL,
968 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
969 0, 0, 0, 0, /* will set later */
971 (HMENU) GetWindowLongW (hwnd, GWL_ID),
972 GetWindowLongW (hwnd, GWL_HINSTANCE),
975 /* native does the following at this point according to trace:
976 * GetWindowThreadProcessId(hwndEdit,0)
977 * GetCurrentThreadId()
978 * GetWindowThreadProcessId(hwndEdit, &???)
979 * GetCurrentProcessId()
983 * Setup a property to hold the pointer to the COMBOBOXEX
986 SetPropA(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
987 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndEdit,
988 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
989 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
993 * Locate the default font if necessary and then set it in
994 * all associated controls
996 if (!infoPtr->font) {
997 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
999 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1001 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1002 if (infoPtr->hwndEdit) {
1003 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1004 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1007 COMBOEX_ReSize (infoPtr);
1009 /* Above is fairly certain, below is much less certain. */
1011 GetWindowRect(hwnd, &wnrc1);
1012 GetClientRect(hwnd, &clrc1);
1013 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1014 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1015 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1016 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1017 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1018 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1019 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1020 SWP_NOACTIVATE | SWP_NOREDRAW);
1022 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1023 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1024 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1025 SetWindowPos(hwnd, HWND_TOP,
1026 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1027 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1029 COMBOEX_AdjustEditPos (infoPtr);
1032 * Create an item structure to represent the data in the
1033 * EDIT control. It is allocated zero-filled.
1035 infoPtr->edit = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1036 //FIXME: what if allocation failed?
1042 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1045 INT command = HIWORD(wParam);
1046 CBE_ITEMDATA *item = 0;
1048 INT cursel, n, oldItem;
1049 NMCBEENDEDITW cbeend;
1051 HWND parent = GetParent (infoPtr->hwndSelf);
1053 TRACE("for command %d\n", command);
1058 SetFocus (infoPtr->hwndCombo);
1059 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1060 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1063 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1065 * from native trace of first dropdown after typing in URL in IE4
1066 * CB_GETCURSEL(Combo)
1067 * GetWindowText(Edit)
1068 * CB_GETCURSEL(Combo)
1069 * CB_GETCOUNT(Combo)
1070 * CB_GETITEMDATA(Combo, n)
1071 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1072 * CB_GETCURSEL(Combo)
1073 * CB_SETCURSEL(COMBOEX, n)
1075 * the rest is supposition
1077 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1078 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1079 InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1080 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1082 /* find match from edit against those in Combobox */
1083 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1084 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1085 for (cursel = 0; cursel < n; cursel++){
1086 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1089 if ((INT)item == CB_ERR) break;
1090 if (lstrcmpiW(item->pszText, wintext) == 0) break;
1092 if ((cursel == n) || ((INT)item == CB_ERR)) {
1093 TRACE("failed to find match??? item=%p cursel=%d\n",
1095 if (infoPtr->hwndEdit)
1096 SetFocus(infoPtr->hwndEdit);
1101 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1104 if ((INT)item == CB_ERR) {
1105 TRACE("failed to find match??? item=%p cursel=%d\n",
1107 if (infoPtr->hwndEdit)
1108 SetFocus(infoPtr->hwndEdit);
1113 /* Save flags for testing and reset them */
1114 oldflags = infoPtr->flags;
1115 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1117 if (oldflags & WCBE_ACTEDIT) {
1118 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1119 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1120 CB_GETCURSEL, 0, 0);
1121 cbeend.iWhy = CBENF_DROPDOWN;
1123 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, item->pszText)) {
1124 /* abort the change */
1125 TRACE("Notify requested abort of change\n");
1130 /* if selection has changed the set the new current selection */
1131 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1132 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1133 infoPtr->selected = cursel;
1134 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1135 SetFocus(infoPtr->hwndCombo);
1141 * CB_GETCURSEL(Combo)
1142 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1145 * WM_GETTEXTLENGTH(Edit)
1147 * EM_SETSEL(Edit, 0,0)
1148 * WM_GETTEXTLENGTH(Edit)
1150 * EM_SETSEL(Edit, 0,len)
1151 * return WM_COMMAND to parent
1153 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1154 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1155 ERR("item %d not found. Problem!\n", oldItem);
1158 infoPtr->selected = oldItem;
1159 COMBOEX_SetEditText (infoPtr, item);
1160 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1164 * We have to change the handle since we are the control
1165 * issuing the message. IE4 depends on this.
1167 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1171 * from native trace:
1174 * WM_GETTEXT(Edit, 104)
1175 * CB_GETCURSEL(Combo) rets -1
1176 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1177 * CB_GETCURSEL(Combo)
1178 * InvalidateRect(Combo, 0, 0)
1181 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1182 if (infoPtr->flags & WCBE_ACTEDIT) {
1183 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1184 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1185 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1186 CB_GETCURSEL, 0, 0);
1187 cbeend.iWhy = CBENF_KILLFOCUS;
1189 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1190 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) {
1191 /* abort the change */
1192 TRACE("Notify requested abort of change\n");
1196 /* possible CB_GETCURSEL */
1197 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1202 * We have to change the handle since we are the control
1203 * issuing the message. IE4 depends on this.
1204 * We also need to set the focus back to the Edit control
1205 * after passing the command to the parent of the ComboEx.
1207 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1208 if (infoPtr->hwndEdit)
1209 SetFocus(infoPtr->hwndEdit);
1216 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
1218 CBE_ITEMDATA *item, *olditem;
1219 NMCOMBOBOXEXW nmcit;
1222 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1223 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1225 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1227 olditem = infoPtr->items;
1228 i = infoPtr->nb_items - 1;
1230 if (i == dis->itemID) {
1231 infoPtr->items = infoPtr->items->next;
1237 /* find the prior item in the list */
1238 while (item->next && (i > dis->itemID)) {
1239 item = (CBE_ITEMDATA *)item->next;
1242 if (!item->next || (i != dis->itemID)) {
1243 ERR("COMBOBOXEX item structures broken. Please report!\n");
1246 olditem = item->next;
1247 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1249 infoPtr->nb_items--;
1251 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1252 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1253 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1255 if (olditem->pszText) COMCTL32_Free(olditem->pszText);
1256 COMCTL32_Free(olditem);
1262 static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
1264 WCHAR nil[] = { 0 };
1265 CBE_ITEMDATA *item = 0;
1269 int drawimage, drawstate;
1271 UINT xioff = 0; /* size and spacer of image if any */
1274 COLORREF nbkc, ntxc, bkc, txc;
1276 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1278 /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
1279 if (!TRACE_ON(message)) {
1280 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1281 dis->CtlType, dis->CtlID);
1282 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1283 dis->itemID, dis->itemAction, dis->itemState);
1284 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1285 dis->hwndItem, dis->hDC, dis->rcItem.left,
1286 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1291 /* "itemID - Specifies the menu item identifier for a menu */
1292 /* item or the index of the item in a list box or combo box. */
1293 /* For an empty list box or combo box, this member can be -1. */
1294 /* This allows the application to draw only the focus */
1295 /* rectangle at the coordinates specified by the rcItem */
1296 /* member even though there are no items in the control. */
1297 /* This indicates to the user whether the list box or combo */
1298 /* box has the focus. How the bits are set in the itemAction */
1299 /* member determines whether the rectangle is to be drawn as */
1300 /* though the list box or combo box has the focus. */
1301 if (dis->itemID == 0xffffffff) {
1302 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1303 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1305 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1306 dis->rcItem.left, dis->rcItem.top,
1307 dis->rcItem.right, dis->rcItem.bottom);
1309 else if ((dis->CtlType == ODT_COMBOBOX) &&
1310 (dis->itemAction == ODA_DRAWENTIRE)) {
1311 /* draw of edit control data */
1315 RECT exrc, cbrc, edrc;
1316 GetWindowRect (infoPtr->hwndSelf, &exrc);
1317 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1318 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1319 if (infoPtr->hwndEdit)
1320 GetWindowRect (infoPtr->hwndEdit, &edrc);
1321 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1322 exrc.left, exrc.top, exrc.right, exrc.bottom,
1323 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1324 edrc.left, edrc.top, edrc.right, edrc.bottom);
1328 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1329 dis->rcItem.left, dis->rcItem.top,
1330 dis->rcItem.right, dis->rcItem.bottom,
1331 dis->itemAction, dis->itemState);
1336 /* If draw item is -1 (edit control) setup the item pointer */
1337 if (dis->itemID == 0xffffffff) {
1338 item = infoPtr->edit;
1340 if (infoPtr->hwndEdit) {
1343 /* free previous text of edit item */
1344 if (item->pszText) {
1345 COMCTL32_Free(item->pszText);
1347 item->mask &= ~CBEIF_TEXT;
1349 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1350 item->mask |= CBEIF_TEXT;
1351 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
1352 //FIXME: what if alloc failed?
1353 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1355 TRACE("edit control hwndEdit=%0x, text len=%d str=%s\n",
1356 infoPtr->hwndEdit, len, debugstr_w(item->pszText));
1362 /* if the item pointer is not set, then get the data and locate it */
1364 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1365 CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
1366 if (item == (CBE_ITEMDATA *)CB_ERR) {
1367 ERR("invalid item for id %d \n", dis->itemID);
1372 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1374 xbase = CBE_STARTOFFSET;
1375 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
1376 xbase += (item->iIndent * CBE_INDENT);
1377 if (item->mask & CBEIF_IMAGE) {
1378 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
1379 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
1382 /* setup pointer to text to be drawn */
1383 if (item && (item->mask & CBEIF_TEXT) && item->pszText)
1384 str = item->pszText;
1388 len = strlenW (str);
1389 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1391 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1393 drawstate = ILD_NORMAL;
1394 if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
1395 if (item->mask & CBEIF_IMAGE)
1396 drawimage = item->iImage;
1397 if (dis->itemState & ODS_COMBOEXLBOX) {
1398 /* drawing listbox entry */
1399 if (dis->itemState & ODS_SELECTED) {
1400 if (item->mask & CBEIF_SELECTEDIMAGE)
1401 drawimage = item->iSelectedImage;
1402 drawstate = ILD_SELECTED;
1406 /* drawing combo/edit entry */
1407 if (IsWindowVisible(infoPtr->hwndEdit)) {
1408 /* if we have an edit control, the slave the
1409 * selection state to the Edit focus state
1411 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1412 if (item->mask & CBEIF_SELECTEDIMAGE)
1413 drawimage = item->iSelectedImage;
1414 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 (drawimage != -1) {
1430 TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
1431 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
1432 xbase, dis->rcItem.top, drawstate);
1435 /* now draw the text */
1436 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1437 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1438 COLOR_HIGHLIGHT : COLOR_WINDOW);
1439 bkc = SetBkColor (dis->hDC, nbkc);
1440 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1441 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1442 txc = SetTextColor (dis->hDC, ntxc);
1444 y = dis->rcItem.top +
1445 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1447 rect.right = x + txtsize.cx;
1448 rect.top = dis->rcItem.top + 1;
1449 rect.bottom = dis->rcItem.bottom - 1;
1450 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1451 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1452 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1453 &rect, str, len, 0);
1454 SetBkColor (dis->hDC, bkc);
1455 SetTextColor (dis->hDC, txc);
1459 if (dis->itemAction & ODA_FOCUS) {
1460 rect.left = xbase + xioff - 1;
1461 rect.right = rect.left + txtsize.cx + 2;
1462 rect.top = dis->rcItem.top;
1463 rect.bottom = dis->rcItem.bottom;
1464 DrawFocusRect(dis->hDC, &rect);
1471 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1473 if (infoPtr->hwndCombo)
1474 DestroyWindow (infoPtr->hwndCombo);
1476 if (infoPtr->edit) {
1477 COMCTL32_Free (infoPtr->edit);
1481 if (infoPtr->items) {
1482 CBE_ITEMDATA *this, *next;
1484 this = infoPtr->items;
1486 next = (CBE_ITEMDATA *)this->next;
1487 if ((this->mask & CBEIF_TEXT) && this->pszText)
1488 COMCTL32_Free (this->pszText);
1489 COMCTL32_Free (this);
1495 if (infoPtr->defaultFont)
1496 DeleteObject (infoPtr->defaultFont);
1498 /* free comboex info data */
1499 COMCTL32_Free (infoPtr);
1500 SetWindowLongW (infoPtr->hwndSelf, 0, 0);
1505 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
1511 GetTextExtentPointA (hdc, "W", 1, &mysize);
1513 mis->itemHeight = mysize.cy + CBE_EXTRA;
1515 TRACE("adjusted height hwnd=%08x, height=%d\n",
1516 infoPtr->hwndSelf, mis->itemHeight);
1522 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1524 /* WARNING: The COMBOEX_INFO structure is not yet created */
1525 DWORD oldstyle, newstyle;
1527 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1528 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1529 if (newstyle != oldstyle) {
1530 TRACE("req style %08lx, reseting style %08lx\n",
1531 oldstyle, newstyle);
1532 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1538 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1540 if (lParam == NF_REQUERY) {
1541 INT i = SendMessageW(GetParent (infoPtr->hwndSelf),
1542 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
1543 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1544 ERR("wrong response to WM_NOTIFYFORMAT (%d), set to ANSI\n", i);
1547 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1550 return (LRESULT)(infoPtr->unicode ? NFR_UNICODE : NFR_ANSI);
1554 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1556 TRACE("(width=%d, height=%d)\n", width, height);
1558 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1560 COMBOEX_AdjustEditPos (infoPtr);
1566 static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1568 RECT cbx_wrect, cbx_crect, cb_wrect;
1571 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1572 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1573 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1575 /* width is winpos value + border width of comboex */
1577 + (cbx_wrect.right-cbx_wrect.left)
1578 - (cbx_crect.right-cbx_crect.left);
1580 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1581 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1582 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1583 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1584 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1585 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1586 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1587 width, cb_wrect.bottom-cb_wrect.top);
1589 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1591 cb_wrect.bottom-cb_wrect.top,
1594 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1596 /* height is combo window height plus border width of comboex */
1597 height = (cb_wrect.bottom-cb_wrect.top)
1598 + (cbx_wrect.bottom-cbx_wrect.top)
1599 - (cbx_crect.bottom-cbx_crect.top);
1600 if (wp->cy < height) wp->cy = height;
1601 if (infoPtr->hwndEdit) {
1602 COMBOEX_AdjustEditPos (infoPtr);
1603 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1610 static LRESULT WINAPI
1611 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1613 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1614 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1615 NMCBEENDEDITW cbeend;
1616 WCHAR edit_text[260];
1622 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1623 hwnd, uMsg, wParam, lParam, infoPtr);
1625 if (!infoPtr) return 0;
1631 /* handle (ignore) the return character */
1632 if (wParam == VK_RETURN) return 0;
1633 /* all other characters pass into the real Edit */
1634 return CallWindowProcW (infoPtr->prevEditWndProc,
1635 hwnd, uMsg, wParam, lParam);
1639 * The following was determined by traces of the native
1642 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1643 GetClientRect (hwnd, &rect);
1644 TRACE("erasing (%d,%d)-(%d,%d)\n",
1645 rect.left, rect.top, rect.right, rect.bottom);
1646 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1647 SetBkColor (hDC, obkc);
1648 return CallWindowProcW (infoPtr->prevEditWndProc,
1649 hwnd, uMsg, wParam, lParam);
1652 INT oldItem, selected, step = 1;
1655 switch ((INT)wParam)
1658 /* native version seems to do following for COMBOEX */
1660 * GetWindowTextA(Edit,&?, 0x104) x
1661 * CB_GETCURSEL to Combo rets -1 x
1662 * WM_NOTIFY to COMBOEX parent (rebar) x
1663 * (CBEN_ENDEDIT{A|W}
1664 * fChanged = FALSE x
1665 * inewSelection = -1 x
1668 * CB_GETCURSEL to Combo rets -1 x
1669 * InvalidateRect(Combo, 0) x
1670 * WM_SETTEXT to Edit x
1671 * EM_SETSEL to Edit (0,0) x
1672 * EM_SETSEL to Edit (0,-1) x
1673 * RedrawWindow(Combo, 0, 0, 5) x
1675 TRACE("special code for VK_ESCAPE\n");
1677 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1679 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1680 cbeend.fChanged = FALSE;
1681 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1682 CB_GETCURSEL, 0, 0);
1683 cbeend.iWhy = CBENF_ESCAPE;
1685 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1686 /* abort the change */
1687 TRACE("Notify requested abort of change\n");
1690 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1691 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1692 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1693 ERR("item %d not found. Problem!\n", oldItem);
1696 infoPtr->selected = oldItem;
1697 COMBOEX_SetEditText (infoPtr, item);
1698 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1703 /* native version seems to do following for COMBOEX */
1705 * GetWindowTextA(Edit,&?, 0x104) x
1706 * CB_GETCURSEL to Combo rets -1 x
1707 * CB_GETCOUNT to Combo rets 0
1709 * CB_GETITEMDATA to match
1710 * *** above 3 lines simulated by FindItem x
1711 * WM_NOTIFY to COMBOEX parent (rebar) x
1712 * (CBEN_ENDEDIT{A|W} x
1713 * fChanged = TRUE (-1) x
1714 * iNewSelection = -1 or selected x
1716 * iWhy = 2 (CBENF_RETURN) x
1717 * CB_GETCURSEL to Combo rets -1 x
1718 * if -1 send CB_SETCURSEL to Combo -1 x
1719 * InvalidateRect(Combo, 0, 0) x
1721 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1724 TRACE("special code for VK_RETURN\n");
1726 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1728 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1729 selected = SendMessageW (infoPtr->hwndCombo,
1730 CB_GETCURSEL, 0, 0);
1732 if (selected != -1) {
1733 item = COMBOEX_FindItem (infoPtr, selected);
1734 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1735 selected, debugstr_w(item->pszText));
1736 TRACE("handling VK_RETURN, edittext=%s\n",
1737 debugstr_w(edit_text));
1738 if (lstrcmpiW (item->pszText, edit_text)) {
1739 /* strings not equal -- indicate edit has changed */
1744 cbeend.iNewSelection = selected;
1745 cbeend.fChanged = TRUE;
1746 cbeend.iWhy = CBENF_RETURN;
1747 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1748 /* abort the change, restore previous */
1749 TRACE("Notify requested abort of change\n");
1750 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1751 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1755 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1756 if (oldItem != -1) {
1757 /* if something is selected, then deselect it */
1758 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1761 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1762 SetFocus(infoPtr->hwndEdit);
1768 /* by default, step is 1 */
1769 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1770 if (oldItem >= 0 && oldItem + step >= 0)
1771 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1774 return CallWindowProcW (infoPtr->prevEditWndProc,
1775 hwnd, uMsg, wParam, lParam);
1781 /* remember the focus to set state of icon */
1782 lret = CallWindowProcW (infoPtr->prevEditWndProc,
1783 hwnd, uMsg, wParam, lParam);
1784 infoPtr->flags |= WCBE_EDITFOCUSED;
1789 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1791 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1792 if (infoPtr->flags & WCBE_ACTEDIT) {
1793 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1795 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1796 cbeend.fChanged = FALSE;
1797 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1798 CB_GETCURSEL, 0, 0);
1799 cbeend.iWhy = CBENF_KILLFOCUS;
1801 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1806 return CallWindowProcW (infoPtr->prevEditWndProc,
1807 hwnd, uMsg, wParam, lParam);
1813 static LRESULT WINAPI
1814 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1816 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1817 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
1818 NMCBEENDEDITW cbeend;
1824 WCHAR edit_text[260];
1826 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1827 hwnd, uMsg, wParam, lParam, infoPtr);
1829 if (!infoPtr) return 0;
1834 case CB_FINDSTRINGEXACT:
1835 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCSTR)lParam);
1839 * The only way this message should come is from the
1840 * child Listbox issuing the message. Flag this so
1841 * that ComboEx knows this is listbox.
1843 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1844 return CallWindowProcW (infoPtr->prevComboWndProc,
1845 hwnd, uMsg, wParam, lParam);
1849 * The following was determined by traces of the native
1852 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
1853 GetClientRect (hwnd, &rect);
1854 TRACE("erasing (%d,%d)-(%d,%d)\n",
1855 rect.left, rect.top, rect.right, rect.bottom);
1856 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1857 SetBkColor (hDC, obkc);
1858 return CallWindowProcW (infoPtr->prevComboWndProc,
1859 hwnd, uMsg, wParam, lParam);
1863 * WM_NOTIFY to comboex parent (rebar)
1864 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1865 * CallWindowProc (previous)
1867 nmmse.dwItemSpec = 0;
1868 nmmse.dwItemData = 0;
1871 nmmse.dwHitInfo = lParam;
1872 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1873 return CallWindowProcW (infoPtr->prevComboWndProc,
1874 hwnd, uMsg, wParam, lParam);
1877 switch (HIWORD(wParam)) {
1880 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1889 * GetFocus() retns AA
1890 * GetWindowTextA(Edit)
1891 * CB_GETCURSEL(Combo) (got -1)
1892 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1893 * CB_GETCURSEL(Combo) (got -1)
1894 * InvalidateRect(Combo, 0, 0)
1895 * WM_KILLFOCUS(Combo, AA)
1898 focusedhwnd = GetFocus();
1899 if (infoPtr->flags & WCBE_ACTEDIT) {
1900 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1901 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1902 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1903 CB_GETCURSEL, 0, 0);
1904 cbeend.iWhy = CBENF_KILLFOCUS;
1906 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1907 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1908 /* abort the change */
1909 TRACE("Notify requested abort of change\n");
1913 /* possible CB_GETCURSEL */
1914 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1916 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
1917 (WPARAM)focusedhwnd, 0);
1922 * For EN_SETFOCUS this issues the same calls and messages
1923 * as the native seems to do.
1925 * for some cases however native does the following:
1926 * (noticed after SetFocus during LBUTTONDOWN on
1927 * on dropdown arrow)
1928 * WM_GETTEXTLENGTH (Edit);
1929 * WM_GETTEXT (Edit, len+1, str);
1930 * EM_SETSEL (Edit, 0, 0);
1931 * WM_GETTEXTLENGTH (Edit);
1932 * WM_GETTEXT (Edit, len+1, str);
1933 * EM_SETSEL (Edit, 0, len);
1934 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
1938 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
1939 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
1940 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
1941 infoPtr->flags |= WCBE_ACTEDIT;
1942 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
1948 * For EN_CHANGE this issues the same calls and messages
1949 * as the native seems to do.
1951 WCHAR edit_text[260];
1956 selected = SendMessageW (infoPtr->hwndCombo,
1957 CB_GETCURSEL, 0, 0);
1959 /* lstrlenA( lastworkingURL ) */
1961 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1962 if (selected == -1) {
1963 lastwrk = infoPtr->edit->pszText;
1964 cnt = lstrlenW (lastwrk);
1965 if (cnt >= 259) cnt = 259;
1968 item = COMBOEX_FindItem (infoPtr, selected);
1969 cnt = lstrlenW (item->pszText);
1970 lastwrk = item->pszText;
1971 if (cnt >= 259) cnt = 259;
1974 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
1975 selected, debugstr_w(lastwrk));
1976 TRACE("handling EN_CHANGE, edittext=%s\n",
1977 debugstr_w(edit_text));
1979 /* lstrcmpiW is between lastworkingURL and GetWindowText */
1981 if (lstrcmpiW (lastwrk, edit_text)) {
1982 /* strings not equal -- indicate edit has changed */
1983 infoPtr->flags |= WCBE_EDITCHG;
1985 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
1986 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
1994 * Therefore from traces there is no additional code here
1998 * Using native COMCTL32 gets the following:
1999 * 1 == SHDOCVW.DLL issues call/message
2000 * 2 == COMCTL32.DLL issues call/message
2001 * 3 == WINE issues call/message
2004 * for LBN_SELCHANGE:
2005 * 1 CB_GETCURSEL(ComboEx)
2006 * 1 CB_GETDROPPEDSTATE(ComboEx)
2007 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2008 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2009 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2010 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2011 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2012 * 3 ShowWindow(ComboLB, SW_HIDE)
2013 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2014 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2016 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2017 * ? LB_GETCURSEL <==|
2019 * ? LB_GETTEXT | Needs to be added to
2020 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2021 * ? LB_GETITEMDATA |
2022 * ? WM_DRAWITEM(ComboEx) <==|
2028 return CallWindowProcW (infoPtr->prevComboWndProc,
2029 hwnd, uMsg, wParam, lParam);
2035 static LRESULT WINAPI
2036 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2038 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2040 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2043 if (uMsg == WM_CREATE)
2044 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2045 if (uMsg == WM_NCCREATE)
2046 COMBOEX_NCCreate (hwnd);
2047 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2052 case CBEM_DELETEITEM:
2053 return COMBOEX_DeleteItem (infoPtr, wParam);
2055 case CBEM_GETCOMBOCONTROL:
2056 return infoPtr->hwndCombo;
2058 case CBEM_GETEDITCONTROL:
2059 return infoPtr->hwndEdit;
2061 case CBEM_GETEXTENDEDSTYLE:
2062 return infoPtr->dwExtStyle;
2064 case CBEM_GETIMAGELIST:
2065 return (LRESULT)infoPtr->himl;
2068 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2071 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2073 case CBEM_GETUNICODEFORMAT:
2074 return infoPtr->unicode;
2076 case CBEM_HASEDITCHANGED:
2077 return COMBOEX_HasEditChanged (infoPtr);
2079 case CBEM_INSERTITEMA:
2080 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2082 case CBEM_INSERTITEMW:
2083 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2085 case CBEM_SETEXSTYLE:
2086 case CBEM_SETEXTENDEDSTYLE:
2087 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2089 case CBEM_SETIMAGELIST:
2090 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2093 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2096 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2098 case CBEM_SETUNICODEFORMAT:
2099 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2101 /* case CBEM_SETWINDOWTHEME: FIXME */
2103 /* Combo messages we are not sure if we need to process or just forward */
2104 case CB_GETDROPPEDCONTROLRECT:
2105 case CB_GETITEMHEIGHT:
2107 case CB_GETLBTEXTLEN:
2108 case CB_GETEXTENDEDUI:
2110 case CB_RESETCONTENT:
2111 case CB_SELECTSTRING:
2114 FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
2115 uMsg, wParam, lParam);
2117 /* Combo messages OK to just forward to the regular COMBO */
2120 case CB_GETDROPPEDSTATE:
2121 case CB_SETDROPPEDWIDTH:
2122 case CB_SETEXTENDEDUI:
2123 case CB_SHOWDROPDOWN:
2124 return COMBOEX_Forward (infoPtr, uMsg, wParam, lParam);
2126 /* Combo messages we need to process specially */
2127 case CB_FINDSTRINGEXACT:
2128 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCSTR)lParam);
2130 case CB_GETITEMDATA:
2131 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2134 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2136 case CB_SETITEMDATA:
2137 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD)lParam);
2139 case CB_SETITEMHEIGHT:
2140 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2144 /* Window messages passed to parent */
2146 return COMBOEX_Command (infoPtr, wParam, lParam);
2149 if (infoPtr->NtfUnicode)
2150 return SendMessageW (GetParent (hwnd), uMsg, wParam, lParam);
2152 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
2155 /* Window messages we need to process */
2157 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2160 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2163 return COMBOEX_Destroy (infoPtr);
2165 case WM_MEASUREITEM:
2166 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2168 case WM_NOTIFYFORMAT:
2169 return COMBOEX_NotifyFormat (infoPtr, lParam);
2172 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2174 case WM_WINDOWPOSCHANGING:
2175 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2178 if (uMsg >= WM_USER)
2179 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
2180 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2186 void COMBOEX_Register (void)
2190 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2191 wndClass.style = CS_GLOBALCLASS;
2192 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2193 wndClass.cbClsExtra = 0;
2194 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2195 wndClass.hCursor = LoadCursorW (0, IDC_ARROWW);
2196 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2197 wndClass.lpszClassName = WC_COMBOBOXEXW;
2199 RegisterClassW (&wndClass);
2203 void COMBOEX_Unregister (void)
2205 UnregisterClassW (WC_COMBOBOXEXW, (HINSTANCE)NULL);