-2001-07-04 André Pönitz <poenitz@htwm.de>
+
+2001-07-10 André Pönitz <poenitz@htwm.de>
+
+ * math_accentinset.[hC]: rewrite
+
+ * math_parser.C:
+ math_cursor.C: subsequent changes
+
+2001-07-10 André Pönitz <poenitz@htwm.de>
* math_grid.C: <Delete> in the first cell of a completely empty row
deletes that row, <C-Return> places the cursor in the first of the
#include "font.h"
#include "math_arrayinset.h"
#include "math_spaceinset.h"
-#include "math_deliminset.h"
#include "support/lyxlib.h"
#include "mathed/support.h"
#include "undo_funcs.h"
mathcursor->handleFont(t);
}
+void handleAccent(BufferView * bv, int code)
+{
+ bv->lockedInsetStoreUndo(Undo::EDIT);
+ mathcursor->handleAccent(code);
+}
+
+void handleDelim(BufferView * bv, int l, int r)
+{
+ bv->lockedInsetStoreUndo(Undo::EDIT);
+ mathcursor->handleDelim(l, r);
+}
+
bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
{
LyXText * lt = bv->getLyXText();
return true;
}
+
} // namespaces
// --- accented characters ------------------------------
- case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
- case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
- case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
- case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
- case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
- case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
- case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
- case LFUN_CARON: mathcursor->setAccent(LM_check); break;
- case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
- case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
+ case LFUN_UMLAUT: handleAccent(bv, LM_ddot); break;
+ case LFUN_CIRCUMFLEX: handleAccent(bv, LM_hat); break;
+ case LFUN_GRAVE: handleAccent(bv, LM_grave); break;
+ case LFUN_ACUTE: handleAccent(bv, LM_acute); break;
+ case LFUN_TILDE: handleAccent(bv, LM_tilde); break;
+ case LFUN_MACRON: handleAccent(bv, LM_bar); break;
+ case LFUN_DOT: handleAccent(bv, LM_dot); break;
+ case LFUN_CARON: handleAccent(bv, LM_check); break;
+ case LFUN_BREVE: handleAccent(bv, LM_breve); break;
+ case LFUN_VECTOR: handleAccent(bv, LM_vec); break;
// Greek mode
case LFUN_GREEK:
} else if (vdelim.find(rt[0]) != string::npos)
irt = rt[0];
- if (mathcursor->selection) {
- MathDelimInset * p = new MathDelimInset(ilt, irt);
- MathArray ar;
- mathcursor->selArray(ar);
- lyxerr << "selarray: " << ar << "\n";
- p->cell(0) = ar;
- mathcursor->insert(p);
- } else {
- mathcursor->insert(new MathDelimInset(ilt, irt));
- }
+ handleDelim(bv, ilt, irt);
updateLocal(bv);
break;
}
default:
if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
unsigned char c = arg[0];
- lyxerr << "char: '" << c << "' int: " << int(c) << endl;
+ //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
//owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
- lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
+ //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
bv->lockedInsetStoreUndo(Undo::INSERT);
- if (c == ' ' && mathcursor->getAccent() == LM_hat) {
- c = '^';
- mathcursor->setAccent(0);
- }
-
if (c == 0) { // Dead key, do nothing
//lyxerr << "deadkey" << endl;
break;
using std::ostream;
-MathAccentInset::MathAccentInset(byte cx, MathTextCodes f, int cd)
- : MathInset(1), c(cx), fn(f), code(cd), inset(0)
+MathAccentInset::MathAccentInset(int f)
+ : MathInset(1), code(f)
{}
-MathAccentInset::MathAccentInset(MathInset * ins, int cd)
- : MathInset(0), c(0), fn(LM_TC_MIN), code(cd), inset(ins)
-{}
-
-
-MathAccentInset::~MathAccentInset()
-{
- delete inset;
-}
-
-
MathInset * MathAccentInset::clone() const
{
- MathAccentInset * p;
-
- if (inset)
- p = new MathAccentInset(inset->clone(), code);
- else
- p = new MathAccentInset(c, fn, code);
-
- return p;
+ return new MathAccentInset(*this);
}
-
-void MathAccentInset::draw(Painter & pain, int x, int y)
-{
- int const dw = width() - 2;
-
- if (inset)
- inset->draw(pain, x, y);
- else
- drawChar(pain, fn, size(), x, y, c);
- x += (code == LM_not) ? (width() - dw) / 2 : 2;
- mathed_draw_deco(pain, x, y - dy, dw, dh, code);
-}
-
-
void MathAccentInset::Metrics(MathStyles st)
{
- if (inset) {
- inset->Metrics(st);
- ascent_ = inset->ascent();
- descent_ = inset->descent();
- width_ = inset->width();
- dh = ascent_;
- } else {
- mathed_char_dim(fn, size(), c, ascent_, descent_, width_);
- dh = width() / 2 - 1;
- }
+ xcell(0).Metrics(st);
+ ascent_ = xcell(0).ascent();
+ descent_ = xcell(0).descent();
+ width_ = xcell(0).width();
+ dh = 5;
+
if (code == LM_not) {
ascent_ += dh;
descent_ += dh;
ascent_ += dh + 2;
dy = ascent_;
-// if (MathIsBinary(fn))
-// width += 2*mathed_char_width(fn, size, ' ');
+}
+
+void MathAccentInset::draw(Painter & pain, int x, int y)
+{
+ int const dw = width() - 2;
+ xcell(0).draw(pain, x, y);
+ x += (code == LM_not) ? (width() - dw) / 2 : 2;
+ mathed_draw_deco(pain, x, y - dy, dw, dh, code);
}
{
latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
os << '\\' << l->name;
- if (code!= LM_not)
- os << '{';
- else
+ if (code == LM_not)
os << ' ';
+ else
+ os << '{';
- if (inset)
- inset->Write(os, fragile);
- else {
- if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM)
- os << '\\' << math_font_name[fn - LM_TC_RM] << '{';
- if (MathIsSymbol(fn)) {
- latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
- if (l)
- os << '\\' << l->name << ' ';
- } else
- os << char(c);
-
- if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM)
- os << '}';
- }
+ cell(0).Write(os, fragile);
- if (code!= LM_not)
+ if (code != LM_not)
os << '}';
}
latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
os << "[accent " << l->name << " ";
- if (inset)
- inset->WriteNormal(os);
- else {
- if (fn >= LM_TC_RM && fn <= LM_TC_TEXTRM)
- os << "[font " << math_font_name[fn - LM_TC_RM] << "]";
- if (MathIsSymbol(fn)) {
- latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
- if (l)
- os << "[symbol " << l->name << "] ";
- } else
- os << "[char " << char(c) << "] ";
- }
+ cell(0).WriteNormal(os);
os << "] ";
}
-
-int MathAccentInset::getAccentCode() const
-{
- return code;
-}
class MathAccentInset : public MathInset {
public:
///
- MathAccentInset(byte, MathTextCodes, int);
+ explicit MathAccentInset(int);
///
- MathAccentInset(MathInset *, int);
- ///
- ~MathAccentInset();
- ///
- MathInset * clone() const;
+ MathInset * clone() const;
///
void draw(Painter &, int, int);
///
int getAccentCode() const;
///
bool isAccentInset() const { return true; }
-protected:
- ///
- byte c;
- ///
- MathTextCodes fn;
+private:
///
int code;
///
- MathInset * inset;
+ int dh;
///
- int dh, dy;
+ int dy;
};
#endif
#include "math_fracinset.h"
#include "math_decorationinset.h"
#include "math_dotsinset.h"
+#include "math_deliminset.h"
#include "math_accentinset.h"
#include "math_macrotemplate.h"
#include "math_sqrtinset.h"
MathCursor::MathCursor(InsetFormulaBase * formula)
: formula_(formula)
{
- accent = 0;
lastcode = LM_TC_MIN;
macro_mode = false;
first();
}
-
void MathCursor::insert(char c, MathTextCodes t)
{
- lyxerr << "inserting '" << c << "'\n";
+ //lyxerr << "inserting '" << c << "'\n";
if (selection)
SelDel();
}
}
- if (accent)
- doAccent(c, t);
- else {
- array().insert(cursor_, c, t);
- array().next(cursor_);
- }
+ array().insert(cursor_, c, t);
+ array().next(cursor_);
lastcode = t;
- return;
}
SelDel();
}
- if (accent && !p->nargs())
- doAccent(p);
- else {
- array().insert(cursor_, p);
- array().next(cursor_);
- }
-
- //if (p->nargs())
- // push(p, true);
+ array().insert(cursor_, p);
+ array().next(cursor_);
}
break;
case LM_TK_ACCENT:
- setAccent(l->id);
+ p = new MathAccentInset(l->id);
break;
case LM_TK_MACRO:
imacro->SetName(l->name);
} else {
Left();
- if (nextInset()->isAccentInset())
- setAccent(
- static_cast<MathAccentInset*>(nextInset())->getAccentCode());
array().erase(cursor_);
if (l || MathMacroTable::hasTemplate(imacro->name()))
Interpret(imacro->name());
}
}
-void MathCursor::selArray(MathArray & ar) const
-{
- int const p1 = min(cursor_, anchor_);
- int const p2 = max(cursor_, anchor_);
- ar = array();
- ar.erase(p2, ar.size());
- ar.erase(0, p1);
-}
-
-
void MathCursor::SelCut()
{
seldump("SelCut");
}
-void MathCursor::setAccent(int ac)
-{
- if (ac > 0 && accent < 8)
- nestaccent[accent++] = ac;
- else
- accent = 0; // consumed!
-}
-
-
-int MathCursor::getAccent() const
-{
- return accent > 0 ? nestaccent[accent - 1] : 0;
-}
-
-
-void MathCursor::doAccent(char c, MathTextCodes t)
-{
- MathInset * ac = 0;
-
- for (int i = accent - 1; i >= 0; --i) {
- if (i == accent - 1)
- ac = new MathAccentInset(c, t, nestaccent[i]);
- else
- ac = new MathAccentInset(ac, nestaccent[i]);
- }
-
- if (ac)
- insert(ac);
-
- accent = 0; // consumed!
-}
-
-
-void MathCursor::doAccent(MathInset * p)
-{
- MathInset * ac = 0;
-
- for (int i = accent - 1; i >= 0; --i) {
- if (i == accent - 1)
- ac = new MathAccentInset(p, nestaccent[i]);
- else
- ac = new MathAccentInset(ac, nestaccent[i]);
- }
-
- if (ac)
- insert(ac);
-
- accent = 0; // consumed!
-}
-
-
void MathCursor::handleFont(MathTextCodes t)
{
if (selection) {
}
+void MathCursor::handleAccent(int code)
+{
+ MathAccentInset * p = new MathAccentInset(code);
+ if (selection) {
+ SelCut();
+ p->cell(0) = selarray;
+ }
+ insert(p);
+}
+
+void MathCursor::handleDelim(int l, int r)
+{
+ MathDelimInset * p = new MathDelimInset(l, r);
+ if (selection) {
+ SelCut();
+ p->cell(0) = selarray;
+ }
+ insert(p);
+}
+
+
void MathCursor::GetPos(int & x, int & y)
{
x = xarray().xo() + xarray().pos2x(cursor_);
void SetSize(MathStyles);
///
bool toggleLimits();
- /// Set accent: if argument = 0 it's considered consumed
- void setAccent(int ac = 0);
- /// Returns last accent
- int getAccent() const;
///
// Macro mode methods
void MacroModeOpen();
void setLastCode(MathTextCodes t);
///
void handleFont(MathTextCodes t);
+ ///
+ void handleAccent(int code);
+ ///
+ void handleDelim(int l, int r);
/// Splits cells and shifts right part to the next cell
void splitCell();
/// Splits line and insert new row of cell
///
MathTextCodes prevCode() const;
///
- void selArray(MathArray &) const;
- ///
char valign() const;
///
char halign() const;
///
InsetFormulaBase * const formula_;
///
- void doAccent(char c, MathTextCodes t);
- ///
- void doAccent(MathInset * p);
- ///
- int accent;
- ///
- int nestaccent[8];
- ///
MathTextCodes lastcode;
///
// This macro doesn't have arguments
{
MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
- t->push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not));
+ MathAccentInset * p = new MathAccentInset(LM_not);
+ p->cell(0).push_back(LM_in, LM_TC_BOPS);
+ t->push_back(p);
insertTemplate(t);
}
{
MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
- t->push_back(new MathAccentInset('0', LM_TC_RM, LM_not));
+ MathAccentInset * p = new MathAccentInset(LM_not);
+ p->cell(0).push_back('0', LM_TC_VAR);
+ t->push_back(p);
insertTemplate(t);
}
int yylex()
{
- static int init_done;
+ static bool init_done = false;
- if (!init_done) LexInitCodes();
+ if (!init_done) {
+ LexInitCodes();
+ init_done = true;
+ }
while (yyis->good()) {
unsigned char c = getuchar(yyis);
}
-// Accent hacks only for 0.12. Stolen from Cursor.
-int accent = 0;
-int nestaccent[8];
-
-void setAccent(int ac)
-{
- if (ac > 0 && accent < 8)
- nestaccent[accent++] = ac;
- else
- accent = 0; // consumed!
-}
-
-
-MathInset * doAccent(unsigned char c, MathTextCodes t)
-{
- MathInset * ac = 0;
-
- for (int i = accent - 1; i >= 0; --i) {
- if (i == accent - 1)
- ac = new MathAccentInset(c, t, nestaccent[i]);
- else
- ac = new MathAccentInset(ac, nestaccent[i]);
- }
- accent = 0; // consumed!
-
- return ac;
-}
-
-
-MathInset * doAccent(MathInset * p)
-{
- MathInset * ac = 0;
-
- for (int i = accent - 1; i >= 0; --i) {
- if (i == accent - 1)
- ac = new MathAccentInset(p, nestaccent[i]);
- else
- ac = new MathAccentInset(ac, nestaccent[i]);
- }
- accent = 0; // consumed!
-
- return ac;
-}
-
-
-void do_insert(MathArray & dat, MathInset * m)
-{
- if (accent)
- dat.push_back(doAccent(m));
- else
- dat.push_back(m);
-}
-
-void do_insert(MathArray & dat, unsigned char ch, MathTextCodes fcode)
-{
- if (accent)
- dat.push_back(doAccent(ch, fcode));
- else
- dat.push_back(ch, fcode);
-}
-
-
void handle_frac(MathArray & dat, string const & name)
{
MathFracInset * p = new MathFracInset(name);
yyvarcode = LM_TC_VAR;
int brace = 0;
- int acc_brace = 0;
- int acc_braces[8];
++plevel;
while (t) {
switch (t) {
case LM_TK_ALPHA:
- do_insert(array, yylval.i, yyvarcode);
+ array.push_back(yylval.i, yyvarcode);
break;
case LM_TK_ARGUMENT:
break;
case LM_TK_STR:
- do_insert(array, yylval.i, LM_TC_CONST);
+ array.push_back(yylval.i, LM_TC_CONST);
break;
case LM_TK_OPEN:
++brace;
- if (accent && tprev == LM_TK_ACCENT) {
- acc_braces[acc_brace++] = brace;
- break;
- }
if (flags & FLAG_BRACE_OPT) {
flags &= ~FLAG_BRACE_OPT;
flags |= FLAG_BRACE;
panic = true;
break;
}
- if (acc_brace && brace == acc_braces[acc_brace - 1] - 1) {
- --acc_brace;
- break;
- }
if (flags & FLAG_BRACE_FONT) {
yyvarcode = LM_TC_VAR;
flags &= ~FLAG_BRACE_FONT;
case LM_TK_SYM:
if (yylval.l->id < 256) {
MathTextCodes tc = MathIsBOPS(yylval.l->id) ? LM_TC_BOPS: LM_TC_SYMB;
- do_insert(array, yylval.l->id, tc);
+ array.push_back(yylval.l->id, tc);
} else
- do_insert(array, new MathFuncInset(yylval.l->name));
+ array.push_back(new MathFuncInset(yylval.l->name));
break;
case LM_TK_BOP:
- do_insert(array, yylval.i, LM_TC_BOP);
+ array.push_back(yylval.i, LM_TC_BOP);
break;
case LM_TK_SPACE:
case LM_TK_WIDE:
{
- MathDecorationInset * sq = new MathDecorationInset(yylval.l->id);
- mathed_parse(sq->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
- array.push_back(sq);
+ MathDecorationInset * p = new MathDecorationInset(yylval.l->id);
+ mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
+ array.push_back(p);
break;
}
case LM_TK_ACCENT:
- setAccent(yylval.l->id);
+ {
+ MathAccentInset * p = new MathAccentInset(yylval.l->id);
+ mathed_parse(p->cell(0), FLAG_BRACE | FLAG_BRACE_LAST);
+ array.push_back(p);
break;
+ }
case LM_TK_NONUM:
curr_num = false;
case LM_TK_PMOD:
case LM_TK_FUNC:
- if (accent)
- array.push_back(t, LM_TC_CONST);
- else
+ //if (accent)
+ // array.push_back(t, LM_TC_CONST);
+ //else
array.push_back(new MathFuncInset(yylval.l->name));
break;
MathMacro * m = MathMacroTable::cloneTemplate(yytext);
for (int i = 0; i < m->nargs(); ++i)
mathed_parse(m->cell(i), FLAG_BRACE_OPT | FLAG_BRACE_LAST);
- do_insert(array, m);
+ array.push_back(m);
m->Metrics(LM_ST_TEXT);
} else
- do_insert(array, new MathFuncInset(yytext, LM_OT_UNDEF));
+ array.push_back(new MathFuncInset(yytext, LM_OT_UNDEF));
break;
case LM_TK_END:
mm->halign(halign);
mathed_parse_lines(mm, halign.size(), latex_mathenv[i].numbered, false);
- do_insert(array, mm);
+ array.push_back(mm);
//lyxerr << "read matrix " << *mm << "\n";
break;
} else
}
case LM_TK_MACRO:
- do_insert(array, MathMacroTable::cloneTemplate(yylval.l->name));
+ array.push_back(MathMacroTable::cloneTemplate(yylval.l->name));
break;
case LM_TK_LABEL:
return p;
}
-
-