]> git.lyx.org Git - lyx.git/blob - src/insets/insetcaption.C
Squash a noisy but useless warning.
[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
35 using lyx::support::bformat;
36
37 using std::endl;
38 using std::string;
39 using std::ostream;
40 using std::ostringstream;
41
42
43 InsetCaption::InsetCaption(BufferParams const & bp)
44         : InsetText(bp)
45 {
46         setAutoBreakRows(true);
47         setDrawFrame(InsetText::LOCKED);
48         setFrameColor(LColor::captionframe);
49 }
50
51
52 void InsetCaption::write(Buffer const & buf, ostream & os) const
53 {
54         os << "Caption\n";
55         text_.write(buf, os);
56 }
57
58
59 void InsetCaption::read(Buffer const & buf, LyXLex & lex)
60 {
61 #if 0
62         // We will enably this check again when the compability
63         // code is removed from Buffer::Read (Lgb)
64         string const token = lex.GetString();
65         if (token != "Caption") {
66                 lyxerr << "InsetCaption::Read: consistency check failed."
67                        << endl;
68         }
69 #endif
70         InsetText::read(buf, lex);
71 }
72
73
74 string const InsetCaption::editMessage() const
75 {
76         return _("Opened Caption Inset");
77 }
78
79
80 void InsetCaption::draw(PainterInfo & pi, int x, int y) const
81 {
82         // We must draw the label, we should get the label string
83         // from the enclosing float inset.
84         // The question is: Who should draw the label, the caption inset,
85         // the text inset or the paragraph?
86         // We should also draw the float number (Lgb)
87
88         // See if we can find the name of the float this caption
89         // belongs to.
90 #if 0
91         InsetOld * i1 = owner();
92         InsetOld * i2 = i1 ? i1->owner() : 0;
93         string type;
94         if (i2->lyxCode() == FLOAT_CODE)
95 #warning Now, what happens for i2 == 0?
96                 type = static_cast<InsetFloat *>(i2)->params().type;
97         else if (i2->lyxCode() == WRAP_CODE)
98                 type = static_cast<InsetWrap *>(i2)->params().type;
99         else
100                 BOOST_ASSERT(false);
101
102         FloatList const & floats =
103                 pi.base.bv->buffer()->params().getLyXTextClass().floats();
104         string const fl = i2 ? floats.getType(type).name() : N_("Float");
105 #else
106         string type = "float";
107         string const fl = N_("Float");
108 #endif
109
110         // Discover the number...
111         string const num = "#";
112
113         // Generate the label
114         string const label = bformat("%1$s %2$s:", _(fl), num);
115         int const w = font_metrics::width(label, pi.base.font);
116         pi.pain.text(x, y, label, pi.base.font);
117         InsetText::draw(pi, x + w, y);
118 }
119
120
121 int InsetCaption::latex(Buffer const & buf, ostream & os,
122                         OutputParams const & runparams) const
123 {
124         // This is a bit too simplistic to take advantage of
125         // caption options we must add more later. (Lgb)
126         // This code is currently only able to handle the simple
127         // \caption{...}, later we will make it take advantage
128         // of the one of the caption packages. (Lgb)
129         ostringstream ost;
130         int const l = InsetText::latex(buf, ost, runparams);
131         os << "\\caption{" << ost.str() << "}\n";
132         return l + 1;
133 }
134
135
136 int InsetCaption::plaintext(Buffer const & /*buf*/,ostream & /*os*/,
137                         OutputParams const & /*runparams*/) const
138 {
139         // FIX: Implement me!
140         return 0;
141 }
142
143
144 int InsetCaption::docbook(Buffer const & buf, ostream & os,
145                           OutputParams const & runparams) const
146 {
147         int ret;
148         os << "<title>";
149         ret = InsetText::docbook(buf, os, runparams);
150         os << "</title>\n";
151         return ret;
152 }