From: David Lawrence Ramsey Date: Tue, 22 May 2007 17:20:28 +0000 (+0000) Subject: more various mouse support-related simplifications X-Git-Tag: v2.1.0~113 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=bc6531310423bee8baf8e8a0a98a78f3062f0883;p=nano.git more various mouse support-related simplifications git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4109 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index cc5f95b9..cbc39225 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-05-22 David Lawrence Ramsey + + * 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 * browser.c (do_browser), nano.c (do_mouse), prompt.c diff --git a/src/browser.c b/src/browser.c index b62debef..0f10bb8c 100644 --- a/src/browser.c +++ b/src/browser.c @@ -134,10 +134,8 @@ char *do_browser(char *path, DIR *dir) if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0) { /* We can click in the edit window to select a * filename. */ - if (wenclose(edit, mouse_y, mouse_x)) { - /* Subtract out the size of topwin. */ - mouse_y -= 2 - no_more_space(); - + if (wmouse_trafo(edit, &mouse_y, &mouse_x, + FALSE)) { /* longest is the width of each column. * There are two spaces between each * column. */ diff --git a/src/nano.c b/src/nano.c index 68c8299e..fe0dcbfd 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1498,7 +1498,7 @@ int do_mouse(void) if (retval == 0) { /* 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; /* Did they click on the line with the cursor? If they * 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 pww_save = openfile->placewewant; - /* Subtract out the size of topwin. */ - mouse_y -= 2 - no_more_space(); - sameline = (mouse_y == openfile->current_y); /* Move to where the click occurred. */ diff --git a/src/prompt.c b/src/prompt.c index 8bb08063..85c78bf7 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -281,16 +281,13 @@ int do_statusbar_mouse(void) if (retval == 0) { /* We can click in the statusbar window text to move the * cursor. */ - if (wenclose(bottomwin, mouse_y, mouse_x)) { + if (wmouse_trafo(bottomwin, &mouse_y, &mouse_x, FALSE)) { size_t start_col; assert(prompt != NULL); 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. */ if (mouse_x > start_col && mouse_y == 0) { size_t pww_save = statusbar_pww; @@ -1338,16 +1335,14 @@ int do_yesno_prompt(bool all, const char *msg) #ifndef DISABLE_MOUSE case KEY_MOUSE: if (get_mouseinput(&mouse_x, &mouse_y, FALSE) == 0 && - wenclose(bottomwin, mouse_y, mouse_x) && - !ISSET(NO_HELP) && mouse_x < (width * 2) && - mouse_y - (2 - no_more_space()) - - editwinrows - 1 >= 0) { + wmouse_trafo(bottomwin, &mouse_y, &mouse_x, + FALSE) && !ISSET(NO_HELP) && mouse_x < + (width * 2) && mouse_y > 0) { int x = mouse_x / width; /* Calculate the x-coordinate relative to the * two columns of the Yes/No/All shortcuts in * bottomwin. */ - int y = mouse_y - (2 - no_more_space()) - - editwinrows - 1; + int y = mouse_y - 1; /* Calculate the y-coordinate relative to the * beginning of the Yes/No/All shortcuts in * bottomwin, i.e. with the sizes of topwin, diff --git a/src/winio.c b/src/winio.c index 69c747ae..ba8eccbe 100644 --- a/src/winio.c +++ b/src/winio.c @@ -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 * 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; + if (allow_shortcuts && !ISSET(NO_HELP) && + wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE)) { + 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; /* The number of shortcuts in the current shortcut * list. */ - const shortcut *s = currshortcut; + const shortcut *s; /* The actual shortcut we released on, starting at the * 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. */ if (currshortcut == main_list) currslen = MAIN_VISIBLE; @@ -1688,17 +1702,6 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts) else 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 * the shortcut list in bottomwin, and add it to j. j * 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 * we released on. */ + s = currshortcut; + for (; j > 0; j--) 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 * rolls of the mouse wheel) . */ else if (mevent.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) { - if (wenclose(edit, *mouse_y, *mouse_x) || wenclose(bottomwin, - *mouse_y, *mouse_x)) { - /* 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 i to it. */ - int i = *mouse_y - (2 - no_more_space()) - editwinrows - 1; + bool in_edit = wmouse_trafo(edit, mouse_y, mouse_x, FALSE); + bool in_bottomwin = wmouse_trafo(bottomwin, mouse_y, mouse_x, + FALSE); + + if (in_edit || in_bottomwin) { + int i; + /* The y-coordinate relative to the beginning of the + * shortcut list in bottomwin. */ /* Ignore presses of the fourth mouse button and presses of * the fifth mouse button below the statusbar. */ - if (i >= 0) + if (in_bottomwin && *mouse_y > 0) 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 * moving up three lines, and one downward roll of the mouse * wheel is equivalent to moving down three lines. */