From 7cc71fc1e4fd7e1f38943a74bdf9237e232c380a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 14 Aug 2002 15:13:07 +0000 Subject: [PATCH] small bugfixes, new inset for comments and the main part is moving lfun stuff from the FormulaBase and the cursor to those math insets that can handle the request... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4970 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/Makefile.am | 2 + src/mathed/math_commentinset.C | 86 ++++++++++++++++++++++++++++++++++ src/mathed/math_commentinset.h | 47 +++++++++++++++++++ src/mathed/math_cursor.C | 13 +---- src/mathed/math_gridinset.C | 36 ++++++++++++++ src/mathed/math_hullinset.C | 8 +++- src/mathed/math_parser.C | 17 ++++++- src/mathed/math_scriptinset.C | 6 --- src/mathed/math_scriptinset.h | 2 - src/mathed/math_spaceinset.C | 2 +- 10 files changed, 197 insertions(+), 22 deletions(-) create mode 100644 src/mathed/math_commentinset.C create mode 100644 src/mathed/math_commentinset.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 6de103b151..3f333fe95a 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -35,6 +35,8 @@ libmathed_la_SOURCES = \ math_casesinset.h \ math_charinset.C \ math_charinset.h \ + math_commentinset.C \ + math_commentinset.h \ math_cursor.C \ math_cursor.h \ math_data.C \ diff --git a/src/mathed/math_commentinset.C b/src/mathed/math_commentinset.C new file mode 100644 index 0000000000..d877b08dac --- /dev/null +++ b/src/mathed/math_commentinset.C @@ -0,0 +1,86 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_commentinset.h" +#include "math_mathmlstream.h" +#include "LaTeXFeatures.h" +#include "support/LOstream.h" +#include "textpainter.h" + + + +MathCommentInset::MathCommentInset() + : MathNestInset(1) +{} + + +MathCommentInset::MathCommentInset(string const & str) + : MathNestInset(1) +{ + cell(0) = asArray(str); +} + + +MathInset * MathCommentInset::clone() const +{ + return new MathCommentInset(*this); +} + + +void MathCommentInset::metrics(MathMetricsInfo & mi) const +{ + dim_ = cell(0).metrics(mi); + metricsMarkers(); +} + + +void MathCommentInset::draw(MathPainterInfo & pi, int x, int y) const +{ + cell(0).draw(pi, x + 1, y); + drawMarkers(pi, x, y); +} + + +void MathCommentInset::metricsT(TextMetricsInfo const & mi) const +{ + dim_ = cell(0).metricsT(mi); +} + + +void MathCommentInset::drawT(TextPainter & pain, int x, int y) const +{ + cell(0).drawT(pain, x, y); +} + + +void MathCommentInset::write(WriteStream & os) const +{ + os << '%' << cell(0) << "\n"; +} + + +void MathCommentInset::maplize(MapleStream & os) const +{} + + +void MathCommentInset::mathematicize(MathematicaStream & os) const +{} + + +void MathCommentInset::octavize(OctaveStream & os) const +{} + + +void MathCommentInset::mathmlize(MathMLStream & os) const +{ + os << MTag("comment") << cell(0) << cell(1) << ETag("comment"); +} + + +void MathCommentInset::infoize(std::ostream & os) const +{ + os << "Comment"; +} diff --git a/src/mathed/math_commentinset.h b/src/mathed/math_commentinset.h new file mode 100644 index 0000000000..184b39c345 --- /dev/null +++ b/src/mathed/math_commentinset.h @@ -0,0 +1,47 @@ +// -*- C++ -*- +#ifndef MATH_COMMENTINSET_H +#define MATH_COMMENTINSET_H + +#include "math_nestinset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Inset for end-of-line comments + \author André Pönitz + */ + +class latexkeys; + +class MathCommentInset : public MathNestInset { +public: + /// + MathCommentInset(); + /// + explicit MathCommentInset(string const &); + /// + MathInset * clone() const; + /// + void metrics(MathMetricsInfo & mi) const; + /// + void draw(MathPainterInfo & pi, int x, int y) const; + /// + void metricsT(TextMetricsInfo const & mi) const; + /// + void drawT(TextPainter & pi, int x, int y) const; + + /// + void write(WriteStream & os) const; + /// + void maplize(MapleStream &) const; + /// + void mathematicize(MathematicaStream &) const; + /// + void octavize(OctaveStream &) const; + /// + void mathmlize(MathMLStream &) const; + /// + void infoize(std::ostream & os) const; +}; +#endif diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 77d3f45041..02593a8b5e 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -33,7 +33,7 @@ #include "math_autocorrect.h" #include "math_arrayinset.h" #include "math_braceinset.h" -#include "math_casesinset.h" +#include "math_commentinset.h" #include "math_charinset.h" #include "math_extern.h" #include "math_factory.h" @@ -1151,15 +1151,6 @@ bool MathCursor::interpret(string const & s) //owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt); //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl; - if (s.size() >= 5 && s.substr(0, 5) == "cases") { - unsigned int n = 1; - istringstream is(s.substr(5).c_str()); - is >> n; - n = max(1u, n); - niceInsert(MathAtom(new MathCasesInset(n))); - return true; - } - if (s.size() >= 6 && s.substr(0, 6) == "matrix") { unsigned int m = 1; unsigned int n = 1; @@ -1384,7 +1375,7 @@ bool MathCursor::interpret(char c) } if (c == '%') { - insert(createMathInset("%")); + niceInsert(MathAtom(new MathCommentInset)); return true; } diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index a679d1fd30..3042e0085f 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -961,6 +961,42 @@ MathInset::result_type MathGridInset::dispatch return DISPATCHED_POP; } + case LFUN_MATH_HALIGN: + halign((cmd.argument + "c")[0], col(idx)); + return DISPATCHED_POP; + + case LFUN_MATH_VALIGN: + valign((cmd.argument + "c")[0]); + return DISPATCHED_POP; + + case LFUN_MATH_ROW_INSERT: + addRow(row(idx)); + return DISPATCHED_POP; + + case LFUN_MATH_ROW_DELETE: + delRow(row(idx)); + if (idx > nargs()) + idx -= ncols(); + return DISPATCHED_POP; + + case LFUN_MATH_COLUMN_INSERT: { + row_type r = row(idx); + col_type c = col(idx); + addFancyCol(c); + idx = index(r, c); + return DISPATCHED_POP; + } + + case LFUN_MATH_COLUMN_DELETE: { + row_type r = row(idx); + col_type c = col(idx); + delFancyCol(col(idx)); + idx = index(r, c); + if (idx > nargs()) + idx -= ncols(); + return DISPATCHED_POP; + } + default: break; } diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 8b3b2d1197..80f855a41f 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -684,8 +684,14 @@ MathInset::result_type MathHullInset::dispatch } return DISPATCHED; + case LFUN_MATH_HALIGN: + case LFUN_MATH_VALIGN: + // we explicitly don't want the default behaviour here + return UNDISPATCHED; + default: - return UNDISPATCHED; + return MathGridInset::dispatch(cmd, idx, pos); + } return UNDISPATCHED; } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 64f0c943e9..f24ea2abfe 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -42,6 +42,7 @@ following hack as starting point to write some macros: #include "math_braceinset.h" #include "math_boxinset.h" #include "math_charinset.h" +#include "math_commentinset.h" #include "math_deliminset.h" #include "math_envinset.h" #include "math_extern.h" @@ -434,12 +435,14 @@ void Parser::tokenize(string const & buffer) break; } +/* case catComment: { while (is.get(c) && catcode(c) != catNewline) ; ++lineno_; break; } +*/ case catEscape: { is.get(c); @@ -563,7 +566,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, #ifdef FILEDEBUG lyxerr << "t: " << t << " flags: " << flags << "\n"; - //cell->dump(); + cell->dump(); lyxerr << "\n"; #endif @@ -724,6 +727,18 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, else if (t.cat() == catOther) cell->push_back(MathAtom(new MathCharInset(t.character()))); + else if (t.cat() == catComment) { + string s; + while (good()) { + Token const & t = getToken(); + if (t.cat() == catNewline) + break; + s += t.asString(); + } + cell->push_back(MathAtom(new MathCommentInset(s))); + skipSpaces(); + } + // // control sequences // diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index da94d8df19..8c5a466cad 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -292,12 +292,6 @@ bool MathScriptInset::has(bool up) const } -bool MathScriptInset::empty() const -{ - return !script_[0] && !script_[1] && cell(2).empty(); -} - - bool MathScriptInset::hasUp() const { return script_[1]; diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 45a91b2d20..b376c7e301 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -83,8 +83,6 @@ public: bool hasDown() const; /// do we have a script? bool has(bool up) const; - /// do we have a anything? - bool empty() const; /// remove script void removeScript(bool up); /// remove script diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index 0e8af83749..2d87300102 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -11,7 +11,7 @@ char const * latex_mathspace[] = { - "!", ",", ";", ":", "quad", "qquad", "lyxnegspace", "lyxposspace" + "!", ",", ":", ";", "quad", "qquad", "lyxnegspace", "lyxposspace" }; -- 2.39.5