4 * Copyright Martin Ayotte, 1993
5 * Constantine Sapuntzakis, 1995
12 * - check if multi-column listboxes work
13 * - implement more messages and styles
14 * - implement caret for LBS_EXTENDEDSEL
30 #include "stackframe.h"
36 #define LIST_HEAP_ALLOC(lphl,f,size) ((int)HEAP_Alloc(&lphl->Heap,f,size) & 0xffff)
37 #define LIST_HEAP_FREE(lphl,handle) (HEAP_Free(&lphl->Heap,LIST_HEAP_ADDR(lphl,handle)))
38 #define LIST_HEAP_ADDR(lphl,handle) \
39 ((void *)((handle) ? ((handle) | ((int)lphl->Heap & 0xffff0000)) : 0))
41 /* FIXME: shouldn't each listbox have its own heap? */
43 #define LIST_HEAP_ALLOC(lphl,f,size) USER_HEAP_ALLOC(size)
44 #define LIST_HEAP_FREE(lphl,handle) USER_HEAP_FREE(handle)
45 #define LIST_HEAP_ADDR(lphl,handle) USER_HEAP_LIN_ADDR(handle)
46 #define LIST_HEAP_SEG_ADDR(lphl,handle) USER_HEAP_SEG_ADDR(handle)
48 /* Something like this maybe ? */
49 #define LIST_HEAP_ALLOC(lphl,f,size) \
50 LOCAL_Alloc( lphl->HeapSel, LMEM_FIXED, (size) )
52 #define LIST_HEAP_REALLOC(handle,size) \
53 LOCAL_ReAlloc( USER_HeapSel, (handle), (size), LMEM_FIXED )
55 #define LIST_HEAP_FREE(lphl,handle) \
56 LOCAL_Free( lphl->HeapSel, (handle) )
57 #define LIST_HEAP_ADDR(lphl,handle) \
58 ((handle) ? PTR_SEG_OFF_TO_LIN(lphl->HeapSel, (handle)) : NULL)
59 #define LIST_HEAP_SEG_ADDR(lphl,handle) \
60 ((handle) ? MAKELONG((handle), lphl->HeapSel) : 0)
64 #define LIST_HEAP_SIZE 0x10000
66 #define LBMM_EDGE 4 /* distance inside box which is same as moving mouse
67 outside box, to trigger scrolling of LB */
69 static void ListBoxInitialize(LPHEADLIST lphl
)
73 lphl
->ItemsVisible
= 0;
74 lphl
->FirstVisible
= 0;
75 lphl
->ColumnsVisible
= 1;
76 lphl
->ItemsPerColumn
= 0;
77 lphl
->ItemFocused
= -1;
78 lphl
->PrevFocused
= -1;
81 void CreateListBoxStruct(HWND hwnd
, WORD CtlType
, LONG styles
, HWND parent
)
86 lphl
= (LPHEADLIST
)xmalloc(sizeof(HEADLIST
));
87 SetWindowLong(hwnd
, 0, (LONG
)lphl
);
88 ListBoxInitialize(lphl
);
89 lphl
->DrawCtlType
= CtlType
;
90 lphl
->CtlID
= GetWindowWord(hwnd
,GWW_ID
);
91 lphl
->bRedrawFlag
= TRUE
;
93 lphl
->TabStops
= NULL
;
94 lphl
->hFont
= GetStockObject(SYSTEM_FONT
);
96 if (CtlType
==ODT_COMBOBOX
) /* use the "faked" style for COMBOLBOX */
97 /* LBS_SORT instead CBS_SORT e.g. */
98 lphl
->dwStyle
= MAKELONG(LOWORD(styles
),HIWORD(GetWindowLong(hwnd
,GWL_STYLE
)));
100 lphl
->dwStyle
= GetWindowLong(hwnd
,GWL_STYLE
); /* use original style dword */
101 lphl
->hParent
= parent
;
102 lphl
->StdItemHeight
= 15; /* FIXME: should get the font height */
103 lphl
->OwnerDrawn
= styles
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
);
104 lphl
->HasStrings
= (styles
& LBS_HASSTRINGS
) || !lphl
->OwnerDrawn
;
106 /* create dummy hdc to set text height */
107 if ((hdc
= GetDC(0)))
110 GetTextMetrics( hdc
, &tm
);
111 lphl
->StdItemHeight
= tm
.tmHeight
;
112 dprintf_listbox(stddeb
,"CreateListBoxStruct: font height %d\n",
113 lphl
->StdItemHeight
);
117 if (lphl
->OwnerDrawn
) {
120 lphl
->hDrawItemStruct
= USER_HEAP_ALLOC(sizeof(DRAWITEMSTRUCT
));
121 lphl
->needMeasure
= TRUE
;
122 dummyls
.mis
.CtlType
= lphl
->DrawCtlType
;
123 dummyls
.mis
.CtlID
= lphl
->CtlID
;
124 dummyls
.mis
.itemID
= -1;
125 dummyls
.mis
.itemWidth
= 0; /* ignored */
126 dummyls
.mis
.itemData
= 0;
128 ListBoxAskMeasure(lphl
,&dummyls
);
130 lphl
->hDrawItemStruct
= 0;
134 HeapHandle
= GlobalAlloc(GMEM_FIXED
, LIST_HEAP_SIZE
);
135 HeapBase
= GlobalLock(HeapHandle
);
136 HEAP_Init(&lphl
->Heap
, HeapBase
, LIST_HEAP_SIZE
);
138 /* WINELIBS list boxes do not operate on local heaps */
140 lphl
->HeapSel
= GlobalAlloc(GMEM_FIXED
,LIST_HEAP_SIZE
);
141 LocalInit( lphl
->HeapSel
, 0, LIST_HEAP_SIZE
-1);
147 void DestroyListBoxStruct(LPHEADLIST lphl
)
149 if (lphl
->hDrawItemStruct
)
150 USER_HEAP_FREE(lphl
->hDrawItemStruct
);
152 /* XXX need to free lphl->Heap */
153 GlobalFree(lphl
->HeapSel
);
157 static LPHEADLIST
ListBoxGetStorageHeader(HWND hwnd
)
159 return (LPHEADLIST
)GetWindowLong(hwnd
,0);
162 /* Send notification "code" as part of a WM_COMMAND-message if hwnd
163 has the LBS_NOTIFY style */
164 void ListBoxSendNotification(LPHEADLIST lphl
, WORD code
)
166 if (lphl
->dwStyle
& LBS_NOTIFY
)
168 SendMessage(lphl
->hParent
, WM_COMMAND
,
169 MAKEWPARAM(lphl
->CtlID
,code
), (LPARAM
)lphl
->hSelf
);
171 SendMessage(lphl
->hParent
, WM_COMMAND
,
172 lphl
->CtlID
, MAKELONG(lphl
->hSelf
, code
));
177 /* get the maximum value of lphl->FirstVisible */
178 int ListMaxFirstVisible(LPHEADLIST lphl
)
180 int m
= lphl
->ItemsCount
-lphl
->ItemsVisible
;
181 return (m
< 0) ? 0 : m
;
185 void ListBoxUpdateWindow(HWND hwnd
, LPHEADLIST lphl
, BOOL repaint
)
187 SetScrollRange(hwnd
, SB_VERT
, 0, ListMaxFirstVisible(lphl
), TRUE
);
188 if (lphl
->ItemsPerColumn
!= 0) {
189 SetScrollRange(hwnd
, SB_HORZ
, 1, lphl
->ItemsVisible
/
190 lphl
->ItemsPerColumn
+ 1, TRUE
);
192 if (repaint
&& lphl
->bRedrawFlag
) {
193 InvalidateRect(hwnd
, NULL
, TRUE
);
197 /* Returns: 0 if nothing needs to be changed */
198 /* 1 if FirstVisible changed */
200 int ListBoxScrollToFocus(LPHEADLIST lphl
)
204 if (lphl
->ItemsCount
== 0) return 0;
205 if (lphl
->ItemFocused
== -1) return 0;
207 end
= lphl
->FirstVisible
+ lphl
->ItemsVisible
- 1;
209 if (lphl
->ItemFocused
< lphl
->FirstVisible
) {
210 lphl
->FirstVisible
= lphl
->ItemFocused
;
213 if (lphl
->ItemFocused
> end
) {
214 WORD maxFirstVisible
= ListMaxFirstVisible(lphl
);
216 lphl
->FirstVisible
= lphl
->ItemFocused
;
218 if (lphl
->FirstVisible
> maxFirstVisible
) {
219 lphl
->FirstVisible
= maxFirstVisible
;
228 LPLISTSTRUCT
ListBoxGetItem(LPHEADLIST lphl
, UINT uIndex
)
233 if (uIndex
>= lphl
->ItemsCount
) return NULL
;
235 lpls
= lphl
->lpFirst
;
236 while (Count
++ < uIndex
) lpls
= lpls
->lpNext
;
241 void ListBoxDrawItem (HWND hwnd
, LPHEADLIST lphl
, HDC hdc
, LPLISTSTRUCT lpls
,
242 RECT
*rect
, WORD itemAction
, WORD itemState
)
244 if (lphl
->OwnerDrawn
) {
245 DRAWITEMSTRUCT
*dis
= USER_HEAP_LIN_ADDR(lphl
->hDrawItemStruct
);
247 dis
->CtlID
= lpls
->mis
.CtlID
;
248 dis
->CtlType
= lpls
->mis
.CtlType
;
249 dis
->itemID
= lpls
->mis
.itemID
;
251 dis
->hwndItem
= hwnd
;
252 dis
->itemData
= lpls
->mis
.itemData
;
253 dis
->itemAction
= itemAction
;
254 dis
->itemState
= itemState
;
256 SendMessage(lphl
->hParent
, WM_DRAWITEM
,
257 0, (LPARAM
)USER_HEAP_SEG_ADDR(lphl
->hDrawItemStruct
));
259 if (itemAction
== ODA_DRAWENTIRE
|| itemAction
== ODA_SELECT
) {
261 DWORD dwOldTextColor
= 0;
263 OldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
265 if (itemState
!= 0) {
266 dwOldTextColor
= SetTextColor(hdc
, 0x00FFFFFFL
);
267 FillRect(hdc
, rect
, GetStockObject(BLACK_BRUSH
));
270 if (lphl
->dwStyle
& LBS_USETABSTOPS
) {
271 TabbedTextOut(hdc
, rect
->left
+ 5, rect
->top
+ 2,
272 (char *)lpls
->itemText
, strlen((char *)lpls
->itemText
),
273 lphl
->iNumStops
, lphl
->TabStops
, 0);
275 TextOut(hdc
, rect
->left
+ 5, rect
->top
+ 2,
276 (char *)lpls
->itemText
, strlen((char *)lpls
->itemText
));
279 if (itemState
!= 0) {
280 SetTextColor(hdc
, dwOldTextColor
);
283 SetBkMode(hdc
, OldBkMode
);
284 } else DrawFocusRect(hdc
, rect
);
291 int ListBoxFindMouse(LPHEADLIST lphl
, int X
, int Y
)
293 LPLISTSTRUCT lpls
= lphl
->lpFirst
;
297 point
.x
= X
; point
.y
= Y
;
298 if (lphl
->ItemsCount
== 0) return LB_ERR
;
300 for(i
= 0; i
< lphl
->FirstVisible
; i
++) {
301 if (lpls
== NULL
) return LB_ERR
;
304 for(j
= 0; j
< lphl
->ItemsVisible
; i
++, j
++) {
305 if (lpls
== NULL
) return LB_ERR
;
306 if (PtInRect(&lpls
->itemRect
,point
)) {
311 dprintf_listbox(stddeb
,"ListBoxFindMouse: not found\n");
316 void ListBoxAskMeasure(LPHEADLIST lphl
, LPLISTSTRUCT lpls
)
318 HANDLE hTemp
= USER_HEAP_ALLOC( sizeof(MEASUREITEMSTRUCT
) );
319 MEASUREITEMSTRUCT
*lpmeasure
= (MEASUREITEMSTRUCT
*) USER_HEAP_LIN_ADDR(hTemp
);
321 if (lpmeasure
== NULL
) {
322 fprintf(stdnimp
,"ListBoxAskMeasure() out of memory !\n");
326 *lpmeasure
= lpls
->mis
;
327 lpmeasure
->itemHeight
= lphl
->StdItemHeight
;
328 SendMessage(lphl
->hParent
, WM_MEASUREITEM
, 0, (LPARAM
)USER_HEAP_SEG_ADDR(hTemp
));
330 if (lphl
->dwStyle
& LBS_OWNERDRAWFIXED
) {
331 lphl
->StdItemHeight
= lpmeasure
->itemHeight
;
332 lpls
->mis
.itemHeight
= lpmeasure
->itemHeight
;
335 USER_HEAP_FREE(hTemp
);
338 /* -------------------- strings and item data ---------------------- */
340 LPLISTSTRUCT
ListBoxCreateItem(LPHEADLIST lphl
, int id
)
342 LPLISTSTRUCT lplsnew
= (LPLISTSTRUCT
)malloc(sizeof(LISTSTRUCT
));
344 if (lplsnew
== NULL
) return NULL
;
346 lplsnew
->itemState
= 0;
347 lplsnew
->mis
.CtlType
= lphl
->DrawCtlType
;
348 lplsnew
->mis
.CtlID
= lphl
->CtlID
;
349 lplsnew
->mis
.itemID
= id
;
350 lplsnew
->mis
.itemHeight
= lphl
->StdItemHeight
;
351 lplsnew
->mis
.itemWidth
= 0; /* ignored */
352 lplsnew
->mis
.itemData
= 0;
353 SetRect(&lplsnew
->itemRect
, 0, 0, 0, 0);
359 int ListBoxInsertString(LPHEADLIST lphl
, UINT uIndex
, LPCSTR newstr
)
361 LPLISTSTRUCT
*lppls
, lplsnew
, lpls
;
366 dprintf_listbox(stddeb
,"ListBoxInsertString(%d, %p);\n", uIndex
, newstr
);
368 if (!newstr
) return -1;
370 if (uIndex
== (UINT
)-1)
371 uIndex
= lphl
->ItemsCount
;
373 lppls
= &lphl
->lpFirst
;
374 for(Count
= 0; Count
< uIndex
; Count
++) {
375 if (*lppls
== NULL
) return LB_ERR
;
376 lppls
= (LPLISTSTRUCT
*) &(*lppls
)->lpNext
;
379 lplsnew
= ListBoxCreateItem(lphl
, Count
);
381 if (lplsnew
== NULL
) {
382 fprintf(stdnimp
,"ListBoxInsertString() out of memory !\n");
386 lplsnew
->lpNext
= *lppls
;
391 if (lphl
->HasStrings
) {
392 dprintf_listbox(stddeb
," string: %s\n", newstr
);
393 hStr
= LIST_HEAP_ALLOC(lphl
, LMEM_MOVEABLE
, strlen(newstr
) + 1);
394 str
= (LPSTR
)LIST_HEAP_ADDR(lphl
, hStr
);
395 if (str
== NULL
) return LB_ERRSPACE
;
397 lplsnew
->itemText
= str
;
398 /* I'm not so sure about the next one */
399 lplsnew
->mis
.itemData
= 0;
401 lplsnew
->itemText
= NULL
;
402 lplsnew
->mis
.itemData
= (DWORD
)newstr
;
405 lplsnew
->mis
.itemID
= uIndex
;
406 lplsnew
->hData
= hStr
;
408 /* adjust the itemID field of the following entries */
409 for(lpls
= lplsnew
->lpNext
; lpls
!= NULL
; lpls
= lpls
->lpNext
) {
413 if (lphl
->needMeasure
) {
414 ListBoxAskMeasure(lphl
, lplsnew
);
417 dprintf_listbox(stddeb
,"ListBoxInsertString // count=%d\n", lphl
->ItemsCount
);
422 int ListBoxAddString(LPHEADLIST lphl
, LPCSTR newstr
)
424 UINT pos
= (UINT
) -1;
426 if (lphl
->HasStrings
&& (lphl
->dwStyle
& LBS_SORT
)) {
427 LPLISTSTRUCT lpls
= lphl
->lpFirst
;
428 for (pos
= 0; lpls
!= NULL
; lpls
= lpls
->lpNext
, pos
++)
429 if (strcmp(lpls
->itemText
, newstr
) >= 0)
432 return ListBoxInsertString(lphl
, pos
, newstr
);
436 int ListBoxGetText(LPHEADLIST lphl
, UINT uIndex
, LPSTR OutStr
)
441 dprintf_listbox(stddeb
, "ListBoxGetText // OutStr==NULL\n");
445 lpls
= ListBoxGetItem (lphl
, uIndex
);
446 if (lpls
== NULL
) return LB_ERR
;
448 if (!lphl
->HasStrings
) {
449 *((long *)OutStr
) = lpls
->mis
.itemData
;
453 strcpy(OutStr
, lpls
->itemText
);
454 return strlen(OutStr
);
458 DWORD
ListBoxGetItemData(LPHEADLIST lphl
, UINT uIndex
)
462 lpls
= ListBoxGetItem (lphl
, uIndex
);
463 if (lpls
== NULL
) return LB_ERR
;
464 return lpls
->mis
.itemData
;
468 int ListBoxSetItemData(LPHEADLIST lphl
, UINT uIndex
, DWORD ItemData
)
470 LPLISTSTRUCT lpls
= ListBoxGetItem(lphl
, uIndex
);
472 if (lpls
== NULL
) return LB_ERR
;
473 lpls
->mis
.itemData
= ItemData
;
478 int ListBoxDeleteString(LPHEADLIST lphl
, UINT uIndex
)
480 LPLISTSTRUCT lpls
, lpls2
;
483 if (uIndex
>= lphl
->ItemsCount
) return LB_ERR
;
485 lpls
= lphl
->lpFirst
;
486 if (lpls
== NULL
) return LB_ERR
;
489 lphl
->lpFirst
= lpls
->lpNext
;
491 LPLISTSTRUCT lpls2
= NULL
;
492 for(Count
= 0; Count
< uIndex
; Count
++) {
493 if (lpls
->lpNext
== NULL
) return LB_ERR
;
496 lpls
= (LPLISTSTRUCT
)lpls
->lpNext
;
498 lpls2
->lpNext
= lpls
->lpNext
;
501 /* adjust the itemID field of the following entries */
502 for(lpls2
= lpls
->lpNext
; lpls2
!= NULL
; lpls2
= lpls2
->lpNext
) {
508 if (lpls
->hData
!= 0) LIST_HEAP_FREE(lphl
, lpls
->hData
);
511 return lphl
->ItemsCount
;
515 int ListBoxFindString(LPHEADLIST lphl
, UINT nFirst
, SEGPTR MatchStr
)
519 UINT First
= nFirst
+ 1;
520 LPSTR lpMatchStr
= (LPSTR
)MatchStr
;
522 if (First
> lphl
->ItemsCount
) return LB_ERR
;
524 if (lphl
->HasStrings
) lpMatchStr
= PTR_SEG_TO_LIN(MatchStr
);
526 lpls
= ListBoxGetItem(lphl
, First
);
528 while(lpls
!= NULL
) {
529 if (lphl
->HasStrings
) {
530 if (strstr(lpls
->itemText
, lpMatchStr
) == lpls
->itemText
) return Count
;
531 } else if (lphl
->dwStyle
& LBS_SORT
) {
532 /* XXX Do a compare item */
535 if (lpls
->mis
.itemData
== (DWORD
)lpMatchStr
) return Count
;
541 /* Start over at top */
543 lpls
= lphl
->lpFirst
;
545 while (Count
< First
) {
546 if (lphl
->HasStrings
) {
547 if (strstr(lpls
->itemText
, lpMatchStr
) == lpls
->itemText
) return Count
;
548 } else if (lphl
->dwStyle
& LBS_SORT
) {
549 /* XXX Do a compare item */
551 if (lpls
->mis
.itemData
== (DWORD
)lpMatchStr
) return Count
;
561 int ListBoxResetContent(LPHEADLIST lphl
)
566 if (lphl
->ItemsCount
== 0) return 0;
568 dprintf_listbox(stddeb
, "ListBoxResetContent // ItemCount = %d\n",
571 for(i
= 0; i
< lphl
->ItemsCount
; i
++) {
572 lpls
= lphl
->lpFirst
;
573 if (lpls
== NULL
) return LB_ERR
;
575 lphl
->lpFirst
= lpls
->lpNext
;
576 if (lpls
->hData
!= 0) LIST_HEAP_FREE(lphl
, lpls
->hData
);
579 ListBoxInitialize(lphl
);
584 /* --------------------- selection ------------------------- */
586 int ListBoxSetCurSel(LPHEADLIST lphl
, WORD wIndex
)
590 /* use ListBoxSetSel instead */
591 if (lphl
->dwStyle
& (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
) ) return 0;
593 /* unselect previous item */
594 if (lphl
->ItemFocused
!= -1) {
595 lphl
->PrevFocused
= lphl
->ItemFocused
;
596 lpls
= ListBoxGetItem(lphl
, lphl
->ItemFocused
);
597 if (lpls
== 0) return LB_ERR
;
601 if (wIndex
!= (UINT
)-1) {
602 lphl
->ItemFocused
= wIndex
;
603 lpls
= ListBoxGetItem(lphl
, wIndex
);
604 if (lpls
== 0) return LB_ERR
;
605 lpls
->itemState
= ODS_SELECTED
| ODS_FOCUS
;
614 int ListBoxSetSel(LPHEADLIST lphl
, WORD wIndex
, WORD state
)
619 if (!(lphl
->dwStyle
& (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
) ))
622 if (wIndex
== (UINT
)-1) {
623 for (lpls
= lphl
->lpFirst
; lpls
!= NULL
; lpls
= lpls
->lpNext
) {
624 if( lpls
->itemState
& ODS_SELECTED
) n
++;
625 lpls
->itemState
= state
? lpls
->itemState
| ODS_SELECTED
626 : lpls
->itemState
& ~ODS_SELECTED
;
631 if (wIndex
>= lphl
->ItemsCount
) return LB_ERR
;
633 lpls
= ListBoxGetItem(lphl
, wIndex
);
634 lpls
->itemState
= state
? lpls
->itemState
| ODS_SELECTED
635 : lpls
->itemState
& ~ODS_SELECTED
;
641 int ListBoxGetSel(LPHEADLIST lphl
, WORD wIndex
)
643 LPLISTSTRUCT lpls
= ListBoxGetItem(lphl
, wIndex
);
645 if (lpls
== NULL
) return LB_ERR
;
646 return lpls
->itemState
& ODS_SELECTED
;
649 /* ------------------------- dir listing ------------------------ */
651 LONG
ListBoxDirectory(LPHEADLIST lphl
, UINT attrib
, LPCSTR filespec
)
653 char temp
[16], mask
[13];
660 dprintf_listbox(stddeb
, "ListBoxDirectory: '%s' %04x\n", filespec
, attrib
);
661 if (!filespec
) return LB_ERR
;
662 if (!(ptr
= DOSFS_GetUnixFileName( filespec
, FALSE
))) return LB_ERR
;
664 p
= strrchr( path
, '/' );
666 if (!(ptr
= DOSFS_ToDosFCBFormat( p
)))
673 dprintf_listbox(stddeb
, "ListBoxDirectory: path=%s mask=%s\n", path
, mask
);
677 while ((count
= DOSFS_FindNext( path
, mask
, 0, attrib
, skip
, &entry
)) > 0)
680 if (entry
.attr
& FA_DIRECTORY
)
682 if ((attrib
& DDL_DIRECTORY
) && strcmp(entry
.name
, ". "))
684 sprintf(temp
, "[%s]", DOSFS_ToDosDTAFormat( entry
.name
) );
686 if ((ret
= ListBoxAddString(lphl
, temp
)) == LB_ERR
) break;
689 else /* not a directory */
691 if (!(attrib
& DDL_EXCLUSIVE
) ||
692 ((attrib
& (FA_RDONLY
|FA_HIDDEN
|FA_SYSTEM
|FA_ARCHIVE
)) ==
693 (entry
.attr
& (FA_RDONLY
|FA_HIDDEN
|FA_SYSTEM
|FA_ARCHIVE
))))
695 strcpy( temp
, DOSFS_ToDosDTAFormat( entry
.name
) );
697 if ((ret
= ListBoxAddString(lphl
, temp
)) == LB_ERR
) break;
701 if (attrib
& DDL_DRIVES
)
704 strcpy( temp
, "[-a-]" );
705 for (x
= 0; x
< MAX_DOS_DRIVES
; x
++, temp
[2]++)
707 if (DRIVE_IsValid(x
))
708 if ((ret
= ListBoxAddString(lphl
, temp
)) == LB_ERR
) break;
715 /* ------------------------- dimensions ------------------------- */
717 int ListBoxGetItemRect(LPHEADLIST lphl
, WORD wIndex
, LPRECT lprect
)
719 LPLISTSTRUCT lpls
= ListBoxGetItem(lphl
,wIndex
);
721 if (lpls
== NULL
) return LB_ERR
;
722 *lprect
= lpls
->itemRect
;
727 int ListBoxSetItemHeight(LPHEADLIST lphl
, WORD wIndex
, long height
)
731 if (!(lphl
->dwStyle
& LBS_OWNERDRAWVARIABLE
)) {
732 lphl
->StdItemHeight
= (short)height
;
736 lpls
= ListBoxGetItem(lphl
, wIndex
);
737 if (lpls
== NULL
) return LB_ERR
;
739 lpls
->mis
.itemHeight
= height
;
743 /* -------------------------- string search ------------------------ */
745 int ListBoxFindNextMatch(LPHEADLIST lphl
, WORD wChar
)
750 if ((char)wChar
< ' ') return LB_ERR
;
751 if (!lphl
->HasStrings
) return LB_ERR
;
753 lpls
= lphl
->lpFirst
;
755 for (count
= 0; lpls
!= NULL
; lpls
= lpls
->lpNext
, count
++) {
756 if (tolower(*lpls
->itemText
) == tolower((char)wChar
)) break;
758 if (lpls
== NULL
) return LB_ERR
;
760 for(; lpls
!= NULL
; lpls
= lpls
->lpNext
, count
++) {
761 if (*lpls
->itemText
!= (char)wChar
)
763 if ((short) count
> lphl
->ItemFocused
)
769 /***********************************************************************
772 static LONG
LBCreate(HWND hwnd
, WORD wParam
, LONG lParam
)
775 LONG dwStyle
= GetWindowLong(hwnd
,GWL_STYLE
);
778 CreateListBoxStruct(hwnd
, ODT_LISTBOX
, dwStyle
, GetParent(hwnd
));
779 lphl
= ListBoxGetStorageHeader(hwnd
);
780 dprintf_listbox(stddeb
,"ListBox created: lphl = %p dwStyle = %04x:%04x\n",
781 lphl
, HIWORD(dwStyle
), LOWORD(dwStyle
));
783 GetClientRect(hwnd
,&rect
);
784 lphl
->ColumnsWidth
= rect
.right
- rect
.left
;
786 SetScrollRange(hwnd
, SB_VERT
, 0, ListMaxFirstVisible(lphl
), TRUE
);
787 SetScrollRange(hwnd
, SB_HORZ
, 1, 1, TRUE
);
793 /***********************************************************************
796 static LONG
LBDestroy(HWND hwnd
, WORD wParam
, LONG lParam
)
798 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
800 ListBoxResetContent(lphl
);
802 DestroyListBoxStruct(lphl
);
803 dprintf_listbox(stddeb
,"ListBox destroyed: lphl = %p\n",lphl
);
807 /***********************************************************************
810 static LONG
LBVScroll(HWND hwnd
, WORD wParam
, LONG lParam
)
812 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
815 dprintf_listbox(stddeb
,"ListBox WM_VSCROLL w=%04X l=%08lX !\n",
817 y
= lphl
->FirstVisible
;
821 if (lphl
->FirstVisible
> 0)
822 lphl
->FirstVisible
--;
826 lphl
->FirstVisible
++;
830 if (lphl
->FirstVisible
> lphl
->ItemsVisible
) {
831 lphl
->FirstVisible
-= lphl
->ItemsVisible
;
833 lphl
->FirstVisible
= 0;
838 lphl
->FirstVisible
+= lphl
->ItemsVisible
;
842 lphl
->FirstVisible
= LOWORD(lParam
);
846 if (lphl
->FirstVisible
> ListMaxFirstVisible(lphl
))
847 lphl
->FirstVisible
= ListMaxFirstVisible(lphl
);
849 if (y
!= lphl
->FirstVisible
) {
850 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
851 InvalidateRect(hwnd
, NULL
, TRUE
);
856 /***********************************************************************
859 static LONG
LBHScroll(HWND hwnd
, WORD wParam
, LONG lParam
)
864 dprintf_listbox(stddeb
,"ListBox WM_HSCROLL w=%04X l=%08lX !\n",
866 lphl
= ListBoxGetStorageHeader(hwnd
);
867 y
= lphl
->FirstVisible
;
870 if (lphl
->FirstVisible
> lphl
->ItemsPerColumn
) {
871 lphl
->FirstVisible
-= lphl
->ItemsPerColumn
;
873 lphl
->FirstVisible
= 0;
877 lphl
->FirstVisible
+= lphl
->ItemsPerColumn
;
880 if (lphl
->ItemsPerColumn
!= 0) {
881 int lbsub
= lphl
->ItemsVisible
/ lphl
->ItemsPerColumn
* lphl
->ItemsPerColumn
;
882 if (lphl
->FirstVisible
> lbsub
) {
883 lphl
->FirstVisible
-= lbsub
;
885 lphl
->FirstVisible
= 0;
890 if (lphl
->ItemsPerColumn
!= 0)
891 lphl
->FirstVisible
+= lphl
->ItemsVisible
/
892 lphl
->ItemsPerColumn
* lphl
->ItemsPerColumn
;
895 lphl
->FirstVisible
= lphl
->ItemsPerColumn
* LOWORD(lParam
);
898 if (lphl
->FirstVisible
> ListMaxFirstVisible(lphl
))
899 lphl
->FirstVisible
= ListMaxFirstVisible(lphl
);
901 if (lphl
->ItemsPerColumn
!= 0) {
902 lphl
->FirstVisible
= lphl
->FirstVisible
/
903 lphl
->ItemsPerColumn
* lphl
->ItemsPerColumn
+ 1;
904 if (y
!= lphl
->FirstVisible
) {
905 SetScrollPos(hwnd
, SB_HORZ
, lphl
->FirstVisible
/
906 lphl
->ItemsPerColumn
+ 1, TRUE
);
907 InvalidateRect(hwnd
, NULL
, TRUE
);
913 /***********************************************************************
916 static LONG
LBLButtonDown(HWND hwnd
, WORD wParam
, LONG lParam
)
918 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
923 tmpPOINT
.x
= LOWORD(lParam
); tmpPOINT
.y
= HIWORD(lParam
);
928 lphl
->PrevFocused
= lphl
->ItemFocused
;
930 y
= ListBoxFindMouse(lphl
, LOWORD(lParam
), HIWORD(lParam
));
932 if (y
== -1) return 0;
934 if (lphl
->dwStyle
& LBS_NOTIFY
&& y
!= LB_ERR
)
935 if( SendMessage(lphl
->hParent
, WM_LBTRACKPOINT
, y
, lParam
) )
939 switch( lphl
->dwStyle
& (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
) )
941 case LBS_MULTIPLESEL
:
942 lphl
->ItemFocused
= y
;
943 wRet
= ListBoxGetSel(lphl
, y
);
944 ListBoxSetSel(lphl
, y
, !wRet
);
946 case LBS_EXTENDEDSEL
:
947 /* should handle extended mode here and in kbd handler
950 if ( lphl
->PrevFocused
!= y
&& y
!= LB_ERR
)
952 LPLISTSTRUCT lpls
= ListBoxGetItem( lphl
, lphl
->ItemFocused
= y
);
953 n
= ListBoxSetSel(lphl
,-1,FALSE
);
955 lpls
->itemState
= ODS_FOCUS
| ODS_SELECTED
;
957 if( n
> 1 && n
!= LB_ERR
)
958 InvalidateRect(hwnd
,NULL
,TRUE
);
965 if( y
!=lphl
->ItemFocused
)
966 ListBoxSetCurSel(lphl
, y
);
971 fprintf(stdnimp
,"Listbox: LBS_MULTIPLESEL and LBS_EXTENDEDSEL are on!\n");
975 /* invalidate changed items */
976 if( lphl
->dwStyle
& LBS_MULTIPLESEL
|| y
!=lphl
->PrevFocused
)
978 ListBoxGetItemRect(lphl
, y
, &rectsel
);
979 InvalidateRect(hwnd
, &rectsel
, TRUE
);
981 if( lphl
->PrevFocused
!=-1 && y
!=lphl
->PrevFocused
)
983 ListBoxGetItemRect(lphl
, lphl
->PrevFocused
, &rectsel
);
984 InvalidateRect(hwnd
, &rectsel
, TRUE
);
988 if (GetWindowLong(lphl
->hSelf
,GWL_EXSTYLE
) & WS_EX_DRAGDETECT
)
989 if( DragDetect(lphl
->hSelf
,tmpPOINT
) )
990 SendMessage(lphl
->hParent
, WM_BEGINDRAG
,0,0L);
995 /***********************************************************************
998 static LONG
LBLButtonUp(HWND hwnd
, WORD wParam
, LONG lParam
)
1000 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1002 if (GetCapture() == hwnd
) ReleaseCapture();
1004 if (lphl
->PrevFocused
!= lphl
->ItemFocused
)
1005 ListBoxSendNotification(lphl
, LBN_SELCHANGE
);
1010 /***********************************************************************
1013 static LONG
LBRButtonUp(HWND hwnd
, WORD wParam
, LONG lParam
)
1015 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1018 SendMessage(lphl
->hParent
, WM_COMMAND
,
1019 MAKEWPARAM(GetWindowWord(hwnd
,GWW_ID
),LBN_DBLCLK
),
1022 SendMessage(lphl
->hParent
, WM_COMMAND
, GetWindowWord(hwnd
,GWW_ID
),
1023 MAKELONG(hwnd
, LBN_DBLCLK
));
1029 /***********************************************************************
1032 static LONG
LBMouseMove(HWND hwnd
, WORD wParam
, LONG lParam
)
1034 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1035 int y
,redraw_prev
= 0;
1037 RECT rect
, rectsel
; /* XXX Broken */
1039 dprintf_listbox(stddeb
,"LBMouseMove %d %d\n",SLOWORD(lParam
),SHIWORD(lParam
));
1040 if ((wParam
& MK_LBUTTON
) != 0) {
1041 y
= SHIWORD(lParam
);
1042 if (y
< LBMM_EDGE
) {
1043 if (lphl
->FirstVisible
> 0) {
1044 lphl
->FirstVisible
--;
1045 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1046 InvalidateRect(hwnd
, NULL
, TRUE
);
1050 GetClientRect(hwnd
, &rect
);
1051 if (y
>= (rect
.bottom
-LBMM_EDGE
)) {
1052 if (lphl
->FirstVisible
< ListMaxFirstVisible(lphl
)) {
1053 lphl
->FirstVisible
++;
1054 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1055 InvalidateRect(hwnd
, NULL
, TRUE
);
1059 if ((y
> 0) && (y
< (rect
.bottom
- LBMM_EDGE
))) {
1060 if ((y
< rectsel
.top
) || (y
> rectsel
.bottom
)) {
1061 iRet
= ListBoxFindMouse(lphl
, LOWORD(lParam
), HIWORD(lParam
));
1062 if (iRet
== lphl
->ItemFocused
|| iRet
== -1) {
1065 if (lphl
->dwStyle
& LBS_MULTIPLESEL
) {
1066 lphl
->ItemFocused
= iRet
;
1067 ListBoxSendNotification(lphl
, LBN_SELCHANGE
);
1068 } else if ( lphl
->dwStyle
& LBS_EXTENDEDSEL
)
1070 /* Fixme: extended selection mode */
1071 ListBoxSetSel( lphl
, lphl
->ItemFocused
, 0);
1072 lphl
->PrevFocused
= lphl
->ItemFocused
;
1073 lphl
->ItemFocused
= iRet
;
1074 ListBoxSetSel( lphl
, iRet
, TRUE
);
1079 ListBoxSetCurSel(lphl
, (WORD
)iRet
);
1082 if( lphl
->PrevFocused
!=-1 && redraw_prev
)
1084 ListBoxGetItemRect(lphl
, lphl
->PrevFocused
, &rectsel
);
1085 InvalidateRect(hwnd
, &rectsel
, TRUE
);
1087 ListBoxGetItemRect(lphl
, iRet
, &rectsel
);
1088 InvalidateRect(hwnd
, &rectsel
, TRUE
);
1096 /***********************************************************************
1099 * Doesn't yet handle properly VK_SHIFT with LB_EXTENDEDSEL
1101 static LONG
LBKeyDown(HWND hwnd
, WORD wParam
, LONG lParam
)
1103 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1104 WORD newFocused
= 0xFFFF;
1107 ListBoxGetItemRect(lphl
,lphl
->ItemFocused
,&rect
);
1118 if ( lphl
->dwStyle
& LBS_WANTKEYBOARDINPUT
)
1120 newFocused
= (WORD
)(INT
)SendMessage(lphl
->hParent
,WM_VKEYTOITEM
,
1121 wParam
,MAKELPARAM(lphl
->ItemFocused
,hwnd
));
1122 if ( newFocused
== 0xFFFE ) return 0L;
1124 if ( newFocused
== 0xFFFF )
1126 newFocused
= lphl
->ItemFocused
;
1135 newFocused
= lphl
->ItemsCount
- 1;
1138 if (lphl
->dwStyle
& LBS_MULTICOLUMN
) {
1139 if (newFocused
>= lphl
->ItemsPerColumn
) {
1140 newFocused
-= lphl
->ItemsPerColumn
;
1147 if (newFocused
> 0) newFocused
--;
1150 if (lphl
->dwStyle
& LBS_MULTICOLUMN
)
1151 newFocused
+= lphl
->ItemsPerColumn
;
1157 if (newFocused
> lphl
->ItemsVisible
)
1158 newFocused
-= lphl
->ItemsVisible
;
1159 else newFocused
= 0;
1162 newFocused
+= lphl
->ItemsVisible
;
1167 /* end of nested switch */
1171 if (lphl
->dwStyle
& LBS_MULTIPLESEL
)
1173 WORD wRet
= ListBoxGetSel(lphl
, lphl
->ItemFocused
);
1174 ListBoxSetSel(lphl
, lphl
->ItemFocused
, !wRet
);
1178 /* chars are handled in LBChar */
1183 /* at this point newFocused is set up */
1185 if (newFocused
>= lphl
->ItemsCount
)
1186 newFocused
= lphl
->ItemsCount
- 1;
1188 if (!(lphl
->dwStyle
& LBS_MULTIPLESEL
))
1190 ListBoxSetCurSel(lphl
, newFocused
);
1191 ListBoxSendNotification(lphl
, LBN_SELCHANGE
);
1194 lphl
->ItemFocused
= newFocused
;
1196 if( ListBoxScrollToFocus(lphl
) || (lphl
->dwStyle
&
1197 (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
)) )
1198 InvalidateRect(hwnd
, NULL
, TRUE
);
1201 InvalidateRect(hwnd
, &rect
, TRUE
);
1202 if( newFocused
< 0x8000 )
1204 ListBoxGetItemRect(lphl
, newFocused
, &rect
);
1205 InvalidateRect(hwnd
, &rect
, TRUE
);
1209 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1214 /***********************************************************************
1217 static LONG
LBChar(HWND hwnd
, WORD wParam
, LONG lParam
)
1219 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1220 WORD newFocused
= 0xFFFF;
1222 if ( (lphl
->dwStyle
& LBS_WANTKEYBOARDINPUT
) && !(lphl
->HasStrings
))
1224 newFocused
= (WORD
)(INT
)SendMessage(lphl
->hParent
,WM_CHARTOITEM
,
1225 wParam
,MAKELPARAM(lphl
->ItemFocused
,hwnd
));
1226 if ( newFocused
== 0xFFFE ) return 0L;
1229 if (newFocused
== 0xFFFF )
1230 newFocused
= ListBoxFindNextMatch(lphl
, wParam
);
1232 if (newFocused
== (WORD
)LB_ERR
) return 0;
1234 if (newFocused
>= lphl
->ItemsCount
)
1235 newFocused
= lphl
->ItemsCount
- 1;
1237 if (!(lphl
->dwStyle
& LBS_MULTIPLESEL
))
1239 ListBoxSetCurSel(lphl
, newFocused
);
1240 ListBoxSendNotification(lphl
, LBN_SELCHANGE
);
1243 lphl
->ItemFocused
= newFocused
;
1244 ListBoxScrollToFocus(lphl
);
1245 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1247 InvalidateRect(hwnd
, NULL
, TRUE
);
1252 /***********************************************************************
1255 static LONG
LBSetRedraw(HWND hwnd
, WORD wParam
, LONG lParam
)
1257 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1259 dprintf_listbox(stddeb
,"ListBox WM_SETREDRAW hWnd=%04x w=%04x !\n",
1261 lphl
->bRedrawFlag
= wParam
;
1266 /***********************************************************************
1269 static LONG
LBSetFont(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1271 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1275 lphl
->hFont
= GetStockObject(SYSTEM_FONT
);
1277 lphl
->hFont
= (HFONT
) wParam
;
1279 /* a new font means possible new text height */
1280 /* does this mean the height of each entry must be separately changed? */
1281 /* or are we guaranteed to get a LBSetFont before the first insert/add? */
1282 if ((hdc
= GetDC(0)))
1285 GetTextMetrics( hdc
, &tm
);
1286 lphl
->StdItemHeight
= tm
.tmHeight
;
1287 dprintf_listbox(stddeb
,"LBSetFont: new font %d with height %d\n",
1288 lphl
->hFont
, lphl
->StdItemHeight
);
1289 ReleaseDC( 0, hdc
);
1295 /***********************************************************************
1298 static LONG
LBPaint(HWND hwnd
, WORD wParam
, LONG lParam
)
1300 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1305 HDC hdc
= BeginPaint( hwnd
, &ps
);
1306 DC
*dc
= (DC
*)GDI_GetObjPtr(hdc
, DC_MAGIC
);
1307 RECT rect
, paintRect
, scratchRect
;
1308 int i
, top
, height
, maxwidth
, ipc
;
1313 if (!IsWindowVisible(hwnd
) || !lphl
->bRedrawFlag
) {
1314 EndPaint(hwnd
, &ps
);
1318 GetRgnBox(dc
->w
.hGCClipRgn
,&paintRect
);
1319 GetClientRect(hwnd
, &rect
);
1320 IntersectRect(&paintRect
,&rect
,&paintRect
);
1322 hOldFont
= SelectObject(hdc
, lphl
->hFont
);
1325 hBrush
= (HBRUSH
) SendMessage(lphl
->hParent
, WM_CTLCOLORLISTBOX
, (WPARAM
)hdc
,
1328 hBrush
= SendMessage(lphl
->hParent
, WM_CTLCOLOR
, hdc
,
1329 MAKELONG(hwnd
, CTLCOLOR_LISTBOX
));
1332 if (hBrush
== 0) hBrush
= GetStockObject(WHITE_BRUSH
);
1334 FillRect(hdc
, &rect
, hBrush
);
1336 maxwidth
= rect
.right
;
1337 if (lphl
->dwStyle
& LBS_MULTICOLUMN
) {
1338 rect
.right
= lphl
->ColumnsWidth
;
1340 lpls
= lphl
->lpFirst
;
1342 lphl
->ItemsVisible
= 0;
1343 lphl
->ItemsPerColumn
= ipc
= 0;
1345 for(i
= 0; i
< lphl
->ItemsCount
; i
++) {
1346 if (lpls
== NULL
) break;
1348 if (i
>= lphl
->FirstVisible
) {
1349 height
= lpls
->mis
.itemHeight
;
1351 if (top
> (rect
.bottom
-height
+1)) {
1352 if (lphl
->dwStyle
& LBS_MULTICOLUMN
) {
1353 lphl
->ItemsPerColumn
= MAX(lphl
->ItemsPerColumn
, ipc
);
1356 rect
.left
+= lphl
->ColumnsWidth
;
1357 rect
.right
+= lphl
->ColumnsWidth
;
1358 if (rect
.left
> maxwidth
) break;
1364 lpls
->itemRect
.top
= top
;
1365 lpls
->itemRect
.bottom
= top
+ height
;
1366 lpls
->itemRect
.left
= rect
.left
;
1367 lpls
->itemRect
.right
= rect
.right
;
1369 if( IntersectRect(&scratchRect
,&paintRect
,&lpls
->itemRect
) )
1371 dprintf_listbox(stddeb
,"LBPaint: drawing item: %d %d %d %d %d\n",
1372 rect
.left
,top
,rect
.right
,top
+height
,lpls
->itemState
);
1374 if (lphl
->OwnerDrawn
&& (lphl
->ItemFocused
== i
) && GetFocus() == hwnd
)
1376 ListBoxDrawItem (hwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_FOCUS
,
1377 lpls
->itemState
& ~ODS_FOCUS
);
1378 ListBoxDrawItem (hwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_DRAWENTIRE
,
1379 lpls
->itemState
& ~ODS_FOCUS
);
1380 ListBoxDrawItem (hwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_FOCUS
, lpls
->itemState
);
1383 ListBoxDrawItem (hwnd
, lphl
, hdc
, lpls
, &lpls
->itemRect
, ODA_DRAWENTIRE
,
1388 lphl
->ItemsVisible
++;
1392 lpls
= lpls
->lpNext
;
1394 ListBoxUpdateWindow(hwnd
,lphl
,FALSE
);
1395 SelectObject(hdc
,hOldFont
);
1396 EndPaint( hwnd
, &ps
);
1400 /***********************************************************************
1403 static LONG
LBSetFocus(HWND hwnd
, WORD wParam
, LONG lParam
)
1405 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1407 dprintf_listbox(stddeb
,"ListBox WM_SETFOCUS for %04x\n",hwnd
);
1408 if(!(lphl
->dwStyle
& LBS_MULTIPLESEL
) )
1409 if( lphl
->ItemsCount
&& lphl
->ItemFocused
!= -1)
1411 HDC hDC
= GetDC(hwnd
);
1412 HFONT hOldFont
= SelectObject(hDC
, lphl
->hFont
);
1415 lpls
= ListBoxGetItem(lphl
,lphl
->ItemFocused
);
1416 lpls
->itemState
|= ODS_FOCUS
;
1418 ListBoxDrawItem(hwnd
,lphl
,hDC
,lpls
,&lpls
->itemRect
, ODA_FOCUS
, lpls
->itemState
);
1419 SelectObject(hDC
, hOldFont
);
1420 ReleaseDC(hwnd
,hDC
);
1423 ListBoxSendNotification(lphl
, LBN_SETFOCUS
);
1428 /***********************************************************************
1431 static LONG
LBKillFocus(HWND hwnd
, WORD wParam
, LONG lParam
)
1433 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1435 dprintf_listbox(stddeb
,"ListBox WM_KILLFOCUS for %04x\n",hwnd
);
1436 if (!(lphl
->dwStyle
& LBS_MULTIPLESEL
))
1438 if( lphl
->ItemsCount
)
1439 if( lphl
->ItemFocused
!= -1 )
1441 HDC hDC
= GetDC(hwnd
);
1442 HFONT hOldFont
= SelectObject(hDC
, lphl
->hFont
);
1445 lpls
= ListBoxGetItem(lphl
,lphl
->ItemFocused
);
1446 lpls
->itemState
&= ~ODS_FOCUS
;
1448 ListBoxDrawItem(hwnd
,lphl
,hDC
,lpls
,&lpls
->itemRect
, ODA_FOCUS
, lpls
->itemState
);
1449 SelectObject(hDC
, hOldFont
);
1450 ReleaseDC(hwnd
,hDC
);
1453 dprintf_listbox(stddeb
,"LBKillFocus: no focused item!\n");
1456 InvalidateRect(hwnd
, NULL
, TRUE
);
1458 ListBoxSendNotification(lphl
, LBN_KILLFOCUS
);
1463 /***********************************************************************
1466 static LONG
LBResetContent(HWND hwnd
, WORD wParam
, LONG lParam
)
1468 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1470 dprintf_listbox(stddeb
,"ListBox LB_RESETCONTENT !\n");
1471 ListBoxResetContent(lphl
);
1472 ListBoxUpdateWindow(hwnd
, lphl
, TRUE
);
1476 /***********************************************************************
1479 static LONG
LBDir(HWND hwnd
, WORD wParam
, LONG lParam
)
1482 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1483 dprintf_listbox(stddeb
,"ListBox LB_DIR !\n");
1485 ret
= ListBoxDirectory(lphl
, wParam
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
1486 ListBoxUpdateWindow(hwnd
, lphl
, TRUE
);
1490 /***********************************************************************
1493 static LONG
LBAddString(HWND hwnd
, WORD wParam
, LONG lParam
)
1496 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1498 if (lphl
->HasStrings
)
1499 wRet
= ListBoxAddString(lphl
, (LPCSTR
)PTR_SEG_TO_LIN(lParam
));
1501 wRet
= ListBoxAddString(lphl
, (LPCSTR
)lParam
);
1503 ListBoxUpdateWindow(hwnd
,lphl
,TRUE
);
1507 /***********************************************************************
1510 static LONG
LBGetText(HWND hwnd
, WORD wParam
, LONG lParam
)
1513 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1515 dprintf_listbox(stddeb
, "LB_GETTEXT wParam=%d\n",wParam
);
1516 wRet
= ListBoxGetText(lphl
, wParam
, (LPSTR
)PTR_SEG_TO_LIN(lParam
));
1521 /***********************************************************************
1524 static LONG
LBInsertString(HWND hwnd
, WORD wParam
, LONG lParam
)
1527 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1529 if (lphl
->HasStrings
)
1530 wRet
= ListBoxInsertString(lphl
, wParam
, (LPCSTR
)PTR_SEG_TO_LIN(lParam
));
1532 wRet
= ListBoxInsertString(lphl
, wParam
, (LPCSTR
)lParam
);
1534 ListBoxUpdateWindow(hwnd
,lphl
,TRUE
);
1538 /***********************************************************************
1541 static LONG
LBDeleteString(HWND hwnd
, WORD wParam
, LONG lParam
)
1543 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1544 LONG lRet
= ListBoxDeleteString(lphl
,wParam
);
1546 ListBoxUpdateWindow(hwnd
,lphl
,TRUE
);
1550 /***********************************************************************
1553 static LONG
LBFindString(HWND hwnd
, WORD wParam
, LONG lParam
)
1555 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1556 return ListBoxFindString(lphl
, wParam
, (SEGPTR
)lParam
);
1559 /***********************************************************************
1562 static LONG
LBGetCaretIndex(HWND hwnd
, WORD wParam
, LONG lParam
)
1564 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1565 return lphl
->ItemFocused
;
1568 /***********************************************************************
1571 static LONG
LBGetCount(HWND hwnd
, WORD wParam
, LONG lParam
)
1575 lphl
= ListBoxGetStorageHeader(hwnd
);
1576 return lphl
->ItemsCount
;
1579 /***********************************************************************
1582 static LONG
LBGetCurSel(HWND hwnd
, WORD wParam
, LONG lParam
)
1586 lphl
= ListBoxGetStorageHeader(hwnd
);
1587 dprintf_listbox(stddeb
,"ListBox LB_GETCURSEL %i !\n",
1589 return lphl
->ItemFocused
;
1592 /***********************************************************************
1593 * LBGetHorizontalExtent
1595 static LONG
LBGetHorizontalExtent(HWND hwnd
, WORD wParam
, LONG lParam
)
1600 /***********************************************************************
1603 static LONG
LBGetItemHeight(HWND hwnd
, WORD wParam
, LONG lParam
)
1605 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1606 LPLISTSTRUCT lpls
= ListBoxGetItem (lphl
, wParam
);
1608 if (lpls
== NULL
) return LB_ERR
;
1609 return lpls
->mis
.itemHeight
;
1612 /***********************************************************************
1615 static LONG
LBGetItemRect(HWND hwnd
, WORD wParam
, LONG lParam
)
1617 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1618 return ListBoxGetItemRect(lphl
, wParam
, PTR_SEG_TO_LIN(lParam
));
1621 /***********************************************************************
1624 static LONG
LBGetSel(HWND hwnd
, WORD wParam
, LONG lParam
)
1626 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1627 int iSel
= ListBoxGetSel(lphl
, wParam
);
1629 dprintf_listbox(stdnimp
,"LBGetSel: item %u - %i\n",wParam
,iSel
);
1631 return (iSel
)? 1 : 0;
1634 /***********************************************************************
1637 static LONG
LBGetSelCount(HWND hwnd
, WORD wParam
, LONG lParam
)
1639 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1644 if (!(lphl
->dwStyle
& (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
) ))
1647 for( lpls
= lphl
->lpFirst
;
1649 lpls
= lpls
->lpNext
)
1652 if (lpls
->itemState
)
1659 /***********************************************************************
1662 static LONG
LBGetSelItems(HWND hwnd
, WORD wParam
, LONG lParam
)
1664 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1667 int *lpItems
= PTR_SEG_TO_LIN(lParam
);
1669 if (!(lphl
->dwStyle
& (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
) ))
1672 if (wParam
== 0) return 0;
1674 lpls
= lphl
->lpFirst
;
1677 while (lpls
!= NULL
) {
1678 if (lpls
->itemState
> 0) lpItems
[cnt
++] = idx
;
1680 if (cnt
== wParam
) break;
1682 lpls
= lpls
->lpNext
;
1688 /***********************************************************************
1691 static LONG
LBGetTextLen(HWND hwnd
, WORD wParam
, LONG lParam
)
1693 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1694 LPLISTSTRUCT lpls
= ListBoxGetItem(lphl
,wParam
);
1696 if (lpls
== NULL
|| !lphl
->HasStrings
) return LB_ERR
;
1697 return strlen(lpls
->itemText
);
1700 /***********************************************************************
1703 static LONG
LBGetDlgCode(HWND hwnd
, WORD wParam
, LONG lParam
)
1705 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
1708 /***********************************************************************
1711 static LONG
LBGetTopIndex(HWND hwnd
, WORD wParam
, LONG lParam
)
1713 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1715 return lphl
->FirstVisible
;
1719 /***********************************************************************
1722 static LONG
LBSelectString(HWND hwnd
, WORD wParam
, LONG lParam
)
1724 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1727 iRet
= ListBoxFindString(lphl
, wParam
, (SEGPTR
)lParam
);
1731 if( lphl
->dwStyle
& (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
) )
1732 ListBoxSetSel(lphl
,iRet
,TRUE
);
1734 ListBoxSetCurSel(lphl
,iRet
);
1736 lphl
->ItemFocused
= iRet
;
1737 InvalidateRect(hwnd
,0,TRUE
);
1742 /***********************************************************************
1745 static LONG
LBSelItemRange(HWND hwnd
, WORD wParam
, LONG lParam
)
1747 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1750 WORD first
= LOWORD(lParam
);
1751 WORD last
= HIWORD(lParam
);
1752 BOOL select
= wParam
;
1754 if (!(lphl
->dwStyle
& (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
) ))
1757 if (first
>= lphl
->ItemsCount
||
1758 last
>= lphl
->ItemsCount
) return LB_ERR
;
1760 lpls
= lphl
->lpFirst
;
1763 while (lpls
!= NULL
) {
1765 lpls
->itemState
= select
? lpls
->itemState
| ODS_SELECTED
: 0;
1770 lpls
= lpls
->lpNext
;
1776 /***********************************************************************
1779 static LONG
LBSetCaretIndex(HWND hwnd
, WORD wParam
, LONG lParam
)
1781 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1784 if (!(lphl
->dwStyle
& (LBS_MULTIPLESEL
| LBS_EXTENDEDSEL
) )) return 0;
1786 dprintf_listbox(stddeb
,"LBSetCaretIndex: hwnd %04x n=%i\n",hwnd
,wParam
);
1788 if (wParam
>= lphl
->ItemsCount
) return LB_ERR
;
1790 lphl
->ItemFocused
= wParam
;
1791 i
= ListBoxScrollToFocus (lphl
);
1793 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1795 InvalidateRect(hwnd
, NULL
, TRUE
);
1800 /***********************************************************************
1803 static LONG
LBSetColumnWidth(HWND hwnd
, WORD wParam
, LONG lParam
)
1805 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1806 lphl
->ColumnsWidth
= wParam
;
1807 InvalidateRect(hwnd
,NULL
,TRUE
);
1811 /***********************************************************************
1812 * LBSetHorizontalExtent
1814 static LONG
LBSetHorizontalExtent(HWND hwnd
, WORD wParam
, LONG lParam
)
1819 /***********************************************************************
1822 static LONG
LBGetItemData(HWND hwnd
, WORD wParam
, LONG lParam
)
1824 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1825 dprintf_listbox(stddeb
, "LB_GETITEMDATA wParam=%x\n", wParam
);
1826 return ListBoxGetItemData(lphl
, wParam
);
1829 /***********************************************************************
1832 static LONG
LBSetItemData(HWND hwnd
, WORD wParam
, LONG lParam
)
1834 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1835 dprintf_listbox(stddeb
, "LB_SETITEMDATA wParam=%x lParam=%lx\n", wParam
, lParam
);
1836 return ListBoxSetItemData(lphl
, wParam
, lParam
);
1839 /***********************************************************************
1842 static LONG
LBSetTabStops(HWND hwnd
, WORD wParam
, LONG lParam
)
1846 lphl
= ListBoxGetStorageHeader(hwnd
);
1848 if (lphl
->TabStops
!= NULL
) {
1849 lphl
->iNumStops
= 0;
1850 free (lphl
->TabStops
);
1853 lphl
->TabStops
= malloc (wParam
* sizeof (short));
1854 if (lphl
->TabStops
) {
1855 lphl
->iNumStops
= wParam
;
1856 memcpy (lphl
->TabStops
, PTR_SEG_TO_LIN(lParam
), wParam
* sizeof (short));
1863 /***********************************************************************
1866 static LONG
LBSetCurSel(HWND hwnd
, WORD wParam
, LONG lParam
)
1868 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1871 dprintf_listbox(stddeb
,"ListBox LB_SETCURSEL wParam=%x !\n",
1874 wRet
= ListBoxSetCurSel(lphl
, wParam
);
1876 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1877 InvalidateRect(hwnd
, NULL
, TRUE
);
1882 /***********************************************************************
1885 static LONG
LBSetSel(HWND hwnd
, WORD wParam
, LONG lParam
)
1887 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1891 dprintf_listbox(stddeb
,"ListBox LB_SETSEL wParam=%x lParam=%lX !\n", wParam
, lParam
);
1893 iRet
= ListBoxSetSel(lphl
, LOWORD(lParam
), wParam
);
1896 InvalidateRect(hwnd
, NULL
, TRUE
);
1897 else if( iRet
!= LB_ERR
)
1899 if( lphl
->dwStyle
& LBS_EXTENDEDSEL
&&
1900 lphl
->ItemFocused
!= LOWORD(lParam
) )
1902 ListBoxGetItemRect(lphl
, lphl
->ItemFocused
, &rect
);
1903 InvalidateRect(hwnd
,&rect
,TRUE
);
1904 lphl
->ItemFocused
= LOWORD(lParam
);
1906 ListBoxGetItemRect(lphl
,LOWORD(lParam
),&rect
);
1907 InvalidateRect(hwnd
,&rect
,TRUE
);
1910 return (iRet
== (WORD
)LB_ERR
)? LB_ERR
: 0;
1913 /***********************************************************************
1916 static LONG
LBSetTopIndex(HWND hwnd
, WORD wParam
, LONG lParam
)
1918 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1920 dprintf_listbox(stddeb
,"ListBox LB_SETTOPINDEX wParam=%x !\n",
1922 lphl
->FirstVisible
= wParam
;
1923 SetScrollPos(hwnd
, SB_VERT
, lphl
->FirstVisible
, TRUE
);
1925 InvalidateRect(hwnd
, NULL
, TRUE
);
1930 /***********************************************************************
1933 static LONG
LBSetItemHeight(HWND hwnd
, WORD wParam
, LONG lParam
)
1935 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
1938 dprintf_listbox(stddeb
,"ListBox LB_SETITEMHEIGHT wParam=%x lParam=%lX !\n", wParam
, lParam
);
1939 wRet
= ListBoxSetItemHeight(lphl
, wParam
, lParam
);
1940 InvalidateRect(hwnd
,NULL
,TRUE
);
1944 /***********************************************************************
1947 static LRESULT
LBPassToParent(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1949 WND
* ptrWnd
= WIN_FindWndPtr(hwnd
);
1952 if( /* !(ptrWnd->dwExStyle & WS_EX_NOPARENTNOTIFY) && */
1954 return SendMessage(ptrWnd
->parent
->hwndSelf
,message
,wParam
,lParam
);
1958 /***********************************************************************
1961 LRESULT
ListBoxWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1964 case WM_CREATE
: return LBCreate(hwnd
, wParam
, lParam
);
1965 case WM_DESTROY
: return LBDestroy(hwnd
, wParam
, lParam
);
1966 case WM_GETDLGCODE
: return LBGetDlgCode(hwnd
, wParam
, lParam
);
1967 case WM_VSCROLL
: return LBVScroll(hwnd
, wParam
, lParam
);
1968 case WM_HSCROLL
: return LBHScroll(hwnd
, wParam
, lParam
);
1969 case WM_LBUTTONDOWN
: return LBLButtonDown(hwnd
, wParam
, lParam
);
1970 case WM_LBUTTONUP
: return LBLButtonUp(hwnd
, wParam
, lParam
);
1971 case WM_RBUTTONUP
: return LBRButtonUp(hwnd
, wParam
, lParam
);
1972 case WM_LBUTTONDBLCLK
: return LBRButtonUp(hwnd
, wParam
, lParam
);
1973 case WM_MOUSEMOVE
: return LBMouseMove(hwnd
, wParam
, lParam
);
1974 case WM_KEYDOWN
: return LBKeyDown(hwnd
, wParam
, lParam
);
1975 case WM_CHAR
: return LBChar(hwnd
, wParam
, lParam
);
1976 case WM_SETFONT
: return LBSetFont(hwnd
, wParam
, lParam
);
1977 case WM_SETREDRAW
: return LBSetRedraw(hwnd
, wParam
, lParam
);
1978 case WM_PAINT
: return LBPaint(hwnd
, wParam
, lParam
);
1979 case WM_SETFOCUS
: return LBSetFocus(hwnd
, wParam
, lParam
);
1980 case WM_KILLFOCUS
: return LBKillFocus(hwnd
, wParam
, lParam
);
1981 case LB_RESETCONTENT
: return LBResetContent(hwnd
, wParam
, lParam
);
1982 case LB_DIR
: return LBDir(hwnd
, wParam
, lParam
);
1983 case LB_ADDSTRING
: return LBAddString(hwnd
, wParam
, lParam
);
1984 case LB_INSERTSTRING
: return LBInsertString(hwnd
, wParam
, lParam
);
1985 case LB_DELETESTRING
: return LBDeleteString(hwnd
, wParam
, lParam
);
1986 case LB_FINDSTRING
: return LBFindString(hwnd
, wParam
, lParam
);
1987 case LB_GETCARETINDEX
: return LBGetCaretIndex(hwnd
, wParam
, lParam
);
1988 case LB_GETCOUNT
: return LBGetCount(hwnd
, wParam
, lParam
);
1989 case LB_GETCURSEL
: return LBGetCurSel(hwnd
, wParam
, lParam
);
1990 case LB_GETHORIZONTALEXTENT
: return LBGetHorizontalExtent(hwnd
, wParam
, lParam
);
1991 case LB_GETITEMDATA
: return LBGetItemData(hwnd
, wParam
, lParam
);
1992 case LB_GETITEMHEIGHT
: return LBGetItemHeight(hwnd
, wParam
, lParam
);
1993 case LB_GETITEMRECT
: return LBGetItemRect(hwnd
, wParam
, lParam
);
1994 case LB_GETSEL
: return LBGetSel(hwnd
, wParam
, lParam
);
1995 case LB_GETSELCOUNT
: return LBGetSelCount(hwnd
, wParam
, lParam
);
1996 case LB_GETSELITEMS
: return LBGetSelItems(hwnd
, wParam
, lParam
);
1997 case LB_GETTEXT
: return LBGetText(hwnd
, wParam
, lParam
);
1998 case LB_GETTEXTLEN
: return LBGetTextLen(hwnd
, wParam
, lParam
);
1999 case LB_GETTOPINDEX
: return LBGetTopIndex(hwnd
, wParam
, lParam
);
2000 case LB_SELECTSTRING
: return LBSelectString(hwnd
, wParam
, lParam
);
2001 case LB_SELITEMRANGE
: return LBSelItemRange(hwnd
, wParam
, lParam
);
2002 case LB_SETCARETINDEX
: return LBSetCaretIndex(hwnd
, wParam
, lParam
);
2003 case LB_SETCOLUMNWIDTH
: return LBSetColumnWidth(hwnd
, wParam
, lParam
);
2004 case LB_SETHORIZONTALEXTENT
: return LBSetHorizontalExtent(hwnd
, wParam
, lParam
);
2005 case LB_SETITEMDATA
: return LBSetItemData(hwnd
, wParam
, lParam
);
2006 case LB_SETTABSTOPS
: return LBSetTabStops(hwnd
, wParam
, lParam
);
2007 case LB_SETCURSEL
: return LBSetCurSel(hwnd
, wParam
, lParam
);
2008 case LB_SETSEL
: return LBSetSel(hwnd
, wParam
, lParam
);
2009 case LB_SETTOPINDEX
: return LBSetTopIndex(hwnd
, wParam
, lParam
);
2010 case LB_SETITEMHEIGHT
: return LBSetItemHeight(hwnd
, wParam
, lParam
);
2012 case WM_DROPFILES
: return LBPassToParent(hwnd
, message
, wParam
, lParam
);
2014 /* these will have to be implemented for proper LBS_EXTENDEDSEL -
2016 * anchor item is an item that with caret (focused) item defines a
2017 * range of currently selected items when listbox is in the extended
2020 case LB_SETANCHORINDEX
: return LB_SETANCHORINDEX
; /* that's what Windows returns */
2021 case LB_GETANCHORINDEX
: return 0;
2024 case WM_QUERYDROPOBJECT
:
2028 LPDRAGINFO lpDragInfo
= (LPDRAGINFO
) PTR_SEG_TO_LIN((SEGPTR
)lParam
);
2029 LPHEADLIST lphl
= ListBoxGetStorageHeader(hwnd
);
2031 lpDragInfo
->l
= ListBoxFindMouse(lphl
,lpDragInfo
->pt
.x
,
2034 return LBPassToParent(hwnd
, message
, wParam
, lParam
);
2038 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
2042 /**********************************************************************
2043 * DlgDirSelect (USER.99)
2045 BOOL
DlgDirSelect( HWND hDlg
, LPSTR lpStr
, INT id
)
2050 dprintf_listbox( stddeb
, "DlgDirSelect: %04x '%s' %d\n", hDlg
, lpStr
, id
);
2051 if ((i
= SendDlgItemMessage( hDlg
, id
, LB_GETCURSEL
, 0, 0 )) == LB_ERR
)
2053 SendDlgItemMessage( hDlg
, id
, LB_GETTEXT
, i
, MAKE_SEGPTR(buffer
) );
2054 if (buffer
[0] == '[') /* drive or directory */
2056 if (buffer
[1] == '-') /* drive */
2058 lpStr
[0] = buffer
[2];
2061 dprintf_listbox( stddeb
, "Returning drive '%s'\n", lpStr
);
2064 strcpy( lpStr
, buffer
+ 1 );
2065 lpStr
[strlen(lpStr
)-1] = '\\';
2066 dprintf_listbox( stddeb
, "Returning directory '%s'\n", lpStr
);
2069 strcpy( lpStr
, buffer
);
2070 dprintf_listbox( stddeb
, "Returning file '%s'\n", lpStr
);
2075 /**********************************************************************
2076 * DlgDirList (USER.100)
2078 INT
DlgDirList( HWND hDlg
, SEGPTR spec
, INT idLBox
, INT idStatic
, UINT attrib
)
2080 char *filespec
= (char *)PTR_SEG_TO_LIN( spec
);
2084 #define SENDMSG(msg,wparam,lparam) \
2085 ((attrib & DDL_POSTMSGS) ? PostMessage( hwnd, msg, wparam, lparam ) \
2086 : SendMessage( hwnd, msg, wparam, lparam ))
2088 dprintf_listbox( stddeb
, "DlgDirList: %04x '%s' %d %d %04x\n",
2089 hDlg
, filespec
? filespec
: "NULL",
2090 idLBox
, idStatic
, attrib
);
2092 if (filespec
&& filespec
[0] && (filespec
[1] == ':'))
2094 drive
= toupper( filespec
[0] ) - 'A';
2096 if (!DRIVE_SetCurrentDrive( drive
)) return FALSE
;
2098 else drive
= DRIVE_GetCurrentDrive();
2100 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
2103 char temp
[] = "*.*";
2105 if (!filespec
[0]) strcpy( mask
, "*.*" );
2108 /* If the path exists and is a directory, chdir to it */
2109 if (DRIVE_Chdir( drive
, filespec
)) strcpy( mask
, "*.*" );
2114 if ((p2
= strrchr( p
, '\\' ))) p
= p2
+ 1;
2115 if ((p2
= strrchr( p
, '/' ))) p
= p2
+ 1;
2116 lstrcpyn( mask
, p
, sizeof(mask
) );
2120 if (!DRIVE_Chdir( drive
, filespec
)) return FALSE
;
2125 strcpy( (char *)PTR_SEG_TO_LIN(spec
), mask
);
2127 dprintf_listbox(stddeb
, "ListBoxDirectory: path=%c:\\%s mask=%s\n",
2128 'A' + drive
, DRIVE_GetDosCwd(drive
), mask
);
2130 SENDMSG( LB_RESETCONTENT
, 0, 0 );
2131 if ((attrib
& DDL_DIRECTORY
) && !(attrib
& DDL_EXCLUSIVE
))
2133 if (SENDMSG( LB_DIR
, attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
2134 (LPARAM
)spec
) == LB_ERR
) return FALSE
;
2135 if (SENDMSG( LB_DIR
, (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
2136 (LPARAM
)MAKE_SEGPTR(temp
) ) == LB_ERR
) return FALSE
;
2140 if (SENDMSG( LB_DIR
, attrib
, (LPARAM
)spec
) == LB_ERR
) return FALSE
;
2144 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
2147 strcpy( temp
, "A:\\" );
2149 lstrcpyn( temp
+3, DRIVE_GetDosCwd(drive
), 253 );
2151 SENDMSG( WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(temp
) );