]> git.lyx.org Git - lyx.git/blob - src/insets/insetcaption.C
reformatting and remove using delc
[lyx.git] / src / insets / insetcaption.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 2000-2001 The LyX Team.
7  *
8  * ======================================================
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "insetcaption.h"
18 #include "Painter.h"
19 #include "font.h"
20 #include "BufferView.h"
21 #include "FloatList.h"
22 #include "insets/insetfloat.h"
23 #include "debug.h"
24
25 using std::ostream;
26 using std::endl;
27
28 InsetCaption::InsetCaption()
29         : InsetText()
30 {
31         SetAutoBreakRows(true);
32         SetDrawFrame(0, InsetText::LOCKED);
33         SetFrameColor(0, LColor::footnoteframe);
34 }
35
36
37 void InsetCaption::Write(Buffer const * buf, ostream & os) const
38 {
39         os << "Caption\n";
40         WriteParagraphData(buf, os);
41 }
42
43
44
45 void InsetCaption::Read(Buffer const * buf, LyXLex & lex)
46 {
47 #if 0
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."
53                        << endl;
54         }
55 #endif
56         InsetText::Read(buf, lex);
57 }
58
59
60 string const InsetCaption::EditMessage() const 
61 {
62         return _("Opened Caption Inset");
63 }
64
65
66 void InsetCaption::draw(BufferView * bv, LyXFont const & f,
67                         int baseline, float & x, bool cleared) const
68 {
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)
74
75         // See if we can find the name of the float this caption
76         // belongs to.
77         Inset * i1 = owner();
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");
81
82         // Discover the number...
83         // ...
84         string const num = "#";
85
86         // Generate the label
87         string const label = _(fl) + " " + num + ":";
88         
89         Painter & pain = bv->painter();
90         int const w = lyxfont::width(label, f);
91         pain.text(int(x), baseline, label, f);
92         x += w;
93
94         InsetText::draw(bv, f, baseline, x, cleared);
95 }
96
97
98 int InsetCaption::Latex(Buffer const * buf, ostream & os,
99                         bool fragile, bool free_spc) const
100 {
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)
106         ostringstream ost;
107         int const l = InsetText::Latex(buf, ost, fragile, free_spc);
108         os << "\\caption{" << ost.str() << "}\n";
109         return l + 1;
110 }
111
112
113 int InsetCaption::Ascii(Buffer const * /*buf*/,
114                         ostream & /*os*/, int /*linelen*/) const
115 {
116 #warning Implement me!
117         return 0;
118 }
119
120
121 int InsetCaption::DocBook(Buffer const * /*buf*/, ostream & /*os*/) const
122 {
123 #warning Implement me!
124         return 0;
125 }