* made *bstr things const
[citadel.git] / webcit / tabs.c
1 /*
2  * $Id$
3  *
4  */
5 #include <stdarg.h>
6 #define SHOW_ME_VAPPEND_PRINTF
7 #include "webcit.h"
8
9 /*
10  * print tabbed dialog
11  */
12 void tabbed_dialog(int num_tabs, char *tabnames[]) {
13         int i;
14
15         wprintf("<script type=\"text/javascript\">                                              "
16                 "var previously_selected_tab = '0';                                             "
17                 "function tabsel(which_tab) {                                                   "
18                 "       if (which_tab == previously_selected_tab) {                             "
19                 "               return;                                                         "
20                 "       }                                                                       "
21                 "       $('tabdiv'+previously_selected_tab).style.display = 'none';             "
22                 "       $('tabdiv'+which_tab).style.display = 'block';                          "
23                 "       $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         "
24                 "       $('tabtd'+which_tab).className = 'tab_cell_label';                      "
25                 "       previously_selected_tab = which_tab;                                    "
26                 "}                                                                              "
27                 "</script>                                                                      \n"
28         );
29
30         wprintf("<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
31                 "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
32         );
33
34         for (i=0; i<num_tabs; ++i) {
35                 wprintf("<td id=\"tabtd%d\" class=\"%s\" "
36                         "onClick='tabsel(\"%d\");'"
37                         ">",
38                         i,
39                         ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
40                         i
41                         );
42                 wprintf("%s", tabnames[i]);
43                 wprintf("</td>");
44
45                 wprintf("<td>&nbsp;</td>\n");
46         }
47
48         wprintf("</tr></table>\n");
49 }
50
51 /*
52  * print the tab-header
53  *
54  * tabnum:       number of the tab to print
55  * num_tabs:     total number oftabs to be printed
56  *
57  */
58 void begin_tab(int tabnum, int num_tabs) {
59
60         if (tabnum == num_tabs) {
61                 wprintf("<!-- begin tab-common epilogue -->\n");
62                 wprintf("<div class=\"tabcontent_submit\">");
63         }
64
65         else {
66                 wprintf("<!-- begin tab %d of %d -->\n", tabnum, num_tabs);
67                 wprintf("<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
68                         tabnum,
69                         ( (tabnum == 0) ? "block" : "none" )
70                 );
71         }
72 }
73
74 /*
75  * print the tab-footer
76  * tabnum:       number of the tab to print
77  * num_tabs:     total number of tabs to be printed
78  *
79  */
80 void end_tab(int tabnum, int num_tabs) {
81
82         if (tabnum == num_tabs) {
83                 wprintf("</div>\n");
84                 wprintf("<!-- end tab-common epilogue -->\n");
85         }
86
87         else {
88                 wprintf("</div>\n");
89                 wprintf("<!-- end tab %d of %d -->\n", tabnum, num_tabs);
90         
91                 if (tabnum == num_tabs-1) {
92                         wprintf("<script type=\"text/javascript\">"
93                                 " Nifty(\"table#TheTabs td\", \"small transparent top\");"
94                                 "</script>"
95                         );
96                 }
97         }
98 }
99
100
101 /*
102  * print tabbed dialog
103  */
104 void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]) {
105         int i;
106
107         StrBufAppendBufPlain(
108                 Target, 
109                 HKEY(
110                         "<script type=\"text/javascript\">                                              "
111                         "var previously_selected_tab = '0';                                             "
112                         "function tabsel(which_tab) {                                                   "
113                         "       if (which_tab == previously_selected_tab) {                             "
114                         "               return;                                                         "
115                         "       }                                                                       "
116                         "       $('tabdiv'+previously_selected_tab).style.display = 'none';             "
117                         "       $('tabdiv'+which_tab).style.display = 'block';                          "
118                         "       $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';         "
119                         "       $('tabtd'+which_tab).className = 'tab_cell_label';                      "
120                         "       previously_selected_tab = which_tab;                                    "
121                         "}                                                                              "
122                         "</script>                                                                      \n"
123                         ), 0);
124
125         StrBufAppendBufPlain(
126                 Target, 
127                 HKEY(
128                         "<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
129                         "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
130                         ), 0);
131
132         for (i=0; i<num_tabs; ++i) {
133                 StrBufAppendPrintf(
134                         Target, 
135                         "<td id=\"tabtd%d\" class=\"%s\" "
136                         "onClick='tabsel(\"%d\");'"
137                         ">",
138                         i,
139                         ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
140                         i
141                         );
142                 StrBufAppendBuf(Target, tabnames[i], 0);
143                 StrBufAppendBufPlain(
144                         Target, 
145                         HKEY(
146                                 "</td>"
147                                 "<td>&nbsp;</td>\n"), 0);
148         }
149
150         StrBufAppendBufPlain(
151                 Target, 
152                 HKEY("</tr></table>\n"), 0);
153 }
154
155 /*
156  * print the tab-header
157  *
158  * tabnum:       number of the tab to print
159  * num_tabs:     total number oftabs to be printed
160  *
161  */
162 void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs) {
163
164         if (tabnum == num_tabs) {
165                 StrBufAppendBufPlain(
166                         Target, 
167                         HKEY(
168                                 "<!-- begin tab-common epilogue -->\n"
169                                 "<div class=\"tabcontent_submit\">"), 0);
170         }
171
172         else {
173                 StrBufAppendPrintf(
174                         Target, 
175                         "<!-- begin tab %d of %d -->\n"
176                         "<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
177                         tabnum, num_tabs, 
178                         tabnum,
179                         ( (tabnum == 0) ? "block" : "none" )
180                         );
181         }
182 }
183
184 /*
185  * print the tab-footer
186  * tabnum:       number of the tab to print
187  * num_tabs:     total number of tabs to be printed
188  *
189  */
190 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs) {
191
192         if (tabnum == num_tabs) {
193                 StrBufAppendBufPlain(
194                         Target, 
195                         HKEY(
196                                 "</div>\n"
197                                 "<!-- end tab-common epilogue -->\n"), 0);
198         }
199
200         else {
201                 StrBufAppendPrintf(
202                         Target, 
203                         "</div>\n",
204                         "<!-- end tab %d of %d -->\n", tabnum, num_tabs);
205         
206                 if (tabnum == num_tabs-1) {
207                         StrBufAppendBufPlain(
208                                 Target, 
209                                 HKEY(
210                                         "<script type=\"text/javascript\">"
211                                         " Nifty(\"table#TheTabs td\", \"small transparent top\");"
212                                         "</script>"), 0);
213                 }
214         }
215 }
216
217