]> git.lyx.org Git - features.git/commitdiff
move cursor related data fro LyXText to new strcut TextCursor
authorAndré Pönitz <poenitz@gmx.net>
Fri, 27 Jun 2003 11:53:41 +0000 (11:53 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 27 Jun 2003 11:53:41 +0000 (11:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7216 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/insettabular.C
src/insets/insettext.C
src/insets/insettext.h
src/lyxtext.h
src/textcursor.h [new file with mode: 0644]
src/undo_funcs.C
src/undo_funcs.h

index f840db1a97e721c3221eab09f3de114c0ace7063..fcca099378f160cde7c9c6eea9f8985ff908f49c 100644 (file)
@@ -1047,7 +1047,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        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::localDispatch(FuncRequest const & cmd)
        }
        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 * bv, LyXFont const & font, bool tall,
                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(BufferView * bv,
                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 9e8c0a868df617695821b44345bf6af7bb8debb5..08ae69cbea35d220d1eeec89a2619d5ed727c3b6 100644 (file)
@@ -87,42 +87,33 @@ void InsetText::saveLyXTextState(LyXText * t) const
                        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 * ins)
        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(BufferView const * lbv,
                                if (locked) {
                                        saveLyXTextState(it->second.text.get());
                                } else {
-                                       sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
+                                       sstate.cursor.par(const_cast<ParagraphList&>(paragraphs).end());
                                }
                        }
                        //
index e295000924118b54e230dc618a2d5aa2030a6bad..e3d85331c5a1e3b9d5b70553e2f3bd64ef028e29 100644 (file)
@@ -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
index ddc07bee4662fe066d3530152b956efd29bef9b8..9395bb8490620fc6536311082499681445f09414 100644 (file)
@@ -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
diff --git a/src/textcursor.h b/src/textcursor.h
new file mode 100644 (file)
index 0000000..dad6348
--- /dev/null
@@ -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 3961d795e2857d8a41c8ecb2ba7c504248628fbb..92304179a4415fbb8a22b8b603b50f4a2490bb69 100644 (file)
@@ -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 1590cb6a334ad94085d23fa196e6999ee2a3b22d..9e0cc8539807d86d4597fa16467e195323b56f2c 100644 (file)
@@ -33,6 +33,8 @@ void setUndo(BufferView *, Undo::undo_kind kind,
                    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 *);