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"
17 #include "bufferparams.h"
18 #include "BufferView.h"
24 #include "latexrunparams.h"
27 #include "paragraph_funcs.h"
28 #include "ParameterStruct.h"
33 #include "insets/insetbibitem.h"
34 #include "insets/insetoptarg.h"
35 #include "insets/insetenv.h"
37 #include "support/filetools.h"
38 #include "support/lstrings.h"
39 #include "support/lyxmanip.h"
40 #include "support/FileInfo.h"
41 #include "support/LAssert.h"
42 #include "support/textutils.h"
53 using std::lower_bound;
54 using std::upper_bound;
59 // this is a minibuffer
64 LyXFont minibuffer_font;
65 Inset * minibuffer_inset;
70 Paragraph::Paragraph()
71 : pimpl_(new Paragraph::Pimpl(this))
79 Paragraph::Paragraph(Paragraph const & lp)
80 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
84 // this is because of the dummy layout of the paragraphs that
86 layout_ = lp.layout();
88 // copy everything behind the break-position to the new paragraph
89 insetlist = lp.insetlist;
90 InsetList::iterator it = insetlist.begin();
91 InsetList::iterator end = insetlist.end();
92 for (; it != end; ++it) {
93 it->inset = it->inset->clone();
94 // tell the new inset who is the boss now
95 it->inset->parOwner(this);
100 void Paragraph::operator=(Paragraph const & lp)
102 // needed as we will destroy the pimpl_ before copying it
105 lyxerr << "Paragraph::operator=()\n";
107 pimpl_ = new Pimpl(*lp.pimpl_, this);
109 enumdepth = lp.enumdepth;
110 itemdepth = lp.itemdepth;
111 // this is because of the dummy layout of the paragraphs that
113 layout_ = lp.layout();
115 // copy everything behind the break-position to the new paragraph
116 insetlist = lp.insetlist;
117 InsetList::iterator it = insetlist.begin();
118 InsetList::iterator end = insetlist.end();
119 for (; it != end; ++it) {
120 it->inset = it->inset->clone();
121 // tell the new inset who is the boss now
122 it->inset->parOwner(this);
126 // the destructor removes the new paragraph from the list
127 Paragraph::~Paragraph()
131 //lyxerr << "Paragraph::paragraph_id = "
132 // << Paragraph::paragraph_id << endl;
136 void Paragraph::write(Buffer const * buf, ostream & os,
137 BufferParams const & bparams,
138 depth_type & dth) const
140 // The beginning or end of a deeper (i.e. nested) area?
141 if (dth != params().depth()) {
142 if (params().depth() > dth) {
143 while (params().depth() > dth) {
144 os << "\n\\begin_deeper ";
148 while (params().depth() < dth) {
149 os << "\n\\end_deeper ";
155 // First write the layout
156 os << "\n\\layout " << layout()->name() << '\n';
160 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
162 Change running_change = Change(Change::UNCHANGED);
163 lyx::time_type const curtime(lyx::current_time());
166 for (pos_type i = 0; i < size(); ++i) {
172 Change change = pimpl_->lookupChangeFull(i);
173 Changes::lyxMarkChange(os, column, curtime, running_change, change);
174 running_change = change;
176 // Write font changes
177 LyXFont font2 = getFontSettings(bparams, i);
178 if (font2 != font1) {
179 font2.lyxWriteChanges(font1, os);
184 value_type const c = getChar(i);
188 Inset const * inset = getInset(i);
190 if (inset->directWrite()) {
191 // international char, let it write
192 // code directly so it's shorter in
194 inset->write(buf, os);
196 os << "\n\\begin_inset ";
197 inset->write(buf, os);
198 os << "\n\\end_inset \n\n";
204 os << "\n\\backslash \n";
208 if (i + 1 < size() && getChar(i + 1) == ' ') {
215 if ((column > 70 && c == ' ')
220 // this check is to amend a bug. LyX sometimes
221 // inserts '\0' this could cause problems.
225 lyxerr << "ERROR (Paragraph::writeFile):"
226 " NULL char in structure." << endl;
232 // to make reading work properly
234 running_change = pimpl_->lookupChange(0);
235 Changes::lyxMarkChange(os, column, curtime,
236 Change(Change::UNCHANGED), running_change);
238 Changes::lyxMarkChange(os, column, curtime,
239 running_change, Change(Change::UNCHANGED));
243 void Paragraph::validate(LaTeXFeatures & features) const
245 pimpl_->validate(features, *layout());
249 // First few functions needed for cut and paste and paragraph breaking.
250 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
252 BufferParams bparams = buffer.params;
254 minibuffer_char = getChar(pos);
255 minibuffer_font = getFontSettings(bparams, pos);
256 minibuffer_inset = 0;
257 if (minibuffer_char == Paragraph::META_INSET) {
259 minibuffer_inset = getInset(pos)->clone();
261 minibuffer_inset = 0;
262 minibuffer_char = ' ';
263 // This reflects what GetInset() does (ARRae)
269 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
271 minibuffer_char = getChar(pos);
272 minibuffer_font = getFontSettings(bparams, pos);
273 minibuffer_inset = 0;
274 if (minibuffer_char == Paragraph::META_INSET) {
276 // the inset is not in a paragraph anymore
277 minibuffer_inset = insetlist.release(pos);
278 minibuffer_inset->parOwner(0);
280 minibuffer_inset = 0;
281 minibuffer_char = ' ';
282 // This reflects what GetInset() does (ARRae)
287 // Erase(pos); now the caller is responsible for that.
291 bool Paragraph::insertFromMinibuffer(pos_type pos)
293 if (minibuffer_char == Paragraph::META_INSET) {
294 if (!insetAllowed(minibuffer_inset->lyxCode())) {
297 insertInset(pos, minibuffer_inset, minibuffer_font);
299 LyXFont f = minibuffer_font;
300 if (!checkInsertChar(f)) {
303 insertChar(pos, minibuffer_char, f);
311 void Paragraph::eraseIntern(lyx::pos_type pos)
313 pimpl_->eraseIntern(pos);
317 bool Paragraph::erase(pos_type pos)
319 return pimpl_->erase(pos);
323 int Paragraph::erase(pos_type start, pos_type end)
325 return pimpl_->erase(start, end);
329 bool Paragraph::checkInsertChar(LyXFont & font)
331 if (pimpl_->inset_owner)
332 return pimpl_->inset_owner->checkInsertChar(font);
337 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
339 LyXFont const f(LyXFont::ALL_INHERIT);
340 insertChar(pos, c, f);
344 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
345 LyXFont const & font, Change change)
347 pimpl_->insertChar(pos, c, font, change);
351 void Paragraph::insertInset(pos_type pos, Inset * inset)
353 LyXFont const f(LyXFont::ALL_INHERIT);
354 insertInset(pos, inset, f);
358 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
360 pimpl_->insertInset(pos, inset, font, change);
364 bool Paragraph::insetAllowed(Inset::Code code)
366 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
367 if (pimpl_->inset_owner)
368 return pimpl_->inset_owner->insetAllowed(code);
373 Inset * Paragraph::getInset(pos_type pos)
375 lyx::Assert(pos < size());
376 return insetlist.get(pos);
380 Inset const * Paragraph::getInset(pos_type pos) const
382 lyx::Assert(pos < size());
383 return insetlist.get(pos);
387 // Gets uninstantiated font setting at position.
388 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
391 lyx::Assert(pos <= size());
393 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
394 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
395 for (; cit != end; ++cit) {
396 if (cit->pos() >= pos)
402 retfont = cit->font();
403 else if (pos == size() && !empty())
404 retfont = getFontSettings(bparams, pos - 1);
406 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
412 // Gets uninstantiated font setting at position 0
413 LyXFont const Paragraph::getFirstFontSettings() const
415 if (!empty() && !pimpl_->fontlist.empty())
416 return pimpl_->fontlist[0].font();
418 return LyXFont(LyXFont::ALL_INHERIT);
422 // Gets the fully instantiated font at a given position in a paragraph
423 // This is basically the same function as LyXText::GetFont() in text2.C.
424 // The difference is that this one is used for generating the LaTeX file,
425 // and thus cosmetic "improvements" are disallowed: This has to deliver
426 // the true picture of the buffer. (Asger)
427 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
428 LyXFont const & outerfont) const
430 lyx::Assert(pos >= 0);
432 LyXLayout_ptr const & lout = layout();
434 pos_type const body_pos = beginningOfBody();
438 layoutfont = lout->labelfont;
440 layoutfont = lout->font;
442 LyXFont tmpfont = getFontSettings(bparams, pos);
443 tmpfont.realize(layoutfont);
444 tmpfont.realize(outerfont);
446 return realizeFont(tmpfont, bparams);
450 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
451 LyXFont const & outerfont) const
453 LyXLayout_ptr const & lout = layout();
455 LyXFont tmpfont = lout->labelfont;
456 tmpfont.setLanguage(getParLanguage(bparams));
457 tmpfont.realize(outerfont);
459 return realizeFont(tmpfont, bparams);
463 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
464 LyXFont const & outerfont) const
466 LyXLayout_ptr const & lout = layout();
468 LyXFont tmpfont = lout->font;
469 tmpfont.setLanguage(getParLanguage(bparams));
470 tmpfont.realize(outerfont);
472 return realizeFont(tmpfont, bparams);
476 /// Returns the height of the highest font in range
478 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
479 LyXFont::FONT_SIZE const def_size) const
481 if (pimpl_->fontlist.empty())
484 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
485 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
486 for (; end_it != end; ++end_it) {
487 if (end_it->pos() >= endpos)
494 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
495 for (; cit != end; ++cit) {
496 if (cit->pos() >= startpos)
500 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
501 for (; cit != end_it; ++cit) {
502 LyXFont::FONT_SIZE size = cit->font().size();
503 if (size == LyXFont::INHERIT_SIZE)
505 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
512 Paragraph::value_type
513 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
515 value_type c = getChar(pos);
516 if (!lyxrc.rtl_support)
546 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
553 void Paragraph::setFont(pos_type pos, LyXFont const & font)
555 lyx::Assert(pos <= size());
557 // First, reduce font against layout/label font
558 // Update: The SetCharFont() routine in text2.C already
559 // reduces font, so we don't need to do that here. (Asger)
560 // No need to simplify this because it will disappear
561 // in a new kernel. (Asger)
562 // Next search font table
564 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
565 Pimpl::FontList::iterator it = beg;
566 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
567 for (; it != endit; ++it) {
568 if (it->pos() >= pos)
571 unsigned int i = std::distance(beg, it);
572 bool notfound = (it == endit);
574 if (!notfound && pimpl_->fontlist[i].font() == font)
577 bool begin = pos == 0 || notfound ||
578 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
579 // Is position pos is a beginning of a font block?
580 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
581 // Is position pos is the end of a font block?
582 if (begin && end) { // A single char block
583 if (i + 1 < pimpl_->fontlist.size() &&
584 pimpl_->fontlist[i + 1].font() == font) {
585 // Merge the singleton block with the next block
586 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
587 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
588 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
589 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
590 // Merge the singleton block with the previous block
591 pimpl_->fontlist[i - 1].pos(pos);
592 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
594 pimpl_->fontlist[i].font(font);
596 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
597 pimpl_->fontlist[i - 1].pos(pos);
599 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
600 Pimpl::FontTable(pos, font));
602 pimpl_->fontlist[i].pos(pos - 1);
603 if (!(i + 1 < pimpl_->fontlist.size() &&
604 pimpl_->fontlist[i + 1].font() == font))
605 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
606 Pimpl::FontTable(pos, font));
607 } else { // The general case. The block is splitted into 3 blocks
608 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
609 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
610 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
611 Pimpl::FontTable(pos, font));
616 void Paragraph::makeSameLayout(Paragraph const & par)
618 layout(par.layout());
620 params() = par.params();
624 int Paragraph::stripLeadingSpaces()
626 if (layout()->free_spacing || isFreeSpacing())
630 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
631 pimpl_->eraseIntern(0);
639 bool Paragraph::hasSameLayout(Paragraph const & par) const
642 par.layout() == layout() &&
643 params().sameLayout(par.params());
647 Paragraph::depth_type Paragraph::getDepth() const
649 return params().depth();
653 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
655 if (layout()->isEnvironment())
656 return params().depth() + 1;
658 return params().depth();
662 char Paragraph::getAlign() const
664 return params().align();
668 string const & Paragraph::getLabelstring() const
670 return params().labelString();
674 // the next two functions are for the manual labels
675 string const Paragraph::getLabelWidthString() const
677 if (!params().labelWidthString().empty())
678 return params().labelWidthString();
680 return _("Senseless with this layout!");
684 void Paragraph::setLabelWidthString(string const & s)
686 params().labelWidthString(s);
690 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
693 params().labelWidthString(string());
694 params().align(LYX_ALIGN_LAYOUT);
695 params().spaceTop(VSpace(VSpace::NONE));
696 params().spaceBottom(VSpace(VSpace::NONE));
697 params().spacing(Spacing(Spacing::Default));
701 int Paragraph::beginningOfBody() const
703 if (layout()->labeltype != LABEL_MANUAL)
706 // Unroll the first two cycles of the loop
707 // and remember the previous character to
708 // remove unnecessary GetChar() calls
710 if (i < size() && !isNewline(i)) {
712 char previous_char = 0;
715 previous_char = getChar(i);
718 while (i < size() && previous_char != ' ') {
724 previous_char = temp;
734 // returns -1 if inset not found
735 int Paragraph::getPositionOfInset(Inset const * inset) const
738 InsetList::const_iterator it = insetlist.begin();
739 InsetList::const_iterator end = insetlist.end();
740 for (; it != end; ++it)
741 if (it->inset == inset)
747 InsetBibitem * Paragraph::bibitem() const
749 InsetList::const_iterator it = insetlist.begin();
750 if (it != insetlist.end() && it->inset->lyxCode() == Inset::BIBTEX_CODE)
751 return static_cast<InsetBibitem *>(it->inset);
757 // This could go to ParagraphParameters if we want to
758 int Paragraph::startTeXParParams(BufferParams const & bparams,
759 ostream & os, bool moving_arg) const
763 if (params().noindent()) {
768 switch (params().align()) {
770 case LYX_ALIGN_BLOCK:
771 case LYX_ALIGN_LAYOUT:
772 case LYX_ALIGN_SPECIAL:
775 case LYX_ALIGN_RIGHT:
776 case LYX_ALIGN_CENTER:
784 switch (params().align()) {
786 case LYX_ALIGN_BLOCK:
787 case LYX_ALIGN_LAYOUT:
788 case LYX_ALIGN_SPECIAL:
791 if (getParLanguage(bparams)->babel() != "hebrew") {
792 os << "\\begin{flushleft}";
795 os << "\\begin{flushright}";
799 case LYX_ALIGN_RIGHT:
800 if (getParLanguage(bparams)->babel() != "hebrew") {
801 os << "\\begin{flushright}";
804 os << "\\begin{flushleft}";
808 case LYX_ALIGN_CENTER:
809 os << "\\begin{center}";
818 // This could go to ParagraphParameters if we want to
819 int Paragraph::endTeXParParams(BufferParams const & bparams,
820 ostream & os, bool moving_arg) const
824 switch (params().align()) {
826 case LYX_ALIGN_BLOCK:
827 case LYX_ALIGN_LAYOUT:
828 case LYX_ALIGN_SPECIAL:
831 case LYX_ALIGN_RIGHT:
832 case LYX_ALIGN_CENTER:
840 switch (params().align()) {
842 case LYX_ALIGN_BLOCK:
843 case LYX_ALIGN_LAYOUT:
844 case LYX_ALIGN_SPECIAL:
847 if (getParLanguage(bparams)->babel() != "hebrew") {
848 os << "\\end{flushleft}";
851 os << "\\end{flushright}";
855 case LYX_ALIGN_RIGHT:
856 if (getParLanguage(bparams)->babel() != "hebrew") {
857 os << "\\end{flushright}";
860 os << "\\end{flushleft}";
864 case LYX_ALIGN_CENTER:
865 os << "\\end{center}";
873 // This one spits out the text of the paragraph
874 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
875 BufferParams const & bparams,
876 LyXFont const & outerfont,
877 ostream & os, TexRow & texrow,
878 LatexRunParams const & runparams)
880 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
882 bool return_value = false;
886 // well we have to check if we are in an inset with unlimited
887 // lenght (all in one row) if that is true then we don't allow
888 // any special options in the paragraph and also we don't allow
889 // any environment other then "Standard" to be valid!
891 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
894 style = bparams.getLyXTextClass().defaultLayout();
901 // Maybe we have to create a optional argument.
904 // FIXME: can we actually skip this check and just call
905 // beginningOfBody() ??
906 if (style->labeltype != LABEL_MANUAL) {
909 body_pos = beginningOfBody();
912 unsigned int column = 0;
917 basefont = getLabelFont(bparams, outerfont);
919 basefont = getLayoutFont(bparams, outerfont);
922 bool moving_arg = runparams.moving_arg;
923 moving_arg |= style->needprotect;
925 // Which font is currently active?
926 LyXFont running_font(basefont);
927 // Do we have an open font change?
928 bool open_font = false;
930 Change::Type running_change = Change::UNCHANGED;
932 texrow.start(id(), 0);
934 // if the paragraph is empty, the loop will not be entered at all
936 if (style->isCommand()) {
941 column += startTeXParParams(bparams, os, moving_arg);
945 for (pos_type i = 0; i < size(); ++i) {
947 // First char in paragraph or after label?
951 column += running_font.latexWriteEndChanges(os, basefont, basefont);
954 basefont = getLayoutFont(bparams, outerfont);
955 running_font = basefont;
959 if (style->isCommand()) {
965 column += startTeXParParams(bparams, os,
969 value_type c = getChar(i);
971 // Fully instantiated font
972 LyXFont font = getFont(bparams, i, outerfont);
974 LyXFont const last_font = running_font;
976 // Spaces at end of font change are simulated to be
977 // outside font change, i.e. we write "\textXX{text} "
978 // rather than "\textXX{text }". (Asger)
979 if (open_font && c == ' ' && i <= size() - 2) {
980 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
981 if (next_font != running_font
982 && next_font != font) {
987 // We end font definition before blanks
989 (font != running_font ||
990 font.language() != running_font.language()))
992 column += running_font.latexWriteEndChanges(os,
994 (i == body_pos-1) ? basefont : font);
995 running_font = basefont;
999 // Blanks are printed before start of fontswitch
1001 // Do not print the separation of the optional argument
1002 if (i != body_pos - 1) {
1003 pimpl_->simpleTeXBlanks(os, texrow, i,
1004 column, font, *style);
1008 // Do we need to change font?
1009 if ((font != running_font ||
1010 font.language() != running_font.language()) &&
1013 column += font.latexWriteStartChanges(os, basefont,
1015 running_font = font;
1019 Change::Type change = pimpl_->lookupChange(i);
1021 column += Changes::latexMarkChange(os, running_change, change);
1022 running_change = change;
1024 LatexRunParams rp = runparams;
1025 rp.moving_arg = moving_arg;
1026 rp.free_spacing = style->free_spacing;
1027 pimpl_->simpleTeXSpecialChars(buf, bparams,
1028 os, texrow, runparams,
1030 basefont, outerfont, open_font,
1032 *style, i, column, c);
1035 column += Changes::latexMarkChange(os,
1036 running_change, Change::UNCHANGED);
1038 // If we have an open font definition, we have to close it
1040 #ifdef FIXED_LANGUAGE_END_DETECTION
1043 .latexWriteEndChanges(os, basefont,
1044 next_->getFont(bparams,
1047 running_font.latexWriteEndChanges(os, basefont,
1051 #ifdef WITH_WARNINGS
1052 //#warning For now we ALWAYS have to close the foreign font settings if they are
1053 //#warning there as we start another \selectlanguage with the next paragraph if
1054 //#warning we are in need of this. This should be fixed sometime (Jug)
1056 running_font.latexWriteEndChanges(os, basefont, basefont);
1060 // Needed if there is an optional argument but no contents.
1061 if (body_pos > 0 && body_pos == size()) {
1063 return_value = false;
1067 column += endTeXParParams(bparams, os, moving_arg);
1070 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1071 return return_value;
1077 bool Paragraph::isHfill(pos_type pos) const
1079 return IsInsetChar(getChar(pos))
1080 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1084 bool Paragraph::isInset(pos_type pos) const
1086 return IsInsetChar(getChar(pos));
1090 bool Paragraph::isNewline(pos_type pos) const
1092 return IsInsetChar(getChar(pos))
1093 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1097 bool Paragraph::isSeparator(pos_type pos) const
1099 return IsSeparatorChar(getChar(pos));
1103 bool Paragraph::isLineSeparator(pos_type pos) const
1105 value_type const c = getChar(pos);
1106 return IsLineSeparatorChar(c)
1107 || (IsInsetChar(c) && getInset(pos) &&
1108 getInset(pos)->isLineSeparator());
1112 bool Paragraph::isKomma(pos_type pos) const
1114 return IsKommaChar(getChar(pos));
1118 /// Used by the spellchecker
1119 bool Paragraph::isLetter(pos_type pos) const
1121 value_type const c = getChar(pos);
1122 if (IsLetterChar(c))
1125 return getInset(pos)->isLetter();
1126 // We want to pass the ' and escape chars to ispell
1127 string const extra = lyxrc.isp_esc_chars + '\'';
1128 return contains(extra, c);
1132 bool Paragraph::isWord(pos_type pos) const
1134 return IsWordChar(getChar(pos)) ;
1139 Paragraph::getParLanguage(BufferParams const & bparams) const
1142 return getFirstFontSettings().language();
1143 #warning FIXME we should check the prev par as well (Lgb)
1145 } else if (previous_) {
1146 return previous_->getParLanguage(bparams);
1149 return bparams.language;
1153 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1155 return lyxrc.rtl_support
1156 && getParLanguage(bparams)->RightToLeft()
1157 && !(inInset() && inInset()->owner() &&
1158 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1162 void Paragraph::changeLanguage(BufferParams const & bparams,
1163 Language const * from, Language const * to)
1165 for (pos_type i = 0; i < size(); ++i) {
1166 LyXFont font = getFontSettings(bparams, i);
1167 if (font.language() == from) {
1168 font.setLanguage(to);
1175 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1177 Language const * doc_language = bparams.language;
1178 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1179 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1181 for (; cit != end; ++cit)
1182 if (cit->font().language() != ignore_language &&
1183 cit->font().language() != latex_language &&
1184 cit->font().language() != doc_language)
1190 // Convert the paragraph to a string.
1191 // Used for building the table of contents
1192 string const Paragraph::asString(Buffer const * buffer, bool label) const
1195 if (label && !params().labelString().empty())
1196 s += params().labelString() + ' ';
1198 for (pos_type i = 0; i < size(); ++i) {
1199 value_type c = getChar(i);
1202 else if (c == META_INSET &&
1203 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1205 getInset(i)->ascii(buffer, ost);
1206 s += subst(STRCONV(ost.str()),'\n',' ');
1214 string const Paragraph::asString(Buffer const * buffer,
1215 pos_type beg, pos_type end, bool label) const
1219 if (beg == 0 && label && !params().labelString().empty())
1220 os << params().labelString() << ' ';
1222 for (pos_type i = beg; i < end; ++i) {
1223 value_type const c = getUChar(buffer->params, i);
1226 else if (c == META_INSET)
1227 getInset(i)->ascii(buffer, os);
1230 return STRCONV(os.str());
1234 void Paragraph::setInsetOwner(UpdatableInset * inset)
1236 pimpl_->inset_owner = inset;
1237 InsetList::iterator it = insetlist.begin();
1238 InsetList::iterator end = insetlist.end();
1239 for (; it != end; ++it)
1241 it->inset->setOwner(inset);
1245 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1248 insetlist.deleteInsetsLyXText(bv);
1252 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1255 insetlist.resizeInsetsLyXText(bv);
1259 void Paragraph::setContentsFromPar(Paragraph const & par)
1261 pimpl_->setContentsFromPar(par);
1265 void Paragraph::trackChanges(Change::Type type)
1267 pimpl_->trackChanges(type);
1271 void Paragraph::untrackChanges()
1273 pimpl_->untrackChanges();
1277 void Paragraph::cleanChanges()
1279 pimpl_->cleanChanges();
1283 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1285 lyx::Assert(!size() || pos < size());
1286 return pimpl_->lookupChange(pos);
1290 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1292 lyx::Assert(!size() || pos < size());
1293 return pimpl_->lookupChangeFull(pos);
1297 bool Paragraph::isChanged(pos_type start, pos_type end) const
1299 return pimpl_->isChanged(start, end);
1303 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1305 return pimpl_->isChangeEdited(start, end);
1309 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1311 pimpl_->setChange(pos, type);
1316 void Paragraph::markErased()
1318 pimpl_->markErased();
1322 void Paragraph::acceptChange(pos_type start, pos_type end)
1324 return pimpl_->acceptChange(start, end);
1328 void Paragraph::rejectChange(pos_type start, pos_type end)
1330 return pimpl_->rejectChange(start, end);
1334 lyx::pos_type Paragraph::size() const
1336 return pimpl_->size();
1340 bool Paragraph::empty() const
1342 return pimpl_->empty();
1346 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1348 return pimpl_->getChar(pos);
1352 int Paragraph::id() const
1358 void Paragraph::id(int i)
1364 LyXLayout_ptr const & Paragraph::layout() const
1367 Inset * inset = inInset();
1368 if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
1369 return static_cast<InsetEnvironment*>(inset)->layout();
1375 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1377 layout_ = new_layout;
1381 UpdatableInset * Paragraph::inInset() const
1383 return pimpl_->inset_owner;
1387 void Paragraph::clearContents()
1392 void Paragraph::setChar(pos_type pos, value_type c)
1394 pimpl_->setChar(pos, c);
1398 ParagraphParameters & Paragraph::params()
1400 return pimpl_->params;
1404 ParagraphParameters const & Paragraph::params() const
1406 return pimpl_->params;
1410 bool Paragraph::isFreeSpacing() const
1412 // for now we just need this, later should we need this in some
1413 // other way we can always add a function to Inset::() too.
1414 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1415 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
1420 bool operator==(Paragraph const & lhs, Paragraph const & rhs)
1422 #warning FIXME this implementatoin must be completely wrong...
1423 return &lhs == &rhs;