binom is binom is binom and choose is choose is choose ...

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4528 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-07-04 11:00:51 +00:00
parent 3fac52583e
commit cbafd3fc82
11 changed files with 115 additions and 123 deletions

View File

@ -63,14 +63,23 @@ InsetFormula::InsetFormula()
: par_(MathAtom(new MathHullInset)), loader_(0)
{}
/*
InsetFormula::InsetFormula(string const & type)
: par_(MathAtom(new MathHullInset(type))), loader_(0)
{}
InsetFormula::InsetFormula(BufferView * bv)
: par_(MathAtom(new MathHullInset)), loader_(0)
{
view_ = bv;
}
*/
InsetFormula::InsetFormula(string const & data)
: par_(MathAtom(new MathHullInset)), loader_(0)
{
if (!data.size())
return;
if (!mathed_parse_normal(par_, data))
lyxerr << "cannot interpret '" << data << "' as math\n";
}
Inset * InsetFormula::clone(Buffer const &, bool) const
@ -95,23 +104,6 @@ int InsetFormula::latex(Buffer const *, ostream & os, bool fragile, bool) const
}
void InsetFormula::read(string const & s)
{
if (s.size()) {
bool res = mathed_parse_normal(par_, s);
if (!res)
res = mathed_parse_normal(par_, "$" + s + "$");
if (!res) {
lyxerr << "cannot interpret '" << s << "' as math\n";
par_ = MathAtom(new MathHullInset("simple"));
}
}
metrics();
updatePreview();
}
int InsetFormula::ascii(Buffer const *, ostream & os, int) const
{
@ -184,7 +176,8 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
if (canPreview()) {
pi.pain.image(x + 1, y - a + 1, w - 2, h - 2, *(loader_->image()));
} else {
pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
//pi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
pi.base.style = LM_ST_TEXT;
pi.base.font = font;
pi.base.font.setColor(LColor::math);
if (lcolor.getX11Name(LColor::mathbg)
@ -302,7 +295,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
int x;
int y;
mathcursor->getPos(x, y);
hull()->mutate(arg);
mutate(arg);
mathcursor->setPos(x, y);
mathcursor->normalize();
updateLocal(bv, true);
@ -326,9 +319,9 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
int y = 0;
mathcursor->getPos(x, y);
if (hullType() == "simple")
hull()->mutate("equation");
mutate("equation");
else
hull()->mutate("simple");
mutate("simple");
mathcursor->setPos(x, y);
mathcursor->normalize();
updateLocal(bv, true);
@ -419,14 +412,15 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const
}
string const & InsetFormula::hullType() const
string InsetFormula::hullType() const
{
return hull()->getType();
return hull() ? hull()->getType() : "none";
}
void InsetFormula::mutate(string const & type )
{
if (hull())
hull()->mutate(type);
}

View File

@ -34,7 +34,9 @@ public:
///
InsetFormula();
///
//explicit InsetFormula(string const & type);
explicit InsetFormula(BufferView *);
///
explicit InsetFormula(const string & data);
///
int ascent(BufferView *, LyXFont const &) const;
///
@ -49,8 +51,6 @@ public:
///
void read(Buffer const *, LyXLex & lex);
///
void read(const string & data);
///
int latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
///
int ascii(Buffer const *, std::ostream &, int linelen) const;
@ -72,7 +72,7 @@ public:
///
std::vector<string> const getLabelList() const;
///
string const & hullType() const;
string hullType() const;
///
MathAtom const & par() const { return par_; }
///

View File

@ -79,7 +79,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
delete new_inset;
return false;
}
new_inset->edit(bv, 0, 0, mouse_button::none);
new_inset->edit(bv, true);
return true;
}
@ -154,7 +154,8 @@ void InsetFormulaBase::metrics(BufferView * bv) const
view_ = bv;
MathMetricsInfo mi;
mi.view = view_;
mi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
//mi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
mi.base.style = LM_ST_TEXT;
mi.base.font = font_;
mi.base.font.setColor(LColor::math);
par()->metrics(mi);
@ -227,8 +228,8 @@ void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
bv->hideLockedInsetCursor();
else {
metrics(bv);
int x;
int y;
int x = 0;
int y = 0;
mathcursor->getPos(x, y);
y -= yo_;
int asc = 0;
@ -935,7 +936,9 @@ bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
if (bv->available()) {
if (!bv->available())
return;
// use selection if available..
//string sel;
//if (action == LFUN_MATH_IMPORT_SELECTION)
@ -945,9 +948,9 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
if (sel.empty()) {
InsetFormula * f = new InsetFormula;
f->mutate("simple");
InsetFormula * f = new InsetFormula(bv);
if (openNewInset(bv, f)) {
f->mutate("simple");
// don't do that also for LFUN_MATH_MODE unless you want end up with
// always changing to mathrm when opening an inlined inset
// -- I really hate "LyXfunc overloading"...
@ -961,9 +964,7 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
if (sel.find("\\newcommand") == string::npos &&
sel.find("\\def") == string::npos)
{
InsetFormula * f = new InsetFormula;
f->mutate("simple");
f->read(sel);
InsetFormula * f = new InsetFormula(sel);
bv->getLyXText()->cutSelection(bv);
openNewInset(bv, f);
} else {
@ -975,7 +976,6 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
openNewInset(bv, f);
}
}
}
bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
}
@ -1000,7 +1000,8 @@ void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
void mathDispatchMathMacro(BufferView * bv, string const & arg)
{
if (bv->available()) {
if (!bv->available())
return;
if (arg.empty())
bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
else {
@ -1010,15 +1011,15 @@ void mathDispatchMathMacro(BufferView * bv, string const & arg)
openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
}
}
}
void mathDispatchMathDelim(BufferView * bv, string const & arg)
{
if (bv->available()) {
InsetFormula * f = new InsetFormula;
if (!bv->available())
return;
InsetFormula * f = new InsetFormula(bv);
if (openNewInset(bv, f)) {
f->mutate("simple");
if (openNewInset(bv, new InsetFormula))
bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
}
}
@ -1026,10 +1027,11 @@ void mathDispatchMathDelim(BufferView * bv, string const & arg)
void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
{
if (bv->available()) {
InsetFormula * f = new InsetFormula;
if (!bv->available())
return;
InsetFormula * f = new InsetFormula(bv);
if (openNewInset(bv, f)) {
f->mutate("simple");
if (openNewInset(bv, new InsetFormula))
bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
}
}
@ -1037,32 +1039,27 @@ void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
void mathDispatchInsertMath(BufferView * bv, string const & arg)
{
if (bv->available()) {
if (arg.size() && arg[0] == '\\') {
InsetFormula * f = new InsetFormula;
f->read(arg);
if (!bv->insertInset(f))
delete f;
else if (!mathcursor) // hotfix
bv->getLyXText()->cursorRight(bv);
} else {
mathDispatchMathMode(bv, arg);
}
if (!bv->available())
return;
InsetFormula * f = new InsetFormula(bv);
if (openNewInset(bv, f)) {
f->mutate("simple");
bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATH, arg);
}
}
void mathDispatchGreek(BufferView * bv, string const & arg)
{
if (bv->available()) {
InsetFormula * f = new InsetFormula;
f->mutate("simple");
if (!bv->available())
return;
InsetFormula * f = new InsetFormula(bv);
if (openNewInset(bv, f)) {
f->mutate("simple");
bv->theLockingInset()->localDispatch(bv, LFUN_GREEK, arg);
bv->unlockInset(f);
}
}
}
void mathDispatch(BufferView *, kb_action, string const &)

View File

@ -43,7 +43,7 @@ public:
///
virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
///
virtual string const & hullType() const = 0;
virtual string hullType() const { return "none"; }
/// lowest x coordinate
virtual int xlow() const;
/// highest x coordinate
@ -125,6 +125,7 @@ private:
/// common base for handling accents
void handleAccent(BufferView * bv, string const & arg, string const & name);
protected:
///
mutable BufferView * view_;
///

View File

@ -158,13 +158,6 @@ Inset::Code InsetFormulaMacro::lyxCode() const
}
string const & InsetFormulaMacro::hullType() const
{
static string macro("macro");
return macro;
}
void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
int y, float & xx, bool /*cleared*/) const
{

View File

@ -64,8 +64,6 @@ public:
///
Inset::Code lyxCode() const;
///
string const & hullType() const;
///
MathAtom const & par() const;
///
MathAtom & par();

View File

@ -13,7 +13,8 @@
using std::max;
MathBinomInset::MathBinomInset()
MathBinomInset::MathBinomInset(bool choose)
: choose_(choose)
{}
@ -58,7 +59,10 @@ void MathBinomInset::draw(MathPainterInfo & pi, int x, int y) const
void MathBinomInset::write(WriteStream & os) const
{
if (choose_)
os << '{' << cell(0) << " \\choose " << cell(1) << '}';
else
os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
}

View File

@ -14,7 +14,7 @@
class MathBinomInset : public MathFracbaseInset {
public:
///
MathBinomInset();
explicit MathBinomInset(bool choose = false);
///
MathInset * clone() const;
///
@ -28,6 +28,8 @@ public:
private:
///
int dw() const;
///
bool choose_;
};
#endif

View File

@ -297,7 +297,7 @@ MathAtom createMathInset(string const & s)
if (s == "stack")
return MathAtom(new MathStackrelInset);
if (s == "binom" || s == "choose")
return MathAtom(new MathBinomInset);
return MathAtom(new MathBinomInset(s == "choose"));
if (s == "over" || s == "frac")
return MathAtom(new MathFracInset);
if (s == "atop")

View File

@ -107,7 +107,7 @@ private:
/// consistency check
void check() const;
/// "simple", "display", "eqnarray",...
/// "none", "simple", "display", "eqnarray",...
string type_;
///
std::vector<int> nonum_;

View File

@ -582,7 +582,10 @@ bool Parser::parse_normal(MathAtom & at)
if (ar.size() != 1) {
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;
return true;
}
at = ar[0];
@ -690,7 +693,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
MathArray ar;
parse_into(ar, FLAG_BRACE_LAST, mathmode);
// reduce multiple nesting levels to a single one
// this helps to keep the annoyance of a choose b to a minimum
// this helps to keep the annoyance of "a choose b" to a minimum
if (ar.size() && ar.front()->asBraceInset())
ar = ar.front()->asBraceInset()->cell(0);
cell->push_back(MathAtom(new MathBraceInset));