[glade/ui-incubator: 9/11] Removed GladeFixed (DnD) support for GtkBox, GtkTable and GtkGrid. Optimized glade_gtk_grid_refresh_
- From: Juan Pablo Ugarte <jpu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade/ui-incubator: 9/11] Removed GladeFixed (DnD) support for GtkBox, GtkTable and GtkGrid. Optimized glade_gtk_grid_refresh_
- Date: Thu, 17 Jan 2013 22:16:21 +0000 (UTC)
commit 9f598e966adcd4f438064edff8696b61e52d8a58
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date: Mon Dec 17 22:31:21 2012 -0300
Removed GladeFixed (DnD) support for GtkBox, GtkTable and GtkGrid.
Optimized glade_gtk_grid_refresh_placeholders() by passing the children list to
glade_gtk_grid_has_child() instead of getting it each time from the container.
plugins/gtk+/glade-gtk-grid.c | 417 +++----------------------------------
plugins/gtk+/glade-gtk-table.c | 453 +---------------------------------------
plugins/gtk+/glade-gtk.c | 224 --------------------
plugins/gtk+/gtk+.xml.in | 5 -
4 files changed, 30 insertions(+), 1069 deletions(-)
---
diff --git a/plugins/gtk+/glade-gtk-grid.c b/plugins/gtk+/glade-gtk-grid.c
index 87e38cc..05259bf 100644
--- a/plugins/gtk+/glade-gtk-grid.c
+++ b/plugins/gtk+/glade-gtk-grid.c
@@ -55,9 +55,6 @@ typedef enum
DIR_RIGHT
} GladeGridDir;
-static GladeGridChild grid_edit = { 0, };
-static GladeGridChild grid_cur_attach = { 0, };
-
static void
glade_gtk_grid_get_child_attachments (GtkWidget *grid,
GtkWidget *child,
@@ -71,354 +68,6 @@ glade_gtk_grid_get_child_attachments (GtkWidget *grid,
NULL);
}
-/* Takes a point (x or y depending on 'row') relative to
- * grid, and returns the row or column in which the point
- * was found.
- */
-static gint
-glade_gtk_grid_get_row_col_from_point (GtkGrid * grid,
- gboolean row, gint point)
-{
- GladeGridAttachments attach;
- GtkAllocation allocation;
- GList *list, *children;
- gint span, trans_point, size, base, end;
-
- children = gtk_container_get_children (GTK_CONTAINER (grid));
-
- for (list = children; list; list = list->next)
- {
- GtkWidget *widget = list->data;
-
- glade_gtk_grid_get_child_attachments (GTK_WIDGET (grid), widget, &attach);
-
- if (row)
- gtk_widget_translate_coordinates (GTK_WIDGET (grid), widget, 0, point, NULL, &trans_point);
- else
- gtk_widget_translate_coordinates (GTK_WIDGET (grid), widget, point, 0, &trans_point, NULL);
-
- gtk_widget_get_allocation (widget, &allocation);
-
- /* Find any widget in our row/column
- */
- end = row ? allocation.height : allocation.width;
-
- if (trans_point >= 0 &&
- /* should be trans_point < end ... test FIXME ! */
- trans_point < end)
- {
- base = row ? attach.top_attach : attach.left_attach;
- size = row ? allocation.height : allocation.width;
- span = row ? attach.height : attach.width;
-
- return base + (trans_point * span / size);
- }
- }
-
- g_list_free (children);
-
- return -1;
-}
-
-
-static gboolean
-glade_gtk_grid_point_crosses_threshold (GtkGrid *grid,
- gboolean row,
- gint num,
- GladeGridDir dir,
- gint point)
-{
- GladeGridAttachments attach;
- GtkAllocation allocation;
- GList *list, *children;
- gint span, trans_point, size, rowcol_size, base;
-
- children = gtk_container_get_children (GTK_CONTAINER (grid));
-
- for (list = children; list; list = list->next)
- {
- GtkWidget *widget = list->data;
-
- glade_gtk_grid_get_child_attachments (GTK_WIDGET (grid), widget, &attach);
-
- /* Find any widget in our row/column
- */
- if ((row && num >= attach.top_attach && num < attach.top_attach + attach.height) ||
- (!row && num >= attach.left_attach && num < attach.left_attach + attach.width))
- {
-
- if (row)
- gtk_widget_translate_coordinates (GTK_WIDGET (grid), widget, 0, point, NULL, &trans_point);
- else
- gtk_widget_translate_coordinates (GTK_WIDGET (grid), widget, point, 0, &trans_point, NULL);
-
- span = row ? attach.height : attach.width;
- gtk_widget_get_allocation (widget, &allocation);
- size = row ? allocation.height : allocation.width;
-
- base = row ? attach.top_attach : attach.left_attach;
- rowcol_size = size / span;
- trans_point -= (num - base) * rowcol_size;
-
-#if 0
- g_print ("dir: %s, widget size: %d, rowcol size: %d, "
- "requested rowcol: %d, widget base rowcol: %d, trim: %d, "
- "widget point: %d, thresh: %d\n",
- dir == DIR_UP ? "up" : dir == DIR_DOWN ? "down" :
- dir == DIR_LEFT ? "left" : "right",
- size, rowcol_size, num, base, (num - base) * rowcol_size,
- trans_point,
- dir == DIR_UP || dir == DIR_LEFT ?
- (rowcol_size / 2) : (rowcol_size / 2));
-#endif
- switch (dir)
- {
- case DIR_UP:
- case DIR_LEFT:
- return trans_point <= (rowcol_size / 2);
- case DIR_DOWN:
- case DIR_RIGHT:
- return trans_point >= (rowcol_size / 2);
- default:
- break;
- }
- }
-
- }
-
- g_list_free (children);
-
- return FALSE;
-}
-
-static gboolean
-glade_gtk_grid_get_attachments (GladeFixed *fixed,
- GtkGrid *grid,
- GdkRectangle *rect,
- GladeGridChild *configure)
-{
- GladeWidget *widget = GLADE_WIDGET (fixed);
- gint center_x, center_y, row, column;
- guint n_columns, n_rows;
-
- center_x = rect->x + (rect->width / 2);
- center_y = rect->y + (rect->height / 2);
-
- column = glade_gtk_grid_get_row_col_from_point (grid, FALSE, center_x);
- row = glade_gtk_grid_get_row_col_from_point (grid, TRUE, center_y);
-
- /* its a start, now try to grow when the rect extents
- * reach at least half way into the next row/column
- */
- configure->left_attach = column;
- configure->width = 1;
- configure->top_attach = row;
- configure->height = 1;
-
- glade_widget_property_get (widget, "n-columns", &n_columns);
- glade_widget_property_get (widget, "n-rows", &n_rows);
-
- if (column >= 0 && row >= 0)
- {
- /* Check and expand left
- */
- while (configure->left_attach > 0)
- {
- if (rect->x < fixed->child_x_origin &&
- fixed->operation != GLADE_CURSOR_DRAG &&
- GLADE_FIXED_CURSOR_LEFT (fixed->operation) == FALSE)
- break;
-
- if (glade_gtk_grid_point_crosses_threshold
- (grid, FALSE, configure->left_attach - 1,
- DIR_LEFT, rect->x) == FALSE)
- break;
-
- configure->left_attach--;
- }
-
- /* Check and expand right
- */
- while (configure->left_attach + configure->width < n_columns)
- {
- if (rect->x + rect->width >
- fixed->child_x_origin + fixed->child_width_origin &&
- fixed->operation != GLADE_CURSOR_DRAG &&
- GLADE_FIXED_CURSOR_RIGHT (fixed->operation) == FALSE)
- break;
-
- if (glade_gtk_grid_point_crosses_threshold
- (grid, FALSE, configure->left_attach + configure->width,
- DIR_RIGHT, rect->x + rect->width) == FALSE)
- break;
-
- configure->width++;
- }
-
- /* Check and expand top
- */
- while (configure->top_attach > 0)
- {
- if (rect->y < fixed->child_y_origin &&
- fixed->operation != GLADE_CURSOR_DRAG &&
- GLADE_FIXED_CURSOR_TOP (fixed->operation) == FALSE)
- break;
-
- if (glade_gtk_grid_point_crosses_threshold
- (grid, TRUE, configure->top_attach - 1,
- DIR_UP, rect->y) == FALSE)
- break;
-
- configure->top_attach--;
- }
-
- /* Check and expand bottom
- */
- while (configure->top_attach + configure->height < n_rows)
- {
- if (rect->y + rect->height >
- fixed->child_y_origin + fixed->child_height_origin &&
- fixed->operation != GLADE_CURSOR_DRAG &&
- GLADE_FIXED_CURSOR_BOTTOM (fixed->operation) == FALSE)
- break;
-
- if (glade_gtk_grid_point_crosses_threshold
- (grid, TRUE, configure->top_attach + configure->height,
- DIR_DOWN, rect->y + rect->height) == FALSE)
- break;
-
- configure->height++;
- }
- }
-
- return column >= 0 && row >= 0;
-}
-
-static gboolean
-glade_gtk_grid_configure_child (GladeFixed * fixed,
- GladeWidget * child,
- GdkRectangle * rect, GtkWidget * grid)
-{
- GladeGridChild configure = { child, };
-
- /* Sometimes we are unable to find a widget in the appropriate column,
- * usually because a placeholder hasnt had its size allocation yet.
- */
- if (glade_gtk_grid_get_attachments (fixed, GTK_GRID (grid), rect, &configure))
- {
- if (memcmp (&configure, &grid_cur_attach, sizeof (GladeGridChild)) != 0)
- {
-
- glade_property_push_superuser ();
- glade_widget_pack_property_set (child, "left-attach",
- configure.left_attach);
- glade_widget_pack_property_set (child, "width",
- configure.width);
- glade_widget_pack_property_set (child, "top-attach",
- configure.top_attach);
- glade_widget_pack_property_set (child, "height",
- configure.height);
- glade_property_pop_superuser ();
-
- memcpy (&grid_cur_attach, &configure, sizeof (GladeGridChild));
- }
- }
- return TRUE;
-}
-
-
-static gboolean
-glade_gtk_grid_configure_begin (GladeFixed * fixed,
- GladeWidget * child, GtkWidget * grid)
-{
- grid_edit.widget = child;
-
- glade_widget_pack_property_get (child, "left-attach", &grid_edit.left_attach);
- glade_widget_pack_property_get (child, "width", &grid_edit.width);
- glade_widget_pack_property_get (child, "top-attach", &grid_edit.top_attach);
- glade_widget_pack_property_get (child, "height", &grid_edit.height);
-
- memcpy (&grid_cur_attach, &grid_edit, sizeof (GladeGridChild));
-
- return TRUE;
-}
-
-static gboolean
-glade_gtk_grid_configure_end (GladeFixed * fixed,
- GladeWidget * child, GtkWidget * grid)
-{
- GladeGridChild new_child = { child, };
-
- glade_widget_pack_property_get (child, "left-attach", &new_child.left_attach);
- glade_widget_pack_property_get (child, "width", &new_child.width);
- glade_widget_pack_property_get (child, "top-attach", &new_child.top_attach);
- glade_widget_pack_property_get (child, "height", &new_child.height);
-
- /* Compare the meaningfull part of the current edit. */
- if (memcmp (&new_child, &grid_edit, sizeof (GladeGridChild)) != 0)
- {
- GValue left_attach_value = { 0, };
- GValue width_attach_value = { 0, };
- GValue top_attach_value = { 0, };
- GValue height_attach_value = { 0, };
-
- GValue new_left_attach_value = { 0, };
- GValue new_width_attach_value = { 0, };
- GValue new_top_attach_value = { 0, };
- GValue new_height_attach_value = { 0, };
-
- GladeProperty *left_attach_prop, *width_attach_prop,
- *top_attach_prop, *height_attach_prop;
-
- left_attach_prop = glade_widget_get_pack_property (child, "left-attach");
- width_attach_prop = glade_widget_get_pack_property (child, "width");
- top_attach_prop = glade_widget_get_pack_property (child, "top-attach");
- height_attach_prop = glade_widget_get_pack_property (child, "height");
-
- g_return_val_if_fail (GLADE_IS_PROPERTY (left_attach_prop), FALSE);
- g_return_val_if_fail (GLADE_IS_PROPERTY (width_attach_prop), FALSE);
- g_return_val_if_fail (GLADE_IS_PROPERTY (top_attach_prop), FALSE);
- g_return_val_if_fail (GLADE_IS_PROPERTY (height_attach_prop), FALSE);
-
- glade_property_get_value (left_attach_prop, &new_left_attach_value);
- glade_property_get_value (width_attach_prop, &new_width_attach_value);
- glade_property_get_value (top_attach_prop, &new_top_attach_value);
- glade_property_get_value (height_attach_prop, &new_height_attach_value);
-
- g_value_init (&left_attach_value, G_TYPE_INT);
- g_value_init (&width_attach_value, G_TYPE_INT);
- g_value_init (&top_attach_value, G_TYPE_INT);
- g_value_init (&height_attach_value, G_TYPE_INT);
-
- g_value_set_int (&left_attach_value, grid_edit.left_attach);
- g_value_set_int (&width_attach_value, grid_edit.width);
- g_value_set_int (&top_attach_value, grid_edit.top_attach);
- g_value_set_int (&height_attach_value, grid_edit.height);
-
- glade_command_push_group (_("Placing %s inside %s"),
- glade_widget_get_name (child),
- glade_widget_get_name (GLADE_WIDGET (fixed)));
- glade_command_set_properties
- (left_attach_prop, &left_attach_value, &new_left_attach_value,
- width_attach_prop, &width_attach_value, &new_width_attach_value,
- top_attach_prop, &top_attach_value, &new_top_attach_value,
- height_attach_prop, &height_attach_value, &new_height_attach_value,
- NULL);
- glade_command_pop_group ();
-
- g_value_unset (&left_attach_value);
- g_value_unset (&width_attach_value);
- g_value_unset (&top_attach_value);
- g_value_unset (&height_attach_value);
- g_value_unset (&new_left_attach_value);
- g_value_unset (&new_width_attach_value);
- g_value_unset (&new_top_attach_value);
- g_value_unset (&new_height_attach_value);
- }
-
- return TRUE;
-}
-
static void
glade_gtk_grid_parse_finished (GladeProject *project, GObject *container)
{
@@ -456,15 +105,6 @@ glade_gtk_grid_post_create (GladeWidgetAdaptor * adaptor,
{
GladeWidget *gwidget = glade_widget_get_from_gobject (container);
- g_signal_connect (G_OBJECT (gwidget), "configure-child",
- G_CALLBACK (glade_gtk_grid_configure_child), container);
-
- g_signal_connect (G_OBJECT (gwidget), "configure-begin",
- G_CALLBACK (glade_gtk_grid_configure_begin), container);
-
- g_signal_connect (G_OBJECT (gwidget), "configure-end",
- G_CALLBACK (glade_gtk_grid_configure_end), container);
-
if (reason == GLADE_CREATE_LOAD)
g_signal_connect (glade_widget_get_project (gwidget), "parse-finished",
G_CALLBACK (glade_gtk_grid_parse_finished),
@@ -472,13 +112,13 @@ glade_gtk_grid_post_create (GladeWidgetAdaptor * adaptor,
}
static gboolean
-glade_gtk_grid_has_child (GtkGrid * grid, guint left_attach,
- guint top_attach)
+glade_gtk_grid_has_child (GtkGrid *grid,
+ GList *children,
+ guint left_attach,
+ guint top_attach)
{
- GList *list, *children;
gboolean ret = FALSE;
-
- children = gtk_container_get_children (GTK_CONTAINER (grid));
+ GList *list;
for (list = children; list && list->data; list = list->next)
{
@@ -495,8 +135,6 @@ glade_gtk_grid_has_child (GtkGrid * grid, guint left_attach,
}
}
- g_list_free (children);
-
return ret;
}
@@ -531,34 +169,38 @@ glade_gtk_grid_widget_exceeds_bounds (GtkGrid *grid, gint n_rows, gint n_cols)
}
static void
-glade_gtk_grid_refresh_placeholders (GtkGrid * grid)
+glade_gtk_grid_refresh_placeholders (GtkGrid *grid)
{
GladeWidget *widget;
+ GtkContainer *container;
GList *list, *children;
guint n_columns, n_rows;
gint i, j;
- widget = glade_widget_get_from_gobject (GTK_WIDGET (grid));
+ widget = glade_widget_get_from_gobject (grid);
glade_widget_property_get (widget, "n-columns", &n_columns);
glade_widget_property_get (widget, "n-rows", &n_rows);
- children = gtk_container_get_children (GTK_CONTAINER (grid));
+ container = GTK_CONTAINER (grid);
+ children = gtk_container_get_children (container);
for (list = children; list && list->data; list = list->next)
{
- if (GLADE_IS_PLACEHOLDER (list->data))
- gtk_container_remove (GTK_CONTAINER (grid), GTK_WIDGET (list->data));
+ GtkWidget *child = list->data;
+ if (GLADE_IS_PLACEHOLDER (child))
+ gtk_container_remove (container, child);
}
g_list_free (children);
+ children = gtk_container_get_children (container);
+
for (i = 0; i < n_columns; i++)
for (j = 0; j < n_rows; j++)
- if (glade_gtk_grid_has_child (grid, i, j) == FALSE)
- {
- gtk_grid_attach (grid, glade_placeholder_new (),
- i, j, 1, 1);
- }
- gtk_container_check_resize (GTK_CONTAINER (grid));
+ if (glade_gtk_grid_has_child (grid, children, i, j) == FALSE)
+ gtk_grid_attach (grid, glade_placeholder_new (), i, j, 1, 1);
+
+ gtk_container_check_resize (container);
+ g_list_free (children);
}
static void
@@ -609,20 +251,20 @@ glade_gtk_grid_remove_child (GladeWidgetAdaptor * adaptor,
}
void
-glade_gtk_grid_replace_child (GladeWidgetAdaptor * adaptor,
- GtkWidget * container,
- GtkWidget * current, GtkWidget * new_widget)
+glade_gtk_grid_replace_child (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *current,
+ GObject *new_widget)
{
g_return_if_fail (GTK_IS_GRID (container));
g_return_if_fail (GTK_IS_WIDGET (current));
g_return_if_fail (GTK_IS_WIDGET (new_widget));
/* Chain Up */
- GWA_GET_CLASS
- (GTK_TYPE_CONTAINER)->replace_child (adaptor,
- G_OBJECT (container),
- G_OBJECT (current),
- G_OBJECT (new_widget));
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->replace_child (adaptor,
+ container,
+ current,
+ new_widget);
/* If we are replacing a GladeWidget, we must refresh placeholders
* because the widget may have spanned multiple rows/columns, we must
@@ -631,9 +273,8 @@ glade_gtk_grid_replace_child (GladeWidgetAdaptor * adaptor,
* (since the remaining placeholder templates no longer exist, only the
* first pasted widget would have proper packing properties).
*/
- if (glade_widget_get_from_gobject (new_widget) == NULL)
+ if (!GLADE_IS_PLACEHOLDER (new_widget))
glade_gtk_grid_refresh_placeholders (GTK_GRID (container));
-
}
static void
diff --git a/plugins/gtk+/glade-gtk-table.c b/plugins/gtk+/glade-gtk-table.c
index e61193b..f93893c 100644
--- a/plugins/gtk+/glade-gtk-table.c
+++ b/plugins/gtk+/glade-gtk-table.c
@@ -47,9 +47,6 @@ typedef enum
DIR_RIGHT
} GladeTableDir;
-static GladeGtkTableChild table_edit = { 0, };
-static GladeGtkTableChild table_cur_attach = { 0, };
-
static void
glade_gtk_table_get_child_attachments (GtkWidget * table,
GtkWidget * child,
@@ -70,454 +67,6 @@ glade_gtk_table_get_child_attachments (GtkWidget * table,
tchild->bottom_attach = bottom;
}
-
-/* Takes a point (x or y depending on 'row') relative to
- * table, and returns the row or column in which the point
- * was found.
- */
-static gint
-glade_gtk_table_get_row_col_from_point (GtkTable * table,
- gboolean row, gint point)
-{
- GtkTableChild tchild;
- GtkAllocation allocation;
- GList *list, *children;
- gint span, trans_point, size, base, end;
-
- children = gtk_container_get_children (GTK_CONTAINER (table));
-
- for (list = children; list; list = list->next)
- {
- glade_gtk_table_get_child_attachments (GTK_WIDGET (table),
- GTK_WIDGET (list->data), &tchild);
-
- if (row)
- gtk_widget_translate_coordinates
- (GTK_WIDGET (table), tchild.widget, 0, point, NULL, &trans_point);
- else
- gtk_widget_translate_coordinates
- (GTK_WIDGET (table), tchild.widget, point, 0, &trans_point, NULL);
-
- gtk_widget_get_allocation (tchild.widget, &allocation);
- /* Find any widget in our row/column
- */
- end = row ? allocation.height : allocation.width;
-
- if (trans_point >= 0 &&
- /* should be trans_point < end ... test FIXME ! */
- trans_point < end)
- {
- base = row ? tchild.top_attach : tchild.left_attach;
- size = row ? allocation.height : allocation.width;
- span = row ? (tchild.bottom_attach - tchild.top_attach) :
- (tchild.right_attach - tchild.left_attach);
-
- return base + (trans_point * span / size);
- }
- }
- g_list_free (children);
-
- return -1;
-}
-
-
-static gboolean
-glade_gtk_table_point_crosses_threshold (GtkTable * table,
- gboolean row,
- gint num,
- GladeTableDir dir, gint point)
-{
-
- GtkTableChild tchild;
- GtkAllocation allocation;
- GList *list, *children;
- gint span, trans_point, size, rowcol_size, base;
-
- children = gtk_container_get_children (GTK_CONTAINER (table));
-
- for (list = children; list; list = list->next)
- {
- glade_gtk_table_get_child_attachments (GTK_WIDGET (table),
- GTK_WIDGET (list->data), &tchild);
-
- /* Find any widget in our row/column
- */
- if ((row && num >= tchild.top_attach && num < tchild.bottom_attach) ||
- (!row && num >= tchild.left_attach && num < tchild.right_attach))
- {
-
- if (row)
- gtk_widget_translate_coordinates
- (GTK_WIDGET (table), tchild.widget,
- 0, point, NULL, &trans_point);
- else
- gtk_widget_translate_coordinates
- (GTK_WIDGET (table), tchild.widget,
- point, 0, &trans_point, NULL);
-
- span = row ? (tchild.bottom_attach - tchild.top_attach) :
- (tchild.right_attach - tchild.left_attach);
- gtk_widget_get_allocation (tchild.widget, &allocation);
- size = row ? allocation.height : allocation.width;
-
- base = row ? tchild.top_attach : tchild.left_attach;
- rowcol_size = size / span;
- trans_point -= (num - base) * rowcol_size;
-
-#if 0
- g_print ("dir: %s, widget size: %d, rowcol size: %d, "
- "requested rowcol: %d, widget base rowcol: %d, trim: %d, "
- "widget point: %d, thresh: %d\n",
- dir == DIR_UP ? "up" : dir == DIR_DOWN ? "down" :
- dir == DIR_LEFT ? "left" : "right",
- size, rowcol_size, num, base, (num - base) * rowcol_size,
- trans_point,
- dir == DIR_UP || dir == DIR_LEFT ?
- (rowcol_size / 2) : (rowcol_size / 2));
-#endif
- switch (dir)
- {
- case DIR_UP:
- case DIR_LEFT:
- return trans_point <= (rowcol_size / 2);
- case DIR_DOWN:
- case DIR_RIGHT:
- return trans_point >= (rowcol_size / 2);
- default:
- break;
- }
- }
-
- }
-
- g_list_free (children);
-
- return FALSE;
-}
-
-static gboolean
-glade_gtk_table_get_attachments (GladeFixed * fixed,
- GtkTable * table,
- GdkRectangle * rect,
- GladeGtkTableChild * configure)
-{
- gint center_x, center_y, row, column;
- guint n_columns, n_rows;
- center_x = rect->x + (rect->width / 2);
- center_y = rect->y + (rect->height / 2);
-
- column = glade_gtk_table_get_row_col_from_point (table, FALSE, center_x);
-
- row = glade_gtk_table_get_row_col_from_point (table, TRUE, center_y);
-
- /* its a start, now try to grow when the rect extents
- * reach at least half way into the next row/column
- */
- configure->left_attach = column;
- configure->right_attach = column + 1;
- configure->top_attach = row;
- configure->bottom_attach = row + 1;
-
- if (column >= 0 && row >= 0)
- {
-
- g_object_get (table, "n-columns", &n_columns, "n-rows", &n_rows, NULL);
-
- /* Check and expand left
- */
- while (configure->left_attach > 0)
- {
- if (rect->x < fixed->child_x_origin &&
- fixed->operation != GLADE_CURSOR_DRAG &&
- GLADE_FIXED_CURSOR_LEFT (fixed->operation) == FALSE)
- break;
-
- if (glade_gtk_table_point_crosses_threshold
- (table, FALSE, configure->left_attach - 1,
- DIR_LEFT, rect->x) == FALSE)
- break;
-
- configure->left_attach--;
- }
-
- /* Check and expand right
- */
- while (configure->right_attach < n_columns)
- {
- if (rect->x + rect->width >
- fixed->child_x_origin + fixed->child_width_origin &&
- fixed->operation != GLADE_CURSOR_DRAG &&
- GLADE_FIXED_CURSOR_RIGHT (fixed->operation) == FALSE)
- break;
-
- if (glade_gtk_table_point_crosses_threshold
- (table, FALSE, configure->right_attach,
- DIR_RIGHT, rect->x + rect->width) == FALSE)
- break;
-
- configure->right_attach++;
- }
-
- /* Check and expand top
- */
- while (configure->top_attach > 0)
- {
- if (rect->y < fixed->child_y_origin &&
- fixed->operation != GLADE_CURSOR_DRAG &&
- GLADE_FIXED_CURSOR_TOP (fixed->operation) == FALSE)
- break;
-
- if (glade_gtk_table_point_crosses_threshold
- (table, TRUE, configure->top_attach - 1,
- DIR_UP, rect->y) == FALSE)
- break;
-
- configure->top_attach--;
- }
-
- /* Check and expand bottom
- */
- while (configure->bottom_attach < n_rows)
- {
- if (rect->y + rect->height >
- fixed->child_y_origin + fixed->child_height_origin &&
- fixed->operation != GLADE_CURSOR_DRAG &&
- GLADE_FIXED_CURSOR_BOTTOM (fixed->operation) == FALSE)
- break;
-
- if (glade_gtk_table_point_crosses_threshold
- (table, TRUE, configure->bottom_attach,
- DIR_DOWN, rect->y + rect->height) == FALSE)
- break;
-
- configure->bottom_attach++;
- }
- }
-
- /* Keep the same row/col span when performing a drag
- */
- if (fixed->operation == GLADE_CURSOR_DRAG)
- {
- gint col_span = table_edit.right_attach - table_edit.left_attach;
- gint row_span = table_edit.bottom_attach - table_edit.top_attach;
-
- if (rect->x < fixed->child_x_origin)
- configure->right_attach = configure->left_attach + col_span;
- else
- configure->left_attach = configure->right_attach - col_span;
-
- if (rect->y < fixed->child_y_origin)
- configure->bottom_attach = configure->top_attach + row_span;
- else
- configure->top_attach = configure->bottom_attach - row_span;
- }
- else if (fixed->operation == GLADE_CURSOR_RESIZE_RIGHT)
- {
- configure->left_attach = table_edit.left_attach;
- configure->top_attach = table_edit.top_attach;
- configure->bottom_attach = table_edit.bottom_attach;
- }
- else if (fixed->operation == GLADE_CURSOR_RESIZE_LEFT)
- {
- configure->right_attach = table_edit.right_attach;
- configure->top_attach = table_edit.top_attach;
- configure->bottom_attach = table_edit.bottom_attach;
- }
- else if (fixed->operation == GLADE_CURSOR_RESIZE_TOP)
- {
- configure->left_attach = table_edit.left_attach;
- configure->right_attach = table_edit.right_attach;
- configure->bottom_attach = table_edit.bottom_attach;
- }
- else if (fixed->operation == GLADE_CURSOR_RESIZE_BOTTOM)
- {
- configure->left_attach = table_edit.left_attach;
- configure->right_attach = table_edit.right_attach;
- configure->top_attach = table_edit.top_attach;
- }
-
- return column >= 0 && row >= 0;
-}
-
-static gboolean
-glade_gtk_table_configure_child (GladeFixed * fixed,
- GladeWidget * child,
- GdkRectangle * rect, GtkWidget * table)
-{
- GladeGtkTableChild configure = { child, };
-
- /* Sometimes we are unable to find a widget in the appropriate column,
- * usually because a placeholder hasnt had its size allocation yet.
- */
- if (glade_gtk_table_get_attachments
- (fixed, GTK_TABLE (table), rect, &configure))
- {
- if (memcmp (&configure, &table_cur_attach, sizeof (GladeGtkTableChild)) != 0)
- {
-
- glade_property_push_superuser ();
- glade_widget_pack_property_set (child, "left-attach",
- configure.left_attach);
- glade_widget_pack_property_set (child, "right-attach",
- configure.right_attach);
- glade_widget_pack_property_set (child, "top-attach",
- configure.top_attach);
- glade_widget_pack_property_set (child, "bottom-attach",
- configure.bottom_attach);
- glade_property_pop_superuser ();
-
- memcpy (&table_cur_attach, &configure, sizeof (GladeGtkTableChild));
- }
- }
- return TRUE;
-}
-
-
-static gboolean
-glade_gtk_table_configure_begin (GladeFixed * fixed,
- GladeWidget * child, GtkWidget * table)
-{
-
- table_edit.widget = child;
-
- glade_widget_pack_property_get (child, "left-attach",
- &table_edit.left_attach);
- glade_widget_pack_property_get (child, "right-attach",
- &table_edit.right_attach);
- glade_widget_pack_property_get (child, "top-attach", &table_edit.top_attach);
- glade_widget_pack_property_get (child, "bottom-attach",
- &table_edit.bottom_attach);
-
- memcpy (&table_cur_attach, &table_edit, sizeof (GladeGtkTableChild));
-
- return TRUE;
-}
-
-static gboolean
-glade_gtk_table_configure_end (GladeFixed * fixed,
- GladeWidget * child, GtkWidget * table)
-{
- GladeGtkTableChild new_child = { child, };
-
- glade_widget_pack_property_get (child, "left-attach", &new_child.left_attach);
- glade_widget_pack_property_get (child, "right-attach",
- &new_child.right_attach);
- glade_widget_pack_property_get (child, "top-attach", &new_child.top_attach);
- glade_widget_pack_property_get (child, "bottom-attach",
- &new_child.bottom_attach);
-
- /* Compare the meaningfull part of the current edit. */
- if (memcmp (&new_child, &table_edit, sizeof (GladeGtkTableChild)) != 0)
- {
- GValue left_attach_value = { 0, };
- GValue right_attach_value = { 0, };
- GValue top_attach_value = { 0, };
- GValue bottom_attach_value = { 0, };
-
- GValue new_left_attach_value = { 0, };
- GValue new_right_attach_value = { 0, };
- GValue new_top_attach_value = { 0, };
- GValue new_bottom_attach_value = { 0, };
-
- GladeProperty *left_attach_prop, *right_attach_prop,
- *top_attach_prop, *bottom_attach_prop;
-
- left_attach_prop = glade_widget_get_pack_property (child, "left-attach");
- right_attach_prop =
- glade_widget_get_pack_property (child, "right-attach");
- top_attach_prop = glade_widget_get_pack_property (child, "top-attach");
- bottom_attach_prop =
- glade_widget_get_pack_property (child, "bottom-attach");
-
- g_return_val_if_fail (GLADE_IS_PROPERTY (left_attach_prop), FALSE);
- g_return_val_if_fail (GLADE_IS_PROPERTY (right_attach_prop), FALSE);
- g_return_val_if_fail (GLADE_IS_PROPERTY (top_attach_prop), FALSE);
- g_return_val_if_fail (GLADE_IS_PROPERTY (bottom_attach_prop), FALSE);
-
- glade_property_get_value (left_attach_prop, &new_left_attach_value);
- glade_property_get_value (right_attach_prop, &new_right_attach_value);
- glade_property_get_value (top_attach_prop, &new_top_attach_value);
- glade_property_get_value (bottom_attach_prop, &new_bottom_attach_value);
-
- g_value_init (&left_attach_value, G_TYPE_UINT);
- g_value_init (&right_attach_value, G_TYPE_UINT);
- g_value_init (&top_attach_value, G_TYPE_UINT);
- g_value_init (&bottom_attach_value, G_TYPE_UINT);
-
- g_value_set_uint (&left_attach_value, table_edit.left_attach);
- g_value_set_uint (&right_attach_value, table_edit.right_attach);
- g_value_set_uint (&top_attach_value, table_edit.top_attach);
- g_value_set_uint (&bottom_attach_value, table_edit.bottom_attach);
-
- glade_command_push_group (_("Placing %s inside %s"),
- glade_widget_get_name (child),
- glade_widget_get_name (GLADE_WIDGET (fixed)));
- glade_command_set_properties
- (left_attach_prop, &left_attach_value, &new_left_attach_value,
- right_attach_prop, &right_attach_value, &new_right_attach_value,
- top_attach_prop, &top_attach_value, &new_top_attach_value,
- bottom_attach_prop, &bottom_attach_value, &new_bottom_attach_value,
- NULL);
- glade_command_pop_group ();
-
- g_value_unset (&left_attach_value);
- g_value_unset (&right_attach_value);
- g_value_unset (&top_attach_value);
- g_value_unset (&bottom_attach_value);
- g_value_unset (&new_left_attach_value);
- g_value_unset (&new_right_attach_value);
- g_value_unset (&new_top_attach_value);
- g_value_unset (&new_bottom_attach_value);
- }
-
- return TRUE;
-}
-
-void
-glade_gtk_table_post_create (GladeWidgetAdaptor * adaptor,
- GObject * container, GladeCreateReason reason)
-{
- GladeWidget *gwidget = glade_widget_get_from_gobject (container);
-
- g_signal_connect (G_OBJECT (gwidget), "configure-child",
- G_CALLBACK (glade_gtk_table_configure_child), container);
-
- g_signal_connect (G_OBJECT (gwidget), "configure-begin",
- G_CALLBACK (glade_gtk_table_configure_begin), container);
-
- g_signal_connect (G_OBJECT (gwidget), "configure-end",
- G_CALLBACK (glade_gtk_table_configure_end), container);
-}
-
-static gboolean
-glade_gtk_table_has_child (GtkTable * table, guint left_attach,
- guint top_attach)
-{
- GList *list, *children;
- gboolean ret = FALSE;
-
- children = gtk_container_get_children (GTK_CONTAINER (table));
-
- for (list = children; list && list->data; list = list->next)
- {
- GtkTableChild child;
-
- glade_gtk_table_get_child_attachments (GTK_WIDGET (table),
- GTK_WIDGET (list->data), &child);
-
- if (left_attach >= child.left_attach && left_attach < child.right_attach
- && top_attach >= child.top_attach && top_attach < child.bottom_attach)
- {
- ret = TRUE;
- break;
- }
- }
-
- g_list_free (children);
-
- return ret;
-}
-
static gboolean
glade_gtk_table_widget_exceeds_bounds (GtkTable * table, gint n_rows,
gint n_cols)
@@ -697,7 +246,7 @@ glade_gtk_table_replace_child (GladeWidgetAdaptor * adaptor,
* (since the remaining placeholder templates no longer exist, only the
* first pasted widget would have proper packing properties).
*/
- if (glade_widget_get_from_gobject (new_widget) == NULL)
+ if (!GLADE_IS_PLACEHOLDER (new_widget))
glade_gtk_table_refresh_placeholders (GTK_TABLE (container));
}
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 510c592..f095994 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -1447,230 +1447,6 @@ glade_gtk_create_fixed_widget (GladeWidgetAdaptor * adaptor,
first_property_name, var_args);
}
-typedef struct
-{
- GtkWidget *widget;
- gint position;
-} GladeGtkBoxChild;
-
-static GList *glade_gtk_box_original_positions = NULL;
-
-static gboolean
-glade_gtk_box_configure_child (GladeFixed * fixed,
- GladeWidget * child,
- GdkRectangle * rect, GtkWidget * box)
-{
- GList *list, *children;
- GtkWidget *bchild;
- GtkAllocation allocation, bchild_allocation;
- gint point, trans_point, span,
- iter_span, position, old_position, offset, orig_offset;
- gboolean found = FALSE;
-
- gtk_widget_get_allocation (GTK_WIDGET (glade_widget_get_object (child)), &allocation);
- if (GTK_IS_HBOX (box) || GTK_IS_HBUTTON_BOX (box))
- {
- point = fixed->mouse_x;
- span = allocation.width;
- offset = rect->x;
- orig_offset = fixed->child_x_origin;
- }
- else
- {
- point = fixed->mouse_y;
- span = allocation.height;
- offset = rect->y;
- orig_offset = fixed->child_y_origin;
- }
-
- glade_widget_pack_property_get (child, "position", &old_position);
-
- children = gtk_container_get_children (GTK_CONTAINER (box));
-
- for (list = children; list; list = list->next)
- {
- bchild = list->data;
-
- if (bchild == GTK_WIDGET (glade_widget_get_object (child)))
- continue;
-
- /* Find the widget in the box where the center of
- * this rectangle fits... and set the position to that
- * position.
- */
-
- gtk_widget_get_allocation (GTK_WIDGET (bchild), &bchild_allocation);
- if (GTK_IS_HBOX (box) || GTK_IS_HBUTTON_BOX (box))
- {
- gtk_widget_translate_coordinates
- (GTK_WIDGET (box), bchild, point, 0, &trans_point, NULL);
-
- iter_span = bchild_allocation.width;
- }
- else
- {
- gtk_widget_translate_coordinates
- (GTK_WIDGET (box), bchild, 0, point, NULL, &trans_point);
- iter_span = bchild_allocation.height;
- }
-
-#if 0
- gtk_container_child_get (GTK_CONTAINER (box),
- bchild, "position", &position, NULL);
- g_print ("widget: %p pos %d, point %d, trans_point %d, iter_span %d\n",
- bchild, position, point, trans_point, iter_span);
-#endif
-
- if (iter_span <= span)
- {
- found = trans_point >= 0 && trans_point < iter_span;
- }
- else
- {
- if (offset > orig_offset)
- found = trans_point >= iter_span - span && trans_point < iter_span;
- else if (offset < orig_offset)
- found = trans_point >= 0 && trans_point < span;
- }
-
- if (found)
- {
- gtk_container_child_get (GTK_CONTAINER (box),
- bchild, "position", &position, NULL);
-
-#if 0
- g_print ("setting position of %s from %d to %d, "
- "(point %d iter_span %d)\n",
- child->name, old_position, position, trans_point, iter_span);
-#endif
-
- glade_widget_pack_property_set (child, "position", position);
-
- break;
- }
-
- }
-
- g_list_free (children);
-
- return TRUE;
-}
-
-static gboolean
-glade_gtk_box_configure_begin (GladeFixed * fixed,
- GladeWidget * child, GtkWidget * box)
-{
- GList *list, *children;
- GtkWidget *bchild;
-
- g_assert (glade_gtk_box_original_positions == NULL);
-
- children = gtk_container_get_children (GTK_CONTAINER (box));
-
- for (list = children; list; list = list->next)
- {
- GladeGtkBoxChild *gbchild;
- GladeWidget *gchild;
-
- bchild = list->data;
- if ((gchild = glade_widget_get_from_gobject (bchild)) == NULL)
- continue;
-
- gbchild = g_new0 (GladeGtkBoxChild, 1);
- gbchild->widget = bchild;
- glade_widget_pack_property_get (gchild, "position", &gbchild->position);
-
- glade_gtk_box_original_positions =
- g_list_prepend (glade_gtk_box_original_positions, gbchild);
- }
-
- g_list_free (children);
-
- return TRUE;
-}
-
-static gboolean
-glade_gtk_box_configure_end (GladeFixed * fixed,
- GladeWidget * child, GtkWidget * box)
-{
- GList *list, *l, *children;
- GList *prop_list = NULL;
-
- children = gtk_container_get_children (GTK_CONTAINER (box));
-
- for (list = children; list; list = list->next)
- {
- GtkWidget *bchild = list->data;
-
- for (l = glade_gtk_box_original_positions; l; l = l->next)
- {
- GladeGtkBoxChild *gbchild = l->data;
- GladeWidget *gchild = glade_widget_get_from_gobject (gbchild->widget);
-
-
- if (bchild == gbchild->widget)
- {
- GCSetPropData *prop_data = g_new0 (GCSetPropData, 1);
- prop_data->property =
- glade_widget_get_pack_property (gchild, "position");
-
- prop_data->old_value = g_new0 (GValue, 1);
- prop_data->new_value = g_new0 (GValue, 1);
-
- glade_property_get_value (prop_data->property,
- prop_data->new_value);
-
- g_value_init (prop_data->old_value, G_TYPE_INT);
- g_value_set_int (prop_data->old_value, gbchild->position);
-
- prop_list = g_list_prepend (prop_list, prop_data);
- break;
- }
- }
- }
-
- g_list_free (children);
-
- glade_command_push_group (_("Ordering children of %s"),
- glade_widget_get_name (GLADE_WIDGET (fixed)));
- glade_property_push_superuser ();
- if (prop_list)
- glade_command_set_properties_list (glade_widget_get_project (GLADE_WIDGET (fixed)),
- prop_list);
- glade_property_pop_superuser ();
- glade_command_pop_group ();
-
- for (l = glade_gtk_box_original_positions; l; l = l->next)
- g_free (l->data);
-
- glade_gtk_box_original_positions =
- (g_list_free (glade_gtk_box_original_positions), NULL);
-
-
- return TRUE;
-}
-
-void
-glade_gtk_box_post_create (GladeWidgetAdaptor * adaptor,
- GObject * container, GladeCreateReason reason)
-{
- GladeWidget *gwidget = glade_widget_get_from_gobject (container);
-
- /* Implement drag in GtkBox but not resize.
- */
- g_object_set (gwidget, "can-resize", FALSE, NULL);
-
- g_signal_connect (G_OBJECT (gwidget), "configure-child",
- G_CALLBACK (glade_gtk_box_configure_child), container);
-
- g_signal_connect (G_OBJECT (gwidget), "configure-begin",
- G_CALLBACK (glade_gtk_box_configure_begin), container);
-
- g_signal_connect (G_OBJECT (gwidget), "configure-end",
- G_CALLBACK (glade_gtk_box_configure_end), container);
-
-}
-
static gint
sort_box_children (GtkWidget * widget_a, GtkWidget * widget_b)
{
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 52b6405..1252862 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -320,8 +320,6 @@ embedded in another object</_tooltip>
</glade-widget-class>
<glade-widget-class name="GtkBox" generic-name="box" _title="Box">
- <create-widget-function>glade_gtk_create_fixed_widget</create-widget-function>
- <post-create-function>glade_gtk_box_post_create</post-create-function>
<get-children-function>glade_gtk_box_get_children</get-children-function>
<set-property-function>glade_gtk_box_set_property</set-property-function>
<get-property-function>glade_gtk_box_get_property</get-property-function>
@@ -1419,8 +1417,6 @@ embedded in another object</_tooltip>
</glade-widget-class>
<glade-widget-class name="GtkTable" generic-name="table" _title="Table">
- <create-widget-function>glade_gtk_create_fixed_widget</create-widget-function>
- <post-create-function>glade_gtk_table_post_create</post-create-function>
<child-set-property-function>glade_gtk_table_set_child_property</child-set-property-function>
<child-verify-function>glade_gtk_table_child_verify_property</child-verify-function>
<get-children-function>glade_gtk_table_get_children</get-children-function>
@@ -1464,7 +1460,6 @@ embedded in another object</_tooltip>
</glade-widget-class>
<glade-widget-class name="GtkGrid" generic-name="grid" _title="Grid">
- <create-widget-function>glade_gtk_create_fixed_widget</create-widget-function>
<post-create-function>glade_gtk_grid_post_create</post-create-function>
<child-set-property-function>glade_gtk_grid_set_child_property</child-set-property-function>
<child-verify-function>glade_gtk_grid_child_verify_property</child-verify-function>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]