]> git.lyx.org Git - lyx.git/blob - src/insets/insetbutton.C
simplify rectText and buttonText add separate metric methods for these
[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();
40
41 #if 0
42         if (editable()) {
43                 bv->painter().buttonText(0, 0, s, font,
44                                          false, width, ascent, descent);
45         } else {
46                 bv->painter().rectText(0, 0, s, font,
47                                        LColor::commandbg, LColor::commandframe,
48                                        false, width, ascent, descent);
49         }
50 #else
51         if (editable()) {
52                 lyxfont::buttonText(s, font, width, ascent, descent);
53         } else {
54                 lyxfont::rectText(s, font, width, ascent, descent);
55         }
56 #endif
57         return ascent;
58 }
59
60
61 int InsetButton::descent(BufferView * bv, LyXFont const &) const
62 {
63         lyx::Assert(bv);
64         
65         LyXFont font(LyXFont::ALL_SANE);
66         font.decSize();
67         
68         int width;
69         int ascent;
70         int descent;
71         string const s = getScreenLabel();
72
73 #if 0
74         if (editable()) {
75                 bv->painter().buttonText(0, 0, s, font,
76                                          false, width, ascent, descent);
77         } else {
78                 bv->painter().rectText(0, 0, s, font,
79                                    LColor::commandbg, LColor::commandframe,
80                                    false, width, ascent, descent);
81         }
82 #else
83         if (editable()) {
84                 lyxfont::buttonText(s, font, width, ascent, descent);
85         } else {
86                 lyxfont::rectText(s, font, width, ascent, descent);
87         }
88 #endif
89         return descent;
90 }
91
92
93 int InsetButton::width(BufferView * bv, LyXFont const &) const
94 {
95         lyx::Assert(bv);
96
97         LyXFont font(LyXFont::ALL_SANE);
98         font.decSize();
99         
100         int width;
101         int ascent;
102         int descent;
103         string const s = getScreenLabel();
104
105 #if 0
106         if (editable()) {
107                 bv->painter().buttonText(0, 0, s, font,
108                                          false, width, ascent, descent);
109         } else {
110                 bv->painter().rectText(0, 0, s, font,
111                                        LColor::commandbg, LColor::commandframe,
112                                        false, width, ascent, descent);
113         }
114 #else
115         if (editable()) {
116                 lyxfont::buttonText(s, font, width, ascent, descent);
117         } else {
118                 lyxfont::rectText(s, font, width, ascent, descent);
119         }
120 #endif
121         return width + 4;
122 }
123
124
125 void InsetButton::draw(BufferView * bv, LyXFont const &,
126                         int baseline, float & x, bool) const
127 {
128         lyx::Assert(bv);
129         
130         Painter & pain = bv->painter();
131         // Draw it as a box with the LaTeX text
132         LyXFont font(LyXFont::ALL_SANE);
133         font.setColor(LColor::command).decSize();
134
135         string const s = getScreenLabel();
136
137 #if 0
138         int width;
139         if (editable()) {
140                 pain.buttonText(int(x) + 2, baseline, s, font, true, width);
141         } else {
142                 pain.rectText(int(x) + 2, baseline, s, font,
143                               LColor::commandbg, LColor::commandframe,
144                               true, width);
145         }
146 #else
147         if (editable()) {
148                 pain.buttonText(int(x) + 2, baseline, s, font);
149         } else {
150                 pain.rectText(int(x) + 2, baseline, s, font,
151                               LColor::commandbg, LColor::commandframe);
152         }
153 #endif
154
155 #if 0
156         x += width + 4;
157 #else
158         x += width(bv, font);
159 #endif
160 }