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"
25 #include "support/lstrings.h"
30 InsetCaption::InsetCaption()
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 string const fl = i2 ? floatList.getType(type).name() : N_("Float");
84 // Discover the number...
86 string const num = "#";
89 string const label = _(fl) + " " + num + ":";
91 Painter & pain = bv->painter();
92 int const w = lyxfont::width(label, f);
93 pain.text(int(x), baseline, label, f);
96 InsetText::draw(bv, f, baseline, x, cleared);
100 int InsetCaption::latex(Buffer const * buf, ostream & os,
101 bool fragile, bool free_spc) const
103 // This is a bit too simplistic to take advantage of
104 // caption options we must add more later. (Lgb)
105 // This code is currently only able to handle the simple
106 // \caption{...}, later we will make it take advantage
107 // of the one of the caption packages. (Lgb)
109 int const l = InsetText::latex(buf, ost, fragile, free_spc);
110 os << "\\caption{" << ost.str() << "}\n";
115 int InsetCaption::ascii(Buffer const * /*buf*/,
116 ostream & /*os*/, int /*linelen*/) const
119 #warning Implement me!
125 int InsetCaption::docBook(Buffer const * /*buf*/, ostream & /*os*/) const
128 #warning Implement me!