Changeset - r9082:63eb44b1f81c
[Not reviewed]
master
0 6 0
rubidium - 16 years ago 2008-05-04 10:05:50
rubidium@openttd.org
(svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
6 files changed with 44 insertions and 29 deletions:
0 comments (0 inline, 0 general)
src/misc_gui.cpp
Show inline comments
 
@@ -1161,13 +1161,13 @@ static void QueryStringWndProc(Window *w
 
						/* If the parent is NULL, the editbox is handled by general function
 
						 * HandleOnEditText */
 
						if (parent != NULL) {
 
							WindowEvent e;
 
							e.event = WE_ON_EDIT_TEXT;
 
							e.we.edittext.str = qs->text.buf;
 
							parent->wndproc(parent, &e);
 
							parent->HandleWindowEvent(&e);
 
						} else {
 
							HandleOnEditText(qs->text.buf);
 
						}
 
					}
 
					/* Fallthrough */
 
				case QUERY_STR_WIDGET_CANCEL:
 
@@ -1191,13 +1191,13 @@ static void QueryStringWndProc(Window *w
 
			if (!qs->handled && w->parent != NULL) {
 
				WindowEvent e;
 
				Window *parent = w->parent;
 

	
 
				qs->handled = true;
 
				e.event = WE_ON_EDIT_TEXT_CANCEL;
 
				parent->wndproc(parent, &e);
 
				parent->HandleWindowEvent(&e);
 
			}
 
			ClrBit(_no_scroll, SCROLL_EDIT);
 
			break;
 
		}
 
}
 

	
src/osk_gui.cpp
Show inline comments
 
@@ -158,25 +158,25 @@ static void OskWndProc(Window *w, Window
 
						/* pass information by simulating a button press on parent window */
 
						if (WP(w, osk_d).ok_btn != 0) {
 
							Window *parent = w->parent;
 
							WindowEvent e;
 
							e.event = WE_CLICK;
 
							e.we.click.widget = WP(w, osk_d).ok_btn;
 
							parent->wndproc(parent, &e);
 
							parent->HandleWindowEvent(&e);
 
						}
 
					}
 
					DeleteWindow(w);
 
					break;
 

	
 
				case OSK_WIDGET_CANCEL:
 
					if (WP(w, osk_d).cancel_btn != 0) { // pass a cancel event to the parent window
 
						Window *parent = w->parent;
 
						WindowEvent e;
 
						e.event = WE_CLICK;
 
						e.we.click.widget = WP(w, osk_d).cancel_btn;
 
						parent->wndproc(parent, &e);
 
						parent->HandleWindowEvent(&e);
 
					} else { // or reset to original string
 
						strcpy(qs->text.buf, WP(w, osk_d).orig);
 
						UpdateTextBufferSize(&qs->text);
 
						MoveTextBufferPos(&qs->text, WKC_END);
 
					}
 
					DeleteWindow(w);
src/viewport.cpp
Show inline comments
 
@@ -2058,13 +2058,13 @@ void PlaceObject()
 
	if (w != NULL) {
 
		WindowEvent e;
 

	
 
		e.event = WE_PLACE_OBJ;
 
		e.we.place.pt = pt;
 
		e.we.place.tile = TileVirtXY(pt.x, pt.y);
 
		w->wndproc(w, &e);
 
		w->HandleWindowEvent(&e);
 
	}
 
}
 

	
 

	
 
/* scrolls the viewport in a window to a given location */
 
bool ScrollWindowTo(int x , int y, Window *w, bool instant)
 
@@ -2709,13 +2709,13 @@ bool VpHandlePlaceSizingDrag()
 
	}
 

	
 
	/* while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() ) */
 
	if (_left_button_down) {
 
		e.event = WE_PLACE_DRAG;
 
		e.we.place.pt = GetTileBelowCursor();
 
		w->wndproc(w, &e);
 
		w->HandleWindowEvent(&e);
 
		return false;
 
	}
 

	
 
	/* mouse button released..
 
	 * keep the selected tool, but reset it to the original mode. */
 
	_special_mouse_mode = WSM_NONE;
 
@@ -2734,13 +2734,13 @@ bool VpHandlePlaceSizingDrag()
 

	
 
	/* and call the mouseup event. */
 
	e.event = WE_PLACE_MOUSEUP;
 
	e.we.place.pt = _thd.selend;
 
	e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y);
 
	e.we.place.starttile = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 

	
 
	return false;
 
}
 

	
 
void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, ViewportHighlightMode mode, Window *w)
 
{
src/widgets/dropdown.cpp
Show inline comments
 
@@ -176,13 +176,13 @@ static void DropDownMenuWndProc(Window *
 

	
 
			if (WP(w, dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) {
 
				WindowEvent e;
 
				e.event = WE_DROPDOWN_SELECT;
 
				e.we.dropdown.button = WP(w, dropdown_d).parent_button;
 
				e.we.dropdown.index  = WP(w, dropdown_d).selected_index;
 
				w2->wndproc(w2, &e);
 
				w2->HandleWindowEvent(&e);
 
				DeleteWindow(w);
 
				return;
 
			}
 

	
 
			if (WP(w, dropdown_d).drag_mode) {
 
				int item = GetDropDownItem(w);
src/window.cpp
Show inline comments
 
@@ -44,12 +44,21 @@ bool _scrolling_scrollbar;
 
bool _scrolling_viewport;
 
bool _popup_menu_active;
 

	
 
byte _special_mouse_mode;
 

	
 

	
 
/**
 
 * Call the window event handler for handling event \a e
 
 * @param e Window event to handle
 
 */
 
void Window::HandleWindowEvent(WindowEvent *e)
 
{
 
	if (wndproc != NULL) wndproc(this, e);
 
}
 

	
 
void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...)
 
{
 
	va_list wdg_list;
 

	
 
	va_start(wdg_list, widgets);
 

	
 
@@ -181,13 +190,13 @@ static void DispatchLeftClickEvent(Windo
 
			w->flags4 ^= WF_STICKY;
 
			w->InvalidateWidget(e.we.click.widget);
 
			return;
 
		}
 
	}
 

	
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 
}
 

	
 
/**
 
 * Dispatch right mouse-button click in window.
 
 * @param w Window to dispatch event in
 
 * @param x X coordinate of the click
 
@@ -209,13 +218,13 @@ static void DispatchRightClickEvent(Wind
 
		}
 
	}
 

	
 
	e.event = WE_RCLICK;
 
	e.we.click.pt.x = x;
 
	e.we.click.pt.y = y;
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 
}
 

	
 
/**
 
 * Dispatch the mousewheel-action to the window.
 
 * The window will scroll any compatible scrollbars if the mouse is pointed over the bar or its contents
 
 * @param w Window
 
@@ -349,13 +358,13 @@ void DrawOverlappedWindowForAll(int left
 
 */
 
void CallWindowEventNP(Window *w, int event)
 
{
 
	WindowEvent e;
 

	
 
	e.event = event;
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 
}
 

	
 
/**
 
 * Mark entire window as dirty (in need of re-paint)
 
 * @param w Window to redraw
 
 * @ingroup dirty
 
@@ -685,23 +694,22 @@ static Window *LocalAllocateWindow(int x
 
	if (_last_z_window == endof(_z_windows)) {
 
		w = FindDeletableWindow();
 
		if (w == NULL) w = ForceFindDeletableWindow();
 
		DeleteWindow(w);
 
	}
 

	
 
	w = new Window;
 
	w = new Window(proc);
 

	
 
	/* Set up window properties */
 
	w->window_class = cls;
 
	w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
 
	w->caption_color = 0xFF;
 
	w->left = x;
 
	w->top = y;
 
	w->width = min_width;
 
	w->height = min_height;
 
	w->wndproc = proc;
 
	AssignWidgetToWindow(w, widget);
 
	w->resize.width = min_width;
 
	w->resize.height = min_height;
 
	w->resize.step_width = 1;
 
	w->resize.step_height = 1;
 
	w->window_number = window_number;
 
@@ -731,13 +739,13 @@ static Window *LocalAllocateWindow(int x
 
		_last_z_window++;
 
	}
 

	
 
	WindowEvent e;
 
	e.event = WE_CREATE;
 
	e.we.create.data = data;
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 

	
 
	/* Try to make windows smaller when our window is too small.
 
	 * w->(width|height) is normally the same as min_(width|height),
 
	 * but this way the GUIs can be made a little more dynamic;
 
	 * one can use the same spec for multiple windows and those
 
	 * can then determine the real minimum size of the window. */
 
@@ -763,13 +771,13 @@ static Window *LocalAllocateWindow(int x
 
		WindowEvent e;
 
		e.event = WE_RESIZE;
 
		e.we.sizing.size.x = w->width;
 
		e.we.sizing.size.y = w->height;
 
		e.we.sizing.diff.x = enlarge_x;
 
		e.we.sizing.diff.y = enlarge_y;
 
		w->wndproc(w, &e);
 
		w->HandleWindowEvent(&e);
 
	}
 

	
 
	int nx = w->left;
 
	int ny = w->top;
 

	
 
	if (nx + w->width > _screen.width) nx -= (nx + w->width - _screen.width);
 
@@ -1141,13 +1149,13 @@ static void HandlePlacePresize()
 
	if (e.we.place.pt.x == -1) {
 
		_thd.selend.x = -1;
 
		return;
 
	}
 
	e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y);
 
	e.event = WE_PLACE_PRESIZE;
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 
}
 

	
 
static bool HandleDragDrop()
 
{
 
	Window *w;
 
	WindowEvent e;
 
@@ -1161,13 +1169,13 @@ static bool HandleDragDrop()
 
	if (w != NULL) {
 
		/* send an event in client coordinates. */
 
		e.event = WE_DRAGDROP;
 
		e.we.dragdrop.pt.x = _cursor.pos.x - w->left;
 
		e.we.dragdrop.pt.y = _cursor.pos.y - w->top;
 
		e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y);
 
		w->wndproc(w, &e);
 
		w->HandleWindowEvent(&e);
 
	}
 

	
 
	ResetObjectToPlace();
 

	
 
	return false;
 
}
 
@@ -1191,13 +1199,13 @@ static bool HandlePopupMenu()
 
	} else {
 
		_popup_menu_active = false;
 
		e.event = WE_POPUPMENU_SELECT;
 
		e.we.popupmenu.pt = _cursor.pos;
 
	}
 

	
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 

	
 
	return false;
 
}
 

	
 
static bool HandleMouseOver()
 
{
 
@@ -1208,13 +1216,13 @@ static bool HandleMouseOver()
 
	/* We changed window, put a MOUSEOVER event to the last window */
 
	if (_mouseover_last_w != NULL && _mouseover_last_w != w) {
 
		/* Reset mouse-over coordinates of previous window */
 
		e.event = WE_MOUSEOVER;
 
		e.we.mouseover.pt.x = -1;
 
		e.we.mouseover.pt.y = -1;
 
		if (_mouseover_last_w->wndproc != NULL) _mouseover_last_w->wndproc(_mouseover_last_w, &e);
 
		_mouseover_last_w->HandleWindowEvent(&e);
 
	}
 

	
 
	/* _mouseover_last_w will get reset when the window is deleted, see DeleteWindow() */
 
	_mouseover_last_w = w;
 

	
 
	if (w != NULL) {
 
@@ -1222,13 +1230,13 @@ static bool HandleMouseOver()
 
		e.event = WE_MOUSEOVER;
 
		e.we.mouseover.pt.x = _cursor.pos.x - w->left;
 
		e.we.mouseover.pt.y = _cursor.pos.y - w->top;
 
		if (w->widget != NULL) {
 
			e.we.mouseover.widget = GetWidgetFromPos(w, e.we.mouseover.pt.x, e.we.mouseover.pt.y);
 
		}
 
		w->wndproc(w, &e);
 
		w->HandleWindowEvent(&e);
 
	}
 

	
 
	/* Mouseover never stops execution */
 
	return true;
 
}
 

	
 
@@ -1474,13 +1482,13 @@ static bool HandleWindowDragging()
 

	
 
			e.event = WE_RESIZE;
 
			e.we.sizing.size.x = x + w->width;
 
			e.we.sizing.size.y = y + w->height;
 
			e.we.sizing.diff.x = x;
 
			e.we.sizing.diff.y = y;
 
			w->wndproc(w, &e);
 
			w->HandleWindowEvent(&e);
 
			return false;
 
		}
 
	}
 

	
 
	_dragging_window = false;
 
	return false;
 
@@ -1605,13 +1613,13 @@ static bool HandleViewportScroll()
 
		_cursor.v_wheel = 0;
 
		_cursor.h_wheel = 0;
 
	}
 

	
 
	/* Create a scroll-event and send it to the window */
 
	e.event = WE_SCROLL;
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 

	
 
	_cursor.delta.x = 0;
 
	_cursor.delta.y = 0;
 
	return false;
 
}
 

	
 
@@ -1680,13 +1688,13 @@ static void SendWindowMessageW(Window *w
 

	
 
	e.event             = WE_MESSAGE;
 
	e.we.message.msg    = msg;
 
	e.we.message.wparam = wparam;
 
	e.we.message.lparam = lparam;
 

	
 
	w->wndproc(w, &e);
 
	w->HandleWindowEvent(&e);
 
}
 

	
 
/** Send a message from one window to another. The receiving window is found by
 
 * @param wnd_class see WindowClass class AND
 
 * @param wnd_num see WindowNumber number, mostly 0
 
 * @param msg Specifies the message to be sent
 
@@ -1778,20 +1786,20 @@ void HandleKeypress(uint32 key)
 
				w->window_class != WC_GENERATE_LANDSCAPE &&
 
				w->window_class != WC_CONSOLE &&
 
				w->window_class != WC_SAVELOAD &&
 
				w->window_class != WC_COMPANY_PASSWORD_WINDOW) {
 
			continue;
 
		}
 
		w->wndproc(w, &e);
 
		w->HandleWindowEvent(&e);
 
		if (!e.we.keypress.cont) break;
 
	}
 

	
 
	if (e.we.keypress.cont) {
 
		Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
		/* When there is no toolbar w is null, check for that */
 
		if (w != NULL) w->wndproc(w, &e);
 
		if (w != NULL) w->HandleWindowEvent(&e);
 
	}
 
}
 

	
 
/**
 
 * State of CONTROL key has changed
 
 */
 
@@ -1802,13 +1810,13 @@ void HandleCtrlChanged()
 
	e.event = WE_CTRL_CHANGED;
 
	e.we.ctrl.cont = true;
 

	
 
	/* Call the event, start with the uppermost window. */
 
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
 
		Window *w = *--wz;
 
		w->wndproc(w, &e);
 
		w->HandleWindowEvent(&e);
 
		if (!e.we.ctrl.cont) break;
 
	}
 
}
 

	
 
/**
 
 * Local counter that is incremented each time an mouse input event is detected.
 
@@ -1909,13 +1917,13 @@ void MouseLoop(MouseClick click, int mou
 
			/* Scrollwheel is in zoom mode. Make the zoom event. */
 
			WindowEvent e;
 

	
 
			/* Send WE_MOUSEWHEEL event to window */
 
			e.event = WE_MOUSEWHEEL;
 
			e.we.wheel.wheel = mousewheel;
 
			w->wndproc(w, &e);
 
			w->HandleWindowEvent(&e);
 
		}
 

	
 
		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
 
		if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
 
	}
 

	
 
@@ -2294,13 +2302,13 @@ void RelocateAllWindows(int neww, int ne
 
					WindowEvent e;
 
					e.event = WE_RESIZE;
 
					e.we.sizing.size.x = w->width;
 
					e.we.sizing.size.y = w->height;
 
					e.we.sizing.diff.x = neww - w->width;
 
					e.we.sizing.diff.y = 0;
 
					w->wndproc(w, &e);
 
					w->HandleWindowEvent(&e);
 
				}
 

	
 
				top = w->top;
 
				left = PositionMainToolbar(w); // changes toolbar orientation
 
				break;
 

	
src/window_gui.h
Show inline comments
 
@@ -288,12 +288,18 @@ struct WindowMessage {
 
};
 

	
 
/**
 
 * Data structure for an opened window
 
 */
 
struct Window : ZeroedMemoryAllocator {
 
private:
 
	WindowProc *wndproc;   ///< Event handler function for the window. Do not use directly, call HandleWindowEvent() instead.
 

	
 
public:
 
	Window(WindowProc *proc) : wndproc(proc) {}
 

	
 
	uint16 flags4;              ///< Window flags, @see WindowFlags
 
	WindowClass window_class;   ///< Window class
 
	WindowNumber window_number; ///< Window number within the window class
 

	
 
	int left;   ///< x position of left edge of the window
 
	int top;    ///< y position of top edge of the window
 
@@ -304,13 +310,12 @@ struct Window : ZeroedMemoryAllocator {
 
	Scrollbar vscroll;  ///< First vertical scroll bar
 
	Scrollbar vscroll2; ///< Second vertical scroll bar
 
	ResizeInfo resize;  ///< Resize information
 

	
 
	byte caption_color; ///< Background color of the window caption, contains PlayerID
 

	
 
	WindowProc *wndproc;   ///< Event handler function for the window
 
	ViewPort *viewport;    ///< Pointer to viewport, if present
 
	const Widget *original_widget; ///< Original widget layout, copied from WindowDesc
 
	Widget *widget;        ///< Widgets of the window
 
	uint widget_count;     ///< Number of widgets of the window
 
	uint32 desc_flags;     ///< Window/widgets default flags setting, @see WindowDefaultFlag
 

	
 
@@ -336,12 +341,14 @@ struct Window : ZeroedMemoryAllocator {
 

	
 
	void RaiseButtons();
 
	void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);
 
	void CDECL SetWidgetsHiddenState(bool hidden_stat, int widgets, ...);
 
	void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...);
 
	void InvalidateWidget(byte widget_index) const;
 

	
 
	virtual void HandleWindowEvent(WindowEvent *e);
 
};
 

	
 
struct menu_d {
 
	byte item_count;      ///< follow_vehicle
 
	byte sel_index;       ///< scrollpos_x
 
	byte main_button;     ///< scrollpos_y
0 comments (0 inline, 0 general)