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
= LoadBitmap(0, MAKEINTRESOURCE(OBM_COMBO
));
55 GetObject(hComboBit
, sizeof(BITMAP
), (LPSTR
)&bm
);
56 CBitHeight
= bm
.bmHeight
;
57 CBitWidth
= bm
.bmWidth
;
61 LPHEADCOMBO
ComboGetStorageHeader(HWND hwnd
)
63 return (LPHEADCOMBO
)GetWindowLong(hwnd
,4);
66 LPHEADLIST
ComboGetListHeader(HWND hwnd
)
68 return (LPHEADLIST
)GetWindowLong(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
= GetWindowLong(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 */
149 dprintf_combo(stddeb
,"CBS_SIMPLE\n");
150 style
= WS_BORDER
| WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
;
151 SetRectEmpty16(&lphc
->RectButton
);
155 case CBS_DROPDOWNLIST
: /* static control, dropdown listbox */
156 case CBS_DROPDOWN
: /* edit control, dropdown listbox */
157 GetWindowRect16(hwnd
,&lboxrect
);
158 style
= WS_POPUP
| WS_BORDER
| WS_VSCROLL
;
159 /* FIXME: WinSight says these should be CHILD windows with the TOPMOST flag
160 * set. Wine doesn't support TOPMOST, and simply setting the WS_CHILD
161 * flag doesn't work. */
162 lphc
->RectButton
= rect
;
163 lphc
->RectButton
.left
= lphc
->RectButton
.right
- 6 - CBitWidth
;
164 lphc
->RectButton
.bottom
= lphc
->RectButton
.top
+ lphl
->StdItemHeight
;
165 SetWindowPos(hwnd
, 0, 0, 0, rect
.right
- rect
.left
+ 2*SYSMETRICS_CXBORDER
,
166 lphl
->StdItemHeight
+ 2*SYSMETRICS_CYBORDER
,
167 SWP_NOMOVE
| SWP_NOZORDER
);
168 rect
.right
=lphc
->RectButton
.left
- 8;
169 dprintf_combo(stddeb
,(cstyle
& 3)==CBS_DROPDOWN
? "CBS_DROPDOWN\n": "CBS_DROPDOWNLIST\n");
172 default: fprintf(stderr
,"COMBOBOX error: bad class style!\n");
176 if ((cstyle
& 3) != CBS_DROPDOWNLIST
)
177 lphc
->hWndEdit
= CreateWindow16(MAKE_SEGPTR(editName
), (SEGPTR
)0,
178 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| ES_LEFT
| WS_BORDER
,
179 0, 0, rect
.right
, lphl
->StdItemHeight
,
180 hwnd
, (HMENU
)ID_EDIT
, WIN_GetWindowInstance(hwnd
), 0L);
182 lboxrect
.top
+=lphc
->LBoxTop
;
183 lphc
->hWndLBox
= CreateWindow16(MAKE_SEGPTR(className
), (SEGPTR
)0, style
|
184 ((cstyle
& WS_HSCROLL
)? WS_HSCROLL
: 0) |
185 ((cstyle
& WS_VSCROLL
)? WS_VSCROLL
: 0),
186 lboxrect
.left
, lboxrect
.top
,
187 lboxrect
.right
- lboxrect
.left
,
188 lboxrect
.bottom
- lboxrect
.top
,
189 hwndp
,(HMENU
)ID_CLB
, WIN_GetWindowInstance(hwnd
),
192 wndPtr
->dwStyle
&= ~(WS_VSCROLL
| WS_HSCROLL
);
194 dprintf_combo( stddeb
, "Combo Creation hwnd=%04x LBox=%04x Edit=%04x\n",
195 hwnd
, lphc
->hWndLBox
, lphc
->hWndEdit
);
196 dprintf_combo( stddeb
, " lbox %d,%d-%d,%d button %d,%d-%d,%d\n",
197 lboxrect
.left
, lboxrect
.top
, lboxrect
.right
, lboxrect
.bottom
,
198 lphc
->RectButton
.left
, lphc
->RectButton
.top
,
199 lphc
->RectButton
.right
, lphc
->RectButton
.bottom
);
200 dprintf_combo( stddeb
, " client %d,%d-%d,%d window %d,%d-%d,%d\n",
201 wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
,
202 wndPtr
->rectClient
.right
, wndPtr
->rectClient
.bottom
,
203 wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
204 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
);
208 /***********************************************************************
211 static LRESULT
CBDestroy(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
213 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
215 ListBoxResetContent(lphl
);
216 DestroyListBoxStruct(lphl
);
217 dprintf_combo(stddeb
,"Combo WM_DESTROY %p !\n", lphl
);
221 /***********************************************************************
224 static LRESULT
CBPaint(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
226 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
227 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
235 hdc
= BeginPaint16(hwnd
, &ps
);
236 if (hComboBit
!= 0 && !IsRectEmpty16(&lphc
->RectButton
))
238 GRAPH_DrawReliefRect(hdc
, &lphc
->RectButton
, 2, 2, FALSE
);
239 GRAPH_DrawBitmap(hdc
, hComboBit
,
240 lphc
->RectButton
.left
+ 2,lphc
->RectButton
.top
+ 2,
241 0, 0, CBitWidth
, CBitHeight
);
243 if (!IsWindowVisible(hwnd
) || !lphl
->bRedrawFlag
244 || (lphc
->dwStyle
& 3) != CBS_DROPDOWNLIST
)
246 /* we don't want to draw an entry when there is an edit control */
247 EndPaint16(hwnd
, &ps
);
251 hOldFont
= SelectObject(hdc
, lphl
->hFont
);
254 hBrush
= SendMessage32A(lphl
->hParent
, WM_CTLCOLORLISTBOX
, hdc
, hwnd
);
256 hBrush
= SendMessage16(lphl
->hParent
, WM_CTLCOLOR
, hdc
,
257 MAKELONG(hwnd
, CTLCOLOR_LISTBOX
));
259 if (hBrush
== 0) hBrush
= GetStockObject(WHITE_BRUSH
);
261 GetClientRect16(hwnd
, &rect
);
264 rect
.right
-= (lphc
->RectButton
.right
- lphc
->RectButton
.left
);
266 lpls
= ListBoxGetItem(lphl
,lphl
->ItemFocused
);
268 FillRect16(hdc
, &rect
, hBrush
);
269 ListBoxDrawItem (hwnd
, lphl
, hdc
, lpls
, &rect
, ODA_DRAWENTIRE
, 0);
270 if (GetFocus() == hwnd
)
271 ListBoxDrawItem (hwnd
,lphl
, hdc
, lpls
, &rect
, ODA_FOCUS
, ODS_FOCUS
);
273 else FillRect16(hdc
, &rect
, hBrush
);
274 SelectObject(hdc
,hOldFont
);
275 EndPaint16(hwnd
, &ps
);
279 /***********************************************************************
282 static LRESULT
CBGetDlgCode(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
284 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
287 /***********************************************************************
290 static LRESULT
CBLButtonDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
292 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
293 SendMessage16(hwnd
,CB_SHOWDROPDOWN
,!lphc
->DropDownVisible
,0);
297 /***********************************************************************
300 static LRESULT
CBKeyDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
302 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
303 WORD newFocused
= lphl
->ItemFocused
;
310 newFocused
= lphl
->ItemsCount
- 1;
313 if (newFocused
> 0) newFocused
--;
322 if (newFocused
>= lphl
->ItemsCount
)
323 newFocused
= lphl
->ItemsCount
- 1;
325 ListBoxSetCurSel(lphl
, newFocused
);
326 SendMessage16(hwnd
, WM_COMMAND
,ID_CLB
,MAKELONG(0,CBN_SELCHANGE
));
327 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
329 lphl
->ItemFocused
= newFocused
;
330 ListBoxScrollToFocus(lphl
);
331 /* SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);*/
332 InvalidateRect32( hwnd
, NULL
, TRUE
);
337 /***********************************************************************
340 static LRESULT
CBChar(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
342 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
345 newFocused
= ListBoxFindNextMatch(lphl
, wParam
);
346 if (newFocused
== (WORD
)LB_ERR
) return 0;
348 if (newFocused
>= lphl
->ItemsCount
)
349 newFocused
= lphl
->ItemsCount
- 1;
351 ListBoxSetCurSel(lphl
, newFocused
);
352 SendMessage16(hwnd
, WM_COMMAND
,ID_CLB
,MAKELONG(0,CBN_SELCHANGE
));
353 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
354 lphl
->ItemFocused
= newFocused
;
355 ListBoxScrollToFocus(lphl
);
357 /* SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);*/
358 InvalidateRect32( hwnd
, NULL
, TRUE
);
363 /***********************************************************************
366 static LRESULT
CBKillFocus(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
371 /***********************************************************************
374 static LRESULT
CBSetFocus(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
379 /***********************************************************************
382 static LRESULT
CBResetContent(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
384 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
385 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
387 ListBoxResetContent(lphl
);
388 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
392 /***********************************************************************
395 static LRESULT
CBDir(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
398 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
399 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
401 wRet
= ListBoxDirectory(lphl
, wParam
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
402 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
406 /***********************************************************************
409 static LRESULT
CBInsertString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
412 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
413 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
415 if (lphl
->HasStrings
)
416 wRet
= ListBoxInsertString(lphl
, wParam
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
418 wRet
= ListBoxInsertString(lphl
, wParam
, (LPSTR
)lParam
);
419 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
423 /***********************************************************************
426 static LRESULT
CBAddString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
429 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
430 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
432 if (lphl
->HasStrings
)
433 wRet
= ListBoxAddString(lphl
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
435 wRet
= ListBoxAddString(lphl
, (LPSTR
)lParam
);
437 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
441 /***********************************************************************
444 static LRESULT
CBDeleteString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
446 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
447 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
448 LONG lRet
= ListBoxDeleteString(lphl
,wParam
);
450 ComboUpdateWindow(hwnd
, lphl
, lphc
, TRUE
);
454 /***********************************************************************
457 static LRESULT
CBSelectString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
459 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
462 wRet
= ListBoxFindString(lphl
, wParam
, (SEGPTR
)lParam
);
464 /* XXX add functionality here */
469 /***********************************************************************
472 static LRESULT
CBFindString(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
474 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
475 return ListBoxFindString(lphl
, wParam
, (SEGPTR
)lParam
);
478 /***********************************************************************
481 static LRESULT
CBGetCount(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
483 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
484 return lphl
->ItemsCount
;
487 /***********************************************************************
490 static LRESULT
CBSetCurSel(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
492 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
495 wRet
= ListBoxSetCurSel(lphl
, wParam
);
497 dprintf_combo(stddeb
,"CBSetCurSel: hwnd %04x wp %x lp %lx wRet %d\n",
498 hwnd
,wParam
,lParam
,wRet
);
499 /* SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);*/
500 InvalidateRect32( hwnd
, NULL
, TRUE
);
505 /***********************************************************************
508 static LRESULT
CBGetCurSel(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
510 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
511 return lphl
->ItemFocused
;
514 /***********************************************************************
517 static LRESULT
CBGetItemHeight(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
519 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
520 LPLISTSTRUCT lpls
= ListBoxGetItem (lphl
, wParam
);
522 if (lpls
== NULL
) return LB_ERR
;
523 return lpls
->mis
.itemHeight
;
526 /***********************************************************************
529 static LRESULT
CBSetItemHeight(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
531 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
532 return ListBoxSetItemHeight(lphl
, wParam
, lParam
);
535 /***********************************************************************
538 static LRESULT
CBSetRedraw(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
540 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
541 lphl
->bRedrawFlag
= wParam
;
545 /***********************************************************************
548 static LRESULT
CBSetFont(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
550 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
551 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
554 lphl
->hFont
= GetStockObject(SYSTEM_FONT
);
556 lphl
->hFont
= (HFONT
)wParam
;
558 SendMessage16(lphc
->hWndEdit
,WM_SETFONT
,lphl
->hFont
,0);
562 /***********************************************************************
565 static LRESULT
CBGetLBTextLen(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
567 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
568 LPLISTSTRUCT lpls
= ListBoxGetItem(lphl
,wParam
);
570 if (lpls
== NULL
|| !lphl
->HasStrings
) return LB_ERR
;
571 return strlen(lpls
->itemText
);
574 /***********************************************************************
577 static LRESULT
CBGetLBText(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
579 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
580 return ListBoxGetText(lphl
, wParam
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
583 /***********************************************************************
586 static LRESULT
CBGetItemData(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
588 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
589 return ListBoxGetItemData(lphl
, wParam
);
592 /***********************************************************************
595 static LRESULT
CBSetItemData(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
597 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
598 return ListBoxSetItemData(lphl
, wParam
, lParam
);
601 /***********************************************************************
604 static LRESULT
CBShowDropDown(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
606 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
609 if ((lphc
->dwStyle
& 3) == CBS_SIMPLE
) return LB_ERR
;
612 if (wParam
!= lphc
->DropDownVisible
) {
613 lphc
->DropDownVisible
= wParam
;
614 GetWindowRect32(hwnd
,&rect
);
615 SetWindowPos(lphc
->hWndLBox
, 0, rect
.left
, rect
.top
+lphc
->LBoxTop
, 0, 0,
616 SWP_NOSIZE
| (wParam
? SWP_SHOWWINDOW
: SWP_HIDEWINDOW
));
617 if (!wParam
) SetFocus(hwnd
);
623 /***********************************************************************
626 static BOOL
CBCheckSize(HWND hwnd
)
628 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
629 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
630 LONG cstyle
= GetWindowLong(hwnd
,GWL_STYLE
);
633 /* TODO - The size of combo's and their listboxes is still broken */
635 if (lphc
->hWndLBox
== 0) return FALSE
;
637 GetClientRect16(hwnd
,&cRect
);
638 GetWindowRect16(hwnd
,&wRect
);
640 dprintf_combo(stddeb
,"CBCheckSize: cRect %d,%d-%d,%d wRect %d,%d-%d,%d\n",
641 cRect
.left
,cRect
.top
,cRect
.right
,cRect
.bottom
,
642 wRect
.left
,wRect
.top
,wRect
.right
,wRect
.bottom
);
643 if ((cstyle
& 3) == CBS_SIMPLE
) return TRUE
;
644 if ((cRect
.bottom
- cRect
.top
) >
645 (lphl
->StdItemHeight
+ 2*SYSMETRICS_CYBORDER
)) {
646 SetWindowPos(hwnd
, 0, 0, 0,
647 cRect
.right
-cRect
.left
,
648 lphl
->StdItemHeight
+2*SYSMETRICS_CYBORDER
,
649 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
| SWP_NOACTIVATE
);
650 GetClientRect16(hwnd
,&cRect
);
651 GetWindowRect16(hwnd
,&wRect
);
654 switch (cstyle
& 3) {
658 case CBS_DROPDOWNLIST
:
659 lphc
->RectButton
.right
= cRect
.right
;
660 lphc
->RectButton
.left
= cRect
.right
- 2*SYSMETRICS_CXBORDER
- 4
662 lphc
->RectButton
.top
= cRect
.top
;
663 lphc
->RectButton
.bottom
= cRect
.bottom
;
666 fprintf(stderr
,"CBCheckSize: style %lx not recognized!\n",cstyle
);
674 /***********************************************************************
677 static LRESULT
CBCommand(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
679 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
680 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
684 if (lphc
->hWndEdit
) /* interdependence only used for CBS_SIMPLE and CBS_DROPDOWN styles */
688 case ID_CLB
: /* update EDIT window */
689 if (HIWORD(lParam
)==CBN_SELCHANGE
)
690 if (lphl
->HasStrings
)
692 ListBoxGetText(lphl
,lphl
->ItemFocused
, buffer
);
693 dprintf_combo(stddeb
,"CBCommand: update Edit: %s\n",buffer
);
694 SetWindowText32A( lphc
->hWndEdit
, buffer
);
697 case ID_EDIT
: /* update LISTBOX window */
698 id
=GetWindowWord(hwnd
,GWW_ID
);
699 switch (HIWORD(lParam
))
701 case EN_UPDATE
:GetWindowText32A(lphc
->hWndEdit
,buffer
,255);
704 newFocused
=ListBoxFindString(lphl
, -1, MAKE_SEGPTR(buffer
));
705 dprintf_combo(stddeb
,"CBCommand: new selection #%d is= %s\n",
707 if (newFocused
!= (WORD
)LB_ERR
)
708 { /* if found something */
709 ListBoxSetCurSel(lphl
, newFocused
);
710 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
711 InvalidateRect32(hwnd
, NULL
, TRUE
);
714 SendMessage16(GetParent(hwnd
),WM_COMMAND
,id
,
715 MAKELONG(hwnd
, CBN_EDITUPDATE
));
717 case EN_CHANGE
:SendMessage16(GetParent(hwnd
),WM_COMMAND
,id
,
718 MAKELONG(hwnd
, CBN_EDITCHANGE
));
720 case EN_ERRSPACE
:SendMessage16(GetParent(hwnd
),WM_COMMAND
,id
,
721 MAKELONG(hwnd
, CBN_ERRSPACE
));
731 /***********************************************************************
734 LRESULT
ComboBoxWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
737 case WM_NCCREATE
: return CBNCCreate(hwnd
, wParam
, lParam
);
738 case WM_CREATE
: return CBCreate(hwnd
, wParam
, lParam
);
739 case WM_DESTROY
: return CBDestroy(hwnd
, wParam
, lParam
);
740 case WM_GETDLGCODE
: return CBGetDlgCode(hwnd
, wParam
, lParam
);
741 case WM_KEYDOWN
: return CBKeyDown(hwnd
, wParam
, lParam
);
742 case WM_CHAR
: return CBChar(hwnd
, wParam
, lParam
);
743 case WM_SETFONT
: return CBSetFont(hwnd
, wParam
, lParam
);
744 case WM_SETREDRAW
: return CBSetRedraw(hwnd
, wParam
, lParam
);
745 case WM_PAINT
: return CBPaint(hwnd
, wParam
, lParam
);
746 case WM_LBUTTONDOWN
: return CBLButtonDown(hwnd
, wParam
, lParam
);
747 case WM_SETFOCUS
: return CBSetFocus(hwnd
, wParam
, lParam
);
748 case WM_KILLFOCUS
: return CBKillFocus(hwnd
, wParam
, lParam
);
749 case WM_SIZE
: return CBCheckSize(hwnd
);
750 case WM_COMMAND
: return CBCommand(hwnd
, wParam
, lParam
);
751 case CB_RESETCONTENT
: return CBResetContent(hwnd
, wParam
, lParam
);
752 case CB_DIR
: return CBDir(hwnd
, wParam
, lParam
);
753 case CB_ADDSTRING
: return CBAddString(hwnd
, wParam
, lParam
);
754 case CB_INSERTSTRING
: return CBInsertString(hwnd
, wParam
, lParam
);
755 case CB_DELETESTRING
: return CBDeleteString(hwnd
, wParam
, lParam
);
756 case CB_FINDSTRING
: return CBFindString(hwnd
, wParam
, lParam
);
757 case CB_GETCOUNT
: return CBGetCount(hwnd
, wParam
, lParam
);
758 case CB_GETCURSEL
: return CBGetCurSel(hwnd
, wParam
, lParam
);
759 case CB_GETITEMDATA
: return CBGetItemData(hwnd
, wParam
, lParam
);
760 case CB_GETITEMHEIGHT
: return CBGetItemHeight(hwnd
, wParam
, lParam
);
761 case CB_GETLBTEXT
: return CBGetLBText(hwnd
, wParam
, lParam
);
762 case CB_GETLBTEXTLEN
: return CBGetLBTextLen(hwnd
, wParam
, lParam
);
763 case CB_SELECTSTRING
: return CBSelectString(hwnd
, wParam
, lParam
);
764 case CB_SETITEMDATA
: return CBSetItemData(hwnd
, wParam
, lParam
);
765 case CB_SETCURSEL
: return CBSetCurSel(hwnd
, wParam
, lParam
);
766 case CB_SETITEMHEIGHT
: return CBSetItemHeight(hwnd
, wParam
, lParam
);
767 case CB_SHOWDROPDOWN
: return CBShowDropDown(hwnd
, wParam
, lParam
);
769 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
772 /*--------------------------------------------------------------------*/
773 /* ComboLBox code starts here */
775 HWND
CLBoxGetCombo(HWND hwnd
)
778 return (HWND
)GetWindowLong(hwnd
,0);
780 return (HWND
)GetWindowWord(hwnd
,0);
784 LPHEADLIST
CLBoxGetListHeader(HWND hwnd
)
786 return ComboGetListHeader(CLBoxGetCombo(hwnd
));
789 /***********************************************************************
792 static LRESULT
CBLCreate( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
794 CREATESTRUCT16
*createStruct
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
796 SetWindowLong(hwnd
,0,(LONG
)createStruct
->lpCreateParams
);
798 SetWindowWord(hwnd
,0,LOWORD(createStruct
->lpCreateParams
));
803 /***********************************************************************
806 static LRESULT
CBLGetDlgCode( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
808 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
811 /***********************************************************************
814 static LRESULT
CBLKeyDown( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
816 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
817 WORD newFocused
= lphl
->ItemFocused
;
824 newFocused
= lphl
->ItemsCount
- 1;
827 if (newFocused
> 0) newFocused
--;
833 if (newFocused
> lphl
->ItemsVisible
) {
834 newFocused
-= lphl
->ItemsVisible
;
840 newFocused
+= lphl
->ItemsVisible
;
846 if (newFocused
>= lphl
->ItemsCount
)
847 newFocused
= lphl
->ItemsCount
- 1;
849 ListBoxSetCurSel(lphl
, newFocused
);
850 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
851 SendMessage16(GetParent(hwnd
), WM_COMMAND
,ID_CLB
,MAKELONG(0,CBN_SELCHANGE
));
852 lphl
->ItemFocused
= newFocused
;
853 ListBoxScrollToFocus(lphl
);
854 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
855 InvalidateRect32( hwnd
, NULL
, TRUE
);
859 /***********************************************************************
862 static LRESULT
CBLChar( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
867 /***********************************************************************
870 static LRESULT
CBLPaint( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
872 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
877 WND
* wndPtr
= WIN_FindWndPtr(hwnd
);
878 HWND combohwnd
= CLBoxGetCombo(hwnd
);
884 hdc
= BeginPaint16( hwnd
, &ps
);
886 if (!IsWindowVisible(hwnd
) || !lphl
->bRedrawFlag
) {
887 EndPaint16(hwnd
, &ps
);
891 hOldFont
= SelectObject(hdc
, lphl
->hFont
);
892 /* listboxes should be white */
893 hBrush
= GetStockObject(WHITE_BRUSH
);
895 GetClientRect16(hwnd
, &rect
);
896 FillRect16(hdc
, &rect
, hBrush
);
899 lpls
= lphl
->lpFirst
;
901 lphl
->ItemsVisible
= 0;
902 for(i
= 0; i
< lphl
->ItemsCount
; i
++) {
903 if (lpls
== NULL
) break;
905 if (i
>= lphl
->FirstVisible
) {
906 height
= lpls
->mis
.itemHeight
;
907 /* must have enough room to draw entire item */
908 if (top
> (rect
.bottom
-height
+1)) break;
910 lpls
->itemRect
.top
= top
;
911 lpls
->itemRect
.bottom
= top
+ height
;
912 lpls
->itemRect
.left
= rect
.left
;
913 lpls
->itemRect
.right
= rect
.right
;
915 dprintf_listbox(stddeb
,"drawing item: %d %d %d %d %d\n",
916 rect
.left
,top
,rect
.right
,top
+height
,lpls
->itemState
);
917 if (lphl
->OwnerDrawn
) {
918 ListBoxDrawItem (combohwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_DRAWENTIRE
, 0);
920 ListBoxDrawItem (combohwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_SELECT
, ODS_SELECTED
);
922 ListBoxDrawItem (combohwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_DRAWENTIRE
,
925 if ((lphl
->ItemFocused
== i
) && GetFocus() == hwnd
)
926 ListBoxDrawItem (combohwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_FOCUS
, ODS_FOCUS
);
929 lphl
->ItemsVisible
++;
935 if (wndPtr
->dwStyle
& WS_VSCROLL
)
936 SetScrollRange(hwnd
, SB_VERT
, 0, ListMaxFirstVisible(lphl
), TRUE
);
938 SelectObject(hdc
,hOldFont
);
939 EndPaint16( hwnd
, &ps
);
944 /***********************************************************************
947 static LRESULT
CBLKillFocus( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
949 /* SendMessage16(CLBoxGetCombo(hwnd),CB_SHOWDROPDOWN,0,0);*/
953 /***********************************************************************
956 static LRESULT
CBLActivate( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
958 if (wParam
== WA_INACTIVE
)
959 SendMessage16(CLBoxGetCombo(hwnd
),CB_SHOWDROPDOWN
,0,0);
963 /***********************************************************************
966 static LRESULT
CBLLButtonDown( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
968 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
975 lphl
->PrevFocused
= lphl
->ItemFocused
;
977 y
= ListBoxFindMouse(lphl
, LOWORD(lParam
), HIWORD(lParam
));
981 ListBoxSetCurSel(lphl
, y
);
982 ListBoxGetItemRect(lphl
, y
, &rectsel
);
984 InvalidateRect32( hwnd
, NULL
, TRUE
);
988 /***********************************************************************
991 static LRESULT
CBLLButtonUp( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
993 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
995 if (GetCapture() == hwnd
) ReleaseCapture();
999 fprintf(stdnimp
,"CBLLButtonUp: CLBoxGetListHeader returned NULL!\n");
1001 else if (lphl
->PrevFocused
!= lphl
->ItemFocused
)
1003 SendMessage16(CLBoxGetCombo(hwnd
),CB_SETCURSEL
,lphl
->ItemFocused
,0);
1004 SendMessage16(GetParent(hwnd
), WM_COMMAND
,ID_CLB
,MAKELONG(0,CBN_SELCHANGE
));
1005 ListBoxSendNotification(lphl
, CBN_SELCHANGE
);
1008 SendMessage16(CLBoxGetCombo(hwnd
),CB_SHOWDROPDOWN
,0,0);
1013 /***********************************************************************
1016 static LRESULT
CBLMouseMove( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1018 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
1021 RECT16 rect
, rectsel
;
1023 y
= SHIWORD(lParam
);
1024 wRet
= ListBoxFindMouse(lphl
, LOWORD(lParam
), HIWORD(lParam
));
1025 ListBoxGetItemRect(lphl
, wRet
, &rectsel
);
1026 GetClientRect16(hwnd
, &rect
);
1028 dprintf_combo(stddeb
,"CBLMouseMove: hwnd %04x wp %x lp %lx y %d if %d wret %d %d,%d-%d,%d\n",
1029 hwnd
,wParam
,lParam
,y
,lphl
->ItemFocused
,wRet
,rectsel
.left
,rectsel
.top
,rectsel
.right
,rectsel
.bottom
);
1031 if ((wParam
& MK_LBUTTON
) != 0) {
1032 if (y
< CBLMM_EDGE
) {
1033 if (lphl
->FirstVisible
> 0) {
1034 lphl
->FirstVisible
--;
1035 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1036 ListBoxSetCurSel(lphl
, wRet
);
1037 InvalidateRect32( hwnd
, NULL
, TRUE
);
1041 else if (y
>= (rect
.bottom
-CBLMM_EDGE
)) {
1042 if (lphl
->FirstVisible
< ListMaxFirstVisible(lphl
)) {
1043 lphl
->FirstVisible
++;
1044 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1045 ListBoxSetCurSel(lphl
, wRet
);
1046 InvalidateRect32( hwnd
, NULL
, TRUE
);
1051 if ((short) wRet
== lphl
->ItemFocused
) return 0;
1052 ListBoxSetCurSel(lphl
, wRet
);
1053 InvalidateRect32( hwnd
, NULL
, TRUE
);
1060 /***********************************************************************
1063 static LRESULT
CBLVScroll( HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1065 LPHEADLIST lphl
= CLBoxGetListHeader(hwnd
);
1068 y
= lphl
->FirstVisible
;
1072 if (lphl
->FirstVisible
> 0)
1073 lphl
->FirstVisible
--;
1077 lphl
->FirstVisible
++;
1081 if (lphl
->FirstVisible
> lphl
->ItemsVisible
) {
1082 lphl
->FirstVisible
-= lphl
->ItemsVisible
;
1084 lphl
->FirstVisible
= 0;
1089 lphl
->FirstVisible
+= lphl
->ItemsVisible
;
1093 lphl
->FirstVisible
= LOWORD(lParam
);
1097 if (lphl
->FirstVisible
> ListMaxFirstVisible(lphl
))
1098 lphl
->FirstVisible
= ListMaxFirstVisible(lphl
);
1100 if (y
!= lphl
->FirstVisible
) {
1101 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1102 InvalidateRect32( hwnd
, NULL
, TRUE
);
1109 /***********************************************************************
1112 static BOOL
CBLCheckSize(HWND hwnd
)
1114 LPHEADCOMBO lphc
= ComboGetStorageHeader(hwnd
);
1115 LPHEADLIST lphl
= ComboGetListHeader(hwnd
);
1118 RECT16 cRect
,wRect
,lRect
,lwRect
;
1122 GetClassName32A(hwnd
,className
,80);
1124 if (strncmp(className
,"COMBOBOX",8)) return FALSE
;
1125 if ((hWndLBox
= lphc
->hWndLBox
) == 0) return FALSE
;
1126 dprintf_combo(stddeb
,"CBLCheckSize headers hw %04x lb %04x name %s\n",
1127 hwnd
,hWndLBox
,className
);
1129 GetClientRect16(hwnd
,&cRect
);
1130 GetWindowRect16(hwnd
,&wRect
);
1131 GetClientRect16(hWndLBox
,&lRect
);
1132 GetWindowRect16(hWndLBox
,&lwRect
);
1134 dprintf_combo(stddeb
,"CBLCheckSize: init cRect %d,%d-%d,%d wRect %d,%d-%d,%d\n",
1135 cRect
.left
,cRect
.top
,cRect
.right
,cRect
.bottom
,
1136 wRect
.left
,wRect
.top
,wRect
.right
,wRect
.bottom
);
1137 dprintf_combo(stddeb
," lRect %d,%d-%d,%d lwRect %d,%d-%d,%d\n",
1138 lRect
.left
,lRect
.top
,lRect
.right
,lRect
.bottom
,
1139 lwRect
.left
,lwRect
.top
,lwRect
.right
,lwRect
.bottom
);
1143 for (lpls
=lphl
->lpFirst
; lpls
!= NULL
; lpls
=lpls
->lpNext
)
1144 totheight
+= lpls
->mis
.itemHeight
;
1146 /* TODO: This isn't really what windows does */
1147 if (lRect
.bottom
-lRect
.top
< 3*lphl
->StdItemHeight
) {
1148 dprintf_combo(stddeb
," Changing; totHeight %d StdItemHght %d\n",
1149 totheight
,lphl
->StdItemHeight
);
1150 SetWindowPos(hWndLBox
, 0, lRect
.left
, lRect
.top
,
1151 lwRect
.right
-lwRect
.left
, totheight
+2*SYSMETRICS_CYBORDER
,
1152 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
| SWP_NOACTIVATE
);
1158 /***********************************************************************
1161 LRESULT
ComboLBoxWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1164 case WM_CREATE
: return CBLCreate(hwnd
, wParam
, lParam
);
1165 case WM_GETDLGCODE
: return CBLGetDlgCode(hwnd
, wParam
, lParam
);
1166 case WM_KEYDOWN
: return CBLKeyDown(hwnd
, wParam
, lParam
);
1167 case WM_CHAR
: return CBLChar(hwnd
, wParam
, lParam
);
1168 case WM_PAINT
: return CBLPaint(hwnd
, wParam
, lParam
);
1169 case WM_KILLFOCUS
: return CBLKillFocus(hwnd
, wParam
, lParam
);
1170 case WM_ACTIVATE
: return CBLActivate(hwnd
, wParam
, lParam
);
1171 case WM_LBUTTONDOWN
: return CBLLButtonDown(hwnd
, wParam
, lParam
);
1172 case WM_LBUTTONUP
: return CBLLButtonUp(hwnd
, wParam
, lParam
);
1173 case WM_MOUSEMOVE
: return CBLMouseMove(hwnd
, wParam
, lParam
);
1174 case WM_VSCROLL
: return CBLVScroll(hwnd
, wParam
, lParam
);
1175 case WM_SIZE
: return CBLCheckSize(hwnd
);
1177 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1180 /************************************************************************
1181 * DlgDirSelectComboBox [USER.194]
1183 BOOL
DlgDirSelectComboBox(HWND hDlg
, LPSTR lpStr
, INT nIDLBox
)
1185 fprintf(stdnimp
,"DlgDirSelectComboBox(%04x, '%s', %d) \n",
1186 hDlg
, lpStr
, nIDLBox
);
1190 static INT32
COMBO_DlgDirList( HWND32 hDlg
, LPARAM path
, INT32 idCBox
,
1191 INT32 idStatic
, UINT32 wType
, BOOL32 unicode
)
1197 SendDlgItemMessage32A( hDlg
, idCBox
, CB_RESETCONTENT
, 0, 0 );
1199 res
= SendDlgItemMessage32W( hDlg
, idCBox
, CB_DIR
, wType
, path
);
1201 res
= SendDlgItemMessage32A( hDlg
, idCBox
, CB_DIR
, wType
, path
);
1205 char temp
[512] = "A:\\";
1206 int drive
= DRIVE_GetCurrentDrive();
1208 lstrcpyn( temp
+ 3, DRIVE_GetDosCwd(drive
), sizeof(temp
)-3 );
1210 SetDlgItemText32A( hDlg
, idStatic
, temp
);
1216 /***********************************************************************
1217 * DlgDirListComboBox16 (USER.195)
1219 INT16
DlgDirListComboBox16( HWND16 hDlg
, LPCSTR path
, INT16 idCBox
,
1220 INT16 idStatic
, UINT16 wType
)
1222 dprintf_combo( stddeb
,"DlgDirListComboBox16(%04x,'%s',%d,%d,%04x)\n",
1223 hDlg
, path
, idCBox
, idStatic
, wType
);
1224 return COMBO_DlgDirList( hDlg
, (LPARAM
)path
, idCBox
,
1225 idStatic
, wType
, FALSE
);
1229 /***********************************************************************
1230 * DlgDirListComboBox32A (USER32.143)
1232 INT32
DlgDirListComboBox32A( HWND32 hDlg
, LPCSTR path
, INT32 idCBox
,
1233 INT32 idStatic
, UINT32 wType
)
1235 dprintf_combo( stddeb
,"DlgDirListComboBox32A(%08x,'%s',%d,%d,%08X)\n",
1236 hDlg
, path
, idCBox
, idStatic
, wType
);
1237 return COMBO_DlgDirList( hDlg
, (LPARAM
)path
, idCBox
,
1238 idStatic
, wType
, FALSE
);
1242 /***********************************************************************
1243 * DlgDirListComboBox32W (USER32.144)
1245 INT32
DlgDirListComboBox32W( HWND32 hDlg
, LPCWSTR path
, INT32 idCBox
,
1246 INT32 idStatic
, UINT32 wType
)
1248 dprintf_combo( stddeb
,"DlgDirListComboBox32W(%08x,%p,%d,%d,%08X)\n",
1249 hDlg
, path
, idCBox
, idStatic
, wType
);
1250 return COMBO_DlgDirList( hDlg
, (LPARAM
)path
, idCBox
,
1251 idStatic
, wType
, TRUE
);