]> saetta.ns0.it Git - zakform/cgi/commitdiff
Added property inline to ZakCgiFormElementRadio.
authorAndrea Zagli <azagli@libero.it>
Sat, 6 May 2017 09:39:34 +0000 (11:39 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 6 May 2017 09:39:34 +0000 (11:39 +0200)
src/formelementradio.c
src/formelementradio.h

index dd36ae4b9f862575bc27b09b45d1574b3a3af7e5..ac79493edf61c8a60b1883de170442c27960c314 100644 (file)
@@ -47,6 +47,7 @@ static void zak_form_cgi_form_element_radio_finalize (GObject *gobject);
 typedef struct _ZakFormCgiFormElementRadioPrivate ZakFormCgiFormElementRadioPrivate;
 struct _ZakFormCgiFormElementRadioPrivate
        {
+               gboolean in_line;
                GHashTable *ht_options;
        };
 
@@ -73,6 +74,7 @@ zak_form_cgi_form_element_radio_init (ZakFormCgiFormElementRadio *zak_form_cgi_f
 {
        ZakFormCgiFormElementRadioPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_RADIO_GET_PRIVATE (zak_form_cgi_form_element_radio);
 
+       priv->in_line = TRUE;
        priv->ht_options = g_hash_table_new (g_str_hash, g_str_equal);
 }
 
@@ -122,6 +124,22 @@ ZakFormCgiFormElement
        return zak_form_cgi_form_element_radio;
 }
 
+gboolean
+zak_form_cgi_form_element_radio_get_in_line (ZakFormCgiFormElementRadio *element)
+{
+       ZakFormCgiFormElementRadioPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_RADIO_GET_PRIVATE (element);
+
+       return priv->in_line;
+}
+
+void
+zak_form_cgi_form_element_radio_set_in_line (ZakFormCgiFormElementRadio *element, gboolean in_line)
+{
+       ZakFormCgiFormElementRadioPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_RADIO_GET_PRIVATE (element);
+
+       priv->in_line = in_line;
+}
+
 gboolean
 zak_form_cgi_form_element_radio_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
 {
@@ -145,18 +163,23 @@ zak_form_cgi_form_element_radio_xml_parsing (ZakFormElement *element, xmlNodePtr
        cur = xmlnode->children;
        while (cur != NULL)
                {
-                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                       if (xmlStrEqual (cur->name, (const xmlChar *)"id"))
                                {
                                        id = (gchar *)xmlNodeGetContent (cur);
                                }
-                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                       else if (xmlStrEqual (cur->name, (const xmlChar *)"label"))
                                {
                                        zak_form_cgi_form_element_set_label (ZAK_FORM_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL);
                                }
-                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                       else if (xmlStrEqual (cur->name, (const xmlChar *)"text"))
                                {
                                }
-                       else if (xmlStrcmp (cur->name, (const xmlChar *)"zak-cgi-options") == 0)
+                       else if (xmlStrEqual (cur->name, (const xmlChar *)"zak-cgi-inline"))
+                               {
+                                       zak_form_cgi_form_element_radio_set_in_line (ZAK_FORM_CGI_FORM_ELEMENT_RADIO (element),
+                                                                                    (gboolean)xmlStrEqual (xmlNodeGetContent (cur), (const xmlChar *)"TRUE"));
+                               }
+                       else if (xmlStrEqual (cur->name, (const xmlChar *)"zak-cgi-options"))
                                {
                                        xmlNode *xnode;
 
@@ -217,7 +240,7 @@ static gchar
 
        ZakFormCgiFormElementRadioPrivate *priv = ZAK_FORM_CGI_FORM_ELEMENT_RADIO_GET_PRIVATE (element);
 
-       ret = g_string_new ("<br/>\n");
+       ret = g_string_new ("");
 
        klass = (ZakFormCgiFormElementClass *)g_type_class_peek_parent (ZAK_FORM_CGI_FORM_ELEMENT_RADIO_GET_CLASS (ZAK_FORM_CGI_FORM_ELEMENT_RADIO (element)));
 
@@ -250,13 +273,18 @@ static gchar
                                        g_free (attr_class);
                                }
 
-                       g_string_append_printf (ret, "\n<label class=\"radio-inline\">\n%s%s</label>",
+                       g_string_append_printf (ret, "\n%s<label%s>\n%s %s</label>%s",
+                                               priv->in_line ? "" : "<div class=\"radio\">\n",
+                                               priv->in_line ? " class=\"radio-inline\"" : "",
                                                zak_cgi_tag_tag_ht ("input",
                                                                    g_strdup_printf ("%s_%d",
                                                                                      zak_form_cgi_form_element_get_id (element),
                                                                                     ++new_id),
                                                                    ht_attrs_option),
-                                               value);
+                                               value,
+                                               priv->in_line ? "" : "\n</div><br/>");
+
+                       g_hash_table_unref (ht_attrs_option);
                }
 
        ret_value = g_strdup (ret->str);
index a672ac296bc51030027d7bab5748853a86243905..aad6fd2085a55562b0c5f01c55f6c0b87bad82d4 100644 (file)
@@ -56,6 +56,9 @@ GType zak_form_cgi_form_element_radio_get_type (void);
 ZakFormCgiFormElement *zak_form_cgi_form_element_radio_new (void);
 ZakFormCgiFormElement *zak_form_cgi_form_element_radio_new_attrs (const gchar *id, ...);
 
+gboolean zak_form_cgi_form_element_radio_get_in_line (ZakFormCgiFormElementRadio *element);
+void zak_form_cgi_form_element_radio_set_in_line (ZakFormCgiFormElementRadio *element, gboolean in_line);
+
 gboolean zak_form_cgi_form_element_radio_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);