3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetText.h"
15 #include "insets/InsetArgument.h"
16 #include "insets/InsetLayout.h"
18 #include "buffer_funcs.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
22 #include "CompletionList.h"
23 #include "CoordCache.h"
25 #include "CutAndPaste.h"
26 #include "DispatchResult.h"
27 #include "ErrorList.h"
28 #include "FuncRequest.h"
29 #include "FuncStatus.h"
30 #include "InsetCaption.h"
31 #include "InsetList.h"
35 #include "LaTeXFeatures.h"
39 #include "MetricsInfo.h"
40 #include "output_docbook.h"
41 #include "output_latex.h"
42 #include "output_xhtml.h"
43 #include "OutputParams.h"
44 #include "output_plaintext.h"
45 #include "Paragraph.h"
46 #include "ParagraphParameters.h"
47 #include "ParIterator.h"
51 #include "TextClass.h"
53 #include "TextMetrics.h"
54 #include "TocBackend.h"
56 #include "frontends/alert.h"
57 #include "frontends/Painter.h"
59 #include "support/convert.h"
60 #include "support/debug.h"
61 #include "support/gettext.h"
62 #include "support/lstrings.h"
64 #include "support/bind.h"
65 #include "support/lassert.h"
71 using namespace lyx::support;
76 using graphics::PreviewLoader;
79 /////////////////////////////////////////////////////////////////////
81 InsetText::InsetText(Buffer * buf, UsePlain type)
82 : Inset(buf), drawFrame_(false), frame_color_(Color_insetframe),
83 text_(this, type == DefaultLayout)
88 InsetText::InsetText(InsetText const & in)
89 : Inset(in), text_(this, in.text_)
91 drawFrame_ = in.drawFrame_;
92 frame_color_ = in.frame_color_;
96 void InsetText::setBuffer(Buffer & buf)
98 ParagraphList::iterator end = paragraphs().end();
99 for (ParagraphList::iterator it = paragraphs().begin(); it != end; ++it)
101 Inset::setBuffer(buf);
105 void InsetText::setMacrocontextPositionRecursive(DocIterator const & pos)
107 text_.setMacrocontextPosition(pos);
109 ParagraphList::const_iterator pit = paragraphs().begin();
110 ParagraphList::const_iterator pend = paragraphs().end();
111 for (; pit != pend; ++pit) {
112 InsetList::const_iterator iit = pit->insetList().begin();
113 InsetList::const_iterator end = pit->insetList().end();
114 for (; iit != end; ++iit) {
115 if (InsetText * txt = iit->inset->asInsetText()) {
116 DocIterator ppos(pos);
117 ppos.push_back(CursorSlice(*txt));
118 iit->inset->asInsetText()->setMacrocontextPositionRecursive(ppos);
125 void InsetText::clear()
127 ParagraphList & pars = paragraphs();
128 LBUFERR(!pars.empty());
130 // This is a gross hack...
131 Layout const & old_layout = pars.begin()->layout();
134 pars.push_back(Paragraph());
135 pars.begin()->setInsetOwner(this);
136 pars.begin()->setLayout(old_layout);
140 Dimension const InsetText::dimension(BufferView const & bv) const
142 TextMetrics const & tm = bv.textMetrics(&text_);
143 Dimension dim = tm.dimension();
144 dim.wid += 2 * TEXT_TO_INSET_OFFSET;
145 dim.des += TEXT_TO_INSET_OFFSET;
146 dim.asc += TEXT_TO_INSET_OFFSET;
151 void InsetText::write(ostream & os) const
158 void InsetText::read(Lexer & lex)
162 // delete the initial paragraph
163 Paragraph oldpar = *paragraphs().begin();
164 paragraphs().clear();
166 lex.setContext("InsetText::read");
167 bool res = text_.read(lex, errorList, this);
170 lex.printError("Missing \\end_inset at this point. ");
173 // ensure we have at least one paragraph.
174 if (paragraphs().empty())
175 paragraphs().push_back(oldpar);
176 // Force default font, if so requested
177 // This avoids paragraphs in buffer language that would have a
178 // foreign language after a document language change, and it ensures
179 // that all new text in ERT and similar gets the "latex" language,
180 // since new text inherits the language from the last position of the
181 // existing text. As a side effect this makes us also robust against
182 // bugs in LyX that might lead to font changes in ERT in .lyx files.
187 void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
189 TextMetrics & tm = mi.base.bv->textMetrics(&text_);
191 //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
193 // Hand font through to contained lyxtext:
194 tm.font_.fontInfo() = mi.base.font;
195 mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
197 // This can happen when a layout has a left and right margin,
198 // and the view is made very narrow. We can't do better than
199 // to draw it partly out of view (bug 5890).
200 if (mi.base.textwidth < 1)
201 mi.base.textwidth = 1;
204 tm.metrics(mi, dim, mi.base.textwidth);
207 mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
208 dim.asc += TEXT_TO_INSET_OFFSET;
209 dim.des += TEXT_TO_INSET_OFFSET;
210 dim.wid += 2 * TEXT_TO_INSET_OFFSET;
214 void InsetText::draw(PainterInfo & pi, int x, int y) const
216 TextMetrics & tm = pi.base.bv->textMetrics(&text_);
218 if (drawFrame_ || pi.full_repaint) {
219 int const w = tm.width() + TEXT_TO_INSET_OFFSET;
220 int const yframe = y - TEXT_TO_INSET_OFFSET - tm.ascent();
221 int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
222 int const xframe = x + TEXT_TO_INSET_OFFSET / 2;
224 pi.pain.fillRectangle(xframe, yframe, w, h,
225 pi.backgroundColor(this));
228 pi.pain.rectangle(xframe, yframe, w, h, frameColor());
230 ColorCode const old_color = pi.background_color;
231 pi.background_color = pi.backgroundColor(this, false);
233 tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y);
235 pi.background_color = old_color;
239 void InsetText::edit(Cursor & cur, bool front, EntryDirection entry_from)
241 pit_type const pit = front ? 0 : paragraphs().size() - 1;
242 pos_type pos = front ? 0 : paragraphs().back().size();
244 // if visual information is not to be ignored, move to extreme right/left
245 if (entry_from != ENTRY_DIRECTION_IGNORE) {
246 Cursor temp_cur = cur;
247 temp_cur.pit() = pit;
248 temp_cur.pos() = pos;
249 temp_cur.posVisToRowExtremity(entry_from == ENTRY_DIRECTION_LEFT);
250 pos = temp_cur.pos();
253 text_.setCursor(cur.top(), pit, pos);
254 cur.clearSelection();
259 Inset * InsetText::editXY(Cursor & cur, int x, int y)
261 return cur.bv().textMetrics(&text_).editXY(cur, x, y);
265 void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
267 LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd);
269 // See bug #9042, for instance.
270 if (isPassThru() && lyxCode() != ARG_CODE) {
271 // Force any new text to latex_language FIXME: This
272 // should only be necessary in constructor, but new
273 // paragraphs that are created by pressing enter at
274 // the start of an existing paragraph get the buffer
275 // language and not latex_language, so we take this
276 // brute force approach.
277 cur.current_font.setLanguage(latex_language);
278 cur.real_current_font.setLanguage(latex_language);
281 switch (cmd.action()) {
283 case LFUN_CLIPBOARD_PASTE:
284 case LFUN_SELECTION_PASTE:
285 case LFUN_PRIMARY_SELECTION_PASTE:
286 text_.dispatch(cur, cmd);
287 // If we we can only store plain text, we must reset all
289 // FIXME: Change only the pasted paragraphs
293 case LFUN_INSET_DISSOLVE: {
294 bool const main_inset = &buffer().inset() == this;
295 bool const target_inset = cmd.argument().empty()
296 || cmd.getArg(0) == insetName(lyxCode());
297 bool const one_cell = nargs() == 1;
299 if (!main_inset && target_inset && one_cell) {
300 // Text::dissolveInset assumes that the cursor
301 // is inside the Inset.
302 if (&cur.inset() != this)
303 cur.pushBackward(*this);
304 cur.beginUndoGroup();
305 text_.dispatch(cur, cmd);
313 text_.dispatch(cur, cmd);
316 if (!cur.result().dispatched())
317 Inset::doDispatch(cur, cmd);
321 bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
322 FuncStatus & status) const
324 switch (cmd.action()) {
325 case LFUN_INSET_DISSOLVE: {
326 bool const main_inset = &buffer().inset() == this;
327 bool const target_inset = cmd.argument().empty()
328 || cmd.getArg(0) == insetName(lyxCode());
329 bool const one_cell = nargs() == 1;
332 status.setEnabled(!main_inset && one_cell);
336 case LFUN_ARGUMENT_INSERT: {
337 string const arg = cmd.getArg(0);
339 status.setEnabled(false);
342 if (&buffer().inset() == this || !cur.paragraph().layout().args().empty())
343 return text_.getStatus(cur, cmd, status);
345 Layout::LaTeXArgMap args = getLayout().args();
346 Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
347 if (lait != args.end()) {
348 status.setEnabled(true);
349 ParagraphList::const_iterator pit = paragraphs().begin();
350 for (; pit != paragraphs().end(); ++pit) {
351 InsetList::const_iterator it = pit->insetList().begin();
352 InsetList::const_iterator end = pit->insetList().end();
353 for (; it != end; ++it) {
354 if (it->inset->lyxCode() == ARG_CODE) {
355 InsetArgument const * ins =
356 static_cast<InsetArgument const *>(it->inset);
357 if (ins->name() == arg) {
358 // we have this already
359 status.setEnabled(false);
366 status.setEnabled(false);
371 // Dispatch only to text_ if the cursor is inside
372 // the text_. It is not for context menus (bug 5797).
374 if (cur.text() == &text_)
375 ret = text_.getStatus(cur, cmd, status);
378 ret = Inset::getStatus(cur, cmd, status);
384 void InsetText::fixParagraphsFont()
386 Font font(inherit_font, buffer().params().language);
387 font.setLanguage(latex_language);
388 ParagraphList::iterator par = paragraphs().begin();
389 ParagraphList::iterator const end = paragraphs().end();
391 if (par->isPassThru())
392 par->resetFonts(font);
393 if (!par->allowParagraphCustomization())
394 par->params().clear();
400 void InsetText::setChange(Change const & change)
402 ParagraphList::iterator pit = paragraphs().begin();
403 ParagraphList::iterator end = paragraphs().end();
404 for (; pit != end; ++pit) {
405 pit->setChange(change);
410 void InsetText::acceptChanges()
412 text_.acceptChanges();
416 void InsetText::rejectChanges()
418 text_.rejectChanges();
422 void InsetText::validate(LaTeXFeatures & features) const
424 features.useInsetLayout(getLayout());
425 for_each(paragraphs().begin(), paragraphs().end(),
426 bind(&Paragraph::validate, _1, ref(features)));
430 void InsetText::latex(otexstream & os, OutputParams const & runparams) const
432 // This implements the standard way of handling the LaTeX
433 // output of a text inset, either a command or an
434 // environment. Standard collapsable insets should not
435 // redefine this, non-standard ones may call this.
436 InsetLayout const & il = getLayout();
437 if (!il.latexname().empty()) {
438 if (il.latextype() == InsetLayout::COMMAND) {
440 if (runparams.moving_arg)
442 os << '\\' << from_utf8(il.latexname());
443 if (!il.latexargs().empty())
444 getArgs(os, runparams);
445 if (!il.latexparam().empty())
446 os << from_utf8(il.latexparam());
448 } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
453 if (runparams.lastid != -1)
454 os.texrow().start(runparams.lastid,
456 os << "\\begin{" << from_utf8(il.latexname()) << "}";
457 if (!il.latexargs().empty())
458 getArgs(os, runparams);
459 if (!il.latexparam().empty())
460 os << from_utf8(il.latexparam());
464 if (!il.latexargs().empty())
465 getArgs(os, runparams);
466 if (!il.latexparam().empty())
467 os << from_utf8(il.latexparam());
470 if (!il.leftdelim().empty())
471 os << il.leftdelim();
473 OutputParams rp = runparams;
476 if (il.isNeedProtect())
477 rp.moving_arg = true;
479 rp.par_end = paragraphs().size();
481 // Output the contents of the inset
482 latexParagraphs(buffer(), text_, os, rp);
483 runparams.encoding = rp.encoding;
485 if (!il.rightdelim().empty())
486 os << il.rightdelim();
488 if (!il.latexname().empty()) {
489 if (il.latextype() == InsetLayout::COMMAND) {
491 if (!il.postcommandargs().empty())
492 getArgs(os, runparams, true);
493 } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
494 // A comment environment doesn't need a % before \n\end
495 if (il.isDisplay() || runparams.inComment)
499 os << "\\end{" << from_utf8(il.latexname()) << "}\n";
501 os.protectSpace(true);
507 int InsetText::plaintext(odocstringstream & os,
508 OutputParams const & runparams, size_t max_length) const
510 ParagraphList::const_iterator beg = paragraphs().begin();
511 ParagraphList::const_iterator end = paragraphs().end();
512 ParagraphList::const_iterator it = beg;
513 bool ref_printed = false;
515 for (; it != end; ++it) {
518 if (runparams.linelen > 0)
521 odocstringstream oss;
522 writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed, max_length);
523 docstring const str = oss.str();
525 // FIXME: len is not computed fully correctly; in principle,
526 // we have to count the characters after the last '\n'
528 if (os.str().size() >= max_length)
536 int InsetText::docbook(odocstream & os, OutputParams const & runparams) const
538 ParagraphList::const_iterator const beg = paragraphs().begin();
541 sgml::openTag(os, getLayout().latexname(),
542 beg->getID(buffer(), runparams) + getLayout().latexparam());
544 docbookParagraphs(text_, buffer(), os, runparams);
547 sgml::closeTag(os, getLayout().latexname());
553 docstring InsetText::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
555 return insetAsXHTML(xs, runparams, WriteEverything);
560 // There are cases where we may need to close open fonts and such
561 // and then re-open them when we are done. This would be the case, e.g.,
562 // if we were otherwise about to write:
563 // <em>word <div class='foot'>footnote text.</div> emph</em>
564 // The problem isn't so much that the footnote text will get emphasized:
565 // we can handle that with CSS. The problem is that this is invalid XHTML.
566 // One solution would be to make the footnote <span>, but the problem is
567 // completely general, and so we'd have to make absolutely everything into
568 // span. What I think will work is to check if we're about to write "div" and,
569 // if so, try to close fonts, etc.
570 // There are probably limits to how well we can do here, though, and we will
571 // have to rely upon users not putting footnotes inside noun-type insets.
572 docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
573 XHTMLOptions opts) const
575 // we will always want to output all our paragraphs when we are
577 OutputParams runparams = rp;
578 runparams.par_begin = 0;
579 runparams.par_end = text().paragraphs().size();
582 xhtmlParagraphs(text_, buffer(), xs, runparams);
586 InsetLayout const & il = getLayout();
587 if (opts & WriteOuterTag)
588 xs << html::StartTag(il.htmltag(), il.htmlattr());
590 if ((opts & WriteLabel) && !il.counter().empty()) {
591 BufferParams const & bp = buffer().masterBuffer()->params();
592 Counters & cntrs = bp.documentClass().counters();
593 cntrs.step(il.counter(), OutputUpdate);
594 // FIXME: translate to paragraph language
595 if (!il.htmllabel().empty()) {
596 docstring const lbl =
597 cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
598 // FIXME is this check necessary?
600 xs << html::StartTag(il.htmllabeltag(), il.htmllabelattr());
602 xs << html::EndTag(il.htmllabeltag());
607 if (opts & WriteInnerTag)
608 xs << html::StartTag(il.htmlinnertag(), il.htmlinnerattr());
610 // we will eventually lose information about the containing inset
611 if (!il.isMultiPar() || opts == JustText)
612 runparams.html_make_pars = false;
614 runparams.pass_thru = true;
616 xhtmlParagraphs(text_, buffer(), xs, runparams);
618 if (opts & WriteInnerTag)
619 xs << html::EndTag(il.htmlinnertag());
621 if (opts & WriteOuterTag)
622 xs << html::EndTag(il.htmltag());
627 void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
628 bool const post) const
630 OutputParams runparams = runparams_in;
631 runparams.local_font =
632 ¶graphs()[0].getFirstFontSettings(buffer().masterBuffer()->params());
634 runparams.pass_thru = true;
636 latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().postcommandargs(), "post:");
638 latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs());
642 void InsetText::cursorPos(BufferView const & bv,
643 CursorSlice const & sl, bool boundary, int & x, int & y) const
645 x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET;
646 y = bv.textMetrics(&text_).cursorY(sl, boundary);
650 void InsetText::setText(docstring const & data, Font const & font, bool trackChanges)
653 Paragraph & first = paragraphs().front();
654 for (unsigned int i = 0; i < data.length(); ++i)
655 first.insertChar(i, data[i], font, trackChanges);
659 void InsetText::setAutoBreakRows(bool flag)
661 if (flag == text_.autoBreakRows_)
664 text_.autoBreakRows_ = flag;
668 // remove previously existing newlines
669 ParagraphList::iterator it = paragraphs().begin();
670 ParagraphList::iterator end = paragraphs().end();
671 for (; it != end; ++it)
672 for (int i = 0; i < it->size(); ++i)
673 if (it->isNewline(i))
674 // do not track the change, because the user
675 // is not allowed to revert/reject it
676 it->eraseChar(i, false);
680 void InsetText::setDrawFrame(bool flag)
686 ColorCode InsetText::frameColor() const
692 void InsetText::setFrameColor(ColorCode col)
698 void InsetText::appendParagraphs(ParagraphList & plist)
700 // There is little we can do here to keep track of changes.
701 // As of 2006/10/20, appendParagraphs is used exclusively by
702 // LyXTabular::setMultiColumn. In this context, the paragraph break
703 // is lost irreversibly and the appended text doesn't really change
705 ParagraphList & pl = paragraphs();
707 ParagraphList::iterator pit = plist.begin();
708 ParagraphList::iterator ins = pl.insert(pl.end(), *pit);
710 mergeParagraph(buffer().params(), pl,
711 distance(pl.begin(), ins) - 1);
713 for_each(pit, plist.end(),
714 bind(&ParagraphList::push_back, ref(pl), _1));
718 void InsetText::addPreview(DocIterator const & text_inset_pos,
719 PreviewLoader & loader) const
721 ParagraphList::const_iterator pit = paragraphs().begin();
722 ParagraphList::const_iterator pend = paragraphs().end();
725 DocIterator inset_pos = text_inset_pos;
726 inset_pos.push_back(CursorSlice(*const_cast<InsetText *>(this)));
728 for (; pit != pend; ++pit, ++pidx) {
729 InsetList::const_iterator it = pit->insetList().begin();
730 InsetList::const_iterator end = pit->insetList().end();
731 inset_pos.pit() = pidx;
732 for (; it != end; ++it) {
733 inset_pos.pos() = it->pos;
734 it->inset->addPreview(inset_pos, loader);
740 ParagraphList const & InsetText::paragraphs() const
742 return text_.paragraphs();
746 ParagraphList & InsetText::paragraphs()
748 return text_.paragraphs();
752 bool InsetText::insetAllowed(InsetCode code) const
755 // Arguments are also allowed in PassThru insets
759 return !isPassThru();
764 void InsetText::updateBuffer(ParIterator const & it, UpdateType utype)
766 ParIterator it2 = it;
768 LASSERT(&it2.inset() == this && it2.pit() == 0, return);
769 if (producesOutput()) {
770 InsetLayout const & il = getLayout();
771 bool const save_layouts = utype == OutputUpdate && il.htmlisblock();
772 Counters & cnt = buffer().masterBuffer()->params().documentClass().counters();
774 // LYXERR0("Entering " << name());
775 cnt.clearLastLayout();
776 // FIXME cnt.saveLastCounter()?
778 buffer().updateBuffer(it2, utype);
780 // LYXERR0("Exiting " << name());
781 cnt.restoreLastLayout();
782 // FIXME cnt.restoreLastCounter()?
785 DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
786 // Note that we do not need to call:
787 // tclass.counters().clearLastLayout()
788 // since we are saving and restoring the existing counters, etc.
789 Counters const savecnt = tclass.counters();
790 tclass.counters().reset();
791 buffer().updateBuffer(it2, utype);
792 tclass.counters() = savecnt;
797 void InsetText::toString(odocstream & os) const
799 os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
803 void InsetText::forOutliner(docstring & os, size_t maxlen) const
805 if (!getLayout().isInToc())
807 text().forOutliner(os, maxlen, false);
811 void InsetText::addToToc(DocIterator const & cdit, bool output_active) const
813 DocIterator dit = cdit;
814 dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
815 iterateForToc(dit, output_active);
819 void InsetText::iterateForToc(DocIterator const & cdit, bool output_active) const
821 DocIterator dit = cdit;
822 Toc & toc = buffer().tocBackend().toc("tableofcontents");
824 BufferParams const & bufparams = buffer_->params();
825 int const min_toclevel = bufparams.documentClass().min_toclevel();
826 // we really should have done this before we got here, but it
827 // can't hurt too much to do it again
828 bool const doing_output = output_active && producesOutput();
830 // For each paragraph, traverse its insets and let them add
832 ParagraphList const & pars = paragraphs();
833 pit_type pend = paragraphs().size();
834 for (pit_type pit = 0; pit != pend; ++pit) {
835 Paragraph const & par = pars[pit];
837 // if we find an optarg, we'll save it for use later.
838 InsetText const * arginset = 0;
839 InsetList::const_iterator it = par.insetList().begin();
840 InsetList::const_iterator end = par.insetList().end();
841 for (; it != end; ++it) {
842 Inset & inset = *it->inset;
844 //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
845 inset.addToToc(dit, doing_output);
846 if (inset.lyxCode() == ARG_CODE)
847 arginset = inset.asInsetText();
849 // now the toc entry for the paragraph
850 int const toclevel = text().getTocLevel(pit);
851 if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
852 // insert this into the table of contents
854 int const length = doing_output ? INT_MAX : TOC_ENTRY_LENGTH;
856 tocstring = par.labelString();
857 if (!tocstring.empty())
859 arginset->text().forOutliner(tocstring, length);
861 par.forOutliner(tocstring, length);
863 toc.push_back(TocItem(dit, toclevel - min_toclevel,
864 tocstring, doing_output, tocstring));
867 // And now the list of changes.
868 par.addChangesToToc(dit, buffer(), doing_output);
873 bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
875 if (buffer().isClean())
876 return Inset::notifyCursorLeaves(old, cur);
878 // find text inset in old cursor
879 Cursor insetCur = old;
880 int scriptSlice = insetCur.find(this);
881 // we can try to continue here. returning true means
882 // the cursor is "now" invalid. which it was.
883 LASSERT(scriptSlice != -1, return true);
884 insetCur.cutOff(scriptSlice);
885 LASSERT(&insetCur.inset() == this, return true);
887 // update the old paragraph's words
888 insetCur.paragraph().updateWords();
890 return Inset::notifyCursorLeaves(old, cur);
894 bool InsetText::completionSupported(Cursor const & cur) const
896 //LASSERT(&cur.bv().cursor().inset() == this, return false);
897 return text_.completionSupported(cur);
901 bool InsetText::inlineCompletionSupported(Cursor const & cur) const
903 return completionSupported(cur);
907 bool InsetText::automaticInlineCompletion() const
909 return lyxrc.completion_inline_text;
913 bool InsetText::automaticPopupCompletion() const
915 return lyxrc.completion_popup_text;
919 bool InsetText::showCompletionCursor() const
921 return lyxrc.completion_cursor_text;
925 CompletionList const * InsetText::createCompletionList(Cursor const & cur) const
927 return completionSupported(cur) ? text_.createCompletionList(cur) : 0;
931 docstring InsetText::completionPrefix(Cursor const & cur) const
933 if (!completionSupported(cur))
935 return text_.completionPrefix(cur);
939 bool InsetText::insertCompletion(Cursor & cur, docstring const & s,
942 if (!completionSupported(cur))
945 return text_.insertCompletion(cur, s, finished);
949 void InsetText::completionPosAndDim(Cursor const & cur, int & x, int & y,
950 Dimension & dim) const
952 TextMetrics const & tm = cur.bv().textMetrics(&text_);
953 tm.completionPosAndDim(cur, x, y, dim);
957 string InsetText::contextMenu(BufferView const &, int, int) const
959 string context_menu = contextMenuName();
960 if (context_menu != InsetText::contextMenuName())
961 context_menu += ";" + InsetText::contextMenuName();
966 string InsetText::contextMenuName() const
968 return "context-edit";
972 docstring InsetText::toolTipText(docstring prefix,
973 size_t numlines, size_t len) const
975 size_t const max_length = numlines * len;
976 OutputParams rp(&buffer().params().encoding());
977 rp.for_tooltip = true;
978 odocstringstream oss;
981 ParagraphList::const_iterator beg = paragraphs().begin();
982 ParagraphList::const_iterator end = paragraphs().end();
983 ParagraphList::const_iterator it = beg;
984 bool ref_printed = false;
987 for (; it != end; ++it) {
990 writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, max_length);
992 if (str.length() >= max_length)
995 return support::wrapParas(str, 4, len, numlines);
999 InsetCaption const * InsetText::getCaptionInset() const
1001 ParagraphList::const_iterator pit = paragraphs().begin();
1002 for (; pit != paragraphs().end(); ++pit) {
1003 InsetList::const_iterator it = pit->insetList().begin();
1004 for (; it != pit->insetList().end(); ++it) {
1005 Inset & inset = *it->inset;
1006 if (inset.lyxCode() == CAPTION_CODE) {
1007 InsetCaption const * ins =
1008 static_cast<InsetCaption const *>(it->inset);
1017 docstring InsetText::getCaptionText(OutputParams const & runparams) const
1019 InsetCaption const * ins = getCaptionInset();
1023 odocstringstream ods;
1024 ins->getCaptionAsPlaintext(ods, runparams);
1029 docstring InsetText::getCaptionHTML(OutputParams const & runparams) const
1031 InsetCaption const * ins = getCaptionInset();
1035 odocstringstream ods;
1036 XHTMLStream xs(ods);
1037 docstring def = ins->getCaptionAsHTML(xs, runparams);
1039 // should already have been escaped
1040 xs << XHTMLStream::ESCAPE_NONE << def << '\n';
1045 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2)
1047 return static_cast<InsetText::XHTMLOptions>((int)a1 | (int)a2);