]> git.lyx.org Git - lyx.git/blob - src/insets/render_button.C
move everything into namespace lyx
[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
22 namespace lyx {
23
24 using std::string;
25 using std::auto_ptr;
26
27
28 RenderButton::RenderButton()
29         : editable_(false)
30 {}
31
32
33 auto_ptr<RenderBase> RenderButton::clone(InsetBase const *) const
34 {
35         return auto_ptr<RenderBase>(new RenderButton(*this));
36 }
37
38
39 void RenderButton::update(docstring const & text, bool editable)
40 {
41         text_ = text;
42         editable_ = editable;
43 }
44
45
46 void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
47 {
48         LyXFont font(LyXFont::ALL_SANE);
49         font.decSize();
50         frontend::FontMetrics const & fm =
51                 theFontMetrics(font);
52         
53         if (editable_)
54                 fm.buttonText(text_, dim.wid, dim.asc, dim.des);
55         else
56                 fm.rectText(text_, dim.wid, dim.asc, dim.des);
57
58         dim.wid += 4;
59 }
60
61
62 void RenderButton::draw(PainterInfo & pi, int x, int y) const
63 {
64         // Draw it as a box with the LaTeX text
65         LyXFont font(LyXFont::ALL_SANE);
66         font.setColor(LColor::command);
67         font.decSize();
68
69         if (editable_) {
70                 pi.pain.buttonText(x + 2, y, text_, font);
71         } else {
72                 pi.pain.rectText(x + 2, y, text_, font,
73                                  LColor::commandbg, LColor::commandframe);
74         }
75 }
76
77
78 } // namespace lyx