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 // If position is -1, we get the layout font of the paragraph.
437 // If position is -2, we get the font of the manual label of the paragraph.
438 LyXFont const Paragraph::getFont(BufferParams const & bparams,
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);
456 return pimpl_->realizeFont(tmpfont, bparams);
460 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
462 LyXLayout_ptr const & lout = layout();
464 LyXFont tmpfont = lout->labelfont;
465 tmpfont.setLanguage(getParLanguage(bparams));
467 return pimpl_->realizeFont(tmpfont, bparams);
471 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
473 LyXLayout_ptr const & lout = layout();
475 LyXFont tmpfont = lout->font;
476 tmpfont.setLanguage(getParLanguage(bparams));
478 return pimpl_->realizeFont(tmpfont, bparams);
482 /// Returns the height of the highest font in range
484 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
485 LyXFont::FONT_SIZE const def_size) const
487 if (pimpl_->fontlist.empty())
490 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
491 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
492 for (; end_it != end; ++end_it) {
493 if (end_it->pos() >= endpos)
500 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
501 for (; cit != end; ++cit) {
502 if (cit->pos() >= startpos)
506 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
507 for (; cit != end_it; ++cit) {
508 LyXFont::FONT_SIZE size = cit->font().size();
509 if (size == LyXFont::INHERIT_SIZE)
511 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
518 Paragraph::value_type
519 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
521 value_type c = getChar(pos);
522 if (!lyxrc.rtl_support)
552 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
559 void Paragraph::setFont(pos_type pos, LyXFont const & font)
561 lyx::Assert(pos <= size());
563 // First, reduce font against layout/label font
564 // Update: The SetCharFont() routine in text2.C already
565 // reduces font, so we don't need to do that here. (Asger)
566 // No need to simplify this because it will disappear
567 // in a new kernel. (Asger)
568 // Next search font table
570 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
571 Pimpl::FontList::iterator it = beg;
572 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
573 for (; it != endit; ++it) {
574 if (it->pos() >= pos)
577 unsigned int i = std::distance(beg, it);
578 bool notfound = (it == endit);
580 if (!notfound && pimpl_->fontlist[i].font() == font)
583 bool begin = pos == 0 || notfound ||
584 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
585 // Is position pos is a beginning of a font block?
586 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
587 // Is position pos is the end of a font block?
588 if (begin && end) { // A single char block
589 if (i + 1 < pimpl_->fontlist.size() &&
590 pimpl_->fontlist[i + 1].font() == font) {
591 // Merge the singleton block with the next block
592 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
593 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
594 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
595 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
596 // Merge the singleton block with the previous block
597 pimpl_->fontlist[i - 1].pos(pos);
598 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
600 pimpl_->fontlist[i].font(font);
602 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
603 pimpl_->fontlist[i - 1].pos(pos);
605 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
606 Pimpl::FontTable(pos, font));
608 pimpl_->fontlist[i].pos(pos - 1);
609 if (!(i + 1 < pimpl_->fontlist.size() &&
610 pimpl_->fontlist[i + 1].font() == font))
611 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
612 Pimpl::FontTable(pos, font));
613 } else { // The general case. The block is splitted into 3 blocks
614 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
615 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
616 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
617 Pimpl::FontTable(pos, font));
623 void Paragraph::next(Paragraph * p)
629 // This function is able to hide closed footnotes.
630 Paragraph * Paragraph::next()
636 Paragraph const * Paragraph::next() const
642 void Paragraph::previous(Paragraph * p)
648 // This function is able to hide closed footnotes.
649 Paragraph * Paragraph::previous()
655 // This function is able to hide closed footnotes.
656 Paragraph const * Paragraph::previous() const
663 void Paragraph::makeSameLayout(Paragraph const * par)
665 layout(par->layout());
667 params() = par->params();
671 int Paragraph::stripLeadingSpaces()
673 if (layout()->free_spacing || isFreeSpacing())
677 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
678 pimpl_->eraseIntern(0);
686 bool Paragraph::hasSameLayout(Paragraph const * par) const
689 par->layout() == layout() &&
690 params().sameLayout(par->params());
694 int Paragraph::getEndLabel() const
696 Paragraph const * par = this;
697 depth_type par_depth = getDepth();
699 LyXLayout_ptr const & layout = par->layout();
700 int const endlabeltype = layout->endlabeltype;
702 if (endlabeltype != END_LABEL_NO_LABEL) {
706 depth_type const next_depth = next_->getDepth();
707 if (par_depth > next_depth ||
708 (par_depth == next_depth
709 && layout != next_->layout()))
715 par = par->outerHook();
717 par_depth = par->getDepth();
719 return END_LABEL_NO_LABEL;
723 Paragraph::depth_type Paragraph::getDepth() const
725 return params().depth();
729 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
731 if (layout()->isEnvironment())
732 return params().depth() + 1;
734 return params().depth();
738 char Paragraph::getAlign() const
740 return params().align();
744 string const & Paragraph::getLabelstring() const
746 return params().labelString();
750 // the next two functions are for the manual labels
751 string const Paragraph::getLabelWidthString() const
753 if (!params().labelWidthString().empty())
754 return params().labelWidthString();
756 return _("Senseless with this layout!");
760 void Paragraph::setLabelWidthString(string const & s)
762 params().labelWidthString(s);
766 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
769 params().labelWidthString(string());
770 params().align(LYX_ALIGN_LAYOUT);
771 params().spaceTop(VSpace(VSpace::NONE));
772 params().spaceBottom(VSpace(VSpace::NONE));
773 params().spacing(Spacing(Spacing::Default));
777 int Paragraph::beginningOfBody() const
779 if (layout()->labeltype != LABEL_MANUAL)
782 // Unroll the first two cycles of the loop
783 // and remember the previous character to
784 // remove unnecessary GetChar() calls
786 if (i < size() && !isNewline(i)) {
788 char previous_char = 0;
791 previous_char = getChar(i);
794 while (i < size() && previous_char != ' ') {
800 previous_char = temp;
810 Paragraph * Paragraph::depthHook(depth_type depth)
812 Paragraph * newpar = this;
815 newpar = newpar->previous();
816 } while (newpar && newpar->getDepth() > depth);
819 if (previous() || getDepth())
820 lyxerr << "ERROR (Paragraph::DepthHook): "
829 Paragraph const * Paragraph::depthHook(depth_type depth) const
831 Paragraph const * newpar = this;
834 newpar = newpar->previous();
835 } while (newpar && newpar->getDepth() > depth);
838 if (previous() || getDepth())
839 lyxerr << "ERROR (Paragraph::DepthHook): "
848 Paragraph * Paragraph::outerHook()
852 return depthHook(depth_type(getDepth() - 1));
856 Paragraph const * Paragraph::outerHook() const
860 return depthHook(depth_type(getDepth() - 1));
864 // returns -1 if inset not found
865 int Paragraph::getPositionOfInset(Inset const * inset) const
868 InsetList::iterator it = insetlist.begin();
869 InsetList::iterator end = insetlist.end();
870 for (; it != end; ++it)
871 if (it.getInset() == inset)
877 InsetBibitem * Paragraph::bibitem()
879 InsetList::iterator it = insetlist.begin();
880 if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
881 return static_cast<InsetBibitem *>(it.getInset());
887 // This could go to ParagraphParameters if we want to
888 int Paragraph::startTeXParParams(BufferParams const & bparams,
889 ostream & os, bool moving_arg) const
893 if (params().noindent()) {
898 switch (params().align()) {
900 case LYX_ALIGN_BLOCK:
901 case LYX_ALIGN_LAYOUT:
902 case LYX_ALIGN_SPECIAL:
905 case LYX_ALIGN_RIGHT:
906 case LYX_ALIGN_CENTER:
914 switch (params().align()) {
916 case LYX_ALIGN_BLOCK:
917 case LYX_ALIGN_LAYOUT:
918 case LYX_ALIGN_SPECIAL:
921 if (getParLanguage(bparams)->babel() != "hebrew") {
922 os << "\\begin{flushleft}";
925 os << "\\begin{flushright}";
929 case LYX_ALIGN_RIGHT:
930 if (getParLanguage(bparams)->babel() != "hebrew") {
931 os << "\\begin{flushright}";
934 os << "\\begin{flushleft}";
938 case LYX_ALIGN_CENTER:
939 os << "\\begin{center}";
948 // This could go to ParagraphParameters if we want to
949 int Paragraph::endTeXParParams(BufferParams const & bparams,
950 ostream & os, bool moving_arg) const
954 switch (params().align()) {
956 case LYX_ALIGN_BLOCK:
957 case LYX_ALIGN_LAYOUT:
958 case LYX_ALIGN_SPECIAL:
961 case LYX_ALIGN_RIGHT:
962 case LYX_ALIGN_CENTER:
970 switch (params().align()) {
972 case LYX_ALIGN_BLOCK:
973 case LYX_ALIGN_LAYOUT:
974 case LYX_ALIGN_SPECIAL:
977 if (getParLanguage(bparams)->babel() != "hebrew") {
978 os << "\\end{flushleft}";
981 os << "\\end{flushright}";
985 case LYX_ALIGN_RIGHT:
986 if (getParLanguage(bparams)->babel() != "hebrew") {
987 os << "\\end{flushright}";
990 os << "\\end{flushleft}";
994 case LYX_ALIGN_CENTER:
995 os << "\\end{center}";
1003 // This one spits out the text of the paragraph
1004 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
1005 BufferParams const & bparams,
1006 ostream & os, TexRow & texrow,
1009 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
1011 bool return_value = false;
1013 LyXLayout_ptr style;
1015 // well we have to check if we are in an inset with unlimited
1016 // lenght (all in one row) if that is true then we don't allow
1017 // any special options in the paragraph and also we don't allow
1018 // any environment other then "Standard" to be valid!
1020 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
1023 style = bparams.getLyXTextClass().defaultLayout();
1030 // Maybe we have to create a optional argument.
1033 // FIXME: can we actually skip this check and just call
1034 // beginningOfBody() ??
1035 if (style->labeltype != LABEL_MANUAL) {
1038 body_pos = beginningOfBody();
1041 unsigned int column = 0;
1046 basefont = getLabelFont(bparams);
1048 basefont = getLayoutFont(bparams);
1051 moving_arg |= style->needprotect;
1053 // Which font is currently active?
1054 LyXFont running_font(basefont);
1055 // Do we have an open font change?
1056 bool open_font = false;
1058 Change::Type running_change = Change::UNCHANGED;
1060 texrow.start(this, 0);
1062 // if the paragraph is empty, the loop will not be entered at all
1064 if (style->isCommand()) {
1069 column += startTeXParParams(bparams, os, moving_arg);
1073 for (pos_type i = 0; i < size(); ++i) {
1075 // First char in paragraph or after label?
1076 if (i == body_pos) {
1079 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1082 basefont = getLayoutFont(bparams);
1083 running_font = basefont;
1087 if (style->isCommand()) {
1093 column += startTeXParParams(bparams, os,
1097 value_type c = getChar(i);
1099 // Fully instantiated font
1100 LyXFont font = getFont(bparams, i);
1102 LyXFont const last_font = running_font;
1104 // Spaces at end of font change are simulated to be
1105 // outside font change, i.e. we write "\textXX{text} "
1106 // rather than "\textXX{text }". (Asger)
1107 if (open_font && c == ' ' && i <= size() - 2) {
1108 LyXFont const & next_font = getFont(bparams, i + 1);
1109 if (next_font != running_font
1110 && next_font != font) {
1115 // We end font definition before blanks
1117 (font != running_font ||
1118 font.language() != running_font.language()))
1120 column += running_font.latexWriteEndChanges(os,
1122 (i == body_pos-1) ? basefont : font);
1123 running_font = basefont;
1127 // Blanks are printed before start of fontswitch
1129 // Do not print the separation of the optional argument
1130 if (i != body_pos - 1) {
1131 pimpl_->simpleTeXBlanks(os, texrow, i,
1132 column, font, *style);
1136 // Do we need to change font?
1137 if ((font != running_font ||
1138 font.language() != running_font.language()) &&
1141 column += font.latexWriteStartChanges(os, basefont,
1143 running_font = font;
1147 Change::Type change = pimpl_->lookupChange(i);
1149 column += Changes::latexMarkChange(os, running_change, change);
1150 running_change = change;
1152 pimpl_->simpleTeXSpecialChars(buf, bparams,
1153 os, texrow, moving_arg,
1155 basefont, open_font,
1157 *style, i, column, c);
1160 column += Changes::latexMarkChange(os,
1161 running_change, Change::UNCHANGED);
1163 // If we have an open font definition, we have to close it
1165 #ifdef FIXED_LANGUAGE_END_DETECTION
1168 .latexWriteEndChanges(os, basefont,
1169 next_->getFont(bparams,
1172 running_font.latexWriteEndChanges(os, basefont,
1176 #ifdef WITH_WARNINGS
1177 //#warning For now we ALWAYS have to close the foreign font settings if they are
1178 //#warning there as we start another \selectlanguage with the next paragraph if
1179 //#warning we are in need of this. This should be fixed sometime (Jug)
1181 running_font.latexWriteEndChanges(os, basefont, basefont);
1185 // Needed if there is an optional argument but no contents.
1186 if (body_pos > 0 && body_pos == size()) {
1188 return_value = false;
1192 column += endTeXParParams(bparams, os, moving_arg);
1195 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1196 return return_value;
1202 bool Paragraph::isHfill(pos_type pos) const
1204 return IsInsetChar(getChar(pos))
1205 && getInset(pos)->lyxCode() == Inset::HFILL_CODE;
1209 bool Paragraph::isInset(pos_type pos) const
1211 return IsInsetChar(getChar(pos));
1215 bool Paragraph::isNewline(pos_type pos) const
1217 return IsInsetChar(getChar(pos))
1218 && getInset(pos)->lyxCode() == Inset::NEWLINE_CODE;
1222 bool Paragraph::isSeparator(pos_type pos) const
1224 return IsSeparatorChar(getChar(pos));
1228 bool Paragraph::isLineSeparator(pos_type pos) const
1230 value_type const c = getChar(pos);
1231 return IsLineSeparatorChar(c)
1232 || (IsInsetChar(c) && getInset(pos) &&
1233 getInset(pos)->isLineSeparator());
1237 bool Paragraph::isKomma(pos_type pos) const
1239 return IsKommaChar(getChar(pos));
1243 /// Used by the spellchecker
1244 bool Paragraph::isLetter(pos_type pos) const
1246 value_type const c = getChar(pos);
1247 if (IsLetterChar(c))
1250 return getInset(pos)->isLetter();
1251 // We want to pass the ' and escape chars to ispell
1252 string const extra = lyxrc.isp_esc_chars + '\'';
1253 return contains(extra, c);
1257 bool Paragraph::isWord(pos_type pos) const
1259 return IsWordChar(getChar(pos)) ;
1264 Paragraph::getParLanguage(BufferParams const & bparams) const
1267 return getFirstFontSettings().language();
1268 } else if (previous_)
1269 return previous_->getParLanguage(bparams);
1271 return bparams.language;
1275 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1277 return lyxrc.rtl_support
1278 && getParLanguage(bparams)->RightToLeft()
1279 && !(inInset() && inInset()->owner() &&
1280 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
1284 void Paragraph::changeLanguage(BufferParams const & bparams,
1285 Language const * from, Language const * to)
1287 for (pos_type i = 0; i < size(); ++i) {
1288 LyXFont font = getFontSettings(bparams, i);
1289 if (font.language() == from) {
1290 font.setLanguage(to);
1297 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1299 Language const * doc_language = bparams.language;
1300 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1301 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1303 for (; cit != end; ++cit)
1304 if (cit->font().language() != ignore_language &&
1305 cit->font().language() != latex_language &&
1306 cit->font().language() != doc_language)
1312 // Convert the paragraph to a string.
1313 // Used for building the table of contents
1314 string const Paragraph::asString(Buffer const * buffer, bool label) const
1317 if (label && !params().labelString().empty())
1318 s += params().labelString() + ' ';
1320 for (pos_type i = 0; i < size(); ++i) {
1321 value_type c = getChar(i);
1324 else if (c == META_INSET &&
1325 getInset(i)->lyxCode() == Inset::MATH_CODE) {
1327 getInset(i)->ascii(buffer, ost);
1328 s += subst(STRCONV(ost.str()),'\n',' ');
1336 string const Paragraph::asString(Buffer const * buffer,
1337 pos_type beg, pos_type end, bool label) const
1341 if (beg == 0 && label && !params().labelString().empty())
1342 os << params().labelString() << ' ';
1344 for (pos_type i = beg; i < end; ++i) {
1345 value_type const c = getUChar(buffer->params, i);
1348 else if (c == META_INSET)
1349 getInset(i)->ascii(buffer, os);
1352 return STRCONV(os.str());
1356 void Paragraph::setInsetOwner(Inset * i)
1358 pimpl_->inset_owner = i;
1359 InsetList::iterator it = insetlist.begin();
1360 InsetList::iterator end = insetlist.end();
1361 for (; it != end; ++it)
1363 it.getInset()->setOwner(i);
1367 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1370 insetlist.deleteInsetsLyXText(bv);
1374 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1377 insetlist.resizeInsetsLyXText(bv);
1381 void Paragraph::setContentsFromPar(Paragraph * par)
1383 pimpl_->setContentsFromPar(par);
1387 void Paragraph::trackChanges(Change::Type type)
1389 pimpl_->trackChanges(type);
1393 void Paragraph::untrackChanges()
1395 pimpl_->untrackChanges();
1399 void Paragraph::cleanChanges()
1401 pimpl_->cleanChanges();
1405 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1407 lyx::Assert(!size() || pos < size());
1408 return pimpl_->lookupChange(pos);
1412 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1414 lyx::Assert(!size() || pos < size());
1415 return pimpl_->lookupChangeFull(pos);
1419 bool Paragraph::isChanged(pos_type start, pos_type end) const
1421 return pimpl_->isChanged(start, end);
1425 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1427 return pimpl_->isChangeEdited(start, end);
1431 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1433 pimpl_->setChange(pos, type);
1438 void Paragraph::markErased()
1440 pimpl_->markErased();
1444 void Paragraph::acceptChange(pos_type start, pos_type end)
1446 return pimpl_->acceptChange(start, end);
1450 void Paragraph::rejectChange(pos_type start, pos_type end)
1452 return pimpl_->rejectChange(start, end);
1456 lyx::pos_type Paragraph::size() const
1458 return pimpl_->size();
1462 bool Paragraph::empty() const
1464 return pimpl_->empty();
1468 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1470 return pimpl_->getChar(pos);
1474 int Paragraph::id() const
1480 LyXLayout_ptr const & Paragraph::layout() const
1486 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1488 layout_ = new_layout;
1492 bool Paragraph::isFirstInSequence() const
1494 Paragraph const * dhook = depthHook(getDepth());
1495 return (dhook == this
1496 || dhook->layout() != layout()
1497 || dhook->getDepth() != getDepth());
1501 Inset * Paragraph::inInset() const
1503 return pimpl_->inset_owner;
1507 void Paragraph::clearContents()
1512 void Paragraph::setChar(pos_type pos, value_type c)
1514 pimpl_->setChar(pos, c);
1518 ParagraphParameters & Paragraph::params()
1520 return pimpl_->params;
1524 ParagraphParameters const & Paragraph::params() const
1526 return pimpl_->params;
1530 bool Paragraph::isFreeSpacing() const
1532 // for now we just need this, later should we need this in some
1533 // other way we can always add a function to Inset::() too.
1534 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1535 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);