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