]> git.lyx.org Git - lyx.git/blob - src/insets/RenderButton.cpp
use bald pointers in clone()
[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
25 RenderButton::RenderButton()
26         : editable_(false)
27 {}
28
29
30 RenderBase * RenderButton::clone(Inset const *) const
31 {
32         return new RenderButton(*this);
33 }
34
35
36 void RenderButton::update(docstring const & text, bool editable)
37 {
38         text_ = text;
39         editable_ = editable;
40 }
41
42
43 bool RenderButton::metrics(MetricsInfo &, Dimension & dim) const
44 {
45         Font font(Font::ALL_SANE);
46         font.decSize();
47         frontend::FontMetrics const & fm =
48                 theFontMetrics(font);
49
50         if (editable_)
51                 fm.buttonText(text_, dim.wid, dim.asc, dim.des);
52         else
53                 fm.rectText(text_, dim.wid, dim.asc, dim.des);
54
55         dim.wid += 4;
56         if (dim_ == dim)
57                 return false;
58         dim_ = dim;
59         return true;
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         Font font(Font::ALL_SANE);
67         font.setColor(Color::command);
68         font.decSize();
69
70         if (editable_) {
71                 pi.pain.buttonText(x + 2, y, text_, font, renderState());
72         } else {
73                 pi.pain.rectText(x + 2, y, text_, font,
74                                  Color::commandbg, Color::commandframe);
75         }
76 }
77
78
79 } // namespace lyx