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"
49 using namespace lyx::support;
55 using std::lower_bound;
56 using std::upper_bound;
61 // this is a minibuffer
66 LyXFont minibuffer_font;
67 InsetOld * minibuffer_inset;
72 Paragraph::Paragraph()
73 : pimpl_(new Paragraph::Pimpl(this))
81 Paragraph::Paragraph(Paragraph const & lp)
82 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
86 // this is because of the dummy layout of the paragraphs that
88 layout_ = lp.layout();
90 // copy everything behind the break-position to the new paragraph
91 insetlist = lp.insetlist;
92 InsetList::iterator it = insetlist.begin();
93 InsetList::iterator end = insetlist.end();
94 for (; it != end; ++it) {
95 // currently we hold Inset*, not InsetBase*
96 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
97 // tell the new inset who is the boss now
98 it->inset->parOwner(this);
103 void Paragraph::operator=(Paragraph const & lp)
105 // needed as we will destroy the pimpl_ before copying it
108 lyxerr << "Paragraph::operator=()\n";
110 pimpl_ = new Pimpl(*lp.pimpl_, this);
112 enumdepth = lp.enumdepth;
113 itemdepth = lp.itemdepth;
114 // this is because of the dummy layout of the paragraphs that
116 layout_ = lp.layout();
118 // copy everything behind the break-position to the new paragraph
119 insetlist = lp.insetlist;
120 InsetList::iterator it = insetlist.begin();
121 InsetList::iterator end = insetlist.end();
122 for (; it != end; ++it) {
123 it->inset = static_cast<InsetOld*>(it->inset->clone().release());
124 // tell the new inset who is the boss now
125 it->inset->parOwner(this);
129 // the destructor removes the new paragraph from the list
130 Paragraph::~Paragraph()
134 //lyxerr << "Paragraph::paragraph_id = "
135 // << Paragraph::paragraph_id << endl;
139 void Paragraph::write(Buffer const * buf, ostream & os,
140 BufferParams const & bparams,
141 depth_type & dth) const
143 // The beginning or end of a deeper (i.e. nested) area?
144 if (dth != params().depth()) {
145 if (params().depth() > dth) {
146 while (params().depth() > dth) {
147 os << "\n\\begin_deeper ";
151 while (params().depth() < dth) {
152 os << "\n\\end_deeper ";
158 // First write the layout
159 os << "\n\\layout " << layout()->name() << '\n';
163 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
165 Change running_change = Change(Change::UNCHANGED);
166 lyx::time_type const curtime(lyx::current_time());
169 for (pos_type i = 0; i < size(); ++i) {
175 Change change = pimpl_->lookupChangeFull(i);
176 Changes::lyxMarkChange(os, column, curtime, running_change, change);
177 running_change = change;
179 // Write font changes
180 LyXFont font2 = getFontSettings(bparams, i);
181 if (font2 != font1) {
182 font2.lyxWriteChanges(font1, os);
187 value_type const c = getChar(i);
191 InsetOld const * inset = getInset(i);
193 if (inset->directWrite()) {
194 // international char, let it write
195 // code directly so it's shorter in
197 inset->write(buf, os);
199 os << "\n\\begin_inset ";
200 inset->write(buf, os);
201 os << "\n\\end_inset \n\n";
207 os << "\n\\backslash \n";
211 if (i + 1 < size() && getChar(i + 1) == ' ') {
218 if ((column > 70 && c == ' ')
223 // this check is to amend a bug. LyX sometimes
224 // inserts '\0' this could cause problems.
228 lyxerr << "ERROR (Paragraph::writeFile):"
229 " NULL char in structure." << endl;
235 // to make reading work properly
237 running_change = pimpl_->lookupChange(0);
238 Changes::lyxMarkChange(os, column, curtime,
239 Change(Change::UNCHANGED), running_change);
241 Changes::lyxMarkChange(os, column, curtime,
242 running_change, Change(Change::UNCHANGED));
244 os << "\n\\end_layout\n";
248 void Paragraph::validate(LaTeXFeatures & features) const
250 pimpl_->validate(features, *layout());
254 // First few functions needed for cut and paste and paragraph breaking.
255 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
257 BufferParams bparams = buffer.params;
259 minibuffer_char = getChar(pos);
260 minibuffer_font = getFontSettings(bparams, pos);
261 minibuffer_inset = 0;
262 if (minibuffer_char == Paragraph::META_INSET) {
264 minibuffer_inset = static_cast<InsetOld *>(getInset(pos)->clone().release());
266 minibuffer_inset = 0;
267 minibuffer_char = ' ';
268 // This reflects what GetInset() does (ARRae)
274 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
276 minibuffer_char = getChar(pos);
277 minibuffer_font = getFontSettings(bparams, pos);
278 minibuffer_inset = 0;
279 if (minibuffer_char == Paragraph::META_INSET) {
281 // the inset is not in a paragraph anymore
282 minibuffer_inset = insetlist.release(pos);
283 minibuffer_inset->parOwner(0);
285 minibuffer_inset = 0;
286 minibuffer_char = ' ';
287 // This reflects what GetInset() does (ARRae)
292 // Erase(pos); now the caller is responsible for that.
296 bool Paragraph::insertFromMinibuffer(pos_type pos)
298 if (minibuffer_char == Paragraph::META_INSET) {
299 if (!insetAllowed(minibuffer_inset->lyxCode())) {
302 insertInset(pos, minibuffer_inset, minibuffer_font);
304 LyXFont f = minibuffer_font;
305 if (!checkInsertChar(f)) {
308 insertChar(pos, minibuffer_char, f);
316 void Paragraph::eraseIntern(lyx::pos_type pos)
318 pimpl_->eraseIntern(pos);
322 bool Paragraph::erase(pos_type pos)
324 return pimpl_->erase(pos);
328 int Paragraph::erase(pos_type start, pos_type end)
330 return pimpl_->erase(start, end);
334 bool Paragraph::checkInsertChar(LyXFont & font)
336 if (pimpl_->inset_owner)
337 return pimpl_->inset_owner->checkInsertChar(font);
342 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
344 LyXFont const f(LyXFont::ALL_INHERIT);
345 insertChar(pos, c, f);
349 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
350 LyXFont const & font, Change change)
352 pimpl_->insertChar(pos, c, font, change);
356 void Paragraph::insertInset(pos_type pos, InsetOld * inset)
358 LyXFont const f(LyXFont::ALL_INHERIT);
359 insertInset(pos, inset, f);
363 void Paragraph::insertInset(pos_type pos, InsetOld * inset, LyXFont const & font, Change change)
365 pimpl_->insertInset(pos, inset, font, change);
369 bool Paragraph::insetAllowed(InsetOld::Code code)
371 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
372 if (pimpl_->inset_owner)
373 return pimpl_->inset_owner->insetAllowed(code);
378 InsetOld * Paragraph::getInset(pos_type pos)
380 Assert(pos < size());
381 return insetlist.get(pos);
385 InsetOld const * Paragraph::getInset(pos_type pos) const
387 Assert(pos < size());
388 return insetlist.get(pos);
392 // Gets uninstantiated font setting at position.
393 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
396 Assert(pos <= size());
398 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
399 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
400 for (; cit != end; ++cit) {
401 if (cit->pos() >= pos)
407 retfont = cit->font();
408 else if (pos == size() && !empty())
409 retfont = getFontSettings(bparams, pos - 1);
411 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
417 Paragraph::getEndPosOfFontSpan(lyx::pos_type pos) const
419 Assert(pos <= size());
421 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
422 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
423 for (; cit != end; ++cit) {
424 if (cit->pos() >= pos)
427 // This should not happen, but if so, we take no chances.
432 // Gets uninstantiated font setting at position 0
433 LyXFont const Paragraph::getFirstFontSettings() const
435 if (!empty() && !pimpl_->fontlist.empty())
436 return pimpl_->fontlist[0].font();
438 return LyXFont(LyXFont::ALL_INHERIT);
442 // Gets the fully instantiated font at a given position in a paragraph
443 // This is basically the same function as LyXText::GetFont() in text2.C.
444 // The difference is that this one is used for generating the LaTeX file,
445 // and thus cosmetic "improvements" are disallowed: This has to deliver
446 // the true picture of the buffer. (Asger)
447 LyXFont const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
448 LyXFont const & outerfont) const
452 LyXLayout_ptr const & lout = layout();
454 pos_type const body_pos = beginningOfBody();
458 layoutfont = lout->labelfont;
460 layoutfont = lout->font;
462 LyXFont tmpfont = getFontSettings(bparams, pos);
463 tmpfont.realize(layoutfont);
464 tmpfont.realize(outerfont);
465 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
471 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams,
472 LyXFont const & outerfont) const
474 LyXLayout_ptr const & lout = layout();
476 LyXFont tmpfont = lout->labelfont;
477 tmpfont.setLanguage(getParLanguage(bparams));
478 tmpfont.realize(outerfont);
479 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
485 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams,
486 LyXFont const & outerfont) const
488 LyXLayout_ptr const & lout = layout();
490 LyXFont tmpfont = lout->font;
491 tmpfont.setLanguage(getParLanguage(bparams));
492 tmpfont.realize(outerfont);
493 tmpfont.realize(bparams.getLyXTextClass().defaultfont());
499 /// Returns the height of the highest font in range
501 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
502 LyXFont::FONT_SIZE const def_size) const
504 if (pimpl_->fontlist.empty())
507 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
508 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
509 for (; end_it != end; ++end_it) {
510 if (end_it->pos() >= endpos)
517 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
518 for (; cit != end; ++cit) {
519 if (cit->pos() >= startpos)
523 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
524 for (; cit != end_it; ++cit) {
525 LyXFont::FONT_SIZE size = cit->font().size();
526 if (size == LyXFont::INHERIT_SIZE)
528 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
535 Paragraph::value_type
536 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
538 value_type c = getChar(pos);
539 if (!lyxrc.rtl_support)
569 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
576 void Paragraph::setFont(pos_type pos, LyXFont const & font)
578 Assert(pos <= size());
580 // First, reduce font against layout/label font
581 // Update: The SetCharFont() routine in text2.C already
582 // reduces font, so we don't need to do that here. (Asger)
583 // No need to simplify this because it will disappear
584 // in a new kernel. (Asger)
585 // Next search font table
587 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
588 Pimpl::FontList::iterator it = beg;
589 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
590 for (; it != endit; ++it) {
591 if (it->pos() >= pos)
594 unsigned int i = std::distance(beg, it);
595 bool notfound = (it == endit);
597 if (!notfound && pimpl_->fontlist[i].font() == font)
600 bool begin = pos == 0 || notfound ||
601 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
602 // Is position pos is a beginning of a font block?
603 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
604 // Is position pos is the end of a font block?
605 if (begin && end) { // A single char block
606 if (i + 1 < pimpl_->fontlist.size() &&
607 pimpl_->fontlist[i + 1].font() == font) {
608 // Merge the singleton block with the next block
609 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
610 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
611 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i - 1);
612 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
613 // Merge the singleton block with the previous block
614 pimpl_->fontlist[i - 1].pos(pos);
615 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
617 pimpl_->fontlist[i].font(font);
619 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
620 pimpl_->fontlist[i - 1].pos(pos);
622 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
623 Pimpl::FontTable(pos, font));
625 pimpl_->fontlist[i].pos(pos - 1);
626 if (!(i + 1 < pimpl_->fontlist.size() &&
627 pimpl_->fontlist[i + 1].font() == font))
628 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
629 Pimpl::FontTable(pos, font));
630 } else { // The general case. The block is splitted into 3 blocks
631 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
632 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
633 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
634 Pimpl::FontTable(pos, font));
639 void Paragraph::makeSameLayout(Paragraph const & par)
641 layout(par.layout());
643 params() = par.params();
647 int Paragraph::stripLeadingSpaces()
653 while (!empty() && (isNewline(0) || isLineSeparator(0))) {
654 pimpl_->eraseIntern(0);
662 bool Paragraph::hasSameLayout(Paragraph const & par) const
665 par.layout() == layout() &&
666 params().sameLayout(par.params());
670 Paragraph::depth_type Paragraph::getDepth() const
672 return params().depth();
676 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
678 if (layout()->isEnvironment())
679 return params().depth() + 1;
681 return params().depth();
685 char Paragraph::getAlign() const
687 return params().align();
691 string const & Paragraph::getLabelstring() const
693 return params().labelString();
697 // the next two functions are for the manual labels
698 string const Paragraph::getLabelWidthString() const
700 if (!params().labelWidthString().empty())
701 return params().labelWidthString();
703 return _("Senseless with this layout!");
707 void Paragraph::setLabelWidthString(string const & s)
709 params().labelWidthString(s);
713 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
716 params().labelWidthString(string());
717 params().align(LYX_ALIGN_LAYOUT);
718 params().spaceTop(VSpace(VSpace::NONE));
719 params().spaceBottom(VSpace(VSpace::NONE));
720 params().spacing(Spacing(Spacing::Default));
724 int Paragraph::beginningOfBody() const
726 if (layout()->labeltype != LABEL_MANUAL)
729 // Unroll the first two cycles of the loop
730 // and remember the previous character to
731 // remove unnecessary GetChar() calls
733 if (i < size() && !isNewline(i)) {
735 char previous_char = 0;
738 previous_char = getChar(i);
741 while (i < size() && previous_char != ' ') {
747 previous_char = temp;
757 // returns -1 if inset not found
758 int Paragraph::getPositionOfInset(InsetOld const * inset) const
761 InsetList::const_iterator it = insetlist.begin();
762 InsetList::const_iterator end = insetlist.end();
763 for (; it != end; ++it)
764 if (it->inset == inset)
770 InsetBibitem * Paragraph::bibitem() const
772 InsetList::const_iterator it = insetlist.begin();
773 if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
774 return static_cast<InsetBibitem *>(it->inset);
780 // This could go to ParagraphParameters if we want to
781 int Paragraph::startTeXParParams(BufferParams const & bparams,
782 ostream & os, bool moving_arg) const
786 if (params().noindent()) {
791 switch (params().align()) {
793 case LYX_ALIGN_BLOCK:
794 case LYX_ALIGN_LAYOUT:
795 case LYX_ALIGN_SPECIAL:
798 case LYX_ALIGN_RIGHT:
799 case LYX_ALIGN_CENTER:
807 switch (params().align()) {
809 case LYX_ALIGN_BLOCK:
810 case LYX_ALIGN_LAYOUT:
811 case LYX_ALIGN_SPECIAL:
814 if (getParLanguage(bparams)->babel() != "hebrew") {
815 os << "\\begin{flushleft}";
818 os << "\\begin{flushright}";
822 case LYX_ALIGN_RIGHT:
823 if (getParLanguage(bparams)->babel() != "hebrew") {
824 os << "\\begin{flushright}";
827 os << "\\begin{flushleft}";
831 case LYX_ALIGN_CENTER:
832 os << "\\begin{center}";
841 // This could go to ParagraphParameters if we want to
842 int Paragraph::endTeXParParams(BufferParams const & bparams,
843 ostream & os, bool moving_arg) const
847 switch (params().align()) {
849 case LYX_ALIGN_BLOCK:
850 case LYX_ALIGN_LAYOUT:
851 case LYX_ALIGN_SPECIAL:
854 case LYX_ALIGN_RIGHT:
855 case LYX_ALIGN_CENTER:
863 switch (params().align()) {
865 case LYX_ALIGN_BLOCK:
866 case LYX_ALIGN_LAYOUT:
867 case LYX_ALIGN_SPECIAL:
870 if (getParLanguage(bparams)->babel() != "hebrew") {
871 os << "\\end{flushleft}";
874 os << "\\end{flushright}";
878 case LYX_ALIGN_RIGHT:
879 if (getParLanguage(bparams)->babel() != "hebrew") {
880 os << "\\end{flushright}";
883 os << "\\end{flushleft}";
887 case LYX_ALIGN_CENTER:
888 os << "\\end{center}";
896 // This one spits out the text of the paragraph
897 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
898 BufferParams const & bparams,
899 LyXFont const & outerfont,
900 ostream & os, TexRow & texrow,
901 LatexRunParams const & runparams)
903 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
905 bool return_value = false;
909 // well we have to check if we are in an inset with unlimited
910 // lenght (all in one row) if that is true then we don't allow
911 // any special options in the paragraph and also we don't allow
912 // any environment other then "Standard" to be valid!
914 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
917 style = bparams.getLyXTextClass().defaultLayout();
924 // Maybe we have to create a optional argument.
927 // FIXME: can we actually skip this check and just call
928 // beginningOfBody() ??
929 if (style->labeltype != LABEL_MANUAL) {
932 body_pos = beginningOfBody();
935 unsigned int column = 0;
940 basefont = getLabelFont(bparams, outerfont);
942 basefont = getLayoutFont(bparams, outerfont);
945 bool moving_arg = runparams.moving_arg;
946 moving_arg |= style->needprotect;
948 // Which font is currently active?
949 LyXFont running_font(basefont);
950 // Do we have an open font change?
951 bool open_font = false;
953 Change::Type running_change = Change::UNCHANGED;
955 texrow.start(id(), 0);
957 // if the paragraph is empty, the loop will not be entered at all
959 if (style->isCommand()) {
964 column += startTeXParParams(bparams, os, moving_arg);
968 for (pos_type i = 0; i < size(); ++i) {
970 // First char in paragraph or after label?
974 column += running_font.latexWriteEndChanges(os, basefont, basefont);
977 basefont = getLayoutFont(bparams, outerfont);
978 running_font = basefont;
982 if (style->isCommand()) {
988 column += startTeXParParams(bparams, os,
992 value_type c = getChar(i);
994 // Fully instantiated font
995 LyXFont font = getFont(bparams, i, outerfont);
997 LyXFont const last_font = running_font;
999 // Spaces at end of font change are simulated to be
1000 // outside font change, i.e. we write "\textXX{text} "
1001 // rather than "\textXX{text }". (Asger)
1002 if (open_font && c == ' ' && i <= size() - 2) {
1003 LyXFont const & next_font = getFont(bparams, i + 1, outerfont);
1004 if (next_font != running_font
1005 && next_font != font) {
1010 // We end font definition before blanks
1012 (font != running_font ||
1013 font.language() != running_font.language()))
1015 column += running_font.latexWriteEndChanges(os,
1017 (i == body_pos-1) ? basefont : font);
1018 running_font = basefont;
1022 // Blanks are printed before start of fontswitch
1024 // Do not print the separation of the optional argument
1025 if (i != body_pos - 1) {
1026 pimpl_->simpleTeXBlanks(os, texrow, i,
1027 column, font, *style);
1031 // Do we need to change font?
1032 if ((font != running_font ||
1033 font.language() != running_font.language()) &&
1036 column += font.latexWriteStartChanges(os, basefont,
1038 running_font = font;
1042 Change::Type change = pimpl_->lookupChange(i);
1044 column += Changes::latexMarkChange(os, running_change, change);
1045 running_change = change;
1047 LatexRunParams rp = runparams;
1048 rp.moving_arg = moving_arg;
1049 rp.free_spacing = style->free_spacing;
1050 pimpl_->simpleTeXSpecialChars(buf, bparams,
1051 os, texrow, runparams,
1053 basefont, outerfont, open_font,
1055 *style, i, column, c);
1058 column += Changes::latexMarkChange(os,
1059 running_change, Change::UNCHANGED);
1061 // If we have an open font definition, we have to close it
1063 #ifdef FIXED_LANGUAGE_END_DETECTION
1066 .latexWriteEndChanges(os, basefont,
1067 next_->getFont(bparams,
1070 running_font.latexWriteEndChanges(os, basefont,
1074 #ifdef WITH_WARNINGS
1075 //#warning For now we ALWAYS have to close the foreign font settings if they are
1076 //#warning there as we start another \selectlanguage with the next paragraph if
1077 //#warning we are in need of this. This should be fixed sometime (Jug)
1079 running_font.latexWriteEndChanges(os, basefont, basefont);
1083 // Needed if there is an optional argument but no contents.
1084 if (body_pos > 0 && body_pos == size()) {
1086 return_value = false;
1090 column += endTeXParParams(bparams, os, moving_arg);
1093 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1094 return return_value;
1100 bool Paragraph::isHfill(pos_type pos) const
1102 return IsInsetChar(getChar(pos))
1103 && getInset(pos)->lyxCode() == InsetOld::HFILL_CODE;
1107 bool Paragraph::isInset(pos_type pos) const
1109 return IsInsetChar(getChar(pos));
1113 bool Paragraph::isNewline(pos_type pos) const
1115 return IsInsetChar(getChar(pos))
1116 && getInset(pos)->lyxCode() == InsetOld::NEWLINE_CODE;
1120 bool Paragraph::isSeparator(pos_type pos) const
1122 return IsSeparatorChar(getChar(pos));
1126 bool Paragraph::isLineSeparator(pos_type pos) const
1128 value_type const c = getChar(pos);
1129 return IsLineSeparatorChar(c)
1130 || (IsInsetChar(c) && getInset(pos) &&
1131 getInset(pos)->isLineSeparator());
1135 bool Paragraph::isKomma(pos_type pos) const
1137 return IsKommaChar(getChar(pos));
1141 /// Used by the spellchecker
1142 bool Paragraph::isLetter(pos_type pos) const
1144 value_type const c = getChar(pos);
1145 if (IsLetterChar(c))
1148 return getInset(pos)->isLetter();
1149 // We want to pass the ' and escape chars to ispell
1150 string const extra = lyxrc.isp_esc_chars + '\'';
1151 return contains(extra, c);
1155 bool Paragraph::isWord(pos_type pos) const
1157 return IsWordChar(getChar(pos)) ;
1162 Paragraph::getParLanguage(BufferParams const & bparams) const
1165 return getFirstFontSettings().language();
1166 #warning FIXME we should check the prev par as well (Lgb)
1167 return bparams.language;
1171 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
1173 return lyxrc.rtl_support
1174 && getParLanguage(bparams)->RightToLeft()
1175 && !(inInset() && inInset()->owner() &&
1176 inInset()->owner()->lyxCode() == InsetOld::ERT_CODE);
1180 void Paragraph::changeLanguage(BufferParams const & bparams,
1181 Language const * from, Language const * to)
1183 for (pos_type i = 0; i < size(); ++i) {
1184 LyXFont font = getFontSettings(bparams, i);
1185 if (font.language() == from) {
1186 font.setLanguage(to);
1193 bool Paragraph::isMultiLingual(BufferParams const & bparams)
1195 Language const * doc_language = bparams.language;
1196 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
1197 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
1199 for (; cit != end; ++cit)
1200 if (cit->font().language() != ignore_language &&
1201 cit->font().language() != latex_language &&
1202 cit->font().language() != doc_language)
1208 // Convert the paragraph to a string.
1209 // Used for building the table of contents
1210 string const Paragraph::asString(Buffer const * buffer, bool label) const
1214 if (label && !params().labelString().empty())
1215 s += params().labelString() + ' ';
1217 for (pos_type i = 0; i < size(); ++i) {
1218 value_type c = getChar(i);
1221 else if (c == META_INSET &&
1222 getInset(i)->lyxCode() == InsetOld::MATH_CODE) {
1224 getInset(i)->ascii(buffer, ost);
1225 s += subst(STRCONV(ost.str()),'\n',' ');
1231 // This should really be done by the caller and not here.
1232 string ret(asString(buffer, 0, size(), label));
1233 return subst(ret, '\n', ' ');
1238 string const Paragraph::asString(Buffer const * buffer,
1239 pos_type beg, pos_type end, bool label) const
1243 if (beg == 0 && label && !params().labelString().empty())
1244 os << params().labelString() << ' ';
1246 for (pos_type i = beg; i < end; ++i) {
1247 value_type const c = getUChar(buffer->params, i);
1250 else if (c == META_INSET)
1251 getInset(i)->ascii(buffer, os);
1254 return STRCONV(os.str());
1258 void Paragraph::setInsetOwner(UpdatableInset * inset)
1260 pimpl_->inset_owner = inset;
1261 InsetList::iterator it = insetlist.begin();
1262 InsetList::iterator end = insetlist.end();
1263 for (; it != end; ++it)
1265 it->inset->setOwner(inset);
1269 void Paragraph::deleteInsetsLyXText(BufferView * bv)
1271 insetlist.deleteInsetsLyXText(bv);
1275 void Paragraph::resizeInsetsLyXText(BufferView * bv)
1277 insetlist.resizeInsetsLyXText(bv);
1281 void Paragraph::setContentsFromPar(Paragraph const & par)
1283 pimpl_->setContentsFromPar(par);
1287 void Paragraph::trackChanges(Change::Type type)
1289 pimpl_->trackChanges(type);
1293 void Paragraph::untrackChanges()
1295 pimpl_->untrackChanges();
1299 void Paragraph::cleanChanges()
1301 pimpl_->cleanChanges();
1305 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
1307 Assert(!size() || pos < size());
1308 return pimpl_->lookupChange(pos);
1312 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
1314 Assert(!size() || pos < size());
1315 return pimpl_->lookupChangeFull(pos);
1319 bool Paragraph::isChanged(pos_type start, pos_type end) const
1321 return pimpl_->isChanged(start, end);
1325 bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
1327 return pimpl_->isChangeEdited(start, end);
1331 void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
1333 pimpl_->setChange(pos, type);
1338 void Paragraph::markErased()
1340 pimpl_->markErased();
1344 void Paragraph::acceptChange(pos_type start, pos_type end)
1346 return pimpl_->acceptChange(start, end);
1350 void Paragraph::rejectChange(pos_type start, pos_type end)
1352 return pimpl_->rejectChange(start, end);
1356 lyx::pos_type Paragraph::size() const
1358 return pimpl_->size();
1362 bool Paragraph::empty() const
1364 return pimpl_->empty();
1368 Paragraph::value_type Paragraph::getChar(pos_type pos) const
1370 return pimpl_->getChar(pos);
1374 int Paragraph::id() const
1380 void Paragraph::id(int i)
1386 LyXLayout_ptr const & Paragraph::layout() const
1389 InsetOld * inset = inInset();
1390 if (inset && inset->lyxCode() == InsetOld::ENVIRONMENT_CODE)
1391 return static_cast<InsetEnvironment*>(inset)->layout();
1397 void Paragraph::layout(LyXLayout_ptr const & new_layout)
1399 layout_ = new_layout;
1403 UpdatableInset * Paragraph::inInset() const
1405 return pimpl_->inset_owner;
1409 void Paragraph::clearContents()
1414 void Paragraph::setChar(pos_type pos, value_type c)
1416 pimpl_->setChar(pos, c);
1420 ParagraphParameters & Paragraph::params()
1422 return pimpl_->params;
1426 ParagraphParameters const & Paragraph::params() const
1428 return pimpl_->params;
1432 bool Paragraph::isFreeSpacing() const
1434 if (layout()->free_spacing)
1437 // for now we just need this, later should we need this in some
1438 // other way we can always add a function to InsetOld::() too.
1439 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1440 return (pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE);
1445 bool Paragraph::allowEmpty() const
1447 if (layout()->keepempty)
1449 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
1450 return (pimpl_->inset_owner->owner()->lyxCode() == InsetOld::ERT_CODE);
1455 bool operator==(Paragraph const & lhs, Paragraph const & rhs)
1457 #warning FIXME this implementatoin must be completely wrong...
1458 return &lhs == &rhs;