2 * Interface code to COMBOBOX widget
4 * Copyright Martin Ayotte, 1993
12 static char Copyright
[] = "Copyright Martin Ayotte, 1993";
16 #include <sys/types.h>
23 #include "prototypes.h"
25 HBITMAP hComboBit
= 0;
27 LPHEADCOMBO
ComboGetStorageHeader(HWND hwnd
);
28 int CreateComboStruct(HWND hwnd
);
31 /***********************************************************************
34 LONG
ComboBoxWndProc( HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
)
46 PAINTSTRUCT paintstruct
;
51 wndPtr
= WIN_FindWndPtr(hwnd
);
52 if (wndPtr
== NULL
) return 0;
54 printf("Combo WM_CREATE %lX !\n", lphc
);
56 if (hComboBit
== (HBITMAP
)NULL
)
57 hComboBit
= LoadBitmap((HINSTANCE
)NULL
, MAKEINTRESOURCE(OBM_COMBO
));
58 GetObject(hComboBit
, sizeof(BITMAP
), (LPSTR
)&bm
);
59 wndPtr
->dwStyle
&= 0xFFFFFFFFL
^ (WS_VSCROLL
| WS_HSCROLL
);
60 GetWindowRect(hwnd
, &rect
);
61 width
= rect
.right
- rect
.left
;
62 height
= rect
.bottom
- rect
.top
;
63 SetWindowPos(hwnd
, 0, 0, 0, width
+ bm
.bmHeight
, bm
.bmHeight
,
64 SWP_NOMOVE
| SWP_NOZORDER
);
65 CreateComboStruct(hwnd
);
66 lphc
= ComboGetStorageHeader(hwnd
);
67 if (lphc
== NULL
) return 0;
68 if (wndPtr
->dwStyle
& CBS_SIMPLE
)
69 /* lphc->hWndEdit = CreateWindow("EDIT", "", */
70 lphc
->hWndEdit
= CreateWindow("STATIC", "",
71 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| SS_LEFT
,
72 0, 0, width
- bm
.bmHeight
, bm
.bmHeight
,
73 hwnd
, 1, wndPtr
->hInstance
, 0L);
75 lphc
->hWndEdit
= CreateWindow("STATIC", "",
76 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| SS_LEFT
,
77 0, 0, width
- bm
.bmHeight
, bm
.bmHeight
,
78 hwnd
, 1, wndPtr
->hInstance
, 0L);
79 lphc
->hWndLBox
= CreateWindow("LISTBOX", "",
80 WS_CHILD
| WS_CLIPCHILDREN
| WS_BORDER
| WS_VSCROLL
| LBS_NOTIFY
,
81 wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
+ bm
.bmHeight
,
82 width
, height
, wndPtr
->hwndParent
, 1,
83 wndPtr
->hInstance
, (LPSTR
)MAKELONG(0, hwnd
));
84 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
86 printf("Combo Creation LBox=%X!\n", lphc
->hWndLBox
);
90 lphc
= ComboGetStorageHeader(hwnd
);
91 if (lphc
== 0) return 0;
93 DestroyWindow(lphc->hWndEdit);
95 DestroyWindow(lphc
->hWndLBox
);
98 *((LPHEADCOMBO *)&wndPtr->wExtra[1]) = 0;
99 printf("Combo WM_DESTROY after clearing wExtra !\n");
102 printf("Combo WM_DESTROY %lX !\n", lphc
);
104 return DefWindowProc( hwnd
, message
, wParam
, lParam
);
107 wndPtr
= WIN_FindWndPtr(hwnd
);
108 lphc
= ComboGetStorageHeader(hwnd
);
109 if (lphc
== NULL
) return 0;
110 if (LOWORD(lParam
) == lphc
->hWndLBox
) {
111 switch(HIWORD(lParam
)) {
113 lphc
->dwState
= lphc
->dwState
& (CB_SHOWDROPDOWN
^ 0xFFFFFFFFL
);
114 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
115 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
117 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
118 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
120 SendMessage(GetParent(hwnd
), WM_COMMAND
, wndPtr
->wIDmenu
,
121 MAKELONG(hwnd
, CBN_SELCHANGE
));
124 SendMessage(GetParent(hwnd
), WM_COMMAND
, wndPtr
->wIDmenu
,
125 MAKELONG(hwnd
, CBN_DBLCLK
));
131 printf("Combo WM_LBUTTONDOWN wParam=%x lParam=%lX !\n", wParam
, lParam
);
132 GetClientRect(hwnd
, &rect
);
133 rect
.left
= rect
.right
- (rect
.bottom
- rect
.top
);
135 InflateRect(&rect
, -1, -1);
136 DrawReliefRect(hDC
, rect
, 1, 1);
137 ReleaseDC(hwnd
, hDC
);
138 wndPtr
= WIN_FindWndPtr(hwnd
);
139 lphc
= ComboGetStorageHeader(hwnd
);
140 lphc
->dwState
= lphc
->dwState
^ CB_SHOWDROPDOWN
;
141 if ((lphc
->dwState
& CB_SHOWDROPDOWN
) == CB_SHOWDROPDOWN
) {
142 ShowWindow(lphc
->hWndLBox
, SW_SHOW
);
143 SetFocus(lphc
->hWndLBox
);
146 SetFocus(lphc
->hWndEdit
);
147 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
148 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
150 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
151 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
156 printf("Combo WM_LBUTTONUP wParam=%x lParam=%lX !\n", wParam
, lParam
);
157 GetClientRect(hwnd
, &rect
);
158 rect
.left
= rect
.right
- (rect
.bottom
- rect
.top
);
160 InflateRect(&rect
, -1, -1);
161 DrawReliefRect(hDC
, rect
, 1, 0);
162 ReleaseDC(hwnd
, hDC
);
165 wndPtr
= WIN_FindWndPtr(hwnd
);
166 lphc
= ComboGetStorageHeader(hwnd
);
167 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
168 count
= SendMessage(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0L);
169 printf("COMBOBOX // GetKeyState(VK_MENU)=%d\n", GetKeyState(VK_MENU
));
170 if (GetKeyState(VK_MENU
) < 0) {
171 lphc
->dwState
= lphc
->dwState
^ CB_SHOWDROPDOWN
;
172 if ((lphc
->dwState
& CB_SHOWDROPDOWN
) == CB_SHOWDROPDOWN
) {
173 ShowWindow(lphc
->hWndLBox
, SW_SHOW
);
174 SetFocus(lphc
->hWndLBox
);
177 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
178 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
180 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
181 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
201 if (y
>= count
) y
= count
- 1;
202 SendMessage(lphc
->hWndLBox
, LB_SETCURSEL
, y
, 0L);
203 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
204 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
205 SendMessage(GetParent(hwnd
), WM_COMMAND
, wndPtr
->wIDmenu
,
206 MAKELONG(hwnd
, CBN_SELCHANGE
));
210 printf("ComboBoxWndProc WM_MEASUREITEM !\n");
211 return(SendMessage(GetParent(hwnd
), WM_MEASUREITEM
, wParam
, lParam
));
213 return(SendMessage(GetParent(hwnd
), WM_CTLCOLOR
, wParam
, lParam
));
215 GetClientRect(hwnd
, &rect
);
216 hDC
= BeginPaint(hwnd
, &paintstruct
);
217 hMemDC
= CreateCompatibleDC(hDC
);
218 GetObject(hComboBit
, sizeof(BITMAP
), (LPSTR
)&bm
);
219 SelectObject(hMemDC
, hComboBit
);
220 BitBlt(hDC
, rect
.right
- bm
.bmWidth
, 0,
221 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
223 EndPaint(hwnd
, &paintstruct
);
224 lphc
= ComboGetStorageHeader(hwnd
);
225 InvalidateRect(lphc
->hWndEdit
, NULL
, TRUE
);
226 UpdateWindow(lphc
->hWndEdit
);
227 if ((lphc
->dwState
& CB_SHOWDROPDOWN
) == CB_SHOWDROPDOWN
) {
228 InvalidateRect(lphc
->hWndLBox
, NULL
, TRUE
);
229 UpdateWindow(lphc
->hWndLBox
);
233 lphc
= ComboGetStorageHeader(hwnd
);
234 SetFocus(lphc
->hWndEdit
);
237 lphc
= ComboGetStorageHeader(hwnd
);
238 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
239 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
241 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
242 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
247 printf("CB_ADDSTRING '%s' !\n", (LPSTR
)lParam
);
249 lphc
= ComboGetStorageHeader(hwnd
);
250 return(SendMessage(lphc
->hWndLBox
, LB_ADDSTRING
, wParam
, lParam
));
252 printf("CB_GETLBTEXT #%u !\n", wParam
);
253 lphc
= ComboGetStorageHeader(hwnd
);
254 return(SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
));
255 case CB_GETLBTEXTLEN
:
256 printf("CB_GETLBTEXTLEN !\n");
257 lphc
= ComboGetStorageHeader(hwnd
);
258 return(SendMessage(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, lParam
));
259 case CB_INSERTSTRING
:
260 printf("CB_INSERTSTRING '%s' !\n", (LPSTR
)lParam
);
261 lphc
= ComboGetStorageHeader(hwnd
);
262 return(SendMessage(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
));
263 case CB_DELETESTRING
:
264 printf("CB_DELETESTRING #%u !\n", wParam
);
265 lphc
= ComboGetStorageHeader(hwnd
);
266 return(SendMessage(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0L));
267 case CB_RESETCONTENT
:
268 printf("CB_RESETCONTENT !\n");
269 lphc
= ComboGetStorageHeader(hwnd
);
270 return(SendMessage(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0L));
272 printf("ComboBox CB_DIR !\n");
273 lphc
= ComboGetStorageHeader(hwnd
);
274 return(SendMessage(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
));
276 lphc
= ComboGetStorageHeader(hwnd
);
277 return(SendMessage(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
));
279 lphc
= ComboGetStorageHeader(hwnd
);
280 return(SendMessage(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0L));
282 printf("ComboBox CB_GETCURSEL !\n");
283 lphc
= ComboGetStorageHeader(hwnd
);
284 return(SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L));
286 printf("ComboBox CB_SETCURSEL wParam=%X !\n", wParam
);
287 lphc
= ComboGetStorageHeader(hwnd
);
288 return(SendMessage(lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0L));
290 printf("ComboBox CB_GETEDITSEL !\n");
291 lphc
= ComboGetStorageHeader(hwnd
);
292 /* return(SendMessage(lphc->hWndEdit, EM_GETSEL, 0, 0L)); */
295 printf("ComboBox CB_SETEDITSEL lParam=%lX !\n", lParam
);
296 lphc
= ComboGetStorageHeader(hwnd
);
297 /* return(SendMessage(lphc->hWndEdit, EM_SETSEL, 0, lParam)); */
299 case CB_SELECTSTRING
:
300 printf("ComboBox CB_SELECTSTRING !\n");
301 lphc
= ComboGetStorageHeader(hwnd
);
303 case CB_SHOWDROPDOWN
:
304 printf("ComboBox CB_SHOWDROPDOWN !\n");
305 lphc
= ComboGetStorageHeader(hwnd
);
306 lphc
->dwState
= lphc
->dwState
| CB_SHOWDROPDOWN
;
308 ShowWindow(lphc
->hWndLBox
, SW_SHOW
);
311 lphc
->dwState
= lphc
->dwState
^ CB_SHOWDROPDOWN
;
312 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
313 SendMessage(GetParent(hwnd
), WM_COMMAND
, wndPtr
->wIDmenu
,
314 MAKELONG(hwnd
, CBN_DROPDOWN
));
318 printf("ComboBox CB_GETITEMDATA wParam=%X !\n", wParam
);
319 lphc
= ComboGetStorageHeader(hwnd
);
320 return(SendMessage(lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0L));
323 printf("ComboBox CB_SETITEMDATA wParam=%X lParam=%lX !\n", wParam
, lParam
);
324 lphc
= ComboGetStorageHeader(hwnd
);
325 return(SendMessage(lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
));
328 printf("ComboBox CB_LIMITTEXT !\n");
329 lphc
= ComboGetStorageHeader(hwnd
);
330 /* return(SendMessage(lphc->hWndEdit, EM_LIMITTEXT, wParam, 0L)); */
334 return DefWindowProc( hwnd
, message
, wParam
, lParam
);
341 LPHEADCOMBO
ComboGetStorageHeader(HWND hwnd
)
345 wndPtr
= WIN_FindWndPtr(hwnd
);
347 printf("Bad Window handle on ComboBox !\n");
350 lphc
= *((LPHEADCOMBO
*)&wndPtr
->wExtra
[1]);
356 int CreateComboStruct(HWND hwnd
)
360 wndPtr
= WIN_FindWndPtr(hwnd
);
362 printf("Bad Window handle on ComboBox !\n");
365 lphc
= (LPHEADCOMBO
)malloc(sizeof(HEADCOMBO
));
366 *((LPHEADCOMBO
*)&wndPtr
->wExtra
[1]) = lphc
;