Commit b45ddd32 authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

* 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.
parent 3693cac9
......@@ -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:
......
......@@ -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)
{
......
......@@ -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;
}
}
......
......@@ -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
......
......@@ -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;
}
......@@ -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. */
......
......@@ -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);
......
......@@ -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 */
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment