From a92d23883e434166230b350660ed01b60d349987 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 1 Aug 2002 15:53:46 +0000 Subject: [PATCH] save inset lock state in the .lyx file git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4828 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_cursor.C | 2 +- src/mathed/math_fontinset.C | 14 +++----------- src/mathed/math_fontinset.h | 6 ++---- src/mathed/math_fracinset.C | 15 +++++++-------- src/mathed/math_fracinset.h | 4 ++-- src/mathed/math_inset.C | 6 ++++++ src/mathed/math_inset.h | 2 ++ src/mathed/math_macro.C | 2 +- src/mathed/math_macro.h | 2 +- src/mathed/math_macrotemplate.C | 2 +- src/mathed/math_macrotemplate.h | 2 +- src/mathed/math_nestinset.C | 19 +++++++++++++++++++ src/mathed/math_nestinset.h | 5 +++++ src/mathed/math_parser.C | 5 +++++ src/mathed/math_scriptinset.C | 3 +++ src/mathed/math_unknowninset.C | 6 +++--- src/mathed/math_unknowninset.h | 8 ++++---- 17 files changed, 66 insertions(+), 37 deletions(-) diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 1eb3180096..468d67d63e 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -1500,7 +1500,7 @@ void MathCursor::setSelection(MathIterator const & where, size_type n) void MathCursor::insetToggle() { if (hasNextAtom()) { - // toggle next inset ... + // toggle previous inset ... nextAtom()->lock(!nextAtom()->lock()); } else if (popLeft() && hasNextAtom()) { // ... or enclosing inset if we are in the last inset position diff --git a/src/mathed/math_fontinset.C b/src/mathed/math_fontinset.C index ef7cdb7393..d0b8e3f948 100644 --- a/src/mathed/math_fontinset.C +++ b/src/mathed/math_fontinset.C @@ -18,9 +18,7 @@ MathFontInset::MathFontInset(latexkeys const * key) : MathNestInset(1), key_(key) -{ - //lock(true); -} +{} MathInset * MathFontInset::clone() const @@ -70,15 +68,9 @@ void MathFontInset::drawT(TextPainter & pain, int x, int y) const } -void MathFontInset::write(WriteStream & os) const -{ - os << '\\' << key_->name << '{' << cell(0) << '}'; -} - - -void MathFontInset::normalize(NormalStream & os) const +string MathFontInset::name() const { - os << "[font " << key_->name << " " << cell(0) << "]"; + return key_->name; } diff --git a/src/mathed/math_fontinset.h b/src/mathed/math_fontinset.h index 91e20458d3..18c8e1b4ae 100644 --- a/src/mathed/math_fontinset.h +++ b/src/mathed/math_fontinset.h @@ -23,6 +23,8 @@ public: /// are we in math mode, text mode, or unsure? mode_type currentMode() const; /// + string name() const; + /// void metrics(MathMetricsInfo & mi) const; /// void draw(MathPainterInfo & pi, int x, int y) const; @@ -31,10 +33,6 @@ public: /// void drawT(TextPainter & pi, int x, int y) const; /// - void write(WriteStream & os) const; - /// - void normalize(NormalStream &) const; - /// void validate(LaTeXFeatures & features) const; /// void infoize(std::ostream & os) const; diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index d8c79465f2..9464058006 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -75,30 +75,29 @@ void MathFracInset::write(WriteStream & os) const { if (atop_) os << '{' << cell(0) << "\\atop " << cell(1) << '}'; - else - os << "\\frac{" << cell(0) << "}{" << cell(1) << '}'; + else // it's \\frac + MathNestInset::write(os); } -void MathFracInset::normalize(NormalStream & os) const +string MathFracInset::name() const { - if (atop_) - os << "[atop "; - else - os << "[frac "; - os << cell(0) << ' ' << cell(1) << ']'; + return atop_ ? "atop" : "frac"; } + void MathFracInset::maplize(MapleStream & os) const { os << '(' << cell(0) << ")/(" << cell(1) << ')'; } + void MathFracInset::mathematicize(MathematicaStream & os) const { os << '(' << cell(0) << ")/(" << cell(1) << ')'; } + void MathFracInset::octavize(OctaveStream & os) const { os << '(' << cell(0) << ")/(" << cell(1) << ')'; diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index 63fd4b72f9..0fc668b914 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -27,12 +27,12 @@ public: void drawT(TextPainter &, int x, int y) const; /// MathFracInset * asFracInset(); + /// + string name() const; /// void write(WriteStream & os) const; /// - void normalize(NormalStream &) const; - /// void maplize(MapleStream &) const; /// void mathematicize(MathematicaStream &) const; diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 0c7e88ad9f..77bdc707b4 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -319,6 +319,12 @@ string const & MathInset::getType() const } +string MathInset::name() const +{ + return "unknown"; +} + + string asString(MathArray const & ar) { std::ostringstream os; diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 456f53a156..5d49ce84b1 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -291,6 +291,8 @@ public: virtual void mutate(string const &) {} /// how is the inset called in the .lyx file? virtual string fileInsetLabel() const { return "Formula"; } + /// usually the latex name + virtual string name() const; }; std::ostream & operator<<(std::ostream &, MathInset const &); diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 67a8070e90..6488d9651d 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -53,7 +53,7 @@ MathInset * MathMacro::clone() const } -string const & MathMacro::name() const +string MathMacro::name() const { return tmplate_->asMacroTemplate()->name(); } diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index 847a19f6ab..77e7784baf 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -79,7 +79,7 @@ private: /// void operator=(MathMacro const &); /// - string const & name() const; + string name() const; /// bool defining() const; /// diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 27fc4d31fe..4ae1ff83de 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -59,7 +59,7 @@ void MathMacroTemplate::numargs(int numargs) } -string const & MathMacroTemplate::name() const +string MathMacroTemplate::name() const { return name_; } diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index 106372f194..ac5c63469c 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -34,7 +34,7 @@ public: /// void numargs(int); /// - string const & name() const; + string name() const; /// void draw(MathPainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 85b4e92469..11a3ba9e83 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -302,6 +302,25 @@ MathArray MathNestInset::glue() const } +void MathNestInset::write(WriteStream & os) const +{ + os << '\\' << name().c_str(); + for (unsigned i = 0; i < nargs(); ++i) + os << '{' << cell(i) << '}'; + if (lock_ && !os.latex()) + os << "\\lyxlock "; +} + + +void MathNestInset::normalize(NormalStream & os) const +{ + os << '[' << name().c_str(); + for (unsigned i = 0; i < nargs(); ++i) + os << ' ' << cell(i); + os << ']'; +} + + void MathNestInset::notifyCursorLeaves() { // Generate a preview only if previews are active and we are leaving diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 3f8fd3e180..e925194935 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -98,6 +98,11 @@ public: /// is the cursor currently somewhere within this inset? virtual bool editing() const; + /// writes \\, name(), and args in braces and '\\lyxlock' if necessary + void write(WriteStream & os) const; + /// writes [, name(), and args in [] + void normalize(NormalStream & os) const; + protected: /// we store the cells in a vector typedef std::vector cells_type; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 56c8ca5332..02decd07b5 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -675,6 +675,11 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, // control sequences // + else if (t.cs() == "lyxlock") { + if (cell->size()) + cell->back()->lock(true); + } + else if (t.cs() == "def" || t.cs() == "newcommand") { string name; int nargs = 0; diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index 10223d75b1..cb50c07d82 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -360,6 +360,9 @@ void MathScriptInset::write(WriteStream & os) const if (hasUp() && up().size()) os << "^{" << up().data() << '}'; + + if (lock_ && !os.latex()) + os << "\\lyxlock "; } diff --git a/src/mathed/math_unknowninset.C b/src/mathed/math_unknowninset.C index d8727778e7..31bb97bcbf 100644 --- a/src/mathed/math_unknowninset.C +++ b/src/mathed/math_unknowninset.C @@ -21,15 +21,15 @@ MathInset * MathUnknownInset::clone() const } -string const & MathUnknownInset::name() const +string MathUnknownInset::name() const { return name_; } -string & MathUnknownInset::name() +void MathUnknownInset::setName(string const & name) { - return name_; + name_ = name; } diff --git a/src/mathed/math_unknowninset.h b/src/mathed/math_unknowninset.h index 36c26ba397..24e0382dbb 100644 --- a/src/mathed/math_unknowninset.h +++ b/src/mathed/math_unknowninset.h @@ -19,13 +19,13 @@ public: /// MathInset * clone() const; /// - void metrics(MathMetricsInfo & st) const; + void metrics(MathMetricsInfo & mi) const; /// - void draw(MathPainterInfo &, int x, int y) const; + void draw(MathPainterInfo & pi, int x, int y) const; /// - string & name(); + void setName(string const & name); /// - string const & name() const; + string name() const; /// identifies UnknownInsets MathUnknownInset const * asUnknownInset() const { return this; } /// identifies UnknownInsets -- 2.39.2