]> git.lyx.org Git - lyx.git/commitdiff
Replace InsetButton and ButtonInset with a ButtonRenderer that can be
authorAngus Leeming <leeming@lyx.org>
Thu, 12 Jun 2003 08:52:36 +0000 (08:52 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 12 Jun 2003 08:52:36 +0000 (08:52 +0000)
included as a member variable.
Enable InsetExternal to choose its renderer dynamically.
diffstat tells me
25 files changed, 627 insertions(+), 646 deletions(-)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7160 a592a061-630c-0410-9148-cb99ea01b6c8

25 files changed:
po/POTFILES.in
src/insets/ChangeLog
src/insets/Makefile.am
src/insets/graphicinset.C [deleted file]
src/insets/graphicinset.h [deleted file]
src/insets/insetbutton.C [deleted file]
src/insets/insetbutton.h [deleted file]
src/insets/insetcommand.C
src/insets/insetcommand.h
src/insets/insetexternal.C
src/insets/insetexternal.h
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/renderers.C [new file with mode: 0644]
src/insets/renderers.h [new file with mode: 0644]
src/mathed/ChangeLog
src/mathed/Makefile.am
src/mathed/button_inset.C [deleted file]
src/mathed/button_inset.h [deleted file]
src/mathed/command_inset.C
src/mathed/command_inset.h
src/mathed/ref_inset.C
src/mathed/ref_inset.h

index 62f9f0357c587f321b3f0d8d8412e6bf8ebd1e42..0a6686e7f24ccfd849919cd8f4e5784e542cadb0 100644 (file)
@@ -132,7 +132,6 @@ src/frontends/xforms/xformsBC.h
 src/frontends/xforms/xforms_helpers.C
 src/gettext.h
 src/importer.C
-src/insets/graphicinset.C
 src/insets/inset.C
 src/insets/insetbibtex.C
 src/insets/insetcaption.C
@@ -158,6 +157,7 @@ src/insets/insettheorem.C
 src/insets/insettoc.C
 src/insets/inseturl.C
 src/insets/insetwrap.C
+src/insets/renderers.C
 src/ispell.C
 src/kbsequence.C
 src/lengthcommon.C
index f563ef09d538602e4d3d925b864e67b6079de690..131cf3f02a6f5f6684bd4959b2d705a118d88a99 100644 (file)
@@ -1,3 +1,28 @@
+2003-06-11  Angus Leeming  <leeming@lyx.org>
+
+       * Makefile.am: remove graphicinset.[Ch], insetbutton.[Ch].
+       Add renderers.[Ch].
+
+       * insetbutton.[Ch]: removed.
+       * graphicinset.[Ch]: renamed as renderers.[Ch].
+
+       * renderers.[Ch]: new files. Rename GraphicsInset as GraphicsRenderer.
+       Create a new class ButtonRenderer using the InsetButton::metrics() and
+       draw() functions.
+       Derive both from a common RenderedInset base class.
+
+       * insetcommand.[Ch]:
+       * insetinclude.[Ch]: derive from Inset, not InsetButton.
+       Give it a ButtonRenderer member variable. Use it.
+       Give the classes working copy c-tors.
+       No longer derive from boost::noncopyable.
+
+       * insetexternal.[Ch]: enable the inset to choose dynamically whether to
+       display its contents as a button or as a graphic.
+
+       * insetgraphic.[Ch]: changes due to the change in name GraphicInset ->
+       GraphicRenderer.
+
 2003-06-11  Angus Leeming  <leeming@lyx.org>
 
        * insetcite.C (localDispatch): reformat.
index 2810f338171d6a63b26b9e0ebbe347137f91ad7b..13ec16c0fbfafaac5e11ed605a5ee9d2ca5fd7de 100644 (file)
@@ -17,8 +17,8 @@ libinsets_la_SOURCES = \
        mailinset.h \
        ExternalTemplate.C \
        ExternalTemplate.h \
-       graphicinset.C \
-       graphicinset.h \
+       renderers.C \
+       renderers.h \
        inset.C \
        inset.h \
        insetbase.h \
@@ -27,8 +27,6 @@ libinsets_la_SOURCES = \
        insetbibitem.h \
        insetbibtex.C \
        insetbibtex.h \
-       insetbutton.C \
-       insetbutton.h \
        insetcaption.C \
        insetcaption.h \
        insetcite.C \
diff --git a/src/insets/graphicinset.C b/src/insets/graphicinset.C
deleted file mode 100644 (file)
index 7d80bfe..0000000
+++ /dev/null
@@ -1,274 +0,0 @@
-/**
- * \file graphicinset.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS
- */
-
-#include <config.h>
-
-#include "insets/graphicinset.h"
-
-#include "buffer.h"
-#include "BufferView.h"
-#include "gettext.h"
-#include "metricsinfo.h"
-
-#include "frontends/font_metrics.h"
-#include "frontends/LyXView.h"
-#include "frontends/Painter.h"
-
-#include "graphics/GraphicsImage.h"
-
-#include "support/filetools.h"
-
-
-GraphicInset::GraphicInset()
-       : checksum_(0)
-{}
-
-
-GraphicInset::GraphicInset(GraphicInset const & other)
-       : loader_(other.loader_),
-         params_(other.params_),
-         nodisplay_message_(other.nodisplay_message_),
-         checksum_(0)
-{}
-
-
-void GraphicInset::update(grfx::Params const & params)
-{
-       params_ = params;
-
-       if (!params_.filename.empty()) {
-               lyx::Assert(AbsolutePath(params_.filename));
-               loader_.reset(params_.filename, params_);
-       }
-}
-
-
-bool GraphicInset::hasFileChanged() const
-{
-       unsigned long const new_checksum = loader_.checksum();
-       bool const file_has_changed = checksum_ != new_checksum;
-       if (file_has_changed)
-               checksum_ = new_checksum;
-       return file_has_changed;
-}
-
-
-BufferView * GraphicInset::view() const
-{
-       return view_.lock().get();
-}
-
-
-boost::signals::connection GraphicInset::connect(slot_type const & slot) const
-{
-       return loader_.connect(slot);
-}
-
-
-void GraphicInset::setNoDisplayMessage(string const & str)
-{
-       nodisplay_message_ = str;
-}
-
-
-string const GraphicInset::statusMessage() const
-{
-       switch (loader_.status()) {
-               case grfx::WaitingToLoad:
-                       return _("Not shown.");
-               case grfx::Loading:
-                       return _("Loading...");
-               case grfx::Converting:
-                       return _("Converting to loadable format...");
-               case grfx::Loaded:
-                       return _("Loaded into memory. Must now generate pixmap.");
-               case grfx::ScalingEtc:
-                       return _("Scaling etc...");
-               case grfx::Ready:
-                       return _("Ready to display");
-               case grfx::ErrorNoFile:
-                       return _("No file found!");
-               case grfx::ErrorConverting:
-                       return _("Error converting to loadable format");
-               case grfx::ErrorLoading:
-                       return _("Error loading file into memory");
-               case grfx::ErrorGeneratingPixmap:
-                       return _("Error generating the pixmap");
-               case grfx::ErrorUnknown:
-                       return _("No image");
-       }
-       return string();
-}
-
-
-GraphicInset::DisplayType GraphicInset::displayType() const
-{
-       if (params_.display == grfx::NoDisplay && !nodisplay_message_.empty())
-               return NODISPLAY_MESSAGE;
-
-       if (!loader_.image() || loader_.status() != grfx::Ready)
-               return STATUS_MESSAGE;
-
-       return loader_.image()->isDrawable() ? IMAGE : STATUS_MESSAGE;
-}
-
-
-void GraphicInset::metrics(MetricsInfo & mi, Dimension & dim) const
-{
-       DisplayType type = displayType();
-
-       dim.asc = (type == IMAGE) ? loader_.image()->getHeight() : 50;
-       dim.des = 0;
-
-       switch (type) {
-       case IMAGE:
-               dim.wid = loader_.image()->getWidth() +
-                       2 * Inset::TEXT_TO_INSET_OFFSET;
-               break;
-
-       case STATUS_MESSAGE:
-       {
-               int font_width = 0;
-
-               LyXFont msgFont(mi.base.font);
-               msgFont.setFamily(LyXFont::SANS_FAMILY);
-
-               string const justname = OnlyFilename(params_.filename);
-               if (!justname.empty()) {
-                       msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
-                       font_width = font_metrics::width(justname, msgFont);
-               }
-
-               string const msg = statusMessage();
-               if (!msg.empty()) {
-                       msgFont.setSize(LyXFont::SIZE_TINY);
-                       font_width = std::max(font_width,
-                                             font_metrics::width(msg, msgFont));
-               }
-
-               dim.wid = std::max(50, font_width + 15);
-               break;
-       }
-
-       case NODISPLAY_MESSAGE:
-       {
-               int font_width = 0;
-
-               LyXFont msgFont(mi.base.font);
-               msgFont.setFamily(LyXFont::SANS_FAMILY);
-               msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
-               font_width = font_metrics::width(nodisplay_message_, msgFont);
-
-               dim.wid = std::max(50, font_width + 15);
-               break;
-       }
-       }
-
-       dim_ = dim;
-}
-
-
-void GraphicInset::draw(PainterInfo & pi, int x, int y) const
-{
-       if (pi.base.bv)
-               view_ = pi.base.bv->owner()->view();
-
-#if 0
-       // Comment this out and see if anything goes wrong.
-       // The explanation for why it _was_ needed once upon a time is below.
-
-       // MakeAbsPath returns filename_ unchanged if it is absolute
-       // already.
-       string const file_with_path =
-               MakeAbsPath(params_.filename, view_->buffer()->filePath());
-
-       // A 'paste' operation creates a new inset with the correct filepath,
-       // but then the 'old' inset stored in the 'copy' operation is actually
-       // added to the buffer.
-
-       // Thus, pasting a graphic into a new buffer with different
-       // buffer->filePath() will result in the image being displayed in LyX even
-       // though the relative path now points at nothing at all. Subsequent
-       // loading of the file into LyX will therefore fail.
-
-       // We should ensure that the filepath is correct.
-       if (file_with_path != loader_.filename()) {
-               params_.filename = file_with_path;
-               update(params_);
-       }
-#endif
-
-       if (params_.display != grfx::NoDisplay &&
-           loader_.status() == grfx::WaitingToLoad)
-               loader_.startLoading();
-
-       if (params_.display != grfx::NoDisplay && !loader_.monitoring())
-               loader_.startMonitoring();
-
-       // This will draw the graphics. If the graphics has not been loaded yet,
-       // we draw just a rectangle.
-
-       switch (displayType()) {
-       case IMAGE: 
-       {
-               pi.pain.image(x + Inset::TEXT_TO_INSET_OFFSET,
-                             y - dim_.asc,
-                             dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET,
-                             dim_.asc + dim_.des,
-                             *loader_.image());
-               break;
-       }
-
-       case STATUS_MESSAGE:
-       {
-               pi.pain.rectangle(x + Inset::TEXT_TO_INSET_OFFSET,
-                                 y - dim_.asc,
-                                 dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET,
-                                 dim_.asc + dim_.des);
-
-               // Print the file name.
-               LyXFont msgFont = pi.base.font;
-               msgFont.setFamily(LyXFont::SANS_FAMILY);
-               string const justname = OnlyFilename(params_.filename);
-
-               if (!justname.empty()) {
-                       msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
-                       pi.pain.text(x + Inset::TEXT_TO_INSET_OFFSET + 6,
-                                  y - font_metrics::maxAscent(msgFont) - 4,
-                                  justname, msgFont);
-               }
-
-               // Print the message.
-               string const msg = statusMessage();
-               if (!msg.empty()) {
-                       msgFont.setSize(LyXFont::SIZE_TINY);
-                       pi.pain.text(x + Inset::TEXT_TO_INSET_OFFSET + 6,
-                                    y - 4, msg, msgFont);
-               }
-               break;
-       }
-
-       case NODISPLAY_MESSAGE:
-       {
-               pi.pain.rectangle(x + Inset::TEXT_TO_INSET_OFFSET,
-                                 y - dim_.asc,
-                                 dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET,
-                                 dim_.asc + dim_.des);
-
-               LyXFont msgFont = pi.base.font;
-               msgFont.setFamily(LyXFont::SANS_FAMILY);
-               msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
-               pi.pain.text(x + Inset::TEXT_TO_INSET_OFFSET + 6,
-                            y - font_metrics::maxAscent(msgFont) - 4,
-                            nodisplay_message_, msgFont);
-               break;
-       }
-       }
-}
diff --git a/src/insets/graphicinset.h b/src/insets/graphicinset.h
deleted file mode 100644 (file)
index cccc74b..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-// -*- C++ -*-
-/**
- * \file graphicinset.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS
- */
-
-#ifndef GRAPHICINSET_H
-#define GRAPHICINSET_H
-
-#include "dimension.h"
-
-#include "graphics/GraphicsLoader.h"
-#include "graphics/GraphicsParams.h"
-#include "graphics/GraphicsTypes.h"
-
-#include <boost/weak_ptr.hpp>
-#include <boost/signals/signal0.hpp>
-
-
-class BufferView;
-class MetricsInfo;
-class PainterInfo;
-
-
-class GraphicInset
-{
-public:
-       GraphicInset();
-       GraphicInset(GraphicInset const &);
-
-       /** Set the message that the inset will show when the
-        *  display of the graphic is deactivated.
-        *  The default is nothing, meaning that the inset will
-        *  show a message descibing the state of the image
-        *  loading process.
-        */
-       void setNoDisplayMessage(string const & msg);
-       
-       /// Refresh the info about which file to display and how to display it.
-       void update(grfx::Params const & params);
-
-       /// compute the size of the object returned in dim
-       void metrics(MetricsInfo & mi, Dimension & dim) const;
-       /// draw inset and update (xo, yo)-cache
-       void draw(PainterInfo & pi, int x, int y) const;
-
-       /// Is the stored checksum different to that of the graphics loader?
-       bool hasFileChanged() const;
-       /// An accessor function to the cached store.
-       BufferView * view() const;
-
-       /** Connect and you'll be informed when the loading status of the image
-        *  changes.
-        */
-       typedef boost::signal0<void>::slot_type slot_type;
-       boost::signals::connection connect(slot_type const &) const;
-
-private:
-       /// Not implemented.
-       GraphicInset & operator=(GraphicInset const &);
-
-       /// The message to display instead of the graphic itself.
-       string const statusMessage() const;
-
-       enum DisplayType {
-               IMAGE,
-               STATUS_MESSAGE,
-               NODISPLAY_MESSAGE
-       };
-
-       /// Is the image ready to draw, or should we display a message instead?
-       DisplayType displayType() const;
-       
-       /// The stored data.
-       grfx::Loader loader_;
-       grfx::Params params_;
-       string nodisplay_message_;
-
-       /// These are all cached variables.
-       mutable unsigned long checksum_;
-       mutable boost::weak_ptr<BufferView> view_;
-       mutable Dimension dim_;
-};
-
-
-#endif // NOT GRAPHICINSET_H
diff --git a/src/insets/insetbutton.C b/src/insets/insetbutton.C
deleted file mode 100644 (file)
index 796d46d..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * \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>
-
-#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"
-#include "metricsinfo.h"
-#include "frontends/font_metrics.h"
-
-using std::ostream;
-using std::endl;
-
-
-void InsetButton::metrics(MetricsInfo & mi, Dimension & dim) const
-{
-       lyx::Assert(mi.base.bv);
-
-       LyXFont font(LyXFont::ALL_SANE);
-       font.decSize();
-
-       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;
-}
-
-
-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.setColor(LColor::command).decSize();
-
-       string const s = getScreenLabel(pi.base.bv->buffer());
-
-       if (editable()) {
-               pi.pain.buttonText(x + 2, y, s, font);
-       } else {
-               pi.pain.rectText(x + 2, y, s, font,
-                             LColor::commandbg, LColor::commandframe);
-       }
-}
-
-
-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);
-}
diff --git a/src/insets/insetbutton.h b/src/insets/insetbutton.h
deleted file mode 100644 (file)
index 04b5cd1..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// -*- C++ -*-
-/**
- * \file insetbutton.h
- * 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
- */
-
-#ifndef INSET_BUTTON_H
-#define INSET_BUTTON_H
-
-#include "inset.h"
-#include "LString.h"
-#include <boost/weak_ptr.hpp>
-
-/** Used to provide an inset that looks like a button.
- */
-class InsetButton: public Inset {
-public:
-       ///
-       void metrics(MetricsInfo &, Dimension &) const;
-       ///
-       void draw(PainterInfo & pi, int x, int y) const;
-       ///
-       dispatch_result localDispatch(FuncRequest const & cmd);
-
-protected:
-       ///
-       virtual void cache(BufferView *) const;
-       ///
-       virtual BufferView * view() const;
-       /// This should provide the text for the button
-       virtual string const getScreenLabel(Buffer const *) const = 0;
-private:
-       mutable boost::weak_ptr<BufferView> view_;
-};
-
-#endif
index 9b2e873ee470ddc7c84728cdfaddc728e083bb2c..b6561066ed0baa848bb4ce63880ab94fd5c65da9 100644 (file)
@@ -16,6 +16,7 @@
 #include "debug.h"
 #include "funcrequest.h"
 #include "lyxlex.h"
+#include "metricsinfo.h"
 
 #include "frontends/Painter.h"
 
@@ -27,13 +28,31 @@ using std::ostream;
 
 
 InsetCommand::InsetCommand(InsetCommandParams const & p)
-       : p_(p.getCmdName(), p.getContents(), p.getOptions())
+       : p_(p.getCmdName(), p.getContents(), p.getOptions()),
+         set_label_(false)
 {}
 
 
-InsetCommand::InsetCommand(InsetCommand const & ic)
-       : p_(ic.p_)
+BufferView * InsetCommand::view() const
 {
+       return button_.view();
+}
+
+
+void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       if (!set_label_) {
+               set_label_ = true;
+               button_.update(getScreenLabel(mi.base.bv->buffer()),
+                              editable() != NOT_EDITABLE);
+       }
+       button_.metrics(mi, dim);
+}
+
+
+void InsetCommand::draw(PainterInfo & pi, int x, int y) const
+{
+       button_.draw(pi, x, y);
 }
 
 
@@ -42,6 +61,7 @@ void InsetCommand::setParams(InsetCommandParams const & p)
        p_.setCmdName(p.getCmdName());
        p_.setContents(p.getContents());
        p_.setOptions(p.getOptions());
+       set_label_ = false;
 }
 
 
index a3e14b818a40d73603971f2fe88095bcd5634052..8478ac9a7a0404a0c1154b3a3f5f25ef334f382a 100644 (file)
 #define INSET_LATEXCOMMAND_H
 
 
-#include "insetbutton.h"
+#include "inset.h"
 #include "insetcommandparams.h"
+#include "renderers.h"
 #include "mailinset.h"
-#include <boost/utility.hpp>
 
 // Created by Alejandro 970222
 /** Used to insert a LaTeX command automatically
  */
 
 ///
-class InsetCommand : public InsetButton, boost::noncopyable {
+class InsetCommand : public Inset {
 public:
        ///
        explicit
        InsetCommand(InsetCommandParams const &);
        ///
-       InsetCommand(InsetCommand const &);
+       void metrics(MetricsInfo &, Dimension &) const;
+       ///
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
        void write(Buffer const *, std::ostream & os) const
                { p_.write(os); }
@@ -55,29 +57,37 @@ public:
        Inset::Code lyxCode() const { return Inset::NO_CODE; }
 
        ///
-       string const getCommand() const { return p_.getCommand(); }
+       InsetCommandParams const & params() const { return p_; }
        ///
-       string const & getCmdName() const { return p_.getCmdName(); }
+       virtual dispatch_result localDispatch(FuncRequest const & cmd);
+       ///
+       string const & getContents() const { return p_.getContents(); }
+       ///
+       void setContents(string const & c) { p_.setContents(c); }
        ///
        string const & getOptions() const { return p_.getOptions(); }
+
+protected:
        ///
-       string const & getContents() const { return p_.getContents(); }
+       string const getCommand() const { return p_.getCommand(); }
+       ///
+       string const & getCmdName() const { return p_.getCmdName(); }
        ///
        void setCmdName(string const & n) { p_.setCmdName(n); }
        ///
        void setOptions(string const & o) { p_.setOptions(o); }
        ///
-       void setContents(string const & c) { p_.setContents(c); }
-       ///
-       InsetCommandParams const & params() const { return p_; }
-       ///
        void setParams(InsetCommandParams const &);
        ///
-       virtual dispatch_result localDispatch(FuncRequest const & cmd);
+       virtual BufferView * view() const;
+       /// This should provide the text for the button
+       virtual string const getScreenLabel(Buffer const *) const = 0;
 
 private:
        ///
        InsetCommandParams p_;
+       mutable bool set_label_;
+       mutable ButtonRenderer button_;
 };
 
 
index ee0cbea2bce080049438023f1904924b09d052e6..749860818fc626702b3e4a420904b2a0dbd0e2c0 100644 (file)
@@ -11,7 +11,7 @@
 #include <config.h>
 
 #include "insetexternal.h"
-#include "insets/graphicinset.h"
+#include "insets/renderers.h"
 
 #include "buffer.h"
 #include "BufferView.h"
@@ -82,19 +82,20 @@ InsetExternal::Params::~Params()
 
 
 InsetExternal::InsetExternal()
-       : renderer_(new GraphicInset)
-{
-       renderer_->connect(boost::bind(&InsetExternal::statusChanged, this));
-}
+       : renderer_(new ButtonRenderer)
+{}
 
 
 InsetExternal::InsetExternal(InsetExternal const & other)
        : Inset(other),
          boost::signals::trackable(),
          params_(other.params_),
-         renderer_(new GraphicInset(*other.renderer_))
+         renderer_(other.renderer_->clone())
 {
-       renderer_->connect(boost::bind(&InsetExternal::statusChanged, this));
+       GraphicRenderer * ptr = dynamic_cast<GraphicRenderer *>(renderer_.get());
+       if (ptr) {
+               ptr->connect(boost::bind(&InsetExternal::statusChanged, this));
+       }
 }
 
 
@@ -231,16 +232,34 @@ void InsetExternal::setParams(Params const & p, string const & filepath)
        params_.display = p.display;
        params_.lyxscale = p.lyxscale;
 
-       // A temporary set of params; whether the thing can be displayed
-       // within LyX depends on the availability of this template.
-       Params tmp = params_;
-       if (!getTemplatePtr(params_))
-               tmp.display = grfx::NoDisplay;
-       
-       // Update the display using the new parameters.
-       if (params_.filename.empty() || !filepath.empty())
-               renderer_->update(get_grfx_params(tmp, filepath));      
-       renderer_->setNoDisplayMessage(getScreenLabel(params_));
+       // We display the inset as a button by default.
+       bool display_button = (!getTemplatePtr(params_) ||
+                              params_.filename.empty() ||
+                              filepath.empty() ||
+                              params_.display == grfx::NoDisplay);
+
+       if (display_button) {
+               ButtonRenderer * button_ptr =
+                       dynamic_cast<ButtonRenderer *>(renderer_.get());
+               if (!button_ptr) {
+                       button_ptr = new ButtonRenderer;
+                       renderer_.reset(button_ptr);
+               }
+
+               button_ptr->update(getScreenLabel(params_), true);
+
+       } else {
+               GraphicRenderer * graphic_ptr =
+                       dynamic_cast<GraphicRenderer *>(renderer_.get());
+               if (!graphic_ptr) {
+                       graphic_ptr = new GraphicRenderer;
+                       graphic_ptr->connect(
+                               boost::bind(&InsetExternal::statusChanged, this));
+                       renderer_.reset(graphic_ptr);
+               }
+
+               graphic_ptr->update(get_grfx_params(params_, filepath));
+       }
 }
 
 
index 4916bae6dae61476b8a3702cea3f9a48cb38cd1a..a3f3f38ce8e44df9f9349b1c77b6d47488ce0e8b 100644 (file)
@@ -20,7 +20,7 @@
 #include <boost/signals/trackable.hpp>
 
 
-class GraphicInset;
+class RenderInset;
 
 ///
 class InsetExternal : public Inset, public boost::signals::trackable {
@@ -116,7 +116,7 @@ private:
        Params params_;
 
        /// The thing that actually draws the image on LyX's screen.
-       boost::scoped_ptr<GraphicInset> const renderer_;
+       boost::scoped_ptr<RenderInset> renderer_;
 };
 
 
index ee094798506714b4d22f4f2cb3509c377aa908ea..782b954033aed0a16c9bd0b28c11a6ab36996587 100644 (file)
@@ -54,7 +54,7 @@ TODO
 
 #include "insets/insetgraphics.h"
 #include "insets/insetgraphicsParams.h"
-#include "insets/graphicinset.h"
+#include "insets/renderers.h"
 
 #include "buffer.h"
 #include "BufferView.h"
@@ -134,7 +134,7 @@ string findTargetFormat(string const & suffix, LatexRunParams const & runparams)
 
 InsetGraphics::InsetGraphics()
        : graphic_label(uniqueID()),
-         graphic_(new GraphicInset)
+         graphic_(new GraphicRenderer)
 {
        graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
 }
@@ -144,7 +144,7 @@ InsetGraphics::InsetGraphics(InsetGraphics const & ig)
        : Inset(ig),
          boost::signals::trackable(),
          graphic_label(uniqueID()),
-         graphic_(new GraphicInset(*ig.graphic_))
+         graphic_(new GraphicRenderer(*ig.graphic_))
 {
        graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
        setParams(ig.params());
@@ -552,7 +552,7 @@ int InsetGraphics::linuxdoc(Buffer const *, ostream &) const
 
 
 // For explanation on inserting graphics into DocBook checkout:
-// http://linuxdoc.org/LDP/LDP-Author-Guide/inserting-pictures.html
+// http://en.tldp.org/LDP/LDP-Author-Guide/inserting-pictures.html
 // See also the docbook guide at http://www.docbook.org/
 int InsetGraphics::docbook(Buffer const *, ostream & os,
                           bool /*mixcont*/) const
index 0ea045452f3cfcdac71dea21a9229ae9b096af17..4e1e59b88e6c20a7954254284d583ac2e89c0c6b 100644 (file)
@@ -21,7 +21,7 @@
 
 
 class Dialogs;
-class GraphicInset;
+class GraphicRenderer;
 class LaTeXFeatures;
 
 ///
@@ -104,7 +104,7 @@ private:
        string const graphic_label;
 
        /// The thing that actually draws the image on LyX's screen.
-       boost::scoped_ptr<GraphicInset> const graphic_;
+       boost::scoped_ptr<GraphicRenderer> const graphic_;
 };
 
 
index 6b25e65864ae634917b44f4720f1e97f1a453e60..57c7db620484c9f557e3361261080360720f0c5c 100644 (file)
@@ -92,19 +92,30 @@ string const uniqueID()
 
 InsetInclude::InsetInclude(Params const & p)
        : params_(p), include_label(uniqueID()),
-         preview_(new PreviewImpl(*this))
+         preview_(new PreviewImpl(*this)),
+         set_label_(false)
 {}
 
 
 InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b)
        : include_label(uniqueID()),
-         preview_(new PreviewImpl(*this))
+         preview_(new PreviewImpl(*this)),
+         set_label_(false)
 {
        params_.cparams = p;
        params_.masterFilename_ = b.fileName();
 }
 
 
+InsetInclude::InsetInclude(InsetInclude const & other)
+       : Inset(other),
+         params_(other.params_),
+         include_label(other.include_label),
+         preview_(new PreviewImpl(*this)),
+         set_label_(other.set_label_)
+{}
+
+
 InsetInclude::~InsetInclude()
 {
        InsetIncludeMailer mailer(*this);
@@ -137,7 +148,7 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
                return DISPATCHED;
 
        default:
-               return InsetButton::localDispatch(cmd);
+               return Inset::localDispatch(cmd);
        }
 }
 
@@ -511,7 +522,12 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
                dim.des = preview_->pimage()->descent();
                dim.wid = preview_->pimage()->width();
        } else {
-               InsetButton::metrics(mi, dim);
+               if (!set_label_) {
+                       set_label_ = true;
+                       button_.update(getScreenLabel(mi.base.bv->buffer()),
+                                      editable() != NOT_EDITABLE);
+               }
+               button_.metrics(mi, dim);
        }
        dim_ = dim;
 }
@@ -521,7 +537,7 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 {
        cache(pi.base.bv);
        if (!preview_->previewReady()) {
-               InsetButton::draw(pi, x, y);
+               button_.draw(pi, x, y);
                return;
        }
 
@@ -533,6 +549,12 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 }
 
 
+BufferView * InsetInclude::view() const
+{
+       return button_.view();
+}
+
+
 //
 // preview stuff
 //
index 008779970740297ce3a33c72936de4e0656b6226..47d767e5f39b45a4919a8685c7b39845f29c6516 100644 (file)
 
 #include "insetcommand.h"
 #include "dimension.h"
-
+#include "renderers.h"
 #include <boost/scoped_ptr.hpp>
 
+
 class Buffer;
 struct LaTeXFeatures;
 
 // Created by AAS 970521
 
 /// for including tex/lyx files
-class InsetInclude: public InsetButton, boost::noncopyable {
+class InsetInclude: public Inset {
 public:
        /// the type of inclusion
        enum Flags {
@@ -52,8 +53,8 @@ public:
 
        ///
        InsetInclude(Params const &);
-       ///
        InsetInclude(InsetCommandParams const &, Buffer const &);
+       InsetInclude(InsetInclude const &);
 
        ~InsetInclude();
 
@@ -64,6 +65,8 @@ public:
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        void draw(PainterInfo & pi, int x, int y) const;
+       ///
+       virtual BufferView * view() const;
 
        /// get the parameters
        Params const & params(void) const;
@@ -131,6 +134,8 @@ private:
 
        /// cache
        mutable Dimension dim_;
+       mutable bool set_label_;
+       mutable ButtonRenderer button_;
 };
 
 
diff --git a/src/insets/renderers.C b/src/insets/renderers.C
new file mode 100644 (file)
index 0000000..656b7b0
--- /dev/null
@@ -0,0 +1,301 @@
+/**
+ * \file renderers.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+#include "insets/renderers.h"
+
+#include "buffer.h"
+#include "BufferView.h"
+#include "gettext.h"
+#include "metricsinfo.h"
+
+#include "frontends/font_metrics.h"
+#include "frontends/LyXView.h"
+#include "frontends/Painter.h"
+
+#include "graphics/GraphicsImage.h"
+
+#include "support/filetools.h"
+
+
+RenderInset::RenderInset()
+{}
+
+
+RenderInset::RenderInset(RenderInset const &)
+{
+       // Cached variables are not copied
+}
+
+
+RenderInset::~RenderInset()
+{}
+
+
+RenderInset & RenderInset::operator=(RenderInset const &)
+{
+       // Cached variables are not copied
+       return *this;
+}
+
+
+BufferView * RenderInset::view() const
+{
+       return view_.lock().get();
+}
+
+
+ButtonRenderer::ButtonRenderer()
+       : editable_(false)
+{}
+
+
+RenderInset * ButtonRenderer::clone() const
+{
+       return new ButtonRenderer(*this);
+}
+
+
+void ButtonRenderer::update(string const & text, bool editable)
+{
+       text_ = text;
+       editable_ = editable;
+}
+
+
+void ButtonRenderer::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       lyx::Assert(mi.base.bv);
+
+       LyXFont font(LyXFont::ALL_SANE);
+       font.decSize();
+
+       if (editable_)
+               font_metrics::buttonText(text_, font, dim.wid, dim.asc, dim.des);
+       else
+               font_metrics::rectText(text_, font, dim.wid, dim.asc, dim.des);
+
+       dim.wid += 4;
+}
+
+
+void ButtonRenderer::draw(PainterInfo & pi, int x, int y) const
+{
+       lyx::Assert(pi.base.bv);
+       view_ = pi.base.bv->owner()->view();
+
+       // Draw it as a box with the LaTeX text
+       LyXFont font(LyXFont::ALL_SANE);
+       font.setColor(LColor::command).decSize();
+
+       if (editable_) {
+               pi.pain.buttonText(x + 2, y, text_, font);
+       } else {
+               pi.pain.rectText(x + 2, y, text_, font,
+                             LColor::commandbg, LColor::commandframe);
+       }
+}
+
+
+GraphicRenderer::GraphicRenderer()
+       : checksum_(0)
+{}
+
+
+GraphicRenderer::GraphicRenderer(GraphicRenderer const & other)
+       : RenderInset(other),
+         loader_(other.loader_),
+         params_(other.params_),
+         checksum_(0)
+{}
+
+
+RenderInset * GraphicRenderer::clone() const
+{
+       return new GraphicRenderer(*this);
+}
+
+
+void GraphicRenderer::update(grfx::Params const & params)
+{
+       params_ = params;
+
+       if (!params_.filename.empty()) {
+               lyx::Assert(AbsolutePath(params_.filename));
+               loader_.reset(params_.filename, params_);
+       }
+}
+
+
+bool GraphicRenderer::hasFileChanged() const
+{
+       unsigned long const new_checksum = loader_.checksum();
+       bool const file_has_changed = checksum_ != new_checksum;
+       if (file_has_changed)
+               checksum_ = new_checksum;
+       return file_has_changed;
+}
+
+
+boost::signals::connection GraphicRenderer::connect(slot_type const & slot) const
+{
+       return loader_.connect(slot);
+}
+
+
+string const GraphicRenderer::statusMessage() const
+{
+       switch (loader_.status()) {
+               case grfx::WaitingToLoad:
+                       return _("Not shown.");
+               case grfx::Loading:
+                       return _("Loading...");
+               case grfx::Converting:
+                       return _("Converting to loadable format...");
+               case grfx::Loaded:
+                       return _("Loaded into memory. Must now generate pixmap.");
+               case grfx::ScalingEtc:
+                       return _("Scaling etc...");
+               case grfx::Ready:
+                       return _("Ready to display");
+               case grfx::ErrorNoFile:
+                       return _("No file found!");
+               case grfx::ErrorConverting:
+                       return _("Error converting to loadable format");
+               case grfx::ErrorLoading:
+                       return _("Error loading file into memory");
+               case grfx::ErrorGeneratingPixmap:
+                       return _("Error generating the pixmap");
+               case grfx::ErrorUnknown:
+                       return _("No image");
+       }
+       return string();
+}
+
+
+bool GraphicRenderer::readyToDisplay() const
+{
+       if (!loader_.image() || loader_.status() != grfx::Ready)
+               return false;
+       return loader_.image()->isDrawable();
+}
+
+
+void GraphicRenderer::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       bool image_ready = readyToDisplay();
+
+       dim.asc = image_ready ? loader_.image()->getHeight() : 50;
+       dim.des = 0;
+
+       if (image_ready) {
+               dim.wid = loader_.image()->getWidth() +
+                       2 * Inset::TEXT_TO_INSET_OFFSET;
+       } else {
+               int font_width = 0;
+
+               LyXFont msgFont(mi.base.font);
+               msgFont.setFamily(LyXFont::SANS_FAMILY);
+
+               string const justname = OnlyFilename(params_.filename);
+               if (!justname.empty()) {
+                       msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
+                       font_width = font_metrics::width(justname, msgFont);
+               }
+
+               string const msg = statusMessage();
+               if (!msg.empty()) {
+                       msgFont.setSize(LyXFont::SIZE_TINY);
+                       font_width = std::max(font_width,
+                                             font_metrics::width(msg, msgFont));
+               }
+
+               dim.wid = std::max(50, font_width + 15);
+       }
+
+       dim_ = dim;
+}
+
+
+void GraphicRenderer::draw(PainterInfo & pi, int x, int y) const
+{
+       lyx::Assert(pi.base.bv);
+       view_ = pi.base.bv->owner()->view();
+
+#if 0
+       // Comment this out and see if anything goes wrong.
+       // The explanation for why it _was_ needed once upon a time is below.
+
+       // MakeAbsPath returns filename_ unchanged if it is absolute
+       // already.
+       string const file_with_path =
+               MakeAbsPath(params_.filename, view_->buffer()->filePath());
+
+       // A 'paste' operation creates a new inset with the correct filepath,
+       // but then the 'old' inset stored in the 'copy' operation is actually
+       // added to the buffer.
+
+       // Thus, pasting a graphic into a new buffer with different
+       // buffer->filePath() will result in the image being displayed in LyX even
+       // though the relative path now points at nothing at all. Subsequent
+       // loading of the file into LyX will therefore fail.
+
+       // We should ensure that the filepath is correct.
+       if (file_with_path != loader_.filename()) {
+               params_.filename = file_with_path;
+               update(params_);
+       }
+#endif
+
+       if (params_.display != grfx::NoDisplay &&
+           loader_.status() == grfx::WaitingToLoad)
+               loader_.startLoading();
+
+       if (params_.display != grfx::NoDisplay && !loader_.monitoring())
+               loader_.startMonitoring();
+
+       // This will draw the graphics. If the graphics has not been loaded yet,
+       // we draw just a rectangle.
+
+       if (readyToDisplay()) {
+               pi.pain.image(x + Inset::TEXT_TO_INSET_OFFSET,
+                             y - dim_.asc,
+                             dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET,
+                             dim_.asc + dim_.des,
+                             *loader_.image());
+
+       } else {
+               pi.pain.rectangle(x + Inset::TEXT_TO_INSET_OFFSET,
+                                 y - dim_.asc,
+                                 dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET,
+                                 dim_.asc + dim_.des);
+
+               // Print the file name.
+               LyXFont msgFont = pi.base.font;
+               msgFont.setFamily(LyXFont::SANS_FAMILY);
+               string const justname = OnlyFilename(params_.filename);
+
+               if (!justname.empty()) {
+                       msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
+                       pi.pain.text(x + Inset::TEXT_TO_INSET_OFFSET + 6,
+                                  y - font_metrics::maxAscent(msgFont) - 4,
+                                  justname, msgFont);
+               }
+
+               // Print the message.
+               string const msg = statusMessage();
+               if (!msg.empty()) {
+                       msgFont.setSize(LyXFont::SIZE_TINY);
+                       pi.pain.text(x + Inset::TEXT_TO_INSET_OFFSET + 6,
+                                    y - 4, msg, msgFont);
+               }
+       }
+}
diff --git a/src/insets/renderers.h b/src/insets/renderers.h
new file mode 100644 (file)
index 0000000..5604bce
--- /dev/null
@@ -0,0 +1,122 @@
+// -*- C++ -*-
+/**
+ * \file renderers.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef RENDERERS_H
+#define RENDERERS_H
+
+#include "dimension.h"
+
+#include "graphics/GraphicsLoader.h"
+#include "graphics/GraphicsParams.h"
+#include "graphics/GraphicsTypes.h"
+
+#include <boost/weak_ptr.hpp>
+#include <boost/signals/signal0.hpp>
+
+
+class BufferView;
+class MetricsInfo;
+class PainterInfo;
+
+
+class RenderInset 
+{
+public:
+       virtual ~RenderInset();
+
+       virtual RenderInset * clone() const = 0;
+
+       /// compute the size of the object returned in dim
+       virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
+       /// draw inset and update (xo, yo)-cache
+       virtual void draw(PainterInfo & pi, int x, int y) const = 0;
+
+       /// An accessor function to the cached store.
+       BufferView * view() const;
+
+protected:
+       RenderInset();
+       RenderInset(RenderInset const &);
+       RenderInset & operator=(RenderInset const &);
+
+       /// These are cached variables (are not copied).
+       mutable boost::weak_ptr<BufferView> view_;
+       mutable Dimension dim_;
+};
+
+
+class ButtonRenderer : public RenderInset
+{
+public:
+       ButtonRenderer();
+
+       virtual RenderInset * clone() const;
+
+       /// This should provide the text for the button
+       void update(string const &, bool editable);
+       
+       /// compute the size of the object returned in dim
+       virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
+       /// draw inset and update (xo, yo)-cache
+       virtual void draw(PainterInfo & pi, int x, int y) const;
+
+private:
+       /// The stored data.
+       string text_;
+       bool editable_;
+};
+
+
+class GraphicRenderer : public RenderInset
+{
+public:
+       GraphicRenderer();
+       GraphicRenderer(GraphicRenderer const &);
+
+       virtual RenderInset * clone() const;
+
+       /// Refresh the info about which file to display and how to display it.
+       void update(grfx::Params const & params);
+
+       /// compute the size of the object returned in dim
+       virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
+       /// draw inset and update (xo, yo)-cache
+       virtual void draw(PainterInfo & pi, int x, int y) const;
+
+       /// Is the stored checksum different to that of the graphics loader?
+       bool hasFileChanged() const;
+
+       /** Connect and you'll be informed when the loading status of the image
+        *  changes.
+        */
+       typedef boost::signal0<void>::slot_type slot_type;
+       virtual boost::signals::connection connect(slot_type const &) const;
+
+private:
+       /// Not implemented.
+       GraphicRenderer & operator=(GraphicRenderer const &);
+
+       /// The message to display instead of the graphic itself.
+       string const statusMessage() const;
+
+       /// Is the image ready to draw, or should we display a message instead?
+       bool readyToDisplay() const;
+       
+       /// The stored data.
+       grfx::Loader loader_;
+       grfx::Params params_;
+
+       /// Cached variable (not copied).
+       mutable unsigned long checksum_;
+};
+
+
+#endif // NOT RENDERERS_H
index ab6c9cdafbf5f18174719bc47c734b68655eddfa..fdf5f29afb3e7af864df62973fa4a5b0d22032cc 100644 (file)
@@ -1,3 +1,13 @@
+2003-06-11  Angus Leeming  <leeming@lyx.org>
+
+       * button_inset.[Ch]: removed.
+       * Makefile.am: remove button_inset.[Ch].
+
+       * command_inset.[Ch]: no longer derived from ButtonInset.
+       Instead has a ButtonRenderer member variable.
+
+       * ref_inset.[Ch]: associated changes.
+       
 2003-06-03  John Levon  <levon@movementarian.org>
 
        * formula.[Ch]:
index 4bae5b7ccc83c335b12f39934a0db57748af7f8b..998fa6c42eae8438480100c167c88eecb6ee4543 100644 (file)
@@ -151,8 +151,6 @@ libmathed_la_SOURCES = \
        math_undersetinset.h \
        math_xarrowinset.C \
        math_xarrowinset.h \
-       button_inset.C \
-       button_inset.h \
        command_inset.h \
        command_inset.C \
        ref_inset.h \
diff --git a/src/mathed/button_inset.C b/src/mathed/button_inset.C
deleted file mode 100644 (file)
index 8a8e59d..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-
-#include <config.h>
-
-#include "button_inset.h"
-#include "math_support.h"
-#include "metricsinfo.h"
-#include "frontends/Painter.h"
-
-#include <algorithm>
-
-using std::max;
-
-
-ButtonInset::ButtonInset()
-       : MathNestInset(2)
-{}
-
-
-void ButtonInset::metrics(MetricsInfo & mi, Dimension & dim) const
-{
-       FontSetChanger dummy(mi.base, "textnormal");
-       if (editing()) {
-               MathNestInset::metrics(mi);
-               dim_.wid = cell(0).width() + cell(1).width() + 4;
-               dim_.asc = max(cell(0).ascent(), cell(1).ascent());
-               dim_.des = max(cell(0).descent(), cell(1).descent());
-       } else {
-               mathed_string_dim(mi.base.font, screenLabel(), dim_);
-               dim_.wid += 10;
-       }
-       dim = dim_;
-}
-
-
-void ButtonInset::draw(PainterInfo & pi, int x, int y) const
-{
-       FontSetChanger dummy(pi.base, "textnormal");
-       if (editing()) {
-               cell(0).draw(pi, x, y);
-               cell(1).draw(pi, x + cell(0).width() + 2, y);
-               //if (mathcursor && mathcursor->isInside(p))
-                       pi.pain.rectangle(x, y - dim_.ascent(), dim_.width(), dim_.height(),
-                               LColor::mathframe);
-       } else {
-               pi.pain.buttonText(x + 2, y, screenLabel(), pi.base.font);
-       }
-}
diff --git a/src/mathed/button_inset.h b/src/mathed/button_inset.h
deleted file mode 100644 (file)
index 8174f3c..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-// -*- C++ -*-
-
-/**
- *  \file button_inset.h
- *
- *  This file is part of LyX, the document processor.
- *  Licence details can be found in the file COPYING.
- *
- *  \author André Pönitz
- *
- *  Full author contact details are available in file CREDITS.
- */
-
-#ifndef BUTTON_INSET_H
-#define BUTTON_INSET_H
-
-
-#include "math_nestinset.h"
-
-/// try to implement the button-like insets "natively" for mathed
-class ButtonInset: public MathNestInset {
-public:
-       ///
-       ButtonInset();
-       ///
-       void metrics(MetricsInfo & mi, Dimension & dim) const;
-       ///
-       void draw(PainterInfo & pi, int x, int y) const;
-
-protected:
-       /// This should provide the text for the button
-       virtual string screenLabel() const = 0;
-};
-
-#endif
index 7c75d36887d4f1e64831f55a87b34b54ca0e6a0b..4c397d6c87a90cc3a9efcbb35d12a150542e93e6 100644 (file)
@@ -6,7 +6,9 @@
 
 
 CommandInset::CommandInset(string const & name)
-       : name_(name)
+       : MathNestInset(2),
+         name_(name),
+         set_label_(false)
 {
        lock_ = true;
 }
@@ -18,12 +20,27 @@ MathInset * CommandInset::clone() const
 }
 
 
+void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       if (!set_label_) {
+               set_label_ = true;
+               button_.update(screenLabel(), true);
+       }
+       button_.metrics(mi, dim);
+}
+
+
+void CommandInset::draw(PainterInfo & pi, int x, int y) const
+{
+       button_.draw(pi, x, y);
+}
+
 dispatch_result
 CommandInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
 {
        switch (cmd.action) {
                default:
-                       return ButtonInset::dispatch(cmd, idx, pos);
+                       return MathNestInset::dispatch(cmd, idx, pos);
        }
        return UNDISPATCHED;
 }
@@ -38,9 +55,9 @@ void CommandInset::write(WriteStream & os) const
 }
 
 
-string CommandInset::screenLabel() const
+string const CommandInset::screenLabel() const
 {
-       return name_;
+       return name_;
 }
 
 
@@ -53,5 +70,3 @@ string const CommandInset::createDialogStr(string const & name) const
        wsdata << "\n\\end_inset\n\n";
        return STRCONV(data.str());
 }
-
-
index d8264067d7063c7de09de3b6957bc907c759ba9e..6844a6119078e19355f679d9d449a53a3558a722 100644 (file)
 #ifndef COMMAND_INSET_H
 #define COMMAND_INSET_H
 
-#include "button_inset.h"
+#include "math_nestinset.h"
+#include "insets/renderers.h"
+
 
 /// Inset for things like \name[options]{contents}
-class CommandInset : public ButtonInset {
+class CommandInset : public MathNestInset {
 public:
        ///
        explicit CommandInset(string const & name);
        ///
        MathInset * clone() const;
        ///
+       void metrics(MetricsInfo & mi, Dimension & dim) const;
+       ///
+       void draw(PainterInfo & pi, int x, int y) const;
+       ///
        void write(WriteStream & os) const;
        ///
        //void infoize(std::ostream & os) const;
        ///
        dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
        ///
-       string screenLabel() const;
-       /// generate something that will be understodd by the Dialogs.
+       virtual string const screenLabel() const;
+       /// generate something that will be understood by the Dialogs.
        string const createDialogStr(string const & name) const;
-public:
+
+       string const & commandname() const { return name_; }
+
+private:
        string name_;
+       mutable bool set_label_;
+       mutable ButtonRenderer button_;
 };
 
 #endif
index b0f2c204e6957a093fc559db08d28b60bc6cda74..77009c80babf3614ee27e365071078d89cc222a6 100644 (file)
@@ -70,11 +70,11 @@ RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
 }
 
 
-string RefInset::screenLabel() const
+string const RefInset::screenLabel() const
 {
        string str;
        for (int i = 0; !types[i].latex_name.empty(); ++i)
-               if (name_ == types[i].latex_name) {
+               if (commandname() == types[i].latex_name) {
                        str = _(types[i].short_gui_name);
                        break;
                }
@@ -90,9 +90,9 @@ string RefInset::screenLabel() const
 
 void RefInset::validate(LaTeXFeatures & features) const
 {
-       if (name_ == "vref" || name_ == "vpageref")
+       if (commandname() == "vref" || commandname() == "vpageref")
                features.require("varioref");
-       else if (name_ == "prettyref")
+       else if (commandname() == "prettyref")
                features.require("prettyref");
 }
 
index 0132d78ab3a61a777b32fd461408014bafe1f4f7..7bd24ac4dc0bbf20c9b5dfe46383d7c3303d46e4 100644 (file)
@@ -20,7 +20,7 @@ public:
        ///
        dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
        ///
-       string screenLabel() const;
+       string const screenLabel() const;
        ///
        void validate(LaTeXFeatures & features) const;
        ///