]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
Rob's latest and greatest dialog tweaking.
[lyx.git] / src / text2.C
index dbb946bb37e656d052fc2e85172d6ffa13bffe3c..075fcc6a58b0a59c3ae56c4ec6a6b96a979a1d01 100644 (file)
@@ -39,6 +39,7 @@
 #include "insets/insetspecialchar.h"
 #include "insets/insettext.h"
 #include "insets/insetfloat.h"
+#include "insets/insetwrap.h"
 
 #include "support/LAssert.h"
 #include "support/textutils.h"
@@ -98,6 +99,8 @@ void LyXText::init(BufferView * bview, bool reinit)
        }
        setCursorIntern(bview, firstrow->par(), 0);
        selection.cursor = cursor;
+
+       updateCounters(bview);
 }
 
 
@@ -127,21 +130,12 @@ LyXFont const realizeFont(LyXFont const & font,
        while (par && par_depth && !tmpfont.resolved()) {
                par = par->outerHook();
                if (par) {
-#ifndef INHERIT_LANGUAGE
                        tmpfont.realize(par->layout()->font);
-#else
-                       tmpfont.realize(tclass[par->layout()]->font,
-                                       buf->params.language);
-#endif
                        par_depth = par->getDepth();
                }
        }
 
-#ifndef INHERIT_LANGUAGE
        tmpfont.realize(tclass.defaultfont());
-#else
-       tmpfont.realize(tclass.defaultfont(), buf->params.language);
-#endif
 
        return tmpfont;
 }
@@ -171,20 +165,12 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
                        LyXFont f = par->getFontSettings(buf->params, pos);
                        if (par->inInset())
                                par->inInset()->getDrawFont(f);
-#ifndef INHERIT_LANGUAGE
                        return f.realize(layout->reslabelfont);
-#else
-                       return f.realize(layout.reslabelfont, buf->params.language);
-#endif
                } else {
                        LyXFont f = par->getFontSettings(buf->params, pos);
                        if (par->inInset())
                                par->inInset()->getDrawFont(f);
-#ifndef INHERIT_LANGUAGE
                        return f.realize(layout->resfont);
-#else
-                       return f.realize(layout.resfont, buf->params.language);
-#endif
                }
        }
 
@@ -201,11 +187,8 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
        }
 
        LyXFont tmpfont = par->getFontSettings(buf->params, pos);
-#ifndef INHERIT_LANGUAGE
        tmpfont.realize(layoutfont);
-#else
-       tmpfont.realize(layoutfont, buf->params.language);
-#endif
+
        if (par->inInset())
                par->inInset()->getDrawFont(tmpfont);
 
@@ -281,20 +264,11 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
                while (!layoutfont.resolved() && tp && tp->getDepth()) {
                        tp = tp->outerHook();
                        if (tp)
-#ifndef INHERIT_LANGUAGE
                                layoutfont.realize(tp->layout()->font);
-#else
-                               layoutfont.realize(tclass[tp->layout()].font,
-                                                  buf->params.language);
-#endif
                }
        }
 
-#ifndef INHERIT_LANGUAGE
        layoutfont.realize(tclass.defaultfont());
-#else
-       layoutfont.realize(tclass.defaultfont(), buf->params.language);
-#endif
 
        // Now, reduce font against full layout font
        font.reduce(layoutfont);
@@ -383,9 +357,6 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
        // insert a new row, starting at position 0
        insertRow(row, par, 0);
 
-       // set the counters
-       setCounter(bview->buffer(), par);
-
        // and now append the whole paragraph behind the new row
        if (!row) {
                firstrow->height(0);
@@ -576,8 +547,6 @@ void  LyXText::incDepth(BufferView * bview)
        // and sel_end cursor
        cursor = selection.start;
 
-       bool anything_changed = false;
-
        while (true) {
                // NOTE: you can't change the depth of a bibliography entry
                if (cursor.par()->layout()->labeltype != LABEL_BIBLIO) {
@@ -587,7 +556,6 @@ void  LyXText::incDepth(BufferView * bview)
                                if (cursor.par()->getDepth()
                                    < prev->getMaxDepthAfter()) {
                                        cursor.par()->params().depth(cursor.par()->getDepth() + 1);
-                                       anything_changed = true;
                                }
                        }
                }
@@ -596,16 +564,6 @@ void  LyXText::incDepth(BufferView * bview)
                cursor.par(cursor.par()->next());
        }
 
-       // if nothing changed set all depth to 0
-       if (!anything_changed) {
-               cursor = selection.start;
-               while (cursor.par() != selection.end.par()) {
-                       cursor.par()->params().depth(0);
-                       cursor.par(cursor.par()->next());
-               }
-               cursor.par()->params().depth(0);
-       }
-
        redoParagraphs(bview, selection.start, endpar);
 
        // we have to reset the selection, because the
@@ -701,12 +659,8 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
                current_font = real_current_font;
                current_font.reduce(layoutfont);
                // And resolve it completely
-#ifndef INHERIT_LANGUAGE
                real_current_font.realize(layoutfont);
-#else
-               real_current_font.realize(layoutfont,
-                                         bview->buffer()->params.language);
-#endif
+
                return;
        }
 
@@ -1218,7 +1172,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                par->params().appendix(par->previous()->params().appendix());
                if (!par->params().appendix() && par->params().startOfAppendix()) {
                        par->params().appendix(true);
-                       buf->counters().reset();
+                       textclass.counters().reset();
                }
                par->enumdepth = par->previous()->enumdepth;
                par->itemdepth = par->previous()->itemdepth;
@@ -1272,7 +1226,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
 
                if (i >= 0 && i <= buf->params.secnumdepth) {
 
-                       buf->counters().step(layout->latexname());
+                       textclass.counters().step(layout->latexname());
 
                        // Is there a label? Useful for Chapter layout
                        if (!par->params().appendix()) {
@@ -1299,7 +1253,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                                        langtype = "latin";
                        }
 
-                       s << buf->counters()
+                       s << textclass.counters()
                                .numberLabel(layout->latexname(),
                                             numbertype, langtype, head);
 
@@ -1308,9 +1262,9 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                        // possible...
 
                        // reset enum counters
-                       buf->counters().reset("enum");
+                       textclass.counters().reset("enum");
                } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
-                       buf->counters().reset("enum");
+                       textclass.counters().reset("enum");
                } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
                        // FIXME
                        // Yes I know this is a really, really! bad solution
@@ -1333,16 +1287,16 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                                break;
                        }
 
-                       buf->counters().step(enumcounter);
+                       textclass.counters().step(enumcounter);
 
-                       s << buf->counters()
+                       s << textclass.counters()
                                .numberLabel(enumcounter,
                                             "enumeration", langtype);
                        par->params().labelString(s.str().c_str());
                }
        } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
-               buf->counters().step("bibitem");
-               int number = buf->counters().value("bibitem");
+               textclass.counters().step("bibitem");
+               int number = textclass.counters().value("bibitem");
                if (!par->bibkey) {
                        InsetCommandParams p("bibitem");
                        par->bibkey = new InsetBibKey(p);
@@ -1362,7 +1316,8 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                        while (tmppar && tmppar->inInset()
                               // the single '=' is intended below
                               && (in = tmppar->inInset()->owner())) {
-                               if (in->lyxCode() == Inset::FLOAT_CODE) {
+                               if (in->lyxCode() == Inset::FLOAT_CODE ||
+                                   in->lyxCode() == Inset::WRAP_CODE) {
                                        isOK = true;
                                        break;
                                } else {
@@ -1374,7 +1329,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                                Floating const & fl
                                        = textclass.floats().getType(static_cast<InsetFloat*>(in)->type());
 
-                               buf->counters().step(fl.type());
+                               textclass.counters().step(fl.type());
 
                                // Doesn't work... yet.
                                ostringstream o;
@@ -1390,17 +1345,19 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                }
                par->params().labelString(s);
 
-               // reset the enumeration counter. They are always resetted
+               // reset the enumeration counter. They are always reset
                // when there is any other layout between
+               // Just fall-through between the cases so that all
+               // enum counters deeper than enumdepth is also reset.
                switch (par->enumdepth) {
                case 0:
-                       buf->counters().reset("enumi");
+                       textclass.counters().reset("enumi");
                case 1:
-                       buf->counters().reset("enumii");
+                       textclass.counters().reset("enumii");
                case 2:
-                       buf->counters().reset("enumiii");
+                       textclass.counters().reset("enumiii");
                case 3:
-                       buf->counters().reset("enumiv");
+                       textclass.counters().reset("enumiv");
                }
        }
 }
@@ -1415,7 +1372,9 @@ void LyXText::updateCounters(BufferView * bview) const
        Row * row = firstrow;
        par = row->par();
 
-       bview->buffer()->counters().reset();
+       // CHECK if this is really needed. (Lgb)
+       bview->buffer()->params.getLyXTextClass().counters().reset();
+
        while (par) {
                while (row->par() != par)
                        row = row->next();