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
67 #warning this seems wrong
69 /* FIXME: if !keepempty, empty() == true, then we reach
70 * here with size() == 0. So pos_end becomes - 1. Why
71 * doesn't this cause problems ???
73 pos_type pos_end = par->size() - 1;
76 for (; i <= pos_end; ++i) {
77 par->cutIntoMinibuffer(bparams, i);
78 if (tmp->insertFromMinibuffer(j - pos))
81 for (i = pos_end; i >= pos; --i) {
89 tmp->params().lineTop(par->params().lineTop());
90 tmp->params().pagebreakTop(par->params().pagebreakTop());
91 tmp->params().spaceTop(par->params().spaceTop());
92 tmp->bibkey = par->bibkey;
95 par->params().clear();
97 par->layout(bparams.getLyXTextClass().defaultLayout());
99 // layout stays the same with latex-environments
101 par->layout(tmp->layout());
102 par->setLabelWidthString(tmp->params().labelWidthString());
103 par->params().depth(tmp->params().depth());
108 void breakParagraphConservative(BufferParams const & bparams,
112 // create a new paragraph
113 Paragraph * tmp = new Paragraph(par);
114 tmp->makeSameLayout(par);
116 // When can pos > Last()?
117 // I guess pos == Last() is possible.
118 if (par->size() > pos) {
119 // copy everything behind the break-position to the new
121 pos_type pos_end = par->size() - 1;
123 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
124 par->cutIntoMinibuffer(bparams, i);
125 if (tmp->insertFromMinibuffer(j - pos))
129 for (pos_type k = pos_end; k >= pos; --k) {
136 void mergeParagraph(BufferParams const & bparams, Paragraph * par)
138 Paragraph * the_next = par->next();
140 // first the DTP-stuff
141 par->params().lineBottom(the_next->params().lineBottom());
142 par->params().spaceBottom(the_next->params().spaceBottom());
143 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
145 pos_type pos_end = the_next->size() - 1;
146 pos_type pos_insert = par->size();
148 // ok, now copy the paragraph
149 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
150 the_next->cutIntoMinibuffer(bparams, i);
151 if (par->insertFromMinibuffer(pos_insert + j))
155 // delete the next paragraph
156 Paragraph * ppar = the_next->previous();
157 Paragraph * npar = the_next->next();
164 Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth)
166 Paragraph * newpar = par;
169 newpar = newpar->previous();
170 } while (newpar && newpar->getDepth() > depth);
173 if (par->previous() || par->getDepth())
174 lyxerr << "Error (depthHook): "
175 << "no hook." << endl;
182 Paragraph * outerHook(Paragraph * par)
184 if (!par->getDepth())
186 return depthHook(par, Paragraph::depth_type(par->getDepth() - 1));
190 bool isFirstInSequence(Paragraph * par)
192 Paragraph const * dhook = depthHook(par, par->getDepth());
194 || dhook->getLayout() != par->getLayout()
195 || dhook->getDepth() != par->getDepth());
199 int getEndLabel(Paragraph * para, BufferParams const & bparams)
201 Paragraph * par = para;
203 Paragraph::depth_type par_depth = par->getDepth();
204 layout_type layout = par->getLayout();
205 int const endlabeltype =
206 textclasslist.Style(bparams.textclass,
207 layout).endlabeltype;
208 if (endlabeltype != END_LABEL_NO_LABEL) {
212 Paragraph::depth_type const next_depth =
213 para->next()->getDepth();
214 if (par_depth > next_depth ||
215 (par_depth == next_depth
216 && layout != para->next()->getLayout()))
222 par = outerHook(par);
224 return END_LABEL_NO_LABEL;