4 * Copyright 1997 Alex Korobka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * This code was audited for completeness against the documented features
23 * of Comctl32.dll version 6.0 on Oct. 4, 2004, by Dimitrie O. Paun.
25 * Unless otherwise noted, we believe this code to be complete, as per
26 * the specification mentioned above.
27 * If you discover missing features, or bugs, please note them below.
30 * - ComboBox_[GS]etMinVisible()
31 * - CB_GETMINVISIBLE, CB_SETMINVISIBLE
37 #include <wine/debug.h>
38 WINE_DEFAULT_DEBUG_CHANNEL(combo
);
40 /* bits in the dwKeyData */
41 #define KEYDATA_ALT 0x2000
42 #define KEYDATA_PREVSTATE 0x4000
45 * Additional combo box definitions
48 #define CB_NOTIFY( lphc, code ) \
49 (SendMessageW((lphc)->owner, WM_COMMAND, \
50 MAKEWPARAM(GetWindowLongPtrW((lphc)->self,GWLP_ID), (code)), (LPARAM)(lphc)->self))
52 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
53 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
54 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
55 #define CB_HWND( lphc ) ((lphc)->self)
56 // ReactOS already define in include/controls.h We have it here as a sync note.
57 //#define CB_GETTYPE( lphc ) ((lphc)->dwStyle & (CBS_DROPDOWNLIST))
59 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
64 static HBITMAP hComboBmp
= 0;
65 static UINT CBitHeight
, CBitWidth
;
68 * Look and feel dependent "constants"
71 #define COMBO_YBORDERGAP 5
72 #define COMBO_XBORDERSIZE() 2
73 #define COMBO_YBORDERSIZE() 2
74 #define COMBO_EDITBUTTONSPACE() 0
75 #define EDIT_CONTROL_PADDING() 1
77 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
78 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
80 /*********************************************************************
81 * combo class descriptor
83 const struct builtin_class_descr COMBO_builtin_class
=
86 L
"ComboBox", /* name */
87 CS_PARENTDC
| CS_VREDRAW
| CS_HREDRAW
| CS_DBLCLKS
, /* style */
88 (WNDPROC
) ComboWndProcW
, /* procW */
89 (WNDPROC
) ComboWndProcA
, /* procA */
90 sizeof(HEADCOMBO
*), /* extra */
91 (LPCWSTR
) IDC_ARROW
, /* cursor */
94 "ComboBox", /* name */
95 CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
, /* style */
96 ComboWndProcA
, /* procA */
97 ComboWndProcW
, /* procW */
98 sizeof(HEADCOMBO
*), /* extra */
99 IDC_ARROW
, /* cursor */
105 /***********************************************************************
108 * Load combo button bitmap.
110 static BOOL
COMBO_Init(void)
114 if( hComboBmp
) return TRUE
;
115 if( (hDC
= CreateCompatibleDC(0)) )
118 if( (hComboBmp
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO
))) )
124 GetObjectW( hComboBmp
, sizeof(bm
), &bm
);
125 CBitHeight
= bm
.bmHeight
;
126 CBitWidth
= bm
.bmWidth
;
128 TRACE("combo bitmap [%i,%i]\n", CBitWidth
, CBitHeight
);
130 hPrevB
= SelectObject( hDC
, hComboBmp
);
131 SetRect( &r
, 0, 0, CBitWidth
, CBitHeight
);
132 InvertRect( hDC
, &r
);
133 SelectObject( hDC
, hPrevB
);
143 /* Retrieve the UI state for the control */
144 static BOOL
COMBO_update_uistate(LPHEADCOMBO lphc
)
148 prev_flags
= lphc
->UIState
;
149 lphc
->UIState
= DefWindowProcW(lphc
->self
, WM_QUERYUISTATE
, 0, 0);
150 return prev_flags
!= lphc
->UIState
;
153 /***********************************************************************
156 static LRESULT
COMBO_NCCreate(HWND hwnd
, LONG style
)
160 if (COMBO_Init() && (lphc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HEADCOMBO
))) )
163 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)lphc
);
165 COMBO_update_uistate(lphc
);
167 /* some braindead apps do try to use scrollbar/border flags */
169 lphc
->dwStyle
= style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
);
170 SetWindowLongW( hwnd
, GWL_STYLE
, style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
) );
173 * We also have to remove the client edge style to make sure
174 * we don't end-up with a non client area.
176 SetWindowLongW( hwnd
, GWL_EXSTYLE
,
177 GetWindowLongW( hwnd
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
179 if( !(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) )
180 lphc
->dwStyle
|= CBS_HASSTRINGS
;
181 if( !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) )
182 lphc
->wState
|= CBF_NOTIFY
;
184 TRACE("[%p], style = %08x\n", lphc
, lphc
->dwStyle
);
190 /***********************************************************************
193 static LRESULT
COMBO_NCDestroy( LPHEADCOMBO lphc
)
198 TRACE("[%p]: freeing storage\n", lphc
->self
);
200 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) && lphc
->hWndLBox
)
201 DestroyWindow( lphc
->hWndLBox
);
203 SetWindowLongPtrW( lphc
->self
, 0, 0 );
204 HeapFree( GetProcessHeap(), 0, lphc
);
209 /***********************************************************************
210 * CBGetTextAreaHeight
212 * This method will calculate the height of the text area of the
214 * The height of the text area is set in two ways.
215 * It can be set explicitly through a combobox message or through a
216 * WM_MEASUREITEM callback.
217 * If this is not the case, the height is set to font height + 4px
218 * This height was determined through experimentation.
219 * CBCalcPlacement will add 2*COMBO_YBORDERSIZE pixels for the border
221 static INT
CBGetTextAreaHeight(
227 if( lphc
->editHeight
) /* explicitly set height */
229 iTextItemHeight
= lphc
->editHeight
;
234 HDC hDC
= GetDC(hwnd
);
239 hPrevFont
= SelectObject( hDC
, lphc
->hFont
);
241 GetTextMetricsW(hDC
, &tm
);
243 baseUnitY
= tm
.tmHeight
;
246 SelectObject( hDC
, hPrevFont
);
248 ReleaseDC(hwnd
, hDC
);
250 iTextItemHeight
= baseUnitY
+ 4;
254 * Check the ownerdraw case if we haven't asked the parent the size
257 if ( CB_OWNERDRAWN(lphc
) &&
258 (lphc
->wState
& CBF_MEASUREITEM
) )
260 MEASUREITEMSTRUCT measureItem
;
262 INT originalItemHeight
= iTextItemHeight
;
263 UINT id
= (UINT
)GetWindowLongPtrW( lphc
->self
, GWLP_ID
);
266 * We use the client rect for the width of the item.
268 GetClientRect(hwnd
, &clientRect
);
270 lphc
->wState
&= ~CBF_MEASUREITEM
;
273 * Send a first one to measure the size of the text area
275 measureItem
.CtlType
= ODT_COMBOBOX
;
276 measureItem
.CtlID
= id
;
277 measureItem
.itemID
= -1;
278 measureItem
.itemWidth
= clientRect
.right
;
279 measureItem
.itemHeight
= iTextItemHeight
- 6; /* ownerdrawn cb is taller */
280 measureItem
.itemData
= 0;
281 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
282 iTextItemHeight
= 6 + measureItem
.itemHeight
;
285 * Send a second one in the case of a fixed ownerdraw list to calculate the
286 * size of the list items. (we basically do this on behalf of the listbox)
288 if (lphc
->dwStyle
& CBS_OWNERDRAWFIXED
)
290 measureItem
.CtlType
= ODT_COMBOBOX
;
291 measureItem
.CtlID
= id
;
292 measureItem
.itemID
= 0;
293 measureItem
.itemWidth
= clientRect
.right
;
294 measureItem
.itemHeight
= originalItemHeight
;
295 measureItem
.itemData
= 0;
296 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
297 lphc
->fixedOwnerDrawHeight
= measureItem
.itemHeight
;
301 * Keep the size for the next time
303 lphc
->editHeight
= iTextItemHeight
;
306 return iTextItemHeight
;
309 /***********************************************************************
312 * The dummy resize is used for listboxes that have a popup to trigger
313 * a re-arranging of the contents of the combobox and the recalculation
314 * of the size of the "real" control window.
316 static void CBForceDummyResize(
322 newComboHeight
= CBGetTextAreaHeight(lphc
->self
,lphc
) + 2*COMBO_YBORDERSIZE();
324 GetWindowRect(lphc
->self
, &windowRect
);
327 * We have to be careful, resizing a combobox also has the meaning that the
328 * dropped rect will be resized. In this case, we want to trigger a resize
329 * to recalculate layout but we don't want to change the dropped rectangle
330 * So, we pass the height of text area of control as the height.
331 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
334 SetWindowPos( lphc
->self
,
337 windowRect
.right
- windowRect
.left
,
339 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
342 /***********************************************************************
345 * Set up component coordinates given valid lphc->RectCombo.
347 static void CBCalcPlacement(
355 * Again, start with the client rectangle.
357 GetClientRect(hwnd
, lprEdit
);
362 InflateRect(lprEdit
, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
365 * Chop off the bottom part to fit with the height of the text area.
367 lprEdit
->bottom
= lprEdit
->top
+ CBGetTextAreaHeight(hwnd
, lphc
);
370 * The button starts the same vertical position as the text area.
372 CopyRect(lprButton
, lprEdit
);
375 * If the combobox is "simple" there is no button.
377 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
378 lprButton
->left
= lprButton
->right
= lprButton
->bottom
= 0;
382 * Let's assume the combobox button is the same width as the
384 * size the button horizontally and cut-off the text area.
386 lprButton
->left
= lprButton
->right
- GetSystemMetrics(SM_CXVSCROLL
);
387 lprEdit
->right
= lprButton
->left
;
391 * In the case of a dropdown, there is an additional spacing between the
392 * text area and the button.
394 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
396 lprEdit
->right
-= COMBO_EDITBUTTONSPACE();
400 * If we have an edit control, we space it away from the borders slightly.
402 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
404 InflateRect(lprEdit
, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
408 * Adjust the size of the listbox popup.
410 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
413 * Use the client rectangle to initialize the listbox rectangle
415 GetClientRect(hwnd
, lprLB
);
418 * Then, chop-off the top part.
420 lprLB
->top
= lprEdit
->bottom
+ COMBO_YBORDERSIZE();
425 * Make sure the dropped width is as large as the combobox itself.
427 if (lphc
->droppedWidth
< (lprButton
->right
+ COMBO_XBORDERSIZE()))
429 lprLB
->right
= lprLB
->left
+ (lprButton
->right
+ COMBO_XBORDERSIZE());
432 * In the case of a dropdown, the popup listbox is offset to the right.
433 * so, we want to make sure it's flush with the right side of the
436 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
437 lprLB
->right
-= COMBO_EDITBUTTONSPACE();
440 lprLB
->right
= lprLB
->left
+ lphc
->droppedWidth
;
443 /* don't allow negative window width */
444 if (lprEdit
->right
< lprEdit
->left
)
445 lprEdit
->right
= lprEdit
->left
;
447 TRACE("\ttext\t= (%ld,%ld-%ld,%ld)\n",
448 lprEdit
->left
, lprEdit
->top
, lprEdit
->right
, lprEdit
->bottom
);
450 TRACE("\tbutton\t= (%ld,%ld-%ld,%ld)\n",
451 lprButton
->left
, lprButton
->top
, lprButton
->right
, lprButton
->bottom
);
453 TRACE("\tlbox\t= (%ld,%ld-%ld,%ld)\n",
454 lprLB
->left
, lprLB
->top
, lprLB
->right
, lprLB
->bottom
);
457 /***********************************************************************
458 * CBGetDroppedControlRect
460 static void CBGetDroppedControlRect( LPHEADCOMBO lphc
, LPRECT lpRect
)
462 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
463 of the combo box and the lower right corner of the listbox */
465 GetWindowRect(lphc
->self
, lpRect
);
467 lpRect
->right
= lpRect
->left
+ lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
468 lpRect
->bottom
= lpRect
->top
+ lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
472 /***********************************************************************
473 * COMBO_WindowPosChanging
475 static LRESULT
COMBO_WindowPosChanging(
478 WINDOWPOS
* posChanging
)
481 * We need to override the WM_WINDOWPOSCHANGING method to handle all
482 * the non-simple comboboxes. The problem is that those controls are
483 * always the same height. We have to make sure they are not resized
486 if ( ( CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
487 ((posChanging
->flags
& SWP_NOSIZE
) == 0) )
491 newComboHeight
= CBGetTextAreaHeight(hwnd
,lphc
) +
492 2*COMBO_YBORDERSIZE();
495 * Resizing a combobox has another side effect, it resizes the dropped
496 * rectangle as well. However, it does it only if the new height for the
497 * combobox is different from the height it should have. In other words,
498 * if the application resizing the combobox only had the intention to resize
499 * the actual control, for example, to do the layout of a dialog that is
500 * resized, the height of the dropdown is not changed.
502 if (posChanging
->cy
!= newComboHeight
)
504 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%ld, oldtop=%ld\n",
505 posChanging
->cy
, newComboHeight
, lphc
->droppedRect
.bottom
,
506 lphc
->droppedRect
.top
);
507 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
+ posChanging
->cy
- newComboHeight
;
509 posChanging
->cy
= newComboHeight
;
516 /***********************************************************************
519 static LRESULT
COMBO_Create( HWND hwnd
, LPHEADCOMBO lphc
, HWND hwndParent
, LONG style
,
522 static const WCHAR clbName
[] = {'C','o','m','b','o','L','B','o','x',0};
523 static const WCHAR editName
[] = {'E','d','i','t',0};
525 if( !CB_GETTYPE(lphc
) ) lphc
->dwStyle
|= CBS_SIMPLE
;
526 if( CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
) lphc
->wState
|= CBF_EDIT
;
528 lphc
->owner
= hwndParent
;
531 * The item height and dropped width are not set when the control
534 lphc
->droppedWidth
= lphc
->editHeight
= 0;
537 * The first time we go through, we want to measure the ownerdraw item
539 lphc
->wState
|= CBF_MEASUREITEM
;
541 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
543 if( lphc
->owner
|| !(style
& WS_VISIBLE
) )
549 * Initialize the dropped rect to the size of the client area of the
550 * control and then, force all the areas of the combobox to be
553 GetClientRect( hwnd
, &lphc
->droppedRect
);
554 CBCalcPlacement(hwnd
, lphc
, &lphc
->textRect
, &lphc
->buttonRect
, &lphc
->droppedRect
);
557 * Adjust the position of the popup listbox if it's necessary
559 if ( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
561 lphc
->droppedRect
.top
= lphc
->textRect
.bottom
+ COMBO_YBORDERSIZE();
564 * If it's a dropdown, the listbox is offset
566 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
567 lphc
->droppedRect
.left
+= COMBO_EDITBUTTONSPACE();
569 if (lphc
->droppedRect
.bottom
< lphc
->droppedRect
.top
)
570 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
;
571 if (lphc
->droppedRect
.right
< lphc
->droppedRect
.left
)
572 lphc
->droppedRect
.right
= lphc
->droppedRect
.left
;
573 MapWindowPoints( hwnd
, 0, (LPPOINT
)&lphc
->droppedRect
, 2 );
576 /* create listbox popup */
578 lbeStyle
= (LBS_NOTIFY
| LBS_COMBOBOX
| WS_BORDER
| WS_CLIPSIBLINGS
| WS_CHILD
) |
579 (style
& (WS_VSCROLL
| CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
));
581 if( lphc
->dwStyle
& CBS_SORT
)
582 lbeStyle
|= LBS_SORT
;
583 if( lphc
->dwStyle
& CBS_HASSTRINGS
)
584 lbeStyle
|= LBS_HASSTRINGS
;
585 if( lphc
->dwStyle
& CBS_NOINTEGRALHEIGHT
)
586 lbeStyle
|= LBS_NOINTEGRALHEIGHT
;
587 if( lphc
->dwStyle
& CBS_DISABLENOSCROLL
)
588 lbeStyle
|= LBS_DISABLENOSCROLL
;
590 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
) /* child listbox */
592 lbeStyle
|= WS_VISIBLE
;
595 * In win 95 look n feel, the listbox in the simple combobox has
596 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
598 lbeStyle
&= ~WS_BORDER
;
599 lbeExStyle
|= WS_EX_CLIENTEDGE
;
603 lbeExStyle
|= (WS_EX_TOPMOST
| WS_EX_TOOLWINDOW
);
607 lphc
->hWndLBox
= CreateWindowExW(lbeExStyle
, clbName
, NULL
, lbeStyle
,
608 lphc
->droppedRect
.left
,
609 lphc
->droppedRect
.top
,
610 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
611 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
612 hwnd
, (HMENU
)ID_CB_LISTBOX
,
613 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), lphc
);
615 lphc
->hWndLBox
= CreateWindowExA(lbeExStyle
, "ComboLBox", NULL
, lbeStyle
,
616 lphc
->droppedRect
.left
,
617 lphc
->droppedRect
.top
,
618 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
619 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
620 hwnd
, (HMENU
)ID_CB_LISTBOX
,
621 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), lphc
);
626 lbeStyle
= WS_CHILD
| WS_VISIBLE
| ES_NOHIDESEL
| ES_LEFT
| ES_COMBO
;
628 if( lphc
->wState
& CBF_EDIT
)
630 if( lphc
->dwStyle
& CBS_OEMCONVERT
)
631 lbeStyle
|= ES_OEMCONVERT
;
632 if( lphc
->dwStyle
& CBS_AUTOHSCROLL
)
633 lbeStyle
|= ES_AUTOHSCROLL
;
634 if( lphc
->dwStyle
& CBS_LOWERCASE
)
635 lbeStyle
|= ES_LOWERCASE
;
636 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
637 lbeStyle
|= ES_UPPERCASE
;
639 if (!IsWindowEnabled(hwnd
)) lbeStyle
|= WS_DISABLED
;
642 lphc
->hWndEdit
= CreateWindowExW(0, editName
, NULL
, lbeStyle
,
643 lphc
->textRect
.left
, lphc
->textRect
.top
,
644 lphc
->textRect
.right
- lphc
->textRect
.left
,
645 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
646 hwnd
, (HMENU
)ID_CB_EDIT
,
647 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), NULL
);
649 lphc
->hWndEdit
= CreateWindowExA(0, "Edit", NULL
, lbeStyle
,
650 lphc
->textRect
.left
, lphc
->textRect
.top
,
651 lphc
->textRect
.right
- lphc
->textRect
.left
,
652 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
653 hwnd
, (HMENU
)ID_CB_EDIT
,
654 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), NULL
);
656 if( !lphc
->hWndEdit
)
662 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
664 /* Now do the trick with parent */
665 SetParent(lphc
->hWndLBox
, HWND_DESKTOP
);
667 * If the combo is a dropdown, we must resize the control
668 * to fit only the text area and button. To do this,
669 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
670 * will take care of setting the height for us.
672 CBForceDummyResize(lphc
);
675 TRACE("init done\n");
678 ERR("edit control failure.\n");
679 } else ERR("listbox failure.\n");
680 } else ERR("no owner for visible combo.\n");
682 /* CreateWindow() will send WM_NCDESTROY to cleanup */
687 /***********************************************************************
690 * Paint combo button (normal, pressed, and disabled states).
692 static void CBPaintButton( LPHEADCOMBO lphc
, HDC hdc
, RECT rectButton
)
694 UINT buttonState
= DFCS_SCROLLCOMBOBOX
;
696 if( lphc
->wState
& CBF_NOREDRAW
)
700 if (lphc
->wState
& CBF_BUTTONDOWN
)
701 buttonState
|= DFCS_PUSHED
;
703 if (CB_DISABLED(lphc
))
704 buttonState
|= DFCS_INACTIVE
;
706 DrawFrameControl(hdc
, &rectButton
, DFC_SCROLL
, buttonState
);
709 /***********************************************************************
712 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
714 static void CBPaintText(
722 if( lphc
->wState
& CBF_NOREDRAW
) return;
726 /* follow Windows combobox that sends a bunch of text
727 * inquiries to its listbox while processing WM_PAINT. */
729 if( (id
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0) ) != LB_ERR
)
731 size
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, id
, 0);
733 FIXME("LB_ERR probably not handled yet\n");
734 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (size
+ 1) * sizeof(WCHAR
))) )
736 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
737 size
=SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, (WPARAM
)id
, (LPARAM
)pText
);
738 pText
[size
] = '\0'; /* just in case */
742 if( !CB_OWNERDRAWN(lphc
) )
745 if( lphc
->wState
& CBF_EDIT
)
747 static const WCHAR empty_stringW
[] = { 0 };
748 if( CB_HASSTRINGS(lphc
) ) SetWindowTextW( lphc
->hWndEdit
, pText
? pText
: empty_stringW
);
749 if( lphc
->wState
& CBF_FOCUSED
)
750 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
752 else /* paint text field ourselves */
754 UINT itemState
= ODS_COMBOBOXEDIT
;
755 HFONT hPrevFont
= (lphc
->hFont
) ? SelectObject(hdc
, lphc
->hFont
) : 0;
758 * Give ourselves some space.
760 InflateRect( &rectEdit
, -1, -1 );
762 if( CB_OWNERDRAWN(lphc
) )
766 UINT ctlid
= (UINT
)GetWindowLongPtrW( lphc
->self
, GWLP_ID
);
768 /* setup state for DRAWITEM message. Owner will highlight */
769 if ( (lphc
->wState
& CBF_FOCUSED
) &&
770 !(lphc
->wState
& CBF_DROPPED
) )
771 itemState
|= ODS_SELECTED
| ODS_FOCUS
;
774 * Save the current clip region.
775 * To retrieve the clip region, we need to create one "dummy"
778 clipRegion
= CreateRectRgnIndirect(&rectEdit
);
780 if (GetClipRgn(hdc
, clipRegion
)!=1)
782 DeleteObject(clipRegion
);
786 if (!(IsWindowEnabled(lphc
->self
) & WS_DISABLED
)) itemState
|= ODS_DISABLED
;
788 dis
.CtlType
= ODT_COMBOBOX
;
790 dis
.hwndItem
= lphc
->self
;
791 dis
.itemAction
= ODA_DRAWENTIRE
;
793 dis
.itemState
= itemState
;
795 dis
.rcItem
= rectEdit
;
796 dis
.itemData
= SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
,
800 * Clip the DC and have the parent draw the item.
802 IntersectClipRect(hdc
,
803 rectEdit
.left
, rectEdit
.top
,
804 rectEdit
.right
, rectEdit
.bottom
);
806 SendMessageW(lphc
->owner
, WM_DRAWITEM
, ctlid
, (LPARAM
)&dis
);
809 * Reset the clipping region.
811 SelectClipRgn(hdc
, clipRegion
);
815 static const WCHAR empty_stringW
[] = { 0 };
817 if ( (lphc
->wState
& CBF_FOCUSED
) &&
818 !(lphc
->wState
& CBF_DROPPED
) ) {
821 FillRect( hdc
, &rectEdit
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
822 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
823 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
829 ETO_OPAQUE
| ETO_CLIPPED
,
831 pText
? pText
: empty_stringW
, size
, NULL
);
833 if(lphc
->wState
& CBF_FOCUSED
&& !(lphc
->wState
& CBF_DROPPED
) &&
834 !(lphc
->UIState
& UISF_HIDEFOCUS
))
835 DrawFocusRect( hdc
, &rectEdit
);
839 SelectObject(hdc
, hPrevFont
);
842 HeapFree( GetProcessHeap(), 0, pText
);
845 /***********************************************************************
848 static void CBPaintBorder(
850 const HEADCOMBO
*lphc
,
855 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
857 GetClientRect(hwnd
, &clientRect
);
861 CopyRect(&clientRect
, &lphc
->textRect
);
863 InflateRect(&clientRect
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
864 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
867 DrawEdge(hdc
, &clientRect
, EDGE_SUNKEN
, BF_RECT
);
870 /***********************************************************************
871 * COMBO_PrepareColors
873 * This method will sent the appropriate WM_CTLCOLOR message to
874 * prepare and setup the colors for the combo's DC.
876 * It also returns the brush to use for the background.
878 static HBRUSH
COMBO_PrepareColors(
885 * Get the background brush for this control.
887 if (CB_DISABLED(lphc
))
889 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORSTATIC
,
890 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
893 * We have to change the text color since WM_CTLCOLORSTATIC will
894 * set it to the "enabled" color. This is the same behavior as the
897 SetTextColor(hDC
, GetSysColor(COLOR_GRAYTEXT
));
901 if (lphc
->wState
& CBF_EDIT
)
903 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLOREDIT
,
904 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
908 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORLISTBOX
,
909 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
917 hBkgBrush
= GetSysColorBrush(COLOR_WINDOW
);
923 /***********************************************************************
926 static LRESULT
COMBO_Paint(LPHEADCOMBO lphc
, HDC hParamDC
)
931 hDC
= (hParamDC
) ? hParamDC
932 : BeginPaint( lphc
->self
, &ps
);
934 TRACE("hdc=%p\n", hDC
);
936 if( hDC
&& !(lphc
->wState
& CBF_NOREDRAW
) )
938 HBRUSH hPrevBrush
, hBkgBrush
;
941 * Retrieve the background brush and select it in the
944 hBkgBrush
= COMBO_PrepareColors(lphc
, hDC
);
946 hPrevBrush
= SelectObject( hDC
, hBkgBrush
);
947 if (!(lphc
->wState
& CBF_EDIT
))
948 FillRect(hDC
, &lphc
->textRect
, hBkgBrush
);
951 * In non 3.1 look, there is a sunken border on the combobox
953 CBPaintBorder(lphc
->self
, lphc
, hDC
);
955 if( !IsRectEmpty(&lphc
->buttonRect
) )
957 CBPaintButton(lphc
, hDC
, lphc
->buttonRect
);
960 /* paint the edit control padding area */
961 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
963 RECT rPadEdit
= lphc
->textRect
;
965 InflateRect(&rPadEdit
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
967 FrameRect( hDC
, &rPadEdit
, GetSysColorBrush(COLOR_WINDOW
) );
970 if( !(lphc
->wState
& CBF_EDIT
) )
971 CBPaintText( lphc
, hDC
, lphc
->textRect
);
974 SelectObject( hDC
, hPrevBrush
);
978 EndPaint(lphc
->self
, &ps
);
983 /***********************************************************************
986 * Select listbox entry according to the contents of the edit control.
988 static INT
CBUpdateLBox( LPHEADCOMBO lphc
, BOOL bSelect
)
994 length
= SendMessageW( lphc
->hWndEdit
, WM_GETTEXTLENGTH
, 0, 0 );
997 pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
999 TRACE("\t edit text length %i\n", length
);
1003 GetWindowTextW( lphc
->hWndEdit
, pText
, length
+ 1);
1004 idx
= SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
,
1005 (WPARAM
)(-1), (LPARAM
)pText
);
1006 HeapFree( GetProcessHeap(), 0, pText
);
1009 SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, (WPARAM
)(bSelect
? idx
: -1), 0);
1011 /* probably superfluous but Windows sends this too */
1012 SendMessageW(lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
1013 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
1018 /***********************************************************************
1021 * Copy a listbox entry to the edit control.
1023 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1026 LPWSTR pText
= NULL
;
1027 static const WCHAR empty_stringW
[] = { 0 };
1029 TRACE("\t %i\n", index
);
1031 if( index
>= 0 ) /* got an entry */
1033 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1034 if( length
!= LB_ERR
)
1036 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
))) )
1038 SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
,
1039 (WPARAM
)index
, (LPARAM
)pText
);
1044 if( CB_HASSTRINGS(lphc
) )
1046 lphc
->wState
|= (CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1047 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, pText
? (LPARAM
)pText
: (LPARAM
)empty_stringW
);
1048 lphc
->wState
&= ~(CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1051 if( lphc
->wState
& CBF_FOCUSED
)
1052 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1054 HeapFree( GetProcessHeap(), 0, pText
);
1057 /***********************************************************************
1060 * Show listbox popup.
1062 static void CBDropDown( LPHEADCOMBO lphc
)
1065 MONITORINFO mon_info
;
1070 TRACE("[%p]: drop down\n", lphc
->self
);
1072 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1076 lphc
->wState
|= CBF_DROPPED
;
1077 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1079 lphc
->droppedIndex
= CBUpdateLBox( lphc
, TRUE
);
1081 /* Update edit only if item is in the list */
1082 if( !(lphc
->wState
& CBF_CAPTURE
) && lphc
->droppedIndex
>= 0)
1083 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1087 lphc
->droppedIndex
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1089 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
,
1090 (WPARAM
)(lphc
->droppedIndex
== LB_ERR
? 0 : lphc
->droppedIndex
), 0 );
1091 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1094 /* now set popup position */
1095 GetWindowRect( lphc
->self
, &rect
);
1098 * If it's a dropdown, the listbox is offset
1100 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1101 rect
.left
+= COMBO_EDITBUTTONSPACE();
1103 /* if the dropped height is greater than the total height of the dropped
1104 items list, then force the drop down list height to be the total height
1105 of the items in the dropped list */
1107 /* And Remove any extra space (Best Fit) */
1108 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1109 /* if listbox length has been set directly by its handle */
1110 GetWindowRect(lphc
->hWndLBox
, &r
);
1111 if (nDroppedHeight
< r
.bottom
- r
.top
)
1112 nDroppedHeight
= r
.bottom
- r
.top
;
1113 nItems
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1120 nIHeight
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, 0, 0);
1122 nHeight
= nIHeight
*nItems
;
1124 if (nHeight
< nDroppedHeight
- COMBO_YBORDERSIZE())
1125 nDroppedHeight
= nHeight
+ COMBO_YBORDERSIZE();
1127 if (nDroppedHeight
< nHeight
)
1130 nDroppedHeight
= (nItems
+1)*nIHeight
;
1132 nDroppedHeight
= 6*nIHeight
;
1136 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1137 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
1138 mon_info
.cbSize
= sizeof(mon_info
);
1139 GetMonitorInfoW( monitor
, &mon_info
);
1141 if( (rect
.bottom
+ nDroppedHeight
) >= mon_info
.rcWork
.bottom
)
1142 rect
.bottom
= rect
.top
- nDroppedHeight
;
1144 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1145 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1147 SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
1150 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1151 RedrawWindow( lphc
->self
, NULL
, 0, RDW_INVALIDATE
|
1152 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1154 EnableWindow( lphc
->hWndLBox
, TRUE
);
1155 if (GetCapture() != lphc
->self
)
1156 SetCapture(lphc
->hWndLBox
);
1159 /***********************************************************************
1162 * Hide listbox popup.
1164 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1166 HWND hWnd
= lphc
->self
;
1168 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1169 lphc
->self
, ok
, (INT
)(lphc
->wState
& CBF_DROPPED
));
1171 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1173 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1176 if( lphc
->wState
& CBF_DROPPED
)
1180 lphc
->wState
&= ~CBF_DROPPED
;
1181 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1183 if(GetCapture() == lphc
->hWndLBox
)
1188 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1190 rect
= lphc
->buttonRect
;
1201 rect
= lphc
->textRect
;
1206 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1207 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1208 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1209 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1214 /***********************************************************************
1217 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1219 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL ok
, BOOL bRedrawButton
)
1221 if( lphc
->wState
& CBF_DROPPED
)
1223 CBRollUp( lphc
, ok
, bRedrawButton
);
1231 /***********************************************************************
1234 static void CBRepaintButton( LPHEADCOMBO lphc
)
1236 InvalidateRect(lphc
->self
, &lphc
->buttonRect
, TRUE
);
1237 UpdateWindow(lphc
->self
);
1240 /***********************************************************************
1243 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1245 if( !(lphc
->wState
& CBF_FOCUSED
) )
1247 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1248 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1250 /* This is wrong. Message sequences seem to indicate that this
1251 is set *after* the notify. */
1252 /* lphc->wState |= CBF_FOCUSED; */
1254 if( !(lphc
->wState
& CBF_EDIT
) )
1255 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1257 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1258 lphc
->wState
|= CBF_FOCUSED
;
1262 /***********************************************************************
1265 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1267 HWND hWnd
= lphc
->self
;
1269 if( lphc
->wState
& CBF_FOCUSED
)
1271 CBRollUp( lphc
, FALSE
, TRUE
);
1272 if( IsWindow( hWnd
) )
1274 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1275 SendMessageW(lphc
->hWndLBox
, LB_CARETOFF
, 0, 0);
1277 lphc
->wState
&= ~CBF_FOCUSED
;
1280 if( !(lphc
->wState
& CBF_EDIT
) )
1281 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1283 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1288 /***********************************************************************
1291 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1293 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1295 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1297 switch( HIWORD(wParam
) >> 8 )
1299 case (EN_SETFOCUS
>> 8):
1301 TRACE("[%p]: edit [%p] got focus\n", lphc
->self
, lphc
->hWndEdit
);
1303 COMBO_SetFocus( lphc
);
1306 case (EN_KILLFOCUS
>> 8):
1308 TRACE("[%p]: edit [%p] lost focus\n", lphc
->self
, lphc
->hWndEdit
);
1310 /* NOTE: it seems that Windows' edit control sends an
1311 * undocumented message WM_USER + 0x1B instead of this
1312 * notification (only when it happens to be a part of
1313 * the combo). ?? - AK.
1316 COMBO_KillFocus( lphc
);
1320 case (EN_CHANGE
>> 8):
1322 * In some circumstances (when the selection of the combobox
1323 * is changed for example) we don't want the EN_CHANGE notification
1324 * to be forwarded to the parent of the combobox. This code
1325 * checks a flag that is set in these occasions and ignores the
1328 if (lphc
->wState
& CBF_NOLBSELECT
)
1330 lphc
->wState
&= ~CBF_NOLBSELECT
;
1334 CBUpdateLBox( lphc
, lphc
->wState
& CBF_DROPPED
);
1337 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1338 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1341 case (EN_UPDATE
>> 8):
1342 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1343 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1346 case (EN_ERRSPACE
>> 8):
1347 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1350 else if( lphc
->hWndLBox
== hWnd
)
1352 switch( (short)HIWORD(wParam
) )
1355 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1359 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1365 TRACE("[%p]: lbox selection change [%x]\n", lphc
->self
, lphc
->wState
);
1367 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1369 if( HIWORD(wParam
) == LBN_SELCHANGE
)
1371 if( lphc
->wState
& CBF_EDIT
)
1373 INT index
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1374 lphc
->wState
|= CBF_NOLBSELECT
;
1375 CBUpdateEdit( lphc
, index
);
1376 /* select text in edit, as Windows does */
1377 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1380 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1383 /* do not roll up if selection is being tracked
1384 * by arrowkeys in the dropdown listbox */
1385 if( ((lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
)) )
1387 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1389 else lphc
->wState
&= ~CBF_NOROLLUP
;
1395 /* nothing to do here since ComboLBox always resets the focus to its
1396 * combo/edit counterpart */
1403 /***********************************************************************
1406 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1408 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
, LPARAM lParam
)
1410 HWND hWnd
= lphc
->self
;
1411 UINT id
= (UINT
)GetWindowLongPtrW( hWnd
, GWLP_ID
);
1413 TRACE("[%p]: ownerdraw op %04x\n", lphc
->self
, msg
);
1419 DELETEITEMSTRUCT
*lpIS
= (DELETEITEMSTRUCT
*)lParam
;
1420 lpIS
->CtlType
= ODT_COMBOBOX
;
1422 lpIS
->hwndItem
= hWnd
;
1427 DRAWITEMSTRUCT
*lpIS
= (DRAWITEMSTRUCT
*)lParam
;
1428 lpIS
->CtlType
= ODT_COMBOBOX
;
1430 lpIS
->hwndItem
= hWnd
;
1433 case WM_COMPAREITEM
:
1435 COMPAREITEMSTRUCT
*lpIS
= (COMPAREITEMSTRUCT
*)lParam
;
1436 lpIS
->CtlType
= ODT_COMBOBOX
;
1438 lpIS
->hwndItem
= hWnd
;
1441 case WM_MEASUREITEM
:
1443 MEASUREITEMSTRUCT
*lpIS
= (MEASUREITEMSTRUCT
*)lParam
;
1444 lpIS
->CtlType
= ODT_COMBOBOX
;
1449 return SendMessageW(lphc
->owner
, msg
, id
, lParam
);
1453 /***********************************************************************
1456 static LRESULT
COMBO_GetTextW( LPHEADCOMBO lphc
, INT count
, LPWSTR buf
)
1460 if( lphc
->wState
& CBF_EDIT
)
1461 return SendMessageW( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1463 /* get it from the listbox */
1465 if (!count
|| !buf
) return 0;
1466 if( lphc
->hWndLBox
)
1468 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1469 if (idx
== LB_ERR
) goto error
;
1470 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1471 if (length
== LB_ERR
) goto error
;
1473 /* 'length' is without the terminating character */
1474 if (length
>= count
)
1476 LPWSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
1477 if (!lpBuffer
) goto error
;
1478 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1480 /* truncate if buffer is too short */
1481 if (length
!= LB_ERR
)
1483 lstrcpynW( buf
, lpBuffer
, count
);
1486 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1488 else length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1490 if (length
== LB_ERR
) return 0;
1494 error
: /* error - truncate string, return zero */
1500 /***********************************************************************
1503 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1504 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1506 static LRESULT
COMBO_GetTextA( LPHEADCOMBO lphc
, INT count
, LPSTR buf
)
1510 if( lphc
->wState
& CBF_EDIT
)
1511 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1513 /* get it from the listbox */
1515 if (!count
|| !buf
) return 0;
1516 if( lphc
->hWndLBox
)
1518 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1519 if (idx
== LB_ERR
) goto error
;
1520 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1521 if (length
== LB_ERR
) goto error
;
1523 /* 'length' is without the terminating character */
1524 if (length
>= count
)
1526 LPSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) );
1527 if (!lpBuffer
) goto error
;
1528 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1530 /* truncate if buffer is too short */
1531 if (length
!= LB_ERR
)
1533 lstrcpynA( buf
, lpBuffer
, count
);
1536 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1538 else length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1540 if (length
== LB_ERR
) return 0;
1544 error
: /* error - truncate string, return zero */
1550 /***********************************************************************
1553 * This function sets window positions according to the updated
1554 * component placement struct.
1556 static void CBResetPos(
1558 const RECT
*rectEdit
,
1562 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1564 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1565 * sizing messages */
1567 if( lphc
->wState
& CBF_EDIT
)
1568 SetWindowPos( lphc
->hWndEdit
, 0,
1569 rectEdit
->left
, rectEdit
->top
,
1570 rectEdit
->right
- rectEdit
->left
,
1571 rectEdit
->bottom
- rectEdit
->top
,
1572 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1574 SetWindowPos( lphc
->hWndLBox
, 0,
1575 rectLB
->left
, rectLB
->top
,
1576 rectLB
->right
- rectLB
->left
,
1577 rectLB
->bottom
- rectLB
->top
,
1578 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1582 if( lphc
->wState
& CBF_DROPPED
)
1584 lphc
->wState
&= ~CBF_DROPPED
;
1585 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1588 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1589 RedrawWindow( lphc
->self
, NULL
, 0,
1590 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1595 /***********************************************************************
1598 static void COMBO_Size( LPHEADCOMBO lphc
, BOOL bRedraw
)
1600 CBCalcPlacement(lphc
->self
,
1604 &lphc
->droppedRect
);
1606 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, bRedraw
);
1610 /***********************************************************************
1613 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1618 lphc
->hFont
= hFont
;
1621 * Propagate to owned windows.
1623 if( lphc
->wState
& CBF_EDIT
)
1624 SendMessageW(lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1625 SendMessageW(lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1628 * Redo the layout of the control.
1630 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1632 CBCalcPlacement(lphc
->self
,
1636 &lphc
->droppedRect
);
1638 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1642 CBForceDummyResize(lphc
);
1647 /***********************************************************************
1648 * COMBO_SetItemHeight
1650 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1652 LRESULT lRet
= CB_ERR
;
1654 if( index
== -1 ) /* set text field height */
1656 if( height
< 32768 )
1658 lphc
->editHeight
= height
+ 2; /* Is the 2 for 2*EDIT_CONTROL_PADDING? */
1661 * Redo the layout of the control.
1663 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1665 CBCalcPlacement(lphc
->self
,
1669 &lphc
->droppedRect
);
1671 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1675 CBForceDummyResize(lphc
);
1681 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1682 lRet
= SendMessageW(lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1683 (WPARAM
)index
, (LPARAM
)height
);
1687 /***********************************************************************
1688 * COMBO_SelectString
1690 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPARAM pText
, BOOL unicode
)
1692 INT index
= unicode
? SendMessageW(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
) :
1693 SendMessageA(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
);
1696 if( lphc
->wState
& CBF_EDIT
)
1697 CBUpdateEdit( lphc
, index
);
1700 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1703 return (LRESULT
)index
;
1706 /***********************************************************************
1709 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1713 HWND hWnd
= lphc
->self
;
1715 pt
.x
= (short)LOWORD(lParam
);
1716 pt
.y
= (short)HIWORD(lParam
);
1717 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1719 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1720 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1722 lphc
->wState
|= CBF_BUTTONDOWN
;
1723 if( lphc
->wState
& CBF_DROPPED
)
1725 /* got a click to cancel selection */
1727 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1728 CBRollUp( lphc
, TRUE
, FALSE
);
1729 if( !IsWindow( hWnd
) ) return;
1731 if( lphc
->wState
& CBF_CAPTURE
)
1733 lphc
->wState
&= ~CBF_CAPTURE
;
1739 /* drop down the listbox and start tracking */
1741 lphc
->wState
|= CBF_CAPTURE
;
1745 if( bButton
) CBRepaintButton( lphc
);
1749 /***********************************************************************
1752 * Release capture and stop tracking if needed.
1754 static void COMBO_LButtonUp( LPHEADCOMBO lphc
)
1756 if( lphc
->wState
& CBF_CAPTURE
)
1758 lphc
->wState
&= ~CBF_CAPTURE
;
1759 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1761 INT index
= CBUpdateLBox( lphc
, TRUE
);
1762 /* Update edit only if item is in the list */
1765 lphc
->wState
|= CBF_NOLBSELECT
;
1766 CBUpdateEdit( lphc
, index
);
1767 lphc
->wState
&= ~CBF_NOLBSELECT
;
1771 SetCapture(lphc
->hWndLBox
);
1774 if( lphc
->wState
& CBF_BUTTONDOWN
)
1776 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1777 CBRepaintButton( lphc
);
1781 /***********************************************************************
1784 * Two things to do - track combo button and release capture when
1785 * pointer goes into the listbox.
1787 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1792 pt
.x
= (short)LOWORD(lParam
);
1793 pt
.y
= (short)HIWORD(lParam
);
1795 if( lphc
->wState
& CBF_BUTTONDOWN
)
1799 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1803 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1804 CBRepaintButton( lphc
);
1808 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1809 MapWindowPoints( lphc
->self
, lphc
->hWndLBox
, &pt
, 1 );
1810 if( PtInRect(&lbRect
, pt
) )
1812 lphc
->wState
&= ~CBF_CAPTURE
;
1814 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
, TRUE
);
1816 /* hand over pointer tracking */
1817 SendMessageW(lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1821 static LRESULT
COMBO_GetComboBoxInfo(const HEADCOMBO
*lphc
, COMBOBOXINFO
*pcbi
)
1823 if (!pcbi
|| (pcbi
->cbSize
< sizeof(COMBOBOXINFO
)))
1826 pcbi
->rcItem
= lphc
->textRect
;
1827 pcbi
->rcButton
= lphc
->buttonRect
;
1828 pcbi
->stateButton
= 0;
1829 if (lphc
->wState
& CBF_BUTTONDOWN
)
1830 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
1831 if (IsRectEmpty(&lphc
->buttonRect
))
1832 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
1833 pcbi
->hwndCombo
= lphc
->self
;
1834 pcbi
->hwndItem
= lphc
->hWndEdit
;
1835 pcbi
->hwndList
= lphc
->hWndLBox
;
1839 static char *strdupA(LPCSTR str
)
1844 if(!str
) return NULL
;
1847 ret
= HeapAlloc(GetProcessHeap(), 0, len
+ 1);
1849 memcpy(ret
, str
, len
+ 1);
1853 /***********************************************************************
1854 * ComboWndProc_common
1856 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxes.asp
1858 static LRESULT
ComboWndProc_common( HWND hwnd
, UINT message
,
1859 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1861 LPHEADCOMBO lphc
= (LPHEADCOMBO
)GetWindowLongPtrW( hwnd
, 0 );
1863 TRACE("[%p]: msg %s wp %08lx lp %08lx\n",
1864 hwnd
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1866 if( lphc
|| message
== WM_NCCREATE
)
1870 /* System messages */
1874 LONG style
= unicode
? ((LPCREATESTRUCTW
)lParam
)->style
:
1875 ((LPCREATESTRUCTA
)lParam
)->style
;
1876 return COMBO_NCCreate(hwnd
, style
);
1879 COMBO_NCDestroy(lphc
);
1880 break;/* -> DefWindowProc */
1888 hwndParent
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
1889 style
= ((LPCREATESTRUCTW
)lParam
)->style
;
1893 hwndParent
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
1894 style
= ((LPCREATESTRUCTA
)lParam
)->style
;
1896 return COMBO_Create(hwnd
, lphc
, hwndParent
, style
, unicode
);
1899 case WM_PRINTCLIENT
:
1902 /* wParam may contain a valid HDC! */
1903 return COMBO_Paint(lphc
, (HDC
)wParam
);
1906 /* do all painting in WM_PAINT like Windows does */
1911 LRESULT result
= DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1912 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1914 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1916 if ((vk
== VK_RETURN
|| vk
== VK_ESCAPE
) && (lphc
->wState
& CBF_DROPPED
))
1917 result
|= DLGC_WANTMESSAGE
;
1921 case WM_WINDOWPOSCHANGING
:
1922 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1923 case WM_WINDOWPOSCHANGED
:
1924 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1925 * In that case, the Combobox itself will not be resized, so we won't
1926 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1929 /* we should not force repainting on WM_WINDOWPOSCHANGED, it breaks
1930 * Z-order based painting.
1934 if( lphc
->hWndLBox
&&
1935 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
, message
== WM_SIZE
);
1938 COMBO_Font( lphc
, (HFONT
)wParam
, (BOOL
)lParam
);
1941 return (LRESULT
)lphc
->hFont
;
1943 if( lphc
->wState
& CBF_EDIT
)
1944 SetFocus( lphc
->hWndEdit
);
1946 COMBO_SetFocus( lphc
);
1951 HWND hwndFocus
= (HWND
)wParam
;
1953 HWND hwndFocus
= WIN_GetFullHandle( (HWND
)wParam
);
1956 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1957 COMBO_KillFocus( lphc
);
1962 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1964 return COMBO_Command( lphc
, wParam
, WIN_GetFullHandle( (HWND
)lParam
) );
1967 return unicode
? COMBO_GetTextW( lphc
, wParam
, (LPWSTR
)lParam
)
1968 : COMBO_GetTextA( lphc
, wParam
, (LPSTR
)lParam
);
1970 case WM_GETTEXTLENGTH
:
1972 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1974 int j
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1975 if (j
== -1) return 0;
1976 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0) :
1977 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1979 else if( lphc
->wState
& CBF_EDIT
)
1982 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1983 ret
= unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1984 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1985 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1992 if( lphc
->wState
& CBF_EDIT
)
1994 return unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1995 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
2001 case WM_COMPAREITEM
:
2002 case WM_MEASUREITEM
:
2003 return COMBO_ItemOp(lphc
, message
, lParam
);
2005 if( lphc
->wState
& CBF_EDIT
)
2006 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
2007 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
2009 /* Force the control to repaint when the enabled state changes. */
2010 InvalidateRect(lphc
->self
, NULL
, TRUE
);
2014 lphc
->wState
&= ~CBF_NOREDRAW
;
2016 lphc
->wState
|= CBF_NOREDRAW
;
2018 if( lphc
->wState
& CBF_EDIT
)
2019 SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
);
2020 SendMessageW(lphc
->hWndLBox
, message
, wParam
, lParam
);
2023 if( KEYDATA_ALT
& HIWORD(lParam
) )
2024 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
2025 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2034 if ((wParam
== VK_RETURN
|| wParam
== VK_ESCAPE
) &&
2035 (lphc
->wState
& CBF_DROPPED
))
2037 CBRollUp( lphc
, wParam
== VK_RETURN
, FALSE
);
2040 else if ((wParam
== VK_F4
) && !(lphc
->wState
& CBF_EUI
))
2042 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2046 if( lphc
->wState
& CBF_EDIT
)
2047 hwndTarget
= lphc
->hWndEdit
;
2049 hwndTarget
= lphc
->hWndLBox
;
2051 return unicode
? SendMessageW(hwndTarget
, message
, wParam
, lParam
) :
2052 SendMessageA(hwndTarget
, message
, wParam
, lParam
);
2054 case WM_LBUTTONDOWN
:
2055 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
);
2056 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
2059 COMBO_LButtonUp( lphc
);
2062 if( lphc
->wState
& CBF_CAPTURE
)
2063 COMBO_MouseMove( lphc
, wParam
, lParam
);
2067 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
2068 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2069 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2071 if (GET_WHEEL_DELTA_WPARAM(wParam
) > 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_UP
, 0);
2072 if (GET_WHEEL_DELTA_WPARAM(wParam
) < 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_DOWN
, 0);
2075 /* Combo messages */
2078 case CB_ADDSTRING16
:
2079 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2085 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2086 CharLowerW((LPWSTR
)lParam
);
2087 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2088 CharUpperW((LPWSTR
)lParam
);
2089 return SendMessageW(lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
2091 else /* unlike the unicode version, the ansi version does not overwrite
2092 the string if converting case */
2094 char *string
= NULL
;
2096 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2098 string
= strdupA((LPSTR
)lParam
);
2102 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2104 string
= strdupA((LPSTR
)lParam
);
2108 ret
= SendMessageA(lphc
->hWndLBox
, LB_ADDSTRING
, 0, string
? (LPARAM
)string
: lParam
);
2109 HeapFree(GetProcessHeap(), 0, string
);
2113 case CB_INSERTSTRING16
:
2114 wParam
= (INT
)(INT16
)wParam
;
2115 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2118 case CB_INSERTSTRING
:
2121 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2122 CharLowerW((LPWSTR
)lParam
);
2123 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2124 CharUpperW((LPWSTR
)lParam
);
2125 return SendMessageW(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2129 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2130 CharLowerA((LPSTR
)lParam
);
2131 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2132 CharUpperA((LPSTR
)lParam
);
2134 return SendMessageA(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2137 case CB_DELETESTRING16
:
2139 case CB_DELETESTRING
:
2140 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0) :
2141 SendMessageA(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
2143 case CB_SELECTSTRING16
:
2144 wParam
= (INT
)(INT16
)wParam
;
2145 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2148 case CB_SELECTSTRING
:
2149 return COMBO_SelectString(lphc
, (INT
)wParam
, lParam
, unicode
);
2151 case CB_FINDSTRING16
:
2152 wParam
= (INT
)(INT16
)wParam
;
2153 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2157 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
) :
2158 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
2160 case CB_FINDSTRINGEXACT16
:
2161 wParam
= (INT
)(INT16
)wParam
;
2162 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2165 case CB_FINDSTRINGEXACT
:
2166 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
) :
2167 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
);
2169 case CB_SETITEMHEIGHT16
:
2170 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
2173 case CB_SETITEMHEIGHT
:
2174 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
2176 case CB_GETITEMHEIGHT16
:
2177 wParam
= (INT
)(INT16
)wParam
;
2180 case CB_GETITEMHEIGHT
:
2181 if( (INT
)wParam
>= 0 ) /* listbox item */
2182 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
2183 return CBGetTextAreaHeight(hwnd
, lphc
);
2185 case CB_RESETCONTENT16
:
2187 case CB_RESETCONTENT
:
2188 SendMessageW(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0);
2189 if( (lphc
->wState
& CBF_EDIT
) && CB_HASSTRINGS(lphc
) )
2191 static const WCHAR empty_stringW
[] = { 0 };
2192 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, (LPARAM
)empty_stringW
);
2195 InvalidateRect(lphc
->self
, NULL
, TRUE
);
2197 case CB_INITSTORAGE
:
2198 return SendMessageW(lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
2199 case CB_GETHORIZONTALEXTENT
:
2200 return SendMessageW(lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
2201 case CB_SETHORIZONTALEXTENT
:
2202 return SendMessageW(lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
2203 case CB_GETTOPINDEX
:
2204 return SendMessageW(lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2206 return SendMessageW(lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2208 return SendMessageW(lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2209 case CB_GETDROPPEDWIDTH
:
2210 if( lphc
->droppedWidth
)
2211 return lphc
->droppedWidth
;
2212 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2213 case CB_SETDROPPEDWIDTH
:
2214 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2215 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2218 case CB_GETDROPPEDCONTROLRECT16
:
2219 lParam
= (LPARAM
)MapSL(lParam
);
2223 CBGetDroppedControlRect( lphc
, &r
);
2224 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2228 case CB_GETDROPPEDCONTROLRECT
:
2229 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2232 case CB_GETDROPPEDSTATE16
:
2234 case CB_GETDROPPEDSTATE
:
2235 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2238 return SendMessageA(lphc
->hWndLBox
, LB_DIR16
, wParam
, lParam
);
2241 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
) :
2242 SendMessageA(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
);
2245 case CB_SHOWDROPDOWN16
:
2247 case CB_SHOWDROPDOWN
:
2248 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2252 if( !(lphc
->wState
& CBF_DROPPED
) )
2256 if( lphc
->wState
& CBF_DROPPED
)
2257 CBRollUp( lphc
, FALSE
, TRUE
);
2264 return SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2266 case CB_GETCURSEL16
:
2269 return SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2271 case CB_SETCURSEL16
:
2272 wParam
= (INT
)(INT16
)wParam
;
2276 lParam
= SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2278 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, wParam
, 0);
2280 /* no LBN_SELCHANGE in this case, update manually */
2281 if( lphc
->wState
& CBF_EDIT
)
2282 CBUpdateEdit( lphc
, (INT
)wParam
);
2284 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2285 lphc
->wState
&= ~CBF_SELCHANGE
;
2288 case CB_GETLBTEXT16
:
2289 wParam
= (INT
)(INT16
)wParam
;
2290 lParam
= (LPARAM
)MapSL(lParam
);
2294 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
) :
2295 SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2297 case CB_GETLBTEXTLEN16
:
2298 wParam
= (INT
)(INT16
)wParam
;
2301 case CB_GETLBTEXTLEN
:
2302 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0) :
2303 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2305 case CB_GETITEMDATA16
:
2306 wParam
= (INT
)(INT16
)wParam
;
2309 case CB_GETITEMDATA
:
2310 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2312 case CB_SETITEMDATA16
:
2313 wParam
= (INT
)(INT16
)wParam
;
2316 case CB_SETITEMDATA
:
2317 return SendMessageW(lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2319 case CB_GETEDITSEL16
:
2320 wParam
= lParam
= 0; /* just in case */
2324 /* Edit checks passed parameters itself */
2325 if( lphc
->wState
& CBF_EDIT
)
2326 return SendMessageW(lphc
->hWndEdit
, EM_GETSEL
, wParam
, lParam
);
2329 case CB_SETEDITSEL16
:
2332 if( lphc
->wState
& CBF_EDIT
)
2333 return SendMessageW(lphc
->hWndEdit
, EM_SETSEL
,
2334 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2337 case CB_SETEXTENDEDUI16
:
2339 case CB_SETEXTENDEDUI
:
2340 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2343 lphc
->wState
|= CBF_EUI
;
2344 else lphc
->wState
&= ~CBF_EUI
;
2347 case CB_GETEXTENDEDUI16
:
2349 case CB_GETEXTENDEDUI
:
2350 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2351 case CB_GETCOMBOBOXINFO
:
2352 return COMBO_GetComboBoxInfo(lphc
, (COMBOBOXINFO
*)lParam
);
2354 if( lphc
->wState
& CBF_EDIT
)
2355 return SendMessageW(lphc
->hWndEdit
, EM_LIMITTEXT
, wParam
, lParam
);
2358 case WM_UPDATEUISTATE
:
2360 DefWindowProcW(lphc
->self
, message
, wParam
, lParam
);
2362 DefWindowProcA(lphc
->self
, message
, wParam
, lParam
);
2364 if (COMBO_update_uistate(lphc
))
2367 if( !(lphc
->wState
& CBF_EDIT
) )
2368 NtUserInvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2373 if (message
>= WM_USER
)
2374 WARN("unknown msg WM_USER+%04x wp=%04lx lp=%08lx\n",
2375 message
- WM_USER
, wParam
, lParam
);
2378 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2379 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2382 /***********************************************************************
2385 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2388 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2390 if (!IsWindow(hwnd
)) return 0;
2391 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
2394 /***********************************************************************
2397 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2399 if (!IsWindow(hwnd
)) return 0;
2400 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
2403 /*************************************************************************
2404 * GetComboBoxInfo (USER32.@)
2406 BOOL WINAPI
GetComboBoxInfo(HWND hwndCombo
, /* [in] handle to combo box */
2407 PCOMBOBOXINFO pcbi
/* [in/out] combo box information */)
2409 TRACE("(%p, %p)\n", hwndCombo
, pcbi
);
2411 return SendMessageW(hwndCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
);
2413 return NtUserGetComboBoxInfo(hwndCombo
, pcbi
);