Delay import of user32 to allow debugging crashes in user init code.
[wine/multimedia.git] / controls / combo.c
blob453974f69e10d58dd83897766a1cb93fb52995a2
1 /*
2 * Combo controls
3 *
4 * Copyright 1997 Alex Korobka
5 *
6 * FIXME: roll up in Netscape 3.01.
7 */
9 #include <string.h>
11 #include "winbase.h"
12 #include "windef.h"
13 #include "wingdi.h"
14 #include "winuser.h"
15 #include "wine/winuser16.h"
16 #include "win.h"
17 #include "spy.h"
18 #include "user.h"
19 #include "heap.h"
20 #include "controls.h"
21 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(combo);
25 /* bits in the dwKeyData */
26 #define KEYDATA_ALT 0x2000
27 #define KEYDATA_PREVSTATE 0x4000
30 * Additional combo box definitions
33 #define CB_GETPTR( wnd ) (*(LPHEADCOMBO*)((wnd)->wExtra))
34 #define CB_NOTIFY( lphc, code ) \
35 (SendMessageW((lphc)->owner, WM_COMMAND, \
36 MAKEWPARAM((lphc)->self->wIDmenu, (code)), (lphc)->self->hwndSelf))
37 #define CB_GETEDITTEXTLENGTH( lphc ) \
38 (SendMessageW((lphc)->hWndEdit, WM_GETTEXTLENGTH, 0, 0 ))
40 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
43 * Drawing globals
45 static HBITMAP hComboBmp = 0;
46 static UINT CBitHeight, CBitWidth;
49 * Look and feel dependant "constants"
52 #define COMBO_YBORDERGAP 5
53 #define COMBO_XBORDERSIZE() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 2 )
54 #define COMBO_YBORDERSIZE() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 2 )
55 #define COMBO_EDITBUTTONSPACE() ( (TWEAK_WineLook == WIN31_LOOK) ? 8 : 0 )
56 #define EDIT_CONTROL_PADDING() ( (TWEAK_WineLook == WIN31_LOOK) ? 0 : 1 )
58 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
59 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
61 /*********************************************************************
62 * combo class descriptor
64 const struct builtin_class_descr COMBO_builtin_class =
66 "ComboBox", /* name */
67 CS_GLOBALCLASS | CS_PARENTDC | CS_DBLCLKS, /* style */
68 ComboWndProcA, /* procA */
69 ComboWndProcW, /* procW */
70 sizeof(HEADCOMBO *), /* extra */
71 IDC_ARROWA, /* cursor */
72 0 /* brush */
76 /***********************************************************************
77 * COMBO_Init
79 * Load combo button bitmap.
81 static BOOL COMBO_Init()
83 HDC hDC;
85 if( hComboBmp ) return TRUE;
86 if( (hDC = CreateCompatibleDC(0)) )
88 BOOL bRet = FALSE;
89 if( (hComboBmp = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO))) )
91 BITMAP bm;
92 HBITMAP hPrevB;
93 RECT r;
95 GetObjectW( hComboBmp, sizeof(bm), &bm );
96 CBitHeight = bm.bmHeight;
97 CBitWidth = bm.bmWidth;
99 TRACE("combo bitmap [%i,%i]\n", CBitWidth, CBitHeight );
101 hPrevB = SelectObject( hDC, hComboBmp);
102 SetRect( &r, 0, 0, CBitWidth, CBitHeight );
103 InvertRect( hDC, &r );
104 SelectObject( hDC, hPrevB );
105 bRet = TRUE;
107 DeleteDC( hDC );
108 return bRet;
110 return FALSE;
113 /***********************************************************************
114 * COMBO_NCCreate
116 static LRESULT COMBO_NCCreate(WND* wnd, LONG style)
118 LPHEADCOMBO lphc;
120 if ( wnd && COMBO_Init() &&
121 (lphc = HeapAlloc(GetProcessHeap(), 0, sizeof(HEADCOMBO))) )
123 memset( lphc, 0, sizeof(HEADCOMBO) );
124 *(LPHEADCOMBO*)wnd->wExtra = lphc;
126 /* some braindead apps do try to use scrollbar/border flags */
128 lphc->dwStyle = style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
129 wnd->dwStyle &= ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL);
132 * We also have to remove the client edge style to make sure
133 * we don't end-up with a non client area.
135 wnd->dwExStyle &= ~(WS_EX_CLIENTEDGE);
137 if( !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) )
138 lphc->dwStyle |= CBS_HASSTRINGS;
139 if( !(wnd->dwExStyle & WS_EX_NOPARENTNOTIFY) )
140 lphc->wState |= CBF_NOTIFY;
142 TRACE("[0x%08x], style = %08x\n",
143 (UINT)lphc, lphc->dwStyle );
145 return (LRESULT)(UINT)wnd->hwndSelf;
147 return (LRESULT)FALSE;
150 /***********************************************************************
151 * COMBO_NCDestroy
153 static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc )
156 if( lphc )
158 WND* wnd = lphc->self;
160 TRACE("[%04x]: freeing storage\n", CB_HWND(lphc));
162 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && lphc->hWndLBox )
163 DestroyWindow( lphc->hWndLBox );
165 HeapFree( GetProcessHeap(), 0, lphc );
166 wnd->wExtra[0] = 0;
168 return 0;
171 /***********************************************************************
172 * CBGetTextAreaHeight
174 * This method will calculate the height of the text area of the
175 * combobox.
176 * The height of the text area is set in two ways.
177 * It can be set explicitly through a combobox message or through a
178 * WM_MEASUREITEM callback.
179 * If this is not the case, the height is set to 13 dialog units.
180 * This height was determined through experimentation.
182 static INT CBGetTextAreaHeight(
183 HWND hwnd,
184 LPHEADCOMBO lphc)
186 INT iTextItemHeight;
188 if( lphc->editHeight ) /* explicitly set height */
190 iTextItemHeight = lphc->editHeight;
192 else
194 TEXTMETRICW tm;
195 HDC hDC = GetDC(hwnd);
196 HFONT hPrevFont = 0;
197 INT baseUnitY;
199 if (lphc->hFont)
200 hPrevFont = SelectObject( hDC, lphc->hFont );
202 GetTextMetricsW(hDC, &tm);
204 baseUnitY = tm.tmHeight;
206 if( hPrevFont )
207 SelectObject( hDC, hPrevFont );
209 ReleaseDC(hwnd, hDC);
211 iTextItemHeight = ((13 * baseUnitY) / 8);
214 * This "formula" calculates the height of the complete control.
215 * To calculate the height of the text area, we have to remove the
216 * borders.
218 iTextItemHeight -= 2*COMBO_YBORDERSIZE();
222 * Check the ownerdraw case if we haven't asked the parent the size
223 * of the item yet.
225 if ( CB_OWNERDRAWN(lphc) &&
226 (lphc->wState & CBF_MEASUREITEM) )
228 MEASUREITEMSTRUCT measureItem;
229 RECT clientRect;
230 INT originalItemHeight = iTextItemHeight;
233 * We use the client rect for the width of the item.
235 GetClientRect(hwnd, &clientRect);
237 lphc->wState &= ~CBF_MEASUREITEM;
240 * Send a first one to measure the size of the text area
242 measureItem.CtlType = ODT_COMBOBOX;
243 measureItem.CtlID = lphc->self->wIDmenu;
244 measureItem.itemID = -1;
245 measureItem.itemWidth = clientRect.right;
246 measureItem.itemHeight = iTextItemHeight - 6; /* ownerdrawn cb is taller */
247 measureItem.itemData = 0;
248 SendMessageW(lphc->owner, WM_MEASUREITEM,
249 (WPARAM)measureItem.CtlID, (LPARAM)&measureItem);
250 iTextItemHeight = 6 + measureItem.itemHeight;
253 * Send a second one in the case of a fixed ownerdraw list to calculate the
254 * size of the list items. (we basically do this on behalf of the listbox)
256 if (lphc->dwStyle & CBS_OWNERDRAWFIXED)
258 measureItem.CtlType = ODT_COMBOBOX;
259 measureItem.CtlID = lphc->self->wIDmenu;
260 measureItem.itemID = 0;
261 measureItem.itemWidth = clientRect.right;
262 measureItem.itemHeight = originalItemHeight;
263 measureItem.itemData = 0;
264 SendMessageW(lphc->owner, WM_MEASUREITEM,
265 (WPARAM)measureItem.CtlID, (LPARAM)&measureItem);
266 lphc->fixedOwnerDrawHeight = measureItem.itemHeight;
270 * Keep the size for the next time
272 lphc->editHeight = iTextItemHeight;
275 return iTextItemHeight;
278 /***********************************************************************
279 * CBForceDummyResize
281 * The dummy resize is used for listboxes that have a popup to trigger
282 * a re-arranging of the contents of the combobox and the recalculation
283 * of the size of the "real" control window.
285 static void CBForceDummyResize(
286 LPHEADCOMBO lphc)
288 RECT windowRect;
289 int newComboHeight;
291 newComboHeight = CBGetTextAreaHeight(CB_HWND(lphc),lphc) + 2*COMBO_YBORDERSIZE();
293 GetWindowRect(CB_HWND(lphc), &windowRect);
296 * We have to be careful, resizing a combobox also has the meaning that the
297 * dropped rect will be resized. In this case, we want to trigger a resize
298 * to recalculate layout but we don't want to change the dropped rectangle
299 * So, we pass the height of text area of control as the height.
300 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
301 * message.
303 SetWindowPos( CB_HWND(lphc),
304 (HWND)NULL,
305 0, 0,
306 windowRect.right - windowRect.left,
307 newComboHeight,
308 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
311 /***********************************************************************
312 * CBCalcPlacement
314 * Set up component coordinates given valid lphc->RectCombo.
316 static void CBCalcPlacement(
317 HWND hwnd,
318 LPHEADCOMBO lphc,
319 LPRECT lprEdit,
320 LPRECT lprButton,
321 LPRECT lprLB)
324 * Again, start with the client rectangle.
326 GetClientRect(hwnd, lprEdit);
329 * Remove the borders
331 InflateRect(lprEdit, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
334 * Chop off the bottom part to fit with the height of the text area.
336 lprEdit->bottom = lprEdit->top + CBGetTextAreaHeight(hwnd, lphc);
339 * The button starts the same vertical position as the text area.
341 CopyRect(lprButton, lprEdit);
344 * If the combobox is "simple" there is no button.
346 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
347 lprButton->left = lprButton->right = lprButton->bottom = 0;
348 else
351 * Let's assume the combobox button is the same width as the
352 * scrollbar button.
353 * size the button horizontally and cut-off the text area.
355 lprButton->left = lprButton->right - GetSystemMetrics(SM_CXVSCROLL);
356 lprEdit->right = lprButton->left;
360 * In the case of a dropdown, there is an additional spacing between the
361 * text area and the button.
363 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
365 lprEdit->right -= COMBO_EDITBUTTONSPACE();
369 * If we have an edit control, we space it away from the borders slightly.
371 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
373 InflateRect(lprEdit, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
377 * Adjust the size of the listbox popup.
379 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
382 * Use the client rectangle to initialize the listbox rectangle
384 GetClientRect(hwnd, lprLB);
387 * Then, chop-off the top part.
389 lprLB->top = lprEdit->bottom + COMBO_YBORDERSIZE();
391 else
394 * Make sure the dropped width is as large as the combobox itself.
396 if (lphc->droppedWidth < (lprButton->right + COMBO_XBORDERSIZE()))
398 lprLB->right = lprLB->left + (lprButton->right + COMBO_XBORDERSIZE());
401 * In the case of a dropdown, the popup listbox is offset to the right.
402 * so, we want to make sure it's flush with the right side of the
403 * combobox
405 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
406 lprLB->right -= COMBO_EDITBUTTONSPACE();
408 else
409 lprLB->right = lprLB->left + lphc->droppedWidth;
412 TRACE("\ttext\t= (%i,%i-%i,%i)\n",
413 lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom);
415 TRACE("\tbutton\t= (%i,%i-%i,%i)\n",
416 lprButton->left, lprButton->top, lprButton->right, lprButton->bottom);
418 TRACE("\tlbox\t= (%i,%i-%i,%i)\n",
419 lprLB->left, lprLB->top, lprLB->right, lprLB->bottom );
422 /***********************************************************************
423 * CBGetDroppedControlRect
425 static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect)
427 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
428 of the combo box and the lower right corner of the listbox */
430 GetWindowRect(lphc->self->hwndSelf, lpRect);
432 lpRect->right = lpRect->left + lphc->droppedRect.right - lphc->droppedRect.left;
433 lpRect->bottom = lpRect->top + lphc->droppedRect.bottom - lphc->droppedRect.top;
437 /***********************************************************************
438 * COMBO_WindowPosChanging
440 static LRESULT COMBO_WindowPosChanging(
441 HWND hwnd,
442 LPHEADCOMBO lphc,
443 WINDOWPOS* posChanging)
446 * We need to override the WM_WINDOWPOSCHANGING method to handle all
447 * the non-simple comboboxes. The problem is that those controls are
448 * always the same height. We have to make sure they are not resized
449 * to another value.
451 if ( ( CB_GETTYPE(lphc) != CBS_SIMPLE ) &&
452 ((posChanging->flags & SWP_NOSIZE) == 0) )
454 int newComboHeight;
456 newComboHeight = CBGetTextAreaHeight(hwnd,lphc) +
457 2*COMBO_YBORDERSIZE();
460 * Resizing a combobox has another side effect, it resizes the dropped
461 * rectangle as well. However, it does it only if the new height for the
462 * combobox is different from the height it should have. In other words,
463 * if the application resizing the combobox only had the intention to resize
464 * the actual control, for example, to do the layout of a dialog that is
465 * resized, the height of the dropdown is not changed.
467 if (posChanging->cy != newComboHeight)
469 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%d, oldtop=%d\n",
470 posChanging->cy, newComboHeight, lphc->droppedRect.bottom,
471 lphc->droppedRect.top);
472 lphc->droppedRect.bottom = lphc->droppedRect.top + posChanging->cy - newComboHeight;
474 posChanging->cy = newComboHeight;
478 return 0;
481 /***********************************************************************
482 * COMBO_Create
484 static LRESULT COMBO_Create( LPHEADCOMBO lphc, WND* wnd, HWND hwndParent, LONG style )
486 static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0};
487 static const WCHAR editName[] = {'E','d','i','t',0};
489 if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE;
490 if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT;
492 lphc->self = wnd;
493 lphc->owner = hwndParent;
496 * The item height and dropped width are not set when the control
497 * is created.
499 lphc->droppedWidth = lphc->editHeight = 0;
502 * The first time we go through, we want to measure the ownerdraw item
504 lphc->wState |= CBF_MEASUREITEM;
506 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
508 if( lphc->owner || !(style & WS_VISIBLE) )
510 UINT lbeStyle = 0;
511 UINT lbeExStyle = 0;
514 * Initialize the dropped rect to the size of the client area of the
515 * control and then, force all the areas of the combobox to be
516 * recalculated.
518 GetClientRect( wnd->hwndSelf, &lphc->droppedRect );
520 CBCalcPlacement(wnd->hwndSelf,
521 lphc,
522 &lphc->textRect,
523 &lphc->buttonRect,
524 &lphc->droppedRect );
527 * Adjust the position of the popup listbox if it's necessary
529 if ( CB_GETTYPE(lphc) != CBS_SIMPLE )
531 lphc->droppedRect.top = lphc->textRect.bottom + COMBO_YBORDERSIZE();
534 * If it's a dropdown, the listbox is offset
536 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
537 lphc->droppedRect.left += COMBO_EDITBUTTONSPACE();
539 ClientToScreen(wnd->hwndSelf, (LPPOINT)&lphc->droppedRect);
540 ClientToScreen(wnd->hwndSelf, (LPPOINT)&lphc->droppedRect.right);
543 /* create listbox popup */
545 lbeStyle = (LBS_NOTIFY | WS_BORDER | WS_CLIPSIBLINGS | WS_CHILD) |
546 (style & (WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE));
548 if( lphc->dwStyle & CBS_SORT )
549 lbeStyle |= LBS_SORT;
550 if( lphc->dwStyle & CBS_HASSTRINGS )
551 lbeStyle |= LBS_HASSTRINGS;
552 if( lphc->dwStyle & CBS_NOINTEGRALHEIGHT )
553 lbeStyle |= LBS_NOINTEGRALHEIGHT;
554 if( lphc->dwStyle & CBS_DISABLENOSCROLL )
555 lbeStyle |= LBS_DISABLENOSCROLL;
557 if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* child listbox */
559 lbeStyle |= WS_VISIBLE;
562 * In win 95 look n feel, the listbox in the simple combobox has
563 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
565 if (TWEAK_WineLook > WIN31_LOOK)
567 lbeStyle &= ~WS_BORDER;
568 lbeExStyle |= WS_EX_CLIENTEDGE;
572 lphc->hWndLBox = CreateWindowExW(lbeExStyle,
573 clbName,
574 NULL,
575 lbeStyle,
576 lphc->droppedRect.left,
577 lphc->droppedRect.top,
578 lphc->droppedRect.right - lphc->droppedRect.left,
579 lphc->droppedRect.bottom - lphc->droppedRect.top,
580 lphc->self->hwndSelf,
581 (HMENU)ID_CB_LISTBOX,
582 lphc->self->hInstance,
583 (LPVOID)lphc );
585 if( lphc->hWndLBox )
587 BOOL bEdit = TRUE;
588 lbeStyle = WS_CHILD | WS_VISIBLE | ES_NOHIDESEL | ES_LEFT | ES_COMBO;
591 * In Win95 look, the border fo the edit control is
592 * provided by the combobox
594 if (TWEAK_WineLook == WIN31_LOOK)
595 lbeStyle |= WS_BORDER;
597 if( lphc->wState & CBF_EDIT )
599 if( lphc->dwStyle & CBS_OEMCONVERT )
600 lbeStyle |= ES_OEMCONVERT;
601 if( lphc->dwStyle & CBS_AUTOHSCROLL )
602 lbeStyle |= ES_AUTOHSCROLL;
603 if( lphc->dwStyle & CBS_LOWERCASE )
604 lbeStyle |= ES_LOWERCASE;
605 else if( lphc->dwStyle & CBS_UPPERCASE )
606 lbeStyle |= ES_UPPERCASE;
608 lphc->hWndEdit = CreateWindowExW(0,
609 editName,
610 NULL,
611 lbeStyle,
612 lphc->textRect.left, lphc->textRect.top,
613 lphc->textRect.right - lphc->textRect.left,
614 lphc->textRect.bottom - lphc->textRect.top,
615 lphc->self->hwndSelf,
616 (HMENU)ID_CB_EDIT,
617 lphc->self->hInstance,
618 NULL );
620 if( !lphc->hWndEdit )
621 bEdit = FALSE;
624 if( bEdit )
626 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
628 /* Now do the trick with parent */
629 SetParent(lphc->hWndLBox, HWND_DESKTOP);
631 * If the combo is a dropdown, we must resize the control
632 * to fit only the text area and button. To do this,
633 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
634 * will take care of setting the height for us.
636 CBForceDummyResize(lphc);
639 TRACE("init done\n");
640 return wnd->hwndSelf;
642 ERR("edit control failure.\n");
643 } else ERR("listbox failure.\n");
644 } else ERR("no owner for visible combo.\n");
646 /* CreateWindow() will send WM_NCDESTROY to cleanup */
648 return -1;
651 /***********************************************************************
652 * CBPaintButton
654 * Paint combo button (normal, pressed, and disabled states).
656 static void CBPaintButton(
657 LPHEADCOMBO lphc,
658 HDC hdc,
659 RECT rectButton)
661 if( lphc->wState & CBF_NOREDRAW )
662 return;
664 if (TWEAK_WineLook == WIN31_LOOK)
666 UINT x, y;
667 BOOL bBool;
668 HDC hMemDC;
669 HBRUSH hPrevBrush;
670 COLORREF oldTextColor, oldBkColor;
673 hPrevBrush = SelectObject(hdc, GetSysColorBrush(COLOR_BTNFACE));
676 * Draw the button background
678 PatBlt( hdc,
679 rectButton.left,
680 rectButton.top,
681 rectButton.right-rectButton.left,
682 rectButton.bottom-rectButton.top,
683 PATCOPY );
685 if( (bBool = lphc->wState & CBF_BUTTONDOWN) )
687 DrawEdge( hdc, &rectButton, EDGE_SUNKEN, BF_RECT );
689 else
691 DrawEdge( hdc, &rectButton, EDGE_RAISED, BF_RECT );
695 * Remove the edge of the button from the rectangle
696 * and calculate the position of the bitmap.
698 InflateRect( &rectButton, -2, -2);
700 x = (rectButton.left + rectButton.right - CBitWidth) >> 1;
701 y = (rectButton.top + rectButton.bottom - CBitHeight) >> 1;
704 hMemDC = CreateCompatibleDC( hdc );
705 SelectObject( hMemDC, hComboBmp );
706 oldTextColor = SetTextColor( hdc, GetSysColor(COLOR_BTNFACE) );
707 oldBkColor = SetBkColor( hdc, CB_DISABLED(lphc) ? RGB(128,128,128) :
708 RGB(0,0,0) );
709 BitBlt( hdc, x, y, CBitWidth, CBitHeight, hMemDC, 0, 0, SRCCOPY );
710 SetBkColor( hdc, oldBkColor );
711 SetTextColor( hdc, oldTextColor );
712 DeleteDC( hMemDC );
713 SelectObject( hdc, hPrevBrush );
715 else
717 UINT buttonState = DFCS_SCROLLCOMBOBOX;
719 if (lphc->wState & CBF_BUTTONDOWN)
721 buttonState |= DFCS_PUSHED;
724 if (CB_DISABLED(lphc))
726 buttonState |= DFCS_INACTIVE;
729 DrawFrameControl(hdc,
730 &rectButton,
731 DFC_SCROLL,
732 buttonState);
736 /***********************************************************************
737 * CBPaintText
739 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
741 static void CBPaintText(
742 LPHEADCOMBO lphc,
743 HDC hdc,
744 RECT rectEdit)
746 INT id, size = 0;
747 LPWSTR pText = NULL;
749 if( lphc->wState & CBF_NOREDRAW ) return;
751 TRACE("\n");
753 /* follow Windows combobox that sends a bunch of text
754 * inquiries to its listbox while processing WM_PAINT. */
756 if( (id = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0) ) != LB_ERR )
758 size = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, id, 0);
759 if( (pText = HeapAlloc( GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))) )
761 SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText);
762 pText[size] = '\0'; /* just in case */
763 } else return;
765 else
766 if( !CB_OWNERDRAWN(lphc) )
767 return;
769 if( lphc->wState & CBF_EDIT )
771 static const WCHAR empty_stringW[] = { 0 };
772 if( CB_HASSTRINGS(lphc) ) SetWindowTextW( lphc->hWndEdit, pText ? pText : empty_stringW );
773 if( lphc->wState & CBF_FOCUSED )
774 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
776 else /* paint text field ourselves */
778 UINT itemState = ODS_COMBOBOXEDIT;
779 HFONT hPrevFont = (lphc->hFont) ? SelectObject(hdc, lphc->hFont) : 0;
782 * Give ourselves some space.
784 InflateRect( &rectEdit, -1, -1 );
786 if( CB_OWNERDRAWN(lphc) )
788 DRAWITEMSTRUCT dis;
789 HRGN clipRegion;
791 /* setup state for DRAWITEM message. Owner will highlight */
792 if ( (lphc->wState & CBF_FOCUSED) &&
793 !(lphc->wState & CBF_DROPPED) )
794 itemState |= ODS_SELECTED | ODS_FOCUS;
797 * Save the current clip region.
798 * To retrieve the clip region, we need to create one "dummy"
799 * clip region.
801 clipRegion = CreateRectRgnIndirect(&rectEdit);
803 if (GetClipRgn(hdc, clipRegion)!=1)
805 DeleteObject(clipRegion);
806 clipRegion=(HRGN)NULL;
809 if ( lphc->self->dwStyle & WS_DISABLED )
810 itemState |= ODS_DISABLED;
812 dis.CtlType = ODT_COMBOBOX;
813 dis.CtlID = lphc->self->wIDmenu;
814 dis.hwndItem = lphc->self->hwndSelf;
815 dis.itemAction = ODA_DRAWENTIRE;
816 dis.itemID = id;
817 dis.itemState = itemState;
818 dis.hDC = hdc;
819 dis.rcItem = rectEdit;
820 dis.itemData = SendMessageW(lphc->hWndLBox, LB_GETITEMDATA,
821 (WPARAM)id, 0 );
824 * Clip the DC and have the parent draw the item.
826 IntersectClipRect(hdc,
827 rectEdit.left, rectEdit.top,
828 rectEdit.right, rectEdit.bottom);
830 SendMessageW(lphc->owner, WM_DRAWITEM,
831 lphc->self->wIDmenu, (LPARAM)&dis );
834 * Reset the clipping region.
836 SelectClipRgn(hdc, clipRegion);
838 else
840 static const WCHAR empty_stringW[] = { 0 };
842 if ( (lphc->wState & CBF_FOCUSED) &&
843 !(lphc->wState & CBF_DROPPED) ) {
845 /* highlight */
846 FillRect( hdc, &rectEdit, GetSysColorBrush(COLOR_HIGHLIGHT) );
847 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
848 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
851 ExtTextOutW( hdc,
852 rectEdit.left + 1,
853 rectEdit.top + 1,
854 ETO_OPAQUE | ETO_CLIPPED,
855 &rectEdit,
856 pText ? pText : empty_stringW , size, NULL );
858 if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED))
859 DrawFocusRect( hdc, &rectEdit );
862 if( hPrevFont )
863 SelectObject(hdc, hPrevFont );
865 if (pText)
866 HeapFree( GetProcessHeap(), 0, pText );
869 /***********************************************************************
870 * CBPaintBorder
872 static void CBPaintBorder(
873 HWND hwnd,
874 LPHEADCOMBO lphc,
875 HDC hdc)
877 RECT clientRect;
879 if (CB_GETTYPE(lphc) != CBS_SIMPLE)
881 GetClientRect(hwnd, &clientRect);
883 else
885 CopyRect(&clientRect, &lphc->textRect);
887 InflateRect(&clientRect, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
888 InflateRect(&clientRect, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
891 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_RECT);
894 /***********************************************************************
895 * COMBO_PrepareColors
897 * This method will sent the appropriate WM_CTLCOLOR message to
898 * prepare and setup the colors for the combo's DC.
900 * It also returns the brush to use for the background.
902 static HBRUSH COMBO_PrepareColors(
903 LPHEADCOMBO lphc,
904 HDC hDC)
906 HBRUSH hBkgBrush;
909 * Get the background brush for this control.
911 if (CB_DISABLED(lphc))
913 hBkgBrush = SendMessageW(lphc->owner, WM_CTLCOLORSTATIC,
914 hDC, lphc->self->hwndSelf );
917 * We have to change the text color since WM_CTLCOLORSTATIC will
918 * set it to the "enabled" color. This is the same behavior as the
919 * edit control
921 SetTextColor(hDC, GetSysColor(COLOR_GRAYTEXT));
923 else
925 if (lphc->wState & CBF_EDIT)
927 hBkgBrush = SendMessageW(lphc->owner, WM_CTLCOLOREDIT,
928 hDC, lphc->self->hwndSelf );
930 else
932 hBkgBrush = SendMessageW(lphc->owner, WM_CTLCOLORLISTBOX,
933 hDC, lphc->self->hwndSelf );
938 * Catch errors.
940 if( !hBkgBrush )
941 hBkgBrush = GetSysColorBrush(COLOR_WINDOW);
943 return hBkgBrush;
946 /***********************************************************************
947 * COMBO_EraseBackground
949 static LRESULT COMBO_EraseBackground(
950 HWND hwnd,
951 LPHEADCOMBO lphc,
952 HDC hParamDC)
954 HBRUSH hBkgBrush;
955 HDC hDC;
957 if(lphc->wState & CBF_EDIT)
958 return TRUE;
960 hDC = (hParamDC) ? hParamDC
961 : GetDC(hwnd);
963 * Retrieve the background brush
965 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
967 FillRect(hDC, &lphc->textRect, hBkgBrush);
969 if (!hParamDC)
970 ReleaseDC(hwnd, hDC);
972 return TRUE;
975 /***********************************************************************
976 * COMBO_Paint
978 static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC)
980 PAINTSTRUCT ps;
981 HDC hDC;
983 hDC = (hParamDC) ? hParamDC
984 : BeginPaint( lphc->self->hwndSelf, &ps);
986 TRACE("hdc=%04x\n", hDC);
988 if( hDC && !(lphc->wState & CBF_NOREDRAW) )
990 HBRUSH hPrevBrush, hBkgBrush;
993 * Retrieve the background brush and select it in the
994 * DC.
996 hBkgBrush = COMBO_PrepareColors(lphc, hDC);
998 hPrevBrush = SelectObject( hDC, hBkgBrush );
1001 * In non 3.1 look, there is a sunken border on the combobox
1003 if (TWEAK_WineLook != WIN31_LOOK)
1005 CBPaintBorder(CB_HWND(lphc), lphc, hDC);
1008 if( !IsRectEmpty(&lphc->buttonRect) )
1010 CBPaintButton(lphc, hDC, lphc->buttonRect);
1013 /* paint the edit control padding area */
1014 if (CB_GETTYPE(lphc) != CBS_DROPDOWNLIST)
1016 HPEN hPrevPen = SelectObject( hDC, GetSysColorPen(COLOR_WINDOW) );
1017 RECT rPadEdit = lphc->textRect;
1019 InflateRect(&rPadEdit, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
1021 Rectangle( hDC, rPadEdit.left, rPadEdit.top, rPadEdit.right, rPadEdit.bottom);
1023 SelectObject( hDC, hPrevPen );
1026 if( !(lphc->wState & CBF_EDIT) )
1029 * The text area has a border only in Win 3.1 look.
1031 if (TWEAK_WineLook == WIN31_LOOK)
1033 HPEN hPrevPen = SelectObject( hDC, GetSysColorPen(COLOR_WINDOWFRAME) );
1035 Rectangle( hDC,
1036 lphc->textRect.left, lphc->textRect.top,
1037 lphc->textRect.right - 1, lphc->textRect.bottom - 1);
1039 SelectObject( hDC, hPrevPen );
1042 CBPaintText( lphc, hDC, lphc->textRect);
1045 if( hPrevBrush )
1046 SelectObject( hDC, hPrevBrush );
1049 if( !hParamDC )
1050 EndPaint(lphc->self->hwndSelf, &ps);
1052 return 0;
1055 /***********************************************************************
1056 * CBUpdateLBox
1058 * Select listbox entry according to the contents of the edit control.
1060 static INT CBUpdateLBox( LPHEADCOMBO lphc, BOOL bSelect )
1062 INT length, idx;
1063 LPWSTR pText = NULL;
1065 idx = LB_ERR;
1066 length = CB_GETEDITTEXTLENGTH( lphc );
1068 if( length > 0 )
1069 pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1071 TRACE("\t edit text length %i\n", length );
1073 if( pText )
1075 if( length ) GetWindowTextW( lphc->hWndEdit, pText, length + 1);
1076 else pText[0] = '\0';
1077 idx = SendMessageW(lphc->hWndLBox, LB_FINDSTRING,
1078 (WPARAM)(-1), (LPARAM)pText );
1079 HeapFree( GetProcessHeap(), 0, pText );
1082 SendMessageW(lphc->hWndLBox, LB_SETCURSEL, (WPARAM)(bSelect ? idx : -1), 0);
1084 /* probably superfluous but Windows sends this too */
1085 SendMessageW(lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1086 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)(idx < 0 ? 0 : idx), 0);
1088 return idx;
1091 /***********************************************************************
1092 * CBUpdateEdit
1094 * Copy a listbox entry to the edit control.
1096 static void CBUpdateEdit( LPHEADCOMBO lphc , INT index )
1098 INT length;
1099 LPWSTR pText = NULL;
1100 static const WCHAR empty_stringW[] = { 0 };
1102 TRACE("\t %i\n", index );
1104 if( index >= 0 ) /* got an entry */
1106 length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0);
1107 if( length )
1109 if( (pText = HeapAlloc( GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR))) )
1111 SendMessageW(lphc->hWndLBox, LB_GETTEXT,
1112 (WPARAM)index, (LPARAM)pText );
1117 lphc->wState |= (CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1118 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, pText ? (LPARAM)pText : (LPARAM)empty_stringW);
1119 lphc->wState &= ~(CBF_NOEDITNOTIFY | CBF_NOLBSELECT);
1121 if( lphc->wState & CBF_FOCUSED )
1122 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1124 if( pText )
1125 HeapFree( GetProcessHeap(), 0, pText );
1128 /***********************************************************************
1129 * CBDropDown
1131 * Show listbox popup.
1133 static void CBDropDown( LPHEADCOMBO lphc )
1135 RECT rect,r;
1136 int nItems = 0;
1137 int nDroppedHeight;
1139 TRACE("[%04x]: drop down\n", CB_HWND(lphc));
1141 CB_NOTIFY( lphc, CBN_DROPDOWN );
1143 /* set selection */
1145 lphc->wState |= CBF_DROPPED;
1146 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1148 lphc->droppedIndex = CBUpdateLBox( lphc, TRUE );
1150 /* Update edit only if item is in the list */
1151 if( !(lphc->wState & CBF_CAPTURE) && lphc->droppedIndex >= 0)
1152 CBUpdateEdit( lphc, lphc->droppedIndex );
1154 else
1156 lphc->droppedIndex = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1158 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX,
1159 (WPARAM)(lphc->droppedIndex == LB_ERR ? 0 : lphc->droppedIndex), 0 );
1160 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1163 /* now set popup position */
1164 GetWindowRect( lphc->self->hwndSelf, &rect );
1167 * If it's a dropdown, the listbox is offset
1169 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1170 rect.left += COMBO_EDITBUTTONSPACE();
1172 /* if the dropped height is greater than the total height of the dropped
1173 items list, then force the drop down list height to be the total height
1174 of the items in the dropped list */
1176 /* And Remove any extra space (Best Fit) */
1177 nDroppedHeight = lphc->droppedRect.bottom - lphc->droppedRect.top;
1178 /* if listbox length has been set directly by its handle */
1179 GetWindowRect(lphc->hWndLBox, &r);
1180 if (nDroppedHeight < r.bottom - r.top)
1181 nDroppedHeight = r.bottom - r.top;
1182 nItems = (int)SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
1184 if (nItems > 0)
1186 int nHeight;
1188 nHeight = (int)SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, 0, 0);
1189 nHeight *= nItems;
1191 if (nHeight < nDroppedHeight - COMBO_YBORDERSIZE())
1192 nDroppedHeight = nHeight + COMBO_YBORDERSIZE();
1195 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1196 if( (rect.bottom + nDroppedHeight) >= GetSystemMetrics( SM_CYSCREEN ) )
1197 rect.bottom = rect.top - nDroppedHeight;
1199 SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.bottom,
1200 lphc->droppedRect.right - lphc->droppedRect.left,
1201 nDroppedHeight,
1202 SWP_NOACTIVATE | SWP_SHOWWINDOW);
1205 if( !(lphc->wState & CBF_NOREDRAW) )
1206 RedrawWindow( lphc->self->hwndSelf, NULL, 0, RDW_INVALIDATE |
1207 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1209 EnableWindow( lphc->hWndLBox, TRUE );
1210 if (GetCapture() != lphc->self->hwndSelf)
1211 SetCapture(lphc->hWndLBox);
1214 /***********************************************************************
1215 * CBRollUp
1217 * Hide listbox popup.
1219 static void CBRollUp( LPHEADCOMBO lphc, BOOL ok, BOOL bButton )
1221 HWND hWnd = lphc->self->hwndSelf;
1223 TRACE("[%04x]: sel ok? [%i] dropped? [%i]\n",
1224 CB_HWND(lphc), (INT)ok, (INT)(lphc->wState & CBF_DROPPED));
1226 CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL );
1228 if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE )
1231 if( lphc->wState & CBF_DROPPED )
1233 RECT rect;
1235 lphc->wState &= ~CBF_DROPPED;
1236 ShowWindow( lphc->hWndLBox, SW_HIDE );
1238 if(GetCapture() == lphc->hWndLBox)
1240 ReleaseCapture();
1243 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1245 rect = lphc->buttonRect;
1247 else
1249 if( bButton )
1251 UnionRect( &rect,
1252 &lphc->buttonRect,
1253 &lphc->textRect);
1255 else
1256 rect = lphc->textRect;
1258 bButton = TRUE;
1261 if( bButton && !(lphc->wState & CBF_NOREDRAW) )
1262 RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE |
1263 RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN );
1264 CB_NOTIFY( lphc, CBN_CLOSEUP );
1269 /***********************************************************************
1270 * COMBO_FlipListbox
1272 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1274 BOOL COMBO_FlipListbox( LPHEADCOMBO lphc, BOOL ok, BOOL bRedrawButton )
1276 if( lphc->wState & CBF_DROPPED )
1278 CBRollUp( lphc, ok, bRedrawButton );
1279 return FALSE;
1282 CBDropDown( lphc );
1283 return TRUE;
1286 /***********************************************************************
1287 * CBRepaintButton
1289 static void CBRepaintButton( LPHEADCOMBO lphc )
1291 InvalidateRect(CB_HWND(lphc), &lphc->buttonRect, TRUE);
1292 UpdateWindow(CB_HWND(lphc));
1295 /***********************************************************************
1296 * COMBO_SetFocus
1298 static void COMBO_SetFocus( LPHEADCOMBO lphc )
1300 if( !(lphc->wState & CBF_FOCUSED) )
1302 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1303 SendMessageW(lphc->hWndLBox, LB_CARETON, 0, 0);
1305 /* This is wrong. Message sequences seem to indicate that this
1306 is set *after* the notify. */
1307 /* lphc->wState |= CBF_FOCUSED; */
1309 if( !(lphc->wState & CBF_EDIT) )
1310 InvalidateRect(CB_HWND(lphc), &lphc->textRect, TRUE);
1312 CB_NOTIFY( lphc, CBN_SETFOCUS );
1313 lphc->wState |= CBF_FOCUSED;
1317 /***********************************************************************
1318 * COMBO_KillFocus
1320 static void COMBO_KillFocus( LPHEADCOMBO lphc )
1322 HWND hWnd = lphc->self->hwndSelf;
1324 if( lphc->wState & CBF_FOCUSED )
1326 CBRollUp( lphc, FALSE, TRUE );
1327 if( IsWindow( hWnd ) )
1329 if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST )
1330 SendMessageW(lphc->hWndLBox, LB_CARETOFF, 0, 0);
1332 lphc->wState &= ~CBF_FOCUSED;
1334 /* redraw text */
1335 if( !(lphc->wState & CBF_EDIT) )
1336 InvalidateRect(CB_HWND(lphc), &lphc->textRect, TRUE);
1338 CB_NOTIFY( lphc, CBN_KILLFOCUS );
1343 /***********************************************************************
1344 * COMBO_Command
1346 static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd )
1348 if ( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd )
1350 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1352 switch( HIWORD(wParam) >> 8 )
1354 case (EN_SETFOCUS >> 8):
1356 TRACE("[%04x]: edit [%04x] got focus\n",
1357 CB_HWND(lphc), lphc->hWndEdit );
1359 COMBO_SetFocus( lphc );
1360 break;
1362 case (EN_KILLFOCUS >> 8):
1364 TRACE("[%04x]: edit [%04x] lost focus\n",
1365 CB_HWND(lphc), lphc->hWndEdit );
1367 /* NOTE: it seems that Windows' edit control sends an
1368 * undocumented message WM_USER + 0x1B instead of this
1369 * notification (only when it happens to be a part of
1370 * the combo). ?? - AK.
1373 COMBO_KillFocus( lphc );
1374 break;
1377 case (EN_CHANGE >> 8):
1379 * In some circumstances (when the selection of the combobox
1380 * is changed for example) we don't wans the EN_CHANGE notification
1381 * to be forwarded to the parent of the combobox. This code
1382 * checks a flag that is set in these occasions and ignores the
1383 * notification.
1385 if (lphc->wState & CBF_NOLBSELECT)
1387 lphc->wState &= ~CBF_NOLBSELECT;
1389 else
1391 CBUpdateLBox( lphc, lphc->wState & CBF_DROPPED );
1394 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1395 CB_NOTIFY( lphc, CBN_EDITCHANGE );
1396 break;
1398 case (EN_UPDATE >> 8):
1399 if (!(lphc->wState & CBF_NOEDITNOTIFY))
1400 CB_NOTIFY( lphc, CBN_EDITUPDATE );
1401 break;
1403 case (EN_ERRSPACE >> 8):
1404 CB_NOTIFY( lphc, CBN_ERRSPACE );
1407 else if( lphc->hWndLBox == hWnd )
1409 switch( HIWORD(wParam) )
1411 case LBN_ERRSPACE:
1412 CB_NOTIFY( lphc, CBN_ERRSPACE );
1413 break;
1415 case LBN_DBLCLK:
1416 CB_NOTIFY( lphc, CBN_DBLCLK );
1417 break;
1419 case LBN_SELCHANGE:
1420 case LBN_SELCANCEL:
1422 TRACE("[%04x]: lbox selection change [%04x]\n",
1423 CB_HWND(lphc), lphc->wState );
1425 if( HIWORD(wParam) == LBN_SELCHANGE)
1427 if( lphc->wState & CBF_EDIT )
1429 INT index = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1430 lphc->wState |= CBF_NOLBSELECT;
1431 CBUpdateEdit( lphc, index );
1432 /* select text in edit, as Windows does */
1433 SendMessageW(lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1));
1435 else
1436 InvalidateRect(CB_HWND(lphc), &lphc->textRect, TRUE);
1439 /* do not roll up if selection is being tracked
1440 * by arrowkeys in the dropdown listbox */
1441 if( ((lphc->wState & CBF_DROPPED) && !(lphc->wState & CBF_NOROLLUP)) )
1443 CBRollUp( lphc, (HIWORD(wParam) == LBN_SELCHANGE), TRUE );
1445 else lphc->wState &= ~CBF_NOROLLUP;
1447 CB_NOTIFY( lphc, CBN_SELCHANGE );
1449 /* fall through */
1451 case LBN_SETFOCUS:
1452 case LBN_KILLFOCUS:
1453 /* nothing to do here since ComboLBox always resets the focus to its
1454 * combo/edit counterpart */
1455 break;
1458 return 0;
1461 /***********************************************************************
1462 * COMBO_ItemOp
1464 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1466 static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
1468 HWND hWnd = lphc->self->hwndSelf;
1470 TRACE("[%04x]: ownerdraw op %04x\n", CB_HWND(lphc), msg );
1472 #define lpIS ((LPDELETEITEMSTRUCT)lParam)
1474 /* two first items are the same in all 4 structs */
1475 lpIS->CtlType = ODT_COMBOBOX;
1476 lpIS->CtlID = lphc->self->wIDmenu;
1478 switch( msg ) /* patch window handle */
1480 case WM_DELETEITEM:
1481 lpIS->hwndItem = hWnd;
1482 #undef lpIS
1483 break;
1484 case WM_DRAWITEM:
1485 #define lpIS ((LPDRAWITEMSTRUCT)lParam)
1486 lpIS->hwndItem = hWnd;
1487 #undef lpIS
1488 break;
1489 case WM_COMPAREITEM:
1490 #define lpIS ((LPCOMPAREITEMSTRUCT)lParam)
1491 lpIS->hwndItem = hWnd;
1492 #undef lpIS
1493 break;
1496 return SendMessageW(lphc->owner, msg, lphc->self->wIDmenu, lParam);
1499 /***********************************************************************
1500 * COMBO_GetText
1502 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1503 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1505 static LRESULT COMBO_GetText( LPHEADCOMBO lphc, INT N, LPARAM lParam, BOOL unicode)
1507 if( lphc->wState & CBF_EDIT )
1508 return unicode ? SendMessageW(lphc->hWndEdit, WM_GETTEXT, (WPARAM)N, lParam) :
1509 SendMessageA(lphc->hWndEdit, WM_GETTEXT, (WPARAM)N, lParam);
1511 /* get it from the listbox */
1513 if( lphc->hWndLBox )
1515 INT idx = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1516 if( idx != LB_ERR )
1518 INT n = 0;
1519 INT length = SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN,
1520 (WPARAM)idx, 0 );
1522 if(unicode)
1524 LPWSTR lpBuffer, lpText = (LPWSTR)lParam;
1526 /* 'length' is without the terminating character */
1527 if(length >= N)
1528 lpBuffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR));
1529 else
1530 lpBuffer = lpText;
1532 if(lpBuffer)
1534 n = SendMessageW(lphc->hWndLBox, LB_GETTEXT, (WPARAM)idx, (LPARAM)lpBuffer);
1536 /* truncate if buffer is too short */
1537 if(length >= N)
1539 if(N && lpText)
1541 if(n != LB_ERR)
1542 strncpyW(lpText, lpBuffer, (N > n) ? n+1 : N-1);
1543 lpText[N - 1] = '\0';
1545 HeapFree( GetProcessHeap(), 0, lpBuffer );
1549 else
1551 LPSTR lpBuffer, lpText = (LPSTR)lParam;
1553 /* 'length' is without the terminating character */
1554 if(length >= N)
1555 lpBuffer = HeapAlloc(GetProcessHeap(), 0, length + 1);
1556 else
1557 lpBuffer = lpText;
1559 if(lpBuffer)
1561 n = SendMessageA(lphc->hWndLBox, LB_GETTEXT, (WPARAM)idx, (LPARAM)lpBuffer);
1563 /* truncate if buffer is too short */
1564 if(length >= N)
1566 if(N && lpText)
1568 if(n != LB_ERR)
1569 strncpy(lpText, lpBuffer, (N > n) ? n+1 : N-1);
1570 lpText[N - 1] = '\0';
1572 HeapFree( GetProcessHeap(), 0, lpBuffer );
1576 if (n<0)
1577 n=0;
1578 else
1579 n++;
1580 return (LRESULT)n;
1583 return 0;
1587 /***********************************************************************
1588 * CBResetPos
1590 * This function sets window positions according to the updated
1591 * component placement struct.
1593 static void CBResetPos(
1594 LPHEADCOMBO lphc,
1595 LPRECT rectEdit,
1596 LPRECT rectLB,
1597 BOOL bRedraw)
1599 BOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE);
1601 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1602 * sizing messages */
1604 if( lphc->wState & CBF_EDIT )
1605 SetWindowPos( lphc->hWndEdit, 0,
1606 rectEdit->left, rectEdit->top,
1607 rectEdit->right - rectEdit->left,
1608 rectEdit->bottom - rectEdit->top,
1609 SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) );
1611 SetWindowPos( lphc->hWndLBox, 0,
1612 rectLB->left, rectLB->top,
1613 rectLB->right - rectLB->left,
1614 rectLB->bottom - rectLB->top,
1615 SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) );
1617 if( bDrop )
1619 if( lphc->wState & CBF_DROPPED )
1621 lphc->wState &= ~CBF_DROPPED;
1622 ShowWindow( lphc->hWndLBox, SW_HIDE );
1625 if( bRedraw && !(lphc->wState & CBF_NOREDRAW) )
1626 RedrawWindow( lphc->self->hwndSelf, NULL, 0,
1627 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
1632 /***********************************************************************
1633 * COMBO_Size
1635 static void COMBO_Size( LPHEADCOMBO lphc )
1637 CBCalcPlacement(lphc->self->hwndSelf,
1638 lphc,
1639 &lphc->textRect,
1640 &lphc->buttonRect,
1641 &lphc->droppedRect);
1643 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1647 /***********************************************************************
1648 * COMBO_Font
1650 static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, BOOL bRedraw )
1653 * Set the font
1655 lphc->hFont = hFont;
1658 * Propagate to owned windows.
1660 if( lphc->wState & CBF_EDIT )
1661 SendMessageW(lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw);
1662 SendMessageW(lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw);
1665 * Redo the layout of the control.
1667 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1669 CBCalcPlacement(lphc->self->hwndSelf,
1670 lphc,
1671 &lphc->textRect,
1672 &lphc->buttonRect,
1673 &lphc->droppedRect);
1675 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1677 else
1679 CBForceDummyResize(lphc);
1684 /***********************************************************************
1685 * COMBO_SetItemHeight
1687 static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height )
1689 LRESULT lRet = CB_ERR;
1691 if( index == -1 ) /* set text field height */
1693 if( height < 32768 )
1695 lphc->editHeight = height;
1698 * Redo the layout of the control.
1700 if ( CB_GETTYPE(lphc) == CBS_SIMPLE)
1702 CBCalcPlacement(lphc->self->hwndSelf,
1703 lphc,
1704 &lphc->textRect,
1705 &lphc->buttonRect,
1706 &lphc->droppedRect);
1708 CBResetPos( lphc, &lphc->textRect, &lphc->droppedRect, TRUE );
1710 else
1712 CBForceDummyResize(lphc);
1715 lRet = height;
1718 else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */
1719 lRet = SendMessageW(lphc->hWndLBox, LB_SETITEMHEIGHT,
1720 (WPARAM)index, (LPARAM)height );
1721 return lRet;
1724 /***********************************************************************
1725 * COMBO_SelectString
1727 static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPARAM pText, BOOL unicode )
1729 INT index = unicode ? SendMessageW(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText) :
1730 SendMessageA(lphc->hWndLBox, LB_SELECTSTRING, (WPARAM)start, pText);
1731 if( index >= 0 )
1733 if( lphc->wState & CBF_EDIT )
1734 CBUpdateEdit( lphc, index );
1735 else
1737 InvalidateRect(CB_HWND(lphc), &lphc->textRect, TRUE);
1740 return (LRESULT)index;
1743 /***********************************************************************
1744 * COMBO_LButtonDown
1746 static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam )
1748 POINT pt;
1749 BOOL bButton;
1750 HWND hWnd = lphc->self->hwndSelf;
1752 pt.x = LOWORD(lParam);
1753 pt.y = HIWORD(lParam);
1754 bButton = PtInRect(&lphc->buttonRect, pt);
1756 if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) ||
1757 (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) )
1759 lphc->wState |= CBF_BUTTONDOWN;
1760 if( lphc->wState & CBF_DROPPED )
1762 /* got a click to cancel selection */
1764 lphc->wState &= ~CBF_BUTTONDOWN;
1765 CBRollUp( lphc, TRUE, FALSE );
1766 if( !IsWindow( hWnd ) ) return;
1768 if( lphc->wState & CBF_CAPTURE )
1770 lphc->wState &= ~CBF_CAPTURE;
1771 ReleaseCapture();
1774 else
1776 /* drop down the listbox and start tracking */
1778 lphc->wState |= CBF_CAPTURE;
1779 SetCapture( hWnd );
1780 CBDropDown( lphc );
1782 if( bButton ) CBRepaintButton( lphc );
1786 /***********************************************************************
1787 * COMBO_LButtonUp
1789 * Release capture and stop tracking if needed.
1791 static void COMBO_LButtonUp( LPHEADCOMBO lphc )
1793 if( lphc->wState & CBF_CAPTURE )
1795 lphc->wState &= ~CBF_CAPTURE;
1796 if( CB_GETTYPE(lphc) == CBS_DROPDOWN )
1798 INT index = CBUpdateLBox( lphc, TRUE );
1799 /* Update edit only if item is in the list */
1800 if(index >= 0)
1802 lphc->wState |= CBF_NOLBSELECT;
1803 CBUpdateEdit( lphc, index );
1804 lphc->wState &= ~CBF_NOLBSELECT;
1807 ReleaseCapture();
1808 SetCapture(lphc->hWndLBox);
1811 if( lphc->wState & CBF_BUTTONDOWN )
1813 lphc->wState &= ~CBF_BUTTONDOWN;
1814 CBRepaintButton( lphc );
1818 /***********************************************************************
1819 * COMBO_MouseMove
1821 * Two things to do - track combo button and release capture when
1822 * pointer goes into the listbox.
1824 static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam )
1826 POINT pt;
1827 RECT lbRect;
1829 pt.x = LOWORD(lParam);
1830 pt.y = HIWORD(lParam);
1832 if( lphc->wState & CBF_BUTTONDOWN )
1834 BOOL bButton;
1836 bButton = PtInRect(&lphc->buttonRect, pt);
1838 if( !bButton )
1840 lphc->wState &= ~CBF_BUTTONDOWN;
1841 CBRepaintButton( lphc );
1845 GetClientRect( lphc->hWndLBox, &lbRect );
1846 MapWindowPoints( lphc->self->hwndSelf, lphc->hWndLBox, &pt, 1 );
1847 if( PtInRect(&lbRect, pt) )
1849 lphc->wState &= ~CBF_CAPTURE;
1850 ReleaseCapture();
1851 if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc, TRUE );
1853 /* hand over pointer tracking */
1854 SendMessageW(lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam);
1859 /***********************************************************************
1860 * ComboWndProc_locked
1862 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1864 static LRESULT ComboWndProc_locked( WND* pWnd, UINT message,
1865 WPARAM wParam, LPARAM lParam, BOOL unicode )
1867 if( pWnd ) {
1868 LPHEADCOMBO lphc = CB_GETPTR(pWnd);
1869 HWND hwnd = pWnd->hwndSelf;
1871 TRACE("[%04x]: msg %s wp %08x lp %08lx\n",
1872 pWnd->hwndSelf, SPY_GetMsgName(message), wParam, lParam );
1874 if( lphc || message == WM_NCCREATE )
1875 switch(message)
1878 /* System messages */
1880 case WM_NCCREATE:
1882 LONG style = unicode ? ((LPCREATESTRUCTW)lParam)->style :
1883 ((LPCREATESTRUCTA)lParam)->style;
1884 return COMBO_NCCreate(pWnd, style);
1886 case WM_NCDESTROY:
1887 COMBO_NCDestroy(lphc);
1888 break;/* -> DefWindowProc */
1890 case WM_CREATE:
1892 HWND hwndParent;
1893 LONG style;
1894 if(unicode)
1896 hwndParent = ((LPCREATESTRUCTW)lParam)->hwndParent;
1897 style = ((LPCREATESTRUCTW)lParam)->style;
1899 else
1901 hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent;
1902 style = ((LPCREATESTRUCTA)lParam)->style;
1904 return COMBO_Create(lphc, pWnd, hwndParent, style);
1907 case WM_PRINTCLIENT:
1908 if (lParam & PRF_ERASEBKGND)
1909 COMBO_EraseBackground(hwnd, lphc, wParam);
1911 /* Fallthrough */
1912 case WM_PAINT:
1913 /* wParam may contain a valid HDC! */
1914 return COMBO_Paint(lphc, wParam);
1915 case WM_ERASEBKGND:
1916 return COMBO_EraseBackground(hwnd, lphc, wParam);
1917 case WM_GETDLGCODE:
1919 LRESULT result = DLGC_WANTARROWS | DLGC_WANTCHARS;
1920 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
1922 int vk = (int)((LPMSG)lParam)->wParam;
1924 if ((vk == VK_RETURN || vk == VK_ESCAPE) && (lphc->wState & CBF_DROPPED))
1925 result |= DLGC_WANTMESSAGE;
1927 return result;
1929 case WM_WINDOWPOSCHANGING:
1930 return COMBO_WindowPosChanging(hwnd, lphc, (LPWINDOWPOS)lParam);
1931 case WM_WINDOWPOSCHANGED:
1932 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1933 * In that case, the Combobox itself will not be resized, so we won't
1934 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1935 * do it here.
1937 /* fall through */
1938 case WM_SIZE:
1939 if( lphc->hWndLBox &&
1940 !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc );
1941 return TRUE;
1942 case WM_SETFONT:
1943 COMBO_Font( lphc, (HFONT16)wParam, (BOOL)lParam );
1944 return TRUE;
1945 case WM_GETFONT:
1946 return (LRESULT)lphc->hFont;
1947 case WM_SETFOCUS:
1948 if( lphc->wState & CBF_EDIT )
1949 SetFocus( lphc->hWndEdit );
1950 else
1951 COMBO_SetFocus( lphc );
1952 return TRUE;
1953 case WM_KILLFOCUS:
1954 #define hwndFocus ((HWND16)wParam)
1955 if( !hwndFocus ||
1956 (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox ))
1957 COMBO_KillFocus( lphc );
1958 #undef hwndFocus
1959 return TRUE;
1960 case WM_COMMAND:
1961 return COMBO_Command( lphc, wParam, (HWND)lParam );
1962 case WM_GETTEXT:
1963 return COMBO_GetText( lphc, (INT)wParam, lParam, unicode );
1964 case WM_SETTEXT:
1965 case WM_GETTEXTLENGTH:
1966 case WM_CLEAR:
1967 if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT))
1969 int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
1970 if (j == -1) return 0;
1971 return SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0);
1973 else if( lphc->wState & CBF_EDIT )
1975 LRESULT ret;
1976 lphc->wState |= CBF_NOEDITNOTIFY;
1977 ret = unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1978 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1979 lphc->wState &= ~CBF_NOEDITNOTIFY;
1980 return ret;
1982 else return CB_ERR;
1983 case WM_CUT:
1984 case WM_PASTE:
1985 case WM_COPY:
1986 if( lphc->wState & CBF_EDIT )
1988 return unicode ? SendMessageW(lphc->hWndEdit, message, wParam, lParam) :
1989 SendMessageA(lphc->hWndEdit, message, wParam, lParam);
1991 else return CB_ERR;
1993 case WM_DRAWITEM:
1994 case WM_DELETEITEM:
1995 case WM_COMPAREITEM:
1996 case WM_MEASUREITEM:
1997 return COMBO_ItemOp(lphc, message, lParam);
1998 case WM_ENABLE:
1999 if( lphc->wState & CBF_EDIT )
2000 EnableWindow( lphc->hWndEdit, (BOOL)wParam );
2001 EnableWindow( lphc->hWndLBox, (BOOL)wParam );
2003 /* Force the control to repaint when the enabled state changes. */
2004 InvalidateRect(CB_HWND(lphc), NULL, TRUE);
2005 return TRUE;
2006 case WM_SETREDRAW:
2007 if( wParam )
2008 lphc->wState &= ~CBF_NOREDRAW;
2009 else
2010 lphc->wState |= CBF_NOREDRAW;
2012 if( lphc->wState & CBF_EDIT )
2013 SendMessageW(lphc->hWndEdit, message, wParam, lParam);
2014 SendMessageW(lphc->hWndLBox, message, wParam, lParam);
2015 return 0;
2016 case WM_SYSKEYDOWN:
2017 if( KEYDATA_ALT & HIWORD(lParam) )
2018 if( wParam == VK_UP || wParam == VK_DOWN )
2019 COMBO_FlipListbox( lphc, FALSE, FALSE );
2020 return 0;
2022 case WM_CHAR:
2023 case WM_KEYDOWN:
2025 HWND hwndTarget;
2027 if ((wParam == VK_RETURN || wParam == VK_ESCAPE) &&
2028 (lphc->wState & CBF_DROPPED))
2030 CBRollUp( lphc, wParam == VK_RETURN, FALSE );
2031 return TRUE;
2034 if( lphc->wState & CBF_EDIT )
2035 hwndTarget = lphc->hWndEdit;
2036 else
2037 hwndTarget = lphc->hWndLBox;
2039 return unicode ? SendMessageW(hwndTarget, message, wParam, lParam) :
2040 SendMessageA(hwndTarget, message, wParam, lParam);
2042 case WM_LBUTTONDOWN:
2043 if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self->hwndSelf );
2044 if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam );
2045 return TRUE;
2046 case WM_LBUTTONUP:
2047 COMBO_LButtonUp( lphc );
2048 return TRUE;
2049 case WM_MOUSEMOVE:
2050 if( lphc->wState & CBF_CAPTURE )
2051 COMBO_MouseMove( lphc, wParam, lParam );
2052 return TRUE;
2054 case WM_MOUSEWHEEL:
2055 if (wParam & (MK_SHIFT | MK_CONTROL))
2056 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2057 DefWindowProcA(hwnd, message, wParam, lParam);
2058 if (SHIWORD(wParam) > 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_UP, 0);
2059 if (SHIWORD(wParam) < 0) return SendMessageW(hwnd, WM_KEYDOWN, VK_DOWN, 0);
2060 return TRUE;
2062 /* Combo messages */
2064 case CB_ADDSTRING16:
2065 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2066 /* fall through */
2067 case CB_ADDSTRING:
2068 return unicode ? SendMessageW(lphc->hWndLBox, LB_ADDSTRING, 0, lParam) :
2069 SendMessageA(lphc->hWndLBox, LB_ADDSTRING, 0, lParam);
2070 case CB_INSERTSTRING16:
2071 wParam = (INT)(INT16)wParam;
2072 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2073 /* fall through */
2074 case CB_INSERTSTRING:
2075 return unicode ? SendMessageW(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam) :
2076 SendMessageA(lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam);
2077 case CB_DELETESTRING16:
2078 case CB_DELETESTRING:
2079 return unicode ? SendMessageW(lphc->hWndLBox, LB_DELETESTRING, wParam, 0) :
2080 SendMessageA(lphc->hWndLBox, LB_DELETESTRING, wParam, 0);
2081 case CB_SELECTSTRING16:
2082 wParam = (INT)(INT16)wParam;
2083 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2084 /* fall through */
2085 case CB_SELECTSTRING:
2086 return COMBO_SelectString(lphc, (INT)wParam, lParam, unicode);
2087 case CB_FINDSTRING16:
2088 wParam = (INT)(INT16)wParam;
2089 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2090 /* fall through */
2091 case CB_FINDSTRING:
2092 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam) :
2093 SendMessageA(lphc->hWndLBox, LB_FINDSTRING, wParam, lParam);
2094 case CB_FINDSTRINGEXACT16:
2095 wParam = (INT)(INT16)wParam;
2096 if( CB_HASSTRINGS(lphc) ) lParam = (LPARAM)MapSL(lParam);
2097 /* fall through */
2098 case CB_FINDSTRINGEXACT:
2099 return unicode ? SendMessageW(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam) :
2100 SendMessageA(lphc->hWndLBox, LB_FINDSTRINGEXACT, wParam, lParam);
2101 case CB_SETITEMHEIGHT16:
2102 wParam = (INT)(INT16)wParam; /* signed integer */
2103 /* fall through */
2104 case CB_SETITEMHEIGHT:
2105 return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam);
2106 case CB_GETITEMHEIGHT16:
2107 wParam = (INT)(INT16)wParam;
2108 /* fall through */
2109 case CB_GETITEMHEIGHT:
2110 if( (INT)wParam >= 0 ) /* listbox item */
2111 return SendMessageW(lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0);
2112 return CBGetTextAreaHeight(hwnd, lphc);
2113 case CB_RESETCONTENT16:
2114 case CB_RESETCONTENT:
2115 SendMessageW(lphc->hWndLBox, LB_RESETCONTENT, 0, 0);
2116 if( (lphc->wState & CBF_EDIT) && CB_HASSTRINGS(lphc) )
2118 static const WCHAR empty_stringW[] = { 0 };
2119 SendMessageW(lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)empty_stringW);
2121 else
2122 InvalidateRect(CB_HWND(lphc), NULL, TRUE);
2123 return TRUE;
2124 case CB_INITSTORAGE:
2125 return SendMessageW(lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam);
2126 case CB_GETHORIZONTALEXTENT:
2127 return SendMessageW(lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0);
2128 case CB_SETHORIZONTALEXTENT:
2129 return SendMessageW(lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0);
2130 case CB_GETTOPINDEX:
2131 return SendMessageW(lphc->hWndLBox, LB_GETTOPINDEX, 0, 0);
2132 case CB_GETLOCALE:
2133 return SendMessageW(lphc->hWndLBox, LB_GETLOCALE, 0, 0);
2134 case CB_SETLOCALE:
2135 return SendMessageW(lphc->hWndLBox, LB_SETLOCALE, wParam, 0);
2136 case CB_GETDROPPEDWIDTH:
2137 if( lphc->droppedWidth )
2138 return lphc->droppedWidth;
2139 return lphc->droppedRect.right - lphc->droppedRect.left;
2140 case CB_SETDROPPEDWIDTH:
2141 if( (CB_GETTYPE(lphc) != CBS_SIMPLE) &&
2142 (INT)wParam < 32768 ) lphc->droppedWidth = (INT)wParam;
2143 return CB_ERR;
2144 case CB_GETDROPPEDCONTROLRECT16:
2145 lParam = (LPARAM)MapSL(lParam);
2146 if( lParam )
2148 RECT r;
2149 CBGetDroppedControlRect( lphc, &r );
2150 CONV_RECT32TO16( &r, (LPRECT16)lParam );
2152 return CB_OKAY;
2153 case CB_GETDROPPEDCONTROLRECT:
2154 if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam );
2155 return CB_OKAY;
2156 case CB_GETDROPPEDSTATE16:
2157 case CB_GETDROPPEDSTATE:
2158 return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE;
2159 case CB_DIR16:
2160 lParam = (LPARAM)MapSL(lParam);
2161 message = LB_DIR16;
2162 /* fall through */
2163 case CB_DIR:
2164 if(message == CB_DIR) message = LB_DIR;
2165 return unicode ? SendMessageW(lphc->hWndLBox, message, wParam, lParam) :
2166 SendMessageA(lphc->hWndLBox, message, wParam, lParam);
2168 case CB_SHOWDROPDOWN16:
2169 case CB_SHOWDROPDOWN:
2170 if( CB_GETTYPE(lphc) != CBS_SIMPLE )
2172 if( wParam )
2174 if( !(lphc->wState & CBF_DROPPED) )
2175 CBDropDown( lphc );
2177 else
2178 if( lphc->wState & CBF_DROPPED )
2179 CBRollUp( lphc, FALSE, TRUE );
2181 return TRUE;
2182 case CB_GETCOUNT16:
2183 case CB_GETCOUNT:
2184 return SendMessageW(lphc->hWndLBox, LB_GETCOUNT, 0, 0);
2185 case CB_GETCURSEL16:
2186 case CB_GETCURSEL:
2187 return SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0);
2188 case CB_SETCURSEL16:
2189 wParam = (INT)(INT16)wParam;
2190 /* fall through */
2191 case CB_SETCURSEL:
2192 lParam = SendMessageW(lphc->hWndLBox, LB_SETCURSEL, wParam, 0);
2193 if( lParam >= 0 )
2194 SendMessageW(lphc->hWndLBox, LB_SETTOPINDEX, wParam, 0);
2196 /* no LBN_SELCHANGE in this case, update manually */
2197 if( lphc->wState & CBF_EDIT )
2198 CBUpdateEdit( lphc, (INT)wParam );
2199 else
2200 InvalidateRect(CB_HWND(lphc), &lphc->textRect, TRUE);
2201 lphc->wState &= ~CBF_SELCHANGE;
2202 return lParam;
2203 case CB_GETLBTEXT16:
2204 wParam = (INT)(INT16)wParam;
2205 lParam = (LPARAM)MapSL(lParam);
2206 /* fall through */
2207 case CB_GETLBTEXT:
2208 return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXT, wParam, lParam) :
2209 SendMessageA(lphc->hWndLBox, LB_GETTEXT, wParam, lParam);
2210 case CB_GETLBTEXTLEN16:
2211 wParam = (INT)(INT16)wParam;
2212 /* fall through */
2213 case CB_GETLBTEXTLEN:
2214 return SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0);
2215 case CB_GETITEMDATA16:
2216 wParam = (INT)(INT16)wParam;
2217 /* fall through */
2218 case CB_GETITEMDATA:
2219 return SendMessageW(lphc->hWndLBox, LB_GETITEMDATA, wParam, 0);
2220 case CB_SETITEMDATA16:
2221 wParam = (INT)(INT16)wParam;
2222 /* fall through */
2223 case CB_SETITEMDATA:
2224 return SendMessageW(lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam);
2225 case CB_GETEDITSEL16:
2226 wParam = lParam = 0; /* just in case */
2227 /* fall through */
2228 case CB_GETEDITSEL:
2229 /* Edit checks passed parameters itself */
2230 if( lphc->wState & CBF_EDIT )
2231 return SendMessageW(lphc->hWndEdit, EM_GETSEL, wParam, lParam);
2232 return CB_ERR;
2233 case CB_SETEDITSEL16:
2234 case CB_SETEDITSEL:
2235 if( lphc->wState & CBF_EDIT )
2236 return SendMessageW(lphc->hWndEdit, EM_SETSEL,
2237 (INT)(INT16)LOWORD(lParam), (INT)(INT16)HIWORD(lParam) );
2238 return CB_ERR;
2239 case CB_SETEXTENDEDUI16:
2240 case CB_SETEXTENDEDUI:
2241 if( CB_GETTYPE(lphc) == CBS_SIMPLE )
2242 return CB_ERR;
2243 if( wParam )
2244 lphc->wState |= CBF_EUI;
2245 else lphc->wState &= ~CBF_EUI;
2246 return CB_OKAY;
2247 case CB_GETEXTENDEDUI16:
2248 case CB_GETEXTENDEDUI:
2249 return (lphc->wState & CBF_EUI) ? TRUE : FALSE;
2251 default:
2252 if (message >= WM_USER)
2253 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2254 message - WM_USER, wParam, lParam );
2255 break;
2257 return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
2258 DefWindowProcA(hwnd, message, wParam, lParam);
2260 return CB_ERR;
2263 /***********************************************************************
2264 * ComboWndProcA
2266 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2267 * window structs.
2269 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2271 WND* pWnd = WIN_FindWndPtr(hwnd);
2272 LRESULT retvalue = ComboWndProc_locked(pWnd, message, wParam, lParam, FALSE);
2274 WIN_ReleaseWndPtr(pWnd);
2275 return retvalue;
2278 /***********************************************************************
2279 * ComboWndProcW
2281 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
2283 WND* pWnd = WIN_FindWndPtr(hwnd);
2284 LRESULT retvalue = ComboWndProc_locked(pWnd, message, wParam, lParam, TRUE);
2286 WIN_ReleaseWndPtr(pWnd);
2287 return retvalue;