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