source: trunk/gsdl/src/recpt/browsetools.cpp@ 241

Last change on this file since 241 was 213, checked in by sjboddie, 25 years ago

More changes to browseaction

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 KB
Line 
1/**********************************************************************
2 *
3 * browsetools.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: browsetools.cpp 213 1999-03-29 02:14:31Z sjboddie $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.2 1999/03/29 02:14:29 sjboddie
15
16 More changes to browseaction
17
18 Revision 1.1 1999/03/25 03:10:15 sjboddie
19
20 new library for browse stuff
21
22 */
23
24
25#include "browsetools.h"
26#include "OIDtools.h"
27
28// sets all the required macros for displaying the navigation bar
29void set_navigation_bar (displayclass &disp, cgiargsclass &args,
30 recptproto *collectproto, const text_t &cname,
31 ostream &/*logout*/) {
32
33 text_tarray classifications;
34 text_t width, navigationbar, javaimagesnavbar;
35 int twidth, swidth, iwidth = 0;
36
37 collectproto->get_all_classifications (classifications);
38 text_tarray::const_iterator here = classifications.begin();
39 text_tarray::const_iterator end = classifications.end();
40
41 navigationbar = "<!-- Navigation Bar -->\n";
42
43 // calculate width of spacers and set macro
44 if (args.getintarg("v") == 0) {
45 disp.expandstring ("Global", "_pagewidth_", width);
46 twidth = width.getint();
47
48 disp.expandstring ("query", "_searchwidth_", width);
49 iwidth += width.getint();
50
51 while (here != end) {
52 disp.expandstring (*here, "_" + *here + "width_", width);
53 iwidth += width.getint();
54 here ++;
55 }
56
57 if (classifications.size() == 0) swidth = twidth - iwidth;
58 else if ((twidth - iwidth) < int(classifications.size())) swidth = 2;
59 else swidth = (twidth - iwidth) / classifications.size();
60 disp.setmacro ("widthtspace", "Global", swidth);
61 }
62
63 navigationbar += "<nobr>\n_imagesearch_";
64 javaimagesnavbar = "_javasearch_";
65 here = classifications.begin();
66 while (here != end) {
67 if (*here == cname)
68 navigationbar += "_imagespacer__icontab" + *here + "green_";
69 else
70 navigationbar += "_imagespacer__image" + *here + "_";
71 javaimagesnavbar += "_java" + *here + "_";
72 here ++;
73 }
74 navigationbar += "\n</nobr>\n";
75 navigationbar += "<!-- End of Navigation Bar -->\n";
76 disp.setmacro ("navigationbar", cname, navigationbar);
77 if (args.getintarg("v") == 0)
78 disp.setmacro ("javaimagesnavbar", cname, javaimagesnavbar);
79}
80
81
82// sets the _httparrowprevious_ and _httparrownext_ macros
83// used by the forward and reverse navigation arrows
84void set_arrow_links (displayclass &disp, cgiargsclass &args,
85 recptproto */*collectproto*/, const text_t &cname,
86 ostream &/*logout*/) {
87
88 disp.setmacro ("httparrowprevious", cname, args["d"] + ".prevpage");
89 disp.setmacro ("httparrownext", cname, args["d"] + ".nextpage");
90
91}
92
93
94// sets the _classificationlinks_ macro
95void set_classification_links (displayclass &disp, cgiargsclass &args,
96 recptproto */*collectproto*/, const text_t &cname,
97 ostream &/*logout*/) {
98
99 if ((args["cl"]).empty()) return;
100
101 text_t link = "<a\nhref=\"_httpbrowse_&d=";
102 text_tarray siblings;
103 text_t child, classificationlinks;
104
105 get_children_array (get_parent(args["cl"]), siblings);
106
107 classificationlinks += "<!-- Classification Links -->\n";
108 classificationlinks += "<table width=_pagewidth_ cellpadding=0 cellspacing=0 border=0>\n";
109 classificationlinks += "<tr><td valign=top><center>\n";
110
111 text_tarray::const_iterator here = siblings.begin();
112 text_tarray::const_iterator end = siblings.end();
113
114 while (here != end) {
115 if (*here == args["cl"]) {
116 classificationlinks += "\n<b>" + *here + "</b>&nbsp;&nbsp;&nbsp;";
117 } else {
118 get_first_child (*here, child);
119 classificationlinks += link + *here + "." + child + "\">";
120 classificationlinks += *here + "</a>";
121 if ((here + 1) != end) classificationlinks += "&nbsp;&nbsp;&nbsp;";
122 }
123 here ++;
124 }
125
126 classificationlinks += "\n</center></td></tr></table>\n";
127 classificationlinks += "<!-- End of Classification Links -->\n";
128
129 disp.setmacro ("classificationlinks", cname, classificationlinks);
130}
131
132
133void get_hierarchy_toc (cgiargsclass &args, recptproto *collectproto,
134 text_t &toc, ostream &logout) {
135
136 toc.clear();
137 toc += "\n<!-- Table of Contents produced by browsetools::get_hierarchy_toc -->\n\n";
138
139 toc += "<p><table width=100% cellpadding=0 cellspacing=0 border=0><tr>\n";
140 toc += "<td valign=top>\n";
141
142 // get table of contents
143 if (args.getintarg("gc"))
144 get_expanded_toc(args, collectproto, toc, logout);
145 else
146 get_contracted_toc(args, collectproto, toc, logout);
147
148 toc += "</td></tr></table>\n";
149 toc += "\n<!-- end of Table of Contents -->\n";
150}
151
152
153void get_book_toc (cgiargsclass &/*args*/, recptproto */*collectproto*/,
154 text_t &/*toc*/, ostream &/*logout*/) {
155
156}
157
158
159void get_datelist_toc (cgiargsclass &/*args*/, recptproto */*collectproto*/,
160 text_t &/*toc*/, ostream &/*logout*/) {
161
162}
163
164
165void get_list_toc (cgiargsclass &args, recptproto */*collectproto*/,
166 text_t &toc, ostream &/*logout*/) {
167
168 text_tarray siblings;
169 toc += "\n<!-- Table of Contents produced by browsetools::get_list_toc -->\n\n";
170
171 // load up siblings array
172 if ((args["d"]).empty()) get_children_array (get_parent(args["cl"]), siblings);
173 else if (is_top (args["d"])) get_children_array (args["cl"], siblings);
174 else get_children_array (get_parent(args["d"]), siblings);
175
176 text_t section, child;
177 text_t doclink = "<a href=\"_httptext_&d=";
178 toc += "<p>\n";
179
180 text_tarray::const_iterator thissection = siblings.begin();
181 text_tarray::const_iterator end = siblings.end();
182
183 while (thissection != end) {
184
185 section.clear();
186 child.clear();
187
188 get_first_child(*thissection, child);
189
190 toc += "<br>" + doclink + *thissection + "." + child +
191 ".1\">" + *thissection + " title</a>\n";
192 thissection ++;
193 }
194 toc += "\n<!-- end of Table of Contents -->\n";
195}
196
197
198void get_contracted_toc (cgiargsclass &args, recptproto */*collectproto*/,
199 text_t &return_text, ostream &/*logout*/) {
200
201 int colnum, tabcount = 0;
202 text_tarray parents, siblings;
203
204 // load up the parents array
205 // don't want classifications unless at top level contents
206 if (!(args["cl"]).empty() && is_top(args["d"]))
207 get_parents_array (args["cl"] + ".", parents);
208 get_parents_array (args["d"], parents);
209
210 // load up siblings array
211 if ((args["d"]).empty()) get_children_array (get_parent(args["cl"]), siblings);
212 else if (is_top (args["d"])) get_children_array (args["cl"], siblings);
213 else get_children_array (get_parent(args["d"]), siblings);
214
215 return_text += "<table>\n";
216 colnum = parents.size() + 1;
217
218 // sort out toc of sections parents
219 if (parents.size() > 0)
220 get_parents_toc(args, parents, tabcount, colnum, return_text);
221
222 // sort out toc of sections siblings
223 if (siblings.size() > 0)
224 get_siblings_toc (args, siblings, tabcount, colnum, return_text);
225
226 return_text += "</table>\n";
227}
228
229
230void get_expanded_toc (cgiargsclass &/*args*/, recptproto */*collectproto*/,
231 text_t &/*return_text*/, ostream &/*logout*/) {
232
233 /*
234 text_t doclink, icon, pointer, tab, pagetype;
235 int totalcols, tabcols, tabsleft;
236 text_tarray contents;
237
238 // get array of all contents to be included (all contents of entire book)
239 text_t book_top;
240 get_book_top (booksection, book_top);
241 get_contents (book_top, gdbm, contents, totalcols);
242
243 vector<text_t>::const_iterator section = contents.begin();
244 vector<text_t>::const_iterator end = contents.end();
245
246 int count = 1;
247 while (section != end) {
248 tab.clear();
249 gdbm.getinfo(*section, info);
250 text_t icontabs;
251
252 // set up icon
253 icon = "_iconsmalltext_";
254 if (is_top_level(*section)) icon = "_iconopenbook_";
255 else if (!info.contents.empty()) icon = "_iconopenfolder_";
256
257 // set up pointer
258 if (*section == booksection) pointer = "_iconpointer_";
259 else pointer = "_icontab_";
260
261 // set up tabbing
262 tabcols = count_dots(*section);
263 for (int i = 0; i < (tabcols - 1); i++) {
264 icontabs += "_icontab_";
265 }
266 //char *tabcolsstr;
267 //itoa(tabcols, tabcolsstr, 10);
268 tab = "<td valign=top colspan=" + text_t(tabcols);
269 tab += ">" + icontabs + pointer + "</td>";
270 tabsleft = totalcols - tabcols;
271
272 // set up url
273 if (is_book(*section) && !is_top_level(*section))
274 doclink = "<a href=\"_httptext_";
275 else doclink = "<a href=\"_httpbrowse_";
276 if (args["x"] == "1") doclink += "&x=1";
277
278 return_text += "<tr>" + tab + "<td valign=top>";
279 if (is_top_level(*section) && args["x"] == "1") {
280 return_text += "<a href=\"\" onClick = \"close_detach()";
281 } else {
282 if (args["g"][1] == '0' || is_top_level(*section) ||
283 !are_same_chapter(booksection, *section) ||
284 !info.contents.empty()) {
285 return_text += doclink + "d=" + classification;
286 return_text += "." + *section + "&a=" + pagetype;
287 } else {
288 return_text += "<a href=\"#";
289 return_text += count;
290 count ++;
291 }
292 }
293 return_text += "\">" + icon + "</a></td>";
294 return_text += "<td colspan=" + text_t(tabsleft);
295 return_text += ">" + info.title;
296 return_text += "</td></tr>\n";
297
298 section ++;
299 }
300 return_text += "</table>\n";
301 return_text += "</td></tr></table>\n";
302 */
303}
304
305
306void get_parents_toc (cgiargsclass &args, const text_tarray &parents,
307 int &tabcount, int &colnum, text_t &return_text) {
308
309 text_t section, tab, icon, doclink;
310
311 doclink = "<a href=\"_httpbrowse_";
312 if (args["x"] == "1") doclink += "&x=1";
313
314 text_tarray::const_iterator thisparent = parents.begin();
315 text_tarray::const_iterator end = parents.end();
316
317 while (thisparent != end) {
318 text_t icontabs;
319 section.clear();
320 tab.clear();
321
322 // set up icon for this parent
323 icon = "_iconopenfolder_";
324 if (is_classification(*thisparent)) icon = "_iconopenbookshelf_";
325 else if (is_top(*thisparent)) icon = "_iconopenbook_";
326
327 for (int j = 0; j < tabcount; j++)
328 icontabs += "_icontab_";
329
330 if (!icontabs.empty()) {
331 tab = "<td valign=top";
332 if (tabcount > 1) tab += " colspan=" + text_t(tabcount);
333 tab += ">" + icontabs + "</td>";
334 }
335 tabcount ++;
336
337 if (is_top(*thisparent) && args["x"] == "1") {
338 return_text += "<tr>" + tab + "<td valign=top><a href=\"\" ";
339 return_text += "onClick = \"close_detach()\">" + icon + "</a></td>";
340 } else {
341 if (is_classification (*thisparent))
342 return_text += "<tr>" + tab + "<td valign=top>" + doclink + "&cl=" + *thisparent;
343 else
344 // this may not need cl= bit once compressed args is done
345 return_text += "<tr>" + tab + "<td valign=top>" + doclink + "&cl=" + args["cl"] + "&d=" + *thisparent;
346 return_text += "\">" + icon + "</a></td>";
347 }
348 return_text += "<td";
349 if (colnum > 1) return_text += " colspan=" + text_t(colnum);
350 return_text += ">" + *thisparent + " title ";
351 return_text += " by " + *thisparent + " author ";
352 return_text += "</td></tr>\n";
353 colnum --;
354 thisparent ++;
355 }
356}
357
358
359void get_siblings_toc (cgiargsclass &args, const text_tarray &siblings,
360 int &tabcount, int &colnum, text_t &return_text) {
361
362 text_t tab, icon, pointer, child, doclink;
363 int count = 1;
364
365 doclink = "<a href=\"_httpbrowse_";
366 if (args["x"] == "1") doclink += "&x=1";
367
368 text_tarray::const_iterator thissibling = siblings.begin();
369 text_tarray::const_iterator sibend = siblings.end();
370
371 while (thissibling != sibend) {
372
373 // set up icon for this sibling
374 icon = "_iconclosedfolder_";
375 if (is_classification(*thissibling)) icon = "_iconclosedbookshelf_";
376 else if (is_top(*thissibling)) icon = "_iconclosedbook_";
377
378 // fit pointer into tabbing if current section
379 pointer = "_icontab_";
380 if (is_classification(*thissibling)) {
381 if (*thissibling == args["cl"])
382 pointer = "_iconpointer_";
383 } else if (*thissibling == args["d"]) pointer = "_iconpointer_";
384
385 text_t thesetabs;
386 for (int j = 0; j < (tabcount - 1); j++)
387 thesetabs += "_icontab_";
388
389 tab = "<td valign=top";
390 if (tabcount > 1) tab += " colspan=" + text_t(tabcount);
391 tab += ">" + thesetabs + pointer + "</td>";
392
393 if (contains_text(*thissibling)) {
394 // sibling is text document
395 icon = "_iconsmalltext_";
396
397 return_text += "<tr>" + tab + "<td valign=top>";
398 if (args["g"][1] == '0') {
399 return_text += doclink + "&d=" + *thissibling;
400 } else {
401 return_text += "<a href=\"#";
402 return_text += count;
403 count ++;
404 }
405 return_text += "\">" + icon + "</a></td><td";
406 if (colnum > 1) return_text += " colspan=" + text_t(colnum);
407 return_text += ">" + *thissibling + " title";
408 return_text += " by " + *thissibling + " author";
409 return_text += "</td></tr>\n";
410 } else {
411 // sibling is closed book or folder so clicking
412 // it should open contents
413 get_first_child(*thissibling, child);
414
415 return_text += "<tr>" + tab + "<td valign=top>" + doclink + "&d=" + child;
416 return_text += "\">" + icon + "</a></td><td";
417 if (colnum > 1) return_text += " colspan=" + text_t(colnum);
418 return_text += ">" + *thissibling + " title";
419 return_text += " by " + *thissibling + " author";
420 return_text += "</td></tr>\n";
421 }
422 thissibling ++;
423 }
424}
Note: See TracBrowser for help on using the repository browser.