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 * ====================================================== */
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 // remember to set the inset_owner
32 tmp->setInsetOwner(par->inInset());
34 // this is an idea for a more userfriendly layout handling, I will
35 // see what the users say
37 // layout stays the same with latex-environments
39 tmp->layout(par->layout());
40 tmp->setLabelWidthString(par->params().labelWidthString());
43 bool isempty = (par->layout()->keepempty && par->empty());
45 if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
46 tmp->layout(par->layout());
47 tmp->params().align(par->params().align());
48 tmp->setLabelWidthString(par->params().labelWidthString());
50 tmp->params().lineBottom(par->params().lineBottom());
51 par->params().lineBottom(false);
52 tmp->params().pagebreakBottom(par->params().pagebreakBottom());
53 par->params().pagebreakBottom(false);
54 tmp->params().spaceBottom(par->params().spaceBottom());
55 par->params().spaceBottom(VSpace(VSpace::NONE));
57 tmp->params().depth(par->params().depth());
58 tmp->params().noindent(par->params().noindent());
60 // copy everything behind the break-position
61 // to the new paragraph
62 pos_type pos_end = par->size() - 1;
65 for (; i <= pos_end; ++i) {
66 par->cutIntoMinibuffer(bparams, i);
67 if (tmp->insertFromMinibuffer(j - pos))
70 for (i = pos_end; i >= pos; --i) {
77 tmp->params().lineTop(par->params().lineTop());
78 tmp->params().pagebreakTop(par->params().pagebreakTop());
79 tmp->params().spaceTop(par->params().spaceTop());
80 tmp->bibkey = par->bibkey;
83 par->params().clear();
85 par->layout(bparams.getLyXTextClass().defaultLayout());
87 // layout stays the same with latex-environments
89 par->layout(tmp->layout());
90 par->setLabelWidthString(tmp->params().labelWidthString());
91 par->params().depth(tmp->params().depth());
97 void breakParagraphConservative(BufferParams const & bparams,
101 // create a new paragraph
102 Paragraph * tmp = new Paragraph(par);
103 tmp->makeSameLayout(par);
105 // When can pos > Last()?
106 // I guess pos == Last() is possible.
107 if (par->size() > pos) {
108 // copy everything behind the break-position to the new
110 pos_type pos_end = par->size() - 1;
112 for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
113 par->cutIntoMinibuffer(bparams, i);
114 if (tmp->insertFromMinibuffer(j - pos))
118 for (pos_type k = pos_end; k >= pos; --k) {
126 // Be carefull, this does not make any check at all.
127 // This method has wrong name, it combined this par with the next par.
128 // In that sense it is the reverse of break paragraph. (Lgb)
129 void pasteParagraph(BufferParams const & bparams,
132 // copy the next paragraph to this one
133 Paragraph * the_next = par->next();
135 // first the DTP-stuff
136 par->params().lineBottom(the_next->params().lineBottom());
137 par->params().spaceBottom(the_next->params().spaceBottom());
138 par->params().pagebreakBottom(the_next->params().pagebreakBottom());
140 pos_type pos_end = the_next->size() - 1;
141 pos_type pos_insert = par->size();
143 // ok, now copy the paragraph
144 for (pos_type i = 0, j = 0; i <= pos_end; ++i) {
145 the_next->cutIntoMinibuffer(bparams, i);
146 if (par->insertFromMinibuffer(pos_insert + j))
150 // delete the next paragraph
151 Paragraph * ppar = the_next->previous();
152 Paragraph * npar = the_next->next();
158 Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth)
160 Paragraph * newpar = par;
163 newpar = newpar->previous();
164 } while (newpar && newpar->getDepth() > depth);
167 if (par->previous() || par->getDepth())
168 lyxerr << "Error (depthHook): "
169 << "no hook." << endl;
176 Paragraph * outerHook(Paragraph * par)
178 if (!par->getDepth())
180 return depthHook(par, Paragraph::depth_type(par->getDepth() - 1));
184 bool isFirstInSequence(Paragraph * par)
186 Paragraph const * dhook = depthHook(par, par->getDepth());
188 || dhook->getLayout() != par->getLayout()
189 || dhook->getDepth() != par->getDepth());
193 int getEndLabel(Paragraph * para, BufferParams const & bparams)
195 Paragraph * par = para;
197 Paragraph::depth_type par_depth = par->getDepth();
198 layout_type layout = par->getLayout();
199 int const endlabeltype =
200 textclasslist.Style(bparams.textclass,
201 layout).endlabeltype;
202 if (endlabeltype != END_LABEL_NO_LABEL) {
206 Paragraph::depth_type const next_depth =
207 para->next()->getDepth();
208 if (par_depth > next_depth ||
209 (par_depth == next_depth
210 && layout != para->next()->getLayout()))
216 par = outerHook(par);
218 return END_LABEL_NO_LABEL;