+2004-04-13 Angus Leeming <angus@localhost.localdomain>
+
+ * render_base.[Ch] (clone): now takes an InsetBase ptr to enable
+ the renderer to inform LyX::updateInset that the inset's status
+ has changed and it should be redrawn.
+
+ * render_button.[Ch] (clone):
+ * render_graphic.[Ch] (c-tors, clone):
+ * render_preview.[Ch] (c-tors, clone): ditto.
+
+ * render_graphic.[Ch] (connect):
+ * render_preview.[Ch] (connect): removed, as connection is now
+ made in the constructors.
+
+ * insetexternal.C:
+ * insetgraphics.C:
+ * insetinclude.C: ensuing simplification of the client code.
+ (statusChanged): now superfluous. Removed.
+
2004-04-12 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* ExternalTemplate.[Ch]: remove editCommand
: InsetOld(other),
boost::signals::trackable(),
params_(other.params_),
- renderer_(other.renderer_->clone())
-{
- if (renderer_->asMonitoredPreview() != 0) {
- RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
- ptr->connect(boost::bind(&InsetExternal::statusChanged, this));
- ptr->fileChanged(boost::bind(&InsetExternal::fileChanged, this));
-
- } else if (renderer_->asGraphic() != 0 ) {
- RenderGraphic * const ptr = renderer_->asGraphic();
- ptr->connect(boost::bind(&InsetExternal::statusChanged, this));
- }
-}
+ renderer_(other.renderer_->clone(this))
+{}
auto_ptr<InsetBase> InsetExternal::clone() const
} case RENDERGRAPHIC: {
RenderGraphic * graphic_ptr = renderer_->asGraphic();
if (!graphic_ptr) {
- renderer_.reset(new RenderGraphic);
+ renderer_.reset(new RenderGraphic(this));
graphic_ptr = renderer_->asGraphic();
- graphic_ptr->connect(
- boost::bind(&InsetExternal::statusChanged, this));
}
graphic_ptr->update(get_grfx_params(params_));
RenderMonitoredPreview * preview_ptr =
renderer_->asMonitoredPreview();
if (!preview_ptr) {
- renderer_.reset(new RenderMonitoredPreview);
+ renderer_.reset(new RenderMonitoredPreview(this));
preview_ptr = renderer_->asMonitoredPreview();
- preview_ptr->connect(
- boost::bind(&InsetExternal::statusChanged, this));
preview_ptr->fileChanged(
boost::bind(&InsetExternal::fileChanged, this));
}
InsetGraphics::InsetGraphics()
: graphic_label(uniqueID()),
- graphic_(new RenderGraphic)
-{
- graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
-}
+ graphic_(new RenderGraphic(this))
+{}
InsetGraphics::InsetGraphics(InsetGraphics const & ig)
: InsetOld(ig),
boost::signals::trackable(),
graphic_label(uniqueID()),
- graphic_(new RenderGraphic(*ig.graphic_))
+ graphic_(new RenderGraphic(*ig.graphic_, this))
{
- graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
setParams(ig.params());
}
}
-void InsetGraphics::statusChanged() const
-{
- LyX::cref().updateInset(this);
-}
-
-
void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
///
friend class InsetGraphicsMailer;
- /** This method is connected to the graphics loader, so we are
- * informed when the image has been loaded.
- */
- void statusChanged() const;
-
/// Read the inset native format
void readInsetGraphics(LyXLex & lex, std::string const & bufpath);
InsetInclude::InsetInclude(InsetCommandParams const & p)
: params_(p), include_label(uniqueID()),
- preview_(new RenderMonitoredPreview),
+ preview_(new RenderMonitoredPreview(this)),
set_label_(false)
{
- preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
}
: InsetOld(other),
params_(other.params_),
include_label(other.include_label),
- preview_(new RenderMonitoredPreview),
+ preview_(new RenderMonitoredPreview(this)),
set_label_(other.set_label_)
{
- preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
}
// preview stuff
//
-void InsetInclude::statusChanged() const
-{
- LyX::cref().updateInset(this);
-}
-
-
void InsetInclude::fileChanged() const
{
Buffer const * const buffer_ptr = LyX::cref().updateInset(this);
///
virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
private:
- /// Slot receiving a signal that the preview is ready to display.
- void statusChanged() const;
/** Slot receiving a signal that the external file has changed
* and the preview should be regenerated.
*/
#include <memory>
+class InsetBase;
class MetricsInfo;
class PainterInfo;
public:
virtual ~RenderBase() {}
- virtual std::auto_ptr<RenderBase> clone() const = 0;
+ virtual std::auto_ptr<RenderBase> clone(InsetBase const *) const = 0;
/// compute the size of the object returned in dim
virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
{}
-auto_ptr<RenderBase> RenderButton::clone() const
+auto_ptr<RenderBase> RenderButton::clone(InsetBase const *) const
{
return auto_ptr<RenderBase>(new RenderButton(*this));
}
public:
RenderButton();
- std::auto_ptr<RenderBase> clone() const;
+ std::auto_ptr<RenderBase> clone(InsetBase const *) const;
/// compute the size of the object returned in dim
virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
#include "gettext.h"
#include "LColor.h"
+#include "lyx_main.h"
#include "lyxrc.h"
#include "metricsinfo.h"
#include "support/filetools.h"
+#include <boost/bind.hpp>
+
namespace graphics = lyx::graphics;
using lyx::support::AbsolutePath;
using std::auto_ptr;
-RenderGraphic::RenderGraphic()
+RenderGraphic::RenderGraphic(InsetBase const * inset)
: checksum_(0)
-{}
+{
+ loader_.connect(boost::bind(&LyX::updateInset,
+ boost::cref(LyX::cref()), inset));
+}
-RenderGraphic::RenderGraphic(RenderGraphic const & other)
+RenderGraphic::RenderGraphic(RenderGraphic const & other,
+ InsetBase const * inset)
: RenderBase(other),
loader_(other.loader_),
params_(other.params_),
checksum_(0)
-{}
+{
+ loader_.connect(boost::bind(&LyX::updateInset,
+ boost::cref(LyX::cref()), inset));
+}
-auto_ptr<RenderBase> RenderGraphic::clone() const
+auto_ptr<RenderBase> RenderGraphic::clone(InsetBase const * inset) const
{
- return auto_ptr<RenderBase>(new RenderGraphic(*this));
+ return auto_ptr<RenderBase>(new RenderGraphic(*this, inset));
}
}
-boost::signals::connection RenderGraphic::connect(slot_type const & slot) const
-{
- return loader_.connect(slot);
-}
-
-
namespace {
bool displayGraphic(graphics::Params const & params)
#include "graphics/GraphicsLoader.h"
#include "graphics/GraphicsParams.h"
-#include <boost/signals/signal0.hpp>
-
class RenderGraphic : public RenderBase
{
public:
- RenderGraphic();
- RenderGraphic(RenderGraphic const &);
- std::auto_ptr<RenderBase> clone() const;
+ RenderGraphic(InsetBase const *);
+ RenderGraphic(RenderGraphic const &, InsetBase const *);
+ std::auto_ptr<RenderBase> clone(InsetBase const *) const;
/// compute the size of the object returned in dim
void metrics(MetricsInfo & mi, Dimension & dim) 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;
- boost::signals::connection connect(slot_type const &) const;
-
/// equivalent to dynamic_cast
virtual RenderGraphic * asGraphic() { return this; }
#include "dimension.h"
#include "gettext.h"
#include "LColor.h"
+#include "lyx_main.h"
#include "metricsinfo.h"
#include "frontends/font_metrics.h"
}
-RenderPreview::RenderPreview()
- : pimage_(0)
+RenderPreview::RenderPreview(InsetBase const * inset)
+ : pimage_(0),
+ parent_(inset)
{}
-RenderPreview::RenderPreview(RenderPreview const & other)
+RenderPreview::RenderPreview(RenderPreview const & other,
+ InsetBase const * inset)
: RenderBase(other),
boost::signals::trackable(),
snippet_(other.snippet_),
- pimage_(0)
+ pimage_(0),
+ parent_(inset)
{}
-auto_ptr<RenderBase> RenderPreview::clone() const
+auto_ptr<RenderBase> RenderPreview::clone(InsetBase const * inset) const
{
- return auto_ptr<RenderBase>(new RenderPreview(*this));
+ return auto_ptr<RenderBase>(new RenderPreview(*this, inset));
}
}
-boost::signals::connection RenderPreview::connect(slot_type const & slot)
-{
- return preview_ready_signal_.connect(slot);
-}
-
-
void RenderPreview::startLoading(Buffer const & buffer) const
{
if (!activated() && !snippet_.empty())
return;
pimage_ = &pimage;
- preview_ready_signal_();
+ LyX::cref().updateInset(parent_);
}
+RenderMonitoredPreview::RenderMonitoredPreview(InsetBase const * inset)
+ : RenderPreview(inset),
+ monitor_(std::string(), 2000)
+{}
+
+
void RenderMonitoredPreview::setAbsFile(string const & file)
{
monitor_.reset(file);
/// a wrapper for Previews::activated()
static bool activated();
- RenderPreview();
- RenderPreview(RenderPreview const &);
- std::auto_ptr<RenderBase> clone() const;
+ RenderPreview(InsetBase const *);
+ RenderPreview(RenderPreview const &, InsetBase const *);
+ std::auto_ptr<RenderBase> clone(InsetBase const *) const;
/// Compute the size of the object, returned in dim
void metrics(MetricsInfo &, Dimension & dim) const;
/// The preview has been generated and is ready to use.
bool previewReady() const;
- /// Connect and you'll be informed when the preview is ready.
- typedef boost::signal0<void>::slot_type slot_type;
- boost::signals::connection connect(slot_type const &);
-
/// equivalent to dynamic_cast
virtual RenderPreview * asPreview() { return this; }
*/
boost::signals::connection ploader_connection_;
- /// This signal is emitted when the preview is ready for display.
- boost::signal0<void> preview_ready_signal_;
+ /// Inform the core that the inset has changed.
+ InsetBase const * parent_;
};
class RenderMonitoredPreview : public RenderPreview {
public:
- RenderMonitoredPreview() : monitor_(std::string(), 2000) {}
+ RenderMonitoredPreview(InsetBase const *);
///
void draw(PainterInfo & pi, int x, int y) const;
///
void startMonitoring() const { monitor_.start(); }
void stopMonitoring() const { monitor_.stop(); }
+
/// Connect and you'll be informed when the file changes.
+ typedef boost::signal0<void>::slot_type slot_type;
boost::signals::connection fileChanged(slot_type const &);
/// equivalent to dynamic_cast