7 char *WMListDidScrollNotification
= "WMListDidScrollNotification";
8 char *WMListSelectionDidChangeNotification
= "WMListSelectionDidChangeNotification";
10 typedef struct W_List
{
14 WMArray
*items
; /* list of WMListItem */
15 WMArray
*selectedItems
; /* list of selected WMListItems */
19 short topItem
; /* index of first visible item */
21 short fullFitLines
; /* no of lines that fit entirely */
25 void *doubleClientData
;
26 WMAction
*doubleAction
;
30 WMHandlerID
*idleID
; /* for updating the scroller after adding elements */
32 WMScroller
*vScroller
;
35 unsigned int allowMultipleSelection
:1;
36 unsigned int allowEmptySelection
:1;
37 unsigned int userDrawn
:1;
38 unsigned int userItemHeight
:1;
39 unsigned int dontFitAll
:1; /* 1 = last item won't be fully visible */
40 unsigned int redrawPending
:1;
41 unsigned int buttonPressed
:1;
42 unsigned int buttonWasPressed
:1;
48 #define DEFAULT_WIDTH 150
49 #define DEFAULT_HEIGHT 150
52 static void destroyList(List
*lPtr
);
53 static void paintList(List
*lPtr
);
56 static void handleEvents(XEvent
*event
, void *data
);
57 static void handleActionEvents(XEvent
*event
, void *data
);
58 static void updateScroller(List
*lPtr
);
60 static void vScrollCallBack(WMWidget
*scroller
, void *self
);
62 static void updateGeometry(WMList
*lPtr
);
63 static void didResizeList();
66 W_ViewDelegate _ListViewDelegate
= {
76 releaseItem(void *data
)
78 WMListItem
*item
= (WMListItem
*)data
;
87 WMCreateList(WMWidget
*parent
)
90 W_Screen
*scrPtr
= W_VIEW(parent
)->screen
;
92 lPtr
= wmalloc(sizeof(List
));
93 memset(lPtr
, 0, sizeof(List
));
95 lPtr
->widgetClass
= WC_List
;
97 lPtr
->view
= W_CreateView(W_VIEW(parent
));
102 lPtr
->view
->self
= lPtr
;
104 lPtr
->view
->delegate
= &_ListViewDelegate
;
106 WMCreateEventHandler(lPtr
->view
, ExposureMask
|StructureNotifyMask
107 |ClientMessageMask
, handleEvents
, lPtr
);
109 WMCreateEventHandler(lPtr
->view
, ButtonPressMask
|ButtonReleaseMask
110 |EnterWindowMask
|LeaveWindowMask
|ButtonMotionMask
,
111 handleActionEvents
, lPtr
);
113 lPtr
->itemHeight
= WMFontHeight(scrPtr
->normalFont
) + 1;
115 lPtr
->items
= WMCreateArrayWithDestructor(4, releaseItem
);
116 lPtr
->selectedItems
= WMCreateArray(4);
118 /* create the vertical scroller */
119 lPtr
->vScroller
= WMCreateScroller(lPtr
);
120 WMMoveWidget(lPtr
->vScroller
, 1, 1);
121 WMSetScrollerArrowsPosition(lPtr
->vScroller
, WSAMaxEnd
);
123 WMSetScrollerAction(lPtr
->vScroller
, vScrollCallBack
, lPtr
);
125 /* make the scroller map itself when it's realized */
126 WMMapWidget(lPtr
->vScroller
);
128 W_ResizeView(lPtr
->view
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
135 WMSetListAllowMultipleSelection(WMList
*lPtr
, Bool flag
)
137 lPtr
->flags
.allowMultipleSelection
= flag
? 1 : 0;
143 WMSetListAllowEmptySelection(WMList
*lPtr
, Bool flag
)
145 lPtr
->flags
.allowEmptySelection
= flag
? 1 : 0;
150 comparator(const void *a
, const void *b
)
152 return (strcmp((*(WMListItem
**)a
)->text
, (*(WMListItem
**)b
)->text
));
157 WMSortListItems(WMList
*lPtr
)
159 WMSortArray(lPtr
->items
, comparator
);
167 WMSortListItemsWithComparer(WMList
*lPtr
, WMCompareDataProc
*func
)
169 WMSortArray(lPtr
->items
, func
);
177 WMInsertListItem(WMList
*lPtr
, int row
, char *text
)
181 CHECK_CLASS(lPtr
, WC_List
);
183 item
= wmalloc(sizeof(WMListItem
));
184 memset(item
, 0, sizeof(WMListItem
));
185 item
->text
= wstrdup(text
);
187 row
= WMIN(row
, WMGetArrayItemCount(lPtr
->items
));
190 WMAddToArray(lPtr
->items
, item
);
192 WMInsertInArray(lPtr
->items
, row
, item
);
194 /* update the scroller when idle, so that we don't waste time
195 * updating it when another item is going to be added later */
197 lPtr
->idleID
= WMAddIdleHandler((WMCallback
*)updateScroller
, lPtr
);
205 WMRemoveListItem(WMList
*lPtr
, int row
)
208 int topItem
= lPtr
->topItem
;
211 CHECK_CLASS(lPtr
, WC_List
);
213 /*wassertr(row>=0 && row<WMGetArrayItemCount(lPtr->items));*/
214 if (row
<0 || row
>=WMGetArrayItemCount(lPtr
->items
))
217 item
= WMGetFromArray(lPtr
->items
, row
);
218 if (item
->selected
) {
219 WMRemoveFromArray(lPtr
->selectedItems
, item
);
223 if (row
<= lPtr
->topItem
+lPtr
->fullFitLines
+lPtr
->flags
.dontFitAll
)
225 if (lPtr
->topItem
< 0)
228 WMDeleteFromArray(lPtr
->items
, row
);
231 lPtr
->idleID
= WMAddIdleHandler((WMCallback
*)updateScroller
, lPtr
);
233 if (lPtr
->topItem
!= topItem
) {
234 WMPostNotificationName(WMListDidScrollNotification
, lPtr
, NULL
);
237 WMPostNotificationName(WMListSelectionDidChangeNotification
, lPtr
, NULL
);
243 WMGetListItem(WMList
*lPtr
, int row
)
245 return WMGetFromArray(lPtr
->items
, row
);
250 WMGetListItems(WMList
*lPtr
)
257 WMSetListUserDrawProc(WMList
*lPtr
, WMListDrawProc
*proc
)
259 lPtr
->flags
.userDrawn
= 1;
265 WMSetListUserDrawItemHeight(WMList
*lPtr
, unsigned short height
)
269 lPtr
->flags
.userItemHeight
= 1;
270 lPtr
->itemHeight
= height
;
272 updateGeometry(lPtr
);
277 WMClearList(WMList
*lPtr
)
279 int selNo
= WMGetArrayItemCount(lPtr
->selectedItems
);
281 WMEmptyArray(lPtr
->selectedItems
);
282 WMEmptyArray(lPtr
->items
);
287 WMDeleteIdleHandler(lPtr
->idleID
);
290 if (lPtr
->view
->flags
.realized
) {
291 updateScroller(lPtr
);
294 WMPostNotificationName(WMListSelectionDidChangeNotification
, lPtr
, NULL
);
300 WMSetListAction(WMList
*lPtr
, WMAction
*action
, void *clientData
)
302 lPtr
->action
= action
;
303 lPtr
->clientData
= clientData
;
308 WMSetListDoubleAction(WMList
*lPtr
, WMAction
*action
, void *clientData
)
310 lPtr
->doubleAction
= action
;
311 lPtr
->doubleClientData
= clientData
;
316 WMGetListSelectedItems(WMList
*lPtr
)
318 return lPtr
->selectedItems
;
323 WMGetListSelectedItem(WMList
*lPtr
)
325 return WMGetFromArray(lPtr
->selectedItems
, 0);
330 WMGetListSelectedItemRow(WMList
*lPtr
)
332 WMListItem
*item
= WMGetFromArray(lPtr
->selectedItems
, 0);
334 return (item
!=NULL
? WMGetFirstInArray(lPtr
->items
, item
) : WLNotFound
);
339 WMGetListItemHeight(WMList
*lPtr
)
341 return lPtr
->itemHeight
;
346 WMSetListPosition(WMList
*lPtr
, int row
)
349 if (lPtr
->topItem
+ lPtr
->fullFitLines
> WMGetArrayItemCount(lPtr
->items
))
350 lPtr
->topItem
= WMGetArrayItemCount(lPtr
->items
) - lPtr
->fullFitLines
;
352 if (lPtr
->topItem
< 0)
355 if (lPtr
->view
->flags
.realized
)
356 updateScroller(lPtr
);
361 WMSetListBottomPosition(WMList
*lPtr
, int row
)
363 if (WMGetArrayItemCount(lPtr
->items
) > lPtr
->fullFitLines
) {
364 lPtr
->topItem
= row
- lPtr
->fullFitLines
;
365 if (lPtr
->topItem
< 0)
367 if (lPtr
->view
->flags
.realized
)
368 updateScroller(lPtr
);
374 WMGetListNumberOfRows(WMList
*lPtr
)
376 return WMGetArrayItemCount(lPtr
->items
);
381 WMGetListPosition(WMList
*lPtr
)
383 return lPtr
->topItem
;
388 WMListAllowsMultipleSelection(WMList
*lPtr
)
390 return lPtr
->flags
.allowMultipleSelection
;
395 WMListAllowsEmptySelection(WMList
*lPtr
)
397 return lPtr
->flags
.allowEmptySelection
;
402 scrollByAmount(WMList
*lPtr
, int amount
)
404 int itemCount
= WMGetArrayItemCount(lPtr
->items
);
406 if ((amount
< 0 && lPtr
->topItem
> 0) ||
407 (amount
> 0 && (lPtr
->topItem
+ lPtr
->fullFitLines
< itemCount
))) {
409 lPtr
->topItem
+= amount
;
410 if (lPtr
->topItem
< 0)
412 if (lPtr
->topItem
+ lPtr
->fullFitLines
> itemCount
)
413 lPtr
->topItem
= itemCount
- lPtr
->fullFitLines
;
415 updateScroller(lPtr
);
421 vScrollCallBack(WMWidget
*scroller
, void *self
)
423 WMList
*lPtr
= (WMList
*)self
;
425 int oldTopItem
= lPtr
->topItem
;
426 int itemCount
= WMGetArrayItemCount(lPtr
->items
);
428 height
= lPtr
->view
->size
.height
- 4;
430 switch (WMGetScrollerHitPart((WMScroller
*)scroller
)) {
431 case WSDecrementLine
:
432 scrollByAmount(lPtr
, -1);
435 case WSIncrementLine
:
436 scrollByAmount(lPtr
, 1);
439 case WSDecrementPage
:
440 scrollByAmount(lPtr
, -lPtr
->fullFitLines
+(1-lPtr
->flags
.dontFitAll
)+1);
443 case WSIncrementPage
:
444 scrollByAmount(lPtr
, lPtr
->fullFitLines
-(1-lPtr
->flags
.dontFitAll
)-1);
447 case WSDecrementWheel
:
448 scrollByAmount(lPtr
, -lPtr
->fullFitLines
/ 3);
451 case WSIncrementWheel
:
452 scrollByAmount(lPtr
, lPtr
->fullFitLines
/ 3);
456 lPtr
->topItem
= WMGetScrollerValue(lPtr
->vScroller
) *
457 (float)(itemCount
- lPtr
->fullFitLines
);
459 if (oldTopItem
!= lPtr
->topItem
)
460 paintList(lPtr
); // use updateScroller(lPtr) here?
470 if (lPtr
->topItem
!= oldTopItem
)
471 WMPostNotificationName(WMListDidScrollNotification
, lPtr
, NULL
);
476 paintItem(List
*lPtr
, int index
)
478 WMView
*view
= lPtr
->view
;
479 W_Screen
*scr
= view
->screen
;
480 int width
, height
, x
, y
;
483 itemPtr
= WMGetFromArray(lPtr
->items
, index
);
485 width
= lPtr
->view
->size
.width
- 2 - 19;
486 height
= lPtr
->itemHeight
;
488 y
= 2 + (index
-lPtr
->topItem
) * lPtr
->itemHeight
+ 1;
490 if (lPtr
->flags
.userDrawn
) {
494 rect
.size
.width
= width
;
495 rect
.size
.height
= height
;
499 flags
= itemPtr
->uflags
;
500 if (itemPtr
->disabled
)
501 flags
|= WLDSDisabled
;
502 if (itemPtr
->selected
)
503 flags
|= WLDSSelected
;
504 if (itemPtr
->isBranch
)
505 flags
|= WLDSIsBranch
;
508 (*lPtr
->draw
)(lPtr
, index
, view
->window
, itemPtr
->text
, flags
,
511 if (itemPtr
->selected
) {
512 XFillRectangle(scr
->display
, view
->window
, WMColorGC(scr
->white
),
513 x
, y
, width
, height
);
515 XClearArea(scr
->display
, view
->window
, x
, y
, width
, height
, False
);
518 W_PaintText(view
, view
->window
, scr
->normalFont
, x
+4, y
, width
,
519 WALeft
, WMColorGC(scr
->black
), False
,
520 itemPtr
->text
, strlen(itemPtr
->text
));
523 if ((index
-lPtr
->topItem
+lPtr
->fullFitLines
)*lPtr
->itemHeight
>
524 lPtr
->view
->size
.height
-2) {
525 W_DrawRelief(lPtr
->view
->screen
, lPtr
->view
->window
, 0, 0,
526 lPtr
->view
->size
.width
, lPtr
->view
->size
.height
,
534 paintList(List
*lPtr
)
536 W_Screen
*scrPtr
= lPtr
->view
->screen
;
539 if (!lPtr
->view
->flags
.mapped
)
542 if (WMGetArrayItemCount(lPtr
->items
) > 0) {
543 if (lPtr
->topItem
+lPtr
->fullFitLines
+lPtr
->flags
.dontFitAll
544 > WMGetArrayItemCount(lPtr
->items
)) {
546 lim
= WMGetArrayItemCount(lPtr
->items
) - lPtr
->topItem
;
547 XClearArea(scrPtr
->display
, lPtr
->view
->window
, 19,
548 2+lim
*lPtr
->itemHeight
, lPtr
->view
->size
.width
-21,
549 lPtr
->view
->size
.height
-lim
*lPtr
->itemHeight
-3, False
);
551 lim
= lPtr
->fullFitLines
+ lPtr
->flags
.dontFitAll
;
553 for (i
= lPtr
->topItem
; i
< lPtr
->topItem
+ lim
; i
++) {
557 XClearWindow(scrPtr
->display
, lPtr
->view
->window
);
559 W_DrawRelief(scrPtr
, lPtr
->view
->window
, 0, 0, lPtr
->view
->size
.width
,
560 lPtr
->view
->size
.height
, WRSunken
);
565 scrollTo(List
*lPtr
, int newTop
)
572 updateScroller(List
*lPtr
)
574 float knobProportion
, floatValue
, tmp
;
575 int count
= WMGetArrayItemCount(lPtr
->items
);
578 WMDeleteIdleHandler(lPtr
->idleID
);
583 if (count
== 0 || count
<= lPtr
->fullFitLines
)
584 WMSetScrollerParameters(lPtr
->vScroller
, 0, 1);
586 tmp
= lPtr
->fullFitLines
;
587 knobProportion
= tmp
/(float)count
;
589 floatValue
= (float)lPtr
->topItem
/(float)(count
- lPtr
->fullFitLines
);
591 WMSetScrollerParameters(lPtr
->vScroller
, floatValue
, knobProportion
);
597 handleEvents(XEvent
*event
, void *data
)
599 List
*lPtr
= (List
*)data
;
601 CHECK_CLASS(data
, WC_List
);
604 switch (event
->type
) {
606 if (event
->xexpose
.count
!=0)
620 matchTitle(void *item
, void *title
)
622 return (strcmp(((WMListItem
*)item
)->text
, (char*)title
)==0 ? 1 : 0);
627 WMFindRowOfListItemWithTitle(WMList
*lPtr
, char *title
)
629 return WMFindInArray(lPtr
->items
, matchTitle
, title
);
634 WMSelectListItem(WMList
*lPtr
, int row
)
638 if (row
>= WMGetArrayItemCount(lPtr
->items
))
642 /* row = -1 will deselects all for backward compatibility.
643 * will be removed later. -Dan */
644 WMUnselectAllListItems(lPtr
);
648 item
= WMGetFromArray(lPtr
->items
, row
);
650 return; /* Return if already selected */
652 if (!lPtr
->flags
.allowMultipleSelection
) {
653 /* unselect previous selected items */
654 WMUnselectAllListItems(lPtr
);
659 WMAddToArray(lPtr
->selectedItems
, item
);
661 if (lPtr
->view
->flags
.mapped
&& row
>=lPtr
->topItem
662 && row
<=lPtr
->topItem
+lPtr
->fullFitLines
) {
663 paintItem(lPtr
, row
);
666 WMPostNotificationName(WMListSelectionDidChangeNotification
, lPtr
, NULL
);
671 WMUnselectListItem(WMList
*lPtr
, int row
)
673 WMListItem
*item
= WMGetFromArray(lPtr
->items
, row
);
675 if (!item
|| !item
->selected
)
678 if (!lPtr
->flags
.allowEmptySelection
&&
679 WMGetArrayItemCount(lPtr
->selectedItems
) <= 1) {
684 WMRemoveFromArray(lPtr
->selectedItems
, item
);
686 if (lPtr
->view
->flags
.mapped
&& row
>=lPtr
->topItem
687 && row
<=lPtr
->topItem
+lPtr
->fullFitLines
) {
688 paintItem(lPtr
, row
);
691 WMPostNotificationName(WMListSelectionDidChangeNotification
, lPtr
, NULL
);
696 WMSelectListItemsInRange(WMList
*lPtr
, WMRange range
)
699 int position
= range
.position
, k
= 1, notify
= 0;
700 int total
= WMGetArrayItemCount(lPtr
->items
);
702 if (!lPtr
->flags
.allowMultipleSelection
)
705 return; /* Nothing to select */
707 if (range
.count
< 0) {
708 range
.count
= -range
.count
;
712 for (; range
.count
>0 && position
>=0 && position
<total
; range
.count
--) {
713 item
= WMGetFromArray(lPtr
->items
, position
);
714 if (!item
->selected
) {
716 WMAddToArray(lPtr
->selectedItems
, item
);
717 if (lPtr
->view
->flags
.mapped
&& position
>=lPtr
->topItem
718 && position
<=lPtr
->topItem
+lPtr
->fullFitLines
) {
719 paintItem(lPtr
, position
);
727 WMPostNotificationName(WMListSelectionDidChangeNotification
, lPtr
, NULL
);
733 WMSetListSelectionToRange(WMList
*lPtr
, WMRange range
)
736 int mark1
, mark2
, i
, k
;
737 int position
= range
.position
, notify
= 0;
738 int total
= WMGetArrayItemCount(lPtr
->items
);
740 if (!lPtr
->flags
.allowMultipleSelection
)
743 if (range
.count
==0) {
744 WMUnselectAllListItems(lPtr
);
748 if (range
.count
< 0) {
749 mark1
= range
.position
+ range
.count
+ 1;
750 mark2
= range
.position
+ 1;
751 range
.count
= -range
.count
;
754 mark1
= range
.position
;
755 mark2
= range
.position
+ range
.count
;
763 WMEmptyArray(lPtr
->selectedItems
);
765 for (i
=0; i
<mark1
; i
++) {
766 item
= WMGetFromArray(lPtr
->items
, i
);
767 if (item
->selected
) {
769 if (lPtr
->view
->flags
.mapped
&& i
>=lPtr
->topItem
770 && i
<=lPtr
->topItem
+lPtr
->fullFitLines
) {
776 for (; range
.count
>0 && position
>=0 && position
<total
; range
.count
--) {
777 item
= WMGetFromArray(lPtr
->items
, position
);
778 if (!item
->selected
) {
780 if (lPtr
->view
->flags
.mapped
&& position
>=lPtr
->topItem
781 && position
<=lPtr
->topItem
+lPtr
->fullFitLines
) {
782 paintItem(lPtr
, position
);
786 WMAddToArray(lPtr
->selectedItems
, item
);
789 for (i
=mark2
; i
<total
; i
++) {
790 item
= WMGetFromArray(lPtr
->items
, i
);
791 if (item
->selected
) {
793 if (lPtr
->view
->flags
.mapped
&& i
>=lPtr
->topItem
794 && i
<=lPtr
->topItem
+lPtr
->fullFitLines
) {
802 WMPostNotificationName(WMListSelectionDidChangeNotification
, lPtr
, NULL
);
808 WMSelectAllListItems(WMList
*lPtr
)
813 if (!lPtr
->flags
.allowMultipleSelection
)
816 if (WMGetArrayItemCount(lPtr
->items
) ==
817 WMGetArrayItemCount(lPtr
->selectedItems
)) {
818 return; /* All items are selected already */
821 WMFreeArray(lPtr
->selectedItems
);
822 lPtr
->selectedItems
= WMCreateArrayWithArray(lPtr
->items
);
824 for (i
=0; i
<WMGetArrayItemCount(lPtr
->items
); i
++) {
825 item
= WMGetFromArray(lPtr
->items
, i
);
826 if (!item
->selected
) {
828 if (lPtr
->view
->flags
.mapped
&& i
>=lPtr
->topItem
829 && i
<=lPtr
->topItem
+lPtr
->fullFitLines
) {
835 WMPostNotificationName(WMListSelectionDidChangeNotification
, lPtr
, NULL
);
840 WMUnselectAllListItems(WMList
*lPtr
)
843 WMListItem
*item
;//, *keepItem;
845 // FIXME: check for allowEmptySelection
847 //keep = lPtr->flags.allowEmptySelection ? 0 : 1;
849 //if (WMGetArrayItemCount(lPtr->selectedItems) == keep)
850 // return 1; /* Nothing selected so return */
852 //keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL);
854 for (i
=0; i
<WMGetArrayItemCount(lPtr
->items
); i
++) {
855 item
= WMGetFromArray(lPtr
->items
, i
);
856 if (item
->selected
) {
858 if (lPtr
->view
->flags
.mapped
&& i
>=lPtr
->topItem
859 && i
<=lPtr
->topItem
+lPtr
->fullFitLines
) {
865 WMEmptyArray(lPtr
->selectedItems
);
866 WMPostNotificationName(WMListSelectionDidChangeNotification
, lPtr
, NULL
);
871 getItemIndexAt(List
*lPtr
, int clickY
)
875 index
= (clickY
- 2) / lPtr
->itemHeight
+ lPtr
->topItem
;
877 if (index
< 0 || index
>= WMGetArrayItemCount(lPtr
->items
))
885 handleActionEvents(XEvent
*event
, void *data
)
887 List
*lPtr
= (List
*)data
;
889 int topItem
= lPtr
->topItem
;
890 static int lastClicked
= -1, prevItem
= -1;
892 CHECK_CLASS(data
, WC_List
);
894 switch (event
->type
) {
896 /* Ignore mouse wheel events, they're not "real" button events */
897 if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
||
898 event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
902 lPtr
->flags
.buttonPressed
= 0;
903 tmp
= getItemIndexAt(lPtr
, event
->xbutton
.y
);
907 (*lPtr
->action
)(lPtr
, lPtr
->clientData
);
910 if (!(event
->xbutton
.state
& ShiftMask
))
911 lastClicked
= prevItem
= tmp
;
916 lPtr
->flags
.buttonPressed
= lPtr
->flags
.buttonWasPressed
;
917 lPtr
->flags
.buttonWasPressed
= 0;
921 lPtr
->flags
.buttonWasPressed
= lPtr
->flags
.buttonPressed
;
922 lPtr
->flags
.buttonPressed
= 0;
926 if (event
->xbutton
.x
<= WMWidgetWidth(lPtr
->vScroller
))
928 if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
||
929 event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
932 if (event
->xbutton
.state
& ControlMask
) {
933 amount
= lPtr
->fullFitLines
-(1-lPtr
->flags
.dontFitAll
)-1;
934 } else if (event
->xbutton
.state
& ShiftMask
) {
937 amount
= lPtr
->fullFitLines
/ 3;
941 if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
)
944 scrollByAmount(lPtr
, amount
);
948 tmp
= getItemIndexAt(lPtr
, event
->xbutton
.y
);
949 lPtr
->flags
.buttonPressed
= 1;
952 if (tmp
== lastClicked
&& WMIsDoubleClick(event
)) {
953 WMSelectListItem(lPtr
, tmp
);
954 if (lPtr
->doubleAction
)
955 (*lPtr
->doubleAction
)(lPtr
, lPtr
->doubleClientData
);
957 if (!lPtr
->flags
.allowMultipleSelection
) {
958 WMSelectListItem(lPtr
, tmp
);
961 WMListItem
*item
, *lastSel
;
963 if (event
->xbutton
.state
& ControlMask
) {
964 item
= WMGetFromArray(lPtr
->items
, tmp
);
965 if (item
&& item
->selected
) {
966 WMUnselectListItem(lPtr
, tmp
);
968 WMSelectListItem(lPtr
, tmp
);
970 } else if (event
->xbutton
.state
& ShiftMask
) {
971 if (WMGetArrayItemCount(lPtr
->selectedItems
) == 0) {
972 WMSelectListItem(lPtr
, tmp
);
974 lastSel
= WMGetFromArray(lPtr
->items
, lastClicked
);
975 range
.position
= WMGetFirstInArray(lPtr
->items
,
977 if (tmp
>= range
.position
)
978 range
.count
= tmp
- range
.position
+ 1;
980 range
.count
= tmp
- range
.position
- 1;
982 WMSetListSelectionToRange(lPtr
, range
);
985 range
.position
= tmp
;
987 WMSetListSelectionToRange(lPtr
, range
);
993 if (!(event
->xbutton
.state
& ShiftMask
))
994 lastClicked
= prevItem
= tmp
;
999 if (lPtr
->flags
.buttonPressed
) {
1000 tmp
= getItemIndexAt(lPtr
, event
->xmotion
.y
);
1001 if (tmp
>=0 && tmp
!=prevItem
) {
1002 if (lPtr
->flags
.allowMultipleSelection
) {
1005 range
.position
= lastClicked
;
1006 if (tmp
>= lastClicked
)
1007 range
.count
= tmp
- lastClicked
+ 1;
1009 range
.count
= tmp
- lastClicked
- 1;
1010 WMSetListSelectionToRange(lPtr
, range
);
1012 WMSelectListItem(lPtr
, tmp
);
1019 if (lPtr
->topItem
!= topItem
)
1020 WMPostNotificationName(WMListDidScrollNotification
, lPtr
, NULL
);
1025 updateGeometry(WMList
*lPtr
)
1027 lPtr
->fullFitLines
= (lPtr
->view
->size
.height
- 4) / lPtr
->itemHeight
;
1028 if (lPtr
->fullFitLines
* lPtr
->itemHeight
< lPtr
->view
->size
.height
- 4) {
1029 lPtr
->flags
.dontFitAll
= 1;
1031 lPtr
->flags
.dontFitAll
= 0;
1034 if (WMGetArrayItemCount(lPtr
->items
) - lPtr
->topItem
<= lPtr
->fullFitLines
) {
1035 lPtr
->topItem
= WMGetArrayItemCount(lPtr
->items
) - lPtr
->fullFitLines
;
1036 if (lPtr
->topItem
< 0)
1040 updateScroller(lPtr
);
1045 didResizeList(W_ViewDelegate
*self
, WMView
*view
)
1047 WMList
*lPtr
= (WMList
*)view
->self
;
1049 WMResizeWidget(lPtr
->vScroller
, 1, view
->size
.height
-2);
1051 updateGeometry(lPtr
);
1056 destroyList(List
*lPtr
)
1059 WMDeleteIdleHandler(lPtr
->idleID
);
1060 lPtr
->idleID
= NULL
;
1062 WMFreeArray(lPtr
->items
);