further simplify processing of mouse events by consolidating if clauses

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4113 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2007-06-28 16:00:50 +00:00
parent 3a504709b7
commit ebc38fd106
4 changed files with 68 additions and 70 deletions

View File

@ -1,3 +1,9 @@
2007-06-28 David Lawrence Ramsey <pooka109@gmail.com>
* browser.c (do_browser), nano.c (do_mouse), prompt.c
(do_statusbar_mouse, do_yesno_prompt): Further simplify
processing of mouse events by consolidating if clauses.
2007-05-29 David Lawrence Ramsey <pooka109@gmail.com> 2007-05-29 David Lawrence Ramsey <pooka109@gmail.com>
* winio.c (do_mouseinput): Deal with clicks of the first mouse * winio.c (do_mouseinput): Deal with clicks of the first mouse

View File

@ -131,14 +131,12 @@ char *do_browser(char *path, DIR *dir)
{ {
int mouse_x, mouse_y; int mouse_x, mouse_y;
if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0) { /* We can click on the edit window to select a
/* We can click in the edit window to select a
* filename. */ * filename. */
if (wmouse_trafo(edit, &mouse_y, &mouse_x, if (get_mouseinput(&mouse_x, &mouse_y, TRUE) == 0 &&
FALSE)) { wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
/* longest is the width of each column. /* longest is the width of each column. There
* There are two spaces between each * are two spaces between each column. */
* column. */
selected = (fileline / editwinrows) * selected = (fileline / editwinrows) *
(editwinrows * width) + (mouse_y * (editwinrows * width) + (mouse_y *
width) + (mouse_x / (longest + 2)); width) + (mouse_x / (longest + 2));
@ -158,9 +156,7 @@ char *do_browser(char *path, DIR *dir)
* time, put back the Enter key so that it's * time, put back the Enter key so that it's
* read in. */ * read in. */
if (old_selected == selected) if (old_selected == selected)
unget_kbinput(NANO_ENTER_KEY, FALSE, unget_kbinput(NANO_ENTER_KEY, FALSE, FALSE);
FALSE);
}
} }
} }
break; break;

View File

@ -1497,9 +1497,8 @@ int do_mouse(void)
int mouse_x, mouse_y; int mouse_x, mouse_y;
int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE); int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
if (retval == 0) { /* We can click on the edit window to move the cursor. */
/* We can click in the edit window to move the cursor. */ if (retval == 0 && wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
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. */
@ -1510,13 +1509,11 @@ int do_mouse(void)
sameline = (mouse_y == openfile->current_y); sameline = (mouse_y == openfile->current_y);
/* Move to where the click occurred. */ /* Move to where the click occurred. */
for (; openfile->current_y < mouse_y && for (; openfile->current_y < mouse_y && openfile->current !=
openfile->current != openfile->filebot; openfile->filebot; openfile->current_y++)
openfile->current_y++)
openfile->current = openfile->current->next; openfile->current = openfile->current->next;
for (; openfile->current_y > mouse_y && for (; openfile->current_y > mouse_y && openfile->current !=
openfile->current != openfile->fileage; openfile->fileage; openfile->current_y--)
openfile->current_y--)
openfile->current = openfile->current->prev; openfile->current = openfile->current->prev;
openfile->current_x = actual_x(openfile->current->data, openfile->current_x = actual_x(openfile->current->data,
@ -1525,15 +1522,14 @@ int do_mouse(void)
#ifndef NANO_TINY #ifndef NANO_TINY
/* Clicking where the cursor is toggles the mark, as does /* Clicking where the cursor is toggles the mark, as does
* clicking beyond the line length with the cursor at the * clicking beyond the line length with the cursor at the end of
* end of the line. */ * the line. */
if (sameline && openfile->current_x == current_x_save) if (sameline && openfile->current_x == current_x_save)
do_mark(); do_mark();
#endif #endif
edit_redraw(current_save, pww_save); edit_redraw(current_save, pww_save);
} }
}
return retval; return retval;
} }

View File

@ -278,10 +278,9 @@ int do_statusbar_mouse(void)
int mouse_x, mouse_y; int mouse_x, mouse_y;
int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE); int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
if (retval == 0) { /* We can click on the statusbar window text to move the cursor. */
/* We can click in the statusbar window text to move the if (retval == 0 && wmouse_trafo(bottomwin, &mouse_y, &mouse_x,
* cursor. */ FALSE)) {
if (wmouse_trafo(bottomwin, &mouse_y, &mouse_x, FALSE)) {
size_t start_col; size_t start_col;
assert(prompt != NULL); assert(prompt != NULL);
@ -294,15 +293,14 @@ int do_statusbar_mouse(void)
statusbar_x = actual_x(answer, statusbar_x = actual_x(answer,
get_statusbar_page_start(start_col, start_col + get_statusbar_page_start(start_col, start_col +
statusbar_xplustabs()) + mouse_x - start_col - statusbar_xplustabs()) + mouse_x -
1); start_col - 1);
statusbar_pww = statusbar_xplustabs(); statusbar_pww = statusbar_xplustabs();
if (need_statusbar_horizontal_update(pww_save)) if (need_statusbar_horizontal_update(pww_save))
update_statusbar_line(answer, statusbar_x); update_statusbar_line(answer, statusbar_x);
} }
} }
}
return retval; return retval;
} }
@ -1334,6 +1332,8 @@ int do_yesno_prompt(bool all, const char *msg)
break; break;
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
case KEY_MOUSE: case KEY_MOUSE:
/* We can click on the shortcut list to select an
* answer. */
if (get_mouseinput(&mouse_x, &mouse_y, FALSE) == 0 && if (get_mouseinput(&mouse_x, &mouse_y, FALSE) == 0 &&
wmouse_trafo(bottomwin, &mouse_y, &mouse_x, wmouse_trafo(bottomwin, &mouse_y, &mouse_x,
FALSE) && !ISSET(NO_HELP) && mouse_x < FALSE) && !ISSET(NO_HELP) && mouse_x <