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