4 * Copyright 1997 Alex Korobka
6 * FIXME: roll up in Netscape 3.01.
15 #include "wine/winuser16.h"
22 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(combo
)
27 /* bits in the dwKeyData */
28 #define KEYDATA_ALT 0x2000
29 #define KEYDATA_PREVSTATE 0x4000
32 * Additional combo box definitions
35 #define CB_GETPTR( wnd ) (*(LPHEADCOMBO*)((wnd)->wExtra))
36 #define CB_NOTIFY( lphc, code ) \
37 (SendMessageA( (lphc)->owner, WM_COMMAND, \
38 MAKEWPARAM((lphc)->self->wIDmenu, (code)), (lphc)->self->hwndSelf))
39 #define CB_GETEDITTEXTLENGTH( lphc ) \
40 (SendMessageA( (lphc)->hWndEdit, WM_GETTEXTLENGTH, 0, 0 ))
42 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
47 static HBITMAP hComboBmp
= 0;
48 static UINT CBitHeight
, CBitWidth
;
51 * Look and feel dependant "constants"
54 #define COMBO_YBORDERGAP 5
55 #define COMBO_XBORDERSIZE() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 2 )
56 #define COMBO_YBORDERSIZE() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 2 )
57 #define COMBO_EDITBUTTONSPACE() ( (TWEAK_WineLook == WIN31_LOOK) ? 8 : 0 )
58 #define EDIT_CONTROL_PADDING() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 1 )
60 /***********************************************************************
63 * Load combo button bitmap.
65 static BOOL
COMBO_Init()
69 if( hComboBmp
) return TRUE
;
70 if( (hDC
= CreateCompatibleDC(0)) )
73 if( (hComboBmp
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_COMBO
))) )
79 GetObjectA( hComboBmp
, sizeof(bm
), &bm
);
80 CBitHeight
= bm
.bmHeight
;
81 CBitWidth
= bm
.bmWidth
;
83 TRACE("combo bitmap [%i,%i]\n", CBitWidth
, CBitHeight
);
85 hPrevB
= SelectObject16( hDC
, hComboBmp
);
86 SetRect( &r
, 0, 0, CBitWidth
, CBitHeight
);
87 InvertRect( hDC
, &r
);
88 SelectObject( hDC
, hPrevB
);
97 /***********************************************************************
100 static LRESULT
COMBO_NCCreate(WND
* wnd
, LPARAM lParam
)
104 if ( wnd
&& COMBO_Init() &&
105 (lphc
= HeapAlloc(GetProcessHeap(), 0, sizeof(HEADCOMBO
))) )
107 LPCREATESTRUCTA lpcs
= (CREATESTRUCTA
*)lParam
;
109 memset( lphc
, 0, sizeof(HEADCOMBO
) );
110 *(LPHEADCOMBO
*)wnd
->wExtra
= lphc
;
112 /* some braindead apps do try to use scrollbar/border flags */
114 lphc
->dwStyle
= (lpcs
->style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
));
115 wnd
->dwStyle
&= ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
);
118 * We also have to remove the client edge style to make sure
119 * we don't end-up with a non client area.
121 wnd
->dwExStyle
&= ~(WS_EX_CLIENTEDGE
);
123 if( !(lpcs
->style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) )
124 lphc
->dwStyle
|= CBS_HASSTRINGS
;
125 if( !(wnd
->dwExStyle
& WS_EX_NOPARENTNOTIFY
) )
126 lphc
->wState
|= CBF_NOTIFY
;
128 TRACE("[0x%08x], style = %08x\n",
129 (UINT
)lphc
, lphc
->dwStyle
);
131 return (LRESULT
)(UINT
)wnd
->hwndSelf
;
133 return (LRESULT
)FALSE
;
136 /***********************************************************************
139 static LRESULT
COMBO_NCDestroy( LPHEADCOMBO lphc
)
144 WND
* wnd
= lphc
->self
;
146 TRACE("[%04x]: freeing storage\n", CB_HWND(lphc
));
148 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) && lphc
->hWndLBox
)
149 DestroyWindow( lphc
->hWndLBox
);
151 HeapFree( GetProcessHeap(), 0, lphc
);
157 /***********************************************************************
158 * CBGetTextAreaHeight
160 * This method will calculate the height of the text area of the
162 * The height of the text area is set in two ways.
163 * It can be set explicitely through a combobox message of through a
164 * WM_MEASUREITEM callback.
165 * If this is not the case, the height is set to 13 dialog units.
166 * This height was determined through experimentation.
168 static INT
CBGetTextAreaHeight(
174 if( lphc
->editHeight
) /* explicitly set height */
176 iTextItemHeight
= lphc
->editHeight
;
181 HDC hDC
= GetDC(hwnd
);
186 hPrevFont
= SelectObject( hDC
, lphc
->hFont
);
188 GetTextMetricsA(hDC
, &tm
);
190 baseUnitY
= tm
.tmHeight
;
193 SelectObject( hDC
, hPrevFont
);
195 ReleaseDC(hwnd
, hDC
);
197 iTextItemHeight
= ((13 * baseUnitY
) / 8);
200 * This "formula" calculates the height of the complete control.
201 * To calculate the height of the text area, we have to remove the
204 iTextItemHeight
-= 2*COMBO_YBORDERSIZE();
208 * Check the ownerdraw case if we haven't asked the parent the size
211 if ( CB_OWNERDRAWN(lphc
) &&
212 (lphc
->wState
& CBF_MEASUREITEM
) )
214 MEASUREITEMSTRUCT measureItem
;
216 INT originalItemHeight
= iTextItemHeight
;
219 * We use the client rect for the width of the item.
221 GetClientRect(hwnd
, &clientRect
);
223 lphc
->wState
&= ~CBF_MEASUREITEM
;
226 * Send a first one to measure the size of the text area
228 measureItem
.CtlType
= ODT_COMBOBOX
;
229 measureItem
.CtlID
= lphc
->self
->wIDmenu
;
230 measureItem
.itemID
= -1;
231 measureItem
.itemWidth
= clientRect
.right
;
232 measureItem
.itemHeight
= iTextItemHeight
- 6; /* ownerdrawn cb is taller */
233 measureItem
.itemData
= 0;
234 SendMessageA(lphc
->owner
, WM_MEASUREITEM
,
235 (WPARAM
)measureItem
.CtlID
, (LPARAM
)&measureItem
);
236 iTextItemHeight
= 6 + measureItem
.itemHeight
;
239 * Send a second one in the case of a fixed ownerdraw list to calculate the
240 * size of the list items. (we basically do this on behalf of the listbox)
242 if (lphc
->dwStyle
& CBS_OWNERDRAWFIXED
)
244 measureItem
.CtlType
= ODT_COMBOBOX
;
245 measureItem
.CtlID
= lphc
->self
->wIDmenu
;
246 measureItem
.itemID
= 0;
247 measureItem
.itemWidth
= clientRect
.right
;
248 measureItem
.itemHeight
= originalItemHeight
;
249 measureItem
.itemData
= 0;
250 SendMessageA(lphc
->owner
, WM_MEASUREITEM
,
251 (WPARAM
)measureItem
.CtlID
, (LPARAM
)&measureItem
);
252 lphc
->fixedOwnerDrawHeight
= measureItem
.itemHeight
;
256 * Keep the size for the next time
258 lphc
->editHeight
= iTextItemHeight
;
261 return iTextItemHeight
;
264 /***********************************************************************
267 * The dummy resize is used for listboxes that have a popup to trigger
268 * a re-arranging of the contents of the combobox and the recalculation
269 * of the size of the "real" control window.
271 static void CBForceDummyResize(
277 newComboHeight
= CBGetTextAreaHeight(CB_HWND(lphc
),lphc
) + 2*COMBO_YBORDERSIZE();
279 GetWindowRect(CB_HWND(lphc
), &windowRect
);
282 * We have to be careful, resizing a combobox also has the meaning that the
283 * dropped rect will be resized. In this case, we want to trigger a resize
284 * to recalculate layout but we don't want to change the dropped rectangle
285 * So, we pass the height of text area of control as the height.
286 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
289 SetWindowPos( CB_HWND(lphc
),
292 windowRect
.right
- windowRect
.left
,
294 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
297 /***********************************************************************
300 * Set up component coordinates given valid lphc->RectCombo.
302 static void CBCalcPlacement(
310 * Again, start with the client rectangle.
312 GetClientRect(hwnd
, lprEdit
);
317 InflateRect(lprEdit
, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
320 * Chop off the bottom part to fit with the height of the text area.
322 lprEdit
->bottom
= lprEdit
->top
+ CBGetTextAreaHeight(hwnd
, lphc
);
325 * The button starts the same vertical position as the text area.
327 CopyRect(lprButton
, lprEdit
);
330 * If the combobox is "simple" there is no button.
332 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
333 lprButton
->left
= lprButton
->right
= lprButton
->bottom
= 0;
337 * Let's assume the combobox button is the same width as the
339 * size the button horizontally and cut-off the text area.
341 lprButton
->left
= lprButton
->right
- GetSystemMetrics(SM_CXVSCROLL
);
342 lprEdit
->right
= lprButton
->left
;
346 * In the case of a dropdown, there is an additional spacing between the
347 * text area and the button.
349 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
351 lprEdit
->right
-= COMBO_EDITBUTTONSPACE();
355 * If we have an edit control, we space it away from the borders slightly.
357 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
359 InflateRect(lprEdit
, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
363 * Adjust the size of the listbox popup.
365 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
368 * Use the client rectangle to initialize the listbox rectangle
370 GetClientRect(hwnd
, lprLB
);
373 * Then, chop-off the top part.
375 lprLB
->top
= lprEdit
->bottom
+ COMBO_YBORDERSIZE();
380 * Make sure the dropped width is as large as the combobox itself.
382 if (lphc
->droppedWidth
< (lprButton
->right
+ COMBO_XBORDERSIZE()))
384 lprLB
->right
= lprLB
->left
+ (lprButton
->right
+ COMBO_XBORDERSIZE());
387 * In the case of a dropdown, the popup listbox is offset to the right.
388 * so, we want to make sure it's flush with the right side of the
391 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
392 lprLB
->right
-= COMBO_EDITBUTTONSPACE();
395 lprLB
->right
= lprLB
->left
+ lphc
->droppedWidth
;
398 TRACE("\ttext\t= (%i,%i-%i,%i)\n",
399 lprEdit
->left
, lprEdit
->top
, lprEdit
->right
, lprEdit
->bottom
);
401 TRACE("\tbutton\t= (%i,%i-%i,%i)\n",
402 lprButton
->left
, lprButton
->top
, lprButton
->right
, lprButton
->bottom
);
404 TRACE("\tlbox\t= (%i,%i-%i,%i)\n",
405 lprLB
->left
, lprLB
->top
, lprLB
->right
, lprLB
->bottom
);
408 /***********************************************************************
409 * CBGetDroppedControlRect
411 static void CBGetDroppedControlRect( LPHEADCOMBO lphc
, LPRECT lpRect
)
413 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
414 of the combo box and the lower right corner of the listbox */
416 GetWindowRect(lphc
->self
->hwndSelf
, lpRect
);
418 lpRect
->right
= lpRect
->left
+ lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
419 lpRect
->bottom
= lpRect
->top
+ lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
423 /***********************************************************************
424 * COMBO_WindowPosChanging
426 static LRESULT
COMBO_WindowPosChanging(
429 WINDOWPOS
* posChanging
)
432 * We need to override the WM_WINDOWPOSCHANGING method to handle all
433 * the non-simple comboboxes. The problem is that those controls are
434 * always the same height. We have to make sure they are not resized
437 if ( ( CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
438 ((posChanging
->flags
& SWP_NOSIZE
) == 0) )
442 newComboHeight
= CBGetTextAreaHeight(hwnd
,lphc
) +
443 2*COMBO_YBORDERSIZE();
446 * Resizing a combobox has another side effect, it resizes the dropped
447 * rectangle as well. However, it does it only if the new height for the
448 * combobox is different than the height it should have. In other words,
449 * if the application resizing the combobox only had the intention to resize
450 * the actual control, for example, to do the layout of a dialog that is
451 * resized, the height of the dropdown is not changed.
453 if (posChanging
->cy
!= newComboHeight
)
455 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
+ posChanging
->cy
- newComboHeight
;
457 posChanging
->cy
= newComboHeight
;
464 /***********************************************************************
467 static LRESULT
COMBO_Create( LPHEADCOMBO lphc
, WND
* wnd
, LPARAM lParam
)
469 static char clbName
[] = "ComboLBox";
470 static char editName
[] = "Edit";
472 LPCREATESTRUCTA lpcs
= (CREATESTRUCTA
*)lParam
;
474 if( !CB_GETTYPE(lphc
) ) lphc
->dwStyle
|= CBS_SIMPLE
;
475 if( CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
) lphc
->wState
|= CBF_EDIT
;
478 lphc
->owner
= lpcs
->hwndParent
;
481 * The item height and dropped width are not set when the control
484 lphc
->droppedWidth
= lphc
->editHeight
= 0;
487 * The first time we go through, we want to measure the ownerdraw item
489 lphc
->wState
|= CBF_MEASUREITEM
;
491 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
493 if( lphc
->owner
|| !(lpcs
->style
& WS_VISIBLE
) )
499 * Initialize the dropped rect to the size of the client area of the
500 * control and then, force all the areas of the combobox to be
503 GetClientRect( wnd
->hwndSelf
, &lphc
->droppedRect
);
505 CBCalcPlacement(wnd
->hwndSelf
,
509 &lphc
->droppedRect
);
512 * Adjust the position of the popup listbox if it's necessary
514 if ( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
516 lphc
->droppedRect
.top
= lphc
->textRect
.bottom
+ COMBO_YBORDERSIZE();
519 * If it's a dropdown, the listbox is offset
521 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
522 lphc
->droppedRect
.left
+= COMBO_EDITBUTTONSPACE();
524 ClientToScreen(wnd
->hwndSelf
, (LPPOINT
)&lphc
->droppedRect
);
525 ClientToScreen(wnd
->hwndSelf
, (LPPOINT
)&lphc
->droppedRect
.right
);
528 /* create listbox popup */
530 lbeStyle
= (LBS_NOTIFY
| WS_BORDER
| WS_CLIPSIBLINGS
| WS_CHILD
) |
531 (lpcs
->style
& (WS_VSCROLL
| CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
));
533 if( lphc
->dwStyle
& CBS_SORT
)
534 lbeStyle
|= LBS_SORT
;
535 if( lphc
->dwStyle
& CBS_HASSTRINGS
)
536 lbeStyle
|= LBS_HASSTRINGS
;
537 if( lphc
->dwStyle
& CBS_NOINTEGRALHEIGHT
)
538 lbeStyle
|= LBS_NOINTEGRALHEIGHT
;
539 if( lphc
->dwStyle
& CBS_DISABLENOSCROLL
)
540 lbeStyle
|= LBS_DISABLENOSCROLL
;
542 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
) /* child listbox */
544 lbeStyle
|= WS_VISIBLE
;
547 * In win 95 look n feel, the listbox in the simple combobox has
548 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
550 if (TWEAK_WineLook
> WIN31_LOOK
)
552 lbeStyle
&= ~WS_BORDER
;
553 lbeExStyle
|= WS_EX_CLIENTEDGE
;
557 lphc
->hWndLBox
= CreateWindowExA(lbeExStyle
,
561 lphc
->droppedRect
.left
,
562 lphc
->droppedRect
.top
,
563 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
564 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
565 lphc
->self
->hwndSelf
,
566 (HMENU
)ID_CB_LISTBOX
,
567 lphc
->self
->hInstance
,
573 lbeStyle
= WS_CHILD
| WS_VISIBLE
| ES_NOHIDESEL
| ES_LEFT
| ES_COMBO
;
576 * In Win95 look, the border fo the edit control is
577 * provided by the combobox
579 if (TWEAK_WineLook
== WIN31_LOOK
)
580 lbeStyle
|= WS_BORDER
;
582 if( lphc
->wState
& CBF_EDIT
)
584 if( lphc
->dwStyle
& CBS_OEMCONVERT
)
585 lbeStyle
|= ES_OEMCONVERT
;
586 if( lphc
->dwStyle
& CBS_AUTOHSCROLL
)
587 lbeStyle
|= ES_AUTOHSCROLL
;
588 if( lphc
->dwStyle
& CBS_LOWERCASE
)
589 lbeStyle
|= ES_LOWERCASE
;
590 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
591 lbeStyle
|= ES_UPPERCASE
;
593 lphc
->hWndEdit
= CreateWindowExA(0,
597 lphc
->textRect
.left
, lphc
->textRect
.top
,
598 lphc
->textRect
.right
- lphc
->textRect
.left
,
599 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
600 lphc
->self
->hwndSelf
,
602 lphc
->self
->hInstance
,
605 if( !lphc
->hWndEdit
)
611 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
613 /* Now do the trick with parent */
614 SetParent(lphc
->hWndLBox
, HWND_DESKTOP
);
616 * If the combo is a dropdown, we must resize the control to fit only
617 * the text area and button. To do this, we send a dummy resize and the
618 * WM_WINDOWPOSCHANGING message will take care of setting the height for
621 CBForceDummyResize(lphc
);
624 TRACE("init done\n");
625 return wnd
->hwndSelf
;
627 ERR("edit control failure.\n");
628 } else ERR("listbox failure.\n");
629 } else ERR("no owner for visible combo.\n");
631 /* CreateWindow() will send WM_NCDESTROY to cleanup */
636 /***********************************************************************
639 * Paint combo button (normal, pressed, and disabled states).
641 static void CBPaintButton(
646 if( lphc
->wState
& CBF_NOREDRAW
)
649 if (TWEAK_WineLook
== WIN31_LOOK
)
655 COLORREF oldTextColor
, oldBkColor
;
658 hPrevBrush
= SelectObject(hdc
, GetSysColorBrush(COLOR_BTNFACE
));
661 * Draw the button background
666 rectButton
.right
-rectButton
.left
,
667 rectButton
.bottom
-rectButton
.top
,
670 if( (bBool
= lphc
->wState
& CBF_BUTTONDOWN
) )
672 DrawEdge( hdc
, &rectButton
, EDGE_SUNKEN
, BF_RECT
);
676 DrawEdge( hdc
, &rectButton
, EDGE_RAISED
, BF_RECT
);
680 * Remove the edge of the button from the rectangle
681 * and calculate the position of the bitmap.
683 InflateRect( &rectButton
, -2, -2);
685 x
= (rectButton
.left
+ rectButton
.right
- CBitWidth
) >> 1;
686 y
= (rectButton
.top
+ rectButton
.bottom
- CBitHeight
) >> 1;
689 hMemDC
= CreateCompatibleDC( hdc
);
690 SelectObject( hMemDC
, hComboBmp
);
691 oldTextColor
= SetTextColor( hdc
, GetSysColor(COLOR_BTNFACE
) );
692 oldBkColor
= SetBkColor( hdc
, CB_DISABLED(lphc
) ? RGB(128,128,128) :
694 BitBlt( hdc
, x
, y
, CBitWidth
, CBitHeight
, hMemDC
, 0, 0, SRCCOPY
);
695 SetBkColor( hdc
, oldBkColor
);
696 SetTextColor( hdc
, oldTextColor
);
698 SelectObject( hdc
, hPrevBrush
);
702 UINT buttonState
= DFCS_SCROLLCOMBOBOX
;
704 if (lphc
->wState
& CBF_BUTTONDOWN
)
706 buttonState
|= DFCS_PUSHED
;
709 if (CB_DISABLED(lphc
))
711 buttonState
|= DFCS_INACTIVE
;
714 DrawFrameControl(hdc
,
721 /***********************************************************************
724 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
726 static void CBPaintText(
734 if( lphc
->wState
& CBF_NOREDRAW
) return;
736 /* follow Windows combobox that sends a bunch of text
737 * inquiries to its listbox while processing WM_PAINT. */
739 if( (id
= SendMessageA(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0) ) != LB_ERR
)
741 size
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, id
, 0);
742 if( (pText
= HeapAlloc( GetProcessHeap(), 0, size
+ 1)) )
744 SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
, (WPARAM
)id
, (LPARAM
)pText
);
745 pText
[size
] = '\0'; /* just in case */
749 if( lphc
->wState
& CBF_EDIT
)
751 if( CB_HASSTRINGS(lphc
) ) SetWindowTextA( lphc
->hWndEdit
, pText
? pText
: "" );
752 if( lphc
->wState
& CBF_FOCUSED
)
753 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
755 else /* paint text field ourselves */
758 HFONT hPrevFont
= (lphc
->hFont
) ? SelectObject(hdc
, lphc
->hFont
) : 0;
761 * Give ourselves some space.
763 InflateRect( &rectEdit
, -1, -1 );
765 if ( (lphc
->wState
& CBF_FOCUSED
) &&
766 !(lphc
->wState
& CBF_DROPPED
) )
770 FillRect( hdc
, &rectEdit
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
771 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
772 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
773 itemState
= ODS_SELECTED
| ODS_FOCUS
;
778 if( CB_OWNERDRAWN(lphc
) )
784 * Save the current clip region.
785 * To retrieve the clip region, we need to create one "dummy"
788 clipRegion
= CreateRectRgnIndirect(&rectEdit
);
790 if (GetClipRgn(hdc
, clipRegion
)!=1)
792 DeleteObject(clipRegion
);
793 clipRegion
=(HRGN
)NULL
;
796 if ( lphc
->self
->dwStyle
& WS_DISABLED
)
797 itemState
|= ODS_DISABLED
;
799 dis
.CtlType
= ODT_COMBOBOX
;
800 dis
.CtlID
= lphc
->self
->wIDmenu
;
801 dis
.hwndItem
= lphc
->self
->hwndSelf
;
802 dis
.itemAction
= ODA_DRAWENTIRE
;
804 dis
.itemState
= itemState
;
806 dis
.rcItem
= rectEdit
;
807 dis
.itemData
= SendMessageA( lphc
->hWndLBox
, LB_GETITEMDATA
,
811 * Clip the DC and have the parent draw the item.
813 IntersectClipRect(hdc
,
814 rectEdit
.left
, rectEdit
.top
,
815 rectEdit
.right
, rectEdit
.bottom
);
817 SendMessageA(lphc
->owner
, WM_DRAWITEM
,
818 lphc
->self
->wIDmenu
, (LPARAM
)&dis
);
821 * Reset the clipping region.
823 SelectClipRgn(hdc
, clipRegion
);
830 ETO_OPAQUE
| ETO_CLIPPED
,
832 pText
? pText
: "" , size
, NULL
);
834 if(lphc
->wState
& CBF_FOCUSED
&& !(lphc
->wState
& CBF_DROPPED
))
835 DrawFocusRect( hdc
, &rectEdit
);
839 SelectObject(hdc
, hPrevFont
);
842 HeapFree( GetProcessHeap(), 0, pText
);
845 /***********************************************************************
848 static void CBPaintBorder(
855 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
857 GetClientRect(hwnd
, &clientRect
);
861 CopyRect(&clientRect
, &lphc
->textRect
);
863 InflateRect(&clientRect
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
864 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
867 DrawEdge(hdc
, &clientRect
, EDGE_SUNKEN
, BF_RECT
);
870 /***********************************************************************
871 * COMBO_PrepareColors
873 * This method will sent the appropriate WM_CTLCOLOR message to
874 * prepare and setup the colors for the combo's DC.
876 * It also returns the brush to use for the background.
878 static HBRUSH
COMBO_PrepareColors(
886 * Get the background brush for this control.
888 if (CB_DISABLED(lphc
))
890 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLORSTATIC
,
891 hDC
, lphc
->self
->hwndSelf
);
894 * We have to change the text color since WM_CTLCOLORSTATIC will
895 * set it to the "enabled" color. This is the same behavior as the
898 SetTextColor(hDC
, GetSysColor(COLOR_GRAYTEXT
));
902 if (lphc
->wState
& CBF_EDIT
)
904 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLOREDIT
,
905 hDC
, lphc
->self
->hwndSelf
);
909 hBkgBrush
= SendMessageA( lphc
->owner
, WM_CTLCOLORLISTBOX
,
910 hDC
, lphc
->self
->hwndSelf
);
918 hBkgBrush
= GetSysColorBrush(COLOR_WINDOW
);
923 /***********************************************************************
924 * COMBO_EraseBackground
926 static LRESULT
COMBO_EraseBackground(
935 hDC
= (hParamDC
) ? hParamDC
939 * Calculate the area that we want to erase.
941 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
943 GetClientRect(hwnd
, &clientRect
);
947 CopyRect(&clientRect
, &lphc
->textRect
);
949 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
953 * Retrieve the background brush
955 hBkgBrush
= COMBO_PrepareColors(hwnd
, lphc
, hDC
);
957 FillRect(hDC
, &clientRect
, hBkgBrush
);
960 ReleaseDC(hwnd
, hDC
);
965 /***********************************************************************
968 static LRESULT
COMBO_Paint(LPHEADCOMBO lphc
, HDC hParamDC
)
973 hDC
= (hParamDC
) ? hParamDC
974 : BeginPaint( lphc
->self
->hwndSelf
, &ps
);
977 if( hDC
&& !(lphc
->wState
& CBF_NOREDRAW
) )
979 HBRUSH hPrevBrush
, hBkgBrush
;
982 * Retrieve the background brush and select it in the
985 hBkgBrush
= COMBO_PrepareColors(lphc
->self
->hwndSelf
, lphc
, hDC
);
987 hPrevBrush
= SelectObject( hDC
, hBkgBrush
);
990 * In non 3.1 look, there is a sunken border on the combobox
992 if (TWEAK_WineLook
!= WIN31_LOOK
)
994 CBPaintBorder(CB_HWND(lphc
), lphc
, hDC
);
997 if( !IsRectEmpty(&lphc
->buttonRect
) )
999 CBPaintButton(lphc
, hDC
, lphc
->buttonRect
);
1002 if( !(lphc
->wState
& CBF_EDIT
) )
1005 * The text area has a border only in Win 3.1 look.
1007 if (TWEAK_WineLook
== WIN31_LOOK
)
1009 HPEN hPrevPen
= SelectObject( hDC
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1012 lphc
->textRect
.left
, lphc
->textRect
.top
,
1013 lphc
->textRect
.right
- 1, lphc
->textRect
.bottom
- 1);
1015 SelectObject( hDC
, hPrevPen
);
1018 CBPaintText( lphc
, hDC
, lphc
->textRect
);
1022 SelectObject( hDC
, hPrevBrush
);
1026 EndPaint(lphc
->self
->hwndSelf
, &ps
);
1031 /***********************************************************************
1034 * Select listbox entry according to the contents of the edit control.
1036 static INT
CBUpdateLBox( LPHEADCOMBO lphc
, BOOL bSelect
)
1042 length
= CB_GETEDITTEXTLENGTH( lphc
);
1045 pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1);
1047 TRACE("\t edit text length %i\n", length
);
1051 if( length
) GetWindowTextA( lphc
->hWndEdit
, pText
, length
+ 1);
1052 else pText
[0] = '\0';
1053 idx
= SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
,
1054 (WPARAM
)(-1), (LPARAM
)pText
);
1055 HeapFree( GetProcessHeap(), 0, pText
);
1058 SendMessageA( lphc
->hWndLBox
, LB_SETCURSEL
, (WPARAM
)(bSelect
? idx
: -1), 0 );
1060 /* probably superfluous but Windows sends this too */
1061 SendMessageA( lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0 );
1062 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0 );
1066 /***********************************************************************
1069 * Copy a listbox entry to the edit control.
1071 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1076 TRACE("\t %i\n", index
);
1078 if( index
>= 0 ) /* got an entry */
1080 length
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1083 if( (pText
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1)) )
1085 SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
,
1086 (WPARAM
)index
, (LPARAM
)pText
);
1091 lphc
->wState
|= (CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1092 SendMessageA( lphc
->hWndEdit
, WM_SETTEXT
, 0, pText
? (LPARAM
)pText
: (LPARAM
)"" );
1093 lphc
->wState
&= ~(CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1095 if( lphc
->wState
& CBF_FOCUSED
)
1096 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1) );
1099 HeapFree( GetProcessHeap(), 0, pText
);
1102 /***********************************************************************
1105 * Show listbox popup.
1107 static void CBDropDown( LPHEADCOMBO lphc
)
1113 TRACE("[%04x]: drop down\n", CB_HWND(lphc
));
1115 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1119 lphc
->wState
|= CBF_DROPPED
;
1120 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1122 lphc
->droppedIndex
= CBUpdateLBox( lphc
, TRUE
);
1124 if( !(lphc
->wState
& CBF_CAPTURE
) )
1125 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1129 lphc
->droppedIndex
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1131 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
,
1132 (WPARAM
)(lphc
->droppedIndex
== LB_ERR
? 0 : lphc
->droppedIndex
), 0 );
1133 SendMessageA( lphc
->hWndLBox
, LB_CARETON
, 0, 0 );
1136 /* now set popup position */
1137 GetWindowRect( lphc
->self
->hwndSelf
, &rect
);
1140 * If it's a dropdown, the listbox is offset
1142 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1143 rect
.left
+= COMBO_EDITBUTTONSPACE();
1145 /* if the dropped height is greater than the total height of the dropped
1146 items list, then force the drop down list height to be the total height
1147 of the items in the dropped list */
1149 /* And Remove any extra space (Best Fit) */
1150 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1151 nItems
= (int)SendMessageA (lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1157 nHeight
= (int)SendMessageA (lphc
->hWndLBox
, LB_GETITEMHEIGHT
, 0, 0);
1160 if (nHeight
< nDroppedHeight
- COMBO_YBORDERSIZE())
1161 nDroppedHeight
= nHeight
+ COMBO_YBORDERSIZE();
1164 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1165 if( (rect
.bottom
+ nDroppedHeight
) >= GetSystemMetrics( SM_CYSCREEN
) )
1166 rect
.bottom
= rect
.top
- nDroppedHeight
;
1168 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1169 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1171 SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
1174 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1175 RedrawWindow( lphc
->self
->hwndSelf
, NULL
, 0, RDW_INVALIDATE
|
1176 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1178 EnableWindow( lphc
->hWndLBox
, TRUE
);
1179 if (GetCapture() != lphc
->self
->hwndSelf
)
1180 SetCapture(lphc
->hWndLBox
);
1183 /***********************************************************************
1186 * Hide listbox popup.
1188 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1190 HWND hWnd
= lphc
->self
->hwndSelf
;
1192 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1194 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1197 TRACE("[%04x]: roll up [%i]\n", CB_HWND(lphc
), (INT
)ok
);
1199 if( lphc
->wState
& CBF_DROPPED
)
1203 lphc
->wState
&= ~CBF_DROPPED
;
1204 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1205 if(GetCapture() == lphc
->hWndLBox
)
1210 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1212 rect
= lphc
->buttonRect
;
1223 rect
= lphc
->textRect
;
1228 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1229 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1230 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1231 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1236 /***********************************************************************
1239 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1241 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL ok
, BOOL bRedrawButton
)
1243 if( lphc
->wState
& CBF_DROPPED
)
1245 CBRollUp( lphc
, ok
, bRedrawButton
);
1253 /***********************************************************************
1256 static void CBRepaintButton( LPHEADCOMBO lphc
)
1258 InvalidateRect(CB_HWND(lphc
), &lphc
->buttonRect
, TRUE
);
1259 UpdateWindow(CB_HWND(lphc
));
1262 /***********************************************************************
1265 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1267 if( !(lphc
->wState
& CBF_FOCUSED
) )
1269 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1270 SendMessageA( lphc
->hWndLBox
, LB_CARETON
, 0, 0 );
1272 lphc
->wState
|= CBF_FOCUSED
;
1274 if( !(lphc
->wState
& CBF_EDIT
) )
1275 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1277 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1281 /***********************************************************************
1284 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1286 HWND hWnd
= lphc
->self
->hwndSelf
;
1288 if( lphc
->wState
& CBF_FOCUSED
)
1290 CBRollUp( lphc
, FALSE
, TRUE
);
1291 if( IsWindow( hWnd
) )
1293 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1294 SendMessageA( lphc
->hWndLBox
, LB_CARETOFF
, 0, 0 );
1296 lphc
->wState
&= ~CBF_FOCUSED
;
1299 if( !(lphc
->wState
& CBF_EDIT
) )
1300 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1302 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1307 /***********************************************************************
1310 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1312 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1314 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1316 switch( HIWORD(wParam
) >> 8 )
1318 case (EN_SETFOCUS
>> 8):
1320 TRACE("[%04x]: edit [%04x] got focus\n",
1321 CB_HWND(lphc
), lphc
->hWndEdit
);
1323 COMBO_SetFocus( lphc
);
1326 case (EN_KILLFOCUS
>> 8):
1328 TRACE("[%04x]: edit [%04x] lost focus\n",
1329 CB_HWND(lphc
), lphc
->hWndEdit
);
1331 /* NOTE: it seems that Windows' edit control sends an
1332 * undocumented message WM_USER + 0x1B instead of this
1333 * notification (only when it happens to be a part of
1334 * the combo). ?? - AK.
1337 COMBO_KillFocus( lphc
);
1341 case (EN_CHANGE
>> 8):
1343 * In some circumstances (when the selection of the combobox
1344 * is changed for example) we don't wans the EN_CHANGE notification
1345 * to be forwarded to the parent of the combobox. This code
1346 * checks a flag that is set in these occasions and ignores the
1349 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1350 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1352 if (lphc
->wState
& CBF_NOLBSELECT
)
1354 lphc
->wState
&= ~CBF_NOLBSELECT
;
1358 CBUpdateLBox( lphc
, lphc
->wState
& CBF_DROPPED
);
1362 case (EN_UPDATE
>> 8):
1363 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1364 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1367 case (EN_ERRSPACE
>> 8):
1368 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1371 else if( lphc
->hWndLBox
== hWnd
)
1373 switch( HIWORD(wParam
) )
1376 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1380 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1386 TRACE("[%04x]: lbox selection change [%04x]\n",
1387 CB_HWND(lphc
), lphc
->wState
);
1389 /* do not roll up if selection is being tracked
1390 * by arrowkeys in the dropdown listbox */
1392 if( (lphc
->dwStyle
& CBS_SIMPLE
) ||
1393 ((lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
)) )
1395 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1397 else lphc
->wState
&= ~CBF_NOROLLUP
;
1399 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1401 if( HIWORD(wParam
) == LBN_SELCHANGE
)
1403 if( lphc
->wState
& CBF_EDIT
)
1405 INT index
= SendMessageA(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1406 lphc
->wState
|= CBF_NOLBSELECT
;
1407 CBUpdateEdit( lphc
, index
);
1408 /* select text in edit, as Windows does */
1409 SendMessageA( lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1) );
1412 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1419 /* nothing to do here since ComboLBox always resets the focus to its
1420 * combo/edit counterpart */
1427 /***********************************************************************
1430 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1432 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
,
1433 WPARAM wParam
, LPARAM lParam
)
1435 HWND hWnd
= lphc
->self
->hwndSelf
;
1437 TRACE("[%04x]: ownerdraw op %04x\n", CB_HWND(lphc
), msg
);
1439 #define lpIS ((LPDELETEITEMSTRUCT)lParam)
1441 /* two first items are the same in all 4 structs */
1442 lpIS
->CtlType
= ODT_COMBOBOX
;
1443 lpIS
->CtlID
= lphc
->self
->wIDmenu
;
1445 switch( msg
) /* patch window handle */
1448 lpIS
->hwndItem
= hWnd
;
1452 #define lpIS ((LPDRAWITEMSTRUCT)lParam)
1453 lpIS
->hwndItem
= hWnd
;
1456 case WM_COMPAREITEM
:
1457 #define lpIS ((LPCOMPAREITEMSTRUCT)lParam)
1458 lpIS
->hwndItem
= hWnd
;
1463 return SendMessageA( lphc
->owner
, msg
, lphc
->self
->wIDmenu
, lParam
);
1466 /***********************************************************************
1469 static LRESULT
COMBO_GetText( LPHEADCOMBO lphc
, UINT N
, LPSTR lpText
)
1471 if( lphc
->wState
& CBF_EDIT
)
1472 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
,
1473 (WPARAM
)N
, (LPARAM
)lpText
);
1475 /* get it from the listbox */
1477 if( lphc
->hWndLBox
)
1479 INT idx
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1483 INT length
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
,
1486 /* 'length' is without the terminating character */
1488 lpBuffer
= (LPSTR
) HeapAlloc( GetProcessHeap(), 0, length
+ 1 );
1494 INT n
= SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
,
1495 (WPARAM
)idx
, (LPARAM
)lpBuffer
);
1497 /* truncate if buffer is too short */
1502 if( n
!= LB_ERR
) memcpy( lpText
, lpBuffer
, (N
>n
) ? n
+1 : N
-1 );
1503 lpText
[N
- 1] = '\0';
1505 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1515 /***********************************************************************
1518 * This function sets window positions according to the updated
1519 * component placement struct.
1521 static void CBResetPos(
1527 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1529 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1530 * sizing messages */
1532 if( lphc
->wState
& CBF_EDIT
)
1533 SetWindowPos( lphc
->hWndEdit
, 0,
1534 rectEdit
->left
, rectEdit
->top
,
1535 rectEdit
->right
- rectEdit
->left
,
1536 rectEdit
->bottom
- rectEdit
->top
,
1537 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1539 SetWindowPos( lphc
->hWndLBox
, 0,
1540 rectLB
->left
, rectLB
->top
,
1541 rectLB
->right
- rectLB
->left
,
1542 rectLB
->bottom
- rectLB
->top
,
1543 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1547 if( lphc
->wState
& CBF_DROPPED
)
1549 lphc
->wState
&= ~CBF_DROPPED
;
1550 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1553 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1554 RedrawWindow( lphc
->self
->hwndSelf
, NULL
, 0,
1555 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1560 /***********************************************************************
1563 static void COMBO_Size( LPHEADCOMBO lphc
)
1565 CBCalcPlacement(lphc
->self
->hwndSelf
,
1569 &lphc
->droppedRect
);
1571 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1575 /***********************************************************************
1578 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1583 lphc
->hFont
= hFont
;
1586 * Propagate to owned windows.
1588 if( lphc
->wState
& CBF_EDIT
)
1589 SendMessageA( lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1590 SendMessageA( lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1593 * Redo the layout of the control.
1595 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1597 CBCalcPlacement(lphc
->self
->hwndSelf
,
1601 &lphc
->droppedRect
);
1603 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1607 CBForceDummyResize(lphc
);
1612 /***********************************************************************
1613 * COMBO_SetItemHeight
1615 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1617 LRESULT lRet
= CB_ERR
;
1619 if( index
== -1 ) /* set text field height */
1621 if( height
< 32768 )
1623 lphc
->editHeight
= height
;
1626 * Redo the layout of the control.
1628 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1630 CBCalcPlacement(lphc
->self
->hwndSelf
,
1634 &lphc
->droppedRect
);
1636 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1640 CBForceDummyResize(lphc
);
1646 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1647 lRet
= SendMessageA( lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1648 (WPARAM
)index
, (LPARAM
)height
);
1652 /***********************************************************************
1653 * COMBO_SelectString
1655 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPCSTR pText
)
1657 INT index
= SendMessageA( lphc
->hWndLBox
, LB_SELECTSTRING
,
1658 (WPARAM
)start
, (LPARAM
)pText
);
1661 if( lphc
->wState
& CBF_EDIT
)
1662 CBUpdateEdit( lphc
, index
);
1665 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
1668 return (LRESULT
)index
;
1671 /***********************************************************************
1674 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1678 HWND hWnd
= lphc
->self
->hwndSelf
;
1680 pt
.x
= LOWORD(lParam
);
1681 pt
.y
= HIWORD(lParam
);
1682 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1684 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1685 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1687 lphc
->wState
|= CBF_BUTTONDOWN
;
1688 if( lphc
->wState
& CBF_DROPPED
)
1690 /* got a click to cancel selection */
1692 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1693 CBRollUp( lphc
, TRUE
, FALSE
);
1694 if( !IsWindow( hWnd
) ) return;
1696 if( lphc
->wState
& CBF_CAPTURE
)
1698 lphc
->wState
&= ~CBF_CAPTURE
;
1704 /* drop down the listbox and start tracking */
1706 lphc
->wState
|= CBF_CAPTURE
;
1710 if( bButton
) CBRepaintButton( lphc
);
1714 /***********************************************************************
1717 * Release capture and stop tracking if needed.
1719 static void COMBO_LButtonUp( LPHEADCOMBO lphc
, LPARAM lParam
)
1721 if( lphc
->wState
& CBF_CAPTURE
)
1723 lphc
->wState
&= ~CBF_CAPTURE
;
1724 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1726 INT index
= CBUpdateLBox( lphc
, TRUE
);
1727 lphc
->wState
|= CBF_NOLBSELECT
;
1728 CBUpdateEdit( lphc
, index
);
1729 lphc
->wState
&= ~CBF_NOLBSELECT
;
1732 SetCapture(lphc
->hWndLBox
);
1736 if( lphc
->wState
& CBF_BUTTONDOWN
)
1738 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1739 CBRepaintButton( lphc
);
1743 /***********************************************************************
1746 * Two things to do - track combo button and release capture when
1747 * pointer goes into the listbox.
1749 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1754 pt
.x
= LOWORD(lParam
);
1755 pt
.y
= HIWORD(lParam
);
1757 if( lphc
->wState
& CBF_BUTTONDOWN
)
1761 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1765 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1766 CBRepaintButton( lphc
);
1770 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1771 MapWindowPoints( lphc
->self
->hwndSelf
, lphc
->hWndLBox
, &pt
, 1 );
1772 if( PtInRect(&lbRect
, pt
) )
1774 lphc
->wState
&= ~CBF_CAPTURE
;
1776 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
, TRUE
);
1778 /* hand over pointer tracking */
1779 SendMessageA( lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1784 /***********************************************************************
1785 * ComboWndProc_locked
1787 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1789 static inline LRESULT WINAPI
ComboWndProc_locked( WND
* pWnd
, UINT message
,
1790 WPARAM wParam
, LPARAM lParam
)
1793 LPHEADCOMBO lphc
= CB_GETPTR(pWnd
);
1794 HWND hwnd
= pWnd
->hwndSelf
;
1796 TRACE("[%04x]: msg %s wp %08x lp %08lx\n",
1797 pWnd
->hwndSelf
, SPY_GetMsgName(message
), wParam
, lParam
);
1799 if( lphc
|| message
== WM_NCCREATE
)
1803 /* System messages */
1806 return COMBO_NCCreate(pWnd
, lParam
);
1808 COMBO_NCDestroy(lphc
);
1809 break;/* -> DefWindowProc */
1812 return COMBO_Create(lphc
, pWnd
, lParam
);
1814 case WM_PRINTCLIENT
:
1815 if (lParam
& PRF_ERASEBKGND
)
1816 COMBO_EraseBackground(hwnd
, lphc
, wParam
);
1820 /* wParam may contain a valid HDC! */
1821 return COMBO_Paint(lphc
, wParam
);
1823 return COMBO_EraseBackground(hwnd
, lphc
, wParam
);
1826 LRESULT result
= DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1827 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1829 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1831 if ((vk
== VK_RETURN
|| vk
== VK_ESCAPE
) && (lphc
->wState
& CBF_DROPPED
))
1832 result
|= DLGC_WANTMESSAGE
;
1836 case WM_WINDOWPOSCHANGING
:
1837 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1839 if( lphc
->hWndLBox
&&
1840 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
);
1843 COMBO_Font( lphc
, (HFONT16
)wParam
, (BOOL
)lParam
);
1846 return (LRESULT
)lphc
->hFont
;
1848 if( lphc
->wState
& CBF_EDIT
)
1849 SetFocus( lphc
->hWndEdit
);
1851 COMBO_SetFocus( lphc
);
1854 #define hwndFocus ((HWND16)wParam)
1856 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1857 COMBO_KillFocus( lphc
);
1861 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1863 return COMBO_GetText( lphc
, (UINT
)wParam
, (LPSTR
)lParam
);
1865 case WM_GETTEXTLENGTH
:
1870 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1872 int j
= SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0 );
1873 if (j
== -1) return 0;
1874 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1876 else if( lphc
->wState
& CBF_EDIT
)
1879 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1880 ret
= SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1881 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1888 case WM_COMPAREITEM
:
1889 case WM_MEASUREITEM
:
1890 return COMBO_ItemOp( lphc
, message
, wParam
, lParam
);
1892 if( lphc
->wState
& CBF_EDIT
)
1893 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
1894 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
1896 /* Force the control to repaint when the enabled state changes. */
1897 InvalidateRect(CB_HWND(lphc
), NULL
, TRUE
);
1901 lphc
->wState
&= ~CBF_NOREDRAW
;
1903 lphc
->wState
|= CBF_NOREDRAW
;
1905 if( lphc
->wState
& CBF_EDIT
)
1906 SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1907 SendMessageA( lphc
->hWndLBox
, message
, wParam
, lParam
);
1910 if( KEYDATA_ALT
& HIWORD(lParam
) )
1911 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
1912 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
1917 if (((CHAR
)wParam
== VK_RETURN
|| (CHAR
)wParam
== VK_ESCAPE
) &&
1918 (lphc
->wState
& CBF_DROPPED
))
1920 CBRollUp( lphc
, (CHAR
)wParam
== VK_RETURN
, FALSE
);
1924 if( lphc
->wState
& CBF_EDIT
)
1925 return SendMessageA( lphc
->hWndEdit
, message
, wParam
, lParam
);
1927 return SendMessageA( lphc
->hWndLBox
, message
, wParam
, lParam
);
1928 case WM_LBUTTONDOWN
:
1929 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
->hwndSelf
);
1930 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
1933 COMBO_LButtonUp( lphc
, lParam
);
1936 if( lphc
->wState
& CBF_CAPTURE
)
1937 COMBO_MouseMove( lphc
, wParam
, lParam
);
1941 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
1942 return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1943 if ((short) HIWORD(wParam
) > 0) return SendMessageA(hwnd
,WM_KEYDOWN
,VK_UP
,0);
1944 if ((short) HIWORD(wParam
) < 0) return SendMessageA(hwnd
,WM_KEYDOWN
,VK_DOWN
,0);
1947 /* Combo messages */
1949 case CB_ADDSTRING16
:
1950 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1952 return SendMessageA( lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
1953 case CB_INSERTSTRING16
:
1954 wParam
= (INT
)(INT16
)wParam
;
1955 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1956 case CB_INSERTSTRING
:
1957 return SendMessageA( lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
1958 case CB_DELETESTRING16
:
1959 case CB_DELETESTRING
:
1960 return SendMessageA( lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
1961 case CB_SELECTSTRING16
:
1962 wParam
= (INT
)(INT16
)wParam
;
1963 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1964 case CB_SELECTSTRING
:
1965 return COMBO_SelectString( lphc
, (INT
)wParam
, (LPSTR
)lParam
);
1966 case CB_FINDSTRING16
:
1967 wParam
= (INT
)(INT16
)wParam
;
1968 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1970 return SendMessageA( lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
1971 case CB_FINDSTRINGEXACT16
:
1972 wParam
= (INT
)(INT16
)wParam
;
1973 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
1974 case CB_FINDSTRINGEXACT
:
1975 return SendMessageA( lphc
->hWndLBox
, LB_FINDSTRINGEXACT
,
1977 case CB_SETITEMHEIGHT16
:
1978 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
1979 case CB_SETITEMHEIGHT
:
1980 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
1981 case CB_GETITEMHEIGHT16
:
1982 wParam
= (INT
)(INT16
)wParam
;
1983 case CB_GETITEMHEIGHT
:
1984 if( (INT
)wParam
>= 0 ) /* listbox item */
1985 return SendMessageA( lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
1986 return CBGetTextAreaHeight(hwnd
, lphc
);
1987 case CB_RESETCONTENT16
:
1988 case CB_RESETCONTENT
:
1989 SendMessageA( lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0 );
1990 InvalidateRect(CB_HWND(lphc
), NULL
, TRUE
);
1992 case CB_INITSTORAGE
:
1993 return SendMessageA( lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
1994 case CB_GETHORIZONTALEXTENT
:
1995 return SendMessageA( lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
1996 case CB_SETHORIZONTALEXTENT
:
1997 return SendMessageA( lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
1998 case CB_GETTOPINDEX
:
1999 return SendMessageA( lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2001 return SendMessageA( lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2003 return SendMessageA( lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2004 case CB_GETDROPPEDWIDTH
:
2005 if( lphc
->droppedWidth
)
2006 return lphc
->droppedWidth
;
2007 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2008 case CB_SETDROPPEDWIDTH
:
2009 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2010 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2012 case CB_GETDROPPEDCONTROLRECT16
:
2013 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2017 CBGetDroppedControlRect( lphc
, &r
);
2018 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2021 case CB_GETDROPPEDCONTROLRECT
:
2022 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2024 case CB_GETDROPPEDSTATE16
:
2025 case CB_GETDROPPEDSTATE
:
2026 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2028 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2031 return COMBO_Directory( lphc
, (UINT
)wParam
,
2032 (LPSTR
)lParam
, (message
== CB_DIR
));
2033 case CB_SHOWDROPDOWN16
:
2034 case CB_SHOWDROPDOWN
:
2035 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2039 if( !(lphc
->wState
& CBF_DROPPED
) )
2043 if( lphc
->wState
& CBF_DROPPED
)
2044 CBRollUp( lphc
, FALSE
, TRUE
);
2049 return SendMessageA( lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2050 case CB_GETCURSEL16
:
2052 return SendMessageA( lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2053 case CB_SETCURSEL16
:
2054 wParam
= (INT
)(INT16
)wParam
;
2056 lParam
= SendMessageA( lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2058 SendMessageA( lphc
->hWndLBox
, LB_SETTOPINDEX
, wParam
, 0);
2059 if( lphc
->wState
& CBF_SELCHANGE
)
2061 /* no LBN_SELCHANGE in this case, update manually */
2062 if( lphc
->wState
& CBF_EDIT
)
2063 CBUpdateEdit( lphc
, (INT
)wParam
);
2065 InvalidateRect(CB_HWND(lphc
), &lphc
->textRect
, TRUE
);
2066 lphc
->wState
&= ~CBF_SELCHANGE
;
2069 case CB_GETLBTEXT16
:
2070 wParam
= (INT
)(INT16
)wParam
;
2071 lParam
= (LPARAM
)PTR_SEG_TO_LIN(lParam
);
2073 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2074 case CB_GETLBTEXTLEN16
:
2075 wParam
= (INT
)(INT16
)wParam
;
2076 case CB_GETLBTEXTLEN
:
2077 return SendMessageA( lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2078 case CB_GETITEMDATA16
:
2079 wParam
= (INT
)(INT16
)wParam
;
2080 case CB_GETITEMDATA
:
2081 return SendMessageA( lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2082 case CB_SETITEMDATA16
:
2083 wParam
= (INT
)(INT16
)wParam
;
2084 case CB_SETITEMDATA
:
2085 return SendMessageA( lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2086 case CB_GETEDITSEL16
:
2087 wParam
= lParam
= 0; /* just in case */
2089 if( lphc
->wState
& CBF_EDIT
)
2093 return SendMessageA( lphc
->hWndEdit
, EM_GETSEL
,
2094 (wParam
) ? wParam
: (WPARAM
)&a
,
2095 (lParam
) ? lParam
: (LPARAM
)&b
);
2098 case CB_SETEDITSEL16
:
2100 if( lphc
->wState
& CBF_EDIT
)
2101 return SendMessageA( lphc
->hWndEdit
, EM_SETSEL
,
2102 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2104 case CB_SETEXTENDEDUI16
:
2105 case CB_SETEXTENDEDUI
:
2106 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2109 lphc
->wState
|= CBF_EUI
;
2110 else lphc
->wState
&= ~CBF_EUI
;
2112 case CB_GETEXTENDEDUI16
:
2113 case CB_GETEXTENDEDUI
:
2114 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2117 if (message
>= WM_USER
)
2118 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2119 message
- WM_USER
, wParam
, lParam
);
2122 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2127 /***********************************************************************
2130 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2133 LRESULT WINAPI
ComboWndProc( HWND hwnd
, UINT message
,
2134 WPARAM wParam
, LPARAM lParam
)
2136 WND
* pWnd
= WIN_FindWndPtr(hwnd
);
2137 LRESULT retvalue
= ComboWndProc_locked(pWnd
,message
,wParam
,lParam
);
2140 WIN_ReleaseWndPtr(pWnd
);