-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2001 The LyX Team.
+/**
+ * \file inseterror.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ====================================================== */
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS
+ */
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include "inseterror.h"
#include "BufferView.h"
-#include "font.h"
+#include "funcrequest.h"
#include "gettext.h"
-#include "inseterror.h"
-#include "LyXView.h"
-#include "Painter.h"
+#include "lyxfont.h"
+#include "metricsinfo.h"
+
#include "frontends/Dialogs.h"
+#include "frontends/font_metrics.h"
+#include "frontends/LyXView.h"
+#include "frontends/Painter.h"
+
+#include "support/LAssert.h"
using std::ostream;
-/* Error, used for the LaTeX-Error Messages */
InsetError::InsetError(string const & str)
: contents(str)
{}
-int InsetError::ascent(BufferView *, LyXFont const & font) const
+// InsetError::InsetError(string const & str, bool)
+// : contents(str)
+// {}
+
+
+InsetError::~InsetError()
{
- LyXFont efont;
- efont.setSize(font.size()).decSize();
- return lyxfont::maxAscent(efont) + 1;
+ Dialogs::hide("error", this);
}
-int InsetError::descent(BufferView *, LyXFont const & font) const
+dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
{
- LyXFont efont;
- efont.setSize(font.size()).decSize();
- return lyxfont::maxDescent(efont) + 1;
+ // UNUSED: dispatch_result result = UNDISPATCHED;
+
+ switch (cmd.action) {
+ case LFUN_MOUSE_RELEASE:
+ case LFUN_INSET_EDIT:
+ cmd.view()->owner()->getDialogs().show("error", getContents(), this);
+ return DISPATCHED;
+
+ default:
+ return Inset::localDispatch(cmd);
+ }
}
-int InsetError::width(BufferView *, LyXFont const & font) const
+void InsetError::metrics(MetricsInfo & mi, Dimension & dim) const
{
LyXFont efont;
- efont.setSize(font.size()).decSize();
- return 6 + lyxfont::width(_("Error"), efont);
+ efont.setSize(mi.base.font.size()).decSize();
+ dim_.asc = font_metrics::maxAscent(efont) + 1;
+ dim_.des = font_metrics::maxDescent(efont) + 1;
+ dim_.wid = 6 + font_metrics::width(_("Error"), efont);
+ dim = dim_;
}
-void InsetError::draw(BufferView * bv, LyXFont const & font,
- int baseline, float & x, bool) const
+void InsetError::draw(PainterInfo & pi, int x, int y) const
{
- Painter & pain = bv->painter();
+ lyx::Assert(pi.base.bv);
+ cache(pi.base.bv);
+
LyXFont efont;
- efont.setSize(font.size()).decSize();
+ efont.setSize(pi.base.font.size()).decSize();
efont.setColor(LColor::error);
-
+
// Draw as "Error" in a framed box
x += 1;
- pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
- width(bv, font) - 2,
- ascent(bv, font) + descent(bv, font) - 2,
- LColor::insetbg);
- pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
- width(bv, font) - 2,
- ascent(bv, font) + descent(bv, font) - 2,
- LColor::error);
- pain.text(int(x + 2), baseline, _("Error"), efont);
-
- x += width(bv, font) - 1;
+ pi.pain.fillRectangle(x, y - dim_.asc + 1,
+ dim_.wid - 2, dim_.asc + dim_.des - 2, LColor::insetbg);
+ pi.pain.rectangle(x, y - dim_.asc + 1,
+ dim_.wid - 2, dim_.asc + dim_.des - 2, LColor::error);
+ pi.pain.text(x + 2, y, _("Error"), efont);
}
-string const InsetError::editMessage() const
+string const InsetError::editMessage() const
{
return _("Opened error");
}
-
-
-void InsetError::edit(BufferView * bv, int, int, unsigned int)
-{
- bv->owner()->getDialogs()->showError( this );
-}