3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetWrap.h"
16 #include "BufferParams.h"
17 #include "BufferView.h"
20 #include "DispatchResult.h"
22 #include "FloatList.h"
23 #include "FuncRequest.h"
24 #include "FuncStatus.h"
26 #include "LaTeXFeatures.h"
29 #include "OutputParams.h"
30 #include "TocBackend.h"
32 #include "support/convert.h"
40 using std::istringstream;
42 using std::ostringstream;
45 InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
46 : InsetCollapsable(bp), name_(from_utf8(type))
48 setLabel(_("wrap: ") + floatName(type, bp));
49 Font font(Font::ALL_SANE);
52 font.setColor(Color::collapsable);
55 params_.width = Length(50, Length::PCW);
59 InsetWrap::~InsetWrap()
61 InsetWrapMailer(*this).hideDialog();
65 void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd)
68 case LFUN_INSET_MODIFY: {
69 InsetWrapParams params;
70 InsetWrapMailer::string2params(to_utf8(cmd.argument()), params);
71 params_.placement = params.placement;
72 params_.width = params.width;
76 case LFUN_INSET_DIALOG_UPDATE:
77 InsetWrapMailer(*this).updateDialog(&cur.bv());
80 case LFUN_MOUSE_RELEASE: {
81 if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
82 InsetWrapMailer(*this).showDialog(&cur.bv());
85 InsetCollapsable::doDispatch(cur, cmd);
90 InsetCollapsable::doDispatch(cur, cmd);
96 bool InsetWrap::getStatus(Cursor & cur, FuncRequest const & cmd,
97 FuncStatus & flag) const
100 case LFUN_INSET_MODIFY:
101 case LFUN_INSET_DIALOG_UPDATE:
106 return InsetCollapsable::getStatus(cur, cmd, flag);
111 void InsetWrapParams::write(ostream & os) const
113 os << "Wrap " << type << '\n';
115 if (!placement.empty())
116 os << "placement " << placement << "\n";
118 os << "width \"" << width.asString() << "\"\n";
122 void InsetWrapParams::read(Lexer & lex)
126 if (token == "placement")
129 // take countermeasures
130 lex.pushToken(token);
135 if (token == "width") {
137 width = Length(lex.getString());
139 lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
141 // take countermeasures
142 lex.pushToken(token);
147 void InsetWrap::write(Buffer const & buf, ostream & os) const
150 InsetCollapsable::write(buf, os);
154 void InsetWrap::read(Buffer const & buf, Lexer & lex)
157 InsetCollapsable::read(buf, lex);
161 void InsetWrap::validate(LaTeXFeatures & features) const
163 features.require("floatflt");
164 InsetCollapsable::validate(features);
168 auto_ptr<Inset> InsetWrap::doClone() const
170 return auto_ptr<Inset>(new InsetWrap(*this));
174 docstring const InsetWrap::editMessage() const
176 return _("Opened Wrap Inset");
180 int InsetWrap::latex(Buffer const & buf, odocstream & os,
181 OutputParams const & runparams) const
183 os << "\\begin{floating" << from_ascii(params_.type) << '}';
184 if (!params_.placement.empty())
185 os << '[' << from_ascii(params_.placement) << ']';
186 os << '{' << from_ascii(params_.width.asLatexString()) << "}%\n";
187 int const i = InsetText::latex(buf, os, runparams);
188 os << "\\end{floating" << from_ascii(params_.type) << "}%\n";
193 int InsetWrap::plaintext(Buffer const & buf, odocstream & os,
194 OutputParams const & runparams) const
196 os << '[' << buf.B_("wrap") << ' ' << floatName(params_.type, buf.params()) << ":\n";
197 InsetText::plaintext(buf, os, runparams);
200 return PLAINTEXT_NEWLINE + 1; // one char on a separate line
204 int InsetWrap::docbook(Buffer const & buf, odocstream & os,
205 OutputParams const & runparams) const
208 os << '<' << from_ascii(params_.type) << '>';
209 int const i = InsetText::docbook(buf, os, runparams);
210 os << "</" << from_ascii(params_.type) << '>';
215 bool InsetWrap::insetAllowed(Inset::Code code) const
223 return InsetCollapsable::insetAllowed(code);
228 bool InsetWrap::showInsetDialog(BufferView * bv) const
230 if (!InsetText::showInsetDialog(bv))
231 InsetWrapMailer(const_cast<InsetWrap &>(*this)).showDialog(bv);
236 string const InsetWrapMailer::name_("wrap");
238 InsetWrapMailer::InsetWrapMailer(InsetWrap & inset)
243 string const InsetWrapMailer::inset2string(Buffer const &) const
245 return params2string(inset_.params());
249 void InsetWrapMailer::string2params(string const & in, InsetWrapParams & params)
251 params = InsetWrapParams();
255 istringstream data(in);
261 if (!lex || name != name_)
262 return print_mailer_error("InsetWrapMailer", in, 1, name_);
264 // This is part of the inset proper that is usually swallowed
265 // by Text::readInset
268 if (!lex || id != "Wrap")
269 return print_mailer_error("InsetBoxMailer", in, 2, "Wrap");
271 // We have to read the type here!
277 string const InsetWrapMailer::params2string(InsetWrapParams const & params)
280 data << name_ << ' ';