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 * FIXME: roll up in Netscape 3.01.
27 WINE_DEFAULT_DEBUG_CHANNEL(combo
);
29 /* bits in the dwKeyData */
30 #define KEYDATA_ALT 0x2000
31 #define KEYDATA_PREVSTATE 0x4000
34 * Additional combo box definitions
37 #define CB_NOTIFY( lphc, code ) \
38 (SendMessageW((lphc)->owner, WM_COMMAND, \
39 MAKEWPARAM(GetWindowLongA((lphc)->self,GWL_ID), (code)), (LPARAM)(lphc)->self))
41 #define CB_DISABLED( lphc ) (!IsWindowEnabled((lphc)->self))
42 #define CB_OWNERDRAWN( lphc ) ((lphc)->dwStyle & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE))
43 #define CB_HASSTRINGS( lphc ) ((lphc)->dwStyle & CBS_HASSTRINGS)
44 #define CB_HWND( lphc ) ((lphc)->self)
46 #define ISWIN31 (LOWORD(GetVersion()) == 0x0a03)
51 static HBITMAP hComboBmp
= 0;
52 static UINT CBitHeight
, CBitWidth
;
55 * Look and feel dependent "constants"
58 #define COMBO_YBORDERGAP 5
59 #define COMBO_XBORDERSIZE() 2
60 #define COMBO_YBORDERSIZE() 2
61 #define COMBO_EDITBUTTONSPACE() 0
62 #define EDIT_CONTROL_PADDING() 1
64 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
65 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
67 /*********************************************************************
68 * combo class descriptor
70 const struct builtin_class_descr COMBO_builtin_class
=
73 L
"ComboBox", /* name */
74 CS_PARENTDC
| CS_VREDRAW
| CS_HREDRAW
| CS_DBLCLKS
, /* style */
75 (WNDPROC
) ComboWndProcW
, /* procW */
76 (WNDPROC
) ComboWndProcA
, /* procA */
77 sizeof(HEADCOMBO
*), /* extra */
78 (LPCWSTR
) IDC_ARROW
, /* cursor */
81 "ComboBox", /* name */
82 CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
, /* style */
83 ComboWndProcA
, /* procA */
84 ComboWndProcW
, /* procW */
85 sizeof(HEADCOMBO
*), /* extra */
86 IDC_ARROW
, /* cursor */
92 /***********************************************************************
95 * Load combo button bitmap.
97 static BOOL
COMBO_Init()
101 if( hComboBmp
) return TRUE
;
102 if( (hDC
= CreateCompatibleDC(0)) )
105 if( (hComboBmp
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_COMBO
))) )
111 GetObjectW( hComboBmp
, sizeof(bm
), &bm
);
112 CBitHeight
= bm
.bmHeight
;
113 CBitWidth
= bm
.bmWidth
;
115 TRACE("combo bitmap [%i,%i]\n", CBitWidth
, CBitHeight
);
117 hPrevB
= SelectObject( hDC
, hComboBmp
);
118 SetRect( &r
, 0, 0, CBitWidth
, CBitHeight
);
119 InvertRect( hDC
, &r
);
120 SelectObject( hDC
, hPrevB
);
129 /***********************************************************************
132 static LRESULT
COMBO_NCCreate(HWND hwnd
, LONG style
)
136 if (COMBO_Init() && (lphc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HEADCOMBO
))) )
139 SetWindowLongA( hwnd
, 0, (LONG
)lphc
);
141 /* some braindead apps do try to use scrollbar/border flags */
143 lphc
->dwStyle
= style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
);
144 SetWindowLongA( hwnd
, GWL_STYLE
, style
& ~(WS_BORDER
| WS_HSCROLL
| WS_VSCROLL
) );
147 * We also have to remove the client edge style to make sure
148 * we don't end-up with a non client area.
150 SetWindowLongA( hwnd
, GWL_EXSTYLE
,
151 GetWindowLongA( hwnd
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
153 if( !(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) )
154 lphc
->dwStyle
|= CBS_HASSTRINGS
;
155 if( !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) )
156 lphc
->wState
|= CBF_NOTIFY
;
158 TRACE("[%p], style = %08x\n", lphc
, lphc
->dwStyle
);
164 /***********************************************************************
167 static LRESULT
COMBO_NCDestroy( LPHEADCOMBO lphc
)
172 TRACE("[%p]: freeing storage\n", lphc
->self
);
174 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) && lphc
->hWndLBox
)
175 DestroyWindow( lphc
->hWndLBox
);
177 SetWindowLongA( lphc
->self
, 0, 0 );
178 HeapFree( GetProcessHeap(), 0, lphc
);
183 /***********************************************************************
184 * CBGetTextAreaHeight
186 * This method will calculate the height of the text area of the
188 * The height of the text area is set in two ways.
189 * It can be set explicitly through a combobox message or through a
190 * WM_MEASUREITEM callback.
191 * If this is not the case, the height is set to 13 dialog units.
192 * This height was determined through experimentation.
194 static INT
CBGetTextAreaHeight(
200 if( lphc
->editHeight
) /* explicitly set height */
202 iTextItemHeight
= lphc
->editHeight
;
207 HDC hDC
= GetDC(hwnd
);
212 hPrevFont
= SelectObject( hDC
, lphc
->hFont
);
214 GetTextMetricsW(hDC
, &tm
);
216 baseUnitY
= tm
.tmHeight
;
219 SelectObject( hDC
, hPrevFont
);
221 ReleaseDC(hwnd
, hDC
);
223 iTextItemHeight
= ((13 * baseUnitY
) / 8);
226 * This "formula" calculates the height of the complete control.
227 * To calculate the height of the text area, we have to remove the
230 iTextItemHeight
-= 2*COMBO_YBORDERSIZE();
234 * Check the ownerdraw case if we haven't asked the parent the size
237 if ( CB_OWNERDRAWN(lphc
) &&
238 (lphc
->wState
& CBF_MEASUREITEM
) )
240 MEASUREITEMSTRUCT measureItem
;
242 INT originalItemHeight
= iTextItemHeight
;
243 UINT id
= GetWindowLongA( lphc
->self
, GWL_ID
);
246 * We use the client rect for the width of the item.
248 GetClientRect(hwnd
, &clientRect
);
250 lphc
->wState
&= ~CBF_MEASUREITEM
;
253 * Send a first one to measure the size of the text area
255 measureItem
.CtlType
= ODT_COMBOBOX
;
256 measureItem
.CtlID
= id
;
257 measureItem
.itemID
= -1;
258 measureItem
.itemWidth
= clientRect
.right
;
259 measureItem
.itemHeight
= iTextItemHeight
- 6; /* ownerdrawn cb is taller */
260 measureItem
.itemData
= 0;
261 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
262 iTextItemHeight
= 6 + measureItem
.itemHeight
;
265 * Send a second one in the case of a fixed ownerdraw list to calculate the
266 * size of the list items. (we basically do this on behalf of the listbox)
268 if (lphc
->dwStyle
& CBS_OWNERDRAWFIXED
)
270 measureItem
.CtlType
= ODT_COMBOBOX
;
271 measureItem
.CtlID
= id
;
272 measureItem
.itemID
= 0;
273 measureItem
.itemWidth
= clientRect
.right
;
274 measureItem
.itemHeight
= originalItemHeight
;
275 measureItem
.itemData
= 0;
276 SendMessageW(lphc
->owner
, WM_MEASUREITEM
, id
, (LPARAM
)&measureItem
);
277 lphc
->fixedOwnerDrawHeight
= measureItem
.itemHeight
;
281 * Keep the size for the next time
283 lphc
->editHeight
= iTextItemHeight
;
286 return iTextItemHeight
;
289 /***********************************************************************
292 * The dummy resize is used for listboxes that have a popup to trigger
293 * a re-arranging of the contents of the combobox and the recalculation
294 * of the size of the "real" control window.
296 static void CBForceDummyResize(
302 newComboHeight
= CBGetTextAreaHeight(lphc
->self
,lphc
) + 2*COMBO_YBORDERSIZE();
304 GetWindowRect(lphc
->self
, &windowRect
);
307 * We have to be careful, resizing a combobox also has the meaning that the
308 * dropped rect will be resized. In this case, we want to trigger a resize
309 * to recalculate layout but we don't want to change the dropped rectangle
310 * So, we pass the height of text area of control as the height.
311 * this will cancel-out in the processing of the WM_WINDOWPOSCHANGING
314 SetWindowPos( lphc
->self
,
317 windowRect
.right
- windowRect
.left
,
319 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
322 /***********************************************************************
325 * Set up component coordinates given valid lphc->RectCombo.
327 static void CBCalcPlacement(
335 * Again, start with the client rectangle.
337 GetClientRect(hwnd
, lprEdit
);
342 InflateRect(lprEdit
, -COMBO_XBORDERSIZE(), -COMBO_YBORDERSIZE());
345 * Chop off the bottom part to fit with the height of the text area.
347 lprEdit
->bottom
= lprEdit
->top
+ CBGetTextAreaHeight(hwnd
, lphc
);
350 * The button starts the same vertical position as the text area.
352 CopyRect(lprButton
, lprEdit
);
355 * If the combobox is "simple" there is no button.
357 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
358 lprButton
->left
= lprButton
->right
= lprButton
->bottom
= 0;
362 * Let's assume the combobox button is the same width as the
364 * size the button horizontally and cut-off the text area.
366 lprButton
->left
= lprButton
->right
- GetSystemMetrics(SM_CXVSCROLL
);
367 lprEdit
->right
= lprButton
->left
;
371 * In the case of a dropdown, there is an additional spacing between the
372 * text area and the button.
374 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
376 lprEdit
->right
-= COMBO_EDITBUTTONSPACE();
380 * If we have an edit control, we space it away from the borders slightly.
382 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
384 InflateRect(lprEdit
, -EDIT_CONTROL_PADDING(), -EDIT_CONTROL_PADDING());
388 * Adjust the size of the listbox popup.
390 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
393 * Use the client rectangle to initialize the listbox rectangle
395 GetClientRect(hwnd
, lprLB
);
398 * Then, chop-off the top part.
400 lprLB
->top
= lprEdit
->bottom
+ COMBO_YBORDERSIZE();
405 * Make sure the dropped width is as large as the combobox itself.
407 if (lphc
->droppedWidth
< (lprButton
->right
+ COMBO_XBORDERSIZE()))
409 lprLB
->right
= lprLB
->left
+ (lprButton
->right
+ COMBO_XBORDERSIZE());
412 * In the case of a dropdown, the popup listbox is offset to the right.
413 * so, we want to make sure it's flush with the right side of the
416 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
417 lprLB
->right
-= COMBO_EDITBUTTONSPACE();
420 lprLB
->right
= lprLB
->left
+ lphc
->droppedWidth
;
423 TRACE("\ttext\t= (%ld,%ld-%ld,%ld)\n",
424 lprEdit
->left
, lprEdit
->top
, lprEdit
->right
, lprEdit
->bottom
);
426 TRACE("\tbutton\t= (%ld,%ld-%ld,%ld)\n",
427 lprButton
->left
, lprButton
->top
, lprButton
->right
, lprButton
->bottom
);
429 TRACE("\tlbox\t= (%ld,%ld-%ld,%ld)\n",
430 lprLB
->left
, lprLB
->top
, lprLB
->right
, lprLB
->bottom
);
433 /***********************************************************************
434 * CBGetDroppedControlRect
436 static void CBGetDroppedControlRect( LPHEADCOMBO lphc
, LPRECT lpRect
)
438 /* In windows, CB_GETDROPPEDCONTROLRECT returns the upper left corner
439 of the combo box and the lower right corner of the listbox */
441 GetWindowRect(lphc
->self
, lpRect
);
443 lpRect
->right
= lpRect
->left
+ lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
444 lpRect
->bottom
= lpRect
->top
+ lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
448 /***********************************************************************
449 * COMBO_WindowPosChanging
451 static LRESULT
COMBO_WindowPosChanging(
454 WINDOWPOS
* posChanging
)
457 * We need to override the WM_WINDOWPOSCHANGING method to handle all
458 * the non-simple comboboxes. The problem is that those controls are
459 * always the same height. We have to make sure they are not resized
462 if ( ( CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
463 ((posChanging
->flags
& SWP_NOSIZE
) == 0) )
467 newComboHeight
= CBGetTextAreaHeight(hwnd
,lphc
) +
468 2*COMBO_YBORDERSIZE();
471 * Resizing a combobox has another side effect, it resizes the dropped
472 * rectangle as well. However, it does it only if the new height for the
473 * combobox is different from the height it should have. In other words,
474 * if the application resizing the combobox only had the intention to resize
475 * the actual control, for example, to do the layout of a dialog that is
476 * resized, the height of the dropdown is not changed.
478 if (posChanging
->cy
!= newComboHeight
)
480 TRACE("posChanging->cy=%d, newComboHeight=%d, oldbot=%ld, oldtop=%ld\n",
481 posChanging
->cy
, newComboHeight
, lphc
->droppedRect
.bottom
,
482 lphc
->droppedRect
.top
);
483 lphc
->droppedRect
.bottom
= lphc
->droppedRect
.top
+ posChanging
->cy
- newComboHeight
;
485 posChanging
->cy
= newComboHeight
;
492 /***********************************************************************
495 static LRESULT
COMBO_Create( HWND hwnd
, LPHEADCOMBO lphc
, HWND hwndParent
, LONG style
,
498 static const WCHAR clbName
[] = {'C','o','m','b','o','L','B','o','x',0};
499 static const WCHAR editName
[] = {'E','d','i','t',0};
501 if( !CB_GETTYPE(lphc
) ) lphc
->dwStyle
|= CBS_SIMPLE
;
502 if( CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
) lphc
->wState
|= CBF_EDIT
;
504 lphc
->owner
= hwndParent
;
507 * The item height and dropped width are not set when the control
510 lphc
->droppedWidth
= lphc
->editHeight
= 0;
513 * The first time we go through, we want to measure the ownerdraw item
515 lphc
->wState
|= CBF_MEASUREITEM
;
517 /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */
519 if( lphc
->owner
|| !(style
& WS_VISIBLE
) )
525 * Initialize the dropped rect to the size of the client area of the
526 * control and then, force all the areas of the combobox to be
529 GetClientRect( hwnd
, &lphc
->droppedRect
);
530 CBCalcPlacement(hwnd
, lphc
, &lphc
->textRect
, &lphc
->buttonRect
, &lphc
->droppedRect
);
533 * Adjust the position of the popup listbox if it's necessary
535 if ( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
537 lphc
->droppedRect
.top
= lphc
->textRect
.bottom
+ COMBO_YBORDERSIZE();
540 * If it's a dropdown, the listbox is offset
542 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
543 lphc
->droppedRect
.left
+= COMBO_EDITBUTTONSPACE();
545 ClientToScreen(hwnd
, (LPPOINT
)&lphc
->droppedRect
);
546 ClientToScreen(hwnd
, (LPPOINT
)&lphc
->droppedRect
.right
);
549 /* create listbox popup */
551 lbeStyle
= (LBS_NOTIFY
| LBS_COMBOBOX
| WS_BORDER
| WS_CLIPSIBLINGS
| WS_CHILD
) |
552 (style
& (WS_VSCROLL
| CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
));
554 if( lphc
->dwStyle
& CBS_SORT
)
555 lbeStyle
|= LBS_SORT
;
556 if( lphc
->dwStyle
& CBS_HASSTRINGS
)
557 lbeStyle
|= LBS_HASSTRINGS
;
558 if( lphc
->dwStyle
& CBS_NOINTEGRALHEIGHT
)
559 lbeStyle
|= LBS_NOINTEGRALHEIGHT
;
560 if( lphc
->dwStyle
& CBS_DISABLENOSCROLL
)
561 lbeStyle
|= LBS_DISABLENOSCROLL
;
563 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
) /* child listbox */
565 lbeStyle
|= WS_VISIBLE
;
568 * In win 95 look n feel, the listbox in the simple combobox has
569 * the WS_EXCLIENTEDGE style instead of the WS_BORDER style.
571 lbeStyle
&= ~WS_BORDER
;
572 lbeExStyle
|= WS_EX_CLIENTEDGE
;
576 lbeExStyle
|= (WS_EX_TOPMOST
| WS_EX_TOOLWINDOW
);
580 lphc
->hWndLBox
= CreateWindowExW(lbeExStyle
, clbName
, NULL
, lbeStyle
,
581 lphc
->droppedRect
.left
,
582 lphc
->droppedRect
.top
,
583 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
584 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
585 hwnd
, (HMENU
)ID_CB_LISTBOX
,
586 (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
), lphc
);
588 lphc
->hWndLBox
= CreateWindowExA(lbeExStyle
, "ComboLBox", NULL
, lbeStyle
,
589 lphc
->droppedRect
.left
,
590 lphc
->droppedRect
.top
,
591 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
592 lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
,
593 hwnd
, (HMENU
)ID_CB_LISTBOX
,
594 (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
), lphc
);
599 lbeStyle
= WS_CHILD
| WS_VISIBLE
| ES_NOHIDESEL
| ES_LEFT
| ES_COMBO
;
601 if( lphc
->wState
& CBF_EDIT
)
603 if( lphc
->dwStyle
& CBS_OEMCONVERT
)
604 lbeStyle
|= ES_OEMCONVERT
;
605 if( lphc
->dwStyle
& CBS_AUTOHSCROLL
)
606 lbeStyle
|= ES_AUTOHSCROLL
;
607 if( lphc
->dwStyle
& CBS_LOWERCASE
)
608 lbeStyle
|= ES_LOWERCASE
;
609 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
610 lbeStyle
|= ES_UPPERCASE
;
612 if (!IsWindowEnabled(hwnd
)) lbeStyle
|= WS_DISABLED
;
615 lphc
->hWndEdit
= CreateWindowExW(0, editName
, NULL
, lbeStyle
,
616 lphc
->textRect
.left
, lphc
->textRect
.top
,
617 lphc
->textRect
.right
- lphc
->textRect
.left
,
618 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
619 hwnd
, (HMENU
)ID_CB_EDIT
,
620 (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
), NULL
);
622 lphc
->hWndEdit
= CreateWindowExA(0, "Edit", NULL
, lbeStyle
,
623 lphc
->textRect
.left
, lphc
->textRect
.top
,
624 lphc
->textRect
.right
- lphc
->textRect
.left
,
625 lphc
->textRect
.bottom
- lphc
->textRect
.top
,
626 hwnd
, (HMENU
)ID_CB_EDIT
,
627 (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
), NULL
);
629 if( !lphc
->hWndEdit
)
635 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
637 /* Now do the trick with parent */
638 SetParent(lphc
->hWndLBox
, HWND_DESKTOP
);
640 * If the combo is a dropdown, we must resize the control
641 * to fit only the text area and button. To do this,
642 * we send a dummy resize and the WM_WINDOWPOSCHANGING message
643 * will take care of setting the height for us.
645 CBForceDummyResize(lphc
);
648 TRACE("init done\n");
651 ERR("edit control failure.\n");
652 } else ERR("listbox failure.\n");
653 } else ERR("no owner for visible combo.\n");
655 /* CreateWindow() will send WM_NCDESTROY to cleanup */
660 /***********************************************************************
663 * Paint combo button (normal, pressed, and disabled states).
665 static void CBPaintButton( LPHEADCOMBO lphc
, HDC hdc
, RECT rectButton
)
667 UINT buttonState
= DFCS_SCROLLCOMBOBOX
;
669 if( lphc
->wState
& CBF_NOREDRAW
)
673 if (lphc
->wState
& CBF_BUTTONDOWN
)
674 buttonState
|= DFCS_PUSHED
;
676 if (CB_DISABLED(lphc
))
677 buttonState
|= DFCS_INACTIVE
;
679 DrawFrameControl(hdc
, &rectButton
, DFC_SCROLL
, buttonState
);
682 /***********************************************************************
685 * Paint CBS_DROPDOWNLIST text field / update edit control contents.
687 static void CBPaintText(
695 if( lphc
->wState
& CBF_NOREDRAW
) return;
699 /* follow Windows combobox that sends a bunch of text
700 * inquiries to its listbox while processing WM_PAINT. */
702 if( (id
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0) ) != LB_ERR
)
704 size
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, id
, 0);
706 FIXME("LB_ERR probably not handled yet\n");
707 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (size
+ 1) * sizeof(WCHAR
))) )
709 /* size from LB_GETTEXTLEN may be too large, from LB_GETTEXT is accurate */
710 size
=SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, (WPARAM
)id
, (LPARAM
)pText
);
711 pText
[size
] = '\0'; /* just in case */
715 if( !CB_OWNERDRAWN(lphc
) )
718 if( lphc
->wState
& CBF_EDIT
)
720 static const WCHAR empty_stringW
[] = { 0 };
721 if( CB_HASSTRINGS(lphc
) ) SetWindowTextW( lphc
->hWndEdit
, pText
? pText
: empty_stringW
);
722 if( lphc
->wState
& CBF_FOCUSED
)
723 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
725 else /* paint text field ourselves */
727 UINT itemState
= ODS_COMBOBOXEDIT
;
728 HFONT hPrevFont
= (lphc
->hFont
) ? SelectObject(hdc
, lphc
->hFont
) : 0;
731 * Give ourselves some space.
733 InflateRect( &rectEdit
, -1, -1 );
735 if( CB_OWNERDRAWN(lphc
) )
739 UINT ctlid
= GetWindowLongA( lphc
->self
, GWL_ID
);
741 /* setup state for DRAWITEM message. Owner will highlight */
742 if ( (lphc
->wState
& CBF_FOCUSED
) &&
743 !(lphc
->wState
& CBF_DROPPED
) )
744 itemState
|= ODS_SELECTED
| ODS_FOCUS
;
747 * Save the current clip region.
748 * To retrieve the clip region, we need to create one "dummy"
751 clipRegion
= CreateRectRgnIndirect(&rectEdit
);
753 if (GetClipRgn(hdc
, clipRegion
)!=1)
755 DeleteObject(clipRegion
);
759 if (!IsWindowEnabled(lphc
->self
) & WS_DISABLED
) itemState
|= ODS_DISABLED
;
761 dis
.CtlType
= ODT_COMBOBOX
;
763 dis
.hwndItem
= lphc
->self
;
764 dis
.itemAction
= ODA_DRAWENTIRE
;
766 dis
.itemState
= itemState
;
768 dis
.rcItem
= rectEdit
;
769 dis
.itemData
= SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
,
773 * Clip the DC and have the parent draw the item.
775 IntersectClipRect(hdc
,
776 rectEdit
.left
, rectEdit
.top
,
777 rectEdit
.right
, rectEdit
.bottom
);
779 SendMessageW(lphc
->owner
, WM_DRAWITEM
, ctlid
, (LPARAM
)&dis
);
782 * Reset the clipping region.
784 SelectClipRgn(hdc
, clipRegion
);
788 static const WCHAR empty_stringW
[] = { 0 };
790 if ( (lphc
->wState
& CBF_FOCUSED
) &&
791 !(lphc
->wState
& CBF_DROPPED
) ) {
794 FillRect( hdc
, &rectEdit
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
795 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
796 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
802 ETO_OPAQUE
| ETO_CLIPPED
,
804 pText
? pText
: empty_stringW
, size
, NULL
);
806 if(lphc
->wState
& CBF_FOCUSED
&& !(lphc
->wState
& CBF_DROPPED
))
807 DrawFocusRect( hdc
, &rectEdit
);
811 SelectObject(hdc
, hPrevFont
);
814 HeapFree( GetProcessHeap(), 0, pText
);
817 /***********************************************************************
820 static void CBPaintBorder(
827 if (CB_GETTYPE(lphc
) != CBS_SIMPLE
)
829 GetClientRect(hwnd
, &clientRect
);
833 CopyRect(&clientRect
, &lphc
->textRect
);
835 InflateRect(&clientRect
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
836 InflateRect(&clientRect
, COMBO_XBORDERSIZE(), COMBO_YBORDERSIZE());
839 DrawEdge(hdc
, &clientRect
, EDGE_SUNKEN
, BF_RECT
);
842 /***********************************************************************
843 * COMBO_PrepareColors
845 * This method will sent the appropriate WM_CTLCOLOR message to
846 * prepare and setup the colors for the combo's DC.
848 * It also returns the brush to use for the background.
850 static HBRUSH
COMBO_PrepareColors(
857 * Get the background brush for this control.
859 if (CB_DISABLED(lphc
))
861 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORSTATIC
,
862 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
865 * We have to change the text color since WM_CTLCOLORSTATIC will
866 * set it to the "enabled" color. This is the same behavior as the
869 SetTextColor(hDC
, GetSysColor(COLOR_GRAYTEXT
));
873 if (lphc
->wState
& CBF_EDIT
)
875 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLOREDIT
,
876 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
880 hBkgBrush
= (HBRUSH
)SendMessageW(lphc
->owner
, WM_CTLCOLORLISTBOX
,
881 (WPARAM
)hDC
, (LPARAM
)lphc
->self
);
889 hBkgBrush
= GetSysColorBrush(COLOR_WINDOW
);
894 /***********************************************************************
895 * COMBO_EraseBackground
897 static LRESULT
COMBO_EraseBackground(
905 if(lphc
->wState
& CBF_EDIT
)
908 hDC
= (hParamDC
) ? hParamDC
911 * Retrieve the background brush
913 hBkgBrush
= COMBO_PrepareColors(lphc
, hDC
);
915 FillRect(hDC
, &lphc
->textRect
, hBkgBrush
);
918 ReleaseDC(hwnd
, hDC
);
923 /***********************************************************************
926 static LRESULT
COMBO_Paint(LPHEADCOMBO lphc
, HDC hParamDC
)
931 hDC
= (hParamDC
) ? hParamDC
932 : BeginPaint( lphc
->self
, &ps
);
934 TRACE("hdc=%p\n", hDC
);
936 if( hDC
&& !(lphc
->wState
& CBF_NOREDRAW
) )
938 HBRUSH hPrevBrush
, hBkgBrush
;
941 * Retrieve the background brush and select it in the
944 hBkgBrush
= COMBO_PrepareColors(lphc
, hDC
);
946 hPrevBrush
= SelectObject( hDC
, hBkgBrush
);
949 * In non 3.1 look, there is a sunken border on the combobox
951 CBPaintBorder(lphc
->self
, lphc
, hDC
);
953 if( !IsRectEmpty(&lphc
->buttonRect
) )
955 CBPaintButton(lphc
, hDC
, lphc
->buttonRect
);
958 /* paint the edit control padding area */
959 if (CB_GETTYPE(lphc
) != CBS_DROPDOWNLIST
)
961 RECT rPadEdit
= lphc
->textRect
;
963 InflateRect(&rPadEdit
, EDIT_CONTROL_PADDING(), EDIT_CONTROL_PADDING());
965 FrameRect( hDC
, &rPadEdit
, GetSysColorBrush(COLOR_WINDOW
) );
968 if( !(lphc
->wState
& CBF_EDIT
) )
969 CBPaintText( lphc
, hDC
, lphc
->textRect
);
972 SelectObject( hDC
, hPrevBrush
);
976 EndPaint(lphc
->self
, &ps
);
981 /***********************************************************************
984 * Select listbox entry according to the contents of the edit control.
986 static INT
CBUpdateLBox( LPHEADCOMBO lphc
, BOOL bSelect
)
992 length
= SendMessageW( lphc
->hWndEdit
, WM_GETTEXTLENGTH
, 0, 0 );
995 pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
997 TRACE("\t edit text length %i\n", length
);
1001 if( length
) GetWindowTextW( lphc
->hWndEdit
, pText
, length
+ 1);
1002 else pText
[0] = '\0';
1003 idx
= SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
,
1004 (WPARAM
)(-1), (LPARAM
)pText
);
1005 HeapFree( GetProcessHeap(), 0, pText
);
1008 SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, (WPARAM
)(bSelect
? idx
: -1), 0);
1010 /* probably superfluous but Windows sends this too */
1011 SendMessageW(lphc
->hWndLBox
, LB_SETCARETINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
1012 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, (WPARAM
)(idx
< 0 ? 0 : idx
), 0);
1017 /***********************************************************************
1020 * Copy a listbox entry to the edit control.
1022 static void CBUpdateEdit( LPHEADCOMBO lphc
, INT index
)
1025 LPWSTR pText
= NULL
;
1026 static const WCHAR empty_stringW
[] = { 0 };
1028 TRACE("\t %i\n", index
);
1030 if( index
>= 0 ) /* got an entry */
1032 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, (WPARAM
)index
, 0);
1033 if( length
!= LB_ERR
)
1035 if( (pText
= HeapAlloc( GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
))) )
1037 SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
,
1038 (WPARAM
)index
, (LPARAM
)pText
);
1043 lphc
->wState
|= (CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1044 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, pText
? (LPARAM
)pText
: (LPARAM
)empty_stringW
);
1045 lphc
->wState
&= ~(CBF_NOEDITNOTIFY
| CBF_NOLBSELECT
);
1047 if( lphc
->wState
& CBF_FOCUSED
)
1048 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1051 HeapFree( GetProcessHeap(), 0, pText
);
1054 /***********************************************************************
1057 * Show listbox popup.
1059 static void CBDropDown( LPHEADCOMBO lphc
)
1065 TRACE("[%p]: drop down\n", lphc
->self
);
1067 CB_NOTIFY( lphc
, CBN_DROPDOWN
);
1071 lphc
->wState
|= CBF_DROPPED
;
1072 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1074 lphc
->droppedIndex
= CBUpdateLBox( lphc
, TRUE
);
1076 /* Update edit only if item is in the list */
1077 if( !(lphc
->wState
& CBF_CAPTURE
) && lphc
->droppedIndex
>= 0)
1078 CBUpdateEdit( lphc
, lphc
->droppedIndex
);
1082 lphc
->droppedIndex
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1084 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
,
1085 (WPARAM
)(lphc
->droppedIndex
== LB_ERR
? 0 : lphc
->droppedIndex
), 0 );
1086 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1089 /* now set popup position */
1090 GetWindowRect( lphc
->self
, &rect
);
1093 * If it's a dropdown, the listbox is offset
1095 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1096 rect
.left
+= COMBO_EDITBUTTONSPACE();
1098 /* if the dropped height is greater than the total height of the dropped
1099 items list, then force the drop down list height to be the total height
1100 of the items in the dropped list */
1102 /* And Remove any extra space (Best Fit) */
1103 nDroppedHeight
= lphc
->droppedRect
.bottom
- lphc
->droppedRect
.top
;
1104 /* if listbox length has been set directly by its handle */
1105 GetWindowRect(lphc
->hWndLBox
, &r
);
1106 if (nDroppedHeight
< r
.bottom
- r
.top
)
1107 nDroppedHeight
= r
.bottom
- r
.top
;
1108 nItems
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
1115 nIHeight
= (int)SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, 0, 0);
1117 nHeight
= nIHeight
*nItems
;
1119 if (nHeight
< nDroppedHeight
- COMBO_YBORDERSIZE())
1120 nDroppedHeight
= nHeight
+ COMBO_YBORDERSIZE();
1122 if (nDroppedHeight
< nIHeight
)
1125 nDroppedHeight
= (nItems
+1)*nIHeight
;
1127 nDroppedHeight
= 6*nIHeight
;
1131 /*If height of dropped rectangle gets beyond a screen size it should go up, otherwise down.*/
1132 if( (rect
.bottom
+ nDroppedHeight
) >= GetSystemMetrics( SM_CYSCREEN
) )
1133 rect
.bottom
= rect
.top
- nDroppedHeight
;
1135 SetWindowPos( lphc
->hWndLBox
, HWND_TOP
, rect
.left
, rect
.bottom
,
1136 lphc
->droppedRect
.right
- lphc
->droppedRect
.left
,
1138 SWP_NOACTIVATE
| SWP_SHOWWINDOW
);
1141 if( !(lphc
->wState
& CBF_NOREDRAW
) )
1142 RedrawWindow( lphc
->self
, NULL
, 0, RDW_INVALIDATE
|
1143 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1145 EnableWindow( lphc
->hWndLBox
, TRUE
);
1146 if (GetCapture() != lphc
->self
)
1147 SetCapture(lphc
->hWndLBox
);
1150 /***********************************************************************
1153 * Hide listbox popup.
1155 static void CBRollUp( LPHEADCOMBO lphc
, BOOL ok
, BOOL bButton
)
1157 HWND hWnd
= lphc
->self
;
1159 TRACE("[%p]: sel ok? [%i] dropped? [%i]\n",
1160 lphc
->self
, (INT
)ok
, (INT
)(lphc
->wState
& CBF_DROPPED
));
1162 CB_NOTIFY( lphc
, (ok
) ? CBN_SELENDOK
: CBN_SELENDCANCEL
);
1164 if( IsWindow( hWnd
) && CB_GETTYPE(lphc
) != CBS_SIMPLE
)
1167 if( lphc
->wState
& CBF_DROPPED
)
1171 lphc
->wState
&= ~CBF_DROPPED
;
1172 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1174 if(GetCapture() == lphc
->hWndLBox
)
1179 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1181 rect
= lphc
->buttonRect
;
1192 rect
= lphc
->textRect
;
1197 if( bButton
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1198 RedrawWindow( hWnd
, &rect
, 0, RDW_INVALIDATE
|
1199 RDW_ERASE
| RDW_UPDATENOW
| RDW_NOCHILDREN
);
1200 CB_NOTIFY( lphc
, CBN_CLOSEUP
);
1205 /***********************************************************************
1208 * Used by the ComboLBox to show/hide itself in response to VK_F4, etc...
1210 BOOL
COMBO_FlipListbox( LPHEADCOMBO lphc
, BOOL ok
, BOOL bRedrawButton
)
1212 if( lphc
->wState
& CBF_DROPPED
)
1214 CBRollUp( lphc
, ok
, bRedrawButton
);
1222 /***********************************************************************
1225 static void CBRepaintButton( LPHEADCOMBO lphc
)
1227 InvalidateRect(lphc
->self
, &lphc
->buttonRect
, TRUE
);
1228 UpdateWindow(lphc
->self
);
1231 /***********************************************************************
1234 static void COMBO_SetFocus( LPHEADCOMBO lphc
)
1236 if( !(lphc
->wState
& CBF_FOCUSED
) )
1238 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1239 SendMessageW(lphc
->hWndLBox
, LB_CARETON
, 0, 0);
1241 /* This is wrong. Message sequences seem to indicate that this
1242 is set *after* the notify. */
1243 /* lphc->wState |= CBF_FOCUSED; */
1245 if( !(lphc
->wState
& CBF_EDIT
) )
1246 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1248 CB_NOTIFY( lphc
, CBN_SETFOCUS
);
1249 lphc
->wState
|= CBF_FOCUSED
;
1253 /***********************************************************************
1256 static void COMBO_KillFocus( LPHEADCOMBO lphc
)
1258 HWND hWnd
= lphc
->self
;
1260 if( lphc
->wState
& CBF_FOCUSED
)
1262 CBRollUp( lphc
, FALSE
, TRUE
);
1263 if( IsWindow( hWnd
) )
1265 if( CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
)
1266 SendMessageW(lphc
->hWndLBox
, LB_CARETOFF
, 0, 0);
1268 lphc
->wState
&= ~CBF_FOCUSED
;
1271 if( !(lphc
->wState
& CBF_EDIT
) )
1272 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1274 CB_NOTIFY( lphc
, CBN_KILLFOCUS
);
1279 /***********************************************************************
1282 static LRESULT
COMBO_Command( LPHEADCOMBO lphc
, WPARAM wParam
, HWND hWnd
)
1284 if ( lphc
->wState
& CBF_EDIT
&& lphc
->hWndEdit
== hWnd
)
1286 /* ">> 8" makes gcc generate jump-table instead of cmp ladder */
1288 switch( HIWORD(wParam
) >> 8 )
1290 case (EN_SETFOCUS
>> 8):
1292 TRACE("[%p]: edit [%p] got focus\n", lphc
->self
, lphc
->hWndEdit
);
1294 COMBO_SetFocus( lphc
);
1297 case (EN_KILLFOCUS
>> 8):
1299 TRACE("[%p]: edit [%p] lost focus\n", lphc
->self
, lphc
->hWndEdit
);
1301 /* NOTE: it seems that Windows' edit control sends an
1302 * undocumented message WM_USER + 0x1B instead of this
1303 * notification (only when it happens to be a part of
1304 * the combo). ?? - AK.
1307 COMBO_KillFocus( lphc
);
1311 case (EN_CHANGE
>> 8):
1313 * In some circumstances (when the selection of the combobox
1314 * is changed for example) we don't wans the EN_CHANGE notification
1315 * to be forwarded to the parent of the combobox. This code
1316 * checks a flag that is set in these occasions and ignores the
1319 if (lphc
->wState
& CBF_NOLBSELECT
)
1321 lphc
->wState
&= ~CBF_NOLBSELECT
;
1325 CBUpdateLBox( lphc
, lphc
->wState
& CBF_DROPPED
);
1328 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1329 CB_NOTIFY( lphc
, CBN_EDITCHANGE
);
1332 case (EN_UPDATE
>> 8):
1333 if (!(lphc
->wState
& CBF_NOEDITNOTIFY
))
1334 CB_NOTIFY( lphc
, CBN_EDITUPDATE
);
1337 case (EN_ERRSPACE
>> 8):
1338 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1341 else if( lphc
->hWndLBox
== hWnd
)
1343 switch( (short)HIWORD(wParam
) )
1346 CB_NOTIFY( lphc
, CBN_ERRSPACE
);
1350 CB_NOTIFY( lphc
, CBN_DBLCLK
);
1356 TRACE("[%p]: lbox selection change [%x]\n", lphc
->self
, lphc
->wState
);
1358 if( HIWORD(wParam
) == LBN_SELCHANGE
)
1360 if( lphc
->wState
& CBF_EDIT
)
1362 INT index
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1363 lphc
->wState
|= CBF_NOLBSELECT
;
1364 CBUpdateEdit( lphc
, index
);
1365 /* select text in edit, as Windows does */
1366 SendMessageW(lphc
->hWndEdit
, EM_SETSEL
, 0, (LPARAM
)(-1));
1369 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1372 /* do not roll up if selection is being tracked
1373 * by arrowkeys in the dropdown listbox */
1374 if( ((lphc
->wState
& CBF_DROPPED
) && !(lphc
->wState
& CBF_NOROLLUP
)) )
1376 CBRollUp( lphc
, (HIWORD(wParam
) == LBN_SELCHANGE
), TRUE
);
1378 else lphc
->wState
&= ~CBF_NOROLLUP
;
1380 CB_NOTIFY( lphc
, CBN_SELCHANGE
);
1386 /* nothing to do here since ComboLBox always resets the focus to its
1387 * combo/edit counterpart */
1394 /***********************************************************************
1397 * Fixup an ownerdrawn item operation and pass it up to the combobox owner.
1399 static LRESULT
COMBO_ItemOp( LPHEADCOMBO lphc
, UINT msg
, LPARAM lParam
)
1401 HWND hWnd
= lphc
->self
;
1402 UINT id
= GetWindowLongA( hWnd
, GWL_ID
);
1404 TRACE("[%p]: ownerdraw op %04x\n", lphc
->self
, msg
);
1410 DELETEITEMSTRUCT
*lpIS
= (DELETEITEMSTRUCT
*)lParam
;
1411 lpIS
->CtlType
= ODT_COMBOBOX
;
1413 lpIS
->hwndItem
= hWnd
;
1418 DRAWITEMSTRUCT
*lpIS
= (DRAWITEMSTRUCT
*)lParam
;
1419 lpIS
->CtlType
= ODT_COMBOBOX
;
1421 lpIS
->hwndItem
= hWnd
;
1424 case WM_COMPAREITEM
:
1426 COMPAREITEMSTRUCT
*lpIS
= (COMPAREITEMSTRUCT
*)lParam
;
1427 lpIS
->CtlType
= ODT_COMBOBOX
;
1429 lpIS
->hwndItem
= hWnd
;
1432 case WM_MEASUREITEM
:
1434 MEASUREITEMSTRUCT
*lpIS
= (MEASUREITEMSTRUCT
*)lParam
;
1435 lpIS
->CtlType
= ODT_COMBOBOX
;
1440 return SendMessageW(lphc
->owner
, msg
, id
, lParam
);
1444 /***********************************************************************
1447 static LRESULT
COMBO_GetTextW( LPHEADCOMBO lphc
, INT count
, LPWSTR buf
)
1451 if( lphc
->wState
& CBF_EDIT
)
1452 return SendMessageW( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1454 /* get it from the listbox */
1456 if (!count
|| !buf
) return 0;
1457 if( lphc
->hWndLBox
)
1459 INT idx
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1460 if (idx
== LB_ERR
) goto error
;
1461 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1462 if (length
== LB_ERR
) goto error
;
1464 /* 'length' is without the terminating character */
1465 if (length
>= count
)
1467 LPWSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) * sizeof(WCHAR
));
1468 if (!lpBuffer
) goto error
;
1469 length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1471 /* truncate if buffer is too short */
1472 if (length
!= LB_ERR
)
1474 lstrcpynW( buf
, lpBuffer
, count
);
1477 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1479 else length
= SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1481 if (length
== LB_ERR
) return 0;
1485 error
: /* error - truncate string, return zero */
1491 /***********************************************************************
1494 * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
1495 * also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
1497 static LRESULT
COMBO_GetTextA( LPHEADCOMBO lphc
, INT count
, LPSTR buf
)
1501 if( lphc
->wState
& CBF_EDIT
)
1502 return SendMessageA( lphc
->hWndEdit
, WM_GETTEXT
, count
, (LPARAM
)buf
);
1504 /* get it from the listbox */
1506 if (!count
|| !buf
) return 0;
1507 if( lphc
->hWndLBox
)
1509 INT idx
= SendMessageA(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1510 if (idx
== LB_ERR
) goto error
;
1511 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, idx
, 0 );
1512 if (length
== LB_ERR
) goto error
;
1514 /* 'length' is without the terminating character */
1515 if (length
>= count
)
1517 LPSTR lpBuffer
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1) );
1518 if (!lpBuffer
) goto error
;
1519 length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)lpBuffer
);
1521 /* truncate if buffer is too short */
1522 if (length
!= LB_ERR
)
1524 lstrcpynA( buf
, lpBuffer
, count
);
1527 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1529 else length
= SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, idx
, (LPARAM
)buf
);
1531 if (length
== LB_ERR
) return 0;
1535 error
: /* error - truncate string, return zero */
1541 /***********************************************************************
1544 * This function sets window positions according to the updated
1545 * component placement struct.
1547 static void CBResetPos(
1553 BOOL bDrop
= (CB_GETTYPE(lphc
) != CBS_SIMPLE
);
1555 /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of
1556 * sizing messages */
1558 if( lphc
->wState
& CBF_EDIT
)
1559 SetWindowPos( lphc
->hWndEdit
, 0,
1560 rectEdit
->left
, rectEdit
->top
,
1561 rectEdit
->right
- rectEdit
->left
,
1562 rectEdit
->bottom
- rectEdit
->top
,
1563 SWP_NOZORDER
| SWP_NOACTIVATE
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1565 SetWindowPos( lphc
->hWndLBox
, 0,
1566 rectLB
->left
, rectLB
->top
,
1567 rectLB
->right
- rectLB
->left
,
1568 rectLB
->bottom
- rectLB
->top
,
1569 SWP_NOACTIVATE
| SWP_NOZORDER
| ((bDrop
) ? SWP_NOREDRAW
: 0) );
1573 if( lphc
->wState
& CBF_DROPPED
)
1575 lphc
->wState
&= ~CBF_DROPPED
;
1576 ShowWindow( lphc
->hWndLBox
, SW_HIDE
);
1579 if( bRedraw
&& !(lphc
->wState
& CBF_NOREDRAW
) )
1580 RedrawWindow( lphc
->self
, NULL
, 0,
1581 RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
);
1586 /***********************************************************************
1589 static void COMBO_Size( LPHEADCOMBO lphc
)
1591 CBCalcPlacement(lphc
->self
,
1595 &lphc
->droppedRect
);
1597 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1601 /***********************************************************************
1604 static void COMBO_Font( LPHEADCOMBO lphc
, HFONT hFont
, BOOL bRedraw
)
1609 lphc
->hFont
= hFont
;
1612 * Propagate to owned windows.
1614 if( lphc
->wState
& CBF_EDIT
)
1615 SendMessageW(lphc
->hWndEdit
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1616 SendMessageW(lphc
->hWndLBox
, WM_SETFONT
, (WPARAM
)hFont
, bRedraw
);
1619 * Redo the layout of the control.
1621 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1623 CBCalcPlacement(lphc
->self
,
1627 &lphc
->droppedRect
);
1629 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1633 CBForceDummyResize(lphc
);
1638 /***********************************************************************
1639 * COMBO_SetItemHeight
1641 static LRESULT
COMBO_SetItemHeight( LPHEADCOMBO lphc
, INT index
, INT height
)
1643 LRESULT lRet
= CB_ERR
;
1645 if( index
== -1 ) /* set text field height */
1647 if( height
< 32768 )
1649 lphc
->editHeight
= height
;
1652 * Redo the layout of the control.
1654 if ( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
1656 CBCalcPlacement(lphc
->self
,
1660 &lphc
->droppedRect
);
1662 CBResetPos( lphc
, &lphc
->textRect
, &lphc
->droppedRect
, TRUE
);
1666 CBForceDummyResize(lphc
);
1672 else if ( CB_OWNERDRAWN(lphc
) ) /* set listbox item height */
1673 lRet
= SendMessageW(lphc
->hWndLBox
, LB_SETITEMHEIGHT
,
1674 (WPARAM
)index
, (LPARAM
)height
);
1678 /***********************************************************************
1679 * COMBO_SelectString
1681 static LRESULT
COMBO_SelectString( LPHEADCOMBO lphc
, INT start
, LPARAM pText
, BOOL unicode
)
1683 INT index
= unicode
? SendMessageW(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
) :
1684 SendMessageA(lphc
->hWndLBox
, LB_SELECTSTRING
, (WPARAM
)start
, pText
);
1687 if( lphc
->wState
& CBF_EDIT
)
1688 CBUpdateEdit( lphc
, index
);
1691 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
1694 return (LRESULT
)index
;
1697 /***********************************************************************
1700 static void COMBO_LButtonDown( LPHEADCOMBO lphc
, LPARAM lParam
)
1704 HWND hWnd
= lphc
->self
;
1706 pt
.x
= LOWORD(lParam
);
1707 pt
.y
= HIWORD(lParam
);
1708 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1710 if( (CB_GETTYPE(lphc
) == CBS_DROPDOWNLIST
) ||
1711 (bButton
&& (CB_GETTYPE(lphc
) == CBS_DROPDOWN
)) )
1713 lphc
->wState
|= CBF_BUTTONDOWN
;
1714 if( lphc
->wState
& CBF_DROPPED
)
1716 /* got a click to cancel selection */
1718 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1719 CBRollUp( lphc
, TRUE
, FALSE
);
1720 if( !IsWindow( hWnd
) ) return;
1722 if( lphc
->wState
& CBF_CAPTURE
)
1724 lphc
->wState
&= ~CBF_CAPTURE
;
1730 /* drop down the listbox and start tracking */
1732 lphc
->wState
|= CBF_CAPTURE
;
1736 if( bButton
) CBRepaintButton( lphc
);
1740 /***********************************************************************
1743 * Release capture and stop tracking if needed.
1745 static void COMBO_LButtonUp( LPHEADCOMBO lphc
)
1747 if( lphc
->wState
& CBF_CAPTURE
)
1749 lphc
->wState
&= ~CBF_CAPTURE
;
1750 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
)
1752 INT index
= CBUpdateLBox( lphc
, TRUE
);
1753 /* Update edit only if item is in the list */
1756 lphc
->wState
|= CBF_NOLBSELECT
;
1757 CBUpdateEdit( lphc
, index
);
1758 lphc
->wState
&= ~CBF_NOLBSELECT
;
1762 SetCapture(lphc
->hWndLBox
);
1765 if( lphc
->wState
& CBF_BUTTONDOWN
)
1767 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1768 CBRepaintButton( lphc
);
1772 /***********************************************************************
1775 * Two things to do - track combo button and release capture when
1776 * pointer goes into the listbox.
1778 static void COMBO_MouseMove( LPHEADCOMBO lphc
, WPARAM wParam
, LPARAM lParam
)
1783 pt
.x
= LOWORD(lParam
);
1784 pt
.y
= HIWORD(lParam
);
1786 if( lphc
->wState
& CBF_BUTTONDOWN
)
1790 bButton
= PtInRect(&lphc
->buttonRect
, pt
);
1794 lphc
->wState
&= ~CBF_BUTTONDOWN
;
1795 CBRepaintButton( lphc
);
1799 GetClientRect( lphc
->hWndLBox
, &lbRect
);
1800 MapWindowPoints( lphc
->self
, lphc
->hWndLBox
, &pt
, 1 );
1801 if( PtInRect(&lbRect
, pt
) )
1803 lphc
->wState
&= ~CBF_CAPTURE
;
1805 if( CB_GETTYPE(lphc
) == CBS_DROPDOWN
) CBUpdateLBox( lphc
, TRUE
);
1807 /* hand over pointer tracking */
1808 SendMessageW(lphc
->hWndLBox
, WM_LBUTTONDOWN
, wParam
, lParam
);
1813 /***********************************************************************
1814 * ComboWndProc_common
1816 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/ctrl/src/combobox_15.htm
1818 static LRESULT
ComboWndProc_common( HWND hwnd
, UINT message
,
1819 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1821 LPHEADCOMBO lphc
= (LPHEADCOMBO
)GetWindowLongA( hwnd
, 0 );
1823 //TRACE("[%p]: msg %s wp %08x lp %08lx\n",
1824 // hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam );
1826 if( lphc
|| message
== WM_NCCREATE
)
1830 /* System messages */
1834 LONG style
= unicode
? ((LPCREATESTRUCTW
)lParam
)->style
:
1835 ((LPCREATESTRUCTA
)lParam
)->style
;
1836 return COMBO_NCCreate(hwnd
, style
);
1839 COMBO_NCDestroy(lphc
);
1840 break;/* -> DefWindowProc */
1848 hwndParent
= ((LPCREATESTRUCTW
)lParam
)->hwndParent
;
1849 style
= ((LPCREATESTRUCTW
)lParam
)->style
;
1853 hwndParent
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
1854 style
= ((LPCREATESTRUCTA
)lParam
)->style
;
1856 return COMBO_Create(hwnd
, lphc
, hwndParent
, style
, unicode
);
1859 case WM_PRINTCLIENT
:
1860 if (lParam
& PRF_ERASEBKGND
)
1861 COMBO_EraseBackground(hwnd
, lphc
, (HDC
)wParam
);
1865 /* wParam may contain a valid HDC! */
1866 return COMBO_Paint(lphc
, (HDC
)wParam
);
1868 return COMBO_EraseBackground(hwnd
, lphc
, (HDC
)wParam
);
1871 LRESULT result
= DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1872 if (lParam
&& (((LPMSG
)lParam
)->message
== WM_KEYDOWN
))
1874 int vk
= (int)((LPMSG
)lParam
)->wParam
;
1876 if ((vk
== VK_RETURN
|| vk
== VK_ESCAPE
) && (lphc
->wState
& CBF_DROPPED
))
1877 result
|= DLGC_WANTMESSAGE
;
1881 case WM_WINDOWPOSCHANGING
:
1882 return COMBO_WindowPosChanging(hwnd
, lphc
, (LPWINDOWPOS
)lParam
);
1883 case WM_WINDOWPOSCHANGED
:
1884 /* SetWindowPos can be called on a Combobox to resize its Listbox.
1885 * In that case, the Combobox itself will not be resized, so we won't
1886 * get a WM_SIZE. Since we still want to update the Listbox, we have to
1891 if( lphc
->hWndLBox
&&
1892 !(lphc
->wState
& CBF_NORESIZE
) ) COMBO_Size( lphc
);
1895 COMBO_Font( lphc
, (HFONT
)wParam
, (BOOL
)lParam
);
1898 return (LRESULT
)lphc
->hFont
;
1900 if( lphc
->wState
& CBF_EDIT
)
1901 SetFocus( lphc
->hWndEdit
);
1903 COMBO_SetFocus( lphc
);
1908 HWND hwndFocus
= (HWND
)wParam
;
1910 HWND hwndFocus
= WIN_GetFullHandle( (HWND
)wParam
);
1913 (hwndFocus
!= lphc
->hWndEdit
&& hwndFocus
!= lphc
->hWndLBox
))
1914 COMBO_KillFocus( lphc
);
1919 return COMBO_Command( lphc
, wParam
, (HWND
)lParam
);
1921 return COMBO_Command( lphc
, wParam
, WIN_GetFullHandle( (HWND
)lParam
) );
1924 return unicode
? COMBO_GetTextW( lphc
, wParam
, (LPWSTR
)lParam
)
1925 : COMBO_GetTextA( lphc
, wParam
, (LPSTR
)lParam
);
1927 case WM_GETTEXTLENGTH
:
1929 if ((message
== WM_GETTEXTLENGTH
) && !ISWIN31
&& !(lphc
->wState
& CBF_EDIT
))
1931 int j
= SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
1932 if (j
== -1) return 0;
1933 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0) :
1934 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, j
, 0);
1936 else if( lphc
->wState
& CBF_EDIT
)
1939 lphc
->wState
|= CBF_NOEDITNOTIFY
;
1940 ret
= unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1941 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1942 lphc
->wState
&= ~CBF_NOEDITNOTIFY
;
1949 if( lphc
->wState
& CBF_EDIT
)
1951 return unicode
? SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
) :
1952 SendMessageA(lphc
->hWndEdit
, message
, wParam
, lParam
);
1958 case WM_COMPAREITEM
:
1959 case WM_MEASUREITEM
:
1960 return COMBO_ItemOp(lphc
, message
, lParam
);
1962 if( lphc
->wState
& CBF_EDIT
)
1963 EnableWindow( lphc
->hWndEdit
, (BOOL
)wParam
);
1964 EnableWindow( lphc
->hWndLBox
, (BOOL
)wParam
);
1966 /* Force the control to repaint when the enabled state changes. */
1967 InvalidateRect(lphc
->self
, NULL
, TRUE
);
1971 lphc
->wState
&= ~CBF_NOREDRAW
;
1973 lphc
->wState
|= CBF_NOREDRAW
;
1975 if( lphc
->wState
& CBF_EDIT
)
1976 SendMessageW(lphc
->hWndEdit
, message
, wParam
, lParam
);
1977 SendMessageW(lphc
->hWndLBox
, message
, wParam
, lParam
);
1980 if( KEYDATA_ALT
& HIWORD(lParam
) )
1981 if( wParam
== VK_UP
|| wParam
== VK_DOWN
)
1982 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
1991 if ((wParam
== VK_RETURN
|| wParam
== VK_ESCAPE
) &&
1992 (lphc
->wState
& CBF_DROPPED
))
1994 CBRollUp( lphc
, wParam
== VK_RETURN
, FALSE
);
1997 else if ((wParam
== VK_F4
) && !(lphc
->wState
& CBF_EUI
))
1999 COMBO_FlipListbox( lphc
, FALSE
, FALSE
);
2003 if( lphc
->wState
& CBF_EDIT
)
2004 hwndTarget
= lphc
->hWndEdit
;
2006 hwndTarget
= lphc
->hWndLBox
;
2008 return unicode
? SendMessageW(hwndTarget
, message
, wParam
, lParam
) :
2009 SendMessageA(hwndTarget
, message
, wParam
, lParam
);
2011 case WM_LBUTTONDOWN
:
2012 if( !(lphc
->wState
& CBF_FOCUSED
) ) SetFocus( lphc
->self
);
2013 if( lphc
->wState
& CBF_FOCUSED
) COMBO_LButtonDown( lphc
, lParam
);
2016 COMBO_LButtonUp( lphc
);
2019 if( lphc
->wState
& CBF_CAPTURE
)
2020 COMBO_MouseMove( lphc
, wParam
, lParam
);
2024 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
2025 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2026 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2028 if (GET_WHEEL_DELTA_WPARAM(wParam
) > 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_UP
, 0);
2029 if (GET_WHEEL_DELTA_WPARAM(wParam
) < 0) return SendMessageW(hwnd
, WM_KEYDOWN
, VK_DOWN
, 0);
2032 /* Combo messages */
2035 case CB_ADDSTRING16
:
2036 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2042 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2043 strlwrW((LPWSTR
)lParam
);
2044 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2045 struprW((LPWSTR
)lParam
);
2046 return SendMessageW(lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
2050 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2051 _strlwr((LPSTR
)lParam
);
2052 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2053 _strupr((LPSTR
)lParam
);
2054 return SendMessageA(lphc
->hWndLBox
, LB_ADDSTRING
, 0, lParam
);
2057 case CB_INSERTSTRING16
:
2058 wParam
= (INT
)(INT16
)wParam
;
2059 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2062 case CB_INSERTSTRING
:
2065 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2066 strlwrW((LPWSTR
)lParam
);
2067 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2068 struprW((LPWSTR
)lParam
);
2069 return SendMessageW(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2073 if( lphc
->dwStyle
& CBS_LOWERCASE
)
2074 _strlwr((LPSTR
)lParam
);
2075 else if( lphc
->dwStyle
& CBS_UPPERCASE
)
2076 _strupr((LPSTR
)lParam
);
2077 return SendMessageA(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
);
2080 case CB_DELETESTRING16
:
2082 case CB_DELETESTRING
:
2083 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0) :
2084 SendMessageA(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0);
2086 case CB_SELECTSTRING16
:
2087 wParam
= (INT
)(INT16
)wParam
;
2088 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2091 case CB_SELECTSTRING
:
2092 return COMBO_SelectString(lphc
, (INT
)wParam
, lParam
, unicode
);
2094 case CB_FINDSTRING16
:
2095 wParam
= (INT
)(INT16
)wParam
;
2096 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2100 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
) :
2101 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
);
2103 case CB_FINDSTRINGEXACT16
:
2104 wParam
= (INT
)(INT16
)wParam
;
2105 if( CB_HASSTRINGS(lphc
) ) lParam
= (LPARAM
)MapSL(lParam
);
2108 case CB_FINDSTRINGEXACT
:
2109 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
) :
2110 SendMessageA(lphc
->hWndLBox
, LB_FINDSTRINGEXACT
, wParam
, lParam
);
2112 case CB_SETITEMHEIGHT16
:
2113 wParam
= (INT
)(INT16
)wParam
; /* signed integer */
2116 case CB_SETITEMHEIGHT
:
2117 return COMBO_SetItemHeight( lphc
, (INT
)wParam
, (INT
)lParam
);
2119 case CB_GETITEMHEIGHT16
:
2120 wParam
= (INT
)(INT16
)wParam
;
2123 case CB_GETITEMHEIGHT
:
2124 if( (INT
)wParam
>= 0 ) /* listbox item */
2125 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMHEIGHT
, wParam
, 0);
2126 return CBGetTextAreaHeight(hwnd
, lphc
);
2128 case CB_RESETCONTENT16
:
2130 case CB_RESETCONTENT
:
2131 SendMessageW(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0);
2132 if( (lphc
->wState
& CBF_EDIT
) && CB_HASSTRINGS(lphc
) )
2134 static const WCHAR empty_stringW
[] = { 0 };
2135 SendMessageW(lphc
->hWndEdit
, WM_SETTEXT
, 0, (LPARAM
)empty_stringW
);
2138 InvalidateRect(lphc
->self
, NULL
, TRUE
);
2140 case CB_INITSTORAGE
:
2141 return SendMessageW(lphc
->hWndLBox
, LB_INITSTORAGE
, wParam
, lParam
);
2142 case CB_GETHORIZONTALEXTENT
:
2143 return SendMessageW(lphc
->hWndLBox
, LB_GETHORIZONTALEXTENT
, 0, 0);
2144 case CB_SETHORIZONTALEXTENT
:
2145 return SendMessageW(lphc
->hWndLBox
, LB_SETHORIZONTALEXTENT
, wParam
, 0);
2146 case CB_GETTOPINDEX
:
2147 return SendMessageW(lphc
->hWndLBox
, LB_GETTOPINDEX
, 0, 0);
2149 return SendMessageW(lphc
->hWndLBox
, LB_GETLOCALE
, 0, 0);
2151 return SendMessageW(lphc
->hWndLBox
, LB_SETLOCALE
, wParam
, 0);
2152 case CB_GETDROPPEDWIDTH
:
2153 if( lphc
->droppedWidth
)
2154 return lphc
->droppedWidth
;
2155 return lphc
->droppedRect
.right
- lphc
->droppedRect
.left
;
2156 case CB_SETDROPPEDWIDTH
:
2157 if( (CB_GETTYPE(lphc
) != CBS_SIMPLE
) &&
2158 (INT
)wParam
< 32768 ) lphc
->droppedWidth
= (INT
)wParam
;
2161 case CB_GETDROPPEDCONTROLRECT16
:
2162 lParam
= (LPARAM
)MapSL(lParam
);
2166 CBGetDroppedControlRect( lphc
, &r
);
2167 CONV_RECT32TO16( &r
, (LPRECT16
)lParam
);
2171 case CB_GETDROPPEDCONTROLRECT
:
2172 if( lParam
) CBGetDroppedControlRect(lphc
, (LPRECT
)lParam
);
2175 case CB_GETDROPPEDSTATE16
:
2177 case CB_GETDROPPEDSTATE
:
2178 return (lphc
->wState
& CBF_DROPPED
) ? TRUE
: FALSE
;
2181 return SendMessageA(lphc
->hWndLBox
, LB_DIR16
, wParam
, lParam
);
2184 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
) :
2185 SendMessageA(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
);
2188 case CB_SHOWDROPDOWN16
:
2190 case CB_SHOWDROPDOWN
:
2191 if( CB_GETTYPE(lphc
) != CBS_SIMPLE
)
2195 if( !(lphc
->wState
& CBF_DROPPED
) )
2199 if( lphc
->wState
& CBF_DROPPED
)
2200 CBRollUp( lphc
, FALSE
, TRUE
);
2207 return SendMessageW(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0);
2209 case CB_GETCURSEL16
:
2212 return SendMessageW(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0);
2214 case CB_SETCURSEL16
:
2215 wParam
= (INT
)(INT16
)wParam
;
2219 lParam
= SendMessageW(lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0);
2221 SendMessageW(lphc
->hWndLBox
, LB_SETTOPINDEX
, wParam
, 0);
2223 /* no LBN_SELCHANGE in this case, update manually */
2224 if( lphc
->wState
& CBF_EDIT
)
2225 CBUpdateEdit( lphc
, (INT
)wParam
);
2227 InvalidateRect(lphc
->self
, &lphc
->textRect
, TRUE
);
2228 lphc
->wState
&= ~CBF_SELCHANGE
;
2231 case CB_GETLBTEXT16
:
2232 wParam
= (INT
)(INT16
)wParam
;
2233 lParam
= (LPARAM
)MapSL(lParam
);
2237 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
) :
2238 SendMessageA(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
);
2240 case CB_GETLBTEXTLEN16
:
2241 wParam
= (INT
)(INT16
)wParam
;
2244 case CB_GETLBTEXTLEN
:
2245 return unicode
? SendMessageW(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0) :
2246 SendMessageA(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, 0);
2248 case CB_GETITEMDATA16
:
2249 wParam
= (INT
)(INT16
)wParam
;
2252 case CB_GETITEMDATA
:
2253 return SendMessageW(lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0);
2255 case CB_SETITEMDATA16
:
2256 wParam
= (INT
)(INT16
)wParam
;
2259 case CB_SETITEMDATA
:
2260 return SendMessageW(lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
);
2262 case CB_GETEDITSEL16
:
2263 wParam
= lParam
= 0; /* just in case */
2267 /* Edit checks passed parameters itself */
2268 if( lphc
->wState
& CBF_EDIT
)
2269 return SendMessageW(lphc
->hWndEdit
, EM_GETSEL
, wParam
, lParam
);
2272 case CB_SETEDITSEL16
:
2275 if( lphc
->wState
& CBF_EDIT
)
2276 return SendMessageW(lphc
->hWndEdit
, EM_SETSEL
,
2277 (INT
)(INT16
)LOWORD(lParam
), (INT
)(INT16
)HIWORD(lParam
) );
2280 case CB_SETEXTENDEDUI16
:
2282 case CB_SETEXTENDEDUI
:
2283 if( CB_GETTYPE(lphc
) == CBS_SIMPLE
)
2286 lphc
->wState
|= CBF_EUI
;
2287 else lphc
->wState
&= ~CBF_EUI
;
2290 case CB_GETEXTENDEDUI16
:
2292 case CB_GETEXTENDEDUI
:
2293 return (lphc
->wState
& CBF_EUI
) ? TRUE
: FALSE
;
2296 if (message
>= WM_USER
)
2297 WARN("unknown msg WM_USER+%04x wp=%04x lp=%08lx\n",
2298 message
- WM_USER
, wParam
, lParam
);
2301 return unicode
? DefWindowProcW(hwnd
, message
, wParam
, lParam
) :
2302 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
2305 /***********************************************************************
2308 * This is just a wrapper for the real ComboWndProc which locks/unlocks
2311 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2313 if (!IsWindow(hwnd
)) return 0;
2314 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
2317 /***********************************************************************
2320 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2322 if (!IsWindow(hwnd
)) return 0;
2323 return ComboWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
2326 /*************************************************************************
2327 * GetComboBoxInfo (USER32.@)
2329 BOOL WINAPI
GetComboBoxInfo(HWND hwndCombo
, /* [in] handle to combo box */
2330 PCOMBOBOXINFO pcbi
/* [in/out] combo box information */)