[glade3] * gladeui/glade-widget-adaptor.[ch]: Add a "scrollable" flag on the adaptor class vtable introsp
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade3] * gladeui/glade-widget-adaptor.[ch]: Add a "scrollable" flag on the adaptor class vtable introsp
- Date: Sun, 28 Mar 2010 20:34:31 +0000 (UTC)
commit b45ddd32b53dc1ab26a4b159427e240935fda692
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Sun Mar 28 16:34:06 2010 -0400
* gladeui/glade-widget-adaptor.[ch]: Add a "scrollable" flag on the adaptor class vtable
introspected by checking if (widget_class->set_scroll_adjustments_signal) != 0.
* gladeui/glade-utils.[ch]: Added glade_util_check_and_warn_scrollable() to check and warn the
user if they are trying to add a non-scrollable widget to a scrolled window.
* gladeui/glade-app.c, gladeui/glade-popup.c, gladeui/glade-placeholder.c, plugins/gtk+/glade-gtk.c:
Consult glade_util_check_and_warn_scrollable() before executing commands that introduce objects
to the project.
ChangeLog | 10 ++++++++++
gladeui/glade-app.c | 8 +++++++-
gladeui/glade-placeholder.c | 27 ++++++++++++++-------------
gladeui/glade-popup.c | 18 ++++++++++++------
gladeui/glade-utils.c | 25 +++++++++++++++++++++++--
gladeui/glade-utils.h | 4 ++++
gladeui/glade-widget-adaptor.c | 5 +++++
gladeui/glade-widget-adaptor.h | 16 ++++++++++++++++
plugins/gtk+/glade-gtk.c | 5 +++++
9 files changed, 96 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b3df831..fc007a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,16 @@
instead of the property mutator implementation (as the "columns" property is construct-only
and the widget is rebuilt - property reference lists are unavailable at ->set_property time).
+ * gladeui/glade-widget-adaptor.[ch]: Add a "scrollable" flag on the adaptor class vtable
+ introspected by checking if (widget_class->set_scroll_adjustments_signal) != 0.
+
+ * gladeui/glade-utils.[ch]: Added glade_util_check_and_warn_scrollable() to check and warn the
+ user if they are trying to add a non-scrollable widget to a scrolled window.
+
+ * gladeui/glade-app.c, gladeui/glade-popup.c, gladeui/glade-placeholder.c, plugins/gtk+/glade-gtk.c:
+ Consult glade_util_check_and_warn_scrollable() before executing commands that introduce objects
+ to the project.
+
2010-03-27 Tristan Van Berkom <tvb gnome org>
* gladeui/glade-marshallers.list, gladeui/glade-placeholder.c:
diff --git a/gladeui/glade-app.c b/gladeui/glade-app.c
index 3fa69b1..3570c40 100644
--- a/gladeui/glade-app.c
+++ b/gladeui/glade-app.c
@@ -1286,8 +1286,14 @@ glade_app_command_paste (GladePlaceholder *placeholder)
return;
}
+
}
-
+
+ /* Abort operation when adding a non scrollable widget to any kind of GtkScrolledWindow. */
+ if (parent && widget &&
+ glade_util_check_and_warn_scrollable (parent, widget->adaptor, glade_app_get_window()))
+ return;
+
/* Check if we have anything to paste */
if (g_list_length (clipboard->selection) == 0)
{
diff --git a/gladeui/glade-placeholder.c b/gladeui/glade-placeholder.c
index b35eabc..593f41c 100644
--- a/gladeui/glade-placeholder.c
+++ b/gladeui/glade-placeholder.c
@@ -362,19 +362,20 @@ glade_placeholder_button_press (GtkWidget *widget, GdkEventButton *event)
{
if (adaptor != NULL)
{
- /* A widget type is selected in the palette.
- * Add a new widget of that type.
- */
- glade_command_create
- (adaptor,
- glade_placeholder_get_parent (placeholder),
- placeholder, project);
-
- glade_palette_deselect_current_item (glade_app_get_palette(), TRUE);
-
- /* reset the cursor */
- glade_cursor_set (event->window, GLADE_CURSOR_SELECTOR);
-
+ GladeWidget *parent = glade_placeholder_get_parent (placeholder);
+
+ if (!glade_util_check_and_warn_scrollable (parent, adaptor, glade_app_get_window()))
+ {
+ /* A widget type is selected in the palette.
+ * Add a new widget of that type.
+ */
+ glade_command_create (adaptor, parent, placeholder, project);
+
+ glade_palette_deselect_current_item (glade_app_get_palette(), TRUE);
+
+ /* reset the cursor */
+ glade_cursor_set (event->window, GLADE_CURSOR_SELECTOR);
+ }
handled = TRUE;
}
}
diff --git a/gladeui/glade-popup.c b/gladeui/glade-popup.c
index 84f67b7..0163065 100644
--- a/gladeui/glade-popup.c
+++ b/gladeui/glade-popup.c
@@ -83,14 +83,20 @@ static void
glade_popup_placeholder_add_cb (GtkMenuItem *item, GladePlaceholder *placeholder)
{
GladeWidgetAdaptor *adaptor;
-
+ GladeWidget *parent;
+
adaptor = glade_palette_get_current_item (glade_app_get_palette ());
g_return_if_fail (adaptor != NULL);
-
- glade_command_create (adaptor, glade_placeholder_get_parent (placeholder),
- placeholder, glade_placeholder_get_project (placeholder));
-
- glade_palette_deselect_current_item (glade_app_get_palette(), TRUE);
+
+ parent = glade_placeholder_get_parent (placeholder);
+
+ if (!glade_util_check_and_warn_scrollable (parent, adaptor, glade_app_get_window()))
+ {
+ glade_command_create (adaptor, parent,
+ placeholder, glade_placeholder_get_project (placeholder));
+
+ glade_palette_deselect_current_item (glade_app_get_palette(), TRUE);
+ }
}
static void
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 16d6a3b..2decba3 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -272,8 +272,28 @@ glade_util_ui_message (GtkWidget *parent,
}
-
-
+gboolean
+glade_util_check_and_warn_scrollable (GladeWidget *parent,
+ GladeWidgetAdaptor *child_adaptor,
+ GtkWidget *parent_widget)
+{
+ if (GTK_IS_SCROLLED_WINDOW (parent->object) &&
+ GWA_SCROLLABLE_WIDGET (child_adaptor) == FALSE)
+ {
+ GladeWidgetAdaptor *vadaptor =
+ glade_widget_adaptor_get_by_type (GTK_TYPE_VIEWPORT);
+
+ glade_util_ui_message (parent_widget,
+ GLADE_UI_INFO, NULL,
+ _("Cannot add non scrollable %s widget to a %s directly.\n"
+ "Add a %s first."),
+ child_adaptor->title,
+ parent->adaptor->title,
+ vadaptor->title);
+ return TRUE;
+ }
+ return FALSE;
+}
typedef struct {
GtkStatusbar *statusbar;
@@ -2327,3 +2347,4 @@ glade_utils_hijack_key_press (GtkWindow *win,
}
return FALSE;
}
+
diff --git a/gladeui/glade-utils.h b/gladeui/glade-utils.h
index f7d314b..f263b06 100644
--- a/gladeui/glade-utils.h
+++ b/gladeui/glade-utils.h
@@ -34,6 +34,10 @@ void glade_util_flash_message (GtkWidget *statusbar,
guint context_id,
gchar *format, ...);
+gboolean glade_util_check_and_warn_scrollable (GladeWidget *parent,
+ GladeWidgetAdaptor *child_adaptor,
+ GtkWidget *parent_widget);
+
/* This is a GCompareFunc for comparing the labels of 2 stock items, ignoring
any '_' characters. It isn't particularly efficient. */
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index c11f5e7..262d412 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -600,6 +600,11 @@ glade_widget_adaptor_constructor (GType type,
gwa_setup_properties (adaptor, object_class, TRUE);
}
+ /* Detect scrollability */
+ if (g_type_is_a (adaptor->type, GTK_TYPE_WIDGET) &&
+ GTK_WIDGET_CLASS (object_class)->set_scroll_adjustments_signal != 0)
+ GLADE_WIDGET_ADAPTOR_GET_CLASS(adaptor)->scrollable = TRUE;
+
/* Inherit packing defaults here */
adaptor->child_packings = gwa_inherit_child_packing (adaptor);
diff --git a/gladeui/glade-widget-adaptor.h b/gladeui/glade-widget-adaptor.h
index 899545c..f4be4ba 100644
--- a/gladeui/glade-widget-adaptor.h
+++ b/gladeui/glade-widget-adaptor.h
@@ -140,6 +140,17 @@ typedef struct _GladeWidgetAdaptorClass GladeWidgetAdaptorClass;
#define GWA_DEFAULT_HEIGHT(obj) \
((obj) ? GLADE_WIDGET_ADAPTOR_GET_CLASS(obj)->default_height : -1)
+
+/**
+ * GWA_SCROLLABLE_WIDGET:
+ * @obj: A #GladeWidgetAdaptor
+ *
+ * Checks whether this is a GtkWidgetClass with scrolling capabilities.
+ */
+#define GWA_SCROLLABLE_WIDGET(obj) \
+ ((obj) ? GLADE_WIDGET_ADAPTOR_GET_CLASS(obj)->scrollable : FALSE)
+
+
/**
* GWA_GET_CLASS:
* @type: A #GType
@@ -636,6 +647,11 @@ struct _GladeWidgetAdaptorClass
* to interface with child widgets.
*/
+ guint scrollable : 1; /* Whether this is a widget class that has
+ * klass->set_scroll_adjustments_signal != NULL (i.e.
+ * can be directly added to a GtkScrolledWindow).
+ */
+
gint default_width; /* Default width in GladeDesignLayout */
gint default_height; /* Default height in GladeDesignLayout */
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 91c6c56..381bf74 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -1285,6 +1285,11 @@ glade_gtk_widget_action_activate (GladeWidgetAdaptor *adaptor,
GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (new_type);
GList *saved_props, *prop_cmds;
GladeProject *project;
+
+ /* Dont add non-scrollable widgets to scrolled windows... */
+ if (gparent &&
+ glade_util_check_and_warn_scrollable (gparent, adaptor, glade_app_get_window()))
+ return;
glade_command_push_group (_("Adding parent %s for %s"),
adaptor->title, gwidget->name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]