2 * Interface code to COMBOBOX widget
4 * Copyright Martin Ayotte, 1993
8 static char Copyright
[] = "Copyright Martin Ayotte, 1993";
12 #include <sys/types.h>
19 #include "prototypes.h"
21 /* #define DEBUG_COMBO */
22 /* #undef DEBUG_COMBO */
26 HBITMAP hComboBit
= 0;
28 LPHEADCOMBO
ComboGetStorageHeader(HWND hwnd
);
29 int CreateComboStruct(HWND hwnd
);
32 /***********************************************************************
35 LONG
ComboBoxWndProc( HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
)
45 PAINTSTRUCT paintstruct
;
50 wndPtr
= WIN_FindWndPtr(hwnd
);
51 if (wndPtr
== NULL
) return 0;
52 dprintf_combo(stddeb
,"Combo WM_CREATE %p !\n", lphc
);
53 if (hComboBit
== (HBITMAP
)NULL
)
54 hComboBit
= LoadBitmap((HINSTANCE
)NULL
, MAKEINTRESOURCE(OBM_COMBO
));
55 GetObject(hComboBit
, sizeof(BITMAP
), (LPSTR
)&bm
);
56 wndPtr
->dwStyle
&= 0xFFFFFFFFL
^ (WS_VSCROLL
| WS_HSCROLL
);
57 GetWindowRect(hwnd
, &rect
);
58 width
= rect
.right
- rect
.left
;
59 height
= rect
.bottom
- rect
.top
;
60 SetWindowPos(hwnd
, 0, 0, 0, width
+ bm
.bmHeight
, bm
.bmHeight
,
61 SWP_NOMOVE
| SWP_NOZORDER
);
62 CreateComboStruct(hwnd
);
63 lphc
= ComboGetStorageHeader(hwnd
);
64 if (lphc
== NULL
) return 0;
65 if (wndPtr
->dwStyle
& CBS_SIMPLE
)
66 /* lphc->hWndEdit = CreateWindow("EDIT", "", */
67 lphc
->hWndEdit
= CreateWindow("STATIC", "",
68 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| SS_LEFT
,
69 0, 0, width
- bm
.bmHeight
, bm
.bmHeight
,
70 hwnd
, 1, wndPtr
->hInstance
, 0L);
72 lphc
->hWndEdit
= CreateWindow("STATIC", "",
73 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| SS_LEFT
,
74 0, 0, width
- bm
.bmHeight
, bm
.bmHeight
,
75 hwnd
, 1, wndPtr
->hInstance
, 0L);
77 if ((wndPtr
->dwStyle
& CBS_HASSTRINGS
) == CBS_HASSTRINGS
)
78 style
|= LBS_HASSTRINGS
;
79 if ((wndPtr
->dwStyle
& CBS_OWNERDRAWFIXED
) ==CBS_OWNERDRAWFIXED
)
80 style
|= LBS_OWNERDRAWFIXED
;
81 if ((wndPtr
->dwStyle
& CBS_OWNERDRAWVARIABLE
)==CBS_OWNERDRAWVARIABLE
)
82 style
|= LBS_OWNERDRAWVARIABLE
;
83 lphc
->hWndLBox
= CreateWindow("LISTBOX", "",
84 WS_POPUP
| WS_BORDER
| WS_VSCROLL
| LBS_NOTIFY
| style
,
85 rect
.left
, rect
.top
+ bm
.bmHeight
,
86 width
, height
, wndPtr
->hwndParent
, 0,
87 wndPtr
->hInstance
, (LPSTR
)MAKELONG(0, hwnd
));
88 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
89 dprintf_combo(stddeb
,"Combo Creation LBox=%X!\n",
93 lphc
= ComboGetStorageHeader(hwnd
);
94 if (lphc
== 0) return 0;
96 DestroyWindow(lphc->hWndEdit);
98 DestroyWindow(lphc
->hWndLBox
);
101 *((LPHEADCOMBO *)&wndPtr->wExtra[1]) = 0;
102 printf("Combo WM_DESTROY after clearing wExtra !\n");
104 dprintf_combo(stddeb
,"Combo WM_DESTROY %p !\n", lphc
);
105 return DefWindowProc( hwnd
, message
, wParam
, lParam
);
107 dprintf_combo(stddeb
,"ComboBox WM_SHOWWINDOW hWnd=%04X !\n",
109 if (!(wParam
== 0 && lParam
== 0L)) {
110 InvalidateRect(hwnd
, NULL
, TRUE
);
115 wndPtr
= WIN_FindWndPtr(hwnd
);
116 lphc
= ComboGetStorageHeader(hwnd
);
117 if (lphc
== NULL
) return 0;
118 if (LOWORD(lParam
) == lphc
->hWndLBox
) {
119 switch(HIWORD(lParam
)) {
121 lphc
->dwState
= lphc
->dwState
& (CB_SHOWDROPDOWN
^ 0xFFFFFFFFL
);
122 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
123 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
125 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
126 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
128 SendMessage(GetParent(hwnd
), WM_COMMAND
, wndPtr
->wIDmenu
,
129 MAKELONG(hwnd
, CBN_SELCHANGE
));
132 SendMessage(GetParent(hwnd
), WM_COMMAND
, wndPtr
->wIDmenu
,
133 MAKELONG(hwnd
, CBN_DBLCLK
));
139 dprintf_combo(stddeb
,"Combo WM_LBUTTONDOWN wParam=%x lParam=%lX !\n", wParam
, lParam
);
140 GetClientRect(hwnd
, &rect
);
141 rect
.left
= rect
.right
- (rect
.bottom
- rect
.top
);
143 InflateRect(&rect
, -1, -1);
144 GRAPH_DrawReliefRect(hDC
, &rect
, 1, 1);
145 ReleaseDC(hwnd
, hDC
);
146 wndPtr
= WIN_FindWndPtr(hwnd
);
147 lphc
= ComboGetStorageHeader(hwnd
);
148 if (lphc
== NULL
) return 0;
149 lphc
->dwState
= lphc
->dwState
^ CB_SHOWDROPDOWN
;
150 if ((lphc
->dwState
& CB_SHOWDROPDOWN
) == CB_SHOWDROPDOWN
) {
151 ShowWindow(lphc
->hWndLBox
, SW_SHOW
);
152 SetFocus(lphc
->hWndLBox
);
155 dprintf_combo(stddeb
,"before Combo Restore Focus !\n");
156 SetFocus(lphc
->hWndEdit
);
157 dprintf_combo(stddeb
,"before Combo List Hide !\n");
158 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
159 dprintf_combo(stddeb
,"before Combo List GetCurSel !\n");
160 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
162 dprintf_combo(stddeb
,"before Combo List GetText !\n");
163 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
164 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
166 dprintf_combo(stddeb
,"End of Combo List Hide !\n");
170 dprintf_combo(stddeb
,"Combo WM_LBUTTONUP wParam=%x lParam=%lX !\n", wParam
, lParam
);
171 GetClientRect(hwnd
, &rect
);
172 rect
.left
= rect
.right
- (rect
.bottom
- rect
.top
);
174 InflateRect(&rect
, -1, -1);
175 GRAPH_DrawReliefRect(hDC
, &rect
, 1, 0);
176 ReleaseDC(hwnd
, hDC
);
179 wndPtr
= WIN_FindWndPtr(hwnd
);
180 lphc
= ComboGetStorageHeader(hwnd
);
181 if (lphc
== NULL
) return 0;
182 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
183 count
= SendMessage(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0L);
184 dprintf_combo(stddeb
,"COMBOBOX // GetKeyState(VK_MENU)=%d\n", GetKeyState(VK_MENU
));
185 if (GetKeyState(VK_MENU
) < 0) {
186 lphc
->dwState
= lphc
->dwState
^ CB_SHOWDROPDOWN
;
187 if ((lphc
->dwState
& CB_SHOWDROPDOWN
) == CB_SHOWDROPDOWN
) {
188 ShowWindow(lphc
->hWndLBox
, SW_SHOW
);
189 SetFocus(lphc
->hWndLBox
);
192 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
193 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
195 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
196 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
216 if (y
>= count
) y
= count
- 1;
217 SendMessage(lphc
->hWndLBox
, LB_SETCURSEL
, y
, 0L);
218 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
219 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
220 SendMessage(GetParent(hwnd
), WM_COMMAND
, wndPtr
->wIDmenu
,
221 MAKELONG(hwnd
, CBN_SELCHANGE
));
225 dprintf_combo(stddeb
,"ComboBoxWndProc WM_MEASUREITEM !\n");
226 return(SendMessage(GetParent(hwnd
), WM_MEASUREITEM
, wParam
, lParam
));
228 return(SendMessage(GetParent(hwnd
), WM_CTLCOLOR
, wParam
, lParam
));
230 return(SendMessage(GetParent(hwnd
), WM_DRAWITEM
, wParam
, lParam
));
232 GetClientRect(hwnd
, &rect
);
233 hDC
= BeginPaint(hwnd
, &paintstruct
);
234 if (hComboBit
!= 0) {
235 GetObject(hComboBit
, sizeof(BITMAP
), (LPSTR
)&bm
);
236 GRAPH_DrawBitmap( hDC
, hComboBit
,
237 rect
.right
- bm
.bmWidth
, 0,
238 0, 0, bm
.bmWidth
, bm
.bmHeight
,
241 EndPaint(hwnd
, &paintstruct
);
242 lphc
= ComboGetStorageHeader(hwnd
);
243 if (lphc
== NULL
) return 0;
244 InvalidateRect(lphc
->hWndEdit
, NULL
, TRUE
);
245 UpdateWindow(lphc
->hWndEdit
);
246 if ((lphc
->dwState
& CB_SHOWDROPDOWN
) == CB_SHOWDROPDOWN
) {
247 InvalidateRect(lphc
->hWndLBox
, NULL
, TRUE
);
248 UpdateWindow(lphc
->hWndLBox
);
252 lphc
= ComboGetStorageHeader(hwnd
);
253 if (lphc
== NULL
) return 0;
254 SetFocus(lphc
->hWndEdit
);
257 lphc
= ComboGetStorageHeader(hwnd
);
258 if (lphc
== NULL
) return 0;
259 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
260 y
= SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L);
262 SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, (WORD
)y
, (LPARAM
)str
);
263 SendMessage(lphc
->hWndEdit
, WM_SETTEXT
, (WORD
)y
, (LPARAM
)str
);
267 dprintf_combo(stddeb
,"CB_ADDSTRING '%s' !\n", (LPSTR
)lParam
);
268 lphc
= ComboGetStorageHeader(hwnd
);
269 if (lphc
== NULL
) return 0;
270 return(SendMessage(lphc
->hWndLBox
, LB_ADDSTRING
, wParam
, lParam
));
272 dprintf_combo(stddeb
,"CB_GETLBTEXT #%u !\n", wParam
);
273 lphc
= ComboGetStorageHeader(hwnd
);
274 if (lphc
== NULL
) return 0;
275 return(SendMessage(lphc
->hWndLBox
, LB_GETTEXT
, wParam
, lParam
));
276 case CB_GETLBTEXTLEN
:
277 dprintf_combo(stddeb
,"CB_GETLBTEXTLEN !\n");
278 lphc
= ComboGetStorageHeader(hwnd
);
279 if (lphc
== NULL
) return 0;
280 return(SendMessage(lphc
->hWndLBox
, LB_GETTEXTLEN
, wParam
, lParam
));
281 case CB_INSERTSTRING
:
282 dprintf_combo(stddeb
,"CB_INSERTSTRING '%s' !\n",(LPSTR
)lParam
);
283 lphc
= ComboGetStorageHeader(hwnd
);
284 if (lphc
== NULL
) return 0;
285 return(SendMessage(lphc
->hWndLBox
, LB_INSERTSTRING
, wParam
, lParam
));
286 case CB_DELETESTRING
:
287 dprintf_combo(stddeb
,"CB_DELETESTRING #%u !\n", wParam
);
288 lphc
= ComboGetStorageHeader(hwnd
);
289 if (lphc
== NULL
) return 0;
290 return(SendMessage(lphc
->hWndLBox
, LB_DELETESTRING
, wParam
, 0L));
291 case CB_RESETCONTENT
:
292 dprintf_combo(stddeb
,"CB_RESETCONTENT !\n");
293 lphc
= ComboGetStorageHeader(hwnd
);
294 if (lphc
== NULL
) return 0;
295 return(SendMessage(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0L));
297 dprintf_combo(stddeb
,"ComboBox CB_DIR !\n");
298 lphc
= ComboGetStorageHeader(hwnd
);
299 if (lphc
== NULL
) return 0;
300 return(SendMessage(lphc
->hWndLBox
, LB_DIR
, wParam
, lParam
));
302 lphc
= ComboGetStorageHeader(hwnd
);
303 return(SendMessage(lphc
->hWndLBox
, LB_FINDSTRING
, wParam
, lParam
));
305 lphc
= ComboGetStorageHeader(hwnd
);
306 if (lphc
== NULL
) return 0;
307 return(SendMessage(lphc
->hWndLBox
, LB_GETCOUNT
, 0, 0L));
309 dprintf_combo(stddeb
,"ComboBox CB_GETCURSEL !\n");
310 lphc
= ComboGetStorageHeader(hwnd
);
311 if (lphc
== NULL
) return 0;
312 return(SendMessage(lphc
->hWndLBox
, LB_GETCURSEL
, 0, 0L));
314 dprintf_combo(stddeb
,"ComboBox CB_SETCURSEL wParam=%X !\n", wParam
);
315 lphc
= ComboGetStorageHeader(hwnd
);
316 if (lphc
== NULL
) return 0;
317 return(SendMessage(lphc
->hWndLBox
, LB_SETCURSEL
, wParam
, 0L));
319 dprintf_combo(stddeb
,"ComboBox CB_GETEDITSEL !\n");
320 lphc
= ComboGetStorageHeader(hwnd
);
321 if (lphc
== NULL
) return 0;
322 /* return(SendMessage(lphc->hWndEdit, EM_GETSEL, 0, 0L)); */
325 dprintf_combo(stddeb
,"ComboBox CB_SETEDITSEL lParam=%lX !\n",
327 lphc
= ComboGetStorageHeader(hwnd
);
328 if (lphc
== NULL
) return 0;
329 /* return(SendMessage(lphc->hWndEdit, EM_SETSEL, 0, lParam)); */
331 case CB_SELECTSTRING
:
332 dprintf_combo(stddeb
,"ComboBox CB_SELECTSTRING !\n");
333 lphc
= ComboGetStorageHeader(hwnd
);
334 if (lphc
== NULL
) return 0;
336 case CB_SHOWDROPDOWN
:
337 dprintf_combo(stddeb
,"ComboBox CB_SHOWDROPDOWN !\n");
338 lphc
= ComboGetStorageHeader(hwnd
);
339 if (lphc
== NULL
) return 0;
340 lphc
->dwState
= lphc
->dwState
| CB_SHOWDROPDOWN
;
342 ShowWindow(lphc
->hWndLBox
, SW_SHOW
);
345 lphc
->dwState
= lphc
->dwState
^ CB_SHOWDROPDOWN
;
346 ShowWindow(lphc
->hWndLBox
, SW_HIDE
);
347 SendMessage(GetParent(hwnd
), WM_COMMAND
, wndPtr
->wIDmenu
,
348 MAKELONG(hwnd
, CBN_DROPDOWN
));
352 dprintf_combo(stddeb
,"ComboBox CB_GETITEMDATA wParam=%X !\n", wParam
);
353 lphc
= ComboGetStorageHeader(hwnd
);
354 if (lphc
== NULL
) return 0;
355 return(SendMessage(lphc
->hWndLBox
, LB_GETITEMDATA
, wParam
, 0L));
358 dprintf_combo(stddeb
,"ComboBox CB_SETITEMDATA wParam=%04X lParam=%08lX!\n", wParam
, lParam
);
359 lphc
= ComboGetStorageHeader(hwnd
);
360 if (lphc
== NULL
) return 0;
361 return(SendMessage(lphc
->hWndLBox
, LB_SETITEMDATA
, wParam
, lParam
));
364 dprintf_combo(stddeb
,"ComboBox CB_LIMITTEXT !\n");
365 lphc
= ComboGetStorageHeader(hwnd
);
366 if (lphc
== NULL
) return 0;
367 /* return(SendMessage(lphc->hWndEdit, EM_LIMITTEXT, wParam, 0L)); */
371 return DefWindowProc( hwnd
, message
, wParam
, lParam
);
378 LPHEADCOMBO
ComboGetStorageHeader(HWND hwnd
)
382 wndPtr
= WIN_FindWndPtr(hwnd
);
384 fprintf(stderr
,"Bad Window handle on ComboBox !\n");
387 lphc
= *((LPHEADCOMBO
*)&wndPtr
->wExtra
[1]);
393 int CreateComboStruct(HWND hwnd
)
397 wndPtr
= WIN_FindWndPtr(hwnd
);
399 fprintf(stderr
,"Bad Window handle on ComboBox !\n");
402 lphc
= (LPHEADCOMBO
)malloc(sizeof(HEADCOMBO
));
403 *((LPHEADCOMBO
*)&wndPtr
->wExtra
[1]) = lphc
;
410 /************************************************************************
411 * DlgDirSelectComboBox [USER.194]
413 BOOL
DlgDirSelectComboBox(HWND hDlg
, LPSTR lpStr
, int nIDLBox
)
415 fprintf(stdnimp
,"DlgDirSelectComboBox(%04X, '%s', %d) \n",
416 hDlg
, lpStr
, nIDLBox
);
420 /************************************************************************
421 * DlgDirListComboBox [USER.195]
423 int DlgDirListComboBox(HWND hDlg
, LPSTR lpPathSpec
,
424 int nIDLBox
, int nIDStat
, WORD wType
)
428 dprintf_combo(stddeb
,"DlgDirListComboBox(%04X, '%s', %d, %d, %04X) \n",
429 hDlg
, lpPathSpec
, nIDLBox
, nIDStat
, wType
);
430 hWnd
= GetDlgItem(hDlg
, nIDLBox
);
431 lphc
= ComboGetStorageHeader(hWnd
);
432 if (lphc
== NULL
) return 0;
433 SendMessage(lphc
->hWndLBox
, LB_RESETCONTENT
, 0, 0L);
434 return SendMessage(lphc
->hWndLBox
, LB_DIR
, wType
, (DWORD
)lpPathSpec
);