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 // currently we hold Inset*, not InsetBase*
94 it->inset = static_cast<Inset*>(it->inset->clone());
95 // tell the new inset who is the boss now
96 it->inset->parOwner(this);
101 void Paragraph::operator=(Paragraph const & lp)
103 // needed as we will destroy the pimpl_ before copying it
106 lyxerr << "Paragraph::operator=()\n";
108 pimpl_ = new Pimpl(*lp.pimpl_, this);
110 enumdepth = lp.enumdepth;
111 itemdepth = lp.itemdepth;
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->inset = static_cast<Inset*>(it->inset->clone());
122 // tell the new inset who is the boss now
123 it->inset->parOwner(this);
127 // the destructor removes the new paragraph from the list
128 Paragraph::~Paragraph()
132 //lyxerr << "Paragraph::paragraph_id = "
133 // << Paragraph::paragraph_id << endl;
137 void Paragraph::write(Buffer const * buf, ostream & os,
138 BufferParams const & bparams,
139 depth_type & dth) const
141 // The beginning or end of a deeper (i.e. nested) area?
142 if (dth != params().depth()) {
143 if (params().depth() > dth) {
144 while (params().depth() > dth) {
145 os << "\n\\begin_deeper ";
149 while (params().depth() < dth) {
150 os << "\n\\end_deeper ";
156 // First write the layout
157 os << "\n\\layout " << layout()->name() << '\n';
161 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
163 Change running_change = Change(Change::UNCHANGED);
164 lyx::time_type const curtime(lyx::current_time());
167 for (pos_type i = 0; i < size(); ++i) {
173 Change change = pimpl_->lookupChangeFull(i);
174 Changes::lyxMarkChange(os, column, curtime, running_change, change);
175 running_change = change;
177 // Write font changes
178 LyXFont font2 = getFontSettings(bparams, i);
179 if (font2 != font1) {
180 font2.lyxWriteChanges(font1, os);
185 value_type const c = getChar(i);
189 Inset const * inset = getInset(i);
191 if (inset->directWrite()) {
192 // international char, let it write
193 // code directly so it's shorter in
195 inset->write(buf, os);
197 os << "\n\\begin_inset ";
198 inset->write(buf, os);
199 os << "\n\\end_inset \n\n";
205 os << "\n\\backslash \n";
209 if (i + 1 < size() && getChar(i + 1) == ' ') {
216 if ((column > 70 && c == ' ')
221 // this check is to amend a bug. LyX sometimes
222 // inserts '\0' this could cause problems.
226 lyxerr << "ERROR (Paragraph::writeFile):"
227 " NULL char in structure." << endl;
233 // to make reading work properly
235 running_change = pimpl_->lookupChange(0);
236 Changes::lyxMarkChange(os, column, curtime,
237 Change(Change::UNCHANGED), running_change);
239 Changes::lyxMarkChange(os, column, curtime,
240 running_change, Change(Change::UNCHANGED));
244 void Paragraph::validate(LaTeXFeatures & features) const
246 pimpl_->validate(features, *layout());
250 // First few functions needed for cut and paste and paragraph breaking.
251 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
253 BufferParams bparams = buffer.params;
255 minibuffer_char = getChar(pos);
256 minibuffer_font = getFontSettings(bparams, pos);
257 minibuffer_inset = 0;
258 if (minibuffer_char == Paragraph::META_INSET) {
260 minibuffer_inset = static_cast<Inset *>(getInset(pos)->clone());
262 minibuffer_inset = 0;
263 minibuffer_char = ' ';
264 // This reflects what GetInset() does (ARRae)
270 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
272 minibuffer_char = getChar(pos);
273 minibuffer_font = getFontSettings(bparams, pos);
274 minibuffer_inset = 0;
275 if (minibuffer_char == Paragraph::META_INSET) {
277 // the inset is not in a paragraph anymore
278 minibuffer_inset = insetlist.release(pos);
279 minibuffer_inset->parOwner(0);
281 minibuffer_inset = 0;
282 minibuffer_char = ' ';
283 // This reflects what GetInset() does (ARRae)
288 // Erase(pos); now the caller is responsible for that.
292 bool Paragraph::insertFromMinibuffer(pos_type pos)
294 if (minibuffer_char == Paragraph::META_INSET) {
295 if (!insetAllowed(minibuffer_inset->lyxCode())) {
298 insertInset(pos, minibuffer_inset, minibuffer_font);
300 LyXFont f = minibuffer_font;
301 if (!checkInsertChar(f)) {
304 insertChar(pos, minibuffer_char, f);
312 void Paragraph::eraseIntern(lyx::pos_type pos)
314 pimpl_->eraseIntern(pos);
318 bool Paragraph::erase(pos_type pos)
320 return pimpl_->erase(pos);
324 int Paragraph::erase(pos_type start, pos_type end)
326 return pimpl_->erase(start, end);
330 bool Paragraph::checkInsertChar(LyXFont & font)
332 if (pimpl_->inset_owner)
333 return pimpl_->inset_owner->checkInsertChar(font);
338 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
340 LyXFont const f(LyXFont::ALL_INHERIT);
341 insertChar(pos, c, f);
345 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
346 LyXFont const & font, Change change)
348 pimpl_->insertChar(pos, c, font, change);
352 void Paragraph::insertInset(pos_type pos, Inset * inset)
354 LyXFont const f(LyXFont::ALL_INHERIT);
355 insertInset(pos, inset, f);
359 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
361 pimpl_->insertInset(pos, inset, font, change);
365 bool Paragraph::insetAllowed(Inset::Code code)
367 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
368 if (pimpl_->inset_owner)
369 return pimpl_->inset_owner->insetAllowed(code);
374 Inset * Paragraph::getInset(pos_type pos)
376 lyx::Assert(pos < size());
377 return insetlist.get(pos);
381 Inset const * Paragraph::getInset(pos_type pos) const
383 lyx::Assert(pos < size());
384 return insetlist.get(pos);
388 // Gets uninstantiated font setting at position.
389 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
392 lyx::Assert(pos <= size());
394 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
395 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
396 for (; cit != end; ++cit) {
397 if (cit->pos() >= pos)
403 retfont = cit->font();
404 else if (pos == size() && !empty())
405 retfont = getFontSettings(bparams, pos - 1);
407 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
413 // Gets uninstantiated font setting at position 0
414 LyXFont const Paragraph::getFirstFontSettings() const
416 if (!empty() && !pimpl_->fontlist.empty())
417 return pimpl_->fontlist[0].font();
419 return LyXFont(LyXFont::ALL_INHERIT);
423 // Gets the fully instantiated font at a given position in a paragraph
424 // This is basically the same function as LyXText::GetFont() in text2.C.
425 // The difference is that this one is used for generating the LaTeX file,
426 // and thus cosmetic "improvements" are disallowed: This has to deliver
427 // the true picture of the buffer. (Asger)
428 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
429 LyXFont const & outerfont) const
431 lyx::Assert(pos >= 0);
433 LyXLayout_ptr const & lout = layout();
435 pos_type const body_pos = beginningOfBody();
439 layoutfont = lout->labelfont;
441 layoutfont = lout->font;
443 LyXFont tmpfont = getFontSettings(bparams, pos);
444 tmpfont.realize(layoutfont);
445 tmpfont.realize(outerfont);
447 return realizeFont(tmpfont, bparams);
451 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
452 LyXFont const & outerfont) const
454 LyXLayout_ptr const & lout = layout();
456 LyXFont tmpfont = lout->labelfont;
457 tmpfont.setLanguage(getParLanguage(bparams));
458 tmpfont.realize(outerfont);
460 return realizeFont(tmpfont, bparams);
464 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
465 LyXFont const & outerfont) const
467 LyXLayout_ptr const & lout = layout();
469 LyXFont tmpfont = lout->font;
470 tmpfont.setLanguage(getParLanguage(bparams));
471 tmpfont.realize(outerfont);
473 return realizeFont(tmpfont, bparams);
477 /// Returns the height of the highest font in range
479 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
480 LyXFont::FONT_SIZE const def_size) const
482 if (pimpl_->fontlist.empty())
485 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
486 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
487 for (; end_it != end; ++end_it) {
488 if (end_it->pos() >= endpos)
495 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
496 for (; cit != end; ++cit) {
497 if (cit->pos() >= startpos)
501 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
502 for (; cit != end_it; ++cit) {
503 LyXFont::FONT_SIZE size = cit->font().size();
504 if (size == LyXFont::INHERIT_SIZE)
506 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
513 Paragraph::value_type
514 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
516 value_type c = getChar(pos);
517 if (!lyxrc.rtl_support)
547 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
554 void Paragraph::setFont(pos_type pos, LyXFont const & font)
556 lyx::Assert(pos <= size());
558 // First, reduce font against layout/label font
559 // Update: The SetCharFont() routine in text2.C already
560 // reduces font, so we don't need to do that here. (Asger)
561 // No need to simplify this because it will disappear
562 // in a new kernel. (Asger)
563 // Next search font table
565 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
566 Pimpl::FontList::iterator it = beg;
567 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
568 for (; it != endit; ++it) {
569 if (it->pos() >= pos)
572 unsigned int i = std::distance(beg, it);
573 bool notfound = (it == endit);
575 if (!notfound && pimpl_->fontlist[i].font() == font)
578 bool begin = pos == 0 || notfound ||
579 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
580 // Is position pos is a beginning of a font block?
581 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
582 // Is position pos is the end of a font block?
583 if (begin && end) { // A single char block
584 if (i + 1 < pimpl_->fontlist.size() &&
585 pimpl_->fontlist[i + 1].font() == font) {
586 // Merge the singleton block with the next block
587 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
588 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
589 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
590 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
591 // Merge the singleton block with the previous block
592 pimpl_->fontlist[i - 1].pos(pos);
593 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
595 pimpl_->fontlist[i].font(font);
597 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
598 pimpl_->fontlist[i - 1].pos(pos);
600 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
601 Pimpl::FontTable(pos, font));
603 pimpl_->fontlist[i].pos(pos - 1);
604 if (!(i + 1 < pimpl_->fontlist.size() &&
605 pimpl_->fontlist[i + 1].font() == font))
606 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
607 Pimpl::FontTable(pos, font));
608 } else { // The general case. The block is splitted into 3 blocks
609 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
610 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
611 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
612 Pimpl::FontTable(pos, font));
617 void Paragraph::makeSameLayout(Paragraph const & par)
619 layout(par.layout());
621 params() = par.params();
625 int Paragraph::stripLeadingSpaces()
631 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
632 pimpl_->eraseIntern(0);
640 bool Paragraph::hasSameLayout(Paragraph const & par) const
643 par.layout() == layout() &&
644 params().sameLayout(par.params());
648 Paragraph::depth_type Paragraph::getDepth() const
650 return params().depth();
654 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
656 if (layout()->isEnvironment())
657 return params().depth() + 1;
659 return params().depth();
663 char Paragraph::getAlign() const
665 return params().align();
669 string const & Paragraph::getLabelstring() const
671 return params().labelString();
675 // the next two functions are for the manual labels
676 string const Paragraph::getLabelWidthString() const
678 if (!params().labelWidthString().empty())
679 return params().labelWidthString();
681 return _("Senseless with this layout!");
685 void Paragraph::setLabelWidthString(string const & s)
687 params().labelWidthString(s);
691 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
694 params().labelWidthString(string());
695 params().align(LYX_ALIGN_LAYOUT);
696 params().spaceTop(VSpace(VSpace::NONE));
697 params().spaceBottom(VSpace(VSpace::NONE));
698 params().spacing(Spacing(Spacing::Default));
702 int Paragraph::beginningOfBody() const
704 if (layout()->labeltype != LABEL_MANUAL)
707 // Unroll the first two cycles of the loop
708 // and remember the previous character to
709 // remove unnecessary GetChar() calls
711 if (i < size() && !isNewline(i)) {
713 char previous_char = 0;
716 previous_char = getChar(i);
719 while (i < size() && previous_char != ' ') {
725 previous_char = temp;
735 // returns -1 if inset not found
736 int Paragraph::getPositionOfInset(Inset const * inset) const
739 InsetList::const_iterator it = insetlist.begin();
740 InsetList::const_iterator end = insetlist.end();
741 for (; it != end; ++it)
742 if (it->inset == inset)
748 InsetBibitem * Paragraph::bibitem() const
750 InsetList::const_iterator it = insetlist.begin();
751 if (it != insetlist.end() && it->inset->lyxCode() == Inset::BIBTEX_CODE)
752 return static_cast<InsetBibitem *>(it->inset);
758 // This could go to ParagraphParameters if we want to
759 int Paragraph::startTeXParParams(BufferParams const & bparams,
760 ostream & os, bool moving_arg) const
764 if (params().noindent()) {
769 switch (params().align()) {
771 case LYX_ALIGN_BLOCK:
772 case LYX_ALIGN_LAYOUT:
773 case LYX_ALIGN_SPECIAL:
776 case LYX_ALIGN_RIGHT:
777 case LYX_ALIGN_CENTER:
785 switch (params().align()) {
787 case LYX_ALIGN_BLOCK:
788 case LYX_ALIGN_LAYOUT:
789 case LYX_ALIGN_SPECIAL:
792 if (getParLanguage(bparams)->babel() != "hebrew") {
793 os << "\\begin{flushleft}";
796 os << "\\begin{flushright}";
800 case LYX_ALIGN_RIGHT:
801 if (getParLanguage(bparams)->babel() != "hebrew") {
802 os << "\\begin{flushright}";
805 os << "\\begin{flushleft}";
809 case LYX_ALIGN_CENTER:
810 os << "\\begin{center}";
819 // This could go to ParagraphParameters if we want to
820 int Paragraph::endTeXParParams(BufferParams const & bparams,
821 ostream & os, bool moving_arg) const
825 switch (params().align()) {
827 case LYX_ALIGN_BLOCK:
828 case LYX_ALIGN_LAYOUT:
829 case LYX_ALIGN_SPECIAL:
832 case LYX_ALIGN_RIGHT:
833 case LYX_ALIGN_CENTER:
841 switch (params().align()) {
843 case LYX_ALIGN_BLOCK:
844 case LYX_ALIGN_LAYOUT:
845 case LYX_ALIGN_SPECIAL:
848 if (getParLanguage(bparams)->babel() != "hebrew") {
849 os << "\\end{flushleft}";
852 os << "\\end{flushright}";
856 case LYX_ALIGN_RIGHT:
857 if (getParLanguage(bparams)->babel() != "hebrew") {
858 os << "\\end{flushright}";
861 os << "\\end{flushleft}";
865 case LYX_ALIGN_CENTER:
866 os << "\\end{center}";
874 // This one spits out the text of the paragraph
875 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
876 BufferParams const & bparams,
877 LyXFont const & outerfont,
878 ostream & os, TexRow & texrow,
879 LatexRunParams const & runparams)
881 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
883 bool return_value = false;
887 // well we have to check if we are in an inset with unlimited
888 // lenght (all in one row) if that is true then we don't allow
889 // any special options in the paragraph and also we don't allow
890 // any environment other then "Standard" to be valid!
892 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
895 style = bparams.getLyXTextClass().defaultLayout();
902 // Maybe we have to create a optional argument.
905 // FIXME: can we actually skip this check and just call
906 // beginningOfBody() ??
907 if (style->labeltype != LABEL_MANUAL) {
910 body_pos = beginningOfBody();
913 unsigned int column = 0;
918 basefont = getLabelFont(bparams, outerfont);
920 basefont = getLayoutFont(bparams, outerfont);
923 bool moving_arg = runparams.moving_arg;
924 moving_arg |= style->needprotect;
926 // Which font is currently active?
927 LyXFont running_font(basefont);
928 // Do we have an open font change?
929 bool open_font = false;
931 Change::Type running_change = Change::UNCHANGED;
933 texrow.start(id(), 0);
935 // if the paragraph is empty, the loop will not be entered at all
937 if (style->isCommand()) {
942 column += startTeXParParams(bparams, os, moving_arg);
946 for (pos_type i = 0; i < size(); ++i) {
948 // First char in paragraph or after label?
952 column += running_font.latexWriteEndChanges(os, basefont, basefont);
955 basefont = getLayoutFont(bparams, outerfont);
956 running_font = basefont;
960 if (style->isCommand()) {
966 column += startTeXParParams(bparams, os,
970 value_type c = getChar(i);
972 // Fully instantiated font
973 LyXFont font = getFont(bparams, i, outerfont);
975 LyXFont const last_font = running_font;
977 // Spaces at end of font change are simulated to be
978 // outside font change, i.e. we write "\textXX{text} "
979 // rather than "\textXX{text }". (Asger)
980 if (open_font && c == ' ' && i <= size() - 2) {
981 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
982 if (next_font != running_font
983 && next_font != font) {
988 // We end font definition before blanks
990 (font != running_font ||
991 font.language() != running_font.language()))
993 column += running_font.latexWriteEndChanges(os,
995 (i == body_pos-1) ? basefont : font);
996 running_font = basefont;
1000 // Blanks are printed before start of fontswitch
1002 // Do not print the separation of the optional argument
1003 if (i != body_pos - 1) {
1004 pimpl_->simpleTeXBlanks(os, texrow, i,
1005 column, font, *style);
1009 // Do we need to change font?
1010 if ((font != running_font ||
1011 font.language() != running_font.language()) &&
1014 column += font.latexWriteStartChanges(os, basefont,
1016 running_font = font;
1020 Change::Type change = pimpl_->lookupChange(i);
1022 column += Changes::latexMarkChange(os, running_change, change);
1023 running_change = change;
1025 LatexRunParams rp = runparams;
1026 rp.moving_arg = moving_arg;
1027 rp.free_spacing = style->free_spacing;
1028 pimpl_->simpleTeXSpecialChars(buf, bparams,
1029 os, texrow, runparams,
1031 basefont, outerfont, open_font,
1033 *style, i, column, c);
1036 column += Changes::latexMarkChange(os,
1037 running_change, Change::UNCHANGED);
1039 // If we have an open font definition, we have to close it
1041 #ifdef FIXED_LANGUAGE_END_DETECTION
1044 .latexWriteEndChanges(os, basefont,
1045 next_->getFont(bparams,
1048 running_font.latexWriteEndChanges(os, basefont,
1052 #ifdef WITH_WARNINGS
1053 //#warning For now we ALWAYS have to close the foreign font settings if they are
1054 //#warning there as we start another \selectlanguage with the next paragraph if
1055 //#warning we are in need of this. This should be fixed sometime (Jug)
1057 running_font.latexWriteEndChanges(os, basefont, basefont);
1061 // Needed if there is an optional argument but no contents.
1062 if (body_pos > 0 && body_pos == size()) {
1064 return_value = false;
1068 column += endTeXParParams(bparams, os, moving_arg);
1071 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1072 return return_value;
1078 bool Paragraph::isHfill(pos_type pos) const
1080 return IsInsetChar(getChar(pos))
1081 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1085 bool Paragraph::isInset(pos_type pos) const
1087 return IsInsetChar(getChar(pos));
1091 bool Paragraph::isNewline(pos_type pos) const
1093 return IsInsetChar(getChar(pos))
1094 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1098 bool Paragraph::isSeparator(pos_type pos) const
1100 return IsSeparatorChar(getChar(pos));
1104 bool Paragraph::isLineSeparator(pos_type pos) const
1106 value_type const c = getChar(pos);
1107 return IsLineSeparatorChar(c)
1108 || (IsInsetChar(c) && getInset(pos) &&
1109 getInset(pos)->isLineSeparator());
1113 bool Paragraph::isKomma(pos_type pos) const
1115 return IsKommaChar(getChar(pos));
1119 /// Used by the spellchecker
1120 bool Paragraph::isLetter(pos_type pos) const
1122 value_type const c = getChar(pos);
1123 if (IsLetterChar(c))
1126 return getInset(pos)->isLetter();
1127 // We want to pass the ' and escape chars to ispell
1128 string const extra = lyxrc.isp_esc_chars + '\'';
1129 return contains(extra, c);
1133 bool Paragraph::isWord(pos_type pos) const
1135 return IsWordChar(getChar(pos)) ;
1140 Paragraph::getParLanguage(BufferParams const & bparams) const
1143 return getFirstFontSettings().language();
1144 #warning FIXME we should check the prev par as well (Lgb)
1146 } else if (previous_) {
1147 return previous_->getParLanguage(bparams);
1150 return bparams.language;
1154 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1156 return lyxrc.rtl_support
1157 && getParLanguage(bparams)->RightToLeft()
1158 && !(inInset() && inInset()->owner() &&
1159 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1163 void Paragraph::changeLanguage(BufferParams const & bparams,
1164 Language const * from, Language const * to)
1166 for (pos_type i = 0; i < size(); ++i) {
1167 LyXFont font = getFontSettings(bparams, i);
1168 if (font.language() == from) {
1169 font.setLanguage(to);
1176 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1178 Language const * doc_language = bparams.language;
1179 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1180 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1182 for (; cit != end; ++cit)
1183 if (cit->font().language() != ignore_language &&
1184 cit->font().language() != latex_language &&
1185 cit->font().language() != doc_language)
1191 // Convert the paragraph to a string.
1192 // Used for building the table of contents
1193 string const Paragraph::asString(Buffer const * buffer, bool label) const
1196 if (label && !params().labelString().empty())
1197 s += params().labelString() + ' ';
1199 for (pos_type i = 0; i < size(); ++i) {
1200 value_type c = getChar(i);
1203 else if (c == META_INSET &&
1204 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1206 getInset(i)->ascii(buffer, ost);
1207 s += subst(STRCONV(ost.str()),'\n',' ');
1215 string const Paragraph::asString(Buffer const * buffer,
1216 pos_type beg, pos_type end, bool label) const
1220 if (beg == 0 && label && !params().labelString().empty())
1221 os << params().labelString() << ' ';
1223 for (pos_type i = beg; i < end; ++i) {
1224 value_type const c = getUChar(buffer->params, i);
1227 else if (c == META_INSET)
1228 getInset(i)->ascii(buffer, os);
1231 return STRCONV(os.str());
1235 void Paragraph::setInsetOwner(UpdatableInset * inset)
1237 pimpl_->inset_owner = inset;
1238 InsetList::iterator it = insetlist.begin();
1239 InsetList::iterator end = insetlist.end();
1240 for (; it != end; ++it)
1242 it->inset->setOwner(inset);
1246 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1249 insetlist.deleteInsetsLyXText(bv);
1253 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1256 insetlist.resizeInsetsLyXText(bv);
1260 void Paragraph::setContentsFromPar(Paragraph const & par)
1262 pimpl_->setContentsFromPar(par);
1266 void Paragraph::trackChanges(Change::Type type)
1268 pimpl_->trackChanges(type);
1272 void Paragraph::untrackChanges()
1274 pimpl_->untrackChanges();
1278 void Paragraph::cleanChanges()
1280 pimpl_->cleanChanges();
1284 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1286 lyx::Assert(!size() || pos < size());
1287 return pimpl_->lookupChange(pos);
1291 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1293 lyx::Assert(!size() || pos < size());
1294 return pimpl_->lookupChangeFull(pos);
1298 bool Paragraph::isChanged(pos_type start, pos_type end) const
1300 return pimpl_->isChanged(start, end);
1304 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1306 return pimpl_->isChangeEdited(start, end);
1310 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1312 pimpl_->setChange(pos, type);
1317 void Paragraph::markErased()
1319 pimpl_->markErased();
1323 void Paragraph::acceptChange(pos_type start, pos_type end)
1325 return pimpl_->acceptChange(start, end);
1329 void Paragraph::rejectChange(pos_type start, pos_type end)
1331 return pimpl_->rejectChange(start, end);
1335 lyx::pos_type Paragraph::size() const
1337 return pimpl_->size();
1341 bool Paragraph::empty() const
1343 return pimpl_->empty();
1347 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1349 return pimpl_->getChar(pos);
1353 int Paragraph::id() const
1359 void Paragraph::id(int i)
1365 LyXLayout_ptr const & Paragraph::layout() const
1368 Inset * inset = inInset();
1369 if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE)
1370 return static_cast<InsetEnvironment*>(inset)->layout();
1376 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1378 layout_ = new_layout;
1382 UpdatableInset * Paragraph::inInset() const
1384 return pimpl_->inset_owner;
1388 void Paragraph::clearContents()
1393 void Paragraph::setChar(pos_type pos, value_type c)
1395 pimpl_->setChar(pos, c);
1399 ParagraphParameters & Paragraph::params()
1401 return pimpl_->params;
1405 ParagraphParameters const & Paragraph::params() const
1407 return pimpl_->params;
1411 bool Paragraph::isFreeSpacing() const
1413 if (layout()->free_spacing)
1416 // for now we just need this, later should we need this in some
1417 // other way we can always add a function to Inset::() too.
1418 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1419 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
1424 bool Paragraph::allowEmpty() const
1426 if (layout()->keepempty)
1428 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1429 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
1434 bool operator==(Paragraph const & lhs, Paragraph const & rhs)
1436 #warning FIXME this implementatoin must be completely wrong...
1437 return &lhs == &rhs;