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