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"
29 /* Error, used for the LaTeX-Error Messages */
31 InsetError::InsetError(string const & str, bool)
36 InsetError::~InsetError()
38 Dialogs::hide("error", this);
42 dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
44 dispatch_result result = UNDISPATCHED;
47 case LFUN_MOUSE_RELEASE:
48 edit(cmd.view(), cmd.x, cmd.y, cmd.button());
59 int InsetError::ascent(BufferView *, LyXFont const & font) const
62 efont.setSize(font.size()).decSize();
63 return font_metrics::maxAscent(efont) + 1;
67 int InsetError::descent(BufferView *, LyXFont const & font) const
70 efont.setSize(font.size()).decSize();
71 return font_metrics::maxDescent(efont) + 1;
75 int InsetError::width(BufferView *, LyXFont const & font) const
78 efont.setSize(font.size()).decSize();
79 return 6 + font_metrics::width(_("Error"), efont);
83 void InsetError::draw(BufferView * bv, LyXFont const & font,
84 int baseline, float & x) const
89 Painter & pain = bv->painter();
91 efont.setSize(font.size()).decSize();
92 efont.setColor(LColor::error);
94 // Draw as "Error" in a framed box
96 pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
98 ascent(bv, font) + descent(bv, font) - 2,
100 pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
102 ascent(bv, font) + descent(bv, font) - 2,
104 pain.text(int(x + 2), baseline, _("Error"), efont);
106 x += width(bv, font) - 1;
110 string const InsetError::editMessage() const
112 return _("Opened error");
116 void InsetError::edit(BufferView * bv, int, int, mouse_button::state)
118 bv->owner()->getDialogs().show("error", getContents(), this);
122 void InsetError::edit(BufferView * bv, bool)
124 edit(bv, 0, 0, mouse_button::none);