]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
Hopefully fixed the redo problems with insets!
[lyx.git] / src / insets / insetbutton.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 2000-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "insetbutton.h"
18 #include "debug.h"
19 #include "BufferView.h"
20 #include "Painter.h"
21 #include "support/LAssert.h"
22 #include "lyxfont.h"
23 #include "font.h"
24
25 using std::ostream;
26 using std::endl;
27
28
29 int InsetButton::ascent(BufferView * bv, LyXFont const &) const
30 {
31         lyx::Assert(bv);
32         
33         LyXFont font(LyXFont::ALL_SANE);
34         font.decSize();
35         
36         int width;
37         int ascent;
38         int descent;
39         string const s = getScreenLabel(bv->buffer());
40
41         if (editable()) {
42                 lyxfont::buttonText(s, font, width, ascent, descent);
43         } else {
44                 lyxfont::rectText(s, font, width, ascent, descent);
45         }
46
47         return ascent;
48 }
49
50
51 int InsetButton::descent(BufferView * bv, LyXFont const &) const
52 {
53         lyx::Assert(bv);
54         
55         LyXFont font(LyXFont::ALL_SANE);
56         font.decSize();
57         
58         int width;
59         int ascent;
60         int descent;
61         string const s = getScreenLabel(bv->buffer());
62
63         if (editable()) {
64                 lyxfont::buttonText(s, font, width, ascent, descent);
65         } else {
66                 lyxfont::rectText(s, font, width, ascent, descent);
67         }
68
69         return descent;
70 }
71
72
73 int InsetButton::width(BufferView * bv, LyXFont const &) const
74 {
75         lyx::Assert(bv);
76
77         LyXFont font(LyXFont::ALL_SANE);
78         font.decSize();
79         
80         int width;
81         int ascent;
82         int descent;
83         string const s = getScreenLabel(bv->buffer());
84
85         if (editable()) {
86                 lyxfont::buttonText(s, font, width, ascent, descent);
87         } else {
88                 lyxfont::rectText(s, font, width, ascent, descent);
89         }
90
91         return width + 4;
92 }
93
94
95 void InsetButton::draw(BufferView * bv, LyXFont const &,
96                         int baseline, float & x, bool) const
97 {
98         lyx::Assert(bv);
99         
100         Painter & pain = bv->painter();
101         // Draw it as a box with the LaTeX text
102         LyXFont font(LyXFont::ALL_SANE);
103         font.setColor(LColor::command).decSize();
104
105         string const s = getScreenLabel(bv->buffer());
106
107         if (editable()) {
108                 pain.buttonText(int(x) + 2, baseline, s, font);
109         } else {
110                 pain.rectText(int(x) + 2, baseline, s, font,
111                               LColor::commandbg, LColor::commandframe);
112         }
113
114         x += width(bv, font);
115 }