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 * ====================================================== */
14 #pragma implementation
17 #include "paragraph.h"
18 #include "paragraph_pimpl.h"
22 #include "tex-strings.h"
24 #include "bufferparams.h"
26 #include "LaTeXFeatures.h"
28 #include "BufferView.h"
30 #include "ParameterStruct.h"
32 #include "lyxtextclasslist.h"
34 #include "insets/insetinclude.h"
35 #include "insets/insetbib.h"
36 #include "insets/insettext.h"
38 #include "support/filetools.h"
39 #include "support/lstrings.h"
40 #include "support/lyxmanip.h"
41 #include "support/FileInfo.h"
42 #include "support/LAssert.h"
43 #include "support/textutils.h"
53 using std::lower_bound;
54 using std::upper_bound;
59 int tex_code_break_column = 72; // needs non-zero initialization. set later.
60 // this is a bad idea, but how can Paragraph find its buffer to get
61 // parameters? (JMarc)
63 extern string bibitemWidest(Buffer const *);
65 // this is a minibuffer
70 LyXFont minibuffer_font;
71 Inset * minibuffer_inset;
76 extern BufferView * current_view;
79 Paragraph::Paragraph()
80 : pimpl_(new Paragraph::Pimpl(this))
82 for (int i = 0; i < 10; ++i)
88 bibkey = 0; // ale970302
93 // This constructor inserts the new paragraph in a list.
94 Paragraph::Paragraph(Paragraph * par)
95 : pimpl_(new Paragraph::Pimpl(this))
97 for (int i = 0; i < 10; ++i)
102 // double linked list begin
105 next_->previous_ = this;
107 previous_->next_ = this;
110 bibkey = 0; // ale970302
115 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
116 : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
118 for (int i = 0; i < 10; ++i)
125 // this is because of the dummy layout of the paragraphs that
127 layout_ = lp.layout();
131 bibkey = static_cast<InsetBibKey *>
132 (lp.bibkey->clone(*current_view->buffer()));
137 // copy everything behind the break-position to the new paragraph
138 insetlist = lp.insetlist;
139 for (InsetList::iterator it = insetlist.begin();
140 it != insetlist.end(); ++it)
142 it->inset = it->inset->clone(*current_view->buffer(), same_ids);
143 // tell the new inset who is the boss now
144 it->inset->parOwner(this);
149 // the destructor removes the new paragraph from the list
150 Paragraph::~Paragraph()
153 previous_->next_ = next_;
155 next_->previous_ = previous_;
157 for (InsetList::iterator it = insetlist.begin();
158 it != insetlist.end(); ++it) {
167 //lyxerr << "Paragraph::paragraph_id = "
168 // << Paragraph::paragraph_id << endl;
172 void Paragraph::writeFile(Buffer const * buf, ostream & os,
173 BufferParams const & bparams,
174 depth_type dth) const
176 // The beginning or end of a deeper (i.e. nested) area?
177 if (dth != params().depth()) {
178 if (params().depth() > dth) {
179 while (params().depth() > dth) {
180 os << "\n\\begin_deeper ";
184 while (params().depth() < dth) {
185 os << "\n\\end_deeper ";
191 // First write the layout
192 os << "\n\\layout " << layout()->name() << "\n";
194 // Maybe some vertical spaces.
195 if (params().spaceTop().kind() != VSpace::NONE)
196 os << "\\added_space_top "
197 << params().spaceTop().asLyXCommand() << " ";
198 if (params().spaceBottom().kind() != VSpace::NONE)
199 os << "\\added_space_bottom "
200 << params().spaceBottom().asLyXCommand() << " ";
202 // Maybe the paragraph has special spacing
203 params().spacing().writeFile(os, true);
205 // The labelwidth string used in lists.
206 if (!params().labelWidthString().empty())
207 os << "\\labelwidthstring "
208 << params().labelWidthString() << '\n';
210 // Lines above or below?
211 if (params().lineTop())
213 if (params().lineBottom())
214 os << "\\line_bottom ";
216 // Pagebreaks above or below?
217 if (params().pagebreakTop())
218 os << "\\pagebreak_top ";
219 if (params().pagebreakBottom())
220 os << "\\pagebreak_bottom ";
222 // Start of appendix?
223 if (params().startOfAppendix())
224 os << "\\start_of_appendix ";
227 if (params().noindent())
230 // Do we have a manual left indent?
231 if (!params().leftIndent().zero())
232 os << "\\leftindent " << params().leftIndent().asString() << " ";
235 if (params().align() != LYX_ALIGN_LAYOUT) {
237 switch (params().align()) {
238 case LYX_ALIGN_LEFT: h = 1; break;
239 case LYX_ALIGN_RIGHT: h = 2; break;
240 case LYX_ALIGN_CENTER: h = 3; break;
241 default: h = 0; break;
243 os << "\\align " << string_align[h] << " ";
248 bibkey->write(buf, os);
250 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
253 for (pos_type i = 0; i < size(); ++i) {
259 // Write font changes
260 LyXFont font2 = getFontSettings(bparams, i);
261 if (font2 != font1) {
262 #ifndef INHERIT_LANGUAGE
263 font2.lyxWriteChanges(font1, os);
265 font2.lyxWriteChanges(font1, bparams.language, os);
271 value_type const c = getChar(i);
275 Inset const * inset = getInset(i);
277 if (inset->directWrite()) {
278 // international char, let it write
279 // code directly so it's shorter in
281 inset->write(buf, os);
283 os << "\n\\begin_inset ";
284 inset->write(buf, os);
285 os << "\n\\end_inset \n\n";
291 os << "\n\\newline \n";
295 os << "\n\\hfill \n";
299 os << "\n\\backslash \n";
303 if (i + 1 < size() && getChar(i + 1) == ' ') {
310 if ((column > 70 && c == ' ')
315 // this check is to amend a bug. LyX sometimes
316 // inserts '\0' this could cause problems.
320 lyxerr << "ERROR (Paragraph::writeFile):"
321 " NULL char in structure." << endl;
327 // now write the next paragraph
329 next_->writeFile(buf, os, bparams, dth);
333 void Paragraph::validate(LaTeXFeatures & features) const
335 BufferParams const & bparams = features.bufferParams();
338 if (params().lineTop() || params().lineBottom())
339 features.require("lyxline");
340 if (!params().spacing().isDefault())
341 features.require("setspace");
344 features.useLayout(layout()->name());
347 Language const * doc_language = bparams.language;
349 Pimpl::FontList::const_iterator fcit = pimpl_->fontlist.begin();
350 Pimpl::FontList::const_iterator fend = pimpl_->fontlist.end();
351 for (; fcit != fend; ++fcit) {
352 if (fcit->font().noun() == LyXFont::ON) {
353 lyxerr[Debug::LATEX] << "font.noun: "
354 << fcit->font().noun()
356 features.require("noun");
357 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
358 << fcit->font().stateText(0)
361 switch (fcit->font().color()) {
363 case LColor::inherit:
365 // probably we should put here all interface colors used for
366 // font displaying! For now I just add this ones I know of (Jug)
371 features.require("color");
372 lyxerr[Debug::LATEX] << "Color enabled. Font: "
373 << fcit->font().stateText(0)
377 Language const * language = fcit->font().language();
378 if (language->babel() != doc_language->babel() &&
379 language != ignore_language &&
380 #ifdef INHERIT_LANGUAGE
381 language != inherit_language &&
383 language != latex_language)
385 features.useLanguage(language);
386 lyxerr[Debug::LATEX] << "Found language "
387 << language->babel() << endl;
391 if (!params().leftIndent().zero())
392 features.require("ParagraphLeftIndent");
395 LyXLayout_ptr const & lout = layout();
397 InsetList::const_iterator icit = insetlist.begin();
398 InsetList::const_iterator iend = insetlist.end();
399 for (; icit != iend; ++icit) {
401 icit->inset->validate(features);
402 if (lout->needprotect &&
403 icit->inset->lyxCode() == Inset::FOOT_CODE)
404 features.require("NeedLyXFootnoteCode");
410 // First few functions needed for cut and paste and paragraph breaking.
411 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
413 BufferParams bparams = buffer.params;
415 minibuffer_char = getChar(pos);
416 minibuffer_font = getFontSettings(bparams, pos);
417 minibuffer_inset = 0;
418 if (minibuffer_char == Paragraph::META_INSET) {
420 minibuffer_inset = getInset(pos)->clone(buffer);
422 minibuffer_inset = 0;
423 minibuffer_char = ' ';
424 // This reflects what GetInset() does (ARRae)
430 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
432 minibuffer_char = getChar(pos);
433 minibuffer_font = getFontSettings(bparams, pos);
434 minibuffer_inset = 0;
435 if (minibuffer_char == Paragraph::META_INSET) {
437 minibuffer_inset = getInset(pos);
438 // This is a little hack since I want exactly
439 // the inset, not just a clone. Otherwise
440 // the inset would be deleted when calling Erase(pos)
442 InsetList::iterator it = insetlist.begin();
443 InsetList::iterator end = insetlist.end();
444 for (; it != end; ++it) {
449 if (it != end && it->pos == pos)
451 // the inset is not in a paragraph anymore
452 minibuffer_inset->parOwner(0);
454 minibuffer_inset = 0;
455 minibuffer_char = ' ';
456 // This reflects what GetInset() does (ARRae)
461 // Erase(pos); now the caller is responsible for that.
465 bool Paragraph::insertFromMinibuffer(pos_type pos)
467 if (minibuffer_char == Paragraph::META_INSET) {
468 if (!insetAllowed(minibuffer_inset->lyxCode())) {
471 insertInset(pos, minibuffer_inset, minibuffer_font);
473 LyXFont f = minibuffer_font;
474 if (!checkInsertChar(f)) {
477 insertChar(pos, minibuffer_char, f);
485 void Paragraph::erase(pos_type pos)
491 bool Paragraph::checkInsertChar(LyXFont & font)
493 if (pimpl_->inset_owner)
494 return pimpl_->inset_owner->checkInsertChar(font);
499 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
501 LyXFont const f(LyXFont::ALL_INHERIT);
502 insertChar(pos, c, f);
506 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
507 LyXFont const & font)
509 pimpl_->insertChar(pos, c, font);
513 void Paragraph::insertInset(pos_type pos, Inset * inset)
515 LyXFont const f(LyXFont::ALL_INHERIT);
516 insertInset(pos, inset, f);
520 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font)
522 pimpl_->insertInset(pos, inset, font);
526 bool Paragraph::insetAllowed(Inset::Code code)
528 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
530 if (pimpl_->inset_owner)
531 return pimpl_->inset_owner->insetAllowed(code);
536 Inset * Paragraph::getInset(pos_type pos)
538 lyx::Assert(pos < size());
541 InsetList::iterator it = insetlist.begin();
542 InsetList::iterator end = insetlist.end();
543 for (; it != end; ++it) {
548 if (it != end && it->pos == pos)
551 lyxerr << "ERROR (Paragraph::getInset): "
552 << "Inset does not exist: " << pos << endl;
555 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
556 // Did this commenting out introduce a bug? So far I have not
557 // see any, please enlighten me. (Lgb)
558 // My guess is that since the inset does not exist, we might
559 // as well replace it with a space to prevent craches. (Asger)
564 Inset const * Paragraph::getInset(pos_type pos) const
566 lyx::Assert(pos < size());
569 InsetList::const_iterator cit = insetlist.begin();
570 InsetList::const_iterator end = insetlist.end();
571 for (; cit != end; ++cit) {
576 if (cit != end && cit->pos == pos)
579 lyxerr << "ERROR (Paragraph::getInset): "
580 << "Inset does not exist: " << pos << endl;
582 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
583 // Did this commenting out introduce a bug? So far I have not
584 // see any, please enlighten me. (Lgb)
585 // My guess is that since the inset does not exist, we might
586 // as well replace it with a space to prevent craches. (Asger)
591 // Gets uninstantiated font setting at position.
592 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
595 lyx::Assert(pos <= size());
597 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
598 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
599 for (; cit != end; ++cit) {
600 if (cit->pos() >= pos)
606 retfont = cit->font();
607 } else if (pos == size() && size()) {
608 retfont = getFontSettings(bparams, pos - 1);
610 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
611 #ifdef INHERIT_LANGUAGE
612 if (retfont.language() == inherit_language)
613 retfont.setLanguage(bparams.language);
620 // Gets uninstantiated font setting at position 0
621 LyXFont const Paragraph::getFirstFontSettings() const
623 if (size() > 0 && !pimpl_->fontlist.empty())
624 return pimpl_->fontlist[0].font();
626 return LyXFont(LyXFont::ALL_INHERIT);
630 // Gets the fully instantiated font at a given position in a paragraph
631 // This is basically the same function as LyXText::GetFont() in text2.C.
632 // The difference is that this one is used for generating the LaTeX file,
633 // and thus cosmetic "improvements" are disallowed: This has to deliver
634 // the true picture of the buffer. (Asger)
635 // If position is -1, we get the layout font of the paragraph.
636 // If position is -2, we get the font of the manual label of the paragraph.
637 LyXFont const Paragraph::getFont(BufferParams const & bparams,
640 lyx::Assert(pos >= 0);
642 LyXLayout_ptr const & lout = layout();
644 pos_type main_body = 0;
645 if (lout->labeltype == LABEL_MANUAL)
646 main_body = beginningOfMainBody();
650 layoutfont = lout->labelfont;
652 layoutfont = lout->font;
654 LyXFont tmpfont = getFontSettings(bparams, pos);
655 #ifndef INHERIT_LANGUAGE
656 tmpfont.realize(layoutfont);
658 tmpfont.realize(layoutfont, bparams.language);
661 return pimpl_->realizeFont(tmpfont, bparams);
665 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
667 LyXLayout_ptr const & lout = layout();
669 LyXFont tmpfont = lout->labelfont;
670 tmpfont.setLanguage(getParLanguage(bparams));
672 return pimpl_->realizeFont(tmpfont, bparams);
676 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
678 LyXLayout_ptr const & lout = layout();
680 LyXFont tmpfont = lout->font;
681 tmpfont.setLanguage(getParLanguage(bparams));
683 return pimpl_->realizeFont(tmpfont, bparams);
687 /// Returns the height of the highest font in range
689 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
690 LyXFont::FONT_SIZE const def_size) const
692 if (pimpl_->fontlist.empty())
695 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
696 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
697 for (; end_it != end; ++end_it) {
698 if (end_it->pos() >= endpos)
705 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
706 for (; cit != end; ++cit) {
707 if (cit->pos() >= startpos)
711 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
712 for (; cit != end_it; ++cit) {
713 LyXFont::FONT_SIZE size = cit->font().size();
714 if (size == LyXFont::INHERIT_SIZE)
716 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
723 Paragraph::value_type
724 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
726 value_type c = getChar(pos);
727 if (!lyxrc.rtl_support)
757 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
764 void Paragraph::setFont(pos_type pos, LyXFont const & font)
766 lyx::Assert(pos <= size());
768 // First, reduce font against layout/label font
769 // Update: The SetCharFont() routine in text2.C already
770 // reduces font, so we don't need to do that here. (Asger)
771 // No need to simplify this because it will disappear
772 // in a new kernel. (Asger)
773 // Next search font table
775 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
776 Pimpl::FontList::iterator it = beg;
777 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
778 for (; it != endit; ++it) {
779 if (it->pos() >= pos)
782 unsigned int i = std::distance(beg, it);
783 bool notfound = (it == endit);
785 if (!notfound && pimpl_->fontlist[i].font() == font)
788 bool begin = pos == 0 || notfound ||
789 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
790 // Is position pos is a beginning of a font block?
791 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
792 // Is position pos is the end of a font block?
793 if (begin && end) { // A single char block
794 if (i + 1 < pimpl_->fontlist.size() &&
795 pimpl_->fontlist[i + 1].font() == font) {
796 // Merge the singleton block with the next block
797 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
798 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
799 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i-1);
800 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
801 // Merge the singleton block with the previous block
802 pimpl_->fontlist[i - 1].pos(pos);
803 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
805 pimpl_->fontlist[i].font(font);
807 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
808 pimpl_->fontlist[i - 1].pos(pos);
810 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
811 Pimpl::FontTable(pos, font));
813 pimpl_->fontlist[i].pos(pos - 1);
814 if (!(i + 1 < pimpl_->fontlist.size() &&
815 pimpl_->fontlist[i + 1].font() == font))
816 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
817 Pimpl::FontTable(pos, font));
818 } else { // The general case. The block is splitted into 3 blocks
819 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
820 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
821 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
822 Pimpl::FontTable(pos, font));
828 void Paragraph::next(Paragraph * p)
834 // This function is able to hide closed footnotes.
835 Paragraph * Paragraph::next()
841 Paragraph const * Paragraph::next() const
847 void Paragraph::previous(Paragraph * p)
853 // This function is able to hide closed footnotes.
854 Paragraph * Paragraph::previous()
860 // This function is able to hide closed footnotes.
861 Paragraph const * Paragraph::previous() const
867 void Paragraph::breakParagraph(BufferParams const & bparams,
871 // create a new paragraph
872 Paragraph * tmp = new Paragraph(this);
873 tmp->layout(textclasslist[bparams.textclass].defaultLayout());
874 // remember to set the inset_owner
875 tmp->setInsetOwner(inInset());
877 // this is an idea for a more userfriendly layout handling, I will
878 // see what the users say
880 // layout stays the same with latex-environments
882 tmp->layout(layout());
883 tmp->setLabelWidthString(params().labelWidthString());
886 bool isempty = (layout()->keepempty && !size());
888 if (!isempty && (size() > pos || !size() || flag == 2)) {
889 tmp->layout(layout());
890 tmp->params().align(params().align());
891 tmp->setLabelWidthString(params().labelWidthString());
893 tmp->params().lineBottom(params().lineBottom());
894 params().lineBottom(false);
895 tmp->params().pagebreakBottom(params().pagebreakBottom());
896 params().pagebreakBottom(false);
897 tmp->params().spaceBottom(params().spaceBottom());
898 params().spaceBottom(VSpace(VSpace::NONE));
900 tmp->params().depth(params().depth());
901 tmp->params().noindent(params().noindent());
903 // copy everything behind the break-position
904 // to the new paragraph
905 pos_type pos_end = size() - 1;
908 for (; i <= pos_end; ++i) {
909 cutIntoMinibuffer(bparams, i);
910 if (tmp->insertFromMinibuffer(j - pos))
913 for (i = pos_end; i >= pos; --i) {
918 // just an idea of me
919 if (!isempty && !pos) {
920 tmp->params().lineTop(params().lineTop());
921 tmp->params().pagebreakTop(params().pagebreakTop());
922 tmp->params().spaceTop(params().spaceTop());
923 tmp->bibkey = bibkey;
928 layout(textclasslist[bparams.textclass].defaultLayout());
930 // layout stays the same with latex-environments
932 layout(tmp->layout());
933 setLabelWidthString(tmp->params().labelWidthString());
934 params().depth(tmp->params().depth());
940 void Paragraph::makeSameLayout(Paragraph const * par)
942 layout(par->layout());
944 params() = par->params();
948 int Paragraph::stripLeadingSpaces()
950 if (layout()->free_spacing ||
956 while (size() && (isNewline(0) || isLineSeparator(0))) {
965 bool Paragraph::hasSameLayout(Paragraph const * par) const
968 par->layout() == layout() &&
969 params().sameLayout(par->params());
973 void Paragraph::breakParagraphConservative(BufferParams const & bparams,
976 // create a new paragraph
977 Paragraph * tmp = new Paragraph(this);
978 tmp->makeSameLayout(this);
980 // When can pos > Last()?
981 // I guess pos == Last() is possible.
983 // copy everything behind the break-position to the new
985 pos_type pos_end = size() - 1;
989 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
990 cutIntoMinibuffer(bparams, i);
991 if (tmp->insertFromMinibuffer(j - pos))
995 for (pos_type k = pos_end; k >= pos; --k) {
1002 // Be carefull, this does not make any check at all.
1003 // This method has wrong name, it combined this par with the next par.
1004 // In that sense it is the reverse of break paragraph. (Lgb)
1005 void Paragraph::pasteParagraph(BufferParams const & bparams)
1007 // copy the next paragraph to this one
1008 Paragraph * the_next = next();
1010 // first the DTP-stuff
1011 params().lineBottom(the_next->params().lineBottom());
1012 params().spaceBottom(the_next->params().spaceBottom());
1013 params().pagebreakBottom(the_next->params().pagebreakBottom());
1015 pos_type pos_end = the_next->pimpl_->size() - 1;
1016 pos_type pos_insert = size();
1018 // ok, now copy the paragraph
1019 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
1020 the_next->cutIntoMinibuffer(bparams, i);
1021 if (insertFromMinibuffer(pos_insert + j))
1025 // delete the next paragraph
1026 Paragraph * ppar = the_next->previous_;
1027 Paragraph * npar = the_next->next_;
1033 int Paragraph::getEndLabel() const
1035 Paragraph const * par = this;
1036 depth_type par_depth = getDepth();
1038 LyXLayout_ptr const & layout = par->layout();
1039 int const endlabeltype = layout->endlabeltype;
1041 if (endlabeltype != END_LABEL_NO_LABEL) {
1043 return endlabeltype;
1045 depth_type const next_depth = next_->getDepth();
1046 if (par_depth > next_depth ||
1047 (par_depth == next_depth
1048 && layout != next_->layout()))
1049 return endlabeltype;
1054 par = par->outerHook();
1056 par_depth = par->getDepth();
1058 return END_LABEL_NO_LABEL;
1062 Paragraph::depth_type Paragraph::getDepth() const
1064 return params().depth();
1068 Paragraph::depth_type Paragraph::getMaxDepthAfter() const
1070 bool const isenv = layout()->isEnvironment();
1073 return params().depth() + 1;
1075 return params().depth();
1079 char Paragraph::getAlign() const
1081 return params().align();
1085 string const & Paragraph::getLabelstring() const
1087 return params().labelString();
1091 int Paragraph::getFirstCounter(int i) const
1093 return pimpl_->counter_[i];
1097 // the next two functions are for the manual labels
1098 string const Paragraph::getLabelWidthString() const
1100 if (!params().labelWidthString().empty())
1101 return params().labelWidthString();
1103 return _("Senseless with this layout!");
1107 void Paragraph::setLabelWidthString(string const & s)
1109 params().labelWidthString(s);
1113 void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
1116 params().labelWidthString(string());
1117 params().align(LYX_ALIGN_LAYOUT);
1118 params().spaceTop(VSpace(VSpace::NONE));
1119 params().spaceBottom(VSpace(VSpace::NONE));
1120 params().spacing(Spacing(Spacing::Default));
1124 // if the layout of a paragraph contains a manual label, the beginning of the
1125 // main body is the beginning of the second word. This is what the par-
1126 // function returns. If the layout does not contain a label, the main
1127 // body always starts with position 0. This differentiation is necessary,
1128 // because there cannot be a newline or a blank <= the beginning of the
1129 // main body in TeX.
1131 int Paragraph::beginningOfMainBody() const
1133 // Unroll the first two cycles of the loop
1134 // and remember the previous character to
1135 // remove unnecessary GetChar() calls
1137 if (i < size() && getChar(i) != Paragraph::META_NEWLINE) {
1139 char previous_char = 0;
1142 && (previous_char = getChar(i)) != Paragraph::META_NEWLINE) {
1143 // Yes, this ^ is supposed to be "= " not "=="
1146 && previous_char != ' '
1147 && (temp = getChar(i)) != Paragraph::META_NEWLINE) {
1149 previous_char = temp;
1158 Paragraph * Paragraph::depthHook(depth_type depth)
1160 Paragraph * newpar = this;
1163 newpar = newpar->previous();
1164 } while (newpar && newpar->getDepth() > depth);
1167 if (previous() || getDepth())
1168 lyxerr << "ERROR (Paragraph::DepthHook): "
1177 Paragraph const * Paragraph::depthHook(depth_type depth) const
1179 Paragraph const * newpar = this;
1182 newpar = newpar->previous();
1183 } while (newpar && newpar->getDepth() > depth);
1186 if (previous() || getDepth())
1187 lyxerr << "ERROR (Paragraph::DepthHook): "
1195 Paragraph * Paragraph::outerHook()
1199 return depthHook(depth_type(getDepth() - 1));
1202 Paragraph const * Paragraph::outerHook() const
1206 return depthHook(depth_type(getDepth() - 1));
1210 Paragraph::inset_iterator
1211 Paragraph::InsetIterator(pos_type pos)
1213 InsetList::iterator it = insetlist.begin();
1214 InsetList::iterator end = insetlist.end();
1215 for (; it != end; ++it) {
1220 return inset_iterator(it);
1224 // returns -1 if inset not found
1225 int Paragraph::getPositionOfInset(Inset const * inset) const
1228 InsetList::const_iterator cit = insetlist.begin();
1229 InsetList::const_iterator end = insetlist.end();
1230 for (; cit != end; ++cit) {
1231 if (cit->inset == inset) {
1235 if (inset == bibkey)
1242 Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
1243 BufferParams const & bparams,
1244 ostream & os, TexRow & texrow,
1247 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1248 Inset const * in = inInset();
1249 bool further_blank_line = false;
1250 LyXLayout_ptr style;
1252 // well we have to check if we are in an inset with unlimited
1253 // lenght (all in one row) if that is true then we don't allow
1254 // any special options in the paragraph and also we don't allow
1255 // any environment other then "Standard" to be valid!
1256 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
1259 if (params().startOfAppendix()) {
1260 os << "\\appendix\n";
1264 if (!params().spacing().isDefault()
1265 && (!previous() || !previous()->hasSameLayout(this))) {
1266 os << params().spacing().writeEnvirBegin() << "\n";
1270 if (tex_code_break_column && style->isCommand()) {
1275 if (params().pagebreakTop()) {
1277 further_blank_line = true;
1279 if (params().spaceTop().kind() != VSpace::NONE) {
1280 os << params().spaceTop().asLatexCommand(bparams);
1281 further_blank_line = true;
1284 if (params().lineTop()) {
1285 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
1286 << "\\vspace{-1\\parskip}";
1287 further_blank_line = true;
1290 if (further_blank_line) {
1295 style = textclasslist[bparams.textclass].defaultLayout();
1298 Language const * language = getParLanguage(bparams);
1299 Language const * doc_language = bparams.language;
1300 Language const * previous_language = previous()
1301 ? previous()->getParLanguage(bparams) : doc_language;
1303 if (language->babel() != previous_language->babel()
1304 // check if we already put language command in TeXEnvironment()
1305 && !(style->isEnvironment()
1306 && (!previous() || previous()->layout() != layout() ||
1307 previous()->params().depth() != params().depth())))
1309 if (!lyxrc.language_command_end.empty() &&
1310 previous_language->babel() != doc_language->babel())
1312 os << subst(lyxrc.language_command_end, "$$lang",
1313 previous_language->babel())
1318 if (lyxrc.language_command_end.empty() ||
1319 language->babel() != doc_language->babel())
1321 os << subst(lyxrc.language_command_begin, "$$lang",
1328 if (bparams.inputenc == "auto" &&
1329 language->encoding() != previous_language->encoding()) {
1330 os << "\\inputencoding{"
1331 << language->encoding()->LatexName()
1336 switch (style->latextype) {
1339 << style->latexname()
1340 << style->latexparam();
1342 case LATEX_ITEM_ENVIRONMENT:
1344 bibkey->latex(buf, os, false, false);
1348 case LATEX_LIST_ENVIRONMENT:
1355 bool need_par = simpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
1357 // Make sure that \\par is done with the font of the last
1358 // character if this has another size as the default.
1359 // This is necessary because LaTeX (and LyX on the screen)
1360 // calculates the space between the baselines according
1361 // to this font. (Matthias)
1363 // Is this really needed ? (Dekel)
1364 // We do not need to use to change the font for the last paragraph
1365 // or for a command.
1366 LyXFont const font =
1368 ? getLayoutFont(bparams) : getFont(bparams, size() - 1));
1370 bool is_command = style->isCommand();
1372 if (style->resfont.size() != font.size() && next_ && !is_command) {
1375 os << "\\" << font.latexSize() << " \\par}";
1376 } else if (need_par) {
1378 } else if (is_command)
1381 switch (style->latextype) {
1382 case LATEX_ITEM_ENVIRONMENT:
1383 case LATEX_LIST_ENVIRONMENT:
1384 if (next_ && (params().depth() < next_->params().depth())) {
1389 case LATEX_ENVIRONMENT:
1390 // if its the last paragraph of the current environment
1391 // skip it otherwise fall through
1393 && (next_->layout() != layout()
1394 || next_->params().depth() != params().depth()))
1396 // fall through possible
1398 // we don't need it for the last paragraph!!!
1405 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
1406 further_blank_line = false;
1407 if (params().lineBottom()) {
1408 os << "\\lyxline{\\" << font.latexSize() << '}';
1409 further_blank_line = true;
1412 if (params().spaceBottom().kind() != VSpace::NONE) {
1413 os << params().spaceBottom().asLatexCommand(bparams);
1414 further_blank_line = true;
1417 if (params().pagebreakBottom()) {
1419 further_blank_line = true;
1422 if (further_blank_line) {
1427 if (!params().spacing().isDefault()
1428 && (!next_ || !next_->hasSameLayout(this))) {
1429 os << params().spacing().writeEnvirEnd() << "\n";
1434 // we don't need it for the last paragraph!!!
1439 // Since \selectlanguage write the language to the aux file,
1440 // we need to reset the language at the end of footnote or
1443 if (language->babel() != doc_language->babel()) {
1444 if (lyxrc.language_command_end.empty())
1445 os << subst(lyxrc.language_command_begin,
1447 doc_language->babel())
1450 os << subst(lyxrc.language_command_end,
1458 lyxerr[Debug::LATEX] << "TeXOnePar...done " << next_ << endl;
1462 // This could go to ParagraphParameters if we want to
1463 int Paragraph::startTeXParParams(BufferParams const & bparams,
1464 ostream & os, bool moving_arg) const
1468 if (params().noindent()) {
1469 os << "\\noindent ";
1473 switch (params().align()) {
1474 case LYX_ALIGN_NONE:
1475 case LYX_ALIGN_BLOCK:
1476 case LYX_ALIGN_LAYOUT:
1477 case LYX_ALIGN_SPECIAL:
1479 case LYX_ALIGN_LEFT:
1480 case LYX_ALIGN_RIGHT:
1481 case LYX_ALIGN_CENTER:
1489 switch (params().align()) {
1490 case LYX_ALIGN_NONE:
1491 case LYX_ALIGN_BLOCK:
1492 case LYX_ALIGN_LAYOUT:
1493 case LYX_ALIGN_SPECIAL:
1495 case LYX_ALIGN_LEFT:
1496 if (getParLanguage(bparams)->babel() != "hebrew") {
1497 os << "\\begin{flushleft}";
1500 os << "\\begin{flushright}";
1504 case LYX_ALIGN_RIGHT:
1505 if (getParLanguage(bparams)->babel() != "hebrew") {
1506 os << "\\begin{flushright}";
1509 os << "\\begin{flushleft}";
1513 case LYX_ALIGN_CENTER:
1514 os << "\\begin{center}";
1522 // This could go to ParagraphParameters if we want to
1523 int Paragraph::endTeXParParams(BufferParams const & bparams,
1524 ostream & os, bool moving_arg) const
1528 switch (params().align()) {
1529 case LYX_ALIGN_NONE:
1530 case LYX_ALIGN_BLOCK:
1531 case LYX_ALIGN_LAYOUT:
1532 case LYX_ALIGN_SPECIAL:
1534 case LYX_ALIGN_LEFT:
1535 case LYX_ALIGN_RIGHT:
1536 case LYX_ALIGN_CENTER:
1544 switch (params().align()) {
1545 case LYX_ALIGN_NONE:
1546 case LYX_ALIGN_BLOCK:
1547 case LYX_ALIGN_LAYOUT:
1548 case LYX_ALIGN_SPECIAL:
1550 case LYX_ALIGN_LEFT:
1551 if (getParLanguage(bparams)->babel() != "hebrew") {
1552 os << "\\end{flushleft}";
1555 os << "\\end{flushright}";
1559 case LYX_ALIGN_RIGHT:
1560 if (getParLanguage(bparams)->babel() != "hebrew") {
1561 os << "\\end{flushright}";
1564 os << "\\end{flushleft}";
1568 case LYX_ALIGN_CENTER:
1569 os << "\\end{center}";
1577 // This one spits out the text of the paragraph
1578 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
1579 BufferParams const & bparams,
1580 ostream & os, TexRow & texrow,
1583 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
1585 bool return_value = false;
1587 LyXLayout_ptr style;
1589 // well we have to check if we are in an inset with unlimited
1590 // lenght (all in one row) if that is true then we don't allow
1591 // any special options in the paragraph and also we don't allow
1592 // any environment other then "Standard" to be valid!
1594 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
1597 style = textclasslist[bparams.textclass].defaultLayout();
1604 // Maybe we have to create a optional argument.
1606 if (style->labeltype != LABEL_MANUAL)
1609 main_body = beginningOfMainBody();
1613 if (main_body > 0) {
1616 basefont = getLabelFont(bparams);
1618 basefont = getLayoutFont(bparams);
1621 moving_arg |= style->needprotect;
1623 // Which font is currently active?
1624 LyXFont running_font(basefont);
1625 // Do we have an open font change?
1626 bool open_font = false;
1628 texrow.start(this, 0);
1630 // if the paragraph is empty, the loop will not be entered at all
1632 if (style->isCommand()) {
1637 column += startTeXParParams(bparams, os, moving_arg);
1641 for (pos_type i = 0; i < size(); ++i) {
1643 // First char in paragraph or after label?
1644 if (i == main_body) {
1645 if (main_body > 0) {
1647 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1650 basefont = getLayoutFont(bparams);
1651 running_font = basefont;
1655 if (style->isCommand()) {
1661 column += startTeXParParams(bparams, os,
1665 value_type c = getChar(i);
1667 // Fully instantiated font
1668 LyXFont font = getFont(bparams, i);
1670 LyXFont const last_font = running_font;
1672 // Spaces at end of font change are simulated to be
1673 // outside font change, i.e. we write "\textXX{text} "
1674 // rather than "\textXX{text }". (Asger)
1675 if (open_font && c == ' ' && i <= size() - 2) {
1676 LyXFont const & next_font = getFont(bparams, i + 1);
1677 if (next_font != running_font
1678 && next_font != font) {
1683 // We end font definition before blanks
1685 (font != running_font ||
1686 font.language() != running_font.language()))
1688 column += running_font.latexWriteEndChanges(os,
1690 (i == main_body-1) ? basefont : font);
1691 running_font = basefont;
1695 // Blanks are printed before start of fontswitch
1697 // Do not print the separation of the optional argument
1698 if (i != main_body - 1) {
1699 pimpl_->simpleTeXBlanks(os, texrow, i,
1700 column, font, *style);
1704 // Do we need to change font?
1705 if ((font != running_font ||
1706 font.language() != running_font.language()) &&
1709 column += font.latexWriteStartChanges(os, basefont,
1711 running_font = font;
1715 if (c == Paragraph::META_NEWLINE) {
1716 // newlines are handled differently here than
1717 // the default in SimpleTeXSpecialChars().
1718 if (!style->newline_allowed) {
1722 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1725 basefont = getLayoutFont(bparams);
1726 running_font = basefont;
1727 if (font.family() ==
1728 LyXFont::TYPEWRITER_FAMILY) {
1737 texrow.start(this, i + 1);
1740 pimpl_->simpleTeXSpecialChars(buf, bparams,
1741 os, texrow, moving_arg,
1743 basefont, open_font,
1744 *style, i, column, c);
1748 // If we have an open font definition, we have to close it
1750 #ifdef FIXED_LANGUAGE_END_DETECTION
1753 .latexWriteEndChanges(os, basefont,
1754 next_->getFont(bparams,
1757 running_font.latexWriteEndChanges(os, basefont,
1761 #ifdef WITH_WARNINGS
1762 //#warning For now we ALWAYS have to close the foreign font settings if they are
1763 //#warning there as we start another \selectlanguage with the next paragraph if
1764 //#warning we are in need of this. This should be fixed sometime (Jug)
1766 running_font.latexWriteEndChanges(os, basefont, basefont);
1770 // Needed if there is an optional argument but no contents.
1771 if (main_body > 0 && main_body == size()) {
1773 return_value = false;
1777 column += endTeXParParams(bparams, os, moving_arg);
1780 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1781 return return_value;
1785 bool Paragraph::sgmlConvertChar(char c, string & sgml_string)
1787 bool retval = false;
1789 case Paragraph::META_HFILL:
1790 sgml_string.erase();
1792 case Paragraph::META_NEWLINE:
1796 sgml_string = "&";
1799 sgml_string = "<";
1802 sgml_string = ">";
1805 sgml_string = "$";
1808 sgml_string = "#";
1811 sgml_string = "%";
1814 sgml_string = "[";
1817 sgml_string = "]";
1820 sgml_string = "{";
1823 sgml_string = "}";
1826 sgml_string = "˜";
1829 sgml_string = """;
1832 sgml_string = "\";
1838 case '\0': // Ignore :-)
1839 sgml_string.erase();
1849 Paragraph * Paragraph::TeXEnvironment(Buffer const * buf,
1850 BufferParams const & bparams,
1851 ostream & os, TexRow & texrow)
1853 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
1855 LyXLayout_ptr const & style = layout();
1857 Language const * language = getParLanguage(bparams);
1858 Language const * doc_language = bparams.language;
1859 Language const * previous_language = previous_
1860 ? previous_->getParLanguage(bparams) : doc_language;
1861 if (language->babel() != previous_language->babel()) {
1863 if (!lyxrc.language_command_end.empty() &&
1864 previous_language->babel() != doc_language->babel()) {
1865 os << subst(lyxrc.language_command_end, "$$lang",
1866 previous_language->babel())
1871 if (lyxrc.language_command_end.empty() ||
1872 language->babel() != doc_language->babel()) {
1873 os << subst(lyxrc.language_command_begin, "$$lang",
1880 bool leftindent_open = false;
1881 if (!params().leftIndent().zero()) {
1882 os << "\\begin{LyXParagraphLeftIndent}{" <<
1883 params().leftIndent().asLatexString() << "}\n";
1885 leftindent_open = true;
1888 if (style->isEnvironment()) {
1889 if (style->latextype == LATEX_LIST_ENVIRONMENT) {
1890 os << "\\begin{" << style->latexname() << "}{"
1891 << params().labelWidthString() << "}\n";
1892 } else if (style->labeltype == LABEL_BIBLIO) {
1894 os << "\\begin{" << style->latexname() << "}{"
1895 << bibitemWidest(buf)
1897 } else if (style->latextype == LATEX_ITEM_ENVIRONMENT) {
1898 os << "\\begin{" << style->latexname() << '}'
1899 << style->latexparam() << '\n';
1901 os << "\\begin{" << style->latexname() << '}'
1902 << style->latexparam() << '\n';
1905 Paragraph * par = this;
1907 par = par->TeXOnePar(buf, bparams, os, texrow, false);
1909 if (par && par->params().depth() > params().depth()) {
1910 if (par->layout()->isParagraph()) {
1913 // How to handle this? (Lgb)
1914 //&& !suffixIs(os, "\n\n")
1916 // There should be at least one '\n' already
1917 // but we need there to be two for Standard
1918 // paragraphs that are depth-increment'ed to be
1919 // output correctly. However, tables can
1920 // also be paragraphs so don't adjust them.
1923 // Will it ever harm to have one '\n' too
1924 // many? i.e. that we sometimes will have
1925 // three in a row. (Lgb)
1929 par = par->pimpl_->TeXDeeper(buf, bparams, os, texrow);
1932 && par->layout() == layout()
1933 && par->params().depth() == params().depth()
1934 && par->params().leftIndent() == params().leftIndent());
1936 if (style->isEnvironment()) {
1937 os << "\\end{" << style->latexname() << "}\n";
1941 if (leftindent_open) {
1942 os << "\\end{LyXParagraphLeftIndent}\n";
1946 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
1947 return par; // ale970302
1951 bool Paragraph::isHfill(pos_type pos) const
1953 return IsHfillChar(getChar(pos));
1957 bool Paragraph::isInset(pos_type pos) const
1959 return IsInsetChar(getChar(pos));
1963 bool Paragraph::isNewline(pos_type pos) const
1965 return pos >= 0 && IsNewlineChar(getChar(pos));
1969 bool Paragraph::isSeparator(pos_type pos) const
1971 return IsSeparatorChar(getChar(pos));
1975 bool Paragraph::isLineSeparator(pos_type pos) const
1977 value_type const c = getChar(pos);
1978 return IsLineSeparatorChar(c)
1979 || (IsInsetChar(c) && getInset(pos) &&
1980 getInset(pos)->isLineSeparator());
1984 bool Paragraph::isKomma(pos_type pos) const
1986 return IsKommaChar(getChar(pos));
1990 /// Used by the spellchecker
1991 bool Paragraph::isLetter(pos_type pos) const
1993 value_type const c = getChar(pos);
1994 if (IsLetterChar(c))
1997 return getInset(pos)->isLetter();
1998 // We want to pass the ' and escape chars to ispell
1999 string const extra = lyxrc.isp_esc_chars + '\'';
2000 return contains(extra, c);
2004 bool Paragraph::isWord(pos_type pos) const
2006 return IsWordChar(getChar(pos)) ;
2011 Paragraph::getParLanguage(BufferParams const & bparams) const
2014 #ifndef INHERIT_LANGUAGE
2015 return getFirstFontSettings().language();
2017 Language const * lang = getFirstFontSettings().language();
2018 #ifdef WITH_WARNINGS
2019 #warning We should make this somewhat better, any ideas? (Jug)
2021 if (lang == inherit_language || lang == ignore_language)
2022 lang = bparams.language;
2025 } else if (previous_)
2026 return previous_->getParLanguage(bparams);
2028 return bparams.language;
2032 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
2034 return lyxrc.rtl_support
2035 && getParLanguage(bparams)->RightToLeft()
2036 && !(inInset() && inInset()->owner() &&
2037 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
2041 void Paragraph::changeLanguage(BufferParams const & bparams,
2042 Language const * from, Language const * to)
2044 for (pos_type i = 0; i < size(); ++i) {
2045 LyXFont font = getFontSettings(bparams, i);
2046 if (font.language() == from) {
2047 font.setLanguage(to);
2054 bool Paragraph::isMultiLingual(BufferParams const & bparams)
2056 Language const * doc_language = bparams.language;
2057 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
2058 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
2060 for (; cit != end; ++cit)
2061 if (cit->font().language() != ignore_language &&
2062 cit->font().language() != latex_language &&
2063 #ifdef INHERIT_LANGUAGE
2064 cit->font().language() != inherit_language &&
2066 cit->font().language() != doc_language)
2072 // Convert the paragraph to a string.
2073 // Used for building the table of contents
2074 string const Paragraph::asString(Buffer const * buffer, bool label)
2076 BufferParams const & bparams = buffer->params;
2078 if (label && !params().labelString().empty())
2079 s += params().labelString() + ' ';
2080 string::size_type const len = s.size();
2082 for (pos_type i = 0; i < size(); ++i) {
2083 value_type c = getChar(i);
2086 else if (c == META_INSET &&
2087 getInset(i)->lyxCode() == Inset::MATH_CODE) {
2089 getInset(i)->ascii(buffer, ost);
2090 s += subst(ost.str().c_str(),'\n',' ');
2094 if (isRightToLeftPar(bparams))
2095 reverse(s.begin() + len,s.end());
2101 string const Paragraph::asString(Buffer const * buffer,
2102 pos_type beg, pos_type end, bool label)
2106 if (beg == 0 && label && !params().labelString().empty())
2107 ost << params().labelString() << ' ';
2109 for (pos_type i = beg; i < end; ++i) {
2110 value_type const c = getUChar(buffer->params, i);
2113 else if (c == META_NEWLINE)
2115 else if (c == META_HFILL)
2117 else if (c == META_INSET) {
2118 getInset(i)->ascii(buffer, ost);
2122 return ost.str().c_str();
2126 void Paragraph::setInsetOwner(Inset * i)
2128 pimpl_->inset_owner = i;
2129 InsetList::const_iterator cit = insetlist.begin();
2130 InsetList::const_iterator end = insetlist.end();
2131 for (; cit != end; ++cit) {
2133 cit->inset->setOwner(i);
2138 void Paragraph::deleteInsetsLyXText(BufferView * bv)
2141 InsetList::const_iterator cit = insetlist.begin();
2142 InsetList::const_iterator end = insetlist.end();
2143 for (; cit != end; ++cit) {
2144 if (cit->inset && cit->inset->isTextInset()) {
2145 static_cast<UpdatableInset *>
2146 (cit->inset)->deleteLyXText(bv, true);
2152 void Paragraph::resizeInsetsLyXText(BufferView * bv)
2155 InsetList::const_iterator cit = insetlist.begin();
2156 InsetList::const_iterator end = insetlist.end();
2157 for (; cit != end; ++cit) {
2159 if (cit->inset->isTextInset()) {
2160 static_cast<UpdatableInset *>
2161 (cit->inset)->resizeLyXText(bv, true);
2168 void Paragraph::setContentsFromPar(Paragraph * par)
2170 pimpl_->setContentsFromPar(par);
2174 lyx::pos_type Paragraph::size() const
2176 return pimpl_->size();
2180 Paragraph::value_type Paragraph::getChar(pos_type pos) const
2182 return pimpl_->getChar(pos);
2186 int Paragraph::id() const
2192 void Paragraph::id(int id_arg)
2194 pimpl_->id_ = id_arg;
2198 LyXLayout_ptr const & Paragraph::layout() const
2204 void Paragraph::layout(LyXLayout_ptr const & new_layout)
2206 layout_ = new_layout;
2210 bool Paragraph::isFirstInSequence() const
2212 Paragraph const * dhook = depthHook(getDepth());
2213 return (dhook == this
2214 || dhook->layout() != layout()
2215 || dhook->getDepth() != getDepth());
2219 Inset * Paragraph::inInset() const
2221 return pimpl_->inset_owner;
2225 void Paragraph::clearContents()
2231 void Paragraph::setCounter(int i, int v)
2233 pimpl_->counter_[i] = v;
2237 int Paragraph::getCounter(int i) const
2239 return pimpl_->counter_[i];
2243 void Paragraph::incCounter(int i)
2245 pimpl_->counter_[i]++;
2249 void Paragraph::setChar(pos_type pos, value_type c)
2251 pimpl_->setChar(pos, c);
2255 Paragraph::inset_iterator::inset_iterator(Paragraph::InsetList::iterator const & iter)
2260 Paragraph::inset_iterator Paragraph::inset_iterator_begin()
2262 return inset_iterator(insetlist.begin());
2266 Paragraph::inset_iterator Paragraph::inset_iterator_end()
2268 return inset_iterator(insetlist.end());
2272 ParagraphParameters & Paragraph::params()
2274 return pimpl_->params;
2278 ParagraphParameters const & Paragraph::params() const
2280 return pimpl_->params;
2284 Paragraph * Paragraph::getParFromID(int id) const
2286 return pimpl_->getParFromID(id);
2290 bool Paragraph::isFreeSpacing() const
2292 // for now we just need this, later should we need this in some
2293 // other way we can always add a function to Inset::() too.
2294 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
2295 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);