indent -kr -i8 -brf -bbb -fnc -l132 -nce on all of webcit-classic
[citadel.git] / webcit / tabs.c
1 #include <stdarg.h>
2 #define SHOW_ME_VAPPEND_PRINTF
3 #include "webcit.h"
4
5 /*
6  * print tabbed dialog
7  */
8 void tabbed_dialog(int num_tabs, const char *tabnames[]) {
9         int i;
10
11         StrBufAppendPrintf(WC->trailing_javascript,
12                            "var previously_selected_tab = '0';                                          \n"
13                            "function tabsel(which_tab) {                                                        \n"
14                            "    if (which_tab == previously_selected_tab) {                             \n"
15                            "            return;                                                         \n"
16                            "    }                                                                       \n"
17                            "    $('tabdiv'+previously_selected_tab).style.display = 'none';             \n"
18                            "    $('tabdiv'+which_tab).style.display = 'block';                          \n"
19                            "    $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         \n"
20                            "    $('tabtd'+which_tab).className = 'tab_cell_label';                      \n"
21                            "    previously_selected_tab = which_tab;                                    \n"
22                            "}                                                                           \n");
23
24         wc_printf("<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
25                   "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>");
26
27         for (i = 0; i < num_tabs; ++i) {
28                 wc_printf("<td id=\"tabtd%d\" class=\"%s\" "
29                           "onClick='tabsel(\"%d\");'" ">", i, ((i == 0) ? "tab_cell_label" : "tab_cell_edit"), i);
30                 wc_printf("%s", tabnames[i]);
31                 wc_printf("</td>");
32
33                 wc_printf("<td>&nbsp;</td>\n");
34         }
35
36         wc_printf("</tr></table>\n");
37 }
38
39 /*
40  * print the tab-header
41  *
42  * tabnum:       number of the tab to print
43  * num_tabs:     total number oftabs to be printed
44  *
45  */
46 void begin_tab(int tabnum, int num_tabs) {
47
48         if (tabnum == num_tabs) {
49                 wc_printf("<!-- begin tab-common epilogue -->\n");
50                 wc_printf("<div class=\"tabcontent_submit\">");
51         }
52
53         else {
54                 wc_printf("<!-- begin tab %d of %d -->\n", tabnum, num_tabs);
55                 wc_printf("<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
56                           tabnum, ((tabnum == 0) ? "block" : "none")
57                     );
58         }
59 }
60
61 /*
62  * print the tab-footer
63  * tabnum:       number of the tab to print
64  * num_tabs:     total number of tabs to be printed
65  *
66  */
67 void end_tab(int tabnum, int num_tabs) {
68
69         if (tabnum == num_tabs) {
70                 wc_printf("</div> <!-- end of 'tabcontent_submit' div -->\n");
71                 wc_printf("<!-- end tab-common epilogue -->\n");
72         }
73
74         else {
75                 wc_printf("</div>\n");
76                 wc_printf("<!-- end tab %d of %d -->\n", tabnum, num_tabs);
77         }
78 }
79
80
81 /*
82  * print tabbed dialog
83  */
84 void StrTabbedDialog(StrBuf * Target, int num_tabs, StrBuf * tabnames[]) {
85         int i;
86
87         StrBufAppendBufPlain(Target,
88                              HKEY("<script type=\"text/javascript\">                                            "
89                                   "var previously_selected_tab = '0';                                           "
90                                   "function tabsel(which_tab) {                                                 "
91                                   "     if (which_tab == previously_selected_tab) {                             "
92                                   "             return;                                                         "
93                                   "     }                                                                       "
94                                   "     $('tabdiv'+previously_selected_tab).style.display = 'none';             "
95                                   "     $('tabdiv'+which_tab).style.display = 'block';                          "
96                                   "     $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         "
97                                   "     $('tabtd'+which_tab).className = 'tab_cell_label';                      "
98                                   "     previously_selected_tab = which_tab;                                    "
99                                   "}                                                                            "
100                                   "</script>                                                                    \n"), 0);
101
102         StrBufAppendBufPlain(Target,
103                              HKEY("<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
104                                   "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"), 0);
105
106         for (i = 0; i < num_tabs; ++i) {
107                 StrBufAppendPrintf(Target,
108                                    "<td id=\"tabtd%d\" class=\"%s\" "
109                                    "onClick='tabsel(\"%d\");'" ">", i, ((i == 0) ? "tab_cell_label" : "tab_cell_edit"), i);
110                 StrEscAppend(Target, tabnames[i], NULL, 0, 0);
111                 StrBufAppendBufPlain(Target, HKEY("</td>" "<td>&nbsp;</td>\n"), 0);
112         }
113
114         StrBufAppendBufPlain(Target, HKEY("</tr></table>\n"), 0);
115 }
116
117 /*
118  * print the tab-header
119  *
120  * tabnum:       number of the tab to print
121  * num_tabs:     total number oftabs to be printed
122  *
123  */
124 void StrBeginTab(StrBuf * Target, int tabnum, int num_tabs, StrBuf ** Names) {
125
126         if (tabnum == num_tabs) {
127                 StrBufAppendBufPlain(Target, HKEY("<!-- begin tab-common epilogue ["), 0);
128                 StrEscAppend(Target, Names[tabnum], NULL, 0, 2);
129                 StrBufAppendBufPlain(Target, HKEY("] -->\n<div class=\"tabcontent_submit\">"), 0);
130         }
131
132         else {
133                 StrBufAppendBufPlain(Target, HKEY("<!-- begin tab "), 0);
134                 StrBufAppendPrintf(Target, "%d of %d [", tabnum, num_tabs);
135
136                 StrEscAppend(Target, Names[tabnum], NULL, 0, 2);
137
138                 StrBufAppendPrintf(Target,
139                                    "] -->\n<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
140                                    tabnum, ((tabnum == 0) ? "block" : "none")
141                     );
142         }
143 }
144
145 /*
146  * print the tab-footer
147  * tabnum:       number of the tab to print
148  * num_tabs:     total number of tabs to be printed
149  *
150  */
151 void StrEndTab(StrBuf * Target, int tabnum, int num_tabs) {
152
153         if (tabnum == num_tabs) {
154                 StrBufAppendBufPlain(Target, HKEY("</div>\n" "<!-- end tab-common epilogue -->\n"), 0);
155         }
156
157         else {
158                 StrBufAppendPrintf(Target, "</div>\n", "<!-- end tab %d of %d -->\n", tabnum, num_tabs);
159         }
160         if (havebstr("last_tabsel")) {
161                 StrBufAppendPrintf(Target, "<script type=\"text/javascript\">tabsel(%s);</script>", BSTR("last_tabsel"));
162         }
163 }