(svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
authorrubidium
Sat, 10 May 2008 12:30:27 +0000
changeset 10485 331014dcd0d3
parent 10484 e8beb2845f13
child 10486 247d43dfa6f1
(svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
src/main_gui.cpp
src/network/network_gui.cpp
src/news_gui.cpp
src/saveload.cpp
src/smallmap_gui.cpp
src/statusbar_gui.cpp
src/toolbar_gui.cpp
src/window.cpp
src/window_func.h
src/window_gui.h
--- a/src/main_gui.cpp	Sat May 10 08:58:52 2008 +0000
+++ b/src/main_gui.cpp	Sat May 10 12:30:27 2008 +0000
@@ -190,7 +190,7 @@
 	}
 	w->SetDirty();
 	/* Update the windows that have zoom-buttons to perhaps disable their buttons */
-	SendWindowMessageClass(w->window_class, how, w->window_number, 0);
+	InvalidateThisWindowData(w);
 	return true;
 }
 
@@ -390,9 +390,9 @@
 			ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w);
 			break;
 
-		case WE_MESSAGE:
+		case WE_INVALIDATE_DATA:
 			/* Forward the message to the appropiate toolbar (ingame or scenario editor) */
-			SendWindowMessage(WC_MAIN_TOOLBAR, 0, e->we.message.msg, e->we.message.wparam, e->we.message.lparam);
+			InvalidateWindowData(WC_MAIN_TOOLBAR, 0, e->we.invalidate.data);
 			break;
 	}
 }
--- a/src/network/network_gui.cpp	Sat May 10 08:58:52 2008 +0000
+++ b/src/network/network_gui.cpp	Sat May 10 12:30:27 2008 +0000
@@ -106,7 +106,7 @@
  * @param unselect unselect the currently selected item */
 void UpdateNetworkGameWindow(bool unselect)
 {
-	SendWindowMessage(WC_NETWORK_WINDOW, 0, unselect, 0, 0);
+	InvalidateWindowData(WC_NETWORK_WINDOW, 0, unselect);
 }
 
 static bool _internal_sort_order; // Used for Qsort order-flipping
@@ -549,8 +549,8 @@
 			if (nd->field == NGWW_PLAYER) HandleEditBox(w, &WP(w, network_ql_d).q, NGWW_PLAYER);
 			break;
 
-		case WE_MESSAGE:
-			if (e->we.message.msg != 0) nd->server = NULL;
+		case WE_INVALIDATE_DATA:
+			if (e->we.invalidate.data != 0) nd->server = NULL;
 			ld->flags |= VL_REBUILD;
 			SetWindowDirty(w);
 			break;
@@ -1183,7 +1183,7 @@
 			}
 			break;
 
-		case WE_MESSAGE:
+		case WE_INVALIDATE_DATA:
 			SetWindowDirty(w);
 			break;
 	}
@@ -1860,7 +1860,7 @@
 {
 	switch (e->event) {
 		case WE_CREATE:
-			SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->height, 0);
+			InvalidateWindowData(WC_NEWS_WINDOW, 0, w->height);
 			SetBit(_no_scroll, SCROLL_CHAT); // do not scroll the game with the arrow-keys
 			break;
 
@@ -1910,7 +1910,7 @@
 			break;
 
 		case WE_DESTROY:
-			SendWindowMessage(WC_NEWS_WINDOW, 0, WE_DESTROY, 0, 0);
+			InvalidateWindowData(WC_NEWS_WINDOW, 0, 0);
 			ClrBit(_no_scroll, SCROLL_CHAT);
 			break;
 	}
--- a/src/news_gui.cpp	Sat May 10 08:58:52 2008 +0000
+++ b/src/news_gui.cpp	Sat May 10 12:30:27 2008 +0000
@@ -62,6 +62,7 @@
 
 struct news_d : vp_d {
 	uint16 follow_vehicle;
+	uint16 chat_height;
 	int32 scrollpos_x;
 	int32 scrollpos_y;
 	int32 dest_scrollpos_x;
@@ -131,7 +132,7 @@
 	switch (e->event) {
 		case WE_CREATE: { // If chatbar is open at creation time, we need to go above it
 			const Window *w1 = FindWindowById(WC_SEND_NETWORK_MSG, 0);
-			w->message.msg = (w1 != NULL) ? w1->height : 0;
+			WP(w, news_d).chat_height = (w1 != NULL) ? w1->height : 0;
 			break;
 		}
 
@@ -231,15 +232,12 @@
 			}
 			break;
 
-		case WE_MESSAGE: // The chatbar has notified us that is was either created or closed
-			switch (e->we.message.msg) {
-				case WE_CREATE: w->message.msg = e->we.message.wparam; break;
-				case WE_DESTROY: w->message.msg = 0; break;
-			}
+		case WE_INVALIDATE_DATA: // The chatbar has notified us that is was either created or closed
+			WP(w, news_d).chat_height = e->we.invalidate.data;
 			break;
 
 		case WE_TICK: { // Scroll up newsmessages from the bottom in steps of 4 pixels
-			int y = max(w->top - 4, _screen.height - w->height - 12 - w->message.msg);
+			int y = max(w->top - 4, _screen.height - w->height - 12 - WP(w, news_d).chat_height);
 			if (y == w->top) return;
 
 			if (w->viewport != NULL) {
--- a/src/saveload.cpp	Sat May 10 08:58:52 2008 +0000
+++ b/src/saveload.cpp	Sat May 10 12:30:27 2008 +0000
@@ -1493,7 +1493,7 @@
 	_fast_forward = 0;
 	if (_cursor.sprite == SPR_CURSOR_MOUSE) SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
 
-	SendWindowMessage(WC_STATUS_BAR, 0, true, 0, 0);
+	InvalidateWindowData(WC_STATUS_BAR, 0, true);
 	_ts.saveinprogress = true;
 }
 
@@ -1504,7 +1504,7 @@
 	_fast_forward = _ts.ff_state;
 	if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
 
-	SendWindowMessage(WC_STATUS_BAR, 0, false, 0, 0);
+	InvalidateWindowData(WC_STATUS_BAR, 0, false);
 	_ts.saveinprogress = false;
 }
 
--- a/src/smallmap_gui.cpp	Sat May 10 08:58:52 2008 +0000
+++ b/src/smallmap_gui.cpp	Sat May 10 12:30:27 2008 +0000
@@ -1182,10 +1182,8 @@
 			ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w);
 			break;
 
-
-		case WE_MESSAGE:
+		case WE_INVALIDATE_DATA:
 			/* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */
-			if (e->we.message.wparam != w->window_number) break;
 			HandleZoomMessage(w, w->viewport, 5, 6);
 			break;
 	}
--- a/src/statusbar_gui.cpp	Sat May 10 08:58:52 2008 +0000
+++ b/src/statusbar_gui.cpp	Sat May 10 12:30:27 2008 +0000
@@ -86,7 +86,7 @@
 			}
 
 			/* Draw status bar */
-			if (w->message.msg) { // true when saving is active
+			if (WP(w, def_d).data_3) { // true when saving is active
 				DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_SAVING_GAME, TC_FROMSTRING);
 			} else if (_do_autosave) {
 				DrawStringCenteredTruncated(w->widget[1].left + 1, w->widget[1].right - 1, 1, STR_032F_AUTOSAVE, TC_FROMSTRING);
@@ -113,9 +113,8 @@
 			if (WP(w, def_d).data_2 > 0) DrawSprite(SPR_BLOT, PALETTE_TO_RED, w->widget[1].right - 11, 2);
 		} break;
 
-		case WE_MESSAGE:
-			w->message.msg = e->we.message.msg;
-			w->SetDirty();
+		case WE_INVALIDATE_DATA:
+			WP(w, def_d).data_3 = e->we.invalidate.data;
 			break;
 
 		case WE_CLICK:
--- a/src/toolbar_gui.cpp	Sat May 10 08:58:52 2008 +0000
+++ b/src/toolbar_gui.cpp	Sat May 10 12:30:27 2008 +0000
@@ -796,7 +796,7 @@
 			}
 			break;
 
-		case WE_MESSAGE:
+		case WE_INVALIDATE_DATA:
 			if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(w, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, 17, 18);
 			break;
 	}
@@ -1032,7 +1032,7 @@
 			}
 			break;
 
-		case WE_MESSAGE:
+		case WE_INVALIDATE_DATA:
 			HandleZoomMessage(w, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, 9, 10);
 			break;
 	}
--- a/src/window.cpp	Sat May 10 08:58:52 2008 +0000
+++ b/src/window.cpp	Sat May 10 12:30:27 2008 +0000
@@ -1591,53 +1591,6 @@
 	return true;
 }
 
-/** Send a message from one window to another. The receiving window is found by
- * @param w Window pointer pointing to the other window
- * @param msg Specifies the message to be sent
- * @param wparam Specifies additional message-specific information
- * @param lparam Specifies additional message-specific information
- */
-static void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam)
-{
-	WindowEvent e;
-
-	e.event             = WE_MESSAGE;
-	e.we.message.msg    = msg;
-	e.we.message.wparam = wparam;
-	e.we.message.lparam = lparam;
-
-	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
- * @param wparam Specifies additional message-specific information
- * @param lparam Specifies additional message-specific information
- */
-void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam)
-{
-	Window *w = FindWindowById(wnd_class, wnd_num);
-	if (w != NULL) SendWindowMessageW(w, msg, wparam, lparam);
-}
-
-/** Send a message from one window to another. The message will be sent
- * to ALL windows of the windowclass specified in the first parameter
- * @param wnd_class see WindowClass class
- * @param msg Specifies the message to be sent
- * @param wparam Specifies additional message-specific information
- * @param lparam Specifies additional message-specific information
- */
-void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam)
-{
-	Window* const *wz;
-
-	FOR_ALL_WINDOWS(wz) {
-		if ((*wz)->window_class == wnd_class) SendWindowMessageW(*wz, msg, wparam, lparam);
-	}
-}
-
 /** Handle keyboard input.
  * @param key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode
  */
@@ -2032,9 +1985,14 @@
  * Mark window data as invalid (in need of re-computing)
  * @param w Window with invalid data
  */
-void InvalidateThisWindowData(Window *w)
+void InvalidateThisWindowData(Window *w, int data)
 {
-	CallWindowEventNP(w, WE_INVALIDATE_DATA);
+	WindowEvent e;
+
+	e.event = WE_INVALIDATE_DATA;
+	e.we.invalidate.data = data;
+
+	w->HandleWindowEvent(&e);
 	w->SetDirty();
 }
 
@@ -2043,13 +2001,13 @@
  * @param cls Window class
  * @param number Window number within the class
  */
-void InvalidateWindowData(WindowClass cls, WindowNumber number)
+void InvalidateWindowData(WindowClass cls, WindowNumber number, int data)
 {
 	Window* const *wz;
 
 	FOR_ALL_WINDOWS(wz) {
 		Window *w = *wz;
-		if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w);
+		if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w, data);
 	}
 }
 
@@ -2057,12 +2015,12 @@
  * Mark window data of all windows of a given class as invalid (in need of re-computing)
  * @param cls Window class
  */
-void InvalidateWindowClassesData(WindowClass cls)
+void InvalidateWindowClassesData(WindowClass cls, int data)
 {
 	Window* const *wz;
 
 	FOR_ALL_WINDOWS(wz) {
-		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz);
+		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz, data);
 	}
 }
 
--- a/src/window_func.h	Sat May 10 08:58:52 2008 +0000
+++ b/src/window_func.h	Sat May 10 12:30:27 2008 +0000
@@ -9,8 +9,6 @@
 #include "player_type.h"
 
 void SetWindowDirty(const Window *w);
-void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam);
-void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam);
 
 Window *FindWindowById(WindowClass cls, WindowNumber number);
 void ChangeWindowOwner(PlayerID old_player, PlayerID new_player);
@@ -23,18 +21,20 @@
 void ResetWindowSystem();
 void SetupColorsAndInitialWindow();
 void InputLoop();
-void InvalidateThisWindowData(Window *w);
-void InvalidateWindowData(WindowClass cls, WindowNumber number);
+
+void InvalidateThisWindowData(Window *w, int data = 0);
+void InvalidateWindowData(WindowClass cls, WindowNumber number, int data = 0);
+void InvalidateWindowClassesData(WindowClass cls, int data = 0);
 
 void DeleteNonVitalWindows();
 void DeleteAllNonVitalWindows();
 void HideVitalWindows();
 void ShowVitalWindows();
 
-void InvalidateWindow(WindowClass cls, WindowNumber number);
 void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index);
+void InvalidateWindow(WindowClass cls, WindowNumber number);
 void InvalidateWindowClasses(WindowClass cls);
-void InvalidateWindowClassesData(WindowClass cls);
+
 void DeleteWindowById(WindowClass cls, WindowNumber number);
 void DeleteWindowByClass(WindowClass cls);
 
--- a/src/window_gui.h	Sat May 10 08:58:52 2008 +0000
+++ b/src/window_gui.h	Sat May 10 12:30:27 2008 +0000
@@ -131,7 +131,6 @@
 	WE_PLACE_PRESIZE,
 	WE_DROPDOWN_SELECT,
 	WE_RESIZE,          ///< Request to resize the window, @see WindowEvent.we.resize
-	WE_MESSAGE,         ///< Receipt of a message from another window. @see WindowEvent.we.message, SendWindowMessage(), SendWindowMessageClass()
 	WE_SCROLL,
 	WE_INVALIDATE_DATA, ///< Notification that data displayed by the window is obsolete
 	WE_CTRL_CHANGED,    ///< CTRL key has changed state
@@ -192,10 +191,8 @@
 		} keypress;
 
 		struct {
-			int msg;      ///< message to be sent
-			int wparam;   ///< additional message-specific information
-			int lparam;   ///< additional message-specific information
-		} message;
+			int data;
+		} invalidate;
 
 		struct {
 			Point delta;   ///< delta position against position of last call
@@ -274,16 +271,6 @@
 };
 
 /**
- * Message data structure for messages sent between winodows
- * @see SendWindowMessageW()
- */
-struct WindowMessage {
-	int msg;
-	int wparam;
-	int lparam;
-};
-
-/**
  * Data structure for an opened window
  */
 struct Window : ZeroedMemoryAllocator {
@@ -322,7 +309,6 @@
 	uint widget_count;     ///< Number of widgets of the window
 	uint32 desc_flags;     ///< Window/widgets default flags setting, @see WindowDefaultFlag
 
-	WindowMessage message; ///< Buffer for storing received messages (for communication between different window events)
 	Window *parent;        ///< Parent window
 	byte custom[WINDOW_CUSTOM_SIZE]; ///< Additional data depending on window type