2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetbutton.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 Asger Alstrup Nielsen
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \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
|
|
|
|
|
*/
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "insetbutton.h"
|
|
|
|
|
#include "debug.h"
|
2000-06-21 15:07:57 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-02-25 14:51:38 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "lyxfont.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
|
int InsetButton::ascent(BufferView * bv, LyXFont const &) const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-05-04 10:36:36 +00:00
|
|
|
|
lyx::Assert(bv);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
int width;
|
|
|
|
|
int ascent;
|
|
|
|
|
int descent;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
string const s = getScreenLabel(bv->buffer());
|
2001-07-24 09:12:20 +00:00
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
if (editable()) {
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::buttonText(s, font, width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
|
} else {
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::rectText(s, font, width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
|
}
|
2001-07-30 11:56:00 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return ascent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
|
int InsetButton::descent(BufferView * bv, LyXFont const &) const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-05-04 10:36:36 +00:00
|
|
|
|
lyx::Assert(bv);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
int width;
|
|
|
|
|
int ascent;
|
|
|
|
|
int descent;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
string const s = getScreenLabel(bv->buffer());
|
2001-07-24 09:12:20 +00:00
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
if (editable()) {
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::buttonText(s, font, width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
|
} else {
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::rectText(s, font, width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
|
}
|
2001-07-30 11:56:00 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return descent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
|
int InsetButton::width(BufferView * bv, LyXFont const &) const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-05-04 10:36:36 +00:00
|
|
|
|
lyx::Assert(bv);
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
int width;
|
|
|
|
|
int ascent;
|
|
|
|
|
int descent;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
string const s = getScreenLabel(bv->buffer());
|
2001-07-24 09:12:20 +00:00
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
if (editable()) {
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::buttonText(s, font, width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
|
} else {
|
2002-05-24 14:34:32 +00:00
|
|
|
|
font_metrics::rectText(s, font, width, ascent, descent);
|
2001-07-24 09:12:20 +00:00
|
|
|
|
}
|
2001-07-30 11:56:00 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return width + 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
void InsetButton::draw(BufferView * bv, LyXFont const &,
|
2003-03-17 01:34:36 +00:00
|
|
|
|
int baseline, float & x) const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-05-04 10:36:36 +00:00
|
|
|
|
lyx::Assert(bv);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
cache(bv);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
Painter & pain = bv->painter();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
// Draw it as a box with the LaTeX text
|
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.setColor(LColor::command).decSize();
|
|
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
|
string const s = getScreenLabel(bv->buffer());
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2001-07-24 09:12:20 +00:00
|
|
|
|
if (editable()) {
|
|
|
|
|
pain.buttonText(int(x) + 2, baseline, s, font);
|
|
|
|
|
} else {
|
|
|
|
|
pain.rectText(int(x) + 2, baseline, s, font,
|
|
|
|
|
LColor::commandbg, LColor::commandframe);
|
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2001-07-24 09:12:20 +00:00
|
|
|
|
x += width(bv, font);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetButton::cache(BufferView * bv) const
|
|
|
|
|
{
|
|
|
|
|
view_ = bv->owner()->view();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-03 15:59:08 +00:00
|
|
|
|
#warning Shouldnt this really return a shared_ptr<BufferView>? (Lgb)
|
2003-02-25 14:51:38 +00:00
|
|
|
|
BufferView * InsetButton::view() const
|
|
|
|
|
{
|
2003-03-03 15:59:08 +00:00
|
|
|
|
return view_.lock().get();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|