]> git.lyx.org Git - lyx.git/blob - src/insets/render_button.C
Merge the unicode branch into trunk.
[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 "LColor.h"
16 #include "metricsinfo.h"
17
18 #include "frontends/font_metrics.h"
19 #include "frontends/Painter.h"
20
21 using lyx::docstring;
22
23 using std::string;
24 using std::auto_ptr;
25
26
27 RenderButton::RenderButton()
28         : editable_(false)
29 {}
30
31
32 auto_ptr<RenderBase> RenderButton::clone(InsetBase const *) const
33 {
34         return auto_ptr<RenderBase>(new RenderButton(*this));
35 }
36
37
38 void RenderButton::update(string const & text, bool editable)
39 {
40         text_ = text;
41         editable_ = editable;
42 }
43
44
45 void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
46 {
47         LyXFont font(LyXFont::ALL_SANE);
48         font.decSize();
49
50         docstring dtext(text_.begin(), text_.end());
51         
52         if (editable_)
53                 font_metrics::buttonText(dtext, font, dim.wid, dim.asc, dim.des);
54         else
55                 font_metrics::rectText(dtext, font, dim.wid, dim.asc, dim.des);
56
57         dim.wid += 4;
58 }
59
60
61 void RenderButton::draw(PainterInfo & pi, int x, int y) const
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         docstring dtext(text_.begin(), text_.end());
69         
70         if (editable_) {
71                 pi.pain.buttonText(x + 2, y, dtext, font);
72         } else {
73                 pi.pain.rectText(x + 2, y, dtext, font,
74                                  LColor::commandbg, LColor::commandframe);
75         }
76 }