]> git.lyx.org Git - features.git/commitdiff
Transfer metrics and screen related methods from Text to TextMetrics.
authorAbdelrazak Younes <younes@lyx.org>
Sun, 2 Sep 2007 11:21:33 +0000 (11:21 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 2 Sep 2007 11:21:33 +0000 (11:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19994 a592a061-630c-0410-9148-cb99ea01b6c8

src/Text.cpp
src/Text.h
src/Text2.cpp
src/Text3.cpp
src/TextMetrics.cpp
src/TextMetrics.h

index a2080170192f9739cdc5ac18c947c4b49ab0386a..4013905d6dccc6001b26bd4e029708be65ea49db 100644 (file)
@@ -810,7 +810,6 @@ void Text::rejectChanges(BufferParams const & bparams)
 }
 
 
-// Delete from cursor up to the end of the current or next word.
 void Text::deleteWordForward(Cursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
@@ -827,7 +826,6 @@ void Text::deleteWordForward(Cursor & cur)
 }
 
 
-// Delete from cursor to start of current or prior word.
 void Text::deleteWordBackward(Cursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
@@ -845,27 +843,6 @@ void Text::deleteWordBackward(Cursor & cur)
 
 
 // Kill to end of line.
-void Text::deleteLineForward(Cursor & cur)
-{
-       BOOST_ASSERT(this == cur.text());
-       if (cur.lastpos() == 0) {
-               // Paragraph is empty, so we just go to the right
-               cursorRight(cur);
-       } else {
-               cur.resetAnchor();
-               cur.selection() = true; // to avoid deletion
-               cursorEnd(cur);
-               cur.setSelection();
-               // What is this test for ??? (JMarc)
-               if (!cur.selection())
-                       deleteWordForward(cur);
-               else
-                       cutSelection(cur, true, false);
-               checkBufferStructure(cur.buffer(), cur);
-       }
-}
-
-
 void Text::changeCase(Cursor & cur, Text::TextCase action)
 {
        BOOST_ASSERT(this == cur.text());
index 88295d2ba6ca96c50417288e1dd44bc758feb6e4..f0d75fa8efedea35f08fd863f4c56847788cb9d7 100644 (file)
@@ -191,17 +191,15 @@ public:
        bool cursorLeftOneWord(Cursor & cur);
        ///
        bool cursorRightOneWord(Cursor & cur);
+       /// Delete from cursor up to the end of the current or next word.
+       void deleteWordForward(Cursor & cur);
+       /// Delete from cursor to start of current or prior word.
+       void deleteWordBackward(Cursor & cur);
        ///
        bool cursorUpParagraph(Cursor & cur);
        ///
        bool cursorDownParagraph(Cursor & cur);
        ///
-       /// FIXME: move to TextMetrics.
-       bool cursorHome(Cursor & cur);
-       ///
-       /// FIXME: move to TextMetrics.
-       bool cursorEnd(Cursor & cur);
-       ///
        bool cursorTop(Cursor & cur);
        ///
        bool cursorBottom(Cursor & cur);
@@ -331,13 +329,6 @@ private:
        bool backspacePos0(Cursor & cur);
        /// handle the case where bibitems were deleted
        bool handleBibitems(Cursor & cur);
-
-       ///
-       void deleteWordForward(Cursor & cur);
-       ///
-       void deleteWordBackward(Cursor & cur);
-       ///
-       void deleteLineForward(Cursor & cur);
        ///
        void charInserted();
        /// set 'number' font property
index 375cb15ff45a552889b7525e0d48d894af6d73a6..9fb515e1b9ee8fbd671bae386eb1529b3363a066 100644 (file)
@@ -465,40 +465,6 @@ void Text::setFont(Buffer const & buffer, CursorSlice const & begin,
 }
 
 
-// the cursor set functions have a special mechanism. When they
-// realize you left an empty paragraph, they will delete it.
-
-bool Text::cursorHome(Cursor & cur)
-{
-       BOOST_ASSERT(this == cur.text());
-       ParagraphMetrics const & pm = cur.bv().parMetrics(this, cur.pit());
-       Row const & row = pm.getRow(cur.pos(),cur.boundary());
-       return setCursor(cur, cur.pit(), row.pos());
-}
-
-
-bool Text::cursorEnd(Cursor & cur)
-{
-       BOOST_ASSERT(this == cur.text());
-       // if not on the last row of the par, put the cursor before
-       // the final space exept if I have a spanning inset or one string
-       // is so long that we force a break.
-       pos_type end = cur.textRow().endpos();
-       if (end == 0)
-               // empty text, end-1 is no valid position
-               return false;
-       bool boundary = false;
-       if (end != cur.lastpos()) {
-               if (!cur.paragraph().isLineSeparator(end-1)
-                   && !cur.paragraph().isNewline(end-1))
-                       boundary = true;
-               else
-                       --end;
-       }
-       return setCursor(cur, cur.pit(), end, true, boundary);
-}
-
-
 bool Text::cursorTop(Cursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
index 320e3b43875f862d277104f7f04ed5f67503c8e2..05495d9d3e986d74ba1ac59063a2ec728af8ef8e 100644 (file)
@@ -398,7 +398,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (cur.selection()) {
                        cutSelection(cur, true, false);
                } else
-                       deleteLineForward(cur);
+                       tm.deleteLineForward(cur);
                finishChange(cur, false);
                break;
 
@@ -516,13 +516,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_LINE_BEGIN:
        case LFUN_LINE_BEGIN_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
-               needsUpdate |= cursorHome(cur);
+               needsUpdate |= tm.cursorHome(cur);
                break;
 
        case LFUN_LINE_END:
        case LFUN_LINE_END_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
-               needsUpdate |= cursorEnd(cur);
+               needsUpdate |= tm.cursorEnd(cur);
                break;
 
        case LFUN_WORD_FORWARD:
@@ -959,9 +959,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_MOUSE_TRIPLE:
                if (cmd.button() == mouse_button::button1) {
-                       cursorHome(cur);
+                       tm.cursorHome(cur);
                        cur.resetAnchor();
-                       cursorEnd(cur);
+                       tm.cursorEnd(cur);
                        cur.setSelection();
                        bv->cursor() = cur;
                }
index e1c9c845b1252215f2118b2ae131004e4eb81782..9bde046c8edc25a659edfeba7285a1e40c166512 100644 (file)
 #include "TextMetrics.h"
 
 #include "Buffer.h"
+#include "buffer_funcs.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "bufferview_funcs.h"
 #include "Color.h"
 #include "CoordCache.h"
+#include "CutAndPaste.h"
 #include "debug.h"
 #include "FontIterator.h"
 #include "FuncRequest.h"
@@ -1400,6 +1402,61 @@ void TextMetrics::cursorNext(Cursor & cur)
 }
 
 
+// the cursor set functions have a special mechanism. When they
+// realize you left an empty paragraph, they will delete it.
+
+bool TextMetrics::cursorHome(Cursor & cur)
+{
+       BOOST_ASSERT(text_ == cur.text());
+       ParagraphMetrics const & pm = par_metrics_[cur.pit()];
+       Row const & row = pm.getRow(cur.pos(),cur.boundary());
+       return text_->setCursor(cur, cur.pit(), row.pos());
+}
+
+
+bool TextMetrics::cursorEnd(Cursor & cur)
+{
+       BOOST_ASSERT(text_ == cur.text());
+       // if not on the last row of the par, put the cursor before
+       // the final space exept if I have a spanning inset or one string
+       // is so long that we force a break.
+       pos_type end = cur.textRow().endpos();
+       if (end == 0)
+               // empty text, end-1 is no valid position
+               return false;
+       bool boundary = false;
+       if (end != cur.lastpos()) {
+               if (!cur.paragraph().isLineSeparator(end-1)
+                   && !cur.paragraph().isNewline(end-1))
+                       boundary = true;
+               else
+                       --end;
+       }
+       return text_->setCursor(cur, cur.pit(), end, true, boundary);
+}
+
+
+void TextMetrics::deleteLineForward(Cursor & cur)
+{
+       BOOST_ASSERT(text_ == cur.text());
+       if (cur.lastpos() == 0) {
+               // Paragraph is empty, so we just go to the right
+               text_->cursorRight(cur);
+       } else {
+               cur.resetAnchor();
+               cur.selection() = true; // to avoid deletion
+               cursorEnd(cur);
+               cur.setSelection();
+               // What is this test for ??? (JMarc)
+               if (!cur.selection())
+                       text_->deleteWordForward(cur);
+               else
+                       cap::cutSelection(cur, true, false);
+               checkBufferStructure(cur.buffer(), cur);
+       }
+}
+
+
 int TextMetrics::leftMargin(int max_width, pit_type pit) const
 {
        BOOST_ASSERT(pit >= 0);
index 57cf9b3f129b0b11d0bba9142c02a50cd5dbda0c..784e91fc365bcd8593e66f06609fd6e299fa5b0e 100644 (file)
@@ -174,6 +174,12 @@ public:
        void cursorPrevious(Cursor & cur);
        ///
        void cursorNext(Cursor & cur);
+       ///
+       bool cursorHome(Cursor & cur);
+       ///
+       bool cursorEnd(Cursor & cur);
+       ///
+       void deleteLineForward(Cursor & cur);
 
        /// Returns an inset if inset was hit, or 0 if not.
        /// \warning This method is not recursive! It will return the