]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
some small updates to Painter, and make the new painter the default.
[lyx.git] / src / insets / inseterror.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-1999 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "inseterror.h"
18 #ifndef USE_PAINTER
19 #include "lyxdraw.h"
20 #endif
21 #include "gettext.h"
22 #include "lyx_gui_misc.h" // CancelCloseBoxCB
23 #include "Painter.h"
24
25 /* Error, used for the LaTeX-Error Messages */
26
27 InsetError::InsetError()
28 {
29         form = 0;
30 }
31
32
33 InsetError::InsetError(string const & str)
34         : contents(str)
35 {
36         form = 0;
37 }
38
39
40 InsetError::~InsetError()
41 {
42         if (form) {
43                 fl_hide_form(form);
44                 fl_free_form(form);
45                 form = 0;
46         }
47 }
48
49
50 #ifdef USE_PAINTER
51 int InsetError::ascent(Painter &, LyXFont const & font) const
52 {
53         LyXFont efont;
54         efont.setSize(font.size()).decSize();
55         return efont.maxAscent() + 1;
56 }
57 #else
58 int InsetError::Ascent(LyXFont const & font) const
59 {
60         LyXFont efont;
61         efont.setSize(font.size()).decSize();
62         return efont.maxAscent()+1;
63 }
64 #endif
65
66
67 #ifdef USE_PAINTER
68 int InsetError::descent(Painter &, LyXFont const & font) const
69 {
70         LyXFont efont;
71         efont.setSize(font.size()).decSize();
72         return efont.maxDescent() + 1;
73 }
74 #else
75 int InsetError::Descent(LyXFont const & font) const
76 {
77         LyXFont efont;
78         efont.setSize(font.size()).decSize();
79         return efont.maxDescent()+1;
80 }
81 #endif
82
83
84 #ifdef USE_PAINTER
85 int InsetError::width(Painter &, LyXFont const & font) const
86 {
87         LyXFont efont;
88         efont.setSize(font.size()).decSize();
89         return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
90 }
91 #else
92 int InsetError::Width(LyXFont const & font) const
93 {
94         LyXFont efont;
95         efont.setSize(font.size()).decSize();
96         return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
97 }
98 #endif
99
100
101 #ifdef USE_PAINTER
102 void InsetError::draw(Painter & pain, LyXFont const & font,
103                       int baseline, float & x) const
104 {
105         LyXFont efont;
106         efont.setSize(font.size()).decSize();
107         efont.setColor(LColor::error);
108    
109         // Draw as "Error" in a framed box
110         x += 1;
111         pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
112                           width(pain, font) - 2,
113                           ascent(pain, font) + descent(pain, font) - 2,
114                            LColor::insetbg);
115         pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
116                        width(pain, font) - 2,
117                        ascent(pain, font) + descent(pain, font) - 2,
118                        LColor::error);
119         pain.text(int(x + 2), baseline, _("Error"), efont);
120
121         x +=  width(pain, font) - 1;
122 }
123 #else
124 void InsetError::Draw(LyXFont font, LyXScreen & scr,
125                       int baseline, float & x)
126 {
127         LyXFont efont;
128         efont.setSize(font.size()).decSize();
129         efont.setLatex(LyXFont::ON);
130    
131         // Draw as "Error" in a framed box
132         x += 1;
133         scr.fillRectangle(gc_lighted,
134                           int(x), baseline - Ascent(font)+1,
135                           Width(font)-2, Ascent(font)+ Descent(font)-2);
136         scr.drawRectangle(gc_foot,
137                           int(x), baseline-Ascent(font)+1,
138                           Width(font)-2, Ascent(font)+Descent(font)-2); 
139         scr.drawString(efont, _("Error"), baseline, int(x+2));
140
141         x +=  Width(font) - 1;
142 }
143 #endif
144
145 void InsetError::Write(ostream &)
146 {
147 }
148
149
150 void InsetError::Read(LyXLex &)
151 {
152 }
153
154
155 int InsetError::Latex(ostream &, signed char /*fragile*/)
156 {
157         return 0;
158 }
159
160
161 int InsetError::Latex(string &, signed char /*fragile*/)
162 {
163         return 0;
164 }
165
166
167 int InsetError::Linuxdoc(string &)
168 {
169         return 0;
170 }
171
172
173 int InsetError::DocBook(string &)
174 {
175         return 0;
176 }
177
178
179 bool InsetError::AutoDelete() const
180 {
181         return true;
182 }
183
184
185 unsigned char InsetError::Editable() const
186 {
187         return 1;
188 }
189
190
191 void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
192 {
193         InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
194         if (inset->form) {
195                 fl_hide_form(inset->form);
196                 fl_free_form(inset->form);
197                 inset->form = 0;
198         }
199 }
200
201
202 // A C wrapper
203 extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
204 {
205         InsetError::CloseErrorCB(ob , data);
206 }
207
208
209 void InsetError::Edit(int, int)
210 {
211         static int ow = 400, oh = 240;
212
213         if (!form) {
214                 FL_OBJECT * obj;
215                 form = fl_bgn_form(FL_UP_BOX, ow, oh);
216                 strobj = fl_add_box(FL_FRAME_BOX, 10, 10, 380, 180, "");
217                 fl_set_object_color(strobj, FL_MCOL, FL_MCOL);
218                 fl_set_object_gravity(strobj, FL_NorthWest, FL_SouthEast);
219                 obj = fl_add_button(FL_RETURN_BUTTON, 140, 200, 120, 30,
220                                     _("Close"));
221                 fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
222                 obj->u_vdata = this;
223                 fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
224                 fl_set_object_resize(obj, FL_RESIZE_NONE);
225                 fl_end_form();
226                 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
227         }
228         fl_set_object_label(strobj, contents.c_str());
229         if (form->visible) {
230                 fl_raise_form(form);
231         } else {
232                 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE,
233                              FL_FULLBORDER, _("LaTeX Error"));
234                 fl_set_form_minsize(form, ow, oh);
235         }
236 }
237
238
239 Inset * InsetError::Clone() const
240 {
241         return new InsetError(contents);
242 }