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()
39 view()->owner()->getDialogs().hide("error");
43 dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
45 dispatch_result result = UNDISPATCHED;
48 case LFUN_MOUSE_RELEASE:
49 edit(cmd.view(), cmd.x, cmd.y, cmd.button());
60 int InsetError::ascent(BufferView *, LyXFont const & font) const
63 efont.setSize(font.size()).decSize();
64 return font_metrics::maxAscent(efont) + 1;
68 int InsetError::descent(BufferView *, LyXFont const & font) const
71 efont.setSize(font.size()).decSize();
72 return font_metrics::maxDescent(efont) + 1;
76 int InsetError::width(BufferView *, LyXFont const & font) const
79 efont.setSize(font.size()).decSize();
80 return 6 + font_metrics::width(_("Error"), efont);
84 void InsetError::draw(BufferView * bv, LyXFont const & font,
85 int baseline, float & x, bool) const
90 Painter & pain = bv->painter();
92 efont.setSize(font.size()).decSize();
93 efont.setColor(LColor::error);
95 // Draw as "Error" in a framed box
97 pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
99 ascent(bv, font) + descent(bv, font) - 2,
101 pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
103 ascent(bv, font) + descent(bv, font) - 2,
105 pain.text(int(x + 2), baseline, _("Error"), efont);
107 x += width(bv, font) - 1;
111 string const InsetError::editMessage() const
113 return _("Opened error");
117 void InsetError::edit(BufferView * bv, int, int, mouse_button::state)
119 bv->owner()->getDialogs().show("error", getContents(), this);
123 void InsetError::edit(BufferView * bv, bool)
125 edit(bv, 0, 0, mouse_button::none);