-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 2000 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 "dimension.h"
#include "BufferView.h"
-#include "Painter.h"
+#include "funcrequest.h"
+#include "frontends/LyXView.h"
+#include "frontends/Painter.h"
+#include "support/LAssert.h"
+#include "lyxfont.h"
+#include "metricsinfo.h"
+#include "frontends/font_metrics.h"
using std::ostream;
using std::endl;
-int InsetButton::ascent(BufferView * bv, LyXFont const &) const
+void InsetButton::metrics(MetricsInfo & mi, Dimension & dim) const
{
+ lyx::Assert(mi.base.bv);
+
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
-
- int width, ascent, descent;
- string s = getScreenLabel();
-
- 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);
- }
- return ascent;
+
+ string const s = getScreenLabel(mi.base.bv->buffer());
+
+ if (editable())
+ font_metrics::buttonText(s, font, dim.wid, dim.asc, dim.des);
+ else
+ font_metrics::rectText(s, font, dim.wid, dim.asc, dim.des);
+
+ dim.wid += 4;
}
-int InsetButton::descent(BufferView * bv, LyXFont const &) const
+void InsetButton::draw(PainterInfo & pi, int x, int y) const
{
+ lyx::Assert(pi.base.bv);
+ cache(pi.base.bv);
+
+ // Draw it as a box with the LaTeX text
LyXFont font(LyXFont::ALL_SANE);
- font.decSize();
-
- int width, ascent, descent;
- string s = getScreenLabel();
-
- if (Editable()) {
- bv->painter().buttonText(0, 0, s, font,
- false, width, ascent, descent);
+ font.setColor(LColor::command).decSize();
+
+ string const s = getScreenLabel(pi.base.bv->buffer());
+
+ if (editable()) {
+ pi.pain.buttonText(x + 2, y, s, font);
} else {
- bv->painter().rectText(0, 0, s, font,
- LColor::commandbg, LColor::commandframe,
- false, width, ascent, descent);
+ pi.pain.rectText(x + 2, y, s, font,
+ LColor::commandbg, LColor::commandframe);
}
- return descent;
}
-int InsetButton::width(BufferView * bv, LyXFont const &) const
+void InsetButton::cache(BufferView * bv) const
{
- LyXFont font(LyXFont::ALL_SANE);
- font.decSize();
-
- int width, ascent, descent;
- string s = getScreenLabel();
- if (!bv)
- return s.length();
-
- 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);
- }
- return width + 4;
+ view_ = bv->owner()->view();
}
-void InsetButton::draw(BufferView * bv, LyXFont const &,
- int baseline, float & x, bool) const
+#warning Shouldnt this really return a shared_ptr<BufferView>? (Lgb)
+BufferView * InsetButton::view() const
{
- Painter & pain = bv->painter();
- // Draw it as a box with the LaTeX text
- LyXFont font(LyXFont::ALL_SANE);
- font.setColor(LColor::command).decSize();
-
- int width;
- string s = getScreenLabel();
+ return view_.lock().get();
+}
- 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);
- }
- x += width + 4;
+dispatch_result InsetButton::localDispatch(FuncRequest const & cmd)
+{
+ return Inset::localDispatch(cmd);
}