New tabbed dialog API. This will be used in something later...
[citadel.git] / webcit / tabs.c
1 /*
2  * $Id:  $
3  *
4  * Utility functions for creating tabbed dialogs
5  */
6
7 #include "webcit.h"
8
9 void tabbed_dialog(int num_tabs, char *tabnames[]) {
10         int i;
11
12         wprintf("<script type=\"text/javascript\">                                              "
13                 "var previously_selected_tab = '0';                                             "
14                 "function tabsel(which_tab) {                                                   "
15                 "       if (which_tab == previously_selected_tab) {                             "
16                 "               return;                                                         "
17                 "       }                                                                       "
18                 "       $('tabtd'+previously_selected_tab).style.backgroundColor = '#cccccc';   "
19                 "       $('tabdiv'+previously_selected_tab).style.display = 'none';             "
20                 "       $('tabtd'+which_tab).style.backgroundColor = '#ffffff';                 "
21                 "       $('tabdiv'+which_tab).style.display = 'block';                          "
22                 "       previously_selected_tab = which_tab;                                    "
23                 "}                                                                              "
24                 "</script>                                                                      \n"
25         );
26
27         wprintf("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%%\">"
28                 "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
29         );
30
31         for (i=0; i<num_tabs; ++i) {
32                 wprintf("<td id=\"tabtd%d\" bgcolor=\"#%s\" onClick='tabsel(\"%d\");'>"
33                         "<span class=\"tablabel\">",
34                         i,
35                         ( (i==0) ? "ffffff" : "cccccc" ),
36                         i
37                 );
38                 wprintf("%s", tabnames[i]);
39                 wprintf("</td>");
40
41                 wprintf("<td>&nbsp;</td>\n");
42         }
43
44         wprintf("</tr></table>\n");
45         wprintf("<table border=\"0\" width=\"100%%\" bgcolor=\"#ffffff\"><tr><td>");
46 }
47
48 void begin_tab(int tabnum, int num_tabs) {
49         wprintf("<div id=\"tabdiv%d\" style=\"display:%s\">",
50                 tabnum,
51                 ( (tabnum == 0) ? "block" : "none" )
52         );
53 }
54
55 void end_tab(int tabnum, int num_tabs) {
56         wprintf("</div>\n");
57
58         if (tabnum == num_tabs-1) {
59                 wprintf("</td></tr></table>\n");
60         }
61 }