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
)
1057 INT length
, idx
, ret
;
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 if( idx
== LB_ERR
) idx
= 0; /* select first item */
1076 HeapFree( GetProcessHeap(), 0, pText
);
1081 SendMessageA( lphc
->hWndLBox
, LB_SETCURSEL
, (WPARAM
)idx
, 0 );
1085 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)idx
, 0 );
1086 /* probably superfluous but Windows sends this too */
1087 SendMessageA( lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)idx
, 0 );
1092 /***********************************************************************
1095 * Copy a listbox entry to the edit control.
1097 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1102 TRACE("\t %i\n", index
);
1106 length
= CB_GETEDITTEXTLENGTH( lphc
);
1109 if( (pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1)) )
1111 GetWindowTextA( lphc
->hWndEdit
, pText
, length
+ 1 );
1112 index
= SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
,
1113 (WPARAM
)(-1), (LPARAM
)pText
);
1114 HeapFree( GetProcessHeap(), 0, pText
);
1119 if( index
>= 0 ) /* got an entry */
1121 length
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1124 if( (pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1)) )
1126 SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
,
1127 (WPARAM
)index
, (LPARAM
)pText
);
1129 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1131 SendMessageA( lphc
->hWndEdit
, WM_SETTEXT
, 0, (LPARAM
)pText
);
1132 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1) );
1133 HeapFree( GetProcessHeap(), 0, pText
);
1139 /***********************************************************************
1142 * Show listbox popup.
1144 static void CBDropDown( LPHEADCOMBO lphc
)
1150 int nDroppedHeight
, nTempDroppedHeight
;
1152 TRACE("[%04x]: drop down\n", CB_HWND(lphc
));
1154 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1158 lphc
->wState
|= CBF_DROPPED
;
1159 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1161 lphc
->droppedIndex
= CBUpdateLBox( lphc
);
1163 if( !(lphc
->wState
& CBF_CAPTURE
) )
1164 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1168 lphc
->droppedIndex
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1170 if( lphc
->droppedIndex
== LB_ERR
)
1171 lphc
->droppedIndex
= 0;
1173 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)lphc
->droppedIndex
, 0 );
1174 SendMessageA( lphc
->hWndLBox
, LB_CARETON
, 0, 0 );
1177 /* now set popup position */
1178 GetWindowRect( lphc
->self
->hwndSelf
, &rect
);
1181 * If it's a dropdown, the listbox is offset
1183 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1184 rect
.left
+= COMBO_EDITBUTTONSPACE();
1186 /* if the dropped height is greater than the total height of the dropped
1187 items list, then force the drop down list height to be the total height
1188 of the items in the dropped list */
1190 /* And Remove any extra space (Best Fit) */
1191 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1192 nItems
= (int)SendMessageA (lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1193 nHeight
= COMBO_YBORDERSIZE();
1194 nTempDroppedHeight
= 0;
1195 for (i
= 0; i
< nItems
; i
++)
1197 nHeight
+= (int)SendMessageA (lphc
->hWndLBox
, LB_GETITEMHEIGHT
, i
, 0);
1199 /* Did we pass the limit of what can be displayed */
1200 if (nHeight
> nDroppedHeight
)
1204 nTempDroppedHeight
= nHeight
;
1207 nDroppedHeight
= nTempDroppedHeight
;
1209 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1210 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1212 SWP_NOACTIVATE
| SWP_NOREDRAW
);
1214 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1215 RedrawWindow( lphc
->self
->hwndSelf
, NULL
, 0, RDW_INVALIDATE
|
1216 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1218 ShowWindow( lphc
->hWndLBox
, SW_SHOWNA
);
1221 /***********************************************************************
1224 * Hide listbox popup.
1226 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1228 HWND hWnd
= lphc
->self
->hwndSelf
;
1230 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1232 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1235 TRACE("[%04x]: roll up [%i]\n", CB_HWND(lphc
), (INT
)ok
);
1237 if( lphc
->wState
& CBF_DROPPED
)
1242 * It seems useful to send the WM_LBUTTONUP with (-1,-1) when cancelling
1243 * and with (0,0) (anywhere in the listbox) when Oking.
1245 SendMessageA( lphc
->hWndLBox
, WM_LBUTTONUP
, 0, ok
? (LPARAM
)0 : (LPARAM
)(-1) );
1247 lphc
->wState
&= ~CBF_DROPPED
;
1248 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1249 if(GetCapture() == lphc
->hWndLBox
)
1255 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1257 INT index
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1258 CBUpdateEdit( lphc
, index
);
1259 rect
= lphc
->buttonRect
;
1270 rect
= lphc
->textRect
;
1275 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1276 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1277 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1278 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1283 /***********************************************************************
1286 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1288 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL bRedrawButton
)
1290 if( lphc
->wState
& CBF_DROPPED
)
1292 CBRollUp( lphc
, TRUE
, bRedrawButton
);
1300 /***********************************************************************
1303 * Edit control helper.
1305 HWND
COMBO_GetLBWindow( WND
* pWnd
)
1307 LPHEADCOMBO lphc
= CB_GETPTR(pWnd
);
1308 if( lphc
) return lphc
->hWndLBox
;
1313 /***********************************************************************
1316 static void CBRepaintButton( LPHEADCOMBO lphc
)
1318 InvalidateRect(CB_HWND(lphc
), &lphc
->buttonRect
, TRUE
);
1319 UpdateWindow(CB_HWND(lphc
));
1322 /***********************************************************************
1325 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1327 if( !(lphc
->wState
& CBF_FOCUSED
) )
1329 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1330 SendMessageA( lphc
->hWndLBox
, LB_CARETON
, 0, 0 );
1332 if( lphc
->wState
& CBF_EDIT
)
1333 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1) );
1334 lphc
->wState
|= CBF_FOCUSED
;
1335 if( !(lphc
->wState
& CBF_EDIT
) )
1337 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1340 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1344 /***********************************************************************
1347 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1349 HWND hWnd
= lphc
->self
->hwndSelf
;
1351 if( lphc
->wState
& CBF_FOCUSED
)
1353 SendMessageA( hWnd
, WM_LBUTTONUP
, 0, (LPARAM
)(-1) );
1355 CBRollUp( lphc
, FALSE
, TRUE
);
1356 if( IsWindow( hWnd
) )
1358 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1359 SendMessageA( lphc
->hWndLBox
, LB_CARETOFF
, 0, 0 );
1361 lphc
->wState
&= ~CBF_FOCUSED
;
1364 if( lphc
->wState
& CBF_EDIT
)
1365 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, (WPARAM
)(-1), 0 );
1368 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1371 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1376 /***********************************************************************
1379 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1381 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1383 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1385 switch( HIWORD(wParam
) >> 8 )
1387 case (EN_SETFOCUS
>> 8):
1389 TRACE("[%04x]: edit [%04x] got focus\n",
1390 CB_HWND(lphc
), lphc
->hWndEdit
);
1392 if( !(lphc
->wState
& CBF_FOCUSED
) ) COMBO_SetFocus( lphc
);
1395 case (EN_KILLFOCUS
>> 8):
1397 TRACE("[%04x]: edit [%04x] lost focus\n",
1398 CB_HWND(lphc
), lphc
->hWndEdit
);
1400 /* NOTE: it seems that Windows' edit control sends an
1401 * undocumented message WM_USER + 0x1B instead of this
1402 * notification (only when it happens to be a part of
1403 * the combo). ?? - AK.
1406 COMBO_KillFocus( lphc
);
1410 case (EN_CHANGE
>> 8):
1412 * In some circumstances (when the selection of the combobox
1413 * is changed for example) we don't wans the EN_CHANGE notification
1414 * to be forwarded to the parent of the combobox. This code
1415 * checks a flag that is set in these occasions and ignores the
1418 if (lphc
->wState
& CBF_NOEDITNOTIFY
)
1420 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1424 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1427 CBUpdateLBox( lphc
);
1430 case (EN_UPDATE
>> 8):
1431 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1434 case (EN_ERRSPACE
>> 8):
1435 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1438 else if( lphc
->hWndLBox
== hWnd
)
1440 switch( HIWORD(wParam
) )
1443 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1447 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1453 TRACE("[%04x]: lbox selection change [%04x]\n",
1454 CB_HWND(lphc
), lphc
->wState
);
1456 /* do not roll up if selection is being tracked
1457 * by arrowkeys in the dropdown listbox */
1459 if( (lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
) )
1460 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1461 else lphc
->wState
&= ~CBF_NOROLLUP
;
1463 if( lphc
->wState
& CBF_EDIT
)
1465 INT index
= SendMessageA(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1466 CBUpdateEdit( lphc
, index
);
1469 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1471 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1476 /* nothing to do here since ComboLBox always resets the focus to its
1477 * combo/edit counterpart */
1484 /***********************************************************************
1487 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1489 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
,
1490 WPARAM wParam
, LPARAM lParam
)
1492 HWND hWnd
= lphc
->self
->hwndSelf
;
1494 TRACE("[%04x]: ownerdraw op %04x\n", CB_HWND(lphc
), msg
);
1496 #define lpIS ((LPDELETEITEMSTRUCT)lParam)
1498 /* two first items are the same in all 4 structs */
1499 lpIS
->CtlType
= ODT_COMBOBOX
;
1500 lpIS
->CtlID
= lphc
->self
->wIDmenu
;
1502 switch( msg
) /* patch window handle */
1505 lpIS
->hwndItem
= hWnd
;
1509 #define lpIS ((LPDRAWITEMSTRUCT)lParam)
1510 lpIS
->hwndItem
= hWnd
;
1513 case WM_COMPAREITEM
:
1514 #define lpIS ((LPCOMPAREITEMSTRUCT)lParam)
1515 lpIS
->hwndItem
= hWnd
;
1520 return SendMessageA( lphc
->owner
, msg
, lphc
->self
->wIDmenu
, lParam
);
1523 /***********************************************************************
1526 static LRESULT
COMBO_GetText( LPHEADCOMBO lphc
, UINT N
, LPSTR lpText
)
1528 if( lphc
->wState
& CBF_EDIT
)
1529 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
,
1530 (WPARAM
)N
, (LPARAM
)lpText
);
1532 /* get it from the listbox */
1534 if( lphc
->hWndLBox
)
1536 INT idx
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1540 INT length
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
,
1543 /* 'length' is without the terminating character */
1545 lpBuffer
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1 );
1551 INT n
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
,
1552 (WPARAM
)idx
, (LPARAM
)lpBuffer
);
1554 /* truncate if buffer is too short */
1559 if( n
!= LB_ERR
) memcpy( lpText
, lpBuffer
, (N
>n
) ? n
+1 : N
-1 );
1560 lpText
[N
- 1] = '\0';
1562 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1572 /***********************************************************************
1575 * This function sets window positions according to the updated
1576 * component placement struct.
1578 static void CBResetPos(
1584 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1586 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1587 * sizing messages */
1589 if( lphc
->wState
& CBF_EDIT
)
1590 SetWindowPos( lphc
->hWndEdit
, 0,
1591 rectEdit
->left
, rectEdit
->top
,
1592 rectEdit
->right
- rectEdit
->left
,
1593 rectEdit
->bottom
- rectEdit
->top
,
1594 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1596 SetWindowPos( lphc
->hWndLBox
, 0,
1597 rectLB
->left
, rectLB
->top
,
1598 rectLB
->right
- rectLB
->left
,
1599 rectLB
->bottom
- rectLB
->top
,
1600 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1604 if( lphc
->wState
& CBF_DROPPED
)
1606 lphc
->wState
&= ~CBF_DROPPED
;
1607 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1610 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1611 RedrawWindow( lphc
->self
->hwndSelf
, NULL
, 0,
1612 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1617 /***********************************************************************
1620 static void COMBO_Size( LPHEADCOMBO lphc
)
1622 CBCalcPlacement(lphc
->self
->hwndSelf
,
1626 &lphc
->droppedRect
);
1628 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1632 /***********************************************************************
1635 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1640 lphc
->hFont
= hFont
;
1643 * Propagate to owned windows.
1645 if( lphc
->wState
& CBF_EDIT
)
1646 SendMessageA( lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1647 SendMessageA( lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1650 * Redo the layout of the control.
1652 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1654 CBCalcPlacement(lphc
->self
->hwndSelf
,
1658 &lphc
->droppedRect
);
1660 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1664 CBForceDummyResize(lphc
);
1669 /***********************************************************************
1670 * COMBO_SetItemHeight
1672 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1674 LRESULT lRet
= CB_ERR
;
1676 if( index
== -1 ) /* set text field height */
1678 if( height
< 32768 )
1680 lphc
->editHeight
= height
;
1683 * Redo the layout of the control.
1685 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1687 CBCalcPlacement(lphc
->self
->hwndSelf
,
1691 &lphc
->droppedRect
);
1693 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1697 CBForceDummyResize(lphc
);
1703 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1704 lRet
= SendMessageA( lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1705 (WPARAM
)index
, (LPARAM
)height
);
1709 /***********************************************************************
1710 * COMBO_SelectString
1712 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPCSTR pText
)
1714 INT index
= SendMessageA( lphc
->hWndLBox
, LB_SELECTSTRING
,
1715 (WPARAM
)start
, (LPARAM
)pText
);
1718 if( lphc
->wState
& CBF_EDIT
)
1719 CBUpdateEdit( lphc
, index
);
1722 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1725 return (LRESULT
)index
;
1728 /***********************************************************************
1731 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1735 HWND hWnd
= lphc
->self
->hwndSelf
;
1737 pt
.x
= LOWORD(lParam
);
1738 pt
.y
= HIWORD(lParam
);
1739 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1741 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1742 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1744 lphc
->wState
|= CBF_BUTTONDOWN
;
1745 if( lphc
->wState
& CBF_DROPPED
)
1747 /* got a click to cancel selection */
1749 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1750 CBRollUp( lphc
, TRUE
, FALSE
);
1751 if( !IsWindow( hWnd
) ) return;
1753 if( lphc
->wState
& CBF_CAPTURE
)
1755 lphc
->wState
&= ~CBF_CAPTURE
;
1761 /* drop down the listbox and start tracking */
1763 lphc
->wState
|= CBF_CAPTURE
;
1767 if( bButton
) CBRepaintButton( lphc
);
1771 /***********************************************************************
1774 * Release capture and stop tracking if needed.
1776 static void COMBO_LButtonUp( LPHEADCOMBO lphc
, LPARAM lParam
)
1778 if( lphc
->wState
& CBF_CAPTURE
)
1780 lphc
->wState
&= ~CBF_CAPTURE
;
1781 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1783 INT index
= CBUpdateLBox( lphc
);
1784 CBUpdateEdit( lphc
, index
);
1787 SetCapture(lphc
->hWndLBox
);
1791 if( lphc
->wState
& CBF_BUTTONDOWN
)
1793 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1794 CBRepaintButton( lphc
);
1798 /***********************************************************************
1801 * Two things to do - track combo button and release capture when
1802 * pointer goes into the listbox.
1804 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1809 pt
.x
= LOWORD(lParam
);
1810 pt
.y
= HIWORD(lParam
);
1812 if( lphc
->wState
& CBF_BUTTONDOWN
)
1816 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1820 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1821 CBRepaintButton( lphc
);
1825 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1826 MapWindowPoints( lphc
->self
->hwndSelf
, lphc
->hWndLBox
, &pt
, 1 );
1827 if( PtInRect(&lbRect
, pt
) )
1829 lphc
->wState
&= ~CBF_CAPTURE
;
1831 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
);
1833 /* hand over pointer tracking */
1834 SendMessageA( lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1839 /***********************************************************************
1840 * ComboWndProc_locked
1842 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1844 static inline LRESULT WINAPI
ComboWndProc_locked( WND
* pWnd
, UINT message
,
1845 WPARAM wParam
, LPARAM lParam
)
1848 LPHEADCOMBO lphc
= CB_GETPTR(pWnd
);
1849 HWND hwnd
= pWnd
->hwndSelf
;
1851 TRACE("[%04x]: msg %s wp %08x lp %08lx\n",
1852 pWnd
->hwndSelf
, SPY_GetMsgName(message
), wParam
, lParam
);
1854 if( lphc
|| message
== WM_NCCREATE
)
1858 /* System messages */
1861 return COMBO_NCCreate(pWnd
, lParam
);
1863 COMBO_NCDestroy(lphc
);
1864 break;/* -> DefWindowProc */
1867 return COMBO_Create(lphc
, pWnd
, lParam
);
1869 case WM_PRINTCLIENT
:
1870 if (lParam
& PRF_ERASEBKGND
)
1871 COMBO_EraseBackground(hwnd
, lphc
, wParam
);
1875 /* wParam may contain a valid HDC! */
1876 return COMBO_Paint(lphc
, wParam
);
1878 return COMBO_EraseBackground(hwnd
, lphc
, wParam
);
1880 return (LRESULT
)(DLGC_WANTARROWS
| DLGC_WANTCHARS
);
1881 case WM_WINDOWPOSCHANGING
:
1882 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1884 if( lphc
->hWndLBox
&&
1885 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
);
1888 COMBO_Font( lphc
, (HFONT16
)wParam
, (BOOL
)lParam
);
1891 return (LRESULT
)lphc
->hFont
;
1893 if( lphc
->wState
& CBF_EDIT
)
1894 SetFocus( lphc
->hWndEdit
);
1896 COMBO_SetFocus( lphc
);
1899 #define hwndFocus ((HWND16)wParam)
1901 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1902 COMBO_KillFocus( lphc
);
1906 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1908 return COMBO_GetText( lphc
, (UINT
)wParam
, (LPSTR
)lParam
);
1910 case WM_GETTEXTLENGTH
:
1915 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1917 int j
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1918 if (j
== -1) return 0;
1919 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1921 else if( lphc
->wState
& CBF_EDIT
)
1923 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1925 return SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1931 case WM_COMPAREITEM
:
1932 case WM_MEASUREITEM
:
1933 return COMBO_ItemOp( lphc
, message
, wParam
, lParam
);
1935 if( lphc
->wState
& CBF_EDIT
)
1936 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
1937 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
1939 /* Force the control to repaint when the enabled state changes. */
1940 InvalidateRect(CB_HWND(lphc
), NULL
, TRUE
);
1944 lphc
->wState
&= ~CBF_NOREDRAW
;
1946 lphc
->wState
|= CBF_NOREDRAW
;
1948 if( lphc
->wState
& CBF_EDIT
)
1949 SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1950 SendMessageA( lphc
->hWndLBox
, message
, wParam
, lParam
);
1953 if( KEYDATA_ALT
& HIWORD(lParam
) )
1954 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
1955 COMBO_FlipListbox( lphc
, TRUE
);
1956 break;/* -> DefWindowProc */
1960 if( lphc
->wState
& CBF_EDIT
)
1961 return SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1963 return SendMessageA( lphc
->hWndLBox
, message
, wParam
, lParam
);
1964 case WM_LBUTTONDOWN
:
1965 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
->hwndSelf
);
1966 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
1969 COMBO_LButtonUp( lphc
, lParam
);
1972 if( lphc
->wState
& CBF_CAPTURE
)
1973 COMBO_MouseMove( lphc
, wParam
, lParam
);
1975 /* Combo messages */
1977 case CB_ADDSTRING16
:
1978 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1980 return SendMessageA( lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
1981 case CB_INSERTSTRING16
:
1982 wParam
= (INT
)(INT16
)wParam
;
1983 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1984 case CB_INSERTSTRING
:
1985 return SendMessageA( lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
1986 case CB_DELETESTRING16
:
1987 case CB_DELETESTRING
:
1988 return SendMessageA( lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
1989 case CB_SELECTSTRING16
:
1990 wParam
= (INT
)(INT16
)wParam
;
1991 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1992 case CB_SELECTSTRING
:
1993 return COMBO_SelectString( lphc
, (INT
)wParam
, (LPSTR
)lParam
);
1994 case CB_FINDSTRING16
:
1995 wParam
= (INT
)(INT16
)wParam
;
1996 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1998 return SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
1999 case CB_FINDSTRINGEXACT16
:
2000 wParam
= (INT
)(INT16
)wParam
;
2001 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2002 case CB_FINDSTRINGEXACT
:
2003 return SendMessageA( lphc
->hWndLBox
, LB_FINDSTRINGEXACT
,
2005 case CB_SETITEMHEIGHT16
:
2006 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
2007 case CB_SETITEMHEIGHT
:
2008 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
2009 case CB_GETITEMHEIGHT16
:
2010 wParam
= (INT
)(INT16
)wParam
;
2011 case CB_GETITEMHEIGHT
:
2012 if( (INT
)wParam
>= 0 ) /* listbox item */
2013 return SendMessageA( lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
2014 return CBGetTextAreaHeight(hwnd
, lphc
);
2015 case CB_RESETCONTENT16
:
2016 case CB_RESETCONTENT
:
2017 SendMessageA( lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0 );
2018 InvalidateRect(CB_HWND(lphc
), NULL
, TRUE
);
2020 case CB_INITSTORAGE
:
2021 return SendMessageA( lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
2022 case CB_GETHORIZONTALEXTENT
:
2023 return SendMessageA( lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
2024 case CB_SETHORIZONTALEXTENT
:
2025 return SendMessageA( lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
2026 case CB_GETTOPINDEX
:
2027 return SendMessageA( lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2029 return SendMessageA( lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2031 return SendMessageA( lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2032 case CB_GETDROPPEDWIDTH
:
2033 if( lphc
->droppedWidth
)
2034 return lphc
->droppedWidth
;
2035 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2036 case CB_SETDROPPEDWIDTH
:
2037 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2038 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2040 case CB_GETDROPPEDCONTROLRECT16
:
2041 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2045 CBGetDroppedControlRect( lphc
, &r
);
2046 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2049 case CB_GETDROPPEDCONTROLRECT
:
2050 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2052 case CB_GETDROPPEDSTATE16
:
2053 case CB_GETDROPPEDSTATE
:
2054 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2056 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2059 return COMBO_Directory( lphc
, (UINT
)wParam
,
2060 (LPSTR
)lParam
, (message
== CB_DIR
));
2061 case CB_SHOWDROPDOWN16
:
2062 case CB_SHOWDROPDOWN
:
2063 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2067 if( !(lphc
->wState
& CBF_DROPPED
) )
2071 if( lphc
->wState
& CBF_DROPPED
)
2072 CBRollUp( lphc
, FALSE
, TRUE
);
2077 return SendMessageA( lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2078 case CB_GETCURSEL16
:
2080 return SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2081 case CB_SETCURSEL16
:
2082 wParam
= (INT
)(INT16
)wParam
;
2084 lParam
= SendMessageA( lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2085 if( lphc
->wState
& CBF_SELCHANGE
)
2087 /* no LBN_SELCHANGE in this case, update manually */
2088 if( lphc
->wState
& CBF_EDIT
)
2089 CBUpdateEdit( lphc
, (INT
)wParam
);
2091 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
2092 lphc
->wState
&= ~CBF_SELCHANGE
;
2095 case CB_GETLBTEXT16
:
2096 wParam
= (INT
)(INT16
)wParam
;
2097 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2099 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2100 case CB_GETLBTEXTLEN16
:
2101 wParam
= (INT
)(INT16
)wParam
;
2102 case CB_GETLBTEXTLEN
:
2103 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2104 case CB_GETITEMDATA16
:
2105 wParam
= (INT
)(INT16
)wParam
;
2106 case CB_GETITEMDATA
:
2107 return SendMessageA( lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2108 case CB_SETITEMDATA16
:
2109 wParam
= (INT
)(INT16
)wParam
;
2110 case CB_SETITEMDATA
:
2111 return SendMessageA( lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2112 case CB_GETEDITSEL16
:
2113 wParam
= lParam
= 0; /* just in case */
2115 if( lphc
->wState
& CBF_EDIT
)
2119 return SendMessageA( lphc
->hWndEdit
, EM_GETSEL
,
2120 (wParam
) ? wParam
: (WPARAM
)&a
,
2121 (lParam
) ? lParam
: (LPARAM
)&b
);
2124 case CB_SETEDITSEL16
:
2126 if( lphc
->wState
& CBF_EDIT
)
2127 return SendMessageA( lphc
->hWndEdit
, EM_SETSEL
,
2128 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2130 case CB_SETEXTENDEDUI16
:
2131 case CB_SETEXTENDEDUI
:
2132 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2135 lphc
->wState
|= CBF_EUI
;
2136 else lphc
->wState
&= ~CBF_EUI
;
2138 case CB_GETEXTENDEDUI16
:
2139 case CB_GETEXTENDEDUI
:
2140 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2141 case (WM_USER
+ 0x1B):
2142 WARN("[%04x]: undocumented msg!\n", hwnd
);
2144 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2149 /***********************************************************************
2152 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2155 LRESULT WINAPI
ComboWndProc( HWND hwnd
, UINT message
,
2156 WPARAM wParam
, LPARAM lParam
)
2158 WND
* pWnd
= WIN_FindWndPtr(hwnd
);
2159 LRESULT retvalue
= ComboWndProc_locked(pWnd
,message
,wParam
,lParam
);
2162 WIN_ReleaseWndPtr(pWnd
);