(svn r13154) -Codechange: make a window class of the news message history window.
authorrubidium
Sun, 18 May 2008 08:50:51 +0000
changeset 10610 dfb846e37be3
parent 10609 b6ebc6c30a83
child 10611 19de4d762169
(svn r13154) -Codechange: make a window class of the news message history window.
src/news_gui.cpp
--- a/src/news_gui.cpp	Sun May 18 08:13:13 2008 +0000
+++ b/src/news_gui.cpp	Sun May 18 08:50:51 2008 +0000
@@ -702,45 +702,56 @@
 }
 
 
-static void MessageHistoryWndProc(Window *w, WindowEvent *e)
-{
-	switch (e->event) {
-		case WE_PAINT: {
-			int y = 19;
-
-			SetVScrollCount(w, _total_news);
-			w->DrawWidgets();
-
-			if (_total_news == 0) break;
-			NewsID show = min(_total_news, w->vscroll.cap);
-
-			for (NewsID p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
-				/* get news in correct order */
-				const NewsItem *ni = &_news_items[getNews(p)];
-
-				SetDParam(0, ni->date);
-				DrawString(4, y, STR_SHORT_DATE, TC_WHITE);
+struct MessageHistoryWindow : Window {
+	MessageHistoryWindow(const WindowDesc *desc) : Window(desc)
+	{
+		this->vscroll.cap = 10;
+		this->vscroll.count = _total_news;
+		this->resize.step_height = 12;
+		this->resize.height = this->height - 12 * 6; // minimum of 4 items in the list, each item 12 high
+		this->resize.step_width = 1;
+		this->resize.width = 200; // can't make window any smaller than 200 pixel
 
-				DrawNewsString(82, y, TC_WHITE, ni, w->width - 95);
-				y += 12;
-			}
-			break;
-		}
+		this->FindWindowPlacementAndResize(desc);
+	}
 
-		case WE_CLICK:
-			if (e->we.click.widget == 3) {
-				int y = (e->we.click.pt.y - 19) / 12;
-				NewsID p = getNews(y + w->vscroll.pos);
+	virtual void OnPaint()
+	{
+		int y = 19;
 
-				if (p != INVALID_NEWS) ShowNewsMessage(p);
-			}
-			break;
+		SetVScrollCount(this, _total_news);
+		this->DrawWidgets();
 
-		case WE_RESIZE:
-			w->vscroll.cap += e->we.sizing.diff.y / 12;
-			break;
+		if (_total_news == 0) return;
+		NewsID show = min(_total_news, this->vscroll.cap);
+
+		for (NewsID p = this->vscroll.pos; p < this->vscroll.pos + show; p++) {
+			/* get news in correct order */
+			const NewsItem *ni = &_news_items[getNews(p)];
+
+			SetDParam(0, ni->date);
+			DrawString(4, y, STR_SHORT_DATE, TC_WHITE);
+
+			DrawNewsString(82, y, TC_WHITE, ni, this->width - 95);
+			y += 12;
+		}
 	}
-}
+
+	virtual void OnClick(Point pt, int widget)
+	{
+		if (widget == 3) {
+			int y = (pt.y - 19) / 12;
+			NewsID p = getNews(y + this->vscroll.pos);
+
+			if (p != INVALID_NEWS) ShowNewsMessage(p);
+		}
+	}
+
+	virtual void OnResize(Point new_size, Point delta)
+	{
+		this->vscroll.cap += delta.y / 12;
+	}
+};
 
 static const Widget _message_history_widgets[] = {
 {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,            STR_018B_CLOSE_WINDOW},
@@ -757,24 +768,14 @@
 	WC_MESSAGE_HISTORY, WC_NONE,
 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
 	_message_history_widgets,
-	MessageHistoryWndProc
+	NULL
 };
 
 /** Display window with news messages history */
 void ShowMessageHistory()
 {
 	DeleteWindowById(WC_MESSAGE_HISTORY, 0);
-	Window *w = new Window(&_message_history_desc);
-
-	if (w == NULL) return;
-
-	w->vscroll.cap = 10;
-	w->vscroll.count = _total_news;
-	w->resize.step_height = 12;
-	w->resize.height = w->height - 12 * 6; // minimum of 4 items in the list, each item 12 high
-	w->resize.step_width = 1;
-	w->resize.width = 200; // can't make window any smaller than 200 pixel
-	w->SetDirty();
+	new MessageHistoryWindow(&_message_history_desc);
 }