]> git.lyx.org Git - lyx.git/blob - src/insets/RenderButton.cpp
Whitespace cleanup
[lyx.git] / src / insets / RenderButton.cpp
1 /**
2  * \file RenderButton.cpp
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 "RenderButton.h"
14
15 #include "Color.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(Inset 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 bool RenderButton::metrics(MetricsInfo &, Dimension & dim) const
47 {
48         Font font(Font::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         if (dim_ == dim)
60                 return false;
61         dim_ = dim;
62         return true;
63 }
64
65
66 void RenderButton::draw(PainterInfo & pi, int x, int y) const
67 {
68         // Draw it as a box with the LaTeX text
69         Font font(Font::ALL_SANE);
70         font.setColor(Color::command);
71         font.decSize();
72
73         if (editable_) {
74                 pi.pain.buttonText(x + 2, y, text_, font, renderState());
75         } else {
76                 pi.pain.rectText(x + 2, y, text_, font,
77                                  Color::commandbg, Color::commandframe);
78         }
79 }
80
81
82 } // namespace lyx