[libgd/wip/rishi/main-box: 5/11] Add GdMainIconBoxChild
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd/wip/rishi/main-box: 5/11] Add GdMainIconBoxChild
- Date: Fri, 2 Dec 2016 17:55:39 +0000 (UTC)
commit 7bcfddc2ff02368435c3c744e153c6b880058275
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 | 268 ++++++++++++++++++++++++++++++++++++++++
libgd/gd-main-icon-box-child.h | 43 +++++++
2 files changed, 311 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..dfe9e88
--- /dev/null
+++ b/libgd/gd-main-icon-box-child.c
@@ -0,0 +1,268 @@
+/*
+ * 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 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 (GdMainIconBoxChild *self)
+{
+ 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);
+ gint index;
+
+ index = gtk_flow_box_child_get_index (GTK_FLOW_BOX_CHILD (self));
+ return index;
+}
+
+static gboolean
+gd_main_icon_box_child_get_selected (GdMainBoxChild *child)
+{
+ GdMainIconBoxChild *self = GD_MAIN_ICON_BOX_CHILD (child);
+ gboolean selected;
+
+ selected = gtk_flow_box_child_is_selected (GTK_FLOW_BOX_CHILD (self));
+ return selected;
+}
+
+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_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 (G_OBJECT (self), "item");
+ 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 (G_OBJECT (self), "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 ();
+ gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (grid, GTK_ALIGN_CENTER);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
+ gtk_container_add (GTK_CONTAINER (self), grid);
+
+ overlay = gtk_overlay_new ();
+ gtk_widget_set_margin_bottom (overlay, 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_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);
+ 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_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
+ g_object_bind_property (priv->item, "primary-text", primary_label, "label", G_BINDING_SYNC_CREATE);
+ gtk_container_add (GTK_CONTAINER (grid), primary_label);
+
+ secondary_label = gtk_label_new (NULL);
+ gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
+ context = gtk_widget_get_style_context (secondary_label);
+ gtk_style_context_add_class (context, "dim-label");
+ g_object_bind_property (priv->item, "secondary-text", secondary_label, "label", G_BINDING_SYNC_CREATE);
+ 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_ICON_BOX_CHILD (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_icon_box_child_get_item (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_ICON_BOX_CHILD (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_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));
+
+ g_object_class_override_property (oclass, PROP_ITEM, "item");
+ g_object_class_override_property (oclass, PROP_SELECTION_MODE, "selection-mode");
+}
+
+static void
+gd_main_box_child_interface_init (GdMainBoxChildInterface *iface)
+{
+ iface->get_index = gd_main_icon_box_child_get_index;
+ iface->get_selected = gd_main_icon_box_child_get_selected;
+}
+
+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]