math internal re-organization to prepare de-centralized dispatch

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4542 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-07-08 06:39:40 +00:00
parent 156cb8ffdd
commit f3059f5772
11 changed files with 150 additions and 76 deletions

View File

@ -139,8 +139,8 @@ Inset * InsetFormula::clone(Buffer const &, bool) const
void InsetFormula::write(Buffer const *, ostream & os) const
{
os << "Formula ";
WriteStream wi(os, false, false);
os << par_->fileInsetLabel() << " ";
par_->write(wi);
}
@ -238,10 +238,10 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
{
mathcursor->drawSelection(pi);
pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
//pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
}
par_->draw(pi, x, y);
par_->draw(pi, x + 1, y);
}
xx += w;
@ -254,7 +254,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
vector<string> const InsetFormula::getLabelList() const
{
return hull()->getLabelList();
return par()->getLabelList();
}
@ -278,7 +278,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
//lyxerr << "toggling all numbers\n";
if (display()) {
bv->lockedInsetStoreUndo(Undo::INSERT);
bool old = hull()->numberedType();
bool old = par()->numberedType();
for (MathInset::row_type row = 0; row < par_->nrows(); ++row)
hull()->numbered(row, !old);
bv->owner()->message(old ? _("No number") : _("Number"));
@ -461,14 +461,13 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
string InsetFormula::hullType() const
{
return hull() ? hull()->getType() : "none";
return par()->getType();
}
void InsetFormula::mutate(string const & type )
void InsetFormula::mutate(string const & type)
{
if (hull())
hull()->mutate(type);
par()->mutate(type);
}

View File

@ -54,7 +54,6 @@
#include "frontends/Dialogs.h"
#include "intl.h"
#include "insets/insetcommandparams.h"
#include "ref_inset.h"
using std::endl;
@ -309,23 +308,36 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
int /*x*/, int /*y*/, mouse_button::state button)
{
//lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
if (!mathcursor)
return false;
//lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
hideInsetCursor(bv);
showInsetCursor(bv);
bv->updateInset(this, false);
if (button == mouse_button::button3) {
// try to dispatch to enclosed insets first
if (mathcursor->dispatch("mouse 3"))
if (mathcursor->dispatch("mouse-3-release"))
return true;
// launch math panel for right mouse button
bv->owner()->getDialogs()->showMathPanel();
return true;
}
if (button == mouse_button::button1) {
// try to dispatch to enclosed insets first
if (mathcursor->dispatch("mouse-1-release"))
return true;
// try to set the cursor
//delete mathcursor;
//mathcursor = new MathCursor(this, x == 0);
//metrics(bv);
//mathcursor->setPos(x + xo_, y + yo_);
return true;
}
return false;
}
@ -333,70 +345,53 @@ bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
void InsetFormulaBase::insetButtonPress(BufferView * bv,
int x, int y, mouse_button::state button)
{
//lyxerr << "insetButtonPress: "
// << x << " " << y << " but: " << button << "\n";
#if 0
switch (button) {
default:
case 1:
// left click
delete mathcursor;
mathcursor = new MathCursor(this, x == 0);
metrics(bv);
first_x = x;
first_y = y;
mathcursor->selClear();
mathcursor->setPos(x + xo_, y + yo_);
break;
/*
case 2:
lyxerr << "insetButtonPress: 2\n";
// insert stuff
if (mathcursor) {
bv->lockedInsetStoreUndo(Undo::EDIT);
MathArray ar;
mathcursor->selGet(ar);
mathcursor->setPos(x + xo_, y + yo_);
string sel =
bv->getLyXText()->selectionAsString(bv->buffer(), false);
mathed_parse_cell(ar, sel);
mathcursor->insert(ar);
}
break;
*/
case 3:
// launch math panel for right mouse button
bv->owner()->getDialogs()->showMathPanel();
break;
}
#else
if (button == mouse_button::button1 || !mathcursor) {
delete mathcursor;
mathcursor = new MathCursor(this, x == 0);
lyxerr << "insetButtonPress: "
<< x << " " << y << " but: " << button << "\n";
lyxerr << "formula: ";
par()->dump();
delete mathcursor;
mathcursor = new MathCursor(this, x == 0);
if (button == mouse_button::button1) {
// just set the cursor here
lyxerr << "setting cursor\n";
metrics(bv);
first_x = x;
first_y = y;
mathcursor->selClear();
mathcursor->setPos(x + xo_, y + yo_);
if (mathcursor->dispatch("mouse-1-press")) {
//delete mathcursor;
return;
}
}
#if 0
#warning Never launch a Dialog on "Press" event ONLY on "Release" event!
if (button == 3) {
// launch math panel for right mouse button
bv->owner()->getDialogs()->showMathPanel();
if (button == mouse_button::button3) {
if (mathcursor->dispatch("mouse-3-press")) {
//delete mathcursor;
return;
}
}
#endif
#endif
bv->updateInset(this, false);
}
void InsetFormulaBase::insetMotionNotify(BufferView * bv,
int x, int y, mouse_button::state)
int x, int y, mouse_button::state button)
{
if (!mathcursor)
return;
if (button == mouse_button::button1)
if (mathcursor->dispatch("mouse-1-motion"))
return;
if (button == mouse_button::button3)
if (mathcursor->dispatch("mouse-3-motion"))
return;
if (abs(x - first_x) < 2 && abs(y - first_y) < 2) {
//lyxerr << "insetMotionNotify: ignored\n";
return;
@ -421,7 +416,9 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
string const & arg)
{
//lyxerr << "InsetFormulaBase::localDispatch: act: " << action
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
// << " arg: '" << arg
// << "' cursor: " << mathcursor
// << "\n";
if (!mathcursor)
return UNDISPATCHED;

View File

@ -736,7 +736,7 @@ MathInset * MathCursor::par() const
}
InsetFormulaBase * MathCursor::formula()
InsetFormulaBase * MathCursor::formula() const
{
return formula_;
}
@ -1759,9 +1759,18 @@ void MathCursor::handleExtern(const string & arg)
int MathCursor::dispatch(string const & cmd)
{
// try to dispatch to adajcent items if they are not editable
// actually, this should only happen for mouse clicks...
if (hasNextAtom() && !openable(nextAtom(), false))
if (int res = nextAtom()->dispatch(cmd, 0, 0))
return res;
if (hasPrevAtom() && !openable(prevAtom(), false))
if (int res = prevAtom()->dispatch(cmd, 0, 0))
return res;
for (int i = Cursor_.size() - 1; i >= 0; --i) {
MathCursorPos & pos = Cursor_[i];
if (int res = pos.par_-> dispatch(cmd, pos.idx_, pos.pos_))
if (int res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_))
return res;
}
return 0;

View File

@ -117,7 +117,7 @@ public:
/// go up to the hull inset
void popToEnclosingHull();
///
InsetFormulaBase * formula();
InsetFormulaBase * formula() const;
/// current offset in the current cell
pos_type pos() const;
/// current cell

View File

@ -31,6 +31,7 @@
#include "math_xymatrixinset.h"
#include "math_xyarrowinset.h"
//#include "insets/insetref.h"
#include "ref_inset.h"
#include "math_metricsinfo.h"
@ -121,10 +122,13 @@ key_type wordlist_array[] =
{"overline", "decoration", ""},
{"overrightarrow", "decoration", ""},
{"overleftrightarrow", "decoration", ""},
{"pageref", "ref", ""},
{"pmatrix", "matrix", ""},
{"prettyref", "ref", ""},
{"protect", "protect", ""},
{"qquad", "space", ""},
{"quad", "space", ""},
{"ref", "ref", ""},
{"right", "right", ""},
{"rm", "oldfont", ""},
{"scriptscriptstyle", "style", ""},
@ -149,6 +153,8 @@ key_type wordlist_array[] =
{"vdots", "dots", ""},
{"vec", "decoration", ""},
{"vmatrix", "matrix", ""},
{"vpageref", "ref", ""},
{"vref", "ref", ""},
{"widehat", "decoration", ""},
{"widetilde", "decoration", ""}
};
@ -307,14 +313,13 @@ MathAtom createMathInset(string const & s)
return MathAtom(new MathNotInset);
if (s == "lefteqn")
return MathAtom(new MathLefteqnInset);
if (s == "ref")
return MathAtom(new RefInset);
latexkeys const * l = in_word_set(s);
if (l) {
string const & inset = l->inset;
lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
if (inset == "ref")
return MathAtom(new RefInset(l->name));
if (inset == "underset")
return MathAtom(new MathUndersetInset);
if (inset == "decoration")

View File

@ -189,13 +189,17 @@ void MathHullInset::metrics(MathMetricsInfo & mi) const
math_font_max_dim(mi.base.font, asc, des);
ascent_ = max(ascent_, asc);
descent_ = max(descent_, des);
// for markers
width_ += 2;
descent_ += 1;
}
void MathHullInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy(pi.base, standardFont());
MathGridInset::draw(pi, x, y);
MathGridInset::draw(pi, x + 1, y);
if (numberedType()) {
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
@ -205,6 +209,8 @@ void MathHullInset::draw(MathPainterInfo & pi, int x, int y) const
drawStr(pi, pi.base.font, xx, yy, nicelabel(row));
}
}
drawMarkers(pi, x, y);
}
@ -286,7 +292,7 @@ bool MathHullInset::display() const
}
vector<string> const MathHullInset::getLabelList() const
vector<string> MathHullInset::getLabelList() const
{
vector<string> res;
for (row_type row = 0; row < nrows(); ++row)

View File

@ -49,7 +49,7 @@ public:
///
bool ams() const;
///
std::vector<string> const getLabelList() const;
std::vector<string> getLabelList() const;
///
void validate(LaTeXFeatures & features) const;
/// identifies MatrixInsets

View File

@ -26,8 +26,14 @@
#include "math_scriptinset.h"
#include "math_charinset.h"
#include "math_mathmlstream.h"
#include "math_cursor.h"
#include "debug.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
#include "BufferView.h"
#include "formulabase.h"
using std::ostream;
using std::vector;
@ -278,6 +284,19 @@ int MathInset::dispatch(string const &, idx_type, pos_type)
}
std::vector<string> MathInset::getLabelList() const
{
return std::vector<string>();
}
string const & MathInset::getType() const
{
static string t("none");
return t;
}
string asString(MathArray const & ar)
{
string res;
@ -295,3 +314,15 @@ MathArray asArray(string const & str)
ar.push_back(MathAtom(new MathCharInset(*it)));
return ar;
}
Dialogs * getDialogs()
{
return mathcursor->formula()->view()->owner()->getDialogs();
}
LyXFunc * getLyXFunc()
{
return mathcursor->formula()->view()->owner()->getLyXFunc();
}

View File

@ -67,6 +67,9 @@ class MathSpaceInset;
class MathSymbolInset;
class MathUnknownInset;
class MathXYMatrixInset;
class MathXYMatrixInset;
class InsetRef;
class NormalStream;
class OctaveStream;
@ -213,6 +216,7 @@ public:
virtual MathUnknownInset * asUnknownInset() { return 0; }
virtual MathUnknownInset const * asUnknownInset() const { return 0; }
virtual MathXYMatrixInset const* asXYMatrixInset() const{ return 0; }
virtual InsetRef * asInsetRef() { return 0; }
/// identifies things that can get scripts
virtual bool isScriptable() const { return false; }
@ -271,6 +275,17 @@ public:
virtual void dump() const;
/// local dispatcher
virtual int dispatch(string const & cmd, idx_type idx, pos_type pos);
/// LyXInset stuff
virtual std::vector<string> getLabelList() const;
/// LyXInset stuff
virtual bool numberedType() const { return false; }
/// hull type
virtual string const & getType() const;
/// change type
virtual void mutate(string const &) {}
/// how is the inset called in the .lyx file?
virtual string fileInsetLabel() const { return "Formula"; }
};
std::ostream & operator<<(std::ostream &, MathInset const &);
@ -279,4 +294,11 @@ std::ostream & operator<<(std::ostream &, MathAtom const &);
string asString(MathArray const & ar);
MathArray asArray(string const & str);
/// here to ssave a few includes in the insets
class Dialogs;
class LyXFunc;
Dialogs * getDialogs();
LyXFunc * getLyXFunc();
#endif

View File

@ -58,6 +58,7 @@ following hack as starting point to write some macros:
#include "math_support.h"
#include "math_xyarrowinset.h"
//#include "insets/insetref.h"
#include "ref_inset.h"
#include "lyxlex.h"
@ -579,13 +580,13 @@ bool Parser::parse_normal(MathAtom & at)
skipSpaces();
MathArray ar;
parse_into(ar, false, false);
if (ar.size() != 1) {
lyxerr << "Unusual contents found: " << ar << endl;
if (ar.size() != 1 || ar.front()->getType() == "none") {
lyxerr << "unusual contents found: " << ar << endl;
at.reset(new MathParInset);
if (at->nargs() > 0)
at->cell(0) = ar;
else
lyxerr << "Unusual contents found: " << ar << endl;
lyxerr << "unusual contents found: " << ar << endl;
return true;
}
at = ar[0];

View File

@ -38,14 +38,14 @@ void RefInset::infoize(std::ostream & os) const
int RefInset::dispatch(string const & cmd, idx_type, pos_type)
{
if (cmd == "mouse 3") {
if (cmd == "mouse-3-release") {
lyxerr << "trying to goto ref" << cell(0) << "\n";
mathcursor->formula()->view()->owner()->getLyXFunc()->
dispatch(LFUN_REF_GOTO, asString(cell(0)));
return 1; // dispatched
}
if (cmd == "mouse 1") {
if (cmd == "mouse-1-release") {
lyxerr << "trying to open ref" << cell(0) << "\n";
// Eventually trigger dialog with button 3 not 1
// mathcursor->formula()->view()->owner()->getDialogs()
@ -53,6 +53,10 @@ int RefInset::dispatch(string const & cmd, idx_type, pos_type)
return 1; // dispatched
}
// eat other mouse commands
if (cmd.substr(0, 6) == "mouse-")
return 1;
return 0; // undispatched
}