1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-25 19:55:48 +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

@@ -417,75 +417,93 @@ WMListAllowsEmptySelection(WMList *lPtr)
} }
static void
scrollByAmount(WMList *lPtr, int amount)
{
int itemCount = WMGetArrayItemCount(lPtr->items);
if ((amount < 0 && lPtr->topItem > 0) ||
(amount > 0 && (lPtr->topItem + lPtr->fullFitLines < itemCount))) {
lPtr->topItem += amount;
if (lPtr->topItem < 0)
lPtr->topItem = 0;
if (lPtr->topItem + lPtr->fullFitLines > itemCount)
lPtr->topItem = itemCount - lPtr->fullFitLines;
updateScroller(lPtr);
}
}
static void static void
vScrollCallBack(WMWidget *scroller, void *self) vScrollCallBack(WMWidget *scroller, void *self)
{ {
WMList *lPtr = (WMList*)self; WMList *lPtr = (WMList*)self;
WMScroller *sPtr = (WMScroller*)scroller;
int height; int height;
int topItem = lPtr->topItem; int oldTopItem = lPtr->topItem;
int itemCount = WMGetArrayItemCount(lPtr->items); int itemCount = WMGetArrayItemCount(lPtr->items);
height = lPtr->view->size.height - 4; height = lPtr->view->size.height - 4;
switch (WMGetScrollerHitPart(sPtr)) { switch (WMGetScrollerHitPart((WMScroller*)scroller)) {
case WSDecrementLine: case WSDecrementLine:
if (lPtr->topItem > 0) { //if (lPtr->topItem > 0) {
lPtr->topItem--; // lPtr->topItem--;
//
// updateScroller(lPtr);
//}
scrollByAmount(lPtr, -1);
break;
updateScroller(lPtr); case WSIncrementLine:
} //if (lPtr->topItem + lPtr->fullFitLines < itemCount) {
// lPtr->topItem++;
//
// updateScroller(lPtr);
//}
scrollByAmount(lPtr, 1);
break; break;
case WSDecrementPage: case WSDecrementPage:
if (lPtr->topItem > 0) { //if (lPtr->topItem > 0) {
lPtr->topItem -= lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1; // 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); // updateScroller(lPtr);
} //}
break; scrollByAmount(lPtr, -lPtr->fullFitLines+(1-lPtr->flags.dontFitAll)+1);
case WSIncrementLine:
if (lPtr->topItem + lPtr->fullFitLines < itemCount) {
lPtr->topItem++;
updateScroller(lPtr);
}
break; break;
case WSIncrementPage: case WSIncrementPage:
if (lPtr->topItem + lPtr->fullFitLines < itemCount) { //if (lPtr->topItem + lPtr->fullFitLines < itemCount) {
lPtr->topItem += lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1; // 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);
} //}
scrollByAmount(lPtr, lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1);
break; break;
case WSKnob: case WSKnob:
{ lPtr->topItem = WMGetScrollerValue(lPtr->vScroller) *
int oldTopItem = lPtr->topItem; (float)(itemCount - lPtr->fullFitLines);
lPtr->topItem = WMGetScrollerValue(lPtr->vScroller) * if (oldTopItem != lPtr->topItem)
(float)(itemCount - lPtr->fullFitLines); paintList(lPtr); // use updateScroller(lPtr) here?
if (oldTopItem != lPtr->topItem)
paintList(lPtr);
}
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