]> saetta.ns0.it Git - zakform/gtk/commitdiff
Added ZakFormGtkFormElementRadio.
authorAndrea Zagli <azagli@libero.it>
Thu, 26 Nov 2015 19:10:54 +0000 (20:10 +0100)
committerAndrea Zagli <azagli@libero.it>
Thu, 26 Nov 2015 19:10:54 +0000 (20:10 +0100)
src/Makefile.am
src/formelement.h
src/formelementradio.c [new file with mode: 0644]
src/formelementradio.h [new file with mode: 0644]
src/libzakformgtk.h

index 44227d6bdcfd95a5b5728195ac6804adee4aab7e..f6a23b24a60b214f06050910125cc1086b3adb71 100644 (file)
@@ -12,6 +12,7 @@ libzakformgtk_la_SOURCES = \
                         formelementcheck.c \
                         formelemententry.c \
                         formelementlabel.c \
+                        formelementradio.c \
                         formelementspin.c \
                         formelementtextview.c
 
@@ -24,6 +25,7 @@ libzakformgtk_include_HEADERS = \
                              formelementcheck.h \
                              formelemententry.h \
                              formelementlabel.h \
+                             formelementradio.h \
                              formelementspin.h \
                              formelementtextview.h
 
index d193f1b8cf63fb613ce43e89291a48b24d8a3f85..9b59849e19ba9fccbb426897a8b477dcdb9c4c8b 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <gtk/gtk.h>
 
+#include <libxml/tree.h>
+
 #include <libzakform/libzakform.h>
 
 
diff --git a/src/formelementradio.c b/src/formelementradio.c
new file mode 100644 (file)
index 0000000..7204db9
--- /dev/null
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+       #include <config.h>
+#endif
+
+#include "formelementradio.h"
+
+enum
+{
+       PROP_0,
+       PROP_RETURN_VALUE
+};
+
+static void zak_form_gtk_form_element_radio_class_init (ZakFormGtkFormElementRadioClass *class);
+static void zak_form_gtk_form_element_radio_init (ZakFormGtkFormElementRadio *zak_form_gtk_form_element_radio);
+
+static void zak_form_gtk_form_element_radio_set_property (GObject *object,
+                               guint property_id,
+                               const GValue *value,
+                               GParamSpec *pspec);
+static void zak_form_gtk_form_element_radio_get_property (GObject *object,
+                               guint property_id,
+                               GValue *value,
+                               GParamSpec *pspec);
+
+static void zak_form_gtk_form_element_radio_dispose (GObject *gobject);
+static void zak_form_gtk_form_element_radio_finalize (GObject *gobject);
+
+static gchar *zak_form_gtk_form_element_radio_get_value (ZakFormGtkFormElementRadio *element);
+static gboolean zak_form_gtk_form_element_radio_set_value (ZakFormGtkFormElementRadio *element, const gchar *value);
+
+#define ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_RADIO, ZakFormGtkFormElementRadioPrivate))
+
+typedef struct _ZakFormGtkFormElementRadioPrivate ZakFormGtkFormElementRadioPrivate;
+struct _ZakFormGtkFormElementRadioPrivate
+       {
+               gchar *return_value;
+       };
+
+G_DEFINE_TYPE (ZakFormGtkFormElementRadio, zak_form_gtk_form_element_radio, ZAK_FORM_GTK_TYPE_FORM_ELEMENT)
+
+static void
+zak_form_gtk_form_element_radio_class_init (ZakFormGtkFormElementRadioClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       ZakFormElementClass *elem_class = ZAK_FORM_ELEMENT_CLASS (klass);
+
+       object_class->set_property = zak_form_gtk_form_element_radio_set_property;
+       object_class->get_property = zak_form_gtk_form_element_radio_get_property;
+       object_class->dispose = zak_form_gtk_form_element_radio_dispose;
+       object_class->finalize = zak_form_gtk_form_element_radio_finalize;
+
+       elem_class->get_value = zak_form_gtk_form_element_radio_get_value;
+       elem_class->set_value = zak_form_gtk_form_element_radio_set_value;
+
+       g_type_class_add_private (object_class, sizeof (ZakFormGtkFormElementRadioPrivate));
+
+       g_object_class_install_property (object_class, PROP_RETURN_VALUE,
+                                        g_param_spec_string ("return-value",
+                                                             "Return value",
+                                                             "Return value",
+                                                             "",
+                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+}
+
+static void
+zak_form_gtk_form_element_radio_init (ZakFormGtkFormElementRadio *zak_form_gtk_form_element_radio)
+{
+       ZakFormGtkFormElementRadioPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_PRIVATE (zak_form_gtk_form_element_radio);
+
+}
+
+/**
+ * zak_form_gtk_form_element_radio_new:
+ *
+ * Returns: the newly created #ZakFormGtkFormElementRadio object.
+ */
+ZakFormGtkFormElement
+*zak_form_gtk_form_element_radio_new ()
+{
+       ZakFormGtkFormElementRadio *zak_form_gtk_form_element_radio;
+
+       zak_form_gtk_form_element_radio = ZAK_FORM_GTK_FORM_ELEMENT_RADIO (g_object_new (zak_form_gtk_form_element_radio_get_type (), NULL));
+
+       return ZAK_FORM_GTK_FORM_ELEMENT (zak_form_gtk_form_element_radio);
+}
+
+/**
+ * zak_form_gtk_form_element_radio_xml_parsing:
+ * @element:
+ * @xmlnode:
+ *
+ */
+gboolean
+zak_form_gtk_form_element_radio_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       xmlNode *cur;
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"return-value") == 0)
+                               {
+                                       zak_form_gtk_form_element_radio_set_return_value (element, (gchar *)xmlNodeGetContent (cur));
+                               }
+
+                       cur = cur->next;
+               }
+
+       return TRUE;
+}
+
+/**
+ * zak_form_gtk_form_element_radio_set_return_value:
+ * @element:
+ * @value:
+ *
+ */
+void
+zak_form_gtk_form_element_radio_set_return_value (ZakFormGtkFormElementRadio *element, const gchar *value)
+{
+       GtkWidget *w;
+
+       ZakFormGtkFormElementRadioPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_PRIVATE (element);
+
+       if (priv->return_value != NULL)
+               {
+                       g_free (priv->return_value);
+               }
+       priv->return_value = g_strdup (value);
+
+       w = zak_form_gtk_form_element_get_widget (ZAK_FORM_GTK_FORM_ELEMENT (element));
+
+       g_object_set_data (G_OBJECT (w), "return-value", (gpointer)priv->return_value);
+}
+
+/**
+ * zak_form_gtk_form_element_radio_get_return_value:
+ * @element:
+ *
+ */
+gchar
+*zak_form_gtk_form_element_radio_get_return_value (ZakFormGtkFormElementRadio *element)
+{
+       ZakFormGtkFormElementRadioPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_PRIVATE (element);
+
+       return g_strdup (priv->return_value);
+}
+
+/* PRIVATE */
+static void
+zak_form_gtk_form_element_radio_set_property (GObject *object,
+                   guint property_id,
+                   const GValue *value,
+                   GParamSpec *pspec)
+{
+       ZakFormGtkFormElementRadio *zak_form_gtk_form_element_radio = (ZakFormGtkFormElementRadio *)object;
+       ZakFormGtkFormElementRadioPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_PRIVATE (zak_form_gtk_form_element_radio);
+
+       switch (property_id)
+               {
+               case PROP_RETURN_VALUE:
+                       zak_form_gtk_form_element_radio_set_value (zak_form_gtk_form_element_radio, g_value_get_string (value));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+               }
+}
+
+static void
+zak_form_gtk_form_element_radio_get_property (GObject *object,
+                   guint property_id,
+                   GValue *value,
+                   GParamSpec *pspec)
+{
+       ZakFormGtkFormElementRadio *zak_form_gtk_form_element_radio = (ZakFormGtkFormElementRadio *)object;
+       ZakFormGtkFormElementRadioPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_PRIVATE (zak_form_gtk_form_element_radio);
+
+       switch (property_id)
+               {
+               case PROP_RETURN_VALUE:
+                       g_value_set_string (value, zak_form_gtk_form_element_radio_get_value (zak_form_gtk_form_element_radio));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                       break;
+               }
+}
+
+static void
+zak_form_gtk_form_element_radio_dispose (GObject *gobject)
+{
+       ZakFormGtkFormElementRadio *zak_form_gtk_form_element_radio = (ZakFormGtkFormElementRadio *)gobject;
+       ZakFormGtkFormElementRadioPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_PRIVATE (zak_form_gtk_form_element_radio);
+
+
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->dispose (gobject);
+}
+
+static void
+zak_form_gtk_form_element_radio_finalize (GObject *gobject)
+{
+       ZakFormGtkFormElementRadio *zak_form_gtk_form_element_radio = (ZakFormGtkFormElementRadio *)gobject;
+       ZakFormGtkFormElementRadioPrivate *priv = ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_PRIVATE (zak_form_gtk_form_element_radio);
+
+
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->finalize (gobject);
+}
+
+static gchar
+*zak_form_gtk_form_element_radio_get_value (ZakFormGtkFormElementRadio *element)
+{
+       gchar *ret;
+
+       GtkWidget *w;
+
+       GSList *group;
+
+       w = zak_form_gtk_form_element_get_widget (ZAK_FORM_GTK_FORM_ELEMENT (element));
+
+       ret = g_strdup ("");
+       group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
+       while (group != NULL)
+               {
+                       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (group->data)))
+                               {
+                                       ret = (gchar *)g_object_get_data (G_OBJECT (group->data), "return-value");
+                                       if (ret == NULL)
+                                               {
+                                                       ret = g_strdup ("");
+                                               }
+                                       break;
+                               }
+
+                       group = g_slist_next (group);
+               }
+
+       return ret;
+}
+
+static gboolean
+zak_form_gtk_form_element_radio_set_value (ZakFormGtkFormElementRadio *element, const gchar *value)
+{
+       GtkWidget *w;
+
+       GSList *group;
+
+       w = zak_form_gtk_form_element_get_widget (ZAK_FORM_GTK_FORM_ELEMENT (element));
+
+       group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
+       while (group != NULL)
+               {
+                       if (g_strcmp0 ((gchar *)g_object_get_data (G_OBJECT (group->data), "return-value"), value) == 0)
+                               {
+                                       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (group->data), TRUE);
+                                       break;
+                               }
+
+                       group = g_slist_next (group);
+               }
+
+       return TRUE;
+}
diff --git a/src/formelementradio.h b/src/formelementradio.h
new file mode 100644 (file)
index 0000000..ba65bc7
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * This library 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.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __ZAK_FORM_GTK_FORM_ELEMENT_RADIO_H__
+#define __ZAK_FORM_GTK_FORM_ELEMENT_RADIO_H__
+
+
+#include <glib-object.h>
+
+#include "formelement.h"
+
+
+G_BEGIN_DECLS
+
+
+#define ZAK_FORM_GTK_TYPE_FORM_ELEMENT_RADIO                 (zak_form_gtk_form_element_radio_get_type ())
+#define ZAK_FORM_GTK_FORM_ELEMENT_RADIO(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_RADIO, ZakFormGtkFormElementRadio))
+#define ZAK_FORM_GTK_FORM_ELEMENT_RADIO_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_RADIO, ZakFormGtkFormElementRadioClass))
+#define ZAK_FORM_GTK_IS_FORM_ELEMENT_RADIO(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_RADIO))
+#define ZAK_FORM_GTK_IS_FORM_ELEMENT_RADIO_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_RADIO))
+#define ZAK_FORM_GTK_FORM_ELEMENT_RADIO_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_FORM_GTK_TYPE_FORM_ELEMENT_RADIO, ZakFormGtkFormElementRadioClass))
+
+typedef struct _ZakFormGtkFormElementRadio ZakFormGtkFormElementRadio;
+typedef struct _ZakFormGtkFormElementRadioClass ZakFormGtkFormElementRadioClass;
+
+struct _ZakFormGtkFormElementRadio
+       {
+               ZakFormGtkFormElement parent_instance;
+       };
+
+struct _ZakFormGtkFormElementRadioClass
+       {
+               ZakFormGtkFormElementClass parent_class;
+       };
+
+
+GType zak_form_gtk_form_element_radio_get_type (void);
+
+ZakFormGtkFormElement *zak_form_gtk_form_element_radio_new (void);
+
+gboolean zak_form_gtk_form_element_radio_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
+
+void zak_form_gtk_form_element_radio_set_return_value (ZakFormGtkFormElementRadio *element, const gchar *value);
+gchar *zak_form_gtk_form_element_radio_get_return_value (ZakFormGtkFormElementRadio *element);
+
+
+G_END_DECLS
+
+
+#endif /* __ZAK_FORM_GTK_FORM_ELEMENT_RADIO_H__ */
index 05cc83d54fb875b7c643a68dc62bd8388ab5e58e..76b657bfb8650475760e99b420047cca29891bbe 100644 (file)
@@ -26,6 +26,7 @@
 #include <libzakformgtk/formelementcheck.h>
 #include <libzakformgtk/formelemententry.h>
 #include <libzakformgtk/formelementlabel.h>
+#include <libzakformgtk/formelementradio.h>
 #include <libzakformgtk/formelementspin.h>
 #include <libzakformgtk/formelementtextview.h>