changeset 14194:e7a880a5d39c draft

(svn r18744) -Fix [FS#3487-ish]: Do not toggle the sticky- and shading-button twice per mouseclick when clicking fast.
author frosch <frosch@openttd.org>
date Wed, 06 Jan 2010 20:17:46 +0000
parents e86ba574d855
children 1ecd28a3b976
files src/window.cpp
diffstat 1 files changed, 73 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -282,81 +282,84 @@
 
 	int widget_index = nw->index; ///< Index of the widget
 
-	/* Clicked on a widget that is not disabled.
-	 * So unless the clicked widget is the caption bar, change focus to this widget */
-	if (widget_type != WWT_CAPTION) {
-		/* Close the OSK window if a edit box loses focus */
-		if (w->nested_focus != NULL &&  w->nested_focus->type == WWT_EDITBOX && w->nested_focus != nw && w->window_class != WC_OSK) {
-			DeleteWindowById(WC_OSK, 0);
+	/* Process special buttons (only single clicks) */
+	if (!double_click) {
+		/* Clicked on a widget that is not disabled.
+		 * So unless the clicked widget is the caption bar, change focus to this widget */
+		if (widget_type != WWT_CAPTION) {
+			/* Close the OSK window if a edit box loses focus */
+			if (w->nested_focus != NULL &&  w->nested_focus->type == WWT_EDITBOX && w->nested_focus != nw && w->window_class != WC_OSK) {
+				DeleteWindowById(WC_OSK, 0);
+			}
+
+			/* focused_widget_changed is 'now' only true if the window this widget
+			 * is in gained focus. In that case it must remain true, also if the
+			 * local widget focus did not change. As such it's the logical-or of
+			 * both changed states.
+			 *
+			 * If this is not preserved, then the OSK window would be opened when
+			 * a user has the edit box focused and then click on another window and
+			 * then back again on the edit box (to type some text).
+			 */
+			focused_widget_changed |= w->SetFocusedWidget(widget_index);
 		}
 
-		/* focused_widget_changed is 'now' only true if the window this widget
-		 * is in gained focus. In that case it must remain true, also if the
-		 * local widget focus did not change. As such it's the logical-or of
-		 * both changed states.
-		 *
-		 * If this is not preserved, then the OSK window would be opened when
-		 * a user has the edit box focused and then click on another window and
-		 * then back again on the edit box (to type some text).
-		 */
-		focused_widget_changed |= w->SetFocusedWidget(widget_index);
-	}
+		/* Close any child drop down menus. If the button pressed was the drop down
+		 * list's own button, then we should not process the click any further. */
+		if (HideDropDownMenu(w) == widget_index && widget_index >= 0) return;
+
+		switch (widget_type) {
+			/* special widget handling for buttons*/
+			case WWT_PANEL   | WWB_PUSHBUTTON: // WWT_PUSHBTN
+			case WWT_IMGBTN  | WWB_PUSHBUTTON: // WWT_PUSHIMGBTN
+			case WWT_TEXTBTN | WWB_PUSHBUTTON: // WWT_PUSHTXTBTN
+				w->HandleButtonClick(widget_index);
+				break;
 
-	/* Close any child drop down menus. If the button pressed was the drop down
-	 * list's own button, then we should not process the click any further. */
-	if (HideDropDownMenu(w) == widget_index && widget_index >= 0) return;
+			case WWT_SCROLLBAR:
+			case WWT_SCROLL2BAR:
+			case WWT_HSCROLLBAR:
+				ScrollbarClickHandler(w, nw, x, y);
+				break;
 
-	switch (widget_type) {
-		/* special widget handling for buttons*/
-		case WWT_PANEL   | WWB_PUSHBUTTON: // WWT_PUSHBTN
-		case WWT_IMGBTN  | WWB_PUSHBUTTON: // WWT_PUSHIMGBTN
-		case WWT_TEXTBTN | WWB_PUSHBUTTON: // WWT_PUSHTXTBTN
-			w->HandleButtonClick(widget_index);
-			break;
-
-		case WWT_SCROLLBAR:
-		case WWT_SCROLL2BAR:
-		case WWT_HSCROLLBAR:
-			ScrollbarClickHandler(w, nw, x, y);
-			break;
+			case WWT_EDITBOX:
+				if (!focused_widget_changed) { // Only open the OSK window if clicking on an already focused edit box
+					/* Open the OSK window if clicked on an edit box */
+					QueryStringBaseWindow *qs = dynamic_cast<QueryStringBaseWindow *>(w);
+					if (qs != NULL) {
+						qs->OnOpenOSKWindow(widget_index);
+					}
+				}
+				break;
 
-		case WWT_EDITBOX:
-			if (!focused_widget_changed) { // Only open the OSK window if clicking on an already focused edit box
-				/* Open the OSK window if clicked on an edit box */
-				QueryStringBaseWindow *qs = dynamic_cast<QueryStringBaseWindow *>(w);
-				if (qs != NULL) {
-					qs->OnOpenOSKWindow(widget_index);
-				}
-			}
-			break;
+			case WWT_CLOSEBOX: // 'X'
+				delete w;
+				return;
 
-		case WWT_CLOSEBOX: // 'X'
-			delete w;
-			return;
-
-		case WWT_CAPTION: // 'Title bar'
-			StartWindowDrag(w);
-			return;
+			case WWT_CAPTION: // 'Title bar'
+				StartWindowDrag(w);
+				return;
 
-		case WWT_RESIZEBOX:
-			/* When the resize widget is on the left size of the window
-			 * we assume that that button is used to resize to the left. */
-			StartWindowSizing(w, (int)nw->pos_x < (w->width / 2));
-			nw->SetDirty(w);
-			return;
+			case WWT_RESIZEBOX:
+				/* When the resize widget is on the left size of the window
+				 * we assume that that button is used to resize to the left. */
+				StartWindowSizing(w, (int)nw->pos_x < (w->width / 2));
+				nw->SetDirty(w);
+				return;
 
-		case WWT_SHADEBOX:
-			nw->SetDirty(w);
-			w->SetShaded(!w->IsShaded());
-			return;
+			case WWT_SHADEBOX:
+				nw->SetDirty(w);
+				w->SetShaded(!w->IsShaded());
+				return;
 
-		case WWT_STICKYBOX:
-			w->flags4 ^= WF_STICKY;
-			nw->SetDirty(w);
-			return;
+			case WWT_STICKYBOX:
+				w->flags4 ^= WF_STICKY;
+				nw->SetDirty(w);
+				return;
 
-		default:
-			break;
+			default:
+				break;
+		}
 	}
 
 	/* Widget has no index, so the window is not interested in it. */
@@ -2118,12 +2121,13 @@
 		}
 	} else {
 		switch (click) {
+			case MC_LEFT:
 			case MC_DOUBLE_LEFT:
-				DispatchLeftClickEvent(w, x - w->left, y - w->top, true);
-				if (_mouseover_last_w == NULL) break; // The window got removed.
-				/* fallthough, and also give a single-click for backwards compatibility */
-			case MC_LEFT:
 				DispatchLeftClickEvent(w, x - w->left, y - w->top, false);
+				if (click == MC_DOUBLE_LEFT && _mouseover_last_w != NULL) {
+					/* Issue the doubleclick, if the window was not removed */
+					DispatchLeftClickEvent(w, x - w->left, y - w->top, true);
+				}
 				break;
 
 			default: