summaryrefslogtreecommitdiff
path: root/gtk/gtkpaned.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>1998-12-15 17:56:31 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-12-15 17:56:31 +0000
commitcceabe57ba5f083b9f7ffc276050bf3634cc7af4 (patch)
tree252c4465bf0b3875fc3ffae3cfa08d40da8ea5cc /gtk/gtkpaned.c
parent1bf27c357d69d4a23eaccdb9aeab168f49e98cd7 (diff)
downloadgtk+-cceabe57ba5f083b9f7ffc276050bf3634cc7af4.tar.gz
Fixed up some warnings.
Tue Dec 15 11:37:05 1998 Owen Taylor <otaylor@redhat.com> * gtk/gtkmain.c: Fixed up some warnings. Tue Dec 15 10:32:01 1998 Owen Taylor <otaylor@redhat.com> * gtk/gtk{h,v,}paned.{c,h}: Add new functions gtk_paned_set_position(), gtk_paned_pack1/2(). The latter take a shrink and resize parameters, that allows setting minimum sizes and getting 'relative' resizing.
Diffstat (limited to 'gtk/gtkpaned.c')
-rw-r--r--gtk/gtkpaned.c94
1 files changed, 92 insertions, 2 deletions
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index d679982b80..a55a6e5e60 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -113,6 +113,7 @@ gtk_paned_init (GtkPaned *paned)
paned->handle_size = 10;
paned->gutter_size = 6;
paned->position_set = FALSE;
+ paned->last_allocation = -1;
paned->in_drag = FALSE;
paned->handle_xpos = -1;
@@ -287,6 +288,24 @@ void
gtk_paned_add1 (GtkPaned *paned,
GtkWidget *widget)
{
+ gtk_paned_pack1 (paned, widget, FALSE, TRUE);
+}
+
+void
+gtk_paned_add2 (GtkPaned *paned,
+ GtkWidget *widget)
+{
+ gtk_paned_pack2 (paned, widget, TRUE, TRUE);
+}
+
+void
+gtk_paned_pack1 (GtkPaned *paned,
+ GtkWidget *widget,
+ gboolean resize,
+ gboolean shrink)
+{
+ g_return_if_fail (paned != NULL);
+ g_return_if_fail (GTK_IS_PANED (paned));
g_return_if_fail (widget != NULL);
if (!paned->child1)
@@ -305,6 +324,8 @@ gtk_paned_add1 (GtkPaned *paned,
}
paned->child1 = widget;
+ paned->child1_resize = resize;
+ paned->child1_shrink = shrink;
if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (paned))
gtk_widget_queue_resize (widget);
@@ -312,9 +333,13 @@ gtk_paned_add1 (GtkPaned *paned,
}
void
-gtk_paned_add2 (GtkPaned *paned,
- GtkWidget *widget)
+gtk_paned_pack2 (GtkPaned *paned,
+ GtkWidget *widget,
+ gboolean resize,
+ gboolean shrink)
{
+ g_return_if_fail (paned != NULL);
+ g_return_if_fail (GTK_IS_PANED (paned));
g_return_if_fail (widget != NULL);
if (!paned->child2)
@@ -333,6 +358,8 @@ gtk_paned_add2 (GtkPaned *paned,
}
paned->child2 = widget;
+ paned->child2_resize = resize;
+ paned->child2_shrink = shrink;
if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (paned))
gtk_widget_queue_resize (widget);
@@ -412,6 +439,26 @@ gtk_paned_forall (GtkContainer *container,
}
void
+gtk_paned_set_position (GtkPaned *paned,
+ gint position)
+{
+ g_return_if_fail (paned != NULL);
+ g_return_if_fail (GTK_IS_PANED (paned));
+
+ if (position >= 0)
+ {
+ paned->child1_size = CLAMP (position,
+ paned->min_position,
+ paned->max_position);
+ paned->position_set = TRUE;
+ }
+ else
+ paned->position_set = FALSE;
+
+ gtk_widget_queue_resize (GTK_WIDGET (paned));
+}
+
+void
gtk_paned_set_handle_size (GtkPaned *paned,
guint16 size)
{
@@ -443,3 +490,46 @@ gtk_paned_set_gutter_size (GtkPaned *paned,
if (GTK_WIDGET_VISIBLE (GTK_WIDGET (paned)))
gtk_widget_queue_resize (GTK_WIDGET (paned));
}
+
+void
+gtk_paned_compute_position (GtkPaned *paned,
+ gint allocation,
+ gint child1_req,
+ gint child2_req)
+{
+ g_return_if_fail (paned != NULL);
+ g_return_if_fail (GTK_IS_PANED (paned));
+
+ paned->min_position = paned->child1_shrink ? 0 : child1_req;
+
+ paned->max_position = allocation;
+ if (!paned->child2_shrink)
+ paned->max_position -= child2_req;
+
+ if (!paned->position_set)
+ {
+ if (paned->child1_resize && !paned->child2_resize)
+ paned->child1_size = allocation - child2_req;
+ else if (!paned->child1_resize && paned->child2_resize)
+ paned->child1_size = child1_req;
+ else
+ paned->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req));
+ }
+ else
+ {
+ if (paned->last_allocation < 0)
+ paned->last_allocation = allocation;
+
+ if (paned->child1_resize && !paned->child2_resize)
+ paned->child1_size += (allocation - paned->last_allocation);
+ else if (!(!paned->child1_resize && paned->child2_resize))
+ paned->child1_size = allocation * ((gdouble)paned->child1_size / (paned->last_allocation));
+ }
+
+ paned->child1_size = CLAMP (paned->child1_size,
+ paned->min_position,
+ paned->max_position);
+
+ paned->last_allocation = allocation;
+
+}