1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
13 #include "paragraph.h"
14 #include "paragraph_pimpl.h"
19 #include "bufferparams.h"
22 #include "BufferView.h"
24 #include "ParameterStruct.h"
27 #include "paragraph_funcs.h"
30 #include "insets/insetbibitem.h"
31 #include "insets/insetoptarg.h"
32 #include "insets/insetenv.h"
34 #include "support/filetools.h"
35 #include "support/lstrings.h"
36 #include "support/lyxmanip.h"
37 #include "support/FileInfo.h"
38 #include "support/LAssert.h"
39 #include "support/textutils.h"
50 using std::lower_bound;
51 using std::upper_bound;
56 // this is a minibuffer
61 LyXFont minibuffer_font;
62 Inset * minibuffer_inset;
67 extern BufferView * current_view;
70 Paragraph::Paragraph()
71 : pimpl_(new Paragraph::Pimpl(this))
83 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
84 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
92 // this is because of the dummy layout of the paragraphs that
94 layout_ = lp.layout();
96 // copy everything behind the break-position to the new paragraph
97 insetlist = lp.insetlist;
98 InsetList::iterator it = insetlist.begin();
99 InsetList::iterator end = insetlist.end();
100 for (; it != end; ++it) {
101 it.setInset(it.getInset()->clone(*current_view->buffer(),
103 // tell the new inset who is the boss now
104 it.getInset()->parOwner(this);
109 // the destructor removes the new paragraph from the list
110 Paragraph::~Paragraph()
114 previous_->next_ = next_;
116 next_->previous_ = previous_;
121 //lyxerr << "Paragraph::paragraph_id = "
122 // << Paragraph::paragraph_id << endl;
126 void Paragraph::write(Buffer const * buf, ostream & os,
127 BufferParams const & bparams,
128 depth_type & dth) const
130 // The beginning or end of a deeper (i.e. nested) area?
131 if (dth != params().depth()) {
132 if (params().depth() > dth) {
133 while (params().depth() > dth) {
134 os << "\n\\begin_deeper ";
138 while (params().depth() < dth) {
139 os << "\n\\end_deeper ";
145 // First write the layout
146 os << "\n\\layout " << layout()->name() << '\n';
150 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
152 Change running_change = Change(Change::UNCHANGED);
153 lyx::time_type const curtime(lyx::current_time());
156 for (pos_type i = 0; i < size(); ++i) {
162 Change change = pimpl_->lookupChangeFull(i);
163 Changes::lyxMarkChange(os, column, curtime, running_change, change);
164 running_change = change;
166 // Write font changes
167 LyXFont font2 = getFontSettings(bparams, i);
168 if (font2 != font1) {
169 font2.lyxWriteChanges(font1, os);
174 value_type const c = getChar(i);
178 Inset const * inset = getInset(i);
180 if (inset->directWrite()) {
181 // international char, let it write
182 // code directly so it's shorter in
184 inset->write(buf, os);
186 os << "\n\\begin_inset ";
187 inset->write(buf, os);
188 os << "\n\\end_inset \n\n";
194 os << "\n\\backslash \n";
198 if (i + 1 < size() && getChar(i + 1) == ' ') {
205 if ((column > 70 && c == ' ')
210 // this check is to amend a bug. LyX sometimes
211 // inserts '\0' this could cause problems.
215 lyxerr << "ERROR (Paragraph::writeFile):"
216 " NULL char in structure." << endl;
222 // to make reading work properly
224 running_change = pimpl_->lookupChange(0);
225 Changes::lyxMarkChange(os, column, curtime,
226 Change(Change::UNCHANGED), running_change);
228 Changes::lyxMarkChange(os, column, curtime,
229 running_change, Change(Change::UNCHANGED));
233 void Paragraph::validate(LaTeXFeatures & features) const
235 pimpl_->validate(features, *layout());
239 // First few functions needed for cut and paste and paragraph breaking.
240 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
242 BufferParams bparams = buffer.params;
244 minibuffer_char = getChar(pos);
245 minibuffer_font = getFontSettings(bparams, pos);
246 minibuffer_inset = 0;
247 if (minibuffer_char == Paragraph::META_INSET) {
249 minibuffer_inset = getInset(pos)->clone(buffer);
251 minibuffer_inset = 0;
252 minibuffer_char = ' ';
253 // This reflects what GetInset() does (ARRae)
259 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
261 minibuffer_char = getChar(pos);
262 minibuffer_font = getFontSettings(bparams, pos);
263 minibuffer_inset = 0;
264 if (minibuffer_char == Paragraph::META_INSET) {
266 // the inset is not in a paragraph anymore
267 minibuffer_inset = insetlist.release(pos);
268 minibuffer_inset->parOwner(0);
270 minibuffer_inset = 0;
271 minibuffer_char = ' ';
272 // This reflects what GetInset() does (ARRae)
277 // Erase(pos); now the caller is responsible for that.
281 bool Paragraph::insertFromMinibuffer(pos_type pos)
283 if (minibuffer_char == Paragraph::META_INSET) {
284 if (!insetAllowed(minibuffer_inset->lyxCode())) {
287 insertInset(pos, minibuffer_inset, minibuffer_font);
289 LyXFont f = minibuffer_font;
290 if (!checkInsertChar(f)) {
293 insertChar(pos, minibuffer_char, f);
301 void Paragraph::eraseIntern(lyx::pos_type pos)
303 pimpl_->eraseIntern(pos);
307 bool Paragraph::erase(pos_type pos)
309 return pimpl_->erase(pos);
313 int Paragraph::erase(pos_type start, pos_type end)
315 return pimpl_->erase(start, end);
319 bool Paragraph::checkInsertChar(LyXFont & font)
321 if (pimpl_->inset_owner)
322 return pimpl_->inset_owner->checkInsertChar(font);
327 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
329 LyXFont const f(LyXFont::ALL_INHERIT);
330 insertChar(pos, c, f);
334 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
335 LyXFont const & font, Change change)
337 pimpl_->insertChar(pos, c, font, change);
341 void Paragraph::insertInset(pos_type pos, Inset * inset)
343 LyXFont const f(LyXFont::ALL_INHERIT);
344 insertInset(pos, inset, f);
348 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
350 pimpl_->insertInset(pos, inset, font, change);
354 bool Paragraph::insetAllowed(Inset::Code code)
356 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
357 if (pimpl_->inset_owner)
358 return pimpl_->inset_owner->insetAllowed(code);
363 Inset * Paragraph::getInset(pos_type pos)
365 lyx::Assert(pos < size());
366 return insetlist.get(pos);
370 Inset const * Paragraph::getInset(pos_type pos) const
372 lyx::Assert(pos < size());
373 return insetlist.get(pos);
377 // Gets uninstantiated font setting at position.
378 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
381 lyx::Assert(pos <= size());
383 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
384 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
385 for (; cit != end; ++cit) {
386 if (cit->pos() >= pos)
392 retfont = cit->font();
393 else if (pos == size() && !empty())
394 retfont = getFontSettings(bparams, pos - 1);
396 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
402 // Gets uninstantiated font setting at position 0
403 LyXFont const Paragraph::getFirstFontSettings() const
405 if (!empty() && !pimpl_->fontlist.empty())
406 return pimpl_->fontlist[0].font();
408 return LyXFont(LyXFont::ALL_INHERIT);
412 // Gets the fully instantiated font at a given position in a paragraph
413 // This is basically the same function as LyXText::GetFont() in text2.C.
414 // The difference is that this one is used for generating the LaTeX file,
415 // and thus cosmetic "improvements" are disallowed: This has to deliver
416 // the true picture of the buffer. (Asger)
417 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
418 LyXFont const & outerfont) const
420 lyx::Assert(pos >= 0);
422 LyXLayout_ptr const & lout = layout();
424 pos_type const body_pos = beginningOfBody();
428 layoutfont = lout->labelfont;
430 layoutfont = lout->font;
432 LyXFont tmpfont = getFontSettings(bparams, pos);
433 tmpfont.realize(layoutfont);
434 tmpfont.realize(outerfont);
436 return realizeFont(tmpfont, bparams);
440 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
441 LyXFont const & outerfont) const
443 LyXLayout_ptr const & lout = layout();
445 LyXFont tmpfont = lout->labelfont;
446 tmpfont.setLanguage(getParLanguage(bparams));
447 tmpfont.realize(outerfont);
449 return realizeFont(tmpfont, bparams);
453 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
454 LyXFont const & outerfont) const
456 LyXLayout_ptr const & lout = layout();
458 LyXFont tmpfont = lout->font;
459 tmpfont.setLanguage(getParLanguage(bparams));
460 tmpfont.realize(outerfont);
462 return realizeFont(tmpfont, bparams);
466 /// Returns the height of the highest font in range
468 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
469 LyXFont::FONT_SIZE const def_size) const
471 if (pimpl_->fontlist.empty())
474 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
475 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
476 for (; end_it != end; ++end_it) {
477 if (end_it->pos() >= endpos)
484 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
485 for (; cit != end; ++cit) {
486 if (cit->pos() >= startpos)
490 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
491 for (; cit != end_it; ++cit) {
492 LyXFont::FONT_SIZE size = cit->font().size();
493 if (size == LyXFont::INHERIT_SIZE)
495 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
502 Paragraph::value_type
503 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
505 value_type c = getChar(pos);
506 if (!lyxrc.rtl_support)
536 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
543 void Paragraph::setFont(pos_type pos, LyXFont const & font)
545 lyx::Assert(pos <= size());
547 // First, reduce font against layout/label font
548 // Update: The SetCharFont() routine in text2.C already
549 // reduces font, so we don't need to do that here. (Asger)
550 // No need to simplify this because it will disappear
551 // in a new kernel. (Asger)
552 // Next search font table
554 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
555 Pimpl::FontList::iterator it = beg;
556 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
557 for (; it != endit; ++it) {
558 if (it->pos() >= pos)
561 unsigned int i = std::distance(beg, it);
562 bool notfound = (it == endit);
564 if (!notfound && pimpl_->fontlist[i].font() == font)
567 bool begin = pos == 0 || notfound ||
568 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
569 // Is position pos is a beginning of a font block?
570 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
571 // Is position pos is the end of a font block?
572 if (begin && end) { // A single char block
573 if (i + 1 < pimpl_->fontlist.size() &&
574 pimpl_->fontlist[i + 1].font() == font) {
575 // Merge the singleton block with the next block
576 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
577 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
578 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
579 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
580 // Merge the singleton block with the previous block
581 pimpl_->fontlist[i - 1].pos(pos);
582 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
584 pimpl_->fontlist[i].font(font);
586 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
587 pimpl_->fontlist[i - 1].pos(pos);
589 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
590 Pimpl::FontTable(pos, font));
592 pimpl_->fontlist[i].pos(pos - 1);
593 if (!(i + 1 < pimpl_->fontlist.size() &&
594 pimpl_->fontlist[i + 1].font() == font))
595 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
596 Pimpl::FontTable(pos, font));
597 } else { // The general case. The block is splitted into 3 blocks
598 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
599 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
600 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
601 Pimpl::FontTable(pos, font));
607 void Paragraph::next(Paragraph * p)
613 // This function is able to hide closed footnotes.
614 Paragraph * Paragraph::next()
620 Paragraph const * Paragraph::next() const
626 void Paragraph::previous(Paragraph * p)
632 // This function is able to hide closed footnotes.
633 Paragraph * Paragraph::previous()
639 // This function is able to hide closed footnotes.
640 Paragraph const * Paragraph::previous() const
647 void Paragraph::makeSameLayout(Paragraph const & par)
649 layout(par.layout());
651 params() = par.params();
655 int Paragraph::stripLeadingSpaces()
657 if (layout()->free_spacing || isFreeSpacing())
661 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
662 pimpl_->eraseIntern(0);
670 bool Paragraph::hasSameLayout(Paragraph const & par) const
673 par.layout() == layout() &&
674 params().sameLayout(par.params());
678 Paragraph::depth_type Paragraph::getDepth() const
680 return params().depth();
684 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
686 if (layout()->isEnvironment())
687 return params().depth() + 1;
689 return params().depth();
693 char Paragraph::getAlign() const
695 return params().align();
699 string const & Paragraph::getLabelstring() const
701 return params().labelString();
705 // the next two functions are for the manual labels
706 string const Paragraph::getLabelWidthString() const
708 if (!params().labelWidthString().empty())
709 return params().labelWidthString();
711 return _("Senseless with this layout!");
715 void Paragraph::setLabelWidthString(string const & s)
717 params().labelWidthString(s);
721 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
724 params().labelWidthString(string());
725 params().align(LYX_ALIGN_LAYOUT);
726 params().spaceTop(VSpace(VSpace::NONE));
727 params().spaceBottom(VSpace(VSpace::NONE));
728 params().spacing(Spacing(Spacing::Default));
732 int Paragraph::beginningOfBody() const
734 if (layout()->labeltype != LABEL_MANUAL)
737 // Unroll the first two cycles of the loop
738 // and remember the previous character to
739 // remove unnecessary GetChar() calls
741 if (i < size() && !isNewline(i)) {
743 char previous_char = 0;
746 previous_char = getChar(i);
749 while (i < size() && previous_char != ' ') {
755 previous_char = temp;
765 // returns -1 if inset not found
766 int Paragraph::getPositionOfInset(Inset const * inset) const
769 InsetList::iterator it = insetlist.begin();
770 InsetList::iterator end = insetlist.end();
771 for (; it != end; ++it)
772 if (it.getInset() == inset)
778 InsetBibitem * Paragraph::bibitem()
780 InsetList::iterator it = insetlist.begin();
781 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
782 return static_cast<InsetBibitem *>(it.getInset());
788 // This could go to ParagraphParameters if we want to
789 int Paragraph::startTeXParParams(BufferParams const & bparams,
790 ostream & os, bool moving_arg) const
794 if (params().noindent()) {
799 switch (params().align()) {
801 case LYX_ALIGN_BLOCK:
802 case LYX_ALIGN_LAYOUT:
803 case LYX_ALIGN_SPECIAL:
806 case LYX_ALIGN_RIGHT:
807 case LYX_ALIGN_CENTER:
815 switch (params().align()) {
817 case LYX_ALIGN_BLOCK:
818 case LYX_ALIGN_LAYOUT:
819 case LYX_ALIGN_SPECIAL:
822 if (getParLanguage(bparams)->babel() != "hebrew") {
823 os << "\\begin{flushleft}";
826 os << "\\begin{flushright}";
830 case LYX_ALIGN_RIGHT:
831 if (getParLanguage(bparams)->babel() != "hebrew") {
832 os << "\\begin{flushright}";
835 os << "\\begin{flushleft}";
839 case LYX_ALIGN_CENTER:
840 os << "\\begin{center}";
849 // This could go to ParagraphParameters if we want to
850 int Paragraph::endTeXParParams(BufferParams const & bparams,
851 ostream & os, bool moving_arg) const
855 switch (params().align()) {
857 case LYX_ALIGN_BLOCK:
858 case LYX_ALIGN_LAYOUT:
859 case LYX_ALIGN_SPECIAL:
862 case LYX_ALIGN_RIGHT:
863 case LYX_ALIGN_CENTER:
871 switch (params().align()) {
873 case LYX_ALIGN_BLOCK:
874 case LYX_ALIGN_LAYOUT:
875 case LYX_ALIGN_SPECIAL:
878 if (getParLanguage(bparams)->babel() != "hebrew") {
879 os << "\\end{flushleft}";
882 os << "\\end{flushright}";
886 case LYX_ALIGN_RIGHT:
887 if (getParLanguage(bparams)->babel() != "hebrew") {
888 os << "\\end{flushright}";
891 os << "\\end{flushleft}";
895 case LYX_ALIGN_CENTER:
896 os << "\\end{center}";
904 // This one spits out the text of the paragraph
905 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
906 BufferParams const & bparams,
907 LyXFont const & outerfont,
908 ostream & os, TexRow & texrow,
911 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
913 bool return_value = false;
917 // well we have to check if we are in an inset with unlimited
918 // lenght (all in one row) if that is true then we don't allow
919 // any special options in the paragraph and also we don't allow
920 // any environment other then "Standard" to be valid!
922 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
925 style = bparams.getLyXTextClass().defaultLayout();
932 // Maybe we have to create a optional argument.
935 // FIXME: can we actually skip this check and just call
936 // beginningOfBody() ??
937 if (style->labeltype != LABEL_MANUAL) {
940 body_pos = beginningOfBody();
943 unsigned int column = 0;
948 basefont = getLabelFont(bparams, outerfont);
950 basefont = getLayoutFont(bparams, outerfont);
953 moving_arg |= style->needprotect;
955 // Which font is currently active?
956 LyXFont running_font(basefont);
957 // Do we have an open font change?
958 bool open_font = false;
960 Change::Type running_change = Change::UNCHANGED;
962 texrow.start(id(), 0);
964 // if the paragraph is empty, the loop will not be entered at all
966 if (style->isCommand()) {
971 column += startTeXParParams(bparams, os, moving_arg);
975 for (pos_type i = 0; i < size(); ++i) {
977 // First char in paragraph or after label?
981 column += running_font.latexWriteEndChanges(os, basefont, basefont);
984 basefont = getLayoutFont(bparams, outerfont);
985 running_font = basefont;
989 if (style->isCommand()) {
995 column += startTeXParParams(bparams, os,
999 value_type c = getChar(i);
1001 // Fully instantiated font
1002 LyXFont font = getFont(bparams, i, outerfont);
1004 LyXFont const last_font = running_font;
1006 // Spaces at end of font change are simulated to be
1007 // outside font change, i.e. we write "\textXX{text} "
1008 // rather than "\textXX{text }". (Asger)
1009 if (open_font && c == ' ' && i <= size() - 2) {
1010 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
1011 if (next_font != running_font
1012 && next_font != font) {
1017 // We end font definition before blanks
1019 (font != running_font ||
1020 font.language() != running_font.language()))
1022 column += running_font.latexWriteEndChanges(os,
1024 (i == body_pos-1) ? basefont : font);
1025 running_font = basefont;
1029 // Blanks are printed before start of fontswitch
1031 // Do not print the separation of the optional argument
1032 if (i != body_pos - 1) {
1033 pimpl_->simpleTeXBlanks(os, texrow, i,
1034 column, font, *style);
1038 // Do we need to change font?
1039 if ((font != running_font ||
1040 font.language() != running_font.language()) &&
1043 column += font.latexWriteStartChanges(os, basefont,
1045 running_font = font;
1049 Change::Type change = pimpl_->lookupChange(i);
1051 column += Changes::latexMarkChange(os, running_change, change);
1052 running_change = change;
1054 pimpl_->simpleTeXSpecialChars(buf, bparams,
1055 os, texrow, moving_arg,
1057 basefont, outerfont, open_font,
1059 *style, i, column, c);
1062 column += Changes::latexMarkChange(os,
1063 running_change, Change::UNCHANGED);
1065 // If we have an open font definition, we have to close it
1067 #ifdef FIXED_LANGUAGE_END_DETECTION
1070 .latexWriteEndChanges(os, basefont,
1071 next_->getFont(bparams,
1074 running_font.latexWriteEndChanges(os, basefont,
1078 #ifdef WITH_WARNINGS
1079 //#warning For now we ALWAYS have to close the foreign font settings if they are
1080 //#warning there as we start another \selectlanguage with the next paragraph if
1081 //#warning we are in need of this. This should be fixed sometime (Jug)
1083 running_font.latexWriteEndChanges(os, basefont, basefont);
1087 // Needed if there is an optional argument but no contents.
1088 if (body_pos > 0 && body_pos == size()) {
1090 return_value = false;
1094 column += endTeXParParams(bparams, os, moving_arg);
1097 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1098 return return_value;
1104 bool Paragraph::isHfill(pos_type pos) const
1106 return IsInsetChar(getChar(pos))
1107 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1111 bool Paragraph::isInset(pos_type pos) const
1113 return IsInsetChar(getChar(pos));
1117 bool Paragraph::isNewline(pos_type pos) const
1119 return IsInsetChar(getChar(pos))
1120 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1124 bool Paragraph::isSeparator(pos_type pos) const
1126 return IsSeparatorChar(getChar(pos));
1130 bool Paragraph::isLineSeparator(pos_type pos) const
1132 value_type const c = getChar(pos);
1133 return IsLineSeparatorChar(c)
1134 || (IsInsetChar(c) && getInset(pos) &&
1135 getInset(pos)->isLineSeparator());
1139 bool Paragraph::isKomma(pos_type pos) const
1141 return IsKommaChar(getChar(pos));
1145 /// Used by the spellchecker
1146 bool Paragraph::isLetter(pos_type pos) const
1148 value_type const c = getChar(pos);
1149 if (IsLetterChar(c))
1152 return getInset(pos)->isLetter();
1153 // We want to pass the ' and escape chars to ispell
1154 string const extra = lyxrc.isp_esc_chars + '\'';
1155 return contains(extra, c);
1159 bool Paragraph::isWord(pos_type pos) const
1161 return IsWordChar(getChar(pos)) ;
1166 Paragraph::getParLanguage(BufferParams const & bparams) const
1169 return getFirstFontSettings().language();
1170 #warning FIXME we should check the prev par as well (Lgb)
1172 } else if (previous_) {
1173 return previous_->getParLanguage(bparams);
1176 return bparams.language;
1180 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1182 return lyxrc.rtl_support
1183 && getParLanguage(bparams)->RightToLeft()
1184 && !(inInset() && inInset()->owner() &&
1185 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1189 void Paragraph::changeLanguage(BufferParams const & bparams,
1190 Language const * from, Language const * to)
1192 for (pos_type i = 0; i < size(); ++i) {
1193 LyXFont font = getFontSettings(bparams, i);
1194 if (font.language() == from) {
1195 font.setLanguage(to);
1202 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1204 Language const * doc_language = bparams.language;
1205 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1206 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1208 for (; cit != end; ++cit)
1209 if (cit->font().language() != ignore_language &&
1210 cit->font().language() != latex_language &&
1211 cit->font().language() != doc_language)
1217 // Convert the paragraph to a string.
1218 // Used for building the table of contents
1219 string const Paragraph::asString(Buffer const * buffer, bool label) const
1222 if (label && !params().labelString().empty())
1223 s += params().labelString() + ' ';
1225 for (pos_type i = 0; i < size(); ++i) {
1226 value_type c = getChar(i);
1229 else if (c == META_INSET &&
1230 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1232 getInset(i)->ascii(buffer, ost);
1233 s += subst(STRCONV(ost.str()),'\n',' ');
1241 string const Paragraph::asString(Buffer const * buffer,
1242 pos_type beg, pos_type end, bool label) const
1246 if (beg == 0 && label && !params().labelString().empty())
1247 os << params().labelString() << ' ';
1249 for (pos_type i = beg; i < end; ++i) {
1250 value_type const c = getUChar(buffer->params, i);
1253 else if (c == META_INSET)
1254 getInset(i)->ascii(buffer, os);
1257 return STRCONV(os.str());
1261 void Paragraph::setInsetOwner(Inset * i)
1263 pimpl_->inset_owner = i;
1264 InsetList::iterator it = insetlist.begin();
1265 InsetList::iterator end = insetlist.end();
1266 for (; it != end; ++it)
1268 it.getInset()->setOwner(i);
1272 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1275 insetlist.deleteInsetsLyXText(bv);
1279 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1282 insetlist.resizeInsetsLyXText(bv);
1286 void Paragraph::setContentsFromPar(Paragraph const & par)
1288 pimpl_->setContentsFromPar(par);
1292 void Paragraph::trackChanges(Change::Type type)
1294 pimpl_->trackChanges(type);
1298 void Paragraph::untrackChanges()
1300 pimpl_->untrackChanges();
1304 void Paragraph::cleanChanges()
1306 pimpl_->cleanChanges();
1310 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1312 lyx::Assert(!size() || pos < size());
1313 return pimpl_->lookupChange(pos);
1317 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1319 lyx::Assert(!size() || pos < size());
1320 return pimpl_->lookupChangeFull(pos);
1324 bool Paragraph::isChanged(pos_type start, pos_type end) const
1326 return pimpl_->isChanged(start, end);
1330 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1332 return pimpl_->isChangeEdited(start, end);
1336 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1338 pimpl_->setChange(pos, type);
1343 void Paragraph::markErased()
1345 pimpl_->markErased();
1349 void Paragraph::acceptChange(pos_type start, pos_type end)
1351 return pimpl_->acceptChange(start, end);
1355 void Paragraph::rejectChange(pos_type start, pos_type end)
1357 return pimpl_->rejectChange(start, end);
1361 lyx::pos_type Paragraph::size() const
1363 return pimpl_->size();
1367 bool Paragraph::empty() const
1369 return pimpl_->empty();
1373 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1375 return pimpl_->getChar(pos);
1379 int Paragraph::id() const
1385 LyXLayout_ptr const & Paragraph::layout() const
1387 Inset * inset = inInset();
1388 if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
1389 return static_cast<InsetEnvironment*>(inset)->layout();
1394 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1396 layout_ = new_layout;
1400 Inset * Paragraph::inInset() const
1402 return pimpl_->inset_owner;
1406 void Paragraph::clearContents()
1411 void Paragraph::setChar(pos_type pos, value_type c)
1413 pimpl_->setChar(pos, c);
1417 ParagraphParameters & Paragraph::params()
1419 return pimpl_->params;
1423 ParagraphParameters const & Paragraph::params() const
1425 return pimpl_->params;
1429 bool Paragraph::isFreeSpacing() const
1431 // for now we just need this, later should we need this in some
1432 // other way we can always add a function to Inset::() too.
1433 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1434 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);