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 LASSERT(!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);
270 // FIXME: This code does not seem to be necessary anymore
271 // Remove for 2.1 if no counter-evidence is found.
272 if (isPassThru() && lyxCode() != ARG_CODE) {
273 // Force any new text to latex_language FIXME: This
274 // should only be necessary in constructor, but new
275 // paragraphs that are created by pressing enter at
276 // the start of an existing paragraph get the buffer
277 // language and not latex_language, so we take this
278 // brute force approach.
279 cur.current_font.setLanguage(latex_language);
280 cur.real_current_font.setLanguage(latex_language);
284 switch (cmd.action()) {
286 case LFUN_CLIPBOARD_PASTE:
287 case LFUN_SELECTION_PASTE:
288 case LFUN_PRIMARY_SELECTION_PASTE:
289 text_.dispatch(cur, cmd);
290 // If we we can only store plain text, we must reset all
292 // FIXME: Change only the pasted paragraphs
296 case LFUN_INSET_DISSOLVE: {
297 bool const main_inset = &buffer().inset() == this;
298 bool const target_inset = cmd.argument().empty()
299 || cmd.getArg(0) == insetName(lyxCode());
300 bool const one_cell = nargs() == 1;
302 if (!main_inset && target_inset && one_cell) {
303 // Text::dissolveInset assumes that the cursor
304 // is inside the Inset.
305 if (&cur.inset() != this)
306 cur.pushBackward(*this);
307 cur.beginUndoGroup();
308 text_.dispatch(cur, cmd);
316 text_.dispatch(cur, cmd);
319 if (!cur.result().dispatched())
320 Inset::doDispatch(cur, cmd);
324 bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
325 FuncStatus & status) const
327 switch (cmd.action()) {
328 case LFUN_INSET_DISSOLVE: {
329 bool const main_inset = &buffer().inset() == this;
330 bool const target_inset = cmd.argument().empty()
331 || cmd.getArg(0) == insetName(lyxCode());
332 bool const one_cell = nargs() == 1;
335 status.setEnabled(!main_inset && one_cell);
339 case LFUN_ARGUMENT_INSERT: {
340 string const arg = cmd.getArg(0);
342 status.setEnabled(false);
345 if (&buffer().inset() == this || !cur.paragraph().layout().args().empty())
346 return text_.getStatus(cur, cmd, status);
348 Layout::LaTeXArgMap args = getLayout().args();
349 Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
350 if (lait != args.end()) {
351 status.setEnabled(true);
352 ParagraphList::const_iterator pit = paragraphs().begin();
353 for (; pit != paragraphs().end(); ++pit) {
354 InsetList::const_iterator it = pit->insetList().begin();
355 InsetList::const_iterator end = pit->insetList().end();
356 for (; it != end; ++it) {
357 if (it->inset->lyxCode() == ARG_CODE) {
358 InsetArgument const * ins =
359 static_cast<InsetArgument const *>(it->inset);
360 if (ins->name() == arg) {
361 // we have this already
362 status.setEnabled(false);
369 status.setEnabled(false);
374 // Dispatch only to text_ if the cursor is inside
375 // the text_. It is not for context menus (bug 5797).
377 if (cur.text() == &text_)
378 ret = text_.getStatus(cur, cmd, status);
381 ret = Inset::getStatus(cur, cmd, status);
387 void InsetText::fixParagraphsFont()
389 Font font(inherit_font, buffer().params().language);
390 font.setLanguage(latex_language);
391 ParagraphList::iterator par = paragraphs().begin();
392 ParagraphList::iterator const end = paragraphs().end();
394 if (par->isPassThru())
395 par->resetFonts(font);
396 if (!par->allowParagraphCustomization())
397 par->params().clear();
403 void InsetText::setChange(Change const & change)
405 ParagraphList::iterator pit = paragraphs().begin();
406 ParagraphList::iterator end = paragraphs().end();
407 for (; pit != end; ++pit) {
408 pit->setChange(change);
413 void InsetText::acceptChanges()
415 text_.acceptChanges();
419 void InsetText::rejectChanges()
421 text_.rejectChanges();
425 void InsetText::validate(LaTeXFeatures & features) const
427 features.useInsetLayout(getLayout());
428 for_each(paragraphs().begin(), paragraphs().end(),
429 bind(&Paragraph::validate, _1, ref(features)));
433 void InsetText::latex(otexstream & os, OutputParams const & runparams) const
435 // This implements the standard way of handling the LaTeX
436 // output of a text inset, either a command or an
437 // environment. Standard collapsable insets should not
438 // redefine this, non-standard ones may call this.
439 InsetLayout const & il = getLayout();
440 if (!il.latexname().empty()) {
441 if (il.latextype() == InsetLayout::COMMAND) {
443 if (runparams.moving_arg)
445 os << '\\' << from_utf8(il.latexname());
446 if (!il.latexargs().empty())
447 getArgs(os, runparams);
448 if (!il.latexparam().empty())
449 os << from_utf8(il.latexparam());
451 } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
456 if (runparams.lastid != -1)
457 os.texrow().start(runparams.lastid,
459 os << "\\begin{" << from_utf8(il.latexname()) << "}";
460 if (!il.latexargs().empty())
461 getArgs(os, runparams);
462 if (!il.latexparam().empty())
463 os << from_utf8(il.latexparam());
467 if (!il.latexargs().empty())
468 getArgs(os, runparams);
469 if (!il.latexparam().empty())
470 os << from_utf8(il.latexparam());
473 if (!il.leftdelim().empty())
474 os << il.leftdelim();
476 OutputParams rp = runparams;
479 if (il.isNeedProtect())
480 rp.moving_arg = true;
482 rp.par_end = paragraphs().size();
484 // Output the contents of the inset
485 latexParagraphs(buffer(), text_, os, rp);
486 runparams.encoding = rp.encoding;
488 if (!il.rightdelim().empty())
489 os << il.rightdelim();
491 if (!il.latexname().empty()) {
492 if (il.latextype() == InsetLayout::COMMAND) {
494 if (!il.postcommandargs().empty())
495 getArgs(os, runparams, true);
496 } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
497 // A comment environment doesn't need a % before \n\end
498 if (il.isDisplay() || runparams.inComment)
502 os << "\\end{" << from_utf8(il.latexname()) << "}\n";
504 os.protectSpace(true);
510 int InsetText::plaintext(odocstringstream & os,
511 OutputParams const & runparams, size_t max_length) const
513 ParagraphList::const_iterator beg = paragraphs().begin();
514 ParagraphList::const_iterator end = paragraphs().end();
515 ParagraphList::const_iterator it = beg;
516 bool ref_printed = false;
518 for (; it != end; ++it) {
521 if (runparams.linelen > 0)
524 odocstringstream oss;
525 writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed, max_length);
526 docstring const str = oss.str();
528 // FIXME: len is not computed fully correctly; in principle,
529 // we have to count the characters after the last '\n'
531 if (os.str().size() >= max_length)
539 int InsetText::docbook(odocstream & os, OutputParams const & runparams) const
541 ParagraphList::const_iterator const beg = paragraphs().begin();
544 sgml::openTag(os, getLayout().latexname(),
545 beg->getID(buffer(), runparams) + getLayout().latexparam());
547 docbookParagraphs(text_, buffer(), os, runparams);
550 sgml::closeTag(os, getLayout().latexname());
556 docstring InsetText::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
558 return insetAsXHTML(xs, runparams, WriteEverything);
563 // There are cases where we may need to close open fonts and such
564 // and then re-open them when we are done. This would be the case, e.g.,
565 // if we were otherwise about to write:
566 // <em>word <div class='foot'>footnote text.</div> emph</em>
567 // The problem isn't so much that the footnote text will get emphasized:
568 // we can handle that with CSS. The problem is that this is invalid XHTML.
569 // One solution would be to make the footnote <span>, but the problem is
570 // completely general, and so we'd have to make absolutely everything into
571 // span. What I think will work is to check if we're about to write "div" and,
572 // if so, try to close fonts, etc.
573 // There are probably limits to how well we can do here, though, and we will
574 // have to rely upon users not putting footnotes inside noun-type insets.
575 docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
576 XHTMLOptions opts) const
578 // we will always want to output all our paragraphs when we are
580 OutputParams runparams = rp;
581 runparams.par_begin = 0;
582 runparams.par_end = text().paragraphs().size();
585 xhtmlParagraphs(text_, buffer(), xs, runparams);
589 InsetLayout const & il = getLayout();
590 if (opts & WriteOuterTag)
591 xs << html::StartTag(il.htmltag(), il.htmlattr());
593 if ((opts & WriteLabel) && !il.counter().empty()) {
594 BufferParams const & bp = buffer().masterBuffer()->params();
595 Counters & cntrs = bp.documentClass().counters();
596 cntrs.step(il.counter(), OutputUpdate);
597 // FIXME: translate to paragraph language
598 if (!il.htmllabel().empty()) {
599 docstring const lbl =
600 cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
601 // FIXME is this check necessary?
603 xs << html::StartTag(il.htmllabeltag(), il.htmllabelattr());
605 xs << html::EndTag(il.htmllabeltag());
610 if (opts & WriteInnerTag)
611 xs << html::StartTag(il.htmlinnertag(), il.htmlinnerattr());
613 // we will eventually lose information about the containing inset
614 if (!il.isMultiPar() || opts == JustText)
615 runparams.html_make_pars = false;
617 runparams.pass_thru = true;
619 xhtmlParagraphs(text_, buffer(), xs, runparams);
621 if (opts & WriteInnerTag)
622 xs << html::EndTag(il.htmlinnertag());
624 if (opts & WriteOuterTag)
625 xs << html::EndTag(il.htmltag());
630 void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
631 bool const post) const
633 OutputParams runparams = runparams_in;
634 runparams.local_font =
635 ¶graphs()[0].getFirstFontSettings(buffer().masterBuffer()->params());
637 runparams.pass_thru = true;
639 latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().postcommandargs(), "post:");
641 latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs());
645 void InsetText::cursorPos(BufferView const & bv,
646 CursorSlice const & sl, bool boundary, int & x, int & y) const
648 x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET;
649 y = bv.textMetrics(&text_).cursorY(sl, boundary);
653 void InsetText::setText(docstring const & data, Font const & font, bool trackChanges)
656 Paragraph & first = paragraphs().front();
657 for (unsigned int i = 0; i < data.length(); ++i)
658 first.insertChar(i, data[i], font, trackChanges);
662 void InsetText::setAutoBreakRows(bool flag)
664 if (flag == text_.autoBreakRows_)
667 text_.autoBreakRows_ = flag;
671 // remove previously existing newlines
672 ParagraphList::iterator it = paragraphs().begin();
673 ParagraphList::iterator end = paragraphs().end();
674 for (; it != end; ++it)
675 for (int i = 0; i < it->size(); ++i)
676 if (it->isNewline(i))
677 // do not track the change, because the user
678 // is not allowed to revert/reject it
679 it->eraseChar(i, false);
683 void InsetText::setDrawFrame(bool flag)
689 ColorCode InsetText::frameColor() const
695 void InsetText::setFrameColor(ColorCode col)
701 void InsetText::appendParagraphs(ParagraphList & plist)
703 // There is little we can do here to keep track of changes.
704 // As of 2006/10/20, appendParagraphs is used exclusively by
705 // LyXTabular::setMultiColumn. In this context, the paragraph break
706 // is lost irreversibly and the appended text doesn't really change
708 ParagraphList & pl = paragraphs();
710 ParagraphList::iterator pit = plist.begin();
711 ParagraphList::iterator ins = pl.insert(pl.end(), *pit);
713 mergeParagraph(buffer().params(), pl,
714 distance(pl.begin(), ins) - 1);
716 for_each(pit, plist.end(),
717 bind(&ParagraphList::push_back, ref(pl), _1));
721 void InsetText::addPreview(DocIterator const & text_inset_pos,
722 PreviewLoader & loader) const
724 ParagraphList::const_iterator pit = paragraphs().begin();
725 ParagraphList::const_iterator pend = paragraphs().end();
728 DocIterator inset_pos = text_inset_pos;
729 inset_pos.push_back(CursorSlice(*const_cast<InsetText *>(this)));
731 for (; pit != pend; ++pit, ++pidx) {
732 InsetList::const_iterator it = pit->insetList().begin();
733 InsetList::const_iterator end = pit->insetList().end();
734 inset_pos.pit() = pidx;
735 for (; it != end; ++it) {
736 inset_pos.pos() = it->pos;
737 it->inset->addPreview(inset_pos, loader);
743 ParagraphList const & InsetText::paragraphs() const
745 return text_.paragraphs();
749 ParagraphList & InsetText::paragraphs()
751 return text_.paragraphs();
755 bool InsetText::insetAllowed(InsetCode code) const
758 // Arguments are also allowed in PassThru insets
762 return !isPassThru();
767 void InsetText::updateBuffer(ParIterator const & it, UpdateType utype)
769 ParIterator it2 = it;
771 LASSERT(&it2.inset() == this && it2.pit() == 0, return);
772 if (producesOutput()) {
773 InsetLayout const & il = getLayout();
774 bool const save_layouts = utype == OutputUpdate && il.htmlisblock();
775 Counters & cnt = buffer().masterBuffer()->params().documentClass().counters();
777 // LYXERR0("Entering " << name());
778 cnt.clearLastLayout();
779 // FIXME cnt.saveLastCounter()?
781 buffer().updateBuffer(it2, utype);
783 // LYXERR0("Exiting " << name());
784 cnt.restoreLastLayout();
785 // FIXME cnt.restoreLastCounter()?
788 DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
789 // Note that we do not need to call:
790 // tclass.counters().clearLastLayout()
791 // since we are saving and restoring the existing counters, etc.
792 Counters const savecnt = tclass.counters();
793 tclass.counters().reset();
794 buffer().updateBuffer(it2, utype);
795 tclass.counters() = savecnt;
800 void InsetText::toString(odocstream & os) const
802 os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
806 void InsetText::forToc(docstring & os, size_t maxlen) const
808 if (!getLayout().isInToc())
810 text().forToc(os, maxlen, false);
814 void InsetText::addToToc(DocIterator const & cdit, bool output_active) const
816 DocIterator dit = cdit;
817 dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
818 Toc & toc = buffer().tocBackend().toc("tableofcontents");
820 BufferParams const & bufparams = buffer_->params();
821 int const min_toclevel = bufparams.documentClass().min_toclevel();
822 // we really should have done this before we got here, but it
823 // can't hurt too much to do it again
824 bool const doing_output = output_active && producesOutput();
826 // For each paragraph, traverse its insets and let them add
828 ParagraphList const & pars = paragraphs();
829 pit_type pend = paragraphs().size();
830 for (pit_type pit = 0; pit != pend; ++pit) {
831 Paragraph const & par = pars[pit];
833 // if we find an optarg, we'll save it for use later.
834 InsetText const * arginset = 0;
835 InsetList::const_iterator it = par.insetList().begin();
836 InsetList::const_iterator end = par.insetList().end();
837 for (; it != end; ++it) {
838 Inset & inset = *it->inset;
840 //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
841 inset.addToToc(dit, doing_output);
842 if (inset.lyxCode() == ARG_CODE)
843 arginset = inset.asInsetText();
845 // now the toc entry for the paragraph
846 int const toclevel = text().getTocLevel(pit);
847 if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
848 // insert this into the table of contents
850 int const length = doing_output ? INT_MAX : TOC_ENTRY_LENGTH;
852 tocstring = par.labelString();
853 if (!tocstring.empty())
855 arginset->text().forToc(tocstring, length);
857 par.forToc(tocstring, length);
859 toc.push_back(TocItem(dit, toclevel - min_toclevel,
860 tocstring, doing_output, tocstring));
863 // And now the list of changes.
864 par.addChangesToToc(dit, buffer(), doing_output);
869 bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
871 if (buffer().isClean())
872 return Inset::notifyCursorLeaves(old, cur);
874 // find text inset in old cursor
875 Cursor insetCur = old;
876 int scriptSlice = insetCur.find(this);
877 LASSERT(scriptSlice != -1, /**/);
878 insetCur.cutOff(scriptSlice);
879 LASSERT(&insetCur.inset() == this, /**/);
881 // update the old paragraph's words
882 insetCur.paragraph().updateWords();
884 return Inset::notifyCursorLeaves(old, cur);
888 bool InsetText::completionSupported(Cursor const & cur) const
890 //LASSERT(&cur.bv().cursor().inset() != this, return false);
891 return text_.completionSupported(cur);
895 bool InsetText::inlineCompletionSupported(Cursor const & cur) const
897 return completionSupported(cur);
901 bool InsetText::automaticInlineCompletion() const
903 return lyxrc.completion_inline_text;
907 bool InsetText::automaticPopupCompletion() const
909 return lyxrc.completion_popup_text;
913 bool InsetText::showCompletionCursor() const
915 return lyxrc.completion_cursor_text;
919 CompletionList const * InsetText::createCompletionList(Cursor const & cur) const
921 return completionSupported(cur) ? text_.createCompletionList(cur) : 0;
925 docstring InsetText::completionPrefix(Cursor const & cur) const
927 if (!completionSupported(cur))
929 return text_.completionPrefix(cur);
933 bool InsetText::insertCompletion(Cursor & cur, docstring const & s,
936 if (!completionSupported(cur))
939 return text_.insertCompletion(cur, s, finished);
943 void InsetText::completionPosAndDim(Cursor const & cur, int & x, int & y,
944 Dimension & dim) const
946 TextMetrics const & tm = cur.bv().textMetrics(&text_);
947 tm.completionPosAndDim(cur, x, y, dim);
951 string InsetText::contextMenu(BufferView const &, int, int) const
953 string context_menu = contextMenuName();
954 if (context_menu != InsetText::contextMenuName())
955 context_menu += ";" + InsetText::contextMenuName();
960 string InsetText::contextMenuName() const
962 return "context-edit";
966 docstring InsetText::toolTipText(docstring prefix,
967 size_t numlines, size_t len) const
969 size_t const max_length = numlines * len;
970 OutputParams rp(&buffer().params().encoding());
971 rp.for_tooltip = true;
972 odocstringstream oss;
975 ParagraphList::const_iterator beg = paragraphs().begin();
976 ParagraphList::const_iterator end = paragraphs().end();
977 ParagraphList::const_iterator it = beg;
978 bool ref_printed = false;
981 for (; it != end; ++it) {
984 writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, max_length);
986 if (str.length() >= max_length)
989 return support::wrapParas(str, 4, len, numlines);
993 InsetCaption const * InsetText::getCaptionInset() const
995 ParagraphList::const_iterator pit = paragraphs().begin();
996 for (; pit != paragraphs().end(); ++pit) {
997 InsetList::const_iterator it = pit->insetList().begin();
998 for (; it != pit->insetList().end(); ++it) {
999 Inset & inset = *it->inset;
1000 if (inset.lyxCode() == CAPTION_CODE) {
1001 InsetCaption const * ins =
1002 static_cast<InsetCaption const *>(it->inset);
1011 docstring InsetText::getCaptionText(OutputParams const & runparams) const
1013 InsetCaption const * ins = getCaptionInset();
1017 odocstringstream ods;
1018 ins->getCaptionAsPlaintext(ods, runparams);
1023 docstring InsetText::getCaptionHTML(OutputParams const & runparams) const
1025 InsetCaption const * ins = getCaptionInset();
1029 odocstringstream ods;
1030 XHTMLStream xs(ods);
1031 docstring def = ins->getCaptionAsHTML(xs, runparams);
1033 // should already have been escaped
1034 xs << XHTMLStream::ESCAPE_NONE << def << '\n';
1039 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2)
1041 return static_cast<InsetText::XHTMLOptions>((int)a1 | (int)a2);