[libgd/wip/rishi/main-box: 6/8] Add GdMainIconBoxChild
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd/wip/rishi/main-box: 6/8] Add GdMainIconBoxChild
- Date: Fri, 25 Nov 2016 18:01:53 +0000 (UTC)
commit ad1226d2f5fc1ffaee3fecfa82fa29e9edd8519d
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 | 279 ++++++++++++++++++++++++++++++++++++++++
libgd/gd-main-icon-box-child.h | 43 ++++++
2 files changed, 322 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..4d606b7
--- /dev/null
+++ b/libgd/gd-main-icon-box-child.c
@@ -0,0 +1,279 @@
+/*
+ * 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-child.h"
+#include "gd-main-icon-box-child.h"
+
+#include <gio/gio.h>
+#include <glib/gi18n.h>
+
+typedef struct _GdMainIconBoxChildPrivate GdMainIconBoxChildPrivate;
+
+struct _GdMainIconBoxChildPrivate
+{
+ GdMainBoxItem *item;
+ gboolean selection_mode;
+};
+
+enum
+{
+ PROP_ITEM = 1,
+ PROP_SELECTION_MODE,
+ NUM_PROPERTIES
+};
+
+static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
+
+static void gd_main_box_child_interface_init (GdMainBoxChildInterface *iface);
+G_DEFINE_TYPE_WITH_CODE (GdMainIconBoxChild, gd_main_icon_box_child, GTK_TYPE_FLOW_BOX_CHILD,
+ G_ADD_PRIVATE (GdMainIconBoxChild)
+ G_IMPLEMENT_INTERFACE (GD_TYPE_MAIN_BOX_CHILD, gd_main_box_child_interface_init))
+
+static GdMainBoxItem *
+gd_main_icon_box_child_get_item (GdMainBoxChild *child)
+{
+ GdMainIconBoxChild *self = GD_MAIN_ICON_BOX_CHILD (child);
+ GdMainIconBoxChildPrivate *priv;
+
+ priv = gd_main_icon_box_child_get_instance_private (self);
+ return priv->item;
+}
+
+static gint
+gd_main_icon_box_child_get_index (GdMainBoxChild *child)
+{
+ GdMainIconBoxChild *self = GD_MAIN_ICON_BOX_CHILD (child);
+
+ index = gtk_flow_box_child_get_index (GTK_FLOW_BOX_CHILD (self));
+ return index;
+}
+
+static gboolean
+gd_main_icon_box_child_get_selection_mode (GdMainBoxChild *child)
+{
+ GdMainIconBoxChild *self = GD_MAIN_ICON_BOX_CHILD (child);
+ GdMainIconBoxChildPrivate *priv;
+
+ priv = gd_main_icon_box_child_get_instance_private (self);
+ return priv->selection_mode;
+}
+
+static void
+gd_main_icon_box_child_set_item (GdMainIconBoxChild *self, GdMainBoxItem *item)
+{
+ GdMainIconBoxChildPrivate *priv;
+
+ priv = gd_main_icon_box_child_get_instance_private (self);
+
+ if (!g_set_object (&priv->item, item))
+ return;
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ITEM]);
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
+static void
+gd_main_icon_box_child_set_selection_mode (GdMainBoxChild *child, gboolean selection_mode)
+{
+ GdMainIconBoxChild *self = GD_MAIN_ICON_BOX_CHILD (child);
+ 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;
+ GtkStyleContext *context;
+ GtkWidget *check_button;
+ GtkWidget *grid;
+ GtkWidget *image;
+ GtkWidget *overlay;
+ GtkWidget *primary_label;
+ GtkWidget *secondary_label;
+ 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_item_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_item_get_icon (priv->item);
+ image = gtk_image_new_from_surface (icon);
+ gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (image, GTK_ALIGN_END);
+ gtk_container_add (GTK_CONTAINER (overlay), image);
+
+ check_button = gtk_check_button_new ();
+ gtk_widget_set_halign (check_button, GTK_ALIGN_END);
+ gtk_widget_set_valign (check_button, GTK_ALIGN_END);
+ gtk_widget_set_no_show_all (check_button, TRUE);
+ context = gtk_widget_get_style_context (self->primary_label);
+ gtk_style_context_add_class (context, "osd");
+ g_object_bind_property (self, "selection-mode", check_button, "visible", G_BINDING_SYNC_CREATE);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), check_button);
+
+ primary_label = gtk_label_new (NULL);
+ gtk_container_add (GTK_CONTAINER (grid), primary_label);
+
+ secondary_label = gtk_label_new (NULL);
+ context = gtk_widget_get_style_context (secondary_label);
+ gtk_style_context_add_class (context, "dim-label");
+ gtk_container_add (GTK_CONTAINER (grid), secondary_label);
+}
+
+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->item);
+
+ 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_ITEM:
+ g_value_set_object (value, gd_main_box_child_get_item (GD_MAIN_BOX_CHILD (self)));
+ break;
+ case PROP_SELECTION_MODE:
+ g_value_set_boolean (value, gd_main_box_child_get_selection_mode (GD_MAIN_BOX_CHILD (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_ITEM:
+ gd_main_icon_box_child_set_item (self, g_value_get_object (value));
+ break;
+ case PROP_SELECTION_MODE:
+ gd_main_box_child_set_selection_mode (GD_MAIN_BOX_CHILD (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_ITEM] = g_param_spec_object ("item",
+ "Item",
+ "The GdMainBoxItem",
+ GD_TYPE_MAIN_BOX_ITEM,
+ 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);
+}
+
+static void
+gd_main_box_child_interface_init (GdMainBoxChildInterface *iface)
+{
+ iface->get_item = gd_main_icon_box_child_get_item;
+ iface->get_index = gd_main_icon_box_child_get_index;
+ iface->get_selection_mode = gd_main_icon_box_get_selection_mode;
+ iface->set_selection_mode = gd_main_icon_box_set_selection_mode;
+}
+
+GtkWidget *
+gd_main_icon_box_child_new (GdMainBoxItem *item, gboolean selection_mode)
+{
+ return g_object_new (GD_TYPE_MAIN_ICON_BOX_CHILD,
+ "item", item,
+ "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..40eb271
--- /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-item.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 (GdMainBoxItem *item, 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]