]> git.lyx.org Git - lyx.git/blob - src/insets/insetcaption.C
Remove unused LColor::color framecolor variable from insetcollabsable.h
[lyx.git] / src / insets / insetcaption.C
1 /**
2  * \file insetcaption.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "insetcaption.h"
14 #include "insetfloat.h"
15 #include "insetwrap.h"
16
17 #include "buffer.h"
18 #include "bufferparams.h"
19 #include "BufferView.h"
20 #include "Floating.h"
21 #include "FloatList.h"
22 #include "gettext.h"
23 #include "LColor.h"
24 #include "metricsinfo.h"
25 #include "paragraph.h"
26
27 #include "frontends/font_metrics.h"
28 #include "frontends/Painter.h"
29
30 #include "support/lstrings.h"
31
32 #include "support/std_sstream.h"
33
34 using lyx::support::bformat;
35
36 using std::endl;
37
38 using std::ostream;
39 using std::ostringstream;
40
41
42 InsetCaption::InsetCaption(BufferParams const & bp)
43         : InsetText(bp)
44 {
45         setAutoBreakRows(true);
46         setDrawFrame(InsetText::LOCKED);
47         setFrameColor(LColor::captionframe);
48 }
49
50
51 void InsetCaption::write(Buffer const & buf, ostream & os) const
52 {
53         os << "Caption\n";
54         writeParagraphData(buf, os);
55 }
56
57
58 void InsetCaption::read(Buffer const & buf, LyXLex & lex)
59 {
60 #if 0
61         // We will enably this check again when the compability
62         // code is removed from Buffer::Read (Lgb)
63         string const token = lex.GetString();
64         if (token != "Caption") {
65                 lyxerr << "InsetCaption::Read: consistency check failed."
66                        << endl;
67         }
68 #endif
69         InsetText::read(buf, lex);
70 }
71
72
73 string const InsetCaption::editMessage() const
74 {
75         return _("Opened Caption Inset");
76 }
77
78
79 void InsetCaption::draw(PainterInfo & pi, int x, int y) const
80 {
81         // We must draw the label, we should get the label string
82         // from the enclosing float inset.
83         // The question is: Who should draw the label, the caption inset,
84         // the text inset or the paragraph?
85         // We should also draw the float number (Lgb)
86
87         // See if we can find the name of the float this caption
88         // belongs to.
89         InsetOld * i1 = owner();
90         InsetOld * i2 = i1 ? i1->owner() : 0;
91         string type;
92         if (i2->lyxCode() == FLOAT_CODE)
93                 type = static_cast<InsetFloat *>(i2)->params().type;
94         else if (i2->lyxCode() == WRAP_CODE)
95                 type = static_cast<InsetWrap *>(i2)->params().type;
96         else
97                 BOOST_ASSERT(false);
98
99         FloatList const & floats =
100                 pi.base.bv->buffer()->params().getLyXTextClass().floats();
101         string const fl = i2 ? floats.getType(type).name() : N_("Float");
102
103         // Discover the number...
104         string const num = "#";
105
106         // Generate the label
107         string const label = bformat("%1$s %2$s:", _(fl), num);
108         int const w = font_metrics::width(label, pi.base.font);
109         pi.pain.text(x, y, label, pi.base.font);
110         InsetText::draw(pi, x + w, y);
111 }
112
113
114 int InsetCaption::latex(Buffer const & buf, ostream & os,
115                         LatexRunParams const & runparams) const
116 {
117         // This is a bit too simplistic to take advantage of
118         // caption options we must add more later. (Lgb)
119         // This code is currently only able to handle the simple
120         // \caption{...}, later we will make it take advantage
121         // of the one of the caption packages. (Lgb)
122         ostringstream ost;
123         int const l = InsetText::latex(buf, ost, runparams);
124         os << "\\caption{" << ost.str() << "}\n";
125         return l + 1;
126 }
127
128
129 int InsetCaption::ascii(Buffer const & /*buf*/,
130                         ostream & /*os*/, int /*linelen*/) const
131 {
132         // FIX: Implement me!
133         return 0;
134 }
135
136
137 int InsetCaption::docbook(Buffer const & buf, ostream & os, bool mixcont) const
138 {
139         int ret;
140         os << "<title>";
141         ret = InsetText::docbook(buf, os, mixcont);
142         os << "</title>\n";
143         return ret;
144 }