mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
Re-enable previews for mathed.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8651 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
fff7d8407c
commit
571594d508
@ -1,3 +1,8 @@
|
||||
2004-04-13 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* text3.C (dispatch): call Inset::.notifyCursorLeaves when the
|
||||
cursor is clicked out of an inset.
|
||||
|
||||
2004-04-13 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* lyx_main.[Ch] (updateInset): pass it an InsetBase pointer rather
|
||||
|
@ -1,3 +1,12 @@
|
||||
2004-04-13 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* math_hullinset.[Ch]: add a RenderPreview variable.
|
||||
(copy c-tor, copy assignment operator, d-tor, notifyCursorLeaves,
|
||||
addPreview): new member functions. The copy c-tor and assignment op
|
||||
could be replaced by the compiler-generated defaults if preview_
|
||||
was stored as a RenderPreview var rather than a scoped pointer.
|
||||
(metrics, draw): use the preview renderer if previewing is turned on.
|
||||
|
||||
2004-04-05 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* math_scriptinset.C (up, down, notifyCursorLeaves): ensure that
|
||||
|
@ -26,15 +26,22 @@
|
||||
#include "gettext.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "LColor.h"
|
||||
#include "lyx_main.h"
|
||||
#include "lyxrc.h"
|
||||
#include "outputparams.h"
|
||||
#include "textpainter.h"
|
||||
#include "undo.h"
|
||||
|
||||
#include "insets/render_preview.h"
|
||||
|
||||
#include "frontends/Alert.h"
|
||||
|
||||
#include "graphics/PreviewLoader.h"
|
||||
|
||||
#include "support/std_sstream.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
||||
using std::endl;
|
||||
using std::max;
|
||||
@ -114,7 +121,8 @@ namespace {
|
||||
|
||||
|
||||
MathHullInset::MathHullInset()
|
||||
: MathGridInset(1, 1), type_("none"), nonum_(1), label_(1)
|
||||
: MathGridInset(1, 1), type_("none"), nonum_(1), label_(1),
|
||||
preview_(new RenderPreview(this))
|
||||
{
|
||||
//lyxerr << "sizeof MathInset: " << sizeof(MathInset) << endl;
|
||||
//lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
|
||||
@ -125,18 +133,42 @@ MathHullInset::MathHullInset()
|
||||
|
||||
|
||||
MathHullInset::MathHullInset(string const & type)
|
||||
: MathGridInset(getCols(type), 1), type_(type), nonum_(1), label_(1)
|
||||
: MathGridInset(getCols(type), 1), type_(type), nonum_(1), label_(1),
|
||||
preview_(new RenderPreview(this))
|
||||
{
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
|
||||
MathHullInset::MathHullInset(MathHullInset const & other)
|
||||
: MathGridInset(other),
|
||||
type_(other.type_), nonum_(other.nonum_), label_(other.label_),
|
||||
preview_(new RenderPreview(this))
|
||||
{}
|
||||
|
||||
|
||||
MathHullInset::~MathHullInset()
|
||||
{}
|
||||
|
||||
|
||||
auto_ptr<InsetBase> MathHullInset::clone() const
|
||||
{
|
||||
return auto_ptr<InsetBase>(new MathHullInset(*this));
|
||||
}
|
||||
|
||||
|
||||
void MathHullInset::operator=(MathHullInset const & other)
|
||||
{
|
||||
if (this == &other)
|
||||
return;
|
||||
*static_cast<MathGridInset*>(this) = MathGridInset(other);
|
||||
type_ = other.type_;
|
||||
nonum_ = other.nonum_;
|
||||
label_ = other.label_;
|
||||
preview_.reset(new RenderPreview(*other.preview_, this));
|
||||
}
|
||||
|
||||
|
||||
MathInset::mode_type MathHullInset::currentMode() const
|
||||
{
|
||||
if (type_ == "none")
|
||||
@ -194,6 +226,20 @@ char const * MathHullInset::standardFont() const
|
||||
|
||||
void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
bool const use_preview = (!editing(mi.base.bv) &&
|
||||
RenderPreview::activated() &&
|
||||
preview_->previewReady());
|
||||
|
||||
if (use_preview) {
|
||||
preview_->metrics(mi, dim);
|
||||
// insert a one pixel gap in front of the formula
|
||||
dim.wid += 1;
|
||||
if (display())
|
||||
dim.des += 12;
|
||||
dim_ = dim;
|
||||
return;
|
||||
}
|
||||
|
||||
FontSetChanger dummy1(mi.base, standardFont());
|
||||
StyleChanger dummy2(mi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
||||
|
||||
@ -228,6 +274,18 @@ void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
|
||||
void MathHullInset::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
// The previews are drawn only when we're not editing the inset.
|
||||
bool const use_preview = (!editing(pi.base.bv) &&
|
||||
RenderPreview::activated() &&
|
||||
preview_->previewReady());
|
||||
|
||||
if (use_preview) {
|
||||
// one pixel gap in front
|
||||
preview_->draw(pi, x + 1, y);
|
||||
setPosCache(pi, x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
FontSetChanger dummy1(pi.base, standardFont());
|
||||
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
||||
MathGridInset::draw(pi, x + 1, y);
|
||||
@ -272,6 +330,38 @@ void MathHullInset::drawT(TextPainter & pain, int x, int y) const
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
string const latex_string(MathHullInset const & inset)
|
||||
{
|
||||
ostringstream ls;
|
||||
WriteStream wi(ls, false, false);
|
||||
inset.write(wi);
|
||||
return ls.str();
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
void MathHullInset::addPreview(lyx::graphics::PreviewLoader & ploader) const
|
||||
{
|
||||
string const snippet = latex_string(*this);
|
||||
preview_->addPreview(snippet, ploader);
|
||||
}
|
||||
|
||||
|
||||
void MathHullInset::notifyCursorLeaves(LCursor & cur)
|
||||
{
|
||||
if (!RenderPreview::activated())
|
||||
return;
|
||||
|
||||
Buffer const & buffer = cur.buffer();
|
||||
string const snippet = latex_string(*this);
|
||||
preview_->addPreview(snippet, buffer);
|
||||
preview_->startLoading(buffer);
|
||||
}
|
||||
|
||||
|
||||
string MathHullInset::label(row_type row) const
|
||||
{
|
||||
row_type n = nrows();
|
||||
@ -784,6 +874,14 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_FINISHED_LEFT:
|
||||
case LFUN_FINISHED_RIGHT:
|
||||
case LFUN_FINISHED_UP:
|
||||
case LFUN_FINISHED_DOWN:
|
||||
MathGridInset::priv_dispatch(cur, cmd);
|
||||
notifyCursorLeaves(cur);
|
||||
break;
|
||||
|
||||
case LFUN_BREAKPARAGRAPH:
|
||||
// just swallow this
|
||||
break;
|
||||
|
@ -13,6 +13,9 @@
|
||||
#define MATH_HULLINSET_H
|
||||
|
||||
#include "math_gridinset.h"
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
class RenderPreview;
|
||||
|
||||
|
||||
/// This provides an interface between "LyX insets" and "LyX math insets"
|
||||
@ -23,8 +26,14 @@ public:
|
||||
///
|
||||
explicit MathHullInset(std::string const & type);
|
||||
///
|
||||
MathHullInset(MathHullInset const &);
|
||||
///
|
||||
~MathHullInset();
|
||||
///
|
||||
std::auto_ptr<InsetBase> clone() const;
|
||||
///
|
||||
void operator=(MathHullInset const &);
|
||||
///
|
||||
mode_type currentMode() const;
|
||||
///
|
||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
@ -104,10 +113,12 @@ public:
|
||||
int docbook(Buffer const &, std::ostream &,
|
||||
OutputParams const &) const;
|
||||
|
||||
/// get notification when the cursor leaves this inset
|
||||
void notifyCursorLeaves(LCursor & cur);
|
||||
///
|
||||
//bool insetAllowed(Code code) const;
|
||||
///
|
||||
//void addPreview(lyx::graphics::PreviewLoader &) const;
|
||||
void addPreview(lyx::graphics::PreviewLoader &) const;
|
||||
|
||||
|
||||
protected:
|
||||
@ -147,7 +158,8 @@ private:
|
||||
std::vector<int> nonum_;
|
||||
///
|
||||
std::vector<std::string> label_;
|
||||
|
||||
///
|
||||
boost::scoped_ptr<RenderPreview> preview_;
|
||||
//
|
||||
// Incorporate me
|
||||
//
|
||||
|
@ -1148,6 +1148,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
finishUndo();
|
||||
cur.x_target() = cursorX(cur.top());
|
||||
|
||||
// Has the cursor just left the inset?
|
||||
if (bv->cursor().inMathed() && !cur.inMathed())
|
||||
bv->cursor().inset().notifyCursorLeaves(bv->cursor());
|
||||
|
||||
// Set cursor here.
|
||||
bv->cursor() = cur;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user