[gtk+/grid-widget: 2/20] Some api changes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/grid-widget: 2/20] Some api changes
- Date: Fri, 15 Oct 2010 00:04:55 +0000 (UTC)
commit 9f71e3d39717566881904d28ca1295d8c22ff199
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Sep 27 10:45:11 2010 -0400
Some api changes
Move from 'col' to a spelled-out 'column' in the api, and add
a place-next-to API.
gtk/gtkgrid.c | 878 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkgrid.h | 98 +++++++
2 files changed, 976 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c
new file mode 100644
index 0000000..ba8af15
--- /dev/null
+++ b/gtk/gtkgrid.c
@@ -0,0 +1,878 @@
+/* TODO
+ * - size allocation
+ * - wfh
+ * - orientable
+ */
+
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Author: Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "gtkgrid.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+
+
+typedef struct _GtkGridChild GtkGridChild;
+typedef struct _GtkGridRowCol GtkGridRowCol;
+
+struct _GtkGridChild
+{
+ GtkWidget *widget;
+ gint left;
+ gint top;
+ gint width;
+ gint height;
+ gboolean hexpand;
+ gboolean vexpand;
+};
+
+struct _GtkGridRowCol
+{
+ guint requisition;
+ guint allocation;
+ gboolean expand;
+};
+
+struct _GtkGridPrivate
+
+{
+ GList *children;
+
+ GtkGridRowCol *rows;
+ GtkGridRowCol *columns;
+
+ gint min_row, max_row;
+ gint min_column, max_column;
+
+ gint16 row_spacing;
+ gint16 column_spacing;
+
+ guint row_homogeneous : 1;
+ guint column_homogeneous : 1;
+};
+
+enum
+{
+ PROP_0,
+ PROP_ROW_SPACING,
+ PROP_COLUMN_SPACING,
+ PROP_ROW_HOMOGENEOUS,
+ PROP_COLUMN_HOMOGENEOUS
+};
+
+enum
+{
+ CHILD_PROP_0,
+ CHILD_PROP_LEFT_ATTACH,
+ CHILD_PROP_TOP_ATTACH,
+ CHILD_PROP_WIDTH,
+ CHILD_PROP_HEIGHT
+};
+
+G_DEFINE_TYPE (GtkGrid, gtk_grid, GTK_TYPE_CONTAINER);
+
+static void
+gtk_grid_finalize (GObject *object)
+{
+ GtkGrid *grid = GTK_GRID (object);
+ GtkGridPrivate *priv = grid->priv;
+
+ g_free (priv->rows);
+ g_free (priv->cols);
+
+ G_OBJECT_CLASS (gtk_grid_parent_class)->finalize (object);
+}
+
+static void
+gtk_grid_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkGrid *grid = GTK_GRID (object);
+ GtkGridPrivate *priv = grid->priv;
+
+ switch (prop_id)
+ {
+ case PROP_ROW_SPACING:
+ g_value_set_int (value, priv->row_spacing);
+ break;
+
+ case PROP_COLUMN_SPACING:
+ g_value_set_int (value, priv->column_spacing);
+ break;
+
+ case PROP_ROW_HOMOGENEOUS:
+ g_value_set_boolean (value, priv->row_homogeneous);
+ break;
+
+ case PROP_COLUMN_HOMOGENEOUS:
+ g_value_set_boolean (value, priv->column_homogeneous);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_grid_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkGrid *grid = GTK_GRID (object);
+
+ switch (prop_id)
+ {
+ case PROP_ROW_SPACING:
+ gtk_grid_set_row_spacing (grid, g_value_get_int (value));
+ break;
+
+ case PROP_COLUMN_SPACING:
+ gtk_grid_set_column_spacing (grid, g_value_get_int (value));
+ break;
+
+ case PROP_ROW_HOMOGENEOUS:
+ gtk_grid_set_row_homogeneous (grid, g_value_get_boolean (value));
+ break;
+
+ case PROP_COLUMN_HOMOGENEOUS:
+ gtk_grid_set_column_homogeneous (grid, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static GtkGridChild *
+find_grid_child (GtkGrid *grid,
+ GtkWidget *child)
+{
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *grid_child;
+ GList *list;
+
+ for (list = priv->children; list; list = list->next)
+ {
+ grid_child = list->data;
+
+ if (grid_child->widget == child)
+ return grid_child;
+ }
+
+ return NULL;
+}
+
+static void
+gtk_grid_get_child_property (GtkContainer *container,
+ GtkWidget *child,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkGrid *grid = GTK_GRID (container);
+ GtkGridChild *grid_child;
+
+ grid_child = find_grid_child (grid, child);
+
+ if (grid_child == NULL)
+ {
+ GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
+ return;
+ }
+
+ switch (property_id)
+ {
+ case CHILD_PROP_LEFT_ATTACH:
+ g_value_set_int (value, grid_child->left);
+ break;
+
+ case CHILD_PROP_TOP_ATTACH:
+ g_value_set_int (value, grid_child->top);
+ break;
+
+ case CHILD_PROP_WIDTH:
+ g_value_set_int (value, grid_child->width);
+ break;
+
+ case CHILD_PROP_HEIGHT:
+ g_value_set_int (value, grid_child->height);
+ break;
+
+ default:
+ GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_grid_resize (GtkGrid *grid)
+{
+ GtkGridPrivate *priv = grid->priv;
+
+ g_free (priv->rows);
+ g_free (priv->cols);
+ priv->rows = NULL;
+ priv->cols = NULL;
+}
+
+static void
+gtk_grid_set_child_property (GtkContainer *container,
+ GtkWidget *child,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkGrid *grid = GTK_GRID (container);
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *grid_child;
+ gint right, bottom;
+
+ grid_child = find_grid_child (grid, child);
+
+ if (grid_child == NULL)
+ {
+ GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
+ return;
+ }
+
+ switch (property_id)
+ {
+ case CHILD_PROP_LEFT_ATTACH:
+ grid_child->left = g_value_get_int (value);
+ gtk_grid_resize (grid);
+ break;
+
+ case CHILD_PROP_TOP_ATTACH:
+ grid_child->top = g_value_get_int (value);
+ gtk_grid_resize (grid);
+ break;
+
+ case CHILD_PROP_WIDTH:
+ grid_child->width = g_value_get_int (value);
+ gtk_grid_resize (grid);
+ break;
+
+ case CHILD_PROP_HEIGHT:
+ grid_child->height = g_value_get_int (value);
+ gtk_grid_resize (grid);
+ break;
+
+ default:
+ GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
+ break;
+ }
+
+ if (gtk_widget_get_visible (child) &&
+ gtk_widget_get_visible (GTK_WIDGET (grid)))
+ gtk_widget_queue_resize (child);
+}
+
+static void
+gtk_grid_init (GtkGrid *grid)
+{
+ GtkGridPrivate *priv;
+
+ grid->priv = G_TYPE_INSTANCE_GET_PRIVATE (grid, GTK_TYPE_GRID, GtkGridPrivate);
+ priv = grid->priv;
+
+ gtk_widget_set_has_window (GTK_WIDGET (grid), FALSE);
+ gtk_widget_set_redraw_on_allocate (GTK_WIDGET (grid), FALSE);
+
+ priv->children = NULL;
+ priv->rows = NULL;
+ priv->columns = NULL;
+ priv->min_row = 0;
+ priv->max_row = 0;
+ priv->min_column = 0;
+ priv->max_column = 0;
+ priv->row_spacing = 0;
+ priv->column_spacing = 0;
+ priv->row_homogeneous = FALSE;
+ priv->column_homogeneous = FALSE;
+}
+
+static void grid_attach (GtkGrid *grid,
+ GtkWidget *child,
+ gint left,
+ gint top,
+ gint width,
+ gint height);
+
+static void
+gtk_grid_add (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkGrid *grid = GTK_GRID (container);
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *grid_child;
+ GList *list;
+ gint right;
+
+ /* stack horizontally */
+ right = 0;
+ for (list = priv->children; list; list = list->next)
+ {
+ grid_child = list->data;
+
+ if (grid_child->top <= 0 && grid_child->top + grid_child->height > 0)
+ right = MAX (right, grid_child->left + grid_child->width);
+ }
+
+ grid_attach (grid, child, right, 0, 1, 1);
+}
+
+static void
+gtk_grid_remove (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkGrid *grid = GTK_GRID (container);
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *grid_child;
+ GList *list;
+
+ for (list = priv->children; list; list = list->next)
+ {
+ grid_child = list->data;
+
+ if (grid_child->widget == child)
+ {
+ gboolean was_visible = gtk_widget_get_visible (child);
+
+ gtk_widget_unparent (child);
+
+ priv->children = g_list_remove (priv->children, grid_child);
+
+ g_free (grid_child);
+
+ if (was_visible && gtk_widget_get_visible (GTK_WIDGET (grid)))
+ gtk_widget_queue_resize (GTK_WIDGET (grid));
+ break;
+ }
+ }
+}
+
+static void
+gtk_grid_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ GtkGrid *grid = GTK_GRID (container);
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *grid_child;
+ GList *list;
+
+ for (list = priv->children; list; list = list->next)
+ {
+ grid_child = list->data;
+
+ (* callback) (grid_child->widget, callback_data);
+ }
+}
+
+static GType
+gtk_grid_child_type (GtkContainer *container)
+{
+ return GTK_TYPE_WIDGET;
+}
+
+static void
+gtk_grid_allocate_rowcols (GtkGrid *grid)
+{
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *grid_child;
+ GList *list;
+ gint minrow, maxrow, mincol, maxcol;
+
+ if (priv->rows && priv->cols)
+ return;
+
+ minrow = mincol = G_MAXINT;
+ maxrow = maxcol = G_MININT;
+ for (list = priv->children; list; list = list->next)
+ {
+ grid_child = list->data;
+
+ if (grid_child->top < minrow)
+ minrow = grid_child->top;
+
+ if (grid_child->top + grid_child->height > maxrow)
+ maxrow = grid_child->top + grid_child->height;
+
+ if (grid_child->left < mincol)
+ mincol = grid_child->left;
+
+ if (grid_child->left + grid_child->width > maxcol)
+ maxcol = grid_child->left + grid_child->width;
+ }
+
+ priv->min_row = minrow;
+ priv->max_row = maxrow;
+ priv->min_column = mincol;
+ priv->max_column = maxcol;
+
+ priv->rows = g_new (GtkGridRowCol, maxrow - minrow);
+ priv->columns = g_new (GtkGridRowCol, maxcol - mincol);
+}
+
+static void
+gtk_grid_size_request_init (GtkGrid *grid)
+{
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *grid_child;
+ GtkList *list;
+ gint i;
+
+ for (i = 0; i < priv->max_row - priv->min_row; i++)
+ {
+ priv->rows[i].requisition = 0;
+ priv->rows[i].expand = FALSE;
+ }
+
+ for (i = 0; i < priv->max_column - priv->min_column; i++)
+ {
+ priv->cols[i].requisition = 0;
+ priv->cols[i].expand = FALSE;
+ }
+
+ for (list = priv->children; list; list = list->next)
+ {
+ grid_child = children->data;
+
+ if (gtk_widget_get_visible (grid_child->widget))
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (grid_child->widget),
+ NULL, NULL);
+
+ if (grid_child->width == 1 && grid_child->hexpand)
+ priv->cols[grid_child->left - priv->min_column].expand = TRUE;
+
+ if (grid_child->height && child->vexpand)
+ priv->rows[grid_child->top - priv->min_row].expand = TRUE;
+ }
+}
+
+static void
+gtk_table_size_request_pass1 (GtkGrid *grid)
+{
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *child;
+ GList *list;
+ gint width;
+ gint height;
+
+ for (list = priv->children; list; list = list->next)
+ {
+ child = list->data;
+
+ if (gtk_widget_get_visible (child->widget))
+ {
+ GtkRequisition child_requisition;
+
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (child->widget),
+ &child_requisition, NULL);
+
+ /* Child spans a single column. */
+ if (child->width == 1)
+ {
+ width = child_requisition.width;
+ priv->cols[child->left - priv->min_column].requisition = MAX (priv->cols[child->left - priv->min_column].requisition, width);
+ }
+
+ /* Child spans a single row. */
+ if (child->height == 1)
+ {
+ height = child_requisition.height;
+ priv->rows[child->top - priv->min_row].requisition = MAX (priv->rows[child->top - priv->min_row].requisition, height);
+ }
+ }
+ }
+}
+
+static void
+gtk_grid_size_request_pass2 (GtkGrid *grid)
+{
+ GtkGridPrivate *priv = grid->priv;
+ gint size;
+ gint i;
+
+ if (priv->row_homogeneous)
+ {
+ size = 0;
+
+ for (i = 0; i < priv->max_row - priv->min_row; i++)
+ size = MAX (size, priv->rows[i].requisition);
+
+ for (i = 0; i < priv->max_row - priv->min_row; i++)
+ priv->rows[i].requisition = size;
+ }
+
+ if (priv->column_homogeneous)
+ {
+ size = 0;
+
+ for (i = 0; i < priv->max_column - priv->min_column; i++)
+ size = MAX (size, priv->columns[i].requisition);
+
+ for (i = 0; i < priv->max_column - priv->min_column; i++)
+ priv->columns[i].requisition = size;
+ }
+}
+
+
+static void
+gtk_grid_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ GtkGrid *grid = GTK_GRID (widget);
+ GtkGridPrivate *priv = grid->priv;
+ gint row, col;
+ guint border_width;
+
+ requisition->width = 0;
+ requisition->height = 0;
+
+ gtk_grid_allocate_rowcols (grid);
+
+ gtk_grid_size_request_init (grid);
+ gtk_grid_size_request_pass1 (grid);
+ gtk_grid_size_request_pass2 (grid);
+ gtk_grid_size_request_pass3 (grid);
+ gtk_grid_size_request_pass2 (grid);
+
+ for (col = 0; col < priv->max_column - priv->min_column; col++)
+ {
+ requisition->width += priv->columns[col].requisition;
+ if (col > 0)
+ requisition->width += priv->column_spacing;
+ }
+
+ for (row = 0; row < priv->max_row - priv->min_row; row++)
+ {
+ requisition->height += priv->rows[row].requisition;
+ if (row > 0)
+ requisition->width += priv->row_spacing;
+ }
+}
+
+static void
+gtk_grid_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+}
+
+static void
+gtk_grid_class_init (GtkGridClass *class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
+
+ gobject_class->finalize = gtk_grid_finalize;
+
+ gobject_class->get_property = gtk_grid_get_property;
+ gobject_class->set_property = gtk_grid_set_property;
+
+ widget_class->size_request = gtk_grid_size_request;
+ widget_class->size_allocate = gtk_grid_size_allocate;
+
+ container_class->add = gtk_grid_add;
+ container_class->remove = gtk_grid_remove;
+ container_class->forall = gtk_grid_forall;
+ container_class->child_type = gtk_grid_child_type;
+ container_class->set_child_property = gtk_grid_set_child_property;
+ container_class->get_child_property = gtk_grid_get_child_property;
+ gtk_container_class_handle_border_width (container_class);
+
+ g_object_class_install_property (gobject_class, PROP_ROW_SPACING,
+ g_param_spec_int ("row-spacing",
+ P_("Row spacing"),
+ P_("The amount of space between two consecutive rows"),
+ 0, G_MAXINT16, 0,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_COLUMN_SPACING,
+ g_param_spec_int ("column-spacing",
+ P_("Column spacing"),
+ P_("The amount of space between two consecutive columns"),
+ 0, G_MAXINT16, 0,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_ROW_HOMOGENEOUS,
+ g_param_spec_boolean ("row-homogeneous",
+ P_("Row Homogeneous"),
+ P_("If TRUE, the rows are all the same height"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_COLUMN_HOMOGENEOUS,
+ g_param_spec_boolean ("column-homogeneous",
+ P_("Column Homogeneous"),
+ P_("If TRUE, the columns are all the same width"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ gtk_container_class_install_child_property (container_class, CHILD_PROP_LEFT_ATTACH,
+ g_param_spec_int ("left-attach",
+ P_("Left attachment"),
+ P_("The column number to attach the left side of the child to"),
+ G_MININT, G_MAXINT, 0,
+ GTK_PARAM_READWRITE));
+
+ gtk_container_class_install_child_property (container_class, CHILD_PROP_TOP_ATTACH,
+ g_param_spec_int ("top-attach",
+ P_("Top attachment"),
+ P_("The row number to attach the top side of a child widget to"),
+ G_MININT, G_MAXINT, 0,
+ GTK_PARAM_READWRITE));
+
+ gtk_container_class_install_child_property (container_class, CHILD_PROP_WIDTH,
+ g_param_spec_int ("width",
+ P_("Width"),
+ P_("The number of columns that a child spans"),
+ 1, G_MAXINT, 1,
+ GTK_PARAM_READWRITE));
+
+ gtk_container_class_install_child_property (container_class, CHILD_PROP_HEIGHT,
+ g_param_spec_int ("height",
+ P_("Height"),
+ P_("The number of rows that a child spans"),
+ 1, G_MAXINT, 1,
+ GTK_PARAM_READWRITE));
+
+ g_type_class_add_private (class, sizeof (GtkGridPrivate));
+}
+
+GtkWidget *
+gtk_grid_new (void)
+{
+ return (GtkWidget *)g_object_new (GTK_TYPE_GRID, NULL);
+}
+
+staic void
+grid_attach (GtkGrid *grid,
+ GtkWidget *child,
+ gint left,
+ gint top,
+ gint width,
+ gint height)
+{
+ GtkGridPrivate *priv = grid->priv;
+ GtkGridChild *grid_child;
+
+ grid_child = g_new (GtkGridChild, 1);
+ grid_child->widget = child;
+ grid_child->left = left;
+ grid_child->top = top;
+ grid_child->width = width;
+ grid_child->height = height;
+
+ priv->children = g_list_prepend (priv->children, grid_child);
+
+ gtk_widget_set_parent (child, GTK_WIDGET (grid));
+
+ gtk_grid_resize (grid);
+}
+
+void
+gtk_grid_attach (GtkGrid *grid,
+ GtkWidget *child,
+ gint left,
+ gint top,
+ gint width,
+ gint height)
+{
+ GtkGridPrivate *priv;
+ GtkGridChild *grid_child;
+
+ g_return_if_fail (GTK_IS_GRID (grid));
+ g_return_if_fail (GTK_IS_WIDGET (child));
+ g_return_if_fail (gtk_widget_get_parent (child) == NULL);
+ g_return_if_fail (width > 0);
+ g_return_if_fail (height > 0);
+
+ grid_attach (grid, child, left, top, width, height);
+}
+
+void
+gtk_grid_attach_next_to (GtkGrid *grid,
+ GtkWidget *child,
+ GtkWidget *sibling,
+ GtkPositionType side,
+ gint width,
+ gint height)
+{
+ GtkGridPrivate *priv;
+ GtkGridChild *grid_sibling;
+ gint left, top;
+
+ g_return_if_fail (GTK_IS_GRID (grid));
+ g_return_if_fail (GTK_IS_WIDGET (child));
+ g_return_if_fail (gtk_widget_get_parent (child) == NULL);
+ g_return_if_fail (gtk_widget_get_parent (sibling) == grid);
+ g_return_if_fail (width > 0);
+ g_return_if_fail (height > 0);
+
+ grid_sibling = find_grid_child (grid, sibling);
+
+ switch (side)
+ {
+ case GTK_POS_LEFT:
+ left = grid_sibling->left_attach - width;
+ top = grid_sibling->top;
+ break;
+ case GTK_POS_RIGHT:
+ left = grid_sibling->left_attach + grid_sibling->width;
+ top - grid_sibling->top;
+ break;
+ case GTK_POS_TOP:
+ left = grid_sibling->left_attach;
+ top = grid_sibling->top_attach - height;
+ break;
+ case GTK_POS_BOTTOM:
+ left = grid_sibling->left_attach;
+ top = grid_sibling->top_attach + grid_sibling->height;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ grid_attach (grid, child, left, top, width, height);
+}
+
+void
+gtk_grid_set_row_homogeneous (GtkGrid *grid,
+ gboolean homogeneous)
+{
+ GtkGridPrivate *priv;
+ g_return_if_fail (GTK_IS_GRID (grid));
+
+ priv = grid->priv;
+
+ if (priv->row_homogeneous != homogeneous)
+ {
+ priv->row_homogeneous = homogeneous;
+
+ if (gtk_widget_get_visible (GTK_WIDGET (grid)))
+ gtk_widget_queue_resize (GTK_WIDGET (grid));
+
+ g_object_notify (G_OBJECT (grid), "row-homogeneous");
+ }
+}
+
+gboolean
+gtk_grid_get_row_homogeneous (GtkGrid *grid)
+{
+ g_return_val_if_fail (GTK_IS_GRID (grid), FALSE);
+
+ return grid->priv->row_homogeneous;
+}
+
+void
+gtk_grid_set_column_homogeneous (GtkGrid *grid,
+ gboolean homogeneous)
+{
+ GtkGridPrivate *priv;
+ g_return_if_fail (GTK_IS_GRID (grid));
+
+ priv = grid->priv;
+
+ if (priv->col_homogeneous != homogeneous)
+ {
+ priv->col_homogeneous = homogeneous;
+
+ if (gtk_widget_get_visible (GTK_WIDGET (grid)))
+ gtk_widget_queue_resize (GTK_WIDGET (grid));
+
+ g_object_notify (G_OBJECT (grid), "column-homogeneous");
+ }
+}
+
+gboolean
+gtk_grid_get_column_homogeneous (GtkGrid *grid)
+{
+ g_return_val_if_fail (GTK_IS_GRID (grid), FALSE);
+
+ return grid->priv->column_homogeneous;
+}
+
+void
+gtk_grid_set_row_spacing (GtkGrid *grid,
+ guint spacing)
+{
+ GtkGridPrivate *priv;
+ g_return_if_fail (GTK_IS_GRID (grid));
+ g_return_if_fail (spacing <= G_MAXINT16);
+
+ priv = grid->priv;
+
+ if (priv->row_spacing != spacing)
+ {
+ priv->row_spacing = spacing;
+
+ if (gtk_widget_get_visible (GTK_WIDGET (grid)))
+ gtk_widget_queue_resize (GTK_WIDGET (grid));
+
+ g_object_notify (G_OBJECT (grid), "row-spacing");
+ }
+}
+
+guint
+gtk_grid_get_row_spacing (GtkGrid *grid)
+{
+ g_return_val_if_fail (GTK_IS_GRID (grid), 0);
+
+ return grid->priv->row_spacing;
+}
+
+void
+gtk_grid_set_column_spacing (GtkGrid *grid,
+ guint spacing)
+{
+ GtkGridPrivate *priv;
+ g_return_if_fail (GTK_IS_GRID (grid));
+ g_return_if_fail (spacing <= G_MAXINT16);
+
+ priv = grid->priv;
+
+ if (priv->column_spacing != spacing)
+ {
+ priv->col_spacing = spacing;
+
+ if (gtk_widget_get_visible (GTK_WIDGET (grid)))
+ gtk_widget_queue_resize (GTK_WIDGET (grid));
+
+ g_object_notify (G_OBJECT (grid), "column-spacing");
+ }
+}
+
+guint
+gtk_grid_get_column_spacing (GtkGrid *grid)
+{
+ g_return_val_if_fail (GTK_IS_GRID (grid), 0);
+
+ return grid->priv->column_spacing;
+}
diff --git a/gtk/gtkgrid.h b/gtk/gtkgrid.h
new file mode 100644
index 0000000..590d9cd
--- /dev/null
+++ b/gtk/gtkgrid.h
@@ -0,0 +1,98 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Author: Matthias Clasen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_GRID_H__
+#define __GTK_GRID_H__
+
+
+#include <gtk/gtkcontainer.h>
+
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_GRID (gtk_grid_get_type ())
+#define GTK_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_GRID, GtkGrid))
+#define GTK_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_GRID, GtkGridClass))
+#define GTK_IS_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_GRID))
+#define GTK_IS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_GRID))
+#define GTK_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_GRID, GtkGridClass))
+
+
+typedef struct _GtkGrid GtkGrid;
+typedef struct _GtkGridPrivate GtkGridPrivate;
+typedef struct _GtkGridClass GtkGridClass;
+
+struct _GtkGrid
+{
+ /* <private> */
+ GtkContainer container;
+
+ GtkGridPrivate *priv;
+};
+
+struct _GtkGridClass
+{
+ GtkContainerClass parent_class;
+
+ void (*_gtk_reserved1) (void);
+ void (*_gtk_reserved2) (void);
+ void (*_gtk_reserved3) (void);
+ void (*_gtk_reserved4) (void);
+ void (*_gtk_reserved5) (void);
+ void (*_gtk_reserved6) (void);
+ void (*_gtk_reserved7) (void);
+ void (*_gtk_reserved8) (void);
+};
+
+GType gtk_grid_get_type (void) G_GNUC_CONST;
+GtkWidget* gtk_grid_new (void);
+void gtk_grid_attach (GtkGrid *grid,
+ GtkWidget *child,
+ gint left,
+ gint top,
+ gint width,
+ gint height);
+void gtk_grid_attach_next_to (GtkGrid *grid,
+ GtkWidget *widget,
+ GtkWidget *sibling,
+ GtkPositionType side,
+ gint width,
+ gint height);
+void gtk_grid_set_row_homogeneous (GtkGrid *grid,
+ gboolean homogeneous);
+gboolean gtk_grid_get_row_homogeneous (GtkGrid *grid);
+void gtk_grid_set_row_spacing (GtkGrid *grid,
+ guint spacing);
+guint gtk_grid_get_row_spacing (GtkGrid *grid);
+void gtk_grid_set_column_homogeneous (GtkGrid *grid,
+ gboolean homogeneous);
+gboolean gtk_grid_get_column_homogeneous (GtkGrid *grid);
+void gtk_grid_set_column_spacing (GtkGrid *grid,
+ guint spacing);
+guint gtk_grid_get_column_spacing (GtkGrid *grid);
+
+
+G_END_DECLS
+
+#endif /* __GTK_GRID_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]