make operator<<(*stream, ...) free functions;

make *stream 'class' instead of 'struct' (not finished);
use LCOlor::mathline only for boxes.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3140 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-12-03 16:24:50 +00:00
parent 8e88c36e20
commit aed2b1804c
23 changed files with 339 additions and 270 deletions

View File

@ -111,6 +111,7 @@ libmathed_la_SOURCES = \
math_sqrtinset.h \ math_sqrtinset.h \
math_stackrelinset.C \ math_stackrelinset.C \
math_stackrelinset.h \ math_stackrelinset.h \
math_streamstr.h \
math_stringinset.C \ math_stringinset.C \
math_stringinset.h \ math_stringinset.h \
math_support.C \ math_support.C \

View File

@ -283,20 +283,19 @@ void InsetFormula::write(Buffer const * buf, ostream & os) const
} }
int InsetFormula::latex(Buffer const * buf, ostream & os, bool fragil, bool) int InsetFormula::latex(Buffer const *, ostream & os, bool fragil, bool) const
const
{ {
WriteStream wi(buf, os, fragil); WriteStream wi(os, fragil);
par_->write(wi); par_->write(wi);
return wi.line_; return wi.line();
} }
int InsetFormula::ascii(Buffer const * buf, ostream & os, int) const int InsetFormula::ascii(Buffer const *, ostream & os, int) const
{ {
WriteStream wi(buf, os, false); WriteStream wi(os, false);
par_->write(wi); par_->write(wi);
return wi.line_; return wi.line();
} }
@ -310,11 +309,11 @@ int InsetFormula::docbook(Buffer const * buf, ostream & os) const
{ {
MathMLStream ms(os); MathMLStream ms(os);
ms << MTag("equation") << MTag("alt"); ms << MTag("equation") << MTag("alt");
int res = ascii(buf, ms.os_, 0); int res = ascii(buf, ms.os(), 0);
ms << ETag("alt") << MTag("math"); ms << ETag("alt") << MTag("math");
ms << par_.nucleus(); ms << par_.nucleus();
ms << ETag("math") << ETag("equation"); ms << ETag("math") << ETag("equation");
return ms.line_ + res; return ms.line() + res;
} }

View File

@ -559,7 +559,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
case LFUN_MATH_DELIM: case LFUN_MATH_DELIM:
{ {
//lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n"; lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
string ls; string ls;
string rs; string rs;
istringstream is(arg.c_str()); istringstream is(arg.c_str());

View File

@ -71,26 +71,26 @@ Inset * InsetFormulaMacro::clone(Buffer const &, bool) const
} }
void InsetFormulaMacro::write(Buffer const * buf, ostream & os) const void InsetFormulaMacro::write(Buffer const *, ostream & os) const
{ {
os << "FormulaMacro "; os << "FormulaMacro ";
WriteStream wi(buf, os, false); WriteStream wi(os, false);
par()->write(wi); par()->write(wi);
} }
int InsetFormulaMacro::latex(Buffer const * buf, ostream & os, bool fragile, int InsetFormulaMacro::latex(Buffer const *, ostream & os, bool fragile,
bool /*free_spacing*/) const bool /*free_spacing*/) const
{ {
WriteStream wi(buf, os, fragile); WriteStream wi(os, fragile);
par()->write(wi); par()->write(wi);
return 2; return 2;
} }
int InsetFormulaMacro::ascii(Buffer const * buf, ostream & os, int) const int InsetFormulaMacro::ascii(Buffer const *, ostream & os, int) const
{ {
WriteStream wi(buf, os, false); WriteStream wi(os, false);
par()->write(wi); par()->write(wi);
return 0; return 0;
} }

View File

@ -71,7 +71,7 @@ void MathArrayInset::metrics(MathMetricsInfo const & st) const
void MathArrayInset::write(WriteStream & os) const void MathArrayInset::write(WriteStream & os) const
{ {
if (os.fragile) if (os.fragile())
os << "\\protect"; os << "\\protect";
os << "\\begin{array}"; os << "\\begin{array}";
@ -81,7 +81,7 @@ void MathArrayInset::write(WriteStream & os) const
MathGridInset::write(os); MathGridInset::write(os);
if (os.fragile) if (os.fragile())
os << "\\protect"; os << "\\protect";
os << "\\end{array}\n"; os << "\\end{array}\n";
} }

View File

@ -36,11 +36,11 @@ void MathCasesInset::draw(Painter & pain, int x, int y) const
void MathCasesInset::write(WriteStream & os) const void MathCasesInset::write(WriteStream & os) const
{ {
if (os.fragile) if (os.fragile())
os << "\\protect"; os << "\\protect";
os << "\\begin{cases}"; os << "\\begin{cases}";
MathGridInset::write(os); MathGridInset::write(os);
if (os.fragile) if (os.fragile())
os << "\\protect"; os << "\\protect";
os << "\\end{cases}\n"; os << "\\end{cases}\n";
} }

View File

@ -96,9 +96,9 @@ void MathCharInset::writeRaw(std::ostream & os) const
void MathCharInset::write(WriteStream & os) const void MathCharInset::write(WriteStream & os) const
{ {
writeHeader(os.os); writeHeader(os.os());
writeRaw(os.os); writeRaw(os.os());
writeTrailer(os.os); writeTrailer(os.os());
} }

View File

@ -805,7 +805,7 @@ void MathCursor::drawSelection(Painter & pain) const
int x = c.xo() + c.pos2x(anc.pos_); int x = c.xo() + c.pos2x(anc.pos_);
int y1 = c.yo() - c.ascent(); int y1 = c.yo() - c.ascent();
int y2 = c.yo() + c.descent(); int y2 = c.yo() + c.descent();
pain.line(x, y1, x, y2, LColor::mathline); pain.line(x, y1, x, y2, LColor::math);
} }
#endif #endif
} }
@ -961,7 +961,7 @@ void MathCursor::normalize() const
lyxerr << "this should not really happen - 2: " lyxerr << "this should not really happen - 2: "
<< pos() << " " << size() << " in idx: " << it->idx() << pos() << " " << size() << " in idx: " << it->idx()
<< " in atom: '"; << " in atom: '";
WriteStream wi(0, lyxerr, false); WriteStream wi(lyxerr, false);
it->par()->write(wi); it->par()->write(wi);
lyxerr << "\n"; lyxerr << "\n";
dump("error 4"); dump("error 4");

View File

@ -29,13 +29,25 @@ class InsetFormulaBase;
class Painter; class Painter;
class Selection; class Selection;
/**
[Have a look at math_inset.h first]
The MathCursor is different from the kind of cursor used in the Outer
World. It contains a stack of MathCursorPositions, each of which is made
up of a inset pointer, an index and a position offset, marking a path from
this formula's mathHullInset to the current position.
*/
/// Description of a position /// Description of a position
struct MathCursorPos { struct MathCursorPos {
/// inset /// pointer to an inset
MathAtom * par_; MathAtom * par_;
/// cell index /// cell index of a position in this inset
MathInset::idx_type idx_; MathInset::idx_type idx_;
/// cell position /// position in this cell
MathInset::pos_type pos_; MathInset::pos_type pos_;
/// returns cell corresponding to this position /// returns cell corresponding to this position
@ -48,13 +60,13 @@ struct MathCursorPos {
MathXArray & xcell(MathInset::idx_type idx) const; MathXArray & xcell(MathInset::idx_type idx) const;
}; };
/// /// test for equality
bool operator==(MathCursorPos const &, MathCursorPos const &); bool operator==(MathCursorPos const &, MathCursorPos const &);
/// /// test for unequality
bool operator<(MathCursorPos const &, MathCursorPos const &); bool operator<(MathCursorPos const &, MathCursorPos const &);
/// This is the external interface of Math's subkernel /// see above
class MathCursor { class MathCursor {
public: public:
/// short of anything else reasonable /// short of anything else reasonable
@ -82,25 +94,25 @@ public:
void erase(); void erase();
/// ///
void backspace(); void backspace();
/// /// called for LFUN_HOME etc
void home(bool sel = false); void home(bool sel = false);
/// /// called for LFUN_END etc
void end(bool sel = false); void end(bool sel = false);
/// /// called for LFUN_RIGHT and LFUN_RIGHTSEL
bool right(bool sel = false); bool right(bool sel = false);
/// /// called for LFUN_LEFT etc
bool left(bool sel = false); bool left(bool sel = false);
/// /// called for LFUN_UP etc
bool up(bool sel = false); bool up(bool sel = false);
/// /// called for LFUN_DOWN etc
bool down(bool sel = false); bool down(bool sel = false);
/// Put the cursor in the first position /// Put the cursor in the first position
void first(); void first();
/// Put the cursor in the last position /// Put the cursor in the last position
void last(); void last();
/// /// move to next cell in current inset
void idxNext(); void idxNext();
/// /// move to previous cell in current inset
void idxPrev(); void idxPrev();
/// ///
void plainErase(); void plainErase();
@ -111,10 +123,9 @@ public:
/// ///
void delLine(); void delLine();
/// This is in pixels from (maybe?) the top of inset /// in pixels from top of screen
void setPos(int x, int y); void setPos(int x, int y);
/// This is in pixels from (maybe?) the top of inset, don't move further /// in pixels from top of screen
///
void getPos(int & x, int & y); void getPos(int & x, int & y);
/// ///
MathAtom & par() const; MathAtom & par() const;
@ -122,11 +133,11 @@ public:
MathGridInset * enclosingGrid(idx_type &) const; MathGridInset * enclosingGrid(idx_type &) const;
/// ///
InsetFormulaBase const * formula(); InsetFormulaBase const * formula();
/// /// current offset in the current cell
pos_type pos() const; pos_type pos() const;
/// /// current cell
idx_type idx() const; idx_type idx() const;
/// /// size of current cell
size_type size() const; size_type size() const;
/// ///
bool interpret(string const &); bool interpret(string const &);
@ -134,8 +145,7 @@ public:
bool interpret(char); bool interpret(char);
/// ///
bool toggleLimits(); bool toggleLimits();
/// /// interpret name a name of a macro
// Macro mode methods
void macroModeClose(); void macroModeClose();
/// ///
bool inMacroMode() const; bool inMacroMode() const;
@ -167,9 +177,9 @@ public:
void handleDelim(string const & l, string const & r); void handleDelim(string const & l, string const & r);
/// ///
void handleNest(MathInset * p); void handleNest(MathInset * p);
/// Splits cells and shifts right part to the next cell /// splits cells and shifts right part to the next cell
void splitCell(); void splitCell();
/// Splits line and insert new row of cell /// splits line and insert new row of cell
void breakLine(); void breakLine();
/// read contents of line into an array /// read contents of line into an array
void readLine(MathArray & ar) const; void readLine(MathArray & ar) const;
@ -192,7 +202,7 @@ public:
/// ///
row_type row() const; row_type row() const;
/// Make sure cursor position is valid /// make sure cursor position is valid
void normalize() const; void normalize() const;
/// ///
UpdatableInset * asHyperActiveInset() const; UpdatableInset * asHyperActiveInset() const;
@ -235,14 +245,14 @@ public:
/// path of positions the anchor had to go if it were leving each inset /// path of positions the anchor had to go if it were leving each inset
cursor_type Anchor_; cursor_type Anchor_;
/// reference to the last item of the path /// reference to the last item of the path, i.e. "The Cursor"
MathCursorPos & cursor(); MathCursorPos & cursor();
/// /// reference to the last item of the path, i.e. "The Cursor"
MathCursorPos const & cursor() const; MathCursorPos const & cursor() const;
/// /// dump selection information for debugging
void seldump(char const * str) const; void seldump(char const * str) const;
/// /// dump selection information for debugging
void dump(char const * str) const; void dump(char const * str) const;
/// ///
void stripFromLastEqualSign(); void stripFromLastEqualSign();

View File

@ -93,7 +93,7 @@ void MathDecorationInset::draw(Painter & pain, int x, int y) const
void MathDecorationInset::write(WriteStream & os) const void MathDecorationInset::write(WriteStream & os) const
{ {
if (os.fragile && protect()) if (os.fragile() && protect())
os << "\\protect"; os << "\\protect";
os << '\\' << name_.c_str() << '{' << cell(0) << '}'; os << '\\' << name_.c_str() << '{' << cell(0) << '}';
} }

View File

@ -713,7 +713,7 @@ void write(MathArray const & dat, WriteStream & wi)
MathArray ar = dat; MathArray ar = dat;
extractStrings(ar); extractStrings(ar);
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) { for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) {
wi.firstitem = (it == ar.begin()); wi.firstitem() = (it == ar.begin());
MathInset const * p = it->nucleus(); MathInset const * p = it->nucleus();
if (it + 1 != ar.end()) { if (it + 1 != ar.end()) {
if (MathScriptInset const * q = asScript(it)) { if (MathScriptInset const * q = asScript(it)) {

View File

@ -43,7 +43,7 @@ void MathFracInset::draw(Painter & pain, int x, int y) const
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5); 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); xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
if (!atop_) if (!atop_)
pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline); pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::math);
} }

View File

@ -3,7 +3,7 @@
#endif #endif
#include "math_gridinset.h" #include "math_gridinset.h"
#include "math_mathmlstream.h" #include "math_streamstr.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "Painter.h" #include "Painter.h"
#include "debug.h" #include "debug.h"

View File

@ -28,14 +28,6 @@
#include "debug.h" #include "debug.h"
MathInset::MathInset()
{}
MathInset::~MathInset()
{}
int MathInset::height() const int MathInset::height() const
{ {
return ascent() + descent(); return ascent() + descent();
@ -44,7 +36,7 @@ int MathInset::height() const
std::ostream & operator<<(std::ostream & os, MathInset const & inset) std::ostream & operator<<(std::ostream & os, MathInset const & inset)
{ {
WriteStream wi(0, os, false); WriteStream wi(os, false);
inset.write(wi); inset.write(wi);
return os; return os;
} }
@ -188,7 +180,7 @@ void MathInset::idxDeleteRange(idx_type, idx_type)
void MathInset::normalize(NormalStream & os) const void MathInset::normalize(NormalStream & os) const
{ {
os << "[unknown "; os << "[unknown ";
WriteStream wi(0, os.os_, false); WriteStream wi(os.os(), false);
write(wi); write(wi);
os << "] "; os << "] ";
} }
@ -197,7 +189,7 @@ void MathInset::normalize(NormalStream & os) const
void MathInset::dump() const void MathInset::dump() const
{ {
lyxerr << "---------------------------------------------\n"; lyxerr << "---------------------------------------------\n";
WriteStream wi(0, lyxerr, false); WriteStream wi(lyxerr, false);
write(wi); write(wi);
lyxerr << "\n---------------------------------------------\n"; lyxerr << "\n---------------------------------------------\n";
} }
@ -244,20 +236,20 @@ void MathInset::write(WriteStream &) const
void MathInset::octavize(OctaveStream & os) const void MathInset::octavize(OctaveStream & os) const
{ {
NormalStream ns(os.os_); NormalStream ns(os.os());
normalize(ns); normalize(ns);
} }
void MathInset::maplize(MapleStream & os) const void MathInset::maplize(MapleStream & os) const
{ {
NormalStream ns(os.os_); NormalStream ns(os.os());
normalize(ns); normalize(ns);
} }
void MathInset::mathmlize(MathMLStream & os) const void MathInset::mathmlize(MathMLStream & os) const
{ {
NormalStream ns(os.os_); NormalStream ns(os.os());
normalize(ns); normalize(ns);
} }

View File

@ -31,10 +31,18 @@
#include "math_xdata.h" #include "math_xdata.h"
#include "math_defs.h" #include "math_defs.h"
/** Abstract base class for all math objects. /**
A math insets is for use of the math editor only, it isn't a
general LyX inset. It's used to represent all the math objects. Abstract base class for all math objects. A math insets is for use of the
The formulaInset (a LyX inset) encapsulates a math inset. math editor only, it isn't a general LyX inset. It's used to represent all
the math objects.
Math insets do not know there parents, a cursor position or things
like that. The are dumb object that are contained in other math insets
(mathNestInsets, in fact) thus forming a tree. The root of this tree is
always a mathHullInset, which provides an interface to the Outer World by
inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
*/ */
@ -79,10 +87,10 @@ public:
/// type for column numbers /// type for column numbers
typedef size_type col_type; typedef size_type col_type;
/// /// our members behave nicely...
MathInset(); MathInset() {}
/// the virtual base destructor /// the virtual base destructor
virtual ~MathInset(); virtual ~MathInset() {}
/// draw the object /// draw the object
virtual void draw(Painter &, int x, int y) const; virtual void draw(Painter &, int x, int y) const;

View File

@ -11,61 +11,61 @@ MathMLStream::MathMLStream(std::ostream & os)
{} {}
MathMLStream & MathMLStream::operator<<(MathInset const * p) MathMLStream & operator<<(MathMLStream & ms, MathInset const * p)
{ {
if (p) if (p)
p->mathmlize(*this); p->mathmlize(ms);
else else
lyxerr << "MathMLStream::operator<<(NULL) called\n"; lyxerr << "operator<<(MathMLStream, NULL) called\n";
return *this; return ms;
} }
MathMLStream & MathMLStream::operator<<(MathArray const & ar) MathMLStream & operator<<(MathMLStream & ms, MathArray const & ar)
{ {
mathmlize(ar, *this); mathmlize(ar, ms);
return *this; return ms;
} }
MathMLStream & MathMLStream::operator<<(char const * s) MathMLStream & operator<<(MathMLStream & ms, char const * s)
{ {
os_ << s; ms.os() << s;
return *this; return ms;
} }
MathMLStream & MathMLStream::operator<<(char c) MathMLStream & operator<<(MathMLStream & ms, char c)
{ {
os_ << c; ms.os() << c;
return *this; return ms;
} }
MathMLStream & MathMLStream::operator<<(MTag const & t) MathMLStream & operator<<(MathMLStream & ms, MTag const & t)
{ {
++tab_; ++ms.tab();
cr(); ms.cr();
os_ << '<' << t.tag_ << '>'; ms.os() << '<' << t.tag_ << '>';
return *this; return ms;
} }
MathMLStream & MathMLStream::operator<<(ETag const & t) MathMLStream & operator<<(MathMLStream & ms, ETag const & t)
{ {
cr(); ms.cr();
if (tab_ > 0) if (ms.tab() > 0)
--tab_; --ms.tab();
os_ << "</" << t.tag_ << '>'; ms.os() << "</" << t.tag_ << '>';
return *this; return ms;
} }
void MathMLStream::cr() void MathMLStream::cr()
{ {
os_ << '\n'; os() << '\n';
for (int i = 0; i < tab_; ++i) for (int i = 0; i < tab(); ++i)
os_ << ' '; os() << ' ';
} }
@ -73,109 +73,109 @@ void MathMLStream::cr()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
MapleStream & MapleStream::operator<<(MathInset const * p) MapleStream & operator<<(MapleStream & ms, MathInset const * p)
{ {
if (p) if (p)
p->maplize(*this); p->maplize(ms);
else else
lyxerr << "MathMLStream::operator<<(NULL) called\n"; lyxerr << "operator<<(MapleStream, NULL) called\n";
return *this; return ms;
} }
MapleStream & MapleStream::operator<<(MathArray const & ar) MapleStream & operator<<(MapleStream & ms, MathArray const & ar)
{ {
maplize(ar, *this); maplize(ar, ms);
return *this; return ms;
} }
MapleStream & MapleStream::operator<<(char const * s) MapleStream & operator<<(MapleStream & ms, char const * s)
{ {
os_ << s; ms.os() << s;
return *this; return ms;
} }
MapleStream & MapleStream::operator<<(char c) MapleStream & operator<<(MapleStream & ms, char c)
{ {
os_ << c; ms.os() << c;
return *this; return ms;
} }
MapleStream & MapleStream::operator<<(int i) MapleStream & operator<<(MapleStream & ms, int i)
{ {
os_ << i; ms.os() << i;
return *this; return ms;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
OctaveStream & OctaveStream::operator<<(MathInset const * p) OctaveStream & operator<<(OctaveStream & ns, MathInset const * p)
{ {
if (p) if (p)
p->octavize(*this); p->octavize(ns);
else else
lyxerr << "MathMLStream::operator<<(NULL) called\n"; lyxerr << "operator<<(OctaveStream, NULL) called\n";
return *this; return ns;
} }
OctaveStream & OctaveStream::operator<<(MathArray const & ar) OctaveStream & operator<<(OctaveStream & ns, MathArray const & ar)
{ {
octavize(ar, *this); octavize(ar, ns);
return *this; return ns;
} }
OctaveStream & OctaveStream::operator<<(char const * s) OctaveStream & operator<<(OctaveStream & ns, char const * s)
{ {
os_ << s; ns.os() << s;
return *this; return ns;
} }
OctaveStream & OctaveStream::operator<<(char c) OctaveStream & operator<<(OctaveStream & ns, char c)
{ {
os_ << c; ns.os() << c;
return *this; return ns;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
NormalStream & NormalStream::operator<<(MathInset const * p) NormalStream & operator<<(NormalStream & ns, MathInset const * p)
{ {
if (p) if (p)
p->normalize(*this); p->normalize(ns);
else else
lyxerr << "MathMLStream::operator<<(NULL) called\n"; lyxerr << "operator<<(NormalStream, NULL) called\n";
return *this; return ns;
} }
NormalStream & NormalStream::operator<<(MathArray const & ar) NormalStream & operator<<(NormalStream & ns, MathArray const & ar)
{ {
normalize(ar, *this); normalize(ar, ns);
return *this; return ns;
} }
NormalStream & NormalStream::operator<<(char const * s) NormalStream & operator<<(NormalStream & ns, char const * s)
{ {
os_ << s; ns.os() << s;
return *this; return ns;
} }
NormalStream & NormalStream::operator<<(char c) NormalStream & operator<<(NormalStream & ns, char c)
{ {
os_ << c; ns.os() << c;
return *this; return ns;
} }
@ -183,76 +183,62 @@ NormalStream & NormalStream::operator<<(char c)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
WriteStream::WriteStream WriteStream::WriteStream(std::ostream & os, bool fragile)
(Buffer const * buffer_, std::ostream & os_, bool fragile_) : os_(os), fragile_(fragile), line_(0)
: buffer(buffer_), os(os_), fragile(fragile_), line_(0)
{} {}
WriteStream::WriteStream(std::ostream & os_) WriteStream::WriteStream(std::ostream & os)
: buffer(0), os(os_), fragile(false), line_(0) : os_(os), fragile_(false), line_(0)
{} {}
WriteStream & WriteStream::operator<<(MathInset const * p) WriteStream & operator<<(WriteStream & ws, MathInset const * p)
{ {
if (p) if (p)
p->write(*this); p->write(ws);
else else
lyxerr << "MathMLStream::operator<<(NULL) called\n"; lyxerr << "operator<<(WriteStream, NULL) called\n";
return *this; return ws;
} }
WriteStream & WriteStream::operator<<(MathArray const & ar) WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
{ {
write(ar, *this); write(ar, ws);
return *this; return ws;
} }
WriteStream & WriteStream::operator<<(string const & s) WriteStream & operator<<(WriteStream & ws, char const * s)
{ {
os << s; ws.os() << s;
string::const_iterator cit = s.begin();
string::const_iterator end = s.end();
for ( ; cit != end ; ++cit) {
if (*cit == '\n')
++line_;
}
return *this;
}
WriteStream & WriteStream::operator<<(char const * s)
{
os << s;
for ( ; *s ; ++s) { for ( ; *s ; ++s) {
if (*s == '\n') if (*s == '\n')
++line_; ++ws.line();
} }
return *this; return ws;
} }
WriteStream & WriteStream::operator<<(char c) WriteStream & operator<<(WriteStream & ws, char c)
{ {
os << c; ws.os() << c;
if (c == '\n') if (c == '\n')
++line_; ++ws.line();
return *this; return ws;
} }
WriteStream & WriteStream::operator<<(int i) WriteStream & operator<<(WriteStream & ws, int i)
{ {
os << i; ws.os() << i;
return *this; return ws;
} }
WriteStream & WriteStream::operator<<(unsigned int i) WriteStream & operator<<(WriteStream & ws, unsigned int i)
{ {
os << i; ws.os() << i;
return *this; return ws;
} }

View File

@ -1,15 +1,20 @@
#ifndef MATH_MATHMLSTREAM_H #ifndef MATH_MATHMLSTREAM_H
#define MATH_MATHMLSTREAM_H #define MATH_MATHMLSTREAM_H
#include "LString.h"
#include "support/LOstream.h" // Please keep all four streams in one file until the interface has
// settled.
#include <iosfwd> #include <iosfwd>
struct MathArray; class MathArray;
struct MathInset; class MathInset;
struct Buffer;
//
// MathML
//
struct MTag { struct MTag {
/// ///
@ -25,24 +30,19 @@ struct ETag {
char const * const tag_; char const * const tag_;
}; };
struct MathMLStream { class MathMLStream {
public:
/// ///
explicit MathMLStream(std::ostream & os); explicit MathMLStream(std::ostream & os);
/// ///
MathMLStream & operator<<(MathInset const *);
///
MathMLStream & operator<<(MathArray const &);
///
MathMLStream & operator<<(char const *);
///
MathMLStream & operator<<(char);
///
MathMLStream & operator<<(MTag const &);
///
MathMLStream & operator<<(ETag const &);
///
void cr(); void cr();
///
std::ostream & os() { return os_; }
///
int & line() { return line_; }
///
int & tab() { return tab_; }
private:
/// ///
std::ostream & os_; std::ostream & os_;
/// ///
@ -53,89 +53,145 @@ struct MathMLStream {
char lastchar_; char lastchar_;
}; };
///
MathMLStream & operator<<(MathMLStream &, MathInset const *);
///
MathMLStream & operator<<(MathMLStream &, MathArray const &);
///
MathMLStream & operator<<(MathMLStream &, char const *);
///
MathMLStream & operator<<(MathMLStream &, char);
///
MathMLStream & operator<<(MathMLStream &, MTag const &);
///
MathMLStream & operator<<(MathMLStream &, ETag const &);
struct NormalStream {
//
// Debugging
//
class NormalStream {
public:
/// ///
explicit NormalStream(std::ostream & os) : os_(os) {} explicit NormalStream(std::ostream & os) : os_(os) {}
///
std::ostream & os() { return os_; }
private:
/// ///
std::ostream & os_; std::ostream & os_;
///
NormalStream & operator<<(MathInset const *);
///
NormalStream & operator<<(MathArray const &);
///
NormalStream & operator<<(char const *);
///
NormalStream & operator<<(char);
}; };
///
NormalStream & operator<<(NormalStream &, MathInset const *);
///
NormalStream & operator<<(NormalStream &, MathArray const &);
///
NormalStream & operator<<(NormalStream &, char const *);
///
NormalStream & operator<<(NormalStream &, char);
struct MapleStream {
//
// Maple
//
class MapleStream {
public:
/// ///
explicit MapleStream(std::ostream & os) : os_(os) {} explicit MapleStream(std::ostream & os) : os_(os) {}
///
std::ostream & os() { return os_; }
private:
/// ///
std::ostream & os_; std::ostream & os_;
///
MapleStream & operator<<(MathInset const *);
///
MapleStream & operator<<(MathArray const &);
///
MapleStream & operator<<(char const *);
///
MapleStream & operator<<(char);
///
MapleStream & operator<<(int);
}; };
struct OctaveStream { ///
MapleStream & operator<<(MapleStream &, MathInset const *);
///
MapleStream & operator<<(MapleStream &, MathArray const &);
///
MapleStream & operator<<(MapleStream &, char const *);
///
MapleStream & operator<<(MapleStream &, char);
///
MapleStream & operator<<(MapleStream &, int);
//
// Octave
//
class OctaveStream {
public:
/// ///
explicit OctaveStream(std::ostream & os) : os_(os) {} explicit OctaveStream(std::ostream & os) : os_(os) {}
///
std::ostream & os() { return os_; }
private:
/// ///
std::ostream & os_; std::ostream & os_;
///
OctaveStream & operator<<(MathInset const *);
///
OctaveStream & operator<<(MathArray const &);
///
OctaveStream & operator<<(char const *);
///
OctaveStream & operator<<(char);
}; };
struct WriteStream {
/// ///
WriteStream(Buffer const * buffer_, std::ostream & os_, bool fragile_); OctaveStream & operator<<(OctaveStream &, MathInset const *);
///
OctaveStream & operator<<(OctaveStream &, MathArray const &);
///
OctaveStream & operator<<(OctaveStream &, char const *);
///
OctaveStream & operator<<(OctaveStream &, char);
//
// LaTeX/LyX
//
class WriteStream {
public:
///
WriteStream(std::ostream & os, bool fragile);
/// ///
explicit WriteStream(std::ostream & os_); explicit WriteStream(std::ostream & os_);
/// yes... the references will be removed some day...
int & line() { return line_; }
/// ///
WriteStream & operator<<(MathInset const *); bool fragile() const { return fragile_; }
/// ///
WriteStream & operator<<(MathArray const &); std::ostream & os() { return os_; }
/// ///
WriteStream & operator<<(string const &); bool & firstitem() { return firstitem_; }
private:
/// ///
WriteStream & operator<<(char const *); std::ostream & os_;
/// ///
WriteStream & operator<<(char); bool fragile_;
///
WriteStream & operator<<(int);
///
WriteStream & operator<<(unsigned int);
///
Buffer const * buffer;
///
std::ostream & os;
///
bool fragile;
/// are we at the beginning of an MathArray? /// are we at the beginning of an MathArray?
bool firstitem; bool firstitem_;
/// ///
int line_; int line_;
}; };
///
WriteStream & operator<<(WriteStream &, MathInset const *);
///
WriteStream & operator<<(WriteStream &, MathArray const &);
///
WriteStream & operator<<(WriteStream &, char const *);
///
WriteStream & operator<<(WriteStream &, char);
///
WriteStream & operator<<(WriteStream &, int);
///
WriteStream & operator<<(WriteStream &, unsigned int);
#endif #endif

View File

@ -54,7 +54,7 @@ void MathRootInset::draw(Painter & pain, int x, int y) const
xp[2] = x + w; yp[2] = y + d; xp[2] = x + w; yp[2] = y + d;
xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2; xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
xp[4] = x; yp[4] = y + (d - a)/2 + 2; xp[4] = x; yp[4] = y + (d - a)/2 + 2;
pain.lines(xp, yp, 5, LColor::mathline); pain.lines(xp, yp, 5, LColor::math);
} }

View File

@ -358,7 +358,7 @@ void MathScriptInset::write2(MathInset const * nuc, WriteStream & os) const
os << "\\limits "; os << "\\limits ";
} }
} else } else
if (os.firstitem) if (os.firstitem())
lyxerr << "suppressing {} \n"; lyxerr << "suppressing {} \n";
else else
os << "{}"; os << "{}";

View File

@ -19,13 +19,13 @@ MathInset * MathSplitInset::clone() const
} }
void MathSplitInset::write(WriteStream & os) const void MathSplitInset::write(WriteStream & ws) const
{ {
if (os.fragile) if (ws.fragile())
os << "\\protect"; ws << "\\protect";
os << "\\begin{split}"; ws << "\\begin{split}";
MathGridInset::write(os); MathGridInset::write(ws);
if (os.fragile) if (ws.fragile())
os << "\\protect"; ws << "\\protect";
os << "\\end{split}\n"; ws << "\\end{split}\n";
} }

View File

@ -39,7 +39,7 @@ void MathSqrtInset::draw(Painter & pain, int x, int y) const
xp[1] = x + 8; yp[1] = y - a + 1; xp[1] = x + 8; yp[1] = y - a + 1;
xp[2] = x + 5; yp[2] = y + d - 1; xp[2] = x + 5; yp[2] = y + d - 1;
xp[3] = x; yp[3] = y + (d - a)/2; xp[3] = x; yp[3] = y + (d - a)/2;
pain.lines(xp, yp, 4, LColor::mathline); pain.lines(xp, yp, 4, LColor::math);
} }

View File

@ -0,0 +1,17 @@
#ifndef MATH_STREAMSTR_H
#define MATH_STREAMSTR_H
#include "LString.h"
#include "math_mathmlstream.h"
//
// writing strings directly
//
inline WriteStream & operator<<(WriteStream & ws, string const & s)
{
ws << s.c_str();
return ws;
}
#endif

View File

@ -659,7 +659,7 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
mt.transform(xx, yy); mt.transform(xx, yy);
mt.transform(x2, y2); mt.transform(x2, y2);
pain.line(x + int(xx), y + int(yy), x + int(x2), y + int(y2), pain.line(x + int(xx), y + int(yy), x + int(x2), y + int(y2),
LColor::mathline); LColor::math);
} else { } else {
int xp[32]; int xp[32];
int yp[32]; int yp[32];
@ -676,7 +676,7 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
yp[j] = y + int(yy); yp[j] = y + int(yy);
// lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]"; // lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]";
} }
pain.lines(xp, yp, n, LColor::mathline); pain.lines(xp, yp, n, LColor::math);
} }
} }
} }