]> git.lyx.org Git - lyx.git/blob - src/insets/render_button.C
The speed patch: redraw only rows that have changed
[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 using std::auto_ptr;
23
24
25 RenderButton::RenderButton()
26         : editable_(false)
27 {}
28
29
30 auto_ptr<RenderBase> RenderButton::clone(InsetBase const *) const
31 {
32         return auto_ptr<RenderBase>(new RenderButton(*this));
33 }
34
35
36 void RenderButton::update(string const & text, bool editable)
37 {
38         text_ = text;
39         editable_ = editable;
40 }
41
42
43 void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
44 {
45         LyXFont font(LyXFont::ALL_SANE);
46         font.decSize();
47
48         if (editable_)
49                 font_metrics::buttonText(text_, font, dim.wid, dim.asc, dim.des);
50         else
51                 font_metrics::rectText(text_, font, dim.wid, dim.asc, dim.des);
52
53         dim.wid += 4;
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         LyXFont font(LyXFont::ALL_SANE);
61         font.setColor(LColor::command);
62         font.decSize();
63
64         if (editable_) {
65                 pi.pain.buttonText(x + 2, y, text_, font);
66         } else {
67                 pi.pain.rectText(x + 2, y, text_, font,
68                                  LColor::commandbg, LColor::commandframe);
69         }
70 }