get rid of several friends small cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1519 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-15 12:22:01 +00:00
parent 50be761b25
commit d5905fabf6
29 changed files with 1597 additions and 1487 deletions

View File

@ -1,3 +1,9 @@
2001-02-15 Lars Gullik Bjønnes <larsbj@lyx.org>
* matriz.C: clean up a bit.
* several files: changes so that several friends can be removed
2001-02-14 André Pönitz <poenitz@htwm.de> 2001-02-14 André Pönitz <poenitz@htwm.de>
* formula.C: reformatting * formula.C: reformatting

View File

@ -18,7 +18,7 @@
#include "Lsstream.h" #include "Lsstream.h"
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "formula.h" #pragma implementation
#endif #endif
#include "formula.h" #include "formula.h"
@ -192,9 +192,9 @@ void mathed_init_fonts() //removed 'static' because DEC cxx does not
Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY); Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
LyXFont f = WhichFont(LM_TC_VAR, LM_ST_TEXT); LyXFont f = WhichFont(LM_TC_VAR, LM_ST_TEXT);
MathedInset::df_asc = lyxfont::maxAscent(f); MathedInset::defaultAscent(lyxfont::maxAscent(f));
MathedInset::df_des = lyxfont::maxDescent(f); MathedInset::defaultDescent(lyxfont::maxDescent(f));
MathedInset::df_width = lyxfont::width('I', f); MathedInset::defaultWidth(lyxfont::width('I', f));
} }
@ -376,7 +376,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & f,
x += float(width(bv, font)); x += float(width(bv, font));
if (is_numbered(par->GetType())) { if (is_numbered(par->GetType())) {
LyXFont wfont = WhichFont(LM_TC_BF, par->size); LyXFont wfont = WhichFont(LM_TC_BF, par->size());
wfont.setLatex(LyXFont::OFF); wfont.setLatex(LyXFont::OFF);
if (is_singlely_numbered(par->GetType())) { if (is_singlely_numbered(par->GetType())) {
@ -424,8 +424,8 @@ void InsetFormula::Edit(BufferView * bv, int x, int y, unsigned int)
par->Metrics(); par->Metrics();
bv->updateInset(this, false); bv->updateInset(this, false);
x += par->xo; x += par->xo();
y += par->yo; y += par->yo();
mathcursor->SetPos(x, y); mathcursor->SetPos(x, y);
sel_x = 0; sel_x = 0;
sel_y = 0; sel_y = 0;
@ -460,8 +460,8 @@ void InsetFormula::InsertSymbol(BufferView * bv, string const & s)
void InsetFormula::GetCursorPos(BufferView *, int & x, int & y) const void InsetFormula::GetCursorPos(BufferView *, int & x, int & y) const
{ {
mathcursor->GetPos(x, y); mathcursor->GetPos(x, y);
x -= par->xo; x -= par->xo();
y -= par->yo; y -= par->yo();
} }
@ -474,7 +474,7 @@ void InsetFormula::ToggleInsetCursor(BufferView * bv)
int y; int y;
mathcursor->GetPos(x, y); mathcursor->GetPos(x, y);
// x -= par->xo; // x -= par->xo;
y -= par->yo; y -= par->yo();
LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT); LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
int asc = lyxfont::maxAscent(font); int asc = lyxfont::maxAscent(font);
int desc = lyxfont::maxDescent(font); int desc = lyxfont::maxDescent(font);
@ -496,7 +496,7 @@ void InsetFormula::ShowInsetCursor(BufferView * bv, bool)
int y; int y;
mathcursor->GetPos(x, y); mathcursor->GetPos(x, y);
// x -= par->xo; // x -= par->xo;
y -= par->yo; y -= par->yo();
LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT); LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
int asc = lyxfont::maxAscent(font); int asc = lyxfont::maxAscent(font);
int desc = lyxfont::maxDescent(font); int desc = lyxfont::maxDescent(font);
@ -583,8 +583,8 @@ void InsetFormula::InsetButtonRelease(BufferView * bv,
{ {
if (mathcursor) { if (mathcursor) {
HideInsetCursor(bv); HideInsetCursor(bv);
x += par->xo; x += par->xo();
y += par->yo; y += par->yo();
mathcursor->SetPos(x, y); mathcursor->SetPos(x, y);
ShowInsetCursor(bv); ShowInsetCursor(bv);
if (sel_flag) { if (sel_flag) {
@ -614,14 +614,14 @@ void InsetFormula::InsetMotionNotify(BufferView * bv,
if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) { if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
sel_flag = true; sel_flag = true;
HideInsetCursor(bv); HideInsetCursor(bv);
mathcursor->SetPos(sel_x + par->xo, sel_y + par->yo); mathcursor->SetPos(sel_x + par->xo(), sel_y + par->yo());
mathcursor->SelStart(); mathcursor->SelStart();
ShowInsetCursor(bv); ShowInsetCursor(bv);
mathcursor->GetPos(sel_x, sel_y); mathcursor->GetPos(sel_x, sel_y);
} else if (sel_flag) { } else if (sel_flag) {
HideInsetCursor(bv); HideInsetCursor(bv);
x += par->xo; x += par->xo();
y += par->yo; y += par->yo();
mathcursor->SetPos(x, y); mathcursor->SetPos(x, y);
ShowInsetCursor(bv); ShowInsetCursor(bv);
mathcursor->GetPos(x, y); mathcursor->GetPos(x, y);
@ -644,7 +644,7 @@ bool InsetFormula::SetNumber(bool numbf)
{ {
if (disp_flag) { if (disp_flag) {
short type = par->GetType(); short type = par->GetType();
bool oldf = is_numbered(type); bool const oldf = is_numbered(type);
if (numbf && !oldf) if (numbf && !oldf)
++type; ++type;
if (!numbf && oldf) if (!numbf && oldf)
@ -1010,9 +1010,11 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg)
? mathcursor->getLabel() : label; ? mathcursor->getLabel() : label;
#warning This is a terrible hack! We should find a better solution. #warning This is a terrible hack! We should find a better solution.
/// This is needed because in some positions mathcursor->cursor->crow // This is needed because in some positions
/// is equal to 0, and therefore the label cannot be inserted. // mathcursor->cursor->crow is equal to 0, and therefore
/// So we move the cursor left until mathcursor->cursor->crow != 0. // the label cannot be inserted.
// So we move the cursor left until
// mathcursor->cursor->crow != 0.
while (old_label == MathedXIter::error_label) { while (old_label == MathedXIter::error_label) {
if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED) if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
return DISPATCHED; return DISPATCHED;
@ -1039,11 +1041,11 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg)
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label)) if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
bv->redraw(); bv->redraw();
if (is_multi_numbered(par->GetType())) if (is_multi_numbered(par->GetType())) {
mathcursor->setLabel(new_label); mathcursor->setLabel(new_label);
// MathMatrixInset *mt = (MathMatrixInset*)par; // MathMatrixInset *mt = (MathMatrixInset*)par;
// mt->SetLabel(new_label); // mt->SetLabel(new_label);
else } else
label = new_label; label = new_label;
UpdateLocal(bv); UpdateLocal(bv);
@ -1096,9 +1098,7 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg)
mathcursor->MacroModeOpen(); mathcursor->MacroModeOpen();
mathcursor->clearLastCode(); mathcursor->clearLastCode();
varcode = LM_TC_MIN; varcode = LM_TC_MIN;
} else } else if (!varcode) {
if (!varcode) {
short f = (mathcursor->getLastCode()) ? short f = (mathcursor->getLastCode()) ?
mathcursor->getLastCode() : mathcursor->getLastCode() :
static_cast<MathedTextCodes>(mathcursor->GetFCode()); static_cast<MathedTextCodes>(mathcursor->GetFCode());
@ -1132,9 +1132,7 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg)
if (greek_kb_flag<2) if (greek_kb_flag<2)
greek_kb_flag = 0; greek_kb_flag = 0;
} else } else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
mathcursor->Insert(c, LM_TC_TEX); mathcursor->Insert(c, LM_TC_TEX);
if (c == '{') { if (c == '{') {
mathcursor->Insert('}', LM_TC_TEX); mathcursor->Insert('}', LM_TC_TEX);
@ -1142,40 +1140,26 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg)
} }
mathcursor->clearLastCode(); mathcursor->clearLastCode();
// varcode = LM_TC_MIN; // varcode = LM_TC_MIN;
} else } else if (c == '_' && varcode == LM_TC_TEX) {
if (c == '_' && varcode == LM_TC_TEX) {
mathcursor->Insert(c, LM_TC_SPECIAL); mathcursor->Insert(c, LM_TC_SPECIAL);
mathcursor->clearLastCode(); mathcursor->clearLastCode();
// varcode = LM_TC_MIN; // varcode = LM_TC_MIN;
} else } else if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
mathcursor->MacroModeOpen(); mathcursor->MacroModeOpen();
mathcursor->clearLastCode(); mathcursor->clearLastCode();
mathcursor->Insert(c, LM_TC_MIN); mathcursor->Insert(c, LM_TC_MIN);
} else } else if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c)) {
if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c)) {
mathcursor->Insert(c, LM_TC_CONST); mathcursor->Insert(c, LM_TC_CONST);
} else } else if (strchr("+/-*<>=", c)) {
if (strchr("+/-*<>=", c)) {
mathcursor->Insert(c, LM_TC_BOP); mathcursor->Insert(c, LM_TC_BOP);
} else } else if (strchr(latex_special_chars, c) && c!= '_') {
if (strchr(latex_special_chars, c) && c!= '_') {
mathcursor->Insert(c, LM_TC_SPECIAL); mathcursor->Insert(c, LM_TC_SPECIAL);
} else } else if (c == '_' || c == '^') {
if (c == '_' || c == '^') {
char s[2]; char s[2];
s[0] = c; s[0] = c;
s[1] = 0; s[1] = 0;
mathcursor->Interpret(s); mathcursor->Interpret(s);
} else } else if (c == ' ') {
if (c == ' ') {
if (!varcode) { if (!varcode) {
short f = (mathcursor->getLastCode()) ? short f = (mathcursor->getLastCode()) ?
mathcursor->getLastCode() : mathcursor->getLastCode() :
@ -1187,27 +1171,17 @@ InsetFormula::LocalDispatch(BufferView * bv, int action, string const & arg)
if (varcode == LM_TC_TEXTRM) { if (varcode == LM_TC_TEXTRM) {
mathcursor->Insert(c, LM_TC_TEXTRM); mathcursor->Insert(c, LM_TC_TEXTRM);
} else } else if (was_macro) {
if (was_macro) {
mathcursor->MacroModeClose(); mathcursor->MacroModeClose();
} else } else if (sp) {
if (sp) {
int isp = (sp->GetSpace()<5) ? sp->GetSpace()+1: 0; int isp = (sp->GetSpace()<5) ? sp->GetSpace()+1: 0;
sp->SetSpace(isp); sp->SetSpace(isp);
space_on = true; space_on = true;
} else } else if (!mathcursor->Pop() && mathcursor->IsEnd())
if (!mathcursor->Pop() && mathcursor->IsEnd())
result = FINISHED; result = FINISHED;
} else } else if (c == '\'' || c == '@') {
if (c == '\'' || c == '@') {
mathcursor->Insert (c, LM_TC_VAR); mathcursor->Insert (c, LM_TC_VAR);
} else } else if (c == '\\') {
if (c == '\\') {
if (was_macro) if (was_macro)
mathcursor->MacroModeClose(); mathcursor->MacroModeClose();
bv->owner()->getMiniBuffer()->Set(_("TeX mode")); bv->owner()->getMiniBuffer()->Set(_("TeX mode"));

View File

@ -14,10 +14,9 @@
*/ */
#include <config.h> #include <config.h>
#include <cstdlib>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "formulamacro.h" #pragma implementation
#endif #endif
#include "formulamacro.h" #include "formulamacro.h"
@ -164,10 +163,9 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
} else { } else {
font.setColor(LColor::math); font.setColor(LColor::math);
int y = baseline - ascent(bv, font) + 1; int const y = baseline - ascent(bv, font) + 1;
int w = width(bv, font) - 2; int const w = width(bv, font) - 2;
int h = (ascent(bv, font) + descent(bv, font) - 2); int const h = (ascent(bv, font) + descent(bv, font) - 2);
pain.fillRectangle(int(x), y, w, h, LColor::mathbg); pain.fillRectangle(int(x), y, w, h, LColor::mathbg);
pain.rectangle(int(x), y, w, h, LColor::mathframe); pain.rectangle(int(x), y, w, h, LColor::mathframe);
@ -213,7 +211,8 @@ InsetFormulaMacro::LocalDispatch(BufferView * bv,
if (action == LFUN_MATH_MACROARG) { if (action == LFUN_MATH_MACROARG) {
int i = lyx::atoi(arg) - 1; int i = lyx::atoi(arg) - 1;
if (i >= 0 && i < tmacro->getNoArgs()) { if (i >= 0 && i < tmacro->getNoArgs()) {
mathcursor->Insert(tmacro->getMacroPar(i), LM_TC_INSET); mathcursor->Insert(tmacro->getMacroPar(i),
LM_TC_INSET);
InsetFormula::UpdateLocal(bv); InsetFormula::UpdateLocal(bv);
} }

View File

@ -48,7 +48,7 @@ MathAccentInset::draw(Painter & pain, int x, int y)
else { else {
string s; string s;
s += c; s += c;
drawStr(pain, fn, size, x, y, s); drawStr(pain, fn, size(), x, y, s);
} }
x += (code == LM_not) ? (width-dw) / 2 : 2; x += (code == LM_not) ? (width-dw) / 2 : 2;
mathed_draw_deco(pain, x, y - dy, dw, dh, code); mathed_draw_deco(pain, x, y - dy, dw, dh, code);
@ -65,8 +65,8 @@ MathAccentInset::Metrics()
width = inset->Width(); width = inset->Width();
dh = ascent; dh = ascent;
} else { } else {
mathed_char_height(fn, size, c, ascent, descent); mathed_char_height(fn, size(), c, ascent, descent);
width = mathed_char_width(fn, size, c); width = mathed_char_width(fn, size(), c);
dh = (width - 2) / 2; dh = (width - 2) / 2;
} }
if (code == LM_not) { if (code == LM_not) {

View File

@ -57,7 +57,7 @@ MathBigopInset::draw(Painter & pain, int x, int y)
LColor::mathline); LColor::mathline);
++x; ++x;
} }
pain.text(x, y, s, mathed_get_font(t, size)); pain.text(x, y, s, mathed_get_font(t, size()));
} }
@ -76,8 +76,8 @@ MathBigopInset::Metrics()
s = name; s = name;
t = LM_TC_TEXTRM; t = LM_TC_TEXTRM;
} }
mathed_string_height(t, size, s, ascent, descent); mathed_string_height(t, size(), s, ascent, descent);
width = mathed_string_width(t, size, s); width = mathed_string_width(t, size(), s);
if (sym == LM_oint) width += 2; if (sym == LM_oint) width += 2;
} }

View File

@ -42,7 +42,8 @@ MathDecorationInset::draw(Painter & pain, int x, int y)
void void
MathDecorationInset::Metrics() MathDecorationInset::Metrics()
{ {
int h = 2*mathed_char_height(LM_TC_VAR, size, 'I', ascent, descent); int h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I',
ascent, descent);
MathParInset::Metrics(); MathParInset::Metrics();
int w = Width() + 4; int w = Width() + 4;
if (w < 16) w = 16; if (w < 16) w = 16;

View File

@ -19,7 +19,6 @@
#include FORMS_H_LOCATION #include FORMS_H_LOCATION
#include <algorithm> #include <algorithm>
#include <cstdlib>
#include "symbol_def.h" #include "symbol_def.h"
#include "math_inset.h" #include "math_inset.h"
#include "LColor.h" #include "LColor.h"

View File

@ -57,19 +57,20 @@ void MathDelimInset::Write(ostream & os, bool fragile)
void void
MathDelimInset::draw(Painter & pain, int x, int y) MathDelimInset::draw(Painter & pain, int x, int y)
{ {
xo = x; yo = y; xo(x);
yo(y);
MathParInset::draw(pain, x + dw + 2, y - dh); MathParInset::draw(pain, x + dw + 2, y - dh);
if (left == '.') { if (left == '.') {
pain.line(x + 4, yo - ascent, pain.line(x + 4, yo() - ascent,
x + 4, yo + descent, x + 4, yo() + descent,
LColor::mathcursor, Painter::line_onoffdash); LColor::mathcursor, Painter::line_onoffdash);
} else } else
mathed_draw_deco(pain, x, y - ascent, dw, Height(), left); mathed_draw_deco(pain, x, y - ascent, dw, Height(), left);
x += Width() - dw - 2; x += Width() - dw - 2;
if (right == '.') { if (right == '.') {
pain.line(x + 4, yo - ascent, pain.line(x + 4, yo() - ascent,
x + 4, yo + descent, x + 4, yo() + descent,
LColor::mathcursor, Painter::line_onoffdash); LColor::mathcursor, Painter::line_onoffdash);
} else } else
mathed_draw_deco(pain, x, y - ascent, dw, Height(), right); mathed_draw_deco(pain, x, y - ascent, dw, Height(), right);
@ -82,7 +83,7 @@ MathDelimInset::Metrics()
MathParInset::Metrics(); MathParInset::Metrics();
int d; int d;
mathed_char_height(LM_TC_CONST, size, 'I', d, dh); mathed_char_height(LM_TC_CONST, size(), 'I', d, dh);
dh /= 2; dh /= 2;
ascent += 2 + dh; ascent += 2 + dh;
descent += 2 - dh; descent += 2 - dh;

View File

@ -30,8 +30,8 @@ MathDotsInset::draw(Painter & pain, int x, int y)
void void
MathDotsInset::Metrics() MathDotsInset::Metrics()
{ {
mathed_char_height(LM_TC_VAR, size, 'M', ascent, descent); mathed_char_height(LM_TC_VAR, size(), 'M', ascent, descent);
width = mathed_char_width(LM_TC_VAR, size, 'M'); width = mathed_char_width(LM_TC_VAR, size(), 'M');
switch (code) { switch (code) {
case LM_ldots: dh = 0; break; case LM_ldots: dh = 0; break;
case LM_cdots: dh = ascent/2; break; case LM_cdots: dh = ascent/2; break;

View File

@ -56,9 +56,9 @@ void MathFracInset::SetStyle(short st)
{ {
MathParInset::SetStyle(st); MathParInset::SetStyle(st);
dh = 0; dh = 0;
den->SetStyle((size == LM_ST_DISPLAY) ? den->SetStyle((size() == LM_ST_DISPLAY) ?
static_cast<short>(LM_ST_TEXT) static_cast<short>(LM_ST_TEXT)
: size); : size());
} }
@ -99,16 +99,19 @@ MathedArray * MathFracInset::GetData()
bool MathFracInset::Inside(int x, int y) bool MathFracInset::Inside(int x, int y)
{ {
int xx = xo - (width - w0) / 2; int xx = xo() - (width - w0) / 2;
return x >= xx && x <= xx + width && y <= yo + descent && y >= yo - ascent; return x >= xx
&& x <= xx + width
&& y <= yo() + descent
&& y >= yo() - ascent;
} }
void MathFracInset::SetFocus(int /*x*/, int y) void MathFracInset::SetFocus(int /*x*/, int y)
{ {
// lyxerr << "y " << y << " " << yo << " " << den->yo << " "; // lyxerr << "y " << y << " " << yo << " " << den->yo << " ";
idx = (y > yo) ? 1: 0; idx = (y > yo()) ? 1: 0;
} }
@ -116,13 +119,13 @@ void
MathFracInset::draw(Painter & pain, int x, int y) MathFracInset::draw(Painter & pain, int x, int y)
{ {
short idxp = idx; short idxp = idx;
short sizex = size; short sizex = size();
idx = 0; idx = 0;
if (size == LM_ST_DISPLAY) ++size; if (size() == LM_ST_DISPLAY) incSize();
MathParInset::draw(pain, x + (width - w0) / 2, y - des0); MathParInset::draw(pain, x + (width - w0) / 2, y - des0);
den->draw(pain, x + (width - w1) / 2, y + den->Ascent() + 2 - dh); den->draw(pain, x + (width - w1) / 2, y + den->Ascent() + 2 - dh);
size = sizex; size(sizex);
if (objtype == LM_OT_FRAC) if (objtype == LM_OT_FRAC)
pain.line(x + 2, y - dh, x + width - 4, y - dh, LColor::mathline); pain.line(x + 2, y - dh, x + width - 4, y - dh, LColor::mathline);
idx = idxp; idx = idxp;
@ -134,14 +137,14 @@ MathFracInset::Metrics()
{ {
if (!dh) { if (!dh) {
int a, b; int a, b;
dh = mathed_char_height(LM_TC_CONST, size, 'I', a, b)/2; dh = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
} }
short idxp = idx; short idxp = idx;
short sizex = size; short sizex = size();
idx = 0; idx = 0;
if (size == LM_ST_DISPLAY) ++size; if (size() == LM_ST_DISPLAY) incSize();
MathParInset::Metrics(); MathParInset::Metrics();
size = sizex; size(sizex);
w0 = width; w0 = width;
int as = Height() + 2 + dh; int as = Height() + 2 + dh;
des0 = Descent() + 2 + dh; des0 = Descent() + 2 + dh;

View File

@ -54,7 +54,7 @@ void
MathFuncInset::draw(Painter & pain, int x, int y) MathFuncInset::draw(Painter & pain, int x, int y)
{ {
if (!name.empty() && name[0] > ' ') { if (!name.empty() && name[0] > ' ') {
LyXFont font = WhichFont(LM_TC_TEXTRM, size); LyXFont font = WhichFont(LM_TC_TEXTRM, size());
font.setLatex(LyXFont::ON); font.setLatex(LyXFont::ON);
x += (lyxfont::width('I', font) + 3) / 4; x += (lyxfont::width('I', font) + 3) / 4;
pain.text(x, y, name, font); pain.text(x, y, name, font);
@ -66,7 +66,7 @@ MathFuncInset::draw(Painter & pain, int x, int y)
void MathFuncInset::Metrics() void MathFuncInset::Metrics()
{ {
//ln = (name) ? strlen(name): 0; //ln = (name) ? strlen(name): 0;
LyXFont font = WhichFont(LM_TC_TEXTRM, size); LyXFont font = WhichFont(LM_TC_TEXTRM, size());
font.setLatex(LyXFont::ON); font.setLatex(LyXFont::ON);
if (name.empty()) { if (name.empty()) {
width = df_width; width = df_width;
@ -75,6 +75,6 @@ void MathFuncInset::Metrics()
} else { } else {
width = lyxfont::width(name, font) width = lyxfont::width(name, font)
+ lyxfont::width('I', font) / 2; + lyxfont::width('I', font) / 2;
mathed_string_height(LM_TC_TEXTRM, size, name, ascent, descent); mathed_string_height(LM_TC_TEXTRM, size(), name, ascent, descent);
} }
} }

View File

@ -2,7 +2,6 @@
/* Command-line: gperf -a -p -o -t -G -D keywords */ /* Command-line: gperf -a -p -o -t -G -D keywords */
#include <config.h> #include <config.h>
#include <cstdlib>
#include <cstring> #include <cstring>
#include "math_defs.h" #include "math_defs.h"
@ -42,7 +41,8 @@ math_hash (register char const *str, register int len)
static static
latexkeys wordlist[] = latexkeys wordlist[] =
{ {
{"",0,0}, {"",0,0}, {"",0,0}, {"",0,0}, {"",0,0}, {"",0,0}, {"",0,0}, {"",0,0}, {"",0,0}, {"",0,0}, {"",0,0}, {"",0,0},
{"",0,0}, {"",0,0}, {"",0,0}, {"",0,0},
{"setminus", LM_TK_SYM, LM_setminus}, {"setminus", LM_TK_SYM, LM_setminus},
{"ldots", LM_TK_DOTS, LM_ldots}, {"ldots", LM_TK_DOTS, LM_ldots},
{"limits", LM_TK_LIMIT, 1 }, {"limits", LM_TK_LIMIT, 1 },
@ -359,10 +359,10 @@ latexkeys *
in_word_set (register char const * str, register int len) in_word_set (register char const * str, register int len)
{ {
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) {
int key = math_hash (str, len); int const key = math_hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0) { if (key <= MAX_HASH_VALUE && key >= 0) {
int idx = lookup[key]; int const idx = lookup[key];
if (idx >= 0 && idx < MAX_HASH_VALUE) { if (idx >= 0 && idx < MAX_HASH_VALUE) {
char const * s = wordlist[idx].name; char const * s = wordlist[idx].name;
@ -372,7 +372,7 @@ in_word_set (register char const *str, register int len)
} else if (idx < 0 && idx >= -MAX_HASH_VALUE) { } else if (idx < 0 && idx >= -MAX_HASH_VALUE) {
return 0; return 0;
} else { } else {
int offset = key + idx + (idx > 0 ? -MAX_HASH_VALUE : MAX_HASH_VALUE); int const offset = key + idx + (idx > 0 ? -MAX_HASH_VALUE : MAX_HASH_VALUE);
latexkeys * base = &wordlist[-lookup[offset]]; latexkeys * base = &wordlist[-lookup[offset]];
latexkeys * ptr = base + -lookup[offset + 1]; latexkeys * ptr = base + -lookup[offset + 1];

View File

@ -39,21 +39,21 @@ MathedInset::MathedInset(MathedInset * inset)
if (inset) { if (inset) {
name = inset->GetName(); name = inset->GetName();
objtype = inset->GetType(); objtype = inset->GetType();
size = inset->GetStyle(); size_ = inset->GetStyle();
width = inset->Width(); width = inset->Width();
ascent = inset->Ascent(); ascent = inset->Ascent();
descent = inset->Descent(); descent = inset->Descent();
} else { } else {
objtype = LM_OT_UNDEF; objtype = LM_OT_UNDEF;
size = LM_ST_TEXT; size_ = LM_ST_TEXT;
width = ascent = descent = 0; width = ascent = descent = 0;
//name = 0; //name = 0;
} }
} }
MathedInset::MathedInset(string const & nm, short ot, short st): MathedInset::MathedInset(string const & nm, short ot, short st)
name(nm), objtype(ot), size(st) : name(nm), objtype(ot), size_(st)
{ {
width = ascent = descent = 0; width = ascent = descent = 0;
} }
@ -65,7 +65,8 @@ void MathedInset::drawStr(Painter & pain, short type, int siz,
{ {
string st; string st;
if (MathIsBinary(type)) if (MathIsBinary(type))
for (string::const_iterator it = s.begin(); it != s.end(); ++it) { for (string::const_iterator it = s.begin();
it != s.end(); ++it) {
st += ' '; st += ' ';
st += *it; st += *it;
st += ' '; st += ' ';
@ -77,3 +78,91 @@ void MathedInset::drawStr(Painter & pain, short type, int siz,
pain.text(x, y, st, mf); pain.text(x, y, st, mf);
} }
int MathedInset::Ascent() const
{
return ascent;
}
int MathedInset::Descent() const
{
return descent;
}
int MathedInset::Width() const
{
return width;
}
int MathedInset::Height() const
{
return ascent + descent;
}
bool MathedInset::GetLimits() const
{
return false;
}
void MathedInset::SetLimits(bool) {}
string const & MathedInset::GetName() const
{
return name;
}
short MathedInset::GetType() const
{
return objtype;
}
short MathedInset::GetStyle() const
{
return size_;
}
void MathedInset::SetType(short t)
{
objtype = t;
}
void MathedInset::SetStyle(short st)
{
size_ = st;
}
void MathedInset::SetName(string const & n)
{
name = n;
}
void MathedInset::defaultAscent(int da)
{
df_asc = da;
}
void MathedInset::defaultDescent(int dd)
{
df_des = dd;
}
void MathedInset::defaultWidth(int dw)
{
df_width = dw;
}

View File

@ -38,7 +38,9 @@ class Painter;
*/ */
class MathedInset { class MathedInset {
public: public:
/// A math inset has a name (usually its LaTeX name), type and font-size /** A math inset has a name (usually its LaTeX name),
type and font-size
*/
MathedInset(string const & nm, short ot, short st); MathedInset(string const & nm, short ot, short st);
/// ///
explicit explicit
@ -54,32 +56,42 @@ class MathedInset {
/// Compute the size of the object /// Compute the size of the object
virtual void Metrics() = 0; virtual void Metrics() = 0;
/// ///
virtual int Ascent() const { return ascent; } virtual int Ascent() const;
/// ///
virtual int Descent() const { return descent; } virtual int Descent() const;
/// ///
virtual int Width() const { return width; } virtual int Width() const;
/// ///
virtual int Height() const { return ascent + descent; } virtual int Height() const;
/// ///
virtual bool GetLimits() const { return false; } virtual bool GetLimits() const;
/// ///
virtual void SetLimits(bool) {} virtual void SetLimits(bool);
/// ///
string const & GetName() const { return name; } string const & GetName() const;
/// ///
short GetType() const { return objtype; } short GetType() const;
/// ///
short GetStyle() const { return size; } short GetStyle() const;
//Man: Avoid to use these functions if it's not strictly necessary //Man: Avoid to use these functions if it's not strictly necessary
/// ///
virtual void SetType(short t) { objtype = t; } virtual void SetType(short t);
/// ///
virtual void SetStyle(short st) { size = st; } // Metrics(); virtual void SetStyle(short st);
/// ///
virtual void SetName(string const & n) { name = n; } virtual void SetName(string const & n);
/// ///
static int workWidth; static int workWidth;
///
static void defaultAscent(int da);
///
static void defaultDescent(int dd);
///
static void defaultWidth(int dw);
///
short size() const {
return size_;
}
protected: protected:
/// ///
string name; string name;
@ -91,8 +103,6 @@ class MathedInset {
int ascent; int ascent;
/// ///
int descent; int descent;
///
short size;
/// Default metrics /// Default metrics
static int df_asc; static int df_asc;
/// ///
@ -102,8 +112,14 @@ class MathedInset {
/// In a near future maybe we use a better fonts renderer than X /// In a near future maybe we use a better fonts renderer than X
void drawStr(Painter &, short, int, int, int, string const &); void drawStr(Painter &, short, int, int, int, string const &);
/// ///
friend class MathedCursor; void size(short s) {
size_ = s;
}
void incSize() {
++size_;
}
private:
/// ///
friend void mathed_init_fonts(); short size_;
}; };
#endif #endif

View File

@ -45,29 +45,29 @@ ostream & operator<<(ostream & o, MathedTextCodes mtc)
MathMacro::MathMacro(MathMacroTemplate * t): MathMacro::MathMacro(MathMacroTemplate * t):
MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate(t) MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate_(t)
{ {
nargs = tmplate->getNoArgs(); nargs_ = tmplate_->getNoArgs();
tcode = tmplate->getTCode(); tcode_ = tmplate_->getTCode();
args_.resize(nargs); args_.resize(nargs_);
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].row = 0; args_[i].row = 0;
} }
idx = 0; idx_ = 0;
SetName(tmplate->GetName()); SetName(tmplate_->GetName());
} }
MathMacro::MathMacro(MathMacro * m): MathMacro::MathMacro(MathMacro * m):
MathParInset(LM_ST_TEXT, m->GetName(), LM_OT_MACRO) MathParInset(LM_ST_TEXT, m->GetName(), LM_OT_MACRO)
{ {
tmplate = m->tmplate; tmplate_ = m->tmplate_;
nargs = tmplate->getNoArgs(); nargs_ = tmplate_->getNoArgs();
tcode = tmplate->getTCode(); tcode_ = tmplate_->getTCode();
args_.resize(nargs); args_.resize(nargs_);
idx = 0; idx_ = 0;
SetName(tmplate->GetName()); SetName(tmplate_->GetName());
for (int i = 0; i < tmplate->nargs; ++i) { for (int i = 0; i < tmplate_->getNoArgs(); ++i) {
m->setArgumentIdx(i); m->setArgumentIdx(i);
MathedIter it(m->GetData()); MathedIter it(m->GetData());
args_[i].row = m->args_[i].row; args_[i].row = m->args_[i].row;
@ -78,10 +78,10 @@ MathMacro::MathMacro(MathMacro * m):
MathMacro::~MathMacro() MathMacro::~MathMacro()
{ {
for (idx = 0; idx < nargs; ++idx) { for (idx_ = 0; idx_ < nargs_; ++idx_) {
MathedIter it(args_[idx].array); MathedIter it(args_[idx_].array);
it.Clear(); it.Clear();
delete args_[idx].row; delete args_[idx_].row;
} }
} }
@ -94,34 +94,34 @@ MathedInset * MathMacro::Clone()
void MathMacro::Metrics() void MathMacro::Metrics()
{ {
if (nargs > 0) if (nargs_ > 0)
tmplate->update(this); tmplate_->update(this);
tmplate->SetStyle(size); tmplate_->SetStyle(size());
tmplate->Metrics(); tmplate_->Metrics();
width = tmplate->Width(); width = tmplate_->Width();
ascent = tmplate->Ascent(); ascent = tmplate_->Ascent();
descent = tmplate->Descent(); descent = tmplate_->Descent();
} }
void MathMacro::draw(Painter & pain, int x, int y) void MathMacro::draw(Painter & pain, int x, int y)
{ {
xo = x; xo(x);
yo = y; yo(y);
Metrics(); Metrics();
tmplate->update(this); tmplate_->update(this);
tmplate->SetStyle(size); tmplate_->SetStyle(size());
tmplate->draw(pain, x, y); tmplate_->draw(pain, x, y);
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
tmplate->GetMacroXY(i, args_[i].x, args_[i].y); tmplate_->GetMacroXY(i, args_[i].x, args_[i].y);
} }
} }
bool MathMacro::setArgumentIdx(int i) bool MathMacro::setArgumentIdx(int i)
{ {
if (i >= 0 && i < nargs) { if (i >= 0 && i < nargs_) {
idx = i; idx_ = i;
return true; return true;
} else } else
return false; return false;
@ -130,52 +130,52 @@ bool MathMacro::setArgumentIdx(int i)
int MathMacro::getArgumentIdx() const int MathMacro::getArgumentIdx() const
{ {
return idx; return idx_;
} }
int MathMacro::getMaxArgumentIdx() const int MathMacro::getMaxArgumentIdx() const
{ {
return nargs - 1; return nargs_ - 1;
} }
MathedArray * MathMacro::GetData() MathedArray * MathMacro::GetData()
{ {
return args_[idx].array; return args_[idx_].array;
} }
int MathMacro::GetColumns() const int MathMacro::GetColumns() const
{ {
return tmplate->getMacroPar(idx)->GetColumns(); return tmplate_->getMacroPar(idx_)->GetColumns();
} }
void MathMacro::GetXY(int & x, int & y) const void MathMacro::GetXY(int & x, int & y) const
{ {
x = args_[idx].x; x = args_[idx_].x;
y = args_[idx].y; y = args_[idx_].y;
} }
bool MathMacro::Permit(short f) const bool MathMacro::Permit(short f) const
{ {
return (nargs > 0) ? return (nargs_ > 0) ?
tmplate->getMacroPar(idx)->Permit(f) : MathParInset::Permit(f); tmplate_->getMacroPar(idx_)->Permit(f) : MathParInset::Permit(f);
} }
void MathMacro::SetFocus(int x, int y) void MathMacro::SetFocus(int x, int y)
{ {
tmplate->update(this); tmplate_->update(this);
tmplate->SetMacroFocus(idx, x, y); tmplate_->SetMacroFocus(idx_, x, y);
} }
void MathMacro::SetData(MathedArray * a) void MathMacro::SetData(MathedArray * a)
{ {
args_[idx].array = a; args_[idx_].array = a;
} }
@ -183,25 +183,25 @@ void MathMacro::SetData(MathedArray * a)
MathedRowSt * MathMacro::getRowSt() const MathedRowSt * MathMacro::getRowSt() const
{ {
return args_[idx].row; return args_[idx_].row;
} }
MathedTextCodes MathMacro::getTCode() const MathedTextCodes MathMacro::getTCode() const
{ {
return tcode; return tcode_;
} }
void MathMacro::Write(ostream & os, bool fragile) void MathMacro::Write(ostream & os, bool fragile)
{ {
if (tmplate->flags & MMF_Exp) { if (tmplate_->flags() & MMF_Exp) {
lyxerr[Debug::MATHED] << "Expand " << tmplate->flags lyxerr[Debug::MATHED] << "Expand " << tmplate_->flags()
<< ' ' << MMF_Exp << endl; << ' ' << MMF_Exp << endl;
tmplate->update(this); tmplate_->update(this);
tmplate->Write(os, fragile); tmplate_->Write(os, fragile);
} else { } else {
if (tmplate->flags & MMF_Env) { if (tmplate_->flags() & MMF_Env) {
os << "\\begin{" os << "\\begin{"
<< name << name
<< "} "; << "} ";
@ -214,21 +214,21 @@ void MathMacro::Write(ostream & os, bool fragile)
// file += ']'; // file += ']';
// } // }
if (!(tmplate->flags & MMF_Env) && nargs > 0) if (!(tmplate_->flags() & MMF_Env) && nargs_ > 0)
os << '{'; os << '{';
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
array = args_[i].array; array = args_[i].array;
MathParInset::Write(os, fragile); MathParInset::Write(os, fragile);
if (i < nargs - 1) if (i < nargs_ - 1)
os << "}{"; os << "}{";
} }
if (tmplate->flags & MMF_Env) { if (tmplate_->flags() & MMF_Env) {
os << "\\end{" os << "\\end{"
<< name << name
<< '}'; << '}';
} else { } else {
if (nargs > 0) if (nargs_ > 0)
os << '}'; os << '}';
else else
os << ' '; os << ' ';

View File

@ -71,7 +71,7 @@ public:
bool Permit(short) const; bool Permit(short) const;
private: private:
/// ///
MathMacroTemplate * tmplate; MathMacroTemplate * tmplate_;
/// ///
struct MacroArgumentBase { struct MacroArgumentBase {
/// Position of the macro /// Position of the macro
@ -83,16 +83,16 @@ private:
/// ///
MathedArray * array; MathedArray * array;
/// ///
MacroArgumentBase() { x = y = 0; array = 0; row = 0; } MacroArgumentBase()
: x(0), y(0), row(0), array(0)
{}
}; };
std::vector<MacroArgumentBase> args_; std::vector<MacroArgumentBase> args_;
/// ///
int idx; int idx_;
/// ///
int nargs; int nargs_;
/// ///
MathedTextCodes tcode; MathedTextCodes tcode_;
///
friend class MathMacroTemplate;
}; };
#endif #endif

View File

@ -53,11 +53,10 @@ void MathMacroArgument::draw(Painter & pain, int x, int baseline)
{ {
if (expnd_mode_) { if (expnd_mode_) {
MathParInset::draw(pain, x, baseline); MathParInset::draw(pain, x, baseline);
} } else {
else {
std::ostringstream ost; std::ostringstream ost;
ost << '#' << number_; ost << '#' << number_;
drawStr(pain, LM_TC_TEX, size, x, baseline, ost.str().c_str()); drawStr(pain, LM_TC_TEX, size(), x, baseline, ost.str().c_str());
} }
} }
@ -68,8 +67,8 @@ void MathMacroArgument::Metrics()
} else { } else {
std::ostringstream ost; std::ostringstream ost;
ost << '#' << number_; ost << '#' << number_;
width = mathed_string_width(LM_TC_TEX, size, ost.str().c_str()); width = mathed_string_width(LM_TC_TEX, size(), ost.str().c_str());
mathed_string_height(LM_TC_TEX, size, ost.str().c_str(), mathed_string_height(LM_TC_TEX, size(), ost.str().c_str(),
ascent, descent); ascent, descent);
} }
} }

View File

@ -10,34 +10,34 @@ using std::ostream;
void MathMacroTemplate::setTCode(MathedTextCodes t) void MathMacroTemplate::setTCode(MathedTextCodes t)
{ {
tcode = t; tcode_ = t;
} }
MathedTextCodes MathMacroTemplate::getTCode() const MathedTextCodes MathMacroTemplate::getTCode() const
{ {
return tcode; return tcode_;
} }
int MathMacroTemplate::getNoArgs() const int MathMacroTemplate::getNoArgs() const
{ {
return nargs; return nargs_;
} }
MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg): MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO), MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
flags(flg), nargs(na) flags_(flg), nargs_(na)
{ {
if (nargs > 0) { if (nargs_ > 0) {
tcode = LM_TC_ACTIVE_INSET; tcode_ = LM_TC_ACTIVE_INSET;
args_.resize(nargs); args_.resize(nargs_);
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setNumber(i + 1); args_[i].setNumber(i + 1);
} }
} else { } else {
tcode = LM_TC_INSET; tcode_ = LM_TC_INSET;
// Here is nargs != args_.size() // Here is nargs != args_.size()
//args = 0; //args = 0;
} }
@ -47,7 +47,7 @@ MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
MathMacroTemplate::~MathMacroTemplate() MathMacroTemplate::~MathMacroTemplate()
{ {
// prevent to delete already deleted objects // prevent to delete already deleted objects
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].SetData(0); args_[i].SetData(0);
} }
} }
@ -56,14 +56,14 @@ MathMacroTemplate::~MathMacroTemplate()
void MathMacroTemplate::setEditMode(bool ed) void MathMacroTemplate::setEditMode(bool ed)
{ {
if (ed) { if (ed) {
flags |= MMF_Edit; flags_ |= MMF_Edit;
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(false); args_[i].setExpand(false);
} }
} }
else { else {
flags &= ~MMF_Edit; flags_ &= ~MMF_Edit;
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(true); args_[i].setExpand(true);
} }
} }
@ -72,23 +72,27 @@ void MathMacroTemplate::setEditMode(bool ed)
void MathMacroTemplate::draw(Painter & pain, int x, int y) void MathMacroTemplate::draw(Painter & pain, int x, int y)
{ {
int x2, y2; int x2;
bool expnd = (nargs > 0) ? args_[0].getExpand(): false; int y2;
if (flags & MMF_Edit) { bool expnd = (nargs_ > 0) ? args_[0].getExpand(): false;
for (int i = 0; i < nargs; ++i) { if (flags_ & MMF_Edit) {
for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(false); args_[i].setExpand(false);
} }
x2 = x; y2 = y; x2 = x;
y2 = y;
} else { } else {
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(true); args_[i].setExpand(true);
} }
x2 = xo; y2 = yo; x2 = xo();
y2 = yo();
} }
MathParInset::draw(pain, x, y); MathParInset::draw(pain, x, y);
xo = x2; yo = y2; xo(x2);
yo(y2);
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(expnd); args_[i].setExpand(expnd);
} }
} }
@ -96,20 +100,20 @@ void MathMacroTemplate::draw(Painter & pain, int x, int y)
void MathMacroTemplate::Metrics() void MathMacroTemplate::Metrics()
{ {
bool expnd = (nargs > 0) ? args_[0].getExpand(): false; bool expnd = (nargs_ > 0) ? args_[0].getExpand(): false;
if (flags & MMF_Edit) { if (flags_ & MMF_Edit) {
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(false); args_[i].setExpand(false);
} }
} else { } else {
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(true); args_[i].setExpand(true);
} }
} }
MathParInset::Metrics(); MathParInset::Metrics();
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(expnd); args_[i].setExpand(expnd);
} }
} }
@ -118,7 +122,7 @@ void MathMacroTemplate::Metrics()
void MathMacroTemplate::update(MathMacro * macro) void MathMacroTemplate::update(MathMacro * macro)
{ {
int idx = (macro) ? macro->getArgumentIdx() : 0; int idx = (macro) ? macro->getArgumentIdx() : 0;
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
if (macro) { if (macro) {
macro->setArgumentIdx(i); macro->setArgumentIdx(i);
args_[i].SetData(macro->GetData()); args_[i].SetData(macro->GetData());
@ -135,12 +139,12 @@ void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
{ {
os << "\n\\newcommand{\\" << name << "}"; os << "\n\\newcommand{\\" << name << "}";
if (nargs > 0 ) if (nargs_ > 0 )
os << "[" << nargs << "]"; os << "[" << nargs_ << "]";
os << "{"; os << "{";
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
args_[i].setExpand(false); args_[i].setExpand(false);
} }
Write(os, fragile); Write(os, fragile);
@ -162,7 +166,7 @@ void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
MathParInset * MathMacroTemplate::getMacroPar(int i) const MathParInset * MathMacroTemplate::getMacroPar(int i) const
{ {
if (i >= 0 && i < nargs) if (i >= 0 && i < nargs_)
return const_cast<MathParInset *> return const_cast<MathParInset *>
(static_cast<MathParInset const *>(&args_[i])); (static_cast<MathParInset const *>(&args_[i]));
else else
@ -172,7 +176,7 @@ MathParInset * MathMacroTemplate::getMacroPar(int i) const
void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y) void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
{ {
for (int i = 0; i < nargs; ++i) { for (int i = 0; i < nargs_; ++i) {
if (args_[i].Inside(x, y)) { if (args_[i].Inside(x, y)) {
idx = i; idx = i;
break; break;

View File

@ -42,16 +42,18 @@ class MathMacroTemplate: public MathParInset {
/// Replace the appropriate arguments with a specific macro's data /// Replace the appropriate arguments with a specific macro's data
void update(MathMacro * m = 0); void update(MathMacro * m = 0);
///
short flags() const {
return flags_;
}
private: private:
/// ///
short flags; short flags_;
/// ///
MathedTextCodes tcode; MathedTextCodes tcode_;
/// ///
std::vector<MathMacroArgument> args_; std::vector<MathMacroArgument> args_;
/// ///
int nargs; int nargs_;
///
friend class MathMacro;
}; };
#endif #endif

View File

@ -65,6 +65,7 @@ enum SomeMathValues {
MM_OK MM_OK
}; };
/// ///
/// Class to manage bitmap menu bars /// Class to manage bitmap menu bars
class BitmapMenu { class BitmapMenu {
@ -83,7 +84,13 @@ class BitmapMenu {
/// Border width /// Border width
int ww; int ww;
/// ///
int x, y, w, h; int x;
///
int y;
///
int w;
///
int h;
/// ///
FL_FORM * form; FL_FORM * form;
/// ///
@ -114,24 +121,29 @@ class BitmapMenu {
int GetIndex(FL_OBJECT * ob); int GetIndex(FL_OBJECT * ob);
}; };
/// This is just a wrapper around peek_event() /// This is just a wrapper around peek_event()
extern "C" int C_peek_event(FL_FORM * form, void * ptr); extern "C" int C_peek_event(FL_FORM * form, void * ptr);
inline inline
void BitmapMenu::Prev() { void BitmapMenu::Prev()
{
Hide(); Hide();
if (prev) if (prev)
prev->Show(); prev->Show();
} }
inline inline
void BitmapMenu::Next() { void BitmapMenu::Next()
{
Hide(); Hide();
if (next) if (next)
next->Show(); next->Show();
} }
#include "math_forms.h" #include "math_forms.h"
/// ///

View File

@ -85,10 +85,12 @@ MathParInset::draw(Painter & pain, int x, int y)
{ {
byte cxp = 0; byte cxp = 0;
int xp = 0; int xp = 0;
int asc = df_asc, des = 0; int asc = df_asc;
int des = 0;
bool limits = false; bool limits = false;
xo = x; yo = y; xo_ = x;
yo_ = y;
if (!array || array->empty()) { if (!array || array->empty()) {
if (array) { if (array) {
MathedXIter data(this); MathedXIter data(this);
@ -104,8 +106,8 @@ MathParInset::draw(Painter & pain, int x, int y)
byte cx = data.GetChar(); byte cx = data.GetChar();
if (cx >= ' ') { if (cx >= ' ') {
string s = data.GetString(); string s = data.GetString();
drawStr(pain, data.FCode(), size, x, y, s); drawStr(pain, data.FCode(), size(), x, y, s);
mathed_char_height(LM_TC_CONST, size, 'y', asc, des); mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
limits = false; limits = false;
} }
else { else {
@ -195,15 +197,16 @@ MathParInset::Metrics()
cx = data.GetChar(); cx = data.GetChar();
if (cx >= ' ') { if (cx >= ' ') {
string s = data.GetString(); string s = data.GetString();
mathed_string_height(data.FCode(), size, s, asc, des); mathed_string_height(data.FCode(),
size(), s, asc, des);
if (asc > ascent) ascent = asc; if (asc > ascent) ascent = asc;
if (des > descent) descent = des; if (des > descent) descent = des;
limits = false; limits = false;
mathed_char_height(LM_TC_CONST, size, 'y', asc, des); mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
} else } else
if (MathIsInset(cx)) { if (MathIsInset(cx)) {
MathedInset * p = data.GetInset(); MathedInset * p = data.GetInset();
p->SetStyle(size); p->SetStyle(size());
p->Metrics(); p->Metrics();
if (cx == LM_TC_UP) { if (cx == LM_TC_UP) {
asc += (limits) ? p->Height() + 4: p->Ascent() + asc += (limits) ? p->Height() + 4: p->Ascent() +
@ -290,7 +293,7 @@ void MathParInset::Write(ostream & os, bool fragile)
data.Reset(); data.Reset();
if (!Permit(LMPF_FIXED_SIZE)) { if (!Permit(LMPF_FIXED_SIZE)) {
l = lm_get_key_by_id(size, LM_TK_STY); l = lm_get_key_by_id(size(), LM_TK_STY);
if (l) { if (l) {
os << '\\' << l->name << ' '; os << '\\' << l->name << ' ';
} }
@ -397,22 +400,22 @@ void MathParInset::Write(ostream & os, bool fragile)
bool MathParInset::Inside(int x, int y) bool MathParInset::Inside(int x, int y)
{ {
return (x >= xo && x <= xo + width return (x >= xo() && x <= xo() + width
&& y <= yo + descent && y >= yo - ascent); && y <= yo() + descent && y >= yo() - ascent);
} }
void MathParInset::GetXY(int & x, int & y) const void MathParInset::GetXY(int & x, int & y) const
{ {
x = xo; x = xo();
y = yo; y = yo();
} }
void MathParInset::UserSetSize(short sz) void MathParInset::UserSetSize(short sz)
{ {
if (sz >= 0) { if (sz >= 0) {
size = sz; size(sz);
flag = flag & ~LMPF_FIXED_SIZE; flag = flag & ~LMPF_FIXED_SIZE;
} }
} }
@ -431,12 +434,6 @@ void MathParInset::SetStyle(short sz)
} }
void MathParInset::setFlag(MathedParFlag f)
{
flag |= f;
}
bool MathParInset::Permit(short f) const bool MathParInset::Permit(short f) const
{ {
return bool(f & flag); return bool(f & flag);
@ -451,6 +448,6 @@ MathedArray * MathParInset::GetData()
void MathParInset::setXY(int x, int y) void MathParInset::setXY(int x, int y)
{ {
xo = x; xo_ = x;
yo = y; yo_ = y;
} }

View File

@ -68,29 +68,31 @@ class MathParInset: public MathedInset {
virtual void setRowSt(MathedRowSt *) {} virtual void setRowSt(MathedRowSt *) {}
/// ///
virtual bool Permit(short f) const; virtual bool Permit(short f) const;
///
int xo() const {
return xo_;
}
///
int yo() const {
return yo_;
}
protected: protected:
/// Paragraph data is stored here /// Paragraph data is stored here
MathedArray * array; MathedArray * array;
/// Cursor start position
int xo;
///
int yo;
/// ///
short flag; short flag;
///
void xo(int tx) {
xo_ = tx;
}
///
void yo(int ty) {
yo_ = ty;
}
private: private:
/// Cursor start position
int xo_;
/// ///
virtual void setFlag(MathedParFlag f); int yo_;
///
friend class InsetFormula;
///
friend class MathedXIter;
///
friend class MathedCursor;
///
friend MathedArray * mathed_parse(unsigned flags = 0,
MathedArray * a = 0,
MathParInset ** p = 0);
}; };
#endif #endif

View File

@ -390,8 +390,8 @@ MathedInset * doAccent(MathedInset * p)
} }
MathedArray * mathed_parse(unsigned flags, MathedArray * array, MathedArray * mathed_parse(unsigned flags = 0, MathedArray * array = 0,
MathParInset ** mtx) MathParInset ** mtx = 0)
{ {
int t = yylex(); int t = yylex();
int tprev = 0; int tprev = 0;

View File

@ -128,13 +128,13 @@ void MathRootInset::SetStyle(short st)
{ {
MathSqrtInset::SetStyle(st); MathSqrtInset::SetStyle(st);
uroot->SetStyle((size<LM_ST_SCRIPTSCRIPT) ? size+1: size); uroot->SetStyle((size() < LM_ST_SCRIPTSCRIPT) ? size() + 1 : size());
} }
void MathRootInset::SetFocus(int x, int) void MathRootInset::SetFocus(int x, int)
{ {
idx = (x > xo + wroot) ? 1: 0; idx = (x > xo() + wroot) ? 1: 0;
} }

View File

@ -24,10 +24,10 @@ MathedInset * MathSqrtInset::Clone()
bool MathSqrtInset::Inside(int x, int y) bool MathSqrtInset::Inside(int x, int y)
{ {
return x >= xo - hmax return x >= xo() - hmax
&& x <= xo + width - hmax && x <= xo() + width - hmax
&& y <= yo + descent && y <= yo() + descent
&& y >= yo - ascent; && y >= yo() - ascent;
} }
@ -55,7 +55,7 @@ MathSqrtInset::Metrics()
ascent += 4; ascent += 4;
descent += 2; descent += 2;
int a, b; int a, b;
hmax = mathed_char_height(LM_TC_VAR, size, 'I', a, b); hmax = mathed_char_height(LM_TC_VAR, size(), 'I', a, b);
if (hmax < 10) hmax = 10; if (hmax < 10) hmax = 10;
wbody = width + 4; wbody = width + 4;
width += hmax + 4; width += hmax + 4;

View File

@ -103,7 +103,6 @@ protected:
/// ///
MathedRowSt * crow; MathedRowSt * crow;
private:
/// ///
friend class MathedCursor; friend class MathedCursor;
}; };

View File

@ -4,29 +4,27 @@
#include "matriz.h" #include "matriz.h"
inline static inline
int odd(int x) { return ((x) & 1); } int odd(int x) { return ((x) & 1); }
typedef float matriz_data[2][2];
const matriz_data MATIDEN= { {1, 0}, {0, 1}};
#define mateq(m1, m2) memcpy(m1, m2, sizeof(matriz_data)) #define mateq(m1, m2) memcpy(m1, m2, sizeof(matriz_data))
Matriz::matriz_data const Matriz::MATIDEN = { {1, 0}, {0, 1}};
Matriz::Matriz() Matriz::Matriz()
{ {
mateq(m, MATIDEN); mateq(m_, MATIDEN);
} }
void Matriz::rota(int code) void Matriz::rota(int code)
{ {
float cs, sn;
matriz_data r; matriz_data r;
mateq(r, MATIDEN); mateq(r, MATIDEN);
cs = (odd(code)) ? 0: 1 - code; float const cs = (odd(code)) ? 0 : (1 - code);
sn = (odd(code)) ? 2 - code: 0; float const sn = (odd(code)) ? (2 - code) : 0;
r[0][0] = cs; r[0][1] = sn; r[0][0] = cs; r[0][1] = sn;
r[1][0] = -r[0][1]; r[1][1] = r[0][0]; r[1][0] = -r[0][1]; r[1][1] = r[0][0];
matmat(r); matmat(r);
@ -46,15 +44,15 @@ void Matriz::matmat(matriz_data & a)
{ {
matriz_data c; matriz_data c;
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
c[0][i] = a[0][0] * m[0][i] + a[0][1] * m[1][i]; c[0][i] = a[0][0] * m_[0][i] + a[0][1] * m_[1][i];
c[1][i] = a[1][0] * m[0][i] + a[1][1] * m[1][i]; c[1][i] = a[1][0] * m_[0][i] + a[1][1] * m_[1][i];
} }
mateq(m, c); mateq(m_, c);
} }
void Matriz::transf(float xp, float yp, float & x, float & y) void Matriz::transf(float xp, float yp, float & x, float & y)
{ {
x = m[0][0] * xp + m[0][1] * yp; x = m_[0][0] * xp + m_[0][1] * yp;
y = m[1][0] * xp + m[1][1] * yp; y = m_[1][0] * xp + m_[1][1] * yp;
} }

View File

@ -3,17 +3,26 @@
#ifndef MATH_MATRIZ_H #ifndef MATH_MATRIZ_H
#define MATH_MATRIZ_H #define MATH_MATRIZ_H
typedef float matriz_data[2][2]; ///
class Matriz { class Matriz {
public: public:
///
typedef float matriz_data[2][2];
///
Matriz(); Matriz();
///
void rota(int); void rota(int);
///
void escala(float, float); void escala(float, float);
///
void transf(float, float, float &, float &); void transf(float, float, float &, float &);
protected: private:
matriz_data m; ///
matriz_data m_;
///
void matmat(matriz_data & a); void matmat(matriz_data & a);
///
static matriz_data const MATIDEN;
}; };
#endif #endif