This creates a new structure 'TextCursor' that contains all cursor related
data from LyXText and replaces InsetText::sstate with such a 'TextCursor'.

Temporarily LyXText now publicly derives from TextCursor. This is not nice
and not intended to stay. However, the situation is not worse than before
(no additional public access etc) and a TextCursor member would have
produced a monster patch.

Intention is now to shuffle strictly cursor related stuff from text*.C to
textcursor.C, consequently cutting down the number of direct 
foo->text.cursor.bar()  uses.

Ok?

Andre'

-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.179
diff -u -p -r1.179 lyxtext.h
--- lyxtext.h   27 Jun 2003 09:44:25 -0000      1.179
+++ lyxtext.h   27 Jun 2003 10:31:19 -0000
@@ -21,6 +21,7 @@
 #include "insets/inset.h"
 #include "RowList.h"
 #include "bufferview_funcs.h"
+#include "textcursor.h"
 
 class Buffer;
 class BufferParams;
@@ -38,7 +39,10 @@ class ParagraphList;
 /**
   This class holds the mapping between buffer paragraphs and screen rows.
   */
-class LyXText {
+
+// The inheritance from TextCursor should go. It's just there to ease
+// transition...
+class LyXText : public TextCursor {
 public:
        /// what repainting is needed
        enum refresh_status {
@@ -268,54 +272,7 @@ public:
                return rowlist_;
        }
 
-       /** The cursor.
-         Later this variable has to be removed. There should be now internal
-         cursor in a text (and thus not in a buffer). By keeping this it is
-         (I think) impossible to have several views with the same buffer, but
-         the cursor placed at different places.
-         [later]
-         Since the LyXText now has been moved from Buffer to BufferView
-         it should not be absolutely needed to move the cursor...
-         */
-       LyXCursor cursor; // actual cursor position
-
-       /** The structure that keeps track of the selections set. */
-       struct Selection {
-               Selection()
-                       : set_(false), mark_(false)
-                       {}
-               bool set() const {
-                       return set_;
-               }
-               void set(bool s) {
-                       set_ = s;
-               }
-               bool mark() const {
-                       return mark_;
-               }
-               void mark(bool m) {
-                       mark_ = m;
-               }
-               LyXCursor cursor; // temporary cursor to hold a cursor position
-                                 // until setSelection is called!
-               LyXCursor start;  // start of a REAL selection
-               LyXCursor end;    // end of a REAL selection
-       private:
-               bool set_; // former selection
-               bool mark_; // former mark_set
-
-       };
-       Selection selection;
-       // this is used to handle XSelection events in the right manner
-       Selection xsel_cache;
-
-       /// needed for the toggling (cursor position on last selection made)
-       LyXCursor last_sel_cursor;
-       /// needed for toggling the selection in screen.C
-       LyXCursor toggle_cursor;
-       /// needed for toggling the selection in screen.C
-       LyXCursor toggle_end_cursor;
-
+       
        /// need the selection cursor:
        void setSelection();
        ///
@@ -636,6 +593,13 @@ public:
 
        /// return true if this is owned by an inset.
        bool isInInset() const;
+
+private:
+       /** Cursor related data.
+         Later this variable has to be removed. There should be now internal
+         cursor in a text */
+       ///
+       ///TextCursor cursor_;
 };
 
 /// return the default height of a row in pixels, considering font zoom
Index: textcursor.h
===================================================================
RCS file: textcursor.h
diff -N textcursor.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ textcursor.h        27 Jun 2003 10:31:19 -0000
@@ -0,0 +1,74 @@
+// -*- C++ -*-
+/**
+ * \file cursor.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author unknown
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include "lyxcursor.h"
+
+#ifndef TEXTCURSOR_H
+#define TEXTCURSOR_H
+
+/** The cursor.
+       Later this variable has to be removed. There should be now internal
+       cursor in a text (and thus not in a buffer). By keeping this it is
+       (I think) impossible to have several views with the same buffer, but
+       the cursor placed at different places.
+       [later]
+       Since the LyXText now has been moved from Buffer to BufferView
+       it should not be absolutely needed to move the cursor...
+       [even later]
+       It should neverthe less to keep classes and intedependencies small 
+       */
+
+// The structure that keeps track of the selections set.
+struct Selection {
+       Selection()
+               : set_(false), mark_(false)
+               {}
+       bool set() const {
+               return set_;
+       }
+       void set(bool s) {
+               set_ = s;
+       }
+       bool mark() const {
+               return mark_;
+       }
+       void mark(bool m) {
+               mark_ = m;
+       }
+       LyXCursor cursor; // temporary cursor to hold a cursor position
+                               // until setSelection is called!
+       LyXCursor start;  // start of a REAL selection
+       LyXCursor end;    // end of a REAL selection
+private:
+       bool set_; // former selection
+       bool mark_; // former mark_set
+
+};
+
+struct TextCursor {
+       // actual cursor position
+       LyXCursor cursor;
+
+       Selection selection;
+       // this is used to handle XSelection events in the right manner
+       Selection xsel_cache;
+
+       /// needed for the toggling (cursor position on last selection made)
+       LyXCursor last_sel_cursor;
+       /// needed for toggling the selection in screen.C
+       LyXCursor toggle_cursor;
+       /// needed for toggling the selection in screen.C
+       LyXCursor toggle_end_cursor;
+};
+
+#endif
Index: undo_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/undo_funcs.C,v
retrieving revision 1.72
diff -u -p -r1.72 undo_funcs.C
--- undo_funcs.C        5 Jun 2003 12:16:06 -0000       1.72
+++ undo_funcs.C        27 Jun 2003 10:31:19 -0000
@@ -344,6 +344,12 @@ bool textRedo(BufferView * bv)
 }
 
 
+void setUndo(BufferView * bv, Undo::undo_kind kind)
+{
+       setUndo(bv, kind, bv->text->cursor.par());
+}
+
+
 void setUndo(BufferView * bv, Undo::undo_kind kind,
             ParagraphList::iterator first)
 {
Index: undo_funcs.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/undo_funcs.h,v
retrieving revision 1.7
diff -u -p -r1.7 undo_funcs.h
--- undo_funcs.h        23 May 2003 10:33:39 -0000      1.7
+++ undo_funcs.h        27 Jun 2003 10:31:19 -0000
@@ -33,6 +33,8 @@ void setUndo(BufferView *, Undo::undo_ki
                    ParagraphList::iterator first, ParagraphList::iterator last);
 void setUndo(BufferView *, Undo::undo_kind kind,
                    ParagraphList::iterator first);
+// set undo for containing paragraph
+void setUndo(BufferView *, Undo::undo_kind kind);
 /// FIXME
 void setCursorParUndo(BufferView *);
 
Index: insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.290
diff -u -p -r1.290 insettabular.C
--- insets/insettabular.C       16 Jun 2003 11:49:32 -0000      1.290
+++ insets/insettabular.C       27 Jun 2003 10:31:20 -0000
@@ -1047,7 +1047,7 @@ Inset::RESULT InsetTabular::localDispatc
                        break;
                // no break here!
        case LFUN_DELETE:
-               setUndo(bv, Undo::DELETE, bv->text->cursor.par());
+               setUndo(bv, Undo::DELETE);
                cutSelection(bv->buffer()->params);
                updateLocal(bv, INIT);
                break;
@@ -1130,7 +1130,7 @@ Inset::RESULT InsetTabular::localDispatc
        }
        case LFUN_PASTE:
                if (hasPasteBuffer()) {
-                       setUndo(bv, Undo::INSERT, bv->text->cursor.par());
+                       setUndo(bv, Undo::INSERT);
                        pasteSelection(bv);
                        updateLocal(bv, INIT);
                        break;
@@ -1624,7 +1624,7 @@ void InsetTabular::setFont(BufferView * 
                setSelection(0, tabular.getNumberOfCells() - 1);
        }
        if (hasSelection()) {
-               setUndo(bv, Undo::EDIT, bv->text->cursor.par());
+               setUndo(bv, Undo::EDIT);
                bool const frozen = undo_frozen;
                if (!frozen)
                        freezeUndo();
@@ -1746,7 +1746,7 @@ void InsetTabular::tabularFeatures(Buffe
                sel_col_start = sel_col_end = tabular.column_of_cell(actcell);
                sel_row_start = sel_row_end = tabular.row_of_cell(actcell);
        }
-       setUndo(bv, Undo::FINISH, bv->text->cursor.par());
+       setUndo(bv, Undo::FINISH);
 
        int row =  tabular.row_of_cell(actcell);
        int column = tabular.column_of_cell(actcell);
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.413
diff -u -p -r1.413 insettext.C
--- insets/insettext.C  27 Jun 2003 09:44:26 -0000      1.413
+++ insets/insettext.C  27 Jun 2003 10:31:20 -0000
@@ -87,42 +87,33 @@ void InsetText::saveLyXTextState(LyXText
                        break;
        }
 
-       if (it != end && t->cursor.pos() <= it->size()) {
-               sstate.lpar = t->cursor.par();
-               sstate.pos = t->cursor.pos();
-               sstate.boundary = t->cursor.boundary();
-               sstate.selstartpar = t->selection.start.par();
-               sstate.selstartpos = t->selection.start.pos();
-               sstate.selstartboundary = t->selection.start.boundary();
-               sstate.selendpar = t->selection.end.par();
-               sstate.selendpos = t->selection.end.pos();
-               sstate.selendboundary = t->selection.end.boundary();
-               sstate.selection = t->selection.set();
-               sstate.mark_set = t->selection.mark();
-       } else {
-               sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
-       }
+       if (it != end && t->cursor.pos() <= it->size())
+               sstate = *t; // slicing intended
+       else
+               sstate.cursor.par(end);
 }
 
 
 void InsetText::restoreLyXTextState(LyXText * t) const
 {
-       if (sstate.lpar == const_cast<ParagraphList&>(paragraphs).end())
+       if (sstate.cursor.par() == const_cast<ParagraphList&>(paragraphs).end())
                return;
 
        t->selection.set(true);
-       /* at this point just to avoid the DEPM when setting the cursor */
-       t->selection.mark(sstate.mark_set);
-       if (sstate.selection) {
-               t->setCursor(sstate.selstartpar, sstate.selstartpos,
-                            true, sstate.selstartboundary);
+       // at this point just to avoid the DEPM when setting the cursor 
+       t->selection.mark(sstate.selection.mark());
+       if (sstate.selection.set()) {
+               t->setCursor(sstate.selection.start.par(),
+                       sstate.selection.start.pos(),
+                       true, sstate.selection.start.boundary());
                t->selection.cursor = t->cursor;
-               t->setCursor(sstate.selendpar, sstate.selendpos,
-                            true, sstate.selendboundary);
+               t->setCursor(sstate.selection.end.par(), sstate.selection.end.pos(),
+                       true, sstate.selection.end.boundary());
                t->setSelection();
-               t->setCursor(sstate.lpar, sstate.pos);
+               t->setCursor(sstate.cursor.par(), sstate.cursor.pos());
        } else {
-               t->setCursor(sstate.lpar, sstate.pos, true, sstate.boundary);
+               t->setCursor(sstate.cursor.par(), sstate.cursor.pos(),
+                       true, sstate.cursor.boundary());
                t->selection.cursor = t->cursor;
                t->selection.set(false);
        }
@@ -189,7 +180,7 @@ void InsetText::init(InsetText const * i
        old_par = paragraphs.end();
        last_drawn_width = -1;
        cached_bview = 0;
-       sstate.lpar = paragraphs.end();
+       sstate.cursor.par(paragraphs.end());
        in_insetAllowed = false;
 }
 
@@ -2114,7 +2105,7 @@ LyXText * InsetText::getLyXText(BufferVi
                                if (locked) {
                                        saveLyXTextState(it->second.text.get());
                                } else {
-                                       sstate.lpar = 
const_cast<ParagraphList&>(paragraphs).end();
+                                       
sstate.cursor.par(const_cast<ParagraphList&>(paragraphs).end());
                                }
                        }
                        //
Index: insets/insettext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v
retrieving revision 1.168
diff -u -p -r1.168 insettext.h
--- insets/insettext.h  16 Jun 2003 11:49:34 -0000      1.168
+++ insets/insettext.h  27 Jun 2003 10:31:20 -0000
@@ -13,6 +13,7 @@
 #define INSETTEXT_H
 
 #include "updatableinset.h"
+#include "textcursor.h"
 #include "LString.h"
 #include "LColor.h"
 #include "ParagraphList.h"
@@ -372,22 +373,9 @@ private:
        mutable BufferView * cached_bview;
        ///
        mutable boost::shared_ptr<LyXText> cached_text;
-       ///
-       struct save_state {
-               ParagraphList::iterator lpar;
-               ParagraphList::iterator selstartpar;
-               ParagraphList::iterator selendpar;
-               lyx::pos_type pos;
-               lyx::pos_type selstartpos;
-               lyx::pos_type selendpos;
-               bool boundary;
-               bool selstartboundary;
-               bool selendboundary;
-               bool selection;
-               bool mark_set;
-       };
-       ///
-       mutable save_state sstate;
+
+       /// some funny 'temporarily saved state'
+       mutable TextCursor sstate;
 
        ///
        // this is needed globally so we know that we're using it actually and

Reply via email to