formula.h \
formulamacro.C \
formulamacro.h \
+ math_amsarrayinset.C \
+ math_amsarrayinset.h \
math_arrayinset.C \
math_arrayinset.h \
math_atom.C \
case LFUN_RIGHT:
result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
+ //lyxerr << "calling scroll 20\n";
+ //scroll(bv, 20);
updateLocal(bv, false);
// write something to the minibuffer
//bv->owner()->message(mathcursor->info());
class BufferView;
class MathAtom;
-///
+/// An abstract base class for all math related LyX insets
class InsetFormulaBase : public UpdatableInset {
public:
///
--- /dev/null
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_amsarrayinset.h"
+#include "math_mathmlstream.h"
+#include "math_support.h"
+#include "math_streamstr.h"
+#include "math_support.h"
+#include "Lsstream.h"
+
+
+MathAMSArrayInset::MathAMSArrayInset(string const & name, int m, int n)
+ : MathGridInset(m, n), name_(name)
+{}
+
+
+MathAMSArrayInset::MathAMSArrayInset(string const & name)
+ : MathGridInset(1, 1), name_(name)
+{}
+
+
+MathInset * MathAMSArrayInset::clone() const
+{
+ return new MathAMSArrayInset(*this);
+}
+
+
+char const * MathAMSArrayInset::name_left() const
+{
+ if (name_ == "bmatrix")
+ return "[";
+ return "(";
+}
+
+
+char const * MathAMSArrayInset::name_right() const
+{
+ if (name_ == "bmatrix")
+ return "]";
+ return ")";
+}
+
+
+void MathAMSArrayInset::metrics(MathMetricsInfo const & st) const
+{
+ MathMetricsInfo mi = st;
+ if (mi.style == LM_ST_DISPLAY)
+ mi.style = LM_ST_TEXT;
+ MathGridInset::metrics(mi);
+ width_ += 12;
+}
+
+
+void MathAMSArrayInset::draw(Painter & pain, int x, int y) const
+{
+ MathGridInset::draw(pain, x + 6, y);
+ int yy = y - ascent_;
+ mathed_draw_deco(pain, x + 1, yy, 5, height(), name_left());
+ mathed_draw_deco(pain, x + width_ - 6, yy, 5, height(), name_right());
+}
+
+
+void MathAMSArrayInset::write(WriteStream & os) const
+{
+ os << "\\begin{" << name_ << "}";
+ MathGridInset::write(os);
+ os << "\\end{" << name_ << "}\n";
+}
+
+
+void MathAMSArrayInset::normalize(NormalStream & os) const
+{
+ os << "[" << name_ << " ";
+ MathGridInset::normalize(os);
+ os << "]";
+}
+
+
+void MathAMSArrayInset::maplize(MapleStream & os) const
+{
+ os << name_ << "(";
+ MathGridInset::maplize(os);
+ os << ")";
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_AMSARRAYINSET_H
+#define MATH_AMSARRAYINSET_H
+
+#include "math_gridinset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+
+class MathAMSArrayInset : public MathGridInset {
+public:
+ ///
+ MathAMSArrayInset(string const & name_, int m, int n);
+ ///
+ MathAMSArrayInset(string const & name_);
+ ///
+ MathInset * clone() const;
+ ///
+ void metrics(MathMetricsInfo const & st) const;
+ ///
+ void draw(Painter & pain, int x, int y) const;
+ ///
+ MathAMSArrayInset * asAMSArrayInset() { return this; }
+
+ ///
+ void write(WriteStream & os) const;
+ ///
+ void normalize(NormalStream &) const;
+ ///
+ void maplize(MapleStream &) const;
+
+private:
+ ///
+ char const * name_left() const;
+ ///
+ char const * name_right() const;
+
+ ///
+ string name_;
+};
+
+#endif
#include "math_parser.h"
#include "math_inset.h"
#include "math_arrayinset.h"
+#include "math_amsarrayinset.h"
#include "math_braceinset.h"
#include "math_casesinset.h"
#include "math_charinset.h"
///
bool parse_lines(MathAtom & t, bool numbered, bool outmost);
/// parses {... & ... \\ ... & ... }
- bool parse_lines2(MathAtom & t);
+ bool parse_lines2(MathAtom & t, bool braced);
/// dump contents to screen
void dump() const;
}
-bool Parser::parse_lines2(MathAtom & t)
+bool Parser::parse_lines2(MathAtom & t, bool braced)
{
MathGridInset * p = t->asGridInset();
if (!p) {
return false;
}
- skipBegin();
-
for (int row = 0; true; ++row) {
// reading a row
for (MathInset::col_type col = 0; true; ++col) {
getToken();
}
- // we are finished if the next token is an '}'
- if (nextToken().cat() == catEnd) {
- // skip the end-token
- getToken();
- // leave the 'read a line'-loop
- break;
+ // we are finished if the next token is the one we expected
+ // skip the end-token
+ // leave the 'read a line'-loop
+ if (braced) {
+ if (nextToken().cat() == catEnd) {
+ getToken();
+ break;
+ }
+ } else {
+ if (nextToken().cs() == "end") {
+ getToken();
+ getArg('{','}');
+ break;
+ }
}
// otherwise, we have to start a new row
} else if (name == "cases") {
array.push_back(MathAtom(new MathCasesInset));
parse_lines(array.back(), false, false);
+ } else if (name == "pmatrix" || name == "bmatrix") {
+ array.push_back(MathAtom(new MathAMSArrayInset(name)));
+ parse_lines2(array.back(), false);
} else
lyxerr << "unknow math inset begin '" << name << "'\n";
}
else if (t.cs() == "xymatrix") {
array.push_back(createMathInset(t.cs()));
- parse_lines2(array.back());
+ skipBegin();
+ parse_lines2(array.back(), true);
}
#if 0
}
}
*/
+
+void MathXArray::center(int & x, int & y) const
+{
+ x = xo_ + width_ / 2;
+ y = yo_ + (descent_ - ascent_) / 2;
+}
+
+
+void MathXArray::towards(int & x, int & y) const
+{
+ int cx = 0;
+ int cy = 0;
+ center(cx, cy);
+
+ double r = 1.0;
+ int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
+
+ x = cx + int(r * (x - cx));
+ y = cy + int(r * (y - cy));
+}
void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
/// find best position to do things
//void findPos(PosFinder &) const;
+ /// gives center coordinates
+ void center(int & x, int & y) const;
+ /// adjust (x,y) to point on boundary on a straight line from the center
+ void towards(int & x, int & y) const;
/// begin iterator of the underlying MathArray
const_iterator begin() const { return data_.begin(); }