]> git.lyx.org Git - lyx.git/blob - src/insets/InsetBox.cpp
20968d89d6efc38deda5565ded05a0cd6a9cd599
[lyx.git] / src / insets / InsetBox.cpp
1 /**
2  * \file InsetBox.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
9  * \author Uwe Stöhr
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "InsetBox.h"
17
18 #include "Buffer.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "ColorSet.h"
22 #include "Cursor.h"
23 #include "DispatchResult.h"
24 #include "FuncStatus.h"
25 #include "FuncRequest.h"
26 #include "LaTeXFeatures.h"
27 #include "Lexer.h"
28 #include "MetricsInfo.h"
29 #include "output_xhtml.h"
30 #include "TextClass.h"
31
32 #include "support/debug.h"
33 #include "support/docstream.h"
34 #include "support/gettext.h"
35 #include "support/lstrings.h"
36 #include "support/Translator.h"
37
38 #include "frontends/Application.h"
39
40 #include <sstream>
41
42 using namespace std;
43 using namespace lyx::support;
44
45 namespace lyx {
46
47 namespace {
48
49 typedef Translator<string, InsetBox::BoxType> BoxTranslator;
50 typedef Translator<docstring, InsetBox::BoxType> BoxTranslatorLoc;
51
52 BoxTranslator initBoxtranslator()
53 {
54         BoxTranslator translator("Boxed", InsetBox::Boxed);
55         translator.addPair("Frameless", InsetBox::Frameless);
56         translator.addPair("Framed", InsetBox::Framed);
57         translator.addPair("ovalbox", InsetBox::ovalbox);
58         translator.addPair("Ovalbox", InsetBox::Ovalbox);
59         translator.addPair("Shadowbox", InsetBox::Shadowbox);
60         translator.addPair("Shaded", InsetBox::Shaded);
61         translator.addPair("Doublebox",InsetBox::Doublebox);
62         return translator;
63 }
64
65
66 BoxTranslatorLoc initBoxtranslatorLoc()
67 {
68         BoxTranslatorLoc translator(_("simple frame"), InsetBox::Boxed);
69         translator.addPair(_("frameless"), InsetBox::Frameless);
70         translator.addPair(_("simple frame, page breaks"), InsetBox::Framed);
71         translator.addPair(_("oval, thin"), InsetBox::ovalbox);
72         translator.addPair(_("oval, thick"), InsetBox::Ovalbox);
73         translator.addPair(_("drop shadow"), InsetBox::Shadowbox);
74         translator.addPair(_("shaded background"), InsetBox::Shaded);
75         translator.addPair(_("double frame"), InsetBox::Doublebox);
76         return translator;
77 }
78
79
80 BoxTranslator const & boxtranslator()
81 {
82         static BoxTranslator const translator = initBoxtranslator();
83         return translator;
84 }
85
86
87 BoxTranslatorLoc const & boxtranslator_loc()
88 {
89         static BoxTranslatorLoc const translator = initBoxtranslatorLoc();
90         return translator;
91 }
92
93 } // namespace anon
94
95
96 /////////////////////////////////////////////////////////////////////////
97 //
98 // InsetBox
99 //
100 /////////////////////////////////////////////////////////////////////////
101
102 InsetBox::InsetBox(Buffer * buffer, string const & label)
103         : InsetCollapsable(buffer), params_(label)
104 {}
105
106
107 docstring InsetBox::layoutName() const
108 {
109         // FIXME: UNICODE
110         return from_ascii("Box:" + params_.type);
111 }
112
113
114 void InsetBox::write(ostream & os) const
115 {
116         params_.write(os);
117         InsetCollapsable::write(os);
118 }
119
120
121 void InsetBox::read(Lexer & lex)
122 {
123         params_.read(lex);
124         InsetCollapsable::read(lex);
125 }
126
127
128 void InsetBox::setButtonLabel()
129 {
130         BoxType const btype = boxtranslator().find(params_.type);
131
132         docstring const type = _("Box");
133
134         docstring inner;
135         if (params_.inner_box) {
136                 if (params_.use_parbox)
137                         inner = _("Parbox");
138                 else if (params_.use_makebox)
139                         inner = _("Makebox");
140                 else
141                         inner = _("Minipage");
142         }
143
144         docstring frame;
145         if (btype != Frameless)
146                 frame = boxtranslator_loc().find(btype);
147
148         docstring label;
149         if (inner.empty() && frame.empty())
150                 label = type;
151         else if (inner.empty())
152                 label = bformat(_("%1$s (%2$s)"),
153                         type, frame);
154         else if (frame.empty())
155                 label = bformat(_("%1$s (%2$s)"),
156                         type, inner);
157         else
158                 label = bformat(_("%1$s (%2$s, %3$s)"),
159                         type, inner, frame);
160         setLabel(label);
161 }
162
163
164 bool InsetBox::hasFixedWidth() const
165 {
166         return !params_.width.empty();
167 }
168
169
170 bool InsetBox::allowMultiPar() const
171 {
172         return (params_.inner_box && !params_.use_makebox)
173                 || params_.type == "Shaded" || params_.type == "Framed";
174 }
175
176
177 void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
178 {
179         // back up textwidth.
180         int textwidth_backup = m.base.textwidth;
181         if (hasFixedWidth())
182                 m.base.textwidth = params_.width.inPixels(m.base);
183         InsetCollapsable::metrics(m, dim);
184         // retore textwidth.
185         m.base.textwidth = textwidth_backup;
186 }
187
188
189 bool InsetBox::forcePlainLayout(idx_type) const
190 {
191         return (!params_.inner_box || params_.use_makebox)
192                 && params_.type != "Shaded" && params_.type != "Framed";
193 }
194
195
196 ColorCode InsetBox::backgroundColor(PainterInfo const &) const
197 {
198         // we only support background color for 3 types
199         if (params_.type != "Shaded" && params_.type != "Frameless" && params_.type != "Boxed")
200                 return getLayout().bgcolor();
201         if (params_.type == "Shaded") {
202                 // FIXME: This hardcoded color is a hack!
203                 if (buffer().params().boxbgcolor == lyx::rgbFromHexName("#ff0000"))
204                         return getLayout().bgcolor();
205                 
206                 ColorCode c = lcolor.getFromLyXName("boxbgcolor");
207                 if (c == Color_none)
208                         return getLayout().bgcolor();
209                 return c;
210         } else {
211                 if (params_.backgroundcolor == "none")
212                         return getLayout().bgcolor();
213                 ColorCode boxbackground = lcolor.getFromLyXName(params_.backgroundcolor);
214                 return boxbackground;
215         }
216         return getLayout().bgcolor();
217 }
218
219
220 void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd)
221 {
222         switch (cmd.action()) {
223
224         case LFUN_INSET_MODIFY: {
225                 //lyxerr << "InsetBox::dispatch MODIFY" << endl;
226                 string const first_arg = cmd.getArg(0);
227                 bool const change_type = first_arg == "changetype";
228                 bool const for_box = first_arg == "box";
229                 if (!change_type && !for_box) {
230                         // not for us
231                         // this will not be handled higher up
232                         cur.undispatched();
233                         return;
234                 }
235                 cur.recordUndoInset(this);
236                 if (change_type)
237                         params_.type = cmd.getArg(1);
238                 else // if (for_box)
239                         string2params(to_utf8(cmd.argument()), params_);
240                 setButtonLabel();
241                 break;
242         }
243
244         default:
245                 InsetCollapsable::doDispatch(cur, cmd);
246                 break;
247         }
248 }
249
250
251 bool InsetBox::getStatus(Cursor & cur, FuncRequest const & cmd,
252                 FuncStatus & flag) const
253 {
254         switch (cmd.action()) {
255
256         case LFUN_INSET_MODIFY: {
257                 string const first_arg = cmd.getArg(0);
258                 if (first_arg == "changetype") {
259                         string const type = cmd.getArg(1);
260                         flag.setOnOff(type == params_.type);
261                         flag.setEnabled(!params_.inner_box || type != "Framed");
262                         return true;
263                 }
264                 if (first_arg == "box") {
265                         flag.setEnabled(true);
266                         return true;
267                 }
268                 return InsetCollapsable::getStatus(cur, cmd, flag);
269         }
270
271         case LFUN_INSET_DIALOG_UPDATE:
272                 flag.setEnabled(true);
273                 return true;
274
275         default:
276                 return InsetCollapsable::getStatus(cur, cmd, flag);
277         }
278 }
279
280
281 const string defaultThick = "0.4pt";
282 const string defaultSep = "3pt";
283 const string defaultShadow = "4pt";
284
285 void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
286 {
287         BoxType btype = boxtranslator().find(params_.type);
288
289         string width_string = params_.width.asLatexString();
290         string thickness_string = params_.thickness.asLatexString();
291         string separation_string = params_.separation.asLatexString();
292         string shadowsize_string = params_.shadowsize.asLatexString();
293         bool stdwidth = false;
294         // in general the overall width of some decorated boxes is wider thean the inner box
295         // we could therefore calculate the real width for all sizes so that if the user wants
296         // e.g. 0.1\columnwidth or 2cm he gets exactly this size
297         // however this makes problems when importing TeX code
298         // therefore only recalculate for the most common case that the box should not protrude
299         // the page margins
300         if (params_.inner_box
301                 && ((width_string.find("1\\columnwidth") != string::npos
302                         || width_string.find("1\\textwidth") != string::npos)
303                         || width_string.find("1\\paperwidth") != string::npos
304                         || width_string.find("1\\linewidth") != string::npos)) {
305                 stdwidth = true;
306                 switch (btype) {
307                 case Frameless:
308                         break;
309                 case Framed:
310                         width_string += " - 2\\FrameSep - 2\\FrameRule";
311                         break;
312                 case Boxed:
313                         width_string += " - 2\\fboxsep - 2\\fboxrule";
314                         break;
315                 case Shaded:
316                         break;
317                 case ovalbox:
318                         width_string += " - 2\\fboxsep - 0.8pt";
319                         break;
320                 case Ovalbox:
321                         width_string += " - 2\\fboxsep - 1.6pt";
322                         break;
323                 case Shadowbox:
324                         width_string += " - 2\\fboxsep - 2\\fboxrule - \\shadowsize";
325                         break;
326                 case Doublebox:
327                         width_string += " - 2\\fboxsep - 7.5\\fboxrule - 1pt";
328                         break;
329                 }
330         }
331
332         os << safebreakln;
333         if (runparams.lastid != -1)
334                 os.texrow().start(runparams.lastid, runparams.lastpos);
335
336         // adapt column/text width correctly also if paragraphs indented
337         if (stdwidth && !(buffer().params().paragraph_separation))
338                 os << "\\noindent";
339
340         switch (btype) {
341         case Frameless:
342                 break;
343         case Framed:
344                 if (thickness_string != defaultThick) {
345                         os << "{\\FrameRule " << from_ascii(thickness_string);
346                         if (separation_string != defaultSep)
347                                 os << "\\FrameSep " << from_ascii(separation_string);
348                 }
349                 if (separation_string != defaultSep && thickness_string == defaultThick)
350                         os << "{\\FrameSep " << from_ascii(separation_string);
351
352                 os << "\\begin{framed}%\n";
353                 break;
354         case Boxed:
355                 if (thickness_string != defaultThick) {
356                         os << "{\\fboxrule " << from_ascii(thickness_string);
357                         if (separation_string != defaultSep)
358                                 os << "\\fboxsep " << from_ascii(separation_string);
359                 }
360                 if (separation_string != defaultSep && thickness_string == defaultThick)
361                         os << "{\\fboxsep " << from_ascii(separation_string);
362                 if (!params_.inner_box && !width_string.empty()) {
363                         if (params_.framecolor != "black" || params_.backgroundcolor != "none") {
364                                 os << "\\fcolorbox{" << params_.framecolor << "}{" << params_.backgroundcolor << "}{";
365                                 os << "\\makebox";
366                         } else
367                                 os << "\\framebox";
368                         // Special widths, see usrguide sec. 3.5
369                         // FIXME UNICODE
370                         if (params_.special != "none") {
371                                 os << "[" << params_.width.value()
372                                    << '\\' << from_utf8(params_.special)
373                                    << ']';
374                         } else
375                                 os << '[' << from_ascii(width_string)
376                                    << ']';
377                         if (params_.hor_pos != 'c')
378                                 os << "[" << params_.hor_pos << "]";
379                 } else {
380                         if (params_.framecolor != "black" || params_.backgroundcolor != "none")
381                                 os << "\\fcolorbox{" << params_.framecolor << "}{" << params_.backgroundcolor << "}";
382                         else
383                                 os << "\\fbox";
384                 }
385                 os << "{";
386                 break;
387         case ovalbox:
388                 if (!separation_string.empty() && separation_string != defaultSep)
389                         os << "{\\fboxsep " << from_ascii(separation_string);
390                 os << "\\ovalbox{";
391                 break;
392         case Ovalbox:
393                 if (!separation_string.empty() && separation_string != defaultSep)
394                         os << "{\\fboxsep " << from_ascii(separation_string);
395                 os << "\\Ovalbox{";
396                 break;
397         case Shadowbox:
398                 if (thickness_string != defaultThick) {
399                         os << "{\\fboxrule " << from_ascii(thickness_string);
400                         if (separation_string != defaultSep) {
401                                 os << "\\fboxsep " << from_ascii(separation_string);
402                                 if (shadowsize_string != defaultShadow)
403                                         os << "\\shadowsize " << from_ascii(shadowsize_string);
404                         }
405                         if (shadowsize_string != defaultShadow  && separation_string == defaultSep)
406                                 os << "\\shadowsize " << from_ascii(shadowsize_string);
407                 }
408                 if (separation_string != defaultSep && thickness_string == defaultThick) {
409                                 os << "{\\fboxsep " << from_ascii(separation_string);
410                                 if (shadowsize_string != defaultShadow)
411                                         os << "\\shadowsize " << from_ascii(shadowsize_string);
412                 }
413                 if (shadowsize_string != defaultShadow
414                                 && separation_string == defaultSep
415                                 && thickness_string == defaultThick)
416                                 os << "{\\shadowsize " << from_ascii(shadowsize_string);
417                 os << "\\shadowbox{";
418                 break;
419         case Shaded:
420                 // must be set later because e.g. the width settings only work when
421                 // it is inside a minipage or parbox
422                 break;
423         case Doublebox:
424                 if (thickness_string != defaultThick) {
425                         os << "{\\fboxrule " << from_ascii(thickness_string);
426                         if (separation_string != defaultSep)
427                                 os << "\\fboxsep " << from_ascii(separation_string);
428                 }
429                 if (separation_string != defaultSep && thickness_string == defaultThick)
430                         os << "{\\fboxsep " << from_ascii(separation_string);
431                 os << "\\doublebox{";
432                 break;
433         }
434
435         if (params_.inner_box) {
436                 if (params_.use_parbox) {
437                         if (params_.backgroundcolor != "none" && btype == Frameless)
438                                 os << "\\colorbox{" << params_.backgroundcolor << "}{";
439                         os << "\\parbox";
440                 } else if (params_.use_makebox) {
441                         if (!width_string.empty()) {
442                                 if (params_.backgroundcolor != "none")
443                                         os << "\\colorbox{" << params_.backgroundcolor << "}{";
444                                 os << "\\makebox";
445                                 // FIXME UNICODE
446                                 // output the width and horizontal position
447                                 if (params_.special != "none") {
448                                         os << "[" << params_.width.value()
449                                            << '\\' << from_utf8(params_.special)
450                                            << ']';
451                                 } else
452                                         os << '[' << from_ascii(width_string)
453                                            << ']';
454                                 if (params_.hor_pos != 'c')
455                                         os << "[" << params_.hor_pos << "]";
456                         } else {
457                                 if (params_.backgroundcolor != "none")
458                                         os << "\\colorbox{" << params_.backgroundcolor << "}";
459                                 else
460                                         os << "\\mbox";
461                         }
462                         os << "{";
463                 }
464                 else {
465                         if (params_.backgroundcolor != "none" && btype == Frameless)
466                                 os << "\\colorbox{" << params_.backgroundcolor << "}{";
467                         os << "\\begin{minipage}";
468                 }
469
470                 // output parameters for parbox and minipage
471                 if (!params_.use_makebox) {
472                         os << "[" << params_.pos << "]";
473                         if (params_.height_special == "none") {
474                                 // FIXME UNICODE
475                                 os << "[" << from_ascii(params_.height.asLatexString()) << "]";
476                         } else {
477                                 // Special heights
478                                 // set no optional argument when the value is the default "1\height"
479                                 // (special units like \height are handled as "in")
480                                 // but when the user has chosen a non-default inner_pos, the height
481                                 // must be given: \minipage[pos][height][inner-pos]{width}
482                                 if ((params_.height != Length("1in") ||
483                                         params_.height_special != "totalheight") ||
484                                         params_.inner_pos != params_.pos) {
485                                                 // FIXME UNICODE
486                                                 os << "[" << params_.height.value()
487                                                         << "\\" << from_utf8(params_.height_special) << "]";
488                                 }
489                         }
490                         if (params_.inner_pos != params_.pos)
491                                 os << "[" << params_.inner_pos << "]";
492                         // FIXME UNICODE
493                         os << '{' << from_ascii(width_string) << '}';
494                         if (params_.use_parbox)
495                                 os << "{";
496                 }
497
498                 os << "%\n";
499         } // end if inner_box
500
501         if (btype == Shaded) {
502                 os << "\\begin{shaded}%\n";
503         }
504
505         // \framebox and \makebox handle hor_pos their own way
506         // hor_pos is senseless for \mbox and \fbox
507         if (!(params_.use_makebox)
508                 && !(btype == Boxed && !params_.inner_box)) {
509                         switch (params_.hor_pos) {
510                         case 'l':
511                                 // do nothing because this is LaTeX's default
512                                 break;
513                         case 'c':
514                                 os << "\\centering ";
515                                 break;
516                         case 'r':
517                                 os << "\\raggedleft ";
518                                 break;
519                         }
520         }
521
522         InsetText::latex(os, runparams);
523
524         if (btype == Shaded)
525                 os << "\\end{shaded}";
526
527         if (params_.inner_box) {
528                 if (params_.use_parbox || params_.use_makebox)
529                         os << "%\n}";
530                 else
531                         os << "%\n\\end{minipage}";
532                 if (params_.backgroundcolor != "none" && btype == Frameless
533                         && !(params_.use_makebox && width_string.empty()))
534                         os << "}";
535         }
536
537         switch (btype) {
538         case Frameless:
539                 break;
540         case Framed:
541                 os << "\\end{framed}";
542                 if (separation_string != defaultSep     || thickness_string != defaultThick)
543                         os << "}";
544                 break;
545         case Boxed:
546                 os << "}";
547                 if (!params_.inner_box && !width_string.empty()
548                         && (params_.framecolor != "black" || params_.backgroundcolor != "none"))
549                         os << "}";
550                 if (separation_string != defaultSep     || thickness_string != defaultThick)
551                         os << "}";
552                 break;
553         case ovalbox:
554                 os << "}";
555                 if (separation_string != defaultSep)
556                         os << "}";
557                 break;
558         case Ovalbox:
559                 os << "}";
560                 if (separation_string != defaultSep)
561                         os << "}";
562                 break;
563         case Doublebox:
564                 os << "}";
565                 if (separation_string != defaultSep || thickness_string != defaultThick)
566                         os << "}";
567                 break;
568         case Shadowbox:
569                 os << "}";
570                 if (separation_string != defaultSep
571                         || thickness_string != defaultThick
572                         || shadowsize_string != defaultShadow)
573                         os << "}";
574                 break;
575         case Shaded:
576                 // already done
577                 break;
578         }
579 }
580
581
582 int InsetBox::plaintext(odocstringstream & os,
583        OutputParams const & runparams, size_t max_length) const
584 {
585         BoxType const btype = boxtranslator().find(params_.type);
586
587         switch (btype) {
588                 case Frameless:
589                         break;
590                 case Framed:
591                 case Boxed:
592                         os << "[\n";
593                         break;
594                 case ovalbox:
595                         os << "(\n";
596                         break;
597                 case Ovalbox:
598                         os << "((\n";
599                         break;
600                 case Shadowbox:
601                 case Shaded:
602                         os << "[/\n";
603                         break;
604                 case Doublebox:
605                         os << "[[\n";
606                         break;
607         }
608
609         InsetText::plaintext(os, runparams, max_length);
610
611         int len = 0;
612         switch (btype) {
613                 case Frameless:
614                         os << "\n";
615                         break;
616                 case Framed:
617                 case Boxed:
618                         os << "\n]";
619                         len = 1;
620                         break;
621                 case ovalbox:
622                         os << "\n)";
623                         len = 1;
624                         break;
625                 case Ovalbox:
626                         os << "\n))";
627                         len = 2;
628                         break;
629                 case Shadowbox:
630                 case Shaded:
631                         os << "\n/]";
632                         len = 2;
633                         break;
634                 case Doublebox:
635                         os << "\n]]";
636                         len = 2;
637                         break;
638         }
639
640         return PLAINTEXT_NEWLINE + len; // len chars on a separate line
641 }
642
643
644 int InsetBox::docbook(odocstream & os, OutputParams const & runparams) const
645 {
646         return InsetText::docbook(os, runparams);
647 }
648
649
650 docstring InsetBox::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
651 {
652         // construct attributes
653         string attrs = "class='" + params_.type + "'";
654         string style;
655         if (!params_.width.empty()) {
656                 string w = params_.width.asHTMLString();
657                 if (w != "100%")
658                         style += ("width: " + params_.width.asHTMLString() + "; ");
659         }
660         // The special heights don't really mean anything for us.
661         if (!params_.height.empty() && params_.height_special == "none")
662                 style += ("height: " + params_.height.asHTMLString() + "; ");
663         if (!style.empty())
664                 attrs += " style='" + style + "'";
665
666         xs << html::StartTag("div", attrs);
667         XHTMLOptions const opts = InsetText::WriteLabel | InsetText::WriteInnerTag;
668         docstring defer = InsetText::insetAsXHTML(xs, runparams, opts);
669         xs << html::EndTag("div");
670         xs << defer;
671         return docstring();
672 }
673
674
675 void InsetBox::validate(LaTeXFeatures & features) const
676 {
677         BoxType btype = boxtranslator().find(params_.type);
678         switch (btype) {
679         case Frameless:
680                 if (params_.backgroundcolor != "none")
681                         features.require("xcolor");
682                 break;
683         case Framed:
684                 features.require("calc");
685                 features.require("framed");
686                 break;
687         case Boxed:
688                 features.require("calc");
689                 if (params_.framecolor != "black" || params_.backgroundcolor != "none")
690                         features.require("xcolor");
691                 break;
692         case ovalbox:
693         case Ovalbox:
694         case Shadowbox:
695         case Doublebox:
696                 features.require("calc");
697                 features.require("fancybox");
698                 break;
699         case Shaded:
700                 features.require("color");
701                 features.require("framed");
702                 break;
703         }
704         InsetCollapsable::validate(features);
705 }
706
707
708 string InsetBox::contextMenuName() const
709 {
710         return "context-box";
711 }
712
713
714 string InsetBox::params2string(InsetBoxParams const & params)
715 {
716         ostringstream data;
717         data << "box" << ' ';
718         params.write(data);
719         return data.str();
720 }
721
722
723 void InsetBox::string2params(string const & in, InsetBoxParams & params)
724 {
725         if (in.empty())
726                 return;
727
728         istringstream data(in);
729         Lexer lex;
730         lex.setStream(data);
731
732         string name;
733         lex >> name;
734         if (!lex || name != "box") {
735                 LYXERR0("InsetBox::string2params(" << in << ")\n"
736                                           "Expected arg 1 to be \"box\"\n");
737                 return;
738         }
739
740         // This is part of the inset proper that is usually swallowed
741         // by Text::readInset
742         string id;
743         lex >> id;
744         if (!lex || id != "Box") {
745                 LYXERR0("InsetBox::string2params(" << in << ")\n"
746                                           "Expected arg 2 to be \"Box\"\n");
747         }
748
749         params = InsetBoxParams(string());
750         params.read(lex);
751 }
752
753
754 /////////////////////////////////////////////////////////////////////////
755 //
756 // InsetBoxParams
757 //
758 /////////////////////////////////////////////////////////////////////////
759
760 InsetBoxParams::InsetBoxParams(string const & label)
761         : type(label),
762           use_parbox(false),
763           use_makebox(false),
764           inner_box(true),
765           width(Length("100col%")),
766           special("none"),
767           pos('t'),
768           hor_pos('c'),
769           inner_pos('t'),
770           height(Length("1in")),
771           height_special("totalheight"), // default is 1\\totalheight
772           thickness(Length(defaultThick)),
773           separation(Length(defaultSep)),
774           shadowsize(Length(defaultShadow)),
775           framecolor("black"),
776           backgroundcolor("none")
777 {}
778
779
780 void InsetBoxParams::write(ostream & os) const
781 {
782         os << "Box " << type << "\n";
783         os << "position \"" << pos << "\"\n";
784         os << "hor_pos \"" << hor_pos << "\"\n";
785         os << "has_inner_box " << inner_box << "\n";
786         os << "inner_pos \"" << inner_pos << "\"\n";
787         os << "use_parbox " << use_parbox << "\n";
788         os << "use_makebox " << use_makebox << "\n";
789         os << "width \"" << width.asString() << "\"\n";
790         os << "special \"" << special << "\"\n";
791         os << "height \"" << height.asString() << "\"\n";
792         os << "height_special \"" << height_special << "\"\n";
793         os << "thickness \"" << thickness.asString() << "\"\n";
794         os << "separation \"" << separation.asString() << "\"\n";
795         os << "shadowsize \"" << shadowsize.asString() << "\"\n";
796         os << "framecolor \"" << framecolor << "\"\n";
797         os << "backgroundcolor \"" << backgroundcolor << "\"\n";
798 }
799
800
801 void InsetBoxParams::read(Lexer & lex)
802 {
803         lex.setContext("InsetBoxParams::read");
804         lex >> type;
805         lex >> "position" >> pos;
806         lex >> "hor_pos" >> hor_pos;
807         lex >> "has_inner_box" >> inner_box;
808         if (type == "Framed")
809                 inner_box = false;
810         lex >> "inner_pos" >> inner_pos;
811         lex >> "use_parbox" >> use_parbox;
812         lex >> "use_makebox" >> use_makebox;
813         lex >> "width" >> width;
814         lex >> "special" >> special;
815         lex >> "height" >> height;
816         lex >> "height_special" >> height_special;
817         lex >> "thickness" >> thickness;
818         lex >> "separation" >> separation;
819         lex >> "shadowsize" >> shadowsize;
820         lex >> "framecolor" >> framecolor;
821         lex >> "backgroundcolor" >> backgroundcolor;
822 }
823
824
825 } // namespace lyx