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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 1. Implement following extended styles:
24 * CBES_EX_PATHWORDBREAKPROC
26 * CBES_EX_CASESENSITIVE
27 * 2. Notify CBEN_DRAGBEGIN is not implemented.
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(comboex
);
54 /* ComboBoxEx structure */
58 HWND hwndSelf
; /* my own hwnd */
61 WNDPROC prevEditWndProc
; /* previous Edit WNDPROC value */
62 WNDPROC prevComboWndProc
; /* previous Combo WNDPROC value */
64 INT selected
; /* index of selected item */
65 DWORD flags
; /* WINE internal flags */
68 INT nb_items
; /* Number of items */
69 BOOL unicode
; /* TRUE if this window is Unicode */
70 BOOL NtfUnicode
; /* TRUE if parent wants notify in Unicode */
71 CBE_ITEMDATA
*edit
; /* item data for edit item */
72 CBE_ITEMDATA
*items
; /* Array of items */
75 /* internal flags in the COMBOEX_INFO structure */
76 #define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
77 * CBEN_BEGINEDIT issued
78 * but CBEN_ENDEDIT{A|W}
80 #define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
81 #define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
82 #define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
85 #define ID_CB_EDIT 1001
89 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
90 * the ComboEx version of the Combo Window Proc so that when the
91 * WM_DRAWITEM message is then passed to ComboEx, we know that this
92 * particular WM_DRAWITEM message is for listbox only items. Any messasges
93 * without this flag is then for the Edit control field.
95 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
96 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
98 #define ODS_COMBOEXLBOX 0x4000
102 /* Height in pixels of control over the amount of the selected font */
105 /* Indent amount per MS documentation */
106 #define CBE_INDENT 10
108 /* Offset in pixels from left side for start of image or text */
109 #define CBE_STARTOFFSET 6
111 /* Offset between image and text */
114 #define COMBOEX_SUBCLASS_PROP "CCComboEx32SubclassInfo"
115 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongW (hwnd, 0))
118 /* Things common to the entire DLL */
119 static LRESULT WINAPI
120 COMBOEX_EditWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
121 static LRESULT WINAPI
122 COMBOEX_ComboWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
123 static LRESULT
COMBOEX_Destroy (COMBOEX_INFO
*infoPtr
);
125 inline static BOOL
is_textW(LPCWSTR str
)
127 return str
&& str
!= LPSTR_TEXTCALLBACKW
;
130 inline static BOOL
is_textA(LPCSTR str
)
132 return str
&& str
!= LPSTR_TEXTCALLBACKA
;
135 inline static LPCSTR
debugstr_txt(LPCWSTR str
)
137 if (str
== LPSTR_TEXTCALLBACKW
) return "(callback)";
138 return debugstr_w(str
);
141 static void COMBOEX_DumpItem (CBE_ITEMDATA
*item
)
143 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
144 item
, item
->mask
, item
->pszText
, item
->cchTextMax
, item
->iImage
);
145 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
146 item
, item
->iSelectedImage
, item
->iOverlay
, item
->iIndent
, item
->lParam
);
147 if (item
->mask
& CBEIF_TEXT
)
148 TRACE("item %p - pszText=%s\n", item
, debugstr_txt(item
->pszText
));
152 static void COMBOEX_DumpInput (COMBOBOXEXITEMW
*input
)
154 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
155 input
->mask
, input
->iItem
, input
->pszText
, input
->cchTextMax
,
157 if (input
->mask
& CBEIF_TEXT
)
158 TRACE("input - pszText=<%s>\n", debugstr_txt(input
->pszText
));
159 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
160 input
->iSelectedImage
, input
->iOverlay
, input
->iIndent
, input
->lParam
);
164 inline static CBE_ITEMDATA
*get_item_data(COMBOEX_INFO
*infoPtr
, INT index
)
166 return (CBE_ITEMDATA
*)SendMessageW (infoPtr
->hwndCombo
, CB_GETITEMDATA
,
171 static INT
COMBOEX_Notify (COMBOEX_INFO
*infoPtr
, INT code
, NMHDR
*hdr
)
173 hdr
->idFrom
= GetDlgCtrlID (infoPtr
->hwndSelf
);
174 hdr
->hwndFrom
= infoPtr
->hwndSelf
;
176 if (infoPtr
->NtfUnicode
)
177 return SendMessageW (GetParent(infoPtr
->hwndSelf
), WM_NOTIFY
, 0,
180 return SendMessageA (GetParent(infoPtr
->hwndSelf
), WM_NOTIFY
, 0,
186 COMBOEX_NotifyItem (COMBOEX_INFO
*infoPtr
, INT code
, NMCOMBOBOXEXW
*hdr
)
188 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
189 if (infoPtr
->NtfUnicode
)
190 return COMBOEX_Notify (infoPtr
, code
, &hdr
->hdr
);
192 LPWSTR wstr
= hdr
->ceItem
.pszText
;
196 if ((hdr
->ceItem
.mask
& CBEIF_TEXT
) && is_textW(wstr
)) {
197 len
= WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, 0, 0, NULL
, NULL
);
199 astr
= (LPSTR
)COMCTL32_Alloc ((len
+ 1)*sizeof(CHAR
));
201 WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, astr
, len
, 0, 0);
202 hdr
->ceItem
.pszText
= (LPWSTR
)astr
;
206 if (code
== CBEN_ENDEDITW
) code
= CBEN_ENDEDITA
;
207 else if (code
== CBEN_GETDISPINFOW
) code
= CBEN_GETDISPINFOA
;
208 else if (code
== CBEN_DRAGBEGINW
) code
= CBEN_DRAGBEGINA
;
210 ret
= COMBOEX_Notify (infoPtr
, code
, (NMHDR
*)hdr
);
212 if (astr
&& hdr
->ceItem
.pszText
== (LPWSTR
)astr
)
213 hdr
->ceItem
.pszText
= wstr
;
215 if (astr
) COMCTL32_Free(astr
);
222 static INT
COMBOEX_NotifyEndEdit (COMBOEX_INFO
*infoPtr
, NMCBEENDEDITW
*neew
, LPCWSTR wstr
)
224 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
225 if (infoPtr
->NtfUnicode
) {
226 lstrcpynW(neew
->szText
, wstr
, CBEMAXSTRLEN
);
227 return COMBOEX_Notify (infoPtr
, CBEN_ENDEDITW
, &neew
->hdr
);
231 memcpy (&neea
.hdr
, &neew
->hdr
, sizeof(NMHDR
));
232 neea
.fChanged
= neew
->fChanged
;
233 neea
.iNewSelection
= neew
->iNewSelection
;
234 WideCharToMultiByte (CP_ACP
, 0, wstr
, -1, neea
.szText
, CBEMAXSTRLEN
, 0, 0);
235 neea
.iWhy
= neew
->iWhy
;
237 return COMBOEX_Notify (infoPtr
, CBEN_ENDEDITA
, &neea
.hdr
);
242 static void COMBOEX_FreeText (CBE_ITEMDATA
*item
)
244 if (is_textW(item
->pszText
)) COMCTL32_Free(item
->pszText
);
246 if (item
->pszTemp
) COMCTL32_Free(item
->pszTemp
);
251 static LPCWSTR
COMBOEX_GetText(COMBOEX_INFO
*infoPtr
, CBE_ITEMDATA
*item
)
257 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
258 return item
->pszText
;
260 ZeroMemory(&nmce
, sizeof(nmce
));
261 nmce
.ceItem
.mask
= CBEIF_TEXT
;
262 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
264 if (is_textW(nmce
.ceItem
.pszText
)) {
265 len
= MultiByteToWideChar (CP_ACP
, 0, (LPSTR
)nmce
.ceItem
.pszText
, -1, NULL
, 0);
266 buf
= (LPWSTR
)COMCTL32_Alloc ((len
+ 1)*sizeof(WCHAR
));
268 MultiByteToWideChar (CP_ACP
, 0, (LPSTR
)nmce
.ceItem
.pszText
, -1, buf
, len
);
269 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) {
270 COMBOEX_FreeText(item
);
273 if (item
->pszTemp
) COMCTL32_Free(item
->pszTemp
);
278 text
= nmce
.ceItem
.pszText
;
280 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
281 item
->pszText
= text
;
286 static void COMBOEX_GetComboFontSize (COMBOEX_INFO
*infoPtr
, SIZE
*size
)
291 mydc
= GetDC (0); /* why the entire screen???? */
292 nfont
= SendMessageW (infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
293 ofont
= (HFONT
) SelectObject (mydc
, nfont
);
294 GetTextExtentPointA (mydc
, "A", 1, size
);
295 SelectObject (mydc
, ofont
);
297 TRACE("selected font hwnd=%08x, height=%ld\n", nfont
, size
->cy
);
301 static void COMBOEX_CopyItem (CBE_ITEMDATA
*item
, COMBOBOXEXITEMW
*cit
)
303 if (cit
->mask
& CBEIF_TEXT
) {
305 * when given a text buffer actually use that buffer
308 if (is_textW(item
->pszText
))
309 lstrcpynW(cit
->pszText
, item
->pszText
, cit
->cchTextMax
);
313 cit
->pszText
= item
->pszText
;
314 cit
->cchTextMax
= item
->cchTextMax
;
317 if (cit
->mask
& CBEIF_IMAGE
)
318 cit
->iImage
= item
->iImage
;
319 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
320 cit
->iSelectedImage
= item
->iSelectedImage
;
321 if (cit
->mask
& CBEIF_OVERLAY
)
322 cit
->iOverlay
= item
->iOverlay
;
323 if (cit
->mask
& CBEIF_INDENT
)
324 cit
->iIndent
= item
->iIndent
;
325 if (cit
->mask
& CBEIF_LPARAM
)
326 cit
->lParam
= item
->lParam
;
330 static void COMBOEX_AdjustEditPos (COMBOEX_INFO
*infoPtr
)
333 INT x
, y
, w
, h
, xioff
;
336 if (!infoPtr
->hwndEdit
) return;
338 if (infoPtr
->himl
&& !(infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGEINDENT
)) {
340 iinfo
.rcImage
.left
= iinfo
.rcImage
.right
= 0;
341 ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
);
342 xioff
= iinfo
.rcImage
.right
- iinfo
.rcImage
.left
+ CBE_SEP
;
345 GetClientRect (infoPtr
->hwndCombo
, &rect
);
346 InflateRect (&rect
, -2, -2);
347 InvalidateRect (infoPtr
->hwndCombo
, &rect
, TRUE
);
349 /* reposition the Edit control based on whether icon exists */
350 COMBOEX_GetComboFontSize (infoPtr
, &mysize
);
351 TRACE("Combo font x=%ld, y=%ld\n", mysize
.cx
, mysize
.cy
);
352 x
= xioff
+ CBE_STARTOFFSET
+ 1;
353 w
= rect
.right
-rect
.left
- x
- GetSystemMetrics(SM_CXVSCROLL
) - 1;
355 y
= rect
.bottom
- h
- 1;
357 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
358 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
, x
, y
, x
+ w
, y
+ h
);
359 SetWindowPos(infoPtr
->hwndEdit
, HWND_TOP
, x
, y
, w
, h
,
360 SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
364 static void COMBOEX_ReSize (COMBOEX_INFO
*infoPtr
)
370 COMBOEX_GetComboFontSize (infoPtr
, &mysize
);
371 cy
= mysize
.cy
+ CBE_EXTRA
;
373 ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
);
374 cy
= max (iinfo
.rcImage
.bottom
- iinfo
.rcImage
.top
, cy
);
375 TRACE("upgraded height due to image: height=%d\n", cy
);
377 SendMessageW (infoPtr
->hwndSelf
, CB_SETITEMHEIGHT
, (WPARAM
)-1, (LPARAM
)cy
);
378 if (infoPtr
->hwndCombo
)
379 SendMessageW (infoPtr
->hwndCombo
, CB_SETITEMHEIGHT
,
380 (WPARAM
) 0, (LPARAM
) cy
);
384 static void COMBOEX_SetEditText (COMBOEX_INFO
*infoPtr
, CBE_ITEMDATA
*item
)
386 if (!infoPtr
->hwndEdit
) return;
387 /* native issues the following messages to the {Edit} control */
388 /* WM_SETTEXT (0,addr) */
389 /* EM_SETSEL32 (0,0) */
390 /* EM_SETSEL32 (0,-1) */
391 if (item
->mask
& CBEIF_TEXT
) {
392 SendMessageW (infoPtr
->hwndEdit
, WM_SETTEXT
, 0, (LPARAM
)COMBOEX_GetText(infoPtr
, item
));
393 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, 0);
394 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
399 static CBE_ITEMDATA
* COMBOEX_FindItem(COMBOEX_INFO
*infoPtr
, INT index
)
404 if ((index
> infoPtr
->nb_items
) || (index
< -1))
407 return infoPtr
->edit
;
408 item
= infoPtr
->items
;
409 i
= infoPtr
->nb_items
- 1;
411 /* find the item in the list */
412 while (item
&& (i
> index
)) {
413 item
= (CBE_ITEMDATA
*)item
->next
;
416 if (!item
|| (i
!= index
)) {
417 ERR("COMBOBOXEX item structures broken. Please report!\n");
424 static inline BOOL
COMBOEX_HasEdit(COMBOEX_INFO
*infoPtr
)
426 return infoPtr
->hwndEdit
;
430 /* *** CBEM_xxx message support *** */
433 static INT
COMBOEX_DeleteItem (COMBOEX_INFO
*infoPtr
, INT index
)
437 TRACE("(index=%d)\n", index
);
439 /* if item number requested does not exist then return failure */
440 if ((index
> infoPtr
->nb_items
) || (index
< 0)) return CB_ERR
;
441 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return CB_ERR
;
443 /* doing this will result in WM_DELETEITEM being issued */
444 SendMessageW (infoPtr
->hwndCombo
, CB_DELETESTRING
, (WPARAM
)index
, 0);
446 return infoPtr
->nb_items
;
450 static BOOL
COMBOEX_GetItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
*cit
)
452 INT index
= cit
->iItem
;
457 /* if item number requested does not exist then return failure */
458 if ((index
> infoPtr
->nb_items
) || (index
< -1)) return FALSE
;
460 /* if the item is the edit control and there is no edit control, skip */
461 if ((index
== -1) && !COMBOEX_HasEdit(infoPtr
)) return FALSE
;
463 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return FALSE
;
465 COMBOEX_CopyItem (item
, cit
);
471 static BOOL
COMBOEX_GetItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
*cit
)
473 COMBOBOXEXITEMW tmpcit
;
477 tmpcit
.mask
= cit
->mask
;
478 tmpcit
.iItem
= cit
->iItem
;
480 if(!COMBOEX_GetItemW (infoPtr
, &tmpcit
)) return FALSE
;
482 if (is_textW(tmpcit
.pszText
) && cit
->pszText
)
483 WideCharToMultiByte (CP_ACP
, 0, tmpcit
.pszText
, -1,
484 cit
->pszText
, cit
->cchTextMax
, NULL
, NULL
);
485 else if (cit
->pszText
) cit
->pszText
[0] = 0;
486 else cit
->pszText
= (LPSTR
)tmpcit
.pszText
;
488 cit
->iImage
= tmpcit
.iImage
;
489 cit
->iSelectedImage
= tmpcit
.iSelectedImage
;
490 cit
->iOverlay
= tmpcit
.iOverlay
;
491 cit
->iIndent
= tmpcit
.iIndent
;
492 cit
->lParam
= tmpcit
.lParam
;
498 inline static BOOL
COMBOEX_HasEditChanged (COMBOEX_INFO
*infoPtr
)
500 return COMBOEX_HasEdit(infoPtr
) &&
501 (infoPtr
->flags
& WCBE_EDITHASCHANGED
) == WCBE_EDITHASCHANGED
;
505 static INT
COMBOEX_InsertItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
*cit
)
513 if (TRACE_ON(comboex
)) COMBOEX_DumpInput (cit
);
515 /* get real index of item to insert */
517 if (index
== -1) index
= infoPtr
->nb_items
;
518 if (index
> infoPtr
->nb_items
) index
= infoPtr
->nb_items
;
520 /* get zero-filled space and chain it in */
521 if(!(item
= (CBE_ITEMDATA
*)COMCTL32_Alloc (sizeof(*item
)))) return -1;
523 /* locate position to insert new item in */
524 if (index
== infoPtr
->nb_items
) {
525 /* fast path for iItem = -1 */
526 item
->next
= infoPtr
->items
;
527 infoPtr
->items
= item
;
530 INT i
= infoPtr
->nb_items
-1;
531 CBE_ITEMDATA
*moving
= infoPtr
->items
;
533 while ((i
> index
) && moving
) {
534 moving
= (CBE_ITEMDATA
*)moving
->next
;
538 ERR("COMBOBOXEX item structures broken. Please report!\n");
542 item
->next
= moving
->next
;
546 /* fill in our hidden item structure */
547 item
->mask
= cit
->mask
;
548 if (item
->mask
& CBEIF_TEXT
) {
551 if (is_textW(cit
->pszText
)) len
= strlenW (cit
->pszText
);
553 item
->pszText
= (LPWSTR
)COMCTL32_Alloc ((len
+ 1)*sizeof(WCHAR
));
554 if (!item
->pszText
) {
558 strcpyW (item
->pszText
, cit
->pszText
);
560 else if (cit
->pszText
== LPSTR_TEXTCALLBACKW
)
561 item
->pszText
= LPSTR_TEXTCALLBACKW
;
562 item
->cchTextMax
= cit
->cchTextMax
;
564 if (item
->mask
& CBEIF_IMAGE
)
565 item
->iImage
= cit
->iImage
;
566 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
567 item
->iSelectedImage
= cit
->iSelectedImage
;
568 if (item
->mask
& CBEIF_OVERLAY
)
569 item
->iOverlay
= cit
->iOverlay
;
570 if (item
->mask
& CBEIF_INDENT
)
571 item
->iIndent
= cit
->iIndent
;
572 if (item
->mask
& CBEIF_LPARAM
)
573 item
->lParam
= cit
->lParam
;
576 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
578 SendMessageW (infoPtr
->hwndCombo
, CB_INSERTSTRING
,
579 (WPARAM
)cit
->iItem
, (LPARAM
)item
);
581 memset (&nmcit
.ceItem
, 0, sizeof(nmcit
.ceItem
));
582 COMBOEX_CopyItem (item
, &nmcit
.ceItem
);
583 COMBOEX_NotifyItem (infoPtr
, CBEN_INSERTITEM
, &nmcit
);
590 static INT
COMBOEX_InsertItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
*cit
)
592 COMBOBOXEXITEMW citW
;
596 memcpy(&citW
,cit
,sizeof(COMBOBOXEXITEMA
));
597 if (cit
->mask
& CBEIF_TEXT
&& is_textA(cit
->pszText
)) {
598 INT len
= MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, NULL
, 0);
599 wstr
= (LPWSTR
)COMCTL32_Alloc ((len
+ 1)*sizeof(WCHAR
));
600 if (!wstr
) return -1;
601 MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, wstr
, len
);
604 ret
= COMBOEX_InsertItemW(infoPtr
, &citW
);;
606 if (wstr
) COMCTL32_Free(wstr
);
613 COMBOEX_SetExtendedStyle (COMBOEX_INFO
*infoPtr
, DWORD mask
, DWORD style
)
617 TRACE("(mask=x%08lx, style=0x%08lx)\n", mask
, style
);
619 dwTemp
= infoPtr
->dwExtStyle
;
621 if (style
& (CBES_EX_PATHWORDBREAKPROC
|
622 CBES_EX_NOSIZELIMIT
|
623 CBES_EX_CASESENSITIVE
))
624 FIXME("Extended style not implemented %08lx\n", style
);
627 infoPtr
->dwExtStyle
= (infoPtr
->dwExtStyle
& ~mask
) | style
;
629 infoPtr
->dwExtStyle
= style
;
631 /* test if the control's appearance has changed */
632 mask
= CBES_EX_NOEDITIMAGE
| CBES_EX_NOEDITIMAGEINDENT
;
633 if ((infoPtr
->dwExtStyle
& mask
) != (dwTemp
& mask
)) {
634 /* if state of EX_NOEDITIMAGE changes, invalidate all */
635 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
636 infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGE
);
637 InvalidateRect (infoPtr
->hwndSelf
, NULL
, TRUE
);
638 COMBOEX_AdjustEditPos (infoPtr
);
639 if (infoPtr
->hwndEdit
)
640 InvalidateRect (infoPtr
->hwndEdit
, NULL
, TRUE
);
647 static HIMAGELIST
COMBOEX_SetImageList (COMBOEX_INFO
*infoPtr
, HIMAGELIST himl
)
649 HIMAGELIST himlTemp
= infoPtr
->himl
;
653 infoPtr
->himl
= himl
;
655 COMBOEX_ReSize (infoPtr
);
656 InvalidateRect (infoPtr
->hwndCombo
, NULL
, TRUE
);
658 /* reposition the Edit control based on whether icon exists */
659 COMBOEX_AdjustEditPos (infoPtr
);
663 static BOOL
COMBOEX_SetItemW (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMW
*cit
)
665 INT index
= cit
->iItem
;
668 if (TRACE_ON(comboex
)) COMBOEX_DumpInput (cit
);
670 /* if item number requested does not exist then return failure */
671 if ((index
> infoPtr
->nb_items
) || (index
< -1)) return FALSE
;
673 /* if the item is the edit control and there is no edit control, skip */
674 if ((index
== -1) && !COMBOEX_HasEdit(infoPtr
)) return FALSE
;
676 if (!(item
= COMBOEX_FindItem(infoPtr
, index
))) return FALSE
;
678 /* add/change stuff to the internal item structure */
679 item
->mask
|= cit
->mask
;
680 if (cit
->mask
& CBEIF_TEXT
) {
683 COMBOEX_FreeText(item
);
684 if (is_textW(cit
->pszText
)) len
= strlenW(cit
->pszText
);
686 item
->pszText
= (LPWSTR
)COMCTL32_Alloc ((len
+ 1)*sizeof(WCHAR
));
687 if (!item
->pszText
) return FALSE
;
688 strcpyW(item
->pszText
, cit
->pszText
);
689 } else if (cit
->pszText
== LPSTR_TEXTCALLBACKW
)
690 item
->pszText
= LPSTR_TEXTCALLBACKW
;
691 item
->cchTextMax
= cit
->cchTextMax
;
693 if (cit
->mask
& CBEIF_IMAGE
)
694 item
->iImage
= cit
->iImage
;
695 if (cit
->mask
& CBEIF_SELECTEDIMAGE
)
696 item
->iSelectedImage
= cit
->iSelectedImage
;
697 if (cit
->mask
& CBEIF_OVERLAY
)
698 item
->iOverlay
= cit
->iOverlay
;
699 if (cit
->mask
& CBEIF_INDENT
)
700 item
->iIndent
= cit
->iIndent
;
701 if (cit
->mask
& CBEIF_LPARAM
)
702 cit
->lParam
= cit
->lParam
;
704 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
706 /* if original request was to update edit control, do some fast foot work */
707 if (cit
->iItem
== -1) {
708 COMBOEX_SetEditText (infoPtr
, item
);
709 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
| RDW_INVALIDATE
);
714 static BOOL
COMBOEX_SetItemA (COMBOEX_INFO
*infoPtr
, COMBOBOXEXITEMA
*cit
)
716 COMBOBOXEXITEMW citW
;
720 memcpy(&citW
, cit
, sizeof(COMBOBOXEXITEMA
));
721 if ((cit
->mask
& CBEIF_TEXT
) && is_textA(cit
->pszText
)) {
722 INT len
= MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, NULL
, 0);
723 wstr
= (LPWSTR
)COMCTL32_Alloc ((len
+ 1)*sizeof(WCHAR
));
724 if (!wstr
) return FALSE
;
725 MultiByteToWideChar (CP_ACP
, 0, cit
->pszText
, -1, wstr
, len
);
728 ret
= COMBOEX_SetItemW(infoPtr
, &citW
);;
730 if (wstr
) COMCTL32_Free(wstr
);
736 static BOOL
COMBOEX_SetUnicodeFormat (COMBOEX_INFO
*infoPtr
, BOOL value
)
738 BOOL bTemp
= infoPtr
->unicode
;
740 TRACE("to %s, was %s\n", value
? "TRUE":"FALSE", bTemp
? "TRUE":"FALSE");
742 infoPtr
->unicode
= value
;
748 /* *** CB_xxx message support *** */
751 COMBOEX_FindStringExact (COMBOEX_INFO
*infoPtr
, INT start
, LPCSTR str
)
755 LPWSTR desired
= NULL
;
757 i
= MultiByteToWideChar (CP_ACP
, 0, str
, -1, NULL
, 0);
759 desired
= (LPWSTR
)COMCTL32_Alloc ((i
+ 1)*sizeof(WCHAR
));
760 if (!desired
) return CB_ERR
;
761 MultiByteToWideChar (CP_ACP
, 0, str
, -1, desired
, i
);
764 count
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCOUNT
, 0, 0);
766 /* now search from after starting loc and wrapping back to start */
767 for(i
=start
+1; i
<count
; i
++) {
768 item
= get_item_data(infoPtr
, i
);
769 if (lstrcmpiW(COMBOEX_GetText(infoPtr
, item
), desired
) == 0) {
770 COMCTL32_Free (desired
);
774 for(i
=0; i
<=start
; i
++) {
775 item
= get_item_data(infoPtr
, i
);
776 if (lstrcmpiW(COMBOEX_GetText(infoPtr
, item
), desired
) == 0) {
777 COMCTL32_Free (desired
);
781 COMCTL32_Free(desired
);
786 static DWORD
COMBOEX_GetItemData (COMBOEX_INFO
*infoPtr
, INT index
)
788 CBE_ITEMDATA
*item1
, *item2
;
791 item1
= get_item_data(infoPtr
, index
);
792 if ((item1
!= NULL
) && ((LRESULT
)item1
!= CB_ERR
)) {
793 item2
= COMBOEX_FindItem (infoPtr
, index
);
794 if (item2
!= item1
) {
795 ERR("data structures damaged!\n");
798 if (item1
->mask
& CBEIF_LPARAM
) ret
= item1
->lParam
;
799 TRACE("returning 0x%08lx\n", ret
);
802 TRACE("non-valid result from combo, returning 0x%08lx\n", ret
);
808 static INT
COMBOEX_SetCursel (COMBOEX_INFO
*infoPtr
, INT index
)
813 if (!(item
= COMBOEX_FindItem(infoPtr
, index
)))
814 return SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, index
, 0);
816 TRACE("selecting item %d text=%s\n", index
, debugstr_txt(item
->pszText
));
817 infoPtr
->selected
= index
;
819 sel
= (INT
)SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
, index
, 0);
820 COMBOEX_SetEditText (infoPtr
, item
);
825 static DWORD
COMBOEX_SetItemData (COMBOEX_INFO
*infoPtr
, INT index
, DWORD data
)
827 CBE_ITEMDATA
*item1
, *item2
;
829 item1
= get_item_data(infoPtr
, index
);
830 if ((item1
!= NULL
) && ((LRESULT
)item1
!= CB_ERR
)) {
831 item2
= COMBOEX_FindItem (infoPtr
, index
);
832 if (item2
!= item1
) {
833 ERR("data structures damaged!\n");
836 item1
->mask
|= CBEIF_LPARAM
;
837 item1
->lParam
= data
;
838 TRACE("setting lparam to 0x%08lx\n", data
);
841 TRACE("non-valid result from combo 0x%08lx\n", (DWORD
)item1
);
842 return (LRESULT
)item1
;
846 static INT
COMBOEX_SetItemHeight (COMBOEX_INFO
*infoPtr
, INT index
, UINT height
)
848 RECT cb_wrect
, cbx_wrect
, cbx_crect
;
850 /* First, lets forward the message to the normal combo control
851 just like Windows. */
852 if (infoPtr
->hwndCombo
)
853 if (SendMessageW (infoPtr
->hwndCombo
, CB_SETITEMHEIGHT
,
854 index
, height
) == CB_ERR
) return CB_ERR
;
856 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
857 GetWindowRect (infoPtr
->hwndSelf
, &cbx_wrect
);
858 GetClientRect (infoPtr
->hwndSelf
, &cbx_crect
);
859 /* the height of comboex as height of the combo + comboex border */
860 height
= cb_wrect
.bottom
-cb_wrect
.top
861 + cbx_wrect
.bottom
-cbx_wrect
.top
862 - (cbx_crect
.bottom
-cbx_crect
.top
);
863 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
864 cbx_wrect
.left
, cbx_wrect
.top
, cbx_wrect
.right
, cbx_wrect
.bottom
,
865 cbx_crect
.left
, cbx_crect
.top
, cbx_crect
.right
, cbx_crect
.bottom
);
866 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
867 cb_wrect
.left
, cb_wrect
.top
, cb_wrect
.right
, cb_wrect
.bottom
,
868 cbx_wrect
.right
-cbx_wrect
.left
, height
);
869 SetWindowPos (infoPtr
->hwndSelf
, HWND_TOP
, 0, 0,
870 cbx_wrect
.right
-cbx_wrect
.left
, height
,
871 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOMOVE
);
877 /* *** WM_xxx message support *** */
880 static LRESULT
COMBOEX_Create (HWND hwnd
, LPCREATESTRUCTA cs
)
882 WCHAR COMBOBOX
[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
883 WCHAR EDIT
[] = { 'E', 'D', 'I', 'T', 0 };
885 COMBOEX_INFO
*infoPtr
;
888 RECT wnrc1
, clrc1
, cmbwrc
;
891 /* allocate memory for info structure */
892 infoPtr
= (COMBOEX_INFO
*)COMCTL32_Alloc (sizeof(COMBOEX_INFO
));
893 if (!infoPtr
) return -1;
895 /* initialize info structure */
896 /* note that infoPtr is allocated zero-filled */
898 infoPtr
->hwndSelf
= hwnd
;
899 infoPtr
->selected
= -1;
901 infoPtr
->unicode
= IsWindowUnicode (hwnd
);
903 i
= SendMessageW(GetParent (hwnd
), WM_NOTIFYFORMAT
, hwnd
, NF_QUERY
);
904 if ((i
!= NFR_ANSI
) && (i
!= NFR_UNICODE
)) {
905 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i
);
908 infoPtr
->NtfUnicode
= (i
== NFR_UNICODE
);
910 SetWindowLongW (hwnd
, 0, (DWORD
)infoPtr
);
912 /* create combo box */
913 dwComboStyle
= GetWindowLongW (hwnd
, GWL_STYLE
) &
914 (CBS_SIMPLE
|CBS_DROPDOWN
|CBS_DROPDOWNLIST
|WS_CHILD
);
916 GetWindowRect(hwnd
, &wnrc1
);
917 GetClientRect(hwnd
, &clrc1
);
918 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
919 wnrc1
.left
, wnrc1
.top
, wnrc1
.right
, wnrc1
.bottom
,
920 clrc1
.left
, clrc1
.top
, clrc1
.right
, clrc1
.bottom
);
921 TRACE("combo style=%08lx, adding style=%08lx\n", dwComboStyle
,
922 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| WS_VSCROLL
|
923 CBS_NOINTEGRALHEIGHT
| CBS_DROPDOWNLIST
|
924 WS_CHILD
| WS_VISIBLE
| CBS_OWNERDRAWFIXED
);
926 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
927 /* specified. It then creates it's own version of the EDIT control */
928 /* and makes the ComboBox the parent. This is because a normal */
929 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
930 /* We also need to place the edit control at the proper location */
931 /* (allow space for the icons). */
933 infoPtr
->hwndCombo
= CreateWindowW (COMBOBOX
, NIL
,
934 /* following line added to match native */
935 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| WS_VSCROLL
|
936 CBS_NOINTEGRALHEIGHT
| CBS_DROPDOWNLIST
|
937 /* was base and is necessary */
938 WS_CHILD
| WS_VISIBLE
| CBS_OWNERDRAWFIXED
| dwComboStyle
,
939 cs
->y
, cs
->x
, cs
->cx
, cs
->cy
, hwnd
,
940 (HMENU
) GetWindowLongW (hwnd
, GWL_ID
),
941 GetWindowLongW (hwnd
, GWL_HINSTANCE
), NULL
);
944 * native does the following at this point according to trace:
945 * GetWindowThreadProcessId(hwndCombo,0)
946 * GetCurrentThreadId()
947 * GetWindowThreadProcessId(hwndCombo, &???)
948 * GetCurrentProcessId()
952 * Setup a property to hold the pointer to the COMBOBOXEX
955 SetPropA(infoPtr
->hwndCombo
, COMBOEX_SUBCLASS_PROP
, hwnd
);
956 infoPtr
->prevComboWndProc
= (WNDPROC
)SetWindowLongW(infoPtr
->hwndCombo
,
957 GWL_WNDPROC
, (LONG
)COMBOEX_ComboWndProc
);
958 infoPtr
->font
= SendMessageW (infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
962 * Now create our own EDIT control so we can position it.
963 * It is created only for CBS_DROPDOWN style
965 if ((cs
->style
& CBS_DROPDOWNLIST
) == CBS_DROPDOWN
) {
966 infoPtr
->hwndEdit
= CreateWindowExW (0, EDIT
, NIL
,
967 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| ES_AUTOHSCROLL
,
968 0, 0, 0, 0, /* will set later */
970 (HMENU
) GetWindowLongW (hwnd
, GWL_ID
),
971 GetWindowLongW (hwnd
, GWL_HINSTANCE
),
974 /* native does the following at this point according to trace:
975 * GetWindowThreadProcessId(hwndEdit,0)
976 * GetCurrentThreadId()
977 * GetWindowThreadProcessId(hwndEdit, &???)
978 * GetCurrentProcessId()
982 * Setup a property to hold the pointer to the COMBOBOXEX
985 SetPropA(infoPtr
->hwndEdit
, COMBOEX_SUBCLASS_PROP
, hwnd
);
986 infoPtr
->prevEditWndProc
= (WNDPROC
)SetWindowLongW(infoPtr
->hwndEdit
,
987 GWL_WNDPROC
, (LONG
)COMBOEX_EditWndProc
);
988 infoPtr
->font
= SendMessageW (infoPtr
->hwndCombo
, WM_GETFONT
, 0, 0);
992 * Locate the default font if necessary and then set it in
993 * all associated controls
995 if (!infoPtr
->font
) {
996 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof(mylogfont
),
998 infoPtr
->font
= infoPtr
->defaultFont
= CreateFontIndirectW (&mylogfont
);
1000 SendMessageW (infoPtr
->hwndCombo
, WM_SETFONT
, (WPARAM
)infoPtr
->font
, 0);
1001 if (infoPtr
->hwndEdit
) {
1002 SendMessageW (infoPtr
->hwndEdit
, WM_SETFONT
, (WPARAM
)infoPtr
->font
, 0);
1003 SendMessageW (infoPtr
->hwndEdit
, EM_SETMARGINS
, (WPARAM
)EC_USEFONTINFO
, 0);
1006 COMBOEX_ReSize (infoPtr
);
1008 /* Above is fairly certain, below is much less certain. */
1010 GetWindowRect(hwnd
, &wnrc1
);
1011 GetClientRect(hwnd
, &clrc1
);
1012 GetWindowRect(infoPtr
->hwndCombo
, &cmbwrc
);
1013 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1014 wnrc1
.left
, wnrc1
.top
, wnrc1
.right
, wnrc1
.bottom
,
1015 clrc1
.left
, clrc1
.top
, clrc1
.right
, clrc1
.bottom
,
1016 cmbwrc
.left
, cmbwrc
.top
, cmbwrc
.right
, cmbwrc
.bottom
);
1017 SetWindowPos(infoPtr
->hwndCombo
, HWND_TOP
,
1018 0, 0, wnrc1
.right
-wnrc1
.left
, wnrc1
.bottom
-wnrc1
.top
,
1019 SWP_NOACTIVATE
| SWP_NOREDRAW
);
1021 GetWindowRect(infoPtr
->hwndCombo
, &cmbwrc
);
1022 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1023 cmbwrc
.left
, cmbwrc
.top
, cmbwrc
.right
, cmbwrc
.bottom
);
1024 SetWindowPos(hwnd
, HWND_TOP
,
1025 0, 0, cmbwrc
.right
-cmbwrc
.left
, cmbwrc
.bottom
-cmbwrc
.top
,
1026 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOMOVE
);
1028 COMBOEX_AdjustEditPos (infoPtr
);
1031 * Create an item structure to represent the data in the
1032 * EDIT control. It is allocated zero-filled.
1034 infoPtr
->edit
= (CBE_ITEMDATA
*)COMCTL32_Alloc (sizeof (CBE_ITEMDATA
));
1035 if (!infoPtr
->edit
) {
1036 COMBOEX_Destroy(infoPtr
);
1044 static LRESULT
COMBOEX_Command (COMBOEX_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1047 INT command
= HIWORD(wParam
);
1048 CBE_ITEMDATA
*item
= 0;
1050 INT cursel
, n
, oldItem
;
1051 NMCBEENDEDITW cbeend
;
1053 HWND parent
= GetParent (infoPtr
->hwndSelf
);
1055 TRACE("for command %d\n", command
);
1060 SetFocus (infoPtr
->hwndCombo
);
1061 ShowWindow (infoPtr
->hwndEdit
, SW_HIDE
);
1062 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1065 SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1067 * from native trace of first dropdown after typing in URL in IE4
1068 * CB_GETCURSEL(Combo)
1069 * GetWindowText(Edit)
1070 * CB_GETCURSEL(Combo)
1071 * CB_GETCOUNT(Combo)
1072 * CB_GETITEMDATA(Combo, n)
1073 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1074 * CB_GETCURSEL(Combo)
1075 * CB_SETCURSEL(COMBOEX, n)
1077 * the rest is supposition
1079 ShowWindow (infoPtr
->hwndEdit
, SW_SHOW
);
1080 InvalidateRect (infoPtr
->hwndCombo
, 0, TRUE
);
1081 InvalidateRect (infoPtr
->hwndEdit
, 0, TRUE
);
1082 cursel
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1084 /* find match from edit against those in Combobox */
1085 GetWindowTextW (infoPtr
->hwndEdit
, wintext
, 520);
1086 n
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCOUNT
, 0, 0);
1087 for (cursel
= 0; cursel
< n
; cursel
++){
1088 item
= get_item_data(infoPtr
, cursel
);
1089 if ((INT
)item
== CB_ERR
) break;
1090 if (!lstrcmpiW(COMBOEX_GetText(infoPtr
, item
), wintext
)) break;
1092 if ((cursel
== n
) || ((INT
)item
== CB_ERR
)) {
1093 TRACE("failed to find match??? item=%p cursel=%d\n",
1095 if (infoPtr
->hwndEdit
)
1096 SetFocus(infoPtr
->hwndEdit
);
1101 item
= get_item_data(infoPtr
, cursel
);
1102 if ((INT
)item
== CB_ERR
) {
1103 TRACE("failed to find match??? item=%p cursel=%d\n",
1105 if (infoPtr
->hwndEdit
)
1106 SetFocus(infoPtr
->hwndEdit
);
1111 /* Save flags for testing and reset them */
1112 oldflags
= infoPtr
->flags
;
1113 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1115 if (oldflags
& WCBE_ACTEDIT
) {
1116 cbeend
.fChanged
= (oldflags
& WCBE_EDITCHG
);
1117 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1118 CB_GETCURSEL
, 0, 0);
1119 cbeend
.iWhy
= CBENF_DROPDOWN
;
1121 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, COMBOEX_GetText(infoPtr
, item
))) return 0;
1124 /* if selection has changed the set the new current selection */
1125 cursel
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1126 if ((oldflags
& WCBE_EDITCHG
) || (cursel
!= infoPtr
->selected
)) {
1127 infoPtr
->selected
= cursel
;
1128 SendMessageW (infoPtr
->hwndSelf
, CB_SETCURSEL
, cursel
, 0);
1129 SetFocus(infoPtr
->hwndCombo
);
1135 * CB_GETCURSEL(Combo)
1136 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1139 * WM_GETTEXTLENGTH(Edit)
1141 * EM_SETSEL(Edit, 0,0)
1142 * WM_GETTEXTLENGTH(Edit)
1144 * EM_SETSEL(Edit, 0,len)
1145 * return WM_COMMAND to parent
1147 oldItem
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1148 if (!(item
= COMBOEX_FindItem(infoPtr
, oldItem
))) {
1149 ERR("item %d not found. Problem!\n", oldItem
);
1152 infoPtr
->selected
= oldItem
;
1153 COMBOEX_SetEditText (infoPtr
, item
);
1154 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1158 * We have to change the handle since we are the control
1159 * issuing the message. IE4 depends on this.
1161 return SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1165 * from native trace:
1168 * WM_GETTEXT(Edit, 104)
1169 * CB_GETCURSEL(Combo) rets -1
1170 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1171 * CB_GETCURSEL(Combo)
1172 * InvalidateRect(Combo, 0, 0)
1175 SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1176 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1177 GetWindowTextW (infoPtr
->hwndEdit
, wintext
, 260);
1178 cbeend
.fChanged
= (infoPtr
->flags
& WCBE_EDITCHG
);
1179 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1180 CB_GETCURSEL
, 0, 0);
1181 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1183 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1184 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, wintext
)) return 0;
1186 /* possible CB_GETCURSEL */
1187 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1192 * We have to change the handle since we are the control
1193 * issuing the message. IE4 depends on this.
1194 * We also need to set the focus back to the Edit control
1195 * after passing the command to the parent of the ComboEx.
1197 lret
= SendMessageW (parent
, WM_COMMAND
, wParam
, (LPARAM
)infoPtr
->hwndSelf
);
1198 if (infoPtr
->hwndEdit
)
1199 SetFocus(infoPtr
->hwndEdit
);
1206 static BOOL
COMBOEX_WM_DeleteItem (COMBOEX_INFO
*infoPtr
, DELETEITEMSTRUCT
*dis
)
1208 CBE_ITEMDATA
*item
, *olditem
;
1209 NMCOMBOBOXEXW nmcit
;
1212 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1213 dis
->CtlType
, dis
->CtlID
, dis
->itemID
, dis
->hwndItem
, dis
->itemData
);
1215 if (dis
->itemID
>= infoPtr
->nb_items
) return FALSE
;
1217 olditem
= infoPtr
->items
;
1218 i
= infoPtr
->nb_items
- 1;
1220 if (i
== dis
->itemID
) {
1221 infoPtr
->items
= infoPtr
->items
->next
;
1227 /* find the prior item in the list */
1228 while (item
->next
&& (i
> dis
->itemID
)) {
1229 item
= (CBE_ITEMDATA
*)item
->next
;
1232 if (!item
->next
|| (i
!= dis
->itemID
)) {
1233 ERR("COMBOBOXEX item structures broken. Please report!\n");
1236 olditem
= item
->next
;
1237 item
->next
= (CBE_ITEMDATA
*)((CBE_ITEMDATA
*)item
->next
)->next
;
1239 infoPtr
->nb_items
--;
1241 memset (&nmcit
.ceItem
, 0, sizeof(nmcit
.ceItem
));
1242 COMBOEX_CopyItem (olditem
, &nmcit
.ceItem
);
1243 COMBOEX_NotifyItem (infoPtr
, CBEN_DELETEITEM
, &nmcit
);
1245 COMBOEX_FreeText(olditem
);
1246 COMCTL32_Free(olditem
);
1252 static LRESULT
COMBOEX_DrawItem (COMBOEX_INFO
*infoPtr
, DRAWITEMSTRUCT
*dis
)
1254 WCHAR nil
[] = { 0 };
1255 CBE_ITEMDATA
*item
= 0;
1261 COLORREF nbkc
, ntxc
, bkc
, txc
;
1262 int drawimage
, drawstate
, xioff
;
1264 if (!IsWindowEnabled(infoPtr
->hwndCombo
)) return 0;
1266 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1267 dis
->CtlType
, dis
->CtlID
);
1268 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1269 dis
->itemID
, dis
->itemAction
, dis
->itemState
);
1270 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1271 dis
->hwndItem
, dis
->hDC
, dis
->rcItem
.left
,
1272 dis
->rcItem
.top
, dis
->rcItem
.right
, dis
->rcItem
.bottom
,
1276 /* "itemID - Specifies the menu item identifier for a menu */
1277 /* item or the index of the item in a list box or combo box. */
1278 /* For an empty list box or combo box, this member can be -1. */
1279 /* This allows the application to draw only the focus */
1280 /* rectangle at the coordinates specified by the rcItem */
1281 /* member even though there are no items in the control. */
1282 /* This indicates to the user whether the list box or combo */
1283 /* box has the focus. How the bits are set in the itemAction */
1284 /* member determines whether the rectangle is to be drawn as */
1285 /* though the list box or combo box has the focus. */
1286 if (dis
->itemID
== 0xffffffff) {
1287 if ( ( (dis
->itemAction
& ODA_FOCUS
) && (dis
->itemState
& ODS_SELECTED
)) ||
1288 ( (dis
->itemAction
& (ODA_SELECT
| ODA_DRAWENTIRE
)) && (dis
->itemState
& ODS_FOCUS
) ) ) {
1290 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1291 dis
->rcItem
.left
, dis
->rcItem
.top
,
1292 dis
->rcItem
.right
, dis
->rcItem
.bottom
);
1294 else if ((dis
->CtlType
== ODT_COMBOBOX
) &&
1295 (dis
->itemAction
== ODA_DRAWENTIRE
)) {
1296 /* draw of edit control data */
1300 RECT exrc
, cbrc
, edrc
;
1301 GetWindowRect (infoPtr
->hwndSelf
, &exrc
);
1302 GetWindowRect (infoPtr
->hwndCombo
, &cbrc
);
1303 edrc
.left
=edrc
.top
=edrc
.right
=edrc
.bottom
=-1;
1304 if (infoPtr
->hwndEdit
)
1305 GetWindowRect (infoPtr
->hwndEdit
, &edrc
);
1306 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1307 exrc
.left
, exrc
.top
, exrc
.right
, exrc
.bottom
,
1308 cbrc
.left
, cbrc
.top
, cbrc
.right
, cbrc
.bottom
,
1309 edrc
.left
, edrc
.top
, edrc
.right
, edrc
.bottom
);
1313 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1314 dis
->rcItem
.left
, dis
->rcItem
.top
,
1315 dis
->rcItem
.right
, dis
->rcItem
.bottom
,
1316 dis
->itemAction
, dis
->itemState
);
1321 /* If draw item is -1 (edit control) setup the item pointer */
1322 if (dis
->itemID
== 0xffffffff) {
1323 item
= infoPtr
->edit
;
1325 if (infoPtr
->hwndEdit
) {
1328 /* free previous text of edit item */
1329 COMBOEX_FreeText(item
);
1330 item
->mask
&= ~CBEIF_TEXT
;
1331 if( (len
= GetWindowTextLengthW(infoPtr
->hwndEdit
)) ) {
1332 item
->mask
|= CBEIF_TEXT
;
1333 item
->pszText
= (LPWSTR
)COMCTL32_Alloc ((len
+ 1)*sizeof(WCHAR
));
1335 GetWindowTextW(infoPtr
->hwndEdit
, item
->pszText
, len
+1);
1337 TRACE("edit control hwndEdit=%0x, text len=%d str=%s\n",
1338 infoPtr
->hwndEdit
, len
, debugstr_txt(item
->pszText
));
1344 /* if the item pointer is not set, then get the data and locate it */
1346 item
= get_item_data(infoPtr
, dis
->itemID
);
1347 if (item
== (CBE_ITEMDATA
*)CB_ERR
) {
1348 ERR("invalid item for id %d \n", dis
->itemID
);
1353 if (TRACE_ON(comboex
)) COMBOEX_DumpItem (item
);
1355 xbase
= CBE_STARTOFFSET
;
1356 if ((item
->mask
& CBEIF_INDENT
) && (dis
->itemState
& ODS_COMBOEXLBOX
)) {
1357 INT indent
= item
->iIndent
;
1358 if (indent
== I_INDENTCALLBACK
) {
1360 ZeroMemory(&nmce
, sizeof(nmce
));
1361 nmce
.ceItem
.mask
= CBEIF_INDENT
;
1362 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1363 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
1364 item
->iIndent
= nmce
.ceItem
.iIndent
;
1365 indent
= nmce
.ceItem
.iIndent
;
1367 xbase
+= (indent
* CBE_INDENT
);
1371 drawstate
= ILD_NORMAL
;
1372 if (item
->mask
& CBEIF_IMAGE
)
1373 drawimage
= item
->iImage
;
1374 if (dis
->itemState
& ODS_COMBOEXLBOX
) {
1375 /* drawing listbox entry */
1376 if (dis
->itemState
& ODS_SELECTED
) {
1377 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1378 drawimage
= item
->iSelectedImage
;
1379 drawstate
= ILD_SELECTED
;
1382 /* drawing combo/edit entry */
1383 if (IsWindowVisible(infoPtr
->hwndEdit
)) {
1384 /* if we have an edit control, the slave the
1385 * selection state to the Edit focus state
1387 if (infoPtr
->flags
& WCBE_EDITFOCUSED
) {
1388 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1389 drawimage
= item
->iSelectedImage
;
1390 drawstate
= ILD_SELECTED
;
1393 /* if we don't have an edit control, use
1394 * the requested state.
1396 if (dis
->itemState
& ODS_SELECTED
) {
1397 if (item
->mask
& CBEIF_SELECTEDIMAGE
)
1398 drawimage
= item
->iSelectedImage
;
1399 drawstate
= ILD_SELECTED
;
1404 if (infoPtr
->himl
&& !(infoPtr
->dwExtStyle
& CBES_EX_NOEDITIMAGEINDENT
)) {
1406 iinfo
.rcImage
.left
= iinfo
.rcImage
.right
= 0;
1407 ImageList_GetImageInfo(infoPtr
->himl
, 0, &iinfo
);
1408 xioff
= iinfo
.rcImage
.right
- iinfo
.rcImage
.left
+ CBE_SEP
;
1411 /* setup pointer to text to be drawn */
1412 str
= COMBOEX_GetText(infoPtr
, item
);
1413 if (!str
) str
= nil
;
1415 len
= strlenW (str
);
1416 GetTextExtentPoint32W (dis
->hDC
, str
, len
, &txtsize
);
1418 if (dis
->itemAction
& (ODA_SELECT
| ODA_DRAWENTIRE
)) {
1419 int overlay
= item
->iOverlay
;
1421 if (drawimage
== I_IMAGECALLBACK
) {
1423 ZeroMemory(&nmce
, sizeof(nmce
));
1424 nmce
.ceItem
.mask
= (drawstate
== ILD_NORMAL
) ? CBEIF_IMAGE
: CBEIF_SELECTEDIMAGE
;
1425 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1426 if (drawstate
== ILD_NORMAL
) {
1427 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) item
->iImage
= nmce
.ceItem
.iImage
;
1428 drawimage
= nmce
.ceItem
.iImage
;
1429 } else if (drawstate
== ILD_SELECTED
) {
1430 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
) item
->iSelectedImage
= nmce
.ceItem
.iSelectedImage
;
1431 drawimage
= nmce
.ceItem
.iSelectedImage
;
1432 } else ERR("Bad draw state = %d\n", drawstate
);
1435 if (overlay
== I_IMAGECALLBACK
) {
1437 ZeroMemory(&nmce
, sizeof(nmce
));
1438 nmce
.ceItem
.mask
= CBEIF_OVERLAY
;
1439 COMBOEX_NotifyItem(infoPtr
, CBEN_GETDISPINFOW
, &nmce
);
1440 if (nmce
.ceItem
.mask
& CBEIF_DI_SETITEM
)
1441 item
->iOverlay
= nmce
.ceItem
.iOverlay
;
1442 overlay
= nmce
.ceItem
.iOverlay
;
1445 if (drawimage
>= 0 &&
1446 !(infoPtr
->dwExtStyle
& (CBES_EX_NOEDITIMAGE
| CBES_EX_NOEDITIMAGEINDENT
))) {
1447 if (overlay
> 0) ImageList_SetOverlayImage (infoPtr
->himl
, overlay
, 1);
1448 ImageList_Draw (infoPtr
->himl
, drawimage
, dis
->hDC
, xbase
, dis
->rcItem
.top
,
1449 drawstate
| (overlay
> 0 ? INDEXTOOVERLAYMASK(1) : 0));
1452 /* now draw the text */
1453 if (!IsWindowVisible (infoPtr
->hwndEdit
)) {
1454 nbkc
= GetSysColor ((dis
->itemState
& ODS_SELECTED
) ?
1455 COLOR_HIGHLIGHT
: COLOR_WINDOW
);
1456 bkc
= SetBkColor (dis
->hDC
, nbkc
);
1457 ntxc
= GetSysColor ((dis
->itemState
& ODS_SELECTED
) ?
1458 COLOR_HIGHLIGHTTEXT
: COLOR_WINDOWTEXT
);
1459 txc
= SetTextColor (dis
->hDC
, ntxc
);
1461 y
= dis
->rcItem
.top
+
1462 (dis
->rcItem
.bottom
- dis
->rcItem
.top
- txtsize
.cy
) / 2;
1464 rect
.right
= x
+ txtsize
.cx
;
1465 rect
.top
= dis
->rcItem
.top
+ 1;
1466 rect
.bottom
= dis
->rcItem
.bottom
- 1;
1467 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1468 dis
->itemID
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1469 ExtTextOutW (dis
->hDC
, x
, y
, ETO_OPAQUE
| ETO_CLIPPED
,
1470 &rect
, str
, len
, 0);
1471 SetBkColor (dis
->hDC
, bkc
);
1472 SetTextColor (dis
->hDC
, txc
);
1476 if (dis
->itemAction
& ODA_FOCUS
) {
1477 rect
.left
= xbase
+ xioff
- 1;
1478 rect
.right
= rect
.left
+ txtsize
.cx
+ 2;
1479 rect
.top
= dis
->rcItem
.top
;
1480 rect
.bottom
= dis
->rcItem
.bottom
;
1481 DrawFocusRect(dis
->hDC
, &rect
);
1488 static LRESULT
COMBOEX_Destroy (COMBOEX_INFO
*infoPtr
)
1490 if (infoPtr
->hwndCombo
)
1491 DestroyWindow (infoPtr
->hwndCombo
);
1493 if (infoPtr
->edit
) {
1494 COMCTL32_Free (infoPtr
->edit
);
1498 if (infoPtr
->items
) {
1499 CBE_ITEMDATA
*item
, *next
;
1501 item
= infoPtr
->items
;
1503 next
= (CBE_ITEMDATA
*)item
->next
;
1504 COMBOEX_FreeText (item
);
1505 COMCTL32_Free (item
);
1511 if (infoPtr
->defaultFont
)
1512 DeleteObject (infoPtr
->defaultFont
);
1514 /* free comboex info data */
1515 COMCTL32_Free (infoPtr
);
1516 SetWindowLongW (infoPtr
->hwndSelf
, 0, 0);
1521 static LRESULT
COMBOEX_MeasureItem (COMBOEX_INFO
*infoPtr
, MEASUREITEMSTRUCT
*mis
)
1527 GetTextExtentPointA (hdc
, "W", 1, &mysize
);
1529 mis
->itemHeight
= mysize
.cy
+ CBE_EXTRA
;
1531 TRACE("adjusted height hwnd=%08x, height=%d\n",
1532 infoPtr
->hwndSelf
, mis
->itemHeight
);
1538 static LRESULT
COMBOEX_NCCreate (HWND hwnd
)
1540 /* WARNING: The COMBOEX_INFO structure is not yet created */
1541 DWORD oldstyle
, newstyle
;
1543 oldstyle
= (DWORD
)GetWindowLongW (hwnd
, GWL_STYLE
);
1544 newstyle
= oldstyle
& ~(WS_VSCROLL
| WS_HSCROLL
);
1545 if (newstyle
!= oldstyle
) {
1546 TRACE("req style %08lx, reseting style %08lx\n",
1547 oldstyle
, newstyle
);
1548 SetWindowLongW (hwnd
, GWL_STYLE
, newstyle
);
1554 static LRESULT
COMBOEX_NotifyFormat (COMBOEX_INFO
*infoPtr
, LPARAM lParam
)
1556 if (lParam
== NF_REQUERY
) {
1557 INT i
= SendMessageW(GetParent (infoPtr
->hwndSelf
),
1558 WM_NOTIFYFORMAT
, infoPtr
->hwndSelf
, NF_QUERY
);
1559 infoPtr
->NtfUnicode
= (i
== NFR_UNICODE
) ? 1 : 0;
1561 return infoPtr
->NtfUnicode
? NFR_UNICODE
: NFR_ANSI
;
1565 static LRESULT
COMBOEX_Size (COMBOEX_INFO
*infoPtr
, INT width
, INT height
)
1567 TRACE("(width=%d, height=%d)\n", width
, height
);
1569 MoveWindow (infoPtr
->hwndCombo
, 0, 0, width
, height
, TRUE
);
1571 COMBOEX_AdjustEditPos (infoPtr
);
1577 static LRESULT
COMBOEX_WindowPosChanging (COMBOEX_INFO
*infoPtr
, WINDOWPOS
*wp
)
1579 RECT cbx_wrect
, cbx_crect
, cb_wrect
;
1582 GetWindowRect (infoPtr
->hwndSelf
, &cbx_wrect
);
1583 GetClientRect (infoPtr
->hwndSelf
, &cbx_crect
);
1584 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
1586 /* width is winpos value + border width of comboex */
1588 + (cbx_wrect
.right
-cbx_wrect
.left
)
1589 - (cbx_crect
.right
-cbx_crect
.left
);
1591 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1592 wp
->x
, wp
->y
, wp
->cx
, wp
->cy
, wp
->flags
);
1593 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1594 cbx_wrect
.left
, cbx_wrect
.top
, cbx_wrect
.right
, cbx_wrect
.bottom
,
1595 cbx_crect
.left
, cbx_crect
.top
, cbx_crect
.right
, cbx_crect
.bottom
);
1596 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1597 cb_wrect
.left
, cb_wrect
.top
, cb_wrect
.right
, cb_wrect
.bottom
,
1598 width
, cb_wrect
.bottom
-cb_wrect
.top
);
1600 if (width
) SetWindowPos (infoPtr
->hwndCombo
, HWND_TOP
, 0, 0,
1602 cb_wrect
.bottom
-cb_wrect
.top
,
1605 GetWindowRect (infoPtr
->hwndCombo
, &cb_wrect
);
1607 /* height is combo window height plus border width of comboex */
1608 height
= (cb_wrect
.bottom
-cb_wrect
.top
)
1609 + (cbx_wrect
.bottom
-cbx_wrect
.top
)
1610 - (cbx_crect
.bottom
-cbx_crect
.top
);
1611 if (wp
->cy
< height
) wp
->cy
= height
;
1612 if (infoPtr
->hwndEdit
) {
1613 COMBOEX_AdjustEditPos (infoPtr
);
1614 InvalidateRect (infoPtr
->hwndCombo
, 0, TRUE
);
1621 static LRESULT WINAPI
1622 COMBOEX_EditWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1624 HWND hwndComboex
= (HWND
)GetPropA(hwnd
, COMBOEX_SUBCLASS_PROP
);
1625 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwndComboex
);
1626 NMCBEENDEDITW cbeend
;
1627 WCHAR edit_text
[260];
1633 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1634 hwnd
, uMsg
, wParam
, lParam
, infoPtr
);
1636 if (!infoPtr
) return 0;
1642 /* handle (ignore) the return character */
1643 if (wParam
== VK_RETURN
) return 0;
1644 /* all other characters pass into the real Edit */
1645 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1646 hwnd
, uMsg
, wParam
, lParam
);
1650 * The following was determined by traces of the native
1653 obkc
= SetBkColor (hDC
, GetSysColor (COLOR_WINDOW
));
1654 GetClientRect (hwnd
, &rect
);
1655 TRACE("erasing (%d,%d)-(%d,%d)\n",
1656 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1657 ExtTextOutW (hDC
, 0, 0, ETO_OPAQUE
, &rect
, 0, 0, 0);
1658 SetBkColor (hDC
, obkc
);
1659 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1660 hwnd
, uMsg
, wParam
, lParam
);
1663 INT oldItem
, selected
, step
= 1;
1666 switch ((INT
)wParam
)
1669 /* native version seems to do following for COMBOEX */
1671 * GetWindowTextA(Edit,&?, 0x104) x
1672 * CB_GETCURSEL to Combo rets -1 x
1673 * WM_NOTIFY to COMBOEX parent (rebar) x
1674 * (CBEN_ENDEDIT{A|W}
1675 * fChanged = FALSE x
1676 * inewSelection = -1 x
1679 * CB_GETCURSEL to Combo rets -1 x
1680 * InvalidateRect(Combo, 0) x
1681 * WM_SETTEXT to Edit x
1682 * EM_SETSEL to Edit (0,0) x
1683 * EM_SETSEL to Edit (0,-1) x
1684 * RedrawWindow(Combo, 0, 0, 5) x
1686 TRACE("special code for VK_ESCAPE\n");
1688 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1690 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1691 cbeend
.fChanged
= FALSE
;
1692 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1693 CB_GETCURSEL
, 0, 0);
1694 cbeend
.iWhy
= CBENF_ESCAPE
;
1696 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) return 0;
1697 oldItem
= SendMessageW (infoPtr
->hwndCombo
, CB_GETCURSEL
, 0, 0);
1698 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1699 if (!(item
= COMBOEX_FindItem(infoPtr
, oldItem
))) {
1700 ERR("item %d not found. Problem!\n", oldItem
);
1703 infoPtr
->selected
= oldItem
;
1704 COMBOEX_SetEditText (infoPtr
, item
);
1705 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
|
1710 /* native version seems to do following for COMBOEX */
1712 * GetWindowTextA(Edit,&?, 0x104) x
1713 * CB_GETCURSEL to Combo rets -1 x
1714 * CB_GETCOUNT to Combo rets 0
1716 * CB_GETITEMDATA to match
1717 * *** above 3 lines simulated by FindItem x
1718 * WM_NOTIFY to COMBOEX parent (rebar) x
1719 * (CBEN_ENDEDIT{A|W} x
1720 * fChanged = TRUE (-1) x
1721 * iNewSelection = -1 or selected x
1723 * iWhy = 2 (CBENF_RETURN) x
1724 * CB_GETCURSEL to Combo rets -1 x
1725 * if -1 send CB_SETCURSEL to Combo -1 x
1726 * InvalidateRect(Combo, 0, 0) x
1728 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1731 TRACE("special code for VK_RETURN\n");
1733 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1735 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1736 selected
= SendMessageW (infoPtr
->hwndCombo
,
1737 CB_GETCURSEL
, 0, 0);
1739 if (selected
!= -1) {
1740 item
= COMBOEX_FindItem (infoPtr
, selected
);
1741 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
1742 selected
, debugstr_txt(item
->pszText
));
1743 TRACE("handling VK_RETURN, edittext=%s\n",
1744 debugstr_w(edit_text
));
1745 if (lstrcmpiW (COMBOEX_GetText(infoPtr
, item
), edit_text
)) {
1746 /* strings not equal -- indicate edit has changed */
1751 cbeend
.iNewSelection
= selected
;
1752 cbeend
.fChanged
= TRUE
;
1753 cbeend
.iWhy
= CBENF_RETURN
;
1754 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) {
1755 /* abort the change, restore previous */
1756 TRACE("Notify requested abort of change\n");
1757 COMBOEX_SetEditText (infoPtr
, infoPtr
->edit
);
1758 RedrawWindow (infoPtr
->hwndCombo
, 0, 0, RDW_ERASE
|
1762 oldItem
= SendMessageW (infoPtr
->hwndCombo
,CB_GETCURSEL
, 0, 0);
1763 if (oldItem
!= -1) {
1764 /* if something is selected, then deselect it */
1765 SendMessageW (infoPtr
->hwndCombo
, CB_SETCURSEL
,
1768 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1769 SetFocus(infoPtr
->hwndEdit
);
1775 /* by default, step is 1 */
1776 oldItem
= SendMessageW (infoPtr
->hwndSelf
, CB_GETCURSEL
, 0, 0);
1777 if (oldItem
>= 0 && oldItem
+ step
>= 0)
1778 SendMessageW (infoPtr
->hwndSelf
, CB_SETCURSEL
, oldItem
+ step
, 0);
1781 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1782 hwnd
, uMsg
, wParam
, lParam
);
1788 /* remember the focus to set state of icon */
1789 lret
= CallWindowProcW (infoPtr
->prevEditWndProc
,
1790 hwnd
, uMsg
, wParam
, lParam
);
1791 infoPtr
->flags
|= WCBE_EDITFOCUSED
;
1796 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
1798 infoPtr
->flags
&= ~WCBE_EDITFOCUSED
;
1799 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1800 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1802 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1803 cbeend
.fChanged
= FALSE
;
1804 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1805 CB_GETCURSEL
, 0, 0);
1806 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1808 COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
);
1813 return CallWindowProcW (infoPtr
->prevEditWndProc
,
1814 hwnd
, uMsg
, wParam
, lParam
);
1820 static LRESULT WINAPI
1821 COMBOEX_ComboWndProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1823 HWND hwndComboex
= (HWND
)GetPropA(hwnd
, COMBOEX_SUBCLASS_PROP
);
1824 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwndComboex
);
1825 NMCBEENDEDITW cbeend
;
1831 WCHAR edit_text
[260];
1833 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1834 hwnd
, uMsg
, wParam
, lParam
, infoPtr
);
1836 if (!infoPtr
) return 0;
1841 case CB_FINDSTRINGEXACT
:
1842 return COMBOEX_FindStringExact (infoPtr
, (INT
)wParam
, (LPCSTR
)lParam
);
1846 * The only way this message should come is from the
1847 * child Listbox issuing the message. Flag this so
1848 * that ComboEx knows this is listbox.
1850 ((DRAWITEMSTRUCT
*)lParam
)->itemState
|= ODS_COMBOEXLBOX
;
1851 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1852 hwnd
, uMsg
, wParam
, lParam
);
1856 * The following was determined by traces of the native
1859 obkc
= SetBkColor (hDC
, GetSysColor (COLOR_WINDOW
));
1860 GetClientRect (hwnd
, &rect
);
1861 TRACE("erasing (%d,%d)-(%d,%d)\n",
1862 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1863 ExtTextOutW (hDC
, 0, 0, ETO_OPAQUE
, &rect
, 0, 0, 0);
1864 SetBkColor (hDC
, obkc
);
1865 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1866 hwnd
, uMsg
, wParam
, lParam
);
1870 * WM_NOTIFY to comboex parent (rebar)
1871 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1872 * CallWindowProc (previous)
1874 nmmse
.dwItemSpec
= 0;
1875 nmmse
.dwItemData
= 0;
1878 nmmse
.dwHitInfo
= lParam
;
1879 COMBOEX_Notify (infoPtr
, NM_SETCURSOR
, (NMHDR
*)&nmmse
);
1880 return CallWindowProcW (infoPtr
->prevComboWndProc
,
1881 hwnd
, uMsg
, wParam
, lParam
);
1884 switch (HIWORD(wParam
)) {
1887 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1896 * GetFocus() retns AA
1897 * GetWindowTextA(Edit)
1898 * CB_GETCURSEL(Combo) (got -1)
1899 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1900 * CB_GETCURSEL(Combo) (got -1)
1901 * InvalidateRect(Combo, 0, 0)
1902 * WM_KILLFOCUS(Combo, AA)
1905 focusedhwnd
= GetFocus();
1906 if (infoPtr
->flags
& WCBE_ACTEDIT
) {
1907 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1908 cbeend
.fChanged
= (infoPtr
->flags
& WCBE_EDITCHG
);
1909 cbeend
.iNewSelection
= SendMessageW (infoPtr
->hwndCombo
,
1910 CB_GETCURSEL
, 0, 0);
1911 cbeend
.iWhy
= CBENF_KILLFOCUS
;
1913 infoPtr
->flags
&= ~(WCBE_ACTEDIT
| WCBE_EDITCHG
);
1914 if (COMBOEX_NotifyEndEdit (infoPtr
, &cbeend
, edit_text
)) return 0;
1916 /* possible CB_GETCURSEL */
1917 InvalidateRect (infoPtr
->hwndCombo
, 0, 0);
1919 SendMessageW (infoPtr
->hwndCombo
, WM_KILLFOCUS
,
1920 (WPARAM
)focusedhwnd
, 0);
1925 * For EN_SETFOCUS this issues the same calls and messages
1926 * as the native seems to do.
1928 * for some cases however native does the following:
1929 * (noticed after SetFocus during LBUTTONDOWN on
1930 * on dropdown arrow)
1931 * WM_GETTEXTLENGTH (Edit);
1932 * WM_GETTEXT (Edit, len+1, str);
1933 * EM_SETSEL (Edit, 0, 0);
1934 * WM_GETTEXTLENGTH (Edit);
1935 * WM_GETTEXT (Edit, len+1, str);
1936 * EM_SETSEL (Edit, 0, len);
1937 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
1941 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, 0);
1942 SendMessageW (infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
1943 COMBOEX_Notify (infoPtr
, CBEN_BEGINEDIT
, &hdr
);
1944 infoPtr
->flags
|= WCBE_ACTEDIT
;
1945 infoPtr
->flags
&= ~WCBE_EDITCHG
; /* no change yet */
1951 * For EN_CHANGE this issues the same calls and messages
1952 * as the native seems to do.
1954 WCHAR edit_text
[260];
1959 selected
= SendMessageW (infoPtr
->hwndCombo
,
1960 CB_GETCURSEL
, 0, 0);
1962 /* lstrlenA( lastworkingURL ) */
1964 GetWindowTextW (infoPtr
->hwndEdit
, edit_text
, 260);
1965 if (selected
== -1) {
1966 lastwrk
= infoPtr
->edit
->pszText
;
1969 item
= COMBOEX_FindItem (infoPtr
, selected
);
1970 lastwrk
= COMBOEX_GetText(infoPtr
, item
);
1973 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
1974 selected
, debugstr_w(lastwrk
));
1975 TRACE("handling EN_CHANGE, edittext=%s\n",
1976 debugstr_w(edit_text
));
1978 /* lstrcmpiW is between lastworkingURL and GetWindowText */
1979 if (lstrcmpiW (lastwrk
, edit_text
)) {
1980 /* strings not equal -- indicate edit has changed */
1981 infoPtr
->flags
|= WCBE_EDITCHG
;
1983 SendMessageW ( GetParent(infoPtr
->hwndSelf
), WM_COMMAND
,
1984 MAKEWPARAM(GetDlgCtrlID (infoPtr
->hwndSelf
),
1992 * Therefore from traces there is no additional code here
1996 * Using native COMCTL32 gets the following:
1997 * 1 == SHDOCVW.DLL issues call/message
1998 * 2 == COMCTL32.DLL issues call/message
1999 * 3 == WINE issues call/message
2002 * for LBN_SELCHANGE:
2003 * 1 CB_GETCURSEL(ComboEx)
2004 * 1 CB_GETDROPPEDSTATE(ComboEx)
2005 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2006 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2007 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2008 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2009 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2010 * 3 ShowWindow(ComboLB, SW_HIDE)
2011 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2012 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2014 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2015 * ? LB_GETCURSEL <==|
2017 * ? LB_GETTEXT | Needs to be added to
2018 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2019 * ? LB_GETITEMDATA |
2020 * ? WM_DRAWITEM(ComboEx) <==|
2026 return CallWindowProcW (infoPtr
->prevComboWndProc
,
2027 hwnd
, uMsg
, wParam
, lParam
);
2033 static LRESULT WINAPI
2034 COMBOEX_WindowProc (HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2036 COMBOEX_INFO
*infoPtr
= COMBOEX_GetInfoPtr (hwnd
);
2038 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd
, uMsg
, wParam
, lParam
);
2041 if (uMsg
== WM_CREATE
)
2042 return COMBOEX_Create (hwnd
, (LPCREATESTRUCTA
)lParam
);
2043 if (uMsg
== WM_NCCREATE
)
2044 COMBOEX_NCCreate (hwnd
);
2045 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2050 case CBEM_DELETEITEM
:
2051 return COMBOEX_DeleteItem (infoPtr
, wParam
);
2053 case CBEM_GETCOMBOCONTROL
:
2054 return infoPtr
->hwndCombo
;
2056 case CBEM_GETEDITCONTROL
:
2057 return infoPtr
->hwndEdit
;
2059 case CBEM_GETEXTENDEDSTYLE
:
2060 return infoPtr
->dwExtStyle
;
2062 case CBEM_GETIMAGELIST
:
2063 return (LRESULT
)infoPtr
->himl
;
2066 return (LRESULT
)COMBOEX_GetItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2069 return (LRESULT
)COMBOEX_GetItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2071 case CBEM_GETUNICODEFORMAT
:
2072 return infoPtr
->unicode
;
2074 case CBEM_HASEDITCHANGED
:
2075 return COMBOEX_HasEditChanged (infoPtr
);
2077 case CBEM_INSERTITEMA
:
2078 return COMBOEX_InsertItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2080 case CBEM_INSERTITEMW
:
2081 return COMBOEX_InsertItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2083 case CBEM_SETEXSTYLE
:
2084 case CBEM_SETEXTENDEDSTYLE
:
2085 return COMBOEX_SetExtendedStyle (infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
2087 case CBEM_SETIMAGELIST
:
2088 return (LRESULT
)COMBOEX_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2091 return COMBOEX_SetItemA (infoPtr
, (COMBOBOXEXITEMA
*)lParam
);
2094 return COMBOEX_SetItemW (infoPtr
, (COMBOBOXEXITEMW
*)lParam
);
2096 case CBEM_SETUNICODEFORMAT
:
2097 return COMBOEX_SetUnicodeFormat (infoPtr
, wParam
);
2099 /*case CBEM_SETWINDOWTHEME:
2100 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
2102 /* Combo messages we are not sure if we need to process or just forward */
2103 case CB_GETDROPPEDCONTROLRECT
:
2104 case CB_GETITEMHEIGHT
:
2106 case CB_GETLBTEXTLEN
:
2107 case CB_GETEXTENDEDUI
:
2109 case CB_RESETCONTENT
:
2110 case CB_SELECTSTRING
:
2113 FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
2114 uMsg
, wParam
, lParam
);
2116 /* Combo messages OK to just forward to the regular COMBO */
2119 case CB_GETDROPPEDSTATE
:
2120 case CB_SETDROPPEDWIDTH
:
2121 case CB_SETEXTENDEDUI
:
2122 case CB_SHOWDROPDOWN
:
2123 return SendMessageW (infoPtr
->hwndCombo
, uMsg
, wParam
, lParam
);
2125 /* Combo messages we need to process specially */
2126 case CB_FINDSTRINGEXACT
:
2127 return COMBOEX_FindStringExact (infoPtr
, (INT
)wParam
, (LPCSTR
)lParam
);
2129 case CB_GETITEMDATA
:
2130 return COMBOEX_GetItemData (infoPtr
, (INT
)wParam
);
2133 return COMBOEX_SetCursel (infoPtr
, (INT
)wParam
);
2135 case CB_SETITEMDATA
:
2136 return COMBOEX_SetItemData (infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
2138 case CB_SETITEMHEIGHT
:
2139 return COMBOEX_SetItemHeight (infoPtr
, (INT
)wParam
, (UINT
)lParam
);
2143 /* Window messages passed to parent */
2145 return COMBOEX_Command (infoPtr
, wParam
, lParam
);
2148 if (infoPtr
->NtfUnicode
)
2149 return SendMessageW (GetParent (hwnd
), uMsg
, wParam
, lParam
);
2151 return SendMessageA (GetParent (hwnd
), uMsg
, wParam
, lParam
);
2154 /* Window messages we need to process */
2156 return COMBOEX_WM_DeleteItem (infoPtr
, (DELETEITEMSTRUCT
*)lParam
);
2159 return COMBOEX_DrawItem (infoPtr
, (DRAWITEMSTRUCT
*)lParam
);
2162 return COMBOEX_Destroy (infoPtr
);
2164 case WM_MEASUREITEM
:
2165 return COMBOEX_MeasureItem (infoPtr
, (MEASUREITEMSTRUCT
*)lParam
);
2167 case WM_NOTIFYFORMAT
:
2168 return COMBOEX_NotifyFormat (infoPtr
, lParam
);
2171 return COMBOEX_Size (infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
2173 case WM_WINDOWPOSCHANGING
:
2174 return COMBOEX_WindowPosChanging (infoPtr
, (WINDOWPOS
*)lParam
);
2177 if (uMsg
>= WM_USER
)
2178 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg
,wParam
,lParam
);
2179 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2185 void COMBOEX_Register (void)
2189 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2190 wndClass
.style
= CS_GLOBALCLASS
;
2191 wndClass
.lpfnWndProc
= (WNDPROC
)COMBOEX_WindowProc
;
2192 wndClass
.cbClsExtra
= 0;
2193 wndClass
.cbWndExtra
= sizeof(COMBOEX_INFO
*);
2194 wndClass
.hCursor
= LoadCursorW (0, IDC_ARROWW
);
2195 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
2196 wndClass
.lpszClassName
= WC_COMBOBOXEXW
;
2198 RegisterClassW (&wndClass
);
2202 void COMBOEX_Unregister (void)
2204 UnregisterClassW (WC_COMBOBOXEXW
, (HINSTANCE
)NULL
);