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 "insetvspace.h"
17 #include "BufferView.h"
18 #include "dispatchresult.h"
19 #include "funcrequest.h"
24 #include "metricsinfo.h"
26 #include "frontends/font_metrics.h"
27 #include "frontends/Painter.h"
29 #include "support/std_sstream.h"
31 using std::istringstream;
33 using std::ostringstream;
39 InsetVSpace::InsetVSpace(VSpace const & space)
44 InsetVSpace::~InsetVSpace()
46 InsetVSpaceMailer(*this).hideDialog();
50 std::auto_ptr<InsetBase> InsetVSpace::clone() const
52 return std::auto_ptr<InsetBase>(new InsetVSpace(*this));
57 InsetVSpace::priv_dispatch(FuncRequest const & cmd,
58 idx_type & idx, pos_type & pos)
62 case LFUN_INSET_MODIFY: {
63 InsetVSpaceMailer::string2params(cmd.argument, space_);
64 return DispatchResult(true, true);
67 case LFUN_MOUSE_PRESS:
68 InsetVSpaceMailer(*this).showDialog(cmd.view());
69 return DispatchResult(true, true);
72 return InsetOld::priv_dispatch(cmd, idx, pos);
77 void InsetVSpace::read(Buffer const &, LyXLex & lex)
81 space_ = VSpace(lex.getString());
86 void InsetVSpace::write(Buffer const &, ostream & os) const
88 os << "VSpace " << space_.asLyXCommand();
92 void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
95 if (space_.kind() != VSpace::NONE) {
96 int const arrow_size = 4;
97 int const space_size = space_.inPixels(*mi.base.bv);
101 int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
103 if (space_.length().len().value() < 0.0)
106 size = max(min_size, space_size);
117 void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
119 static std::string const label = _("Vertical Space");
124 //if (space_.kind() == VSpace::NONE)
127 int const arrow_size = 4;
128 int const start = y - dim_.asc;
129 int const end = y + dim_.des;
131 // the label to display (if any)
133 // y-values for top arrow
135 // y-values for bottom arrow
138 str = label + " (" + space_.asLyXCommand() + ")";
140 if (space_.kind() == VSpace::VFILL) {
144 // adding or removing space
145 bool const added = space_.kind() != VSpace::LENGTH ||
146 space_.length().len().value() > 0.0;
147 ty1 = added ? (start + arrow_size) : start;
148 ty2 = added ? start : (start + arrow_size);
149 by1 = added ? (end - arrow_size) : end;
150 by2 = added ? end : (end - arrow_size);
153 int const midx = xo_ + arrow_size;
154 int const rightx = midx + arrow_size;
162 font.setColor(LColor::added_space);
165 font_metrics::rectText(str, font, w, a, d);
167 pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
168 str, font, LColor::none, LColor::none);
171 pi.pain.line(x, ty1, midx, ty2, LColor::added_space);
172 pi.pain.line(midx, ty2, rightx, ty1, LColor::added_space);
175 pi.pain.line(x, by1, midx, by2, LColor::added_space);
176 pi.pain.line(midx, by2, rightx, by1, LColor::added_space);
179 pi.pain.line(midx, ty2, midx, by2, LColor::added_space);
183 int InsetVSpace::latex(Buffer const & buf, ostream & os,
184 OutputParams const &) const
186 os << space_.asLatexCommand(buf.params()) << '\n';
191 int InsetVSpace::plaintext(Buffer const &, ostream & os,
192 OutputParams const &) const
199 int InsetVSpace::linuxdoc(Buffer const &, std::ostream & os,
200 OutputParams const &) const
207 int InsetVSpace::docbook(Buffer const &, std::ostream & os,
208 OutputParams const &) const
215 string const InsetVSpaceMailer::name_ = "vspace";
218 InsetVSpaceMailer::InsetVSpaceMailer(InsetVSpace & inset)
223 string const InsetVSpaceMailer::inset2string(Buffer const &) const
225 return params2string(inset_.space_);
229 void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
236 istringstream data(in);
242 string const name = lex.getString();
245 // This is part of the inset proper that is usually swallowed
246 // by Buffer::readInset
249 vspace = VSpace(lex.getString());
254 string const InsetVSpaceMailer::params2string(VSpace const & vspace)
257 data << name_ << ' ' << vspace.asLyXCommand();