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
40 WINE_DEFAULT_DEBUG_CHANNEL(combo
);
42 /* bits in the dwKeyData */
43 #define KEYDATA_ALT 0x2000
44 #define KEYDATA_PREVSTATE 0x4000
47 * Additional combo box definitions
50 #define CB_NOTIFY( lphc, code ) \
51 (SendMessageW((lphc)->owner, WM_COMMAND, \
52 MAKEWPARAM(GetWindowLongPtrW((lphc)->self,GWLP_ID), (code)), (LPARAM)(lphc)->self))
54 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
55 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
56 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
57 #define CB_HWND( lphc ) ((lphc)->self)
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
);
142 /***********************************************************************
145 static LRESULT
COMBO_NCCreate(HWND hwnd
, LONG style
)
149 if (COMBO_Init() && (lphc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HEADCOMBO
))) )
152 SetWindowLongW( hwnd
, 0, (LONG
)lphc
);
154 /* some braindead apps do try to use scrollbar/border flags */
156 lphc
->dwStyle
= style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
);
157 SetWindowLongW( hwnd
, GWL_STYLE
, style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
) );
160 * We also have to remove the client edge style to make sure
161 * we don't end-up with a non client area.
163 SetWindowLongW( hwnd
, GWL_EXSTYLE
,
164 GetWindowLongW( hwnd
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
166 if( !(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) )
167 lphc
->dwStyle
|= CBS_HASSTRINGS
;
168 if( !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) )
169 lphc
->wState
|= CBF_NOTIFY
;
171 TRACE("[%p], style = %08x\n", lphc
, lphc
->dwStyle
);
177 /***********************************************************************
180 static LRESULT
COMBO_NCDestroy( LPHEADCOMBO lphc
)
185 TRACE("[%p]: freeing storage\n", lphc
->self
);
187 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) && lphc
->hWndLBox
)
188 DestroyWindow( lphc
->hWndLBox
);
190 SetWindowLongPtrW( lphc
->self
, 0, 0 );
191 HeapFree( GetProcessHeap(), 0, lphc
);
196 /***********************************************************************
197 * CBGetTextAreaHeight
199 * This method will calculate the height of the text area of the
201 * The height of the text area is set in two ways.
202 * It can be set explicitly through a combobox message or through a
203 * WM_MEASUREITEM callback.
204 * If this is not the case, the height is set to 13 dialog units.
205 * This height was determined through experimentation.
207 static INT
CBGetTextAreaHeight(
213 if( lphc
->editHeight
) /* explicitly set height */
215 iTextItemHeight
= lphc
->editHeight
;
220 HDC hDC
= GetDC(hwnd
);
225 hPrevFont
= SelectObject( hDC
, lphc
->hFont
);
227 GetTextMetricsW(hDC
, &tm
);
229 baseUnitY
= tm
.tmHeight
;
232 SelectObject( hDC
, hPrevFont
);
234 ReleaseDC(hwnd
, hDC
);
236 iTextItemHeight
= ((13 * baseUnitY
) / 8);
239 * This "formula" calculates the height of the complete control.
240 * To calculate the height of the text area, we have to remove the
243 iTextItemHeight
-= 2*COMBO_YBORDERSIZE();
247 * Check the ownerdraw case if we haven't asked the parent the size
250 if ( CB_OWNERDRAWN(lphc
) &&
251 (lphc
->wState
& CBF_MEASUREITEM
) )
253 MEASUREITEMSTRUCT measureItem
;
255 INT originalItemHeight
= iTextItemHeight
;
256 UINT id
= GetWindowLongPtrW( lphc
->self
, GWLP_ID
);
259 * We use the client rect for the width of the item.
261 GetClientRect(hwnd
, &clientRect
);
263 lphc
->wState
&= ~CBF_MEASUREITEM
;
266 * Send a first one to measure the size of the text area
268 measureItem
.CtlType
= ODT_COMBOBOX
;
269 measureItem
.CtlID
= id
;
270 measureItem
.itemID
= -1;
271 measureItem
.itemWidth
= clientRect
.right
;
272 measureItem
.itemHeight
= iTextItemHeight
- 6; /* ownerdrawn cb is taller */
273 measureItem
.itemData
= 0;
274 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
275 iTextItemHeight
= 6 + measureItem
.itemHeight
;
278 * Send a second one in the case of a fixed ownerdraw list to calculate the
279 * size of the list items. (we basically do this on behalf of the listbox)
281 if (lphc
->dwStyle
& CBS_OWNERDRAWFIXED
)
283 measureItem
.CtlType
= ODT_COMBOBOX
;
284 measureItem
.CtlID
= id
;
285 measureItem
.itemID
= 0;
286 measureItem
.itemWidth
= clientRect
.right
;
287 measureItem
.itemHeight
= originalItemHeight
;
288 measureItem
.itemData
= 0;
289 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
290 lphc
->fixedOwnerDrawHeight
= measureItem
.itemHeight
;
294 * Keep the size for the next time
296 lphc
->editHeight
= iTextItemHeight
;
299 return iTextItemHeight
;
302 /***********************************************************************
305 * The dummy resize is used for listboxes that have a popup to trigger
306 * a re-arranging of the contents of the combobox and the recalculation
307 * of the size of the "real" control window.
309 static void CBForceDummyResize(
315 newComboHeight
= CBGetTextAreaHeight(lphc
->self
,lphc
) + 2*COMBO_YBORDERSIZE();
317 GetWindowRect(lphc
->self
, &windowRect
);
320 * We have to be careful, resizing a combobox also has the meaning that the
321 * dropped rect will be resized. In this case, we want to trigger a resize
322 * to recalculate layout but we don't want to change the dropped rectangle
323 * So, we pass the height of text area of control as the height.
324 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
327 SetWindowPos( lphc
->self
,
330 windowRect
.right
- windowRect
.left
,
332 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
335 /***********************************************************************
338 * Set up component coordinates given valid lphc->RectCombo.
340 static void CBCalcPlacement(
348 * Again, start with the client rectangle.
350 GetClientRect(hwnd
, lprEdit
);
355 InflateRect(lprEdit
, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
358 * Chop off the bottom part to fit with the height of the text area.
360 lprEdit
->bottom
= lprEdit
->top
+ CBGetTextAreaHeight(hwnd
, lphc
);
363 * The button starts the same vertical position as the text area.
365 CopyRect(lprButton
, lprEdit
);
368 * If the combobox is "simple" there is no button.
370 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
371 lprButton
->left
= lprButton
->right
= lprButton
->bottom
= 0;
375 * Let's assume the combobox button is the same width as the
377 * size the button horizontally and cut-off the text area.
379 lprButton
->left
= lprButton
->right
- GetSystemMetrics(SM_CXVSCROLL
);
380 lprEdit
->right
= lprButton
->left
;
384 * In the case of a dropdown, there is an additional spacing between the
385 * text area and the button.
387 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
389 lprEdit
->right
-= COMBO_EDITBUTTONSPACE();
393 * If we have an edit control, we space it away from the borders slightly.
395 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
397 InflateRect(lprEdit
, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
401 * Adjust the size of the listbox popup.
403 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
406 * Use the client rectangle to initialize the listbox rectangle
408 GetClientRect(hwnd
, lprLB
);
411 * Then, chop-off the top part.
413 lprLB
->top
= lprEdit
->bottom
+ COMBO_YBORDERSIZE();
418 * Make sure the dropped width is as large as the combobox itself.
420 if (lphc
->droppedWidth
< (lprButton
->right
+ COMBO_XBORDERSIZE()))
422 lprLB
->right
= lprLB
->left
+ (lprButton
->right
+ COMBO_XBORDERSIZE());
425 * In the case of a dropdown, the popup listbox is offset to the right.
426 * so, we want to make sure it's flush with the right side of the
429 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
430 lprLB
->right
-= COMBO_EDITBUTTONSPACE();
433 lprLB
->right
= lprLB
->left
+ lphc
->droppedWidth
;
436 TRACE("\ttext\t= (%ld,%ld-%ld,%ld)\n",
437 lprEdit
->left
, lprEdit
->top
, lprEdit
->right
, lprEdit
->bottom
);
439 TRACE("\tbutton\t= (%ld,%ld-%ld,%ld)\n",
440 lprButton
->left
, lprButton
->top
, lprButton
->right
, lprButton
->bottom
);
442 TRACE("\tlbox\t= (%ld,%ld-%ld,%ld)\n",
443 lprLB
->left
, lprLB
->top
, lprLB
->right
, lprLB
->bottom
);
446 /***********************************************************************
447 * CBGetDroppedControlRect
449 static void CBGetDroppedControlRect( LPHEADCOMBO lphc
, LPRECT lpRect
)
451 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
452 of the combo box and the lower right corner of the listbox */
454 GetWindowRect(lphc
->self
, lpRect
);
456 lpRect
->right
= lpRect
->left
+ lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
457 lpRect
->bottom
= lpRect
->top
+ lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
461 /***********************************************************************
462 * COMBO_WindowPosChanging
464 static LRESULT
COMBO_WindowPosChanging(
467 WINDOWPOS
* posChanging
)
470 * We need to override the WM_WINDOWPOSCHANGING method to handle all
471 * the non-simple comboboxes. The problem is that those controls are
472 * always the same height. We have to make sure they are not resized
475 if ( ( CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
476 ((posChanging
->flags
& SWP_NOSIZE
) == 0) )
480 newComboHeight
= CBGetTextAreaHeight(hwnd
,lphc
) +
481 2*COMBO_YBORDERSIZE();
484 * Resizing a combobox has another side effect, it resizes the dropped
485 * rectangle as well. However, it does it only if the new height for the
486 * combobox is different from the height it should have. In other words,
487 * if the application resizing the combobox only had the intention to resize
488 * the actual control, for example, to do the layout of a dialog that is
489 * resized, the height of the dropdown is not changed.
491 if (posChanging
->cy
!= newComboHeight
)
493 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%ld, oldtop=%ld\n",
494 posChanging
->cy
, newComboHeight
, lphc
->droppedRect
.bottom
,
495 lphc
->droppedRect
.top
);
496 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
+ posChanging
->cy
- newComboHeight
;
498 posChanging
->cy
= newComboHeight
;
505 /***********************************************************************
508 static LRESULT
COMBO_Create( HWND hwnd
, LPHEADCOMBO lphc
, HWND hwndParent
, LONG style
,
511 static const WCHAR clbName
[] = {'C','o','m','b','o','L','B','o','x',0};
512 static const WCHAR editName
[] = {'E','d','i','t',0};
514 if( !CB_GETTYPE(lphc
) ) lphc
->dwStyle
|= CBS_SIMPLE
;
515 if( CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
) lphc
->wState
|= CBF_EDIT
;
517 lphc
->owner
= hwndParent
;
520 * The item height and dropped width are not set when the control
523 lphc
->droppedWidth
= lphc
->editHeight
= 0;
526 * The first time we go through, we want to measure the ownerdraw item
528 lphc
->wState
|= CBF_MEASUREITEM
;
530 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
532 if( lphc
->owner
|| !(style
& WS_VISIBLE
) )
538 * Initialize the dropped rect to the size of the client area of the
539 * control and then, force all the areas of the combobox to be
542 GetClientRect( hwnd
, &lphc
->droppedRect
);
543 CBCalcPlacement(hwnd
, lphc
, &lphc
->textRect
, &lphc
->buttonRect
, &lphc
->droppedRect
);
546 * Adjust the position of the popup listbox if it's necessary
548 if ( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
550 lphc
->droppedRect
.top
= lphc
->textRect
.bottom
+ COMBO_YBORDERSIZE();
553 * If it's a dropdown, the listbox is offset
555 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
556 lphc
->droppedRect
.left
+= COMBO_EDITBUTTONSPACE();
558 if (lphc
->droppedRect
.bottom
< lphc
->droppedRect
.top
)
559 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
;
560 if (lphc
->droppedRect
.right
< lphc
->droppedRect
.left
)
561 lphc
->droppedRect
.right
= lphc
->droppedRect
.left
;
562 MapWindowPoints( hwnd
, 0, (LPPOINT
)&lphc
->droppedRect
, 2 );
565 /* create listbox popup */
567 lbeStyle
= (LBS_NOTIFY
| LBS_COMBOBOX
| WS_BORDER
| WS_CLIPSIBLINGS
| WS_CHILD
) |
568 (style
& (WS_VSCROLL
| CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
));
570 if( lphc
->dwStyle
& CBS_SORT
)
571 lbeStyle
|= LBS_SORT
;
572 if( lphc
->dwStyle
& CBS_HASSTRINGS
)
573 lbeStyle
|= LBS_HASSTRINGS
;
574 if( lphc
->dwStyle
& CBS_NOINTEGRALHEIGHT
)
575 lbeStyle
|= LBS_NOINTEGRALHEIGHT
;
576 if( lphc
->dwStyle
& CBS_DISABLENOSCROLL
)
577 lbeStyle
|= LBS_DISABLENOSCROLL
;
579 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
) /* child listbox */
581 lbeStyle
|= WS_VISIBLE
;
584 * In win 95 look n feel, the listbox in the simple combobox has
585 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
587 lbeStyle
&= ~WS_BORDER
;
588 lbeExStyle
|= WS_EX_CLIENTEDGE
;
592 lbeExStyle
|= (WS_EX_TOPMOST
| WS_EX_TOOLWINDOW
);
596 lphc
->hWndLBox
= CreateWindowExW(lbeExStyle
, clbName
, NULL
, lbeStyle
,
597 lphc
->droppedRect
.left
,
598 lphc
->droppedRect
.top
,
599 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
600 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
601 hwnd
, (HMENU
)ID_CB_LISTBOX
,
602 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), lphc
);
604 lphc
->hWndLBox
= CreateWindowExA(lbeExStyle
, "ComboLBox", NULL
, lbeStyle
,
605 lphc
->droppedRect
.left
,
606 lphc
->droppedRect
.top
,
607 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
608 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
609 hwnd
, (HMENU
)ID_CB_LISTBOX
,
610 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), lphc
);
615 lbeStyle
= WS_CHILD
| WS_VISIBLE
| ES_NOHIDESEL
| ES_LEFT
| ES_COMBO
;
617 if( lphc
->wState
& CBF_EDIT
)
619 if( lphc
->dwStyle
& CBS_OEMCONVERT
)
620 lbeStyle
|= ES_OEMCONVERT
;
621 if( lphc
->dwStyle
& CBS_AUTOHSCROLL
)
622 lbeStyle
|= ES_AUTOHSCROLL
;
623 if( lphc
->dwStyle
& CBS_LOWERCASE
)
624 lbeStyle
|= ES_LOWERCASE
;
625 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
626 lbeStyle
|= ES_UPPERCASE
;
628 if (!IsWindowEnabled(hwnd
)) lbeStyle
|= WS_DISABLED
;
631 lphc
->hWndEdit
= CreateWindowExW(0, editName
, NULL
, lbeStyle
,
632 lphc
->textRect
.left
, lphc
->textRect
.top
,
633 lphc
->textRect
.right
- lphc
->textRect
.left
,
634 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
635 hwnd
, (HMENU
)ID_CB_EDIT
,
636 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), NULL
);
638 lphc
->hWndEdit
= CreateWindowExA(0, "Edit", NULL
, lbeStyle
,
639 lphc
->textRect
.left
, lphc
->textRect
.top
,
640 lphc
->textRect
.right
- lphc
->textRect
.left
,
641 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
642 hwnd
, (HMENU
)ID_CB_EDIT
,
643 (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
), NULL
);
645 if( !lphc
->hWndEdit
)
651 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
653 /* Now do the trick with parent */
654 SetParent(lphc
->hWndLBox
, HWND_DESKTOP
);
656 * If the combo is a dropdown, we must resize the control
657 * to fit only the text area and button. To do this,
658 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
659 * will take care of setting the height for us.
661 CBForceDummyResize(lphc
);
664 TRACE("init done\n");
667 ERR("edit control failure.\n");
668 } else ERR("listbox failure.\n");
669 } else ERR("no owner for visible combo.\n");
671 /* CreateWindow() will send WM_NCDESTROY to cleanup */
676 /***********************************************************************
679 * Paint combo button (normal, pressed, and disabled states).
681 static void CBPaintButton( LPHEADCOMBO lphc
, HDC hdc
, RECT rectButton
)
683 UINT buttonState
= DFCS_SCROLLCOMBOBOX
;
685 if( lphc
->wState
& CBF_NOREDRAW
)
689 if (lphc
->wState
& CBF_BUTTONDOWN
)
690 buttonState
|= DFCS_PUSHED
;
692 if (CB_DISABLED(lphc
))
693 buttonState
|= DFCS_INACTIVE
;
695 DrawFrameControl(hdc
, &rectButton
, DFC_SCROLL
, buttonState
);
698 /***********************************************************************
701 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
703 static void CBPaintText(
711 if( lphc
->wState
& CBF_NOREDRAW
) return;
715 /* follow Windows combobox that sends a bunch of text
716 * inquiries to its listbox while processing WM_PAINT. */
718 if( (id
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0) ) != LB_ERR
)
720 size
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, id
, 0);
722 FIXME("LB_ERR probably not handled yet\n");
723 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (size
+ 1) * sizeof(WCHAR
))) )
725 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
726 size
=SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, (WPARAM
)id
, (LPARAM
)pText
);
727 pText
[size
] = '\0'; /* just in case */
731 if( !CB_OWNERDRAWN(lphc
) )
734 if( lphc
->wState
& CBF_EDIT
)
736 static const WCHAR empty_stringW
[] = { 0 };
737 if( CB_HASSTRINGS(lphc
) ) SetWindowTextW( lphc
->hWndEdit
, pText
? pText
: empty_stringW
);
738 if( lphc
->wState
& CBF_FOCUSED
)
739 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
741 else /* paint text field ourselves */
743 UINT itemState
= ODS_COMBOBOXEDIT
;
744 HFONT hPrevFont
= (lphc
->hFont
) ? SelectObject(hdc
, lphc
->hFont
) : 0;
747 * Give ourselves some space.
749 InflateRect( &rectEdit
, -1, -1 );
751 if( CB_OWNERDRAWN(lphc
) )
755 UINT ctlid
= (UINT
)GetWindowLongPtrW( lphc
->self
, GWLP_ID
);
757 /* setup state for DRAWITEM message. Owner will highlight */
758 if ( (lphc
->wState
& CBF_FOCUSED
) &&
759 !(lphc
->wState
& CBF_DROPPED
) )
760 itemState
|= ODS_SELECTED
| ODS_FOCUS
;
763 * Save the current clip region.
764 * To retrieve the clip region, we need to create one "dummy"
767 clipRegion
= CreateRectRgnIndirect(&rectEdit
);
769 if (GetClipRgn(hdc
, clipRegion
)!=1)
771 DeleteObject(clipRegion
);
775 if (!IsWindowEnabled(lphc
->self
) & WS_DISABLED
) itemState
|= ODS_DISABLED
;
777 dis
.CtlType
= ODT_COMBOBOX
;
779 dis
.hwndItem
= lphc
->self
;
780 dis
.itemAction
= ODA_DRAWENTIRE
;
782 dis
.itemState
= itemState
;
784 dis
.rcItem
= rectEdit
;
785 dis
.itemData
= SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
,
789 * Clip the DC and have the parent draw the item.
791 IntersectClipRect(hdc
,
792 rectEdit
.left
, rectEdit
.top
,
793 rectEdit
.right
, rectEdit
.bottom
);
795 SendMessageW(lphc
->owner
, WM_DRAWITEM
, ctlid
, (LPARAM
)&dis
);
798 * Reset the clipping region.
800 SelectClipRgn(hdc
, clipRegion
);
804 static const WCHAR empty_stringW
[] = { 0 };
806 if ( (lphc
->wState
& CBF_FOCUSED
) &&
807 !(lphc
->wState
& CBF_DROPPED
) ) {
810 FillRect( hdc
, &rectEdit
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
811 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
812 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
818 ETO_OPAQUE
| ETO_CLIPPED
,
820 pText
? pText
: empty_stringW
, size
, NULL
);
822 if(lphc
->wState
& CBF_FOCUSED
&& !(lphc
->wState
& CBF_DROPPED
))
823 DrawFocusRect( hdc
, &rectEdit
);
827 SelectObject(hdc
, hPrevFont
);
830 HeapFree( GetProcessHeap(), 0, pText
);
833 /***********************************************************************
836 static void CBPaintBorder(
843 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
845 GetClientRect(hwnd
, &clientRect
);
849 CopyRect(&clientRect
, &lphc
->textRect
);
851 InflateRect(&clientRect
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
852 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
855 DrawEdge(hdc
, &clientRect
, EDGE_SUNKEN
, BF_RECT
);
858 /***********************************************************************
859 * COMBO_PrepareColors
861 * This method will sent the appropriate WM_CTLCOLOR message to
862 * prepare and setup the colors for the combo's DC.
864 * It also returns the brush to use for the background.
866 static HBRUSH
COMBO_PrepareColors(
873 * Get the background brush for this control.
875 if (CB_DISABLED(lphc
))
877 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORSTATIC
,
878 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
881 * We have to change the text color since WM_CTLCOLORSTATIC will
882 * set it to the "enabled" color. This is the same behavior as the
885 SetTextColor(hDC
, GetSysColor(COLOR_GRAYTEXT
));
889 if (lphc
->wState
& CBF_EDIT
)
891 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLOREDIT
,
892 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
896 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORLISTBOX
,
897 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
905 hBkgBrush
= GetSysColorBrush(COLOR_WINDOW
);
910 /***********************************************************************
911 * COMBO_EraseBackground
913 static LRESULT
COMBO_EraseBackground(
921 if(lphc
->wState
& CBF_EDIT
)
924 hDC
= (hParamDC
) ? hParamDC
927 * Retrieve the background brush
929 hBkgBrush
= COMBO_PrepareColors(lphc
, hDC
);
931 FillRect(hDC
, &lphc
->textRect
, hBkgBrush
);
934 ReleaseDC(hwnd
, hDC
);
939 /***********************************************************************
942 static LRESULT
COMBO_Paint(LPHEADCOMBO lphc
, HDC hParamDC
)
947 hDC
= (hParamDC
) ? hParamDC
948 : BeginPaint( lphc
->self
, &ps
);
950 TRACE("hdc=%p\n", hDC
);
952 if( hDC
&& !(lphc
->wState
& CBF_NOREDRAW
) )
954 HBRUSH hPrevBrush
, hBkgBrush
;
957 * Retrieve the background brush and select it in the
960 hBkgBrush
= COMBO_PrepareColors(lphc
, hDC
);
962 hPrevBrush
= SelectObject( hDC
, hBkgBrush
);
965 * In non 3.1 look, there is a sunken border on the combobox
967 CBPaintBorder(lphc
->self
, lphc
, hDC
);
969 if( !IsRectEmpty(&lphc
->buttonRect
) )
971 CBPaintButton(lphc
, hDC
, lphc
->buttonRect
);
974 /* paint the edit control padding area */
975 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
977 RECT rPadEdit
= lphc
->textRect
;
979 InflateRect(&rPadEdit
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
981 FrameRect( hDC
, &rPadEdit
, GetSysColorBrush(COLOR_WINDOW
) );
984 if( !(lphc
->wState
& CBF_EDIT
) )
985 CBPaintText( lphc
, hDC
, lphc
->textRect
);
988 SelectObject( hDC
, hPrevBrush
);
992 EndPaint(lphc
->self
, &ps
);
997 /***********************************************************************
1000 * Select listbox entry according to the contents of the edit control.
1002 static INT
CBUpdateLBox( LPHEADCOMBO lphc
, BOOL bSelect
)
1005 LPWSTR pText
= NULL
;
1008 length
= SendMessageW( lphc
->hWndEdit
, WM_GETTEXTLENGTH
, 0, 0 );
1011 pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
1013 TRACE("\t edit text length %i\n", length
);
1017 if( length
) GetWindowTextW( lphc
->hWndEdit
, pText
, length
+ 1);
1018 else pText
[0] = '\0';
1019 idx
= SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
,
1020 (WPARAM
)(-1), (LPARAM
)pText
);
1021 HeapFree( GetProcessHeap(), 0, pText
);
1024 SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, (WPARAM
)(bSelect
? idx
: -1), 0);
1026 /* probably superfluous but Windows sends this too */
1027 SendMessageW(lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
1028 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
1033 /***********************************************************************
1036 * Copy a listbox entry to the edit control.
1038 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1041 LPWSTR pText
= NULL
;
1042 static const WCHAR empty_stringW
[] = { 0 };
1044 TRACE("\t %i\n", index
);
1046 if( index
>= 0 ) /* got an entry */
1048 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1049 if( length
!= LB_ERR
)
1051 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
))) )
1053 SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
,
1054 (WPARAM
)index
, (LPARAM
)pText
);
1059 lphc
->wState
|= (CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1060 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, pText
? (LPARAM
)pText
: (LPARAM
)empty_stringW
);
1061 lphc
->wState
&= ~(CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1063 if( lphc
->wState
& CBF_FOCUSED
)
1064 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1066 HeapFree( GetProcessHeap(), 0, pText
);
1069 /***********************************************************************
1072 * Show listbox popup.
1074 static void CBDropDown( LPHEADCOMBO lphc
)
1080 TRACE("[%p]: drop down\n", lphc
->self
);
1082 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1086 lphc
->wState
|= CBF_DROPPED
;
1087 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1089 lphc
->droppedIndex
= CBUpdateLBox( lphc
, TRUE
);
1091 /* Update edit only if item is in the list */
1092 if( !(lphc
->wState
& CBF_CAPTURE
) && lphc
->droppedIndex
>= 0)
1093 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1097 lphc
->droppedIndex
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1099 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
,
1100 (WPARAM
)(lphc
->droppedIndex
== LB_ERR
? 0 : lphc
->droppedIndex
), 0 );
1101 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1104 /* now set popup position */
1105 GetWindowRect( lphc
->self
, &rect
);
1108 * If it's a dropdown, the listbox is offset
1110 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1111 rect
.left
+= COMBO_EDITBUTTONSPACE();
1113 /* if the dropped height is greater than the total height of the dropped
1114 items list, then force the drop down list height to be the total height
1115 of the items in the dropped list */
1117 /* And Remove any extra space (Best Fit) */
1118 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1119 /* if listbox length has been set directly by its handle */
1120 GetWindowRect(lphc
->hWndLBox
, &r
);
1121 if (nDroppedHeight
< r
.bottom
- r
.top
)
1122 nDroppedHeight
= r
.bottom
- r
.top
;
1123 nItems
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1130 nIHeight
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, 0, 0);
1132 nHeight
= nIHeight
*nItems
;
1134 if (nHeight
< nDroppedHeight
- COMBO_YBORDERSIZE())
1135 nDroppedHeight
= nHeight
+ COMBO_YBORDERSIZE();
1137 if (nDroppedHeight
< nIHeight
)
1140 nDroppedHeight
= (nItems
+1)*nIHeight
;
1142 nDroppedHeight
= 6*nIHeight
;
1146 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1147 if( (rect
.bottom
+ nDroppedHeight
) >= GetSystemMetrics( SM_CYSCREEN
) )
1148 rect
.bottom
= rect
.top
- nDroppedHeight
;
1150 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1151 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1153 SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
1156 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1157 RedrawWindow( lphc
->self
, NULL
, 0, RDW_INVALIDATE
|
1158 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1160 EnableWindow( lphc
->hWndLBox
, TRUE
);
1161 if (GetCapture() != lphc
->self
)
1162 SetCapture(lphc
->hWndLBox
);
1165 /***********************************************************************
1168 * Hide listbox popup.
1170 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1172 HWND hWnd
= lphc
->self
;
1174 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1175 lphc
->self
, (INT
)ok
, (INT
)(lphc
->wState
& CBF_DROPPED
));
1177 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1179 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1182 if( lphc
->wState
& CBF_DROPPED
)
1186 lphc
->wState
&= ~CBF_DROPPED
;
1187 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1189 if(GetCapture() == lphc
->hWndLBox
)
1194 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1196 rect
= lphc
->buttonRect
;
1207 rect
= lphc
->textRect
;
1212 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1213 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1214 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1215 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1220 /***********************************************************************
1223 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1225 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL ok
, BOOL bRedrawButton
)
1227 if( lphc
->wState
& CBF_DROPPED
)
1229 CBRollUp( lphc
, ok
, bRedrawButton
);
1237 /***********************************************************************
1240 static void CBRepaintButton( LPHEADCOMBO lphc
)
1242 InvalidateRect(lphc
->self
, &lphc
->buttonRect
, TRUE
);
1243 UpdateWindow(lphc
->self
);
1246 /***********************************************************************
1249 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1251 if( !(lphc
->wState
& CBF_FOCUSED
) )
1253 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1254 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1256 /* This is wrong. Message sequences seem to indicate that this
1257 is set *after* the notify. */
1258 /* lphc->wState |= CBF_FOCUSED; */
1260 if( !(lphc
->wState
& CBF_EDIT
) )
1261 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1263 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1264 lphc
->wState
|= CBF_FOCUSED
;
1268 /***********************************************************************
1271 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1273 HWND hWnd
= lphc
->self
;
1275 if( lphc
->wState
& CBF_FOCUSED
)
1277 CBRollUp( lphc
, FALSE
, TRUE
);
1278 if( IsWindow( hWnd
) )
1280 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1281 SendMessageW(lphc
->hWndLBox
, LB_CARETOFF
, 0, 0);
1283 lphc
->wState
&= ~CBF_FOCUSED
;
1286 if( !(lphc
->wState
& CBF_EDIT
) )
1287 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1289 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1294 /***********************************************************************
1297 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1299 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1301 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1303 switch( HIWORD(wParam
) >> 8 )
1305 case (EN_SETFOCUS
>> 8):
1307 TRACE("[%p]: edit [%p] got focus\n", lphc
->self
, lphc
->hWndEdit
);
1309 COMBO_SetFocus( lphc
);
1312 case (EN_KILLFOCUS
>> 8):
1314 TRACE("[%p]: edit [%p] lost focus\n", lphc
->self
, lphc
->hWndEdit
);
1316 /* NOTE: it seems that Windows' edit control sends an
1317 * undocumented message WM_USER + 0x1B instead of this
1318 * notification (only when it happens to be a part of
1319 * the combo). ?? - AK.
1322 COMBO_KillFocus( lphc
);
1326 case (EN_CHANGE
>> 8):
1328 * In some circumstances (when the selection of the combobox
1329 * is changed for example) we don't wans the EN_CHANGE notification
1330 * to be forwarded to the parent of the combobox. This code
1331 * checks a flag that is set in these occasions and ignores the
1334 if (lphc
->wState
& CBF_NOLBSELECT
)
1336 lphc
->wState
&= ~CBF_NOLBSELECT
;
1340 CBUpdateLBox( lphc
, lphc
->wState
& CBF_DROPPED
);
1343 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1344 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1347 case (EN_UPDATE
>> 8):
1348 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1349 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1352 case (EN_ERRSPACE
>> 8):
1353 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1356 else if( lphc
->hWndLBox
== hWnd
)
1358 switch( (short)HIWORD(wParam
) )
1361 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1365 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1371 TRACE("[%p]: lbox selection change [%x]\n", lphc
->self
, lphc
->wState
);
1373 if( HIWORD(wParam
) == LBN_SELCHANGE
)
1375 if( lphc
->wState
& CBF_EDIT
)
1377 INT index
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1378 lphc
->wState
|= CBF_NOLBSELECT
;
1379 CBUpdateEdit( lphc
, index
);
1380 /* select text in edit, as Windows does */
1381 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1384 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1387 /* do not roll up if selection is being tracked
1388 * by arrowkeys in the dropdown listbox */
1389 if( ((lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
)) )
1391 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1393 else lphc
->wState
&= ~CBF_NOROLLUP
;
1395 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1401 /* nothing to do here since ComboLBox always resets the focus to its
1402 * combo/edit counterpart */
1409 /***********************************************************************
1412 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1414 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
, LPARAM lParam
)
1416 HWND hWnd
= lphc
->self
;
1417 UINT id
= (UINT
)GetWindowLongPtrW( hWnd
, GWLP_ID
);
1419 TRACE("[%p]: ownerdraw op %04x\n", lphc
->self
, msg
);
1425 DELETEITEMSTRUCT
*lpIS
= (DELETEITEMSTRUCT
*)lParam
;
1426 lpIS
->CtlType
= ODT_COMBOBOX
;
1428 lpIS
->hwndItem
= hWnd
;
1433 DRAWITEMSTRUCT
*lpIS
= (DRAWITEMSTRUCT
*)lParam
;
1434 lpIS
->CtlType
= ODT_COMBOBOX
;
1436 lpIS
->hwndItem
= hWnd
;
1439 case WM_COMPAREITEM
:
1441 COMPAREITEMSTRUCT
*lpIS
= (COMPAREITEMSTRUCT
*)lParam
;
1442 lpIS
->CtlType
= ODT_COMBOBOX
;
1444 lpIS
->hwndItem
= hWnd
;
1447 case WM_MEASUREITEM
:
1449 MEASUREITEMSTRUCT
*lpIS
= (MEASUREITEMSTRUCT
*)lParam
;
1450 lpIS
->CtlType
= ODT_COMBOBOX
;
1455 return SendMessageW(lphc
->owner
, msg
, id
, lParam
);
1459 /***********************************************************************
1462 static LRESULT
COMBO_GetTextW( LPHEADCOMBO lphc
, INT count
, LPWSTR buf
)
1466 if( lphc
->wState
& CBF_EDIT
)
1467 return SendMessageW( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1469 /* get it from the listbox */
1471 if (!count
|| !buf
) return 0;
1472 if( lphc
->hWndLBox
)
1474 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1475 if (idx
== LB_ERR
) goto error
;
1476 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1477 if (length
== LB_ERR
) goto error
;
1479 /* 'length' is without the terminating character */
1480 if (length
>= count
)
1482 LPWSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
1483 if (!lpBuffer
) goto error
;
1484 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1486 /* truncate if buffer is too short */
1487 if (length
!= LB_ERR
)
1489 lstrcpynW( buf
, lpBuffer
, count
);
1492 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1494 else length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1496 if (length
== LB_ERR
) return 0;
1500 error
: /* error - truncate string, return zero */
1506 /***********************************************************************
1509 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1510 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1512 static LRESULT
COMBO_GetTextA( LPHEADCOMBO lphc
, INT count
, LPSTR buf
)
1516 if( lphc
->wState
& CBF_EDIT
)
1517 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1519 /* get it from the listbox */
1521 if (!count
|| !buf
) return 0;
1522 if( lphc
->hWndLBox
)
1524 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1525 if (idx
== LB_ERR
) goto error
;
1526 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1527 if (length
== LB_ERR
) goto error
;
1529 /* 'length' is without the terminating character */
1530 if (length
>= count
)
1532 LPSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) );
1533 if (!lpBuffer
) goto error
;
1534 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1536 /* truncate if buffer is too short */
1537 if (length
!= LB_ERR
)
1539 lstrcpynA( buf
, lpBuffer
, count
);
1542 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1544 else length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1546 if (length
== LB_ERR
) return 0;
1550 error
: /* error - truncate string, return zero */
1556 /***********************************************************************
1559 * This function sets window positions according to the updated
1560 * component placement struct.
1562 static void CBResetPos(
1568 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1570 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1571 * sizing messages */
1573 if( lphc
->wState
& CBF_EDIT
)
1574 SetWindowPos( lphc
->hWndEdit
, 0,
1575 rectEdit
->left
, rectEdit
->top
,
1576 rectEdit
->right
- rectEdit
->left
,
1577 rectEdit
->bottom
- rectEdit
->top
,
1578 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1580 SetWindowPos( lphc
->hWndLBox
, 0,
1581 rectLB
->left
, rectLB
->top
,
1582 rectLB
->right
- rectLB
->left
,
1583 rectLB
->bottom
- rectLB
->top
,
1584 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1588 if( lphc
->wState
& CBF_DROPPED
)
1590 lphc
->wState
&= ~CBF_DROPPED
;
1591 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1594 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1595 RedrawWindow( lphc
->self
, NULL
, 0,
1596 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1601 /***********************************************************************
1604 static void COMBO_Size( LPHEADCOMBO lphc
)
1606 CBCalcPlacement(lphc
->self
,
1610 &lphc
->droppedRect
);
1612 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1616 /***********************************************************************
1619 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1624 lphc
->hFont
= hFont
;
1627 * Propagate to owned windows.
1629 if( lphc
->wState
& CBF_EDIT
)
1630 SendMessageW(lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1631 SendMessageW(lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1634 * Redo the layout of the control.
1636 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1638 CBCalcPlacement(lphc
->self
,
1642 &lphc
->droppedRect
);
1644 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1648 CBForceDummyResize(lphc
);
1653 /***********************************************************************
1654 * COMBO_SetItemHeight
1656 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1658 LRESULT lRet
= CB_ERR
;
1660 if( index
== -1 ) /* set text field height */
1662 if( height
< 32768 )
1664 lphc
->editHeight
= height
;
1667 * Redo the layout of the control.
1669 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1671 CBCalcPlacement(lphc
->self
,
1675 &lphc
->droppedRect
);
1677 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1681 CBForceDummyResize(lphc
);
1687 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1688 lRet
= SendMessageW(lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1689 (WPARAM
)index
, (LPARAM
)height
);
1693 /***********************************************************************
1694 * COMBO_SelectString
1696 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPARAM pText
, BOOL unicode
)
1698 INT index
= unicode
? SendMessageW(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
) :
1699 SendMessageA(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
);
1702 if( lphc
->wState
& CBF_EDIT
)
1703 CBUpdateEdit( lphc
, index
);
1706 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1709 return (LRESULT
)index
;
1712 /***********************************************************************
1715 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1719 HWND hWnd
= lphc
->self
;
1721 pt
.x
= LOWORD(lParam
);
1722 pt
.y
= HIWORD(lParam
);
1723 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1725 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1726 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1728 lphc
->wState
|= CBF_BUTTONDOWN
;
1729 if( lphc
->wState
& CBF_DROPPED
)
1731 /* got a click to cancel selection */
1733 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1734 CBRollUp( lphc
, TRUE
, FALSE
);
1735 if( !IsWindow( hWnd
) ) return;
1737 if( lphc
->wState
& CBF_CAPTURE
)
1739 lphc
->wState
&= ~CBF_CAPTURE
;
1745 /* drop down the listbox and start tracking */
1747 lphc
->wState
|= CBF_CAPTURE
;
1751 if( bButton
) CBRepaintButton( lphc
);
1755 /***********************************************************************
1758 * Release capture and stop tracking if needed.
1760 static void COMBO_LButtonUp( LPHEADCOMBO lphc
)
1762 if( lphc
->wState
& CBF_CAPTURE
)
1764 lphc
->wState
&= ~CBF_CAPTURE
;
1765 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1767 INT index
= CBUpdateLBox( lphc
, TRUE
);
1768 /* Update edit only if item is in the list */
1771 lphc
->wState
|= CBF_NOLBSELECT
;
1772 CBUpdateEdit( lphc
, index
);
1773 lphc
->wState
&= ~CBF_NOLBSELECT
;
1777 SetCapture(lphc
->hWndLBox
);
1780 if( lphc
->wState
& CBF_BUTTONDOWN
)
1782 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1783 CBRepaintButton( lphc
);
1787 /***********************************************************************
1790 * Two things to do - track combo button and release capture when
1791 * pointer goes into the listbox.
1793 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1798 pt
.x
= LOWORD(lParam
);
1799 pt
.y
= HIWORD(lParam
);
1801 if( lphc
->wState
& CBF_BUTTONDOWN
)
1805 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1809 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1810 CBRepaintButton( lphc
);
1814 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1815 MapWindowPoints( lphc
->self
, lphc
->hWndLBox
, &pt
, 1 );
1816 if( PtInRect(&lbRect
, pt
) )
1818 lphc
->wState
&= ~CBF_CAPTURE
;
1820 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
, TRUE
);
1822 /* hand over pointer tracking */
1823 SendMessageW(lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1827 static LRESULT
COMBO_GetComboBoxInfo(LPHEADCOMBO lphc
, COMBOBOXINFO
*pcbi
)
1829 if (!pcbi
|| (pcbi
->cbSize
< sizeof(COMBOBOXINFO
)))
1832 pcbi
->rcItem
= lphc
->textRect
;
1833 pcbi
->rcButton
= lphc
->buttonRect
;
1834 pcbi
->stateButton
= 0;
1835 if (lphc
->wState
& CBF_BUTTONDOWN
)
1836 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
1837 if (IsRectEmpty(&lphc
->buttonRect
))
1838 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
1839 pcbi
->hwndCombo
= lphc
->self
;
1840 pcbi
->hwndItem
= lphc
->hWndEdit
;
1841 pcbi
->hwndList
= lphc
->hWndLBox
;
1845 /***********************************************************************
1846 * ComboWndProc_common
1848 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1850 static LRESULT
ComboWndProc_common( HWND hwnd
, UINT message
,
1851 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1853 LPHEADCOMBO lphc
= (LPHEADCOMBO
)GetWindowLongPtrW( hwnd
, 0 );
1855 //TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1856 // hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1858 if( lphc
|| message
== WM_NCCREATE
)
1862 /* System messages */
1866 LONG style
= unicode
? ((LPCREATESTRUCTW
)lParam
)->style
:
1867 ((LPCREATESTRUCTA
)lParam
)->style
;
1868 return COMBO_NCCreate(hwnd
, style
);
1871 COMBO_NCDestroy(lphc
);
1872 break;/* -> DefWindowProc */
1880 hwndParent
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
1881 style
= ((LPCREATESTRUCTW
)lParam
)->style
;
1885 hwndParent
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
1886 style
= ((LPCREATESTRUCTA
)lParam
)->style
;
1888 return COMBO_Create(hwnd
, lphc
, hwndParent
, style
, unicode
);
1891 case WM_PRINTCLIENT
:
1892 if (lParam
& PRF_ERASEBKGND
)
1893 COMBO_EraseBackground(hwnd
, lphc
, (HDC
)wParam
);
1897 /* wParam may contain a valid HDC! */
1898 return COMBO_Paint(lphc
, (HDC
)wParam
);
1900 return COMBO_EraseBackground(hwnd
, lphc
, (HDC
)wParam
);
1903 LRESULT result
= DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1904 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1906 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1908 if ((vk
== VK_RETURN
|| vk
== VK_ESCAPE
) && (lphc
->wState
& CBF_DROPPED
))
1909 result
|= DLGC_WANTMESSAGE
;
1913 case WM_WINDOWPOSCHANGING
:
1914 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1915 case WM_WINDOWPOSCHANGED
:
1916 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1917 * In that case, the Combobox itself will not be resized, so we won't
1918 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1923 if( lphc
->hWndLBox
&&
1924 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
);
1927 COMBO_Font( lphc
, (HFONT
)wParam
, (BOOL
)lParam
);
1930 return (LRESULT
)lphc
->hFont
;
1932 if( lphc
->wState
& CBF_EDIT
)
1933 SetFocus( lphc
->hWndEdit
);
1935 COMBO_SetFocus( lphc
);
1940 HWND hwndFocus
= (HWND
)wParam
;
1942 HWND hwndFocus
= WIN_GetFullHandle( (HWND
)wParam
);
1945 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1946 COMBO_KillFocus( lphc
);
1951 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1953 return COMBO_Command( lphc
, wParam
, WIN_GetFullHandle( (HWND
)lParam
) );
1956 return unicode
? COMBO_GetTextW( lphc
, wParam
, (LPWSTR
)lParam
)
1957 : COMBO_GetTextA( lphc
, wParam
, (LPSTR
)lParam
);
1959 case WM_GETTEXTLENGTH
:
1961 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1963 int j
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1964 if (j
== -1) return 0;
1965 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0) :
1966 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1968 else if( lphc
->wState
& CBF_EDIT
)
1971 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1972 ret
= unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1973 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1974 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1981 if( lphc
->wState
& CBF_EDIT
)
1983 return unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1984 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1990 case WM_COMPAREITEM
:
1991 case WM_MEASUREITEM
:
1992 return COMBO_ItemOp(lphc
, message
, lParam
);
1994 if( lphc
->wState
& CBF_EDIT
)
1995 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
1996 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
1998 /* Force the control to repaint when the enabled state changes. */
1999 InvalidateRect(lphc
->self
, NULL
, TRUE
);
2003 lphc
->wState
&= ~CBF_NOREDRAW
;
2005 lphc
->wState
|= CBF_NOREDRAW
;
2007 if( lphc
->wState
& CBF_EDIT
)
2008 SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
);
2009 SendMessageW(lphc
->hWndLBox
, message
, wParam
, lParam
);
2012 if( KEYDATA_ALT
& HIWORD(lParam
) )
2013 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
2014 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2023 if ((wParam
== VK_RETURN
|| wParam
== VK_ESCAPE
) &&
2024 (lphc
->wState
& CBF_DROPPED
))
2026 CBRollUp( lphc
, wParam
== VK_RETURN
, FALSE
);
2029 else if ((wParam
== VK_F4
) && !(lphc
->wState
& CBF_EUI
))
2031 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2035 if( lphc
->wState
& CBF_EDIT
)
2036 hwndTarget
= lphc
->hWndEdit
;
2038 hwndTarget
= lphc
->hWndLBox
;
2040 return unicode
? SendMessageW(hwndTarget
, message
, wParam
, lParam
) :
2041 SendMessageA(hwndTarget
, message
, wParam
, lParam
);
2043 case WM_LBUTTONDOWN
:
2044 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
);
2045 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
2048 COMBO_LButtonUp( lphc
);
2051 if( lphc
->wState
& CBF_CAPTURE
)
2052 COMBO_MouseMove( lphc
, wParam
, lParam
);
2056 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
2057 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2058 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2060 if (GET_WHEEL_DELTA_WPARAM(wParam
) > 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_UP
, 0);
2061 if (GET_WHEEL_DELTA_WPARAM(wParam
) < 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_DOWN
, 0);
2064 /* Combo messages */
2067 case CB_ADDSTRING16
:
2068 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2073 UINT msg
= LB_ADDSTRING
;
2074 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2075 msg
= LB_ADDSTRING_LOWER
;
2076 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2077 msg
= LB_ADDSTRING_UPPER
;
2078 return SendMessageW(lphc
->hWndLBox
, msg
, 0, lParam
);
2081 case CB_INSERTSTRING16
:
2082 wParam
= (INT
)(INT16
)wParam
;
2083 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2086 case CB_INSERTSTRING
:
2088 UINT msg
= LB_INSERTSTRING
;
2089 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2090 msg
= LB_INSERTSTRING_LOWER
;
2091 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2092 msg
= LB_INSERTSTRING_UPPER
;
2093 return SendMessageW(lphc
->hWndLBox
, msg
, 0, lParam
);
2096 case CB_DELETESTRING16
:
2098 case CB_DELETESTRING
:
2099 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0) :
2100 SendMessageA(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
2102 case CB_SELECTSTRING16
:
2103 wParam
= (INT
)(INT16
)wParam
;
2104 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2107 case CB_SELECTSTRING
:
2108 return COMBO_SelectString(lphc
, (INT
)wParam
, lParam
, unicode
);
2110 case CB_FINDSTRING16
:
2111 wParam
= (INT
)(INT16
)wParam
;
2112 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2116 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
) :
2117 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
2119 case CB_FINDSTRINGEXACT16
:
2120 wParam
= (INT
)(INT16
)wParam
;
2121 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2124 case CB_FINDSTRINGEXACT
:
2125 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
) :
2126 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
);
2128 case CB_SETITEMHEIGHT16
:
2129 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
2132 case CB_SETITEMHEIGHT
:
2133 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
2135 case CB_GETITEMHEIGHT16
:
2136 wParam
= (INT
)(INT16
)wParam
;
2139 case CB_GETITEMHEIGHT
:
2140 if( (INT
)wParam
>= 0 ) /* listbox item */
2141 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
2142 return CBGetTextAreaHeight(hwnd
, lphc
);
2144 case CB_RESETCONTENT16
:
2146 case CB_RESETCONTENT
:
2147 SendMessageW(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0);
2148 if( (lphc
->wState
& CBF_EDIT
) && CB_HASSTRINGS(lphc
) )
2150 static const WCHAR empty_stringW
[] = { 0 };
2151 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, (LPARAM
)empty_stringW
);
2154 InvalidateRect(lphc
->self
, NULL
, TRUE
);
2156 case CB_INITSTORAGE
:
2157 return SendMessageW(lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
2158 case CB_GETHORIZONTALEXTENT
:
2159 return SendMessageW(lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
2160 case CB_SETHORIZONTALEXTENT
:
2161 return SendMessageW(lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
2162 case CB_GETTOPINDEX
:
2163 return SendMessageW(lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2165 return SendMessageW(lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2167 return SendMessageW(lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2168 case CB_GETDROPPEDWIDTH
:
2169 if( lphc
->droppedWidth
)
2170 return lphc
->droppedWidth
;
2171 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2172 case CB_SETDROPPEDWIDTH
:
2173 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2174 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2177 case CB_GETDROPPEDCONTROLRECT16
:
2178 lParam
= (LPARAM
)MapSL(lParam
);
2182 CBGetDroppedControlRect( lphc
, &r
);
2183 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2187 case CB_GETDROPPEDCONTROLRECT
:
2188 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2191 case CB_GETDROPPEDSTATE16
:
2193 case CB_GETDROPPEDSTATE
:
2194 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2197 return SendMessageA(lphc
->hWndLBox
, LB_DIR16
, wParam
, lParam
);
2200 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
) :
2201 SendMessageA(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
);
2204 case CB_SHOWDROPDOWN16
:
2206 case CB_SHOWDROPDOWN
:
2207 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2211 if( !(lphc
->wState
& CBF_DROPPED
) )
2215 if( lphc
->wState
& CBF_DROPPED
)
2216 CBRollUp( lphc
, FALSE
, TRUE
);
2223 return SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2225 case CB_GETCURSEL16
:
2228 return SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2230 case CB_SETCURSEL16
:
2231 wParam
= (INT
)(INT16
)wParam
;
2235 lParam
= SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2237 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, wParam
, 0);
2239 /* no LBN_SELCHANGE in this case, update manually */
2240 if( lphc
->wState
& CBF_EDIT
)
2241 CBUpdateEdit( lphc
, (INT
)wParam
);
2243 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2244 lphc
->wState
&= ~CBF_SELCHANGE
;
2247 case CB_GETLBTEXT16
:
2248 wParam
= (INT
)(INT16
)wParam
;
2249 lParam
= (LPARAM
)MapSL(lParam
);
2253 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
) :
2254 SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2256 case CB_GETLBTEXTLEN16
:
2257 wParam
= (INT
)(INT16
)wParam
;
2260 case CB_GETLBTEXTLEN
:
2261 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0) :
2262 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2264 case CB_GETITEMDATA16
:
2265 wParam
= (INT
)(INT16
)wParam
;
2268 case CB_GETITEMDATA
:
2269 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2271 case CB_SETITEMDATA16
:
2272 wParam
= (INT
)(INT16
)wParam
;
2275 case CB_SETITEMDATA
:
2276 return SendMessageW(lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2278 case CB_GETEDITSEL16
:
2279 wParam
= lParam
= 0; /* just in case */
2283 /* Edit checks passed parameters itself */
2284 if( lphc
->wState
& CBF_EDIT
)
2285 return SendMessageW(lphc
->hWndEdit
, EM_GETSEL
, wParam
, lParam
);
2288 case CB_SETEDITSEL16
:
2291 if( lphc
->wState
& CBF_EDIT
)
2292 return SendMessageW(lphc
->hWndEdit
, EM_SETSEL
,
2293 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2296 case CB_SETEXTENDEDUI16
:
2298 case CB_SETEXTENDEDUI
:
2299 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2302 lphc
->wState
|= CBF_EUI
;
2303 else lphc
->wState
&= ~CBF_EUI
;
2306 case CB_GETEXTENDEDUI16
:
2308 case CB_GETEXTENDEDUI
:
2309 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2310 case CB_GETCOMBOBOXINFO
:
2311 return COMBO_GetComboBoxInfo(lphc
, (COMBOBOXINFO
*)lParam
);
2314 if (message
>= WM_USER
)
2315 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2316 message
- WM_USER
, wParam
, lParam
);
2319 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2320 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2323 /***********************************************************************
2326 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2329 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2331 if (!IsWindow(hwnd
)) return 0;
2332 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
2335 /***********************************************************************
2338 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2340 if (!IsWindow(hwnd
)) return 0;
2341 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
2344 /*************************************************************************
2345 * GetComboBoxInfo (USER32.@)
2347 BOOL WINAPI
GetComboBoxInfo(HWND hwndCombo
, /* [in] handle to combo box */
2348 PCOMBOBOXINFO pcbi
/* [in/out] combo box information */)
2350 return SendMessageW(hwndCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
);