window.c
changeset 4634 07699ac2bf37
parent 4549 106ed18a7675
child 4719 fc6e14219f72
equal deleted inserted replaced
4633:cf6c2f173030 4634:07699ac2bf37
    31 static void DispatchLeftClickEvent(Window *w, int x, int y)
    31 static void DispatchLeftClickEvent(Window *w, int x, int y)
    32 {
    32 {
    33 	WindowEvent e;
    33 	WindowEvent e;
    34 	const Widget *wi;
    34 	const Widget *wi;
    35 
    35 
    36 	e.click.pt.x = x;
    36 	e.we.click.pt.x = x;
    37 	e.click.pt.y = y;
    37 	e.we.click.pt.y = y;
    38 	e.event = WE_CLICK;
    38 	e.event = WE_CLICK;
    39 
    39 
    40 	if (w->desc_flags & WDF_DEF_WIDGET) {
    40 	if (w->desc_flags & WDF_DEF_WIDGET) {
    41 		e.click.widget = GetWidgetFromPos(w, x, y);
    41 		e.we.click.widget = GetWidgetFromPos(w, x, y);
    42 		if (e.click.widget < 0) return; /* exit if clicked outside of widgets */
    42 		if (e.we.click.widget < 0) return; /* exit if clicked outside of widgets */
    43 
    43 
    44 		wi = &w->widget[e.click.widget];
    44 		wi = &w->widget[e.we.click.widget];
    45 
    45 
    46 		/* don't allow any interaction if the button has been disabled */
    46 		/* don't allow any interaction if the button has been disabled */
    47 		if (HASBIT(w->disabled_state, e.click.widget)) return;
    47 		if (HASBIT(w->disabled_state, e.we.click.widget)) return;
    48 
    48 
    49 		if (wi->type & 0xE0) {
    49 		if (wi->type & 0xE0) {
    50 			/* special widget handling for buttons*/
    50 			/* special widget handling for buttons*/
    51 			switch (wi->type) {
    51 			switch (wi->type) {
    52 			case WWT_IMGBTN  | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */
    52 			case WWT_IMGBTN  | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */
    53 			case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
    53 			case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
    54 				HandleButtonClick(w, e.click.widget);
    54 				HandleButtonClick(w, e.we.click.widget);
    55 				break;
    55 				break;
    56 			case WWT_NODISTXTBTN:
    56 			case WWT_NODISTXTBTN:
    57 				break;
    57 				break;
    58 			}
    58 			}
    59 		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
    59 		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
    60 			ScrollbarClickHandler(w, wi, e.click.pt.x, e.click.pt.y);
    60 			ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y);
    61 		}
    61 		}
    62 
    62 
    63 		if (w->desc_flags & WDF_STD_BTN) {
    63 		if (w->desc_flags & WDF_STD_BTN) {
    64 			if (e.click.widget == 0) { /* 'X' */
    64 			if (e.we.click.widget == 0) { /* 'X' */
    65 				DeleteWindow(w);
    65 				DeleteWindow(w);
    66 				return;
    66 				return;
    67 			}
    67 			}
    68 
    68 
    69 			if (e.click.widget == 1) { /* 'Title bar' */
    69 			if (e.we.click.widget == 1) { /* 'Title bar' */
    70 				StartWindowDrag(w); // if not return then w = StartWindowDrag(w); to get correct pointer
    70 				StartWindowDrag(w); // if not return then w = StartWindowDrag(w); to get correct pointer
    71 				return;
    71 				return;
    72 			}
    72 			}
    73 		}
    73 		}
    74 
    74 
    77 			return;
    77 			return;
    78 		}
    78 		}
    79 
    79 
    80 		if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
    80 		if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
    81 			w->flags4 ^= WF_STICKY;
    81 			w->flags4 ^= WF_STICKY;
    82 			InvalidateWidget(w, e.click.widget);
    82 			InvalidateWidget(w, e.we.click.widget);
    83 			return;
    83 			return;
    84 		}
    84 		}
    85 	}
    85 	}
    86 
    86 
    87 	w->wndproc(w, &e);
    87 	w->wndproc(w, &e);
    91 {
    91 {
    92 	WindowEvent e;
    92 	WindowEvent e;
    93 
    93 
    94 	/* default tooltips handler? */
    94 	/* default tooltips handler? */
    95 	if (w->desc_flags & WDF_STD_TOOLTIPS) {
    95 	if (w->desc_flags & WDF_STD_TOOLTIPS) {
    96 		e.click.widget = GetWidgetFromPos(w, x, y);
    96 		e.we.click.widget = GetWidgetFromPos(w, x, y);
    97 		if (e.click.widget < 0)
    97 		if (e.we.click.widget < 0)
    98 			return; /* exit if clicked outside of widgets */
    98 			return; /* exit if clicked outside of widgets */
    99 
    99 
   100 		if (w->widget[e.click.widget].tooltips != 0) {
   100 		if (w->widget[e.we.click.widget].tooltips != 0) {
   101 			GuiShowTooltips(w->widget[e.click.widget].tooltips);
   101 			GuiShowTooltips(w->widget[e.we.click.widget].tooltips);
   102 			return;
   102 			return;
   103 		}
   103 		}
   104 	}
   104 	}
   105 
   105 
   106 	e.event = WE_RCLICK;
   106 	e.event = WE_RCLICK;
   107 	e.click.pt.x = x;
   107 	e.we.click.pt.x = x;
   108 	e.click.pt.y = y;
   108 	e.we.click.pt.y = y;
   109 	w->wndproc(w, &e);
   109 	w->wndproc(w, &e);
   110 }
   110 }
   111 
   111 
   112 /** Dispatch the mousewheel-action to the window which will scroll any
   112 /** Dispatch the mousewheel-action to the window which will scroll any
   113  * compatible scrollbars if the mouse is pointed over the bar or its contents
   113  * compatible scrollbars if the mouse is pointed over the bar or its contents
   772 	if (_special_mouse_mode != WSM_PRESIZE) return;
   772 	if (_special_mouse_mode != WSM_PRESIZE) return;
   773 
   773 
   774 	w = GetCallbackWnd();
   774 	w = GetCallbackWnd();
   775 	if (w == NULL) return;
   775 	if (w == NULL) return;
   776 
   776 
   777 	e.place.pt = GetTileBelowCursor();
   777 	e.we.place.pt = GetTileBelowCursor();
   778 	if (e.place.pt.x == -1) {
   778 	if (e.we.place.pt.x == -1) {
   779 		_thd.selend.x = -1;
   779 		_thd.selend.x = -1;
   780 		return;
   780 		return;
   781 	}
   781 	}
   782 	e.place.tile = TileVirtXY(e.place.pt.x, e.place.pt.y);
   782 	e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y);
   783 	e.event = WE_PLACE_PRESIZE;
   783 	e.event = WE_PLACE_PRESIZE;
   784 	w->wndproc(w, &e);
   784 	w->wndproc(w, &e);
   785 }
   785 }
   786 
   786 
   787 static bool HandleDragDrop(void)
   787 static bool HandleDragDrop(void)
   798 	ResetObjectToPlace();
   798 	ResetObjectToPlace();
   799 
   799 
   800 	if (w != NULL) {
   800 	if (w != NULL) {
   801 		// send an event in client coordinates.
   801 		// send an event in client coordinates.
   802 		e.event = WE_DRAGDROP;
   802 		e.event = WE_DRAGDROP;
   803 		e.dragdrop.pt.x = _cursor.pos.x - w->left;
   803 		e.we.dragdrop.pt.x = _cursor.pos.x - w->left;
   804 		e.dragdrop.pt.y = _cursor.pos.y - w->top;
   804 		e.we.dragdrop.pt.y = _cursor.pos.y - w->top;
   805 		e.dragdrop.widget = GetWidgetFromPos(w, e.dragdrop.pt.x, e.dragdrop.pt.y);
   805 		e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y);
   806 		w->wndproc(w, &e);
   806 		w->wndproc(w, &e);
   807 	}
   807 	}
   808 	return false;
   808 	return false;
   809 }
   809 }
   810 
   810 
   821 		return false;
   821 		return false;
   822 	}
   822 	}
   823 
   823 
   824 	if (_left_button_down) {
   824 	if (_left_button_down) {
   825 		e.event = WE_POPUPMENU_OVER;
   825 		e.event = WE_POPUPMENU_OVER;
   826 		e.popupmenu.pt = _cursor.pos;
   826 		e.we.popupmenu.pt = _cursor.pos;
   827 	} else {
   827 	} else {
   828 		_popup_menu_active = false;
   828 		_popup_menu_active = false;
   829 		e.event = WE_POPUPMENU_SELECT;
   829 		e.event = WE_POPUPMENU_SELECT;
   830 		e.popupmenu.pt = _cursor.pos;
   830 		e.we.popupmenu.pt = _cursor.pos;
   831 	}
   831 	}
   832 
   832 
   833 	w->wndproc(w, &e);
   833 	w->wndproc(w, &e);
   834 
   834 
   835 	return false;
   835 	return false;
   844 	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
   844 	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
   845 
   845 
   846 	// We changed window, put a MOUSEOVER event to the last window
   846 	// We changed window, put a MOUSEOVER event to the last window
   847 	if (last_w != NULL && last_w != w) {
   847 	if (last_w != NULL && last_w != w) {
   848 		e.event = WE_MOUSEOVER;
   848 		e.event = WE_MOUSEOVER;
   849 		e.mouseover.pt.x = -1;
   849 		e.we.mouseover.pt.x = -1;
   850 		e.mouseover.pt.y = -1;
   850 		e.we.mouseover.pt.y = -1;
   851 		if (last_w->wndproc) last_w->wndproc(last_w, &e);
   851 		if (last_w->wndproc) last_w->wndproc(last_w, &e);
   852 	}
   852 	}
   853 	last_w = w;
   853 	last_w = w;
   854 
   854 
   855 	if (w != NULL) {
   855 	if (w != NULL) {
   856 		// send an event in client coordinates.
   856 		// send an event in client coordinates.
   857 		e.event = WE_MOUSEOVER;
   857 		e.event = WE_MOUSEOVER;
   858 		e.mouseover.pt.x = _cursor.pos.x - w->left;
   858 		e.we.mouseover.pt.x = _cursor.pos.x - w->left;
   859 		e.mouseover.pt.y = _cursor.pos.y - w->top;
   859 		e.we.mouseover.pt.y = _cursor.pos.y - w->top;
   860 		if (w->widget != NULL) {
   860 		if (w->widget != NULL) {
   861 			e.mouseover.widget = GetWidgetFromPos(w, e.mouseover.pt.x, e.mouseover.pt.y);
   861 			e.we.mouseover.widget = GetWidgetFromPos(w, e.we.mouseover.pt.x, e.we.mouseover.pt.y);
   862 		}
   862 		}
   863 		w->wndproc(w, &e);
   863 		w->wndproc(w, &e);
   864 	}
   864 	}
   865 
   865 
   866 	// Mouseover never stops execution
   866 	// Mouseover never stops execution
  1082 				if (resize_width)  w->width  = x + w->width;
  1082 				if (resize_width)  w->width  = x + w->width;
  1083 				if (resize_height) w->height = y + w->height;
  1083 				if (resize_height) w->height = y + w->height;
  1084 			}
  1084 			}
  1085 
  1085 
  1086 			e.event = WE_RESIZE;
  1086 			e.event = WE_RESIZE;
  1087 			e.sizing.size.x = x + w->width;
  1087 			e.we.sizing.size.x = x + w->width;
  1088 			e.sizing.size.y = y + w->height;
  1088 			e.we.sizing.size.y = y + w->height;
  1089 			e.sizing.diff.x = x;
  1089 			e.we.sizing.diff.x = x;
  1090 			e.sizing.diff.y = y;
  1090 			e.we.sizing.diff.y = y;
  1091 			w->wndproc(w, &e);
  1091 			w->wndproc(w, &e);
  1092 
  1092 
  1093 			SetWindowDirty(w);
  1093 			SetWindowDirty(w);
  1094 			return false;
  1094 			return false;
  1095 		}
  1095 		}
  1186 		_scrolling_viewport = false;
  1186 		_scrolling_viewport = false;
  1187 		return true;
  1187 		return true;
  1188 	}
  1188 	}
  1189 
  1189 
  1190 	if (_patches.reverse_scroll) {
  1190 	if (_patches.reverse_scroll) {
  1191 		e.scroll.delta.x = -_cursor.delta.x;
  1191 		e.we.scroll.delta.x = -_cursor.delta.x;
  1192 		e.scroll.delta.y = -_cursor.delta.y;
  1192 		e.we.scroll.delta.y = -_cursor.delta.y;
  1193 	} else {
  1193 	} else {
  1194 		e.scroll.delta.x = _cursor.delta.x;
  1194 		e.we.scroll.delta.x = _cursor.delta.x;
  1195 		e.scroll.delta.y = _cursor.delta.y;
  1195 		e.we.scroll.delta.y = _cursor.delta.y;
  1196 	}
  1196 	}
  1197 
  1197 
  1198 	/* Create a scroll-event and send it to the window */
  1198 	/* Create a scroll-event and send it to the window */
  1199 	e.event = WE_SCROLL;
  1199 	e.event = WE_SCROLL;
  1200 	w->wndproc(w, &e);
  1200 	w->wndproc(w, &e);
  1244  */
  1244  */
  1245 static void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam)
  1245 static void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam)
  1246 {
  1246 {
  1247 	WindowEvent e;
  1247 	WindowEvent e;
  1248 
  1248 
  1249 	e.message.event  = WE_MESSAGE;
  1249 	e.event             = WE_MESSAGE;
  1250 	e.message.msg    = msg;
  1250 	e.we.message.msg    = msg;
  1251 	e.message.wparam = wparam;
  1251 	e.we.message.wparam = wparam;
  1252 	e.message.lparam = lparam;
  1252 	e.we.message.lparam = lparam;
  1253 
  1253 
  1254 	w->wndproc(w, &e);
  1254 	w->wndproc(w, &e);
  1255 }
  1255 }
  1256 
  1256 
  1257 /** Send a message from one window to another. The receiving window is found by
  1257 /** Send a message from one window to another. The receiving window is found by
  1268 }
  1268 }
  1269 
  1269 
  1270 static void HandleKeypress(uint32 key)
  1270 static void HandleKeypress(uint32 key)
  1271 {
  1271 {
  1272 	Window *w;
  1272 	Window *w;
  1273 	WindowEvent we;
  1273 	WindowEvent e;
  1274 	/* Stores if a window with a textfield for typing is open
  1274 	/* Stores if a window with a textfield for typing is open
  1275 	 * If this is the case, keypress events are only passed to windows with text fields and
  1275 	 * If this is the case, keypress events are only passed to windows with text fields and
  1276 	 * to thein this main toolbar. */
  1276 	 * to thein this main toolbar. */
  1277 	bool query_open = false;
  1277 	bool query_open = false;
  1278 
  1278 
  1279 	// Setup event
  1279 	// Setup event
  1280 	we.keypress.event = WE_KEYPRESS;
  1280 	e.event = WE_KEYPRESS;
  1281 	we.keypress.ascii = key & 0xFF;
  1281 	e.we.keypress.ascii = key & 0xFF;
  1282 	we.keypress.keycode = key >> 16;
  1282 	e.we.keypress.keycode = key >> 16;
  1283 	we.keypress.cont = true;
  1283 	e.we.keypress.cont = true;
  1284 
  1284 
  1285 	// check if we have a query string window open before allowing hotkeys
  1285 	// check if we have a query string window open before allowing hotkeys
  1286 	if (FindWindowById(WC_QUERY_STRING,       0) != NULL ||
  1286 	if (FindWindowById(WC_QUERY_STRING,       0) != NULL ||
  1287 			FindWindowById(WC_SEND_NETWORK_MSG,   0) != NULL ||
  1287 			FindWindowById(WC_SEND_NETWORK_MSG,   0) != NULL ||
  1288 			FindWindowById(WC_GENERATE_LANDSCAPE, 0) != NULL ||
  1288 			FindWindowById(WC_GENERATE_LANDSCAPE, 0) != NULL ||
  1301 				w->window_class != WC_GENERATE_LANDSCAPE &&
  1301 				w->window_class != WC_GENERATE_LANDSCAPE &&
  1302 				w->window_class != WC_CONSOLE &&
  1302 				w->window_class != WC_CONSOLE &&
  1303 				w->window_class != WC_SAVELOAD) {
  1303 				w->window_class != WC_SAVELOAD) {
  1304 			continue;
  1304 			continue;
  1305 		}
  1305 		}
  1306 		w->wndproc(w, &we);
  1306 		w->wndproc(w, &e);
  1307 		if (!we.keypress.cont) break;
  1307 		if (!e.we.keypress.cont) break;
  1308 	}
  1308 	}
  1309 
  1309 
  1310 	if (we.keypress.cont) {
  1310 	if (e.we.keypress.cont) {
  1311 		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
  1311 		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
  1312 		// When there is no toolbar w is null, check for that
  1312 		// When there is no toolbar w is null, check for that
  1313 		if (w != NULL) w->wndproc(w, &we);
  1313 		if (w != NULL) w->wndproc(w, &e);
  1314 	}
  1314 	}
  1315 }
  1315 }
  1316 
  1316 
  1317 extern void UpdateTileSelection(void);
  1317 extern void UpdateTileSelection(void);
  1318 extern bool VpHandlePlaceSizingDrag(void);
  1318 extern bool VpHandlePlaceSizingDrag(void);
  1374 	if (mousewheel != 0) {
  1374 	if (mousewheel != 0) {
  1375 		WindowEvent e;
  1375 		WindowEvent e;
  1376 
  1376 
  1377 		/* Send WE_MOUSEWHEEL event to window */
  1377 		/* Send WE_MOUSEWHEEL event to window */
  1378 		e.event = WE_MOUSEWHEEL;
  1378 		e.event = WE_MOUSEWHEEL;
  1379 		e.wheel.wheel = mousewheel;
  1379 		e.we.wheel.wheel = mousewheel;
  1380 		w->wndproc(w, &e);
  1380 		w->wndproc(w, &e);
  1381 
  1381 
  1382 		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
  1382 		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
  1383 		if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
  1383 		if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
  1384 	}
  1384 	}