]> git.lyx.org Git - lyx.git/blob - src/insets/insetcaption.C
Make it compile when USE_BOOST_FORMAT is unset
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "insetcaption.h"
18 #include "frontends/Painter.h"
19 #include "frontends/font_metrics.h"
20 #include "BufferView.h"
21 #include "buffer.h"
22 #include "FloatList.h"
23 #include "insets/insetfloat.h"
24 #include "debug.h"
25 #include "gettext.h"
26 #include "support/lstrings.h"
27
28 #include "BoostFormat.h"
29
30 using std::ostream;
31 using std::endl;
32
33 InsetCaption::InsetCaption(BufferParams const & bp)
34         : InsetText(bp)
35 {
36         setAutoBreakRows(true);
37         setDrawFrame(0, InsetText::LOCKED);
38         setFrameColor(0, LColor::captionframe);
39 }
40
41
42 void InsetCaption::write(Buffer const * buf, ostream & os) const
43 {
44         os << "Caption\n";
45         writeParagraphData(buf, os);
46 }
47
48
49
50 void InsetCaption::read(Buffer const * buf, LyXLex & lex)
51 {
52 #if 0
53         // We will enably this check again when the compability
54         // code is removed from Buffer::Read (Lgb)
55         string const token = lex.GetString();
56         if (token != "Caption") {
57                 lyxerr << "InsetCaption::Read: consistency check failed."
58                        << endl;
59         }
60 #endif
61         InsetText::read(buf, lex);
62 }
63
64
65 string const InsetCaption::editMessage() const
66 {
67         return _("Opened Caption Inset");
68 }
69
70
71 void InsetCaption::draw(BufferView * bv, LyXFont const & f,
72                         int baseline, float & x, bool cleared) const
73 {
74         // We must draw the label, we should get the label string
75         // from the enclosing float inset.
76         // The question is: Who should draw the label, the caption inset,
77         // the text inset or the paragraph?
78         // We should also draw the float number (Lgb)
79
80         // See if we can find the name of the float this caption
81         // belongs to.
82         Inset * i1 = owner();
83         Inset * i2 = i1 ? i1->owner() : 0;
84         string const type = static_cast<InsetFloat *>(i2)->type();
85         FloatList const & floats =
86                 bv->buffer()->params.getLyXTextClass().floats();
87         string const fl = i2 ? floats.getType(type).name() : N_("Float");
88
89         // Discover the number...
90         // ...
91         string const num("#");
92
93 #if USE_BOOST_FORMAT
94         // Generate the label
95         boost::format frm("%1$s %2$s:");
96         frm % _(fl) % num;
97         string const label = frm.str();
98 #else
99         // Generate the label
100         string const label = _(fl) + " " + num + ":";
101 #endif
102         Painter & pain = bv->painter();
103         int const w = font_metrics::width(label, f);
104         pain.text(int(x), baseline, label, f);
105         x += w;
106
107         InsetText::draw(bv, f, baseline, x, cleared);
108 }
109
110
111 int InsetCaption::latex(Buffer const * buf, ostream & os,
112                         bool fragile, bool free_spc) 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, fragile, free_spc);
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 }