- /* create a new paragraph */
- LyXParagraph * result = new LyXParagraph;
-
- result->MakeSameLayout(this);
-
- /* this is because of the dummy layout of the paragraphs that
- follow footnotes */
- result->layout = layout;
-
- /* table stuff -- begin*/
- if (table)
- result->table = table->Clone();
- else
- result->table = 0;
- /* table stuff -- end*/
-
- // ale970302
- result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
-
-
- /* copy everything behind the break-position to the new paragraph */
-
-#ifdef NEW_TEXT
- result->text.reserve(size());
- for (size_type i = 0; i < size(); i++) {
- CopyIntoMinibuffer(i);
- result->InsertFromMinibuffer(i);
- }
-#else
- /* make shure there is enough memory for the now larger paragraph.
- * This is not neccessary, because InsertFromMinibuffer will enlarge
- * the memory (it uses InsertChar of course). But doing it by hand
- * is MUCH faster! (only one time, not thousend times!!) */
- result->Enlarge(0, last+2);
- for (int i = 0; i < last; i++) {
- CopyIntoMinibuffer(i);
- result->InsertFromMinibuffer(i);
- }
-#endif
- return result;
-}
-
-
-bool LyXParagraph::HasSameLayout(LyXParagraph * par)
-{
- par = par->FirstPhysicalPar();
-
- return (
- par->footnoteflag == footnoteflag &&
- par->footnotekind == footnotekind &&
-
- par->layout == layout &&
-
- par->align == align &&
-
- par->line_bottom == line_bottom &&
- par->pagebreak_bottom == pagebreak_bottom &&
- par->added_space_bottom == added_space_bottom &&
-
- par->line_top == line_top &&
- par->pagebreak_top == pagebreak_top &&
- par->added_space_top == added_space_top &&
-
- par->pextra_type == pextra_type &&
- par->pextra_width == pextra_width &&
- par->pextra_widthp == pextra_widthp &&
- par->pextra_alignment == pextra_alignment &&
- par->pextra_hfill == pextra_hfill &&
- par->pextra_start_minipage == pextra_start_minipage &&
-
- par->table == table && // what means: NO TABLE AT ALL
-
- par->noindent == noindent &&
- par->depth == depth);
-}
-
-#ifdef NEW_TEXT
-void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
-#else
-void LyXParagraph::BreakParagraphConservative(int pos)
-#endif
-{
-#ifdef NEW_TEXT
- size_type i, pos_end, pos_first;
-#else
- int i, pos_end, pos_first;
-#endif
-
- /* create a new paragraph */
- LyXParagraph * par = ParFromPos(pos);
-
- LyXParagraph * tmp = new LyXParagraph(par);
-
- tmp->MakeSameLayout(par);
-
- if (Last() > pos) {
- /* copy everything behind the break-position to the new
- paragraph */
- pos_first = 0;
- while (ParFromPos(pos_first) != par)
- pos_first++;
-#ifdef NEW_TEXT
- pos_end = pos_first + par->text.size() - 1;
-#else
- pos_end = pos_first + par->last - 1;
-#endif
- /* make shure there is enough memory for the now larger
- paragraph. This is not neccessary, because
- InsertFromMinibuffer will enlarge the memory (it uses
- InsertChar of course). But doing it by hand
- is MUCH faster! (only one time, not thousend times!!) */
-#ifdef NEW_TEXT
- tmp->text.reserve(pos_end - pos);
-#else
- tmp->Enlarge(0, pos_end - pos);
-#endif
- for (i = pos; i <= pos_end; i++) {
-
- par->CutIntoMinibuffer(i - pos_first);
- tmp->InsertFromMinibuffer(i - pos);
- }
- for (i = pos_end; i >= pos; i--)
- par->Erase(i - pos_first);
-#ifdef NEW_TEXT
- par->text.resize(par->text.size());
-#else
- /* free memory of the now shorter paragraph*/
- par->FitSize();
-#endif
- }
-}
-
-
-/* be carefull, this does not make any check at all */
-void LyXParagraph::PasteParagraph()
-{
- /* copy the next paragraph to this one */
- LyXParagraph * the_next = Next();
-
- LyXParagraph * firstpar = FirstPhysicalPar();
-
- /* first the DTP-stuff */
- firstpar->line_bottom = the_next->line_bottom;
- firstpar->added_space_bottom = the_next->added_space_bottom;
- firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
-
-#ifdef NEW_TEXT
- size_type pos_end = the_next->text.size() - 1;
- size_type pos_insert = Last();
- size_type i;
-#else
- int pos_end = the_next->last - 1;
- int pos_insert = Last();
- /* enlarge the paragraph. This is faster than enlarge it
- * every 10th insertion. */
- if (pos_end >= 0)
- Enlarge(pos_insert, pos_end);
- int i;
-#endif
-
- /* ok, now copy the paragraph */
- for (i = 0; i <= pos_end; i++) {
- the_next->CutIntoMinibuffer(i);
- InsertFromMinibuffer(pos_insert + i);
- }
-
- /* delete the next paragraph */
- delete the_next;
-}
-
-#ifdef NEW_TEXT
-void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
-#else
-void LyXParagraph::OpenFootnote(int pos)
-#endif
-{
- LyXParagraph * par = ParFromPos(pos);
- par = par->next;
- while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
- par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
- par = par->next;
- }
-}
-
-#ifdef NEW_TEXT
-void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
-#else
-void LyXParagraph::CloseFootnote(int pos)
-#endif
-{
- LyXParagraph * par = ParFromPos(pos);
- par = par->next;
- while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
- par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
- par = par->next;
- }
-}
-
-
-LyXTextClass::LayoutList::size_type LyXParagraph::GetLayout()
-{
- return FirstPhysicalPar()->layout;
-}
-
-
-char LyXParagraph::GetDepth()
-{
- return FirstPhysicalPar()->depth;
-}
-
-
-char LyXParagraph::GetAlign()
-{
- return FirstPhysicalPar()->align;
-}
-
-
-string LyXParagraph::GetLabestring()
-{
- return FirstPhysicalPar()->labelstring;
-}
-
-
-int LyXParagraph::GetFirstCounter(int i)
-{
- return FirstPhysicalPar()->counter[i];
-}
-
-
-/* the next two functions are for the manual labels */
-string LyXParagraph::GetLabelWidthString()
-{
- if (!FirstPhysicalPar()->labelwidthstring.empty())
- return FirstPhysicalPar()->labelwidthstring;
- else
- return _("Senseless with this layout!");
-}
-
-
-void LyXParagraph::SetLabelWidthString(string const & s)
-{
- LyXParagraph * par = FirstPhysicalPar();
-
- par->labelwidthstring = s;
-}
-
-
-void LyXParagraph::SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout)
-{
- LyXParagraph * par = FirstPhysicalPar();
- LyXParagraph * ppar = 0;
- LyXParagraph * npar = 0;
-
- par->layout = new_layout;
- /* table stuff -- begin*/
- if (table)
- par->layout = 0;
- /* table stuff -- end*/
- if (par->pextra_type == PEXTRA_NONE) {
- if (par->Previous()) {
- ppar = par->Previous()->FirstPhysicalPar();
- while(ppar
- && ppar->Previous()
- && (ppar->depth > par->depth))
- ppar = ppar->Previous()->FirstPhysicalPar();
- }
- if (par->Next()) {
- npar = par->Next()->NextAfterFootnote();
- while(npar
- && npar->Next()
- && (npar->depth > par->depth))
- npar = npar->Next()->NextAfterFootnote();
- }
- if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
- string
- p1 = ppar->pextra_width,
- p2 = ppar->pextra_widthp;
- ppar->SetPExtraType(ppar->pextra_type,
- p1.c_str(),p2.c_str());
- }
- if ((par->pextra_type == PEXTRA_NONE) &&
- npar && (npar->pextra_type != PEXTRA_NONE)) {
- string
- p1 = npar->pextra_width,
- p2 = npar->pextra_widthp;
- npar->SetPExtraType(npar->pextra_type,
- p1.c_str(),p2.c_str());
- }
- }
-}
-
-
-void LyXParagraph::SetLayout(LyXTextClass::LayoutList::size_type new_layout)
-{
- LyXParagraph
- * par = FirstPhysicalPar(),
- * ppar = 0,
- * npar = 0;
-
- par->layout = new_layout;
- par->labelwidthstring.clear();
- par->align = LYX_ALIGN_LAYOUT;
- par->added_space_top = VSpace(VSpace::NONE);
- par->added_space_bottom = VSpace(VSpace::NONE);
- /* table stuff -- begin*/
- if (table)
- par->layout = 0;
- /* table stuff -- end*/
- if (par->pextra_type == PEXTRA_NONE) {
- if (par->Previous()) {
- ppar = par->Previous()->FirstPhysicalPar();
- while(ppar
- && ppar->Previous()
- && (ppar->depth > par->depth))
- ppar = ppar->Previous()->FirstPhysicalPar();
- }
- if (par->Next()) {
- npar = par->Next()->NextAfterFootnote();
- while(npar
- && npar->Next()
- && (npar->depth > par->depth))
- npar = npar->Next()->NextAfterFootnote();
- }
- if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
- string
- p1 = ppar->pextra_width,
- p2 = ppar->pextra_widthp;
- ppar->SetPExtraType(ppar->pextra_type,
- p1.c_str(),p2.c_str());
- }
- if ((par->pextra_type == PEXTRA_NONE) &&
- npar && (npar->pextra_type != PEXTRA_NONE)) {
- string
- p1 = npar->pextra_width,
- p2 = npar->pextra_widthp;
- npar->SetPExtraType(npar->pextra_type,
- p1.c_str(),p2.c_str());
- }
- }
-}
-
-
-/* if the layout of a paragraph contains a manual label, the beginning of the
-* main body is the beginning of the second word. This is what the par-
-* function returns. If the layout does not contain a label, the main
-* body always starts with position 0. This differentiation is necessary,
-* because there cannot be a newline or a blank <= the beginning of the
-* main body in TeX. */
-
-int LyXParagraph::BeginningOfMainBody()
-{
- if (FirstPhysicalPar() != this)
- return -1;
-
-
-// Unroll the first two cycles of the loop
-// and remember the previous character to remove unnecessary GetChar() calls
-#ifdef NEW_TEXT
- size_type i = 0;