4 * Copyright 1997 Alex Korobka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * FIXME: roll up in Netscape 3.01.
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(combo
);
37 /* bits in the dwKeyData */
38 #define KEYDATA_ALT 0x2000
39 #define KEYDATA_PREVSTATE 0x4000
42 * Additional combo box definitions
45 #define CB_NOTIFY( lphc, code ) \
46 (SendMessageW((lphc)->owner, WM_COMMAND, \
47 MAKEWPARAM(GetWindowLongA((lphc)->self,GWL_ID), (code)), (LPARAM)(lphc)->self))
49 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
50 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
51 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
52 #define CB_HWND( lphc ) ((lphc)->self)
54 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
59 static HBITMAP hComboBmp
= 0;
60 static UINT CBitHeight
, CBitWidth
;
63 * Look and feel dependent "constants"
66 #define COMBO_YBORDERGAP 5
67 #define COMBO_XBORDERSIZE() 2
68 #define COMBO_YBORDERSIZE() 2
69 #define COMBO_EDITBUTTONSPACE() 0
70 #define EDIT_CONTROL_PADDING() 1
72 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
73 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
75 /*********************************************************************
76 * combo class descriptor
78 const struct builtin_class_descr COMBO_builtin_class
=
81 L
"ComboBox", /* name */
82 CS_PARENTDC
| CS_VREDRAW
| CS_HREDRAW
| CS_DBLCLKS
, /* style */
83 (WNDPROC
) ComboWndProcW
, /* procW */
84 (WNDPROC
) ComboWndProcA
, /* procA */
85 sizeof(HEADCOMBO
*), /* extra */
86 (LPCWSTR
) IDC_ARROW
, /* cursor */
89 "ComboBox", /* name */
90 CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
, /* style */
91 ComboWndProcA
, /* procA */
92 ComboWndProcW
, /* procW */
93 sizeof(HEADCOMBO
*), /* extra */
94 IDC_ARROW
, /* cursor */
100 /***********************************************************************
103 * Load combo button bitmap.
105 static BOOL
COMBO_Init()
109 if( hComboBmp
) return TRUE
;
110 if( (hDC
= CreateCompatibleDC(0)) )
113 if( (hComboBmp
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO
))) )
119 GetObjectW( hComboBmp
, sizeof(bm
), &bm
);
120 CBitHeight
= bm
.bmHeight
;
121 CBitWidth
= bm
.bmWidth
;
123 TRACE("combo bitmap [%i,%i]\n", CBitWidth
, CBitHeight
);
125 hPrevB
= SelectObject( hDC
, hComboBmp
);
126 SetRect( &r
, 0, 0, CBitWidth
, CBitHeight
);
127 InvertRect( hDC
, &r
);
128 SelectObject( hDC
, hPrevB
);
137 /***********************************************************************
140 static LRESULT
COMBO_NCCreate(HWND hwnd
, LONG style
)
144 if (COMBO_Init() && (lphc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HEADCOMBO
))) )
147 SetWindowLongA( hwnd
, 0, (LONG
)lphc
);
149 /* some braindead apps do try to use scrollbar/border flags */
151 lphc
->dwStyle
= style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
);
152 SetWindowLongA( hwnd
, GWL_STYLE
, style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
) );
155 * We also have to remove the client edge style to make sure
156 * we don't end-up with a non client area.
158 SetWindowLongA( hwnd
, GWL_EXSTYLE
,
159 GetWindowLongA( hwnd
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
161 if( !(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) )
162 lphc
->dwStyle
|= CBS_HASSTRINGS
;
163 if( !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) )
164 lphc
->wState
|= CBF_NOTIFY
;
166 TRACE("[%p], style = %08x\n", lphc
, lphc
->dwStyle
);
172 /***********************************************************************
175 static LRESULT
COMBO_NCDestroy( LPHEADCOMBO lphc
)
180 TRACE("[%p]: freeing storage\n", lphc
->self
);
182 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) && lphc
->hWndLBox
)
183 DestroyWindow( lphc
->hWndLBox
);
185 SetWindowLongA( lphc
->self
, 0, 0 );
186 HeapFree( GetProcessHeap(), 0, lphc
);
191 /***********************************************************************
192 * CBGetTextAreaHeight
194 * This method will calculate the height of the text area of the
196 * The height of the text area is set in two ways.
197 * It can be set explicitly through a combobox message or through a
198 * WM_MEASUREITEM callback.
199 * If this is not the case, the height is set to 13 dialog units.
200 * This height was determined through experimentation.
202 static INT
CBGetTextAreaHeight(
208 if( lphc
->editHeight
) /* explicitly set height */
210 iTextItemHeight
= lphc
->editHeight
;
215 HDC hDC
= GetDC(hwnd
);
220 hPrevFont
= SelectObject( hDC
, lphc
->hFont
);
222 GetTextMetricsW(hDC
, &tm
);
224 baseUnitY
= tm
.tmHeight
;
227 SelectObject( hDC
, hPrevFont
);
229 ReleaseDC(hwnd
, hDC
);
231 iTextItemHeight
= ((13 * baseUnitY
) / 8);
234 * This "formula" calculates the height of the complete control.
235 * To calculate the height of the text area, we have to remove the
238 iTextItemHeight
-= 2*COMBO_YBORDERSIZE();
242 * Check the ownerdraw case if we haven't asked the parent the size
245 if ( CB_OWNERDRAWN(lphc
) &&
246 (lphc
->wState
& CBF_MEASUREITEM
) )
248 MEASUREITEMSTRUCT measureItem
;
250 INT originalItemHeight
= iTextItemHeight
;
251 UINT id
= GetWindowLongA( lphc
->self
, GWL_ID
);
254 * We use the client rect for the width of the item.
256 GetClientRect(hwnd
, &clientRect
);
258 lphc
->wState
&= ~CBF_MEASUREITEM
;
261 * Send a first one to measure the size of the text area
263 measureItem
.CtlType
= ODT_COMBOBOX
;
264 measureItem
.CtlID
= id
;
265 measureItem
.itemID
= -1;
266 measureItem
.itemWidth
= clientRect
.right
;
267 measureItem
.itemHeight
= iTextItemHeight
- 6; /* ownerdrawn cb is taller */
268 measureItem
.itemData
= 0;
269 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
270 iTextItemHeight
= 6 + measureItem
.itemHeight
;
273 * Send a second one in the case of a fixed ownerdraw list to calculate the
274 * size of the list items. (we basically do this on behalf of the listbox)
276 if (lphc
->dwStyle
& CBS_OWNERDRAWFIXED
)
278 measureItem
.CtlType
= ODT_COMBOBOX
;
279 measureItem
.CtlID
= id
;
280 measureItem
.itemID
= 0;
281 measureItem
.itemWidth
= clientRect
.right
;
282 measureItem
.itemHeight
= originalItemHeight
;
283 measureItem
.itemData
= 0;
284 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
285 lphc
->fixedOwnerDrawHeight
= measureItem
.itemHeight
;
289 * Keep the size for the next time
291 lphc
->editHeight
= iTextItemHeight
;
294 return iTextItemHeight
;
297 /***********************************************************************
300 * The dummy resize is used for listboxes that have a popup to trigger
301 * a re-arranging of the contents of the combobox and the recalculation
302 * of the size of the "real" control window.
304 static void CBForceDummyResize(
310 newComboHeight
= CBGetTextAreaHeight(lphc
->self
,lphc
) + 2*COMBO_YBORDERSIZE();
312 GetWindowRect(lphc
->self
, &windowRect
);
315 * We have to be careful, resizing a combobox also has the meaning that the
316 * dropped rect will be resized. In this case, we want to trigger a resize
317 * to recalculate layout but we don't want to change the dropped rectangle
318 * So, we pass the height of text area of control as the height.
319 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
322 SetWindowPos( lphc
->self
,
325 windowRect
.right
- windowRect
.left
,
327 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
330 /***********************************************************************
333 * Set up component coordinates given valid lphc->RectCombo.
335 static void CBCalcPlacement(
343 * Again, start with the client rectangle.
345 GetClientRect(hwnd
, lprEdit
);
350 InflateRect(lprEdit
, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
353 * Chop off the bottom part to fit with the height of the text area.
355 lprEdit
->bottom
= lprEdit
->top
+ CBGetTextAreaHeight(hwnd
, lphc
);
358 * The button starts the same vertical position as the text area.
360 CopyRect(lprButton
, lprEdit
);
363 * If the combobox is "simple" there is no button.
365 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
366 lprButton
->left
= lprButton
->right
= lprButton
->bottom
= 0;
370 * Let's assume the combobox button is the same width as the
372 * size the button horizontally and cut-off the text area.
374 lprButton
->left
= lprButton
->right
- GetSystemMetrics(SM_CXVSCROLL
);
375 lprEdit
->right
= lprButton
->left
;
379 * In the case of a dropdown, there is an additional spacing between the
380 * text area and the button.
382 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
384 lprEdit
->right
-= COMBO_EDITBUTTONSPACE();
388 * If we have an edit control, we space it away from the borders slightly.
390 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
392 InflateRect(lprEdit
, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
396 * Adjust the size of the listbox popup.
398 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
401 * Use the client rectangle to initialize the listbox rectangle
403 GetClientRect(hwnd
, lprLB
);
406 * Then, chop-off the top part.
408 lprLB
->top
= lprEdit
->bottom
+ COMBO_YBORDERSIZE();
413 * Make sure the dropped width is as large as the combobox itself.
415 if (lphc
->droppedWidth
< (lprButton
->right
+ COMBO_XBORDERSIZE()))
417 lprLB
->right
= lprLB
->left
+ (lprButton
->right
+ COMBO_XBORDERSIZE());
420 * In the case of a dropdown, the popup listbox is offset to the right.
421 * so, we want to make sure it's flush with the right side of the
424 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
425 lprLB
->right
-= COMBO_EDITBUTTONSPACE();
428 lprLB
->right
= lprLB
->left
+ lphc
->droppedWidth
;
431 TRACE("\ttext\t= (%ld,%ld-%ld,%ld)\n",
432 lprEdit
->left
, lprEdit
->top
, lprEdit
->right
, lprEdit
->bottom
);
434 TRACE("\tbutton\t= (%ld,%ld-%ld,%ld)\n",
435 lprButton
->left
, lprButton
->top
, lprButton
->right
, lprButton
->bottom
);
437 TRACE("\tlbox\t= (%ld,%ld-%ld,%ld)\n",
438 lprLB
->left
, lprLB
->top
, lprLB
->right
, lprLB
->bottom
);
441 /***********************************************************************
442 * CBGetDroppedControlRect
444 static void CBGetDroppedControlRect( LPHEADCOMBO lphc
, LPRECT lpRect
)
446 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
447 of the combo box and the lower right corner of the listbox */
449 GetWindowRect(lphc
->self
, lpRect
);
451 lpRect
->right
= lpRect
->left
+ lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
452 lpRect
->bottom
= lpRect
->top
+ lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
456 /***********************************************************************
457 * COMBO_WindowPosChanging
459 static LRESULT
COMBO_WindowPosChanging(
462 WINDOWPOS
* posChanging
)
465 * We need to override the WM_WINDOWPOSCHANGING method to handle all
466 * the non-simple comboboxes. The problem is that those controls are
467 * always the same height. We have to make sure they are not resized
470 if ( ( CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
471 ((posChanging
->flags
& SWP_NOSIZE
) == 0) )
475 newComboHeight
= CBGetTextAreaHeight(hwnd
,lphc
) +
476 2*COMBO_YBORDERSIZE();
479 * Resizing a combobox has another side effect, it resizes the dropped
480 * rectangle as well. However, it does it only if the new height for the
481 * combobox is different from the height it should have. In other words,
482 * if the application resizing the combobox only had the intention to resize
483 * the actual control, for example, to do the layout of a dialog that is
484 * resized, the height of the dropdown is not changed.
486 if (posChanging
->cy
!= newComboHeight
)
488 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%ld, oldtop=%ld\n",
489 posChanging
->cy
, newComboHeight
, lphc
->droppedRect
.bottom
,
490 lphc
->droppedRect
.top
);
491 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
+ posChanging
->cy
- newComboHeight
;
493 posChanging
->cy
= newComboHeight
;
500 /***********************************************************************
503 static LRESULT
COMBO_Create( HWND hwnd
, LPHEADCOMBO lphc
, HWND hwndParent
, LONG style
,
506 static const WCHAR clbName
[] = {'C','o','m','b','o','L','B','o','x',0};
507 static const WCHAR editName
[] = {'E','d','i','t',0};
509 if( !CB_GETTYPE(lphc
) ) lphc
->dwStyle
|= CBS_SIMPLE
;
510 if( CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
) lphc
->wState
|= CBF_EDIT
;
512 lphc
->owner
= hwndParent
;
515 * The item height and dropped width are not set when the control
518 lphc
->droppedWidth
= lphc
->editHeight
= 0;
521 * The first time we go through, we want to measure the ownerdraw item
523 lphc
->wState
|= CBF_MEASUREITEM
;
525 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
527 if( lphc
->owner
|| !(style
& WS_VISIBLE
) )
533 * Initialize the dropped rect to the size of the client area of the
534 * control and then, force all the areas of the combobox to be
537 GetClientRect( hwnd
, &lphc
->droppedRect
);
538 CBCalcPlacement(hwnd
, lphc
, &lphc
->textRect
, &lphc
->buttonRect
, &lphc
->droppedRect
);
541 * Adjust the position of the popup listbox if it's necessary
543 if ( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
545 lphc
->droppedRect
.top
= lphc
->textRect
.bottom
+ COMBO_YBORDERSIZE();
548 * If it's a dropdown, the listbox is offset
550 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
551 lphc
->droppedRect
.left
+= COMBO_EDITBUTTONSPACE();
553 ClientToScreen(hwnd
, (LPPOINT
)&lphc
->droppedRect
);
554 ClientToScreen(hwnd
, (LPPOINT
)&lphc
->droppedRect
.right
);
557 /* create listbox popup */
559 lbeStyle
= (LBS_NOTIFY
| WS_BORDER
| WS_CLIPSIBLINGS
| WS_CHILD
) |
560 (style
& (WS_VSCROLL
| CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
));
562 if( lphc
->dwStyle
& CBS_SORT
)
563 lbeStyle
|= LBS_SORT
;
564 if( lphc
->dwStyle
& CBS_HASSTRINGS
)
565 lbeStyle
|= LBS_HASSTRINGS
;
566 if( lphc
->dwStyle
& CBS_NOINTEGRALHEIGHT
)
567 lbeStyle
|= LBS_NOINTEGRALHEIGHT
;
568 if( lphc
->dwStyle
& CBS_DISABLENOSCROLL
)
569 lbeStyle
|= LBS_DISABLENOSCROLL
;
571 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
) /* child listbox */
573 lbeStyle
|= WS_VISIBLE
;
576 * In win 95 look n feel, the listbox in the simple combobox has
577 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
579 lbeStyle
&= ~WS_BORDER
;
580 lbeExStyle
|= WS_EX_CLIENTEDGE
;
584 lbeExStyle
|= (WS_EX_TOPMOST
| WS_EX_TOOLWINDOW
);
588 lphc
->hWndLBox
= CreateWindowExW(lbeExStyle
, clbName
, NULL
, lbeStyle
,
589 lphc
->droppedRect
.left
,
590 lphc
->droppedRect
.top
,
591 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
592 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
593 hwnd
, (HMENU
)ID_CB_LISTBOX
,
594 (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
), lphc
);
596 lphc
->hWndLBox
= CreateWindowExA(lbeExStyle
, "ComboLBox", NULL
, lbeStyle
,
597 lphc
->droppedRect
.left
,
598 lphc
->droppedRect
.top
,
599 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
600 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
601 hwnd
, (HMENU
)ID_CB_LISTBOX
,
602 (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
), lphc
);
607 lbeStyle
= WS_CHILD
| WS_VISIBLE
| ES_NOHIDESEL
| ES_LEFT
| ES_COMBO
;
609 if( lphc
->wState
& CBF_EDIT
)
611 if( lphc
->dwStyle
& CBS_OEMCONVERT
)
612 lbeStyle
|= ES_OEMCONVERT
;
613 if( lphc
->dwStyle
& CBS_AUTOHSCROLL
)
614 lbeStyle
|= ES_AUTOHSCROLL
;
615 if( lphc
->dwStyle
& CBS_LOWERCASE
)
616 lbeStyle
|= ES_LOWERCASE
;
617 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
618 lbeStyle
|= ES_UPPERCASE
;
620 if (!IsWindowEnabled(hwnd
)) lbeStyle
|= WS_DISABLED
;
623 lphc
->hWndEdit
= CreateWindowExW(0, editName
, NULL
, lbeStyle
,
624 lphc
->textRect
.left
, lphc
->textRect
.top
,
625 lphc
->textRect
.right
- lphc
->textRect
.left
,
626 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
627 hwnd
, (HMENU
)ID_CB_EDIT
,
628 (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
), NULL
);
630 lphc
->hWndEdit
= CreateWindowExA(0, "Edit", NULL
, lbeStyle
,
631 lphc
->textRect
.left
, lphc
->textRect
.top
,
632 lphc
->textRect
.right
- lphc
->textRect
.left
,
633 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
634 hwnd
, (HMENU
)ID_CB_EDIT
,
635 (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
), NULL
);
637 if( !lphc
->hWndEdit
)
643 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
645 /* Now do the trick with parent */
646 SetParent(lphc
->hWndLBox
, HWND_DESKTOP
);
648 * If the combo is a dropdown, we must resize the control
649 * to fit only the text area and button. To do this,
650 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
651 * will take care of setting the height for us.
653 CBForceDummyResize(lphc
);
656 TRACE("init done\n");
659 ERR("edit control failure.\n");
660 } else ERR("listbox failure.\n");
661 } else ERR("no owner for visible combo.\n");
663 /* CreateWindow() will send WM_NCDESTROY to cleanup */
668 /***********************************************************************
671 * Paint combo button (normal, pressed, and disabled states).
673 static void CBPaintButton( LPHEADCOMBO lphc
, HDC hdc
, RECT rectButton
)
675 UINT buttonState
= DFCS_SCROLLCOMBOBOX
;
677 if( lphc
->wState
& CBF_NOREDRAW
)
681 if (lphc
->wState
& CBF_BUTTONDOWN
)
682 buttonState
|= DFCS_PUSHED
;
684 if (CB_DISABLED(lphc
))
685 buttonState
|= DFCS_INACTIVE
;
687 DrawFrameControl(hdc
, &rectButton
, DFC_SCROLL
, buttonState
);
690 /***********************************************************************
693 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
695 static void CBPaintText(
703 if( lphc
->wState
& CBF_NOREDRAW
) return;
707 /* follow Windows combobox that sends a bunch of text
708 * inquiries to its listbox while processing WM_PAINT. */
710 if( (id
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0) ) != LB_ERR
)
712 size
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, id
, 0);
714 FIXME("LB_ERR probably not handled yet\n");
715 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (size
+ 1) * sizeof(WCHAR
))) )
717 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
718 size
=SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, (WPARAM
)id
, (LPARAM
)pText
);
719 pText
[size
] = '\0'; /* just in case */
723 if( !CB_OWNERDRAWN(lphc
) )
726 if( lphc
->wState
& CBF_EDIT
)
728 static const WCHAR empty_stringW
[] = { 0 };
729 if( CB_HASSTRINGS(lphc
) ) SetWindowTextW( lphc
->hWndEdit
, pText
? pText
: empty_stringW
);
730 if( lphc
->wState
& CBF_FOCUSED
)
731 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
733 else /* paint text field ourselves */
735 UINT itemState
= ODS_COMBOBOXEDIT
;
736 HFONT hPrevFont
= (lphc
->hFont
) ? SelectObject(hdc
, lphc
->hFont
) : 0;
739 * Give ourselves some space.
741 InflateRect( &rectEdit
, -1, -1 );
743 if( CB_OWNERDRAWN(lphc
) )
747 UINT ctlid
= GetWindowLongA( lphc
->self
, GWL_ID
);
749 /* setup state for DRAWITEM message. Owner will highlight */
750 if ( (lphc
->wState
& CBF_FOCUSED
) &&
751 !(lphc
->wState
& CBF_DROPPED
) )
752 itemState
|= ODS_SELECTED
| ODS_FOCUS
;
755 * Save the current clip region.
756 * To retrieve the clip region, we need to create one "dummy"
759 clipRegion
= CreateRectRgnIndirect(&rectEdit
);
761 if (GetClipRgn(hdc
, clipRegion
)!=1)
763 DeleteObject(clipRegion
);
767 if (!IsWindowEnabled(lphc
->self
) & WS_DISABLED
) itemState
|= ODS_DISABLED
;
769 dis
.CtlType
= ODT_COMBOBOX
;
771 dis
.hwndItem
= lphc
->self
;
772 dis
.itemAction
= ODA_DRAWENTIRE
;
774 dis
.itemState
= itemState
;
776 dis
.rcItem
= rectEdit
;
777 dis
.itemData
= SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
,
781 * Clip the DC and have the parent draw the item.
783 IntersectClipRect(hdc
,
784 rectEdit
.left
, rectEdit
.top
,
785 rectEdit
.right
, rectEdit
.bottom
);
787 SendMessageW(lphc
->owner
, WM_DRAWITEM
, ctlid
, (LPARAM
)&dis
);
790 * Reset the clipping region.
792 SelectClipRgn(hdc
, clipRegion
);
796 static const WCHAR empty_stringW
[] = { 0 };
798 if ( (lphc
->wState
& CBF_FOCUSED
) &&
799 !(lphc
->wState
& CBF_DROPPED
) ) {
802 FillRect( hdc
, &rectEdit
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
803 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
804 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
810 ETO_OPAQUE
| ETO_CLIPPED
,
812 pText
? pText
: empty_stringW
, size
, NULL
);
814 if(lphc
->wState
& CBF_FOCUSED
&& !(lphc
->wState
& CBF_DROPPED
))
815 DrawFocusRect( hdc
, &rectEdit
);
819 SelectObject(hdc
, hPrevFont
);
822 HeapFree( GetProcessHeap(), 0, pText
);
825 /***********************************************************************
828 static void CBPaintBorder(
835 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
837 GetClientRect(hwnd
, &clientRect
);
841 CopyRect(&clientRect
, &lphc
->textRect
);
843 InflateRect(&clientRect
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
844 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
847 DrawEdge(hdc
, &clientRect
, EDGE_SUNKEN
, BF_RECT
);
850 /***********************************************************************
851 * COMBO_PrepareColors
853 * This method will sent the appropriate WM_CTLCOLOR message to
854 * prepare and setup the colors for the combo's DC.
856 * It also returns the brush to use for the background.
858 static HBRUSH
COMBO_PrepareColors(
865 * Get the background brush for this control.
867 if (CB_DISABLED(lphc
))
869 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORSTATIC
,
870 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
873 * We have to change the text color since WM_CTLCOLORSTATIC will
874 * set it to the "enabled" color. This is the same behavior as the
877 SetTextColor(hDC
, GetSysColor(COLOR_GRAYTEXT
));
881 if (lphc
->wState
& CBF_EDIT
)
883 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLOREDIT
,
884 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
888 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORLISTBOX
,
889 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
897 hBkgBrush
= GetSysColorBrush(COLOR_WINDOW
);
902 /***********************************************************************
903 * COMBO_EraseBackground
905 static LRESULT
COMBO_EraseBackground(
913 if(lphc
->wState
& CBF_EDIT
)
916 hDC
= (hParamDC
) ? hParamDC
919 * Retrieve the background brush
921 hBkgBrush
= COMBO_PrepareColors(lphc
, hDC
);
923 FillRect(hDC
, &lphc
->textRect
, hBkgBrush
);
926 ReleaseDC(hwnd
, hDC
);
931 /***********************************************************************
934 static LRESULT
COMBO_Paint(LPHEADCOMBO lphc
, HDC hParamDC
)
939 hDC
= (hParamDC
) ? hParamDC
940 : BeginPaint( lphc
->self
, &ps
);
942 TRACE("hdc=%p\n", hDC
);
944 if( hDC
&& !(lphc
->wState
& CBF_NOREDRAW
) )
946 HBRUSH hPrevBrush
, hBkgBrush
;
949 * Retrieve the background brush and select it in the
952 hBkgBrush
= COMBO_PrepareColors(lphc
, hDC
);
954 hPrevBrush
= SelectObject( hDC
, hBkgBrush
);
957 * In non 3.1 look, there is a sunken border on the combobox
959 CBPaintBorder(lphc
->self
, lphc
, hDC
);
961 if( !IsRectEmpty(&lphc
->buttonRect
) )
963 CBPaintButton(lphc
, hDC
, lphc
->buttonRect
);
966 /* paint the edit control padding area */
967 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
969 RECT rPadEdit
= lphc
->textRect
;
971 InflateRect(&rPadEdit
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
973 FrameRect( hDC
, &rPadEdit
, GetSysColorBrush(COLOR_WINDOW
) );
976 if( !(lphc
->wState
& CBF_EDIT
) )
977 CBPaintText( lphc
, hDC
, lphc
->textRect
);
980 SelectObject( hDC
, hPrevBrush
);
984 EndPaint(lphc
->self
, &ps
);
989 /***********************************************************************
992 * Select listbox entry according to the contents of the edit control.
994 static INT
CBUpdateLBox( LPHEADCOMBO lphc
, BOOL bSelect
)
1000 length
= SendMessageW( lphc
->hWndEdit
, WM_GETTEXTLENGTH
, 0, 0 );
1003 pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
1005 TRACE("\t edit text length %i\n", length
);
1009 if( length
) GetWindowTextW( lphc
->hWndEdit
, pText
, length
+ 1);
1010 else pText
[0] = '\0';
1011 idx
= SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
,
1012 (WPARAM
)(-1), (LPARAM
)pText
);
1013 HeapFree( GetProcessHeap(), 0, pText
);
1016 SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, (WPARAM
)(bSelect
? idx
: -1), 0);
1018 /* probably superfluous but Windows sends this too */
1019 SendMessageW(lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
1020 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
1025 /***********************************************************************
1028 * Copy a listbox entry to the edit control.
1030 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1033 LPWSTR pText
= NULL
;
1034 static const WCHAR empty_stringW
[] = { 0 };
1036 TRACE("\t %i\n", index
);
1038 if( index
>= 0 ) /* got an entry */
1040 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1041 if( length
!= LB_ERR
)
1043 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
))) )
1045 SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
,
1046 (WPARAM
)index
, (LPARAM
)pText
);
1051 lphc
->wState
|= (CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1052 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, pText
? (LPARAM
)pText
: (LPARAM
)empty_stringW
);
1053 lphc
->wState
&= ~(CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1055 if( lphc
->wState
& CBF_FOCUSED
)
1056 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1059 HeapFree( GetProcessHeap(), 0, pText
);
1062 /***********************************************************************
1065 * Show listbox popup.
1067 static void CBDropDown( LPHEADCOMBO lphc
)
1073 TRACE("[%p]: drop down\n", lphc
->self
);
1075 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1079 lphc
->wState
|= CBF_DROPPED
;
1080 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1082 lphc
->droppedIndex
= CBUpdateLBox( lphc
, TRUE
);
1084 /* Update edit only if item is in the list */
1085 if( !(lphc
->wState
& CBF_CAPTURE
) && lphc
->droppedIndex
>= 0)
1086 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1090 lphc
->droppedIndex
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1092 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
,
1093 (WPARAM
)(lphc
->droppedIndex
== LB_ERR
? 0 : lphc
->droppedIndex
), 0 );
1094 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1097 /* now set popup position */
1098 GetWindowRect( lphc
->self
, &rect
);
1101 * If it's a dropdown, the listbox is offset
1103 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1104 rect
.left
+= COMBO_EDITBUTTONSPACE();
1106 /* if the dropped height is greater than the total height of the dropped
1107 items list, then force the drop down list height to be the total height
1108 of the items in the dropped list */
1110 /* And Remove any extra space (Best Fit) */
1111 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1112 /* if listbox length has been set directly by its handle */
1113 GetWindowRect(lphc
->hWndLBox
, &r
);
1114 if (nDroppedHeight
< r
.bottom
- r
.top
)
1115 nDroppedHeight
= r
.bottom
- r
.top
;
1116 nItems
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1123 nIHeight
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, 0, 0);
1125 nHeight
= nIHeight
*nItems
;
1127 if (nHeight
< nDroppedHeight
- COMBO_YBORDERSIZE())
1128 nDroppedHeight
= nHeight
+ COMBO_YBORDERSIZE();
1130 if (nDroppedHeight
< nIHeight
)
1133 nDroppedHeight
= (nItems
+1)*nIHeight
;
1135 nDroppedHeight
= 6*nIHeight
;
1139 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1140 if( (rect
.bottom
+ nDroppedHeight
) >= GetSystemMetrics( SM_CYSCREEN
) )
1141 rect
.bottom
= rect
.top
- nDroppedHeight
;
1143 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1144 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1146 SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
1149 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1150 RedrawWindow( lphc
->self
, NULL
, 0, RDW_INVALIDATE
|
1151 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1153 EnableWindow( lphc
->hWndLBox
, TRUE
);
1154 if (GetCapture() != lphc
->self
)
1155 SetCapture(lphc
->hWndLBox
);
1158 /***********************************************************************
1161 * Hide listbox popup.
1163 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1165 HWND hWnd
= lphc
->self
;
1167 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1168 lphc
->self
, (INT
)ok
, (INT
)(lphc
->wState
& CBF_DROPPED
));
1170 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1172 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1175 if( lphc
->wState
& CBF_DROPPED
)
1179 lphc
->wState
&= ~CBF_DROPPED
;
1180 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1182 if(GetCapture() == lphc
->hWndLBox
)
1187 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1189 rect
= lphc
->buttonRect
;
1200 rect
= lphc
->textRect
;
1205 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1206 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1207 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1208 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1213 /***********************************************************************
1216 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1218 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL ok
, BOOL bRedrawButton
)
1220 if( lphc
->wState
& CBF_DROPPED
)
1222 CBRollUp( lphc
, ok
, bRedrawButton
);
1230 /***********************************************************************
1233 static void CBRepaintButton( LPHEADCOMBO lphc
)
1235 InvalidateRect(lphc
->self
, &lphc
->buttonRect
, TRUE
);
1236 UpdateWindow(lphc
->self
);
1239 /***********************************************************************
1242 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1244 if( !(lphc
->wState
& CBF_FOCUSED
) )
1246 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1247 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1249 /* This is wrong. Message sequences seem to indicate that this
1250 is set *after* the notify. */
1251 /* lphc->wState |= CBF_FOCUSED; */
1253 if( !(lphc
->wState
& CBF_EDIT
) )
1254 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1256 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1257 lphc
->wState
|= CBF_FOCUSED
;
1261 /***********************************************************************
1264 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1266 HWND hWnd
= lphc
->self
;
1268 if( lphc
->wState
& CBF_FOCUSED
)
1270 CBRollUp( lphc
, FALSE
, TRUE
);
1271 if( IsWindow( hWnd
) )
1273 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1274 SendMessageW(lphc
->hWndLBox
, LB_CARETOFF
, 0, 0);
1276 lphc
->wState
&= ~CBF_FOCUSED
;
1279 if( !(lphc
->wState
& CBF_EDIT
) )
1280 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1282 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1287 /***********************************************************************
1290 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1292 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1294 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1296 switch( HIWORD(wParam
) >> 8 )
1298 case (EN_SETFOCUS
>> 8):
1300 TRACE("[%p]: edit [%p] got focus\n", lphc
->self
, lphc
->hWndEdit
);
1302 COMBO_SetFocus( lphc
);
1305 case (EN_KILLFOCUS
>> 8):
1307 TRACE("[%p]: edit [%p] lost focus\n", lphc
->self
, lphc
->hWndEdit
);
1309 /* NOTE: it seems that Windows' edit control sends an
1310 * undocumented message WM_USER + 0x1B instead of this
1311 * notification (only when it happens to be a part of
1312 * the combo). ?? - AK.
1315 COMBO_KillFocus( lphc
);
1319 case (EN_CHANGE
>> 8):
1321 * In some circumstances (when the selection of the combobox
1322 * is changed for example) we don't wans the EN_CHANGE notification
1323 * to be forwarded to the parent of the combobox. This code
1324 * checks a flag that is set in these occasions and ignores the
1327 if (lphc
->wState
& CBF_NOLBSELECT
)
1329 lphc
->wState
&= ~CBF_NOLBSELECT
;
1333 CBUpdateLBox( lphc
, lphc
->wState
& CBF_DROPPED
);
1336 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1337 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1340 case (EN_UPDATE
>> 8):
1341 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1342 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1345 case (EN_ERRSPACE
>> 8):
1346 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1349 else if( lphc
->hWndLBox
== hWnd
)
1351 switch( (short)HIWORD(wParam
) )
1354 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1358 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1364 TRACE("[%p]: lbox selection change [%x]\n", lphc
->self
, lphc
->wState
);
1366 if( HIWORD(wParam
) == LBN_SELCHANGE
)
1368 if( lphc
->wState
& CBF_EDIT
)
1370 INT index
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1371 lphc
->wState
|= CBF_NOLBSELECT
;
1372 CBUpdateEdit( lphc
, index
);
1373 /* select text in edit, as Windows does */
1374 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1377 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1380 /* do not roll up if selection is being tracked
1381 * by arrowkeys in the dropdown listbox */
1382 if( ((lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
)) )
1384 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1386 else lphc
->wState
&= ~CBF_NOROLLUP
;
1388 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1394 /* nothing to do here since ComboLBox always resets the focus to its
1395 * combo/edit counterpart */
1402 /***********************************************************************
1405 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1407 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
, LPARAM lParam
)
1409 HWND hWnd
= lphc
->self
;
1410 UINT id
= GetWindowLongA( hWnd
, GWL_ID
);
1412 TRACE("[%p]: ownerdraw op %04x\n", lphc
->self
, msg
);
1418 DELETEITEMSTRUCT
*lpIS
= (DELETEITEMSTRUCT
*)lParam
;
1419 lpIS
->CtlType
= ODT_COMBOBOX
;
1421 lpIS
->hwndItem
= hWnd
;
1426 DRAWITEMSTRUCT
*lpIS
= (DRAWITEMSTRUCT
*)lParam
;
1427 lpIS
->CtlType
= ODT_COMBOBOX
;
1429 lpIS
->hwndItem
= hWnd
;
1432 case WM_COMPAREITEM
:
1434 COMPAREITEMSTRUCT
*lpIS
= (COMPAREITEMSTRUCT
*)lParam
;
1435 lpIS
->CtlType
= ODT_COMBOBOX
;
1437 lpIS
->hwndItem
= hWnd
;
1440 case WM_MEASUREITEM
:
1442 MEASUREITEMSTRUCT
*lpIS
= (MEASUREITEMSTRUCT
*)lParam
;
1443 lpIS
->CtlType
= ODT_COMBOBOX
;
1448 return SendMessageW(lphc
->owner
, msg
, id
, lParam
);
1452 /***********************************************************************
1455 static LRESULT
COMBO_GetTextW( LPHEADCOMBO lphc
, INT count
, LPWSTR buf
)
1459 if( lphc
->wState
& CBF_EDIT
)
1460 return SendMessageW( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1462 /* get it from the listbox */
1464 if (!count
|| !buf
) return 0;
1465 if( lphc
->hWndLBox
)
1467 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1468 if (idx
== LB_ERR
) goto error
;
1469 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1470 if (length
== LB_ERR
) goto error
;
1472 /* 'length' is without the terminating character */
1473 if (length
>= count
)
1475 LPWSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
1476 if (!lpBuffer
) goto error
;
1477 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1479 /* truncate if buffer is too short */
1480 if (length
!= LB_ERR
)
1482 lstrcpynW( buf
, lpBuffer
, count
);
1485 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1487 else length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1489 if (length
== LB_ERR
) return 0;
1493 error
: /* error - truncate string, return zero */
1499 /***********************************************************************
1502 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1503 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1505 static LRESULT
COMBO_GetTextA( LPHEADCOMBO lphc
, INT count
, LPSTR buf
)
1509 if( lphc
->wState
& CBF_EDIT
)
1510 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1512 /* get it from the listbox */
1514 if (!count
|| !buf
) return 0;
1515 if( lphc
->hWndLBox
)
1517 INT idx
= SendMessageA(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1518 if (idx
== LB_ERR
) goto error
;
1519 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1520 if (length
== LB_ERR
) goto error
;
1522 /* 'length' is without the terminating character */
1523 if (length
>= count
)
1525 LPSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) );
1526 if (!lpBuffer
) goto error
;
1527 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1529 /* truncate if buffer is too short */
1530 if (length
!= LB_ERR
)
1532 lstrcpynA( buf
, lpBuffer
, count
);
1535 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1537 else length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1539 if (length
== LB_ERR
) return 0;
1543 error
: /* error - truncate string, return zero */
1549 /***********************************************************************
1552 * This function sets window positions according to the updated
1553 * component placement struct.
1555 static void CBResetPos(
1561 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1563 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1564 * sizing messages */
1566 if( lphc
->wState
& CBF_EDIT
)
1567 SetWindowPos( lphc
->hWndEdit
, 0,
1568 rectEdit
->left
, rectEdit
->top
,
1569 rectEdit
->right
- rectEdit
->left
,
1570 rectEdit
->bottom
- rectEdit
->top
,
1571 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1573 SetWindowPos( lphc
->hWndLBox
, 0,
1574 rectLB
->left
, rectLB
->top
,
1575 rectLB
->right
- rectLB
->left
,
1576 rectLB
->bottom
- rectLB
->top
,
1577 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1581 if( lphc
->wState
& CBF_DROPPED
)
1583 lphc
->wState
&= ~CBF_DROPPED
;
1584 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1587 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1588 RedrawWindow( lphc
->self
, NULL
, 0,
1589 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1594 /***********************************************************************
1597 static void COMBO_Size( LPHEADCOMBO lphc
)
1599 CBCalcPlacement(lphc
->self
,
1603 &lphc
->droppedRect
);
1605 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1609 /***********************************************************************
1612 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1617 lphc
->hFont
= hFont
;
1620 * Propagate to owned windows.
1622 if( lphc
->wState
& CBF_EDIT
)
1623 SendMessageW(lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1624 SendMessageW(lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1627 * Redo the layout of the control.
1629 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1631 CBCalcPlacement(lphc
->self
,
1635 &lphc
->droppedRect
);
1637 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1641 CBForceDummyResize(lphc
);
1646 /***********************************************************************
1647 * COMBO_SetItemHeight
1649 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1651 LRESULT lRet
= CB_ERR
;
1653 if( index
== -1 ) /* set text field height */
1655 if( height
< 32768 )
1657 lphc
->editHeight
= height
;
1660 * Redo the layout of the control.
1662 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1664 CBCalcPlacement(lphc
->self
,
1668 &lphc
->droppedRect
);
1670 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1674 CBForceDummyResize(lphc
);
1680 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1681 lRet
= SendMessageW(lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1682 (WPARAM
)index
, (LPARAM
)height
);
1686 /***********************************************************************
1687 * COMBO_SelectString
1689 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPARAM pText
, BOOL unicode
)
1691 INT index
= unicode
? SendMessageW(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
) :
1692 SendMessageA(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
);
1695 if( lphc
->wState
& CBF_EDIT
)
1696 CBUpdateEdit( lphc
, index
);
1699 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1702 return (LRESULT
)index
;
1705 /***********************************************************************
1708 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1712 HWND hWnd
= lphc
->self
;
1714 pt
.x
= LOWORD(lParam
);
1715 pt
.y
= HIWORD(lParam
);
1716 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1718 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1719 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1721 lphc
->wState
|= CBF_BUTTONDOWN
;
1722 if( lphc
->wState
& CBF_DROPPED
)
1724 /* got a click to cancel selection */
1726 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1727 CBRollUp( lphc
, TRUE
, FALSE
);
1728 if( !IsWindow( hWnd
) ) return;
1730 if( lphc
->wState
& CBF_CAPTURE
)
1732 lphc
->wState
&= ~CBF_CAPTURE
;
1738 /* drop down the listbox and start tracking */
1740 lphc
->wState
|= CBF_CAPTURE
;
1744 if( bButton
) CBRepaintButton( lphc
);
1748 /***********************************************************************
1751 * Release capture and stop tracking if needed.
1753 static void COMBO_LButtonUp( LPHEADCOMBO lphc
)
1755 if( lphc
->wState
& CBF_CAPTURE
)
1757 lphc
->wState
&= ~CBF_CAPTURE
;
1758 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1760 INT index
= CBUpdateLBox( lphc
, TRUE
);
1761 /* Update edit only if item is in the list */
1764 lphc
->wState
|= CBF_NOLBSELECT
;
1765 CBUpdateEdit( lphc
, index
);
1766 lphc
->wState
&= ~CBF_NOLBSELECT
;
1770 SetCapture(lphc
->hWndLBox
);
1773 if( lphc
->wState
& CBF_BUTTONDOWN
)
1775 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1776 CBRepaintButton( lphc
);
1780 /***********************************************************************
1783 * Two things to do - track combo button and release capture when
1784 * pointer goes into the listbox.
1786 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1791 pt
.x
= LOWORD(lParam
);
1792 pt
.y
= HIWORD(lParam
);
1794 if( lphc
->wState
& CBF_BUTTONDOWN
)
1798 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1802 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1803 CBRepaintButton( lphc
);
1807 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1808 MapWindowPoints( lphc
->self
, lphc
->hWndLBox
, &pt
, 1 );
1809 if( PtInRect(&lbRect
, pt
) )
1811 lphc
->wState
&= ~CBF_CAPTURE
;
1813 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
, TRUE
);
1815 /* hand over pointer tracking */
1816 SendMessageW(lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1821 /***********************************************************************
1822 * ComboWndProc_common
1824 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1826 static LRESULT
ComboWndProc_common( HWND hwnd
, UINT message
,
1827 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1829 LPHEADCOMBO lphc
= (LPHEADCOMBO
)GetWindowLongA( hwnd
, 0 );
1831 TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1832 hwnd
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1834 if( lphc
|| message
== WM_NCCREATE
)
1838 /* System messages */
1842 LONG style
= unicode
? ((LPCREATESTRUCTW
)lParam
)->style
:
1843 ((LPCREATESTRUCTA
)lParam
)->style
;
1844 return COMBO_NCCreate(hwnd
, style
);
1847 COMBO_NCDestroy(lphc
);
1848 break;/* -> DefWindowProc */
1856 hwndParent
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
1857 style
= ((LPCREATESTRUCTW
)lParam
)->style
;
1861 hwndParent
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
1862 style
= ((LPCREATESTRUCTA
)lParam
)->style
;
1864 return COMBO_Create(hwnd
, lphc
, hwndParent
, style
, unicode
);
1867 case WM_PRINTCLIENT
:
1868 if (lParam
& PRF_ERASEBKGND
)
1869 COMBO_EraseBackground(hwnd
, lphc
, (HDC
)wParam
);
1873 /* wParam may contain a valid HDC! */
1874 return COMBO_Paint(lphc
, (HDC
)wParam
);
1876 return COMBO_EraseBackground(hwnd
, lphc
, (HDC
)wParam
);
1879 LRESULT result
= DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1880 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1882 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1884 if ((vk
== VK_RETURN
|| vk
== VK_ESCAPE
) && (lphc
->wState
& CBF_DROPPED
))
1885 result
|= DLGC_WANTMESSAGE
;
1889 case WM_WINDOWPOSCHANGING
:
1890 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1891 case WM_WINDOWPOSCHANGED
:
1892 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1893 * In that case, the Combobox itself will not be resized, so we won't
1894 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1899 if( lphc
->hWndLBox
&&
1900 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
);
1903 COMBO_Font( lphc
, (HFONT
)wParam
, (BOOL
)lParam
);
1906 return (LRESULT
)lphc
->hFont
;
1908 if( lphc
->wState
& CBF_EDIT
)
1909 SetFocus( lphc
->hWndEdit
);
1911 COMBO_SetFocus( lphc
);
1916 HWND hwndFocus
= (HWND
)wParam
;
1918 HWND hwndFocus
= WIN_GetFullHandle( (HWND
)wParam
);
1921 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1922 COMBO_KillFocus( lphc
);
1927 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1929 return COMBO_Command( lphc
, wParam
, WIN_GetFullHandle( (HWND
)lParam
) );
1932 return unicode
? COMBO_GetTextW( lphc
, wParam
, (LPWSTR
)lParam
)
1933 : COMBO_GetTextA( lphc
, wParam
, (LPSTR
)lParam
);
1935 case WM_GETTEXTLENGTH
:
1937 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1939 int j
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1940 if (j
== -1) return 0;
1941 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0) :
1942 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1944 else if( lphc
->wState
& CBF_EDIT
)
1947 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1948 ret
= unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1949 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1950 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1957 if( lphc
->wState
& CBF_EDIT
)
1959 return unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1960 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1966 case WM_COMPAREITEM
:
1967 case WM_MEASUREITEM
:
1968 return COMBO_ItemOp(lphc
, message
, lParam
);
1970 if( lphc
->wState
& CBF_EDIT
)
1971 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
1972 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
1974 /* Force the control to repaint when the enabled state changes. */
1975 InvalidateRect(lphc
->self
, NULL
, TRUE
);
1979 lphc
->wState
&= ~CBF_NOREDRAW
;
1981 lphc
->wState
|= CBF_NOREDRAW
;
1983 if( lphc
->wState
& CBF_EDIT
)
1984 SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
);
1985 SendMessageW(lphc
->hWndLBox
, message
, wParam
, lParam
);
1988 if( KEYDATA_ALT
& HIWORD(lParam
) )
1989 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
1990 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
1999 if ((wParam
== VK_RETURN
|| wParam
== VK_ESCAPE
) &&
2000 (lphc
->wState
& CBF_DROPPED
))
2002 CBRollUp( lphc
, wParam
== VK_RETURN
, FALSE
);
2005 else if ((wParam
== VK_F4
) && !(lphc
->wState
& CBF_EUI
))
2007 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2011 if( lphc
->wState
& CBF_EDIT
)
2012 hwndTarget
= lphc
->hWndEdit
;
2014 hwndTarget
= lphc
->hWndLBox
;
2016 return unicode
? SendMessageW(hwndTarget
, message
, wParam
, lParam
) :
2017 SendMessageA(hwndTarget
, message
, wParam
, lParam
);
2019 case WM_LBUTTONDOWN
:
2020 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
);
2021 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
2024 COMBO_LButtonUp( lphc
);
2027 if( lphc
->wState
& CBF_CAPTURE
)
2028 COMBO_MouseMove( lphc
, wParam
, lParam
);
2032 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
2033 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2034 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2036 if (GET_WHEEL_DELTA_WPARAM(wParam
) > 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_UP
, 0);
2037 if (GET_WHEEL_DELTA_WPARAM(wParam
) < 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_DOWN
, 0);
2040 /* Combo messages */
2043 case CB_ADDSTRING16
:
2044 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2050 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2051 strlwrW((LPWSTR
)lParam
);
2052 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2053 struprW((LPWSTR
)lParam
);
2054 return SendMessageW(lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
2058 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2059 _strlwr((LPSTR
)lParam
);
2060 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2061 _strupr((LPSTR
)lParam
);
2062 return SendMessageA(lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
2065 case CB_INSERTSTRING16
:
2066 wParam
= (INT
)(INT16
)wParam
;
2067 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2070 case CB_INSERTSTRING
:
2073 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2074 strlwrW((LPWSTR
)lParam
);
2075 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2076 struprW((LPWSTR
)lParam
);
2077 return SendMessageW(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2081 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2082 _strlwr((LPSTR
)lParam
);
2083 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2084 _strupr((LPSTR
)lParam
);
2085 return SendMessageA(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2088 case CB_DELETESTRING16
:
2090 case CB_DELETESTRING
:
2091 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0) :
2092 SendMessageA(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
2094 case CB_SELECTSTRING16
:
2095 wParam
= (INT
)(INT16
)wParam
;
2096 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2099 case CB_SELECTSTRING
:
2100 return COMBO_SelectString(lphc
, (INT
)wParam
, lParam
, unicode
);
2102 case CB_FINDSTRING16
:
2103 wParam
= (INT
)(INT16
)wParam
;
2104 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2108 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
) :
2109 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
2111 case CB_FINDSTRINGEXACT16
:
2112 wParam
= (INT
)(INT16
)wParam
;
2113 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2116 case CB_FINDSTRINGEXACT
:
2117 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
) :
2118 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
);
2120 case CB_SETITEMHEIGHT16
:
2121 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
2124 case CB_SETITEMHEIGHT
:
2125 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
2127 case CB_GETITEMHEIGHT16
:
2128 wParam
= (INT
)(INT16
)wParam
;
2131 case CB_GETITEMHEIGHT
:
2132 if( (INT
)wParam
>= 0 ) /* listbox item */
2133 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
2134 return CBGetTextAreaHeight(hwnd
, lphc
);
2136 case CB_RESETCONTENT16
:
2138 case CB_RESETCONTENT
:
2139 SendMessageW(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0);
2140 if( (lphc
->wState
& CBF_EDIT
) && CB_HASSTRINGS(lphc
) )
2142 static const WCHAR empty_stringW
[] = { 0 };
2143 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, (LPARAM
)empty_stringW
);
2146 InvalidateRect(lphc
->self
, NULL
, TRUE
);
2148 case CB_INITSTORAGE
:
2149 return SendMessageW(lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
2150 case CB_GETHORIZONTALEXTENT
:
2151 return SendMessageW(lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
2152 case CB_SETHORIZONTALEXTENT
:
2153 return SendMessageW(lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
2154 case CB_GETTOPINDEX
:
2155 return SendMessageW(lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2157 return SendMessageW(lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2159 return SendMessageW(lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2160 case CB_GETDROPPEDWIDTH
:
2161 if( lphc
->droppedWidth
)
2162 return lphc
->droppedWidth
;
2163 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2164 case CB_SETDROPPEDWIDTH
:
2165 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2166 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2169 case CB_GETDROPPEDCONTROLRECT16
:
2170 lParam
= (LPARAM
)MapSL(lParam
);
2174 CBGetDroppedControlRect( lphc
, &r
);
2175 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2179 case CB_GETDROPPEDCONTROLRECT
:
2180 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2183 case CB_GETDROPPEDSTATE16
:
2185 case CB_GETDROPPEDSTATE
:
2186 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2189 return SendMessageA(lphc
->hWndLBox
, LB_DIR16
, wParam
, lParam
);
2192 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
) :
2193 SendMessageA(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
);
2196 case CB_SHOWDROPDOWN16
:
2198 case CB_SHOWDROPDOWN
:
2199 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2203 if( !(lphc
->wState
& CBF_DROPPED
) )
2207 if( lphc
->wState
& CBF_DROPPED
)
2208 CBRollUp( lphc
, FALSE
, TRUE
);
2215 return SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2217 case CB_GETCURSEL16
:
2220 return SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2222 case CB_SETCURSEL16
:
2223 wParam
= (INT
)(INT16
)wParam
;
2227 lParam
= SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2229 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, wParam
, 0);
2231 /* no LBN_SELCHANGE in this case, update manually */
2232 if( lphc
->wState
& CBF_EDIT
)
2233 CBUpdateEdit( lphc
, (INT
)wParam
);
2235 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2236 lphc
->wState
&= ~CBF_SELCHANGE
;
2239 case CB_GETLBTEXT16
:
2240 wParam
= (INT
)(INT16
)wParam
;
2241 lParam
= (LPARAM
)MapSL(lParam
);
2245 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
) :
2246 SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2248 case CB_GETLBTEXTLEN16
:
2249 wParam
= (INT
)(INT16
)wParam
;
2252 case CB_GETLBTEXTLEN
:
2253 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0) :
2254 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2256 case CB_GETITEMDATA16
:
2257 wParam
= (INT
)(INT16
)wParam
;
2260 case CB_GETITEMDATA
:
2261 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2263 case CB_SETITEMDATA16
:
2264 wParam
= (INT
)(INT16
)wParam
;
2267 case CB_SETITEMDATA
:
2268 return SendMessageW(lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2270 case CB_GETEDITSEL16
:
2271 wParam
= lParam
= 0; /* just in case */
2275 /* Edit checks passed parameters itself */
2276 if( lphc
->wState
& CBF_EDIT
)
2277 return SendMessageW(lphc
->hWndEdit
, EM_GETSEL
, wParam
, lParam
);
2280 case CB_SETEDITSEL16
:
2283 if( lphc
->wState
& CBF_EDIT
)
2284 return SendMessageW(lphc
->hWndEdit
, EM_SETSEL
,
2285 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2288 case CB_SETEXTENDEDUI16
:
2290 case CB_SETEXTENDEDUI
:
2291 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2294 lphc
->wState
|= CBF_EUI
;
2295 else lphc
->wState
&= ~CBF_EUI
;
2298 case CB_GETEXTENDEDUI16
:
2300 case CB_GETEXTENDEDUI
:
2301 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2304 if (message
>= WM_USER
)
2305 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2306 message
- WM_USER
, wParam
, lParam
);
2309 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2310 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2313 /***********************************************************************
2316 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2319 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2321 if (!IsWindow(hwnd
)) return 0;
2322 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
2325 /***********************************************************************
2328 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2330 if (!IsWindow(hwnd
)) return 0;
2331 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
2334 /*************************************************************************
2335 * GetComboBoxInfo (USER32.@)
2337 BOOL WINAPI
GetComboBoxInfo(HWND hwndCombo
, /* [in] handle to combo box */
2338 PCOMBOBOXINFO pcbi
/* [in/out] combo box information */)