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 /*********************************************************************
78 * combo class descriptor
80 static const WCHAR comboboxW
[] = {'C','o','m','b','o','B','o','x',0};
81 const struct builtin_class_descr COMBO_builtin_class
=
84 CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
, /* style */
85 ComboWndProcA
, /* procA */
86 ComboWndProcW
, /* procW */
87 sizeof(HEADCOMBO
*), /* extra */
88 IDC_ARROW
, /* cursor */
93 /***********************************************************************
96 * Load combo button bitmap.
98 static BOOL
COMBO_Init(void)
102 if( hComboBmp
) return TRUE
;
103 if( (hDC
= CreateCompatibleDC(0)) )
106 if( (hComboBmp
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO
))) )
112 GetObjectW( hComboBmp
, sizeof(bm
), &bm
);
113 CBitHeight
= bm
.bmHeight
;
114 CBitWidth
= bm
.bmWidth
;
116 TRACE("combo bitmap [%i,%i]\n", CBitWidth
, CBitHeight
);
118 hPrevB
= SelectObject( hDC
, hComboBmp
);
119 SetRect( &r
, 0, 0, CBitWidth
, CBitHeight
);
120 InvertRect( hDC
, &r
);
121 SelectObject( hDC
, hPrevB
);
131 /* Retrieve the UI state for the control */
132 static BOOL
COMBO_update_uistate(LPHEADCOMBO lphc
)
136 prev_flags
= lphc
->UIState
;
137 lphc
->UIState
= DefWindowProcW(lphc
->self
, WM_QUERYUISTATE
, 0, 0);
138 return prev_flags
!= lphc
->UIState
;
141 /***********************************************************************
144 static LRESULT
COMBO_NCCreate(HWND hwnd
, LONG style
)
148 if (COMBO_Init() && (lphc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HEADCOMBO
))) )
151 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)lphc
);
153 COMBO_update_uistate(lphc
);
155 /* some braindead apps do try to use scrollbar/border flags */
157 lphc
->dwStyle
= style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
);
158 SetWindowLongPtrW( hwnd
, GWL_STYLE
, style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
) );
161 * We also have to remove the client edge style to make sure
162 * we don't end-up with a non client area.
164 SetWindowLongPtrW( hwnd
, GWL_EXSTYLE
,
165 GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
167 if( !(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) )
168 lphc
->dwStyle
|= CBS_HASSTRINGS
;
169 if( !(GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) )
170 lphc
->wState
|= CBF_NOTIFY
;
172 TRACE("[%p], style = %08x\n", lphc
, lphc
->dwStyle
);
178 /***********************************************************************
181 static LRESULT
COMBO_NCDestroy( LPHEADCOMBO lphc
)
186 TRACE("[%p]: freeing storage\n", lphc
->self
);
188 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) && lphc
->hWndLBox
)
189 DestroyWindow( lphc
->hWndLBox
);
191 SetWindowLongPtrW( lphc
->self
, 0, 0 );
192 HeapFree( GetProcessHeap(), 0, lphc
);
197 /***********************************************************************
198 * CBGetTextAreaHeight
200 * This method will calculate the height of the text area of the
202 * The height of the text area is set in two ways.
203 * It can be set explicitly through a combobox message or through a
204 * WM_MEASUREITEM callback.
205 * If this is not the case, the height is set to font height + 4px
206 * This height was determined through experimentation.
207 * CBCalcPlacement will add 2*COMBO_YBORDERSIZE pixels for the border
209 static INT
CBGetTextAreaHeight(
215 if( lphc
->editHeight
) /* explicitly set height */
217 iTextItemHeight
= lphc
->editHeight
;
222 HDC hDC
= GetDC(hwnd
);
227 hPrevFont
= SelectObject( hDC
, lphc
->hFont
);
229 GetTextMetricsW(hDC
, &tm
);
231 baseUnitY
= tm
.tmHeight
;
234 SelectObject( hDC
, hPrevFont
);
236 ReleaseDC(hwnd
, hDC
);
238 iTextItemHeight
= baseUnitY
+ 4;
242 * Check the ownerdraw case if we haven't asked the parent the size
245 if ( CB_OWNERDRAWN(lphc
) &&
246 (lphc
->wState
& CBF_MEASUREITEM
) )
248 MEASUREITEMSTRUCT measureItem
;
250 INT originalItemHeight
= iTextItemHeight
;
251 UINT id
= (UINT
)GetWindowLongPtrW( lphc
->self
, GWLP_ID
);
254 * We use the client rect for the width of the item.
256 GetClientRect(hwnd
, &clientRect
);
258 lphc
->wState
&= ~CBF_MEASUREITEM
;
261 * Send a first one to measure the size of the text area
263 measureItem
.CtlType
= ODT_COMBOBOX
;
264 measureItem
.CtlID
= id
;
265 measureItem
.itemID
= -1;
266 measureItem
.itemWidth
= clientRect
.right
;
267 measureItem
.itemHeight
= iTextItemHeight
- 6; /* ownerdrawn cb is taller */
268 measureItem
.itemData
= 0;
269 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
270 iTextItemHeight
= 6 + measureItem
.itemHeight
;
273 * Send a second one in the case of a fixed ownerdraw list to calculate the
274 * size of the list items. (we basically do this on behalf of the listbox)
276 if (lphc
->dwStyle
& CBS_OWNERDRAWFIXED
)
278 measureItem
.CtlType
= ODT_COMBOBOX
;
279 measureItem
.CtlID
= id
;
280 measureItem
.itemID
= 0;
281 measureItem
.itemWidth
= clientRect
.right
;
282 measureItem
.itemHeight
= originalItemHeight
;
283 measureItem
.itemData
= 0;
284 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
285 lphc
->fixedOwnerDrawHeight
= measureItem
.itemHeight
;
289 * Keep the size for the next time
291 lphc
->editHeight
= iTextItemHeight
;
294 return iTextItemHeight
;
297 /***********************************************************************
300 * The dummy resize is used for listboxes that have a popup to trigger
301 * a re-arranging of the contents of the combobox and the recalculation
302 * of the size of the "real" control window.
304 static void CBForceDummyResize(
310 newComboHeight
= CBGetTextAreaHeight(lphc
->self
,lphc
) + 2*COMBO_YBORDERSIZE();
312 GetWindowRect(lphc
->self
, &windowRect
);
315 * We have to be careful, resizing a combobox also has the meaning that the
316 * dropped rect will be resized. In this case, we want to trigger a resize
317 * to recalculate layout but we don't want to change the dropped rectangle
318 * So, we pass the height of text area of control as the height.
319 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
322 SetWindowPos( lphc
->self
,
325 windowRect
.right
- windowRect
.left
,
327 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
330 /***********************************************************************
333 * Set up component coordinates given valid lphc->RectCombo.
335 static void CBCalcPlacement(
343 * Again, start with the client rectangle.
345 GetClientRect(hwnd
, lprEdit
);
350 InflateRect(lprEdit
, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
353 * Chop off the bottom part to fit with the height of the text area.
355 lprEdit
->bottom
= lprEdit
->top
+ CBGetTextAreaHeight(hwnd
, lphc
);
358 * The button starts the same vertical position as the text area.
360 CopyRect(lprButton
, lprEdit
);
363 * If the combobox is "simple" there is no button.
365 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
366 lprButton
->left
= lprButton
->right
= lprButton
->bottom
= 0;
370 * Let's assume the combobox button is the same width as the
372 * size the button horizontally and cut-off the text area.
374 lprButton
->left
= lprButton
->right
- GetSystemMetrics(SM_CXVSCROLL
);
375 lprEdit
->right
= lprButton
->left
;
379 * In the case of a dropdown, there is an additional spacing between the
380 * text area and the button.
382 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
384 lprEdit
->right
-= COMBO_EDITBUTTONSPACE();
388 * If we have an edit control, we space it away from the borders slightly.
390 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
392 InflateRect(lprEdit
, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
396 * Adjust the size of the listbox popup.
398 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
401 * Use the client rectangle to initialize the listbox rectangle
403 GetClientRect(hwnd
, lprLB
);
406 * Then, chop-off the top part.
408 lprLB
->top
= lprEdit
->bottom
+ COMBO_YBORDERSIZE();
413 * Make sure the dropped width is as large as the combobox itself.
415 if (lphc
->droppedWidth
< (lprButton
->right
+ COMBO_XBORDERSIZE()))
417 lprLB
->right
= lprLB
->left
+ (lprButton
->right
+ COMBO_XBORDERSIZE());
420 * In the case of a dropdown, the popup listbox is offset to the right.
421 * so, we want to make sure it's flush with the right side of the
424 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
425 lprLB
->right
-= COMBO_EDITBUTTONSPACE();
428 lprLB
->right
= lprLB
->left
+ lphc
->droppedWidth
;
431 /* don't allow negative window width */
432 if (lprEdit
->right
< lprEdit
->left
)
433 lprEdit
->right
= lprEdit
->left
;
435 TRACE("\ttext\t= (%s)\n", wine_dbgstr_rect(lprEdit
));
437 TRACE("\tbutton\t= (%s)\n", wine_dbgstr_rect(lprButton
));
439 TRACE("\tlbox\t= (%s)\n", wine_dbgstr_rect(lprLB
));
442 /***********************************************************************
443 * CBGetDroppedControlRect
445 static void CBGetDroppedControlRect( LPHEADCOMBO lphc
, LPRECT lpRect
)
447 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
448 of the combo box and the lower right corner of the listbox */
450 GetWindowRect(lphc
->self
, lpRect
);
452 lpRect
->right
= lpRect
->left
+ lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
453 lpRect
->bottom
= lpRect
->top
+ lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
457 /***********************************************************************
458 * COMBO_WindowPosChanging
460 static LRESULT
COMBO_WindowPosChanging(
463 WINDOWPOS
* posChanging
)
466 * We need to override the WM_WINDOWPOSCHANGING method to handle all
467 * the non-simple comboboxes. The problem is that those controls are
468 * always the same height. We have to make sure they are not resized
471 if ( ( CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
472 ((posChanging
->flags
& SWP_NOSIZE
) == 0) )
476 newComboHeight
= CBGetTextAreaHeight(hwnd
,lphc
) +
477 2*COMBO_YBORDERSIZE();
480 * Resizing a combobox has another side effect, it resizes the dropped
481 * rectangle as well. However, it does it only if the new height for the
482 * combobox is more than the height it should have. In other words,
483 * if the application resizing the combobox only had the intention to resize
484 * the actual control, for example, to do the layout of a dialog that is
485 * resized, the height of the dropdown is not changed.
487 if (posChanging
->cy
> newComboHeight
)
489 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%d, oldtop=%d\n",
490 posChanging
->cy
, newComboHeight
, lphc
->droppedRect
.bottom
,
491 lphc
->droppedRect
.top
);
492 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
+ posChanging
->cy
- newComboHeight
;
495 posChanging
->cy
= newComboHeight
;
501 /***********************************************************************
504 static LRESULT
COMBO_Create( HWND hwnd
, LPHEADCOMBO lphc
, HWND hwndParent
, LONG style
,
507 static const WCHAR clbName
[] = {'C','o','m','b','o','L','B','o','x',0};
508 static const WCHAR editName
[] = {'E','d','i','t',0};
510 if( !CB_GETTYPE(lphc
) ) lphc
->dwStyle
|= CBS_SIMPLE
;
511 if( CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
) lphc
->wState
|= CBF_EDIT
;
513 lphc
->owner
= hwndParent
;
516 * The item height and dropped width are not set when the control
519 lphc
->droppedWidth
= lphc
->editHeight
= 0;
522 * The first time we go through, we want to measure the ownerdraw item
524 lphc
->wState
|= CBF_MEASUREITEM
;
526 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
528 if( lphc
->owner
|| !(style
& WS_VISIBLE
) )
534 * Initialize the dropped rect to the size of the client area of the
535 * control and then, force all the areas of the combobox to be
538 GetClientRect( hwnd
, &lphc
->droppedRect
);
539 CBCalcPlacement(hwnd
, lphc
, &lphc
->textRect
, &lphc
->buttonRect
, &lphc
->droppedRect
);
542 * Adjust the position of the popup listbox if it's necessary
544 if ( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
546 lphc
->droppedRect
.top
= lphc
->textRect
.bottom
+ COMBO_YBORDERSIZE();
549 * If it's a dropdown, the listbox is offset
551 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
552 lphc
->droppedRect
.left
+= COMBO_EDITBUTTONSPACE();
554 if (lphc
->droppedRect
.bottom
< lphc
->droppedRect
.top
)
555 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
;
556 if (lphc
->droppedRect
.right
< lphc
->droppedRect
.left
)
557 lphc
->droppedRect
.right
= lphc
->droppedRect
.left
;
558 MapWindowPoints( hwnd
, 0, (LPPOINT
)&lphc
->droppedRect
, 2 );
561 /* create listbox popup */
563 lbeStyle
= (LBS_NOTIFY
| LBS_COMBOBOX
| WS_BORDER
| WS_CLIPSIBLINGS
| WS_CHILD
) |
564 (style
& (WS_VSCROLL
| CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
));
566 if( lphc
->dwStyle
& CBS_SORT
)
567 lbeStyle
|= LBS_SORT
;
568 if( lphc
->dwStyle
& CBS_HASSTRINGS
)
569 lbeStyle
|= LBS_HASSTRINGS
;
570 if( lphc
->dwStyle
& CBS_NOINTEGRALHEIGHT
)
571 lbeStyle
|= LBS_NOINTEGRALHEIGHT
;
572 if( lphc
->dwStyle
& CBS_DISABLENOSCROLL
)
573 lbeStyle
|= LBS_DISABLENOSCROLL
;
575 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
) /* child listbox */
577 lbeStyle
|= WS_VISIBLE
;
580 * In win 95 look n feel, the listbox in the simple combobox has
581 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
583 lbeStyle
&= ~WS_BORDER
;
584 lbeExStyle
|= WS_EX_CLIENTEDGE
;
588 lbeExStyle
|= (WS_EX_TOPMOST
| WS_EX_TOOLWINDOW
);
592 lphc
->hWndLBox
= CreateWindowExW(lbeExStyle
, clbName
, NULL
, lbeStyle
,
593 lphc
->droppedRect
.left
,
594 lphc
->droppedRect
.top
,
595 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
596 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
597 hwnd
, (HMENU
)ID_CB_LISTBOX
,
598 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), lphc
);
600 lphc
->hWndLBox
= CreateWindowExA(lbeExStyle
, "ComboLBox", NULL
, lbeStyle
,
601 lphc
->droppedRect
.left
,
602 lphc
->droppedRect
.top
,
603 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
604 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
605 hwnd
, (HMENU
)ID_CB_LISTBOX
,
606 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), lphc
);
611 lbeStyle
= WS_CHILD
| WS_VISIBLE
| ES_NOHIDESEL
| ES_LEFT
| ES_COMBO
;
613 if( lphc
->wState
& CBF_EDIT
)
615 if( lphc
->dwStyle
& CBS_OEMCONVERT
)
616 lbeStyle
|= ES_OEMCONVERT
;
617 if( lphc
->dwStyle
& CBS_AUTOHSCROLL
)
618 lbeStyle
|= ES_AUTOHSCROLL
;
619 if( lphc
->dwStyle
& CBS_LOWERCASE
)
620 lbeStyle
|= ES_LOWERCASE
;
621 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
622 lbeStyle
|= ES_UPPERCASE
;
624 if (!IsWindowEnabled(hwnd
)) lbeStyle
|= WS_DISABLED
;
627 lphc
->hWndEdit
= CreateWindowExW(0, editName
, NULL
, lbeStyle
,
628 lphc
->textRect
.left
, lphc
->textRect
.top
,
629 lphc
->textRect
.right
- lphc
->textRect
.left
,
630 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
631 hwnd
, (HMENU
)ID_CB_EDIT
,
632 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), NULL
);
634 lphc
->hWndEdit
= CreateWindowExA(0, "Edit", NULL
, lbeStyle
,
635 lphc
->textRect
.left
, lphc
->textRect
.top
,
636 lphc
->textRect
.right
- lphc
->textRect
.left
,
637 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
638 hwnd
, (HMENU
)ID_CB_EDIT
,
639 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), NULL
);
641 if( !lphc
->hWndEdit
)
647 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
649 /* Now do the trick with parent */
650 SetParent(lphc
->hWndLBox
, HWND_DESKTOP
);
652 * If the combo is a dropdown, we must resize the control
653 * to fit only the text area and button. To do this,
654 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
655 * will take care of setting the height for us.
657 CBForceDummyResize(lphc
);
660 TRACE("init done\n");
663 ERR("edit control failure.\n");
664 } else ERR("listbox failure.\n");
665 } else ERR("no owner for visible combo.\n");
667 /* CreateWindow() will send WM_NCDESTROY to cleanup */
672 /***********************************************************************
675 * Paint combo button (normal, pressed, and disabled states).
677 static void CBPaintButton( LPHEADCOMBO lphc
, HDC hdc
, RECT rectButton
)
679 UINT buttonState
= DFCS_SCROLLCOMBOBOX
;
681 if( lphc
->wState
& CBF_NOREDRAW
)
685 if (lphc
->wState
& CBF_BUTTONDOWN
)
686 buttonState
|= DFCS_PUSHED
;
688 if (CB_DISABLED(lphc
))
689 buttonState
|= DFCS_INACTIVE
;
691 DrawFrameControl(hdc
, &rectButton
, DFC_SCROLL
, buttonState
);
694 /***********************************************************************
697 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
699 static void CBPaintText(
707 if( lphc
->wState
& CBF_NOREDRAW
) return;
711 /* follow Windows combobox that sends a bunch of text
712 * inquiries to its listbox while processing WM_PAINT. */
714 if( (id
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0) ) != LB_ERR
)
716 size
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, id
, 0);
718 FIXME("LB_ERR probably not handled yet\n");
719 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (size
+ 1) * sizeof(WCHAR
))) )
721 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
722 size
=SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, (WPARAM
)id
, (LPARAM
)pText
);
723 pText
[size
] = '\0'; /* just in case */
727 if( !CB_OWNERDRAWN(lphc
) )
730 if( lphc
->wState
& CBF_EDIT
)
732 static const WCHAR empty_stringW
[] = { 0 };
733 if( CB_HASSTRINGS(lphc
) ) SetWindowTextW( lphc
->hWndEdit
, pText
? pText
: empty_stringW
);
734 if( lphc
->wState
& CBF_FOCUSED
)
735 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
737 else /* paint text field ourselves */
739 UINT itemState
= ODS_COMBOBOXEDIT
;
740 HFONT hPrevFont
= (lphc
->hFont
) ? SelectObject(hdc
, lphc
->hFont
) : 0;
743 * Give ourselves some space.
745 InflateRect( &rectEdit
, -1, -1 );
747 if( CB_OWNERDRAWN(lphc
) )
751 UINT ctlid
= (UINT
)GetWindowLongPtrW( lphc
->self
, GWLP_ID
);
753 /* setup state for DRAWITEM message. Owner will highlight */
754 if ( (lphc
->wState
& CBF_FOCUSED
) &&
755 !(lphc
->wState
& CBF_DROPPED
) )
756 itemState
|= ODS_SELECTED
| ODS_FOCUS
;
759 * Save the current clip region.
760 * To retrieve the clip region, we need to create one "dummy"
763 clipRegion
= CreateRectRgnIndirect(&rectEdit
);
765 if (GetClipRgn(hdc
, clipRegion
)!=1)
767 DeleteObject(clipRegion
);
771 if (!IsWindowEnabled(lphc
->self
)) itemState
|= ODS_DISABLED
;
773 dis
.CtlType
= ODT_COMBOBOX
;
775 dis
.hwndItem
= lphc
->self
;
776 dis
.itemAction
= ODA_DRAWENTIRE
;
778 dis
.itemState
= itemState
;
780 dis
.rcItem
= rectEdit
;
781 dis
.itemData
= SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
,
785 * Clip the DC and have the parent draw the item.
787 IntersectClipRect(hdc
,
788 rectEdit
.left
, rectEdit
.top
,
789 rectEdit
.right
, rectEdit
.bottom
);
791 SendMessageW(lphc
->owner
, WM_DRAWITEM
, ctlid
, (LPARAM
)&dis
);
794 * Reset the clipping region.
796 SelectClipRgn(hdc
, clipRegion
);
800 static const WCHAR empty_stringW
[] = { 0 };
802 if ( (lphc
->wState
& CBF_FOCUSED
) &&
803 !(lphc
->wState
& CBF_DROPPED
) ) {
806 FillRect( hdc
, &rectEdit
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
807 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
808 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
814 ETO_OPAQUE
| ETO_CLIPPED
,
816 pText
? pText
: empty_stringW
, size
, NULL
);
818 if(lphc
->wState
& CBF_FOCUSED
&& !(lphc
->wState
& CBF_DROPPED
) &&
819 !(lphc
->UIState
& UISF_HIDEFOCUS
))
820 DrawFocusRect( hdc
, &rectEdit
);
824 SelectObject(hdc
, hPrevFont
);
827 HeapFree( GetProcessHeap(), 0, pText
);
830 /***********************************************************************
833 static void CBPaintBorder(
835 const HEADCOMBO
*lphc
,
840 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
842 GetClientRect(hwnd
, &clientRect
);
846 CopyRect(&clientRect
, &lphc
->textRect
);
848 InflateRect(&clientRect
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
849 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
852 DrawEdge(hdc
, &clientRect
, EDGE_SUNKEN
, BF_RECT
);
855 /***********************************************************************
856 * COMBO_PrepareColors
858 * This method will sent the appropriate WM_CTLCOLOR message to
859 * prepare and setup the colors for the combo's DC.
861 * It also returns the brush to use for the background.
863 static HBRUSH
COMBO_PrepareColors(
870 * Get the background brush for this control.
872 if (CB_DISABLED(lphc
))
874 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORSTATIC
,
875 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
878 * We have to change the text color since WM_CTLCOLORSTATIC will
879 * set it to the "enabled" color. This is the same behavior as the
882 SetTextColor(hDC
, GetSysColor(COLOR_GRAYTEXT
));
886 /* FIXME: In which cases WM_CTLCOLORLISTBOX should be sent? */
887 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLOREDIT
,
888 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
895 hBkgBrush
= GetSysColorBrush(COLOR_WINDOW
);
901 /***********************************************************************
904 static LRESULT
COMBO_Paint(LPHEADCOMBO lphc
, HDC hParamDC
)
909 hDC
= (hParamDC
) ? hParamDC
910 : BeginPaint( lphc
->self
, &ps
);
912 TRACE("hdc=%p\n", hDC
);
914 if( hDC
&& !(lphc
->wState
& CBF_NOREDRAW
) )
916 HBRUSH hPrevBrush
, hBkgBrush
;
919 * Retrieve the background brush and select it in the
922 hBkgBrush
= COMBO_PrepareColors(lphc
, hDC
);
924 hPrevBrush
= SelectObject( hDC
, hBkgBrush
);
925 if (!(lphc
->wState
& CBF_EDIT
))
926 FillRect(hDC
, &lphc
->textRect
, hBkgBrush
);
929 * In non 3.1 look, there is a sunken border on the combobox
931 CBPaintBorder(lphc
->self
, lphc
, hDC
);
933 if( !IsRectEmpty(&lphc
->buttonRect
) )
935 CBPaintButton(lphc
, hDC
, lphc
->buttonRect
);
938 /* paint the edit control padding area */
939 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
941 RECT rPadEdit
= lphc
->textRect
;
943 InflateRect(&rPadEdit
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
945 FrameRect( hDC
, &rPadEdit
, GetSysColorBrush(COLOR_WINDOW
) );
948 if( !(lphc
->wState
& CBF_EDIT
) )
949 CBPaintText( lphc
, hDC
, lphc
->textRect
);
952 SelectObject( hDC
, hPrevBrush
);
956 EndPaint(lphc
->self
, &ps
);
961 /***********************************************************************
964 * Select listbox entry according to the contents of the edit control.
966 static INT
CBUpdateLBox( LPHEADCOMBO lphc
, BOOL bSelect
)
972 length
= SendMessageW( lphc
->hWndEdit
, WM_GETTEXTLENGTH
, 0, 0 );
975 pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
977 TRACE("\t edit text length %i\n", length
);
981 GetWindowTextW( lphc
->hWndEdit
, pText
, length
+ 1);
982 idx
= SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
,
983 (WPARAM
)(-1), (LPARAM
)pText
);
984 HeapFree( GetProcessHeap(), 0, pText
);
987 SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, (WPARAM
)(bSelect
? idx
: -1), 0);
989 /* probably superfluous but Windows sends this too */
990 SendMessageW(lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
991 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
996 /***********************************************************************
999 * Copy a listbox entry to the edit control.
1001 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1004 LPWSTR pText
= NULL
;
1005 static const WCHAR empty_stringW
[] = { 0 };
1007 TRACE("\t %i\n", index
);
1009 if( index
>= 0 ) /* got an entry */
1011 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1012 if( length
!= LB_ERR
)
1014 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
))) )
1016 SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
,
1017 (WPARAM
)index
, (LPARAM
)pText
);
1022 if( CB_HASSTRINGS(lphc
) )
1024 lphc
->wState
|= (CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1025 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, pText
? (LPARAM
)pText
: (LPARAM
)empty_stringW
);
1026 lphc
->wState
&= ~(CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1029 if( lphc
->wState
& CBF_FOCUSED
)
1030 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1032 HeapFree( GetProcessHeap(), 0, pText
);
1035 /***********************************************************************
1038 * Show listbox popup.
1040 static void CBDropDown( LPHEADCOMBO lphc
)
1043 MONITORINFO mon_info
;
1048 TRACE("[%p]: drop down\n", lphc
->self
);
1050 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1054 lphc
->wState
|= CBF_DROPPED
;
1055 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1057 lphc
->droppedIndex
= CBUpdateLBox( lphc
, TRUE
);
1059 /* Update edit only if item is in the list */
1060 if( !(lphc
->wState
& CBF_CAPTURE
) && lphc
->droppedIndex
>= 0)
1061 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1065 lphc
->droppedIndex
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1067 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
,
1068 (WPARAM
)(lphc
->droppedIndex
== LB_ERR
? 0 : lphc
->droppedIndex
), 0 );
1069 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1072 /* now set popup position */
1073 GetWindowRect( lphc
->self
, &rect
);
1076 * If it's a dropdown, the listbox is offset
1078 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1079 rect
.left
+= COMBO_EDITBUTTONSPACE();
1081 /* if the dropped height is greater than the total height of the dropped
1082 items list, then force the drop down list height to be the total height
1083 of the items in the dropped list */
1085 /* And Remove any extra space (Best Fit) */
1086 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1087 /* if listbox length has been set directly by its handle */
1088 GetWindowRect(lphc
->hWndLBox
, &r
);
1089 if (nDroppedHeight
< r
.bottom
- r
.top
)
1090 nDroppedHeight
= r
.bottom
- r
.top
;
1091 nItems
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1098 nIHeight
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, 0, 0);
1100 nHeight
= nIHeight
*nItems
;
1102 if (nHeight
< nDroppedHeight
- COMBO_YBORDERSIZE())
1103 nDroppedHeight
= nHeight
+ COMBO_YBORDERSIZE();
1105 if (nDroppedHeight
< nHeight
)
1108 nDroppedHeight
= (nItems
+1)*nIHeight
;
1109 else if (nDroppedHeight
< 6*nIHeight
)
1110 nDroppedHeight
= 6*nIHeight
;
1114 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1115 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
1116 mon_info
.cbSize
= sizeof(mon_info
);
1117 GetMonitorInfoW( monitor
, &mon_info
);
1119 if( (rect
.bottom
+ nDroppedHeight
) >= mon_info
.rcWork
.bottom
)
1120 rect
.bottom
= rect
.top
- nDroppedHeight
;
1122 SetWindowPos( lphc
->hWndLBox
, HWND_TOPMOST
, rect
.left
, rect
.bottom
,
1123 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1125 SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
1128 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1129 RedrawWindow( lphc
->self
, NULL
, 0, RDW_INVALIDATE
|
1130 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1132 EnableWindow( lphc
->hWndLBox
, TRUE
);
1133 if (GetCapture() != lphc
->self
)
1134 SetCapture(lphc
->hWndLBox
);
1137 /***********************************************************************
1140 * Hide listbox popup.
1142 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1144 HWND hWnd
= lphc
->self
;
1146 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1147 lphc
->self
, ok
, (INT
)(lphc
->wState
& CBF_DROPPED
));
1149 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1151 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1154 if( lphc
->wState
& CBF_DROPPED
)
1158 lphc
->wState
&= ~CBF_DROPPED
;
1159 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1161 if(GetCapture() == lphc
->hWndLBox
)
1166 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1168 rect
= lphc
->buttonRect
;
1179 rect
= lphc
->textRect
;
1184 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1185 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1186 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1187 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1192 /***********************************************************************
1195 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1197 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL ok
, BOOL bRedrawButton
)
1199 if( lphc
->wState
& CBF_DROPPED
)
1201 CBRollUp( lphc
, ok
, bRedrawButton
);
1209 /***********************************************************************
1212 static void CBRepaintButton( LPHEADCOMBO lphc
)
1214 InvalidateRect(lphc
->self
, &lphc
->buttonRect
, TRUE
);
1215 UpdateWindow(lphc
->self
);
1218 /***********************************************************************
1221 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1223 if( !(lphc
->wState
& CBF_FOCUSED
) )
1225 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1226 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1228 /* This is wrong. Message sequences seem to indicate that this
1229 is set *after* the notify. */
1230 /* lphc->wState |= CBF_FOCUSED; */
1232 if( !(lphc
->wState
& CBF_EDIT
) )
1233 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1235 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1236 lphc
->wState
|= CBF_FOCUSED
;
1240 /***********************************************************************
1243 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1245 HWND hWnd
= lphc
->self
;
1247 if( lphc
->wState
& CBF_FOCUSED
)
1249 CBRollUp( lphc
, FALSE
, TRUE
);
1250 if( IsWindow( hWnd
) )
1252 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1253 SendMessageW(lphc
->hWndLBox
, LB_CARETOFF
, 0, 0);
1255 lphc
->wState
&= ~CBF_FOCUSED
;
1258 if( !(lphc
->wState
& CBF_EDIT
) )
1259 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1261 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1266 /***********************************************************************
1269 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1271 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1273 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1275 switch( HIWORD(wParam
) >> 8 )
1277 case (EN_SETFOCUS
>> 8):
1279 TRACE("[%p]: edit [%p] got focus\n", lphc
->self
, lphc
->hWndEdit
);
1281 COMBO_SetFocus( lphc
);
1284 case (EN_KILLFOCUS
>> 8):
1286 TRACE("[%p]: edit [%p] lost focus\n", lphc
->self
, lphc
->hWndEdit
);
1288 /* NOTE: it seems that Windows' edit control sends an
1289 * undocumented message WM_USER + 0x1B instead of this
1290 * notification (only when it happens to be a part of
1291 * the combo). ?? - AK.
1294 COMBO_KillFocus( lphc
);
1298 case (EN_CHANGE
>> 8):
1300 * In some circumstances (when the selection of the combobox
1301 * is changed for example) we don't want the EN_CHANGE notification
1302 * to be forwarded to the parent of the combobox. This code
1303 * checks a flag that is set in these occasions and ignores the
1306 if (lphc
->wState
& CBF_NOLBSELECT
)
1308 lphc
->wState
&= ~CBF_NOLBSELECT
;
1312 CBUpdateLBox( lphc
, lphc
->wState
& CBF_DROPPED
);
1315 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1316 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1319 case (EN_UPDATE
>> 8):
1320 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1321 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1324 case (EN_ERRSPACE
>> 8):
1325 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1328 else if( lphc
->hWndLBox
== hWnd
)
1330 switch( (short)HIWORD(wParam
) )
1333 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1337 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1343 TRACE("[%p]: lbox selection change [%x]\n", lphc
->self
, lphc
->wState
);
1345 /* do not roll up if selection is being tracked
1346 * by arrow keys in the dropdown listbox */
1347 if (!(lphc
->wState
& CBF_NOROLLUP
))
1349 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1351 else lphc
->wState
&= ~CBF_NOROLLUP
;
1353 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1355 if( HIWORD(wParam
) == LBN_SELCHANGE
)
1357 if( lphc
->wState
& CBF_EDIT
)
1359 INT index
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1360 lphc
->wState
|= CBF_NOLBSELECT
;
1361 CBUpdateEdit( lphc
, index
);
1362 /* select text in edit, as Windows does */
1363 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1367 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1368 UpdateWindow(lphc
->self
);
1375 /* nothing to do here since ComboLBox always resets the focus to its
1376 * combo/edit counterpart */
1383 /***********************************************************************
1386 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1388 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
, LPARAM lParam
)
1390 HWND hWnd
= lphc
->self
;
1391 UINT id
= (UINT
)GetWindowLongPtrW( hWnd
, GWLP_ID
);
1393 TRACE("[%p]: ownerdraw op %04x\n", lphc
->self
, msg
);
1399 DELETEITEMSTRUCT
*lpIS
= (DELETEITEMSTRUCT
*)lParam
;
1400 lpIS
->CtlType
= ODT_COMBOBOX
;
1402 lpIS
->hwndItem
= hWnd
;
1407 DRAWITEMSTRUCT
*lpIS
= (DRAWITEMSTRUCT
*)lParam
;
1408 lpIS
->CtlType
= ODT_COMBOBOX
;
1410 lpIS
->hwndItem
= hWnd
;
1413 case WM_COMPAREITEM
:
1415 COMPAREITEMSTRUCT
*lpIS
= (COMPAREITEMSTRUCT
*)lParam
;
1416 lpIS
->CtlType
= ODT_COMBOBOX
;
1418 lpIS
->hwndItem
= hWnd
;
1421 case WM_MEASUREITEM
:
1423 MEASUREITEMSTRUCT
*lpIS
= (MEASUREITEMSTRUCT
*)lParam
;
1424 lpIS
->CtlType
= ODT_COMBOBOX
;
1429 return SendMessageW(lphc
->owner
, msg
, id
, lParam
);
1433 /***********************************************************************
1436 static LRESULT
COMBO_GetTextW( LPHEADCOMBO lphc
, INT count
, LPWSTR buf
)
1440 if( lphc
->wState
& CBF_EDIT
)
1441 return SendMessageW( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1443 /* get it from the listbox */
1445 if (!count
|| !buf
) return 0;
1446 if( lphc
->hWndLBox
)
1448 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1449 if (idx
== LB_ERR
) goto error
;
1450 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1451 if (length
== LB_ERR
) goto error
;
1453 /* 'length' is without the terminating character */
1454 if (length
>= count
)
1456 LPWSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
1457 if (!lpBuffer
) goto error
;
1458 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1460 /* truncate if buffer is too short */
1461 if (length
!= LB_ERR
)
1463 lstrcpynW( buf
, lpBuffer
, count
);
1466 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1468 else length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1470 if (length
== LB_ERR
) return 0;
1474 error
: /* error - truncate string, return zero */
1480 /***********************************************************************
1483 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1484 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1486 static LRESULT
COMBO_GetTextA( LPHEADCOMBO lphc
, INT count
, LPSTR buf
)
1490 if( lphc
->wState
& CBF_EDIT
)
1491 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1493 /* get it from the listbox */
1495 if (!count
|| !buf
) return 0;
1496 if( lphc
->hWndLBox
)
1498 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1499 if (idx
== LB_ERR
) goto error
;
1500 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1501 if (length
== LB_ERR
) goto error
;
1503 /* 'length' is without the terminating character */
1504 if (length
>= count
)
1506 LPSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) );
1507 if (!lpBuffer
) goto error
;
1508 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1510 /* truncate if buffer is too short */
1511 if (length
!= LB_ERR
)
1513 lstrcpynA( buf
, lpBuffer
, count
);
1516 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1518 else length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1520 if (length
== LB_ERR
) return 0;
1524 error
: /* error - truncate string, return zero */
1530 /***********************************************************************
1533 * This function sets window positions according to the updated
1534 * component placement struct.
1536 static void CBResetPos(
1538 const RECT
*rectEdit
,
1542 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1544 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1545 * sizing messages */
1547 if( lphc
->wState
& CBF_EDIT
)
1548 SetWindowPos( lphc
->hWndEdit
, 0,
1549 rectEdit
->left
, rectEdit
->top
,
1550 rectEdit
->right
- rectEdit
->left
,
1551 rectEdit
->bottom
- rectEdit
->top
,
1552 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1554 SetWindowPos( lphc
->hWndLBox
, 0,
1555 rectLB
->left
, rectLB
->top
,
1556 rectLB
->right
- rectLB
->left
,
1557 rectLB
->bottom
- rectLB
->top
,
1558 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1562 if( lphc
->wState
& CBF_DROPPED
)
1564 lphc
->wState
&= ~CBF_DROPPED
;
1565 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1568 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1569 RedrawWindow( lphc
->self
, NULL
, 0,
1570 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1575 /***********************************************************************
1578 static void COMBO_Size( LPHEADCOMBO lphc
, BOOL bRedraw
)
1580 CBCalcPlacement(lphc
->self
,
1584 &lphc
->droppedRect
);
1586 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, bRedraw
);
1590 /***********************************************************************
1593 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1598 lphc
->hFont
= hFont
;
1601 * Propagate to owned windows.
1603 if( lphc
->wState
& CBF_EDIT
)
1604 SendMessageW(lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1605 SendMessageW(lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1608 * Redo the layout of the control.
1610 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1612 CBCalcPlacement(lphc
->self
,
1616 &lphc
->droppedRect
);
1618 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1622 CBForceDummyResize(lphc
);
1627 /***********************************************************************
1628 * COMBO_SetItemHeight
1630 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1632 LRESULT lRet
= CB_ERR
;
1634 if( index
== -1 ) /* set text field height */
1636 if( height
< 32768 )
1638 lphc
->editHeight
= height
+ 2; /* Is the 2 for 2*EDIT_CONTROL_PADDING? */
1641 * Redo the layout of the control.
1643 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1645 CBCalcPlacement(lphc
->self
,
1649 &lphc
->droppedRect
);
1651 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1655 CBForceDummyResize(lphc
);
1661 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1662 lRet
= SendMessageW(lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1663 (WPARAM
)index
, (LPARAM
)height
);
1667 /***********************************************************************
1668 * COMBO_SelectString
1670 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPARAM pText
, BOOL unicode
)
1672 INT index
= unicode
? SendMessageW(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
) :
1673 SendMessageA(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
);
1676 if( lphc
->wState
& CBF_EDIT
)
1677 CBUpdateEdit( lphc
, index
);
1680 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1683 return (LRESULT
)index
;
1686 /***********************************************************************
1689 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1693 HWND hWnd
= lphc
->self
;
1695 pt
.x
= (short)LOWORD(lParam
);
1696 pt
.y
= (short)HIWORD(lParam
);
1697 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1699 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1700 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1702 lphc
->wState
|= CBF_BUTTONDOWN
;
1703 if( lphc
->wState
& CBF_DROPPED
)
1705 /* got a click to cancel selection */
1707 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1708 CBRollUp( lphc
, TRUE
, FALSE
);
1709 if( !IsWindow( hWnd
) ) return;
1711 if( lphc
->wState
& CBF_CAPTURE
)
1713 lphc
->wState
&= ~CBF_CAPTURE
;
1719 /* drop down the listbox and start tracking */
1721 lphc
->wState
|= CBF_CAPTURE
;
1725 if( bButton
) CBRepaintButton( lphc
);
1729 /***********************************************************************
1732 * Release capture and stop tracking if needed.
1734 static void COMBO_LButtonUp( LPHEADCOMBO lphc
)
1736 if( lphc
->wState
& CBF_CAPTURE
)
1738 lphc
->wState
&= ~CBF_CAPTURE
;
1739 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1741 INT index
= CBUpdateLBox( lphc
, TRUE
);
1742 /* Update edit only if item is in the list */
1745 lphc
->wState
|= CBF_NOLBSELECT
;
1746 CBUpdateEdit( lphc
, index
);
1747 lphc
->wState
&= ~CBF_NOLBSELECT
;
1751 SetCapture(lphc
->hWndLBox
);
1754 if( lphc
->wState
& CBF_BUTTONDOWN
)
1756 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1757 CBRepaintButton( lphc
);
1761 /***********************************************************************
1764 * Two things to do - track combo button and release capture when
1765 * pointer goes into the listbox.
1767 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1772 pt
.x
= (short)LOWORD(lParam
);
1773 pt
.y
= (short)HIWORD(lParam
);
1775 if( lphc
->wState
& CBF_BUTTONDOWN
)
1779 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1783 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1784 CBRepaintButton( lphc
);
1788 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1789 MapWindowPoints( lphc
->self
, lphc
->hWndLBox
, &pt
, 1 );
1790 if( PtInRect(&lbRect
, pt
) )
1792 lphc
->wState
&= ~CBF_CAPTURE
;
1794 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
, TRUE
);
1796 /* hand over pointer tracking */
1797 SendMessageW(lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1801 static LRESULT
COMBO_GetComboBoxInfo(const HEADCOMBO
*lphc
, COMBOBOXINFO
*pcbi
)
1803 if (!pcbi
|| (pcbi
->cbSize
< sizeof(COMBOBOXINFO
)))
1806 pcbi
->rcItem
= lphc
->textRect
;
1807 pcbi
->rcButton
= lphc
->buttonRect
;
1808 pcbi
->stateButton
= 0;
1809 if (lphc
->wState
& CBF_BUTTONDOWN
)
1810 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
1811 if (IsRectEmpty(&lphc
->buttonRect
))
1812 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
1813 pcbi
->hwndCombo
= lphc
->self
;
1814 pcbi
->hwndItem
= lphc
->hWndEdit
;
1815 pcbi
->hwndList
= lphc
->hWndLBox
;
1819 static char *strdupA(LPCSTR str
)
1824 if(!str
) return NULL
;
1827 ret
= HeapAlloc(GetProcessHeap(), 0, len
+ 1);
1829 memcpy(ret
, str
, len
+ 1);
1833 /***********************************************************************
1834 * ComboWndProc_common
1836 LRESULT WINAPI
ComboWndProc_common( HWND hwnd
, UINT message
,
1837 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1839 LPHEADCOMBO lphc
= (LPHEADCOMBO
)GetWindowLongPtrW( hwnd
, 0 );
1843 pWnd
= ValidateHwnd(hwnd
);
1848 NtUserSetWindowFNID(hwnd
, FNID_COMBOBOX
);
1853 TRACE("[%p]: msg %s wp %08lx lp %08lx\n",
1854 hwnd
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1856 if( lphc
|| message
== WM_NCCREATE
)
1860 /* System messages */
1864 LONG style
= unicode
? ((LPCREATESTRUCTW
)lParam
)->style
:
1865 ((LPCREATESTRUCTA
)lParam
)->style
;
1866 return COMBO_NCCreate(hwnd
, style
);
1869 COMBO_NCDestroy(lphc
);
1871 NtUserSetWindowFNID(hwnd
, FNID_DESTROY
);
1873 break;/* -> DefWindowProc */
1881 hwndParent
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
1882 style
= ((LPCREATESTRUCTW
)lParam
)->style
;
1886 hwndParent
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
1887 style
= ((LPCREATESTRUCTA
)lParam
)->style
;
1889 return COMBO_Create(hwnd
, lphc
, hwndParent
, style
, unicode
);
1892 case WM_PRINTCLIENT
:
1895 /* wParam may contain a valid HDC! */
1896 return COMBO_Paint(lphc
, (HDC
)wParam
);
1899 /* do all painting in WM_PAINT like Windows does */
1904 LRESULT result
= DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1905 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1907 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1909 if ((vk
== VK_RETURN
|| vk
== VK_ESCAPE
) && (lphc
->wState
& CBF_DROPPED
))
1910 result
|= DLGC_WANTMESSAGE
;
1914 case WM_WINDOWPOSCHANGING
:
1915 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1916 case WM_WINDOWPOSCHANGED
:
1917 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1918 * In that case, the Combobox itself will not be resized, so we won't
1919 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1922 /* we should not force repainting on WM_WINDOWPOSCHANGED, it breaks
1923 * Z-order based painting.
1927 if( lphc
->hWndLBox
&&
1928 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
, message
== WM_SIZE
);
1931 COMBO_Font( lphc
, (HFONT
)wParam
, (BOOL
)lParam
);
1934 return (LRESULT
)lphc
->hFont
;
1936 if( lphc
->wState
& CBF_EDIT
) {
1937 SetFocus( lphc
->hWndEdit
);
1938 /* The first time focus is received, select all the text */
1939 if( !(lphc
->wState
& CBF_BEENFOCUSED
) ) {
1940 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, -1);
1941 lphc
->wState
|= CBF_BEENFOCUSED
;
1945 COMBO_SetFocus( lphc
);
1949 HWND hwndFocus
= WIN_GetFullHandle( (HWND
)wParam
);
1951 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1952 COMBO_KillFocus( lphc
);
1956 return COMBO_Command( lphc
, wParam
, WIN_GetFullHandle( (HWND
)lParam
) );
1958 return unicode
? COMBO_GetTextW( lphc
, wParam
, (LPWSTR
)lParam
)
1959 : COMBO_GetTextA( lphc
, wParam
, (LPSTR
)lParam
);
1961 case WM_GETTEXTLENGTH
:
1963 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1965 int j
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1966 if (j
== -1) return 0;
1967 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0) :
1968 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1970 else if( lphc
->wState
& CBF_EDIT
)
1973 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1974 ret
= unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1975 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1976 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1983 if( lphc
->wState
& CBF_EDIT
)
1985 return unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1986 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1992 case WM_COMPAREITEM
:
1993 case WM_MEASUREITEM
:
1994 return COMBO_ItemOp(lphc
, message
, lParam
);
1996 if( lphc
->wState
& CBF_EDIT
)
1997 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
1998 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
2000 /* Force the control to repaint when the enabled state changes. */
2001 InvalidateRect(lphc
->self
, NULL
, TRUE
);
2005 lphc
->wState
&= ~CBF_NOREDRAW
;
2007 lphc
->wState
|= CBF_NOREDRAW
;
2009 if( lphc
->wState
& CBF_EDIT
)
2010 SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
);
2011 SendMessageW(lphc
->hWndLBox
, message
, wParam
, lParam
);
2014 if( KEYDATA_ALT
& HIWORD(lParam
) )
2015 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
2016 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2020 if ((wParam
== VK_RETURN
|| wParam
== VK_ESCAPE
) &&
2021 (lphc
->wState
& CBF_DROPPED
))
2023 CBRollUp( lphc
, wParam
== VK_RETURN
, FALSE
);
2026 else if ((wParam
== VK_F4
) && !(lphc
->wState
& CBF_EUI
))
2028 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2037 if( lphc
->wState
& CBF_EDIT
)
2038 hwndTarget
= lphc
->hWndEdit
;
2040 hwndTarget
= lphc
->hWndLBox
;
2042 return unicode
? SendMessageW(hwndTarget
, message
, wParam
, lParam
) :
2043 SendMessageA(hwndTarget
, message
, wParam
, lParam
);
2045 case WM_LBUTTONDOWN
:
2046 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
);
2047 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
2050 COMBO_LButtonUp( lphc
);
2053 if( lphc
->wState
& CBF_CAPTURE
)
2054 COMBO_MouseMove( lphc
, wParam
, lParam
);
2058 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
2059 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2060 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2062 if (GET_WHEEL_DELTA_WPARAM(wParam
) > 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_UP
, 0);
2063 if (GET_WHEEL_DELTA_WPARAM(wParam
) < 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_DOWN
, 0);
2066 /* Combo messages */
2071 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2072 CharLowerW((LPWSTR
)lParam
);
2073 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2074 CharUpperW((LPWSTR
)lParam
);
2075 return SendMessageW(lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
2077 else /* unlike the unicode version, the ansi version does not overwrite
2078 the string if converting case */
2080 char *string
= NULL
;
2082 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2084 string
= strdupA((LPSTR
)lParam
);
2088 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2090 string
= strdupA((LPSTR
)lParam
);
2094 ret
= SendMessageA(lphc
->hWndLBox
, LB_ADDSTRING
, 0, string
? (LPARAM
)string
: lParam
);
2095 HeapFree(GetProcessHeap(), 0, string
);
2098 case CB_INSERTSTRING
:
2101 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2102 CharLowerW((LPWSTR
)lParam
);
2103 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2104 CharUpperW((LPWSTR
)lParam
);
2105 return SendMessageW(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2109 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2110 CharLowerA((LPSTR
)lParam
);
2111 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2112 CharUpperA((LPSTR
)lParam
);
2114 return SendMessageA(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2116 case CB_DELETESTRING
:
2117 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0) :
2118 SendMessageA(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
2119 case CB_SELECTSTRING
:
2120 return COMBO_SelectString(lphc
, (INT
)wParam
, lParam
, unicode
);
2122 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
) :
2123 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
2124 case CB_FINDSTRINGEXACT
:
2125 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
) :
2126 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
);
2127 case CB_SETITEMHEIGHT
:
2128 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
2129 case CB_GETITEMHEIGHT
:
2130 if( (INT
)wParam
>= 0 ) /* listbox item */
2131 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
2132 return CBGetTextAreaHeight(hwnd
, lphc
);
2133 case CB_RESETCONTENT
:
2134 SendMessageW(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0);
2135 if( (lphc
->wState
& CBF_EDIT
) && CB_HASSTRINGS(lphc
) )
2137 static const WCHAR empty_stringW
[] = { 0 };
2138 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, (LPARAM
)empty_stringW
);
2141 InvalidateRect(lphc
->self
, NULL
, TRUE
);
2143 case CB_INITSTORAGE
:
2144 return SendMessageW(lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
2145 case CB_GETHORIZONTALEXTENT
:
2146 return SendMessageW(lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
2147 case CB_SETHORIZONTALEXTENT
:
2148 return SendMessageW(lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
2149 case CB_GETTOPINDEX
:
2150 return SendMessageW(lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2152 return SendMessageW(lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2154 return SendMessageW(lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2155 case CB_GETDROPPEDWIDTH
:
2156 if( lphc
->droppedWidth
)
2157 return lphc
->droppedWidth
;
2158 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2159 case CB_SETDROPPEDWIDTH
:
2160 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2161 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2163 case CB_GETDROPPEDCONTROLRECT
:
2164 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2166 case CB_GETDROPPEDSTATE
:
2167 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2169 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
) :
2170 SendMessageA(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
);
2172 case CB_SHOWDROPDOWN
:
2173 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2177 if( !(lphc
->wState
& CBF_DROPPED
) )
2181 if( lphc
->wState
& CBF_DROPPED
)
2182 CBRollUp( lphc
, FALSE
, TRUE
);
2186 return SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2188 return SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2190 lParam
= SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2192 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, wParam
, 0);
2194 /* no LBN_SELCHANGE in this case, update manually */
2195 if( lphc
->wState
& CBF_EDIT
)
2196 CBUpdateEdit( lphc
, (INT
)wParam
);
2198 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2199 lphc
->wState
&= ~CBF_SELCHANGE
;
2202 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
) :
2203 SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2204 case CB_GETLBTEXTLEN
:
2205 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0) :
2206 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2207 case CB_GETITEMDATA
:
2208 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2209 case CB_SETITEMDATA
:
2210 return SendMessageW(lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2212 /* Edit checks passed parameters itself */
2213 if( lphc
->wState
& CBF_EDIT
)
2214 return SendMessageW(lphc
->hWndEdit
, EM_GETSEL
, wParam
, lParam
);
2217 if( lphc
->wState
& CBF_EDIT
)
2218 return SendMessageW(lphc
->hWndEdit
, EM_SETSEL
,
2219 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2221 case CB_SETEXTENDEDUI
:
2222 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2225 lphc
->wState
|= CBF_EUI
;
2226 else lphc
->wState
&= ~CBF_EUI
;
2228 case CB_GETEXTENDEDUI
:
2229 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2230 case CB_GETCOMBOBOXINFO
:
2231 return COMBO_GetComboBoxInfo(lphc
, (COMBOBOXINFO
*)lParam
);
2233 if( lphc
->wState
& CBF_EDIT
)
2234 return SendMessageW(lphc
->hWndEdit
, EM_LIMITTEXT
, wParam
, lParam
);
2236 case WM_UPDATEUISTATE
:
2238 DefWindowProcW(lphc
->self
, message
, wParam
, lParam
);
2240 DefWindowProcA(lphc
->self
, message
, wParam
, lParam
);
2242 if (COMBO_update_uistate(lphc
))
2245 if( !(lphc
->wState
& CBF_EDIT
) )
2246 NtUserInvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2251 if (message
>= WM_USER
)
2252 WARN("unknown msg WM_USER+%04x wp=%04lx lp=%08lx\n",
2253 message
- WM_USER
, wParam
, lParam
);
2256 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2257 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2260 /***********************************************************************
2263 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2266 LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2268 if (!IsWindow(hwnd
)) return 0;
2269 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
2272 /***********************************************************************
2275 LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2277 if (!IsWindow(hwnd
)) return 0;
2278 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
2281 /*************************************************************************
2282 * GetComboBoxInfo (USER32.@)
2284 BOOL WINAPI
GetComboBoxInfo(HWND hwndCombo
, /* [in] handle to combo box */
2285 PCOMBOBOXINFO pcbi
/* [in/out] combo box information */)
2287 TRACE("(%p, %p)\n", hwndCombo
, pcbi
);
2289 return SendMessageW(hwndCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
);
2291 return NtUserGetComboBoxInfo(hwndCombo
, pcbi
);