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.
30 #include "wine/winuser16.h"
31 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(combo);
42 /* bits in the dwKeyData */
43 #define KEYDATA_ALT 0x2000
44 #define KEYDATA_PREVSTATE 0x4000
47 * Additional combo box definitions
50 #define CB_NOTIFY( lphc, code ) \
51 (SendMessageW((lphc)->owner, WM_COMMAND, \
52 MAKEWPARAM(GetWindowLongPtrA((lphc)->self,GWLP_ID), (code)), (LPARAM)(lphc)->self))
54 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
55 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
56 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
57 #define CB_HWND( lphc ) ((lphc)->self)
59 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
64 static HBITMAP hComboBmp = 0;
65 static UINT CBitHeight, CBitWidth;
68 * Look and feel dependent "constants"
71 #define COMBO_YBORDERGAP 5
72 #define COMBO_XBORDERSIZE() 2
73 #define COMBO_YBORDERSIZE() 2
74 #define COMBO_EDITBUTTONSPACE() 0
75 #define EDIT_CONTROL_PADDING() 1
77 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
78 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
80 /*********************************************************************
81 * combo class descriptor
83 const struct builtin_class_descr COMBO_builtin_class =
85 "ComboBox", /* name */
86 CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, /* style */
87 ComboWndProcA, /* procA */
88 ComboWndProcW, /* procW */
89 sizeof(HEADCOMBO *), /* extra */
90 IDC_ARROW, /* cursor */
95 /***********************************************************************
98 * Load combo button bitmap.
100 static BOOL COMBO_Init()
104 if( hComboBmp ) return TRUE;
105 if( (hDC = CreateCompatibleDC(0)) )
108 if( (hComboBmp = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO))) )
114 GetObjectW( hComboBmp, sizeof(bm), &bm );
115 CBitHeight = bm.bmHeight;
116 CBitWidth = bm.bmWidth;
118 TRACE("combo bitmap [%i,%i]\n", CBitWidth, CBitHeight );
120 hPrevB = SelectObject( hDC, hComboBmp);
121 SetRect( &r, 0, 0, CBitWidth, CBitHeight );
122 InvertRect( hDC, &r );
123 SelectObject( hDC, hPrevB );
132 /***********************************************************************
135 static LRESULT COMBO_NCCreate(HWND hwnd, LONG style)
139 if (COMBO_Init() && (lphc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEADCOMBO))) )
142 SetWindowLongA( hwnd, 0, (LONG)lphc );
144 /* some braindead apps do try to use scrollbar/border flags */
146 lphc->dwStyle = style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
147 SetWindowLongA( hwnd, GWL_STYLE, style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL) );
150 * We also have to remove the client edge style to make sure
151 * we don't end-up with a non client area.
153 SetWindowLongA( hwnd, GWL_EXSTYLE,
154 GetWindowLongA( hwnd, GWL_EXSTYLE ) & ~WS_EX_CLIENTEDGE );
156 if( !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
157 lphc->dwStyle |= CBS_HASSTRINGS;
158 if( !(GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) )
159 lphc->wState |= CBF_NOTIFY;
161 TRACE("[%p], style = %08x\n", lphc, lphc->dwStyle );
167 /***********************************************************************
170 static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc )
175 TRACE("[%p]: freeing storage\n", lphc->self);
177 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && lphc->hWndLBox )
178 DestroyWindow( lphc->hWndLBox );
180 SetWindowLongA( lphc->self, 0, 0 );
181 HeapFree( GetProcessHeap(), 0, lphc );
186 /***********************************************************************
187 * CBGetTextAreaHeight
189 * This method will calculate the height of the text area of the
191 * The height of the text area is set in two ways.
192 * It can be set explicitly through a combobox message or through a
193 * WM_MEASUREITEM callback.
194 * If this is not the case, the height is set to 13 dialog units.
195 * This height was determined through experimentation.
197 static INT CBGetTextAreaHeight(
203 if( lphc->editHeight ) /* explicitly set height */
205 iTextItemHeight = lphc->editHeight;
210 HDC hDC = GetDC(hwnd);
215 hPrevFont = SelectObject( hDC, lphc->hFont );
217 GetTextMetricsW(hDC, &tm);
219 baseUnitY = tm.tmHeight;
222 SelectObject( hDC, hPrevFont );
224 ReleaseDC(hwnd, hDC);
226 iTextItemHeight = ((13 * baseUnitY) / 8);
229 * This "formula" calculates the height of the complete control.
230 * To calculate the height of the text area, we have to remove the
233 iTextItemHeight -= 2*COMBO_YBORDERSIZE();
237 * Check the ownerdraw case if we haven't asked the parent the size
240 if ( CB_OWNERDRAWN(lphc) &&
241 (lphc->wState & CBF_MEASUREITEM) )
243 MEASUREITEMSTRUCT measureItem;
245 INT originalItemHeight = iTextItemHeight;
246 UINT id = (UINT)GetWindowLongPtrA( lphc->self, GWLP_ID );
249 * We use the client rect for the width of the item.
251 GetClientRect(hwnd, &clientRect);
253 lphc->wState &= ~CBF_MEASUREITEM;
256 * Send a first one to measure the size of the text area
258 measureItem.CtlType = ODT_COMBOBOX;
259 measureItem.CtlID = id;
260 measureItem.itemID = -1;
261 measureItem.itemWidth = clientRect.right;
262 measureItem.itemHeight = iTextItemHeight - 6; /* ownerdrawn cb is taller */
263 measureItem.itemData = 0;
264 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
265 iTextItemHeight = 6 + measureItem.itemHeight;
268 * Send a second one in the case of a fixed ownerdraw list to calculate the
269 * size of the list items. (we basically do this on behalf of the listbox)
271 if (lphc->dwStyle & CBS_OWNERDRAWFIXED)
273 measureItem.CtlType = ODT_COMBOBOX;
274 measureItem.CtlID = id;
275 measureItem.itemID = 0;
276 measureItem.itemWidth = clientRect.right;
277 measureItem.itemHeight = originalItemHeight;
278 measureItem.itemData = 0;
279 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
280 lphc->fixedOwnerDrawHeight = measureItem.itemHeight;
284 * Keep the size for the next time
286 lphc->editHeight = iTextItemHeight;
289 return iTextItemHeight;
292 /***********************************************************************
295 * The dummy resize is used for listboxes that have a popup to trigger
296 * a re-arranging of the contents of the combobox and the recalculation
297 * of the size of the "real" control window.
299 static void CBForceDummyResize(
305 newComboHeight = CBGetTextAreaHeight(lphc->self,lphc) + 2*COMBO_YBORDERSIZE();
307 GetWindowRect(lphc->self, &windowRect);
310 * We have to be careful, resizing a combobox also has the meaning that the
311 * dropped rect will be resized. In this case, we want to trigger a resize
312 * to recalculate layout but we don't want to change the dropped rectangle
313 * So, we pass the height of text area of control as the height.
314 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
317 SetWindowPos( lphc->self,
320 windowRect.right - windowRect.left,
322 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
325 /***********************************************************************
328 * Set up component coordinates given valid lphc->RectCombo.
330 static void CBCalcPlacement(
338 * Again, start with the client rectangle.
340 GetClientRect(hwnd, lprEdit);
345 InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
348 * Chop off the bottom part to fit with the height of the text area.
350 lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
353 * The button starts the same vertical position as the text area.
355 CopyRect(lprButton, lprEdit);
358 * If the combobox is "simple" there is no button.
360 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
361 lprButton->left = lprButton->right = lprButton->bottom = 0;
365 * Let's assume the combobox button is the same width as the
367 * size the button horizontally and cut-off the text area.
369 lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
370 lprEdit->right = lprButton->left;
374 * In the case of a dropdown, there is an additional spacing between the
375 * text area and the button.
377 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
379 lprEdit->right -= COMBO_EDITBUTTONSPACE();
383 * If we have an edit control, we space it away from the borders slightly.
385 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
387 InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
391 * Adjust the size of the listbox popup.
393 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
396 * Use the client rectangle to initialize the listbox rectangle
398 GetClientRect(hwnd, lprLB);
401 * Then, chop-off the top part.
403 lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
408 * Make sure the dropped width is as large as the combobox itself.
410 if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
412 lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
415 * In the case of a dropdown, the popup listbox is offset to the right.
416 * so, we want to make sure it's flush with the right side of the
419 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
420 lprLB->right -= COMBO_EDITBUTTONSPACE();
423 lprLB->right = lprLB->left + lphc->droppedWidth;
426 TRACE("\ttext\t= (%ld,%ld-%ld,%ld)\n",
427 lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom);
429 TRACE("\tbutton\t= (%ld,%ld-%ld,%ld)\n",
430 lprButton->left, lprButton->top, lprButton->right, lprButton->bottom);
432 TRACE("\tlbox\t= (%ld,%ld-%ld,%ld)\n",
433 lprLB->left, lprLB->top, lprLB->right, lprLB->bottom );
436 /***********************************************************************
437 * CBGetDroppedControlRect
439 static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect)
441 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
442 of the combo box and the lower right corner of the listbox */
444 GetWindowRect(lphc->self, lpRect);
446 lpRect->right = lpRect->left + lphc->droppedRect.right - lphc->droppedRect.left;
447 lpRect->bottom = lpRect->top + lphc->droppedRect.bottom - lphc->droppedRect.top;
451 /***********************************************************************
452 * COMBO_WindowPosChanging
454 static LRESULT COMBO_WindowPosChanging(
457 WINDOWPOS* posChanging)
460 * We need to override the WM_WINDOWPOSCHANGING method to handle all
461 * the non-simple comboboxes. The problem is that those controls are
462 * always the same height. We have to make sure they are not resized
465 if ( ( CB_GETTYPE(lphc) != CBS_SIMPLE ) &&
466 ((posChanging->flags & SWP_NOSIZE) == 0) )
470 newComboHeight = CBGetTextAreaHeight(hwnd,lphc) +
471 2*COMBO_YBORDERSIZE();
474 * Resizing a combobox has another side effect, it resizes the dropped
475 * rectangle as well. However, it does it only if the new height for the
476 * combobox is different from the height it should have. In other words,
477 * if the application resizing the combobox only had the intention to resize
478 * the actual control, for example, to do the layout of a dialog that is
479 * resized, the height of the dropdown is not changed.
481 if (posChanging->cy != newComboHeight)
483 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%ld, oldtop=%ld\n",
484 posChanging->cy, newComboHeight, lphc->droppedRect.bottom,
485 lphc->droppedRect.top);
486 lphc->droppedRect.bottom = lphc->droppedRect.top + posChanging->cy - newComboHeight;
488 posChanging->cy = newComboHeight;
495 /***********************************************************************
498 static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style,
501 static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0};
502 static const WCHAR editName[] = {'E','d','i','t',0};
504 if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE;
505 if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT;
507 lphc->owner = hwndParent;
510 * The item height and dropped width are not set when the control
513 lphc->droppedWidth = lphc->editHeight = 0;
516 * The first time we go through, we want to measure the ownerdraw item
518 lphc->wState |= CBF_MEASUREITEM;
520 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
522 if( lphc->owner || !(style & WS_VISIBLE) )
528 * Initialize the dropped rect to the size of the client area of the
529 * control and then, force all the areas of the combobox to be
532 GetClientRect( hwnd, &lphc->droppedRect );
533 CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
536 * Adjust the position of the popup listbox if it's necessary
538 if ( CB_GETTYPE(lphc) != CBS_SIMPLE )
540 lphc->droppedRect.top = lphc->textRect.bottom + COMBO_YBORDERSIZE();
543 * If it's a dropdown, the listbox is offset
545 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
546 lphc->droppedRect.left += COMBO_EDITBUTTONSPACE();
548 ClientToScreen(hwnd, (LPPOINT)&lphc->droppedRect);
549 ClientToScreen(hwnd, (LPPOINT)&lphc->droppedRect.right);
552 /* create listbox popup */
554 lbeStyle = (LBS_NOTIFY | WS_BORDER | WS_CLIPSIBLINGS | WS_CHILD) |
555 (style & (WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE));
557 if( lphc->dwStyle & CBS_SORT )
558 lbeStyle |= LBS_SORT;
559 if( lphc->dwStyle & CBS_HASSTRINGS )
560 lbeStyle |= LBS_HASSTRINGS;
561 if( lphc->dwStyle & CBS_NOINTEGRALHEIGHT )
562 lbeStyle |= LBS_NOINTEGRALHEIGHT;
563 if( lphc->dwStyle & CBS_DISABLENOSCROLL )
564 lbeStyle |= LBS_DISABLENOSCROLL;
566 if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* child listbox */
568 lbeStyle |= WS_VISIBLE;
571 * In win 95 look n feel, the listbox in the simple combobox has
572 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
574 lbeStyle &= ~WS_BORDER;
575 lbeExStyle |= WS_EX_CLIENTEDGE;
579 lbeExStyle |= (WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
583 lphc->hWndLBox = CreateWindowExW(lbeExStyle, clbName, NULL, lbeStyle,
584 lphc->droppedRect.left,
585 lphc->droppedRect.top,
586 lphc->droppedRect.right - lphc->droppedRect.left,
587 lphc->droppedRect.bottom - lphc->droppedRect.top,
588 hwnd, (HMENU)ID_CB_LISTBOX,
589 (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), lphc );
591 lphc->hWndLBox = CreateWindowExA(lbeExStyle, "ComboLBox", NULL, lbeStyle,
592 lphc->droppedRect.left,
593 lphc->droppedRect.top,
594 lphc->droppedRect.right - lphc->droppedRect.left,
595 lphc->droppedRect.bottom - lphc->droppedRect.top,
596 hwnd, (HMENU)ID_CB_LISTBOX,
597 (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), lphc );
602 lbeStyle = WS_CHILD | WS_VISIBLE | ES_NOHIDESEL | ES_LEFT | ES_COMBO;
604 if( lphc->wState & CBF_EDIT )
606 if( lphc->dwStyle & CBS_OEMCONVERT )
607 lbeStyle |= ES_OEMCONVERT;
608 if( lphc->dwStyle & CBS_AUTOHSCROLL )
609 lbeStyle |= ES_AUTOHSCROLL;
610 if( lphc->dwStyle & CBS_LOWERCASE )
611 lbeStyle |= ES_LOWERCASE;
612 else if( lphc->dwStyle & CBS_UPPERCASE )
613 lbeStyle |= ES_UPPERCASE;
615 if (!IsWindowEnabled(hwnd)) lbeStyle |= WS_DISABLED;
618 lphc->hWndEdit = CreateWindowExW(0, editName, NULL, lbeStyle,
619 lphc->textRect.left, lphc->textRect.top,
620 lphc->textRect.right - lphc->textRect.left,
621 lphc->textRect.bottom - lphc->textRect.top,
622 hwnd, (HMENU)ID_CB_EDIT,
623 (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), NULL );
625 lphc->hWndEdit = CreateWindowExA(0, "Edit", NULL, lbeStyle,
626 lphc->textRect.left, lphc->textRect.top,
627 lphc->textRect.right - lphc->textRect.left,
628 lphc->textRect.bottom - lphc->textRect.top,
629 hwnd, (HMENU)ID_CB_EDIT,
630 (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), NULL );
632 if( !lphc->hWndEdit )
638 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
640 /* Now do the trick with parent */
641 SetParent(lphc->hWndLBox, HWND_DESKTOP);
643 * If the combo is a dropdown, we must resize the control
644 * to fit only the text area and button. To do this,
645 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
646 * will take care of setting the height for us.
648 CBForceDummyResize(lphc);
651 TRACE("init done\n");
654 ERR("edit control failure.\n");
655 } else ERR("listbox failure.\n");
656 } else ERR("no owner for visible combo.\n");
658 /* CreateWindow() will send WM_NCDESTROY to cleanup */
663 /***********************************************************************
666 * Paint combo button (normal, pressed, and disabled states).
668 static void CBPaintButton( LPHEADCOMBO lphc, HDC hdc, RECT rectButton)
670 UINT buttonState = DFCS_SCROLLCOMBOBOX;
672 if( lphc->wState & CBF_NOREDRAW )
676 if (lphc->wState & CBF_BUTTONDOWN)
677 buttonState |= DFCS_PUSHED;
679 if (CB_DISABLED(lphc))
680 buttonState |= DFCS_INACTIVE;
682 DrawFrameControl(hdc, &rectButton, DFC_SCROLL, buttonState);
685 /***********************************************************************
688 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
690 static void CBPaintText(
698 if( lphc->wState & CBF_NOREDRAW ) return;
702 /* follow Windows combobox that sends a bunch of text
703 * inquiries to its listbox while processing WM_PAINT. */
705 if( (id = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0) ) != LB_ERR )
707 size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0);
709 FIXME("LB_ERR probably not handled yet\n");
710 if( (pText = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))) )
712 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
713 size=SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText);
714 pText[size] = '\0'; /* just in case */
718 if( !CB_OWNERDRAWN(lphc) )
721 if( lphc->wState & CBF_EDIT )
723 static const WCHAR empty_stringW[] = { 0 };
724 if( CB_HASSTRINGS(lphc) ) SetWindowTextW( lphc->hWndEdit, pText ? pText : empty_stringW );
725 if( lphc->wState & CBF_FOCUSED )
726 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
728 else /* paint text field ourselves */
730 UINT itemState = ODS_COMBOBOXEDIT;
731 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hdc, lphc->hFont) : 0;
734 * Give ourselves some space.
736 InflateRect( &rectEdit, -1, -1 );
738 if( CB_OWNERDRAWN(lphc) )
742 UINT ctlid = (UINT)GetWindowLongPtrA( lphc->self, GWLP_ID );
744 /* setup state for DRAWITEM message. Owner will highlight */
745 if ( (lphc->wState & CBF_FOCUSED) &&
746 !(lphc->wState & CBF_DROPPED) )
747 itemState |= ODS_SELECTED | ODS_FOCUS;
750 * Save the current clip region.
751 * To retrieve the clip region, we need to create one "dummy"
754 clipRegion = CreateRectRgnIndirect(&rectEdit);
756 if (GetClipRgn(hdc, clipRegion)!=1)
758 DeleteObject(clipRegion);
762 if (!IsWindowEnabled(lphc->self) & WS_DISABLED) itemState |= ODS_DISABLED;
764 dis.CtlType = ODT_COMBOBOX;
766 dis.hwndItem = lphc->self;
767 dis.itemAction = ODA_DRAWENTIRE;
769 dis.itemState = itemState;
771 dis.rcItem = rectEdit;
772 dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA,
776 * Clip the DC and have the parent draw the item.
778 IntersectClipRect(hdc,
779 rectEdit.left, rectEdit.top,
780 rectEdit.right, rectEdit.bottom);
782 SendMessageW(lphc->owner, WM_DRAWITEM, ctlid, (LPARAM)&dis );
785 * Reset the clipping region.
787 SelectClipRgn(hdc, clipRegion);
791 static const WCHAR empty_stringW[] = { 0 };
793 if ( (lphc->wState & CBF_FOCUSED) &&
794 !(lphc->wState & CBF_DROPPED) ) {
797 FillRect( hdc, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) );
798 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
799 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
805 ETO_OPAQUE | ETO_CLIPPED,
807 pText ? pText : empty_stringW , size, NULL );
809 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED))
810 DrawFocusRect( hdc, &rectEdit );
814 SelectObject(hdc, hPrevFont );
817 HeapFree( GetProcessHeap(), 0, pText );
820 /***********************************************************************
823 static void CBPaintBorder(
830 if (CB_GETTYPE(lphc) != CBS_SIMPLE)
832 GetClientRect(hwnd, &clientRect);
836 CopyRect(&clientRect, &lphc->textRect);
838 InflateRect(&clientRect, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
839 InflateRect(&clientRect, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
842 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_RECT);
845 /***********************************************************************
846 * COMBO_PrepareColors
848 * This method will sent the appropriate WM_CTLCOLOR message to
849 * prepare and setup the colors for the combo's DC.
851 * It also returns the brush to use for the background.
853 static HBRUSH COMBO_PrepareColors(
860 * Get the background brush for this control.
862 if (CB_DISABLED(lphc))
864 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORSTATIC,
865 (WPARAM)hDC, (LPARAM)lphc->self );
868 * We have to change the text color since WM_CTLCOLORSTATIC will
869 * set it to the "enabled" color. This is the same behavior as the
872 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
876 if (lphc->wState & CBF_EDIT)
878 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLOREDIT,
879 (WPARAM)hDC, (LPARAM)lphc->self );
883 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORLISTBOX,
884 (WPARAM)hDC, (LPARAM)lphc->self );
892 hBkgBrush = GetSysColorBrush(COLOR_WINDOW);
897 /***********************************************************************
898 * COMBO_EraseBackground
900 static LRESULT COMBO_EraseBackground(
908 if(lphc->wState & CBF_EDIT)
911 hDC = (hParamDC) ? hParamDC
914 * Retrieve the background brush
916 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
918 FillRect(hDC, &lphc->textRect, hBkgBrush);
921 ReleaseDC(hwnd, hDC);
926 /***********************************************************************
929 static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC)
934 hDC = (hParamDC) ? hParamDC
935 : BeginPaint( lphc->self, &ps);
937 TRACE("hdc=%p\n", hDC);
939 if( hDC && !(lphc->wState & CBF_NOREDRAW) )
941 HBRUSH hPrevBrush, hBkgBrush;
944 * Retrieve the background brush and select it in the
947 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
949 hPrevBrush = SelectObject( hDC, hBkgBrush );
952 * In non 3.1 look, there is a sunken border on the combobox
954 CBPaintBorder(lphc->self, lphc, hDC);
956 if( !IsRectEmpty(&lphc->buttonRect) )
958 CBPaintButton(lphc, hDC, lphc->buttonRect);
961 /* paint the edit control padding area */
962 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
964 RECT rPadEdit = lphc->textRect;
966 InflateRect(&rPadEdit, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
968 FrameRect( hDC, &rPadEdit, GetSysColorBrush(COLOR_WINDOW) );
971 if( !(lphc->wState & CBF_EDIT) )
972 CBPaintText( lphc, hDC, lphc->textRect);
975 SelectObject( hDC, hPrevBrush );
979 EndPaint(lphc->self, &ps);
984 /***********************************************************************
987 * Select listbox entry according to the contents of the edit control.
989 static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
995 length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 );
998 pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1000 TRACE("\t edit text length %i\n", length );
1004 if( length ) GetWindowTextW( lphc->hWndEdit, pText, length + 1);
1005 else pText[0] = '\0';
1006 idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING,
1007 (WPARAM)(-1), (LPARAM)pText );
1008 HeapFree( GetProcessHeap(), 0, pText );
1011 SendMessageW(lphc->hWndLBox, LB_SETCURSEL, (WPARAM)(bSelect ? idx : -1), 0);
1013 /* probably superfluous but Windows sends this too */
1014 SendMessageW(lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1015 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1020 /***********************************************************************
1023 * Copy a listbox entry to the edit control.
1025 static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
1028 LPWSTR pText = NULL;
1029 static const WCHAR empty_stringW[] = { 0 };
1031 TRACE("\t %i\n", index );
1033 if( index >= 0 ) /* got an entry */
1035 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0);
1036 if( length != LB_ERR)
1038 if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) )
1040 SendMessageW(lphc->hWndLBox, LB_GETTEXT,
1041 (WPARAM)index, (LPARAM)pText );
1046 lphc->wState |= (CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1047 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, pText ? (LPARAM)pText : (LPARAM)empty_stringW);
1048 lphc->wState &= ~(CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1050 if( lphc->wState & CBF_FOCUSED )
1051 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1054 HeapFree( GetProcessHeap(), 0, pText );
1057 /***********************************************************************
1060 * Show listbox popup.
1062 static void CBDropDown( LPHEADCOMBO lphc )
1068 TRACE("[%p]: drop down\n", lphc->self);
1070 CB_NOTIFY( lphc, CBN_DROPDOWN );
1074 lphc->wState |= CBF_DROPPED;
1075 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1077 lphc->droppedIndex = CBUpdateLBox( lphc, TRUE );
1079 /* Update edit only if item is in the list */
1080 if( !(lphc->wState & CBF_CAPTURE) && lphc->droppedIndex >= 0)
1081 CBUpdateEdit( lphc, lphc->droppedIndex );
1085 lphc->droppedIndex = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1087 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX,
1088 (WPARAM)(lphc->droppedIndex == LB_ERR ? 0 : lphc->droppedIndex), 0 );
1089 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1092 /* now set popup position */
1093 GetWindowRect( lphc->self, &rect );
1096 * If it's a dropdown, the listbox is offset
1098 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1099 rect.left += COMBO_EDITBUTTONSPACE();
1101 /* if the dropped height is greater than the total height of the dropped
1102 items list, then force the drop down list height to be the total height
1103 of the items in the dropped list */
1105 /* And Remove any extra space (Best Fit) */
1106 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
1107 /* if listbox length has been set directly by its handle */
1108 GetWindowRect(lphc->hWndLBox, &r);
1109 if (nDroppedHeight < r.bottom - r.top)
1110 nDroppedHeight = r.bottom - r.top;
1111 nItems = (int)SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
1118 nIHeight = (int)SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, 0, 0);
1120 nHeight = nIHeight*nItems;
1122 if (nHeight < nDroppedHeight - COMBO_YBORDERSIZE())
1123 nDroppedHeight = nHeight + COMBO_YBORDERSIZE();
1125 if (nDroppedHeight < nIHeight)
1128 nDroppedHeight = (nItems+1)*nIHeight;
1130 nDroppedHeight = 6*nIHeight;
1134 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1135 if( (rect.bottom + nDroppedHeight) >= GetSystemMetrics( SM_CYSCREEN ) )
1136 rect.bottom = rect.top - nDroppedHeight;
1138 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
1139 lphc->droppedRect.right - lphc->droppedRect.left,
1141 SWP_NOACTIVATE | SWP_SHOWWINDOW);
1144 if( !(lphc->wState & CBF_NOREDRAW) )
1145 RedrawWindow( lphc->self, NULL, 0, RDW_INVALIDATE |
1146 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1148 EnableWindow( lphc->hWndLBox, TRUE );
1149 if (GetCapture() != lphc->self)
1150 SetCapture(lphc->hWndLBox);
1153 /***********************************************************************
1156 * Hide listbox popup.
1158 static void CBRollUp( LPHEADCOMBO lphc, BOOL ok, BOOL bButton )
1160 HWND hWnd = lphc->self;
1162 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1163 lphc->self, (INT)ok, (INT)(lphc->wState & CBF_DROPPED));
1165 CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL );
1167 if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE )
1170 if( lphc->wState & CBF_DROPPED )
1174 lphc->wState &= ~CBF_DROPPED;
1175 ShowWindow( lphc->hWndLBox, SW_HIDE );
1177 if(GetCapture() == lphc->hWndLBox)
1182 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1184 rect = lphc->buttonRect;
1195 rect = lphc->textRect;
1200 if( bButton && !(lphc->wState & CBF_NOREDRAW) )
1201 RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE |
1202 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1203 CB_NOTIFY( lphc, CBN_CLOSEUP );
1208 /***********************************************************************
1211 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1213 BOOL COMBO_FlipListbox( LPHEADCOMBO lphc, BOOL ok, BOOL bRedrawButton )
1215 if( lphc->wState & CBF_DROPPED )
1217 CBRollUp( lphc, ok, bRedrawButton );
1225 /***********************************************************************
1228 static void CBRepaintButton( LPHEADCOMBO lphc )
1230 InvalidateRect(lphc->self, &lphc->buttonRect, TRUE);
1231 UpdateWindow(lphc->self);
1234 /***********************************************************************
1237 static void COMBO_SetFocus( LPHEADCOMBO lphc )
1239 if( !(lphc->wState & CBF_FOCUSED) )
1241 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1242 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1244 /* This is wrong. Message sequences seem to indicate that this
1245 is set *after* the notify. */
1246 /* lphc->wState |= CBF_FOCUSED; */
1248 if( !(lphc->wState & CBF_EDIT) )
1249 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1251 CB_NOTIFY( lphc, CBN_SETFOCUS );
1252 lphc->wState |= CBF_FOCUSED;
1256 /***********************************************************************
1259 static void COMBO_KillFocus( LPHEADCOMBO lphc )
1261 HWND hWnd = lphc->self;
1263 if( lphc->wState & CBF_FOCUSED )
1265 CBRollUp( lphc, FALSE, TRUE );
1266 if( IsWindow( hWnd ) )
1268 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1269 SendMessageW(lphc->hWndLBox, LB_CARETOFF, 0, 0);
1271 lphc->wState &= ~CBF_FOCUSED;
1274 if( !(lphc->wState & CBF_EDIT) )
1275 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1277 CB_NOTIFY( lphc, CBN_KILLFOCUS );
1282 /***********************************************************************
1285 static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd )
1287 if ( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd )
1289 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1291 switch( HIWORD(wParam) >> 8 )
1293 case (EN_SETFOCUS >> 8):
1295 TRACE("[%p]: edit [%p] got focus\n", lphc->self, lphc->hWndEdit );
1297 COMBO_SetFocus( lphc );
1300 case (EN_KILLFOCUS >> 8):
1302 TRACE("[%p]: edit [%p] lost focus\n", lphc->self, lphc->hWndEdit );
1304 /* NOTE: it seems that Windows' edit control sends an
1305 * undocumented message WM_USER + 0x1B instead of this
1306 * notification (only when it happens to be a part of
1307 * the combo). ?? - AK.
1310 COMBO_KillFocus( lphc );
1314 case (EN_CHANGE >> 8):
1316 * In some circumstances (when the selection of the combobox
1317 * is changed for example) we don't wans the EN_CHANGE notification
1318 * to be forwarded to the parent of the combobox. This code
1319 * checks a flag that is set in these occasions and ignores the
1322 if (lphc->wState & CBF_NOLBSELECT)
1324 lphc->wState &= ~CBF_NOLBSELECT;
1328 CBUpdateLBox( lphc, lphc->wState & CBF_DROPPED );
1331 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1332 CB_NOTIFY( lphc, CBN_EDITCHANGE );
1335 case (EN_UPDATE >> 8):
1336 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1337 CB_NOTIFY( lphc, CBN_EDITUPDATE );
1340 case (EN_ERRSPACE >> 8):
1341 CB_NOTIFY( lphc, CBN_ERRSPACE );
1344 else if( lphc->hWndLBox == hWnd )
1346 switch( (short)HIWORD(wParam) )
1349 CB_NOTIFY( lphc, CBN_ERRSPACE );
1353 CB_NOTIFY( lphc, CBN_DBLCLK );
1359 TRACE("[%p]: lbox selection change [%x]\n", lphc->self, lphc->wState );
1361 if( HIWORD(wParam) == LBN_SELCHANGE)
1363 if( lphc->wState & CBF_EDIT )
1365 INT index = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1366 lphc->wState |= CBF_NOLBSELECT;
1367 CBUpdateEdit( lphc, index );
1368 /* select text in edit, as Windows does */
1369 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1372 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1375 /* do not roll up if selection is being tracked
1376 * by arrowkeys in the dropdown listbox */
1377 if( ((lphc->wState & CBF_DROPPED) && !(lphc->wState & CBF_NOROLLUP)) )
1379 CBRollUp( lphc, (HIWORD(wParam) == LBN_SELCHANGE), TRUE );
1381 else lphc->wState &= ~CBF_NOROLLUP;
1383 CB_NOTIFY( lphc, CBN_SELCHANGE );
1389 /* nothing to do here since ComboLBox always resets the focus to its
1390 * combo/edit counterpart */
1397 /***********************************************************************
1400 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1402 static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
1404 HWND hWnd = lphc->self;
1405 UINT id = (UINT)GetWindowLongPtrA( hWnd, GWLP_ID );
1407 TRACE("[%p]: ownerdraw op %04x\n", lphc->self, msg );
1413 DELETEITEMSTRUCT *lpIS = (DELETEITEMSTRUCT *)lParam;
1414 lpIS->CtlType = ODT_COMBOBOX;
1416 lpIS->hwndItem = hWnd;
1421 DRAWITEMSTRUCT *lpIS = (DRAWITEMSTRUCT *)lParam;
1422 lpIS->CtlType = ODT_COMBOBOX;
1424 lpIS->hwndItem = hWnd;
1427 case WM_COMPAREITEM:
1429 COMPAREITEMSTRUCT *lpIS = (COMPAREITEMSTRUCT *)lParam;
1430 lpIS->CtlType = ODT_COMBOBOX;
1432 lpIS->hwndItem = hWnd;
1435 case WM_MEASUREITEM:
1437 MEASUREITEMSTRUCT *lpIS = (MEASUREITEMSTRUCT *)lParam;
1438 lpIS->CtlType = ODT_COMBOBOX;
1443 return SendMessageW(lphc->owner, msg, id, lParam);
1447 /***********************************************************************
1450 static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf )
1454 if( lphc->wState & CBF_EDIT )
1455 return SendMessageW( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1457 /* get it from the listbox */
1459 if (!count || !buf) return 0;
1460 if( lphc->hWndLBox )
1462 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1463 if (idx == LB_ERR) goto error;
1464 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1465 if (length == LB_ERR) goto error;
1467 /* 'length' is without the terminating character */
1468 if (length >= count)
1470 LPWSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1471 if (!lpBuffer) goto error;
1472 length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1474 /* truncate if buffer is too short */
1475 if (length != LB_ERR)
1477 lstrcpynW( buf, lpBuffer, count );
1480 HeapFree( GetProcessHeap(), 0, lpBuffer );
1482 else length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1484 if (length == LB_ERR) return 0;
1488 error: /* error - truncate string, return zero */
1494 /***********************************************************************
1497 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1498 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1500 static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf )
1504 if( lphc->wState & CBF_EDIT )
1505 return SendMessageA( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1507 /* get it from the listbox */
1509 if (!count || !buf) return 0;
1510 if( lphc->hWndLBox )
1512 INT idx = SendMessageA(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1513 if (idx == LB_ERR) goto error;
1514 length = SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1515 if (length == LB_ERR) goto error;
1517 /* 'length' is without the terminating character */
1518 if (length >= count)
1520 LPSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) );
1521 if (!lpBuffer) goto error;
1522 length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1524 /* truncate if buffer is too short */
1525 if (length != LB_ERR)
1527 lstrcpynA( buf, lpBuffer, count );
1530 HeapFree( GetProcessHeap(), 0, lpBuffer );
1532 else length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1534 if (length == LB_ERR) return 0;
1538 error: /* error - truncate string, return zero */
1544 /***********************************************************************
1547 * This function sets window positions according to the updated
1548 * component placement struct.
1550 static void CBResetPos(
1556 BOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE);
1558 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1559 * sizing messages */
1561 if( lphc->wState & CBF_EDIT )
1562 SetWindowPos( lphc->hWndEdit, 0,
1563 rectEdit->left, rectEdit->top,
1564 rectEdit->right - rectEdit->left,
1565 rectEdit->bottom - rectEdit->top,
1566 SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) );
1568 SetWindowPos( lphc->hWndLBox, 0,
1569 rectLB->left, rectLB->top,
1570 rectLB->right - rectLB->left,
1571 rectLB->bottom - rectLB->top,
1572 SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) );
1576 if( lphc->wState & CBF_DROPPED )
1578 lphc->wState &= ~CBF_DROPPED;
1579 ShowWindow( lphc->hWndLBox, SW_HIDE );
1582 if( bRedraw && !(lphc->wState & CBF_NOREDRAW) )
1583 RedrawWindow( lphc->self, NULL, 0,
1584 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
1589 /***********************************************************************
1592 static void COMBO_Size( LPHEADCOMBO lphc )
1594 CBCalcPlacement(lphc->self,
1598 &lphc->droppedRect);
1600 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1604 /***********************************************************************
1607 static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
1612 lphc->hFont = hFont;
1615 * Propagate to owned windows.
1617 if( lphc->wState & CBF_EDIT )
1618 SendMessageW(lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw);
1619 SendMessageW(lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw);
1622 * Redo the layout of the control.
1624 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1626 CBCalcPlacement(lphc->self,
1630 &lphc->droppedRect);
1632 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1636 CBForceDummyResize(lphc);
1641 /***********************************************************************
1642 * COMBO_SetItemHeight
1644 static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
1646 LRESULT lRet = CB_ERR;
1648 if( index == -1 ) /* set text field height */
1650 if( height < 32768 )
1652 lphc->editHeight = height;
1655 * Redo the layout of the control.
1657 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1659 CBCalcPlacement(lphc->self,
1663 &lphc->droppedRect);
1665 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1669 CBForceDummyResize(lphc);
1675 else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */
1676 lRet = SendMessageW(lphc->hWndLBox, LB_SETITEMHEIGHT,
1677 (WPARAM)index, (LPARAM)height );
1681 /***********************************************************************
1682 * COMBO_SelectString
1684 static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPARAM pText, BOOL unicode )
1686 INT index = unicode ? SendMessageW(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText) :
1687 SendMessageA(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText);
1690 if( lphc->wState & CBF_EDIT )
1691 CBUpdateEdit( lphc, index );
1694 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1697 return (LRESULT)index;
1700 /***********************************************************************
1703 static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam )
1707 HWND hWnd = lphc->self;
1709 pt.x = LOWORD(lParam);
1710 pt.y = HIWORD(lParam);
1711 bButton = PtInRect(&lphc->buttonRect, pt);
1713 if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) ||
1714 (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) )
1716 lphc->wState |= CBF_BUTTONDOWN;
1717 if( lphc->wState & CBF_DROPPED )
1719 /* got a click to cancel selection */
1721 lphc->wState &= ~CBF_BUTTONDOWN;
1722 CBRollUp( lphc, TRUE, FALSE );
1723 if( !IsWindow( hWnd ) ) return;
1725 if( lphc->wState & CBF_CAPTURE )
1727 lphc->wState &= ~CBF_CAPTURE;
1733 /* drop down the listbox and start tracking */
1735 lphc->wState |= CBF_CAPTURE;
1739 if( bButton ) CBRepaintButton( lphc );
1743 /***********************************************************************
1746 * Release capture and stop tracking if needed.
1748 static void COMBO_LButtonUp( LPHEADCOMBO lphc )
1750 if( lphc->wState & CBF_CAPTURE )
1752 lphc->wState &= ~CBF_CAPTURE;
1753 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1755 INT index = CBUpdateLBox( lphc, TRUE );
1756 /* Update edit only if item is in the list */
1759 lphc->wState |= CBF_NOLBSELECT;
1760 CBUpdateEdit( lphc, index );
1761 lphc->wState &= ~CBF_NOLBSELECT;
1765 SetCapture(lphc->hWndLBox);
1768 if( lphc->wState & CBF_BUTTONDOWN )
1770 lphc->wState &= ~CBF_BUTTONDOWN;
1771 CBRepaintButton( lphc );
1775 /***********************************************************************
1778 * Two things to do - track combo button and release capture when
1779 * pointer goes into the listbox.
1781 static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam )
1786 pt.x = LOWORD(lParam);
1787 pt.y = HIWORD(lParam);
1789 if( lphc->wState & CBF_BUTTONDOWN )
1793 bButton = PtInRect(&lphc->buttonRect, pt);
1797 lphc->wState &= ~CBF_BUTTONDOWN;
1798 CBRepaintButton( lphc );
1802 GetClientRect( lphc->hWndLBox, &lbRect );
1803 MapWindowPoints( lphc->self, lphc->hWndLBox, &pt, 1 );
1804 if( PtInRect(&lbRect, pt) )
1806 lphc->wState &= ~CBF_CAPTURE;
1808 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc, TRUE );
1810 /* hand over pointer tracking */
1811 SendMessageW(lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam);
1816 /***********************************************************************
1817 * ComboWndProc_common
1819 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxes.asp
1821 static LRESULT ComboWndProc_common( HWND hwnd, UINT message,
1822 WPARAM wParam, LPARAM lParam, BOOL unicode )
1824 LPHEADCOMBO lphc = (LPHEADCOMBO)GetWindowLongA( hwnd, 0 );
1826 TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1827 hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1829 if( lphc || message == WM_NCCREATE )
1833 /* System messages */
1837 LONG style = unicode ? ((LPCREATESTRUCTW)lParam)->style :
1838 ((LPCREATESTRUCTA)lParam)->style;
1839 return COMBO_NCCreate(hwnd, style);
1842 COMBO_NCDestroy(lphc);
1843 break;/* -> DefWindowProc */
1851 hwndParent = ((LPCREATESTRUCTW)lParam)->hwndParent;
1852 style = ((LPCREATESTRUCTW)lParam)->style;
1856 hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent;
1857 style = ((LPCREATESTRUCTA)lParam)->style;
1859 return COMBO_Create(hwnd, lphc, hwndParent, style, unicode);
1862 case WM_PRINTCLIENT:
1863 if (lParam & PRF_ERASEBKGND)
1864 COMBO_EraseBackground(hwnd, lphc, (HDC)wParam);
1868 /* wParam may contain a valid HDC! */
1869 return COMBO_Paint(lphc, (HDC)wParam);
1871 return COMBO_EraseBackground(hwnd, lphc, (HDC)wParam);
1874 LRESULT result = DLGC_WANTARROWS | DLGC_WANTCHARS;
1875 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1877 int vk = (int)((LPMSG)lParam)->wParam;
1879 if ((vk == VK_RETURN || vk == VK_ESCAPE) && (lphc->wState & CBF_DROPPED))
1880 result |= DLGC_WANTMESSAGE;
1884 case WM_WINDOWPOSCHANGING:
1885 return COMBO_WindowPosChanging(hwnd, lphc, (LPWINDOWPOS)lParam);
1886 case WM_WINDOWPOSCHANGED:
1887 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1888 * In that case, the Combobox itself will not be resized, so we won't
1889 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1894 if( lphc->hWndLBox &&
1895 !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc );
1898 COMBO_Font( lphc, (HFONT)wParam, (BOOL)lParam );
1901 return (LRESULT)lphc->hFont;
1903 if( lphc->wState & CBF_EDIT )
1904 SetFocus( lphc->hWndEdit );
1906 COMBO_SetFocus( lphc );
1910 HWND hwndFocus = WIN_GetFullHandle( (HWND)wParam );
1912 (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox ))
1913 COMBO_KillFocus( lphc );
1917 return COMBO_Command( lphc, wParam, WIN_GetFullHandle( (HWND)lParam ) );
1919 return unicode ? COMBO_GetTextW( lphc, wParam, (LPWSTR)lParam )
1920 : COMBO_GetTextA( lphc, wParam, (LPSTR)lParam );
1922 case WM_GETTEXTLENGTH:
1924 if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT))
1926 int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1927 if (j == -1) return 0;
1928 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0) :
1929 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, j, 0);
1931 else if( lphc->wState & CBF_EDIT )
1934 lphc->wState |= CBF_NOEDITNOTIFY;
1935 ret = unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1936 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1937 lphc->wState &= ~CBF_NOEDITNOTIFY;
1944 if( lphc->wState & CBF_EDIT )
1946 return unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1947 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1953 case WM_COMPAREITEM:
1954 case WM_MEASUREITEM:
1955 return COMBO_ItemOp(lphc, message, lParam);
1957 if( lphc->wState & CBF_EDIT )
1958 EnableWindow( lphc->hWndEdit, (BOOL)wParam );
1959 EnableWindow( lphc->hWndLBox, (BOOL)wParam );
1961 /* Force the control to repaint when the enabled state changes. */
1962 InvalidateRect(lphc->self, NULL, TRUE);
1966 lphc->wState &= ~CBF_NOREDRAW;
1968 lphc->wState |= CBF_NOREDRAW;
1970 if( lphc->wState & CBF_EDIT )
1971 SendMessageW(lphc->hWndEdit, message, wParam, lParam);
1972 SendMessageW(lphc->hWndLBox, message, wParam, lParam);
1975 if( KEYDATA_ALT & HIWORD(lParam) )
1976 if( wParam == VK_UP || wParam == VK_DOWN )
1977 COMBO_FlipListbox( lphc, FALSE, FALSE );
1986 if ((wParam == VK_RETURN || wParam == VK_ESCAPE) &&
1987 (lphc->wState & CBF_DROPPED))
1989 CBRollUp( lphc, wParam == VK_RETURN, FALSE );
1993 if( lphc->wState & CBF_EDIT )
1994 hwndTarget = lphc->hWndEdit;
1996 hwndTarget = lphc->hWndLBox;
1998 return unicode ? SendMessageW(hwndTarget, message, wParam, lParam) :
1999 SendMessageA(hwndTarget, message, wParam, lParam);
2001 case WM_LBUTTONDOWN:
2002 if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self );
2003 if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
2006 COMBO_LButtonUp( lphc );
2009 if( lphc->wState & CBF_CAPTURE )
2010 COMBO_MouseMove( lphc, wParam, lParam );
2014 if (wParam & (MK_SHIFT | MK_CONTROL))
2015 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2016 DefWindowProcA(hwnd, message, wParam, lParam);
2018 if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_UP, 0);
2019 if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_DOWN, 0);
2022 /* Combo messages */
2024 case CB_ADDSTRING16:
2025 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2030 if( lphc->dwStyle & CBS_LOWERCASE )
2031 strlwrW((LPWSTR)lParam);
2032 else if( lphc->dwStyle & CBS_UPPERCASE )
2033 struprW((LPWSTR)lParam);
2034 return SendMessageW(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2038 if( lphc->dwStyle & CBS_LOWERCASE )
2039 _strlwr((LPSTR)lParam);
2040 else if( lphc->dwStyle & CBS_UPPERCASE )
2041 _strupr((LPSTR)lParam);
2042 return SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2044 case CB_INSERTSTRING16:
2045 wParam = (INT)(INT16)wParam;
2046 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2048 case CB_INSERTSTRING:
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_INSERTSTRING, wParam, 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_INSERTSTRING, wParam, lParam);
2065 case CB_DELETESTRING16:
2066 case CB_DELETESTRING:
2067 return unicode ? SendMessageW(lphc->hWndLBox, LB_DELETESTRING, wParam, 0) :
2068 SendMessageA(lphc->hWndLBox, LB_DELETESTRING, wParam, 0);
2069 case CB_SELECTSTRING16:
2070 wParam = (INT)(INT16)wParam;
2071 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2073 case CB_SELECTSTRING:
2074 return COMBO_SelectString(lphc, (INT)wParam, lParam, unicode);
2075 case CB_FINDSTRING16:
2076 wParam = (INT)(INT16)wParam;
2077 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2080 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam) :
2081 SendMessageA(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam);
2082 case CB_FINDSTRINGEXACT16:
2083 wParam = (INT)(INT16)wParam;
2084 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2086 case CB_FINDSTRINGEXACT:
2087 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam) :
2088 SendMessageA(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam);
2089 case CB_SETITEMHEIGHT16:
2090 wParam = (INT)(INT16)wParam; /* signed integer */
2092 case CB_SETITEMHEIGHT:
2093 return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam);
2094 case CB_GETITEMHEIGHT16:
2095 wParam = (INT)(INT16)wParam;
2097 case CB_GETITEMHEIGHT:
2098 if( (INT)wParam >= 0 ) /* listbox item */
2099 return SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0);
2100 return CBGetTextAreaHeight(hwnd, lphc);
2101 case CB_RESETCONTENT16:
2102 case CB_RESETCONTENT:
2103 SendMessageW(lphc->hWndLBox, LB_RESETCONTENT, 0, 0);
2104 if( (lphc->wState & CBF_EDIT) && CB_HASSTRINGS(lphc) )
2106 static const WCHAR empty_stringW[] = { 0 };
2107 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);
2110 InvalidateRect(lphc->self, NULL, TRUE);
2112 case CB_INITSTORAGE:
2113 return SendMessageW(lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam);
2114 case CB_GETHORIZONTALEXTENT:
2115 return SendMessageW(lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0);
2116 case CB_SETHORIZONTALEXTENT:
2117 return SendMessageW(lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0);
2118 case CB_GETTOPINDEX:
2119 return SendMessageW(lphc->hWndLBox, LB_GETTOPINDEX, 0, 0);
2121 return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0);
2123 return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0);
2124 case CB_GETDROPPEDWIDTH:
2125 if( lphc->droppedWidth )
2126 return lphc->droppedWidth;
2127 return lphc->droppedRect.right - lphc->droppedRect.left;
2128 case CB_SETDROPPEDWIDTH:
2129 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) &&
2130 (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam;
2132 case CB_GETDROPPEDCONTROLRECT16:
2133 lParam = (LPARAM)MapSL(lParam);
2137 RECT16 *r16 = (RECT16 *)lParam;
2138 CBGetDroppedControlRect( lphc, &r );
2141 r16->right = r.right;
2142 r16->bottom = r.bottom;
2145 case CB_GETDROPPEDCONTROLRECT:
2146 if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam );
2148 case CB_GETDROPPEDSTATE16:
2149 case CB_GETDROPPEDSTATE:
2150 return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE;
2152 return SendMessageA(lphc->hWndLBox, LB_DIR16, wParam, lParam);
2154 return unicode ? SendMessageW(lphc->hWndLBox, LB_DIR, wParam, lParam) :
2155 SendMessageA(lphc->hWndLBox, LB_DIR, wParam, lParam);
2157 case CB_SHOWDROPDOWN16:
2158 case CB_SHOWDROPDOWN:
2159 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
2163 if( !(lphc->wState & CBF_DROPPED) )
2167 if( lphc->wState & CBF_DROPPED )
2168 CBRollUp( lphc, FALSE, TRUE );
2173 return SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
2174 case CB_GETCURSEL16:
2176 return SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
2177 case CB_SETCURSEL16:
2178 wParam = (INT)(INT16)wParam;
2181 lParam = SendMessageW(lphc->hWndLBox, LB_SETCURSEL, wParam, 0);
2183 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, wParam, 0);
2185 /* no LBN_SELCHANGE in this case, update manually */
2186 if( lphc->wState & CBF_EDIT )
2187 CBUpdateEdit( lphc, (INT)wParam );
2189 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
2190 lphc->wState &= ~CBF_SELCHANGE;
2192 case CB_GETLBTEXT16:
2193 wParam = (INT)(INT16)wParam;
2194 lParam = (LPARAM)MapSL(lParam);
2197 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXT, wParam, lParam) :
2198 SendMessageA(lphc->hWndLBox, LB_GETTEXT, wParam, lParam);
2199 case CB_GETLBTEXTLEN16:
2200 wParam = (INT)(INT16)wParam;
2202 case CB_GETLBTEXTLEN:
2203 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0) :
2204 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0);
2205 case CB_GETITEMDATA16:
2206 wParam = (INT)(INT16)wParam;
2208 case CB_GETITEMDATA:
2209 return SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0);
2210 case CB_SETITEMDATA16:
2211 wParam = (INT)(INT16)wParam;
2213 case CB_SETITEMDATA:
2214 return SendMessageW(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam);
2215 case CB_GETEDITSEL16:
2216 wParam = lParam = 0; /* just in case */
2219 /* Edit checks passed parameters itself */
2220 if( lphc->wState & CBF_EDIT )
2221 return SendMessageW(lphc->hWndEdit, EM_GETSEL, wParam, lParam);
2223 case CB_SETEDITSEL16:
2225 if( lphc->wState & CBF_EDIT )
2226 return SendMessageW(lphc->hWndEdit, EM_SETSEL,
2227 (INT)(INT16)LOWORD(lParam), (INT)(INT16)HIWORD(lParam) );
2229 case CB_SETEXTENDEDUI16:
2230 case CB_SETEXTENDEDUI:
2231 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
2234 lphc->wState |= CBF_EUI;
2235 else lphc->wState &= ~CBF_EUI;
2237 case CB_GETEXTENDEDUI16:
2238 case CB_GETEXTENDEDUI:
2239 return (lphc->wState & CBF_EUI) ? TRUE : FALSE;
2242 if (message >= WM_USER)
2243 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2244 message - WM_USER, wParam, lParam );
2247 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2248 DefWindowProcA(hwnd, message, wParam, lParam);
2251 /***********************************************************************
2254 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2257 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2259 if (!IsWindow(hwnd)) return 0;
2260 return ComboWndProc_common( hwnd, message, wParam, lParam, FALSE );
2263 /***********************************************************************
2266 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2268 if (!IsWindow(hwnd)) return 0;
2269 return ComboWndProc_common( hwnd, message, wParam, lParam, TRUE );
2272 /*************************************************************************
2273 * GetComboBoxInfo (USER32.@)
2275 BOOL WINAPI GetComboBoxInfo(HWND hwndCombo, /* [in] handle to combo box */
2276 PCOMBOBOXINFO pcbi /* [in/out] combo box information */)