[libgd/wip/rishi/main-box: 6/7] Add GdMainIconBoxChild



commit 27116c2b626f4d1ba034509cd8eb3f6ec6745039
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Nov 23 17:33:59 2016 +0100

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

 libgd/gd-main-icon-box-child.c |  241 ++++++++++++++++++++++++++++++++++++++++
 libgd/gd-main-icon-box-child.h |   43 +++++++
 2 files changed, 284 insertions(+), 0 deletions(-)
---
diff --git a/libgd/gd-main-icon-box-child.c b/libgd/gd-main-icon-box-child.c
new file mode 100644
index 0000000..f0e70d9
--- /dev/null
+++ b/libgd/gd-main-icon-box-child.c
@@ -0,0 +1,241 @@
+/*
+ * 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-child.h"
+#include "gd-main-box-displayable.h"
+
+#include <gio/gio.h>
+#include <glib/gi18n.h>
+
+typedef struct _GdMainIconBoxChildPrivate GdMainIconBoxChildPrivate;
+
+struct _GdMainIconBoxChildPrivate
+{
+  GdMainBoxDisplayable *displayable;
+  gboolean selection_mode;
+};
+
+enum
+{
+  PROP_DISPLAYABLE = 1,
+  PROP_SELECTION_MODE,
+  NUM_PROPERTIES
+};
+
+static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
+
+G_DEFINE_TYPE_WITH_PRIVATE (GdMainIconBoxChild, gd_main_icon_box_child, GTK_TYPE_FLOW_BOX_CHILD)
+
+static GdMainIconBoxChild *
+gd_main_icon_box_child_get_displayable (GdMainIconBoxChild *self)
+{
+  GdMainIconBoxChildPrivate *priv;
+
+  priv = gd_main_icon_box_child_get_instance_private (self);
+  return priv->displayable;
+}
+
+static gboolean
+gd_main_icon_box_child_get_selection_mode (GdMainIconBoxChild *self)
+{
+  GdMainIconBoxChildPrivate *priv;
+
+  priv = gd_main_icon_box_child_get_instance_private (self);
+  return priv->selection_mode;
+}
+
+static void
+gd_main_icon_box_child_set_displayable (GdMainIconBoxChild *self, GdMainBoxDisplayable *displayable)
+{
+  GdMainIconBoxChildPrivate *priv;
+
+  priv = gd_main_icon_box_child_get_instance_private (self);
+
+  if (g_set_object (&priv->displayable, displayable))
+    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DISPLAYABLE]);
+
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
+static void
+gd_main_icon_box_child_set_selection_mode (GdMainIconBoxChild *self, gboolean selection_mode)
+{
+  GdMainIconBoxChildPrivate *priv;
+
+  priv = gd_main_icon_box_child_get_instance_private (self);
+
+  if (priv->selection_mode == selection_mode)
+    return;
+
+  priv->selection_mode = selection_mode;
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTION_MODE]);
+
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
+static void
+gd_main_icon_box_child_constructed (GObject *obj)
+{
+  GdMainIconBoxChild *self = GD_MAIN_ICON_BOX_CHILD (obj);
+  GdMainIconBoxChildPrivate *priv;
+  GtkWidget *check_button;
+  GtkWidget *grid;
+  GtkWidget *image;
+  GtkWidget *overlay;
+  cairo_surface_t *icon;
+
+  priv = gd_main_icon_box_child_get_instance_private (self);
+
+  G_OBJECT_CLASS (gd_main_icon_box_child_parent_class)->constructed (obj);
+
+  grid = gtk_grid_new ();
+  gd_main_box_displayable_get_icon (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
+  gtk_container_add (GTK_CONTAINER (self), grid);
+
+  overlay = gtk_overlay_new ();
+  gtk_widget_set_margin_bottom (priv->flow_box, 4);
+  gtk_container_add (GTK_CONTAINER (grid), overlay);
+
+  icon = gd_main_box_displayable_get_icon (priv->displayable);
+  image = gtk_image_new_from_surface (icon);
+  gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (image, GTK_ALIGN_CENTER);
+  gtk_container_add (GTK_CONTAINER (overlay), image);
+
+  check_button = gtk_check_button_new ();
+  gtk_widget_set_halign (image, GTK_ALIGN_END);
+  gtk_widget_set_valign (image, GTK_ALIGN_END);
+  gtk_widget_set_no_show_all (check_button, TRUE);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), check_button);
+}
+
+static void
+gd_main_icon_box_child_dispose (GObject *obj)
+{
+  GdMainIconBoxChild *self = GD_MAIN_ICON_BOX_CHILD (obj);
+  GdMainIconBoxChildPrivate *priv;
+
+  priv = gd_main_icon_box_child_get_instance_private (self);
+
+  g_clear_object (&priv->displayable);
+
+  G_OBJECT_CLASS (gd_main_icon_box_child_parent_class)->dispose (obj);
+}
+
+static void
+gd_main_icon_box_child_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+  GdMainIconBoxChild *self = GD_MAIN_VIEW (object);
+  GdMainIconBoxChildPrivate *priv;
+
+  priv = gd_main_icon_box_child_get_instance_private (self);
+
+  switch (property_id)
+    {
+    case PROP_DISPLAYABLE:
+      g_value_set_object (value, gd_main_icon_box_child_get_displayable (self));
+      break;
+    case PROP_SELECTION_MODE:
+      g_value_set_boolean (value, gd_main_icon_box_child_get_selection_mode (self));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gd_main_icon_box_child_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec 
*pspec)
+{
+  GdMainIconBoxChild *self = GD_MAIN_VIEW (object);
+  GdMainIconBoxChildPrivate *priv;
+
+  priv = gd_main_icon_box_child_get_instance_private (self);
+
+  switch (property_id)
+    {
+    case PROP_DISPLAYABLE:
+      gd_main_icon_box_child_set_displayable (self, g_value_get_object (value));
+      break;
+    case PROP_SELECTION_MODE:
+      gd_main_icon_box_child_set_selection_mode (self, g_value_get_boolean (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gd_main_icon_box_child_init (GdMainIconBoxChild *self)
+{
+}
+
+static void
+gd_main_icon_box_child_class_init (GdMainIconBoxChildClass *klass)
+{
+  GObjectClass *oclass = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
+  GdkModifierType activate_modifiers[] = { GDK_SHIFT_MASK, GDK_CONTROL_MASK, GDK_SHIFT_MASK | 
GDK_CONTROL_MASK };
+
+  oclass->constructed = gd_main_icon_box_child_constructed;
+  oclass->dispose = gd_main_icon_box_child_dispose;
+  oclass->get_property = gd_main_icon_box_child_get_property;
+  oclass->set_property = gd_main_icon_box_child_set_property;
+
+  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));
+
+  properties[PROP_DISPLAYABLE] = g_param_spec_object ("displayable",
+                                                      "Displayable",
+                                                      "The GdMainBoxDisplayable",
+                                                      GD_TYPE_MAIN_BOX_DISPLAYABLE,
+                                                      G_PARAM_CONSTRUCT_ONLY |
+                                                      G_PARAM_EXPLICIT_NOTIFY |
+                                                      G_PARAM_READWRITE |
+                                                      G_PARAM_STATIC_STRINGS);
+
+  properties[PROP_SELECTION_MODE] = g_param_spec_boolean ("selection-mode",
+                                                          "Selection mode",
+                                                          "Whether the child is in selection mode",
+                                                          FALSE,
+                                                          G_PARAM_CONSTRUCT |
+                                                          G_PARAM_EXPLICIT_NOTIFY |
+                                                          G_PARAM_READWRITE |
+                                                          G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+}
+
+GtkWidget *
+gd_main_icon_box_child_new (GdMainBoxDisplayable *displayable, gboolean selection_mode)
+{
+  return g_object_new (GD_TYPE_MAIN_ICON_BOX_CHILD,
+                       "displayable", displayable,
+                       "selection-mode", selection_mode,
+                       NULL);
+}
diff --git a/libgd/gd-main-icon-box-child.h b/libgd/gd-main-icon-box-child.h
new file mode 100644
index 0000000..9de27f4
--- /dev/null
+++ b/libgd/gd-main-icon-box-child.h
@@ -0,0 +1,43 @@
+/*
+ * 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_CHILD_H__
+#define __GD_MAIN_ICON_BOX_CHILD_H__
+
+#include <gtk/gtk.h>
+
+#include "gd-main-box-displayable.h"
+
+G_BEGIN_DECLS
+
+#define GD_TYPE_MAIN_ICON_BOX_CHILD gd_main_icon_box_child_get_type()
+G_DECLARE_DERIVABLE_TYPE (GdMainIconBoxChild, gd_main_icon_box_child, GD, MAIN_ICON_BOX_CHILD, 
GtkFlowBoxChild)
+
+struct _GdMainIconBoxChildClass
+{
+  GtkFlowBoxChildClass parent_class;
+};
+
+GtkWidget * gd_main_icon_box_child_new (GdMainBoxDisplayable *displayable, gboolean selection_mode);
+
+G_END_DECLS
+
+#endif /* __GD_MAIN_ICON_BOX_CHILD_H__ */


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