]> git.lyx.org Git - lyx.git/blob - src/insets/insetcaption.C
fix compilation pb ; update eu.po
[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 #include "gettext.h"
25
26 using std::ostream;
27 using std::endl;
28
29 InsetCaption::InsetCaption()
30         : InsetText()
31 {
32         SetAutoBreakRows(true);
33         SetDrawFrame(0, InsetText::LOCKED);
34         SetFrameColor(0, LColor::footnoteframe);
35 }
36
37
38 void InsetCaption::Write(Buffer const * buf, ostream & os) const
39 {
40         os << "Caption\n";
41         WriteParagraphData(buf, os);
42 }
43
44
45
46 void InsetCaption::Read(Buffer const * buf, LyXLex & lex)
47 {
48 #if 0
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."
54                        << endl;
55         }
56 #endif
57         InsetText::Read(buf, lex);
58 }
59
60
61 string const InsetCaption::EditMessage() const 
62 {
63         return _("Opened Caption Inset");
64 }
65
66
67 void InsetCaption::draw(BufferView * bv, LyXFont const & f,
68                         int baseline, float & x, bool cleared) const
69 {
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)
75
76         // See if we can find the name of the float this caption
77         // belongs to.
78         Inset * i1 = owner();
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");
82
83         // Discover the number...
84         // ...
85         string const num = "#";
86
87         // Generate the label
88         string const label = _(fl) + " " + num + ":";
89         
90         Painter & pain = bv->painter();
91         int const w = lyxfont::width(label, f);
92         pain.text(int(x), baseline, label, f);
93         x += w;
94
95         InsetText::draw(bv, f, baseline, x, cleared);
96 }
97
98
99 int InsetCaption::Latex(Buffer const * buf, ostream & os,
100                         bool fragile, bool free_spc) const
101 {
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)
107         ostringstream ost;
108         int const l = InsetText::Latex(buf, ost, fragile, free_spc);
109         os << "\\caption{" << ost.str() << "}\n";
110         return l + 1;
111 }
112
113
114 int InsetCaption::Ascii(Buffer const * /*buf*/,
115                         ostream & /*os*/, int /*linelen*/) const
116 {
117 #ifdef WITH_WARNINGS
118 #warning Implement me!
119 #endif
120         return 0;
121 }
122
123
124 int InsetCaption::DocBook(Buffer const * /*buf*/, ostream & /*os*/) const
125 {
126 #ifdef WITH_WARNINGS
127 #warning Implement me!
128 #endif
129         return 0;
130 }