]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.cpp
eb01cfb23c1cfd36330fb5e131a08c5fedb79e9b
[lyx.git] / src / insets / InsetText.cpp
1 /**
2  * \file InsetText.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetText.h"
14
15 #include "insets/InsetOptArg.h"
16
17 #include "buffer_funcs.h"
18 #include "Buffer.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "CompletionList.h"
22 #include "CoordCache.h"
23 #include "Cursor.h"
24 #include "CutAndPaste.h"
25 #include "DispatchResult.h"
26 #include "ErrorList.h"
27 #include "FuncRequest.h"
28 #include "FuncStatus.h"
29 #include "InsetCaption.h"
30 #include "InsetList.h"
31 #include "Intl.h"
32 #include "Language.h"
33 #include "LaTeXFeatures.h"
34 #include "Lexer.h"
35 #include "lyxfind.h"
36 #include "LyXRC.h"
37 #include "MetricsInfo.h"
38 #include "output_docbook.h"
39 #include "output_latex.h"
40 #include "output_xhtml.h"
41 #include "OutputParams.h"
42 #include "output_plaintext.h"
43 #include "paragraph_funcs.h"
44 #include "Paragraph.h"
45 #include "ParagraphParameters.h"
46 #include "ParIterator.h"
47 #include "Row.h"
48 #include "sgml.h"
49 #include "TexRow.h"
50 #include "TextClass.h"
51 #include "Text.h"
52 #include "TextMetrics.h"
53 #include "TocBackend.h"
54
55 #include "frontends/alert.h"
56 #include "frontends/Painter.h"
57
58 #include "support/debug.h"
59 #include "support/gettext.h"
60 #include "support/lstrings.h"
61
62 #include <boost/bind.hpp>
63 #include "support/lassert.h"
64
65 using namespace std;
66 using namespace lyx::support;
67
68 using boost::bind;
69 using boost::ref;
70
71 namespace lyx {
72
73 using graphics::PreviewLoader;
74
75
76 /////////////////////////////////////////////////////////////////////
77
78 InsetText::InsetText(Buffer const & buf, UsePlain type)
79         : drawFrame_(false), frame_color_(Color_insetframe)
80 {
81         setBuffer(const_cast<Buffer &>(buf));
82         initParagraphs(type);
83 }
84
85
86 InsetText::InsetText(InsetText const & in)
87         : Inset(in), text_()
88 {
89         text_.autoBreakRows_ = in.text_.autoBreakRows_;
90         drawFrame_ = in.drawFrame_;
91         frame_color_ = in.frame_color_;
92         text_.paragraphs() = in.text_.paragraphs();
93         setParagraphOwner();
94 }
95
96
97 void InsetText::setBuffer(Buffer & buf)
98 {
99         ParagraphList::iterator end = paragraphs().end();
100         for (ParagraphList::iterator it = paragraphs().begin(); it != end; ++it)
101                 it->setBuffer(buf);
102         Inset::setBuffer(buf);
103 }
104
105
106 void InsetText::initParagraphs(UsePlain type)
107 {
108         LASSERT(paragraphs().empty(), /**/);
109         paragraphs().push_back(Paragraph());
110         Paragraph & ourpar = paragraphs().back();
111         ourpar.setInsetOwner(this);
112         DocumentClass const & dc = buffer_->params().documentClass();
113         if (type == DefaultLayout)
114                 ourpar.setDefaultLayout(dc);
115         else
116                 ourpar.setPlainLayout(dc);
117 }
118
119
120 void InsetText::setParagraphOwner()
121 {
122         for_each(paragraphs().begin(), paragraphs().end(),
123                  bind(&Paragraph::setInsetOwner, _1, this));
124 }
125
126
127 void InsetText::clear()
128 {
129         ParagraphList & pars = paragraphs();
130         LASSERT(!pars.empty(), /**/);
131
132         // This is a gross hack...
133         Layout const & old_layout = pars.begin()->layout();
134
135         pars.clear();
136         pars.push_back(Paragraph());
137         pars.begin()->setInsetOwner(this);
138         pars.begin()->setLayout(old_layout);
139 }
140
141
142 Dimension const InsetText::dimension(BufferView const & bv) const
143 {
144         TextMetrics const & tm = bv.textMetrics(&text_);
145         Dimension dim = tm.dimension();
146         dim.wid += 2 * TEXT_TO_INSET_OFFSET;
147         dim.des += TEXT_TO_INSET_OFFSET;
148         dim.asc += TEXT_TO_INSET_OFFSET;
149         return dim;
150 }
151
152
153 void InsetText::write(ostream & os) const
154 {
155         os << "Text\n";
156         text_.write(buffer(), os);
157 }
158
159
160 void InsetText::read(Lexer & lex)
161 {
162         clear();
163
164         // delete the initial paragraph
165         Paragraph oldpar = *paragraphs().begin();
166         paragraphs().clear();
167         ErrorList errorList;
168         lex.setContext("InsetText::read");
169         bool res = text_.read(buffer(), lex, errorList, this);
170
171         if (!res)
172                 lex.printError("Missing \\end_inset at this point. ");
173
174         // sanity check
175         // ensure we have at least one paragraph.
176         if (paragraphs().empty())
177                 paragraphs().push_back(oldpar);
178         // Force default font, if so requested
179         // This avoids paragraphs in buffer language that would have a
180         // foreign language after a document language change, and it ensures
181         // that all new text in ERT and similar gets the "latex" language,
182         // since new text inherits the language from the last position of the
183         // existing text.  As a side effect this makes us also robust against
184         // bugs in LyX that might lead to font changes in ERT in .lyx files.
185         fixParagraphsFont();
186 }
187
188
189 void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
190 {
191         TextMetrics & tm = mi.base.bv->textMetrics(&text_);
192
193         //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
194
195         // Hand font through to contained lyxtext:
196         tm.font_.fontInfo() = mi.base.font;
197         mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
198
199         // This can happen when a layout has a left and right margin,
200         // and the view is made very narrow. We can't do better than 
201         // to draw it partly out of view (bug 5890).
202         if (mi.base.textwidth < 1)
203                 mi.base.textwidth = 1;
204
205         if (hasFixedWidth())
206                 tm.metrics(mi, dim, mi.base.textwidth);
207         else
208                 tm.metrics(mi, dim);
209         mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
210         dim.asc += TEXT_TO_INSET_OFFSET;
211         dim.des += TEXT_TO_INSET_OFFSET;
212         dim.wid += 2 * TEXT_TO_INSET_OFFSET;
213 }
214
215
216 void InsetText::draw(PainterInfo & pi, int x, int y) const
217 {
218         TextMetrics & tm = pi.base.bv->textMetrics(&text_);
219
220         if (drawFrame_ || pi.full_repaint) {
221                 int const w = tm.width() + TEXT_TO_INSET_OFFSET;
222                 int const yframe = y - TEXT_TO_INSET_OFFSET - tm.ascent();
223                 int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
224                 int const xframe = x + TEXT_TO_INSET_OFFSET / 2;
225                 if (pi.full_repaint)
226                         pi.pain.fillRectangle(xframe, yframe, w, h,
227                                 pi.backgroundColor(this));
228
229                 if (drawFrame_)
230                         pi.pain.rectangle(xframe, yframe, w, h, frameColor());
231         }
232         ColorCode const old_color = pi.background_color;
233         pi.background_color = pi.backgroundColor(this, false);
234
235         tm.draw(pi, x + TEXT_TO_INSET_OFFSET, y);
236
237         pi.background_color = old_color;
238 }
239
240
241 docstring InsetText::editMessage() const
242 {
243         return _("Opened Text Inset");
244 }
245
246
247 void InsetText::edit(Cursor & cur, bool front, EntryDirection entry_from)
248 {
249         pit_type const pit = front ? 0 : paragraphs().size() - 1;
250         pos_type pos = front ? 0 : paragraphs().back().size();
251
252         // if visual information is not to be ignored, move to extreme right/left
253         if (entry_from != ENTRY_DIRECTION_IGNORE) {
254                 Cursor temp_cur = cur;
255                 temp_cur.pit() = pit;
256                 temp_cur.pos() = pos;
257                 temp_cur.posVisToRowExtremity(entry_from == ENTRY_DIRECTION_LEFT);
258                 pos = temp_cur.pos();
259         }
260
261         text_.setCursor(cur.top(), pit, pos);
262         cur.clearSelection();
263         cur.finishUndo();
264 }
265
266
267 Inset * InsetText::editXY(Cursor & cur, int x, int y)
268 {
269         return cur.bv().textMetrics(&text_).editXY(cur, x, y);
270 }
271
272
273 void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
274 {
275         LYXERR(Debug::ACTION, "InsetText::doDispatch()"
276                 << " [ cmd.action = " << cmd.action << ']');
277
278         // FIXME this use of forceLTR is dubious
279         // introduced in http://www.lyx.org/trac/changeset/21285
280         if (forceLTR()) {
281                 // Force any new text to latex_language FIXME: This
282                 // should only be necessary in constructor, but new
283                 // paragraphs that are created by pressing enter at
284                 // the start of an existing paragraph get the buffer
285                 // language and not latex_language, so we take this
286                 // brute force approach.
287                 cur.current_font.setLanguage(latex_language);
288                 cur.real_current_font.setLanguage(latex_language);
289         }
290
291         switch (cmd.action) {
292         case LFUN_PASTE:
293         case LFUN_CLIPBOARD_PASTE:
294         case LFUN_SELECTION_PASTE:
295         case LFUN_PRIMARY_SELECTION_PASTE:
296                 text_.dispatch(cur, cmd);
297                 // If we we can only store plain text, we must reset all
298                 // attributes.
299                 // FIXME: Change only the pasted paragraphs
300                 fixParagraphsFont();
301                 break;
302         default:
303                 text_.dispatch(cur, cmd);
304         }
305         
306         if (!cur.result().dispatched())
307                 Inset::doDispatch(cur, cmd);
308 }
309
310
311 bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
312         FuncStatus & status) const
313 {
314         switch (cmd.action) {
315         case LFUN_LAYOUT:
316                 status.setEnabled(!forcePlainLayout());
317                 return true;
318
319         case LFUN_LAYOUT_PARAGRAPH:
320         case LFUN_PARAGRAPH_PARAMS:
321         case LFUN_PARAGRAPH_PARAMS_APPLY:
322         case LFUN_PARAGRAPH_SPACING:
323         case LFUN_PARAGRAPH_UPDATE:
324                 status.setEnabled(allowParagraphCustomization());
325                 return true;
326         default:
327                 // Dispatch only to text_ if the cursor is inside
328                 // the text_. It is not for context menus (bug 5797).
329                 bool ret = false;
330                 if (cur.text() == &text_)
331                         ret = text_.getStatus(cur, cmd, status);
332                 
333                 if (!ret)
334                         ret = Inset::getStatus(cur, cmd, status);
335                 return ret;
336         }
337 }
338
339
340 void InsetText::fixParagraphsFont()
341 {
342         Font font(inherit_font, buffer().params().language);
343         if (getLayout().isForceLtr())
344                 font.setLanguage(latex_language);
345         if (getLayout().isPassThru()) {
346                 ParagraphList::iterator par = paragraphs().begin();
347                 ParagraphList::iterator const end = paragraphs().end();
348                 while (par != end) {
349                         par->resetFonts(font);
350                         par->params().clear();
351                         ++par;
352                 }
353         }
354 }
355
356
357 void InsetText::setChange(Change const & change)
358 {
359         ParagraphList::iterator pit = paragraphs().begin();
360         ParagraphList::iterator end = paragraphs().end();
361         for (; pit != end; ++pit) {
362                 pit->setChange(change);
363         }
364 }
365
366
367 void InsetText::acceptChanges()
368 {
369         text_.acceptChanges(buffer().params());
370 }
371
372
373 void InsetText::rejectChanges()
374 {
375         text_.rejectChanges(buffer().params());
376 }
377
378
379 int InsetText::latex(odocstream & os, OutputParams const & runparams) const
380 {
381         // This implements the standard way of handling the LaTeX
382         // output of a text inset, either a command or an
383         // environment. Standard collapsable insets should not
384         // redefine this, non-standard ones may call this.
385         InsetLayout const & il = getLayout();
386         int rows = 0;
387         if (!il.latexname().empty()) {
388                 if (il.latextype() == InsetLayout::COMMAND) {
389                         // FIXME UNICODE
390                         if (runparams.moving_arg)
391                                 os << "\\protect";
392                         os << '\\' << from_utf8(il.latexname());
393                         if (!il.latexparam().empty())
394                                 os << from_utf8(il.latexparam());
395                         os << '{';
396                 } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
397                         os << "%\n\\begin{" << from_utf8(il.latexname()) << "}\n";
398                         if (!il.latexparam().empty())
399                                 os << from_utf8(il.latexparam());
400                         rows += 2;
401                 }
402         }
403         OutputParams rp = runparams;
404         if (il.isPassThru())
405                 rp.verbatim = true;
406         if (il.isNeedProtect())
407                 rp.moving_arg = true;
408
409         // Output the contents of the inset
410         TexRow texrow;
411         latexParagraphs(buffer(), text_, os, texrow, rp);
412         rows += texrow.rows();
413
414         if (!il.latexname().empty()) {
415                 if (il.latextype() == InsetLayout::COMMAND) {
416                         os << "}";
417                 } else if (il.latextype() == InsetLayout::ENVIRONMENT) {
418                         os << "\n\\end{" << from_utf8(il.latexname()) << "}\n";
419                         rows += 2;
420                 }
421         }
422         return rows;
423 }
424
425
426 int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const
427 {
428         ParagraphList::const_iterator beg = paragraphs().begin();
429         ParagraphList::const_iterator end = paragraphs().end();
430         ParagraphList::const_iterator it = beg;
431         bool ref_printed = false;
432         int len = 0;
433         for (; it != end; ++it) {
434                 if (it != beg) {
435                         os << '\n';
436                         if (runparams.linelen > 0)
437                                 os << '\n';
438                 }
439                 odocstringstream oss;
440                 writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed);
441                 docstring const str = oss.str();
442                 os << str;
443                 // FIXME: len is not computed fully correctly; in principle,
444                 // we have to count the characters after the last '\n'
445                 len = str.size();
446         }
447
448         return len;
449 }
450
451
452 int InsetText::docbook(odocstream & os, OutputParams const & runparams) const
453 {
454         docbookParagraphs(paragraphs(), buffer(), os, runparams);
455         return 0;
456 }
457
458
459 docstring InsetText::xhtml(odocstream & os, OutputParams const & runparams) const
460 {
461         xhtmlParagraphs(paragraphs(), buffer(), os, runparams);
462         return docstring();
463 }
464
465
466 void InsetText::validate(LaTeXFeatures & features) const
467 {
468         features.useInsetLayout(getLayout());
469         for_each(paragraphs().begin(), paragraphs().end(),
470                  bind(&Paragraph::validate, _1, ref(features)));
471 }
472
473
474 void InsetText::cursorPos(BufferView const & bv,
475                 CursorSlice const & sl, bool boundary, int & x, int & y) const
476 {
477         x = bv.textMetrics(&text_).cursorX(sl, boundary) + TEXT_TO_INSET_OFFSET;
478         y = bv.textMetrics(&text_).cursorY(sl, boundary);
479 }
480
481
482 bool InsetText::showInsetDialog(BufferView *) const
483 {
484         return false;
485 }
486
487
488 void InsetText::setText(docstring const & data, Font const & font, bool trackChanges)
489 {
490         clear();
491         Paragraph & first = paragraphs().front();
492         for (unsigned int i = 0; i < data.length(); ++i)
493                 first.insertChar(i, data[i], font, trackChanges);
494 }
495
496
497 void InsetText::setAutoBreakRows(bool flag)
498 {
499         if (flag == text_.autoBreakRows_)
500                 return;
501
502         text_.autoBreakRows_ = flag;
503         if (flag)
504                 return;
505
506         // remove previously existing newlines
507         ParagraphList::iterator it = paragraphs().begin();
508         ParagraphList::iterator end = paragraphs().end();
509         for (; it != end; ++it)
510                 for (int i = 0; i < it->size(); ++i)
511                         if (it->isNewline(i))
512                                 // do not track the change, because the user
513                                 // is not allowed to revert/reject it
514                                 it->eraseChar(i, false);
515 }
516
517
518 void InsetText::setDrawFrame(bool flag)
519 {
520         drawFrame_ = flag;
521 }
522
523
524 ColorCode InsetText::frameColor() const
525 {
526         return frame_color_;
527 }
528
529
530 void InsetText::setFrameColor(ColorCode col)
531 {
532         frame_color_ = col;
533 }
534
535
536 void InsetText::appendParagraphs(ParagraphList & plist)
537 {
538         // There is little we can do here to keep track of changes.
539         // As of 2006/10/20, appendParagraphs is used exclusively by
540         // LyXTabular::setMultiColumn. In this context, the paragraph break
541         // is lost irreversibly and the appended text doesn't really change
542
543         ParagraphList & pl = paragraphs();
544
545         ParagraphList::iterator pit = plist.begin();
546         ParagraphList::iterator ins = pl.insert(pl.end(), *pit);
547         ++pit;
548         mergeParagraph(buffer().params(), pl,
549                        distance(pl.begin(), ins) - 1);
550
551         for_each(pit, plist.end(),
552                  bind(&ParagraphList::push_back, ref(pl), _1));
553 }
554
555
556 void InsetText::addPreview(PreviewLoader & loader) const
557 {
558         ParagraphList::const_iterator pit = paragraphs().begin();
559         ParagraphList::const_iterator pend = paragraphs().end();
560
561         for (; pit != pend; ++pit) {
562                 InsetList::const_iterator it  = pit->insetList().begin();
563                 InsetList::const_iterator end = pit->insetList().end();
564                 for (; it != end; ++it)
565                         it->inset->addPreview(loader);
566         }
567 }
568
569
570 ParagraphList const & InsetText::paragraphs() const
571 {
572         return text_.paragraphs();
573 }
574
575
576 ParagraphList & InsetText::paragraphs()
577 {
578         return text_.paragraphs();
579 }
580
581
582 void InsetText::updateLabels(ParIterator const & it)
583 {
584         ParIterator it2 = it;
585         it2.forwardPos();
586         LASSERT(&it2.inset() == this && it2.pit() == 0, return);
587         if (producesOutput())
588                 buffer().updateLabels(it2);
589         else {
590                 DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
591                 Counters const savecnt = tclass.counters();
592                 buffer().updateLabels(it2);
593                 tclass.counters() = savecnt;
594         }
595 }
596
597
598 void InsetText::addToToc(DocIterator const & cdit)
599 {
600         DocIterator dit = cdit;
601         dit.push_back(CursorSlice(*this));
602         Toc & toc = buffer().tocBackend().toc("tableofcontents");
603
604         BufferParams const & bufparams = buffer_->params();
605         const int min_toclevel = bufparams.documentClass().min_toclevel();
606
607         // For each paragraph, traverse its insets and let them add
608         // their toc items
609         ParagraphList & pars = paragraphs();
610         pit_type pend = paragraphs().size();
611         for (pit_type pit = 0; pit != pend; ++pit) {
612                 Paragraph const & par = pars[pit];
613                 dit.pit() = pit;
614                 // the string that goes to the toc (could be the optarg)
615                 docstring tocstring;
616                 InsetList::const_iterator it  = par.insetList().begin();
617                 InsetList::const_iterator end = par.insetList().end();
618                 for (; it != end; ++it) {
619                         Inset & inset = *it->inset;
620                         dit.pos() = it->pos;
621                         //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
622                         inset.addToToc(dit);
623                         switch (inset.lyxCode()) {
624                         case OPTARG_CODE: {
625                                 if (!tocstring.empty())
626                                         break;
627                                 dit.pos() = 0;
628                                 Paragraph const & insetpar =
629                                         *static_cast<InsetOptArg&>(inset).paragraphs().begin();
630                                 if (!par.labelString().empty())
631                                         tocstring = par.labelString() + ' ';
632                                 tocstring += insetpar.asString(AS_STR_INSETS);
633                                 break;
634                         }
635                         default:
636                                 break;
637                         }
638                 }
639                 // now the toc entry for the paragraph
640                 int const toclevel = par.layout().toclevel;
641                 if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
642                         dit.pos() = 0;
643                         // insert this into the table of contents
644                         if (tocstring.empty())
645                                 tocstring = par.asString(AS_STR_LABEL | AS_STR_INSETS);
646                         toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring));
647                 }
648                 
649                 // And now the list of changes.
650                 par.addChangesToToc(dit, buffer());
651         }
652 }
653
654
655 bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
656 {
657         if (buffer().isClean())
658                 return Inset::notifyCursorLeaves(old, cur);
659         
660         // find text inset in old cursor
661         Cursor insetCur = old;
662         int scriptSlice = insetCur.find(this);
663         LASSERT(scriptSlice != -1, /**/);
664         insetCur.cutOff(scriptSlice);
665         LASSERT(&insetCur.inset() == this, /**/);
666         
667         // update the old paragraph's words
668         insetCur.paragraph().updateWords();
669         
670         return Inset::notifyCursorLeaves(old, cur);
671 }
672
673
674 bool InsetText::completionSupported(Cursor const & cur) const
675 {
676         //LASSERT(&cur.bv().cursor().inset() != this, return false);
677         return text_.completionSupported(cur);
678 }
679
680
681 bool InsetText::inlineCompletionSupported(Cursor const & cur) const
682 {
683         return completionSupported(cur);
684 }
685
686
687 bool InsetText::automaticInlineCompletion() const
688 {
689         return lyxrc.completion_inline_text;
690 }
691
692
693 bool InsetText::automaticPopupCompletion() const
694 {
695         return lyxrc.completion_popup_text;
696 }
697
698
699 bool InsetText::showCompletionCursor() const
700 {
701         return lyxrc.completion_cursor_text;
702 }
703
704
705 CompletionList const * InsetText::createCompletionList(Cursor const & cur) const
706 {
707         return completionSupported(cur) ? text_.createCompletionList(cur) : 0;
708 }
709
710
711 docstring InsetText::completionPrefix(Cursor const & cur) const
712 {
713         if (!completionSupported(cur))
714                 return docstring();
715         return text_.completionPrefix(cur);
716 }
717
718
719 bool InsetText::insertCompletion(Cursor & cur, docstring const & s,
720         bool finished)
721 {
722         if (!completionSupported(cur))
723                 return false;
724
725         return text_.insertCompletion(cur, s, finished);
726 }
727
728
729 void InsetText::completionPosAndDim(Cursor const & cur, int & x, int & y, 
730         Dimension & dim) const
731 {
732         TextMetrics const & tm = cur.bv().textMetrics(&text_);
733         tm.completionPosAndDim(cur, x, y, dim);
734 }
735
736
737 docstring InsetText::contextMenu(BufferView const &, int, int) const
738 {
739         return from_ascii("context-edit");
740 }
741
742
743 InsetCaption const * InsetText::getCaptionInset() const
744 {
745         ParagraphList::const_iterator pit = paragraphs().begin();
746         for (; pit != paragraphs().end(); ++pit) {
747                 InsetList::const_iterator it = pit->insetList().begin();
748                 for (; it != pit->insetList().end(); ++it) {
749                         Inset & inset = *it->inset;
750                         if (inset.lyxCode() == CAPTION_CODE) {
751                                 InsetCaption const * ins =
752                                         static_cast<InsetCaption const *>(it->inset);
753                                 return ins;
754                         }
755                 }
756         }
757         return 0;
758 }
759
760
761 docstring InsetText::getCaptionText(OutputParams const & runparams) const
762 {
763         InsetCaption const * ins = getCaptionInset();
764         if (ins == 0)
765                 return docstring();
766
767         odocstringstream ods;
768         ins->getCaptionAsPlaintext(ods, runparams);
769         return ods.str();
770 }
771
772
773 docstring InsetText::getCaptionHTML(OutputParams const & runparams) const
774 {
775         InsetCaption const * ins = getCaptionInset();
776         if (ins == 0)
777                 return docstring();
778
779         odocstringstream ods;
780         docstring def = ins->getCaptionAsHTML(ods, runparams);
781         if (!def.empty())
782                 ods << def << '\n';
783         return ods.str();
784 }
785
786
787 } // namespace lyx