(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
authorrubidium
Sun, 29 Jul 2007 22:57:40 +0000
changeset 7367 cafca0510781
parent 7366 f2c2c5515649
child 7368 92dd846cf2c5
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
src/window.cpp
src/window.h
--- a/src/window.cpp	Sun Jul 29 22:21:26 2007 +0000
+++ b/src/window.cpp	Sun Jul 29 22:57:40 2007 +0000
@@ -598,10 +598,11 @@
  * @param cls see WindowClass class of the window, used for identification and grouping
  * @param *widget see Widget pointer to the window layout and various elements
  * @param window_number number being assigned to the new window
+ * @param data the data to be given during the WE_CREATE message
  * @return Window pointer of the newly created window */
 static Window *LocalAllocateWindow(
 							int x, int y, int min_width, int min_height, int def_width, int def_height,
-							WindowProc *proc, WindowClass cls, const Widget *widget, int window_number)
+							WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data)
 {
 	Window *w = FindFreeWindow();
 
@@ -654,7 +655,10 @@
 		_last_z_window++;
 	}
 
-	CallWindowEventNP(w, WE_CREATE);
+	WindowEvent e;
+	e.event = WE_CREATE;
+	e.we.create.data = data;
+	w->wndproc(w, &e);
 
 	/* Try to make windows smaller when our window is too small.
 	 * w->(width|height) is normally the same as min_(width|height),
@@ -715,9 +719,9 @@
  * @return Window pointer of the newly created window */
 Window *AllocateWindow(
 							int x, int y, int width, int height,
-							WindowProc *proc, WindowClass cls, const Widget *widget)
+							WindowProc *proc, WindowClass cls, const Widget *widget, void *data)
 {
-	return LocalAllocateWindow(x, y, width, height, width, height, proc, cls, widget, 0);
+	return LocalAllocateWindow(x, y, width, height, width, height, proc, cls, widget, 0, data);
 }
 
 struct SizeRect {
@@ -829,7 +833,7 @@
 	}
 }
 
-static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number)
+static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number, void *data)
 {
 	Point pt;
 	Window *w;
@@ -884,7 +888,7 @@
 	}
 
 allocate_window:
-	w = LocalAllocateWindow(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number);
+	w = LocalAllocateWindow(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data);
 	w->desc_flags = desc->flags;
 	return w;
 }
@@ -892,25 +896,27 @@
 /**
  * Open a new window.
  * @param *desc The pointer to the WindowDesc to be created
+ * @param data arbitrary data that is send with the WE_CREATE message
  * @return Window pointer of the newly created window
  */
-Window *AllocateWindowDesc(const WindowDesc *desc)
+Window *AllocateWindowDesc(const WindowDesc *desc, void *data)
 {
-	return LocalAllocateWindowDesc(desc, 0);
+	return LocalAllocateWindowDesc(desc, 0, data);
 }
 
 /**
  * Open a new window.
  * @param *desc The pointer to the WindowDesc to be created
  * @param window_number the window number of the new window
+ * @param data arbitrary data that is send with the WE_CREATE message
  * @return see Window pointer of the newly created window
  */
-Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number)
+Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data)
 {
 	Window *w;
 
 	if (BringWindowToFrontById(desc->cls, window_number)) return NULL;
-	w = LocalAllocateWindowDesc(desc, window_number);
+	w = LocalAllocateWindowDesc(desc, window_number, data);
 	return w;
 }
 
--- a/src/window.h	Sun Jul 29 22:21:26 2007 +0000
+++ b/src/window.h	Sun Jul 29 22:57:40 2007 +0000
@@ -127,7 +127,11 @@
 struct WindowEvent {
 	byte event;
 	union {
-		struct{
+		struct {
+			void *data;
+		} create;
+
+		struct {
 			Point pt;
 			int widget;
 		} click;
@@ -581,10 +585,11 @@
 							int height,
 							WindowProc *proc,
 							WindowClass cls,
-							const Widget *widget);
+							const Widget *widget,
+							void *data = NULL);
 
-Window *AllocateWindowDesc(const WindowDesc *desc);
-Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number);
+Window *AllocateWindowDesc(const WindowDesc *desc, void *data = NULL);
+Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data = NULL);
 
 void DrawWindowViewport(const Window *w);
 void ResizeWindow(Window *w, int x, int y);