]> git.lyx.org Git - lyx.git/blob - src/insets/render_button.C
RenderButton, RenderGraphic and RenderPreview now have a common lineage.
[lyx.git] / src / insets / render_button.C
1 /**
2  * \file render_button.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "render_button.h"
14
15 #include "BufferView.h"
16 #include "LColor.h"
17 #include "metricsinfo.h"
18
19 #include "frontends/font_metrics.h"
20 #include "frontends/LyXView.h"
21 #include "frontends/Painter.h"
22
23 using std::string;
24
25
26 RenderButton::RenderButton()
27         : editable_(false)
28 {}
29
30
31 RenderBase * RenderButton::clone() const
32 {
33         return new RenderButton(*this);
34 }
35
36
37 void RenderButton::update(string const & text, bool editable)
38 {
39         text_ = text;
40         editable_ = editable;
41 }
42
43
44 void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
45 {
46         LyXFont font(LyXFont::ALL_SANE);
47         font.decSize();
48
49         if (editable_)
50                 font_metrics::buttonText(text_, font, dim.wid, dim.asc, dim.des);
51         else
52                 font_metrics::rectText(text_, font, dim.wid, dim.asc, dim.des);
53
54         dim.wid += 4;
55 }
56
57
58 void RenderButton::draw(PainterInfo & pi, int x, int y) const
59 {
60         BOOST_ASSERT(pi.base.bv);
61         view_ = pi.base.bv->owner()->view();
62
63         // Draw it as a box with the LaTeX text
64         LyXFont font(LyXFont::ALL_SANE);
65         font.setColor(LColor::command);
66         font.decSize();
67
68         if (editable_) {
69                 pi.pain.buttonText(x + 2, y, text_, font);
70         } else {
71                 pi.pain.rectText(x + 2, y, text_, font,
72                                  LColor::commandbg, LColor::commandframe);
73         }
74 }