par_->draw(pain, x, y);
xx += par_->width();
+ xo_ = x;
+ yo_ = y;
setCursorVisible(false);
}
if (!mathcursor)
return;
+ bool selected = mathcursor->selection();
+
MathArray ar;
- if (mathcursor->selection())
+ if (selected) {
mathcursor->selGet(ar);
- else
+ lyxerr << "use selection: " << ar << "\n";
+ } else {
ar = mathcursor->cursor().cell();
+ lyxerr << "use whole cell: " << ar << "\n";
+ }
+
// parse args
string lang;
string code = os.str().c_str();
// run external sript
- string script = "lyx2" + arg + " '" + code + "' " + outfile;
+ string script = "lyx2" + lang + " '" + code + "' " + outfile;
lyxerr << "calling: " << script << endl;
Systemcalls cmd(Systemcalls::System, script, 0);
- // append a '='
- //ar.push_back(MathAtom(new MathCharInset('=')));
-
// append result
MathArray br;
+ if (selected)
+ br.push_back(MathAtom(new MathCharInset('=', LM_TC_VAR)));
ifstream is(outfile.c_str());
mathed_parse_cell(br, is);
mathcursor->insert(br);
InsetFormulaBase::InsetFormulaBase()
- : view_(0), font_()
+ : view_(0), font_(), xo_(0), yo_(0)
{
// This is needed as long the math parser is not re-entrant
MathMacroTable::builtinMacros();
void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
{
mathcursor->getPos(x, y);
- x -= par()->xo();
- y -= par()->yo();
- y -= 3;
+ x += xo_;
+ y += yo_ - 3;
+ //lyxerr << "getCursorPos: " << x << " " << y << "\n";
}
int x;
int y;
mathcursor->getPos(x, y);
- //x -= par()->xo();
- y -= par()->yo();
y -= 3;
+ y -= yo_;
int asc = 0;
int des = 0;
MathMetricsInfo mi(bv, font_, LM_ST_TEXT);
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
bv->showLockedInsetCursor(x, y, asc, des);
+ //lyxerr << "toggleInsetCursor: " << x << " " << y << "\n";
}
toggleCursorVisible();
int x;
int y;
mathcursor->getPos(x, y);
- x -= par()->xo();
- y -= par()->yo();
int asc = 0;
int des = 0;
MathMetricsInfo mi(bv, font_, LM_ST_TEXT);
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
bv->fitLockedInsetCursor(x, y, asc, des);
+ //lyxerr << "showInsetCursor: " << x << " " << y << "\n";
}
toggleInsetCursor(bv);
}
{
if (mathcursor) {
hideInsetCursor(bv);
- x += par()->xo();
- y += par()->yo();
- mathcursor->setPos(x, y);
+ mathcursor->setPos(x + xo_, y + yo_);
+ //lyxerr << "insetButtonRelease: " << x + xo_ << " " << y + yo_ << "\n";
showInsetCursor(bv);
if (sel_flag) {
sel_flag = false;
if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
sel_flag = true;
hideInsetCursor(bv);
- mathcursor->setPos(sel_x + par()->xo(), sel_y + par()->yo());
+ mathcursor->setPos(sel_x, sel_y);
mathcursor->selStart();
showInsetCursor(bv);
mathcursor->getPos(sel_x, sel_y);
} else if (sel_flag) {
hideInsetCursor(bv);
- x += par()->xo();
- y += par()->yo();
mathcursor->setPos(x, y);
showInsetCursor(bv);
mathcursor->getPos(x, y);
// break;
case LFUN_SETXY: {
lyxerr << "LFUN_SETXY broken!\n";
- int x;
- int y;
- int x1;
- int y1;
+ int x = 0;
+ int y = 0;
istringstream is(arg.c_str());
is >> x >> y;
- par()->getXY(x1, y1);
- mathcursor->setPos(x1 + x, y1 + y);
+ mathcursor->setPos(x, y);
updateLocal(bv, false);
break;
}
}
+int InsetFormulaBase::upperY() const
+{
+ return yo_ - ascent(view_, font_);
+}
+
+
+int InsetFormulaBase::lowerY() const
+{
+ return yo_ + descent(view_, font_);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+
+
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
if (bv->available()) {
}
}
+
virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
///
virtual MathInsetTypes getType() const = 0;
+ /// upper y coordinate
+ virtual int upperY() const;
+ /// lower y coordinate
+ virtual int lowerY() const;
public:
///
virtual void metrics(BufferView * bv = 0, LyXFont const & font = LyXFont()) const;
///
virtual void updateLocal(BufferView * bv, bool mark_dirty);
+ ///
+ int xo() const { return xo_; }
+ ///
+ int yo() const { return yo_; }
private:
/// unimplemented
void operator=(const InsetFormulaBase &);
mutable BufferView * view_;
///
mutable LyXFont font_;
+protected:
+ ///
+ mutable int xo_;
+ ///
+ mutable int yo_;
};
// We don't really mess want around with mathed stuff outside mathed.
{
string name = mathed_parse_macro(lex);
setInsetName(name);
- lyxerr << "metrics disabled";
+ //lyxerr << "metrics disabled";
metrics();
}
void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
- int baseline, float & x, bool /*cleared*/) const
+ int y, float & x, bool /*cleared*/) const
{
Painter & pain = bv->painter();
LyXFont font(f);
// label
font.setColor(LColor::math);
- int const y = baseline - ascent(bv, font) + 1;
+ int const a = y - ascent(bv, font) + 1;
int const w = width(bv, font) - 2;
int const h = ascent(bv, font) + descent(bv, font) - 2;
// LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
- pain.fillRectangle(int(x), y , w, h, LColor::mathmacrobg);
- pain.rectangle(int(x), y, w, h, LColor::mathframe);
+ pain.fillRectangle(int(x), a , w, h, LColor::mathmacrobg);
+ pain.rectangle(int(x), a, w, h, LColor::mathframe);
if (mathcursor && mathcursor->formula() == this)
mathcursor->drawSelection(pain);
- pain.text(int(x + 2), baseline, prefix(), font);
+ pain.text(int(x + 2), y, prefix(), font);
x += width(bv, font);
// formula
- float t = par()->width() + 5;
- x -= t;
- par()->draw(pain, int(x), baseline);
- x += t;
+ xo_ = int(x) - par()->width() - 5;
+ yo_ = y;
+ par()->draw(pain, xo_, yo_);
}
void MathBinomInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
void MathCharInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
//lyxerr << "drawing '" << char_ << "' code: " << code_ << endl;
drawChar(pain, code_, mi_, x, y, char_);
}
void MathCursor::selGet(MathArray & ar)
{
seldump("selGet");
- if (selection_)
+ if (!selection_)
return;
theSelection.grab(*this);
int y0;
getPos(x0, y0);
std::vector<MathCursorPos> save = Cursor_;
- MathAtom const & out = formula()->par();
y0 -= xarray().ascent();
- for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
+ for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
setPos(x0, y);
if (save != Cursor_ && xarray().yo() < y0)
return true;
int y0;
getPos(x0, y0);
std::vector<MathCursorPos> save = Cursor_;
- MathAtom const & out = formula()->par();
y0 += xarray().descent();
- for (int y = y0 + 4; y < out->yo() + out->descent(); y += 4) {
+ for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
setPos(x0, y);
if (save != Cursor_ && xarray().yo() > y0)
return true;
void MathDecorationInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(x);
xcell(0).draw(pain, x, y);
if (wide())
mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
void MathDelimInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
-
int const w = dw();
int const b = y - ascent_;
xcell(0).draw(pain, x + w + 2, y);
void MathFracInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
void MathFuncInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
drawStr(pain, LM_TC_TEX, mi_, x, y, name_);
}
void MathFuncLimInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
drawStr(pain, LM_TC_TEXTRM, mi_, x, y, sym_->name);
}
void MathGridInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
for (idx_type idx = 0; idx < nargs(); ++idx)
xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx));
}
MathInset::MathInset()
- : xo_(0), yo_(0)
{}
}
-int MathInset::xo() const
-{
- return xo_;
-}
-
-
-int MathInset::yo() const
-{
- return yo_;
-}
-
-
-void MathInset::xo(int x) const
-{
- xo_ = x;
-}
-
-
-void MathInset::yo(int y) const
-{
- yo_ = y;
-}
-
-
MathInset::size_type MathInset::nargs() const
{
return 0;
{}
-void MathInset::getXY(int & x, int & y) const
-{
- x = xo();
- y = yo();
-}
-
-
void MathInset::writeNormal(std::ostream & os) const
{
os << "[unknown ";
bool MathInset::covers(int x, int y) const
{
- //lyxerr << "cover? p: " << this << " x: " << x << " y: " << y
- // << " xo_: " << xo_ << " yo_: " << yo_ << endl;
- return
- x >= xo_ &&
- x <= xo_ + width() &&
- y >= yo_ - ascent() &&
- y <= yo_ + descent();
+ lyxerr << "MathInset::covers() called directly!\n";
+ return false;
}
/// the virtual base destructor
virtual ~MathInset();
- /// draw the object, sets xo_ and yo_ cached values
+ /// draw the object
virtual void draw(Painter &, int x, int y) const;
/// write LaTeX and Lyx code
virtual void write(MathWriteInfo & os) const;
///
virtual MathXArray const & xcell(idx_type) const;
- ///
- virtual int xo() const;
- ///
- virtual int yo() const;
- ///
- virtual void xo(int tx) const;
- ///
- virtual void yo(int ty) const;
- ///
-
///
virtual col_type ncols() const { return 1; }
///
///
virtual void delCol(col_type) {}
- ///
- virtual void getXY(int & x, int & y) const;
///
virtual bool covers(int x, int y) const;
virtual void validate(LaTeXFeatures & features) const;
///
virtual void handleFont(MathTextCodes) {}
-
-private:
- /// the following are used for positioning the cursor with the mouse
- /// cached cursor start position in pixels from the document left
- mutable int xo_;
- /// cached cursor start position in pixels from the document top
- mutable int yo_;
};
std::ostream & operator<<(std::ostream &, MathInset const &);
void MathMacro::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
-
metrics(mi_);
if (defining()) {
void MathMacroTemplate::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
xcell(0).draw(pain, x + 2, y + 1);
pain.rectangle(x, y - ascent(), width(), height(), LColor::blue);
}
void MathMatrixInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
-
MathGridInset::draw(pain, x, y);
if (numberedType()) {
void MathNestInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
for (idx_type i = 0; i < nargs(); ++i)
xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
}
for (idx_type i = 0; i < nargs(); ++i)
cell(i).validate(features);
}
+
+
+bool MathNestInset::covers(int x, int y) const
+{
+ if (!nargs())
+ return false;
+ int x0 = xcell(0).xo();
+ int y0 = xcell(0).yo() - xcell(0).ascent();
+ int x1 = xcell(0).xo() + xcell(0).width();
+ int y1 = xcell(0).yo() + xcell(0).descent();
+ for (idx_type i = 1; i < nargs(); ++i) {
+ x0 = min(x0, xcell(i).xo());
+ y0 = min(y0, xcell(i).yo() - xcell(i).ascent());
+ x1 = max(x1, xcell(i).xo() + xcell(i).width());
+ y1 = max(y1, xcell(i).yo() + xcell(i).descent());
+ }
+ return x >= x0 && x <= x1 && y >= y0 && y <= y1;
+}
///
void validate(LaTeXFeatures & features) const;
+ ///
+ bool covers(int x, int y) const;
protected:
///
void MathNotInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
-
if (math_font_available(LM_TC_CMSY))
drawChar(pain, LM_TC_CMSY, mi_, x, y, 54);
else
void MathRootInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
int const w = xcell(0).width();
xcell(0).draw(pain, x, y - 5 - xcell(0).descent()); // the "exponent"
xcell(1).draw(pain, x + w + 8, y); // the "base"
void MathScriptInset::draw(MathInset const * nuc, Painter & pain,
int x, int y) const
{
- xo(x);
- yo(y);
-
if (nuc)
nuc->draw(pain, x + dxx(nuc), y);
else
void MathSizeInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
xcell(0).draw(pain, x, y);
}
void MathSpecialCharInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
drawChar(pain, LM_TC_CONST, mi_, x, y, char_);
}
void MathSqrtInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
xcell(0).draw(pain, x + 10, y);
int const a = ascent_;
int const d = descent_;
void MathStackrelInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).height() - 4);
xcell(1).draw(pain, m - xcell(1).width() / 2, y);
void MathSymbolInset::draw(Painter & pain, int x, int y) const
{
- xo(x);
- yo(y);
MathTextCodes Code = code();
if (sym_->latex_font_id > 0 && math_font_available(Code))
drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);