]> git.lyx.org Git - lyx.git/blob - src/insets/render_button.C
ws changes only
[lyx.git] / src / insets / render_button.C
1 /**
2  * \file render_button.C
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 "render_button.h"
14
15 #include "LColor.h"
16 #include "metricsinfo.h"
17
18 #include "frontends/font_metrics.h"
19 #include "frontends/Painter.h"
20
21 using std::string;
22
23
24 RenderButton::RenderButton()
25         : editable_(false)
26 {}
27
28
29 RenderBase * RenderButton::clone() const
30 {
31         return new RenderButton(*this);
32 }
33
34
35 void RenderButton::update(string const & text, bool editable)
36 {
37         text_ = text;
38         editable_ = editable;
39 }
40
41
42 void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
43 {
44         LyXFont font(LyXFont::ALL_SANE);
45         font.decSize();
46
47         if (editable_)
48                 font_metrics::buttonText(text_, font, dim.wid, dim.asc, dim.des);
49         else
50                 font_metrics::rectText(text_, font, dim.wid, dim.asc, dim.des);
51
52         dim.wid += 4;
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         LyXFont font(LyXFont::ALL_SANE);
60         font.setColor(LColor::command);
61         font.decSize();
62
63         if (editable_) {
64                 pi.pain.buttonText(x + 2, y, text_, font);
65         } else {
66                 pi.pain.rectText(x + 2, y, text_, font,
67                                  LColor::commandbg, LColor::commandframe);
68         }
69 }