4 * Copyright 1997 Alex Korobka
6 * FIXME: roll up in Netscape 3.01.
14 #include "wine/winuser16.h"
21 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(combo
)
26 /* bits in the dwKeyData */
27 #define KEYDATA_ALT 0x2000
28 #define KEYDATA_PREVSTATE 0x4000
31 * Additional combo box definitions
34 #define CB_GETPTR( wnd ) (*(LPHEADCOMBO*)((wnd)->wExtra))
35 #define CB_NOTIFY( lphc, code ) \
36 (SendMessageA( (lphc)->owner, WM_COMMAND, \
37 MAKEWPARAM((lphc)->self->wIDmenu, (code)), (lphc)->self->hwndSelf))
38 #define CB_GETEDITTEXTLENGTH( lphc ) \
39 (SendMessageA( (lphc)->hWndEdit, WM_GETTEXTLENGTH, 0, 0 ))
41 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
46 static HBITMAP hComboBmp
= 0;
47 static UINT CBitHeight
, CBitWidth
;
50 * Look and feel dependant "constants"
53 #define COMBO_YBORDERGAP 5
54 #define COMBO_XBORDERSIZE() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 2 )
55 #define COMBO_YBORDERSIZE() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 2 )
56 #define COMBO_EDITBUTTONSPACE() ( (TWEAK_WineLook == WIN31_LOOK) ? 8 : 0 )
57 #define EDIT_CONTROL_PADDING() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 1 )
59 /***********************************************************************
62 * Load combo button bitmap.
64 static BOOL
COMBO_Init()
68 if( hComboBmp
) return TRUE
;
69 if( (hDC
= CreateCompatibleDC(0)) )
72 if( (hComboBmp
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_COMBO
))) )
78 GetObjectA( hComboBmp
, sizeof(bm
), &bm
);
79 CBitHeight
= bm
.bmHeight
;
80 CBitWidth
= bm
.bmWidth
;
82 TRACE("combo bitmap [%i,%i]\n", CBitWidth
, CBitHeight
);
84 hPrevB
= SelectObject16( hDC
, hComboBmp
);
85 SetRect( &r
, 0, 0, CBitWidth
, CBitHeight
);
86 InvertRect( hDC
, &r
);
87 SelectObject( hDC
, hPrevB
);
96 /***********************************************************************
99 static LRESULT
COMBO_NCCreate(WND
* wnd
, LPARAM lParam
)
103 if ( wnd
&& COMBO_Init() &&
104 (lphc
= HeapAlloc(GetProcessHeap(), 0, sizeof(HEADCOMBO
))) )
106 LPCREATESTRUCTA lpcs
= (CREATESTRUCTA
*)lParam
;
108 memset( lphc
, 0, sizeof(HEADCOMBO
) );
109 *(LPHEADCOMBO
*)wnd
->wExtra
= lphc
;
111 /* some braindead apps do try to use scrollbar/border flags */
113 lphc
->dwStyle
= (lpcs
->style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
));
114 wnd
->dwStyle
&= ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
);
117 * We also have to remove the client edge style to make sure
118 * we don't end-up with a non client area.
120 wnd
->dwExStyle
&= ~(WS_EX_CLIENTEDGE
);
122 if( !(lpcs
->style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) )
123 lphc
->dwStyle
|= CBS_HASSTRINGS
;
124 if( !(wnd
->dwExStyle
& WS_EX_NOPARENTNOTIFY
) )
125 lphc
->wState
|= CBF_NOTIFY
;
127 TRACE("[0x%08x], style = %08x\n",
128 (UINT
)lphc
, lphc
->dwStyle
);
130 return (LRESULT
)(UINT
)wnd
->hwndSelf
;
132 return (LRESULT
)FALSE
;
135 /***********************************************************************
138 static LRESULT
COMBO_NCDestroy( LPHEADCOMBO lphc
)
143 WND
* wnd
= lphc
->self
;
145 TRACE("[%04x]: freeing storage\n", CB_HWND(lphc
));
147 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) && lphc
->hWndLBox
)
148 DestroyWindow( lphc
->hWndLBox
);
150 HeapFree( GetProcessHeap(), 0, lphc
);
156 /***********************************************************************
159 * The dummy resize is used for listboxes that have a popup to trigger
160 * a re-arranging of the contents of the combobox and the recalculation
161 * of the size of the "real" control window.
163 static void CBForceDummyResize(
168 GetWindowRect(CB_HWND(lphc
), &windowRect
);
171 * We have to be careful, resizing a combobox also has the meaning that the
172 * dropped rect will be resized. In this case, we want to trigger a resize
173 * to recalculate layout but we don't want to change the dropped rectangle
174 * So, we add the size of the dropped rectangle to the size of the control.
175 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
178 SetWindowPos( CB_HWND(lphc
),
181 windowRect
.right
- windowRect
.left
,
182 windowRect
.bottom
- windowRect
.top
+
183 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
184 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
187 /***********************************************************************
188 * CBGetTextAreaHeight
190 * This method will calculate the height of the text area of the
192 * The height of the text area is set in two ways.
193 * It can be set explicitely through a combobox message of through a
194 * WM_MEASUREITEM callback.
195 * If this is not the case, the height is set to 13 dialog units.
196 * This height was determined through experimentation.
198 static INT
CBGetTextAreaHeight(
204 if( lphc
->editHeight
) /* explicitly set height */
206 iTextItemHeight
= lphc
->editHeight
;
211 HDC hDC
= GetDC(hwnd
);
216 hPrevFont
= SelectObject( hDC
, lphc
->hFont
);
218 GetTextMetricsA(hDC
, &tm
);
220 baseUnitY
= tm
.tmHeight
;
223 SelectObject( hDC
, hPrevFont
);
225 ReleaseDC(hwnd
, hDC
);
227 iTextItemHeight
= ((13 * baseUnitY
) / 8);
230 * This "formula" calculates the height of the complete control.
231 * To calculate the height of the text area, we have to remove the
234 iTextItemHeight
-= 2*COMBO_YBORDERSIZE();
238 * Check the ownerdraw case if we haven't asked the parent the size
241 if ( CB_OWNERDRAWN(lphc
) &&
242 (lphc
->wState
& CBF_MEASUREITEM
) )
244 MEASUREITEMSTRUCT measureItem
;
246 INT originalItemHeight
= iTextItemHeight
;
249 * We use the client rect for the width of the item.
251 GetClientRect(hwnd
, &clientRect
);
253 lphc
->wState
&= ~CBF_MEASUREITEM
;
256 * Send a first one to measure the size of the text area
258 measureItem
.CtlType
= ODT_COMBOBOX
;
259 measureItem
.CtlID
= lphc
->self
->wIDmenu
;
260 measureItem
.itemID
= -1;
261 measureItem
.itemWidth
= clientRect
.right
;
262 measureItem
.itemHeight
= iTextItemHeight
- 6; /* ownerdrawn cb is taller */
263 measureItem
.itemData
= 0;
264 SendMessageA(lphc
->owner
, WM_MEASUREITEM
,
265 (WPARAM
)measureItem
.CtlID
, (LPARAM
)&measureItem
);
266 iTextItemHeight
= 6 + measureItem
.itemHeight
;
269 * Send a second one in the case of a fixed ownerdraw list to calculate the
270 * size of the list items. (we basically do this on behalf of the listbox)
272 if (lphc
->dwStyle
& CBS_OWNERDRAWFIXED
)
274 measureItem
.CtlType
= ODT_COMBOBOX
;
275 measureItem
.CtlID
= lphc
->self
->wIDmenu
;
276 measureItem
.itemID
= 0;
277 measureItem
.itemWidth
= clientRect
.right
;
278 measureItem
.itemHeight
= originalItemHeight
;
279 measureItem
.itemData
= 0;
280 SendMessageA(lphc
->owner
, WM_MEASUREITEM
,
281 (WPARAM
)measureItem
.CtlID
, (LPARAM
)&measureItem
);
282 lphc
->fixedOwnerDrawHeight
= measureItem
.itemHeight
;
286 * Keep the size for the next time
288 lphc
->editHeight
= iTextItemHeight
;
291 return iTextItemHeight
;
295 /***********************************************************************
298 * Set up component coordinates given valid lphc->RectCombo.
300 static void CBCalcPlacement(
308 * Again, start with the client rectangle.
310 GetClientRect(hwnd
, lprEdit
);
315 InflateRect(lprEdit
, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
318 * Chop off the bottom part to fit with the height of the text area.
320 lprEdit
->bottom
= lprEdit
->top
+ CBGetTextAreaHeight(hwnd
, lphc
);
323 * The button starts the same vertical position as the text area.
325 CopyRect(lprButton
, lprEdit
);
328 * If the combobox is "simple" there is no button.
330 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
331 lprButton
->left
= lprButton
->right
= lprButton
->bottom
= 0;
335 * Let's assume the combobox button is the same width as the
337 * size the button horizontally and cut-off the text area.
339 lprButton
->left
= lprButton
->right
- GetSystemMetrics(SM_CXVSCROLL
);
340 lprEdit
->right
= lprButton
->left
;
344 * In the case of a dropdown, there is an additional spacing between the
345 * text area and the button.
347 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
349 lprEdit
->right
-= COMBO_EDITBUTTONSPACE();
353 * If we have an edit control, we space it away from the borders slightly.
355 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
357 InflateRect(lprEdit
, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
361 * Adjust the size of the listbox popup.
363 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
366 * Use the client rectangle to initialize the listbox rectangle
368 GetClientRect(hwnd
, lprLB
);
371 * Then, chop-off the top part.
373 lprLB
->top
= lprEdit
->bottom
+ COMBO_YBORDERSIZE();
378 * Make sure the dropped width is as large as the combobox itself.
380 if (lphc
->droppedWidth
< (lprButton
->right
+ COMBO_XBORDERSIZE()))
382 lprLB
->right
= lprLB
->left
+ (lprButton
->right
+ COMBO_XBORDERSIZE());
385 * In the case of a dropdown, the popup listbox is offset to the right.
386 * so, we want to make sure it's flush with the right side of the
389 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
390 lprLB
->right
-= COMBO_EDITBUTTONSPACE();
393 lprLB
->right
= lprLB
->left
+ lphc
->droppedWidth
;
396 TRACE("\ttext\t= (%i,%i-%i,%i)\n",
397 lprEdit
->left
, lprEdit
->top
, lprEdit
->right
, lprEdit
->bottom
);
399 TRACE("\tbutton\t= (%i,%i-%i,%i)\n",
400 lprButton
->left
, lprButton
->top
, lprButton
->right
, lprButton
->bottom
);
402 TRACE("\tlbox\t= (%i,%i-%i,%i)\n",
403 lprLB
->left
, lprLB
->top
, lprLB
->right
, lprLB
->bottom
);
406 /***********************************************************************
407 * CBGetDroppedControlRect
409 static void CBGetDroppedControlRect( LPHEADCOMBO lphc
, LPRECT lpRect
)
411 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
412 of the combo box and the lower right corner of the listbox */
414 GetWindowRect(lphc
->self
->hwndSelf
, lpRect
);
416 lpRect
->right
= lpRect
->left
+ lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
417 lpRect
->bottom
= lpRect
->top
+ lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
421 /***********************************************************************
422 * COMBO_WindowPosChanging
424 static LRESULT
COMBO_WindowPosChanging(
427 WINDOWPOS
* posChanging
)
430 * We need to override the WM_WINDOWPOSCHANGING method to handle all
431 * the non-simple comboboxes. The problem is that those controls are
432 * always the same height. We have to make sure they are not resized
435 if ( ( CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
436 ((posChanging
->flags
& SWP_NOSIZE
) == 0) )
440 newComboHeight
= CBGetTextAreaHeight(hwnd
,lphc
) +
441 2*COMBO_YBORDERSIZE();
444 * Resizing a combobox has another side effect, it resizes the dropped
445 * rectangle as well. However, it does it only if the new height for the
446 * combobox is different than the height it should have. In other words,
447 * if the application resizing the combobox only had the intention to resize
448 * the actual control, for example, to do the layout of a dialog that is
449 * resized, the height of the dropdown is not changed.
451 if (posChanging
->cy
!= newComboHeight
)
453 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
+ posChanging
->cy
- newComboHeight
;
455 posChanging
->cy
= newComboHeight
;
462 /***********************************************************************
465 static LRESULT
COMBO_Create( LPHEADCOMBO lphc
, WND
* wnd
, LPARAM lParam
)
467 static char clbName
[] = "ComboLBox";
468 static char editName
[] = "Edit";
470 LPCREATESTRUCTA lpcs
= (CREATESTRUCTA
*)lParam
;
472 if( !CB_GETTYPE(lphc
) ) lphc
->dwStyle
|= CBS_SIMPLE
;
473 else if( CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
) lphc
->wState
|= CBF_EDIT
;
476 lphc
->owner
= lpcs
->hwndParent
;
479 * The item height and dropped width are not set when the control
482 lphc
->droppedWidth
= lphc
->editHeight
= 0;
485 * The first time we go through, we want to measure the ownerdraw item
487 lphc
->wState
|= CBF_MEASUREITEM
;
489 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
491 if( lphc
->owner
|| !(lpcs
->style
& WS_VISIBLE
) )
497 * Initialize the dropped rect to the size of the client area of the
498 * control and then, force all the areas of the combobox to be
501 GetClientRect( wnd
->hwndSelf
, &lphc
->droppedRect
);
503 CBCalcPlacement(wnd
->hwndSelf
,
507 &lphc
->droppedRect
);
510 * Adjust the position of the popup listbox if it's necessary
512 if ( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
514 lphc
->droppedRect
.top
= lphc
->textRect
.bottom
+ COMBO_YBORDERSIZE();
517 * If it's a dropdown, the listbox is offset
519 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
520 lphc
->droppedRect
.left
+= COMBO_EDITBUTTONSPACE();
522 ClientToScreen(wnd
->hwndSelf
, (LPPOINT
)&lphc
->droppedRect
);
523 ClientToScreen(wnd
->hwndSelf
, (LPPOINT
)&lphc
->droppedRect
.right
);
526 /* create listbox popup */
528 lbeStyle
= (LBS_NOTIFY
| WS_BORDER
| WS_CLIPSIBLINGS
) |
529 (lpcs
->style
& (WS_VSCROLL
| CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
));
531 if( lphc
->dwStyle
& CBS_SORT
)
532 lbeStyle
|= LBS_SORT
;
533 if( lphc
->dwStyle
& CBS_HASSTRINGS
)
534 lbeStyle
|= LBS_HASSTRINGS
;
535 if( lphc
->dwStyle
& CBS_NOINTEGRALHEIGHT
)
536 lbeStyle
|= LBS_NOINTEGRALHEIGHT
;
537 if( lphc
->dwStyle
& CBS_DISABLENOSCROLL
)
538 lbeStyle
|= LBS_DISABLENOSCROLL
;
540 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
) /* child listbox */
542 lbeStyle
|= WS_CHILD
| WS_VISIBLE
;
545 * In win 95 look n feel, the listbox in the simple combobox has
546 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
548 if (TWEAK_WineLook
> WIN31_LOOK
)
550 lbeStyle
&= ~WS_BORDER
;
551 lbeExStyle
|= WS_EX_CLIENTEDGE
;
554 else /* popup listbox */
555 lbeStyle
|= WS_POPUP
;
557 /* Dropdown ComboLBox is not a child window and we cannot pass
558 * ID_CB_LISTBOX directly because it will be treated as a menu handle.
560 lphc
->hWndLBox
= CreateWindowExA(lbeExStyle
,
564 lphc
->droppedRect
.left
,
565 lphc
->droppedRect
.top
,
566 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
567 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
568 lphc
->self
->hwndSelf
,
569 (lphc
->dwStyle
& CBS_DROPDOWN
)? (HMENU
)0 : (HMENU
)ID_CB_LISTBOX
,
570 lphc
->self
->hInstance
,
574 * The ComboLBox is a strange little beast (when it's not a CBS_SIMPLE)...
575 * It's a popup window but, when you get the window style, you get WS_CHILD.
576 * When created, it's parent is the combobox but, when you ask for it's parent
577 * after that, you're supposed to get the desktop. (see MFC code function
579 * To achieve this in Wine, we have to create it as a popup and change
580 * it's style to child after the creation.
582 if ( (lphc
->hWndLBox
!= 0) &&
583 (CB_GETTYPE(lphc
) != CBS_SIMPLE
) )
585 SetWindowLongA(lphc
->hWndLBox
,
587 (GetWindowLongA(lphc
->hWndLBox
, GWL_STYLE
) | WS_CHILD
) & ~WS_POPUP
);
593 lbeStyle
= WS_CHILD
| WS_VISIBLE
| ES_NOHIDESEL
| ES_LEFT
;
596 * In Win95 look, the border fo the edit control is
597 * provided by the combobox
599 if (TWEAK_WineLook
== WIN31_LOOK
)
600 lbeStyle
|= WS_BORDER
;
602 if( lphc
->wState
& CBF_EDIT
)
604 if( lphc
->dwStyle
& CBS_OEMCONVERT
)
605 lbeStyle
|= ES_OEMCONVERT
;
606 if( lphc
->dwStyle
& CBS_AUTOHSCROLL
)
607 lbeStyle
|= ES_AUTOHSCROLL
;
608 if( lphc
->dwStyle
& CBS_LOWERCASE
)
609 lbeStyle
|= ES_LOWERCASE
;
610 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
611 lbeStyle
|= ES_UPPERCASE
;
613 lphc
->hWndEdit
= CreateWindowExA(0,
617 lphc
->textRect
.left
, lphc
->textRect
.top
,
618 lphc
->textRect
.right
- lphc
->textRect
.left
,
619 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
620 lphc
->self
->hwndSelf
,
622 lphc
->self
->hInstance
,
625 if( !lphc
->hWndEdit
)
632 * If the combo is a dropdown, we must resize the control to fit only
633 * the text area and button. To do this, we send a dummy resize and the
634 * WM_WINDOWPOSCHANGING message will take care of setting the height for
637 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
639 CBForceDummyResize(lphc
);
642 TRACE("init done\n");
643 return wnd
->hwndSelf
;
645 ERR("edit control failure.\n");
646 } else ERR("listbox failure.\n");
647 } else ERR("no owner for visible combo.\n");
649 /* CreateWindow() will send WM_NCDESTROY to cleanup */
654 /***********************************************************************
657 * Paint combo button (normal, pressed, and disabled states).
659 static void CBPaintButton(
664 if( lphc
->wState
& CBF_NOREDRAW
)
667 if (TWEAK_WineLook
== WIN31_LOOK
)
673 COLORREF oldTextColor
, oldBkColor
;
676 hPrevBrush
= SelectObject(hdc
, GetSysColorBrush(COLOR_BTNFACE
));
679 * Draw the button background
684 rectButton
.right
-rectButton
.left
,
685 rectButton
.bottom
-rectButton
.top
,
688 if( (bBool
= lphc
->wState
& CBF_BUTTONDOWN
) )
690 DrawEdge( hdc
, &rectButton
, EDGE_SUNKEN
, BF_RECT
);
694 DrawEdge( hdc
, &rectButton
, EDGE_RAISED
, BF_RECT
);
698 * Remove the edge of the button from the rectangle
699 * and calculate the position of the bitmap.
701 InflateRect( &rectButton
, -2, -2);
703 x
= (rectButton
.left
+ rectButton
.right
- CBitWidth
) >> 1;
704 y
= (rectButton
.top
+ rectButton
.bottom
- CBitHeight
) >> 1;
707 hMemDC
= CreateCompatibleDC( hdc
);
708 SelectObject( hMemDC
, hComboBmp
);
709 oldTextColor
= SetTextColor( hdc
, GetSysColor(COLOR_BTNFACE
) );
710 oldBkColor
= SetBkColor( hdc
, CB_DISABLED(lphc
) ? RGB(128,128,128) :
712 BitBlt( hdc
, x
, y
, CBitWidth
, CBitHeight
, hMemDC
, 0, 0, SRCCOPY
);
713 SetBkColor( hdc
, oldBkColor
);
714 SetTextColor( hdc
, oldTextColor
);
716 SelectObject( hdc
, hPrevBrush
);
720 UINT buttonState
= DFCS_SCROLLCOMBOBOX
;
722 if (lphc
->wState
& CBF_BUTTONDOWN
)
724 buttonState
|= DFCS_PUSHED
;
727 if (CB_DISABLED(lphc
))
729 buttonState
|= DFCS_INACTIVE
;
732 DrawFrameControl(hdc
,
739 /***********************************************************************
742 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
744 static void CBPaintText(
752 if( lphc
->wState
& CBF_NOREDRAW
) return;
754 /* follow Windows combobox that sends a bunch of text
755 * inquiries to its listbox while processing WM_PAINT. */
757 if( (id
= SendMessageA(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0) ) != LB_ERR
)
759 size
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, id
, 0);
760 if( (pText
= HeapAlloc( GetProcessHeap(), 0, size
+ 1)) )
762 SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
, (WPARAM
)id
, (LPARAM
)pText
);
763 pText
[size
] = '\0'; /* just in case */
767 if( lphc
->wState
& CBF_EDIT
)
769 if( CB_HASSTRINGS(lphc
) ) SetWindowTextA( lphc
->hWndEdit
, pText
? pText
: "" );
770 if( lphc
->wState
& CBF_FOCUSED
)
771 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
773 else /* paint text field ourselves */
776 HFONT hPrevFont
= (lphc
->hFont
) ? SelectObject(hdc
, lphc
->hFont
) : 0;
779 * Give ourselves some space.
781 InflateRect( &rectEdit
, -1, -1 );
783 if ( (lphc
->wState
& CBF_FOCUSED
) &&
784 !(lphc
->wState
& CBF_DROPPED
) )
788 FillRect( hdc
, &rectEdit
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
789 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
790 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
791 itemState
= ODS_SELECTED
| ODS_FOCUS
;
796 if( CB_OWNERDRAWN(lphc
) )
802 * Save the current clip region.
803 * To retrieve the clip region, we need to create one "dummy"
806 clipRegion
= CreateRectRgnIndirect(&rectEdit
);
808 if (GetClipRgn(hdc
, clipRegion
)!=1)
810 DeleteObject(clipRegion
);
811 clipRegion
=(HRGN
)NULL
;
814 if ( lphc
->self
->dwStyle
& WS_DISABLED
)
815 itemState
|= ODS_DISABLED
;
817 dis
.CtlType
= ODT_COMBOBOX
;
818 dis
.CtlID
= lphc
->self
->wIDmenu
;
819 dis
.hwndItem
= lphc
->self
->hwndSelf
;
820 dis
.itemAction
= ODA_DRAWENTIRE
;
822 dis
.itemState
= itemState
;
824 dis
.rcItem
= rectEdit
;
825 dis
.itemData
= SendMessageA( lphc
->hWndLBox
, LB_GETITEMDATA
,
829 * Clip the DC and have the parent draw the item.
831 IntersectClipRect(hdc
,
832 rectEdit
.left
, rectEdit
.top
,
833 rectEdit
.right
, rectEdit
.bottom
);
835 SendMessageA(lphc
->owner
, WM_DRAWITEM
,
836 lphc
->self
->wIDmenu
, (LPARAM
)&dis
);
839 * Reset the clipping region.
841 SelectClipRgn(hdc
, clipRegion
);
848 ETO_OPAQUE
| ETO_CLIPPED
,
850 pText
? pText
: "" , size
, NULL
);
852 if(lphc
->wState
& CBF_FOCUSED
&& !(lphc
->wState
& CBF_DROPPED
))
853 DrawFocusRect( hdc
, &rectEdit
);
857 SelectObject(hdc
, hPrevFont
);
860 HeapFree( GetProcessHeap(), 0, pText
);
863 /***********************************************************************
866 static void CBPaintBorder(
873 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
875 GetClientRect(hwnd
, &clientRect
);
879 CopyRect(&clientRect
, &lphc
->textRect
);
881 InflateRect(&clientRect
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
882 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
885 DrawEdge(hdc
, &clientRect
, EDGE_SUNKEN
, BF_RECT
);
888 /***********************************************************************
889 * COMBO_PrepareColors
891 * This method will sent the appropriate WM_CTLCOLOR message to
892 * prepare and setup the colors for the combo's DC.
894 * It also returns the brush to use for the background.
896 static HBRUSH
COMBO_PrepareColors(
904 * Get the background brush for this control.
906 if (CB_DISABLED(lphc
))
908 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLORSTATIC
,
909 hDC
, lphc
->self
->hwndSelf
);
912 * We have to change the text color since WM_CTLCOLORSTATIC will
913 * set it to the "enabled" color. This is the same behavior as the
916 SetTextColor(hDC
, GetSysColor(COLOR_GRAYTEXT
));
920 if (lphc
->wState
& CBF_EDIT
)
922 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLOREDIT
,
923 hDC
, lphc
->self
->hwndSelf
);
927 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLORLISTBOX
,
928 hDC
, lphc
->self
->hwndSelf
);
936 hBkgBrush
= GetSysColorBrush(COLOR_WINDOW
);
941 /***********************************************************************
942 * COMBO_EraseBackground
944 static LRESULT
COMBO_EraseBackground(
953 hDC
= (hParamDC
) ? hParamDC
957 * Calculate the area that we want to erase.
959 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
961 GetClientRect(hwnd
, &clientRect
);
965 CopyRect(&clientRect
, &lphc
->textRect
);
967 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
971 * Retrieve the background brush
973 hBkgBrush
= COMBO_PrepareColors(hwnd
, lphc
, hDC
);
975 FillRect(hDC
, &clientRect
, hBkgBrush
);
978 ReleaseDC(hwnd
, hDC
);
983 /***********************************************************************
986 static LRESULT
COMBO_Paint(LPHEADCOMBO lphc
, HDC hParamDC
)
991 hDC
= (hParamDC
) ? hParamDC
992 : BeginPaint( lphc
->self
->hwndSelf
, &ps
);
995 if( hDC
&& !(lphc
->wState
& CBF_NOREDRAW
) )
997 HBRUSH hPrevBrush
, hBkgBrush
;
1000 * Retrieve the background brush and select it in the
1003 hBkgBrush
= COMBO_PrepareColors(lphc
->self
->hwndSelf
, lphc
, hDC
);
1005 hPrevBrush
= SelectObject( hDC
, hBkgBrush
);
1008 * In non 3.1 look, there is a sunken border on the combobox
1010 if (TWEAK_WineLook
!= WIN31_LOOK
)
1012 CBPaintBorder(CB_HWND(lphc
), lphc
, hDC
);
1015 if( !IsRectEmpty(&lphc
->buttonRect
) )
1017 CBPaintButton(lphc
, hDC
, lphc
->buttonRect
);
1020 if( !(lphc
->wState
& CBF_EDIT
) )
1023 * The text area has a border only in Win 3.1 look.
1025 if (TWEAK_WineLook
== WIN31_LOOK
)
1027 HPEN hPrevPen
= SelectObject( hDC
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1030 lphc
->textRect
.left
, lphc
->textRect
.top
,
1031 lphc
->textRect
.right
- 1, lphc
->textRect
.bottom
- 1);
1033 SelectObject( hDC
, hPrevPen
);
1036 CBPaintText( lphc
, hDC
, lphc
->textRect
);
1040 SelectObject( hDC
, hPrevBrush
);
1044 EndPaint(lphc
->self
->hwndSelf
, &ps
);
1049 /***********************************************************************
1052 * Select listbox entry according to the contents of the edit control.
1054 static INT
CBUpdateLBox( LPHEADCOMBO lphc
)
1056 INT length
, idx
, ret
;
1060 length
= CB_GETEDITTEXTLENGTH( lphc
);
1063 pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1);
1065 TRACE("\t edit text length %i\n", length
);
1069 if( length
) GetWindowTextA( lphc
->hWndEdit
, pText
, length
+ 1);
1070 else pText
[0] = '\0';
1071 idx
= SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
,
1072 (WPARAM
)(-1), (LPARAM
)pText
);
1073 if( idx
== LB_ERR
) idx
= 0; /* select first item */
1075 HeapFree( GetProcessHeap(), 0, pText
);
1080 SendMessageA( lphc
->hWndLBox
, LB_SETCURSEL
, (WPARAM
)idx
, 0 );
1084 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)idx
, 0 );
1085 /* probably superfluous but Windows sends this too */
1086 SendMessageA( lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)idx
, 0 );
1091 /***********************************************************************
1094 * Copy a listbox entry to the edit control.
1096 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1101 TRACE("\t %i\n", index
);
1105 length
= CB_GETEDITTEXTLENGTH( lphc
);
1108 if( (pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1)) )
1110 GetWindowTextA( lphc
->hWndEdit
, pText
, length
+ 1 );
1111 index
= SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
,
1112 (WPARAM
)(-1), (LPARAM
)pText
);
1113 HeapFree( GetProcessHeap(), 0, pText
);
1118 if( index
>= 0 ) /* got an entry */
1120 length
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1123 if( (pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1)) )
1125 SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
,
1126 (WPARAM
)index
, (LPARAM
)pText
);
1128 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1130 SendMessageA( lphc
->hWndEdit
, WM_SETTEXT
, 0, (LPARAM
)pText
);
1131 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1) );
1132 HeapFree( GetProcessHeap(), 0, pText
);
1138 /***********************************************************************
1141 * Show listbox popup.
1143 static void CBDropDown( LPHEADCOMBO lphc
)
1149 int nDroppedHeight
, nTempDroppedHeight
;
1151 TRACE("[%04x]: drop down\n", CB_HWND(lphc
));
1153 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1157 lphc
->wState
|= CBF_DROPPED
;
1158 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1160 lphc
->droppedIndex
= CBUpdateLBox( lphc
);
1162 if( !(lphc
->wState
& CBF_CAPTURE
) )
1163 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1167 lphc
->droppedIndex
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1169 if( lphc
->droppedIndex
== LB_ERR
)
1170 lphc
->droppedIndex
= 0;
1172 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)lphc
->droppedIndex
, 0 );
1173 SendMessageA( lphc
->hWndLBox
, LB_CARETON
, 0, 0 );
1176 /* now set popup position */
1177 GetWindowRect( lphc
->self
->hwndSelf
, &rect
);
1180 * If it's a dropdown, the listbox is offset
1182 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1183 rect
.left
+= COMBO_EDITBUTTONSPACE();
1185 /* if the dropped height is greater than the total height of the dropped
1186 items list, then force the drop down list height to be the total height
1187 of the items in the dropped list */
1189 /* And Remove any extra space (Best Fit) */
1190 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1191 nItems
= (int)SendMessageA (lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1192 nHeight
= COMBO_YBORDERSIZE();
1193 nTempDroppedHeight
= 0;
1194 for (i
= 0; i
< nItems
; i
++)
1196 nHeight
+= (int)SendMessageA (lphc
->hWndLBox
, LB_GETITEMHEIGHT
, i
, 0);
1198 /* Did we pass the limit of what can be displayed */
1199 if (nHeight
> nDroppedHeight
)
1203 nTempDroppedHeight
= nHeight
;
1206 nDroppedHeight
= nTempDroppedHeight
;
1208 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1209 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1211 SWP_NOACTIVATE
| SWP_NOREDRAW
);
1213 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1214 RedrawWindow( lphc
->self
->hwndSelf
, NULL
, 0, RDW_INVALIDATE
|
1215 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1217 ShowWindow( lphc
->hWndLBox
, SW_SHOWNA
);
1220 /***********************************************************************
1223 * Hide listbox popup.
1225 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1227 HWND hWnd
= lphc
->self
->hwndSelf
;
1229 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1231 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1234 TRACE("[%04x]: roll up [%i]\n", CB_HWND(lphc
), (INT
)ok
);
1236 if( lphc
->wState
& CBF_DROPPED
)
1241 * It seems useful to send the WM_LBUTTONUP with (-1,-1) when cancelling
1242 * and with (0,0) (anywhere in the listbox) when Oking.
1244 SendMessageA( lphc
->hWndLBox
, WM_LBUTTONUP
, 0, ok
? (LPARAM
)0 : (LPARAM
)(-1) );
1246 lphc
->wState
&= ~CBF_DROPPED
;
1247 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1248 if(GetCapture() == lphc
->hWndLBox
)
1254 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1256 INT index
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1257 CBUpdateEdit( lphc
, index
);
1258 rect
= lphc
->buttonRect
;
1269 rect
= lphc
->textRect
;
1274 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1275 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1276 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1277 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1282 /***********************************************************************
1285 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1287 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL bRedrawButton
)
1289 if( lphc
->wState
& CBF_DROPPED
)
1291 CBRollUp( lphc
, TRUE
, bRedrawButton
);
1299 /***********************************************************************
1302 * Edit control helper.
1304 HWND
COMBO_GetLBWindow( WND
* pWnd
)
1306 LPHEADCOMBO lphc
= CB_GETPTR(pWnd
);
1307 if( lphc
) return lphc
->hWndLBox
;
1312 /***********************************************************************
1315 static void CBRepaintButton( LPHEADCOMBO lphc
)
1317 InvalidateRect(CB_HWND(lphc
), &lphc
->buttonRect
, TRUE
);
1318 UpdateWindow(CB_HWND(lphc
));
1321 /***********************************************************************
1324 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1326 if( !(lphc
->wState
& CBF_FOCUSED
) )
1328 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1329 SendMessageA( lphc
->hWndLBox
, LB_CARETON
, 0, 0 );
1331 if( lphc
->wState
& CBF_EDIT
)
1332 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1) );
1333 lphc
->wState
|= CBF_FOCUSED
;
1334 if( !(lphc
->wState
& CBF_EDIT
) )
1336 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1339 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1343 /***********************************************************************
1346 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1348 HWND hWnd
= lphc
->self
->hwndSelf
;
1350 if( lphc
->wState
& CBF_FOCUSED
)
1352 SendMessageA( hWnd
, WM_LBUTTONUP
, 0, (LPARAM
)(-1) );
1354 CBRollUp( lphc
, FALSE
, TRUE
);
1355 if( IsWindow( hWnd
) )
1357 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1358 SendMessageA( lphc
->hWndLBox
, LB_CARETOFF
, 0, 0 );
1360 lphc
->wState
&= ~CBF_FOCUSED
;
1363 if( lphc
->wState
& CBF_EDIT
)
1364 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, (WPARAM
)(-1), 0 );
1367 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1370 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1375 /***********************************************************************
1378 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1380 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1382 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1384 switch( HIWORD(wParam
) >> 8 )
1386 case (EN_SETFOCUS
>> 8):
1388 TRACE("[%04x]: edit [%04x] got focus\n",
1389 CB_HWND(lphc
), lphc
->hWndEdit
);
1391 if( !(lphc
->wState
& CBF_FOCUSED
) ) COMBO_SetFocus( lphc
);
1394 case (EN_KILLFOCUS
>> 8):
1396 TRACE("[%04x]: edit [%04x] lost focus\n",
1397 CB_HWND(lphc
), lphc
->hWndEdit
);
1399 /* NOTE: it seems that Windows' edit control sends an
1400 * undocumented message WM_USER + 0x1B instead of this
1401 * notification (only when it happens to be a part of
1402 * the combo). ?? - AK.
1405 COMBO_KillFocus( lphc
);
1409 case (EN_CHANGE
>> 8):
1411 * In some circumstances (when the selection of the combobox
1412 * is changed for example) we don't wans the EN_CHANGE notification
1413 * to be forwarded to the parent of the combobox. This code
1414 * checks a flag that is set in these occasions and ignores the
1417 if (lphc
->wState
& CBF_NOEDITNOTIFY
)
1419 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1423 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1426 CBUpdateLBox( lphc
);
1429 case (EN_UPDATE
>> 8):
1430 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1433 case (EN_ERRSPACE
>> 8):
1434 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1437 else if( lphc
->hWndLBox
== hWnd
)
1439 switch( HIWORD(wParam
) )
1442 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1446 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1452 TRACE("[%04x]: lbox selection change [%04x]\n",
1453 CB_HWND(lphc
), lphc
->wState
);
1455 /* do not roll up if selection is being tracked
1456 * by arrowkeys in the dropdown listbox */
1458 if( (lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
) )
1459 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1460 else lphc
->wState
&= ~CBF_NOROLLUP
;
1462 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1463 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1468 /* nothing to do here since ComboLBox always resets the focus to its
1469 * combo/edit counterpart */
1476 /***********************************************************************
1479 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1481 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
,
1482 WPARAM wParam
, LPARAM lParam
)
1484 HWND hWnd
= lphc
->self
->hwndSelf
;
1486 TRACE("[%04x]: ownerdraw op %04x\n", CB_HWND(lphc
), msg
);
1488 #define lpIS ((LPDELETEITEMSTRUCT)lParam)
1490 /* two first items are the same in all 4 structs */
1491 lpIS
->CtlType
= ODT_COMBOBOX
;
1492 lpIS
->CtlID
= lphc
->self
->wIDmenu
;
1494 switch( msg
) /* patch window handle */
1497 lpIS
->hwndItem
= hWnd
;
1501 #define lpIS ((LPDRAWITEMSTRUCT)lParam)
1502 lpIS
->hwndItem
= hWnd
;
1505 case WM_COMPAREITEM
:
1506 #define lpIS ((LPCOMPAREITEMSTRUCT)lParam)
1507 lpIS
->hwndItem
= hWnd
;
1512 return SendMessageA( lphc
->owner
, msg
, lphc
->self
->wIDmenu
, lParam
);
1515 /***********************************************************************
1518 static LRESULT
COMBO_GetText( LPHEADCOMBO lphc
, UINT N
, LPSTR lpText
)
1520 if( lphc
->wState
& CBF_EDIT
)
1521 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
,
1522 (WPARAM
)N
, (LPARAM
)lpText
);
1524 /* get it from the listbox */
1526 if( lphc
->hWndLBox
)
1528 INT idx
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1532 INT length
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
,
1535 /* 'length' is without the terminating character */
1537 lpBuffer
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1 );
1543 INT n
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
,
1544 (WPARAM
)idx
, (LPARAM
)lpBuffer
);
1546 /* truncate if buffer is too short */
1551 if( n
!= LB_ERR
) memcpy( lpText
, lpBuffer
, (N
>n
) ? n
+1 : N
-1 );
1552 lpText
[N
- 1] = '\0';
1554 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1564 /***********************************************************************
1567 * This function sets window positions according to the updated
1568 * component placement struct.
1570 static void CBResetPos(
1576 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1578 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1579 * sizing messages */
1581 if( lphc
->wState
& CBF_EDIT
)
1582 SetWindowPos( lphc
->hWndEdit
, 0,
1583 rectEdit
->left
, rectEdit
->top
,
1584 rectEdit
->right
- rectEdit
->left
,
1585 rectEdit
->bottom
- rectEdit
->top
,
1586 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1588 SetWindowPos( lphc
->hWndLBox
, 0,
1589 rectLB
->left
, rectLB
->top
,
1590 rectLB
->right
- rectLB
->left
,
1591 rectLB
->bottom
- rectLB
->top
,
1592 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1596 if( lphc
->wState
& CBF_DROPPED
)
1598 lphc
->wState
&= ~CBF_DROPPED
;
1599 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1602 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1603 RedrawWindow( lphc
->self
->hwndSelf
, NULL
, 0,
1604 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1609 /***********************************************************************
1612 static void COMBO_Size( LPHEADCOMBO lphc
)
1614 CBCalcPlacement(lphc
->self
->hwndSelf
,
1618 &lphc
->droppedRect
);
1620 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1624 /***********************************************************************
1627 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1632 lphc
->hFont
= hFont
;
1635 * Propagate to owned windows.
1637 if( lphc
->wState
& CBF_EDIT
)
1638 SendMessageA( lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1639 SendMessageA( lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1642 * Redo the layout of the control.
1644 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1646 CBCalcPlacement(lphc
->self
->hwndSelf
,
1650 &lphc
->droppedRect
);
1652 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1656 CBForceDummyResize(lphc
);
1661 /***********************************************************************
1662 * COMBO_SetItemHeight
1664 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1666 LRESULT lRet
= CB_ERR
;
1668 if( index
== -1 ) /* set text field height */
1670 if( height
< 32768 )
1672 lphc
->editHeight
= height
;
1675 * Redo the layout of the control.
1677 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1679 CBCalcPlacement(lphc
->self
->hwndSelf
,
1683 &lphc
->droppedRect
);
1685 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1689 CBForceDummyResize(lphc
);
1695 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1696 lRet
= SendMessageA( lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1697 (WPARAM
)index
, (LPARAM
)height
);
1701 /***********************************************************************
1702 * COMBO_SelectString
1704 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPCSTR pText
)
1706 INT index
= SendMessageA( lphc
->hWndLBox
, LB_SELECTSTRING
,
1707 (WPARAM
)start
, (LPARAM
)pText
);
1710 if( lphc
->wState
& CBF_EDIT
)
1711 CBUpdateEdit( lphc
, index
);
1714 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1717 return (LRESULT
)index
;
1720 /***********************************************************************
1723 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1727 HWND hWnd
= lphc
->self
->hwndSelf
;
1729 pt
.x
= LOWORD(lParam
);
1730 pt
.y
= HIWORD(lParam
);
1731 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1733 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1734 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1736 lphc
->wState
|= CBF_BUTTONDOWN
;
1737 if( lphc
->wState
& CBF_DROPPED
)
1739 /* got a click to cancel selection */
1741 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1742 CBRollUp( lphc
, TRUE
, FALSE
);
1743 if( !IsWindow( hWnd
) ) return;
1745 if( lphc
->wState
& CBF_CAPTURE
)
1747 lphc
->wState
&= ~CBF_CAPTURE
;
1753 /* drop down the listbox and start tracking */
1755 lphc
->wState
|= CBF_CAPTURE
;
1759 if( bButton
) CBRepaintButton( lphc
);
1763 /***********************************************************************
1766 * Release capture and stop tracking if needed.
1768 static void COMBO_LButtonUp( LPHEADCOMBO lphc
, LPARAM lParam
)
1770 if( lphc
->wState
& CBF_CAPTURE
)
1772 lphc
->wState
&= ~CBF_CAPTURE
;
1773 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1775 INT index
= CBUpdateLBox( lphc
);
1776 CBUpdateEdit( lphc
, index
);
1779 SetCapture(lphc
->hWndLBox
);
1783 if( lphc
->wState
& CBF_BUTTONDOWN
)
1785 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1786 CBRepaintButton( lphc
);
1790 /***********************************************************************
1793 * Two things to do - track combo button and release capture when
1794 * pointer goes into the listbox.
1796 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1801 pt
.x
= LOWORD(lParam
);
1802 pt
.y
= HIWORD(lParam
);
1804 if( lphc
->wState
& CBF_BUTTONDOWN
)
1808 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1812 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1813 CBRepaintButton( lphc
);
1817 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1818 MapWindowPoints( lphc
->self
->hwndSelf
, lphc
->hWndLBox
, &pt
, 1 );
1819 if( PtInRect(&lbRect
, pt
) )
1821 lphc
->wState
&= ~CBF_CAPTURE
;
1823 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
);
1825 /* hand over pointer tracking */
1826 SendMessageA( lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1831 /***********************************************************************
1832 * ComboWndProc_locked
1834 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1836 static inline LRESULT WINAPI
ComboWndProc_locked( WND
* pWnd
, UINT message
,
1837 WPARAM wParam
, LPARAM lParam
)
1840 LPHEADCOMBO lphc
= CB_GETPTR(pWnd
);
1841 HWND hwnd
= pWnd
->hwndSelf
;
1843 TRACE("[%04x]: msg %s wp %08x lp %08lx\n",
1844 pWnd
->hwndSelf
, SPY_GetMsgName(message
), wParam
, lParam
);
1846 if( lphc
|| message
== WM_NCCREATE
)
1850 /* System messages */
1853 return COMBO_NCCreate(pWnd
, lParam
);
1855 COMBO_NCDestroy(lphc
);
1856 break;/* -> DefWindowProc */
1859 return COMBO_Create(lphc
, pWnd
, lParam
);
1861 case WM_PRINTCLIENT
:
1862 if (lParam
& PRF_ERASEBKGND
)
1863 COMBO_EraseBackground(hwnd
, lphc
, wParam
);
1867 /* wParam may contain a valid HDC! */
1868 return COMBO_Paint(lphc
, wParam
);
1870 return COMBO_EraseBackground(hwnd
, lphc
, wParam
);
1872 return (LRESULT
)(DLGC_WANTARROWS
| DLGC_WANTCHARS
);
1873 case WM_WINDOWPOSCHANGING
:
1874 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1876 if( lphc
->hWndLBox
&&
1877 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
);
1880 COMBO_Font( lphc
, (HFONT16
)wParam
, (BOOL
)lParam
);
1883 return (LRESULT
)lphc
->hFont
;
1885 if( lphc
->wState
& CBF_EDIT
)
1886 SetFocus( lphc
->hWndEdit
);
1888 COMBO_SetFocus( lphc
);
1891 #define hwndFocus ((HWND16)wParam)
1893 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1894 COMBO_KillFocus( lphc
);
1898 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1900 return COMBO_GetText( lphc
, (UINT
)wParam
, (LPSTR
)lParam
);
1902 case WM_GETTEXTLENGTH
:
1907 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1909 int j
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1910 if (j
== -1) return 0;
1911 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1913 else if( lphc
->wState
& CBF_EDIT
)
1915 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1917 return SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1923 case WM_COMPAREITEM
:
1924 case WM_MEASUREITEM
:
1925 return COMBO_ItemOp( lphc
, message
, wParam
, lParam
);
1927 if( lphc
->wState
& CBF_EDIT
)
1928 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
1929 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
1931 /* Force the control to repaint when the enabled state changes. */
1932 InvalidateRect(CB_HWND(lphc
), NULL
, TRUE
);
1936 lphc
->wState
&= ~CBF_NOREDRAW
;
1938 lphc
->wState
|= CBF_NOREDRAW
;
1940 if( lphc
->wState
& CBF_EDIT
)
1941 SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1942 SendMessageA( lphc
->hWndLBox
, message
, wParam
, lParam
);
1945 if( KEYDATA_ALT
& HIWORD(lParam
) )
1946 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
1947 COMBO_FlipListbox( lphc
, TRUE
);
1948 break;/* -> DefWindowProc */
1952 if( lphc
->wState
& CBF_EDIT
)
1953 return SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1955 return SendMessageA( lphc
->hWndLBox
, message
, wParam
, lParam
);
1956 case WM_LBUTTONDOWN
:
1957 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
->hwndSelf
);
1958 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
1961 COMBO_LButtonUp( lphc
, lParam
);
1964 if( lphc
->wState
& CBF_CAPTURE
)
1965 COMBO_MouseMove( lphc
, wParam
, lParam
);
1967 /* Combo messages */
1969 case CB_ADDSTRING16
:
1970 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1972 return SendMessageA( lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
1973 case CB_INSERTSTRING16
:
1974 wParam
= (INT
)(INT16
)wParam
;
1975 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1976 case CB_INSERTSTRING
:
1977 return SendMessageA( lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
1978 case CB_DELETESTRING16
:
1979 case CB_DELETESTRING
:
1980 return SendMessageA( lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
1981 case CB_SELECTSTRING16
:
1982 wParam
= (INT
)(INT16
)wParam
;
1983 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1984 case CB_SELECTSTRING
:
1985 return COMBO_SelectString( lphc
, (INT
)wParam
, (LPSTR
)lParam
);
1986 case CB_FINDSTRING16
:
1987 wParam
= (INT
)(INT16
)wParam
;
1988 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1990 return SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
1991 case CB_FINDSTRINGEXACT16
:
1992 wParam
= (INT
)(INT16
)wParam
;
1993 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1994 case CB_FINDSTRINGEXACT
:
1995 return SendMessageA( lphc
->hWndLBox
, LB_FINDSTRINGEXACT
,
1997 case CB_SETITEMHEIGHT16
:
1998 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
1999 case CB_SETITEMHEIGHT
:
2000 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
2001 case CB_GETITEMHEIGHT16
:
2002 wParam
= (INT
)(INT16
)wParam
;
2003 case CB_GETITEMHEIGHT
:
2004 if( (INT
)wParam
>= 0 ) /* listbox item */
2005 return SendMessageA( lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
2006 return CBGetTextAreaHeight(hwnd
, lphc
);
2007 case CB_RESETCONTENT16
:
2008 case CB_RESETCONTENT
:
2009 SendMessageA( lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0 );
2010 InvalidateRect(CB_HWND(lphc
), NULL
, TRUE
);
2012 case CB_INITSTORAGE
:
2013 return SendMessageA( lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
2014 case CB_GETHORIZONTALEXTENT
:
2015 return SendMessageA( lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
2016 case CB_SETHORIZONTALEXTENT
:
2017 return SendMessageA( lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
2018 case CB_GETTOPINDEX
:
2019 return SendMessageA( lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2021 return SendMessageA( lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2023 return SendMessageA( lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2024 case CB_GETDROPPEDWIDTH
:
2025 if( lphc
->droppedWidth
)
2026 return lphc
->droppedWidth
;
2027 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2028 case CB_SETDROPPEDWIDTH
:
2029 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2030 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2032 case CB_GETDROPPEDCONTROLRECT16
:
2033 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2037 CBGetDroppedControlRect( lphc
, &r
);
2038 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2041 case CB_GETDROPPEDCONTROLRECT
:
2042 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2044 case CB_GETDROPPEDSTATE16
:
2045 case CB_GETDROPPEDSTATE
:
2046 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2048 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2051 return COMBO_Directory( lphc
, (UINT
)wParam
,
2052 (LPSTR
)lParam
, (message
== CB_DIR
));
2053 case CB_SHOWDROPDOWN16
:
2054 case CB_SHOWDROPDOWN
:
2055 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2059 if( !(lphc
->wState
& CBF_DROPPED
) )
2063 if( lphc
->wState
& CBF_DROPPED
)
2064 CBRollUp( lphc
, FALSE
, TRUE
);
2069 return SendMessageA( lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2070 case CB_GETCURSEL16
:
2072 return SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2073 case CB_SETCURSEL16
:
2074 wParam
= (INT
)(INT16
)wParam
;
2076 lParam
= SendMessageA( lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2077 if( lphc
->wState
& CBF_SELCHANGE
)
2079 /* no LBN_SELCHANGE in this case, update manually */
2080 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
2081 lphc
->wState
&= ~CBF_SELCHANGE
;
2084 case CB_GETLBTEXT16
:
2085 wParam
= (INT
)(INT16
)wParam
;
2086 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2088 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2089 case CB_GETLBTEXTLEN16
:
2090 wParam
= (INT
)(INT16
)wParam
;
2091 case CB_GETLBTEXTLEN
:
2092 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2093 case CB_GETITEMDATA16
:
2094 wParam
= (INT
)(INT16
)wParam
;
2095 case CB_GETITEMDATA
:
2096 return SendMessageA( lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2097 case CB_SETITEMDATA16
:
2098 wParam
= (INT
)(INT16
)wParam
;
2099 case CB_SETITEMDATA
:
2100 return SendMessageA( lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2101 case CB_GETEDITSEL16
:
2102 wParam
= lParam
= 0; /* just in case */
2104 if( lphc
->wState
& CBF_EDIT
)
2108 return SendMessageA( lphc
->hWndEdit
, EM_GETSEL
,
2109 (wParam
) ? wParam
: (WPARAM
)&a
,
2110 (lParam
) ? lParam
: (LPARAM
)&b
);
2113 case CB_SETEDITSEL16
:
2115 if( lphc
->wState
& CBF_EDIT
)
2116 return SendMessageA( lphc
->hWndEdit
, EM_SETSEL
,
2117 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2119 case CB_SETEXTENDEDUI16
:
2120 case CB_SETEXTENDEDUI
:
2121 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2124 lphc
->wState
|= CBF_EUI
;
2125 else lphc
->wState
&= ~CBF_EUI
;
2127 case CB_GETEXTENDEDUI16
:
2128 case CB_GETEXTENDEDUI
:
2129 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2130 case (WM_USER
+ 0x1B):
2131 WARN("[%04x]: undocumented msg!\n", hwnd
);
2133 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2138 /***********************************************************************
2141 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2144 LRESULT WINAPI
ComboWndProc( HWND hwnd
, UINT message
,
2145 WPARAM wParam
, LPARAM lParam
)
2147 WND
* pWnd
= WIN_FindWndPtr(hwnd
);
2148 LRESULT retvalue
= ComboWndProc_locked(pWnd
,message
,wParam
,lParam
);
2151 WIN_ReleaseWndPtr(pWnd
);