mathed87.diff (Bug fixes, new feature "change font on selection")

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2169 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-07-03 07:56:55 +00:00
parent f52893a07d
commit 3d00527d48
9 changed files with 87 additions and 368 deletions

View File

@ -1,3 +1,11 @@
2001-04-27 André Pönitz <poenitz@htwm.de>
* math_parser.C: fix bug where equations did not get their labels
* formulabase.C: new feature: changing font on selection
* several files: subsequent changes
2001-06-29 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* formulabase.C (localDispatch): use .c_str() on istringstream
@ -78,6 +86,20 @@
* math_cursor.C: Renamed stack to path.
2001-06-24 The LyX Project <André>
* *.[Ch]:
Makefile.am: The Big Patch
(rewrite of MathArray, MathCursor, MathMatrixInset, MathBigopInset;
new MathScriptInset for up/down stuff;
delete MathIter/MatXIter, MathParInset, MathRowSt
Changes to the inset inheritance tree, reunification of abstract math
inset base classes;
label/numbering handling back to life;
major changes to the parser(s);
new base class FormulaBase for the two math LyXInsets;
general cleanup and cosmetic changes)
2001-06-19 Angus Leeming <a.leeming@ic.ac.uk>
* math_macro.C:

View File

@ -110,6 +110,14 @@ MathTextCodes MathArray::GetCode(int pos) const
return pos < size() ? MathTextCodes(bf_[pos]) : LM_TC_MIN;
}
void MathArray::setCode(int pos, MathTextCodes t)
{
if (pos > size() || isInset(pos))
return;
bf_[pos] = t;
bf_[pos + 2] = t;
}
void MathArray::insert(int pos, MathInset * p)
{
bf_.insert(bf_.begin() + pos, 2 + sizeof(p), LM_TC_INSET);

View File

@ -110,6 +110,8 @@ public:
///
MathTextCodes GetCode(int pos) const;
///
void setCode(int pos, MathTextCodes t);
///
bool isInset(int pos) const;
///
void Write(std::ostream &, bool) const;

View File

@ -68,6 +68,13 @@ string nicelabel(string const & label)
return label.empty() ? string("(#)") : "(" + label + ")";
}
void handleFont(BufferView * bv, MathTextCodes t)
{
if (mathcursor->Selection())
bv->lockedInsetStoreUndo(Undo::EDIT);
mathcursor->handleFont(t);
}
} // namespaces
@ -431,6 +438,7 @@ void InsetFormulaBase::insetKeyPress(XKeyEvent *)
}
UpdatableInset::RESULT
InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
string const & arg)
@ -619,24 +627,27 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
break;
// Math fonts
case LFUN_BOLD: mathcursor->toggleLastCode(LM_TC_BF); break;
case LFUN_SANS: mathcursor->toggleLastCode(LM_TC_SF); break;
case LFUN_EMPH: mathcursor->toggleLastCode(LM_TC_CAL); break;
case LFUN_ROMAN: mathcursor->toggleLastCode(LM_TC_RM); break;
case LFUN_CODE: mathcursor->toggleLastCode(LM_TC_TT); break;
case LFUN_DEFAULT: mathcursor->setLastCode(LM_TC_VAR); break;
case LFUN_BOLD: handleFont(bv, LM_TC_BF); break;
case LFUN_SANS: handleFont(bv, LM_TC_SF); break;
case LFUN_EMPH: handleFont(bv, LM_TC_CAL); break;
case LFUN_ROMAN: handleFont(bv, LM_TC_RM); break;
case LFUN_CODE: handleFont(bv, LM_TC_TT); break;
case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
case LFUN_MATH_MODE:
handleFont(bv, LM_TC_TEXTRM);
//bv->owner()->message(_("math text mode toggled"));
break;
#ifndef NO_LATEX
#ifdef WITH_WARNINGS
#warning This needs a fix.
// Can we use the ERT inset here? (Lgb)
#endif
case LFUN_TEX:
// varcode = LM_TC_TEX;
mathcursor->setLastCode(LM_TC_TEX);
bv->owner()->message(_("TeX mode"));
if (!mathcursor->Selection()) {
mathcursor->handleFont(LM_TC_TEX);
//bv->owner()->message(_("TeX mode toggled"));
}
break;
#endif
case LFUN_MATH_LIMITS:
bv->lockedInsetStoreUndo(Undo::INSERT);
if (mathcursor->toggleLimits())
@ -730,16 +741,6 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
updateLocal(bv);
break;
// Invalid actions under math mode
case LFUN_MATH_MODE:
if (mathcursor->getLastCode() != LM_TC_TEXTRM) {
bv->owner()->message(_("math text mode"));
varcode = LM_TC_TEXTRM;
} else
varcode = LM_TC_VAR;
mathcursor->setLastCode(varcode);
break;
case LFUN_UNDO:
bv->owner()->message(_("Invalid action in math mode!"));
break;

View File

@ -915,13 +915,23 @@ void MathCursor::doAccent(MathInset * p)
}
void MathCursor::toggleLastCode(MathTextCodes t)
void MathCursor::handleFont(MathTextCodes t)
{
if (selection) {
int const p1 = std::min(cursor_, anchor_);
int const p2 = std::max(cursor_, anchor_);
for (int pos = p1; pos != p2; array().next(pos))
if (!array().isInset(pos)) {
MathTextCodes c = array().GetCode(pos) == t ? LM_TC_VAR : t;
array().setCode(pos, c);
}
} else {
if (lastcode == t)
lastcode = LM_TC_VAR;
else
lastcode = t;
}
}
void MathCursor::GetPos(int & x, int & y)

View File

@ -116,7 +116,7 @@ public:
///
void setLastCode(MathTextCodes t);
///
void toggleLastCode(MathTextCodes t);
void handleFont(MathTextCodes t);
///
MathTextCodes getLastCode() const;
///

View File

@ -109,10 +109,9 @@ union {
string yytext;
int yylineno;
istream * yyis;
bool yy_mtextmode = false;
MathTextCodes yyvarcode;
@ -234,7 +233,7 @@ int yylex()
char c;
yyis->get(c);
if (yy_mtextmode && c == ' ') {
if (yyvarcode == LM_TC_TEXTRM && c == ' ') {
yylval.i = ' ';
return LM_TK_ALPHA;
} else if (lexcode[c] == LexNewLine) {
@ -419,6 +418,10 @@ static string curr_label;
void mathed_parse_lines(MathInset * inset, int col, bool numbered, bool outmost)
{
// save global variables
bool saved_num = curr_num;
string saved_label = curr_label;
MathGridInset * p = static_cast<MathGridInset *>(inset);
for (int row = 0; true; ++row) {
// reset global variables
@ -444,6 +447,10 @@ void mathed_parse_lines(MathInset * inset, int col, bool numbered, bool outmost)
p->appendRow();
}
// restore global variables
curr_num = saved_num;
curr_label = saved_label;
}
@ -536,7 +543,7 @@ void mathed_parse(MathArray & array, unsigned flags)
int tprev = 0;
bool panic = false;
static int plevel = -1;
MathTextCodes varcode = LM_TC_VAR;
yyvarcode = LM_TC_VAR;
int brace = 0;
int acc_brace = 0;
@ -560,7 +567,7 @@ void mathed_parse(MathArray & array, unsigned flags)
switch (t) {
case LM_TK_ALPHA:
do_insert(array, yylval.i, varcode);
do_insert(array, yylval.i, yyvarcode);
break;
case LM_TK_ARGUMENT:
@ -604,8 +611,7 @@ void mathed_parse(MathArray & array, unsigned flags)
break;
}
if (flags & FLAG_BRACE_FONT) {
varcode = LM_TC_VAR;
yy_mtextmode = false;
yyvarcode = LM_TC_VAR;
flags &= ~FLAG_BRACE_FONT;
break;
}
@ -777,7 +783,7 @@ void mathed_parse(MathArray & array, unsigned flags)
break;
case LM_TK_FONT:
yy_mtextmode = (yylval.l->id == LM_TC_TEXTRM);
yyvarcode = static_cast<MathTextCodes>(yylval.l->id);
flags |= (FLAG_BRACE | FLAG_BRACE_FONT);
break;

View File

@ -1,210 +0,0 @@
#include <config.h>
#include "math_rowst.h"
#include "support/LAssert.h"
//
// MathedRowContainer
//
MathedRowStruct::MathedRowStruct()
: asc_(0), desc_(0), y_(0), numbered_(true)
{}
string const & MathedRowStruct::getLabel() const
{
return label_;
}
bool MathedRowStruct::isNumbered() const
{
return numbered_;
}
int MathedRowStruct::getBaseline() const
{
return y_;
}
void MathedRowStruct::setBaseline(int b)
{
y_ = b;
}
int MathedRowStruct::ascent() const
{
return asc_;
}
int MathedRowStruct::descent() const
{
return desc_;
}
void MathedRowStruct::ascent(int a)
{
asc_ = a;
}
void MathedRowStruct::descent(int d)
{
desc_ = d;
}
int MathedRowStruct::getTab(unsigned int i) const
{
return i < widths_.size() ? widths_[i] : 0;
}
void MathedRowStruct::setLabel(string const & l)
{
label_ = l;
}
void MathedRowStruct::setNumbered(bool nf)
{
numbered_ = nf;
}
void MathedRowStruct::setTab(unsigned int i, int t)
{
if (i >= widths_.size())
widths_.resize(i + 2);
widths_[i] = t;
}
//
// MathedRowContainer
//
MathedRowContainer::iterator MathedRowContainer::begin()
{
return iterator(this);
}
MathedRowContainer::iterator MathedRowContainer::end()
{
iterator it(this);
it.pos_ = data_.size();
return it;
}
bool MathedRowContainer::empty() const
{
return data_.size() == 0;
}
void MathedRowContainer::insert(iterator const & it)
{
lyx::Assert(it.st_ == this);
data_.insert(data_.begin() + it.pos_, MathedRowStruct());
}
void MathedRowContainer::erase(iterator & it)
{
lyx::Assert(it.st_ == this);
data_.erase(data_.begin() + it.pos_);
}
MathedRowStruct & MathedRowContainer::back()
{
lyx::Assert(data_.size());
return data_.back();
}
MathedRowStruct const & MathedRowContainer::back() const
{
lyx::Assert(data_.size());
return data_.back();
}
void MathedRowContainer::push_back()
{
data_.push_back(MathedRowStruct());
}
MathedRowContainer::size_type MathedRowContainer::size() const
{
return data_.size();
}
//
// MathedRowContainer::iterator
//
MathedRowContainer::iterator::iterator()
: st_(0), pos_(0)
{}
MathedRowContainer::iterator::iterator(MathedRowContainer * m)
: st_(m), pos_(0)
{}
MathedRowContainer::iterator::operator void *() const
{
return (void *)(st_ && pos_ < st_->size());
}
MathedRowStruct * MathedRowContainer::iterator::operator->()
{
lyx::Assert(st_);
return &st_->data_[pos_];
}
MathedRowStruct const * MathedRowContainer::iterator::operator->() const
{
lyx::Assert(st_);
return &st_->data_[pos_];
}
void MathedRowContainer::iterator::operator++()
{
lyx::Assert(st_);
++pos_;
}
bool MathedRowContainer::iterator::is_last() const
{
lyx::Assert(st_);
return pos_ == st_->size() - 1;
}
bool MathedRowContainer::iterator::operator==(const iterator & it) const
{
return st_ == it.st_ && pos_ == it.pos_;
}

View File

@ -1,120 +0,0 @@
// -*- C++ -*-
#ifndef MATH_ROWST_H
#define MATH_ROWST_H
#include "support/LAssert.h"
#include <vector>
/** The physical structure of a row and aditional information is stored here.
It allows to manage the extra info independently of the paragraph data.
Only used for multiline paragraphs.
*/
class MathedRowStruct
{
public:
///
typedef std::vector<int> Widths;
///
MathedRowStruct();
///
string const & getLabel() const;
///
bool isNumbered() const;
///
int getBaseline() const;
///
void setBaseline(int b);
///
int ascent() const;
///
int descent() const;
///
void ascent(int a);
///
void descent(int d);
///
int getTab(unsigned int i) const;
///
void setLabel(string const & l);
///
void setNumbered(bool nf);
///
void setTab(unsigned int i, int t);
///
friend class MathedRowSt;
protected:
/// Vericals
int asc_;
///
int desc_;
///
int y_;
/// widths
Widths widths_;
///
string label_;
///
bool numbered_;
};
class MathedRowContainer {
public:
///
typedef std::vector<MathedRowStruct> data_type;
///
typedef data_type::size_type size_type;
///
struct iterator {
///
iterator();
///
explicit iterator(MathedRowContainer * m);
/// "better" conversion to bool
operator void *() const;
///
MathedRowStruct * operator->();
///
MathedRowStruct const * operator->() const;
///
void operator++();
///
bool is_last() const;
///
bool operator==(const iterator & it) const;
//private:
MathedRowContainer * st_;
///
unsigned int pos_;
};
public:
///
iterator begin();
///
iterator end();
///
bool empty() const;
/// insert item before 'it'
void insert(iterator const & it);
/// erase item pointed to by 'it'
void erase(iterator & it);
/// access to last row
MathedRowStruct & back();
/// access to last row
MathedRowStruct const & back() const;
/// append empty element
void push_back();
///
size_type size() const;
//private:
///
std::vector<MathedRowStruct> data_;
};
#endif