Repaired shared PE data sections.
[wine/multimedia.git] / dlls / comctl32 / comboex.c
blobf69e12316a127475d562e6ce852b52b1079f3d50
1 /*
2 * TODO <-------------
3 * 1. The following extended styles need to be implemented, use will
4 * result in a FIXME:
5 * CBES_EX_NOEDITIMAGEINDENT
6 * CBES_EX_PATHWORDBREAKPROC
7 * CBES_EX_NOSIZELIMIT
8 * CBES_EX_CASESENSITIVE
9 * 2. None of the following callback items are implemented. Therefor
10 * no CBEN_GETDISPINFO notifies are issued. Use in either CBEM_INSERTITEM
11 * or CBEM_SETITEM will result in a FIXME:
12 * LPSTR_TEXTCALLBACK
13 * I_IMAGECALLBACK
14 * I_INDENTCALLBACK
15 * 3. No use is made of the iOverlay image.
16 * 4. Notify CBEN_DRAGBEGIN is not implemented.
21 * ComboBoxEx control v2 (mod4)
23 * Copyright 1998, 1999 Eric Kohl
25 * NOTES
26 * This is just a dummy control. An author is needed! Any volunteers?
27 * I will only improve this control once in a while.
28 * Eric <ekohl@abo.rhein-zeitung.de>
31 * Changes Guy Albertelli <galberte@neo.lrun.com>
32 * v1 Implemented messages: CB_SETITEMHEIGHT, WM_WINDOWPOSCHANGING,
33 * WM_DRAWITEM, and WM_MEASUREITEM. Fixed WM_CREATE. Fixed height
34 * of window rect reported fixing rebar control.
35 * v2
36 * 1. Rewrite of WM_Create for own created EDIT control. Also try to
37 * generate message sequence similar to native DLL.
38 * 2. Handle case where CBEM_SETITEM is called to display data in EDIT
39 * Control.
40 * 3. Add override for WNDPROC for the EDIT control (reqed for VK_RETURN).
41 * 4. Dump input data for things using COMBOBOXEXITEM{A|W}.
42 * 5. Handle positioning EDIT control based on whether icon present.
43 * 6. Make InsertItemA use InsertItemW, and store all data in ..W form.
44 * 7. Implement CBEM_DELETEITEM, CBEM_GETITEM{A|W}, CB_SETCURSEL,
45 * CBEM_{GET|SET}UNICODEFORMAT.
46 * 8. Add override for WNDPROC for the COMBO control.
47 * 9. Support extended style CBES_EX_NOEDITIMAGE and warn others are not
48 * supported.
49 * 10. Implement CB_FINDSTRINGEXACT in both the Combo and ComboEx window
50 * procs to match the items. This eliminates dup entries in the listbox.
52 * mod 4
53 * 1. Implemented CBN_SELCHANGE, CBN_KILLFOCUS, and CBN_SELENDOK.
54 * 2. Fix putting text in CBEN_ENDEDIT notifys for CBN_DROPDOWN case.
55 * 3. Lock image selected status to focus state of edit control if
56 * edit control exists. Mimics native actions.
57 * 4. Implemented WM_SETFOCUS in EditWndProc to track status of
58 * focus for 3 above.
59 * 5. The LBN_SELCHANGE is just for documentation purposes.
61 * Test vehicals were the ControlSpy modules (rebar.exe and comboboxex.exe),
62 * and IE 4.0.
66 #include <string.h>
67 #include "winbase.h"
68 #include "commctrl.h"
69 #include "debugtools.h"
70 #include "wine/unicode.h"
72 DEFAULT_DEBUG_CHANNEL(comboex);
74 * The following is necessary for the test done in COMBOEX_DrawItem
75 * to determine whether to dump out the DRAWITEM structure or not.
77 DECLARE_DEBUG_CHANNEL(message);
79 /* Item structure */
80 typedef struct
82 VOID *next;
83 UINT mask;
84 LPWSTR pszText;
85 int cchTextMax;
86 int iImage;
87 int iSelectedImage;
88 int iOverlay;
89 int iIndent;
90 LPARAM lParam;
91 } CBE_ITEMDATA;
93 /* ComboBoxEx structure */
94 typedef struct
96 HIMAGELIST himl;
97 HWND hwndSelf; /* my own hwnd */
98 HWND hwndCombo;
99 HWND hwndEdit;
100 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
101 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
102 DWORD dwExtStyle;
103 DWORD flags; /* WINE internal flags */
104 HFONT font;
105 INT nb_items; /* Number of items */
106 BOOL bUnicode; /* ASCII (FALSE) or Unicode (TRUE)? */
107 CBE_ITEMDATA *edit; /* item data for edit item */
108 CBE_ITEMDATA *items; /* Array of items */
109 } COMBOEX_INFO;
111 /* internal flags in the COMBOEX_INFO structure */
112 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
113 * CBEN_BEGINEDIT issued
114 * but CBEN_ENDEDIT{A|W}
115 * not yet issued. */
116 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
117 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
120 #define ID_CB_EDIT 1001
124 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
125 * the ComboEx version of the Combo Window Proc so that when the
126 * WM_DRAWITEM message is then passed to ComboEx, we know that this
127 * particular WM_DRAWITEM message is for listbox only items. Any messasges
128 * without this flag is then for the Edit control field.
130 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
131 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
133 #define ODS_COMBOEXLBOX 0x4000
137 /* Height in pixels of control over the amount of the selected font */
138 #define CBE_EXTRA 3
140 /* Indent amount per MS documentation */
141 #define CBE_INDENT 10
143 /* Offset in pixels from left side for start of image or text */
144 #define CBE_STARTOFFSET 6
146 /* Offset between image and text */
147 #define CBE_SEP 4
149 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
152 /* Things common to the entire DLL */
153 static ATOM ComboExInfo;
154 static LRESULT WINAPI
155 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
156 static LRESULT WINAPI
157 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
159 static void
160 COMBOEX_DumpItem (CBE_ITEMDATA *item)
162 if (TRACE_ON(comboex)){
163 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
164 item, item->mask, item->pszText, item->cchTextMax,
165 item->iImage);
166 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
167 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
168 if ((item->mask & CBEIF_TEXT) && item->pszText)
169 TRACE("item %p - pszText=%s\n",
170 item, debugstr_w((const WCHAR *)item->pszText));
175 static void
176 COMBOEX_DumpInput (COMBOBOXEXITEMA *input, BOOL true_for_w)
178 if (TRACE_ON(comboex)){
179 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
180 input->mask, input->iItem, input->pszText, input->cchTextMax,
181 input->iImage);
182 if ((input->mask & CBEIF_TEXT) && input->pszText) {
183 if (true_for_w)
184 TRACE("input - pszText=<%s>\n",
185 debugstr_w((const WCHAR *)input->pszText));
186 else
187 TRACE("input - pszText=<%s>\n",
188 debugstr_a((const char *)input->pszText));
190 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
191 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
196 inline static LRESULT
197 COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
199 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
201 if (infoPtr->hwndCombo)
202 return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
204 return 0;
208 static INT
209 COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr, BOOL doW)
212 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
213 hdr->hwndFrom = infoPtr->hwndSelf;
214 hdr->code = code;
215 if (doW)
216 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
217 (LPARAM)hdr);
218 else
219 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
220 (LPARAM)hdr);
224 static void
225 COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
227 HFONT nfont, ofont;
228 HDC mydc;
230 mydc = GetDC (0); /* why the entire screen???? */
231 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
232 ofont = (HFONT) SelectObject (mydc, nfont);
233 GetTextExtentPointA (mydc, "A", 1, size);
234 SelectObject (mydc, ofont);
235 ReleaseDC (0, mydc);
236 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
240 static void
241 COMBOEX_CopyItem (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
243 if (cit->mask & CBEIF_TEXT) {
244 cit->pszText = item->pszText;
245 cit->cchTextMax = item->cchTextMax;
247 if (cit->mask & CBEIF_IMAGE)
248 cit->iImage = item->iImage;
249 if (cit->mask & CBEIF_SELECTEDIMAGE)
250 cit->iSelectedImage = item->iSelectedImage;
251 if (cit->mask & CBEIF_OVERLAY)
252 cit->iOverlay = item->iOverlay;
253 if (cit->mask & CBEIF_INDENT)
254 cit->iIndent = item->iIndent;
255 if (cit->mask & CBEIF_LPARAM)
256 cit->lParam = item->lParam;
261 static void
262 COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
264 SIZE mysize;
265 IMAGEINFO iinfo;
266 INT x, y, w, h, xoff = 0;
267 RECT rect;
269 if (!infoPtr->hwndEdit) return;
270 iinfo.rcImage.left = iinfo.rcImage.right = 0;
271 if (infoPtr->himl) {
272 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
273 xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
275 GetClientRect (infoPtr->hwndCombo, &rect);
276 InflateRect (&rect, -2, -2);
277 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
279 /* reposition the Edit control based on whether icon exists */
280 COMBOEX_GetComboFontSize (infoPtr, &mysize);
281 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
282 x = xoff + CBE_STARTOFFSET + 1;
283 y = CBE_EXTRA + 1;
284 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
285 h = mysize.cy + 1;
287 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
288 rect.left, rect.top, rect.right, rect.bottom,
289 x, y, x + w, y + h);
290 SetWindowPos(infoPtr->hwndEdit, HWND_TOP,
291 x, y,
292 w, h,
293 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
297 static void
298 COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
300 SIZE mysize;
301 UINT cy;
302 IMAGEINFO iinfo;
304 COMBOEX_GetComboFontSize (infoPtr, &mysize);
305 cy = mysize.cy + CBE_EXTRA;
306 if (infoPtr->himl) {
307 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
308 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
309 TRACE("upgraded height due to image: height=%d\n", cy);
311 SendMessageW (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
312 if (infoPtr->hwndCombo)
313 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
314 (WPARAM) 0, (LPARAM) cy);
318 static void
319 COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
321 if (!infoPtr->hwndEdit) return;
322 /* native issues the following messages to the {Edit} control */
323 /* WM_SETTEXT (0,addr) */
324 /* EM_SETSEL32 (0,0) */
325 /* EM_SETSEL32 (0,-1) */
326 if (item->mask & CBEIF_TEXT) {
327 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
328 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
329 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
334 static CBE_ITEMDATA *
335 COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
337 CBE_ITEMDATA *item;
338 INT i;
340 if ((index > infoPtr->nb_items) || (index < -1))
341 return 0;
342 if (index == -1)
343 return infoPtr->edit;
344 item = infoPtr->items;
345 i = infoPtr->nb_items - 1;
347 /* find the item in the list */
348 while (item && (i > index)) {
349 item = (CBE_ITEMDATA *)item->next;
350 i--;
352 if (!item || (i != index)) {
353 FIXME("COMBOBOXEX item structures broken. Please report!\n");
354 return 0;
356 return item;
360 static void
361 COMBOEX_WarnCallBack (CBE_ITEMDATA *item)
363 if (item->pszText == LPSTR_TEXTCALLBACKW)
364 FIXME("Callback not implemented yet for pszText\n");
365 if (item->iImage == I_IMAGECALLBACK)
366 FIXME("Callback not implemented yet for iImage\n");
367 if (item->iSelectedImage == I_IMAGECALLBACK)
368 FIXME("Callback not implemented yet for iSelectedImage\n");
369 if (item->iOverlay == I_IMAGECALLBACK)
370 FIXME("Callback not implemented yet for iOverlay\n");
371 if (item->iIndent == I_INDENTCALLBACK)
372 FIXME("Callback not implemented yet for iIndent\n");
376 /* *** CBEM_xxx message support *** */
379 static LRESULT
380 COMBOEX_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
382 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
383 INT index = (INT) wParam;
384 CBE_ITEMDATA *item;
386 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
388 /* if item number requested does not exist then return failure */
389 if ((index > infoPtr->nb_items) || (index < 0)) {
390 ERR("attempt to delete item that does not exist\n");
391 return CB_ERR;
394 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
395 ERR("attempt to delete item that was not found!\n");
396 return CB_ERR;
399 /* doing this will result in WM_DELETEITEM being issued */
400 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
402 return infoPtr->nb_items;
406 inline static LRESULT
407 COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
409 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
411 TRACE("\n");
413 return (LRESULT)infoPtr->hwndCombo;
417 inline static LRESULT
418 COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
420 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
422 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
423 return 0;
425 TRACE("-- 0x%x\n", infoPtr->hwndEdit);
427 return (LRESULT)infoPtr->hwndEdit;
431 inline static LRESULT
432 COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
434 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
436 TRACE("-- 0x%08lx\n", infoPtr->dwExtStyle);
438 return (LRESULT)infoPtr->dwExtStyle;
442 inline static LRESULT
443 COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
445 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
447 TRACE("-- 0x%p\n", infoPtr->himl);
449 return (LRESULT)infoPtr->himl;
453 static LRESULT
454 COMBOEX_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
456 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
457 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
458 INT index;
459 CBE_ITEMDATA *item;
461 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
463 /* get real index of item to insert */
464 index = cit->iItem;
466 /* if item number requested does not exist then return failure */
467 if ((index > infoPtr->nb_items) || (index < -1)) {
468 ERR("attempt to get item that does not exist\n");
469 return 0;
472 /* if the item is the edit control and there is no edit control, skip */
473 if ((index == -1) &&
474 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
475 return 0;
477 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
478 ERR("attempt to get item that was not found!\n");
479 return 0;
482 COMBOEX_CopyItem (infoPtr, item, cit);
484 return TRUE;
488 inline static LRESULT
489 COMBOEX_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
491 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
492 COMBOBOXEXITEMW tmpcit;
493 INT len;
495 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
497 tmpcit.mask = cit->mask;
498 tmpcit.iItem = cit->iItem;
499 COMBOEX_GetItemW (hwnd, wParam, (LPARAM) &tmpcit);
501 len = WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1, 0, 0, NULL, NULL);
502 if (len > 0)
503 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
504 cit->pszText, cit->cchTextMax, NULL, NULL);
506 cit->iImage = tmpcit.iImage;
507 cit->iSelectedImage = tmpcit.iSelectedImage;
508 cit->iOverlay = tmpcit.iOverlay;
509 cit->iIndent = tmpcit.iIndent;
510 cit->lParam = tmpcit.lParam;
512 return TRUE;
516 inline static LRESULT
517 COMBOEX_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
519 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
521 TRACE("%s hwnd=0x%x stub!\n",
522 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
524 return infoPtr->bUnicode;
528 inline static LRESULT
529 COMBOEX_HasEditChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
531 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
533 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
534 return FALSE;
535 if ((infoPtr->flags & (WCBE_ACTEDIT | WCBE_EDITCHG)) ==
536 (WCBE_ACTEDIT | WCBE_EDITCHG))
537 return TRUE;
538 return FALSE;
542 static LRESULT
543 COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
545 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
546 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
547 INT index;
548 CBE_ITEMDATA *item;
549 NMCOMBOBOXEXW nmcit;
551 TRACE("\n");
553 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
555 /* get real index of item to insert */
556 index = cit->iItem;
557 if (index == -1) index = infoPtr->nb_items;
558 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
560 /* get space and chain it in */
561 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
562 item->next = NULL;
563 item->pszText = NULL;
565 /* locate position to insert new item in */
566 if (index == infoPtr->nb_items) {
567 /* fast path for iItem = -1 */
568 item->next = infoPtr->items;
569 infoPtr->items = item;
571 else {
572 INT i = infoPtr->nb_items-1;
573 CBE_ITEMDATA *moving = infoPtr->items;
575 while ((i > index) && moving) {
576 moving = (CBE_ITEMDATA *)moving->next;
577 i--;
579 if (!moving) {
580 FIXME("COMBOBOXEX item structures broken. Please report!\n");
581 COMCTL32_Free(item);
582 return -1;
584 item->next = moving->next;
585 moving->next = item;
588 /* fill in our hidden item structure */
589 item->mask = cit->mask;
590 if (item->mask & CBEIF_TEXT) {
591 LPWSTR str;
592 INT len;
594 str = cit->pszText;
595 if (!str) str = (LPWSTR) L"";
596 len = strlenW (str);
597 if (len > 0) {
598 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
599 strcpyW (item->pszText, str);
601 item->cchTextMax = cit->cchTextMax;
603 if (item->mask & CBEIF_IMAGE)
604 item->iImage = cit->iImage;
605 if (item->mask & CBEIF_SELECTEDIMAGE)
606 item->iSelectedImage = cit->iSelectedImage;
607 if (item->mask & CBEIF_OVERLAY)
608 item->iOverlay = cit->iOverlay;
609 if (item->mask & CBEIF_INDENT)
610 item->iIndent = cit->iIndent;
611 if (item->mask & CBEIF_LPARAM)
612 item->lParam = cit->lParam;
613 infoPtr->nb_items++;
615 COMBOEX_WarnCallBack (item);
617 COMBOEX_DumpItem (item);
619 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
620 (WPARAM)cit->iItem, (LPARAM)item);
622 COMBOEX_CopyItem (infoPtr, item, &nmcit.ceItem);
623 COMBOEX_Notify (infoPtr, CBEN_INSERTITEM, (NMHDR *)&nmcit, TRUE);
625 return index;
630 static LRESULT
631 COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
633 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
634 COMBOBOXEXITEMW citW;
635 LRESULT ret;
637 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
638 if (cit->mask & CBEIF_TEXT) {
639 LPSTR str;
640 INT len;
642 str = cit->pszText;
643 if (!str) str="";
644 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
645 if (len > 0) {
646 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
647 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
650 ret = COMBOEX_InsertItemW(hwnd,wParam,(LPARAM)&citW);;
652 if (cit->mask & CBEIF_TEXT)
653 COMCTL32_Free(citW.pszText);
654 return ret;
658 static LRESULT
659 COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
661 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
662 DWORD dwTemp;
664 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
666 dwTemp = infoPtr->dwExtStyle;
668 if (lParam & (CBES_EX_NOEDITIMAGEINDENT |
669 CBES_EX_PATHWORDBREAKPROC |
670 CBES_EX_NOSIZELIMIT |
671 CBES_EX_CASESENSITIVE))
672 FIXME("Extended style not implemented %08lx\n", lParam);
674 if ((DWORD)wParam) {
675 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
677 else
678 infoPtr->dwExtStyle = (DWORD)lParam;
681 * native does this for CBES_EX_NOEDITIMAGE state change
683 if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
684 (dwTemp & CBES_EX_NOEDITIMAGE)) {
685 /* if state of EX_NOEDITIMAGE changes, invalidate all */
686 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
687 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
688 InvalidateRect (hwnd, NULL, TRUE);
689 COMBOEX_AdjustEditPos (infoPtr);
690 if (infoPtr->hwndEdit)
691 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
694 return (LRESULT)dwTemp;
698 inline static LRESULT
699 COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
701 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
702 HIMAGELIST himlTemp;
704 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
706 himlTemp = infoPtr->himl;
707 infoPtr->himl = (HIMAGELIST)lParam;
709 COMBOEX_ReSize (hwnd, infoPtr);
710 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
712 /* reposition the Edit control based on whether icon exists */
713 COMBOEX_AdjustEditPos (infoPtr);
714 return (LRESULT)himlTemp;
717 static LRESULT
718 COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
720 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
721 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
722 INT index;
723 CBE_ITEMDATA *item;
725 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
727 /* get real index of item to insert */
728 index = cit->iItem;
730 /* if item number requested does not exist then return failure */
731 if ((index > infoPtr->nb_items) || (index < -1)) {
732 ERR("attempt to set item that does not exist yet!\n");
733 return 0;
736 /* if the item is the edit control and there is no edit control, skip */
737 if ((index == -1) &&
738 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
739 return 0;
741 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
742 ERR("attempt to set item that was not found!\n");
743 return 0;
746 /* add/change stuff to the internal item structure */
747 item->mask |= cit->mask;
748 if (cit->mask & CBEIF_TEXT) {
749 LPWSTR str;
750 INT len;
751 WCHAR emptystr[1] = {0};
753 str = cit->pszText;
754 if (!str) str=emptystr;
755 len = strlenW(str);
756 if (len > 0) {
757 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
758 strcpyW(item->pszText,str);
760 item->cchTextMax = cit->cchTextMax;
762 if (cit->mask & CBEIF_IMAGE)
763 item->iImage = cit->iImage;
764 if (cit->mask & CBEIF_SELECTEDIMAGE)
765 item->iSelectedImage = cit->iSelectedImage;
766 if (cit->mask & CBEIF_OVERLAY)
767 item->iOverlay = cit->iOverlay;
768 if (cit->mask & CBEIF_INDENT)
769 item->iIndent = cit->iIndent;
770 if (cit->mask & CBEIF_LPARAM)
771 cit->lParam = cit->lParam;
773 COMBOEX_WarnCallBack (item);
775 COMBOEX_DumpItem (item);
777 /* if original request was to update edit control, do some fast foot work */
778 if (cit->iItem == -1) {
779 COMBOEX_SetEditText (infoPtr, item);
780 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
782 return TRUE;
785 static LRESULT
786 COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
788 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
789 COMBOBOXEXITEMW citW;
790 LRESULT ret;
792 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
793 if (cit->mask & CBEIF_TEXT) {
794 LPSTR str;
795 INT len;
797 str = cit->pszText;
798 if (!str) str="";
799 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
800 if (len > 0) {
801 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
802 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
805 ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
807 if (cit->mask & CBEIF_TEXT)
808 COMCTL32_Free(citW.pszText);
809 return ret;
813 inline static LRESULT
814 COMBOEX_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
816 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
817 BOOL bTemp;
819 TRACE("%s hwnd=0x%04x stub!\n",
820 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd);
822 bTemp = infoPtr->bUnicode;
823 infoPtr->bUnicode = (BOOL)wParam;
825 return bTemp;
830 /* *** CB_xxx message support *** */
833 static LRESULT
834 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
836 INT i, count;
837 CBE_ITEMDATA *item;
838 LPWSTR desired = NULL;
839 INT start = (INT) wParam;
841 i = MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
842 if (i > 0) {
843 desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
844 MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, desired, i);
847 count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0 , 0);
849 /* now search from after starting loc and wrapping back to start */
850 for(i=start+1; i<count; i++) {
851 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
852 CB_GETITEMDATA, (WPARAM)i, 0);
853 TRACE("desired=%s, item=%s\n",
854 debugstr_w(desired), debugstr_w(item->pszText));
855 if (lstrcmpiW(item->pszText, desired) == 0) {
856 COMCTL32_Free (desired);
857 return i;
860 for(i=0; i<=start; i++) {
861 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
862 CB_GETITEMDATA, (WPARAM)i, 0);
863 TRACE("desired=%s, item=%s\n",
864 debugstr_w(desired), debugstr_w(item->pszText));
865 if (lstrcmpiW(item->pszText, desired) == 0) {
866 COMCTL32_Free (desired);
867 return i;
870 COMCTL32_Free(desired);
871 return CB_ERR;
875 static LRESULT
876 COMBOEX_SetCursel (HWND hwnd, WPARAM wParam, LPARAM lParam)
878 INT index = wParam;
879 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
880 CBE_ITEMDATA *item;
881 LRESULT lret;
883 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
884 /* FIXME: need to clear selection */
885 return CB_ERR;
888 TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
889 debugstr_w(item->pszText) : "<null>");
891 lret = SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, wParam, lParam);
892 COMBOEX_SetEditText (infoPtr, item);
893 return lret;
897 static LRESULT
898 COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
900 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
901 RECT cb_wrect, cbx_wrect, cbx_crect;
902 LRESULT ret = 0;
903 UINT height;
905 /* First, lets forward the message to the normal combo control
906 just like Windows. */
907 if (infoPtr->hwndCombo)
908 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
910 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
911 GetWindowRect (hwnd, &cbx_wrect);
912 GetClientRect (hwnd, &cbx_crect);
913 /* the height of comboex as height of the combo + comboex border */
914 height = cb_wrect.bottom-cb_wrect.top
915 + cbx_wrect.bottom-cbx_wrect.top
916 - (cbx_crect.bottom-cbx_crect.top);
917 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
918 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
919 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
920 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
921 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
922 cbx_wrect.right-cbx_wrect.left, height);
923 SetWindowPos (hwnd, HWND_TOP, 0, 0,
924 cbx_wrect.right-cbx_wrect.left,
925 height,
926 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
928 return ret;
932 /* *** WM_xxx message support *** */
935 static LRESULT
936 COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
938 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
939 COMBOEX_INFO *infoPtr;
940 DWORD dwComboStyle;
941 LOGFONTA mylogfont;
942 CBE_ITEMDATA *item;
943 RECT wnrc1, clrc1, cmbwrc;
944 LONG test;
946 /* allocate memory for info structure */
947 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
948 if (infoPtr == NULL) {
949 ERR("could not allocate info memory!\n");
950 return 0;
953 /* initialize info structure */
955 infoPtr->items = NULL;
956 infoPtr->nb_items = 0;
957 infoPtr->hwndSelf = hwnd;
959 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
961 /* create combo box */
962 dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
963 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
965 TRACE("combo style=%08lx, additional style=%08lx\n", dwComboStyle,
966 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
967 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
968 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED);
970 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
971 /* specified. It then creates it's own version of the EDIT control */
972 /* and makes the ComboBox the parent. This is because a normal */
973 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
974 /* We also need to place the edit control at the proper location */
975 /* (allow space for the icons). */
977 infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
978 /* following line added to match native */
979 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
980 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
981 /* was base and is necessary */
982 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
983 cs->y, cs->x, cs->cx, cs->cy, hwnd,
984 (HMENU) GetWindowLongA (hwnd, GWL_ID),
985 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
988 * native does the following at this point according to trace:
989 * GetWindowThreadProcessId(hwndCombo,0)
990 * GetCurrentThreadId()
991 * GetWindowThreadProcessId(hwndCombo, &???)
992 * GetCurrentProcessId()
996 * Setup a property to hold the pointer to the COMBOBOXEX
997 * data structure.
999 test = GetPropA(infoPtr->hwndCombo, (LPCSTR)(LONG)ComboExInfo);
1000 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1001 SetPropA(infoPtr->hwndCombo, "CC32SubclassInfo", (LONG)infoPtr);
1003 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndCombo,
1004 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
1005 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1009 * Now create our own EDIT control so we can position it.
1010 * It is created only for CBS_DROPDOWN style
1012 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1013 infoPtr->hwndEdit = CreateWindowExA (0, "EDIT", "",
1014 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1015 0, 0, 0, 0, /* will set later */
1016 infoPtr->hwndCombo,
1017 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1018 GetWindowLongA (hwnd, GWL_HINSTANCE),
1019 NULL);
1021 /* native does the following at this point according to trace:
1022 * GetWindowThreadProcessId(hwndEdit,0)
1023 * GetCurrentThreadId()
1024 * GetWindowThreadProcessId(hwndEdit, &???)
1025 * GetCurrentProcessId()
1029 * Setup a property to hold the pointer to the COMBOBOXEX
1030 * data structure.
1032 test = GetPropA(infoPtr->hwndEdit, (LPCSTR)(LONG)ComboExInfo);
1033 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1034 SetPropA(infoPtr->hwndEdit, "CC32SubclassInfo", (LONG)infoPtr);
1036 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndEdit,
1037 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1038 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1040 else {
1041 infoPtr->hwndEdit = 0;
1042 infoPtr->font = 0;
1046 * Locate the default font if necessary and then set it in
1047 * all associated controls
1049 if (!infoPtr->font) {
1050 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1051 &mylogfont, 0);
1052 infoPtr->font = CreateFontIndirectA (&mylogfont);
1054 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1055 if (infoPtr->hwndEdit) {
1056 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1057 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1060 COMBOEX_ReSize (hwnd, infoPtr);
1062 /* Above is fairly certain, below is much less certain. */
1064 GetWindowRect(hwnd, &wnrc1);
1065 GetClientRect(hwnd, &clrc1);
1066 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1067 TRACE("Ex wnd=(%d,%d)-(%d,%d) Ex clt=(%d,%d)-(%d,%d) Cb wnd=(%d,%d)-(%d,%d)\n",
1068 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1069 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1070 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1071 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1072 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1073 SWP_NOACTIVATE | SWP_NOREDRAW);
1075 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1076 TRACE("Ex wnd=(%d,%d)-(%d,%d)\n",
1077 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1078 SetWindowPos(hwnd, HWND_TOP,
1079 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1080 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1082 COMBOEX_AdjustEditPos (infoPtr);
1085 * Create an item structure to represent the data in the
1086 * EDIT control.
1088 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1089 item->next = NULL;
1090 item->pszText = NULL;
1091 item->mask = 0;
1092 infoPtr->edit = item;
1094 return 0;
1098 inline static LRESULT
1099 COMBOEX_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
1101 LRESULT lret;
1102 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1103 INT command = HIWORD(wParam);
1104 CBE_ITEMDATA *item = 0;
1105 WCHAR wintext[520];
1106 INT cursel, n, oldItem;
1107 NMCBEENDEDITA cbeend;
1109 TRACE("for command %d\n", command);
1111 switch (command)
1113 case CBN_DROPDOWN:
1114 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1115 (LPARAM)hwnd);
1117 * from native trace of first dropdown after typing in URL in IE4
1118 * CB_GETCURSEL(Combo)
1119 * GetWindowText(Edit)
1120 * CB_GETCURSEL(Combo)
1121 * CB_GETCOUNT(Combo)
1122 * CB_GETITEMDATA(Combo, n)
1123 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1124 * CB_GETCURSEL(Combo)
1125 * CB_SETCURSEL(COMBOEX, n)
1126 * SetFocus(Combo)
1127 * the rest is supposition
1129 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1130 if (cursel == -1) {
1131 /* find match from edit against those in Combobox */
1132 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1133 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1134 for (cursel = 0; cursel < n; cursel++){
1135 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1136 CB_GETITEMDATA,
1137 cursel, 0);
1138 if ((INT)item == CB_ERR) break;
1139 if (lstrcmpiW(item->pszText, wintext) == 0) break;
1141 if ((cursel == n) || ((INT)item == CB_ERR)) {
1142 TRACE("failed to find match??? item=%p cursel=%d\n",
1143 item, cursel);
1144 if (infoPtr->hwndEdit)
1145 SetFocus(infoPtr->hwndEdit);
1146 return 0;
1149 else {
1150 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1151 CB_GETITEMDATA,
1152 cursel, 0);
1153 if ((INT)item == CB_ERR) {
1154 TRACE("failed to find match??? item=%p cursel=%d\n",
1155 item, cursel);
1156 if (infoPtr->hwndEdit)
1157 SetFocus(infoPtr->hwndEdit);
1158 return 0;
1161 if (infoPtr->flags & WCBE_ACTEDIT) {
1162 WideCharToMultiByte (CP_ACP, 0, item->pszText, -1,
1163 cbeend.szText, sizeof(cbeend.szText),
1164 NULL, NULL);
1165 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1166 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1167 CB_GETCURSEL, 0, 0);
1168 cbeend.iWhy = CBENF_DROPDOWN;
1170 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1171 if (COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1172 (NMHDR *)&cbeend, FALSE)) {
1173 /* abort the change */
1174 TRACE("Notify requested abort of change\n");
1175 return 0;
1178 SendMessageW (hwnd, CB_SETCURSEL, cursel, 0);
1179 SetFocus(infoPtr->hwndCombo);
1180 return 0;
1182 case CBN_SELCHANGE:
1184 * CB_GETCURSEL(Combo)
1185 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1186 * lstrlenA
1187 * WM_SETTEXT(Edit)
1188 * WM_GETTEXTLENGTH(Edit)
1189 * WM_GETTEXT(Edit)
1190 * EM_SETSEL(Edit, 0,0)
1191 * WM_GETTEXTLENGTH(Edit)
1192 * WM_GETTEXT(Edit)
1193 * EM_SETSEL(Edit, 0,len)
1194 * return WM_COMMAND to parent
1196 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1197 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1198 ERR("item %d not found. Problem!\n", oldItem);
1199 break;
1201 COMBOEX_SetEditText (infoPtr, item);
1202 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1203 (LPARAM)hwnd);
1205 case CBN_SELENDOK:
1207 * We have to change the handle since we are the control
1208 * issuing the message. IE4 depends on this.
1210 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1211 (LPARAM)hwnd);
1213 case CBN_KILLFOCUS:
1215 * from native trace:
1217 * pass to parent
1218 * WM_GETTEXT(Edit, 104)
1219 * CB_GETCURSEL(Combo) rets -1
1220 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1221 * CB_GETCURSEL(Combo)
1222 * InvalidateRect(Combo, 0, 0)
1223 * return 0
1225 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1226 (LPARAM)hwnd);
1227 if (infoPtr->flags & WCBE_ACTEDIT) {
1228 GetWindowTextA (infoPtr->hwndEdit, cbeend.szText, 260);
1229 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1230 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1231 CB_GETCURSEL, 0, 0);
1232 cbeend.iWhy = CBENF_KILLFOCUS;
1234 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1235 if (COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1236 (NMHDR *)&cbeend, FALSE)) {
1237 /* abort the change */
1238 TRACE("Notify requested abort of change\n");
1239 return 0;
1242 /* possible CB_GETCURSEL */
1243 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1244 return 0;
1246 case CBN_CLOSEUP:
1247 default:
1249 * We have to change the handle since we are the control
1250 * issuing the message. IE4 depends on this.
1251 * We also need to set the focus back to the Edit control
1252 * after passing the command to the parent of the ComboEx.
1254 lret = SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1255 (LPARAM)hwnd);
1256 if (infoPtr->hwndEdit)
1257 SetFocus(infoPtr->hwndEdit);
1258 return lret;
1260 return 0;
1264 inline static LRESULT
1265 COMBOEX_WM_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1267 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1268 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)lParam;
1269 CBE_ITEMDATA *item, *olditem;
1270 INT i;
1271 NMCOMBOBOXEXW nmcit;
1273 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1274 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1276 if ((dis->itemID >= infoPtr->nb_items) || (dis->itemID < 0)) return FALSE;
1278 olditem = infoPtr->items;
1279 i = infoPtr->nb_items - 1;
1281 if (i == dis->itemID) {
1282 infoPtr->items = infoPtr->items->next;
1284 else {
1285 item = olditem;
1286 i--;
1288 /* find the prior item in the list */
1289 while (item->next && (i > dis->itemID)) {
1290 item = (CBE_ITEMDATA *)item->next;
1291 i--;
1293 if (!item->next || (i != dis->itemID)) {
1294 FIXME("COMBOBOXEX item structures broken. Please report!\n");
1295 return FALSE;
1297 olditem = item->next;
1298 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1300 infoPtr->nb_items--;
1302 COMBOEX_CopyItem (infoPtr, olditem, &nmcit.ceItem);
1303 COMBOEX_Notify (infoPtr, CBEN_DELETEITEM, (NMHDR *)&nmcit, TRUE);
1305 COMCTL32_Free(olditem);
1307 return TRUE;
1312 inline static LRESULT
1313 COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1315 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1316 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
1317 CBE_ITEMDATA *item = 0;
1318 SIZE txtsize;
1319 RECT rect;
1320 int drawimage, drawstate;
1321 UINT xbase;
1322 UINT xioff = 0; /* size and spacer of image if any */
1323 IMAGEINFO iinfo;
1324 INT len;
1326 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1328 /* MSDN says: */
1329 /* "itemID - Specifies the menu item identifier for a menu */
1330 /* item or the index of the item in a list box or combo box. */
1331 /* For an empty list box or combo box, this member can be -1. */
1332 /* This allows the application to draw only the focus */
1333 /* rectangle at the coordinates specified by the rcItem */
1334 /* member even though there are no items in the control. */
1335 /* This indicates to the user whether the list box or combo */
1336 /* box has the focus. How the bits are set in the itemAction */
1337 /* member determines whether the rectangle is to be drawn as */
1338 /* though the list box or combo box has the focus. */
1339 if (dis->itemID == 0xffffffff) {
1340 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1341 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1343 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1344 dis->rcItem.left, dis->rcItem.top,
1345 dis->rcItem.right, dis->rcItem.bottom);
1347 else if ((dis->CtlType == ODT_COMBOBOX) &&
1348 (dis->itemAction == ODA_DRAWENTIRE)) {
1349 /* draw of edit control data */
1351 /* testing */
1353 RECT exrc, cbrc, edrc;
1354 GetWindowRect (hwnd, &exrc);
1355 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1356 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1357 if (infoPtr->hwndEdit)
1358 GetWindowRect (infoPtr->hwndEdit, &edrc);
1359 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1360 exrc.left, exrc.top, exrc.right, exrc.bottom,
1361 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1362 edrc.left, edrc.top, edrc.right, edrc.bottom);
1365 else {
1366 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1367 dis->rcItem.left, dis->rcItem.top,
1368 dis->rcItem.right, dis->rcItem.bottom,
1369 dis->itemAction, dis->itemState);
1370 return 0;
1374 /* If draw item is -1 (edit control) setup the item pointer */
1375 if (dis->itemID == 0xffffffff) {
1376 CHAR str[260];
1377 INT wlen, alen;
1379 if (!infoPtr->hwndEdit) {
1380 ERR("request to draw edit item, but no edit control exists!\n");
1381 return 0;
1384 item = infoPtr->edit;
1385 /* free previous text of edit item */
1386 if (item->pszText) {
1387 COMCTL32_Free(item->pszText);
1388 item->pszText = 0;
1389 item->mask &= ~CBEIF_TEXT;
1391 alen = SendMessageA (infoPtr->hwndEdit, WM_GETTEXT, 260, (LPARAM)&str);
1392 TRACE("edit control hwndEdit=%0x, text len=%d str=<%s>\n",
1393 infoPtr->hwndEdit, alen, str);
1394 if (alen > 0) {
1395 item->mask |= CBEIF_TEXT;
1396 wlen = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
1397 if (wlen > 0) {
1398 item->pszText = (LPWSTR)COMCTL32_Alloc ((wlen + 1)*sizeof(WCHAR));
1399 MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, wlen);
1404 /* if the item pointer is not set, then get the data and locate it */
1405 if (!item) {
1406 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1407 CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
1408 if (item == (CBE_ITEMDATA *)CB_ERR)
1410 FIXME("invalid item for id %d \n",dis->itemID);
1411 return 0;
1415 /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
1416 if (!TRACE_ON(message)) {
1417 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1418 dis->CtlType, dis->CtlID);
1419 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1420 dis->itemID, dis->itemAction, dis->itemState);
1421 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1422 dis->hwndItem, dis->hDC, dis->rcItem.left,
1423 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1424 dis->itemData);
1426 COMBOEX_DumpItem (item);
1428 xbase = CBE_STARTOFFSET;
1429 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
1430 xbase += (item->iIndent * CBE_INDENT);
1431 if (item->mask & CBEIF_IMAGE) {
1432 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
1433 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
1436 switch (dis->itemAction) {
1437 case ODA_FOCUS:
1438 if (dis->itemState & ODS_SELECTED /*1*/) {
1439 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1440 RECT rect2;
1442 len = strlenW (item->pszText);
1443 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1444 rect.left = xbase + xioff - 1;
1445 rect.right = rect.left + txtsize.cx + 2;
1446 rect.top = dis->rcItem.top;
1447 rect.bottom = dis->rcItem.bottom;
1448 GetClipBox (dis->hDC, &rect2);
1449 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
1450 dis->itemID, rect.left, rect.top,
1451 rect.right, rect.bottom);
1452 TRACE(" clip=(%d,%d)-(%d,%d)\n",
1453 rect2.left, rect2.top,
1454 rect2.right, rect2.bottom);
1456 DrawFocusRect(dis->hDC, &rect);
1458 else {
1459 FIXME("ODA_FOCUS and ODS_SELECTED but no text\n");
1462 else {
1463 FIXME("ODA_FOCUS but not ODS_SELECTED\n");
1465 break;
1466 case ODA_SELECT:
1467 case ODA_DRAWENTIRE:
1468 drawimage = -1;
1469 drawstate = ILD_NORMAL;
1470 if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
1471 if (item->mask & CBEIF_IMAGE)
1472 drawimage = item->iImage;
1473 if (dis->itemState & ODS_COMBOEXLBOX) {
1474 /* drawing listbox entry */
1475 if (dis->itemState & ODS_SELECTED) {
1476 if (item->mask & CBEIF_SELECTEDIMAGE)
1477 drawimage = item->iSelectedImage;
1478 drawstate = ILD_SELECTED;
1481 else {
1482 /* drawing combo/edit entry */
1483 if (infoPtr->hwndEdit) {
1484 /* if we have an edit control, the slave the
1485 * selection state to the Edit focus state
1487 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1488 if (item->mask & CBEIF_SELECTEDIMAGE)
1489 drawimage = item->iSelectedImage;
1490 drawstate = ILD_SELECTED;
1493 else {
1494 /* if we don't have an edit control, use
1495 * the requested state.
1497 if (dis->itemState & ODS_SELECTED) {
1498 if (item->mask & CBEIF_SELECTEDIMAGE)
1499 drawimage = item->iSelectedImage;
1500 drawstate = ILD_SELECTED;
1505 if (drawimage != -1) {
1506 TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
1507 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
1508 xbase, dis->rcItem.top, drawstate);
1510 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1511 UINT x, y;
1512 COLORREF nbkc, ntxc;
1514 len = lstrlenW (item->pszText);
1515 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1516 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1517 COLOR_HIGHLIGHT : COLOR_WINDOW);
1518 SetBkColor (dis->hDC, nbkc);
1519 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1520 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1521 SetTextColor (dis->hDC, ntxc);
1522 x = xbase + xioff;
1523 y = dis->rcItem.top +
1524 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1525 rect.left = x;
1526 rect.right = x + txtsize.cx;
1527 rect.top = dis->rcItem.top + 1;
1528 rect.bottom = dis->rcItem.bottom - 1;
1529 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1530 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1531 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1532 &rect, item->pszText, len, 0);
1533 if (dis->itemState & ODS_FOCUS) {
1534 rect.top -= 1;
1535 rect.bottom += 1;
1536 rect.left -= 1;
1537 rect.right += 1;
1538 TRACE("drawing item %d focus after text, rect=(%d,%d)-(%d,%d)\n",
1539 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1540 DrawFocusRect (dis->hDC, &rect);
1543 break;
1544 default:
1545 FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
1546 hwnd, wParam, lParam, dis->itemAction);
1549 return 0;
1553 static LRESULT
1554 COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1556 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1558 if (infoPtr->hwndCombo)
1559 DestroyWindow (infoPtr->hwndCombo);
1561 if (infoPtr->edit) {
1562 COMCTL32_Free (infoPtr->edit);
1563 infoPtr->edit = 0;
1566 if (infoPtr->items) {
1567 CBE_ITEMDATA *this, *next;
1569 this = infoPtr->items;
1570 while (this) {
1571 next = (CBE_ITEMDATA *)this->next;
1572 if ((this->mask & CBEIF_TEXT) && this->pszText)
1573 COMCTL32_Free (this->pszText);
1574 COMCTL32_Free (this);
1575 this = next;
1579 DeleteObject (infoPtr->font);
1581 /* free comboex info data */
1582 COMCTL32_Free (infoPtr);
1583 SetWindowLongA (hwnd, 0, 0);
1584 return 0;
1588 static LRESULT
1589 COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1591 /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
1592 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
1593 HDC hdc;
1594 SIZE mysize;
1596 hdc = GetDC (0);
1597 GetTextExtentPointA (hdc, "W", 1, &mysize);
1598 ReleaseDC (0, hdc);
1599 mis->itemHeight = mysize.cy + CBE_EXTRA;
1601 TRACE("adjusted height hwnd=%08x, height=%d\n",
1602 hwnd, mis->itemHeight);
1604 return 0;
1608 static LRESULT
1609 COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1611 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1612 RECT rect;
1614 GetWindowRect (hwnd, &rect);
1615 TRACE("my rect (%d,%d)-(%d,%d)\n",
1616 rect.left, rect.top, rect.right, rect.bottom);
1618 MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
1619 rect.bottom - rect.top, TRUE);
1621 COMBOEX_AdjustEditPos (infoPtr);
1623 return 0;
1627 static LRESULT
1628 COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
1630 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1631 LRESULT ret;
1632 RECT cbx_wrect, cbx_crect, cb_wrect;
1633 UINT width, height;
1634 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1636 ret = DefWindowProcA (hwnd, WM_WINDOWPOSCHANGING, wParam, lParam);
1637 GetWindowRect (hwnd, &cbx_wrect);
1638 GetClientRect (hwnd, &cbx_crect);
1639 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1641 /* width is winpos value + border width of comboex */
1642 width = wp->cx
1643 + (cbx_wrect.right-cbx_wrect.left)
1644 - (cbx_crect.right-cbx_crect.left);
1646 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1647 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1648 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1649 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1650 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1651 width, cb_wrect.bottom-cb_wrect.top);
1653 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1654 width,
1655 cb_wrect.bottom-cb_wrect.top,
1656 SWP_NOACTIVATE);
1658 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1660 /* height is combo window height plus border width of comboex */
1661 height = (cb_wrect.bottom-cb_wrect.top)
1662 + (cbx_wrect.bottom-cbx_wrect.top)
1663 - (cbx_crect.bottom-cbx_crect.top);
1664 if (wp->cy < height) wp->cy = height;
1665 if (infoPtr->hwndEdit) {
1666 COMBOEX_AdjustEditPos (infoPtr);
1667 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1670 return 0;
1674 static LRESULT WINAPI
1675 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1677 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1678 NMCBEENDEDITA cbeend;
1679 COLORREF nbkc, obkc;
1680 HDC hDC;
1681 RECT rect;
1682 LRESULT lret;
1684 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1685 hwnd, uMsg, wParam, lParam, infoPtr);
1687 if (!infoPtr) return 0;
1689 switch (uMsg)
1692 case WM_CHAR:
1693 /* handle (ignore) the return character */
1694 if (wParam == VK_RETURN) return 0;
1695 /* all other characters pass into the real Edit */
1696 return CallWindowProcA (infoPtr->prevEditWndProc,
1697 hwnd, uMsg, wParam, lParam);
1699 case WM_ERASEBKGND:
1701 * The following was determined by traces of the native
1703 hDC = (HDC) wParam;
1704 nbkc = GetSysColor (COLOR_WINDOW);
1705 obkc = SetBkColor (hDC, nbkc);
1706 GetClientRect (hwnd, &rect);
1707 TRACE("erasing (%d,%d)-(%d,%d)\n",
1708 rect.left, rect.top, rect.right, rect.bottom);
1709 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1710 SetBkColor (hDC, obkc);
1711 return CallWindowProcA (infoPtr->prevEditWndProc,
1712 hwnd, uMsg, wParam, lParam);
1714 case WM_KEYDOWN: {
1715 INT oldItem, selected;
1716 CBE_ITEMDATA *item;
1717 WCHAR edit_text[260];
1719 switch ((INT)wParam)
1721 case VK_ESCAPE:
1722 /* native version seems to do following for COMBOEX */
1724 * GetWindowTextA(Edit,&?, 0x104) x
1725 * CB_GETCURSEL to Combo rets -1 x
1726 * WM_NOTIFY to COMBOEX parent (rebar) x
1727 * (CBEN_ENDEDIT{A|W}
1728 * fChanged = FALSE x
1729 * inewSelection = -1 x
1730 * txt="www.hoho" x
1731 * iWhy = 3 x
1732 * CB_GETCURSEL to Combo rets -1 x
1733 * InvalidateRect(Combo, 0) x
1734 * WM_SETTEXT to Edit x
1735 * EM_SETSEL to Edit (0,0) x
1736 * EM_SETSEL to Edit (0,-1) x
1737 * RedrawWindow(Combo, 0, 0, 5) x
1739 TRACE("special code for VK_ESCAPE\n");
1741 GetWindowTextA (infoPtr->hwndEdit, cbeend.szText, 260);
1743 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1744 cbeend.fChanged = FALSE;
1745 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1746 CB_GETCURSEL, 0, 0);
1747 cbeend.iWhy = CBENF_ESCAPE;
1749 if (COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1750 (NMHDR *)&cbeend, FALSE)) {
1751 /* abort the change */
1752 TRACE("Notify requested abort of change\n");
1753 return 0;
1755 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1756 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1757 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1758 ERR("item %d not found. Problem!\n", oldItem);
1759 break;
1762 COMBOEX_SetEditText (infoPtr, item);
1763 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1764 RDW_INVALIDATE);
1765 break;
1767 case VK_RETURN:
1768 /* native version seems to do following for COMBOEX */
1770 * GetWindowTextA(Edit,&?, 0x104) x
1771 * CB_GETCURSEL to Combo rets -1 x
1772 * CB_GETCOUNT to Combo rets 0
1773 * if >0 loop
1774 * CB_GETITEMDATA to match
1775 * *** above 3 lines simulated by FindItem x
1776 * WM_NOTIFY to COMBOEX parent (rebar) x
1777 * (CBEN_ENDEDIT{A|W} x
1778 * fChanged = TRUE (-1) x
1779 * iNewSelection = -1 or selected x
1780 * txt= x
1781 * iWhy = 2 (CBENF_RETURN) x
1782 * CB_GETCURSEL to Combo rets -1 x
1783 * if -1 send CB_SETCURSEL to Combo -1 x
1784 * InvalidateRect(Combo, 0, 0) x
1785 * SetFocus(Edit) x
1786 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1789 TRACE("special code for VK_RETURN\n");
1791 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1793 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1794 selected = SendMessageW (infoPtr->hwndCombo,
1795 CB_GETCURSEL, 0, 0);
1797 if (selected != -1) {
1798 item = COMBOEX_FindItem (infoPtr, selected);
1799 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1800 selected, debugstr_w(item->pszText));
1801 TRACE("handling VK_RETURN, edittext=%s\n",
1802 debugstr_w(edit_text));
1803 if (lstrcmpiW (item->pszText, edit_text)) {
1804 /* strings not equal -- indicate edit has changed */
1805 selected = -1;
1809 cbeend.iNewSelection = selected;
1810 cbeend.fChanged = TRUE;
1811 cbeend.iWhy = CBENF_RETURN;
1812 WideCharToMultiByte (CP_ACP, 0, edit_text, -1,
1813 cbeend.szText, sizeof(cbeend.szText),
1814 NULL, NULL);
1816 if (COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1817 (NMHDR *)&cbeend, FALSE)) {
1818 /* abort the change, restore previous */
1819 TRACE("Notify requested abort of change\n");
1820 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1821 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1822 RDW_INVALIDATE);
1823 return 0;
1825 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1826 if (oldItem != -1) {
1827 /* if something is selected, then deselect it */
1828 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
1829 (WPARAM)-1, 0);
1831 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1832 SetFocus(infoPtr->hwndEdit);
1833 break;
1835 default:
1836 return CallWindowProcA (infoPtr->prevEditWndProc,
1837 hwnd, uMsg, wParam, lParam);
1839 return 0;
1842 case WM_SETFOCUS:
1843 /* remember the focus to set state of icon */
1844 lret = CallWindowProcA (infoPtr->prevEditWndProc,
1845 hwnd, uMsg, wParam, lParam);
1846 infoPtr->flags |= WCBE_EDITFOCUSED;
1847 return lret;
1849 case WM_KILLFOCUS:
1851 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1853 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1854 if (infoPtr->flags & WCBE_ACTEDIT) {
1855 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1856 cbeend.fChanged = FALSE;
1857 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1858 CB_GETCURSEL, 0, 0);
1859 cbeend.iWhy = CBENF_KILLFOCUS;
1861 COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1862 (NMHDR *)&cbeend, FALSE);
1864 /* fall through */
1866 default:
1867 return CallWindowProcA (infoPtr->prevEditWndProc,
1868 hwnd, uMsg, wParam, lParam);
1870 return 0;
1874 static LRESULT WINAPI
1875 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1877 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1878 NMCBEENDEDITA cbeend;
1879 NMMOUSE nmmse;
1880 COLORREF nbkc, obkc;
1881 HDC hDC;
1882 HWND focusedhwnd;
1883 RECT rect;
1885 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1886 hwnd, uMsg, wParam, lParam, infoPtr);
1888 if (!infoPtr) return 0;
1890 switch (uMsg)
1893 case CB_FINDSTRINGEXACT:
1894 return COMBOEX_FindStringExact (infoPtr, wParam, lParam);
1896 case WM_DRAWITEM:
1898 * The only way this message should come is from the
1899 * child Listbox issuing the message. Flag this so
1900 * that ComboEx knows this is listbox.
1902 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1903 return CallWindowProcA (infoPtr->prevComboWndProc,
1904 hwnd, uMsg, wParam, lParam);
1906 case WM_ERASEBKGND:
1908 * The following was determined by traces of the native
1910 hDC = (HDC) wParam;
1911 nbkc = GetSysColor (COLOR_WINDOW);
1912 obkc = SetBkColor (hDC, nbkc);
1913 GetClientRect (hwnd, &rect);
1914 TRACE("erasing (%d,%d)-(%d,%d)\n",
1915 rect.left, rect.top, rect.right, rect.bottom);
1916 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1917 SetBkColor (hDC, obkc);
1918 return CallWindowProcA (infoPtr->prevComboWndProc,
1919 hwnd, uMsg, wParam, lParam);
1921 case WM_SETCURSOR:
1923 * WM_NOTIFY to comboex parent (rebar)
1924 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1925 * CallWindowProc (previous)
1927 nmmse.dwItemSpec = 0;
1928 nmmse.dwItemData = 0;
1929 nmmse.pt.x = 0;
1930 nmmse.pt.y = 0;
1931 nmmse.dwHitInfo = lParam;
1932 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse, FALSE);
1933 return CallWindowProcA (infoPtr->prevComboWndProc,
1934 hwnd, uMsg, wParam, lParam);
1936 case WM_COMMAND:
1937 switch (HIWORD(wParam)) {
1939 case EN_UPDATE:
1940 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1941 * on the EN_UPDATE
1943 return 0;
1945 case EN_KILLFOCUS:
1947 * Native does:
1949 * GetFocus() retns AA
1950 * GetWindowTextA(Edit)
1951 * CB_GETCURSEL(Combo) (got -1)
1952 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1953 * CB_GETCURSEL(Combo) (got -1)
1954 * InvalidateRect(Combo, 0, 0)
1955 * WM_KILLFOCUS(Combo, AA)
1956 * return 0;
1958 focusedhwnd = GetFocus();
1959 if (infoPtr->flags & WCBE_ACTEDIT) {
1960 GetWindowTextA (infoPtr->hwndEdit, cbeend.szText, 260);
1961 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1962 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1963 CB_GETCURSEL, 0, 0);
1964 cbeend.iWhy = CBENF_KILLFOCUS;
1966 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1967 if (COMBOEX_Notify (infoPtr, CBEN_ENDEDITA,
1968 (NMHDR *)&cbeend, FALSE)) {
1969 /* abort the change */
1970 TRACE("Notify requested abort of change\n");
1971 return 0;
1974 /* possible CB_GETCURSEL */
1975 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1976 if (focusedhwnd)
1977 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
1978 (WPARAM)focusedhwnd, 0);
1979 return 0;
1981 case EN_SETFOCUS: {
1983 * For EN_SETFOCUS this issues the same calls and messages
1984 * as the native seems to do.
1986 * for some cases however native does the following:
1987 * (noticed after SetFocus during LBUTTONDOWN on
1988 * on dropdown arrow)
1989 * WM_GETTEXTLENGTH (Edit);
1990 * WM_GETTEXT (Edit, len+1, str);
1991 * EM_SETSEL (Edit, 0, 0);
1992 * WM_GETTEXTLENGTH (Edit);
1993 * WM_GETTEXT (Edit, len+1, str);
1994 * EM_SETSEL (Edit, 0, len);
1995 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
1997 NMHDR hdr;
1999 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2000 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2001 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr, FALSE);
2002 infoPtr->flags |= WCBE_ACTEDIT;
2003 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2004 return 0;
2007 case EN_CHANGE: {
2009 * For EN_CHANGE this issues the same calls and messages
2010 * as the native seems to do.
2012 WCHAR edit_text[260];
2013 WCHAR *lastwrk;
2014 INT selected, cnt;
2015 CBE_ITEMDATA *item;
2017 selected = SendMessageW (infoPtr->hwndCombo,
2018 CB_GETCURSEL, 0, 0);
2020 /* lstrlenA( lastworkingURL ) */
2022 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2023 if (selected == -1) {
2024 lastwrk = infoPtr->edit->pszText;
2025 cnt = lstrlenW (lastwrk);
2026 if (cnt >= 259) cnt = 259;
2028 else {
2029 item = COMBOEX_FindItem (infoPtr, selected);
2030 cnt = lstrlenW (item->pszText);
2031 lastwrk = item->pszText;
2032 if (cnt >= 259) cnt = 259;
2035 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2036 selected, debugstr_w(lastwrk));
2037 TRACE("handling EN_CHANGE, edittext=%s\n",
2038 debugstr_w(edit_text));
2040 /* lstrcmpiW is between lastworkingURL and GetWindowText */
2042 if (lstrcmpiW (lastwrk, edit_text)) {
2043 /* strings not equal -- indicate edit has changed */
2044 infoPtr->flags |= WCBE_EDITCHG;
2046 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2047 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2048 CBN_EDITCHANGE),
2049 infoPtr->hwndSelf);
2050 return 0;
2053 case LBN_SELCHANGE:
2055 * Therefore from traces there is no additional code here
2059 * Using native COMCTL32 gets the following:
2060 * 1 == SHDOCVW.DLL issues call/message
2061 * 2 == COMCTL32.DLL issues call/message
2062 * 3 == WINE issues call/message
2065 * for LBN_SELCHANGE:
2066 * 1 CB_GETCURSEL(ComboEx)
2067 * 1 CB_GETDROPPEDSTATE(ComboEx)
2068 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2069 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2070 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2071 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2072 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2073 * 3 ShowWindow(ComboLB, SW_HIDE)
2074 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2075 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2076 ** end of CBRollUp
2077 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2078 * ? LB_GETCURSEL <==|
2079 * ? LB_GETTEXTLEN |
2080 * ? LB_GETTEXT | Needs to be added to
2081 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2082 * ? LB_GETITEMDATA |
2083 * ? WM_DRAWITEM(ComboEx) <==|
2085 default:
2086 break;
2087 }/* fall through */
2088 default:
2089 return CallWindowProcA (infoPtr->prevComboWndProc,
2090 hwnd, uMsg, wParam, lParam);
2092 return 0;
2096 static LRESULT WINAPI
2097 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2099 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2100 if (!COMBOEX_GetInfoPtr (hwnd) && (uMsg != WM_CREATE))
2101 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2103 switch (uMsg)
2105 case CBEM_DELETEITEM: /* maps to CB_DELETESTRING */
2106 return COMBOEX_DeleteItem (hwnd, wParam, lParam);
2108 case CBEM_GETCOMBOCONTROL:
2109 return COMBOEX_GetComboControl (hwnd, wParam, lParam);
2111 case CBEM_GETEDITCONTROL:
2112 return COMBOEX_GetEditControl (hwnd, wParam, lParam);
2114 case CBEM_GETEXTENDEDSTYLE:
2115 return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
2117 case CBEM_GETIMAGELIST:
2118 return COMBOEX_GetImageList (hwnd, wParam, lParam);
2120 case CBEM_GETITEMA:
2121 return COMBOEX_GetItemA (hwnd, wParam, lParam);
2123 case CBEM_GETITEMW:
2124 return COMBOEX_GetItemW (hwnd, wParam, lParam);
2126 case CBEM_GETUNICODEFORMAT:
2127 return COMBOEX_GetUnicodeFormat (hwnd, wParam, lParam);
2129 case CBEM_HASEDITCHANGED:
2130 return COMBOEX_HasEditChanged (hwnd, wParam, lParam);
2132 case CBEM_INSERTITEMA:
2133 return COMBOEX_InsertItemA (hwnd, wParam, lParam);
2135 case CBEM_INSERTITEMW:
2136 return COMBOEX_InsertItemW (hwnd, wParam, lParam);
2138 case CBEM_SETEXSTYLE: /* FIXME: obsoleted, should be the same as: */
2139 case CBEM_SETEXTENDEDSTYLE:
2140 return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
2142 case CBEM_SETIMAGELIST:
2143 return COMBOEX_SetImageList (hwnd, wParam, lParam);
2145 case CBEM_SETITEMA:
2146 return COMBOEX_SetItemA (hwnd, wParam, lParam);
2148 case CBEM_SETITEMW:
2149 return COMBOEX_SetItemW (hwnd, wParam, lParam);
2151 case CBEM_SETUNICODEFORMAT:
2152 return COMBOEX_SetUnicodeFormat (hwnd, wParam, lParam);
2155 /* Combo messages we are not sure if we need to process or just forward */
2156 case CB_GETDROPPEDCONTROLRECT:
2157 case CB_GETITEMDATA:
2158 case CB_GETITEMHEIGHT:
2159 case CB_GETLBTEXT:
2160 case CB_GETLBTEXTLEN:
2161 case CB_GETEXTENDEDUI:
2162 case CB_LIMITTEXT:
2163 case CB_RESETCONTENT:
2164 case CB_SELECTSTRING:
2165 case CB_SETITEMDATA:
2166 case WM_SETTEXT:
2167 case WM_GETTEXT:
2168 FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
2169 uMsg, wParam, lParam);
2170 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2172 /* Combo messages OK to just forward to the regular COMBO */
2173 case CB_GETCOUNT:
2174 case CB_GETCURSEL:
2175 case CB_GETDROPPEDSTATE:
2176 case CB_SETDROPPEDWIDTH:
2177 case CB_SETEXTENDEDUI:
2178 case CB_SHOWDROPDOWN:
2179 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2181 /* Combo messages we need to process specially */
2182 case CB_FINDSTRINGEXACT:
2183 return COMBOEX_FindStringExact (COMBOEX_GetInfoPtr (hwnd),
2184 wParam, lParam);
2186 case CB_SETCURSEL:
2187 return COMBOEX_SetCursel (hwnd, wParam, lParam);
2189 case CB_SETITEMHEIGHT:
2190 return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
2194 /* Window messages passed to parent */
2195 case WM_COMMAND:
2196 return COMBOEX_Command (hwnd, wParam, lParam);
2198 case WM_NOTIFY:
2199 return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
2202 /* Window messages we need to process */
2203 case WM_CREATE:
2204 return COMBOEX_Create (hwnd, wParam, lParam);
2206 case WM_DELETEITEM:
2207 return COMBOEX_WM_DeleteItem (hwnd, wParam, lParam);
2209 case WM_DRAWITEM:
2210 return COMBOEX_DrawItem (hwnd, wParam, lParam);
2212 case WM_DESTROY:
2213 return COMBOEX_Destroy (hwnd, wParam, lParam);
2215 case WM_MEASUREITEM:
2216 return COMBOEX_MeasureItem (hwnd, wParam, lParam);
2218 case WM_SIZE:
2219 return COMBOEX_Size (hwnd, wParam, lParam);
2221 case WM_WINDOWPOSCHANGING:
2222 return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
2224 default:
2225 if (uMsg >= WM_USER)
2226 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2227 uMsg, wParam, lParam);
2228 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2230 return 0;
2234 VOID
2235 COMBOEX_Register (void)
2237 WNDCLASSA wndClass;
2239 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2240 wndClass.style = CS_GLOBALCLASS;
2241 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2242 wndClass.cbClsExtra = 0;
2243 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2244 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2245 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2246 wndClass.lpszClassName = WC_COMBOBOXEXA;
2248 RegisterClassA (&wndClass);
2250 ComboExInfo = GlobalAddAtomA("CC32SubclassInfo");
2254 VOID
2255 COMBOEX_Unregister (void)
2257 UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);