Changeset - r13311:815ca89c5b47
[Not reviewed]
master
0 3 0
frosch - 15 years ago 2009-10-20 21:25:25
frosch@openttd.org
(svn r17830) -Fix [FS#3276]: Some windows already need their window_number when setting up smallest size (e.g. for DParams). So assign it earlier in Window::InitializeData instead of dealing with each window separately.
3 files changed with 11 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/autoreplace_gui.cpp
Show inline comments
 
@@ -197,25 +197,24 @@ class ReplaceVehicleWindow : public Wind
 

	
 
public:
 
	ReplaceVehicleWindow(const WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window()
 
	{
 
		this->replace_engines  = true; // start with locomotives (all other vehicles will not read this bool)
 
		this->engines[0].ForceRebuild();
 
		this->engines[1].ForceRebuild();
 
		this->reset_sel_engine = true;
 
		this->details_height   = ((vehicletype == VEH_TRAIN) ? 10 : 9) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
		this->sel_engine[0] = INVALID_ENGINE;
 
		this->sel_engine[1] = INVALID_ENGINE;
 

	
 
		this->window_number = vehicletype;
 
		this->InitNested(desc, vehicletype);
 

	
 
		this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(RVW_WIDGET_LEFT_MATRIX)->current_y / this->resize.step_height);
 
		this->vscroll2.SetCapacity(this->vscroll.GetCapacity());   // these two are always the same
 

	
 
		this->GetWidget<NWidgetCore>(RVW_WIDGET_LEFT_MATRIX)->widget_data =
 
				this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 

	
 
		this->owner = _local_company;
 
		this->sel_group = id_g;
 
	}
 

	
src/depot_gui.cpp
Show inline comments
 
@@ -221,29 +221,27 @@ struct DepotWindow : Window {
 
	VehicleType type;
 
	bool generate_list;
 
	VehicleList vehicle_list;
 
	VehicleList wagon_list;
 

	
 
	DepotWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window()
 
	{
 
		this->sel = INVALID_VEHICLE;
 
		this->generate_list = true;
 
		this->type = type;
 

	
 
		this->CreateNestedTree(desc);
 
		this->SetupWidgetData(type);
 
		this->FinishInitNested(desc, tile);
 

	
 
		this->window_number = tile;
 
		this->SetupWidgetData(type);
 

	
 
		this->FinishInitNested(desc, tile);
 
		this->owner = GetTileOwner(tile);
 
		this->CreateDepotListWindow(type);
 
	}
 

	
 
	~DepotWindow()
 
	{
 
		DeleteWindowById(WC_BUILD_VEHICLE, this->window_number);
 
	}
 

	
 
	/** Draw a vehicle in the depot window in the box with the top left corner at x,y.
 
	 * @param v     Vehicle to draw.
 
	 * @param x     Left side of the box to draw in.
src/window.cpp
Show inline comments
 
@@ -908,48 +908,50 @@ static void AssignWidgetToWindow(Window 
 

	
 
/**
 
 * Initializes the data (except the position and initial size) of a new Window.
 
 * @param cls           Class of the window, used for identification and grouping. @see WindowClass
 
 * @param *widget       Pointer to the widget array, it is \c NULL when nested widgets are used. @see Widget
 
 * @param window_number Number being assigned to the new window
 
 * @return Window pointer of the newly created window
 
 * @pre If nested widgets are used (\a widget is \c NULL), #nested_root and #nested_array_size must be initialized.
 
 *      In addition, #nested_array is either \c NULL, or already initialized.
 
 */
 
void Window::InitializeData(WindowClass cls, const Widget *widget, int window_number)
 
{
 
	/* Set up window properties; some of them are needed to set up smallest size below */
 
	this->window_class = cls;
 
	this->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
 
	this->owner = INVALID_OWNER;
 
	this->focused_widget = NULL;
 
	this->nested_focus = NULL;
 
	this->window_number = window_number;
 

	
 
	/* If available, initialize nested widget tree. */
 
	if (widget == NULL) {
 
		if (this->nested_array == NULL) {
 
			this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
 
			this->nested_root->SetupSmallestSize(this, true);
 
		} else {
 
			this->nested_root->SetupSmallestSize(this, false);
 
		}
 
		/* Initialize to smallest size. */
 
		this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, false);
 
	}
 
	/* Else, all data members of nested widgets have been set to 0 by the #ZeroedMemoryAllocator base class. */
 

	
 
	/* Set up window properties,
 
	/* Further set up window properties,
 
	 * this->left, this->top, this->width, this->height, this->resize.width, and this->resize.height are initialized later. */
 
	this->window_class = cls;
 
	this->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
 
	this->owner = INVALID_OWNER;
 
	AssignWidgetToWindow(this, widget);
 
	this->focused_widget = NULL;
 
	this->nested_focus = NULL;
 
	this->resize.step_width  = (this->nested_root != NULL) ? this->nested_root->resize_x : 1;
 
	this->resize.step_height = (this->nested_root != NULL) ? this->nested_root->resize_y : 1;
 
	this->window_number = window_number;
 

	
 
	/* Give focus to the opened window unless it is the OSK window or a text box
 
	 * of focused window has focus (so we don't interrupt typing). But if the new
 
	 * window has a text box, then take focus anyway. */
 
	bool has_editbox = (this->widget != NULL && this->GetWidgetOfType(WWT_EDITBOX) != NULL) ||
 
			(this->nested_root != NULL && this->nested_root->GetWidgetOfType(WWT_EDITBOX) != NULL);
 
	if (this->window_class != WC_OSK && (!EditBoxInGlobalFocus() || has_editbox)) SetFocusedWindow(this);
 

	
 
	/* Hacky way of specifying always-on-top windows. These windows are
 
	 * always above other windows because they are moved below them.
 
	 * status-bar is above news-window because it has been created earlier.
 
	 * Also, as the chat-window is excluded from this, it will always be
0 comments (0 inline, 0 general)