(svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
--- a/src/airport_gui.cpp Thu May 15 14:12:22 2008 +0000
+++ b/src/airport_gui.cpp Thu May 15 14:41:56 2008 +0000
@@ -102,9 +102,7 @@
case WE_ABORT_PLACE_OBJ:
w->RaiseButtons();
- w = FindWindowById(WC_BUILD_STATION, 0);
- if (w != 0)
- WP(w, def_d).close = true;
+ delete FindWindowById(WC_BUILD_STATION, 0);
break;
case WE_DESTROY:
@@ -171,8 +169,6 @@
uint32 avail_airports;
const AirportFTAClass *airport;
- if (WP(w, def_d).close) return;
-
avail_airports = GetValidAirports();
w->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
@@ -230,17 +226,12 @@
}
} break;
- case WE_TICK: {
- if (WP(w, def_d).close) {
- delete w;
- return;
- }
-
+ case WE_TICK:
CheckRedrawStationCoverage(w);
- } break;
+ break;
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
}
}
--- a/src/dock_gui.cpp Thu May 15 14:12:22 2008 +0000
+++ b/src/dock_gui.cpp Thu May 15 14:41:56 2008 +0000
@@ -175,11 +175,8 @@
case WE_ABORT_PLACE_OBJ:
w->RaiseButtons();
- w = FindWindowById(WC_BUILD_STATION, 0);
- if (w != NULL) WP(w, def_d).close = true;
-
- w = FindWindowById(WC_BUILD_DEPOT, 0);
- if (w != NULL) WP(w, def_d).close = true;
+ delete FindWindowById(WC_BUILD_STATION, 0);
+ delete FindWindowById(WC_BUILD_DEPOT, 0);
break;
case WE_PLACE_PRESIZE: {
@@ -241,7 +238,6 @@
case WE_PAINT: {
int rad = (_patches.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
- if (WP(w, def_d).close) return;
DrawWindowWidgets(w);
if (_station_show_coverage) {
@@ -275,16 +271,11 @@
break;
case WE_TICK:
- if (WP(w, def_d).close) {
- delete w;
- return;
- }
-
CheckRedrawStationCoverage(w);
break;
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
}
}
@@ -349,12 +340,8 @@
}
} break;
- case WE_TICK:
- if (WP(w, def_d).close) delete w;
- break;
-
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
}
}
--- a/src/rail_gui.cpp Thu May 15 14:12:22 2008 +0000
+++ b/src/rail_gui.cpp Thu May 15 14:41:56 2008 +0000
@@ -653,12 +653,9 @@
w->DisableWidget(RTW_REMOVE);
w->InvalidateWidget(RTW_REMOVE);
- w = FindWindowById(WC_BUILD_SIGNAL, 0);
- if (w != NULL) WP(w, def_d).close = true;
- w = FindWindowById(WC_BUILD_STATION, 0);
- if (w != NULL) WP(w, def_d).close = true;
- w = FindWindowById(WC_BUILD_DEPOT, 0);
- if (w != NULL) WP(w, def_d).close = true;
+ delete FindWindowById(WC_BUILD_SIGNAL, 0);
+ delete FindWindowById(WC_BUILD_STATION, 0);
+ delete FindWindowById(WC_BUILD_DEPOT, 0);
break;
case WE_PLACE_PRESIZE: {
@@ -875,8 +872,6 @@
DrawPixelInfo tmp_dpi, *old_dpi;
const StationSpec *statspec = newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
- if (WP(w, def_d).close) return;
-
if (_railstation.dragdrop) {
SetTileSelectSize(1, 1);
} else {
@@ -1123,15 +1118,11 @@
break;
case WE_TICK:
- if (WP(w, def_d).close) {
- delete w;
- return;
- }
CheckRedrawStationCoverage(w);
break;
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
}
}
@@ -1345,12 +1336,8 @@
w->SetDirty();
break;
- case WE_TICK:
- if (WP(w, def_d).close) delete w;
- return;
-
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
}
}
@@ -1436,12 +1423,8 @@
}
break;
- case WE_TICK:
- if (WP(w, def_d).close) delete w;
- return;
-
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
}
}
@@ -1535,12 +1518,8 @@
break;
}
- case WE_TICK:
- if (WP(w, def_d).close) delete w;
- break;
-
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
}
}
--- a/src/road_gui.cpp Thu May 15 14:12:22 2008 +0000
+++ b/src/road_gui.cpp Thu May 15 14:41:56 2008 +0000
@@ -511,12 +511,9 @@
w->InvalidateWidget(RTW_REMOVE);
w->InvalidateWidget(RTW_ONE_WAY);
- w = FindWindowById(WC_BUS_STATION, 0);
- if (w != NULL) WP(w, def_d).close = true;
- w = FindWindowById(WC_TRUCK_STATION, 0);
- if (w != NULL) WP(w, def_d).close = true;
- w = FindWindowById(WC_BUILD_DEPOT, 0);
- if (w != NULL) WP(w, def_d).close = true;
+ delete FindWindowById(WC_BUS_STATION, 0);
+ delete FindWindowById(WC_TRUCK_STATION, 0);
+ delete FindWindowById(WC_BUILD_DEPOT, 0);
break;
case WE_PLACE_DRAG:
@@ -762,12 +759,8 @@
}
break;
- case WE_TICK:
- if (WP(w, def_d).close) delete w;
- break;
-
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
default:
@@ -856,8 +849,6 @@
break;
case WE_PAINT: {
- if (WP(w, def_d).close) return;
-
DrawWindowWidgets(w);
if (_station_show_coverage) {
@@ -920,16 +911,11 @@
break;
case WE_TICK:
- if (WP(w, def_d).close) {
- delete w;
- return;
- }
-
CheckRedrawStationCoverage(w);
break;
case WE_DESTROY:
- if (!WP(w, def_d).close) ResetObjectToPlace();
+ ResetObjectToPlace();
break;
default:
--- a/src/viewport.cpp Thu May 15 14:12:22 2008 +0000
+++ b/src/viewport.cpp Thu May 15 14:41:56 2008 +0000
@@ -2708,12 +2708,11 @@
void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num)
{
- Window *w;
+ 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);
- if (w != NULL) w->OnPlaceObjectAbort();
}
SetTileSelectSize(1, 1);
@@ -2734,10 +2733,16 @@
if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode
VpStartPreSizing();
- if ( (int)icon < 0)
+ if ((int)icon < 0) {
SetAnimatedMouseCursor(_animcursors[~icon]);
- else
+ } else {
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_gui.h Thu May 15 14:12:22 2008 +0000
+++ b/src/window_gui.h Thu May 15 14:41:56 2008 +0000
@@ -527,7 +527,6 @@
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d));
struct def_d {
- bool close;
int16 data_1, data_2, data_3;
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d));