]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbutton.C
Rename LatexRunParams::fragile as moving_arg.
[lyx.git] / src / insets / insetbutton.C
index eef13251ef0988e9704ec28d61ffd6ed8bf4d480..7367a638ac5372569847a62689136c5ac1d14b7d 100644 (file)
@@ -1,22 +1,23 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file insetbutton.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Asger Alstrup Nielsen
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
  *
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 2000-2001 The LyX Team.
- *
- * ====================================================== */
+ * 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 "funcrequest.h"
+#include "frontends/LyXView.h"
 #include "frontends/Painter.h"
 #include "support/LAssert.h"
 #include "lyxfont.h"
@@ -26,90 +27,63 @@ using std::ostream;
 using std::endl;
 
 
-int InsetButton::ascent(BufferView * bv, LyXFont const &) const
+void InsetButton::dimension(BufferView * bv, LyXFont const &,
+       Dimension & dim) const
 {
        lyx::Assert(bv);
 
        LyXFont font(LyXFont::ALL_SANE);
        font.decSize();
 
-       int width;
-       int ascent;
-       int descent;
        string const s = getScreenLabel(bv->buffer());
 
-        if (editable()) {
-               font_metrics::buttonText(s, font, width, ascent, descent);
-       } else {
-               font_metrics::rectText(s, font, width, ascent, descent);
-       }
+       if (editable())
+               font_metrics::buttonText(s, font, dim.w, dim.a, dim.d);
+       else
+               font_metrics::rectText(s, font, dim.w, dim.a, dim.d);
 
-       return ascent;
+       dim.w += 4;
 }
 
 
-int InsetButton::descent(BufferView * bv, 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.decSize();
+       font.setColor(LColor::command).decSize();
 
-       int width;
-       int ascent;
-       int descent;
        string const s = getScreenLabel(bv->buffer());
 
-        if (editable()) {
-               font_metrics::buttonText(s, font, width, ascent, descent);
+       if (editable()) {
+               pain.buttonText(int(x) + 2, baseline, s, font);
        } else {
-               font_metrics::rectText(s, font, width, ascent, descent);
+               pain.rectText(int(x) + 2, baseline, s, font,
+                             LColor::commandbg, LColor::commandframe);
        }
 
-       return descent;
+       x += width(bv, font);
 }
 
 
-int InsetButton::width(BufferView * bv, LyXFont const &) const
+void InsetButton::cache(BufferView * bv) const
 {
-       lyx::Assert(bv);
-
-       LyXFont font(LyXFont::ALL_SANE);
-       font.decSize();
-
-       int width;
-       int ascent;
-       int descent;
-       string const s = getScreenLabel(bv->buffer());
-
-        if (editable()) {
-               font_metrics::buttonText(s, font, width, ascent, descent);
-       } else {
-               font_metrics::rectText(s, font, 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
 {
-       lyx::Assert(bv);
-
-       Painter & pain = bv->painter();
-       // Draw it as a box with the LaTeX text
-       LyXFont font(LyXFont::ALL_SANE);
-       font.setColor(LColor::command).decSize();
-
-       string const s = getScreenLabel(bv->buffer());
+       return view_.lock().get();
+}
 
-       if (editable()) {
-               pain.buttonText(int(x) + 2, baseline, s, font);
-       } else {
-               pain.rectText(int(x) + 2, baseline, s, font,
-                             LColor::commandbg, LColor::commandframe);
-       }
 
-       x += width(bv, font);
+dispatch_result InsetButton::localDispatch(FuncRequest const & cmd)
+{
+       return Inset::localDispatch(cmd);
 }