configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / comctl32 / comboex.c
blob4b5e079ac99a23ac44b174786e4efcd6efd901a9
1 /*
2 * ComboBoxEx control
4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 2000, 2001, 2002 Guy Albertelli <galberte@neo.lrun.com>
6 * Copyright 2002 Dimitrie O. Paun
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTE
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Sep. 9, 2002, by Dimitrie O. Paun.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
33 #include <stdarg.h>
34 #include <string.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38 #include "winuser.h"
39 #include "winnls.h"
40 #include "commctrl.h"
41 #include "comctl32.h"
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(comboex);
47 /* Item structure */
48 typedef struct _CBE_ITEMDATA
50 struct _CBE_ITEMDATA *next;
51 UINT mask;
52 LPWSTR pszText;
53 LPWSTR pszTemp;
54 int cchTextMax;
55 int iImage;
56 int iSelectedImage;
57 int iOverlay;
58 int iIndent;
59 LPARAM lParam;
60 } CBE_ITEMDATA;
62 /* ComboBoxEx structure */
63 typedef struct
65 HIMAGELIST himl;
66 HWND hwndSelf; /* my own hwnd */
67 HWND hwndNotify; /* my parent hwnd */
68 HWND hwndCombo;
69 HWND hwndEdit;
70 DWORD dwExtStyle;
71 INT selected; /* index of selected item */
72 DWORD flags; /* WINE internal flags */
73 HFONT defaultFont;
74 HFONT font;
75 INT nb_items; /* Number of items */
76 BOOL unicode; /* TRUE if this window is Unicode */
77 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
78 CBE_ITEMDATA *edit; /* item data for edit item */
79 CBE_ITEMDATA *items; /* Array of items */
80 } COMBOEX_INFO;
82 /* internal flags in the COMBOEX_INFO structure */
83 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
84 * CBEN_BEGINEDIT issued
85 * but CBEN_ENDEDIT{A|W}
86 * not yet issued. */
87 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
88 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
89 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
90 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
91 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
93 #define ID_CB_EDIT 1001
97 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
98 * the ComboEx version of the Combo Window Proc so that when the
99 * WM_DRAWITEM message is then passed to ComboEx, we know that this
100 * particular WM_DRAWITEM message is for listbox only items. Any messasges
101 * without this flag is then for the Edit control field.
103 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
104 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
106 #define ODS_COMBOEXLBOX 0x4000
110 /* Height in pixels of control over the amount of the selected font */
111 #define CBE_EXTRA 3
113 /* Indent amount per MS documentation */
114 #define CBE_INDENT 10
116 /* Offset in pixels from left side for start of image or text */
117 #define CBE_STARTOFFSET 6
119 /* Offset between image and text */
120 #define CBE_SEP 4
122 #define COMBO_SUBCLASSID 1
123 #define EDIT_SUBCLASSID 2
125 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongPtrW (hwnd, 0))
127 static LRESULT CALLBACK COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
128 UINT_PTR uId, DWORD_PTR ref_data);
129 static LRESULT CALLBACK COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
130 UINT_PTR uId, DWORD_PTR ref_data);
131 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
132 typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
134 static inline BOOL is_textW(LPCWSTR str)
136 return str && str != LPSTR_TEXTCALLBACKW;
139 static inline BOOL is_textA(LPCSTR str)
141 return str && str != LPSTR_TEXTCALLBACKA;
144 static inline LPCSTR debugstr_txt(LPCWSTR str)
146 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
147 return debugstr_w(str);
150 static void COMBOEX_DumpItem (CBE_ITEMDATA const *item)
152 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
153 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
154 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
155 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
156 if (item->mask & CBEIF_TEXT)
157 TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
161 static void COMBOEX_DumpInput (COMBOBOXEXITEMW const *input)
163 TRACE("input - mask=%08x, iItem=%ld, pszText=%p, cchTM=%d, iImage=%d\n",
164 input->mask, input->iItem, input->pszText, input->cchTextMax,
165 input->iImage);
166 if (input->mask & CBEIF_TEXT)
167 TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
168 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
169 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
173 static inline CBE_ITEMDATA *get_item_data(const COMBOEX_INFO *infoPtr, INT index)
175 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
176 index, 0);
179 static inline cmp_func_t get_cmp_func(COMBOEX_INFO const *infoPtr)
181 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
184 static INT COMBOEX_Notify (const COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
186 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
187 hdr->hwndFrom = infoPtr->hwndSelf;
188 hdr->code = code;
189 if (infoPtr->NtfUnicode)
190 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
191 else
192 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
196 static INT
197 COMBOEX_NotifyItem (const COMBOEX_INFO *infoPtr, UINT code, NMCOMBOBOXEXW *hdr)
199 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
200 if (infoPtr->NtfUnicode)
201 return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
202 else {
203 LPWSTR wstr = hdr->ceItem.pszText;
204 LPSTR astr = 0;
205 INT ret, len = 0;
207 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
208 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
209 if (len > 0) {
210 astr = Alloc ((len + 1)*sizeof(CHAR));
211 if (!astr) return 0;
212 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
213 hdr->ceItem.pszText = (LPWSTR)astr;
217 if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
218 else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
219 else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
221 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
223 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
224 hdr->ceItem.pszText = wstr;
226 Free(astr);
228 return ret;
233 static INT COMBOEX_NotifyEndEdit (const COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
235 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
236 if (infoPtr->NtfUnicode) {
237 lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
238 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
239 } else {
240 NMCBEENDEDITA neea;
242 neea.hdr = neew->hdr;
243 neea.fChanged = neew->fChanged;
244 neea.iNewSelection = neew->iNewSelection;
245 WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
246 neea.iWhy = neew->iWhy;
248 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
253 static void COMBOEX_NotifyDragBegin(const COMBOEX_INFO *infoPtr, LPCWSTR wstr)
255 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
256 if (infoPtr->NtfUnicode) {
257 NMCBEDRAGBEGINW ndbw;
259 ndbw.iItemid = -1;
260 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
261 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
262 } else {
263 NMCBEDRAGBEGINA ndba;
265 ndba.iItemid = -1;
266 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
268 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
273 static void COMBOEX_FreeText (CBE_ITEMDATA *item)
275 if (is_textW(item->pszText)) Free(item->pszText);
276 item->pszText = 0;
277 Free(item->pszTemp);
278 item->pszTemp = 0;
282 static INT COMBOEX_GetIndex(COMBOEX_INFO const *infoPtr, CBE_ITEMDATA const *item)
284 CBE_ITEMDATA const *moving;
285 INT index;
287 moving = infoPtr->items;
288 index = infoPtr->nb_items - 1;
290 while (moving && (moving != item)) {
291 moving = moving->next;
292 index--;
294 if (!moving || (index < 0)) {
295 ERR("COMBOBOXEX item structures broken. Please report!\n");
296 return -1;
298 return index;
302 static LPCWSTR COMBOEX_GetText(const COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
304 NMCOMBOBOXEXW nmce;
305 LPWSTR text, buf;
306 INT len;
308 if (item->pszText != LPSTR_TEXTCALLBACKW)
309 return item->pszText;
311 ZeroMemory(&nmce, sizeof(nmce));
312 nmce.ceItem.mask = CBEIF_TEXT;
313 nmce.ceItem.lParam = item->lParam;
314 nmce.ceItem.iItem = COMBOEX_GetIndex(infoPtr, item);
315 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
317 if (is_textW(nmce.ceItem.pszText)) {
318 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
319 buf = Alloc ((len + 1)*sizeof(WCHAR));
320 if (buf)
321 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
322 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
323 COMBOEX_FreeText(item);
324 item->pszText = buf;
325 } else {
326 Free(item->pszTemp);
327 item->pszTemp = buf;
329 text = buf;
330 } else
331 text = nmce.ceItem.pszText;
333 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
334 item->pszText = text;
335 return text;
339 static void COMBOEX_GetComboFontSize (const COMBOEX_INFO *infoPtr, SIZE *size)
341 static const WCHAR strA[] = { 'A', 0 };
342 HFONT nfont, ofont;
343 HDC mydc;
345 mydc = GetDC (0); /* why the entire screen???? */
346 nfont = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
347 ofont = SelectObject (mydc, nfont);
348 GetTextExtentPointW (mydc, strA, 1, size);
349 SelectObject (mydc, ofont);
350 ReleaseDC (0, mydc);
351 TRACE("selected font hwnd=%p, height=%d\n", nfont, size->cy);
355 static void COMBOEX_CopyItem (const CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
357 if (cit->mask & CBEIF_TEXT) {
359 * when given a text buffer actually use that buffer
361 if (cit->pszText) {
362 if (is_textW(item->pszText))
363 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
364 else
365 cit->pszText[0] = 0;
366 } else {
367 cit->pszText = item->pszText;
368 cit->cchTextMax = item->cchTextMax;
371 if (cit->mask & CBEIF_IMAGE)
372 cit->iImage = item->iImage;
373 if (cit->mask & CBEIF_SELECTEDIMAGE)
374 cit->iSelectedImage = item->iSelectedImage;
375 if (cit->mask & CBEIF_OVERLAY)
376 cit->iOverlay = item->iOverlay;
377 if (cit->mask & CBEIF_INDENT)
378 cit->iIndent = item->iIndent;
379 if (cit->mask & CBEIF_LPARAM)
380 cit->lParam = item->lParam;
384 static void COMBOEX_AdjustEditPos (const COMBOEX_INFO *infoPtr)
386 SIZE mysize;
387 INT x, y, w, h, xioff;
388 RECT rect;
390 if (!infoPtr->hwndEdit) return;
392 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
393 IMAGEINFO iinfo;
394 iinfo.rcImage.left = iinfo.rcImage.right = 0;
395 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
396 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
397 } else xioff = 0;
399 GetClientRect (infoPtr->hwndCombo, &rect);
400 InflateRect (&rect, -2, -2);
401 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
403 /* reposition the Edit control based on whether icon exists */
404 COMBOEX_GetComboFontSize (infoPtr, &mysize);
405 TRACE("Combo font x=%d, y=%d\n", mysize.cx, mysize.cy);
406 x = xioff + CBE_STARTOFFSET + 1;
407 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
408 h = mysize.cy + 1;
409 y = rect.bottom - h - 1;
411 TRACE("Combo client (%s), setting Edit to (%d,%d)-(%d,%d)\n",
412 wine_dbgstr_rect(&rect), x, y, x + w, y + h);
413 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
414 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
418 static void COMBOEX_ReSize (const COMBOEX_INFO *infoPtr)
420 SIZE mysize;
421 LONG cy;
422 IMAGEINFO iinfo;
424 COMBOEX_GetComboFontSize (infoPtr, &mysize);
425 cy = mysize.cy + CBE_EXTRA;
426 if (infoPtr->himl && ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo)) {
427 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
428 TRACE("upgraded height due to image: height=%d\n", cy);
430 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, -1, cy);
431 if (infoPtr->hwndCombo) {
432 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, 0, cy);
433 if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
434 RECT comboRect;
435 if (GetWindowRect(infoPtr->hwndCombo, &comboRect)) {
436 RECT ourRect;
437 if (GetWindowRect(infoPtr->hwndSelf, &ourRect)) {
438 if (comboRect.bottom > ourRect.bottom) {
439 POINT pt = { ourRect.left, ourRect.top };
440 if (ScreenToClient(infoPtr->hwndSelf, &pt))
441 MoveWindow( infoPtr->hwndSelf, pt.x, pt.y, ourRect.right - ourRect.left,
442 comboRect.bottom - comboRect.top, FALSE);
451 static void COMBOEX_SetEditText (const COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
453 if (!infoPtr->hwndEdit) return;
455 if (item->mask & CBEIF_TEXT) {
456 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
457 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
458 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
463 static CBE_ITEMDATA * COMBOEX_FindItem(const COMBOEX_INFO *infoPtr, INT_PTR index)
465 CBE_ITEMDATA *item;
466 INT i;
468 if ((index >= infoPtr->nb_items) || (index < -1))
469 return 0;
470 if (index == -1)
471 return infoPtr->edit;
472 item = infoPtr->items;
473 i = infoPtr->nb_items - 1;
475 /* find the item in the list */
476 while (item && (i > index)) {
477 item = item->next;
478 i--;
480 if (!item || (i != index)) {
481 ERR("COMBOBOXEX item structures broken. Please report!\n");
482 return 0;
484 return item;
487 /* *** CBEM_xxx message support *** */
489 static UINT COMBOEX_GetListboxText(const COMBOEX_INFO *infoPtr, INT_PTR n, LPWSTR buf)
491 CBE_ITEMDATA *item;
492 LPCWSTR str;
494 item = COMBOEX_FindItem(infoPtr, n);
495 if (!item)
496 return 0;
498 str = COMBOEX_GetText(infoPtr, item);
499 if (!str)
501 if (buf)
503 if (infoPtr->unicode)
504 buf[0] = 0;
505 else
506 *((LPSTR)buf) = 0;
508 return 0;
511 if (infoPtr->unicode)
513 if (buf)
514 lstrcpyW(buf, str);
515 return lstrlenW(str);
517 else
519 UINT r;
520 r = WideCharToMultiByte(CP_ACP, 0, str, -1, (LPSTR)buf, 0x40000000, NULL, NULL);
521 if (r) r--;
522 return r;
527 static INT COMBOEX_DeleteItem (const COMBOEX_INFO *infoPtr, INT_PTR index)
529 TRACE("(index=%ld)\n", index);
531 /* if item number requested does not exist then return failure */
532 if ((index >= infoPtr->nb_items) || (index < 0)) return CB_ERR;
533 if (!COMBOEX_FindItem(infoPtr, index)) return CB_ERR;
535 /* doing this will result in WM_DELETEITEM being issued */
536 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, index, 0);
538 return infoPtr->nb_items;
542 static BOOL COMBOEX_GetItemW (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
544 INT_PTR index = cit->iItem;
545 CBE_ITEMDATA *item;
547 TRACE("\n");
549 /* if item number requested does not exist then return failure */
550 if ((index >= infoPtr->nb_items) || (index < -1)) return FALSE;
552 /* if the item is the edit control and there is no edit control, skip */
553 if ((index == -1) && !infoPtr->hwndEdit) return FALSE;
555 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
557 COMBOEX_CopyItem (item, cit);
559 return TRUE;
563 static BOOL COMBOEX_GetItemA (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
565 COMBOBOXEXITEMW tmpcit;
567 TRACE("\n");
569 tmpcit.mask = cit->mask;
570 tmpcit.iItem = cit->iItem;
571 tmpcit.pszText = 0;
572 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
574 if (cit->mask & CBEIF_TEXT)
576 if (is_textW(tmpcit.pszText) && cit->pszText)
577 WideCharToMultiByte(CP_ACP, 0, tmpcit.pszText, -1,
578 cit->pszText, cit->cchTextMax, NULL, NULL);
579 else if (cit->pszText) cit->pszText[0] = 0;
580 else cit->pszText = (LPSTR)tmpcit.pszText;
583 if (cit->mask & CBEIF_IMAGE)
584 cit->iImage = tmpcit.iImage;
585 if (cit->mask & CBEIF_SELECTEDIMAGE)
586 cit->iSelectedImage = tmpcit.iSelectedImage;
587 if (cit->mask & CBEIF_OVERLAY)
588 cit->iOverlay = tmpcit.iOverlay;
589 if (cit->mask & CBEIF_INDENT)
590 cit->iIndent = tmpcit.iIndent;
591 if (cit->mask & CBEIF_LPARAM)
592 cit->lParam = tmpcit.lParam;
594 return TRUE;
598 static inline BOOL COMBOEX_HasEditChanged (COMBOEX_INFO const *infoPtr)
600 return infoPtr->hwndEdit && (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
604 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW const *cit)
606 INT_PTR index;
607 CBE_ITEMDATA *item;
608 NMCOMBOBOXEXW nmcit;
610 TRACE("\n");
612 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
614 /* get real index of item to insert */
615 index = cit->iItem;
616 if (index == -1) index = infoPtr->nb_items;
617 if (index > infoPtr->nb_items) return -1;
619 /* get zero-filled space and chain it in */
620 if(!(item = Alloc (sizeof(*item)))) return -1;
622 /* locate position to insert new item in */
623 if (index == infoPtr->nb_items) {
624 /* fast path for iItem = -1 */
625 item->next = infoPtr->items;
626 infoPtr->items = item;
628 else {
629 INT i = infoPtr->nb_items-1;
630 CBE_ITEMDATA *moving = infoPtr->items;
632 while ((i > index) && moving) {
633 moving = moving->next;
634 i--;
636 if (!moving) {
637 ERR("COMBOBOXEX item structures broken. Please report!\n");
638 Free(item);
639 return -1;
641 item->next = moving->next;
642 moving->next = item;
645 /* fill in our hidden item structure */
646 item->mask = cit->mask;
647 if (item->mask & CBEIF_TEXT) {
648 INT len = 0;
650 if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
651 if (len > 0) {
652 item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
653 if (!item->pszText) {
654 Free(item);
655 return -1;
657 strcpyW (item->pszText, cit->pszText);
659 else if (cit->pszText == LPSTR_TEXTCALLBACKW)
660 item->pszText = LPSTR_TEXTCALLBACKW;
661 item->cchTextMax = cit->cchTextMax;
663 if (item->mask & CBEIF_IMAGE)
664 item->iImage = cit->iImage;
665 if (item->mask & CBEIF_SELECTEDIMAGE)
666 item->iSelectedImage = cit->iSelectedImage;
667 if (item->mask & CBEIF_OVERLAY)
668 item->iOverlay = cit->iOverlay;
669 if (item->mask & CBEIF_INDENT)
670 item->iIndent = cit->iIndent;
671 if (item->mask & CBEIF_LPARAM)
672 item->lParam = cit->lParam;
673 infoPtr->nb_items++;
675 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
677 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING, cit->iItem, (LPARAM)item);
679 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
680 COMBOEX_CopyItem (item, &nmcit.ceItem);
681 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
683 return index;
688 static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA const *cit)
690 COMBOBOXEXITEMW citW;
691 LPWSTR wstr = NULL;
692 INT ret;
694 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
695 if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
696 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
697 wstr = Alloc ((len + 1)*sizeof(WCHAR));
698 if (!wstr) return -1;
699 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
700 citW.pszText = wstr;
702 ret = COMBOEX_InsertItemW(infoPtr, &citW);
704 Free(wstr);
706 return ret;
710 static DWORD
711 COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
713 DWORD dwTemp;
715 TRACE("(mask=x%08x, style=0x%08x)\n", mask, style);
717 dwTemp = infoPtr->dwExtStyle;
719 if (mask)
720 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
721 else
722 infoPtr->dwExtStyle = style;
724 /* see if we need to change the word break proc on the edit */
725 if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC)
726 SetPathWordBreakProc(infoPtr->hwndEdit,
727 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ? TRUE : FALSE);
729 /* test if the control's appearance has changed */
730 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
731 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
732 /* if state of EX_NOEDITIMAGE changes, invalidate all */
733 TRACE("EX_NOEDITIMAGE state changed to %d\n",
734 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
735 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
736 COMBOEX_AdjustEditPos (infoPtr);
737 if (infoPtr->hwndEdit)
738 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
741 return dwTemp;
745 static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
747 HIMAGELIST himlTemp = infoPtr->himl;
749 TRACE("\n");
751 infoPtr->himl = himl;
753 COMBOEX_ReSize (infoPtr);
754 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
756 /* reposition the Edit control based on whether icon exists */
757 COMBOEX_AdjustEditPos (infoPtr);
758 return himlTemp;
761 static BOOL COMBOEX_SetItemW (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
763 INT_PTR index = cit->iItem;
764 CBE_ITEMDATA *item;
766 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
768 /* if item number requested does not exist then return failure */
769 if ((index >= infoPtr->nb_items) || (index < -1)) return FALSE;
771 /* if the item is the edit control and there is no edit control, skip */
772 if ((index == -1) && !infoPtr->hwndEdit) return FALSE;
774 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
776 /* add/change stuff to the internal item structure */
777 item->mask |= cit->mask;
778 if (cit->mask & CBEIF_TEXT) {
779 INT len = 0;
781 COMBOEX_FreeText(item);
782 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
783 if (len > 0) {
784 item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
785 if (!item->pszText) return FALSE;
786 strcpyW(item->pszText, cit->pszText);
787 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
788 item->pszText = LPSTR_TEXTCALLBACKW;
789 item->cchTextMax = cit->cchTextMax;
791 if (cit->mask & CBEIF_IMAGE)
792 item->iImage = cit->iImage;
793 if (cit->mask & CBEIF_SELECTEDIMAGE)
794 item->iSelectedImage = cit->iSelectedImage;
795 if (cit->mask & CBEIF_OVERLAY)
796 item->iOverlay = cit->iOverlay;
797 if (cit->mask & CBEIF_INDENT)
798 item->iIndent = cit->iIndent;
799 if (cit->mask & CBEIF_LPARAM)
800 item->lParam = cit->lParam;
802 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
804 /* if original request was to update edit control, do some fast foot work */
805 if (cit->iItem == -1 && cit->mask & CBEIF_TEXT) {
806 COMBOEX_SetEditText (infoPtr, item);
807 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
809 return TRUE;
812 static BOOL COMBOEX_SetItemA (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA const *cit)
814 COMBOBOXEXITEMW citW;
815 LPWSTR wstr = NULL;
816 BOOL ret;
818 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
819 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
820 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
821 wstr = Alloc ((len + 1)*sizeof(WCHAR));
822 if (!wstr) return FALSE;
823 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
824 citW.pszText = wstr;
826 ret = COMBOEX_SetItemW(infoPtr, &citW);
828 Free(wstr);
830 return ret;
834 static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
836 BOOL bTemp = infoPtr->unicode;
838 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
840 infoPtr->unicode = value;
842 return bTemp;
846 /* *** CB_xxx message support *** */
848 static INT
849 COMBOEX_FindStringExact (const COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
851 INT i;
852 cmp_func_t cmptext = get_cmp_func(infoPtr);
853 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
855 /* now search from after starting loc and wrapping back to start */
856 for(i=start+1; i<count; i++) {
857 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
858 if ((LRESULT)item == CB_ERR) continue;
859 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
861 for(i=0; i<=start; i++) {
862 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
863 if ((LRESULT)item == CB_ERR) continue;
864 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
866 return CB_ERR;
870 static DWORD_PTR COMBOEX_GetItemData (const COMBOEX_INFO *infoPtr, INT_PTR index)
872 CBE_ITEMDATA const *item1;
873 CBE_ITEMDATA const *item2;
874 DWORD_PTR ret = 0;
876 item1 = get_item_data(infoPtr, index);
877 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
878 item2 = COMBOEX_FindItem (infoPtr, index);
879 if (item2 != item1) {
880 ERR("data structures damaged!\n");
881 return CB_ERR;
883 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
884 TRACE("returning 0x%08lx\n", ret);
885 } else {
886 ret = (DWORD_PTR)item1;
887 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
889 return ret;
893 static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT_PTR index)
895 CBE_ITEMDATA *item;
896 INT sel;
898 if (!(item = COMBOEX_FindItem(infoPtr, index)))
899 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
901 TRACE("selecting item %ld text=%s\n", index, debugstr_txt(item->pszText));
902 infoPtr->selected = index;
904 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
905 COMBOEX_SetEditText (infoPtr, item);
906 return sel;
910 static DWORD_PTR COMBOEX_SetItemData (const COMBOEX_INFO *infoPtr, INT_PTR index, DWORD_PTR data)
912 CBE_ITEMDATA *item1;
913 CBE_ITEMDATA const *item2;
915 item1 = get_item_data(infoPtr, index);
916 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
917 item2 = COMBOEX_FindItem (infoPtr, index);
918 if (item2 != item1) {
919 ERR("data structures damaged!\n");
920 return CB_ERR;
922 item1->mask |= CBEIF_LPARAM;
923 item1->lParam = data;
924 TRACE("setting lparam to 0x%08lx\n", data);
925 return 0;
927 TRACE("non-valid result from combo %p\n", item1);
928 return (DWORD_PTR)item1;
932 static INT COMBOEX_SetItemHeight (COMBOEX_INFO const *infoPtr, INT index, UINT height)
934 RECT cb_wrect, cbx_wrect, cbx_crect;
936 /* First, lets forward the message to the normal combo control
937 just like Windows. */
938 if (infoPtr->hwndCombo)
939 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
940 index, height) == CB_ERR) return CB_ERR;
942 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
943 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
944 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
945 /* the height of comboex as height of the combo + comboex border */
946 height = cb_wrect.bottom-cb_wrect.top
947 + cbx_wrect.bottom-cbx_wrect.top
948 - (cbx_crect.bottom-cbx_crect.top);
949 TRACE("EX window=(%s), client=(%s)\n",
950 wine_dbgstr_rect(&cbx_wrect), wine_dbgstr_rect(&cbx_crect));
951 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
952 wine_dbgstr_rect(&cbx_wrect), cbx_wrect.right-cbx_wrect.left, height);
953 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
954 cbx_wrect.right-cbx_wrect.left, height,
955 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
957 return 0;
961 /* *** WM_xxx message support *** */
964 static LRESULT COMBOEX_Create (HWND hwnd, CREATESTRUCTA const *cs)
966 static const WCHAR NIL[] = { 0 };
967 COMBOEX_INFO *infoPtr;
968 LOGFONTW mylogfont;
969 RECT win_rect;
970 INT i;
972 /* allocate memory for info structure */
973 infoPtr = Alloc (sizeof(COMBOEX_INFO));
974 if (!infoPtr) return -1;
976 /* initialize info structure */
977 /* note that infoPtr is allocated zero-filled */
979 infoPtr->hwndSelf = hwnd;
980 infoPtr->selected = -1;
982 infoPtr->unicode = IsWindowUnicode (hwnd);
983 infoPtr->hwndNotify = cs->hwndParent;
985 i = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
986 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
987 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
988 i = NFR_ANSI;
990 infoPtr->NtfUnicode = (i == NFR_UNICODE);
992 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
994 if (TRACE_ON(comboex)) {
995 RECT client, rect;
996 GetWindowRect(hwnd, &rect);
997 GetClientRect(hwnd, &client);
998 TRACE("EX window=(%s), client=(%s)\n",
999 wine_dbgstr_rect(&rect), wine_dbgstr_rect(&client));
1002 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1003 /* specified. It then creates it's own version of the EDIT control */
1004 /* and makes the ComboBox the parent. This is because a normal */
1005 /* DROPDOWNLIST does not have an EDIT control, but we need one. */
1006 /* We also need to place the edit control at the proper location */
1007 /* (allow space for the icons). */
1009 infoPtr->hwndCombo = CreateWindowW (WC_COMBOBOXW, NIL,
1010 /* following line added to match native */
1011 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1012 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1013 /* was base and is necessary */
1014 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
1015 GetWindowLongW (hwnd, GWL_STYLE),
1016 cs->y, cs->x, cs->cx, cs->cy, hwnd,
1017 (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
1018 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
1021 * native does the following at this point according to trace:
1022 * GetWindowThreadProcessId(hwndCombo,0)
1023 * GetCurrentThreadId()
1024 * GetWindowThreadProcessId(hwndCombo, &???)
1025 * GetCurrentProcessId()
1028 SetWindowSubclass(infoPtr->hwndCombo, COMBOEX_ComboWndProc, COMBO_SUBCLASSID,
1029 (DWORD_PTR)hwnd);
1030 infoPtr->font = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1033 * Now create our own EDIT control so we can position it.
1034 * It is created only for CBS_DROPDOWN style
1036 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1037 infoPtr->hwndEdit = CreateWindowExW (0, WC_EDITW, NIL,
1038 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1039 0, 0, 0, 0, /* will set later */
1040 infoPtr->hwndCombo,
1041 (HMENU) GetWindowLongPtrW (hwnd, GWLP_ID),
1042 (HINSTANCE)GetWindowLongPtrW (hwnd, GWLP_HINSTANCE), NULL);
1044 /* native does the following at this point according to trace:
1045 * GetWindowThreadProcessId(hwndEdit,0)
1046 * GetCurrentThreadId()
1047 * GetWindowThreadProcessId(hwndEdit, &???)
1048 * GetCurrentProcessId()
1050 SetWindowSubclass(infoPtr->hwndEdit, COMBOEX_EditWndProc, EDIT_SUBCLASSID,
1051 (DWORD_PTR)hwnd);
1053 infoPtr->font = (HFONT)SendMessageW(infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1057 * Locate the default font if necessary and then set it in
1058 * all associated controls
1060 if (!infoPtr->font) {
1061 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1062 &mylogfont, 0);
1063 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
1065 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1066 if (infoPtr->hwndEdit) {
1067 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1068 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, EC_USEFONTINFO, 0);
1071 COMBOEX_ReSize (infoPtr);
1073 /* Above is fairly certain, below is much less certain. */
1075 GetWindowRect(hwnd, &win_rect);
1077 if (TRACE_ON(comboex)) {
1078 RECT client, rect;
1079 GetClientRect(hwnd, &client);
1080 GetWindowRect(infoPtr->hwndCombo, &rect);
1081 TRACE("EX window=(%s) client=(%s) CB wnd=(%s)\n",
1082 wine_dbgstr_rect(&win_rect), wine_dbgstr_rect(&client),
1083 wine_dbgstr_rect(&rect));
1085 SetWindowPos(infoPtr->hwndCombo, HWND_TOP, 0, 0,
1086 win_rect.right - win_rect.left, win_rect.bottom - win_rect.top,
1087 SWP_NOACTIVATE | SWP_NOREDRAW);
1089 GetWindowRect(infoPtr->hwndCombo, &win_rect);
1090 TRACE("CB window=(%s)\n", wine_dbgstr_rect(&win_rect));
1091 SetWindowPos(hwnd, HWND_TOP, 0, 0,
1092 win_rect.right - win_rect.left, win_rect.bottom - win_rect.top,
1093 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1095 COMBOEX_AdjustEditPos (infoPtr);
1098 * Create an item structure to represent the data in the
1099 * EDIT control. It is allocated zero-filled.
1101 infoPtr->edit = Alloc (sizeof (CBE_ITEMDATA));
1102 if (!infoPtr->edit) {
1103 COMBOEX_Destroy(infoPtr);
1104 return -1;
1107 return 0;
1111 static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam)
1113 LRESULT lret;
1114 INT command = HIWORD(wParam);
1115 CBE_ITEMDATA *item = 0;
1116 WCHAR wintext[520];
1117 INT cursel, n;
1118 INT_PTR oldItem;
1119 NMCBEENDEDITW cbeend;
1120 DWORD oldflags;
1121 HWND parent = infoPtr->hwndNotify;
1123 TRACE("for command %d\n", command);
1125 switch (command)
1127 case CBN_DROPDOWN:
1128 SetFocus (infoPtr->hwndCombo);
1129 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1130 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1132 case CBN_CLOSEUP:
1133 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1135 * from native trace of first dropdown after typing in URL in IE4
1136 * CB_GETCURSEL(Combo)
1137 * GetWindowText(Edit)
1138 * CB_GETCURSEL(Combo)
1139 * CB_GETCOUNT(Combo)
1140 * CB_GETITEMDATA(Combo, n)
1141 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1142 * CB_GETCURSEL(Combo)
1143 * CB_SETCURSEL(COMBOEX, n)
1144 * SetFocus(Combo)
1145 * the rest is supposition
1147 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1148 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1149 if (infoPtr->hwndEdit) InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
1150 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1151 if (cursel == -1) {
1152 cmp_func_t cmptext = get_cmp_func(infoPtr);
1153 /* find match from edit against those in Combobox */
1154 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1155 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1156 for (cursel = 0; cursel < n; cursel++){
1157 item = get_item_data(infoPtr, cursel);
1158 if ((INT_PTR)item == CB_ERR) break;
1159 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
1161 if ((cursel == n) || ((INT_PTR)item == CB_ERR)) {
1162 TRACE("failed to find match??? item=%p cursel=%d\n",
1163 item, cursel);
1164 if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1165 return 0;
1168 else {
1169 item = get_item_data(infoPtr, cursel);
1170 if ((INT_PTR)item == CB_ERR) {
1171 TRACE("failed to find match??? item=%p cursel=%d\n",
1172 item, cursel);
1173 if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1174 return 0;
1178 /* Save flags for testing and reset them */
1179 oldflags = infoPtr->flags;
1180 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1182 if (oldflags & WCBE_ACTEDIT) {
1183 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1184 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1185 CB_GETCURSEL, 0, 0);
1186 cbeend.iWhy = CBENF_DROPDOWN;
1188 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
1191 /* if selection has changed the set the new current selection */
1192 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1193 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1194 infoPtr->selected = cursel;
1195 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
1196 SetFocus(infoPtr->hwndCombo);
1198 return 0;
1200 case CBN_SELCHANGE:
1202 * CB_GETCURSEL(Combo)
1203 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1204 * lstrlenA
1205 * WM_SETTEXT(Edit)
1206 * WM_GETTEXTLENGTH(Edit)
1207 * WM_GETTEXT(Edit)
1208 * EM_SETSEL(Edit, 0,0)
1209 * WM_GETTEXTLENGTH(Edit)
1210 * WM_GETTEXT(Edit)
1211 * EM_SETSEL(Edit, 0,len)
1212 * return WM_COMMAND to parent
1214 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1215 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1216 ERR("item %ld not found. Problem!\n", oldItem);
1217 break;
1219 infoPtr->selected = oldItem;
1220 COMBOEX_SetEditText (infoPtr, item);
1221 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1223 case CBN_SELENDOK:
1224 case CBN_SELENDCANCEL:
1226 * We have to change the handle since we are the control
1227 * issuing the message. IE4 depends on this.
1229 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1231 case CBN_KILLFOCUS:
1233 * from native trace:
1235 * pass to parent
1236 * WM_GETTEXT(Edit, 104)
1237 * CB_GETCURSEL(Combo) rets -1
1238 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1239 * CB_GETCURSEL(Combo)
1240 * InvalidateRect(Combo, 0, 0)
1241 * return 0
1243 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1244 if (infoPtr->flags & WCBE_ACTEDIT) {
1245 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1246 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1247 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1248 CB_GETCURSEL, 0, 0);
1249 cbeend.iWhy = CBENF_KILLFOCUS;
1251 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1252 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
1254 /* possible CB_GETCURSEL */
1255 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1256 return 0;
1258 case CBN_SETFOCUS:
1259 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1261 default:
1263 * We have to change the handle since we are the control
1264 * issuing the message. IE4 depends on this.
1265 * We also need to set the focus back to the Edit control
1266 * after passing the command to the parent of the ComboEx.
1268 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
1269 if (infoPtr->hwndEdit) SetFocus(infoPtr->hwndEdit);
1270 return lret;
1272 return 0;
1276 static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT const *dis)
1278 CBE_ITEMDATA *item, *olditem;
1279 NMCOMBOBOXEXW nmcit;
1280 UINT i;
1282 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1283 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1285 if (dis->itemID >= infoPtr->nb_items) return FALSE;
1287 olditem = infoPtr->items;
1288 i = infoPtr->nb_items - 1;
1290 if (i == dis->itemID) {
1291 infoPtr->items = infoPtr->items->next;
1293 else {
1294 item = olditem;
1295 i--;
1297 /* find the prior item in the list */
1298 while (item->next && (i > dis->itemID)) {
1299 item = item->next;
1300 i--;
1302 if (!item->next || (i != dis->itemID)) {
1303 ERR("COMBOBOXEX item structures broken. Please report!\n");
1304 return FALSE;
1306 olditem = item->next;
1307 item->next = item->next->next;
1309 infoPtr->nb_items--;
1311 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
1312 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
1313 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1315 COMBOEX_FreeText(olditem);
1316 Free(olditem);
1318 return TRUE;
1322 static LRESULT COMBOEX_DrawItem (const COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT const *dis)
1324 static const WCHAR nil[] = { 0 };
1325 CBE_ITEMDATA *item = 0;
1326 SIZE txtsize;
1327 RECT rect;
1328 LPCWSTR str = nil;
1329 UINT xbase, x, y;
1330 INT len;
1331 COLORREF nbkc, ntxc, bkc, txc;
1332 int drawimage, drawstate, xioff;
1334 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1336 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1337 dis->CtlType, dis->CtlID);
1338 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1339 dis->itemID, dis->itemAction, dis->itemState);
1340 TRACE("hWnd=%p hDC=%p (%s) itemData=0x%08lx\n",
1341 dis->hwndItem, dis->hDC, wine_dbgstr_rect(&dis->rcItem), dis->itemData);
1343 /* MSDN says: */
1344 /* "itemID - Specifies the menu item identifier for a menu */
1345 /* item or the index of the item in a list box or combo box. */
1346 /* For an empty list box or combo box, this member can be -1. */
1347 /* This allows the application to draw only the focus */
1348 /* rectangle at the coordinates specified by the rcItem */
1349 /* member even though there are no items in the control. */
1350 /* This indicates to the user whether the list box or combo */
1351 /* box has the focus. How the bits are set in the itemAction */
1352 /* member determines whether the rectangle is to be drawn as */
1353 /* though the list box or combo box has the focus. */
1354 if (dis->itemID == 0xffffffff) {
1355 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1356 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1358 TRACE("drawing item -1 special focus, rect=(%s)\n",
1359 wine_dbgstr_rect(&dis->rcItem));
1361 else if ((dis->CtlType == ODT_COMBOBOX) &&
1362 (dis->itemAction == ODA_DRAWENTIRE)) {
1363 /* draw of edit control data */
1365 if (TRACE_ON(comboex)) {
1366 RECT exrc, cbrc, edrc;
1367 GetWindowRect (infoPtr->hwndSelf, &exrc);
1368 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1369 edrc.left = edrc.top = edrc.right = edrc.bottom = -1;
1370 if (infoPtr->hwndEdit) GetWindowRect (infoPtr->hwndEdit, &edrc);
1371 TRACE("window rects ex=(%s), cb=(%s), ed=(%s)\n",
1372 wine_dbgstr_rect(&exrc), wine_dbgstr_rect(&cbrc),
1373 wine_dbgstr_rect(&edrc));
1376 else {
1377 ERR("NOT drawing item -1 special focus, rect=(%s), action=%08x, state=%08x\n",
1378 wine_dbgstr_rect(&dis->rcItem),
1379 dis->itemAction, dis->itemState);
1380 return 0;
1384 /* If draw item is -1 (edit control) setup the item pointer */
1385 if (dis->itemID == 0xffffffff) {
1386 item = infoPtr->edit;
1388 if (infoPtr->hwndEdit) {
1389 INT len;
1391 /* free previous text of edit item */
1392 COMBOEX_FreeText(item);
1393 item->mask &= ~CBEIF_TEXT;
1394 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
1395 item->mask |= CBEIF_TEXT;
1396 item->pszText = Alloc ((len + 1)*sizeof(WCHAR));
1397 if (item->pszText)
1398 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
1400 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1401 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
1407 /* if the item pointer is not set, then get the data and locate it */
1408 if (!item) {
1409 item = get_item_data(infoPtr, dis->itemID);
1410 if (item == (CBE_ITEMDATA *)CB_ERR) {
1411 ERR("invalid item for id %d\n", dis->itemID);
1412 return 0;
1416 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
1418 xbase = CBE_STARTOFFSET;
1419 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1420 INT indent = item->iIndent;
1421 if (indent == I_INDENTCALLBACK) {
1422 NMCOMBOBOXEXW nmce;
1423 ZeroMemory(&nmce, sizeof(nmce));
1424 nmce.ceItem.mask = CBEIF_INDENT;
1425 nmce.ceItem.lParam = item->lParam;
1426 nmce.ceItem.iItem = dis->itemID;
1427 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1428 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1429 item->iIndent = nmce.ceItem.iIndent;
1430 indent = nmce.ceItem.iIndent;
1432 xbase += (indent * CBE_INDENT);
1435 drawimage = -2;
1436 drawstate = ILD_NORMAL;
1437 if (item->mask & CBEIF_IMAGE)
1438 drawimage = item->iImage;
1439 if (dis->itemState & ODS_COMBOEXLBOX) {
1440 /* drawing listbox entry */
1441 if (dis->itemState & ODS_SELECTED) {
1442 if (item->mask & CBEIF_SELECTEDIMAGE)
1443 drawimage = item->iSelectedImage;
1444 drawstate = ILD_SELECTED;
1446 } else {
1447 /* drawing combo/edit entry */
1448 if (IsWindowVisible(infoPtr->hwndEdit)) {
1449 /* if we have an edit control, the slave the
1450 * selection state to the Edit focus state
1452 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1453 if (item->mask & CBEIF_SELECTEDIMAGE)
1454 drawimage = item->iSelectedImage;
1455 drawstate = ILD_SELECTED;
1457 } else {
1458 /* if we don't have an edit control, use
1459 * the requested state.
1461 if (dis->itemState & ODS_SELECTED) {
1462 if (item->mask & CBEIF_SELECTEDIMAGE)
1463 drawimage = item->iSelectedImage;
1464 drawstate = ILD_SELECTED;
1469 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1470 IMAGEINFO iinfo;
1471 iinfo.rcImage.left = iinfo.rcImage.right = 0;
1472 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1473 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1474 } else xioff = 0;
1476 /* setup pointer to text to be drawn */
1477 str = COMBOEX_GetText(infoPtr, item);
1478 if (!str) str = nil;
1480 len = strlenW (str);
1481 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
1483 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
1484 int overlay = item->iOverlay;
1486 if (drawimage == I_IMAGECALLBACK) {
1487 NMCOMBOBOXEXW nmce;
1488 ZeroMemory(&nmce, sizeof(nmce));
1489 nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
1490 nmce.ceItem.lParam = item->lParam;
1491 nmce.ceItem.iItem = dis->itemID;
1492 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1493 if (drawstate == ILD_NORMAL) {
1494 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1495 drawimage = nmce.ceItem.iImage;
1496 } else if (drawstate == ILD_SELECTED) {
1497 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1498 drawimage = nmce.ceItem.iSelectedImage;
1499 } else ERR("Bad draw state = %d\n", drawstate);
1502 if (overlay == I_IMAGECALLBACK) {
1503 NMCOMBOBOXEXW nmce;
1504 ZeroMemory(&nmce, sizeof(nmce));
1505 nmce.ceItem.mask = CBEIF_OVERLAY;
1506 nmce.ceItem.lParam = item->lParam;
1507 nmce.ceItem.iItem = dis->itemID;
1508 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1509 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1510 item->iOverlay = nmce.ceItem.iOverlay;
1511 overlay = nmce.ceItem.iOverlay;
1514 if (drawimage >= 0 &&
1515 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1516 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
1517 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
1518 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
1521 /* now draw the text */
1522 if (!IsWindowVisible (infoPtr->hwndEdit)) {
1523 nbkc = (dis->itemState & ODS_SELECTED) ?
1524 comctl32_color.clrHighlight : comctl32_color.clrWindow;
1525 bkc = SetBkColor (dis->hDC, nbkc);
1526 ntxc = (dis->itemState & ODS_SELECTED) ?
1527 comctl32_color.clrHighlightText : comctl32_color.clrWindowText;
1528 txc = SetTextColor (dis->hDC, ntxc);
1529 x = xbase + xioff;
1530 y = dis->rcItem.top +
1531 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1532 rect.left = x;
1533 rect.right = x + txtsize.cx;
1534 rect.top = dis->rcItem.top + 1;
1535 rect.bottom = dis->rcItem.bottom - 1;
1536 TRACE("drawing item %d text, rect=(%s)\n",
1537 dis->itemID, wine_dbgstr_rect(&rect));
1538 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1539 &rect, str, len, 0);
1540 SetBkColor (dis->hDC, bkc);
1541 SetTextColor (dis->hDC, txc);
1545 if (dis->itemAction & ODA_FOCUS) {
1546 rect.left = xbase + xioff - 1;
1547 rect.right = rect.left + txtsize.cx + 2;
1548 rect.top = dis->rcItem.top;
1549 rect.bottom = dis->rcItem.bottom;
1550 DrawFocusRect(dis->hDC, &rect);
1553 return 0;
1557 static void COMBOEX_ResetContent (COMBOEX_INFO *infoPtr)
1559 if (infoPtr->items)
1561 CBE_ITEMDATA *item, *next;
1563 item = infoPtr->items;
1564 while (item) {
1565 next = item->next;
1566 COMBOEX_FreeText (item);
1567 Free (item);
1568 item = next;
1570 infoPtr->items = 0;
1573 infoPtr->selected = -1;
1574 infoPtr->nb_items = 0;
1578 static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
1580 if (infoPtr->hwndCombo)
1581 RemoveWindowSubclass(infoPtr->hwndCombo, COMBOEX_ComboWndProc, COMBO_SUBCLASSID);
1583 if (infoPtr->hwndEdit)
1584 RemoveWindowSubclass(infoPtr->hwndEdit, COMBOEX_EditWndProc, EDIT_SUBCLASSID);
1586 COMBOEX_FreeText (infoPtr->edit);
1587 Free (infoPtr->edit);
1588 infoPtr->edit = 0;
1590 COMBOEX_ResetContent (infoPtr);
1592 if (infoPtr->defaultFont)
1593 DeleteObject (infoPtr->defaultFont);
1595 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1597 /* free comboex info data */
1598 Free (infoPtr);
1600 return 0;
1604 static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO const *infoPtr, MEASUREITEMSTRUCT *mis)
1606 static const WCHAR strW[] = { 'W', 0 };
1607 SIZE mysize;
1608 HDC hdc;
1610 hdc = GetDC (0);
1611 GetTextExtentPointW (hdc, strW, 1, &mysize);
1612 ReleaseDC (0, hdc);
1613 mis->itemHeight = mysize.cy + CBE_EXTRA;
1615 TRACE("adjusted height hwnd=%p, height=%d\n",
1616 infoPtr->hwndSelf, mis->itemHeight);
1618 return 0;
1622 static LRESULT COMBOEX_NCCreate (HWND hwnd)
1624 /* WARNING: The COMBOEX_INFO structure is not yet created */
1625 DWORD oldstyle, newstyle;
1627 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
1628 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL | WS_BORDER);
1629 if (newstyle != oldstyle) {
1630 TRACE("req style %08x, resetting style %08x\n",
1631 oldstyle, newstyle);
1632 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
1634 return 1;
1638 static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
1640 if (lParam == NF_REQUERY) {
1641 INT i = SendMessageW(infoPtr->hwndNotify,
1642 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1643 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1645 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
1649 static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
1651 TRACE("(width=%d, height=%d)\n", width, height);
1653 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
1655 COMBOEX_AdjustEditPos (infoPtr);
1657 return 0;
1661 static LRESULT COMBOEX_SetRedraw(const COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1663 LRESULT ret = DefWindowProcW( infoPtr->hwndSelf, WM_SETREDRAW, wParam, lParam );
1664 if (wParam) RedrawWindow( infoPtr->hwndSelf, NULL, 0, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN );
1665 return ret;
1669 static LRESULT COMBOEX_WindowPosChanging (const COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
1671 RECT cbx_wrect, cbx_crect, cb_wrect;
1672 INT width, height;
1674 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1675 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
1676 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1678 /* width is winpos value + border width of comboex */
1679 width = wp->cx
1680 + (cbx_wrect.right-cbx_wrect.left)
1681 - (cbx_crect.right-cbx_crect.left);
1683 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1684 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1685 TRACE("EX window=(%s), client=(%s)\n",
1686 wine_dbgstr_rect(&cbx_wrect), wine_dbgstr_rect(&cbx_crect));
1687 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
1688 wine_dbgstr_rect(&cbx_wrect), width, cb_wrect.bottom-cb_wrect.top);
1690 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1691 width,
1692 cb_wrect.bottom-cb_wrect.top,
1693 SWP_NOACTIVATE);
1695 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1697 /* height is combo window height plus border width of comboex */
1698 height = (cb_wrect.bottom-cb_wrect.top)
1699 + (cbx_wrect.bottom-cbx_wrect.top)
1700 - (cbx_crect.bottom-cbx_crect.top);
1701 if (wp->cy < height) wp->cy = height;
1702 if (infoPtr->hwndEdit) {
1703 COMBOEX_AdjustEditPos (infoPtr);
1704 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1707 return 0;
1710 static LRESULT CALLBACK
1711 COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
1712 UINT_PTR uId, DWORD_PTR ref_data)
1714 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr ((HWND)ref_data);
1715 NMCBEENDEDITW cbeend;
1716 WCHAR edit_text[260];
1717 COLORREF obkc;
1718 HDC hDC;
1719 RECT rect;
1720 LRESULT lret;
1722 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1723 hwnd, uMsg, wParam, lParam, infoPtr);
1725 if (!infoPtr) return 0;
1727 switch (uMsg)
1730 case WM_CHAR:
1731 /* handle (ignore) the return character */
1732 if (wParam == VK_RETURN) return 0;
1733 /* all other characters pass into the real Edit */
1734 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1736 case WM_ERASEBKGND:
1738 * The following was determined by traces of the native
1740 hDC = (HDC) wParam;
1741 obkc = SetBkColor (hDC, comctl32_color.clrWindow);
1742 GetClientRect (hwnd, &rect);
1743 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect));
1744 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1745 SetBkColor (hDC, obkc);
1746 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1748 case WM_KEYDOWN: {
1749 INT_PTR oldItem, selected, step = 1;
1750 CBE_ITEMDATA *item;
1752 switch ((INT)wParam)
1754 case VK_ESCAPE:
1755 /* native version seems to do following for COMBOEX */
1757 * GetWindowTextW(Edit,&?, 0x104) x
1758 * CB_GETCURSEL to Combo rets -1 x
1759 * WM_NOTIFY to COMBOEX parent (rebar) x
1760 * (CBEN_ENDEDIT{A|W}
1761 * fChanged = FALSE x
1762 * inewSelection = -1 x
1763 * txt="www.hoho" x
1764 * iWhy = 3 x
1765 * CB_GETCURSEL to Combo rets -1 x
1766 * InvalidateRect(Combo, 0) x
1767 * WM_SETTEXT to Edit x
1768 * EM_SETSEL to Edit (0,0) x
1769 * EM_SETSEL to Edit (0,-1) x
1770 * RedrawWindow(Combo, 0, 0, 5) x
1772 TRACE("special code for VK_ESCAPE\n");
1774 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1776 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1777 cbeend.fChanged = FALSE;
1778 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1779 CB_GETCURSEL, 0, 0);
1780 cbeend.iWhy = CBENF_ESCAPE;
1782 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
1783 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1784 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1785 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1786 ERR("item %ld not found. Problem!\n", oldItem);
1787 break;
1789 infoPtr->selected = oldItem;
1790 COMBOEX_SetEditText (infoPtr, item);
1791 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1792 RDW_INVALIDATE);
1793 break;
1795 case VK_RETURN:
1796 /* native version seems to do following for COMBOEX */
1798 * GetWindowTextW(Edit,&?, 0x104) x
1799 * CB_GETCURSEL to Combo rets -1 x
1800 * CB_GETCOUNT to Combo rets 0
1801 * if >0 loop
1802 * CB_GETITEMDATA to match
1803 * *** above 3 lines simulated by FindItem x
1804 * WM_NOTIFY to COMBOEX parent (rebar) x
1805 * (CBEN_ENDEDIT{A|W} x
1806 * fChanged = TRUE (-1) x
1807 * iNewSelection = -1 or selected x
1808 * txt= x
1809 * iWhy = 2 (CBENF_RETURN) x
1810 * CB_GETCURSEL to Combo rets -1 x
1811 * if -1 send CB_SETCURSEL to Combo -1 x
1812 * InvalidateRect(Combo, 0, 0) x
1813 * SetFocus(Edit) x
1814 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1817 TRACE("special code for VK_RETURN\n");
1819 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1821 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1822 selected = SendMessageW (infoPtr->hwndCombo,
1823 CB_GETCURSEL, 0, 0);
1825 if (selected != -1) {
1826 cmp_func_t cmptext = get_cmp_func(infoPtr);
1827 item = COMBOEX_FindItem (infoPtr, selected);
1828 TRACE("handling VK_RETURN, selected = %ld, selected_text=%s\n",
1829 selected, debugstr_txt(item->pszText));
1830 TRACE("handling VK_RETURN, edittext=%s\n",
1831 debugstr_w(edit_text));
1832 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
1833 /* strings not equal -- indicate edit has changed */
1834 selected = -1;
1838 cbeend.iNewSelection = selected;
1839 cbeend.fChanged = TRUE;
1840 cbeend.iWhy = CBENF_RETURN;
1841 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1842 /* abort the change, restore previous */
1843 TRACE("Notify requested abort of change\n");
1844 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
1845 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1846 RDW_INVALIDATE);
1847 return 0;
1849 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1850 if (oldItem != -1) {
1851 /* if something is selected, then deselect it */
1852 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, -1, 0);
1854 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1855 SetFocus(infoPtr->hwndEdit);
1856 break;
1858 case VK_UP:
1859 step = -1;
1860 case VK_DOWN:
1861 /* by default, step is 1 */
1862 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1863 if (oldItem >= 0 && oldItem + step >= 0)
1864 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1865 return 0;
1866 default:
1867 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1869 return 0;
1872 case WM_SETFOCUS:
1873 /* remember the focus to set state of icon */
1874 lret = DefSubclassProc(hwnd, uMsg, wParam, lParam);
1875 infoPtr->flags |= WCBE_EDITFOCUSED;
1876 return lret;
1878 case WM_KILLFOCUS:
1880 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1882 infoPtr->flags &= ~WCBE_EDITFOCUSED;
1883 if (infoPtr->flags & WCBE_ACTEDIT) {
1884 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1886 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1887 cbeend.fChanged = FALSE;
1888 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1889 CB_GETCURSEL, 0, 0);
1890 cbeend.iWhy = CBENF_KILLFOCUS;
1892 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
1894 /* fall through */
1896 default:
1897 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1902 static LRESULT CALLBACK
1903 COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
1904 UINT_PTR uId, DWORD_PTR ref_data)
1906 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr ((HWND)ref_data);
1907 NMCBEENDEDITW cbeend;
1908 NMMOUSE nmmse;
1909 COLORREF obkc;
1910 HDC hDC;
1911 HWND focusedhwnd;
1912 RECT rect;
1913 POINT pt;
1914 WCHAR edit_text[260];
1916 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1917 hwnd, uMsg, wParam, lParam, infoPtr);
1919 if (!infoPtr) return 0;
1921 switch (uMsg)
1924 case WM_DRAWITEM:
1926 * The only way this message should come is from the
1927 * child Listbox issuing the message. Flag this so
1928 * that ComboEx knows this is listbox.
1930 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
1931 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1933 case WM_ERASEBKGND:
1935 * The following was determined by traces of the native
1937 hDC = (HDC) wParam;
1938 obkc = SetBkColor (hDC, comctl32_color.clrWindow);
1939 GetClientRect (hwnd, &rect);
1940 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect));
1941 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1942 SetBkColor (hDC, obkc);
1943 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1945 case WM_SETCURSOR:
1947 * WM_NOTIFY to comboex parent (rebar)
1948 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1949 * CallWindowProc (previous)
1951 nmmse.dwItemSpec = 0;
1952 nmmse.dwItemData = 0;
1953 nmmse.pt.x = 0;
1954 nmmse.pt.y = 0;
1955 nmmse.dwHitInfo = lParam;
1956 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
1957 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1959 case WM_LBUTTONDOWN:
1960 GetClientRect (hwnd, &rect);
1961 rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1962 CB_GETITEMHEIGHT, -1, 0);
1963 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
1964 pt.x = (short)LOWORD(lParam);
1965 pt.y = (short)HIWORD(lParam);
1966 if (PtInRect(&rect, pt))
1967 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1969 infoPtr->flags |= WCBE_MOUSECAPTURED;
1970 SetCapture(hwnd);
1971 break;
1973 case WM_LBUTTONUP:
1974 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1975 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1977 ReleaseCapture();
1978 infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1979 if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1980 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1981 } else {
1982 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1984 break;
1986 case WM_MOUSEMOVE:
1987 if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1988 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
1989 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1990 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
1991 infoPtr->flags |= WCBE_MOUSEDRAGGED;
1993 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1995 case WM_COMMAND:
1996 switch (HIWORD(wParam)) {
1998 case EN_UPDATE:
1999 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2000 * on the EN_UPDATE
2002 return 0;
2004 case EN_KILLFOCUS:
2006 * Native does:
2008 * GetFocus() retns AA
2009 * GetWindowTextW(Edit)
2010 * CB_GETCURSEL(Combo) (got -1)
2011 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2012 * CB_GETCURSEL(Combo) (got -1)
2013 * InvalidateRect(Combo, 0, 0)
2014 * WM_KILLFOCUS(Combo, AA)
2015 * return 0;
2017 focusedhwnd = GetFocus();
2018 if (infoPtr->flags & WCBE_ACTEDIT) {
2019 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2020 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2021 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2022 CB_GETCURSEL, 0, 0);
2023 cbeend.iWhy = CBENF_KILLFOCUS;
2025 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2026 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
2028 /* possible CB_GETCURSEL */
2029 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2030 if (focusedhwnd)
2031 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2032 (WPARAM)focusedhwnd, 0);
2033 return 0;
2035 case EN_SETFOCUS: {
2037 * For EN_SETFOCUS this issues the same calls and messages
2038 * as the native seems to do.
2040 * for some cases however native does the following:
2041 * (noticed after SetFocus during LBUTTONDOWN on
2042 * on dropdown arrow)
2043 * WM_GETTEXTLENGTH (Edit);
2044 * WM_GETTEXT (Edit, len+1, str);
2045 * EM_SETSEL (Edit, 0, 0);
2046 * WM_GETTEXTLENGTH (Edit);
2047 * WM_GETTEXT (Edit, len+1, str);
2048 * EM_SETSEL (Edit, 0, len);
2049 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2051 NMHDR hdr;
2053 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2054 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2055 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2056 infoPtr->flags |= WCBE_ACTEDIT;
2057 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2058 return 0;
2061 case EN_CHANGE: {
2063 * For EN_CHANGE this issues the same calls and messages
2064 * as the native seems to do.
2066 WCHAR edit_text[260];
2067 LPCWSTR lastwrk;
2068 cmp_func_t cmptext = get_cmp_func(infoPtr);
2070 INT_PTR selected = SendMessageW (infoPtr->hwndCombo,
2071 CB_GETCURSEL, 0, 0);
2073 /* lstrlenW( lastworkingURL ) */
2075 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2076 if (selected == -1) {
2077 lastwrk = infoPtr->edit->pszText;
2079 else {
2080 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
2081 lastwrk = COMBOEX_GetText(infoPtr, item);
2084 TRACE("handling EN_CHANGE, selected = %ld, selected_text=%s\n",
2085 selected, debugstr_w(lastwrk));
2086 TRACE("handling EN_CHANGE, edittext=%s\n",
2087 debugstr_w(edit_text));
2089 /* cmptext is between lastworkingURL and GetWindowText */
2090 if (cmptext (lastwrk, edit_text)) {
2091 /* strings not equal -- indicate edit has changed */
2092 infoPtr->flags |= WCBE_EDITCHG;
2094 SendMessageW ( infoPtr->hwndNotify, WM_COMMAND,
2095 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2096 CBN_EDITCHANGE),
2097 (LPARAM)infoPtr->hwndSelf);
2098 return 0;
2101 case LBN_SELCHANGE:
2103 * Therefore from traces there is no additional code here
2107 * Using native COMCTL32 gets the following:
2108 * 1 == SHDOCVW.DLL issues call/message
2109 * 2 == COMCTL32.DLL issues call/message
2110 * 3 == WINE issues call/message
2113 * for LBN_SELCHANGE:
2114 * 1 CB_GETCURSEL(ComboEx)
2115 * 1 CB_GETDROPPEDSTATE(ComboEx)
2116 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2117 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2118 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2119 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2120 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2121 * 3 ShowWindow(ComboLB, SW_HIDE)
2122 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2123 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2124 ** end of CBRollUp
2125 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2126 * ? LB_GETCURSEL <==|
2127 * ? LB_GETTEXTLEN |
2128 * ? LB_GETTEXT | Needs to be added to
2129 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2130 * ? LB_GETITEMDATA |
2131 * ? WM_DRAWITEM(ComboEx) <==|
2133 default:
2134 break;
2135 }/* fall through */
2136 default:
2137 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2139 return 0;
2143 static LRESULT WINAPI
2144 COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2146 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2148 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2150 if (!infoPtr) {
2151 if (uMsg == WM_CREATE)
2152 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
2153 if (uMsg == WM_NCCREATE)
2154 COMBOEX_NCCreate (hwnd);
2155 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2158 switch (uMsg)
2160 case CBEM_DELETEITEM:
2161 return COMBOEX_DeleteItem (infoPtr, wParam);
2163 case CBEM_GETCOMBOCONTROL:
2164 return (LRESULT)infoPtr->hwndCombo;
2166 case CBEM_GETEDITCONTROL:
2167 return (LRESULT)infoPtr->hwndEdit;
2169 case CBEM_GETEXTENDEDSTYLE:
2170 return infoPtr->dwExtStyle;
2172 case CBEM_GETIMAGELIST:
2173 return (LRESULT)infoPtr->himl;
2175 case CBEM_GETITEMA:
2176 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2178 case CBEM_GETITEMW:
2179 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2181 case CBEM_GETUNICODEFORMAT:
2182 return infoPtr->unicode;
2184 case CBEM_HASEDITCHANGED:
2185 return COMBOEX_HasEditChanged (infoPtr);
2187 case CBEM_INSERTITEMA:
2188 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2190 case CBEM_INSERTITEMW:
2191 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2193 case CBEM_SETEXSTYLE:
2194 case CBEM_SETEXTENDEDSTYLE:
2195 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
2197 case CBEM_SETIMAGELIST:
2198 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
2200 case CBEM_SETITEMA:
2201 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
2203 case CBEM_SETITEMW:
2204 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
2206 case CBEM_SETUNICODEFORMAT:
2207 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
2209 /*case CBEM_SETWINDOWTHEME:
2210 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2212 case WM_SETTEXT:
2213 case WM_GETTEXT:
2214 case WM_GETTEXTLENGTH:
2215 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2217 case CB_GETLBTEXT:
2218 return COMBOEX_GetListboxText(infoPtr, wParam, (LPWSTR)lParam);
2220 case CB_GETLBTEXTLEN:
2221 return COMBOEX_GetListboxText(infoPtr, wParam, NULL);
2223 case CB_RESETCONTENT:
2224 COMBOEX_ResetContent(infoPtr);
2225 /* fall through */
2227 /* Combo messages we are not sure if we need to process or just forward */
2228 case CB_GETDROPPEDCONTROLRECT:
2229 case CB_GETITEMHEIGHT:
2230 case CB_GETEXTENDEDUI:
2231 case CB_LIMITTEXT:
2232 case CB_SELECTSTRING:
2234 /* Combo messages OK to just forward to the regular COMBO */
2235 case CB_GETCOUNT:
2236 case CB_GETCURSEL:
2237 case CB_GETDROPPEDSTATE:
2238 case CB_SETDROPPEDWIDTH:
2239 case CB_SETEXTENDEDUI:
2240 case CB_SHOWDROPDOWN:
2241 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
2243 /* Combo messages we need to process specially */
2244 case CB_FINDSTRINGEXACT:
2245 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
2247 case CB_GETITEMDATA:
2248 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
2250 case CB_SETCURSEL:
2251 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
2253 case CB_SETITEMDATA:
2254 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD_PTR)lParam);
2256 case CB_SETITEMHEIGHT:
2257 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
2261 /* Window messages passed to parent */
2262 case WM_COMMAND:
2263 return COMBOEX_Command (infoPtr, wParam);
2265 case WM_NOTIFY:
2266 if (infoPtr->NtfUnicode)
2267 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
2268 else
2269 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
2272 /* Window messages we need to process */
2273 case WM_DELETEITEM:
2274 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
2276 case WM_DRAWITEM:
2277 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
2279 case WM_DESTROY:
2280 return COMBOEX_Destroy (infoPtr);
2282 case WM_MEASUREITEM:
2283 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
2285 case WM_NOTIFYFORMAT:
2286 return COMBOEX_NotifyFormat (infoPtr, lParam);
2288 case WM_SIZE:
2289 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
2291 case WM_SETREDRAW:
2292 return COMBOEX_SetRedraw(infoPtr, wParam, lParam);
2294 case WM_WINDOWPOSCHANGING:
2295 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
2297 case WM_SETFOCUS:
2298 SetFocus(infoPtr->hwndCombo);
2299 return 0;
2301 case WM_SYSCOLORCHANGE:
2302 COMCTL32_RefreshSysColors();
2303 return 0;
2305 default:
2306 if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
2307 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",uMsg,wParam,lParam);
2308 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2313 void COMBOEX_Register (void)
2315 WNDCLASSW wndClass;
2317 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2318 wndClass.style = CS_GLOBALCLASS;
2319 wndClass.lpfnWndProc = COMBOEX_WindowProc;
2320 wndClass.cbClsExtra = 0;
2321 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2322 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2323 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2324 wndClass.lpszClassName = WC_COMBOBOXEXW;
2326 RegisterClassW (&wndClass);
2330 void COMBOEX_Unregister (void)
2332 UnregisterClassW (WC_COMBOBOXEXW, NULL);