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