]> git.lyx.org Git - lyx.git/blob - src/insets/InsetBox.cpp
Cmake export tests: Add missing failing tests
[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         // set the frame color for the inset if the type is Boxed
163         if (btype == Boxed)
164                 setFrameColor(lcolor.getFromLaTeXName(params_.framecolor));
165         else
166                 setFrameColor(Color_collapsableframe);
167 }
168
169
170 bool InsetBox::hasFixedWidth() const
171 {
172         return !params_.width.empty();
173 }
174
175
176 bool InsetBox::allowMultiPar() const
177 {
178         return (params_.inner_box && !params_.use_makebox)
179                 || params_.type == "Shaded" || params_.type == "Framed";
180 }
181
182
183 void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
184 {
185         // back up textwidth.
186         int textwidth_backup = m.base.textwidth;
187         if (hasFixedWidth())
188                 m.base.textwidth = params_.width.inPixels(m.base);
189         InsetCollapsable::metrics(m, dim);
190         // retore textwidth.
191         m.base.textwidth = textwidth_backup;
192 }
193
194
195 bool InsetBox::forcePlainLayout(idx_type) const
196 {
197         return (!params_.inner_box || params_.use_makebox)
198                 && params_.type != "Shaded" && params_.type != "Framed";
199 }
200
201
202 ColorCode InsetBox::backgroundColor(PainterInfo const &) const
203 {
204         // we only support background color for 3 types
205         if (params_.type != "Shaded" && params_.type != "Frameless" && params_.type != "Boxed")
206                 return getLayout().bgcolor();
207
208         if (params_.type == "Shaded") {
209                 // FIXME: This hardcoded color is a hack!
210                 if (buffer().params().boxbgcolor == lyx::rgbFromHexName("#ff0000"))
211                         return getLayout().bgcolor();
212
213                 ColorCode c = lcolor.getFromLyXName("boxbgcolor");
214                 if (c == Color_none)
215                         return getLayout().bgcolor();
216                 return c;
217         }
218
219         if (params_.backgroundcolor != "none")
220                 return lcolor.getFromLaTeXName(params_.backgroundcolor);
221
222         return getLayout().bgcolor();
223 }
224
225
226 LyXAlignment InsetBox::contentAlignment() const
227 {
228         if (!params_.use_makebox)
229                 return LYX_ALIGN_NONE;
230
231         // The default value below is actually irrelevant
232         LyXAlignment align = LYX_ALIGN_NONE;
233         switch (params_.hor_pos) {
234         case 'l':
235                 align = LYX_ALIGN_LEFT;
236                 break;
237         case 'c':
238                 align = LYX_ALIGN_CENTER;
239                 break;
240         case 'r':
241                 align = LYX_ALIGN_RIGHT;
242                 break;
243         case 's':
244                 align = LYX_ALIGN_BLOCK;
245                 break;
246         }
247         return align;
248 }
249
250
251 void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd)
252 {
253         switch (cmd.action()) {
254
255         case LFUN_INSET_MODIFY: {
256                 //lyxerr << "InsetBox::dispatch MODIFY" << endl;
257                 string const first_arg = cmd.getArg(0);
258                 bool const change_type = first_arg == "changetype";
259                 bool const for_box = first_arg == "box";
260                 if (!change_type && !for_box) {
261                         // not for us
262                         // this will not be handled higher up
263                         cur.undispatched();
264                         return;
265                 }
266                 cur.recordUndoInset(this);
267                 if (change_type)
268                         params_.type = cmd.getArg(1);
269                 else // if (for_box)
270                         string2params(to_utf8(cmd.argument()), params_);
271                 setButtonLabel();
272                 break;
273         }
274
275         default:
276                 InsetCollapsable::doDispatch(cur, cmd);
277                 break;
278         }
279 }
280
281
282 bool InsetBox::getStatus(Cursor & cur, FuncRequest const & cmd,
283                 FuncStatus & flag) const
284 {
285         switch (cmd.action()) {
286
287         case LFUN_INSET_MODIFY: {
288                 string const first_arg = cmd.getArg(0);
289                 if (first_arg == "changetype") {
290                         string const type = cmd.getArg(1);
291                         flag.setOnOff(type == params_.type);
292                         flag.setEnabled(!params_.inner_box || type != "Framed");
293                         return true;
294                 }
295                 if (first_arg == "box") {
296                         flag.setEnabled(true);
297                         return true;
298                 }
299                 return InsetCollapsable::getStatus(cur, cmd, flag);
300         }
301
302         case LFUN_INSET_DIALOG_UPDATE:
303                 flag.setEnabled(true);
304                 return true;
305
306         default:
307                 return InsetCollapsable::getStatus(cur, cmd, flag);
308         }
309 }
310
311
312 const string defaultThick = "0.4pt";
313 const string defaultSep = "3pt";
314 const string defaultShadow = "4pt";
315
316 void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
317 {
318         BoxType btype = boxtranslator().find(params_.type);
319
320         string width_string = params_.width.asLatexString();
321         string thickness_string = params_.thickness.asLatexString();
322         string separation_string = params_.separation.asLatexString();
323         string shadowsize_string = params_.shadowsize.asLatexString();
324         bool stdwidth = false;
325         // in general the overall width of some decorated boxes is wider thean the inner box
326         // we could therefore calculate the real width for all sizes so that if the user wants
327         // e.g. 0.1\columnwidth or 2cm he gets exactly this size
328         // however this makes problems when importing TeX code
329         // therefore only recalculate for the most common case that the box should not protrude
330         // the page margins
331         if (params_.inner_box
332                 && ((width_string.find("1\\columnwidth") != string::npos
333                         || width_string.find("1\\textwidth") != string::npos)
334                         || width_string.find("1\\paperwidth") != string::npos
335                         || width_string.find("1\\linewidth") != string::npos)) {
336                 stdwidth = true;
337                 switch (btype) {
338                 case Frameless:
339                         break;
340                 case Framed:
341                         width_string += " - 2\\FrameSep - 2\\FrameRule";
342                         break;
343                 case Boxed:
344                         width_string += " - 2\\fboxsep - 2\\fboxrule";
345                         break;
346                 case Shaded:
347                         break;
348                 case ovalbox:
349                         width_string += " - 2\\fboxsep - 0.8pt";
350                         break;
351                 case Ovalbox:
352                         width_string += " - 2\\fboxsep - 1.6pt";
353                         break;
354                 case Shadowbox:
355                         width_string += " - 2\\fboxsep - 2\\fboxrule - \\shadowsize";
356                         break;
357                 case Doublebox:
358                         width_string += " - 2\\fboxsep - 7.5\\fboxrule - 1pt";
359                         break;
360                 }
361         }
362
363         os << safebreakln;
364         if (runparams.lastid != -1)
365                 os.texrow().start(runparams.lastid, runparams.lastpos);
366
367         // adapt column/text width correctly also if paragraphs indented
368         if (stdwidth && !(buffer().params().paragraph_separation))
369                 os << "\\noindent";
370
371         switch (btype) {
372         case Frameless:
373                 break;
374         case Framed:
375                 if (thickness_string != defaultThick) {
376                         os << "{\\FrameRule " << from_ascii(thickness_string);
377                         if (separation_string != defaultSep)
378                                 os << "\\FrameSep " << from_ascii(separation_string);
379                 }
380                 if (separation_string != defaultSep && thickness_string == defaultThick)
381                         os << "{\\FrameSep " << from_ascii(separation_string);
382
383                 os << "\\begin{framed}%\n";
384                 break;
385         case Boxed:
386                 if (thickness_string != defaultThick) {
387                         os << "{\\fboxrule " << from_ascii(thickness_string);
388                         if (separation_string != defaultSep)
389                                 os << "\\fboxsep " << from_ascii(separation_string);
390                 }
391                 if (separation_string != defaultSep && thickness_string == defaultThick)
392                         os << "{\\fboxsep " << from_ascii(separation_string);
393                 if (!params_.inner_box && !width_string.empty()) {
394                         if (params_.framecolor != "black" || params_.backgroundcolor != "none") {
395                                 os << "\\fcolorbox{" << params_.framecolor << "}{" << params_.backgroundcolor << "}{";
396                                 os << "\\makebox";
397                         } else
398                                 os << "\\framebox";
399                         // Special widths, see usrguide sec. 3.5
400                         // FIXME UNICODE
401                         if (params_.special != "none") {
402                                 os << "[" << params_.width.value()
403                                    << '\\' << from_utf8(params_.special)
404                                    << ']';
405                         } else
406                                 os << '[' << from_ascii(width_string)
407                                    << ']';
408                         // default horizontal alignment is 'c'
409                         if (params_.hor_pos != 'c')
410                                 os << "[" << params_.hor_pos << "]";
411                 } else {
412                         if (params_.framecolor != "black" || params_.backgroundcolor != "none")
413                                 os << "\\fcolorbox{" << params_.framecolor << "}{" << params_.backgroundcolor << "}";
414                         else
415                                 os << "\\fbox";
416                 }
417                 os << "{";
418                 break;
419         case ovalbox:
420                 if (!separation_string.empty() && separation_string != defaultSep)
421                         os << "{\\fboxsep " << from_ascii(separation_string);
422                 os << "\\ovalbox{";
423                 break;
424         case Ovalbox:
425                 if (!separation_string.empty() && separation_string != defaultSep)
426                         os << "{\\fboxsep " << from_ascii(separation_string);
427                 os << "\\Ovalbox{";
428                 break;
429         case Shadowbox:
430                 if (thickness_string != defaultThick) {
431                         os << "{\\fboxrule " << from_ascii(thickness_string);
432                         if (separation_string != defaultSep) {
433                                 os << "\\fboxsep " << from_ascii(separation_string);
434                                 if (shadowsize_string != defaultShadow)
435                                         os << "\\shadowsize " << from_ascii(shadowsize_string);
436                         }
437                         if (shadowsize_string != defaultShadow  && separation_string == defaultSep)
438                                 os << "\\shadowsize " << from_ascii(shadowsize_string);
439                 }
440                 if (separation_string != defaultSep && thickness_string == defaultThick) {
441                                 os << "{\\fboxsep " << from_ascii(separation_string);
442                                 if (shadowsize_string != defaultShadow)
443                                         os << "\\shadowsize " << from_ascii(shadowsize_string);
444                 }
445                 if (shadowsize_string != defaultShadow
446                                 && separation_string == defaultSep
447                                 && thickness_string == defaultThick)
448                                 os << "{\\shadowsize " << from_ascii(shadowsize_string);
449                 os << "\\shadowbox{";
450                 break;
451         case Shaded:
452                 // must be set later because e.g. the width settings only work when
453                 // it is inside a minipage or parbox
454                 break;
455         case Doublebox:
456                 if (thickness_string != defaultThick) {
457                         os << "{\\fboxrule " << from_ascii(thickness_string);
458                         if (separation_string != defaultSep)
459                                 os << "\\fboxsep " << from_ascii(separation_string);
460                 }
461                 if (separation_string != defaultSep && thickness_string == defaultThick)
462                         os << "{\\fboxsep " << from_ascii(separation_string);
463                 os << "\\doublebox{";
464                 break;
465         }
466
467         if (params_.inner_box) {
468                 if (params_.use_parbox) {
469                         if (params_.backgroundcolor != "none" && btype == Frameless)
470                                 os << "\\colorbox{" << params_.backgroundcolor << "}{";
471                         os << "\\parbox";
472                 } else if (params_.use_makebox) {
473                         if (!width_string.empty()) {
474                                 if (params_.backgroundcolor != "none")
475                                         os << "\\colorbox{" << params_.backgroundcolor << "}{";
476                                 os << "\\makebox";
477                                 // FIXME UNICODE
478                                 // output the width and horizontal position
479                                 if (params_.special != "none") {
480                                         os << "[" << params_.width.value()
481                                            << '\\' << from_utf8(params_.special)
482                                            << ']';
483                                 } else
484                                         os << '[' << from_ascii(width_string)
485                                            << ']';
486                                 if (params_.hor_pos != 'c')
487                                         os << "[" << params_.hor_pos << "]";
488                         } else {
489                                 if (params_.backgroundcolor != "none")
490                                         os << "\\colorbox{" << params_.backgroundcolor << "}";
491                                 else
492                                         os << "\\mbox";
493                         }
494                         os << "{";
495                 }
496                 else {
497                         if (params_.backgroundcolor != "none" && btype == Frameless)
498                                 os << "\\colorbox{" << params_.backgroundcolor << "}{";
499                         os << "\\begin{minipage}";
500                 }
501
502                 // output parameters for parbox and minipage
503                 if (!params_.use_makebox) {
504                         os << "[" << params_.pos << "]";
505                         if (params_.height_special == "none") {
506                                 // FIXME UNICODE
507                                 os << "[" << from_ascii(params_.height.asLatexString()) << "]";
508                         } else {
509                                 // Special heights
510                                 // set no optional argument when the value is the default "1\height"
511                                 // (special units like \height are handled as "in")
512                                 // but when the user has chosen a non-default inner_pos, the height
513                                 // must be given: \minipage[pos][height][inner-pos]{width}
514                                 if ((params_.height != Length("1in") ||
515                                         params_.height_special != "totalheight") ||
516                                         params_.inner_pos != params_.pos) {
517                                                 // FIXME UNICODE
518                                                 os << "[" << params_.height.value()
519                                                         << "\\" << from_utf8(params_.height_special) << "]";
520                                 }
521                         }
522                         if (params_.inner_pos != params_.pos)
523                                 os << "[" << params_.inner_pos << "]";
524                         // FIXME UNICODE
525                         os << '{' << from_ascii(width_string) << '}';
526                         if (params_.use_parbox)
527                                 os << "{";
528                 }
529
530                 os << "%\n";
531         } // end if inner_box
532
533         if (btype == Shaded) {
534                 os << "\\begin{shaded}%\n";
535         }
536
537         InsetText::latex(os, runparams);
538
539         if (btype == Shaded)
540                 os << "\\end{shaded}";
541
542         if (params_.inner_box) {
543                 if (params_.use_parbox || params_.use_makebox)
544                         os << "%\n}";
545                 else
546                         os << "%\n\\end{minipage}";
547                 if (params_.backgroundcolor != "none" && btype == Frameless
548                         && !(params_.use_makebox && width_string.empty()))
549                         os << "}";
550         }
551
552         switch (btype) {
553         case Frameless:
554                 break;
555         case Framed:
556                 os << "\\end{framed}";
557                 if (separation_string != defaultSep     || thickness_string != defaultThick)
558                         os << "}";
559                 break;
560         case Boxed:
561                 os << "}";
562                 if (!params_.inner_box && !width_string.empty()
563                         && (params_.framecolor != "black" || params_.backgroundcolor != "none"))
564                         os << "}";
565                 if (separation_string != defaultSep     || thickness_string != defaultThick)
566                         os << "}";
567                 break;
568         case ovalbox:
569                 os << "}";
570                 if (separation_string != defaultSep)
571                         os << "}";
572                 break;
573         case Ovalbox:
574                 os << "}";
575                 if (separation_string != defaultSep)
576                         os << "}";
577                 break;
578         case Doublebox:
579                 os << "}";
580                 if (separation_string != defaultSep || thickness_string != defaultThick)
581                         os << "}";
582                 break;
583         case Shadowbox:
584                 os << "}";
585                 if (separation_string != defaultSep
586                         || thickness_string != defaultThick
587                         || shadowsize_string != defaultShadow)
588                         os << "}";
589                 break;
590         case Shaded:
591                 // already done
592                 break;
593         }
594 }
595
596
597 int InsetBox::plaintext(odocstringstream & os,
598        OutputParams const & runparams, size_t max_length) const
599 {
600         BoxType const btype = boxtranslator().find(params_.type);
601
602         switch (btype) {
603                 case Frameless:
604                         break;
605                 case Framed:
606                 case Boxed:
607                         os << "[\n";
608                         break;
609                 case ovalbox:
610                         os << "(\n";
611                         break;
612                 case Ovalbox:
613                         os << "((\n";
614                         break;
615                 case Shadowbox:
616                 case Shaded:
617                         os << "[/\n";
618                         break;
619                 case Doublebox:
620                         os << "[[\n";
621                         break;
622         }
623
624         InsetText::plaintext(os, runparams, max_length);
625
626         int len = 0;
627         switch (btype) {
628                 case Frameless:
629                         os << "\n";
630                         break;
631                 case Framed:
632                 case Boxed:
633                         os << "\n]";
634                         len = 1;
635                         break;
636                 case ovalbox:
637                         os << "\n)";
638                         len = 1;
639                         break;
640                 case Ovalbox:
641                         os << "\n))";
642                         len = 2;
643                         break;
644                 case Shadowbox:
645                 case Shaded:
646                         os << "\n/]";
647                         len = 2;
648                         break;
649                 case Doublebox:
650                         os << "\n]]";
651                         len = 2;
652                         break;
653         }
654
655         return PLAINTEXT_NEWLINE + len; // len chars on a separate line
656 }
657
658
659 int InsetBox::docbook(odocstream & os, OutputParams const & runparams) const
660 {
661         return InsetText::docbook(os, runparams);
662 }
663
664
665 docstring InsetBox::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
666 {
667         // construct attributes
668         string attrs = "class='" + params_.type + "'";
669         string style;
670         if (!params_.width.empty()) {
671                 string w = params_.width.asHTMLString();
672                 if (w != "100%")
673                         style += ("width: " + params_.width.asHTMLString() + "; ");
674         }
675         // The special heights don't really mean anything for us.
676         if (!params_.height.empty() && params_.height_special == "none")
677                 style += ("height: " + params_.height.asHTMLString() + "; ");
678         if (!style.empty())
679                 attrs += " style='" + style + "'";
680
681         xs << html::StartTag("div", attrs);
682         XHTMLOptions const opts = InsetText::WriteLabel | InsetText::WriteInnerTag;
683         docstring defer = InsetText::insetAsXHTML(xs, runparams, opts);
684         xs << html::EndTag("div");
685         xs << defer;
686         return docstring();
687 }
688
689
690 void InsetBox::validate(LaTeXFeatures & features) const
691 {
692         BoxType btype = boxtranslator().find(params_.type);
693         switch (btype) {
694         case Frameless:
695                 if (params_.backgroundcolor != "none")
696                         features.require("xcolor");
697                 break;
698         case Framed:
699                 features.require("calc");
700                 features.require("framed");
701                 break;
702         case Boxed:
703                 features.require("calc");
704                 if (params_.framecolor != "black" || params_.backgroundcolor != "none")
705                         features.require("xcolor");
706                 break;
707         case ovalbox:
708         case Ovalbox:
709         case Shadowbox:
710         case Doublebox:
711                 features.require("calc");
712                 features.require("fancybox");
713                 break;
714         case Shaded:
715                 features.require("color");
716                 features.require("framed");
717                 break;
718         }
719         InsetCollapsable::validate(features);
720 }
721
722
723 string InsetBox::contextMenuName() const
724 {
725         return "context-box";
726 }
727
728
729 string InsetBox::params2string(InsetBoxParams const & params)
730 {
731         ostringstream data;
732         data << "box" << ' ';
733         params.write(data);
734         return data.str();
735 }
736
737
738 void InsetBox::string2params(string const & in, InsetBoxParams & params)
739 {
740         if (in.empty())
741                 return;
742
743         istringstream data(in);
744         Lexer lex;
745         lex.setStream(data);
746
747         string name;
748         lex >> name;
749         if (!lex || name != "box") {
750                 LYXERR0("InsetBox::string2params(" << in << ")\n"
751                                           "Expected arg 1 to be \"box\"\n");
752                 return;
753         }
754
755         // This is part of the inset proper that is usually swallowed
756         // by Text::readInset
757         string id;
758         lex >> id;
759         if (!lex || id != "Box") {
760                 LYXERR0("InsetBox::string2params(" << in << ")\n"
761                                           "Expected arg 2 to be \"Box\"\n");
762         }
763
764         params = InsetBoxParams(string());
765         params.read(lex);
766 }
767
768
769 /////////////////////////////////////////////////////////////////////////
770 //
771 // InsetBoxParams
772 //
773 /////////////////////////////////////////////////////////////////////////
774
775 InsetBoxParams::InsetBoxParams(string const & label)
776         : type(label),
777           use_parbox(false),
778           use_makebox(false),
779           inner_box(true),
780           width(Length("100col%")),
781           special("none"),
782           pos('t'),
783           hor_pos('c'),
784           inner_pos('t'),
785           height(Length("1in")),
786           height_special("totalheight"), // default is 1\\totalheight
787           thickness(Length(defaultThick)),
788           separation(Length(defaultSep)),
789           shadowsize(Length(defaultShadow)),
790           framecolor("black"),
791           backgroundcolor("none")
792 {}
793
794
795 void InsetBoxParams::write(ostream & os) const
796 {
797         os << "Box " << type << "\n";
798         os << "position \"" << pos << "\"\n";
799         os << "hor_pos \"" << hor_pos << "\"\n";
800         os << "has_inner_box " << inner_box << "\n";
801         os << "inner_pos \"" << inner_pos << "\"\n";
802         os << "use_parbox " << use_parbox << "\n";
803         os << "use_makebox " << use_makebox << "\n";
804         os << "width \"" << width.asString() << "\"\n";
805         os << "special \"" << special << "\"\n";
806         os << "height \"" << height.asString() << "\"\n";
807         os << "height_special \"" << height_special << "\"\n";
808         os << "thickness \"" << thickness.asString() << "\"\n";
809         os << "separation \"" << separation.asString() << "\"\n";
810         os << "shadowsize \"" << shadowsize.asString() << "\"\n";
811         os << "framecolor \"" << framecolor << "\"\n";
812         os << "backgroundcolor \"" << backgroundcolor << "\"\n";
813 }
814
815
816 void InsetBoxParams::read(Lexer & lex)
817 {
818         lex.setContext("InsetBoxParams::read");
819         lex >> type;
820         lex >> "position" >> pos;
821         lex >> "hor_pos" >> hor_pos;
822         lex >> "has_inner_box" >> inner_box;
823         if (type == "Framed")
824                 inner_box = false;
825         lex >> "inner_pos" >> inner_pos;
826         lex >> "use_parbox" >> use_parbox;
827         lex >> "use_makebox" >> use_makebox;
828         lex >> "width" >> width;
829         lex >> "special" >> special;
830         lex >> "height" >> height;
831         lex >> "height_special" >> height_special;
832         lex >> "thickness" >> thickness;
833         lex >> "separation" >> separation;
834         lex >> "shadowsize" >> shadowsize;
835         lex >> "framecolor" >> framecolor;
836         lex >> "backgroundcolor" >> backgroundcolor;
837 }
838
839
840 } // namespace lyx