Changeset - r5907:578987d7f5a5
[Not reviewed]
master
0 1 0
rubidium - 17 years ago 2007-02-02 14:32:23
rubidium@openttd.org
(svn r8533) -Fix: segmentation fault when the toolbar gets removed and you have selected one of the items in a submenu of the toolbar.
1 file changed with 1 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/window.cpp
Show inline comments
 
@@ -1870,96 +1870,97 @@ void DeleteNonVitalWindows(void)
 

	
 
restart_search:
 
	/* When we find the window to delete, we need to restart the search
 
	 * as deleting this window could cascade in deleting (many) others
 
	 * anywhere in the z-array */
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
		if (w->window_class != WC_MAIN_WINDOW &&
 
				w->window_class != WC_SELECT_GAME &&
 
				w->window_class != WC_MAIN_TOOLBAR &&
 
				w->window_class != WC_STATUS_BAR &&
 
				w->window_class != WC_TOOLBAR_MENU &&
 
				w->window_class != WC_TOOLTIPS &&
 
				(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
 

	
 
			DeleteWindow(w);
 
			goto restart_search;
 
		}
 
	}
 
}
 

	
 
/* It is possible that a stickied window gets to a position where the
 
 * 'close' button is outside the gaming area. You cannot close it then; except
 
 * with this function. It closes all windows calling the standard function,
 
 * then, does a little hacked loop of closing all stickied windows. Note
 
 * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
 
void DeleteAllNonVitalWindows(void)
 
{
 
	Window* const *wz;
 

	
 
	/* Delete every window except for stickied ones, then sticky ones as well */
 
	DeleteNonVitalWindows();
 

	
 
restart_search:
 
	/* When we find the window to delete, we need to restart the search
 
	 * as deleting this window could cascade in deleting (many) others
 
	 * anywhere in the z-array */
 
	FOR_ALL_WINDOWS(wz) {
 
		if ((*wz)->flags4 & WF_STICKY) {
 
			DeleteWindow(*wz);
 
			goto restart_search;
 
		}
 
	}
 
}
 

	
 
/* Delete all always on-top windows to get an empty screen */
 
void HideVitalWindows(void)
 
{
 
	DeleteWindowById(WC_TOOLBAR_MENU, 0);
 
	DeleteWindowById(WC_MAIN_TOOLBAR, 0);
 
	DeleteWindowById(WC_STATUS_BAR, 0);
 
}
 

	
 
int PositionMainToolbar(Window *w)
 
{
 
	DEBUG(misc, 5, "Repositioning Main Toolbar...");
 

	
 
	if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) {
 
		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
	}
 

	
 
	switch (_patches.toolbar_pos) {
 
		case 1:  w->left = (_screen.width - w->width) / 2; break;
 
		case 2:  w->left = _screen.width - w->width; break;
 
		default: w->left = 0;
 
	}
 
	SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part
 
	return w->left;
 
}
 

	
 
void RelocateAllWindows(int neww, int newh)
 
{
 
	Window* const *wz;
 

	
 
	FOR_ALL_WINDOWS(wz) {
 
		Window *w = *wz;
 
		int left, top;
 

	
 
		if (w->window_class == WC_MAIN_WINDOW) {
 
			ViewPort *vp = w->viewport;
 
			vp->width = w->width = neww;
 
			vp->height = w->height = newh;
 
			vp->virtual_width = neww << vp->zoom;
 
			vp->virtual_height = newh << vp->zoom;
 
			continue; // don't modify top,left
 
		}
 

	
 
		/* XXX - this probably needs something more sane. For example specying
 
		 * in a 'backup'-desc that the window should always be centred. */
 
		switch (w->window_class) {
 
			case WC_MAIN_TOOLBAR:
 
				top = w->top;
 
				left = PositionMainToolbar(w); // changes toolbar orientation
 
				break;
 

	
 
			case WC_SELECT_GAME:
 
			case WC_GAME_OPTIONS:
0 comments (0 inline, 0 general)