1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-11 00:44:12 +01:00

Initial mouse wheel code.

This commit is contained in:
dan
2000-04-13 21:24:28 +00:00
parent b188d55bbe
commit 5c76167098
6 changed files with 153 additions and 17 deletions

View File

@@ -387,9 +387,11 @@ typedef struct W_EventHandler {
typedef struct _WINGsConfiguration {
char *systemFont;
char *boldSystemFont;
int defaultFontSize;
int defaultFontSize;
Bool useMultiByte;
unsigned doubleClickDelay;
unsigned mouseWheelUp;
unsigned mouseWheelDown;
} _WINGsConfiguration;
extern _WINGsConfiguration WINGsConfiguration;

View File

@@ -10,11 +10,32 @@ _WINGsConfiguration WINGsConfiguration;
#define SYSTEM_FONT "-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-*-*-%d-*-*-*-*-*-*-*"
#define BOLD_SYSTEM_FONT "-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-bold-r-*-*-%d-*-*-*-*-*-*-*"
static unsigned
getButtonWithName(const char *name, unsigned defaultButton)
{
if (strncmp(name, "Button", 6)==0 && strlen(name)==7) {
switch (name[6]) {
case '1':
return Button1;
case '2':
return Button2;
case '3':
return Button3;
case '4':
return Button4;
case '5':
return Button5;
default:
break;
}
}
return defaultButton;
}
void
@@ -27,6 +48,9 @@ W_ReadConfigurations(void)
defaults = WMGetStandardUserDefaults();
if (defaults) {
char *buttonName;
unsigned button;
WINGsConfiguration.systemFont =
WMGetUDStringForKey(defaults, "SystemFont");
@@ -38,11 +62,34 @@ W_ReadConfigurations(void)
WINGsConfiguration.doubleClickDelay =
WMGetUDIntegerForKey(defaults, "DoubleClickTime");
buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
if (buttonName) {
button = getButtonWithName(buttonName, Button4);
free(buttonName);
} else {
button = Button4;
}
WINGsConfiguration.mouseWheelUp = button;
buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
if (buttonName) {
button = getButtonWithName(buttonName, Button5);
free(buttonName);
} else {
button = Button5;
}
WINGsConfiguration.mouseWheelDown = button;
if (WINGsConfiguration.mouseWheelDown==WINGsConfiguration.mouseWheelUp) {
WINGsConfiguration.mouseWheelUp = Button4;
WINGsConfiguration.mouseWheelDown = Button5;
}
WINGsConfiguration.defaultFontSize =
WMGetUDIntegerForKey(defaults, "DefaultFontSize");
WMGetUDIntegerForKey(defaults, "DefaultFontSize");
}
if (!WINGsConfiguration.systemFont) {
WINGsConfiguration.systemFont = SYSTEM_FONT;
@@ -53,6 +100,12 @@ W_ReadConfigurations(void)
if (WINGsConfiguration.doubleClickDelay == 0) {
WINGsConfiguration.doubleClickDelay = 250;
}
if (WINGsConfiguration.mouseWheelUp == 0) {
WINGsConfiguration.mouseWheelUp = Button4;
}
if (WINGsConfiguration.mouseWheelDown == 0) {
WINGsConfiguration.mouseWheelDown = Button5;
}
if (WINGsConfiguration.defaultFontSize == 0) {
WINGsConfiguration.defaultFontSize = 12;
}

View File

@@ -634,6 +634,37 @@ autoScroll(void *data)
}
static void
wheelScrollUp(PopUpButton *bPtr)
{
int testIndex = bPtr->selectedItemIndex - 1;
while (testIndex>=0 && !WMGetPopUpButtonItemEnabled(bPtr, testIndex))
testIndex--;
if (testIndex != -1) {
WMSetPopUpButtonSelectedItem(bPtr, testIndex);
if (bPtr->action)
(*bPtr->action)(bPtr, bPtr->clientData);
}
}
static void
wheelScrollDown(PopUpButton *bPtr)
{
int itemCount = WMGetBagItemCount(bPtr->items);
int testIndex = bPtr->selectedItemIndex + 1;
while (testIndex<itemCount && !WMGetPopUpButtonItemEnabled(bPtr, testIndex))
testIndex++;
if (testIndex != itemCount) {
WMSetPopUpButtonSelectedItem(bPtr, testIndex);
if (bPtr->action)
(*bPtr->action)(bPtr, bPtr->clientData);
}
}
static void
handleActionEvents(XEvent *event, void *data)
{
@@ -699,6 +730,14 @@ handleActionEvents(XEvent *event, void *data)
if (!bPtr->flags.enabled)
break;
if (!bPtr->flags.pullsDown && !bPtr->menuView->flags.mapped) {
if (event->xbutton.button==WINGsConfiguration.mouseWheelDown) {
wheelScrollDown(bPtr);
} else if (event->xbutton.button==WINGsConfiguration.mouseWheelUp) {
wheelScrollUp(bPtr);
}
break;
}
popUpMenu(bPtr);
if (!bPtr->flags.pullsDown) {
bPtr->highlightedItem = bPtr->selectedItemIndex;
@@ -714,6 +753,10 @@ handleActionEvents(XEvent *event, void *data)
break;
case ButtonRelease:
if (event->xbutton.button==WINGsConfiguration.mouseWheelUp ||
event->xbutton.button==WINGsConfiguration.mouseWheelDown) {
break;
}
XUngrabPointer(bPtr->view->screen->display, event->xbutton.time);
if (!bPtr->flags.pullsDown)
popDownMenu(bPtr);
@@ -725,9 +768,9 @@ handleActionEvents(XEvent *event, void *data)
if (bPtr->flags.insideMenu && bPtr->highlightedItem>=0) {
WMMenuItem *item;
item = WMGetPopUpButtonMenuItem(bPtr, bPtr->highlightedItem);
if (WMGetMenuItemEnabled(item)) {
int i;
WMSetPopUpButtonSelectedItem(bPtr, bPtr->highlightedItem);

View File

@@ -815,14 +815,29 @@ handleActionEvents(XEvent *event, void *data)
case ButtonPress:
/* FIXME: change Mod1Mask with something else */
handlePush(sPtr, event->xbutton.x, event->xbutton.y,
(event->xbutton.state & Mod1Mask)
||event->xbutton.button==Button2);
/* continue scrolling if pushed on the buttons */
if (sPtr->flags.hitPart == WSIncrementLine
|| sPtr->flags.hitPart == WSDecrementLine) {
sPtr->timerID = WMAddTimerHandler(AUTOSCROLL_INITIAL_DELAY,
autoScroll, sPtr);
if (event->xbutton.button==WINGsConfiguration.mouseWheelUp) {
sPtr->flags.decrDown = 1;
sPtr->flags.hitPart = WSDecrementPage;
if (sPtr->action) {
(*sPtr->action)(sPtr, sPtr->clientData);
}
}
else if (event->xbutton.button==WINGsConfiguration.mouseWheelDown) {
sPtr->flags.incrDown = 1;
sPtr->flags.hitPart = WSIncrementPage;
if (sPtr->action) {
(*sPtr->action)(sPtr, sPtr->clientData);
}
} else {
handlePush(sPtr, event->xbutton.x, event->xbutton.y,
(event->xbutton.state & Mod1Mask)
||event->xbutton.button==Button2);
/* continue scrolling if pushed on the buttons */
if (sPtr->flags.hitPart == WSIncrementLine
|| sPtr->flags.hitPart == WSDecrementLine) {
sPtr->timerID = WMAddTimerHandler(AUTOSCROLL_INITIAL_DELAY,
autoScroll, sPtr);
}
}
break;

View File

@@ -481,7 +481,28 @@ handleActionEvents(XEvent *event, void *data)
switch (event->type) {
case ButtonPress:
if (getSliderPart(sPtr, event->xbutton.x, event->xbutton.y)==KNOB_PART)
if (event->xbutton.button==WINGsConfiguration.mouseWheelUp
&&!sPtr->flags.dragging) {
// Wheel up
if (sPtr->value+1<=sPtr->maxValue) {
WMSetSliderValue(sPtr, sPtr->value+1);
if (sPtr->flags.continuous && sPtr->action) {
(*sPtr->action)(sPtr, sPtr->clientData);
}
}
} else if (event->xbutton.button==WINGsConfiguration.mouseWheelDown
&&!sPtr->flags.dragging) {
// Wheel down
if (sPtr->value-1>=sPtr->minValue)
{
WMSetSliderValue(sPtr, sPtr->value-1);
if (sPtr->flags.continuous && sPtr->action) {
(*sPtr->action)(sPtr, sPtr->clientData);
}
}
}
else if (getSliderPart(sPtr, event->xbutton.x, event->xbutton.y)
==KNOB_PART)
sPtr->flags.dragging = 1;
else {
#ifdef STRICT_NEXT_BEHAVIOUR

View File

@@ -3,4 +3,6 @@
BoldSystemFont = "-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*";
MultiByteText = NO;
DoubleClickTime = 250;
MouseWheelUp = Button4;
MouseWheelDown = Button5;
}