]> git.lyx.org Git - lyx.git/blob - src/insets/render_button.C
This commit cleans up everything related to singleton. The other important change...
[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/FontMetrics.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         lyx::frontend::FontMetrics const & fm =
50                 theFontMetrics(font);
51         
52         docstring dtext(text_.begin(), text_.end());
53         
54         if (editable_)
55                 fm.buttonText(dtext, dim.wid, dim.asc, dim.des);
56         else
57                 fm.rectText(dtext, dim.wid, dim.asc, dim.des);
58
59         dim.wid += 4;
60 }
61
62
63 void RenderButton::draw(PainterInfo & pi, int x, int y) const
64 {
65         // Draw it as a box with the LaTeX text
66         LyXFont font(LyXFont::ALL_SANE);
67         font.setColor(LColor::command);
68         font.decSize();
69
70         docstring dtext(text_.begin(), text_.end());
71         
72         if (editable_) {
73                 pi.pain.buttonText(x + 2, y, dtext, font);
74         } else {
75                 pi.pain.rectText(x + 2, y, dtext, font,
76                                  LColor::commandbg, LColor::commandframe);
77         }
78 }