f41b982009-05-07Martin Stjernholm // The outlined box module, Copyright © 1996 - 2009, Roxen IS.
d2bf2c1997-11-09Francesco Chemolli // // Fredrik Noring et al // // Several modifications by Francesco Chemolli.
ea01431997-08-03Fredrik Noring 
d2bf2c1997-11-09Francesco Chemolli 
f41b982009-05-07Martin Stjernholm constant cvs_version = "$Id: obox.pike,v 1.42 2009/05/07 14:15:56 mast Exp $";
07bf511997-08-31Peter Bortas constant thread_safe=1;
ea01431997-08-03Fredrik Noring #include <module.h>
55a8662000-11-20Per Hedbor // #include <roxen.h>
07bf511997-08-31Peter Bortas inherit "module";
ea01431997-08-03Fredrik Noring 
55a8662000-11-20Per Hedbor // begin locale stuff //<locale-token project="mod_obox">LOCALE</locale-token> //<locale-token project="mod_obox">SLOCALE</locale-token> #define SLOCALE(X,Y) _STR_LOCALE("mod_obox",X,Y) #define LOCALE(X,Y) _DEF_LOCALE("mod_obox",X,Y) // end locale stuff
ff8e662000-05-05Kenneth Johansson 
55a8662000-11-20Per Hedbor constant module_type = MODULE_TAG;
bc0fa02001-03-08Per Hedbor LocaleString module_name = LOCALE(1,"Tags: Outlined box");
ff8e662000-05-05Kenneth Johansson 
f0d6942001-01-29Per Hedbor LocaleString module_doc =
55a8662000-11-20Per Hedbor  LOCALE(2,"This module provides the <tt>&lt;obox&gt;</tt> tag that " "draws outlined boxes.");
ea01431997-08-03Fredrik Noring 
a68f5d1999-12-08Martin Nilsson constant unit_gif = "/internal-roxen-unit";
5458ff1997-08-23Henrik Grubbström (Grubba) 
fc40392008-08-15Martin Stjernholm protected string img_placeholder (mapping args)
d2bf2c1997-11-09Francesco Chemolli { int width=((int)args->outlinewidth)||1;
049b002002-05-22Dan Nelson  return sprintf("<img src=\"%s\" alt=\"\" " // border:1 is here to work around a buggy rendering in NS4. "style=\"display:block; border:1;\" " "width=\"%d\" height=\"%d\"%s>",
14ae4b1999-07-26Martin Nilsson  unit_gif, width, width, (args->noxml?"":" /"));
d2bf2c1997-11-09Francesco Chemolli }
fc40392008-08-15Martin Stjernholm protected string handle_title(string name, mapping junk_args, string contents, mapping args)
d2bf2c1997-11-09Francesco Chemolli { args->title=contents; return ""; }
fc40392008-08-15Martin Stjernholm protected string horiz_line(mapping args)
d2bf2c1997-11-09Francesco Chemolli {
9f2fdf1998-10-18Martin Stjernholm  args->fixedleft="";
14ae4b1999-07-26Martin Nilsson  return sprintf("<tr><td colspan=\"5\" bgcolor=\"%s\">\n"
d2bf2c1997-11-09Francesco Chemolli  "%s</td></tr>\n", args->outlinecolor, img_placeholder(args)); }
fc40392008-08-15Martin Stjernholm protected string title(mapping args)
d2bf2c1997-11-09Francesco Chemolli { if (!args->title) return horiz_line(args); string empty=img_placeholder(args);
5864ba1999-05-24David Hedbor  if (!args->left && !args->fixedleft) if (args->width && !args->fixedright) args->fixedleft = "7"; else args->left = "20"; if (!args->right && !args->fixedright) args->right = args->width || "20";
d2bf2c1997-11-09Francesco Chemolli  switch (args->style) {
5864ba1999-05-24David Hedbor  case "groupbox":
14ae4b1999-07-26Martin Nilsson  return sprintf("<tr><td colspan=\"2\"><font size=\"-3\">&nbsp;</font></td>\n" "<td rowspan=\"3\"%s nowrap=\"nowrap\">&nbsp;<b>" /* bgcolor */
d2bf2c1997-11-09Francesco Chemolli  "%s%s%s" /* titlecolor, title, titlecolor */
9f2fdf1998-10-18Martin Stjernholm  "</b>&nbsp;</td>\n"
14ae4b1999-07-26Martin Nilsson  "<td colspan=\"2\"><font size=\"-3\">&nbsp;</font></td></tr>\n"
d2bf2c1997-11-09Francesco Chemolli  "<tr%s>" /* bgcolor */
14ae4b1999-07-26Martin Nilsson  "<td bgcolor=\"%s\" colspan=\"2\">\n" /* outlinecolor */
d2bf2c1997-11-09Francesco Chemolli  "%s</td>\n" /* empty */
14ae4b1999-07-26Martin Nilsson  "<td bgcolor=\"%s\" colspan=\"2\">\n"
d2bf2c1997-11-09Francesco Chemolli  "%s</td></tr>\n" /* empty */ "<tr%s><td bgcolor=\"%s\">" /* bgcolor, outlinecolor */ "%s</td>\n" /* empty */
14ae4b1999-07-26Martin Nilsson  "<td%s><font size=\"-3\">%s</font></td>" /* left, fixedleft */ "<td%s><font size=\"-3\">%s</font></td>\n" /* right, fixedright */
d2bf2c1997-11-09Francesco Chemolli  "<td bgcolor=\"%s\">" /* outlinecolor */ "%s</td></tr>\n" /* empty */ , args->bgcolor ? " bgcolor=\""+args->bgcolor+"\"" : "",
e3da5f1999-08-16Martin Nilsson  args->titlecolor ? "<font color=\""+args->titlecolor+"\">" : "",
d2bf2c1997-11-09Francesco Chemolli  args->title,
e3da5f1999-08-16Martin Nilsson  args->titlecolor ? "</font>" : "",
d2bf2c1997-11-09Francesco Chemolli  args->bgcolor ? " bgcolor=\""+args->bgcolor+"\"" : "", args->outlinecolor, empty, args->outlinecolor, empty, args->bgcolor ? " bgcolor=\""+args->bgcolor+"\"" : "", args->outlinecolor, empty,
6953032000-03-13Martin Nilsson  args->left ? " width=\""+args->left+"\"" : "",
9f2fdf1998-10-18Martin Stjernholm  (args->fixedleft ?
735de42002-12-14Anders Johansson  ("&nbsp;"*(int)args->fixedleft) : "&nbsp;"),
6953032000-03-13Martin Nilsson  args->right ? " width=\""+args->right+"\"" : "",
9f2fdf1998-10-18Martin Stjernholm  (args->fixedright ?
735de42002-12-14Anders Johansson  ("&nbsp;"*(int)args->fixedright) : "&nbsp;"),
d2bf2c1997-11-09Francesco Chemolli  args->outlinecolor, empty);
5864ba1999-05-24David Hedbor  case "caption":
14ae4b1999-07-26Martin Nilsson  return sprintf("<tr%s><td colspan=\"2\"><font size=\"-3\">&nbsp;</font></td>\n" "<td rowspan=\"3\" nowrap=\"nowrap\">&nbsp;<b>" /* bgcolor */
5864ba1999-05-24David Hedbor  "%s%s%s" /* titlecolor, title, titlecolor */ "</b>&nbsp;</td>\n"
14ae4b1999-07-26Martin Nilsson  "<td colspan=\"2\"><font size=\"-3\">&nbsp;</font></td></tr>\n"
5864ba1999-05-24David Hedbor  "<tr bgcolor=\"%s\">" /* outlinecolor */
14ae4b1999-07-26Martin Nilsson  "<td colspan=\"2\">\n"
5864ba1999-05-24David Hedbor  "%s</td>\n" /* empty */
14ae4b1999-07-26Martin Nilsson  "<td colspan=\"2\">\n"
5864ba1999-05-24David Hedbor  "%s</td></tr>\n" /* empty */ "<tr bgcolor=\"%s\"><td>" /* outlinecolor */ "%s</td>\n" /* empty */
14ae4b1999-07-26Martin Nilsson  "<td%s><font size=\"-3\">%s</font></td>" /* left, fixedleft */ "<td%s><font size=\"-3\">%s</font></td>\n" /* right, fixedright */
5864ba1999-05-24David Hedbor  "<td bgcolor=\"%s\">" /* outlinecolor */ "%s</td></tr>\n" /* empty */ , args->outlinecolor ? " bgcolor=\""+args->outlinecolor+"\"" : "",
e3da5f1999-08-16Martin Nilsson  args->titlecolor ? "<font color=\""+args->titlecolor+"\">" : "",
d2bf2c1997-11-09Francesco Chemolli  args->title,
e3da5f1999-08-16Martin Nilsson  args->titlecolor ? "</font>" : "",
5864ba1999-05-24David Hedbor  args->outlinecolor, empty, empty, args->outlinecolor, empty,
6953032000-03-13Martin Nilsson  args->left ? " width=\""+args->left+"\"" : "",
5864ba1999-05-24David Hedbor  (args->fixedleft ?
735de42002-12-14Anders Johansson  ("&nbsp;"*(int)args->fixedleft) : "&nbsp;"),
6953032000-03-13Martin Nilsson  args->right ? " width=\""+args->right+"\"" : "",
5864ba1999-05-24David Hedbor  (args->fixedright ?
735de42002-12-14Anders Johansson  ("&nbsp;"*(int)args->fixedright) : "&nbsp;"),
5864ba1999-05-24David Hedbor  args->outlinecolor,
d2bf2c1997-11-09Francesco Chemolli  empty); } }
6953032000-03-13Martin Nilsson string simpletag_obox(string name, mapping args, string contents)
ea01431997-08-03Fredrik Noring {
d2bf2c1997-11-09Francesco Chemolli  string s;
0e834c2000-02-24Martin Nilsson 
d2bf2c1997-11-09Francesco Chemolli  // Set the defaults... args->outlinecolor = args->outlinecolor || "#000000"; args->style = args->style || "groupbox"; if (!args->title) { contents=parse_html(contents,([]),(["title":handle_title,]),args);
ea01431997-08-03Fredrik Noring  }
e3da5f1999-08-16Martin Nilsson  s = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"" + (args->align?" align=\""+args->align+"\"":"") +
0e834c2000-02-24Martin Nilsson  (args->width ? " width=" + args->width : "") + (args->hspace ? " hspace=" + args->hspace : "") +
64324f1999-10-04Fred van Dijk  (args->vspace ? " vspace=" + args->vspace : "") + ">\n" +
e3da5f1999-08-16Martin Nilsson  title(args) + "<tr" + (args->bgcolor?" bgcolor=\""+args->bgcolor+"\"":"") + "><td bgcolor=\"" + args->outlinecolor + "\">" + img_placeholder(args) + "</td>\n" "<td" + (args->width && !args->fixedleft && !args->fixedright ? " width=\"1\"" : "") + (args->aligncontents ? " align=" + args->aligncontents : "") + " colspan=\"3\"" + ">\n" "<table border=\"0\" cellspacing=\"0\" cellpadding=\"" + (args->padding || "5") + "\""+ (!args->spacing && args->width?" width=\""+(string)((int)args->width-((int)args->outlinewidth*2||2))+"\"":"")+ (args->spacing?" width=\""+(string)args->spacing+"\"":"")+">" "<tr><td>\n"; if (args->textcolor) s += "<font color=\""+args->textcolor+"\">" + contents + "</font>"; else s += contents;
0e834c2000-02-24Martin Nilsson 
e3da5f1999-08-16Martin Nilsson  s += "</td></tr></table>\n" "</td><td bgcolor=\"" + args->outlinecolor + "\">" + img_placeholder(args) + "</td></tr>\n" + horiz_line(args) + "</table>\n";
0e834c2000-02-24Martin Nilsson 
ea01431997-08-03Fredrik Noring  return s; }
55a8662000-11-20Per Hedbor  TAGDOCUMENTATION #ifdef manual
9b03652001-03-07Kenneth Johansson constant tagdoc=([ "obox": ([
ce8fb02001-09-21Johan Sundström  "standard":#"<desc type='cont'><p><short>
9b03652001-03-07Kenneth Johansson  This tag creates an outlined box.</short> </p></desc> <attr name='align' value='left|right'><p> Vertical alignment of the box.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='bgcolor' value='color'><p> Color of the background and title label.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='fixedleft' value='number'><p>
55a8662000-11-20Per Hedbor  Fixed length of line on the left side of the title. The unit is the
9b03652001-03-07Kenneth Johansson  approximate width of a character.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='fixedright' value='number'><p>
55a8662000-11-20Per Hedbor  Fixed length of line on the right side of the title. The unit is the
9b03652001-03-07Kenneth Johansson  approximate width of a character.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='left' value='number'><p> Length of the line on the left of the title.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='outlinecolor' value='color'><p> Color of the outline.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='outlinewidth' value='number'><p> Width, in pixels, of the outline.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='right' value='number'><p> Length of the line on the right of the title.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='spacing' value='number'><p> Width, in pixels, of the space in the box.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='style' value='caption|groupbox'><p> Style of the box. Groupbox is default.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='textcolor' value='color'><p> Color of the text inside the box.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='title' value='string'><p> Sets the title of the obox.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='titlecolor' value='color'><p> Color of the title text.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='width' value='number'><p> Width, in pixels, of the box.</p>
55a8662000-11-20Per Hedbor 
9b03652001-03-07Kenneth Johansson  <p>Note that the left and right attributes are constrained by the width
55a8662000-11-20Per Hedbor  argument. If the title is not specified in the argument list, you can
9b03652001-03-07Kenneth Johansson  put it in a <tag>title</tag> container in the obox contents.</p>
55a8662000-11-20Per Hedbor  <ex><obox align='left' outlinewidth='5' outlinecolor='green' width='200'> <title>Sample box</title> This is just a sample box. </obox> </ex> </attr>",
ce8fb02001-09-21Johan Sundström  "svenska":#"<desc type='cont'><p><short>
9b03652001-03-07Kenneth Johansson  Denna tagg skapar en ramlåda runt dess innehåll.</short> </p></desc>
55a8662000-11-20Per Hedbor 
9b03652001-03-07Kenneth Johansson <attr name='align' value='left|right'><p> Ramlådans vertikala position.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='bgcolor' value='färg'><p> Färgen på bakgrunden samt titeln.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='fixedleft' value='nummer'><p>
55a8662000-11-20Per Hedbor  Längden på linjen till vänster om titeln. Värdet på 1 'nummer' är den
9b03652001-03-07Kenneth Johansson  ungefärliga bredden av ett tecken.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='fixedright' value='nummer'><p>
55a8662000-11-20Per Hedbor  Längden på linjen till vänster om titeln. Värdet på 1 'nummer' är den
9b03652001-03-07Kenneth Johansson  ungefärliga bredden av ett tecken.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='left' value='nummer'><p> Längden på linjen till vänster om titeln.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='outlinecolor' value='färg'><p> Färgen på ramen.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='outlinewidth' value='nummer'><p> Ramens bredd, i antal pixlar.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='right' value='nummer'><p> Längden på linjen till höger om titeln.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='spacing' value='nummer'><p> Vidden på utrymmet i ramlådan, i antal pixlar.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='style' value='caption|groupbox'><p> Ramlådans stil. Groupbox är standardvärde.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='textcolor' value='färg'><p> Färgen på texten inuti lådan.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='title' value='textsträng'><p> Ramlådans titel.</p>
55a8662000-11-20Per Hedbor </attr>
9b03652001-03-07Kenneth Johansson <attr name='titlecolor' value='färg'><p> Färgen på titeltexten.</p>
55a8662000-11-20Per Hedbor  </attr>
9b03652001-03-07Kenneth Johansson <attr name='width' value='nummer'><p> Bredden på lådan, i antal pixlar.</p>
55a8662000-11-20Per Hedbor 
9b03652001-03-07Kenneth Johansson  <p>Tänk på att <att>left</att> och <att>right</att> attributen begränsas
55a8662000-11-20Per Hedbor  av värdet på <att>width</att> attributet. Om titeln inte är satt i taggen, finns möjligheten att sätta den inuti en <tag>title</tag>
9b03652001-03-07Kenneth Johansson  tagg och placera denna i ramlådans innehåll.</p>
55a8662000-11-20Per Hedbor  <ex><obox align='left' outlinewidth='5' outlinecolor='green' width='200'> <title>Ramlåda</title> Detta är innehållet. </obox> </ex>
9b03652001-03-07Kenneth Johansson </attr>" ]) ]);
55a8662000-11-20Per Hedbor #endif