]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
Rename LatexRunParams::fragile as moving_arg.
[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 #include "insetbutton.h"
16 #include "debug.h"
17 #include "dimension.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 void InsetButton::dimension(BufferView * bv, LyXFont const &,
31         Dimension & dim) const
32 {
33         lyx::Assert(bv);
34
35         LyXFont font(LyXFont::ALL_SANE);
36         font.decSize();
37
38         string const s = getScreenLabel(bv->buffer());
39
40         if (editable())
41                 font_metrics::buttonText(s, font, dim.w, dim.a, dim.d);
42         else
43                 font_metrics::rectText(s, font, dim.w, dim.a, dim.d);
44
45         dim.w += 4;
46 }
47
48
49 void InsetButton::draw(BufferView * bv, LyXFont const &,
50                         int baseline, float & x) const
51 {
52         lyx::Assert(bv);
53         cache(bv);
54
55         Painter & pain = bv->painter();
56         // Draw it as a box with the LaTeX text
57         LyXFont font(LyXFont::ALL_SANE);
58         font.setColor(LColor::command).decSize();
59
60         string const s = getScreenLabel(bv->buffer());
61
62         if (editable()) {
63                 pain.buttonText(int(x) + 2, baseline, s, font);
64         } else {
65                 pain.rectText(int(x) + 2, baseline, s, font,
66                               LColor::commandbg, LColor::commandframe);
67         }
68
69         x += width(bv, font);
70 }
71
72
73 void InsetButton::cache(BufferView * bv) const
74 {
75         view_ = bv->owner()->view();
76 }
77
78
79 #warning Shouldnt this really return a shared_ptr<BufferView>? (Lgb)
80 BufferView * InsetButton::view() const
81 {
82         return view_.lock().get();
83 }
84
85
86 dispatch_result InsetButton::localDispatch(FuncRequest const & cmd)
87 {
88         return Inset::localDispatch(cmd);
89 }