]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
Few more update text-inset issues + some fixes, see ChangeLog.
[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 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
22 using std::ostream;
23 using std::endl;
24
25
26 InsetButton::InsetButton()
27 {
28 }
29
30 int InsetButton::ascent(BufferView * bv, LyXFont const &) const
31 {
32         LyXFont font(LyXFont::ALL_SANE);
33         font.decSize();
34         
35         int width, ascent, descent;
36         string s = getScreenLabel();
37         
38         if (Editable()) {
39                 bv->painter().buttonText(0, 0, s, font,
40                                          false, width, ascent, descent);
41         } else {
42                 bv->painter().rectText(0, 0, s, font,
43                                        LColor::commandbg, LColor::commandframe,
44                                        false, width, ascent, descent);
45         }
46         return ascent;
47 }
48
49
50 int InsetButton::descent(BufferView * bv, LyXFont const &) const
51 {
52         LyXFont font(LyXFont::ALL_SANE);
53         font.decSize();
54         
55         int width, ascent, descent;
56         string s = getScreenLabel();
57         
58         if (Editable()) {
59                 bv->painter().buttonText(0, 0, s, font,
60                                          false, width, ascent, descent);
61         } else {
62                 bv->painter().rectText(0, 0, s, font,
63                                    LColor::commandbg, LColor::commandframe,
64                                    false, width, ascent, descent);
65         }
66         return descent;
67 }
68
69
70 int InsetButton::width(BufferView * bv, LyXFont const &) const
71 {
72         LyXFont font(LyXFont::ALL_SANE);
73         font.decSize();
74         
75         int width, ascent, descent;
76         string s = getScreenLabel();
77         
78         if (Editable()) {
79                 bv->painter().buttonText(0, 0, s, font,
80                                          false, width, ascent, descent);
81         } else {
82                 bv->painter().rectText(0, 0, s, font,
83                                        LColor::commandbg, LColor::commandframe,
84                                        false, width, ascent, descent);
85         }
86         return width + 4;
87 }
88
89
90 void InsetButton::draw(BufferView * bv, LyXFont const &,
91                         int baseline, float & x, bool) const
92 {
93         Painter & pain = bv->painter();
94         // Draw it as a box with the LaTeX text
95         LyXFont font(LyXFont::ALL_SANE);
96         font.setColor(LColor::command).decSize();
97
98         int width;
99         string s = getScreenLabel();
100
101         if (Editable()) {
102                 pain.buttonText(int(x)+2, baseline, s, font, true, width);
103         } else {
104                 pain.rectText(int(x)+2, baseline, s, font,
105                               LColor::commandbg, LColor::commandframe,
106                               true, width);
107         }
108
109         x += width + 4;
110 }