changeset 119:1cad81b7cc4c

Implemented initial splitbar code on Unix. And made some fixes for setting the ID on all platforms, but specifically windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 19 Oct 2002 06:36:41 +0000
parents c170181668b7
children 7d2108cbcd3e
files dw.h gtk/dw.c os2/dw.c win/dw.c
diffstat 4 files changed, 118 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Sat Oct 19 03:41:36 2002 +0000
+++ b/dw.h	Sat Oct 19 06:36:41 2002 +0000
@@ -728,7 +728,7 @@
 void dw_notebook_page_set(HWND handle, unsigned int pageid);
 unsigned int dw_notebook_page_query(HWND handle);
 void dw_notebook_pack(HWND handle, unsigned long pageid, HWND page);
-HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright);
+HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id);
 void dw_splitbar_set(HWND handle, int percent);
 int dw_splitbar_get(HWND handle);
 HMENUI dw_menu_new(unsigned long id);
--- a/gtk/dw.c	Sat Oct 19 03:41:36 2002 +0000
+++ b/gtk/dw.c	Sat Oct 19 06:36:41 2002 +0000
@@ -5524,25 +5524,111 @@
 	DW_MUTEX_UNLOCK;
 }
 
-
-/*
- * Pack a splitbar (sizer) into the specified box from the start.
- * Parameters:
- *       box: Window handle of the box to be packed into.
- */
-void dw_box_pack_splitbar_start(HWND box)
-{
-    /* TODO */
-}
-
-/*
- * Pack a splitbar (sizer) into the specified box from the end.
- * Parameters:
- *       box: Window handle of the box to be packed into.
- */
-void dw_box_pack_splitbar_end(HWND box)
-{
-	/* TODO */
+/* Reposition the bar according to the percentage */
+gint _splitbar_size_allocate(GtkWidget *widget, GtkAllocation *event, gpointer data)
+{
+	int percent = (int)gtk_object_get_data(GTK_OBJECT(widget), "_dw_percent");
+	int lastwidth = (int)gtk_object_get_data(GTK_OBJECT(widget), "_dw_lastwidth");
+	int lastheight = (int)gtk_object_get_data(GTK_OBJECT(widget), "_dw_lastheight");
+	float ratio = ((float)percent/100.0);
+
+	/* Prevent infinite recursion ;) */  
+	if(lastwidth == event->width && lastheight == event->height)
+		return TRUE;
+
+	lastwidth = event->width; lastheight = event->height;
+  
+	gtk_object_set_data(GTK_OBJECT(widget), "_dw_splitbar_sizing", (gpointer)1);
+	gtk_object_set_data(GTK_OBJECT(widget), "_dw_lastwidth", (gpointer)lastwidth);
+	gtk_object_set_data(GTK_OBJECT(widget), "_dw_lastheight", (gpointer)lastheight);
+
+	if(GTK_IS_HPANED(widget))
+		gtk_paned_set_position(GTK_PANED(widget), (int)(event->width * ratio));
+	if(GTK_IS_VPANED(widget))
+		gtk_paned_set_position(GTK_PANED(widget), (int)(event->height * ratio));
+	return TRUE;
+}
+
+/* Figure out the new percentage */
+gint _splitbar_child_size_allocate(GtkWidget *widget, GtkAllocation *event, gpointer data)
+{
+	GtkWidget *splitbar = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(widget), "_dw_splitbar");
+	int percent;
+  
+	if(!splitbar)
+		return TRUE;  
+
+	if(gtk_object_get_data(GTK_OBJECT(splitbar), "_dw_splitbar_sizing"))
+	{
+		gtk_object_set_data(GTK_OBJECT(splitbar), "_dw_splitbar_sizing", (gpointer)0);
+		return TRUE;
+	}
+  
+	if(GTK_IS_VPANED(splitbar))
+		percent = (int)((event->height * 100) / (splitbar->allocation.height - 3));
+	else if(GTK_IS_HPANED(splitbar))
+		percent = (int)((event->width * 100) / (splitbar->allocation.width - 3));
+	else
+		return TRUE;
+
+	gtk_object_set_data(GTK_OBJECT(splitbar), "_dw_percent", (gpointer)percent);
+  
+	return TRUE;
+}
+
+/*
+ * Creates a splitbar window (widget) with given parameters.
+ * Parameters:
+ *       type: Value can be BOXVERT or BOXHORZ.
+ *       topleft: Handle to the window to be top or left.
+ *       bottomright:  Handle to the window to be bottom or right.
+ * Returns:
+ *       A handle to a splitbar window or NULL on failure.
+ */
+HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id)
+{
+	GtkWidget *tmp = NULL;
+	int _locked_by_me = FALSE;
+
+	DW_MUTEX_LOCK;
+	if(type == BOXHORZ)
+		tmp = gtk_hpaned_new();
+	else
+		tmp = gtk_vpaned_new();
+	gtk_paned_add1(GTK_PANED(tmp), topleft);
+	gtk_paned_add2(GTK_PANED(tmp), bottomright);
+	gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id);
+	gtk_object_set_data(GTK_OBJECT(tmp), "_dw_percent", (gpointer)50);
+	gtk_signal_connect(GTK_OBJECT(tmp), "size-allocate", GTK_SIGNAL_FUNC(_splitbar_size_allocate), NULL);
+	gtk_object_set_data(GTK_OBJECT(topleft), "_dw_splitbar", (gpointer)tmp);
+#if 0
+	gtk_signal_connect(GTK_OBJECT(topleft), "size-allocate", GTK_SIGNAL_FUNC(_splitbar_child_size_allocate), NULL);
+#endif
+	gtk_paned_set_handle_size(GTK_PANED(tmp), 3);
+	gtk_widget_show(tmp);
+	DW_MUTEX_UNLOCK;
+	return tmp;
+}
+
+/*
+ * Sets the position of a splitbar (pecentage).
+ * Parameters:
+ *       handle: The handle to the splitbar returned by dw_splitbar_new().
+ */
+void dw_splitbar_set(HWND handle, int percent)
+{
+	/* We probably need to force a redraw here */
+	dw_window_set_data(handle, "_dw_percent", (void *)percent);
+}
+
+/*
+ * Gets the position of a splitbar (pecentage).
+ * Parameters:
+ *       handle: The handle to the splitbar returned by dw_splitbar_new().
+ */
+int dw_splitbar_get(HWND handle)
+{
+	return (int)dw_window_get_data(handle, "_dw_percent");
 }
 
 /*
--- a/os2/dw.c	Sat Oct 19 03:41:36 2002 +0000
+++ b/os2/dw.c	Sat Oct 19 06:36:41 2002 +0000
@@ -6703,7 +6703,7 @@
  * Returns:
  *       A handle to a splitbar window or NULL on failure.
  */
-HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright)
+HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id)
 {
 	HWND tmp = WinCreateWindow(HWND_OBJECT,
 							   SplitbarClassName,
@@ -6712,7 +6712,7 @@
 							   0,0,2000,1000,
 							   NULLHANDLE,
 							   HWND_TOP,
-							   0L,
+							   id,
 							   NULL,
 							   NULL);
 	if(tmp)
--- a/win/dw.c	Sat Oct 19 03:41:36 2002 +0000
+++ b/win/dw.c	Sat Oct 19 06:36:41 2002 +0000
@@ -3570,7 +3570,7 @@
 							 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
 							 0,0,2000,1000,
 							 DW_HWND_OBJECT,
-							 NULL,
+							 (HMENU)id,
 							 DWInstance,
 							 &ccs);
 	return hwndframe;
@@ -3589,7 +3589,7 @@
 						WS_CHILD | WS_CLIPCHILDREN,
 						0,0,2000,1000,
 						DW_HWND_OBJECT,
-						NULL,
+						(HMENU)id,
 						DWInstance,
 						NULL);
 }
@@ -3614,7 +3614,7 @@
 					   WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
 					   0,0,2000,1000,
 					   DW_HWND_OBJECT,
-					   NULL,
+					   (HMENU)id,
 					   DWInstance,
 					   NULL);
 	SetWindowLong(tmp, GWL_USERDATA, (ULONG)array);
@@ -4221,7 +4221,7 @@
 							(vertical ? TBS_VERT : TBS_HORZ),
 							0,0,2000,1000,
 							DW_HWND_OBJECT,
-							NULL,
+							(HMENU)id,
 							DWInstance,
 							NULL);
 	ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
@@ -4248,7 +4248,7 @@
 						WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
 						0,0,2000,1000,
 						DW_HWND_OBJECT,
-						NULL,
+						(HMENU)id,
 						DWInstance,
 						NULL);
 }
@@ -4268,7 +4268,7 @@
 							BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE,
 							0,0,2000,1000,
 							DW_HWND_OBJECT,
-							NULL,
+							(HMENU)id,
 							DWInstance,
 							NULL);
 	bubble->id = id;
@@ -4297,7 +4297,7 @@
 							WS_VSCROLL | (multi ? LBS_MULTIPLESEL : 0) ,
 							0,0,2000,1000,
 							DW_HWND_OBJECT,
-							NULL,
+							(HMENU)id,
 							DWInstance,
 							NULL);
 	ContainerInfo *cinfo = (ContainerInfo *)calloc(1, sizeof(ContainerInfo));
@@ -6211,7 +6211,7 @@
 							WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
 							0,0,2000,1000,
 							DW_HWND_OBJECT,
-							NULL,
+							(HMENU)id,
 							DWInstance,
 							NULL);
 	newbox->pad = 0;
@@ -6771,14 +6771,14 @@
  * Returns:
  *       A handle to a splitbar window or NULL on failure.
  */
-HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright)
+HWND dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id)
 {
 	HWND tmp = CreateWindow(SplitbarClassName,
 							"",
 							WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
 							0,0,2000,1000,
 							DW_HWND_OBJECT,
-							NULL,
+							(HMENU)id,
 							DWInstance,
 							NULL);