(svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
authorDarkvater
Sat, 18 Nov 2006 17:04:44 +0000
changeset 5125 60b21cf18b50
parent 5124 d30772d0e9e1
child 5126 d87bd8d5e159
(svn r7206) -Codechange: Remove (some of) the magic needed for windows that could be invalid after
a call to DeleteWindow() somewhere else. Also do some cleanup with AllowWindowDescFront()
depot_gui.c
engine_gui.c
misc_gui.c
network_gui.c
roadveh_gui.c
ship_gui.c
vehicle_gui.c
widget.c
--- a/depot_gui.c	Sat Nov 18 16:47:02 2006 +0000
+++ b/depot_gui.c	Sat Nov 18 17:04:44 2006 +0000
@@ -189,11 +189,8 @@
 		case WE_CLICK:
 			switch (e->we.click.widget) {
 				case 4:
-					/* Weird issue here. If We execute the DoCommandP first, then the window is not closed */
-					DeleteWindow(w);
 					DoCommandP(tile, vehicle_type, 0, NULL, CMD_DEPOT_SELL_ALL_VEHICLES);
-					break;
-
+					/* Fallthrough */
 				case 3:
 					DeleteWindow(w);
 					break;
--- a/engine_gui.c	Sat Nov 18 16:47:02 2006 +0000
+++ b/engine_gui.c	Sat Nov 18 17:04:44 2006 +0000
@@ -93,12 +93,10 @@
 
 	case WE_CLICK:
 		switch (e->we.click.widget) {
-			case 3:
-				DeleteWindow(w);
-				break;
-
 			case 4:
 				DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
+				/* Fallthrough */
+			case 3:
 				DeleteWindow(w);
 				break;
 		}
@@ -117,10 +115,7 @@
 
 void ShowEnginePreviewWindow(EngineID engine)
 {
-	Window *w;
-
-	w = AllocateWindowDesc(&_engine_preview_desc);
-	w->window_number = engine;
+	Window *w = AllocateWindowDescFront(&_engine_preview_desc, engine);
 }
 
 static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
--- a/misc_gui.c	Sat Nov 18 16:47:02 2006 +0000
+++ b/misc_gui.c	Sat Nov 18 17:04:44 2006 +0000
@@ -1856,8 +1856,6 @@
 
 	DeleteWindowById(WC_CHEATS, 0);
 	w = AllocateWindowDesc(&_cheats_desc);
-
-	if (w != NULL) SetWindowDirty(w);
 }
 
 /** Resize the widgets in a window
--- a/network_gui.c	Sat Nov 18 16:47:02 2006 +0000
+++ b/network_gui.c	Sat Nov 18 17:04:44 2006 +0000
@@ -1258,11 +1258,6 @@
 		if (index >= 0 && e->we.popupmenu.pt.y >= w->top)
 			HandleClientListPopupClick(index, WP(w,menu_d).main_button);
 
-		// Sometimes, because of the bad DeleteWindow-proc, the 'w' pointer is
-		//  invalid after the last functions (mostly because it kills a window
-		//  that is in front of 'w', and because of a silly memmove, the address
-		//  'w' was pointing to becomes invalid), so we need to refetch
-		//  the right address...
 		DeleteWindowById(WC_TOOLBAR_MENU, 0);
 	}	break;
 
--- a/roadveh_gui.c	Sat Nov 18 16:47:02 2006 +0000
+++ b/roadveh_gui.c	Sat Nov 18 17:04:44 2006 +0000
@@ -534,8 +534,7 @@
 
 	DeleteWindowById(WC_BUILD_VEHICLE, tile);
 
-	w = AllocateWindowDesc(&_new_road_veh_desc);
-	w->window_number = tile;
+	w = AllocateWindowDescFront(&_new_road_veh_desc, tile);
 	w->vscroll.cap = 8;
 	w->widget[2].data = (w->vscroll.cap << 8) + 1;
 
--- a/ship_gui.c	Sat Nov 18 16:47:02 2006 +0000
+++ b/ship_gui.c	Sat Nov 18 17:04:44 2006 +0000
@@ -357,8 +357,7 @@
 
 	DeleteWindowById(WC_BUILD_VEHICLE, tile);
 
-	w = AllocateWindowDesc(&_new_ship_desc);
-	w->window_number = tile;
+	w = AllocateWindowDescFront(&_new_ship_desc, tile);
 	w->vscroll.cap = 4;
 	w->widget[2].data = (w->vscroll.cap << 8) + 1;
 
--- a/vehicle_gui.c	Sat Nov 18 16:47:02 2006 +0000
+++ b/vehicle_gui.c	Sat Nov 18 17:04:44 2006 +0000
@@ -454,7 +454,6 @@
 	WP(w, refit_d).order = order;
 
 	if (w != NULL) {
-		w->window_number = v->index;
 		w->caption_color = v->owner;
 		w->vscroll.cap = 8;
 		w->resize.step_height = 14;
--- a/widget.c	Sat Nov 18 16:47:02 2006 +0000
+++ b/widget.c	Sat Nov 18 17:04:44 2006 +0000
@@ -616,8 +616,6 @@
 
 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask)
 {
-	WindowNumber num;
-	WindowClass cls;
 	int i;
 	const Widget *wi;
 	Window *w2;
@@ -627,10 +625,7 @@
 	int screen_top, screen_bottom;
 	bool scroll = false;
 
-	cls = w->window_class;
-	num = w->window_number;
 	DeleteWindowById(WC_DROPDOWN_MENU, 0);
-	w = FindWindowById(cls, num);
 
 	if (is_dropdown_menu_shown) return;