3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
11 * \author André Pönitz
13 * \author Jürgen Vigna
15 * Full author contact details are available in file CREDITS.
20 #include "paragraph.h"
21 #include "paragraph_pimpl.h"
28 #include "latexrunparams.h"
32 #include "insets/insetbibitem.h"
33 #include "insets/insetoptarg.h"
35 #include "support/lstrings.h"
36 #include "support/LAssert.h"
37 #include "support/textutils.h"
39 #include "support/std_sstream.h"
42 using namespace lyx::support;
45 using std::ostringstream;
51 Paragraph::Paragraph()
52 : y(0), pimpl_(new Paragraph::Pimpl(this))
60 Paragraph::Paragraph(Paragraph const & lp)
61 : y(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
65 // this is because of the dummy layout of the paragraphs that
67 layout_ = lp.layout();
69 // copy everything behind the break-position to the new paragraph
70 insetlist = lp.insetlist;
71 InsetList::iterator it = insetlist.begin();
72 InsetList::iterator end = insetlist.end();
73 for (; it != end; ++it) {
74 // currently we hold Inset*, not InsetBase*
75 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
80 void Paragraph::operator=(Paragraph const & lp)
82 // needed as we will destroy the pimpl_ before copying it
86 lyxerr << "Paragraph::operator=()" << endl;
89 pimpl_ = new Pimpl(*lp.pimpl_, this);
91 enumdepth = lp.enumdepth;
92 itemdepth = lp.itemdepth;
93 // this is because of the dummy layout of the paragraphs that
95 layout_ = lp.layout();
97 // copy everything behind the break-position to the new paragraph
98 insetlist = lp.insetlist;
99 InsetList::iterator it = insetlist.begin();
100 InsetList::iterator end = insetlist.end();
101 for (; it != end; ++it) {
102 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
106 // the destructor removes the new paragraph from the list
107 Paragraph::~Paragraph()
111 //lyxerr << "Paragraph::paragraph_id = "
112 // << Paragraph::paragraph_id << endl;
116 void Paragraph::write(Buffer const & buf, ostream & os,
117 BufferParams const & bparams,
118 depth_type & dth) const
120 // The beginning or end of a deeper (i.e. nested) area?
121 if (dth != params().depth()) {
122 if (params().depth() > dth) {
123 while (params().depth() > dth) {
124 os << "\n\\begin_deeper ";
128 while (params().depth() < dth) {
129 os << "\n\\end_deeper ";
135 // First write the layout
136 os << "\n\\begin_layout " << layout()->name() << '\n';
140 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
142 Change running_change = Change(Change::UNCHANGED);
143 lyx::time_type const curtime(lyx::current_time());
146 for (pos_type i = 0; i < size(); ++i) {
152 Change change = pimpl_->lookupChangeFull(i);
153 Changes::lyxMarkChange(os, column, curtime, running_change, change);
154 running_change = change;
156 // Write font changes
157 LyXFont font2 = getFontSettings(bparams, i);
158 if (font2 != font1) {
159 font2.lyxWriteChanges(font1, os);
164 value_type const c = getChar(i);
168 InsetOld const * inset = getInset(i);
170 if (inset->directWrite()) {
171 // international char, let it write
172 // code directly so it's shorter in
174 inset->write(buf, os);
176 os << "\n\\begin_inset ";
177 inset->write(buf, os);
178 os << "\n\\end_inset \n\n";
184 os << "\n\\backslash \n";
188 if (i + 1 < size() && getChar(i + 1) == ' ') {
195 if ((column > 70 && c == ' ')
200 // this check is to amend a bug. LyX sometimes
201 // inserts '\0' this could cause problems.
205 lyxerr << "ERROR (Paragraph::writeFile):"
206 " NULL char in structure." << endl;
212 // to make reading work properly
214 running_change = pimpl_->lookupChange(0);
215 Changes::lyxMarkChange(os, column, curtime,
216 Change(Change::UNCHANGED), running_change);
218 Changes::lyxMarkChange(os, column, curtime,
219 running_change, Change(Change::UNCHANGED));
221 os << "\n\\end_layout\n";
225 void Paragraph::validate(LaTeXFeatures & features) const
227 pimpl_->validate(features, *layout());
231 void Paragraph::eraseIntern(lyx::pos_type pos)
233 pimpl_->eraseIntern(pos);
237 bool Paragraph::erase(pos_type pos)
239 return pimpl_->erase(pos);
243 int Paragraph::erase(pos_type start, pos_type end)
245 return pimpl_->erase(start, end);
249 bool Paragraph::checkInsertChar(LyXFont & font)
251 if (pimpl_->inset_owner)
252 return pimpl_->inset_owner->checkInsertChar(font);
257 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
259 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
263 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
264 LyXFont const & font, Change change)
266 pimpl_->insertChar(pos, c, font, change);
270 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
272 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
276 void Paragraph::insertInset(pos_type pos, InsetOld * inset,
277 LyXFont const & font, Change change)
279 pimpl_->insertInset(pos, inset, font, change);
283 bool Paragraph::insetAllowed(InsetOld::Code code)
285 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
286 if (pimpl_->inset_owner)
287 return pimpl_->inset_owner->insetAllowed(code);
292 InsetOld * Paragraph::getInset(pos_type pos)
294 Assert(pos < size());
295 return insetlist.get(pos);
299 InsetOld const * Paragraph::getInset(pos_type pos) const
301 Assert(pos < size());
302 return insetlist.get(pos);
306 // Gets uninstantiated font setting at position.
307 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
310 Assert(pos <= size());
312 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
313 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
314 for (; cit != end; ++cit)
315 if (cit->pos() >= pos)
321 if (pos == size() && !empty())
322 return getFontSettings(bparams, pos - 1);
324 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
328 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
330 Assert(pos <= size());
332 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
333 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
334 for (; cit != end; ++cit)
335 if (cit->pos() >= pos)
338 // This should not happen, but if so, we take no chances.
339 //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
345 // Gets uninstantiated font setting at position 0
346 LyXFont const Paragraph::getFirstFontSettings() const
348 if (!empty() && !pimpl_->fontlist.empty())
349 return pimpl_->fontlist[0].font();
351 return LyXFont(LyXFont::ALL_INHERIT);
355 // Gets the fully instantiated font at a given position in a paragraph
356 // This is basically the same function as LyXText::GetFont() in text2.C.
357 // The difference is that this one is used for generating the LaTeX file,
358 // and thus cosmetic "improvements" are disallowed: This has to deliver
359 // the true picture of the buffer. (Asger)
360 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
361 LyXFont const & outerfont) const
365 LyXLayout_ptr const & lout = layout();
367 pos_type const body_pos = beginningOfBody();
371 layoutfont = lout->labelfont;
373 layoutfont = lout->font;
375 LyXFont tmpfont = getFontSettings(bparams, pos);
376 tmpfont.realize(layoutfont);
377 tmpfont.realize(outerfont);
378 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
384 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
385 LyXFont const & outerfont) const
387 LyXFont tmpfont = layout()->labelfont;
388 tmpfont.setLanguage(getParLanguage(bparams));
389 tmpfont.realize(outerfont);
390 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
395 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
396 LyXFont const & outerfont) const
398 LyXFont tmpfont = layout()->font;
399 tmpfont.setLanguage(getParLanguage(bparams));
400 tmpfont.realize(outerfont);
401 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
406 /// Returns the height of the highest font in range
408 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
409 LyXFont::FONT_SIZE const def_size) const
411 if (pimpl_->fontlist.empty())
414 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
415 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
416 for (; end_it != end; ++end_it) {
417 if (end_it->pos() >= endpos)
424 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
425 for (; cit != end; ++cit) {
426 if (cit->pos() >= startpos)
430 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
431 for (; cit != end_it; ++cit) {
432 LyXFont::FONT_SIZE size = cit->font().size();
433 if (size == LyXFont::INHERIT_SIZE)
435 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
442 Paragraph::value_type
443 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
445 value_type c = getChar(pos);
446 if (!lyxrc.rtl_support)
476 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
483 void Paragraph::setFont(pos_type pos, LyXFont const & font)
485 Assert(pos <= size());
487 // First, reduce font against layout/label font
488 // Update: The SetCharFont() routine in text2.C already
489 // reduces font, so we don't need to do that here. (Asger)
490 // No need to simplify this because it will disappear
491 // in a new kernel. (Asger)
492 // Next search font table
494 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
495 Pimpl::FontList::iterator it = beg;
496 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
497 for (; it != endit; ++it) {
498 if (it->pos() >= pos)
501 unsigned int i = std::distance(beg, it);
502 bool notfound = (it == endit);
504 if (!notfound && pimpl_->fontlist[i].font() == font)
507 bool begin = pos == 0 || notfound ||
508 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
509 // Is position pos is a beginning of a font block?
510 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
511 // Is position pos is the end of a font block?
512 if (begin && end) { // A single char block
513 if (i + 1 < pimpl_->fontlist.size() &&
514 pimpl_->fontlist[i + 1].font() == font) {
515 // Merge the singleton block with the next block
516 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
517 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
518 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
519 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
520 // Merge the singleton block with the previous block
521 pimpl_->fontlist[i - 1].pos(pos);
522 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
524 pimpl_->fontlist[i].font(font);
526 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
527 pimpl_->fontlist[i - 1].pos(pos);
529 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
530 Pimpl::FontTable(pos, font));
532 pimpl_->fontlist[i].pos(pos - 1);
533 if (!(i + 1 < pimpl_->fontlist.size() &&
534 pimpl_->fontlist[i + 1].font() == font))
535 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
536 Pimpl::FontTable(pos, font));
537 } else { // The general case. The block is splitted into 3 blocks
538 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
539 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
540 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
541 Pimpl::FontTable(pos, font));
546 void Paragraph::makeSameLayout(Paragraph const & par)
548 layout(par.layout());
550 params() = par.params();
554 int Paragraph::stripLeadingSpaces()
560 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
561 pimpl_->eraseIntern(0);
569 bool Paragraph::hasSameLayout(Paragraph const & par) const
572 par.layout() == layout() &&
573 params().sameLayout(par.params());
577 Paragraph::depth_type Paragraph::getDepth() const
579 return params().depth();
583 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
585 if (layout()->isEnvironment())
586 return params().depth() + 1;
588 return params().depth();
592 char Paragraph::getAlign() const
594 return params().align();
598 string const & Paragraph::getLabelstring() const
600 return params().labelString();
604 // the next two functions are for the manual labels
605 string const Paragraph::getLabelWidthString() const
607 if (!params().labelWidthString().empty())
608 return params().labelWidthString();
610 return _("Senseless with this layout!");
614 void Paragraph::setLabelWidthString(string const & s)
616 params().labelWidthString(s);
620 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
623 params().labelWidthString(string());
624 params().align(LYX_ALIGN_LAYOUT);
625 params().spaceTop(VSpace(VSpace::NONE));
626 params().spaceBottom(VSpace(VSpace::NONE));
627 params().spacing(Spacing(Spacing::Default));
631 int Paragraph::beginningOfBody() const
633 if (layout()->labeltype != LABEL_MANUAL)
636 // Unroll the first two cycles of the loop
637 // and remember the previous character to
638 // remove unnecessary GetChar() calls
640 if (i < size() && !isNewline(i)) {
642 char previous_char = 0;
645 previous_char = getChar(i);
648 while (i < size() && previous_char != ' ') {
654 previous_char = temp;
664 // returns -1 if inset not found
665 int Paragraph::getPositionOfInset(InsetOld const * inset) const
668 InsetList::const_iterator it = insetlist.begin();
669 InsetList::const_iterator end = insetlist.end();
670 for (; it != end; ++it)
671 if (it->inset == inset)
677 InsetBibitem * Paragraph::bibitem() const
679 InsetList::const_iterator it = insetlist.begin();
680 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
681 return static_cast<InsetBibitem *>(it->inset);
687 // This could go to ParagraphParameters if we want to
688 int Paragraph::startTeXParParams(BufferParams const & bparams,
689 ostream & os, bool moving_arg) const
693 if (params().noindent()) {
698 switch (params().align()) {
700 case LYX_ALIGN_BLOCK:
701 case LYX_ALIGN_LAYOUT:
702 case LYX_ALIGN_SPECIAL:
705 case LYX_ALIGN_RIGHT:
706 case LYX_ALIGN_CENTER:
714 switch (params().align()) {
716 case LYX_ALIGN_BLOCK:
717 case LYX_ALIGN_LAYOUT:
718 case LYX_ALIGN_SPECIAL:
721 if (getParLanguage(bparams)->babel() != "hebrew") {
722 os << "\\begin{flushleft}";
725 os << "\\begin{flushright}";
729 case LYX_ALIGN_RIGHT:
730 if (getParLanguage(bparams)->babel() != "hebrew") {
731 os << "\\begin{flushright}";
734 os << "\\begin{flushleft}";
738 case LYX_ALIGN_CENTER:
739 os << "\\begin{center}";
748 // This could go to ParagraphParameters if we want to
749 int Paragraph::endTeXParParams(BufferParams const & bparams,
750 ostream & os, bool moving_arg) const
754 switch (params().align()) {
756 case LYX_ALIGN_BLOCK:
757 case LYX_ALIGN_LAYOUT:
758 case LYX_ALIGN_SPECIAL:
761 case LYX_ALIGN_RIGHT:
762 case LYX_ALIGN_CENTER:
770 switch (params().align()) {
772 case LYX_ALIGN_BLOCK:
773 case LYX_ALIGN_LAYOUT:
774 case LYX_ALIGN_SPECIAL:
777 if (getParLanguage(bparams)->babel() != "hebrew") {
778 os << "\\end{flushleft}";
781 os << "\\end{flushright}";
785 case LYX_ALIGN_RIGHT:
786 if (getParLanguage(bparams)->babel() != "hebrew") {
787 os << "\\end{flushright}";
790 os << "\\end{flushleft}";
794 case LYX_ALIGN_CENTER:
795 os << "\\end{center}";
803 // This one spits out the text of the paragraph
804 bool Paragraph::simpleTeXOnePar(Buffer const & buf,
805 BufferParams const & bparams,
806 LyXFont const & outerfont,
807 ostream & os, TexRow & texrow,
808 LatexRunParams const & runparams)
810 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
812 bool return_value = false;
816 // well we have to check if we are in an inset with unlimited
817 // lenght (all in one row) if that is true then we don't allow
818 // any special options in the paragraph and also we don't allow
819 // any environment other then "Standard" to be valid!
821 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
824 style = bparams.getLyXTextClass().defaultLayout();
831 // Maybe we have to create a optional argument.
834 // FIXME: can we actually skip this check and just call
835 // beginningOfBody() ??
836 if (style->labeltype != LABEL_MANUAL) {
839 body_pos = beginningOfBody();
842 unsigned int column = 0;
847 basefont = getLabelFont(bparams, outerfont);
849 basefont = getLayoutFont(bparams, outerfont);
852 bool moving_arg = runparams.moving_arg;
853 moving_arg |= style->needprotect;
855 // Which font is currently active?
856 LyXFont running_font(basefont);
857 // Do we have an open font change?
858 bool open_font = false;
860 Change::Type running_change = Change::UNCHANGED;
862 texrow.start(id(), 0);
864 // if the paragraph is empty, the loop will not be entered at all
866 if (style->isCommand()) {
871 column += startTeXParParams(bparams, os, moving_arg);
875 for (pos_type i = 0; i < size(); ++i) {
877 // First char in paragraph or after label?
881 column += running_font.latexWriteEndChanges(os, basefont, basefont);
884 basefont = getLayoutFont(bparams, outerfont);
885 running_font = basefont;
889 if (style->isCommand()) {
895 column += startTeXParParams(bparams, os,
899 value_type c = getChar(i);
901 // Fully instantiated font
902 LyXFont font = getFont(bparams, i, outerfont);
904 LyXFont const last_font = running_font;
906 // Spaces at end of font change are simulated to be
907 // outside font change, i.e. we write "\textXX{text} "
908 // rather than "\textXX{text }". (Asger)
909 if (open_font && c == ' ' && i <= size() - 2) {
910 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
911 if (next_font != running_font
912 && next_font != font) {
917 // We end font definition before blanks
919 (font != running_font ||
920 font.language() != running_font.language()))
922 column += running_font.latexWriteEndChanges(os,
924 (i == body_pos-1) ? basefont : font);
925 running_font = basefont;
929 // Blanks are printed before start of fontswitch
931 // Do not print the separation of the optional argument
932 if (i != body_pos - 1) {
933 pimpl_->simpleTeXBlanks(os, texrow, i,
934 column, font, *style);
938 // Do we need to change font?
939 if ((font != running_font ||
940 font.language() != running_font.language()) &&
943 column += font.latexWriteStartChanges(os, basefont,
949 Change::Type change = pimpl_->lookupChange(i);
951 column += Changes::latexMarkChange(os, running_change, change);
952 running_change = change;
954 LatexRunParams rp = runparams;
955 rp.moving_arg = moving_arg;
956 rp.free_spacing = style->free_spacing;
957 pimpl_->simpleTeXSpecialChars(buf, bparams,
958 os, texrow, runparams,
960 basefont, outerfont, open_font,
962 *style, i, column, c);
965 column += Changes::latexMarkChange(os,
966 running_change, Change::UNCHANGED);
968 // If we have an open font definition, we have to close it
970 #ifdef FIXED_LANGUAGE_END_DETECTION
973 .latexWriteEndChanges(os, basefont,
974 next_->getFont(bparams,
977 running_font.latexWriteEndChanges(os, basefont,
982 //#warning For now we ALWAYS have to close the foreign font settings if they are
983 //#warning there as we start another \selectlanguage with the next paragraph if
984 //#warning we are in need of this. This should be fixed sometime (Jug)
986 running_font.latexWriteEndChanges(os, basefont, basefont);
990 // Needed if there is an optional argument but no contents.
991 if (body_pos > 0 && body_pos == size()) {
993 return_value = false;
997 column += endTeXParParams(bparams, os, moving_arg);
1000 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1001 return return_value;
1007 bool Paragraph::isHfill(pos_type pos) const
1009 return IsInsetChar(getChar(pos))
1010 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1014 bool Paragraph::isInset(pos_type pos) const
1016 return IsInsetChar(getChar(pos));
1020 bool Paragraph::isNewline(pos_type pos) const
1022 return IsInsetChar(getChar(pos))
1023 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1027 bool Paragraph::isSeparator(pos_type pos) const
1029 return IsSeparatorChar(getChar(pos));
1033 bool Paragraph::isLineSeparator(pos_type pos) const
1035 value_type const c = getChar(pos);
1036 return IsLineSeparatorChar(c)
1037 || (IsInsetChar(c) && getInset(pos) &&
1038 getInset(pos)->isLineSeparator());
1042 bool Paragraph::isKomma(pos_type pos) const
1044 return IsKommaChar(getChar(pos));
1048 /// Used by the spellchecker
1049 bool Paragraph::isLetter(pos_type pos) const
1051 value_type const c = getChar(pos);
1052 if (IsLetterChar(c))
1055 return getInset(pos)->isLetter();
1056 // We want to pass the ' and escape chars to ispell
1057 string const extra = lyxrc.isp_esc_chars + '\'';
1058 return contains(extra, c);
1062 bool Paragraph::isWord(pos_type pos) const
1064 return IsWordChar(getChar(pos)) ;
1069 Paragraph::getParLanguage(BufferParams const & bparams) const
1072 return getFirstFontSettings().language();
1073 #warning FIXME we should check the prev par as well (Lgb)
1074 return bparams.language;
1078 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1080 return lyxrc.rtl_support
1081 && getParLanguage(bparams)->RightToLeft()
1082 && !(inInset() && inInset()->owner() &&
1083 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1087 void Paragraph::changeLanguage(BufferParams const & bparams,
1088 Language const * from, Language const * to)
1090 for (pos_type i = 0; i < size(); ++i) {
1091 LyXFont font = getFontSettings(bparams, i);
1092 if (font.language() == from) {
1093 font.setLanguage(to);
1100 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1102 Language const * doc_language = bparams.language;
1103 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1104 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1106 for (; cit != end; ++cit)
1107 if (cit->font().language() != ignore_language &&
1108 cit->font().language() != latex_language &&
1109 cit->font().language() != doc_language)
1115 // Convert the paragraph to a string.
1116 // Used for building the table of contents
1117 string const Paragraph::asString(Buffer const & buffer, bool label) const
1121 if (label && !params().labelString().empty())
1122 s += params().labelString() + ' ';
1124 for (pos_type i = 0; i < size(); ++i) {
1125 value_type c = getChar(i);
1128 else if (c == META_INSET &&
1129 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1131 getInset(i)->ascii(buffer, ost);
1132 s += subst(STRCONV(ost.str()),'\n',' ');
1138 // This should really be done by the caller and not here.
1139 string ret(asString(buffer, 0, size(), label));
1140 return subst(ret, '\n', ' ');
1145 string const Paragraph::asString(Buffer const & buffer,
1146 pos_type beg, pos_type end, bool label) const
1150 if (beg == 0 && label && !params().labelString().empty())
1151 os << params().labelString() << ' ';
1153 for (pos_type i = beg; i < end; ++i) {
1154 value_type const c = getUChar(buffer.params(), i);
1157 else if (c == META_INSET)
1158 getInset(i)->ascii(buffer, os);
1161 return STRCONV(os.str());
1165 void Paragraph::setInsetOwner(UpdatableInset * inset)
1167 pimpl_->inset_owner = inset;
1168 InsetList::iterator it = insetlist.begin();
1169 InsetList::iterator end = insetlist.end();
1170 for (; it != end; ++it)
1172 it->inset->setOwner(inset);
1176 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1178 insetlist.deleteInsetsLyXText(bv);
1182 void Paragraph::setContentsFromPar(Paragraph const & par)
1184 pimpl_->setContentsFromPar(par);
1188 void Paragraph::trackChanges(Change::Type type)
1190 pimpl_->trackChanges(type);
1194 void Paragraph::untrackChanges()
1196 pimpl_->untrackChanges();
1200 void Paragraph::cleanChanges()
1202 pimpl_->cleanChanges();
1206 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1208 Assert(!size() || pos < size());
1209 return pimpl_->lookupChange(pos);
1213 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1215 Assert(!size() || pos < size());
1216 return pimpl_->lookupChangeFull(pos);
1220 bool Paragraph::isChanged(pos_type start, pos_type end) const
1222 return pimpl_->isChanged(start, end);
1226 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1228 return pimpl_->isChangeEdited(start, end);
1232 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1234 pimpl_->setChange(pos, type);
1239 void Paragraph::markErased()
1241 pimpl_->markErased();
1245 void Paragraph::acceptChange(pos_type start, pos_type end)
1247 return pimpl_->acceptChange(start, end);
1251 void Paragraph::rejectChange(pos_type start, pos_type end)
1253 return pimpl_->rejectChange(start, end);
1257 lyx::pos_type Paragraph::size() const
1259 return pimpl_->size();
1263 bool Paragraph::empty() const
1265 return pimpl_->empty();
1269 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1271 return pimpl_->getChar(pos);
1275 int Paragraph::id() const
1281 void Paragraph::id(int i)
1287 LyXLayout_ptr const & Paragraph::layout() const
1290 InsetOld * inset = inInset();
1291 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1292 return static_cast<InsetEnvironment*>(inset)->layout();
1298 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1300 layout_ = new_layout;
1304 UpdatableInset * Paragraph::inInset() const
1306 return pimpl_->inset_owner;
1310 void Paragraph::clearContents()
1315 void Paragraph::setChar(pos_type pos, value_type c)
1317 pimpl_->setChar(pos, c);
1321 ParagraphParameters & Paragraph::params()
1323 return pimpl_->params;
1327 ParagraphParameters const & Paragraph::params() const
1329 return pimpl_->params;
1333 bool Paragraph::isFreeSpacing() const
1335 if (layout()->free_spacing)
1338 // for now we just need this, later should we need this in some
1339 // other way we can always add a function to InsetOld too.
1340 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1341 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1346 bool Paragraph::allowEmpty() const
1348 if (layout()->keepempty)
1350 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1351 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;