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=%d, 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
= (LPSTR
)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
= (LPWSTR
)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
= (HFONT
) 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 (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
, (WPARAM
)-1, (LPARAM
)cy
);
435 if (infoPtr
->hwndCombo
) {
436 SendMessageW (infoPtr
->hwndCombo
, CB_SETITEMHEIGHT
,
437 (WPARAM
) 0, (LPARAM
) cy
);
438 if ( !(infoPtr
->flags
& CBES_EX_NOSIZELIMIT
)) {
440 if (GetWindowRect(infoPtr
->hwndCombo
, &comboRect
)) {
442 if (GetWindowRect(infoPtr
->hwndSelf
, &ourRect
)) {
443 if (comboRect
.bottom
> ourRect
.bottom
) {
444 POINT pt
= { ourRect
.left
, ourRect
.top
};
445 if (ScreenToClient(infoPtr
->hwndSelf
, &pt
))
446 MoveWindow( infoPtr
->hwndSelf
, pt
.x
, pt
.y
, ourRect
.right
- ourRect
.left
,
447 comboRect
.bottom
- comboRect
.top
, FALSE
);
456 static void COMBOEX_SetEditText (COMBOEX_INFO
*infoPtr
, CBE_ITEMDATA
*item
)
458 if (!infoPtr
->hwndEdit
) return;
459 /* native issues the following messages to the {Edit} control */
460 /* WM_SETTEXT (0,addr) */
461 /* EM_SETSEL32 (0,0) */
462 /* EM_SETSEL32 (0,-1) */
463 if (item
->mask
& CBEIF_TEXT
) {
464 SendMessageW (infoPtr
->hwndEdit
, WM_SETTEXT
, 0, (LPARAM
)COMBOEX_GetText(infoPtr
, item
));
465 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, 0);
466 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
471 static CBE_ITEMDATA
* COMBOEX_FindItem(COMBOEX_INFO
*infoPtr
, INT index
)
476 if ((index
>= infoPtr
->nb_items
) || (index
< -1))
479 return infoPtr
->edit
;
480 item
= infoPtr
->items
;
481 i
= infoPtr
->nb_items
- 1;
483 /* find the item in the list */
484 while (item
&& (i
> index
)) {
488 if (!item
|| (i
!= index
)) {
489 ERR("COMBOBOXEX item structures broken. Please report!\n");
496 static inline BOOL
COMBOEX_HasEdit(COMBOEX_INFO
const *infoPtr
)
498 return infoPtr
->hwndEdit
? TRUE
: FALSE
;
502 /* *** CBEM_xxx message support *** */
504 static UINT
COMBOEX_GetListboxText(COMBOEX_INFO
*infoPtr
, int n
, LPWSTR buf
)
509 item
= COMBOEX_FindItem(infoPtr
, n
);
513 str
= COMBOEX_GetText(infoPtr
, item
);
515 if (infoPtr
->unicode
)
519 return lstrlenW(str
);
524 r
= WideCharToMultiByte(CP_ACP
, 0, str
, -1, (LPSTR
)buf
, 0x40000000, NULL
, NULL
);
531 static INT
COMBOEX_DeleteItem (COMBOEX_INFO
*infoPtr
, INT index
)
533 TRACE("(index=%d)\n", index
);
535 /* if item number requested does not exist then return failure */
536 if ((index
>= infoPtr
->nb_items
) || (index
< 0)) return CB_ERR
;
537 if (!COMBOEX_FindItem(infoPtr
, index
)) return CB_ERR
;
539 /* doing this will result in WM_DELETEITEM being issued */
540 SendMessageW (infoPtr
->hwndCombo
, CB_DELETESTRING
, (WPARAM
)index
, 0);
542 return infoPtr
->nb_items
;
546 static BOOL
COMBOEX_GetItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
*cit
)
548 INT index
= cit
->iItem
;
553 /* if item number requested does not exist then return failure */
554 if ((index
>= infoPtr
->nb_items
) || (index
< -1)) return FALSE
;
556 /* if the item is the edit control and there is no edit control, skip */
557 if ((index
== -1) && !COMBOEX_HasEdit(infoPtr
)) return FALSE
;
559 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return FALSE
;
561 COMBOEX_CopyItem (item
, cit
);
567 static BOOL
COMBOEX_GetItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
*cit
)
569 COMBOBOXEXITEMW tmpcit
;
573 tmpcit
.mask
= cit
->mask
;
574 tmpcit
.iItem
= cit
->iItem
;
576 if(!COMBOEX_GetItemW (infoPtr
, &tmpcit
)) return FALSE
;
578 if (cit
->mask
& CBEIF_TEXT
)
580 if (is_textW(tmpcit
.pszText
) && cit
->pszText
)
581 WideCharToMultiByte(CP_ACP
, 0, tmpcit
.pszText
, -1,
582 cit
->pszText
, cit
->cchTextMax
, NULL
, NULL
);
583 else if (cit
->pszText
) cit
->pszText
[0] = 0;
584 else cit
->pszText
= (LPSTR
)tmpcit
.pszText
;
587 if (cit
->mask
& CBEIF_IMAGE
)
588 cit
->iImage
= tmpcit
.iImage
;
589 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
590 cit
->iSelectedImage
= tmpcit
.iSelectedImage
;
591 if (cit
->mask
& CBEIF_OVERLAY
)
592 cit
->iOverlay
= tmpcit
.iOverlay
;
593 if (cit
->mask
& CBEIF_INDENT
)
594 cit
->iIndent
= tmpcit
.iIndent
;
595 if (cit
->mask
& CBEIF_LPARAM
)
596 cit
->lParam
= tmpcit
.lParam
;
602 static inline BOOL
COMBOEX_HasEditChanged (COMBOEX_INFO
const *infoPtr
)
604 return COMBOEX_HasEdit(infoPtr
) &&
605 (infoPtr
->flags
& WCBE_EDITHASCHANGED
) == WCBE_EDITHASCHANGED
;
609 static INT
COMBOEX_InsertItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
const *cit
)
617 if (TRACE_ON(comboex
)) COMBOEX_DumpInput (cit
);
619 /* get real index of item to insert */
621 if (index
== -1) index
= infoPtr
->nb_items
;
622 if (index
> infoPtr
->nb_items
) return -1;
624 /* get zero-filled space and chain it in */
625 if(!(item
= (CBE_ITEMDATA
*)Alloc (sizeof(*item
)))) return -1;
627 /* locate position to insert new item in */
628 if (index
== infoPtr
->nb_items
) {
629 /* fast path for iItem = -1 */
630 item
->next
= infoPtr
->items
;
631 infoPtr
->items
= item
;
634 INT i
= infoPtr
->nb_items
-1;
635 CBE_ITEMDATA
*moving
= infoPtr
->items
;
637 while ((i
> index
) && moving
) {
638 moving
= moving
->next
;
642 ERR("COMBOBOXEX item structures broken. Please report!\n");
646 item
->next
= moving
->next
;
650 /* fill in our hidden item structure */
651 item
->mask
= cit
->mask
;
652 if (item
->mask
& CBEIF_TEXT
) {
655 if (is_textW(cit
->pszText
)) len
= strlenW (cit
->pszText
);
657 item
->pszText
= (LPWSTR
)Alloc ((len
+ 1)*sizeof(WCHAR
));
658 if (!item
->pszText
) {
662 strcpyW (item
->pszText
, cit
->pszText
);
664 else if (cit
->pszText
== LPSTR_TEXTCALLBACKW
)
665 item
->pszText
= LPSTR_TEXTCALLBACKW
;
666 item
->cchTextMax
= cit
->cchTextMax
;
668 if (item
->mask
& CBEIF_IMAGE
)
669 item
->iImage
= cit
->iImage
;
670 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
671 item
->iSelectedImage
= cit
->iSelectedImage
;
672 if (item
->mask
& CBEIF_OVERLAY
)
673 item
->iOverlay
= cit
->iOverlay
;
674 if (item
->mask
& CBEIF_INDENT
)
675 item
->iIndent
= cit
->iIndent
;
676 if (item
->mask
& CBEIF_LPARAM
)
677 item
->lParam
= cit
->lParam
;
680 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
682 SendMessageW (infoPtr
->hwndCombo
, CB_INSERTSTRING
,
683 (WPARAM
)cit
->iItem
, (LPARAM
)item
);
685 memset (&nmcit
.ceItem
, 0, sizeof(nmcit
.ceItem
));
686 COMBOEX_CopyItem (item
, &nmcit
.ceItem
);
687 COMBOEX_NotifyItem (infoPtr
, CBEN_INSERTITEM
, &nmcit
);
694 static INT
COMBOEX_InsertItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
const *cit
)
696 COMBOBOXEXITEMW citW
;
700 memcpy(&citW
,cit
,sizeof(COMBOBOXEXITEMA
));
701 if (cit
->mask
& CBEIF_TEXT
&& is_textA(cit
->pszText
)) {
702 INT len
= MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, NULL
, 0);
703 wstr
= (LPWSTR
)Alloc ((len
+ 1)*sizeof(WCHAR
));
704 if (!wstr
) return -1;
705 MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, wstr
, len
);
708 ret
= COMBOEX_InsertItemW(infoPtr
, &citW
);
717 COMBOEX_SetExtendedStyle (COMBOEX_INFO
*infoPtr
, DWORD mask
, DWORD style
)
721 TRACE("(mask=x%08x, style=0x%08x)\n", mask
, style
);
723 dwTemp
= infoPtr
->dwExtStyle
;
726 infoPtr
->dwExtStyle
= (infoPtr
->dwExtStyle
& ~mask
) | style
;
728 infoPtr
->dwExtStyle
= style
;
730 /* see if we need to change the word break proc on the edit */
731 if ((infoPtr
->dwExtStyle
^ dwTemp
) & CBES_EX_PATHWORDBREAKPROC
)
732 SetPathWordBreakProc(infoPtr
->hwndEdit
,
733 (infoPtr
->dwExtStyle
& CBES_EX_PATHWORDBREAKPROC
) ? TRUE
: FALSE
);
735 /* test if the control's appearance has changed */
736 mask
= CBES_EX_NOEDITIMAGE
| CBES_EX_NOEDITIMAGEINDENT
;
737 if ((infoPtr
->dwExtStyle
& mask
) != (dwTemp
& mask
)) {
738 /* if state of EX_NOEDITIMAGE changes, invalidate all */
739 TRACE("EX_NOEDITIMAGE state changed to %d\n",
740 infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGE
);
741 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
742 COMBOEX_AdjustEditPos (infoPtr
);
743 if (infoPtr
->hwndEdit
)
744 InvalidateRect (infoPtr
->hwndEdit
, NULL
, TRUE
);
751 static HIMAGELIST
COMBOEX_SetImageList (COMBOEX_INFO
*infoPtr
, HIMAGELIST himl
)
753 HIMAGELIST himlTemp
= infoPtr
->himl
;
757 infoPtr
->himl
= himl
;
759 COMBOEX_ReSize (infoPtr
);
760 InvalidateRect (infoPtr
->hwndCombo
, NULL
, TRUE
);
762 /* reposition the Edit control based on whether icon exists */
763 COMBOEX_AdjustEditPos (infoPtr
);
767 static BOOL
COMBOEX_SetItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
*cit
)
769 INT index
= cit
->iItem
;
772 if (TRACE_ON(comboex
)) COMBOEX_DumpInput (cit
);
774 /* if item number requested does not exist then return failure */
775 if ((index
>= infoPtr
->nb_items
) || (index
< -1)) return FALSE
;
777 /* if the item is the edit control and there is no edit control, skip */
778 if ((index
== -1) && !COMBOEX_HasEdit(infoPtr
)) return FALSE
;
780 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return FALSE
;
782 /* add/change stuff to the internal item structure */
783 item
->mask
|= cit
->mask
;
784 if (cit
->mask
& CBEIF_TEXT
) {
787 COMBOEX_FreeText(item
);
788 if (is_textW(cit
->pszText
)) len
= strlenW(cit
->pszText
);
790 item
->pszText
= (LPWSTR
)Alloc ((len
+ 1)*sizeof(WCHAR
));
791 if (!item
->pszText
) return FALSE
;
792 strcpyW(item
->pszText
, cit
->pszText
);
793 } else if (cit
->pszText
== LPSTR_TEXTCALLBACKW
)
794 item
->pszText
= LPSTR_TEXTCALLBACKW
;
795 item
->cchTextMax
= cit
->cchTextMax
;
797 if (cit
->mask
& CBEIF_IMAGE
)
798 item
->iImage
= cit
->iImage
;
799 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
800 item
->iSelectedImage
= cit
->iSelectedImage
;
801 if (cit
->mask
& CBEIF_OVERLAY
)
802 item
->iOverlay
= cit
->iOverlay
;
803 if (cit
->mask
& CBEIF_INDENT
)
804 item
->iIndent
= cit
->iIndent
;
805 if (cit
->mask
& CBEIF_LPARAM
)
806 cit
->lParam
= cit
->lParam
;
808 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
810 /* if original request was to update edit control, do some fast foot work */
811 if (cit
->iItem
== -1) {
812 COMBOEX_SetEditText (infoPtr
, item
);
813 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
| RDW_INVALIDATE
);
818 static BOOL
COMBOEX_SetItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
const *cit
)
820 COMBOBOXEXITEMW citW
;
824 memcpy(&citW
, cit
, sizeof(COMBOBOXEXITEMA
));
825 if ((cit
->mask
& CBEIF_TEXT
) && is_textA(cit
->pszText
)) {
826 INT len
= MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, NULL
, 0);
827 wstr
= (LPWSTR
)Alloc ((len
+ 1)*sizeof(WCHAR
));
828 if (!wstr
) return FALSE
;
829 MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, wstr
, len
);
832 ret
= COMBOEX_SetItemW(infoPtr
, &citW
);
840 static BOOL
COMBOEX_SetUnicodeFormat (COMBOEX_INFO
*infoPtr
, BOOL value
)
842 BOOL bTemp
= infoPtr
->unicode
;
844 TRACE("to %s, was %s\n", value
? "TRUE":"FALSE", bTemp
? "TRUE":"FALSE");
846 infoPtr
->unicode
= value
;
852 /* *** CB_xxx message support *** */
855 COMBOEX_FindStringExact (COMBOEX_INFO
*infoPtr
, INT start
, LPCWSTR str
)
858 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
859 INT count
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCOUNT
, 0, 0);
861 /* now search from after starting loc and wrapping back to start */
862 for(i
=start
+1; i
<count
; i
++) {
863 CBE_ITEMDATA
*item
= get_item_data(infoPtr
, i
);
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 (cmptext(COMBOEX_GetText(infoPtr
, item
), str
) == 0) return i
;
874 static DWORD_PTR
COMBOEX_GetItemData (COMBOEX_INFO
*infoPtr
, INT index
)
876 CBE_ITEMDATA
const *item1
;
877 CBE_ITEMDATA
const *item2
;
880 item1
= get_item_data(infoPtr
, index
);
881 if ((item1
!= NULL
) && ((LRESULT
)item1
!= CB_ERR
)) {
882 item2
= COMBOEX_FindItem (infoPtr
, index
);
883 if (item2
!= item1
) {
884 ERR("data structures damaged!\n");
887 if (item1
->mask
& CBEIF_LPARAM
) ret
= item1
->lParam
;
888 TRACE("returning 0x%08lx\n", ret
);
890 ret
= (DWORD_PTR
)item1
;
891 TRACE("non-valid result from combo, returning 0x%08lx\n", ret
);
897 static INT
COMBOEX_SetCursel (COMBOEX_INFO
*infoPtr
, INT index
)
902 if (!(item
= COMBOEX_FindItem(infoPtr
, index
)))
903 return SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, index
, 0);
905 TRACE("selecting item %d text=%s\n", index
, debugstr_txt(item
->pszText
));
906 infoPtr
->selected
= index
;
908 sel
= (INT
)SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, index
, 0);
909 COMBOEX_SetEditText (infoPtr
, item
);
914 static DWORD_PTR
COMBOEX_SetItemData (COMBOEX_INFO
*infoPtr
, INT index
, DWORD_PTR data
)
917 CBE_ITEMDATA
const *item2
;
919 item1
= get_item_data(infoPtr
, index
);
920 if ((item1
!= NULL
) && ((LRESULT
)item1
!= CB_ERR
)) {
921 item2
= COMBOEX_FindItem (infoPtr
, index
);
922 if (item2
!= item1
) {
923 ERR("data structures damaged!\n");
926 item1
->mask
|= CBEIF_LPARAM
;
927 item1
->lParam
= data
;
928 TRACE("setting lparam to 0x%08lx\n", data
);
931 TRACE("non-valid result from combo %p\n", item1
);
932 return (DWORD_PTR
)item1
;
936 static INT
COMBOEX_SetItemHeight (COMBOEX_INFO
const *infoPtr
, INT index
, UINT height
)
938 RECT cb_wrect
, cbx_wrect
, cbx_crect
;
940 /* First, lets forward the message to the normal combo control
941 just like Windows. */
942 if (infoPtr
->hwndCombo
)
943 if (SendMessageW (infoPtr
->hwndCombo
, CB_SETITEMHEIGHT
,
944 index
, height
) == CB_ERR
) return CB_ERR
;
946 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
947 GetWindowRect (infoPtr
->hwndSelf
, &cbx_wrect
);
948 GetClientRect (infoPtr
->hwndSelf
, &cbx_crect
);
949 /* the height of comboex as height of the combo + comboex border */
950 height
= cb_wrect
.bottom
-cb_wrect
.top
951 + cbx_wrect
.bottom
-cbx_wrect
.top
952 - (cbx_crect
.bottom
-cbx_crect
.top
);
953 TRACE("EX window=(%s), client=(%s)\n",
954 wine_dbgstr_rect(&cbx_wrect
), wine_dbgstr_rect(&cbx_crect
));
955 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
956 wine_dbgstr_rect(&cbx_wrect
), cbx_wrect
.right
-cbx_wrect
.left
, height
);
957 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0,
958 cbx_wrect
.right
-cbx_wrect
.left
, height
,
959 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOMOVE
);
965 /* *** WM_xxx message support *** */
968 static LRESULT
COMBOEX_Create (HWND hwnd
, CREATESTRUCTA
const *cs
)
970 static const WCHAR COMBOBOX
[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
971 static const WCHAR EDIT
[] = { 'E', 'D', 'I', 'T', 0 };
972 static const WCHAR NIL
[] = { 0 };
973 COMBOEX_INFO
*infoPtr
;
975 RECT wnrc1
, clrc1
, cmbwrc
;
978 /* allocate memory for info structure */
979 infoPtr
= (COMBOEX_INFO
*)Alloc (sizeof(COMBOEX_INFO
));
980 if (!infoPtr
) return -1;
982 /* initialize info structure */
983 /* note that infoPtr is allocated zero-filled */
985 infoPtr
->hwndSelf
= hwnd
;
986 infoPtr
->selected
= -1;
988 infoPtr
->unicode
= IsWindowUnicode (hwnd
);
989 infoPtr
->hwndNotify
= cs
->hwndParent
;
991 i
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
992 if ((i
!= NFR_ANSI
) && (i
!= NFR_UNICODE
)) {
993 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i
);
996 infoPtr
->NtfUnicode
= (i
== NFR_UNICODE
);
998 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1000 /* create combo box */
1001 GetWindowRect(hwnd
, &wnrc1
);
1002 GetClientRect(hwnd
, &clrc1
);
1003 TRACE("EX window=(%s), client=(%s)\n",
1004 wine_dbgstr_rect(&wnrc1
), wine_dbgstr_rect(&clrc1
));
1006 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1007 /* specified. It then creates it's own version of the EDIT control */
1008 /* and makes the ComboBox the parent. This is because a normal */
1009 /* DROPDOWNLIST does not have an EDIT control, but we need one. */
1010 /* We also need to place the edit control at the proper location */
1011 /* (allow space for the icons). */
1013 infoPtr
->hwndCombo
= CreateWindowW (COMBOBOX
, NIL
,
1014 /* following line added to match native */
1015 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| WS_VSCROLL
|
1016 CBS_NOINTEGRALHEIGHT
| CBS_DROPDOWNLIST
|
1017 /* was base and is necessary */
1018 WS_CHILD
| WS_VISIBLE
| CBS_OWNERDRAWFIXED
|
1019 GetWindowLongW (hwnd
, GWL_STYLE
),
1020 cs
->y
, cs
->x
, cs
->cx
, cs
->cy
, hwnd
,
1021 (HMENU
) GetWindowLongPtrW (hwnd
, GWLP_ID
),
1022 (HINSTANCE
)GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
), NULL
);
1025 * native does the following at this point according to trace:
1026 * GetWindowThreadProcessId(hwndCombo,0)
1027 * GetCurrentThreadId()
1028 * GetWindowThreadProcessId(hwndCombo, &???)
1029 * GetCurrentProcessId()
1033 * Setup a property to hold the pointer to the COMBOBOXEX
1036 SetPropW(infoPtr
->hwndCombo
, COMBOEX_SUBCLASS_PROP
, hwnd
);
1037 infoPtr
->prevComboWndProc
= (WNDPROC
)SetWindowLongPtrW(infoPtr
->hwndCombo
,
1038 GWLP_WNDPROC
, (DWORD_PTR
)COMBOEX_ComboWndProc
);
1039 infoPtr
->font
= (HFONT
)SendMessageW (infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
1043 * Now create our own EDIT control so we can position it.
1044 * It is created only for CBS_DROPDOWN style
1046 if ((cs
->style
& CBS_DROPDOWNLIST
) == CBS_DROPDOWN
) {
1047 infoPtr
->hwndEdit
= CreateWindowExW (0, EDIT
, NIL
,
1048 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| ES_AUTOHSCROLL
,
1049 0, 0, 0, 0, /* will set later */
1051 (HMENU
) GetWindowLongPtrW (hwnd
, GWLP_ID
),
1052 (HINSTANCE
)GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
), NULL
);
1054 /* native does the following at this point according to trace:
1055 * GetWindowThreadProcessId(hwndEdit,0)
1056 * GetCurrentThreadId()
1057 * GetWindowThreadProcessId(hwndEdit, &???)
1058 * GetCurrentProcessId()
1062 * Setup a property to hold the pointer to the COMBOBOXEX
1065 SetPropW(infoPtr
->hwndEdit
, COMBOEX_SUBCLASS_PROP
, hwnd
);
1066 infoPtr
->prevEditWndProc
= (WNDPROC
)SetWindowLongPtrW(infoPtr
->hwndEdit
,
1067 GWLP_WNDPROC
, (DWORD_PTR
)COMBOEX_EditWndProc
);
1068 infoPtr
->font
= (HFONT
)SendMessageW(infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
1072 * Locate the default font if necessary and then set it in
1073 * all associated controls
1075 if (!infoPtr
->font
) {
1076 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof(mylogfont
),
1078 infoPtr
->font
= infoPtr
->defaultFont
= CreateFontIndirectW (&mylogfont
);
1080 SendMessageW (infoPtr
->hwndCombo
, WM_SETFONT
, (WPARAM
)infoPtr
->font
, 0);
1081 if (infoPtr
->hwndEdit
) {
1082 SendMessageW (infoPtr
->hwndEdit
, WM_SETFONT
, (WPARAM
)infoPtr
->font
, 0);
1083 SendMessageW (infoPtr
->hwndEdit
, EM_SETMARGINS
, (WPARAM
)EC_USEFONTINFO
, 0);
1086 COMBOEX_ReSize (infoPtr
);
1088 /* Above is fairly certain, below is much less certain. */
1090 GetWindowRect(hwnd
, &wnrc1
);
1091 GetClientRect(hwnd
, &clrc1
);
1092 GetWindowRect(infoPtr
->hwndCombo
, &cmbwrc
);
1093 TRACE("EX window=(%s) client=(%s) CB wnd=(%s)\n",
1094 wine_dbgstr_rect(&wnrc1
), wine_dbgstr_rect(&clrc1
),
1095 wine_dbgstr_rect(&cmbwrc
));
1096 SetWindowPos(infoPtr
->hwndCombo
, HWND_TOP
,
1097 0, 0, wnrc1
.right
-wnrc1
.left
, wnrc1
.bottom
-wnrc1
.top
,
1098 SWP_NOACTIVATE
| SWP_NOREDRAW
);
1100 GetWindowRect(infoPtr
->hwndCombo
, &cmbwrc
);
1101 TRACE("CB window=(%s)\n", wine_dbgstr_rect(&cmbwrc
));
1102 SetWindowPos(hwnd
, HWND_TOP
,
1103 0, 0, cmbwrc
.right
-cmbwrc
.left
, cmbwrc
.bottom
-cmbwrc
.top
,
1104 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOMOVE
);
1106 COMBOEX_AdjustEditPos (infoPtr
);
1109 * Create an item structure to represent the data in the
1110 * EDIT control. It is allocated zero-filled.
1112 infoPtr
->edit
= (CBE_ITEMDATA
*)Alloc (sizeof (CBE_ITEMDATA
));
1113 if (!infoPtr
->edit
) {
1114 COMBOEX_Destroy(infoPtr
);
1122 static LRESULT
COMBOEX_Command (COMBOEX_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1125 INT command
= HIWORD(wParam
);
1126 CBE_ITEMDATA
*item
= 0;
1128 INT cursel
, n
, oldItem
;
1129 NMCBEENDEDITW cbeend
;
1131 HWND parent
= infoPtr
->hwndNotify
;
1133 TRACE("for command %d\n", command
);
1138 SetFocus (infoPtr
->hwndCombo
);
1139 ShowWindow (infoPtr
->hwndEdit
, SW_HIDE
);
1140 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1143 SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1145 * from native trace of first dropdown after typing in URL in IE4
1146 * CB_GETCURSEL(Combo)
1147 * GetWindowText(Edit)
1148 * CB_GETCURSEL(Combo)
1149 * CB_GETCOUNT(Combo)
1150 * CB_GETITEMDATA(Combo, n)
1151 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1152 * CB_GETCURSEL(Combo)
1153 * CB_SETCURSEL(COMBOEX, n)
1155 * the rest is supposition
1157 ShowWindow (infoPtr
->hwndEdit
, SW_SHOW
);
1158 InvalidateRect (infoPtr
->hwndCombo
, 0, TRUE
);
1159 InvalidateRect (infoPtr
->hwndEdit
, 0, TRUE
);
1160 cursel
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1162 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
1163 /* find match from edit against those in Combobox */
1164 GetWindowTextW (infoPtr
->hwndEdit
, wintext
, 520);
1165 n
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCOUNT
, 0, 0);
1166 for (cursel
= 0; cursel
< n
; cursel
++){
1167 item
= get_item_data(infoPtr
, cursel
);
1168 if ((INT_PTR
)item
== CB_ERR
) break;
1169 if (!cmptext(COMBOEX_GetText(infoPtr
, item
), wintext
)) break;
1171 if ((cursel
== n
) || ((INT_PTR
)item
== CB_ERR
)) {
1172 TRACE("failed to find match??? item=%p cursel=%d\n",
1174 if (infoPtr
->hwndEdit
)
1175 SetFocus(infoPtr
->hwndEdit
);
1180 item
= get_item_data(infoPtr
, cursel
);
1181 if ((INT_PTR
)item
== CB_ERR
) {
1182 TRACE("failed to find match??? item=%p cursel=%d\n",
1184 if (infoPtr
->hwndEdit
)
1185 SetFocus(infoPtr
->hwndEdit
);
1190 /* Save flags for testing and reset them */
1191 oldflags
= infoPtr
->flags
;
1192 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1194 if (oldflags
& WCBE_ACTEDIT
) {
1195 cbeend
.fChanged
= (oldflags
& WCBE_EDITCHG
);
1196 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1197 CB_GETCURSEL
, 0, 0);
1198 cbeend
.iWhy
= CBENF_DROPDOWN
;
1200 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, COMBOEX_GetText(infoPtr
, item
))) return 0;
1203 /* if selection has changed the set the new current selection */
1204 cursel
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1205 if ((oldflags
& WCBE_EDITCHG
) || (cursel
!= infoPtr
->selected
)) {
1206 infoPtr
->selected
= cursel
;
1207 SendMessageW (infoPtr
->hwndSelf
, CB_SETCURSEL
, cursel
, 0);
1208 SetFocus(infoPtr
->hwndCombo
);
1214 * CB_GETCURSEL(Combo)
1215 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1218 * WM_GETTEXTLENGTH(Edit)
1220 * EM_SETSEL(Edit, 0,0)
1221 * WM_GETTEXTLENGTH(Edit)
1223 * EM_SETSEL(Edit, 0,len)
1224 * return WM_COMMAND to parent
1226 oldItem
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1227 if (!(item
= COMBOEX_FindItem(infoPtr
, oldItem
))) {
1228 ERR("item %d not found. Problem!\n", oldItem
);
1231 infoPtr
->selected
= oldItem
;
1232 COMBOEX_SetEditText (infoPtr
, item
);
1233 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1236 case CBN_SELENDCANCEL
:
1238 * We have to change the handle since we are the control
1239 * issuing the message. IE4 depends on this.
1241 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1245 * from native trace:
1248 * WM_GETTEXT(Edit, 104)
1249 * CB_GETCURSEL(Combo) rets -1
1250 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1251 * CB_GETCURSEL(Combo)
1252 * InvalidateRect(Combo, 0, 0)
1255 SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1256 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1257 GetWindowTextW (infoPtr
->hwndEdit
, wintext
, 260);
1258 cbeend
.fChanged
= (infoPtr
->flags
& WCBE_EDITCHG
);
1259 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1260 CB_GETCURSEL
, 0, 0);
1261 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1263 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1264 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, wintext
)) return 0;
1266 /* possible CB_GETCURSEL */
1267 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1271 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1275 * We have to change the handle since we are the control
1276 * issuing the message. IE4 depends on this.
1277 * We also need to set the focus back to the Edit control
1278 * after passing the command to the parent of the ComboEx.
1280 lret
= SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1281 if (infoPtr
->hwndEdit
)
1282 SetFocus(infoPtr
->hwndEdit
);
1289 static BOOL
COMBOEX_WM_DeleteItem (COMBOEX_INFO
*infoPtr
, DELETEITEMSTRUCT
const *dis
)
1291 CBE_ITEMDATA
*item
, *olditem
;
1292 NMCOMBOBOXEXW nmcit
;
1295 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1296 dis
->CtlType
, dis
->CtlID
, dis
->itemID
, dis
->hwndItem
, dis
->itemData
);
1298 if (dis
->itemID
>= infoPtr
->nb_items
) return FALSE
;
1300 olditem
= infoPtr
->items
;
1301 i
= infoPtr
->nb_items
- 1;
1303 if (i
== dis
->itemID
) {
1304 infoPtr
->items
= infoPtr
->items
->next
;
1310 /* find the prior item in the list */
1311 while (item
->next
&& (i
> dis
->itemID
)) {
1315 if (!item
->next
|| (i
!= dis
->itemID
)) {
1316 ERR("COMBOBOXEX item structures broken. Please report!\n");
1319 olditem
= item
->next
;
1320 item
->next
= item
->next
->next
;
1322 infoPtr
->nb_items
--;
1324 memset (&nmcit
.ceItem
, 0, sizeof(nmcit
.ceItem
));
1325 COMBOEX_CopyItem (olditem
, &nmcit
.ceItem
);
1326 COMBOEX_NotifyItem (infoPtr
, CBEN_DELETEITEM
, &nmcit
);
1328 COMBOEX_FreeText(olditem
);
1335 static LRESULT
COMBOEX_DrawItem (COMBOEX_INFO
*infoPtr
, DRAWITEMSTRUCT
const *dis
)
1337 static const WCHAR nil
[] = { 0 };
1338 CBE_ITEMDATA
*item
= 0;
1344 COLORREF nbkc
, ntxc
, bkc
, txc
;
1345 int drawimage
, drawstate
, xioff
;
1347 if (!IsWindowEnabled(infoPtr
->hwndCombo
)) return 0;
1349 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1350 dis
->CtlType
, dis
->CtlID
);
1351 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1352 dis
->itemID
, dis
->itemAction
, dis
->itemState
);
1353 TRACE("hWnd=%p hDC=%p (%s) itemData=0x%08lx\n",
1354 dis
->hwndItem
, dis
->hDC
, wine_dbgstr_rect(&dis
->rcItem
), dis
->itemData
);
1357 /* "itemID - Specifies the menu item identifier for a menu */
1358 /* item or the index of the item in a list box or combo box. */
1359 /* For an empty list box or combo box, this member can be -1. */
1360 /* This allows the application to draw only the focus */
1361 /* rectangle at the coordinates specified by the rcItem */
1362 /* member even though there are no items in the control. */
1363 /* This indicates to the user whether the list box or combo */
1364 /* box has the focus. How the bits are set in the itemAction */
1365 /* member determines whether the rectangle is to be drawn as */
1366 /* though the list box or combo box has the focus. */
1367 if (dis
->itemID
== 0xffffffff) {
1368 if ( ( (dis
->itemAction
& ODA_FOCUS
) && (dis
->itemState
& ODS_SELECTED
)) ||
1369 ( (dis
->itemAction
& (ODA_SELECT
| ODA_DRAWENTIRE
)) && (dis
->itemState
& ODS_FOCUS
) ) ) {
1371 TRACE("drawing item -1 special focus, rect=(%s)\n",
1372 wine_dbgstr_rect(&dis
->rcItem
));
1374 else if ((dis
->CtlType
== ODT_COMBOBOX
) &&
1375 (dis
->itemAction
== ODA_DRAWENTIRE
)) {
1376 /* draw of edit control data */
1380 RECT exrc
, cbrc
, edrc
;
1381 GetWindowRect (infoPtr
->hwndSelf
, &exrc
);
1382 GetWindowRect (infoPtr
->hwndCombo
, &cbrc
);
1383 edrc
.left
=edrc
.top
=edrc
.right
=edrc
.bottom
=-1;
1384 if (infoPtr
->hwndEdit
)
1385 GetWindowRect (infoPtr
->hwndEdit
, &edrc
);
1386 TRACE("window rects ex=(%s), cb=(%s), ed=(%s)\n",
1387 wine_dbgstr_rect(&exrc
), wine_dbgstr_rect(&cbrc
),
1388 wine_dbgstr_rect(&edrc
));
1392 ERR("NOT drawing item -1 special focus, rect=(%s), action=%08x, state=%08x\n",
1393 wine_dbgstr_rect(&dis
->rcItem
),
1394 dis
->itemAction
, dis
->itemState
);
1399 /* If draw item is -1 (edit control) setup the item pointer */
1400 if (dis
->itemID
== 0xffffffff) {
1401 item
= infoPtr
->edit
;
1403 if (infoPtr
->hwndEdit
) {
1406 /* free previous text of edit item */
1407 COMBOEX_FreeText(item
);
1408 item
->mask
&= ~CBEIF_TEXT
;
1409 if( (len
= GetWindowTextLengthW(infoPtr
->hwndEdit
)) ) {
1410 item
->mask
|= CBEIF_TEXT
;
1411 item
->pszText
= (LPWSTR
)Alloc ((len
+ 1)*sizeof(WCHAR
));
1413 GetWindowTextW(infoPtr
->hwndEdit
, item
->pszText
, len
+1);
1415 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1416 infoPtr
->hwndEdit
, len
, debugstr_txt(item
->pszText
));
1422 /* if the item pointer is not set, then get the data and locate it */
1424 item
= get_item_data(infoPtr
, dis
->itemID
);
1425 if (item
== (CBE_ITEMDATA
*)CB_ERR
) {
1426 ERR("invalid item for id %d\n", dis
->itemID
);
1431 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
1433 xbase
= CBE_STARTOFFSET
;
1434 if ((item
->mask
& CBEIF_INDENT
) && (dis
->itemState
& ODS_COMBOEXLBOX
)) {
1435 INT indent
= item
->iIndent
;
1436 if (indent
== I_INDENTCALLBACK
) {
1438 ZeroMemory(&nmce
, sizeof(nmce
));
1439 nmce
.ceItem
.mask
= CBEIF_INDENT
;
1440 nmce
.ceItem
.lParam
= item
->lParam
;
1441 nmce
.ceItem
.iItem
= dis
->itemID
;
1442 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1443 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
1444 item
->iIndent
= nmce
.ceItem
.iIndent
;
1445 indent
= nmce
.ceItem
.iIndent
;
1447 xbase
+= (indent
* CBE_INDENT
);
1451 drawstate
= ILD_NORMAL
;
1452 if (item
->mask
& CBEIF_IMAGE
)
1453 drawimage
= item
->iImage
;
1454 if (dis
->itemState
& ODS_COMBOEXLBOX
) {
1455 /* drawing listbox entry */
1456 if (dis
->itemState
& ODS_SELECTED
) {
1457 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1458 drawimage
= item
->iSelectedImage
;
1459 drawstate
= ILD_SELECTED
;
1462 /* drawing combo/edit entry */
1463 if (IsWindowVisible(infoPtr
->hwndEdit
)) {
1464 /* if we have an edit control, the slave the
1465 * selection state to the Edit focus state
1467 if (infoPtr
->flags
& WCBE_EDITFOCUSED
) {
1468 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1469 drawimage
= item
->iSelectedImage
;
1470 drawstate
= ILD_SELECTED
;
1473 /* if we don't have an edit control, use
1474 * the requested state.
1476 if (dis
->itemState
& ODS_SELECTED
) {
1477 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1478 drawimage
= item
->iSelectedImage
;
1479 drawstate
= ILD_SELECTED
;
1484 if (infoPtr
->himl
&& !(infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGEINDENT
)) {
1486 iinfo
.rcImage
.left
= iinfo
.rcImage
.right
= 0;
1487 ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
);
1488 xioff
= iinfo
.rcImage
.right
- iinfo
.rcImage
.left
+ CBE_SEP
;
1491 /* setup pointer to text to be drawn */
1492 str
= COMBOEX_GetText(infoPtr
, item
);
1493 if (!str
) str
= nil
;
1495 len
= strlenW (str
);
1496 GetTextExtentPoint32W (dis
->hDC
, str
, len
, &txtsize
);
1498 if (dis
->itemAction
& (ODA_SELECT
| ODA_DRAWENTIRE
)) {
1499 int overlay
= item
->iOverlay
;
1501 if (drawimage
== I_IMAGECALLBACK
) {
1503 ZeroMemory(&nmce
, sizeof(nmce
));
1504 nmce
.ceItem
.mask
= (drawstate
== ILD_NORMAL
) ? CBEIF_IMAGE
: CBEIF_SELECTEDIMAGE
;
1505 nmce
.ceItem
.lParam
= item
->lParam
;
1506 nmce
.ceItem
.iItem
= dis
->itemID
;
1507 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1508 if (drawstate
== ILD_NORMAL
) {
1509 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) item
->iImage
= nmce
.ceItem
.iImage
;
1510 drawimage
= nmce
.ceItem
.iImage
;
1511 } else if (drawstate
== ILD_SELECTED
) {
1512 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) item
->iSelectedImage
= nmce
.ceItem
.iSelectedImage
;
1513 drawimage
= nmce
.ceItem
.iSelectedImage
;
1514 } else ERR("Bad draw state = %d\n", drawstate
);
1517 if (overlay
== I_IMAGECALLBACK
) {
1519 ZeroMemory(&nmce
, sizeof(nmce
));
1520 nmce
.ceItem
.mask
= CBEIF_OVERLAY
;
1521 nmce
.ceItem
.lParam
= item
->lParam
;
1522 nmce
.ceItem
.iItem
= dis
->itemID
;
1523 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1524 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
1525 item
->iOverlay
= nmce
.ceItem
.iOverlay
;
1526 overlay
= nmce
.ceItem
.iOverlay
;
1529 if (drawimage
>= 0 &&
1530 !(infoPtr
->dwExtStyle
& (CBES_EX_NOEDITIMAGE
| CBES_EX_NOEDITIMAGEINDENT
))) {
1531 if (overlay
> 0) ImageList_SetOverlayImage (infoPtr
->himl
, overlay
, 1);
1532 ImageList_Draw (infoPtr
->himl
, drawimage
, dis
->hDC
, xbase
, dis
->rcItem
.top
,
1533 drawstate
| (overlay
> 0 ? INDEXTOOVERLAYMASK(1) : 0));
1536 /* now draw the text */
1537 if (!IsWindowVisible (infoPtr
->hwndEdit
)) {
1538 nbkc
= GetSysColor ((dis
->itemState
& ODS_SELECTED
) ?
1539 COLOR_HIGHLIGHT
: COLOR_WINDOW
);
1540 bkc
= SetBkColor (dis
->hDC
, nbkc
);
1541 ntxc
= GetSysColor ((dis
->itemState
& ODS_SELECTED
) ?
1542 COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
1543 txc
= SetTextColor (dis
->hDC
, ntxc
);
1545 y
= dis
->rcItem
.top
+
1546 (dis
->rcItem
.bottom
- dis
->rcItem
.top
- txtsize
.cy
) / 2;
1548 rect
.right
= x
+ txtsize
.cx
;
1549 rect
.top
= dis
->rcItem
.top
+ 1;
1550 rect
.bottom
= dis
->rcItem
.bottom
- 1;
1551 TRACE("drawing item %d text, rect=(%s)\n",
1552 dis
->itemID
, wine_dbgstr_rect(&rect
));
1553 ExtTextOutW (dis
->hDC
, x
, y
, ETO_OPAQUE
| ETO_CLIPPED
,
1554 &rect
, str
, len
, 0);
1555 SetBkColor (dis
->hDC
, bkc
);
1556 SetTextColor (dis
->hDC
, txc
);
1560 if (dis
->itemAction
& ODA_FOCUS
) {
1561 rect
.left
= xbase
+ xioff
- 1;
1562 rect
.right
= rect
.left
+ txtsize
.cx
+ 2;
1563 rect
.top
= dis
->rcItem
.top
;
1564 rect
.bottom
= dis
->rcItem
.bottom
;
1565 DrawFocusRect(dis
->hDC
, &rect
);
1572 static void COMBOEX_ResetContent (COMBOEX_INFO
*infoPtr
)
1576 CBE_ITEMDATA
*item
, *next
;
1578 item
= infoPtr
->items
;
1581 COMBOEX_FreeText (item
);
1588 infoPtr
->selected
= -1;
1589 infoPtr
->nb_items
= 0;
1593 static LRESULT
COMBOEX_Destroy (COMBOEX_INFO
*infoPtr
)
1595 if (infoPtr
->hwndCombo
)
1596 DestroyWindow (infoPtr
->hwndCombo
);
1598 Free (infoPtr
->edit
);
1601 COMBOEX_ResetContent (infoPtr
);
1603 if (infoPtr
->defaultFont
)
1604 DeleteObject (infoPtr
->defaultFont
);
1606 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1608 /* free comboex info data */
1615 static LRESULT
COMBOEX_MeasureItem (COMBOEX_INFO
const *infoPtr
, MEASUREITEMSTRUCT
*mis
)
1617 static const WCHAR strW
[] = { 'W', 0 };
1622 GetTextExtentPointW (hdc
, strW
, 1, &mysize
);
1624 mis
->itemHeight
= mysize
.cy
+ CBE_EXTRA
;
1626 TRACE("adjusted height hwnd=%p, height=%d\n",
1627 infoPtr
->hwndSelf
, mis
->itemHeight
);
1633 static LRESULT
COMBOEX_NCCreate (HWND hwnd
)
1635 /* WARNING: The COMBOEX_INFO structure is not yet created */
1636 DWORD oldstyle
, newstyle
;
1638 oldstyle
= (DWORD
)GetWindowLongW (hwnd
, GWL_STYLE
);
1639 newstyle
= oldstyle
& ~(WS_VSCROLL
| WS_HSCROLL
| WS_BORDER
);
1640 if (newstyle
!= oldstyle
) {
1641 TRACE("req style %08x, resetting style %08x\n",
1642 oldstyle
, newstyle
);
1643 SetWindowLongW (hwnd
, GWL_STYLE
, newstyle
);
1649 static LRESULT
COMBOEX_NotifyFormat (COMBOEX_INFO
*infoPtr
, LPARAM lParam
)
1651 if (lParam
== NF_REQUERY
) {
1652 INT i
= SendMessageW(infoPtr
->hwndNotify
,
1653 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1654 infoPtr
->NtfUnicode
= (i
== NFR_UNICODE
) ? 1 : 0;
1656 return infoPtr
->NtfUnicode
? NFR_UNICODE
: NFR_ANSI
;
1660 static LRESULT
COMBOEX_Size (COMBOEX_INFO
*infoPtr
, INT width
, INT height
)
1662 TRACE("(width=%d, height=%d)\n", width
, height
);
1664 MoveWindow (infoPtr
->hwndCombo
, 0, 0, width
, height
, TRUE
);
1666 COMBOEX_AdjustEditPos (infoPtr
);
1672 static LRESULT
COMBOEX_WindowPosChanging (COMBOEX_INFO
*infoPtr
, WINDOWPOS
*wp
)
1674 RECT cbx_wrect
, cbx_crect
, cb_wrect
;
1677 GetWindowRect (infoPtr
->hwndSelf
, &cbx_wrect
);
1678 GetClientRect (infoPtr
->hwndSelf
, &cbx_crect
);
1679 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
1681 /* width is winpos value + border width of comboex */
1683 + (cbx_wrect
.right
-cbx_wrect
.left
)
1684 - (cbx_crect
.right
-cbx_crect
.left
);
1686 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1687 wp
->x
, wp
->y
, wp
->cx
, wp
->cy
, wp
->flags
);
1688 TRACE("EX window=(%s), client=(%s)\n",
1689 wine_dbgstr_rect(&cbx_wrect
), wine_dbgstr_rect(&cbx_crect
));
1690 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
1691 wine_dbgstr_rect(&cbx_wrect
), width
, cb_wrect
.bottom
-cb_wrect
.top
);
1693 if (width
) SetWindowPos (infoPtr
->hwndCombo
, HWND_TOP
, 0, 0,
1695 cb_wrect
.bottom
-cb_wrect
.top
,
1698 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
1700 /* height is combo window height plus border width of comboex */
1701 height
= (cb_wrect
.bottom
-cb_wrect
.top
)
1702 + (cbx_wrect
.bottom
-cbx_wrect
.top
)
1703 - (cbx_crect
.bottom
-cbx_crect
.top
);
1704 if (wp
->cy
< height
) wp
->cy
= height
;
1705 if (infoPtr
->hwndEdit
) {
1706 COMBOEX_AdjustEditPos (infoPtr
);
1707 InvalidateRect (infoPtr
->hwndCombo
, 0, TRUE
);
1713 static LRESULT WINAPI
1714 COMBOEX_EditWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1716 HWND hwndComboex
= (HWND
)GetPropW(hwnd
, COMBOEX_SUBCLASS_PROP
);
1717 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwndComboex
);
1718 NMCBEENDEDITW cbeend
;
1719 WCHAR edit_text
[260];
1725 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1726 hwnd
, uMsg
, wParam
, lParam
, infoPtr
);
1728 if (!infoPtr
) return 0;
1734 /* handle (ignore) the return character */
1735 if (wParam
== VK_RETURN
) return 0;
1736 /* all other characters pass into the real Edit */
1737 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1738 hwnd
, uMsg
, wParam
, lParam
);
1742 * The following was determined by traces of the native
1745 obkc
= SetBkColor (hDC
, GetSysColor (COLOR_WINDOW
));
1746 GetClientRect (hwnd
, &rect
);
1747 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect
));
1748 ExtTextOutW (hDC
, 0, 0, ETO_OPAQUE
, &rect
, 0, 0, 0);
1749 SetBkColor (hDC
, obkc
);
1750 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1751 hwnd
, uMsg
, wParam
, lParam
);
1754 INT oldItem
, selected
, step
= 1;
1757 switch ((INT
)wParam
)
1760 /* native version seems to do following for COMBOEX */
1762 * GetWindowTextW(Edit,&?, 0x104) x
1763 * CB_GETCURSEL to Combo rets -1 x
1764 * WM_NOTIFY to COMBOEX parent (rebar) x
1765 * (CBEN_ENDEDIT{A|W}
1766 * fChanged = FALSE x
1767 * inewSelection = -1 x
1770 * CB_GETCURSEL to Combo rets -1 x
1771 * InvalidateRect(Combo, 0) x
1772 * WM_SETTEXT to Edit x
1773 * EM_SETSEL to Edit (0,0) x
1774 * EM_SETSEL to Edit (0,-1) x
1775 * RedrawWindow(Combo, 0, 0, 5) x
1777 TRACE("special code for VK_ESCAPE\n");
1779 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1781 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1782 cbeend
.fChanged
= FALSE
;
1783 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1784 CB_GETCURSEL
, 0, 0);
1785 cbeend
.iWhy
= CBENF_ESCAPE
;
1787 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) return 0;
1788 oldItem
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1789 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1790 if (!(item
= COMBOEX_FindItem(infoPtr
, oldItem
))) {
1791 ERR("item %d not found. Problem!\n", oldItem
);
1794 infoPtr
->selected
= oldItem
;
1795 COMBOEX_SetEditText (infoPtr
, item
);
1796 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
|
1801 /* native version seems to do following for COMBOEX */
1803 * GetWindowTextW(Edit,&?, 0x104) x
1804 * CB_GETCURSEL to Combo rets -1 x
1805 * CB_GETCOUNT to Combo rets 0
1807 * CB_GETITEMDATA to match
1808 * *** above 3 lines simulated by FindItem x
1809 * WM_NOTIFY to COMBOEX parent (rebar) x
1810 * (CBEN_ENDEDIT{A|W} x
1811 * fChanged = TRUE (-1) x
1812 * iNewSelection = -1 or selected x
1814 * iWhy = 2 (CBENF_RETURN) x
1815 * CB_GETCURSEL to Combo rets -1 x
1816 * if -1 send CB_SETCURSEL to Combo -1 x
1817 * InvalidateRect(Combo, 0, 0) x
1819 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1822 TRACE("special code for VK_RETURN\n");
1824 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1826 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1827 selected
= SendMessageW (infoPtr
->hwndCombo
,
1828 CB_GETCURSEL
, 0, 0);
1830 if (selected
!= -1) {
1831 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
1832 item
= COMBOEX_FindItem (infoPtr
, selected
);
1833 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1834 selected
, debugstr_txt(item
->pszText
));
1835 TRACE("handling VK_RETURN, edittext=%s\n",
1836 debugstr_w(edit_text
));
1837 if (cmptext (COMBOEX_GetText(infoPtr
, item
), edit_text
)) {
1838 /* strings not equal -- indicate edit has changed */
1843 cbeend
.iNewSelection
= selected
;
1844 cbeend
.fChanged
= TRUE
;
1845 cbeend
.iWhy
= CBENF_RETURN
;
1846 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) {
1847 /* abort the change, restore previous */
1848 TRACE("Notify requested abort of change\n");
1849 COMBOEX_SetEditText (infoPtr
, infoPtr
->edit
);
1850 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
|
1854 oldItem
= SendMessageW (infoPtr
->hwndCombo
,CB_GETCURSEL
, 0, 0);
1855 if (oldItem
!= -1) {
1856 /* if something is selected, then deselect it */
1857 SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
,
1860 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1861 SetFocus(infoPtr
->hwndEdit
);
1867 /* by default, step is 1 */
1868 oldItem
= SendMessageW (infoPtr
->hwndSelf
, CB_GETCURSEL
, 0, 0);
1869 if (oldItem
>= 0 && oldItem
+ step
>= 0)
1870 SendMessageW (infoPtr
->hwndSelf
, CB_SETCURSEL
, oldItem
+ step
, 0);
1873 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1874 hwnd
, uMsg
, wParam
, lParam
);
1880 /* remember the focus to set state of icon */
1881 lret
= CallWindowProcW (infoPtr
->prevEditWndProc
,
1882 hwnd
, uMsg
, wParam
, lParam
);
1883 infoPtr
->flags
|= WCBE_EDITFOCUSED
;
1888 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1890 infoPtr
->flags
&= ~WCBE_EDITFOCUSED
;
1891 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1892 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1894 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1895 cbeend
.fChanged
= FALSE
;
1896 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1897 CB_GETCURSEL
, 0, 0);
1898 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1900 COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
);
1905 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1906 hwnd
, uMsg
, wParam
, lParam
);
1911 static LRESULT WINAPI
1912 COMBOEX_ComboWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1914 HWND hwndComboex
= (HWND
)GetPropW(hwnd
, COMBOEX_SUBCLASS_PROP
);
1915 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwndComboex
);
1916 NMCBEENDEDITW cbeend
;
1923 WCHAR edit_text
[260];
1925 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1926 hwnd
, uMsg
, wParam
, lParam
, infoPtr
);
1928 if (!infoPtr
) return 0;
1935 * The only way this message should come is from the
1936 * child Listbox issuing the message. Flag this so
1937 * that ComboEx knows this is listbox.
1939 ((DRAWITEMSTRUCT
*)lParam
)->itemState
|= ODS_COMBOEXLBOX
;
1940 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1941 hwnd
, uMsg
, wParam
, lParam
);
1945 * The following was determined by traces of the native
1948 obkc
= SetBkColor (hDC
, GetSysColor (COLOR_WINDOW
));
1949 GetClientRect (hwnd
, &rect
);
1950 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect
));
1951 ExtTextOutW (hDC
, 0, 0, ETO_OPAQUE
, &rect
, 0, 0, 0);
1952 SetBkColor (hDC
, obkc
);
1953 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1954 hwnd
, uMsg
, wParam
, lParam
);
1958 * WM_NOTIFY to comboex parent (rebar)
1959 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1960 * CallWindowProc (previous)
1962 nmmse
.dwItemSpec
= 0;
1963 nmmse
.dwItemData
= 0;
1966 nmmse
.dwHitInfo
= lParam
;
1967 COMBOEX_Notify (infoPtr
, NM_SETCURSOR
, (NMHDR
*)&nmmse
);
1968 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1969 hwnd
, uMsg
, wParam
, lParam
);
1971 case WM_LBUTTONDOWN
:
1972 GetClientRect (hwnd
, &rect
);
1973 rect
.bottom
= rect
.top
+ SendMessageW(infoPtr
->hwndSelf
,
1974 CB_GETITEMHEIGHT
, -1, 0);
1975 rect
.left
= rect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1976 pt
.x
= (short)LOWORD(lParam
);
1977 pt
.y
= (short)HIWORD(lParam
);
1978 if (PtInRect(&rect
, pt
))
1979 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1980 hwnd
, uMsg
, wParam
, lParam
);
1981 infoPtr
->flags
|= WCBE_MOUSECAPTURED
;
1986 if (!(infoPtr
->flags
& WCBE_MOUSECAPTURED
))
1987 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1988 hwnd
, uMsg
, wParam
, lParam
);
1990 infoPtr
->flags
&= ~WCBE_MOUSECAPTURED
;
1991 if (infoPtr
->flags
& WCBE_MOUSEDRAGGED
) {
1992 infoPtr
->flags
&= ~WCBE_MOUSEDRAGGED
;
1994 SendMessageW(hwnd
, CB_SHOWDROPDOWN
, TRUE
, 0);
1999 if ( (infoPtr
->flags
& WCBE_MOUSECAPTURED
) &&
2000 !(infoPtr
->flags
& WCBE_MOUSEDRAGGED
)) {
2001 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
2002 COMBOEX_NotifyDragBegin(infoPtr
, edit_text
);
2003 infoPtr
->flags
|= WCBE_MOUSEDRAGGED
;
2005 return CallWindowProcW (infoPtr
->prevComboWndProc
,
2006 hwnd
, uMsg
, wParam
, lParam
);
2009 switch (HIWORD(wParam
)) {
2012 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2021 * GetFocus() retns AA
2022 * GetWindowTextW(Edit)
2023 * CB_GETCURSEL(Combo) (got -1)
2024 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2025 * CB_GETCURSEL(Combo) (got -1)
2026 * InvalidateRect(Combo, 0, 0)
2027 * WM_KILLFOCUS(Combo, AA)
2030 focusedhwnd
= GetFocus();
2031 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
2032 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
2033 cbeend
.fChanged
= (infoPtr
->flags
& WCBE_EDITCHG
);
2034 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
2035 CB_GETCURSEL
, 0, 0);
2036 cbeend
.iWhy
= CBENF_KILLFOCUS
;
2038 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
2039 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) return 0;
2041 /* possible CB_GETCURSEL */
2042 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
2044 SendMessageW (infoPtr
->hwndCombo
, WM_KILLFOCUS
,
2045 (WPARAM
)focusedhwnd
, 0);
2050 * For EN_SETFOCUS this issues the same calls and messages
2051 * as the native seems to do.
2053 * for some cases however native does the following:
2054 * (noticed after SetFocus during LBUTTONDOWN on
2055 * on dropdown arrow)
2056 * WM_GETTEXTLENGTH (Edit);
2057 * WM_GETTEXT (Edit, len+1, str);
2058 * EM_SETSEL (Edit, 0, 0);
2059 * WM_GETTEXTLENGTH (Edit);
2060 * WM_GETTEXT (Edit, len+1, str);
2061 * EM_SETSEL (Edit, 0, len);
2062 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2066 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, 0);
2067 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
2068 COMBOEX_Notify (infoPtr
, CBEN_BEGINEDIT
, &hdr
);
2069 infoPtr
->flags
|= WCBE_ACTEDIT
;
2070 infoPtr
->flags
&= ~WCBE_EDITCHG
; /* no change yet */
2076 * For EN_CHANGE this issues the same calls and messages
2077 * as the native seems to do.
2079 WCHAR edit_text
[260];
2081 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
2083 INT selected
= SendMessageW (infoPtr
->hwndCombo
,
2084 CB_GETCURSEL
, 0, 0);
2086 /* lstrlenW( lastworkingURL ) */
2088 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
2089 if (selected
== -1) {
2090 lastwrk
= infoPtr
->edit
->pszText
;
2093 CBE_ITEMDATA
*item
= COMBOEX_FindItem (infoPtr
, selected
);
2094 lastwrk
= COMBOEX_GetText(infoPtr
, item
);
2097 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2098 selected
, debugstr_w(lastwrk
));
2099 TRACE("handling EN_CHANGE, edittext=%s\n",
2100 debugstr_w(edit_text
));
2102 /* cmptext is between lastworkingURL and GetWindowText */
2103 if (cmptext (lastwrk
, edit_text
)) {
2104 /* strings not equal -- indicate edit has changed */
2105 infoPtr
->flags
|= WCBE_EDITCHG
;
2107 SendMessageW ( infoPtr
->hwndNotify
, WM_COMMAND
,
2108 MAKEWPARAM(GetDlgCtrlID (infoPtr
->hwndSelf
),
2110 (LPARAM
)infoPtr
->hwndSelf
);
2116 * Therefore from traces there is no additional code here
2120 * Using native COMCTL32 gets the following:
2121 * 1 == SHDOCVW.DLL issues call/message
2122 * 2 == COMCTL32.DLL issues call/message
2123 * 3 == WINE issues call/message
2126 * for LBN_SELCHANGE:
2127 * 1 CB_GETCURSEL(ComboEx)
2128 * 1 CB_GETDROPPEDSTATE(ComboEx)
2129 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2130 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2131 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2132 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2133 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2134 * 3 ShowWindow(ComboLB, SW_HIDE)
2135 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2136 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2138 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2139 * ? LB_GETCURSEL <==|
2141 * ? LB_GETTEXT | Needs to be added to
2142 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2143 * ? LB_GETITEMDATA |
2144 * ? WM_DRAWITEM(ComboEx) <==|
2150 return CallWindowProcW (infoPtr
->prevComboWndProc
,
2151 hwnd
, uMsg
, wParam
, lParam
);
2157 static LRESULT WINAPI
2158 COMBOEX_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2160 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwnd
);
2162 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2165 if (uMsg
== WM_CREATE
)
2166 return COMBOEX_Create (hwnd
, (LPCREATESTRUCTA
)lParam
);
2167 if (uMsg
== WM_NCCREATE
)
2168 COMBOEX_NCCreate (hwnd
);
2169 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2174 case CBEM_DELETEITEM
:
2175 return COMBOEX_DeleteItem (infoPtr
, wParam
);
2177 case CBEM_GETCOMBOCONTROL
:
2178 return (LRESULT
)infoPtr
->hwndCombo
;
2180 case CBEM_GETEDITCONTROL
:
2181 return (LRESULT
)infoPtr
->hwndEdit
;
2183 case CBEM_GETEXTENDEDSTYLE
:
2184 return infoPtr
->dwExtStyle
;
2186 case CBEM_GETIMAGELIST
:
2187 return (LRESULT
)infoPtr
->himl
;
2190 return (LRESULT
)COMBOEX_GetItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2193 return (LRESULT
)COMBOEX_GetItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2195 case CBEM_GETUNICODEFORMAT
:
2196 return infoPtr
->unicode
;
2198 case CBEM_HASEDITCHANGED
:
2199 return COMBOEX_HasEditChanged (infoPtr
);
2201 case CBEM_INSERTITEMA
:
2202 return COMBOEX_InsertItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2204 case CBEM_INSERTITEMW
:
2205 return COMBOEX_InsertItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2207 case CBEM_SETEXSTYLE
:
2208 case CBEM_SETEXTENDEDSTYLE
:
2209 return COMBOEX_SetExtendedStyle (infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
2211 case CBEM_SETIMAGELIST
:
2212 return (LRESULT
)COMBOEX_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2215 return COMBOEX_SetItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2218 return COMBOEX_SetItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2220 case CBEM_SETUNICODEFORMAT
:
2221 return COMBOEX_SetUnicodeFormat (infoPtr
, wParam
);
2223 /*case CBEM_SETWINDOWTHEME:
2224 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2228 case WM_GETTEXTLENGTH
:
2229 return SendMessageW(infoPtr
->hwndEdit
, uMsg
, wParam
, lParam
);
2232 return COMBOEX_GetListboxText(infoPtr
, wParam
, (LPWSTR
)lParam
);
2234 case CB_GETLBTEXTLEN
:
2235 return COMBOEX_GetListboxText(infoPtr
, wParam
, NULL
);
2237 case CB_RESETCONTENT
:
2238 COMBOEX_ResetContent(infoPtr
);
2241 /* Combo messages we are not sure if we need to process or just forward */
2242 case CB_GETDROPPEDCONTROLRECT
:
2243 case CB_GETITEMHEIGHT
:
2244 case CB_GETEXTENDEDUI
:
2246 case CB_SELECTSTRING
:
2248 /* Combo messages OK to just forward to the regular COMBO */
2251 case CB_GETDROPPEDSTATE
:
2252 case CB_SETDROPPEDWIDTH
:
2253 case CB_SETEXTENDEDUI
:
2254 case CB_SHOWDROPDOWN
:
2255 return SendMessageW (infoPtr
->hwndCombo
, uMsg
, wParam
, lParam
);
2257 /* Combo messages we need to process specially */
2258 case CB_FINDSTRINGEXACT
:
2259 return COMBOEX_FindStringExact (infoPtr
, (INT
)wParam
, (LPCWSTR
)lParam
);
2261 case CB_GETITEMDATA
:
2262 return COMBOEX_GetItemData (infoPtr
, (INT
)wParam
);
2265 return COMBOEX_SetCursel (infoPtr
, (INT
)wParam
);
2267 case CB_SETITEMDATA
:
2268 return COMBOEX_SetItemData (infoPtr
, (INT
)wParam
, (DWORD_PTR
)lParam
);
2270 case CB_SETITEMHEIGHT
:
2271 return COMBOEX_SetItemHeight (infoPtr
, (INT
)wParam
, (UINT
)lParam
);
2275 /* Window messages passed to parent */
2277 return COMBOEX_Command (infoPtr
, wParam
, lParam
);
2280 if (infoPtr
->NtfUnicode
)
2281 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
2283 return SendMessageA (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
2286 /* Window messages we need to process */
2288 return COMBOEX_WM_DeleteItem (infoPtr
, (DELETEITEMSTRUCT
*)lParam
);
2291 return COMBOEX_DrawItem (infoPtr
, (DRAWITEMSTRUCT
*)lParam
);
2294 return COMBOEX_Destroy (infoPtr
);
2296 case WM_MEASUREITEM
:
2297 return COMBOEX_MeasureItem (infoPtr
, (MEASUREITEMSTRUCT
*)lParam
);
2299 case WM_NOTIFYFORMAT
:
2300 return COMBOEX_NotifyFormat (infoPtr
, lParam
);
2303 return COMBOEX_Size (infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
2305 case WM_WINDOWPOSCHANGING
:
2306 return COMBOEX_WindowPosChanging (infoPtr
, (WINDOWPOS
*)lParam
);
2309 SetFocus(infoPtr
->hwndCombo
);
2313 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2314 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",uMsg
,wParam
,lParam
);
2315 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2320 void COMBOEX_Register (void)
2324 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2325 wndClass
.style
= CS_GLOBALCLASS
;
2326 wndClass
.lpfnWndProc
= COMBOEX_WindowProc
;
2327 wndClass
.cbClsExtra
= 0;
2328 wndClass
.cbWndExtra
= sizeof(COMBOEX_INFO
*);
2329 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2330 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2331 wndClass
.lpszClassName
= WC_COMBOBOXEXW
;
2333 RegisterClassW (&wndClass
);
2337 void COMBOEX_Unregister (void)
2339 UnregisterClassW (WC_COMBOBOXEXW
, NULL
);