]> git.lyx.org Git - lyx.git/blobdiff - src/insets/inseterror.C
Rename LatexRunParams::fragile as moving_arg.
[lyx.git] / src / insets / inseterror.C
index 493a01de20a2979daec85d26563cba7b8dfc8b43..b32c8880584f76273a2a466cc94df5f8c878ce2c 100644 (file)
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2000 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 "gettext.h"
-#include "lyx_gui_misc.h" // CancelCloseBoxCB
-#include "Painter.h"
+
 #include "BufferView.h"
-#include "font.h"
+#include "dimension.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "lyxfont.h"
 
-using std::ostream;
+#include "frontends/Dialogs.h"
+#include "frontends/font_metrics.h"
+#include "frontends/LyXView.h"
+#include "frontends/Painter.h"
 
-/* Error, used for the LaTeX-Error Messages */
+#include "support/LAssert.h"
 
-InsetError::InsetError()
-{
-       form = 0;
-}
+using std::ostream;
 
 
-InsetError::InsetError(string const & str)
+InsetError::InsetError(string const & str, bool)
        : contents(str)
-{
-       form = 0;
-}
+{}
 
 
 InsetError::~InsetError()
 {
-       if (form) {
-               fl_hide_form(form);
-               fl_free_form(form);
-               form = 0;
-       }
+       Dialogs::hide("error", this);
 }
 
 
-int InsetError::ascent(Painter &, LyXFont const & font) const
+dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
 {
-       LyXFont efont;
-       efont.setSize(font.size()).decSize();
-       return lyxfont::maxAscent(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;
 
-int InsetError::descent(Painter &, LyXFont const & font) const
-{
-       LyXFont efont;
-       efont.setSize(font.size()).decSize();
-       return lyxfont::maxDescent(efont) + 1;
+       default:
+               return Inset::localDispatch(cmd);
+       }
 }
 
 
-int InsetError::width(Painter &, LyXFont const & font) const
+void InsetError::dimension(BufferView *, LyXFont const & font,
+       Dimension & dim) const
 {
        LyXFont efont;
        efont.setSize(font.size()).decSize();
-       return 6 + lyxfont::width(_("Error"), efont);
+       dim.a = font_metrics::maxAscent(efont) + 1;
+       dim.d = font_metrics::maxDescent(efont) + 1;
+       dim.w = 6 + font_metrics::width(_("Error"), efont);
 }
 
 
 void InsetError::draw(BufferView * bv, LyXFont const & font,
-                     int baseline, float & x, bool) const
+                     int baseline, float & x) const
 {
+       lyx::Assert(bv);
+       cache(bv);
+
        Painter & pain = bv->painter();
        LyXFont efont;
        efont.setSize(font.size()).decSize();
        efont.setColor(LColor::error);
-   
+
        // Draw as "Error" in a framed box
        x += 1;
-       pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
-                         width(pain, font) - 2,
-                         ascent(pain, font) + descent(pain, font) - 2,
+       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(pain, font) + 1,
-                      width(pain, font) - 2,
-                      ascent(pain, font) + descent(pain, font) - 2,
+       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(pain, font) - 1;
-}
-
-
-void InsetError::Write(Buffer const *, ostream &) const
-{
-}
-
-
-void InsetError::Read(Buffer const *, LyXLex &)
-{
-}
-
-
-int InsetError::Latex(Buffer const *, ostream &,
-                     bool /*fragile*/, bool /*fs*/) const
-{
-       return 0;
-}
-
-
-int InsetError::Ascii(Buffer const *, ostream &) const
-{
-       return 0;
-}
-
-
-int InsetError::Linuxdoc(Buffer const *, ostream &) const
-{
-       return 0;
-}
-
-
-int InsetError::DocBook(Buffer const *, ostream &) const
-{
-       return 0;
-}
-
-
-bool InsetError::AutoDelete() const
-{
-       return true;
-}
-
-
-Inset::EDITABLE InsetError::Editable() const
-{
-       return IS_EDITABLE;
-}
-
-
-void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
-{
-       InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
-       if (inset->form) {
-               fl_hide_form(inset->form);
-               fl_free_form(inset->form);
-               inset->form = 0;
-       }
+       x +=  width(bv, font) - 1;
 }
 
 
-// A C wrapper
-extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
-{
-        InsetError::CloseErrorCB(ob , data);
-}
-
-
-char const * InsetError::EditMessage() const 
+string const InsetError::editMessage() const
 {
        return _("Opened error");
 }
-
-
-void InsetError::Edit(BufferView *, int, int, unsigned int)
-{
-       static int ow = 400, oh = 240;
-
-       if (!form) {
-               FL_OBJECT * obj;
-               form = fl_bgn_form(FL_UP_BOX, ow, oh);
-               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, C_InsetError_CloseErrorCB, 0);
-               obj->u_vdata = this;
-               fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
-               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"));
-               fl_set_form_minsize(form, ow, oh);
-       }
-}
-
-
-Inset * InsetError::Clone() const
-{
-       return new InsetError(contents);
-}