user32: We are calculating the height for the drop down based on
[wine/multimedia.git] / dlls / user32 / combo.c
blob7e54ea8922c4e24979d6eb917f924f772b3af4e8
1 /*
2 * Combo controls
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * NOTES
22 * This code was audited for completeness against the documented features
23 * of Comctl32.dll version 6.0 on Oct. 4, 2004, by Dimitrie O. Paun.
25 * Unless otherwise noted, we believe this code to be complete, as per
26 * the specification mentioned above.
27 * If you discover missing features, or bugs, please note them below.
29 * TODO:
30 * - ComboBox_[GS]etMinVisible()
31 * - CB_GETMINVISIBLE, CB_SETMINVISIBLE
32 * - CB_SETTOPINDEX
35 #include <stdarg.h>
36 #include <string.h>
38 #define OEMRESOURCE
40 #include "windef.h"
41 #include "winbase.h"
42 #include "wingdi.h"
43 #include "winuser.h"
44 #include "wine/winuser16.h"
45 #include "wine/unicode.h"
46 #include "user_private.h"
47 #include "win.h"
48 #include "controls.h"
49 #include "winreg.h"
50 #include "winternl.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(combo);
55 /* bits in the dwKeyData */
56 #define KEYDATA_ALT 0x2000
57 #define KEYDATA_PREVSTATE 0x4000
60 * Additional combo box definitions
63 #define CB_NOTIFY( lphc, code ) \
64 (SendMessageW((lphc)->owner, WM_COMMAND, \
65 MAKEWPARAM(GetWindowLongPtrW((lphc)->self,GWLP_ID), (code)), (LPARAM)(lphc)->self))
67 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
68 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
69 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
70 #define CB_HWND( lphc ) ((lphc)->self)
71 #define CB_GETTYPE( lphc ) ((lphc)->dwStyle & (CBS_DROPDOWNLIST))
73 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
76 * Drawing globals
78 static HBITMAP hComboBmp = 0;
79 static UINT CBitHeight, CBitWidth;
82 * Look and feel dependent "constants"
85 #define COMBO_YBORDERGAP 5
86 #define COMBO_XBORDERSIZE() 2
87 #define COMBO_YBORDERSIZE() 2
88 #define COMBO_EDITBUTTONSPACE() 0
89 #define EDIT_CONTROL_PADDING() 1
91 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
92 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
94 /*********************************************************************
95 * combo class descriptor
97 const struct builtin_class_descr COMBO_builtin_class =
99 "ComboBox", /* name */
100 CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, /* style */
101 ComboWndProcA, /* procA */
102 ComboWndProcW, /* procW */
103 sizeof(HEADCOMBO *), /* extra */
104 IDC_ARROW, /* cursor */
105 0 /* brush */
109 /***********************************************************************
110 * COMBO_Init
112 * Load combo button bitmap.
114 static BOOL COMBO_Init(void)
116 HDC hDC;
118 if( hComboBmp ) return TRUE;
119 if( (hDC = CreateCompatibleDC(0)) )
121 BOOL bRet = FALSE;
122 if( (hComboBmp = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO))) )
124 BITMAP bm;
125 HBITMAP hPrevB;
126 RECT r;
128 GetObjectW( hComboBmp, sizeof(bm), &bm );
129 CBitHeight = bm.bmHeight;
130 CBitWidth = bm.bmWidth;
132 TRACE("combo bitmap [%i,%i]\n", CBitWidth, CBitHeight );
134 hPrevB = SelectObject( hDC, hComboBmp);
135 SetRect( &r, 0, 0, CBitWidth, CBitHeight );
136 InvertRect( hDC, &r );
137 SelectObject( hDC, hPrevB );
138 bRet = TRUE;
140 DeleteDC( hDC );
141 return bRet;
143 return FALSE;
146 /***********************************************************************
147 * COMBO_NCCreate
149 static LRESULT COMBO_NCCreate(HWND hwnd, LONG style)
151 LPHEADCOMBO lphc;
153 if (COMBO_Init() && (lphc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEADCOMBO))) )
155 lphc->self = hwnd;
156 SetWindowLongPtrW( hwnd, 0, (LONG_PTR)lphc );
158 /* some braindead apps do try to use scrollbar/border flags */
160 lphc->dwStyle = style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
161 SetWindowLongW( hwnd, GWL_STYLE, style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL) );
164 * We also have to remove the client edge style to make sure
165 * we don't end-up with a non client area.
167 SetWindowLongW( hwnd, GWL_EXSTYLE,
168 GetWindowLongW( hwnd, GWL_EXSTYLE ) & ~WS_EX_CLIENTEDGE );
170 if( !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
171 lphc->dwStyle |= CBS_HASSTRINGS;
172 if( !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) )
173 lphc->wState |= CBF_NOTIFY;
175 TRACE("[%p], style = %08x\n", lphc, lphc->dwStyle );
176 return TRUE;
178 return FALSE;
181 /***********************************************************************
182 * COMBO_NCDestroy
184 static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc )
187 if( lphc )
189 TRACE("[%p]: freeing storage\n", lphc->self);
191 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && lphc->hWndLBox )
192 DestroyWindow( lphc->hWndLBox );
194 SetWindowLongPtrW( lphc->self, 0, 0 );
195 HeapFree( GetProcessHeap(), 0, lphc );
197 return 0;
200 /***********************************************************************
201 * CBGetTextAreaHeight
203 * This method will calculate the height of the text area of the
204 * combobox.
205 * The height of the text area is set in two ways.
206 * It can be set explicitly through a combobox message or through a
207 * WM_MEASUREITEM callback.
208 * If this is not the case, the height is set to 13 dialog units.
209 * This height was determined through experimentation.
211 static INT CBGetTextAreaHeight(
212 HWND hwnd,
213 LPHEADCOMBO lphc)
215 INT iTextItemHeight;
217 if( lphc->editHeight ) /* explicitly set height */
219 iTextItemHeight = lphc->editHeight;
221 else
223 TEXTMETRICW tm;
224 HDC hDC = GetDC(hwnd);
225 HFONT hPrevFont = 0;
226 INT baseUnitY;
228 if (lphc->hFont)
229 hPrevFont = SelectObject( hDC, lphc->hFont );
231 GetTextMetricsW(hDC, &tm);
233 baseUnitY = tm.tmHeight;
235 if( hPrevFont )
236 SelectObject( hDC, hPrevFont );
238 ReleaseDC(hwnd, hDC);
240 iTextItemHeight = ((13 * baseUnitY) / 8);
243 * This "formula" calculates the height of the complete control.
244 * To calculate the height of the text area, we have to remove the
245 * borders.
247 iTextItemHeight -= 2*COMBO_YBORDERSIZE();
251 * Check the ownerdraw case if we haven't asked the parent the size
252 * of the item yet.
254 if ( CB_OWNERDRAWN(lphc) &&
255 (lphc->wState & CBF_MEASUREITEM) )
257 MEASUREITEMSTRUCT measureItem;
258 RECT clientRect;
259 INT originalItemHeight = iTextItemHeight;
260 UINT id = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
263 * We use the client rect for the width of the item.
265 GetClientRect(hwnd, &clientRect);
267 lphc->wState &= ~CBF_MEASUREITEM;
270 * Send a first one to measure the size of the text area
272 measureItem.CtlType = ODT_COMBOBOX;
273 measureItem.CtlID = id;
274 measureItem.itemID = -1;
275 measureItem.itemWidth = clientRect.right;
276 measureItem.itemHeight = iTextItemHeight - 6; /* ownerdrawn cb is taller */
277 measureItem.itemData = 0;
278 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
279 iTextItemHeight = 6 + measureItem.itemHeight;
282 * Send a second one in the case of a fixed ownerdraw list to calculate the
283 * size of the list items. (we basically do this on behalf of the listbox)
285 if (lphc->dwStyle & CBS_OWNERDRAWFIXED)
287 measureItem.CtlType = ODT_COMBOBOX;
288 measureItem.CtlID = id;
289 measureItem.itemID = 0;
290 measureItem.itemWidth = clientRect.right;
291 measureItem.itemHeight = originalItemHeight;
292 measureItem.itemData = 0;
293 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
294 lphc->fixedOwnerDrawHeight = measureItem.itemHeight;
298 * Keep the size for the next time
300 lphc->editHeight = iTextItemHeight;
303 return iTextItemHeight;
306 /***********************************************************************
307 * CBForceDummyResize
309 * The dummy resize is used for listboxes that have a popup to trigger
310 * a re-arranging of the contents of the combobox and the recalculation
311 * of the size of the "real" control window.
313 static void CBForceDummyResize(
314 LPHEADCOMBO lphc)
316 RECT windowRect;
317 int newComboHeight;
319 newComboHeight = CBGetTextAreaHeight(lphc->self,lphc) + 2*COMBO_YBORDERSIZE();
321 GetWindowRect(lphc->self, &windowRect);
324 * We have to be careful, resizing a combobox also has the meaning that the
325 * dropped rect will be resized. In this case, we want to trigger a resize
326 * to recalculate layout but we don't want to change the dropped rectangle
327 * So, we pass the height of text area of control as the height.
328 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
329 * message.
331 SetWindowPos( lphc->self,
332 NULL,
333 0, 0,
334 windowRect.right - windowRect.left,
335 newComboHeight,
336 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
339 /***********************************************************************
340 * CBCalcPlacement
342 * Set up component coordinates given valid lphc->RectCombo.
344 static void CBCalcPlacement(
345 HWND hwnd,
346 LPHEADCOMBO lphc,
347 LPRECT lprEdit,
348 LPRECT lprButton,
349 LPRECT lprLB)
352 * Again, start with the client rectangle.
354 GetClientRect(hwnd, lprEdit);
357 * Remove the borders
359 InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
362 * Chop off the bottom part to fit with the height of the text area.
364 lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
367 * The button starts the same vertical position as the text area.
369 CopyRect(lprButton, lprEdit);
372 * If the combobox is "simple" there is no button.
374 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
375 lprButton->left = lprButton->right = lprButton->bottom = 0;
376 else
379 * Let's assume the combobox button is the same width as the
380 * scrollbar button.
381 * size the button horizontally and cut-off the text area.
383 lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
384 lprEdit->right = lprButton->left;
388 * In the case of a dropdown, there is an additional spacing between the
389 * text area and the button.
391 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
393 lprEdit->right -= COMBO_EDITBUTTONSPACE();
397 * If we have an edit control, we space it away from the borders slightly.
399 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
401 InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
405 * Adjust the size of the listbox popup.
407 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
410 * Use the client rectangle to initialize the listbox rectangle
412 GetClientRect(hwnd, lprLB);
415 * Then, chop-off the top part.
417 lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
419 else
422 * Make sure the dropped width is as large as the combobox itself.
424 if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
426 lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
429 * In the case of a dropdown, the popup listbox is offset to the right.
430 * so, we want to make sure it's flush with the right side of the
431 * combobox
433 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
434 lprLB->right -= COMBO_EDITBUTTONSPACE();
436 else
437 lprLB->right = lprLB->left + lphc->droppedWidth;
440 /* don't allow negative window width */
441 if (lprEdit->right < lprEdit->left)
442 lprEdit->right = lprEdit->left;
444 TRACE("\ttext\t= (%d,%d-%d,%d)\n",
445 lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom);
447 TRACE("\tbutton\t= (%d,%d-%d,%d)\n",
448 lprButton->left, lprButton->top, lprButton->right, lprButton->bottom);
450 TRACE("\tlbox\t= (%d,%d-%d,%d)\n",
451 lprLB->left, lprLB->top, lprLB->right, lprLB->bottom );
454 /***********************************************************************
455 * CBGetDroppedControlRect
457 static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect)
459 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
460 of the combo box and the lower right corner of the listbox */
462 GetWindowRect(lphc->self, lpRect);
464 lpRect->right = lpRect->left + lphc->droppedRect.right - lphc->droppedRect.left;
465 lpRect->bottom = lpRect->top + lphc->droppedRect.bottom - lphc->droppedRect.top;
469 /***********************************************************************
470 * COMBO_WindowPosChanging
472 static LRESULT COMBO_WindowPosChanging(
473 HWND hwnd,
474 LPHEADCOMBO lphc,
475 WINDOWPOS* posChanging)
478 * We need to override the WM_WINDOWPOSCHANGING method to handle all
479 * the non-simple comboboxes. The problem is that those controls are
480 * always the same height. We have to make sure they are not resized
481 * to another value.
483 if ( ( CB_GETTYPE(lphc) != CBS_SIMPLE ) &&
484 ((posChanging->flags & SWP_NOSIZE) == 0) )
486 int newComboHeight;
488 newComboHeight = CBGetTextAreaHeight(hwnd,lphc) +
489 2*COMBO_YBORDERSIZE();
492 * Resizing a combobox has another side effect, it resizes the dropped
493 * rectangle as well. However, it does it only if the new height for the
494 * combobox is different from the height it should have. In other words,
495 * if the application resizing the combobox only had the intention to resize
496 * the actual control, for example, to do the layout of a dialog that is
497 * resized, the height of the dropdown is not changed.
499 if (posChanging->cy != newComboHeight)
501 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%d, oldtop=%d\n",
502 posChanging->cy, newComboHeight, lphc->droppedRect.bottom,
503 lphc->droppedRect.top);
504 lphc->droppedRect.bottom = lphc->droppedRect.top + posChanging->cy - newComboHeight;
506 posChanging->cy = newComboHeight;
510 return 0;
513 /***********************************************************************
514 * COMBO_Create
516 static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style,
517 BOOL unicode )
519 static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0};
520 static const WCHAR editName[] = {'E','d','i','t',0};
522 if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE;
523 if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT;
525 lphc->owner = hwndParent;
528 * The item height and dropped width are not set when the control
529 * is created.
531 lphc->droppedWidth = lphc->editHeight = 0;
534 * The first time we go through, we want to measure the ownerdraw item
536 lphc->wState |= CBF_MEASUREITEM;
538 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
540 if( lphc->owner || !(style & WS_VISIBLE) )
542 UINT lbeStyle = 0;
543 UINT lbeExStyle = 0;
546 * Initialize the dropped rect to the size of the client area of the
547 * control and then, force all the areas of the combobox to be
548 * recalculated.
550 GetClientRect( hwnd, &lphc->droppedRect );
551 CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
554 * Adjust the position of the popup listbox if it's necessary
556 if ( CB_GETTYPE(lphc) != CBS_SIMPLE )
558 lphc->droppedRect.top = lphc->textRect.bottom + COMBO_YBORDERSIZE();
561 * If it's a dropdown, the listbox is offset
563 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
564 lphc->droppedRect.left += COMBO_EDITBUTTONSPACE();
566 if (lphc->droppedRect.bottom < lphc->droppedRect.top)
567 lphc->droppedRect.bottom = lphc->droppedRect.top;
568 if (lphc->droppedRect.right < lphc->droppedRect.left)
569 lphc->droppedRect.right = lphc->droppedRect.left;
570 MapWindowPoints( hwnd, 0, (LPPOINT)&lphc->droppedRect, 2 );
573 /* create listbox popup */
575 lbeStyle = (LBS_NOTIFY | LBS_COMBOBOX | WS_BORDER | WS_CLIPSIBLINGS | WS_CHILD) |
576 (style & (WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE));
578 if( lphc->dwStyle & CBS_SORT )
579 lbeStyle |= LBS_SORT;
580 if( lphc->dwStyle & CBS_HASSTRINGS )
581 lbeStyle |= LBS_HASSTRINGS;
582 if( lphc->dwStyle & CBS_NOINTEGRALHEIGHT )
583 lbeStyle |= LBS_NOINTEGRALHEIGHT;
584 if( lphc->dwStyle & CBS_DISABLENOSCROLL )
585 lbeStyle |= LBS_DISABLENOSCROLL;
587 if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* child listbox */
589 lbeStyle |= WS_VISIBLE;
592 * In win 95 look n feel, the listbox in the simple combobox has
593 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
595 lbeStyle &= ~WS_BORDER;
596 lbeExStyle |= WS_EX_CLIENTEDGE;
598 else
600 lbeExStyle |= (WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
603 if (unicode)
604 lphc->hWndLBox = CreateWindowExW(lbeExStyle, clbName, NULL, lbeStyle,
605 lphc->droppedRect.left,
606 lphc->droppedRect.top,
607 lphc->droppedRect.right - lphc->droppedRect.left,
608 lphc->droppedRect.bottom - lphc->droppedRect.top,
609 hwnd, (HMENU)ID_CB_LISTBOX,
610 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), lphc );
611 else
612 lphc->hWndLBox = CreateWindowExA(lbeExStyle, "ComboLBox", NULL, lbeStyle,
613 lphc->droppedRect.left,
614 lphc->droppedRect.top,
615 lphc->droppedRect.right - lphc->droppedRect.left,
616 lphc->droppedRect.bottom - lphc->droppedRect.top,
617 hwnd, (HMENU)ID_CB_LISTBOX,
618 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), lphc );
620 if( lphc->hWndLBox )
622 BOOL bEdit = TRUE;
623 lbeStyle = WS_CHILD | WS_VISIBLE | ES_NOHIDESEL | ES_LEFT | ES_COMBO;
625 if( lphc->wState & CBF_EDIT )
627 if( lphc->dwStyle & CBS_OEMCONVERT )
628 lbeStyle |= ES_OEMCONVERT;
629 if( lphc->dwStyle & CBS_AUTOHSCROLL )
630 lbeStyle |= ES_AUTOHSCROLL;
631 if( lphc->dwStyle & CBS_LOWERCASE )
632 lbeStyle |= ES_LOWERCASE;
633 else if( lphc->dwStyle & CBS_UPPERCASE )
634 lbeStyle |= ES_UPPERCASE;
636 if (!IsWindowEnabled(hwnd)) lbeStyle |= WS_DISABLED;
638 if (unicode)
639 lphc->hWndEdit = CreateWindowExW(0, editName, NULL, lbeStyle,
640 lphc->textRect.left, lphc->textRect.top,
641 lphc->textRect.right - lphc->textRect.left,
642 lphc->textRect.bottom - lphc->textRect.top,
643 hwnd, (HMENU)ID_CB_EDIT,
644 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), NULL );
645 else
646 lphc->hWndEdit = CreateWindowExA(0, "Edit", NULL, lbeStyle,
647 lphc->textRect.left, lphc->textRect.top,
648 lphc->textRect.right - lphc->textRect.left,
649 lphc->textRect.bottom - lphc->textRect.top,
650 hwnd, (HMENU)ID_CB_EDIT,
651 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), NULL );
653 if( !lphc->hWndEdit )
654 bEdit = FALSE;
657 if( bEdit )
659 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
661 /* Now do the trick with parent */
662 SetParent(lphc->hWndLBox, HWND_DESKTOP);
664 * If the combo is a dropdown, we must resize the control
665 * to fit only the text area and button. To do this,
666 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
667 * will take care of setting the height for us.
669 CBForceDummyResize(lphc);
672 TRACE("init done\n");
673 return 0;
675 ERR("edit control failure.\n");
676 } else ERR("listbox failure.\n");
677 } else ERR("no owner for visible combo.\n");
679 /* CreateWindow() will send WM_NCDESTROY to cleanup */
681 return -1;
684 /***********************************************************************
685 * CBPaintButton
687 * Paint combo button (normal, pressed, and disabled states).
689 static void CBPaintButton( LPHEADCOMBO lphc, HDC hdc, RECT rectButton)
691 UINT buttonState = DFCS_SCROLLCOMBOBOX;
693 if( lphc->wState & CBF_NOREDRAW )
694 return;
697 if (lphc->wState & CBF_BUTTONDOWN)
698 buttonState |= DFCS_PUSHED;
700 if (CB_DISABLED(lphc))
701 buttonState |= DFCS_INACTIVE;
703 DrawFrameControl(hdc, &rectButton, DFC_SCROLL, buttonState);
706 /***********************************************************************
707 * CBPaintText
709 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
711 static void CBPaintText(
712 LPHEADCOMBO lphc,
713 HDC hdc,
714 RECT rectEdit)
716 INT id, size = 0;
717 LPWSTR pText = NULL;
719 if( lphc->wState & CBF_NOREDRAW ) return;
721 TRACE("\n");
723 /* follow Windows combobox that sends a bunch of text
724 * inquiries to its listbox while processing WM_PAINT. */
726 if( (id = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0) ) != LB_ERR )
728 size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0);
729 if (size == LB_ERR)
730 FIXME("LB_ERR probably not handled yet\n");
731 if( (pText = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))) )
733 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
734 size=SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText);
735 pText[size] = '\0'; /* just in case */
736 } else return;
738 else
739 if( !CB_OWNERDRAWN(lphc) )
740 return;
742 if( lphc->wState & CBF_EDIT )
744 static const WCHAR empty_stringW[] = { 0 };
745 if( CB_HASSTRINGS(lphc) ) SetWindowTextW( lphc->hWndEdit, pText ? pText : empty_stringW );
746 if( lphc->wState & CBF_FOCUSED )
747 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
749 else /* paint text field ourselves */
751 UINT itemState = ODS_COMBOBOXEDIT;
752 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hdc, lphc->hFont) : 0;
755 * Give ourselves some space.
757 InflateRect( &rectEdit, -1, -1 );
759 if( CB_OWNERDRAWN(lphc) )
761 DRAWITEMSTRUCT dis;
762 HRGN clipRegion;
763 UINT ctlid = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
765 /* setup state for DRAWITEM message. Owner will highlight */
766 if ( (lphc->wState & CBF_FOCUSED) &&
767 !(lphc->wState & CBF_DROPPED) )
768 itemState |= ODS_SELECTED | ODS_FOCUS;
771 * Save the current clip region.
772 * To retrieve the clip region, we need to create one "dummy"
773 * clip region.
775 clipRegion = CreateRectRgnIndirect(&rectEdit);
777 if (GetClipRgn(hdc, clipRegion)!=1)
779 DeleteObject(clipRegion);
780 clipRegion=NULL;
783 if (!IsWindowEnabled(lphc->self) & WS_DISABLED) itemState |= ODS_DISABLED;
785 dis.CtlType = ODT_COMBOBOX;
786 dis.CtlID = ctlid;
787 dis.hwndItem = lphc->self;
788 dis.itemAction = ODA_DRAWENTIRE;
789 dis.itemID = id;
790 dis.itemState = itemState;
791 dis.hDC = hdc;
792 dis.rcItem = rectEdit;
793 dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA,
794 (WPARAM)id, 0 );
797 * Clip the DC and have the parent draw the item.
799 IntersectClipRect(hdc,
800 rectEdit.left, rectEdit.top,
801 rectEdit.right, rectEdit.bottom);
803 SendMessageW(lphc->owner, WM_DRAWITEM, ctlid, (LPARAM)&dis );
806 * Reset the clipping region.
808 SelectClipRgn(hdc, clipRegion);
810 else
812 static const WCHAR empty_stringW[] = { 0 };
814 if ( (lphc->wState & CBF_FOCUSED) &&
815 !(lphc->wState & CBF_DROPPED) ) {
817 /* highlight */
818 FillRect( hdc, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) );
819 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
820 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
823 ExtTextOutW( hdc,
824 rectEdit.left + 1,
825 rectEdit.top + 1,
826 ETO_OPAQUE | ETO_CLIPPED,
827 &rectEdit,
828 pText ? pText : empty_stringW , size, NULL );
830 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED))
831 DrawFocusRect( hdc, &rectEdit );
834 if( hPrevFont )
835 SelectObject(hdc, hPrevFont );
837 HeapFree( GetProcessHeap(), 0, pText );
840 /***********************************************************************
841 * CBPaintBorder
843 static void CBPaintBorder(
844 HWND hwnd,
845 LPHEADCOMBO lphc,
846 HDC hdc)
848 RECT clientRect;
850 if (CB_GETTYPE(lphc) != CBS_SIMPLE)
852 GetClientRect(hwnd, &clientRect);
854 else
856 CopyRect(&clientRect, &lphc->textRect);
858 InflateRect(&clientRect, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
859 InflateRect(&clientRect, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
862 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_RECT);
865 /***********************************************************************
866 * COMBO_PrepareColors
868 * This method will sent the appropriate WM_CTLCOLOR message to
869 * prepare and setup the colors for the combo's DC.
871 * It also returns the brush to use for the background.
873 static HBRUSH COMBO_PrepareColors(
874 LPHEADCOMBO lphc,
875 HDC hDC)
877 HBRUSH hBkgBrush;
880 * Get the background brush for this control.
882 if (CB_DISABLED(lphc))
884 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORSTATIC,
885 (WPARAM)hDC, (LPARAM)lphc->self );
888 * We have to change the text color since WM_CTLCOLORSTATIC will
889 * set it to the "enabled" color. This is the same behavior as the
890 * edit control
892 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
894 else
896 if (lphc->wState & CBF_EDIT)
898 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLOREDIT,
899 (WPARAM)hDC, (LPARAM)lphc->self );
901 else
903 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORLISTBOX,
904 (WPARAM)hDC, (LPARAM)lphc->self );
909 * Catch errors.
911 if( !hBkgBrush )
912 hBkgBrush = GetSysColorBrush(COLOR_WINDOW);
914 return hBkgBrush;
918 /***********************************************************************
919 * COMBO_Paint
921 static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC)
923 PAINTSTRUCT ps;
924 HDC hDC;
926 hDC = (hParamDC) ? hParamDC
927 : BeginPaint( lphc->self, &ps);
929 TRACE("hdc=%p\n", hDC);
931 if( hDC && !(lphc->wState & CBF_NOREDRAW) )
933 HBRUSH hPrevBrush, hBkgBrush;
936 * Retrieve the background brush and select it in the
937 * DC.
939 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
941 hPrevBrush = SelectObject( hDC, hBkgBrush );
942 if (!(lphc->wState & CBF_EDIT))
943 FillRect(hDC, &lphc->textRect, hBkgBrush);
946 * In non 3.1 look, there is a sunken border on the combobox
948 CBPaintBorder(lphc->self, lphc, hDC);
950 if( !IsRectEmpty(&lphc->buttonRect) )
952 CBPaintButton(lphc, hDC, lphc->buttonRect);
955 /* paint the edit control padding area */
956 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
958 RECT rPadEdit = lphc->textRect;
960 InflateRect(&rPadEdit, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
962 FrameRect( hDC, &rPadEdit, GetSysColorBrush(COLOR_WINDOW) );
965 if( !(lphc->wState & CBF_EDIT) )
966 CBPaintText( lphc, hDC, lphc->textRect);
968 if( hPrevBrush )
969 SelectObject( hDC, hPrevBrush );
972 if( !hParamDC )
973 EndPaint(lphc->self, &ps);
975 return 0;
978 /***********************************************************************
979 * CBUpdateLBox
981 * Select listbox entry according to the contents of the edit control.
983 static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
985 INT length, idx;
986 LPWSTR pText = NULL;
988 idx = LB_ERR;
989 length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 );
991 if( length > 0 )
992 pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
994 TRACE("\t edit text length %i\n", length );
996 if( pText )
998 GetWindowTextW( lphc->hWndEdit, pText, length + 1);
999 idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING,
1000 (WPARAM)(-1), (LPARAM)pText );
1001 HeapFree( GetProcessHeap(), 0, pText );
1004 SendMessageW(lphc->hWndLBox, LB_SETCURSEL, (WPARAM)(bSelect ? idx : -1), 0);
1006 /* probably superfluous but Windows sends this too */
1007 SendMessageW(lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1008 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1010 return idx;
1013 /***********************************************************************
1014 * CBUpdateEdit
1016 * Copy a listbox entry to the edit control.
1018 static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
1020 INT length;
1021 LPWSTR pText = NULL;
1022 static const WCHAR empty_stringW[] = { 0 };
1024 TRACE("\t %i\n", index );
1026 if( index >= 0 ) /* got an entry */
1028 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0);
1029 if( length != LB_ERR)
1031 if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) )
1033 SendMessageW(lphc->hWndLBox, LB_GETTEXT,
1034 (WPARAM)index, (LPARAM)pText );
1039 lphc->wState |= (CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1040 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, pText ? (LPARAM)pText : (LPARAM)empty_stringW);
1041 lphc->wState &= ~(CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1043 if( lphc->wState & CBF_FOCUSED )
1044 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1046 HeapFree( GetProcessHeap(), 0, pText );
1049 /***********************************************************************
1050 * CBDropDown
1052 * Show listbox popup.
1054 static void CBDropDown( LPHEADCOMBO lphc )
1056 HMONITOR monitor;
1057 MONITORINFO mon_info;
1058 RECT rect,r;
1059 int nItems = 0;
1060 int nDroppedHeight;
1062 TRACE("[%p]: drop down\n", lphc->self);
1064 CB_NOTIFY( lphc, CBN_DROPDOWN );
1066 /* set selection */
1068 lphc->wState |= CBF_DROPPED;
1069 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1071 lphc->droppedIndex = CBUpdateLBox( lphc, TRUE );
1073 /* Update edit only if item is in the list */
1074 if( !(lphc->wState & CBF_CAPTURE) && lphc->droppedIndex >= 0)
1075 CBUpdateEdit( lphc, lphc->droppedIndex );
1077 else
1079 lphc->droppedIndex = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1081 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX,
1082 (WPARAM)(lphc->droppedIndex == LB_ERR ? 0 : lphc->droppedIndex), 0 );
1083 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1086 /* now set popup position */
1087 GetWindowRect( lphc->self, &rect );
1090 * If it's a dropdown, the listbox is offset
1092 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1093 rect.left += COMBO_EDITBUTTONSPACE();
1095 /* if the dropped height is greater than the total height of the dropped
1096 items list, then force the drop down list height to be the total height
1097 of the items in the dropped list */
1099 /* And Remove any extra space (Best Fit) */
1100 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
1101 /* if listbox length has been set directly by its handle */
1102 GetWindowRect(lphc->hWndLBox, &r);
1103 if (nDroppedHeight < r.bottom - r.top)
1104 nDroppedHeight = r.bottom - r.top;
1105 nItems = (int)SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
1107 if (nItems > 0)
1109 int nHeight;
1110 int nIHeight;
1112 nIHeight = (int)SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, 0, 0);
1114 nHeight = nIHeight*nItems;
1116 if (nHeight < nDroppedHeight - COMBO_YBORDERSIZE())
1117 nDroppedHeight = nHeight + COMBO_YBORDERSIZE();
1119 if (nDroppedHeight < nHeight)
1121 if (nItems < 5)
1122 nDroppedHeight = (nItems+1)*nIHeight;
1123 else
1124 nDroppedHeight = 6*nIHeight;
1128 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1129 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
1130 mon_info.cbSize = sizeof(mon_info);
1131 GetMonitorInfoW( monitor, &mon_info );
1133 if( (rect.bottom + nDroppedHeight) >= mon_info.rcWork.bottom )
1134 rect.bottom = rect.top - nDroppedHeight;
1136 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
1137 lphc->droppedRect.right - lphc->droppedRect.left,
1138 nDroppedHeight,
1139 SWP_NOACTIVATE | SWP_SHOWWINDOW);
1142 if( !(lphc->wState & CBF_NOREDRAW) )
1143 RedrawWindow( lphc->self, NULL, 0, RDW_INVALIDATE |
1144 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1146 EnableWindow( lphc->hWndLBox, TRUE );
1147 if (GetCapture() != lphc->self)
1148 SetCapture(lphc->hWndLBox);
1151 /***********************************************************************
1152 * CBRollUp
1154 * Hide listbox popup.
1156 static void CBRollUp( LPHEADCOMBO lphc, BOOL ok, BOOL bButton )
1158 HWND hWnd = lphc->self;
1160 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1161 lphc->self, (INT)ok, (INT)(lphc->wState & CBF_DROPPED));
1163 CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL );
1165 if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE )
1168 if( lphc->wState & CBF_DROPPED )
1170 RECT rect;
1172 lphc->wState &= ~CBF_DROPPED;
1173 ShowWindow( lphc->hWndLBox, SW_HIDE );
1175 if(GetCapture() == lphc->hWndLBox)
1177 ReleaseCapture();
1180 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1182 rect = lphc->buttonRect;
1184 else
1186 if( bButton )
1188 UnionRect( &rect,
1189 &lphc->buttonRect,
1190 &lphc->textRect);
1192 else
1193 rect = lphc->textRect;
1195 bButton = TRUE;
1198 if( bButton && !(lphc->wState & CBF_NOREDRAW) )
1199 RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE |
1200 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1201 CB_NOTIFY( lphc, CBN_CLOSEUP );
1206 /***********************************************************************
1207 * COMBO_FlipListbox
1209 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1211 BOOL COMBO_FlipListbox( LPHEADCOMBO lphc, BOOL ok, BOOL bRedrawButton )
1213 if( lphc->wState & CBF_DROPPED )
1215 CBRollUp( lphc, ok, bRedrawButton );
1216 return FALSE;
1219 CBDropDown( lphc );
1220 return TRUE;
1223 /***********************************************************************
1224 * CBRepaintButton
1226 static void CBRepaintButton( LPHEADCOMBO lphc )
1228 InvalidateRect(lphc->self, &lphc->buttonRect, TRUE);
1229 UpdateWindow(lphc->self);
1232 /***********************************************************************
1233 * COMBO_SetFocus
1235 static void COMBO_SetFocus( LPHEADCOMBO lphc )
1237 if( !(lphc->wState & CBF_FOCUSED) )
1239 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1240 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1242 /* This is wrong. Message sequences seem to indicate that this
1243 is set *after* the notify. */
1244 /* lphc->wState |= CBF_FOCUSED; */
1246 if( !(lphc->wState & CBF_EDIT) )
1247 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1249 CB_NOTIFY( lphc, CBN_SETFOCUS );
1250 lphc->wState |= CBF_FOCUSED;
1254 /***********************************************************************
1255 * COMBO_KillFocus
1257 static void COMBO_KillFocus( LPHEADCOMBO lphc )
1259 HWND hWnd = lphc->self;
1261 if( lphc->wState & CBF_FOCUSED )
1263 CBRollUp( lphc, FALSE, TRUE );
1264 if( IsWindow( hWnd ) )
1266 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1267 SendMessageW(lphc->hWndLBox, LB_CARETOFF, 0, 0);
1269 lphc->wState &= ~CBF_FOCUSED;
1271 /* redraw text */
1272 if( !(lphc->wState & CBF_EDIT) )
1273 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1275 CB_NOTIFY( lphc, CBN_KILLFOCUS );
1280 /***********************************************************************
1281 * COMBO_Command
1283 static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd )
1285 if ( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd )
1287 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1289 switch( HIWORD(wParam) >> 8 )
1291 case (EN_SETFOCUS >> 8):
1293 TRACE("[%p]: edit [%p] got focus\n", lphc->self, lphc->hWndEdit );
1295 COMBO_SetFocus( lphc );
1296 break;
1298 case (EN_KILLFOCUS >> 8):
1300 TRACE("[%p]: edit [%p] lost focus\n", lphc->self, lphc->hWndEdit );
1302 /* NOTE: it seems that Windows' edit control sends an
1303 * undocumented message WM_USER + 0x1B instead of this
1304 * notification (only when it happens to be a part of
1305 * the combo). ?? - AK.
1308 COMBO_KillFocus( lphc );
1309 break;
1312 case (EN_CHANGE >> 8):
1314 * In some circumstances (when the selection of the combobox
1315 * is changed for example) we don't want the EN_CHANGE notification
1316 * to be forwarded to the parent of the combobox. This code
1317 * checks a flag that is set in these occasions and ignores the
1318 * notification.
1320 if (lphc->wState & CBF_NOLBSELECT)
1322 lphc->wState &= ~CBF_NOLBSELECT;
1324 else
1326 CBUpdateLBox( lphc, lphc->wState & CBF_DROPPED );
1329 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1330 CB_NOTIFY( lphc, CBN_EDITCHANGE );
1331 break;
1333 case (EN_UPDATE >> 8):
1334 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1335 CB_NOTIFY( lphc, CBN_EDITUPDATE );
1336 break;
1338 case (EN_ERRSPACE >> 8):
1339 CB_NOTIFY( lphc, CBN_ERRSPACE );
1342 else if( lphc->hWndLBox == hWnd )
1344 switch( (short)HIWORD(wParam) )
1346 case LBN_ERRSPACE:
1347 CB_NOTIFY( lphc, CBN_ERRSPACE );
1348 break;
1350 case LBN_DBLCLK:
1351 CB_NOTIFY( lphc, CBN_DBLCLK );
1352 break;
1354 case LBN_SELCHANGE:
1355 case LBN_SELCANCEL:
1357 TRACE("[%p]: lbox selection change [%x]\n", lphc->self, lphc->wState );
1359 if( HIWORD(wParam) == LBN_SELCHANGE)
1361 if( lphc->wState & CBF_EDIT )
1363 INT index = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1364 lphc->wState |= CBF_NOLBSELECT;
1365 CBUpdateEdit( lphc, index );
1366 /* select text in edit, as Windows does */
1367 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1369 else
1370 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1373 /* do not roll up if selection is being tracked
1374 * by arrowkeys in the dropdown listbox */
1375 if( ((lphc->wState & CBF_DROPPED) && !(lphc->wState & CBF_NOROLLUP)) )
1377 CBRollUp( lphc, (HIWORD(wParam) == LBN_SELCHANGE), TRUE );
1379 else lphc->wState &= ~CBF_NOROLLUP;
1381 CB_NOTIFY( lphc, CBN_SELCHANGE );
1383 /* fall through */
1385 case LBN_SETFOCUS:
1386 case LBN_KILLFOCUS:
1387 /* nothing to do here since ComboLBox always resets the focus to its
1388 * combo/edit counterpart */
1389 break;
1392 return 0;
1395 /***********************************************************************
1396 * COMBO_ItemOp
1398 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1400 static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
1402 HWND hWnd = lphc->self;
1403 UINT id = (UINT)GetWindowLongPtrW( hWnd, GWLP_ID );
1405 TRACE("[%p]: ownerdraw op %04x\n", lphc->self, msg );
1407 switch( msg )
1409 case WM_DELETEITEM:
1411 DELETEITEMSTRUCT *lpIS = (DELETEITEMSTRUCT *)lParam;
1412 lpIS->CtlType = ODT_COMBOBOX;
1413 lpIS->CtlID = id;
1414 lpIS->hwndItem = hWnd;
1415 break;
1417 case WM_DRAWITEM:
1419 DRAWITEMSTRUCT *lpIS = (DRAWITEMSTRUCT *)lParam;
1420 lpIS->CtlType = ODT_COMBOBOX;
1421 lpIS->CtlID = id;
1422 lpIS->hwndItem = hWnd;
1423 break;
1425 case WM_COMPAREITEM:
1427 COMPAREITEMSTRUCT *lpIS = (COMPAREITEMSTRUCT *)lParam;
1428 lpIS->CtlType = ODT_COMBOBOX;
1429 lpIS->CtlID = id;
1430 lpIS->hwndItem = hWnd;
1431 break;
1433 case WM_MEASUREITEM:
1435 MEASUREITEMSTRUCT *lpIS = (MEASUREITEMSTRUCT *)lParam;
1436 lpIS->CtlType = ODT_COMBOBOX;
1437 lpIS->CtlID = id;
1438 break;
1441 return SendMessageW(lphc->owner, msg, id, lParam);
1445 /***********************************************************************
1446 * COMBO_GetTextW
1448 static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf )
1450 INT length;
1452 if( lphc->wState & CBF_EDIT )
1453 return SendMessageW( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1455 /* get it from the listbox */
1457 if (!count || !buf) return 0;
1458 if( lphc->hWndLBox )
1460 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1461 if (idx == LB_ERR) goto error;
1462 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1463 if (length == LB_ERR) goto error;
1465 /* 'length' is without the terminating character */
1466 if (length >= count)
1468 LPWSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1469 if (!lpBuffer) goto error;
1470 length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1472 /* truncate if buffer is too short */
1473 if (length != LB_ERR)
1475 lstrcpynW( buf, lpBuffer, count );
1476 length = count;
1478 HeapFree( GetProcessHeap(), 0, lpBuffer );
1480 else length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1482 if (length == LB_ERR) return 0;
1483 return length;
1486 error: /* error - truncate string, return zero */
1487 buf[0] = 0;
1488 return 0;
1492 /***********************************************************************
1493 * COMBO_GetTextA
1495 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1496 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1498 static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf )
1500 INT length;
1502 if( lphc->wState & CBF_EDIT )
1503 return SendMessageA( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1505 /* get it from the listbox */
1507 if (!count || !buf) return 0;
1508 if( lphc->hWndLBox )
1510 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1511 if (idx == LB_ERR) goto error;
1512 length = SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1513 if (length == LB_ERR) goto error;
1515 /* 'length' is without the terminating character */
1516 if (length >= count)
1518 LPSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) );
1519 if (!lpBuffer) goto error;
1520 length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1522 /* truncate if buffer is too short */
1523 if (length != LB_ERR)
1525 lstrcpynA( buf, lpBuffer, count );
1526 length = count;
1528 HeapFree( GetProcessHeap(), 0, lpBuffer );
1530 else length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1532 if (length == LB_ERR) return 0;
1533 return length;
1536 error: /* error - truncate string, return zero */
1537 buf[0] = 0;
1538 return 0;
1542 /***********************************************************************
1543 * CBResetPos
1545 * This function sets window positions according to the updated
1546 * component placement struct.
1548 static void CBResetPos(
1549 LPHEADCOMBO lphc,
1550 LPRECT rectEdit,
1551 LPRECT rectLB,
1552 BOOL bRedraw)
1554 BOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE);
1556 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1557 * sizing messages */
1559 if( lphc->wState & CBF_EDIT )
1560 SetWindowPos( lphc->hWndEdit, 0,
1561 rectEdit->left, rectEdit->top,
1562 rectEdit->right - rectEdit->left,
1563 rectEdit->bottom - rectEdit->top,
1564 SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) );
1566 SetWindowPos( lphc->hWndLBox, 0,
1567 rectLB->left, rectLB->top,
1568 rectLB->right - rectLB->left,
1569 rectLB->bottom - rectLB->top,
1570 SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) );
1572 if( bDrop )
1574 if( lphc->wState & CBF_DROPPED )
1576 lphc->wState &= ~CBF_DROPPED;
1577 ShowWindow( lphc->hWndLBox, SW_HIDE );
1580 if( bRedraw && !(lphc->wState & CBF_NOREDRAW) )
1581 RedrawWindow( lphc->self, NULL, 0,
1582 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
1587 /***********************************************************************
1588 * COMBO_Size
1590 static void COMBO_Size( LPHEADCOMBO lphc, BOOL bRedraw )
1592 CBCalcPlacement(lphc->self,
1593 lphc,
1594 &lphc->textRect,
1595 &lphc->buttonRect,
1596 &lphc->droppedRect);
1598 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, bRedraw );
1602 /***********************************************************************
1603 * COMBO_Font
1605 static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
1608 * Set the font
1610 lphc->hFont = hFont;
1613 * Propagate to owned windows.
1615 if( lphc->wState & CBF_EDIT )
1616 SendMessageW(lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw);
1617 SendMessageW(lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw);
1620 * Redo the layout of the control.
1622 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1624 CBCalcPlacement(lphc->self,
1625 lphc,
1626 &lphc->textRect,
1627 &lphc->buttonRect,
1628 &lphc->droppedRect);
1630 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1632 else
1634 CBForceDummyResize(lphc);
1639 /***********************************************************************
1640 * COMBO_SetItemHeight
1642 static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
1644 LRESULT lRet = CB_ERR;
1646 if( index == -1 ) /* set text field height */
1648 if( height < 32768 )
1650 lphc->editHeight = height;
1653 * Redo the layout of the control.
1655 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1657 CBCalcPlacement(lphc->self,
1658 lphc,
1659 &lphc->textRect,
1660 &lphc->buttonRect,
1661 &lphc->droppedRect);
1663 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1665 else
1667 CBForceDummyResize(lphc);
1670 lRet = height;
1673 else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */
1674 lRet = SendMessageW(lphc->hWndLBox, LB_SETITEMHEIGHT,
1675 (WPARAM)index, (LPARAM)height );
1676 return lRet;
1679 /***********************************************************************
1680 * COMBO_SelectString
1682 static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPARAM pText, BOOL unicode )
1684 INT index = unicode ? SendMessageW(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText) :
1685 SendMessageA(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText);
1686 if( index >= 0 )
1688 if( lphc->wState & CBF_EDIT )
1689 CBUpdateEdit( lphc, index );
1690 else
1692 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1695 return (LRESULT)index;
1698 /***********************************************************************
1699 * COMBO_LButtonDown
1701 static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam )
1703 POINT pt;
1704 BOOL bButton;
1705 HWND hWnd = lphc->self;
1707 pt.x = (short)LOWORD(lParam);
1708 pt.y = (short)HIWORD(lParam);
1709 bButton = PtInRect(&lphc->buttonRect, pt);
1711 if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) ||
1712 (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) )
1714 lphc->wState |= CBF_BUTTONDOWN;
1715 if( lphc->wState & CBF_DROPPED )
1717 /* got a click to cancel selection */
1719 lphc->wState &= ~CBF_BUTTONDOWN;
1720 CBRollUp( lphc, TRUE, FALSE );
1721 if( !IsWindow( hWnd ) ) return;
1723 if( lphc->wState & CBF_CAPTURE )
1725 lphc->wState &= ~CBF_CAPTURE;
1726 ReleaseCapture();
1729 else
1731 /* drop down the listbox and start tracking */
1733 lphc->wState |= CBF_CAPTURE;
1734 SetCapture( hWnd );
1735 CBDropDown( lphc );
1737 if( bButton ) CBRepaintButton( lphc );
1741 /***********************************************************************
1742 * COMBO_LButtonUp
1744 * Release capture and stop tracking if needed.
1746 static void COMBO_LButtonUp( LPHEADCOMBO lphc )
1748 if( lphc->wState & CBF_CAPTURE )
1750 lphc->wState &= ~CBF_CAPTURE;
1751 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1753 INT index = CBUpdateLBox( lphc, TRUE );
1754 /* Update edit only if item is in the list */
1755 if(index >= 0)
1757 lphc->wState |= CBF_NOLBSELECT;
1758 CBUpdateEdit( lphc, index );
1759 lphc->wState &= ~CBF_NOLBSELECT;
1762 ReleaseCapture();
1763 SetCapture(lphc->hWndLBox);
1766 if( lphc->wState & CBF_BUTTONDOWN )
1768 lphc->wState &= ~CBF_BUTTONDOWN;
1769 CBRepaintButton( lphc );
1773 /***********************************************************************
1774 * COMBO_MouseMove
1776 * Two things to do - track combo button and release capture when
1777 * pointer goes into the listbox.
1779 static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam )
1781 POINT pt;
1782 RECT lbRect;
1784 pt.x = (short)LOWORD(lParam);
1785 pt.y = (short)HIWORD(lParam);
1787 if( lphc->wState & CBF_BUTTONDOWN )
1789 BOOL bButton;
1791 bButton = PtInRect(&lphc->buttonRect, pt);
1793 if( !bButton )
1795 lphc->wState &= ~CBF_BUTTONDOWN;
1796 CBRepaintButton( lphc );
1800 GetClientRect( lphc->hWndLBox, &lbRect );
1801 MapWindowPoints( lphc->self, lphc->hWndLBox, &pt, 1 );
1802 if( PtInRect(&lbRect, pt) )
1804 lphc->wState &= ~CBF_CAPTURE;
1805 ReleaseCapture();
1806 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc, TRUE );
1808 /* hand over pointer tracking */
1809 SendMessageW(lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam);
1813 static LRESULT COMBO_GetComboBoxInfo(LPHEADCOMBO lphc, COMBOBOXINFO *pcbi)
1815 if (!pcbi || (pcbi->cbSize < sizeof(COMBOBOXINFO)))
1816 return FALSE;
1818 pcbi->rcItem = lphc->textRect;
1819 pcbi->rcButton = lphc->buttonRect;
1820 pcbi->stateButton = 0;
1821 if (lphc->wState & CBF_BUTTONDOWN)
1822 pcbi->stateButton |= STATE_SYSTEM_PRESSED;
1823 if (IsRectEmpty(&lphc->buttonRect))
1824 pcbi->stateButton |= STATE_SYSTEM_INVISIBLE;
1825 pcbi->hwndCombo = lphc->self;
1826 pcbi->hwndItem = lphc->hWndEdit;
1827 pcbi->hwndList = lphc->hWndLBox;
1828 return TRUE;
1831 static char *strdupA(LPCSTR str)
1833 char *ret;
1834 DWORD len;
1836 if(!str) return NULL;
1838 len = strlen(str);
1839 ret = HeapAlloc(GetProcessHeap(), 0, len + 1);
1840 memcpy(ret, str, len + 1);
1841 return ret;
1844 /***********************************************************************
1845 * ComboWndProc_common
1847 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxes.asp
1849 static LRESULT ComboWndProc_common( HWND hwnd, UINT message,
1850 WPARAM wParam, LPARAM lParam, BOOL unicode )
1852 LPHEADCOMBO lphc = (LPHEADCOMBO)GetWindowLongPtrW( hwnd, 0 );
1854 TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1855 hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1857 if( lphc || message == WM_NCCREATE )
1858 switch(message)
1861 /* System messages */
1863 case WM_NCCREATE:
1865 LONG style = unicode ? ((LPCREATESTRUCTW)lParam)->style :
1866 ((LPCREATESTRUCTA)lParam)->style;
1867 return COMBO_NCCreate(hwnd, style);
1869 case WM_NCDESTROY:
1870 COMBO_NCDestroy(lphc);
1871 break;/* -> DefWindowProc */
1873 case WM_CREATE:
1875 HWND hwndParent;
1876 LONG style;
1877 if(unicode)
1879 hwndParent = ((LPCREATESTRUCTW)lParam)->hwndParent;
1880 style = ((LPCREATESTRUCTW)lParam)->style;
1882 else
1884 hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent;
1885 style = ((LPCREATESTRUCTA)lParam)->style;
1887 return COMBO_Create(hwnd, lphc, hwndParent, style, unicode);
1890 case WM_PRINTCLIENT:
1891 /* Fallthrough */
1892 case WM_PAINT:
1893 /* wParam may contain a valid HDC! */
1894 return COMBO_Paint(lphc, (HDC)wParam);
1896 case WM_ERASEBKGND:
1897 /* do all painting in WM_PAINT like Windows does */
1898 return 1;
1900 case WM_GETDLGCODE:
1902 LRESULT result = DLGC_WANTARROWS | DLGC_WANTCHARS;
1903 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1905 int vk = (int)((LPMSG)lParam)->wParam;
1907 if ((vk == VK_RETURN || vk == VK_ESCAPE) && (lphc->wState & CBF_DROPPED))
1908 result |= DLGC_WANTMESSAGE;
1910 return result;
1912 case WM_WINDOWPOSCHANGING:
1913 return COMBO_WindowPosChanging(hwnd, lphc, (LPWINDOWPOS)lParam);
1914 case WM_WINDOWPOSCHANGED:
1915 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1916 * In that case, the Combobox itself will not be resized, so we won't
1917 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1918 * do it here.
1920 /* we should not force repainting on WM_WINDOWPOSCHANGED, it breaks
1921 * Z-order based painting.
1923 /* fall through */
1924 case WM_SIZE:
1925 if( lphc->hWndLBox &&
1926 !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc, message == WM_SIZE );
1927 return TRUE;
1928 case WM_SETFONT:
1929 COMBO_Font( lphc, (HFONT)wParam, (BOOL)lParam );
1930 return TRUE;
1931 case WM_GETFONT:
1932 return (LRESULT)lphc->hFont;
1933 case WM_SETFOCUS:
1934 if( lphc->wState & CBF_EDIT )
1935 SetFocus( lphc->hWndEdit );
1936 else
1937 COMBO_SetFocus( lphc );
1938 return TRUE;
1939 case WM_KILLFOCUS:
1941 HWND hwndFocus = WIN_GetFullHandle( (HWND)wParam );
1942 if( !hwndFocus ||
1943 (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox ))
1944 COMBO_KillFocus( lphc );
1945 return TRUE;
1947 case WM_COMMAND:
1948 return COMBO_Command( lphc, wParam, WIN_GetFullHandle( (HWND)lParam ) );
1949 case WM_GETTEXT:
1950 return unicode ? COMBO_GetTextW( lphc, wParam, (LPWSTR)lParam )
1951 : COMBO_GetTextA( lphc, wParam, (LPSTR)lParam );
1952 case WM_SETTEXT:
1953 case WM_GETTEXTLENGTH:
1954 case WM_CLEAR:
1955 if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT))
1957 int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1958 if (j == -1) return 0;
1959 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0) :
1960 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, j, 0);
1962 else if( lphc->wState & CBF_EDIT )
1964 LRESULT ret;
1965 lphc->wState |= CBF_NOEDITNOTIFY;
1966 ret = unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1967 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1968 lphc->wState &= ~CBF_NOEDITNOTIFY;
1969 return ret;
1971 else return CB_ERR;
1972 case WM_CUT:
1973 case WM_PASTE:
1974 case WM_COPY:
1975 if( lphc->wState & CBF_EDIT )
1977 return unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1978 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1980 else return CB_ERR;
1982 case WM_DRAWITEM:
1983 case WM_DELETEITEM:
1984 case WM_COMPAREITEM:
1985 case WM_MEASUREITEM:
1986 return COMBO_ItemOp(lphc, message, lParam);
1987 case WM_ENABLE:
1988 if( lphc->wState & CBF_EDIT )
1989 EnableWindow( lphc->hWndEdit, (BOOL)wParam );
1990 EnableWindow( lphc->hWndLBox, (BOOL)wParam );
1992 /* Force the control to repaint when the enabled state changes. */
1993 InvalidateRect(lphc->self, NULL, TRUE);
1994 return TRUE;
1995 case WM_SETREDRAW:
1996 if( wParam )
1997 lphc->wState &= ~CBF_NOREDRAW;
1998 else
1999 lphc->wState |= CBF_NOREDRAW;
2001 if( lphc->wState & CBF_EDIT )
2002 SendMessageW(lphc->hWndEdit, message, wParam, lParam);
2003 SendMessageW(lphc->hWndLBox, message, wParam, lParam);
2004 return 0;
2005 case WM_SYSKEYDOWN:
2006 if( KEYDATA_ALT & HIWORD(lParam) )
2007 if( wParam == VK_UP || wParam == VK_DOWN )
2008 COMBO_FlipListbox( lphc, FALSE, FALSE );
2009 return 0;
2011 case WM_CHAR:
2012 case WM_IME_CHAR:
2013 case WM_KEYDOWN:
2015 HWND hwndTarget;
2017 if ((wParam == VK_RETURN || wParam == VK_ESCAPE) &&
2018 (lphc->wState & CBF_DROPPED))
2020 CBRollUp( lphc, wParam == VK_RETURN, FALSE );
2021 return TRUE;
2023 else if ((wParam == VK_F4) && !(lphc->wState & CBF_EUI))
2025 COMBO_FlipListbox( lphc, FALSE, FALSE );
2026 return TRUE;
2029 if( lphc->wState & CBF_EDIT )
2030 hwndTarget = lphc->hWndEdit;
2031 else
2032 hwndTarget = lphc->hWndLBox;
2034 return unicode ? SendMessageW(hwndTarget, message, wParam, lParam) :
2035 SendMessageA(hwndTarget, message, wParam, lParam);
2037 case WM_LBUTTONDOWN:
2038 if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self );
2039 if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
2040 return TRUE;
2041 case WM_LBUTTONUP:
2042 COMBO_LButtonUp( lphc );
2043 return TRUE;
2044 case WM_MOUSEMOVE:
2045 if( lphc->wState & CBF_CAPTURE )
2046 COMBO_MouseMove( lphc, wParam, lParam );
2047 return TRUE;
2049 case WM_MOUSEWHEEL:
2050 if (wParam & (MK_SHIFT | MK_CONTROL))
2051 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2052 DefWindowProcA(hwnd, message, wParam, lParam);
2054 if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_UP, 0);
2055 if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_DOWN, 0);
2056 return TRUE;
2058 /* Combo messages */
2060 case CB_ADDSTRING16:
2061 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2062 /* fall through */
2063 case CB_ADDSTRING:
2064 if( unicode )
2066 if( lphc->dwStyle & CBS_LOWERCASE )
2067 CharLowerW((LPWSTR)lParam);
2068 else if( lphc->dwStyle & CBS_UPPERCASE )
2069 CharUpperW((LPWSTR)lParam);
2070 return SendMessageW(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2072 else /* unlike the unicode version, the ansi version does not overwrite
2073 the string if converting case */
2075 char *string = NULL;
2076 LRESULT ret;
2077 if( lphc->dwStyle & CBS_LOWERCASE )
2079 string = strdupA((LPSTR)lParam);
2080 CharLowerA(string);
2083 else if( lphc->dwStyle & CBS_UPPERCASE )
2085 string = strdupA((LPSTR)lParam);
2086 CharUpperA(string);
2089 ret = SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, string ? (LPARAM)string : lParam);
2090 HeapFree(GetProcessHeap(), 0, string);
2091 return ret;
2093 case CB_INSERTSTRING16:
2094 wParam = (INT)(INT16)wParam;
2095 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2096 /* fall through */
2097 case CB_INSERTSTRING:
2098 if( unicode )
2100 if( lphc->dwStyle & CBS_LOWERCASE )
2101 CharLowerW((LPWSTR)lParam);
2102 else if( lphc->dwStyle & CBS_UPPERCASE )
2103 CharUpperW((LPWSTR)lParam);
2104 return SendMessageW(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2106 else
2108 if( lphc->dwStyle & CBS_LOWERCASE )
2109 CharLowerA((LPSTR)lParam);
2110 else if( lphc->dwStyle & CBS_UPPERCASE )
2111 CharUpperA((LPSTR)lParam);
2113 return SendMessageA(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2115 case CB_DELETESTRING16:
2116 case CB_DELETESTRING:
2117 return unicode ? SendMessageW(lphc->hWndLBox, LB_DELETESTRING, wParam, 0) :
2118 SendMessageA(lphc->hWndLBox, LB_DELETESTRING, wParam, 0);
2119 case CB_SELECTSTRING16:
2120 wParam = (INT)(INT16)wParam;
2121 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2122 /* fall through */
2123 case CB_SELECTSTRING:
2124 return COMBO_SelectString(lphc, (INT)wParam, lParam, unicode);
2125 case CB_FINDSTRING16:
2126 wParam = (INT)(INT16)wParam;
2127 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2128 /* fall through */
2129 case CB_FINDSTRING:
2130 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam) :
2131 SendMessageA(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam);
2132 case CB_FINDSTRINGEXACT16:
2133 wParam = (INT)(INT16)wParam;
2134 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2135 /* fall through */
2136 case CB_FINDSTRINGEXACT:
2137 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam) :
2138 SendMessageA(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam);
2139 case CB_SETITEMHEIGHT16:
2140 wParam = (INT)(INT16)wParam; /* signed integer */
2141 /* fall through */
2142 case CB_SETITEMHEIGHT:
2143 return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam);
2144 case CB_GETITEMHEIGHT16:
2145 wParam = (INT)(INT16)wParam;
2146 /* fall through */
2147 case CB_GETITEMHEIGHT:
2148 if( (INT)wParam >= 0 ) /* listbox item */
2149 return SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0);
2150 return CBGetTextAreaHeight(hwnd, lphc);
2151 case CB_RESETCONTENT16:
2152 case CB_RESETCONTENT:
2153 SendMessageW(lphc->hWndLBox, LB_RESETCONTENT, 0, 0);
2154 if( (lphc->wState & CBF_EDIT) && CB_HASSTRINGS(lphc) )
2156 static const WCHAR empty_stringW[] = { 0 };
2157 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);
2159 else
2160 InvalidateRect(lphc->self, NULL, TRUE);
2161 return TRUE;
2162 case CB_INITSTORAGE:
2163 return SendMessageW(lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam);
2164 case CB_GETHORIZONTALEXTENT:
2165 return SendMessageW(lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0);
2166 case CB_SETHORIZONTALEXTENT:
2167 return SendMessageW(lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0);
2168 case CB_GETTOPINDEX:
2169 return SendMessageW(lphc->hWndLBox, LB_GETTOPINDEX, 0, 0);
2170 case CB_GETLOCALE:
2171 return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0);
2172 case CB_SETLOCALE:
2173 return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0);
2174 case CB_GETDROPPEDWIDTH:
2175 if( lphc->droppedWidth )
2176 return lphc->droppedWidth;
2177 return lphc->droppedRect.right - lphc->droppedRect.left;
2178 case CB_SETDROPPEDWIDTH:
2179 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) &&
2180 (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam;
2181 return CB_ERR;
2182 case CB_GETDROPPEDCONTROLRECT16:
2183 lParam = (LPARAM)MapSL(lParam);
2184 if( lParam )
2186 RECT r;
2187 RECT16 *r16 = (RECT16 *)lParam;
2188 CBGetDroppedControlRect( lphc, &r );
2189 r16->left = r.left;
2190 r16->top = r.top;
2191 r16->right = r.right;
2192 r16->bottom = r.bottom;
2194 return CB_OKAY;
2195 case CB_GETDROPPEDCONTROLRECT:
2196 if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam );
2197 return CB_OKAY;
2198 case CB_GETDROPPEDSTATE16:
2199 case CB_GETDROPPEDSTATE:
2200 return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE;
2201 case CB_DIR16:
2202 return SendMessageA(lphc->hWndLBox, LB_DIR16, wParam, lParam);
2203 case CB_DIR:
2204 return unicode ? SendMessageW(lphc->hWndLBox, LB_DIR, wParam, lParam) :
2205 SendMessageA(lphc->hWndLBox, LB_DIR, wParam, lParam);
2207 case CB_SHOWDROPDOWN16:
2208 case CB_SHOWDROPDOWN:
2209 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
2211 if( wParam )
2213 if( !(lphc->wState & CBF_DROPPED) )
2214 CBDropDown( lphc );
2216 else
2217 if( lphc->wState & CBF_DROPPED )
2218 CBRollUp( lphc, FALSE, TRUE );
2220 return TRUE;
2221 case CB_GETCOUNT16:
2222 case CB_GETCOUNT:
2223 return SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
2224 case CB_GETCURSEL16:
2225 case CB_GETCURSEL:
2226 return SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
2227 case CB_SETCURSEL16:
2228 wParam = (INT)(INT16)wParam;
2229 /* fall through */
2230 case CB_SETCURSEL:
2231 lParam = SendMessageW(lphc->hWndLBox, LB_SETCURSEL, wParam, 0);
2232 if( lParam >= 0 )
2233 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, wParam, 0);
2235 /* no LBN_SELCHANGE in this case, update manually */
2236 if( lphc->wState & CBF_EDIT )
2237 CBUpdateEdit( lphc, (INT)wParam );
2238 else
2239 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
2240 lphc->wState &= ~CBF_SELCHANGE;
2241 return lParam;
2242 case CB_GETLBTEXT16:
2243 wParam = (INT)(INT16)wParam;
2244 lParam = (LPARAM)MapSL(lParam);
2245 /* fall through */
2246 case CB_GETLBTEXT:
2247 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXT, wParam, lParam) :
2248 SendMessageA(lphc->hWndLBox, LB_GETTEXT, wParam, lParam);
2249 case CB_GETLBTEXTLEN16:
2250 wParam = (INT)(INT16)wParam;
2251 /* fall through */
2252 case CB_GETLBTEXTLEN:
2253 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0) :
2254 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0);
2255 case CB_GETITEMDATA16:
2256 wParam = (INT)(INT16)wParam;
2257 /* fall through */
2258 case CB_GETITEMDATA:
2259 return SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0);
2260 case CB_SETITEMDATA16:
2261 wParam = (INT)(INT16)wParam;
2262 /* fall through */
2263 case CB_SETITEMDATA:
2264 return SendMessageW(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam);
2265 case CB_GETEDITSEL16:
2266 wParam = lParam = 0; /* just in case */
2267 /* fall through */
2268 case CB_GETEDITSEL:
2269 /* Edit checks passed parameters itself */
2270 if( lphc->wState & CBF_EDIT )
2271 return SendMessageW(lphc->hWndEdit, EM_GETSEL, wParam, lParam);
2272 return CB_ERR;
2273 case CB_SETEDITSEL16:
2274 case CB_SETEDITSEL:
2275 if( lphc->wState & CBF_EDIT )
2276 return SendMessageW(lphc->hWndEdit, EM_SETSEL,
2277 (INT)(INT16)LOWORD(lParam), (INT)(INT16)HIWORD(lParam) );
2278 return CB_ERR;
2279 case CB_SETEXTENDEDUI16:
2280 case CB_SETEXTENDEDUI:
2281 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
2282 return CB_ERR;
2283 if( wParam )
2284 lphc->wState |= CBF_EUI;
2285 else lphc->wState &= ~CBF_EUI;
2286 return CB_OKAY;
2287 case CB_GETEXTENDEDUI16:
2288 case CB_GETEXTENDEDUI:
2289 return (lphc->wState & CBF_EUI) ? TRUE : FALSE;
2290 case CB_GETCOMBOBOXINFO:
2291 return COMBO_GetComboBoxInfo(lphc, (COMBOBOXINFO *)lParam);
2292 case CB_LIMITTEXT:
2293 if( lphc->wState & CBF_EDIT )
2294 return SendMessageW(lphc->hWndEdit, EM_LIMITTEXT, wParam, lParam);
2295 default:
2296 if (message >= WM_USER)
2297 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2298 message - WM_USER, wParam, lParam );
2299 break;
2301 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2302 DefWindowProcA(hwnd, message, wParam, lParam);
2305 /***********************************************************************
2306 * ComboWndProcA
2308 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2309 * window structs.
2311 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2313 if (!IsWindow(hwnd)) return 0;
2314 return ComboWndProc_common( hwnd, message, wParam, lParam, FALSE );
2317 /***********************************************************************
2318 * ComboWndProcW
2320 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2322 if (!IsWindow(hwnd)) return 0;
2323 return ComboWndProc_common( hwnd, message, wParam, lParam, TRUE );
2326 /*************************************************************************
2327 * GetComboBoxInfo (USER32.@)
2329 BOOL WINAPI GetComboBoxInfo(HWND hwndCombo, /* [in] handle to combo box */
2330 PCOMBOBOXINFO pcbi /* [in/out] combo box information */)
2332 TRACE("(%p, %p)\n", hwndCombo, pcbi);
2333 return SendMessageW(hwndCombo, CB_GETCOMBOBOXINFO, 0, (LPARAM)pcbi);