Index: /trunk/gsdl/src/recpt/browsetools.cpp
===================================================================
--- /trunk/gsdl/src/recpt/browsetools.cpp	(revision 666)
+++ /trunk/gsdl/src/recpt/browsetools.cpp	(revision 667)
@@ -29,4 +29,8 @@
 /*
    $Log$
+   Revision 1.26  1999/10/14 22:58:05  sjboddie
+   finished up on changes to browseing support - may still need some
+   tidying up
+
    Revision 1.25  1999/10/10 08:14:04  sjboddie
    - metadata now returns mp rather than array
@@ -162,5 +166,95 @@
 }
 
-// expects haschidren, doctype, and classifytype metadata elements
+// output_controls displays the detach, expand/contract contents,
+// expand/contract text and highlighting/no highlighting buttons
+static void output_controls (cgiargsclass &args, const text_tarray &ibuttons,
+			     recptproto * /*collectproto*/, displayclass &disp, 
+			     outconvertclass &outconvert, ostream &textout, 
+			     ostream &/*logout*/) {
+
+  if (args["u"] != "1") {
+    
+    FilterResponse_t response;
+    text_tarray metadata;
+    text_tarray buttons;
+    
+    text_tarray::const_iterator here = ibuttons.begin();
+    text_tarray::const_iterator end = ibuttons.end();
+    
+    while (here != end) {
+      
+      if (*here == "Detach")
+	buttons.push_back ("_document:imagedetach_");
+      else if (*here == "Highlight") {
+	if (args["hl"] == "1") 
+	  buttons.push_back ("_document:imagenohighlight_");
+	else 
+	  buttons.push_back ("_document:imagehighlight_");
+      } else if (*here == "Expand Contents") {
+	if (args["gc"] == "1")
+	  buttons.push_back ("_document:imagecontracttoc_");
+	else 
+	  buttons.push_back ("_document:imageexpandtoc_");
+      } else if (*here == "Expand Text") {
+	if (args.getintarg("gt"))
+	  buttons.push_back ("_document:imagecontracttext_");
+	else 
+	  buttons.push_back ("_document:imageexpandtext_");
+      }
+      here ++;
+    }
+    
+    here = buttons.begin();
+    end = buttons.end();
+    int count = 0;
+    while (here != end) {
+      if ((count != 0) && ((count % 3) == 0)) textout << "<br>\n";
+      textout << outconvert << disp << *here;
+      count ++;
+      here ++;
+    }
+  }
+}
+
+
+// at the moment this just writes out the html to display 
+// the cover image (assuming it's called cover.jpg)
+// this whole thing should be done with a call to the collection
+// server which would send a link to the cover image if there
+// was one otherwise send title, author and stuff
+static void output_cover_image (cgiargsclass &args, recptproto */*collectproto*/, 
+				displayclass &disp, outconvertclass &outconvert, 
+				ostream &textout, ostream &/*logout*/) {
+  
+  if (args["d"].empty()) return;
+  
+  textout << outconvert << disp << 
+    "<img src=\"_httpcollection_/archives/_thisOID_/cover.jpg\"><br>\n";
+}
+
+static void output_titles (cgiargsclass &args, recptproto *collectproto, 
+			   formatinfo_t &formatinfo, displayclass &disp, 
+			   outconvertclass &outconvert, ostream &textout, 
+			   ostream &logout) {
+
+  if (args["d"].empty()) return;
+
+  text_tset metadata;
+  bool getParents;
+  FilterResponse_t response;
+
+  format_t *formatlistptr = new format_t();
+  parse_formatstring (formatinfo.DocumentHeading, formatlistptr, metadata, getParents);
+
+  text_t topOID;
+  get_top (args["d"], topOID);
+
+  if (!get_info (topOID, args["c"], metadata, getParents, collectproto, response, logout))
+    return;
+
+  textout << outconvert << disp << get_formatted_string (response.docInfo[0], formatlistptr);
+}
+
+
 static void recurse_contents (ResultDocInfo_t &section, cgiargsclass &args,
 			      browserclass *bptr, text_tset &metadata, bool &getParents, 
@@ -176,6 +270,7 @@
   // output this section 
   bool use_table = is_table_content (formatlistptr);
-  colnumber += bptr->output_section_group (section, args, colnumber, formatlistptr, 
-					   use_table, disp, outconvert, textout, logout);
+  colnumber += bptr->output_section_group (section, args, colnumber, formatlistptr, use_table, 
+					   metadata, getParents, collectproto, disp, outconvert, 
+					   textout, logout);
 
   text_t classification;
@@ -187,7 +282,7 @@
   text_t classifytype = section.metadata["classifytype"].values[0];
   // HLists are displayed as VLists when contents are expanded,
-  // Books are displayed as HLists
+  // Paged documents are displayed as HLists
   if (classifytype == "HList") classifytype = "VList";
-  if (classifytype == "Book") classifytype = "HList";
+  if (classifytype == "Paged") classifytype = "HList";
 
   // recurse through children
@@ -322,4 +417,5 @@
 }
 
+
 static void load_formatstring (const text_t &classifytype, text_tset &metadata,
 			       bool &getParents, const text_t &classification, 
@@ -357,19 +453,67 @@
 
   while (thisdoc != lastdoc) {
-    if (classification != "Document" && is_top ((*thisdoc).OID)) {
-      text_t &thistype = (*thisdoc).metadata["thistype"].values[0];
-      if (!thistype.empty()) load_formatstring (thistype, metadata, getParents, classification,
-						browsermap, formatinfo, formatlistmap);
-    }
+
+    if (is_top ((*thisdoc).OID))
+      load_formatstring ((*thisdoc).metadata["thistype"].values[0], metadata, 
+			 getParents, classification, browsermap, formatinfo, 
+			 formatlistmap);
+
     text_t &childtype = (*thisdoc).metadata["childtype"].values[0];
     text_tset::const_iterator it = cache.find (childtype);
     if (it == cache.end()) {
-      if (!childtype.empty()) {
-	load_formatstring (childtype, metadata, getParents, classification,
-			   browsermap, formatinfo, formatlistmap);
-	cache.insert (childtype);
-      }
+      load_formatstring (childtype, metadata, getParents, classification,
+			 browsermap, formatinfo, formatlistmap);
+      cache.insert (childtype);
     }
     thisdoc ++;
+  }
+}
+
+static void output_parents (FilterResponse_t &response, cgiargsclass &args, 
+			    browsermapclass *browsermap, formatinfo_t &formatinfo, 
+			    format_tmap &formatlistmap, const text_t &classification,
+			    int &colnumber, text_tset &metadata, bool &getParents,
+			    recptproto *collectproto, displayclass &disp, 
+			    outconvertclass &outconvert, ostream textout, 
+			    ostream &logout) {
+
+  format_t *formatlistptr = NULL;
+  text_t classifytype, formatstring;
+  bool use_table, first = true;
+  ResultDocInfo_tarray::iterator thisparent = response.docInfo.begin();
+  ResultDocInfo_tarray::iterator lastparent = response.docInfo.end();
+  while (thisparent != lastparent) {
+
+    // get classifytype of this level
+    if (is_top ((*thisparent).OID)) classifytype = (*thisparent).metadata["thistype"].values[0];
+    else if (!first) classifytype = (*(thisparent-1)).metadata["childtype"].values[0];
+    
+    // if we still don't have a classifytype we'll use the default
+    if (classifytype.empty()) {
+      browserclass *bptr = browsermap->get_default_browser ();
+      classifytype = bptr->get_browser_name ();
+    }
+    
+    browserclass *bptr = browsermap->getbrowser (classifytype);
+
+    // get the formatstring if there is one or use the browsers default
+    if (!get_formatstring (classification, classifytype, 
+			   formatinfo.formatstrings, formatstring))
+      formatstring = bptr->get_default_formatstring();
+    
+    // see if it's cached
+    format_tmap::const_iterator it = formatlistmap.find (formatstring);
+    if (it != formatlistmap.end()) formatlistptr = (*it).second;
+    else {
+      logout << "browsetools error\n";
+      return;
+    }
+    
+    use_table = is_table_content (formatlistptr);
+    colnumber += bptr->output_section_group (*thisparent, args, colnumber, formatlistptr, use_table, 
+					     metadata, getParents, collectproto, disp, outconvert, 
+					     textout, logout);
+    first = false;
+    thisparent ++;
   }
 }
@@ -383,9 +527,13 @@
   text_tset metadata;
   bool getParents = false;
+  text_t formatstring;
   text_tarray parents;
   text_t OID = args["d"];
-  if (OID.empty()) OID = args["d"];
   text_t classification = "Document";
-  if (args["d"].empty()) get_top (args["cl"], classification);
+  if (OID.empty()) {
+    OID = args["cl"];
+    get_top (OID, classification);
+  } 
+  int colnumber = 0;
 
   bool haschildren = has_children (OID, args["c"], collectproto, logout);
@@ -394,19 +542,73 @@
   else get_parents_array (OID, parents);
 
-  // get classifytypes of each parent
-  metadata.insert ("thistype");
-  metadata.insert ("childtype");
-  if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
-    return;
-  
-  metadata.erase (metadata.begin(), metadata.end());
-
-  // get formatstrings for all parents
-  format_tmap formatlistmap;  
-  load_formatstrings (response, metadata, getParents, classification, 
-		      browsermap, formatinfo, formatlistmap);
-
-  ///////////////////
-
+  if (!parents.empty()) {
+    // get classifytypes of each parent
+    metadata.insert ("thistype");
+    metadata.insert ("childtype");
+    
+    if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
+      return;
+    
+    // get formatstrings for all parents
+    format_tmap formatlistmap;  
+    load_formatstrings (response, metadata, getParents, classification, 
+			browsermap, formatinfo, formatlistmap);
+
+    if (!get_info (parents, args["c"], metadata, getParents, collectproto, response, logout))
+      return;
+    
+    // display each parent
+    output_parents (response, args, browsermap, formatinfo, formatlistmap, 
+		    classification, colnumber, metadata, getParents, 
+		    collectproto, disp, outconvert, textout, logout);
+    
+    metadata.erase (metadata.begin(), metadata.end());
+    
+    // clean up cached format list pointers
+    format_tmap::const_iterator here = formatlistmap.begin();
+    format_tmap::const_iterator end = formatlistmap.end();
+    while (here != end) {
+      delete (*here).second;
+      here ++;
+    }
+  }
+
+  // get childrens classifytype
+  text_t classifytype;
+  int numparents = response.docInfo.size();
+  if (!parents.empty())
+    classifytype = response.docInfo[numparents-1].metadata["childtype"].values[0];
+  else {
+    // use the default
+    browserclass *bptr = browsermap->get_default_browser ();
+    classifytype = bptr->get_browser_name ();
+  }
+    
+  // load up metadata array with browser defaults
+  browserclass *bptr = browsermap->getbrowser (classifytype);
+  bptr->load_metadata_defaults (metadata);
+
+  // get the formatstring if there is one or use the browsers default
+  if (!get_formatstring (classification, classifytype, 
+			 formatinfo.formatstrings, formatstring))
+    formatstring = bptr->get_default_formatstring();
+
+  format_t *formatlistptr = new format_t();
+  parse_formatstring (formatstring, formatlistptr, metadata, getParents);
+
+  if (haschildren) 
+    get_children (OID, args["c"], metadata, getParents,
+		  collectproto, response, logout);
+  else 
+    get_children (OID + ".pr", args["c"], metadata, getParents, 
+		  collectproto, response, logout);
+
+  // display children
+  bool use_table = is_table_content (formatlistptr);
+  bptr->output_section_group (response, args, colnumber, formatlistptr, use_table, 
+			      metadata, getParents, collectproto, disp, outconvert, 
+			      textout, logout);
+  
+  delete formatlistptr;
 }
 
@@ -416,15 +618,35 @@
                  ostream &textout, ostream &logout) {
 
-  if (args.getintarg("gc") == 1) {
-
-    // expanded table of contents
-    expanded_contents (args, browsermap, formatinfo, collectproto, 
-		       disp, outconvert, textout, logout);
-  } else {
-
-    // contracted table of contents
-    contracted_contents (args, browsermap, formatinfo, collectproto, 
+  bool havecontrols = false;
+  
+  // get the cover image (if there is one) and the control buttons
+  // if we're inside a book
+  if (!args["d"].empty()) {
+    textout << "<p><table cellpadding=0 cellspacing=0><tr>\n";
+    textout << "<td valign=top width=200>\n";
+    if (formatinfo.DocumentImages) 
+      output_cover_image (args, collectproto, disp, outconvert, textout, logout);
+    else if (formatinfo.DocumentTitles)
+      output_titles (args, collectproto, formatinfo, disp, outconvert, textout, logout);
+    output_controls (args, formatinfo.DocumentButtons, collectproto, disp, 
+		     outconvert, textout, logout);
+    textout << "</td><td valign=top>\n";
+    havecontrols = true;
+  }
+
+  if (formatinfo.DocumentContents) {
+    if (args.getintarg("gc") == 1) {
+      
+      // expanded table of contents
+      expanded_contents (args, browsermap, formatinfo, collectproto, 
 			 disp, outconvert, textout, logout);
-
-  }
-}
+    } else {
+      
+      // contracted table of contents
+      contracted_contents (args, browsermap, formatinfo, collectproto, 
+			   disp, outconvert, textout, logout);
+    }
+  }
+
+  if (havecontrols) textout << "</td></tr></table>\n";
+}
