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 // Force any new text to latex_language FIXME: This
271 // should only be necessary in constructor, but new
272 // paragraphs that are created by pressing enter at
273 // the start of an existing paragraph get the buffer
274 // language and not latex_language, so we take this
275 // brute force approach.
276 cur.current_font.setLanguage(latex_language);
277 cur.real_current_font.setLanguage(latex_language);
280 switch (cmd.action()) {
282 case LFUN_CLIPBOARD_PASTE:
283 case LFUN_SELECTION_PASTE:
284 case LFUN_PRIMARY_SELECTION_PASTE:
285 text_.dispatch(cur, cmd);
286 // If we we can only store plain text, we must reset all
288 // FIXME: Change only the pasted paragraphs
292 case LFUN_INSET_DISSOLVE: {
293 bool const main_inset = &buffer().inset() == this;
294 bool const target_inset = cmd.argument().empty()
295 || cmd.getArg(0) == insetName(lyxCode());
296 bool const one_cell = nargs() == 1;
298 if (!main_inset && target_inset && one_cell) {
299 // Text::dissolveInset assumes that the cursor
300 // is inside the Inset.
301 if (&cur.inset() != this)
302 cur.pushBackward(*this);
303 cur.beginUndoGroup();
304 text_.dispatch(cur, cmd);
312 text_.dispatch(cur, cmd);
315 if (!cur.result().dispatched())
316 Inset::doDispatch(cur, cmd);
320 bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
321 FuncStatus & status) const
323 switch (cmd.action()) {
324 case LFUN_INSET_DISSOLVE: {
325 bool const main_inset = &buffer().inset() == this;
326 bool const target_inset = cmd.argument().empty()
327 || cmd.getArg(0) == insetName(lyxCode());
328 bool const one_cell = nargs() == 1;
331 status.setEnabled(!main_inset && one_cell);
335 case LFUN_ARGUMENT_INSERT: {
336 string const arg = cmd.getArg(0);
338 status.setEnabled(false);
341 if (&buffer().inset() == this || !cur.paragraph().layout().latexargs().empty()
342 || !cur.paragraph().layout().itemargs().empty())
343 return text_.getStatus(cur, cmd, status);
344 Layout::LaTeXArgMap args = getLayout().latexargs();
345 Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
346 if (lait != args.end()) {
347 status.setEnabled(true);
348 InsetList::const_iterator it = cur.paragraph().insetList().begin();
349 InsetList::const_iterator end = cur.paragraph().insetList().end();
350 for (; it != end; ++it) {
351 if (it->inset->lyxCode() == ARG_CODE) {
352 InsetArgument const * ins =
353 static_cast<InsetArgument const *>(it->inset);
354 if (ins->name() == arg) {
355 // we have this already
356 status.setEnabled(false);
362 status.setEnabled(false);
367 // Dispatch only to text_ if the cursor is inside
368 // the text_. It is not for context menus (bug 5797).
370 if (cur.text() == &text_)
371 ret = text_.getStatus(cur, cmd, status);
374 ret = Inset::getStatus(cur, cmd, status);
380 void InsetText::fixParagraphsFont()
382 Font font(inherit_font, buffer().params().language);
383 font.setLanguage(latex_language);
384 ParagraphList::iterator par = paragraphs().begin();
385 ParagraphList::iterator const end = paragraphs().end();
387 if (par->isPassThru())
388 par->resetFonts(font);
389 if (!par->allowParagraphCustomization())
390 par->params().clear();
396 void InsetText::setChange(Change const & change)
398 ParagraphList::iterator pit = paragraphs().begin();
399 ParagraphList::iterator end = paragraphs().end();
400 for (; pit != end; ++pit) {
401 pit->setChange(change);
406 void InsetText::acceptChanges()
408 text_.acceptChanges();
412 void InsetText::rejectChanges()
414 text_.rejectChanges();
418 void InsetText::validate(LaTeXFeatures & features) const
420 features.useInsetLayout(getLayout());
421 for_each(paragraphs().begin(), paragraphs().end(),
422 bind(&Paragraph::validate, _1, ref(features)));
426 void InsetText::latex(otexstream & os, OutputParams const & runparams) const
428 // This implements the standard way of handling the LaTeX
429 // output of a text inset, either a command or an
430 // environment. Standard collapsable insets should not
431 // redefine this, non-standard ones may call this.
432 InsetLayout const & il = getLayout();
433 if (!il.latexname().empty()) {
434 if (il.latextype() == InsetLayout::COMMAND) {
436 if (runparams.moving_arg)
438 os << '\\' << from_utf8(il.latexname());
439 if (!il.latexargs().empty())
440 getOptArg(os, runparams);
441 if (!il.latexparam().empty())
442 os << from_utf8(il.latexparam());
444 } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
449 if (runparams.lastid != -1)
450 os.texrow().start(runparams.lastid,
452 os << "\\begin{" << from_utf8(il.latexname()) << "}";
453 if (!il.latexargs().empty())
454 getOptArg(os, runparams);
455 if (!il.latexparam().empty())
456 os << from_utf8(il.latexparam());
460 if (!il.latexargs().empty())
461 getOptArg(os, runparams);
462 if (!il.latexparam().empty())
463 os << from_utf8(il.latexparam());
466 if (!il.leftdelim().empty())
467 os << il.leftdelim();
469 OutputParams rp = runparams;
472 if (il.isNeedProtect())
473 rp.moving_arg = true;
475 rp.par_end = paragraphs().size();
477 // Output the contents of the inset
478 latexParagraphs(buffer(), text_, os, rp);
479 runparams.encoding = rp.encoding;
481 if (!il.rightdelim().empty())
482 os << il.rightdelim();
484 if (!il.latexname().empty()) {
485 if (il.latextype() == InsetLayout::COMMAND) {
487 } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
488 // A comment environment doesn't need a % before \n\end
489 if (il.isDisplay() || runparams.inComment)
493 os << "\\end{" << from_utf8(il.latexname()) << "}\n";
495 os.protectSpace(true);
501 int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const
503 ParagraphList::const_iterator beg = paragraphs().begin();
504 ParagraphList::const_iterator end = paragraphs().end();
505 ParagraphList::const_iterator it = beg;
506 bool ref_printed = false;
508 for (; it != end; ++it) {
511 if (runparams.linelen > 0)
514 odocstringstream oss;
515 writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed);
516 docstring const str = oss.str();
518 // FIXME: len is not computed fully correctly; in principle,
519 // we have to count the characters after the last '\n'
527 int InsetText::docbook(odocstream & os, OutputParams const & runparams) const
529 ParagraphList::const_iterator const beg = paragraphs().begin();
532 sgml::openTag(os, getLayout().latexname(),
533 beg->getID(buffer(), runparams) + getLayout().latexparam());
535 docbookParagraphs(text_, buffer(), os, runparams);
538 sgml::closeTag(os, getLayout().latexname());
544 docstring InsetText::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
546 return insetAsXHTML(xs, runparams, WriteEverything);
551 // There are cases where we may need to close open fonts and such
552 // and then re-open them when we are done. This would be the case, e.g.,
553 // if we were otherwise about to write:
554 // <em>word <div class='foot'>footnote text.</div> emph</em>
555 // The problem isn't so much that the footnote text will get emphasized:
556 // we can handle that with CSS. The problem is that this is invalid XHTML.
557 // One solution would be to make the footnote <span>, but the problem is
558 // completely general, and so we'd have to make absolutely everything into
559 // span. What I think will work is to check if we're about to write "div" and,
560 // if so, try to close fonts, etc.
561 // There are probably limits to how well we can do here, though, and we will
562 // have to rely upon users not putting footnotes inside noun-type insets.
563 docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
564 XHTMLOptions opts) const
566 // we will always want to output all our paragraphs when we are
568 OutputParams runparams = rp;
569 runparams.par_begin = 0;
570 runparams.par_end = text().paragraphs().size();
573 xhtmlParagraphs(text_, buffer(), xs, runparams);
577 InsetLayout const & il = getLayout();
578 if (opts & WriteOuterTag)
579 xs << html::StartTag(il.htmltag(), il.htmlattr());
580 if ((opts & WriteLabel) && !il.counter().empty()) {
581 BufferParams const & bp = buffer().masterBuffer()->params();
582 Counters & cntrs = bp.documentClass().counters();
583 cntrs.step(il.counter(), OutputUpdate);
584 // FIXME: translate to paragraph language
585 if (!il.htmllabel().empty()) {
586 docstring const lbl =
587 cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code());
588 // FIXME is this check necessary?
590 xs << html::StartTag(il.htmllabeltag(), il.htmllabelattr());
592 xs << html::EndTag(il.htmllabeltag());
597 if (opts & WriteInnerTag)
598 xs << html::StartTag(il.htmlinnertag(), il.htmlinnerattr());
599 OutputParams ours = runparams;
600 if (!il.isMultiPar() || opts == JustText)
601 ours.html_make_pars = false;
602 xhtmlParagraphs(text_, buffer(), xs, ours);
603 if (opts & WriteInnerTag)
604 xs << html::EndTag(il.htmlinnertag());
605 if (opts & WriteOuterTag)
606 xs << html::EndTag(il.htmltag());
610 void InsetText::getOptArg(otexstream & os,
611 OutputParams const & runparams_in) const
613 OutputParams runparams = runparams_in;
614 runparams.local_font =
615 ¶graphs()[0].getFirstFontSettings(buffer().masterBuffer()->params());
617 runparams.pass_thru = true;
618 latexArgInsets(paragraphs()[0], os, runparams, getLayout().latexargs());
622 void InsetText::cursorPos(BufferView const & bv,
623 CursorSlice const & sl, bool boundary, int & x, int & y) const
625 x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET;
626 y = bv.textMetrics(&text_).cursorY(sl, boundary);
630 void InsetText::setText(docstring const & data, Font const & font, bool trackChanges)
633 Paragraph & first = paragraphs().front();
634 for (unsigned int i = 0; i < data.length(); ++i)
635 first.insertChar(i, data[i], font, trackChanges);
639 void InsetText::setAutoBreakRows(bool flag)
641 if (flag == text_.autoBreakRows_)
644 text_.autoBreakRows_ = flag;
648 // remove previously existing newlines
649 ParagraphList::iterator it = paragraphs().begin();
650 ParagraphList::iterator end = paragraphs().end();
651 for (; it != end; ++it)
652 for (int i = 0; i < it->size(); ++i)
653 if (it->isNewline(i))
654 // do not track the change, because the user
655 // is not allowed to revert/reject it
656 it->eraseChar(i, false);
660 void InsetText::setDrawFrame(bool flag)
666 ColorCode InsetText::frameColor() const
672 void InsetText::setFrameColor(ColorCode col)
678 void InsetText::appendParagraphs(ParagraphList & plist)
680 // There is little we can do here to keep track of changes.
681 // As of 2006/10/20, appendParagraphs is used exclusively by
682 // LyXTabular::setMultiColumn. In this context, the paragraph break
683 // is lost irreversibly and the appended text doesn't really change
685 ParagraphList & pl = paragraphs();
687 ParagraphList::iterator pit = plist.begin();
688 ParagraphList::iterator ins = pl.insert(pl.end(), *pit);
690 mergeParagraph(buffer().params(), pl,
691 distance(pl.begin(), ins) - 1);
693 for_each(pit, plist.end(),
694 bind(&ParagraphList::push_back, ref(pl), _1));
698 void InsetText::addPreview(DocIterator const & text_inset_pos,
699 PreviewLoader & loader) const
701 ParagraphList::const_iterator pit = paragraphs().begin();
702 ParagraphList::const_iterator pend = paragraphs().end();
705 DocIterator inset_pos = text_inset_pos;
706 inset_pos.push_back(CursorSlice(*const_cast<InsetText *>(this)));
708 for (; pit != pend; ++pit, ++pidx) {
709 InsetList::const_iterator it = pit->insetList().begin();
710 InsetList::const_iterator end = pit->insetList().end();
711 inset_pos.pit() = pidx;
712 for (; it != end; ++it) {
713 inset_pos.pos() = it->pos;
714 it->inset->addPreview(inset_pos, loader);
720 ParagraphList const & InsetText::paragraphs() const
722 return text_.paragraphs();
726 ParagraphList & InsetText::paragraphs()
728 return text_.paragraphs();
732 bool InsetText::insetAllowed(InsetCode code) const
735 // Arguments are also allowed in PassThru insets
739 return !isPassThru();
744 void InsetText::updateBuffer(ParIterator const & it, UpdateType utype)
746 ParIterator it2 = it;
748 LASSERT(&it2.inset() == this && it2.pit() == 0, return);
749 if (producesOutput()) {
750 InsetLayout const & il = getLayout();
751 bool const save_layouts = utype == OutputUpdate && il.htmlisblock();
752 Counters & cnt = buffer().masterBuffer()->params().documentClass().counters();
754 // LYXERR0("Entering " << name());
755 cnt.clearLastLayout();
756 // FIXME cnt.saveLastCounter()?
758 buffer().updateBuffer(it2, utype);
760 // LYXERR0("Exiting " << name());
761 cnt.restoreLastLayout();
762 // FIXME cnt.restoreLastCounter()?
765 DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
766 // Note that we do not need to call:
767 // tclass.counters().clearLastLayout()
768 // since we are saving and restoring the existing counters, etc.
769 Counters const savecnt = tclass.counters();
770 tclass.counters().reset();
771 buffer().updateBuffer(it2, utype);
772 tclass.counters() = savecnt;
777 void InsetText::toString(odocstream & os) const
779 os << text().asString(0, 1, AS_STR_LABEL | AS_STR_INSETS);
783 void InsetText::forToc(docstring & os, size_t maxlen) const
785 if (!getLayout().isInToc())
787 text().forToc(os, maxlen, false);
791 void InsetText::addToToc(DocIterator const & cdit) const
793 DocIterator dit = cdit;
794 dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
795 Toc & toc = buffer().tocBackend().toc("tableofcontents");
797 BufferParams const & bufparams = buffer_->params();
798 int const min_toclevel = bufparams.documentClass().min_toclevel();
800 // For each paragraph, traverse its insets and let them add
802 ParagraphList const & pars = paragraphs();
803 pit_type pend = paragraphs().size();
804 for (pit_type pit = 0; pit != pend; ++pit) {
805 Paragraph const & par = pars[pit];
807 // if we find an optarg, we'll save it for use later.
808 InsetText const * arginset = 0;
809 InsetList::const_iterator it = par.insetList().begin();
810 InsetList::const_iterator end = par.insetList().end();
811 for (; it != end; ++it) {
812 Inset & inset = *it->inset;
814 //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
816 if (inset.lyxCode() == ARG_CODE)
817 arginset = inset.asInsetText();
819 // now the toc entry for the paragraph
820 int const toclevel = par.layout().toclevel;
821 if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
822 // insert this into the table of contents
825 tocstring = par.labelString();
826 if (!tocstring.empty())
828 arginset->text().forToc(tocstring, TOC_ENTRY_LENGTH);
830 par.forToc(tocstring, TOC_ENTRY_LENGTH);
832 toc.push_back(TocItem(dit, toclevel - min_toclevel,
833 tocstring, tocstring));
836 // And now the list of changes.
837 par.addChangesToToc(dit, buffer());
842 bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
844 if (buffer().isClean())
845 return Inset::notifyCursorLeaves(old, cur);
847 // find text inset in old cursor
848 Cursor insetCur = old;
849 int scriptSlice = insetCur.find(this);
850 LASSERT(scriptSlice != -1, /**/);
851 insetCur.cutOff(scriptSlice);
852 LASSERT(&insetCur.inset() == this, /**/);
854 // update the old paragraph's words
855 insetCur.paragraph().updateWords();
857 return Inset::notifyCursorLeaves(old, cur);
861 bool InsetText::completionSupported(Cursor const & cur) const
863 //LASSERT(&cur.bv().cursor().inset() != this, return false);
864 return text_.completionSupported(cur);
868 bool InsetText::inlineCompletionSupported(Cursor const & cur) const
870 return completionSupported(cur);
874 bool InsetText::automaticInlineCompletion() const
876 return lyxrc.completion_inline_text;
880 bool InsetText::automaticPopupCompletion() const
882 return lyxrc.completion_popup_text;
886 bool InsetText::showCompletionCursor() const
888 return lyxrc.completion_cursor_text;
892 CompletionList const * InsetText::createCompletionList(Cursor const & cur) const
894 return completionSupported(cur) ? text_.createCompletionList(cur) : 0;
898 docstring InsetText::completionPrefix(Cursor const & cur) const
900 if (!completionSupported(cur))
902 return text_.completionPrefix(cur);
906 bool InsetText::insertCompletion(Cursor & cur, docstring const & s,
909 if (!completionSupported(cur))
912 return text_.insertCompletion(cur, s, finished);
916 void InsetText::completionPosAndDim(Cursor const & cur, int & x, int & y,
917 Dimension & dim) const
919 TextMetrics const & tm = cur.bv().textMetrics(&text_);
920 tm.completionPosAndDim(cur, x, y, dim);
924 string InsetText::contextMenu(BufferView const &, int, int) const
926 string context_menu = contextMenuName();
927 if (context_menu != InsetText::contextMenuName())
928 context_menu += ";" + InsetText::contextMenuName();
933 string InsetText::contextMenuName() const
935 return "context-edit";
939 docstring InsetText::toolTipText(docstring prefix,
940 size_t numlines, size_t len) const
942 size_t const max_length = numlines * len;
943 OutputParams rp(&buffer().params().encoding());
944 odocstringstream oss;
947 ParagraphList::const_iterator beg = paragraphs().begin();
948 ParagraphList::const_iterator end = paragraphs().end();
949 ParagraphList::const_iterator it = beg;
950 bool ref_printed = false;
953 for (; it != end; ++it) {
956 writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed);
958 if (str.length() > max_length)
961 return support::wrapParas(str, 4, len, numlines);
965 InsetCaption const * InsetText::getCaptionInset() const
967 ParagraphList::const_iterator pit = paragraphs().begin();
968 for (; pit != paragraphs().end(); ++pit) {
969 InsetList::const_iterator it = pit->insetList().begin();
970 for (; it != pit->insetList().end(); ++it) {
971 Inset & inset = *it->inset;
972 if (inset.lyxCode() == CAPTION_CODE) {
973 InsetCaption const * ins =
974 static_cast<InsetCaption const *>(it->inset);
983 docstring InsetText::getCaptionText(OutputParams const & runparams) const
985 InsetCaption const * ins = getCaptionInset();
989 odocstringstream ods;
990 ins->getCaptionAsPlaintext(ods, runparams);
995 docstring InsetText::getCaptionHTML(OutputParams const & runparams) const
997 InsetCaption const * ins = getCaptionInset();
1001 odocstringstream ods;
1002 XHTMLStream xs(ods);
1003 docstring def = ins->getCaptionAsHTML(xs, runparams);
1005 // should already have been escaped
1006 xs << XHTMLStream::ESCAPE_NONE << def << '\n';
1011 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2)
1013 return static_cast<InsetText::XHTMLOptions>((int)a1 | (int)a2);