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.
29 #include "wine/winuser16.h"
30 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(combo);
39 /* bits in the dwKeyData */
40 #define KEYDATA_ALT 0x2000
41 #define KEYDATA_PREVSTATE 0x4000
44 * Additional combo box definitions
47 #define CB_NOTIFY( lphc, code ) \
48 (SendMessageW((lphc)->owner, WM_COMMAND, \
49 MAKEWPARAM(GetWindowLongA((lphc)->self,GWL_ID), (code)), (LPARAM)(lphc)->self))
51 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
52 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
53 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
54 #define CB_HWND( lphc ) ((lphc)->self)
56 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
61 static HBITMAP hComboBmp = 0;
62 static UINT CBitHeight, CBitWidth;
65 * Look and feel dependant "constants"
68 #define COMBO_YBORDERGAP 5
69 #define COMBO_XBORDERSIZE() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 2 )
70 #define COMBO_YBORDERSIZE() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 2 )
71 #define COMBO_EDITBUTTONSPACE() ( (TWEAK_WineLook == WIN31_LOOK) ? 8 : 0 )
72 #define EDIT_CONTROL_PADDING() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 1 )
74 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
75 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
77 /*********************************************************************
78 * combo class descriptor
80 const struct builtin_class_descr COMBO_builtin_class =
82 "ComboBox", /* name */
83 CS_GLOBALCLASS | CS_PARENTDC | CS_DBLCLKS, /* style */
84 ComboWndProcA, /* procA */
85 ComboWndProcW, /* procW */
86 sizeof(HEADCOMBO *), /* extra */
87 IDC_ARROWA, /* cursor */
92 /***********************************************************************
95 * Load combo button bitmap.
97 static BOOL COMBO_Init()
101 if( hComboBmp ) return TRUE;
102 if( (hDC = CreateCompatibleDC(0)) )
105 if( (hComboBmp = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO))) )
111 GetObjectW( hComboBmp, sizeof(bm), &bm );
112 CBitHeight = bm.bmHeight;
113 CBitWidth = bm.bmWidth;
115 TRACE("combo bitmap [%i,%i]\n", CBitWidth, CBitHeight );
117 hPrevB = SelectObject( hDC, hComboBmp);
118 SetRect( &r, 0, 0, CBitWidth, CBitHeight );
119 InvertRect( hDC, &r );
120 SelectObject( hDC, hPrevB );
129 /***********************************************************************
132 static LRESULT COMBO_NCCreate(HWND hwnd, LONG style)
136 if (COMBO_Init() && (lphc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEADCOMBO))) )
139 SetWindowLongA( hwnd, 0, (LONG)lphc );
141 /* some braindead apps do try to use scrollbar/border flags */
143 lphc->dwStyle = style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
144 SetWindowLongA( hwnd, GWL_STYLE, style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL) );
147 * We also have to remove the client edge style to make sure
148 * we don't end-up with a non client area.
150 SetWindowLongA( hwnd, GWL_EXSTYLE,
151 GetWindowLongA( hwnd, GWL_EXSTYLE ) & ~WS_EX_CLIENTEDGE );
153 if( !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
154 lphc->dwStyle |= CBS_HASSTRINGS;
155 if( !(GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) )
156 lphc->wState |= CBF_NOTIFY;
158 TRACE("[%p], style = %08x\n", lphc, lphc->dwStyle );
164 /***********************************************************************
167 static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc )
172 TRACE("[%04x]: freeing storage\n", lphc->self);
174 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && lphc->hWndLBox )
175 DestroyWindow( lphc->hWndLBox );
177 SetWindowLongA( lphc->self, 0, 0 );
178 HeapFree( GetProcessHeap(), 0, lphc );
183 /***********************************************************************
184 * CBGetTextAreaHeight
186 * This method will calculate the height of the text area of the
188 * The height of the text area is set in two ways.
189 * It can be set explicitly through a combobox message or through a
190 * WM_MEASUREITEM callback.
191 * If this is not the case, the height is set to 13 dialog units.
192 * This height was determined through experimentation.
194 static INT CBGetTextAreaHeight(
200 if( lphc->editHeight ) /* explicitly set height */
202 iTextItemHeight = lphc->editHeight;
207 HDC hDC = GetDC(hwnd);
212 hPrevFont = SelectObject( hDC, lphc->hFont );
214 GetTextMetricsW(hDC, &tm);
216 baseUnitY = tm.tmHeight;
219 SelectObject( hDC, hPrevFont );
221 ReleaseDC(hwnd, hDC);
223 iTextItemHeight = ((13 * baseUnitY) / 8);
226 * This "formula" calculates the height of the complete control.
227 * To calculate the height of the text area, we have to remove the
230 iTextItemHeight -= 2*COMBO_YBORDERSIZE();
234 * Check the ownerdraw case if we haven't asked the parent the size
237 if ( CB_OWNERDRAWN(lphc) &&
238 (lphc->wState & CBF_MEASUREITEM) )
240 MEASUREITEMSTRUCT measureItem;
242 INT originalItemHeight = iTextItemHeight;
243 UINT id = GetWindowLongA( lphc->self, GWL_ID );
246 * We use the client rect for the width of the item.
248 GetClientRect(hwnd, &clientRect);
250 lphc->wState &= ~CBF_MEASUREITEM;
253 * Send a first one to measure the size of the text area
255 measureItem.CtlType = ODT_COMBOBOX;
256 measureItem.CtlID = id;
257 measureItem.itemID = -1;
258 measureItem.itemWidth = clientRect.right;
259 measureItem.itemHeight = iTextItemHeight - 6; /* ownerdrawn cb is taller */
260 measureItem.itemData = 0;
261 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
262 iTextItemHeight = 6 + measureItem.itemHeight;
265 * Send a second one in the case of a fixed ownerdraw list to calculate the
266 * size of the list items. (we basically do this on behalf of the listbox)
268 if (lphc->dwStyle & CBS_OWNERDRAWFIXED)
270 measureItem.CtlType = ODT_COMBOBOX;
271 measureItem.CtlID = id;
272 measureItem.itemID = 0;
273 measureItem.itemWidth = clientRect.right;
274 measureItem.itemHeight = originalItemHeight;
275 measureItem.itemData = 0;
276 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
277 lphc->fixedOwnerDrawHeight = measureItem.itemHeight;
281 * Keep the size for the next time
283 lphc->editHeight = iTextItemHeight;
286 return iTextItemHeight;
289 /***********************************************************************
292 * The dummy resize is used for listboxes that have a popup to trigger
293 * a re-arranging of the contents of the combobox and the recalculation
294 * of the size of the "real" control window.
296 static void CBForceDummyResize(
302 newComboHeight = CBGetTextAreaHeight(lphc->self,lphc) + 2*COMBO_YBORDERSIZE();
304 GetWindowRect(lphc->self, &windowRect);
307 * We have to be careful, resizing a combobox also has the meaning that the
308 * dropped rect will be resized. In this case, we want to trigger a resize
309 * to recalculate layout but we don't want to change the dropped rectangle
310 * So, we pass the height of text area of control as the height.
311 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
314 SetWindowPos( lphc->self,
317 windowRect.right - windowRect.left,
319 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
322 /***********************************************************************
325 * Set up component coordinates given valid lphc->RectCombo.
327 static void CBCalcPlacement(
335 * Again, start with the client rectangle.
337 GetClientRect(hwnd, lprEdit);
342 InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
345 * Chop off the bottom part to fit with the height of the text area.
347 lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
350 * The button starts the same vertical position as the text area.
352 CopyRect(lprButton, lprEdit);
355 * If the combobox is "simple" there is no button.
357 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
358 lprButton->left = lprButton->right = lprButton->bottom = 0;
362 * Let's assume the combobox button is the same width as the
364 * size the button horizontally and cut-off the text area.
366 lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
367 lprEdit->right = lprButton->left;
371 * In the case of a dropdown, there is an additional spacing between the
372 * text area and the button.
374 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
376 lprEdit->right -= COMBO_EDITBUTTONSPACE();
380 * If we have an edit control, we space it away from the borders slightly.
382 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
384 InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
388 * Adjust the size of the listbox popup.
390 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
393 * Use the client rectangle to initialize the listbox rectangle
395 GetClientRect(hwnd, lprLB);
398 * Then, chop-off the top part.
400 lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
405 * Make sure the dropped width is as large as the combobox itself.
407 if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
409 lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
412 * In the case of a dropdown, the popup listbox is offset to the right.
413 * so, we want to make sure it's flush with the right side of the
416 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
417 lprLB->right -= COMBO_EDITBUTTONSPACE();
420 lprLB->right = lprLB->left + lphc->droppedWidth;
423 TRACE("\ttext\t= (%i,%i-%i,%i)\n",
424 lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom);
426 TRACE("\tbutton\t= (%i,%i-%i,%i)\n",
427 lprButton->left, lprButton->top, lprButton->right, lprButton->bottom);
429 TRACE("\tlbox\t= (%i,%i-%i,%i)\n",
430 lprLB->left, lprLB->top, lprLB->right, lprLB->bottom );
433 /***********************************************************************
434 * CBGetDroppedControlRect
436 static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect)
438 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
439 of the combo box and the lower right corner of the listbox */
441 GetWindowRect(lphc->self, lpRect);
443 lpRect->right = lpRect->left + lphc->droppedRect.right - lphc->droppedRect.left;
444 lpRect->bottom = lpRect->top + lphc->droppedRect.bottom - lphc->droppedRect.top;
448 /***********************************************************************
449 * COMBO_WindowPosChanging
451 static LRESULT COMBO_WindowPosChanging(
454 WINDOWPOS* posChanging)
457 * We need to override the WM_WINDOWPOSCHANGING method to handle all
458 * the non-simple comboboxes. The problem is that those controls are
459 * always the same height. We have to make sure they are not resized
462 if ( ( CB_GETTYPE(lphc) != CBS_SIMPLE ) &&
463 ((posChanging->flags & SWP_NOSIZE) == 0) )
467 newComboHeight = CBGetTextAreaHeight(hwnd,lphc) +
468 2*COMBO_YBORDERSIZE();
471 * Resizing a combobox has another side effect, it resizes the dropped
472 * rectangle as well. However, it does it only if the new height for the
473 * combobox is different from the height it should have. In other words,
474 * if the application resizing the combobox only had the intention to resize
475 * the actual control, for example, to do the layout of a dialog that is
476 * resized, the height of the dropdown is not changed.
478 if (posChanging->cy != newComboHeight)
480 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%d, oldtop=%d\n",
481 posChanging->cy, newComboHeight, lphc->droppedRect.bottom,
482 lphc->droppedRect.top);
483 lphc->droppedRect.bottom = lphc->droppedRect.top + posChanging->cy - newComboHeight;
485 posChanging->cy = newComboHeight;
492 /***********************************************************************
495 static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style,
498 static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0};
499 static const WCHAR editName[] = {'E','d','i','t',0};
501 if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE;
502 if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT;
504 lphc->owner = hwndParent;
507 * The item height and dropped width are not set when the control
510 lphc->droppedWidth = lphc->editHeight = 0;
513 * The first time we go through, we want to measure the ownerdraw item
515 lphc->wState |= CBF_MEASUREITEM;
517 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
519 if( lphc->owner || !(style & WS_VISIBLE) )
525 * Initialize the dropped rect to the size of the client area of the
526 * control and then, force all the areas of the combobox to be
529 GetClientRect( hwnd, &lphc->droppedRect );
530 CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
533 * Adjust the position of the popup listbox if it's necessary
535 if ( CB_GETTYPE(lphc) != CBS_SIMPLE )
537 lphc->droppedRect.top = lphc->textRect.bottom + COMBO_YBORDERSIZE();
540 * If it's a dropdown, the listbox is offset
542 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
543 lphc->droppedRect.left += COMBO_EDITBUTTONSPACE();
545 ClientToScreen(hwnd, (LPPOINT)&lphc->droppedRect);
546 ClientToScreen(hwnd, (LPPOINT)&lphc->droppedRect.right);
549 /* create listbox popup */
551 lbeStyle = (LBS_NOTIFY | WS_BORDER | WS_CLIPSIBLINGS | WS_CHILD) |
552 (style & (WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE));
554 if( lphc->dwStyle & CBS_SORT )
555 lbeStyle |= LBS_SORT;
556 if( lphc->dwStyle & CBS_HASSTRINGS )
557 lbeStyle |= LBS_HASSTRINGS;
558 if( lphc->dwStyle & CBS_NOINTEGRALHEIGHT )
559 lbeStyle |= LBS_NOINTEGRALHEIGHT;
560 if( lphc->dwStyle & CBS_DISABLENOSCROLL )
561 lbeStyle |= LBS_DISABLENOSCROLL;
563 if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* child listbox */
565 lbeStyle |= WS_VISIBLE;
568 * In win 95 look n feel, the listbox in the simple combobox has
569 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
571 if (TWEAK_WineLook > WIN31_LOOK)
573 lbeStyle &= ~WS_BORDER;
574 lbeExStyle |= WS_EX_CLIENTEDGE;
579 lphc->hWndLBox = CreateWindowExW(lbeExStyle, clbName, NULL, lbeStyle,
580 lphc->droppedRect.left,
581 lphc->droppedRect.top,
582 lphc->droppedRect.right - lphc->droppedRect.left,
583 lphc->droppedRect.bottom - lphc->droppedRect.top,
584 hwnd, (HMENU)ID_CB_LISTBOX,
585 GetWindowLongA( hwnd, GWL_HINSTANCE ), lphc );
587 lphc->hWndLBox = CreateWindowExA(lbeExStyle, "ComboLBox", NULL, lbeStyle,
588 lphc->droppedRect.left,
589 lphc->droppedRect.top,
590 lphc->droppedRect.right - lphc->droppedRect.left,
591 lphc->droppedRect.bottom - lphc->droppedRect.top,
592 hwnd, (HMENU)ID_CB_LISTBOX,
593 GetWindowLongA( hwnd, GWL_HINSTANCE ), lphc );
598 lbeStyle = WS_CHILD | WS_VISIBLE | ES_NOHIDESEL | ES_LEFT | ES_COMBO;
601 * In Win95 look, the border fo the edit control is
602 * provided by the combobox
604 if (TWEAK_WineLook == WIN31_LOOK)
605 lbeStyle |= WS_BORDER;
607 if( lphc->wState & CBF_EDIT )
609 if( lphc->dwStyle & CBS_OEMCONVERT )
610 lbeStyle |= ES_OEMCONVERT;
611 if( lphc->dwStyle & CBS_AUTOHSCROLL )
612 lbeStyle |= ES_AUTOHSCROLL;
613 if( lphc->dwStyle & CBS_LOWERCASE )
614 lbeStyle |= ES_LOWERCASE;
615 else if( lphc->dwStyle & CBS_UPPERCASE )
616 lbeStyle |= ES_UPPERCASE;
618 if (!IsWindowEnabled(hwnd)) lbeStyle |= WS_DISABLED;
621 lphc->hWndEdit = CreateWindowExW(0, editName, NULL, lbeStyle,
622 lphc->textRect.left, lphc->textRect.top,
623 lphc->textRect.right - lphc->textRect.left,
624 lphc->textRect.bottom - lphc->textRect.top,
625 hwnd, (HMENU)ID_CB_EDIT,
626 GetWindowLongA( hwnd, GWL_HINSTANCE ), NULL );
628 lphc->hWndEdit = CreateWindowExA(0, "Edit", NULL, lbeStyle,
629 lphc->textRect.left, lphc->textRect.top,
630 lphc->textRect.right - lphc->textRect.left,
631 lphc->textRect.bottom - lphc->textRect.top,
632 hwnd, (HMENU)ID_CB_EDIT,
633 GetWindowLongA( hwnd, GWL_HINSTANCE ), NULL );
635 if( !lphc->hWndEdit )
641 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
643 /* Now do the trick with parent */
644 SetParent(lphc->hWndLBox, HWND_DESKTOP);
646 * If the combo is a dropdown, we must resize the control
647 * to fit only the text area and button. To do this,
648 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
649 * will take care of setting the height for us.
651 CBForceDummyResize(lphc);
654 TRACE("init done\n");
657 ERR("edit control failure.\n");
658 } else ERR("listbox failure.\n");
659 } else ERR("no owner for visible combo.\n");
661 /* CreateWindow() will send WM_NCDESTROY to cleanup */
666 /***********************************************************************
669 * Paint combo button (normal, pressed, and disabled states).
671 static void CBPaintButton(
676 if( lphc->wState & CBF_NOREDRAW )
679 if (TWEAK_WineLook == WIN31_LOOK)
685 COLORREF oldTextColor, oldBkColor;
688 hPrevBrush = SelectObject(hdc, GetSysColorBrush(COLOR_BTNFACE));
691 * Draw the button background
696 rectButton.right-rectButton.left,
697 rectButton.bottom-rectButton.top,
700 if( (bBool = lphc->wState & CBF_BUTTONDOWN) )
702 DrawEdge( hdc, &rectButton, EDGE_SUNKEN, BF_RECT );
706 DrawEdge( hdc, &rectButton, EDGE_RAISED, BF_RECT );
710 * Remove the edge of the button from the rectangle
711 * and calculate the position of the bitmap.
713 InflateRect( &rectButton, -2, -2);
715 x = (rectButton.left + rectButton.right - CBitWidth) >> 1;
716 y = (rectButton.top + rectButton.bottom - CBitHeight) >> 1;
719 hMemDC = CreateCompatibleDC( hdc );
720 SelectObject( hMemDC, hComboBmp );
721 oldTextColor = SetTextColor( hdc, GetSysColor(COLOR_BTNFACE) );
722 oldBkColor = SetBkColor( hdc, CB_DISABLED(lphc) ? RGB(128,128,128) :
724 BitBlt( hdc, x, y, CBitWidth, CBitHeight, hMemDC, 0, 0, SRCCOPY );
725 SetBkColor( hdc, oldBkColor );
726 SetTextColor( hdc, oldTextColor );
728 SelectObject( hdc, hPrevBrush );
732 UINT buttonState = DFCS_SCROLLCOMBOBOX;
734 if (lphc->wState & CBF_BUTTONDOWN)
736 buttonState |= DFCS_PUSHED;
739 if (CB_DISABLED(lphc))
741 buttonState |= DFCS_INACTIVE;
744 DrawFrameControl(hdc,
751 /***********************************************************************
754 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
756 static void CBPaintText(
764 if( lphc->wState & CBF_NOREDRAW ) return;
768 /* follow Windows combobox that sends a bunch of text
769 * inquiries to its listbox while processing WM_PAINT. */
771 if( (id = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0) ) != LB_ERR )
773 size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0);
775 FIXME("LB_ERR probably not handled yet\n");
776 if( (pText = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))) )
778 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
779 size=SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText);
780 pText[size] = '\0'; /* just in case */
784 if( !CB_OWNERDRAWN(lphc) )
787 if( lphc->wState & CBF_EDIT )
789 static const WCHAR empty_stringW[] = { 0 };
790 if( CB_HASSTRINGS(lphc) ) SetWindowTextW( lphc->hWndEdit, pText ? pText : empty_stringW );
791 if( lphc->wState & CBF_FOCUSED )
792 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
794 else /* paint text field ourselves */
796 UINT itemState = ODS_COMBOBOXEDIT;
797 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hdc, lphc->hFont) : 0;
800 * Give ourselves some space.
802 InflateRect( &rectEdit, -1, -1 );
804 if( CB_OWNERDRAWN(lphc) )
808 UINT ctlid = GetWindowLongA( lphc->self, GWL_ID );
810 /* setup state for DRAWITEM message. Owner will highlight */
811 if ( (lphc->wState & CBF_FOCUSED) &&
812 !(lphc->wState & CBF_DROPPED) )
813 itemState |= ODS_SELECTED | ODS_FOCUS;
816 * Save the current clip region.
817 * To retrieve the clip region, we need to create one "dummy"
820 clipRegion = CreateRectRgnIndirect(&rectEdit);
822 if (GetClipRgn(hdc, clipRegion)!=1)
824 DeleteObject(clipRegion);
825 clipRegion=(HRGN)NULL;
828 if (!IsWindowEnabled(lphc->self) & WS_DISABLED) itemState |= ODS_DISABLED;
830 dis.CtlType = ODT_COMBOBOX;
832 dis.hwndItem = lphc->self;
833 dis.itemAction = ODA_DRAWENTIRE;
835 dis.itemState = itemState;
837 dis.rcItem = rectEdit;
838 dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA,
842 * Clip the DC and have the parent draw the item.
844 IntersectClipRect(hdc,
845 rectEdit.left, rectEdit.top,
846 rectEdit.right, rectEdit.bottom);
848 SendMessageW(lphc->owner, WM_DRAWITEM, ctlid, (LPARAM)&dis );
851 * Reset the clipping region.
853 SelectClipRgn(hdc, clipRegion);
857 static const WCHAR empty_stringW[] = { 0 };
859 if ( (lphc->wState & CBF_FOCUSED) &&
860 !(lphc->wState & CBF_DROPPED) ) {
863 FillRect( hdc, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) );
864 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
865 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
871 ETO_OPAQUE | ETO_CLIPPED,
873 pText ? pText : empty_stringW , size, NULL );
875 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED))
876 DrawFocusRect( hdc, &rectEdit );
880 SelectObject(hdc, hPrevFont );
883 HeapFree( GetProcessHeap(), 0, pText );
886 /***********************************************************************
889 static void CBPaintBorder(
896 if (CB_GETTYPE(lphc) != CBS_SIMPLE)
898 GetClientRect(hwnd, &clientRect);
902 CopyRect(&clientRect, &lphc->textRect);
904 InflateRect(&clientRect, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
905 InflateRect(&clientRect, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
908 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_RECT);
911 /***********************************************************************
912 * COMBO_PrepareColors
914 * This method will sent the appropriate WM_CTLCOLOR message to
915 * prepare and setup the colors for the combo's DC.
917 * It also returns the brush to use for the background.
919 static HBRUSH COMBO_PrepareColors(
926 * Get the background brush for this control.
928 if (CB_DISABLED(lphc))
930 hBkgBrush = SendMessageW(lphc->owner, WM_CTLCOLORSTATIC, hDC, (LPARAM)lphc->self );
933 * We have to change the text color since WM_CTLCOLORSTATIC will
934 * set it to the "enabled" color. This is the same behavior as the
937 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
941 if (lphc->wState & CBF_EDIT)
943 hBkgBrush = SendMessageW(lphc->owner, WM_CTLCOLOREDIT, hDC, (LPARAM)lphc->self );
947 hBkgBrush = SendMessageW(lphc->owner, WM_CTLCOLORLISTBOX, hDC, (LPARAM)lphc->self );
955 hBkgBrush = GetSysColorBrush(COLOR_WINDOW);
960 /***********************************************************************
961 * COMBO_EraseBackground
963 static LRESULT COMBO_EraseBackground(
971 if(lphc->wState & CBF_EDIT)
974 hDC = (hParamDC) ? hParamDC
977 * Retrieve the background brush
979 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
981 FillRect(hDC, &lphc->textRect, hBkgBrush);
984 ReleaseDC(hwnd, hDC);
989 /***********************************************************************
992 static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC)
997 hDC = (hParamDC) ? hParamDC
998 : BeginPaint( lphc->self, &ps);
1000 TRACE("hdc=%04x\n", hDC);
1002 if( hDC && !(lphc->wState & CBF_NOREDRAW) )
1004 HBRUSH hPrevBrush, hBkgBrush;
1007 * Retrieve the background brush and select it in the
1010 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
1012 hPrevBrush = SelectObject( hDC, hBkgBrush );
1015 * In non 3.1 look, there is a sunken border on the combobox
1017 if (TWEAK_WineLook != WIN31_LOOK)
1019 CBPaintBorder(lphc->self, lphc, hDC);
1022 if( !IsRectEmpty(&lphc->buttonRect) )
1024 CBPaintButton(lphc, hDC, lphc->buttonRect);
1027 /* paint the edit control padding area */
1028 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
1030 RECT rPadEdit = lphc->textRect;
1032 InflateRect(&rPadEdit, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
1034 FrameRect( hDC, &rPadEdit, GetSysColorBrush(COLOR_WINDOW) );
1037 if( !(lphc->wState & CBF_EDIT) )
1040 * The text area has a border only in Win 3.1 look.
1042 if (TWEAK_WineLook == WIN31_LOOK)
1044 HPEN hPrevPen = SelectObject( hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME) );
1047 lphc->textRect.left, lphc->textRect.top,
1048 lphc->textRect.right - 1, lphc->textRect.bottom - 1);
1050 SelectObject( hDC, hPrevPen );
1053 CBPaintText( lphc, hDC, lphc->textRect);
1057 SelectObject( hDC, hPrevBrush );
1061 EndPaint(lphc->self, &ps);
1066 /***********************************************************************
1069 * Select listbox entry according to the contents of the edit control.
1071 static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
1074 LPWSTR pText = NULL;
1077 length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 );
1080 pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1082 TRACE("\t edit text length %i\n", length );
1086 if( length ) GetWindowTextW( lphc->hWndEdit, pText, length + 1);
1087 else pText[0] = '\0';
1088 idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING,
1089 (WPARAM)(-1), (LPARAM)pText );
1090 HeapFree( GetProcessHeap(), 0, pText );
1093 SendMessageW(lphc->hWndLBox, LB_SETCURSEL, (WPARAM)(bSelect ? idx : -1), 0);
1095 /* probably superfluous but Windows sends this too */
1096 SendMessageW(lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1097 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1102 /***********************************************************************
1105 * Copy a listbox entry to the edit control.
1107 static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
1110 LPWSTR pText = NULL;
1111 static const WCHAR empty_stringW[] = { 0 };
1113 TRACE("\t %i\n", index );
1115 if( index >= 0 ) /* got an entry */
1117 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0);
1118 if( length != LB_ERR)
1120 if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) )
1122 SendMessageW(lphc->hWndLBox, LB_GETTEXT,
1123 (WPARAM)index, (LPARAM)pText );
1128 lphc->wState |= (CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1129 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, pText ? (LPARAM)pText : (LPARAM)empty_stringW);
1130 lphc->wState &= ~(CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1132 if( lphc->wState & CBF_FOCUSED )
1133 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1136 HeapFree( GetProcessHeap(), 0, pText );
1139 /***********************************************************************
1142 * Show listbox popup.
1144 static void CBDropDown( LPHEADCOMBO lphc )
1150 TRACE("[%04x]: drop down\n", lphc->self);
1152 CB_NOTIFY( lphc, CBN_DROPDOWN );
1156 lphc->wState |= CBF_DROPPED;
1157 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1159 lphc->droppedIndex = CBUpdateLBox( lphc, TRUE );
1161 /* Update edit only if item is in the list */
1162 if( !(lphc->wState & CBF_CAPTURE) && lphc->droppedIndex >= 0)
1163 CBUpdateEdit( lphc, lphc->droppedIndex );
1167 lphc->droppedIndex = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1169 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX,
1170 (WPARAM)(lphc->droppedIndex == LB_ERR ? 0 : lphc->droppedIndex), 0 );
1171 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1174 /* now set popup position */
1175 GetWindowRect( lphc->self, &rect );
1178 * If it's a dropdown, the listbox is offset
1180 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1181 rect.left += COMBO_EDITBUTTONSPACE();
1183 /* if the dropped height is greater than the total height of the dropped
1184 items list, then force the drop down list height to be the total height
1185 of the items in the dropped list */
1187 /* And Remove any extra space (Best Fit) */
1188 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
1189 /* if listbox length has been set directly by its handle */
1190 GetWindowRect(lphc->hWndLBox, &r);
1191 if (nDroppedHeight < r.bottom - r.top)
1192 nDroppedHeight = r.bottom - r.top;
1193 nItems = (int)SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
1199 nHeight = (int)SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, 0, 0);
1202 if (nHeight < nDroppedHeight - COMBO_YBORDERSIZE())
1203 nDroppedHeight = nHeight + COMBO_YBORDERSIZE();
1206 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1207 if( (rect.bottom + nDroppedHeight) >= GetSystemMetrics( SM_CYSCREEN ) )
1208 rect.bottom = rect.top - nDroppedHeight;
1210 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
1211 lphc->droppedRect.right - lphc->droppedRect.left,
1213 SWP_NOACTIVATE | SWP_SHOWWINDOW);
1216 if( !(lphc->wState & CBF_NOREDRAW) )
1217 RedrawWindow( lphc->self, NULL, 0, RDW_INVALIDATE |
1218 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1220 EnableWindow( lphc->hWndLBox, TRUE );
1221 if (GetCapture() != lphc->self)
1222 SetCapture(lphc->hWndLBox);
1225 /***********************************************************************
1228 * Hide listbox popup.
1230 static void CBRollUp( LPHEADCOMBO lphc, BOOL ok, BOOL bButton )
1232 HWND hWnd = lphc->self;
1234 TRACE("[%04x]: sel ok? [%i] dropped? [%i]\n",
1235 lphc->self, (INT)ok, (INT)(lphc->wState & CBF_DROPPED));
1237 CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL );
1239 if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE )
1242 if( lphc->wState & CBF_DROPPED )
1246 lphc->wState &= ~CBF_DROPPED;
1247 ShowWindow( lphc->hWndLBox, SW_HIDE );
1249 if(GetCapture() == lphc->hWndLBox)
1254 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1256 rect = lphc->buttonRect;
1267 rect = lphc->textRect;
1272 if( bButton && !(lphc->wState & CBF_NOREDRAW) )
1273 RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE |
1274 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1275 CB_NOTIFY( lphc, CBN_CLOSEUP );
1280 /***********************************************************************
1283 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1285 BOOL COMBO_FlipListbox( LPHEADCOMBO lphc, BOOL ok, BOOL bRedrawButton )
1287 if( lphc->wState & CBF_DROPPED )
1289 CBRollUp( lphc, ok, bRedrawButton );
1297 /***********************************************************************
1300 static void CBRepaintButton( LPHEADCOMBO lphc )
1302 InvalidateRect(lphc->self, &lphc->buttonRect, TRUE);
1303 UpdateWindow(lphc->self);
1306 /***********************************************************************
1309 static void COMBO_SetFocus( LPHEADCOMBO lphc )
1311 if( !(lphc->wState & CBF_FOCUSED) )
1313 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1314 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1316 /* This is wrong. Message sequences seem to indicate that this
1317 is set *after* the notify. */
1318 /* lphc->wState |= CBF_FOCUSED; */
1320 if( !(lphc->wState & CBF_EDIT) )
1321 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1323 CB_NOTIFY( lphc, CBN_SETFOCUS );
1324 lphc->wState |= CBF_FOCUSED;
1328 /***********************************************************************
1331 static void COMBO_KillFocus( LPHEADCOMBO lphc )
1333 HWND hWnd = lphc->self;
1335 if( lphc->wState & CBF_FOCUSED )
1337 CBRollUp( lphc, FALSE, TRUE );
1338 if( IsWindow( hWnd ) )
1340 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1341 SendMessageW(lphc->hWndLBox, LB_CARETOFF, 0, 0);
1343 lphc->wState &= ~CBF_FOCUSED;
1346 if( !(lphc->wState & CBF_EDIT) )
1347 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1349 CB_NOTIFY( lphc, CBN_KILLFOCUS );
1354 /***********************************************************************
1357 static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd )
1359 if ( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd )
1361 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1363 switch( HIWORD(wParam) >> 8 )
1365 case (EN_SETFOCUS >> 8):
1367 TRACE("[%04x]: edit [%04x] got focus\n",
1368 lphc->self, lphc->hWndEdit );
1370 COMBO_SetFocus( lphc );
1373 case (EN_KILLFOCUS >> 8):
1375 TRACE("[%04x]: edit [%04x] lost focus\n",
1376 lphc->self, lphc->hWndEdit );
1378 /* NOTE: it seems that Windows' edit control sends an
1379 * undocumented message WM_USER + 0x1B instead of this
1380 * notification (only when it happens to be a part of
1381 * the combo). ?? - AK.
1384 COMBO_KillFocus( lphc );
1388 case (EN_CHANGE >> 8):
1390 * In some circumstances (when the selection of the combobox
1391 * is changed for example) we don't wans the EN_CHANGE notification
1392 * to be forwarded to the parent of the combobox. This code
1393 * checks a flag that is set in these occasions and ignores the
1396 if (lphc->wState & CBF_NOLBSELECT)
1398 lphc->wState &= ~CBF_NOLBSELECT;
1402 CBUpdateLBox( lphc, lphc->wState & CBF_DROPPED );
1405 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1406 CB_NOTIFY( lphc, CBN_EDITCHANGE );
1409 case (EN_UPDATE >> 8):
1410 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1411 CB_NOTIFY( lphc, CBN_EDITUPDATE );
1414 case (EN_ERRSPACE >> 8):
1415 CB_NOTIFY( lphc, CBN_ERRSPACE );
1418 else if( lphc->hWndLBox == hWnd )
1420 switch( HIWORD(wParam) )
1423 CB_NOTIFY( lphc, CBN_ERRSPACE );
1427 CB_NOTIFY( lphc, CBN_DBLCLK );
1433 TRACE("[%04x]: lbox selection change [%04x]\n",
1434 lphc->self, lphc->wState );
1436 if( HIWORD(wParam) == LBN_SELCHANGE)
1438 if( lphc->wState & CBF_EDIT )
1440 INT index = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1441 lphc->wState |= CBF_NOLBSELECT;
1442 CBUpdateEdit( lphc, index );
1443 /* select text in edit, as Windows does */
1444 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1447 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1450 /* do not roll up if selection is being tracked
1451 * by arrowkeys in the dropdown listbox */
1452 if( ((lphc->wState & CBF_DROPPED) && !(lphc->wState & CBF_NOROLLUP)) )
1454 CBRollUp( lphc, (HIWORD(wParam) == LBN_SELCHANGE), TRUE );
1456 else lphc->wState &= ~CBF_NOROLLUP;
1458 CB_NOTIFY( lphc, CBN_SELCHANGE );
1464 /* nothing to do here since ComboLBox always resets the focus to its
1465 * combo/edit counterpart */
1472 /***********************************************************************
1475 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1477 static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
1479 HWND hWnd = lphc->self;
1480 UINT id = GetWindowLongA( hWnd, GWL_ID );
1482 TRACE("[%04x]: ownerdraw op %04x\n", lphc->self, msg );
1488 DELETEITEMSTRUCT *lpIS = (DELETEITEMSTRUCT *)lParam;
1489 lpIS->CtlType = ODT_COMBOBOX;
1491 lpIS->hwndItem = hWnd;
1496 DRAWITEMSTRUCT *lpIS = (DRAWITEMSTRUCT *)lParam;
1497 lpIS->CtlType = ODT_COMBOBOX;
1499 lpIS->hwndItem = hWnd;
1502 case WM_COMPAREITEM:
1504 COMPAREITEMSTRUCT *lpIS = (COMPAREITEMSTRUCT *)lParam;
1505 lpIS->CtlType = ODT_COMBOBOX;
1507 lpIS->hwndItem = hWnd;
1510 case WM_MEASUREITEM:
1512 MEASUREITEMSTRUCT *lpIS = (MEASUREITEMSTRUCT *)lParam;
1513 lpIS->CtlType = ODT_COMBOBOX;
1518 return SendMessageW(lphc->owner, msg, id, lParam);
1521 /***********************************************************************
1524 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1525 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1527 static LRESULT COMBO_GetText( LPHEADCOMBO lphc, INT N, LPARAM lParam, BOOL unicode)
1529 if( lphc->wState & CBF_EDIT )
1530 return unicode ? SendMessageW(lphc->hWndEdit, WM_GETTEXT, (WPARAM)N, lParam) :
1531 SendMessageA(lphc->hWndEdit, WM_GETTEXT, (WPARAM)N, lParam);
1533 /* get it from the listbox */
1535 if( lphc->hWndLBox )
1537 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1541 INT length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN,
1543 if(length == LB_ERR)
1544 FIXME("LB_ERR probably not handled yet\n");
1547 LPWSTR lpBuffer, lpText = (LPWSTR)lParam;
1549 /* 'length' is without the terminating character */
1551 lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1557 n = SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)idx, (LPARAM)lpBuffer);
1559 /* truncate if buffer is too short */
1565 strncpyW(lpText, lpBuffer, (N > n) ? n+1 : N-1);
1566 lpText[N - 1] = '\0';
1568 HeapFree( GetProcessHeap(), 0, lpBuffer );
1574 LPSTR lpBuffer, lpText = (LPSTR)lParam;
1576 /* 'length' is without the terminating character */
1578 lpBuffer = HeapAlloc(GetProcessHeap(), 0, length + 1);
1584 n = SendMessageA(lphc->hWndLBox, LB_GETTEXT, (WPARAM)idx, (LPARAM)lpBuffer);
1586 /* truncate if buffer is too short */
1592 strncpy(lpText, lpBuffer, (N > n) ? n+1 : N-1);
1593 lpText[N - 1] = '\0';
1595 HeapFree( GetProcessHeap(), 0, lpBuffer );
1610 /***********************************************************************
1613 * This function sets window positions according to the updated
1614 * component placement struct.
1616 static void CBResetPos(
1622 BOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE);
1624 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1625 * sizing messages */
1627 if( lphc->wState & CBF_EDIT )
1628 SetWindowPos( lphc->hWndEdit, 0,
1629 rectEdit->left, rectEdit->top,
1630 rectEdit->right - rectEdit->left,
1631 rectEdit->bottom - rectEdit->top,
1632 SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) );
1634 SetWindowPos( lphc->hWndLBox, 0,
1635 rectLB->left, rectLB->top,
1636 rectLB->right - rectLB->left,
1637 rectLB->bottom - rectLB->top,
1638 SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) );
1642 if( lphc->wState & CBF_DROPPED )
1644 lphc->wState &= ~CBF_DROPPED;
1645 ShowWindow( lphc->hWndLBox, SW_HIDE );
1648 if( bRedraw && !(lphc->wState & CBF_NOREDRAW) )
1649 RedrawWindow( lphc->self, NULL, 0,
1650 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
1655 /***********************************************************************
1658 static void COMBO_Size( LPHEADCOMBO lphc )
1660 CBCalcPlacement(lphc->self,
1664 &lphc->droppedRect);
1666 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1670 /***********************************************************************
1673 static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
1678 lphc->hFont = hFont;
1681 * Propagate to owned windows.
1683 if( lphc->wState & CBF_EDIT )
1684 SendMessageW(lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw);
1685 SendMessageW(lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw);
1688 * Redo the layout of the control.
1690 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1692 CBCalcPlacement(lphc->self,
1696 &lphc->droppedRect);
1698 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1702 CBForceDummyResize(lphc);
1707 /***********************************************************************
1708 * COMBO_SetItemHeight
1710 static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
1712 LRESULT lRet = CB_ERR;
1714 if( index == -1 ) /* set text field height */
1716 if( height < 32768 )
1718 lphc->editHeight = height;
1721 * Redo the layout of the control.
1723 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1725 CBCalcPlacement(lphc->self,
1729 &lphc->droppedRect);
1731 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1735 CBForceDummyResize(lphc);
1741 else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */
1742 lRet = SendMessageW(lphc->hWndLBox, LB_SETITEMHEIGHT,
1743 (WPARAM)index, (LPARAM)height );
1747 /***********************************************************************
1748 * COMBO_SelectString
1750 static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPARAM pText, BOOL unicode )
1752 INT index = unicode ? SendMessageW(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText) :
1753 SendMessageA(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText);
1756 if( lphc->wState & CBF_EDIT )
1757 CBUpdateEdit( lphc, index );
1760 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1763 return (LRESULT)index;
1766 /***********************************************************************
1769 static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam )
1773 HWND hWnd = lphc->self;
1775 pt.x = LOWORD(lParam);
1776 pt.y = HIWORD(lParam);
1777 bButton = PtInRect(&lphc->buttonRect, pt);
1779 if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) ||
1780 (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) )
1782 lphc->wState |= CBF_BUTTONDOWN;
1783 if( lphc->wState & CBF_DROPPED )
1785 /* got a click to cancel selection */
1787 lphc->wState &= ~CBF_BUTTONDOWN;
1788 CBRollUp( lphc, TRUE, FALSE );
1789 if( !IsWindow( hWnd ) ) return;
1791 if( lphc->wState & CBF_CAPTURE )
1793 lphc->wState &= ~CBF_CAPTURE;
1799 /* drop down the listbox and start tracking */
1801 lphc->wState |= CBF_CAPTURE;
1805 if( bButton ) CBRepaintButton( lphc );
1809 /***********************************************************************
1812 * Release capture and stop tracking if needed.
1814 static void COMBO_LButtonUp( LPHEADCOMBO lphc )
1816 if( lphc->wState & CBF_CAPTURE )
1818 lphc->wState &= ~CBF_CAPTURE;
1819 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1821 INT index = CBUpdateLBox( lphc, TRUE );
1822 /* Update edit only if item is in the list */
1825 lphc->wState |= CBF_NOLBSELECT;
1826 CBUpdateEdit( lphc, index );
1827 lphc->wState &= ~CBF_NOLBSELECT;
1831 SetCapture(lphc->hWndLBox);
1834 if( lphc->wState & CBF_BUTTONDOWN )
1836 lphc->wState &= ~CBF_BUTTONDOWN;
1837 CBRepaintButton( lphc );
1841 /***********************************************************************
1844 * Two things to do - track combo button and release capture when
1845 * pointer goes into the listbox.
1847 static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam )
1852 pt.x = LOWORD(lParam);
1853 pt.y = HIWORD(lParam);
1855 if( lphc->wState & CBF_BUTTONDOWN )
1859 bButton = PtInRect(&lphc->buttonRect, pt);
1863 lphc->wState &= ~CBF_BUTTONDOWN;
1864 CBRepaintButton( lphc );
1868 GetClientRect( lphc->hWndLBox, &lbRect );
1869 MapWindowPoints( lphc->self, lphc->hWndLBox, &pt, 1 );
1870 if( PtInRect(&lbRect, pt) )
1872 lphc->wState &= ~CBF_CAPTURE;
1874 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc, TRUE );
1876 /* hand over pointer tracking */
1877 SendMessageW(lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam);
1882 /***********************************************************************
1883 * ComboWndProc_common
1885 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1887 static LRESULT ComboWndProc_common( HWND hwnd, UINT message,
1888 WPARAM wParam, LPARAM lParam, BOOL unicode )
1890 LPHEADCOMBO lphc = (LPHEADCOMBO)GetWindowLongA( hwnd, 0 );
1892 TRACE("[%04x]: msg %s wp %08x lp %08lx\n",
1893 hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1895 if( lphc || message == WM_NCCREATE )
1899 /* System messages */
1903 LONG style = unicode ? ((LPCREATESTRUCTW)lParam)->style :
1904 ((LPCREATESTRUCTA)lParam)->style;
1905 return COMBO_NCCreate(hwnd, style);
1908 COMBO_NCDestroy(lphc);
1909 break;/* -> DefWindowProc */
1917 hwndParent = ((LPCREATESTRUCTW)lParam)->hwndParent;
1918 style = ((LPCREATESTRUCTW)lParam)->style;
1922 hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent;
1923 style = ((LPCREATESTRUCTA)lParam)->style;
1925 return COMBO_Create(hwnd, lphc, hwndParent, style, unicode);
1928 case WM_PRINTCLIENT:
1929 if (lParam & PRF_ERASEBKGND)
1930 COMBO_EraseBackground(hwnd, lphc, wParam);
1934 /* wParam may contain a valid HDC! */
1935 return COMBO_Paint(lphc, wParam);
1937 return COMBO_EraseBackground(hwnd, lphc, wParam);
1940 LRESULT result = DLGC_WANTARROWS | DLGC_WANTCHARS;
1941 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1943 int vk = (int)((LPMSG)lParam)->wParam;
1945 if ((vk == VK_RETURN || vk == VK_ESCAPE) && (lphc->wState & CBF_DROPPED))
1946 result |= DLGC_WANTMESSAGE;
1950 case WM_WINDOWPOSCHANGING:
1951 return COMBO_WindowPosChanging(hwnd, lphc, (LPWINDOWPOS)lParam);
1952 case WM_WINDOWPOSCHANGED:
1953 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1954 * In that case, the Combobox itself will not be resized, so we won't
1955 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1960 if( lphc->hWndLBox &&
1961 !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc );
1964 COMBO_Font( lphc, (HFONT16)wParam, (BOOL)lParam );
1967 return (LRESULT)lphc->hFont;
1969 if( lphc->wState & CBF_EDIT )
1970 SetFocus( lphc->hWndEdit );
1972 COMBO_SetFocus( lphc );
1976 HWND hwndFocus = WIN_GetFullHandle( (HWND)wParam );
1978 (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox ))
1979 COMBO_KillFocus( lphc );
1983 return COMBO_Command( lphc, wParam, WIN_GetFullHandle( (HWND)lParam ) );
1985 return COMBO_GetText( lphc, (INT)wParam, lParam, unicode );
1987 case WM_GETTEXTLENGTH:
1989 if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT))
1991 int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1992 if (j == -1) return 0;
1993 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0) :
1994 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, j, 0);
1996 else if( lphc->wState & CBF_EDIT )
1999 lphc->wState |= CBF_NOEDITNOTIFY;
2000 ret = unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
2001 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
2002 lphc->wState &= ~CBF_NOEDITNOTIFY;
2009 if( lphc->wState & CBF_EDIT )
2011 return unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
2012 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
2018 case WM_COMPAREITEM:
2019 case WM_MEASUREITEM:
2020 return COMBO_ItemOp(lphc, message, lParam);
2022 if( lphc->wState & CBF_EDIT )
2023 EnableWindow( lphc->hWndEdit, (BOOL)wParam );
2024 EnableWindow( lphc->hWndLBox, (BOOL)wParam );
2026 /* Force the control to repaint when the enabled state changes. */
2027 InvalidateRect(lphc->self, NULL, TRUE);
2031 lphc->wState &= ~CBF_NOREDRAW;
2033 lphc->wState |= CBF_NOREDRAW;
2035 if( lphc->wState & CBF_EDIT )
2036 SendMessageW(lphc->hWndEdit, message, wParam, lParam);
2037 SendMessageW(lphc->hWndLBox, message, wParam, lParam);
2040 if( KEYDATA_ALT & HIWORD(lParam) )
2041 if( wParam == VK_UP || wParam == VK_DOWN )
2042 COMBO_FlipListbox( lphc, FALSE, FALSE );
2050 if ((wParam == VK_RETURN || wParam == VK_ESCAPE) &&
2051 (lphc->wState & CBF_DROPPED))
2053 CBRollUp( lphc, wParam == VK_RETURN, FALSE );
2057 if( lphc->wState & CBF_EDIT )
2058 hwndTarget = lphc->hWndEdit;
2060 hwndTarget = lphc->hWndLBox;
2062 return unicode ? SendMessageW(hwndTarget, message, wParam, lParam) :
2063 SendMessageA(hwndTarget, message, wParam, lParam);
2065 case WM_LBUTTONDOWN:
2066 if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self );
2067 if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
2070 COMBO_LButtonUp( lphc );
2073 if( lphc->wState & CBF_CAPTURE )
2074 COMBO_MouseMove( lphc, wParam, lParam );
2078 if (wParam & (MK_SHIFT | MK_CONTROL))
2079 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2080 DefWindowProcA(hwnd, message, wParam, lParam);
2081 if (SHIWORD(wParam) > 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_UP, 0);
2082 if (SHIWORD(wParam) < 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_DOWN, 0);
2085 /* Combo messages */
2087 case CB_ADDSTRING16:
2088 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2091 return unicode ? SendMessageW(lphc->hWndLBox, LB_ADDSTRING, 0, lParam) :
2092 SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2093 case CB_INSERTSTRING16:
2094 wParam = (INT)(INT16)wParam;
2095 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2097 case CB_INSERTSTRING:
2098 return unicode ? SendMessageW(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam) :
2099 SendMessageA(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2100 case CB_DELETESTRING16:
2101 case CB_DELETESTRING:
2102 return unicode ? SendMessageW(lphc->hWndLBox, LB_DELETESTRING, wParam, 0) :
2103 SendMessageA(lphc->hWndLBox, LB_DELETESTRING, wParam, 0);
2104 case CB_SELECTSTRING16:
2105 wParam = (INT)(INT16)wParam;
2106 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2108 case CB_SELECTSTRING:
2109 return COMBO_SelectString(lphc, (INT)wParam, lParam, unicode);
2110 case CB_FINDSTRING16:
2111 wParam = (INT)(INT16)wParam;
2112 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2115 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam) :
2116 SendMessageA(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam);
2117 case CB_FINDSTRINGEXACT16:
2118 wParam = (INT)(INT16)wParam;
2119 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2121 case CB_FINDSTRINGEXACT:
2122 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam) :
2123 SendMessageA(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam);
2124 case CB_SETITEMHEIGHT16:
2125 wParam = (INT)(INT16)wParam; /* signed integer */
2127 case CB_SETITEMHEIGHT:
2128 return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam);
2129 case CB_GETITEMHEIGHT16:
2130 wParam = (INT)(INT16)wParam;
2132 case CB_GETITEMHEIGHT:
2133 if( (INT)wParam >= 0 ) /* listbox item */
2134 return SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0);
2135 return CBGetTextAreaHeight(hwnd, lphc);
2136 case CB_RESETCONTENT16:
2137 case CB_RESETCONTENT:
2138 SendMessageW(lphc->hWndLBox, LB_RESETCONTENT, 0, 0);
2139 if( (lphc->wState & CBF_EDIT) && CB_HASSTRINGS(lphc) )
2141 static const WCHAR empty_stringW[] = { 0 };
2142 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);
2145 InvalidateRect(lphc->self, NULL, TRUE);
2147 case CB_INITSTORAGE:
2148 return SendMessageW(lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam);
2149 case CB_GETHORIZONTALEXTENT:
2150 return SendMessageW(lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0);
2151 case CB_SETHORIZONTALEXTENT:
2152 return SendMessageW(lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0);
2153 case CB_GETTOPINDEX:
2154 return SendMessageW(lphc->hWndLBox, LB_GETTOPINDEX, 0, 0);
2156 return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0);
2158 return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0);
2159 case CB_GETDROPPEDWIDTH:
2160 if( lphc->droppedWidth )
2161 return lphc->droppedWidth;
2162 return lphc->droppedRect.right - lphc->droppedRect.left;
2163 case CB_SETDROPPEDWIDTH:
2164 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) &&
2165 (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam;
2167 case CB_GETDROPPEDCONTROLRECT16:
2168 lParam = (LPARAM)MapSL(lParam);
2172 CBGetDroppedControlRect( lphc, &r );
2173 CONV_RECT32TO16( &r, (LPRECT16)lParam );
2176 case CB_GETDROPPEDCONTROLRECT:
2177 if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam );
2179 case CB_GETDROPPEDSTATE16:
2180 case CB_GETDROPPEDSTATE:
2181 return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE;
2183 lParam = (LPARAM)MapSL(lParam);
2187 if(message == CB_DIR) message = LB_DIR;
2188 return unicode ? SendMessageW(lphc->hWndLBox, message, wParam, lParam) :
2189 SendMessageA(lphc->hWndLBox, message, wParam, lParam);
2191 case CB_SHOWDROPDOWN16:
2192 case CB_SHOWDROPDOWN:
2193 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
2197 if( !(lphc->wState & CBF_DROPPED) )
2201 if( lphc->wState & CBF_DROPPED )
2202 CBRollUp( lphc, FALSE, TRUE );
2207 return SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
2208 case CB_GETCURSEL16:
2210 return SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
2211 case CB_SETCURSEL16:
2212 wParam = (INT)(INT16)wParam;
2215 lParam = SendMessageW(lphc->hWndLBox, LB_SETCURSEL, wParam, 0);
2217 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, wParam, 0);
2219 /* no LBN_SELCHANGE in this case, update manually */
2220 if( lphc->wState & CBF_EDIT )
2221 CBUpdateEdit( lphc, (INT)wParam );
2223 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
2224 lphc->wState &= ~CBF_SELCHANGE;
2226 case CB_GETLBTEXT16:
2227 wParam = (INT)(INT16)wParam;
2228 lParam = (LPARAM)MapSL(lParam);
2231 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXT, wParam, lParam) :
2232 SendMessageA(lphc->hWndLBox, LB_GETTEXT, wParam, lParam);
2233 case CB_GETLBTEXTLEN16:
2234 wParam = (INT)(INT16)wParam;
2236 case CB_GETLBTEXTLEN:
2237 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0) :
2238 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0);
2239 case CB_GETITEMDATA16:
2240 wParam = (INT)(INT16)wParam;
2242 case CB_GETITEMDATA:
2243 return SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0);
2244 case CB_SETITEMDATA16:
2245 wParam = (INT)(INT16)wParam;
2247 case CB_SETITEMDATA:
2248 return SendMessageW(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam);
2249 case CB_GETEDITSEL16:
2250 wParam = lParam = 0; /* just in case */
2253 /* Edit checks passed parameters itself */
2254 if( lphc->wState & CBF_EDIT )
2255 return SendMessageW(lphc->hWndEdit, EM_GETSEL, wParam, lParam);
2257 case CB_SETEDITSEL16:
2259 if( lphc->wState & CBF_EDIT )
2260 return SendMessageW(lphc->hWndEdit, EM_SETSEL,
2261 (INT)(INT16)LOWORD(lParam), (INT)(INT16)HIWORD(lParam) );
2263 case CB_SETEXTENDEDUI16:
2264 case CB_SETEXTENDEDUI:
2265 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
2268 lphc->wState |= CBF_EUI;
2269 else lphc->wState &= ~CBF_EUI;
2271 case CB_GETEXTENDEDUI16:
2272 case CB_GETEXTENDEDUI:
2273 return (lphc->wState & CBF_EUI) ? TRUE : FALSE;
2276 if (message >= WM_USER)
2277 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2278 message - WM_USER, wParam, lParam );
2281 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2282 DefWindowProcA(hwnd, message, wParam, lParam);
2285 /***********************************************************************
2288 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2291 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2293 if (!IsWindow(hwnd)) return 0;
2294 return ComboWndProc_common( hwnd, message, wParam, lParam, FALSE );
2297 /***********************************************************************
2300 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2302 if (!IsWindow(hwnd)) return 0;
2303 return ComboWndProc_common( hwnd, message, wParam, lParam, TRUE );