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
This commit is contained in:
André Pönitz 2002-08-14 15:13:07 +00:00
parent 3ce78466b5
commit 7cc71fc1e4
10 changed files with 197 additions and 22 deletions

View File

@ -35,6 +35,8 @@ libmathed_la_SOURCES = \
math_casesinset.h \ math_casesinset.h \
math_charinset.C \ math_charinset.C \
math_charinset.h \ math_charinset.h \
math_commentinset.C \
math_commentinset.h \
math_cursor.C \ math_cursor.C \
math_cursor.h \ math_cursor.h \
math_data.C \ math_data.C \

View File

@ -0,0 +1,86 @@
#include <config.h>
#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";
}

View File

@ -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

View File

@ -33,7 +33,7 @@
#include "math_autocorrect.h" #include "math_autocorrect.h"
#include "math_arrayinset.h" #include "math_arrayinset.h"
#include "math_braceinset.h" #include "math_braceinset.h"
#include "math_casesinset.h" #include "math_commentinset.h"
#include "math_charinset.h" #include "math_charinset.h"
#include "math_extern.h" #include "math_extern.h"
#include "math_factory.h" #include "math_factory.h"
@ -1151,15 +1151,6 @@ bool MathCursor::interpret(string const & s)
//owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt); //owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt);
//lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl; //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") { if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
unsigned int m = 1; unsigned int m = 1;
unsigned int n = 1; unsigned int n = 1;
@ -1384,7 +1375,7 @@ bool MathCursor::interpret(char c)
} }
if (c == '%') { if (c == '%') {
insert(createMathInset("%")); niceInsert(MathAtom(new MathCommentInset));
return true; return true;
} }

View File

@ -961,6 +961,42 @@ MathInset::result_type MathGridInset::dispatch
return DISPATCHED_POP; 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: default:
break; break;
} }

View File

@ -684,8 +684,14 @@ MathInset::result_type MathHullInset::dispatch
} }
return DISPATCHED; return DISPATCHED;
default: case LFUN_MATH_HALIGN:
case LFUN_MATH_VALIGN:
// we explicitly don't want the default behaviour here
return UNDISPATCHED; return UNDISPATCHED;
default:
return MathGridInset::dispatch(cmd, idx, pos);
} }
return UNDISPATCHED; return UNDISPATCHED;
} }

View File

@ -42,6 +42,7 @@ following hack as starting point to write some macros:
#include "math_braceinset.h" #include "math_braceinset.h"
#include "math_boxinset.h" #include "math_boxinset.h"
#include "math_charinset.h" #include "math_charinset.h"
#include "math_commentinset.h"
#include "math_deliminset.h" #include "math_deliminset.h"
#include "math_envinset.h" #include "math_envinset.h"
#include "math_extern.h" #include "math_extern.h"
@ -434,12 +435,14 @@ void Parser::tokenize(string const & buffer)
break; break;
} }
/*
case catComment: { case catComment: {
while (is.get(c) && catcode(c) != catNewline) while (is.get(c) && catcode(c) != catNewline)
; ;
++lineno_; ++lineno_;
break; break;
} }
*/
case catEscape: { case catEscape: {
is.get(c); is.get(c);
@ -563,7 +566,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
#ifdef FILEDEBUG #ifdef FILEDEBUG
lyxerr << "t: " << t << " flags: " << flags << "\n"; lyxerr << "t: " << t << " flags: " << flags << "\n";
//cell->dump(); cell->dump();
lyxerr << "\n"; lyxerr << "\n";
#endif #endif
@ -724,6 +727,18 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
else if (t.cat() == catOther) else if (t.cat() == catOther)
cell->push_back(MathAtom(new MathCharInset(t.character()))); 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 // control sequences
// //

View File

@ -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 bool MathScriptInset::hasUp() const
{ {
return script_[1]; return script_[1];

View File

@ -83,8 +83,6 @@ public:
bool hasDown() const; bool hasDown() const;
/// do we have a script? /// do we have a script?
bool has(bool up) const; bool has(bool up) const;
/// do we have a anything?
bool empty() const;
/// remove script /// remove script
void removeScript(bool up); void removeScript(bool up);
/// remove script /// remove script

View File

@ -11,7 +11,7 @@
char const * latex_mathspace[] = { char const * latex_mathspace[] = {
"!", ",", ";", ":", "quad", "qquad", "lyxnegspace", "lyxposspace" "!", ",", ":", ";", "quad", "qquad", "lyxnegspace", "lyxposspace"
}; };