2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file inseterror.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
#include "BufferView.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2001-11-29 17:12:21 +00:00
|
|
|
|
#include "lyxfont.h"
|
2000-09-22 15:09:51 +00:00
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "inseterror.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2000-09-22 15:09:51 +00:00
|
|
|
|
#include "frontends/Dialogs.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
|
|
|
|
using std::ostream;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/* Error, used for the LaTeX-Error Messages */
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
InsetError::InsetError(string const & str, bool)
|
2000-09-22 15:09:51 +00:00
|
|
|
|
: contents(str)
|
2000-07-15 23:51:46 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
|
int InsetError::ascent(BufferView *, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
LyXFont efont;
|
|
|
|
|
efont.setSize(font.size()).decSize();
|
2002-05-24 14:34:32 +00:00
|
|
|
|
return font_metrics::maxAscent(efont) + 1;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
|
int InsetError::descent(BufferView *, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
LyXFont efont;
|
|
|
|
|
efont.setSize(font.size()).decSize();
|
2002-05-24 14:34:32 +00:00
|
|
|
|
return font_metrics::maxDescent(efont) + 1;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
|
int InsetError::width(BufferView *, LyXFont const & font) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
|
|
|
|
LyXFont efont;
|
|
|
|
|
efont.setSize(font.size()).decSize();
|
2002-05-24 14:34:32 +00:00
|
|
|
|
return 6 + font_metrics::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-06-23 15:02:46 +00:00
|
|
|
|
int baseline, float & x, bool) const
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
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);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
// Draw as "Error" in a framed box
|
|
|
|
|
x += 1;
|
2000-07-05 14:57:48 +00:00
|
|
|
|
pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
|
|
|
|
|
width(bv, font) - 2,
|
|
|
|
|
ascent(bv, font) + descent(bv, font) - 2,
|
2000-02-10 17:53:36 +00:00
|
|
|
|
LColor::insetbg);
|
2000-07-05 14:57:48 +00:00
|
|
|
|
pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
|
|
|
|
|
width(bv, font) - 2,
|
|
|
|
|
ascent(bv, font) + descent(bv, font) - 2,
|
2000-02-10 17:53:36 +00:00
|
|
|
|
LColor::error);
|
|
|
|
|
pain.text(int(x + 2), baseline, _("Error"), efont);
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
|
x += width(bv, font) - 1;
|
2000-02-10 17:53:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
string const InsetError::editMessage() const
|
2000-04-04 00:19:15 +00:00
|
|
|
|
{
|
|
|
|
|
return _("Opened error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
|
void InsetError::edit(BufferView * bv, int, int, mouse_button::state)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-08-13 14:40:38 +00:00
|
|
|
|
bv->owner()->getDialogs().showError(this);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetError::edit(BufferView * bv, bool)
|
|
|
|
|
{
|
2002-05-26 17:33:14 +00:00
|
|
|
|
edit(bv, 0, 0, mouse_button::none);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|