]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
* Painter.h:
[lyx.git] / src / text.C
index b06eb1912eeeac64a1723670e63e7b846bc2043a..9b806455a2d52dfbd807a2df1540e7ac80a9f855 100644 (file)
@@ -41,7 +41,6 @@
 #include "lyxlex.h"
 #include "lyxrc.h"
 #include "lyxrow.h"
-#include "lyxrow_funcs.h"
 #include "metricsinfo.h"
 #include "paragraph.h"
 #include "paragraph_funcs.h"
@@ -332,7 +331,6 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
                        errorList.push_back(ErrorItem(_("Change tracking error"),
                                            bformat(_("Unknown author index for insertion: %1$d\n"), aid),
                                            par.id(), 0, par.size()));
-
                        change = Change(Change::UNCHANGED);
                } else
                        change = Change(Change::INSERTED, bp.author_map[aid], ct);
@@ -346,7 +344,6 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
                        errorList.push_back(ErrorItem(_("Change tracking error"),
                                            bformat(_("Unknown author index for deletion: %1$d\n"), aid),
                                            par.id(), 0, par.size()));
-
                        change = Change(Change::UNCHANGED);
                } else
                        change = Change(Change::DELETED, bp.author_map[aid], ct);
@@ -369,7 +366,6 @@ void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex,
        Change change(Change::UNCHANGED);
 
        while (lex.isOK()) {
-
                readParToken(buf, par, lex, token, font, change, errorList);
 
                lex.nextToken();
@@ -1102,7 +1098,7 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
        // It is better to erase the space (Dekel)
        if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos()))
                // FIXME: change tracking (MG)
-               cpar.erase(cur.pos(), cur.buffer().params().trackChanges);
+               cpar.eraseChar(cur.pos(), cur.buffer().params().trackChanges);
 
        // How should the layout for the new paragraph be?
        int preserve_layout = 0;
@@ -1138,7 +1134,7 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
 
        while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
                // FIXME: change tracking (MG)
-               pars_[next_par].erase(0, cur.buffer().params().trackChanges);
+               pars_[next_par].eraseChar(0, cur.buffer().params().trackChanges);
 
        ParIterator current_it(cur);
        ParIterator last_it(cur);
@@ -1233,10 +1229,8 @@ void LyXText::insertChar(LCursor & cur, char_type c)
                        return;
                }
                BOOST_ASSERT(cur.pos() > 0);
-               if ((par.isLineSeparator(cur.pos() - 1)
-                   || par.isNewline(cur.pos() - 1))
-                   // FIXME: change tracking (MG)
-                   && par.lookupChange(cur.pos() - 1) != Change(Change::DELETED)) {
+               if ((par.isLineSeparator(cur.pos() - 1) || par.isNewline(cur.pos() - 1))
+                   && !par.isDeleted(cur.pos() - 1)) {
                        static bool sent_space_message = false;
                        if (!sent_space_message) {
                                cur.message(_("You cannot type two spaces this way. "
@@ -1247,8 +1241,7 @@ void LyXText::insertChar(LCursor & cur, char_type c)
                }
        }
 
-       // FIXME: change tracking (MG)
-       par.insertChar(cur.pos(), c, current_font, Change(Change::INSERTED));
+       par.insertChar(cur.pos(), c, current_font, cur.buffer().params().trackChanges);
        setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
        charInserted();
 }
@@ -1466,14 +1459,14 @@ void LyXText::acceptChange(LCursor & cur)
        DocIterator it = cur.selectionBegin();
        DocIterator et = cur.selectionEnd();
        pit_type pit = it.pit();
-       Change::Type const type = pars_[pit].lookupChange(it.pos()).type;
+       bool isDeleted = pars_[pit].isDeleted(it.pos());
        for (; pit <= et.pit(); ++pit) {
                pos_type left  = ( pit == it.pit() ? it.pos() : 0 );
                pos_type right =
                    ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
-               pars_[pit].acceptChange(left, right);
+               pars_[pit].acceptChanges(left, right);
        }
-       if (type == Change::DELETED) {
+       if (isDeleted) {
                ParagraphList & plist = paragraphs();
                if (it.pit() + 1 < et.pit())
                        pars_.erase(boost::next(plist.begin(), it.pit() + 1),
@@ -1481,8 +1474,7 @@ void LyXText::acceptChange(LCursor & cur)
 
                // Paragraph merge if appropriate:
                // FIXME: change tracking (MG)
-               if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
-                       == Change(Change::DELETED)) {
+               if (pars_[it.pit()].isDeleted(pars_[it.pit()].size())) {
                        setCursorIntern(cur, it.pit() + 1, 0);
                        backspacePos0(cur);
                }
@@ -1504,22 +1496,21 @@ void LyXText::rejectChange(LCursor & cur)
        DocIterator it = cur.selectionBegin();
        DocIterator et = cur.selectionEnd();
        pit_type pit = it.pit();
-       Change::Type const type = pars_[pit].lookupChange(it.pos()).type;
+       bool isInserted = pars_[pit].isInserted(it.pos());
        for (; pit <= et.pit(); ++pit) {
                pos_type left  = ( pit == it.pit() ? it.pos() : 0 );
                pos_type right =
                    ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
-               pars_[pit].rejectChange(left, right);
+               pars_[pit].rejectChanges(left, right);
        }
-       if (type == Change::INSERTED) {
+       if (isInserted) {
                ParagraphList & plist = paragraphs();
                if (it.pit() + 1 < et.pit())
                        pars_.erase(boost::next(plist.begin(), it.pit() + 1),
                                    boost::next(plist.begin(), et.pit()));
                // Paragraph merge if appropriate:
                // FIXME: change tracking (MG)
-               if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
-                       == Change(Change::INSERTED)) {
+               if (pars_[it.pit()].isInserted(pars_[it.pit()].size())) {
                        setCursorIntern(cur, it.pit() + 1, 0);
                        backspacePos0(cur);
                }
@@ -1625,10 +1616,11 @@ void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
                                break;
                        }
                }
-#ifdef WITH_WARNINGS
-#warning changes
-#endif
-               pars_[pit].setChar(pos, c);
+
+               // FIXME: change tracking (MG)
+               // sorry but we are no longer allowed to set a single character directly
+               // we have to rewrite this method in terms of erase&insert operations
+               //pars_[pit].setChar(pos, c);
                ++pos;
        }
 }
@@ -1644,7 +1636,7 @@ bool LyXText::erase(LCursor & cur)
                setCursorIntern(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
                needsUpdate = backspace(cur);
                // FIXME: change tracking (MG)
-               if (cur.paragraph().lookupChange(cur.pos()) == Change(Change::DELETED))
+               if (cur.paragraph().isDeleted(cur.pos()))
                        cur.posRight();
        } else if (cur.pit() != cur.lastpit()) {
                LCursor scur = cur;
@@ -1658,7 +1650,7 @@ bool LyXText::erase(LCursor & cur)
                                // move forward after the paragraph break is DELETED
                                Paragraph & par = cur.paragraph();
                                // FIXME: change tracking (MG)
-                               if (par.lookupChange(par.size()) == Change(Change::DELETED))
+                               if (par.isDeleted(par.size()))
                                        setCursorIntern(cur, cur.pit() + 1, 0);
                                }
                } else {
@@ -1766,7 +1758,7 @@ bool LyXText::backspace(LCursor & cur)
                        Paragraph & par = pars_[cur.pit() - 1];
                        // Take care of a just inserted para break:
                        // FIXME: change tracking (MG)
-                       if (par.lookupChange(par.size()) != Change(Change::INSERTED)) {
+                       if (!par.isInserted(par.size())) {
                                // FIXME: change tracking (MG)
                                par.setChange(par.size(), Change(Change::DELETED));
                                setCursorIntern(cur, cur.pit() - 1, par.size());
@@ -1787,7 +1779,7 @@ bool LyXText::backspace(LCursor & cur)
                setCursorIntern(cur, cur.pit(), cur.pos() - 1,
                                false, cur.boundary());
                // FIXME: change tracking (MG)
-               cur.paragraph().erase(cur.pos(), cur.buffer().params().trackChanges);
+               cur.paragraph().eraseChar(cur.pos(), cur.buffer().params().trackChanges);
        }
 
        if (cur.pos() == cur.lastpos())
@@ -1820,7 +1812,7 @@ bool LyXText::dissolveInset(LCursor & cur) {
        spit += cur.pit();
        Buffer & b = cur.buffer();
        // FIXME: change tracking (MG)
-       cur.paragraph().erase(cur.pos(), b.params().trackChanges);
+       cur.paragraph().eraseChar(cur.pos(), b.params().trackChanges);
        if (!plist.empty()) {
                pasteParagraphList(cur, plist, b.params().textclass,
                                   b.errorList("Paste"));
@@ -2303,7 +2295,7 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
 
                x += singleWidth(par, pos, par.getChar(pos), font);
 
-               if (hfillExpansion(par, row, pos))
+               if (par.hfillExpansion(row, pos))
                        x += (pos >= body_pos) ? m.hfill : m.label_hfill;
                else if (par.isSeparator(pos) && pos >= body_pos)
                        x += m.separator;
@@ -2358,20 +2350,17 @@ string LyXText::currentState(LCursor & cur)
        Paragraph const & par = cur.paragraph();
        std::ostringstream os;
 
-       // FIXME: change tracking (MG)
-       bool const show_change = par.lookupChange(cur.pos()) != Change(Change::UNCHANGED);
-
        if (buf.params().trackChanges)
                os << "[C] ";
 
-       if (show_change) {
-               Change change = par.lookupChange(cur.pos());
+       Change change = par.lookupChange(cur.pos());
+
+       if (change.type != Change::UNCHANGED) {
                Author const & a = buf.params().authors().get(change.author);
                os << to_utf8(_("Change: ")) << a.name();
                if (!a.email().empty())
                        os << " (" << a.email() << ")";
-               if (change.changetime)
-                       os << to_utf8(_(" at ")) << ctime(&change.changetime);
+               os << to_utf8(_(" at ")) << ctime(&change.changetime);
                os << " : ";
        }
 
@@ -2448,13 +2437,11 @@ string LyXText::getPossibleLabel(LCursor & cur) const
        // for captions, we want the abbreviation of the float type
        if (layout->labeltype == LABEL_SENSITIVE) {
                // Search for the first float or wrap inset in the iterator
-               size_t i = cur.depth();
-               while (i > 0) {
-                       --i;
+               for (int i = cur.depth(); --i >= 0; ) {
                        InsetBase * const in = &cur[i].inset();
                        if (in->lyxCode() == InsetBase::FLOAT_CODE
                            || in->lyxCode() == InsetBase::WRAP_CODE) {
-                               name = in->getInsetName();
+                               name = to_utf8(in->getInsetName());
                                break;
                        }
                }