]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
Enable the external inset to handle unknown templates gracefully.
[lyx.git] / src / insets / insetbutton.C
1 /**
2  * \file insetbutton.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup Nielsen
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #include <config.h>
14
15 #include "insetbutton.h"
16 #include "debug.h"
17 #include "dimension.h"
18 #include "BufferView.h"
19 #include "funcrequest.h"
20 #include "frontends/LyXView.h"
21 #include "frontends/Painter.h"
22 #include "support/LAssert.h"
23 #include "lyxfont.h"
24 #include "metricsinfo.h"
25 #include "frontends/font_metrics.h"
26
27 using std::ostream;
28 using std::endl;
29
30
31 void InsetButton::metrics(MetricsInfo & mi, Dimension & dim) const
32 {
33         lyx::Assert(mi.base.bv);
34
35         LyXFont font(LyXFont::ALL_SANE);
36         font.decSize();
37
38         string const s = getScreenLabel(mi.base.bv->buffer());
39
40         if (editable())
41                 font_metrics::buttonText(s, font, dim.wid, dim.asc, dim.des);
42         else
43                 font_metrics::rectText(s, font, dim.wid, dim.asc, dim.des);
44
45         dim.wid += 4;
46 }
47
48
49 void InsetButton::draw(PainterInfo & pi, int x, int y) const
50 {
51         lyx::Assert(pi.base.bv);
52         cache(pi.base.bv);
53
54         // Draw it as a box with the LaTeX text
55         LyXFont font(LyXFont::ALL_SANE);
56         font.setColor(LColor::command).decSize();
57
58         string const s = getScreenLabel(pi.base.bv->buffer());
59
60         if (editable()) {
61                 pi.pain.buttonText(x + 2, y, s, font);
62         } else {
63                 pi.pain.rectText(x + 2, y, s, font,
64                               LColor::commandbg, LColor::commandframe);
65         }
66 }
67
68
69 void InsetButton::cache(BufferView * bv) const
70 {
71         view_ = bv->owner()->view();
72 }
73
74
75 #warning Shouldnt this really return a shared_ptr<BufferView>? (Lgb)
76 BufferView * InsetButton::view() const
77 {
78         return view_.lock().get();
79 }
80
81
82 dispatch_result InsetButton::localDispatch(FuncRequest const & cmd)
83 {
84         return Inset::localDispatch(cmd);
85 }