1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "inseterror.h"
20 #include "lyx_gui_misc.h" // CancelCloseBoxCB
23 /* Error, used for the LaTeX-Error Messages */
25 InsetError::InsetError()
31 InsetError::InsetError(string const & str)
38 InsetError::~InsetError()
49 int InsetError::ascent(Painter &, LyXFont const & font) const
52 efont.setSize(font.size()).decSize();
53 return efont.maxAscent() + 1;
56 int InsetError::Ascent(LyXFont const & font) const
59 efont.setSize(font.size()).decSize();
60 return efont.maxAscent()+1;
66 int InsetError::descent(Painter &, LyXFont const & font) const
69 efont.setSize(font.size()).decSize();
70 return efont.maxDescent() + 1;
73 int InsetError::Descent(LyXFont const & font) const
76 efont.setSize(font.size()).decSize();
77 return efont.maxDescent()+1;
83 int InsetError::width(Painter &, LyXFont const & font) const
86 efont.setSize(font.size()).decSize();
87 return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
90 int InsetError::Width(LyXFont const & font) const
93 efont.setSize(font.size()).decSize();
94 return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
100 void InsetError::draw(Painter & pain, LyXFont const & font,
101 int baseline, float & x) const
104 efont.setSize(font.size()).decSize();
105 efont.setColor(LColor::error);
107 // Draw as "Error" in a framed box
109 pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
110 width(pain, font) - 2,
111 ascent(pain, font) + descent(pain, font) - 2,
113 pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
114 width(pain, font) - 2,
115 ascent(pain, font) + descent(pain, font) - 2,
117 pain.text(int(x + 2), baseline, _("Error"), efont);
119 x += width(pain, font) - 1;
122 void InsetError::Draw(LyXFont font, LyXScreen & scr,
123 int baseline, float & x)
126 efont.setSize(font.size()).decSize();
127 efont.setLatex(LyXFont::ON);
129 // Draw as "Error" in a framed box
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));
139 x += Width(font) - 1;
143 void InsetError::Write(ostream &)
148 void InsetError::Read(LyXLex &)
153 int InsetError::Latex(ostream &, signed char /*fragile*/)
159 int InsetError::Latex(string &, signed char /*fragile*/)
165 int InsetError::Linuxdoc(string &)
171 int InsetError::DocBook(string &)
177 bool InsetError::AutoDelete() const
183 unsigned char InsetError::Editable() const
189 void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
191 InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
193 fl_hide_form(inset->form);
194 fl_free_form(inset->form);
201 extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
203 InsetError::CloseErrorCB(ob , data);
207 void InsetError::Edit(int, int)
209 static int ow = 400, oh = 240;
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,
219 fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
221 fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
222 fl_set_object_resize(obj, FL_RESIZE_NONE);
224 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
226 fl_set_object_label(strobj, contents.c_str());
230 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE,
231 FL_FULLBORDER, _("LaTeX Error"));
232 fl_set_form_minsize(form, ow, oh);
237 Inset * InsetError::Clone() const
239 return new InsetError(contents);