1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * ======================================================
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"
31 InsetCaption::InsetCaption(BufferParams const & bp)
34 setAutoBreakRows(true);
35 setDrawFrame(0, InsetText::LOCKED);
36 setFrameColor(0, LColor::captionframe);
40 void InsetCaption::write(Buffer const * buf, ostream & os) const
43 writeParagraphData(buf, os);
48 void InsetCaption::read(Buffer const * buf, LyXLex & lex)
51 // We will enably this check again when the compability
52 // code is removed from Buffer::Read (Lgb)
53 string const token = lex.GetString();
54 if (token != "Caption") {
55 lyxerr << "InsetCaption::Read: consistency check failed."
59 InsetText::read(buf, lex);
63 string const InsetCaption::editMessage() const
65 return _("Opened Caption Inset");
69 void InsetCaption::draw(BufferView * bv, LyXFont const & f,
70 int baseline, float & x, bool cleared) const
72 // We must draw the label, we should get the label string
73 // from the enclosing float inset.
74 // The question is: Who should draw the label, the caption inset,
75 // the text inset or the paragraph?
76 // We should also draw the float number (Lgb)
78 // See if we can find the name of the float this caption
81 Inset * i2 = i1 ? i1->owner() : 0;
82 string const type = static_cast<InsetFloat *>(i2)->type();
83 FloatList const & floats =
84 bv->buffer()->params.getLyXTextClass().floats();
85 string const fl = i2 ? floats.getType(type).name() : N_("Float");
87 // Discover the number...
89 string const num = "#";
92 string const label = _(fl) + " " + num + ":";
94 Painter & pain = bv->painter();
95 int const w = font_metrics::width(label, f);
96 pain.text(int(x), baseline, label, f);
99 InsetText::draw(bv, f, baseline, x, cleared);
103 int InsetCaption::latex(Buffer const * buf, ostream & os,
104 bool fragile, bool free_spc) const
106 // This is a bit too simplistic to take advantage of
107 // caption options we must add more later. (Lgb)
108 // This code is currently only able to handle the simple
109 // \caption{...}, later we will make it take advantage
110 // of the one of the caption packages. (Lgb)
112 int const l = InsetText::latex(buf, ost, fragile, free_spc);
113 os << "\\caption{" << ost.str() << "}\n";
118 int InsetCaption::ascii(Buffer const * /*buf*/,
119 ostream & /*os*/, int /*linelen*/) const
121 // FIX: Implement me!
126 int InsetCaption::docbook(Buffer const * buf, ostream & os, bool mixcont) const
130 ret = InsetText::docbook(buf, os, mixcont);