[libgd/wip/rishi/main-box: 7/8] Add GdMainIconBox



commit da1d2a1c7f953a4c7ae018d87cc945077dd1a17e
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Nov 23 16:46:50 2016 +0100

    Add GdMainIconBox
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774914

 libgd/gd-main-icon-box.c |  210 ++++++++++++++++++++++++++++++++++++++++++++++
 libgd/gd-main-icon-box.h |   41 +++++++++
 2 files changed, 251 insertions(+), 0 deletions(-)
---
diff --git a/libgd/gd-main-icon-box.c b/libgd/gd-main-icon-box.c
new file mode 100644
index 0000000..42a241a
--- /dev/null
+++ b/libgd/gd-main-icon-box.c
@@ -0,0 +1,210 @@
+/*
+ * 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-icon-box.h"
+#include "gd-main-box-displayable.h"
+#include "gd-main-box-generic.h"
+
+#include <math.h>
+#include <gio/gio.h>
+#include <glib/gi18n.h>
+#include <cairo-gobject.h>
+
+#define BOX_COLUMN_SPACING 20
+#define BOX_MARGIN 16
+
+typedef struct _GdMainIconBoxPrivate GdMainIconBoxPrivate;
+
+struct _GdMainIconBoxPrivate
+{
+  GListModel *model;
+  GtkWidget *flow_box;
+  gboolean selection_mode;
+};
+
+static void gd_main_box_generic_iface_init (GdMainBoxGenericInterface *iface);
+G_DEFINE_TYPE_WITH_CODE (GdMainIconBox, gd_main_icon_box, GTK_TYPE_BIN,
+                         G_ADD_PRIVATE (GdMainIconBox)
+                         G_IMPLEMENT_INTERFACE (GD_TYPE_MAIN_BOX_GENERIC,
+                                                gd_main_box_generic_interface_init))
+
+GtkWidget *
+gd_main_icon_box_create_widget_func (gpointer item, gpointer user_data)
+{
+  GdMainIconBox *self = GD_MAIN_ICON_BOX (user_data);
+  GdMainIconBoxPrivate *priv;
+  GdMainBoxDisplayable *displayable;
+  GtkWidget *child;
+
+  g_return_if_fail (GD_IS_MAIN_BOX_DISPLAYABLE (item));
+
+  priv = gd_main_icon_box_get_instance_private (self);
+  displayable = GD_MAIN_BOX_DISPLAYABLE (item);
+
+  child = gd_main_icon_box_child_new (displayable, priv->selection_mode);
+  return child;
+}
+
+static void
+gd_main_icon_box_constructed (GObject *obj)
+{
+  GdMainIconBox *self = GD_MAIN_ICON_BOX (obj);
+  GdMainIconBoxPrivate *priv;
+
+  priv = gd_main_icon_box_get_instance_private (self);
+
+  G_OBJECT_CLASS (gd_main_icon_box_parent_class)->constructed (obj);
+
+  gtk_widget_set_hexpand (priv->flow_box, TRUE);
+  gtk_widget_set_vexpand (priv->flow_box, TRUE);
+  gtk_widget_set_margin_bottom (priv->flow_box, BOX_MARGIN);
+  gtk_widget_set_margin_end (priv->flow_box, BOX_MARGIN);
+  gtk_widget_set_margin_start (priv->flow_box, BOX_MARGIN);
+  gtk_widget_set_margin_top (priv->flow_box, BOX_MARGIN);
+  gtk_flow_box_set_column_spacing (GTK_FLOW_BOX (priv->flow_box), BOX_COLUMN_SPACING);
+  gtk_flow_box_set_selection_mode (GTK_FLOW_BOX (priv->flow_box), GTK_SELECTION_NONE);
+}
+
+static void
+gd_main_icon_box_dispose (GObject *obj)
+{
+  GdMainIconBox *self = GD_MAIN_ICON_BOX (obj);
+  GdMainIconBoxPrivate *priv;
+
+  priv = gd_main_icon_box_get_instance_private (self);
+
+  g_clear_object (&priv->model);
+
+  G_OBJECT_CLASS (gd_main_icon_box_parent_class)->dispose (obj);
+}
+
+static void
+gd_main_icon_box_init (GdMainIconBox *self)
+{
+  self->flow_box = gtk_flow_box_new ();
+  gtk_container_add (GTK_CONTAINER (self), self->flow_box);
+}
+
+static void
+gd_main_icon_box_class_init (GdMainIconBoxClass *klass)
+{
+  GObjectClass *oclass = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
+  GtkBindingSet *binding_set;
+  GdkModifierType activate_modifiers[] = { GDK_SHIFT_MASK, GDK_CONTROL_MASK, GDK_SHIFT_MASK | 
GDK_CONTROL_MASK };
+  guint i;
+
+  binding_set = gtk_binding_set_by_class (klass);
+
+  oclass->constructed = gd_main_icon_box_constructed;
+  oclass->dispose = gd_main_icon_box_dispose;
+
+  gtk_widget_class_install_style_property (wclass,
+                                           g_param_spec_int ("check-icon-size",
+                                                             "Check icon size",
+                                                             "Check icon size",
+                                                             -1,
+                                                             G_MAXINT,
+                                                             40,
+                                                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  for (i = 0; i < G_N_ELEMENTS (activate_modifiers); i++)
+    {
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, activate_modifiers[i],
+                                   "activate-cursor-child", 0);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, activate_modifiers[i],
+                                   "activate-cursor-child", 0);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, activate_modifiers[i],
+                                   "activate-cursor-child", 0);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, activate_modifiers[i],
+                                   "activate-cursor-child", 0);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, activate_modifiers[i],
+                                   "activate-cursor-child", 0);
+    }
+}
+
+static void
+gd_main_icon_box_set_selection_mode (GdMainBoxGeneric *generic, gboolean selection_mode)
+{
+  GdMainIconBox *self = GD_MAIN_ICON_BOX (generic);
+  GdMainIconBoxPrivate *priv;
+  gint i;
+
+  priv = gd_main_icon_box_get_instance_private (self);
+
+  if (priv->selection_mode == selection_mode)
+    return;
+
+  priv->selection_mode = selection_mode;
+
+  for (i = 0; ; i++)
+    {
+      GtkFlowBoxChild *child;
+
+      child = gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (priv->flow_box), i);
+      if (child == NULL)
+        break;
+
+      gd_main_box_child_set_selection_mode (GD_MAIN_BOX_CHILD (child), priv->selection_mode);
+    }
+}
+
+static void
+gd_main_icon_box_set_model (GdMainBoxGeneric *generic, GListModel *model)
+{
+  GdMainIconBox *self = GD_MAIN_ICON_BOX (generic);
+  GdMainIconBoxPrivate *priv;
+
+  priv = gd_main_icon_box_get_instance_private (self);
+
+  if (!g_set_object (&priv->model, model))
+    return;
+
+  gtk_flow_box_bind_model (GTK_FLOW_BOX (priv->flow_box),
+                           priv->model,
+                           gd_main_icon_box_create_widget_func,
+                           self,
+                           NULL);
+}
+
+static GListModel *
+gd_main_icon_box_get_model (GdMainBoxGeneric *generic)
+{
+  GdMainIconBox *self = GD_MAIN_ICON_BOX (generic);
+  GdMainIconBoxPrivate *priv;
+
+  priv = gd_main_icon_box_get_instance_private (self);
+  return priv->model;
+}
+
+static void
+gd_main_box_generic_iface_init (GdMainBoxGenericInterface *iface)
+{
+  iface->set_model = gd_main_icon_box_set_model;
+  iface->get_model = gd_main_icon_box_get_model;
+  iface->set_selection_mode = gd_main_icon_box_set_selection_mode;
+}
+
+GtkWidget *
+gd_main_icon_box_new (void)
+{
+  return g_object_new (GD_TYPE_MAIN_ICON_BOX, NULL);
+}
diff --git a/libgd/gd-main-icon-box.h b/libgd/gd-main-icon-box.h
new file mode 100644
index 0000000..fbf5e37
--- /dev/null
+++ b/libgd/gd-main-icon-box.h
@@ -0,0 +1,41 @@
+/*
+ * 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_ICON_BOX_H__
+#define __GD_MAIN_ICON_BOX_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GD_TYPE_MAIN_ICON_BOX gd_main_icon_box_get_type()
+G_DECLARE_DERIVABLE_TYPE (GdMainIconBox, gd_main_icon_box, GD, MAIN_ICON_BOX, GtkBin)
+
+struct _GdMainIconBoxClass
+{
+  GtkBinClass parent_class;
+};
+
+GtkWidget * gd_main_icon_box_new (void);
+
+G_END_DECLS
+
+#endif /* __GD_MAIN_ICON_BOX_H__ */


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