[libgd/wip/rishi/main-box: 3/9] Add GdMainBoxGeneric



commit 72aecf0203c9d53cf45e34e5d82e4172d616c8ec
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Dec 1 15:51:11 2016 +0100

    Add GdMainBoxGeneric
    
    This is the interface that a GtkWidget must implement to be able to
    contain multiple GdMainBoxChild implementations.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774914

 libgd/gd-main-box-generic.c |  207 +++++++++++++++++++++++++++++++++++++++++++
 libgd/gd-main-box-generic.h |   59 ++++++++++++
 2 files changed, 266 insertions(+), 0 deletions(-)
---
diff --git a/libgd/gd-main-box-generic.c b/libgd/gd-main-box-generic.c
new file mode 100644
index 0000000..64ea58e
--- /dev/null
+++ b/libgd/gd-main-box-generic.c
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by 
+ * the Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License 
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ *
+ */
+
+#include "gd-main-box-generic.h"
+
+enum
+{
+  VIEW_SELECTION_CHANGED,
+  NUM_SIGNALS
+};
+
+static guint signals[NUM_SIGNALS] = { 0, };
+
+G_DEFINE_INTERFACE (GdMainBoxGeneric, gd_main_box_generic, GTK_TYPE_WIDGET)
+
+static void
+gd_main_box_generic_default_init (GdMainBoxGenericInterface *iface)
+{
+  GParamSpec *pspec;
+
+  /**
+   * GdMainBoxGeneric:model:
+   *
+   * A #GListModel that is rendered by the #GdMainBoxGeneric widget.
+   */
+  pspec = g_param_spec_object ("model",
+                               "Model",
+                               "A model that is rendered by the widget",
+                               G_TYPE_LIST_MODEL,
+                               G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_interface_install_property (iface, pspec);
+
+  /**
+   * GdMainBoxGeneric:selection-mode:
+   *
+   * Whether the #GdMainBoxGeneric widget is in selection mode.
+   */
+  pspec = g_param_spec_object ("selection-mode",
+                               "Selection Mode",
+                               "Whether the widget is in selection mode",
+                               FALSE,
+                               G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_interface_install_property (iface, pspec);
+
+  signals[VIEW_SELECTION_CHANGED] = g_signal_new ("view-selection-changed",
+                                                  GD_TYPE_MAIN_BOX_GENERIC,
+                                                  G_SIGNAL_RUN_LAST,
+                                                  0,
+                                                  NULL,
+                                                  NULL,
+                                                  g_cclosure_marshal_VOID__VOID,
+                                                  G_TYPE_NONE,
+                                                  0);
+}
+
+/**
+ * gd_main_box_generic_get_child_at_index:
+ * @self:
+ * @index:
+ *
+ * Returns: (transfer none): The child at @index.
+ */
+GdMainBoxChild *
+gd_main_box_generic_get_child_at_index (GdMainBoxGeneric *self, gint index)
+{
+  GdMainBoxGenericInterface *iface;
+
+  g_return_val_if_fail (GD_IS_MAIN_BOX_GENERIC (self), NULL);
+
+  iface = GD_MAIN_BOX_GENERIC_GET_IFACE (self);
+
+  return (* iface->get_child_at_index) (self, index);
+}
+
+/**
+ * gd_main_box_generic_get_model:
+ * @self:
+ *
+ * Returns: (transfer none): The associated model
+ */
+GListModel *
+gd_main_box_generic_get_model (GdMainBoxGeneric *self)
+{
+  GListModel *model;
+
+  g_return_val_if_fail (GD_IS_MAIN_BOX_GENERIC (self), NULL);
+
+  g_object_get (self, "model", &model, NULL);
+
+  if (model != NULL)
+    g_object_unref (model);
+
+  return model;
+}
+
+/**
+ * gd_main_box_generic_get_selection_mode:
+ * @self:
+ *
+ * Returns: (transfer none): Whether @self is in selection mode
+ */
+gboolean
+gd_main_box_generic_get_selection_mode (GdMainBoxGeneric *self)
+{
+  gboolean selection_mode;
+
+  g_return_val_if_fail (GD_IS_MAIN_BOX_GENERIC (self), FALSE);
+
+  g_object_get (self, "selection-mode", &selection_mode, NULL);
+  return selection_mode;
+}
+
+void
+gd_main_box_generic_select_all (GdMainBoxGeneric *self)
+{
+  GdMainBoxGenericInterface *iface;
+
+  g_return_if_fail (GD_IS_MAIN_BOX_GENERIC (self));
+
+  iface = GD_MAIN_BOX_GENERIC_GET_IFACE (self);
+
+  (* iface->select_all) (self);
+}
+
+void
+gd_main_box_generic_select_child (GdMainBoxGeneric *self, GdMainBoxChild *child)
+{
+  GdMainBoxGenericInterface *iface;
+
+  g_return_if_fail (GD_IS_MAIN_BOX_GENERIC (self));
+  g_return_if_fail (GD_IS_MAIN_BOX_CHILD (child));
+
+  iface = GD_MAIN_BOX_GENERIC_GET_IFACE (self);
+
+  (* iface->select_child) (self, child);
+}
+
+/**
+ * gd_main_box_generic_set_model:
+ * @self:
+ * @model: (allow-none):
+ *
+ */
+void
+gd_main_box_generic_set_model (GdMainBoxGeneric *self, GListModel *model)
+{
+  g_return_if_fail (GD_IS_MAIN_BOX_GENERIC (self));
+  g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
+
+  g_object_set (self, "model", model, NULL);
+}
+
+/**
+ * gd_main_box_generic_set_selection_mode:
+ * @self:
+ * @selection_mode:
+ *
+ */
+void
+gd_main_box_generic_set_selection_mode (GdMainBoxGeneric *self, gboolean selection_mode)
+{
+  g_return_if_fail (GD_IS_MAIN_BOX_GENERIC (self));
+  g_object_set (self, "selection-mode", selection_mode, NULL);
+}
+
+void
+gd_main_box_generic_unselect_all (GdMainBoxGeneric *self)
+{
+  GdMainBoxGenericInterface *iface;
+
+  g_return_if_fail (GD_IS_MAIN_BOX_GENERIC (self));
+
+  iface = GD_MAIN_BOX_GENERIC_GET_IFACE (self);
+
+  (* iface->unselect_all) (self);
+}
+
+void
+gd_main_box_generic_unselect_child (GdMainBoxGeneric *self, GdMainBoxChild *child)
+{
+  GdMainBoxGenericInterface *iface;
+
+  g_return_if_fail (GD_IS_MAIN_BOX_GENERIC (self));
+  g_return_if_fail (GD_IS_MAIN_BOX_CHILD (child));
+
+  iface = GD_MAIN_BOX_GENERIC_GET_IFACE (self);
+
+  (* iface->unselect_child) (self, child);
+}
diff --git a/libgd/gd-main-box-generic.h b/libgd/gd-main-box-generic.h
new file mode 100644
index 0000000..e88c72e
--- /dev/null
+++ b/libgd/gd-main-box-generic.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by 
+ * the Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License 
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Debarshi Ray <debarshir gnome org>
+ *
+ */
+
+#ifndef __GD_MAIN_BOX_GENERIC_H__
+#define __GD_MAIN_BOX_GENERIC_H__
+
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+
+#include "gd-main-box-child.h"
+
+G_BEGIN_DECLS
+
+#define GD_TYPE_MAIN_BOX_GENERIC gd_main_box_generic_get_type()
+G_DECLARE_INTERFACE (GdMainBoxGeneric, gd_main_box_generic, GD, MAIN_BOX_GENERIC, GtkWidget)
+
+struct _GdMainBoxGenericInterface
+{
+  GTypeInterface base_iface;
+
+  /* vtable */
+  GdMainBoxChild  * (* get_child_at_index)  (GdMainBoxGeneric *self, gint index);
+  void              (* select_all)          (GdMainBoxGeneric *self);
+  void              (* select_child)        (GdMainBoxGeneric *self, GdMainBoxChild *child);
+  void              (* unselect_all)        (GdMainBoxGeneric *self);
+  void              (* unselect_child)      (GdMainBoxGeneric *self, GdMainBoxChild *child);
+};
+
+GdMainBoxChild  * gd_main_box_generic_get_child_at_index  (GdMainBoxGeneric *self, gint index);
+GListModel      * gd_main_box_generic_get_model           (GdMainBoxGeneric *self);
+gboolean          gd_main_box_generic_get_selection_mode  (GdMainBoxGeneric *self);
+void              gd_main_box_generic_select_all          (GdMainBoxGeneric *self);
+void              gd_main_box_generic_select_child        (GdMainBoxGeneric *self, GdMainBoxChild *child);
+void              gd_main_box_generic_set_model           (GdMainBoxGeneric *self, GListModel *model);
+void              gd_main_box_generic_set_selection_mode  (GdMainBoxGeneric *self, gboolean selection_mode);
+void              gd_main_box_generic_unselect_all        (GdMainBoxGeneric *self);
+void              gd_main_box_generic_unselect_child      (GdMainBoxGeneric *self, GdMainBoxChild *child);
+
+G_END_DECLS
+
+#endif /* __GD_MAIN_BOX_GENERIC_H__ */


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