Back to index

webcit  8.12-dfsg
tabs.c
Go to the documentation of this file.
00001 #include <stdarg.h>
00002 #define SHOW_ME_VAPPEND_PRINTF
00003 #include "webcit.h"
00004 
00005 /*
00006  * print tabbed dialog
00007  */
00008 void tabbed_dialog(int num_tabs, char *tabnames[]) {
00009        int i;
00010 
00011        StrBufAppendPrintf(WC->trailing_javascript,
00012               "var previously_selected_tab = '0';                                          \n"
00013               "function tabsel(which_tab) {                                                \n"
00014               "      if (which_tab == previously_selected_tab) {                           \n"
00015               "             return;                                                        \n"
00016               "      }                                                              \n"
00017               "      $('tabdiv'+previously_selected_tab).style.display = 'none';           \n"
00018               "      $('tabdiv'+which_tab).style.display = 'block';                        \n"
00019               "      $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';              \n"
00020               "      $('tabtd'+which_tab).className = 'tab_cell_label';                    \n"
00021               "      previously_selected_tab = which_tab;                                  \n"
00022               "}                                                                    \n"
00023        );
00024 
00025        wc_printf("<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
00026               "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
00027        );
00028 
00029        for (i=0; i<num_tabs; ++i) {
00030               wc_printf("<td id=\"tabtd%d\" class=\"%s\" "
00031                      "onClick='tabsel(\"%d\");'"
00032                      ">",
00033                      i,
00034                      ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
00035                      i
00036                      );
00037               wc_printf("%s", tabnames[i]);
00038               wc_printf("</td>");
00039 
00040               wc_printf("<td>&nbsp;</td>\n");
00041        }
00042 
00043        wc_printf("</tr></table>\n");
00044 }
00045 
00046 /*
00047  * print the tab-header
00048  *
00049  * tabnum:     number of the tab to print
00050  * num_tabs:   total number oftabs to be printed
00051  *
00052  */
00053 void begin_tab(int tabnum, int num_tabs) {
00054 
00055        if (tabnum == num_tabs) {
00056               wc_printf("<!-- begin tab-common epilogue -->\n");
00057               wc_printf("<div class=\"tabcontent_submit\">");
00058        }
00059 
00060        else {
00061               wc_printf("<!-- begin tab %d of %d -->\n", tabnum, num_tabs);
00062               wc_printf("<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
00063                      tabnum,
00064                      ( (tabnum == 0) ? "block" : "none" )
00065               );
00066        }
00067 }
00068 
00069 /*
00070  * print the tab-footer
00071  * tabnum:     number of the tab to print
00072  * num_tabs:   total number of tabs to be printed
00073  *
00074  */
00075 void end_tab(int tabnum, int num_tabs) {
00076 
00077        if (tabnum == num_tabs) {
00078               wc_printf("</div> <!-- end of 'tabcontent_submit' div -->\n");
00079               wc_printf("<!-- end tab-common epilogue -->\n");
00080        }
00081 
00082        else {
00083               wc_printf("</div>\n");
00084               wc_printf("<!-- end tab %d of %d -->\n", tabnum, num_tabs);
00085        }
00086 }
00087 
00088 
00089 /*
00090  * print tabbed dialog
00091  */
00092 void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]) {
00093        int i;
00094 
00095        StrBufAppendBufPlain(
00096               Target, 
00097               HKEY(
00098                      "<script type=\"text/javascript\">                                    "
00099                      "var previously_selected_tab = '0';                                          "
00100                      "function tabsel(which_tab) {                                                "
00101                      "      if (which_tab == previously_selected_tab) {                           "
00102                      "             return;                                                        "
00103                      "      }                                                              "
00104                      "      $('tabdiv'+previously_selected_tab).style.display = 'none';           "
00105                      "      $('tabdiv'+which_tab).style.display = 'block';                        "
00106                      "      $('tabtd'+previously_selected_tab).className = 'tab_cell_edit';              "
00107                      "      $('tabtd'+which_tab).className = 'tab_cell_label';                    "
00108                      "      previously_selected_tab = which_tab;                                  "
00109                      "}                                                                    "
00110                      "</script>                                                            \n"
00111                      ), 0);
00112 
00113        StrBufAppendBufPlain(
00114               Target, 
00115               HKEY(
00116                      "<table id=\"TheTabs\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
00117                      "<tr align=\"center\" style=\"cursor:pointer\"><td>&nbsp;</td>"
00118                      ), 0);
00119 
00120        for (i=0; i<num_tabs; ++i) {
00121               StrBufAppendPrintf(
00122                      Target, 
00123                      "<td id=\"tabtd%d\" class=\"%s\" "
00124                      "onClick='tabsel(\"%d\");'"
00125                      ">",
00126                      i,
00127                      ( (i==0) ? "tab_cell_label" : "tab_cell_edit" ),
00128                      i
00129                      );
00130               StrBufAppendBuf(Target, tabnames[i], 0);
00131               StrBufAppendBufPlain(
00132                      Target, 
00133                      HKEY(
00134                             "</td>"
00135                             "<td>&nbsp;</td>\n"), 0);
00136        }
00137 
00138        StrBufAppendBufPlain(
00139               Target, 
00140               HKEY("</tr></table>\n"), 0);
00141 }
00142 
00143 /*
00144  * print the tab-header
00145  *
00146  * tabnum:     number of the tab to print
00147  * num_tabs:   total number oftabs to be printed
00148  *
00149  */
00150 void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs, StrBuf **Names) {
00151 
00152        if (tabnum == num_tabs) {
00153               StrBufAppendBufPlain(
00154                      Target, 
00155                      HKEY("<!-- begin tab-common epilogue ["), 0);
00156               StrEscAppend(Target, Names[tabnum], NULL, 0, 2);
00157               StrBufAppendBufPlain(
00158                      Target, 
00159                      HKEY("] -->\n<div class=\"tabcontent_submit\">"), 0);
00160        }
00161 
00162        else {
00163               StrBufAppendBufPlain(
00164                      Target, 
00165                      HKEY("<!-- begin tab "), 0);
00166               StrBufAppendPrintf(
00167                      Target,  "%d of %d [",
00168                      tabnum, num_tabs);
00169               
00170               StrEscAppend(Target, Names[tabnum], NULL, 0, 2);
00171 
00172               StrBufAppendPrintf(
00173                      Target, 
00174                      "] -->\n<div id=\"tabdiv%d\" style=\"display:%s\" class=\"tabcontent\" >",
00175                      tabnum,
00176                      ( (tabnum == 0) ? "block" : "none" )
00177                      );
00178        }
00179 }
00180 
00181 /*
00182  * print the tab-footer
00183  * tabnum:     number of the tab to print
00184  * num_tabs:   total number of tabs to be printed
00185  *
00186  */
00187 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs) {
00188 
00189        if (tabnum == num_tabs) {
00190               StrBufAppendBufPlain(
00191                      Target, 
00192                      HKEY(
00193                             "</div>\n"
00194                             "<!-- end tab-common epilogue -->\n"), 0);
00195        }
00196 
00197        else {
00198               StrBufAppendPrintf(
00199                      Target, 
00200                      "</div>\n",
00201                      "<!-- end tab %d of %d -->\n", tabnum, num_tabs
00202               );
00203        }
00204        if (HAVEBSTR("last_tabsel"))
00205        {
00206               StrBufAppendPrintf(Target, "<script type=\"text/javascript\">tabsel(%s);</script>", BSTR("last_tabsel"));
00207        }
00208 }
00209 
00210