2 * Interface code to listbox widgets
4 * Copyright Martin Ayotte, 1993
9 static char Copyright[] = "Copyright Martin Ayotte, 1993";
13 #include <sys/types.h>
23 #include "prototypes.h"
25 /* #define DEBUG_LISTBOX /* */
26 /* #undef DEBUG_LISTBOX /* */
29 #define GMEM_ZEROINIT 0x0040
32 LPHEADLIST ListBoxGetWindowAndStorage(HWND hwnd, WND **wndPtr);
33 LPHEADLIST ListBoxGetStorageHeader(HWND hwnd);
34 void StdDrawListBox(HWND hwnd);
35 void OwnerDrawListBox(HWND hwnd);
36 int ListBoxFindMouse(HWND hwnd, int X, int Y);
37 int CreateListBoxStruct(HWND hwnd);
38 void ListBoxAskMeasure(WND *wndPtr, LPHEADLIST lphl, LPLISTSTRUCT lpls);
39 int ListBoxAddString(HWND hwnd, LPSTR newstr);
40 int ListBoxInsertString(HWND hwnd, UINT uIndex, LPSTR newstr);
41 int ListBoxGetText(HWND hwnd, UINT uIndex, LPSTR OutStr, BOOL bItemData);
42 int ListBoxSetItemData(HWND hwnd, UINT uIndex, DWORD ItemData);
43 int ListBoxDeleteString(HWND hwnd, UINT uIndex);
44 int ListBoxFindString(HWND hwnd, UINT nFirst, LPSTR MatchStr);
45 int ListBoxResetContent(HWND hwnd);
46 int ListBoxSetCurSel(HWND hwnd, WORD wIndex);
47 int ListBoxSetSel(HWND hwnd, WORD wIndex, WORD state);
48 int ListBoxGetSel(HWND hwnd, WORD wIndex);
49 int ListBoxDirectory(HWND hwnd, UINT attrib, LPSTR filespec);
50 int ListBoxGetItemRect(HWND hwnd, WORD wIndex, LPRECT rect);
51 int ListBoxSetItemHeight(HWND hwnd, WORD wIndex, long height);
52 int ListBoxDefaultItem(HWND hwnd, WND *wndPtr,
53 LPHEADLIST lphl, LPLISTSTRUCT lpls);
54 int ListBoxFindNextMatch(HWND hwnd, WORD wChar);
56 #define HasStrings(wndPtr) ( \
57 ( ((wndPtr->dwStyle & LBS_OWNERDRAWFIXED) != LBS_OWNERDRAWFIXED) && \
58 ((wndPtr->dwStyle & LBS_OWNERDRAWVARIABLE) != LBS_OWNERDRAWVARIABLE) ) || \
59 ((wndPtr->dwStyle & LBS_HASSTRINGS) == LBS_HASSTRINGS) )
62 /***********************************************************************
65 LONG ListBoxWndProc( HWND hwnd, WORD message, WORD wParam, LONG lParam )
73 CREATESTRUCT *createStruct;
77 CreateListBoxStruct(hwnd);
78 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
79 dprintf_listbox(stddeb,"ListBox WM_CREATE %lX !\n", lphl);
80 if (lphl == NULL) return 0;
81 createStruct = (CREATESTRUCT *)lParam;
82 if (HIWORD(createStruct->lpCreateParams) != 0)
83 lphl->hWndLogicParent = (HWND)HIWORD(createStruct->lpCreateParams);
85 lphl->hWndLogicParent = GetParent(hwnd);
86 lphl->hFont = GetStockObject(SYSTEM_FONT);
87 lphl->ColumnsWidth = wndPtr->rectClient.right - wndPtr->rectClient.left;
88 if (wndPtr->dwStyle & WS_VSCROLL) {
89 SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount, TRUE);
90 ShowScrollBar(hwnd, SB_VERT, FALSE);
92 if (wndPtr->dwStyle & WS_HSCROLL) {
93 SetScrollRange(hwnd, SB_HORZ, 1, 1, TRUE);
94 ShowScrollBar(hwnd, SB_HORZ, FALSE);
96 if ((wndPtr->dwStyle & LBS_OWNERDRAWFIXED) == LBS_OWNERDRAWFIXED) {
100 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
101 if (lphl == NULL) return 0;
102 ListBoxResetContent(hwnd);
104 *((LPHEADLIST *)&wndPtr->wExtra[1]) = 0;
105 dprintf_listbox(stddeb,"ListBox WM_DESTROY %lX !\n", lphl);
109 dprintf_listbox(stddeb,"ListBox WM_VSCROLL w=%04X l=%08X !\n",
111 lphl = ListBoxGetStorageHeader(hwnd);
112 if (lphl == NULL) return 0;
113 y = lphl->FirstVisible;
116 if (lphl->FirstVisible > 1)
117 lphl->FirstVisible--;
120 if (lphl->FirstVisible < lphl->ItemsCount)
121 lphl->FirstVisible++;
124 if (lphl->FirstVisible > 1)
125 lphl->FirstVisible -= lphl->ItemsVisible;
128 if (lphl->FirstVisible < lphl->ItemsCount)
129 lphl->FirstVisible += lphl->ItemsVisible;
132 lphl->FirstVisible = LOWORD(lParam);
135 if (lphl->FirstVisible < 1) lphl->FirstVisible = 1;
136 if (lphl->FirstVisible > lphl->ItemsCount)
137 lphl->FirstVisible = lphl->ItemsCount;
138 if (y != lphl->FirstVisible) {
139 SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
140 InvalidateRect(hwnd, NULL, TRUE);
146 dprintf_listbox(stddeb,"ListBox WM_HSCROLL w=%04X l=%08X !\n",
148 lphl = ListBoxGetStorageHeader(hwnd);
149 if (lphl == NULL) return 0;
150 y = lphl->FirstVisible;
153 if (lphl->FirstVisible > 1)
154 lphl->FirstVisible -= lphl->ItemsPerColumn;
157 if (lphl->FirstVisible < lphl->ItemsCount)
158 lphl->FirstVisible += lphl->ItemsPerColumn;
161 if (lphl->FirstVisible > 1 && lphl->ItemsPerColumn != 0)
162 lphl->FirstVisible -= lphl->ItemsVisible /
163 lphl->ItemsPerColumn * lphl->ItemsPerColumn;
166 if (lphl->FirstVisible < lphl->ItemsCount &&
167 lphl->ItemsPerColumn != 0)
168 lphl->FirstVisible += lphl->ItemsVisible /
169 lphl->ItemsPerColumn * lphl->ItemsPerColumn;
172 lphl->FirstVisible = lphl->ItemsPerColumn *
173 (LOWORD(lParam) - 1) + 1;
176 if (lphl->FirstVisible < 1) lphl->FirstVisible = 1;
177 if (lphl->FirstVisible > lphl->ItemsCount)
178 lphl->FirstVisible = lphl->ItemsCount;
179 if (lphl->ItemsPerColumn != 0) {
180 lphl->FirstVisible = lphl->FirstVisible /
181 lphl->ItemsPerColumn * lphl->ItemsPerColumn + 1;
182 if (y != lphl->FirstVisible) {
183 SetScrollPos(hwnd, SB_HORZ, lphl->FirstVisible /
184 lphl->ItemsPerColumn + 1, TRUE);
185 InvalidateRect(hwnd, NULL, TRUE);
194 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
195 if (lphl == NULL) return 0;
196 lphl->PrevFocused = lphl->ItemFocused;
197 y = ListBoxFindMouse(hwnd, LOWORD(lParam), HIWORD(lParam));
198 if ((wndPtr->dwStyle & LBS_MULTIPLESEL) == LBS_MULTIPLESEL) {
199 lphl->ItemFocused = y;
200 wRet = ListBoxGetSel(hwnd, y);
201 ListBoxSetSel(hwnd, y, !wRet);
204 ListBoxSetCurSel(hwnd, y);
206 ListBoxGetItemRect(hwnd, y, &rectsel);
207 InvalidateRect(hwnd, NULL, TRUE);
212 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
213 if (lphl == NULL) return 0;
214 if (lphl->PrevFocused != lphl->ItemFocused)
215 SendMessage(lphl->hWndLogicParent, WM_COMMAND, wndPtr->wIDmenu,
216 MAKELONG(hwnd, LBN_SELCHANGE));
219 case WM_LBUTTONDBLCLK:
220 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
221 if (lphl == NULL) return 0;
222 SendMessage(lphl->hWndLogicParent, WM_COMMAND, wndPtr->wIDmenu,
223 MAKELONG(hwnd, LBN_DBLCLK));
226 if ((wParam & MK_LBUTTON) != 0) {
229 lphl = ListBoxGetStorageHeader(hwnd);
230 if (lphl == NULL) return 0;
231 if (lphl->FirstVisible > 1) {
232 lphl->FirstVisible--;
233 if (wndPtr->dwStyle & WS_VSCROLL)
234 SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
235 InvalidateRect(hwnd, NULL, TRUE);
240 GetClientRect(hwnd, &rect);
241 if (y > (rect.bottom - 4)) {
242 lphl = ListBoxGetStorageHeader(hwnd);
243 if (lphl == NULL) return 0;
244 if (lphl->FirstVisible < lphl->ItemsCount) {
245 lphl->FirstVisible++;
246 if (wndPtr->dwStyle & WS_VSCROLL)
247 SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
248 InvalidateRect(hwnd, NULL, TRUE);
253 if ((y > 0) && (y < (rect.bottom - 4))) {
254 if ((y < rectsel.top) || (y > rectsel.bottom)) {
255 lphl = ListBoxGetStorageHeader(hwnd);
256 if (lphl == NULL) return 0;
257 wRet = ListBoxFindMouse(hwnd, LOWORD(lParam), HIWORD(lParam));
258 if ((wndPtr->dwStyle & LBS_MULTIPLESEL) == LBS_MULTIPLESEL) {
259 lphl->ItemFocused = wRet;
262 ListBoxSetCurSel(hwnd, wRet);
264 ListBoxGetItemRect(hwnd, wRet, &rectsel);
265 InvalidateRect(hwnd, NULL, TRUE);
272 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
273 if (lphl == NULL) return 0;
276 hWndCtl = GetNextDlgTabItem(lphl->hWndLogicParent,
277 hwnd, !(GetKeyState(VK_SHIFT) < 0));
280 if ((GetKeyState(VK_SHIFT) < 0))
281 dprintf_listbox(stddeb,"ListBox PreviousDlgTabItem %04X !\n", hWndCtl);
283 dprintf_listbox(stddeb,"ListBox NextDlgTabItem %04X !\n", hWndCtl);
287 lphl->ItemFocused = 0;
290 lphl->ItemFocused = lphl->ItemsCount - 1;
293 if ((wndPtr->dwStyle & LBS_MULTICOLUMN) == LBS_MULTICOLUMN) {
294 lphl->ItemFocused -= lphl->ItemsPerColumn;
301 if ((wndPtr->dwStyle & LBS_MULTICOLUMN) == LBS_MULTICOLUMN) {
302 lphl->ItemFocused += lphl->ItemsPerColumn;
309 lphl->ItemFocused -= lphl->ItemsVisible;
312 lphl->ItemFocused += lphl->ItemsVisible;
315 wRet = ListBoxGetSel(hwnd, lphl->ItemFocused);
316 ListBoxSetSel(hwnd, lphl->ItemFocused, !wRet);
319 ListBoxFindNextMatch(hwnd, wParam);
322 if (lphl->ItemFocused < 0) lphl->ItemFocused = 0;
323 if (lphl->ItemFocused >= lphl->ItemsCount)
324 lphl->ItemFocused = lphl->ItemsCount - 1;
325 lphl->FirstVisible = lphl->ItemFocused / lphl->ItemsVisible *
326 lphl->ItemsVisible + 1;
327 if (lphl->FirstVisible < 1) lphl->FirstVisible = 1;
328 if ((wndPtr->dwStyle & LBS_MULTIPLESEL) != LBS_MULTIPLESEL) {
329 ListBoxSetCurSel(hwnd, lphl->ItemFocused);
331 if (wndPtr->dwStyle & WS_VSCROLL)
332 SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
333 InvalidateRect(hwnd, NULL, TRUE);
337 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
338 if (lphl == NULL) return 0;
340 lphl->hFont = GetStockObject(SYSTEM_FONT);
342 lphl->hFont = wParam;
343 if (wParam == 0) break;
345 wndPtr = WIN_FindWndPtr(hwnd);
346 if ((wndPtr->dwStyle & LBS_OWNERDRAWFIXED) == LBS_OWNERDRAWFIXED) {
347 OwnerDrawListBox(hwnd);
350 if ((wndPtr->dwStyle & LBS_OWNERDRAWVARIABLE) == LBS_OWNERDRAWVARIABLE) {
351 OwnerDrawListBox(hwnd);
354 StdDrawListBox(hwnd);
357 dprintf_listbox(stddeb,"ListBox WM_SETFOCUS !\n");
358 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
361 dprintf_listbox(stddeb,"ListBox WM_KILLFOCUS !\n");
362 InvalidateRect(hwnd, NULL, TRUE);
366 case LB_RESETCONTENT:
367 dprintf_listbox(stddeb,"ListBox LB_RESETCONTENT !\n");
368 ListBoxResetContent(hwnd);
371 dprintf_listbox(stddeb,"ListBox LB_DIR !\n");
372 wRet = ListBoxDirectory(hwnd, wParam, (LPSTR)lParam);
373 InvalidateRect(hwnd, NULL, TRUE);
377 wRet = ListBoxAddString(hwnd, (LPSTR)lParam);
380 wRet = ListBoxGetText(hwnd, wParam, (LPSTR)lParam, FALSE);
382 case LB_INSERTSTRING:
383 wRet = ListBoxInsertString(hwnd, wParam, (LPSTR)lParam);
385 case LB_DELETESTRING:
386 wRet = ListBoxDeleteString(hwnd, wParam);
389 wRet = ListBoxFindString(hwnd, wParam, (LPSTR)lParam);
391 case LB_GETCARETINDEX:
394 lphl = ListBoxGetStorageHeader(hwnd);
395 return lphl->ItemsCount;
397 lphl = ListBoxGetStorageHeader(hwnd);
398 dprintf_listbox(stddeb,"ListBox LB_GETCURSEL %u !\n",
400 return lphl->ItemFocused;
401 case LB_GETHORIZONTALEXTENT:
404 wRet = ListBoxGetText(hwnd, wParam, (LPSTR)lParam, TRUE);
406 case LB_GETITEMHEIGHT:
411 wRet = ListBoxGetSel(hwnd, wParam);
421 case LB_SELECTSTRING:
423 case LB_SELITEMRANGE:
425 case LB_SETCARETINDEX:
427 case LB_SETCOLUMNWIDTH:
428 lphl = ListBoxGetStorageHeader(hwnd);
429 lphl->ColumnsWidth = wParam;
431 case LB_SETHORIZONTALEXTENT:
434 wRet = ListBoxSetItemData(hwnd, wParam, lParam);
439 dprintf_listbox(stddeb,"ListBox LB_SETCURSEL wParam=%x !\n",
441 wRet = ListBoxSetCurSel(hwnd, wParam);
442 InvalidateRect(hwnd, NULL, TRUE);
446 dprintf_listbox(stddeb,"ListBox LB_SETSEL wParam=%x lParam=%lX !\n", wParam, lParam);
447 wRet = ListBoxSetSel(hwnd, LOWORD(lParam), wParam);
448 InvalidateRect(hwnd, NULL, TRUE);
452 dprintf_listbox(stddeb,"ListBox LB_SETTOPINDEX wParam=%x !\n",
454 lphl = ListBoxGetStorageHeader(hwnd);
455 lphl->FirstVisible = wParam;
456 wndPtr = WIN_FindWndPtr(hwnd);
457 if (wndPtr->dwStyle & WS_VSCROLL)
458 SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
459 InvalidateRect(hwnd, NULL, TRUE);
462 case LB_SETITEMHEIGHT:
463 dprintf_listbox(stddeb,"ListBox LB_SETITEMHEIGHT wParam=%x lParam=%lX !\n", wParam, lParam);
464 wRet = ListBoxSetItemHeight(hwnd, wParam, lParam);
468 return DefWindowProc( hwnd, message, wParam, lParam );
474 LPHEADLIST ListBoxGetWindowAndStorage(HWND hwnd, WND **wndPtr)
478 *(wndPtr) = Ptr = WIN_FindWndPtr(hwnd);
479 lphl = *((LPHEADLIST *)&Ptr->wExtra[1]);
484 LPHEADLIST ListBoxGetStorageHeader(HWND hwnd)
488 wndPtr = WIN_FindWndPtr(hwnd);
489 lphl = *((LPHEADLIST *)&wndPtr->wExtra[1]);
494 void StdDrawListBox(HWND hwnd)
502 DWORD dwOldTextColor;
506 UINT i, h, h2, maxwidth, ipc;
509 hdc = BeginPaint( hwnd, &ps );
510 if (!IsWindowVisible(hwnd)) {
511 EndPaint( hwnd, &ps );
514 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
515 if (lphl == NULL) goto EndOfPaint;
516 SelectObject(hdc, lphl->hFont);
517 hBrush = SendMessage(lphl->hWndLogicParent, WM_CTLCOLOR, (WORD)hdc,
518 MAKELONG(hwnd, CTLCOLOR_LISTBOX));
519 if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(WHITE_BRUSH);
520 GetClientRect(hwnd, &rect);
522 if (wndPtr->dwStyle & WS_VSCROLL) rect.right -= 16;
523 if (wndPtr->dwStyle & WS_HSCROLL) rect.bottom -= 16;
525 FillRect(hdc, &rect, hBrush);
526 maxwidth = rect.right;
527 rect.right = lphl->ColumnsWidth;
528 if (lphl->ItemsCount == 0) goto EndOfPaint;
529 lpls = lphl->lpFirst;
530 if (lpls == NULL) goto EndOfPaint;
531 lphl->ItemsVisible = 0;
532 lphl->ItemsPerColumn = ipc = 0;
533 for(i = 1; i <= lphl->ItemsCount; i++) {
534 if (i >= lphl->FirstVisible) {
535 if (lpls == NULL) break;
536 if ((h + lpls->dis.rcItem.bottom - lpls->dis.rcItem.top) > rect.bottom) {
537 if ((wndPtr->dwStyle & LBS_MULTICOLUMN) == LBS_MULTICOLUMN) {
538 lphl->ItemsPerColumn = max(lphl->ItemsPerColumn, ipc);
541 rect.left += lphl->ColumnsWidth;
542 rect.right += lphl->ColumnsWidth;
543 if (rect.left > maxwidth) break;
548 h2 = lpls->dis.rcItem.bottom - lpls->dis.rcItem.top;
549 lpls->dis.rcItem.top = h;
550 lpls->dis.rcItem.bottom = h + h2;
551 lpls->dis.rcItem.left = rect.left;
552 lpls->dis.rcItem.right = rect.right;
553 OldBkMode = SetBkMode(hdc, TRANSPARENT);
554 if (lpls->dis.itemState != 0) {
555 dwOldTextColor = SetTextColor(hdc, 0x00FFFFFFL);
556 FillRect(hdc, &lpls->dis.rcItem, GetStockObject(BLACK_BRUSH));
558 TextOut(hdc, rect.left + 5, h + 2, (char *)lpls->itemText,
559 strlen((char *)lpls->itemText));
560 if (lpls->dis.itemState != 0) {
561 SetTextColor(hdc, dwOldTextColor);
563 SetBkMode(hdc, OldBkMode);
564 if ((lphl->ItemFocused == i - 1) && GetFocus() == hwnd) {
565 DrawFocusRect(hdc, &lpls->dis.rcItem);
568 lphl->ItemsVisible++;
571 if (lpls->lpNext == NULL) goto EndOfPaint;
572 lpls = (LPLISTSTRUCT)lpls->lpNext;
575 EndPaint( hwnd, &ps );
576 if ((lphl->ItemsCount > lphl->ItemsVisible) &
577 (wndPtr->dwStyle & WS_VSCROLL)) {
579 InvalidateRect(wndPtr->hWndVScroll, NULL, TRUE);
580 UpdateWindow(wndPtr->hWndVScroll);
587 void OwnerDrawListBox(HWND hwnd)
589 WND *wndPtr,*ParentWndPtr;
597 UINT i, h, h2, maxwidth;
600 hdc = BeginPaint(hwnd, &ps);
601 if (!IsWindowVisible(hwnd)) {
602 EndPaint( hwnd, &ps );
605 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
606 if (lphl == NULL) goto EndOfPaint;
607 hBrush = SendMessage(lphl->hWndLogicParent, WM_CTLCOLOR, (WORD)hdc,
608 MAKELONG(hwnd, CTLCOLOR_LISTBOX));
609 if (hBrush == (HBRUSH)NULL) hBrush = GetStockObject(WHITE_BRUSH);
610 GetClientRect(hwnd, &rect);
611 if (wndPtr->dwStyle & WS_VSCROLL) rect.right -= 16;
612 if (wndPtr->dwStyle & WS_HSCROLL) rect.bottom -= 16;
613 FillRect(hdc, &rect, hBrush);
614 maxwidth = rect.right;
615 rect.right = lphl->ColumnsWidth;
616 if (lphl->ItemsCount == 0) goto EndOfPaint;
617 lpls = lphl->lpFirst;
618 if (lpls == NULL) goto EndOfPaint;
619 lphl->ItemsVisible = 0;
620 for (i = 1; i <= lphl->ItemsCount; i++) {
621 if (i >= lphl->FirstVisible) {
623 lpls->dis.hwndItem = hwnd;
624 lpls->dis.CtlType = ODT_LISTBOX;
625 lpls->dis.itemID = i - 1;
626 if ((!lpls->dis.CtlID)&&(lphl->hWndLogicParent))
628 ListBoxGetWindowAndStorage(lphl->hWndLogicParent, &ParentWndPtr);
629 lpls->dis.CtlID = ParentWndPtr->wIDmenu;
631 h2 = lpls->dis.rcItem.bottom - lpls->dis.rcItem.top;
632 lpls->dis.rcItem.top = h;
633 lpls->dis.rcItem.bottom = h + h2;
634 lpls->dis.rcItem.left = rect.left;
635 lpls->dis.rcItem.right = rect.right;
636 lpls->dis.itemAction = ODA_DRAWENTIRE;
637 /* if (lpls->dis.itemState != 0) {
638 lpls->dis.itemAction |= ODA_SELECT;
640 if (lphl->ItemFocused == i - 1) {
641 lpls->dis.itemAction |= ODA_FOCUS;
643 dprintf_listbox(stddeb,"LBOX WM_DRAWITEM #%d left=%d top=%d right=%d bottom=%d !\n",
644 i-1, lpls->dis.rcItem.left, lpls->dis.rcItem.top,
645 lpls->dis.rcItem.right, lpls->dis.rcItem.bottom);
646 dprintf_listbox(stddeb,"LBOX WM_DRAWITEM Parent=%X &dis=%lX CtlID=%u !\n",
647 hWndParent, (LONG)&lpls->dis, lpls->dis.CtlID);
648 dprintf_listbox(stddeb,"LBOX WM_DRAWITEM %08X!\n",lpls->dis.itemData);
649 if (HasStrings(wndPtr))
650 dprintf_listbox(stddeb," '%s'\n",lpls->itemText);
651 SendMessage(lphl->hWndLogicParent, WM_DRAWITEM, i-1, (LPARAM)&lpls->dis);
652 /* if (lpls->dis.itemState != 0) {
653 InvertRect(hdc, &lpls->dis.rcItem);
656 lphl->ItemsVisible++;
657 /* if (h > rect.bottom) goto EndOfPaint;*/
659 if (lpls->lpNext == NULL) goto EndOfPaint;
660 lpls = (LPLISTSTRUCT)lpls->lpNext;
663 EndPaint( hwnd, &ps );
664 if ((lphl->ItemsCount > lphl->ItemsVisible) &
665 (wndPtr->dwStyle & WS_VSCROLL)) {
667 InvalidateRect(wndPtr->hWndVScroll, NULL, TRUE);
668 UpdateWindow(wndPtr->hWndVScroll);
676 int ListBoxFindMouse(HWND hwnd, int X, int Y)
682 UINT i, h, h2, w, w2;
684 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
685 if (lphl == NULL) return LB_ERR;
686 if (lphl->ItemsCount == 0) return LB_ERR;
687 lpls = lphl->lpFirst;
688 if (lpls == NULL) return LB_ERR;
689 GetClientRect(hwnd, &rect);
690 if (wndPtr->dwStyle & WS_VSCROLL) rect.right -= 16;
691 if (wndPtr->dwStyle & WS_HSCROLL) rect.bottom -= 16;
693 w = lphl->ColumnsWidth;
694 for(i = 1; i <= lphl->ItemsCount; i++) {
695 if (i >= lphl->FirstVisible) {
697 h += lpls->dis.rcItem.bottom - lpls->dis.rcItem.top;
698 if ((Y > h2) && (Y < h) &&
699 (X > w2) && (X < w)) return(i - 1);
700 if (h > rect.bottom) {
701 if ((wndPtr->dwStyle & LBS_MULTICOLUMN) != LBS_MULTICOLUMN) return LB_ERR;
704 w += lphl->ColumnsWidth;
705 if (w2 > rect.right) return LB_ERR;
708 if (lpls->lpNext == NULL) return LB_ERR;
709 lpls = (LPLISTSTRUCT)lpls->lpNext;
716 int CreateListBoxStruct(HWND hwnd)
720 wndPtr = WIN_FindWndPtr(hwnd);
721 lphl = (LPHEADLIST)malloc(sizeof(HEADLIST));
722 lphl->lpFirst = NULL;
723 *((LPHEADLIST *)&wndPtr->wExtra[1]) = lphl; /* HEAD of List */
724 lphl->ItemsCount = 0;
725 lphl->ItemsVisible = 0;
726 lphl->FirstVisible = 1;
727 lphl->StdItemHeight = 15;
728 lphl->DrawCtlType = ODT_LISTBOX;
733 void ListBoxAskMeasure(WND *wndPtr, LPHEADLIST lphl, LPLISTSTRUCT lpls)
735 MEASUREITEMSTRUCT *measure;
736 HANDLE hTemp = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(MEASUREITEMSTRUCT));
737 measure = (MEASUREITEMSTRUCT *) USER_HEAP_ADDR(hTemp);
738 if (measure == NULL) {
739 fprintf(stderr,"ListBoxAskMeasure() // Bad allocation of Measure struct !\n");
742 measure->CtlType = ODT_LISTBOX;
743 measure->CtlID = wndPtr->wIDmenu;
744 measure->itemID = lpls->dis.itemID;
745 measure->itemWidth = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
746 measure->itemHeight = 0;
747 measure->itemData = lpls->dis.itemData;
748 SendMessage(lphl->hWndLogicParent, WM_MEASUREITEM, 0, (DWORD)measure);
749 lpls->dis.rcItem.right = lpls->dis.rcItem.left + measure->itemWidth;
750 lpls->dis.rcItem.bottom = lpls->dis.rcItem.top + measure->itemHeight;
751 USER_HEAP_FREE(hTemp);
755 int ListBoxAddString(HWND hwnd, LPSTR newstr)
759 LPLISTSTRUCT lpls, lplsnew;
762 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
763 if (lphl == NULL) return LB_ERR;
764 hTemp = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LISTSTRUCT));
765 lplsnew = (LPLISTSTRUCT) USER_HEAP_ADDR(hTemp);
766 if (lplsnew == NULL) {
767 fprintf(stderr,"ListBoxAddString() // Bad allocation of new item !\n");
770 lpls = lphl->lpFirst;
772 while(lpls->lpNext != NULL) {
773 lpls = (LPLISTSTRUCT)lpls->lpNext;
775 lpls->lpNext = lplsnew;
778 lphl->lpFirst = lplsnew;
780 dprintf_listbox(stddeb,"Items Count = %u\n", lphl->ItemsCount);
782 ListBoxDefaultItem(hwnd, wndPtr, lphl, lplsnew);
783 if (HasStrings(wndPtr))
785 hTemp = USER_HEAP_ALLOC(GMEM_MOVEABLE, strlen(newstr) + 1);
786 str = (LPSTR)USER_HEAP_ADDR(hTemp);
787 if (str == NULL) return LB_ERRSPACE;
790 lplsnew->itemText = str;
791 lplsnew->dis.itemData = 0;
792 dprintf_listbox(stddeb,"ListBoxAddString// after strcpy '%s'\n", str);
796 lplsnew->itemText = NULL;
797 lplsnew->dis.itemData = (DWORD)newstr;
799 lplsnew->hMem = hTemp;
800 lplsnew->lpNext = NULL;
801 lplsnew->dis.itemID = lphl->ItemsCount;
802 lplsnew->hData = hTemp;
803 if (((wndPtr->dwStyle & LBS_OWNERDRAWVARIABLE) == LBS_OWNERDRAWVARIABLE)|| ((wndPtr->dwStyle & LBS_OWNERDRAWFIXED) == LBS_OWNERDRAWFIXED))
804 ListBoxAskMeasure(wndPtr, lphl, lplsnew);
805 if (wndPtr->dwStyle & WS_VSCROLL)
806 SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount,
807 (lphl->FirstVisible != 1));
808 if ((wndPtr->dwStyle & WS_HSCROLL) && lphl->ItemsPerColumn != 0)
809 SetScrollRange(hwnd, SB_HORZ, 1, lphl->ItemsVisible /
810 lphl->ItemsPerColumn + 1, (lphl->FirstVisible != 1));
811 if (lphl->FirstVisible >= (lphl->ItemsCount - lphl->ItemsVisible)) {
812 InvalidateRect(hwnd, NULL, TRUE);
815 if ((lphl->ItemsCount - lphl->FirstVisible) == lphl->ItemsVisible) {
816 if (wndPtr->dwStyle & WS_VSCROLL)
817 ShowScrollBar(hwnd, SB_VERT, TRUE);
818 if (wndPtr->dwStyle & WS_HSCROLL)
819 ShowScrollBar(hwnd, SB_HORZ, TRUE);
821 return lphl->ItemsCount-1;
825 int ListBoxInsertString(HWND hwnd, UINT uIndex, LPSTR newstr)
829 LPLISTSTRUCT lpls, lplsnew;
833 dprintf_listbox(stddeb,"ListBoxInsertString(%04X, %d, %08X);\n",
834 hwnd, uIndex, newstr);
835 if (uIndex == (UINT)-1) return ListBoxAddString(hwnd, newstr);
836 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
837 if (lphl == NULL) return LB_ERR;
838 /* The following line will cause problems if the content of the */
839 /* listbox is sorted by the listbox itself */
840 if (uIndex == lphl->ItemsCount) return ListBoxAddString(hwnd, newstr);
841 if (uIndex >= lphl->ItemsCount) return LB_ERR;
842 lpls = lphl->lpFirst;
843 if (lpls == NULL) return LB_ERR;
844 if (uIndex > lphl->ItemsCount) return LB_ERR;
845 for(Count = 1; Count < uIndex; Count++) {
846 if (lpls->lpNext == NULL) return LB_ERR;
847 lpls = (LPLISTSTRUCT)lpls->lpNext;
849 hTemp = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LISTSTRUCT));
850 lplsnew = (LPLISTSTRUCT) USER_HEAP_ADDR(hTemp);
851 if (lplsnew == NULL) {
852 fprintf(stderr,"ListBoxInsertString() // Bad allocation of new item !\n");
855 ListBoxDefaultItem(hwnd, wndPtr, lphl, lplsnew);
856 lplsnew->hMem = hTemp;
859 lplsnew->lpNext = lphl->lpFirst;
860 lphl->lpFirst = lplsnew;
864 lplsnew->lpNext = lpls->lpNext;
865 lpls->lpNext = lplsnew;
869 if (HasStrings(wndPtr))
871 hTemp = USER_HEAP_ALLOC(GMEM_MOVEABLE, strlen(newstr) + 1);
872 str = (LPSTR)USER_HEAP_ADDR(hTemp);
873 if (str == NULL) return LB_ERRSPACE;
876 lplsnew->itemText = str;
877 lplsnew->dis.itemData = 0;
879 printf("ListBoxInsertString // after strcpy '%s'\n", str);
884 lplsnew->itemText = NULL;
885 lplsnew->dis.itemData = (DWORD)newstr;
887 lplsnew->dis.itemID = lphl->ItemsCount;
888 lplsnew->hData = hTemp;
889 if (((wndPtr->dwStyle & LBS_OWNERDRAWVARIABLE) == LBS_OWNERDRAWVARIABLE)|| ((wndPtr->dwStyle & LBS_OWNERDRAWFIXED) == LBS_OWNERDRAWFIXED))
890 ListBoxAskMeasure(wndPtr, lphl, lplsnew);
891 if (wndPtr->dwStyle & WS_VSCROLL)
892 SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount,
893 (lphl->FirstVisible != 1));
894 if ((wndPtr->dwStyle & WS_HSCROLL) && lphl->ItemsPerColumn != 0)
895 SetScrollRange(hwnd, SB_HORZ, 1, lphl->ItemsVisible /
896 lphl->ItemsPerColumn + 1, (lphl->FirstVisible != 1));
897 if (((lphl->ItemsCount - lphl->FirstVisible) == lphl->ItemsVisible) &&
898 (lphl->ItemsVisible != 0)) {
899 if (wndPtr->dwStyle & WS_VSCROLL) ShowScrollBar(hwnd, SB_VERT, TRUE);
900 if (wndPtr->dwStyle & WS_HSCROLL) ShowScrollBar(hwnd, SB_HORZ, TRUE);
902 if ((lphl->FirstVisible <= uIndex) &&
903 ((lphl->FirstVisible + lphl->ItemsVisible) >= uIndex)) {
904 InvalidateRect(hwnd, NULL, TRUE);
908 printf("ListBoxInsertString // count=%d\n", lphl->ItemsCount);
910 return /* lphl->ItemsCount;*/ uIndex;
914 int ListBoxGetText(HWND hwnd, UINT uIndex, LPSTR OutStr, BOOL bItemData)
922 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
923 if (lphl == NULL) return LB_ERR;
924 if (uIndex >= lphl->ItemsCount) return LB_ERR;
925 lpls = lphl->lpFirst;
926 if (lpls == NULL) return LB_ERR;
927 if (uIndex > lphl->ItemsCount) return LB_ERR;
928 for(Count = 0; Count < uIndex; Count++) {
929 if (lpls->lpNext == NULL) return LB_ERR;
930 lpls = (LPLISTSTRUCT)lpls->lpNext;
933 return lpls->dis.itemData;
934 if (!(HasStrings(wndPtr)) )
936 *((long *)OutStr) = lpls->dis.itemData;
940 strcpy(OutStr, lpls->itemText);
941 return strlen(OutStr);
944 int ListBoxSetItemData(HWND hwnd, UINT uIndex, DWORD ItemData)
950 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
951 if (lphl == NULL) return LB_ERR;
952 if (uIndex >= lphl->ItemsCount) return LB_ERR;
953 lpls = lphl->lpFirst;
954 if (lpls == NULL) return LB_ERR;
955 if (uIndex > lphl->ItemsCount) return LB_ERR;
956 for(Count = 0; Count < uIndex; Count++) {
957 if (lpls->lpNext == NULL) return LB_ERR;
958 lpls = (LPLISTSTRUCT)lpls->lpNext;
960 lpls->dis.itemData = ItemData;
965 int ListBoxDeleteString(HWND hwnd, UINT uIndex)
969 LPLISTSTRUCT lpls, lpls2;
971 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
972 if (lphl == NULL) return LB_ERR;
973 if (uIndex >= lphl->ItemsCount) return LB_ERR;
974 lpls = lphl->lpFirst;
975 if (lpls == NULL) return LB_ERR;
976 if (uIndex > lphl->ItemsCount) return LB_ERR;
977 for(Count = 1; Count < uIndex; Count++) {
978 if (lpls->lpNext == NULL) return LB_ERR;
980 lpls = (LPLISTSTRUCT)lpls->lpNext;
982 lpls2->lpNext = (LPLISTSTRUCT)lpls->lpNext;
984 if (lpls->hData != 0) USER_HEAP_FREE(lpls->hData);
985 if (lpls->hMem != 0) USER_HEAP_FREE(lpls->hMem);
986 if (wndPtr->dwStyle & WS_VSCROLL)
987 SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount, TRUE);
988 if ((wndPtr->dwStyle & WS_HSCROLL) && lphl->ItemsPerColumn != 0)
989 SetScrollRange(hwnd, SB_HORZ, 1, lphl->ItemsVisible /
990 lphl->ItemsPerColumn + 1, TRUE);
991 if (lphl->ItemsCount < lphl->ItemsVisible) {
992 if (wndPtr->dwStyle & WS_VSCROLL)
993 ShowScrollBar(hwnd, SB_VERT, FALSE);
994 if (wndPtr->dwStyle & WS_HSCROLL)
995 ShowScrollBar(hwnd, SB_HORZ, FALSE);
997 if ((lphl->FirstVisible <= uIndex) &&
998 ((lphl->FirstVisible + lphl->ItemsVisible) >= uIndex)) {
999 InvalidateRect(hwnd, NULL, TRUE);
1002 return lphl->ItemsCount;
1006 int ListBoxFindString(HWND hwnd, UINT nFirst, LPSTR MatchStr)
1012 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
1013 if (lphl == NULL) return LB_ERR;
1014 if (nFirst > lphl->ItemsCount) return LB_ERR;
1015 lpls = lphl->lpFirst;
1016 if (lpls == NULL) return LB_ERR;
1018 while(lpls != NULL) {
1019 if (HasStrings(wndPtr))
1021 if (strcmp(lpls->itemText, MatchStr) == 0) return Count;
1025 if (lpls->dis.itemData == (DWORD)MatchStr) return Count;
1027 lpls = (LPLISTSTRUCT)lpls->lpNext;
1034 int ListBoxResetContent(HWND hwnd)
1038 LPLISTSTRUCT lpls, lpls2;
1040 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
1041 if (lphl == NULL) return LB_ERR;
1042 lpls = lphl->lpFirst;
1043 if (lpls == NULL) return LB_ERR;
1044 for(i = 0; i <= lphl->ItemsCount; i++) {
1046 lpls = (LPLISTSTRUCT)lpls->lpNext;
1048 dprintf_listbox(stddeb,"ResetContent #%u\n", i);
1049 if (lpls2->hData != 0 && lpls2->hData != lpls2->hMem)
1050 USER_HEAP_FREE(lpls2->hData);
1051 if (lpls2->hMem != 0) USER_HEAP_FREE(lpls2->hMem);
1053 if (lpls == NULL) break;
1055 lphl->lpFirst = NULL;
1056 lphl->FirstVisible = 1;
1057 lphl->ItemsCount = 0;
1058 lphl->ItemFocused = /*0*/-1;
1059 lphl->PrevFocused = /*0*/-1;
1060 if ((wndPtr->dwStyle && LBS_NOTIFY) != 0)
1061 SendMessage(lphl->hWndLogicParent, WM_COMMAND,
1062 wndPtr->wIDmenu, MAKELONG(hwnd, LBN_SELCHANGE));
1063 if (wndPtr->dwStyle & WS_VSCROLL)
1064 SetScrollRange(hwnd, SB_VERT, 1, lphl->ItemsCount, TRUE);
1065 if ((wndPtr->dwStyle & WS_HSCROLL) && lphl->ItemsPerColumn != 0)
1066 SetScrollRange(hwnd, SB_HORZ, 1, lphl->ItemsVisible /
1067 lphl->ItemsPerColumn + 1, TRUE);
1068 if (wndPtr->dwStyle & WS_VSCROLL)
1069 ShowScrollBar(hwnd, SB_VERT, FALSE);
1070 if (wndPtr->dwStyle & WS_HSCROLL)
1071 ShowScrollBar(hwnd, SB_HORZ, FALSE);
1072 InvalidateRect(hwnd, NULL, TRUE);
1078 int ListBoxSetCurSel(HWND hwnd, WORD wIndex)
1082 LPLISTSTRUCT lpls, lpls2;
1084 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
1085 if (lphl == NULL) return LB_ERR;
1086 lphl->ItemFocused = LB_ERR;
1087 if (wIndex >= lphl->ItemsCount) return LB_ERR;
1088 lpls = lphl->lpFirst;
1089 if (lpls == NULL) return LB_ERR;
1090 for(i = 0; i < lphl->ItemsCount; i++) {
1092 lpls = (LPLISTSTRUCT)lpls->lpNext;
1094 lpls2->dis.itemState = 1;
1096 if (lpls2->dis.itemState != 0)
1097 lpls2->dis.itemState = 0;
1098 if (lpls == NULL) break;
1100 lphl->ItemFocused = wIndex;
1101 if ((wndPtr->dwStyle && LBS_NOTIFY) != 0)
1102 SendMessage(lphl->hWndLogicParent, WM_COMMAND,
1103 wndPtr->wIDmenu, MAKELONG(hwnd, LBN_SELCHANGE));
1109 int ListBoxSetSel(HWND hwnd, WORD wIndex, WORD state)
1112 LPLISTSTRUCT lpls, lpls2;
1114 lphl = ListBoxGetStorageHeader(hwnd);
1115 if (lphl == NULL) return LB_ERR;
1116 if (wIndex >= lphl->ItemsCount) return LB_ERR;
1117 lpls = lphl->lpFirst;
1118 if (lpls == NULL) return LB_ERR;
1119 for(i = 0; i < lphl->ItemsCount; i++) {
1121 lpls = (LPLISTSTRUCT)lpls->lpNext;
1122 if ((i == wIndex) || (wIndex == (WORD)-1)) {
1123 lpls2->dis.itemState = state;
1126 if (lpls == NULL) break;
1132 int ListBoxGetSel(HWND hwnd, WORD wIndex)
1135 LPLISTSTRUCT lpls, lpls2;
1137 lphl = ListBoxGetStorageHeader(hwnd);
1138 if (lphl == NULL) return LB_ERR;
1139 if (wIndex >= lphl->ItemsCount) return LB_ERR;
1140 lpls = lphl->lpFirst;
1141 if (lpls == NULL) return LB_ERR;
1142 for(i = 0; i < lphl->ItemsCount; i++) {
1144 lpls = (LPLISTSTRUCT)lpls->lpNext;
1146 return lpls2->dis.itemState;
1148 if (lpls == NULL) break;
1154 int ListBoxDirectory(HWND hwnd, UINT attrib, LPSTR filespec)
1156 struct dosdirent *dp;
1157 struct dosdirent *newdp;
1161 #ifdef DEBUG_LISTBOX
1162 fprintf(stderr,"ListBoxDirectory: %s, %4x\n",filespec,attrib);
1164 if ((dp = (struct dosdirent *)DOS_opendir(filespec)) ==NULL) return 0;
1165 while (dp = (struct dosdirent *)DOS_readdir(dp))
1167 if (!dp->inuse) break;
1168 #ifdef DEBUG_LISTBOX
1169 printf("ListBoxDirectory %08X '%s' !\n", dp->filename, dp->filename);
1171 if (dp->attribute & FA_DIREC)
1173 if (attrib & DDL_DIRECTORY)
1175 sprintf(temp, "[%s]", dp->filename);
1176 if ( (wRet = ListBoxAddString(hwnd, temp)) == LB_ERR) break;
1181 if (attrib & DDL_EXCLUSIVE)
1183 if (attrib & (DDL_READWRITE | DDL_READONLY | DDL_HIDDEN |
1185 if ( (wRet = ListBoxAddString(hwnd, dp->filename))
1191 if ( (wRet = ListBoxAddString(hwnd, dp->filename)) == LB_ERR)
1198 if (attrib & DDL_DRIVES)
1200 for (x=0;x!=MAX_DOS_DRIVES;x++)
1202 if (DOS_ValidDrive(x))
1204 sprintf(temp, "[-%c-]", 'a'+x);
1205 if ( (wRet = ListBoxAddString(hwnd, temp)) == LB_ERR)
1210 #ifdef DEBUG_LISTBOX
1211 printf("End of ListBoxDirectory !\n");
1217 int ListBoxGetItemRect(HWND hwnd, WORD wIndex, LPRECT lprect)
1220 LPLISTSTRUCT lpls, lpls2;
1222 lphl = ListBoxGetStorageHeader(hwnd);
1223 if (lphl == NULL) return LB_ERR;
1224 if (wIndex > lphl->ItemsCount) return LB_ERR;
1225 lpls = lphl->lpFirst;
1226 if (lpls == NULL) return LB_ERR;
1227 for(i = 0; i < lphl->ItemsCount; i++) {
1229 lpls = (LPLISTSTRUCT)lpls->lpNext;
1231 *(lprect) = lpls2->dis.rcItem;
1234 if (lpls == NULL) break;
1241 int ListBoxSetItemHeight(HWND hwnd, WORD wIndex, long height)
1244 LPLISTSTRUCT lpls, lpls2;
1246 lphl = ListBoxGetStorageHeader(hwnd);
1247 if (lphl == NULL) return LB_ERR;
1248 if (wIndex > lphl->ItemsCount) return LB_ERR;
1249 lpls = lphl->lpFirst;
1250 if (lpls == NULL) return LB_ERR;
1251 for(i = 0; i < lphl->ItemsCount; i++) {
1253 lpls = (LPLISTSTRUCT)lpls->lpNext;
1255 lpls2->dis.rcItem.bottom = lpls2->dis.rcItem.top + (short)height;
1256 InvalidateRect(hwnd, NULL, TRUE);
1260 if (lpls == NULL) break;
1269 int ListBoxDefaultItem(HWND hwnd, WND *wndPtr,
1270 LPHEADLIST lphl, LPLISTSTRUCT lpls)
1273 if (wndPtr == NULL || lphl == NULL || lpls == NULL) {
1274 fprintf(stderr,"ListBoxDefaultItem() // Bad Pointers !\n");
1277 GetClientRect(hwnd, &rect);
1278 SetRect(&lpls->dis.rcItem, 0, 0, rect.right, lphl->StdItemHeight);
1279 lpls->dis.CtlType = lphl->DrawCtlType;
1280 lpls->dis.CtlID = wndPtr->wIDmenu;
1281 lpls->dis.itemID = 0;
1282 lpls->dis.itemAction = 0;
1283 lpls->dis.itemState = 0;
1284 lpls->dis.hwndItem = hwnd;
1286 lpls->dis.itemData = 0;
1292 int ListBoxFindNextMatch(HWND hwnd, WORD wChar)
1298 lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
1299 if (lphl == NULL) return LB_ERR;
1300 lpls = lphl->lpFirst;
1301 if (lpls == NULL) return LB_ERR;
1302 if (wChar < ' ') return LB_ERR;
1303 if (((wndPtr->dwStyle & LBS_OWNERDRAWFIXED) == LBS_OWNERDRAWFIXED) ||
1304 ((wndPtr->dwStyle & LBS_OWNERDRAWVARIABLE) == LBS_OWNERDRAWVARIABLE)) {
1305 if ((wndPtr->dwStyle & LBS_HASSTRINGS) != LBS_HASSTRINGS) {
1310 while(lpls != NULL) {
1311 if (Count > lphl->ItemFocused) {
1312 if (*(lpls->itemText) == (char)wChar) {
1313 lphl->FirstVisible = Count - lphl->ItemsVisible / 2;
1314 if (lphl->FirstVisible < 1) lphl->FirstVisible = 1;
1315 if ((wndPtr->dwStyle & LBS_MULTIPLESEL) == LBS_MULTIPLESEL) {
1316 lphl->ItemFocused = Count;
1319 ListBoxSetCurSel(hwnd, Count);
1321 SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
1322 InvalidateRect(hwnd, NULL, TRUE);
1327 lpls = (LPLISTSTRUCT)lpls->lpNext;
1331 lpls = lphl->lpFirst;
1332 while(lpls != NULL) {
1333 if (*(lpls->itemText) == (char)wChar) {
1334 if (Count == lphl->ItemFocused) return LB_ERR;
1335 lphl->FirstVisible = Count - lphl->ItemsVisible / 2;
1336 if (lphl->FirstVisible < 1) lphl->FirstVisible = 1;
1337 if ((wndPtr->dwStyle & LBS_MULTIPLESEL) == LBS_MULTIPLESEL) {
1338 lphl->ItemFocused = Count;
1341 ListBoxSetCurSel(hwnd, Count);
1343 SetScrollPos(hwnd, SB_VERT, lphl->FirstVisible, TRUE);
1344 InvalidateRect(hwnd, NULL, TRUE);
1348 lpls = (LPLISTSTRUCT)lpls->lpNext;
1355 /************************************************************************
1356 * DlgDirSelect [USER.99]
1358 BOOL DlgDirSelect(HWND hDlg, LPSTR lpStr, int nIDLBox)
1360 fprintf(stdnimp,"DlgDirSelect(%04X, '%s', %d) \n", hDlg, lpStr, nIDLBox);
1364 /************************************************************************
1365 * DlgDirList [USER.100]
1367 int DlgDirList(HWND hDlg, LPSTR lpPathSpec,
1368 int nIDLBox, int nIDStat, WORD wType)
1372 dprintf_listbox(stddeb,"DlgDirList(%04X, '%s', %d, %d, %04X) \n",
1373 hDlg, lpPathSpec, nIDLBox, nIDStat, wType);
1375 hWnd = GetDlgItem(hDlg, nIDLBox);
1379 ListBoxResetContent(hWnd);
1381 ret=ListBoxDirectory(hWnd, wType, lpPathSpec);
1387 drive = DOS_GetDefaultDrive();
1388 SendDlgItemMessage(hDlg, nIDStat, WM_SETTEXT, 0,
1389 (LONG) DOS_GetCurrentDir(drive) );