]> err.no Git - libchamplain/commitdiff
Make it possible to create ChamplainView after ChamplainViewEmbed
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Thu, 21 May 2009 22:21:14 +0000 (18:21 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Fri, 12 Jun 2009 03:54:55 +0000 (23:54 -0400)
If not, the first tiles could be loaded while the stage isn't created yet,
resulting in COGL errors.

champlain-gtk/champlain-view-embed.c
champlain-gtk/champlain-view-embed.h
demos/launcher-gtk.c

index c30c1494536829d542ff756fb08b366324e2b40f..e72957092fc4d093ea26cf742aad71e471a5dda8 100644 (file)
@@ -48,6 +48,9 @@ struct _ChamplainViewEmbedPrivate
 
   GdkCursor *cursor_hand_open;
   GdkCursor *cursor_hand_closed;
+
+  guint width;
+  guint height;
 };
 
 
@@ -101,17 +104,10 @@ champlain_view_embed_set_property (GObject *object,
   {
     case PROP_VIEW:
       {
-        ClutterActor *stage;
-        stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutter_embed));
-
-        if (priv->view != NULL)
-          {
-            g_object_unref (priv->view);
-            clutter_container_remove_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (priv->view));
-          }
+        ChamplainView *view;
 
-        priv->view = g_value_dup_object (value);
-        clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (priv->view));
+        view = g_value_get_object (value);
+        champlain_view_embed_set_view (CHAMPLAIN_VIEW_EMBED (object), view);
         break;
       }
     default:
@@ -152,7 +148,7 @@ champlain_view_embed_class_init (ChamplainViewEmbedClass *klass)
          "Champlain view",
          "The ChamplainView to embed into the Gtk+ widget",
          CHAMPLAIN_TYPE_VIEW,
-         CHAMPLAIN_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+         CHAMPLAIN_PARAM_READWRITE));
 }
 
 static void
@@ -211,7 +207,11 @@ view_size_allocated_cb (GtkWidget *widget,
 {
   ChamplainViewEmbedPrivate *priv = view->priv;
 
-  champlain_view_set_size(priv->view, allocation->width, allocation->height);
+  if (priv->view != NULL)
+    champlain_view_set_size (priv->view, allocation->width, allocation->height);
+
+  priv->width = allocation->width;
+  priv->height = allocation->height;
 }
 
 static gboolean
@@ -237,11 +237,9 @@ mouse_button_cb (GtkWidget *widget,
  * Since: 0.2.1
  */
 GtkWidget *
-champlain_view_embed_new (ChamplainView *view)
+champlain_view_embed_new ()
 {
-  g_return_val_if_fail (CHAMPLAIN_IS_VIEW (view), NULL);
-
-  return g_object_new (CHAMPLAIN_TYPE_VIEW_EMBED, "champlain-view", view, NULL);
+  return g_object_new (CHAMPLAIN_TYPE_VIEW_EMBED, NULL);
 }
 
 ChamplainView *
@@ -252,3 +250,26 @@ champlain_view_embed_get_view (ChamplainViewEmbed* embed)
   ChamplainViewEmbedPrivate *priv = embed->priv;
   return priv->view;
 }
+
+void
+champlain_view_embed_set_view (ChamplainViewEmbed* embed,
+    ChamplainView *view)
+{
+  g_return_if_fail (CHAMPLAIN_IS_VIEW_EMBED(embed));
+  g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
+
+  ChamplainViewEmbedPrivate *priv = embed->priv;
+  ClutterActor *stage;
+
+  if (priv->view != NULL)
+    {
+      g_object_unref (priv->view);
+      clutter_container_remove_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (priv->view));
+    }
+
+  priv->view = g_object_ref (view);
+  champlain_view_set_size (priv->view, priv->width, priv->height);
+
+  stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutter_embed));
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (priv->view));
+}
index 249f8bd476ca1ba481f592e9d1dad903c0e1efd6..5c3e94a9c9be80eccbf382f9602d97f422501298 100644 (file)
@@ -55,8 +55,9 @@ typedef struct _ChamplainViewEmbedClass ChamplainViewEmbedClass;
 
 GType champlain_view_embed_get_type (void);
 
-GtkWidget *champlain_view_embed_new (ChamplainView* view);
+GtkWidget *champlain_view_embed_new ();
 
 ChamplainView *champlain_view_embed_get_view (ChamplainViewEmbed* embed);
+void champlain_view_embed_set_view (ChamplainViewEmbed* embed, ChamplainView *view);
 
 #endif
index b0cc5917515a671102f3daf97db2c2432ffdc2f6..d34d8489c519b849e45284a946f55938a9c8de88 100644 (file)
@@ -207,8 +207,9 @@ main (int argc,
 
   vbox = gtk_vbox_new(FALSE, 10);
 
-  view = champlain_view_new ();
-  widget = champlain_view_embed_new (CHAMPLAIN_VIEW (view));
+  widget = champlain_view_embed_new ();
+
+  view = champlain_view_embed_get_view (CHAMPLAIN_VIEW_EMBED (widget));
   g_object_set (G_OBJECT (view), "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
       "zoom-level", 5, NULL);
   layer = create_marker_layer (CHAMPLAIN_VIEW (view));