]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
parlist-a-1.diff
[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 "funcrequest.h"
20 #include "frontends/LyXView.h"
21 #include "frontends/Painter.h"
22 #include "support/LAssert.h"
23 #include "lyxfont.h"
24 #include "frontends/font_metrics.h"
25
26 using std::ostream;
27 using std::endl;
28
29
30 int InsetButton::ascent(BufferView * bv, LyXFont const &) const
31 {
32         lyx::Assert(bv);
33
34         LyXFont font(LyXFont::ALL_SANE);
35         font.decSize();
36
37         int width;
38         int ascent;
39         int descent;
40         string const s = getScreenLabel(bv->buffer());
41
42         if (editable()) {
43                 font_metrics::buttonText(s, font, width, ascent, descent);
44         } else {
45                 font_metrics::rectText(s, font, width, ascent, descent);
46         }
47
48         return ascent;
49 }
50
51
52 int InsetButton::descent(BufferView * bv, LyXFont const &) const
53 {
54         lyx::Assert(bv);
55
56         LyXFont font(LyXFont::ALL_SANE);
57         font.decSize();
58
59         int width;
60         int ascent;
61         int descent;
62         string const s = getScreenLabel(bv->buffer());
63
64         if (editable()) {
65                 font_metrics::buttonText(s, font, width, ascent, descent);
66         } else {
67                 font_metrics::rectText(s, font, width, ascent, descent);
68         }
69
70         return descent;
71 }
72
73
74 int InsetButton::width(BufferView * bv, LyXFont const &) const
75 {
76         lyx::Assert(bv);
77
78         LyXFont font(LyXFont::ALL_SANE);
79         font.decSize();
80
81         int width;
82         int ascent;
83         int descent;
84         string const s = getScreenLabel(bv->buffer());
85
86         if (editable()) {
87                 font_metrics::buttonText(s, font, width, ascent, descent);
88         } else {
89                 font_metrics::rectText(s, font, width, ascent, descent);
90         }
91
92         return width + 4;
93 }
94
95
96 void InsetButton::draw(BufferView * bv, LyXFont const &,
97                         int baseline, float & x) const
98 {
99         lyx::Assert(bv);
100         cache(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 }
118
119
120 void InsetButton::cache(BufferView * bv) const
121 {
122         view_ = bv->owner()->view();
123 }
124
125
126 #warning Shouldnt this really return a shared_ptr<BufferView>? (Lgb)
127 BufferView * InsetButton::view() const
128 {
129         return view_.lock().get();
130 }
131
132
133 dispatch_result InsetButton::localDispatch(FuncRequest const & cmd)
134 {
135         FuncRequest cmd1(cmd);
136         edit(cmd1.view(), cmd1.x, cmd1.y, cmd1.button());
137         return DISPATCHED;
138 }