Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / user32 / combo.c
bloba849685d2c3b8443ab5dad3959d3975925b6d32e
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 font height + 4px
209 * This height was determined through experimentation.
210 * CBCalcPlacement will add 2*COMBO_YBORDERSIZE pixels for the border
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 = baseUnitY + 4;
245 * Check the ownerdraw case if we haven't asked the parent the size
246 * of the item yet.
248 if ( CB_OWNERDRAWN(lphc) &&
249 (lphc->wState & CBF_MEASUREITEM) )
251 MEASUREITEMSTRUCT measureItem;
252 RECT clientRect;
253 INT originalItemHeight = iTextItemHeight;
254 UINT id = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
257 * We use the client rect for the width of the item.
259 GetClientRect(hwnd, &clientRect);
261 lphc->wState &= ~CBF_MEASUREITEM;
264 * Send a first one to measure the size of the text area
266 measureItem.CtlType = ODT_COMBOBOX;
267 measureItem.CtlID = id;
268 measureItem.itemID = -1;
269 measureItem.itemWidth = clientRect.right;
270 measureItem.itemHeight = iTextItemHeight - 6; /* ownerdrawn cb is taller */
271 measureItem.itemData = 0;
272 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
273 iTextItemHeight = 6 + measureItem.itemHeight;
276 * Send a second one in the case of a fixed ownerdraw list to calculate the
277 * size of the list items. (we basically do this on behalf of the listbox)
279 if (lphc->dwStyle & CBS_OWNERDRAWFIXED)
281 measureItem.CtlType = ODT_COMBOBOX;
282 measureItem.CtlID = id;
283 measureItem.itemID = 0;
284 measureItem.itemWidth = clientRect.right;
285 measureItem.itemHeight = originalItemHeight;
286 measureItem.itemData = 0;
287 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
288 lphc->fixedOwnerDrawHeight = measureItem.itemHeight;
292 * Keep the size for the next time
294 lphc->editHeight = iTextItemHeight;
297 return iTextItemHeight;
300 /***********************************************************************
301 * CBForceDummyResize
303 * The dummy resize is used for listboxes that have a popup to trigger
304 * a re-arranging of the contents of the combobox and the recalculation
305 * of the size of the "real" control window.
307 static void CBForceDummyResize(
308 LPHEADCOMBO lphc)
310 RECT windowRect;
311 int newComboHeight;
313 newComboHeight = CBGetTextAreaHeight(lphc->self,lphc) + 2*COMBO_YBORDERSIZE();
315 GetWindowRect(lphc->self, &windowRect);
318 * We have to be careful, resizing a combobox also has the meaning that the
319 * dropped rect will be resized. In this case, we want to trigger a resize
320 * to recalculate layout but we don't want to change the dropped rectangle
321 * So, we pass the height of text area of control as the height.
322 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
323 * message.
325 SetWindowPos( lphc->self,
326 NULL,
327 0, 0,
328 windowRect.right - windowRect.left,
329 newComboHeight,
330 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
333 /***********************************************************************
334 * CBCalcPlacement
336 * Set up component coordinates given valid lphc->RectCombo.
338 static void CBCalcPlacement(
339 HWND hwnd,
340 LPHEADCOMBO lphc,
341 LPRECT lprEdit,
342 LPRECT lprButton,
343 LPRECT lprLB)
346 * Again, start with the client rectangle.
348 GetClientRect(hwnd, lprEdit);
351 * Remove the borders
353 InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
356 * Chop off the bottom part to fit with the height of the text area.
358 lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
361 * The button starts the same vertical position as the text area.
363 CopyRect(lprButton, lprEdit);
366 * If the combobox is "simple" there is no button.
368 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
369 lprButton->left = lprButton->right = lprButton->bottom = 0;
370 else
373 * Let's assume the combobox button is the same width as the
374 * scrollbar button.
375 * size the button horizontally and cut-off the text area.
377 lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
378 lprEdit->right = lprButton->left;
382 * In the case of a dropdown, there is an additional spacing between the
383 * text area and the button.
385 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
387 lprEdit->right -= COMBO_EDITBUTTONSPACE();
391 * If we have an edit control, we space it away from the borders slightly.
393 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
395 InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
399 * Adjust the size of the listbox popup.
401 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
404 * Use the client rectangle to initialize the listbox rectangle
406 GetClientRect(hwnd, lprLB);
409 * Then, chop-off the top part.
411 lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
413 else
416 * Make sure the dropped width is as large as the combobox itself.
418 if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
420 lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
423 * In the case of a dropdown, the popup listbox is offset to the right.
424 * so, we want to make sure it's flush with the right side of the
425 * combobox
427 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
428 lprLB->right -= COMBO_EDITBUTTONSPACE();
430 else
431 lprLB->right = lprLB->left + lphc->droppedWidth;
434 /* don't allow negative window width */
435 if (lprEdit->right < lprEdit->left)
436 lprEdit->right = lprEdit->left;
438 TRACE("\ttext\t= (%d,%d-%d,%d)\n",
439 lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom);
441 TRACE("\tbutton\t= (%d,%d-%d,%d)\n",
442 lprButton->left, lprButton->top, lprButton->right, lprButton->bottom);
444 TRACE("\tlbox\t= (%d,%d-%d,%d)\n",
445 lprLB->left, lprLB->top, lprLB->right, lprLB->bottom );
448 /***********************************************************************
449 * CBGetDroppedControlRect
451 static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect)
453 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
454 of the combo box and the lower right corner of the listbox */
456 GetWindowRect(lphc->self, lpRect);
458 lpRect->right = lpRect->left + lphc->droppedRect.right - lphc->droppedRect.left;
459 lpRect->bottom = lpRect->top + lphc->droppedRect.bottom - lphc->droppedRect.top;
463 /***********************************************************************
464 * COMBO_WindowPosChanging
466 static LRESULT COMBO_WindowPosChanging(
467 HWND hwnd,
468 LPHEADCOMBO lphc,
469 WINDOWPOS* posChanging)
472 * We need to override the WM_WINDOWPOSCHANGING method to handle all
473 * the non-simple comboboxes. The problem is that those controls are
474 * always the same height. We have to make sure they are not resized
475 * to another value.
477 if ( ( CB_GETTYPE(lphc) != CBS_SIMPLE ) &&
478 ((posChanging->flags & SWP_NOSIZE) == 0) )
480 int newComboHeight;
482 newComboHeight = CBGetTextAreaHeight(hwnd,lphc) +
483 2*COMBO_YBORDERSIZE();
486 * Resizing a combobox has another side effect, it resizes the dropped
487 * rectangle as well. However, it does it only if the new height for the
488 * combobox is different from the height it should have. In other words,
489 * if the application resizing the combobox only had the intention to resize
490 * the actual control, for example, to do the layout of a dialog that is
491 * resized, the height of the dropdown is not changed.
493 if (posChanging->cy != newComboHeight)
495 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%d, oldtop=%d\n",
496 posChanging->cy, newComboHeight, lphc->droppedRect.bottom,
497 lphc->droppedRect.top);
498 lphc->droppedRect.bottom = lphc->droppedRect.top + posChanging->cy - newComboHeight;
500 posChanging->cy = newComboHeight;
504 return 0;
507 /***********************************************************************
508 * COMBO_Create
510 static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style,
511 BOOL unicode )
513 static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0};
514 static const WCHAR editName[] = {'E','d','i','t',0};
516 if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE;
517 if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT;
519 lphc->owner = hwndParent;
522 * The item height and dropped width are not set when the control
523 * is created.
525 lphc->droppedWidth = lphc->editHeight = 0;
528 * The first time we go through, we want to measure the ownerdraw item
530 lphc->wState |= CBF_MEASUREITEM;
532 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
534 if( lphc->owner || !(style & WS_VISIBLE) )
536 UINT lbeStyle = 0;
537 UINT lbeExStyle = 0;
540 * Initialize the dropped rect to the size of the client area of the
541 * control and then, force all the areas of the combobox to be
542 * recalculated.
544 GetClientRect( hwnd, &lphc->droppedRect );
545 CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
548 * Adjust the position of the popup listbox if it's necessary
550 if ( CB_GETTYPE(lphc) != CBS_SIMPLE )
552 lphc->droppedRect.top = lphc->textRect.bottom + COMBO_YBORDERSIZE();
555 * If it's a dropdown, the listbox is offset
557 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
558 lphc->droppedRect.left += COMBO_EDITBUTTONSPACE();
560 if (lphc->droppedRect.bottom < lphc->droppedRect.top)
561 lphc->droppedRect.bottom = lphc->droppedRect.top;
562 if (lphc->droppedRect.right < lphc->droppedRect.left)
563 lphc->droppedRect.right = lphc->droppedRect.left;
564 MapWindowPoints( hwnd, 0, (LPPOINT)&lphc->droppedRect, 2 );
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 HeapFree( GetProcessHeap(), 0, pText );
834 /***********************************************************************
835 * CBPaintBorder
837 static void CBPaintBorder(
838 HWND hwnd,
839 LPHEADCOMBO lphc,
840 HDC hdc)
842 RECT clientRect;
844 if (CB_GETTYPE(lphc) != CBS_SIMPLE)
846 GetClientRect(hwnd, &clientRect);
848 else
850 CopyRect(&clientRect, &lphc->textRect);
852 InflateRect(&clientRect, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
853 InflateRect(&clientRect, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
856 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_RECT);
859 /***********************************************************************
860 * COMBO_PrepareColors
862 * This method will sent the appropriate WM_CTLCOLOR message to
863 * prepare and setup the colors for the combo's DC.
865 * It also returns the brush to use for the background.
867 static HBRUSH COMBO_PrepareColors(
868 LPHEADCOMBO lphc,
869 HDC hDC)
871 HBRUSH hBkgBrush;
874 * Get the background brush for this control.
876 if (CB_DISABLED(lphc))
878 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORSTATIC,
879 (WPARAM)hDC, (LPARAM)lphc->self );
882 * We have to change the text color since WM_CTLCOLORSTATIC will
883 * set it to the "enabled" color. This is the same behavior as the
884 * edit control
886 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
888 else
890 if (lphc->wState & CBF_EDIT)
892 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLOREDIT,
893 (WPARAM)hDC, (LPARAM)lphc->self );
895 else
897 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORLISTBOX,
898 (WPARAM)hDC, (LPARAM)lphc->self );
903 * Catch errors.
905 if( !hBkgBrush )
906 hBkgBrush = GetSysColorBrush(COLOR_WINDOW);
908 return hBkgBrush;
912 /***********************************************************************
913 * COMBO_Paint
915 static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC)
917 PAINTSTRUCT ps;
918 HDC hDC;
920 hDC = (hParamDC) ? hParamDC
921 : BeginPaint( lphc->self, &ps);
923 TRACE("hdc=%p\n", hDC);
925 if( hDC && !(lphc->wState & CBF_NOREDRAW) )
927 HBRUSH hPrevBrush, hBkgBrush;
930 * Retrieve the background brush and select it in the
931 * DC.
933 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
935 hPrevBrush = SelectObject( hDC, hBkgBrush );
936 if (!(lphc->wState & CBF_EDIT))
937 FillRect(hDC, &lphc->textRect, hBkgBrush);
940 * In non 3.1 look, there is a sunken border on the combobox
942 CBPaintBorder(lphc->self, lphc, hDC);
944 if( !IsRectEmpty(&lphc->buttonRect) )
946 CBPaintButton(lphc, hDC, lphc->buttonRect);
949 /* paint the edit control padding area */
950 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
952 RECT rPadEdit = lphc->textRect;
954 InflateRect(&rPadEdit, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
956 FrameRect( hDC, &rPadEdit, GetSysColorBrush(COLOR_WINDOW) );
959 if( !(lphc->wState & CBF_EDIT) )
960 CBPaintText( lphc, hDC, lphc->textRect);
962 if( hPrevBrush )
963 SelectObject( hDC, hPrevBrush );
966 if( !hParamDC )
967 EndPaint(lphc->self, &ps);
969 return 0;
972 /***********************************************************************
973 * CBUpdateLBox
975 * Select listbox entry according to the contents of the edit control.
977 static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
979 INT length, idx;
980 LPWSTR pText = NULL;
982 idx = LB_ERR;
983 length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 );
985 if( length > 0 )
986 pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
988 TRACE("\t edit text length %i\n", length );
990 if( pText )
992 GetWindowTextW( lphc->hWndEdit, pText, length + 1);
993 idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING,
994 (WPARAM)(-1), (LPARAM)pText );
995 HeapFree( GetProcessHeap(), 0, pText );
998 SendMessageW(lphc->hWndLBox, LB_SETCURSEL, (WPARAM)(bSelect ? idx : -1), 0);
1000 /* probably superfluous but Windows sends this too */
1001 SendMessageW(lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1002 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1004 return idx;
1007 /***********************************************************************
1008 * CBUpdateEdit
1010 * Copy a listbox entry to the edit control.
1012 static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
1014 INT length;
1015 LPWSTR pText = NULL;
1016 static const WCHAR empty_stringW[] = { 0 };
1018 TRACE("\t %i\n", index );
1020 if( index >= 0 ) /* got an entry */
1022 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0);
1023 if( length != LB_ERR)
1025 if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) )
1027 SendMessageW(lphc->hWndLBox, LB_GETTEXT,
1028 (WPARAM)index, (LPARAM)pText );
1033 lphc->wState |= (CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1034 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, pText ? (LPARAM)pText : (LPARAM)empty_stringW);
1035 lphc->wState &= ~(CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1037 if( lphc->wState & CBF_FOCUSED )
1038 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1040 HeapFree( GetProcessHeap(), 0, pText );
1043 /***********************************************************************
1044 * CBDropDown
1046 * Show listbox popup.
1048 static void CBDropDown( LPHEADCOMBO lphc )
1050 HMONITOR monitor;
1051 MONITORINFO mon_info;
1052 RECT rect,r;
1053 int nItems = 0;
1054 int nDroppedHeight;
1056 TRACE("[%p]: drop down\n", lphc->self);
1058 CB_NOTIFY( lphc, CBN_DROPDOWN );
1060 /* set selection */
1062 lphc->wState |= CBF_DROPPED;
1063 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1065 lphc->droppedIndex = CBUpdateLBox( lphc, TRUE );
1067 /* Update edit only if item is in the list */
1068 if( !(lphc->wState & CBF_CAPTURE) && lphc->droppedIndex >= 0)
1069 CBUpdateEdit( lphc, lphc->droppedIndex );
1071 else
1073 lphc->droppedIndex = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1075 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX,
1076 (WPARAM)(lphc->droppedIndex == LB_ERR ? 0 : lphc->droppedIndex), 0 );
1077 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1080 /* now set popup position */
1081 GetWindowRect( lphc->self, &rect );
1084 * If it's a dropdown, the listbox is offset
1086 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1087 rect.left += COMBO_EDITBUTTONSPACE();
1089 /* if the dropped height is greater than the total height of the dropped
1090 items list, then force the drop down list height to be the total height
1091 of the items in the dropped list */
1093 /* And Remove any extra space (Best Fit) */
1094 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
1095 /* if listbox length has been set directly by its handle */
1096 GetWindowRect(lphc->hWndLBox, &r);
1097 if (nDroppedHeight < r.bottom - r.top)
1098 nDroppedHeight = r.bottom - r.top;
1099 nItems = (int)SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
1101 if (nItems > 0)
1103 int nHeight;
1104 int nIHeight;
1106 nIHeight = (int)SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, 0, 0);
1108 nHeight = nIHeight*nItems;
1110 if (nHeight < nDroppedHeight - COMBO_YBORDERSIZE())
1111 nDroppedHeight = nHeight + COMBO_YBORDERSIZE();
1113 if (nDroppedHeight < nHeight)
1115 if (nItems < 5)
1116 nDroppedHeight = (nItems+1)*nIHeight;
1117 else
1118 nDroppedHeight = 6*nIHeight;
1122 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1123 monitor = MonitorFromRect( &rect, MONITOR_DEFAULTTOPRIMARY );
1124 mon_info.cbSize = sizeof(mon_info);
1125 GetMonitorInfoW( monitor, &mon_info );
1127 if( (rect.bottom + nDroppedHeight) >= mon_info.rcWork.bottom )
1128 rect.bottom = rect.top - nDroppedHeight;
1130 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
1131 lphc->droppedRect.right - lphc->droppedRect.left,
1132 nDroppedHeight,
1133 SWP_NOACTIVATE | SWP_SHOWWINDOW);
1136 if( !(lphc->wState & CBF_NOREDRAW) )
1137 RedrawWindow( lphc->self, NULL, 0, RDW_INVALIDATE |
1138 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1140 EnableWindow( lphc->hWndLBox, TRUE );
1141 if (GetCapture() != lphc->self)
1142 SetCapture(lphc->hWndLBox);
1145 /***********************************************************************
1146 * CBRollUp
1148 * Hide listbox popup.
1150 static void CBRollUp( LPHEADCOMBO lphc, BOOL ok, BOOL bButton )
1152 HWND hWnd = lphc->self;
1154 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1155 lphc->self, (INT)ok, (INT)(lphc->wState & CBF_DROPPED));
1157 CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL );
1159 if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE )
1162 if( lphc->wState & CBF_DROPPED )
1164 RECT rect;
1166 lphc->wState &= ~CBF_DROPPED;
1167 ShowWindow( lphc->hWndLBox, SW_HIDE );
1169 if(GetCapture() == lphc->hWndLBox)
1171 ReleaseCapture();
1174 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1176 rect = lphc->buttonRect;
1178 else
1180 if( bButton )
1182 UnionRect( &rect,
1183 &lphc->buttonRect,
1184 &lphc->textRect);
1186 else
1187 rect = lphc->textRect;
1189 bButton = TRUE;
1192 if( bButton && !(lphc->wState & CBF_NOREDRAW) )
1193 RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE |
1194 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1195 CB_NOTIFY( lphc, CBN_CLOSEUP );
1200 /***********************************************************************
1201 * COMBO_FlipListbox
1203 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1205 BOOL COMBO_FlipListbox( LPHEADCOMBO lphc, BOOL ok, BOOL bRedrawButton )
1207 if( lphc->wState & CBF_DROPPED )
1209 CBRollUp( lphc, ok, bRedrawButton );
1210 return FALSE;
1213 CBDropDown( lphc );
1214 return TRUE;
1217 /***********************************************************************
1218 * CBRepaintButton
1220 static void CBRepaintButton( LPHEADCOMBO lphc )
1222 InvalidateRect(lphc->self, &lphc->buttonRect, TRUE);
1223 UpdateWindow(lphc->self);
1226 /***********************************************************************
1227 * COMBO_SetFocus
1229 static void COMBO_SetFocus( LPHEADCOMBO lphc )
1231 if( !(lphc->wState & CBF_FOCUSED) )
1233 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1234 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1236 /* This is wrong. Message sequences seem to indicate that this
1237 is set *after* the notify. */
1238 /* lphc->wState |= CBF_FOCUSED; */
1240 if( !(lphc->wState & CBF_EDIT) )
1241 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1243 CB_NOTIFY( lphc, CBN_SETFOCUS );
1244 lphc->wState |= CBF_FOCUSED;
1248 /***********************************************************************
1249 * COMBO_KillFocus
1251 static void COMBO_KillFocus( LPHEADCOMBO lphc )
1253 HWND hWnd = lphc->self;
1255 if( lphc->wState & CBF_FOCUSED )
1257 CBRollUp( lphc, FALSE, TRUE );
1258 if( IsWindow( hWnd ) )
1260 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1261 SendMessageW(lphc->hWndLBox, LB_CARETOFF, 0, 0);
1263 lphc->wState &= ~CBF_FOCUSED;
1265 /* redraw text */
1266 if( !(lphc->wState & CBF_EDIT) )
1267 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1269 CB_NOTIFY( lphc, CBN_KILLFOCUS );
1274 /***********************************************************************
1275 * COMBO_Command
1277 static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd )
1279 if ( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd )
1281 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1283 switch( HIWORD(wParam) >> 8 )
1285 case (EN_SETFOCUS >> 8):
1287 TRACE("[%p]: edit [%p] got focus\n", lphc->self, lphc->hWndEdit );
1289 COMBO_SetFocus( lphc );
1290 break;
1292 case (EN_KILLFOCUS >> 8):
1294 TRACE("[%p]: edit [%p] lost focus\n", lphc->self, lphc->hWndEdit );
1296 /* NOTE: it seems that Windows' edit control sends an
1297 * undocumented message WM_USER + 0x1B instead of this
1298 * notification (only when it happens to be a part of
1299 * the combo). ?? - AK.
1302 COMBO_KillFocus( lphc );
1303 break;
1306 case (EN_CHANGE >> 8):
1308 * In some circumstances (when the selection of the combobox
1309 * is changed for example) we don't want the EN_CHANGE notification
1310 * to be forwarded to the parent of the combobox. This code
1311 * checks a flag that is set in these occasions and ignores the
1312 * notification.
1314 if (lphc->wState & CBF_NOLBSELECT)
1316 lphc->wState &= ~CBF_NOLBSELECT;
1318 else
1320 CBUpdateLBox( lphc, lphc->wState & CBF_DROPPED );
1323 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1324 CB_NOTIFY( lphc, CBN_EDITCHANGE );
1325 break;
1327 case (EN_UPDATE >> 8):
1328 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1329 CB_NOTIFY( lphc, CBN_EDITUPDATE );
1330 break;
1332 case (EN_ERRSPACE >> 8):
1333 CB_NOTIFY( lphc, CBN_ERRSPACE );
1336 else if( lphc->hWndLBox == hWnd )
1338 switch( (short)HIWORD(wParam) )
1340 case LBN_ERRSPACE:
1341 CB_NOTIFY( lphc, CBN_ERRSPACE );
1342 break;
1344 case LBN_DBLCLK:
1345 CB_NOTIFY( lphc, CBN_DBLCLK );
1346 break;
1348 case LBN_SELCHANGE:
1349 case LBN_SELCANCEL:
1351 TRACE("[%p]: lbox selection change [%x]\n", lphc->self, lphc->wState );
1353 if( HIWORD(wParam) == LBN_SELCHANGE)
1355 if( lphc->wState & CBF_EDIT )
1357 INT index = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1358 lphc->wState |= CBF_NOLBSELECT;
1359 CBUpdateEdit( lphc, index );
1360 /* select text in edit, as Windows does */
1361 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1363 else
1364 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1367 /* do not roll up if selection is being tracked
1368 * by arrowkeys in the dropdown listbox */
1369 if( ((lphc->wState & CBF_DROPPED) && !(lphc->wState & CBF_NOROLLUP)) )
1371 CBRollUp( lphc, (HIWORD(wParam) == LBN_SELCHANGE), TRUE );
1373 else lphc->wState &= ~CBF_NOROLLUP;
1375 CB_NOTIFY( lphc, CBN_SELCHANGE );
1377 /* fall through */
1379 case LBN_SETFOCUS:
1380 case LBN_KILLFOCUS:
1381 /* nothing to do here since ComboLBox always resets the focus to its
1382 * combo/edit counterpart */
1383 break;
1386 return 0;
1389 /***********************************************************************
1390 * COMBO_ItemOp
1392 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1394 static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
1396 HWND hWnd = lphc->self;
1397 UINT id = (UINT)GetWindowLongPtrW( hWnd, GWLP_ID );
1399 TRACE("[%p]: ownerdraw op %04x\n", lphc->self, msg );
1401 switch( msg )
1403 case WM_DELETEITEM:
1405 DELETEITEMSTRUCT *lpIS = (DELETEITEMSTRUCT *)lParam;
1406 lpIS->CtlType = ODT_COMBOBOX;
1407 lpIS->CtlID = id;
1408 lpIS->hwndItem = hWnd;
1409 break;
1411 case WM_DRAWITEM:
1413 DRAWITEMSTRUCT *lpIS = (DRAWITEMSTRUCT *)lParam;
1414 lpIS->CtlType = ODT_COMBOBOX;
1415 lpIS->CtlID = id;
1416 lpIS->hwndItem = hWnd;
1417 break;
1419 case WM_COMPAREITEM:
1421 COMPAREITEMSTRUCT *lpIS = (COMPAREITEMSTRUCT *)lParam;
1422 lpIS->CtlType = ODT_COMBOBOX;
1423 lpIS->CtlID = id;
1424 lpIS->hwndItem = hWnd;
1425 break;
1427 case WM_MEASUREITEM:
1429 MEASUREITEMSTRUCT *lpIS = (MEASUREITEMSTRUCT *)lParam;
1430 lpIS->CtlType = ODT_COMBOBOX;
1431 lpIS->CtlID = id;
1432 break;
1435 return SendMessageW(lphc->owner, msg, id, lParam);
1439 /***********************************************************************
1440 * COMBO_GetTextW
1442 static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf )
1444 INT length;
1446 if( lphc->wState & CBF_EDIT )
1447 return SendMessageW( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1449 /* get it from the listbox */
1451 if (!count || !buf) return 0;
1452 if( lphc->hWndLBox )
1454 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1455 if (idx == LB_ERR) goto error;
1456 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1457 if (length == LB_ERR) goto error;
1459 /* 'length' is without the terminating character */
1460 if (length >= count)
1462 LPWSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1463 if (!lpBuffer) goto error;
1464 length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1466 /* truncate if buffer is too short */
1467 if (length != LB_ERR)
1469 lstrcpynW( buf, lpBuffer, count );
1470 length = count;
1472 HeapFree( GetProcessHeap(), 0, lpBuffer );
1474 else length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1476 if (length == LB_ERR) return 0;
1477 return length;
1480 error: /* error - truncate string, return zero */
1481 buf[0] = 0;
1482 return 0;
1486 /***********************************************************************
1487 * COMBO_GetTextA
1489 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1490 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1492 static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf )
1494 INT length;
1496 if( lphc->wState & CBF_EDIT )
1497 return SendMessageA( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1499 /* get it from the listbox */
1501 if (!count || !buf) return 0;
1502 if( lphc->hWndLBox )
1504 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1505 if (idx == LB_ERR) goto error;
1506 length = SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1507 if (length == LB_ERR) goto error;
1509 /* 'length' is without the terminating character */
1510 if (length >= count)
1512 LPSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) );
1513 if (!lpBuffer) goto error;
1514 length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1516 /* truncate if buffer is too short */
1517 if (length != LB_ERR)
1519 lstrcpynA( buf, lpBuffer, count );
1520 length = count;
1522 HeapFree( GetProcessHeap(), 0, lpBuffer );
1524 else length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1526 if (length == LB_ERR) return 0;
1527 return length;
1530 error: /* error - truncate string, return zero */
1531 buf[0] = 0;
1532 return 0;
1536 /***********************************************************************
1537 * CBResetPos
1539 * This function sets window positions according to the updated
1540 * component placement struct.
1542 static void CBResetPos(
1543 LPHEADCOMBO lphc,
1544 LPRECT rectEdit,
1545 LPRECT rectLB,
1546 BOOL bRedraw)
1548 BOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE);
1550 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1551 * sizing messages */
1553 if( lphc->wState & CBF_EDIT )
1554 SetWindowPos( lphc->hWndEdit, 0,
1555 rectEdit->left, rectEdit->top,
1556 rectEdit->right - rectEdit->left,
1557 rectEdit->bottom - rectEdit->top,
1558 SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) );
1560 SetWindowPos( lphc->hWndLBox, 0,
1561 rectLB->left, rectLB->top,
1562 rectLB->right - rectLB->left,
1563 rectLB->bottom - rectLB->top,
1564 SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) );
1566 if( bDrop )
1568 if( lphc->wState & CBF_DROPPED )
1570 lphc->wState &= ~CBF_DROPPED;
1571 ShowWindow( lphc->hWndLBox, SW_HIDE );
1574 if( bRedraw && !(lphc->wState & CBF_NOREDRAW) )
1575 RedrawWindow( lphc->self, NULL, 0,
1576 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
1581 /***********************************************************************
1582 * COMBO_Size
1584 static void COMBO_Size( LPHEADCOMBO lphc, BOOL bRedraw )
1586 RECT oldtext,olddrop;
1587 CopyRect(&oldtext,&lphc->textRect);
1588 CopyRect(&olddrop,&lphc->droppedRect);
1590 CBCalcPlacement(lphc->self,
1591 lphc,
1592 &lphc->textRect,
1593 &lphc->buttonRect,
1594 &lphc->droppedRect);
1596 if (EqualRect(&oldtext,&lphc->textRect) &&
1597 EqualRect(&olddrop,&lphc->droppedRect))
1598 return;
1599 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, bRedraw );
1603 /***********************************************************************
1604 * COMBO_Font
1606 static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
1609 * Set the font
1611 lphc->hFont = hFont;
1614 * Propagate to owned windows.
1616 if( lphc->wState & CBF_EDIT )
1617 SendMessageW(lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw);
1618 SendMessageW(lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw);
1621 * Redo the layout of the control.
1623 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1625 CBCalcPlacement(lphc->self,
1626 lphc,
1627 &lphc->textRect,
1628 &lphc->buttonRect,
1629 &lphc->droppedRect);
1631 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1633 else
1635 CBForceDummyResize(lphc);
1640 /***********************************************************************
1641 * COMBO_SetItemHeight
1643 static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
1645 LRESULT lRet = CB_ERR;
1647 if( index == -1 ) /* set text field height */
1649 if( height < 32768 )
1651 lphc->editHeight = height;
1654 * Redo the layout of the control.
1656 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1658 CBCalcPlacement(lphc->self,
1659 lphc,
1660 &lphc->textRect,
1661 &lphc->buttonRect,
1662 &lphc->droppedRect);
1664 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1666 else
1668 CBForceDummyResize(lphc);
1671 lRet = height;
1674 else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */
1675 lRet = SendMessageW(lphc->hWndLBox, LB_SETITEMHEIGHT,
1676 (WPARAM)index, (LPARAM)height );
1677 return lRet;
1680 /***********************************************************************
1681 * COMBO_SelectString
1683 static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPARAM pText, BOOL unicode )
1685 INT index = unicode ? SendMessageW(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText) :
1686 SendMessageA(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText);
1687 if( index >= 0 )
1689 if( lphc->wState & CBF_EDIT )
1690 CBUpdateEdit( lphc, index );
1691 else
1693 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1696 return (LRESULT)index;
1699 /***********************************************************************
1700 * COMBO_LButtonDown
1702 static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam )
1704 POINT pt;
1705 BOOL bButton;
1706 HWND hWnd = lphc->self;
1708 pt.x = (short)LOWORD(lParam);
1709 pt.y = (short)HIWORD(lParam);
1710 bButton = PtInRect(&lphc->buttonRect, pt);
1712 if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) ||
1713 (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) )
1715 lphc->wState |= CBF_BUTTONDOWN;
1716 if( lphc->wState & CBF_DROPPED )
1718 /* got a click to cancel selection */
1720 lphc->wState &= ~CBF_BUTTONDOWN;
1721 CBRollUp( lphc, TRUE, FALSE );
1722 if( !IsWindow( hWnd ) ) return;
1724 if( lphc->wState & CBF_CAPTURE )
1726 lphc->wState &= ~CBF_CAPTURE;
1727 ReleaseCapture();
1730 else
1732 /* drop down the listbox and start tracking */
1734 lphc->wState |= CBF_CAPTURE;
1735 SetCapture( hWnd );
1736 CBDropDown( lphc );
1738 if( bButton ) CBRepaintButton( lphc );
1742 /***********************************************************************
1743 * COMBO_LButtonUp
1745 * Release capture and stop tracking if needed.
1747 static void COMBO_LButtonUp( LPHEADCOMBO lphc )
1749 if( lphc->wState & CBF_CAPTURE )
1751 lphc->wState &= ~CBF_CAPTURE;
1752 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1754 INT index = CBUpdateLBox( lphc, TRUE );
1755 /* Update edit only if item is in the list */
1756 if(index >= 0)
1758 lphc->wState |= CBF_NOLBSELECT;
1759 CBUpdateEdit( lphc, index );
1760 lphc->wState &= ~CBF_NOLBSELECT;
1763 ReleaseCapture();
1764 SetCapture(lphc->hWndLBox);
1767 if( lphc->wState & CBF_BUTTONDOWN )
1769 lphc->wState &= ~CBF_BUTTONDOWN;
1770 CBRepaintButton( lphc );
1774 /***********************************************************************
1775 * COMBO_MouseMove
1777 * Two things to do - track combo button and release capture when
1778 * pointer goes into the listbox.
1780 static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam )
1782 POINT pt;
1783 RECT lbRect;
1785 pt.x = (short)LOWORD(lParam);
1786 pt.y = (short)HIWORD(lParam);
1788 if( lphc->wState & CBF_BUTTONDOWN )
1790 BOOL bButton;
1792 bButton = PtInRect(&lphc->buttonRect, pt);
1794 if( !bButton )
1796 lphc->wState &= ~CBF_BUTTONDOWN;
1797 CBRepaintButton( lphc );
1801 GetClientRect( lphc->hWndLBox, &lbRect );
1802 MapWindowPoints( lphc->self, lphc->hWndLBox, &pt, 1 );
1803 if( PtInRect(&lbRect, pt) )
1805 lphc->wState &= ~CBF_CAPTURE;
1806 ReleaseCapture();
1807 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc, TRUE );
1809 /* hand over pointer tracking */
1810 SendMessageW(lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam);
1814 static LRESULT COMBO_GetComboBoxInfo(LPHEADCOMBO lphc, COMBOBOXINFO *pcbi)
1816 if (!pcbi || (pcbi->cbSize < sizeof(COMBOBOXINFO)))
1817 return FALSE;
1819 pcbi->rcItem = lphc->textRect;
1820 pcbi->rcButton = lphc->buttonRect;
1821 pcbi->stateButton = 0;
1822 if (lphc->wState & CBF_BUTTONDOWN)
1823 pcbi->stateButton |= STATE_SYSTEM_PRESSED;
1824 if (IsRectEmpty(&lphc->buttonRect))
1825 pcbi->stateButton |= STATE_SYSTEM_INVISIBLE;
1826 pcbi->hwndCombo = lphc->self;
1827 pcbi->hwndItem = lphc->hWndEdit;
1828 pcbi->hwndList = lphc->hWndLBox;
1829 return TRUE;
1832 static char *strdupA(LPCSTR str)
1834 char *ret;
1835 DWORD len;
1837 if(!str) return NULL;
1839 len = strlen(str);
1840 ret = HeapAlloc(GetProcessHeap(), 0, len + 1);
1841 memcpy(ret, str, len + 1);
1842 return ret;
1845 /***********************************************************************
1846 * ComboWndProc_common
1848 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxes.asp
1850 static LRESULT ComboWndProc_common( HWND hwnd, UINT message,
1851 WPARAM wParam, LPARAM lParam, BOOL unicode )
1853 LPHEADCOMBO lphc = (LPHEADCOMBO)GetWindowLongPtrW( hwnd, 0 );
1855 TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1856 hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1858 if( lphc || message == WM_NCCREATE )
1859 switch(message)
1862 /* System messages */
1864 case WM_NCCREATE:
1866 LONG style = unicode ? ((LPCREATESTRUCTW)lParam)->style :
1867 ((LPCREATESTRUCTA)lParam)->style;
1868 return COMBO_NCCreate(hwnd, style);
1870 case WM_NCDESTROY:
1871 COMBO_NCDestroy(lphc);
1872 break;/* -> DefWindowProc */
1874 case WM_CREATE:
1876 HWND hwndParent;
1877 LONG style;
1878 if(unicode)
1880 hwndParent = ((LPCREATESTRUCTW)lParam)->hwndParent;
1881 style = ((LPCREATESTRUCTW)lParam)->style;
1883 else
1885 hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent;
1886 style = ((LPCREATESTRUCTA)lParam)->style;
1888 return COMBO_Create(hwnd, lphc, hwndParent, style, unicode);
1891 case WM_PRINTCLIENT:
1892 /* Fallthrough */
1893 case WM_PAINT:
1894 /* wParam may contain a valid HDC! */
1895 return COMBO_Paint(lphc, (HDC)wParam);
1897 case WM_ERASEBKGND:
1898 /* do all painting in WM_PAINT like Windows does */
1899 return 1;
1901 case WM_GETDLGCODE:
1903 LRESULT result = DLGC_WANTARROWS | DLGC_WANTCHARS;
1904 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1906 int vk = (int)((LPMSG)lParam)->wParam;
1908 if ((vk == VK_RETURN || vk == VK_ESCAPE) && (lphc->wState & CBF_DROPPED))
1909 result |= DLGC_WANTMESSAGE;
1911 return result;
1913 case WM_WINDOWPOSCHANGING:
1914 return COMBO_WindowPosChanging(hwnd, lphc, (LPWINDOWPOS)lParam);
1915 case WM_WINDOWPOSCHANGED:
1916 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1917 * In that case, the Combobox itself will not be resized, so we won't
1918 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1919 * do it here.
1921 /* we should not force repainting on WM_WINDOWPOSCHANGED, it breaks
1922 * Z-order based painting.
1924 /* fall through */
1925 case WM_SIZE:
1926 if( lphc->hWndLBox &&
1927 !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc, message == WM_SIZE );
1928 return TRUE;
1929 case WM_SETFONT:
1930 COMBO_Font( lphc, (HFONT)wParam, (BOOL)lParam );
1931 return TRUE;
1932 case WM_GETFONT:
1933 return (LRESULT)lphc->hFont;
1934 case WM_SETFOCUS:
1935 if( lphc->wState & CBF_EDIT )
1936 SetFocus( lphc->hWndEdit );
1937 else
1938 COMBO_SetFocus( lphc );
1939 return TRUE;
1940 case WM_KILLFOCUS:
1942 HWND hwndFocus = WIN_GetFullHandle( (HWND)wParam );
1943 if( !hwndFocus ||
1944 (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox ))
1945 COMBO_KillFocus( lphc );
1946 return TRUE;
1948 case WM_COMMAND:
1949 return COMBO_Command( lphc, wParam, WIN_GetFullHandle( (HWND)lParam ) );
1950 case WM_GETTEXT:
1951 return unicode ? COMBO_GetTextW( lphc, wParam, (LPWSTR)lParam )
1952 : COMBO_GetTextA( lphc, wParam, (LPSTR)lParam );
1953 case WM_SETTEXT:
1954 case WM_GETTEXTLENGTH:
1955 case WM_CLEAR:
1956 if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT))
1958 int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1959 if (j == -1) return 0;
1960 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0) :
1961 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, j, 0);
1963 else if( lphc->wState & CBF_EDIT )
1965 LRESULT ret;
1966 lphc->wState |= CBF_NOEDITNOTIFY;
1967 ret = unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1968 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1969 lphc->wState &= ~CBF_NOEDITNOTIFY;
1970 return ret;
1972 else return CB_ERR;
1973 case WM_CUT:
1974 case WM_PASTE:
1975 case WM_COPY:
1976 if( lphc->wState & CBF_EDIT )
1978 return unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1979 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1981 else return CB_ERR;
1983 case WM_DRAWITEM:
1985 * WM_DELETEITEM causes an infinite loop within the ACT2000 installer
1986 * so we need to revisit why this is here and why we get the loop in
1987 * ACT2000
1989 case WM_DELETEITEM:
1991 case WM_COMPAREITEM:
1992 case WM_MEASUREITEM:
1993 return COMBO_ItemOp(lphc, message, lParam);
1994 case WM_ENABLE:
1995 if( lphc->wState & CBF_EDIT )
1996 EnableWindow( lphc->hWndEdit, (BOOL)wParam );
1997 EnableWindow( lphc->hWndLBox, (BOOL)wParam );
1999 /* Force the control to repaint when the enabled state changes. */
2000 InvalidateRect(lphc->self, NULL, TRUE);
2001 return TRUE;
2002 case WM_SETREDRAW:
2003 if( wParam )
2004 lphc->wState &= ~CBF_NOREDRAW;
2005 else
2006 lphc->wState |= CBF_NOREDRAW;
2008 if( lphc->wState & CBF_EDIT )
2009 SendMessageW(lphc->hWndEdit, message, wParam, lParam);
2010 SendMessageW(lphc->hWndLBox, message, wParam, lParam);
2011 return 0;
2012 case WM_SYSKEYDOWN:
2013 if( KEYDATA_ALT & HIWORD(lParam) )
2014 if( wParam == VK_UP || wParam == VK_DOWN )
2015 COMBO_FlipListbox( lphc, FALSE, FALSE );
2016 return 0;
2018 case WM_CHAR:
2019 case WM_IME_CHAR:
2020 case WM_KEYDOWN:
2022 HWND hwndTarget;
2024 if ((wParam == VK_RETURN || wParam == VK_ESCAPE) &&
2025 (lphc->wState & CBF_DROPPED))
2027 CBRollUp( lphc, wParam == VK_RETURN, FALSE );
2028 return TRUE;
2030 else if ((wParam == VK_F4) && !(lphc->wState & CBF_EUI))
2032 COMBO_FlipListbox( lphc, FALSE, FALSE );
2033 return TRUE;
2036 if( lphc->wState & CBF_EDIT )
2037 hwndTarget = lphc->hWndEdit;
2038 else
2039 hwndTarget = lphc->hWndLBox;
2041 return unicode ? SendMessageW(hwndTarget, message, wParam, lParam) :
2042 SendMessageA(hwndTarget, message, wParam, lParam);
2044 case WM_LBUTTONDOWN:
2045 if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self );
2046 if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
2047 return TRUE;
2048 case WM_LBUTTONUP:
2049 COMBO_LButtonUp( lphc );
2050 return TRUE;
2051 case WM_MOUSEMOVE:
2052 if( lphc->wState & CBF_CAPTURE )
2053 COMBO_MouseMove( lphc, wParam, lParam );
2054 return TRUE;
2056 case WM_MOUSEWHEEL:
2057 if (wParam & (MK_SHIFT | MK_CONTROL))
2058 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2059 DefWindowProcA(hwnd, message, wParam, lParam);
2061 if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_UP, 0);
2062 if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_DOWN, 0);
2063 return TRUE;
2065 /* Combo messages */
2067 case CB_ADDSTRING16:
2068 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2069 /* fall through */
2070 case CB_ADDSTRING:
2071 if( unicode )
2073 if( lphc->dwStyle & CBS_LOWERCASE )
2074 CharLowerW((LPWSTR)lParam);
2075 else if( lphc->dwStyle & CBS_UPPERCASE )
2076 CharUpperW((LPWSTR)lParam);
2077 return SendMessageW(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2079 else /* unlike the unicode version, the ansi version does not overwrite
2080 the string if converting case */
2082 char *string = NULL;
2083 LRESULT ret;
2084 if( lphc->dwStyle & CBS_LOWERCASE )
2086 string = strdupA((LPSTR)lParam);
2087 CharLowerA(string);
2090 else if( lphc->dwStyle & CBS_UPPERCASE )
2092 string = strdupA((LPSTR)lParam);
2093 CharUpperA(string);
2096 ret = SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, string ? (LPARAM)string : lParam);
2097 HeapFree(GetProcessHeap(), 0, string);
2098 return ret;
2100 case CB_INSERTSTRING16:
2101 wParam = (INT)(INT16)wParam;
2102 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2103 /* fall through */
2104 case CB_INSERTSTRING:
2105 if( unicode )
2107 if( lphc->dwStyle & CBS_LOWERCASE )
2108 CharLowerW((LPWSTR)lParam);
2109 else if( lphc->dwStyle & CBS_UPPERCASE )
2110 CharUpperW((LPWSTR)lParam);
2111 return SendMessageW(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2113 else
2115 if( lphc->dwStyle & CBS_LOWERCASE )
2116 CharLowerA((LPSTR)lParam);
2117 else if( lphc->dwStyle & CBS_UPPERCASE )
2118 CharUpperA((LPSTR)lParam);
2120 return SendMessageA(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2122 case CB_DELETESTRING16:
2123 case CB_DELETESTRING:
2124 return unicode ? SendMessageW(lphc->hWndLBox, LB_DELETESTRING, wParam, 0) :
2125 SendMessageA(lphc->hWndLBox, LB_DELETESTRING, wParam, 0);
2126 case CB_SELECTSTRING16:
2127 wParam = (INT)(INT16)wParam;
2128 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2129 /* fall through */
2130 case CB_SELECTSTRING:
2131 return COMBO_SelectString(lphc, (INT)wParam, lParam, unicode);
2132 case CB_FINDSTRING16:
2133 wParam = (INT)(INT16)wParam;
2134 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2135 /* fall through */
2136 case CB_FINDSTRING:
2137 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam) :
2138 SendMessageA(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam);
2139 case CB_FINDSTRINGEXACT16:
2140 wParam = (INT)(INT16)wParam;
2141 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2142 /* fall through */
2143 case CB_FINDSTRINGEXACT:
2144 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam) :
2145 SendMessageA(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam);
2146 case CB_SETITEMHEIGHT16:
2147 wParam = (INT)(INT16)wParam; /* signed integer */
2148 /* fall through */
2149 case CB_SETITEMHEIGHT:
2150 return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam);
2151 case CB_GETITEMHEIGHT16:
2152 wParam = (INT)(INT16)wParam;
2153 /* fall through */
2154 case CB_GETITEMHEIGHT:
2155 if( (INT)wParam >= 0 ) /* listbox item */
2156 return SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0);
2157 return CBGetTextAreaHeight(hwnd, lphc);
2158 case CB_RESETCONTENT16:
2159 case CB_RESETCONTENT:
2160 SendMessageW(lphc->hWndLBox, LB_RESETCONTENT, 0, 0);
2161 if( (lphc->wState & CBF_EDIT) && CB_HASSTRINGS(lphc) )
2163 static const WCHAR empty_stringW[] = { 0 };
2164 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);
2166 else
2167 InvalidateRect(lphc->self, NULL, TRUE);
2168 return TRUE;
2169 case CB_INITSTORAGE:
2170 return SendMessageW(lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam);
2171 case CB_GETHORIZONTALEXTENT:
2172 return SendMessageW(lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0);
2173 case CB_SETHORIZONTALEXTENT:
2174 return SendMessageW(lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0);
2175 case CB_GETTOPINDEX:
2176 return SendMessageW(lphc->hWndLBox, LB_GETTOPINDEX, 0, 0);
2177 case CB_GETLOCALE:
2178 return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0);
2179 case CB_SETLOCALE:
2180 return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0);
2181 case CB_GETDROPPEDWIDTH:
2182 if( lphc->droppedWidth )
2183 return lphc->droppedWidth;
2184 return lphc->droppedRect.right - lphc->droppedRect.left;
2185 case CB_SETDROPPEDWIDTH:
2186 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) &&
2187 (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam;
2188 return CB_ERR;
2189 case CB_GETDROPPEDCONTROLRECT16:
2190 lParam = (LPARAM)MapSL(lParam);
2191 if( lParam )
2193 RECT r;
2194 RECT16 *r16 = (RECT16 *)lParam;
2195 CBGetDroppedControlRect( lphc, &r );
2196 r16->left = r.left;
2197 r16->top = r.top;
2198 r16->right = r.right;
2199 r16->bottom = r.bottom;
2201 return CB_OKAY;
2202 case CB_GETDROPPEDCONTROLRECT:
2203 if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam );
2204 return CB_OKAY;
2205 case CB_GETDROPPEDSTATE16:
2206 case CB_GETDROPPEDSTATE:
2207 return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE;
2208 case CB_DIR16:
2209 return SendMessageA(lphc->hWndLBox, LB_DIR16, wParam, lParam);
2210 case CB_DIR:
2211 return unicode ? SendMessageW(lphc->hWndLBox, LB_DIR, wParam, lParam) :
2212 SendMessageA(lphc->hWndLBox, LB_DIR, wParam, lParam);
2214 case CB_SHOWDROPDOWN16:
2215 case CB_SHOWDROPDOWN:
2216 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
2218 if( wParam )
2220 if( !(lphc->wState & CBF_DROPPED) )
2221 CBDropDown( lphc );
2223 else
2224 if( lphc->wState & CBF_DROPPED )
2225 CBRollUp( lphc, FALSE, TRUE );
2227 return TRUE;
2228 case CB_GETCOUNT16:
2229 case CB_GETCOUNT:
2230 return SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
2231 case CB_GETCURSEL16:
2232 case CB_GETCURSEL:
2233 return SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
2234 case CB_SETCURSEL16:
2235 wParam = (INT)(INT16)wParam;
2236 /* fall through */
2237 case CB_SETCURSEL:
2238 lParam = SendMessageW(lphc->hWndLBox, LB_SETCURSEL, wParam, 0);
2239 if( lParam >= 0 )
2240 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, wParam, 0);
2242 /* no LBN_SELCHANGE in this case, update manually */
2243 if( lphc->wState & CBF_EDIT )
2244 CBUpdateEdit( lphc, (INT)wParam );
2245 else
2246 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
2247 lphc->wState &= ~CBF_SELCHANGE;
2248 return lParam;
2249 case CB_GETLBTEXT16:
2250 wParam = (INT)(INT16)wParam;
2251 lParam = (LPARAM)MapSL(lParam);
2252 /* fall through */
2253 case CB_GETLBTEXT:
2254 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXT, wParam, lParam) :
2255 SendMessageA(lphc->hWndLBox, LB_GETTEXT, wParam, lParam);
2256 case CB_GETLBTEXTLEN16:
2257 wParam = (INT)(INT16)wParam;
2258 /* fall through */
2259 case CB_GETLBTEXTLEN:
2260 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0) :
2261 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0);
2262 case CB_GETITEMDATA16:
2263 wParam = (INT)(INT16)wParam;
2264 /* fall through */
2265 case CB_GETITEMDATA:
2266 return SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0);
2267 case CB_SETITEMDATA16:
2268 wParam = (INT)(INT16)wParam;
2269 /* fall through */
2270 case CB_SETITEMDATA:
2271 return SendMessageW(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam);
2272 case CB_GETEDITSEL16:
2273 wParam = lParam = 0; /* just in case */
2274 /* fall through */
2275 case CB_GETEDITSEL:
2276 /* Edit checks passed parameters itself */
2277 if( lphc->wState & CBF_EDIT )
2278 return SendMessageW(lphc->hWndEdit, EM_GETSEL, wParam, lParam);
2279 return CB_ERR;
2280 case CB_SETEDITSEL16:
2281 case CB_SETEDITSEL:
2282 if( lphc->wState & CBF_EDIT )
2283 return SendMessageW(lphc->hWndEdit, EM_SETSEL,
2284 (INT)(INT16)LOWORD(lParam), (INT)(INT16)HIWORD(lParam) );
2285 return CB_ERR;
2286 case CB_SETEXTENDEDUI16:
2287 case CB_SETEXTENDEDUI:
2288 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
2289 return CB_ERR;
2290 if( wParam )
2291 lphc->wState |= CBF_EUI;
2292 else lphc->wState &= ~CBF_EUI;
2293 return CB_OKAY;
2294 case CB_GETEXTENDEDUI16:
2295 case CB_GETEXTENDEDUI:
2296 return (lphc->wState & CBF_EUI) ? TRUE : FALSE;
2297 case CB_GETCOMBOBOXINFO:
2298 return COMBO_GetComboBoxInfo(lphc, (COMBOBOXINFO *)lParam);
2299 case CB_LIMITTEXT:
2300 if( lphc->wState & CBF_EDIT )
2301 return SendMessageW(lphc->hWndEdit, EM_LIMITTEXT, wParam, lParam);
2302 default:
2303 if (message >= WM_USER)
2304 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2305 message - WM_USER, wParam, lParam );
2306 break;
2308 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2309 DefWindowProcA(hwnd, message, wParam, lParam);
2312 /***********************************************************************
2313 * ComboWndProcA
2315 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2316 * window structs.
2318 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2320 if (!IsWindow(hwnd)) return 0;
2321 return ComboWndProc_common( hwnd, message, wParam, lParam, FALSE );
2324 /***********************************************************************
2325 * ComboWndProcW
2327 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2329 if (!IsWindow(hwnd)) return 0;
2330 return ComboWndProc_common( hwnd, message, wParam, lParam, TRUE );
2333 /*************************************************************************
2334 * GetComboBoxInfo (USER32.@)
2336 BOOL WINAPI GetComboBoxInfo(HWND hwndCombo, /* [in] handle to combo box */
2337 PCOMBOBOXINFO pcbi /* [in/out] combo box information */)
2339 TRACE("(%p, %p)\n", hwndCombo, pcbi);
2340 return SendMessageW(hwndCombo, CB_GETCOMBOBOXINFO, 0, (LPARAM)pcbi);