]> git.lyx.org Git - lyx.git/blob - src/insets/insetert.C
6a7fd1a1587a0a5bd7d7a885d5ab9ee081c1505c
[lyx.git] / src / insets / insetert.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1998 The LyX Team.
7  *
8  *======================================================*/
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "insetert.h"
17 #include "gettext.h"
18 #include "lyxfont.h"
19 #include "Painter.h"
20 #include "lyx_gui_misc.h"
21
22
23 InsetERT::InsetERT(Buffer * bf)
24         : InsetText(bf)
25 {
26         closed = true;
27         nomotion = false;
28 }
29
30
31 InsetERT * InsetERT::Clone() const
32 {
33     InsetERT * result = new InsetERT(buffer);
34     return result;
35 }
36
37
38 void InsetERT::Write(ostream & os) const
39 {
40     os << "ERT\n";
41     WriteParagraphData(os);
42 }
43
44
45 int InsetERT::ascent_closed(Painter & pain, LyXFont const & f) const
46 {
47         int width, ascent, descent;
48         LyXFont font(LyXFont::ALL_SANE);
49         font.setSize(f.size());
50         font.decSize();
51         font.decSize();
52         pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent);
53         return ascent;
54 }
55
56
57 int InsetERT::descent_closed(Painter & pain, LyXFont const & f) const
58 {
59         int width, ascent, descent;
60         LyXFont font(LyXFont::ALL_SANE);
61         font.setSize(f.size());
62         font.decSize();
63         font.decSize();
64         pain.buttonText(0, 0, _("ERT"), font, false, width, ascent, descent);
65         return descent;
66 }
67
68
69 int InsetERT::width_closed(Painter & pain, LyXFont const & f) const
70 {
71         int width, ascent, descent;
72         LyXFont font(LyXFont::ALL_SANE);
73         font.setSize(f.size());
74         font.decSize();
75         font.decSize();
76         pain.buttonText(TEXT_TO_INSET_OFFSET, 0, _("ERT"), font, false,
77                         width, ascent, descent);
78         return width + (2*TEXT_TO_INSET_OFFSET);
79 }
80
81
82 int InsetERT::ascent(Painter & pain, LyXFont const & font) const
83 {
84     if (closed) 
85         return ascent_closed(pain, font);
86     else 
87         return InsetText::ascent(pain, font);
88 }
89
90
91 int InsetERT::descent(Painter & pain, LyXFont const & font) const
92 {
93
94     if (closed) 
95         return descent_closed(pain, font);
96     else 
97         return InsetText::descent(pain, font);
98 }
99
100
101 int InsetERT::width(Painter & pain, LyXFont const & font) const
102 {
103     if (closed) 
104         return width_closed(pain, font);
105     else 
106         return InsetText::width(pain, font);
107 }
108
109
110 void InsetERT::draw_closed(Painter & pain, LyXFont const & f,
111                            int baseline, float & x) const
112 {
113         LyXFont font(LyXFont::ALL_SANE);
114         font.setSize(f.size());
115         font.decSize();
116         font.decSize();
117         font.setColor(LColor::ert);
118         int width;
119         pain.buttonText(int(x)+TEXT_TO_INSET_OFFSET, baseline, _("ERT"), font,
120                         true, width);
121         x += width + (2*TEXT_TO_INSET_OFFSET);
122 }
123
124
125 void InsetERT::draw(Painter & pain, LyXFont const & f,
126                     int baseline, float & x) const
127 {
128     if (closed) {
129         top_x = int(x);
130         top_baseline = baseline;
131         draw_closed(pain, f, baseline, x);
132     } else {
133         InsetText::draw(pain, f, baseline, x);
134     }
135 //    resetPos(bv);
136 }
137
138
139 void InsetERT::InsetButtonRelease(BufferView * bv, int x, int y, int button)
140 {
141     nomotion = false;
142     InsetText::InsetButtonRelease(bv, x, y, button);
143 }
144
145
146 void InsetERT::InsetButtonPress(BufferView * bv, int x, int y, int button)
147 {
148     nomotion = false;
149     InsetText::InsetButtonPress(bv, x, y, button);
150 }
151
152
153 void InsetERT::InsetMotionNotify(BufferView * bv, int x, int y, int button)
154 {
155     if (nomotion)
156         return;
157     InsetText::InsetMotionNotify(bv, x, y, button);
158 }
159
160
161 void InsetERT::Edit(BufferView * bv, int x, int y, unsigned int button)
162 {
163     closed = false;
164     nomotion = true;
165     LyXFont font(LyXFont::ALL_SANE);
166     font.setLatex (LyXFont::ON);
167     InsetText::Edit(bv, (x > (width_closed(bv->getPainter(),font)-5) ?
168                      width(bv->getPainter(), font) : 0), y, button);
169     real_current_font = current_font = font;
170     bv->updateInset(this, false);
171 }
172
173
174 void InsetERT::InsetUnlock(BufferView * bv)
175 {
176     closed = true;
177     InsetText::InsetUnlock(bv);
178     bv->updateInset(this, false);
179 }
180
181
182 bool InsetERT::InsertInset(Inset *)
183 {
184     return false;
185 }
186
187
188 void InsetERT::SetFont(LyXFont const &, bool)
189 {
190     WriteAlert(_("Impossible Operation!"),
191                _("Not permitted to change font-types inside ERT-insets!"),
192                _("Sorry."));
193 }