2000-06-12 11:27:15 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 2000-2001 The LyX Team.
|
2000-06-12 11:27:15 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetbutton.h"
|
|
|
|
#include "debug.h"
|
2000-06-21 15:07:57 +00:00
|
|
|
#include "BufferView.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include "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"
|
2001-07-24 09:12:20 +00:00
|
|
|
#include "font.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);
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
font.decSize();
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
int width;
|
|
|
|
int ascent;
|
|
|
|
int descent;
|
2001-07-28 12:24:16 +00:00
|
|
|
string const s = getScreenLabel(bv->buffer());
|
2001-07-24 09:12:20 +00:00
|
|
|
|
|
|
|
if (editable()) {
|
|
|
|
lyxfont::buttonText(s, font, width, ascent, descent);
|
|
|
|
} else {
|
|
|
|
lyxfont::rectText(s, font, width, ascent, descent);
|
|
|
|
}
|
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);
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
font.decSize();
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
int width;
|
|
|
|
int ascent;
|
|
|
|
int descent;
|
2001-07-28 12:24:16 +00:00
|
|
|
string const s = getScreenLabel(bv->buffer());
|
2001-07-24 09:12:20 +00:00
|
|
|
|
|
|
|
if (editable()) {
|
|
|
|
lyxfont::buttonText(s, font, width, ascent, descent);
|
|
|
|
} else {
|
|
|
|
lyxfont::rectText(s, font, width, ascent, descent);
|
|
|
|
}
|
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();
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
int width;
|
|
|
|
int ascent;
|
|
|
|
int descent;
|
2001-07-28 12:24:16 +00:00
|
|
|
string const s = getScreenLabel(bv->buffer());
|
2001-07-24 09:12:20 +00:00
|
|
|
|
|
|
|
if (editable()) {
|
|
|
|
lyxfont::buttonText(s, font, width, ascent, descent);
|
|
|
|
} else {
|
|
|
|
lyxfont::rectText(s, font, width, ascent, descent);
|
|
|
|
}
|
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 &,
|
2000-06-23 15:02:46 +00:00
|
|
|
int baseline, float & x, bool) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2001-05-04 10:36:36 +00:00
|
|
|
lyx::Assert(bv);
|
|
|
|
|
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
|
|
|
}
|