]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
Make it compile when USE_BOOST_FORMAT is unset
[lyx.git] / src / insets / insetbutton.C
1 /**
2  * \file insetbutton.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup Nielsen
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #include <config.h>
14
15 #ifdef __GNUG__
16 #pragma implementation
17 #endif
18
19 #include "insetbutton.h"
20 #include "debug.h"
21 #include "BufferView.h"
22 #include "frontends/Painter.h"
23 #include "support/LAssert.h"
24 #include "lyxfont.h"
25 #include "frontends/font_metrics.h"
26
27 using std::ostream;
28 using std::endl;
29
30
31 int InsetButton::ascent(BufferView * bv, LyXFont const &) const
32 {
33         lyx::Assert(bv);
34
35         LyXFont font(LyXFont::ALL_SANE);
36         font.decSize();
37
38         int width;
39         int ascent;
40         int descent;
41         string const s = getScreenLabel(bv->buffer());
42
43         if (editable()) {
44                 font_metrics::buttonText(s, font, width, ascent, descent);
45         } else {
46                 font_metrics::rectText(s, font, width, ascent, descent);
47         }
48
49         return ascent;
50 }
51
52
53 int InsetButton::descent(BufferView * bv, LyXFont const &) const
54 {
55         lyx::Assert(bv);
56
57         LyXFont font(LyXFont::ALL_SANE);
58         font.decSize();
59
60         int width;
61         int ascent;
62         int descent;
63         string const s = getScreenLabel(bv->buffer());
64
65         if (editable()) {
66                 font_metrics::buttonText(s, font, width, ascent, descent);
67         } else {
68                 font_metrics::rectText(s, font, width, ascent, descent);
69         }
70
71         return descent;
72 }
73
74
75 int InsetButton::width(BufferView * bv, LyXFont const &) const
76 {
77         lyx::Assert(bv);
78
79         LyXFont font(LyXFont::ALL_SANE);
80         font.decSize();
81
82         int width;
83         int ascent;
84         int descent;
85         string const s = getScreenLabel(bv->buffer());
86
87         if (editable()) {
88                 font_metrics::buttonText(s, font, width, ascent, descent);
89         } else {
90                 font_metrics::rectText(s, font, width, ascent, descent);
91         }
92
93         return width + 4;
94 }
95
96
97 void InsetButton::draw(BufferView * bv, LyXFont const &,
98                         int baseline, float & x, bool) const
99 {
100         lyx::Assert(bv);
101
102         Painter & pain = bv->painter();
103         // Draw it as a box with the LaTeX text
104         LyXFont font(LyXFont::ALL_SANE);
105         font.setColor(LColor::command).decSize();
106
107         string const s = getScreenLabel(bv->buffer());
108
109         if (editable()) {
110                 pain.buttonText(int(x) + 2, baseline, s, font);
111         } else {
112                 pain.rectText(int(x) + 2, baseline, s, font,
113                               LColor::commandbg, LColor::commandframe);
114         }
115
116         x += width(bv, font);
117 }