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))
86 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
87 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
98 // this is because of the dummy layout of the paragraphs that
100 layout_ = lp.layout();
102 // copy everything behind the break-position to the new paragraph
103 insetlist = lp.insetlist;
104 InsetList::iterator it = insetlist.begin();
105 InsetList::iterator end = insetlist.end();
106 for (; it != end; ++it) {
107 it.setInset(it.getInset()->clone(*current_view->buffer(),
109 // tell the new inset who is the boss now
110 it.getInset()->parOwner(this);
115 // the destructor removes the new paragraph from the list
116 Paragraph::~Paragraph()
120 previous_->next_ = next_;
122 next_->previous_ = previous_;
127 //lyxerr << "Paragraph::paragraph_id = "
128 // << Paragraph::paragraph_id << endl;
132 void Paragraph::write(Buffer const * buf, ostream & os,
133 BufferParams const & bparams,
134 depth_type & dth) const
136 // The beginning or end of a deeper (i.e. nested) area?
137 if (dth != params().depth()) {
138 if (params().depth() > dth) {
139 while (params().depth() > dth) {
140 os << "\n\\begin_deeper ";
144 while (params().depth() < dth) {
145 os << "\n\\end_deeper ";
151 // First write the layout
152 os << "\n\\layout " << layout()->name() << '\n';
156 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
158 Change running_change = Change(Change::UNCHANGED);
159 lyx::time_type const curtime(lyx::current_time());
162 for (pos_type i = 0; i < size(); ++i) {
168 Change change = pimpl_->lookupChangeFull(i);
169 Changes::lyxMarkChange(os, column, curtime, running_change, change);
170 running_change = change;
172 // Write font changes
173 LyXFont font2 = getFontSettings(bparams, i);
174 if (font2 != font1) {
175 font2.lyxWriteChanges(font1, os);
180 value_type const c = getChar(i);
184 Inset const * inset = getInset(i);
186 if (inset->directWrite()) {
187 // international char, let it write
188 // code directly so it's shorter in
190 inset->write(buf, os);
192 os << "\n\\begin_inset ";
193 inset->write(buf, os);
194 os << "\n\\end_inset \n\n";
200 os << "\n\\backslash \n";
204 if (i + 1 < size() && getChar(i + 1) == ' ') {
211 if ((column > 70 && c == ' ')
216 // this check is to amend a bug. LyX sometimes
217 // inserts '\0' this could cause problems.
221 lyxerr << "ERROR (Paragraph::writeFile):"
222 " NULL char in structure." << endl;
228 // to make reading work properly
230 running_change = pimpl_->lookupChange(0);
231 Changes::lyxMarkChange(os, column, curtime,
232 Change(Change::UNCHANGED), running_change);
234 Changes::lyxMarkChange(os, column, curtime,
235 running_change, Change(Change::UNCHANGED));
239 void Paragraph::validate(LaTeXFeatures & features) const
241 pimpl_->validate(features, *layout());
245 // First few functions needed for cut and paste and paragraph breaking.
246 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
248 BufferParams bparams = buffer.params;
250 minibuffer_char = getChar(pos);
251 minibuffer_font = getFontSettings(bparams, pos);
252 minibuffer_inset = 0;
253 if (minibuffer_char == Paragraph::META_INSET) {
255 minibuffer_inset = getInset(pos)->clone(buffer);
257 minibuffer_inset = 0;
258 minibuffer_char = ' ';
259 // This reflects what GetInset() does (ARRae)
265 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
267 minibuffer_char = getChar(pos);
268 minibuffer_font = getFontSettings(bparams, pos);
269 minibuffer_inset = 0;
270 if (minibuffer_char == Paragraph::META_INSET) {
272 // the inset is not in a paragraph anymore
273 minibuffer_inset = insetlist.release(pos);
274 minibuffer_inset->parOwner(0);
276 minibuffer_inset = 0;
277 minibuffer_char = ' ';
278 // This reflects what GetInset() does (ARRae)
283 // Erase(pos); now the caller is responsible for that.
287 bool Paragraph::insertFromMinibuffer(pos_type pos)
289 if (minibuffer_char == Paragraph::META_INSET) {
290 if (!insetAllowed(minibuffer_inset->lyxCode())) {
293 insertInset(pos, minibuffer_inset, minibuffer_font);
295 LyXFont f = minibuffer_font;
296 if (!checkInsertChar(f)) {
299 insertChar(pos, minibuffer_char, f);
307 void Paragraph::eraseIntern(lyx::pos_type pos)
309 pimpl_->eraseIntern(pos);
313 bool Paragraph::erase(pos_type pos)
315 return pimpl_->erase(pos);
319 int Paragraph::erase(pos_type start, pos_type end)
321 return pimpl_->erase(start, end);
325 bool Paragraph::checkInsertChar(LyXFont & font)
327 if (pimpl_->inset_owner)
328 return pimpl_->inset_owner->checkInsertChar(font);
333 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
335 LyXFont const f(LyXFont::ALL_INHERIT);
336 insertChar(pos, c, f);
340 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
341 LyXFont const & font, Change change)
343 pimpl_->insertChar(pos, c, font, change);
347 void Paragraph::insertInset(pos_type pos, Inset * inset)
349 LyXFont const f(LyXFont::ALL_INHERIT);
350 insertInset(pos, inset, f);
354 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
356 pimpl_->insertInset(pos, inset, font, change);
360 bool Paragraph::insetAllowed(Inset::Code code)
362 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
363 if (pimpl_->inset_owner)
364 return pimpl_->inset_owner->insetAllowed(code);
369 Inset * Paragraph::getInset(pos_type pos)
371 lyx::Assert(pos < size());
372 return insetlist.get(pos);
376 Inset const * Paragraph::getInset(pos_type pos) const
378 lyx::Assert(pos < size());
379 return insetlist.get(pos);
383 // Gets uninstantiated font setting at position.
384 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
387 lyx::Assert(pos <= size());
389 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
390 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
391 for (; cit != end; ++cit) {
392 if (cit->pos() >= pos)
398 retfont = cit->font();
399 else if (pos == size() && !empty())
400 retfont = getFontSettings(bparams, pos - 1);
402 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
408 // Gets uninstantiated font setting at position 0
409 LyXFont const Paragraph::getFirstFontSettings() const
411 if (!empty() && !pimpl_->fontlist.empty())
412 return pimpl_->fontlist[0].font();
414 return LyXFont(LyXFont::ALL_INHERIT);
418 // Gets the fully instantiated font at a given position in a paragraph
419 // This is basically the same function as LyXText::GetFont() in text2.C.
420 // The difference is that this one is used for generating the LaTeX file,
421 // and thus cosmetic "improvements" are disallowed: This has to deliver
422 // the true picture of the buffer. (Asger)
423 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
424 LyXFont const & outerfont) const
426 lyx::Assert(pos >= 0);
428 LyXLayout_ptr const & lout = layout();
430 pos_type const body_pos = beginningOfBody();
434 layoutfont = lout->labelfont;
436 layoutfont = lout->font;
438 LyXFont tmpfont = getFontSettings(bparams, pos);
439 tmpfont.realize(layoutfont);
440 tmpfont.realize(outerfont);
442 return realizeFont(tmpfont, bparams);
446 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
447 LyXFont const & outerfont) const
449 LyXLayout_ptr const & lout = layout();
451 LyXFont tmpfont = lout->labelfont;
452 tmpfont.setLanguage(getParLanguage(bparams));
453 tmpfont.realize(outerfont);
455 return realizeFont(tmpfont, bparams);
459 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
460 LyXFont const & outerfont) const
462 LyXLayout_ptr const & lout = layout();
464 LyXFont tmpfont = lout->font;
465 tmpfont.setLanguage(getParLanguage(bparams));
466 tmpfont.realize(outerfont);
468 return realizeFont(tmpfont, bparams);
472 /// Returns the height of the highest font in range
474 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
475 LyXFont::FONT_SIZE const def_size) const
477 if (pimpl_->fontlist.empty())
480 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
481 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
482 for (; end_it != end; ++end_it) {
483 if (end_it->pos() >= endpos)
490 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
491 for (; cit != end; ++cit) {
492 if (cit->pos() >= startpos)
496 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
497 for (; cit != end_it; ++cit) {
498 LyXFont::FONT_SIZE size = cit->font().size();
499 if (size == LyXFont::INHERIT_SIZE)
501 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
508 Paragraph::value_type
509 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
511 value_type c = getChar(pos);
512 if (!lyxrc.rtl_support)
542 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
549 void Paragraph::setFont(pos_type pos, LyXFont const & font)
551 lyx::Assert(pos <= size());
553 // First, reduce font against layout/label font
554 // Update: The SetCharFont() routine in text2.C already
555 // reduces font, so we don't need to do that here. (Asger)
556 // No need to simplify this because it will disappear
557 // in a new kernel. (Asger)
558 // Next search font table
560 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
561 Pimpl::FontList::iterator it = beg;
562 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
563 for (; it != endit; ++it) {
564 if (it->pos() >= pos)
567 unsigned int i = std::distance(beg, it);
568 bool notfound = (it == endit);
570 if (!notfound && pimpl_->fontlist[i].font() == font)
573 bool begin = pos == 0 || notfound ||
574 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
575 // Is position pos is a beginning of a font block?
576 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
577 // Is position pos is the end of a font block?
578 if (begin && end) { // A single char block
579 if (i + 1 < pimpl_->fontlist.size() &&
580 pimpl_->fontlist[i + 1].font() == font) {
581 // Merge the singleton block with the next block
582 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
583 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
584 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
585 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
586 // Merge the singleton block with the previous block
587 pimpl_->fontlist[i - 1].pos(pos);
588 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
590 pimpl_->fontlist[i].font(font);
592 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
593 pimpl_->fontlist[i - 1].pos(pos);
595 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
596 Pimpl::FontTable(pos, font));
598 pimpl_->fontlist[i].pos(pos - 1);
599 if (!(i + 1 < pimpl_->fontlist.size() &&
600 pimpl_->fontlist[i + 1].font() == font))
601 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
602 Pimpl::FontTable(pos, font));
603 } else { // The general case. The block is splitted into 3 blocks
604 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
605 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
606 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
607 Pimpl::FontTable(pos, font));
613 void Paragraph::next(Paragraph * p)
619 // This function is able to hide closed footnotes.
620 Paragraph * Paragraph::next()
626 Paragraph const * Paragraph::next() const
632 void Paragraph::previous(Paragraph * p)
638 // This function is able to hide closed footnotes.
639 Paragraph * Paragraph::previous()
645 // This function is able to hide closed footnotes.
646 Paragraph const * Paragraph::previous() const
653 void Paragraph::makeSameLayout(Paragraph const & par)
655 layout(par.layout());
657 params() = par.params();
661 int Paragraph::stripLeadingSpaces()
663 if (layout()->free_spacing || isFreeSpacing())
667 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
668 pimpl_->eraseIntern(0);
676 bool Paragraph::hasSameLayout(Paragraph const & par) const
679 par.layout() == layout() &&
680 params().sameLayout(par.params());
684 Paragraph::depth_type Paragraph::getDepth() const
686 return params().depth();
690 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
692 if (layout()->isEnvironment())
693 return params().depth() + 1;
695 return params().depth();
699 char Paragraph::getAlign() const
701 return params().align();
705 string const & Paragraph::getLabelstring() const
707 return params().labelString();
711 // the next two functions are for the manual labels
712 string const Paragraph::getLabelWidthString() const
714 if (!params().labelWidthString().empty())
715 return params().labelWidthString();
717 return _("Senseless with this layout!");
721 void Paragraph::setLabelWidthString(string const & s)
723 params().labelWidthString(s);
727 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
730 params().labelWidthString(string());
731 params().align(LYX_ALIGN_LAYOUT);
732 params().spaceTop(VSpace(VSpace::NONE));
733 params().spaceBottom(VSpace(VSpace::NONE));
734 params().spacing(Spacing(Spacing::Default));
738 int Paragraph::beginningOfBody() const
740 if (layout()->labeltype != LABEL_MANUAL)
743 // Unroll the first two cycles of the loop
744 // and remember the previous character to
745 // remove unnecessary GetChar() calls
747 if (i < size() && !isNewline(i)) {
749 char previous_char = 0;
752 previous_char = getChar(i);
755 while (i < size() && previous_char != ' ') {
761 previous_char = temp;
771 // returns -1 if inset not found
772 int Paragraph::getPositionOfInset(Inset const * inset) const
775 InsetList::iterator it = insetlist.begin();
776 InsetList::iterator end = insetlist.end();
777 for (; it != end; ++it)
778 if (it.getInset() == inset)
784 InsetBibitem * Paragraph::bibitem()
786 InsetList::iterator it = insetlist.begin();
787 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
788 return static_cast<InsetBibitem *>(it.getInset());
794 // This could go to ParagraphParameters if we want to
795 int Paragraph::startTeXParParams(BufferParams const & bparams,
796 ostream & os, bool moving_arg) const
800 if (params().noindent()) {
805 switch (params().align()) {
807 case LYX_ALIGN_BLOCK:
808 case LYX_ALIGN_LAYOUT:
809 case LYX_ALIGN_SPECIAL:
812 case LYX_ALIGN_RIGHT:
813 case LYX_ALIGN_CENTER:
821 switch (params().align()) {
823 case LYX_ALIGN_BLOCK:
824 case LYX_ALIGN_LAYOUT:
825 case LYX_ALIGN_SPECIAL:
828 if (getParLanguage(bparams)->babel() != "hebrew") {
829 os << "\\begin{flushleft}";
832 os << "\\begin{flushright}";
836 case LYX_ALIGN_RIGHT:
837 if (getParLanguage(bparams)->babel() != "hebrew") {
838 os << "\\begin{flushright}";
841 os << "\\begin{flushleft}";
845 case LYX_ALIGN_CENTER:
846 os << "\\begin{center}";
855 // This could go to ParagraphParameters if we want to
856 int Paragraph::endTeXParParams(BufferParams const & bparams,
857 ostream & os, bool moving_arg) const
861 switch (params().align()) {
863 case LYX_ALIGN_BLOCK:
864 case LYX_ALIGN_LAYOUT:
865 case LYX_ALIGN_SPECIAL:
868 case LYX_ALIGN_RIGHT:
869 case LYX_ALIGN_CENTER:
877 switch (params().align()) {
879 case LYX_ALIGN_BLOCK:
880 case LYX_ALIGN_LAYOUT:
881 case LYX_ALIGN_SPECIAL:
884 if (getParLanguage(bparams)->babel() != "hebrew") {
885 os << "\\end{flushleft}";
888 os << "\\end{flushright}";
892 case LYX_ALIGN_RIGHT:
893 if (getParLanguage(bparams)->babel() != "hebrew") {
894 os << "\\end{flushright}";
897 os << "\\end{flushleft}";
901 case LYX_ALIGN_CENTER:
902 os << "\\end{center}";
910 // This one spits out the text of the paragraph
911 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
912 BufferParams const & bparams,
913 LyXFont const & outerfont,
914 ostream & os, TexRow & texrow,
915 LatexRunParams const & runparams,
918 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
920 bool return_value = false;
924 // well we have to check if we are in an inset with unlimited
925 // lenght (all in one row) if that is true then we don't allow
926 // any special options in the paragraph and also we don't allow
927 // any environment other then "Standard" to be valid!
929 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
932 style = bparams.getLyXTextClass().defaultLayout();
939 // Maybe we have to create a optional argument.
942 // FIXME: can we actually skip this check and just call
943 // beginningOfBody() ??
944 if (style->labeltype != LABEL_MANUAL) {
947 body_pos = beginningOfBody();
950 unsigned int column = 0;
955 basefont = getLabelFont(bparams, outerfont);
957 basefont = getLayoutFont(bparams, outerfont);
960 moving_arg |= style->needprotect;
962 // Which font is currently active?
963 LyXFont running_font(basefont);
964 // Do we have an open font change?
965 bool open_font = false;
967 Change::Type running_change = Change::UNCHANGED;
969 texrow.start(id(), 0);
971 // if the paragraph is empty, the loop will not be entered at all
973 if (style->isCommand()) {
978 column += startTeXParParams(bparams, os, moving_arg);
982 for (pos_type i = 0; i < size(); ++i) {
984 // First char in paragraph or after label?
988 column += running_font.latexWriteEndChanges(os, basefont, basefont);
991 basefont = getLayoutFont(bparams, outerfont);
992 running_font = basefont;
996 if (style->isCommand()) {
1002 column += startTeXParParams(bparams, os,
1006 value_type c = getChar(i);
1008 // Fully instantiated font
1009 LyXFont font = getFont(bparams, i, outerfont);
1011 LyXFont const last_font = running_font;
1013 // Spaces at end of font change are simulated to be
1014 // outside font change, i.e. we write "\textXX{text} "
1015 // rather than "\textXX{text }". (Asger)
1016 if (open_font && c == ' ' && i <= size() - 2) {
1017 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
1018 if (next_font != running_font
1019 && next_font != font) {
1024 // We end font definition before blanks
1026 (font != running_font ||
1027 font.language() != running_font.language()))
1029 column += running_font.latexWriteEndChanges(os,
1031 (i == body_pos-1) ? basefont : font);
1032 running_font = basefont;
1036 // Blanks are printed before start of fontswitch
1038 // Do not print the separation of the optional argument
1039 if (i != body_pos - 1) {
1040 pimpl_->simpleTeXBlanks(os, texrow, i,
1041 column, font, *style);
1045 // Do we need to change font?
1046 if ((font != running_font ||
1047 font.language() != running_font.language()) &&
1050 column += font.latexWriteStartChanges(os, basefont,
1052 running_font = font;
1056 Change::Type change = pimpl_->lookupChange(i);
1058 column += Changes::latexMarkChange(os, running_change, change);
1059 running_change = change;
1061 pimpl_->simpleTeXSpecialChars(buf, bparams,
1062 os, texrow, runparams, moving_arg,
1064 basefont, outerfont, open_font,
1066 *style, i, column, c);
1069 column += Changes::latexMarkChange(os,
1070 running_change, Change::UNCHANGED);
1072 // If we have an open font definition, we have to close it
1074 #ifdef FIXED_LANGUAGE_END_DETECTION
1077 .latexWriteEndChanges(os, basefont,
1078 next_->getFont(bparams,
1081 running_font.latexWriteEndChanges(os, basefont,
1085 #ifdef WITH_WARNINGS
1086 //#warning For now we ALWAYS have to close the foreign font settings if they are
1087 //#warning there as we start another \selectlanguage with the next paragraph if
1088 //#warning we are in need of this. This should be fixed sometime (Jug)
1090 running_font.latexWriteEndChanges(os, basefont, basefont);
1094 // Needed if there is an optional argument but no contents.
1095 if (body_pos > 0 && body_pos == size()) {
1097 return_value = false;
1101 column += endTeXParParams(bparams, os, moving_arg);
1104 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1105 return return_value;
1111 bool Paragraph::isHfill(pos_type pos) const
1113 return IsInsetChar(getChar(pos))
1114 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1118 bool Paragraph::isInset(pos_type pos) const
1120 return IsInsetChar(getChar(pos));
1124 bool Paragraph::isNewline(pos_type pos) const
1126 return IsInsetChar(getChar(pos))
1127 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1131 bool Paragraph::isSeparator(pos_type pos) const
1133 return IsSeparatorChar(getChar(pos));
1137 bool Paragraph::isLineSeparator(pos_type pos) const
1139 value_type const c = getChar(pos);
1140 return IsLineSeparatorChar(c)
1141 || (IsInsetChar(c) && getInset(pos) &&
1142 getInset(pos)->isLineSeparator());
1146 bool Paragraph::isKomma(pos_type pos) const
1148 return IsKommaChar(getChar(pos));
1152 /// Used by the spellchecker
1153 bool Paragraph::isLetter(pos_type pos) const
1155 value_type const c = getChar(pos);
1156 if (IsLetterChar(c))
1159 return getInset(pos)->isLetter();
1160 // We want to pass the ' and escape chars to ispell
1161 string const extra = lyxrc.isp_esc_chars + '\'';
1162 return contains(extra, c);
1166 bool Paragraph::isWord(pos_type pos) const
1168 return IsWordChar(getChar(pos)) ;
1173 Paragraph::getParLanguage(BufferParams const & bparams) const
1176 return getFirstFontSettings().language();
1177 #warning FIXME we should check the prev par as well (Lgb)
1179 } else if (previous_) {
1180 return previous_->getParLanguage(bparams);
1183 return bparams.language;
1187 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1189 return lyxrc.rtl_support
1190 && getParLanguage(bparams)->RightToLeft()
1191 && !(inInset() && inInset()->owner() &&
1192 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1196 void Paragraph::changeLanguage(BufferParams const & bparams,
1197 Language const * from, Language const * to)
1199 for (pos_type i = 0; i < size(); ++i) {
1200 LyXFont font = getFontSettings(bparams, i);
1201 if (font.language() == from) {
1202 font.setLanguage(to);
1209 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1211 Language const * doc_language = bparams.language;
1212 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1213 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1215 for (; cit != end; ++cit)
1216 if (cit->font().language() != ignore_language &&
1217 cit->font().language() != latex_language &&
1218 cit->font().language() != doc_language)
1224 // Convert the paragraph to a string.
1225 // Used for building the table of contents
1226 string const Paragraph::asString(Buffer const * buffer, bool label) const
1229 if (label && !params().labelString().empty())
1230 s += params().labelString() + ' ';
1232 for (pos_type i = 0; i < size(); ++i) {
1233 value_type c = getChar(i);
1236 else if (c == META_INSET &&
1237 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1239 getInset(i)->ascii(buffer, ost);
1240 s += subst(STRCONV(ost.str()),'\n',' ');
1248 string const Paragraph::asString(Buffer const * buffer,
1249 pos_type beg, pos_type end, bool label) const
1253 if (beg == 0 && label && !params().labelString().empty())
1254 os << params().labelString() << ' ';
1256 for (pos_type i = beg; i < end; ++i) {
1257 value_type const c = getUChar(buffer->params, i);
1260 else if (c == META_INSET)
1261 getInset(i)->ascii(buffer, os);
1264 return STRCONV(os.str());
1268 void Paragraph::setInsetOwner(Inset * i)
1270 pimpl_->inset_owner = i;
1271 InsetList::iterator it = insetlist.begin();
1272 InsetList::iterator end = insetlist.end();
1273 for (; it != end; ++it)
1275 it.getInset()->setOwner(i);
1279 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1282 insetlist.deleteInsetsLyXText(bv);
1286 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1289 insetlist.resizeInsetsLyXText(bv);
1293 void Paragraph::setContentsFromPar(Paragraph const & par)
1295 pimpl_->setContentsFromPar(par);
1299 void Paragraph::trackChanges(Change::Type type)
1301 pimpl_->trackChanges(type);
1305 void Paragraph::untrackChanges()
1307 pimpl_->untrackChanges();
1311 void Paragraph::cleanChanges()
1313 pimpl_->cleanChanges();
1317 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1319 lyx::Assert(!size() || pos < size());
1320 return pimpl_->lookupChange(pos);
1324 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1326 lyx::Assert(!size() || pos < size());
1327 return pimpl_->lookupChangeFull(pos);
1331 bool Paragraph::isChanged(pos_type start, pos_type end) const
1333 return pimpl_->isChanged(start, end);
1337 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1339 return pimpl_->isChangeEdited(start, end);
1343 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1345 pimpl_->setChange(pos, type);
1350 void Paragraph::markErased()
1352 pimpl_->markErased();
1356 void Paragraph::acceptChange(pos_type start, pos_type end)
1358 return pimpl_->acceptChange(start, end);
1362 void Paragraph::rejectChange(pos_type start, pos_type end)
1364 return pimpl_->rejectChange(start, end);
1368 lyx::pos_type Paragraph::size() const
1370 return pimpl_->size();
1374 bool Paragraph::empty() const
1376 return pimpl_->empty();
1380 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1382 return pimpl_->getChar(pos);
1386 int Paragraph::id() const
1392 LyXLayout_ptr const & Paragraph::layout() const
1394 Inset * inset = inInset();
1395 if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
1396 return static_cast<InsetEnvironment*>(inset)->layout();
1401 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1403 layout_ = new_layout;
1407 Inset * Paragraph::inInset() const
1409 return pimpl_->inset_owner;
1413 void Paragraph::clearContents()
1418 void Paragraph::setChar(pos_type pos, value_type c)
1420 pimpl_->setChar(pos, c);
1424 ParagraphParameters & Paragraph::params()
1426 return pimpl_->params;
1430 ParagraphParameters const & Paragraph::params() const
1432 return pimpl_->params;
1436 bool Paragraph::isFreeSpacing() const
1438 // for now we just need this, later should we need this in some
1439 // other way we can always add a function to Inset::() too.
1440 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1441 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);