Replace InsetButton and ButtonInset with a ButtonRenderer that can be

included as a member variable.
Enable InsetExternal to choose its renderer dynamically.
diffstat tells me
25 files changed, 627 insertions(+), 646 deletions(-)


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7160 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-06-12 08:52:36 +00:00
parent 79ca0d3b49
commit ba01e80b7c
24 changed files with 435 additions and 454 deletions

View File

@ -132,7 +132,6 @@ src/frontends/xforms/xformsBC.h
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
@ -158,6 +157,7 @@ src/insets/insettheorem.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

View File

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

View File

@ -17,8 +17,8 @@ libinsets_la_SOURCES = \
mailinset.h \
ExternalTemplate.C \
ExternalTemplate.h \
graphicinset.C \
graphicinset.h \
renderers.C \
renderers.h \
inset.C \
inset.h \
insetbase.h \
@ -27,8 +27,6 @@ libinsets_la_SOURCES = \
insetbibitem.h \
insetbibtex.C \
insetbibtex.h \
insetbutton.C \
insetbutton.h \
insetcaption.C \
insetcaption.h \
insetcite.C \

View File

@ -1,91 +0,0 @@
// -*- 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

View File

@ -1,85 +0,0 @@
/**
* \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);
}

View File

@ -1,43 +0,0 @@
// -*- 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

View File

@ -16,6 +16,7 @@
#include "debug.h"
#include "funcrequest.h"
#include "lyxlex.h"
#include "metricsinfo.h"
#include "frontends/Painter.h"
@ -27,13 +28,31 @@ using std::ostream;
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);
}
@ -42,6 +61,7 @@ void InsetCommand::setParams(InsetCommandParams const & p)
p_.setCmdName(p.getCmdName());
p_.setContents(p.getContents());
p_.setOptions(p.getOptions());
set_label_ = false;
}

View File

@ -14,10 +14,10 @@
#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
@ -27,13 +27,15 @@
*/
///
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); }
@ -54,30 +56,38 @@ public:
///
Inset::Code lyxCode() const { return Inset::NO_CODE; }
///
InsetCommandParams const & params() const { return p_; }
///
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 getCommand() const { return p_.getCommand(); }
///
string const & getCmdName() const { return p_.getCmdName(); }
///
string const & getOptions() const { return p_.getOptions(); }
///
string const & getContents() const { return p_.getContents(); }
///
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_;
};

View File

@ -11,7 +11,7 @@
#include <config.h>
#include "insetexternal.h"
#include "insets/graphicinset.h"
#include "insets/renderers.h"
#include "buffer.h"
#include "BufferView.h"
@ -82,19 +82,20 @@ InsetExternal::Params::~Params()
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));
}
}
@ -231,16 +232,34 @@ void InsetExternal::setParams(Params const & p, string const & filepath)
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));
}
}

View File

@ -20,7 +20,7 @@
#include <boost/signals/trackable.hpp>
class GraphicInset;
class RenderInset;
///
class InsetExternal : public Inset, public boost::signals::trackable {
@ -116,7 +116,7 @@ private:
Params params_;
/// The thing that actually draws the image on LyX's screen.
boost::scoped_ptr<GraphicInset> const renderer_;
boost::scoped_ptr<RenderInset> renderer_;
};

View File

@ -54,7 +54,7 @@ TODO
#include "insets/insetgraphics.h"
#include "insets/insetgraphicsParams.h"
#include "insets/graphicinset.h"
#include "insets/renderers.h"
#include "buffer.h"
#include "BufferView.h"
@ -134,7 +134,7 @@ string findTargetFormat(string const & suffix, LatexRunParams const & runparams)
InsetGraphics::InsetGraphics()
: graphic_label(uniqueID()),
graphic_(new GraphicInset)
graphic_(new GraphicRenderer)
{
graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
}
@ -144,7 +144,7 @@ InsetGraphics::InsetGraphics(InsetGraphics const & ig)
: 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());
@ -552,7 +552,7 @@ int InsetGraphics::linuxdoc(Buffer const *, ostream &) const
// 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

View File

@ -21,7 +21,7 @@
class Dialogs;
class GraphicInset;
class GraphicRenderer;
class LaTeXFeatures;
///
@ -104,7 +104,7 @@ private:
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_;
};

View File

@ -92,19 +92,30 @@ string const uniqueID()
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);
@ -137,7 +148,7 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
return DISPATCHED;
default:
return InsetButton::localDispatch(cmd);
return Inset::localDispatch(cmd);
}
}
@ -511,7 +522,12 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
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;
}
@ -521,7 +537,7 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
{
cache(pi.base.bv);
if (!preview_->previewReady()) {
InsetButton::draw(pi, x, y);
button_.draw(pi, x, y);
return;
}
@ -533,6 +549,12 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
}
BufferView * InsetInclude::view() const
{
return button_.view();
}
//
// preview stuff
//

View File

@ -14,16 +14,17 @@
#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 {
@ -52,8 +53,8 @@ public:
///
InsetInclude(Params const &);
///
InsetInclude(InsetCommandParams const &, Buffer const &);
InsetInclude(InsetInclude const &);
~InsetInclude();
@ -64,6 +65,8 @@ public:
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;
@ -131,6 +134,8 @@ private:
/// cache
mutable Dimension dim_;
mutable bool set_label_;
mutable ButtonRenderer button_;
};

View File

@ -1,5 +1,5 @@
/**
* \file graphicinset.C
* \file renderers.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/graphicinset.h"
#include "insets/renderers.h"
#include "buffer.h"
#include "BufferView.h"
@ -26,20 +26,105 @@
#include "support/filetools.h"
GraphicInset::GraphicInset()
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)
{}
GraphicInset::GraphicInset(GraphicInset const & other)
: loader_(other.loader_),
GraphicRenderer::GraphicRenderer(GraphicRenderer const & other)
: RenderInset(other),
loader_(other.loader_),
params_(other.params_),
nodisplay_message_(other.nodisplay_message_),
checksum_(0)
{}
void GraphicInset::update(grfx::Params const & params)
RenderInset * GraphicRenderer::clone() const
{
return new GraphicRenderer(*this);
}
void GraphicRenderer::update(grfx::Params const & params)
{
params_ = params;
@ -50,7 +135,7 @@ void GraphicInset::update(grfx::Params const & params)
}
bool GraphicInset::hasFileChanged() const
bool GraphicRenderer::hasFileChanged() const
{
unsigned long const new_checksum = loader_.checksum();
bool const file_has_changed = checksum_ != new_checksum;
@ -60,25 +145,13 @@ bool GraphicInset::hasFileChanged() const
}
BufferView * GraphicInset::view() const
{
return view_.lock().get();
}
boost::signals::connection GraphicInset::connect(slot_type const & slot) const
boost::signals::connection GraphicRenderer::connect(slot_type const & slot) const
{
return loader_.connect(slot);
}
void GraphicInset::setNoDisplayMessage(string const & str)
{
nodisplay_message_ = str;
}
string const GraphicInset::statusMessage() const
string const GraphicRenderer::statusMessage() const
{
switch (loader_.status()) {
case grfx::WaitingToLoad:
@ -108,33 +181,25 @@ string const GraphicInset::statusMessage() const
}
GraphicInset::DisplayType GraphicInset::displayType() const
bool GraphicRenderer::readyToDisplay() 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;
return false;
return loader_.image()->isDrawable();
}
void GraphicInset::metrics(MetricsInfo & mi, Dimension & dim) const
void GraphicRenderer::metrics(MetricsInfo & mi, Dimension & dim) const
{
DisplayType type = displayType();
bool image_ready = readyToDisplay();
dim.asc = (type == IMAGE) ? loader_.image()->getHeight() : 50;
dim.asc = image_ready ? loader_.image()->getHeight() : 50;
dim.des = 0;
switch (type) {
case IMAGE:
if (image_ready) {
dim.wid = loader_.image()->getWidth() +
2 * Inset::TEXT_TO_INSET_OFFSET;
break;
case STATUS_MESSAGE:
{
} else {
int font_width = 0;
LyXFont msgFont(mi.base.font);
@ -154,31 +219,16 @@ void GraphicInset::metrics(MetricsInfo & mi, Dimension & dim) const
}
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
void GraphicRenderer::draw(PainterInfo & pi, int x, int y) const
{
if (pi.base.bv)
view_ = pi.base.bv->owner()->view();
lyx::Assert(pi.base.bv);
view_ = pi.base.bv->owner()->view();
#if 0
// Comment this out and see if anything goes wrong.
@ -215,19 +265,14 @@ void GraphicInset::draw(PainterInfo & pi, int x, int y) const
// This will draw the graphics. If the graphics has not been loaded yet,
// we draw just a rectangle.
switch (displayType()) {
case IMAGE:
{
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());
break;
}
case STATUS_MESSAGE:
{
} else {
pi.pain.rectangle(x + Inset::TEXT_TO_INSET_OFFSET,
y - dim_.asc,
dim_.wid - 2 * Inset::TEXT_TO_INSET_OFFSET,
@ -252,23 +297,5 @@ void GraphicInset::draw(PainterInfo & pi, int x, int y) const
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;
}
}
}

122
src/insets/renderers.h Normal file
View File

@ -0,0 +1,122 @@
// -*- 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

View File

@ -1,3 +1,13 @@
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]:

View File

@ -151,8 +151,6 @@ libmathed_la_SOURCES = \
math_undersetinset.h \
math_xarrowinset.C \
math_xarrowinset.h \
button_inset.C \
button_inset.h \
command_inset.h \
command_inset.C \
ref_inset.h \

View File

@ -1,47 +0,0 @@
#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);
}
}

View File

@ -1,35 +0,0 @@
// -*- 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

View File

@ -6,7 +6,9 @@
CommandInset::CommandInset(string const & name)
: name_(name)
: MathNestInset(2),
name_(name),
set_label_(false)
{
lock_ = true;
}
@ -18,12 +20,27 @@ MathInset * CommandInset::clone() const
}
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;
}
@ -38,9 +55,9 @@ void CommandInset::write(WriteStream & os) const
}
string CommandInset::screenLabel() const
string const CommandInset::screenLabel() const
{
return name_;
return name_;
}
@ -53,5 +70,3 @@ string const CommandInset::createDialogStr(string const & name) const
wsdata << "\n\\end_inset\n\n";
return STRCONV(data.str());
}

View File

@ -15,27 +15,38 @@
#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

View File

@ -70,11 +70,11 @@ RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
}
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;
}
@ -90,9 +90,9 @@ string RefInset::screenLabel() const
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");
}

View File

@ -20,7 +20,7 @@ public:
///
dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
///
string screenLabel() const;
string const screenLabel() const;
///
void validate(LaTeXFeatures & features) const;
///