(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
authorrubidium
Thu, 15 May 2008 20:52:28 +0000
changeset 9244 bd42e32e71f3
parent 9243 8e5cea2fe464
child 9245 cd9305c986e4
(svn r13110) -Fix [FS#2018]: some toolbar buttons not being unpressed properly.
src/viewport.cpp
src/window_type.h
--- a/src/viewport.cpp	Thu May 15 20:51:52 2008 +0000
+++ b/src/viewport.cpp	Thu May 15 20:52:28 2008 +0000
@@ -2708,11 +2708,18 @@
 
 void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num)
 {
-	Window *w = NULL;
-
 	/* undo clicking on button and drag & drop */
 	if (_thd.place_mode != VHM_NONE || _special_mouse_mode == WSM_DRAGDROP) {
-		w = FindWindowById(_thd.window_class, _thd.window_number);
+		Window *w = FindWindowById(_thd.window_class, _thd.window_number);
+		if (w != NULL) {
+			/* Call the abort function, but set the window class to something
+			 * that will never be used to avoid infinite loops. Setting it to
+			 * the 'next' window class must not be done because recursion into
+			 * this function might in some cases reset the newly set object to
+			 * place or not properly reset the original selection. */
+			_thd.window_class = WC_INVALID;
+			w->OnPlaceObjectAbort();
+		}
 	}
 
 	SetTileSelectSize(1, 1);
@@ -2739,10 +2746,6 @@
 		SetMouseCursor(icon, pal);
 	}
 
-	/* Call the abort function only *after* the window class/number
-	 * are reset so one doesn't get into infinite loops when someone
-	 * resets the object to place during the abort callback. */
-	if (w != NULL) w->OnPlaceObjectAbort();
 }
 
 void ResetObjectToPlace()
--- a/src/window_type.h	Thu May 15 20:51:52 2008 +0000
+++ b/src/window_type.h	Thu May 15 20:52:28 2008 +0000
@@ -94,6 +94,8 @@
 	WC_BUILD_SIGNAL,
 	WC_COMPANY_PASSWORD_WINDOW,
 	WC_OSK,
+
+	WC_INVALID = 0xFFFF
 };
 
 struct Window;