]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
tiny..
[lyx.git] / src / text2.C
index 839f7ce6cb1b99dbae48d73e2fcdb9f81582a40b..04d3b35de579343b146223feab67e59ef4ff1887 100644 (file)
@@ -163,9 +163,8 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
 
        LyXLayout_ptr const & layout = par->layout();
 
-       Paragraph::depth_type par_depth = par->getDepth();
        // We specialize the 95% common case:
-       if (!par_depth) {
+       if (!par->getDepth()) {
                if (layout->labeltype == LABEL_MANUAL
                    && pos < beginningOfMainBody(buf, par)) {
                        // 1% goes here
@@ -218,9 +217,7 @@ LyXFont const LyXText::getLayoutFont(Buffer const * buf, Paragraph * par) const
 {
        LyXLayout_ptr const & layout = par->layout();
 
-       Paragraph::depth_type par_depth = par->getDepth();
-
-       if (!par_depth) {
+       if (!par->getDepth()) {
                return layout->resfont;
        }
 
@@ -232,9 +229,7 @@ LyXFont const LyXText::getLabelFont(Buffer const * buf, Paragraph * par) const
 {
        LyXLayout_ptr const & layout = par->layout();
 
-       Paragraph::depth_type par_depth = par->getDepth();
-
-       if (!par_depth) {
+       if (!par->getDepth()) {
                return layout->reslabelfont;
        }
 
@@ -542,7 +537,7 @@ void LyXText::setLayout(BufferView * bview, string const & layout)
                  selection.start.pos(), false);
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos(), false);
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
        clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
@@ -619,7 +614,7 @@ void  LyXText::incDepth(BufferView * bview)
        setCursor(bview, selection.start.par(), selection.start.pos());
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
        clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos());
@@ -676,7 +671,7 @@ void  LyXText::decDepth(BufferView * bview)
                  selection.start.pos());
        selection.cursor = cursor;
        setCursor(bview, selection.end.par(), selection.end.pos());
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
        clearSelection();
        setSelection(bview);
        setCursor(bview, tmpcursor.par(), tmpcursor.pos());
@@ -883,6 +878,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
 
        if (tmprow && tmprow->next())
                setHeightOfRow(bview, tmprow->next());
+       updateCounters(bview);
 }
 
 
@@ -974,7 +970,7 @@ string const LyXText::selectionAsString(Buffer const * buffer,
        Paragraph * endpar(selection.end.par());
        pos_type const startpos(selection.start.pos());
        pos_type const endpos(selection.end.pos());
-        
+
        if (startpar == endpar) {
                return startpar->asString(buffer, startpos, endpos, label);
        }
@@ -1024,7 +1020,7 @@ void LyXText::cursorEnd(BufferView * bview) const
            || cursor.row()->next()->par() != cursor.row()->par()) {
                setCursor(bview, cursor.par(), rowLast(cursor.row()) + 1);
        } else {
-               if (cursor.par()->size() &&
+               if (!cursor.par()->empty() &&
                    (cursor.par()->getChar(rowLast(cursor.row())) == ' '
                     || cursor.par()->isNewline(rowLast(cursor.row())))) {
                        setCursor(bview, cursor.par(), rowLast(cursor.row()));
@@ -1218,21 +1214,16 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
        LyXTextClass const & textclass = buf->params.getLyXTextClass();
        LyXLayout_ptr const & layout = par->layout();
 
-       // copy the prev-counters to this one,
-       // unless this is the first paragraph
        if (par->previous()) {
 
-               par->ctrs.copy(par->previous()->ctrs, par->ctrs, "");
-               
                par->params().appendix(par->previous()->params().appendix());
                if (!par->params().appendix() && par->params().startOfAppendix()) {
                        par->params().appendix(true);
-                       par->ctrs.reset("");
+                       buf->counters().reset();
                }
                par->enumdepth = par->previous()->enumdepth;
                par->itemdepth = par->previous()->itemdepth;
        } else {
-               par->ctrs.reset("");
                par->params().appendix(par->params().startOfAppendix());
                par->enumdepth = 0;
                par->itemdepth = 0;
@@ -1258,8 +1249,6 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
            && par->previous()->getDepth() > par->getDepth()
            && layout->labeltype != LABEL_BIBLIO) {
                par->enumdepth = par->depthHook(par->getDepth())->enumdepth;
-               par->ctrs.set(par->ctrs.enums[par->enumdepth],
-                       par->depthHook(par->getDepth())->ctrs.value(par->ctrs.enums[par->enumdepth]));
        }
 
        if (!par->params().labelString().empty()) {
@@ -1273,17 +1262,17 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
        } else {
                par->setLabelWidthString(string());
        }
-   
+
        // is it a layout that has an automatic label?
        if (layout->labeltype >=  LABEL_COUNTER_CHAPTER) {
 
                int i = layout->labeltype - LABEL_COUNTER_CHAPTER;
-               string numbertype, langtype;    
+               string numbertype, langtype;
                ostringstream s;
 
                if (i >= 0 && i<= buf->params.secnumdepth) {
 
-                       par->ctrs.step(par->ctrs.sects[i]);
+                       buf->counters().step(buf->counters().sects[i]);
 
                        // Is there a label? Useful for Chapter layout
                        if (!par->params().appendix()) {
@@ -1309,29 +1298,29 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                                else
                                        langtype = "latin";
                        }
-               
-                       s << par->ctrs.numberLabel(par->ctrs.sects[i], 
+
+                       s << buf->counters().numberLabel(buf->counters().sects[i],
                                numbertype, langtype, head);
 
-                       par->params().labelString(par->params().labelString() +s.str().c_str());
+                       par->params().labelString(par->params().labelString() + s.str().c_str());
                        // We really want to remove the c_str as soon as
                        // possible...
 
                        // reset enum counters
-                       par->ctrs.reset("enum");
+                       buf->counters().reset("enum");
                } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
-                       par->ctrs.reset("enum");
+                       buf->counters().reset("enum");
                } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
-                       par->ctrs.step(par->ctrs.enums[par->enumdepth]);
+                       buf->counters().step(buf->counters().enums[par->enumdepth]);
 
-                       s << par->ctrs.numberLabel(par->ctrs.enums[par->enumdepth], 
+                       s << buf->counters().numberLabel(buf->counters().enums[par->enumdepth],
                                "enumeration", langtype);
                        par->params().labelString(s.str().c_str());
 
                }
        } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
-               par->ctrs.step("bibitem");
-               int number = par->ctrs.value("bibitem");
+               buf->counters().step("bibitem");
+               int number = buf->counters().value("bibitem");
                if (!par->bibkey) {
                        InsetCommandParams p("bibitem" );
                        par->bibkey = new InsetBibKey(p);
@@ -1345,19 +1334,30 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
 
                // the caption hack:
                if (layout->labeltype == LABEL_SENSITIVE) {
-                       bool isOK (par->inInset() && par->inInset()->owner() &&
-                                  (par->inInset()->owner()->lyxCode() == Inset::FLOAT_CODE));
+                       Paragraph * tmppar = par;
+                       Inset * in = 0;
+                       bool isOK = false;
+                       while (tmppar && tmppar->inInset()
+                              // the single '=' is intended below
+                              && (in = tmppar->inInset()->owner())) {
+                               if (in->lyxCode() == Inset::FLOAT_CODE) {
+                                       isOK = true;
+                                       break;
+                               } else {
+                                       tmppar = in->parOwner();
+                               }
+                       }
 
                        if (isOK) {
-                               InsetFloat * tmp = static_cast<InsetFloat*>(par->inInset()->owner());
                                Floating const & fl
-                                       = floatList.getType(tmp->type());
+                                       = floatList.getType(static_cast<InsetFloat*>(in)->type());
 
-                               // Why doesn't it work? -- MV
-                               par->ctrs.step(fl.name());
-                               // We should get the correct number here too.
+                               buf->counters().step(fl.name());
+                               
+                               // Doesn't work... yet.
                                ostringstream o;
-                               o << fl.name() << " " << par->ctrs.value(fl.name()) << ":";
+                               //o << fl.name() << " " << buf->counters().value(fl.name()) << ":";
+                               o << fl.name() << " #:";
                                s = o.str();
                        } else {
                                /* par->SetLayout(0);
@@ -1371,7 +1371,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                /* reset the enumeration counter. They are always resetted
                 * when there is any other layout between */
                for (int i = par->enumdepth + 1; i < 4; i++) {
-                       par->ctrs.set(par->ctrs.enums[i], 0);
+                       buf->counters().set(buf->counters().enums[i], 0);
                }
        }
 }
@@ -1379,21 +1379,18 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
 
 // Updates all counters BEHIND the row. Changed paragraphs
 // with a dynamic left margin will be rebroken.
-void LyXText::updateCounters(BufferView * bview, Row * row) const
+void LyXText::updateCounters(BufferView * bview) const
 {
        Paragraph * par;
+       
+       Row * row = firstrow;
+       par = row->par();
 
-       if (!row) {
-               row = firstrow;
-               par = row->par();
-       } else {
-               par = row->par()->next();
-       }
-
+       bview->buffer()->counters().reset();
        while (par) {
                while (row->par() != par)
                        row = row->next();
-
+               
                setCounter(bview->buffer(), par);
 
                // now check for the headline layouts. remember that they
@@ -1520,7 +1517,7 @@ void LyXText::cutSelection(BufferView * bview, bool doclear, bool realcut)
 
        setCursor(bview, cursor.par(), cursor.pos());
        selection.cursor = cursor;
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
 }
 
 
@@ -1573,7 +1570,7 @@ void LyXText::pasteSelection(BufferView * bview)
        selection.cursor = cursor;
        setCursor(bview, actpar, pos);
        setSelection(bview);
-       updateCounters(bview, cursor.row());
+       updateCounters(bview);
 }
 
 
@@ -2040,7 +2037,7 @@ namespace {
                return false;
        }
 }
+
 
 void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
                                       int x, int y) const
@@ -2055,7 +2052,7 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
        cur.x(x);
        cur.y(y + row->baseline());
        cur.row(row);
+
        if (beforeFullRowInset(*row, cur)) {
                pos_type last = rowLastPrintable(row);
                float x = getCursorX(bview, row->next(), cur.pos(), last, bound);
@@ -2281,7 +2278,7 @@ bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
        // we can't possibly have deleted a paragraph before this point
        bool deleted = false;
 
-       if ((old_cursor.par()->size() == 0
+       if ((old_cursor.par()->empty()
             || (old_cursor.par()->size() == 1
                 && old_cursor.par()->isLineSeparator(0)))) {
                // ok, we will delete anything
@@ -2319,7 +2316,7 @@ bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                         * there is another layout before */
                        if (refresh_row->next()) {
                                breakAgain(bview, refresh_row->next());
-                               updateCounters(bview, refresh_row);
+                               updateCounters(bview);
                        }
                        setHeightOfRow(bview, refresh_row);
                } else {
@@ -2352,7 +2349,7 @@ bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                           there is another layout before */
                        if (refresh_row) {
                                breakAgain(bview, refresh_row);
-                               updateCounters(bview, refresh_row->previous());
+                               updateCounters(bview);
                        }
                }
 
@@ -2378,34 +2375,12 @@ bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
 }
 
 
-void LyXText::toggleAppendix(BufferView * bview)
-{
-       Paragraph * par = cursor.par();
-       bool start = !par->params().startOfAppendix();
-
-       // ensure that we have only one start_of_appendix in this document
-       Paragraph * tmp = ownerParagraph();
-       for (; tmp; tmp = tmp->next()) {
-               tmp->params().startOfAppendix(false);
-       }
-
-       par->params().startOfAppendix(start);
-
-       // we can set the refreshing parameters now
-       status(bview, LyXText::NEED_MORE_REFRESH);
-       refresh_y = 0;
-       refresh_row = 0; // not needed for full update
-       updateCounters(bview, 0);
-       setCursor(bview, cursor.par(), cursor.pos());
-}
-
-
 Paragraph * LyXText::ownerParagraph() const
 {
        if (inset_owner) {
                return inset_owner->paragraph();
        }
-       return bv_owner->buffer()->paragraph;
+       return &*(bv_owner->buffer()->paragraphs.begin());
 }
 
 
@@ -2414,7 +2389,7 @@ void LyXText::ownerParagraph(Paragraph * p) const
        if (inset_owner) {
                inset_owner->paragraph(p);
        } else {
-               bv_owner->buffer()->paragraph = p;
+               bv_owner->buffer()->paragraphs.set(p);
        }
 }
 
@@ -2439,7 +2414,7 @@ LyXText::text_status LyXText::status() const
 void LyXText::status(BufferView * bview, LyXText::text_status st) const
 {
        LyXText * t = bview->text;
+
        // We should only go up with refreshing code so this means that if
        // we have a MORE refresh we should never set it to LITTLE if we still
        // didn't handle it (and then it will be UNCHANGED. Now as long as