re-enabling the "selected text gets converted to math"-feature

small bix fix
cosmetics


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2510 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-08-14 07:46:11 +00:00
parent 1279189bd0
commit 8766c98cfe
7 changed files with 142 additions and 111 deletions

View File

@ -1,8 +1,3 @@
2001-08-13 Angus Leeming <a.leeming@ic.ac.uk>
* math_parser.C (lexArg): remove default argument from the .C file
as it causes DEC cxx to complain about a redefinition.
2001-08-13 André Pönitz <poenitz@gmx.net>
* math_factory.[Ch]: new files for the creation of math insets
@ -16,6 +11,14 @@
* math_parser.C:
math_cursor.C: reading support for TeX style \over and \choose
* formulabase.C: re-enabling the "selected text gets converted to
math when pressing C-m" feature.
2001-08-13 Angus Leeming <a.leeming@ic.ac.uk>
* math_parser.C (lexArg): remove default argument from the .C file
as it causes DEC cxx to complain about a redefinition.
2001-08-10 André Pönitz <poenitz@gmx.net>
* math_scopeinset.[Ch]: new inset for {} blocks

View File

@ -46,9 +46,6 @@ using std::pair;
using std::endl;
using std::vector;
extern char const * latex_mathenv[];
extern MathCursor * mathcursor;
InsetFormula::InsetFormula()
: par_(new MathMatrixInset)
@ -68,6 +65,13 @@ InsetFormula::InsetFormula(MathInsetTypes t)
InsetFormula::InsetFormula(string const & s)
: par_(mathed_parse_normal(s))
{
if (!par_)
par_ = mathed_parse_normal("$" + s + "$");
if (!par_) {
lyxerr << "cannot interpret '" << s << "' as math\n";
par_ = new MathMatrixInset(LM_OT_SIMPLE);
}
metrics();
}

View File

@ -131,22 +131,26 @@ void InsetFormulaBase::write(Buffer const *, ostream & os) const
write(os);
}
int InsetFormulaBase::latex(Buffer const *, ostream & os,
bool fragile, bool spacing) const
{
return latex(os, fragile, spacing);
}
int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
{
return ascii(os, spacing);
}
int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
{
return linuxdoc(os);
}
int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
{
return docBook(os);
@ -186,6 +190,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
void InsetFormulaBase::edit(BufferView * bv, bool front)
{
// looks hackish but seems to work
edit(bv, front ? 0 : 1, 0, 0);
}
@ -713,16 +718,16 @@ Inset::Code InsetFormulaBase::lyxCode() const
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
if (bv->available()) {
// Feature "Read math inset from selection" disabled.
// // use selection if available..
// use selection if available..
//string sel;
//if (action == LFUN_MATH_IMPORT_SELECTION)
// sel = "";
//else
// sel = bv->getLyXText()->selectionAsString(bv->buffer());
InsetFormula * f;
// if (sel.empty()) {
string sel = bv->getLyXText()->selectionAsString(bv->buffer());
InsetFormulaBase * f;
if (sel.empty()) {
f = new InsetFormula;
if (openNewInset(bv, f)) {
// don't do that also for LFUN_MATH_MODE unless you want end up with
@ -732,11 +737,16 @@ void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
f->localDispatch(bv, LFUN_INSERT_MATH, arg);
}
// } else {
// f = new InsetFormula(sel);
// bv->getLyXText()->cutSelection(bv);
// openNewInset(bv, f);
// }
} else {
// create a macro if we see "\\newcommand" somewhere, and an ordinary
// formula otherwise
if (sel.find("\\newcommand") == string::npos)
f = new InsetFormula(sel);
else
f = new InsetFormulaMacro(sel);
bv->getLyXText()->cutSelection(bv);
openNewInset(bv, f);
}
}
bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
}
@ -746,16 +756,19 @@ void mathDispatchMathDisplay(BufferView * bv, string const & arg)
mathDispatchCreation(bv, arg, true);
}
void mathDispatchMathMode(BufferView * bv, string const & arg)
{
mathDispatchCreation(bv, arg, false);
}
void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
{
mathDispatchCreation(bv, arg, true);
}
void mathDispatchMathMacro(BufferView * bv, string const & arg)
{
if (bv->available()) {
@ -770,6 +783,7 @@ void mathDispatchMathMacro(BufferView * bv, string const & arg)
}
}
void mathDispatchMathDelim(BufferView * bv, string const & arg)
{
if (bv->available()) {
@ -787,6 +801,7 @@ void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
}
}
void mathDispatchInsertMath(BufferView * bv, string const & arg)
{
if (bv->available()) {

View File

@ -44,6 +44,7 @@ extern MathCursor * mathcursor;
InsetFormulaMacro::InsetFormulaMacro()
{
// inset name is inherited from Inset
setInsetName("unknown");
}
@ -55,6 +56,16 @@ InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
}
InsetFormulaMacro::InsetFormulaMacro(string const & s)
{
MathMacroTemplate * t = mathed_parse_macro(s);
MathMacroTable::insertTemplate(*t);
setInsetName(t->name());
delete t;
metrics();
}
Inset * InsetFormulaMacro::clone(Buffer const &, bool) const
{
return new InsetFormulaMacro(*this);

View File

@ -25,17 +25,18 @@
class MathMacroTemplate;
// InsetFormulaMacro's ParInset is the ParInset of the macro definition
// which in turn is stored in the global MathMacroTable.
// No copying/updating needed anymore...
// InsetFormulaMacro's only knows its name and asks the global
// MathMacroTable if it needs to know more.
///
class InsetFormulaMacro: public InsetFormulaBase {
public:
///
InsetFormulaMacro();
///
/// construct a macro hull from its name and the number of arguments
explicit InsetFormulaMacro(string name, int na);
/// constructs a mocro from its LaTeX definition
explicit InsetFormulaMacro(string const & s);
///
int ascent(BufferView *, LyXFont const &) const;
///

View File

@ -1194,62 +1194,6 @@ MathMatrixInset * MathCursor::outerPar() const
static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
}
////////////////////////////////////////////////////////////////////////
bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
{
return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
}
bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
{
if (ti.par_ != it.par_) {
lyxerr << "can't compare cursor and anchor in different insets\n";
return true;
}
if (ti.idx_ != it.idx_)
return ti.idx_ < it.idx_;
return ti.pos_ < it.pos_;
}
MathArray & MathCursorPos::cell(int idx) const
{
return par_->cell(idx);
}
MathArray & MathCursorPos::cell() const
{
return par_->cell(idx_);
}
MathXArray & MathCursorPos::xcell(int idx) const
{
return par_->xcell(idx);
}
MathXArray & MathCursorPos::xcell() const
{
return par_->xcell(idx_);
}
MathCursorPos MathCursor::normalAnchor() const
{
// use Anchor on the same level as Cursor
MathCursorPos normal = Anchor_[Cursor_.size() - 1];
if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
// anchor is behind cursor -> move anchor behind the inset
++normal.pos_;
}
return normal;
}
void MathCursor::interpret(string const & s)
{
@ -1441,3 +1385,61 @@ void MathCursor::interpret(string const & s)
}
////////////////////////////////////////////////////////////////////////
bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
{
return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
}
bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
{
if (ti.par_ != it.par_) {
lyxerr << "can't compare cursor and anchor in different insets\n";
return true;
}
if (ti.idx_ != it.idx_)
return ti.idx_ < it.idx_;
return ti.pos_ < it.pos_;
}
MathArray & MathCursorPos::cell(int idx) const
{
return par_->cell(idx);
}
MathArray & MathCursorPos::cell() const
{
return par_->cell(idx_);
}
MathXArray & MathCursorPos::xcell(int idx) const
{
return par_->xcell(idx);
}
MathXArray & MathCursorPos::xcell() const
{
return par_->xcell(idx_);
}
MathCursorPos MathCursor::normalAnchor() const
{
// use Anchor on the same level as Cursor
MathCursorPos normal = Anchor_[Cursor_.size() - 1];
if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
// anchor is behind cursor -> move anchor behind the inset
++normal.pos_;
}
return normal;
}

View File

@ -316,8 +316,12 @@ int Parser::yylex()
while (is_.good()) {
unsigned char c = getuchar();
//lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl;
if (!is_.good())
break;
if (lexcode[c] == LexNewLine) {
++lineno_;
continue;
@ -329,29 +333,23 @@ int Parser::yylex()
} while (c != '\n' && is_.good()); // eat comments
}
if (lexcode[c] == LexOther) {
ival_ = c;
if (lexcode[c] == LexOther)
return LM_TK_STR;
}
if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) {
ival_ = c;
if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace)
return LM_TK_ALPHA;
}
if (lexcode[c] == LexBOP) {
ival_ = c;
if (lexcode[c] == LexBOP)
return LM_TK_BOP;
}
if (lexcode[c] == LexMath) {
ival_ = 0;
return LM_TK_MATH;
}
if (lexcode[c] == LexSelf) {
if (lexcode[c] == LexSelf)
return c;
}
if (lexcode[c] == LexArgument) {
c = getuchar();
@ -361,9 +359,9 @@ int Parser::yylex()
if (lexcode[c] == LexESC) {
c = getuchar();
//lyxerr << "reading second byte: '" << c << "' code: " << lexcode[c] << endl;
string s;
s += c;
//lyxerr << "reading second byte: '" << c
// << "' code: " << lexcode[c] << endl;
string s(1, c);
latexkeys const * l = in_word_set(s);
if (l) {
//lyxerr << "found key: " << l << endl;
@ -578,11 +576,11 @@ void Parser::parse_into(MathArray & array, unsigned flags)
{
MathTextCodes yyvarcode = LM_TC_VAR;
int t = yylex();
bool panic = false;
int limits = 0;
while (t) {
while (int t = yylex()) {
//lyxerr << "t: " << t << " flags: " << flags << " i: " << ival_
// << " '" << sval_ << "'\n";
//array.dump(lyxerr);
@ -594,9 +592,9 @@ void Parser::parse_into(MathArray & array, unsigned flags)
// skip the brace and collect everything to the next matching
// closing brace
flags |= FLAG_BRACE_LAST;
t = yylex();
continue;
} else {
// take only this single token
// handle only this single token, leave the loop if done
flags |= FLAG_LEAVE;
}
}
@ -608,14 +606,12 @@ void Parser::parse_into(MathArray & array, unsigned flags)
break;
} else {
flags &= ~FLAG_BRACE;
t = yylex();
continue;
}
}
if (flags & FLAG_BLOCK) {
if (t == LM_TK_CLOSE || t == '&' ||
t == LM_TK_NEWLINE || t == LM_TK_END) {
if (t == LM_TK_CLOSE || t == '&' || t == LM_TK_NEWLINE || t == LM_TK_END){
putback(t);
return;
}
@ -844,16 +840,15 @@ void Parser::parse_into(MathArray & array, unsigned flags)
flags &= ~FLAG_LEAVE;
break;
}
}
if (panic) {
lyxerr << " Math Panic, expect problems!\n";
// Search for the end command.
int t;
do {
t = yylex();
} while (is_.good() && t != LM_TK_END && t);
} else {
t = yylex();
}
}
}