This version includes basic support for making math formulae
non-editable. Andre, please look it over

thanks
john

Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.663
diff -u -a -p -r1.663 lyxfunc.C
--- lyxfunc.C   16 Jul 2005 10:35:41 -0000      1.663
+++ lyxfunc.C   21 Jul 2005 15:02:35 -0000
@@ -360,6 +360,17 @@ FuncStatus LyXFunc::getStatus(FuncReques
                return flag;
        }
 
+       // if we're inside an erased inset (under change tracking),
+       // don't allow any modifications. This is not perfect; we
+       // probably need a new FuncStatus flag
+       if (cur && cur.inset().erased()) {
+               if (!lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly) &&
+                   !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
+                       flag.enabled(false);
+                       return flag;
+               }
+       }
+
        // I would really like to avoid having this switch and rather try to
        // encode this in the function itself.
        // -- And I'd rather let an inset decide which LFUNs it is willing
Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.412
diff -u -a -p -r1.412 paragraph.C
--- paragraph.C 18 Jul 2005 12:57:05 -0000      1.412
+++ paragraph.C 21 Jul 2005 15:02:48 -0000
@@ -1659,9 +1659,9 @@ void Paragraph::setChange(lyx::pos_type 
 }
 
 
-void Paragraph::markErased()
+void Paragraph::markErased(bool erased)
 {
-       pimpl_->markErased();
+       pimpl_->markErased(erased);
 }
 
 
Index: paragraph.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v
retrieving revision 1.156
diff -u -a -p -r1.156 paragraph.h
--- paragraph.h 18 Jul 2005 14:25:20 -0000      1.156
+++ paragraph.h 21 Jul 2005 15:02:54 -0000
@@ -231,8 +231,8 @@ public:
        /// reject change
        void rejectChange(lyx::pos_type start, lyx::pos_type end);
 
-       /// mark whole par as erased
-       void markErased();
+       /// mark whole par as erased or not
+       void markErased(bool erased);
 
        /// Paragraphs can contain "manual labels", for example, Description
        /// environment. The text for this user-editable label is stored in
Index: paragraph_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.C,v
retrieving revision 1.99
diff -u -a -p -r1.99 paragraph_pimpl.C
--- paragraph_pimpl.C   24 Jan 2005 17:12:19 -0000      1.99
+++ paragraph_pimpl.C   21 Jul 2005 15:03:00 -0000
@@ -165,15 +165,21 @@ Change const Paragraph::Pimpl::lookupCha
 }
 
 
-void Paragraph::Pimpl::markErased()
+void Paragraph::Pimpl::markErased(bool erased)
 {
        BOOST_ASSERT(tracking());
 
-       // FIXME: we should actually remove INSERTED chars.
-       // difficult because owning insettexts/tabulars need
-       // to update themselves when rows etc. change
-       changes_->set(Change::DELETED, 0, size());
-       changes_->reset(Change::DELETED);
+       if (erased) {
+               erase(0, size());
+       } else {
+               pos_type i = 0;
+
+               for (; i < size(); ++i) {
+                       changes_->set(Change::UNCHANGED, i);
+                       if (owner_->text_[i] == Paragraph::META_INSET)
+                               owner_->getInset(i)->markErased(false);
+               }
+       }
 }
 
 
@@ -239,6 +245,8 @@ void Paragraph::Pimpl::rejectChange(pos_
 
                        case Change::DELETED:
                                changes_->set(Change::UNCHANGED, i);
+                               if (owner_->text_[i] == Paragraph::META_INSET)
+                                       owner_->getInset(i)->markErased(false);
                                break;
                }
        }
@@ -353,9 +361,8 @@ bool Paragraph::Pimpl::erase(pos_type po
 
                // only allow the actual removal if it was /new/ text
                if (changetype != Change::INSERTED) {
-                       if (owner_->text_[pos] == Paragraph::META_INSET) {
-                               owner_->getInset(pos)->markErased();
-                       }
+                       if (owner_->text_[pos] == Paragraph::META_INSET)
+                               owner_->getInset(pos)->markErased(true);
                        return false;
                }
        }
Index: paragraph_pimpl.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.h,v
retrieving revision 1.47
diff -u -a -p -r1.47 paragraph_pimpl.h
--- paragraph_pimpl.h   15 Jul 2005 22:10:19 -0000      1.47
+++ paragraph_pimpl.h   21 Jul 2005 15:03:00 -0000
@@ -55,7 +55,7 @@ public:
        /// set change at pos
        void setChange(lyx::pos_type pos, Change::Type type);
        /// mark as erased
-       void markErased();
+       void markErased(bool);
        /// accept change
        void acceptChange(lyx::pos_type start, lyx::pos_type end);
        /// reject change
Index: tabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.C,v
retrieving revision 1.226
diff -u -a -p -r1.226 tabular.C
--- tabular.C   20 Jul 2005 00:10:56 -0000      1.226
+++ tabular.C   21 Jul 2005 15:03:19 -0000
@@ -515,7 +515,7 @@ void LyXTabular::appendColumn(BufferPara
        }
        //++column;
        for (row_type i = 0; i < rows_; ++i) {
-               cell_info[i][column + 1].inset->clear(false);
+               cell_info[i][column + 1].inset->clear();
                if (bp.tracking_changes)
                        cell_info[i][column + 1].inset->markNew(true);
        }
@@ -1350,7 +1350,7 @@ void LyXTabular::setMultiColumn(Buffer *
                cellstruct & cs1 = cellinfo_of_cell(cell + i);
                cs1.multicolumn = CELL_PART_OF_MULTICOLUMN;
                cs.inset->appendParagraphs(buffer, cs1.inset->paragraphs());
-               cs1.inset->clear(false);
+               cs1.inset->clear();
        }
        set_row_column_number_info();
 }
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.624
diff -u -a -p -r1.624 text2.C
--- text2.C     18 Jul 2005 20:34:55 -0000      1.624
+++ text2.C     21 Jul 2005 15:03:29 -0000
@@ -622,18 +622,11 @@ void LyXText::insertInset(LCursor & cur,
 // needed to insert the selection
 void LyXText::insertStringAsLines(LCursor & cur, string const & str)
 {
-       pit_type pit = cur.pit();
-       pos_type pos = cur.pos();
        recordUndo(cur);
 
-       // only to be sure, should not be neccessary
-       cur.clearSelection();
-       cur.buffer().insertStringAsLines(pars_, pit, pos, current_font, str,
-               autoBreakRows_);
-
+       cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(),
+                                        current_font, str, autoBreakRows_);
        cur.resetAnchor();
-       setCursor(cur, cur.pit(), pos);
-       cur.setSelection();
 }
 
 
Index: insets/inset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.C,v
retrieving revision 1.134
diff -u -a -p -r1.134 inset.C
--- insets/inset.C      15 Jul 2005 22:10:21 -0000      1.134
+++ insets/inset.C      21 Jul 2005 15:04:04 -0000
@@ -27,13 +27,14 @@ using std::string;
 
 
 InsetOld::InsetOld()
-       : //background_color_(LColor::inherit)
+       : erased_(false),
+         //background_color_(LColor::inherit)
          background_color_(LColor::background)
 {}
 
 
 InsetOld::InsetOld(InsetOld const & in)
-       : InsetBase(in), name_(in.name_),
+       : InsetBase(in), erased_(in.erased_), name_(in.name_),
          background_color_(in.background_color_)
 {}
 
Index: insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.162
diff -u -a -p -r1.162 inset.h
--- insets/inset.h      15 Jul 2005 22:10:21 -0000      1.162
+++ insets/inset.h      21 Jul 2005 15:04:04 -0000
@@ -50,11 +50,19 @@ public:
        /// set x/y drawing position cache
        void setPosCache(PainterInfo const &, int, int) const;
 
+       virtual bool erased() const {
+               return erased_;
+       }
+       
 protected:
        ///
        InsetOld(InsetOld const & in);
+
        ///
        mutable Dimension dim_;
+
+       /// is this change-tracked and marked erased?
+       bool erased_;
 
 private:
        InsetOld & operator=(InsetOld const &) const;
Index: insets/insetbase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.C,v
retrieving revision 1.47
diff -u -a -p -r1.47 insetbase.C
--- insets/insetbase.C  18 Jul 2005 21:19:23 -0000      1.47
+++ insets/insetbase.C  21 Jul 2005 15:04:08 -0000
@@ -273,7 +273,7 @@ std::string const & InsetBase::getInsetN
 }
 
 
-void InsetBase::markErased()
+void InsetBase::markErased(bool)
 {}
 
 
Index: insets/insetbase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.h,v
retrieving revision 1.57
diff -u -a -p -r1.57 insetbase.h
--- insets/insetbase.h  17 Jul 2005 01:13:35 -0000      1.57
+++ insets/insetbase.h  21 Jul 2005 15:04:14 -0000
@@ -209,6 +209,8 @@ public:
        virtual bool descendable() const { return false; }
        ///
        virtual bool isTextInset() const { return false; }
+       /// is this a change-tracked erased inset?
+       virtual bool erased() const { return false; }
        /// return true if the inset should be removed automatically
        virtual bool autoDelete() const;
 
@@ -372,12 +374,12 @@ public:
        virtual mode_type currentMode() const { return UNDECIDED_MODE; }
        /// returns whether this inset is allowed in other insets of given mode
        virtual bool allowedIn(mode_type) const { return true; }
-
        /// is this inset allowed within a font change?
        virtual bool noFontChange() const { return false; }
 
-       ///
-       virtual void markErased();
+       /// mark the inset as erased or not
+       virtual void markErased(bool erased);
+               
        /// pretty arbitrary
        virtual int width() const { return 10; }
        /// pretty arbitrary
Index: insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.481
diff -u -a -p -r1.481 insettabular.C
--- insets/insettabular.C       18 Jul 2005 17:12:28 -0000      1.481
+++ insets/insettabular.C       21 Jul 2005 15:06:31 -0000
@@ -367,24 +367,31 @@ void InsetTabular::drawCellLines(Painter
 {
        int x2 = x + tabular.getWidthOfColumn(cell);
        bool on_off = false;
+       LColor::color col = LColor::tabularline;
+       LColor::color onoffcol = LColor::tabularonoffline;
+
+       if (erased_) {
+               col = LColor::strikeout;
+               onoffcol = LColor::strikeout;
+       }
 
        if (!tabular.topAlreadyDrawn(cell)) {
                on_off = !tabular.topLine(cell);
                pain.line(x, y - tabular.getAscentOfRow(row),
                          x2, y -  tabular.getAscentOfRow(row),
-                         on_off ? LColor::tabularonoffline : 
LColor::tabularline,
+                         on_off ? onoffcol : col,
                          on_off ? Painter::line_onoffdash : 
Painter::line_solid);
        }
        on_off = !tabular.bottomLine(cell);
        pain.line(x, y + tabular.getDescentOfRow(row),
                  x2, y + tabular.getDescentOfRow(row),
-                 on_off ? LColor::tabularonoffline : LColor::tabularline,
+                 on_off ? onoffcol : col,
                  on_off ? Painter::line_onoffdash : Painter::line_solid);
        if (!tabular.leftAlreadyDrawn(cell)) {
                on_off = !tabular.leftLine(cell);
                pain.line(x, y -  tabular.getAscentOfRow(row),
                          x, y +  tabular.getDescentOfRow(row),
-                         on_off ? LColor::tabularonoffline : 
LColor::tabularline,
+                         on_off ? onoffcol : col,
                          on_off ? Painter::line_onoffdash : 
Painter::line_solid);
        }
        on_off = !tabular.rightLine(cell);
@@ -392,7 +399,7 @@ void InsetTabular::drawCellLines(Painter
                  y -  tabular.getAscentOfRow(row),
                  x2 - tabular.getAdditionalWidth(cell),
                  y +  tabular.getDescentOfRow(row),
-                 on_off ? LColor::tabularonoffline : LColor::tabularline,
+                 on_off ? onoffcol : col,
                  on_off ? Painter::line_onoffdash : Painter::line_solid);
 }
 
@@ -1749,13 +1756,19 @@ void InsetTabular::cutSelection(LCursor 
        if (!cur.selection())
                return;
 
-       bool const track = cur.buffer().params().tracking_changes;
        row_type rs, re;
        col_type cs, ce;
        getSelection(cur, rs, re, cs, ce);
-       for (row_type i = rs; i <= re; ++i)
-               for (col_type j = cs; j <= ce; ++j)
-                       cell(tabular.getCellNumber(i, j))->clear(track);
+       for (row_type i = rs; i <= re; ++i) {
+               for (col_type j = cs; j <= ce; ++j) {
+                       shared_ptr<InsetText> t
+                               = cell(tabular.getCellNumber(i, j));
+                       if (cur.buffer().params().tracking_changes)
+                               t->markErased(true);
+                       else
+                               t->clear();
+               }
+       }
 
        // cursor position might be invalid now
        cur.pos() = cur.lastpos();
@@ -1800,10 +1813,12 @@ LyXText * InsetTabular::getText(int idx)
 }
 
 
-void InsetTabular::markErased()
+void InsetTabular::markErased(bool erased)
 {
+       erased_ = erased;
+
        for (idx_type idx = 0; idx < nargs(); ++idx)
-               cell(idx)->markErased();
+               cell(idx)->markErased(erased);
 }
 
 
Index: insets/insettabular.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.h,v
retrieving revision 1.207
diff -u -a -p -r1.207 insettabular.h
--- insets/insettabular.h       18 Jul 2005 12:57:07 -0000      1.207
+++ insets/insettabular.h       21 Jul 2005 15:06:31 -0000
@@ -115,7 +115,7 @@ public:
        LyXText * getText(int) const;
 
        ///
-       void markErased();
+       void markErased(bool);
 
        // this should return true if we have a "normal" cell, otherwise true.
        // "normal" means without width set!
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.619
diff -u -a -p -r1.619 insettext.C
--- insets/insettext.C  18 Jul 2005 12:57:07 -0000      1.619
+++ insets/insettext.C  21 Jul 2005 15:06:39 -0000
@@ -108,14 +108,18 @@ void InsetText::init()
 }
 
 
-void InsetText::clear(bool just_mark_erased)
+void InsetText::markErased(bool erased)
+{
+       erased_ = erased;
+       ParagraphList & pars = paragraphs();
+       for_each(pars.begin(), pars.end(),
+                bind(&Paragraph::markErased, _1, erased));
+}
+
+
+void InsetText::clear()
 {
        ParagraphList & pars = paragraphs();
-       if (just_mark_erased) {
-               for_each(pars.begin(), pars.end(),
-                        bind(&Paragraph::markErased, _1));
-               return;
-       }
 
        // This is a gross hack...
        LyXLayout_ptr old_layout = pars.begin()->layout();
@@ -142,7 +146,7 @@ void InsetText::write(Buffer const & buf
 
 void InsetText::read(Buffer const & buf, LyXLex & lex)
 {
-       clear(false);
+       clear();
 
 #ifdef WITH_WARNINGS
 #warning John, look here. Doesnt make much sense.
@@ -352,7 +356,7 @@ void InsetText::markNew(bool track_chang
 
 void InsetText::setText(string const & data, LyXFont const & font)
 {
-       clear(false);
+       clear();
        Paragraph & first = paragraphs().front();
        for (unsigned int i = 0; i < data.length(); ++i)
                first.insertChar(i, data[i], font);
Index: insets/insettext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v
retrieving revision 1.275
diff -u -a -p -r1.275 insettext.h
--- insets/insettext.h  18 Jul 2005 12:57:08 -0000      1.275
+++ insets/insettext.h  21 Jul 2005 15:06:39 -0000
@@ -40,8 +40,8 @@ public:
        explicit InsetText(BufferParams const &);
        ///
        InsetText();
-       /// empty inset to empty par, or just mark as erased
-       void clear(bool just_mark_erased);
+       /// empty inset to empty par
+       void clear();
        ///
        void read(Buffer const & buf, LyXLex & lex);
        ///
@@ -107,7 +107,8 @@ public:
        bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) 
const;
 
        /// mark as erased for change tracking
-       void markErased() { clear(true); }
+       void markErased(bool erased);
+
        /**
         * Mark as new. Used when pasting in tabular, and adding rows
         * or columns. Note that pasting will ensure that tracking already
Index: mathed/math_hullinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hullinset.C,v
retrieving revision 1.179
diff -u -a -p -r1.179 math_hullinset.C
--- mathed/math_hullinset.C     18 Jul 2005 17:12:28 -0000      1.179
+++ mathed/math_hullinset.C     21 Jul 2005 15:07:15 -0000
@@ -136,7 +136,8 @@ namespace {
 
 MathHullInset::MathHullInset()
        : MathGridInset(1, 1), type_("none"), nonum_(1), label_(1),
-         preview_(new RenderPreview(this))
+         preview_(new RenderPreview(this)), use_preview_(false),
+         erased_(false)
 {
        //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << endl;
        //lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
@@ -148,7 +149,8 @@ MathHullInset::MathHullInset()
 
 MathHullInset::MathHullInset(string const & type)
        : MathGridInset(getCols(type), 1), type_(type), nonum_(1), label_(1),
-         preview_(new RenderPreview(this))
+         preview_(new RenderPreview(this)), use_preview_(false),
+         erased_(false)
 {
        setDefaults();
 }
@@ -157,7 +159,8 @@ MathHullInset::MathHullInset(string cons
 MathHullInset::MathHullInset(MathHullInset const & other)
        : MathGridInset(other),
          type_(other.type_), nonum_(other.nonum_), label_(other.label_),
-         preview_(new RenderPreview(this))
+         preview_(new RenderPreview(this)), use_preview_(false),
+         erased_(false)
 {}
 
 
Index: mathed/math_hullinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hullinset.h,v
retrieving revision 1.63
diff -u -a -p -r1.63 math_hullinset.h
--- mathed/math_hullinset.h     18 Jul 2005 00:45:10 -0000      1.63
+++ mathed/math_hullinset.h     21 Jul 2005 15:07:20 -0000
@@ -116,6 +116,15 @@ public:
        ///
        void addPreview(lyx::graphics::PreviewLoader &) const;
 
+       /// is this change-tracked and marked erased?
+       virtual bool erased() const {
+               return erased_;
+       }
+
+       /// mark as erased for change tracking
+       void markErased(bool erased) {
+               erased_ = erased;
+       }
 
 protected:
        MathHullInset(MathHullInset const &);
@@ -179,6 +188,10 @@ private:
        boost::scoped_ptr<RenderPreview> preview_;
        ///
        mutable bool use_preview_;
+
+       /// is this change-tracked and marked erased?
+       bool erased_;
+
 //
 // Incorporate me
 //

Reply via email to