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 string lay = layout();
194 lay = textclasslist[bparams.textclass].defaultLayoutName();
197 os << "\n\\layout " << layout() << "\n";
199 // Maybe some vertical spaces.
200 if (params().spaceTop().kind() != VSpace::NONE)
201 os << "\\added_space_top "
202 << params().spaceTop().asLyXCommand() << " ";
203 if (params().spaceBottom().kind() != VSpace::NONE)
204 os << "\\added_space_bottom "
205 << params().spaceBottom().asLyXCommand() << " ";
207 // Maybe the paragraph has special spacing
208 params().spacing().writeFile(os, true);
210 // The labelwidth string used in lists.
211 if (!params().labelWidthString().empty())
212 os << "\\labelwidthstring "
213 << params().labelWidthString() << '\n';
215 // Lines above or below?
216 if (params().lineTop())
218 if (params().lineBottom())
219 os << "\\line_bottom ";
221 // Pagebreaks above or below?
222 if (params().pagebreakTop())
223 os << "\\pagebreak_top ";
224 if (params().pagebreakBottom())
225 os << "\\pagebreak_bottom ";
227 // Start of appendix?
228 if (params().startOfAppendix())
229 os << "\\start_of_appendix ";
232 if (params().noindent())
235 // Do we have a manual left indent?
236 if (!params().leftIndent().zero())
237 os << "\\leftindent " << params().leftIndent().asString() << " ";
240 if (params().align() != LYX_ALIGN_LAYOUT) {
242 switch (params().align()) {
243 case LYX_ALIGN_LEFT: h = 1; break;
244 case LYX_ALIGN_RIGHT: h = 2; break;
245 case LYX_ALIGN_CENTER: h = 3; break;
246 default: h = 0; break;
248 os << "\\align " << string_align[h] << " ";
253 bibkey->write(buf, os);
255 LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
258 for (pos_type i = 0; i < size(); ++i) {
264 // Write font changes
265 LyXFont font2 = getFontSettings(bparams, i);
266 if (font2 != font1) {
267 #ifndef INHERIT_LANGUAGE
268 font2.lyxWriteChanges(font1, os);
270 font2.lyxWriteChanges(font1, bparams.language, os);
276 value_type const c = getChar(i);
280 Inset const * inset = getInset(i);
282 if (inset->directWrite()) {
283 // international char, let it write
284 // code directly so it's shorter in
286 inset->write(buf, os);
288 os << "\n\\begin_inset ";
289 inset->write(buf, os);
290 os << "\n\\end_inset \n\n";
296 os << "\n\\newline \n";
300 os << "\n\\hfill \n";
304 os << "\n\\backslash \n";
308 if (i + 1 < size() && getChar(i + 1) == ' ') {
315 if ((column > 70 && c == ' ')
320 // this check is to amend a bug. LyX sometimes
321 // inserts '\0' this could cause problems.
325 lyxerr << "ERROR (Paragraph::writeFile):"
326 " NULL char in structure." << endl;
332 // now write the next paragraph
334 next_->writeFile(buf, os, bparams, dth);
338 void Paragraph::validate(LaTeXFeatures & features) const
340 BufferParams const & bparams = features.bufferParams();
343 if (params().lineTop() || params().lineBottom())
344 features.require("lyxline");
345 if (!params().spacing().isDefault())
346 features.require("setspace");
349 features.useLayout(layout());
352 Language const * doc_language = bparams.language;
354 Pimpl::FontList::const_iterator fcit = pimpl_->fontlist.begin();
355 Pimpl::FontList::const_iterator fend = pimpl_->fontlist.end();
356 for (; fcit != fend; ++fcit) {
357 if (fcit->font().noun() == LyXFont::ON) {
358 lyxerr[Debug::LATEX] << "font.noun: "
359 << fcit->font().noun()
361 features.require("noun");
362 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
363 << fcit->font().stateText(0)
366 switch (fcit->font().color()) {
368 case LColor::inherit:
370 // probably we should put here all interface colors used for
371 // font displaying! For now I just add this ones I know of (Jug)
376 features.require("color");
377 lyxerr[Debug::LATEX] << "Color enabled. Font: "
378 << fcit->font().stateText(0)
382 Language const * language = fcit->font().language();
383 if (language->babel() != doc_language->babel() &&
384 language != ignore_language &&
385 #ifdef INHERIT_LANGUAGE
386 language != inherit_language &&
388 language != latex_language)
390 features.useLanguage(language);
391 lyxerr[Debug::LATEX] << "Found language "
392 << language->babel() << endl;
396 if (!params().leftIndent().zero())
397 features.require("ParagraphLeftIndent");
400 LyXLayout const & lout = textclasslist[bparams.textclass][layout()];
402 InsetList::const_iterator icit = insetlist.begin();
403 InsetList::const_iterator iend = insetlist.end();
404 for (; icit != iend; ++icit) {
406 icit->inset->validate(features);
407 if (lout.needprotect &&
408 icit->inset->lyxCode() == Inset::FOOT_CODE)
409 features.require("NeedLyXFootnoteCode");
415 // First few functions needed for cut and paste and paragraph breaking.
416 void Paragraph::copyIntoMinibuffer(Buffer const & buffer, pos_type pos) const
418 BufferParams bparams = buffer.params;
420 minibuffer_char = getChar(pos);
421 minibuffer_font = getFontSettings(bparams, pos);
422 minibuffer_inset = 0;
423 if (minibuffer_char == Paragraph::META_INSET) {
425 minibuffer_inset = getInset(pos)->clone(buffer);
427 minibuffer_inset = 0;
428 minibuffer_char = ' ';
429 // This reflects what GetInset() does (ARRae)
435 void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
437 minibuffer_char = getChar(pos);
438 minibuffer_font = getFontSettings(bparams, pos);
439 minibuffer_inset = 0;
440 if (minibuffer_char == Paragraph::META_INSET) {
442 minibuffer_inset = getInset(pos);
443 // This is a little hack since I want exactly
444 // the inset, not just a clone. Otherwise
445 // the inset would be deleted when calling Erase(pos)
447 InsetList::iterator it = insetlist.begin();
448 InsetList::iterator end = insetlist.end();
449 for (; it != end; ++it) {
454 if (it != end && it->pos == pos)
456 // the inset is not in a paragraph anymore
457 minibuffer_inset->parOwner(0);
459 minibuffer_inset = 0;
460 minibuffer_char = ' ';
461 // This reflects what GetInset() does (ARRae)
466 // Erase(pos); now the caller is responsible for that.
470 bool Paragraph::insertFromMinibuffer(pos_type pos)
472 if (minibuffer_char == Paragraph::META_INSET) {
473 if (!insetAllowed(minibuffer_inset->lyxCode())) {
476 insertInset(pos, minibuffer_inset, minibuffer_font);
478 LyXFont f = minibuffer_font;
479 if (!checkInsertChar(f)) {
482 insertChar(pos, minibuffer_char, f);
490 void Paragraph::erase(pos_type pos)
496 bool Paragraph::checkInsertChar(LyXFont & font)
498 if (pimpl_->inset_owner)
499 return pimpl_->inset_owner->checkInsertChar(font);
504 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c)
506 LyXFont const f(LyXFont::ALL_INHERIT);
507 insertChar(pos, c, f);
511 void Paragraph::insertChar(pos_type pos, Paragraph::value_type c,
512 LyXFont const & font)
514 pimpl_->insertChar(pos, c, font);
518 void Paragraph::insertInset(pos_type pos, Inset * inset)
520 LyXFont const f(LyXFont::ALL_INHERIT);
521 insertInset(pos, inset, f);
525 void Paragraph::insertInset(pos_type pos, Inset * inset, LyXFont const & font)
527 pimpl_->insertInset(pos, inset, font);
531 bool Paragraph::insetAllowed(Inset::Code code)
533 //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
535 if (pimpl_->inset_owner)
536 return pimpl_->inset_owner->insetAllowed(code);
541 Inset * Paragraph::getInset(pos_type pos)
543 lyx::Assert(pos < size());
546 InsetList::iterator it = insetlist.begin();
547 InsetList::iterator end = insetlist.end();
548 for (; it != end; ++it) {
553 if (it != end && it->pos == pos)
556 lyxerr << "ERROR (Paragraph::getInset): "
557 << "Inset does not exist: " << pos << endl;
560 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
561 // Did this commenting out introduce a bug? So far I have not
562 // see any, please enlighten me. (Lgb)
563 // My guess is that since the inset does not exist, we might
564 // as well replace it with a space to prevent craches. (Asger)
569 Inset const * Paragraph::getInset(pos_type pos) const
571 lyx::Assert(pos < size());
574 InsetList::const_iterator cit = insetlist.begin();
575 InsetList::const_iterator end = insetlist.end();
576 for (; cit != end; ++cit) {
581 if (cit != end && cit->pos == pos)
584 lyxerr << "ERROR (Paragraph::getInset): "
585 << "Inset does not exist: " << pos << endl;
587 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
588 // Did this commenting out introduce a bug? So far I have not
589 // see any, please enlighten me. (Lgb)
590 // My guess is that since the inset does not exist, we might
591 // as well replace it with a space to prevent craches. (Asger)
596 // Gets uninstantiated font setting at position.
597 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
600 lyx::Assert(pos <= size());
602 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
603 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
604 for (; cit != end; ++cit) {
605 if (cit->pos() >= pos)
611 retfont = cit->font();
612 } else if (pos == size() && size()) {
613 retfont = getFontSettings(bparams, pos - 1);
615 retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
616 #ifdef INHERIT_LANGUAGE
617 if (retfont.language() == inherit_language)
618 retfont.setLanguage(bparams.language);
625 // Gets uninstantiated font setting at position 0
626 LyXFont const Paragraph::getFirstFontSettings() const
628 if (size() > 0 && !pimpl_->fontlist.empty())
629 return pimpl_->fontlist[0].font();
631 return LyXFont(LyXFont::ALL_INHERIT);
635 // Gets the fully instantiated font at a given position in a paragraph
636 // This is basically the same function as LyXText::GetFont() in text2.C.
637 // The difference is that this one is used for generating the LaTeX file,
638 // and thus cosmetic "improvements" are disallowed: This has to deliver
639 // the true picture of the buffer. (Asger)
640 // If position is -1, we get the layout font of the paragraph.
641 // If position is -2, we get the font of the manual label of the paragraph.
642 LyXFont const Paragraph::getFont(BufferParams const & bparams,
645 lyx::Assert(pos >= 0);
647 LyXLayout const & lout =
648 textclasslist[bparams.textclass][layout()];
649 pos_type main_body = 0;
650 if (lout.labeltype == LABEL_MANUAL)
651 main_body = beginningOfMainBody();
655 layoutfont = lout.labelfont;
657 layoutfont = lout.font;
659 LyXFont tmpfont = getFontSettings(bparams, pos);
660 #ifndef INHERIT_LANGUAGE
661 tmpfont.realize(layoutfont);
663 tmpfont.realize(layoutfont, bparams.language);
666 return pimpl_->realizeFont(tmpfont, bparams);
670 LyXFont const Paragraph::getLabelFont(BufferParams const & bparams) const
672 LyXLayout const & lout =
673 textclasslist[bparams.textclass][layout()];
675 LyXFont tmpfont = lout.labelfont;
676 tmpfont.setLanguage(getParLanguage(bparams));
678 return pimpl_->realizeFont(tmpfont, bparams);
682 LyXFont const Paragraph::getLayoutFont(BufferParams const & bparams) const
684 LyXLayout const & lout =
685 textclasslist[bparams.textclass][layout()];
687 LyXFont tmpfont = lout.font;
688 tmpfont.setLanguage(getParLanguage(bparams));
690 return pimpl_->realizeFont(tmpfont, bparams);
694 /// Returns the height of the highest font in range
696 Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
697 LyXFont::FONT_SIZE const def_size) const
699 if (pimpl_->fontlist.empty())
702 Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
703 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
704 for (; end_it != end; ++end_it) {
705 if (end_it->pos() >= endpos)
712 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
713 for (; cit != end; ++cit) {
714 if (cit->pos() >= startpos)
718 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
719 for (; cit != end_it; ++cit) {
720 LyXFont::FONT_SIZE size = cit->font().size();
721 if (size == LyXFont::INHERIT_SIZE)
723 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
730 Paragraph::value_type
731 Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
733 value_type c = getChar(pos);
734 if (!lyxrc.rtl_support)
764 if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
771 void Paragraph::setFont(pos_type pos, LyXFont const & font)
773 lyx::Assert(pos <= size());
775 // First, reduce font against layout/label font
776 // Update: The SetCharFont() routine in text2.C already
777 // reduces font, so we don't need to do that here. (Asger)
778 // No need to simplify this because it will disappear
779 // in a new kernel. (Asger)
780 // Next search font table
782 Pimpl::FontList::iterator beg = pimpl_->fontlist.begin();
783 Pimpl::FontList::iterator it = beg;
784 Pimpl::FontList::iterator endit = pimpl_->fontlist.end();
785 for (; it != endit; ++it) {
786 if (it->pos() >= pos)
789 unsigned int i = std::distance(beg, it);
790 bool notfound = (it == endit);
792 if (!notfound && pimpl_->fontlist[i].font() == font)
795 bool begin = pos == 0 || notfound ||
796 (i > 0 && pimpl_->fontlist[i - 1].pos() == pos - 1);
797 // Is position pos is a beginning of a font block?
798 bool end = !notfound && pimpl_->fontlist[i].pos() == pos;
799 // Is position pos is the end of a font block?
800 if (begin && end) { // A single char block
801 if (i + 1 < pimpl_->fontlist.size() &&
802 pimpl_->fontlist[i + 1].font() == font) {
803 // Merge the singleton block with the next block
804 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
805 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
806 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i-1);
807 } else if (i > 0 && pimpl_->fontlist[i - 1].font() == font) {
808 // Merge the singleton block with the previous block
809 pimpl_->fontlist[i - 1].pos(pos);
810 pimpl_->fontlist.erase(pimpl_->fontlist.begin() + i);
812 pimpl_->fontlist[i].font(font);
814 if (i > 0 && pimpl_->fontlist[i - 1].font() == font)
815 pimpl_->fontlist[i - 1].pos(pos);
817 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
818 Pimpl::FontTable(pos, font));
820 pimpl_->fontlist[i].pos(pos - 1);
821 if (!(i + 1 < pimpl_->fontlist.size() &&
822 pimpl_->fontlist[i + 1].font() == font))
823 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
824 Pimpl::FontTable(pos, font));
825 } else { // The general case. The block is splitted into 3 blocks
826 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i,
827 Pimpl::FontTable(pos - 1, pimpl_->fontlist[i].font()));
828 pimpl_->fontlist.insert(pimpl_->fontlist.begin() + i + 1,
829 Pimpl::FontTable(pos, font));
835 void Paragraph::next(Paragraph * p)
841 // This function is able to hide closed footnotes.
842 Paragraph * Paragraph::next()
848 Paragraph const * Paragraph::next() const
854 void Paragraph::previous(Paragraph * p)
860 // This function is able to hide closed footnotes.
861 Paragraph * Paragraph::previous()
867 // This function is able to hide closed footnotes.
868 Paragraph const * Paragraph::previous() const
874 void Paragraph::breakParagraph(BufferParams const & bparams,
878 // create a new paragraph
879 Paragraph * tmp = new Paragraph(this);
880 tmp->layout(textclasslist[bparams.textclass].defaultLayoutName());
882 // remember to set the inset_owner
883 tmp->setInsetOwner(inInset());
885 // this is an idea for a more userfriendly layout handling, I will
886 // see what the users say
888 // layout stays the same with latex-environments
890 tmp->layout(layout());
891 tmp->setLabelWidthString(params().labelWidthString());
894 bool isempty = (textclasslist[bparams.textclass][layout()].keepempty &&
896 if (!isempty && (size() > pos || !size() || flag == 2)) {
897 tmp->layout(layout());
898 tmp->params().align(params().align());
899 tmp->setLabelWidthString(params().labelWidthString());
901 tmp->params().lineBottom(params().lineBottom());
902 params().lineBottom(false);
903 tmp->params().pagebreakBottom(params().pagebreakBottom());
904 params().pagebreakBottom(false);
905 tmp->params().spaceBottom(params().spaceBottom());
906 params().spaceBottom(VSpace(VSpace::NONE));
908 tmp->params().depth(params().depth());
909 tmp->params().noindent(params().noindent());
911 // copy everything behind the break-position
912 // to the new paragraph
913 pos_type pos_end = size() - 1;
916 for (; i <= pos_end; ++i) {
917 cutIntoMinibuffer(bparams, i);
918 if (tmp->insertFromMinibuffer(j - pos))
921 for (i = pos_end; i >= pos; --i) {
926 // just an idea of me
927 if (!isempty && !pos) {
928 tmp->params().lineTop(params().lineTop());
929 tmp->params().pagebreakTop(params().pagebreakTop());
930 tmp->params().spaceTop(params().spaceTop());
931 tmp->bibkey = bibkey;
935 layout(textclasslist[bparams.textclass].defaultLayoutName());
937 // layout stays the same with latex-environments
939 layout(tmp->layout());
940 setLabelWidthString(tmp->params().labelWidthString());
941 params().depth(tmp->params().depth());
947 void Paragraph::makeSameLayout(Paragraph const * par)
949 layout(par->layout());
951 params() = par->params();
955 int Paragraph::stripLeadingSpaces(lyx::textclass_type tclass)
957 if (textclasslist[tclass][layout()].free_spacing ||
963 while (size() && (isNewline(0) || isLineSeparator(0))) {
972 bool Paragraph::hasSameLayout(Paragraph const * par) const
975 par->layout() == layout() &&
976 params().sameLayout(par->params());
980 void Paragraph::breakParagraphConservative(BufferParams const & bparams,
983 // create a new paragraph
984 Paragraph * tmp = new Paragraph(this);
985 tmp->makeSameLayout(this);
987 // When can pos > Last()?
988 // I guess pos == Last() is possible.
990 // copy everything behind the break-position to the new
992 pos_type pos_end = size() - 1;
996 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
997 cutIntoMinibuffer(bparams, i);
998 if (tmp->insertFromMinibuffer(j - pos))
1002 for (pos_type k = pos_end; k >= pos; --k) {
1009 // Be carefull, this does not make any check at all.
1010 // This method has wrong name, it combined this par with the next par.
1011 // In that sense it is the reverse of break paragraph. (Lgb)
1012 void Paragraph::pasteParagraph(BufferParams const & bparams)
1014 // copy the next paragraph to this one
1015 Paragraph * the_next = next();
1017 // first the DTP-stuff
1018 params().lineBottom(the_next->params().lineBottom());
1019 params().spaceBottom(the_next->params().spaceBottom());
1020 params().pagebreakBottom(the_next->params().pagebreakBottom());
1022 pos_type pos_end = the_next->pimpl_->size() - 1;
1023 pos_type pos_insert = size();
1025 // ok, now copy the paragraph
1026 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
1027 the_next->cutIntoMinibuffer(bparams, i);
1028 if (insertFromMinibuffer(pos_insert + j))
1032 // delete the next paragraph
1033 Paragraph * ppar = the_next->previous_;
1034 Paragraph * npar = the_next->next_;
1040 int Paragraph::getEndLabel(BufferParams const & bparams) const
1042 Paragraph const * par = this;
1043 depth_type par_depth = getDepth();
1045 string const & layout = par->layout();
1046 int const endlabeltype =
1047 textclasslist[bparams.textclass][layout].endlabeltype;
1048 if (endlabeltype != END_LABEL_NO_LABEL) {
1050 return endlabeltype;
1052 depth_type const next_depth = next_->getDepth();
1053 if (par_depth > next_depth ||
1054 (par_depth == next_depth
1055 && layout != next_->layout()))
1056 return endlabeltype;
1061 par = par->outerHook();
1063 par_depth = par->getDepth();
1065 return END_LABEL_NO_LABEL;
1069 Paragraph::depth_type Paragraph::getDepth() const
1071 return params().depth();
1075 Paragraph::depth_type Paragraph::getMaxDepthAfter(Buffer const * buffer) const
1077 bool const isenv = textclasslist[buffer->params.textclass][layout()].isEnvironment();
1080 return params().depth() + 1;
1082 return params().depth();
1086 char Paragraph::getAlign() const
1088 return params().align();
1092 string const & Paragraph::getLabelstring() const
1094 return params().labelString();
1098 int Paragraph::getFirstCounter(int i) const
1100 return pimpl_->counter_[i];
1104 // the next two functions are for the manual labels
1105 string const Paragraph::getLabelWidthString() const
1107 if (!params().labelWidthString().empty())
1108 return params().labelWidthString();
1110 return _("Senseless with this layout!");
1114 void Paragraph::setLabelWidthString(string const & s)
1116 params().labelWidthString(s);
1120 void Paragraph::applyLayout(string const & new_layout)
1123 params().labelWidthString(string());
1124 params().align(LYX_ALIGN_LAYOUT);
1125 params().spaceTop(VSpace(VSpace::NONE));
1126 params().spaceBottom(VSpace(VSpace::NONE));
1127 params().spacing(Spacing(Spacing::Default));
1131 // if the layout of a paragraph contains a manual label, the beginning of the
1132 // main body is the beginning of the second word. This is what the par-
1133 // function returns. If the layout does not contain a label, the main
1134 // body always starts with position 0. This differentiation is necessary,
1135 // because there cannot be a newline or a blank <= the beginning of the
1136 // main body in TeX.
1138 int Paragraph::beginningOfMainBody() const
1140 // Unroll the first two cycles of the loop
1141 // and remember the previous character to
1142 // remove unnecessary GetChar() calls
1144 if (i < size() && getChar(i) != Paragraph::META_NEWLINE) {
1146 char previous_char = 0;
1149 && (previous_char = getChar(i)) != Paragraph::META_NEWLINE) {
1150 // Yes, this ^ is supposed to be "= " not "=="
1153 && previous_char != ' '
1154 && (temp = getChar(i)) != Paragraph::META_NEWLINE) {
1156 previous_char = temp;
1165 Paragraph * Paragraph::depthHook(depth_type depth)
1167 Paragraph * newpar = this;
1170 newpar = newpar->previous();
1171 } while (newpar && newpar->getDepth() > depth);
1174 if (previous() || getDepth())
1175 lyxerr << "ERROR (Paragraph::DepthHook): "
1184 Paragraph const * Paragraph::depthHook(depth_type depth) const
1186 Paragraph const * newpar = this;
1189 newpar = newpar->previous();
1190 } while (newpar && newpar->getDepth() > depth);
1193 if (previous() || getDepth())
1194 lyxerr << "ERROR (Paragraph::DepthHook): "
1202 Paragraph * Paragraph::outerHook()
1206 return depthHook(depth_type(getDepth() - 1));
1209 Paragraph const * Paragraph::outerHook() const
1213 return depthHook(depth_type(getDepth() - 1));
1217 Paragraph::inset_iterator
1218 Paragraph::InsetIterator(pos_type pos)
1220 InsetList::iterator it = insetlist.begin();
1221 InsetList::iterator end = insetlist.end();
1222 for (; it != end; ++it) {
1227 return inset_iterator(it);
1231 // returns -1 if inset not found
1232 int Paragraph::getPositionOfInset(Inset const * inset) const
1235 InsetList::const_iterator cit = insetlist.begin();
1236 InsetList::const_iterator end = insetlist.end();
1237 for (; cit != end; ++cit) {
1238 if (cit->inset == inset) {
1242 if (inset == bibkey)
1249 Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
1250 BufferParams const & bparams,
1251 ostream & os, TexRow & texrow,
1254 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1255 Inset const * in = inInset();
1256 bool further_blank_line = false;
1259 // well we have to check if we are in an inset with unlimited
1260 // lenght (all in one row) if that is true then we don't allow
1261 // any special options in the paragraph and also we don't allow
1262 // any environment other then "Standard" to be valid!
1263 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
1264 style = textclasslist[bparams.textclass][layout()];
1266 if (params().startOfAppendix()) {
1267 os << "\\appendix\n";
1271 if (!params().spacing().isDefault()
1272 && (!previous() || !previous()->hasSameLayout(this))) {
1273 os << params().spacing().writeEnvirBegin() << "\n";
1277 if (tex_code_break_column && style.isCommand()) {
1282 if (params().pagebreakTop()) {
1284 further_blank_line = true;
1286 if (params().spaceTop().kind() != VSpace::NONE) {
1287 os << params().spaceTop().asLatexCommand(bparams);
1288 further_blank_line = true;
1291 if (params().lineTop()) {
1292 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
1293 << "\\vspace{-1\\parskip}";
1294 further_blank_line = true;
1297 if (further_blank_line) {
1302 style = textclasslist[bparams.textclass].defaultLayout();
1305 Language const * language = getParLanguage(bparams);
1306 Language const * doc_language = bparams.language;
1307 Language const * previous_language = previous()
1308 ? previous()->getParLanguage(bparams) : doc_language;
1310 if (language->babel() != previous_language->babel()
1311 // check if we already put language command in TeXEnvironment()
1312 && !(style.isEnvironment()
1313 && (!previous() || previous()->layout() != layout() ||
1314 previous()->params().depth() != params().depth())))
1316 if (!lyxrc.language_command_end.empty() &&
1317 previous_language->babel() != doc_language->babel())
1319 os << subst(lyxrc.language_command_end, "$$lang",
1320 previous_language->babel())
1325 if (lyxrc.language_command_end.empty() ||
1326 language->babel() != doc_language->babel())
1328 os << subst(lyxrc.language_command_begin, "$$lang",
1335 if (bparams.inputenc == "auto" &&
1336 language->encoding() != previous_language->encoding()) {
1337 os << "\\inputencoding{"
1338 << language->encoding()->LatexName()
1343 switch (style.latextype) {
1346 << style.latexname()
1347 << style.latexparam();
1349 case LATEX_ITEM_ENVIRONMENT:
1351 bibkey->latex(buf, os, false, false);
1355 case LATEX_LIST_ENVIRONMENT:
1362 bool need_par = simpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
1364 // Make sure that \\par is done with the font of the last
1365 // character if this has another size as the default.
1366 // This is necessary because LaTeX (and LyX on the screen)
1367 // calculates the space between the baselines according
1368 // to this font. (Matthias)
1370 // Is this really needed ? (Dekel)
1371 // We do not need to use to change the font for the last paragraph
1372 // or for a command.
1373 LyXFont const font =
1375 ? getLayoutFont(bparams) : getFont(bparams, size() - 1));
1377 bool is_command = style.isCommand();
1379 if (style.resfont.size() != font.size() && next_ && !is_command) {
1382 os << "\\" << font.latexSize() << " \\par}";
1383 } else if (need_par) {
1385 } else if (is_command)
1388 switch (style.latextype) {
1389 case LATEX_ITEM_ENVIRONMENT:
1390 case LATEX_LIST_ENVIRONMENT:
1391 if (next_ && (params().depth() < next_->params().depth())) {
1396 case LATEX_ENVIRONMENT:
1397 // if its the last paragraph of the current environment
1398 // skip it otherwise fall through
1400 && (next_->layout() != layout()
1401 || next_->params().depth() != params().depth()))
1403 // fall through possible
1405 // we don't need it for the last paragraph!!!
1412 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
1413 further_blank_line = false;
1414 if (params().lineBottom()) {
1415 os << "\\lyxline{\\" << font.latexSize() << '}';
1416 further_blank_line = true;
1419 if (params().spaceBottom().kind() != VSpace::NONE) {
1420 os << params().spaceBottom().asLatexCommand(bparams);
1421 further_blank_line = true;
1424 if (params().pagebreakBottom()) {
1426 further_blank_line = true;
1429 if (further_blank_line) {
1434 if (!params().spacing().isDefault()
1435 && (!next_ || !next_->hasSameLayout(this))) {
1436 os << params().spacing().writeEnvirEnd() << "\n";
1441 // we don't need it for the last paragraph!!!
1446 // Since \selectlanguage write the language to the aux file,
1447 // we need to reset the language at the end of footnote or
1450 if (language->babel() != doc_language->babel()) {
1451 if (lyxrc.language_command_end.empty())
1452 os << subst(lyxrc.language_command_begin,
1454 doc_language->babel())
1457 os << subst(lyxrc.language_command_end,
1465 lyxerr[Debug::LATEX] << "TeXOnePar...done " << next_ << endl;
1469 // This could go to ParagraphParameters if we want to
1470 int Paragraph::startTeXParParams(BufferParams const & bparams,
1475 if (params().noindent()) {
1476 os << "\\noindent ";
1480 switch (params().align()) {
1481 case LYX_ALIGN_NONE:
1482 case LYX_ALIGN_BLOCK:
1483 case LYX_ALIGN_LAYOUT:
1484 case LYX_ALIGN_SPECIAL:
1486 case LYX_ALIGN_LEFT:
1487 if (getParLanguage(bparams)->babel() != "hebrew") {
1488 os << "\\begin{flushleft}";
1491 os << "\\begin{flushright}";
1495 case LYX_ALIGN_RIGHT:
1496 if (getParLanguage(bparams)->babel() != "hebrew") {
1497 os << "\\begin{flushright}";
1500 os << "\\begin{flushleft}";
1504 case LYX_ALIGN_CENTER:
1505 os << "\\begin{center}";
1513 // This could go to ParagraphParameters if we want to
1514 int Paragraph::endTeXParParams(BufferParams const & bparams,
1519 switch (params().align()) {
1520 case LYX_ALIGN_NONE:
1521 case LYX_ALIGN_BLOCK:
1522 case LYX_ALIGN_LAYOUT:
1523 case LYX_ALIGN_SPECIAL:
1525 case LYX_ALIGN_LEFT:
1526 if (getParLanguage(bparams)->babel() != "hebrew") {
1527 os << "\\end{flushleft}";
1530 os << "\\end{flushright}";
1534 case LYX_ALIGN_RIGHT:
1535 if (getParLanguage(bparams)->babel() != "hebrew") {
1536 os << "\\end{flushright}";
1539 os << "\\end{flushleft}";
1543 case LYX_ALIGN_CENTER:
1544 os << "\\end{center}";
1552 // This one spits out the text of the paragraph
1553 bool Paragraph::simpleTeXOnePar(Buffer const * buf,
1554 BufferParams const & bparams,
1555 ostream & os, TexRow & texrow,
1558 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
1560 bool return_value = false;
1564 // well we have to check if we are in an inset with unlimited
1565 // lenght (all in one row) if that is true then we don't allow
1566 // any special options in the paragraph and also we don't allow
1567 // any environment other then "Standard" to be valid!
1569 (inInset() && inInset()->forceDefaultParagraphs(inInset()));
1572 style = textclasslist[bparams.textclass].defaultLayout();
1574 style = textclasslist[bparams.textclass][layout()];
1579 // Maybe we have to create a optional argument.
1581 if (style.labeltype != LABEL_MANUAL)
1584 main_body = beginningOfMainBody();
1588 if (main_body > 0) {
1591 basefont = getLabelFont(bparams);
1593 basefont = getLayoutFont(bparams);
1596 moving_arg |= style.needprotect;
1598 // Which font is currently active?
1599 LyXFont running_font(basefont);
1600 // Do we have an open font change?
1601 bool open_font = false;
1603 texrow.start(this, 0);
1605 // if the paragraph is empty, the loop will not be entered at all
1607 if (style.isCommand()) {
1612 column += startTeXParParams(bparams, os);
1616 for (pos_type i = 0; i < size(); ++i) {
1618 // First char in paragraph or after label?
1619 if (i == main_body) {
1620 if (main_body > 0) {
1622 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1625 basefont = getLayoutFont(bparams);
1626 running_font = basefont;
1630 if (style.isCommand()) {
1636 column += startTeXParParams(bparams, os);
1639 value_type c = getChar(i);
1641 // Fully instantiated font
1642 LyXFont font = getFont(bparams, i);
1644 LyXFont const last_font = running_font;
1646 // Spaces at end of font change are simulated to be
1647 // outside font change, i.e. we write "\textXX{text} "
1648 // rather than "\textXX{text }". (Asger)
1649 if (open_font && c == ' ' && i <= size() - 2) {
1650 LyXFont const & next_font = getFont(bparams, i + 1);
1651 if (next_font != running_font
1652 && next_font != font) {
1657 // We end font definition before blanks
1659 (font != running_font ||
1660 font.language() != running_font.language()))
1662 column += running_font.latexWriteEndChanges(os,
1664 (i == main_body-1) ? basefont : font);
1665 running_font = basefont;
1669 // Blanks are printed before start of fontswitch
1671 // Do not print the separation of the optional argument
1672 if (i != main_body - 1) {
1673 pimpl_->simpleTeXBlanks(os, texrow, i,
1674 column, font, style);
1678 // Do we need to change font?
1679 if ((font != running_font ||
1680 font.language() != running_font.language()) &&
1683 column += font.latexWriteStartChanges(os, basefont,
1685 running_font = font;
1689 if (c == Paragraph::META_NEWLINE) {
1690 // newlines are handled differently here than
1691 // the default in SimpleTeXSpecialChars().
1692 if (!style.newline_allowed) {
1696 column += running_font.latexWriteEndChanges(os, basefont, basefont);
1699 basefont = getLayoutFont(bparams);
1700 running_font = basefont;
1701 if (font.family() ==
1702 LyXFont::TYPEWRITER_FAMILY) {
1710 texrow.start(this, i + 1);
1713 pimpl_->simpleTeXSpecialChars(buf, bparams,
1714 os, texrow, moving_arg,
1716 basefont, open_font,
1717 style, i, column, c);
1721 // If we have an open font definition, we have to close it
1723 #ifdef FIXED_LANGUAGE_END_DETECTION
1726 .latexWriteEndChanges(os, basefont,
1727 next_->getFont(bparams,
1730 running_font.latexWriteEndChanges(os, basefont,
1734 #ifdef WITH_WARNINGS
1735 //#warning For now we ALWAYS have to close the foreign font settings if they are
1736 //#warning there as we start another \selectlanguage with the next paragraph if
1737 //#warning we are in need of this. This should be fixed sometime (Jug)
1739 running_font.latexWriteEndChanges(os, basefont, basefont);
1743 // Needed if there is an optional argument but no contents.
1744 if (main_body > 0 && main_body == size()) {
1746 return_value = false;
1750 column += endTeXParParams(bparams, os);
1753 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
1754 return return_value;
1758 bool Paragraph::sgmlConvertChar(char c, string & sgml_string)
1760 bool retval = false;
1762 case Paragraph::META_HFILL:
1763 sgml_string.erase();
1765 case Paragraph::META_NEWLINE:
1769 sgml_string = "&";
1772 sgml_string = "<";
1775 sgml_string = ">";
1778 sgml_string = "$";
1781 sgml_string = "#";
1784 sgml_string = "%";
1787 sgml_string = "[";
1790 sgml_string = "]";
1793 sgml_string = "{";
1796 sgml_string = "}";
1799 sgml_string = "˜";
1802 sgml_string = """;
1805 sgml_string = "\";
1811 case '\0': // Ignore :-)
1812 sgml_string.erase();
1822 Paragraph * Paragraph::TeXEnvironment(Buffer const * buf,
1823 BufferParams const & bparams,
1824 ostream & os, TexRow & texrow)
1826 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
1828 LyXLayout const & style =
1829 textclasslist[bparams.textclass][layout()];
1831 Language const * language = getParLanguage(bparams);
1832 Language const * doc_language = bparams.language;
1833 Language const * previous_language = previous_
1834 ? previous_->getParLanguage(bparams) : doc_language;
1835 if (language->babel() != previous_language->babel()) {
1837 if (!lyxrc.language_command_end.empty() &&
1838 previous_language->babel() != doc_language->babel()) {
1839 os << subst(lyxrc.language_command_end, "$$lang",
1840 previous_language->babel())
1845 if (lyxrc.language_command_end.empty() ||
1846 language->babel() != doc_language->babel()) {
1847 os << subst(lyxrc.language_command_begin, "$$lang",
1854 bool leftindent_open = false;
1855 if (!params().leftIndent().zero()) {
1856 os << "\\begin{LyXParagraphLeftIndent}{" <<
1857 params().leftIndent().asLatexString() << "}\n";
1859 leftindent_open = true;
1862 if (style.isEnvironment()) {
1863 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
1864 os << "\\begin{" << style.latexname() << "}{"
1865 << params().labelWidthString() << "}\n";
1866 } else if (style.labeltype == LABEL_BIBLIO) {
1868 os << "\\begin{" << style.latexname() << "}{"
1869 << bibitemWidest(buf)
1871 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
1872 os << "\\begin{" << style.latexname() << '}'
1873 << style.latexparam() << '\n';
1875 os << "\\begin{" << style.latexname() << '}'
1876 << style.latexparam() << '\n';
1879 Paragraph * par = this;
1881 par = par->TeXOnePar(buf, bparams, os, texrow, false);
1883 if (par && par->params().depth() > params().depth()) {
1884 if (textclasslist[bparams.textclass][par->layout()].isParagraph()
1886 // How to handle this? (Lgb)
1887 //&& !suffixIs(os, "\n\n")
1889 // There should be at least one '\n' already
1890 // but we need there to be two for Standard
1891 // paragraphs that are depth-increment'ed to be
1892 // output correctly. However, tables can
1893 // also be paragraphs so don't adjust them.
1896 // Will it ever harm to have one '\n' too
1897 // many? i.e. that we sometimes will have
1898 // three in a row. (Lgb)
1902 par = par->pimpl_->TeXDeeper(buf, bparams, os, texrow);
1905 && par->layout() == layout()
1906 && par->params().depth() == params().depth()
1907 && par->params().leftIndent() == params().leftIndent());
1909 if (style.isEnvironment()) {
1910 os << "\\end{" << style.latexname() << "}\n";
1914 if (leftindent_open) {
1915 os << "\\end{LyXParagraphLeftIndent}\n";
1919 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
1920 return par; // ale970302
1924 bool Paragraph::isHfill(pos_type pos) const
1926 return IsHfillChar(getChar(pos));
1930 bool Paragraph::isInset(pos_type pos) const
1932 return IsInsetChar(getChar(pos));
1936 bool Paragraph::isNewline(pos_type pos) const
1938 return pos >= 0 && IsNewlineChar(getChar(pos));
1942 bool Paragraph::isSeparator(pos_type pos) const
1944 return IsSeparatorChar(getChar(pos));
1948 bool Paragraph::isLineSeparator(pos_type pos) const
1950 value_type const c = getChar(pos);
1951 return IsLineSeparatorChar(c)
1952 || (IsInsetChar(c) && getInset(pos) &&
1953 getInset(pos)->isLineSeparator());
1957 bool Paragraph::isKomma(pos_type pos) const
1959 return IsKommaChar(getChar(pos));
1963 /// Used by the spellchecker
1964 bool Paragraph::isLetter(pos_type pos) const
1966 value_type const c = getChar(pos);
1967 if (IsLetterChar(c))
1970 return getInset(pos)->isLetter();
1971 // We want to pass the ' and escape chars to ispell
1972 string const extra = lyxrc.isp_esc_chars + '\'';
1973 return contains(extra, c);
1977 bool Paragraph::isWord(pos_type pos) const
1979 return IsWordChar(getChar(pos)) ;
1984 Paragraph::getParLanguage(BufferParams const & bparams) const
1987 #ifndef INHERIT_LANGUAGE
1988 return getFirstFontSettings().language();
1990 Language const * lang = getFirstFontSettings().language();
1991 #ifdef WITH_WARNINGS
1992 #warning We should make this somewhat better, any ideas? (Jug)
1994 if (lang == inherit_language || lang == ignore_language)
1995 lang = bparams.language;
1998 } else if (previous_)
1999 return previous_->getParLanguage(bparams);
2001 return bparams.language;
2005 bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
2007 return lyxrc.rtl_support
2008 && getParLanguage(bparams)->RightToLeft()
2009 && !(inInset() && inInset()->owner() &&
2010 inInset()->owner()->lyxCode() == Inset::ERT_CODE);
2014 void Paragraph::changeLanguage(BufferParams const & bparams,
2015 Language const * from, Language const * to)
2017 for (pos_type i = 0; i < size(); ++i) {
2018 LyXFont font = getFontSettings(bparams, i);
2019 if (font.language() == from) {
2020 font.setLanguage(to);
2027 bool Paragraph::isMultiLingual(BufferParams const & bparams)
2029 Language const * doc_language = bparams.language;
2030 Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
2031 Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
2033 for (; cit != end; ++cit)
2034 if (cit->font().language() != ignore_language &&
2035 cit->font().language() != latex_language &&
2036 #ifdef INHERIT_LANGUAGE
2037 cit->font().language() != inherit_language &&
2039 cit->font().language() != doc_language)
2045 // Convert the paragraph to a string.
2046 // Used for building the table of contents
2047 string const Paragraph::asString(Buffer const * buffer, bool label)
2049 BufferParams const & bparams = buffer->params;
2051 if (label && !params().labelString().empty())
2052 s += params().labelString() + ' ';
2053 string::size_type const len = s.size();
2055 for (pos_type i = 0; i < size(); ++i) {
2056 value_type c = getChar(i);
2059 else if (c == META_INSET &&
2060 getInset(i)->lyxCode() == Inset::MATH_CODE) {
2062 getInset(i)->ascii(buffer, ost);
2063 s += subst(ost.str().c_str(),'\n',' ');
2067 if (isRightToLeftPar(bparams))
2068 reverse(s.begin() + len,s.end());
2074 string const Paragraph::asString(Buffer const * buffer,
2075 pos_type beg, pos_type end, bool label)
2079 if (beg == 0 && label && !params().labelString().empty())
2080 ost << params().labelString() << ' ';
2082 for (pos_type i = beg; i < end; ++i) {
2083 value_type const c = getUChar(buffer->params, i);
2086 else if (c == META_NEWLINE)
2088 else if (c == META_HFILL)
2090 else if (c == META_INSET) {
2091 getInset(i)->ascii(buffer, ost);
2095 return ost.str().c_str();
2099 void Paragraph::setInsetOwner(Inset * i)
2101 pimpl_->inset_owner = i;
2102 InsetList::const_iterator cit = insetlist.begin();
2103 InsetList::const_iterator end = insetlist.end();
2104 for (; cit != end; ++cit) {
2106 cit->inset->setOwner(i);
2111 void Paragraph::deleteInsetsLyXText(BufferView * bv)
2114 InsetList::const_iterator cit = insetlist.begin();
2115 InsetList::const_iterator end = insetlist.end();
2116 for (; cit != end; ++cit) {
2117 if (cit->inset && cit->inset->isTextInset()) {
2118 static_cast<UpdatableInset *>
2119 (cit->inset)->deleteLyXText(bv, true);
2125 void Paragraph::resizeInsetsLyXText(BufferView * bv)
2128 InsetList::const_iterator cit = insetlist.begin();
2129 InsetList::const_iterator end = insetlist.end();
2130 for (; cit != end; ++cit) {
2132 if (cit->inset->isTextInset()) {
2133 static_cast<UpdatableInset *>
2134 (cit->inset)->resizeLyXText(bv, true);
2141 void Paragraph::setContentsFromPar(Paragraph * par)
2143 pimpl_->setContentsFromPar(par);
2147 lyx::pos_type Paragraph::size() const
2149 return pimpl_->size();
2153 Paragraph::value_type Paragraph::getChar(pos_type pos) const
2155 return pimpl_->getChar(pos);
2159 int Paragraph::id() const
2165 void Paragraph::id(int id_arg)
2167 pimpl_->id_ = id_arg;
2171 string const & Paragraph::layout() const
2177 void Paragraph::layout(string const & new_layout)
2179 lyx::Assert(!new_layout.empty());
2181 layout_ = new_layout;
2185 bool Paragraph::isFirstInSequence() const
2187 Paragraph const * dhook = depthHook(getDepth());
2188 return (dhook == this
2189 || dhook->layout() != layout()
2190 || dhook->getDepth() != getDepth());
2194 Inset * Paragraph::inInset() const
2196 return pimpl_->inset_owner;
2200 void Paragraph::clearContents()
2206 void Paragraph::setCounter(int i, int v)
2208 pimpl_->counter_[i] = v;
2212 int Paragraph::getCounter(int i) const
2214 return pimpl_->counter_[i];
2218 void Paragraph::incCounter(int i)
2220 pimpl_->counter_[i]++;
2224 void Paragraph::setChar(pos_type pos, value_type c)
2226 pimpl_->setChar(pos, c);
2230 Paragraph::inset_iterator::inset_iterator(Paragraph::InsetList::iterator const & iter)
2235 Paragraph::inset_iterator Paragraph::inset_iterator_begin()
2237 return inset_iterator(insetlist.begin());
2241 Paragraph::inset_iterator Paragraph::inset_iterator_end()
2243 return inset_iterator(insetlist.end());
2247 ParagraphParameters & Paragraph::params()
2249 return pimpl_->params;
2253 ParagraphParameters const & Paragraph::params() const
2255 return pimpl_->params;
2259 Paragraph * Paragraph::getParFromID(int id) const
2261 return pimpl_->getParFromID(id);
2265 bool Paragraph::isFreeSpacing() const
2267 // for now we just need this, later should we need this in some
2268 // other way we can always add a function to Inset::() too.
2269 if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
2270 return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);