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"
30 #include "support/std_sstream.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"
40 using namespace lyx::support;
46 using std::lower_bound;
47 using std::upper_bound;
52 Paragraph::Paragraph()
53 : y(0), pimpl_(new Paragraph::Pimpl(this))
61 Paragraph::Paragraph(Paragraph const & lp)
62 : y(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
66 // this is because of the dummy layout of the paragraphs that
68 layout_ = lp.layout();
70 // copy everything behind the break-position to the new paragraph
71 insetlist = lp.insetlist;
72 InsetList::iterator it = insetlist.begin();
73 InsetList::iterator end = insetlist.end();
74 for (; it != end; ++it) {
75 // currently we hold Inset*, not InsetBase*
76 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
81 void Paragraph::operator=(Paragraph const & lp)
83 // needed as we will destroy the pimpl_ before copying it
87 lyxerr << "Paragraph::operator=()" << endl;
90 pimpl_ = new Pimpl(*lp.pimpl_, this);
92 enumdepth = lp.enumdepth;
93 itemdepth = lp.itemdepth;
94 // this is because of the dummy layout of the paragraphs that
96 layout_ = lp.layout();
98 // copy everything behind the break-position to the new paragraph
99 insetlist = lp.insetlist;
100 InsetList::iterator it = insetlist.begin();
101 InsetList::iterator end = insetlist.end();
102 for (; it != end; ++it) {
103 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
107 // the destructor removes the new paragraph from the list
108 Paragraph::~Paragraph()
112 //lyxerr << "Paragraph::paragraph_id = "
113 // << Paragraph::paragraph_id << endl;
117 void Paragraph::write(Buffer const & buf, ostream & os,
118 BufferParams const & bparams,
119 depth_type & dth) const
121 // The beginning or end of a deeper (i.e. nested) area?
122 if (dth != params().depth()) {
123 if (params().depth() > dth) {
124 while (params().depth() > dth) {
125 os << "\n\\begin_deeper ";
129 while (params().depth() < dth) {
130 os << "\n\\end_deeper ";
136 // First write the layout
137 os << "\n\\begin_layout " << layout()->name() << '\n';
141 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
143 Change running_change = Change(Change::UNCHANGED);
144 lyx::time_type const curtime(lyx::current_time());
147 for (pos_type i = 0; i < size(); ++i) {
153 Change change = pimpl_->lookupChangeFull(i);
154 Changes::lyxMarkChange(os, column, curtime, running_change, change);
155 running_change = change;
157 // Write font changes
158 LyXFont font2 = getFontSettings(bparams, i);
159 if (font2 != font1) {
160 font2.lyxWriteChanges(font1, os);
165 value_type const c = getChar(i);
169 InsetOld const * inset = getInset(i);
171 if (inset->directWrite()) {
172 // international char, let it write
173 // code directly so it's shorter in
175 inset->write(buf, os);
177 os << "\n\\begin_inset ";
178 inset->write(buf, os);
179 os << "\n\\end_inset \n\n";
185 os << "\n\\backslash \n";
189 if (i + 1 < size() && getChar(i + 1) == ' ') {
196 if ((column > 70 && c == ' ')
201 // this check is to amend a bug. LyX sometimes
202 // inserts '\0' this could cause problems.
206 lyxerr << "ERROR (Paragraph::writeFile):"
207 " NULL char in structure." << endl;
213 // to make reading work properly
215 running_change = pimpl_->lookupChange(0);
216 Changes::lyxMarkChange(os, column, curtime,
217 Change(Change::UNCHANGED), running_change);
219 Changes::lyxMarkChange(os, column, curtime,
220 running_change, Change(Change::UNCHANGED));
222 os << "\n\\end_layout\n";
226 void Paragraph::validate(LaTeXFeatures & features) const
228 pimpl_->validate(features, *layout());
232 void Paragraph::eraseIntern(lyx::pos_type pos)
234 pimpl_->eraseIntern(pos);
238 bool Paragraph::erase(pos_type pos)
240 return pimpl_->erase(pos);
244 int Paragraph::erase(pos_type start, pos_type end)
246 return pimpl_->erase(start, end);
250 bool Paragraph::checkInsertChar(LyXFont & font)
252 if (pimpl_->inset_owner)
253 return pimpl_->inset_owner->checkInsertChar(font);
258 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
260 insertChar(pos, c, LyXFont(LyXFont::ALL_INHERIT));
264 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
265 LyXFont const & font, Change change)
267 pimpl_->insertChar(pos, c, font, change);
271 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
273 insertInset(pos, inset, LyXFont(LyXFont::ALL_INHERIT));
277 void Paragraph::insertInset(pos_type pos, InsetOld * inset,
278 LyXFont const & font, Change change)
280 pimpl_->insertInset(pos, inset, font, change);
284 bool Paragraph::insetAllowed(InsetOld::Code code)
286 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
287 if (pimpl_->inset_owner)
288 return pimpl_->inset_owner->insetAllowed(code);
293 InsetOld * Paragraph::getInset(pos_type pos)
295 Assert(pos < size());
296 return insetlist.get(pos);
300 InsetOld const * Paragraph::getInset(pos_type pos) const
302 Assert(pos < size());
303 return insetlist.get(pos);
307 // Gets uninstantiated font setting at position.
308 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
311 Assert(pos <= size());
313 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
314 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
315 for (; cit != end; ++cit)
316 if (cit->pos() >= pos)
322 if (pos == size() && !empty())
323 return getFontSettings(bparams, pos - 1);
325 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
329 lyx::pos_type Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
331 Assert(pos <= size());
333 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
334 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
335 for (; cit != end; ++cit)
336 if (cit->pos() >= pos)
339 // This should not happen, but if so, we take no chances.
340 //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
346 // Gets uninstantiated font setting at position 0
347 LyXFont const Paragraph::getFirstFontSettings() const
349 if (!empty() && !pimpl_->fontlist.empty())
350 return pimpl_->fontlist[0].font();
352 return LyXFont(LyXFont::ALL_INHERIT);
356 // Gets the fully instantiated font at a given position in a paragraph
357 // This is basically the same function as LyXText::GetFont() in text2.C.
358 // The difference is that this one is used for generating the LaTeX file,
359 // and thus cosmetic "improvements" are disallowed: This has to deliver
360 // the true picture of the buffer. (Asger)
361 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
362 LyXFont const & outerfont) const
366 LyXLayout_ptr const & lout = layout();
368 pos_type const body_pos = beginningOfBody();
372 layoutfont = lout->labelfont;
374 layoutfont = lout->font;
376 LyXFont tmpfont = getFontSettings(bparams, pos);
377 tmpfont.realize(layoutfont);
378 tmpfont.realize(outerfont);
379 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
385 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
386 LyXFont const & outerfont) const
388 LyXFont tmpfont = layout()->labelfont;
389 tmpfont.setLanguage(getParLanguage(bparams));
390 tmpfont.realize(outerfont);
391 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
396 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
397 LyXFont const & outerfont) const
399 LyXFont tmpfont = layout()->font;
400 tmpfont.setLanguage(getParLanguage(bparams));
401 tmpfont.realize(outerfont);
402 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
407 /// Returns the height of the highest font in range
409 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
410 LyXFont::FONT_SIZE const def_size) const
412 if (pimpl_->fontlist.empty())
415 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
416 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
417 for (; end_it != end; ++end_it) {
418 if (end_it->pos() >= endpos)
425 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
426 for (; cit != end; ++cit) {
427 if (cit->pos() >= startpos)
431 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
432 for (; cit != end_it; ++cit) {
433 LyXFont::FONT_SIZE size = cit->font().size();
434 if (size == LyXFont::INHERIT_SIZE)
436 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
443 Paragraph::value_type
444 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
446 value_type c = getChar(pos);
447 if (!lyxrc.rtl_support)
477 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
484 void Paragraph::setFont(pos_type pos, LyXFont const & font)
486 Assert(pos <= size());
488 // First, reduce font against layout/label font
489 // Update: The SetCharFont() routine in text2.C already
490 // reduces font, so we don't need to do that here. (Asger)
491 // No need to simplify this because it will disappear
492 // in a new kernel. (Asger)
493 // Next search font table
495 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
496 Pimpl::FontList::iterator it = beg;
497 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
498 for (; it != endit; ++it) {
499 if (it->pos() >= pos)
502 unsigned int i = std::distance(beg, it);
503 bool notfound = (it == endit);
505 if (!notfound && pimpl_->fontlist[i].font() == font)
508 bool begin = pos == 0 || notfound ||
509 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
510 // Is position pos is a beginning of a font block?
511 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
512 // Is position pos is the end of a font block?
513 if (begin && end) { // A single char block
514 if (i + 1 < pimpl_->fontlist.size() &&
515 pimpl_->fontlist[i + 1].font() == font) {
516 // Merge the singleton block with the next block
517 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
518 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
519 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
520 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
521 // Merge the singleton block with the previous block
522 pimpl_->fontlist[i - 1].pos(pos);
523 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
525 pimpl_->fontlist[i].font(font);
527 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
528 pimpl_->fontlist[i - 1].pos(pos);
530 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
531 Pimpl::FontTable(pos, font));
533 pimpl_->fontlist[i].pos(pos - 1);
534 if (!(i + 1 < pimpl_->fontlist.size() &&
535 pimpl_->fontlist[i + 1].font() == font))
536 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
537 Pimpl::FontTable(pos, font));
538 } else { // The general case. The block is splitted into 3 blocks
539 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
540 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
541 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
542 Pimpl::FontTable(pos, font));
547 void Paragraph::makeSameLayout(Paragraph const & par)
549 layout(par.layout());
551 params() = par.params();
555 int Paragraph::stripLeadingSpaces()
561 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
562 pimpl_->eraseIntern(0);
570 bool Paragraph::hasSameLayout(Paragraph const & par) const
573 par.layout() == layout() &&
574 params().sameLayout(par.params());
578 Paragraph::depth_type Paragraph::getDepth() const
580 return params().depth();
584 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
586 if (layout()->isEnvironment())
587 return params().depth() + 1;
589 return params().depth();
593 char Paragraph::getAlign() const
595 return params().align();
599 string const & Paragraph::getLabelstring() const
601 return params().labelString();
605 // the next two functions are for the manual labels
606 string const Paragraph::getLabelWidthString() const
608 if (!params().labelWidthString().empty())
609 return params().labelWidthString();
611 return _("Senseless with this layout!");
615 void Paragraph::setLabelWidthString(string const & s)
617 params().labelWidthString(s);
621 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
624 params().labelWidthString(string());
625 params().align(LYX_ALIGN_LAYOUT);
626 params().spaceTop(VSpace(VSpace::NONE));
627 params().spaceBottom(VSpace(VSpace::NONE));
628 params().spacing(Spacing(Spacing::Default));
632 int Paragraph::beginningOfBody() const
634 if (layout()->labeltype != LABEL_MANUAL)
637 // Unroll the first two cycles of the loop
638 // and remember the previous character to
639 // remove unnecessary GetChar() calls
641 if (i < size() && !isNewline(i)) {
643 char previous_char = 0;
646 previous_char = getChar(i);
649 while (i < size() && previous_char != ' ') {
655 previous_char = temp;
665 // returns -1 if inset not found
666 int Paragraph::getPositionOfInset(InsetOld const * inset) const
669 InsetList::const_iterator it = insetlist.begin();
670 InsetList::const_iterator end = insetlist.end();
671 for (; it != end; ++it)
672 if (it->inset == inset)
678 InsetBibitem * Paragraph::bibitem() const
680 InsetList::const_iterator it = insetlist.begin();
681 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
682 return static_cast<InsetBibitem *>(it->inset);
688 // This could go to ParagraphParameters if we want to
689 int Paragraph::startTeXParParams(BufferParams const & bparams,
690 ostream & os, bool moving_arg) const
694 if (params().noindent()) {
699 switch (params().align()) {
701 case LYX_ALIGN_BLOCK:
702 case LYX_ALIGN_LAYOUT:
703 case LYX_ALIGN_SPECIAL:
706 case LYX_ALIGN_RIGHT:
707 case LYX_ALIGN_CENTER:
715 switch (params().align()) {
717 case LYX_ALIGN_BLOCK:
718 case LYX_ALIGN_LAYOUT:
719 case LYX_ALIGN_SPECIAL:
722 if (getParLanguage(bparams)->babel() != "hebrew") {
723 os << "\\begin{flushleft}";
726 os << "\\begin{flushright}";
730 case LYX_ALIGN_RIGHT:
731 if (getParLanguage(bparams)->babel() != "hebrew") {
732 os << "\\begin{flushright}";
735 os << "\\begin{flushleft}";
739 case LYX_ALIGN_CENTER:
740 os << "\\begin{center}";
749 // This could go to ParagraphParameters if we want to
750 int Paragraph::endTeXParParams(BufferParams const & bparams,
751 ostream & os, bool moving_arg) const
755 switch (params().align()) {
757 case LYX_ALIGN_BLOCK:
758 case LYX_ALIGN_LAYOUT:
759 case LYX_ALIGN_SPECIAL:
762 case LYX_ALIGN_RIGHT:
763 case LYX_ALIGN_CENTER:
771 switch (params().align()) {
773 case LYX_ALIGN_BLOCK:
774 case LYX_ALIGN_LAYOUT:
775 case LYX_ALIGN_SPECIAL:
778 if (getParLanguage(bparams)->babel() != "hebrew") {
779 os << "\\end{flushleft}";
782 os << "\\end{flushright}";
786 case LYX_ALIGN_RIGHT:
787 if (getParLanguage(bparams)->babel() != "hebrew") {
788 os << "\\end{flushright}";
791 os << "\\end{flushleft}";
795 case LYX_ALIGN_CENTER:
796 os << "\\end{center}";
804 // This one spits out the text of the paragraph
805 bool Paragraph::simpleTeXOnePar(Buffer const & buf,
806 BufferParams const & bparams,
807 LyXFont const & outerfont,
808 ostream & os, TexRow & texrow,
809 LatexRunParams const & runparams)
811 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
813 bool return_value = false;
817 // well we have to check if we are in an inset with unlimited
818 // lenght (all in one row) if that is true then we don't allow
819 // any special options in the paragraph and also we don't allow
820 // any environment other then "Standard" to be valid!
822 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
825 style = bparams.getLyXTextClass().defaultLayout();
832 // Maybe we have to create a optional argument.
835 // FIXME: can we actually skip this check and just call
836 // beginningOfBody() ??
837 if (style->labeltype != LABEL_MANUAL) {
840 body_pos = beginningOfBody();
843 unsigned int column = 0;
848 basefont = getLabelFont(bparams, outerfont);
850 basefont = getLayoutFont(bparams, outerfont);
853 bool moving_arg = runparams.moving_arg;
854 moving_arg |= style->needprotect;
856 // Which font is currently active?
857 LyXFont running_font(basefont);
858 // Do we have an open font change?
859 bool open_font = false;
861 Change::Type running_change = Change::UNCHANGED;
863 texrow.start(id(), 0);
865 // if the paragraph is empty, the loop will not be entered at all
867 if (style->isCommand()) {
872 column += startTeXParParams(bparams, os, moving_arg);
876 for (pos_type i = 0; i < size(); ++i) {
878 // First char in paragraph or after label?
882 column += running_font.latexWriteEndChanges(os, basefont, basefont);
885 basefont = getLayoutFont(bparams, outerfont);
886 running_font = basefont;
890 if (style->isCommand()) {
896 column += startTeXParParams(bparams, os,
900 value_type c = getChar(i);
902 // Fully instantiated font
903 LyXFont font = getFont(bparams, i, outerfont);
905 LyXFont const last_font = running_font;
907 // Spaces at end of font change are simulated to be
908 // outside font change, i.e. we write "\textXX{text} "
909 // rather than "\textXX{text }". (Asger)
910 if (open_font && c == ' ' && i <= size() - 2) {
911 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
912 if (next_font != running_font
913 && next_font != font) {
918 // We end font definition before blanks
920 (font != running_font ||
921 font.language() != running_font.language()))
923 column += running_font.latexWriteEndChanges(os,
925 (i == body_pos-1) ? basefont : font);
926 running_font = basefont;
930 // Blanks are printed before start of fontswitch
932 // Do not print the separation of the optional argument
933 if (i != body_pos - 1) {
934 pimpl_->simpleTeXBlanks(os, texrow, i,
935 column, font, *style);
939 // Do we need to change font?
940 if ((font != running_font ||
941 font.language() != running_font.language()) &&
944 column += font.latexWriteStartChanges(os, basefont,
950 Change::Type change = pimpl_->lookupChange(i);
952 column += Changes::latexMarkChange(os, running_change, change);
953 running_change = change;
955 LatexRunParams rp = runparams;
956 rp.moving_arg = moving_arg;
957 rp.free_spacing = style->free_spacing;
958 pimpl_->simpleTeXSpecialChars(buf, bparams,
959 os, texrow, runparams,
961 basefont, outerfont, open_font,
963 *style, i, column, c);
966 column += Changes::latexMarkChange(os,
967 running_change, Change::UNCHANGED);
969 // If we have an open font definition, we have to close it
971 #ifdef FIXED_LANGUAGE_END_DETECTION
974 .latexWriteEndChanges(os, basefont,
975 next_->getFont(bparams,
978 running_font.latexWriteEndChanges(os, basefont,
983 //#warning For now we ALWAYS have to close the foreign font settings if they are
984 //#warning there as we start another \selectlanguage with the next paragraph if
985 //#warning we are in need of this. This should be fixed sometime (Jug)
987 running_font.latexWriteEndChanges(os, basefont, basefont);
991 // Needed if there is an optional argument but no contents.
992 if (body_pos > 0 && body_pos == size()) {
994 return_value = false;
998 column += endTeXParParams(bparams, os, moving_arg);
1001 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1002 return return_value;
1008 bool Paragraph::isHfill(pos_type pos) const
1010 return IsInsetChar(getChar(pos))
1011 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1015 bool Paragraph::isInset(pos_type pos) const
1017 return IsInsetChar(getChar(pos));
1021 bool Paragraph::isNewline(pos_type pos) const
1023 return IsInsetChar(getChar(pos))
1024 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1028 bool Paragraph::isSeparator(pos_type pos) const
1030 return IsSeparatorChar(getChar(pos));
1034 bool Paragraph::isLineSeparator(pos_type pos) const
1036 value_type const c = getChar(pos);
1037 return IsLineSeparatorChar(c)
1038 || (IsInsetChar(c) && getInset(pos) &&
1039 getInset(pos)->isLineSeparator());
1043 bool Paragraph::isKomma(pos_type pos) const
1045 return IsKommaChar(getChar(pos));
1049 /// Used by the spellchecker
1050 bool Paragraph::isLetter(pos_type pos) const
1052 value_type const c = getChar(pos);
1053 if (IsLetterChar(c))
1056 return getInset(pos)->isLetter();
1057 // We want to pass the ' and escape chars to ispell
1058 string const extra = lyxrc.isp_esc_chars + '\'';
1059 return contains(extra, c);
1063 bool Paragraph::isWord(pos_type pos) const
1065 return IsWordChar(getChar(pos)) ;
1070 Paragraph::getParLanguage(BufferParams const & bparams) const
1073 return getFirstFontSettings().language();
1074 #warning FIXME we should check the prev par as well (Lgb)
1075 return bparams.language;
1079 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1081 return lyxrc.rtl_support
1082 && getParLanguage(bparams)->RightToLeft()
1083 && !(inInset() && inInset()->owner() &&
1084 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1088 void Paragraph::changeLanguage(BufferParams const & bparams,
1089 Language const * from, Language const * to)
1091 for (pos_type i = 0; i < size(); ++i) {
1092 LyXFont font = getFontSettings(bparams, i);
1093 if (font.language() == from) {
1094 font.setLanguage(to);
1101 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1103 Language const * doc_language = bparams.language;
1104 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1105 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1107 for (; cit != end; ++cit)
1108 if (cit->font().language() != ignore_language &&
1109 cit->font().language() != latex_language &&
1110 cit->font().language() != doc_language)
1116 // Convert the paragraph to a string.
1117 // Used for building the table of contents
1118 string const Paragraph::asString(Buffer const & buffer, bool label) const
1122 if (label && !params().labelString().empty())
1123 s += params().labelString() + ' ';
1125 for (pos_type i = 0; i < size(); ++i) {
1126 value_type c = getChar(i);
1129 else if (c == META_INSET &&
1130 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1132 getInset(i)->ascii(buffer, ost);
1133 s += subst(STRCONV(ost.str()),'\n',' ');
1139 // This should really be done by the caller and not here.
1140 string ret(asString(buffer, 0, size(), label));
1141 return subst(ret, '\n', ' ');
1146 string const Paragraph::asString(Buffer const & buffer,
1147 pos_type beg, pos_type end, bool label) const
1151 if (beg == 0 && label && !params().labelString().empty())
1152 os << params().labelString() << ' ';
1154 for (pos_type i = beg; i < end; ++i) {
1155 value_type const c = getUChar(buffer.params, i);
1158 else if (c == META_INSET)
1159 getInset(i)->ascii(buffer, os);
1162 return STRCONV(os.str());
1166 void Paragraph::setInsetOwner(UpdatableInset * inset)
1168 pimpl_->inset_owner = inset;
1169 InsetList::iterator it = insetlist.begin();
1170 InsetList::iterator end = insetlist.end();
1171 for (; it != end; ++it)
1173 it->inset->setOwner(inset);
1177 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1179 insetlist.deleteInsetsLyXText(bv);
1183 void Paragraph::setContentsFromPar(Paragraph const & par)
1185 pimpl_->setContentsFromPar(par);
1189 void Paragraph::trackChanges(Change::Type type)
1191 pimpl_->trackChanges(type);
1195 void Paragraph::untrackChanges()
1197 pimpl_->untrackChanges();
1201 void Paragraph::cleanChanges()
1203 pimpl_->cleanChanges();
1207 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1209 Assert(!size() || pos < size());
1210 return pimpl_->lookupChange(pos);
1214 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1216 Assert(!size() || pos < size());
1217 return pimpl_->lookupChangeFull(pos);
1221 bool Paragraph::isChanged(pos_type start, pos_type end) const
1223 return pimpl_->isChanged(start, end);
1227 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1229 return pimpl_->isChangeEdited(start, end);
1233 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1235 pimpl_->setChange(pos, type);
1240 void Paragraph::markErased()
1242 pimpl_->markErased();
1246 void Paragraph::acceptChange(pos_type start, pos_type end)
1248 return pimpl_->acceptChange(start, end);
1252 void Paragraph::rejectChange(pos_type start, pos_type end)
1254 return pimpl_->rejectChange(start, end);
1258 lyx::pos_type Paragraph::size() const
1260 return pimpl_->size();
1264 bool Paragraph::empty() const
1266 return pimpl_->empty();
1270 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1272 return pimpl_->getChar(pos);
1276 int Paragraph::id() const
1282 void Paragraph::id(int i)
1288 LyXLayout_ptr const & Paragraph::layout() const
1291 InsetOld * inset = inInset();
1292 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1293 return static_cast<InsetEnvironment*>(inset)->layout();
1299 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1301 layout_ = new_layout;
1305 UpdatableInset * Paragraph::inInset() const
1307 return pimpl_->inset_owner;
1311 void Paragraph::clearContents()
1316 void Paragraph::setChar(pos_type pos, value_type c)
1318 pimpl_->setChar(pos, c);
1322 ParagraphParameters & Paragraph::params()
1324 return pimpl_->params;
1328 ParagraphParameters const & Paragraph::params() const
1330 return pimpl_->params;
1334 bool Paragraph::isFreeSpacing() const
1336 if (layout()->free_spacing)
1339 // for now we just need this, later should we need this in some
1340 // other way we can always add a function to InsetOld too.
1341 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1342 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;
1347 bool Paragraph::allowEmpty() const
1349 if (layout()->keepempty)
1351 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1352 return pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE;