Use the supplied buffer when copying item text.
[wine/wine-kai.git] / dlls / comctl32 / comboex.c
bloba268c27e86ce8cb08596e00e7848e5329fa77f53
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 (mod6)
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 notifies 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 * mod 5
62 * 1. Add support for CB_GETITEMDATA to a Comboex. Returns the LPARAM
63 * passed during insert of item.
64 * 2. Remember selected item and don't issue CB_SETCURSEL unless needed.
65 * 3. Add initial support for WM_NCCREATE to remove unwanted window styles
66 * (Currently just WS_VSCROLL and WS_HSCROLL, but probably should be
67 * more.)
68 * 4. Improve some traces.
69 * 5. Add support for CB_SETITEMDATA sets LPARAM value from item.
71 * mod 6
72 * 1. Add support for WM_NOTIFYFORMAT (both incoming and outgoing) and do
73 * WM_NOTIFY correctly based on results.
74 * 2. Fix memory leaks of text strings in COMBOEX_WM_DELETEITEM.
75 * 3. Add routines to handle special cases of NMCBEENDEDIT and NMCOMBOXEX
76 * so translation to ANSI is done correctly.
77 * 4. Fix some issues with COMBOEX_DrawItem.
79 * Test vehicals were the ControlSpy modules (rebar.exe and comboboxex.exe),
80 * WinRAR, and IE 4.0.
84 #include <string.h>
85 #include "winbase.h"
86 #include "commctrl.h"
87 #include "debugtools.h"
88 #include "wine/unicode.h"
90 DEFAULT_DEBUG_CHANNEL(comboex);
92 * The following is necessary for the test done in COMBOEX_DrawItem
93 * to determine whether to dump out the DRAWITEM structure or not.
95 DECLARE_DEBUG_CHANNEL(message);
97 /* Item structure */
98 typedef struct
100 VOID *next;
101 UINT mask;
102 LPWSTR pszText;
103 int cchTextMax;
104 int iImage;
105 int iSelectedImage;
106 int iOverlay;
107 int iIndent;
108 LPARAM lParam;
109 } CBE_ITEMDATA;
111 /* ComboBoxEx structure */
112 typedef struct
114 HIMAGELIST himl;
115 HWND hwndSelf; /* my own hwnd */
116 HWND hwndCombo;
117 HWND hwndEdit;
118 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
119 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
120 DWORD dwExtStyle;
121 INT selected; /* index of selected item */
122 DWORD flags; /* WINE internal flags */
123 HFONT hDefaultFont;
124 HFONT font;
125 INT nb_items; /* Number of items */
126 BOOL bUnicode; /* TRUE if this window is Unicode */
127 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
128 CBE_ITEMDATA *edit; /* item data for edit item */
129 CBE_ITEMDATA *items; /* Array of items */
130 } COMBOEX_INFO;
132 /* internal flags in the COMBOEX_INFO structure */
133 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
134 * CBEN_BEGINEDIT issued
135 * but CBEN_ENDEDIT{A|W}
136 * not yet issued. */
137 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
138 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
141 #define ID_CB_EDIT 1001
145 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
146 * the ComboEx version of the Combo Window Proc so that when the
147 * WM_DRAWITEM message is then passed to ComboEx, we know that this
148 * particular WM_DRAWITEM message is for listbox only items. Any messasges
149 * without this flag is then for the Edit control field.
151 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
152 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
154 #define ODS_COMBOEXLBOX 0x4000
158 /* Height in pixels of control over the amount of the selected font */
159 #define CBE_EXTRA 3
161 /* Indent amount per MS documentation */
162 #define CBE_INDENT 10
164 /* Offset in pixels from left side for start of image or text */
165 #define CBE_STARTOFFSET 6
167 /* Offset between image and text */
168 #define CBE_SEP 4
170 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
173 /* Things common to the entire DLL */
174 static ATOM ComboExInfo;
175 static LRESULT WINAPI
176 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
177 static LRESULT WINAPI
178 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
180 static void
181 COMBOEX_DumpItem (CBE_ITEMDATA *item)
183 if (TRACE_ON(comboex)){
184 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
185 item, item->mask, item->pszText, item->cchTextMax,
186 item->iImage);
187 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
188 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
189 if ((item->mask & CBEIF_TEXT) && item->pszText)
190 TRACE("item %p - pszText=%s\n",
191 item, debugstr_w((const WCHAR *)item->pszText));
196 static void
197 COMBOEX_DumpInput (COMBOBOXEXITEMA *input, BOOL true_for_w)
199 if (TRACE_ON(comboex)){
200 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
201 input->mask, input->iItem, input->pszText, input->cchTextMax,
202 input->iImage);
203 if ((input->mask & CBEIF_TEXT) && input->pszText) {
204 if (true_for_w)
205 TRACE("input - pszText=<%s>\n",
206 debugstr_w((const WCHAR *)input->pszText));
207 else
208 TRACE("input - pszText=<%s>\n",
209 debugstr_a((const char *)input->pszText));
211 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
212 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
217 inline static LRESULT
218 COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
220 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
222 if (infoPtr->hwndCombo)
223 return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
225 return 0;
229 static INT
230 COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
233 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
234 hdr->hwndFrom = infoPtr->hwndSelf;
235 hdr->code = code;
236 if (infoPtr->NtfUnicode)
237 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
238 (LPARAM)hdr);
239 else
240 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
241 (LPARAM)hdr);
245 static INT
246 COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
249 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
251 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
252 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
253 hdr->hdr.code = code;
254 if (infoPtr->NtfUnicode)
255 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
256 (LPARAM)hdr);
257 else {
258 LPWSTR str, ostr = NULL;
259 INT ret, len = 0;
261 if (hdr->ceItem.mask & CBEIF_TEXT) {
262 ostr = hdr->ceItem.pszText;
263 str = ostr;
264 if (!str) str = (LPWSTR)L"";
265 len = WideCharToMultiByte (CP_ACP, 0, str, -1, 0, 0, NULL, NULL);
266 if (len > 0) {
267 hdr->ceItem.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
268 WideCharToMultiByte (CP_ACP, 0, str, -1, (LPSTR)hdr->ceItem.pszText,
269 len, NULL, NULL);
273 ret = SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
274 (LPARAM)hdr);
275 if (hdr->ceItem.mask & CBEIF_TEXT) {
276 if (len > 0)
277 COMCTL32_Free (hdr->ceItem.pszText);
278 hdr->ceItem.pszText = ostr;
280 return ret;
285 static INT
286 COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *hdr, LPWSTR itemText)
289 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
291 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
292 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
293 hdr->hdr.code = (infoPtr->NtfUnicode) ? CBEN_ENDEDITW : CBEN_ENDEDITA;
294 if (infoPtr->NtfUnicode)
295 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
296 (LPARAM)hdr);
297 else {
298 NMCBEENDEDITA ansi;
300 memcpy (&ansi.hdr, &hdr->hdr, sizeof(NMHDR));
301 ansi.fChanged = hdr->fChanged;
302 ansi.iNewSelection = hdr->iNewSelection;
303 WideCharToMultiByte (CP_ACP, 0, itemText, -1,
304 (LPSTR)&ansi.szText, CBEMAXSTRLEN, NULL, NULL);
305 ansi.iWhy = hdr->iWhy;
306 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
307 (LPARAM)&ansi);
312 static void
313 COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
315 HFONT nfont, ofont;
316 HDC mydc;
318 mydc = GetDC (0); /* why the entire screen???? */
319 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
320 ofont = (HFONT) SelectObject (mydc, nfont);
321 GetTextExtentPointA (mydc, "A", 1, size);
322 SelectObject (mydc, ofont);
323 ReleaseDC (0, mydc);
324 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
328 static void
329 COMBOEX_CopyItem (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
331 if (cit->mask & CBEIF_TEXT) {
333 * when given a text buffer actually use that buffer
335 if (cit->pszText)
337 lstrcpynW(cit->pszText,item->pszText,cit->cchTextMax);
339 else
341 cit->pszText = item->pszText;
342 cit->cchTextMax = item->cchTextMax;
345 if (cit->mask & CBEIF_IMAGE)
346 cit->iImage = item->iImage;
347 if (cit->mask & CBEIF_SELECTEDIMAGE)
348 cit->iSelectedImage = item->iSelectedImage;
349 if (cit->mask & CBEIF_OVERLAY)
350 cit->iOverlay = item->iOverlay;
351 if (cit->mask & CBEIF_INDENT)
352 cit->iIndent = item->iIndent;
353 if (cit->mask & CBEIF_LPARAM)
354 cit->lParam = item->lParam;
359 static void
360 COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
362 SIZE mysize;
363 IMAGEINFO iinfo;
364 INT x, y, w, h, xoff = 0;
365 RECT rect;
367 if (!infoPtr->hwndEdit) return;
368 iinfo.rcImage.left = iinfo.rcImage.right = 0;
369 if (infoPtr->himl) {
370 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
371 xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
373 GetClientRect (infoPtr->hwndCombo, &rect);
374 InflateRect (&rect, -2, -2);
375 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
377 /* reposition the Edit control based on whether icon exists */
378 COMBOEX_GetComboFontSize (infoPtr, &mysize);
379 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
380 x = xoff + CBE_STARTOFFSET + 1;
381 y = CBE_EXTRA + 1;
382 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
383 h = mysize.cy + 1;
385 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
386 rect.left, rect.top, rect.right, rect.bottom,
387 x, y, x + w, y + h);
388 SetWindowPos(infoPtr->hwndEdit, HWND_TOP,
389 x, y,
390 w, h,
391 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
395 static void
396 COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
398 SIZE mysize;
399 UINT cy;
400 IMAGEINFO iinfo;
402 COMBOEX_GetComboFontSize (infoPtr, &mysize);
403 cy = mysize.cy + CBE_EXTRA;
404 if (infoPtr->himl) {
405 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
406 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
407 TRACE("upgraded height due to image: height=%d\n", cy);
409 SendMessageW (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
410 if (infoPtr->hwndCombo)
411 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
412 (WPARAM) 0, (LPARAM) cy);
416 static void
417 COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
419 if (!infoPtr->hwndEdit) return;
420 /* native issues the following messages to the {Edit} control */
421 /* WM_SETTEXT (0,addr) */
422 /* EM_SETSEL32 (0,0) */
423 /* EM_SETSEL32 (0,-1) */
424 if (item->mask & CBEIF_TEXT) {
425 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
426 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
427 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
432 static CBE_ITEMDATA *
433 COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
435 CBE_ITEMDATA *item;
436 INT i;
438 if ((index > infoPtr->nb_items) || (index < -1))
439 return 0;
440 if (index == -1)
441 return infoPtr->edit;
442 item = infoPtr->items;
443 i = infoPtr->nb_items - 1;
445 /* find the item in the list */
446 while (item && (i > index)) {
447 item = (CBE_ITEMDATA *)item->next;
448 i--;
450 if (!item || (i != index)) {
451 FIXME("COMBOBOXEX item structures broken. Please report!\n");
452 return 0;
454 return item;
458 static void
459 COMBOEX_WarnCallBack (CBE_ITEMDATA *item)
461 if (item->pszText == LPSTR_TEXTCALLBACKW)
462 FIXME("Callback not implemented yet for pszText\n");
463 if (item->iImage == I_IMAGECALLBACK)
464 FIXME("Callback not implemented yet for iImage\n");
465 if (item->iSelectedImage == I_IMAGECALLBACK)
466 FIXME("Callback not implemented yet for iSelectedImage\n");
467 if (item->iOverlay == I_IMAGECALLBACK)
468 FIXME("Callback not implemented yet for iOverlay\n");
469 if (item->iIndent == I_INDENTCALLBACK)
470 FIXME("Callback not implemented yet for iIndent\n");
474 /* *** CBEM_xxx message support *** */
477 static LRESULT
478 COMBOEX_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
480 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
481 INT index = (INT) wParam;
482 CBE_ITEMDATA *item;
484 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
486 /* if item number requested does not exist then return failure */
487 if ((index > infoPtr->nb_items) || (index < 0)) {
488 ERR("attempt to delete item that does not exist\n");
489 return CB_ERR;
492 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
493 ERR("attempt to delete item that was not found!\n");
494 return CB_ERR;
497 /* doing this will result in WM_DELETEITEM being issued */
498 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
500 return infoPtr->nb_items;
504 inline static LRESULT
505 COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
507 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
509 TRACE("\n");
511 return (LRESULT)infoPtr->hwndCombo;
515 inline static LRESULT
516 COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
518 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
520 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
521 return 0;
523 TRACE("-- 0x%x\n", infoPtr->hwndEdit);
525 return (LRESULT)infoPtr->hwndEdit;
529 inline static LRESULT
530 COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
532 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
534 TRACE("-- 0x%08lx\n", infoPtr->dwExtStyle);
536 return (LRESULT)infoPtr->dwExtStyle;
540 inline static LRESULT
541 COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
543 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
545 TRACE("-- %p\n", infoPtr->himl);
547 return (LRESULT)infoPtr->himl;
551 static LRESULT
552 COMBOEX_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
554 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
555 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
556 INT index;
557 CBE_ITEMDATA *item;
559 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
561 /* get real index of item to insert */
562 index = cit->iItem;
564 /* if item number requested does not exist then return failure */
565 if ((index > infoPtr->nb_items) || (index < -1)) {
566 ERR("attempt to get item that does not exist\n");
567 return 0;
570 /* if the item is the edit control and there is no edit control, skip */
571 if ((index == -1) &&
572 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
573 return 0;
575 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
576 ERR("attempt to get item that was not found!\n");
577 return 0;
580 COMBOEX_CopyItem (infoPtr, item, cit);
582 return TRUE;
586 inline static LRESULT
587 COMBOEX_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
589 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
590 COMBOBOXEXITEMW tmpcit;
591 INT len;
593 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
595 tmpcit.mask = cit->mask;
596 tmpcit.iItem = cit->iItem;
597 COMBOEX_GetItemW (hwnd, wParam, (LPARAM) &tmpcit);
599 len = WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1, 0, 0, NULL, NULL);
600 if (len > 0)
601 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
602 cit->pszText, cit->cchTextMax, NULL, NULL);
604 cit->iImage = tmpcit.iImage;
605 cit->iSelectedImage = tmpcit.iSelectedImage;
606 cit->iOverlay = tmpcit.iOverlay;
607 cit->iIndent = tmpcit.iIndent;
608 cit->lParam = tmpcit.lParam;
610 return TRUE;
614 inline static LRESULT
615 COMBOEX_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
617 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
619 TRACE("%s hwnd=0x%x\n",
620 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
622 return infoPtr->bUnicode;
626 inline static LRESULT
627 COMBOEX_HasEditChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
629 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
631 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
632 return FALSE;
633 if ((infoPtr->flags & (WCBE_ACTEDIT | WCBE_EDITCHG)) ==
634 (WCBE_ACTEDIT | WCBE_EDITCHG))
635 return TRUE;
636 return FALSE;
640 static LRESULT
641 COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
643 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
644 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
645 INT index;
646 CBE_ITEMDATA *item;
647 NMCOMBOBOXEXW nmcit;
649 TRACE("\n");
651 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
653 /* get real index of item to insert */
654 index = cit->iItem;
655 if (index == -1) index = infoPtr->nb_items;
656 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
658 /* get space and chain it in */
659 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
660 item->next = NULL;
661 item->pszText = NULL;
663 /* locate position to insert new item in */
664 if (index == infoPtr->nb_items) {
665 /* fast path for iItem = -1 */
666 item->next = infoPtr->items;
667 infoPtr->items = item;
669 else {
670 INT i = infoPtr->nb_items-1;
671 CBE_ITEMDATA *moving = infoPtr->items;
673 while ((i > index) && moving) {
674 moving = (CBE_ITEMDATA *)moving->next;
675 i--;
677 if (!moving) {
678 FIXME("COMBOBOXEX item structures broken. Please report!\n");
679 COMCTL32_Free(item);
680 return -1;
682 item->next = moving->next;
683 moving->next = item;
686 /* fill in our hidden item structure */
687 item->mask = cit->mask;
688 if (item->mask & CBEIF_TEXT) {
689 LPWSTR str;
690 INT len;
692 str = cit->pszText;
693 if (!str) str = (LPWSTR) L"";
694 len = strlenW (str);
695 if (len > 0) {
696 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
697 strcpyW (item->pszText, str);
699 else
700 item->pszText = NULL;
701 item->cchTextMax = cit->cchTextMax;
703 if (item->mask & CBEIF_IMAGE)
704 item->iImage = cit->iImage;
705 if (item->mask & CBEIF_SELECTEDIMAGE)
706 item->iSelectedImage = cit->iSelectedImage;
707 if (item->mask & CBEIF_OVERLAY)
708 item->iOverlay = cit->iOverlay;
709 if (item->mask & CBEIF_INDENT)
710 item->iIndent = cit->iIndent;
711 if (item->mask & CBEIF_LPARAM)
712 item->lParam = cit->lParam;
713 infoPtr->nb_items++;
715 COMBOEX_WarnCallBack (item);
717 COMBOEX_DumpItem (item);
719 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
720 (WPARAM)cit->iItem, (LPARAM)item);
722 COMBOEX_CopyItem (infoPtr, item, &nmcit.ceItem);
723 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
725 return index;
730 static LRESULT
731 COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
733 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
734 COMBOBOXEXITEMW citW;
735 LRESULT ret;
737 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
738 if (cit->mask & CBEIF_TEXT) {
739 LPSTR str;
740 INT len;
742 str = cit->pszText;
743 if (!str) str="";
744 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
745 if (len > 0) {
746 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
747 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
750 ret = COMBOEX_InsertItemW(hwnd,wParam,(LPARAM)&citW);;
752 if (cit->mask & CBEIF_TEXT)
753 COMCTL32_Free(citW.pszText);
754 return ret;
758 static LRESULT
759 COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
761 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
762 DWORD dwTemp;
764 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
766 dwTemp = infoPtr->dwExtStyle;
768 if (lParam & (CBES_EX_NOEDITIMAGEINDENT |
769 CBES_EX_PATHWORDBREAKPROC |
770 CBES_EX_NOSIZELIMIT |
771 CBES_EX_CASESENSITIVE))
772 FIXME("Extended style not implemented %08lx\n", lParam);
774 if ((DWORD)wParam) {
775 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
777 else
778 infoPtr->dwExtStyle = (DWORD)lParam;
781 * native does this for CBES_EX_NOEDITIMAGE state change
783 if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
784 (dwTemp & CBES_EX_NOEDITIMAGE)) {
785 /* if state of EX_NOEDITIMAGE changes, invalidate all */
786 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
787 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
788 InvalidateRect (hwnd, NULL, TRUE);
789 COMBOEX_AdjustEditPos (infoPtr);
790 if (infoPtr->hwndEdit)
791 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
794 return (LRESULT)dwTemp;
798 inline static LRESULT
799 COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
801 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
802 HIMAGELIST himlTemp;
804 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
806 himlTemp = infoPtr->himl;
807 infoPtr->himl = (HIMAGELIST)lParam;
809 COMBOEX_ReSize (hwnd, infoPtr);
810 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
812 /* reposition the Edit control based on whether icon exists */
813 COMBOEX_AdjustEditPos (infoPtr);
814 return (LRESULT)himlTemp;
817 static LRESULT
818 COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
820 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
821 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
822 INT index;
823 CBE_ITEMDATA *item;
825 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
827 /* get real index of item to insert */
828 index = cit->iItem;
830 /* if item number requested does not exist then return failure */
831 if ((index > infoPtr->nb_items) || (index < -1)) {
832 ERR("attempt to set item that does not exist yet!\n");
833 return 0;
836 /* if the item is the edit control and there is no edit control, skip */
837 if ((index == -1) &&
838 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
839 return 0;
841 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
842 ERR("attempt to set item that was not found!\n");
843 return 0;
846 /* add/change stuff to the internal item structure */
847 item->mask |= cit->mask;
848 if (cit->mask & CBEIF_TEXT) {
849 LPWSTR str;
850 INT len;
851 WCHAR emptystr[1] = {0};
853 str = cit->pszText;
854 if (!str) str=emptystr;
855 len = strlenW(str);
856 if (len > 0) {
857 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
858 strcpyW(item->pszText,str);
860 item->cchTextMax = cit->cchTextMax;
862 if (cit->mask & CBEIF_IMAGE)
863 item->iImage = cit->iImage;
864 if (cit->mask & CBEIF_SELECTEDIMAGE)
865 item->iSelectedImage = cit->iSelectedImage;
866 if (cit->mask & CBEIF_OVERLAY)
867 item->iOverlay = cit->iOverlay;
868 if (cit->mask & CBEIF_INDENT)
869 item->iIndent = cit->iIndent;
870 if (cit->mask & CBEIF_LPARAM)
871 cit->lParam = cit->lParam;
873 COMBOEX_WarnCallBack (item);
875 COMBOEX_DumpItem (item);
877 /* if original request was to update edit control, do some fast foot work */
878 if (cit->iItem == -1) {
879 COMBOEX_SetEditText (infoPtr, item);
880 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
882 return TRUE;
885 static LRESULT
886 COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
888 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
889 COMBOBOXEXITEMW citW;
890 LRESULT ret;
892 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
893 if (cit->mask & CBEIF_TEXT) {
894 LPSTR str;
895 INT len;
897 str = cit->pszText;
898 if (!str) str="";
899 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
900 if (len > 0) {
901 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
902 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
905 ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
907 if (cit->mask & CBEIF_TEXT)
908 COMCTL32_Free(citW.pszText);
909 return ret;
913 inline static LRESULT
914 COMBOEX_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
916 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
917 BOOL bTemp = infoPtr->bUnicode;
919 TRACE("to %s hwnd=0x%04x, was %s\n",
920 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd,
921 (bTemp) ? "TRUE" : "FALSE");
923 infoPtr->bUnicode = (BOOL)wParam;
925 return bTemp;
930 /* *** CB_xxx message support *** */
933 static LRESULT
934 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
936 INT i, count;
937 CBE_ITEMDATA *item;
938 LPWSTR desired = NULL;
939 INT start = (INT) wParam;
941 i = MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
942 if (i > 0) {
943 desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
944 MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, desired, i);
947 count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0 , 0);
949 /* now search from after starting loc and wrapping back to start */
950 for(i=start+1; i<count; i++) {
951 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
952 CB_GETITEMDATA, (WPARAM)i, 0);
953 TRACE("desired=%s, item=%s\n",
954 debugstr_w(desired), debugstr_w(item->pszText));
955 if (lstrcmpiW(item->pszText, desired) == 0) {
956 COMCTL32_Free (desired);
957 return i;
960 for(i=0; i<=start; i++) {
961 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
962 CB_GETITEMDATA, (WPARAM)i, 0);
963 TRACE("desired=%s, item=%s\n",
964 debugstr_w(desired), debugstr_w(item->pszText));
965 if (lstrcmpiW(item->pszText, desired) == 0) {
966 COMCTL32_Free (desired);
967 return i;
970 COMCTL32_Free(desired);
971 return CB_ERR;
975 static LRESULT
976 COMBOEX_GetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
978 INT index = wParam;
979 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
980 CBE_ITEMDATA *item1, *item2;
981 LRESULT lret = 0;
983 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
984 wParam, lParam);
985 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
986 item2 = COMBOEX_FindItem (infoPtr, index);
987 if (item2 != item1) {
988 ERR("data structures damaged!\n");
989 return CB_ERR;
991 if (item1->mask & CBEIF_LPARAM)
992 lret = (LRESULT) item1->lParam;
993 TRACE("returning 0x%08lx\n", lret);
994 return lret;
996 lret = (LRESULT)item1;
997 TRACE("non-valid result from combo, returning 0x%08lx\n", lret);
998 return lret;
1002 static LRESULT
1003 COMBOEX_SetCursel (HWND hwnd, WPARAM wParam, LPARAM lParam)
1005 INT index = wParam;
1006 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1007 CBE_ITEMDATA *item;
1008 LRESULT lret;
1010 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
1011 /* FIXME: need to clear selection */
1012 return CB_ERR;
1015 TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
1016 debugstr_w(item->pszText) : "<null>");
1017 infoPtr->selected = index;
1019 lret = SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, wParam, lParam);
1020 COMBOEX_SetEditText (infoPtr, item);
1021 return lret;
1025 static LRESULT
1026 COMBOEX_SetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
1028 INT index = wParam;
1029 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1030 CBE_ITEMDATA *item1, *item2;
1032 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
1033 wParam, lParam);
1034 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
1035 item2 = COMBOEX_FindItem (infoPtr, index);
1036 if (item2 != item1) {
1037 ERR("data structures damaged!\n");
1038 return CB_ERR;
1040 item1->mask |= CBEIF_LPARAM;
1041 item1->lParam = lParam;
1042 TRACE("setting lparam to 0x%08lx\n", lParam);
1043 return 0;
1045 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
1046 return (LRESULT)item1;
1050 static LRESULT
1051 COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
1053 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1054 RECT cb_wrect, cbx_wrect, cbx_crect;
1055 LRESULT ret = 0;
1056 UINT height;
1058 /* First, lets forward the message to the normal combo control
1059 just like Windows. */
1060 if (infoPtr->hwndCombo)
1061 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
1063 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1064 GetWindowRect (hwnd, &cbx_wrect);
1065 GetClientRect (hwnd, &cbx_crect);
1066 /* the height of comboex as height of the combo + comboex border */
1067 height = cb_wrect.bottom-cb_wrect.top
1068 + cbx_wrect.bottom-cbx_wrect.top
1069 - (cbx_crect.bottom-cbx_crect.top);
1070 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1071 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1072 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1073 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1074 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1075 cbx_wrect.right-cbx_wrect.left, height);
1076 SetWindowPos (hwnd, HWND_TOP, 0, 0,
1077 cbx_wrect.right-cbx_wrect.left,
1078 height,
1079 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1081 return ret;
1085 /* *** WM_xxx message support *** */
1088 static LRESULT
1089 COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1091 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
1092 COMBOEX_INFO *infoPtr;
1093 DWORD dwComboStyle;
1094 LOGFONTA mylogfont;
1095 CBE_ITEMDATA *item;
1096 RECT wnrc1, clrc1, cmbwrc;
1097 LONG test;
1098 INT i;
1100 /* allocate memory for info structure */
1101 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
1102 if (infoPtr == NULL) {
1103 ERR("could not allocate info memory!\n");
1104 return 0;
1107 /* initialize info structure */
1109 infoPtr->items = NULL;
1110 infoPtr->nb_items = 0;
1111 infoPtr->hwndSelf = hwnd;
1112 infoPtr->selected = -1;
1114 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1116 i = SendMessageA(GetParent (hwnd),
1117 WM_NOTIFYFORMAT, hwnd, NF_QUERY);
1118 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1119 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1121 i = NFR_ANSI;
1123 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1125 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1127 /* create combo box */
1128 dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
1129 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
1131 GetWindowRect(hwnd, &wnrc1);
1132 GetClientRect(hwnd, &clrc1);
1133 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1134 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1135 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
1136 TRACE("combo style=%08lx, adding style=%08lx\n", dwComboStyle,
1137 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1138 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1139 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED);
1141 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1142 /* specified. It then creates it's own version of the EDIT control */
1143 /* and makes the ComboBox the parent. This is because a normal */
1144 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
1145 /* We also need to place the edit control at the proper location */
1146 /* (allow space for the icons). */
1148 infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
1149 /* following line added to match native */
1150 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1151 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1152 /* was base and is necessary */
1153 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
1154 cs->y, cs->x, cs->cx, cs->cy, hwnd,
1155 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1156 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
1159 * native does the following at this point according to trace:
1160 * GetWindowThreadProcessId(hwndCombo,0)
1161 * GetCurrentThreadId()
1162 * GetWindowThreadProcessId(hwndCombo, &???)
1163 * GetCurrentProcessId()
1167 * Setup a property to hold the pointer to the COMBOBOXEX
1168 * data structure.
1170 test = GetPropA(infoPtr->hwndCombo, (LPCSTR)(LONG)ComboExInfo);
1171 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1172 SetPropA(infoPtr->hwndCombo, "CC32SubclassInfo", (LONG)infoPtr);
1174 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndCombo,
1175 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
1176 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1180 * Now create our own EDIT control so we can position it.
1181 * It is created only for CBS_DROPDOWN style
1183 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1184 infoPtr->hwndEdit = CreateWindowExA (0, "EDIT", "",
1185 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1186 0, 0, 0, 0, /* will set later */
1187 infoPtr->hwndCombo,
1188 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1189 GetWindowLongA (hwnd, GWL_HINSTANCE),
1190 NULL);
1192 /* native does the following at this point according to trace:
1193 * GetWindowThreadProcessId(hwndEdit,0)
1194 * GetCurrentThreadId()
1195 * GetWindowThreadProcessId(hwndEdit, &???)
1196 * GetCurrentProcessId()
1200 * Setup a property to hold the pointer to the COMBOBOXEX
1201 * data structure.
1203 test = GetPropA(infoPtr->hwndEdit, (LPCSTR)(LONG)ComboExInfo);
1204 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1205 SetPropA(infoPtr->hwndEdit, "CC32SubclassInfo", (LONG)infoPtr);
1207 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndEdit,
1208 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1209 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1211 else {
1212 infoPtr->hwndEdit = 0;
1213 infoPtr->font = 0;
1217 * Locate the default font if necessary and then set it in
1218 * all associated controls
1220 if (!infoPtr->font) {
1221 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1222 &mylogfont, 0);
1223 infoPtr->font = infoPtr->hDefaultFont = CreateFontIndirectA (&mylogfont);
1225 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1226 if (infoPtr->hwndEdit) {
1227 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1228 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1231 COMBOEX_ReSize (hwnd, infoPtr);
1233 /* Above is fairly certain, below is much less certain. */
1235 GetWindowRect(hwnd, &wnrc1);
1236 GetClientRect(hwnd, &clrc1);
1237 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1238 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1239 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1240 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1241 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1242 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1243 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1244 SWP_NOACTIVATE | SWP_NOREDRAW);
1246 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1247 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1248 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1249 SetWindowPos(hwnd, HWND_TOP,
1250 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1251 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1253 COMBOEX_AdjustEditPos (infoPtr);
1256 * Create an item structure to represent the data in the
1257 * EDIT control.
1259 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1260 item->next = NULL;
1261 item->pszText = NULL;
1262 item->mask = 0;
1263 infoPtr->edit = item;
1265 return 0;
1269 inline static LRESULT
1270 COMBOEX_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
1272 LRESULT lret;
1273 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1274 INT command = HIWORD(wParam);
1275 CBE_ITEMDATA *item = 0;
1276 WCHAR wintext[520];
1277 INT cursel, n, oldItem;
1278 NMCBEENDEDITW cbeend;
1279 DWORD oldflags;
1281 TRACE("for command %d\n", command);
1283 switch (command)
1285 case CBN_DROPDOWN:
1286 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1287 (LPARAM)hwnd);
1289 * from native trace of first dropdown after typing in URL in IE4
1290 * CB_GETCURSEL(Combo)
1291 * GetWindowText(Edit)
1292 * CB_GETCURSEL(Combo)
1293 * CB_GETCOUNT(Combo)
1294 * CB_GETITEMDATA(Combo, n)
1295 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1296 * CB_GETCURSEL(Combo)
1297 * CB_SETCURSEL(COMBOEX, n)
1298 * SetFocus(Combo)
1299 * the rest is supposition
1301 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1302 if (cursel == -1) {
1303 /* find match from edit against those in Combobox */
1304 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1305 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1306 for (cursel = 0; cursel < n; cursel++){
1307 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1308 CB_GETITEMDATA,
1309 cursel, 0);
1310 if ((INT)item == CB_ERR) break;
1311 if (lstrcmpiW(item->pszText, wintext) == 0) break;
1313 if ((cursel == n) || ((INT)item == CB_ERR)) {
1314 TRACE("failed to find match??? item=%p cursel=%d\n",
1315 item, cursel);
1316 if (infoPtr->hwndEdit)
1317 SetFocus(infoPtr->hwndEdit);
1318 return 0;
1321 else {
1322 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1323 CB_GETITEMDATA,
1324 cursel, 0);
1325 if ((INT)item == CB_ERR) {
1326 TRACE("failed to find match??? item=%p cursel=%d\n",
1327 item, cursel);
1328 if (infoPtr->hwndEdit)
1329 SetFocus(infoPtr->hwndEdit);
1330 return 0;
1334 /* Save flags for testing and reset them */
1335 oldflags = infoPtr->flags;
1336 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1338 if (oldflags & WCBE_ACTEDIT) {
1339 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1340 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1341 CB_GETCURSEL, 0, 0);
1342 cbeend.iWhy = CBENF_DROPDOWN;
1344 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, item->pszText)) {
1345 /* abort the change */
1346 TRACE("Notify requested abort of change\n");
1347 return 0;
1351 /* if selection has changed the set the new current selection */
1352 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1353 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1354 infoPtr->selected = cursel;
1355 SendMessageW (hwnd, CB_SETCURSEL, cursel, 0);
1356 SetFocus(infoPtr->hwndCombo);
1358 return 0;
1360 case CBN_SELCHANGE:
1362 * CB_GETCURSEL(Combo)
1363 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1364 * lstrlenA
1365 * WM_SETTEXT(Edit)
1366 * WM_GETTEXTLENGTH(Edit)
1367 * WM_GETTEXT(Edit)
1368 * EM_SETSEL(Edit, 0,0)
1369 * WM_GETTEXTLENGTH(Edit)
1370 * WM_GETTEXT(Edit)
1371 * EM_SETSEL(Edit, 0,len)
1372 * return WM_COMMAND to parent
1374 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1375 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1376 ERR("item %d not found. Problem!\n", oldItem);
1377 break;
1379 infoPtr->selected = oldItem;
1380 COMBOEX_SetEditText (infoPtr, item);
1381 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1382 (LPARAM)hwnd);
1384 case CBN_SELENDOK:
1386 * We have to change the handle since we are the control
1387 * issuing the message. IE4 depends on this.
1389 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1390 (LPARAM)hwnd);
1392 case CBN_KILLFOCUS:
1394 * from native trace:
1396 * pass to parent
1397 * WM_GETTEXT(Edit, 104)
1398 * CB_GETCURSEL(Combo) rets -1
1399 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1400 * CB_GETCURSEL(Combo)
1401 * InvalidateRect(Combo, 0, 0)
1402 * return 0
1404 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1405 (LPARAM)hwnd);
1406 if (infoPtr->flags & WCBE_ACTEDIT) {
1407 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1408 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1409 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1410 CB_GETCURSEL, 0, 0);
1411 cbeend.iWhy = CBENF_KILLFOCUS;
1413 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1414 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) {
1415 /* abort the change */
1416 TRACE("Notify requested abort of change\n");
1417 return 0;
1420 /* possible CB_GETCURSEL */
1421 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1422 return 0;
1424 case CBN_CLOSEUP:
1425 default:
1427 * We have to change the handle since we are the control
1428 * issuing the message. IE4 depends on this.
1429 * We also need to set the focus back to the Edit control
1430 * after passing the command to the parent of the ComboEx.
1432 lret = SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1433 (LPARAM)hwnd);
1434 if (infoPtr->hwndEdit)
1435 SetFocus(infoPtr->hwndEdit);
1436 return lret;
1438 return 0;
1442 inline static LRESULT
1443 COMBOEX_WM_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1445 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1446 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)lParam;
1447 CBE_ITEMDATA *item, *olditem;
1448 INT i;
1449 NMCOMBOBOXEXW nmcit;
1451 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1452 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1454 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1456 olditem = infoPtr->items;
1457 i = infoPtr->nb_items - 1;
1459 if (i == dis->itemID) {
1460 infoPtr->items = infoPtr->items->next;
1462 else {
1463 item = olditem;
1464 i--;
1466 /* find the prior item in the list */
1467 while (item->next && (i > dis->itemID)) {
1468 item = (CBE_ITEMDATA *)item->next;
1469 i--;
1471 if (!item->next || (i != dis->itemID)) {
1472 FIXME("COMBOBOXEX item structures broken. Please report!\n");
1473 return FALSE;
1475 olditem = item->next;
1476 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1478 infoPtr->nb_items--;
1480 COMBOEX_CopyItem (infoPtr, olditem, &nmcit.ceItem);
1481 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1483 if (olditem->pszText)
1484 COMCTL32_Free(olditem->pszText);
1485 COMCTL32_Free(olditem);
1487 return TRUE;
1492 inline static LRESULT
1493 COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1495 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1496 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
1497 CBE_ITEMDATA *item = 0;
1498 SIZE txtsize;
1499 RECT rect;
1500 LPWSTR str;
1501 int drawimage, drawstate;
1502 UINT xbase, x, y;
1503 UINT xioff = 0; /* size and spacer of image if any */
1504 IMAGEINFO iinfo;
1505 INT len;
1506 COLORREF nbkc, ntxc;
1508 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1510 /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
1511 if (!TRACE_ON(message)) {
1512 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1513 dis->CtlType, dis->CtlID);
1514 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1515 dis->itemID, dis->itemAction, dis->itemState);
1516 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1517 dis->hwndItem, dis->hDC, dis->rcItem.left,
1518 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1519 dis->itemData);
1522 /* MSDN says: */
1523 /* "itemID - Specifies the menu item identifier for a menu */
1524 /* item or the index of the item in a list box or combo box. */
1525 /* For an empty list box or combo box, this member can be -1. */
1526 /* This allows the application to draw only the focus */
1527 /* rectangle at the coordinates specified by the rcItem */
1528 /* member even though there are no items in the control. */
1529 /* This indicates to the user whether the list box or combo */
1530 /* box has the focus. How the bits are set in the itemAction */
1531 /* member determines whether the rectangle is to be drawn as */
1532 /* though the list box or combo box has the focus. */
1533 if (dis->itemID == 0xffffffff) {
1534 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1535 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1537 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1538 dis->rcItem.left, dis->rcItem.top,
1539 dis->rcItem.right, dis->rcItem.bottom);
1541 else if ((dis->CtlType == ODT_COMBOBOX) &&
1542 (dis->itemAction == ODA_DRAWENTIRE)) {
1543 /* draw of edit control data */
1545 /* testing */
1547 RECT exrc, cbrc, edrc;
1548 GetWindowRect (hwnd, &exrc);
1549 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1550 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1551 if (infoPtr->hwndEdit)
1552 GetWindowRect (infoPtr->hwndEdit, &edrc);
1553 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1554 exrc.left, exrc.top, exrc.right, exrc.bottom,
1555 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1556 edrc.left, edrc.top, edrc.right, edrc.bottom);
1559 else {
1560 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1561 dis->rcItem.left, dis->rcItem.top,
1562 dis->rcItem.right, dis->rcItem.bottom,
1563 dis->itemAction, dis->itemState);
1564 return 0;
1568 /* If draw item is -1 (edit control) setup the item pointer */
1569 if (dis->itemID == 0xffffffff) {
1570 CHAR str[260];
1571 INT wlen, alen;
1573 item = infoPtr->edit;
1575 if (infoPtr->hwndEdit) {
1577 /* free previous text of edit item */
1578 if (item->pszText) {
1579 COMCTL32_Free(item->pszText);
1580 item->pszText = 0;
1581 item->mask &= ~CBEIF_TEXT;
1583 alen = SendMessageA (infoPtr->hwndEdit, WM_GETTEXT, 260, (LPARAM)&str);
1584 TRACE("edit control hwndEdit=%0x, text len=%d str=<%s>\n",
1585 infoPtr->hwndEdit, alen, str);
1586 if (alen > 0) {
1587 item->mask |= CBEIF_TEXT;
1588 wlen = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
1589 if (wlen > 0) {
1590 item->pszText = (LPWSTR)COMCTL32_Alloc ((wlen + 1)*sizeof(WCHAR));
1591 MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, wlen);
1597 /* if the item pointer is not set, then get the data and locate it */
1598 if (!item) {
1599 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1600 CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
1601 if (item == (CBE_ITEMDATA *)CB_ERR)
1603 FIXME("invalid item for id %d \n",dis->itemID);
1604 return 0;
1608 COMBOEX_DumpItem (item);
1610 xbase = CBE_STARTOFFSET;
1611 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
1612 xbase += (item->iIndent * CBE_INDENT);
1613 if (item->mask & CBEIF_IMAGE) {
1614 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
1615 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
1618 switch (dis->itemAction) {
1619 case ODA_FOCUS:
1620 if (dis->itemState & ODS_SELECTED /*1*/) {
1621 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1622 RECT rect2;
1624 len = strlenW (item->pszText);
1625 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1626 rect.left = xbase + xioff - 1;
1627 rect.right = rect.left + txtsize.cx + 2;
1628 rect.top = dis->rcItem.top;
1629 rect.bottom = dis->rcItem.bottom;
1630 GetClipBox (dis->hDC, &rect2);
1631 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
1632 dis->itemID, rect.left, rect.top,
1633 rect.right, rect.bottom);
1634 TRACE(" clip=(%d,%d)-(%d,%d)\n",
1635 rect2.left, rect2.top,
1636 rect2.right, rect2.bottom);
1638 DrawFocusRect(dis->hDC, &rect);
1640 else {
1641 FIXME("ODA_FOCUS and ODS_SELECTED but no text\n");
1644 else {
1645 FIXME("ODA_FOCUS but not ODS_SELECTED\n");
1647 break;
1648 case ODA_SELECT:
1649 case ODA_DRAWENTIRE:
1650 drawimage = -1;
1651 drawstate = ILD_NORMAL;
1652 if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
1653 if (item->mask & CBEIF_IMAGE)
1654 drawimage = item->iImage;
1655 if (dis->itemState & ODS_COMBOEXLBOX) {
1656 /* drawing listbox entry */
1657 if (dis->itemState & ODS_SELECTED) {
1658 if (item->mask & CBEIF_SELECTEDIMAGE)
1659 drawimage = item->iSelectedImage;
1660 drawstate = ILD_SELECTED;
1663 else {
1664 /* drawing combo/edit entry */
1665 if (infoPtr->hwndEdit) {
1666 /* if we have an edit control, the slave the
1667 * selection state to the Edit focus state
1669 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1670 if (item->mask & CBEIF_SELECTEDIMAGE)
1671 drawimage = item->iSelectedImage;
1672 drawstate = ILD_SELECTED;
1675 else {
1676 /* if we don't have an edit control, use
1677 * the requested state.
1679 if (dis->itemState & ODS_SELECTED) {
1680 if (item->mask & CBEIF_SELECTEDIMAGE)
1681 drawimage = item->iSelectedImage;
1682 drawstate = ILD_SELECTED;
1687 if (drawimage != -1) {
1688 TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
1689 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
1690 xbase, dis->rcItem.top, drawstate);
1693 /* setup pointer to text to be drawn */
1694 if ((item->mask & CBEIF_TEXT) && item->pszText)
1695 str = item->pszText;
1696 else
1697 str = (LPWSTR) L"";
1699 /* now draw the text */
1700 len = lstrlenW (str);
1701 GetTextExtentPointW (dis->hDC, str, len, &txtsize);
1702 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1703 COLOR_HIGHLIGHT : COLOR_WINDOW);
1704 SetBkColor (dis->hDC, nbkc);
1705 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1706 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1707 SetTextColor (dis->hDC, ntxc);
1708 x = xbase + xioff;
1709 y = dis->rcItem.top +
1710 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1711 rect.left = x;
1712 rect.right = x + txtsize.cx;
1713 rect.top = dis->rcItem.top + 1;
1714 rect.bottom = dis->rcItem.bottom - 1;
1715 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1716 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1717 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1718 &rect, str, len, 0);
1719 if (dis->itemState & ODS_FOCUS) {
1720 rect.top -= 1;
1721 rect.bottom += 1;
1722 rect.left -= 1;
1723 rect.right += 1;
1724 TRACE("drawing item %d focus after text, rect=(%d,%d)-(%d,%d)\n",
1725 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1726 DrawFocusRect (dis->hDC, &rect);
1728 break;
1729 default:
1730 FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
1731 hwnd, wParam, lParam, dis->itemAction);
1734 return 0;
1738 static LRESULT
1739 COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1741 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1743 if (infoPtr->hwndCombo)
1744 DestroyWindow (infoPtr->hwndCombo);
1746 if (infoPtr->edit) {
1747 COMCTL32_Free (infoPtr->edit);
1748 infoPtr->edit = 0;
1751 if (infoPtr->items) {
1752 CBE_ITEMDATA *this, *next;
1754 this = infoPtr->items;
1755 while (this) {
1756 next = (CBE_ITEMDATA *)this->next;
1757 if ((this->mask & CBEIF_TEXT) && this->pszText)
1758 COMCTL32_Free (this->pszText);
1759 COMCTL32_Free (this);
1760 this = next;
1764 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
1766 /* free comboex info data */
1767 COMCTL32_Free (infoPtr);
1768 SetWindowLongA (hwnd, 0, 0);
1769 return 0;
1773 static LRESULT
1774 COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1776 /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
1777 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
1778 HDC hdc;
1779 SIZE mysize;
1781 hdc = GetDC (0);
1782 GetTextExtentPointA (hdc, "W", 1, &mysize);
1783 ReleaseDC (0, hdc);
1784 mis->itemHeight = mysize.cy + CBE_EXTRA;
1786 TRACE("adjusted height hwnd=%08x, height=%d\n",
1787 hwnd, mis->itemHeight);
1789 return 0;
1793 static LRESULT
1794 COMBOEX_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1796 /* WARNING: The COMBOEX_INFO structure is not yet created */
1797 DWORD oldstyle, newstyle;
1799 oldstyle = (DWORD)GetWindowLongA (hwnd, GWL_STYLE);
1800 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1801 if (newstyle != oldstyle) {
1802 TRACE("req style %08lx, reseting style %08lx\n",
1803 oldstyle, newstyle);
1804 SetWindowLongA (hwnd, GWL_STYLE, newstyle);
1806 return 1;
1810 static LRESULT
1811 COMBOEX_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1813 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1814 INT i;
1816 if (lParam == NF_REQUERY) {
1817 i = SendMessageA(GetParent (hwnd),
1818 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
1819 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1820 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1822 i = NFR_ANSI;
1824 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1825 return (LRESULT)i;
1827 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
1831 static LRESULT
1832 COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1834 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1835 RECT rect;
1837 GetWindowRect (hwnd, &rect);
1838 TRACE("my rect (%d,%d)-(%d,%d)\n",
1839 rect.left, rect.top, rect.right, rect.bottom);
1841 MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
1842 rect.bottom - rect.top, TRUE);
1844 COMBOEX_AdjustEditPos (infoPtr);
1846 return 0;
1850 static LRESULT
1851 COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
1853 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1854 RECT cbx_wrect, cbx_crect, cb_wrect;
1855 UINT width, height;
1856 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1858 GetWindowRect (hwnd, &cbx_wrect);
1859 GetClientRect (hwnd, &cbx_crect);
1860 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1862 /* width is winpos value + border width of comboex */
1863 width = wp->cx
1864 + (cbx_wrect.right-cbx_wrect.left)
1865 - (cbx_crect.right-cbx_crect.left);
1867 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1868 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1869 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1870 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1871 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1872 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1873 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1874 width, cb_wrect.bottom-cb_wrect.top);
1876 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1877 width,
1878 cb_wrect.bottom-cb_wrect.top,
1879 SWP_NOACTIVATE);
1881 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1883 /* height is combo window height plus border width of comboex */
1884 height = (cb_wrect.bottom-cb_wrect.top)
1885 + (cbx_wrect.bottom-cbx_wrect.top)
1886 - (cbx_crect.bottom-cbx_crect.top);
1887 if (wp->cy < height) wp->cy = height;
1888 if (infoPtr->hwndEdit) {
1889 COMBOEX_AdjustEditPos (infoPtr);
1890 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1893 return 0;
1897 static LRESULT WINAPI
1898 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1900 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1901 NMCBEENDEDITW cbeend;
1902 WCHAR edit_text[260];
1903 COLORREF nbkc, obkc;
1904 HDC hDC;
1905 RECT rect;
1906 LRESULT lret;
1908 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1909 hwnd, uMsg, wParam, lParam, infoPtr);
1911 if (!infoPtr) return 0;
1913 switch (uMsg)
1916 case WM_CHAR:
1917 /* handle (ignore) the return character */
1918 if (wParam == VK_RETURN) return 0;
1919 /* all other characters pass into the real Edit */
1920 return CallWindowProcA (infoPtr->prevEditWndProc,
1921 hwnd, uMsg, wParam, lParam);
1923 case WM_ERASEBKGND:
1925 * The following was determined by traces of the native
1927 hDC = (HDC) wParam;
1928 nbkc = GetSysColor (COLOR_WINDOW);
1929 obkc = SetBkColor (hDC, nbkc);
1930 GetClientRect (hwnd, &rect);
1931 TRACE("erasing (%d,%d)-(%d,%d)\n",
1932 rect.left, rect.top, rect.right, rect.bottom);
1933 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1934 SetBkColor (hDC, obkc);
1935 return CallWindowProcA (infoPtr->prevEditWndProc,
1936 hwnd, uMsg, wParam, lParam);
1938 case WM_KEYDOWN: {
1939 INT oldItem, selected;
1940 CBE_ITEMDATA *item;
1942 switch ((INT)wParam)
1944 case VK_ESCAPE:
1945 /* native version seems to do following for COMBOEX */
1947 * GetWindowTextA(Edit,&?, 0x104) x
1948 * CB_GETCURSEL to Combo rets -1 x
1949 * WM_NOTIFY to COMBOEX parent (rebar) x
1950 * (CBEN_ENDEDIT{A|W}
1951 * fChanged = FALSE x
1952 * inewSelection = -1 x
1953 * txt="www.hoho" x
1954 * iWhy = 3 x
1955 * CB_GETCURSEL to Combo rets -1 x
1956 * InvalidateRect(Combo, 0) x
1957 * WM_SETTEXT to Edit x
1958 * EM_SETSEL to Edit (0,0) x
1959 * EM_SETSEL to Edit (0,-1) x
1960 * RedrawWindow(Combo, 0, 0, 5) x
1962 TRACE("special code for VK_ESCAPE\n");
1964 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1966 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1967 cbeend.fChanged = FALSE;
1968 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1969 CB_GETCURSEL, 0, 0);
1970 cbeend.iWhy = CBENF_ESCAPE;
1972 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1973 /* abort the change */
1974 TRACE("Notify requested abort of change\n");
1975 return 0;
1977 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1978 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1979 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1980 ERR("item %d not found. Problem!\n", oldItem);
1981 break;
1983 infoPtr->selected = oldItem;
1984 COMBOEX_SetEditText (infoPtr, item);
1985 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1986 RDW_INVALIDATE);
1987 break;
1989 case VK_RETURN:
1990 /* native version seems to do following for COMBOEX */
1992 * GetWindowTextA(Edit,&?, 0x104) x
1993 * CB_GETCURSEL to Combo rets -1 x
1994 * CB_GETCOUNT to Combo rets 0
1995 * if >0 loop
1996 * CB_GETITEMDATA to match
1997 * *** above 3 lines simulated by FindItem x
1998 * WM_NOTIFY to COMBOEX parent (rebar) x
1999 * (CBEN_ENDEDIT{A|W} x
2000 * fChanged = TRUE (-1) x
2001 * iNewSelection = -1 or selected x
2002 * txt= x
2003 * iWhy = 2 (CBENF_RETURN) x
2004 * CB_GETCURSEL to Combo rets -1 x
2005 * if -1 send CB_SETCURSEL to Combo -1 x
2006 * InvalidateRect(Combo, 0, 0) x
2007 * SetFocus(Edit) x
2008 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
2011 TRACE("special code for VK_RETURN\n");
2013 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2015 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2016 selected = SendMessageW (infoPtr->hwndCombo,
2017 CB_GETCURSEL, 0, 0);
2019 if (selected != -1) {
2020 item = COMBOEX_FindItem (infoPtr, selected);
2021 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
2022 selected, debugstr_w(item->pszText));
2023 TRACE("handling VK_RETURN, edittext=%s\n",
2024 debugstr_w(edit_text));
2025 if (lstrcmpiW (item->pszText, edit_text)) {
2026 /* strings not equal -- indicate edit has changed */
2027 selected = -1;
2031 cbeend.iNewSelection = selected;
2032 cbeend.fChanged = TRUE;
2033 cbeend.iWhy = CBENF_RETURN;
2034 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2035 /* abort the change, restore previous */
2036 TRACE("Notify requested abort of change\n");
2037 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
2038 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
2039 RDW_INVALIDATE);
2040 return 0;
2042 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
2043 if (oldItem != -1) {
2044 /* if something is selected, then deselect it */
2045 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
2046 (WPARAM)-1, 0);
2048 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2049 SetFocus(infoPtr->hwndEdit);
2050 break;
2052 default:
2053 return CallWindowProcA (infoPtr->prevEditWndProc,
2054 hwnd, uMsg, wParam, lParam);
2056 return 0;
2059 case WM_SETFOCUS:
2060 /* remember the focus to set state of icon */
2061 lret = CallWindowProcA (infoPtr->prevEditWndProc,
2062 hwnd, uMsg, wParam, lParam);
2063 infoPtr->flags |= WCBE_EDITFOCUSED;
2064 return lret;
2066 case WM_KILLFOCUS:
2068 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
2070 infoPtr->flags &= ~WCBE_EDITFOCUSED;
2071 if (infoPtr->flags & WCBE_ACTEDIT) {
2072 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2074 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2075 cbeend.fChanged = FALSE;
2076 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2077 CB_GETCURSEL, 0, 0);
2078 cbeend.iWhy = CBENF_KILLFOCUS;
2080 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
2082 /* fall through */
2084 default:
2085 return CallWindowProcA (infoPtr->prevEditWndProc,
2086 hwnd, uMsg, wParam, lParam);
2088 return 0;
2092 static LRESULT WINAPI
2093 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2095 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
2096 NMCBEENDEDITW cbeend;
2097 NMMOUSE nmmse;
2098 COLORREF nbkc, obkc;
2099 HDC hDC;
2100 HWND focusedhwnd;
2101 RECT rect;
2102 WCHAR edit_text[260];
2104 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
2105 hwnd, uMsg, wParam, lParam, infoPtr);
2107 if (!infoPtr) return 0;
2109 switch (uMsg)
2112 case CB_FINDSTRINGEXACT:
2113 return COMBOEX_FindStringExact (infoPtr, wParam, lParam);
2115 case WM_DRAWITEM:
2117 * The only way this message should come is from the
2118 * child Listbox issuing the message. Flag this so
2119 * that ComboEx knows this is listbox.
2121 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
2122 return CallWindowProcA (infoPtr->prevComboWndProc,
2123 hwnd, uMsg, wParam, lParam);
2125 case WM_ERASEBKGND:
2127 * The following was determined by traces of the native
2129 hDC = (HDC) wParam;
2130 nbkc = GetSysColor (COLOR_WINDOW);
2131 obkc = SetBkColor (hDC, nbkc);
2132 GetClientRect (hwnd, &rect);
2133 TRACE("erasing (%d,%d)-(%d,%d)\n",
2134 rect.left, rect.top, rect.right, rect.bottom);
2135 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
2136 SetBkColor (hDC, obkc);
2137 return CallWindowProcA (infoPtr->prevComboWndProc,
2138 hwnd, uMsg, wParam, lParam);
2140 case WM_SETCURSOR:
2142 * WM_NOTIFY to comboex parent (rebar)
2143 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
2144 * CallWindowProc (previous)
2146 nmmse.dwItemSpec = 0;
2147 nmmse.dwItemData = 0;
2148 nmmse.pt.x = 0;
2149 nmmse.pt.y = 0;
2150 nmmse.dwHitInfo = lParam;
2151 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
2152 return CallWindowProcA (infoPtr->prevComboWndProc,
2153 hwnd, uMsg, wParam, lParam);
2155 case WM_COMMAND:
2156 switch (HIWORD(wParam)) {
2158 case EN_UPDATE:
2159 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2160 * on the EN_UPDATE
2162 return 0;
2164 case EN_KILLFOCUS:
2166 * Native does:
2168 * GetFocus() retns AA
2169 * GetWindowTextA(Edit)
2170 * CB_GETCURSEL(Combo) (got -1)
2171 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2172 * CB_GETCURSEL(Combo) (got -1)
2173 * InvalidateRect(Combo, 0, 0)
2174 * WM_KILLFOCUS(Combo, AA)
2175 * return 0;
2177 focusedhwnd = GetFocus();
2178 if (infoPtr->flags & WCBE_ACTEDIT) {
2179 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2180 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2181 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2182 CB_GETCURSEL, 0, 0);
2183 cbeend.iWhy = CBENF_KILLFOCUS;
2185 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2186 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2187 /* abort the change */
2188 TRACE("Notify requested abort of change\n");
2189 return 0;
2192 /* possible CB_GETCURSEL */
2193 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2194 if (focusedhwnd)
2195 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2196 (WPARAM)focusedhwnd, 0);
2197 return 0;
2199 case EN_SETFOCUS: {
2201 * For EN_SETFOCUS this issues the same calls and messages
2202 * as the native seems to do.
2204 * for some cases however native does the following:
2205 * (noticed after SetFocus during LBUTTONDOWN on
2206 * on dropdown arrow)
2207 * WM_GETTEXTLENGTH (Edit);
2208 * WM_GETTEXT (Edit, len+1, str);
2209 * EM_SETSEL (Edit, 0, 0);
2210 * WM_GETTEXTLENGTH (Edit);
2211 * WM_GETTEXT (Edit, len+1, str);
2212 * EM_SETSEL (Edit, 0, len);
2213 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2215 NMHDR hdr;
2217 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2218 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2219 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2220 infoPtr->flags |= WCBE_ACTEDIT;
2221 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2222 return 0;
2225 case EN_CHANGE: {
2227 * For EN_CHANGE this issues the same calls and messages
2228 * as the native seems to do.
2230 WCHAR edit_text[260];
2231 WCHAR *lastwrk;
2232 INT selected, cnt;
2233 CBE_ITEMDATA *item;
2235 selected = SendMessageW (infoPtr->hwndCombo,
2236 CB_GETCURSEL, 0, 0);
2238 /* lstrlenA( lastworkingURL ) */
2240 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2241 if (selected == -1) {
2242 lastwrk = infoPtr->edit->pszText;
2243 cnt = lstrlenW (lastwrk);
2244 if (cnt >= 259) cnt = 259;
2246 else {
2247 item = COMBOEX_FindItem (infoPtr, selected);
2248 cnt = lstrlenW (item->pszText);
2249 lastwrk = item->pszText;
2250 if (cnt >= 259) cnt = 259;
2253 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2254 selected, debugstr_w(lastwrk));
2255 TRACE("handling EN_CHANGE, edittext=%s\n",
2256 debugstr_w(edit_text));
2258 /* lstrcmpiW is between lastworkingURL and GetWindowText */
2260 if (lstrcmpiW (lastwrk, edit_text)) {
2261 /* strings not equal -- indicate edit has changed */
2262 infoPtr->flags |= WCBE_EDITCHG;
2264 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2265 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2266 CBN_EDITCHANGE),
2267 infoPtr->hwndSelf);
2268 return 0;
2271 case LBN_SELCHANGE:
2273 * Therefore from traces there is no additional code here
2277 * Using native COMCTL32 gets the following:
2278 * 1 == SHDOCVW.DLL issues call/message
2279 * 2 == COMCTL32.DLL issues call/message
2280 * 3 == WINE issues call/message
2283 * for LBN_SELCHANGE:
2284 * 1 CB_GETCURSEL(ComboEx)
2285 * 1 CB_GETDROPPEDSTATE(ComboEx)
2286 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2287 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2288 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2289 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2290 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2291 * 3 ShowWindow(ComboLB, SW_HIDE)
2292 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2293 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2294 ** end of CBRollUp
2295 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2296 * ? LB_GETCURSEL <==|
2297 * ? LB_GETTEXTLEN |
2298 * ? LB_GETTEXT | Needs to be added to
2299 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2300 * ? LB_GETITEMDATA |
2301 * ? WM_DRAWITEM(ComboEx) <==|
2303 default:
2304 break;
2305 }/* fall through */
2306 default:
2307 return CallWindowProcA (infoPtr->prevComboWndProc,
2308 hwnd, uMsg, wParam, lParam);
2310 return 0;
2314 static LRESULT WINAPI
2315 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2317 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2319 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2321 if (!COMBOEX_GetInfoPtr (hwnd)) {
2322 if (uMsg == WM_CREATE)
2323 return COMBOEX_Create (hwnd, wParam, lParam);
2324 if (uMsg == WM_NCCREATE)
2325 COMBOEX_NCCreate (hwnd, wParam, lParam);
2326 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2329 switch (uMsg)
2331 case CBEM_DELETEITEM: /* maps to CB_DELETESTRING */
2332 return COMBOEX_DeleteItem (hwnd, wParam, lParam);
2334 case CBEM_GETCOMBOCONTROL:
2335 return COMBOEX_GetComboControl (hwnd, wParam, lParam);
2337 case CBEM_GETEDITCONTROL:
2338 return COMBOEX_GetEditControl (hwnd, wParam, lParam);
2340 case CBEM_GETEXTENDEDSTYLE:
2341 return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
2343 case CBEM_GETIMAGELIST:
2344 return COMBOEX_GetImageList (hwnd, wParam, lParam);
2346 case CBEM_GETITEMA:
2347 return COMBOEX_GetItemA (hwnd, wParam, lParam);
2349 case CBEM_GETITEMW:
2350 return COMBOEX_GetItemW (hwnd, wParam, lParam);
2352 case CBEM_GETUNICODEFORMAT:
2353 return COMBOEX_GetUnicodeFormat (hwnd, wParam, lParam);
2355 case CBEM_HASEDITCHANGED:
2356 return COMBOEX_HasEditChanged (hwnd, wParam, lParam);
2358 case CBEM_INSERTITEMA:
2359 return COMBOEX_InsertItemA (hwnd, wParam, lParam);
2361 case CBEM_INSERTITEMW:
2362 return COMBOEX_InsertItemW (hwnd, wParam, lParam);
2364 case CBEM_SETEXSTYLE: /* FIXME: obsoleted, should be the same as: */
2365 case CBEM_SETEXTENDEDSTYLE:
2366 return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
2368 case CBEM_SETIMAGELIST:
2369 return COMBOEX_SetImageList (hwnd, wParam, lParam);
2371 case CBEM_SETITEMA:
2372 return COMBOEX_SetItemA (hwnd, wParam, lParam);
2374 case CBEM_SETITEMW:
2375 return COMBOEX_SetItemW (hwnd, wParam, lParam);
2377 case CBEM_SETUNICODEFORMAT:
2378 return COMBOEX_SetUnicodeFormat (hwnd, wParam, lParam);
2381 /* Combo messages we are not sure if we need to process or just forward */
2382 case CB_GETDROPPEDCONTROLRECT:
2383 case CB_GETITEMHEIGHT:
2384 case CB_GETLBTEXT:
2385 case CB_GETLBTEXTLEN:
2386 case CB_GETEXTENDEDUI:
2387 case CB_LIMITTEXT:
2388 case CB_RESETCONTENT:
2389 case CB_SELECTSTRING:
2390 case WM_SETTEXT:
2391 case WM_GETTEXT:
2392 FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
2393 uMsg, wParam, lParam);
2394 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2396 /* Combo messages OK to just forward to the regular COMBO */
2397 case CB_GETCOUNT:
2398 case CB_GETCURSEL:
2399 case CB_GETDROPPEDSTATE:
2400 case CB_SETDROPPEDWIDTH:
2401 case CB_SETEXTENDEDUI:
2402 case CB_SHOWDROPDOWN:
2403 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2405 /* Combo messages we need to process specially */
2406 case CB_FINDSTRINGEXACT:
2407 return COMBOEX_FindStringExact (COMBOEX_GetInfoPtr (hwnd),
2408 wParam, lParam);
2410 case CB_GETITEMDATA:
2411 return COMBOEX_GetItemData (hwnd, wParam, lParam);
2413 case CB_SETCURSEL:
2414 return COMBOEX_SetCursel (hwnd, wParam, lParam);
2416 case CB_SETITEMDATA:
2417 return COMBOEX_SetItemData (hwnd, wParam, lParam);
2419 case CB_SETITEMHEIGHT:
2420 return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
2424 /* Window messages passed to parent */
2425 case WM_COMMAND:
2426 return COMBOEX_Command (hwnd, wParam, lParam);
2428 case WM_NOTIFY:
2429 if (infoPtr->NtfUnicode)
2430 return SendMessageW (GetParent (hwnd),
2431 uMsg, wParam, lParam);
2432 else
2433 return SendMessageA (GetParent (hwnd),
2434 uMsg, wParam, lParam);
2437 /* Window messages we need to process */
2438 case WM_DELETEITEM:
2439 return COMBOEX_WM_DeleteItem (hwnd, wParam, lParam);
2441 case WM_DRAWITEM:
2442 return COMBOEX_DrawItem (hwnd, wParam, lParam);
2444 case WM_DESTROY:
2445 return COMBOEX_Destroy (hwnd, wParam, lParam);
2447 case WM_MEASUREITEM:
2448 return COMBOEX_MeasureItem (hwnd, wParam, lParam);
2450 case WM_NOTIFYFORMAT:
2451 return COMBOEX_NotifyFormat (hwnd, wParam, lParam);
2453 case WM_SIZE:
2454 return COMBOEX_Size (hwnd, wParam, lParam);
2456 case WM_WINDOWPOSCHANGING:
2457 return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
2459 default:
2460 if (uMsg >= WM_USER)
2461 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2462 uMsg, wParam, lParam);
2463 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2465 return 0;
2469 VOID
2470 COMBOEX_Register (void)
2472 WNDCLASSA wndClass;
2474 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2475 wndClass.style = CS_GLOBALCLASS;
2476 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2477 wndClass.cbClsExtra = 0;
2478 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2479 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2480 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2481 wndClass.lpszClassName = WC_COMBOBOXEXA;
2483 RegisterClassA (&wndClass);
2485 ComboExInfo = GlobalAddAtomA("CC32SubclassInfo");
2489 VOID
2490 COMBOEX_Unregister (void)
2492 UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);