]> git.lyx.org Git - lyx.git/blob - src/insets/RenderButton.cpp
Do not forceLTR in InsetHyperlink (#12044)
[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), broken_(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, bool broken)
37 {
38         text_ = text;
39         editable_ = editable;
40         inherit_font_ = inherit;
41         broken_ = broken;
42 }
43
44
45 void RenderButton::metrics(MetricsInfo & mi, Dimension & dim) const
46 {
47         FontInfo font = inherit_font_ ? mi.base.font : sane_font;
48         font.decSize();
49         frontend::FontMetrics const & fm = theFontMetrics(font);
50
51         fm.buttonText(text_, Inset::textOffset(mi.base.bv), dim.wid, dim.asc, dim.des);
52
53         dim_ = dim;
54 }
55
56
57 void RenderButton::draw(PainterInfo & pi, int x, int y) const
58 {
59         // Draw it as a box with the LaTeX text
60         FontInfo font = inherit_font_ ? pi.base.font : sane_font;
61         font.setColor(Color_command);
62         font.decSize();
63
64         if (broken_) {
65                 font.setColor(Color_command_broken);
66                 pi.pain.buttonText(x, y, text_, font,
67                                    renderState() ? Color_buttonhoverbg_broken : Color_buttonbg_broken,
68                                    Color_buttonframe_broken, Inset::textOffset(pi.base.bv));
69         } else if (editable_) {
70                 pi.pain.buttonText(x, y, text_, font,
71                                    renderState() ? Color_buttonhoverbg : Color_buttonbg,
72                                    Color_buttonframe, Inset::textOffset(pi.base.bv));
73         } else {
74                 pi.pain.buttonText(x, y, text_, font,
75                                    Color_commandbg, Color_commandframe,
76                                    Inset::textOffset(pi.base.bv));
77         }
78 }
79
80
81 } // namespace lyx