in do_mouseinput(), add mouse wheel support, per Helmut Jarausch's

suggestion


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4105 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2007-05-15 18:04:25 +00:00
parent c88556cbb1
commit b9fa1b1466
2 changed files with 122 additions and 82 deletions

View File

@ -1,3 +1,11 @@
2007-05-15 David Lawrence Ramsey <pooka109@gmail.com>
* winio.c (do_mouseinput): Add mouse wheel support, per Helmut
Jarausch's suggestion. Now, if nano is built with mouse support
and is using a version of ncurses compiled with the
--enable-ext-mouse option, rolling the mouse wheel up or down
will move the cursor three lines up or down.
2007-04-23 David Lawrence Ramsey <pooka109@gmail.com> 2007-04-23 David Lawrence Ramsey <pooka109@gmail.com>
* TODO: Add entries for fixing limitations with pasting text and * TODO: Add entries for fixing limitations with pasting text and

View File

@ -1624,14 +1624,17 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len)
} }
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
/* Check for a mouse event, and if one's taken place, save the /* Handle any mouse events that may have occurred. We currently handle
* coordinates where it took place in mouse_x and mouse_y. After that, * releases or clicks of the first mouse button. If allow_shortcuts is
* assuming allow_shortcuts is FALSE, if the shortcut list on the * TRUE, releasing or clicking on a visible shortcut will put back the
* bottom two lines of the screen is visible and the mouse event took * keystroke associated with that shortcut. If NCURSES_MOUSE_VERSION is
* place on it, figure out which shortcut was clicked and put back the * at least 2, we also currently handle presses of the fourth mouse
* equivalent keystroke(s). Return FALSE if no keystrokes were * button (upward rolls of the mouse wheel) by putting back the
* put back, or TRUE if at least one was. Assume that KEY_MOUSE has * keystrokes to move up, and presses of the fifth mouse button
* already been read in. */ * (downward rolls of the mouse wheel) by putting back the keystrokes to
* move down. Return FALSE if we don't put back any keystrokes in the
* course of handling mouse events, or TRUE if we do. Assume that
* KEY_MOUSE has already been read in. */
bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts) bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
{ {
MEVENT mevent; MEVENT mevent;
@ -1643,27 +1646,27 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
if (getmouse(&mevent) == ERR) if (getmouse(&mevent) == ERR)
return FALSE; return FALSE;
/* If it's not a release or click of the first mouse button, get /* Handle releases or clicks of the first mouse button. */
* out. */ if (mevent.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) {
if (!(mevent.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED))) /* Save the screen coordinates where the mouse event took
return FALSE; * place. */
/* Save the screen coordinates where the mouse event took place. */
*mouse_x = mevent.x; *mouse_x = mevent.x;
*mouse_y = mevent.y; *mouse_y = mevent.y;
/* If we're allowing shortcuts, the current shortcut list is being /* If we're allowing shortcuts, the current shortcut list is
* displayed on the last two lines of the screen, and the mouse * being displayed on the last two lines of the screen, and the
* event took place inside it, we need to figure out which shortcut * mouse event took place inside it, we need to figure out which
* was clicked and put back the equivalent keystroke(s) for it. */ * shortcut was clicked and put back the equivalent keystroke(s)
* for it. */
if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin, if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin,
*mouse_y, *mouse_x)) { *mouse_y, *mouse_x)) {
int i, j; int i, j;
size_t currslen; size_t currslen;
/* The number of shortcuts in the current shortcut list. */ /* The number of shortcuts in the current shortcut
* list. */
const shortcut *s = currshortcut; const shortcut *s = currshortcut;
/* The actual shortcut we clicked on, starting at the first /* The actual shortcut we clicked on, starting at the
* one in the current shortcut list. */ * first one in the current shortcut list. */
/* Get the shortcut lists' length. */ /* Get the shortcut lists' length. */
if (currshortcut == main_list) if (currshortcut == main_list)
@ -1695,9 +1698,10 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
if (j < 0) if (j < 0)
return FALSE; return FALSE;
/* Calculate the x-coordinate relative to the beginning of the /* Calculate the x-coordinate relative to the beginning of
* shortcut list in bottomwin, and add it to j. j should now be * the shortcut list in bottomwin, and add it to j. j
* the index in the shortcut list of the shortcut we clicked. */ * should now be the index in the shortcut list of the
* shortcut we clicked. */
j = (*mouse_x / i) * 2 + j; j = (*mouse_x / i) * 2 + j;
/* Adjust j if we clicked in the last two shortcuts. */ /* Adjust j if we clicked in the last two shortcuts. */
@ -1708,14 +1712,14 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
if (j >= currslen) if (j >= currslen)
return FALSE; return FALSE;
/* Go through the shortcut list to determine which shortcut was /* Go through the shortcut list to determine which shortcut
* clicked. */ * was clicked. */
for (; j > 0; j--) for (; j > 0; j--)
s = s->next; s = s->next;
/* And put back the equivalent key. Assume that each shortcut /* And put back the equivalent key. Assume that each
* has, at the very least, an equivalent control key, an * shortcut has, at the very least, an equivalent control
* equivalent primary meta key sequence, or both. */ * key, an equivalent primary meta key sequence, or both. */
if (s->ctrlval != NANO_NO_KEY) { if (s->ctrlval != NANO_NO_KEY) {
unget_kbinput(s->ctrlval, FALSE, FALSE); unget_kbinput(s->ctrlval, FALSE, FALSE);
return TRUE; return TRUE;
@ -1723,7 +1727,35 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
unget_kbinput(s->metaval, TRUE, FALSE); unget_kbinput(s->metaval, TRUE, FALSE);
return TRUE; return TRUE;
} }
} else
return FALSE;
} }
#if NCURSES_MOUSE_VERSION >= 2
/* Handle presses of the fourth mouse button (upward rolls of the
* mouse wheel). */
else if (mevent.bstate & BUTTON4_PRESSED) {
int i = 0;
/* One upward roll of the mouse wheel is equivalent to moving up
* three lines. */
for (; i < 3; i++)
unget_kbinput(NANO_PREVLINE_KEY, FALSE, FALSE);
return TRUE;
/* Handle presses of the fifth mouse button (downward rolls of the
* mouse wheel). */
} else if (mevent.bstate & BUTTON5_PRESSED) {
int i = 0;
/* One downward roll of the mouse wheel is equivalent to moving
* down three lines. */
for (; i < 3; i++)
unget_kbinput(NANO_NEXTLINE_KEY, FALSE, FALSE);
return TRUE;
}
#endif
else
return FALSE; return FALSE;
} }
#endif /* !DISABLE_MOUSE */ #endif /* !DISABLE_MOUSE */