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