3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup Nielsen
8 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS
16 #include "insetbutton.h"
18 #include "BufferView.h"
19 #include "funcrequest.h"
20 #include "frontends/LyXView.h"
21 #include "frontends/Painter.h"
22 #include "support/LAssert.h"
24 #include "frontends/font_metrics.h"
30 int InsetButton::ascent(BufferView * bv, LyXFont const &) const
34 LyXFont font(LyXFont::ALL_SANE);
40 string const s = getScreenLabel(bv->buffer());
43 font_metrics::buttonText(s, font, width, ascent, descent);
45 font_metrics::rectText(s, font, width, ascent, descent);
52 int InsetButton::descent(BufferView * bv, LyXFont const &) const
56 LyXFont font(LyXFont::ALL_SANE);
62 string const s = getScreenLabel(bv->buffer());
65 font_metrics::buttonText(s, font, width, ascent, descent);
67 font_metrics::rectText(s, font, width, ascent, descent);
74 int InsetButton::width(BufferView * bv, LyXFont const &) const
78 LyXFont font(LyXFont::ALL_SANE);
84 string const s = getScreenLabel(bv->buffer());
87 font_metrics::buttonText(s, font, width, ascent, descent);
89 font_metrics::rectText(s, font, width, ascent, descent);
96 void InsetButton::draw(BufferView * bv, LyXFont const &,
97 int baseline, float & x) const
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();
107 string const s = getScreenLabel(bv->buffer());
110 pain.buttonText(int(x) + 2, baseline, s, font);
112 pain.rectText(int(x) + 2, baseline, s, font,
113 LColor::commandbg, LColor::commandframe);
116 x += width(bv, font);
120 void InsetButton::cache(BufferView * bv) const
122 view_ = bv->owner()->view();
126 #warning Shouldnt this really return a shared_ptr<BufferView>? (Lgb)
127 BufferView * InsetButton::view() const
129 return view_.lock().get();
133 dispatch_result InsetButton::localDispatch(FuncRequest const & cmd)
135 FuncRequest cmd1(cmd);
136 edit(cmd1.view(), cmd1.x, cmd1.y, cmd1.button());