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"
28 #include "insets/insetbibitem.h"
29 #include "insets/insetoptarg.h"
31 #include "support/filetools.h"
32 #include "support/lstrings.h"
33 #include "support/lyxmanip.h"
34 #include "support/FileInfo.h"
35 #include "support/LAssert.h"
36 #include "support/textutils.h"
47 using std::lower_bound;
48 using std::upper_bound;
53 // this is a minibuffer
58 LyXFont minibuffer_font;
59 Inset * minibuffer_inset;
64 extern BufferView * current_view;
67 Paragraph::Paragraph()
68 : pimpl_(new Paragraph::Pimpl(this))
81 // This constructor inserts the new paragraph in a list.
82 // It is placed after par.
83 Paragraph::Paragraph(Paragraph * par)
84 : pimpl_(new Paragraph::Pimpl(this))
89 // double linked list begin
92 next_->previous_ = this;
94 previous_->next_ = this;
102 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
103 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
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.setInset(it.getInset()->clone(*current_view->buffer(),
122 // tell the new inset who is the boss now
123 it.getInset()->parOwner(this);
128 // the destructor removes the new paragraph from the list
129 Paragraph::~Paragraph()
133 previous_->next_ = next_;
135 next_->previous_ = previous_;
140 //lyxerr << "Paragraph::paragraph_id = "
141 // << Paragraph::paragraph_id << endl;
145 void Paragraph::write(Buffer const * buf, ostream & os,
146 BufferParams const & bparams,
147 depth_type & dth) const
149 // The beginning or end of a deeper (i.e. nested) area?
150 if (dth != params().depth()) {
151 if (params().depth() > dth) {
152 while (params().depth() > dth) {
153 os << "\n\\begin_deeper ";
157 while (params().depth() < dth) {
158 os << "\n\\end_deeper ";
164 // First write the layout
165 os << "\n\\layout " << layout()->name() << '\n';
169 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
171 Change running_change = Change(Change::UNCHANGED);
172 lyx::time_type const curtime(lyx::current_time());
175 for (pos_type i = 0; i < size(); ++i) {
181 Change change = pimpl_->lookupChangeFull(i);
182 Changes::lyxMarkChange(os, column, curtime, running_change, change);
183 running_change = change;
185 // Write font changes
186 LyXFont font2 = getFontSettings(bparams, i);
187 if (font2 != font1) {
188 font2.lyxWriteChanges(font1, os);
193 value_type const c = getChar(i);
197 Inset const * inset = getInset(i);
199 if (inset->directWrite()) {
200 // international char, let it write
201 // code directly so it's shorter in
203 inset->write(buf, os);
205 os << "\n\\begin_inset ";
206 inset->write(buf, os);
207 os << "\n\\end_inset \n\n";
213 os << "\n\\backslash \n";
217 if (i + 1 < size() && getChar(i + 1) == ' ') {
224 if ((column > 70 && c == ' ')
229 // this check is to amend a bug. LyX sometimes
230 // inserts '\0' this could cause problems.
234 lyxerr << "ERROR (Paragraph::writeFile):"
235 " NULL char in structure." << endl;
241 // to make reading work properly
243 running_change = pimpl_->lookupChange(0);
244 Changes::lyxMarkChange(os, column, curtime,
245 Change(Change::UNCHANGED), running_change);
247 Changes::lyxMarkChange(os, column, curtime,
248 running_change, Change(Change::UNCHANGED));
252 void Paragraph::validate(LaTeXFeatures & features) const
254 pimpl_->validate(features, *layout());
258 // First few functions needed for cut and paste and paragraph breaking.
259 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
261 BufferParams bparams = buffer.params;
263 minibuffer_char = getChar(pos);
264 minibuffer_font = getFontSettings(bparams, pos);
265 minibuffer_inset = 0;
266 if (minibuffer_char == Paragraph::META_INSET) {
268 minibuffer_inset = getInset(pos)->clone(buffer);
270 minibuffer_inset = 0;
271 minibuffer_char = ' ';
272 // This reflects what GetInset() does (ARRae)
278 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
280 minibuffer_char = getChar(pos);
281 minibuffer_font = getFontSettings(bparams, pos);
282 minibuffer_inset = 0;
283 if (minibuffer_char == Paragraph::META_INSET) {
285 // the inset is not in a paragraph anymore
286 minibuffer_inset = insetlist.release(pos);
287 minibuffer_inset->parOwner(0);
289 minibuffer_inset = 0;
290 minibuffer_char = ' ';
291 // This reflects what GetInset() does (ARRae)
296 // Erase(pos); now the caller is responsible for that.
300 bool Paragraph::insertFromMinibuffer(pos_type pos)
302 if (minibuffer_char == Paragraph::META_INSET) {
303 if (!insetAllowed(minibuffer_inset->lyxCode())) {
306 insertInset(pos, minibuffer_inset, minibuffer_font);
308 LyXFont f = minibuffer_font;
309 if (!checkInsertChar(f)) {
312 insertChar(pos, minibuffer_char, f);
320 void Paragraph::eraseIntern(lyx::pos_type pos)
322 pimpl_->eraseIntern(pos);
326 void Paragraph::erase(pos_type pos)
332 bool Paragraph::erase(pos_type start, pos_type end)
334 return pimpl_->erase(start, end);
338 bool Paragraph::checkInsertChar(LyXFont & font)
340 if (pimpl_->inset_owner)
341 return pimpl_->inset_owner->checkInsertChar(font);
346 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
348 LyXFont const f(LyXFont::ALL_INHERIT);
349 insertChar(pos, c, f);
353 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
354 LyXFont const & font, Change change)
356 pimpl_->insertChar(pos, c, font, change);
360 void Paragraph::insertInset(pos_type pos, Inset * inset)
362 LyXFont const f(LyXFont::ALL_INHERIT);
363 insertInset(pos, inset, f);
367 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font, Change change)
369 pimpl_->insertInset(pos, inset, font, change);
373 bool Paragraph::insetAllowed(Inset::Code code)
375 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
376 if (pimpl_->inset_owner)
377 return pimpl_->inset_owner->insetAllowed(code);
382 Inset * Paragraph::getInset(pos_type pos)
384 lyx::Assert(pos < size());
385 return insetlist.get(pos);
389 Inset const * Paragraph::getInset(pos_type pos) const
391 lyx::Assert(pos < size());
392 return insetlist.get(pos);
396 // Gets uninstantiated font setting at position.
397 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
400 lyx::Assert(pos <= size());
402 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
403 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
404 for (; cit != end; ++cit) {
405 if (cit->pos() >= pos)
411 retfont = cit->font();
412 else if (pos == size() && !empty())
413 retfont = getFontSettings(bparams, pos - 1);
415 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
421 // Gets uninstantiated font setting at position 0
422 LyXFont const Paragraph::getFirstFontSettings() const
424 if (!empty() && !pimpl_->fontlist.empty())
425 return pimpl_->fontlist[0].font();
427 return LyXFont(LyXFont::ALL_INHERIT);
431 // Gets the fully instantiated font at a given position in a paragraph
432 // This is basically the same function as LyXText::GetFont() in text2.C.
433 // The difference is that this one is used for generating the LaTeX file,
434 // and thus cosmetic "improvements" are disallowed: This has to deliver
435 // the true picture of the buffer. (Asger)
436 LyXFont const Paragraph::getFont(BufferParams const & bparams,
439 lyx::Assert(pos >= 0);
441 LyXLayout_ptr const & lout = layout();
443 pos_type const body_pos = beginningOfBody();
447 layoutfont = lout->labelfont;
449 layoutfont = lout->font;
451 LyXFont tmpfont = getFontSettings(bparams, pos);
452 tmpfont.realize(layoutfont);
454 return pimpl_->realizeFont(tmpfont, bparams);
458 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
460 LyXLayout_ptr const & lout = layout();
462 LyXFont tmpfont = lout->labelfont;
463 tmpfont.setLanguage(getParLanguage(bparams));
465 return pimpl_->realizeFont(tmpfont, bparams);
469 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
471 LyXLayout_ptr const & lout = layout();
473 LyXFont tmpfont = lout->font;
474 tmpfont.setLanguage(getParLanguage(bparams));
476 return pimpl_->realizeFont(tmpfont, bparams);
480 /// Returns the height of the highest font in range
482 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
483 LyXFont::FONT_SIZE const def_size) const
485 if (pimpl_->fontlist.empty())
488 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
489 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
490 for (; end_it != end; ++end_it) {
491 if (end_it->pos() >= endpos)
498 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
499 for (; cit != end; ++cit) {
500 if (cit->pos() >= startpos)
504 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
505 for (; cit != end_it; ++cit) {
506 LyXFont::FONT_SIZE size = cit->font().size();
507 if (size == LyXFont::INHERIT_SIZE)
509 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
516 Paragraph::value_type
517 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
519 value_type c = getChar(pos);
520 if (!lyxrc.rtl_support)
550 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
557 void Paragraph::setFont(pos_type pos, LyXFont const & font)
559 lyx::Assert(pos <= size());
561 // First, reduce font against layout/label font
562 // Update: The SetCharFont() routine in text2.C already
563 // reduces font, so we don't need to do that here. (Asger)
564 // No need to simplify this because it will disappear
565 // in a new kernel. (Asger)
566 // Next search font table
568 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
569 Pimpl::FontList::iterator it = beg;
570 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
571 for (; it != endit; ++it) {
572 if (it->pos() >= pos)
575 unsigned int i = std::distance(beg, it);
576 bool notfound = (it == endit);
578 if (!notfound && pimpl_->fontlist[i].font() == font)
581 bool begin = pos == 0 || notfound ||
582 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
583 // Is position pos is a beginning of a font block?
584 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
585 // Is position pos is the end of a font block?
586 if (begin && end) { // A single char block
587 if (i + 1 < pimpl_->fontlist.size() &&
588 pimpl_->fontlist[i + 1].font() == font) {
589 // Merge the singleton block with the next block
590 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
591 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
592 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
593 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
594 // Merge the singleton block with the previous block
595 pimpl_->fontlist[i - 1].pos(pos);
596 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
598 pimpl_->fontlist[i].font(font);
600 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
601 pimpl_->fontlist[i - 1].pos(pos);
603 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
604 Pimpl::FontTable(pos, font));
606 pimpl_->fontlist[i].pos(pos - 1);
607 if (!(i + 1 < pimpl_->fontlist.size() &&
608 pimpl_->fontlist[i + 1].font() == font))
609 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
610 Pimpl::FontTable(pos, font));
611 } else { // The general case. The block is splitted into 3 blocks
612 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
613 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
614 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
615 Pimpl::FontTable(pos, font));
621 void Paragraph::next(Paragraph * p)
627 // This function is able to hide closed footnotes.
628 Paragraph * Paragraph::next()
634 Paragraph const * Paragraph::next() const
640 void Paragraph::previous(Paragraph * p)
646 // This function is able to hide closed footnotes.
647 Paragraph * Paragraph::previous()
653 // This function is able to hide closed footnotes.
654 Paragraph const * Paragraph::previous() const
661 void Paragraph::makeSameLayout(Paragraph const * par)
663 layout(par->layout());
665 params() = par->params();
669 int Paragraph::stripLeadingSpaces()
671 if (layout()->free_spacing || isFreeSpacing())
675 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
676 pimpl_->eraseIntern(0);
684 bool Paragraph::hasSameLayout(Paragraph const * par) const
687 par->layout() == layout() &&
688 params().sameLayout(par->params());
692 int Paragraph::getEndLabel() const
694 Paragraph const * par = this;
695 depth_type par_depth = getDepth();
697 LyXLayout_ptr const & layout = par->layout();
698 int const endlabeltype = layout->endlabeltype;
700 if (endlabeltype != END_LABEL_NO_LABEL) {
704 depth_type const next_depth = next_->getDepth();
705 if (par_depth > next_depth ||
706 (par_depth == next_depth
707 && layout != next_->layout()))
713 par = par->outerHook();
715 par_depth = par->getDepth();
717 return END_LABEL_NO_LABEL;
721 Paragraph::depth_type Paragraph::getDepth() const
723 return params().depth();
727 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
729 if (layout()->isEnvironment())
730 return params().depth() + 1;
732 return params().depth();
736 char Paragraph::getAlign() const
738 return params().align();
742 string const & Paragraph::getLabelstring() const
744 return params().labelString();
748 // the next two functions are for the manual labels
749 string const Paragraph::getLabelWidthString() const
751 if (!params().labelWidthString().empty())
752 return params().labelWidthString();
754 return _("Senseless with this layout!");
758 void Paragraph::setLabelWidthString(string const & s)
760 params().labelWidthString(s);
764 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
767 params().labelWidthString(string());
768 params().align(LYX_ALIGN_LAYOUT);
769 params().spaceTop(VSpace(VSpace::NONE));
770 params().spaceBottom(VSpace(VSpace::NONE));
771 params().spacing(Spacing(Spacing::Default));
775 int Paragraph::beginningOfBody() const
777 if (layout()->labeltype != LABEL_MANUAL)
780 // Unroll the first two cycles of the loop
781 // and remember the previous character to
782 // remove unnecessary GetChar() calls
784 if (i < size() && !isNewline(i)) {
786 char previous_char = 0;
789 previous_char = getChar(i);
792 while (i < size() && previous_char != ' ') {
798 previous_char = temp;
808 Paragraph * Paragraph::depthHook(depth_type depth)
810 Paragraph * newpar = this;
813 newpar = newpar->previous();
814 } while (newpar && newpar->getDepth() > depth);
817 if (previous() || getDepth())
818 lyxerr << "ERROR (Paragraph::DepthHook): "
827 Paragraph const * Paragraph::depthHook(depth_type depth) const
829 Paragraph const * newpar = this;
832 newpar = newpar->previous();
833 } while (newpar && newpar->getDepth() > depth);
836 if (previous() || getDepth())
837 lyxerr << "ERROR (Paragraph::DepthHook): "
846 Paragraph * Paragraph::outerHook()
850 return depthHook(depth_type(getDepth() - 1));
854 Paragraph const * Paragraph::outerHook() const
858 return depthHook(depth_type(getDepth() - 1));
862 // returns -1 if inset not found
863 int Paragraph::getPositionOfInset(Inset const * inset) const
866 InsetList::iterator it = insetlist.begin();
867 InsetList::iterator end = insetlist.end();
868 for (; it != end; ++it)
869 if (it.getInset() == inset)
875 InsetBibitem * Paragraph::bibitem()
877 InsetList::iterator it = insetlist.begin();
878 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
879 return static_cast<InsetBibitem *>(it.getInset());
885 // This could go to ParagraphParameters if we want to
886 int Paragraph::startTeXParParams(BufferParams const & bparams,
887 ostream & os, bool moving_arg) const
891 if (params().noindent()) {
896 switch (params().align()) {
898 case LYX_ALIGN_BLOCK:
899 case LYX_ALIGN_LAYOUT:
900 case LYX_ALIGN_SPECIAL:
903 case LYX_ALIGN_RIGHT:
904 case LYX_ALIGN_CENTER:
912 switch (params().align()) {
914 case LYX_ALIGN_BLOCK:
915 case LYX_ALIGN_LAYOUT:
916 case LYX_ALIGN_SPECIAL:
919 if (getParLanguage(bparams)->babel() != "hebrew") {
920 os << "\\begin{flushleft}";
923 os << "\\begin{flushright}";
927 case LYX_ALIGN_RIGHT:
928 if (getParLanguage(bparams)->babel() != "hebrew") {
929 os << "\\begin{flushright}";
932 os << "\\begin{flushleft}";
936 case LYX_ALIGN_CENTER:
937 os << "\\begin{center}";
946 // This could go to ParagraphParameters if we want to
947 int Paragraph::endTeXParParams(BufferParams const & bparams,
948 ostream & os, bool moving_arg) const
952 switch (params().align()) {
954 case LYX_ALIGN_BLOCK:
955 case LYX_ALIGN_LAYOUT:
956 case LYX_ALIGN_SPECIAL:
959 case LYX_ALIGN_RIGHT:
960 case LYX_ALIGN_CENTER:
968 switch (params().align()) {
970 case LYX_ALIGN_BLOCK:
971 case LYX_ALIGN_LAYOUT:
972 case LYX_ALIGN_SPECIAL:
975 if (getParLanguage(bparams)->babel() != "hebrew") {
976 os << "\\end{flushleft}";
979 os << "\\end{flushright}";
983 case LYX_ALIGN_RIGHT:
984 if (getParLanguage(bparams)->babel() != "hebrew") {
985 os << "\\end{flushright}";
988 os << "\\end{flushleft}";
992 case LYX_ALIGN_CENTER:
993 os << "\\end{center}";
1001 // This one spits out the text of the paragraph
1002 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
1003 BufferParams const & bparams,
1004 ostream & os, TexRow & texrow,
1007 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
1009 bool return_value = false;
1011 LyXLayout_ptr style;
1013 // well we have to check if we are in an inset with unlimited
1014 // lenght (all in one row) if that is true then we don't allow
1015 // any special options in the paragraph and also we don't allow
1016 // any environment other then "Standard" to be valid!
1018 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
1021 style = bparams.getLyXTextClass().defaultLayout();
1028 // Maybe we have to create a optional argument.
1031 // FIXME: can we actually skip this check and just call
1032 // beginningOfBody() ??
1033 if (style->labeltype != LABEL_MANUAL) {
1036 body_pos = beginningOfBody();
1039 unsigned int column = 0;
1044 basefont = getLabelFont(bparams);
1046 basefont = getLayoutFont(bparams);
1049 moving_arg |= style->needprotect;
1051 // Which font is currently active?
1052 LyXFont running_font(basefont);
1053 // Do we have an open font change?
1054 bool open_font = false;
1056 Change::Type running_change = Change::UNCHANGED;
1058 texrow.start(this, 0);
1060 // if the paragraph is empty, the loop will not be entered at all
1062 if (style->isCommand()) {
1067 column += startTeXParParams(bparams, os, moving_arg);
1071 for (pos_type i = 0; i < size(); ++i) {
1073 // First char in paragraph or after label?
1074 if (i == body_pos) {
1077 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1080 basefont = getLayoutFont(bparams);
1081 running_font = basefont;
1085 if (style->isCommand()) {
1091 column += startTeXParParams(bparams, os,
1095 value_type c = getChar(i);
1097 // Fully instantiated font
1098 LyXFont font = getFont(bparams, i);
1100 LyXFont const last_font = running_font;
1102 // Spaces at end of font change are simulated to be
1103 // outside font change, i.e. we write "\textXX{text} "
1104 // rather than "\textXX{text }". (Asger)
1105 if (open_font && c == ' ' && i <= size() - 2) {
1106 LyXFont const & next_font = getFont(bparams, i + 1);
1107 if (next_font != running_font
1108 && next_font != font) {
1113 // We end font definition before blanks
1115 (font != running_font ||
1116 font.language() != running_font.language()))
1118 column += running_font.latexWriteEndChanges(os,
1120 (i == body_pos-1) ? basefont : font);
1121 running_font = basefont;
1125 // Blanks are printed before start of fontswitch
1127 // Do not print the separation of the optional argument
1128 if (i != body_pos - 1) {
1129 pimpl_->simpleTeXBlanks(os, texrow, i,
1130 column, font, *style);
1134 // Do we need to change font?
1135 if ((font != running_font ||
1136 font.language() != running_font.language()) &&
1139 column += font.latexWriteStartChanges(os, basefont,
1141 running_font = font;
1145 Change::Type change = pimpl_->lookupChange(i);
1147 column += Changes::latexMarkChange(os, running_change, change);
1148 running_change = change;
1150 pimpl_->simpleTeXSpecialChars(buf, bparams,
1151 os, texrow, moving_arg,
1153 basefont, open_font,
1155 *style, i, column, c);
1158 column += Changes::latexMarkChange(os,
1159 running_change, Change::UNCHANGED);
1161 // If we have an open font definition, we have to close it
1163 #ifdef FIXED_LANGUAGE_END_DETECTION
1166 .latexWriteEndChanges(os, basefont,
1167 next_->getFont(bparams,
1170 running_font.latexWriteEndChanges(os, basefont,
1174 #ifdef WITH_WARNINGS
1175 //#warning For now we ALWAYS have to close the foreign font settings if they are
1176 //#warning there as we start another \selectlanguage with the next paragraph if
1177 //#warning we are in need of this. This should be fixed sometime (Jug)
1179 running_font.latexWriteEndChanges(os, basefont, basefont);
1183 // Needed if there is an optional argument but no contents.
1184 if (body_pos > 0 && body_pos == size()) {
1186 return_value = false;
1190 column += endTeXParParams(bparams, os, moving_arg);
1193 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1194 return return_value;
1200 bool Paragraph::isHfill(pos_type pos) const
1202 return IsInsetChar(getChar(pos))
1203 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1207 bool Paragraph::isInset(pos_type pos) const
1209 return IsInsetChar(getChar(pos));
1213 bool Paragraph::isNewline(pos_type pos) const
1215 return IsInsetChar(getChar(pos))
1216 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1220 bool Paragraph::isSeparator(pos_type pos) const
1222 return IsSeparatorChar(getChar(pos));
1226 bool Paragraph::isLineSeparator(pos_type pos) const
1228 value_type const c = getChar(pos);
1229 return IsLineSeparatorChar(c)
1230 || (IsInsetChar(c) && getInset(pos) &&
1231 getInset(pos)->isLineSeparator());
1235 bool Paragraph::isKomma(pos_type pos) const
1237 return IsKommaChar(getChar(pos));
1241 /// Used by the spellchecker
1242 bool Paragraph::isLetter(pos_type pos) const
1244 value_type const c = getChar(pos);
1245 if (IsLetterChar(c))
1248 return getInset(pos)->isLetter();
1249 // We want to pass the ' and escape chars to ispell
1250 string const extra = lyxrc.isp_esc_chars + '\'';
1251 return contains(extra, c);
1255 bool Paragraph::isWord(pos_type pos) const
1257 return IsWordChar(getChar(pos)) ;
1262 Paragraph::getParLanguage(BufferParams const & bparams) const
1265 return getFirstFontSettings().language();
1266 } else if (previous_)
1267 return previous_->getParLanguage(bparams);
1269 return bparams.language;
1273 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1275 return lyxrc.rtl_support
1276 && getParLanguage(bparams)->RightToLeft()
1277 && !(inInset() && inInset()->owner() &&
1278 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1282 void Paragraph::changeLanguage(BufferParams const & bparams,
1283 Language const * from, Language const * to)
1285 for (pos_type i = 0; i < size(); ++i) {
1286 LyXFont font = getFontSettings(bparams, i);
1287 if (font.language() == from) {
1288 font.setLanguage(to);
1295 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1297 Language const * doc_language = bparams.language;
1298 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1299 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1301 for (; cit != end; ++cit)
1302 if (cit->font().language() != ignore_language &&
1303 cit->font().language() != latex_language &&
1304 cit->font().language() != doc_language)
1310 // Convert the paragraph to a string.
1311 // Used for building the table of contents
1312 string const Paragraph::asString(Buffer const * buffer, bool label) const
1315 if (label && !params().labelString().empty())
1316 s += params().labelString() + ' ';
1318 for (pos_type i = 0; i < size(); ++i) {
1319 value_type c = getChar(i);
1322 else if (c == META_INSET &&
1323 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1325 getInset(i)->ascii(buffer, ost);
1326 s += subst(STRCONV(ost.str()),'\n',' ');
1334 string const Paragraph::asString(Buffer const * buffer,
1335 pos_type beg, pos_type end, bool label) const
1339 if (beg == 0 && label && !params().labelString().empty())
1340 os << params().labelString() << ' ';
1342 for (pos_type i = beg; i < end; ++i) {
1343 value_type const c = getUChar(buffer->params, i);
1346 else if (c == META_INSET)
1347 getInset(i)->ascii(buffer, os);
1350 return STRCONV(os.str());
1354 void Paragraph::setInsetOwner(Inset * i)
1356 pimpl_->inset_owner = i;
1357 InsetList::iterator it = insetlist.begin();
1358 InsetList::iterator end = insetlist.end();
1359 for (; it != end; ++it)
1361 it.getInset()->setOwner(i);
1365 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1368 insetlist.deleteInsetsLyXText(bv);
1372 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1375 insetlist.resizeInsetsLyXText(bv);
1379 void Paragraph::setContentsFromPar(Paragraph * par)
1381 pimpl_->setContentsFromPar(par);
1385 void Paragraph::trackChanges(Change::Type type)
1387 pimpl_->trackChanges(type);
1391 void Paragraph::untrackChanges()
1393 pimpl_->untrackChanges();
1397 void Paragraph::cleanChanges()
1399 pimpl_->cleanChanges();
1403 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1405 lyx::Assert(!size() || pos < size());
1406 return pimpl_->lookupChange(pos);
1410 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1412 lyx::Assert(!size() || pos < size());
1413 return pimpl_->lookupChangeFull(pos);
1417 bool Paragraph::isChanged(pos_type start, pos_type end) const
1419 return pimpl_->isChanged(start, end);
1423 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1425 return pimpl_->isChangeEdited(start, end);
1429 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1431 pimpl_->setChange(pos, type);
1436 void Paragraph::markErased()
1438 pimpl_->markErased();
1442 void Paragraph::acceptChange(pos_type start, pos_type end)
1444 return pimpl_->acceptChange(start, end);
1448 void Paragraph::rejectChange(pos_type start, pos_type end)
1450 return pimpl_->rejectChange(start, end);
1454 lyx::pos_type Paragraph::size() const
1456 return pimpl_->size();
1460 bool Paragraph::empty() const
1462 return pimpl_->empty();
1466 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1468 return pimpl_->getChar(pos);
1472 int Paragraph::id() const
1478 LyXLayout_ptr const & Paragraph::layout() const
1484 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1486 layout_ = new_layout;
1490 bool Paragraph::isFirstInSequence() const
1492 Paragraph const * dhook = depthHook(getDepth());
1493 return (dhook == this
1494 || dhook->layout() != layout()
1495 || dhook->getDepth() != getDepth());
1499 Inset * Paragraph::inInset() const
1501 return pimpl_->inset_owner;
1505 void Paragraph::clearContents()
1510 void Paragraph::setChar(pos_type pos, value_type c)
1512 pimpl_->setChar(pos, c);
1516 ParagraphParameters & Paragraph::params()
1518 return pimpl_->params;
1522 ParagraphParameters const & Paragraph::params() const
1524 return pimpl_->params;
1528 bool Paragraph::isFreeSpacing() const
1530 // for now we just need this, later should we need this in some
1531 // other way we can always add a function to Inset::() too.
1532 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1533 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);