]> git.lyx.org Git - lyx.git/blob - src/insets/RenderButton.cpp
* src/paragraph_funcs.cpp (breakParagraph): change parameter 'flag' to
[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 void 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         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         Font font(Font::ALL_SANE);
64         font.setColor(Color::command);
65         font.decSize();
66
67         if (editable_) {
68                 pi.pain.buttonText(x + 2, y, text_, font, renderState());
69         } else {
70                 pi.pain.rectText(x + 2, y, text_, font,
71                                  Color::commandbg, Color::commandframe);
72         }
73 }
74
75
76 } // namespace lyx