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
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.
42 #include "wine/debug.h"
43 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(comboex
);
48 typedef struct _CBE_ITEMDATA
50 struct _CBE_ITEMDATA
*next
;
62 /* ComboBoxEx structure */
66 HWND hwndSelf
; /* my own hwnd */
67 HWND hwndNotify
; /* my parent hwnd */
70 WNDPROC prevEditWndProc
; /* previous Edit WNDPROC value */
71 WNDPROC prevComboWndProc
; /* previous Combo WNDPROC value */
73 INT selected
; /* index of selected item */
74 DWORD flags
; /* WINE internal flags */
77 INT nb_items
; /* Number of items */
78 BOOL unicode
; /* TRUE if this window is Unicode */
79 BOOL NtfUnicode
; /* TRUE if parent wants notify in Unicode */
80 CBE_ITEMDATA
*edit
; /* item data for edit item */
81 CBE_ITEMDATA
*items
; /* Array of items */
84 /* internal flags in the COMBOEX_INFO structure */
85 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
86 * CBEN_BEGINEDIT issued
87 * but CBEN_ENDEDIT{A|W}
89 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
90 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
91 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
92 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
93 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
95 #define ID_CB_EDIT 1001
99 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
100 * the ComboEx version of the Combo Window Proc so that when the
101 * WM_DRAWITEM message is then passed to ComboEx, we know that this
102 * particular WM_DRAWITEM message is for listbox only items. Any messasges
103 * without this flag is then for the Edit control field.
105 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
106 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
108 #define ODS_COMBOEXLBOX 0x4000
112 /* Height in pixels of control over the amount of the selected font */
115 /* Indent amount per MS documentation */
116 #define CBE_INDENT 10
118 /* Offset in pixels from left side for start of image or text */
119 #define CBE_STARTOFFSET 6
121 /* Offset between image and text */
124 static const WCHAR COMBOEX_SUBCLASS_PROP
[] = {
125 'C','C','C','o','m','b','o','E','x','3','2',
126 'S','u','b','c','l','a','s','s','I','n','f','o',0
129 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongPtrW (hwnd, 0))
132 /* Things common to the entire DLL */
133 static LRESULT WINAPI
COMBOEX_EditWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
134 static LRESULT WINAPI
COMBOEX_ComboWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
135 static LRESULT
COMBOEX_Destroy (COMBOEX_INFO
*infoPtr
);
136 typedef INT (WINAPI
*cmp_func_t
)(LPCWSTR
, LPCWSTR
);
138 static inline BOOL
is_textW(LPCWSTR str
)
140 return str
&& str
!= LPSTR_TEXTCALLBACKW
;
143 static inline BOOL
is_textA(LPCSTR str
)
145 return str
&& str
!= LPSTR_TEXTCALLBACKA
;
148 static inline LPCSTR
debugstr_txt(LPCWSTR str
)
150 if (str
== LPSTR_TEXTCALLBACKW
) return "(callback)";
151 return debugstr_w(str
);
154 static void COMBOEX_DumpItem (CBE_ITEMDATA
const *item
)
156 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
157 item
, item
->mask
, item
->pszText
, item
->cchTextMax
, item
->iImage
);
158 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
159 item
, item
->iSelectedImage
, item
->iOverlay
, item
->iIndent
, item
->lParam
);
160 if (item
->mask
& CBEIF_TEXT
)
161 TRACE("item %p - pszText=%s\n", item
, debugstr_txt(item
->pszText
));
165 static void COMBOEX_DumpInput (COMBOBOXEXITEMW
const *input
)
167 TRACE("input - mask=%08x, iItem=%ld, pszText=%p, cchTM=%d, iImage=%d\n",
168 input
->mask
, input
->iItem
, input
->pszText
, input
->cchTextMax
,
170 if (input
->mask
& CBEIF_TEXT
)
171 TRACE("input - pszText=<%s>\n", debugstr_txt(input
->pszText
));
172 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
173 input
->iSelectedImage
, input
->iOverlay
, input
->iIndent
, input
->lParam
);
177 static inline CBE_ITEMDATA
*get_item_data(COMBOEX_INFO
*infoPtr
, INT index
)
179 return (CBE_ITEMDATA
*)SendMessageW (infoPtr
->hwndCombo
, CB_GETITEMDATA
,
183 static inline cmp_func_t
get_cmp_func(COMBOEX_INFO
const *infoPtr
)
185 return infoPtr
->dwExtStyle
& CBES_EX_CASESENSITIVE
? lstrcmpW
: lstrcmpiW
;
188 static INT
COMBOEX_Notify (COMBOEX_INFO
*infoPtr
, INT code
, NMHDR
*hdr
)
190 hdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
191 hdr
->hwndFrom
= infoPtr
->hwndSelf
;
193 if (infoPtr
->NtfUnicode
)
194 return SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)hdr
);
196 return SendMessageA (infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)hdr
);
201 COMBOEX_NotifyItem (COMBOEX_INFO
*infoPtr
, UINT code
, NMCOMBOBOXEXW
*hdr
)
203 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
204 if (infoPtr
->NtfUnicode
)
205 return COMBOEX_Notify (infoPtr
, code
, &hdr
->hdr
);
207 LPWSTR wstr
= hdr
->ceItem
.pszText
;
211 if ((hdr
->ceItem
.mask
& CBEIF_TEXT
) && is_textW(wstr
)) {
212 len
= WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, 0, 0, NULL
, NULL
);
214 astr
= Alloc ((len
+ 1)*sizeof(CHAR
));
216 WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, astr
, len
, 0, 0);
217 hdr
->ceItem
.pszText
= (LPWSTR
)astr
;
221 if (code
== CBEN_ENDEDITW
) code
= CBEN_ENDEDITA
;
222 else if (code
== CBEN_GETDISPINFOW
) code
= CBEN_GETDISPINFOA
;
223 else if (code
== CBEN_DRAGBEGINW
) code
= CBEN_DRAGBEGINA
;
225 ret
= COMBOEX_Notify (infoPtr
, code
, (NMHDR
*)hdr
);
227 if (astr
&& hdr
->ceItem
.pszText
== (LPWSTR
)astr
)
228 hdr
->ceItem
.pszText
= wstr
;
237 static INT
COMBOEX_NotifyEndEdit (COMBOEX_INFO
*infoPtr
, NMCBEENDEDITW
*neew
, LPCWSTR wstr
)
239 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
240 if (infoPtr
->NtfUnicode
) {
241 lstrcpynW(neew
->szText
, wstr
, CBEMAXSTRLEN
);
242 return COMBOEX_Notify (infoPtr
, CBEN_ENDEDITW
, &neew
->hdr
);
246 neea
.hdr
= neew
->hdr
;
247 neea
.fChanged
= neew
->fChanged
;
248 neea
.iNewSelection
= neew
->iNewSelection
;
249 WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, neea
.szText
, CBEMAXSTRLEN
, 0, 0);
250 neea
.iWhy
= neew
->iWhy
;
252 return COMBOEX_Notify (infoPtr
, CBEN_ENDEDITA
, &neea
.hdr
);
257 static void COMBOEX_NotifyDragBegin(COMBOEX_INFO
*infoPtr
, LPCWSTR wstr
)
259 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
260 if (infoPtr
->NtfUnicode
) {
261 NMCBEDRAGBEGINW ndbw
;
264 lstrcpynW(ndbw
.szText
, wstr
, CBEMAXSTRLEN
);
265 COMBOEX_Notify (infoPtr
, CBEN_DRAGBEGINW
, &ndbw
.hdr
);
267 NMCBEDRAGBEGINA ndba
;
270 WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, ndba
.szText
, CBEMAXSTRLEN
, 0, 0);
272 COMBOEX_Notify (infoPtr
, CBEN_DRAGBEGINA
, &ndba
.hdr
);
277 static void COMBOEX_FreeText (CBE_ITEMDATA
*item
)
279 if (is_textW(item
->pszText
)) Free(item
->pszText
);
286 static INT
COMBOEX_GetIndex(COMBOEX_INFO
const *infoPtr
, CBE_ITEMDATA
const *item
)
288 CBE_ITEMDATA
const *moving
;
291 moving
= infoPtr
->items
;
292 index
= infoPtr
->nb_items
- 1;
294 while (moving
&& (moving
!= item
)) {
295 moving
= moving
->next
;
298 if (!moving
|| (index
< 0)) {
299 ERR("COMBOBOXEX item structures broken. Please report!\n");
306 static LPCWSTR
COMBOEX_GetText(COMBOEX_INFO
*infoPtr
, CBE_ITEMDATA
*item
)
312 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
313 return item
->pszText
;
315 ZeroMemory(&nmce
, sizeof(nmce
));
316 nmce
.ceItem
.mask
= CBEIF_TEXT
;
317 nmce
.ceItem
.lParam
= item
->lParam
;
318 nmce
.ceItem
.iItem
= COMBOEX_GetIndex(infoPtr
, item
);
319 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
321 if (is_textW(nmce
.ceItem
.pszText
)) {
322 len
= MultiByteToWideChar (CP_ACP
, 0, (LPSTR
)nmce
.ceItem
.pszText
, -1, NULL
, 0);
323 buf
= Alloc ((len
+ 1)*sizeof(WCHAR
));
325 MultiByteToWideChar (CP_ACP
, 0, (LPSTR
)nmce
.ceItem
.pszText
, -1, buf
, len
);
326 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) {
327 COMBOEX_FreeText(item
);
335 text
= nmce
.ceItem
.pszText
;
337 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
338 item
->pszText
= text
;
343 static void COMBOEX_GetComboFontSize (COMBOEX_INFO
*infoPtr
, SIZE
*size
)
345 static const WCHAR strA
[] = { 'A', 0 };
349 mydc
= GetDC (0); /* why the entire screen???? */
350 nfont
= (HFONT
)SendMessageW (infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
351 ofont
= SelectObject (mydc
, nfont
);
352 GetTextExtentPointW (mydc
, strA
, 1, size
);
353 SelectObject (mydc
, ofont
);
355 TRACE("selected font hwnd=%p, height=%d\n", nfont
, size
->cy
);
359 static void COMBOEX_CopyItem (const CBE_ITEMDATA
*item
, COMBOBOXEXITEMW
*cit
)
361 if (cit
->mask
& CBEIF_TEXT
) {
363 * when given a text buffer actually use that buffer
366 if (is_textW(item
->pszText
))
367 lstrcpynW(cit
->pszText
, item
->pszText
, cit
->cchTextMax
);
371 cit
->pszText
= item
->pszText
;
372 cit
->cchTextMax
= item
->cchTextMax
;
375 if (cit
->mask
& CBEIF_IMAGE
)
376 cit
->iImage
= item
->iImage
;
377 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
378 cit
->iSelectedImage
= item
->iSelectedImage
;
379 if (cit
->mask
& CBEIF_OVERLAY
)
380 cit
->iOverlay
= item
->iOverlay
;
381 if (cit
->mask
& CBEIF_INDENT
)
382 cit
->iIndent
= item
->iIndent
;
383 if (cit
->mask
& CBEIF_LPARAM
)
384 cit
->lParam
= item
->lParam
;
388 static void COMBOEX_AdjustEditPos (COMBOEX_INFO
*infoPtr
)
391 INT x
, y
, w
, h
, xioff
;
394 if (!infoPtr
->hwndEdit
) return;
396 if (infoPtr
->himl
&& !(infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGEINDENT
)) {
398 iinfo
.rcImage
.left
= iinfo
.rcImage
.right
= 0;
399 ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
);
400 xioff
= iinfo
.rcImage
.right
- iinfo
.rcImage
.left
+ CBE_SEP
;
403 GetClientRect (infoPtr
->hwndCombo
, &rect
);
404 InflateRect (&rect
, -2, -2);
405 InvalidateRect (infoPtr
->hwndCombo
, &rect
, TRUE
);
407 /* reposition the Edit control based on whether icon exists */
408 COMBOEX_GetComboFontSize (infoPtr
, &mysize
);
409 TRACE("Combo font x=%d, y=%d\n", mysize
.cx
, mysize
.cy
);
410 x
= xioff
+ CBE_STARTOFFSET
+ 1;
411 w
= rect
.right
-rect
.left
- x
- GetSystemMetrics(SM_CXVSCROLL
) - 1;
413 y
= rect
.bottom
- h
- 1;
415 TRACE("Combo client (%s), setting Edit to (%d,%d)-(%d,%d)\n",
416 wine_dbgstr_rect(&rect
), x
, y
, x
+ w
, y
+ h
);
417 SetWindowPos(infoPtr
->hwndEdit
, HWND_TOP
, x
, y
, w
, h
,
418 SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
422 static void COMBOEX_ReSize (COMBOEX_INFO
*infoPtr
)
428 COMBOEX_GetComboFontSize (infoPtr
, &mysize
);
429 cy
= mysize
.cy
+ CBE_EXTRA
;
430 if (infoPtr
->himl
&& ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
)) {
431 cy
= max (iinfo
.rcImage
.bottom
- iinfo
.rcImage
.top
, cy
);
432 TRACE("upgraded height due to image: height=%d\n", cy
);
434 SendMessageW (infoPtr
->hwndSelf
, CB_SETITEMHEIGHT
, -1, cy
);
435 if (infoPtr
->hwndCombo
) {
436 SendMessageW (infoPtr
->hwndCombo
, CB_SETITEMHEIGHT
, 0, cy
);
437 if ( !(infoPtr
->flags
& CBES_EX_NOSIZELIMIT
)) {
439 if (GetWindowRect(infoPtr
->hwndCombo
, &comboRect
)) {
441 if (GetWindowRect(infoPtr
->hwndSelf
, &ourRect
)) {
442 if (comboRect
.bottom
> ourRect
.bottom
) {
443 POINT pt
= { ourRect
.left
, ourRect
.top
};
444 if (ScreenToClient(infoPtr
->hwndSelf
, &pt
))
445 MoveWindow( infoPtr
->hwndSelf
, pt
.x
, pt
.y
, ourRect
.right
- ourRect
.left
,
446 comboRect
.bottom
- comboRect
.top
, FALSE
);
455 static void COMBOEX_SetEditText (COMBOEX_INFO
*infoPtr
, CBE_ITEMDATA
*item
)
457 if (!infoPtr
->hwndEdit
) return;
458 /* native issues the following messages to the {Edit} control */
459 /* WM_SETTEXT (0,addr) */
460 /* EM_SETSEL32 (0,0) */
461 /* EM_SETSEL32 (0,-1) */
462 if (item
->mask
& CBEIF_TEXT
) {
463 SendMessageW (infoPtr
->hwndEdit
, WM_SETTEXT
, 0, (LPARAM
)COMBOEX_GetText(infoPtr
, item
));
464 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, 0);
465 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
470 static CBE_ITEMDATA
* COMBOEX_FindItem(const COMBOEX_INFO
*infoPtr
, INT_PTR index
)
475 if ((index
>= infoPtr
->nb_items
) || (index
< -1))
478 return infoPtr
->edit
;
479 item
= infoPtr
->items
;
480 i
= infoPtr
->nb_items
- 1;
482 /* find the item in the list */
483 while (item
&& (i
> index
)) {
487 if (!item
|| (i
!= index
)) {
488 ERR("COMBOBOXEX item structures broken. Please report!\n");
495 static inline BOOL
COMBOEX_HasEdit(COMBOEX_INFO
const *infoPtr
)
497 return infoPtr
->hwndEdit
? TRUE
: FALSE
;
501 /* *** CBEM_xxx message support *** */
503 static UINT
COMBOEX_GetListboxText(COMBOEX_INFO
*infoPtr
, INT_PTR n
, LPWSTR buf
)
508 item
= COMBOEX_FindItem(infoPtr
, n
);
512 str
= COMBOEX_GetText(infoPtr
, item
);
514 if (infoPtr
->unicode
)
518 return lstrlenW(str
);
523 r
= WideCharToMultiByte(CP_ACP
, 0, str
, -1, (LPSTR
)buf
, 0x40000000, NULL
, NULL
);
530 static INT
COMBOEX_DeleteItem (COMBOEX_INFO
*infoPtr
, INT_PTR index
)
532 TRACE("(index=%ld)\n", index
);
534 /* if item number requested does not exist then return failure */
535 if ((index
>= infoPtr
->nb_items
) || (index
< 0)) return CB_ERR
;
536 if (!COMBOEX_FindItem(infoPtr
, index
)) return CB_ERR
;
538 /* doing this will result in WM_DELETEITEM being issued */
539 SendMessageW (infoPtr
->hwndCombo
, CB_DELETESTRING
, (WPARAM
)index
, 0);
541 return infoPtr
->nb_items
;
545 static BOOL
COMBOEX_GetItemW (const COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
*cit
)
547 INT_PTR index
= cit
->iItem
;
552 /* if item number requested does not exist then return failure */
553 if ((index
>= infoPtr
->nb_items
) || (index
< -1)) return FALSE
;
555 /* if the item is the edit control and there is no edit control, skip */
556 if ((index
== -1) && !COMBOEX_HasEdit(infoPtr
)) return FALSE
;
558 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return FALSE
;
560 COMBOEX_CopyItem (item
, cit
);
566 static BOOL
COMBOEX_GetItemA (const COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
*cit
)
568 COMBOBOXEXITEMW tmpcit
;
572 tmpcit
.mask
= cit
->mask
;
573 tmpcit
.iItem
= cit
->iItem
;
575 if(!COMBOEX_GetItemW (infoPtr
, &tmpcit
)) return FALSE
;
577 if (cit
->mask
& CBEIF_TEXT
)
579 if (is_textW(tmpcit
.pszText
) && cit
->pszText
)
580 WideCharToMultiByte(CP_ACP
, 0, tmpcit
.pszText
, -1,
581 cit
->pszText
, cit
->cchTextMax
, NULL
, NULL
);
582 else if (cit
->pszText
) cit
->pszText
[0] = 0;
583 else cit
->pszText
= (LPSTR
)tmpcit
.pszText
;
586 if (cit
->mask
& CBEIF_IMAGE
)
587 cit
->iImage
= tmpcit
.iImage
;
588 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
589 cit
->iSelectedImage
= tmpcit
.iSelectedImage
;
590 if (cit
->mask
& CBEIF_OVERLAY
)
591 cit
->iOverlay
= tmpcit
.iOverlay
;
592 if (cit
->mask
& CBEIF_INDENT
)
593 cit
->iIndent
= tmpcit
.iIndent
;
594 if (cit
->mask
& CBEIF_LPARAM
)
595 cit
->lParam
= tmpcit
.lParam
;
601 static inline BOOL
COMBOEX_HasEditChanged (COMBOEX_INFO
const *infoPtr
)
603 return COMBOEX_HasEdit(infoPtr
) &&
604 (infoPtr
->flags
& WCBE_EDITHASCHANGED
) == WCBE_EDITHASCHANGED
;
608 static INT
COMBOEX_InsertItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
const *cit
)
616 if (TRACE_ON(comboex
)) COMBOEX_DumpInput (cit
);
618 /* get real index of item to insert */
620 if (index
== -1) index
= infoPtr
->nb_items
;
621 if (index
> infoPtr
->nb_items
) return -1;
623 /* get zero-filled space and chain it in */
624 if(!(item
= Alloc (sizeof(*item
)))) return -1;
626 /* locate position to insert new item in */
627 if (index
== infoPtr
->nb_items
) {
628 /* fast path for iItem = -1 */
629 item
->next
= infoPtr
->items
;
630 infoPtr
->items
= item
;
633 INT i
= infoPtr
->nb_items
-1;
634 CBE_ITEMDATA
*moving
= infoPtr
->items
;
636 while ((i
> index
) && moving
) {
637 moving
= moving
->next
;
641 ERR("COMBOBOXEX item structures broken. Please report!\n");
645 item
->next
= moving
->next
;
649 /* fill in our hidden item structure */
650 item
->mask
= cit
->mask
;
651 if (item
->mask
& CBEIF_TEXT
) {
654 if (is_textW(cit
->pszText
)) len
= strlenW (cit
->pszText
);
656 item
->pszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
657 if (!item
->pszText
) {
661 strcpyW (item
->pszText
, cit
->pszText
);
663 else if (cit
->pszText
== LPSTR_TEXTCALLBACKW
)
664 item
->pszText
= LPSTR_TEXTCALLBACKW
;
665 item
->cchTextMax
= cit
->cchTextMax
;
667 if (item
->mask
& CBEIF_IMAGE
)
668 item
->iImage
= cit
->iImage
;
669 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
670 item
->iSelectedImage
= cit
->iSelectedImage
;
671 if (item
->mask
& CBEIF_OVERLAY
)
672 item
->iOverlay
= cit
->iOverlay
;
673 if (item
->mask
& CBEIF_INDENT
)
674 item
->iIndent
= cit
->iIndent
;
675 if (item
->mask
& CBEIF_LPARAM
)
676 item
->lParam
= cit
->lParam
;
679 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
681 SendMessageW (infoPtr
->hwndCombo
, CB_INSERTSTRING
,
682 (WPARAM
)cit
->iItem
, (LPARAM
)item
);
684 memset (&nmcit
.ceItem
, 0, sizeof(nmcit
.ceItem
));
685 COMBOEX_CopyItem (item
, &nmcit
.ceItem
);
686 COMBOEX_NotifyItem (infoPtr
, CBEN_INSERTITEM
, &nmcit
);
693 static INT
COMBOEX_InsertItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
const *cit
)
695 COMBOBOXEXITEMW citW
;
699 memcpy(&citW
,cit
,sizeof(COMBOBOXEXITEMA
));
700 if (cit
->mask
& CBEIF_TEXT
&& is_textA(cit
->pszText
)) {
701 INT len
= MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, NULL
, 0);
702 wstr
= Alloc ((len
+ 1)*sizeof(WCHAR
));
703 if (!wstr
) return -1;
704 MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, wstr
, len
);
707 ret
= COMBOEX_InsertItemW(infoPtr
, &citW
);
716 COMBOEX_SetExtendedStyle (COMBOEX_INFO
*infoPtr
, DWORD mask
, DWORD style
)
720 TRACE("(mask=x%08x, style=0x%08x)\n", mask
, style
);
722 dwTemp
= infoPtr
->dwExtStyle
;
725 infoPtr
->dwExtStyle
= (infoPtr
->dwExtStyle
& ~mask
) | style
;
727 infoPtr
->dwExtStyle
= style
;
729 /* see if we need to change the word break proc on the edit */
730 if ((infoPtr
->dwExtStyle
^ dwTemp
) & CBES_EX_PATHWORDBREAKPROC
)
731 SetPathWordBreakProc(infoPtr
->hwndEdit
,
732 (infoPtr
->dwExtStyle
& CBES_EX_PATHWORDBREAKPROC
) ? TRUE
: FALSE
);
734 /* test if the control's appearance has changed */
735 mask
= CBES_EX_NOEDITIMAGE
| CBES_EX_NOEDITIMAGEINDENT
;
736 if ((infoPtr
->dwExtStyle
& mask
) != (dwTemp
& mask
)) {
737 /* if state of EX_NOEDITIMAGE changes, invalidate all */
738 TRACE("EX_NOEDITIMAGE state changed to %d\n",
739 infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGE
);
740 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
741 COMBOEX_AdjustEditPos (infoPtr
);
742 if (infoPtr
->hwndEdit
)
743 InvalidateRect (infoPtr
->hwndEdit
, NULL
, TRUE
);
750 static HIMAGELIST
COMBOEX_SetImageList (COMBOEX_INFO
*infoPtr
, HIMAGELIST himl
)
752 HIMAGELIST himlTemp
= infoPtr
->himl
;
756 infoPtr
->himl
= himl
;
758 COMBOEX_ReSize (infoPtr
);
759 InvalidateRect (infoPtr
->hwndCombo
, NULL
, TRUE
);
761 /* reposition the Edit control based on whether icon exists */
762 COMBOEX_AdjustEditPos (infoPtr
);
766 static BOOL
COMBOEX_SetItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
*cit
)
768 INT_PTR index
= cit
->iItem
;
771 if (TRACE_ON(comboex
)) COMBOEX_DumpInput (cit
);
773 /* if item number requested does not exist then return failure */
774 if ((index
>= infoPtr
->nb_items
) || (index
< -1)) return FALSE
;
776 /* if the item is the edit control and there is no edit control, skip */
777 if ((index
== -1) && !COMBOEX_HasEdit(infoPtr
)) return FALSE
;
779 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return FALSE
;
781 /* add/change stuff to the internal item structure */
782 item
->mask
|= cit
->mask
;
783 if (cit
->mask
& CBEIF_TEXT
) {
786 COMBOEX_FreeText(item
);
787 if (is_textW(cit
->pszText
)) len
= strlenW(cit
->pszText
);
789 item
->pszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
790 if (!item
->pszText
) return FALSE
;
791 strcpyW(item
->pszText
, cit
->pszText
);
792 } else if (cit
->pszText
== LPSTR_TEXTCALLBACKW
)
793 item
->pszText
= LPSTR_TEXTCALLBACKW
;
794 item
->cchTextMax
= cit
->cchTextMax
;
796 if (cit
->mask
& CBEIF_IMAGE
)
797 item
->iImage
= cit
->iImage
;
798 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
799 item
->iSelectedImage
= cit
->iSelectedImage
;
800 if (cit
->mask
& CBEIF_OVERLAY
)
801 item
->iOverlay
= cit
->iOverlay
;
802 if (cit
->mask
& CBEIF_INDENT
)
803 item
->iIndent
= cit
->iIndent
;
804 if (cit
->mask
& CBEIF_LPARAM
)
805 cit
->lParam
= cit
->lParam
;
807 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
809 /* if original request was to update edit control, do some fast foot work */
810 if (cit
->iItem
== -1 && cit
->mask
& CBEIF_TEXT
) {
811 COMBOEX_SetEditText (infoPtr
, item
);
812 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
| RDW_INVALIDATE
);
817 static BOOL
COMBOEX_SetItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
const *cit
)
819 COMBOBOXEXITEMW citW
;
823 memcpy(&citW
, cit
, sizeof(COMBOBOXEXITEMA
));
824 if ((cit
->mask
& CBEIF_TEXT
) && is_textA(cit
->pszText
)) {
825 INT len
= MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, NULL
, 0);
826 wstr
= Alloc ((len
+ 1)*sizeof(WCHAR
));
827 if (!wstr
) return FALSE
;
828 MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, wstr
, len
);
831 ret
= COMBOEX_SetItemW(infoPtr
, &citW
);
839 static BOOL
COMBOEX_SetUnicodeFormat (COMBOEX_INFO
*infoPtr
, BOOL value
)
841 BOOL bTemp
= infoPtr
->unicode
;
843 TRACE("to %s, was %s\n", value
? "TRUE":"FALSE", bTemp
? "TRUE":"FALSE");
845 infoPtr
->unicode
= value
;
851 /* *** CB_xxx message support *** */
854 COMBOEX_FindStringExact (COMBOEX_INFO
*infoPtr
, INT start
, LPCWSTR str
)
857 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
858 INT count
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCOUNT
, 0, 0);
860 /* now search from after starting loc and wrapping back to start */
861 for(i
=start
+1; i
<count
; 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 for(i
=0; i
<=start
; i
++) {
867 CBE_ITEMDATA
*item
= get_item_data(infoPtr
, i
);
868 if ((LRESULT
)item
== CB_ERR
) continue;
869 if (cmptext(COMBOEX_GetText(infoPtr
, item
), str
) == 0) return i
;
875 static DWORD_PTR
COMBOEX_GetItemData (COMBOEX_INFO
*infoPtr
, INT_PTR index
)
877 CBE_ITEMDATA
const *item1
;
878 CBE_ITEMDATA
const *item2
;
881 item1
= get_item_data(infoPtr
, index
);
882 if ((item1
!= NULL
) && ((LRESULT
)item1
!= CB_ERR
)) {
883 item2
= COMBOEX_FindItem (infoPtr
, index
);
884 if (item2
!= item1
) {
885 ERR("data structures damaged!\n");
888 if (item1
->mask
& CBEIF_LPARAM
) ret
= item1
->lParam
;
889 TRACE("returning 0x%08lx\n", ret
);
891 ret
= (DWORD_PTR
)item1
;
892 TRACE("non-valid result from combo, returning 0x%08lx\n", ret
);
898 static INT
COMBOEX_SetCursel (COMBOEX_INFO
*infoPtr
, INT_PTR index
)
903 if (!(item
= COMBOEX_FindItem(infoPtr
, index
)))
904 return SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, index
, 0);
906 TRACE("selecting item %ld text=%s\n", index
, debugstr_txt(item
->pszText
));
907 infoPtr
->selected
= index
;
909 sel
= (INT
)SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, index
, 0);
910 COMBOEX_SetEditText (infoPtr
, item
);
915 static DWORD_PTR
COMBOEX_SetItemData (COMBOEX_INFO
*infoPtr
, INT_PTR index
, DWORD_PTR data
)
918 CBE_ITEMDATA
const *item2
;
920 item1
= get_item_data(infoPtr
, index
);
921 if ((item1
!= NULL
) && ((LRESULT
)item1
!= CB_ERR
)) {
922 item2
= COMBOEX_FindItem (infoPtr
, index
);
923 if (item2
!= item1
) {
924 ERR("data structures damaged!\n");
927 item1
->mask
|= CBEIF_LPARAM
;
928 item1
->lParam
= data
;
929 TRACE("setting lparam to 0x%08lx\n", data
);
932 TRACE("non-valid result from combo %p\n", item1
);
933 return (DWORD_PTR
)item1
;
937 static INT
COMBOEX_SetItemHeight (COMBOEX_INFO
const *infoPtr
, INT index
, UINT height
)
939 RECT cb_wrect
, cbx_wrect
, cbx_crect
;
941 /* First, lets forward the message to the normal combo control
942 just like Windows. */
943 if (infoPtr
->hwndCombo
)
944 if (SendMessageW (infoPtr
->hwndCombo
, CB_SETITEMHEIGHT
,
945 index
, height
) == CB_ERR
) return CB_ERR
;
947 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
948 GetWindowRect (infoPtr
->hwndSelf
, &cbx_wrect
);
949 GetClientRect (infoPtr
->hwndSelf
, &cbx_crect
);
950 /* the height of comboex as height of the combo + comboex border */
951 height
= cb_wrect
.bottom
-cb_wrect
.top
952 + cbx_wrect
.bottom
-cbx_wrect
.top
953 - (cbx_crect
.bottom
-cbx_crect
.top
);
954 TRACE("EX window=(%s), client=(%s)\n",
955 wine_dbgstr_rect(&cbx_wrect
), wine_dbgstr_rect(&cbx_crect
));
956 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
957 wine_dbgstr_rect(&cbx_wrect
), cbx_wrect
.right
-cbx_wrect
.left
, height
);
958 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0,
959 cbx_wrect
.right
-cbx_wrect
.left
, height
,
960 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOMOVE
);
966 /* *** WM_xxx message support *** */
969 static LRESULT
COMBOEX_Create (HWND hwnd
, CREATESTRUCTA
const *cs
)
971 static const WCHAR COMBOBOX
[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
972 static const WCHAR EDIT
[] = { 'E', 'D', 'I', 'T', 0 };
973 static const WCHAR NIL
[] = { 0 };
974 COMBOEX_INFO
*infoPtr
;
976 RECT wnrc1
, clrc1
, cmbwrc
;
979 /* allocate memory for info structure */
980 infoPtr
= Alloc (sizeof(COMBOEX_INFO
));
981 if (!infoPtr
) return -1;
983 /* initialize info structure */
984 /* note that infoPtr is allocated zero-filled */
986 infoPtr
->hwndSelf
= hwnd
;
987 infoPtr
->selected
= -1;
989 infoPtr
->unicode
= IsWindowUnicode (hwnd
);
990 infoPtr
->hwndNotify
= cs
->hwndParent
;
992 i
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
993 if ((i
!= NFR_ANSI
) && (i
!= NFR_UNICODE
)) {
994 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i
);
997 infoPtr
->NtfUnicode
= (i
== NFR_UNICODE
);
999 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1001 /* create combo box */
1002 GetWindowRect(hwnd
, &wnrc1
);
1003 GetClientRect(hwnd
, &clrc1
);
1004 TRACE("EX window=(%s), client=(%s)\n",
1005 wine_dbgstr_rect(&wnrc1
), wine_dbgstr_rect(&clrc1
));
1007 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1008 /* specified. It then creates it's own version of the EDIT control */
1009 /* and makes the ComboBox the parent. This is because a normal */
1010 /* DROPDOWNLIST does not have an EDIT control, but we need one. */
1011 /* We also need to place the edit control at the proper location */
1012 /* (allow space for the icons). */
1014 infoPtr
->hwndCombo
= CreateWindowW (COMBOBOX
, NIL
,
1015 /* following line added to match native */
1016 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| WS_VSCROLL
|
1017 CBS_NOINTEGRALHEIGHT
| CBS_DROPDOWNLIST
|
1018 /* was base and is necessary */
1019 WS_CHILD
| WS_VISIBLE
| CBS_OWNERDRAWFIXED
|
1020 GetWindowLongW (hwnd
, GWL_STYLE
),
1021 cs
->y
, cs
->x
, cs
->cx
, cs
->cy
, hwnd
,
1022 (HMENU
) GetWindowLongPtrW (hwnd
, GWLP_ID
),
1023 (HINSTANCE
)GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
), NULL
);
1026 * native does the following at this point according to trace:
1027 * GetWindowThreadProcessId(hwndCombo,0)
1028 * GetCurrentThreadId()
1029 * GetWindowThreadProcessId(hwndCombo, &???)
1030 * GetCurrentProcessId()
1034 * Setup a property to hold the pointer to the COMBOBOXEX
1037 SetPropW(infoPtr
->hwndCombo
, COMBOEX_SUBCLASS_PROP
, hwnd
);
1038 infoPtr
->prevComboWndProc
= (WNDPROC
)SetWindowLongPtrW(infoPtr
->hwndCombo
,
1039 GWLP_WNDPROC
, (DWORD_PTR
)COMBOEX_ComboWndProc
);
1040 infoPtr
->font
= (HFONT
)SendMessageW (infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
1044 * Now create our own EDIT control so we can position it.
1045 * It is created only for CBS_DROPDOWN style
1047 if ((cs
->style
& CBS_DROPDOWNLIST
) == CBS_DROPDOWN
) {
1048 infoPtr
->hwndEdit
= CreateWindowExW (0, EDIT
, NIL
,
1049 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| ES_AUTOHSCROLL
,
1050 0, 0, 0, 0, /* will set later */
1052 (HMENU
) GetWindowLongPtrW (hwnd
, GWLP_ID
),
1053 (HINSTANCE
)GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
), NULL
);
1055 /* native does the following at this point according to trace:
1056 * GetWindowThreadProcessId(hwndEdit,0)
1057 * GetCurrentThreadId()
1058 * GetWindowThreadProcessId(hwndEdit, &???)
1059 * GetCurrentProcessId()
1063 * Setup a property to hold the pointer to the COMBOBOXEX
1066 SetPropW(infoPtr
->hwndEdit
, COMBOEX_SUBCLASS_PROP
, hwnd
);
1067 infoPtr
->prevEditWndProc
= (WNDPROC
)SetWindowLongPtrW(infoPtr
->hwndEdit
,
1068 GWLP_WNDPROC
, (DWORD_PTR
)COMBOEX_EditWndProc
);
1069 infoPtr
->font
= (HFONT
)SendMessageW(infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
1073 * Locate the default font if necessary and then set it in
1074 * all associated controls
1076 if (!infoPtr
->font
) {
1077 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof(mylogfont
),
1079 infoPtr
->font
= infoPtr
->defaultFont
= CreateFontIndirectW (&mylogfont
);
1081 SendMessageW (infoPtr
->hwndCombo
, WM_SETFONT
, (WPARAM
)infoPtr
->font
, 0);
1082 if (infoPtr
->hwndEdit
) {
1083 SendMessageW (infoPtr
->hwndEdit
, WM_SETFONT
, (WPARAM
)infoPtr
->font
, 0);
1084 SendMessageW (infoPtr
->hwndEdit
, EM_SETMARGINS
, (WPARAM
)EC_USEFONTINFO
, 0);
1087 COMBOEX_ReSize (infoPtr
);
1089 /* Above is fairly certain, below is much less certain. */
1091 GetWindowRect(hwnd
, &wnrc1
);
1092 GetClientRect(hwnd
, &clrc1
);
1093 GetWindowRect(infoPtr
->hwndCombo
, &cmbwrc
);
1094 TRACE("EX window=(%s) client=(%s) CB wnd=(%s)\n",
1095 wine_dbgstr_rect(&wnrc1
), wine_dbgstr_rect(&clrc1
),
1096 wine_dbgstr_rect(&cmbwrc
));
1097 SetWindowPos(infoPtr
->hwndCombo
, HWND_TOP
,
1098 0, 0, wnrc1
.right
-wnrc1
.left
, wnrc1
.bottom
-wnrc1
.top
,
1099 SWP_NOACTIVATE
| SWP_NOREDRAW
);
1101 GetWindowRect(infoPtr
->hwndCombo
, &cmbwrc
);
1102 TRACE("CB window=(%s)\n", wine_dbgstr_rect(&cmbwrc
));
1103 SetWindowPos(hwnd
, HWND_TOP
,
1104 0, 0, cmbwrc
.right
-cmbwrc
.left
, cmbwrc
.bottom
-cmbwrc
.top
,
1105 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOMOVE
);
1107 COMBOEX_AdjustEditPos (infoPtr
);
1110 * Create an item structure to represent the data in the
1111 * EDIT control. It is allocated zero-filled.
1113 infoPtr
->edit
= Alloc (sizeof (CBE_ITEMDATA
));
1114 if (!infoPtr
->edit
) {
1115 COMBOEX_Destroy(infoPtr
);
1123 static LRESULT
COMBOEX_Command (COMBOEX_INFO
*infoPtr
, WPARAM wParam
)
1126 INT command
= HIWORD(wParam
);
1127 CBE_ITEMDATA
*item
= 0;
1131 NMCBEENDEDITW cbeend
;
1133 HWND parent
= infoPtr
->hwndNotify
;
1135 TRACE("for command %d\n", command
);
1140 SetFocus (infoPtr
->hwndCombo
);
1141 ShowWindow (infoPtr
->hwndEdit
, SW_HIDE
);
1142 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1145 SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1147 * from native trace of first dropdown after typing in URL in IE4
1148 * CB_GETCURSEL(Combo)
1149 * GetWindowText(Edit)
1150 * CB_GETCURSEL(Combo)
1151 * CB_GETCOUNT(Combo)
1152 * CB_GETITEMDATA(Combo, n)
1153 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1154 * CB_GETCURSEL(Combo)
1155 * CB_SETCURSEL(COMBOEX, n)
1157 * the rest is supposition
1159 ShowWindow (infoPtr
->hwndEdit
, SW_SHOW
);
1160 InvalidateRect (infoPtr
->hwndCombo
, 0, TRUE
);
1161 InvalidateRect (infoPtr
->hwndEdit
, 0, TRUE
);
1162 cursel
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1164 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
1165 /* find match from edit against those in Combobox */
1166 GetWindowTextW (infoPtr
->hwndEdit
, wintext
, 520);
1167 n
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCOUNT
, 0, 0);
1168 for (cursel
= 0; cursel
< n
; cursel
++){
1169 item
= get_item_data(infoPtr
, cursel
);
1170 if ((INT_PTR
)item
== CB_ERR
) break;
1171 if (!cmptext(COMBOEX_GetText(infoPtr
, item
), wintext
)) break;
1173 if ((cursel
== n
) || ((INT_PTR
)item
== CB_ERR
)) {
1174 TRACE("failed to find match??? item=%p cursel=%d\n",
1176 if (infoPtr
->hwndEdit
)
1177 SetFocus(infoPtr
->hwndEdit
);
1182 item
= get_item_data(infoPtr
, cursel
);
1183 if ((INT_PTR
)item
== CB_ERR
) {
1184 TRACE("failed to find match??? item=%p cursel=%d\n",
1186 if (infoPtr
->hwndEdit
)
1187 SetFocus(infoPtr
->hwndEdit
);
1192 /* Save flags for testing and reset them */
1193 oldflags
= infoPtr
->flags
;
1194 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1196 if (oldflags
& WCBE_ACTEDIT
) {
1197 cbeend
.fChanged
= (oldflags
& WCBE_EDITCHG
);
1198 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1199 CB_GETCURSEL
, 0, 0);
1200 cbeend
.iWhy
= CBENF_DROPDOWN
;
1202 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, COMBOEX_GetText(infoPtr
, item
))) return 0;
1205 /* if selection has changed the set the new current selection */
1206 cursel
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1207 if ((oldflags
& WCBE_EDITCHG
) || (cursel
!= infoPtr
->selected
)) {
1208 infoPtr
->selected
= cursel
;
1209 SendMessageW (infoPtr
->hwndSelf
, CB_SETCURSEL
, cursel
, 0);
1210 SetFocus(infoPtr
->hwndCombo
);
1216 * CB_GETCURSEL(Combo)
1217 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1220 * WM_GETTEXTLENGTH(Edit)
1222 * EM_SETSEL(Edit, 0,0)
1223 * WM_GETTEXTLENGTH(Edit)
1225 * EM_SETSEL(Edit, 0,len)
1226 * return WM_COMMAND to parent
1228 oldItem
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1229 if (!(item
= COMBOEX_FindItem(infoPtr
, oldItem
))) {
1230 ERR("item %ld not found. Problem!\n", oldItem
);
1233 infoPtr
->selected
= oldItem
;
1234 COMBOEX_SetEditText (infoPtr
, item
);
1235 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1238 case CBN_SELENDCANCEL
:
1240 * We have to change the handle since we are the control
1241 * issuing the message. IE4 depends on this.
1243 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1247 * from native trace:
1250 * WM_GETTEXT(Edit, 104)
1251 * CB_GETCURSEL(Combo) rets -1
1252 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1253 * CB_GETCURSEL(Combo)
1254 * InvalidateRect(Combo, 0, 0)
1257 SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1258 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1259 GetWindowTextW (infoPtr
->hwndEdit
, wintext
, 260);
1260 cbeend
.fChanged
= (infoPtr
->flags
& WCBE_EDITCHG
);
1261 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1262 CB_GETCURSEL
, 0, 0);
1263 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1265 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1266 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, wintext
)) return 0;
1268 /* possible CB_GETCURSEL */
1269 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1273 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1277 * We have to change the handle since we are the control
1278 * issuing the message. IE4 depends on this.
1279 * We also need to set the focus back to the Edit control
1280 * after passing the command to the parent of the ComboEx.
1282 lret
= SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1283 if (infoPtr
->hwndEdit
)
1284 SetFocus(infoPtr
->hwndEdit
);
1291 static BOOL
COMBOEX_WM_DeleteItem (COMBOEX_INFO
*infoPtr
, DELETEITEMSTRUCT
const *dis
)
1293 CBE_ITEMDATA
*item
, *olditem
;
1294 NMCOMBOBOXEXW nmcit
;
1297 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1298 dis
->CtlType
, dis
->CtlID
, dis
->itemID
, dis
->hwndItem
, dis
->itemData
);
1300 if (dis
->itemID
>= infoPtr
->nb_items
) return FALSE
;
1302 olditem
= infoPtr
->items
;
1303 i
= infoPtr
->nb_items
- 1;
1305 if (i
== dis
->itemID
) {
1306 infoPtr
->items
= infoPtr
->items
->next
;
1312 /* find the prior item in the list */
1313 while (item
->next
&& (i
> dis
->itemID
)) {
1317 if (!item
->next
|| (i
!= dis
->itemID
)) {
1318 ERR("COMBOBOXEX item structures broken. Please report!\n");
1321 olditem
= item
->next
;
1322 item
->next
= item
->next
->next
;
1324 infoPtr
->nb_items
--;
1326 memset (&nmcit
.ceItem
, 0, sizeof(nmcit
.ceItem
));
1327 COMBOEX_CopyItem (olditem
, &nmcit
.ceItem
);
1328 COMBOEX_NotifyItem (infoPtr
, CBEN_DELETEITEM
, &nmcit
);
1330 COMBOEX_FreeText(olditem
);
1337 static LRESULT
COMBOEX_DrawItem (COMBOEX_INFO
*infoPtr
, DRAWITEMSTRUCT
const *dis
)
1339 static const WCHAR nil
[] = { 0 };
1340 CBE_ITEMDATA
*item
= 0;
1346 COLORREF nbkc
, ntxc
, bkc
, txc
;
1347 int drawimage
, drawstate
, xioff
;
1349 if (!IsWindowEnabled(infoPtr
->hwndCombo
)) return 0;
1351 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1352 dis
->CtlType
, dis
->CtlID
);
1353 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1354 dis
->itemID
, dis
->itemAction
, dis
->itemState
);
1355 TRACE("hWnd=%p hDC=%p (%s) itemData=0x%08lx\n",
1356 dis
->hwndItem
, dis
->hDC
, wine_dbgstr_rect(&dis
->rcItem
), dis
->itemData
);
1359 /* "itemID - Specifies the menu item identifier for a menu */
1360 /* item or the index of the item in a list box or combo box. */
1361 /* For an empty list box or combo box, this member can be -1. */
1362 /* This allows the application to draw only the focus */
1363 /* rectangle at the coordinates specified by the rcItem */
1364 /* member even though there are no items in the control. */
1365 /* This indicates to the user whether the list box or combo */
1366 /* box has the focus. How the bits are set in the itemAction */
1367 /* member determines whether the rectangle is to be drawn as */
1368 /* though the list box or combo box has the focus. */
1369 if (dis
->itemID
== 0xffffffff) {
1370 if ( ( (dis
->itemAction
& ODA_FOCUS
) && (dis
->itemState
& ODS_SELECTED
)) ||
1371 ( (dis
->itemAction
& (ODA_SELECT
| ODA_DRAWENTIRE
)) && (dis
->itemState
& ODS_FOCUS
) ) ) {
1373 TRACE("drawing item -1 special focus, rect=(%s)\n",
1374 wine_dbgstr_rect(&dis
->rcItem
));
1376 else if ((dis
->CtlType
== ODT_COMBOBOX
) &&
1377 (dis
->itemAction
== ODA_DRAWENTIRE
)) {
1378 /* draw of edit control data */
1382 RECT exrc
, cbrc
, edrc
;
1383 GetWindowRect (infoPtr
->hwndSelf
, &exrc
);
1384 GetWindowRect (infoPtr
->hwndCombo
, &cbrc
);
1385 edrc
.left
=edrc
.top
=edrc
.right
=edrc
.bottom
=-1;
1386 if (infoPtr
->hwndEdit
)
1387 GetWindowRect (infoPtr
->hwndEdit
, &edrc
);
1388 TRACE("window rects ex=(%s), cb=(%s), ed=(%s)\n",
1389 wine_dbgstr_rect(&exrc
), wine_dbgstr_rect(&cbrc
),
1390 wine_dbgstr_rect(&edrc
));
1394 ERR("NOT drawing item -1 special focus, rect=(%s), action=%08x, state=%08x\n",
1395 wine_dbgstr_rect(&dis
->rcItem
),
1396 dis
->itemAction
, dis
->itemState
);
1401 /* If draw item is -1 (edit control) setup the item pointer */
1402 if (dis
->itemID
== 0xffffffff) {
1403 item
= infoPtr
->edit
;
1405 if (infoPtr
->hwndEdit
) {
1408 /* free previous text of edit item */
1409 COMBOEX_FreeText(item
);
1410 item
->mask
&= ~CBEIF_TEXT
;
1411 if( (len
= GetWindowTextLengthW(infoPtr
->hwndEdit
)) ) {
1412 item
->mask
|= CBEIF_TEXT
;
1413 item
->pszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1415 GetWindowTextW(infoPtr
->hwndEdit
, item
->pszText
, len
+1);
1417 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1418 infoPtr
->hwndEdit
, len
, debugstr_txt(item
->pszText
));
1424 /* if the item pointer is not set, then get the data and locate it */
1426 item
= get_item_data(infoPtr
, dis
->itemID
);
1427 if (item
== (CBE_ITEMDATA
*)CB_ERR
) {
1428 ERR("invalid item for id %d\n", dis
->itemID
);
1433 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
1435 xbase
= CBE_STARTOFFSET
;
1436 if ((item
->mask
& CBEIF_INDENT
) && (dis
->itemState
& ODS_COMBOEXLBOX
)) {
1437 INT indent
= item
->iIndent
;
1438 if (indent
== I_INDENTCALLBACK
) {
1440 ZeroMemory(&nmce
, sizeof(nmce
));
1441 nmce
.ceItem
.mask
= CBEIF_INDENT
;
1442 nmce
.ceItem
.lParam
= item
->lParam
;
1443 nmce
.ceItem
.iItem
= dis
->itemID
;
1444 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1445 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
1446 item
->iIndent
= nmce
.ceItem
.iIndent
;
1447 indent
= nmce
.ceItem
.iIndent
;
1449 xbase
+= (indent
* CBE_INDENT
);
1453 drawstate
= ILD_NORMAL
;
1454 if (item
->mask
& CBEIF_IMAGE
)
1455 drawimage
= item
->iImage
;
1456 if (dis
->itemState
& ODS_COMBOEXLBOX
) {
1457 /* drawing listbox entry */
1458 if (dis
->itemState
& ODS_SELECTED
) {
1459 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1460 drawimage
= item
->iSelectedImage
;
1461 drawstate
= ILD_SELECTED
;
1464 /* drawing combo/edit entry */
1465 if (IsWindowVisible(infoPtr
->hwndEdit
)) {
1466 /* if we have an edit control, the slave the
1467 * selection state to the Edit focus state
1469 if (infoPtr
->flags
& WCBE_EDITFOCUSED
) {
1470 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1471 drawimage
= item
->iSelectedImage
;
1472 drawstate
= ILD_SELECTED
;
1475 /* if we don't have an edit control, use
1476 * the requested state.
1478 if (dis
->itemState
& ODS_SELECTED
) {
1479 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1480 drawimage
= item
->iSelectedImage
;
1481 drawstate
= ILD_SELECTED
;
1486 if (infoPtr
->himl
&& !(infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGEINDENT
)) {
1488 iinfo
.rcImage
.left
= iinfo
.rcImage
.right
= 0;
1489 ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
);
1490 xioff
= iinfo
.rcImage
.right
- iinfo
.rcImage
.left
+ CBE_SEP
;
1493 /* setup pointer to text to be drawn */
1494 str
= COMBOEX_GetText(infoPtr
, item
);
1495 if (!str
) str
= nil
;
1497 len
= strlenW (str
);
1498 GetTextExtentPoint32W (dis
->hDC
, str
, len
, &txtsize
);
1500 if (dis
->itemAction
& (ODA_SELECT
| ODA_DRAWENTIRE
)) {
1501 int overlay
= item
->iOverlay
;
1503 if (drawimage
== I_IMAGECALLBACK
) {
1505 ZeroMemory(&nmce
, sizeof(nmce
));
1506 nmce
.ceItem
.mask
= (drawstate
== ILD_NORMAL
) ? CBEIF_IMAGE
: CBEIF_SELECTEDIMAGE
;
1507 nmce
.ceItem
.lParam
= item
->lParam
;
1508 nmce
.ceItem
.iItem
= dis
->itemID
;
1509 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1510 if (drawstate
== ILD_NORMAL
) {
1511 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) item
->iImage
= nmce
.ceItem
.iImage
;
1512 drawimage
= nmce
.ceItem
.iImage
;
1513 } else if (drawstate
== ILD_SELECTED
) {
1514 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) item
->iSelectedImage
= nmce
.ceItem
.iSelectedImage
;
1515 drawimage
= nmce
.ceItem
.iSelectedImage
;
1516 } else ERR("Bad draw state = %d\n", drawstate
);
1519 if (overlay
== I_IMAGECALLBACK
) {
1521 ZeroMemory(&nmce
, sizeof(nmce
));
1522 nmce
.ceItem
.mask
= CBEIF_OVERLAY
;
1523 nmce
.ceItem
.lParam
= item
->lParam
;
1524 nmce
.ceItem
.iItem
= dis
->itemID
;
1525 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1526 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
1527 item
->iOverlay
= nmce
.ceItem
.iOverlay
;
1528 overlay
= nmce
.ceItem
.iOverlay
;
1531 if (drawimage
>= 0 &&
1532 !(infoPtr
->dwExtStyle
& (CBES_EX_NOEDITIMAGE
| CBES_EX_NOEDITIMAGEINDENT
))) {
1533 if (overlay
> 0) ImageList_SetOverlayImage (infoPtr
->himl
, overlay
, 1);
1534 ImageList_Draw (infoPtr
->himl
, drawimage
, dis
->hDC
, xbase
, dis
->rcItem
.top
,
1535 drawstate
| (overlay
> 0 ? INDEXTOOVERLAYMASK(1) : 0));
1538 /* now draw the text */
1539 if (!IsWindowVisible (infoPtr
->hwndEdit
)) {
1540 nbkc
= (dis
->itemState
& ODS_SELECTED
) ?
1541 comctl32_color
.clrHighlight
: comctl32_color
.clrWindow
;
1542 bkc
= SetBkColor (dis
->hDC
, nbkc
);
1543 ntxc
= (dis
->itemState
& ODS_SELECTED
) ?
1544 comctl32_color
.clrHighlightText
: comctl32_color
.clrWindowText
;
1545 txc
= SetTextColor (dis
->hDC
, ntxc
);
1547 y
= dis
->rcItem
.top
+
1548 (dis
->rcItem
.bottom
- dis
->rcItem
.top
- txtsize
.cy
) / 2;
1550 rect
.right
= x
+ txtsize
.cx
;
1551 rect
.top
= dis
->rcItem
.top
+ 1;
1552 rect
.bottom
= dis
->rcItem
.bottom
- 1;
1553 TRACE("drawing item %d text, rect=(%s)\n",
1554 dis
->itemID
, wine_dbgstr_rect(&rect
));
1555 ExtTextOutW (dis
->hDC
, x
, y
, ETO_OPAQUE
| ETO_CLIPPED
,
1556 &rect
, str
, len
, 0);
1557 SetBkColor (dis
->hDC
, bkc
);
1558 SetTextColor (dis
->hDC
, txc
);
1562 if (dis
->itemAction
& ODA_FOCUS
) {
1563 rect
.left
= xbase
+ xioff
- 1;
1564 rect
.right
= rect
.left
+ txtsize
.cx
+ 2;
1565 rect
.top
= dis
->rcItem
.top
;
1566 rect
.bottom
= dis
->rcItem
.bottom
;
1567 DrawFocusRect(dis
->hDC
, &rect
);
1574 static void COMBOEX_ResetContent (COMBOEX_INFO
*infoPtr
)
1578 CBE_ITEMDATA
*item
, *next
;
1580 item
= infoPtr
->items
;
1583 COMBOEX_FreeText (item
);
1590 infoPtr
->selected
= -1;
1591 infoPtr
->nb_items
= 0;
1595 static LRESULT
COMBOEX_Destroy (COMBOEX_INFO
*infoPtr
)
1597 if (infoPtr
->hwndCombo
)
1598 DestroyWindow (infoPtr
->hwndCombo
);
1600 Free (infoPtr
->edit
);
1603 COMBOEX_ResetContent (infoPtr
);
1605 if (infoPtr
->defaultFont
)
1606 DeleteObject (infoPtr
->defaultFont
);
1608 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1610 /* free comboex info data */
1617 static LRESULT
COMBOEX_MeasureItem (COMBOEX_INFO
const *infoPtr
, MEASUREITEMSTRUCT
*mis
)
1619 static const WCHAR strW
[] = { 'W', 0 };
1624 GetTextExtentPointW (hdc
, strW
, 1, &mysize
);
1626 mis
->itemHeight
= mysize
.cy
+ CBE_EXTRA
;
1628 TRACE("adjusted height hwnd=%p, height=%d\n",
1629 infoPtr
->hwndSelf
, mis
->itemHeight
);
1635 static LRESULT
COMBOEX_NCCreate (HWND hwnd
)
1637 /* WARNING: The COMBOEX_INFO structure is not yet created */
1638 DWORD oldstyle
, newstyle
;
1640 oldstyle
= (DWORD
)GetWindowLongW (hwnd
, GWL_STYLE
);
1641 newstyle
= oldstyle
& ~(WS_VSCROLL
| WS_HSCROLL
| WS_BORDER
);
1642 if (newstyle
!= oldstyle
) {
1643 TRACE("req style %08x, resetting style %08x\n",
1644 oldstyle
, newstyle
);
1645 SetWindowLongW (hwnd
, GWL_STYLE
, newstyle
);
1651 static LRESULT
COMBOEX_NotifyFormat (COMBOEX_INFO
*infoPtr
, LPARAM lParam
)
1653 if (lParam
== NF_REQUERY
) {
1654 INT i
= SendMessageW(infoPtr
->hwndNotify
,
1655 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1656 infoPtr
->NtfUnicode
= (i
== NFR_UNICODE
) ? 1 : 0;
1658 return infoPtr
->NtfUnicode
? NFR_UNICODE
: NFR_ANSI
;
1662 static LRESULT
COMBOEX_Size (COMBOEX_INFO
*infoPtr
, INT width
, INT height
)
1664 TRACE("(width=%d, height=%d)\n", width
, height
);
1666 MoveWindow (infoPtr
->hwndCombo
, 0, 0, width
, height
, TRUE
);
1668 COMBOEX_AdjustEditPos (infoPtr
);
1674 static LRESULT
COMBOEX_SetRedraw(COMBOEX_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1676 LRESULT ret
= DefWindowProcW( infoPtr
->hwndSelf
, WM_SETREDRAW
, wParam
, lParam
);
1677 if (wParam
) RedrawWindow( infoPtr
->hwndSelf
, NULL
, 0, RDW_INVALIDATE
|RDW_ERASE
|RDW_ALLCHILDREN
);
1682 static LRESULT
COMBOEX_WindowPosChanging (COMBOEX_INFO
*infoPtr
, WINDOWPOS
*wp
)
1684 RECT cbx_wrect
, cbx_crect
, cb_wrect
;
1687 GetWindowRect (infoPtr
->hwndSelf
, &cbx_wrect
);
1688 GetClientRect (infoPtr
->hwndSelf
, &cbx_crect
);
1689 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
1691 /* width is winpos value + border width of comboex */
1693 + (cbx_wrect
.right
-cbx_wrect
.left
)
1694 - (cbx_crect
.right
-cbx_crect
.left
);
1696 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1697 wp
->x
, wp
->y
, wp
->cx
, wp
->cy
, wp
->flags
);
1698 TRACE("EX window=(%s), client=(%s)\n",
1699 wine_dbgstr_rect(&cbx_wrect
), wine_dbgstr_rect(&cbx_crect
));
1700 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
1701 wine_dbgstr_rect(&cbx_wrect
), width
, cb_wrect
.bottom
-cb_wrect
.top
);
1703 if (width
) SetWindowPos (infoPtr
->hwndCombo
, HWND_TOP
, 0, 0,
1705 cb_wrect
.bottom
-cb_wrect
.top
,
1708 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
1710 /* height is combo window height plus border width of comboex */
1711 height
= (cb_wrect
.bottom
-cb_wrect
.top
)
1712 + (cbx_wrect
.bottom
-cbx_wrect
.top
)
1713 - (cbx_crect
.bottom
-cbx_crect
.top
);
1714 if (wp
->cy
< height
) wp
->cy
= height
;
1715 if (infoPtr
->hwndEdit
) {
1716 COMBOEX_AdjustEditPos (infoPtr
);
1717 InvalidateRect (infoPtr
->hwndCombo
, 0, TRUE
);
1723 static LRESULT WINAPI
1724 COMBOEX_EditWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1726 HWND hwndComboex
= GetPropW(hwnd
, COMBOEX_SUBCLASS_PROP
);
1727 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwndComboex
);
1728 NMCBEENDEDITW cbeend
;
1729 WCHAR edit_text
[260];
1735 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1736 hwnd
, uMsg
, wParam
, lParam
, infoPtr
);
1738 if (!infoPtr
) return 0;
1744 /* handle (ignore) the return character */
1745 if (wParam
== VK_RETURN
) return 0;
1746 /* all other characters pass into the real Edit */
1747 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1748 hwnd
, uMsg
, wParam
, lParam
);
1752 * The following was determined by traces of the native
1755 obkc
= SetBkColor (hDC
, comctl32_color
.clrWindow
);
1756 GetClientRect (hwnd
, &rect
);
1757 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect
));
1758 ExtTextOutW (hDC
, 0, 0, ETO_OPAQUE
, &rect
, 0, 0, 0);
1759 SetBkColor (hDC
, obkc
);
1760 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1761 hwnd
, uMsg
, wParam
, lParam
);
1764 INT_PTR oldItem
, selected
, step
= 1;
1767 switch ((INT
)wParam
)
1770 /* native version seems to do following for COMBOEX */
1772 * GetWindowTextW(Edit,&?, 0x104) x
1773 * CB_GETCURSEL to Combo rets -1 x
1774 * WM_NOTIFY to COMBOEX parent (rebar) x
1775 * (CBEN_ENDEDIT{A|W}
1776 * fChanged = FALSE x
1777 * inewSelection = -1 x
1780 * CB_GETCURSEL to Combo rets -1 x
1781 * InvalidateRect(Combo, 0) x
1782 * WM_SETTEXT to Edit x
1783 * EM_SETSEL to Edit (0,0) x
1784 * EM_SETSEL to Edit (0,-1) x
1785 * RedrawWindow(Combo, 0, 0, 5) x
1787 TRACE("special code for VK_ESCAPE\n");
1789 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1791 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1792 cbeend
.fChanged
= FALSE
;
1793 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1794 CB_GETCURSEL
, 0, 0);
1795 cbeend
.iWhy
= CBENF_ESCAPE
;
1797 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) return 0;
1798 oldItem
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1799 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1800 if (!(item
= COMBOEX_FindItem(infoPtr
, oldItem
))) {
1801 ERR("item %ld not found. Problem!\n", oldItem
);
1804 infoPtr
->selected
= oldItem
;
1805 COMBOEX_SetEditText (infoPtr
, item
);
1806 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
|
1811 /* native version seems to do following for COMBOEX */
1813 * GetWindowTextW(Edit,&?, 0x104) x
1814 * CB_GETCURSEL to Combo rets -1 x
1815 * CB_GETCOUNT to Combo rets 0
1817 * CB_GETITEMDATA to match
1818 * *** above 3 lines simulated by FindItem x
1819 * WM_NOTIFY to COMBOEX parent (rebar) x
1820 * (CBEN_ENDEDIT{A|W} x
1821 * fChanged = TRUE (-1) x
1822 * iNewSelection = -1 or selected x
1824 * iWhy = 2 (CBENF_RETURN) x
1825 * CB_GETCURSEL to Combo rets -1 x
1826 * if -1 send CB_SETCURSEL to Combo -1 x
1827 * InvalidateRect(Combo, 0, 0) x
1829 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1832 TRACE("special code for VK_RETURN\n");
1834 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1836 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1837 selected
= SendMessageW (infoPtr
->hwndCombo
,
1838 CB_GETCURSEL
, 0, 0);
1840 if (selected
!= -1) {
1841 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
1842 item
= COMBOEX_FindItem (infoPtr
, selected
);
1843 TRACE("handling VK_RETURN, selected = %ld, selected_text=%s\n",
1844 selected
, debugstr_txt(item
->pszText
));
1845 TRACE("handling VK_RETURN, edittext=%s\n",
1846 debugstr_w(edit_text
));
1847 if (cmptext (COMBOEX_GetText(infoPtr
, item
), edit_text
)) {
1848 /* strings not equal -- indicate edit has changed */
1853 cbeend
.iNewSelection
= selected
;
1854 cbeend
.fChanged
= TRUE
;
1855 cbeend
.iWhy
= CBENF_RETURN
;
1856 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) {
1857 /* abort the change, restore previous */
1858 TRACE("Notify requested abort of change\n");
1859 COMBOEX_SetEditText (infoPtr
, infoPtr
->edit
);
1860 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
|
1864 oldItem
= SendMessageW (infoPtr
->hwndCombo
,CB_GETCURSEL
, 0, 0);
1865 if (oldItem
!= -1) {
1866 /* if something is selected, then deselect it */
1867 SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
,
1870 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1871 SetFocus(infoPtr
->hwndEdit
);
1877 /* by default, step is 1 */
1878 oldItem
= SendMessageW (infoPtr
->hwndSelf
, CB_GETCURSEL
, 0, 0);
1879 if (oldItem
>= 0 && oldItem
+ step
>= 0)
1880 SendMessageW (infoPtr
->hwndSelf
, CB_SETCURSEL
, oldItem
+ step
, 0);
1883 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1884 hwnd
, uMsg
, wParam
, lParam
);
1890 /* remember the focus to set state of icon */
1891 lret
= CallWindowProcW (infoPtr
->prevEditWndProc
,
1892 hwnd
, uMsg
, wParam
, lParam
);
1893 infoPtr
->flags
|= WCBE_EDITFOCUSED
;
1898 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1900 infoPtr
->flags
&= ~WCBE_EDITFOCUSED
;
1901 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1902 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1904 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1905 cbeend
.fChanged
= FALSE
;
1906 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1907 CB_GETCURSEL
, 0, 0);
1908 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1910 COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
);
1915 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1916 hwnd
, uMsg
, wParam
, lParam
);
1921 static LRESULT WINAPI
1922 COMBOEX_ComboWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1924 HWND hwndComboex
= GetPropW(hwnd
, COMBOEX_SUBCLASS_PROP
);
1925 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwndComboex
);
1926 NMCBEENDEDITW cbeend
;
1933 WCHAR edit_text
[260];
1935 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1936 hwnd
, uMsg
, wParam
, lParam
, infoPtr
);
1938 if (!infoPtr
) return 0;
1945 * The only way this message should come is from the
1946 * child Listbox issuing the message. Flag this so
1947 * that ComboEx knows this is listbox.
1949 ((DRAWITEMSTRUCT
*)lParam
)->itemState
|= ODS_COMBOEXLBOX
;
1950 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1951 hwnd
, uMsg
, wParam
, lParam
);
1955 * The following was determined by traces of the native
1958 obkc
= SetBkColor (hDC
, comctl32_color
.clrWindow
);
1959 GetClientRect (hwnd
, &rect
);
1960 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect
));
1961 ExtTextOutW (hDC
, 0, 0, ETO_OPAQUE
, &rect
, 0, 0, 0);
1962 SetBkColor (hDC
, obkc
);
1963 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1964 hwnd
, uMsg
, wParam
, lParam
);
1968 * WM_NOTIFY to comboex parent (rebar)
1969 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1970 * CallWindowProc (previous)
1972 nmmse
.dwItemSpec
= 0;
1973 nmmse
.dwItemData
= 0;
1976 nmmse
.dwHitInfo
= lParam
;
1977 COMBOEX_Notify (infoPtr
, NM_SETCURSOR
, (NMHDR
*)&nmmse
);
1978 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1979 hwnd
, uMsg
, wParam
, lParam
);
1981 case WM_LBUTTONDOWN
:
1982 GetClientRect (hwnd
, &rect
);
1983 rect
.bottom
= rect
.top
+ SendMessageW(infoPtr
->hwndSelf
,
1984 CB_GETITEMHEIGHT
, -1, 0);
1985 rect
.left
= rect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1986 pt
.x
= (short)LOWORD(lParam
);
1987 pt
.y
= (short)HIWORD(lParam
);
1988 if (PtInRect(&rect
, pt
))
1989 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1990 hwnd
, uMsg
, wParam
, lParam
);
1991 infoPtr
->flags
|= WCBE_MOUSECAPTURED
;
1996 if (!(infoPtr
->flags
& WCBE_MOUSECAPTURED
))
1997 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1998 hwnd
, uMsg
, wParam
, lParam
);
2000 infoPtr
->flags
&= ~WCBE_MOUSECAPTURED
;
2001 if (infoPtr
->flags
& WCBE_MOUSEDRAGGED
) {
2002 infoPtr
->flags
&= ~WCBE_MOUSEDRAGGED
;
2004 SendMessageW(hwnd
, CB_SHOWDROPDOWN
, TRUE
, 0);
2009 if ( (infoPtr
->flags
& WCBE_MOUSECAPTURED
) &&
2010 !(infoPtr
->flags
& WCBE_MOUSEDRAGGED
)) {
2011 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
2012 COMBOEX_NotifyDragBegin(infoPtr
, edit_text
);
2013 infoPtr
->flags
|= WCBE_MOUSEDRAGGED
;
2015 return CallWindowProcW (infoPtr
->prevComboWndProc
,
2016 hwnd
, uMsg
, wParam
, lParam
);
2019 switch (HIWORD(wParam
)) {
2022 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2031 * GetFocus() retns AA
2032 * GetWindowTextW(Edit)
2033 * CB_GETCURSEL(Combo) (got -1)
2034 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2035 * CB_GETCURSEL(Combo) (got -1)
2036 * InvalidateRect(Combo, 0, 0)
2037 * WM_KILLFOCUS(Combo, AA)
2040 focusedhwnd
= GetFocus();
2041 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
2042 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
2043 cbeend
.fChanged
= (infoPtr
->flags
& WCBE_EDITCHG
);
2044 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
2045 CB_GETCURSEL
, 0, 0);
2046 cbeend
.iWhy
= CBENF_KILLFOCUS
;
2048 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
2049 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) return 0;
2051 /* possible CB_GETCURSEL */
2052 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
2054 SendMessageW (infoPtr
->hwndCombo
, WM_KILLFOCUS
,
2055 (WPARAM
)focusedhwnd
, 0);
2060 * For EN_SETFOCUS this issues the same calls and messages
2061 * as the native seems to do.
2063 * for some cases however native does the following:
2064 * (noticed after SetFocus during LBUTTONDOWN on
2065 * on dropdown arrow)
2066 * WM_GETTEXTLENGTH (Edit);
2067 * WM_GETTEXT (Edit, len+1, str);
2068 * EM_SETSEL (Edit, 0, 0);
2069 * WM_GETTEXTLENGTH (Edit);
2070 * WM_GETTEXT (Edit, len+1, str);
2071 * EM_SETSEL (Edit, 0, len);
2072 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2076 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, 0);
2077 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
2078 COMBOEX_Notify (infoPtr
, CBEN_BEGINEDIT
, &hdr
);
2079 infoPtr
->flags
|= WCBE_ACTEDIT
;
2080 infoPtr
->flags
&= ~WCBE_EDITCHG
; /* no change yet */
2086 * For EN_CHANGE this issues the same calls and messages
2087 * as the native seems to do.
2089 WCHAR edit_text
[260];
2091 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
2093 INT_PTR selected
= SendMessageW (infoPtr
->hwndCombo
,
2094 CB_GETCURSEL
, 0, 0);
2096 /* lstrlenW( lastworkingURL ) */
2098 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
2099 if (selected
== -1) {
2100 lastwrk
= infoPtr
->edit
->pszText
;
2103 CBE_ITEMDATA
*item
= COMBOEX_FindItem (infoPtr
, selected
);
2104 lastwrk
= COMBOEX_GetText(infoPtr
, item
);
2107 TRACE("handling EN_CHANGE, selected = %ld, selected_text=%s\n",
2108 selected
, debugstr_w(lastwrk
));
2109 TRACE("handling EN_CHANGE, edittext=%s\n",
2110 debugstr_w(edit_text
));
2112 /* cmptext is between lastworkingURL and GetWindowText */
2113 if (cmptext (lastwrk
, edit_text
)) {
2114 /* strings not equal -- indicate edit has changed */
2115 infoPtr
->flags
|= WCBE_EDITCHG
;
2117 SendMessageW ( infoPtr
->hwndNotify
, WM_COMMAND
,
2118 MAKEWPARAM(GetDlgCtrlID (infoPtr
->hwndSelf
),
2120 (LPARAM
)infoPtr
->hwndSelf
);
2126 * Therefore from traces there is no additional code here
2130 * Using native COMCTL32 gets the following:
2131 * 1 == SHDOCVW.DLL issues call/message
2132 * 2 == COMCTL32.DLL issues call/message
2133 * 3 == WINE issues call/message
2136 * for LBN_SELCHANGE:
2137 * 1 CB_GETCURSEL(ComboEx)
2138 * 1 CB_GETDROPPEDSTATE(ComboEx)
2139 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2140 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2141 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2142 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2143 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2144 * 3 ShowWindow(ComboLB, SW_HIDE)
2145 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2146 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2148 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2149 * ? LB_GETCURSEL <==|
2151 * ? LB_GETTEXT | Needs to be added to
2152 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2153 * ? LB_GETITEMDATA |
2154 * ? WM_DRAWITEM(ComboEx) <==|
2160 return CallWindowProcW (infoPtr
->prevComboWndProc
,
2161 hwnd
, uMsg
, wParam
, lParam
);
2167 static LRESULT WINAPI
2168 COMBOEX_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2170 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwnd
);
2172 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2175 if (uMsg
== WM_CREATE
)
2176 return COMBOEX_Create (hwnd
, (LPCREATESTRUCTA
)lParam
);
2177 if (uMsg
== WM_NCCREATE
)
2178 COMBOEX_NCCreate (hwnd
);
2179 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2184 case CBEM_DELETEITEM
:
2185 return COMBOEX_DeleteItem (infoPtr
, wParam
);
2187 case CBEM_GETCOMBOCONTROL
:
2188 return (LRESULT
)infoPtr
->hwndCombo
;
2190 case CBEM_GETEDITCONTROL
:
2191 return (LRESULT
)infoPtr
->hwndEdit
;
2193 case CBEM_GETEXTENDEDSTYLE
:
2194 return infoPtr
->dwExtStyle
;
2196 case CBEM_GETIMAGELIST
:
2197 return (LRESULT
)infoPtr
->himl
;
2200 return (LRESULT
)COMBOEX_GetItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2203 return (LRESULT
)COMBOEX_GetItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2205 case CBEM_GETUNICODEFORMAT
:
2206 return infoPtr
->unicode
;
2208 case CBEM_HASEDITCHANGED
:
2209 return COMBOEX_HasEditChanged (infoPtr
);
2211 case CBEM_INSERTITEMA
:
2212 return COMBOEX_InsertItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2214 case CBEM_INSERTITEMW
:
2215 return COMBOEX_InsertItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2217 case CBEM_SETEXSTYLE
:
2218 case CBEM_SETEXTENDEDSTYLE
:
2219 return COMBOEX_SetExtendedStyle (infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
2221 case CBEM_SETIMAGELIST
:
2222 return (LRESULT
)COMBOEX_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2225 return COMBOEX_SetItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2228 return COMBOEX_SetItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2230 case CBEM_SETUNICODEFORMAT
:
2231 return COMBOEX_SetUnicodeFormat (infoPtr
, wParam
);
2233 /*case CBEM_SETWINDOWTHEME:
2234 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2238 case WM_GETTEXTLENGTH
:
2239 return SendMessageW(infoPtr
->hwndEdit
, uMsg
, wParam
, lParam
);
2242 return COMBOEX_GetListboxText(infoPtr
, wParam
, (LPWSTR
)lParam
);
2244 case CB_GETLBTEXTLEN
:
2245 return COMBOEX_GetListboxText(infoPtr
, wParam
, NULL
);
2247 case CB_RESETCONTENT
:
2248 COMBOEX_ResetContent(infoPtr
);
2251 /* Combo messages we are not sure if we need to process or just forward */
2252 case CB_GETDROPPEDCONTROLRECT
:
2253 case CB_GETITEMHEIGHT
:
2254 case CB_GETEXTENDEDUI
:
2256 case CB_SELECTSTRING
:
2258 /* Combo messages OK to just forward to the regular COMBO */
2261 case CB_GETDROPPEDSTATE
:
2262 case CB_SETDROPPEDWIDTH
:
2263 case CB_SETEXTENDEDUI
:
2264 case CB_SHOWDROPDOWN
:
2265 return SendMessageW (infoPtr
->hwndCombo
, uMsg
, wParam
, lParam
);
2267 /* Combo messages we need to process specially */
2268 case CB_FINDSTRINGEXACT
:
2269 return COMBOEX_FindStringExact (infoPtr
, (INT
)wParam
, (LPCWSTR
)lParam
);
2271 case CB_GETITEMDATA
:
2272 return COMBOEX_GetItemData (infoPtr
, (INT
)wParam
);
2275 return COMBOEX_SetCursel (infoPtr
, (INT
)wParam
);
2277 case CB_SETITEMDATA
:
2278 return COMBOEX_SetItemData (infoPtr
, (INT
)wParam
, (DWORD_PTR
)lParam
);
2280 case CB_SETITEMHEIGHT
:
2281 return COMBOEX_SetItemHeight (infoPtr
, (INT
)wParam
, (UINT
)lParam
);
2285 /* Window messages passed to parent */
2287 return COMBOEX_Command (infoPtr
, wParam
);
2290 if (infoPtr
->NtfUnicode
)
2291 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
2293 return SendMessageA (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
2296 /* Window messages we need to process */
2298 return COMBOEX_WM_DeleteItem (infoPtr
, (DELETEITEMSTRUCT
*)lParam
);
2301 return COMBOEX_DrawItem (infoPtr
, (DRAWITEMSTRUCT
*)lParam
);
2304 return COMBOEX_Destroy (infoPtr
);
2306 case WM_MEASUREITEM
:
2307 return COMBOEX_MeasureItem (infoPtr
, (MEASUREITEMSTRUCT
*)lParam
);
2309 case WM_NOTIFYFORMAT
:
2310 return COMBOEX_NotifyFormat (infoPtr
, lParam
);
2313 return COMBOEX_Size (infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
2316 return COMBOEX_SetRedraw(infoPtr
, wParam
, lParam
);
2318 case WM_WINDOWPOSCHANGING
:
2319 return COMBOEX_WindowPosChanging (infoPtr
, (WINDOWPOS
*)lParam
);
2322 SetFocus(infoPtr
->hwndCombo
);
2325 case WM_SYSCOLORCHANGE
:
2326 COMCTL32_RefreshSysColors();
2330 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2331 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",uMsg
,wParam
,lParam
);
2332 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2337 void COMBOEX_Register (void)
2341 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2342 wndClass
.style
= CS_GLOBALCLASS
;
2343 wndClass
.lpfnWndProc
= COMBOEX_WindowProc
;
2344 wndClass
.cbClsExtra
= 0;
2345 wndClass
.cbWndExtra
= sizeof(COMBOEX_INFO
*);
2346 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2347 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2348 wndClass
.lpszClassName
= WC_COMBOBOXEXW
;
2350 RegisterClassW (&wndClass
);
2354 void COMBOEX_Unregister (void)
2356 UnregisterClassW (WC_COMBOBOXEXW
, NULL
);