]> git.lyx.org Git - lyx.git/blob - src/insets/RenderButton.cpp
Merge branch 'master' of git.lyx.org:lyx
[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 "MetricsInfo.h"
16
17 #include "frontends/FontMetrics.h"
18 #include "frontends/Painter.h"
19
20
21 namespace lyx {
22
23
24 RenderButton::RenderButton()
25         : editable_(false)
26 {}
27
28
29 RenderBase * RenderButton::clone(Inset const *) const
30 {
31         return new RenderButton(*this);
32 }
33
34
35 void RenderButton::update(docstring const & text, bool editable)
36 {
37         text_ = text;
38         editable_ = editable;
39 }
40
41
42 void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
43 {
44         FontInfo font = sane_font;
45         font.decSize();
46         frontend::FontMetrics const & fm =
47                 theFontMetrics(font);
48
49         if (editable_)
50                 fm.buttonText(text_, dim.wid, dim.asc, dim.des);
51         else
52                 fm.rectText(text_, dim.wid, dim.asc, dim.des);
53
54         dim_ = dim;
55 }
56
57
58 void RenderButton::draw(PainterInfo & pi, int x, int y) const
59 {
60         // Draw it as a box with the LaTeX text
61         FontInfo font = sane_font;
62         font.setColor(Color_command);
63         font.decSize();
64
65         if (editable_) {
66                 pi.pain.buttonText(x, y, text_, font, renderState());
67         } else {
68                 pi.pain.rectText(x, y, text_, font,
69                                  Color_commandbg, Color_commandframe);
70         }
71 }
72
73
74 } // namespace lyx