1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "inseterror.h"
19 #include "lyx_gui_misc.h" // CancelCloseBoxCB
21 #include "BufferView.h"
26 /* Error, used for the LaTeX-Error Messages */
29 InsetError::InsetError()
36 InsetError::InsetError(string const & str)
37 : contents(str), form(0)
41 InsetError::~InsetError()
51 int InsetError::ascent(BufferView *, LyXFont const & font) const
54 efont.setSize(font.size()).decSize();
55 return lyxfont::maxAscent(efont) + 1;
59 int InsetError::descent(BufferView *, LyXFont const & font) const
62 efont.setSize(font.size()).decSize();
63 return lyxfont::maxDescent(efont) + 1;
67 int InsetError::width(BufferView *, LyXFont const & font) const
70 efont.setSize(font.size()).decSize();
71 return 6 + lyxfont::width(_("Error"), efont);
75 void InsetError::draw(BufferView * bv, LyXFont const & font,
76 int baseline, float & x, bool) const
78 Painter & pain = bv->painter();
80 efont.setSize(font.size()).decSize();
81 efont.setColor(LColor::error);
83 // Draw as "Error" in a framed box
85 pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
87 ascent(bv, font) + descent(bv, font) - 2,
89 pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
91 ascent(bv, font) + descent(bv, font) - 2,
93 pain.text(int(x + 2), baseline, _("Error"), efont);
95 x += width(bv, font) - 1;
99 void InsetError::Write(Buffer const *, ostream &) const
104 void InsetError::Read(Buffer const *, LyXLex &)
109 int InsetError::Latex(Buffer const *, ostream &,
110 bool /*fragile*/, bool /*fs*/) const
116 int InsetError::Ascii(Buffer const *, ostream &) const
122 int InsetError::Linuxdoc(Buffer const *, ostream &) const
128 int InsetError::DocBook(Buffer const *, ostream &) const
134 bool InsetError::AutoDelete() const
140 Inset::EDITABLE InsetError::Editable() const
146 void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
148 InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
150 fl_hide_form(inset->form);
151 fl_free_form(inset->form);
159 void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
161 InsetError::CloseErrorCB(ob , data);
165 char const * InsetError::EditMessage() const
167 return _("Opened error");
171 void InsetError::Edit(BufferView *, int, int, unsigned int)
173 static int ow = 400, oh = 240;
177 form = fl_bgn_form(FL_UP_BOX, ow, oh);
178 strobj = fl_add_box(FL_FRAME_BOX, 10, 10, 380, 180, "");
179 fl_set_object_color(strobj, FL_MCOL, FL_MCOL);
180 fl_set_object_gravity(strobj, FL_NorthWest, FL_SouthEast);
181 obj = fl_add_button(FL_RETURN_BUTTON, 140, 200, 120, 30,
183 fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
185 fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
186 fl_set_object_resize(obj, FL_RESIZE_NONE);
188 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
190 fl_set_object_label(strobj, contents.c_str());
194 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE,
195 FL_FULLBORDER, _("LaTeX Error"));
196 fl_set_form_minsize(form, ow, oh);
201 Inset * InsetError::Clone() const
203 return new InsetError(contents);