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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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()
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
= 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(
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 lphc
->wState
|= (CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1045 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, pText
? (LPARAM
)pText
: (LPARAM
)empty_stringW
);
1046 lphc
->wState
&= ~(CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1048 if( lphc
->wState
& CBF_FOCUSED
)
1049 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1051 HeapFree( GetProcessHeap(), 0, pText
);
1054 /***********************************************************************
1057 * Show listbox popup.
1059 static void CBDropDown( LPHEADCOMBO lphc
)
1062 MONITORINFO mon_info
;
1067 TRACE("[%p]: drop down\n", lphc
->self
);
1069 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1073 lphc
->wState
|= CBF_DROPPED
;
1074 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1076 lphc
->droppedIndex
= CBUpdateLBox( lphc
, TRUE
);
1078 /* Update edit only if item is in the list */
1079 if( !(lphc
->wState
& CBF_CAPTURE
) && lphc
->droppedIndex
>= 0)
1080 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1084 lphc
->droppedIndex
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1086 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
,
1087 (WPARAM
)(lphc
->droppedIndex
== LB_ERR
? 0 : lphc
->droppedIndex
), 0 );
1088 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1091 /* now set popup position */
1092 GetWindowRect( lphc
->self
, &rect
);
1095 * If it's a dropdown, the listbox is offset
1097 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1098 rect
.left
+= COMBO_EDITBUTTONSPACE();
1100 /* if the dropped height is greater than the total height of the dropped
1101 items list, then force the drop down list height to be the total height
1102 of the items in the dropped list */
1104 /* And Remove any extra space (Best Fit) */
1105 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1106 /* if listbox length has been set directly by its handle */
1107 GetWindowRect(lphc
->hWndLBox
, &r
);
1108 if (nDroppedHeight
< r
.bottom
- r
.top
)
1109 nDroppedHeight
= r
.bottom
- r
.top
;
1110 nItems
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1117 nIHeight
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, 0, 0);
1119 nHeight
= nIHeight
*nItems
;
1121 if (nHeight
< nDroppedHeight
- COMBO_YBORDERSIZE())
1122 nDroppedHeight
= nHeight
+ COMBO_YBORDERSIZE();
1124 if (nDroppedHeight
< nIHeight
)
1127 nDroppedHeight
= (nItems
+1)*nIHeight
;
1129 nDroppedHeight
= 6*nIHeight
;
1133 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1134 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
1135 mon_info
.cbSize
= sizeof(mon_info
);
1136 GetMonitorInfoW( monitor
, &mon_info
);
1138 if( (rect
.bottom
+ nDroppedHeight
) >= GetSystemMetrics( SM_CYSCREEN
) )
1139 rect
.bottom
= rect
.top
- nDroppedHeight
;
1141 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1142 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1144 SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
1147 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1148 RedrawWindow( lphc
->self
, NULL
, 0, RDW_INVALIDATE
|
1149 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1151 EnableWindow( lphc
->hWndLBox
, TRUE
);
1152 if (GetCapture() != lphc
->self
)
1153 SetCapture(lphc
->hWndLBox
);
1156 /***********************************************************************
1159 * Hide listbox popup.
1161 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1163 HWND hWnd
= lphc
->self
;
1165 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1166 lphc
->self
, (INT
)ok
, (INT
)(lphc
->wState
& CBF_DROPPED
));
1168 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1170 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1173 if( lphc
->wState
& CBF_DROPPED
)
1177 lphc
->wState
&= ~CBF_DROPPED
;
1178 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1180 if(GetCapture() == lphc
->hWndLBox
)
1185 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1187 rect
= lphc
->buttonRect
;
1198 rect
= lphc
->textRect
;
1203 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1204 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1205 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1206 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1211 /***********************************************************************
1214 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1216 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL ok
, BOOL bRedrawButton
)
1218 if( lphc
->wState
& CBF_DROPPED
)
1220 CBRollUp( lphc
, ok
, bRedrawButton
);
1228 /***********************************************************************
1231 static void CBRepaintButton( LPHEADCOMBO lphc
)
1233 NtUserInvalidateRect(lphc
->self
, &lphc
->buttonRect
, TRUE
);
1234 UpdateWindow(lphc
->self
);
1237 /***********************************************************************
1240 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1242 if( !(lphc
->wState
& CBF_FOCUSED
) )
1244 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1245 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1247 /* This is wrong. Message sequences seem to indicate that this
1248 is set *after* the notify. */
1249 /* lphc->wState |= CBF_FOCUSED; */
1251 if( !(lphc
->wState
& CBF_EDIT
) )
1253 NtUserInvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1256 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1257 lphc
->wState
|= CBF_FOCUSED
;
1261 /***********************************************************************
1264 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1266 HWND hWnd
= lphc
->self
;
1268 if( lphc
->wState
& CBF_FOCUSED
)
1270 CBRollUp( lphc
, FALSE
, TRUE
);
1271 if( IsWindow( hWnd
) )
1273 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1274 SendMessageW(lphc
->hWndLBox
, LB_CARETOFF
, 0, 0);
1276 lphc
->wState
&= ~CBF_FOCUSED
;
1279 if( !(lphc
->wState
& CBF_EDIT
) )
1280 NtUserInvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1282 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1287 /***********************************************************************
1290 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1292 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1294 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1296 switch( HIWORD(wParam
) >> 8 )
1298 case (EN_SETFOCUS
>> 8):
1300 TRACE("[%p]: edit [%p] got focus\n", lphc
->self
, lphc
->hWndEdit
);
1302 COMBO_SetFocus( lphc
);
1305 case (EN_KILLFOCUS
>> 8):
1307 TRACE("[%p]: edit [%p] lost focus\n", lphc
->self
, lphc
->hWndEdit
);
1309 /* NOTE: it seems that Windows' edit control sends an
1310 * undocumented message WM_USER + 0x1B instead of this
1311 * notification (only when it happens to be a part of
1312 * the combo). ?? - AK.
1315 COMBO_KillFocus( lphc
);
1319 case (EN_CHANGE
>> 8):
1321 * In some circumstances (when the selection of the combobox
1322 * is changed for example) we don't wans the EN_CHANGE notification
1323 * to be forwarded to the parent of the combobox. This code
1324 * checks a flag that is set in these occasions and ignores the
1327 if (lphc
->wState
& CBF_NOLBSELECT
)
1329 lphc
->wState
&= ~CBF_NOLBSELECT
;
1333 CBUpdateLBox( lphc
, lphc
->wState
& CBF_DROPPED
);
1336 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1337 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1340 case (EN_UPDATE
>> 8):
1341 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1342 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1345 case (EN_ERRSPACE
>> 8):
1346 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1349 else if( lphc
->hWndLBox
== hWnd
)
1351 switch( (short)HIWORD(wParam
) )
1354 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1358 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1364 TRACE("[%p]: lbox selection change [%x]\n", lphc
->self
, lphc
->wState
);
1366 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1368 if( HIWORD(wParam
) == LBN_SELCHANGE
)
1370 if( lphc
->wState
& CBF_EDIT
)
1372 INT index
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1373 lphc
->wState
|= CBF_NOLBSELECT
;
1374 CBUpdateEdit( lphc
, index
);
1375 /* select text in edit, as Windows does */
1376 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1379 NtUserInvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1382 /* do not roll up if selection is being tracked
1383 * by arrowkeys in the dropdown listbox */
1384 if( ((lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
)) )
1386 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1388 else lphc
->wState
&= ~CBF_NOROLLUP
;
1394 /* nothing to do here since ComboLBox always resets the focus to its
1395 * combo/edit counterpart */
1402 /***********************************************************************
1405 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1407 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
, LPARAM lParam
)
1409 HWND hWnd
= lphc
->self
;
1410 UINT id
= (UINT
)GetWindowLongPtrW( hWnd
, GWLP_ID
);
1412 TRACE("[%p]: ownerdraw op %04x\n", lphc
->self
, msg
);
1418 DELETEITEMSTRUCT
*lpIS
= (DELETEITEMSTRUCT
*)lParam
;
1419 lpIS
->CtlType
= ODT_COMBOBOX
;
1421 lpIS
->hwndItem
= hWnd
;
1426 DRAWITEMSTRUCT
*lpIS
= (DRAWITEMSTRUCT
*)lParam
;
1427 lpIS
->CtlType
= ODT_COMBOBOX
;
1429 lpIS
->hwndItem
= hWnd
;
1432 case WM_COMPAREITEM
:
1434 COMPAREITEMSTRUCT
*lpIS
= (COMPAREITEMSTRUCT
*)lParam
;
1435 lpIS
->CtlType
= ODT_COMBOBOX
;
1437 lpIS
->hwndItem
= hWnd
;
1440 case WM_MEASUREITEM
:
1442 MEASUREITEMSTRUCT
*lpIS
= (MEASUREITEMSTRUCT
*)lParam
;
1443 lpIS
->CtlType
= ODT_COMBOBOX
;
1448 return SendMessageW(lphc
->owner
, msg
, id
, lParam
);
1452 /***********************************************************************
1455 static LRESULT
COMBO_GetTextW( LPHEADCOMBO lphc
, INT count
, LPWSTR buf
)
1459 if( lphc
->wState
& CBF_EDIT
)
1460 return SendMessageW( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1462 /* get it from the listbox */
1464 if (!count
|| !buf
) return 0;
1465 if( lphc
->hWndLBox
)
1467 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1468 if (idx
== LB_ERR
) goto error
;
1469 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1470 if (length
== LB_ERR
) goto error
;
1472 /* 'length' is without the terminating character */
1473 if (length
>= count
)
1475 LPWSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
1476 if (!lpBuffer
) goto error
;
1477 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1479 /* truncate if buffer is too short */
1480 if (length
!= LB_ERR
)
1482 lstrcpynW( buf
, lpBuffer
, count
);
1485 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1487 else length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1489 if (length
== LB_ERR
) return 0;
1493 error
: /* error - truncate string, return zero */
1499 /***********************************************************************
1502 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1503 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1505 static LRESULT
COMBO_GetTextA( LPHEADCOMBO lphc
, INT count
, LPSTR buf
)
1509 if( lphc
->wState
& CBF_EDIT
)
1510 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1512 /* get it from the listbox */
1514 if (!count
|| !buf
) return 0;
1515 if( lphc
->hWndLBox
)
1517 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1518 if (idx
== LB_ERR
) goto error
;
1519 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1520 if (length
== LB_ERR
) goto error
;
1522 /* 'length' is without the terminating character */
1523 if (length
>= count
)
1525 LPSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) );
1526 if (!lpBuffer
) goto error
;
1527 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1529 /* truncate if buffer is too short */
1530 if (length
!= LB_ERR
)
1532 lstrcpynA( buf
, lpBuffer
, count
);
1535 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1537 else length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1539 if (length
== LB_ERR
) return 0;
1543 error
: /* error - truncate string, return zero */
1549 /***********************************************************************
1552 * This function sets window positions according to the updated
1553 * component placement struct.
1555 static void CBResetPos(
1561 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1563 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1564 * sizing messages */
1566 if( lphc
->wState
& CBF_EDIT
)
1567 SetWindowPos( lphc
->hWndEdit
, 0,
1568 rectEdit
->left
, rectEdit
->top
,
1569 rectEdit
->right
- rectEdit
->left
,
1570 rectEdit
->bottom
- rectEdit
->top
,
1571 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1573 SetWindowPos( lphc
->hWndLBox
, 0,
1574 rectLB
->left
, rectLB
->top
,
1575 rectLB
->right
- rectLB
->left
,
1576 rectLB
->bottom
- rectLB
->top
,
1577 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1581 if( lphc
->wState
& CBF_DROPPED
)
1583 lphc
->wState
&= ~CBF_DROPPED
;
1584 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1587 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1588 RedrawWindow( lphc
->self
, NULL
, 0,
1589 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1594 /***********************************************************************
1597 static void COMBO_Size( LPHEADCOMBO lphc
, BOOL bRedraw
)
1599 CBCalcPlacement(lphc
->self
,
1603 &lphc
->droppedRect
);
1605 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, bRedraw
);
1609 /***********************************************************************
1612 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1617 lphc
->hFont
= hFont
;
1620 * Propagate to owned windows.
1622 if( lphc
->wState
& CBF_EDIT
)
1623 SendMessageW(lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1624 SendMessageW(lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1627 * Redo the layout of the control.
1629 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1631 CBCalcPlacement(lphc
->self
,
1635 &lphc
->droppedRect
);
1637 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1641 CBForceDummyResize(lphc
);
1646 /***********************************************************************
1647 * COMBO_SetItemHeight
1649 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1651 LRESULT lRet
= CB_ERR
;
1653 if( index
== -1 ) /* set text field height */
1655 if( height
< 32768 )
1657 lphc
->editHeight
= height
+ 2; /* Is the 2 for 2*EDIT_CONTROL_PADDING? */
1660 * Redo the layout of the control.
1662 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1664 CBCalcPlacement(lphc
->self
,
1668 &lphc
->droppedRect
);
1670 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1674 CBForceDummyResize(lphc
);
1680 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1681 lRet
= SendMessageW(lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1682 (WPARAM
)index
, (LPARAM
)height
);
1686 /***********************************************************************
1687 * COMBO_SelectString
1689 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPARAM pText
, BOOL unicode
)
1691 INT index
= unicode
? SendMessageW(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
) :
1692 SendMessageA(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
);
1695 if( lphc
->wState
& CBF_EDIT
)
1696 CBUpdateEdit( lphc
, index
);
1699 NtUserInvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1702 return (LRESULT
)index
;
1705 /***********************************************************************
1708 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1712 HWND hWnd
= lphc
->self
;
1714 pt
.x
= LOWORD(lParam
);
1715 pt
.y
= HIWORD(lParam
);
1716 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1718 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1719 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1721 lphc
->wState
|= CBF_BUTTONDOWN
;
1722 if( lphc
->wState
& CBF_DROPPED
)
1724 /* got a click to cancel selection */
1726 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1727 CBRollUp( lphc
, TRUE
, FALSE
);
1728 if( !IsWindow( hWnd
) ) return;
1730 if( lphc
->wState
& CBF_CAPTURE
)
1732 lphc
->wState
&= ~CBF_CAPTURE
;
1738 /* drop down the listbox and start tracking */
1740 lphc
->wState
|= CBF_CAPTURE
;
1744 if( bButton
) CBRepaintButton( lphc
);
1748 /***********************************************************************
1751 * Release capture and stop tracking if needed.
1753 static void COMBO_LButtonUp( LPHEADCOMBO lphc
)
1755 if( lphc
->wState
& CBF_CAPTURE
)
1757 lphc
->wState
&= ~CBF_CAPTURE
;
1758 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1760 INT index
= CBUpdateLBox( lphc
, TRUE
);
1761 /* Update edit only if item is in the list */
1764 lphc
->wState
|= CBF_NOLBSELECT
;
1765 CBUpdateEdit( lphc
, index
);
1766 lphc
->wState
&= ~CBF_NOLBSELECT
;
1770 SetCapture(lphc
->hWndLBox
);
1773 if( lphc
->wState
& CBF_BUTTONDOWN
)
1775 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1776 CBRepaintButton( lphc
);
1780 /***********************************************************************
1783 * Two things to do - track combo button and release capture when
1784 * pointer goes into the listbox.
1786 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1791 pt
.x
= LOWORD(lParam
);
1792 pt
.y
= HIWORD(lParam
);
1794 if( lphc
->wState
& CBF_BUTTONDOWN
)
1798 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1802 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1803 CBRepaintButton( lphc
);
1807 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1808 MapWindowPoints( lphc
->self
, lphc
->hWndLBox
, &pt
, 1 );
1809 if( PtInRect(&lbRect
, pt
) )
1811 lphc
->wState
&= ~CBF_CAPTURE
;
1813 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
, TRUE
);
1815 /* hand over pointer tracking */
1816 SendMessageW(lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1820 static LRESULT
COMBO_GetComboBoxInfo(LPHEADCOMBO lphc
, COMBOBOXINFO
*pcbi
)
1822 if (!pcbi
|| (pcbi
->cbSize
< sizeof(COMBOBOXINFO
)))
1825 pcbi
->rcItem
= lphc
->textRect
;
1826 pcbi
->rcButton
= lphc
->buttonRect
;
1827 pcbi
->stateButton
= 0;
1828 if (lphc
->wState
& CBF_BUTTONDOWN
)
1829 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
1830 if (IsRectEmpty(&lphc
->buttonRect
))
1831 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
1832 pcbi
->hwndCombo
= lphc
->self
;
1833 pcbi
->hwndItem
= lphc
->hWndEdit
;
1834 pcbi
->hwndList
= lphc
->hWndLBox
;
1838 static char *strdupA(LPCSTR str
)
1843 if(!str
) return NULL
;
1846 ret
= HeapAlloc(GetProcessHeap(), 0, len
+ 1);
1847 memcpy(ret
, str
, len
+ 1);
1851 /***********************************************************************
1852 * ComboWndProc_common
1854 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1856 static LRESULT
ComboWndProc_common( HWND hwnd
, UINT message
,
1857 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1859 LPHEADCOMBO lphc
= (LPHEADCOMBO
)GetWindowLongPtrW( hwnd
, 0 );
1861 TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1862 hwnd
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1864 if( lphc
|| message
== WM_NCCREATE
)
1868 /* System messages */
1872 LONG style
= unicode
? ((LPCREATESTRUCTW
)lParam
)->style
:
1873 ((LPCREATESTRUCTA
)lParam
)->style
;
1874 return COMBO_NCCreate(hwnd
, style
);
1877 COMBO_NCDestroy(lphc
);
1878 break;/* -> DefWindowProc */
1886 hwndParent
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
1887 style
= ((LPCREATESTRUCTW
)lParam
)->style
;
1891 hwndParent
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
1892 style
= ((LPCREATESTRUCTA
)lParam
)->style
;
1894 return COMBO_Create(hwnd
, lphc
, hwndParent
, style
, unicode
);
1897 case WM_PRINTCLIENT
:
1900 /* wParam may contain a valid HDC! */
1901 return COMBO_Paint(lphc
, (HDC
)wParam
);
1904 /* do all painting in WM_PAINT like Windows does */
1909 LRESULT result
= DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1910 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1912 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1914 if ((vk
== VK_RETURN
|| vk
== VK_ESCAPE
) && (lphc
->wState
& CBF_DROPPED
))
1915 result
|= DLGC_WANTMESSAGE
;
1919 case WM_WINDOWPOSCHANGING
:
1920 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1921 case WM_WINDOWPOSCHANGED
:
1922 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1923 * In that case, the Combobox itself will not be resized, so we won't
1924 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1927 /* we should not force repainting on WM_WINDOWPOSCHANGED, it breaks
1928 * Z-order based painting.
1932 if( lphc
->hWndLBox
&&
1933 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
, message
== WM_SIZE
);
1936 COMBO_Font( lphc
, (HFONT
)wParam
, (BOOL
)lParam
);
1939 return (LRESULT
)lphc
->hFont
;
1941 if( lphc
->wState
& CBF_EDIT
)
1942 SetFocus( lphc
->hWndEdit
);
1944 COMBO_SetFocus( lphc
);
1949 HWND hwndFocus
= (HWND
)wParam
;
1951 HWND hwndFocus
= WIN_GetFullHandle( (HWND
)wParam
);
1954 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1955 COMBO_KillFocus( lphc
);
1960 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1962 return COMBO_Command( lphc
, wParam
, WIN_GetFullHandle( (HWND
)lParam
) );
1965 return unicode
? COMBO_GetTextW( lphc
, wParam
, (LPWSTR
)lParam
)
1966 : COMBO_GetTextA( lphc
, wParam
, (LPSTR
)lParam
);
1968 case WM_GETTEXTLENGTH
:
1970 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1972 int j
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1973 if (j
== -1) return 0;
1974 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0) :
1975 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1977 else if( lphc
->wState
& CBF_EDIT
)
1980 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1981 ret
= unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1982 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1983 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1990 if( lphc
->wState
& CBF_EDIT
)
1992 return unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1993 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1999 case WM_COMPAREITEM
:
2000 case WM_MEASUREITEM
:
2001 return COMBO_ItemOp(lphc
, message
, lParam
);
2003 if( lphc
->wState
& CBF_EDIT
)
2004 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
2005 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
2007 /* Force the control to repaint when the enabled state changes. */
2008 NtUserInvalidateRect(lphc
->self
, NULL
, TRUE
);
2012 lphc
->wState
&= ~CBF_NOREDRAW
;
2014 lphc
->wState
|= CBF_NOREDRAW
;
2016 if( lphc
->wState
& CBF_EDIT
)
2017 SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
);
2018 SendMessageW(lphc
->hWndLBox
, message
, wParam
, lParam
);
2021 if( KEYDATA_ALT
& HIWORD(lParam
) )
2022 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
2023 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2032 if ((wParam
== VK_RETURN
|| wParam
== VK_ESCAPE
) &&
2033 (lphc
->wState
& CBF_DROPPED
))
2035 CBRollUp( lphc
, wParam
== VK_RETURN
, FALSE
);
2038 else if ((wParam
== VK_F4
) && !(lphc
->wState
& CBF_EUI
))
2040 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2044 if( lphc
->wState
& CBF_EDIT
)
2045 hwndTarget
= lphc
->hWndEdit
;
2047 hwndTarget
= lphc
->hWndLBox
;
2049 return unicode
? SendMessageW(hwndTarget
, message
, wParam
, lParam
) :
2050 SendMessageA(hwndTarget
, message
, wParam
, lParam
);
2052 case WM_LBUTTONDOWN
:
2053 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
);
2054 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
2057 COMBO_LButtonUp( lphc
);
2060 if( lphc
->wState
& CBF_CAPTURE
)
2061 COMBO_MouseMove( lphc
, wParam
, lParam
);
2065 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
2066 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2067 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2069 if (GET_WHEEL_DELTA_WPARAM(wParam
) > 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_UP
, 0);
2070 if (GET_WHEEL_DELTA_WPARAM(wParam
) < 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_DOWN
, 0);
2073 /* Combo messages */
2076 case CB_ADDSTRING16
:
2077 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2083 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2084 CharLowerW((LPWSTR
)lParam
);
2085 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2086 CharUpperW((LPWSTR
)lParam
);
2087 return SendMessageW(lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
2089 else /* unlike the unicode version, the ansi version does not overwrite
2090 the string if converting case */
2092 char *string
= NULL
;
2094 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2096 string
= strdupA((LPSTR
)lParam
);
2100 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2102 string
= strdupA((LPSTR
)lParam
);
2106 ret
= SendMessageA(lphc
->hWndLBox
, LB_ADDSTRING
, 0, string
? (LPARAM
)string
: lParam
);
2107 HeapFree(GetProcessHeap(), 0, string
);
2111 case CB_INSERTSTRING16
:
2112 wParam
= (INT
)(INT16
)wParam
;
2113 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2116 case CB_INSERTSTRING
:
2119 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2120 CharLowerW((LPWSTR
)lParam
);
2121 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2122 CharUpperW((LPWSTR
)lParam
);
2123 return SendMessageW(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2127 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2128 CharLowerA((LPSTR
)lParam
);
2129 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2130 CharUpperA((LPSTR
)lParam
);
2131 return SendMessageA(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2134 case CB_DELETESTRING16
:
2136 case CB_DELETESTRING
:
2137 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0) :
2138 SendMessageA(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
2140 case CB_SELECTSTRING16
:
2141 wParam
= (INT
)(INT16
)wParam
;
2142 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2145 case CB_SELECTSTRING
:
2146 return COMBO_SelectString(lphc
, (INT
)wParam
, lParam
, unicode
);
2148 case CB_FINDSTRING16
:
2149 wParam
= (INT
)(INT16
)wParam
;
2150 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2154 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
) :
2155 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
2157 case CB_FINDSTRINGEXACT16
:
2158 wParam
= (INT
)(INT16
)wParam
;
2159 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2162 case CB_FINDSTRINGEXACT
:
2163 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
) :
2164 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
);
2166 case CB_SETITEMHEIGHT16
:
2167 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
2170 case CB_SETITEMHEIGHT
:
2171 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
2173 case CB_GETITEMHEIGHT16
:
2174 wParam
= (INT
)(INT16
)wParam
;
2177 case CB_GETITEMHEIGHT
:
2178 if( (INT
)wParam
>= 0 ) /* listbox item */
2179 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
2180 return CBGetTextAreaHeight(hwnd
, lphc
);
2182 case CB_RESETCONTENT16
:
2184 case CB_RESETCONTENT
:
2185 SendMessageW(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0);
2186 if( (lphc
->wState
& CBF_EDIT
) && CB_HASSTRINGS(lphc
) )
2188 static const WCHAR empty_stringW
[] = { 0 };
2189 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, (LPARAM
)empty_stringW
);
2192 NtUserInvalidateRect(lphc
->self
, NULL
, TRUE
);
2194 case CB_INITSTORAGE
:
2195 return SendMessageW(lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
2196 case CB_GETHORIZONTALEXTENT
:
2197 return SendMessageW(lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
2198 case CB_SETHORIZONTALEXTENT
:
2199 return SendMessageW(lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
2200 case CB_GETTOPINDEX
:
2201 return SendMessageW(lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2203 return SendMessageW(lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2205 return SendMessageW(lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2206 case CB_GETDROPPEDWIDTH
:
2207 if( lphc
->droppedWidth
)
2208 return lphc
->droppedWidth
;
2209 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2210 case CB_SETDROPPEDWIDTH
:
2211 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2212 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2215 case CB_GETDROPPEDCONTROLRECT16
:
2216 lParam
= (LPARAM
)MapSL(lParam
);
2220 CBGetDroppedControlRect( lphc
, &r
);
2221 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2225 case CB_GETDROPPEDCONTROLRECT
:
2226 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2229 case CB_GETDROPPEDSTATE16
:
2231 case CB_GETDROPPEDSTATE
:
2232 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2235 return SendMessageA(lphc
->hWndLBox
, LB_DIR16
, wParam
, lParam
);
2238 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
) :
2239 SendMessageA(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
);
2242 case CB_SHOWDROPDOWN16
:
2244 case CB_SHOWDROPDOWN
:
2245 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2249 if( !(lphc
->wState
& CBF_DROPPED
) )
2253 if( lphc
->wState
& CBF_DROPPED
)
2254 CBRollUp( lphc
, FALSE
, TRUE
);
2261 return SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2263 case CB_GETCURSEL16
:
2266 return SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2268 case CB_SETCURSEL16
:
2269 wParam
= (INT
)(INT16
)wParam
;
2273 lParam
= SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2275 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, wParam
, 0);
2277 /* no LBN_SELCHANGE in this case, update manually */
2278 if( lphc
->wState
& CBF_EDIT
)
2279 CBUpdateEdit( lphc
, (INT
)wParam
);
2281 NtUserInvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2282 lphc
->wState
&= ~CBF_SELCHANGE
;
2285 case CB_GETLBTEXT16
:
2286 wParam
= (INT
)(INT16
)wParam
;
2287 lParam
= (LPARAM
)MapSL(lParam
);
2291 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
) :
2292 SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2294 case CB_GETLBTEXTLEN16
:
2295 wParam
= (INT
)(INT16
)wParam
;
2298 case CB_GETLBTEXTLEN
:
2299 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0) :
2300 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2302 case CB_GETITEMDATA16
:
2303 wParam
= (INT
)(INT16
)wParam
;
2306 case CB_GETITEMDATA
:
2307 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2309 case CB_SETITEMDATA16
:
2310 wParam
= (INT
)(INT16
)wParam
;
2313 case CB_SETITEMDATA
:
2314 return SendMessageW(lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2316 case CB_GETEDITSEL16
:
2317 wParam
= lParam
= 0; /* just in case */
2321 /* Edit checks passed parameters itself */
2322 if( lphc
->wState
& CBF_EDIT
)
2323 return SendMessageW(lphc
->hWndEdit
, EM_GETSEL
, wParam
, lParam
);
2326 case CB_SETEDITSEL16
:
2329 if( lphc
->wState
& CBF_EDIT
)
2330 return SendMessageW(lphc
->hWndEdit
, EM_SETSEL
,
2331 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2334 case CB_SETEXTENDEDUI16
:
2336 case CB_SETEXTENDEDUI
:
2337 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2340 lphc
->wState
|= CBF_EUI
;
2341 else lphc
->wState
&= ~CBF_EUI
;
2344 case CB_GETEXTENDEDUI16
:
2346 case CB_GETEXTENDEDUI
:
2347 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2348 case CB_GETCOMBOBOXINFO
:
2349 return COMBO_GetComboBoxInfo(lphc
, (COMBOBOXINFO
*)lParam
);
2351 if( lphc
->wState
& CBF_EDIT
)
2352 return SendMessageW(lphc
->hWndEdit
, EM_LIMITTEXT
, wParam
, lParam
);
2355 case WM_UPDATEUISTATE
:
2357 DefWindowProcW(lphc
->self
, message
, wParam
, lParam
);
2359 DefWindowProcA(lphc
->self
, message
, wParam
, lParam
);
2361 if (COMBO_update_uistate(lphc
))
2364 if( !(lphc
->wState
& CBF_EDIT
) )
2365 NtUserInvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2370 if (message
>= WM_USER
)
2371 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2372 message
- WM_USER
, wParam
, lParam
);
2375 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2376 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2379 /***********************************************************************
2382 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2385 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2387 if (!IsWindow(hwnd
)) return 0;
2388 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
2391 /***********************************************************************
2394 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2396 if (!IsWindow(hwnd
)) return 0;
2397 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
2400 /*************************************************************************
2401 * GetComboBoxInfo (USER32.@)
2403 BOOL WINAPI
GetComboBoxInfo(HWND hwndCombo
, /* [in] handle to combo box */
2404 PCOMBOBOXINFO pcbi
/* [in/out] combo box information */)
2406 TRACE("(%p, %p)\n", hwndCombo
, pcbi
);
2408 return SendMessageW(hwndCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
);
2410 return NtUserGetComboBoxInfo(hwndCombo
, pcbi
);