]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
last Friday's text*.C -> text_func shuffle
[lyx.git] / src / text2.C
index 4fef3bdb4ee855d1e086b4be3cd94ef138dfb20a..af480ff84fde7a82d352c8a840bb2ad7a0343e9c 100644 (file)
@@ -47,6 +47,8 @@
 
 #include <boost/tuple/tuple.hpp>
 
+using namespace lyx::support;
+
 using std::vector;
 using std::copy;
 using std::endl;
@@ -115,7 +117,7 @@ void LyXText::init(BufferView * bview, bool reinit)
 LyXFont const LyXText::getFont(Buffer const * buf, ParagraphList::iterator pit,
                               pos_type pos) const
 {
-       lyx::Assert(pos >= 0);
+       Assert(pos >= 0);
 
        LyXLayout_ptr const & layout = pit->layout();
 
@@ -530,7 +532,6 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
        LyXCursor tmpcursor;
        setCursor(tmpcursor, start, 0);
 
-       //redoParagraphs(tmpcursor, &(*pastend));
        redoParagraphs(tmpcursor, pastend);
 
        // We need to actually move the text->cursor. I don't
@@ -723,6 +724,14 @@ void LyXText::redoParagraphs(LyXCursor const & cur,
 
 
 void LyXText::fullRebreak()
+{
+       need_break_row = rows().begin();
+       partialRebreak();
+       setCursorIntern(cursor.par(), cursor.pos());
+}
+
+
+void LyXText::partialRebreak()
 {
        if (rows().empty()) {
                init(bv());
@@ -749,98 +758,18 @@ void LyXText::fullRebreak()
 // need the selection cursor:
 void LyXText::setSelection()
 {
-       bool const lsel = selection.set();
-
-       if (!selection.set()) {
-               last_sel_cursor = selection.cursor;
-               selection.start = selection.cursor;
-               selection.end = selection.cursor;
-       }
-
-       selection.set(true);
-
-       // first the toggling area
-       if (cursor.y() < last_sel_cursor.y()
-           || (cursor.y() == last_sel_cursor.y()
-               && cursor.x() < last_sel_cursor.x())) {
-               toggle_end_cursor = last_sel_cursor;
-               toggle_cursor = cursor;
-       } else {
-               toggle_end_cursor = cursor;
-               toggle_cursor = last_sel_cursor;
-       }
-
-       last_sel_cursor = cursor;
-
-       // and now the whole selection
-
-       if (selection.cursor.par() == cursor.par())
-               if (selection.cursor.pos() < cursor.pos()) {
-                       selection.end = cursor;
-                       selection.start = selection.cursor;
-               } else {
-                       selection.end = selection.cursor;
-                       selection.start = cursor;
-               }
-       else if (selection.cursor.y() < cursor.y() ||
-                (selection.cursor.y() == cursor.y()
-                 && selection.cursor.x() < cursor.x())) {
-               selection.end = cursor;
-               selection.start = selection.cursor;
-       }
-       else {
-               selection.end = selection.cursor;
-               selection.start = cursor;
-       }
-
-       // a selection with no contents is not a selection
-       if (selection.start.par() == selection.end.par() &&
-           selection.start.pos() == selection.end.pos())
-               selection.set(false);
+       bool const lsel = TextCursor::setSelection();
 
        if (inset_owner && (selection.set() || lsel))
                inset_owner->setUpdateStatus(bv(), InsetText::SELECTION);
 }
 
 
-string const LyXText::selectionAsString(Buffer const * buffer,
-                                       bool label) const
-{
-       if (!selection.set()) return string();
-
-       // should be const ...
-       ParagraphList::iterator startpit = selection.start.par();
-       ParagraphList::iterator endpit = selection.end.par();
-       pos_type const startpos(selection.start.pos());
-       pos_type const endpos(selection.end.pos());
-
-       if (startpit == endpit) {
-               return startpit->asString(buffer, startpos, endpos, label);
-       }
-
-       string result;
-
-       // First paragraph in selection
-       result += startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
-
-       // The paragraphs in between (if any)
-       ParagraphList::iterator pit = boost::next(startpit);
-       for (; pit != endpit; ++pit) {
-               result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
-       }
-
-       // Last paragraph in selection
-       result += endpit->asString(buffer, 0, endpos, label);
-
-       return result;
-}
-
 
 void LyXText::clearSelection()
 {
-       selection.set(false);
-       selection.mark(false);
-       last_sel_cursor = selection.end = selection.start = selection.cursor = cursor;
+       TextCursor::clearSelection();
+
        // reset this in the bv_owner!
        if (bv_owner && bv_owner->text)
                bv_owner->text->xsel_cache.set(false);
@@ -905,7 +834,7 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
        LyXCursor resetCursor = cursor;
        bool implicitSelection = (font.language() == ignore_language
                                  && font.number() == LyXFont::IGNORE)
-               ? selectWordWhenUnderCursor(WHOLE_WORD_STRICT) : false;
+               ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
 
        // Set font
        setFont(font, toggleall);
@@ -929,7 +858,8 @@ string LyXText::getStringToIndex()
        // If there is a change in the language the implicit word selection
        // is disabled.
        LyXCursor const reset_cursor = cursor;
-       bool const implicitSelection = selectWordWhenUnderCursor(PREVIOUS_WORD);
+       bool const implicitSelection =
+               selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
 
        string idxstring;
        if (!selection.set())
@@ -1201,7 +1131,7 @@ void LyXText::setCounter(Buffer const * buf, ParagraphList::iterator pit)
                                else if (in->lyxCode() == Inset::WRAP_CODE)
                                        type = static_cast<InsetWrap*>(in)->params().type;
                                else
-                                       lyx::Assert(0);
+                                       Assert(0);
 
                                Floating const & fl = textclass.floats().getType(type);
 
@@ -1640,7 +1570,7 @@ bool LyXText::setCursor(ParagraphList::iterator pit,
 void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
                        pos_type pos, bool boundary)
 {
-       lyx::Assert(pit != ownerParagraphs().end());
+       Assert(pit != ownerParagraphs().end());
 
        cur.par(pit);
        cur.pos(pos);