2 * \file paragraph_funcs.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS
13 #include "paragraph_funcs.h"
15 #include "ParagraphParameters.h"
16 #include "lyxtextclasslist.h"
20 //using lyx::layout_type;
24 void breakParagraph(BufferParams const & bparams,
29 // create a new paragraph
30 Paragraph * tmp = new Paragraph(par);
31 // without doing that we get a crash when typing <Return> at the
33 tmp->layout(bparams.getLyXTextClass().defaultLayout());
34 // remember to set the inset_owner
35 tmp->setInsetOwner(par->inInset());
37 // this is an idea for a more userfriendly layout handling, I will
38 // see what the users say
40 // layout stays the same with latex-environments
42 tmp->layout(par->layout());
43 tmp->setLabelWidthString(par->params().labelWidthString());
46 bool const isempty = (par->layout()->keepempty && par->empty());
48 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
49 tmp->layout(par->layout());
50 tmp->params().align(par->params().align());
51 tmp->setLabelWidthString(par->params().labelWidthString());
53 tmp->params().lineBottom(par->params().lineBottom());
54 par->params().lineBottom(false);
55 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
56 par->params().pagebreakBottom(false);
57 tmp->params().spaceBottom(par->params().spaceBottom());
58 par->params().spaceBottom(VSpace(VSpace::NONE));
60 tmp->params().depth(par->params().depth());
61 tmp->params().noindent(par->params().noindent());
63 // copy everything behind the break-position
64 // to the new paragraph
65 pos_type pos_end = par->size() - 1;
68 for (; i <= pos_end; ++i) {
69 par->cutIntoMinibuffer(bparams, i);
70 if (tmp->insertFromMinibuffer(j - pos))
73 for (i = pos_end; i >= pos; --i) {
81 tmp->params().lineTop(par->params().lineTop());
82 tmp->params().pagebreakTop(par->params().pagebreakTop());
83 tmp->params().spaceTop(par->params().spaceTop());
84 tmp->bibkey = par->bibkey;
87 par->params().clear();
89 par->layout(bparams.getLyXTextClass().defaultLayout());
91 // layout stays the same with latex-environments
93 par->layout(tmp->layout());
94 par->setLabelWidthString(tmp->params().labelWidthString());
95 par->params().depth(tmp->params().depth());
100 void breakParagraphConservative(BufferParams const & bparams,
104 // create a new paragraph
105 Paragraph * tmp = new Paragraph(par);
106 tmp->makeSameLayout(par);
108 // When can pos > Last()?
109 // I guess pos == Last() is possible.
110 if (par->size() > pos) {
111 // copy everything behind the break-position to the new
113 pos_type pos_end = par->size() - 1;
115 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
116 par->cutIntoMinibuffer(bparams, i);
117 if (tmp->insertFromMinibuffer(j - pos))
121 for (pos_type k = pos_end; k >= pos; --k) {
128 void mergeParagraph(BufferParams const & bparams, Paragraph * par)
130 Paragraph * the_next = par->next();
132 // first the DTP-stuff
133 par->params().lineBottom(the_next->params().lineBottom());
134 par->params().spaceBottom(the_next->params().spaceBottom());
135 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
137 pos_type pos_end = the_next->size() - 1;
138 pos_type pos_insert = par->size();
140 // ok, now copy the paragraph
141 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
142 the_next->cutIntoMinibuffer(bparams, i);
143 if (par->insertFromMinibuffer(pos_insert + j))
147 // delete the next paragraph
148 Paragraph * ppar = the_next->previous();
149 Paragraph * npar = the_next->next();
156 Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth)
158 Paragraph * newpar = par;
161 newpar = newpar->previous();
162 } while (newpar && newpar->getDepth() > depth);
165 if (par->previous() || par->getDepth())
166 lyxerr << "Error (depthHook): "
167 << "no hook." << endl;
174 Paragraph * outerHook(Paragraph * par)
176 if (!par->getDepth())
178 return depthHook(par, Paragraph::depth_type(par->getDepth() - 1));
182 bool isFirstInSequence(Paragraph * par)
184 Paragraph const * dhook = depthHook(par, par->getDepth());
186 || dhook->getLayout() != par->getLayout()
187 || dhook->getDepth() != par->getDepth());
191 int getEndLabel(Paragraph * para, BufferParams const & bparams)
193 Paragraph * par = para;
195 Paragraph::depth_type par_depth = par->getDepth();
196 layout_type layout = par->getLayout();
197 int const endlabeltype =
198 textclasslist.Style(bparams.textclass,
199 layout).endlabeltype;
200 if (endlabeltype != END_LABEL_NO_LABEL) {
204 Paragraph::depth_type const next_depth =
205 para->next()->getDepth();
206 if (par_depth > next_depth ||
207 (par_depth == next_depth
208 && layout != para->next()->getLayout()))
214 par = outerHook(par);
216 return END_LABEL_NO_LABEL;