]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
IU for second phase of two-phase drawing
[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::dimension(BufferView * bv, LyXFont const &,
32         Dimension & dim) const
33 {
34         lyx::Assert(bv);
35
36         LyXFont font(LyXFont::ALL_SANE);
37         font.decSize();
38
39         string const s = getScreenLabel(bv->buffer());
40
41         if (editable())
42                 font_metrics::buttonText(s, font, dim.wid, dim.asc, dim.des);
43         else
44                 font_metrics::rectText(s, font, dim.wid, dim.asc, dim.des);
45
46         dim.wid += 4;
47 }
48
49
50 void InsetButton::draw(PainterInfo & pi, int x, int y) const
51 {
52         lyx::Assert(pi.base.bv);
53         cache(pi.base.bv);
54
55         // Draw it as a box with the LaTeX text
56         LyXFont font(LyXFont::ALL_SANE);
57         font.setColor(LColor::command).decSize();
58
59         string const s = getScreenLabel(pi.base.bv->buffer());
60
61         if (editable()) {
62                 pi.pain.buttonText(x + 2, y, s, font);
63         } else {
64                 pi.pain.rectText(x + 2, y, s, font,
65                               LColor::commandbg, LColor::commandframe);
66         }
67 }
68
69
70 void InsetButton::cache(BufferView * bv) const
71 {
72         view_ = bv->owner()->view();
73 }
74
75
76 #warning Shouldnt this really return a shared_ptr<BufferView>? (Lgb)
77 BufferView * InsetButton::view() const
78 {
79         return view_.lock().get();
80 }
81
82
83 dispatch_result InsetButton::localDispatch(FuncRequest const & cmd)
84 {
85         return Inset::localDispatch(cmd);
86 }