The original intention was (a) to separate non-LyXText users from
lyxtext.h/text.C and (b) to make text*.C smaller.

With the paroffset changes we need access to the tet for cursorPar() so
(a) is not achievable anymore. (b) was not too succesful (180 lines) but
text*.C is much slimmer now for other reasons.

As there is no real difference between, say, cursorLeftOneWord() and
cursorLeft() having two different concepts to handle them is one too
much.

Interface is leaner, too.

Andre'
? .lyxtext.h.swp
? 1.diff
? 1.diff.gz
? 2.diff
? 3.diff
? ?t
? fullredraw.diff
? par-row.diff
? textcache.diff
? insets/.insetcommand.C.swp
? insets/1.diff
? mathed/cursor.diff
? support/1.diff
Index: Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/Makefile.am,v
retrieving revision 1.200
diff -u -p -r1.200 Makefile.am
--- Makefile.am 10 Nov 2003 09:06:34 -0000      1.200
+++ Makefile.am 11 Nov 2003 09:22:44 -0000
@@ -262,8 +262,6 @@ lyx_SOURCES = \
        text3.C \
        textcursor.C \
        textcursor.h \
-       text_funcs.C \
-       text_funcs.h \
        toc.C \
        toc.h \
        trans.C \
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.253
diff -u -p -r1.253 lyxtext.h
--- lyxtext.h   10 Nov 2003 18:15:53 -0000      1.253
+++ lyxtext.h   11 Nov 2003 09:22:44 -0000
@@ -439,6 +439,11 @@ public:
        std::string selectionAsString(Buffer const & buffer, bool label) const;
        ///
        double spacing(Paragraph const &) const;
+       ///
+       void cursorLeftOneWord(LyXCursor &);
+       ///
+       void cursorRightOneWord(LyXCursor &);
+
 private:
        /** Cursor related data.
          Later this variable has to be removed. There should be now internal
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.494
diff -u -p -r1.494 text.C
--- text.C      10 Nov 2003 09:06:35 -0000      1.494
+++ text.C      11 Nov 2003 09:22:44 -0000
@@ -37,7 +37,6 @@
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "rowpainter.h"
-#include "text_funcs.h"
 #include "undo.h"
 #include "vspace.h"
 #include "WordLangTuple.h"
@@ -1142,16 +1141,12 @@ void LyXText::prepareToPrint(ParagraphLi
 }
 
 
-// important for the screen
-
-
 // the cursor set functions have a special mechanism. When they
 // realize, that you left an empty paragraph, they will delete it.
-// They also delete the corresponding row
 
 void LyXText::cursorRightOneWord()
 {
-       ::cursorRightOneWord(*this, cursor, ownerParagraphs());
+       cursorRightOneWord(cursor);
        setCursor(cursorPar(), cursor.pos());
 }
 
@@ -1161,7 +1156,7 @@ void LyXText::cursorRightOneWord()
 void LyXText::cursorLeftOneWord()
 {
        LyXCursor tmpcursor = cursor;
-       ::cursorLeftOneWord(*this, tmpcursor, ownerParagraphs());
+       cursorLeftOneWord(tmpcursor);
        setCursor(getPar(tmpcursor), tmpcursor.pos());
 }
 
@@ -1170,7 +1165,7 @@ void LyXText::selectWord(word_location l
 {
        LyXCursor from = cursor;
        LyXCursor to = cursor;
-       ::getWord(*this, from, to, loc, ownerParagraphs());
+       getWord(from, to, loc);
        if (cursor != from)
                setCursor(from.par(), from.pos());
        if (to == from)
@@ -1302,7 +1297,7 @@ void LyXText::changeCase(LyXText::TextCa
                to = selection.end;
        } else {
                from = cursor;
-               ::getWord(*this, from, to, lyx::PARTIAL_WORD, ownerParagraphs());
+               getWord(from, to, lyx::PARTIAL_WORD);
                setCursor(to.par(), to.pos() + 1);
        }
 
@@ -1702,4 +1697,117 @@ bool LyXText::isLastRow(ParagraphList::i
 bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const
 {
        return row.pos() == 0 && pit == ownerParagraphs().begin();
+}
+
+
+void LyXText::cursorLeftOneWord(LyXCursor & cursor)
+{
+       // treat HFills, floats and Insets as words
+
+       ParagraphList::iterator pit = cursorPar();
+       size_t pos = cursor.pos();
+
+       while (pos &&
+              (pit->isSeparator(pos - 1) ||
+               pit->isKomma(pos - 1) ||
+               pit->isNewline(pos - 1)) &&
+              !(pit->isHfill(pos - 1) ||
+                pit->isInset(pos - 1)))
+               --pos;
+
+       if (pos &&
+           (pit->isInset(pos - 1) ||
+            pit->isHfill(pos - 1))) {
+               --pos;
+       } else if (!pos) {
+               // cast only for BSD's g++ 2.95
+               if (pit != ownerParagraphs().begin()) {
+                       --pit;
+                       pos = pit->size();
+               }
+       } else {                // Here, cur != 0
+               while (pos > 0 && pit->isWord(pos - 1))
+                       --pos;
+       }
+
+       cursor.par(parOffset(pit));
+       cursor.pos(pos);
+}
+
+
+void LyXText::cursorRightOneWord(LyXCursor & cursor)
+{
+       // treat floats, HFills and Insets as words
+       ParagraphList::iterator pit = cursorPar();
+       pos_type pos = cursor.pos();
+
+       // CHECK See comment on top of text.C
+
+       // cast only for BSD's g++ 2.95
+       if (pos == pit->size() &&
+               boost::next(pit) != ownerParagraphs().end()) {
+               ++pit;
+               pos = 0;
+       } else {
+               // Skip through initial nonword stuff.
+               while (pos < pit->size() && !pit->isWord(pos)) {
+                       ++pos;
+               }
+               // Advance through word.
+               while (pos < pit->size() && pit->isWord(pos)) {
+                       ++pos;
+               }
+       }
+
+       cursor.par(parOffset(pit));
+       cursor.pos(pos);
+}
+
+
+void LyXText::getWord(LyXCursor & from, LyXCursor & to, word_location const loc)
+{
+       ParagraphList::iterator from_par = getPar(from);
+       ParagraphList::iterator to_par = getPar(to);
+       switch (loc) {
+       case lyx::WHOLE_WORD_STRICT:
+               if (from.pos() == 0 || from.pos() == from_par->size()
+                   || from_par->isSeparator(from.pos())
+                   || from_par->isKomma(from.pos())
+                   || from_par->isNewline(from.pos())
+                   || from_par->isSeparator(from.pos() - 1)
+                   || from_par->isKomma(from.pos() - 1)
+                   || from_par->isNewline(from.pos() - 1)) {
+                       to = from;
+                       return;
+               }
+               // no break here, we go to the next
+
+       case lyx::WHOLE_WORD:
+               // Move cursor to the beginning, when not already there.
+               if (from.pos() && !from_par->isSeparator(from.pos() - 1)
+                   && !(from_par->isKomma(from.pos() - 1)
+                        || from_par->isNewline(from.pos() - 1)))
+                       cursorLeftOneWord(from);
+               break;
+       case lyx::PREVIOUS_WORD:
+               // always move the cursor to the beginning of previous word
+               cursorLeftOneWord(from);
+               break;
+       case lyx::NEXT_WORD:
+               lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
+                      << endl;
+               break;
+       case lyx::PARTIAL_WORD:
+               break;
+       }
+       to = from;
+       while (to.pos() < to_par->size()
+              && !to_par->isSeparator(to.pos())
+              && !to_par->isKomma(to.pos())
+              && !to_par->isNewline(to.pos())
+              && !to_par->isHfill(to.pos())
+              && !to_par->isInset(to.pos()))
+       {
+               to.pos(to.pos() + 1);
+       }
 }
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.498
diff -u -p -r1.498 text2.C
--- text2.C     10 Nov 2003 18:15:53 -0000      1.498
+++ text2.C     11 Nov 2003 09:22:44 -0000
@@ -399,7 +399,7 @@ void LyXText::setLayout(string const & l
 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
 {
        ParagraphList::iterator pit = cursorPar();
-       ParagraphList::iterator end = cursorPar();
+       ParagraphList::iterator end = pit;
        ParagraphList::iterator start = pit;
 
        if (selection.set()) {
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.174
diff -u -p -r1.174 text3.C
--- text3.C     10 Nov 2003 18:15:55 -0000      1.174
+++ text3.C     11 Nov 2003 09:22:44 -0000
@@ -33,7 +33,6 @@
 #include "paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
-#include "text_funcs.h"
 #include "undo.h"
 #include "vspace.h"
 
@@ -703,7 +702,7 @@ DispatchResult LyXText::dispatch(FuncReq
        case LFUN_WORDSEL: {
                LyXCursor cur1 = cursor;
                LyXCursor cur2;
-               ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
+               getWord(cur1, cur2, lyx::WHOLE_WORD);
                setCursor(cur1.par(), cur1.pos());
                clearSelection();
                setCursor(cur2.par(), cur2.pos());
@@ -1231,8 +1230,7 @@ DispatchResult LyXText::dispatch(FuncReq
                gotoInset(InsetOld::NOTE_CODE, false);
                break;
 
-       case LFUN_REFERENCE_GOTO:
-       {
+       case LFUN_REFERENCE_GOTO: {
                vector<InsetOld::Code> tmp;
                tmp.push_back(InsetOld::LABEL_CODE);
                tmp.push_back(InsetOld::REF_CODE);
Index: text_funcs.C
===================================================================
RCS file: text_funcs.C
diff -N text_funcs.C
--- text_funcs.C        9 Oct 2003 10:52:10 -0000       1.13
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,177 +0,0 @@
-/**
- * \file text_funcs.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- *
- * This file contains some utility functions for actually mutating
- * the text contents of a document
- */
-
-#include <config.h>
-
-#include "text_funcs.h"
-#include "debug.h"
-#include "lyxcursor.h"
-#include "lyxtext.h"
-#include "paragraph.h"
-
-#include <boost/next_prior.hpp>
-
-using lyx::pos_type;
-using lyx::word_location;
-
-using std::endl;
-
-
-bool transposeChars(LyXText & text, LyXCursor const & cursor)
-{
-       ParagraphList::iterator tmppit = text.cursorPar();
-       pos_type tmppos = cursor.pos();
-
-       // First decide if it is possible to transpose at all
-
-       if (tmppos == 0 || tmppos == tmppit->size())
-               return false;
-
-       if (isDeletedText(*tmppit, tmppos - 1)
-               || isDeletedText(*tmppit, tmppos))
-               return false;
-
-       unsigned char c1 = tmppit->getChar(tmppos);
-       unsigned char c2 = tmppit->getChar(tmppos - 1);
-
-       // We should have an implementation that handles insets
-       // as well, but that will have to come later. (Lgb)
-       if (c1 == Paragraph::META_INSET || c2 == Paragraph::META_INSET)
-               return false;
-
-       bool const erased = tmppit->erase(tmppos - 1, tmppos + 1);
-       size_t const ipos = erased ? tmppos - 1 : tmppos + 1;
-
-       tmppit->insertChar(ipos, c1);
-       tmppit->insertChar(ipos + 1, c2);
-       return true;
-}
-
-
-void cursorLeftOneWord(LyXText & text,
-       LyXCursor & cursor, ParagraphList const & pars)
-{
-       // treat HFills, floats and Insets as words
-
-       ParagraphList::iterator pit = text.cursorPar();
-       size_t pos = cursor.pos();
-
-       while (pos &&
-              (pit->isSeparator(pos - 1) ||
-               pit->isKomma(pos - 1) ||
-               pit->isNewline(pos - 1)) &&
-              !(pit->isHfill(pos - 1) ||
-                pit->isInset(pos - 1)))
-               --pos;
-
-       if (pos &&
-           (pit->isInset(pos - 1) ||
-            pit->isHfill(pos - 1))) {
-               --pos;
-       } else if (!pos) {
-               // cast only for BSD's g++ 2.95
-               if (pit != const_cast<ParagraphList &>(pars).begin()) {
-                       --pit;
-                       pos = pit->size();
-               }
-       } else {                // Here, cur != 0
-               while (pos > 0 && pit->isWord(pos - 1))
-                       --pos;
-       }
-
-       cursor.par(text.parOffset(pit));
-       cursor.pos(pos);
-}
-
-
-void cursorRightOneWord(LyXText & text,
-       LyXCursor & cursor, ParagraphList const & pars)
-{
-       // treat floats, HFills and Insets as words
-       ParagraphList::iterator pit = text.cursorPar();
-       pos_type pos = cursor.pos();
-
-       // CHECK See comment on top of text.C
-
-       // cast only for BSD's g++ 2.95
-       if (pos == pit->size() &&
-               boost::next(pit) != const_cast<ParagraphList &>(pars).end()) {
-               ++pit;
-               pos = 0;
-       } else {
-               // Skip through initial nonword stuff.
-               while (pos < pit->size() && !pit->isWord(pos)) {
-                       ++pos;
-               }
-               // Advance through word.
-               while (pos < pit->size() && pit->isWord(pos)) {
-                       ++pos;
-               }
-       }
-
-       cursor.par(text.parOffset(pit));
-       cursor.pos(pos);
-}
-
-
-// Select current word. This depends on behaviour of
-// CursorLeftOneWord(), so it is patched as well.
-void getWord(LyXText & text, LyXCursor & from, LyXCursor & to,
-       word_location const loc, ParagraphList const & pars)
-{
-       ParagraphList::iterator from_par = text.getPar(from);
-       ParagraphList::iterator to_par = text.getPar(to);
-       switch (loc) {
-       case lyx::WHOLE_WORD_STRICT:
-               if (from.pos() == 0 || from.pos() == from_par->size()
-                   || from_par->isSeparator(from.pos())
-                   || from_par->isKomma(from.pos())
-                   || from_par->isNewline(from.pos())
-                   || from_par->isSeparator(from.pos() - 1)
-                   || from_par->isKomma(from.pos() - 1)
-                   || from_par->isNewline(from.pos() - 1)) {
-                       to = from;
-                       return;
-               }
-               // no break here, we go to the next
-
-       case lyx::WHOLE_WORD:
-               // Move cursor to the beginning, when not already there.
-               if (from.pos() && !from_par->isSeparator(from.pos() - 1)
-                   && !(from_par->isKomma(from.pos() - 1)
-                        || from_par->isNewline(from.pos() - 1)))
-                       cursorLeftOneWord(text, from, pars);
-               break;
-       case lyx::PREVIOUS_WORD:
-               // always move the cursor to the beginning of previous word
-               cursorLeftOneWord(text, from, pars);
-               break;
-       case lyx::NEXT_WORD:
-               lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
-                      << endl;
-               break;
-       case lyx::PARTIAL_WORD:
-               break;
-       }
-       to = from;
-       while (to.pos() < to_par->size()
-              && !to_par->isSeparator(to.pos())
-              && !to_par->isKomma(to.pos())
-              && !to_par->isNewline(to.pos())
-              && !to_par->isHfill(to.pos())
-              && !to_par->isInset(to.pos()))
-       {
-               to.pos(to.pos() + 1);
-       }
-}
Index: text_funcs.h
===================================================================
RCS file: text_funcs.h
diff -N text_funcs.h
--- text_funcs.h        9 Oct 2003 10:52:10 -0000       1.6
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,41 +0,0 @@
-// -*- C++ -*-
-/**
- * \file text_funcs.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- *
- * This file contains some utility functions for actually mutating
- * the text contents of a document
- */
-
-#ifndef TEXT_FUNCS_H
-#define TEXT_FUNCS_H
-
-#include "ParagraphList_fwd.h"
-#include "support/types.h"
-
-class LyXCursor;
-class LyXText;
-
-
-// do no use LyXText or BufferView here
-
-
-///
-bool transposeChars(LyXText &, LyXCursor const & cursor);
-///
-void cursorLeftOneWord(LyXText &, LyXCursor &, ParagraphList const &);
-///
-void cursorRightOneWord(LyXText &, LyXCursor &, ParagraphList const &);
-
-// Select current word. This depends on behaviour of
-// CursorLeftOneWord(), so it is patched as well.
-void getWord(LyXText &, LyXCursor & from, LyXCursor & to, lyx::word_location const 
loc,
-       ParagraphList const & pars);
-
-#endif // TEXT_FUNCS_H

Reply via email to