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