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
14 #pragma implementation
17 #include "insetwrap.h"
20 #include "BufferView.h"
22 #include "insets/insettext.h"
23 #include "support/LOstream.h"
24 #include "support/lstrings.h"
25 #include "LaTeXFeatures.h"
28 #include "frontends/LyXView.h"
29 #include "frontends/Dialogs.h"
36 InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
37 : InsetCollapsable(bp), width_(50, LyXLength::PCW)
39 string lab(_("wrap"));
42 LyXFont font(LyXFont::ALL_SANE);
45 font.setColor(LColor::collapsable);
52 InsetWrap::InsetWrap(InsetWrap const & in, bool same_id)
53 : InsetCollapsable(in, same_id), Type_(in.Type_),
54 Placement_(in.Placement_), width_(in.width_)
58 InsetWrap::~InsetWrap()
64 void InsetWrap::write(Buffer const * buf, ostream & os) const
66 os << "Wrap " // getInsetName()
69 if (!Placement_.empty()) {
70 os << "placement " << Placement_ << "\n";
72 os << "width \"" << width_.asString() << "\"\n";
74 InsetCollapsable::write(buf, os);
78 void InsetWrap::read(Buffer const * buf, LyXLex & lex)
82 string token = lex.getString();
83 if (token == "placement") {
85 Placement_ = lex.getString();
87 // take countermeasures
93 string token = lex.getString();
94 if (token == "width") {
96 width_ = LyXLength(lex.getString());
98 lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
100 // take countermeasures
101 lex.pushToken(token);
104 InsetCollapsable::read(buf, lex);
108 void InsetWrap::validate(LaTeXFeatures & features) const
110 features.require("floatflt");
111 InsetCollapsable::validate(features);
115 Inset * InsetWrap::clone(Buffer const &, bool same_id) const
117 return new InsetWrap(*const_cast<InsetWrap *>(this), same_id);
121 string const InsetWrap::editMessage() const
123 return _("Opened Wrap Inset");
127 int InsetWrap::latex(Buffer const * buf,
128 ostream & os, bool fragile, bool fp) const
130 os << "\\begin{floating" << Type_ << "}";
131 if (!Placement_.empty()) {
132 os << "[" << Placement_ << "]";
134 os << "{" << width_.asLatexString() << "}%\n";
136 int const i = inset.latex(buf, os, fragile, fp);
138 os << "\\end{floating" << Type_ << "}%\n";
143 int InsetWrap::docbook(Buffer const * buf, ostream & os, bool mixcont) const
145 os << "<" << Type_ << ">";
146 int const i = inset.docbook(buf, os, mixcont);
147 os << "</" << Type_ << ">";
153 bool InsetWrap::insetAllowed(Inset::Code code) const
161 return InsetCollapsable::insetAllowed(code);
165 int InsetWrap::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
169 static_cast<UpdatableInset*>(owner())->getMaxWidth(bv, inset) < 0) {
172 if (!width_.zero()) {
173 int ww1 = latexTextWidth(bv);
174 int ww2 = InsetCollapsable::getMaxWidth(bv, inset);
175 if (ww2 > 0 && ww2 < ww1) {
180 // this should not happen!
181 return InsetCollapsable::getMaxWidth(bv, inset);
185 int InsetWrap::latexTextWidth(BufferView * bv) const
187 return width_.inPixels(InsetCollapsable::latexTextWidth(bv),
188 bv->text->defaultHeight());
192 string const & InsetWrap::type() const
198 LyXLength const & InsetWrap::pageWidth() const
204 void InsetWrap::pageWidth(LyXLength const & ll)
213 void InsetWrap::placement(string const & p)
219 string const & InsetWrap::placement() const
225 bool InsetWrap::showInsetDialog(BufferView * bv) const
227 if (!inset.showInsetDialog(bv)) {
228 bv->owner()->getDialogs().showWrap(const_cast<InsetWrap *>(this));