]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbutton.C
fix #832
[lyx.git] / src / insets / insetbutton.C
index 327ab0b6566cd97f74cccae7a4c3f6e4c00f160b..809f49cf776ce387e2c4ae3e62d63d7af146a156 100644 (file)
@@ -1,88 +1,94 @@
-/* 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 "BufferView.h"
-#include "Painter.h"
+#include "funcrequest.h"
+#include "frontends/LyXView.h"
+#include "frontends/Painter.h"
+#include "support/LAssert.h"
+#include "lyxfont.h"
+#include "frontends/font_metrics.h"
 
 using std::ostream;
 using std::endl;
 
 
-InsetButton::InsetButton()
+int InsetButton::ascent(BufferView * bv, LyXFont const &) const
 {
-}
+       lyx::Assert(bv);
 
-int InsetButton::ascent(Painter & pain, LyXFont const &) const
-{
        LyXFont font(LyXFont::ALL_SANE);
        font.decSize();
-       
-       int width, ascent, descent;
-        string s = getScreenLabel();
-       
-        if (Editable()) {
-               pain.buttonText(0, 0, s, font,
-                               false, width, ascent, descent);
+
+       int width;
+       int ascent;
+       int descent;
+       string const s = getScreenLabel(bv->buffer());
+
+       if (editable()) {
+               font_metrics::buttonText(s, font, width, ascent, descent);
        } else {
-               pain.rectText(0, 0, s, font,
-                             LColor::commandbg, LColor::commandframe,
-                             false, width, ascent, descent);
+               font_metrics::rectText(s, font, width, ascent, descent);
        }
+
        return ascent;
 }
 
 
-int InsetButton::descent(Painter & pain, LyXFont const &) const
+int InsetButton::descent(BufferView * bv, LyXFont const &) const
 {
+       lyx::Assert(bv);
+
        LyXFont font(LyXFont::ALL_SANE);
        font.decSize();
-       
-       int width, ascent, descent;
-        string s = getScreenLabel();
-       
-        if (Editable()) {
-               pain.buttonText(0, 0, s, font,
-                               false, width, ascent, descent);
+
+       int width;
+       int ascent;
+       int descent;
+       string const s = getScreenLabel(bv->buffer());
+
+       if (editable()) {
+               font_metrics::buttonText(s, font, width, ascent, descent);
        } else {
-               pain.rectText(0, 0, s, font,
-                             LColor::commandbg, LColor::commandframe,
-                             false, width, ascent, descent);
+               font_metrics::rectText(s, font, width, ascent, descent);
        }
+
        return descent;
 }
 
 
-int InsetButton::width(Painter & pain, LyXFont const &) const
+int InsetButton::width(BufferView * bv, LyXFont const &) const
 {
+       lyx::Assert(bv);
+
        LyXFont font(LyXFont::ALL_SANE);
        font.decSize();
-       
-       int width, ascent, descent;
-        string s = getScreenLabel();
-       
-        if (Editable()) {
-               pain.buttonText(0, 0, s, font,
-                               false, width, ascent, descent);
+
+       int width;
+       int ascent;
+       int descent;
+       string const s = getScreenLabel(bv->buffer());
+
+       if (editable()) {
+               font_metrics::buttonText(s, font, width, ascent, descent);
        } else {
-               pain.rectText(0, 0, s, font,
-                             LColor::commandbg, LColor::commandframe,
-                             false, width, ascent, descent);
+               font_metrics::rectText(s, font, width, ascent, descent);
        }
+
        return width + 4;
 }
 
@@ -90,21 +96,41 @@ int InsetButton::width(Painter & pain, LyXFont const &) const
 void InsetButton::draw(BufferView * bv, LyXFont 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);
        font.setColor(LColor::command).decSize();
 
-       int width;
-       string s = getScreenLabel();
+       string const s = getScreenLabel(bv->buffer());
 
-       if (Editable()) {
-               pain.buttonText(int(x)+2, baseline, s, font, true, width);
+       if (editable()) {
+               pain.buttonText(int(x) + 2, baseline, s, font);
        } else {
-               pain.rectText(int(x)+2, baseline, s, font,
-                             LColor::commandbg, LColor::commandframe,
-                             true, width);
+               pain.rectText(int(x) + 2, baseline, s, font,
+                             LColor::commandbg, LColor::commandframe);
        }
 
-       x += width + 4;
+       x += width(bv, font);
+}
+
+
+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();
+}
+
+
+dispatch_result InsetButton::localDispatch(FuncRequest const & cmd)
+{
+       return Inset::localDispatch(cmd);
 }