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 /***********************************************************************
157 * CBGetTextAreaHeight
159 * This method will calculate the height of the text area of the
161 * The height of the text area is set in two ways.
162 * It can be set explicitely through a combobox message of through a
163 * WM_MEASUREITEM callback.
164 * If this is not the case, the height is set to 13 dialog units.
165 * This height was determined through experimentation.
167 static INT
CBGetTextAreaHeight(
173 if( lphc
->editHeight
) /* explicitly set height */
175 iTextItemHeight
= lphc
->editHeight
;
180 HDC hDC
= GetDC(hwnd
);
185 hPrevFont
= SelectObject( hDC
, lphc
->hFont
);
187 GetTextMetricsA(hDC
, &tm
);
189 baseUnitY
= tm
.tmHeight
;
192 SelectObject( hDC
, hPrevFont
);
194 ReleaseDC(hwnd
, hDC
);
196 iTextItemHeight
= ((13 * baseUnitY
) / 8);
199 * This "formula" calculates the height of the complete control.
200 * To calculate the height of the text area, we have to remove the
203 iTextItemHeight
-= 2*COMBO_YBORDERSIZE();
207 * Check the ownerdraw case if we haven't asked the parent the size
210 if ( CB_OWNERDRAWN(lphc
) &&
211 (lphc
->wState
& CBF_MEASUREITEM
) )
213 MEASUREITEMSTRUCT measureItem
;
215 INT originalItemHeight
= iTextItemHeight
;
218 * We use the client rect for the width of the item.
220 GetClientRect(hwnd
, &clientRect
);
222 lphc
->wState
&= ~CBF_MEASUREITEM
;
225 * Send a first one to measure the size of the text area
227 measureItem
.CtlType
= ODT_COMBOBOX
;
228 measureItem
.CtlID
= lphc
->self
->wIDmenu
;
229 measureItem
.itemID
= -1;
230 measureItem
.itemWidth
= clientRect
.right
;
231 measureItem
.itemHeight
= iTextItemHeight
- 6; /* ownerdrawn cb is taller */
232 measureItem
.itemData
= 0;
233 SendMessageA(lphc
->owner
, WM_MEASUREITEM
,
234 (WPARAM
)measureItem
.CtlID
, (LPARAM
)&measureItem
);
235 iTextItemHeight
= 6 + measureItem
.itemHeight
;
238 * Send a second one in the case of a fixed ownerdraw list to calculate the
239 * size of the list items. (we basically do this on behalf of the listbox)
241 if (lphc
->dwStyle
& CBS_OWNERDRAWFIXED
)
243 measureItem
.CtlType
= ODT_COMBOBOX
;
244 measureItem
.CtlID
= lphc
->self
->wIDmenu
;
245 measureItem
.itemID
= 0;
246 measureItem
.itemWidth
= clientRect
.right
;
247 measureItem
.itemHeight
= originalItemHeight
;
248 measureItem
.itemData
= 0;
249 SendMessageA(lphc
->owner
, WM_MEASUREITEM
,
250 (WPARAM
)measureItem
.CtlID
, (LPARAM
)&measureItem
);
251 lphc
->fixedOwnerDrawHeight
= measureItem
.itemHeight
;
255 * Keep the size for the next time
257 lphc
->editHeight
= iTextItemHeight
;
260 return iTextItemHeight
;
263 /***********************************************************************
266 * The dummy resize is used for listboxes that have a popup to trigger
267 * a re-arranging of the contents of the combobox and the recalculation
268 * of the size of the "real" control window.
270 static void CBForceDummyResize(
276 newComboHeight
= CBGetTextAreaHeight(CB_HWND(lphc
),lphc
) + 2*COMBO_YBORDERSIZE();
278 GetWindowRect(CB_HWND(lphc
), &windowRect
);
281 * We have to be careful, resizing a combobox also has the meaning that the
282 * dropped rect will be resized. In this case, we want to trigger a resize
283 * to recalculate layout but we don't want to change the dropped rectangle
284 * So, we pass the height of text area of control as the height.
285 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
288 SetWindowPos( CB_HWND(lphc
),
291 windowRect
.right
- windowRect
.left
,
293 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
296 /***********************************************************************
299 * Set up component coordinates given valid lphc->RectCombo.
301 static void CBCalcPlacement(
309 * Again, start with the client rectangle.
311 GetClientRect(hwnd
, lprEdit
);
316 InflateRect(lprEdit
, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
319 * Chop off the bottom part to fit with the height of the text area.
321 lprEdit
->bottom
= lprEdit
->top
+ CBGetTextAreaHeight(hwnd
, lphc
);
324 * The button starts the same vertical position as the text area.
326 CopyRect(lprButton
, lprEdit
);
329 * If the combobox is "simple" there is no button.
331 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
332 lprButton
->left
= lprButton
->right
= lprButton
->bottom
= 0;
336 * Let's assume the combobox button is the same width as the
338 * size the button horizontally and cut-off the text area.
340 lprButton
->left
= lprButton
->right
- GetSystemMetrics(SM_CXVSCROLL
);
341 lprEdit
->right
= lprButton
->left
;
345 * In the case of a dropdown, there is an additional spacing between the
346 * text area and the button.
348 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
350 lprEdit
->right
-= COMBO_EDITBUTTONSPACE();
354 * If we have an edit control, we space it away from the borders slightly.
356 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
358 InflateRect(lprEdit
, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
362 * Adjust the size of the listbox popup.
364 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
367 * Use the client rectangle to initialize the listbox rectangle
369 GetClientRect(hwnd
, lprLB
);
372 * Then, chop-off the top part.
374 lprLB
->top
= lprEdit
->bottom
+ COMBO_YBORDERSIZE();
379 * Make sure the dropped width is as large as the combobox itself.
381 if (lphc
->droppedWidth
< (lprButton
->right
+ COMBO_XBORDERSIZE()))
383 lprLB
->right
= lprLB
->left
+ (lprButton
->right
+ COMBO_XBORDERSIZE());
386 * In the case of a dropdown, the popup listbox is offset to the right.
387 * so, we want to make sure it's flush with the right side of the
390 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
391 lprLB
->right
-= COMBO_EDITBUTTONSPACE();
394 lprLB
->right
= lprLB
->left
+ lphc
->droppedWidth
;
397 TRACE("\ttext\t= (%i,%i-%i,%i)\n",
398 lprEdit
->left
, lprEdit
->top
, lprEdit
->right
, lprEdit
->bottom
);
400 TRACE("\tbutton\t= (%i,%i-%i,%i)\n",
401 lprButton
->left
, lprButton
->top
, lprButton
->right
, lprButton
->bottom
);
403 TRACE("\tlbox\t= (%i,%i-%i,%i)\n",
404 lprLB
->left
, lprLB
->top
, lprLB
->right
, lprLB
->bottom
);
407 /***********************************************************************
408 * CBGetDroppedControlRect
410 static void CBGetDroppedControlRect( LPHEADCOMBO lphc
, LPRECT lpRect
)
412 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
413 of the combo box and the lower right corner of the listbox */
415 GetWindowRect(lphc
->self
->hwndSelf
, lpRect
);
417 lpRect
->right
= lpRect
->left
+ lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
418 lpRect
->bottom
= lpRect
->top
+ lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
422 /***********************************************************************
423 * COMBO_WindowPosChanging
425 static LRESULT
COMBO_WindowPosChanging(
428 WINDOWPOS
* posChanging
)
431 * We need to override the WM_WINDOWPOSCHANGING method to handle all
432 * the non-simple comboboxes. The problem is that those controls are
433 * always the same height. We have to make sure they are not resized
436 if ( ( CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
437 ((posChanging
->flags
& SWP_NOSIZE
) == 0) )
441 newComboHeight
= CBGetTextAreaHeight(hwnd
,lphc
) +
442 2*COMBO_YBORDERSIZE();
445 * Resizing a combobox has another side effect, it resizes the dropped
446 * rectangle as well. However, it does it only if the new height for the
447 * combobox is different than the height it should have. In other words,
448 * if the application resizing the combobox only had the intention to resize
449 * the actual control, for example, to do the layout of a dialog that is
450 * resized, the height of the dropdown is not changed.
452 if (posChanging
->cy
!= newComboHeight
)
454 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
+ posChanging
->cy
- newComboHeight
;
456 posChanging
->cy
= newComboHeight
;
463 /***********************************************************************
466 static LRESULT
COMBO_Create( LPHEADCOMBO lphc
, WND
* wnd
, LPARAM lParam
)
468 static char clbName
[] = "ComboLBox";
469 static char editName
[] = "Edit";
471 LPCREATESTRUCTA lpcs
= (CREATESTRUCTA
*)lParam
;
473 if( !CB_GETTYPE(lphc
) ) lphc
->dwStyle
|= CBS_SIMPLE
;
474 else if( CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
) lphc
->wState
|= CBF_EDIT
;
477 lphc
->owner
= lpcs
->hwndParent
;
480 * The item height and dropped width are not set when the control
483 lphc
->droppedWidth
= lphc
->editHeight
= 0;
486 * The first time we go through, we want to measure the ownerdraw item
488 lphc
->wState
|= CBF_MEASUREITEM
;
490 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
492 if( lphc
->owner
|| !(lpcs
->style
& WS_VISIBLE
) )
498 * Initialize the dropped rect to the size of the client area of the
499 * control and then, force all the areas of the combobox to be
502 GetClientRect( wnd
->hwndSelf
, &lphc
->droppedRect
);
504 CBCalcPlacement(wnd
->hwndSelf
,
508 &lphc
->droppedRect
);
511 * Adjust the position of the popup listbox if it's necessary
513 if ( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
515 lphc
->droppedRect
.top
= lphc
->textRect
.bottom
+ COMBO_YBORDERSIZE();
518 * If it's a dropdown, the listbox is offset
520 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
521 lphc
->droppedRect
.left
+= COMBO_EDITBUTTONSPACE();
523 ClientToScreen(wnd
->hwndSelf
, (LPPOINT
)&lphc
->droppedRect
);
524 ClientToScreen(wnd
->hwndSelf
, (LPPOINT
)&lphc
->droppedRect
.right
);
527 /* create listbox popup */
529 lbeStyle
= (LBS_NOTIFY
| WS_BORDER
| WS_CLIPSIBLINGS
) |
530 (lpcs
->style
& (WS_VSCROLL
| CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
));
532 if( lphc
->dwStyle
& CBS_SORT
)
533 lbeStyle
|= LBS_SORT
;
534 if( lphc
->dwStyle
& CBS_HASSTRINGS
)
535 lbeStyle
|= LBS_HASSTRINGS
;
536 if( lphc
->dwStyle
& CBS_NOINTEGRALHEIGHT
)
537 lbeStyle
|= LBS_NOINTEGRALHEIGHT
;
538 if( lphc
->dwStyle
& CBS_DISABLENOSCROLL
)
539 lbeStyle
|= LBS_DISABLENOSCROLL
;
541 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
) /* child listbox */
543 lbeStyle
|= WS_CHILD
| WS_VISIBLE
;
546 * In win 95 look n feel, the listbox in the simple combobox has
547 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
549 if (TWEAK_WineLook
> WIN31_LOOK
)
551 lbeStyle
&= ~WS_BORDER
;
552 lbeExStyle
|= WS_EX_CLIENTEDGE
;
555 else /* popup listbox */
556 lbeStyle
|= WS_POPUP
;
558 /* Dropdown ComboLBox is not a child window and we cannot pass
559 * ID_CB_LISTBOX directly because it will be treated as a menu handle.
561 lphc
->hWndLBox
= CreateWindowExA(lbeExStyle
,
565 lphc
->droppedRect
.left
,
566 lphc
->droppedRect
.top
,
567 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
568 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
569 lphc
->self
->hwndSelf
,
570 (lphc
->dwStyle
& CBS_DROPDOWN
)? (HMENU
)0 : (HMENU
)ID_CB_LISTBOX
,
571 lphc
->self
->hInstance
,
575 * The ComboLBox is a strange little beast (when it's not a CBS_SIMPLE)...
576 * It's a popup window but, when you get the window style, you get WS_CHILD.
577 * When created, it's parent is the combobox but, when you ask for it's parent
578 * after that, you're supposed to get the desktop. (see MFC code function
580 * To achieve this in Wine, we have to create it as a popup and change
581 * it's style to child after the creation.
583 if ( (lphc
->hWndLBox
!= 0) &&
584 (CB_GETTYPE(lphc
) != CBS_SIMPLE
) )
586 SetWindowLongA(lphc
->hWndLBox
,
588 (GetWindowLongA(lphc
->hWndLBox
, GWL_STYLE
) | WS_CHILD
) & ~WS_POPUP
);
594 lbeStyle
= WS_CHILD
| WS_VISIBLE
| ES_NOHIDESEL
| ES_LEFT
;
597 * In Win95 look, the border fo the edit control is
598 * provided by the combobox
600 if (TWEAK_WineLook
== WIN31_LOOK
)
601 lbeStyle
|= WS_BORDER
;
603 if( lphc
->wState
& CBF_EDIT
)
605 if( lphc
->dwStyle
& CBS_OEMCONVERT
)
606 lbeStyle
|= ES_OEMCONVERT
;
607 if( lphc
->dwStyle
& CBS_AUTOHSCROLL
)
608 lbeStyle
|= ES_AUTOHSCROLL
;
609 if( lphc
->dwStyle
& CBS_LOWERCASE
)
610 lbeStyle
|= ES_LOWERCASE
;
611 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
612 lbeStyle
|= ES_UPPERCASE
;
614 lphc
->hWndEdit
= CreateWindowExA(0,
618 lphc
->textRect
.left
, lphc
->textRect
.top
,
619 lphc
->textRect
.right
- lphc
->textRect
.left
,
620 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
621 lphc
->self
->hwndSelf
,
623 lphc
->self
->hInstance
,
626 if( !lphc
->hWndEdit
)
633 * If the combo is a dropdown, we must resize the control to fit only
634 * the text area and button. To do this, we send a dummy resize and the
635 * WM_WINDOWPOSCHANGING message will take care of setting the height for
638 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
640 CBForceDummyResize(lphc
);
643 TRACE("init done\n");
644 return wnd
->hwndSelf
;
646 ERR("edit control failure.\n");
647 } else ERR("listbox failure.\n");
648 } else ERR("no owner for visible combo.\n");
650 /* CreateWindow() will send WM_NCDESTROY to cleanup */
655 /***********************************************************************
658 * Paint combo button (normal, pressed, and disabled states).
660 static void CBPaintButton(
665 if( lphc
->wState
& CBF_NOREDRAW
)
668 if (TWEAK_WineLook
== WIN31_LOOK
)
674 COLORREF oldTextColor
, oldBkColor
;
677 hPrevBrush
= SelectObject(hdc
, GetSysColorBrush(COLOR_BTNFACE
));
680 * Draw the button background
685 rectButton
.right
-rectButton
.left
,
686 rectButton
.bottom
-rectButton
.top
,
689 if( (bBool
= lphc
->wState
& CBF_BUTTONDOWN
) )
691 DrawEdge( hdc
, &rectButton
, EDGE_SUNKEN
, BF_RECT
);
695 DrawEdge( hdc
, &rectButton
, EDGE_RAISED
, BF_RECT
);
699 * Remove the edge of the button from the rectangle
700 * and calculate the position of the bitmap.
702 InflateRect( &rectButton
, -2, -2);
704 x
= (rectButton
.left
+ rectButton
.right
- CBitWidth
) >> 1;
705 y
= (rectButton
.top
+ rectButton
.bottom
- CBitHeight
) >> 1;
708 hMemDC
= CreateCompatibleDC( hdc
);
709 SelectObject( hMemDC
, hComboBmp
);
710 oldTextColor
= SetTextColor( hdc
, GetSysColor(COLOR_BTNFACE
) );
711 oldBkColor
= SetBkColor( hdc
, CB_DISABLED(lphc
) ? RGB(128,128,128) :
713 BitBlt( hdc
, x
, y
, CBitWidth
, CBitHeight
, hMemDC
, 0, 0, SRCCOPY
);
714 SetBkColor( hdc
, oldBkColor
);
715 SetTextColor( hdc
, oldTextColor
);
717 SelectObject( hdc
, hPrevBrush
);
721 UINT buttonState
= DFCS_SCROLLCOMBOBOX
;
723 if (lphc
->wState
& CBF_BUTTONDOWN
)
725 buttonState
|= DFCS_PUSHED
;
728 if (CB_DISABLED(lphc
))
730 buttonState
|= DFCS_INACTIVE
;
733 DrawFrameControl(hdc
,
740 /***********************************************************************
743 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
745 static void CBPaintText(
753 if( lphc
->wState
& CBF_NOREDRAW
) return;
755 /* follow Windows combobox that sends a bunch of text
756 * inquiries to its listbox while processing WM_PAINT. */
758 if( (id
= SendMessageA(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0) ) != LB_ERR
)
760 size
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, id
, 0);
761 if( (pText
= HeapAlloc( GetProcessHeap(), 0, size
+ 1)) )
763 SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
, (WPARAM
)id
, (LPARAM
)pText
);
764 pText
[size
] = '\0'; /* just in case */
768 if( lphc
->wState
& CBF_EDIT
)
770 if( CB_HASSTRINGS(lphc
) ) SetWindowTextA( lphc
->hWndEdit
, pText
? pText
: "" );
771 if( lphc
->wState
& CBF_FOCUSED
)
772 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
774 else /* paint text field ourselves */
777 HFONT hPrevFont
= (lphc
->hFont
) ? SelectObject(hdc
, lphc
->hFont
) : 0;
780 * Give ourselves some space.
782 InflateRect( &rectEdit
, -1, -1 );
784 if ( (lphc
->wState
& CBF_FOCUSED
) &&
785 !(lphc
->wState
& CBF_DROPPED
) )
789 FillRect( hdc
, &rectEdit
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
790 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
791 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
792 itemState
= ODS_SELECTED
| ODS_FOCUS
;
797 if( CB_OWNERDRAWN(lphc
) )
803 * Save the current clip region.
804 * To retrieve the clip region, we need to create one "dummy"
807 clipRegion
= CreateRectRgnIndirect(&rectEdit
);
809 if (GetClipRgn(hdc
, clipRegion
)!=1)
811 DeleteObject(clipRegion
);
812 clipRegion
=(HRGN
)NULL
;
815 if ( lphc
->self
->dwStyle
& WS_DISABLED
)
816 itemState
|= ODS_DISABLED
;
818 dis
.CtlType
= ODT_COMBOBOX
;
819 dis
.CtlID
= lphc
->self
->wIDmenu
;
820 dis
.hwndItem
= lphc
->self
->hwndSelf
;
821 dis
.itemAction
= ODA_DRAWENTIRE
;
823 dis
.itemState
= itemState
;
825 dis
.rcItem
= rectEdit
;
826 dis
.itemData
= SendMessageA( lphc
->hWndLBox
, LB_GETITEMDATA
,
830 * Clip the DC and have the parent draw the item.
832 IntersectClipRect(hdc
,
833 rectEdit
.left
, rectEdit
.top
,
834 rectEdit
.right
, rectEdit
.bottom
);
836 SendMessageA(lphc
->owner
, WM_DRAWITEM
,
837 lphc
->self
->wIDmenu
, (LPARAM
)&dis
);
840 * Reset the clipping region.
842 SelectClipRgn(hdc
, clipRegion
);
849 ETO_OPAQUE
| ETO_CLIPPED
,
851 pText
? pText
: "" , size
, NULL
);
853 if(lphc
->wState
& CBF_FOCUSED
&& !(lphc
->wState
& CBF_DROPPED
))
854 DrawFocusRect( hdc
, &rectEdit
);
858 SelectObject(hdc
, hPrevFont
);
861 HeapFree( GetProcessHeap(), 0, pText
);
864 /***********************************************************************
867 static void CBPaintBorder(
874 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
876 GetClientRect(hwnd
, &clientRect
);
880 CopyRect(&clientRect
, &lphc
->textRect
);
882 InflateRect(&clientRect
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
883 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
886 DrawEdge(hdc
, &clientRect
, EDGE_SUNKEN
, BF_RECT
);
889 /***********************************************************************
890 * COMBO_PrepareColors
892 * This method will sent the appropriate WM_CTLCOLOR message to
893 * prepare and setup the colors for the combo's DC.
895 * It also returns the brush to use for the background.
897 static HBRUSH
COMBO_PrepareColors(
905 * Get the background brush for this control.
907 if (CB_DISABLED(lphc
))
909 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLORSTATIC
,
910 hDC
, lphc
->self
->hwndSelf
);
913 * We have to change the text color since WM_CTLCOLORSTATIC will
914 * set it to the "enabled" color. This is the same behavior as the
917 SetTextColor(hDC
, GetSysColor(COLOR_GRAYTEXT
));
921 if (lphc
->wState
& CBF_EDIT
)
923 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLOREDIT
,
924 hDC
, lphc
->self
->hwndSelf
);
928 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLORLISTBOX
,
929 hDC
, lphc
->self
->hwndSelf
);
937 hBkgBrush
= GetSysColorBrush(COLOR_WINDOW
);
942 /***********************************************************************
943 * COMBO_EraseBackground
945 static LRESULT
COMBO_EraseBackground(
954 hDC
= (hParamDC
) ? hParamDC
958 * Calculate the area that we want to erase.
960 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
962 GetClientRect(hwnd
, &clientRect
);
966 CopyRect(&clientRect
, &lphc
->textRect
);
968 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
972 * Retrieve the background brush
974 hBkgBrush
= COMBO_PrepareColors(hwnd
, lphc
, hDC
);
976 FillRect(hDC
, &clientRect
, hBkgBrush
);
979 ReleaseDC(hwnd
, hDC
);
984 /***********************************************************************
987 static LRESULT
COMBO_Paint(LPHEADCOMBO lphc
, HDC hParamDC
)
992 hDC
= (hParamDC
) ? hParamDC
993 : BeginPaint( lphc
->self
->hwndSelf
, &ps
);
996 if( hDC
&& !(lphc
->wState
& CBF_NOREDRAW
) )
998 HBRUSH hPrevBrush
, hBkgBrush
;
1001 * Retrieve the background brush and select it in the
1004 hBkgBrush
= COMBO_PrepareColors(lphc
->self
->hwndSelf
, lphc
, hDC
);
1006 hPrevBrush
= SelectObject( hDC
, hBkgBrush
);
1009 * In non 3.1 look, there is a sunken border on the combobox
1011 if (TWEAK_WineLook
!= WIN31_LOOK
)
1013 CBPaintBorder(CB_HWND(lphc
), lphc
, hDC
);
1016 if( !IsRectEmpty(&lphc
->buttonRect
) )
1018 CBPaintButton(lphc
, hDC
, lphc
->buttonRect
);
1021 if( !(lphc
->wState
& CBF_EDIT
) )
1024 * The text area has a border only in Win 3.1 look.
1026 if (TWEAK_WineLook
== WIN31_LOOK
)
1028 HPEN hPrevPen
= SelectObject( hDC
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1031 lphc
->textRect
.left
, lphc
->textRect
.top
,
1032 lphc
->textRect
.right
- 1, lphc
->textRect
.bottom
- 1);
1034 SelectObject( hDC
, hPrevPen
);
1037 CBPaintText( lphc
, hDC
, lphc
->textRect
);
1041 SelectObject( hDC
, hPrevBrush
);
1045 EndPaint(lphc
->self
->hwndSelf
, &ps
);
1050 /***********************************************************************
1053 * Select listbox entry according to the contents of the edit control.
1055 static INT
CBUpdateLBox( LPHEADCOMBO lphc
)
1061 length
= CB_GETEDITTEXTLENGTH( lphc
);
1064 pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1);
1066 TRACE("\t edit text length %i\n", length
);
1070 if( length
) GetWindowTextA( lphc
->hWndEdit
, pText
, length
+ 1);
1071 else pText
[0] = '\0';
1072 idx
= SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
,
1073 (WPARAM
)(-1), (LPARAM
)pText
);
1074 HeapFree( GetProcessHeap(), 0, pText
);
1079 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)idx
, 0 );
1080 /* probably superfluous but Windows sends this too */
1081 SendMessageA( lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)idx
, 0 );
1086 /***********************************************************************
1089 * Copy a listbox entry to the edit control.
1091 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1096 TRACE("\t %i\n", index
);
1098 if( index
>= 0 ) /* got an entry */
1100 length
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1103 if( (pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1)) )
1105 SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
,
1106 (WPARAM
)index
, (LPARAM
)pText
);
1111 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1113 SendMessageA( lphc
->hWndEdit
, WM_SETTEXT
, 0, pText
? (LPARAM
)pText
: (LPARAM
)"" );
1116 HeapFree( GetProcessHeap(), 0, pText
);
1119 /***********************************************************************
1122 * Show listbox popup.
1124 static void CBDropDown( LPHEADCOMBO lphc
)
1130 int nDroppedHeight
, nTempDroppedHeight
;
1132 TRACE("[%04x]: drop down\n", CB_HWND(lphc
));
1134 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1138 lphc
->wState
|= CBF_DROPPED
;
1139 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1141 lphc
->droppedIndex
= CBUpdateLBox( lphc
);
1143 if( !(lphc
->wState
& CBF_CAPTURE
) )
1144 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1148 lphc
->droppedIndex
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1150 if( lphc
->droppedIndex
== LB_ERR
)
1151 lphc
->droppedIndex
= 0;
1153 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)lphc
->droppedIndex
, 0 );
1154 SendMessageA( lphc
->hWndLBox
, LB_CARETON
, 0, 0 );
1157 /* now set popup position */
1158 GetWindowRect( lphc
->self
->hwndSelf
, &rect
);
1161 * If it's a dropdown, the listbox is offset
1163 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1164 rect
.left
+= COMBO_EDITBUTTONSPACE();
1166 /* if the dropped height is greater than the total height of the dropped
1167 items list, then force the drop down list height to be the total height
1168 of the items in the dropped list */
1170 /* And Remove any extra space (Best Fit) */
1171 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1172 nItems
= (int)SendMessageA (lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1173 nHeight
= COMBO_YBORDERSIZE();
1174 nTempDroppedHeight
= 0;
1175 for (i
= 0; i
< nItems
; i
++)
1177 nHeight
+= (int)SendMessageA (lphc
->hWndLBox
, LB_GETITEMHEIGHT
, i
, 0);
1179 /* Did we pass the limit of what can be displayed */
1180 if (nHeight
> nDroppedHeight
)
1184 nTempDroppedHeight
= nHeight
;
1187 nDroppedHeight
= nTempDroppedHeight
;
1189 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1190 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1192 SWP_NOACTIVATE
| SWP_NOREDRAW
);
1194 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1195 RedrawWindow( lphc
->self
->hwndSelf
, NULL
, 0, RDW_INVALIDATE
|
1196 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1198 ShowWindow( lphc
->hWndLBox
, SW_SHOWNA
);
1201 /***********************************************************************
1204 * Hide listbox popup.
1206 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1208 HWND hWnd
= lphc
->self
->hwndSelf
;
1210 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1212 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1215 TRACE("[%04x]: roll up [%i]\n", CB_HWND(lphc
), (INT
)ok
);
1217 if( lphc
->wState
& CBF_DROPPED
)
1221 lphc
->wState
&= ~CBF_DROPPED
;
1222 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1223 if(GetCapture() == lphc
->hWndLBox
)
1228 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1230 INT index
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1231 CBUpdateEdit( lphc
, index
);
1232 rect
= lphc
->buttonRect
;
1243 rect
= lphc
->textRect
;
1248 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1249 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1250 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1251 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1256 /***********************************************************************
1259 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1261 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL bRedrawButton
)
1263 if( lphc
->wState
& CBF_DROPPED
)
1265 CBRollUp( lphc
, TRUE
, bRedrawButton
);
1273 /***********************************************************************
1276 * Edit control helper.
1278 HWND
COMBO_GetLBWindow( WND
* pWnd
)
1280 LPHEADCOMBO lphc
= CB_GETPTR(pWnd
);
1281 if( lphc
) return lphc
->hWndLBox
;
1286 /***********************************************************************
1289 static void CBRepaintButton( LPHEADCOMBO lphc
)
1291 InvalidateRect(CB_HWND(lphc
), &lphc
->buttonRect
, TRUE
);
1292 UpdateWindow(CB_HWND(lphc
));
1295 /***********************************************************************
1298 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1300 if( !(lphc
->wState
& CBF_FOCUSED
) )
1302 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1303 SendMessageA( lphc
->hWndLBox
, LB_CARETON
, 0, 0 );
1305 lphc
->wState
|= CBF_FOCUSED
;
1307 if( !(lphc
->wState
& CBF_EDIT
) )
1308 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1310 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1314 /***********************************************************************
1317 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1319 HWND hWnd
= lphc
->self
->hwndSelf
;
1321 if( lphc
->wState
& CBF_FOCUSED
)
1323 CBRollUp( lphc
, FALSE
, TRUE
);
1324 if( IsWindow( hWnd
) )
1326 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1327 SendMessageA( lphc
->hWndLBox
, LB_CARETOFF
, 0, 0 );
1329 lphc
->wState
&= ~CBF_FOCUSED
;
1332 if( !(lphc
->wState
& CBF_EDIT
) )
1333 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1335 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1340 /***********************************************************************
1343 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1345 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1347 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1349 switch( HIWORD(wParam
) >> 8 )
1351 case (EN_SETFOCUS
>> 8):
1353 TRACE("[%04x]: edit [%04x] got focus\n",
1354 CB_HWND(lphc
), lphc
->hWndEdit
);
1356 COMBO_SetFocus( lphc
);
1359 case (EN_KILLFOCUS
>> 8):
1361 TRACE("[%04x]: edit [%04x] lost focus\n",
1362 CB_HWND(lphc
), lphc
->hWndEdit
);
1364 /* NOTE: it seems that Windows' edit control sends an
1365 * undocumented message WM_USER + 0x1B instead of this
1366 * notification (only when it happens to be a part of
1367 * the combo). ?? - AK.
1370 COMBO_KillFocus( lphc
);
1374 case (EN_CHANGE
>> 8):
1376 * In some circumstances (when the selection of the combobox
1377 * is changed for example) we don't wans the EN_CHANGE notification
1378 * to be forwarded to the parent of the combobox. This code
1379 * checks a flag that is set in these occasions and ignores the
1382 if (lphc
->wState
& CBF_NOEDITNOTIFY
)
1384 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1388 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1391 CBUpdateLBox( lphc
);
1394 case (EN_UPDATE
>> 8):
1395 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1398 case (EN_ERRSPACE
>> 8):
1399 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1402 else if( lphc
->hWndLBox
== hWnd
)
1404 switch( HIWORD(wParam
) )
1407 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1411 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1417 TRACE("[%04x]: lbox selection change [%04x]\n",
1418 CB_HWND(lphc
), lphc
->wState
);
1420 /* do not roll up if selection is being tracked
1421 * by arrowkeys in the dropdown listbox */
1423 if( (lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
) )
1424 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1425 else lphc
->wState
&= ~CBF_NOROLLUP
;
1427 if( lphc
->wState
& CBF_EDIT
)
1429 INT index
= SendMessageA(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1430 CBUpdateEdit( lphc
, index
);
1431 /* select text in edit, as Windows does */
1432 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1) );
1435 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1437 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1442 /* nothing to do here since ComboLBox always resets the focus to its
1443 * combo/edit counterpart */
1450 /***********************************************************************
1453 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1455 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
,
1456 WPARAM wParam
, LPARAM lParam
)
1458 HWND hWnd
= lphc
->self
->hwndSelf
;
1460 TRACE("[%04x]: ownerdraw op %04x\n", CB_HWND(lphc
), msg
);
1462 #define lpIS ((LPDELETEITEMSTRUCT)lParam)
1464 /* two first items are the same in all 4 structs */
1465 lpIS
->CtlType
= ODT_COMBOBOX
;
1466 lpIS
->CtlID
= lphc
->self
->wIDmenu
;
1468 switch( msg
) /* patch window handle */
1471 lpIS
->hwndItem
= hWnd
;
1475 #define lpIS ((LPDRAWITEMSTRUCT)lParam)
1476 lpIS
->hwndItem
= hWnd
;
1479 case WM_COMPAREITEM
:
1480 #define lpIS ((LPCOMPAREITEMSTRUCT)lParam)
1481 lpIS
->hwndItem
= hWnd
;
1486 return SendMessageA( lphc
->owner
, msg
, lphc
->self
->wIDmenu
, lParam
);
1489 /***********************************************************************
1492 static LRESULT
COMBO_GetText( LPHEADCOMBO lphc
, UINT N
, LPSTR lpText
)
1494 if( lphc
->wState
& CBF_EDIT
)
1495 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
,
1496 (WPARAM
)N
, (LPARAM
)lpText
);
1498 /* get it from the listbox */
1500 if( lphc
->hWndLBox
)
1502 INT idx
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1506 INT length
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
,
1509 /* 'length' is without the terminating character */
1511 lpBuffer
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1 );
1517 INT n
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
,
1518 (WPARAM
)idx
, (LPARAM
)lpBuffer
);
1520 /* truncate if buffer is too short */
1525 if( n
!= LB_ERR
) memcpy( lpText
, lpBuffer
, (N
>n
) ? n
+1 : N
-1 );
1526 lpText
[N
- 1] = '\0';
1528 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1538 /***********************************************************************
1541 * This function sets window positions according to the updated
1542 * component placement struct.
1544 static void CBResetPos(
1550 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1552 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1553 * sizing messages */
1555 if( lphc
->wState
& CBF_EDIT
)
1556 SetWindowPos( lphc
->hWndEdit
, 0,
1557 rectEdit
->left
, rectEdit
->top
,
1558 rectEdit
->right
- rectEdit
->left
,
1559 rectEdit
->bottom
- rectEdit
->top
,
1560 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1562 SetWindowPos( lphc
->hWndLBox
, 0,
1563 rectLB
->left
, rectLB
->top
,
1564 rectLB
->right
- rectLB
->left
,
1565 rectLB
->bottom
- rectLB
->top
,
1566 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1570 if( lphc
->wState
& CBF_DROPPED
)
1572 lphc
->wState
&= ~CBF_DROPPED
;
1573 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1576 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1577 RedrawWindow( lphc
->self
->hwndSelf
, NULL
, 0,
1578 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1583 /***********************************************************************
1586 static void COMBO_Size( LPHEADCOMBO lphc
)
1588 CBCalcPlacement(lphc
->self
->hwndSelf
,
1592 &lphc
->droppedRect
);
1594 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1598 /***********************************************************************
1601 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1606 lphc
->hFont
= hFont
;
1609 * Propagate to owned windows.
1611 if( lphc
->wState
& CBF_EDIT
)
1612 SendMessageA( lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1613 SendMessageA( lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1616 * Redo the layout of the control.
1618 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1620 CBCalcPlacement(lphc
->self
->hwndSelf
,
1624 &lphc
->droppedRect
);
1626 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1630 CBForceDummyResize(lphc
);
1635 /***********************************************************************
1636 * COMBO_SetItemHeight
1638 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1640 LRESULT lRet
= CB_ERR
;
1642 if( index
== -1 ) /* set text field height */
1644 if( height
< 32768 )
1646 lphc
->editHeight
= height
;
1649 * Redo the layout of the control.
1651 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1653 CBCalcPlacement(lphc
->self
->hwndSelf
,
1657 &lphc
->droppedRect
);
1659 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1663 CBForceDummyResize(lphc
);
1669 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1670 lRet
= SendMessageA( lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1671 (WPARAM
)index
, (LPARAM
)height
);
1675 /***********************************************************************
1676 * COMBO_SelectString
1678 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPCSTR pText
)
1680 INT index
= SendMessageA( lphc
->hWndLBox
, LB_SELECTSTRING
,
1681 (WPARAM
)start
, (LPARAM
)pText
);
1684 if( lphc
->wState
& CBF_EDIT
)
1685 CBUpdateEdit( lphc
, index
);
1688 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1691 return (LRESULT
)index
;
1694 /***********************************************************************
1697 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1701 HWND hWnd
= lphc
->self
->hwndSelf
;
1703 pt
.x
= LOWORD(lParam
);
1704 pt
.y
= HIWORD(lParam
);
1705 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1707 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1708 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1710 lphc
->wState
|= CBF_BUTTONDOWN
;
1711 if( lphc
->wState
& CBF_DROPPED
)
1713 /* got a click to cancel selection */
1715 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1716 CBRollUp( lphc
, TRUE
, FALSE
);
1717 if( !IsWindow( hWnd
) ) return;
1719 if( lphc
->wState
& CBF_CAPTURE
)
1721 lphc
->wState
&= ~CBF_CAPTURE
;
1727 /* drop down the listbox and start tracking */
1729 lphc
->wState
|= CBF_CAPTURE
;
1733 if( bButton
) CBRepaintButton( lphc
);
1737 /***********************************************************************
1740 * Release capture and stop tracking if needed.
1742 static void COMBO_LButtonUp( LPHEADCOMBO lphc
, LPARAM lParam
)
1744 if( lphc
->wState
& CBF_CAPTURE
)
1746 lphc
->wState
&= ~CBF_CAPTURE
;
1747 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1749 INT index
= CBUpdateLBox( lphc
);
1750 CBUpdateEdit( lphc
, index
);
1753 SetCapture(lphc
->hWndLBox
);
1757 if( lphc
->wState
& CBF_BUTTONDOWN
)
1759 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1760 CBRepaintButton( lphc
);
1764 /***********************************************************************
1767 * Two things to do - track combo button and release capture when
1768 * pointer goes into the listbox.
1770 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1775 pt
.x
= LOWORD(lParam
);
1776 pt
.y
= HIWORD(lParam
);
1778 if( lphc
->wState
& CBF_BUTTONDOWN
)
1782 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1786 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1787 CBRepaintButton( lphc
);
1791 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1792 MapWindowPoints( lphc
->self
->hwndSelf
, lphc
->hWndLBox
, &pt
, 1 );
1793 if( PtInRect(&lbRect
, pt
) )
1795 lphc
->wState
&= ~CBF_CAPTURE
;
1797 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
);
1799 /* hand over pointer tracking */
1800 SendMessageA( lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1805 /***********************************************************************
1806 * ComboWndProc_locked
1808 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1810 static inline LRESULT WINAPI
ComboWndProc_locked( WND
* pWnd
, UINT message
,
1811 WPARAM wParam
, LPARAM lParam
)
1814 LPHEADCOMBO lphc
= CB_GETPTR(pWnd
);
1815 HWND hwnd
= pWnd
->hwndSelf
;
1817 TRACE("[%04x]: msg %s wp %08x lp %08lx\n",
1818 pWnd
->hwndSelf
, SPY_GetMsgName(message
), wParam
, lParam
);
1820 if( lphc
|| message
== WM_NCCREATE
)
1824 /* System messages */
1827 return COMBO_NCCreate(pWnd
, lParam
);
1829 COMBO_NCDestroy(lphc
);
1830 break;/* -> DefWindowProc */
1833 return COMBO_Create(lphc
, pWnd
, lParam
);
1835 case WM_PRINTCLIENT
:
1836 if (lParam
& PRF_ERASEBKGND
)
1837 COMBO_EraseBackground(hwnd
, lphc
, wParam
);
1841 /* wParam may contain a valid HDC! */
1842 return COMBO_Paint(lphc
, wParam
);
1844 return COMBO_EraseBackground(hwnd
, lphc
, wParam
);
1846 return (LRESULT
)(DLGC_WANTARROWS
| DLGC_WANTCHARS
);
1847 case WM_WINDOWPOSCHANGING
:
1848 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1850 if( lphc
->hWndLBox
&&
1851 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
);
1854 COMBO_Font( lphc
, (HFONT16
)wParam
, (BOOL
)lParam
);
1857 return (LRESULT
)lphc
->hFont
;
1859 if( lphc
->wState
& CBF_EDIT
)
1860 SetFocus( lphc
->hWndEdit
);
1862 COMBO_SetFocus( lphc
);
1865 #define hwndFocus ((HWND16)wParam)
1867 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1868 COMBO_KillFocus( lphc
);
1872 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1874 return COMBO_GetText( lphc
, (UINT
)wParam
, (LPSTR
)lParam
);
1876 case WM_GETTEXTLENGTH
:
1881 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1883 int j
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1884 if (j
== -1) return 0;
1885 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1887 else if( lphc
->wState
& CBF_EDIT
)
1889 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1891 return SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1897 case WM_COMPAREITEM
:
1898 case WM_MEASUREITEM
:
1899 return COMBO_ItemOp( lphc
, message
, wParam
, lParam
);
1901 if( lphc
->wState
& CBF_EDIT
)
1902 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
1903 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
1905 /* Force the control to repaint when the enabled state changes. */
1906 InvalidateRect(CB_HWND(lphc
), NULL
, TRUE
);
1910 lphc
->wState
&= ~CBF_NOREDRAW
;
1912 lphc
->wState
|= CBF_NOREDRAW
;
1914 if( lphc
->wState
& CBF_EDIT
)
1915 SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1916 SendMessageA( lphc
->hWndLBox
, message
, wParam
, lParam
);
1919 if( KEYDATA_ALT
& HIWORD(lParam
) )
1920 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
1921 COMBO_FlipListbox( lphc
, TRUE
);
1922 break;/* -> DefWindowProc */
1926 if( lphc
->wState
& CBF_EDIT
)
1927 return SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1929 return SendMessageA( lphc
->hWndLBox
, message
, wParam
, lParam
);
1930 case WM_LBUTTONDOWN
:
1931 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
->hwndSelf
);
1932 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
1935 COMBO_LButtonUp( lphc
, lParam
);
1938 if( lphc
->wState
& CBF_CAPTURE
)
1939 COMBO_MouseMove( lphc
, wParam
, lParam
);
1941 /* Combo messages */
1943 case CB_ADDSTRING16
:
1944 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1946 return SendMessageA( lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
1947 case CB_INSERTSTRING16
:
1948 wParam
= (INT
)(INT16
)wParam
;
1949 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1950 case CB_INSERTSTRING
:
1951 return SendMessageA( lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
1952 case CB_DELETESTRING16
:
1953 case CB_DELETESTRING
:
1954 return SendMessageA( lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
1955 case CB_SELECTSTRING16
:
1956 wParam
= (INT
)(INT16
)wParam
;
1957 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1958 case CB_SELECTSTRING
:
1959 return COMBO_SelectString( lphc
, (INT
)wParam
, (LPSTR
)lParam
);
1960 case CB_FINDSTRING16
:
1961 wParam
= (INT
)(INT16
)wParam
;
1962 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1964 return SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
1965 case CB_FINDSTRINGEXACT16
:
1966 wParam
= (INT
)(INT16
)wParam
;
1967 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1968 case CB_FINDSTRINGEXACT
:
1969 return SendMessageA( lphc
->hWndLBox
, LB_FINDSTRINGEXACT
,
1971 case CB_SETITEMHEIGHT16
:
1972 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
1973 case CB_SETITEMHEIGHT
:
1974 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
1975 case CB_GETITEMHEIGHT16
:
1976 wParam
= (INT
)(INT16
)wParam
;
1977 case CB_GETITEMHEIGHT
:
1978 if( (INT
)wParam
>= 0 ) /* listbox item */
1979 return SendMessageA( lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
1980 return CBGetTextAreaHeight(hwnd
, lphc
);
1981 case CB_RESETCONTENT16
:
1982 case CB_RESETCONTENT
:
1983 SendMessageA( lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0 );
1984 InvalidateRect(CB_HWND(lphc
), NULL
, TRUE
);
1986 case CB_INITSTORAGE
:
1987 return SendMessageA( lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
1988 case CB_GETHORIZONTALEXTENT
:
1989 return SendMessageA( lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
1990 case CB_SETHORIZONTALEXTENT
:
1991 return SendMessageA( lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
1992 case CB_GETTOPINDEX
:
1993 return SendMessageA( lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
1995 return SendMessageA( lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
1997 return SendMessageA( lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
1998 case CB_GETDROPPEDWIDTH
:
1999 if( lphc
->droppedWidth
)
2000 return lphc
->droppedWidth
;
2001 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2002 case CB_SETDROPPEDWIDTH
:
2003 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2004 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2006 case CB_GETDROPPEDCONTROLRECT16
:
2007 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2011 CBGetDroppedControlRect( lphc
, &r
);
2012 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2015 case CB_GETDROPPEDCONTROLRECT
:
2016 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2018 case CB_GETDROPPEDSTATE16
:
2019 case CB_GETDROPPEDSTATE
:
2020 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2022 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2025 return COMBO_Directory( lphc
, (UINT
)wParam
,
2026 (LPSTR
)lParam
, (message
== CB_DIR
));
2027 case CB_SHOWDROPDOWN16
:
2028 case CB_SHOWDROPDOWN
:
2029 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2033 if( !(lphc
->wState
& CBF_DROPPED
) )
2037 if( lphc
->wState
& CBF_DROPPED
)
2038 CBRollUp( lphc
, FALSE
, TRUE
);
2043 return SendMessageA( lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2044 case CB_GETCURSEL16
:
2046 return SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2047 case CB_SETCURSEL16
:
2048 wParam
= (INT
)(INT16
)wParam
;
2050 lParam
= SendMessageA( lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2051 if( lphc
->wState
& CBF_SELCHANGE
)
2053 /* no LBN_SELCHANGE in this case, update manually */
2054 if( lphc
->wState
& CBF_EDIT
)
2055 CBUpdateEdit( lphc
, (INT
)wParam
);
2057 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
2058 lphc
->wState
&= ~CBF_SELCHANGE
;
2061 case CB_GETLBTEXT16
:
2062 wParam
= (INT
)(INT16
)wParam
;
2063 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2065 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2066 case CB_GETLBTEXTLEN16
:
2067 wParam
= (INT
)(INT16
)wParam
;
2068 case CB_GETLBTEXTLEN
:
2069 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2070 case CB_GETITEMDATA16
:
2071 wParam
= (INT
)(INT16
)wParam
;
2072 case CB_GETITEMDATA
:
2073 return SendMessageA( lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2074 case CB_SETITEMDATA16
:
2075 wParam
= (INT
)(INT16
)wParam
;
2076 case CB_SETITEMDATA
:
2077 return SendMessageA( lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2078 case CB_GETEDITSEL16
:
2079 wParam
= lParam
= 0; /* just in case */
2081 if( lphc
->wState
& CBF_EDIT
)
2085 return SendMessageA( lphc
->hWndEdit
, EM_GETSEL
,
2086 (wParam
) ? wParam
: (WPARAM
)&a
,
2087 (lParam
) ? lParam
: (LPARAM
)&b
);
2090 case CB_SETEDITSEL16
:
2092 if( lphc
->wState
& CBF_EDIT
)
2093 return SendMessageA( lphc
->hWndEdit
, EM_SETSEL
,
2094 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2096 case CB_SETEXTENDEDUI16
:
2097 case CB_SETEXTENDEDUI
:
2098 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2101 lphc
->wState
|= CBF_EUI
;
2102 else lphc
->wState
&= ~CBF_EUI
;
2104 case CB_GETEXTENDEDUI16
:
2105 case CB_GETEXTENDEDUI
:
2106 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2109 if (message
>= WM_USER
)
2110 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2111 message
- WM_USER
, wParam
, lParam
);
2114 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2119 /***********************************************************************
2122 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2125 LRESULT WINAPI
ComboWndProc( HWND hwnd
, UINT message
,
2126 WPARAM wParam
, LPARAM lParam
)
2128 WND
* pWnd
= WIN_FindWndPtr(hwnd
);
2129 LRESULT retvalue
= ComboWndProc_locked(pWnd
,message
,wParam
,lParam
);
2132 WIN_ReleaseWndPtr(pWnd
);