]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
Revert 23154.
[lyx.git] / src / Text3.cpp
index d5c1051080f85566edc0938071a51a744abfd385..5f2abc8847b562b08cf56af7319b30c2575ed222 100644 (file)
@@ -219,10 +219,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
        InsetText * insetText = dynamic_cast<InsetText *>(inset);
        if (insetText && !insetText->allowMultiPar() || cur.lastpit() == 0) {
                // reset first par to default
-               LayoutPtr const layout = insetText->useEmptyLayout()
-                       ? bparams.getTextClass().emptyLayout()
-                       : bparams.getTextClass().defaultLayout();
-               cur.text()->paragraphs().begin()->layout(layout);
+               cur.text()->paragraphs().begin()
+                       ->setEmptyOrDefaultLayout(bparams.getTextClass());
                cur.pos() = 0;
                cur.pit() = 0;
                // Merge multiple paragraphs -- hack
@@ -268,10 +266,7 @@ static void outline(OutlineOp mode, Cursor & cur)
        ParagraphList::iterator finish = start;
        ParagraphList::iterator end = pars.end();
 
-       TextClass::const_iterator lit =
-               buf.params().getTextClass().begin();
-       TextClass::const_iterator const lend =
-               buf.params().getTextClass().end();
+       TextClass const & tc = buf.params().getTextClass();
 
        int const thistoclevel = start->layout()->toclevel;
        int toclevel;
@@ -346,20 +341,22 @@ static void outline(OutlineOp mode, Cursor & cur)
                }
                case OutlineIn:
                        buf.undo().recordUndo(cur);
-                       for (; lit != lend; ++lit) {
-                               if ((*lit)->toclevel == thistoclevel + 1 &&
-                                   start->layout()->labeltype == (*lit)->labeltype) {
-                                       start->layout((*lit));
+                       for (size_t i = 0; i != tc.layoutCount(); ++i) {
+                               LayoutPtr const & lt = tc.layout(i);
+                               if (lt->toclevel == thistoclevel + 1 &&
+                                   start->layout()->labeltype == lt->labeltype) {
+                                       start->setLayout(lt);
                                        break;
                                }
                        }
                        break;
                case OutlineOut:
                        buf.undo().recordUndo(cur);
-                       for (; lit != lend; ++lit) {
-                               if ((*lit)->toclevel == thistoclevel - 1 &&
-                                   start->layout()->labeltype == (*lit)->labeltype) {
-                                       start->layout((*lit));
+                       for (size_t i = 0; i != tc.layoutCount(); ++i) {
+                               LayoutPtr const & lt = tc.layout(i);
+                               if (lt->toclevel == thistoclevel - 1 &&
+                                   start->layout()->labeltype == lt->labeltype) {
+                                       start->setLayout(lt);
                                        break;
                                }
                        }
@@ -374,7 +371,7 @@ void Text::number(Cursor & cur)
 {
        FontInfo font = ignore_font;
        font.setNumber(FONT_TOGGLE);
-       toggleAndShow(cur, this, Font(font));
+       toggleAndShow(cur, this, Font(font, ignore_language));
 }
 
 
@@ -388,14 +385,17 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 {
        LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd);
 
+       BufferView * bv = &cur.bv();
+       TextMetrics & tm = bv->textMetrics(this);
+       if (!tm.has(cur.pit()))
+               lyx::dispatch(FuncRequest(LFUN_SCREEN_RECENTER));
+
        // FIXME: We use the update flag to indicates wether a singlePar or a
        // full screen update is needed. We reset it here but shall we restore it
        // at the end?
        cur.noUpdate();
 
        BOOST_ASSERT(cur.text() == this);
-       BufferView * bv = &cur.bv();
-       TextMetrics & tm = cur.bv().textMetrics(this);
        CursorSlice oldTopSlice = cur.top();
        bool oldBoundary = cur.boundary();
        bool sel = cur.selection();
@@ -406,10 +406,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        // Signals that a full-screen update is required
        bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action,
                LyXAction::NoUpdate) || singleParUpdate);
-       // Remember the old paragraph metric (_outer_ paragraph!)
-       ParagraphMetrics const & pm = cur.bv().parMetrics(
-               cur.bottom().text(), cur.bottom().pit());
-       Dimension olddim = pm.dim();
 
        switch (cmd.action) {
 
@@ -591,10 +587,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
                bool const successful = cur.upDownInText(up, needsUpdate);
                if (successful) {
-                       // notify insets which were left and get their update flags 
-                       notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
-                       cur.fixIfBroken();
-                       
                        // redraw if you leave mathed (for the decorations)
                        needsUpdate |= cur.beforeDispatchCursor().inMathed();
                } else
@@ -1397,11 +1389,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // add a separate paragraph for the caption inset
                pars.push_back(Paragraph());
                pars.back().setInsetOwner(pars[0].inInset());
-               if (pars.back().useEmptyLayout())
-                       pars.back().layout(tclass.emptyLayout());
-               else
-                       pars.back().layout(tclass.defaultLayout());
-
+               pars.back().setEmptyOrDefaultLayout(tclass);
                int cap_pit = pars.size() - 1;
 
                // if an empty inset was created, we create an additional empty
@@ -1410,10 +1398,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (!content) {
                        pars.push_back(Paragraph());
                        pars.back().setInsetOwner(pars[0].inInset());
-                       if (pars.back().useEmptyLayout())
-                               pars.back().layout(tclass.emptyLayout());
-                       else
-                               pars.back().layout(tclass.defaultLayout());
+                       pars.back().setEmptyOrDefaultLayout(tclass);
                }
 
                // reposition the cursor to the caption
@@ -1820,16 +1805,11 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        // FIXME: the following code should go in favor of fine grained
        // update flag treatment.
        if (singleParUpdate) {
-               // Inserting characters does not change par height
-               ParagraphMetrics const & pms
-                       = cur.bv().parMetrics(cur.bottom().text(), cur.bottom().pit());
-               if (pms.dim().height() == olddim.height()) {
-                       // if so, update _only_ this paragraph
-                       cur.updateFlags(Update::SinglePar |
-                               Update::FitCursor);
-                       return;
-               }
-               needsUpdate = true;
+               // Inserting characters does not change par height in general. So, try
+               // to update _only_ this paragraph. BufferView will detect if a full
+               // metrics update is needed anyway.
+               cur.updateFlags(Update::SinglePar | Update::FitCursor);
+               return;
        }
 
        if (!needsUpdate
@@ -1966,11 +1946,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_FLEX_INSERT: {
                code = FLEX_CODE;
                string s = cmd.getArg(0);
-               InsetLayout il =  cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
-               if (il.lyxtype != "charstyle" &&
-                   il.lyxtype != "custom" &&
-                   il.lyxtype != "element" &&
-                   il.lyxtype != "standard")
+               InsetLayout il =  cur.buffer().params().getTextClass().insetLayout(from_utf8(s));
+               if (il.lyxtype() != "charstyle" &&
+                   il.lyxtype() != "custom" &&
+                   il.lyxtype() != "element" &&
+                   il.lyxtype ()!= "standard")
                        enable = false;
                break;
                }
@@ -2117,7 +2097,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                if (!cmd.argument().empty()) {
                        InsetLayout il = cur.inset().getLayout(cur.buffer().params());
                        enable = cur.inset().lyxCode() == FLEX_CODE
-                                && il.lyxtype == to_utf8(cmd.argument());
+                                && il.lyxtype() == to_utf8(cmd.argument());
                } else {
                        enable = !isMainText(cur.bv().buffer()) 
                                 && cur.inset().nargs() == 1;