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,
909 LatexRunParams const & runparams,
912 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
914 bool return_value = false;
918 // well we have to check if we are in an inset with unlimited
919 // lenght (all in one row) if that is true then we don't allow
920 // any special options in the paragraph and also we don't allow
921 // any environment other then "Standard" to be valid!
923 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
926 style = bparams.getLyXTextClass().defaultLayout();
933 // Maybe we have to create a optional argument.
936 // FIXME: can we actually skip this check and just call
937 // beginningOfBody() ??
938 if (style->labeltype != LABEL_MANUAL) {
941 body_pos = beginningOfBody();
944 unsigned int column = 0;
949 basefont = getLabelFont(bparams, outerfont);
951 basefont = getLayoutFont(bparams, outerfont);
954 moving_arg |= style->needprotect;
956 // Which font is currently active?
957 LyXFont running_font(basefont);
958 // Do we have an open font change?
959 bool open_font = false;
961 Change::Type running_change = Change::UNCHANGED;
963 texrow.start(id(), 0);
965 // if the paragraph is empty, the loop will not be entered at all
967 if (style->isCommand()) {
972 column += startTeXParParams(bparams, os, moving_arg);
976 for (pos_type i = 0; i < size(); ++i) {
978 // First char in paragraph or after label?
982 column += running_font.latexWriteEndChanges(os, basefont, basefont);
985 basefont = getLayoutFont(bparams, outerfont);
986 running_font = basefont;
990 if (style->isCommand()) {
996 column += startTeXParParams(bparams, os,
1000 value_type c = getChar(i);
1002 // Fully instantiated font
1003 LyXFont font = getFont(bparams, i, outerfont);
1005 LyXFont const last_font = running_font;
1007 // Spaces at end of font change are simulated to be
1008 // outside font change, i.e. we write "\textXX{text} "
1009 // rather than "\textXX{text }". (Asger)
1010 if (open_font && c == ' ' && i <= size() - 2) {
1011 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
1012 if (next_font != running_font
1013 && next_font != font) {
1018 // We end font definition before blanks
1020 (font != running_font ||
1021 font.language() != running_font.language()))
1023 column += running_font.latexWriteEndChanges(os,
1025 (i == body_pos-1) ? basefont : font);
1026 running_font = basefont;
1030 // Blanks are printed before start of fontswitch
1032 // Do not print the separation of the optional argument
1033 if (i != body_pos - 1) {
1034 pimpl_->simpleTeXBlanks(os, texrow, i,
1035 column, font, *style);
1039 // Do we need to change font?
1040 if ((font != running_font ||
1041 font.language() != running_font.language()) &&
1044 column += font.latexWriteStartChanges(os, basefont,
1046 running_font = font;
1050 Change::Type change = pimpl_->lookupChange(i);
1052 column += Changes::latexMarkChange(os, running_change, change);
1053 running_change = change;
1055 pimpl_->simpleTeXSpecialChars(buf, bparams,
1056 os, texrow, runparams, moving_arg,
1058 basefont, outerfont, open_font,
1060 *style, i, column, c);
1063 column += Changes::latexMarkChange(os,
1064 running_change, Change::UNCHANGED);
1066 // If we have an open font definition, we have to close it
1068 #ifdef FIXED_LANGUAGE_END_DETECTION
1071 .latexWriteEndChanges(os, basefont,
1072 next_->getFont(bparams,
1075 running_font.latexWriteEndChanges(os, basefont,
1079 #ifdef WITH_WARNINGS
1080 //#warning For now we ALWAYS have to close the foreign font settings if they are
1081 //#warning there as we start another \selectlanguage with the next paragraph if
1082 //#warning we are in need of this. This should be fixed sometime (Jug)
1084 running_font.latexWriteEndChanges(os, basefont, basefont);
1088 // Needed if there is an optional argument but no contents.
1089 if (body_pos > 0 && body_pos == size()) {
1091 return_value = false;
1095 column += endTeXParParams(bparams, os, moving_arg);
1098 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1099 return return_value;
1105 bool Paragraph::isHfill(pos_type pos) const
1107 return IsInsetChar(getChar(pos))
1108 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1112 bool Paragraph::isInset(pos_type pos) const
1114 return IsInsetChar(getChar(pos));
1118 bool Paragraph::isNewline(pos_type pos) const
1120 return IsInsetChar(getChar(pos))
1121 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1125 bool Paragraph::isSeparator(pos_type pos) const
1127 return IsSeparatorChar(getChar(pos));
1131 bool Paragraph::isLineSeparator(pos_type pos) const
1133 value_type const c = getChar(pos);
1134 return IsLineSeparatorChar(c)
1135 || (IsInsetChar(c) && getInset(pos) &&
1136 getInset(pos)->isLineSeparator());
1140 bool Paragraph::isKomma(pos_type pos) const
1142 return IsKommaChar(getChar(pos));
1146 /// Used by the spellchecker
1147 bool Paragraph::isLetter(pos_type pos) const
1149 value_type const c = getChar(pos);
1150 if (IsLetterChar(c))
1153 return getInset(pos)->isLetter();
1154 // We want to pass the ' and escape chars to ispell
1155 string const extra = lyxrc.isp_esc_chars + '\'';
1156 return contains(extra, c);
1160 bool Paragraph::isWord(pos_type pos) const
1162 return IsWordChar(getChar(pos)) ;
1167 Paragraph::getParLanguage(BufferParams const & bparams) const
1170 return getFirstFontSettings().language();
1171 #warning FIXME we should check the prev par as well (Lgb)
1173 } else if (previous_) {
1174 return previous_->getParLanguage(bparams);
1177 return bparams.language;
1181 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1183 return lyxrc.rtl_support
1184 && getParLanguage(bparams)->RightToLeft()
1185 && !(inInset() && inInset()->owner() &&
1186 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1190 void Paragraph::changeLanguage(BufferParams const & bparams,
1191 Language const * from, Language const * to)
1193 for (pos_type i = 0; i < size(); ++i) {
1194 LyXFont font = getFontSettings(bparams, i);
1195 if (font.language() == from) {
1196 font.setLanguage(to);
1203 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1205 Language const * doc_language = bparams.language;
1206 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1207 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1209 for (; cit != end; ++cit)
1210 if (cit->font().language() != ignore_language &&
1211 cit->font().language() != latex_language &&
1212 cit->font().language() != doc_language)
1218 // Convert the paragraph to a string.
1219 // Used for building the table of contents
1220 string const Paragraph::asString(Buffer const * buffer, bool label) const
1223 if (label && !params().labelString().empty())
1224 s += params().labelString() + ' ';
1226 for (pos_type i = 0; i < size(); ++i) {
1227 value_type c = getChar(i);
1230 else if (c == META_INSET &&
1231 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1233 getInset(i)->ascii(buffer, ost);
1234 s += subst(STRCONV(ost.str()),'\n',' ');
1242 string const Paragraph::asString(Buffer const * buffer,
1243 pos_type beg, pos_type end, bool label) const
1247 if (beg == 0 && label && !params().labelString().empty())
1248 os << params().labelString() << ' ';
1250 for (pos_type i = beg; i < end; ++i) {
1251 value_type const c = getUChar(buffer->params, i);
1254 else if (c == META_INSET)
1255 getInset(i)->ascii(buffer, os);
1258 return STRCONV(os.str());
1262 void Paragraph::setInsetOwner(Inset * i)
1264 pimpl_->inset_owner = i;
1265 InsetList::iterator it = insetlist.begin();
1266 InsetList::iterator end = insetlist.end();
1267 for (; it != end; ++it)
1269 it.getInset()->setOwner(i);
1273 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1276 insetlist.deleteInsetsLyXText(bv);
1280 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1283 insetlist.resizeInsetsLyXText(bv);
1287 void Paragraph::setContentsFromPar(Paragraph const & par)
1289 pimpl_->setContentsFromPar(par);
1293 void Paragraph::trackChanges(Change::Type type)
1295 pimpl_->trackChanges(type);
1299 void Paragraph::untrackChanges()
1301 pimpl_->untrackChanges();
1305 void Paragraph::cleanChanges()
1307 pimpl_->cleanChanges();
1311 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1313 lyx::Assert(!size() || pos < size());
1314 return pimpl_->lookupChange(pos);
1318 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1320 lyx::Assert(!size() || pos < size());
1321 return pimpl_->lookupChangeFull(pos);
1325 bool Paragraph::isChanged(pos_type start, pos_type end) const
1327 return pimpl_->isChanged(start, end);
1331 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1333 return pimpl_->isChangeEdited(start, end);
1337 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1339 pimpl_->setChange(pos, type);
1344 void Paragraph::markErased()
1346 pimpl_->markErased();
1350 void Paragraph::acceptChange(pos_type start, pos_type end)
1352 return pimpl_->acceptChange(start, end);
1356 void Paragraph::rejectChange(pos_type start, pos_type end)
1358 return pimpl_->rejectChange(start, end);
1362 lyx::pos_type Paragraph::size() const
1364 return pimpl_->size();
1368 bool Paragraph::empty() const
1370 return pimpl_->empty();
1374 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1376 return pimpl_->getChar(pos);
1380 int Paragraph::id() const
1386 LyXLayout_ptr const & Paragraph::layout() const
1388 Inset * inset = inInset();
1389 if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
1390 return static_cast<InsetEnvironment*>(inset)->layout();
1395 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1397 layout_ = new_layout;
1401 Inset * Paragraph::inInset() const
1403 return pimpl_->inset_owner;
1407 void Paragraph::clearContents()
1412 void Paragraph::setChar(pos_type pos, value_type c)
1414 pimpl_->setChar(pos, c);
1418 ParagraphParameters & Paragraph::params()
1420 return pimpl_->params;
1424 ParagraphParameters const & Paragraph::params() const
1426 return pimpl_->params;
1430 bool Paragraph::isFreeSpacing() const
1432 // for now we just need this, later should we need this in some
1433 // other way we can always add a function to Inset::() too.
1434 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1435 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);