diff --git a/ChangeLog b/ChangeLog
index 516a8dd7cc305279f9cbec07e854708f02d1c814..2a0874c8aa7d0d807a384ec2748c4171a46cd559 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-05-20  David Lawrence Ramsey  <pooka109@gmail.com>
+
+	* nano.c (do_mouse), prompt.c (do_statusbar_mouse,
+	do_yesno_prompt), winio.c (do_mouseinput): Fix processing of
+	mouse events so that those we don't handle are ignored instead
+	of being erroneously passed through.
+	* winio.c (do_mouseinput): Simplify handling of mouse events
+	involving the first mouse button.
+	* winio.c (do_mouseinput): Improve mouse wheel support to only
+	move the cursor if we're in the edit window or on the statusbar.
+
 2007-05-15  David Lawrence Ramsey  <pooka109@gmail.com>
 
 	* winio.c (do_mouseinput): Add mouse wheel support, per Helmut
diff --git a/src/browser.c b/src/browser.c
index 44d94825495e4580698522bd0cc91bb124b4e165..b62debef041d5944261a60b7adb77f38442ecd95 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -131,7 +131,7 @@ char *do_browser(char *path, DIR *dir)
 		{
 		    int mouse_x, mouse_y;
 
-		    if (!get_mouseinput(&mouse_x, &mouse_y, TRUE)) {
+		    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)) {
diff --git a/src/nano.c b/src/nano.c
index 8a1d8af8d21fd238469896f102fdf38fa39f753a..68c8299ea8f9a0e111378f049c5d9118ceaea4ec 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1333,7 +1333,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
 	/* If we got a mouse click and it was on a shortcut, read in the
 	 * shortcut character. */
 	if (*func_key && input == KEY_MOUSE) {
-	    if (do_mouse())
+	    if (do_mouse() == 1)
 		input = get_kbinput(edit, meta_key, func_key);
 	    else {
 		*meta_key = FALSE;
@@ -1491,12 +1491,12 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
 
 #ifndef DISABLE_MOUSE
 /* Handle a mouse click on the edit window or the shortcut list. */
-bool do_mouse(void)
+int do_mouse(void)
 {
     int mouse_x, mouse_y;
-    bool retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
+    int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
 
-    if (!retval) {
+    if (retval == 0) {
 	/* We can click in the edit window to move the cursor. */
 	if (wenclose(edit, mouse_y, mouse_x)) {
 	    bool sameline;
diff --git a/src/prompt.c b/src/prompt.c
index af1c7dd7f12230099d41df0b53af74f8c3ce967f..8bb080630e3830638ee8a07778c6009ab6ef9fef 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -76,7 +76,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
 	/* If we got a mouse click and it was on a shortcut, read in the
 	 * shortcut character. */
 	if (*func_key && input == KEY_MOUSE) {
-	    if (do_statusbar_mouse())
+	    if (do_statusbar_mouse() == 1)
 		input = get_kbinput(bottomwin, meta_key, func_key);
 	    else {
 		*meta_key = FALSE;
@@ -273,12 +273,12 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
 
 #ifndef DISABLE_MOUSE
 /* Handle a mouse click on the statusbar prompt or the shortcut list. */
-bool do_statusbar_mouse(void)
+int do_statusbar_mouse(void)
 {
     int mouse_x, mouse_y;
-    bool retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
+    int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
 
-    if (!retval) {
+    if (retval == 0) {
 	/* We can click in the statusbar window text to move the
 	 * cursor. */
 	if (wenclose(bottomwin, mouse_y, mouse_x)) {
@@ -1337,9 +1337,8 @@ int do_yesno_prompt(bool all, const char *msg)
 		break;
 #ifndef DISABLE_MOUSE
 	    case KEY_MOUSE:
-		get_mouseinput(&mouse_x, &mouse_y, FALSE);
-
-		if (wenclose(bottomwin, mouse_y, mouse_x) &&
+		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) {
diff --git a/src/proto.h b/src/proto.h
index 0250b5a006ef3f47f0976b40157c695faf3be5ee..2bd0bfde59857c9d735261625909e18313a41cb4 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -485,7 +485,7 @@ void terminal_init(void);
 int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
 	*ran_func, bool *finished, bool allow_funcs);
 #ifndef DISABLE_MOUSE
-bool do_mouse(void);
+int do_mouse(void);
 #endif
 void do_output(char *output, size_t output_len, bool allow_cntrls);
 
@@ -494,7 +494,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
 	bool *ran_func, bool *finished, bool allow_funcs, void
 	(*refresh_func)(void));
 #ifndef DISABLE_MOUSE
-bool do_statusbar_mouse(void);
+int do_statusbar_mouse(void);
 #endif
 void do_statusbar_output(char *output, size_t output_len, bool
 	*got_enter, bool allow_cntrls);
@@ -749,7 +749,7 @@ void unparse_kbinput(char *output, size_t output_len);
 int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len);
 int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len);
 #ifndef DISABLE_MOUSE
-bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
+int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
 #endif
 const shortcut *get_shortcut(const shortcut *s_list, int *kbinput, bool
 	*meta_key, bool *func_key);
diff --git a/src/winio.c b/src/winio.c
index 95a4c9049e686fa75f6dde2f3250a015e16ad6ef..69c747aec48f594a101e94c7d8554b02ed17009a 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1625,17 +1625,18 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len)
 
 #ifndef DISABLE_MOUSE
 /* Handle any mouse events that may have occurred.  We currently handle
- * releases or clicks of the first mouse button.  If allow_shortcuts is
- * TRUE, releasing or clicking on a visible shortcut will put back the
- * keystroke associated with that shortcut.  If NCURSES_MOUSE_VERSION is
- * at least 2, we also currently handle presses of the fourth mouse
- * button (upward rolls of the mouse wheel) by putting back the
- * keystrokes to move up, and presses of the fifth mouse button
- * (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)
+ * releases of the first mouse button.  If allow_shortcuts is TRUE,
+ * releasing on a visible shortcut will put back the keystroke
+ * associated with that shortcut.  If NCURSES_MOUSE_VERSION is at least
+ * 2, we also currently handle presses of the fourth mouse button
+ * (upward rolls of the mouse wheel) by putting back the keystrokes to
+ * move up, and presses of the fifth mouse button (downward rolls of the
+ * mouse wheel) by putting back the keystrokes to move down.  Return -1
+ * on error, 0 if the mouse event needs to be handled, 1 if it's been
+ * handled by putting back keystrokes that need to be handled. or 2 if
+ * the mouse event is ignored.  Assume that KEY_MOUSE has already been
+ * read in. */
+int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
 {
     MEVENT mevent;
 
@@ -1644,20 +1645,19 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
 
     /* First, get the actual mouse event. */
     if (getmouse(&mevent) == ERR)
-	return FALSE;
+	return -1;
 
-    /* Handle releases or clicks of the first mouse button. */
-    if (mevent.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) {
-	/* Save the screen coordinates where the mouse event took
-	 * place. */
-	*mouse_x = mevent.x;
-	*mouse_y = mevent.y;
+    /* Save the screen coordinates where the mouse event took place. */
+    *mouse_x = mevent.x;
+    *mouse_y = mevent.y;
 
+    /* Handle releases of the first mouse button. */
+    if (mevent.bstate & BUTTON1_RELEASED) {
 	/* If we're allowing shortcuts, the current shortcut list is
 	 * being displayed on the last two lines of the screen, and the
-	 * mouse event took place inside it, we need to figure out which
-	 * shortcut was clicked and put back the equivalent keystroke(s)
-	 * for it. */
+	 * 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;
@@ -1665,7 +1665,7 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
 		/* The number of shortcuts in the current shortcut
 		 * list. */
 	    const shortcut *s = currshortcut;
-		/* The actual shortcut we clicked on, starting at the
+		/* The actual shortcut we released on, starting at the
 		 * first one in the current shortcut list. */
 
 	    /* Get the shortcut lists' length. */
@@ -1694,26 +1694,28 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
 	     * 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. */
+	    /* Ignore releases of the first mouse button on the
+	     * statusbar. */
 	    if (j < 0)
-		return FALSE;
+		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
-	     * shortcut we clicked. */
+	     * shortcut we released on. */
 	    j = (*mouse_x / i) * 2 + j;
 
-	    /* Adjust j if we clicked in the last two shortcuts. */
+	    /* Adjust j if we released on 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. */
+	    /* Ignore releases of the first mouse button beyond the last
+	     * shortcut. */
 	    if (j >= currslen)
-		return FALSE;
+		return 2;
 
 	    /* Go through the shortcut list to determine which shortcut
-	     * was clicked. */
+	     * we released on. */
 	    for (; j > 0; j--)
 		s = s->next;
 
@@ -1722,41 +1724,53 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
 	     * key, an equivalent primary meta key sequence, or both. */
 	    if (s->ctrlval != NANO_NO_KEY) {
 		unget_kbinput(s->ctrlval, FALSE, FALSE);
-		return TRUE;
+		return 1;
 	    } else if (s->metaval != NANO_NO_KEY) {
 		unget_kbinput(s->metaval, TRUE, FALSE);
-		return TRUE;
+		return 1;
 	    }
 	} else
-	    return FALSE;
+	    /* Handle releases of the first mouse button that aren't on
+	     * the current shortcut list elsewhere. */
+	    return 0;
     }
 #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;
+     * 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;
+
+	    /* Ignore presses of the fourth mouse button and presses of
+	     * the fifth mouse button below the statusbar. */
+	    if (i >= 0)
+		return 2;
+
+	    /* 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. */
+	    for (i = 0; i < 3; i++)
+		unget_kbinput((mevent.bstate & BUTTON4_PRESSED) ?
+			NANO_PREVLINE_KEY : NANO_NEXTLINE_KEY, FALSE,
+			FALSE);
+
+	    return 1;
+	} else
+	    /* Ignore presses of the fourth mouse button and presses of
+	     * the fifth mouse buttons that aren't on the edit window or
+	     * the statusbar. */
+	    return 2;
     }
 #endif
     else
-	return FALSE;
+	/* Ignore all other mouse events. */
+	return 2;
 }
 #endif /* !DISABLE_MOUSE */