4 * Copyright 1993 Martin Ayotte
5 * Copyright 1995 Bernd Schmidt
6 * Copyright 1996 Albrecht Kleine [some fixes]
13 #include <sys/types.h>
17 #include "sysmetrics.h"
19 #include "stackframe.h"
32 * Note: Combos are probably implemented in a different way by Windows.
33 * Using a message spy for Windows, you can see some undocumented
34 * messages being passed between ComboBox and ComboLBox.
35 * I hope no programs rely on the implementation of combos.
40 #define CBLMM_EDGE 4 /* distance inside box which is same as moving mouse
41 outside box, to trigger scrolling of CBL */
43 static BOOL
CBCheckSize(HWND hwnd
);
44 static BOOL
CBLCheckSize(HWND hwnd
);
46 static HBITMAP hComboBit
= 0;
47 static WORD CBitHeight
, CBitWidth
;
49 static int COMBO_Init()
53 dprintf_combo(stddeb
, "COMBO_Init\n");
54 hComboBit
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_COMBO
));
55 GetObject16( hComboBit
, sizeof(bm
), &bm
);
56 CBitHeight
= bm
.bmHeight
;
57 CBitWidth
= bm
.bmWidth
;
61 LPHEADCOMBO
ComboGetStorageHeader(HWND hwnd
)
63 return (LPHEADCOMBO
)GetWindowLong32A(hwnd
,4);
66 LPHEADLIST
ComboGetListHeader(HWND hwnd
)
68 return (LPHEADLIST
)GetWindowLong32A(hwnd
,0);
71 int CreateComboStruct(HWND hwnd
, LONG style
)
75 lphc
= (LPHEADCOMBO
)xmalloc(sizeof(HEADCOMBO
));
76 SetWindowLong32A(hwnd
,4,(LONG
)lphc
);
81 lphc
->dwStyle
= style
;
82 lphc
->DropDownVisible
= FALSE
;
86 void ComboUpdateWindow(HWND hwnd
, LPHEADLIST lphl
, LPHEADCOMBO lphc
, BOOL repaint
)
88 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
90 if (wndPtr
->dwStyle
& WS_VSCROLL
)
91 SetScrollRange(lphc
->hWndLBox
,SB_VERT
,0,ListMaxFirstVisible(lphl
),TRUE
);
92 if (repaint
&& lphl
->bRedrawFlag
) InvalidateRect32( hwnd
, NULL
, TRUE
);
95 /***********************************************************************
98 static LRESULT
CBNCCreate(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
100 CREATESTRUCT16
*createStruct
;
102 if (!hComboBit
) COMBO_Init();
104 createStruct
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
105 createStruct
->style
|= WS_BORDER
;
106 SetWindowLong32A(hwnd
, GWL_STYLE
, createStruct
->style
);
108 dprintf_combo(stddeb
,"ComboBox WM_NCCREATE!\n");
109 return DefWindowProc16(hwnd
, WM_NCCREATE
, wParam
, lParam
);
113 /***********************************************************************
116 static LRESULT
CBCreate(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
121 LONG cstyle
= GetWindowLong32A(hwnd
,GWL_STYLE
);
122 RECT16 rect
,lboxrect
;
123 WND
* wndPtr
= WIN_FindWndPtr(hwnd
);
124 char className
[] = "COMBOLBOX"; /* Hack so that class names are > 0x10000 */
125 char editName
[] = "EDIT";
128 /* translate combo into listbox styles */
130 if (cstyle
& CBS_OWNERDRAWFIXED
) style
|= LBS_OWNERDRAWFIXED
;
131 if (cstyle
& CBS_OWNERDRAWVARIABLE
) style
|= LBS_OWNERDRAWVARIABLE
;
132 if (cstyle
& CBS_SORT
) style
|= LBS_SORT
;
133 if (cstyle
& CBS_HASSTRINGS
) style
|= LBS_HASSTRINGS
;
135 CreateListBoxStruct(hwnd
, ODT_COMBOBOX
, style
, GetParent(hwnd
));
136 CreateComboStruct(hwnd
,cstyle
);
138 lphl
= ComboGetListHeader(hwnd
);
139 lphc
= ComboGetStorageHeader(hwnd
);
141 GetClientRect16(hwnd
,&rect
);
142 lphc
->LBoxTop
= lphl
->StdItemHeight
;
146 case CBS_SIMPLE
: /* edit control, list always visible */
148 dprintf_combo(stddeb
,"CBS_SIMPLE\n");
149 style
= WS_BORDER
| WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
;
150 SetRectEmpty16(&lphc
->RectButton
);
154 case CBS_DROPDOWNLIST
: /* static control, dropdown listbox */
155 case CBS_DROPDOWN
: /* edit control, dropdown listbox */
156 GetWindowRect16(hwnd
,&lboxrect
);
157 style
= WS_POPUP
| WS_BORDER
| WS_VSCROLL
;
158 /* FIXME: WinSight says these should be CHILD windows with the TOPMOST flag
159 * set. Wine doesn't support TOPMOST, and simply setting the WS_CHILD
160 * flag doesn't work. */
161 lphc
->RectButton
= rect
;
162 lphc
->RectButton
.left
= lphc
->RectButton
.right
- 6 - CBitWidth
;
163 lphc
->RectButton
.bottom
= lphc
->RectButton
.top
+ lphl
->StdItemHeight
;
164 SetWindowPos(hwnd
, 0, 0, 0, rect
.right
-rect
.left
+ 2*SYSMETRICS_CXBORDER
,
165 lphl
->StdItemHeight
+ 2*SYSMETRICS_CYBORDER
,
166 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOSENDCHANGING
);
167 dprintf_combo(stddeb
,(cstyle
& 3)==CBS_DROPDOWN
? "CBS_DROPDOWN\n": "CBS_DROPDOWNLIST\n");
170 default: fprintf(stderr
,"COMBOBOX error: bad class style!\n");
174 if ((cstyle
& 3) != CBS_DROPDOWNLIST
)
175 lphc
->hWndEdit
= CreateWindow16( editName
, NULL
,
176 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| ES_LEFT
,
177 0, 0, rect
.right
-6-CBitWidth
,
178 lphl
->StdItemHeight
+2*SYSMETRICS_CYBORDER
,
179 hwnd
, (HMENU
)ID_EDIT
, WIN_GetWindowInstance(hwnd
), NULL
);
181 lboxrect
.top
+=lphc
->LBoxTop
;
182 lphc
->hWndLBox
= CreateWindow16( className
, NULL
, style
|
183 ((cstyle
& WS_HSCROLL
)? WS_HSCROLL
: 0) |
184 ((cstyle
& WS_VSCROLL
)? WS_VSCROLL
: 0),
185 lboxrect
.left
, lboxrect
.top
,
186 lboxrect
.right
- lboxrect
.left
,
187 lboxrect
.bottom
- lboxrect
.top
,
188 hwndp
,(HMENU
)ID_CLB
, WIN_GetWindowInstance(hwnd
),
189 (LPVOID
)(HWND32
)hwnd
);
191 wndPtr
->dwStyle
&= ~(WS_VSCROLL
| WS_HSCROLL
);
193 dprintf_combo( stddeb
, "Combo Creation hwnd=%04x LBox=%04x Edit=%04x\n",
194 hwnd
, lphc
->hWndLBox
, lphc
->hWndEdit
);
195 dprintf_combo( stddeb
, " lbox %d,%d-%d,%d button %d,%d-%d,%d\n",
196 lboxrect
.left
, lboxrect
.top
, lboxrect
.right
, lboxrect
.bottom
,
197 lphc
->RectButton
.left
, lphc
->RectButton
.top
,
198 lphc
->RectButton
.right
, lphc
->RectButton
.bottom
);
199 dprintf_combo( stddeb
, " client %d,%d-%d,%d window %d,%d-%d,%d\n",
200 wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
,
201 wndPtr
->rectClient
.right
, wndPtr
->rectClient
.bottom
,
202 wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
203 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
);
207 /***********************************************************************
210 static LRESULT
CBDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
212 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
214 if (lphc
->hWndEdit
) DestroyWindow( lphc
->hWndEdit
);
215 if (lphc
->hWndLBox
) DestroyWindow( lphc
->hWndLBox
);
219 /***********************************************************************
222 static LRESULT
CBPaint(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
224 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
225 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
233 hdc
= BeginPaint16(hwnd
, &ps
);
235 GetClientRect16(hwnd
, &rect
);
237 /* 1 for button border */
238 rect
.right
= lphc
->RectButton
.left
- 1;
240 if (hComboBit
!= 0 && !IsRectEmpty16(&lphc
->RectButton
))
242 Rectangle(hdc
,lphc
->RectButton
.left
-1,lphc
->RectButton
.top
-1,
243 lphc
->RectButton
.right
+1,lphc
->RectButton
.bottom
+1);
244 GRAPH_DrawReliefRect(hdc
, &lphc
->RectButton
, 2, 2, FALSE
);
245 GRAPH_DrawBitmap(hdc
, hComboBit
,
246 lphc
->RectButton
.left
+ 2,lphc
->RectButton
.top
+ 2,
247 0, 0, CBitWidth
, CBitHeight
);
249 if (!IsWindowVisible(hwnd
) || !lphl
->bRedrawFlag
250 || (lphc
->dwStyle
& 3) != CBS_DROPDOWNLIST
)
252 /* we don't want to draw an entry when there is an edit control */
253 EndPaint16(hwnd
, &ps
);
257 hOldFont
= SelectObject(hdc
, lphl
->hFont
);
259 hBrush
= SendMessage32A( lphl
->hParent
, WM_CTLCOLORLISTBOX
, hdc
, hwnd
);
260 if (hBrush
== 0) hBrush
= GetStockObject(WHITE_BRUSH
);
262 lpls
= ListBoxGetItem(lphl
,lphl
->ItemFocused
);
264 FillRect16(hdc
, &rect
, hBrush
);
265 ListBoxDrawItem (hwnd
, lphl
, hdc
, lpls
, &rect
, ODA_DRAWENTIRE
, 0);
266 if (GetFocus() == hwnd
)
267 ListBoxDrawItem (hwnd
,lphl
, hdc
, lpls
, &rect
, ODA_FOCUS
, ODS_FOCUS
);
269 else FillRect16(hdc
, &rect
, hBrush
);
270 SelectObject(hdc
,hOldFont
);
271 EndPaint16(hwnd
, &ps
);
275 /***********************************************************************
278 static LRESULT
CBGetDlgCode(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
280 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
283 /***********************************************************************
286 static LRESULT
CBLButtonDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
288 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
289 SendMessage16(hwnd
,CB_SHOWDROPDOWN
,!lphc
->DropDownVisible
,0);
293 /***********************************************************************
296 static LRESULT
CBKeyDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
298 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
299 WORD newFocused
= lphl
->ItemFocused
;
306 newFocused
= lphl
->ItemsCount
- 1;
309 if (newFocused
> 0) newFocused
--;
318 if (newFocused
>= lphl
->ItemsCount
)
319 newFocused
= lphl
->ItemsCount
- 1;
321 ListBoxSetCurSel(lphl
, newFocused
);
322 SendMessage16(hwnd
, WM_COMMAND
,ID_CLB
,MAKELONG(0,CBN_SELCHANGE
));
323 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
325 lphl
->ItemFocused
= newFocused
;
326 ListBoxScrollToFocus(lphl
);
327 /* SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);*/
328 InvalidateRect32( hwnd
, NULL
, TRUE
);
333 /***********************************************************************
336 static LRESULT
CBChar(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
338 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
341 newFocused
= ListBoxFindNextMatch(lphl
, wParam
);
342 if (newFocused
== (WORD
)LB_ERR
) return 0;
344 if (newFocused
>= lphl
->ItemsCount
)
345 newFocused
= lphl
->ItemsCount
- 1;
347 ListBoxSetCurSel(lphl
, newFocused
);
348 SendMessage16(hwnd
, WM_COMMAND
,ID_CLB
,MAKELONG(0,CBN_SELCHANGE
));
349 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
350 lphl
->ItemFocused
= newFocused
;
351 ListBoxScrollToFocus(lphl
);
353 /* SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);*/
354 InvalidateRect32( hwnd
, NULL
, TRUE
);
359 /***********************************************************************
362 static LRESULT
CBKillFocus(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
367 /***********************************************************************
370 static LRESULT
CBSetFocus(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
375 /***********************************************************************
378 static LRESULT
CBResetContent(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
380 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
381 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
383 ListBoxResetContent(lphl
);
384 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
388 /***********************************************************************
391 static LRESULT
CBDir(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
394 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
395 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
397 wRet
= ListBoxDirectory(lphl
, wParam
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
398 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
402 /***********************************************************************
405 static LRESULT
CBInsertString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
408 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
409 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
411 if (lphl
->HasStrings
)
412 wRet
= ListBoxInsertString(lphl
, wParam
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
414 wRet
= ListBoxInsertString(lphl
, wParam
, (LPSTR
)lParam
);
415 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
419 /***********************************************************************
422 static LRESULT
CBAddString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
425 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
426 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
428 wRet
= ListBoxAddString(lphl
, (SEGPTR
)lParam
);
430 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
434 /***********************************************************************
437 static LRESULT
CBDeleteString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
439 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
440 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
441 LONG lRet
= ListBoxDeleteString(lphl
,wParam
);
443 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
447 /***********************************************************************
450 static LRESULT
CBSelectString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
452 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
455 wRet
= ListBoxFindString(lphl
, wParam
, (SEGPTR
)lParam
);
457 /* XXX add functionality here */
462 /***********************************************************************
465 static LRESULT
CBFindString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
467 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
468 return ListBoxFindString(lphl
, wParam
, (SEGPTR
)lParam
);
471 /***********************************************************************
474 static LRESULT
CBGetCount(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
476 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
477 return lphl
->ItemsCount
;
480 /***********************************************************************
483 static LRESULT
CBSetCurSel(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
485 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
488 wRet
= ListBoxSetCurSel(lphl
, wParam
);
490 dprintf_combo(stddeb
,"CBSetCurSel: hwnd %04x wp %x lp %lx wRet %d\n",
491 hwnd
,wParam
,lParam
,wRet
);
492 /* SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);*/
493 InvalidateRect32( hwnd
, NULL
, TRUE
);
498 /***********************************************************************
501 static LRESULT
CBGetCurSel(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
503 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
504 return lphl
->ItemFocused
;
507 /***********************************************************************
510 static LRESULT
CBGetItemHeight(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
512 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
513 LPLISTSTRUCT lpls
= ListBoxGetItem (lphl
, wParam
);
515 if (lpls
== NULL
) return LB_ERR
;
516 return lpls
->mis
.itemHeight
;
519 /***********************************************************************
522 static LRESULT
CBSetItemHeight(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
524 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
525 return ListBoxSetItemHeight(lphl
, wParam
, lParam
);
528 /***********************************************************************
531 static LRESULT
CBSetRedraw(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
533 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
534 lphl
->bRedrawFlag
= wParam
;
538 /***********************************************************************
541 static LRESULT
CBSetFont(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
543 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
544 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
547 lphl
->hFont
= GetStockObject(SYSTEM_FONT
);
549 lphl
->hFont
= (HFONT
)wParam
;
551 SendMessage16(lphc
->hWndEdit
,WM_SETFONT
,lphl
->hFont
,0);
555 /***********************************************************************
558 static LRESULT
CBGetLBTextLen(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
560 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
561 LPLISTSTRUCT lpls
= ListBoxGetItem(lphl
,wParam
);
563 if (lpls
== NULL
|| !lphl
->HasStrings
) return LB_ERR
;
564 return strlen(lpls
->itemText
);
567 /***********************************************************************
570 static LRESULT
CBGetLBText(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
572 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
573 return ListBoxGetText(lphl
, wParam
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
576 /***********************************************************************
579 static LRESULT
CBGetItemData(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
581 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
582 return ListBoxGetItemData(lphl
, wParam
);
585 /***********************************************************************
588 static LRESULT
CBSetItemData(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
590 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
591 return ListBoxSetItemData(lphl
, wParam
, lParam
);
594 /***********************************************************************
597 static LRESULT
CBShowDropDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
599 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
602 if ((lphc
->dwStyle
& 3) == CBS_SIMPLE
) return LB_ERR
;
605 if (wParam
!= lphc
->DropDownVisible
) {
606 lphc
->DropDownVisible
= wParam
;
607 GetWindowRect32(hwnd
,&rect
);
608 SetWindowPos(lphc
->hWndLBox
, 0, rect
.left
, rect
.top
+lphc
->LBoxTop
, 0, 0,
609 SWP_NOSIZE
| (wParam
? SWP_SHOWWINDOW
: SWP_HIDEWINDOW
));
610 if (!wParam
) SetFocus(hwnd
);
616 /***********************************************************************
619 static BOOL
CBCheckSize(HWND hwnd
)
621 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
622 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
623 LONG cstyle
= GetWindowLong32A(hwnd
,GWL_STYLE
);
626 if (lphc
->hWndLBox
== 0) return FALSE
;
628 GetClientRect16(hwnd
,&cRect
);
629 GetWindowRect16(hwnd
,&wRect
);
631 dprintf_combo(stddeb
,
632 "CBCheckSize: hwnd %04x Rect %d,%d-%d,%d wRect %d,%d-%d,%d\n",
633 hwnd
,cRect
.left
,cRect
.top
,cRect
.right
,cRect
.bottom
,
634 wRect
.left
,wRect
.top
,wRect
.right
,wRect
.bottom
);
635 if ((cstyle
& 3) == CBS_SIMPLE
) return TRUE
;
637 if ((cRect
.bottom
- cRect
.top
) >
638 (lphl
->StdItemHeight
+ 2*SYSMETRICS_CYBORDER
)) {
639 SetWindowPos(hwnd
, 0, 0, 0,
640 cRect
.right
-cRect
.left
,
641 lphl
->StdItemHeight
+2*SYSMETRICS_CYBORDER
,
642 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
| SWP_NOACTIVATE
);
643 GetClientRect16(hwnd
,&cRect
);
644 GetWindowRect16(hwnd
,&wRect
);
646 lphc
->RectButton
.right
= cRect
.right
;
647 lphc
->RectButton
.left
= cRect
.right
- 2*SYSMETRICS_CXBORDER
- 4
649 lphc
->RectButton
.top
= cRect
.top
;
650 lphc
->RectButton
.bottom
= cRect
.bottom
;
653 if (cRect
.right
< lphc
->RectButton
.left
) {
654 /* if the button is outside the window, move it in */
655 if ((wRect
.right
- wRect
.left
- 2*SYSMETRICS_CXBORDER
) == (cRect
.right
- cRect
.left
)) {
656 lphc
->RectButton
.right
= cRect
.right
;
657 lphc
->RectButton
.left
= cRect
.right
- 2*SYSMETRICS_CXBORDER
- 4
659 lphc
->RectButton
.top
= cRect
.top
;
660 lphc
->RectButton
.bottom
= cRect
.bottom
;
662 /* otherwise we need to make the client include the button */
664 SetWindowPos(hwnd
, 0, 0, 0, lphc
->RectButton
.right
,
665 lphl
->StdItemHeight
+2*SYSMETRICS_CYBORDER
,
666 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
| SWP_NOACTIVATE
);
673 /***********************************************************************
676 static LRESULT
CBCommand(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
678 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
679 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
683 if (lphc
->hWndEdit
) /* interdependence only used for CBS_SIMPLE and CBS_DROPDOWN styles */
687 case ID_CLB
: /* update EDIT window */
688 if (HIWORD(lParam
)==CBN_SELCHANGE
)
689 if (lphl
->HasStrings
)
691 ListBoxGetText(lphl
,lphl
->ItemFocused
, buffer
);
692 dprintf_combo(stddeb
,"CBCommand: update Edit: %s\n",buffer
);
693 SetWindowText32A( lphc
->hWndEdit
, buffer
);
696 case ID_EDIT
: /* update LISTBOX window */
697 id
=GetWindowWord(hwnd
,GWW_ID
);
698 switch (HIWORD(lParam
))
700 case EN_UPDATE
:GetWindowText32A(lphc
->hWndEdit
,buffer
,255);
703 newFocused
=ListBoxFindString(lphl
, -1, MAKE_SEGPTR(buffer
));
704 dprintf_combo(stddeb
,"CBCommand: new selection #%d is= %s\n",
706 if (newFocused
!= (WORD
)LB_ERR
)
707 { /* if found something */
708 ListBoxSetCurSel(lphl
, newFocused
);
709 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
710 InvalidateRect32(hwnd
, NULL
, TRUE
);
713 SendMessage16(GetParent(hwnd
),WM_COMMAND
,id
,
714 MAKELONG(hwnd
, CBN_EDITUPDATE
));
716 case EN_CHANGE
:SendMessage16(GetParent(hwnd
),WM_COMMAND
,id
,
717 MAKELONG(hwnd
, CBN_EDITCHANGE
));
719 case EN_ERRSPACE
:SendMessage16(GetParent(hwnd
),WM_COMMAND
,id
,
720 MAKELONG(hwnd
, CBN_ERRSPACE
));
730 /***********************************************************************
733 LRESULT
ComboBoxWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
736 case WM_NCCREATE
: return CBNCCreate(hwnd
, wParam
, lParam
);
737 case WM_CREATE
: return CBCreate(hwnd
, wParam
, lParam
);
738 case WM_DESTROY
: return CBDestroy(hwnd
, wParam
, lParam
);
739 case WM_GETDLGCODE
: return CBGetDlgCode(hwnd
, wParam
, lParam
);
740 case WM_KEYDOWN
: return CBKeyDown(hwnd
, wParam
, lParam
);
741 case WM_CHAR
: return CBChar(hwnd
, wParam
, lParam
);
742 case WM_SETFONT
: return CBSetFont(hwnd
, wParam
, lParam
);
743 case WM_SETREDRAW
: return CBSetRedraw(hwnd
, wParam
, lParam
);
744 case WM_PAINT
: return CBPaint(hwnd
, wParam
, lParam
);
745 case WM_LBUTTONDOWN
: return CBLButtonDown(hwnd
, wParam
, lParam
);
746 case WM_SETFOCUS
: return CBSetFocus(hwnd
, wParam
, lParam
);
747 case WM_KILLFOCUS
: return CBKillFocus(hwnd
, wParam
, lParam
);
748 case WM_SIZE
: return CBCheckSize(hwnd
);
749 case WM_COMMAND
: return CBCommand(hwnd
, wParam
, lParam
);
750 case CB_RESETCONTENT
: return CBResetContent(hwnd
, wParam
, lParam
);
751 case CB_DIR
: return CBDir(hwnd
, wParam
, lParam
);
752 case CB_ADDSTRING
: return CBAddString(hwnd
, wParam
, lParam
);
753 case CB_INSERTSTRING
: return CBInsertString(hwnd
, wParam
, lParam
);
754 case CB_DELETESTRING
: return CBDeleteString(hwnd
, wParam
, lParam
);
755 case CB_FINDSTRING
: return CBFindString(hwnd
, wParam
, lParam
);
756 case CB_GETCOUNT
: return CBGetCount(hwnd
, wParam
, lParam
);
757 case CB_GETCURSEL
: return CBGetCurSel(hwnd
, wParam
, lParam
);
758 case CB_GETITEMDATA
: return CBGetItemData(hwnd
, wParam
, lParam
);
759 case CB_GETITEMHEIGHT
: return CBGetItemHeight(hwnd
, wParam
, lParam
);
760 case CB_GETLBTEXT
: return CBGetLBText(hwnd
, wParam
, lParam
);
761 case CB_GETLBTEXTLEN
: return CBGetLBTextLen(hwnd
, wParam
, lParam
);
762 case CB_SELECTSTRING
: return CBSelectString(hwnd
, wParam
, lParam
);
763 case CB_SETITEMDATA
: return CBSetItemData(hwnd
, wParam
, lParam
);
764 case CB_SETCURSEL
: return CBSetCurSel(hwnd
, wParam
, lParam
);
765 case CB_SETITEMHEIGHT
: return CBSetItemHeight(hwnd
, wParam
, lParam
);
766 case CB_SHOWDROPDOWN
: return CBShowDropDown(hwnd
, wParam
, lParam
);
768 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
771 /*--------------------------------------------------------------------*/
772 /* ComboLBox code starts here */
774 HWND
CLBoxGetCombo(HWND hwnd
)
776 return (HWND
)GetWindowLong32A(hwnd
,0);
779 LPHEADLIST
CLBoxGetListHeader(HWND hwnd
)
781 return ComboGetListHeader(CLBoxGetCombo(hwnd
));
784 /***********************************************************************
787 static LRESULT
CBLCreate( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
789 CREATESTRUCT16
*createStruct
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
790 SetWindowLong32A(hwnd
,0,(LONG
)createStruct
->lpCreateParams
);
794 /***********************************************************************
797 static LRESULT
CBLGetDlgCode( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
799 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
802 /***********************************************************************
805 static LRESULT
CBLKeyDown( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
807 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
808 WORD newFocused
= lphl
->ItemFocused
;
815 newFocused
= lphl
->ItemsCount
- 1;
818 if (newFocused
> 0) newFocused
--;
824 if (newFocused
> lphl
->ItemsVisible
) {
825 newFocused
-= lphl
->ItemsVisible
;
831 newFocused
+= lphl
->ItemsVisible
;
837 if (newFocused
>= lphl
->ItemsCount
)
838 newFocused
= lphl
->ItemsCount
- 1;
840 ListBoxSetCurSel(lphl
, newFocused
);
841 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
842 SendMessage16(GetParent(hwnd
), WM_COMMAND
,ID_CLB
,MAKELONG(0,CBN_SELCHANGE
));
843 lphl
->ItemFocused
= newFocused
;
844 ListBoxScrollToFocus(lphl
);
845 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
846 InvalidateRect32( hwnd
, NULL
, TRUE
);
850 /***********************************************************************
853 static LRESULT
CBLChar( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
858 /***********************************************************************
861 static LRESULT
CBLPaint( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
863 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
868 WND
* wndPtr
= WIN_FindWndPtr(hwnd
);
869 HWND combohwnd
= CLBoxGetCombo(hwnd
);
875 hdc
= BeginPaint16( hwnd
, &ps
);
877 if (!IsWindowVisible(hwnd
) || !lphl
->bRedrawFlag
) {
878 EndPaint16(hwnd
, &ps
);
882 hOldFont
= SelectObject(hdc
, lphl
->hFont
);
883 /* listboxes should be white */
884 hBrush
= GetStockObject(WHITE_BRUSH
);
886 GetClientRect16(hwnd
, &rect
);
887 FillRect16(hdc
, &rect
, hBrush
);
890 lpls
= lphl
->lpFirst
;
892 lphl
->ItemsVisible
= 0;
893 for(i
= 0; i
< lphl
->ItemsCount
; i
++) {
894 if (lpls
== NULL
) break;
896 if (i
>= lphl
->FirstVisible
) {
897 height
= lpls
->mis
.itemHeight
;
898 /* must have enough room to draw entire item */
899 if (top
> (rect
.bottom
-height
+1)) break;
901 lpls
->itemRect
.top
= top
;
902 lpls
->itemRect
.bottom
= top
+ height
;
903 lpls
->itemRect
.left
= rect
.left
;
904 lpls
->itemRect
.right
= rect
.right
;
906 dprintf_listbox(stddeb
,"drawing item: %d %d %d %d %d\n",
907 rect
.left
,top
,rect
.right
,top
+height
,lpls
->itemState
);
908 if (lphl
->OwnerDrawn
) {
909 ListBoxDrawItem (combohwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_DRAWENTIRE
, 0);
911 ListBoxDrawItem (combohwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_SELECT
, ODS_SELECTED
);
913 ListBoxDrawItem (combohwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_DRAWENTIRE
,
916 if ((lphl
->ItemFocused
== i
) && GetFocus() == hwnd
)
917 ListBoxDrawItem (combohwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_FOCUS
, ODS_FOCUS
);
920 lphl
->ItemsVisible
++;
926 if (wndPtr
->dwStyle
& WS_VSCROLL
)
927 SetScrollRange(hwnd
, SB_VERT
, 0, ListMaxFirstVisible(lphl
), TRUE
);
929 SelectObject(hdc
,hOldFont
);
930 EndPaint16( hwnd
, &ps
);
935 /***********************************************************************
938 static LRESULT
CBLKillFocus( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
940 /* SendMessage16(CLBoxGetCombo(hwnd),CB_SHOWDROPDOWN,0,0);*/
944 /***********************************************************************
947 static LRESULT
CBLActivate( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
949 if (wParam
== WA_INACTIVE
)
950 SendMessage16(CLBoxGetCombo(hwnd
),CB_SHOWDROPDOWN
,0,0);
954 /***********************************************************************
957 static LRESULT
CBLLButtonDown( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
959 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
966 lphl
->PrevFocused
= lphl
->ItemFocused
;
968 y
= ListBoxFindMouse(lphl
, LOWORD(lParam
), HIWORD(lParam
));
972 ListBoxSetCurSel(lphl
, y
);
973 ListBoxGetItemRect(lphl
, y
, &rectsel
);
975 InvalidateRect32( hwnd
, NULL
, TRUE
);
979 /***********************************************************************
982 static LRESULT
CBLLButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
984 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
986 if (GetCapture() == hwnd
) ReleaseCapture();
990 fprintf(stdnimp
,"CBLLButtonUp: CLBoxGetListHeader returned NULL!\n");
992 else if (lphl
->PrevFocused
!= lphl
->ItemFocused
)
994 SendMessage16(CLBoxGetCombo(hwnd
),CB_SETCURSEL
,lphl
->ItemFocused
,0);
995 SendMessage16(GetParent(hwnd
), WM_COMMAND
,ID_CLB
,MAKELONG(0,CBN_SELCHANGE
));
996 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
999 SendMessage16(CLBoxGetCombo(hwnd
),CB_SHOWDROPDOWN
,0,0);
1004 /***********************************************************************
1007 static LRESULT
CBLMouseMove( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1009 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
1012 RECT16 rect
, rectsel
;
1014 y
= SHIWORD(lParam
);
1015 wRet
= ListBoxFindMouse(lphl
, LOWORD(lParam
), HIWORD(lParam
));
1016 ListBoxGetItemRect(lphl
, wRet
, &rectsel
);
1017 GetClientRect16(hwnd
, &rect
);
1019 dprintf_combo(stddeb
,"CBLMouseMove: hwnd %04x wp %x lp %lx y %d if %d wret %d %d,%d-%d,%d\n",
1020 hwnd
,wParam
,lParam
,y
,lphl
->ItemFocused
,wRet
,rectsel
.left
,rectsel
.top
,rectsel
.right
,rectsel
.bottom
);
1022 if ((wParam
& MK_LBUTTON
) != 0) {
1023 if (y
< CBLMM_EDGE
) {
1024 if (lphl
->FirstVisible
> 0) {
1025 lphl
->FirstVisible
--;
1026 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1027 ListBoxSetCurSel(lphl
, wRet
);
1028 InvalidateRect32( hwnd
, NULL
, TRUE
);
1032 else if (y
>= (rect
.bottom
-CBLMM_EDGE
)) {
1033 if (lphl
->FirstVisible
< ListMaxFirstVisible(lphl
)) {
1034 lphl
->FirstVisible
++;
1035 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1036 ListBoxSetCurSel(lphl
, wRet
);
1037 InvalidateRect32( hwnd
, NULL
, TRUE
);
1042 if ((short) wRet
== lphl
->ItemFocused
) return 0;
1043 ListBoxSetCurSel(lphl
, wRet
);
1044 InvalidateRect32( hwnd
, NULL
, TRUE
);
1051 /***********************************************************************
1054 static LRESULT
CBLVScroll( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1056 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
1059 y
= lphl
->FirstVisible
;
1063 if (lphl
->FirstVisible
> 0)
1064 lphl
->FirstVisible
--;
1068 lphl
->FirstVisible
++;
1072 if (lphl
->FirstVisible
> lphl
->ItemsVisible
) {
1073 lphl
->FirstVisible
-= lphl
->ItemsVisible
;
1075 lphl
->FirstVisible
= 0;
1080 lphl
->FirstVisible
+= lphl
->ItemsVisible
;
1084 lphl
->FirstVisible
= LOWORD(lParam
);
1088 if (lphl
->FirstVisible
> ListMaxFirstVisible(lphl
))
1089 lphl
->FirstVisible
= ListMaxFirstVisible(lphl
);
1091 if (y
!= lphl
->FirstVisible
) {
1092 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1093 InvalidateRect32( hwnd
, NULL
, TRUE
);
1100 /***********************************************************************
1103 static BOOL
CBLCheckSize(HWND hwnd
)
1105 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
1106 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
1109 RECT16 cRect
,wRect
,lRect
,lwRect
;
1113 GetClassName32A(hwnd
,className
,80);
1115 if (strncmp(className
,"COMBOBOX",8)) return FALSE
;
1116 if ((hWndLBox
= lphc
->hWndLBox
) == 0) return FALSE
;
1117 dprintf_combo(stddeb
,"CBLCheckSize headers hw %04x lb %04x name %s\n",
1118 hwnd
,hWndLBox
,className
);
1120 GetClientRect16(hwnd
,&cRect
);
1121 GetWindowRect16(hwnd
,&wRect
);
1122 GetClientRect16(hWndLBox
,&lRect
);
1123 GetWindowRect16(hWndLBox
,&lwRect
);
1125 dprintf_combo(stddeb
,"CBLCheckSize: init cRect %d,%d-%d,%d wRect %d,%d-%d,%d\n",
1126 cRect
.left
,cRect
.top
,cRect
.right
,cRect
.bottom
,
1127 wRect
.left
,wRect
.top
,wRect
.right
,wRect
.bottom
);
1128 dprintf_combo(stddeb
," lRect %d,%d-%d,%d lwRect %d,%d-%d,%d\n",
1129 lRect
.left
,lRect
.top
,lRect
.right
,lRect
.bottom
,
1130 lwRect
.left
,lwRect
.top
,lwRect
.right
,lwRect
.bottom
);
1134 for (lpls
=lphl
->lpFirst
; lpls
!= NULL
; lpls
=lpls
->lpNext
)
1135 totheight
+= lpls
->mis
.itemHeight
;
1137 dw
= cRect
.right
-cRect
.left
+2*SYSMETRICS_CXBORDER
+SYSMETRICS_CXVSCROLL
;
1138 dw
-= lwRect
.right
-lwRect
.left
;
1139 dw
-= SYSMETRICS_CXVSCROLL
;
1141 /* TODO: This isn't really what windows does */
1142 if ((lRect
.bottom
-lRect
.top
< 3*lphl
->StdItemHeight
) || dw
) {
1143 dprintf_combo(stddeb
," Changing; totHeight %d StdItemHght %d dw %d\n",
1144 totheight
,lphl
->StdItemHeight
,dw
);
1145 SetWindowPos(hWndLBox
, 0, lRect
.left
, lRect
.top
,
1146 lwRect
.right
-lwRect
.left
+dw
, totheight
+2*SYSMETRICS_CYBORDER
,
1147 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
| SWP_NOACTIVATE
);
1153 /***********************************************************************
1156 LRESULT
ComboLBoxWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1159 case WM_CREATE
: return CBLCreate(hwnd
, wParam
, lParam
);
1160 case WM_GETDLGCODE
: return CBLGetDlgCode(hwnd
, wParam
, lParam
);
1161 case WM_KEYDOWN
: return CBLKeyDown(hwnd
, wParam
, lParam
);
1162 case WM_CHAR
: return CBLChar(hwnd
, wParam
, lParam
);
1163 case WM_PAINT
: return CBLPaint(hwnd
, wParam
, lParam
);
1164 case WM_KILLFOCUS
: return CBLKillFocus(hwnd
, wParam
, lParam
);
1165 case WM_ACTIVATE
: return CBLActivate(hwnd
, wParam
, lParam
);
1166 case WM_LBUTTONDOWN
: return CBLLButtonDown(hwnd
, wParam
, lParam
);
1167 case WM_LBUTTONUP
: return CBLLButtonUp(hwnd
, wParam
, lParam
);
1168 case WM_MOUSEMOVE
: return CBLMouseMove(hwnd
, wParam
, lParam
);
1169 case WM_VSCROLL
: return CBLVScroll(hwnd
, wParam
, lParam
);
1170 case WM_SIZE
: return CBLCheckSize(hwnd
);
1172 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1175 /************************************************************************
1176 * DlgDirSelectComboBox [USER.194]
1178 BOOL
DlgDirSelectComboBox(HWND hDlg
, LPSTR lpStr
, INT nIDLBox
)
1180 fprintf(stdnimp
,"DlgDirSelectComboBox(%04x, '%s', %d) \n",
1181 hDlg
, lpStr
, nIDLBox
);
1185 static INT32
COMBO_DlgDirList( HWND32 hDlg
, LPARAM path
, INT32 idCBox
,
1186 INT32 idStatic
, UINT32 wType
, BOOL32 unicode
)
1192 SendDlgItemMessage32A( hDlg
, idCBox
, CB_RESETCONTENT
, 0, 0 );
1194 res
= SendDlgItemMessage32W( hDlg
, idCBox
, CB_DIR
, wType
, path
);
1196 res
= SendDlgItemMessage32A( hDlg
, idCBox
, CB_DIR
, wType
, path
);
1200 char temp
[512] = "A:\\";
1201 int drive
= DRIVE_GetCurrentDrive();
1203 lstrcpyn32A( temp
+ 3, DRIVE_GetDosCwd(drive
), sizeof(temp
)-3 );
1205 SetDlgItemText32A( hDlg
, idStatic
, temp
);
1211 /***********************************************************************
1212 * DlgDirListComboBox16 (USER.195)
1214 INT16
DlgDirListComboBox16( HWND16 hDlg
, LPCSTR path
, INT16 idCBox
,
1215 INT16 idStatic
, UINT16 wType
)
1217 dprintf_combo( stddeb
,"DlgDirListComboBox16(%04x,'%s',%d,%d,%04x)\n",
1218 hDlg
, path
, idCBox
, idStatic
, wType
);
1219 return COMBO_DlgDirList( hDlg
, (LPARAM
)path
, idCBox
,
1220 idStatic
, wType
, FALSE
);
1224 /***********************************************************************
1225 * DlgDirListComboBox32A (USER32.143)
1227 INT32
DlgDirListComboBox32A( HWND32 hDlg
, LPCSTR path
, INT32 idCBox
,
1228 INT32 idStatic
, UINT32 wType
)
1230 dprintf_combo( stddeb
,"DlgDirListComboBox32A(%08x,'%s',%d,%d,%08X)\n",
1231 hDlg
, path
, idCBox
, idStatic
, wType
);
1232 return COMBO_DlgDirList( hDlg
, (LPARAM
)path
, idCBox
,
1233 idStatic
, wType
, FALSE
);
1237 /***********************************************************************
1238 * DlgDirListComboBox32W (USER32.144)
1240 INT32
DlgDirListComboBox32W( HWND32 hDlg
, LPCWSTR path
, INT32 idCBox
,
1241 INT32 idStatic
, UINT32 wType
)
1243 dprintf_combo( stddeb
,"DlgDirListComboBox32W(%08x,%p,%d,%d,%08X)\n",
1244 hDlg
, path
, idCBox
, idStatic
, wType
);
1245 return COMBO_DlgDirList( hDlg
, (LPARAM
)path
, idCBox
,
1246 idStatic
, wType
, TRUE
);