1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-03-18 08:33:33 +01:00

- More code for multiple selection in WMList.

- Better handling of mouse wheels (Shift and Control modifiers are used to
  select how muct to scroll on mouse wheel movement).
This commit is contained in:
dan
2000-09-28 14:06:50 +00:00
parent bb8065ebc9
commit 60a01b0f58

View File

@@ -418,74 +418,92 @@ WMListAllowsEmptySelection(WMList *lPtr)
static void static void
vScrollCallBack(WMWidget *scroller, void *self) scrollByAmount(WMList *lPtr, int amount)
{ {
WMList *lPtr = (WMList*)self;
WMScroller *sPtr = (WMScroller*)scroller;
int height;
int topItem = lPtr->topItem;
int itemCount = WMGetArrayItemCount(lPtr->items); int itemCount = WMGetArrayItemCount(lPtr->items);
height = lPtr->view->size.height - 4; if ((amount < 0 && lPtr->topItem > 0) ||
(amount > 0 && (lPtr->topItem + lPtr->fullFitLines < itemCount))) {
switch (WMGetScrollerHitPart(sPtr)) { lPtr->topItem += amount;
case WSDecrementLine:
if (lPtr->topItem > 0) {
lPtr->topItem--;
updateScroller(lPtr);
}
break;
case WSDecrementPage:
if (lPtr->topItem > 0) {
lPtr->topItem -= lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1;
if (lPtr->topItem < 0) if (lPtr->topItem < 0)
lPtr->topItem = 0; lPtr->topItem = 0;
updateScroller(lPtr);
}
break;
case WSIncrementLine:
if (lPtr->topItem + lPtr->fullFitLines < itemCount) {
lPtr->topItem++;
updateScroller(lPtr);
}
break;
case WSIncrementPage:
if (lPtr->topItem + lPtr->fullFitLines < itemCount) {
lPtr->topItem += lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1;
if (lPtr->topItem + lPtr->fullFitLines > itemCount) if (lPtr->topItem + lPtr->fullFitLines > itemCount)
lPtr->topItem = itemCount - lPtr->fullFitLines; lPtr->topItem = itemCount - lPtr->fullFitLines;
updateScroller(lPtr); updateScroller(lPtr);
} }
}
static void
vScrollCallBack(WMWidget *scroller, void *self)
{
WMList *lPtr = (WMList*)self;
int height;
int oldTopItem = lPtr->topItem;
int itemCount = WMGetArrayItemCount(lPtr->items);
height = lPtr->view->size.height - 4;
switch (WMGetScrollerHitPart((WMScroller*)scroller)) {
case WSDecrementLine:
//if (lPtr->topItem > 0) {
// lPtr->topItem--;
//
// updateScroller(lPtr);
//}
scrollByAmount(lPtr, -1);
break;
case WSIncrementLine:
//if (lPtr->topItem + lPtr->fullFitLines < itemCount) {
// lPtr->topItem++;
//
// updateScroller(lPtr);
//}
scrollByAmount(lPtr, 1);
break;
case WSDecrementPage:
//if (lPtr->topItem > 0) {
// lPtr->topItem -= lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1;
// if (lPtr->topItem < 0)
// lPtr->topItem = 0;
//
// updateScroller(lPtr);
//}
scrollByAmount(lPtr, -lPtr->fullFitLines+(1-lPtr->flags.dontFitAll)+1);
break;
case WSIncrementPage:
//if (lPtr->topItem + lPtr->fullFitLines < itemCount) {
// lPtr->topItem += lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1;
//
// if (lPtr->topItem + lPtr->fullFitLines > itemCount)
// lPtr->topItem = itemCount - lPtr->fullFitLines;
//
// updateScroller(lPtr);
//}
scrollByAmount(lPtr, lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1);
break; break;
case WSKnob: case WSKnob:
{
int oldTopItem = lPtr->topItem;
lPtr->topItem = WMGetScrollerValue(lPtr->vScroller) * lPtr->topItem = WMGetScrollerValue(lPtr->vScroller) *
(float)(itemCount - lPtr->fullFitLines); (float)(itemCount - lPtr->fullFitLines);
if (oldTopItem != lPtr->topItem) if (oldTopItem != lPtr->topItem)
paintList(lPtr); paintList(lPtr); // use updateScroller(lPtr) here?
}
break; break;
case WSKnobSlot: case WSKnobSlot:
case WSNoPart: case WSNoPart:
default:
/* do nothing */ /* do nothing */
break; break;
} }
if (lPtr->topItem != topItem) if (lPtr->topItem != oldTopItem)
WMPostNotificationName(WMListDidScrollNotification, lPtr, NULL); WMPostNotificationName(WMListDidScrollNotification, lPtr, NULL);
} }
@@ -728,8 +746,9 @@ handleActionEvents(XEvent *event, void *data)
#ifdef CHECK_WHEEL_PATCH #ifdef CHECK_WHEEL_PATCH
/* Ignore mouse wheel events, they're not "real" button events */ /* Ignore mouse wheel events, they're not "real" button events */
if (event->xbutton.button == WINGsConfiguration.mouseWheelUp || if (event->xbutton.button == WINGsConfiguration.mouseWheelUp ||
event->xbutton.button == WINGsConfiguration.mouseWheelDown) event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
break; break;
}
#endif #endif
lPtr->flags.buttonPressed = 0; lPtr->flags.buttonPressed = 0;
@@ -754,17 +773,12 @@ handleActionEvents(XEvent *event, void *data)
case ButtonPress: case ButtonPress:
if (event->xbutton.x > WMWidgetWidth(lPtr->vScroller)) { if (event->xbutton.x > WMWidgetWidth(lPtr->vScroller)) {
#ifdef CHECK_WHEEL_PATCH #ifdef CHECK_WHEEL_PATCH
/* Mouse wheel events need to be properly handled here. It would int amount = 0;
* be best to somehow route them to lPtr->vScroller so that the
* correct chain of actions is triggered. However, I found no
* clean way to do so, so I mostly copied the code that deals with
* WSIncrementPage and WSDecrementPage from vScrollCallBack.
*
* - Martynas Kunigelis <diskena@linuxfreak.com> */
// join them
if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) { if (event->xbutton.button == WINGsConfiguration.mouseWheelDown) {
/* Wheel down */ /* Wheel down */
int itemCount = WMGetArrayItemCount(lPtr->items); /*int itemCount = WMGetArrayItemCount(lPtr->items);
if (lPtr->topItem + lPtr->fullFitLines < itemCount) { if (lPtr->topItem + lPtr->fullFitLines < itemCount) {
int incr = lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1; int incr = lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1;
lPtr->topItem += incr; lPtr->topItem += incr;
@@ -773,13 +787,24 @@ handleActionEvents(XEvent *event, void *data)
lPtr->topItem = itemCount - lPtr->fullFitLines; lPtr->topItem = itemCount - lPtr->fullFitLines;
updateScroller(lPtr); updateScroller(lPtr);
}*/
if (event->xbutton.state & ShiftMask) {
amount = lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1;
} else if (event->xbutton.state & ControlMask) {
amount = 1;
} else {
amount = lPtr->fullFitLines / 3;
if (amount == 0)
amount++;
} }
scrollByAmount(lPtr, amount);
break; break;
} }
if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) { if (event->xbutton.button == WINGsConfiguration.mouseWheelUp) {
/* Wheel up */ /* Wheel up */
if (lPtr->topItem > 0) { /*if (lPtr->topItem > 0) {
int decr = lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1; int decr = lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1;
lPtr->topItem -= decr; lPtr->topItem -= decr;
@@ -787,7 +812,18 @@ handleActionEvents(XEvent *event, void *data)
lPtr->topItem = 0; lPtr->topItem = 0;
updateScroller(lPtr); updateScroller(lPtr);
}*/
if (event->xbutton.state & ShiftMask) {
amount = -lPtr->fullFitLines+(1-lPtr->flags.dontFitAll)+1;
} else if (event->xbutton.state & ControlMask) {
amount = -1;
} else {
amount = -(lPtr->fullFitLines / 3);
if (amount == 0)
amount--;
} }
scrollByAmount(lPtr, amount);
break; break;
} }
#endif #endif