]> git.lyx.org Git - lyx.git/blob - src/insets/RenderButton.cpp
Let command inset honor inheritFont() on screen
[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), inherit_font_(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                           bool inherit_font)
37 {
38         text_ = text;
39         editable_ = editable;
40         inherit_font_ = inherit_font;
41 }
42
43
44 void RenderButton::metrics(MetricsInfo & mi, Dimension & dim) const
45 {
46         FontInfo font = inherit_font_ ? mi.base.font : sane_font;
47         font.decSize();
48         frontend::FontMetrics const & fm =
49                 theFontMetrics(font);
50
51         if (editable_)
52                 fm.buttonText(text_, dim.wid, dim.asc, dim.des);
53         else
54                 fm.rectText(text_, dim.wid, dim.asc, dim.des);
55
56         dim_ = dim;
57 }
58
59
60 void RenderButton::draw(PainterInfo & pi, int x, int y) const
61 {
62         // Draw it as a box with the LaTeX text
63         FontInfo font = inherit_font_ ? pi.base.font : sane_font;
64         font.setColor(Color_command);
65         font.decSize();
66
67         if (editable_) {
68                 pi.pain.buttonText(x, y, text_, font, renderState());
69         } else {
70                 pi.pain.rectText(x, y, text_, font,
71                                  Color_commandbg, Color_commandframe);
72         }
73 }
74
75
76 } // namespace lyx