+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>
* browser.c (do_browser), nano.c (do_mouse), prompt.c
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. */
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. */
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;
#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,
* 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;
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
/* Go through the shortcut list to determine which shortcut
* we released on. */
+ s = currshortcut;
+
for (; j > 0; j--)
s = s->next;
* 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. */