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
22 * This code was audited for completeness against the documented features
23 * of Comctl32.dll version 6.0 on Oct. 4, 2004, by Dimitrie O. Paun.
25 * Unless otherwise noted, we believe this code to be complete, as per
26 * the specification mentioned above.
27 * If you discover missing features, or bugs, please note them below.
31 * - ComboBox_[GS]etMinVisible()
32 * - CB_GETCOMBOBOXINFO
33 * - CB_GETMINVISIBLE, CB_SETMINVISIBLE
45 #include "wine/winuser16.h"
46 #include "wine/unicode.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(combo);
56 /* bits in the dwKeyData */
57 #define KEYDATA_ALT 0x2000
58 #define KEYDATA_PREVSTATE 0x4000
61 * Additional combo box definitions
64 #define CB_NOTIFY( lphc, code ) \
65 (SendMessageW((lphc)->owner, WM_COMMAND, \
66 MAKEWPARAM(GetWindowLongPtrW((lphc)->self,GWLP_ID), (code)), (LPARAM)(lphc)->self))
68 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
69 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
70 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
71 #define CB_HWND( lphc ) ((lphc)->self)
72 #define CB_GETTYPE( lphc ) ((lphc)->dwStyle & (CBS_DROPDOWNLIST))
74 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
79 static HBITMAP hComboBmp = 0;
80 static UINT CBitHeight, CBitWidth;
83 * Look and feel dependent "constants"
86 #define COMBO_YBORDERGAP 5
87 #define COMBO_XBORDERSIZE() 2
88 #define COMBO_YBORDERSIZE() 2
89 #define COMBO_EDITBUTTONSPACE() 0
90 #define EDIT_CONTROL_PADDING() 1
92 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
93 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
95 /*********************************************************************
96 * combo class descriptor
98 const struct builtin_class_descr COMBO_builtin_class =
100 "ComboBox", /* name */
101 CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, /* style */
102 ComboWndProcA, /* procA */
103 ComboWndProcW, /* procW */
104 sizeof(HEADCOMBO *), /* extra */
105 IDC_ARROW, /* cursor */
110 /***********************************************************************
113 * Load combo button bitmap.
115 static BOOL COMBO_Init()
119 if( hComboBmp ) return TRUE;
120 if( (hDC = CreateCompatibleDC(0)) )
123 if( (hComboBmp = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO))) )
129 GetObjectW( hComboBmp, sizeof(bm), &bm );
130 CBitHeight = bm.bmHeight;
131 CBitWidth = bm.bmWidth;
133 TRACE("combo bitmap [%i,%i]\n", CBitWidth, CBitHeight );
135 hPrevB = SelectObject( hDC, hComboBmp);
136 SetRect( &r, 0, 0, CBitWidth, CBitHeight );
137 InvertRect( hDC, &r );
138 SelectObject( hDC, hPrevB );
147 /***********************************************************************
150 static LRESULT COMBO_NCCreate(HWND hwnd, LONG style)
154 if (COMBO_Init() && (lphc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEADCOMBO))) )
157 SetWindowLongW( hwnd, 0, (LONG)lphc );
159 /* some braindead apps do try to use scrollbar/border flags */
161 lphc->dwStyle = style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
162 SetWindowLongW( hwnd, GWL_STYLE, style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL) );
165 * We also have to remove the client edge style to make sure
166 * we don't end-up with a non client area.
168 SetWindowLongW( hwnd, GWL_EXSTYLE,
169 GetWindowLongW( hwnd, GWL_EXSTYLE ) & ~WS_EX_CLIENTEDGE );
171 if( !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
172 lphc->dwStyle |= CBS_HASSTRINGS;
173 if( !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) )
174 lphc->wState |= CBF_NOTIFY;
176 TRACE("[%p], style = %08x\n", lphc, lphc->dwStyle );
182 /***********************************************************************
185 static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc )
190 TRACE("[%p]: freeing storage\n", lphc->self);
192 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && lphc->hWndLBox )
193 DestroyWindow( lphc->hWndLBox );
195 SetWindowLongW( lphc->self, 0, 0 );
196 HeapFree( GetProcessHeap(), 0, lphc );
201 /***********************************************************************
202 * CBGetTextAreaHeight
204 * This method will calculate the height of the text area of the
206 * The height of the text area is set in two ways.
207 * It can be set explicitly through a combobox message or through a
208 * WM_MEASUREITEM callback.
209 * If this is not the case, the height is set to 13 dialog units.
210 * This height was determined through experimentation.
212 static INT CBGetTextAreaHeight(
218 if( lphc->editHeight ) /* explicitly set height */
220 iTextItemHeight = lphc->editHeight;
225 HDC hDC = GetDC(hwnd);
230 hPrevFont = SelectObject( hDC, lphc->hFont );
232 GetTextMetricsW(hDC, &tm);
234 baseUnitY = tm.tmHeight;
237 SelectObject( hDC, hPrevFont );
239 ReleaseDC(hwnd, hDC);
241 iTextItemHeight = ((13 * baseUnitY) / 8);
244 * This "formula" calculates the height of the complete control.
245 * To calculate the height of the text area, we have to remove the
248 iTextItemHeight -= 2*COMBO_YBORDERSIZE();
252 * Check the ownerdraw case if we haven't asked the parent the size
255 if ( CB_OWNERDRAWN(lphc) &&
256 (lphc->wState & CBF_MEASUREITEM) )
258 MEASUREITEMSTRUCT measureItem;
260 INT originalItemHeight = iTextItemHeight;
261 UINT id = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
264 * We use the client rect for the width of the item.
266 GetClientRect(hwnd, &clientRect);
268 lphc->wState &= ~CBF_MEASUREITEM;
271 * Send a first one to measure the size of the text area
273 measureItem.CtlType = ODT_COMBOBOX;
274 measureItem.CtlID = id;
275 measureItem.itemID = -1;
276 measureItem.itemWidth = clientRect.right;
277 measureItem.itemHeight = iTextItemHeight - 6; /* ownerdrawn cb is taller */
278 measureItem.itemData = 0;
279 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
280 iTextItemHeight = 6 + measureItem.itemHeight;
283 * Send a second one in the case of a fixed ownerdraw list to calculate the
284 * size of the list items. (we basically do this on behalf of the listbox)
286 if (lphc->dwStyle & CBS_OWNERDRAWFIXED)
288 measureItem.CtlType = ODT_COMBOBOX;
289 measureItem.CtlID = id;
290 measureItem.itemID = 0;
291 measureItem.itemWidth = clientRect.right;
292 measureItem.itemHeight = originalItemHeight;
293 measureItem.itemData = 0;
294 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
295 lphc->fixedOwnerDrawHeight = measureItem.itemHeight;
299 * Keep the size for the next time
301 lphc->editHeight = iTextItemHeight;
304 return iTextItemHeight;
307 /***********************************************************************
310 * The dummy resize is used for listboxes that have a popup to trigger
311 * a re-arranging of the contents of the combobox and the recalculation
312 * of the size of the "real" control window.
314 static void CBForceDummyResize(
320 newComboHeight = CBGetTextAreaHeight(lphc->self,lphc) + 2*COMBO_YBORDERSIZE();
322 GetWindowRect(lphc->self, &windowRect);
325 * We have to be careful, resizing a combobox also has the meaning that the
326 * dropped rect will be resized. In this case, we want to trigger a resize
327 * to recalculate layout but we don't want to change the dropped rectangle
328 * So, we pass the height of text area of control as the height.
329 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
332 SetWindowPos( lphc->self,
335 windowRect.right - windowRect.left,
337 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
340 /***********************************************************************
343 * Set up component coordinates given valid lphc->RectCombo.
345 static void CBCalcPlacement(
353 * Again, start with the client rectangle.
355 GetClientRect(hwnd, lprEdit);
360 InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
363 * Chop off the bottom part to fit with the height of the text area.
365 lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
368 * The button starts the same vertical position as the text area.
370 CopyRect(lprButton, lprEdit);
373 * If the combobox is "simple" there is no button.
375 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
376 lprButton->left = lprButton->right = lprButton->bottom = 0;
380 * Let's assume the combobox button is the same width as the
382 * size the button horizontally and cut-off the text area.
384 lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
385 lprEdit->right = lprButton->left;
389 * In the case of a dropdown, there is an additional spacing between the
390 * text area and the button.
392 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
394 lprEdit->right -= COMBO_EDITBUTTONSPACE();
398 * If we have an edit control, we space it away from the borders slightly.
400 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
402 InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
406 * Adjust the size of the listbox popup.
408 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
411 * Use the client rectangle to initialize the listbox rectangle
413 GetClientRect(hwnd, lprLB);
416 * Then, chop-off the top part.
418 lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
423 * Make sure the dropped width is as large as the combobox itself.
425 if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
427 lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
430 * In the case of a dropdown, the popup listbox is offset to the right.
431 * so, we want to make sure it's flush with the right side of the
434 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
435 lprLB->right -= COMBO_EDITBUTTONSPACE();
438 lprLB->right = lprLB->left + lphc->droppedWidth;
441 TRACE("\ttext\t= (%ld,%ld-%ld,%ld)\n",
442 lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom);
444 TRACE("\tbutton\t= (%ld,%ld-%ld,%ld)\n",
445 lprButton->left, lprButton->top, lprButton->right, lprButton->bottom);
447 TRACE("\tlbox\t= (%ld,%ld-%ld,%ld)\n",
448 lprLB->left, lprLB->top, lprLB->right, lprLB->bottom );
451 /***********************************************************************
452 * CBGetDroppedControlRect
454 static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect)
456 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
457 of the combo box and the lower right corner of the listbox */
459 GetWindowRect(lphc->self, lpRect);
461 lpRect->right = lpRect->left + lphc->droppedRect.right - lphc->droppedRect.left;
462 lpRect->bottom = lpRect->top + lphc->droppedRect.bottom - lphc->droppedRect.top;
466 /***********************************************************************
467 * COMBO_WindowPosChanging
469 static LRESULT COMBO_WindowPosChanging(
472 WINDOWPOS* posChanging)
475 * We need to override the WM_WINDOWPOSCHANGING method to handle all
476 * the non-simple comboboxes. The problem is that those controls are
477 * always the same height. We have to make sure they are not resized
480 if ( ( CB_GETTYPE(lphc) != CBS_SIMPLE ) &&
481 ((posChanging->flags & SWP_NOSIZE) == 0) )
485 newComboHeight = CBGetTextAreaHeight(hwnd,lphc) +
486 2*COMBO_YBORDERSIZE();
489 * Resizing a combobox has another side effect, it resizes the dropped
490 * rectangle as well. However, it does it only if the new height for the
491 * combobox is different from the height it should have. In other words,
492 * if the application resizing the combobox only had the intention to resize
493 * the actual control, for example, to do the layout of a dialog that is
494 * resized, the height of the dropdown is not changed.
496 if (posChanging->cy != newComboHeight)
498 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%ld, oldtop=%ld\n",
499 posChanging->cy, newComboHeight, lphc->droppedRect.bottom,
500 lphc->droppedRect.top);
501 lphc->droppedRect.bottom = lphc->droppedRect.top + posChanging->cy - newComboHeight;
503 posChanging->cy = newComboHeight;
510 /***********************************************************************
513 static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style,
516 static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0};
517 static const WCHAR editName[] = {'E','d','i','t',0};
519 if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE;
520 if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT;
522 lphc->owner = hwndParent;
525 * The item height and dropped width are not set when the control
528 lphc->droppedWidth = lphc->editHeight = 0;
531 * The first time we go through, we want to measure the ownerdraw item
533 lphc->wState |= CBF_MEASUREITEM;
535 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
537 if( lphc->owner || !(style & WS_VISIBLE) )
543 * Initialize the dropped rect to the size of the client area of the
544 * control and then, force all the areas of the combobox to be
547 GetClientRect( hwnd, &lphc->droppedRect );
548 CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
551 * Adjust the position of the popup listbox if it's necessary
553 if ( CB_GETTYPE(lphc) != CBS_SIMPLE )
555 lphc->droppedRect.top = lphc->textRect.bottom + COMBO_YBORDERSIZE();
558 * If it's a dropdown, the listbox is offset
560 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
561 lphc->droppedRect.left += COMBO_EDITBUTTONSPACE();
563 if (lphc->droppedRect.bottom < lphc->droppedRect.top)
564 lphc->droppedRect.bottom = lphc->droppedRect.top;
565 if (lphc->droppedRect.right < lphc->droppedRect.left)
566 lphc->droppedRect.right = lphc->droppedRect.left;
567 MapWindowPoints( hwnd, 0, (LPPOINT)&lphc->droppedRect, 2 );
570 /* create listbox popup */
572 lbeStyle = (LBS_NOTIFY | LBS_COMBOBOX | WS_BORDER | WS_CLIPSIBLINGS | WS_CHILD) |
573 (style & (WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE));
575 if( lphc->dwStyle & CBS_SORT )
576 lbeStyle |= LBS_SORT;
577 if( lphc->dwStyle & CBS_HASSTRINGS )
578 lbeStyle |= LBS_HASSTRINGS;
579 if( lphc->dwStyle & CBS_NOINTEGRALHEIGHT )
580 lbeStyle |= LBS_NOINTEGRALHEIGHT;
581 if( lphc->dwStyle & CBS_DISABLENOSCROLL )
582 lbeStyle |= LBS_DISABLENOSCROLL;
584 if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* child listbox */
586 lbeStyle |= WS_VISIBLE;
589 * In win 95 look n feel, the listbox in the simple combobox has
590 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
592 lbeStyle &= ~WS_BORDER;
593 lbeExStyle |= WS_EX_CLIENTEDGE;
597 lbeExStyle |= (WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
601 lphc->hWndLBox = CreateWindowExW(lbeExStyle, clbName, NULL, lbeStyle,
602 lphc->droppedRect.left,
603 lphc->droppedRect.top,
604 lphc->droppedRect.right - lphc->droppedRect.left,
605 lphc->droppedRect.bottom - lphc->droppedRect.top,
606 hwnd, (HMENU)ID_CB_LISTBOX,
607 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), lphc );
609 lphc->hWndLBox = CreateWindowExA(lbeExStyle, "ComboLBox", NULL, lbeStyle,
610 lphc->droppedRect.left,
611 lphc->droppedRect.top,
612 lphc->droppedRect.right - lphc->droppedRect.left,
613 lphc->droppedRect.bottom - lphc->droppedRect.top,
614 hwnd, (HMENU)ID_CB_LISTBOX,
615 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), lphc );
620 lbeStyle = WS_CHILD | WS_VISIBLE | ES_NOHIDESEL | ES_LEFT | ES_COMBO;
622 if( lphc->wState & CBF_EDIT )
624 if( lphc->dwStyle & CBS_OEMCONVERT )
625 lbeStyle |= ES_OEMCONVERT;
626 if( lphc->dwStyle & CBS_AUTOHSCROLL )
627 lbeStyle |= ES_AUTOHSCROLL;
628 if( lphc->dwStyle & CBS_LOWERCASE )
629 lbeStyle |= ES_LOWERCASE;
630 else if( lphc->dwStyle & CBS_UPPERCASE )
631 lbeStyle |= ES_UPPERCASE;
633 if (!IsWindowEnabled(hwnd)) lbeStyle |= WS_DISABLED;
636 lphc->hWndEdit = CreateWindowExW(0, editName, NULL, lbeStyle,
637 lphc->textRect.left, lphc->textRect.top,
638 lphc->textRect.right - lphc->textRect.left,
639 lphc->textRect.bottom - lphc->textRect.top,
640 hwnd, (HMENU)ID_CB_EDIT,
641 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), NULL );
643 lphc->hWndEdit = CreateWindowExA(0, "Edit", NULL, lbeStyle,
644 lphc->textRect.left, lphc->textRect.top,
645 lphc->textRect.right - lphc->textRect.left,
646 lphc->textRect.bottom - lphc->textRect.top,
647 hwnd, (HMENU)ID_CB_EDIT,
648 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), NULL );
650 if( !lphc->hWndEdit )
656 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
658 /* Now do the trick with parent */
659 SetParent(lphc->hWndLBox, HWND_DESKTOP);
661 * If the combo is a dropdown, we must resize the control
662 * to fit only the text area and button. To do this,
663 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
664 * will take care of setting the height for us.
666 CBForceDummyResize(lphc);
669 TRACE("init done\n");
672 ERR("edit control failure.\n");
673 } else ERR("listbox failure.\n");
674 } else ERR("no owner for visible combo.\n");
676 /* CreateWindow() will send WM_NCDESTROY to cleanup */
681 /***********************************************************************
684 * Paint combo button (normal, pressed, and disabled states).
686 static void CBPaintButton( LPHEADCOMBO lphc, HDC hdc, RECT rectButton)
688 UINT buttonState = DFCS_SCROLLCOMBOBOX;
690 if( lphc->wState & CBF_NOREDRAW )
694 if (lphc->wState & CBF_BUTTONDOWN)
695 buttonState |= DFCS_PUSHED;
697 if (CB_DISABLED(lphc))
698 buttonState |= DFCS_INACTIVE;
700 DrawFrameControl(hdc, &rectButton, DFC_SCROLL, buttonState);
703 /***********************************************************************
706 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
708 static void CBPaintText(
716 if( lphc->wState & CBF_NOREDRAW ) return;
720 /* follow Windows combobox that sends a bunch of text
721 * inquiries to its listbox while processing WM_PAINT. */
723 if( (id = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0) ) != LB_ERR )
725 size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0);
727 FIXME("LB_ERR probably not handled yet\n");
728 if( (pText = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))) )
730 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
731 size=SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText);
732 pText[size] = '\0'; /* just in case */
736 if( !CB_OWNERDRAWN(lphc) )
739 if( lphc->wState & CBF_EDIT )
741 static const WCHAR empty_stringW[] = { 0 };
742 if( CB_HASSTRINGS(lphc) ) SetWindowTextW( lphc->hWndEdit, pText ? pText : empty_stringW );
743 if( lphc->wState & CBF_FOCUSED )
744 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
746 else /* paint text field ourselves */
748 UINT itemState = ODS_COMBOBOXEDIT;
749 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hdc, lphc->hFont) : 0;
752 * Give ourselves some space.
754 InflateRect( &rectEdit, -1, -1 );
756 if( CB_OWNERDRAWN(lphc) )
760 UINT ctlid = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
762 /* setup state for DRAWITEM message. Owner will highlight */
763 if ( (lphc->wState & CBF_FOCUSED) &&
764 !(lphc->wState & CBF_DROPPED) )
765 itemState |= ODS_SELECTED | ODS_FOCUS;
768 * Save the current clip region.
769 * To retrieve the clip region, we need to create one "dummy"
772 clipRegion = CreateRectRgnIndirect(&rectEdit);
774 if (GetClipRgn(hdc, clipRegion)!=1)
776 DeleteObject(clipRegion);
780 if (!IsWindowEnabled(lphc->self) & WS_DISABLED) itemState |= ODS_DISABLED;
782 dis.CtlType = ODT_COMBOBOX;
784 dis.hwndItem = lphc->self;
785 dis.itemAction = ODA_DRAWENTIRE;
787 dis.itemState = itemState;
789 dis.rcItem = rectEdit;
790 dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA,
794 * Clip the DC and have the parent draw the item.
796 IntersectClipRect(hdc,
797 rectEdit.left, rectEdit.top,
798 rectEdit.right, rectEdit.bottom);
800 SendMessageW(lphc->owner, WM_DRAWITEM, ctlid, (LPARAM)&dis );
803 * Reset the clipping region.
805 SelectClipRgn(hdc, clipRegion);
809 static const WCHAR empty_stringW[] = { 0 };
811 if ( (lphc->wState & CBF_FOCUSED) &&
812 !(lphc->wState & CBF_DROPPED) ) {
815 FillRect( hdc, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) );
816 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
817 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
823 ETO_OPAQUE | ETO_CLIPPED,
825 pText ? pText : empty_stringW , size, NULL );
827 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED))
828 DrawFocusRect( hdc, &rectEdit );
832 SelectObject(hdc, hPrevFont );
834 HeapFree( GetProcessHeap(), 0, pText );
837 /***********************************************************************
840 static void CBPaintBorder(
847 if (CB_GETTYPE(lphc) != CBS_SIMPLE)
849 GetClientRect(hwnd, &clientRect);
853 CopyRect(&clientRect, &lphc->textRect);
855 InflateRect(&clientRect, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
856 InflateRect(&clientRect, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
859 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_RECT);
862 /***********************************************************************
863 * COMBO_PrepareColors
865 * This method will sent the appropriate WM_CTLCOLOR message to
866 * prepare and setup the colors for the combo's DC.
868 * It also returns the brush to use for the background.
870 static HBRUSH COMBO_PrepareColors(
877 * Get the background brush for this control.
879 if (CB_DISABLED(lphc))
881 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORSTATIC,
882 (WPARAM)hDC, (LPARAM)lphc->self );
885 * We have to change the text color since WM_CTLCOLORSTATIC will
886 * set it to the "enabled" color. This is the same behavior as the
889 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
893 if (lphc->wState & CBF_EDIT)
895 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLOREDIT,
896 (WPARAM)hDC, (LPARAM)lphc->self );
900 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORLISTBOX,
901 (WPARAM)hDC, (LPARAM)lphc->self );
909 hBkgBrush = GetSysColorBrush(COLOR_WINDOW);
914 /***********************************************************************
915 * COMBO_EraseBackground
917 static LRESULT COMBO_EraseBackground(
925 if(lphc->wState & CBF_EDIT)
928 hDC = (hParamDC) ? hParamDC
931 * Retrieve the background brush
933 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
935 FillRect(hDC, &lphc->textRect, hBkgBrush);
938 ReleaseDC(hwnd, hDC);
943 /***********************************************************************
946 static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC)
951 hDC = (hParamDC) ? hParamDC
952 : BeginPaint( lphc->self, &ps);
954 TRACE("hdc=%p\n", hDC);
956 if( hDC && !(lphc->wState & CBF_NOREDRAW) )
958 HBRUSH hPrevBrush, hBkgBrush;
961 * Retrieve the background brush and select it in the
964 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
966 hPrevBrush = SelectObject( hDC, hBkgBrush );
969 * In non 3.1 look, there is a sunken border on the combobox
971 CBPaintBorder(lphc->self, lphc, hDC);
973 if( !IsRectEmpty(&lphc->buttonRect) )
975 CBPaintButton(lphc, hDC, lphc->buttonRect);
978 /* paint the edit control padding area */
979 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
981 RECT rPadEdit = lphc->textRect;
983 InflateRect(&rPadEdit, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
985 FrameRect( hDC, &rPadEdit, GetSysColorBrush(COLOR_WINDOW) );
988 if( !(lphc->wState & CBF_EDIT) )
989 CBPaintText( lphc, hDC, lphc->textRect);
992 SelectObject( hDC, hPrevBrush );
996 EndPaint(lphc->self, &ps);
1001 /***********************************************************************
1004 * Select listbox entry according to the contents of the edit control.
1006 static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
1009 LPWSTR pText = NULL;
1012 length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 );
1015 pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1017 TRACE("\t edit text length %i\n", length );
1021 if( length ) GetWindowTextW( lphc->hWndEdit, pText, length + 1);
1022 else pText[0] = '\0';
1023 idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING,
1024 (WPARAM)(-1), (LPARAM)pText );
1025 HeapFree( GetProcessHeap(), 0, pText );
1028 SendMessageW(lphc->hWndLBox, LB_SETCURSEL, (WPARAM)(bSelect ? idx : -1), 0);
1030 /* probably superfluous but Windows sends this too */
1031 SendMessageW(lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1032 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1037 /***********************************************************************
1040 * Copy a listbox entry to the edit control.
1042 static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
1045 LPWSTR pText = NULL;
1046 static const WCHAR empty_stringW[] = { 0 };
1048 TRACE("\t %i\n", index );
1050 if( index >= 0 ) /* got an entry */
1052 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0);
1053 if( length != LB_ERR)
1055 if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) )
1057 SendMessageW(lphc->hWndLBox, LB_GETTEXT,
1058 (WPARAM)index, (LPARAM)pText );
1063 lphc->wState |= (CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1064 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, pText ? (LPARAM)pText : (LPARAM)empty_stringW);
1065 lphc->wState &= ~(CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1067 if( lphc->wState & CBF_FOCUSED )
1068 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1070 HeapFree( GetProcessHeap(), 0, pText );
1073 /***********************************************************************
1076 * Show listbox popup.
1078 static void CBDropDown( LPHEADCOMBO lphc )
1084 TRACE("[%p]: drop down\n", lphc->self);
1086 CB_NOTIFY( lphc, CBN_DROPDOWN );
1090 lphc->wState |= CBF_DROPPED;
1091 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1093 lphc->droppedIndex = CBUpdateLBox( lphc, TRUE );
1095 /* Update edit only if item is in the list */
1096 if( !(lphc->wState & CBF_CAPTURE) && lphc->droppedIndex >= 0)
1097 CBUpdateEdit( lphc, lphc->droppedIndex );
1101 lphc->droppedIndex = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1103 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX,
1104 (WPARAM)(lphc->droppedIndex == LB_ERR ? 0 : lphc->droppedIndex), 0 );
1105 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1108 /* now set popup position */
1109 GetWindowRect( lphc->self, &rect );
1112 * If it's a dropdown, the listbox is offset
1114 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1115 rect.left += COMBO_EDITBUTTONSPACE();
1117 /* if the dropped height is greater than the total height of the dropped
1118 items list, then force the drop down list height to be the total height
1119 of the items in the dropped list */
1121 /* And Remove any extra space (Best Fit) */
1122 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
1123 /* if listbox length has been set directly by its handle */
1124 GetWindowRect(lphc->hWndLBox, &r);
1125 if (nDroppedHeight < r.bottom - r.top)
1126 nDroppedHeight = r.bottom - r.top;
1127 nItems = (int)SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
1134 nIHeight = (int)SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, 0, 0);
1136 nHeight = nIHeight*nItems;
1138 if (nHeight < nDroppedHeight - COMBO_YBORDERSIZE())
1139 nDroppedHeight = nHeight + COMBO_YBORDERSIZE();
1141 if (nDroppedHeight < nIHeight)
1144 nDroppedHeight = (nItems+1)*nIHeight;
1146 nDroppedHeight = 6*nIHeight;
1150 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1151 if( (rect.bottom + nDroppedHeight) >= GetSystemMetrics( SM_CYSCREEN ) )
1152 rect.bottom = rect.top - nDroppedHeight;
1154 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
1155 lphc->droppedRect.right - lphc->droppedRect.left,
1157 SWP_NOACTIVATE | SWP_SHOWWINDOW);
1160 if( !(lphc->wState & CBF_NOREDRAW) )
1161 RedrawWindow( lphc->self, NULL, 0, RDW_INVALIDATE |
1162 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1164 EnableWindow( lphc->hWndLBox, TRUE );
1165 if (GetCapture() != lphc->self)
1166 SetCapture(lphc->hWndLBox);
1169 /***********************************************************************
1172 * Hide listbox popup.
1174 static void CBRollUp( LPHEADCOMBO lphc, BOOL ok, BOOL bButton )
1176 HWND hWnd = lphc->self;
1178 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1179 lphc->self, (INT)ok, (INT)(lphc->wState & CBF_DROPPED));
1181 CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL );
1183 if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE )
1186 if( lphc->wState & CBF_DROPPED )
1190 lphc->wState &= ~CBF_DROPPED;
1191 ShowWindow( lphc->hWndLBox, SW_HIDE );
1193 if(GetCapture() == lphc->hWndLBox)
1198 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1200 rect = lphc->buttonRect;
1211 rect = lphc->textRect;
1216 if( bButton && !(lphc->wState & CBF_NOREDRAW) )
1217 RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE |
1218 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1219 CB_NOTIFY( lphc, CBN_CLOSEUP );
1224 /***********************************************************************
1227 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1229 BOOL COMBO_FlipListbox( LPHEADCOMBO lphc, BOOL ok, BOOL bRedrawButton )
1231 if( lphc->wState & CBF_DROPPED )
1233 CBRollUp( lphc, ok, bRedrawButton );
1241 /***********************************************************************
1244 static void CBRepaintButton( LPHEADCOMBO lphc )
1246 InvalidateRect(lphc->self, &lphc->buttonRect, TRUE);
1247 UpdateWindow(lphc->self);
1250 /***********************************************************************
1253 static void COMBO_SetFocus( LPHEADCOMBO lphc )
1255 if( !(lphc->wState & CBF_FOCUSED) )
1257 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1258 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1260 /* This is wrong. Message sequences seem to indicate that this
1261 is set *after* the notify. */
1262 /* lphc->wState |= CBF_FOCUSED; */
1264 if( !(lphc->wState & CBF_EDIT) )
1265 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1267 CB_NOTIFY( lphc, CBN_SETFOCUS );
1268 lphc->wState |= CBF_FOCUSED;
1272 /***********************************************************************
1275 static void COMBO_KillFocus( LPHEADCOMBO lphc )
1277 HWND hWnd = lphc->self;
1279 if( lphc->wState & CBF_FOCUSED )
1281 CBRollUp( lphc, FALSE, TRUE );
1282 if( IsWindow( hWnd ) )
1284 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1285 SendMessageW(lphc->hWndLBox, LB_CARETOFF, 0, 0);
1287 lphc->wState &= ~CBF_FOCUSED;
1290 if( !(lphc->wState & CBF_EDIT) )
1291 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1293 CB_NOTIFY( lphc, CBN_KILLFOCUS );
1298 /***********************************************************************
1301 static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd )
1303 if ( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd )
1305 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1307 switch( HIWORD(wParam) >> 8 )
1309 case (EN_SETFOCUS >> 8):
1311 TRACE("[%p]: edit [%p] got focus\n", lphc->self, lphc->hWndEdit );
1313 COMBO_SetFocus( lphc );
1316 case (EN_KILLFOCUS >> 8):
1318 TRACE("[%p]: edit [%p] lost focus\n", lphc->self, lphc->hWndEdit );
1320 /* NOTE: it seems that Windows' edit control sends an
1321 * undocumented message WM_USER + 0x1B instead of this
1322 * notification (only when it happens to be a part of
1323 * the combo). ?? - AK.
1326 COMBO_KillFocus( lphc );
1330 case (EN_CHANGE >> 8):
1332 * In some circumstances (when the selection of the combobox
1333 * is changed for example) we don't want the EN_CHANGE notification
1334 * to be forwarded to the parent of the combobox. This code
1335 * checks a flag that is set in these occasions and ignores the
1338 if (lphc->wState & CBF_NOLBSELECT)
1340 lphc->wState &= ~CBF_NOLBSELECT;
1344 CBUpdateLBox( lphc, lphc->wState & CBF_DROPPED );
1347 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1348 CB_NOTIFY( lphc, CBN_EDITCHANGE );
1351 case (EN_UPDATE >> 8):
1352 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1353 CB_NOTIFY( lphc, CBN_EDITUPDATE );
1356 case (EN_ERRSPACE >> 8):
1357 CB_NOTIFY( lphc, CBN_ERRSPACE );
1360 else if( lphc->hWndLBox == hWnd )
1362 switch( (short)HIWORD(wParam) )
1365 CB_NOTIFY( lphc, CBN_ERRSPACE );
1369 CB_NOTIFY( lphc, CBN_DBLCLK );
1375 TRACE("[%p]: lbox selection change [%x]\n", lphc->self, lphc->wState );
1377 if( HIWORD(wParam) == LBN_SELCHANGE)
1379 if( lphc->wState & CBF_EDIT )
1381 INT index = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1382 lphc->wState |= CBF_NOLBSELECT;
1383 CBUpdateEdit( lphc, index );
1384 /* select text in edit, as Windows does */
1385 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1388 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1391 /* do not roll up if selection is being tracked
1392 * by arrowkeys in the dropdown listbox */
1393 if( ((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 );
1405 /* nothing to do here since ComboLBox always resets the focus to its
1406 * combo/edit counterpart */
1413 /***********************************************************************
1416 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1418 static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
1420 HWND hWnd = lphc->self;
1421 UINT id = (UINT)GetWindowLongPtrW( hWnd, GWLP_ID );
1423 TRACE("[%p]: ownerdraw op %04x\n", lphc->self, msg );
1429 DELETEITEMSTRUCT *lpIS = (DELETEITEMSTRUCT *)lParam;
1430 lpIS->CtlType = ODT_COMBOBOX;
1432 lpIS->hwndItem = hWnd;
1437 DRAWITEMSTRUCT *lpIS = (DRAWITEMSTRUCT *)lParam;
1438 lpIS->CtlType = ODT_COMBOBOX;
1440 lpIS->hwndItem = hWnd;
1443 case WM_COMPAREITEM:
1445 COMPAREITEMSTRUCT *lpIS = (COMPAREITEMSTRUCT *)lParam;
1446 lpIS->CtlType = ODT_COMBOBOX;
1448 lpIS->hwndItem = hWnd;
1451 case WM_MEASUREITEM:
1453 MEASUREITEMSTRUCT *lpIS = (MEASUREITEMSTRUCT *)lParam;
1454 lpIS->CtlType = ODT_COMBOBOX;
1459 return SendMessageW(lphc->owner, msg, id, lParam);
1463 /***********************************************************************
1466 static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf )
1470 if( lphc->wState & CBF_EDIT )
1471 return SendMessageW( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1473 /* get it from the listbox */
1475 if (!count || !buf) return 0;
1476 if( lphc->hWndLBox )
1478 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1479 if (idx == LB_ERR) goto error;
1480 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1481 if (length == LB_ERR) goto error;
1483 /* 'length' is without the terminating character */
1484 if (length >= count)
1486 LPWSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1487 if (!lpBuffer) goto error;
1488 length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1490 /* truncate if buffer is too short */
1491 if (length != LB_ERR)
1493 lstrcpynW( buf, lpBuffer, count );
1496 HeapFree( GetProcessHeap(), 0, lpBuffer );
1498 else length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1500 if (length == LB_ERR) return 0;
1504 error: /* error - truncate string, return zero */
1510 /***********************************************************************
1513 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1514 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1516 static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf )
1520 if( lphc->wState & CBF_EDIT )
1521 return SendMessageA( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1523 /* get it from the listbox */
1525 if (!count || !buf) return 0;
1526 if( lphc->hWndLBox )
1528 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1529 if (idx == LB_ERR) goto error;
1530 length = SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1531 if (length == LB_ERR) goto error;
1533 /* 'length' is without the terminating character */
1534 if (length >= count)
1536 LPSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) );
1537 if (!lpBuffer) goto error;
1538 length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1540 /* truncate if buffer is too short */
1541 if (length != LB_ERR)
1543 lstrcpynA( buf, lpBuffer, count );
1546 HeapFree( GetProcessHeap(), 0, lpBuffer );
1548 else length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1550 if (length == LB_ERR) return 0;
1554 error: /* error - truncate string, return zero */
1560 /***********************************************************************
1563 * This function sets window positions according to the updated
1564 * component placement struct.
1566 static void CBResetPos(
1572 BOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE);
1574 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1575 * sizing messages */
1577 if( lphc->wState & CBF_EDIT )
1578 SetWindowPos( lphc->hWndEdit, 0,
1579 rectEdit->left, rectEdit->top,
1580 rectEdit->right - rectEdit->left,
1581 rectEdit->bottom - rectEdit->top,
1582 SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) );
1584 SetWindowPos( lphc->hWndLBox, 0,
1585 rectLB->left, rectLB->top,
1586 rectLB->right - rectLB->left,
1587 rectLB->bottom - rectLB->top,
1588 SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) );
1592 if( lphc->wState & CBF_DROPPED )
1594 lphc->wState &= ~CBF_DROPPED;
1595 ShowWindow( lphc->hWndLBox, SW_HIDE );
1598 if( bRedraw && !(lphc->wState & CBF_NOREDRAW) )
1599 RedrawWindow( lphc->self, NULL, 0,
1600 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
1605 /***********************************************************************
1608 static void COMBO_Size( LPHEADCOMBO lphc )
1610 CBCalcPlacement(lphc->self,
1614 &lphc->droppedRect);
1616 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1620 /***********************************************************************
1623 static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
1628 lphc->hFont = hFont;
1631 * Propagate to owned windows.
1633 if( lphc->wState & CBF_EDIT )
1634 SendMessageW(lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw);
1635 SendMessageW(lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw);
1638 * Redo the layout of the control.
1640 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1642 CBCalcPlacement(lphc->self,
1646 &lphc->droppedRect);
1648 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1652 CBForceDummyResize(lphc);
1657 /***********************************************************************
1658 * COMBO_SetItemHeight
1660 static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
1662 LRESULT lRet = CB_ERR;
1664 if( index == -1 ) /* set text field height */
1666 if( height < 32768 )
1668 lphc->editHeight = height;
1671 * Redo the layout of the control.
1673 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1675 CBCalcPlacement(lphc->self,
1679 &lphc->droppedRect);
1681 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1685 CBForceDummyResize(lphc);
1691 else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */
1692 lRet = SendMessageW(lphc->hWndLBox, LB_SETITEMHEIGHT,
1693 (WPARAM)index, (LPARAM)height );
1697 /***********************************************************************
1698 * COMBO_SelectString
1700 static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPARAM pText, BOOL unicode )
1702 INT index = unicode ? SendMessageW(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText) :
1703 SendMessageA(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText);
1706 if( lphc->wState & CBF_EDIT )
1707 CBUpdateEdit( lphc, index );
1710 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1713 return (LRESULT)index;
1716 /***********************************************************************
1719 static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam )
1723 HWND hWnd = lphc->self;
1725 pt.x = LOWORD(lParam);
1726 pt.y = HIWORD(lParam);
1727 bButton = PtInRect(&lphc->buttonRect, pt);
1729 if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) ||
1730 (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) )
1732 lphc->wState |= CBF_BUTTONDOWN;
1733 if( lphc->wState & CBF_DROPPED )
1735 /* got a click to cancel selection */
1737 lphc->wState &= ~CBF_BUTTONDOWN;
1738 CBRollUp( lphc, TRUE, FALSE );
1739 if( !IsWindow( hWnd ) ) return;
1741 if( lphc->wState & CBF_CAPTURE )
1743 lphc->wState &= ~CBF_CAPTURE;
1749 /* drop down the listbox and start tracking */
1751 lphc->wState |= CBF_CAPTURE;
1755 if( bButton ) CBRepaintButton( lphc );
1759 /***********************************************************************
1762 * Release capture and stop tracking if needed.
1764 static void COMBO_LButtonUp( LPHEADCOMBO lphc )
1766 if( lphc->wState & CBF_CAPTURE )
1768 lphc->wState &= ~CBF_CAPTURE;
1769 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1771 INT index = CBUpdateLBox( lphc, TRUE );
1772 /* Update edit only if item is in the list */
1775 lphc->wState |= CBF_NOLBSELECT;
1776 CBUpdateEdit( lphc, index );
1777 lphc->wState &= ~CBF_NOLBSELECT;
1781 SetCapture(lphc->hWndLBox);
1784 if( lphc->wState & CBF_BUTTONDOWN )
1786 lphc->wState &= ~CBF_BUTTONDOWN;
1787 CBRepaintButton( lphc );
1791 /***********************************************************************
1794 * Two things to do - track combo button and release capture when
1795 * pointer goes into the listbox.
1797 static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam )
1802 pt.x = LOWORD(lParam);
1803 pt.y = HIWORD(lParam);
1805 if( lphc->wState & CBF_BUTTONDOWN )
1809 bButton = PtInRect(&lphc->buttonRect, pt);
1813 lphc->wState &= ~CBF_BUTTONDOWN;
1814 CBRepaintButton( lphc );
1818 GetClientRect( lphc->hWndLBox, &lbRect );
1819 MapWindowPoints( lphc->self, lphc->hWndLBox, &pt, 1 );
1820 if( PtInRect(&lbRect, pt) )
1822 lphc->wState &= ~CBF_CAPTURE;
1824 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc, TRUE );
1826 /* hand over pointer tracking */
1827 SendMessageW(lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam);
1832 /***********************************************************************
1833 * ComboWndProc_common
1835 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxes.asp
1837 static LRESULT ComboWndProc_common( HWND hwnd, UINT message,
1838 WPARAM wParam, LPARAM lParam, BOOL unicode )
1840 LPHEADCOMBO lphc = (LPHEADCOMBO)GetWindowLongW( hwnd, 0 );
1842 TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1843 hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1845 if( lphc || message == WM_NCCREATE )
1849 /* System messages */
1853 LONG style = unicode ? ((LPCREATESTRUCTW)lParam)->style :
1854 ((LPCREATESTRUCTA)lParam)->style;
1855 return COMBO_NCCreate(hwnd, style);
1858 COMBO_NCDestroy(lphc);
1859 break;/* -> DefWindowProc */
1867 hwndParent = ((LPCREATESTRUCTW)lParam)->hwndParent;
1868 style = ((LPCREATESTRUCTW)lParam)->style;
1872 hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent;
1873 style = ((LPCREATESTRUCTA)lParam)->style;
1875 return COMBO_Create(hwnd, lphc, hwndParent, style, unicode);
1878 case WM_PRINTCLIENT:
1879 if (lParam & PRF_ERASEBKGND)
1880 COMBO_EraseBackground(hwnd, lphc, (HDC)wParam);
1884 /* wParam may contain a valid HDC! */
1885 return COMBO_Paint(lphc, (HDC)wParam);
1887 return COMBO_EraseBackground(hwnd, lphc, (HDC)wParam);
1890 LRESULT result = DLGC_WANTARROWS | DLGC_WANTCHARS;
1891 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1893 int vk = (int)((LPMSG)lParam)->wParam;
1895 if ((vk == VK_RETURN || vk == VK_ESCAPE) && (lphc->wState & CBF_DROPPED))
1896 result |= DLGC_WANTMESSAGE;
1900 case WM_WINDOWPOSCHANGING:
1901 return COMBO_WindowPosChanging(hwnd, lphc, (LPWINDOWPOS)lParam);
1902 case WM_WINDOWPOSCHANGED:
1903 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1904 * In that case, the Combobox itself will not be resized, so we won't
1905 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1910 if( lphc->hWndLBox &&
1911 !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc );
1914 COMBO_Font( lphc, (HFONT)wParam, (BOOL)lParam );
1917 return (LRESULT)lphc->hFont;
1919 if( lphc->wState & CBF_EDIT )
1920 SetFocus( lphc->hWndEdit );
1922 COMBO_SetFocus( lphc );
1926 HWND hwndFocus = WIN_GetFullHandle( (HWND)wParam );
1928 (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox ))
1929 COMBO_KillFocus( lphc );
1933 return COMBO_Command( lphc, wParam, WIN_GetFullHandle( (HWND)lParam ) );
1935 return unicode ? COMBO_GetTextW( lphc, wParam, (LPWSTR)lParam )
1936 : COMBO_GetTextA( lphc, wParam, (LPSTR)lParam );
1938 case WM_GETTEXTLENGTH:
1940 if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT))
1942 int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1943 if (j == -1) return 0;
1944 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0) :
1945 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, j, 0);
1947 else if( lphc->wState & CBF_EDIT )
1950 lphc->wState |= CBF_NOEDITNOTIFY;
1951 ret = unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1952 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1953 lphc->wState &= ~CBF_NOEDITNOTIFY;
1960 if( lphc->wState & CBF_EDIT )
1962 return unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1963 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1969 case WM_COMPAREITEM:
1970 case WM_MEASUREITEM:
1971 return COMBO_ItemOp(lphc, message, lParam);
1973 if( lphc->wState & CBF_EDIT )
1974 EnableWindow( lphc->hWndEdit, (BOOL)wParam );
1975 EnableWindow( lphc->hWndLBox, (BOOL)wParam );
1977 /* Force the control to repaint when the enabled state changes. */
1978 InvalidateRect(lphc->self, NULL, TRUE);
1982 lphc->wState &= ~CBF_NOREDRAW;
1984 lphc->wState |= CBF_NOREDRAW;
1986 if( lphc->wState & CBF_EDIT )
1987 SendMessageW(lphc->hWndEdit, message, wParam, lParam);
1988 SendMessageW(lphc->hWndLBox, message, wParam, lParam);
1991 if( KEYDATA_ALT & HIWORD(lParam) )
1992 if( wParam == VK_UP || wParam == VK_DOWN )
1993 COMBO_FlipListbox( lphc, FALSE, FALSE );
2002 if ((wParam == VK_RETURN || wParam == VK_ESCAPE) &&
2003 (lphc->wState & CBF_DROPPED))
2005 CBRollUp( lphc, wParam == VK_RETURN, FALSE );
2008 else if ((wParam == VK_F4) && !(lphc->wState & CBF_EUI))
2010 COMBO_FlipListbox( lphc, FALSE, FALSE );
2014 if( lphc->wState & CBF_EDIT )
2015 hwndTarget = lphc->hWndEdit;
2017 hwndTarget = lphc->hWndLBox;
2019 return unicode ? SendMessageW(hwndTarget, message, wParam, lParam) :
2020 SendMessageA(hwndTarget, message, wParam, lParam);
2022 case WM_LBUTTONDOWN:
2023 if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self );
2024 if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
2027 COMBO_LButtonUp( lphc );
2030 if( lphc->wState & CBF_CAPTURE )
2031 COMBO_MouseMove( lphc, wParam, lParam );
2035 if (wParam & (MK_SHIFT | MK_CONTROL))
2036 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2037 DefWindowProcA(hwnd, message, wParam, lParam);
2039 if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_UP, 0);
2040 if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_DOWN, 0);
2043 /* Combo messages */
2045 case CB_ADDSTRING16:
2046 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2051 if( lphc->dwStyle & CBS_LOWERCASE )
2052 strlwrW((LPWSTR)lParam);
2053 else if( lphc->dwStyle & CBS_UPPERCASE )
2054 struprW((LPWSTR)lParam);
2055 return SendMessageW(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2059 if( lphc->dwStyle & CBS_LOWERCASE )
2060 _strlwr((LPSTR)lParam);
2061 else if( lphc->dwStyle & CBS_UPPERCASE )
2062 _strupr((LPSTR)lParam);
2063 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);
2069 case CB_INSERTSTRING:
2072 if( lphc->dwStyle & CBS_LOWERCASE )
2073 strlwrW((LPWSTR)lParam);
2074 else if( lphc->dwStyle & CBS_UPPERCASE )
2075 struprW((LPWSTR)lParam);
2076 return SendMessageW(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2080 if( lphc->dwStyle & CBS_LOWERCASE )
2081 _strlwr((LPSTR)lParam);
2082 else if( lphc->dwStyle & CBS_UPPERCASE )
2083 _strupr((LPSTR)lParam);
2084 return SendMessageA(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2086 case CB_DELETESTRING16:
2087 case CB_DELETESTRING:
2088 return unicode ? SendMessageW(lphc->hWndLBox, LB_DELETESTRING, wParam, 0) :
2089 SendMessageA(lphc->hWndLBox, LB_DELETESTRING, wParam, 0);
2090 case CB_SELECTSTRING16:
2091 wParam = (INT)(INT16)wParam;
2092 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2094 case CB_SELECTSTRING:
2095 return COMBO_SelectString(lphc, (INT)wParam, lParam, unicode);
2096 case CB_FINDSTRING16:
2097 wParam = (INT)(INT16)wParam;
2098 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2101 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam) :
2102 SendMessageA(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam);
2103 case CB_FINDSTRINGEXACT16:
2104 wParam = (INT)(INT16)wParam;
2105 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2107 case CB_FINDSTRINGEXACT:
2108 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam) :
2109 SendMessageA(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam);
2110 case CB_SETITEMHEIGHT16:
2111 wParam = (INT)(INT16)wParam; /* signed integer */
2113 case CB_SETITEMHEIGHT:
2114 return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam);
2115 case CB_GETITEMHEIGHT16:
2116 wParam = (INT)(INT16)wParam;
2118 case CB_GETITEMHEIGHT:
2119 if( (INT)wParam >= 0 ) /* listbox item */
2120 return SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0);
2121 return CBGetTextAreaHeight(hwnd, lphc);
2122 case CB_RESETCONTENT16:
2123 case CB_RESETCONTENT:
2124 SendMessageW(lphc->hWndLBox, LB_RESETCONTENT, 0, 0);
2125 if( (lphc->wState & CBF_EDIT) && CB_HASSTRINGS(lphc) )
2127 static const WCHAR empty_stringW[] = { 0 };
2128 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);
2131 InvalidateRect(lphc->self, NULL, TRUE);
2133 case CB_INITSTORAGE:
2134 return SendMessageW(lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam);
2135 case CB_GETHORIZONTALEXTENT:
2136 return SendMessageW(lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0);
2137 case CB_SETHORIZONTALEXTENT:
2138 return SendMessageW(lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0);
2139 case CB_GETTOPINDEX:
2140 return SendMessageW(lphc->hWndLBox, LB_GETTOPINDEX, 0, 0);
2142 return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0);
2144 return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0);
2145 case CB_GETDROPPEDWIDTH:
2146 if( lphc->droppedWidth )
2147 return lphc->droppedWidth;
2148 return lphc->droppedRect.right - lphc->droppedRect.left;
2149 case CB_SETDROPPEDWIDTH:
2150 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) &&
2151 (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam;
2153 case CB_GETDROPPEDCONTROLRECT16:
2154 lParam = (LPARAM)MapSL(lParam);
2158 RECT16 *r16 = (RECT16 *)lParam;
2159 CBGetDroppedControlRect( lphc, &r );
2162 r16->right = r.right;
2163 r16->bottom = r.bottom;
2166 case CB_GETDROPPEDCONTROLRECT:
2167 if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam );
2169 case CB_GETDROPPEDSTATE16:
2170 case CB_GETDROPPEDSTATE:
2171 return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE;
2173 return SendMessageA(lphc->hWndLBox, LB_DIR16, wParam, lParam);
2175 return unicode ? SendMessageW(lphc->hWndLBox, LB_DIR, wParam, lParam) :
2176 SendMessageA(lphc->hWndLBox, LB_DIR, wParam, lParam);
2178 case CB_SHOWDROPDOWN16:
2179 case CB_SHOWDROPDOWN:
2180 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
2184 if( !(lphc->wState & CBF_DROPPED) )
2188 if( lphc->wState & CBF_DROPPED )
2189 CBRollUp( lphc, FALSE, TRUE );
2194 return SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
2195 case CB_GETCURSEL16:
2197 return SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
2198 case CB_SETCURSEL16:
2199 wParam = (INT)(INT16)wParam;
2202 lParam = SendMessageW(lphc->hWndLBox, LB_SETCURSEL, wParam, 0);
2204 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, wParam, 0);
2206 /* no LBN_SELCHANGE in this case, update manually */
2207 if( lphc->wState & CBF_EDIT )
2208 CBUpdateEdit( lphc, (INT)wParam );
2210 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
2211 lphc->wState &= ~CBF_SELCHANGE;
2213 case CB_GETLBTEXT16:
2214 wParam = (INT)(INT16)wParam;
2215 lParam = (LPARAM)MapSL(lParam);
2218 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXT, wParam, lParam) :
2219 SendMessageA(lphc->hWndLBox, LB_GETTEXT, wParam, lParam);
2220 case CB_GETLBTEXTLEN16:
2221 wParam = (INT)(INT16)wParam;
2223 case CB_GETLBTEXTLEN:
2224 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0) :
2225 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0);
2226 case CB_GETITEMDATA16:
2227 wParam = (INT)(INT16)wParam;
2229 case CB_GETITEMDATA:
2230 return SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0);
2231 case CB_SETITEMDATA16:
2232 wParam = (INT)(INT16)wParam;
2234 case CB_SETITEMDATA:
2235 return SendMessageW(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam);
2236 case CB_GETEDITSEL16:
2237 wParam = lParam = 0; /* just in case */
2240 /* Edit checks passed parameters itself */
2241 if( lphc->wState & CBF_EDIT )
2242 return SendMessageW(lphc->hWndEdit, EM_GETSEL, wParam, lParam);
2244 case CB_SETEDITSEL16:
2246 if( lphc->wState & CBF_EDIT )
2247 return SendMessageW(lphc->hWndEdit, EM_SETSEL,
2248 (INT)(INT16)LOWORD(lParam), (INT)(INT16)HIWORD(lParam) );
2250 case CB_SETEXTENDEDUI16:
2251 case CB_SETEXTENDEDUI:
2252 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
2255 lphc->wState |= CBF_EUI;
2256 else lphc->wState &= ~CBF_EUI;
2258 case CB_GETEXTENDEDUI16:
2259 case CB_GETEXTENDEDUI:
2260 return (lphc->wState & CBF_EUI) ? TRUE : FALSE;
2263 if (message >= WM_USER)
2264 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2265 message - WM_USER, wParam, lParam );
2268 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2269 DefWindowProcA(hwnd, message, wParam, lParam);
2272 /***********************************************************************
2275 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2278 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2280 if (!IsWindow(hwnd)) return 0;
2281 return ComboWndProc_common( hwnd, message, wParam, lParam, FALSE );
2284 /***********************************************************************
2287 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2289 if (!IsWindow(hwnd)) return 0;
2290 return ComboWndProc_common( hwnd, message, wParam, lParam, TRUE );
2293 /*************************************************************************
2294 * GetComboBoxInfo (USER32.@)
2296 BOOL WINAPI GetComboBoxInfo(HWND hwndCombo, /* [in] handle to combo box */
2297 PCOMBOBOXINFO pcbi /* [in/out] combo box information */)