Never delete the font object received by WM_SETFONT.
[wine/testsucceed.git] / dlls / comctl32 / comboex.c
blob508a592e287ff7c155208941999651955181edc5
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) {
332 cit->pszText = item->pszText;
333 cit->cchTextMax = item->cchTextMax;
335 if (cit->mask & CBEIF_IMAGE)
336 cit->iImage = item->iImage;
337 if (cit->mask & CBEIF_SELECTEDIMAGE)
338 cit->iSelectedImage = item->iSelectedImage;
339 if (cit->mask & CBEIF_OVERLAY)
340 cit->iOverlay = item->iOverlay;
341 if (cit->mask & CBEIF_INDENT)
342 cit->iIndent = item->iIndent;
343 if (cit->mask & CBEIF_LPARAM)
344 cit->lParam = item->lParam;
349 static void
350 COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
352 SIZE mysize;
353 IMAGEINFO iinfo;
354 INT x, y, w, h, xoff = 0;
355 RECT rect;
357 if (!infoPtr->hwndEdit) return;
358 iinfo.rcImage.left = iinfo.rcImage.right = 0;
359 if (infoPtr->himl) {
360 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
361 xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
363 GetClientRect (infoPtr->hwndCombo, &rect);
364 InflateRect (&rect, -2, -2);
365 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
367 /* reposition the Edit control based on whether icon exists */
368 COMBOEX_GetComboFontSize (infoPtr, &mysize);
369 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
370 x = xoff + CBE_STARTOFFSET + 1;
371 y = CBE_EXTRA + 1;
372 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
373 h = mysize.cy + 1;
375 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
376 rect.left, rect.top, rect.right, rect.bottom,
377 x, y, x + w, y + h);
378 SetWindowPos(infoPtr->hwndEdit, HWND_TOP,
379 x, y,
380 w, h,
381 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
385 static void
386 COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
388 SIZE mysize;
389 UINT cy;
390 IMAGEINFO iinfo;
392 COMBOEX_GetComboFontSize (infoPtr, &mysize);
393 cy = mysize.cy + CBE_EXTRA;
394 if (infoPtr->himl) {
395 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
396 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
397 TRACE("upgraded height due to image: height=%d\n", cy);
399 SendMessageW (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
400 if (infoPtr->hwndCombo)
401 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
402 (WPARAM) 0, (LPARAM) cy);
406 static void
407 COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
409 if (!infoPtr->hwndEdit) return;
410 /* native issues the following messages to the {Edit} control */
411 /* WM_SETTEXT (0,addr) */
412 /* EM_SETSEL32 (0,0) */
413 /* EM_SETSEL32 (0,-1) */
414 if (item->mask & CBEIF_TEXT) {
415 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
416 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
417 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
422 static CBE_ITEMDATA *
423 COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
425 CBE_ITEMDATA *item;
426 INT i;
428 if ((index > infoPtr->nb_items) || (index < -1))
429 return 0;
430 if (index == -1)
431 return infoPtr->edit;
432 item = infoPtr->items;
433 i = infoPtr->nb_items - 1;
435 /* find the item in the list */
436 while (item && (i > index)) {
437 item = (CBE_ITEMDATA *)item->next;
438 i--;
440 if (!item || (i != index)) {
441 FIXME("COMBOBOXEX item structures broken. Please report!\n");
442 return 0;
444 return item;
448 static void
449 COMBOEX_WarnCallBack (CBE_ITEMDATA *item)
451 if (item->pszText == LPSTR_TEXTCALLBACKW)
452 FIXME("Callback not implemented yet for pszText\n");
453 if (item->iImage == I_IMAGECALLBACK)
454 FIXME("Callback not implemented yet for iImage\n");
455 if (item->iSelectedImage == I_IMAGECALLBACK)
456 FIXME("Callback not implemented yet for iSelectedImage\n");
457 if (item->iOverlay == I_IMAGECALLBACK)
458 FIXME("Callback not implemented yet for iOverlay\n");
459 if (item->iIndent == I_INDENTCALLBACK)
460 FIXME("Callback not implemented yet for iIndent\n");
464 /* *** CBEM_xxx message support *** */
467 static LRESULT
468 COMBOEX_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
470 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
471 INT index = (INT) wParam;
472 CBE_ITEMDATA *item;
474 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
476 /* if item number requested does not exist then return failure */
477 if ((index > infoPtr->nb_items) || (index < 0)) {
478 ERR("attempt to delete item that does not exist\n");
479 return CB_ERR;
482 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
483 ERR("attempt to delete item that was not found!\n");
484 return CB_ERR;
487 /* doing this will result in WM_DELETEITEM being issued */
488 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
490 return infoPtr->nb_items;
494 inline static LRESULT
495 COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
497 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
499 TRACE("\n");
501 return (LRESULT)infoPtr->hwndCombo;
505 inline static LRESULT
506 COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
508 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
510 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
511 return 0;
513 TRACE("-- 0x%x\n", infoPtr->hwndEdit);
515 return (LRESULT)infoPtr->hwndEdit;
519 inline static LRESULT
520 COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
522 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
524 TRACE("-- 0x%08lx\n", infoPtr->dwExtStyle);
526 return (LRESULT)infoPtr->dwExtStyle;
530 inline static LRESULT
531 COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
533 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
535 TRACE("-- %p\n", infoPtr->himl);
537 return (LRESULT)infoPtr->himl;
541 static LRESULT
542 COMBOEX_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
544 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
545 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
546 INT index;
547 CBE_ITEMDATA *item;
549 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
551 /* get real index of item to insert */
552 index = cit->iItem;
554 /* if item number requested does not exist then return failure */
555 if ((index > infoPtr->nb_items) || (index < -1)) {
556 ERR("attempt to get item that does not exist\n");
557 return 0;
560 /* if the item is the edit control and there is no edit control, skip */
561 if ((index == -1) &&
562 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
563 return 0;
565 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
566 ERR("attempt to get item that was not found!\n");
567 return 0;
570 COMBOEX_CopyItem (infoPtr, item, cit);
572 return TRUE;
576 inline static LRESULT
577 COMBOEX_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
579 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
580 COMBOBOXEXITEMW tmpcit;
581 INT len;
583 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
585 tmpcit.mask = cit->mask;
586 tmpcit.iItem = cit->iItem;
587 COMBOEX_GetItemW (hwnd, wParam, (LPARAM) &tmpcit);
589 len = WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1, 0, 0, NULL, NULL);
590 if (len > 0)
591 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
592 cit->pszText, cit->cchTextMax, NULL, NULL);
594 cit->iImage = tmpcit.iImage;
595 cit->iSelectedImage = tmpcit.iSelectedImage;
596 cit->iOverlay = tmpcit.iOverlay;
597 cit->iIndent = tmpcit.iIndent;
598 cit->lParam = tmpcit.lParam;
600 return TRUE;
604 inline static LRESULT
605 COMBOEX_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
607 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
609 TRACE("%s hwnd=0x%x\n",
610 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
612 return infoPtr->bUnicode;
616 inline static LRESULT
617 COMBOEX_HasEditChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
619 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
621 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
622 return FALSE;
623 if ((infoPtr->flags & (WCBE_ACTEDIT | WCBE_EDITCHG)) ==
624 (WCBE_ACTEDIT | WCBE_EDITCHG))
625 return TRUE;
626 return FALSE;
630 static LRESULT
631 COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
633 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
634 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
635 INT index;
636 CBE_ITEMDATA *item;
637 NMCOMBOBOXEXW nmcit;
639 TRACE("\n");
641 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
643 /* get real index of item to insert */
644 index = cit->iItem;
645 if (index == -1) index = infoPtr->nb_items;
646 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
648 /* get space and chain it in */
649 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
650 item->next = NULL;
651 item->pszText = NULL;
653 /* locate position to insert new item in */
654 if (index == infoPtr->nb_items) {
655 /* fast path for iItem = -1 */
656 item->next = infoPtr->items;
657 infoPtr->items = item;
659 else {
660 INT i = infoPtr->nb_items-1;
661 CBE_ITEMDATA *moving = infoPtr->items;
663 while ((i > index) && moving) {
664 moving = (CBE_ITEMDATA *)moving->next;
665 i--;
667 if (!moving) {
668 FIXME("COMBOBOXEX item structures broken. Please report!\n");
669 COMCTL32_Free(item);
670 return -1;
672 item->next = moving->next;
673 moving->next = item;
676 /* fill in our hidden item structure */
677 item->mask = cit->mask;
678 if (item->mask & CBEIF_TEXT) {
679 LPWSTR str;
680 INT len;
682 str = cit->pszText;
683 if (!str) str = (LPWSTR) L"";
684 len = strlenW (str);
685 if (len > 0) {
686 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
687 strcpyW (item->pszText, str);
689 else
690 item->pszText = NULL;
691 item->cchTextMax = cit->cchTextMax;
693 if (item->mask & CBEIF_IMAGE)
694 item->iImage = cit->iImage;
695 if (item->mask & CBEIF_SELECTEDIMAGE)
696 item->iSelectedImage = cit->iSelectedImage;
697 if (item->mask & CBEIF_OVERLAY)
698 item->iOverlay = cit->iOverlay;
699 if (item->mask & CBEIF_INDENT)
700 item->iIndent = cit->iIndent;
701 if (item->mask & CBEIF_LPARAM)
702 item->lParam = cit->lParam;
703 infoPtr->nb_items++;
705 COMBOEX_WarnCallBack (item);
707 COMBOEX_DumpItem (item);
709 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
710 (WPARAM)cit->iItem, (LPARAM)item);
712 COMBOEX_CopyItem (infoPtr, item, &nmcit.ceItem);
713 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
715 return index;
720 static LRESULT
721 COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
723 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
724 COMBOBOXEXITEMW citW;
725 LRESULT ret;
727 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
728 if (cit->mask & CBEIF_TEXT) {
729 LPSTR str;
730 INT len;
732 str = cit->pszText;
733 if (!str) str="";
734 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
735 if (len > 0) {
736 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
737 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
740 ret = COMBOEX_InsertItemW(hwnd,wParam,(LPARAM)&citW);;
742 if (cit->mask & CBEIF_TEXT)
743 COMCTL32_Free(citW.pszText);
744 return ret;
748 static LRESULT
749 COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
751 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
752 DWORD dwTemp;
754 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
756 dwTemp = infoPtr->dwExtStyle;
758 if (lParam & (CBES_EX_NOEDITIMAGEINDENT |
759 CBES_EX_PATHWORDBREAKPROC |
760 CBES_EX_NOSIZELIMIT |
761 CBES_EX_CASESENSITIVE))
762 FIXME("Extended style not implemented %08lx\n", lParam);
764 if ((DWORD)wParam) {
765 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
767 else
768 infoPtr->dwExtStyle = (DWORD)lParam;
771 * native does this for CBES_EX_NOEDITIMAGE state change
773 if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
774 (dwTemp & CBES_EX_NOEDITIMAGE)) {
775 /* if state of EX_NOEDITIMAGE changes, invalidate all */
776 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
777 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
778 InvalidateRect (hwnd, NULL, TRUE);
779 COMBOEX_AdjustEditPos (infoPtr);
780 if (infoPtr->hwndEdit)
781 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
784 return (LRESULT)dwTemp;
788 inline static LRESULT
789 COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
791 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
792 HIMAGELIST himlTemp;
794 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
796 himlTemp = infoPtr->himl;
797 infoPtr->himl = (HIMAGELIST)lParam;
799 COMBOEX_ReSize (hwnd, infoPtr);
800 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
802 /* reposition the Edit control based on whether icon exists */
803 COMBOEX_AdjustEditPos (infoPtr);
804 return (LRESULT)himlTemp;
807 static LRESULT
808 COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
810 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
811 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
812 INT index;
813 CBE_ITEMDATA *item;
815 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
817 /* get real index of item to insert */
818 index = cit->iItem;
820 /* if item number requested does not exist then return failure */
821 if ((index > infoPtr->nb_items) || (index < -1)) {
822 ERR("attempt to set item that does not exist yet!\n");
823 return 0;
826 /* if the item is the edit control and there is no edit control, skip */
827 if ((index == -1) &&
828 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
829 return 0;
831 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
832 ERR("attempt to set item that was not found!\n");
833 return 0;
836 /* add/change stuff to the internal item structure */
837 item->mask |= cit->mask;
838 if (cit->mask & CBEIF_TEXT) {
839 LPWSTR str;
840 INT len;
841 WCHAR emptystr[1] = {0};
843 str = cit->pszText;
844 if (!str) str=emptystr;
845 len = strlenW(str);
846 if (len > 0) {
847 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
848 strcpyW(item->pszText,str);
850 item->cchTextMax = cit->cchTextMax;
852 if (cit->mask & CBEIF_IMAGE)
853 item->iImage = cit->iImage;
854 if (cit->mask & CBEIF_SELECTEDIMAGE)
855 item->iSelectedImage = cit->iSelectedImage;
856 if (cit->mask & CBEIF_OVERLAY)
857 item->iOverlay = cit->iOverlay;
858 if (cit->mask & CBEIF_INDENT)
859 item->iIndent = cit->iIndent;
860 if (cit->mask & CBEIF_LPARAM)
861 cit->lParam = cit->lParam;
863 COMBOEX_WarnCallBack (item);
865 COMBOEX_DumpItem (item);
867 /* if original request was to update edit control, do some fast foot work */
868 if (cit->iItem == -1) {
869 COMBOEX_SetEditText (infoPtr, item);
870 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
872 return TRUE;
875 static LRESULT
876 COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
878 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
879 COMBOBOXEXITEMW citW;
880 LRESULT ret;
882 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
883 if (cit->mask & CBEIF_TEXT) {
884 LPSTR str;
885 INT len;
887 str = cit->pszText;
888 if (!str) str="";
889 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
890 if (len > 0) {
891 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
892 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
895 ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
897 if (cit->mask & CBEIF_TEXT)
898 COMCTL32_Free(citW.pszText);
899 return ret;
903 inline static LRESULT
904 COMBOEX_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
906 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
907 BOOL bTemp = infoPtr->bUnicode;
909 TRACE("to %s hwnd=0x%04x, was %s\n",
910 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd,
911 (bTemp) ? "TRUE" : "FALSE");
913 infoPtr->bUnicode = (BOOL)wParam;
915 return bTemp;
920 /* *** CB_xxx message support *** */
923 static LRESULT
924 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
926 INT i, count;
927 CBE_ITEMDATA *item;
928 LPWSTR desired = NULL;
929 INT start = (INT) wParam;
931 i = MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
932 if (i > 0) {
933 desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
934 MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, desired, i);
937 count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0 , 0);
939 /* now search from after starting loc and wrapping back to start */
940 for(i=start+1; i<count; i++) {
941 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
942 CB_GETITEMDATA, (WPARAM)i, 0);
943 TRACE("desired=%s, item=%s\n",
944 debugstr_w(desired), debugstr_w(item->pszText));
945 if (lstrcmpiW(item->pszText, desired) == 0) {
946 COMCTL32_Free (desired);
947 return i;
950 for(i=0; i<=start; 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 COMCTL32_Free(desired);
961 return CB_ERR;
965 static LRESULT
966 COMBOEX_GetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
968 INT index = wParam;
969 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
970 CBE_ITEMDATA *item1, *item2;
971 LRESULT lret = 0;
973 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
974 wParam, lParam);
975 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
976 item2 = COMBOEX_FindItem (infoPtr, index);
977 if (item2 != item1) {
978 ERR("data structures damaged!\n");
979 return CB_ERR;
981 if (item1->mask & CBEIF_LPARAM)
982 lret = (LRESULT) item1->lParam;
983 TRACE("returning 0x%08lx\n", lret);
984 return lret;
986 lret = (LRESULT)item1;
987 TRACE("non-valid result from combo, returning 0x%08lx\n", lret);
988 return lret;
992 static LRESULT
993 COMBOEX_SetCursel (HWND hwnd, WPARAM wParam, LPARAM lParam)
995 INT index = wParam;
996 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
997 CBE_ITEMDATA *item;
998 LRESULT lret;
1000 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
1001 /* FIXME: need to clear selection */
1002 return CB_ERR;
1005 TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
1006 debugstr_w(item->pszText) : "<null>");
1007 infoPtr->selected = index;
1009 lret = SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, wParam, lParam);
1010 COMBOEX_SetEditText (infoPtr, item);
1011 return lret;
1015 static LRESULT
1016 COMBOEX_SetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
1018 INT index = wParam;
1019 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1020 CBE_ITEMDATA *item1, *item2;
1022 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
1023 wParam, lParam);
1024 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
1025 item2 = COMBOEX_FindItem (infoPtr, index);
1026 if (item2 != item1) {
1027 ERR("data structures damaged!\n");
1028 return CB_ERR;
1030 item1->mask |= CBEIF_LPARAM;
1031 item1->lParam = lParam;
1032 TRACE("setting lparam to 0x%08lx\n", lParam);
1033 return 0;
1035 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
1036 return (LRESULT)item1;
1040 static LRESULT
1041 COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
1043 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1044 RECT cb_wrect, cbx_wrect, cbx_crect;
1045 LRESULT ret = 0;
1046 UINT height;
1048 /* First, lets forward the message to the normal combo control
1049 just like Windows. */
1050 if (infoPtr->hwndCombo)
1051 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
1053 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1054 GetWindowRect (hwnd, &cbx_wrect);
1055 GetClientRect (hwnd, &cbx_crect);
1056 /* the height of comboex as height of the combo + comboex border */
1057 height = cb_wrect.bottom-cb_wrect.top
1058 + cbx_wrect.bottom-cbx_wrect.top
1059 - (cbx_crect.bottom-cbx_crect.top);
1060 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1061 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1062 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1063 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1064 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1065 cbx_wrect.right-cbx_wrect.left, height);
1066 SetWindowPos (hwnd, HWND_TOP, 0, 0,
1067 cbx_wrect.right-cbx_wrect.left,
1068 height,
1069 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1071 return ret;
1075 /* *** WM_xxx message support *** */
1078 static LRESULT
1079 COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1081 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
1082 COMBOEX_INFO *infoPtr;
1083 DWORD dwComboStyle;
1084 LOGFONTA mylogfont;
1085 CBE_ITEMDATA *item;
1086 RECT wnrc1, clrc1, cmbwrc;
1087 LONG test;
1088 INT i;
1090 /* allocate memory for info structure */
1091 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
1092 if (infoPtr == NULL) {
1093 ERR("could not allocate info memory!\n");
1094 return 0;
1097 /* initialize info structure */
1099 infoPtr->items = NULL;
1100 infoPtr->nb_items = 0;
1101 infoPtr->hwndSelf = hwnd;
1102 infoPtr->selected = -1;
1104 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1106 i = SendMessageA(GetParent (hwnd),
1107 WM_NOTIFYFORMAT, hwnd, NF_QUERY);
1108 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1109 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1111 i = NFR_ANSI;
1113 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1115 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1117 /* create combo box */
1118 dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
1119 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
1121 GetWindowRect(hwnd, &wnrc1);
1122 GetClientRect(hwnd, &clrc1);
1123 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1124 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1125 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
1126 TRACE("combo style=%08lx, adding style=%08lx\n", dwComboStyle,
1127 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1128 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1129 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED);
1131 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1132 /* specified. It then creates it's own version of the EDIT control */
1133 /* and makes the ComboBox the parent. This is because a normal */
1134 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
1135 /* We also need to place the edit control at the proper location */
1136 /* (allow space for the icons). */
1138 infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
1139 /* following line added to match native */
1140 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1141 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1142 /* was base and is necessary */
1143 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
1144 cs->y, cs->x, cs->cx, cs->cy, hwnd,
1145 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1146 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
1149 * native does the following at this point according to trace:
1150 * GetWindowThreadProcessId(hwndCombo,0)
1151 * GetCurrentThreadId()
1152 * GetWindowThreadProcessId(hwndCombo, &???)
1153 * GetCurrentProcessId()
1157 * Setup a property to hold the pointer to the COMBOBOXEX
1158 * data structure.
1160 test = GetPropA(infoPtr->hwndCombo, (LPCSTR)(LONG)ComboExInfo);
1161 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1162 SetPropA(infoPtr->hwndCombo, "CC32SubclassInfo", (LONG)infoPtr);
1164 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndCombo,
1165 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
1166 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1170 * Now create our own EDIT control so we can position it.
1171 * It is created only for CBS_DROPDOWN style
1173 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1174 infoPtr->hwndEdit = CreateWindowExA (0, "EDIT", "",
1175 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1176 0, 0, 0, 0, /* will set later */
1177 infoPtr->hwndCombo,
1178 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1179 GetWindowLongA (hwnd, GWL_HINSTANCE),
1180 NULL);
1182 /* native does the following at this point according to trace:
1183 * GetWindowThreadProcessId(hwndEdit,0)
1184 * GetCurrentThreadId()
1185 * GetWindowThreadProcessId(hwndEdit, &???)
1186 * GetCurrentProcessId()
1190 * Setup a property to hold the pointer to the COMBOBOXEX
1191 * data structure.
1193 test = GetPropA(infoPtr->hwndEdit, (LPCSTR)(LONG)ComboExInfo);
1194 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1195 SetPropA(infoPtr->hwndEdit, "CC32SubclassInfo", (LONG)infoPtr);
1197 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndEdit,
1198 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1199 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1201 else {
1202 infoPtr->hwndEdit = 0;
1203 infoPtr->font = 0;
1207 * Locate the default font if necessary and then set it in
1208 * all associated controls
1210 if (!infoPtr->font) {
1211 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1212 &mylogfont, 0);
1213 infoPtr->font = infoPtr->hDefaultFont = CreateFontIndirectA (&mylogfont);
1215 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1216 if (infoPtr->hwndEdit) {
1217 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1218 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1221 COMBOEX_ReSize (hwnd, infoPtr);
1223 /* Above is fairly certain, below is much less certain. */
1225 GetWindowRect(hwnd, &wnrc1);
1226 GetClientRect(hwnd, &clrc1);
1227 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1228 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1229 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1230 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1231 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1232 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1233 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1234 SWP_NOACTIVATE | SWP_NOREDRAW);
1236 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1237 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1238 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1239 SetWindowPos(hwnd, HWND_TOP,
1240 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1241 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1243 COMBOEX_AdjustEditPos (infoPtr);
1246 * Create an item structure to represent the data in the
1247 * EDIT control.
1249 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1250 item->next = NULL;
1251 item->pszText = NULL;
1252 item->mask = 0;
1253 infoPtr->edit = item;
1255 return 0;
1259 inline static LRESULT
1260 COMBOEX_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
1262 LRESULT lret;
1263 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1264 INT command = HIWORD(wParam);
1265 CBE_ITEMDATA *item = 0;
1266 WCHAR wintext[520];
1267 INT cursel, n, oldItem;
1268 NMCBEENDEDITW cbeend;
1269 DWORD oldflags;
1271 TRACE("for command %d\n", command);
1273 switch (command)
1275 case CBN_DROPDOWN:
1276 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1277 (LPARAM)hwnd);
1279 * from native trace of first dropdown after typing in URL in IE4
1280 * CB_GETCURSEL(Combo)
1281 * GetWindowText(Edit)
1282 * CB_GETCURSEL(Combo)
1283 * CB_GETCOUNT(Combo)
1284 * CB_GETITEMDATA(Combo, n)
1285 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1286 * CB_GETCURSEL(Combo)
1287 * CB_SETCURSEL(COMBOEX, n)
1288 * SetFocus(Combo)
1289 * the rest is supposition
1291 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1292 if (cursel == -1) {
1293 /* find match from edit against those in Combobox */
1294 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1295 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1296 for (cursel = 0; cursel < n; cursel++){
1297 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1298 CB_GETITEMDATA,
1299 cursel, 0);
1300 if ((INT)item == CB_ERR) break;
1301 if (lstrcmpiW(item->pszText, wintext) == 0) break;
1303 if ((cursel == n) || ((INT)item == CB_ERR)) {
1304 TRACE("failed to find match??? item=%p cursel=%d\n",
1305 item, cursel);
1306 if (infoPtr->hwndEdit)
1307 SetFocus(infoPtr->hwndEdit);
1308 return 0;
1311 else {
1312 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1313 CB_GETITEMDATA,
1314 cursel, 0);
1315 if ((INT)item == CB_ERR) {
1316 TRACE("failed to find match??? item=%p cursel=%d\n",
1317 item, cursel);
1318 if (infoPtr->hwndEdit)
1319 SetFocus(infoPtr->hwndEdit);
1320 return 0;
1324 /* Save flags for testing and reset them */
1325 oldflags = infoPtr->flags;
1326 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1328 if (oldflags & WCBE_ACTEDIT) {
1329 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1330 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1331 CB_GETCURSEL, 0, 0);
1332 cbeend.iWhy = CBENF_DROPDOWN;
1334 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, item->pszText)) {
1335 /* abort the change */
1336 TRACE("Notify requested abort of change\n");
1337 return 0;
1341 /* if selection has changed the set the new current selection */
1342 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1343 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1344 infoPtr->selected = cursel;
1345 SendMessageW (hwnd, CB_SETCURSEL, cursel, 0);
1346 SetFocus(infoPtr->hwndCombo);
1348 return 0;
1350 case CBN_SELCHANGE:
1352 * CB_GETCURSEL(Combo)
1353 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1354 * lstrlenA
1355 * WM_SETTEXT(Edit)
1356 * WM_GETTEXTLENGTH(Edit)
1357 * WM_GETTEXT(Edit)
1358 * EM_SETSEL(Edit, 0,0)
1359 * WM_GETTEXTLENGTH(Edit)
1360 * WM_GETTEXT(Edit)
1361 * EM_SETSEL(Edit, 0,len)
1362 * return WM_COMMAND to parent
1364 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1365 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1366 ERR("item %d not found. Problem!\n", oldItem);
1367 break;
1369 infoPtr->selected = oldItem;
1370 COMBOEX_SetEditText (infoPtr, item);
1371 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1372 (LPARAM)hwnd);
1374 case CBN_SELENDOK:
1376 * We have to change the handle since we are the control
1377 * issuing the message. IE4 depends on this.
1379 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1380 (LPARAM)hwnd);
1382 case CBN_KILLFOCUS:
1384 * from native trace:
1386 * pass to parent
1387 * WM_GETTEXT(Edit, 104)
1388 * CB_GETCURSEL(Combo) rets -1
1389 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1390 * CB_GETCURSEL(Combo)
1391 * InvalidateRect(Combo, 0, 0)
1392 * return 0
1394 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1395 (LPARAM)hwnd);
1396 if (infoPtr->flags & WCBE_ACTEDIT) {
1397 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1398 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1399 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1400 CB_GETCURSEL, 0, 0);
1401 cbeend.iWhy = CBENF_KILLFOCUS;
1403 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1404 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) {
1405 /* abort the change */
1406 TRACE("Notify requested abort of change\n");
1407 return 0;
1410 /* possible CB_GETCURSEL */
1411 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1412 return 0;
1414 case CBN_CLOSEUP:
1415 default:
1417 * We have to change the handle since we are the control
1418 * issuing the message. IE4 depends on this.
1419 * We also need to set the focus back to the Edit control
1420 * after passing the command to the parent of the ComboEx.
1422 lret = SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1423 (LPARAM)hwnd);
1424 if (infoPtr->hwndEdit)
1425 SetFocus(infoPtr->hwndEdit);
1426 return lret;
1428 return 0;
1432 inline static LRESULT
1433 COMBOEX_WM_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1435 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1436 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)lParam;
1437 CBE_ITEMDATA *item, *olditem;
1438 INT i;
1439 NMCOMBOBOXEXW nmcit;
1441 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1442 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1444 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1446 olditem = infoPtr->items;
1447 i = infoPtr->nb_items - 1;
1449 if (i == dis->itemID) {
1450 infoPtr->items = infoPtr->items->next;
1452 else {
1453 item = olditem;
1454 i--;
1456 /* find the prior item in the list */
1457 while (item->next && (i > dis->itemID)) {
1458 item = (CBE_ITEMDATA *)item->next;
1459 i--;
1461 if (!item->next || (i != dis->itemID)) {
1462 FIXME("COMBOBOXEX item structures broken. Please report!\n");
1463 return FALSE;
1465 olditem = item->next;
1466 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1468 infoPtr->nb_items--;
1470 COMBOEX_CopyItem (infoPtr, olditem, &nmcit.ceItem);
1471 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1473 if (olditem->pszText)
1474 COMCTL32_Free(olditem->pszText);
1475 COMCTL32_Free(olditem);
1477 return TRUE;
1482 inline static LRESULT
1483 COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1485 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1486 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
1487 CBE_ITEMDATA *item = 0;
1488 SIZE txtsize;
1489 RECT rect;
1490 LPWSTR str;
1491 int drawimage, drawstate;
1492 UINT xbase, x, y;
1493 UINT xioff = 0; /* size and spacer of image if any */
1494 IMAGEINFO iinfo;
1495 INT len;
1496 COLORREF nbkc, ntxc;
1498 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1500 /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
1501 if (!TRACE_ON(message)) {
1502 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1503 dis->CtlType, dis->CtlID);
1504 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1505 dis->itemID, dis->itemAction, dis->itemState);
1506 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1507 dis->hwndItem, dis->hDC, dis->rcItem.left,
1508 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1509 dis->itemData);
1512 /* MSDN says: */
1513 /* "itemID - Specifies the menu item identifier for a menu */
1514 /* item or the index of the item in a list box or combo box. */
1515 /* For an empty list box or combo box, this member can be -1. */
1516 /* This allows the application to draw only the focus */
1517 /* rectangle at the coordinates specified by the rcItem */
1518 /* member even though there are no items in the control. */
1519 /* This indicates to the user whether the list box or combo */
1520 /* box has the focus. How the bits are set in the itemAction */
1521 /* member determines whether the rectangle is to be drawn as */
1522 /* though the list box or combo box has the focus. */
1523 if (dis->itemID == 0xffffffff) {
1524 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1525 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1527 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1528 dis->rcItem.left, dis->rcItem.top,
1529 dis->rcItem.right, dis->rcItem.bottom);
1531 else if ((dis->CtlType == ODT_COMBOBOX) &&
1532 (dis->itemAction == ODA_DRAWENTIRE)) {
1533 /* draw of edit control data */
1535 /* testing */
1537 RECT exrc, cbrc, edrc;
1538 GetWindowRect (hwnd, &exrc);
1539 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1540 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1541 if (infoPtr->hwndEdit)
1542 GetWindowRect (infoPtr->hwndEdit, &edrc);
1543 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1544 exrc.left, exrc.top, exrc.right, exrc.bottom,
1545 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1546 edrc.left, edrc.top, edrc.right, edrc.bottom);
1549 else {
1550 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1551 dis->rcItem.left, dis->rcItem.top,
1552 dis->rcItem.right, dis->rcItem.bottom,
1553 dis->itemAction, dis->itemState);
1554 return 0;
1558 /* If draw item is -1 (edit control) setup the item pointer */
1559 if (dis->itemID == 0xffffffff) {
1560 CHAR str[260];
1561 INT wlen, alen;
1563 item = infoPtr->edit;
1565 if (infoPtr->hwndEdit) {
1567 /* free previous text of edit item */
1568 if (item->pszText) {
1569 COMCTL32_Free(item->pszText);
1570 item->pszText = 0;
1571 item->mask &= ~CBEIF_TEXT;
1573 alen = SendMessageA (infoPtr->hwndEdit, WM_GETTEXT, 260, (LPARAM)&str);
1574 TRACE("edit control hwndEdit=%0x, text len=%d str=<%s>\n",
1575 infoPtr->hwndEdit, alen, str);
1576 if (alen > 0) {
1577 item->mask |= CBEIF_TEXT;
1578 wlen = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
1579 if (wlen > 0) {
1580 item->pszText = (LPWSTR)COMCTL32_Alloc ((wlen + 1)*sizeof(WCHAR));
1581 MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, wlen);
1587 /* if the item pointer is not set, then get the data and locate it */
1588 if (!item) {
1589 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1590 CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
1591 if (item == (CBE_ITEMDATA *)CB_ERR)
1593 FIXME("invalid item for id %d \n",dis->itemID);
1594 return 0;
1598 COMBOEX_DumpItem (item);
1600 xbase = CBE_STARTOFFSET;
1601 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
1602 xbase += (item->iIndent * CBE_INDENT);
1603 if (item->mask & CBEIF_IMAGE) {
1604 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
1605 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
1608 switch (dis->itemAction) {
1609 case ODA_FOCUS:
1610 if (dis->itemState & ODS_SELECTED /*1*/) {
1611 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1612 RECT rect2;
1614 len = strlenW (item->pszText);
1615 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1616 rect.left = xbase + xioff - 1;
1617 rect.right = rect.left + txtsize.cx + 2;
1618 rect.top = dis->rcItem.top;
1619 rect.bottom = dis->rcItem.bottom;
1620 GetClipBox (dis->hDC, &rect2);
1621 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
1622 dis->itemID, rect.left, rect.top,
1623 rect.right, rect.bottom);
1624 TRACE(" clip=(%d,%d)-(%d,%d)\n",
1625 rect2.left, rect2.top,
1626 rect2.right, rect2.bottom);
1628 DrawFocusRect(dis->hDC, &rect);
1630 else {
1631 FIXME("ODA_FOCUS and ODS_SELECTED but no text\n");
1634 else {
1635 FIXME("ODA_FOCUS but not ODS_SELECTED\n");
1637 break;
1638 case ODA_SELECT:
1639 case ODA_DRAWENTIRE:
1640 drawimage = -1;
1641 drawstate = ILD_NORMAL;
1642 if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
1643 if (item->mask & CBEIF_IMAGE)
1644 drawimage = item->iImage;
1645 if (dis->itemState & ODS_COMBOEXLBOX) {
1646 /* drawing listbox entry */
1647 if (dis->itemState & ODS_SELECTED) {
1648 if (item->mask & CBEIF_SELECTEDIMAGE)
1649 drawimage = item->iSelectedImage;
1650 drawstate = ILD_SELECTED;
1653 else {
1654 /* drawing combo/edit entry */
1655 if (infoPtr->hwndEdit) {
1656 /* if we have an edit control, the slave the
1657 * selection state to the Edit focus state
1659 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1660 if (item->mask & CBEIF_SELECTEDIMAGE)
1661 drawimage = item->iSelectedImage;
1662 drawstate = ILD_SELECTED;
1665 else {
1666 /* if we don't have an edit control, use
1667 * the requested state.
1669 if (dis->itemState & ODS_SELECTED) {
1670 if (item->mask & CBEIF_SELECTEDIMAGE)
1671 drawimage = item->iSelectedImage;
1672 drawstate = ILD_SELECTED;
1677 if (drawimage != -1) {
1678 TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
1679 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
1680 xbase, dis->rcItem.top, drawstate);
1683 /* setup pointer to text to be drawn */
1684 if ((item->mask & CBEIF_TEXT) && item->pszText)
1685 str = item->pszText;
1686 else
1687 str = (LPWSTR) L"";
1689 /* now draw the text */
1690 len = lstrlenW (str);
1691 GetTextExtentPointW (dis->hDC, str, len, &txtsize);
1692 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1693 COLOR_HIGHLIGHT : COLOR_WINDOW);
1694 SetBkColor (dis->hDC, nbkc);
1695 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1696 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1697 SetTextColor (dis->hDC, ntxc);
1698 x = xbase + xioff;
1699 y = dis->rcItem.top +
1700 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1701 rect.left = x;
1702 rect.right = x + txtsize.cx;
1703 rect.top = dis->rcItem.top + 1;
1704 rect.bottom = dis->rcItem.bottom - 1;
1705 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1706 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1707 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1708 &rect, str, len, 0);
1709 if (dis->itemState & ODS_FOCUS) {
1710 rect.top -= 1;
1711 rect.bottom += 1;
1712 rect.left -= 1;
1713 rect.right += 1;
1714 TRACE("drawing item %d focus after text, rect=(%d,%d)-(%d,%d)\n",
1715 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1716 DrawFocusRect (dis->hDC, &rect);
1718 break;
1719 default:
1720 FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
1721 hwnd, wParam, lParam, dis->itemAction);
1724 return 0;
1728 static LRESULT
1729 COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1731 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1733 if (infoPtr->hwndCombo)
1734 DestroyWindow (infoPtr->hwndCombo);
1736 if (infoPtr->edit) {
1737 COMCTL32_Free (infoPtr->edit);
1738 infoPtr->edit = 0;
1741 if (infoPtr->items) {
1742 CBE_ITEMDATA *this, *next;
1744 this = infoPtr->items;
1745 while (this) {
1746 next = (CBE_ITEMDATA *)this->next;
1747 if ((this->mask & CBEIF_TEXT) && this->pszText)
1748 COMCTL32_Free (this->pszText);
1749 COMCTL32_Free (this);
1750 this = next;
1754 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
1756 /* free comboex info data */
1757 COMCTL32_Free (infoPtr);
1758 SetWindowLongA (hwnd, 0, 0);
1759 return 0;
1763 static LRESULT
1764 COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1766 /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
1767 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
1768 HDC hdc;
1769 SIZE mysize;
1771 hdc = GetDC (0);
1772 GetTextExtentPointA (hdc, "W", 1, &mysize);
1773 ReleaseDC (0, hdc);
1774 mis->itemHeight = mysize.cy + CBE_EXTRA;
1776 TRACE("adjusted height hwnd=%08x, height=%d\n",
1777 hwnd, mis->itemHeight);
1779 return 0;
1783 static LRESULT
1784 COMBOEX_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1786 /* WARNING: The COMBOEX_INFO structure is not yet created */
1787 DWORD oldstyle, newstyle;
1789 oldstyle = (DWORD)GetWindowLongA (hwnd, GWL_STYLE);
1790 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1791 if (newstyle != oldstyle) {
1792 TRACE("req style %08lx, reseting style %08lx\n",
1793 oldstyle, newstyle);
1794 SetWindowLongA (hwnd, GWL_STYLE, newstyle);
1796 return 1;
1800 static LRESULT
1801 COMBOEX_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1803 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1804 INT i;
1806 if (lParam == NF_REQUERY) {
1807 i = SendMessageA(GetParent (hwnd),
1808 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
1809 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1810 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1812 i = NFR_ANSI;
1814 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1815 return (LRESULT)i;
1817 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
1821 static LRESULT
1822 COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1824 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1825 RECT rect;
1827 GetWindowRect (hwnd, &rect);
1828 TRACE("my rect (%d,%d)-(%d,%d)\n",
1829 rect.left, rect.top, rect.right, rect.bottom);
1831 MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
1832 rect.bottom - rect.top, TRUE);
1834 COMBOEX_AdjustEditPos (infoPtr);
1836 return 0;
1840 static LRESULT
1841 COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
1843 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1844 RECT cbx_wrect, cbx_crect, cb_wrect;
1845 UINT width, height;
1846 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1848 GetWindowRect (hwnd, &cbx_wrect);
1849 GetClientRect (hwnd, &cbx_crect);
1850 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1852 /* width is winpos value + border width of comboex */
1853 width = wp->cx
1854 + (cbx_wrect.right-cbx_wrect.left)
1855 - (cbx_crect.right-cbx_crect.left);
1857 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1858 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1859 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1860 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1861 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1862 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1863 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1864 width, cb_wrect.bottom-cb_wrect.top);
1866 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1867 width,
1868 cb_wrect.bottom-cb_wrect.top,
1869 SWP_NOACTIVATE);
1871 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1873 /* height is combo window height plus border width of comboex */
1874 height = (cb_wrect.bottom-cb_wrect.top)
1875 + (cbx_wrect.bottom-cbx_wrect.top)
1876 - (cbx_crect.bottom-cbx_crect.top);
1877 if (wp->cy < height) wp->cy = height;
1878 if (infoPtr->hwndEdit) {
1879 COMBOEX_AdjustEditPos (infoPtr);
1880 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1883 return 0;
1887 static LRESULT WINAPI
1888 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1890 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1891 NMCBEENDEDITW cbeend;
1892 WCHAR edit_text[260];
1893 COLORREF nbkc, obkc;
1894 HDC hDC;
1895 RECT rect;
1896 LRESULT lret;
1898 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1899 hwnd, uMsg, wParam, lParam, infoPtr);
1901 if (!infoPtr) return 0;
1903 switch (uMsg)
1906 case WM_CHAR:
1907 /* handle (ignore) the return character */
1908 if (wParam == VK_RETURN) return 0;
1909 /* all other characters pass into the real Edit */
1910 return CallWindowProcA (infoPtr->prevEditWndProc,
1911 hwnd, uMsg, wParam, lParam);
1913 case WM_ERASEBKGND:
1915 * The following was determined by traces of the native
1917 hDC = (HDC) wParam;
1918 nbkc = GetSysColor (COLOR_WINDOW);
1919 obkc = SetBkColor (hDC, nbkc);
1920 GetClientRect (hwnd, &rect);
1921 TRACE("erasing (%d,%d)-(%d,%d)\n",
1922 rect.left, rect.top, rect.right, rect.bottom);
1923 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1924 SetBkColor (hDC, obkc);
1925 return CallWindowProcA (infoPtr->prevEditWndProc,
1926 hwnd, uMsg, wParam, lParam);
1928 case WM_KEYDOWN: {
1929 INT oldItem, selected;
1930 CBE_ITEMDATA *item;
1932 switch ((INT)wParam)
1934 case VK_ESCAPE:
1935 /* native version seems to do following for COMBOEX */
1937 * GetWindowTextA(Edit,&?, 0x104) x
1938 * CB_GETCURSEL to Combo rets -1 x
1939 * WM_NOTIFY to COMBOEX parent (rebar) x
1940 * (CBEN_ENDEDIT{A|W}
1941 * fChanged = FALSE x
1942 * inewSelection = -1 x
1943 * txt="www.hoho" x
1944 * iWhy = 3 x
1945 * CB_GETCURSEL to Combo rets -1 x
1946 * InvalidateRect(Combo, 0) x
1947 * WM_SETTEXT to Edit x
1948 * EM_SETSEL to Edit (0,0) x
1949 * EM_SETSEL to Edit (0,-1) x
1950 * RedrawWindow(Combo, 0, 0, 5) x
1952 TRACE("special code for VK_ESCAPE\n");
1954 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1956 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1957 cbeend.fChanged = FALSE;
1958 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1959 CB_GETCURSEL, 0, 0);
1960 cbeend.iWhy = CBENF_ESCAPE;
1962 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1963 /* abort the change */
1964 TRACE("Notify requested abort of change\n");
1965 return 0;
1967 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1968 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1969 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1970 ERR("item %d not found. Problem!\n", oldItem);
1971 break;
1973 infoPtr->selected = oldItem;
1974 COMBOEX_SetEditText (infoPtr, item);
1975 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1976 RDW_INVALIDATE);
1977 break;
1979 case VK_RETURN:
1980 /* native version seems to do following for COMBOEX */
1982 * GetWindowTextA(Edit,&?, 0x104) x
1983 * CB_GETCURSEL to Combo rets -1 x
1984 * CB_GETCOUNT to Combo rets 0
1985 * if >0 loop
1986 * CB_GETITEMDATA to match
1987 * *** above 3 lines simulated by FindItem x
1988 * WM_NOTIFY to COMBOEX parent (rebar) x
1989 * (CBEN_ENDEDIT{A|W} x
1990 * fChanged = TRUE (-1) x
1991 * iNewSelection = -1 or selected x
1992 * txt= x
1993 * iWhy = 2 (CBENF_RETURN) x
1994 * CB_GETCURSEL to Combo rets -1 x
1995 * if -1 send CB_SETCURSEL to Combo -1 x
1996 * InvalidateRect(Combo, 0, 0) x
1997 * SetFocus(Edit) x
1998 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
2001 TRACE("special code for VK_RETURN\n");
2003 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2005 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2006 selected = SendMessageW (infoPtr->hwndCombo,
2007 CB_GETCURSEL, 0, 0);
2009 if (selected != -1) {
2010 item = COMBOEX_FindItem (infoPtr, selected);
2011 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
2012 selected, debugstr_w(item->pszText));
2013 TRACE("handling VK_RETURN, edittext=%s\n",
2014 debugstr_w(edit_text));
2015 if (lstrcmpiW (item->pszText, edit_text)) {
2016 /* strings not equal -- indicate edit has changed */
2017 selected = -1;
2021 cbeend.iNewSelection = selected;
2022 cbeend.fChanged = TRUE;
2023 cbeend.iWhy = CBENF_RETURN;
2024 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2025 /* abort the change, restore previous */
2026 TRACE("Notify requested abort of change\n");
2027 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
2028 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
2029 RDW_INVALIDATE);
2030 return 0;
2032 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
2033 if (oldItem != -1) {
2034 /* if something is selected, then deselect it */
2035 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
2036 (WPARAM)-1, 0);
2038 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2039 SetFocus(infoPtr->hwndEdit);
2040 break;
2042 default:
2043 return CallWindowProcA (infoPtr->prevEditWndProc,
2044 hwnd, uMsg, wParam, lParam);
2046 return 0;
2049 case WM_SETFOCUS:
2050 /* remember the focus to set state of icon */
2051 lret = CallWindowProcA (infoPtr->prevEditWndProc,
2052 hwnd, uMsg, wParam, lParam);
2053 infoPtr->flags |= WCBE_EDITFOCUSED;
2054 return lret;
2056 case WM_KILLFOCUS:
2058 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
2060 infoPtr->flags &= ~WCBE_EDITFOCUSED;
2061 if (infoPtr->flags & WCBE_ACTEDIT) {
2062 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2064 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2065 cbeend.fChanged = FALSE;
2066 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2067 CB_GETCURSEL, 0, 0);
2068 cbeend.iWhy = CBENF_KILLFOCUS;
2070 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
2072 /* fall through */
2074 default:
2075 return CallWindowProcA (infoPtr->prevEditWndProc,
2076 hwnd, uMsg, wParam, lParam);
2078 return 0;
2082 static LRESULT WINAPI
2083 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2085 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
2086 NMCBEENDEDITW cbeend;
2087 NMMOUSE nmmse;
2088 COLORREF nbkc, obkc;
2089 HDC hDC;
2090 HWND focusedhwnd;
2091 RECT rect;
2092 WCHAR edit_text[260];
2094 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
2095 hwnd, uMsg, wParam, lParam, infoPtr);
2097 if (!infoPtr) return 0;
2099 switch (uMsg)
2102 case CB_FINDSTRINGEXACT:
2103 return COMBOEX_FindStringExact (infoPtr, wParam, lParam);
2105 case WM_DRAWITEM:
2107 * The only way this message should come is from the
2108 * child Listbox issuing the message. Flag this so
2109 * that ComboEx knows this is listbox.
2111 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
2112 return CallWindowProcA (infoPtr->prevComboWndProc,
2113 hwnd, uMsg, wParam, lParam);
2115 case WM_ERASEBKGND:
2117 * The following was determined by traces of the native
2119 hDC = (HDC) wParam;
2120 nbkc = GetSysColor (COLOR_WINDOW);
2121 obkc = SetBkColor (hDC, nbkc);
2122 GetClientRect (hwnd, &rect);
2123 TRACE("erasing (%d,%d)-(%d,%d)\n",
2124 rect.left, rect.top, rect.right, rect.bottom);
2125 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
2126 SetBkColor (hDC, obkc);
2127 return CallWindowProcA (infoPtr->prevComboWndProc,
2128 hwnd, uMsg, wParam, lParam);
2130 case WM_SETCURSOR:
2132 * WM_NOTIFY to comboex parent (rebar)
2133 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
2134 * CallWindowProc (previous)
2136 nmmse.dwItemSpec = 0;
2137 nmmse.dwItemData = 0;
2138 nmmse.pt.x = 0;
2139 nmmse.pt.y = 0;
2140 nmmse.dwHitInfo = lParam;
2141 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
2142 return CallWindowProcA (infoPtr->prevComboWndProc,
2143 hwnd, uMsg, wParam, lParam);
2145 case WM_COMMAND:
2146 switch (HIWORD(wParam)) {
2148 case EN_UPDATE:
2149 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2150 * on the EN_UPDATE
2152 return 0;
2154 case EN_KILLFOCUS:
2156 * Native does:
2158 * GetFocus() retns AA
2159 * GetWindowTextA(Edit)
2160 * CB_GETCURSEL(Combo) (got -1)
2161 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2162 * CB_GETCURSEL(Combo) (got -1)
2163 * InvalidateRect(Combo, 0, 0)
2164 * WM_KILLFOCUS(Combo, AA)
2165 * return 0;
2167 focusedhwnd = GetFocus();
2168 if (infoPtr->flags & WCBE_ACTEDIT) {
2169 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2170 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2171 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2172 CB_GETCURSEL, 0, 0);
2173 cbeend.iWhy = CBENF_KILLFOCUS;
2175 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2176 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2177 /* abort the change */
2178 TRACE("Notify requested abort of change\n");
2179 return 0;
2182 /* possible CB_GETCURSEL */
2183 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2184 if (focusedhwnd)
2185 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2186 (WPARAM)focusedhwnd, 0);
2187 return 0;
2189 case EN_SETFOCUS: {
2191 * For EN_SETFOCUS this issues the same calls and messages
2192 * as the native seems to do.
2194 * for some cases however native does the following:
2195 * (noticed after SetFocus during LBUTTONDOWN on
2196 * on dropdown arrow)
2197 * WM_GETTEXTLENGTH (Edit);
2198 * WM_GETTEXT (Edit, len+1, str);
2199 * EM_SETSEL (Edit, 0, 0);
2200 * WM_GETTEXTLENGTH (Edit);
2201 * WM_GETTEXT (Edit, len+1, str);
2202 * EM_SETSEL (Edit, 0, len);
2203 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2205 NMHDR hdr;
2207 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2208 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2209 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2210 infoPtr->flags |= WCBE_ACTEDIT;
2211 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2212 return 0;
2215 case EN_CHANGE: {
2217 * For EN_CHANGE this issues the same calls and messages
2218 * as the native seems to do.
2220 WCHAR edit_text[260];
2221 WCHAR *lastwrk;
2222 INT selected, cnt;
2223 CBE_ITEMDATA *item;
2225 selected = SendMessageW (infoPtr->hwndCombo,
2226 CB_GETCURSEL, 0, 0);
2228 /* lstrlenA( lastworkingURL ) */
2230 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2231 if (selected == -1) {
2232 lastwrk = infoPtr->edit->pszText;
2233 cnt = lstrlenW (lastwrk);
2234 if (cnt >= 259) cnt = 259;
2236 else {
2237 item = COMBOEX_FindItem (infoPtr, selected);
2238 cnt = lstrlenW (item->pszText);
2239 lastwrk = item->pszText;
2240 if (cnt >= 259) cnt = 259;
2243 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2244 selected, debugstr_w(lastwrk));
2245 TRACE("handling EN_CHANGE, edittext=%s\n",
2246 debugstr_w(edit_text));
2248 /* lstrcmpiW is between lastworkingURL and GetWindowText */
2250 if (lstrcmpiW (lastwrk, edit_text)) {
2251 /* strings not equal -- indicate edit has changed */
2252 infoPtr->flags |= WCBE_EDITCHG;
2254 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2255 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2256 CBN_EDITCHANGE),
2257 infoPtr->hwndSelf);
2258 return 0;
2261 case LBN_SELCHANGE:
2263 * Therefore from traces there is no additional code here
2267 * Using native COMCTL32 gets the following:
2268 * 1 == SHDOCVW.DLL issues call/message
2269 * 2 == COMCTL32.DLL issues call/message
2270 * 3 == WINE issues call/message
2273 * for LBN_SELCHANGE:
2274 * 1 CB_GETCURSEL(ComboEx)
2275 * 1 CB_GETDROPPEDSTATE(ComboEx)
2276 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2277 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2278 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2279 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2280 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2281 * 3 ShowWindow(ComboLB, SW_HIDE)
2282 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2283 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2284 ** end of CBRollUp
2285 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2286 * ? LB_GETCURSEL <==|
2287 * ? LB_GETTEXTLEN |
2288 * ? LB_GETTEXT | Needs to be added to
2289 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2290 * ? LB_GETITEMDATA |
2291 * ? WM_DRAWITEM(ComboEx) <==|
2293 default:
2294 break;
2295 }/* fall through */
2296 default:
2297 return CallWindowProcA (infoPtr->prevComboWndProc,
2298 hwnd, uMsg, wParam, lParam);
2300 return 0;
2304 static LRESULT WINAPI
2305 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2307 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2309 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2311 if (!COMBOEX_GetInfoPtr (hwnd)) {
2312 if (uMsg == WM_CREATE)
2313 return COMBOEX_Create (hwnd, wParam, lParam);
2314 if (uMsg == WM_NCCREATE)
2315 COMBOEX_NCCreate (hwnd, wParam, lParam);
2316 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2319 switch (uMsg)
2321 case CBEM_DELETEITEM: /* maps to CB_DELETESTRING */
2322 return COMBOEX_DeleteItem (hwnd, wParam, lParam);
2324 case CBEM_GETCOMBOCONTROL:
2325 return COMBOEX_GetComboControl (hwnd, wParam, lParam);
2327 case CBEM_GETEDITCONTROL:
2328 return COMBOEX_GetEditControl (hwnd, wParam, lParam);
2330 case CBEM_GETEXTENDEDSTYLE:
2331 return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
2333 case CBEM_GETIMAGELIST:
2334 return COMBOEX_GetImageList (hwnd, wParam, lParam);
2336 case CBEM_GETITEMA:
2337 return COMBOEX_GetItemA (hwnd, wParam, lParam);
2339 case CBEM_GETITEMW:
2340 return COMBOEX_GetItemW (hwnd, wParam, lParam);
2342 case CBEM_GETUNICODEFORMAT:
2343 return COMBOEX_GetUnicodeFormat (hwnd, wParam, lParam);
2345 case CBEM_HASEDITCHANGED:
2346 return COMBOEX_HasEditChanged (hwnd, wParam, lParam);
2348 case CBEM_INSERTITEMA:
2349 return COMBOEX_InsertItemA (hwnd, wParam, lParam);
2351 case CBEM_INSERTITEMW:
2352 return COMBOEX_InsertItemW (hwnd, wParam, lParam);
2354 case CBEM_SETEXSTYLE: /* FIXME: obsoleted, should be the same as: */
2355 case CBEM_SETEXTENDEDSTYLE:
2356 return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
2358 case CBEM_SETIMAGELIST:
2359 return COMBOEX_SetImageList (hwnd, wParam, lParam);
2361 case CBEM_SETITEMA:
2362 return COMBOEX_SetItemA (hwnd, wParam, lParam);
2364 case CBEM_SETITEMW:
2365 return COMBOEX_SetItemW (hwnd, wParam, lParam);
2367 case CBEM_SETUNICODEFORMAT:
2368 return COMBOEX_SetUnicodeFormat (hwnd, wParam, lParam);
2371 /* Combo messages we are not sure if we need to process or just forward */
2372 case CB_GETDROPPEDCONTROLRECT:
2373 case CB_GETITEMHEIGHT:
2374 case CB_GETLBTEXT:
2375 case CB_GETLBTEXTLEN:
2376 case CB_GETEXTENDEDUI:
2377 case CB_LIMITTEXT:
2378 case CB_RESETCONTENT:
2379 case CB_SELECTSTRING:
2380 case WM_SETTEXT:
2381 case WM_GETTEXT:
2382 FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
2383 uMsg, wParam, lParam);
2384 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2386 /* Combo messages OK to just forward to the regular COMBO */
2387 case CB_GETCOUNT:
2388 case CB_GETCURSEL:
2389 case CB_GETDROPPEDSTATE:
2390 case CB_SETDROPPEDWIDTH:
2391 case CB_SETEXTENDEDUI:
2392 case CB_SHOWDROPDOWN:
2393 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2395 /* Combo messages we need to process specially */
2396 case CB_FINDSTRINGEXACT:
2397 return COMBOEX_FindStringExact (COMBOEX_GetInfoPtr (hwnd),
2398 wParam, lParam);
2400 case CB_GETITEMDATA:
2401 return COMBOEX_GetItemData (hwnd, wParam, lParam);
2403 case CB_SETCURSEL:
2404 return COMBOEX_SetCursel (hwnd, wParam, lParam);
2406 case CB_SETITEMDATA:
2407 return COMBOEX_SetItemData (hwnd, wParam, lParam);
2409 case CB_SETITEMHEIGHT:
2410 return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
2414 /* Window messages passed to parent */
2415 case WM_COMMAND:
2416 return COMBOEX_Command (hwnd, wParam, lParam);
2418 case WM_NOTIFY:
2419 if (infoPtr->NtfUnicode)
2420 return SendMessageW (GetParent (hwnd),
2421 uMsg, wParam, lParam);
2422 else
2423 return SendMessageA (GetParent (hwnd),
2424 uMsg, wParam, lParam);
2427 /* Window messages we need to process */
2428 case WM_DELETEITEM:
2429 return COMBOEX_WM_DeleteItem (hwnd, wParam, lParam);
2431 case WM_DRAWITEM:
2432 return COMBOEX_DrawItem (hwnd, wParam, lParam);
2434 case WM_DESTROY:
2435 return COMBOEX_Destroy (hwnd, wParam, lParam);
2437 case WM_MEASUREITEM:
2438 return COMBOEX_MeasureItem (hwnd, wParam, lParam);
2440 case WM_NOTIFYFORMAT:
2441 return COMBOEX_NotifyFormat (hwnd, wParam, lParam);
2443 case WM_SIZE:
2444 return COMBOEX_Size (hwnd, wParam, lParam);
2446 case WM_WINDOWPOSCHANGING:
2447 return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
2449 default:
2450 if (uMsg >= WM_USER)
2451 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2452 uMsg, wParam, lParam);
2453 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2455 return 0;
2459 VOID
2460 COMBOEX_Register (void)
2462 WNDCLASSA wndClass;
2464 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2465 wndClass.style = CS_GLOBALCLASS;
2466 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2467 wndClass.cbClsExtra = 0;
2468 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2469 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2470 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2471 wndClass.lpszClassName = WC_COMBOBOXEXA;
2473 RegisterClassA (&wndClass);
2475 ComboExInfo = GlobalAddAtomA("CC32SubclassInfo");
2479 VOID
2480 COMBOEX_Unregister (void)
2482 UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);