3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "insetcaption.h"
18 #include "frontends/Painter.h"
19 #include "frontends/font_metrics.h"
20 #include "BufferView.h"
22 #include "FloatList.h"
23 #include "insets/insetfloat.h"
26 #include "support/lstrings.h"
28 #include "BoostFormat.h"
33 InsetCaption::InsetCaption(BufferParams const & bp)
36 setAutoBreakRows(true);
37 setDrawFrame(0, InsetText::LOCKED);
38 setFrameColor(0, LColor::captionframe);
42 void InsetCaption::write(Buffer const * buf, ostream & os) const
45 writeParagraphData(buf, os);
50 void InsetCaption::read(Buffer const * buf, LyXLex & lex)
53 // We will enably this check again when the compability
54 // code is removed from Buffer::Read (Lgb)
55 string const token = lex.GetString();
56 if (token != "Caption") {
57 lyxerr << "InsetCaption::Read: consistency check failed."
61 InsetText::read(buf, lex);
65 string const InsetCaption::editMessage() const
67 return _("Opened Caption Inset");
71 void InsetCaption::draw(BufferView * bv, LyXFont const & f,
72 int baseline, float & x, bool cleared) const
74 // We must draw the label, we should get the label string
75 // from the enclosing float inset.
76 // The question is: Who should draw the label, the caption inset,
77 // the text inset or the paragraph?
78 // We should also draw the float number (Lgb)
80 // See if we can find the name of the float this caption
83 Inset * i2 = i1 ? i1->owner() : 0;
84 string const type = static_cast<InsetFloat *>(i2)->type();
85 FloatList const & floats =
86 bv->buffer()->params.getLyXTextClass().floats();
87 string const fl = i2 ? floats.getType(type).name() : N_("Float");
89 // Discover the number...
91 string const num("#");
94 string const label = boost::io::str(boost::format("%1$s %2$s:") % _(fl) % num);
96 Painter & pain = bv->painter();
97 int const w = font_metrics::width(label, f);
98 pain.text(int(x), baseline, label, f);
101 InsetText::draw(bv, f, baseline, x, cleared);
105 int InsetCaption::latex(Buffer const * buf, ostream & os,
106 bool fragile, bool free_spc) const
108 // This is a bit too simplistic to take advantage of
109 // caption options we must add more later. (Lgb)
110 // This code is currently only able to handle the simple
111 // \caption{...}, later we will make it take advantage
112 // of the one of the caption packages. (Lgb)
114 int const l = InsetText::latex(buf, ost, fragile, free_spc);
115 os << "\\caption{" << ost.str() << "}\n";
120 int InsetCaption::ascii(Buffer const * /*buf*/,
121 ostream & /*os*/, int /*linelen*/) const
123 // FIX: Implement me!
128 int InsetCaption::docbook(Buffer const * buf, ostream & os, bool mixcont) const
132 ret = InsetText::docbook(buf, os, mixcont);