]> git.lyx.org Git - lyx.git/blob - src/insets/RenderButton.cpp
Use the same code for editable and non-editable buttons
[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 = theFontMetrics(font);
49
50         fm.buttonText(text_, Inset::TEXT_TO_INSET_OFFSET, dim.wid, dim.asc, dim.des);
51
52         dim_ = dim;
53 }
54
55
56 void RenderButton::draw(PainterInfo & pi, int x, int y) const
57 {
58         // Draw it as a box with the LaTeX text
59         FontInfo font = inherit_font_ ? pi.base.font : sane_font;
60         font.setColor(Color_command);
61         font.decSize();
62
63         if (editable_) {
64                 pi.pain.buttonText(x, y, text_, font,
65                                    renderState() ? Color_buttonhoverbg : Color_buttonbg,
66                                    Color_buttonframe, Inset::TEXT_TO_INSET_OFFSET);
67         } else {
68                 pi.pain.buttonText(x, y, text_, font,
69                                    Color_commandbg, Color_commandframe,
70                                    Inset::TEXT_TO_INSET_OFFSET);
71         }
72 }
73
74
75 } // namespace lyx