X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FText2.cpp;h=24a3317cf7cafcf14c7438dcd739b22574ea3d8b;hb=e1a685fcb1da65211e9eecd7ed3ac9daf7cd5f22;hp=5eedf4f3078bcf079c0844e8ec7924c8f8596f01;hpb=f35561d0557a9d8eb13072532aa130a46b0a0fe1;p=lyx.git diff --git a/src/Text2.cpp b/src/Text2.cpp index 5eedf4f307..24a3317cf7 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -33,14 +33,12 @@ #include "CutAndPaste.h" #include "DispatchResult.h" #include "ErrorList.h" -#include "FuncRequest.h" #include "Language.h" #include "Layout.h" #include "Lexer.h" -#include "LyXFunc.h" +#include "LyX.h" #include "LyXRC.h" #include "Paragraph.h" -#include "paragraph_funcs.h" #include "ParagraphParameters.h" #include "TextClass.h" #include "TextMetrics.h" @@ -85,7 +83,7 @@ FontInfo Text::layoutFont(pit_type const pit) const // now, because Inset::getLayout() will return a default-constructed // InsetLayout, and that e.g. sets the foreground color to red. So we // need to do some work to make that possible. - InsetCollapsable const * icp = pars_[pit].inInset().asInsetCollapsable(); + InsetCollapsable const * icp = owner_->asInsetCollapsable(); if (!icp) return lf; FontInfo icf = icp->getLayout().font(); @@ -95,7 +93,7 @@ FontInfo Text::layoutFont(pit_type const pit) const FontInfo font = layout.font; // Realize with the fonts of lesser depth. - //font.realize(outerFont(pit, paragraphs())); + //font.realize(outerFont(pit)); font.realize(owner_->buffer().params().getFont().fontInfo()); return font; @@ -145,7 +143,7 @@ void Text::setCharFont(pit_type pit, while (!layoutfont.resolved() && tp != pit_type(paragraphs().size()) && pars_[tp].getDepth()) { - tp = outerHook(tp, paragraphs()); + tp = outerHook(tp); if (tp != pit_type(paragraphs().size())) layoutfont.realize(pars_[tp].layout().font); } @@ -232,7 +230,7 @@ void Text::setLayout(Cursor & cur, docstring const & layout) pit_type undopit = undoSpan(end - 1); recUndo(cur, start, undopit - 1); setLayout(start, end, layout); - cur.buffer()->updateLabels(); + cur.forceBufferUpdate(); } @@ -291,7 +289,7 @@ void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type) } // this handles the counter labels, and also fixes up // depth values for follow-on (child) paragraphs - cur.buffer()->updateLabels(); + cur.forceBufferUpdate(); } @@ -358,6 +356,9 @@ void Text::setFont(BufferView const & bv, CursorSlice const & begin, Font f = tm.displayFont(pit, pos); f.update(font, language, toggleall); setCharFont(pit, pos, f, tm.font_); + // font change may change language... + // spell checker has to know that + pars_[pit].requestSpellCheck(pos); } } @@ -432,6 +433,32 @@ docstring Text::getStringToIndex(Cursor const & cur) } +void Text::setLabelWidthStringToSequence(pit_type const par_offset, + docstring const & s) +{ + pit_type offset = par_offset; + // Find first of same layout in sequence + while (!isFirstInSequence(offset)) { + offset = depthHook(offset, pars_[offset].getDepth()); + } + + // now apply label width string to every par + // in sequence + pit_type const end = pars_.size(); + depth_type const depth = pars_[offset].getDepth(); + Layout const & layout = pars_[offset].layout(); + for (pit_type pit = offset; pit != end; ++pit) { + while (pars_[pit].getDepth() > depth) + ++pit; + if (pars_[pit].getDepth() < depth) + return; + if (pars_[pit].layout() != layout) + return; + pars_[pit].setLabelWidthString(s); + } +} + + void Text::setParagraphs(Cursor & cur, docstring arg, bool merge) { LASSERT(cur.text(), /**/); @@ -453,8 +480,7 @@ void Text::setParagraphs(Cursor & cur, docstring arg, bool merge) // Do this only once for a selected range of paragraphs // of the same layout and depth. if (par.getDepth() != priordepth || par.layout() != priorlayout) - setLabelWidthStringToSequence(pit, pars_, - params.labelWidthString()); + setLabelWidthStringToSequence(pit, params.labelWidthString()); par.params().apply(params, par.layout()); priordepth = par.getDepth(); priorlayout = par.layout(); @@ -482,8 +508,8 @@ void Text::setParagraphs(Cursor & cur, ParagraphParameters const & p) // Do this only once for a selected range of paragraphs // of the same layout and depth. if (par.getDepth() != priordepth || par.layout() != priorlayout) - setLabelWidthStringToSequence(pit, pars_, - par.params().labelWidthString()); + setLabelWidthStringToSequence(pit, + par.params().labelWidthString()); par.params().apply(p, par.layout()); priordepth = par.getDepth(); priorlayout = par.layout(); @@ -502,85 +528,6 @@ void Text::insertInset(Cursor & cur, Inset * inset) } -// needed to insert the selection -void Text::insertStringAsLines(DocIterator const & dit, docstring const & str, - Font const & font) -{ - BufferParams const & bparams = owner_->buffer().params(); - pit_type pit = dit.pit(); - pos_type pos = dit.pos(); - - // insert the string, don't insert doublespace - bool space_inserted = true; - for (docstring::const_iterator cit = str.begin(); - cit != str.end(); ++cit) { - Paragraph & par = pars_[pit]; - if (*cit == '\n') { - if (autoBreakRows_ && (!par.empty() || par.allowEmpty())) { - lyx::breakParagraph(bparams, pars_, pit, pos, - par.layout().isEnvironment()); - ++pit; - pos = 0; - space_inserted = true; - } else { - continue; - } - // do not insert consecutive spaces if !free_spacing - } else if ((*cit == ' ' || *cit == '\t') && - space_inserted && !par.isFreeSpacing()) { - continue; - } else if (*cit == '\t') { - if (!par.isFreeSpacing()) { - // tabs are like spaces here - par.insertChar(pos, ' ', font, bparams.trackChanges); - ++pos; - space_inserted = true; - } else { - par.insertChar(pos, *cit, font, bparams.trackChanges); - ++pos; - space_inserted = true; - } - } else if (!isPrintable(*cit)) { - // Ignore unprintables - continue; - } else { - // just insert the character - par.insertChar(pos, *cit, font, bparams.trackChanges); - ++pos; - space_inserted = (*cit == ' '); - } - } -} - - -// turn double CR to single CR, others are converted into one -// blank. Then insertStringAsLines is called -void Text::insertStringAsParagraphs(DocIterator const & dit, docstring const & str, - Font const & font) -{ - docstring linestr = str; - bool newline_inserted = false; - - for (string::size_type i = 0, siz = linestr.size(); i < siz; ++i) { - if (linestr[i] == '\n') { - if (newline_inserted) { - // we know that \r will be ignored by - // insertStringAsLines. Of course, it is a dirty - // trick, but it works... - linestr[i - 1] = '\r'; - linestr[i] = '\n'; - } else { - linestr[i] = ' '; - newline_inserted = true; - } - } else if (isPrintable(linestr[i])) { - newline_inserted = false; - } - } - insertStringAsLines(dit, linestr, font); -} - - bool Text::setCursor(Cursor & cur, pit_type par, pos_type pos, bool setfont, bool boundary) { @@ -603,12 +550,12 @@ void Text::setCursor(CursorSlice & cur, pit_type par, pos_type pos) // None of these should happen, but we're scaredy-cats if (pos < 0) { - lyxerr << "dont like -1" << endl; + lyxerr << "don't like -1" << endl; LASSERT(false, /**/); } if (pos > para.size()) { - lyxerr << "dont like 1, pos: " << pos + lyxerr << "don't like 1, pos: " << pos << " size: " << para.size() << " par: " << par << endl; LASSERT(false, /**/); @@ -673,7 +620,7 @@ bool Text::checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool mo bool Text::cursorBackward(Cursor & cur) { // Tell BufferView to test for FitCursor in any case! - cur.updateFlags(Update::FitCursor); + cur.screenUpdateFlags(Update::FitCursor); // not at paragraph start? if (cur.pos() > 0) { @@ -741,7 +688,7 @@ bool Text::cursorVisRight(Cursor & cur, bool skip_inset) bool Text::cursorForward(Cursor & cur) { // Tell BufferView to test for FitCursor in any case! - cur.updateFlags(Update::FitCursor); + cur.screenUpdateFlags(Update::FitCursor); // not at paragraph end? if (cur.pos() != cur.lastpos()) { @@ -972,8 +919,9 @@ void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool tra } } - // don't delete anything if this is the only remaining paragraph within the given range - // note: Text::acceptOrRejectChanges() sets the cursor to 'first' after calling DEPM + // don't delete anything if this is the only remaining paragraph + // within the given range. Note: Text::acceptOrRejectChanges() + // sets the cursor to 'first' after calling DEPM if (first == last) continue;