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"
29 #include "insets/insetbibitem.h"
30 #include "insets/insetoptarg.h"
32 #include "support/filetools.h"
33 #include "support/lstrings.h"
34 #include "support/lyxmanip.h"
35 #include "support/FileInfo.h"
36 #include "support/LAssert.h"
37 #include "support/textutils.h"
48 using std::lower_bound;
49 using std::upper_bound;
54 // this is a minibuffer
59 LyXFont minibuffer_font;
60 Inset * minibuffer_inset;
65 extern BufferView * current_view;
68 Paragraph::Paragraph()
69 : pimpl_(new Paragraph::Pimpl(this))
82 // This constructor inserts the new paragraph in a list.
83 // It is placed after par.
84 Paragraph::Paragraph(Paragraph * par)
85 : pimpl_(new Paragraph::Pimpl(this))
90 // double linked list begin
93 next_->previous_ = this;
95 previous_->next_ = this;
103 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
104 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
112 // this is because of the dummy layout of the paragraphs that
114 layout_ = lp.layout();
116 // copy everything behind the break-position to the new paragraph
117 insetlist = lp.insetlist;
118 InsetList::iterator it = insetlist.begin();
119 InsetList::iterator end = insetlist.end();
120 for (; it != end; ++it) {
121 it.setInset(it.getInset()->clone(*current_view->buffer(),
123 // tell the new inset who is the boss now
124 it.getInset()->parOwner(this);
129 // the destructor removes the new paragraph from the list
130 Paragraph::~Paragraph()
134 previous_->next_ = next_;
136 next_->previous_ = previous_;
141 //lyxerr << "Paragraph::paragraph_id = "
142 // << Paragraph::paragraph_id << endl;
146 void Paragraph::write(Buffer const * buf, ostream & os,
147 BufferParams const & bparams,
148 depth_type & dth) const
150 // The beginning or end of a deeper (i.e. nested) area?
151 if (dth != params().depth()) {
152 if (params().depth() > dth) {
153 while (params().depth() > dth) {
154 os << "\n\\begin_deeper ";
158 while (params().depth() < dth) {
159 os << "\n\\end_deeper ";
165 // First write the layout
166 os << "\n\\layout " << layout()->name() << '\n';
170 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
172 Change running_change = Change(Change::UNCHANGED);
173 lyx::time_type const curtime(lyx::current_time());
176 for (pos_type i = 0; i < size(); ++i) {
182 Change change = pimpl_->lookupChangeFull(i);
183 Changes::lyxMarkChange(os, column, curtime, running_change, change);
184 running_change = change;
186 // Write font changes
187 LyXFont font2 = getFontSettings(bparams, i);
188 if (font2 != font1) {
189 font2.lyxWriteChanges(font1, os);
194 value_type const c = getChar(i);
198 Inset const * inset = getInset(i);
200 if (inset->directWrite()) {
201 // international char, let it write
202 // code directly so it's shorter in
204 inset->write(buf, os);
206 os << "\n\\begin_inset ";
207 inset->write(buf, os);
208 os << "\n\\end_inset \n\n";
214 os << "\n\\backslash \n";
218 if (i + 1 < size() && getChar(i + 1) == ' ') {
225 if ((column > 70 && c == ' ')
230 // this check is to amend a bug. LyX sometimes
231 // inserts '\0' this could cause problems.
235 lyxerr << "ERROR (Paragraph::writeFile):"
236 " NULL char in structure." << endl;
242 // to make reading work properly
244 running_change = pimpl_->lookupChange(0);
245 Changes::lyxMarkChange(os, column, curtime,
246 Change(Change::UNCHANGED), running_change);
248 Changes::lyxMarkChange(os, column, curtime,
249 running_change, Change(Change::UNCHANGED));
253 void Paragraph::validate(LaTeXFeatures & features) const
255 pimpl_->validate(features, *layout());
259 // First few functions needed for cut and paste and paragraph breaking.
260 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
262 BufferParams bparams = buffer.params;
264 minibuffer_char = getChar(pos);
265 minibuffer_font = getFontSettings(bparams, pos);
266 minibuffer_inset = 0;
267 if (minibuffer_char == Paragraph::META_INSET) {
269 minibuffer_inset = getInset(pos)->clone(buffer);
271 minibuffer_inset = 0;
272 minibuffer_char = ' ';
273 // This reflects what GetInset() does (ARRae)
279 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
281 minibuffer_char = getChar(pos);
282 minibuffer_font = getFontSettings(bparams, pos);
283 minibuffer_inset = 0;
284 if (minibuffer_char == Paragraph::META_INSET) {
286 // the inset is not in a paragraph anymore
287 minibuffer_inset = insetlist.release(pos);
288 minibuffer_inset->parOwner(0);
290 minibuffer_inset = 0;
291 minibuffer_char = ' ';
292 // This reflects what GetInset() does (ARRae)
297 // Erase(pos); now the caller is responsible for that.
301 bool Paragraph::insertFromMinibuffer(pos_type pos)
303 if (minibuffer_char == Paragraph::META_INSET) {
304 if (!insetAllowed(minibuffer_inset->lyxCode())) {
307 insertInset(pos, minibuffer_inset, minibuffer_font);
309 LyXFont f = minibuffer_font;
310 if (!checkInsertChar(f)) {
313 insertChar(pos, minibuffer_char, f);
321 void Paragraph::eraseIntern(lyx::pos_type pos)
323 pimpl_->eraseIntern(pos);
327 void Paragraph::erase(pos_type pos)
333 bool Paragraph::erase(pos_type start, pos_type end)
335 return pimpl_->erase(start, end);
339 bool Paragraph::checkInsertChar(LyXFont & font)
341 if (pimpl_->inset_owner)
342 return pimpl_->inset_owner->checkInsertChar(font);
347 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
349 LyXFont const f(LyXFont::ALL_INHERIT);
350 insertChar(pos, c, f);
354 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
355 LyXFont const & font, Change change)
357 pimpl_->insertChar(pos, c, font, change);
361 void Paragraph::insertInset(pos_type pos, Inset * inset)
363 LyXFont const f(LyXFont::ALL_INHERIT);
364 insertInset(pos, inset, f);
368 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
370 pimpl_->insertInset(pos, inset, font, change);
374 bool Paragraph::insetAllowed(Inset::Code code)
376 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
377 if (pimpl_->inset_owner)
378 return pimpl_->inset_owner->insetAllowed(code);
383 Inset * Paragraph::getInset(pos_type pos)
385 lyx::Assert(pos < size());
386 return insetlist.get(pos);
390 Inset const * Paragraph::getInset(pos_type pos) const
392 lyx::Assert(pos < size());
393 return insetlist.get(pos);
397 // Gets uninstantiated font setting at position.
398 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
401 lyx::Assert(pos <= size());
403 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
404 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
405 for (; cit != end; ++cit) {
406 if (cit->pos() >= pos)
412 retfont = cit->font();
413 else if (pos == size() && !empty())
414 retfont = getFontSettings(bparams, pos - 1);
416 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
422 // Gets uninstantiated font setting at position 0
423 LyXFont const Paragraph::getFirstFontSettings() const
425 if (!empty() && !pimpl_->fontlist.empty())
426 return pimpl_->fontlist[0].font();
428 return LyXFont(LyXFont::ALL_INHERIT);
432 // Gets the fully instantiated font at a given position in a paragraph
433 // This is basically the same function as LyXText::GetFont() in text2.C.
434 // The difference is that this one is used for generating the LaTeX file,
435 // and thus cosmetic "improvements" are disallowed: This has to deliver
436 // the true picture of the buffer. (Asger)
437 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
438 LyXFont const & outerfont) const
440 lyx::Assert(pos >= 0);
442 LyXLayout_ptr const & lout = layout();
444 pos_type const body_pos = beginningOfBody();
448 layoutfont = lout->labelfont;
450 layoutfont = lout->font;
452 LyXFont tmpfont = getFontSettings(bparams, pos);
453 tmpfont.realize(layoutfont);
454 tmpfont.realize(outerfont);
456 return realizeFont(tmpfont, bparams, 0, false);
460 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
462 LyXLayout_ptr const & lout = layout();
464 LyXFont tmpfont = lout->labelfont;
465 tmpfont.setLanguage(getParLanguage(bparams));
467 return pimpl_->realizeFont(tmpfont, bparams);
471 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
473 LyXLayout_ptr const & lout = layout();
475 LyXFont tmpfont = lout->font;
476 tmpfont.setLanguage(getParLanguage(bparams));
478 return pimpl_->realizeFont(tmpfont, bparams);
482 /// Returns the height of the highest font in range
484 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
485 LyXFont::FONT_SIZE const def_size) const
487 if (pimpl_->fontlist.empty())
490 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
491 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
492 for (; end_it != end; ++end_it) {
493 if (end_it->pos() >= endpos)
500 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
501 for (; cit != end; ++cit) {
502 if (cit->pos() >= startpos)
506 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
507 for (; cit != end_it; ++cit) {
508 LyXFont::FONT_SIZE size = cit->font().size();
509 if (size == LyXFont::INHERIT_SIZE)
511 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
518 Paragraph::value_type
519 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
521 value_type c = getChar(pos);
522 if (!lyxrc.rtl_support)
552 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
559 void Paragraph::setFont(pos_type pos, LyXFont const & font)
561 lyx::Assert(pos <= size());
563 // First, reduce font against layout/label font
564 // Update: The SetCharFont() routine in text2.C already
565 // reduces font, so we don't need to do that here. (Asger)
566 // No need to simplify this because it will disappear
567 // in a new kernel. (Asger)
568 // Next search font table
570 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
571 Pimpl::FontList::iterator it = beg;
572 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
573 for (; it != endit; ++it) {
574 if (it->pos() >= pos)
577 unsigned int i = std::distance(beg, it);
578 bool notfound = (it == endit);
580 if (!notfound && pimpl_->fontlist[i].font() == font)
583 bool begin = pos == 0 || notfound ||
584 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
585 // Is position pos is a beginning of a font block?
586 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
587 // Is position pos is the end of a font block?
588 if (begin && end) { // A single char block
589 if (i + 1 < pimpl_->fontlist.size() &&
590 pimpl_->fontlist[i + 1].font() == font) {
591 // Merge the singleton block with the next block
592 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
593 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
594 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
595 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
596 // Merge the singleton block with the previous block
597 pimpl_->fontlist[i - 1].pos(pos);
598 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
600 pimpl_->fontlist[i].font(font);
602 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
603 pimpl_->fontlist[i - 1].pos(pos);
605 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
606 Pimpl::FontTable(pos, font));
608 pimpl_->fontlist[i].pos(pos - 1);
609 if (!(i + 1 < pimpl_->fontlist.size() &&
610 pimpl_->fontlist[i + 1].font() == font))
611 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
612 Pimpl::FontTable(pos, font));
613 } else { // The general case. The block is splitted into 3 blocks
614 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
615 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
616 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
617 Pimpl::FontTable(pos, font));
623 void Paragraph::next(Paragraph * p)
629 // This function is able to hide closed footnotes.
630 Paragraph * Paragraph::next()
636 Paragraph const * Paragraph::next() const
642 void Paragraph::previous(Paragraph * p)
648 // This function is able to hide closed footnotes.
649 Paragraph * Paragraph::previous()
655 // This function is able to hide closed footnotes.
656 Paragraph const * Paragraph::previous() const
663 void Paragraph::makeSameLayout(Paragraph const * par)
665 layout(par->layout());
667 params() = par->params();
671 int Paragraph::stripLeadingSpaces()
673 if (layout()->free_spacing || isFreeSpacing())
677 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
678 pimpl_->eraseIntern(0);
686 bool Paragraph::hasSameLayout(Paragraph const * par) const
689 par->layout() == layout() &&
690 params().sameLayout(par->params());
694 Paragraph::depth_type Paragraph::getDepth() const
696 return params().depth();
700 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
702 if (layout()->isEnvironment())
703 return params().depth() + 1;
705 return params().depth();
709 char Paragraph::getAlign() const
711 return params().align();
715 string const & Paragraph::getLabelstring() const
717 return params().labelString();
721 // the next two functions are for the manual labels
722 string const Paragraph::getLabelWidthString() const
724 if (!params().labelWidthString().empty())
725 return params().labelWidthString();
727 return _("Senseless with this layout!");
731 void Paragraph::setLabelWidthString(string const & s)
733 params().labelWidthString(s);
737 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
740 params().labelWidthString(string());
741 params().align(LYX_ALIGN_LAYOUT);
742 params().spaceTop(VSpace(VSpace::NONE));
743 params().spaceBottom(VSpace(VSpace::NONE));
744 params().spacing(Spacing(Spacing::Default));
748 int Paragraph::beginningOfBody() const
750 if (layout()->labeltype != LABEL_MANUAL)
753 // Unroll the first two cycles of the loop
754 // and remember the previous character to
755 // remove unnecessary GetChar() calls
757 if (i < size() && !isNewline(i)) {
759 char previous_char = 0;
762 previous_char = getChar(i);
765 while (i < size() && previous_char != ' ') {
771 previous_char = temp;
781 // returns -1 if inset not found
782 int Paragraph::getPositionOfInset(Inset const * inset) const
785 InsetList::iterator it = insetlist.begin();
786 InsetList::iterator end = insetlist.end();
787 for (; it != end; ++it)
788 if (it.getInset() == inset)
794 InsetBibitem * Paragraph::bibitem()
796 InsetList::iterator it = insetlist.begin();
797 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
798 return static_cast<InsetBibitem *>(it.getInset());
804 // This could go to ParagraphParameters if we want to
805 int Paragraph::startTeXParParams(BufferParams const & bparams,
806 ostream & os, bool moving_arg) const
810 if (params().noindent()) {
815 switch (params().align()) {
817 case LYX_ALIGN_BLOCK:
818 case LYX_ALIGN_LAYOUT:
819 case LYX_ALIGN_SPECIAL:
822 case LYX_ALIGN_RIGHT:
823 case LYX_ALIGN_CENTER:
831 switch (params().align()) {
833 case LYX_ALIGN_BLOCK:
834 case LYX_ALIGN_LAYOUT:
835 case LYX_ALIGN_SPECIAL:
838 if (getParLanguage(bparams)->babel() != "hebrew") {
839 os << "\\begin{flushleft}";
842 os << "\\begin{flushright}";
846 case LYX_ALIGN_RIGHT:
847 if (getParLanguage(bparams)->babel() != "hebrew") {
848 os << "\\begin{flushright}";
851 os << "\\begin{flushleft}";
855 case LYX_ALIGN_CENTER:
856 os << "\\begin{center}";
865 // This could go to ParagraphParameters if we want to
866 int Paragraph::endTeXParParams(BufferParams const & bparams,
867 ostream & os, bool moving_arg) const
871 switch (params().align()) {
873 case LYX_ALIGN_BLOCK:
874 case LYX_ALIGN_LAYOUT:
875 case LYX_ALIGN_SPECIAL:
878 case LYX_ALIGN_RIGHT:
879 case LYX_ALIGN_CENTER:
887 switch (params().align()) {
889 case LYX_ALIGN_BLOCK:
890 case LYX_ALIGN_LAYOUT:
891 case LYX_ALIGN_SPECIAL:
894 if (getParLanguage(bparams)->babel() != "hebrew") {
895 os << "\\end{flushleft}";
898 os << "\\end{flushright}";
902 case LYX_ALIGN_RIGHT:
903 if (getParLanguage(bparams)->babel() != "hebrew") {
904 os << "\\end{flushright}";
907 os << "\\end{flushleft}";
911 case LYX_ALIGN_CENTER:
912 os << "\\end{center}";
920 // This one spits out the text of the paragraph
921 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
922 BufferParams const & bparams,
923 LyXFont const & outerfont,
924 ostream & os, TexRow & texrow,
927 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
929 bool return_value = false;
933 // well we have to check if we are in an inset with unlimited
934 // lenght (all in one row) if that is true then we don't allow
935 // any special options in the paragraph and also we don't allow
936 // any environment other then "Standard" to be valid!
938 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
941 style = bparams.getLyXTextClass().defaultLayout();
948 // Maybe we have to create a optional argument.
951 // FIXME: can we actually skip this check and just call
952 // beginningOfBody() ??
953 if (style->labeltype != LABEL_MANUAL) {
956 body_pos = beginningOfBody();
959 unsigned int column = 0;
964 basefont = getLabelFont(bparams);
966 basefont = getLayoutFont(bparams);
969 moving_arg |= style->needprotect;
971 // Which font is currently active?
972 LyXFont running_font(basefont);
973 // Do we have an open font change?
974 bool open_font = false;
976 Change::Type running_change = Change::UNCHANGED;
978 texrow.start(this, 0);
980 // if the paragraph is empty, the loop will not be entered at all
982 if (style->isCommand()) {
987 column += startTeXParParams(bparams, os, moving_arg);
991 for (pos_type i = 0; i < size(); ++i) {
993 // First char in paragraph or after label?
997 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1000 basefont = getLayoutFont(bparams);
1001 running_font = basefont;
1005 if (style->isCommand()) {
1011 column += startTeXParParams(bparams, os,
1015 value_type c = getChar(i);
1017 // Fully instantiated font
1018 LyXFont font = getFont(bparams, i, outerfont);
1020 LyXFont const last_font = running_font;
1022 // Spaces at end of font change are simulated to be
1023 // outside font change, i.e. we write "\textXX{text} "
1024 // rather than "\textXX{text }". (Asger)
1025 if (open_font && c == ' ' && i <= size() - 2) {
1026 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
1027 if (next_font != running_font
1028 && next_font != font) {
1033 // We end font definition before blanks
1035 (font != running_font ||
1036 font.language() != running_font.language()))
1038 column += running_font.latexWriteEndChanges(os,
1040 (i == body_pos-1) ? basefont : font);
1041 running_font = basefont;
1045 // Blanks are printed before start of fontswitch
1047 // Do not print the separation of the optional argument
1048 if (i != body_pos - 1) {
1049 pimpl_->simpleTeXBlanks(os, texrow, i,
1050 column, font, *style);
1054 // Do we need to change font?
1055 if ((font != running_font ||
1056 font.language() != running_font.language()) &&
1059 column += font.latexWriteStartChanges(os, basefont,
1061 running_font = font;
1065 Change::Type change = pimpl_->lookupChange(i);
1067 column += Changes::latexMarkChange(os, running_change, change);
1068 running_change = change;
1070 pimpl_->simpleTeXSpecialChars(buf, bparams,
1071 os, texrow, moving_arg,
1073 basefont, open_font,
1075 *style, i, column, c);
1078 column += Changes::latexMarkChange(os,
1079 running_change, Change::UNCHANGED);
1081 // If we have an open font definition, we have to close it
1083 #ifdef FIXED_LANGUAGE_END_DETECTION
1086 .latexWriteEndChanges(os, basefont,
1087 next_->getFont(bparams,
1090 running_font.latexWriteEndChanges(os, basefont,
1094 #ifdef WITH_WARNINGS
1095 //#warning For now we ALWAYS have to close the foreign font settings if they are
1096 //#warning there as we start another \selectlanguage with the next paragraph if
1097 //#warning we are in need of this. This should be fixed sometime (Jug)
1099 running_font.latexWriteEndChanges(os, basefont, basefont);
1103 // Needed if there is an optional argument but no contents.
1104 if (body_pos > 0 && body_pos == size()) {
1106 return_value = false;
1110 column += endTeXParParams(bparams, os, moving_arg);
1113 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1114 return return_value;
1120 bool Paragraph::isHfill(pos_type pos) const
1122 return IsInsetChar(getChar(pos))
1123 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1127 bool Paragraph::isInset(pos_type pos) const
1129 return IsInsetChar(getChar(pos));
1133 bool Paragraph::isNewline(pos_type pos) const
1135 return IsInsetChar(getChar(pos))
1136 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1140 bool Paragraph::isSeparator(pos_type pos) const
1142 return IsSeparatorChar(getChar(pos));
1146 bool Paragraph::isLineSeparator(pos_type pos) const
1148 value_type const c = getChar(pos);
1149 return IsLineSeparatorChar(c)
1150 || (IsInsetChar(c) && getInset(pos) &&
1151 getInset(pos)->isLineSeparator());
1155 bool Paragraph::isKomma(pos_type pos) const
1157 return IsKommaChar(getChar(pos));
1161 /// Used by the spellchecker
1162 bool Paragraph::isLetter(pos_type pos) const
1164 value_type const c = getChar(pos);
1165 if (IsLetterChar(c))
1168 return getInset(pos)->isLetter();
1169 // We want to pass the ' and escape chars to ispell
1170 string const extra = lyxrc.isp_esc_chars + '\'';
1171 return contains(extra, c);
1175 bool Paragraph::isWord(pos_type pos) const
1177 return IsWordChar(getChar(pos)) ;
1182 Paragraph::getParLanguage(BufferParams const & bparams) const
1185 return getFirstFontSettings().language();
1186 } else if (previous_)
1187 return previous_->getParLanguage(bparams);
1189 return bparams.language;
1193 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1195 return lyxrc.rtl_support
1196 && getParLanguage(bparams)->RightToLeft()
1197 && !(inInset() && inInset()->owner() &&
1198 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1202 void Paragraph::changeLanguage(BufferParams const & bparams,
1203 Language const * from, Language const * to)
1205 for (pos_type i = 0; i < size(); ++i) {
1206 LyXFont font = getFontSettings(bparams, i);
1207 if (font.language() == from) {
1208 font.setLanguage(to);
1215 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1217 Language const * doc_language = bparams.language;
1218 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1219 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1221 for (; cit != end; ++cit)
1222 if (cit->font().language() != ignore_language &&
1223 cit->font().language() != latex_language &&
1224 cit->font().language() != doc_language)
1230 // Convert the paragraph to a string.
1231 // Used for building the table of contents
1232 string const Paragraph::asString(Buffer const * buffer, bool label) const
1235 if (label && !params().labelString().empty())
1236 s += params().labelString() + ' ';
1238 for (pos_type i = 0; i < size(); ++i) {
1239 value_type c = getChar(i);
1242 else if (c == META_INSET &&
1243 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1245 getInset(i)->ascii(buffer, ost);
1246 s += subst(STRCONV(ost.str()),'\n',' ');
1254 string const Paragraph::asString(Buffer const * buffer,
1255 pos_type beg, pos_type end, bool label) const
1259 if (beg == 0 && label && !params().labelString().empty())
1260 os << params().labelString() << ' ';
1262 for (pos_type i = beg; i < end; ++i) {
1263 value_type const c = getUChar(buffer->params, i);
1266 else if (c == META_INSET)
1267 getInset(i)->ascii(buffer, os);
1270 return STRCONV(os.str());
1274 void Paragraph::setInsetOwner(Inset * i)
1276 pimpl_->inset_owner = i;
1277 InsetList::iterator it = insetlist.begin();
1278 InsetList::iterator end = insetlist.end();
1279 for (; it != end; ++it)
1281 it.getInset()->setOwner(i);
1285 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1288 insetlist.deleteInsetsLyXText(bv);
1292 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1295 insetlist.resizeInsetsLyXText(bv);
1299 void Paragraph::setContentsFromPar(Paragraph * par)
1301 pimpl_->setContentsFromPar(par);
1305 void Paragraph::trackChanges(Change::Type type)
1307 pimpl_->trackChanges(type);
1311 void Paragraph::untrackChanges()
1313 pimpl_->untrackChanges();
1317 void Paragraph::cleanChanges()
1319 pimpl_->cleanChanges();
1323 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1325 lyx::Assert(!size() || pos < size());
1326 return pimpl_->lookupChange(pos);
1330 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1332 lyx::Assert(!size() || pos < size());
1333 return pimpl_->lookupChangeFull(pos);
1337 bool Paragraph::isChanged(pos_type start, pos_type end) const
1339 return pimpl_->isChanged(start, end);
1343 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1345 return pimpl_->isChangeEdited(start, end);
1349 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1351 pimpl_->setChange(pos, type);
1356 void Paragraph::markErased()
1358 pimpl_->markErased();
1362 void Paragraph::acceptChange(pos_type start, pos_type end)
1364 return pimpl_->acceptChange(start, end);
1368 void Paragraph::rejectChange(pos_type start, pos_type end)
1370 return pimpl_->rejectChange(start, end);
1374 lyx::pos_type Paragraph::size() const
1376 return pimpl_->size();
1380 bool Paragraph::empty() const
1382 return pimpl_->empty();
1386 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1388 return pimpl_->getChar(pos);
1392 int Paragraph::id() const
1398 LyXLayout_ptr const & Paragraph::layout() const
1404 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1406 layout_ = new_layout;
1410 Inset * Paragraph::inInset() const
1412 return pimpl_->inset_owner;
1416 void Paragraph::clearContents()
1421 void Paragraph::setChar(pos_type pos, value_type c)
1423 pimpl_->setChar(pos, c);
1427 ParagraphParameters & Paragraph::params()
1429 return pimpl_->params;
1433 ParagraphParameters const & Paragraph::params() const
1435 return pimpl_->params;
1439 bool Paragraph::isFreeSpacing() const
1441 // for now we just need this, later should we need this in some
1442 // other way we can always add a function to Inset::() too.
1443 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1444 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);