summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--gtk/gtk.symbols5
-rw-r--r--gtk/gtkhpaned.c187
-rw-r--r--gtk/gtkhpaned.h5
-rw-r--r--gtk/gtkpaned.c344
-rw-r--r--gtk/gtkpaned.h52
-rw-r--r--gtk/gtkvpaned.c175
-rw-r--r--gtk/gtkvpaned.h7
8 files changed, 379 insertions, 411 deletions
diff --git a/ChangeLog b/ChangeLog
index 3a63380428..cbfdb97e07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-11-07 Michael Natterer <mitch@gimp.org>
+
+ Bug 553586 – Add orientation API to GtkPaned
+
+ * gtk/gtkpaned.[ch]: implement the GtkOrientable interface
+ and swallow all code from GtkHPaned and GtkVPaned. Add
+ gtk_paned_new() which takes a GtkOrientation argument. Deprecate
+ gtk_paned_compute_position() for good (also for GTK_COMPILATION).
+
+ * gtk/gtkhpaned.[ch]
+ * gtk/gtkvpaned.[ch]: remove all code except the constructor and
+ call gtk_orientable_set_orientation() in init().
+
+ * gtk/gtk.symbols: add gtk_box_new().
+
2008-11-07 Johan Dahlin <jdahlin@async.com.br>
* gtk/gtkcontainer.c (gtk_container_buildable_add_child):
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index b364de1040..b8f51a55dd 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2592,14 +2592,17 @@ gtk_option_menu_set_menu
#if IN_FILE(__GTK_PANED_C__)
gtk_paned_add1
gtk_paned_add2
-gtk_paned_compute_position
gtk_paned_get_child1
gtk_paned_get_child2
gtk_paned_get_position
gtk_paned_get_type G_GNUC_CONST
+gtk_paned_new
gtk_paned_pack1
gtk_paned_pack2
gtk_paned_set_position
+#ifndef GTK_DISABLE_DEPRECATED
+gtk_paned_compute_position
+#endif
#endif
#endif
diff --git a/gtk/gtkhpaned.c b/gtk/gtkhpaned.c
index f719d3dfed..95afcb72bb 100644
--- a/gtk/gtkhpaned.c
+++ b/gtk/gtkhpaned.c
@@ -21,208 +21,33 @@
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
+
#include "gtkhpaned.h"
-#include "gtkintl.h"
+#include "gtkorientable.h"
#include "gtkalias.h"
-static void gtk_hpaned_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_hpaned_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-
G_DEFINE_TYPE (GtkHPaned, gtk_hpaned, GTK_TYPE_PANED)
static void
gtk_hpaned_class_init (GtkHPanedClass *class)
{
- GtkWidgetClass *widget_class;
-
- widget_class = (GtkWidgetClass *) class;
-
- widget_class->size_request = gtk_hpaned_size_request;
- widget_class->size_allocate = gtk_hpaned_size_allocate;
}
static void
gtk_hpaned_init (GtkHPaned *hpaned)
{
- GtkPaned *paned = GTK_PANED (hpaned);
-
- paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
- paned->orientation = GTK_ORIENTATION_VERTICAL;
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (hpaned),
+ GTK_ORIENTATION_HORIZONTAL);
}
GtkWidget *
gtk_hpaned_new (void)
{
- GtkHPaned *hpaned;
-
- hpaned = g_object_new (GTK_TYPE_HPANED, NULL);
-
- return GTK_WIDGET (hpaned);
-}
-
-static void
-gtk_hpaned_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- GtkPaned *paned = GTK_PANED (widget);
- GtkRequisition child_requisition;
-
- requisition->width = 0;
- requisition->height = 0;
-
- if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
- {
- gtk_widget_size_request (paned->child1, &child_requisition);
-
- requisition->height = child_requisition.height;
- requisition->width = child_requisition.width;
- }
-
- if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
- {
- gtk_widget_size_request (paned->child2, &child_requisition);
-
- requisition->height = MAX(requisition->height, child_requisition.height);
- requisition->width += child_requisition.width;
- }
-
- requisition->width += GTK_CONTAINER (paned)->border_width * 2;
- requisition->height += GTK_CONTAINER (paned)->border_width * 2;
-
- if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
- paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
- {
- gint handle_size;
-
- gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
- requisition->width += handle_size;
- }
-}
-
-static void
-flip_child (GtkWidget *widget, GtkAllocation *child_pos)
-{
- gint x = widget->allocation.x;
- gint width = widget->allocation.width;
-
- child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
-}
-
-static void
-gtk_hpaned_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GtkPaned *paned = GTK_PANED (widget);
- gint border_width = GTK_CONTAINER (paned)->border_width;
-
- widget->allocation = *allocation;
-
- if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
- paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
- {
- GtkAllocation child1_allocation;
- GtkAllocation child2_allocation;
- GtkRequisition child1_requisition;
- GtkRequisition child2_requisition;
- GdkRectangle old_handle_pos;
- gint handle_size;
-
- gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
-
- gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
- gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
-
- gtk_paned_compute_position (paned,
- MAX (1, widget->allocation.width
- - handle_size
- - 2 * border_width),
- child1_requisition.width,
- child2_requisition.width);
-
- old_handle_pos = paned->handle_pos;
-
- paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
- paned->handle_pos.y = widget->allocation.y + border_width;
- paned->handle_pos.width = handle_size;
- paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
-
- child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
- child1_allocation.width = MAX (1, paned->child1_size);
- child1_allocation.x = widget->allocation.x + border_width;
- child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
-
- child2_allocation.x = child1_allocation.x + paned->child1_size + paned->handle_pos.width;
- child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
-
- if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
- {
- flip_child (widget, &(child2_allocation));
- flip_child (widget, &(child1_allocation));
- flip_child (widget, &(paned->handle_pos));
- }
-
- if (GTK_WIDGET_MAPPED (widget) &&
- (old_handle_pos.x != paned->handle_pos.x || old_handle_pos.y != paned->handle_pos.y ||
- old_handle_pos.width != paned->handle_pos.width || old_handle_pos.height != paned->handle_pos.height))
- {
- gdk_window_invalidate_rect (widget->window, &old_handle_pos, FALSE);
- gdk_window_invalidate_rect (widget->window, &paned->handle_pos, FALSE);
- }
-
- if (GTK_WIDGET_REALIZED (widget))
- {
- if (GTK_WIDGET_MAPPED (widget))
- gdk_window_show (paned->handle);
- gdk_window_move_resize (paned->handle,
- paned->handle_pos.x,
- paned->handle_pos.y,
- handle_size,
- paned->handle_pos.height);
- }
-
- /* Now allocate the childen, making sure, when resizing not to
- * overlap the windows
- */
- if (GTK_WIDGET_MAPPED (widget) &&
- paned->child1->allocation.width < child1_allocation.width)
- {
- gtk_widget_size_allocate (paned->child2, &child2_allocation);
- gtk_widget_size_allocate (paned->child1, &child1_allocation);
- }
- else
- {
- gtk_widget_size_allocate (paned->child1, &child1_allocation);
- gtk_widget_size_allocate (paned->child2, &child2_allocation);
- }
- }
- else
- {
- GtkAllocation child_allocation;
-
- if (GTK_WIDGET_REALIZED (widget))
- gdk_window_hide (paned->handle);
-
- if (paned->child1)
- gtk_widget_set_child_visible (paned->child1, TRUE);
- if (paned->child2)
- gtk_widget_set_child_visible (paned->child2, TRUE);
-
- child_allocation.x = widget->allocation.x + border_width;
- child_allocation.y = widget->allocation.y + border_width;
- child_allocation.width = MAX (1, allocation->width - 2 * border_width);
- child_allocation.height = MAX (1, allocation->height - 2 * border_width);
-
- if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
- gtk_widget_size_allocate (paned->child1, &child_allocation);
- else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
- gtk_widget_size_allocate (paned->child2, &child_allocation);
- }
+ return g_object_new (GTK_TYPE_HPANED, NULL);
}
#define __GTK_HPANED_C__
diff --git a/gtk/gtkhpaned.h b/gtk/gtkhpaned.h
index f2c8ad581d..560ea2e3e6 100644
--- a/gtk/gtkhpaned.h
+++ b/gtk/gtkhpaned.h
@@ -56,8 +56,9 @@ struct _GtkHPanedClass
GtkPanedClass parent_class;
};
-GType gtk_hpaned_get_type (void) G_GNUC_CONST;
-GtkWidget *gtk_hpaned_new (void);
+
+GType gtk_hpaned_get_type (void) G_GNUC_CONST;
+GtkWidget * gtk_hpaned_new (void);
G_END_DECLS
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 4f2db528a5..a1ed20c1bc 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -21,22 +21,25 @@
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
-#include "gtkintl.h"
-#include "gtkpaned.h"
-#include "gtkbindings.h"
+
#include "gdk/gdkkeysyms.h"
-#include "gtkwindow.h"
+#include "gtkbindings.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
+#include "gtkorientable.h"
+#include "gtkpaned.h"
+#include "gtkwindow.h"
#include "gtkprivate.h"
+#include "gtkintl.h"
#include "gtkalias.h"
enum {
PROP_0,
+ PROP_ORIENTATION,
PROP_POSITION,
PROP_POSITION_SET,
PROP_MIN_POSITION,
@@ -78,6 +81,11 @@ static void gtk_paned_get_child_property (GtkContainer *container,
GValue *value,
GParamSpec *pspec);
static void gtk_paned_finalize (GObject *object);
+
+static void gtk_paned_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void gtk_paned_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
static void gtk_paned_realize (GtkWidget *widget);
static void gtk_paned_unrealize (GtkWidget *widget);
static void gtk_paned_map (GtkWidget *widget);
@@ -108,6 +116,10 @@ static void gtk_paned_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
+static void gtk_paned_calc_position (GtkPaned *paned,
+ gint allocation,
+ gint child1_req,
+ gint child2_req);
static void gtk_paned_set_focus_child (GtkContainer *container,
GtkWidget *child);
static void gtk_paned_set_saved_focus (GtkPaned *paned,
@@ -134,15 +146,20 @@ static void gtk_paned_grab_notify (GtkWidget *widget,
struct _GtkPanedPrivate
{
- GtkWidget *saved_focus;
- GtkPaned *first_paned;
- guint32 grab_time;
+ GtkOrientation orientation;
+ GtkWidget *saved_focus;
+ GtkPaned *first_paned;
+ guint32 grab_time;
};
-G_DEFINE_ABSTRACT_TYPE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER)
+
+G_DEFINE_TYPE_WITH_CODE (GtkPaned, gtk_paned, GTK_TYPE_CONTAINER,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
+ NULL))
static guint signals[LAST_SIGNAL] = { 0 };
+
static void
add_tab_bindings (GtkBindingSet *binding_set,
GdkModifierType modifiers)
@@ -182,6 +199,8 @@ gtk_paned_class_init (GtkPanedClass *class)
object_class->get_property = gtk_paned_get_property;
object_class->finalize = gtk_paned_finalize;
+ widget_class->size_request = gtk_paned_size_request;
+ widget_class->size_allocate = gtk_paned_size_allocate;
widget_class->realize = gtk_paned_realize;
widget_class->unrealize = gtk_paned_unrealize;
widget_class->map = gtk_paned_map;
@@ -196,7 +215,7 @@ gtk_paned_class_init (GtkPanedClass *class)
widget_class->grab_broken_event = gtk_paned_grab_broken;
widget_class->grab_notify = gtk_paned_grab_notify;
widget_class->state_changed = gtk_paned_state_changed;
-
+
container_class->add = gtk_paned_add;
container_class->remove = gtk_paned_remove;
container_class->forall = gtk_paned_forall;
@@ -212,6 +231,10 @@ gtk_paned_class_init (GtkPanedClass *class)
paned_class->accept_position = gtk_paned_accept_position;
paned_class->cancel_position = gtk_paned_cancel_position;
+ g_object_class_override_property (object_class,
+ PROP_ORIENTATION,
+ "orientation");
+
g_object_class_install_property (object_class,
PROP_POSITION,
g_param_spec_int ("position",
@@ -221,6 +244,7 @@ gtk_paned_class_init (GtkPanedClass *class)
G_MAXINT,
0,
GTK_PARAM_READWRITE));
+
g_object_class_install_property (object_class,
PROP_POSITION_SET,
g_param_spec_boolean ("position-set",
@@ -520,7 +544,7 @@ gtk_paned_class_init (GtkPanedClass *class)
add_move_binding (binding_set, GDK_End, 0, GTK_SCROLL_END);
add_move_binding (binding_set, GDK_KP_End, 0, GTK_SCROLL_END);
- g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
+ g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
}
static GType
@@ -538,9 +562,15 @@ gtk_paned_init (GtkPaned *paned)
GTK_WIDGET_SET_FLAGS (paned, GTK_NO_WINDOW | GTK_CAN_FOCUS);
/* We only need to redraw when the handle position moves, which is
- * independent of the overall allocation of the GtkPaned */
+ * independent of the overall allocation of the GtkPaned
+ */
gtk_widget_set_redraw_on_allocate (GTK_WIDGET (paned), FALSE);
+ paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
+
+ paned->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
+ paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
+
paned->child1 = NULL;
paned->child2 = NULL;
paned->handle = NULL;
@@ -553,7 +583,6 @@ gtk_paned_init (GtkPaned *paned)
paned->last_allocation = -1;
paned->in_drag = FALSE;
- paned->priv = G_TYPE_INSTANCE_GET_PRIVATE (paned, GTK_TYPE_PANED, GtkPanedPrivate);
paned->last_child1_focus = NULL;
paned->last_child2_focus = NULL;
paned->in_recursion = FALSE;
@@ -573,9 +602,22 @@ gtk_paned_set_property (GObject *object,
GParamSpec *pspec)
{
GtkPaned *paned = GTK_PANED (object);
-
+
switch (prop_id)
{
+ case PROP_ORIENTATION:
+ paned->priv->orientation = g_value_get_enum (value);
+ paned->orientation = !paned->priv->orientation;
+
+ if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
+ else
+ paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
+
+ /* state_changed updates the cursor */
+ gtk_paned_state_changed (GTK_WIDGET (paned), GTK_WIDGET (paned)->state);
+ gtk_widget_queue_resize (GTK_WIDGET (paned));
+ break;
case PROP_POSITION:
gtk_paned_set_position (paned, g_value_get_int (value));
break;
@@ -596,9 +638,12 @@ gtk_paned_get_property (GObject *object,
GParamSpec *pspec)
{
GtkPaned *paned = GTK_PANED (object);
-
+
switch (prop_id)
{
+ case PROP_ORIENTATION:
+ g_value_set_enum (value, paned->priv->orientation);
+ break;
case PROP_POSITION:
g_value_set_int (value, paned->child1_size);
break;
@@ -708,6 +753,224 @@ gtk_paned_finalize (GObject *object)
}
static void
+gtk_paned_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ GtkPaned *paned = GTK_PANED (widget);
+ GtkRequisition child_requisition;
+
+ requisition->width = 0;
+ requisition->height = 0;
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
+ {
+ gtk_widget_size_request (paned->child1, &child_requisition);
+
+ requisition->height = child_requisition.height;
+ requisition->width = child_requisition.width;
+ }
+
+ if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ {
+ gtk_widget_size_request (paned->child2, &child_requisition);
+
+ if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ requisition->height = MAX (requisition->height,
+ child_requisition.height);
+ requisition->width += child_requisition.width;
+ }
+ else
+ {
+ requisition->width = MAX (requisition->width,
+ child_requisition.width);
+ requisition->height += child_requisition.height;
+ }
+ }
+
+ requisition->width += GTK_CONTAINER (paned)->border_width * 2;
+ requisition->height += GTK_CONTAINER (paned)->border_width * 2;
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
+ paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ {
+ gint handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+ if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ requisition->width += handle_size;
+ else
+ requisition->height += handle_size;
+ }
+}
+
+static void
+flip_child (GtkWidget *widget,
+ GtkAllocation *child_pos)
+{
+ gint x = widget->allocation.x;
+ gint width = widget->allocation.width;
+
+ child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
+}
+
+static void
+gtk_paned_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkPaned *paned = GTK_PANED (widget);
+ gint border_width = GTK_CONTAINER (paned)->border_width;
+
+ widget->allocation = *allocation;
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
+ paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ {
+ GtkRequisition child1_requisition;
+ GtkRequisition child2_requisition;
+ GtkAllocation child1_allocation;
+ GtkAllocation child2_allocation;
+ GdkRectangle old_handle_pos;
+ gint handle_size;
+
+ gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
+
+ gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
+ gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
+
+ old_handle_pos = paned->handle_pos;
+
+ if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gtk_paned_compute_position (paned,
+ MAX (1, widget->allocation.width
+ - handle_size
+ - 2 * border_width),
+ child1_requisition.width,
+ child2_requisition.width);
+
+ paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
+ paned->handle_pos.y = widget->allocation.y + border_width;
+ paned->handle_pos.width = handle_size;
+ paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
+
+ child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
+ child1_allocation.width = MAX (1, paned->child1_size);
+ child1_allocation.x = widget->allocation.x + border_width;
+ child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
+
+ child2_allocation.x = child1_allocation.x + paned->child1_size + paned->handle_pos.width;
+ child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
+
+ if (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL)
+ {
+ flip_child (widget, &(child2_allocation));
+ flip_child (widget, &(child1_allocation));
+ flip_child (widget, &(paned->handle_pos));
+ }
+ }
+ else
+ {
+ gtk_paned_compute_position (paned,
+ MAX (1, widget->allocation.height
+ - handle_size
+ - 2 * border_width),
+ child1_requisition.height,
+ child2_requisition.height);
+
+ paned->handle_pos.x = widget->allocation.x + border_width;
+ paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
+ paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
+ paned->handle_pos.height = handle_size;
+
+ child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
+ child1_allocation.height = MAX (1, paned->child1_size);
+ child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
+ child1_allocation.y = widget->allocation.y + border_width;
+
+ child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
+ child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
+ }
+
+ if (GTK_WIDGET_MAPPED (widget) &&
+ (old_handle_pos.x != paned->handle_pos.x ||
+ old_handle_pos.y != paned->handle_pos.y ||
+ old_handle_pos.width != paned->handle_pos.width ||
+ old_handle_pos.height != paned->handle_pos.height))
+ {
+ gdk_window_invalidate_rect (widget->window, &old_handle_pos, FALSE);
+ gdk_window_invalidate_rect (widget->window, &paned->handle_pos, FALSE);
+ }
+
+ if (GTK_WIDGET_REALIZED (widget))
+ {
+ if (GTK_WIDGET_MAPPED (widget))
+ gdk_window_show (paned->handle);
+
+ if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gdk_window_move_resize (paned->handle,
+ paned->handle_pos.x,
+ paned->handle_pos.y,
+ handle_size,
+ paned->handle_pos.height);
+ }
+ else
+ {
+ gdk_window_move_resize (paned->handle,
+ paned->handle_pos.x,
+ paned->handle_pos.y,
+ paned->handle_pos.width,
+ handle_size);
+ }
+ }
+
+ /* Now allocate the childen, making sure, when resizing not to
+ * overlap the windows
+ */
+ if (GTK_WIDGET_MAPPED (widget) &&
+
+ ((paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
+ paned->child1->allocation.width < child1_allocation.width) ||
+
+ (paned->priv->orientation == GTK_ORIENTATION_VERTICAL &&
+ paned->child1->allocation.height < child1_allocation.height)))
+ {
+ gtk_widget_size_allocate (paned->child2, &child2_allocation);
+ gtk_widget_size_allocate (paned->child1, &child1_allocation);
+ }
+ else
+ {
+ gtk_widget_size_allocate (paned->child1, &child1_allocation);
+ gtk_widget_size_allocate (paned->child2, &child2_allocation);
+ }
+ }
+ else
+ {
+ GtkAllocation child_allocation;
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gdk_window_hide (paned->handle);
+
+ if (paned->child1)
+ gtk_widget_set_child_visible (paned->child1, TRUE);
+ if (paned->child2)
+ gtk_widget_set_child_visible (paned->child2, TRUE);
+
+ child_allocation.x = widget->allocation.x + border_width;
+ child_allocation.y = widget->allocation.y + border_width;
+ child_allocation.width = MAX (1, allocation->width - 2 * border_width);
+ child_allocation.height = MAX (1, allocation->height - 2 * border_width);
+
+ if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
+ gtk_widget_size_allocate (paned->child1, &child_allocation);
+ else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
+ gtk_widget_size_allocate (paned->child2, &child_allocation);
+ }
+}
+
+static void
gtk_paned_realize (GtkWidget *widget)
{
GtkPaned *paned;
@@ -824,7 +1087,7 @@ gtk_paned_expose (GtkWidget *widget,
&paned->handle_pos, widget, "paned",
paned->handle_pos.x, paned->handle_pos.y,
paned->handle_pos.width, paned->handle_pos.height,
- paned->orientation);
+ !paned->priv->orientation);
}
/* Chain up to draw children */
@@ -836,7 +1099,7 @@ gtk_paned_expose (GtkWidget *widget,
static gboolean
is_rtl (GtkPaned *paned)
{
- if (paned->orientation == GTK_ORIENTATION_VERTICAL &&
+ if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (GTK_WIDGET (paned)) == GTK_TEXT_DIR_RTL)
{
return TRUE;
@@ -851,11 +1114,11 @@ update_drag (GtkPaned *paned)
gint pos;
gint handle_size;
gint size;
-
- if (paned->orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_widget_get_pointer (GTK_WIDGET (paned), NULL, &pos);
- else
+
+ if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
gtk_widget_get_pointer (GTK_WIDGET (paned), &pos, NULL);
+ else
+ gtk_widget_get_pointer (GTK_WIDGET (paned), NULL, &pos);
pos -= paned->drag_pos;
@@ -964,11 +1227,11 @@ gtk_paned_button_press (GtkWidget *widget,
paned->in_drag = TRUE;
paned->priv->grab_time = event->time;
- if (paned->orientation == GTK_ORIENTATION_HORIZONTAL)
- paned->drag_pos = event->y;
- else
+ if (paned->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
paned->drag_pos = event->x;
-
+ else
+ paned->drag_pos = event->y;
+
return TRUE;
}
@@ -1061,6 +1324,24 @@ gtk_paned_motion (GtkWidget *widget,
return FALSE;
}
+/**
+ * gtk_paned_new:
+ * @orientation: the paned's orientation.
+ *
+ * Creates a new #GtkPaned widget.
+ *
+ * Return value: a new #GtkPaned.
+ *
+ * Since: 2.16
+ **/
+GtkWidget *
+gtk_paned_new (GtkOrientation orientation)
+{
+ return g_object_new (GTK_TYPE_PANED,
+ "orientation", orientation,
+ NULL);
+}
+
void
gtk_paned_add1 (GtkPaned *paned,
GtkWidget *widget)
@@ -1289,11 +1570,20 @@ gtk_paned_compute_position (GtkPaned *paned,
gint child1_req,
gint child2_req)
{
+ g_return_if_fail (GTK_IS_PANED (paned));
+
+ gtk_paned_calc_position (paned, allocation, child1_req, child2_req);
+}
+
+static void
+gtk_paned_calc_position (GtkPaned *paned,
+ gint allocation,
+ gint child1_req,
+ gint child2_req)
+{
gint old_position;
gint old_min_position;
gint old_max_position;
-
- g_return_if_fail (GTK_IS_PANED (paned));
old_position = paned->child1_size;
old_min_position = paned->min_position;
diff --git a/gtk/gtkpaned.h b/gtk/gtkpaned.h
index f816105986..a1c774d913 100644
--- a/gtk/gtkpaned.h
+++ b/gtk/gtkpaned.h
@@ -1,4 +1,3 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
@@ -107,34 +106,35 @@ struct _GtkPanedClass
};
-GType gtk_paned_get_type (void) G_GNUC_CONST;
-void gtk_paned_add1 (GtkPaned *paned,
- GtkWidget *child);
-void gtk_paned_add2 (GtkPaned *paned,
- GtkWidget *child);
-void gtk_paned_pack1 (GtkPaned *paned,
- GtkWidget *child,
- gboolean resize,
- gboolean shrink);
-void gtk_paned_pack2 (GtkPaned *paned,
- GtkWidget *child,
- gboolean resize,
- gboolean shrink);
-gint gtk_paned_get_position (GtkPaned *paned);
-void gtk_paned_set_position (GtkPaned *paned,
- gint position);
-
-GtkWidget *gtk_paned_get_child1 (GtkPaned *paned);
-GtkWidget *gtk_paned_get_child2 (GtkPaned *paned);
+GType gtk_paned_get_type (void) G_GNUC_CONST;
+GtkWidget * gtk_paned_new (GtkOrientation orientation);
+void gtk_paned_add1 (GtkPaned *paned,
+ GtkWidget *child);
+void gtk_paned_add2 (GtkPaned *paned,
+ GtkWidget *child);
+void gtk_paned_pack1 (GtkPaned *paned,
+ GtkWidget *child,
+ gboolean resize,
+ gboolean shrink);
+void gtk_paned_pack2 (GtkPaned *paned,
+ GtkWidget *child,
+ gboolean resize,
+ gboolean shrink);
+
+gint gtk_paned_get_position (GtkPaned *paned);
+void gtk_paned_set_position (GtkPaned *paned,
+ gint position);
+
+GtkWidget * gtk_paned_get_child1 (GtkPaned *paned);
+GtkWidget * gtk_paned_get_child2 (GtkPaned *paned);
+
+#ifndef GTK_DISABLE_DEPRECATED
/* Internal function */
-#if !defined (GTK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION)
void gtk_paned_compute_position (GtkPaned *paned,
- gint allocation,
- gint child1_req,
- gint child2_req);
-#endif /* !GTK_DISABLE_DEPRECATED || GTK_COMPILATION */
-#ifndef GTK_DISABLE_DEPRECATED
+ gint allocation,
+ gint child1_req,
+ gint child2_req);
#define gtk_paned_gutter_size(p,s) (void) 0
#define gtk_paned_set_gutter_size(p,s) (void) 0
#endif /* GTK_DISABLE_DEPRECATED */
diff --git a/gtk/gtkvpaned.c b/gtk/gtkvpaned.c
index 3b11db6d34..42bba68ede 100644
--- a/gtk/gtkvpaned.c
+++ b/gtk/gtkvpaned.c
@@ -21,196 +21,33 @@
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
+
+#include "gtkorientable.h"
#include "gtkvpaned.h"
-#include "gtkintl.h"
#include "gtkalias.h"
-static void gtk_vpaned_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_vpaned_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-
G_DEFINE_TYPE (GtkVPaned, gtk_vpaned, GTK_TYPE_PANED)
static void
gtk_vpaned_class_init (GtkVPanedClass *class)
{
- GtkWidgetClass *widget_class;
-
- widget_class = (GtkWidgetClass *) class;
-
- widget_class->size_request = gtk_vpaned_size_request;
- widget_class->size_allocate = gtk_vpaned_size_allocate;
}
static void
gtk_vpaned_init (GtkVPaned *vpaned)
{
- GtkPaned *paned;
-
- g_return_if_fail (GTK_IS_PANED (vpaned));
-
- paned = GTK_PANED (vpaned);
-
- paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
- paned->orientation = GTK_ORIENTATION_HORIZONTAL;
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (vpaned),
+ GTK_ORIENTATION_VERTICAL);
}
GtkWidget *
gtk_vpaned_new (void)
{
- GtkVPaned *vpaned;
-
- vpaned = g_object_new (GTK_TYPE_VPANED, NULL);
-
- return GTK_WIDGET (vpaned);
-}
-
-static void
-gtk_vpaned_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- GtkPaned *paned = GTK_PANED (widget);
- GtkRequisition child_requisition;
-
- requisition->width = 0;
- requisition->height = 0;
-
- if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
- {
- gtk_widget_size_request (paned->child1, &child_requisition);
-
- requisition->height = child_requisition.height;
- requisition->width = child_requisition.width;
- }
-
- if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
- {
- gtk_widget_size_request (paned->child2, &child_requisition);
-
- requisition->width = MAX (requisition->width, child_requisition.width);
- requisition->height += child_requisition.height;
- }
-
- requisition->height += GTK_CONTAINER (paned)->border_width * 2;
- requisition->width += GTK_CONTAINER (paned)->border_width * 2;
-
- if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
- paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
- {
- gint handle_size;
-
- gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
- requisition->height += handle_size;
- }
-}
-
-static void
-gtk_vpaned_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GtkPaned *paned = GTK_PANED (widget);
- gint border_width = GTK_CONTAINER (paned)->border_width;
-
- widget->allocation = *allocation;
-
- if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
- paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
- {
- GtkRequisition child1_requisition;
- GtkRequisition child2_requisition;
- GtkAllocation child1_allocation;
- GtkAllocation child2_allocation;
- GdkRectangle old_handle_pos;
- gint handle_size;
-
- gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
-
- gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
- gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
-
- gtk_paned_compute_position (paned,
- MAX (1, widget->allocation.height
- - handle_size
- - 2 * border_width),
- child1_requisition.height,
- child2_requisition.height);
-
- old_handle_pos = paned->handle_pos;
-
- paned->handle_pos.x = widget->allocation.x + border_width;
- paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
- paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
- paned->handle_pos.height = handle_size;
-
- if (GTK_WIDGET_MAPPED (widget) &&
- (old_handle_pos.x != paned->handle_pos.x || old_handle_pos.y != paned->handle_pos.y ||
- old_handle_pos.width != paned->handle_pos.width || old_handle_pos.height != paned->handle_pos.height))
- {
- gdk_window_invalidate_rect (widget->window, &old_handle_pos, FALSE);
- gdk_window_invalidate_rect (widget->window, &paned->handle_pos, FALSE);
- }
-
- if (GTK_WIDGET_REALIZED (widget))
- {
- if (GTK_WIDGET_MAPPED (widget))
- gdk_window_show (paned->handle);
- gdk_window_move_resize (paned->handle,
- paned->handle_pos.x,
- paned->handle_pos.y,
- paned->handle_pos.width,
- handle_size);
- }
-
- child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
- child1_allocation.height = MAX (1, paned->child1_size);
- child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
- child1_allocation.y = widget->allocation.y + border_width;
-
- child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
- child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
-
- /* Now allocate the childen, making sure, when resizing not to
- * overlap the windows
- */
- if (GTK_WIDGET_MAPPED (widget) &&
- paned->child1->allocation.height < child1_allocation.height)
- {
- gtk_widget_size_allocate (paned->child2, &child2_allocation);
- gtk_widget_size_allocate (paned->child1, &child1_allocation);
- }
- else
- {
- gtk_widget_size_allocate (paned->child1, &child1_allocation);
- gtk_widget_size_allocate (paned->child2, &child2_allocation);
- }
- }
- else
- {
- GtkAllocation child_allocation;
-
- if (GTK_WIDGET_REALIZED (widget))
- gdk_window_hide (paned->handle);
-
- if (paned->child1)
- gtk_widget_set_child_visible (paned->child1, TRUE);
- if (paned->child2)
- gtk_widget_set_child_visible (paned->child2, TRUE);
-
- child_allocation.x = widget->allocation.x + border_width;
- child_allocation.y = widget->allocation.y + border_width;
- child_allocation.width = MAX (1, allocation->width - 2 * border_width);
- child_allocation.height = MAX (1, allocation->height - 2 * border_width);
-
- if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
- gtk_widget_size_allocate (paned->child1, &child_allocation);
- else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
- gtk_widget_size_allocate (paned->child2, &child_allocation);
- }
+ return g_object_new (GTK_TYPE_VPANED, NULL);
}
#define __GTK_VPANED_C__
diff --git a/gtk/gtkvpaned.h b/gtk/gtkvpaned.h
index 37bc52a082..49a1aec48b 100644
--- a/gtk/gtkvpaned.h
+++ b/gtk/gtkvpaned.h
@@ -33,10 +33,8 @@
#include <gtk/gtkpaned.h>
-
G_BEGIN_DECLS
-
#define GTK_TYPE_VPANED (gtk_vpaned_get_type ())
#define GTK_VPANED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_VPANED, GtkVPaned))
#define GTK_VPANED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_VPANED, GtkVPanedClass))
@@ -58,11 +56,10 @@ struct _GtkVPanedClass
GtkPanedClass parent_class;
};
-GType gtk_vpaned_get_type (void) G_GNUC_CONST;
-GtkWidget *gtk_vpaned_new (void);
+GType gtk_vpaned_get_type (void) G_GNUC_CONST;
+GtkWidget * gtk_vpaned_new (void);
G_END_DECLS
-
#endif /* __GTK_VPANED_H__ */