summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/html.c89
-rw-r--r--src/html.h3
2 files changed, 92 insertions, 0 deletions
diff --git a/src/html.c b/src/html.c
index 9380068..0e3ee36 100644
--- a/src/html.c
+++ b/src/html.c
@@ -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;
diff --git a/src/html.h b/src/html.h
index 84a133a..f80f897 100644
--- a/src/html.h
+++ b/src/html.h
@@ -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 *