mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
RenderButton, RenderGraphic and RenderPreview now have a common lineage.
Almost sane code ;-) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7894 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f690ef67a6
commit
dff822442a
@ -168,7 +168,7 @@ src/insets/insettheorem.C
|
||||
src/insets/insettoc.C
|
||||
src/insets/inseturl.C
|
||||
src/insets/insetwrap.C
|
||||
src/insets/renderers.C
|
||||
src/insets/render_graphic.C
|
||||
src/ispell.C
|
||||
src/kbsequence.C
|
||||
src/lengthcommon.C
|
||||
@ -188,7 +188,6 @@ src/mathed/ref_inset.C
|
||||
src/paragraph.C
|
||||
src/paragraph_funcs.C
|
||||
src/rowpainter.C
|
||||
src/support/path_defines.C
|
||||
src/text.C
|
||||
src/text2.C
|
||||
src/text3.C
|
||||
|
@ -1,3 +1,9 @@
|
||||
2003-10-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* PreviewedInset.[Ch]: removed.
|
||||
|
||||
* Makefile.am: remove PreviewedInset.[Ch].
|
||||
|
||||
2003-10-09 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* PreviewedInset.[Ch] (previewReady): remove the side effects.
|
||||
|
@ -26,6 +26,4 @@ libgraphics_la_SOURCES = \
|
||||
PreviewLoader.h \
|
||||
PreviewLoader.C \
|
||||
Previews.h \
|
||||
Previews.C \
|
||||
PreviewedInset.h \
|
||||
PreviewedInset.C
|
||||
Previews.C
|
||||
|
@ -1,109 +0,0 @@
|
||||
/**
|
||||
* \file PreviewedInset.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 "PreviewedInset.h"
|
||||
#include "PreviewImage.h"
|
||||
#include "PreviewLoader.h"
|
||||
#include "Previews.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace graphics = lyx::graphics;
|
||||
namespace support = lyx::support;
|
||||
|
||||
|
||||
bool PreviewedInset::activated()
|
||||
{
|
||||
return graphics::Previews::activated();
|
||||
}
|
||||
|
||||
|
||||
PreviewedInset::PreviewedInset()
|
||||
: pimage_(0)
|
||||
{}
|
||||
|
||||
|
||||
boost::signals::connection PreviewedInset::connect(slot_type const & slot)
|
||||
{
|
||||
return preview_ready_signal_.connect(slot);
|
||||
}
|
||||
|
||||
|
||||
void PreviewedInset::generatePreview(Buffer const & buffer)
|
||||
{
|
||||
if (!activated() || !previewWanted(buffer))
|
||||
return;
|
||||
|
||||
graphics::Previews & previews = graphics::Previews::get();
|
||||
graphics::PreviewLoader & loader = previews.loader(buffer);
|
||||
addPreview(loader);
|
||||
if (!snippet_.empty())
|
||||
loader.startLoading();
|
||||
}
|
||||
|
||||
|
||||
void PreviewedInset::addPreview(graphics::PreviewLoader & ploader)
|
||||
{
|
||||
if (!activated() || !previewWanted(ploader.buffer()))
|
||||
return;
|
||||
|
||||
snippet_ = support::trim(latexString(ploader.buffer()));
|
||||
pimage_ = 0;
|
||||
if (snippet_.empty())
|
||||
return;
|
||||
|
||||
pimage_ = ploader.preview(snippet_);
|
||||
if (pimage_)
|
||||
return;
|
||||
|
||||
// If this is the first time of calling, connect to the
|
||||
// PreviewLoader signal that'll inform us when the preview image
|
||||
// is ready for loading.
|
||||
if (!ploader_connection_.connected()) {
|
||||
ploader_connection_ = ploader.connect(
|
||||
boost::bind(&PreviewedInset::imageReady, this, _1));
|
||||
}
|
||||
|
||||
ploader.add(snippet_);
|
||||
}
|
||||
|
||||
|
||||
void PreviewedInset::removePreview(Buffer const & buffer)
|
||||
{
|
||||
if (snippet_.empty())
|
||||
return;
|
||||
|
||||
graphics::Previews & previews = graphics::Previews::get();
|
||||
graphics::PreviewLoader & loader = previews.loader(buffer);
|
||||
loader.remove(snippet_);
|
||||
snippet_.erase();
|
||||
pimage_ = 0;
|
||||
}
|
||||
|
||||
|
||||
bool PreviewedInset::previewReady() const
|
||||
{
|
||||
return pimage_ ? pimage_->image() : false;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
preview_ready_signal_();
|
||||
}
|
@ -1,3 +1,29 @@
|
||||
2003-10-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* renderers.[Ch]: removed.
|
||||
|
||||
* render_base.[Ch]:
|
||||
* render_button.[Ch]:
|
||||
* render_graphic.[Ch]:
|
||||
* render_preview.[Ch]: new files. The first three are split out of
|
||||
renderers.[Ch]. The last one is a renamed PreviewedInset.[Ch]. which
|
||||
contains a re-worked InsetInclude::PreviewImpl also.
|
||||
|
||||
* Makefile.am: reflect the changed files.
|
||||
|
||||
* insetcommand.h:
|
||||
* insetexternal.[Ch]:
|
||||
* insetgraphics.[Ch]: trivial changes ButtonRenderer -> RenderButton, etc.
|
||||
|
||||
* insetinclude.[Ch]: changes reflecting the change from
|
||||
InsetInclude::PreviewImpl to RenderMonitoredPreview.
|
||||
|
||||
* insethfill.C:
|
||||
* insetindex.C:
|
||||
* insetlabel.C:
|
||||
* insettoc.C:
|
||||
* inseturl.C: add #include "support/std_ostream.h"
|
||||
|
||||
2003-10-09 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* insetinclude.C (metrics, draw): no longer need to pass a Buffer arg
|
||||
|
@ -19,8 +19,14 @@ libinsets_la_SOURCES = \
|
||||
ExternalTemplate.h \
|
||||
ExternalTransforms.C \
|
||||
ExternalTransforms.h \
|
||||
renderers.C \
|
||||
renderers.h \
|
||||
render_base.C \
|
||||
render_base.h \
|
||||
render_button.C \
|
||||
render_button.h \
|
||||
render_graphic.C \
|
||||
render_graphic.h \
|
||||
render_preview.C \
|
||||
render_preview.h \
|
||||
inset.C \
|
||||
inset.h \
|
||||
insetbase.h \
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "inset.h"
|
||||
#include "insetcommandparams.h"
|
||||
#include "renderers.h"
|
||||
#include "render_button.h"
|
||||
#include "mailinset.h"
|
||||
|
||||
// Created by Alejandro 970222
|
||||
@ -67,7 +67,7 @@ public:
|
||||
///
|
||||
std::string const & getOptions() const { return p_.getOptions(); }
|
||||
///
|
||||
ButtonRenderer & button() const { return button_; }
|
||||
RenderButton & button() const { return button_; }
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -89,7 +89,7 @@ private:
|
||||
///
|
||||
InsetCommandParams p_;
|
||||
mutable bool set_label_;
|
||||
mutable ButtonRenderer button_;
|
||||
mutable RenderButton button_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -11,9 +11,10 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "insetexternal.h"
|
||||
#include "insets/renderers.h"
|
||||
#include "insets/ExternalSupport.h"
|
||||
#include "insets/ExternalTemplate.h"
|
||||
#include "insets/render_button.h"
|
||||
#include "insets/render_graphic.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "BufferView.h"
|
||||
@ -358,7 +359,7 @@ bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
|
||||
|
||||
|
||||
InsetExternal::InsetExternal()
|
||||
: renderer_(new ButtonRenderer)
|
||||
: renderer_(new RenderButton)
|
||||
{}
|
||||
|
||||
|
||||
@ -368,8 +369,8 @@ InsetExternal::InsetExternal(InsetExternal const & other)
|
||||
params_(other.params_),
|
||||
renderer_(other.renderer_->clone())
|
||||
{
|
||||
GraphicRenderer * ptr =
|
||||
dynamic_cast<GraphicRenderer *>(renderer_.get());
|
||||
RenderGraphic * ptr =
|
||||
dynamic_cast<RenderGraphic *>(renderer_.get());
|
||||
if (ptr)
|
||||
ptr->connect(boost::bind(&InsetExternal::statusChanged, this));
|
||||
}
|
||||
@ -503,20 +504,20 @@ void InsetExternal::setParams(InsetExternalParams const & p,
|
||||
params_.display == lyx::graphics::NoDisplay);
|
||||
|
||||
if (display_button) {
|
||||
ButtonRenderer * button_ptr =
|
||||
dynamic_cast<ButtonRenderer *>(renderer_.get());
|
||||
RenderButton * button_ptr =
|
||||
dynamic_cast<RenderButton *>(renderer_.get());
|
||||
if (!button_ptr) {
|
||||
button_ptr = new ButtonRenderer;
|
||||
button_ptr = new RenderButton;
|
||||
renderer_.reset(button_ptr);
|
||||
}
|
||||
|
||||
button_ptr->update(getScreenLabel(params_, buffer), true);
|
||||
|
||||
} else {
|
||||
GraphicRenderer * graphic_ptr =
|
||||
dynamic_cast<GraphicRenderer *>(renderer_.get());
|
||||
RenderGraphic * graphic_ptr =
|
||||
dynamic_cast<RenderGraphic *>(renderer_.get());
|
||||
if (!graphic_ptr) {
|
||||
graphic_ptr = new GraphicRenderer;
|
||||
graphic_ptr = new RenderGraphic;
|
||||
graphic_ptr->connect(
|
||||
boost::bind(&InsetExternal::statusChanged, this));
|
||||
renderer_.reset(graphic_ptr);
|
||||
|
@ -79,7 +79,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class RenderInset;
|
||||
class RenderBase;
|
||||
|
||||
///
|
||||
class InsetExternal : public InsetOld, public boost::signals::trackable
|
||||
@ -136,7 +136,7 @@ private:
|
||||
/// The current params
|
||||
InsetExternalParams params_;
|
||||
/// The thing that actually draws the image on LyX's screen.
|
||||
boost::scoped_ptr<RenderInset> renderer_;
|
||||
boost::scoped_ptr<RenderBase> renderer_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@ TODO
|
||||
#include <config.h>
|
||||
|
||||
#include "insets/insetgraphics.h"
|
||||
#include "insets/renderers.h"
|
||||
#include "insets/render_graphic.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "BufferView.h"
|
||||
@ -152,7 +152,7 @@ string findTargetFormat(string const & suffix, LatexRunParams const & runparams)
|
||||
|
||||
InsetGraphics::InsetGraphics()
|
||||
: graphic_label(uniqueID()),
|
||||
graphic_(new GraphicRenderer)
|
||||
graphic_(new RenderGraphic)
|
||||
{
|
||||
graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
|
||||
}
|
||||
@ -162,7 +162,7 @@ InsetGraphics::InsetGraphics(InsetGraphics const & ig)
|
||||
: InsetOld(ig),
|
||||
boost::signals::trackable(),
|
||||
graphic_label(uniqueID()),
|
||||
graphic_(new GraphicRenderer(*ig.graphic_))
|
||||
graphic_(new RenderGraphic(*ig.graphic_))
|
||||
{
|
||||
graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
|
||||
setParams(ig.params());
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
|
||||
class Dialogs;
|
||||
class GraphicRenderer;
|
||||
class RenderGraphic;
|
||||
class LaTeXFeatures;
|
||||
|
||||
///
|
||||
@ -104,7 +104,7 @@ private:
|
||||
std::string const graphic_label;
|
||||
|
||||
/// The thing that actually draws the image on LyX's screen.
|
||||
boost::scoped_ptr<GraphicRenderer> const graphic_;
|
||||
boost::scoped_ptr<RenderGraphic> const graphic_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
#include "insethfill.h"
|
||||
|
||||
#include "support/std_ostream.h"
|
||||
|
||||
using std::ostream;
|
||||
|
||||
|
||||
|
@ -27,24 +27,25 @@
|
||||
|
||||
#include "frontends/Painter.h"
|
||||
|
||||
#include "graphics/PreviewedInset.h"
|
||||
#include "graphics/PreviewImage.h"
|
||||
#include "graphics/PreviewLoader.h"
|
||||
|
||||
#include "insets/render_preview.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/FileMonitor.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h" // contains
|
||||
#include "support/tostr.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "support/std_ostream.h"
|
||||
#include "support/std_sstream.h"
|
||||
|
||||
using lyx::support::AddName;
|
||||
using lyx::support::ChangeExtension;
|
||||
using lyx::support::contains;
|
||||
using lyx::support::FileInfo;
|
||||
using lyx::support::FileMonitor;
|
||||
using lyx::support::GetFileContents;
|
||||
using lyx::support::IsFileReadable;
|
||||
using lyx::support::IsLyXFilename;
|
||||
@ -65,33 +66,6 @@ using std::ostringstream;
|
||||
extern BufferList bufferlist;
|
||||
|
||||
|
||||
class InsetInclude::PreviewImpl : public PreviewedInset {
|
||||
public:
|
||||
///
|
||||
PreviewImpl(InsetInclude const & p) : parent_(p) {}
|
||||
|
||||
///
|
||||
bool previewWanted(Buffer const &) const;
|
||||
///
|
||||
string const latexString(Buffer const &) const;
|
||||
///
|
||||
///
|
||||
bool monitoring() const { return monitor_.get(); }
|
||||
///
|
||||
void startMonitoring(string const & file);
|
||||
///
|
||||
void stopMonitoring() { monitor_.reset(); }
|
||||
|
||||
private:
|
||||
/// Invoked by monitor_ should the parent file change.
|
||||
void restartLoading();
|
||||
///
|
||||
boost::scoped_ptr<FileMonitor> monitor_;
|
||||
///
|
||||
InsetInclude const & parent_;
|
||||
};
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
string const uniqueID()
|
||||
@ -105,10 +79,11 @@ string const uniqueID()
|
||||
|
||||
InsetInclude::InsetInclude(InsetCommandParams const & p)
|
||||
: params_(p), include_label(uniqueID()),
|
||||
preview_(new PreviewImpl(*this)),
|
||||
preview_(new RenderMonitoredPreview),
|
||||
set_label_(false)
|
||||
{
|
||||
preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
|
||||
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
|
||||
}
|
||||
|
||||
|
||||
@ -116,10 +91,11 @@ InsetInclude::InsetInclude(InsetInclude const & other)
|
||||
: InsetOld(other),
|
||||
params_(other.params_),
|
||||
include_label(other.include_label),
|
||||
preview_(new PreviewImpl(*this)),
|
||||
preview_(new RenderMonitoredPreview),
|
||||
set_label_(other.set_label_)
|
||||
{
|
||||
preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
|
||||
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
|
||||
}
|
||||
|
||||
|
||||
@ -201,6 +177,23 @@ bool isVerbatim(InsetCommandParams const & params)
|
||||
command_name == "verbatiminput*";
|
||||
}
|
||||
|
||||
|
||||
string const masterFilename(Buffer const & buffer)
|
||||
{
|
||||
return buffer.fileName();
|
||||
}
|
||||
|
||||
|
||||
string const includedFilename(Buffer const & buffer,
|
||||
InsetCommandParams const & params)
|
||||
{
|
||||
return MakeAbsPath(params.getContents(),
|
||||
OnlyPath(masterFilename(buffer)));
|
||||
}
|
||||
|
||||
|
||||
void generate_preview(RenderPreview &, InsetInclude const &, Buffer const &);
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
@ -212,8 +205,8 @@ void InsetInclude::set(InsetCommandParams const & p, Buffer const & buffer)
|
||||
if (preview_->monitoring())
|
||||
preview_->stopMonitoring();
|
||||
|
||||
if (PreviewedInset::activated() && type(params_) == INPUT)
|
||||
preview_->generatePreview(buffer);
|
||||
if (type(params_) == INPUT)
|
||||
generate_preview(*preview_, *this, buffer);
|
||||
}
|
||||
|
||||
|
||||
@ -272,20 +265,6 @@ string const InsetInclude::getScreenLabel(Buffer const &) const
|
||||
|
||||
namespace {
|
||||
|
||||
string const masterFilename(Buffer const & buffer)
|
||||
{
|
||||
return buffer.fileName();
|
||||
}
|
||||
|
||||
|
||||
string const includedFilename(Buffer const & buffer,
|
||||
InsetCommandParams const & params)
|
||||
{
|
||||
return MakeAbsPath(params.getContents(),
|
||||
OnlyPath(masterFilename(buffer)));
|
||||
}
|
||||
|
||||
|
||||
/// return true if the file is or got loaded.
|
||||
bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
|
||||
{
|
||||
@ -598,51 +577,63 @@ void InsetInclude::statusChanged() const
|
||||
}
|
||||
|
||||
|
||||
void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
|
||||
void InsetInclude::fileChanged() const
|
||||
{
|
||||
preview_->addPreview(ploader);
|
||||
BufferView * const bv = view();
|
||||
if (!bv)
|
||||
return;
|
||||
bv->updateInset(this);
|
||||
|
||||
if (!bv->buffer())
|
||||
return;
|
||||
Buffer const & buffer = *bv->buffer();
|
||||
|
||||
preview_->removePreview(buffer);
|
||||
generate_preview(*preview_.get(), *this, buffer);
|
||||
}
|
||||
|
||||
|
||||
bool InsetInclude::PreviewImpl::previewWanted(Buffer const & buffer) const
|
||||
{
|
||||
string const included_file = includedFilename(buffer, parent_.params());
|
||||
namespace {
|
||||
|
||||
return type(parent_.params_) == INPUT &&
|
||||
parent_.params_.preview() &&
|
||||
bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
|
||||
{
|
||||
string const included_file = includedFilename(buffer, params);
|
||||
|
||||
return type(params) == INPUT && params.preview() &&
|
||||
IsFileReadable(included_file);
|
||||
}
|
||||
|
||||
|
||||
string const InsetInclude::PreviewImpl::latexString(Buffer const & buffer) const
|
||||
string const latex_string(InsetInclude const & inset, Buffer const & buffer)
|
||||
{
|
||||
ostringstream os;
|
||||
LatexRunParams runparams;
|
||||
runparams.flavor = LatexRunParams::LATEX;
|
||||
parent_.latex(buffer, os, runparams);
|
||||
inset.latex(buffer, os, runparams);
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
void InsetInclude::PreviewImpl::startMonitoring(string const & file)
|
||||
void generate_preview(RenderPreview & renderer,
|
||||
InsetInclude const & inset,
|
||||
Buffer const & buffer)
|
||||
{
|
||||
monitor_.reset(new FileMonitor(file, 2000));
|
||||
monitor_->connect(boost::bind(&PreviewImpl::restartLoading, this));
|
||||
monitor_->start();
|
||||
InsetCommandParams const & params = inset.params();
|
||||
if (RenderPreview::activated() && preview_wanted(params, buffer)) {
|
||||
string const snippet = latex_string(inset, buffer);
|
||||
renderer.generatePreview(snippet, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
void InsetInclude::PreviewImpl::restartLoading()
|
||||
|
||||
void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
|
||||
{
|
||||
BufferView * const view = parent_.view();
|
||||
if (!view)
|
||||
return;
|
||||
view->updateInset(&parent_);
|
||||
if (view->buffer()) {
|
||||
Buffer const & buffer = *view->buffer();
|
||||
removePreview(buffer);
|
||||
generatePreview(buffer);
|
||||
if (preview_wanted(params(), ploader.buffer())) {
|
||||
string const snippet = latex_string(*this, ploader.buffer());
|
||||
preview_->addPreview(snippet, ploader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,15 +14,15 @@
|
||||
|
||||
#include "inset.h"
|
||||
#include "insetcommandparams.h"
|
||||
#include "renderers.h"
|
||||
#include "render_button.h"
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
|
||||
class Buffer;
|
||||
class Dimension;
|
||||
struct LaTeXFeatures;
|
||||
class RenderMonitoredPreview;
|
||||
|
||||
// Created by AAS 970521
|
||||
|
||||
/// for including tex/lyx files
|
||||
class InsetInclude: public InsetOld {
|
||||
@ -85,6 +85,11 @@ public:
|
||||
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.
|
||||
*/
|
||||
void fileChanged() const;
|
||||
|
||||
|
||||
friend class InsetIncludeMailer;
|
||||
|
||||
@ -102,15 +107,12 @@ private:
|
||||
/// holds the entity name that defines the file location (SGML)
|
||||
std::string const include_label;
|
||||
|
||||
/// Use the Pimpl idiom to hide the internals of the previewer.
|
||||
class PreviewImpl;
|
||||
friend class PreviewImpl;
|
||||
/// The pointer never changes although *preview_'s contents may.
|
||||
boost::scoped_ptr<PreviewImpl> const preview_;
|
||||
boost::scoped_ptr<RenderMonitoredPreview> const preview_;
|
||||
|
||||
/// cache
|
||||
mutable bool set_label_;
|
||||
mutable ButtonRenderer button_;
|
||||
mutable RenderButton button_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "metricsinfo.h"
|
||||
|
||||
#include "support/std_ostream.h"
|
||||
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include "support/std_ostream.h"
|
||||
|
||||
using lyx::support::escape;
|
||||
|
||||
using std::string;
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "metricsinfo.h"
|
||||
#include "toc.h"
|
||||
|
||||
#include "support/std_ostream.h"
|
||||
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include "support/std_ostream.h"
|
||||
|
||||
using lyx::support::subst;
|
||||
|
||||
|
21
src/insets/render_base.C
Normal file
21
src/insets/render_base.C
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* \file render_base.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 "render_base.h"
|
||||
|
||||
#include "BufferView.h"
|
||||
|
||||
|
||||
BufferView * RenderBase::view() const
|
||||
{
|
||||
return view_.lock().get();
|
||||
}
|
48
src/insets/render_base.h
Normal file
48
src/insets/render_base.h
Normal file
@ -0,0 +1,48 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file render_base.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 RENDER_BASE_H
|
||||
#define RENDER_BASE_H
|
||||
|
||||
#include "dimension.h"
|
||||
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
class BufferView;
|
||||
class MetricsInfo;
|
||||
class PainterInfo;
|
||||
|
||||
|
||||
class RenderBase {
|
||||
public:
|
||||
virtual ~RenderBase() {}
|
||||
|
||||
virtual RenderBase * 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:
|
||||
RenderBase() {}
|
||||
RenderBase(RenderBase const &) {}
|
||||
void operator=(RenderBase const &) {}
|
||||
|
||||
/// These are cached variables (are not copied).
|
||||
mutable boost::weak_ptr<BufferView> view_;
|
||||
mutable Dimension dim_;
|
||||
};
|
||||
|
||||
#endif // NOT RENDER_BASE_H
|
74
src/insets/render_button.C
Normal file
74
src/insets/render_button.C
Normal file
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* \file render_button.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 "render_button.h"
|
||||
|
||||
#include "BufferView.h"
|
||||
#include "LColor.h"
|
||||
#include "metricsinfo.h"
|
||||
|
||||
#include "frontends/font_metrics.h"
|
||||
#include "frontends/LyXView.h"
|
||||
#include "frontends/Painter.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
RenderButton::RenderButton()
|
||||
: editable_(false)
|
||||
{}
|
||||
|
||||
|
||||
RenderBase * RenderButton::clone() const
|
||||
{
|
||||
return new RenderButton(*this);
|
||||
}
|
||||
|
||||
|
||||
void RenderButton::update(string const & text, bool editable)
|
||||
{
|
||||
text_ = text;
|
||||
editable_ = editable;
|
||||
}
|
||||
|
||||
|
||||
void RenderButton::metrics(MetricsInfo &, Dimension & dim) const
|
||||
{
|
||||
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 RenderButton::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
BOOST_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);
|
||||
font.decSize();
|
||||
|
||||
if (editable_) {
|
||||
pi.pain.buttonText(x + 2, y, text_, font);
|
||||
} else {
|
||||
pi.pain.rectText(x + 2, y, text_, font,
|
||||
LColor::commandbg, LColor::commandframe);
|
||||
}
|
||||
}
|
47
src/insets/render_button.h
Normal file
47
src/insets/render_button.h
Normal file
@ -0,0 +1,47 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file render_button.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 RENDER_BUTTON_H
|
||||
#define RENDER_BUTTON_H
|
||||
|
||||
#include "render_base.h"
|
||||
#include "box.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
class RenderButton : public RenderBase
|
||||
{
|
||||
public:
|
||||
RenderButton();
|
||||
|
||||
RenderBase * clone() const;
|
||||
|
||||
/// 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;
|
||||
|
||||
/// Provide the text for the button
|
||||
void update(std::string const &, bool editable);
|
||||
|
||||
/// The "sensitive area" box, i.e., the button area
|
||||
Box box() const { return button_box_; }
|
||||
///
|
||||
void setBox(Box b) { button_box_ = b; }
|
||||
|
||||
private:
|
||||
/// The stored data.
|
||||
std::string text_;
|
||||
bool editable_;
|
||||
Box button_box_;
|
||||
};
|
||||
|
||||
#endif // NOT RENDER_BUTTON_H
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* \file renderers.C
|
||||
* \file render_graphic.C
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "insets/renderers.h"
|
||||
#include "render_graphic.h"
|
||||
|
||||
#include "insets/inset.h"
|
||||
|
||||
@ -34,106 +34,26 @@ using lyx::support::OnlyFilename;
|
||||
using std::string;
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
BOOST_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
|
||||
{
|
||||
BOOST_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);
|
||||
font.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()
|
||||
RenderGraphic::RenderGraphic()
|
||||
: checksum_(0)
|
||||
{}
|
||||
|
||||
|
||||
GraphicRenderer::GraphicRenderer(GraphicRenderer const & other)
|
||||
: RenderInset(other),
|
||||
RenderGraphic::RenderGraphic(RenderGraphic const & other)
|
||||
: RenderBase(other),
|
||||
loader_(other.loader_),
|
||||
params_(other.params_),
|
||||
checksum_(0)
|
||||
{}
|
||||
|
||||
|
||||
RenderInset * GraphicRenderer::clone() const
|
||||
RenderBase * RenderGraphic::clone() const
|
||||
{
|
||||
return new GraphicRenderer(*this);
|
||||
return new RenderGraphic(*this);
|
||||
}
|
||||
|
||||
|
||||
void GraphicRenderer::update(lyx::graphics::Params const & params)
|
||||
void RenderGraphic::update(lyx::graphics::Params const & params)
|
||||
{
|
||||
params_ = params;
|
||||
|
||||
@ -144,7 +64,7 @@ void GraphicRenderer::update(lyx::graphics::Params const & params)
|
||||
}
|
||||
|
||||
|
||||
bool GraphicRenderer::hasFileChanged() const
|
||||
bool RenderGraphic::hasFileChanged() const
|
||||
{
|
||||
unsigned long const new_checksum = loader_.checksum();
|
||||
bool const file_has_changed = checksum_ != new_checksum;
|
||||
@ -154,13 +74,13 @@ bool GraphicRenderer::hasFileChanged() const
|
||||
}
|
||||
|
||||
|
||||
boost::signals::connection GraphicRenderer::connect(slot_type const & slot) const
|
||||
boost::signals::connection RenderGraphic::connect(slot_type const & slot) const
|
||||
{
|
||||
return loader_.connect(slot);
|
||||
}
|
||||
|
||||
|
||||
string const GraphicRenderer::statusMessage() const
|
||||
string const RenderGraphic::statusMessage() const
|
||||
{
|
||||
switch (loader_.status()) {
|
||||
case lyx::graphics::WaitingToLoad:
|
||||
@ -190,7 +110,7 @@ string const GraphicRenderer::statusMessage() const
|
||||
}
|
||||
|
||||
|
||||
bool GraphicRenderer::readyToDisplay() const
|
||||
bool RenderGraphic::readyToDisplay() const
|
||||
{
|
||||
if (!loader_.image() || loader_.status() != lyx::graphics::Ready)
|
||||
return false;
|
||||
@ -198,7 +118,7 @@ bool GraphicRenderer::readyToDisplay() const
|
||||
}
|
||||
|
||||
|
||||
void GraphicRenderer::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
bool image_ready = readyToDisplay();
|
||||
|
||||
@ -234,36 +154,11 @@ void GraphicRenderer::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
}
|
||||
|
||||
|
||||
void GraphicRenderer::draw(PainterInfo & pi, int x, int y) const
|
||||
void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
BOOST_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 != lyx::graphics::NoDisplay &&
|
||||
loader_.status() == lyx::graphics::WaitingToLoad)
|
||||
loader_.startLoading();
|
66
src/insets/render_graphic.h
Normal file
66
src/insets/render_graphic.h
Normal file
@ -0,0 +1,66 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file render_graphic.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 RENDER_GRAPHIC_H
|
||||
#define RENDER_GRAPHIC_H
|
||||
|
||||
#include "render_base.h"
|
||||
|
||||
#include "graphics/GraphicsLoader.h"
|
||||
#include "graphics/GraphicsParams.h"
|
||||
|
||||
#include <boost/signals/signal0.hpp>
|
||||
|
||||
|
||||
class RenderGraphic : public RenderBase
|
||||
{
|
||||
public:
|
||||
RenderGraphic();
|
||||
RenderGraphic(RenderGraphic const &);
|
||||
RenderBase * clone() const;
|
||||
|
||||
/// 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;
|
||||
|
||||
/// Refresh the info about which file to display and how to display it.
|
||||
void update(lyx::graphics::Params const & params);
|
||||
|
||||
/// 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;
|
||||
|
||||
private:
|
||||
/// Not implemented.
|
||||
RenderGraphic & operator=(RenderGraphic const &);
|
||||
|
||||
/// The message to display instead of the graphic itself.
|
||||
std::string const statusMessage() const;
|
||||
|
||||
/// Is the image ready to draw, or should we display a message instead?
|
||||
bool readyToDisplay() const;
|
||||
|
||||
/// The stored data.
|
||||
lyx::graphics::Loader loader_;
|
||||
lyx::graphics::Params params_;
|
||||
|
||||
/// Cached variable (not copied).
|
||||
mutable unsigned long checksum_;
|
||||
};
|
||||
|
||||
|
||||
#endif // NOT RENDER_GRAPHIC_H
|
178
src/insets/render_preview.C
Normal file
178
src/insets/render_preview.C
Normal file
@ -0,0 +1,178 @@
|
||||
/**
|
||||
* \file render_preview.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 "render_preview.h"
|
||||
|
||||
#include "dimension.h"
|
||||
#include "LColor.h"
|
||||
#include "metricsinfo.h"
|
||||
|
||||
#include "frontends/Painter.h"
|
||||
|
||||
#include "graphics/PreviewImage.h"
|
||||
#include "graphics/PreviewLoader.h"
|
||||
#include "graphics/Previews.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace graphics = lyx::graphics;
|
||||
namespace support = lyx::support;
|
||||
|
||||
|
||||
bool RenderPreview::activated()
|
||||
{
|
||||
return graphics::Previews::activated();
|
||||
}
|
||||
|
||||
|
||||
RenderPreview::RenderPreview()
|
||||
: pimage_(0)
|
||||
{}
|
||||
|
||||
|
||||
RenderPreview::RenderPreview(RenderPreview const & other)
|
||||
: RenderBase(other),
|
||||
boost::signals::trackable(),
|
||||
snippet_(other.snippet_),
|
||||
pimage_(0)
|
||||
{}
|
||||
|
||||
|
||||
RenderBase * RenderPreview::clone() const
|
||||
{
|
||||
return new RenderPreview(*this);
|
||||
}
|
||||
|
||||
|
||||
void RenderPreview::metrics(MetricsInfo &, Dimension & dim) const
|
||||
{
|
||||
if (previewReady()) {
|
||||
dim.asc = pimage()->ascent();
|
||||
dim.des = pimage()->descent();
|
||||
dim.wid = pimage()->width();
|
||||
} else {
|
||||
dim.asc = 20;
|
||||
dim.des = 20;
|
||||
dim.wid = 20;
|
||||
}
|
||||
|
||||
dim_ = dim;
|
||||
}
|
||||
|
||||
|
||||
void RenderPreview::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
BOOST_ASSERT(pi.base.bv);
|
||||
view_ = pi.base.bv->owner()->view();
|
||||
|
||||
if (!previewReady())
|
||||
pi.pain.rectangle(x, y - dim_.asc, dim_.wid, dim_.height(),
|
||||
LColor::foreground);
|
||||
else
|
||||
pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(),
|
||||
*(pimage()->image()));
|
||||
}
|
||||
|
||||
|
||||
boost::signals::connection RenderPreview::connect(slot_type const & slot)
|
||||
{
|
||||
return preview_ready_signal_.connect(slot);
|
||||
}
|
||||
|
||||
|
||||
void RenderPreview::generatePreview(string const & latex_snippet,
|
||||
Buffer const & buffer)
|
||||
{
|
||||
if (!activated())
|
||||
return;
|
||||
|
||||
graphics::Previews & previews = graphics::Previews::get();
|
||||
graphics::PreviewLoader & loader = previews.loader(buffer);
|
||||
addPreview(latex_snippet, loader);
|
||||
if (!snippet_.empty())
|
||||
loader.startLoading();
|
||||
}
|
||||
|
||||
|
||||
void RenderPreview::addPreview(string const & latex_snippet,
|
||||
graphics::PreviewLoader & ploader)
|
||||
{
|
||||
if (!activated())
|
||||
return;
|
||||
|
||||
snippet_ = support::trim(latex_snippet);
|
||||
pimage_ = 0;
|
||||
if (snippet_.empty())
|
||||
return;
|
||||
|
||||
pimage_ = ploader.preview(snippet_);
|
||||
if (pimage_)
|
||||
return;
|
||||
|
||||
// If this is the first time of calling, connect to the
|
||||
// PreviewLoader signal that'll inform us when the preview image
|
||||
// is ready for loading.
|
||||
if (!ploader_connection_.connected()) {
|
||||
ploader_connection_ = ploader.connect(
|
||||
boost::bind(&RenderPreview::imageReady, this, _1));
|
||||
}
|
||||
|
||||
ploader.add(snippet_);
|
||||
}
|
||||
|
||||
|
||||
void RenderPreview::removePreview(Buffer const & buffer)
|
||||
{
|
||||
if (snippet_.empty())
|
||||
return;
|
||||
|
||||
graphics::Previews & previews = graphics::Previews::get();
|
||||
graphics::PreviewLoader & loader = previews.loader(buffer);
|
||||
loader.remove(snippet_);
|
||||
snippet_.erase();
|
||||
pimage_ = 0;
|
||||
}
|
||||
|
||||
|
||||
bool RenderPreview::previewReady() const
|
||||
{
|
||||
return pimage_ ? pimage_->image() : false;
|
||||
}
|
||||
|
||||
|
||||
void RenderPreview::imageReady(graphics::PreviewImage const & pimage)
|
||||
{
|
||||
// Check the current snippet is the same as that previewed.
|
||||
if (snippet_ != pimage.snippet())
|
||||
return;
|
||||
|
||||
pimage_ = &pimage;
|
||||
preview_ready_signal_();
|
||||
}
|
||||
|
||||
|
||||
void RenderMonitoredPreview::startMonitoring(string const & file)
|
||||
{
|
||||
monitor_.reset(file);
|
||||
monitor_.start();
|
||||
}
|
||||
|
||||
|
||||
boost::signals::connection
|
||||
RenderMonitoredPreview::fileChanged(slot_type const & slot)
|
||||
{
|
||||
return monitor_.connect(slot);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file PreviewedInset.h
|
||||
* \file render_preview.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
@ -8,13 +8,17 @@
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*
|
||||
* lyx::graphics::PreviewedInset is an abstract base class that can help
|
||||
* lyx::graphics::RenderPreview is an abstract base class that can help
|
||||
* insets to generate previews. The daughter class must instantiate two small
|
||||
* methods. The Inset would own an instance of this daughter class.
|
||||
*/
|
||||
|
||||
#ifndef PREVIEWEDINSET_H
|
||||
#define PREVIEWEDINSET_H
|
||||
#ifndef RENDER_PREVIEW_H
|
||||
#define RENDER_PREVIEW_H
|
||||
|
||||
#include "render_base.h"
|
||||
|
||||
#include "support/FileMonitor.h"
|
||||
|
||||
#include <boost/signals/signal0.hpp>
|
||||
#include <boost/signals/trackable.hpp>
|
||||
@ -22,7 +26,8 @@
|
||||
|
||||
class Buffer;
|
||||
class BufferView;
|
||||
|
||||
class MetricsInfo;
|
||||
class PainterInfo;
|
||||
|
||||
namespace lyx {
|
||||
namespace graphics {
|
||||
@ -33,23 +38,32 @@ class PreviewLoader;
|
||||
} // namespace graphics
|
||||
} // namespace lyx
|
||||
|
||||
class PreviewedInset : public boost::signals::trackable {
|
||||
|
||||
class RenderPreview : public RenderBase, public boost::signals::trackable {
|
||||
public:
|
||||
/// a wrapper for Previews::activated()
|
||||
static bool activated();
|
||||
|
||||
RenderPreview();
|
||||
RenderPreview(RenderPreview const &);
|
||||
RenderBase * clone() const;
|
||||
|
||||
/// Compute the size of the object, returned in dim
|
||||
void metrics(MetricsInfo &, Dimension & dim) const;
|
||||
///
|
||||
PreviewedInset();
|
||||
void draw(PainterInfo & pi, int x, int y) const;
|
||||
|
||||
/** Find the PreviewLoader, add a LaTeX snippet to it and
|
||||
* start the loading process.
|
||||
*/
|
||||
void generatePreview(Buffer const &);
|
||||
void generatePreview(std::string const & latex_snippet,
|
||||
Buffer const &);
|
||||
|
||||
/** Add a LaTeX snippet to the PreviewLoader but do not start the
|
||||
* loading process.
|
||||
*/
|
||||
void addPreview(lyx::graphics::PreviewLoader & ploader);
|
||||
void addPreview(std::string const & latex_snippet,
|
||||
lyx::graphics::PreviewLoader & ploader);
|
||||
|
||||
/** Remove a snippet from the cache of previews.
|
||||
* Useful if previewing the contents of a file that has changed.
|
||||
@ -60,30 +74,25 @@ public:
|
||||
bool previewReady() const;
|
||||
|
||||
/// If the preview is not ready, returns 0.
|
||||
lyx::graphics::PreviewImage const * const pimage() const { return pimage_; }
|
||||
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() {}
|
||||
|
||||
private:
|
||||
/// This method is connected to the PreviewLoader::imageReady signal.
|
||||
void imageReady(lyx::graphics::PreviewImage const &) const;
|
||||
/// Not implemented.
|
||||
void operator=(RenderPreview 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;
|
||||
/// This method is connected to the PreviewLoader::imageReady signal.
|
||||
void imageReady(lyx::graphics::PreviewImage const &);
|
||||
|
||||
/// The thing that we're trying to generate a preview of.
|
||||
std::string snippet_;
|
||||
|
||||
/// We don't own this. Cached for efficiency reasons.
|
||||
mutable lyx::graphics::PreviewImage const * pimage_;
|
||||
lyx::graphics::PreviewImage const * pimage_;
|
||||
|
||||
/** Store the connection to the preview loader so that we connect
|
||||
* only once.
|
||||
@ -94,4 +103,23 @@ private:
|
||||
boost::signal0<void> preview_ready_signal_;
|
||||
};
|
||||
|
||||
#endif // PREVIEWEDINSET_H
|
||||
|
||||
class RenderMonitoredPreview : public RenderPreview {
|
||||
public:
|
||||
RenderMonitoredPreview() : monitor_(std::string(), 2000) {}
|
||||
///
|
||||
bool monitoring() const { return monitor_.monitoring(); }
|
||||
///
|
||||
void startMonitoring(std::string const & file);
|
||||
///
|
||||
void stopMonitoring() { monitor_.stop(); }
|
||||
|
||||
/// Connect and you'll be informed when the file changes.
|
||||
boost::signals::connection fileChanged(slot_type const &);
|
||||
|
||||
private:
|
||||
///
|
||||
lyx::support::FileMonitor monitor_;
|
||||
};
|
||||
|
||||
#endif // RENDERPREVIEW_H
|
@ -1,128 +0,0 @@
|
||||
// -*- 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 "box.h"
|
||||
#include "dimension.h"
|
||||
|
||||
#include "graphics/GraphicsLoader.h"
|
||||
#include "graphics/GraphicsParams.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(std::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;
|
||||
|
||||
/// The "sensitive area" box, i.e., the button area
|
||||
Box box() const { return button_box_; }
|
||||
///
|
||||
void setBox(Box b) { button_box_ = b; }
|
||||
|
||||
private:
|
||||
/// The stored data.
|
||||
std::string text_;
|
||||
bool editable_;
|
||||
Box button_box_;
|
||||
};
|
||||
|
||||
|
||||
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(lyx::graphics::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.
|
||||
std::string const statusMessage() const;
|
||||
|
||||
/// Is the image ready to draw, or should we display a message instead?
|
||||
bool readyToDisplay() const;
|
||||
|
||||
/// The stored data.
|
||||
lyx::graphics::Loader loader_;
|
||||
lyx::graphics::Params params_;
|
||||
|
||||
/// Cached variable (not copied).
|
||||
mutable unsigned long checksum_;
|
||||
};
|
||||
|
||||
|
||||
#endif // NOT RENDERERS_H
|
@ -1,3 +1,10 @@
|
||||
2003-10-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* command_inset.h:trivial changes ButtonRenderer -> RenderButton.
|
||||
|
||||
* formula.[Ch]: get rid of InsetFormula::PreviewImpl entirely. Use
|
||||
RenderPreview and some free-standing functions in its place.
|
||||
|
||||
2003-10-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* formula.C (draw): don't try and generate the previews from draw.
|
||||
|
@ -14,7 +14,7 @@
|
||||
#define COMMAND_INSET_H
|
||||
|
||||
#include "math_nestinset.h"
|
||||
#include "insets/renderers.h"
|
||||
#include "insets/render_button.h"
|
||||
|
||||
|
||||
/// Inset for things like \name[options]{contents}
|
||||
@ -44,7 +44,7 @@ public:
|
||||
private:
|
||||
std::string name_;
|
||||
mutable bool set_label_;
|
||||
mutable ButtonRenderer button_;
|
||||
mutable RenderButton button_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -25,8 +25,10 @@
|
||||
|
||||
#include "frontends/Painter.h"
|
||||
|
||||
#include "graphics/PreviewedInset.h"
|
||||
#include "graphics/PreviewImage.h"
|
||||
#include "graphics/PreviewLoader.h"
|
||||
|
||||
#include "insets/render_preview.h"
|
||||
|
||||
#include "support/std_sstream.h"
|
||||
|
||||
@ -40,24 +42,9 @@ using std::auto_ptr;
|
||||
using std::endl;
|
||||
|
||||
|
||||
class InsetFormula::PreviewImpl : public PreviewedInset {
|
||||
public:
|
||||
///
|
||||
PreviewImpl(InsetFormula const & p) : parent_(p) {}
|
||||
|
||||
private:
|
||||
///
|
||||
bool previewWanted(Buffer const &) const;
|
||||
///
|
||||
string const latexString(Buffer const &) const;
|
||||
///
|
||||
InsetFormula const & parent_;
|
||||
};
|
||||
|
||||
|
||||
InsetFormula::InsetFormula(bool chemistry)
|
||||
: par_(MathAtom(new MathHullInset)),
|
||||
preview_(new PreviewImpl(*this))
|
||||
preview_(new RenderPreview)
|
||||
{
|
||||
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
|
||||
if (chemistry)
|
||||
@ -68,7 +55,7 @@ InsetFormula::InsetFormula(bool chemistry)
|
||||
InsetFormula::InsetFormula(InsetFormula const & other)
|
||||
: InsetFormulaBase(other),
|
||||
par_(other.par_),
|
||||
preview_(new PreviewImpl(*this))
|
||||
preview_(new RenderPreview)
|
||||
{
|
||||
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
|
||||
}
|
||||
@ -76,7 +63,7 @@ InsetFormula::InsetFormula(InsetFormula const & other)
|
||||
|
||||
InsetFormula::InsetFormula(BufferView *)
|
||||
: par_(MathAtom(new MathHullInset)),
|
||||
preview_(new PreviewImpl(*this))
|
||||
preview_(new RenderPreview)
|
||||
{
|
||||
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
|
||||
}
|
||||
@ -84,7 +71,7 @@ InsetFormula::InsetFormula(BufferView *)
|
||||
|
||||
InsetFormula::InsetFormula(string const & data)
|
||||
: par_(MathAtom(new MathHullInset)),
|
||||
preview_(new PreviewImpl(*this))
|
||||
preview_(new RenderPreview)
|
||||
{
|
||||
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
|
||||
if (!data.size())
|
||||
@ -193,6 +180,7 @@ void InsetFormula::read(Buffer const &, LyXLex & lex)
|
||||
|
||||
void InsetFormula::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
BOOST_ASSERT(pi.base.bv);
|
||||
BufferView * bv = pi.base.bv;
|
||||
cache(bv);
|
||||
|
||||
@ -206,8 +194,8 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const
|
||||
int const h = a + d;
|
||||
|
||||
if (use_preview) {
|
||||
pi.pain.image(x + 1, y - a, w, h, // one pixel gap in front
|
||||
*(preview_->pimage()->image()));
|
||||
// one pixel gap in front
|
||||
preview_->draw(pi, x + 1, y);
|
||||
} else {
|
||||
PainterInfo p(bv);
|
||||
p.base.style = LM_ST_TEXT;
|
||||
@ -260,16 +248,16 @@ bool InsetFormula::insetAllowed(InsetOld::Code code) const
|
||||
|
||||
void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const
|
||||
{
|
||||
BOOST_ASSERT(m.base.bv);
|
||||
view_ = m.base.bv;
|
||||
|
||||
bool const editing_inset = mathcursor && mathcursor->formula() == this;
|
||||
bool const use_preview = !editing_inset && preview_->previewReady();
|
||||
|
||||
if (use_preview) {
|
||||
dim.asc = preview_->pimage()->ascent();
|
||||
dim.des = preview_->pimage()->descent();
|
||||
preview_->metrics(m, dim);
|
||||
// insert a one pixel gap in front of the formula
|
||||
dim.wid = 1 + preview_->pimage()->width();
|
||||
dim.wid += 1;
|
||||
if (display())
|
||||
dim.des += 12;
|
||||
} else {
|
||||
@ -309,28 +297,39 @@ void InsetFormula::statusChanged() const
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
bool preview_wanted(InsetFormula const & inset, Buffer const &)
|
||||
{
|
||||
// Don't want a preview when we're editing the inset
|
||||
return !(mathcursor && mathcursor->formula() == &inset);
|
||||
}
|
||||
|
||||
|
||||
string const latex_string(InsetFormula const & inset, Buffer const &)
|
||||
{
|
||||
ostringstream ls;
|
||||
WriteStream wi(ls, false, false);
|
||||
inset.par()->write(wi);
|
||||
return ls.str();
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
void InsetFormula::addPreview(lyx::graphics::PreviewLoader & ploader) const
|
||||
{
|
||||
preview_->addPreview(ploader);
|
||||
if (preview_wanted(*this, ploader.buffer())) {
|
||||
string const snippet = latex_string(*this, ploader.buffer());
|
||||
preview_->addPreview(snippet, ploader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InsetFormula::generatePreview(Buffer const & buffer) const
|
||||
{
|
||||
preview_->generatePreview(buffer);
|
||||
}
|
||||
|
||||
|
||||
bool InsetFormula::PreviewImpl::previewWanted(Buffer const &) const
|
||||
{
|
||||
return !parent_.par_->asNestInset()->editing();
|
||||
}
|
||||
|
||||
|
||||
string const InsetFormula::PreviewImpl::latexString(Buffer const &) const
|
||||
{
|
||||
ostringstream ls;
|
||||
WriteStream wi(ls, false, false);
|
||||
parent_.par_->write(wi);
|
||||
return ls.str();
|
||||
if (preview_wanted(*this, buffer)) {
|
||||
string const snippet = latex_string(*this, buffer);
|
||||
preview_->generatePreview(snippet, buffer);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
class RenderPreview;
|
||||
|
||||
|
||||
/// The main LyX math inset
|
||||
class InsetFormula : public InsetFormulaBase {
|
||||
@ -84,10 +86,7 @@ private:
|
||||
/// x offset for drawing displayed formula
|
||||
mutable int offset_;
|
||||
|
||||
/// Use the Pimpl idiom to hide the internals of the previewer.
|
||||
class PreviewImpl;
|
||||
friend class PreviewImpl;
|
||||
/// The pointer never changes although *preview_'s contents may.
|
||||
boost::scoped_ptr<PreviewImpl> const preview_;
|
||||
boost::scoped_ptr<RenderPreview> const preview_;
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user