-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-1999 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 "definitions.h"
#include "inseterror.h"
-#include "lyxdraw.h"
-#include "gettext.h"
-#include "lyx_gui_misc.h" // CancelCloseBoxCB
-
-/* Error, used for the LaTeX-Error Messages */
-InsetError::InsetError()
-{
- form = 0;
-}
-
-InsetError::InsetError(string const & string)
- : contents(string)
-{
- form = 0;
-}
-
-
-InsetError::~InsetError()
-{
- if (form) {
- fl_hide_form(form);
- fl_free_form(form);
- form = 0;
- }
-}
-
-
-int InsetError::Ascent(LyXFont const &font) const
-{
- LyXFont efont;
- efont.setSize(font.size()).decSize();
- return efont.maxAscent()+1;
-}
-
-
-int InsetError::Descent(LyXFont const &font) const
-{
- LyXFont efont;
- efont.setSize(font.size()).decSize();
- return efont.maxDescent()+1;
-}
-
-
-int InsetError::Width(LyXFont const &font) const
-{
- LyXFont efont;
- efont.setSize(font.size()).decSize();
- return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
-}
+#include "BufferView.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "lyxfont.h"
+#include "metricsinfo.h"
+#include "frontends/Dialogs.h"
+#include "frontends/font_metrics.h"
+#include "frontends/LyXView.h"
+#include "frontends/Painter.h"
-void InsetError::Draw(LyXFont font, LyXScreen &scr,
- int baseline, float &x)
-{
- LyXFont efont;
- efont.setSize(font.size()).decSize();
- efont.setLatex(LyXFont::ON);
-
- // Draw as "Error" in a framed box
- x += 1;
- //scr.drawFilledRectangle(int(x), baseline - Ascent(font)+1,
- // Width(font)-2,Ascent(font)+ Descent(font)-2,
- // FL_GRAY80);
- scr.fillRectangle(gc_lighted,
- int(x), baseline - Ascent(font)+1,
- Width(font)-2,Ascent(font)+ Descent(font)-2);
- //scr.drawRectangle(int(x), baseline-Ascent(font)+1,
- // Width(font)-2, Ascent(font)+Descent(font)-2,
- // FL_RED);
- scr.drawRectangle(gc_foot,
- int(x), baseline-Ascent(font)+1,
- Width(font)-2, Ascent(font)+Descent(font)-2);
- scr.drawString(efont, _("Error"), baseline, int(x+2));
-
- x += Width(font) - 1;
-}
+#include "support/LAssert.h"
+using std::ostream;
-void InsetError::Write(FILE *)
-{
-}
-void InsetError::Read(LyXLex &)
-{
-}
+InsetError::InsetError(string const & str)
+ : contents(str)
+{}
-int InsetError::Latex(FILE *, signed char /*fragile*/)
-{
- return 0;
-}
+// InsetError::InsetError(string const & str, bool)
+// : contents(str)
+// {}
-int InsetError::Latex(string &, signed char /*fragile*/)
+InsetError::~InsetError()
{
- return 0;
+ Dialogs::hide("error", this);
}
-int InsetError::Linuxdoc(string &)
+dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
{
- return 0;
-}
+ // 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;
-int InsetError::DocBook(string &)
-{
- return 0;
+ default:
+ return Inset::localDispatch(cmd);
+ }
}
-bool InsetError::AutoDelete() const
+void InsetError::metrics(MetricsInfo & mi, Dimension & dim) const
{
- return true;
+ LyXFont 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_;
}
-unsigned char InsetError::Editable() const
+void InsetError::draw(PainterInfo & pi, int x, int y) const
{
- return 1;
-}
+ lyx::Assert(pi.base.bv);
+ cache(pi.base.bv);
+ LyXFont efont;
+ efont.setSize(pi.base.font.size()).decSize();
+ efont.setColor(LColor::error);
-void InsetError::CloseErrorCB(FL_OBJECT *, long data)
-{
- InsetError *inset = (InsetError*) data;
- if (inset->form) {
- fl_hide_form(inset->form);
- fl_free_form(inset->form);
- inset->form = 0;
- }
-}
-
-void InsetError::Edit(int, int)
-{
- if (!form) {
- FL_OBJECT *obj;
- form = fl_bgn_form(FL_UP_BOX,400,240);
- strobj = fl_add_box(FL_FRAME_BOX,10,10,380,180,"");
- fl_set_object_color(strobj,FL_MCOL,FL_MCOL);
- fl_set_object_gravity(strobj, FL_NorthWest, FL_SouthEast);
- obj = fl_add_button(FL_RETURN_BUTTON,140,200,120,30,_("Close"));
- fl_set_object_callback(obj, CloseErrorCB, (long)this);
- fl_set_object_gravity(obj, FL_South, FL_South);
- fl_set_object_resize(obj, FL_RESIZE_NONE);
- fl_end_form();
- fl_set_form_atclose(form, CancelCloseBoxCB, 0);
- }
- fl_set_object_label(strobj, contents.c_str());
- if (form->visible) {
- fl_raise_form(form);
- } else {
- fl_show_form(form,FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
- _("LaTeX Error"));
- }
+ // Draw as "Error" in a framed box
+ x += 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);
}
-Inset* InsetError::Clone()
+string const InsetError::editMessage() const
{
- InsetError *result = new InsetError(contents);
- return result;
+ return _("Opened error");
}