|
@@ -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;
|
|
|
|