Moved private USER definitions to a new user_private.h header, and
[wine.git] / dlls / user / combo.c
blobe7c53481159adda1b59d6617ab30a104041e520b
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 * - GetComboBoxInfo()
31 * - ComboBox_[GS]etMinVisible()
32 * - CB_GETCOMBOBOXINFO
33 * - CB_GETMINVISIBLE, CB_SETMINVISIBLE
34 * - CB_LIMITTEXT
35 * - CB_SETTOPINDEX
38 #include <stdarg.h>
39 #include <string.h>
41 #include "windef.h"
42 #include "winbase.h"
43 #include "wingdi.h"
44 #include "winuser.h"
45 #include "wine/winuser16.h"
46 #include "wine/unicode.h"
47 #include "message.h"
48 #include "win.h"
49 #include "controls.h"
50 #include "winreg.h"
51 #include "winternl.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(combo);
56 /* bits in the dwKeyData */
57 #define KEYDATA_ALT 0x2000
58 #define KEYDATA_PREVSTATE 0x4000
61 * Additional combo box definitions
64 #define CB_NOTIFY( lphc, code ) \
65 (SendMessageW((lphc)->owner, WM_COMMAND, \
66 MAKEWPARAM(GetWindowLongPtrW((lphc)->self,GWLP_ID), (code)), (LPARAM)(lphc)->self))
68 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
69 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
70 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
71 #define CB_HWND( lphc ) ((lphc)->self)
72 #define CB_GETTYPE( lphc ) ((lphc)->dwStyle & (CBS_DROPDOWNLIST))
74 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
77 * Drawing globals
79 static HBITMAP hComboBmp = 0;
80 static UINT CBitHeight, CBitWidth;
83 * Look and feel dependent "constants"
86 #define COMBO_YBORDERGAP 5
87 #define COMBO_XBORDERSIZE() 2
88 #define COMBO_YBORDERSIZE() 2
89 #define COMBO_EDITBUTTONSPACE() 0
90 #define EDIT_CONTROL_PADDING() 1
92 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
93 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
95 /*********************************************************************
96 * combo class descriptor
98 const struct builtin_class_descr COMBO_builtin_class =
100 "ComboBox", /* name */
101 CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, /* style */
102 ComboWndProcA, /* procA */
103 ComboWndProcW, /* procW */
104 sizeof(HEADCOMBO *), /* extra */
105 IDC_ARROW, /* cursor */
106 0 /* brush */
110 /***********************************************************************
111 * COMBO_Init
113 * Load combo button bitmap.
115 static BOOL COMBO_Init()
117 HDC hDC;
119 if( hComboBmp ) return TRUE;
120 if( (hDC = CreateCompatibleDC(0)) )
122 BOOL bRet = FALSE;
123 if( (hComboBmp = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO))) )
125 BITMAP bm;
126 HBITMAP hPrevB;
127 RECT r;
129 GetObjectW( hComboBmp, sizeof(bm), &bm );
130 CBitHeight = bm.bmHeight;
131 CBitWidth = bm.bmWidth;
133 TRACE("combo bitmap [%i,%i]\n", CBitWidth, CBitHeight );
135 hPrevB = SelectObject( hDC, hComboBmp);
136 SetRect( &r, 0, 0, CBitWidth, CBitHeight );
137 InvertRect( hDC, &r );
138 SelectObject( hDC, hPrevB );
139 bRet = TRUE;
141 DeleteDC( hDC );
142 return bRet;
144 return FALSE;
147 /***********************************************************************
148 * COMBO_NCCreate
150 static LRESULT COMBO_NCCreate(HWND hwnd, LONG style)
152 LPHEADCOMBO lphc;
154 if (COMBO_Init() && (lphc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEADCOMBO))) )
156 lphc->self = hwnd;
157 SetWindowLongW( hwnd, 0, (LONG)lphc );
159 /* some braindead apps do try to use scrollbar/border flags */
161 lphc->dwStyle = style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
162 SetWindowLongW( hwnd, GWL_STYLE, style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL) );
165 * We also have to remove the client edge style to make sure
166 * we don't end-up with a non client area.
168 SetWindowLongW( hwnd, GWL_EXSTYLE,
169 GetWindowLongW( hwnd, GWL_EXSTYLE ) & ~WS_EX_CLIENTEDGE );
171 if( !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
172 lphc->dwStyle |= CBS_HASSTRINGS;
173 if( !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) )
174 lphc->wState |= CBF_NOTIFY;
176 TRACE("[%p], style = %08x\n", lphc, lphc->dwStyle );
177 return TRUE;
179 return FALSE;
182 /***********************************************************************
183 * COMBO_NCDestroy
185 static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc )
188 if( lphc )
190 TRACE("[%p]: freeing storage\n", lphc->self);
192 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && lphc->hWndLBox )
193 DestroyWindow( lphc->hWndLBox );
195 SetWindowLongW( lphc->self, 0, 0 );
196 HeapFree( GetProcessHeap(), 0, lphc );
198 return 0;
201 /***********************************************************************
202 * CBGetTextAreaHeight
204 * This method will calculate the height of the text area of the
205 * combobox.
206 * The height of the text area is set in two ways.
207 * It can be set explicitly through a combobox message or through a
208 * WM_MEASUREITEM callback.
209 * If this is not the case, the height is set to 13 dialog units.
210 * This height was determined through experimentation.
212 static INT CBGetTextAreaHeight(
213 HWND hwnd,
214 LPHEADCOMBO lphc)
216 INT iTextItemHeight;
218 if( lphc->editHeight ) /* explicitly set height */
220 iTextItemHeight = lphc->editHeight;
222 else
224 TEXTMETRICW tm;
225 HDC hDC = GetDC(hwnd);
226 HFONT hPrevFont = 0;
227 INT baseUnitY;
229 if (lphc->hFont)
230 hPrevFont = SelectObject( hDC, lphc->hFont );
232 GetTextMetricsW(hDC, &tm);
234 baseUnitY = tm.tmHeight;
236 if( hPrevFont )
237 SelectObject( hDC, hPrevFont );
239 ReleaseDC(hwnd, hDC);
241 iTextItemHeight = ((13 * baseUnitY) / 8);
244 * This "formula" calculates the height of the complete control.
245 * To calculate the height of the text area, we have to remove the
246 * borders.
248 iTextItemHeight -= 2*COMBO_YBORDERSIZE();
252 * Check the ownerdraw case if we haven't asked the parent the size
253 * of the item yet.
255 if ( CB_OWNERDRAWN(lphc) &&
256 (lphc->wState & CBF_MEASUREITEM) )
258 MEASUREITEMSTRUCT measureItem;
259 RECT clientRect;
260 INT originalItemHeight = iTextItemHeight;
261 UINT id = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
264 * We use the client rect for the width of the item.
266 GetClientRect(hwnd, &clientRect);
268 lphc->wState &= ~CBF_MEASUREITEM;
271 * Send a first one to measure the size of the text area
273 measureItem.CtlType = ODT_COMBOBOX;
274 measureItem.CtlID = id;
275 measureItem.itemID = -1;
276 measureItem.itemWidth = clientRect.right;
277 measureItem.itemHeight = iTextItemHeight - 6; /* ownerdrawn cb is taller */
278 measureItem.itemData = 0;
279 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
280 iTextItemHeight = 6 + measureItem.itemHeight;
283 * Send a second one in the case of a fixed ownerdraw list to calculate the
284 * size of the list items. (we basically do this on behalf of the listbox)
286 if (lphc->dwStyle & CBS_OWNERDRAWFIXED)
288 measureItem.CtlType = ODT_COMBOBOX;
289 measureItem.CtlID = id;
290 measureItem.itemID = 0;
291 measureItem.itemWidth = clientRect.right;
292 measureItem.itemHeight = originalItemHeight;
293 measureItem.itemData = 0;
294 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
295 lphc->fixedOwnerDrawHeight = measureItem.itemHeight;
299 * Keep the size for the next time
301 lphc->editHeight = iTextItemHeight;
304 return iTextItemHeight;
307 /***********************************************************************
308 * CBForceDummyResize
310 * The dummy resize is used for listboxes that have a popup to trigger
311 * a re-arranging of the contents of the combobox and the recalculation
312 * of the size of the "real" control window.
314 static void CBForceDummyResize(
315 LPHEADCOMBO lphc)
317 RECT windowRect;
318 int newComboHeight;
320 newComboHeight = CBGetTextAreaHeight(lphc->self,lphc) + 2*COMBO_YBORDERSIZE();
322 GetWindowRect(lphc->self, &windowRect);
325 * We have to be careful, resizing a combobox also has the meaning that the
326 * dropped rect will be resized. In this case, we want to trigger a resize
327 * to recalculate layout but we don't want to change the dropped rectangle
328 * So, we pass the height of text area of control as the height.
329 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
330 * message.
332 SetWindowPos( lphc->self,
333 NULL,
334 0, 0,
335 windowRect.right - windowRect.left,
336 newComboHeight,
337 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
340 /***********************************************************************
341 * CBCalcPlacement
343 * Set up component coordinates given valid lphc->RectCombo.
345 static void CBCalcPlacement(
346 HWND hwnd,
347 LPHEADCOMBO lphc,
348 LPRECT lprEdit,
349 LPRECT lprButton,
350 LPRECT lprLB)
353 * Again, start with the client rectangle.
355 GetClientRect(hwnd, lprEdit);
358 * Remove the borders
360 InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
363 * Chop off the bottom part to fit with the height of the text area.
365 lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
368 * The button starts the same vertical position as the text area.
370 CopyRect(lprButton, lprEdit);
373 * If the combobox is "simple" there is no button.
375 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
376 lprButton->left = lprButton->right = lprButton->bottom = 0;
377 else
380 * Let's assume the combobox button is the same width as the
381 * scrollbar button.
382 * size the button horizontally and cut-off the text area.
384 lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
385 lprEdit->right = lprButton->left;
389 * In the case of a dropdown, there is an additional spacing between the
390 * text area and the button.
392 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
394 lprEdit->right -= COMBO_EDITBUTTONSPACE();
398 * If we have an edit control, we space it away from the borders slightly.
400 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
402 InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
406 * Adjust the size of the listbox popup.
408 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
411 * Use the client rectangle to initialize the listbox rectangle
413 GetClientRect(hwnd, lprLB);
416 * Then, chop-off the top part.
418 lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
420 else
423 * Make sure the dropped width is as large as the combobox itself.
425 if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
427 lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
430 * In the case of a dropdown, the popup listbox is offset to the right.
431 * so, we want to make sure it's flush with the right side of the
432 * combobox
434 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
435 lprLB->right -= COMBO_EDITBUTTONSPACE();
437 else
438 lprLB->right = lprLB->left + lphc->droppedWidth;
441 TRACE("\ttext\t= (%ld,%ld-%ld,%ld)\n",
442 lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom);
444 TRACE("\tbutton\t= (%ld,%ld-%ld,%ld)\n",
445 lprButton->left, lprButton->top, lprButton->right, lprButton->bottom);
447 TRACE("\tlbox\t= (%ld,%ld-%ld,%ld)\n",
448 lprLB->left, lprLB->top, lprLB->right, lprLB->bottom );
451 /***********************************************************************
452 * CBGetDroppedControlRect
454 static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect)
456 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
457 of the combo box and the lower right corner of the listbox */
459 GetWindowRect(lphc->self, lpRect);
461 lpRect->right = lpRect->left + lphc->droppedRect.right - lphc->droppedRect.left;
462 lpRect->bottom = lpRect->top + lphc->droppedRect.bottom - lphc->droppedRect.top;
466 /***********************************************************************
467 * COMBO_WindowPosChanging
469 static LRESULT COMBO_WindowPosChanging(
470 HWND hwnd,
471 LPHEADCOMBO lphc,
472 WINDOWPOS* posChanging)
475 * We need to override the WM_WINDOWPOSCHANGING method to handle all
476 * the non-simple comboboxes. The problem is that those controls are
477 * always the same height. We have to make sure they are not resized
478 * to another value.
480 if ( ( CB_GETTYPE(lphc) != CBS_SIMPLE ) &&
481 ((posChanging->flags & SWP_NOSIZE) == 0) )
483 int newComboHeight;
485 newComboHeight = CBGetTextAreaHeight(hwnd,lphc) +
486 2*COMBO_YBORDERSIZE();
489 * Resizing a combobox has another side effect, it resizes the dropped
490 * rectangle as well. However, it does it only if the new height for the
491 * combobox is different from the height it should have. In other words,
492 * if the application resizing the combobox only had the intention to resize
493 * the actual control, for example, to do the layout of a dialog that is
494 * resized, the height of the dropdown is not changed.
496 if (posChanging->cy != newComboHeight)
498 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%ld, oldtop=%ld\n",
499 posChanging->cy, newComboHeight, lphc->droppedRect.bottom,
500 lphc->droppedRect.top);
501 lphc->droppedRect.bottom = lphc->droppedRect.top + posChanging->cy - newComboHeight;
503 posChanging->cy = newComboHeight;
507 return 0;
510 /***********************************************************************
511 * COMBO_Create
513 static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style,
514 BOOL unicode )
516 static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0};
517 static const WCHAR editName[] = {'E','d','i','t',0};
519 if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE;
520 if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT;
522 lphc->owner = hwndParent;
525 * The item height and dropped width are not set when the control
526 * is created.
528 lphc->droppedWidth = lphc->editHeight = 0;
531 * The first time we go through, we want to measure the ownerdraw item
533 lphc->wState |= CBF_MEASUREITEM;
535 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
537 if( lphc->owner || !(style & WS_VISIBLE) )
539 UINT lbeStyle = 0;
540 UINT lbeExStyle = 0;
543 * Initialize the dropped rect to the size of the client area of the
544 * control and then, force all the areas of the combobox to be
545 * recalculated.
547 GetClientRect( hwnd, &lphc->droppedRect );
548 CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
551 * Adjust the position of the popup listbox if it's necessary
553 if ( CB_GETTYPE(lphc) != CBS_SIMPLE )
555 lphc->droppedRect.top = lphc->textRect.bottom + COMBO_YBORDERSIZE();
558 * If it's a dropdown, the listbox is offset
560 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
561 lphc->droppedRect.left += COMBO_EDITBUTTONSPACE();
563 ClientToScreen(hwnd, (LPPOINT)&lphc->droppedRect);
564 ClientToScreen(hwnd, (LPPOINT)&lphc->droppedRect.right);
567 /* create listbox popup */
569 lbeStyle = (LBS_NOTIFY | LBS_COMBOBOX | WS_BORDER | WS_CLIPSIBLINGS | WS_CHILD) |
570 (style & (WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE));
572 if( lphc->dwStyle & CBS_SORT )
573 lbeStyle |= LBS_SORT;
574 if( lphc->dwStyle & CBS_HASSTRINGS )
575 lbeStyle |= LBS_HASSTRINGS;
576 if( lphc->dwStyle & CBS_NOINTEGRALHEIGHT )
577 lbeStyle |= LBS_NOINTEGRALHEIGHT;
578 if( lphc->dwStyle & CBS_DISABLENOSCROLL )
579 lbeStyle |= LBS_DISABLENOSCROLL;
581 if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* child listbox */
583 lbeStyle |= WS_VISIBLE;
586 * In win 95 look n feel, the listbox in the simple combobox has
587 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
589 lbeStyle &= ~WS_BORDER;
590 lbeExStyle |= WS_EX_CLIENTEDGE;
592 else
594 lbeExStyle |= (WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
597 if (unicode)
598 lphc->hWndLBox = CreateWindowExW(lbeExStyle, clbName, NULL, lbeStyle,
599 lphc->droppedRect.left,
600 lphc->droppedRect.top,
601 lphc->droppedRect.right - lphc->droppedRect.left,
602 lphc->droppedRect.bottom - lphc->droppedRect.top,
603 hwnd, (HMENU)ID_CB_LISTBOX,
604 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), lphc );
605 else
606 lphc->hWndLBox = CreateWindowExA(lbeExStyle, "ComboLBox", NULL, lbeStyle,
607 lphc->droppedRect.left,
608 lphc->droppedRect.top,
609 lphc->droppedRect.right - lphc->droppedRect.left,
610 lphc->droppedRect.bottom - lphc->droppedRect.top,
611 hwnd, (HMENU)ID_CB_LISTBOX,
612 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), lphc );
614 if( lphc->hWndLBox )
616 BOOL bEdit = TRUE;
617 lbeStyle = WS_CHILD | WS_VISIBLE | ES_NOHIDESEL | ES_LEFT | ES_COMBO;
619 if( lphc->wState & CBF_EDIT )
621 if( lphc->dwStyle & CBS_OEMCONVERT )
622 lbeStyle |= ES_OEMCONVERT;
623 if( lphc->dwStyle & CBS_AUTOHSCROLL )
624 lbeStyle |= ES_AUTOHSCROLL;
625 if( lphc->dwStyle & CBS_LOWERCASE )
626 lbeStyle |= ES_LOWERCASE;
627 else if( lphc->dwStyle & CBS_UPPERCASE )
628 lbeStyle |= ES_UPPERCASE;
630 if (!IsWindowEnabled(hwnd)) lbeStyle |= WS_DISABLED;
632 if (unicode)
633 lphc->hWndEdit = CreateWindowExW(0, editName, NULL, lbeStyle,
634 lphc->textRect.left, lphc->textRect.top,
635 lphc->textRect.right - lphc->textRect.left,
636 lphc->textRect.bottom - lphc->textRect.top,
637 hwnd, (HMENU)ID_CB_EDIT,
638 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), NULL );
639 else
640 lphc->hWndEdit = CreateWindowExA(0, "Edit", NULL, lbeStyle,
641 lphc->textRect.left, lphc->textRect.top,
642 lphc->textRect.right - lphc->textRect.left,
643 lphc->textRect.bottom - lphc->textRect.top,
644 hwnd, (HMENU)ID_CB_EDIT,
645 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), NULL );
647 if( !lphc->hWndEdit )
648 bEdit = FALSE;
651 if( bEdit )
653 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
655 /* Now do the trick with parent */
656 SetParent(lphc->hWndLBox, HWND_DESKTOP);
658 * If the combo is a dropdown, we must resize the control
659 * to fit only the text area and button. To do this,
660 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
661 * will take care of setting the height for us.
663 CBForceDummyResize(lphc);
666 TRACE("init done\n");
667 return 0;
669 ERR("edit control failure.\n");
670 } else ERR("listbox failure.\n");
671 } else ERR("no owner for visible combo.\n");
673 /* CreateWindow() will send WM_NCDESTROY to cleanup */
675 return -1;
678 /***********************************************************************
679 * CBPaintButton
681 * Paint combo button (normal, pressed, and disabled states).
683 static void CBPaintButton( LPHEADCOMBO lphc, HDC hdc, RECT rectButton)
685 UINT buttonState = DFCS_SCROLLCOMBOBOX;
687 if( lphc->wState & CBF_NOREDRAW )
688 return;
691 if (lphc->wState & CBF_BUTTONDOWN)
692 buttonState |= DFCS_PUSHED;
694 if (CB_DISABLED(lphc))
695 buttonState |= DFCS_INACTIVE;
697 DrawFrameControl(hdc, &rectButton, DFC_SCROLL, buttonState);
700 /***********************************************************************
701 * CBPaintText
703 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
705 static void CBPaintText(
706 LPHEADCOMBO lphc,
707 HDC hdc,
708 RECT rectEdit)
710 INT id, size = 0;
711 LPWSTR pText = NULL;
713 if( lphc->wState & CBF_NOREDRAW ) return;
715 TRACE("\n");
717 /* follow Windows combobox that sends a bunch of text
718 * inquiries to its listbox while processing WM_PAINT. */
720 if( (id = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0) ) != LB_ERR )
722 size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0);
723 if (size == LB_ERR)
724 FIXME("LB_ERR probably not handled yet\n");
725 if( (pText = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))) )
727 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
728 size=SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText);
729 pText[size] = '\0'; /* just in case */
730 } else return;
732 else
733 if( !CB_OWNERDRAWN(lphc) )
734 return;
736 if( lphc->wState & CBF_EDIT )
738 static const WCHAR empty_stringW[] = { 0 };
739 if( CB_HASSTRINGS(lphc) ) SetWindowTextW( lphc->hWndEdit, pText ? pText : empty_stringW );
740 if( lphc->wState & CBF_FOCUSED )
741 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
743 else /* paint text field ourselves */
745 UINT itemState = ODS_COMBOBOXEDIT;
746 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hdc, lphc->hFont) : 0;
749 * Give ourselves some space.
751 InflateRect( &rectEdit, -1, -1 );
753 if( CB_OWNERDRAWN(lphc) )
755 DRAWITEMSTRUCT dis;
756 HRGN clipRegion;
757 UINT ctlid = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
759 /* setup state for DRAWITEM message. Owner will highlight */
760 if ( (lphc->wState & CBF_FOCUSED) &&
761 !(lphc->wState & CBF_DROPPED) )
762 itemState |= ODS_SELECTED | ODS_FOCUS;
765 * Save the current clip region.
766 * To retrieve the clip region, we need to create one "dummy"
767 * clip region.
769 clipRegion = CreateRectRgnIndirect(&rectEdit);
771 if (GetClipRgn(hdc, clipRegion)!=1)
773 DeleteObject(clipRegion);
774 clipRegion=NULL;
777 if (!IsWindowEnabled(lphc->self) & WS_DISABLED) itemState |= ODS_DISABLED;
779 dis.CtlType = ODT_COMBOBOX;
780 dis.CtlID = ctlid;
781 dis.hwndItem = lphc->self;
782 dis.itemAction = ODA_DRAWENTIRE;
783 dis.itemID = id;
784 dis.itemState = itemState;
785 dis.hDC = hdc;
786 dis.rcItem = rectEdit;
787 dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA,
788 (WPARAM)id, 0 );
791 * Clip the DC and have the parent draw the item.
793 IntersectClipRect(hdc,
794 rectEdit.left, rectEdit.top,
795 rectEdit.right, rectEdit.bottom);
797 SendMessageW(lphc->owner, WM_DRAWITEM, ctlid, (LPARAM)&dis );
800 * Reset the clipping region.
802 SelectClipRgn(hdc, clipRegion);
804 else
806 static const WCHAR empty_stringW[] = { 0 };
808 if ( (lphc->wState & CBF_FOCUSED) &&
809 !(lphc->wState & CBF_DROPPED) ) {
811 /* highlight */
812 FillRect( hdc, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) );
813 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
814 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
817 ExtTextOutW( hdc,
818 rectEdit.left + 1,
819 rectEdit.top + 1,
820 ETO_OPAQUE | ETO_CLIPPED,
821 &rectEdit,
822 pText ? pText : empty_stringW , size, NULL );
824 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED))
825 DrawFocusRect( hdc, &rectEdit );
828 if( hPrevFont )
829 SelectObject(hdc, hPrevFont );
831 if (pText)
832 HeapFree( GetProcessHeap(), 0, pText );
835 /***********************************************************************
836 * CBPaintBorder
838 static void CBPaintBorder(
839 HWND hwnd,
840 LPHEADCOMBO lphc,
841 HDC hdc)
843 RECT clientRect;
845 if (CB_GETTYPE(lphc) != CBS_SIMPLE)
847 GetClientRect(hwnd, &clientRect);
849 else
851 CopyRect(&clientRect, &lphc->textRect);
853 InflateRect(&clientRect, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
854 InflateRect(&clientRect, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
857 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_RECT);
860 /***********************************************************************
861 * COMBO_PrepareColors
863 * This method will sent the appropriate WM_CTLCOLOR message to
864 * prepare and setup the colors for the combo's DC.
866 * It also returns the brush to use for the background.
868 static HBRUSH COMBO_PrepareColors(
869 LPHEADCOMBO lphc,
870 HDC hDC)
872 HBRUSH hBkgBrush;
875 * Get the background brush for this control.
877 if (CB_DISABLED(lphc))
879 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORSTATIC,
880 (WPARAM)hDC, (LPARAM)lphc->self );
883 * We have to change the text color since WM_CTLCOLORSTATIC will
884 * set it to the "enabled" color. This is the same behavior as the
885 * edit control
887 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
889 else
891 if (lphc->wState & CBF_EDIT)
893 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLOREDIT,
894 (WPARAM)hDC, (LPARAM)lphc->self );
896 else
898 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORLISTBOX,
899 (WPARAM)hDC, (LPARAM)lphc->self );
904 * Catch errors.
906 if( !hBkgBrush )
907 hBkgBrush = GetSysColorBrush(COLOR_WINDOW);
909 return hBkgBrush;
912 /***********************************************************************
913 * COMBO_EraseBackground
915 static LRESULT COMBO_EraseBackground(
916 HWND hwnd,
917 LPHEADCOMBO lphc,
918 HDC hParamDC)
920 HBRUSH hBkgBrush;
921 HDC hDC;
923 if(lphc->wState & CBF_EDIT)
924 return TRUE;
926 hDC = (hParamDC) ? hParamDC
927 : GetDC(hwnd);
929 * Retrieve the background brush
931 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
933 FillRect(hDC, &lphc->textRect, hBkgBrush);
935 if (!hParamDC)
936 ReleaseDC(hwnd, hDC);
938 return TRUE;
941 /***********************************************************************
942 * COMBO_Paint
944 static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC)
946 PAINTSTRUCT ps;
947 HDC hDC;
949 hDC = (hParamDC) ? hParamDC
950 : BeginPaint( lphc->self, &ps);
952 TRACE("hdc=%p\n", hDC);
954 if( hDC && !(lphc->wState & CBF_NOREDRAW) )
956 HBRUSH hPrevBrush, hBkgBrush;
959 * Retrieve the background brush and select it in the
960 * DC.
962 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
964 hPrevBrush = SelectObject( hDC, hBkgBrush );
967 * In non 3.1 look, there is a sunken border on the combobox
969 CBPaintBorder(lphc->self, lphc, hDC);
971 if( !IsRectEmpty(&lphc->buttonRect) )
973 CBPaintButton(lphc, hDC, lphc->buttonRect);
976 /* paint the edit control padding area */
977 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
979 RECT rPadEdit = lphc->textRect;
981 InflateRect(&rPadEdit, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
983 FrameRect( hDC, &rPadEdit, GetSysColorBrush(COLOR_WINDOW) );
986 if( !(lphc->wState & CBF_EDIT) )
987 CBPaintText( lphc, hDC, lphc->textRect);
989 if( hPrevBrush )
990 SelectObject( hDC, hPrevBrush );
993 if( !hParamDC )
994 EndPaint(lphc->self, &ps);
996 return 0;
999 /***********************************************************************
1000 * CBUpdateLBox
1002 * Select listbox entry according to the contents of the edit control.
1004 static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
1006 INT length, idx;
1007 LPWSTR pText = NULL;
1009 idx = LB_ERR;
1010 length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 );
1012 if( length > 0 )
1013 pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1015 TRACE("\t edit text length %i\n", length );
1017 if( pText )
1019 if( length ) GetWindowTextW( lphc->hWndEdit, pText, length + 1);
1020 else pText[0] = '\0';
1021 idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING,
1022 (WPARAM)(-1), (LPARAM)pText );
1023 HeapFree( GetProcessHeap(), 0, pText );
1026 SendMessageW(lphc->hWndLBox, LB_SETCURSEL, (WPARAM)(bSelect ? idx : -1), 0);
1028 /* probably superfluous but Windows sends this too */
1029 SendMessageW(lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1030 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1032 return idx;
1035 /***********************************************************************
1036 * CBUpdateEdit
1038 * Copy a listbox entry to the edit control.
1040 static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
1042 INT length;
1043 LPWSTR pText = NULL;
1044 static const WCHAR empty_stringW[] = { 0 };
1046 TRACE("\t %i\n", index );
1048 if( index >= 0 ) /* got an entry */
1050 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0);
1051 if( length != LB_ERR)
1053 if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) )
1055 SendMessageW(lphc->hWndLBox, LB_GETTEXT,
1056 (WPARAM)index, (LPARAM)pText );
1061 lphc->wState |= (CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1062 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, pText ? (LPARAM)pText : (LPARAM)empty_stringW);
1063 lphc->wState &= ~(CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1065 if( lphc->wState & CBF_FOCUSED )
1066 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1068 if( pText )
1069 HeapFree( GetProcessHeap(), 0, pText );
1072 /***********************************************************************
1073 * CBDropDown
1075 * Show listbox popup.
1077 static void CBDropDown( LPHEADCOMBO lphc )
1079 RECT rect,r;
1080 int nItems = 0;
1081 int nDroppedHeight;
1083 TRACE("[%p]: drop down\n", lphc->self);
1085 CB_NOTIFY( lphc, CBN_DROPDOWN );
1087 /* set selection */
1089 lphc->wState |= CBF_DROPPED;
1090 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1092 lphc->droppedIndex = CBUpdateLBox( lphc, TRUE );
1094 /* Update edit only if item is in the list */
1095 if( !(lphc->wState & CBF_CAPTURE) && lphc->droppedIndex >= 0)
1096 CBUpdateEdit( lphc, lphc->droppedIndex );
1098 else
1100 lphc->droppedIndex = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1102 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX,
1103 (WPARAM)(lphc->droppedIndex == LB_ERR ? 0 : lphc->droppedIndex), 0 );
1104 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1107 /* now set popup position */
1108 GetWindowRect( lphc->self, &rect );
1111 * If it's a dropdown, the listbox is offset
1113 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1114 rect.left += COMBO_EDITBUTTONSPACE();
1116 /* if the dropped height is greater than the total height of the dropped
1117 items list, then force the drop down list height to be the total height
1118 of the items in the dropped list */
1120 /* And Remove any extra space (Best Fit) */
1121 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
1122 /* if listbox length has been set directly by its handle */
1123 GetWindowRect(lphc->hWndLBox, &r);
1124 if (nDroppedHeight < r.bottom - r.top)
1125 nDroppedHeight = r.bottom - r.top;
1126 nItems = (int)SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
1128 if (nItems > 0)
1130 int nHeight;
1131 int nIHeight;
1133 nIHeight = (int)SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, 0, 0);
1135 nHeight = nIHeight*nItems;
1137 if (nHeight < nDroppedHeight - COMBO_YBORDERSIZE())
1138 nDroppedHeight = nHeight + COMBO_YBORDERSIZE();
1140 if (nDroppedHeight < nIHeight)
1142 if (nItems < 5)
1143 nDroppedHeight = (nItems+1)*nIHeight;
1144 else
1145 nDroppedHeight = 6*nIHeight;
1149 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1150 if( (rect.bottom + nDroppedHeight) >= GetSystemMetrics( SM_CYSCREEN ) )
1151 rect.bottom = rect.top - nDroppedHeight;
1153 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
1154 lphc->droppedRect.right - lphc->droppedRect.left,
1155 nDroppedHeight,
1156 SWP_NOACTIVATE | SWP_SHOWWINDOW);
1159 if( !(lphc->wState & CBF_NOREDRAW) )
1160 RedrawWindow( lphc->self, NULL, 0, RDW_INVALIDATE |
1161 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1163 EnableWindow( lphc->hWndLBox, TRUE );
1164 if (GetCapture() != lphc->self)
1165 SetCapture(lphc->hWndLBox);
1168 /***********************************************************************
1169 * CBRollUp
1171 * Hide listbox popup.
1173 static void CBRollUp( LPHEADCOMBO lphc, BOOL ok, BOOL bButton )
1175 HWND hWnd = lphc->self;
1177 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1178 lphc->self, (INT)ok, (INT)(lphc->wState & CBF_DROPPED));
1180 CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL );
1182 if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE )
1185 if( lphc->wState & CBF_DROPPED )
1187 RECT rect;
1189 lphc->wState &= ~CBF_DROPPED;
1190 ShowWindow( lphc->hWndLBox, SW_HIDE );
1192 if(GetCapture() == lphc->hWndLBox)
1194 ReleaseCapture();
1197 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1199 rect = lphc->buttonRect;
1201 else
1203 if( bButton )
1205 UnionRect( &rect,
1206 &lphc->buttonRect,
1207 &lphc->textRect);
1209 else
1210 rect = lphc->textRect;
1212 bButton = TRUE;
1215 if( bButton && !(lphc->wState & CBF_NOREDRAW) )
1216 RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE |
1217 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1218 CB_NOTIFY( lphc, CBN_CLOSEUP );
1223 /***********************************************************************
1224 * COMBO_FlipListbox
1226 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1228 BOOL COMBO_FlipListbox( LPHEADCOMBO lphc, BOOL ok, BOOL bRedrawButton )
1230 if( lphc->wState & CBF_DROPPED )
1232 CBRollUp( lphc, ok, bRedrawButton );
1233 return FALSE;
1236 CBDropDown( lphc );
1237 return TRUE;
1240 /***********************************************************************
1241 * CBRepaintButton
1243 static void CBRepaintButton( LPHEADCOMBO lphc )
1245 InvalidateRect(lphc->self, &lphc->buttonRect, TRUE);
1246 UpdateWindow(lphc->self);
1249 /***********************************************************************
1250 * COMBO_SetFocus
1252 static void COMBO_SetFocus( LPHEADCOMBO lphc )
1254 if( !(lphc->wState & CBF_FOCUSED) )
1256 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1257 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1259 /* This is wrong. Message sequences seem to indicate that this
1260 is set *after* the notify. */
1261 /* lphc->wState |= CBF_FOCUSED; */
1263 if( !(lphc->wState & CBF_EDIT) )
1264 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1266 CB_NOTIFY( lphc, CBN_SETFOCUS );
1267 lphc->wState |= CBF_FOCUSED;
1271 /***********************************************************************
1272 * COMBO_KillFocus
1274 static void COMBO_KillFocus( LPHEADCOMBO lphc )
1276 HWND hWnd = lphc->self;
1278 if( lphc->wState & CBF_FOCUSED )
1280 CBRollUp( lphc, FALSE, TRUE );
1281 if( IsWindow( hWnd ) )
1283 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1284 SendMessageW(lphc->hWndLBox, LB_CARETOFF, 0, 0);
1286 lphc->wState &= ~CBF_FOCUSED;
1288 /* redraw text */
1289 if( !(lphc->wState & CBF_EDIT) )
1290 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1292 CB_NOTIFY( lphc, CBN_KILLFOCUS );
1297 /***********************************************************************
1298 * COMBO_Command
1300 static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd )
1302 if ( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd )
1304 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1306 switch( HIWORD(wParam) >> 8 )
1308 case (EN_SETFOCUS >> 8):
1310 TRACE("[%p]: edit [%p] got focus\n", lphc->self, lphc->hWndEdit );
1312 COMBO_SetFocus( lphc );
1313 break;
1315 case (EN_KILLFOCUS >> 8):
1317 TRACE("[%p]: edit [%p] lost focus\n", lphc->self, lphc->hWndEdit );
1319 /* NOTE: it seems that Windows' edit control sends an
1320 * undocumented message WM_USER + 0x1B instead of this
1321 * notification (only when it happens to be a part of
1322 * the combo). ?? - AK.
1325 COMBO_KillFocus( lphc );
1326 break;
1329 case (EN_CHANGE >> 8):
1331 * In some circumstances (when the selection of the combobox
1332 * is changed for example) we don't want the EN_CHANGE notification
1333 * to be forwarded to the parent of the combobox. This code
1334 * checks a flag that is set in these occasions and ignores the
1335 * notification.
1337 if (lphc->wState & CBF_NOLBSELECT)
1339 lphc->wState &= ~CBF_NOLBSELECT;
1341 else
1343 CBUpdateLBox( lphc, lphc->wState & CBF_DROPPED );
1346 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1347 CB_NOTIFY( lphc, CBN_EDITCHANGE );
1348 break;
1350 case (EN_UPDATE >> 8):
1351 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1352 CB_NOTIFY( lphc, CBN_EDITUPDATE );
1353 break;
1355 case (EN_ERRSPACE >> 8):
1356 CB_NOTIFY( lphc, CBN_ERRSPACE );
1359 else if( lphc->hWndLBox == hWnd )
1361 switch( (short)HIWORD(wParam) )
1363 case LBN_ERRSPACE:
1364 CB_NOTIFY( lphc, CBN_ERRSPACE );
1365 break;
1367 case LBN_DBLCLK:
1368 CB_NOTIFY( lphc, CBN_DBLCLK );
1369 break;
1371 case LBN_SELCHANGE:
1372 case LBN_SELCANCEL:
1374 TRACE("[%p]: lbox selection change [%x]\n", lphc->self, lphc->wState );
1376 if( HIWORD(wParam) == LBN_SELCHANGE)
1378 if( lphc->wState & CBF_EDIT )
1380 INT index = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1381 lphc->wState |= CBF_NOLBSELECT;
1382 CBUpdateEdit( lphc, index );
1383 /* select text in edit, as Windows does */
1384 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1386 else
1387 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1390 /* do not roll up if selection is being tracked
1391 * by arrowkeys in the dropdown listbox */
1392 if( ((lphc->wState & CBF_DROPPED) && !(lphc->wState & CBF_NOROLLUP)) )
1394 CBRollUp( lphc, (HIWORD(wParam) == LBN_SELCHANGE), TRUE );
1396 else lphc->wState &= ~CBF_NOROLLUP;
1398 CB_NOTIFY( lphc, CBN_SELCHANGE );
1400 /* fall through */
1402 case LBN_SETFOCUS:
1403 case LBN_KILLFOCUS:
1404 /* nothing to do here since ComboLBox always resets the focus to its
1405 * combo/edit counterpart */
1406 break;
1409 return 0;
1412 /***********************************************************************
1413 * COMBO_ItemOp
1415 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1417 static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
1419 HWND hWnd = lphc->self;
1420 UINT id = (UINT)GetWindowLongPtrW( hWnd, GWLP_ID );
1422 TRACE("[%p]: ownerdraw op %04x\n", lphc->self, msg );
1424 switch( msg )
1426 case WM_DELETEITEM:
1428 DELETEITEMSTRUCT *lpIS = (DELETEITEMSTRUCT *)lParam;
1429 lpIS->CtlType = ODT_COMBOBOX;
1430 lpIS->CtlID = id;
1431 lpIS->hwndItem = hWnd;
1432 break;
1434 case WM_DRAWITEM:
1436 DRAWITEMSTRUCT *lpIS = (DRAWITEMSTRUCT *)lParam;
1437 lpIS->CtlType = ODT_COMBOBOX;
1438 lpIS->CtlID = id;
1439 lpIS->hwndItem = hWnd;
1440 break;
1442 case WM_COMPAREITEM:
1444 COMPAREITEMSTRUCT *lpIS = (COMPAREITEMSTRUCT *)lParam;
1445 lpIS->CtlType = ODT_COMBOBOX;
1446 lpIS->CtlID = id;
1447 lpIS->hwndItem = hWnd;
1448 break;
1450 case WM_MEASUREITEM:
1452 MEASUREITEMSTRUCT *lpIS = (MEASUREITEMSTRUCT *)lParam;
1453 lpIS->CtlType = ODT_COMBOBOX;
1454 lpIS->CtlID = id;
1455 break;
1458 return SendMessageW(lphc->owner, msg, id, lParam);
1462 /***********************************************************************
1463 * COMBO_GetTextW
1465 static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf )
1467 INT length;
1469 if( lphc->wState & CBF_EDIT )
1470 return SendMessageW( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1472 /* get it from the listbox */
1474 if (!count || !buf) return 0;
1475 if( lphc->hWndLBox )
1477 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1478 if (idx == LB_ERR) goto error;
1479 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1480 if (length == LB_ERR) goto error;
1482 /* 'length' is without the terminating character */
1483 if (length >= count)
1485 LPWSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1486 if (!lpBuffer) goto error;
1487 length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1489 /* truncate if buffer is too short */
1490 if (length != LB_ERR)
1492 lstrcpynW( buf, lpBuffer, count );
1493 length = count;
1495 HeapFree( GetProcessHeap(), 0, lpBuffer );
1497 else length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1499 if (length == LB_ERR) return 0;
1500 return length;
1503 error: /* error - truncate string, return zero */
1504 buf[0] = 0;
1505 return 0;
1509 /***********************************************************************
1510 * COMBO_GetTextA
1512 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1513 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1515 static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf )
1517 INT length;
1519 if( lphc->wState & CBF_EDIT )
1520 return SendMessageA( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1522 /* get it from the listbox */
1524 if (!count || !buf) return 0;
1525 if( lphc->hWndLBox )
1527 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1528 if (idx == LB_ERR) goto error;
1529 length = SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1530 if (length == LB_ERR) goto error;
1532 /* 'length' is without the terminating character */
1533 if (length >= count)
1535 LPSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) );
1536 if (!lpBuffer) goto error;
1537 length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1539 /* truncate if buffer is too short */
1540 if (length != LB_ERR)
1542 lstrcpynA( buf, lpBuffer, count );
1543 length = count;
1545 HeapFree( GetProcessHeap(), 0, lpBuffer );
1547 else length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1549 if (length == LB_ERR) return 0;
1550 return length;
1553 error: /* error - truncate string, return zero */
1554 buf[0] = 0;
1555 return 0;
1559 /***********************************************************************
1560 * CBResetPos
1562 * This function sets window positions according to the updated
1563 * component placement struct.
1565 static void CBResetPos(
1566 LPHEADCOMBO lphc,
1567 LPRECT rectEdit,
1568 LPRECT rectLB,
1569 BOOL bRedraw)
1571 BOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE);
1573 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1574 * sizing messages */
1576 if( lphc->wState & CBF_EDIT )
1577 SetWindowPos( lphc->hWndEdit, 0,
1578 rectEdit->left, rectEdit->top,
1579 rectEdit->right - rectEdit->left,
1580 rectEdit->bottom - rectEdit->top,
1581 SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) );
1583 SetWindowPos( lphc->hWndLBox, 0,
1584 rectLB->left, rectLB->top,
1585 rectLB->right - rectLB->left,
1586 rectLB->bottom - rectLB->top,
1587 SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) );
1589 if( bDrop )
1591 if( lphc->wState & CBF_DROPPED )
1593 lphc->wState &= ~CBF_DROPPED;
1594 ShowWindow( lphc->hWndLBox, SW_HIDE );
1597 if( bRedraw && !(lphc->wState & CBF_NOREDRAW) )
1598 RedrawWindow( lphc->self, NULL, 0,
1599 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
1604 /***********************************************************************
1605 * COMBO_Size
1607 static void COMBO_Size( LPHEADCOMBO lphc )
1609 CBCalcPlacement(lphc->self,
1610 lphc,
1611 &lphc->textRect,
1612 &lphc->buttonRect,
1613 &lphc->droppedRect);
1615 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1619 /***********************************************************************
1620 * COMBO_Font
1622 static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
1625 * Set the font
1627 lphc->hFont = hFont;
1630 * Propagate to owned windows.
1632 if( lphc->wState & CBF_EDIT )
1633 SendMessageW(lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw);
1634 SendMessageW(lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw);
1637 * Redo the layout of the control.
1639 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1641 CBCalcPlacement(lphc->self,
1642 lphc,
1643 &lphc->textRect,
1644 &lphc->buttonRect,
1645 &lphc->droppedRect);
1647 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1649 else
1651 CBForceDummyResize(lphc);
1656 /***********************************************************************
1657 * COMBO_SetItemHeight
1659 static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
1661 LRESULT lRet = CB_ERR;
1663 if( index == -1 ) /* set text field height */
1665 if( height < 32768 )
1667 lphc->editHeight = height;
1670 * Redo the layout of the control.
1672 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1674 CBCalcPlacement(lphc->self,
1675 lphc,
1676 &lphc->textRect,
1677 &lphc->buttonRect,
1678 &lphc->droppedRect);
1680 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1682 else
1684 CBForceDummyResize(lphc);
1687 lRet = height;
1690 else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */
1691 lRet = SendMessageW(lphc->hWndLBox, LB_SETITEMHEIGHT,
1692 (WPARAM)index, (LPARAM)height );
1693 return lRet;
1696 /***********************************************************************
1697 * COMBO_SelectString
1699 static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPARAM pText, BOOL unicode )
1701 INT index = unicode ? SendMessageW(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText) :
1702 SendMessageA(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText);
1703 if( index >= 0 )
1705 if( lphc->wState & CBF_EDIT )
1706 CBUpdateEdit( lphc, index );
1707 else
1709 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1712 return (LRESULT)index;
1715 /***********************************************************************
1716 * COMBO_LButtonDown
1718 static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam )
1720 POINT pt;
1721 BOOL bButton;
1722 HWND hWnd = lphc->self;
1724 pt.x = LOWORD(lParam);
1725 pt.y = HIWORD(lParam);
1726 bButton = PtInRect(&lphc->buttonRect, pt);
1728 if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) ||
1729 (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) )
1731 lphc->wState |= CBF_BUTTONDOWN;
1732 if( lphc->wState & CBF_DROPPED )
1734 /* got a click to cancel selection */
1736 lphc->wState &= ~CBF_BUTTONDOWN;
1737 CBRollUp( lphc, TRUE, FALSE );
1738 if( !IsWindow( hWnd ) ) return;
1740 if( lphc->wState & CBF_CAPTURE )
1742 lphc->wState &= ~CBF_CAPTURE;
1743 ReleaseCapture();
1746 else
1748 /* drop down the listbox and start tracking */
1750 lphc->wState |= CBF_CAPTURE;
1751 SetCapture( hWnd );
1752 CBDropDown( lphc );
1754 if( bButton ) CBRepaintButton( lphc );
1758 /***********************************************************************
1759 * COMBO_LButtonUp
1761 * Release capture and stop tracking if needed.
1763 static void COMBO_LButtonUp( LPHEADCOMBO lphc )
1765 if( lphc->wState & CBF_CAPTURE )
1767 lphc->wState &= ~CBF_CAPTURE;
1768 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1770 INT index = CBUpdateLBox( lphc, TRUE );
1771 /* Update edit only if item is in the list */
1772 if(index >= 0)
1774 lphc->wState |= CBF_NOLBSELECT;
1775 CBUpdateEdit( lphc, index );
1776 lphc->wState &= ~CBF_NOLBSELECT;
1779 ReleaseCapture();
1780 SetCapture(lphc->hWndLBox);
1783 if( lphc->wState & CBF_BUTTONDOWN )
1785 lphc->wState &= ~CBF_BUTTONDOWN;
1786 CBRepaintButton( lphc );
1790 /***********************************************************************
1791 * COMBO_MouseMove
1793 * Two things to do - track combo button and release capture when
1794 * pointer goes into the listbox.
1796 static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam )
1798 POINT pt;
1799 RECT lbRect;
1801 pt.x = LOWORD(lParam);
1802 pt.y = HIWORD(lParam);
1804 if( lphc->wState & CBF_BUTTONDOWN )
1806 BOOL bButton;
1808 bButton = PtInRect(&lphc->buttonRect, pt);
1810 if( !bButton )
1812 lphc->wState &= ~CBF_BUTTONDOWN;
1813 CBRepaintButton( lphc );
1817 GetClientRect( lphc->hWndLBox, &lbRect );
1818 MapWindowPoints( lphc->self, lphc->hWndLBox, &pt, 1 );
1819 if( PtInRect(&lbRect, pt) )
1821 lphc->wState &= ~CBF_CAPTURE;
1822 ReleaseCapture();
1823 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc, TRUE );
1825 /* hand over pointer tracking */
1826 SendMessageW(lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam);
1831 /***********************************************************************
1832 * ComboWndProc_common
1834 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxes.asp
1836 static LRESULT ComboWndProc_common( HWND hwnd, UINT message,
1837 WPARAM wParam, LPARAM lParam, BOOL unicode )
1839 LPHEADCOMBO lphc = (LPHEADCOMBO)GetWindowLongW( hwnd, 0 );
1841 TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1842 hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1844 if( lphc || message == WM_NCCREATE )
1845 switch(message)
1848 /* System messages */
1850 case WM_NCCREATE:
1852 LONG style = unicode ? ((LPCREATESTRUCTW)lParam)->style :
1853 ((LPCREATESTRUCTA)lParam)->style;
1854 return COMBO_NCCreate(hwnd, style);
1856 case WM_NCDESTROY:
1857 COMBO_NCDestroy(lphc);
1858 break;/* -> DefWindowProc */
1860 case WM_CREATE:
1862 HWND hwndParent;
1863 LONG style;
1864 if(unicode)
1866 hwndParent = ((LPCREATESTRUCTW)lParam)->hwndParent;
1867 style = ((LPCREATESTRUCTW)lParam)->style;
1869 else
1871 hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent;
1872 style = ((LPCREATESTRUCTA)lParam)->style;
1874 return COMBO_Create(hwnd, lphc, hwndParent, style, unicode);
1877 case WM_PRINTCLIENT:
1878 if (lParam & PRF_ERASEBKGND)
1879 COMBO_EraseBackground(hwnd, lphc, (HDC)wParam);
1881 /* Fallthrough */
1882 case WM_PAINT:
1883 /* wParam may contain a valid HDC! */
1884 return COMBO_Paint(lphc, (HDC)wParam);
1885 case WM_ERASEBKGND:
1886 return COMBO_EraseBackground(hwnd, lphc, (HDC)wParam);
1887 case WM_GETDLGCODE:
1889 LRESULT result = DLGC_WANTARROWS | DLGC_WANTCHARS;
1890 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1892 int vk = (int)((LPMSG)lParam)->wParam;
1894 if ((vk == VK_RETURN || vk == VK_ESCAPE) && (lphc->wState & CBF_DROPPED))
1895 result |= DLGC_WANTMESSAGE;
1897 return result;
1899 case WM_WINDOWPOSCHANGING:
1900 return COMBO_WindowPosChanging(hwnd, lphc, (LPWINDOWPOS)lParam);
1901 case WM_WINDOWPOSCHANGED:
1902 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1903 * In that case, the Combobox itself will not be resized, so we won't
1904 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1905 * do it here.
1907 /* fall through */
1908 case WM_SIZE:
1909 if( lphc->hWndLBox &&
1910 !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc );
1911 return TRUE;
1912 case WM_SETFONT:
1913 COMBO_Font( lphc, (HFONT)wParam, (BOOL)lParam );
1914 return TRUE;
1915 case WM_GETFONT:
1916 return (LRESULT)lphc->hFont;
1917 case WM_SETFOCUS:
1918 if( lphc->wState & CBF_EDIT )
1919 SetFocus( lphc->hWndEdit );
1920 else
1921 COMBO_SetFocus( lphc );
1922 return TRUE;
1923 case WM_KILLFOCUS:
1925 HWND hwndFocus = WIN_GetFullHandle( (HWND)wParam );
1926 if( !hwndFocus ||
1927 (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox ))
1928 COMBO_KillFocus( lphc );
1929 return TRUE;
1931 case WM_COMMAND:
1932 return COMBO_Command( lphc, wParam, WIN_GetFullHandle( (HWND)lParam ) );
1933 case WM_GETTEXT:
1934 return unicode ? COMBO_GetTextW( lphc, wParam, (LPWSTR)lParam )
1935 : COMBO_GetTextA( lphc, wParam, (LPSTR)lParam );
1936 case WM_SETTEXT:
1937 case WM_GETTEXTLENGTH:
1938 case WM_CLEAR:
1939 if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT))
1941 int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1942 if (j == -1) return 0;
1943 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0) :
1944 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, j, 0);
1946 else if( lphc->wState & CBF_EDIT )
1948 LRESULT ret;
1949 lphc->wState |= CBF_NOEDITNOTIFY;
1950 ret = unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1951 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1952 lphc->wState &= ~CBF_NOEDITNOTIFY;
1953 return ret;
1955 else return CB_ERR;
1956 case WM_CUT:
1957 case WM_PASTE:
1958 case WM_COPY:
1959 if( lphc->wState & CBF_EDIT )
1961 return unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1962 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1964 else return CB_ERR;
1966 case WM_DRAWITEM:
1967 case WM_DELETEITEM:
1968 case WM_COMPAREITEM:
1969 case WM_MEASUREITEM:
1970 return COMBO_ItemOp(lphc, message, lParam);
1971 case WM_ENABLE:
1972 if( lphc->wState & CBF_EDIT )
1973 EnableWindow( lphc->hWndEdit, (BOOL)wParam );
1974 EnableWindow( lphc->hWndLBox, (BOOL)wParam );
1976 /* Force the control to repaint when the enabled state changes. */
1977 InvalidateRect(lphc->self, NULL, TRUE);
1978 return TRUE;
1979 case WM_SETREDRAW:
1980 if( wParam )
1981 lphc->wState &= ~CBF_NOREDRAW;
1982 else
1983 lphc->wState |= CBF_NOREDRAW;
1985 if( lphc->wState & CBF_EDIT )
1986 SendMessageW(lphc->hWndEdit, message, wParam, lParam);
1987 SendMessageW(lphc->hWndLBox, message, wParam, lParam);
1988 return 0;
1989 case WM_SYSKEYDOWN:
1990 if( KEYDATA_ALT & HIWORD(lParam) )
1991 if( wParam == VK_UP || wParam == VK_DOWN )
1992 COMBO_FlipListbox( lphc, FALSE, FALSE );
1993 return 0;
1995 case WM_CHAR:
1996 case WM_IME_CHAR:
1997 case WM_KEYDOWN:
1999 HWND hwndTarget;
2001 if ((wParam == VK_RETURN || wParam == VK_ESCAPE) &&
2002 (lphc->wState & CBF_DROPPED))
2004 CBRollUp( lphc, wParam == VK_RETURN, FALSE );
2005 return TRUE;
2007 else if ((wParam == VK_F4) && !(lphc->wState & CBF_EUI))
2009 COMBO_FlipListbox( lphc, FALSE, FALSE );
2010 return TRUE;
2013 if( lphc->wState & CBF_EDIT )
2014 hwndTarget = lphc->hWndEdit;
2015 else
2016 hwndTarget = lphc->hWndLBox;
2018 return unicode ? SendMessageW(hwndTarget, message, wParam, lParam) :
2019 SendMessageA(hwndTarget, message, wParam, lParam);
2021 case WM_LBUTTONDOWN:
2022 if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self );
2023 if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
2024 return TRUE;
2025 case WM_LBUTTONUP:
2026 COMBO_LButtonUp( lphc );
2027 return TRUE;
2028 case WM_MOUSEMOVE:
2029 if( lphc->wState & CBF_CAPTURE )
2030 COMBO_MouseMove( lphc, wParam, lParam );
2031 return TRUE;
2033 case WM_MOUSEWHEEL:
2034 if (wParam & (MK_SHIFT | MK_CONTROL))
2035 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2036 DefWindowProcA(hwnd, message, wParam, lParam);
2038 if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_UP, 0);
2039 if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_DOWN, 0);
2040 return TRUE;
2042 /* Combo messages */
2044 case CB_ADDSTRING16:
2045 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2046 /* fall through */
2047 case CB_ADDSTRING:
2048 if( unicode )
2050 if( lphc->dwStyle & CBS_LOWERCASE )
2051 strlwrW((LPWSTR)lParam);
2052 else if( lphc->dwStyle & CBS_UPPERCASE )
2053 struprW((LPWSTR)lParam);
2054 return SendMessageW(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2056 else
2058 if( lphc->dwStyle & CBS_LOWERCASE )
2059 _strlwr((LPSTR)lParam);
2060 else if( lphc->dwStyle & CBS_UPPERCASE )
2061 _strupr((LPSTR)lParam);
2062 return SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2064 case CB_INSERTSTRING16:
2065 wParam = (INT)(INT16)wParam;
2066 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2067 /* fall through */
2068 case CB_INSERTSTRING:
2069 if( unicode )
2071 if( lphc->dwStyle & CBS_LOWERCASE )
2072 strlwrW((LPWSTR)lParam);
2073 else if( lphc->dwStyle & CBS_UPPERCASE )
2074 struprW((LPWSTR)lParam);
2075 return SendMessageW(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2077 else
2079 if( lphc->dwStyle & CBS_LOWERCASE )
2080 _strlwr((LPSTR)lParam);
2081 else if( lphc->dwStyle & CBS_UPPERCASE )
2082 _strupr((LPSTR)lParam);
2083 return SendMessageA(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2085 case CB_DELETESTRING16:
2086 case CB_DELETESTRING:
2087 return unicode ? SendMessageW(lphc->hWndLBox, LB_DELETESTRING, wParam, 0) :
2088 SendMessageA(lphc->hWndLBox, LB_DELETESTRING, wParam, 0);
2089 case CB_SELECTSTRING16:
2090 wParam = (INT)(INT16)wParam;
2091 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2092 /* fall through */
2093 case CB_SELECTSTRING:
2094 return COMBO_SelectString(lphc, (INT)wParam, lParam, unicode);
2095 case CB_FINDSTRING16:
2096 wParam = (INT)(INT16)wParam;
2097 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2098 /* fall through */
2099 case CB_FINDSTRING:
2100 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam) :
2101 SendMessageA(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam);
2102 case CB_FINDSTRINGEXACT16:
2103 wParam = (INT)(INT16)wParam;
2104 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2105 /* fall through */
2106 case CB_FINDSTRINGEXACT:
2107 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam) :
2108 SendMessageA(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam);
2109 case CB_SETITEMHEIGHT16:
2110 wParam = (INT)(INT16)wParam; /* signed integer */
2111 /* fall through */
2112 case CB_SETITEMHEIGHT:
2113 return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam);
2114 case CB_GETITEMHEIGHT16:
2115 wParam = (INT)(INT16)wParam;
2116 /* fall through */
2117 case CB_GETITEMHEIGHT:
2118 if( (INT)wParam >= 0 ) /* listbox item */
2119 return SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0);
2120 return CBGetTextAreaHeight(hwnd, lphc);
2121 case CB_RESETCONTENT16:
2122 case CB_RESETCONTENT:
2123 SendMessageW(lphc->hWndLBox, LB_RESETCONTENT, 0, 0);
2124 if( (lphc->wState & CBF_EDIT) && CB_HASSTRINGS(lphc) )
2126 static const WCHAR empty_stringW[] = { 0 };
2127 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);
2129 else
2130 InvalidateRect(lphc->self, NULL, TRUE);
2131 return TRUE;
2132 case CB_INITSTORAGE:
2133 return SendMessageW(lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam);
2134 case CB_GETHORIZONTALEXTENT:
2135 return SendMessageW(lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0);
2136 case CB_SETHORIZONTALEXTENT:
2137 return SendMessageW(lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0);
2138 case CB_GETTOPINDEX:
2139 return SendMessageW(lphc->hWndLBox, LB_GETTOPINDEX, 0, 0);
2140 case CB_GETLOCALE:
2141 return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0);
2142 case CB_SETLOCALE:
2143 return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0);
2144 case CB_GETDROPPEDWIDTH:
2145 if( lphc->droppedWidth )
2146 return lphc->droppedWidth;
2147 return lphc->droppedRect.right - lphc->droppedRect.left;
2148 case CB_SETDROPPEDWIDTH:
2149 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) &&
2150 (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam;
2151 return CB_ERR;
2152 case CB_GETDROPPEDCONTROLRECT16:
2153 lParam = (LPARAM)MapSL(lParam);
2154 if( lParam )
2156 RECT r;
2157 RECT16 *r16 = (RECT16 *)lParam;
2158 CBGetDroppedControlRect( lphc, &r );
2159 r16->left = r.left;
2160 r16->top = r.top;
2161 r16->right = r.right;
2162 r16->bottom = r.bottom;
2164 return CB_OKAY;
2165 case CB_GETDROPPEDCONTROLRECT:
2166 if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam );
2167 return CB_OKAY;
2168 case CB_GETDROPPEDSTATE16:
2169 case CB_GETDROPPEDSTATE:
2170 return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE;
2171 case CB_DIR16:
2172 return SendMessageA(lphc->hWndLBox, LB_DIR16, wParam, lParam);
2173 case CB_DIR:
2174 return unicode ? SendMessageW(lphc->hWndLBox, LB_DIR, wParam, lParam) :
2175 SendMessageA(lphc->hWndLBox, LB_DIR, wParam, lParam);
2177 case CB_SHOWDROPDOWN16:
2178 case CB_SHOWDROPDOWN:
2179 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
2181 if( wParam )
2183 if( !(lphc->wState & CBF_DROPPED) )
2184 CBDropDown( lphc );
2186 else
2187 if( lphc->wState & CBF_DROPPED )
2188 CBRollUp( lphc, FALSE, TRUE );
2190 return TRUE;
2191 case CB_GETCOUNT16:
2192 case CB_GETCOUNT:
2193 return SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
2194 case CB_GETCURSEL16:
2195 case CB_GETCURSEL:
2196 return SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
2197 case CB_SETCURSEL16:
2198 wParam = (INT)(INT16)wParam;
2199 /* fall through */
2200 case CB_SETCURSEL:
2201 lParam = SendMessageW(lphc->hWndLBox, LB_SETCURSEL, wParam, 0);
2202 if( lParam >= 0 )
2203 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, wParam, 0);
2205 /* no LBN_SELCHANGE in this case, update manually */
2206 if( lphc->wState & CBF_EDIT )
2207 CBUpdateEdit( lphc, (INT)wParam );
2208 else
2209 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
2210 lphc->wState &= ~CBF_SELCHANGE;
2211 return lParam;
2212 case CB_GETLBTEXT16:
2213 wParam = (INT)(INT16)wParam;
2214 lParam = (LPARAM)MapSL(lParam);
2215 /* fall through */
2216 case CB_GETLBTEXT:
2217 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXT, wParam, lParam) :
2218 SendMessageA(lphc->hWndLBox, LB_GETTEXT, wParam, lParam);
2219 case CB_GETLBTEXTLEN16:
2220 wParam = (INT)(INT16)wParam;
2221 /* fall through */
2222 case CB_GETLBTEXTLEN:
2223 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0) :
2224 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0);
2225 case CB_GETITEMDATA16:
2226 wParam = (INT)(INT16)wParam;
2227 /* fall through */
2228 case CB_GETITEMDATA:
2229 return SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0);
2230 case CB_SETITEMDATA16:
2231 wParam = (INT)(INT16)wParam;
2232 /* fall through */
2233 case CB_SETITEMDATA:
2234 return SendMessageW(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam);
2235 case CB_GETEDITSEL16:
2236 wParam = lParam = 0; /* just in case */
2237 /* fall through */
2238 case CB_GETEDITSEL:
2239 /* Edit checks passed parameters itself */
2240 if( lphc->wState & CBF_EDIT )
2241 return SendMessageW(lphc->hWndEdit, EM_GETSEL, wParam, lParam);
2242 return CB_ERR;
2243 case CB_SETEDITSEL16:
2244 case CB_SETEDITSEL:
2245 if( lphc->wState & CBF_EDIT )
2246 return SendMessageW(lphc->hWndEdit, EM_SETSEL,
2247 (INT)(INT16)LOWORD(lParam), (INT)(INT16)HIWORD(lParam) );
2248 return CB_ERR;
2249 case CB_SETEXTENDEDUI16:
2250 case CB_SETEXTENDEDUI:
2251 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
2252 return CB_ERR;
2253 if( wParam )
2254 lphc->wState |= CBF_EUI;
2255 else lphc->wState &= ~CBF_EUI;
2256 return CB_OKAY;
2257 case CB_GETEXTENDEDUI16:
2258 case CB_GETEXTENDEDUI:
2259 return (lphc->wState & CBF_EUI) ? TRUE : FALSE;
2261 default:
2262 if (message >= WM_USER)
2263 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2264 message - WM_USER, wParam, lParam );
2265 break;
2267 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2268 DefWindowProcA(hwnd, message, wParam, lParam);
2271 /***********************************************************************
2272 * ComboWndProcA
2274 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2275 * window structs.
2277 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2279 if (!IsWindow(hwnd)) return 0;
2280 return ComboWndProc_common( hwnd, message, wParam, lParam, FALSE );
2283 /***********************************************************************
2284 * ComboWndProcW
2286 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2288 if (!IsWindow(hwnd)) return 0;
2289 return ComboWndProc_common( hwnd, message, wParam, lParam, TRUE );
2292 /*************************************************************************
2293 * GetComboBoxInfo (USER32.@)
2295 BOOL WINAPI GetComboBoxInfo(HWND hwndCombo, /* [in] handle to combo box */
2296 PCOMBOBOXINFO pcbi /* [in/out] combo box information */)
2298 FIXME("\n");
2299 return FALSE;