static bool equal(DocIterator & o, DocIterator & n) { // Explicitly check for this, so we won't call // Paragraph::getChar for the last pos. bool const o_lastpos = o.pos() == o.lastpos(); bool const n_lastpos = n.pos() == n.lastpos(); if (o_lastpos || n_lastpos) return o_lastpos && n_lastpos; Paragraph const & old_par = o.text()->getPar(o.pit()); Paragraph const & new_par = n.text()->getPar(n.pit()); char_type const c_o = old_par.getChar(o.pos()); char_type const c_n = new_par.getChar(n.pos()); if (c_o != c_n) return false; if (old_par.isInset(o.pos())) { Inset const * i_o = old_par.getInset(o.pos()); Inset const * i_n = new_par.getInset(n.pos()); if (i_o && i_n) return equal(i_o, i_n); } Font fo = old_par.getFontSettings(o.buffer()->params(), o.pos()); Font fn = new_par.getFontSettings(n.buffer()->params(), n.pos()); return fo == fn; }
void InsetText::iterateForToc(DocIterator const & cdit, bool output_active) const { DocIterator dit = cdit; Toc & toc = buffer().tocBackend().toc("tableofcontents"); BufferParams const & bufparams = buffer_->params(); int const min_toclevel = bufparams.documentClass().min_toclevel(); // we really should have done this before we got here, but it // can't hurt too much to do it again bool const doing_output = output_active && producesOutput(); // For each paragraph, traverse its insets and let them add // their toc items ParagraphList const & pars = paragraphs(); pit_type pend = paragraphs().size(); for (pit_type pit = 0; pit != pend; ++pit) { Paragraph const & par = pars[pit]; dit.pit() = pit; // if we find an optarg, we'll save it for use later. InsetText const * arginset = 0; InsetList::const_iterator it = par.insetList().begin(); InsetList::const_iterator end = par.insetList().end(); for (; it != end; ++it) { Inset & inset = *it->inset; dit.pos() = it->pos; //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl; inset.addToToc(dit, doing_output); if (inset.lyxCode() == ARG_CODE) arginset = inset.asInsetText(); } // now the toc entry for the paragraph int const toclevel = text().getTocLevel(pit); if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) { // insert this into the table of contents docstring tocstring; int const length = doing_output ? INT_MAX : TOC_ENTRY_LENGTH; if (arginset) { tocstring = par.labelString(); if (!tocstring.empty()) tocstring += ' '; arginset->text().forToc(tocstring, length); } else par.forToc(tocstring, length); dit.pos() = 0; toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring, doing_output, tocstring)); } // And now the list of changes. par.addChangesToToc(dit, buffer(), doing_output); } }
void SpellcheckerWidget::Private::setSelection( DocIterator const & from, DocIterator const & to) const { BufferView * bv = gv_->documentBufferView(); DocIterator end = to; if (from.pit() != end.pit()) { // there are multiple paragraphs in selection Cursor & bvcur = bv->cursor(); bvcur.setCursor(from); bvcur.clearSelection(); bvcur.setSelection(true); bvcur.setCursor(end); bvcur.setSelection(true); } else { // FIXME LFUN // If we used a LFUN, dispatch would do all of this for us int const size = end.pos() - from.pos(); bv->putSelectionAt(from, size, false); } bv->processUpdateFlags(Update::Force | Update::FitCursor); }
void InsetText::addToToc(DocIterator const & cdit) const { DocIterator dit = cdit; dit.push_back(CursorSlice(const_cast<InsetText &>(*this))); Toc & toc = buffer().tocBackend().toc("tableofcontents"); BufferParams const & bufparams = buffer_->params(); int const min_toclevel = bufparams.documentClass().min_toclevel(); // For each paragraph, traverse its insets and let them add // their toc items ParagraphList const & pars = paragraphs(); pit_type pend = paragraphs().size(); for (pit_type pit = 0; pit != pend; ++pit) { Paragraph const & par = pars[pit]; dit.pit() = pit; // if we find an optarg, we'll save it for use later. InsetText const * arginset = 0; InsetList::const_iterator it = par.insetList().begin(); InsetList::const_iterator end = par.insetList().end(); for (; it != end; ++it) { Inset & inset = *it->inset; dit.pos() = it->pos; //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl; inset.addToToc(dit); if (inset.lyxCode() == ARG_CODE) arginset = inset.asInsetText(); } // now the toc entry for the paragraph int const toclevel = par.layout().toclevel; if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) { // insert this into the table of contents docstring tocstring; if (arginset) { tocstring = par.labelString(); if (!tocstring.empty()) tocstring += ' '; arginset->text().forToc(tocstring, TOC_ENTRY_LENGTH); } else par.forToc(tocstring, TOC_ENTRY_LENGTH); dit.pos() = 0; toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring, tocstring)); } // And now the list of changes. par.addChangesToToc(dit, buffer()); } }
void InsetText::iterateForToc(DocIterator const & cdit, bool output_active, UpdateType utype, TocBackend & backend) const { DocIterator dit = cdit; // This also ensures that any document has a table of contents shared_ptr<Toc> toc = backend.toc("tableofcontents"); BufferParams const & bufparams = buffer_->params(); int const min_toclevel = bufparams.documentClass().min_toclevel(); // we really should have done this before we got here, but it // can't hurt too much to do it again bool const doing_output = output_active && producesOutput(); // For each paragraph, // * Add a toc item for the paragraph if it is AddToToc--merging adjacent // paragraphs as needed. // * Traverse its insets and let them add their toc items // * Compute the main table of contents (this is hardcoded) // * Add the list of changes ParagraphList const & pars = paragraphs(); pit_type pend = paragraphs().size(); // Record pairs {start,end} of where a toc item was opened for a paragraph // and where it must be closed stack<pair<pit_type, pit_type>> addtotoc_stack; for (pit_type pit = 0; pit != pend; ++pit) { Paragraph const & par = pars[pit]; dit.pit() = pit; dit.pos() = 0; // Custom AddToToc in paragraph layouts (i.e. theorems) if (par.layout().addToToc() && text().isFirstInSequence(pit)) { pit_type end = openAddToTocForParagraph(pit, dit, output_active, backend); addtotoc_stack.push({pit, end}); } // If we find an InsetArgument that is supposed to provide the TOC caption, // we'll save it for use later. InsetArgument const * arginset = nullptr; for (auto const & table : par.insetList()) { dit.pos() = table.pos; table.inset->addToToc(dit, doing_output, utype, backend); if (InsetArgument const * x = table.inset->asInsetArgument()) if (x->isTocCaption()) arginset = x; } // End custom AddToToc in paragraph layouts while (!addtotoc_stack.empty() && addtotoc_stack.top().second == pit) { // execute the closing function closeAddToTocForParagraph(addtotoc_stack.top().first, addtotoc_stack.top().second, backend); addtotoc_stack.pop(); } // now the toc entry for the paragraph in the main table of contents int const toclevel = text().getTocLevel(pit); if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) { // insert this into the table of contents docstring tocstring; int const length = (doing_output && utype == OutputUpdate) ? INT_MAX : TOC_ENTRY_LENGTH; if (arginset) { tocstring = par.labelString(); if (!tocstring.empty()) tocstring += ' '; arginset->text().forOutliner(tocstring, length); } else par.forOutliner(tocstring, length); dit.pos() = 0; toc->push_back(TocItem(dit, toclevel - min_toclevel, tocstring, doing_output)); } // And now the list of changes. par.addChangesToToc(dit, buffer(), doing_output, backend); } }