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