+2003-10-09 Angus Leeming <leeming@lyx.org>
+
+ * PreviewedInset.[Ch]: move PreviewedInset out of namespace lyx::graphics.
+ Remove the inset and view member functions.
+ Add a new connect member function and preview_ready_signal_ member
+ variable, to enable the class to tell an arbirary connectee that the
+ preview is ready.
+
2003-10-09 Angus Leeming <leeming@lyx.org>
* PreviewedInset.[Ch] (removePreview, previewReady): these functions
#include "PreviewLoader.h"
#include "Previews.h"
-#include "BufferView.h"
-
-#include "insets/inset.h"
-
#include "support/lstrings.h"
#include <boost/bind.hpp>
-namespace support = lyx::support;
-
+namespace graphics = lyx::graphics;
+namespace support = lyx::support;
-namespace lyx {
-namespace graphics {
bool PreviewedInset::activated()
{
- return Previews::activated();
+ return graphics::Previews::activated();
}
-PreviewedInset::PreviewedInset(InsetOld & inset)
- : inset_(inset), pimage_(0)
+PreviewedInset::PreviewedInset()
+ : pimage_(0)
{}
-BufferView * PreviewedInset::view() const
+boost::signals::connection PreviewedInset::connect(slot_type const & slot)
{
- return inset_.view();
+ return preview_ready_signal_.connect(slot);
}
void PreviewedInset::generatePreview(Buffer const & buffer)
{
- if (!Previews::activated() || !previewWanted(buffer))
+ if (!activated() || !previewWanted(buffer))
return;
- Previews & previews = Previews::get();
- PreviewLoader & loader = previews.loader(buffer);
+ graphics::Previews & previews = graphics::Previews::get();
+ graphics::PreviewLoader & loader = previews.loader(buffer);
addPreview(loader);
if (!snippet_.empty())
loader.startLoading();
}
-void PreviewedInset::addPreview(PreviewLoader & ploader)
+void PreviewedInset::addPreview(graphics::PreviewLoader & ploader)
{
- if (!Previews::activated() || !previewWanted(ploader.buffer()))
+ if (!activated() || !previewWanted(ploader.buffer()))
return;
snippet_ = support::trim(latexString(ploader.buffer()));
if (snippet_.empty())
return;
- Previews & previews = Previews::get();
- PreviewLoader & loader = previews.loader(buffer);
+ graphics::Previews & previews = graphics::Previews::get();
+ graphics::PreviewLoader & loader = previews.loader(buffer);
loader.remove(snippet_);
snippet_.erase();
pimage_ = 0;
bool PreviewedInset::previewReady(Buffer const & buffer) const
{
- if (!Previews::activated() || !previewWanted(buffer))
+ if (!activated() || !previewWanted(buffer))
return false;
if (!pimage_ || snippet_ != pimage_->snippet()) {
- PreviewLoader & ploader = Previews::get().loader(buffer);
+ graphics::PreviewLoader & ploader =
+ graphics::Previews::get().loader(buffer);
pimage_ = ploader.preview(snippet_);
}
}
-void PreviewedInset::imageReady(PreviewImage const & pimage) const
+void PreviewedInset::imageReady(graphics::PreviewImage const & pimage) const
{
// Check the current snippet is the same as that previewed.
if (snippet_ != pimage.snippet())
return;
pimage_ = &pimage;
-
- if (view())
- view()->updateInset(&inset());
+ preview_ready_signal_();
}
-
-} // namespace graphics
-} // namespace lyx
#ifndef PREVIEWEDINSET_H
#define PREVIEWEDINSET_H
+#include <boost/signals/signal0.hpp>
#include <boost/signals/trackable.hpp>
#include <boost/signals/connection.hpp>
class Buffer;
class BufferView;
-class InsetOld;
namespace lyx {
class PreviewImage;
class PreviewLoader;
+} // namespace graphics
+} // namespace lyx
+
class PreviewedInset : public boost::signals::trackable {
public:
/// a wrapper for Previews::activated()
static bool activated();
///
- PreviewedInset(InsetOld & inset);
+ PreviewedInset();
/** Find the PreviewLoader, add a LaTeX snippet to it and
* start the loading process.
/** Add a LaTeX snippet to the PreviewLoader but do not start the
* loading process.
*/
- void addPreview(PreviewLoader & ploader);
+ void addPreview(lyx::graphics::PreviewLoader & ploader);
/** Remove a snippet from the cache of previews.
* Useful if previewing the contents of a file that has changed.
/// The preview has been generated and is ready to use.
bool previewReady(Buffer const &) const;
- /// If !previewReady() returns 0.
- PreviewImage const * pimage() const;
+ /// If the preview is not ready, returns 0.
+ lyx::graphics::PreviewImage const * const pimage() const { return pimage_; }
+
+ /// 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 &);
protected:
///
virtual ~PreviewedInset() {}
- /// Allow the daughter classes to cast up to the parent inset.
- InsetOld const & inset() const;
- ///
- BufferView * view() const;
private:
/// This method is connected to the PreviewLoader::imageReady signal.
- void imageReady(PreviewImage const &) const;
+ void imageReady(lyx::graphics::PreviewImage const &) const;
/// Does the owning inset want a preview?
virtual bool previewWanted(Buffer const &) const = 0;
/// a wrapper to Inset::latex
virtual std::string const latexString(Buffer const &) const = 0;
- ///
- InsetOld & inset_;
- ///
+ /// The thing that we're trying to generate a preview of.
std::string snippet_;
/// We don't own this. Cached for efficiency reasons.
- mutable PreviewImage const * pimage_;
+ mutable lyx::graphics::PreviewImage const * pimage_;
+
/** Store the connection to the preview loader so that we connect
* only once.
*/
boost::signals::connection ploader_connection_;
-};
-
-
-inline
-PreviewImage const * PreviewedInset::pimage() const
-{
- return pimage_;
-}
-
-inline
-InsetOld const & PreviewedInset::inset() const
-{
- return inset_;
-}
-
-} // namespace graphics
-} // namespace lyx
+ /// This signal is emitted when the preview is ready for display.
+ boost::signal0<void> preview_ready_signal_;
+};
#endif // PREVIEWEDINSET_H
+2003-10-09 Angus Leeming <leeming@lyx.org>
+
+ * insetexternal.[Ch] (statusChanged):
+ * insetgraphics.[Ch] (statusChanged): make a const member function.
+
+ * insetinclude.[Ch]: mods to PreviewImpl due to the changes to
+ PreviewedInset.
+
2003-10-09 Angus Leeming <leeming@lyx.org>
* insetinclude.C (metrics, draw, restartLoading): pass a buffer arg
}
-void InsetExternal::statusChanged()
+void InsetExternal::statusChanged() const
{
BufferView * const bv = renderer_->view();
if (bv)
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
*/
- void statusChanged();
+ void statusChanged() const;
/// The current params
InsetExternalParams params_;
}
-void InsetGraphics::statusChanged()
+void InsetGraphics::statusChanged() const
{
BufferView * bv = graphic_->view();
if (bv)
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
*/
- void statusChanged();
+ void statusChanged() const;
/// Read the inset native format
void readInsetGraphics(LyXLex & lex, std::string const & bufpath);
extern BufferList bufferlist;
-class InsetInclude::PreviewImpl : public lyx::graphics::PreviewedInset {
+class InsetInclude::PreviewImpl : public PreviewedInset {
public:
///
- PreviewImpl(InsetInclude & p) : PreviewedInset(p) {}
+ PreviewImpl(InsetInclude const & p) : parent_(p) {}
///
bool previewWanted(Buffer const &) const;
///
string const latexString(Buffer const &) const;
///
- InsetInclude const & parent() const {
- return dynamic_cast<InsetInclude const &>(inset());
- }
-
///
bool monitoring() const { return monitor_.get(); }
///
void restartLoading();
///
boost::scoped_ptr<FileMonitor> monitor_;
+ ///
+ InsetInclude const & parent_;
};
: params_(p), include_label(uniqueID()),
preview_(new PreviewImpl(*this)),
set_label_(false)
-{}
+{
+ preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
+}
InsetInclude::InsetInclude(InsetInclude const & other)
include_label(other.include_label),
preview_(new PreviewImpl(*this)),
set_label_(other.set_label_)
-{}
+{
+ preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
+}
InsetInclude::~InsetInclude()
bool isVerbatim(InsetCommandParams const & params)
{
string const command_name = params.getCmdName();
- return command_name == "verbatiminput" ||
+ return command_name == "verbatiminput" ||
command_name == "verbatiminput*";
}
if (preview_->monitoring())
preview_->stopMonitoring();
- if (lyx::graphics::PreviewedInset::activated() &&
- type(params_) == INPUT)
+ if (PreviewedInset::activated() && type(params_) == INPUT)
preview_->generatePreview(buffer);
}
// preview stuff
//
+void InsetInclude::statusChanged() const
+{
+ if (view())
+ view()->updateInset(this);
+}
+
+
void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
{
preview_->addPreview(ploader);
bool InsetInclude::PreviewImpl::previewWanted(Buffer const & buffer) const
{
- string const included_file = includedFilename(buffer, parent().params());
+ string const included_file = includedFilename(buffer, parent_.params());
- return type(parent().params_) == INPUT &&
- parent().params_.preview() &&
+ return type(parent_.params_) == INPUT &&
+ parent_.params_.preview() &&
IsFileReadable(included_file);
}
ostringstream os;
LatexRunParams runparams;
runparams.flavor = LatexRunParams::LATEX;
- parent().latex(buffer, os, runparams);
+ parent_.latex(buffer, os, runparams);
return os.str();
}
void InsetInclude::PreviewImpl::restartLoading()
{
- if (!view())
+ BufferView * const view = parent_.view();
+ if (!view)
return;
- view()->updateInset(&parent());
- if (view()->buffer()) {
- Buffer const & buffer = *view()->buffer();
+ view->updateInset(&parent_);
+ if (view->buffer()) {
+ Buffer const & buffer = *view->buffer();
removePreview(buffer);
generatePreview(buffer);
}
void addPreview(lyx::graphics::PreviewLoader &) const;
private:
+ /// Slot receiving a signal that the preview is ready to display.
+ void statusChanged() const;
+
friend class InsetIncludeMailer;
/// set the parameters
+2003-10-09 Angus Leeming <leeming@lyx.org>
+
+ * formula.[Ch]: mods to PreviewImpl due to the changes to
+ PreviewedInset.
+
2003-10-09 Angus Leeming <leeming@lyx.org>
* formula.C (metrics, draw): pass a buffer arg to PreviewedInset's
#include "support/std_sstream.h"
+#include <boost/bind.hpp>
using std::string;
using std::ostream;
using std::endl;
-class InsetFormula::PreviewImpl : public lyx::graphics::PreviewedInset {
+class InsetFormula::PreviewImpl : public PreviewedInset {
public:
///
- PreviewImpl(InsetFormula & p) : PreviewedInset(p) {}
+ PreviewImpl(InsetFormula const & p) : parent_(p) {}
private:
///
///
string const latexString(Buffer const &) const;
///
- InsetFormula const & parent() const
- {
- return dynamic_cast<InsetFormula const &>(inset());
- }
+ InsetFormula const & parent_;
};
-
InsetFormula::InsetFormula(bool chemistry)
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{
+ preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
if (chemistry)
mutate("chemistry");
}
: InsetFormulaBase(other),
par_(other.par_),
preview_(new PreviewImpl(*this))
-{}
+{
+ preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
+}
InsetFormula::InsetFormula(BufferView *)
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{
- //view_ = bv->owner()->view();
+ preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
}
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{
+ preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
if (!data.size())
return;
if (!mathed_parse_normal(par_, data))
}
-
InsetFormula::~InsetFormula()
{}
// preview stuff
//
+void InsetFormula::statusChanged() const
+{
+ if (view())
+ view()->updateInset(this);
+}
+
+
void InsetFormula::addPreview(lyx::graphics::PreviewLoader & ploader) const
{
preview_->addPreview(ploader);
bool InsetFormula::PreviewImpl::previewWanted(Buffer const &) const
{
- return !parent().par_->asNestInset()->editing();
+ return !parent_.par_->asNestInset()->editing();
}
{
ostringstream ls;
WriteStream wi(ls, false, false);
- parent().par_->write(wi);
+ parent_.par_->write(wi);
return ls.str();
}
void mutate(std::string const & type);
private:
+ /// Slot receiving a signal that the preview is ready to display.
+ void statusChanged() const;
/// available in AMS only?
bool ams() const;