diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-09-30 19:23:24 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-09-30 19:23:24 (EDT) |
commit | 89f9769dd414de3ae090b30dda04cb01cb9034b0 (patch) | |
tree | b3782948c608898c5ca2e73db200fecc8a4b2109 | |
parent | 8f3e4ae1db8220df1ba2884f4dffa352a7c6e91d (diff) | |
download | marquee-89f9769dd414de3ae090b30dda04cb01cb9034b0.zip marquee-89f9769dd414de3ae090b30dda04cb01cb9034b0.tar.gz marquee-89f9769dd414de3ae090b30dda04cb01cb9034b0.tar.bz2 |
mq_html_notebook(): New function
-rw-r--r-- | src/html.c | 89 | ||||
-rw-r--r-- | src/html.h | 3 |
2 files changed, 92 insertions, 0 deletions
@@ -27,6 +27,95 @@ #include "html.h" gchar * +mq_html_notebook(gboolean vertical, const gchar *name, ...) +{ + gsize name_len; + gsize len; + va_list ap; + gsize i; + gchar *child; + gchar *tab_label; + gchar *i_str; + gchar *notebook; + gchar *ptr; + + /* Calculate length. */ + name_len = strlen(name); + len = strlen("<div class=\"notebook-") + 1 + strlen("\">\n"); + va_start(ap, name); + i = 0; + while ((child = va_arg(ap, gchar *)) && + (tab_label = va_arg(ap, gchar *))) { + i_str = g_strdup_printf("%zu", i); + len += strlen("<input id=\"_tab_"); + len += name_len; + len += strlen("_"); + len += strlen(i_str); + /* len += (gsize) log10(i) + 1; */ + len += strlen("\" type=\"radio\" checked=\"checked\" " + "name=\"_tabs\"></input>\n"); + len += strlen("<label for=\"_tab_"); + len += name_len; + len += strlen("_"); + len += strlen(i_str); + /* len += (gsize) log10(i) + 1; */ + len += strlen("\">"); + len += strlen(tab_label); + len += strlen("</label>\n"); + ++i; + } + va_end(ap); + va_start(ap, name); + while ((child = va_arg(ap, gchar *)) && + (tab_label = va_arg(ap, gchar *))) { + /* TODO: Page ID and control CSS */ + len += strlen(child); + } + va_end(ap); + len += strlen("</div>\n"); + ++len; /* NUL byte */ + + /* Build string. */ + notebook = g_new(gchar, len); + ptr = g_stpcpy(notebook, "<div class=\"notebook-"); + ptr = g_stpcpy(ptr, vertical ? "v" : "h"); + ptr = g_stpcpy(ptr, "\">\n"); + va_start(ap, name); + i = 0; + while ((child = va_arg(ap, gchar *)) && + (tab_label = va_arg(ap, gchar *))) { + i_str = g_strdup_printf("%zu", i); + ptr = g_stpcpy(ptr, "<input id=\"_tab_"); + ptr = g_stpcpy(ptr, name); + ptr = g_stpcpy(ptr, "_"); + ptr = g_stpcpy(ptr, i_str); + ptr = g_stpcpy(ptr, "\" type=\"radio\" checked=\"checked\" " + "name=\"_tabs\"></input>\n"); + ptr = g_stpcpy(ptr, "<label for=\"_tab_"); + ptr = g_stpcpy(ptr, name); + ptr = g_stpcpy(ptr, "_"); + ptr = g_stpcpy(ptr, i_str); + ptr = g_stpcpy(ptr, "\">"); + ptr = g_stpcpy(ptr, tab_label); + ptr = g_stpcpy(ptr, "</label>\n"); + g_free(i_str); + ++i; + } + va_end(ap); + va_start(ap, name); + while ((child = va_arg(ap, gchar *)) && + (tab_label = va_arg(ap, gchar *))) { + /* TODO: Page ID and control CSS */ + ptr = g_stpcpy(ptr, child); + g_free(child); + } + va_end(ap); + ptr = g_stpcpy(ptr, "</div>\n"); /* g_stpcpy() adds the NUL. */ + + return notebook; +} + +gchar * mq_html_form(const gchar *submit_label, const gchar *reset_label, ...) { gsize len; @@ -25,6 +25,9 @@ #include <glib.h> gchar * +mq_html_notebook(gboolean vertical, const gchar *name, ...); + +gchar * mq_html_form(const gchar *submit_label, const gchar *reset_label, ...); gchar * |