(svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods cpp_gui
authorKUDr
Tue, 13 Feb 2007 13:00:37 +0000
branchcpp_gui
changeset 6243 8f231ee779cb
parent 6242 17609af8a1d1
child 6244 4b42fb40e6d2
(svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
src/window.cpp
src/window.h
--- a/src/window.cpp	Tue Feb 13 11:38:40 2007 +0000
+++ b/src/window.cpp	Tue Feb 13 13:00:37 2007 +0000
@@ -592,7 +592,7 @@
 
 
 
-static void DispatchLeftClickEvent(Window *w, int x, int y)
+void Window::DispatchLeftClickEvent(int x, int y)
 {
 	WindowEvent e;
 	const Widget *wi;
@@ -601,14 +601,14 @@
 	e.we.click.pt.y = y;
 	e.event = WE_CLICK;
 
-	if (w->desc_flags & WDF_DEF_WIDGET) {
-		e.we.click.widget = w->GetWidgetFromPos(x, y);
+	if (desc_flags & WDF_DEF_WIDGET) {
+		e.we.click.widget = GetWidgetFromPos(x, y);
 		if (e.we.click.widget < 0) return; /* exit if clicked outside of widgets */
 
 		/* don't allow any interaction if the button has been disabled */
-		if (IsWindowWidgetDisabled(w, e.we.click.widget)) return;
+		if (IsWindowWidgetDisabled(this, e.we.click.widget)) return;
 
-		wi = &w->widget[e.we.click.widget];
+		wi = &widget[e.we.click.widget];
 
 		if (wi->type & WWB_MASK) {
 			/* special widget handling for buttons*/
@@ -616,53 +616,53 @@
 				case WWT_PANEL   | WWB_PUSHBUTTON: /* WWT_PUSHBTN */
 				case WWT_IMGBTN  | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */
 				case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
-					w->HandleButtonClick(e.we.click.widget);
+					HandleButtonClick(e.we.click.widget);
 					break;
 			}
 		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
-			ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y);
+			ScrollbarClickHandler(this, wi, e.we.click.pt.x, e.we.click.pt.y);
 		}
 
-		if (w->desc_flags & WDF_STD_BTN) {
+		if (desc_flags & WDF_STD_BTN) {
 			if (e.we.click.widget == 0) { /* 'X' */
-				w->Close();
+				Close();
 				return;
 			}
 
 			if (e.we.click.widget == 1) { /* 'Title bar' */
-				w->StartDrag();
+				StartDrag();
 				return;
 			}
 		}
 
-		if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) {
-			w->StartSizing();
-			w->InvalidateWidget(e.we.click.widget);
+		if (desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) {
+			StartSizing();
+			InvalidateWidget(e.we.click.widget);
 			return;
 		}
 
-		if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
-			w->flags4 ^= WF_STICKY;
-			w->InvalidateWidget(e.we.click.widget);
+		if (desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
+			flags4 ^= WF_STICKY;
+			InvalidateWidget(e.we.click.widget);
 			return;
 		}
 	}
 
-	w->wndproc(w, &e);
+	wndproc(this, &e);
 }
 
-static void DispatchRightClickEvent(Window *w, int x, int y)
+void Window::DispatchRightClickEvent(int x, int y)
 {
 	WindowEvent e;
 
 	/* default tooltips handler? */
-	if (w->desc_flags & WDF_STD_TOOLTIPS) {
-		e.we.click.widget = w->GetWidgetFromPos(x, y);
+	if (desc_flags & WDF_STD_TOOLTIPS) {
+		e.we.click.widget = GetWidgetFromPos(x, y);
 		if (e.we.click.widget < 0)
 			return; /* exit if clicked outside of widgets */
 
-		if (w->widget[e.we.click.widget].tooltips != 0) {
-			GuiShowTooltips(w->widget[e.we.click.widget].tooltips);
+		if (widget[e.we.click.widget].tooltips != 0) {
+			GuiShowTooltips(widget[e.we.click.widget].tooltips);
 			return;
 		}
 	}
@@ -670,7 +670,7 @@
 	e.event = WE_RCLICK;
 	e.we.click.pt.x = x;
 	e.we.click.pt.y = y;
-	w->wndproc(w, &e);
+	wndproc(this, &e);
 }
 
 /** Dispatch the mousewheel-action to the window which will scroll any
@@ -679,51 +679,33 @@
  * @param widget the widget where the scrollwheel was used
  * @param wheel scroll up or down
  */
-static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
+void Window::DispatchMouseWheelEvent(int widget_idx, int wheel)
 {
 	const Widget *wi1, *wi2;
 	Scrollbar *sb;
 
-	if (widget < 0) return;
+	if (widget_idx < 0) return;
 
-	wi1 = &w->widget[widget];
-	wi2 = &w->widget[widget + 1];
+	wi1 = &widget[widget_idx];
+	wi2 = &widget[widget_idx + 1];
 
 	/* The listbox can only scroll if scrolling was done on the scrollbar itself,
 	 * or on the listbox (and the next item is (must be) the scrollbar)
 	 * XXX - should be rewritten as a widget-dependent scroller but that's
 	 * not happening until someone rewrites the whole widget-code */
-	if ((sb = &w->vscroll,  wi1->type == WWT_SCROLLBAR)  || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR)  ||
-			(sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) {
+	if ((sb = &vscroll,  wi1->type == WWT_SCROLLBAR)  || (sb = &vscroll2, wi1->type == WWT_SCROLL2BAR)  ||
+			(sb = &vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &vscroll, wi2->type == WWT_SCROLLBAR) ) {
 
 		if (sb->count > sb->cap) {
 			int pos = clamp(sb->pos + wheel, 0, sb->count - sb->cap);
 			if (pos != sb->pos) {
 				sb->pos = pos;
-				w->SetDirty();
+				SetDirty();
 			}
 		}
 	}
 }
 
-static void DrawOverlappedWindow(WindowList::Iterator it, int left, int top, int right, int bottom);
-
-void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
-{
-	DrawPixelInfo bk;
-	_cur_dpi = &bk;
-
-	const Window *w;
-	FOR_ALL_WINDOWS(w) {
-		if (right > w->left &&
-				bottom > w->top &&
-				left < w->left + w->width &&
-				top < w->top + w->height) {
-			DrawOverlappedWindow(it, left, top, right, bottom);
-		}
-	}
-}
-
 static void DrawOverlappedWindow(WindowList::Iterator wit, int left, int top, int right, int bottom)
 {
 	Window *w = (*wit).w;
@@ -777,6 +759,23 @@
 	}
 }
 
+void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
+{
+	DrawPixelInfo bk;
+	_cur_dpi = &bk;
+
+	const Window *w;
+	FOR_ALL_WINDOWS(w) {
+		if (right > w->left &&
+			bottom > w->top &&
+			left < w->left + w->width &&
+			top < w->top + w->height) {
+				DrawOverlappedWindow(it, left, top, right, bottom);
+		}
+	}
+}
+
+
 void CallWindowEventNP(Window *w, int event)
 {
 	WindowEvent e;
@@ -1729,7 +1728,7 @@
 		w->wndproc(w, &e);
 
 		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
-		if (vp == NULL) DispatchMouseWheelEvent(w, w->GetWidgetFromPos(x - w->left, y - w->top), mousewheel);
+		if (vp == NULL) w->DispatchMouseWheelEvent(w->GetWidgetFromPos(x - w->left, y - w->top), mousewheel);
 	}
 
 	if (vp != NULL) {
@@ -1761,8 +1760,8 @@
 		}
 	} else {
 		switch (click) {
-			case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top);  break;
-			case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
+			case 1: w->DispatchLeftClickEvent(x - w->left, y - w->top);  break;
+			case 2: w->DispatchRightClickEvent(x - w->left, y - w->top); break;
 		}
 	}
 }
--- a/src/window.h	Tue Feb 13 11:38:40 2007 +0000
+++ b/src/window.h	Tue Feb 13 13:00:37 2007 +0000
@@ -399,6 +399,9 @@
 	void StartSizing();
 	bool ContinueSizing();
 	static bool HandleWindowDragging(void);
+	void DispatchLeftClickEvent(int x, int y);
+	void DispatchRightClickEvent(int x, int y);
+	void DispatchMouseWheelEvent(int widget, int wheel);
 
 	/*virtual*/ void FinalRelease();
 	virtual void Close();