diff options
author | rubidium <rubidium@openttd.org> | 2008-05-15 14:41:56 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-05-15 14:41:56 +0000 |
commit | 6d880ada7f8e9e43961f71db503f18da3cd5d6a3 (patch) | |
tree | 43c72cfecc28dfa3d1fafc35fe5d61d59367a67c | |
parent | 31ab1e815a8f2af78bc1f17fa2e69b05e5806cd7 (diff) | |
download | openttd-6d880ada7f8e9e43961f71db503f18da3cd5d6a3.tar.xz |
(svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
-rw-r--r-- | src/airport_gui.cpp | 17 | ||||
-rw-r--r-- | src/dock_gui.cpp | 21 | ||||
-rw-r--r-- | src/rail_gui.cpp | 35 | ||||
-rw-r--r-- | src/road_gui.cpp | 24 | ||||
-rw-r--r-- | src/viewport.cpp | 13 | ||||
-rw-r--r-- | src/window_gui.h | 1 |
6 files changed, 29 insertions, 82 deletions
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index b19469ce2..74f5e50d6 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -102,9 +102,7 @@ static void BuildAirToolbWndProc(Window *w, WindowEvent *e) 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 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) 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 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) } } 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; } } diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index e6369fdcf..c4bf10b42 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -175,11 +175,8 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e) 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 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e) 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 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e) 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 @@ static void BuildDocksDepotWndProc(Window *w, WindowEvent *e) } } 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; } } diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 12ddba97b..c56f014c4 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -653,12 +653,9 @@ static void BuildRailToolbWndProc(Window *w, WindowEvent *e) 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 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) 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 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) 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 @@ static void SignalBuildWndProc(Window *w, WindowEvent *e) 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 @@ static void BuildTrainDepotWndProc(Window *w, WindowEvent *e) } 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 @@ static void BuildWaypointWndProc(Window *w, WindowEvent *e) 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; } } diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 216d6bc01..7016d4b43 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -511,12 +511,9 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) 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 @@ static void BuildRoadDepotWndProc(Window *w, WindowEvent *e) } 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 @@ static void RoadStationPickerWndProc(Window *w, WindowEvent *e) break; case WE_PAINT: { - if (WP(w, def_d).close) return; - DrawWindowWidgets(w); if (_station_show_coverage) { @@ -920,16 +911,11 @@ static void RoadStationPickerWndProc(Window *w, WindowEvent *e) 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: diff --git a/src/viewport.cpp b/src/viewport.cpp index 1eb5ec63d..10369e1ec 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2708,12 +2708,11 @@ void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, ViewportHighlightMode mode 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 @@ void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, W 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() diff --git a/src/window_gui.h b/src/window_gui.h index cc72d2613..84a1c22d3 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -527,7 +527,6 @@ struct menu_d { 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)); |