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 #include "insetcaption.h"
15 #include "frontends/Painter.h"
16 #include "frontends/font_metrics.h"
17 #include "BufferView.h"
19 #include "FloatList.h"
20 #include "insets/insetfloat.h"
23 #include "support/lstrings.h"
25 #include "BoostFormat.h"
30 InsetCaption::InsetCaption(BufferParams const & bp)
33 setAutoBreakRows(true);
34 setDrawFrame(0, InsetText::LOCKED);
35 setFrameColor(0, LColor::captionframe);
39 void InsetCaption::write(Buffer const * buf, ostream & os) const
42 writeParagraphData(buf, os);
47 void InsetCaption::read(Buffer const * buf, LyXLex & lex)
50 // We will enably this check again when the compability
51 // code is removed from Buffer::Read (Lgb)
52 string const token = lex.GetString();
53 if (token != "Caption") {
54 lyxerr << "InsetCaption::Read: consistency check failed."
58 InsetText::read(buf, lex);
62 string const InsetCaption::editMessage() const
64 return _("Opened Caption Inset");
68 void InsetCaption::draw(BufferView * bv, LyXFont const & f,
69 int baseline, float & x, bool cleared) const
71 // We must draw the label, we should get the label string
72 // from the enclosing float inset.
73 // The question is: Who should draw the label, the caption inset,
74 // the text inset or the paragraph?
75 // We should also draw the float number (Lgb)
77 // See if we can find the name of the float this caption
80 Inset * i2 = i1 ? i1->owner() : 0;
81 string const type = static_cast<InsetFloat *>(i2)->type();
82 FloatList const & floats =
83 bv->buffer()->params.getLyXTextClass().floats();
84 string const fl = i2 ? floats.getType(type).name() : N_("Float");
86 // Discover the number...
88 string const num("#");
92 boost::format frm("%1$s %2$s:");
94 string const label = frm.str();
97 string const label = _(fl) + ' ' + num + ':';
99 Painter & pain = bv->painter();
100 int const w = font_metrics::width(label, f);
101 pain.text(int(x), baseline, label, f);
104 InsetText::draw(bv, f, baseline, x, cleared);
108 int InsetCaption::latex(Buffer const * buf, ostream & os,
109 bool fragile, bool free_spc) const
111 // This is a bit too simplistic to take advantage of
112 // caption options we must add more later. (Lgb)
113 // This code is currently only able to handle the simple
114 // \caption{...}, later we will make it take advantage
115 // of the one of the caption packages. (Lgb)
117 int const l = InsetText::latex(buf, ost, fragile, free_spc);
118 os << "\\caption{" << ost.str() << "}\n";
123 int InsetCaption::ascii(Buffer const * /*buf*/,
124 ostream & /*os*/, int /*linelen*/) const
126 // FIX: Implement me!
131 int InsetCaption::docbook(Buffer const * buf, ostream & os, bool mixcont) const
135 ret = InsetText::docbook(buf, os, mixcont);