3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS
13 #include "inseterror.h"
15 #include "BufferView.h"
16 #include "funcrequest.h"
20 #include "frontends/Dialogs.h"
21 #include "frontends/font_metrics.h"
22 #include "frontends/LyXView.h"
23 #include "frontends/Painter.h"
25 #include "support/LAssert.h"
30 InsetError::InsetError(string const & str, bool)
35 InsetError::~InsetError()
37 Dialogs::hide("error", this);
41 dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
43 dispatch_result result = UNDISPATCHED;
46 case LFUN_MOUSE_RELEASE:
48 cmd.view()->owner()->getDialogs().show("error", getContents(), this);
52 return Inset::localDispatch(cmd);
57 int InsetError::ascent(BufferView *, LyXFont const & font) const
60 efont.setSize(font.size()).decSize();
61 return font_metrics::maxAscent(efont) + 1;
65 int InsetError::descent(BufferView *, LyXFont const & font) const
68 efont.setSize(font.size()).decSize();
69 return font_metrics::maxDescent(efont) + 1;
73 int InsetError::width(BufferView *, LyXFont const & font) const
76 efont.setSize(font.size()).decSize();
77 return 6 + font_metrics::width(_("Error"), efont);
81 void InsetError::draw(BufferView * bv, LyXFont const & font,
82 int baseline, float & x) const
87 Painter & pain = bv->painter();
89 efont.setSize(font.size()).decSize();
90 efont.setColor(LColor::error);
92 // Draw as "Error" in a framed box
94 pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
96 ascent(bv, font) + descent(bv, font) - 2,
98 pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
100 ascent(bv, font) + descent(bv, font) - 2,
102 pain.text(int(x + 2), baseline, _("Error"), efont);
104 x += width(bv, font) - 1;
108 string const InsetError::editMessage() const
110 return _("Opened error");