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"
29 InsetCaption::InsetCaption()
32 SetAutoBreakRows(true);
33 SetDrawFrame(0, InsetText::LOCKED);
34 SetFrameColor(0, LColor::footnoteframe);
38 void InsetCaption::Write(Buffer const * buf, ostream & os) const
41 WriteParagraphData(buf, os);
46 void InsetCaption::Read(Buffer const * buf, LyXLex & lex)
49 // We will enably this check again when the compability
50 // code is removed from Buffer::Read (Lgb)
51 string const token = lex.GetString();
52 if (token != "Caption") {
53 lyxerr << "InsetCaption::Read: consistency check failed."
57 InsetText::Read(buf, lex);
61 string const InsetCaption::EditMessage() const
63 return _("Opened Caption Inset");
67 void InsetCaption::draw(BufferView * bv, LyXFont const & f,
68 int baseline, float & x, bool cleared) const
70 // We must draw the label, we should get the label string
71 // from the enclosing float inset.
72 // The question is: Who should draw the label, the caption inset,
73 // the text inset or the paragraph?
74 // We should also draw the float number (Lgb)
76 // See if we can find the name of the float this caption
79 Inset * i2 = i1 ? i1->owner() : 0;
80 string const type = static_cast<InsetFloat *>(i2)->type();
81 string const fl = i2 ? floatList.getType(type).name() : N_("Float");
83 // Discover the number...
85 string const num = "#";
88 string const label = _(fl) + " " + num + ":";
90 Painter & pain = bv->painter();
91 int const w = lyxfont::width(label, f);
92 pain.text(int(x), baseline, label, f);
95 InsetText::draw(bv, f, baseline, x, cleared);
99 int InsetCaption::Latex(Buffer const * buf, ostream & os,
100 bool fragile, bool free_spc) const
102 // This is a bit too simplistic to take advantage of
103 // caption options we must add more later. (Lgb)
104 // This code is currently only able to handle the simple
105 // \caption{...}, later we will make it take advantage
106 // of the one of the caption packages. (Lgb)
108 int const l = InsetText::Latex(buf, ost, fragile, free_spc);
109 os << "\\caption{" << ost.str() << "}\n";
114 int InsetCaption::Ascii(Buffer const * /*buf*/,
115 ostream & /*os*/, int /*linelen*/) const
117 #warning Implement me!
122 int InsetCaption::DocBook(Buffer const * /*buf*/, ostream & /*os*/) const
124 #warning Implement me!