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,88 +1646,117 @@ 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. */
*mouse_x = mevent.x;
*mouse_y = mevent.y;
/* Save the screen coordinates where the mouse event took place. */ /* If we're allowing shortcuts, the current shortcut list is
*mouse_x = mevent.x; * being displayed on the last two lines of the screen, and the
*mouse_y = mevent.y; * mouse event took place inside it, we need to figure out which
* shortcut was clicked and put back the equivalent keystroke(s)
* for it. */
if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin,
*mouse_y, *mouse_x)) {
int i, j;
size_t currslen;
/* The number of shortcuts in the current shortcut
* list. */
const shortcut *s = currshortcut;
/* The actual shortcut we clicked on, starting at the
* first one in the current shortcut list. */
/* If we're allowing shortcuts, the current shortcut list is being /* Get the shortcut lists' length. */
* displayed on the last two lines of the screen, and the mouse if (currshortcut == main_list)
* event took place inside it, we need to figure out which shortcut
* was clicked and put back the equivalent keystroke(s) for it. */
if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin,
*mouse_y, *mouse_x)) {
int i, j;
size_t currslen;
/* The number of shortcuts in the current shortcut list. */
const shortcut *s = currshortcut;
/* The actual shortcut we clicked on, starting at the first
* one in the current shortcut list. */
/* Get the shortcut lists' length. */
if (currshortcut == main_list)
currslen = MAIN_VISIBLE;
else {
currslen = length_of_list(currshortcut);
/* We don't show any more shortcuts than the main list
* does. */
if (currslen > MAIN_VISIBLE)
currslen = MAIN_VISIBLE; currslen = MAIN_VISIBLE;
} else {
currslen = length_of_list(currshortcut);
/* Calculate the width of all of the shortcuts in the list /* We don't show any more shortcuts than the main list
* except for the last two, which are longer by (COLS % i) * does. */
* columns so as to not waste space. */ if (currslen > MAIN_VISIBLE)
if (currslen < 2) currslen = MAIN_VISIBLE;
i = COLS / (MAIN_VISIBLE / 2); }
else
i = COLS / ((currslen / 2) + (currslen % 2));
/* Calculate the y-coordinate relative to the beginning of /* Calculate the width of all of the shortcuts in the list
* the shortcut list in bottomwin, i.e. with the sizes of * except for the last two, which are longer by (COLS % i)
* topwin, edit, and the first line of bottomwin subtracted * columns so as to not waste space. */
* out, and set j to it. */ if (currslen < 2)
j = *mouse_y - (2 - no_more_space()) - editwinrows - 1; i = COLS / (MAIN_VISIBLE / 2);
else
i = COLS / ((currslen / 2) + (currslen % 2));
/* If we're on the statusbar, don't do anything. */ /* Calculate the y-coordinate relative to the beginning of
if (j < 0) * the shortcut list in bottomwin, i.e. with the sizes of
* topwin, edit, and the first line of bottomwin subtracted
* out, and set j to it. */
j = *mouse_y - (2 - no_more_space()) - editwinrows - 1;
/* If we're on the statusbar, don't do anything. */
if (j < 0)
return FALSE;
/* Calculate the x-coordinate relative to the beginning of
* the shortcut list in bottomwin, and add it to j. j
* should now be the index in the shortcut list of the
* shortcut we clicked. */
j = (*mouse_x / i) * 2 + j;
/* Adjust j if we clicked in the last two shortcuts. */
if ((j >= currslen) && (*mouse_x % i < COLS % i))
j -= 2;
/* If we're beyond the last shortcut, don't do anything. */
if (j >= currslen)
return FALSE;
/* Go through the shortcut list to determine which shortcut
* was clicked. */
for (; j > 0; j--)
s = s->next;
/* And put back the equivalent key. Assume that each
* shortcut has, at the very least, an equivalent control
* key, an equivalent primary meta key sequence, or both. */
if (s->ctrlval != NANO_NO_KEY) {
unget_kbinput(s->ctrlval, FALSE, FALSE);
return TRUE;
} else if (s->metaval != NANO_NO_KEY) {
unget_kbinput(s->metaval, TRUE, FALSE);
return TRUE;
}
} else
return FALSE; return FALSE;
/* Calculate the x-coordinate relative to the beginning of the
* shortcut list in bottomwin, and add it to j. j should now be
* the index in the shortcut list of the shortcut we clicked. */
j = (*mouse_x / i) * 2 + j;
/* Adjust j if we clicked in the last two shortcuts. */
if ((j >= currslen) && (*mouse_x % i < COLS % i))
j -= 2;
/* If we're beyond the last shortcut, don't do anything. */
if (j >= currslen)
return FALSE;
/* Go through the shortcut list to determine which shortcut was
* clicked. */
for (; j > 0; j--)
s = s->next;
/* And put back the equivalent key. Assume that each shortcut
* has, at the very least, an equivalent control key, an
* equivalent primary meta key sequence, or both. */
if (s->ctrlval != NANO_NO_KEY) {
unget_kbinput(s->ctrlval, FALSE, FALSE);
return TRUE;
} else if (s->metaval != NANO_NO_KEY) {
unget_kbinput(s->metaval, TRUE, FALSE);
return TRUE;
}
} }
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;
} }
#endif /* !DISABLE_MOUSE */ #endif /* !DISABLE_MOUSE */