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
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
+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.
mailinset.h \
ExternalTemplate.C \
ExternalTemplate.h \
- graphicinset.C \
- graphicinset.h \
+ renderers.C \
+ renderers.h \
inset.C \
inset.h \
insetbase.h \
insetbibitem.h \
insetbibtex.C \
insetbibtex.h \
- insetbutton.C \
- insetbutton.h \
insetcaption.C \
insetcaption.h \
insetcite.C \
+++ /dev/null
-/**
- * \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;
- }
- }
-}
+++ /dev/null
-// -*- 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
+++ /dev/null
-/**
- * \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);
-}
+++ /dev/null
-// -*- 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
#include "debug.h"
#include "funcrequest.h"
#include "lyxlex.h"
+#include "metricsinfo.h"
#include "frontends/Painter.h"
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);
}
p_.setCmdName(p.getCmdName());
p_.setContents(p.getContents());
p_.setOptions(p.getOptions());
+ set_label_ = false;
}
#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); }
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_;
};
#include <config.h>
#include "insetexternal.h"
-#include "insets/graphicinset.h"
+#include "insets/renderers.h"
#include "buffer.h"
#include "BufferView.h"
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));
+ }
}
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));
+ }
}
#include <boost/signals/trackable.hpp>
-class GraphicInset;
+class RenderInset;
///
class InsetExternal : public Inset, public boost::signals::trackable {
Params params_;
/// The thing that actually draws the image on LyX's screen.
- boost::scoped_ptr<GraphicInset> const renderer_;
+ boost::scoped_ptr<RenderInset> renderer_;
};
#include "insets/insetgraphics.h"
#include "insets/insetgraphicsParams.h"
-#include "insets/graphicinset.h"
+#include "insets/renderers.h"
#include "buffer.h"
#include "BufferView.h"
InsetGraphics::InsetGraphics()
: graphic_label(uniqueID()),
- graphic_(new GraphicInset)
+ graphic_(new GraphicRenderer)
{
graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
}
: 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());
// 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
class Dialogs;
-class GraphicInset;
+class GraphicRenderer;
class LaTeXFeatures;
///
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_;
};
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);
return DISPATCHED;
default:
- return InsetButton::localDispatch(cmd);
+ return Inset::localDispatch(cmd);
}
}
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;
}
{
cache(pi.base.bv);
if (!preview_->previewReady()) {
- InsetButton::draw(pi, x, y);
+ button_.draw(pi, x, y);
return;
}
}
+BufferView * InsetInclude::view() const
+{
+ return button_.view();
+}
+
+
//
// preview stuff
//
#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 {
///
InsetInclude(Params const &);
- ///
InsetInclude(InsetCommandParams const &, Buffer const &);
+ InsetInclude(InsetInclude const &);
~InsetInclude();
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;
/// cache
mutable Dimension dim_;
+ mutable bool set_label_;
+ mutable ButtonRenderer button_;
};
--- /dev/null
+/**
+ * \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);
+ }
+ }
+}
--- /dev/null
+// -*- 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
+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]:
math_undersetinset.h \
math_xarrowinset.C \
math_xarrowinset.h \
- button_inset.C \
- button_inset.h \
command_inset.h \
command_inset.C \
ref_inset.h \
+++ /dev/null
-
-#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);
- }
-}
+++ /dev/null
-// -*- 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
CommandInset::CommandInset(string const & name)
- : name_(name)
+ : MathNestInset(2),
+ name_(name),
+ set_label_(false)
{
lock_ = true;
}
}
+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;
}
}
-string CommandInset::screenLabel() const
+string const CommandInset::screenLabel() const
{
- return name_;
+ return name_;
}
wsdata << "\n\\end_inset\n\n";
return STRCONV(data.str());
}
-
-
#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
}
-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;
}
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");
}
///
dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
///
- string screenLabel() const;
+ string const screenLabel() const;
///
void validate(LaTeXFeatures & features) const;
///