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"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
35 #include "support/lyxmanip.h"
36 #include "support/FileInfo.h"
37 #include "support/LAssert.h"
38 #include "support/textutils.h"
49 using std::lower_bound;
50 using std::upper_bound;
55 // this is a minibuffer
60 LyXFont minibuffer_font;
61 Inset * minibuffer_inset;
66 extern BufferView * current_view;
69 Paragraph::Paragraph()
70 : pimpl_(new Paragraph::Pimpl(this))
83 // This constructor inserts the new paragraph in a list.
84 // It is placed after par.
85 Paragraph::Paragraph(Paragraph * par)
86 : pimpl_(new Paragraph::Pimpl(this))
91 // double linked list begin
94 next_->previous_ = this;
96 previous_->next_ = this;
104 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
105 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
113 // this is because of the dummy layout of the paragraphs that
115 layout_ = lp.layout();
117 // copy everything behind the break-position to the new paragraph
118 insetlist = lp.insetlist;
119 InsetList::iterator it = insetlist.begin();
120 InsetList::iterator end = insetlist.end();
121 for (; it != end; ++it) {
122 it.setInset(it.getInset()->clone(*current_view->buffer(),
124 // tell the new inset who is the boss now
125 it.getInset()->parOwner(this);
130 // the destructor removes the new paragraph from the list
131 Paragraph::~Paragraph()
135 previous_->next_ = next_;
137 next_->previous_ = previous_;
142 //lyxerr << "Paragraph::paragraph_id = "
143 // << Paragraph::paragraph_id << endl;
147 void Paragraph::write(Buffer const * buf, ostream & os,
148 BufferParams const & bparams,
149 depth_type & dth) const
151 // The beginning or end of a deeper (i.e. nested) area?
152 if (dth != params().depth()) {
153 if (params().depth() > dth) {
154 while (params().depth() > dth) {
155 os << "\n\\begin_deeper ";
159 while (params().depth() < dth) {
160 os << "\n\\end_deeper ";
166 // First write the layout
167 os << "\n\\layout " << layout()->name() << '\n';
171 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
173 Change running_change = Change(Change::UNCHANGED);
174 lyx::time_type const curtime(lyx::current_time());
177 for (pos_type i = 0; i < size(); ++i) {
183 Change change = pimpl_->lookupChangeFull(i);
184 Changes::lyxMarkChange(os, column, curtime, running_change, change);
185 running_change = change;
187 // Write font changes
188 LyXFont font2 = getFontSettings(bparams, i);
189 if (font2 != font1) {
190 font2.lyxWriteChanges(font1, os);
195 value_type const c = getChar(i);
199 Inset const * inset = getInset(i);
201 if (inset->directWrite()) {
202 // international char, let it write
203 // code directly so it's shorter in
205 inset->write(buf, os);
207 os << "\n\\begin_inset ";
208 inset->write(buf, os);
209 os << "\n\\end_inset \n\n";
215 os << "\n\\backslash \n";
219 if (i + 1 < size() && getChar(i + 1) == ' ') {
226 if ((column > 70 && c == ' ')
231 // this check is to amend a bug. LyX sometimes
232 // inserts '\0' this could cause problems.
236 lyxerr << "ERROR (Paragraph::writeFile):"
237 " NULL char in structure." << endl;
243 // to make reading work properly
245 running_change = pimpl_->lookupChange(0);
246 Changes::lyxMarkChange(os, column, curtime,
247 Change(Change::UNCHANGED), running_change);
249 Changes::lyxMarkChange(os, column, curtime,
250 running_change, Change(Change::UNCHANGED));
254 void Paragraph::validate(LaTeXFeatures & features) const
256 pimpl_->validate(features, *layout());
260 // First few functions needed for cut and paste and paragraph breaking.
261 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
263 BufferParams bparams = buffer.params;
265 minibuffer_char = getChar(pos);
266 minibuffer_font = getFontSettings(bparams, pos);
267 minibuffer_inset = 0;
268 if (minibuffer_char == Paragraph::META_INSET) {
270 minibuffer_inset = getInset(pos)->clone(buffer);
272 minibuffer_inset = 0;
273 minibuffer_char = ' ';
274 // This reflects what GetInset() does (ARRae)
280 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
282 minibuffer_char = getChar(pos);
283 minibuffer_font = getFontSettings(bparams, pos);
284 minibuffer_inset = 0;
285 if (minibuffer_char == Paragraph::META_INSET) {
287 // the inset is not in a paragraph anymore
288 minibuffer_inset = insetlist.release(pos);
289 minibuffer_inset->parOwner(0);
291 minibuffer_inset = 0;
292 minibuffer_char = ' ';
293 // This reflects what GetInset() does (ARRae)
298 // Erase(pos); now the caller is responsible for that.
302 bool Paragraph::insertFromMinibuffer(pos_type pos)
304 if (minibuffer_char == Paragraph::META_INSET) {
305 if (!insetAllowed(minibuffer_inset->lyxCode())) {
308 insertInset(pos, minibuffer_inset, minibuffer_font);
310 LyXFont f = minibuffer_font;
311 if (!checkInsertChar(f)) {
314 insertChar(pos, minibuffer_char, f);
322 void Paragraph::eraseIntern(lyx::pos_type pos)
324 pimpl_->eraseIntern(pos);
328 bool Paragraph::erase(pos_type pos)
330 return pimpl_->erase(pos);
334 int Paragraph::erase(pos_type start, pos_type end)
336 return pimpl_->erase(start, end);
340 bool Paragraph::checkInsertChar(LyXFont & font)
342 if (pimpl_->inset_owner)
343 return pimpl_->inset_owner->checkInsertChar(font);
348 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
350 LyXFont const f(LyXFont::ALL_INHERIT);
351 insertChar(pos, c, f);
355 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
356 LyXFont const & font, Change change)
358 pimpl_->insertChar(pos, c, font, change);
362 void Paragraph::insertInset(pos_type pos, Inset * inset)
364 LyXFont const f(LyXFont::ALL_INHERIT);
365 insertInset(pos, inset, f);
369 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
371 pimpl_->insertInset(pos, inset, font, change);
375 bool Paragraph::insetAllowed(Inset::Code code)
377 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
378 if (pimpl_->inset_owner)
379 return pimpl_->inset_owner->insetAllowed(code);
384 Inset * Paragraph::getInset(pos_type pos)
386 lyx::Assert(pos < size());
387 return insetlist.get(pos);
391 Inset const * Paragraph::getInset(pos_type pos) const
393 lyx::Assert(pos < size());
394 return insetlist.get(pos);
398 // Gets uninstantiated font setting at position.
399 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
402 lyx::Assert(pos <= size());
404 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
405 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
406 for (; cit != end; ++cit) {
407 if (cit->pos() >= pos)
413 retfont = cit->font();
414 else if (pos == size() && !empty())
415 retfont = getFontSettings(bparams, pos - 1);
417 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
423 // Gets uninstantiated font setting at position 0
424 LyXFont const Paragraph::getFirstFontSettings() const
426 if (!empty() && !pimpl_->fontlist.empty())
427 return pimpl_->fontlist[0].font();
429 return LyXFont(LyXFont::ALL_INHERIT);
433 // Gets the fully instantiated font at a given position in a paragraph
434 // This is basically the same function as LyXText::GetFont() in text2.C.
435 // The difference is that this one is used for generating the LaTeX file,
436 // and thus cosmetic "improvements" are disallowed: This has to deliver
437 // the true picture of the buffer. (Asger)
438 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
439 LyXFont const & outerfont) const
441 lyx::Assert(pos >= 0);
443 LyXLayout_ptr const & lout = layout();
445 pos_type const body_pos = beginningOfBody();
449 layoutfont = lout->labelfont;
451 layoutfont = lout->font;
453 LyXFont tmpfont = getFontSettings(bparams, pos);
454 tmpfont.realize(layoutfont);
455 tmpfont.realize(outerfont);
457 return realizeFont(tmpfont, bparams);
461 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
462 LyXFont const & outerfont) const
464 LyXLayout_ptr const & lout = layout();
466 LyXFont tmpfont = lout->labelfont;
467 tmpfont.setLanguage(getParLanguage(bparams));
468 tmpfont.realize(outerfont);
470 return realizeFont(tmpfont, bparams);
474 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
475 LyXFont const & outerfont) const
477 LyXLayout_ptr const & lout = layout();
479 LyXFont tmpfont = lout->font;
480 tmpfont.setLanguage(getParLanguage(bparams));
481 tmpfont.realize(outerfont);
483 return realizeFont(tmpfont, bparams);
487 /// Returns the height of the highest font in range
489 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
490 LyXFont::FONT_SIZE const def_size) const
492 if (pimpl_->fontlist.empty())
495 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
496 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
497 for (; end_it != end; ++end_it) {
498 if (end_it->pos() >= endpos)
505 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
506 for (; cit != end; ++cit) {
507 if (cit->pos() >= startpos)
511 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
512 for (; cit != end_it; ++cit) {
513 LyXFont::FONT_SIZE size = cit->font().size();
514 if (size == LyXFont::INHERIT_SIZE)
516 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
523 Paragraph::value_type
524 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
526 value_type c = getChar(pos);
527 if (!lyxrc.rtl_support)
557 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
564 void Paragraph::setFont(pos_type pos, LyXFont const & font)
566 lyx::Assert(pos <= size());
568 // First, reduce font against layout/label font
569 // Update: The SetCharFont() routine in text2.C already
570 // reduces font, so we don't need to do that here. (Asger)
571 // No need to simplify this because it will disappear
572 // in a new kernel. (Asger)
573 // Next search font table
575 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
576 Pimpl::FontList::iterator it = beg;
577 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
578 for (; it != endit; ++it) {
579 if (it->pos() >= pos)
582 unsigned int i = std::distance(beg, it);
583 bool notfound = (it == endit);
585 if (!notfound && pimpl_->fontlist[i].font() == font)
588 bool begin = pos == 0 || notfound ||
589 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
590 // Is position pos is a beginning of a font block?
591 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
592 // Is position pos is the end of a font block?
593 if (begin && end) { // A single char block
594 if (i + 1 < pimpl_->fontlist.size() &&
595 pimpl_->fontlist[i + 1].font() == font) {
596 // Merge the singleton block with the next block
597 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
598 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
599 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
600 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
601 // Merge the singleton block with the previous block
602 pimpl_->fontlist[i - 1].pos(pos);
603 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
605 pimpl_->fontlist[i].font(font);
607 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
608 pimpl_->fontlist[i - 1].pos(pos);
610 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
611 Pimpl::FontTable(pos, font));
613 pimpl_->fontlist[i].pos(pos - 1);
614 if (!(i + 1 < pimpl_->fontlist.size() &&
615 pimpl_->fontlist[i + 1].font() == font))
616 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
617 Pimpl::FontTable(pos, font));
618 } else { // The general case. The block is splitted into 3 blocks
619 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
620 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
621 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
622 Pimpl::FontTable(pos, font));
628 void Paragraph::next(Paragraph * p)
634 // This function is able to hide closed footnotes.
635 Paragraph * Paragraph::next()
641 Paragraph const * Paragraph::next() const
647 void Paragraph::previous(Paragraph * p)
653 // This function is able to hide closed footnotes.
654 Paragraph * Paragraph::previous()
660 // This function is able to hide closed footnotes.
661 Paragraph const * Paragraph::previous() const
668 void Paragraph::makeSameLayout(Paragraph const & par)
670 layout(par.layout());
672 params() = par.params();
676 int Paragraph::stripLeadingSpaces()
678 if (layout()->free_spacing || isFreeSpacing())
682 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
683 pimpl_->eraseIntern(0);
691 bool Paragraph::hasSameLayout(Paragraph const & par) const
694 par.layout() == layout() &&
695 params().sameLayout(par.params());
699 Paragraph::depth_type Paragraph::getDepth() const
701 return params().depth();
705 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
707 if (layout()->isEnvironment())
708 return params().depth() + 1;
710 return params().depth();
714 char Paragraph::getAlign() const
716 return params().align();
720 string const & Paragraph::getLabelstring() const
722 return params().labelString();
726 // the next two functions are for the manual labels
727 string const Paragraph::getLabelWidthString() const
729 if (!params().labelWidthString().empty())
730 return params().labelWidthString();
732 return _("Senseless with this layout!");
736 void Paragraph::setLabelWidthString(string const & s)
738 params().labelWidthString(s);
742 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
745 params().labelWidthString(string());
746 params().align(LYX_ALIGN_LAYOUT);
747 params().spaceTop(VSpace(VSpace::NONE));
748 params().spaceBottom(VSpace(VSpace::NONE));
749 params().spacing(Spacing(Spacing::Default));
753 int Paragraph::beginningOfBody() const
755 if (layout()->labeltype != LABEL_MANUAL)
758 // Unroll the first two cycles of the loop
759 // and remember the previous character to
760 // remove unnecessary GetChar() calls
762 if (i < size() && !isNewline(i)) {
764 char previous_char = 0;
767 previous_char = getChar(i);
770 while (i < size() && previous_char != ' ') {
776 previous_char = temp;
786 // returns -1 if inset not found
787 int Paragraph::getPositionOfInset(Inset const * inset) const
790 InsetList::iterator it = insetlist.begin();
791 InsetList::iterator end = insetlist.end();
792 for (; it != end; ++it)
793 if (it.getInset() == inset)
799 InsetBibitem * Paragraph::bibitem()
801 InsetList::iterator it = insetlist.begin();
802 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
803 return static_cast<InsetBibitem *>(it.getInset());
809 // This could go to ParagraphParameters if we want to
810 int Paragraph::startTeXParParams(BufferParams const & bparams,
811 ostream & os, bool moving_arg) const
815 if (params().noindent()) {
820 switch (params().align()) {
822 case LYX_ALIGN_BLOCK:
823 case LYX_ALIGN_LAYOUT:
824 case LYX_ALIGN_SPECIAL:
827 case LYX_ALIGN_RIGHT:
828 case LYX_ALIGN_CENTER:
836 switch (params().align()) {
838 case LYX_ALIGN_BLOCK:
839 case LYX_ALIGN_LAYOUT:
840 case LYX_ALIGN_SPECIAL:
843 if (getParLanguage(bparams)->babel() != "hebrew") {
844 os << "\\begin{flushleft}";
847 os << "\\begin{flushright}";
851 case LYX_ALIGN_RIGHT:
852 if (getParLanguage(bparams)->babel() != "hebrew") {
853 os << "\\begin{flushright}";
856 os << "\\begin{flushleft}";
860 case LYX_ALIGN_CENTER:
861 os << "\\begin{center}";
870 // This could go to ParagraphParameters if we want to
871 int Paragraph::endTeXParParams(BufferParams const & bparams,
872 ostream & os, bool moving_arg) const
876 switch (params().align()) {
878 case LYX_ALIGN_BLOCK:
879 case LYX_ALIGN_LAYOUT:
880 case LYX_ALIGN_SPECIAL:
883 case LYX_ALIGN_RIGHT:
884 case LYX_ALIGN_CENTER:
892 switch (params().align()) {
894 case LYX_ALIGN_BLOCK:
895 case LYX_ALIGN_LAYOUT:
896 case LYX_ALIGN_SPECIAL:
899 if (getParLanguage(bparams)->babel() != "hebrew") {
900 os << "\\end{flushleft}";
903 os << "\\end{flushright}";
907 case LYX_ALIGN_RIGHT:
908 if (getParLanguage(bparams)->babel() != "hebrew") {
909 os << "\\end{flushright}";
912 os << "\\end{flushleft}";
916 case LYX_ALIGN_CENTER:
917 os << "\\end{center}";
925 // This one spits out the text of the paragraph
926 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
927 BufferParams const & bparams,
928 LyXFont const & outerfont,
929 ostream & os, TexRow & texrow,
932 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
934 bool return_value = false;
938 // well we have to check if we are in an inset with unlimited
939 // lenght (all in one row) if that is true then we don't allow
940 // any special options in the paragraph and also we don't allow
941 // any environment other then "Standard" to be valid!
943 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
946 style = bparams.getLyXTextClass().defaultLayout();
953 // Maybe we have to create a optional argument.
956 // FIXME: can we actually skip this check and just call
957 // beginningOfBody() ??
958 if (style->labeltype != LABEL_MANUAL) {
961 body_pos = beginningOfBody();
964 unsigned int column = 0;
969 basefont = getLabelFont(bparams, outerfont);
971 basefont = getLayoutFont(bparams, outerfont);
974 moving_arg |= style->needprotect;
976 // Which font is currently active?
977 LyXFont running_font(basefont);
978 // Do we have an open font change?
979 bool open_font = false;
981 Change::Type running_change = Change::UNCHANGED;
983 texrow.start(id(), 0);
985 // if the paragraph is empty, the loop will not be entered at all
987 if (style->isCommand()) {
992 column += startTeXParParams(bparams, os, moving_arg);
996 for (pos_type i = 0; i < size(); ++i) {
998 // First char in paragraph or after label?
1002 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1005 basefont = getLayoutFont(bparams, outerfont);
1006 running_font = basefont;
1010 if (style->isCommand()) {
1016 column += startTeXParParams(bparams, os,
1020 value_type c = getChar(i);
1022 // Fully instantiated font
1023 LyXFont font = getFont(bparams, i, outerfont);
1025 LyXFont const last_font = running_font;
1027 // Spaces at end of font change are simulated to be
1028 // outside font change, i.e. we write "\textXX{text} "
1029 // rather than "\textXX{text }". (Asger)
1030 if (open_font && c == ' ' && i <= size() - 2) {
1031 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
1032 if (next_font != running_font
1033 && next_font != font) {
1038 // We end font definition before blanks
1040 (font != running_font ||
1041 font.language() != running_font.language()))
1043 column += running_font.latexWriteEndChanges(os,
1045 (i == body_pos-1) ? basefont : font);
1046 running_font = basefont;
1050 // Blanks are printed before start of fontswitch
1052 // Do not print the separation of the optional argument
1053 if (i != body_pos - 1) {
1054 pimpl_->simpleTeXBlanks(os, texrow, i,
1055 column, font, *style);
1059 // Do we need to change font?
1060 if ((font != running_font ||
1061 font.language() != running_font.language()) &&
1064 column += font.latexWriteStartChanges(os, basefont,
1066 running_font = font;
1070 Change::Type change = pimpl_->lookupChange(i);
1072 column += Changes::latexMarkChange(os, running_change, change);
1073 running_change = change;
1075 pimpl_->simpleTeXSpecialChars(buf, bparams,
1076 os, texrow, moving_arg,
1078 basefont, outerfont, open_font,
1080 *style, i, column, c);
1083 column += Changes::latexMarkChange(os,
1084 running_change, Change::UNCHANGED);
1086 // If we have an open font definition, we have to close it
1088 #ifdef FIXED_LANGUAGE_END_DETECTION
1091 .latexWriteEndChanges(os, basefont,
1092 next_->getFont(bparams,
1095 running_font.latexWriteEndChanges(os, basefont,
1099 #ifdef WITH_WARNINGS
1100 //#warning For now we ALWAYS have to close the foreign font settings if they are
1101 //#warning there as we start another \selectlanguage with the next paragraph if
1102 //#warning we are in need of this. This should be fixed sometime (Jug)
1104 running_font.latexWriteEndChanges(os, basefont, basefont);
1108 // Needed if there is an optional argument but no contents.
1109 if (body_pos > 0 && body_pos == size()) {
1111 return_value = false;
1115 column += endTeXParParams(bparams, os, moving_arg);
1118 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1119 return return_value;
1125 bool Paragraph::isHfill(pos_type pos) const
1127 return IsInsetChar(getChar(pos))
1128 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1132 bool Paragraph::isInset(pos_type pos) const
1134 return IsInsetChar(getChar(pos));
1138 bool Paragraph::isNewline(pos_type pos) const
1140 return IsInsetChar(getChar(pos))
1141 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1145 bool Paragraph::isSeparator(pos_type pos) const
1147 return IsSeparatorChar(getChar(pos));
1151 bool Paragraph::isLineSeparator(pos_type pos) const
1153 value_type const c = getChar(pos);
1154 return IsLineSeparatorChar(c)
1155 || (IsInsetChar(c) && getInset(pos) &&
1156 getInset(pos)->isLineSeparator());
1160 bool Paragraph::isKomma(pos_type pos) const
1162 return IsKommaChar(getChar(pos));
1166 /// Used by the spellchecker
1167 bool Paragraph::isLetter(pos_type pos) const
1169 value_type const c = getChar(pos);
1170 if (IsLetterChar(c))
1173 return getInset(pos)->isLetter();
1174 // We want to pass the ' and escape chars to ispell
1175 string const extra = lyxrc.isp_esc_chars + '\'';
1176 return contains(extra, c);
1180 bool Paragraph::isWord(pos_type pos) const
1182 return IsWordChar(getChar(pos)) ;
1187 Paragraph::getParLanguage(BufferParams const & bparams) const
1190 return getFirstFontSettings().language();
1191 #warning FIXME we should check the prev par as well (Lgb)
1193 } else if (previous_) {
1194 return previous_->getParLanguage(bparams);
1197 return bparams.language;
1201 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1203 return lyxrc.rtl_support
1204 && getParLanguage(bparams)->RightToLeft()
1205 && !(inInset() && inInset()->owner() &&
1206 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1210 void Paragraph::changeLanguage(BufferParams const & bparams,
1211 Language const * from, Language const * to)
1213 for (pos_type i = 0; i < size(); ++i) {
1214 LyXFont font = getFontSettings(bparams, i);
1215 if (font.language() == from) {
1216 font.setLanguage(to);
1223 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1225 Language const * doc_language = bparams.language;
1226 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1227 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1229 for (; cit != end; ++cit)
1230 if (cit->font().language() != ignore_language &&
1231 cit->font().language() != latex_language &&
1232 cit->font().language() != doc_language)
1238 // Convert the paragraph to a string.
1239 // Used for building the table of contents
1240 string const Paragraph::asString(Buffer const * buffer, bool label) const
1243 if (label && !params().labelString().empty())
1244 s += params().labelString() + ' ';
1246 for (pos_type i = 0; i < size(); ++i) {
1247 value_type c = getChar(i);
1250 else if (c == META_INSET &&
1251 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1253 getInset(i)->ascii(buffer, ost);
1254 s += subst(STRCONV(ost.str()),'\n',' ');
1262 string const Paragraph::asString(Buffer const * buffer,
1263 pos_type beg, pos_type end, bool label) const
1267 if (beg == 0 && label && !params().labelString().empty())
1268 os << params().labelString() << ' ';
1270 for (pos_type i = beg; i < end; ++i) {
1271 value_type const c = getUChar(buffer->params, i);
1274 else if (c == META_INSET)
1275 getInset(i)->ascii(buffer, os);
1278 return STRCONV(os.str());
1282 void Paragraph::setInsetOwner(Inset * i)
1284 pimpl_->inset_owner = i;
1285 InsetList::iterator it = insetlist.begin();
1286 InsetList::iterator end = insetlist.end();
1287 for (; it != end; ++it)
1289 it.getInset()->setOwner(i);
1293 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1296 insetlist.deleteInsetsLyXText(bv);
1300 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1303 insetlist.resizeInsetsLyXText(bv);
1307 void Paragraph::setContentsFromPar(Paragraph const & par)
1309 pimpl_->setContentsFromPar(par);
1313 void Paragraph::trackChanges(Change::Type type)
1315 pimpl_->trackChanges(type);
1319 void Paragraph::untrackChanges()
1321 pimpl_->untrackChanges();
1325 void Paragraph::cleanChanges()
1327 pimpl_->cleanChanges();
1331 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1333 lyx::Assert(!size() || pos < size());
1334 return pimpl_->lookupChange(pos);
1338 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1340 lyx::Assert(!size() || pos < size());
1341 return pimpl_->lookupChangeFull(pos);
1345 bool Paragraph::isChanged(pos_type start, pos_type end) const
1347 return pimpl_->isChanged(start, end);
1351 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1353 return pimpl_->isChangeEdited(start, end);
1357 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1359 pimpl_->setChange(pos, type);
1364 void Paragraph::markErased()
1366 pimpl_->markErased();
1370 void Paragraph::acceptChange(pos_type start, pos_type end)
1372 return pimpl_->acceptChange(start, end);
1376 void Paragraph::rejectChange(pos_type start, pos_type end)
1378 return pimpl_->rejectChange(start, end);
1382 lyx::pos_type Paragraph::size() const
1384 return pimpl_->size();
1388 bool Paragraph::empty() const
1390 return pimpl_->empty();
1394 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1396 return pimpl_->getChar(pos);
1400 int Paragraph::id() const
1406 LyXLayout_ptr const & Paragraph::layout() const
1412 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1414 layout_ = new_layout;
1418 Inset * Paragraph::inInset() const
1420 return pimpl_->inset_owner;
1424 void Paragraph::clearContents()
1429 void Paragraph::setChar(pos_type pos, value_type c)
1431 pimpl_->setChar(pos, c);
1435 ParagraphParameters & Paragraph::params()
1437 return pimpl_->params;
1441 ParagraphParameters const & Paragraph::params() const
1443 return pimpl_->params;
1447 bool Paragraph::isFreeSpacing() const
1449 // for now we just need this, later should we need this in some
1450 // other way we can always add a function to Inset::() too.
1451 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1452 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);