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
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(comboex
);
38 typedef struct _CBE_ITEMDATA
40 struct _CBE_ITEMDATA
*next
;
52 /* ComboBoxEx structure */
56 HWND hwndSelf
; /* my own hwnd */
57 HWND hwndNotify
; /* my parent hwnd */
61 INT selected
; /* index of selected item */
62 DWORD flags
; /* WINE internal flags */
65 INT nb_items
; /* Number of items */
66 BOOL unicode
; /* TRUE if this window is Unicode */
67 BOOL NtfUnicode
; /* TRUE if parent wants notify in Unicode */
68 CBE_ITEMDATA edit
; /* item data for edit item */
69 CBE_ITEMDATA
*items
; /* Array of items */
72 /* internal flags in the COMBOEX_INFO structure */
73 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
74 * CBEN_BEGINEDIT issued
75 * but CBEN_ENDEDIT{A|W}
77 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
78 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
79 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
80 #define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
81 #define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
83 #define ID_CB_EDIT 1001
87 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
88 * the ComboEx version of the Combo Window Proc so that when the
89 * WM_DRAWITEM message is then passed to ComboEx, we know that this
90 * particular WM_DRAWITEM message is for listbox only items. Any message
91 * without this flag is then for the Edit control field.
93 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
94 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
96 #define ODS_COMBOEXLBOX 0x4000
100 /* Height in pixels of control over the amount of the selected font */
103 /* Indent amount per MS documentation */
104 #define CBE_INDENT 10
106 /* Offset in pixels from left side for start of image or text */
107 #define CBE_STARTOFFSET 6
109 /* Offset between image and text */
112 #define COMBO_SUBCLASSID 1
113 #define EDIT_SUBCLASSID 2
115 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongPtrW (hwnd, 0))
117 static LRESULT CALLBACK
COMBOEX_EditWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
118 UINT_PTR uId
, DWORD_PTR ref_data
);
119 static LRESULT CALLBACK
COMBOEX_ComboWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
120 UINT_PTR uId
, DWORD_PTR ref_data
);
121 static LRESULT
COMBOEX_Destroy (COMBOEX_INFO
*infoPtr
);
122 typedef INT (WINAPI
*cmp_func_t
)(LPCWSTR
, LPCWSTR
);
124 static inline BOOL
is_textW(LPCWSTR str
)
126 return str
&& str
!= LPSTR_TEXTCALLBACKW
;
129 static inline BOOL
is_textA(LPCSTR str
)
131 return str
&& str
!= LPSTR_TEXTCALLBACKA
;
134 static inline LPCSTR
debugstr_txt(LPCWSTR str
)
136 if (str
== LPSTR_TEXTCALLBACKW
) return "(callback)";
137 return debugstr_w(str
);
140 static void COMBOEX_DumpItem (CBE_ITEMDATA
const *item
)
142 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
143 item
, item
->mask
, item
->pszText
, item
->cchTextMax
, item
->iImage
);
144 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
145 item
, item
->iSelectedImage
, item
->iOverlay
, item
->iIndent
, item
->lParam
);
146 if (item
->mask
& CBEIF_TEXT
)
147 TRACE("item %p - pszText=%s\n", item
, debugstr_txt(item
->pszText
));
151 static void COMBOEX_DumpInput (COMBOBOXEXITEMW
const *input
)
153 TRACE("input - mask=%08x, iItem=%ld, pszText=%p, cchTM=%d, iImage=%d\n",
154 input
->mask
, input
->iItem
, input
->pszText
, input
->cchTextMax
,
156 if (input
->mask
& CBEIF_TEXT
)
157 TRACE("input - pszText=<%s>\n", debugstr_txt(input
->pszText
));
158 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
159 input
->iSelectedImage
, input
->iOverlay
, input
->iIndent
, input
->lParam
);
163 static inline CBE_ITEMDATA
*get_item_data(const COMBOEX_INFO
*infoPtr
, INT index
)
165 return (CBE_ITEMDATA
*)SendMessageW (infoPtr
->hwndCombo
, CB_GETITEMDATA
,
169 static inline cmp_func_t
get_cmp_func(COMBOEX_INFO
const *infoPtr
)
171 return infoPtr
->dwExtStyle
& CBES_EX_CASESENSITIVE
? lstrcmpW
: lstrcmpiW
;
174 static INT
COMBOEX_Notify (const COMBOEX_INFO
*infoPtr
, INT code
, NMHDR
*hdr
)
176 hdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
177 hdr
->hwndFrom
= infoPtr
->hwndSelf
;
179 if (infoPtr
->NtfUnicode
)
180 return SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)hdr
);
182 return SendMessageA (infoPtr
->hwndNotify
, WM_NOTIFY
, 0, (LPARAM
)hdr
);
187 COMBOEX_NotifyItem (const COMBOEX_INFO
*infoPtr
, UINT code
, NMCOMBOBOXEXW
*hdr
)
189 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
190 if (infoPtr
->NtfUnicode
)
191 return COMBOEX_Notify (infoPtr
, code
, &hdr
->hdr
);
193 LPWSTR wstr
= hdr
->ceItem
.pszText
;
197 if ((hdr
->ceItem
.mask
& CBEIF_TEXT
) && is_textW(wstr
)) {
198 len
= WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, 0, 0, NULL
, NULL
);
200 astr
= Alloc ((len
+ 1)*sizeof(CHAR
));
202 WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, astr
, len
, 0, 0);
203 hdr
->ceItem
.pszText
= (LPWSTR
)astr
;
207 if (code
== CBEN_ENDEDITW
) code
= CBEN_ENDEDITA
;
208 else if (code
== CBEN_GETDISPINFOW
) code
= CBEN_GETDISPINFOA
;
209 else if (code
== CBEN_DRAGBEGINW
) code
= CBEN_DRAGBEGINA
;
211 ret
= COMBOEX_Notify (infoPtr
, code
, (NMHDR
*)hdr
);
213 if (astr
&& hdr
->ceItem
.pszText
== (LPWSTR
)astr
)
214 hdr
->ceItem
.pszText
= wstr
;
223 static INT
COMBOEX_NotifyEndEdit (const COMBOEX_INFO
*infoPtr
, NMCBEENDEDITW
*neew
, LPCWSTR wstr
)
225 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
226 if (infoPtr
->NtfUnicode
) {
227 lstrcpynW(neew
->szText
, wstr
, CBEMAXSTRLEN
);
228 return COMBOEX_Notify (infoPtr
, CBEN_ENDEDITW
, &neew
->hdr
);
232 neea
.hdr
= neew
->hdr
;
233 neea
.fChanged
= neew
->fChanged
;
234 neea
.iNewSelection
= neew
->iNewSelection
;
235 WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, neea
.szText
, CBEMAXSTRLEN
, 0, 0);
236 neea
.iWhy
= neew
->iWhy
;
238 return COMBOEX_Notify (infoPtr
, CBEN_ENDEDITA
, &neea
.hdr
);
243 static void COMBOEX_NotifyDragBegin(const COMBOEX_INFO
*infoPtr
, LPCWSTR wstr
)
245 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
246 if (infoPtr
->NtfUnicode
) {
247 NMCBEDRAGBEGINW ndbw
;
250 lstrcpynW(ndbw
.szText
, wstr
, CBEMAXSTRLEN
);
251 COMBOEX_Notify (infoPtr
, CBEN_DRAGBEGINW
, &ndbw
.hdr
);
253 NMCBEDRAGBEGINA ndba
;
256 WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, ndba
.szText
, CBEMAXSTRLEN
, 0, 0);
258 COMBOEX_Notify (infoPtr
, CBEN_DRAGBEGINA
, &ndba
.hdr
);
263 static void COMBOEX_FreeText (CBE_ITEMDATA
*item
)
265 if (is_textW(item
->pszText
)) Free(item
->pszText
);
266 item
->pszText
= NULL
;
268 item
->pszTemp
= NULL
;
272 static INT
COMBOEX_GetIndex(COMBOEX_INFO
const *infoPtr
, CBE_ITEMDATA
const *item
)
274 CBE_ITEMDATA
const *moving
;
277 moving
= infoPtr
->items
;
278 index
= infoPtr
->nb_items
- 1;
280 while (moving
&& (moving
!= item
)) {
281 moving
= moving
->next
;
284 if (!moving
|| (index
< 0)) {
285 ERR("COMBOBOXEX item structures broken. Please report!\n");
292 static LPCWSTR
COMBOEX_GetText(const COMBOEX_INFO
*infoPtr
, CBE_ITEMDATA
*item
)
298 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
299 return item
->pszText
;
301 ZeroMemory(&nmce
, sizeof(nmce
));
302 nmce
.ceItem
.mask
= CBEIF_TEXT
;
303 nmce
.ceItem
.lParam
= item
->lParam
;
304 nmce
.ceItem
.iItem
= COMBOEX_GetIndex(infoPtr
, item
);
305 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
307 if (is_textW(nmce
.ceItem
.pszText
)) {
308 len
= MultiByteToWideChar (CP_ACP
, 0, (LPSTR
)nmce
.ceItem
.pszText
, -1, NULL
, 0);
309 buf
= Alloc ((len
+ 1)*sizeof(WCHAR
));
311 MultiByteToWideChar (CP_ACP
, 0, (LPSTR
)nmce
.ceItem
.pszText
, -1, buf
, len
);
312 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) {
313 COMBOEX_FreeText(item
);
321 text
= nmce
.ceItem
.pszText
;
323 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
324 item
->pszText
= text
;
329 static void COMBOEX_GetComboFontSize (const COMBOEX_INFO
*infoPtr
, SIZE
*size
)
331 static const WCHAR strA
[] = { 'A', 0 };
335 mydc
= GetDC (0); /* why the entire screen???? */
336 nfont
= (HFONT
)SendMessageW (infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
337 ofont
= SelectObject (mydc
, nfont
);
338 GetTextExtentPointW (mydc
, strA
, 1, size
);
339 SelectObject (mydc
, ofont
);
341 TRACE("selected font hwnd=%p, height=%d\n", nfont
, size
->cy
);
345 static void COMBOEX_CopyItem (const CBE_ITEMDATA
*item
, COMBOBOXEXITEMW
*cit
)
347 if (cit
->mask
& CBEIF_TEXT
) {
349 * when given a text buffer actually use that buffer
352 if (is_textW(item
->pszText
))
353 lstrcpynW(cit
->pszText
, item
->pszText
, cit
->cchTextMax
);
357 cit
->pszText
= item
->pszText
;
358 cit
->cchTextMax
= item
->cchTextMax
;
361 if (cit
->mask
& CBEIF_IMAGE
)
362 cit
->iImage
= item
->iImage
;
363 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
364 cit
->iSelectedImage
= item
->iSelectedImage
;
365 if (cit
->mask
& CBEIF_OVERLAY
)
366 cit
->iOverlay
= item
->iOverlay
;
367 if (cit
->mask
& CBEIF_INDENT
)
368 cit
->iIndent
= item
->iIndent
;
369 if (cit
->mask
& CBEIF_LPARAM
)
370 cit
->lParam
= item
->lParam
;
374 static void COMBOEX_AdjustEditPos (const COMBOEX_INFO
*infoPtr
)
377 INT x
, y
, w
, h
, xioff
;
380 if (!infoPtr
->hwndEdit
) return;
382 if (infoPtr
->himl
&& !(infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGEINDENT
)) {
384 iinfo
.rcImage
.left
= iinfo
.rcImage
.right
= 0;
385 ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
);
386 xioff
= iinfo
.rcImage
.right
- iinfo
.rcImage
.left
+ CBE_SEP
;
389 GetClientRect (infoPtr
->hwndCombo
, &rect
);
390 InflateRect (&rect
, -2, -2);
391 InvalidateRect (infoPtr
->hwndCombo
, &rect
, TRUE
);
393 /* reposition the Edit control based on whether icon exists */
394 COMBOEX_GetComboFontSize (infoPtr
, &mysize
);
395 TRACE("Combo font x=%d, y=%d\n", mysize
.cx
, mysize
.cy
);
396 x
= xioff
+ CBE_STARTOFFSET
+ 1;
397 w
= rect
.right
-rect
.left
- x
- GetSystemMetrics(SM_CXVSCROLL
) - 1;
399 y
= rect
.bottom
- h
- 1;
401 TRACE("Combo client (%s), setting Edit to (%d,%d)-(%d,%d)\n",
402 wine_dbgstr_rect(&rect
), x
, y
, x
+ w
, y
+ h
);
403 SetWindowPos(infoPtr
->hwndEdit
, HWND_TOP
, x
, y
, w
, h
,
404 SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
408 static void COMBOEX_ReSize (const COMBOEX_INFO
*infoPtr
)
414 COMBOEX_GetComboFontSize (infoPtr
, &mysize
);
415 cy
= mysize
.cy
+ CBE_EXTRA
;
416 if (infoPtr
->himl
&& ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
)) {
417 cy
= max (iinfo
.rcImage
.bottom
- iinfo
.rcImage
.top
, cy
);
418 TRACE("upgraded height due to image: height=%d\n", cy
);
420 SendMessageW (infoPtr
->hwndSelf
, CB_SETITEMHEIGHT
, -1, cy
);
421 if (infoPtr
->hwndCombo
) {
422 SendMessageW (infoPtr
->hwndCombo
, CB_SETITEMHEIGHT
, 0, cy
);
423 if ( !(infoPtr
->flags
& CBES_EX_NOSIZELIMIT
)) {
424 RECT comboRect
, ourRect
;
425 GetWindowRect(infoPtr
->hwndCombo
, &comboRect
);
426 GetWindowRect(infoPtr
->hwndSelf
, &ourRect
);
427 if (comboRect
.bottom
> ourRect
.bottom
)
428 SetWindowPos( infoPtr
->hwndSelf
, 0, 0, 0, ourRect
.right
- ourRect
.left
,
429 comboRect
.bottom
- comboRect
.top
,
430 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
436 static void COMBOEX_SetEditText (const COMBOEX_INFO
*infoPtr
, CBE_ITEMDATA
*item
)
438 if (!infoPtr
->hwndEdit
) return;
440 if (item
->mask
& CBEIF_TEXT
) {
441 SendMessageW (infoPtr
->hwndEdit
, WM_SETTEXT
, 0, (LPARAM
)COMBOEX_GetText(infoPtr
, item
));
442 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, 0);
443 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
448 static CBE_ITEMDATA
*COMBOEX_FindItem(COMBOEX_INFO
*infoPtr
, INT_PTR index
)
453 if ((index
>= infoPtr
->nb_items
) || (index
< -1))
456 return &infoPtr
->edit
;
457 item
= infoPtr
->items
;
458 i
= infoPtr
->nb_items
- 1;
460 /* find the item in the list */
461 while (item
&& (i
> index
)) {
465 if (!item
|| (i
!= index
)) {
466 ERR("COMBOBOXEX item structures broken. Please report!\n");
472 /* *** CBEM_xxx message support *** */
474 static UINT
COMBOEX_GetListboxText(COMBOEX_INFO
*infoPtr
, INT_PTR n
, LPWSTR buf
)
479 item
= COMBOEX_FindItem(infoPtr
, n
);
483 str
= COMBOEX_GetText(infoPtr
, item
);
488 if (infoPtr
->unicode
)
496 if (infoPtr
->unicode
)
500 return lstrlenW(str
);
505 r
= WideCharToMultiByte(CP_ACP
, 0, str
, -1, (LPSTR
)buf
, 0x40000000, NULL
, NULL
);
512 static INT
COMBOEX_DeleteItem (COMBOEX_INFO
*infoPtr
, INT_PTR index
)
514 TRACE("(index=%ld)\n", index
);
516 /* if item number requested does not exist then return failure */
517 if ((index
>= infoPtr
->nb_items
) || (index
< 0)) return CB_ERR
;
518 if (!COMBOEX_FindItem(infoPtr
, index
)) return CB_ERR
;
520 /* doing this will result in WM_DELETEITEM being issued */
521 SendMessageW (infoPtr
->hwndCombo
, CB_DELETESTRING
, index
, 0);
523 return infoPtr
->nb_items
;
527 static BOOL
COMBOEX_GetItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
*cit
)
529 INT_PTR index
= cit
->iItem
;
534 /* if item number requested does not exist then return failure */
535 if ((index
>= infoPtr
->nb_items
) || (index
< -1)) return FALSE
;
537 /* if the item is the edit control and there is no edit control, skip */
538 if ((index
== -1) && !infoPtr
->hwndEdit
) return FALSE
;
540 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return FALSE
;
542 COMBOEX_CopyItem (item
, cit
);
548 static BOOL
COMBOEX_GetItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
*cit
)
550 COMBOBOXEXITEMW tmpcit
;
554 tmpcit
.mask
= cit
->mask
;
555 tmpcit
.iItem
= cit
->iItem
;
557 if(!COMBOEX_GetItemW (infoPtr
, &tmpcit
)) return FALSE
;
559 if (cit
->mask
& CBEIF_TEXT
)
561 if (is_textW(tmpcit
.pszText
) && cit
->pszText
)
562 WideCharToMultiByte(CP_ACP
, 0, tmpcit
.pszText
, -1,
563 cit
->pszText
, cit
->cchTextMax
, NULL
, NULL
);
564 else if (cit
->pszText
) cit
->pszText
[0] = 0;
565 else cit
->pszText
= (LPSTR
)tmpcit
.pszText
;
568 if (cit
->mask
& CBEIF_IMAGE
)
569 cit
->iImage
= tmpcit
.iImage
;
570 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
571 cit
->iSelectedImage
= tmpcit
.iSelectedImage
;
572 if (cit
->mask
& CBEIF_OVERLAY
)
573 cit
->iOverlay
= tmpcit
.iOverlay
;
574 if (cit
->mask
& CBEIF_INDENT
)
575 cit
->iIndent
= tmpcit
.iIndent
;
576 if (cit
->mask
& CBEIF_LPARAM
)
577 cit
->lParam
= tmpcit
.lParam
;
583 static inline BOOL
COMBOEX_HasEditChanged (COMBOEX_INFO
const *infoPtr
)
585 return infoPtr
->hwndEdit
&& (infoPtr
->flags
& WCBE_EDITHASCHANGED
) == WCBE_EDITHASCHANGED
;
589 static INT
COMBOEX_InsertItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
const *cit
)
597 if (TRACE_ON(comboex
)) COMBOEX_DumpInput (cit
);
599 /* get real index of item to insert */
601 if (index
== -1) index
= infoPtr
->nb_items
;
602 if (index
> infoPtr
->nb_items
) return -1;
604 /* get zero-filled space and chain it in */
605 if(!(item
= Alloc (sizeof(*item
)))) return -1;
607 /* locate position to insert new item in */
608 if (index
== infoPtr
->nb_items
) {
609 /* fast path for iItem = -1 */
610 item
->next
= infoPtr
->items
;
611 infoPtr
->items
= item
;
614 INT i
= infoPtr
->nb_items
-1;
615 CBE_ITEMDATA
*moving
= infoPtr
->items
;
617 while ((i
> index
) && moving
) {
618 moving
= moving
->next
;
622 ERR("COMBOBOXEX item structures broken. Please report!\n");
626 item
->next
= moving
->next
;
630 /* fill in our hidden item structure */
631 item
->mask
= cit
->mask
;
632 if (item
->mask
& CBEIF_TEXT
) {
635 if (is_textW(cit
->pszText
)) len
= strlenW (cit
->pszText
);
637 item
->pszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
638 if (!item
->pszText
) {
642 strcpyW (item
->pszText
, cit
->pszText
);
644 else if (cit
->pszText
== LPSTR_TEXTCALLBACKW
)
645 item
->pszText
= LPSTR_TEXTCALLBACKW
;
646 item
->cchTextMax
= cit
->cchTextMax
;
648 if (item
->mask
& CBEIF_IMAGE
)
649 item
->iImage
= cit
->iImage
;
650 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
651 item
->iSelectedImage
= cit
->iSelectedImage
;
652 if (item
->mask
& CBEIF_OVERLAY
)
653 item
->iOverlay
= cit
->iOverlay
;
654 if (item
->mask
& CBEIF_INDENT
)
655 item
->iIndent
= cit
->iIndent
;
656 if (item
->mask
& CBEIF_LPARAM
)
657 item
->lParam
= cit
->lParam
;
660 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
662 SendMessageW (infoPtr
->hwndCombo
, CB_INSERTSTRING
, cit
->iItem
, (LPARAM
)item
);
664 memset (&nmcit
.ceItem
, 0, sizeof(nmcit
.ceItem
));
665 nmcit
.ceItem
.mask
=~0;
666 COMBOEX_CopyItem (item
, &nmcit
.ceItem
);
667 COMBOEX_NotifyItem (infoPtr
, CBEN_INSERTITEM
, &nmcit
);
674 static INT
COMBOEX_InsertItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
const *cit
)
676 COMBOBOXEXITEMW citW
;
680 memcpy(&citW
,cit
,sizeof(COMBOBOXEXITEMA
));
681 if (cit
->mask
& CBEIF_TEXT
&& is_textA(cit
->pszText
)) {
682 INT len
= MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, NULL
, 0);
683 wstr
= Alloc ((len
+ 1)*sizeof(WCHAR
));
684 if (!wstr
) return -1;
685 MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, wstr
, len
);
688 ret
= COMBOEX_InsertItemW(infoPtr
, &citW
);
697 COMBOEX_SetExtendedStyle (COMBOEX_INFO
*infoPtr
, DWORD mask
, DWORD style
)
701 TRACE("(mask=x%08x, style=0x%08x)\n", mask
, style
);
703 dwTemp
= infoPtr
->dwExtStyle
;
706 infoPtr
->dwExtStyle
= (infoPtr
->dwExtStyle
& ~mask
) | style
;
708 infoPtr
->dwExtStyle
= style
;
710 /* see if we need to change the word break proc on the edit */
711 if ((infoPtr
->dwExtStyle
^ dwTemp
) & CBES_EX_PATHWORDBREAKPROC
)
712 SetPathWordBreakProc(infoPtr
->hwndEdit
,
713 (infoPtr
->dwExtStyle
& CBES_EX_PATHWORDBREAKPROC
) != 0);
715 /* test if the control's appearance has changed */
716 mask
= CBES_EX_NOEDITIMAGE
| CBES_EX_NOEDITIMAGEINDENT
;
717 if ((infoPtr
->dwExtStyle
& mask
) != (dwTemp
& mask
)) {
718 /* if state of EX_NOEDITIMAGE changes, invalidate all */
719 TRACE("EX_NOEDITIMAGE state changed to %d\n",
720 infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGE
);
721 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
722 COMBOEX_AdjustEditPos (infoPtr
);
723 if (infoPtr
->hwndEdit
)
724 InvalidateRect (infoPtr
->hwndEdit
, NULL
, TRUE
);
731 static HIMAGELIST
COMBOEX_SetImageList (COMBOEX_INFO
*infoPtr
, HIMAGELIST himl
)
733 HIMAGELIST himlTemp
= infoPtr
->himl
;
737 infoPtr
->himl
= himl
;
739 COMBOEX_ReSize (infoPtr
);
740 InvalidateRect (infoPtr
->hwndCombo
, NULL
, TRUE
);
742 /* reposition the Edit control based on whether icon exists */
743 COMBOEX_AdjustEditPos (infoPtr
);
747 static BOOL
COMBOEX_SetItemW (COMBOEX_INFO
*infoPtr
, const COMBOBOXEXITEMW
*cit
)
749 INT_PTR index
= cit
->iItem
;
752 if (TRACE_ON(comboex
)) COMBOEX_DumpInput (cit
);
754 /* if item number requested does not exist then return failure */
755 if ((index
>= infoPtr
->nb_items
) || (index
< -1)) return FALSE
;
757 /* if the item is the edit control and there is no edit control, skip */
758 if ((index
== -1) && !infoPtr
->hwndEdit
) return FALSE
;
760 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return FALSE
;
762 /* add/change stuff to the internal item structure */
763 item
->mask
|= cit
->mask
;
764 if (cit
->mask
& CBEIF_TEXT
) {
767 COMBOEX_FreeText(item
);
768 if (is_textW(cit
->pszText
)) len
= strlenW(cit
->pszText
);
770 item
->pszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
771 if (!item
->pszText
) return FALSE
;
772 strcpyW(item
->pszText
, cit
->pszText
);
773 } else if (cit
->pszText
== LPSTR_TEXTCALLBACKW
)
774 item
->pszText
= LPSTR_TEXTCALLBACKW
;
775 item
->cchTextMax
= cit
->cchTextMax
;
777 if (cit
->mask
& CBEIF_IMAGE
)
778 item
->iImage
= cit
->iImage
;
779 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
780 item
->iSelectedImage
= cit
->iSelectedImage
;
781 if (cit
->mask
& CBEIF_OVERLAY
)
782 item
->iOverlay
= cit
->iOverlay
;
783 if (cit
->mask
& CBEIF_INDENT
)
784 item
->iIndent
= cit
->iIndent
;
785 if (cit
->mask
& CBEIF_LPARAM
)
786 item
->lParam
= cit
->lParam
;
788 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
790 /* if original request was to update edit control, do some fast foot work */
791 if (cit
->iItem
== -1 && cit
->mask
& CBEIF_TEXT
) {
792 COMBOEX_SetEditText (infoPtr
, item
);
793 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
| RDW_INVALIDATE
);
798 static BOOL
COMBOEX_SetItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
const *cit
)
800 COMBOBOXEXITEMW citW
;
804 memcpy(&citW
, cit
, sizeof(COMBOBOXEXITEMA
));
805 if ((cit
->mask
& CBEIF_TEXT
) && is_textA(cit
->pszText
)) {
806 INT len
= MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, NULL
, 0);
807 wstr
= Alloc ((len
+ 1)*sizeof(WCHAR
));
808 if (!wstr
) return FALSE
;
809 MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, wstr
, len
);
812 ret
= COMBOEX_SetItemW(infoPtr
, &citW
);
820 static BOOL
COMBOEX_SetUnicodeFormat (COMBOEX_INFO
*infoPtr
, BOOL value
)
822 BOOL bTemp
= infoPtr
->unicode
;
824 TRACE("to %s, was %s\n", value
? "TRUE":"FALSE", bTemp
? "TRUE":"FALSE");
826 infoPtr
->unicode
= value
;
832 /* *** CB_xxx message support *** */
835 COMBOEX_FindStringExact (const COMBOEX_INFO
*infoPtr
, INT start
, LPCWSTR str
)
838 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
839 INT count
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCOUNT
, 0, 0);
841 /* now search from after starting loc and wrapping back to start */
842 for(i
=start
+1; i
<count
; i
++) {
843 CBE_ITEMDATA
*item
= get_item_data(infoPtr
, i
);
844 if ((LRESULT
)item
== CB_ERR
) continue;
845 if (cmptext(COMBOEX_GetText(infoPtr
, item
), str
) == 0) return i
;
847 for(i
=0; i
<=start
; i
++) {
848 CBE_ITEMDATA
*item
= get_item_data(infoPtr
, i
);
849 if ((LRESULT
)item
== CB_ERR
) continue;
850 if (cmptext(COMBOEX_GetText(infoPtr
, item
), str
) == 0) return i
;
856 static DWORD_PTR
COMBOEX_GetItemData (COMBOEX_INFO
*infoPtr
, INT_PTR index
)
858 CBE_ITEMDATA
const *item1
;
859 CBE_ITEMDATA
const *item2
;
862 item1
= get_item_data(infoPtr
, index
);
863 if ((item1
!= NULL
) && ((LRESULT
)item1
!= CB_ERR
)) {
864 item2
= COMBOEX_FindItem (infoPtr
, index
);
865 if (item2
!= item1
) {
866 ERR("data structures damaged!\n");
869 if (item1
->mask
& CBEIF_LPARAM
) ret
= item1
->lParam
;
870 TRACE("returning 0x%08lx\n", ret
);
872 ret
= (DWORD_PTR
)item1
;
873 TRACE("non-valid result from combo, returning 0x%08lx\n", ret
);
879 static INT
COMBOEX_SetCursel (COMBOEX_INFO
*infoPtr
, INT_PTR index
)
884 if (!(item
= COMBOEX_FindItem(infoPtr
, index
)))
885 return SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, index
, 0);
887 TRACE("selecting item %ld text=%s\n", index
, debugstr_txt(item
->pszText
));
888 infoPtr
->selected
= index
;
890 sel
= (INT
)SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, index
, 0);
891 COMBOEX_SetEditText (infoPtr
, item
);
896 static DWORD_PTR
COMBOEX_SetItemData (COMBOEX_INFO
*infoPtr
, INT_PTR index
, DWORD_PTR data
)
899 CBE_ITEMDATA
const *item2
;
901 item1
= get_item_data(infoPtr
, index
);
902 if ((item1
!= NULL
) && ((LRESULT
)item1
!= CB_ERR
)) {
903 item2
= COMBOEX_FindItem (infoPtr
, index
);
904 if (item2
!= item1
) {
905 ERR("data structures damaged!\n");
908 item1
->mask
|= CBEIF_LPARAM
;
909 item1
->lParam
= data
;
910 TRACE("setting lparam to 0x%08lx\n", data
);
913 TRACE("non-valid result from combo %p\n", item1
);
914 return (DWORD_PTR
)item1
;
918 static INT
COMBOEX_SetItemHeight (COMBOEX_INFO
const *infoPtr
, INT index
, UINT height
)
920 RECT cb_wrect
, cbx_wrect
, cbx_crect
;
922 /* First, lets forward the message to the normal combo control
923 just like Windows. */
924 if (infoPtr
->hwndCombo
)
925 if (SendMessageW (infoPtr
->hwndCombo
, CB_SETITEMHEIGHT
,
926 index
, height
) == CB_ERR
) return CB_ERR
;
928 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
929 GetWindowRect (infoPtr
->hwndSelf
, &cbx_wrect
);
930 GetClientRect (infoPtr
->hwndSelf
, &cbx_crect
);
931 /* the height of comboex as height of the combo + comboex border */
932 height
= cb_wrect
.bottom
-cb_wrect
.top
933 + cbx_wrect
.bottom
-cbx_wrect
.top
934 - (cbx_crect
.bottom
-cbx_crect
.top
);
935 TRACE("EX window=(%s), client=(%s)\n",
936 wine_dbgstr_rect(&cbx_wrect
), wine_dbgstr_rect(&cbx_crect
));
937 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
938 wine_dbgstr_rect(&cbx_wrect
), cbx_wrect
.right
-cbx_wrect
.left
, height
);
939 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0,
940 cbx_wrect
.right
-cbx_wrect
.left
, height
,
941 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOMOVE
);
947 /* *** WM_xxx message support *** */
950 static LRESULT
COMBOEX_Create (HWND hwnd
, CREATESTRUCTA
const *cs
)
952 static const WCHAR NIL
[] = { 0 };
953 COMBOEX_INFO
*infoPtr
;
958 /* allocate memory for info structure */
959 infoPtr
= Alloc (sizeof(COMBOEX_INFO
));
960 if (!infoPtr
) return -1;
962 /* initialize info structure */
963 /* note that infoPtr is allocated zero-filled */
965 infoPtr
->hwndSelf
= hwnd
;
966 infoPtr
->selected
= -1;
968 infoPtr
->unicode
= IsWindowUnicode (hwnd
);
969 infoPtr
->hwndNotify
= cs
->hwndParent
;
971 i
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
972 if ((i
!= NFR_ANSI
) && (i
!= NFR_UNICODE
)) {
973 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i
);
976 infoPtr
->NtfUnicode
= (i
== NFR_UNICODE
);
978 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
980 if (TRACE_ON(comboex
)) {
982 GetWindowRect(hwnd
, &rect
);
983 GetClientRect(hwnd
, &client
);
984 TRACE("EX window=(%s), client=(%s)\n",
985 wine_dbgstr_rect(&rect
), wine_dbgstr_rect(&client
));
988 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
989 /* specified. It then creates its own version of the EDIT control */
990 /* and makes the ComboBox the parent. This is because a normal */
991 /* DROPDOWNLIST does not have an EDIT control, but we need one. */
992 /* We also need to place the edit control at the proper location */
993 /* (allow space for the icons). */
995 infoPtr
->hwndCombo
= CreateWindowW (WC_COMBOBOXW
, NIL
,
996 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| WS_VSCROLL
|
997 CBS_NOINTEGRALHEIGHT
| CBS_DROPDOWNLIST
|
998 WS_CHILD
| WS_VISIBLE
| CBS_OWNERDRAWFIXED
|
999 GetWindowLongW (hwnd
, GWL_STYLE
),
1000 cs
->y
, cs
->x
, cs
->cx
, cs
->cy
, hwnd
,
1001 (HMENU
) GetWindowLongPtrW (hwnd
, GWLP_ID
),
1002 (HINSTANCE
)GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
), NULL
);
1004 SetWindowSubclass(infoPtr
->hwndCombo
, COMBOEX_ComboWndProc
, COMBO_SUBCLASSID
,
1006 infoPtr
->font
= (HFONT
)SendMessageW (infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
1009 * Now create our own EDIT control so we can position it.
1010 * It is created only for CBS_DROPDOWN style
1012 if ((cs
->style
& CBS_DROPDOWNLIST
) == CBS_DROPDOWN
) {
1013 infoPtr
->hwndEdit
= CreateWindowExW (0, WC_EDITW
, NIL
,
1014 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| ES_AUTOHSCROLL
,
1015 0, 0, 0, 0, /* will set later */
1017 (HMENU
) GetWindowLongPtrW (hwnd
, GWLP_ID
),
1018 (HINSTANCE
)GetWindowLongPtrW (hwnd
, GWLP_HINSTANCE
), NULL
);
1020 SetWindowSubclass(infoPtr
->hwndEdit
, COMBOEX_EditWndProc
, EDIT_SUBCLASSID
,
1023 infoPtr
->font
= (HFONT
)SendMessageW(infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
1027 * Locate the default font if necessary and then set it in
1028 * all associated controls
1030 if (!infoPtr
->font
) {
1031 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof(mylogfont
),
1033 infoPtr
->font
= infoPtr
->defaultFont
= CreateFontIndirectW (&mylogfont
);
1035 SendMessageW (infoPtr
->hwndCombo
, WM_SETFONT
, (WPARAM
)infoPtr
->font
, 0);
1036 if (infoPtr
->hwndEdit
) {
1037 SendMessageW (infoPtr
->hwndEdit
, WM_SETFONT
, (WPARAM
)infoPtr
->font
, 0);
1038 SendMessageW (infoPtr
->hwndEdit
, EM_SETMARGINS
, EC_USEFONTINFO
, 0);
1041 COMBOEX_ReSize (infoPtr
);
1043 /* Above is fairly certain, below is much less certain. */
1045 GetWindowRect(hwnd
, &win_rect
);
1047 if (TRACE_ON(comboex
)) {
1049 GetClientRect(hwnd
, &client
);
1050 GetWindowRect(infoPtr
->hwndCombo
, &rect
);
1051 TRACE("EX window=(%s) client=(%s) CB wnd=(%s)\n",
1052 wine_dbgstr_rect(&win_rect
), wine_dbgstr_rect(&client
),
1053 wine_dbgstr_rect(&rect
));
1055 SetWindowPos(infoPtr
->hwndCombo
, HWND_TOP
, 0, 0,
1056 win_rect
.right
- win_rect
.left
, win_rect
.bottom
- win_rect
.top
,
1057 SWP_NOACTIVATE
| SWP_NOREDRAW
);
1059 GetWindowRect(infoPtr
->hwndCombo
, &win_rect
);
1060 TRACE("CB window=(%s)\n", wine_dbgstr_rect(&win_rect
));
1061 SetWindowPos(hwnd
, HWND_TOP
, 0, 0,
1062 win_rect
.right
- win_rect
.left
, win_rect
.bottom
- win_rect
.top
,
1063 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOMOVE
);
1065 COMBOEX_AdjustEditPos (infoPtr
);
1071 static LRESULT
COMBOEX_Command (COMBOEX_INFO
*infoPtr
, WPARAM wParam
)
1074 INT command
= HIWORD(wParam
);
1075 CBE_ITEMDATA
*item
= 0;
1079 NMCBEENDEDITW cbeend
;
1081 HWND parent
= infoPtr
->hwndNotify
;
1083 TRACE("for command %d\n", command
);
1088 SetFocus (infoPtr
->hwndCombo
);
1089 ShowWindow (infoPtr
->hwndEdit
, SW_HIDE
);
1090 infoPtr
->flags
|= WCBE_ACTEDIT
;
1091 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1093 SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1094 ShowWindow (infoPtr
->hwndEdit
, SW_SHOW
);
1095 InvalidateRect (infoPtr
->hwndCombo
, 0, TRUE
);
1096 if (infoPtr
->hwndEdit
) InvalidateRect (infoPtr
->hwndEdit
, 0, TRUE
);
1097 cursel
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1099 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
1100 /* find match from edit against those in Combobox */
1101 GetWindowTextW (infoPtr
->hwndEdit
, wintext
, 520);
1102 n
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCOUNT
, 0, 0);
1103 for (cursel
= 0; cursel
< n
; cursel
++){
1104 item
= get_item_data(infoPtr
, cursel
);
1105 if ((INT_PTR
)item
== CB_ERR
) break;
1106 if (!cmptext(COMBOEX_GetText(infoPtr
, item
), wintext
)) break;
1108 if ((cursel
== n
) || ((INT_PTR
)item
== CB_ERR
)) {
1109 TRACE("failed to find match??? item=%p cursel=%d\n",
1111 if (infoPtr
->hwndEdit
) SetFocus(infoPtr
->hwndEdit
);
1116 item
= get_item_data(infoPtr
, cursel
);
1117 if ((INT_PTR
)item
== CB_ERR
) {
1118 TRACE("failed to find match??? item=%p cursel=%d\n",
1120 if (infoPtr
->hwndEdit
) SetFocus(infoPtr
->hwndEdit
);
1125 /* Save flags for testing and reset them */
1126 oldflags
= infoPtr
->flags
;
1127 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1129 if (oldflags
& WCBE_ACTEDIT
) {
1130 cbeend
.fChanged
= (oldflags
& WCBE_EDITCHG
);
1131 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1132 CB_GETCURSEL
, 0, 0);
1133 cbeend
.iWhy
= CBENF_DROPDOWN
;
1135 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, COMBOEX_GetText(infoPtr
, item
))) return 0;
1138 /* if selection has changed the set the new current selection */
1139 cursel
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1140 if ((oldflags
& WCBE_EDITCHG
) || (cursel
!= infoPtr
->selected
)) {
1141 infoPtr
->selected
= cursel
;
1142 SendMessageW (infoPtr
->hwndSelf
, CB_SETCURSEL
, cursel
, 0);
1143 SetFocus(infoPtr
->hwndCombo
);
1149 * CB_GETCURSEL(Combo)
1150 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1153 * WM_GETTEXTLENGTH(Edit)
1155 * EM_SETSEL(Edit, 0,0)
1156 * WM_GETTEXTLENGTH(Edit)
1158 * EM_SETSEL(Edit, 0,len)
1159 * return WM_COMMAND to parent
1161 oldItem
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1162 if (!(item
= COMBOEX_FindItem(infoPtr
, oldItem
))) {
1163 ERR("item %ld not found. Problem!\n", oldItem
);
1166 infoPtr
->selected
= oldItem
;
1167 COMBOEX_SetEditText (infoPtr
, item
);
1168 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1171 case CBN_SELENDCANCEL
:
1173 * We have to change the handle since we are the control
1174 * issuing the message. IE4 depends on this.
1176 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1179 SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1180 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1181 GetWindowTextW (infoPtr
->hwndEdit
, wintext
, 260);
1182 cbeend
.fChanged
= (infoPtr
->flags
& WCBE_EDITCHG
);
1183 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1184 CB_GETCURSEL
, 0, 0);
1185 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1187 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1188 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, wintext
)) return 0;
1190 /* possible CB_GETCURSEL */
1191 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1195 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1199 * We have to change the handle since we are the control
1200 * issuing the message. IE4 depends on this.
1201 * We also need to set the focus back to the Edit control
1202 * after passing the command to the parent of the ComboEx.
1204 lret
= SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1205 if (infoPtr
->hwndEdit
) SetFocus(infoPtr
->hwndEdit
);
1212 static BOOL
COMBOEX_WM_DeleteItem (COMBOEX_INFO
*infoPtr
, DELETEITEMSTRUCT
const *dis
)
1214 CBE_ITEMDATA
*item
, *olditem
;
1215 NMCOMBOBOXEXW nmcit
;
1218 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
1219 dis
->CtlType
, dis
->CtlID
, dis
->itemID
, dis
->hwndItem
, dis
->itemData
);
1221 if (dis
->itemID
>= infoPtr
->nb_items
) return FALSE
;
1223 olditem
= infoPtr
->items
;
1224 i
= infoPtr
->nb_items
- 1;
1226 if (i
== dis
->itemID
) {
1227 infoPtr
->items
= infoPtr
->items
->next
;
1233 /* find the prior item in the list */
1234 while (item
->next
&& (i
> dis
->itemID
)) {
1238 if (!item
->next
|| (i
!= dis
->itemID
)) {
1239 ERR("COMBOBOXEX item structures broken. Please report!\n");
1242 olditem
= item
->next
;
1243 item
->next
= item
->next
->next
;
1245 infoPtr
->nb_items
--;
1247 memset (&nmcit
.ceItem
, 0, sizeof(nmcit
.ceItem
));
1248 nmcit
.ceItem
.mask
=~0;
1249 COMBOEX_CopyItem (olditem
, &nmcit
.ceItem
);
1250 COMBOEX_NotifyItem (infoPtr
, CBEN_DELETEITEM
, &nmcit
);
1252 COMBOEX_FreeText(olditem
);
1259 static LRESULT
COMBOEX_DrawItem (COMBOEX_INFO
*infoPtr
, DRAWITEMSTRUCT
const *dis
)
1261 static const WCHAR nil
[] = { 0 };
1262 CBE_ITEMDATA
*item
= NULL
;
1268 COLORREF nbkc
, ntxc
, bkc
, txc
;
1269 int drawimage
, drawstate
, xioff
, selected
;
1271 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1272 dis
->CtlType
, dis
->CtlID
);
1273 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1274 dis
->itemID
, dis
->itemAction
, dis
->itemState
);
1275 TRACE("hWnd=%p hDC=%p (%s) itemData=0x%08lx\n",
1276 dis
->hwndItem
, dis
->hDC
, wine_dbgstr_rect(&dis
->rcItem
), dis
->itemData
);
1279 /* "itemID - Specifies the menu item identifier for a menu */
1280 /* item or the index of the item in a list box or combo box. */
1281 /* For an empty list box or combo box, this member can be -1. */
1282 /* This allows the application to draw only the focus */
1283 /* rectangle at the coordinates specified by the rcItem */
1284 /* member even though there are no items in the control. */
1285 /* This indicates to the user whether the list box or combo */
1286 /* box has the focus. How the bits are set in the itemAction */
1287 /* member determines whether the rectangle is to be drawn as */
1288 /* though the list box or combo box has the focus. */
1289 if (dis
->itemID
== 0xffffffff) {
1290 if ( ( (dis
->itemAction
& ODA_FOCUS
) && (dis
->itemState
& ODS_SELECTED
)) ||
1291 ( (dis
->itemAction
& (ODA_SELECT
| ODA_DRAWENTIRE
)) && (dis
->itemState
& ODS_FOCUS
) ) ) {
1293 TRACE("drawing item -1 special focus, rect=(%s)\n",
1294 wine_dbgstr_rect(&dis
->rcItem
));
1296 else if ((dis
->CtlType
== ODT_COMBOBOX
) &&
1297 (dis
->itemAction
== ODA_DRAWENTIRE
)) {
1298 /* draw of edit control data */
1300 if (TRACE_ON(comboex
)) {
1301 RECT exrc
, cbrc
, edrc
;
1302 GetWindowRect (infoPtr
->hwndSelf
, &exrc
);
1303 GetWindowRect (infoPtr
->hwndCombo
, &cbrc
);
1304 SetRect(&edrc
, -1, -1, -1, -1);
1305 if (infoPtr
->hwndEdit
) GetWindowRect (infoPtr
->hwndEdit
, &edrc
);
1306 TRACE("window rects ex=(%s), cb=(%s), ed=(%s)\n",
1307 wine_dbgstr_rect(&exrc
), wine_dbgstr_rect(&cbrc
),
1308 wine_dbgstr_rect(&edrc
));
1312 ERR("NOT drawing item -1 special focus, rect=(%s), action=%08x, state=%08x\n",
1313 wine_dbgstr_rect(&dis
->rcItem
),
1314 dis
->itemAction
, dis
->itemState
);
1319 /* If draw item is -1 (edit control) setup the item pointer */
1320 if (dis
->itemID
== 0xffffffff) {
1321 item
= &infoPtr
->edit
;
1323 if (infoPtr
->hwndEdit
) {
1324 /* free previous text of edit item */
1325 COMBOEX_FreeText(item
);
1326 item
->mask
&= ~CBEIF_TEXT
;
1327 if( (len
= GetWindowTextLengthW(infoPtr
->hwndEdit
)) ) {
1328 item
->mask
|= CBEIF_TEXT
;
1329 item
->pszText
= Alloc ((len
+ 1)*sizeof(WCHAR
));
1331 GetWindowTextW(infoPtr
->hwndEdit
, item
->pszText
, len
+1);
1333 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
1334 infoPtr
->hwndEdit
, len
, debugstr_txt(item
->pszText
));
1340 /* if the item pointer is not set, then get the data and locate it */
1342 item
= get_item_data(infoPtr
, dis
->itemID
);
1343 if (item
== (CBE_ITEMDATA
*)CB_ERR
) {
1344 ERR("invalid item for id %d\n", dis
->itemID
);
1349 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
1351 xbase
= CBE_STARTOFFSET
;
1352 if ((item
->mask
& CBEIF_INDENT
) && (dis
->itemState
& ODS_COMBOEXLBOX
)) {
1353 INT indent
= item
->iIndent
;
1354 if (indent
== I_INDENTCALLBACK
) {
1356 ZeroMemory(&nmce
, sizeof(nmce
));
1357 nmce
.ceItem
.mask
= CBEIF_INDENT
;
1358 nmce
.ceItem
.lParam
= item
->lParam
;
1359 nmce
.ceItem
.iItem
= dis
->itemID
;
1360 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1361 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
1362 item
->iIndent
= nmce
.ceItem
.iIndent
;
1363 indent
= nmce
.ceItem
.iIndent
;
1365 xbase
+= (indent
* CBE_INDENT
);
1369 drawstate
= ILD_NORMAL
;
1370 selected
= infoPtr
->selected
== dis
->itemID
;
1372 if (item
->mask
& CBEIF_IMAGE
)
1373 drawimage
= item
->iImage
;
1374 if (item
->mask
& CBEIF_SELECTEDIMAGE
&& selected
)
1375 drawimage
= item
->iSelectedImage
;
1376 if (dis
->itemState
& ODS_COMBOEXLBOX
) {
1377 /* drawing listbox entry */
1378 if (dis
->itemState
& ODS_SELECTED
)
1379 drawstate
= ILD_SELECTED
;
1381 /* drawing combo/edit entry */
1382 if (IsWindowVisible(infoPtr
->hwndEdit
)) {
1383 /* if we have an edit control, the slave the
1384 * selection state to the Edit focus state
1386 if (infoPtr
->flags
& WCBE_EDITFOCUSED
)
1387 drawstate
= ILD_SELECTED
;
1389 /* if we don't have an edit control, use
1390 * the requested state.
1392 if (dis
->itemState
& ODS_SELECTED
)
1393 drawstate
= ILD_SELECTED
;
1396 if (infoPtr
->himl
&& !(infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGEINDENT
)) {
1398 iinfo
.rcImage
.left
= iinfo
.rcImage
.right
= 0;
1399 ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
);
1400 xioff
= iinfo
.rcImage
.right
- iinfo
.rcImage
.left
+ CBE_SEP
;
1403 /* setup pointer to text to be drawn */
1404 str
= COMBOEX_GetText(infoPtr
, item
);
1405 if (!str
) str
= nil
;
1407 len
= strlenW (str
);
1408 GetTextExtentPoint32W (dis
->hDC
, str
, len
, &txtsize
);
1410 if (dis
->itemAction
& (ODA_SELECT
| ODA_DRAWENTIRE
)) {
1411 int overlay
= item
->iOverlay
;
1413 if (drawimage
== I_IMAGECALLBACK
) {
1415 ZeroMemory(&nmce
, sizeof(nmce
));
1416 nmce
.ceItem
.mask
= selected
? CBEIF_SELECTEDIMAGE
: CBEIF_IMAGE
;
1417 nmce
.ceItem
.lParam
= item
->lParam
;
1418 nmce
.ceItem
.iItem
= dis
->itemID
;
1419 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1421 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) item
->iImage
= nmce
.ceItem
.iImage
;
1422 drawimage
= nmce
.ceItem
.iImage
;
1424 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) item
->iSelectedImage
= nmce
.ceItem
.iSelectedImage
;
1425 drawimage
= nmce
.ceItem
.iSelectedImage
;
1429 if (overlay
== I_IMAGECALLBACK
) {
1431 ZeroMemory(&nmce
, sizeof(nmce
));
1432 nmce
.ceItem
.mask
= CBEIF_OVERLAY
;
1433 nmce
.ceItem
.lParam
= item
->lParam
;
1434 nmce
.ceItem
.iItem
= dis
->itemID
;
1435 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1436 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
1437 item
->iOverlay
= nmce
.ceItem
.iOverlay
;
1438 overlay
= nmce
.ceItem
.iOverlay
;
1441 if (drawimage
>= 0 &&
1442 !(infoPtr
->dwExtStyle
& (CBES_EX_NOEDITIMAGE
| CBES_EX_NOEDITIMAGEINDENT
))) {
1443 if (overlay
> 0) ImageList_SetOverlayImage (infoPtr
->himl
, overlay
, 1);
1444 ImageList_Draw (infoPtr
->himl
, drawimage
, dis
->hDC
, xbase
, dis
->rcItem
.top
,
1445 drawstate
| (overlay
> 0 ? INDEXTOOVERLAYMASK(1) : 0));
1448 /* now draw the text */
1449 if (!IsWindowVisible (infoPtr
->hwndEdit
)) {
1450 nbkc
= (dis
->itemState
& ODS_SELECTED
) ?
1451 comctl32_color
.clrHighlight
: comctl32_color
.clrWindow
;
1452 bkc
= SetBkColor (dis
->hDC
, nbkc
);
1453 ntxc
= (dis
->itemState
& ODS_SELECTED
) ?
1454 comctl32_color
.clrHighlightText
: comctl32_color
.clrWindowText
;
1455 txc
= SetTextColor (dis
->hDC
, ntxc
);
1457 y
= dis
->rcItem
.top
+
1458 (dis
->rcItem
.bottom
- dis
->rcItem
.top
- txtsize
.cy
) / 2;
1459 SetRect(&rect
, x
, dis
->rcItem
.top
+ 1, x
+ txtsize
.cx
, dis
->rcItem
.bottom
- 1);
1460 TRACE("drawing item %d text, rect=(%s)\n",
1461 dis
->itemID
, wine_dbgstr_rect(&rect
));
1462 ExtTextOutW (dis
->hDC
, x
, y
, ETO_OPAQUE
| ETO_CLIPPED
,
1463 &rect
, str
, len
, 0);
1464 SetBkColor (dis
->hDC
, bkc
);
1465 SetTextColor (dis
->hDC
, txc
);
1469 if (dis
->itemAction
& ODA_FOCUS
) {
1470 rect
.left
= xbase
+ xioff
- 1;
1471 rect
.right
= rect
.left
+ txtsize
.cx
+ 2;
1472 rect
.top
= dis
->rcItem
.top
;
1473 rect
.bottom
= dis
->rcItem
.bottom
;
1474 DrawFocusRect(dis
->hDC
, &rect
);
1481 static void COMBOEX_ResetContent (COMBOEX_INFO
*infoPtr
)
1485 CBE_ITEMDATA
*item
, *next
;
1487 item
= infoPtr
->items
;
1490 COMBOEX_FreeText (item
);
1497 infoPtr
->selected
= -1;
1498 infoPtr
->nb_items
= 0;
1502 static LRESULT
COMBOEX_Destroy (COMBOEX_INFO
*infoPtr
)
1504 if (infoPtr
->hwndCombo
)
1505 SetWindowSubclass(infoPtr
->hwndCombo
, COMBOEX_ComboWndProc
, COMBO_SUBCLASSID
, 0);
1507 if (infoPtr
->hwndEdit
)
1508 SetWindowSubclass(infoPtr
->hwndEdit
, COMBOEX_EditWndProc
, EDIT_SUBCLASSID
, 0);
1510 COMBOEX_FreeText (&infoPtr
->edit
);
1511 COMBOEX_ResetContent (infoPtr
);
1513 if (infoPtr
->defaultFont
)
1514 DeleteObject (infoPtr
->defaultFont
);
1516 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1518 /* free comboex info data */
1525 static LRESULT
COMBOEX_Enable (COMBOEX_INFO
*infoPtr
, BOOL enable
)
1527 TRACE("hwnd=%p, enable=%s\n", infoPtr
->hwndSelf
, enable
? "TRUE":"FALSE");
1529 if (infoPtr
->hwndEdit
)
1530 EnableWindow(infoPtr
->hwndEdit
, enable
);
1532 EnableWindow(infoPtr
->hwndCombo
, enable
);
1534 /* Force the control to repaint when the enabled state changes. */
1535 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1541 static LRESULT
COMBOEX_MeasureItem (COMBOEX_INFO
const *infoPtr
, MEASUREITEMSTRUCT
*mis
)
1543 static const WCHAR strW
[] = { 'W', 0 };
1548 GetTextExtentPointW (hdc
, strW
, 1, &mysize
);
1550 mis
->itemHeight
= mysize
.cy
+ CBE_EXTRA
;
1552 TRACE("adjusted height hwnd=%p, height=%d\n",
1553 infoPtr
->hwndSelf
, mis
->itemHeight
);
1559 static LRESULT
COMBOEX_NCCreate (HWND hwnd
)
1561 /* WARNING: The COMBOEX_INFO structure is not yet created */
1562 DWORD oldstyle
, newstyle
;
1564 oldstyle
= (DWORD
)GetWindowLongW (hwnd
, GWL_STYLE
);
1565 newstyle
= oldstyle
& ~(WS_VSCROLL
| WS_HSCROLL
| WS_BORDER
);
1566 if (newstyle
!= oldstyle
) {
1567 TRACE("req style %08x, resetting style %08x\n",
1568 oldstyle
, newstyle
);
1569 SetWindowLongW (hwnd
, GWL_STYLE
, newstyle
);
1575 static LRESULT
COMBOEX_NotifyFormat (COMBOEX_INFO
*infoPtr
, LPARAM lParam
)
1577 if (lParam
== NF_REQUERY
) {
1578 INT i
= SendMessageW(infoPtr
->hwndNotify
,
1579 WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1580 infoPtr
->NtfUnicode
= (i
== NFR_UNICODE
);
1582 return infoPtr
->NtfUnicode
? NFR_UNICODE
: NFR_ANSI
;
1586 static LRESULT
COMBOEX_Size (COMBOEX_INFO
*infoPtr
, INT width
, INT height
)
1588 TRACE("(width=%d, height=%d)\n", width
, height
);
1590 MoveWindow (infoPtr
->hwndCombo
, 0, 0, width
, height
, TRUE
);
1592 COMBOEX_AdjustEditPos (infoPtr
);
1597 static LRESULT
COMBOEX_SetFont( COMBOEX_INFO
*infoPtr
, HFONT font
, BOOL redraw
)
1599 infoPtr
->font
= font
;
1600 SendMessageW( infoPtr
->hwndCombo
, WM_SETFONT
, (WPARAM
)font
, 0 );
1601 if (infoPtr
->hwndEdit
) SendMessageW( infoPtr
->hwndEdit
, WM_SETFONT
, (WPARAM
)font
, 0 );
1602 COMBOEX_ReSize( infoPtr
);
1603 if (redraw
) InvalidateRect( infoPtr
->hwndCombo
, NULL
, TRUE
);
1607 static LRESULT
COMBOEX_SetRedraw(const COMBOEX_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1609 LRESULT ret
= DefWindowProcW( infoPtr
->hwndSelf
, WM_SETREDRAW
, wParam
, lParam
);
1610 if (wParam
) RedrawWindow( infoPtr
->hwndSelf
, NULL
, 0, RDW_INVALIDATE
|RDW_ERASE
|RDW_ALLCHILDREN
);
1615 static LRESULT
COMBOEX_WindowPosChanging (const COMBOEX_INFO
*infoPtr
, WINDOWPOS
*wp
)
1617 RECT cbx_wrect
, cbx_crect
, cb_wrect
;
1620 GetWindowRect (infoPtr
->hwndSelf
, &cbx_wrect
);
1621 GetClientRect (infoPtr
->hwndSelf
, &cbx_crect
);
1622 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
1624 /* width is winpos value + border width of comboex */
1626 + (cbx_wrect
.right
-cbx_wrect
.left
)
1627 - (cbx_crect
.right
-cbx_crect
.left
);
1629 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1630 wp
->x
, wp
->y
, wp
->cx
, wp
->cy
, wp
->flags
);
1631 TRACE("EX window=(%s), client=(%s)\n",
1632 wine_dbgstr_rect(&cbx_wrect
), wine_dbgstr_rect(&cbx_crect
));
1633 TRACE("CB window=(%s), EX setting=(0,0)-(%d,%d)\n",
1634 wine_dbgstr_rect(&cbx_wrect
), width
, cb_wrect
.bottom
-cb_wrect
.top
);
1636 if (width
) SetWindowPos (infoPtr
->hwndCombo
, HWND_TOP
, 0, 0,
1638 cb_wrect
.bottom
-cb_wrect
.top
,
1641 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
1643 /* height is combo window height plus border width of comboex */
1644 height
= (cb_wrect
.bottom
-cb_wrect
.top
)
1645 + (cbx_wrect
.bottom
-cbx_wrect
.top
)
1646 - (cbx_crect
.bottom
-cbx_crect
.top
);
1648 if (infoPtr
->hwndEdit
) {
1649 COMBOEX_AdjustEditPos (infoPtr
);
1650 InvalidateRect (infoPtr
->hwndCombo
, 0, TRUE
);
1656 static LRESULT CALLBACK
1657 COMBOEX_EditWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
1658 UINT_PTR uId
, DWORD_PTR ref_data
)
1660 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr ((HWND
)ref_data
);
1661 NMCBEENDEDITW cbeend
;
1662 WCHAR edit_text
[260];
1668 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1669 hwnd
, uMsg
, wParam
, lParam
, infoPtr
);
1671 if (uMsg
== WM_NCDESTROY
)
1672 RemoveWindowSubclass(hwnd
, COMBOEX_EditWndProc
, EDIT_SUBCLASSID
);
1675 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
1681 /* handle (ignore) the return character */
1682 if (wParam
== VK_RETURN
) return 0;
1683 /* all other characters pass into the real Edit */
1684 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
1688 obkc
= SetBkColor (hDC
, comctl32_color
.clrWindow
);
1689 GetClientRect (hwnd
, &rect
);
1690 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect
));
1691 ExtTextOutW (hDC
, 0, 0, ETO_OPAQUE
, &rect
, 0, 0, 0);
1692 SetBkColor (hDC
, obkc
);
1693 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
1696 INT_PTR oldItem
, selected
;
1699 switch ((INT
)wParam
)
1702 TRACE("special code for VK_ESCAPE\n");
1704 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1706 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1707 cbeend
.fChanged
= FALSE
;
1708 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1709 CB_GETCURSEL
, 0, 0);
1710 cbeend
.iWhy
= CBENF_ESCAPE
;
1712 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) return 0;
1713 oldItem
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1714 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1715 if (!(item
= COMBOEX_FindItem(infoPtr
, oldItem
))) {
1716 ERR("item %ld not found. Problem!\n", oldItem
);
1719 infoPtr
->selected
= oldItem
;
1720 COMBOEX_SetEditText (infoPtr
, item
);
1721 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
|
1726 TRACE("special code for VK_RETURN\n");
1728 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1730 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1731 selected
= SendMessageW (infoPtr
->hwndCombo
,
1732 CB_GETCURSEL
, 0, 0);
1734 if (selected
!= -1) {
1735 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
1736 item
= COMBOEX_FindItem (infoPtr
, selected
);
1737 TRACE("handling VK_RETURN, selected = %ld, selected_text=%s\n",
1738 selected
, debugstr_txt(item
->pszText
));
1739 TRACE("handling VK_RETURN, edittext=%s\n",
1740 debugstr_w(edit_text
));
1741 if (cmptext (COMBOEX_GetText(infoPtr
, item
), edit_text
)) {
1742 /* strings not equal -- indicate edit has changed */
1747 cbeend
.iNewSelection
= selected
;
1748 cbeend
.fChanged
= TRUE
;
1749 cbeend
.iWhy
= CBENF_RETURN
;
1750 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) {
1751 /* abort the change, restore previous */
1752 TRACE("Notify requested abort of change\n");
1753 COMBOEX_SetEditText (infoPtr
, &infoPtr
->edit
);
1754 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
|
1758 oldItem
= SendMessageW (infoPtr
->hwndCombo
,CB_GETCURSEL
, 0, 0);
1759 if (oldItem
!= -1) {
1760 /* if something is selected, then deselect it */
1761 SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, -1, 0);
1763 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1764 SetFocus(infoPtr
->hwndEdit
);
1770 INT step
= wParam
== VK_DOWN
? 1 : -1;
1772 oldItem
= SendMessageW (infoPtr
->hwndSelf
, CB_GETCURSEL
, 0, 0);
1773 if (oldItem
>= 0 && oldItem
+ step
>= 0)
1774 SendMessageW (infoPtr
->hwndSelf
, CB_SETCURSEL
, oldItem
+ step
, 0);
1778 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
1784 /* remember the focus to set state of icon */
1785 lret
= DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
1786 infoPtr
->flags
|= WCBE_EDITFOCUSED
;
1791 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1793 infoPtr
->flags
&= ~WCBE_EDITFOCUSED
;
1794 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1795 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1797 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1798 cbeend
.fChanged
= FALSE
;
1799 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1800 CB_GETCURSEL
, 0, 0);
1801 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1803 COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
);
1808 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
1813 static LRESULT CALLBACK
1814 COMBOEX_ComboWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,
1815 UINT_PTR uId
, DWORD_PTR ref_data
)
1817 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr ((HWND
)ref_data
);
1818 NMCBEENDEDITW cbeend
;
1825 WCHAR edit_text
[260];
1827 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx, info_ptr=%p\n",
1828 hwnd
, uMsg
, wParam
, lParam
, infoPtr
);
1830 if (uMsg
== WM_NCDESTROY
)
1831 RemoveWindowSubclass(hwnd
, COMBOEX_ComboWndProc
, COMBO_SUBCLASSID
);
1834 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
1840 * The only way this message should come is from the
1841 * child Listbox issuing the message. Flag this so
1842 * that ComboEx knows this is listbox.
1844 ((DRAWITEMSTRUCT
*)lParam
)->itemState
|= ODS_COMBOEXLBOX
;
1849 obkc
= SetBkColor (hDC
, comctl32_color
.clrWindow
);
1850 GetClientRect (hwnd
, &rect
);
1851 TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect
));
1852 ExtTextOutW (hDC
, 0, 0, ETO_OPAQUE
, &rect
, 0, 0, 0);
1853 SetBkColor (hDC
, obkc
);
1858 * WM_NOTIFY to comboex parent (rebar)
1859 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1860 * CallWindowProc (previous)
1862 nmmse
.dwItemSpec
= 0;
1863 nmmse
.dwItemData
= 0;
1866 nmmse
.dwHitInfo
= lParam
;
1867 COMBOEX_Notify (infoPtr
, NM_SETCURSOR
, (NMHDR
*)&nmmse
);
1870 case WM_LBUTTONDOWN
:
1871 GetClientRect (hwnd
, &rect
);
1872 rect
.bottom
= rect
.top
+ SendMessageW(infoPtr
->hwndSelf
,
1873 CB_GETITEMHEIGHT
, -1, 0);
1874 rect
.left
= rect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
1875 pt
.x
= (short)LOWORD(lParam
);
1876 pt
.y
= (short)HIWORD(lParam
);
1877 if (PtInRect(&rect
, pt
))
1880 infoPtr
->flags
|= WCBE_MOUSECAPTURED
;
1885 if (!(infoPtr
->flags
& WCBE_MOUSECAPTURED
))
1889 infoPtr
->flags
&= ~WCBE_MOUSECAPTURED
;
1890 if (infoPtr
->flags
& WCBE_MOUSEDRAGGED
) {
1891 infoPtr
->flags
&= ~WCBE_MOUSEDRAGGED
;
1893 SendMessageW(hwnd
, CB_SHOWDROPDOWN
, TRUE
, 0);
1898 if ( (infoPtr
->flags
& WCBE_MOUSECAPTURED
) &&
1899 !(infoPtr
->flags
& WCBE_MOUSEDRAGGED
)) {
1900 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1901 COMBOEX_NotifyDragBegin(infoPtr
, edit_text
);
1902 infoPtr
->flags
|= WCBE_MOUSEDRAGGED
;
1907 switch (HIWORD(wParam
)) {
1910 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1916 focusedhwnd
= GetFocus();
1917 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1918 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1919 cbeend
.fChanged
= (infoPtr
->flags
& WCBE_EDITCHG
);
1920 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1921 CB_GETCURSEL
, 0, 0);
1922 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1924 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1925 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) return 0;
1927 /* possible CB_GETCURSEL */
1928 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1930 SendMessageW (infoPtr
->hwndCombo
, WM_KILLFOCUS
,
1931 (WPARAM
)focusedhwnd
, 0);
1937 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, 0);
1938 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
1939 COMBOEX_Notify (infoPtr
, CBEN_BEGINEDIT
, &hdr
);
1940 infoPtr
->flags
|= WCBE_ACTEDIT
;
1941 infoPtr
->flags
&= ~WCBE_EDITCHG
; /* no change yet */
1947 cmp_func_t cmptext
= get_cmp_func(infoPtr
);
1949 INT_PTR selected
= SendMessageW (infoPtr
->hwndCombo
,
1950 CB_GETCURSEL
, 0, 0);
1952 /* lstrlenW( lastworkingURL ) */
1954 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1955 if (selected
== -1) {
1956 lastwrk
= infoPtr
->edit
.pszText
;
1959 CBE_ITEMDATA
*item
= COMBOEX_FindItem (infoPtr
, selected
);
1960 lastwrk
= COMBOEX_GetText(infoPtr
, item
);
1963 TRACE("handling EN_CHANGE, selected = %ld, selected_text=%s\n",
1964 selected
, debugstr_w(lastwrk
));
1965 TRACE("handling EN_CHANGE, edittext=%s\n",
1966 debugstr_w(edit_text
));
1968 /* cmptext is between lastworkingURL and GetWindowText */
1969 if (cmptext (lastwrk
, edit_text
)) {
1970 /* strings not equal -- indicate edit has changed */
1971 infoPtr
->flags
|= WCBE_EDITCHG
;
1973 SendMessageW ( infoPtr
->hwndNotify
, WM_COMMAND
,
1974 MAKEWPARAM(GetDlgCtrlID (infoPtr
->hwndSelf
),
1976 (LPARAM
)infoPtr
->hwndSelf
);
1988 return DefSubclassProc(hwnd
, uMsg
, wParam
, lParam
);
1992 static LRESULT WINAPI
1993 COMBOEX_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1995 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwnd
);
1997 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2000 if (uMsg
== WM_CREATE
)
2001 return COMBOEX_Create (hwnd
, (LPCREATESTRUCTA
)lParam
);
2002 if (uMsg
== WM_NCCREATE
)
2003 COMBOEX_NCCreate (hwnd
);
2004 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2009 case CBEM_DELETEITEM
:
2010 return COMBOEX_DeleteItem (infoPtr
, wParam
);
2012 case CBEM_GETCOMBOCONTROL
:
2013 return (LRESULT
)infoPtr
->hwndCombo
;
2015 case CBEM_GETEDITCONTROL
:
2016 return (LRESULT
)infoPtr
->hwndEdit
;
2018 case CBEM_GETEXTENDEDSTYLE
:
2019 return infoPtr
->dwExtStyle
;
2021 case CBEM_GETIMAGELIST
:
2022 return (LRESULT
)infoPtr
->himl
;
2025 return (LRESULT
)COMBOEX_GetItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2028 return (LRESULT
)COMBOEX_GetItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2030 case CBEM_GETUNICODEFORMAT
:
2031 return infoPtr
->unicode
;
2033 case CBEM_HASEDITCHANGED
:
2034 return COMBOEX_HasEditChanged (infoPtr
);
2036 case CBEM_INSERTITEMA
:
2037 return COMBOEX_InsertItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2039 case CBEM_INSERTITEMW
:
2040 return COMBOEX_InsertItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2042 case CBEM_SETEXSTYLE
:
2043 case CBEM_SETEXTENDEDSTYLE
:
2044 return COMBOEX_SetExtendedStyle (infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
2046 case CBEM_SETIMAGELIST
:
2047 return (LRESULT
)COMBOEX_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2050 return COMBOEX_SetItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2053 return COMBOEX_SetItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2055 case CBEM_SETUNICODEFORMAT
:
2056 return COMBOEX_SetUnicodeFormat (infoPtr
, wParam
);
2058 /*case CBEM_SETWINDOWTHEME:
2059 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2063 case WM_GETTEXTLENGTH
:
2064 return SendMessageW(infoPtr
->hwndEdit
, uMsg
, wParam
, lParam
);
2067 return COMBOEX_GetListboxText(infoPtr
, wParam
, (LPWSTR
)lParam
);
2069 case CB_GETLBTEXTLEN
:
2070 return COMBOEX_GetListboxText(infoPtr
, wParam
, NULL
);
2072 case CB_RESETCONTENT
:
2073 COMBOEX_ResetContent(infoPtr
);
2076 /* Combo messages we are not sure if we need to process or just forward */
2077 case CB_GETDROPPEDCONTROLRECT
:
2078 case CB_GETITEMHEIGHT
:
2079 case CB_GETEXTENDEDUI
:
2081 case CB_SELECTSTRING
:
2083 /* Combo messages OK to just forward to the regular COMBO */
2086 case CB_GETDROPPEDSTATE
:
2087 case CB_SETDROPPEDWIDTH
:
2088 case CB_SETEXTENDEDUI
:
2089 case CB_SHOWDROPDOWN
:
2090 return SendMessageW (infoPtr
->hwndCombo
, uMsg
, wParam
, lParam
);
2092 /* Combo messages we need to process specially */
2093 case CB_FINDSTRINGEXACT
:
2094 return COMBOEX_FindStringExact (infoPtr
, (INT
)wParam
, (LPCWSTR
)lParam
);
2096 case CB_GETITEMDATA
:
2097 return COMBOEX_GetItemData (infoPtr
, (INT
)wParam
);
2100 return COMBOEX_SetCursel (infoPtr
, (INT
)wParam
);
2102 case CB_SETITEMDATA
:
2103 return COMBOEX_SetItemData (infoPtr
, (INT
)wParam
, (DWORD_PTR
)lParam
);
2105 case CB_SETITEMHEIGHT
:
2106 return COMBOEX_SetItemHeight (infoPtr
, (INT
)wParam
, (UINT
)lParam
);
2110 /* Window messages passed to parent */
2112 return COMBOEX_Command (infoPtr
, wParam
);
2115 if (infoPtr
->NtfUnicode
)
2116 return SendMessageW (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
2118 return SendMessageA (infoPtr
->hwndNotify
, uMsg
, wParam
, lParam
);
2121 /* Window messages we need to process */
2123 return COMBOEX_WM_DeleteItem (infoPtr
, (DELETEITEMSTRUCT
*)lParam
);
2126 return COMBOEX_DrawItem (infoPtr
, (DRAWITEMSTRUCT
*)lParam
);
2129 return COMBOEX_Destroy (infoPtr
);
2132 return COMBOEX_Enable (infoPtr
, (BOOL
)wParam
);
2134 case WM_MEASUREITEM
:
2135 return COMBOEX_MeasureItem (infoPtr
, (MEASUREITEMSTRUCT
*)lParam
);
2137 case WM_NOTIFYFORMAT
:
2138 return COMBOEX_NotifyFormat (infoPtr
, lParam
);
2141 return COMBOEX_Size (infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
2144 return (LRESULT
)infoPtr
->font
;
2147 return COMBOEX_SetFont( infoPtr
, (HFONT
)wParam
, LOWORD(lParam
) != 0 );
2150 return COMBOEX_SetRedraw(infoPtr
, wParam
, lParam
);
2152 case WM_WINDOWPOSCHANGING
:
2153 return COMBOEX_WindowPosChanging (infoPtr
, (WINDOWPOS
*)lParam
);
2156 if (infoPtr
->hwndEdit
) SetFocus( infoPtr
->hwndEdit
);
2157 else SetFocus( infoPtr
->hwndCombo
);
2160 case WM_SYSCOLORCHANGE
:
2161 COMCTL32_RefreshSysColors();
2165 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
2166 ERR("unknown msg %04x wp=%08lx lp=%08lx\n",uMsg
,wParam
,lParam
);
2167 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2172 void COMBOEX_Register (void)
2176 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2177 wndClass
.style
= CS_GLOBALCLASS
;
2178 wndClass
.lpfnWndProc
= COMBOEX_WindowProc
;
2179 wndClass
.cbClsExtra
= 0;
2180 wndClass
.cbWndExtra
= sizeof(COMBOEX_INFO
*);
2181 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2182 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2183 wndClass
.lpszClassName
= WC_COMBOBOXEXW
;
2185 RegisterClassW (&wndClass
);
2189 void COMBOEX_Unregister (void)
2191 UnregisterClassW (WC_COMBOBOXEXW
, NULL
);