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