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"
20 #include "BufferView.h"
21 #include "FloatList.h"
22 #include "insets/insetfloat.h"
28 InsetCaption::InsetCaption()
31 SetAutoBreakRows(true);
32 SetDrawFrame(0, InsetText::LOCKED);
33 SetFrameColor(0, LColor::footnoteframe);
37 void InsetCaption::Write(Buffer const * buf, ostream & os) const
40 WriteParagraphData(buf, os);
45 void InsetCaption::Read(Buffer const * buf, LyXLex & lex)
48 // We will enably this check again when the compability
49 // code is removed from Buffer::Read (Lgb)
50 string const token = lex.GetString();
51 if (token != "Caption") {
52 lyxerr << "InsetCaption::Read: consistency check failed."
56 InsetText::Read(buf, lex);
60 string const InsetCaption::EditMessage() const
62 return _("Opened Caption Inset");
66 void InsetCaption::draw(BufferView * bv, LyXFont const & f,
67 int baseline, float & x, bool cleared) const
69 // We must draw the label, we should get the label string
70 // from the enclosing float inset.
71 // The question is: Who should draw the label, the caption inset,
72 // the text inset or the paragraph?
73 // We should also draw the float number (Lgb)
75 // See if we can find the name of the float this caption
78 Inset * i2 = i1 ? i1->owner() : 0;
79 string const type = static_cast<InsetFloat *>(i2)->type();
80 string const fl = i2 ? floatList.getType(type).name() : N_("Float");
82 // Discover the number...
84 string const num = "#";
87 string const label = _(fl) + " " + num + ":";
89 Painter & pain = bv->painter();
90 int const w = lyxfont::width(label, f);
91 pain.text(int(x), baseline, label, f);
94 InsetText::draw(bv, f, baseline, x, cleared);
98 int InsetCaption::Latex(Buffer const * buf, ostream & os,
99 bool fragile, bool free_spc) const
101 // This is a bit too simplistic to take advantage of
102 // caption options we must add more later. (Lgb)
103 // This code is currently only able to handle the simple
104 // \caption{...}, later we will make it take advantage
105 // of the one of the caption packages. (Lgb)
107 int const l = InsetText::Latex(buf, ost, fragile, free_spc);
108 os << "\\caption{" << ost.str() << "}\n";
113 int InsetCaption::Ascii(Buffer const * /*buf*/,
114 ostream & /*os*/, int /*linelen*/) const
116 #warning Implement me!
121 int InsetCaption::DocBook(Buffer const * /*buf*/, ostream & /*os*/) const
123 #warning Implement me!