1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 10:58:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "inseterror.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
2000-02-10 17:53:36 +00:00
|
|
|
#include "Painter.h"
|
2000-06-21 15:07:57 +00:00
|
|
|
#include "BufferView.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
#include "font.h"
|
|
|
|
|
|
|
|
using std::ostream;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/* Error, used for the LaTeX-Error Messages */
|
|
|
|
|
|
|
|
InsetError::InsetError()
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
form = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetError::InsetError(string const & str)
|
|
|
|
: contents(str)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
form = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetError::~InsetError()
|
|
|
|
{
|
|
|
|
if (form) {
|
|
|
|
fl_hide_form(form);
|
|
|
|
fl_free_form(form);
|
1999-10-02 16:21:10 +00:00
|
|
|
form = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
int InsetError::ascent(Painter &, LyXFont const & font) const
|
|
|
|
{
|
|
|
|
LyXFont efont;
|
|
|
|
efont.setSize(font.size()).decSize();
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::maxAscent(efont) + 1;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
int InsetError::descent(Painter &, LyXFont const & font) const
|
|
|
|
{
|
|
|
|
LyXFont efont;
|
|
|
|
efont.setSize(font.size()).decSize();
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::maxDescent(efont) + 1;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
int InsetError::width(Painter &, LyXFont const & font) const
|
|
|
|
{
|
|
|
|
LyXFont efont;
|
|
|
|
efont.setSize(font.size()).decSize();
|
2000-04-04 00:19:15 +00:00
|
|
|
return 6 + lyxfont::width(_("Error"), efont);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
void InsetError::draw(BufferView * bv, LyXFont const & font,
|
2000-02-10 17:53:36 +00:00
|
|
|
int baseline, float & x) const
|
|
|
|
{
|
2000-06-21 15:07:57 +00:00
|
|
|
Painter & pain = bv->painter();
|
2000-02-10 17:53:36 +00:00
|
|
|
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,
|
|
|
|
LColor::insetbg);
|
|
|
|
pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
|
|
|
|
width(pain, font) - 2,
|
|
|
|
ascent(pain, font) + descent(pain, font) - 2,
|
|
|
|
LColor::error);
|
|
|
|
pain.text(int(x + 2), baseline, _("Error"), efont);
|
|
|
|
|
|
|
|
x += width(pain, font) - 1;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetError::Write(Buffer const *, ostream &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetError::Read(Buffer const *, LyXLex &)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetError::Latex(Buffer const *, ostream &,
|
2000-04-19 01:42:55 +00:00
|
|
|
bool /*fragile*/, bool /*fs*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetError::Ascii(Buffer const *, ostream &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetError::Linuxdoc(Buffer const *, ostream &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetError::DocBook(Buffer const *, ostream &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
bool InsetError::AutoDelete() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
Inset::EDITABLE InsetError::Editable() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-08 13:52:57 +00:00
|
|
|
return IS_EDITABLE;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (inset->form) {
|
|
|
|
fl_hide_form(inset->form);
|
|
|
|
fl_free_form(inset->form);
|
1999-10-02 16:21:10 +00:00
|
|
|
inset->form = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
1999-10-19 15:06:30 +00:00
|
|
|
// A C wrapper
|
1999-11-04 01:40:20 +00:00
|
|
|
extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
|
1999-10-19 15:06:30 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetError::CloseErrorCB(ob , data);
|
1999-10-19 15:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
char const * InsetError::EditMessage() const
|
|
|
|
{
|
|
|
|
return _("Opened error");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetError::Edit(BufferView *, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-25 14:50:26 +00:00
|
|
|
static int ow = 400, oh = 240;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!form) {
|
1999-11-04 01:40:20 +00:00
|
|
|
FL_OBJECT * obj;
|
|
|
|
form = fl_bgn_form(FL_UP_BOX, ow, oh);
|
1999-11-15 10:58:38 +00:00
|
|
|
strobj = fl_add_box(FL_FRAME_BOX, 10, 10, 380, 180, "");
|
|
|
|
fl_set_object_color(strobj, FL_MCOL, FL_MCOL);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_gravity(strobj, FL_NorthWest, FL_SouthEast);
|
1999-11-15 10:58:38 +00:00
|
|
|
obj = fl_add_button(FL_RETURN_BUTTON, 140, 200, 120, 30,
|
|
|
|
_("Close"));
|
1999-11-04 01:40:20 +00:00
|
|
|
fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
|
|
|
|
obj->u_vdata = this;
|
1999-10-25 14:50:26 +00:00
|
|
|
fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_resize(obj, FL_RESIZE_NONE);
|
|
|
|
fl_end_form();
|
1999-10-02 16:21:10 +00:00
|
|
|
fl_set_form_atclose(form, CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
fl_set_object_label(strobj, contents.c_str());
|
|
|
|
if (form->visible) {
|
|
|
|
fl_raise_form(form);
|
|
|
|
} else {
|
1999-11-15 10:58:38 +00:00
|
|
|
fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE,
|
|
|
|
FL_FULLBORDER, _("LaTeX Error"));
|
1999-10-25 14:50:26 +00:00
|
|
|
fl_set_form_minsize(form, ow, oh);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
Inset * InsetError::Clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
return new InsetError(contents);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|