more various mouse support-related simplifications

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4109 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2007-05-22 17:20:28 +00:00
parent 54fdb75bd8
commit bc65313104
5 changed files with 51 additions and 41 deletions

View File

@ -1,3 +1,13 @@
2007-05-22 David Lawrence Ramsey <pooka109@gmail.com>
* browser.c (do_browser), nano.c (do_mouse), prompt.c
(do_statusbar_mouse, do_yesno_prompt), winio.c (do_mouseinput):
Simplify processing of mouse events. Instead of calling
wenclose() to get the window a mouse event took place in and
manually adjusting the returned coordinates to be relative to
that window the mouse event took place in, call wmouse_trafo(),
which does both.
2007-05-20 David Lawrence Ramsey <pooka109@gmail.com> 2007-05-20 David Lawrence Ramsey <pooka109@gmail.com>
* browser.c (do_browser), nano.c (do_mouse), prompt.c * browser.c (do_browser), nano.c (do_mouse), prompt.c

View File

@ -134,10 +134,8 @@ char *do_browser(char *path, DIR *dir)
if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0) { if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0) {
/* We can click in the edit window to select a /* We can click in the edit window to select a
* filename. */ * filename. */
if (wenclose(edit, mouse_y, mouse_x)) { if (wmouse_trafo(edit, &mouse_y, &mouse_x,
/* Subtract out the size of topwin. */ FALSE)) {
mouse_y -= 2 - no_more_space();
/* longest is the width of each column. /* longest is the width of each column.
* There are two spaces between each * There are two spaces between each
* column. */ * column. */

View File

@ -1498,7 +1498,7 @@ int do_mouse(void)
if (retval == 0) { if (retval == 0) {
/* We can click in the edit window to move the cursor. */ /* We can click in the edit window to move the cursor. */
if (wenclose(edit, mouse_y, mouse_x)) { if (wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
bool sameline; bool sameline;
/* Did they click on the line with the cursor? If they /* Did they click on the line with the cursor? If they
* clicked on the cursor, we set the mark. */ * clicked on the cursor, we set the mark. */
@ -1506,9 +1506,6 @@ int do_mouse(void)
size_t current_x_save = openfile->current_x; size_t current_x_save = openfile->current_x;
size_t pww_save = openfile->placewewant; size_t pww_save = openfile->placewewant;
/* Subtract out the size of topwin. */
mouse_y -= 2 - no_more_space();
sameline = (mouse_y == openfile->current_y); sameline = (mouse_y == openfile->current_y);
/* Move to where the click occurred. */ /* Move to where the click occurred. */

View File

@ -281,16 +281,13 @@ int do_statusbar_mouse(void)
if (retval == 0) { if (retval == 0) {
/* We can click in the statusbar window text to move the /* We can click in the statusbar window text to move the
* cursor. */ * cursor. */
if (wenclose(bottomwin, mouse_y, mouse_x)) { if (wmouse_trafo(bottomwin, &mouse_y, &mouse_x, FALSE)) {
size_t start_col; size_t start_col;
assert(prompt != NULL); assert(prompt != NULL);
start_col = strlenpt(prompt) + 1; start_col = strlenpt(prompt) + 1;
/* Subtract out the sizes of topwin and edit. */
mouse_y -= (2 - no_more_space()) + editwinrows;
/* Move to where the click occurred. */ /* Move to where the click occurred. */
if (mouse_x > start_col && mouse_y == 0) { if (mouse_x > start_col && mouse_y == 0) {
size_t pww_save = statusbar_pww; size_t pww_save = statusbar_pww;
@ -1338,16 +1335,14 @@ int do_yesno_prompt(bool all, const char *msg)
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
case KEY_MOUSE: case KEY_MOUSE:
if (get_mouseinput(&mouse_x, &mouse_y, FALSE) == 0 && if (get_mouseinput(&mouse_x, &mouse_y, FALSE) == 0 &&
wenclose(bottomwin, mouse_y, mouse_x) && wmouse_trafo(bottomwin, &mouse_y, &mouse_x,
!ISSET(NO_HELP) && mouse_x < (width * 2) && FALSE) && !ISSET(NO_HELP) && mouse_x <
mouse_y - (2 - no_more_space()) - (width * 2) && mouse_y > 0) {
editwinrows - 1 >= 0) {
int x = mouse_x / width; int x = mouse_x / width;
/* Calculate the x-coordinate relative to the /* Calculate the x-coordinate relative to the
* two columns of the Yes/No/All shortcuts in * two columns of the Yes/No/All shortcuts in
* bottomwin. */ * bottomwin. */
int y = mouse_y - (2 - no_more_space()) - int y = mouse_y - 1;
editwinrows - 1;
/* Calculate the y-coordinate relative to the /* Calculate the y-coordinate relative to the
* beginning of the Yes/No/All shortcuts in * beginning of the Yes/No/All shortcuts in
* bottomwin, i.e. with the sizes of topwin, * bottomwin, i.e. with the sizes of topwin,

View File

@ -1658,16 +1658,30 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
* first mouse button was pressed inside it, we need to figure * first mouse button was pressed inside it, we need to figure
* out which shortcut was clicked and put back the equivalent * out which shortcut was clicked and put back the equivalent
* keystroke(s) for it. */ * keystroke(s) for it. */
if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin, if (allow_shortcuts && !ISSET(NO_HELP) &&
*mouse_y, *mouse_x)) { wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE)) {
int i, j; int i;
/* The width of all the shortcuts, except for the last
* two, in the shortcut list in bottomwin. */
int j;
/* The y-coordinate relative to the beginning of the
* shortcut list in bottomwin. */
size_t currslen; size_t currslen;
/* The number of shortcuts in the current shortcut /* The number of shortcuts in the current shortcut
* list. */ * list. */
const shortcut *s = currshortcut; const shortcut *s;
/* The actual shortcut we released on, starting at the /* The actual shortcut we released on, starting at the
* first one in the current shortcut list. */ * first one in the current shortcut list. */
/* Ignore releases of the first mouse button on the
* statusbar. */
if (*mouse_y == 0)
return 2;
/* Calculate the y-coordinate relative to the beginning of
* the shortcut list in bottomwin. */
j = *mouse_y - 1;
/* Get the shortcut lists' length. */ /* Get the shortcut lists' length. */
if (currshortcut == main_list) if (currshortcut == main_list)
currslen = MAIN_VISIBLE; currslen = MAIN_VISIBLE;
@ -1688,17 +1702,6 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
else else
i = COLS / ((currslen / 2) + (currslen % 2)); i = COLS / ((currslen / 2) + (currslen % 2));
/* Calculate the y-coordinate relative to the beginning of
* 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;
/* Ignore releases of the first mouse button on the
* statusbar. */
if (j < 0)
return 2;
/* Calculate the x-coordinate relative to the beginning of /* Calculate the x-coordinate relative to the beginning of
* the shortcut list in bottomwin, and add it to j. j * the shortcut list in bottomwin, and add it to j. j
* should now be the index in the shortcut list of the * should now be the index in the shortcut list of the
@ -1716,6 +1719,8 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
/* Go through the shortcut list to determine which shortcut /* Go through the shortcut list to determine which shortcut
* we released on. */ * we released on. */
s = currshortcut;
for (; j > 0; j--) for (; j > 0; j--)
s = s->next; s = s->next;
@ -1739,19 +1744,24 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
* mouse wheel) and presses of the fifth mouse button (downward * mouse wheel) and presses of the fifth mouse button (downward
* rolls of the mouse wheel) . */ * rolls of the mouse wheel) . */
else if (mevent.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) { else if (mevent.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) {
if (wenclose(edit, *mouse_y, *mouse_x) || wenclose(bottomwin, bool in_edit = wmouse_trafo(edit, mouse_y, mouse_x, FALSE);
*mouse_y, *mouse_x)) { bool in_bottomwin = wmouse_trafo(bottomwin, mouse_y, mouse_x,
/* Calculate the y-coordinate relative to the beginning of FALSE);
* the shortcut list in bottomwin, i.e. with the sizes of
* topwin, edit, and the first line of bottomwin subtracted if (in_edit || in_bottomwin) {
* out, and set i to it. */ int i;
int i = *mouse_y - (2 - no_more_space()) - editwinrows - 1; /* The y-coordinate relative to the beginning of the
* shortcut list in bottomwin. */
/* Ignore presses of the fourth mouse button and presses of /* Ignore presses of the fourth mouse button and presses of
* the fifth mouse button below the statusbar. */ * the fifth mouse button below the statusbar. */
if (i >= 0) if (in_bottomwin && *mouse_y > 0)
return 2; return 2;
/* Calculate the y-coordinate relative to the beginning of
* the shortcut list in bottomwin. */
i = *mouse_y - 1;
/* One upward roll of the mouse wheel is equivalent to /* One upward roll of the mouse wheel is equivalent to
* moving up three lines, and one downward roll of the mouse * moving up three lines, and one downward roll of the mouse
* wheel is equivalent to moving down three lines. */ * wheel is equivalent to moving down three lines. */