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 // Be carefull, this does not make any check at all.
129 // This method has wrong name, it combined this par with the next par.
130 // In that sense it is the reverse of break paragraph. (Lgb)
131 void pasteParagraph(BufferParams const & bparams,
134 // copy the next paragraph to this one
135 Paragraph * the_next = par->next();
137 // first the DTP-stuff
138 par->params().lineBottom(the_next->params().lineBottom());
139 par->params().spaceBottom(the_next->params().spaceBottom());
140 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
142 pos_type pos_end = the_next->size() - 1;
143 pos_type pos_insert = par->size();
145 // ok, now copy the paragraph
146 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
147 the_next->cutIntoMinibuffer(bparams, i);
148 if (par->insertFromMinibuffer(pos_insert + j))
152 // delete the next paragraph
153 Paragraph * ppar = the_next->previous();
154 Paragraph * npar = the_next->next();
161 Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth)
163 Paragraph * newpar = par;
166 newpar = newpar->previous();
167 } while (newpar && newpar->getDepth() > depth);
170 if (par->previous() || par->getDepth())
171 lyxerr << "Error (depthHook): "
172 << "no hook." << endl;
179 Paragraph * outerHook(Paragraph * par)
181 if (!par->getDepth())
183 return depthHook(par, Paragraph::depth_type(par->getDepth() - 1));
187 bool isFirstInSequence(Paragraph * par)
189 Paragraph const * dhook = depthHook(par, par->getDepth());
191 || dhook->getLayout() != par->getLayout()
192 || dhook->getDepth() != par->getDepth());
196 int getEndLabel(Paragraph * para, BufferParams const & bparams)
198 Paragraph * par = para;
200 Paragraph::depth_type par_depth = par->getDepth();
201 layout_type layout = par->getLayout();
202 int const endlabeltype =
203 textclasslist.Style(bparams.textclass,
204 layout).endlabeltype;
205 if (endlabeltype != END_LABEL_NO_LABEL) {
209 Paragraph::depth_type const next_depth =
210 para->next()->getDepth();
211 if (par_depth > next_depth ||
212 (par_depth == next_depth
213 && layout != para->next()->getLayout()))
219 par = outerHook(par);
221 return END_LABEL_NO_LABEL;