[gnome-control-center/wip/animated-notebook] shell: Add "current-page" property



commit 14dc416b6f0f9aace5afe8ed6a81027791ad5a0a
Author: Bastien Nocera <hadess hadess net>
Date:   Tue May 1 15:12:19 2012 +0100

    shell: Add "current-page" property

 shell/cc-notebook.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 65 insertions(+), 1 deletions(-)
---
diff --git a/shell/cc-notebook.c b/shell/cc-notebook.c
index 70d1ec7..d96bb92 100644
--- a/shell/cc-notebook.c
+++ b/shell/cc-notebook.c
@@ -36,6 +36,13 @@ struct _CcNotebookPrivate
         ClutterActor *scroll_actor;
         ClutterActor *bin;
         GList *children; /* GList of ClutterActor */
+
+        GtkWidget *current_page;
+};
+
+enum {
+        PROP_0,
+        PROP_CURRENT_PAGE
 };
 
 G_DEFINE_TYPE (CcNotebook, cc_notebook, GTK_TYPE_BOX);
@@ -46,14 +53,22 @@ cc_notebook_add (CcNotebook *notebook,
 {
 	ClutterConstraint *constraint;
 	ClutterActor *child;
+	gboolean notify = FALSE;
 
 	child = gtk_clutter_actor_new_with_contents (widget);
 	constraint = clutter_bind_constraint_new (notebook->priv->bin, CLUTTER_BIND_SIZE, 0.0);
 	clutter_actor_add_constraint_with_name (child, "size", constraint);
 	clutter_actor_add_child (notebook->priv->bin, child);
 
+	if (notebook->priv->children == NULL)
+		notify = TRUE;
+
 	notebook->priv->children = g_list_prepend (notebook->priv->children,
 						   child);
+
+	if (notify == FALSE)
+		return;
+	g_object_notify (G_OBJECT (notebook), "current-page");
 }
 
 static int
@@ -81,6 +96,39 @@ cc_notebook_remove (CcNotebook *notebook,
 }
 
 static void
+cc_notebook_set_property (GObject      *object,
+			  guint         prop_id,
+			  const GValue *value,
+			  GParamSpec   *pspec)
+{
+        switch (prop_id) {
+        case PROP_CURRENT_PAGE:
+                cc_notebook_set_current (CC_NOTEBOOK (object),
+					      g_value_get_pointer (value));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
+cc_notebook_get_property (GObject    *object,
+			  guint       prop_id,
+			  GValue     *value,
+			  GParamSpec *pspec)
+{
+        switch (prop_id) {
+        case PROP_CURRENT_PAGE:
+                g_value_set_pointer (value, cc_notebook_get_current (CC_NOTEBOOK (object)));
+                break;
+        default:
+                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                break;
+        }
+}
+
+static void
 cc_notebook_class_init (CcNotebookClass *class)
 {
         GObjectClass *gobject_class;
@@ -89,6 +137,16 @@ cc_notebook_class_init (CcNotebookClass *class)
         gobject_class = (GObjectClass*)class;
         widget_class = (GtkWidgetClass*)class;
 
+        gobject_class->set_property = cc_notebook_set_property;
+        gobject_class->get_property = cc_notebook_get_property;
+
+	g_object_class_install_property (gobject_class,
+					 PROP_CURRENT_PAGE,
+					 g_param_spec_pointer ("current-page",
+							      "Current Page",
+							      "Current Page",
+							      G_PARAM_READWRITE));
+
         g_type_class_add_private (class, sizeof (CcNotebookPrivate));
 }
 
@@ -137,6 +195,9 @@ cc_notebook_set_current (CcNotebook *notebook,
 	g_return_if_fail (CC_IS_NOTEBOOK (notebook));
 	g_return_if_fail (GTK_IS_WIDGET (widget));
 
+	if (widget == notebook->priv->current_page)
+		return;
+
 	l = g_list_find_custom (notebook->priv->children,
 				widget,
 				(GCompareFunc) _cc_notebook_find_widget);
@@ -151,6 +212,9 @@ cc_notebook_set_current (CcNotebook *notebook,
 	clutter_scroll_actor_scroll_to_point (CLUTTER_SCROLL_ACTOR (notebook->priv->scroll_actor), &pos);
 
 	clutter_actor_restore_easing_state (notebook->priv->scroll_actor);
+
+	notebook->priv->current_page = widget;
+	g_object_notify (G_OBJECT (notebook), "current-page");
 }
 
 GtkWidget *
@@ -158,5 +222,5 @@ cc_notebook_get_current (CcNotebook *notebook)
 {
 	g_return_val_if_fail (CC_IS_NOTEBOOK (notebook), NULL);
 
-	return NULL;
+	return notebook->priv->current_page;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]