]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
dont use pragma impementation and interface anymore
[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
16 #include "insetbutton.h"
17 #include "debug.h"
18 #include "BufferView.h"
19 #include "frontends/Painter.h"
20 #include "support/LAssert.h"
21 #include "lyxfont.h"
22 #include "frontends/font_metrics.h"
23
24 using std::ostream;
25 using std::endl;
26
27
28 int InsetButton::ascent(BufferView * bv, LyXFont const &) const
29 {
30         lyx::Assert(bv);
31
32         LyXFont font(LyXFont::ALL_SANE);
33         font.decSize();
34
35         int width;
36         int ascent;
37         int descent;
38         string const s = getScreenLabel(bv->buffer());
39
40         if (editable()) {
41                 font_metrics::buttonText(s, font, width, ascent, descent);
42         } else {
43                 font_metrics::rectText(s, font, width, ascent, descent);
44         }
45
46         return ascent;
47 }
48
49
50 int InsetButton::descent(BufferView * bv, LyXFont const &) const
51 {
52         lyx::Assert(bv);
53
54         LyXFont font(LyXFont::ALL_SANE);
55         font.decSize();
56
57         int width;
58         int ascent;
59         int descent;
60         string const s = getScreenLabel(bv->buffer());
61
62         if (editable()) {
63                 font_metrics::buttonText(s, font, width, ascent, descent);
64         } else {
65                 font_metrics::rectText(s, font, width, ascent, descent);
66         }
67
68         return descent;
69 }
70
71
72 int InsetButton::width(BufferView * bv, LyXFont const &) const
73 {
74         lyx::Assert(bv);
75
76         LyXFont font(LyXFont::ALL_SANE);
77         font.decSize();
78
79         int width;
80         int ascent;
81         int descent;
82         string const s = getScreenLabel(bv->buffer());
83
84         if (editable()) {
85                 font_metrics::buttonText(s, font, width, ascent, descent);
86         } else {
87                 font_metrics::rectText(s, font, width, ascent, descent);
88         }
89
90         return width + 4;
91 }
92
93
94 void InsetButton::draw(BufferView * bv, LyXFont const &,
95                         int baseline, float & x, bool) const
96 {
97         lyx::Assert(bv);
98
99         Painter & pain = bv->painter();
100         // Draw it as a box with the LaTeX text
101         LyXFont font(LyXFont::ALL_SANE);
102         font.setColor(LColor::command).decSize();
103
104         string const s = getScreenLabel(bv->buffer());
105
106         if (editable()) {
107                 pain.buttonText(int(x) + 2, baseline, s, font);
108         } else {
109                 pain.rectText(int(x) + 2, baseline, s, font,
110                               LColor::commandbg, LColor::commandframe);
111         }
112
113         x += width(bv, font);
114 }