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"
22 #include "lyx_gui_misc.h" // CancelCloseBoxCB
25 /* Error, used for the LaTeX-Error Messages */
27 InsetError::InsetError()
33 InsetError::InsetError(string const & str)
40 InsetError::~InsetError()
51 int InsetError::ascent(Painter &, LyXFont const & font) const
54 efont.setSize(font.size()).decSize();
55 return efont.maxAscent() + 1;
58 int InsetError::Ascent(LyXFont const & font) const
61 efont.setSize(font.size()).decSize();
62 return efont.maxAscent()+1;
68 int InsetError::descent(Painter &, LyXFont const & font) const
71 efont.setSize(font.size()).decSize();
72 return efont.maxDescent() + 1;
75 int InsetError::Descent(LyXFont const & font) const
78 efont.setSize(font.size()).decSize();
79 return efont.maxDescent()+1;
85 int InsetError::width(Painter &, LyXFont const & font) const
88 efont.setSize(font.size()).decSize();
89 return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
92 int InsetError::Width(LyXFont const & font) const
95 efont.setSize(font.size()).decSize();
96 return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
102 void InsetError::draw(Painter & pain, LyXFont const & font,
103 int baseline, float & x) const
106 efont.setSize(font.size()).decSize();
107 efont.setColor(LColor::error);
109 // Draw as "Error" in a framed box
111 pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
112 width(pain, font) - 2,
113 ascent(pain, font) + descent(pain, font) - 2,
115 pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
116 width(pain, font) - 2,
117 ascent(pain, font) + descent(pain, font) - 2,
119 pain.text(int(x + 2), baseline, _("Error"), efont);
121 x += width(pain, font) - 1;
124 void InsetError::Draw(LyXFont font, LyXScreen & scr,
125 int baseline, float & x)
128 efont.setSize(font.size()).decSize();
129 efont.setLatex(LyXFont::ON);
131 // Draw as "Error" in a framed box
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));
141 x += Width(font) - 1;
145 void InsetError::Write(ostream &)
150 void InsetError::Read(LyXLex &)
155 int InsetError::Latex(ostream &, signed char /*fragile*/)
161 int InsetError::Latex(string &, signed char /*fragile*/)
167 int InsetError::Linuxdoc(string &)
173 int InsetError::DocBook(string &)
179 bool InsetError::AutoDelete() const
185 unsigned char InsetError::Editable() const
191 void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
193 InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
195 fl_hide_form(inset->form);
196 fl_free_form(inset->form);
203 extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
205 InsetError::CloseErrorCB(ob , data);
209 void InsetError::Edit(int, int)
211 static int ow = 400, oh = 240;
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,
221 fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
223 fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
224 fl_set_object_resize(obj, FL_RESIZE_NONE);
226 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
228 fl_set_object_label(strobj, contents.c_str());
232 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE,
233 FL_FULLBORDER, _("LaTeX Error"));
234 fl_set_form_minsize(form, ow, oh);
239 Inset * InsetError::Clone() const
241 return new InsetError(contents);