summaryrefslogtreecommitdiff
path: root/gladeui/glade-design-view.c
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <jp@synctv.com>2011-01-31 18:22:24 -0300
committerJuan Pablo Ugarte <jp@synctv.com>2011-01-31 18:22:24 -0300
commit38d12938b286e3326827c2b2ce719acb7a555b97 (patch)
tree0a8dc292afe3a70f6a788a2806d11a393a87be8c /gladeui/glade-design-view.c
parent0f48965b596e93b0276703915e549caa4f4479a6 (diff)
downloadglade-38d12938b286e3326827c2b2ce719acb7a555b97.tar.gz
* gladeui/glade-design-layout.c:
o implemented get_preferred_width_for_height() and get_preferred_width_for_height() to fix allocation problem o check if toplevel has a child selected before selecting it itself on button press o dont draw selection if widget has no allocation * gladeui/glade-design-view.c: o delegate scrolling to size-allocate if toplevel layout has no allocation Fixes scrolling while creating a new widget from the palette. o also add widgets on visibility change
Diffstat (limited to 'gladeui/glade-design-view.c')
-rw-r--r--gladeui/glade-design-view.c111
1 files changed, 67 insertions, 44 deletions
diff --git a/gladeui/glade-design-view.c b/gladeui/glade-design-view.c
index 7a8302e5..1910b8fc 100644
--- a/gladeui/glade-design-view.c
+++ b/gladeui/glade-design-view.c
@@ -93,12 +93,10 @@ glade_design_view_load_progress (GladeProject * project,
gchar *path;
gchar *str;
- path =
- glade_utils_replace_home_dir_with_tilde (glade_project_get_path
- (project));
- str =
- g_strdup_printf (_("Loading %s: loaded %d of %d objects"), path, step,
- total);
+ path = glade_utils_replace_home_dir_with_tilde (glade_project_get_path (project));
+ str = g_strdup_printf (_("Loading %s: loaded %d of %d objects"),
+ path, step, total);
+
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (view->priv->progress), str);
g_free (str);
g_free (path);
@@ -107,9 +105,39 @@ glade_design_view_load_progress (GladeProject * project,
step * 1.0 / total);
}
+static void
+glade_design_layout_scroll (GladeDesignView *view, gint x, gint y, gint w, gint h)
+{
+ gdouble vadj_val, hadj_val, vpage_end, hpage_end;
+ GtkAdjustment *vadj, *hadj;
+
+ vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (view->priv->scrolled_window));
+ hadj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (view->priv->scrolled_window));
+
+ vadj_val = gtk_adjustment_get_value (vadj);
+ hadj_val = gtk_adjustment_get_value (hadj);
+ vpage_end = gtk_adjustment_get_page_size (vadj) + vadj_val;
+ hpage_end = gtk_adjustment_get_page_size (hadj) + hadj_val;
+
+ /* TODO: we could set this value in increments in a timeout callback
+ * to make it look like its scrolling instead of jumping.
+ */
+ if (y < vadj_val || y > vpage_end || (y + h) > vpage_end)
+ gtk_adjustment_set_value (vadj, y);
+
+ if (x < hadj_val || x > hpage_end || (x + w) > hpage_end)
+ gtk_adjustment_set_value (hadj, x);
+}
+
+static void
+on_layout_size_allocate (GtkWidget *widget, GtkAllocation *alloc, GladeDesignView *view)
+{
+ glade_design_layout_scroll (view, alloc->x, alloc->y, alloc->width, alloc->height);
+ g_signal_handlers_disconnect_by_func (widget, on_layout_size_allocate, view);
+}
static void
-glade_design_view_selection_changed (GladeProject * project, GladeDesignView * view)
+glade_design_view_selection_changed (GladeProject *project, GladeDesignView *view)
{
GladeWidget *gwidget, *gtoplevel;
GList *selection;
@@ -129,30 +157,36 @@ glade_design_view_selection_changed (GladeProject * project, GladeDesignView * v
(layout = gtk_widget_get_parent (GTK_WIDGET (toplevel))) &&
GLADE_IS_DESIGN_LAYOUT (layout))
{
- gdouble vadj_val, hadj_val, vpage_end, hpage_end;
- GtkAdjustment *vadj, *hadj;
GtkAllocation alloc;
+ gtk_widget_get_allocation (layout, &alloc);
+
+ if (alloc.x < 0)
+ g_signal_connect (layout, "size-allocate", G_CALLBACK (on_layout_size_allocate), view);
+ else
+ glade_design_layout_scroll (view, alloc.x, alloc.y, alloc.width, alloc.height);
+ }
+ }
+}
- vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (view->priv->scrolled_window));
- hadj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (view->priv->scrolled_window));
-
- vadj_val = gtk_adjustment_get_value (vadj);
- hadj_val = gtk_adjustment_get_value (hadj);
- vpage_end = gtk_adjustment_get_page_size (vadj) + vadj_val;
- hpage_end = gtk_adjustment_get_page_size (hadj) + hadj_val;
+static void
+glade_design_view_add_toplevel (GladeDesignView *view, GladeWidget *widget)
+{
+ GtkWidget *layout;
+ GObject *object;
- gtk_widget_get_allocation (layout, &alloc);
+ if (glade_widget_get_parent (widget) ||
+ (object = glade_widget_get_object (widget)) == NULL ||
+ !GTK_IS_WIDGET (object) ||
+ gtk_widget_get_parent (GTK_WIDGET (object)))
+ return;
- /* TODO: we could set this value in increments in a timeout callback
- * to make it look like its scrolling instead of jumping.
- */
- if (alloc.y < vadj_val || alloc.y > vpage_end || (alloc.y + alloc.height) > vpage_end)
- gtk_adjustment_set_value (vadj, alloc.y);
+ /* Create a GladeDesignLayout and add the toplevel widget to the view */
+ layout = _glade_design_layout_new (view);
+ gtk_box_pack_start (GTK_BOX (view->priv->layout_box), layout, FALSE, TRUE, 0);
- if (alloc.x < hadj_val || alloc.x > hpage_end || (alloc.x + alloc.width) > hpage_end)
- gtk_adjustment_set_value (hadj, alloc.x);
- }
- }
+ gtk_container_add (GTK_CONTAINER (layout), GTK_WIDGET (object));
+ gtk_widget_show (GTK_WIDGET (object));
+ gtk_widget_show (layout);
}
static void
@@ -166,8 +200,8 @@ glade_design_view_remove_toplevel (GladeDesignView *view, GladeWidget *widget)
!GTK_IS_WIDGET (object)) return;
/* Remove toplevel widget from the view */
- layout = gtk_widget_get_parent (GTK_WIDGET (object));
- if (layout)
+ if ((layout = gtk_widget_get_parent (GTK_WIDGET (object))) &&
+ gtk_widget_is_ancestor (layout, GTK_WIDGET (view)))
{
gtk_container_remove (GTK_CONTAINER (layout), GTK_WIDGET (object));
gtk_container_remove (GTK_CONTAINER (view->priv->layout_box), layout);
@@ -180,27 +214,16 @@ glade_design_view_widget_visibility_changed (GladeProject *project,
gboolean visible,
GladeDesignView *view)
{
- if (visible) return;
- glade_design_view_remove_toplevel (view, widget);
+ if (visible)
+ glade_design_view_add_toplevel (view, widget);
+ else
+ glade_design_view_remove_toplevel (view, widget);
}
static void
on_project_add_widget (GladeProject *project, GladeWidget *widget, GladeDesignView *view)
{
- GtkWidget *layout;
- GObject *object;
-
- if (glade_widget_get_parent (widget) ||
- (object = glade_widget_get_object (widget)) == NULL ||
- !GTK_IS_WIDGET (object)) return;
-
- /* Create a GladeDesignLayout and add the toplevel widget to the view */
- layout = _glade_design_layout_new (view);
- gtk_box_pack_start (GTK_BOX (view->priv->layout_box), layout, FALSE, TRUE, 0);
-
- gtk_container_add (GTK_CONTAINER (layout), GTK_WIDGET (object));
- gtk_widget_show (GTK_WIDGET (object));
- gtk_widget_show (layout);
+ glade_design_view_add_toplevel (view, widget);
}
static void