-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 2000-2001 The LyX Team.
+/**
+ * \file insetbutton.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ====================================================== */
+ * \author Asger Alstrup Nielsen
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS
+ */
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
#include "insetbutton.h"
#include "debug.h"
#include "BufferView.h"
-#include "Painter.h"
+#include "frontends/LyXView.h"
+#include "frontends/Painter.h"
#include "support/LAssert.h"
#include "lyxfont.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
using std::ostream;
using std::endl;
int InsetButton::ascent(BufferView * bv, LyXFont const &) const
{
lyx::Assert(bv);
-
+
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
-
+
int width;
int ascent;
int descent;
- string const s = getScreenLabel(bv->buffer());
+ string const s = getScreenLabel(bv->buffer());
-#if 0
- if (editable()) {
- bv->painter().buttonText(0, 0, s, font,
- false, width, ascent, descent);
- } else {
- bv->painter().rectText(0, 0, s, font,
- LColor::commandbg, LColor::commandframe,
- false, width, ascent, descent);
- }
-#else
- if (editable()) {
- lyxfont::buttonText(s, font, width, ascent, descent);
+ if (editable()) {
+ font_metrics::buttonText(s, font, width, ascent, descent);
} else {
- lyxfont::rectText(s, font, width, ascent, descent);
+ font_metrics::rectText(s, font, width, ascent, descent);
}
-#endif
+
return ascent;
}
int InsetButton::descent(BufferView * bv, LyXFont const &) const
{
lyx::Assert(bv);
-
+
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
-
+
int width;
int ascent;
int descent;
- string const s = getScreenLabel(bv->buffer());
+ string const s = getScreenLabel(bv->buffer());
-#if 0
- if (editable()) {
- bv->painter().buttonText(0, 0, s, font,
- false, width, ascent, descent);
- } else {
- bv->painter().rectText(0, 0, s, font,
- LColor::commandbg, LColor::commandframe,
- false, width, ascent, descent);
- }
-#else
- if (editable()) {
- lyxfont::buttonText(s, font, width, ascent, descent);
+ if (editable()) {
+ font_metrics::buttonText(s, font, width, ascent, descent);
} else {
- lyxfont::rectText(s, font, width, ascent, descent);
+ font_metrics::rectText(s, font, width, ascent, descent);
}
-#endif
+
return descent;
}
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
-
+
int width;
int ascent;
int descent;
- string const s = getScreenLabel(bv->buffer());
+ string const s = getScreenLabel(bv->buffer());
-#if 0
- if (editable()) {
- bv->painter().buttonText(0, 0, s, font,
- false, width, ascent, descent);
- } else {
- bv->painter().rectText(0, 0, s, font,
- LColor::commandbg, LColor::commandframe,
- false, width, ascent, descent);
- }
-#else
- if (editable()) {
- lyxfont::buttonText(s, font, width, ascent, descent);
+ if (editable()) {
+ font_metrics::buttonText(s, font, width, ascent, descent);
} else {
- lyxfont::rectText(s, font, width, ascent, descent);
+ font_metrics::rectText(s, font, width, ascent, descent);
}
-#endif
+
return width + 4;
}
void InsetButton::draw(BufferView * bv, LyXFont const &,
- int baseline, float & x, bool) const
+ int baseline, float & x) const
{
lyx::Assert(bv);
-
+ cache(bv);
+
Painter & pain = bv->painter();
// Draw it as a box with the LaTeX text
LyXFont font(LyXFont::ALL_SANE);
string const s = getScreenLabel(bv->buffer());
-#if 0
- int width;
- if (editable()) {
- pain.buttonText(int(x) + 2, baseline, s, font, true, width);
- } else {
- pain.rectText(int(x) + 2, baseline, s, font,
- LColor::commandbg, LColor::commandframe,
- true, width);
- }
-#else
if (editable()) {
pain.buttonText(int(x) + 2, baseline, s, font);
} else {
pain.rectText(int(x) + 2, baseline, s, font,
LColor::commandbg, LColor::commandframe);
}
-#endif
-#if 0
- x += width + 4;
-#else
x += width(bv, font);
-#endif
+}
+
+
+void InsetButton::cache(BufferView * bv) const
+{
+ view_ = bv->owner()->view();
+}
+
+
+#warning Shouldnt this really return a shared_ptr<BufferView>? (Lgb)
+BufferView * InsetButton::view() const
+{
+ return view_.lock().get();
}