3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "InsetWrap.h"
17 #include "BufferParams.h"
18 #include "BufferView.h"
21 #include "DispatchResult.h"
23 #include "FloatList.h"
24 #include "FuncRequest.h"
25 #include "FuncStatus.h"
26 #include "LaTeXFeatures.h"
28 #include "TextClass.h"
29 #include "TocBackend.h"
31 #include "support/convert.h"
32 #include "support/docstream.h"
33 #include "support/debug.h"
34 #include "support/gettext.h"
36 #include "frontends/Application.h"
43 InsetWrap::InsetWrap(Buffer const & buf, string const & type)
44 : InsetCollapsable(buf)
46 setLabel(_("wrap: ") + floatName(type, buf.params()));
49 params_.placement = "o";
50 params_.overhang = Length(0, Length::PCW);
51 params_.width = Length(50, Length::PCW);
55 InsetWrap::~InsetWrap()
57 hideDialogs("wrap", this);
61 docstring InsetWrap::name() const
63 return from_utf8(params_.type);
67 void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd)
70 case LFUN_INSET_MODIFY: {
71 InsetWrapParams params;
72 InsetWrap::string2params(to_utf8(cmd.argument()), params);
73 params_.lines = params.lines;
74 params_.placement = params.placement;
75 params_.overhang = params.overhang;
76 params_.width = params.width;
80 case LFUN_INSET_DIALOG_UPDATE:
81 cur.bv().updateDialog("wrap", params2string(params()));
85 InsetCollapsable::doDispatch(cur, cmd);
91 bool InsetWrap::getStatus(Cursor & cur, FuncRequest const & cmd,
92 FuncStatus & flag) const
95 case LFUN_INSET_MODIFY:
96 case LFUN_INSET_DIALOG_UPDATE:
101 return InsetCollapsable::getStatus(cur, cmd, flag);
106 void InsetWrap::updateLabels(ParIterator const & it)
108 setLabel(_("wrap: ") + floatName(params_.type, buffer().params()));
109 Counters & cnts = buffer().params().documentClass().counters();
110 string const saveflt = cnts.current_float();
112 // Tell to captions what the current float is
113 cnts.current_float(params().type);
115 InsetCollapsable::updateLabels(it);
118 cnts.current_float(saveflt);
122 void InsetWrapParams::write(ostream & os) const
124 os << "Wrap " << type << '\n';
125 os << "lines " << lines << '\n';
126 os << "placement " << placement << '\n';
127 os << "overhang " << overhang.asString() << '\n';
128 os << "width \"" << width.asString() << "\"\n";
132 void InsetWrapParams::read(Lexer & lex)
134 lex.setContext("InsetWrapParams::read");
135 lex >> "lines" >> lines;
136 lex >> "placement" >> placement;
137 lex >> "overhang" >> overhang;
138 lex >> "width" >> width;
142 void InsetWrap::write(ostream & os) const
145 InsetCollapsable::write(os);
149 void InsetWrap::read(Lexer & lex)
152 InsetCollapsable::read(lex);
156 void InsetWrap::validate(LaTeXFeatures & features) const
158 features.require("wrapfig");
159 InsetCollapsable::validate(features);
163 docstring InsetWrap::editMessage() const
165 return _("Opened Wrap Inset");
169 int InsetWrap::latex(odocstream & os, OutputParams const & runparams) const
171 os << "\\begin{wrap" << from_ascii(params_.type) << '}';
172 // no optional argument when lines are zero
173 if (params_.lines != 0)
174 os << '[' << params_.lines << ']';
175 os << '{' << from_ascii(params_.placement) << '}';
176 Length over(params_.overhang);
177 // no optional argument when the value is zero
178 if (over.value() != 0)
179 os << '[' << from_ascii(params_.overhang.asLatexString()) << ']';
180 os << '{' << from_ascii(params_.width.asLatexString()) << "}%\n";
181 int const i = InsetText::latex(os, runparams);
182 os << "\\end{wrap" << from_ascii(params_.type) << "}%\n";
187 int InsetWrap::plaintext(odocstream & os, OutputParams const & runparams) const
189 os << '[' << buffer().B_("wrap") << ' '
190 << floatName(params_.type, buffer().params()) << ":\n";
191 InsetText::plaintext(os, runparams);
194 return PLAINTEXT_NEWLINE + 1; // one char on a separate line
198 int InsetWrap::docbook(odocstream & os, OutputParams const & runparams) const
201 os << '<' << from_ascii(params_.type) << '>';
202 int const i = InsetText::docbook(os, runparams);
203 os << "</" << from_ascii(params_.type) << '>';
208 bool InsetWrap::insetAllowed(InsetCode code) const
216 return InsetCollapsable::insetAllowed(code);
221 bool InsetWrap::showInsetDialog(BufferView * bv) const
223 if (!InsetText::showInsetDialog(bv))
224 bv->showDialog("wrap", params2string(params()),
225 const_cast<InsetWrap *>(this));
230 void InsetWrap::string2params(string const & in, InsetWrapParams & params)
232 params = InsetWrapParams();
233 istringstream data(in);
236 lex.setContext("InsetWrap::string2params");
238 lex >> "Wrap"; // Part of the inset proper, swallowed by Text::readInset
239 lex >> params.type; // We have to read the type here!
244 string InsetWrap::params2string(InsetWrapParams const & params)
247 data << "wrap" << ' ';