diff options
Diffstat (limited to 'src/html.c')
-rw-r--r-- | src/html.c | 89 |
1 files changed, 89 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; |