exdisp.idl: Added missing IE6 methods to DWebBrowserEvents2.
[wine/hacks.git] / dlls / user / combo.c
blob55f04f9574f5448b682a4df188a6f8c5a0bea9d8
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 * - ComboBox_[GS]etMinVisible()
31 * - CB_GETMINVISIBLE, CB_SETMINVISIBLE
32 * - CB_SETTOPINDEX
35 #include <stdarg.h>
36 #include <string.h>
38 #include "windef.h"
39 #include "winbase.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "wine/winuser16.h"
43 #include "wine/unicode.h"
44 #include "user_private.h"
45 #include "win.h"
46 #include "controls.h"
47 #include "winreg.h"
48 #include "winternl.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(combo);
53 /* bits in the dwKeyData */
54 #define KEYDATA_ALT 0x2000
55 #define KEYDATA_PREVSTATE 0x4000
58 * Additional combo box definitions
61 #define CB_NOTIFY( lphc, code ) \
62 (SendMessageW((lphc)->owner, WM_COMMAND, \
63 MAKEWPARAM(GetWindowLongPtrW((lphc)->self,GWLP_ID), (code)), (LPARAM)(lphc)->self))
65 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
66 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
67 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
68 #define CB_HWND( lphc ) ((lphc)->self)
69 #define CB_GETTYPE( lphc ) ((lphc)->dwStyle & (CBS_DROPDOWNLIST))
71 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
74 * Drawing globals
76 static HBITMAP hComboBmp = 0;
77 static UINT CBitHeight, CBitWidth;
80 * Look and feel dependent "constants"
83 #define COMBO_YBORDERGAP 5
84 #define COMBO_XBORDERSIZE() 2
85 #define COMBO_YBORDERSIZE() 2
86 #define COMBO_EDITBUTTONSPACE() 0
87 #define EDIT_CONTROL_PADDING() 1
89 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
90 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
92 /*********************************************************************
93 * combo class descriptor
95 const struct builtin_class_descr COMBO_builtin_class =
97 "ComboBox", /* name */
98 CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, /* style */
99 ComboWndProcA, /* procA */
100 ComboWndProcW, /* procW */
101 sizeof(HEADCOMBO *), /* extra */
102 IDC_ARROW, /* cursor */
103 0 /* brush */
107 /***********************************************************************
108 * COMBO_Init
110 * Load combo button bitmap.
112 static BOOL COMBO_Init(void)
114 HDC hDC;
116 if( hComboBmp ) return TRUE;
117 if( (hDC = CreateCompatibleDC(0)) )
119 BOOL bRet = FALSE;
120 if( (hComboBmp = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO))) )
122 BITMAP bm;
123 HBITMAP hPrevB;
124 RECT r;
126 GetObjectW( hComboBmp, sizeof(bm), &bm );
127 CBitHeight = bm.bmHeight;
128 CBitWidth = bm.bmWidth;
130 TRACE("combo bitmap [%i,%i]\n", CBitWidth, CBitHeight );
132 hPrevB = SelectObject( hDC, hComboBmp);
133 SetRect( &r, 0, 0, CBitWidth, CBitHeight );
134 InvertRect( hDC, &r );
135 SelectObject( hDC, hPrevB );
136 bRet = TRUE;
138 DeleteDC( hDC );
139 return bRet;
141 return FALSE;
144 /***********************************************************************
145 * COMBO_NCCreate
147 static LRESULT COMBO_NCCreate(HWND hwnd, LONG style)
149 LPHEADCOMBO lphc;
151 if (COMBO_Init() && (lphc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEADCOMBO))) )
153 lphc->self = hwnd;
154 SetWindowLongPtrW( hwnd, 0, (LONG_PTR)lphc );
156 /* some braindead apps do try to use scrollbar/border flags */
158 lphc->dwStyle = style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
159 SetWindowLongW( hwnd, GWL_STYLE, style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL) );
162 * We also have to remove the client edge style to make sure
163 * we don't end-up with a non client area.
165 SetWindowLongW( hwnd, GWL_EXSTYLE,
166 GetWindowLongW( hwnd, GWL_EXSTYLE ) & ~WS_EX_CLIENTEDGE );
168 if( !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
169 lphc->dwStyle |= CBS_HASSTRINGS;
170 if( !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) )
171 lphc->wState |= CBF_NOTIFY;
173 TRACE("[%p], style = %08x\n", lphc, lphc->dwStyle );
174 return TRUE;
176 return FALSE;
179 /***********************************************************************
180 * COMBO_NCDestroy
182 static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc )
185 if( lphc )
187 TRACE("[%p]: freeing storage\n", lphc->self);
189 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && lphc->hWndLBox )
190 DestroyWindow( lphc->hWndLBox );
192 SetWindowLongPtrW( lphc->self, 0, 0 );
193 HeapFree( GetProcessHeap(), 0, lphc );
195 return 0;
198 /***********************************************************************
199 * CBGetTextAreaHeight
201 * This method will calculate the height of the text area of the
202 * combobox.
203 * The height of the text area is set in two ways.
204 * It can be set explicitly through a combobox message or through a
205 * WM_MEASUREITEM callback.
206 * If this is not the case, the height is set to 13 dialog units.
207 * This height was determined through experimentation.
209 static INT CBGetTextAreaHeight(
210 HWND hwnd,
211 LPHEADCOMBO lphc)
213 INT iTextItemHeight;
215 if( lphc->editHeight ) /* explicitly set height */
217 iTextItemHeight = lphc->editHeight;
219 else
221 TEXTMETRICW tm;
222 HDC hDC = GetDC(hwnd);
223 HFONT hPrevFont = 0;
224 INT baseUnitY;
226 if (lphc->hFont)
227 hPrevFont = SelectObject( hDC, lphc->hFont );
229 GetTextMetricsW(hDC, &tm);
231 baseUnitY = tm.tmHeight;
233 if( hPrevFont )
234 SelectObject( hDC, hPrevFont );
236 ReleaseDC(hwnd, hDC);
238 iTextItemHeight = ((13 * baseUnitY) / 8);
241 * This "formula" calculates the height of the complete control.
242 * To calculate the height of the text area, we have to remove the
243 * borders.
245 iTextItemHeight -= 2*COMBO_YBORDERSIZE();
249 * Check the ownerdraw case if we haven't asked the parent the size
250 * of the item yet.
252 if ( CB_OWNERDRAWN(lphc) &&
253 (lphc->wState & CBF_MEASUREITEM) )
255 MEASUREITEMSTRUCT measureItem;
256 RECT clientRect;
257 INT originalItemHeight = iTextItemHeight;
258 UINT id = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
261 * We use the client rect for the width of the item.
263 GetClientRect(hwnd, &clientRect);
265 lphc->wState &= ~CBF_MEASUREITEM;
268 * Send a first one to measure the size of the text area
270 measureItem.CtlType = ODT_COMBOBOX;
271 measureItem.CtlID = id;
272 measureItem.itemID = -1;
273 measureItem.itemWidth = clientRect.right;
274 measureItem.itemHeight = iTextItemHeight - 6; /* ownerdrawn cb is taller */
275 measureItem.itemData = 0;
276 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
277 iTextItemHeight = 6 + measureItem.itemHeight;
280 * Send a second one in the case of a fixed ownerdraw list to calculate the
281 * size of the list items. (we basically do this on behalf of the listbox)
283 if (lphc->dwStyle & CBS_OWNERDRAWFIXED)
285 measureItem.CtlType = ODT_COMBOBOX;
286 measureItem.CtlID = id;
287 measureItem.itemID = 0;
288 measureItem.itemWidth = clientRect.right;
289 measureItem.itemHeight = originalItemHeight;
290 measureItem.itemData = 0;
291 SendMessageW(lphc->owner, WM_MEASUREITEM, id, (LPARAM)&measureItem);
292 lphc->fixedOwnerDrawHeight = measureItem.itemHeight;
296 * Keep the size for the next time
298 lphc->editHeight = iTextItemHeight;
301 return iTextItemHeight;
304 /***********************************************************************
305 * CBForceDummyResize
307 * The dummy resize is used for listboxes that have a popup to trigger
308 * a re-arranging of the contents of the combobox and the recalculation
309 * of the size of the "real" control window.
311 static void CBForceDummyResize(
312 LPHEADCOMBO lphc)
314 RECT windowRect;
315 int newComboHeight;
317 newComboHeight = CBGetTextAreaHeight(lphc->self,lphc) + 2*COMBO_YBORDERSIZE();
319 GetWindowRect(lphc->self, &windowRect);
322 * We have to be careful, resizing a combobox also has the meaning that the
323 * dropped rect will be resized. In this case, we want to trigger a resize
324 * to recalculate layout but we don't want to change the dropped rectangle
325 * So, we pass the height of text area of control as the height.
326 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
327 * message.
329 SetWindowPos( lphc->self,
330 NULL,
331 0, 0,
332 windowRect.right - windowRect.left,
333 newComboHeight,
334 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
337 /***********************************************************************
338 * CBCalcPlacement
340 * Set up component coordinates given valid lphc->RectCombo.
342 static void CBCalcPlacement(
343 HWND hwnd,
344 LPHEADCOMBO lphc,
345 LPRECT lprEdit,
346 LPRECT lprButton,
347 LPRECT lprLB)
350 * Again, start with the client rectangle.
352 GetClientRect(hwnd, lprEdit);
355 * Remove the borders
357 InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
360 * Chop off the bottom part to fit with the height of the text area.
362 lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
365 * The button starts the same vertical position as the text area.
367 CopyRect(lprButton, lprEdit);
370 * If the combobox is "simple" there is no button.
372 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
373 lprButton->left = lprButton->right = lprButton->bottom = 0;
374 else
377 * Let's assume the combobox button is the same width as the
378 * scrollbar button.
379 * size the button horizontally and cut-off the text area.
381 lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
382 lprEdit->right = lprButton->left;
386 * In the case of a dropdown, there is an additional spacing between the
387 * text area and the button.
389 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
391 lprEdit->right -= COMBO_EDITBUTTONSPACE();
395 * If we have an edit control, we space it away from the borders slightly.
397 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
399 InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
403 * Adjust the size of the listbox popup.
405 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
408 * Use the client rectangle to initialize the listbox rectangle
410 GetClientRect(hwnd, lprLB);
413 * Then, chop-off the top part.
415 lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
417 else
420 * Make sure the dropped width is as large as the combobox itself.
422 if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
424 lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
427 * In the case of a dropdown, the popup listbox is offset to the right.
428 * so, we want to make sure it's flush with the right side of the
429 * combobox
431 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
432 lprLB->right -= COMBO_EDITBUTTONSPACE();
434 else
435 lprLB->right = lprLB->left + lphc->droppedWidth;
438 /* don't allow negative window width */
439 if (lprEdit->right < lprEdit->left)
440 lprEdit->right = lprEdit->left;
442 TRACE("\ttext\t= (%ld,%ld-%ld,%ld)\n",
443 lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom);
445 TRACE("\tbutton\t= (%ld,%ld-%ld,%ld)\n",
446 lprButton->left, lprButton->top, lprButton->right, lprButton->bottom);
448 TRACE("\tlbox\t= (%ld,%ld-%ld,%ld)\n",
449 lprLB->left, lprLB->top, lprLB->right, lprLB->bottom );
452 /***********************************************************************
453 * CBGetDroppedControlRect
455 static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect)
457 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
458 of the combo box and the lower right corner of the listbox */
460 GetWindowRect(lphc->self, lpRect);
462 lpRect->right = lpRect->left + lphc->droppedRect.right - lphc->droppedRect.left;
463 lpRect->bottom = lpRect->top + lphc->droppedRect.bottom - lphc->droppedRect.top;
467 /***********************************************************************
468 * COMBO_WindowPosChanging
470 static LRESULT COMBO_WindowPosChanging(
471 HWND hwnd,
472 LPHEADCOMBO lphc,
473 WINDOWPOS* posChanging)
476 * We need to override the WM_WINDOWPOSCHANGING method to handle all
477 * the non-simple comboboxes. The problem is that those controls are
478 * always the same height. We have to make sure they are not resized
479 * to another value.
481 if ( ( CB_GETTYPE(lphc) != CBS_SIMPLE ) &&
482 ((posChanging->flags & SWP_NOSIZE) == 0) )
484 int newComboHeight;
486 newComboHeight = CBGetTextAreaHeight(hwnd,lphc) +
487 2*COMBO_YBORDERSIZE();
490 * Resizing a combobox has another side effect, it resizes the dropped
491 * rectangle as well. However, it does it only if the new height for the
492 * combobox is different from the height it should have. In other words,
493 * if the application resizing the combobox only had the intention to resize
494 * the actual control, for example, to do the layout of a dialog that is
495 * resized, the height of the dropdown is not changed.
497 if (posChanging->cy != newComboHeight)
499 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%ld, oldtop=%ld\n",
500 posChanging->cy, newComboHeight, lphc->droppedRect.bottom,
501 lphc->droppedRect.top);
502 lphc->droppedRect.bottom = lphc->droppedRect.top + posChanging->cy - newComboHeight;
504 posChanging->cy = newComboHeight;
508 return 0;
511 /***********************************************************************
512 * COMBO_Create
514 static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style,
515 BOOL unicode )
517 static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0};
518 static const WCHAR editName[] = {'E','d','i','t',0};
520 if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE;
521 if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT;
523 lphc->owner = hwndParent;
526 * The item height and dropped width are not set when the control
527 * is created.
529 lphc->droppedWidth = lphc->editHeight = 0;
532 * The first time we go through, we want to measure the ownerdraw item
534 lphc->wState |= CBF_MEASUREITEM;
536 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
538 if( lphc->owner || !(style & WS_VISIBLE) )
540 UINT lbeStyle = 0;
541 UINT lbeExStyle = 0;
544 * Initialize the dropped rect to the size of the client area of the
545 * control and then, force all the areas of the combobox to be
546 * recalculated.
548 GetClientRect( hwnd, &lphc->droppedRect );
549 CBCalcPlacement(hwnd, lphc, &lphc->textRect, &lphc->buttonRect, &lphc->droppedRect );
552 * Adjust the position of the popup listbox if it's necessary
554 if ( CB_GETTYPE(lphc) != CBS_SIMPLE )
556 lphc->droppedRect.top = lphc->textRect.bottom + COMBO_YBORDERSIZE();
559 * If it's a dropdown, the listbox is offset
561 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
562 lphc->droppedRect.left += COMBO_EDITBUTTONSPACE();
564 if (lphc->droppedRect.bottom < lphc->droppedRect.top)
565 lphc->droppedRect.bottom = lphc->droppedRect.top;
566 if (lphc->droppedRect.right < lphc->droppedRect.left)
567 lphc->droppedRect.right = lphc->droppedRect.left;
568 MapWindowPoints( hwnd, 0, (LPPOINT)&lphc->droppedRect, 2 );
571 /* create listbox popup */
573 lbeStyle = (LBS_NOTIFY | LBS_COMBOBOX | WS_BORDER | WS_CLIPSIBLINGS | WS_CHILD) |
574 (style & (WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE));
576 if( lphc->dwStyle & CBS_SORT )
577 lbeStyle |= LBS_SORT;
578 if( lphc->dwStyle & CBS_HASSTRINGS )
579 lbeStyle |= LBS_HASSTRINGS;
580 if( lphc->dwStyle & CBS_NOINTEGRALHEIGHT )
581 lbeStyle |= LBS_NOINTEGRALHEIGHT;
582 if( lphc->dwStyle & CBS_DISABLENOSCROLL )
583 lbeStyle |= LBS_DISABLENOSCROLL;
585 if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* child listbox */
587 lbeStyle |= WS_VISIBLE;
590 * In win 95 look n feel, the listbox in the simple combobox has
591 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
593 lbeStyle &= ~WS_BORDER;
594 lbeExStyle |= WS_EX_CLIENTEDGE;
596 else
598 lbeExStyle |= (WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
601 if (unicode)
602 lphc->hWndLBox = CreateWindowExW(lbeExStyle, clbName, NULL, lbeStyle,
603 lphc->droppedRect.left,
604 lphc->droppedRect.top,
605 lphc->droppedRect.right - lphc->droppedRect.left,
606 lphc->droppedRect.bottom - lphc->droppedRect.top,
607 hwnd, (HMENU)ID_CB_LISTBOX,
608 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), lphc );
609 else
610 lphc->hWndLBox = CreateWindowExA(lbeExStyle, "ComboLBox", NULL, lbeStyle,
611 lphc->droppedRect.left,
612 lphc->droppedRect.top,
613 lphc->droppedRect.right - lphc->droppedRect.left,
614 lphc->droppedRect.bottom - lphc->droppedRect.top,
615 hwnd, (HMENU)ID_CB_LISTBOX,
616 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), lphc );
618 if( lphc->hWndLBox )
620 BOOL bEdit = TRUE;
621 lbeStyle = WS_CHILD | WS_VISIBLE | ES_NOHIDESEL | ES_LEFT | ES_COMBO;
623 if( lphc->wState & CBF_EDIT )
625 if( lphc->dwStyle & CBS_OEMCONVERT )
626 lbeStyle |= ES_OEMCONVERT;
627 if( lphc->dwStyle & CBS_AUTOHSCROLL )
628 lbeStyle |= ES_AUTOHSCROLL;
629 if( lphc->dwStyle & CBS_LOWERCASE )
630 lbeStyle |= ES_LOWERCASE;
631 else if( lphc->dwStyle & CBS_UPPERCASE )
632 lbeStyle |= ES_UPPERCASE;
634 if (!IsWindowEnabled(hwnd)) lbeStyle |= WS_DISABLED;
636 if (unicode)
637 lphc->hWndEdit = CreateWindowExW(0, editName, NULL, lbeStyle,
638 lphc->textRect.left, lphc->textRect.top,
639 lphc->textRect.right - lphc->textRect.left,
640 lphc->textRect.bottom - lphc->textRect.top,
641 hwnd, (HMENU)ID_CB_EDIT,
642 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), NULL );
643 else
644 lphc->hWndEdit = CreateWindowExA(0, "Edit", NULL, lbeStyle,
645 lphc->textRect.left, lphc->textRect.top,
646 lphc->textRect.right - lphc->textRect.left,
647 lphc->textRect.bottom - lphc->textRect.top,
648 hwnd, (HMENU)ID_CB_EDIT,
649 (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE ), NULL );
651 if( !lphc->hWndEdit )
652 bEdit = FALSE;
655 if( bEdit )
657 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
659 /* Now do the trick with parent */
660 SetParent(lphc->hWndLBox, HWND_DESKTOP);
662 * If the combo is a dropdown, we must resize the control
663 * to fit only the text area and button. To do this,
664 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
665 * will take care of setting the height for us.
667 CBForceDummyResize(lphc);
670 TRACE("init done\n");
671 return 0;
673 ERR("edit control failure.\n");
674 } else ERR("listbox failure.\n");
675 } else ERR("no owner for visible combo.\n");
677 /* CreateWindow() will send WM_NCDESTROY to cleanup */
679 return -1;
682 /***********************************************************************
683 * CBPaintButton
685 * Paint combo button (normal, pressed, and disabled states).
687 static void CBPaintButton( LPHEADCOMBO lphc, HDC hdc, RECT rectButton)
689 UINT buttonState = DFCS_SCROLLCOMBOBOX;
691 if( lphc->wState & CBF_NOREDRAW )
692 return;
695 if (lphc->wState & CBF_BUTTONDOWN)
696 buttonState |= DFCS_PUSHED;
698 if (CB_DISABLED(lphc))
699 buttonState |= DFCS_INACTIVE;
701 DrawFrameControl(hdc, &rectButton, DFC_SCROLL, buttonState);
704 /***********************************************************************
705 * CBPaintText
707 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
709 static void CBPaintText(
710 LPHEADCOMBO lphc,
711 HDC hdc,
712 RECT rectEdit)
714 INT id, size = 0;
715 LPWSTR pText = NULL;
717 if( lphc->wState & CBF_NOREDRAW ) return;
719 TRACE("\n");
721 /* follow Windows combobox that sends a bunch of text
722 * inquiries to its listbox while processing WM_PAINT. */
724 if( (id = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0) ) != LB_ERR )
726 size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0);
727 if (size == LB_ERR)
728 FIXME("LB_ERR probably not handled yet\n");
729 if( (pText = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))) )
731 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
732 size=SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText);
733 pText[size] = '\0'; /* just in case */
734 } else return;
736 else
737 if( !CB_OWNERDRAWN(lphc) )
738 return;
740 if( lphc->wState & CBF_EDIT )
742 static const WCHAR empty_stringW[] = { 0 };
743 if( CB_HASSTRINGS(lphc) ) SetWindowTextW( lphc->hWndEdit, pText ? pText : empty_stringW );
744 if( lphc->wState & CBF_FOCUSED )
745 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
747 else /* paint text field ourselves */
749 UINT itemState = ODS_COMBOBOXEDIT;
750 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hdc, lphc->hFont) : 0;
753 * Give ourselves some space.
755 InflateRect( &rectEdit, -1, -1 );
757 if( CB_OWNERDRAWN(lphc) )
759 DRAWITEMSTRUCT dis;
760 HRGN clipRegion;
761 UINT ctlid = (UINT)GetWindowLongPtrW( lphc->self, GWLP_ID );
763 /* setup state for DRAWITEM message. Owner will highlight */
764 if ( (lphc->wState & CBF_FOCUSED) &&
765 !(lphc->wState & CBF_DROPPED) )
766 itemState |= ODS_SELECTED | ODS_FOCUS;
769 * Save the current clip region.
770 * To retrieve the clip region, we need to create one "dummy"
771 * clip region.
773 clipRegion = CreateRectRgnIndirect(&rectEdit);
775 if (GetClipRgn(hdc, clipRegion)!=1)
777 DeleteObject(clipRegion);
778 clipRegion=NULL;
781 if (!IsWindowEnabled(lphc->self) & WS_DISABLED) itemState |= ODS_DISABLED;
783 dis.CtlType = ODT_COMBOBOX;
784 dis.CtlID = ctlid;
785 dis.hwndItem = lphc->self;
786 dis.itemAction = ODA_DRAWENTIRE;
787 dis.itemID = id;
788 dis.itemState = itemState;
789 dis.hDC = hdc;
790 dis.rcItem = rectEdit;
791 dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA,
792 (WPARAM)id, 0 );
795 * Clip the DC and have the parent draw the item.
797 IntersectClipRect(hdc,
798 rectEdit.left, rectEdit.top,
799 rectEdit.right, rectEdit.bottom);
801 SendMessageW(lphc->owner, WM_DRAWITEM, ctlid, (LPARAM)&dis );
804 * Reset the clipping region.
806 SelectClipRgn(hdc, clipRegion);
808 else
810 static const WCHAR empty_stringW[] = { 0 };
812 if ( (lphc->wState & CBF_FOCUSED) &&
813 !(lphc->wState & CBF_DROPPED) ) {
815 /* highlight */
816 FillRect( hdc, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) );
817 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
818 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
821 ExtTextOutW( hdc,
822 rectEdit.left + 1,
823 rectEdit.top + 1,
824 ETO_OPAQUE | ETO_CLIPPED,
825 &rectEdit,
826 pText ? pText : empty_stringW , size, NULL );
828 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED))
829 DrawFocusRect( hdc, &rectEdit );
832 if( hPrevFont )
833 SelectObject(hdc, hPrevFont );
835 HeapFree( GetProcessHeap(), 0, pText );
838 /***********************************************************************
839 * CBPaintBorder
841 static void CBPaintBorder(
842 HWND hwnd,
843 LPHEADCOMBO lphc,
844 HDC hdc)
846 RECT clientRect;
848 if (CB_GETTYPE(lphc) != CBS_SIMPLE)
850 GetClientRect(hwnd, &clientRect);
852 else
854 CopyRect(&clientRect, &lphc->textRect);
856 InflateRect(&clientRect, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
857 InflateRect(&clientRect, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
860 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_RECT);
863 /***********************************************************************
864 * COMBO_PrepareColors
866 * This method will sent the appropriate WM_CTLCOLOR message to
867 * prepare and setup the colors for the combo's DC.
869 * It also returns the brush to use for the background.
871 static HBRUSH COMBO_PrepareColors(
872 LPHEADCOMBO lphc,
873 HDC hDC)
875 HBRUSH hBkgBrush;
878 * Get the background brush for this control.
880 if (CB_DISABLED(lphc))
882 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORSTATIC,
883 (WPARAM)hDC, (LPARAM)lphc->self );
886 * We have to change the text color since WM_CTLCOLORSTATIC will
887 * set it to the "enabled" color. This is the same behavior as the
888 * edit control
890 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
892 else
894 if (lphc->wState & CBF_EDIT)
896 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLOREDIT,
897 (WPARAM)hDC, (LPARAM)lphc->self );
899 else
901 hBkgBrush = (HBRUSH)SendMessageW(lphc->owner, WM_CTLCOLORLISTBOX,
902 (WPARAM)hDC, (LPARAM)lphc->self );
907 * Catch errors.
909 if( !hBkgBrush )
910 hBkgBrush = GetSysColorBrush(COLOR_WINDOW);
912 return hBkgBrush;
915 /***********************************************************************
916 * COMBO_EraseBackground
918 static LRESULT COMBO_EraseBackground(
919 HWND hwnd,
920 LPHEADCOMBO lphc,
921 HDC hParamDC)
923 HBRUSH hBkgBrush;
924 HDC hDC;
926 if(lphc->wState & CBF_EDIT)
927 return TRUE;
929 hDC = (hParamDC) ? hParamDC
930 : GetDC(hwnd);
932 * Retrieve the background brush
934 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
936 FillRect(hDC, &lphc->textRect, hBkgBrush);
938 if (!hParamDC)
939 ReleaseDC(hwnd, hDC);
941 return TRUE;
944 /***********************************************************************
945 * COMBO_Paint
947 static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC)
949 PAINTSTRUCT ps;
950 HDC hDC;
952 hDC = (hParamDC) ? hParamDC
953 : BeginPaint( lphc->self, &ps);
955 TRACE("hdc=%p\n", hDC);
957 if( hDC && !(lphc->wState & CBF_NOREDRAW) )
959 HBRUSH hPrevBrush, hBkgBrush;
962 * Retrieve the background brush and select it in the
963 * DC.
965 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
967 hPrevBrush = SelectObject( hDC, hBkgBrush );
970 * In non 3.1 look, there is a sunken border on the combobox
972 CBPaintBorder(lphc->self, lphc, hDC);
974 if( !IsRectEmpty(&lphc->buttonRect) )
976 CBPaintButton(lphc, hDC, lphc->buttonRect);
979 /* paint the edit control padding area */
980 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
982 RECT rPadEdit = lphc->textRect;
984 InflateRect(&rPadEdit, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
986 FrameRect( hDC, &rPadEdit, GetSysColorBrush(COLOR_WINDOW) );
989 if( !(lphc->wState & CBF_EDIT) )
990 CBPaintText( lphc, hDC, lphc->textRect);
992 if( hPrevBrush )
993 SelectObject( hDC, hPrevBrush );
996 if( !hParamDC )
997 EndPaint(lphc->self, &ps);
999 return 0;
1002 /***********************************************************************
1003 * CBUpdateLBox
1005 * Select listbox entry according to the contents of the edit control.
1007 static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
1009 INT length, idx;
1010 LPWSTR pText = NULL;
1012 idx = LB_ERR;
1013 length = SendMessageW( lphc->hWndEdit, WM_GETTEXTLENGTH, 0, 0 );
1015 if( length > 0 )
1016 pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1018 TRACE("\t edit text length %i\n", length );
1020 if( pText )
1022 if( length ) GetWindowTextW( lphc->hWndEdit, pText, length + 1);
1023 else pText[0] = '\0';
1024 idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING,
1025 (WPARAM)(-1), (LPARAM)pText );
1026 HeapFree( GetProcessHeap(), 0, pText );
1029 SendMessageW(lphc->hWndLBox, LB_SETCURSEL, (WPARAM)(bSelect ? idx : -1), 0);
1031 /* probably superfluous but Windows sends this too */
1032 SendMessageW(lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1033 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1035 return idx;
1038 /***********************************************************************
1039 * CBUpdateEdit
1041 * Copy a listbox entry to the edit control.
1043 static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
1045 INT length;
1046 LPWSTR pText = NULL;
1047 static const WCHAR empty_stringW[] = { 0 };
1049 TRACE("\t %i\n", index );
1051 if( index >= 0 ) /* got an entry */
1053 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0);
1054 if( length != LB_ERR)
1056 if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) )
1058 SendMessageW(lphc->hWndLBox, LB_GETTEXT,
1059 (WPARAM)index, (LPARAM)pText );
1064 lphc->wState |= (CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1065 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, pText ? (LPARAM)pText : (LPARAM)empty_stringW);
1066 lphc->wState &= ~(CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1068 if( lphc->wState & CBF_FOCUSED )
1069 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1071 HeapFree( GetProcessHeap(), 0, pText );
1074 /***********************************************************************
1075 * CBDropDown
1077 * Show listbox popup.
1079 static void CBDropDown( LPHEADCOMBO lphc )
1081 RECT rect,r;
1082 int nItems = 0;
1083 int nDroppedHeight;
1085 TRACE("[%p]: drop down\n", lphc->self);
1087 CB_NOTIFY( lphc, CBN_DROPDOWN );
1089 /* set selection */
1091 lphc->wState |= CBF_DROPPED;
1092 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1094 lphc->droppedIndex = CBUpdateLBox( lphc, TRUE );
1096 /* Update edit only if item is in the list */
1097 if( !(lphc->wState & CBF_CAPTURE) && lphc->droppedIndex >= 0)
1098 CBUpdateEdit( lphc, lphc->droppedIndex );
1100 else
1102 lphc->droppedIndex = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1104 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX,
1105 (WPARAM)(lphc->droppedIndex == LB_ERR ? 0 : lphc->droppedIndex), 0 );
1106 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1109 /* now set popup position */
1110 GetWindowRect( lphc->self, &rect );
1113 * If it's a dropdown, the listbox is offset
1115 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1116 rect.left += COMBO_EDITBUTTONSPACE();
1118 /* if the dropped height is greater than the total height of the dropped
1119 items list, then force the drop down list height to be the total height
1120 of the items in the dropped list */
1122 /* And Remove any extra space (Best Fit) */
1123 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
1124 /* if listbox length has been set directly by its handle */
1125 GetWindowRect(lphc->hWndLBox, &r);
1126 if (nDroppedHeight < r.bottom - r.top)
1127 nDroppedHeight = r.bottom - r.top;
1128 nItems = (int)SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
1130 if (nItems > 0)
1132 int nHeight;
1133 int nIHeight;
1135 nIHeight = (int)SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, 0, 0);
1137 nHeight = nIHeight*nItems;
1139 if (nHeight < nDroppedHeight - COMBO_YBORDERSIZE())
1140 nDroppedHeight = nHeight + COMBO_YBORDERSIZE();
1142 if (nDroppedHeight < nIHeight)
1144 if (nItems < 5)
1145 nDroppedHeight = (nItems+1)*nIHeight;
1146 else
1147 nDroppedHeight = 6*nIHeight;
1151 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1152 if( (rect.bottom + nDroppedHeight) >= GetSystemMetrics( SM_CYSCREEN ) )
1153 rect.bottom = rect.top - nDroppedHeight;
1155 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
1156 lphc->droppedRect.right - lphc->droppedRect.left,
1157 nDroppedHeight,
1158 SWP_NOACTIVATE | SWP_SHOWWINDOW);
1161 if( !(lphc->wState & CBF_NOREDRAW) )
1162 RedrawWindow( lphc->self, NULL, 0, RDW_INVALIDATE |
1163 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1165 EnableWindow( lphc->hWndLBox, TRUE );
1166 if (GetCapture() != lphc->self)
1167 SetCapture(lphc->hWndLBox);
1170 /***********************************************************************
1171 * CBRollUp
1173 * Hide listbox popup.
1175 static void CBRollUp( LPHEADCOMBO lphc, BOOL ok, BOOL bButton )
1177 HWND hWnd = lphc->self;
1179 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1180 lphc->self, (INT)ok, (INT)(lphc->wState & CBF_DROPPED));
1182 CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL );
1184 if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE )
1187 if( lphc->wState & CBF_DROPPED )
1189 RECT rect;
1191 lphc->wState &= ~CBF_DROPPED;
1192 ShowWindow( lphc->hWndLBox, SW_HIDE );
1194 if(GetCapture() == lphc->hWndLBox)
1196 ReleaseCapture();
1199 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1201 rect = lphc->buttonRect;
1203 else
1205 if( bButton )
1207 UnionRect( &rect,
1208 &lphc->buttonRect,
1209 &lphc->textRect);
1211 else
1212 rect = lphc->textRect;
1214 bButton = TRUE;
1217 if( bButton && !(lphc->wState & CBF_NOREDRAW) )
1218 RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE |
1219 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1220 CB_NOTIFY( lphc, CBN_CLOSEUP );
1225 /***********************************************************************
1226 * COMBO_FlipListbox
1228 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1230 BOOL COMBO_FlipListbox( LPHEADCOMBO lphc, BOOL ok, BOOL bRedrawButton )
1232 if( lphc->wState & CBF_DROPPED )
1234 CBRollUp( lphc, ok, bRedrawButton );
1235 return FALSE;
1238 CBDropDown( lphc );
1239 return TRUE;
1242 /***********************************************************************
1243 * CBRepaintButton
1245 static void CBRepaintButton( LPHEADCOMBO lphc )
1247 InvalidateRect(lphc->self, &lphc->buttonRect, TRUE);
1248 UpdateWindow(lphc->self);
1251 /***********************************************************************
1252 * COMBO_SetFocus
1254 static void COMBO_SetFocus( LPHEADCOMBO lphc )
1256 if( !(lphc->wState & CBF_FOCUSED) )
1258 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1259 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1261 /* This is wrong. Message sequences seem to indicate that this
1262 is set *after* the notify. */
1263 /* lphc->wState |= CBF_FOCUSED; */
1265 if( !(lphc->wState & CBF_EDIT) )
1266 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1268 CB_NOTIFY( lphc, CBN_SETFOCUS );
1269 lphc->wState |= CBF_FOCUSED;
1273 /***********************************************************************
1274 * COMBO_KillFocus
1276 static void COMBO_KillFocus( LPHEADCOMBO lphc )
1278 HWND hWnd = lphc->self;
1280 if( lphc->wState & CBF_FOCUSED )
1282 CBRollUp( lphc, FALSE, TRUE );
1283 if( IsWindow( hWnd ) )
1285 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1286 SendMessageW(lphc->hWndLBox, LB_CARETOFF, 0, 0);
1288 lphc->wState &= ~CBF_FOCUSED;
1290 /* redraw text */
1291 if( !(lphc->wState & CBF_EDIT) )
1292 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1294 CB_NOTIFY( lphc, CBN_KILLFOCUS );
1299 /***********************************************************************
1300 * COMBO_Command
1302 static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd )
1304 if ( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd )
1306 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1308 switch( HIWORD(wParam) >> 8 )
1310 case (EN_SETFOCUS >> 8):
1312 TRACE("[%p]: edit [%p] got focus\n", lphc->self, lphc->hWndEdit );
1314 COMBO_SetFocus( lphc );
1315 break;
1317 case (EN_KILLFOCUS >> 8):
1319 TRACE("[%p]: edit [%p] lost focus\n", lphc->self, lphc->hWndEdit );
1321 /* NOTE: it seems that Windows' edit control sends an
1322 * undocumented message WM_USER + 0x1B instead of this
1323 * notification (only when it happens to be a part of
1324 * the combo). ?? - AK.
1327 COMBO_KillFocus( lphc );
1328 break;
1331 case (EN_CHANGE >> 8):
1333 * In some circumstances (when the selection of the combobox
1334 * is changed for example) we don't want the EN_CHANGE notification
1335 * to be forwarded to the parent of the combobox. This code
1336 * checks a flag that is set in these occasions and ignores the
1337 * notification.
1339 if (lphc->wState & CBF_NOLBSELECT)
1341 lphc->wState &= ~CBF_NOLBSELECT;
1343 else
1345 CBUpdateLBox( lphc, lphc->wState & CBF_DROPPED );
1348 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1349 CB_NOTIFY( lphc, CBN_EDITCHANGE );
1350 break;
1352 case (EN_UPDATE >> 8):
1353 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1354 CB_NOTIFY( lphc, CBN_EDITUPDATE );
1355 break;
1357 case (EN_ERRSPACE >> 8):
1358 CB_NOTIFY( lphc, CBN_ERRSPACE );
1361 else if( lphc->hWndLBox == hWnd )
1363 switch( (short)HIWORD(wParam) )
1365 case LBN_ERRSPACE:
1366 CB_NOTIFY( lphc, CBN_ERRSPACE );
1367 break;
1369 case LBN_DBLCLK:
1370 CB_NOTIFY( lphc, CBN_DBLCLK );
1371 break;
1373 case LBN_SELCHANGE:
1374 case LBN_SELCANCEL:
1376 TRACE("[%p]: lbox selection change [%x]\n", lphc->self, lphc->wState );
1378 if( HIWORD(wParam) == LBN_SELCHANGE)
1380 if( lphc->wState & CBF_EDIT )
1382 INT index = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1383 lphc->wState |= CBF_NOLBSELECT;
1384 CBUpdateEdit( lphc, index );
1385 /* select text in edit, as Windows does */
1386 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1388 else
1389 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1392 /* do not roll up if selection is being tracked
1393 * by arrowkeys in the dropdown listbox */
1394 if( ((lphc->wState & CBF_DROPPED) && !(lphc->wState & CBF_NOROLLUP)) )
1396 CBRollUp( lphc, (HIWORD(wParam) == LBN_SELCHANGE), TRUE );
1398 else lphc->wState &= ~CBF_NOROLLUP;
1400 CB_NOTIFY( lphc, CBN_SELCHANGE );
1402 /* fall through */
1404 case LBN_SETFOCUS:
1405 case LBN_KILLFOCUS:
1406 /* nothing to do here since ComboLBox always resets the focus to its
1407 * combo/edit counterpart */
1408 break;
1411 return 0;
1414 /***********************************************************************
1415 * COMBO_ItemOp
1417 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1419 static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
1421 HWND hWnd = lphc->self;
1422 UINT id = (UINT)GetWindowLongPtrW( hWnd, GWLP_ID );
1424 TRACE("[%p]: ownerdraw op %04x\n", lphc->self, msg );
1426 switch( msg )
1428 case WM_DELETEITEM:
1430 DELETEITEMSTRUCT *lpIS = (DELETEITEMSTRUCT *)lParam;
1431 lpIS->CtlType = ODT_COMBOBOX;
1432 lpIS->CtlID = id;
1433 lpIS->hwndItem = hWnd;
1434 break;
1436 case WM_DRAWITEM:
1438 DRAWITEMSTRUCT *lpIS = (DRAWITEMSTRUCT *)lParam;
1439 lpIS->CtlType = ODT_COMBOBOX;
1440 lpIS->CtlID = id;
1441 lpIS->hwndItem = hWnd;
1442 break;
1444 case WM_COMPAREITEM:
1446 COMPAREITEMSTRUCT *lpIS = (COMPAREITEMSTRUCT *)lParam;
1447 lpIS->CtlType = ODT_COMBOBOX;
1448 lpIS->CtlID = id;
1449 lpIS->hwndItem = hWnd;
1450 break;
1452 case WM_MEASUREITEM:
1454 MEASUREITEMSTRUCT *lpIS = (MEASUREITEMSTRUCT *)lParam;
1455 lpIS->CtlType = ODT_COMBOBOX;
1456 lpIS->CtlID = id;
1457 break;
1460 return SendMessageW(lphc->owner, msg, id, lParam);
1464 /***********************************************************************
1465 * COMBO_GetTextW
1467 static LRESULT COMBO_GetTextW( LPHEADCOMBO lphc, INT count, LPWSTR buf )
1469 INT length;
1471 if( lphc->wState & CBF_EDIT )
1472 return SendMessageW( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1474 /* get it from the listbox */
1476 if (!count || !buf) return 0;
1477 if( lphc->hWndLBox )
1479 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1480 if (idx == LB_ERR) goto error;
1481 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1482 if (length == LB_ERR) goto error;
1484 /* 'length' is without the terminating character */
1485 if (length >= count)
1487 LPWSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1488 if (!lpBuffer) goto error;
1489 length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1491 /* truncate if buffer is too short */
1492 if (length != LB_ERR)
1494 lstrcpynW( buf, lpBuffer, count );
1495 length = count;
1497 HeapFree( GetProcessHeap(), 0, lpBuffer );
1499 else length = SendMessageW(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1501 if (length == LB_ERR) return 0;
1502 return length;
1505 error: /* error - truncate string, return zero */
1506 buf[0] = 0;
1507 return 0;
1511 /***********************************************************************
1512 * COMBO_GetTextA
1514 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1515 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1517 static LRESULT COMBO_GetTextA( LPHEADCOMBO lphc, INT count, LPSTR buf )
1519 INT length;
1521 if( lphc->wState & CBF_EDIT )
1522 return SendMessageA( lphc->hWndEdit, WM_GETTEXT, count, (LPARAM)buf );
1524 /* get it from the listbox */
1526 if (!count || !buf) return 0;
1527 if( lphc->hWndLBox )
1529 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1530 if (idx == LB_ERR) goto error;
1531 length = SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, idx, 0 );
1532 if (length == LB_ERR) goto error;
1534 /* 'length' is without the terminating character */
1535 if (length >= count)
1537 LPSTR lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) );
1538 if (!lpBuffer) goto error;
1539 length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)lpBuffer);
1541 /* truncate if buffer is too short */
1542 if (length != LB_ERR)
1544 lstrcpynA( buf, lpBuffer, count );
1545 length = count;
1547 HeapFree( GetProcessHeap(), 0, lpBuffer );
1549 else length = SendMessageA(lphc->hWndLBox, LB_GETTEXT, idx, (LPARAM)buf);
1551 if (length == LB_ERR) return 0;
1552 return length;
1555 error: /* error - truncate string, return zero */
1556 buf[0] = 0;
1557 return 0;
1561 /***********************************************************************
1562 * CBResetPos
1564 * This function sets window positions according to the updated
1565 * component placement struct.
1567 static void CBResetPos(
1568 LPHEADCOMBO lphc,
1569 LPRECT rectEdit,
1570 LPRECT rectLB,
1571 BOOL bRedraw)
1573 BOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE);
1575 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1576 * sizing messages */
1578 if( lphc->wState & CBF_EDIT )
1579 SetWindowPos( lphc->hWndEdit, 0,
1580 rectEdit->left, rectEdit->top,
1581 rectEdit->right - rectEdit->left,
1582 rectEdit->bottom - rectEdit->top,
1583 SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) );
1585 SetWindowPos( lphc->hWndLBox, 0,
1586 rectLB->left, rectLB->top,
1587 rectLB->right - rectLB->left,
1588 rectLB->bottom - rectLB->top,
1589 SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) );
1591 if( bDrop )
1593 if( lphc->wState & CBF_DROPPED )
1595 lphc->wState &= ~CBF_DROPPED;
1596 ShowWindow( lphc->hWndLBox, SW_HIDE );
1599 if( bRedraw && !(lphc->wState & CBF_NOREDRAW) )
1600 RedrawWindow( lphc->self, NULL, 0,
1601 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
1606 /***********************************************************************
1607 * COMBO_Size
1609 static void COMBO_Size( LPHEADCOMBO lphc )
1611 CBCalcPlacement(lphc->self,
1612 lphc,
1613 &lphc->textRect,
1614 &lphc->buttonRect,
1615 &lphc->droppedRect);
1617 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1621 /***********************************************************************
1622 * COMBO_Font
1624 static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
1627 * Set the font
1629 lphc->hFont = hFont;
1632 * Propagate to owned windows.
1634 if( lphc->wState & CBF_EDIT )
1635 SendMessageW(lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw);
1636 SendMessageW(lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw);
1639 * Redo the layout of the control.
1641 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1643 CBCalcPlacement(lphc->self,
1644 lphc,
1645 &lphc->textRect,
1646 &lphc->buttonRect,
1647 &lphc->droppedRect);
1649 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1651 else
1653 CBForceDummyResize(lphc);
1658 /***********************************************************************
1659 * COMBO_SetItemHeight
1661 static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
1663 LRESULT lRet = CB_ERR;
1665 if( index == -1 ) /* set text field height */
1667 if( height < 32768 )
1669 lphc->editHeight = height;
1672 * Redo the layout of the control.
1674 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1676 CBCalcPlacement(lphc->self,
1677 lphc,
1678 &lphc->textRect,
1679 &lphc->buttonRect,
1680 &lphc->droppedRect);
1682 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1684 else
1686 CBForceDummyResize(lphc);
1689 lRet = height;
1692 else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */
1693 lRet = SendMessageW(lphc->hWndLBox, LB_SETITEMHEIGHT,
1694 (WPARAM)index, (LPARAM)height );
1695 return lRet;
1698 /***********************************************************************
1699 * COMBO_SelectString
1701 static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPARAM pText, BOOL unicode )
1703 INT index = unicode ? SendMessageW(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText) :
1704 SendMessageA(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText);
1705 if( index >= 0 )
1707 if( lphc->wState & CBF_EDIT )
1708 CBUpdateEdit( lphc, index );
1709 else
1711 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
1714 return (LRESULT)index;
1717 /***********************************************************************
1718 * COMBO_LButtonDown
1720 static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam )
1722 POINT pt;
1723 BOOL bButton;
1724 HWND hWnd = lphc->self;
1726 pt.x = LOWORD(lParam);
1727 pt.y = HIWORD(lParam);
1728 bButton = PtInRect(&lphc->buttonRect, pt);
1730 if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) ||
1731 (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) )
1733 lphc->wState |= CBF_BUTTONDOWN;
1734 if( lphc->wState & CBF_DROPPED )
1736 /* got a click to cancel selection */
1738 lphc->wState &= ~CBF_BUTTONDOWN;
1739 CBRollUp( lphc, TRUE, FALSE );
1740 if( !IsWindow( hWnd ) ) return;
1742 if( lphc->wState & CBF_CAPTURE )
1744 lphc->wState &= ~CBF_CAPTURE;
1745 ReleaseCapture();
1748 else
1750 /* drop down the listbox and start tracking */
1752 lphc->wState |= CBF_CAPTURE;
1753 SetCapture( hWnd );
1754 CBDropDown( lphc );
1756 if( bButton ) CBRepaintButton( lphc );
1760 /***********************************************************************
1761 * COMBO_LButtonUp
1763 * Release capture and stop tracking if needed.
1765 static void COMBO_LButtonUp( LPHEADCOMBO lphc )
1767 if( lphc->wState & CBF_CAPTURE )
1769 lphc->wState &= ~CBF_CAPTURE;
1770 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1772 INT index = CBUpdateLBox( lphc, TRUE );
1773 /* Update edit only if item is in the list */
1774 if(index >= 0)
1776 lphc->wState |= CBF_NOLBSELECT;
1777 CBUpdateEdit( lphc, index );
1778 lphc->wState &= ~CBF_NOLBSELECT;
1781 ReleaseCapture();
1782 SetCapture(lphc->hWndLBox);
1785 if( lphc->wState & CBF_BUTTONDOWN )
1787 lphc->wState &= ~CBF_BUTTONDOWN;
1788 CBRepaintButton( lphc );
1792 /***********************************************************************
1793 * COMBO_MouseMove
1795 * Two things to do - track combo button and release capture when
1796 * pointer goes into the listbox.
1798 static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam )
1800 POINT pt;
1801 RECT lbRect;
1803 pt.x = LOWORD(lParam);
1804 pt.y = HIWORD(lParam);
1806 if( lphc->wState & CBF_BUTTONDOWN )
1808 BOOL bButton;
1810 bButton = PtInRect(&lphc->buttonRect, pt);
1812 if( !bButton )
1814 lphc->wState &= ~CBF_BUTTONDOWN;
1815 CBRepaintButton( lphc );
1819 GetClientRect( lphc->hWndLBox, &lbRect );
1820 MapWindowPoints( lphc->self, lphc->hWndLBox, &pt, 1 );
1821 if( PtInRect(&lbRect, pt) )
1823 lphc->wState &= ~CBF_CAPTURE;
1824 ReleaseCapture();
1825 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc, TRUE );
1827 /* hand over pointer tracking */
1828 SendMessageW(lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam);
1832 static LRESULT COMBO_GetComboBoxInfo(LPHEADCOMBO lphc, COMBOBOXINFO *pcbi)
1834 if (!pcbi || (pcbi->cbSize < sizeof(COMBOBOXINFO)))
1835 return FALSE;
1837 pcbi->rcItem = lphc->textRect;
1838 pcbi->rcButton = lphc->buttonRect;
1839 pcbi->stateButton = 0;
1840 if (lphc->wState & CBF_BUTTONDOWN)
1841 pcbi->stateButton |= STATE_SYSTEM_PRESSED;
1842 if (IsRectEmpty(&lphc->buttonRect))
1843 pcbi->stateButton |= STATE_SYSTEM_INVISIBLE;
1844 pcbi->hwndCombo = lphc->self;
1845 pcbi->hwndItem = lphc->hWndEdit;
1846 pcbi->hwndList = lphc->hWndLBox;
1847 return TRUE;
1850 static char *strdupA(LPCSTR str)
1852 char *ret;
1853 DWORD len;
1855 if(!str) return NULL;
1857 len = strlen(str);
1858 ret = HeapAlloc(GetProcessHeap(), 0, len + 1);
1859 memcpy(ret, str, len + 1);
1860 return ret;
1863 /***********************************************************************
1864 * ComboWndProc_common
1866 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxes.asp
1868 static LRESULT ComboWndProc_common( HWND hwnd, UINT message,
1869 WPARAM wParam, LPARAM lParam, BOOL unicode )
1871 LPHEADCOMBO lphc = (LPHEADCOMBO)GetWindowLongPtrW( hwnd, 0 );
1873 TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1874 hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1876 if( lphc || message == WM_NCCREATE )
1877 switch(message)
1880 /* System messages */
1882 case WM_NCCREATE:
1884 LONG style = unicode ? ((LPCREATESTRUCTW)lParam)->style :
1885 ((LPCREATESTRUCTA)lParam)->style;
1886 return COMBO_NCCreate(hwnd, style);
1888 case WM_NCDESTROY:
1889 COMBO_NCDestroy(lphc);
1890 break;/* -> DefWindowProc */
1892 case WM_CREATE:
1894 HWND hwndParent;
1895 LONG style;
1896 if(unicode)
1898 hwndParent = ((LPCREATESTRUCTW)lParam)->hwndParent;
1899 style = ((LPCREATESTRUCTW)lParam)->style;
1901 else
1903 hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent;
1904 style = ((LPCREATESTRUCTA)lParam)->style;
1906 return COMBO_Create(hwnd, lphc, hwndParent, style, unicode);
1909 case WM_PRINTCLIENT:
1910 if (lParam & PRF_ERASEBKGND)
1911 COMBO_EraseBackground(hwnd, lphc, (HDC)wParam);
1913 /* Fallthrough */
1914 case WM_PAINT:
1915 /* wParam may contain a valid HDC! */
1916 return COMBO_Paint(lphc, (HDC)wParam);
1917 case WM_ERASEBKGND:
1918 return COMBO_EraseBackground(hwnd, lphc, (HDC)wParam);
1919 case WM_GETDLGCODE:
1921 LRESULT result = DLGC_WANTARROWS | DLGC_WANTCHARS;
1922 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1924 int vk = (int)((LPMSG)lParam)->wParam;
1926 if ((vk == VK_RETURN || vk == VK_ESCAPE) && (lphc->wState & CBF_DROPPED))
1927 result |= DLGC_WANTMESSAGE;
1929 return result;
1931 case WM_WINDOWPOSCHANGING:
1932 return COMBO_WindowPosChanging(hwnd, lphc, (LPWINDOWPOS)lParam);
1933 case WM_WINDOWPOSCHANGED:
1934 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1935 * In that case, the Combobox itself will not be resized, so we won't
1936 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1937 * do it here.
1939 /* fall through */
1940 case WM_SIZE:
1941 if( lphc->hWndLBox &&
1942 !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc );
1943 return TRUE;
1944 case WM_SETFONT:
1945 COMBO_Font( lphc, (HFONT)wParam, (BOOL)lParam );
1946 return TRUE;
1947 case WM_GETFONT:
1948 return (LRESULT)lphc->hFont;
1949 case WM_SETFOCUS:
1950 if( lphc->wState & CBF_EDIT )
1951 SetFocus( lphc->hWndEdit );
1952 else
1953 COMBO_SetFocus( lphc );
1954 return TRUE;
1955 case WM_KILLFOCUS:
1957 HWND hwndFocus = WIN_GetFullHandle( (HWND)wParam );
1958 if( !hwndFocus ||
1959 (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox ))
1960 COMBO_KillFocus( lphc );
1961 return TRUE;
1963 case WM_COMMAND:
1964 return COMBO_Command( lphc, wParam, WIN_GetFullHandle( (HWND)lParam ) );
1965 case WM_GETTEXT:
1966 return unicode ? COMBO_GetTextW( lphc, wParam, (LPWSTR)lParam )
1967 : COMBO_GetTextA( lphc, wParam, (LPSTR)lParam );
1968 case WM_SETTEXT:
1969 case WM_GETTEXTLENGTH:
1970 case WM_CLEAR:
1971 if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT))
1973 int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1974 if (j == -1) return 0;
1975 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0) :
1976 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, j, 0);
1978 else if( lphc->wState & CBF_EDIT )
1980 LRESULT ret;
1981 lphc->wState |= CBF_NOEDITNOTIFY;
1982 ret = unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1983 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1984 lphc->wState &= ~CBF_NOEDITNOTIFY;
1985 return ret;
1987 else return CB_ERR;
1988 case WM_CUT:
1989 case WM_PASTE:
1990 case WM_COPY:
1991 if( lphc->wState & CBF_EDIT )
1993 return unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1994 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1996 else return CB_ERR;
1998 case WM_DRAWITEM:
1999 case WM_DELETEITEM:
2000 case WM_COMPAREITEM:
2001 case WM_MEASUREITEM:
2002 return COMBO_ItemOp(lphc, message, lParam);
2003 case WM_ENABLE:
2004 if( lphc->wState & CBF_EDIT )
2005 EnableWindow( lphc->hWndEdit, (BOOL)wParam );
2006 EnableWindow( lphc->hWndLBox, (BOOL)wParam );
2008 /* Force the control to repaint when the enabled state changes. */
2009 InvalidateRect(lphc->self, NULL, TRUE);
2010 return TRUE;
2011 case WM_SETREDRAW:
2012 if( wParam )
2013 lphc->wState &= ~CBF_NOREDRAW;
2014 else
2015 lphc->wState |= CBF_NOREDRAW;
2017 if( lphc->wState & CBF_EDIT )
2018 SendMessageW(lphc->hWndEdit, message, wParam, lParam);
2019 SendMessageW(lphc->hWndLBox, message, wParam, lParam);
2020 return 0;
2021 case WM_SYSKEYDOWN:
2022 if( KEYDATA_ALT & HIWORD(lParam) )
2023 if( wParam == VK_UP || wParam == VK_DOWN )
2024 COMBO_FlipListbox( lphc, FALSE, FALSE );
2025 return 0;
2027 case WM_CHAR:
2028 case WM_IME_CHAR:
2029 case WM_KEYDOWN:
2031 HWND hwndTarget;
2033 if ((wParam == VK_RETURN || wParam == VK_ESCAPE) &&
2034 (lphc->wState & CBF_DROPPED))
2036 CBRollUp( lphc, wParam == VK_RETURN, FALSE );
2037 return TRUE;
2039 else if ((wParam == VK_F4) && !(lphc->wState & CBF_EUI))
2041 COMBO_FlipListbox( lphc, FALSE, FALSE );
2042 return TRUE;
2045 if( lphc->wState & CBF_EDIT )
2046 hwndTarget = lphc->hWndEdit;
2047 else
2048 hwndTarget = lphc->hWndLBox;
2050 return unicode ? SendMessageW(hwndTarget, message, wParam, lParam) :
2051 SendMessageA(hwndTarget, message, wParam, lParam);
2053 case WM_LBUTTONDOWN:
2054 if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self );
2055 if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
2056 return TRUE;
2057 case WM_LBUTTONUP:
2058 COMBO_LButtonUp( lphc );
2059 return TRUE;
2060 case WM_MOUSEMOVE:
2061 if( lphc->wState & CBF_CAPTURE )
2062 COMBO_MouseMove( lphc, wParam, lParam );
2063 return TRUE;
2065 case WM_MOUSEWHEEL:
2066 if (wParam & (MK_SHIFT | MK_CONTROL))
2067 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2068 DefWindowProcA(hwnd, message, wParam, lParam);
2070 if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_UP, 0);
2071 if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_DOWN, 0);
2072 return TRUE;
2074 /* Combo messages */
2076 case CB_ADDSTRING16:
2077 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2078 /* fall through */
2079 case CB_ADDSTRING:
2080 if( unicode )
2082 if( lphc->dwStyle & CBS_LOWERCASE )
2083 strlwrW((LPWSTR)lParam);
2084 else if( lphc->dwStyle & CBS_UPPERCASE )
2085 struprW((LPWSTR)lParam);
2086 return SendMessageW(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2088 else /* unlike the unicode version, the ansi version does not overwrite
2089 the string if converting case */
2091 char *p, *string = NULL;
2092 LRESULT ret;
2093 if( lphc->dwStyle & CBS_LOWERCASE )
2095 string = strdupA((LPSTR)lParam);
2096 for (p = string; *p; p++) *p = tolower(*p);
2098 else if( lphc->dwStyle & CBS_UPPERCASE )
2100 string = strdupA((LPSTR)lParam);
2101 for (p = string; *p; p++) *p = toupper(*p);
2103 ret = SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, string ? (LPARAM)string : lParam);
2104 HeapFree(GetProcessHeap(), 0, string);
2105 return ret;
2107 case CB_INSERTSTRING16:
2108 wParam = (INT)(INT16)wParam;
2109 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2110 /* fall through */
2111 case CB_INSERTSTRING:
2112 if( unicode )
2114 if( lphc->dwStyle & CBS_LOWERCASE )
2115 strlwrW((LPWSTR)lParam);
2116 else if( lphc->dwStyle & CBS_UPPERCASE )
2117 struprW((LPWSTR)lParam);
2118 return SendMessageW(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2120 else
2122 char *p;
2123 if( lphc->dwStyle & CBS_LOWERCASE )
2124 for (p = (LPSTR)lParam; *p; p++) *p = tolower(*p);
2125 else if( lphc->dwStyle & CBS_UPPERCASE )
2126 for (p = (LPSTR)lParam; *p; p++) *p = toupper(*p);
2127 return SendMessageA(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2129 case CB_DELETESTRING16:
2130 case CB_DELETESTRING:
2131 return unicode ? SendMessageW(lphc->hWndLBox, LB_DELETESTRING, wParam, 0) :
2132 SendMessageA(lphc->hWndLBox, LB_DELETESTRING, wParam, 0);
2133 case CB_SELECTSTRING16:
2134 wParam = (INT)(INT16)wParam;
2135 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2136 /* fall through */
2137 case CB_SELECTSTRING:
2138 return COMBO_SelectString(lphc, (INT)wParam, lParam, unicode);
2139 case CB_FINDSTRING16:
2140 wParam = (INT)(INT16)wParam;
2141 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2142 /* fall through */
2143 case CB_FINDSTRING:
2144 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam) :
2145 SendMessageA(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam);
2146 case CB_FINDSTRINGEXACT16:
2147 wParam = (INT)(INT16)wParam;
2148 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2149 /* fall through */
2150 case CB_FINDSTRINGEXACT:
2151 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam) :
2152 SendMessageA(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam);
2153 case CB_SETITEMHEIGHT16:
2154 wParam = (INT)(INT16)wParam; /* signed integer */
2155 /* fall through */
2156 case CB_SETITEMHEIGHT:
2157 return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam);
2158 case CB_GETITEMHEIGHT16:
2159 wParam = (INT)(INT16)wParam;
2160 /* fall through */
2161 case CB_GETITEMHEIGHT:
2162 if( (INT)wParam >= 0 ) /* listbox item */
2163 return SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0);
2164 return CBGetTextAreaHeight(hwnd, lphc);
2165 case CB_RESETCONTENT16:
2166 case CB_RESETCONTENT:
2167 SendMessageW(lphc->hWndLBox, LB_RESETCONTENT, 0, 0);
2168 if( (lphc->wState & CBF_EDIT) && CB_HASSTRINGS(lphc) )
2170 static const WCHAR empty_stringW[] = { 0 };
2171 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);
2173 else
2174 InvalidateRect(lphc->self, NULL, TRUE);
2175 return TRUE;
2176 case CB_INITSTORAGE:
2177 return SendMessageW(lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam);
2178 case CB_GETHORIZONTALEXTENT:
2179 return SendMessageW(lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0);
2180 case CB_SETHORIZONTALEXTENT:
2181 return SendMessageW(lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0);
2182 case CB_GETTOPINDEX:
2183 return SendMessageW(lphc->hWndLBox, LB_GETTOPINDEX, 0, 0);
2184 case CB_GETLOCALE:
2185 return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0);
2186 case CB_SETLOCALE:
2187 return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0);
2188 case CB_GETDROPPEDWIDTH:
2189 if( lphc->droppedWidth )
2190 return lphc->droppedWidth;
2191 return lphc->droppedRect.right - lphc->droppedRect.left;
2192 case CB_SETDROPPEDWIDTH:
2193 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) &&
2194 (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam;
2195 return CB_ERR;
2196 case CB_GETDROPPEDCONTROLRECT16:
2197 lParam = (LPARAM)MapSL(lParam);
2198 if( lParam )
2200 RECT r;
2201 RECT16 *r16 = (RECT16 *)lParam;
2202 CBGetDroppedControlRect( lphc, &r );
2203 r16->left = r.left;
2204 r16->top = r.top;
2205 r16->right = r.right;
2206 r16->bottom = r.bottom;
2208 return CB_OKAY;
2209 case CB_GETDROPPEDCONTROLRECT:
2210 if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam );
2211 return CB_OKAY;
2212 case CB_GETDROPPEDSTATE16:
2213 case CB_GETDROPPEDSTATE:
2214 return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE;
2215 case CB_DIR16:
2216 return SendMessageA(lphc->hWndLBox, LB_DIR16, wParam, lParam);
2217 case CB_DIR:
2218 return unicode ? SendMessageW(lphc->hWndLBox, LB_DIR, wParam, lParam) :
2219 SendMessageA(lphc->hWndLBox, LB_DIR, wParam, lParam);
2221 case CB_SHOWDROPDOWN16:
2222 case CB_SHOWDROPDOWN:
2223 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
2225 if( wParam )
2227 if( !(lphc->wState & CBF_DROPPED) )
2228 CBDropDown( lphc );
2230 else
2231 if( lphc->wState & CBF_DROPPED )
2232 CBRollUp( lphc, FALSE, TRUE );
2234 return TRUE;
2235 case CB_GETCOUNT16:
2236 case CB_GETCOUNT:
2237 return SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
2238 case CB_GETCURSEL16:
2239 case CB_GETCURSEL:
2240 return SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
2241 case CB_SETCURSEL16:
2242 wParam = (INT)(INT16)wParam;
2243 /* fall through */
2244 case CB_SETCURSEL:
2245 lParam = SendMessageW(lphc->hWndLBox, LB_SETCURSEL, wParam, 0);
2246 if( lParam >= 0 )
2247 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, wParam, 0);
2249 /* no LBN_SELCHANGE in this case, update manually */
2250 if( lphc->wState & CBF_EDIT )
2251 CBUpdateEdit( lphc, (INT)wParam );
2252 else
2253 InvalidateRect(lphc->self, &lphc->textRect, TRUE);
2254 lphc->wState &= ~CBF_SELCHANGE;
2255 return lParam;
2256 case CB_GETLBTEXT16:
2257 wParam = (INT)(INT16)wParam;
2258 lParam = (LPARAM)MapSL(lParam);
2259 /* fall through */
2260 case CB_GETLBTEXT:
2261 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXT, wParam, lParam) :
2262 SendMessageA(lphc->hWndLBox, LB_GETTEXT, wParam, lParam);
2263 case CB_GETLBTEXTLEN16:
2264 wParam = (INT)(INT16)wParam;
2265 /* fall through */
2266 case CB_GETLBTEXTLEN:
2267 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0) :
2268 SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0);
2269 case CB_GETITEMDATA16:
2270 wParam = (INT)(INT16)wParam;
2271 /* fall through */
2272 case CB_GETITEMDATA:
2273 return SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0);
2274 case CB_SETITEMDATA16:
2275 wParam = (INT)(INT16)wParam;
2276 /* fall through */
2277 case CB_SETITEMDATA:
2278 return SendMessageW(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam);
2279 case CB_GETEDITSEL16:
2280 wParam = lParam = 0; /* just in case */
2281 /* fall through */
2282 case CB_GETEDITSEL:
2283 /* Edit checks passed parameters itself */
2284 if( lphc->wState & CBF_EDIT )
2285 return SendMessageW(lphc->hWndEdit, EM_GETSEL, wParam, lParam);
2286 return CB_ERR;
2287 case CB_SETEDITSEL16:
2288 case CB_SETEDITSEL:
2289 if( lphc->wState & CBF_EDIT )
2290 return SendMessageW(lphc->hWndEdit, EM_SETSEL,
2291 (INT)(INT16)LOWORD(lParam), (INT)(INT16)HIWORD(lParam) );
2292 return CB_ERR;
2293 case CB_SETEXTENDEDUI16:
2294 case CB_SETEXTENDEDUI:
2295 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
2296 return CB_ERR;
2297 if( wParam )
2298 lphc->wState |= CBF_EUI;
2299 else lphc->wState &= ~CBF_EUI;
2300 return CB_OKAY;
2301 case CB_GETEXTENDEDUI16:
2302 case CB_GETEXTENDEDUI:
2303 return (lphc->wState & CBF_EUI) ? TRUE : FALSE;
2304 case CB_GETCOMBOBOXINFO:
2305 return COMBO_GetComboBoxInfo(lphc, (COMBOBOXINFO *)lParam);
2306 case CB_LIMITTEXT:
2307 if( lphc->wState & CBF_EDIT )
2308 return SendMessageW(lphc->hWndEdit, EM_LIMITTEXT, wParam, lParam);
2309 default:
2310 if (message >= WM_USER)
2311 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2312 message - WM_USER, wParam, lParam );
2313 break;
2315 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2316 DefWindowProcA(hwnd, message, wParam, lParam);
2319 /***********************************************************************
2320 * ComboWndProcA
2322 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2323 * window structs.
2325 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2327 if (!IsWindow(hwnd)) return 0;
2328 return ComboWndProc_common( hwnd, message, wParam, lParam, FALSE );
2331 /***********************************************************************
2332 * ComboWndProcW
2334 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2336 if (!IsWindow(hwnd)) return 0;
2337 return ComboWndProc_common( hwnd, message, wParam, lParam, TRUE );
2340 /*************************************************************************
2341 * GetComboBoxInfo (USER32.@)
2343 BOOL WINAPI GetComboBoxInfo(HWND hwndCombo, /* [in] handle to combo box */
2344 PCOMBOBOXINFO pcbi /* [in/out] combo box information */)
2346 TRACE("(%p, %p)\n", hwndCombo, pcbi);
2347 return SendMessageW(hwndCombo, CB_GETCOMBOBOXINFO, 0, (LPARAM)pcbi);