Refactoring of renderer code to make inset code simpler.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8650 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-04-13 17:25:23 +00:00
parent 3aeb0e7f41
commit fff7d8407c
13 changed files with 78 additions and 98 deletions

View File

@ -1,3 +1,22 @@
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

View File

@ -410,18 +410,8 @@ InsetExternal::InsetExternal(InsetExternal const & other)
: 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
@ -611,10 +601,8 @@ void InsetExternal::setParams(InsetExternalParams const & p,
} 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_));
@ -625,10 +613,8 @@ void InsetExternal::setParams(InsetExternalParams const & p,
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));
}

View File

@ -152,19 +152,16 @@ string findTargetFormat(string const & suffix, OutputParams const & runparams)
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());
}
@ -181,12 +178,6 @@ InsetGraphics::~InsetGraphics()
}
void InsetGraphics::statusChanged() const
{
LyX::cref().updateInset(this);
}
void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {

View File

@ -88,11 +88,6 @@ private:
///
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);

View File

@ -91,10 +91,9 @@ string const uniqueID()
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));
}
@ -103,10 +102,9 @@ InsetInclude::InsetInclude(InsetInclude const & other)
: 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));
}
@ -607,12 +605,6 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
// preview stuff
//
void InsetInclude::statusChanged() const
{
LyX::cref().updateInset(this);
}
void InsetInclude::fileChanged() const
{
Buffer const * const buffer_ptr = LyX::cref().updateInset(this);

View File

@ -85,8 +85,6 @@ protected:
///
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.
*/

View File

@ -16,6 +16,7 @@
#include <memory>
class InsetBase;
class MetricsInfo;
class PainterInfo;
@ -28,7 +29,7 @@ class RenderBase {
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;

View File

@ -27,7 +27,7 @@ RenderButton::RenderButton()
{}
auto_ptr<RenderBase> RenderButton::clone() const
auto_ptr<RenderBase> RenderButton::clone(InsetBase const *) const
{
return auto_ptr<RenderBase>(new RenderButton(*this));
}

View File

@ -22,7 +22,7 @@ class RenderButton : public RenderBase
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;

View File

@ -16,6 +16,7 @@
#include "gettext.h"
#include "LColor.h"
#include "lyx_main.h"
#include "lyxrc.h"
#include "metricsinfo.h"
@ -26,6 +27,8 @@
#include "support/filetools.h"
#include <boost/bind.hpp>
namespace graphics = lyx::graphics;
using lyx::support::AbsolutePath;
@ -35,22 +38,29 @@ using std::string;
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)
{}
auto_ptr<RenderBase> RenderGraphic::clone() const
{
return auto_ptr<RenderBase>(new RenderGraphic(*this));
loader_.connect(boost::bind(&LyX::updateInset,
boost::cref(LyX::cref()), inset));
}
auto_ptr<RenderBase> RenderGraphic::clone(InsetBase const * inset) const
{
return auto_ptr<RenderBase>(new RenderGraphic(*this, inset));
}
@ -75,12 +85,6 @@ bool RenderGraphic::hasFileChanged() const
}
boost::signals::connection RenderGraphic::connect(slot_type const & slot) const
{
return loader_.connect(slot);
}
namespace {
bool displayGraphic(graphics::Params const & params)

View File

@ -17,15 +17,13 @@
#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;
@ -38,12 +36,6 @@ public:
/// 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; }

View File

@ -17,6 +17,7 @@
#include "dimension.h"
#include "gettext.h"
#include "LColor.h"
#include "lyx_main.h"
#include "metricsinfo.h"
#include "frontends/font_metrics.h"
@ -43,22 +44,25 @@ bool RenderPreview::activated()
}
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));
}
@ -142,12 +146,6 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const
}
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())
@ -224,10 +222,16 @@ void RenderPreview::imageReady(graphics::PreviewImage const & pimage)
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);

View File

@ -44,9 +44,9 @@ public:
/// 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;
@ -75,10 +75,6 @@ public:
/// 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; }
@ -100,14 +96,14 @@ private:
*/
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;
///
@ -117,7 +113,9 @@ public:
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