[gtk+/overlay: 16/34] overlay: manage main widget with gtk_container_add/remove
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/overlay: 16/34] overlay: manage main widget with gtk_container_add/remove
- Date: Sat, 11 Jun 2011 01:00:00 +0000 (UTC)
commit faf782420d4ebe177b450b8d14304de750ee2c1e
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu May 26 23:29:20 2011 +0200
overlay: manage main widget with gtk_container_add/remove
demos/gtk-demo/overlay.c | 3 +-
gtk/gtkoverlay.c | 54 ++++++++++++++++++++-------------------------
gtk/gtkoverlay.h | 2 +-
3 files changed, 27 insertions(+), 32 deletions(-)
---
diff --git a/demos/gtk-demo/overlay.c b/demos/gtk-demo/overlay.c
index 078bfb7..40a71b7 100644
--- a/demos/gtk-demo/overlay.c
+++ b/demos/gtk-demo/overlay.c
@@ -38,7 +38,8 @@ do_overlay (GtkWidget *do_widget)
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (sw), view);
- overlay = gtk_overlay_new (sw);
+ overlay = gtk_overlay_new ();
+ gtk_container_add (GTK_CONTAINER (overlay), sw);
gtk_overlay_set_relative_widget (GTK_OVERLAY (overlay), view);
gtk_container_add (GTK_CONTAINER (window), overlay);
diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c
index 6373964..ebf4aca 100644
--- a/gtk/gtkoverlay.c
+++ b/gtk/gtkoverlay.c
@@ -47,7 +47,6 @@ struct _GtkOverlayChild
enum
{
PROP_0,
- PROP_MAIN_WIDGET,
PROP_RELATIVE_WIDGET
};
@@ -144,9 +143,6 @@ gtk_overlay_get_property (GObject *object,
switch (prop_id)
{
- case PROP_MAIN_WIDGET:
- g_value_set_object (value, priv->main_widget);
- break;
case PROP_RELATIVE_WIDGET:
g_value_set_object (value, priv->relative_widget);
break;
@@ -167,10 +163,6 @@ gtk_overlay_set_property (GObject *object,
switch (prop_id)
{
- case PROP_MAIN_WIDGET:
- priv->main_widget = g_value_get_object (value);
- add_child (overlay, priv->main_widget);
- break;
case PROP_RELATIVE_WIDGET:
priv->relative_widget = g_value_get_object (value);
break;
@@ -445,10 +437,26 @@ gtk_overlay_draw (GtkWidget *widget,
}
static void
-overlay_add (GtkContainer *overlay,
+overlay_add (GtkContainer *container,
GtkWidget *widget)
{
- gtk_overlay_add (GTK_OVERLAY (overlay), widget);
+ GtkOverlay *overlay = GTK_OVERLAY (container);
+ GtkOverlayPrivate *priv = overlay->priv;
+
+ if (priv->main_widget != NULL)
+ {
+ g_warning ("Attempting to add a widget with type %s to a %s, "
+ "but as a GtkOverlay subclass a %s can only contain one main widget at a time; "
+ "it already contains a widget of type %s",
+ g_type_name (G_OBJECT_TYPE (widget)),
+ g_type_name (G_OBJECT_TYPE (container)),
+ g_type_name (G_OBJECT_TYPE (container)),
+ g_type_name (G_OBJECT_TYPE (priv->main_widget)));
+ return;
+ }
+
+ priv->main_widget = widget;
+ add_child (overlay, widget);
}
static void
@@ -471,6 +479,9 @@ gtk_overlay_remove (GtkContainer *overlay,
gdk_window_destroy (child->window);
}
+ if (widget == priv->main_widget)
+ priv->main_widget = NULL;
+
gtk_widget_unparent (widget);
priv->children = g_slist_delete_link (priv->children,
@@ -622,15 +633,6 @@ gtk_overlay_class_init (GtkOverlayClass *klass)
container_class->set_child_property = gtk_overlay_set_child_property;
container_class->get_child_property = gtk_overlay_get_child_property;
- g_object_class_install_property (object_class, PROP_MAIN_WIDGET,
- g_param_spec_object ("main-widget",
- "Main Widget",
- "The Main Widget",
- GTK_TYPE_WIDGET,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
g_object_class_install_property (object_class, PROP_RELATIVE_WIDGET,
g_param_spec_object ("relative-widget",
"Relative Widget",
@@ -668,23 +670,15 @@ gtk_overlay_init (GtkOverlay *overlay)
/**
* gtk_overlay_new:
- * @main_widget: a #GtkWidget
- * @relative_widget: (allow-none): a #Gtkwidget
*
- * Creates a new #GtkOverlay. If @relative_widget is not %NULL the floating
- * widgets will be placed in relation to it, if not @main_widget will be use
- * for this purpose.
+ * Creates a new #GtkOverlay.
*
* Returns: a new #GtkOverlay object.
*/
GtkWidget *
-gtk_overlay_new (GtkWidget *main_widget)
+gtk_overlay_new (void)
{
- g_return_val_if_fail (GTK_IS_WIDGET (main_widget), NULL);
-
- return GTK_WIDGET (g_object_new (GTK_TYPE_OVERLAY,
- "main-widget", main_widget,
- NULL));
+ return g_object_new (GTK_TYPE_OVERLAY, NULL);
}
/**
diff --git a/gtk/gtkoverlay.h b/gtk/gtkoverlay.h
index 36d02dd..b3a48c6 100644
--- a/gtk/gtkoverlay.h
+++ b/gtk/gtkoverlay.h
@@ -68,7 +68,7 @@ struct _GtkOverlayClass
GType gtk_overlay_get_type (void) G_GNUC_CONST;
-GtkWidget *gtk_overlay_new (GtkWidget *main_widget);
+GtkWidget *gtk_overlay_new (void);
void gtk_overlay_set_relative_widget (GtkOverlay *overlay,
GtkWidget *relative_widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]