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("#");
95 boost::format frm("%1$s %2$s:");
97 string const label = frm.str();
100 string const label = _(fl) + ' ' + num + ':';
102 Painter & pain = bv->painter();
103 int const w = font_metrics::width(label, f);
104 pain.text(int(x), baseline, label, f);
107 InsetText::draw(bv, f, baseline, x, cleared);
111 int InsetCaption::latex(Buffer const * buf, ostream & os,
112 bool fragile, bool free_spc) const
114 // This is a bit too simplistic to take advantage of
115 // caption options we must add more later. (Lgb)
116 // This code is currently only able to handle the simple
117 // \caption{...}, later we will make it take advantage
118 // of the one of the caption packages. (Lgb)
120 int const l = InsetText::latex(buf, ost, fragile, free_spc);
121 os << "\\caption{" << ost.str() << "}\n";
126 int InsetCaption::ascii(Buffer const * /*buf*/,
127 ostream & /*os*/, int /*linelen*/) const
129 // FIX: Implement me!
134 int InsetCaption::docbook(Buffer const * buf, ostream & os, bool mixcont) const
138 ret = InsetText::docbook(buf, os, mixcont);