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 * ====================================================== */
15 #include "paragraph.h"
17 #include "bufferparams.h"
23 #include "frontends/LyXView.h"
24 #include "frontends/Painter.h"
25 #include "frontends/font_metrics.h"
26 #include "frontends/screen.h"
27 #include "frontends/WorkArea.h"
28 #include "bufferview_funcs.h"
29 #include "BufferView.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "WordLangTuple.h"
34 #include "paragraph_funcs.h"
35 #include "rowpainter.h"
36 #include "lyxrow_funcs.h"
38 #include "insets/insettext.h"
40 #include "support/textutils.h"
41 #include "support/LAssert.h"
42 #include "support/lstrings.h"
51 using namespace bv_funcs;
53 /// top, right, bottom pixel margin
54 extern int const PAPER_MARGIN = 20;
55 /// margin for changebar
56 extern int const CHANGEBAR_MARGIN = 10;
58 extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
60 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
63 BufferView * LyXText::bv()
65 lyx::Assert(bv_owner != 0);
70 BufferView * LyXText::bv() const
72 lyx::Assert(bv_owner != 0);
77 int LyXText::top_y() const
79 if (anchor_row_ == rowlist_.end())
84 RowList::iterator rit = rowlist_.begin();
85 RowList::iterator end = rowlist_.end();
86 for (; rit != end && rit != anchor_row_; ++rit) {
89 return y + anchor_row_offset_;
93 void LyXText::top_y(int newy)
97 lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
100 RowList::iterator rit = getRowNearY(y);
102 if (rit == anchor_row_ && anchor_row_offset_ == newy - y) {
103 lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
108 anchor_row_offset_ = newy - y;
109 lyxerr[Debug::GUI] << "changing reference to row: " << &*anchor_row_
110 << " offset: " << anchor_row_offset_ << endl;
115 void LyXText::anchor_row(RowList::iterator rit)
118 anchor_row_offset_ = 0;
120 anchor_row_offset_ = old_y - top_y();
121 lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
122 << &*anchor_row_ << " offset: "
123 << anchor_row_offset_ << endl;
127 int LyXText::workWidth() const
130 // FIXME: pass (const ?) ref
131 return inset_owner->textWidth(bv());
133 return bv()->workWidth();
137 int LyXText::workWidth(Inset * inset) const
139 Paragraph * par = inset->parOwner();
142 pos_type pos = par->getPositionOfInset(inset);
143 lyx::Assert(pos != -1);
145 LyXLayout_ptr const & layout = par->layout();
147 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
148 // Optimization here: in most cases, the real row is
149 // not needed, but only the par/pos values. So we just
150 // construct a dummy row for leftMargin. (JMarc)
154 return workWidth() - leftMargin(dummyrow);
157 RowList::iterator row = getRow(par, pos, dummy_y);
158 RowList::iterator frow = row;
159 RowList::iterator beg = rowlist_.begin();
161 while (frow != beg && frow->par() == boost::prior(frow)->par())
164 // FIXME: I don't understand this code - jbl
166 unsigned int maxw = 0;
167 while (!isParEnd(*this, frow)) {
168 if ((frow != row) && (maxw < frow->width()))
169 maxw = frow->width();
180 int LyXText::getRealCursorX() const
183 if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
184 x = the_locking_inset->getLyXText(bv())->getRealCursorX();
189 unsigned char LyXText::transformChar(unsigned char c, Paragraph * par,
192 if (!Encodings::is_arabic(c))
193 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
194 return c + (0xb0 - '0');
198 unsigned char const prev_char = pos > 0 ? par->getChar(pos-1) : ' ';
199 unsigned char next_char = ' ';
201 for (pos_type i = pos+1; i < par->size(); ++i)
202 if (!Encodings::IsComposeChar_arabic(par->getChar(i))) {
203 next_char = par->getChar(i);
207 if (Encodings::is_arabic(next_char)) {
208 if (Encodings::is_arabic(prev_char) &&
209 !Encodings::is_arabic_special(prev_char))
210 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
212 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
214 if (Encodings::is_arabic(prev_char) &&
215 !Encodings::is_arabic_special(prev_char))
216 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
218 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
222 // This is the comments that some of the warnings below refers to.
223 // There are some issues in this file and I don't think they are
224 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
225 // this is a problem that has been here almost from day one and that a
226 // larger userbase with differenct access patters triggers the bad
227 // behaviour. (segfaults.) What I think happen is: In several places
228 // we store the paragraph in the current cursor and then moves the
229 // cursor. This movement of the cursor will delete paragraph at the
230 // old position if it is now empty. This will make the temporary
231 // pointer to the old cursor paragraph invalid and dangerous to use.
232 // And is some cases this will trigger a segfault. I have marked some
233 // of the cases where this happens with a warning, but I am sure there
234 // are others in this file and in text2.C. There is also a note in
235 // Delete() that you should read. In Delete I store the paragraph->id
236 // instead of a pointer to the paragraph. I am pretty sure this faulty
237 // use of temporary pointers to paragraphs that might have gotten
238 // invalidated (through a cursor movement) before they are used, are
239 // the cause of the strange crashes we get reported often.
241 // It is very tiresom to change this code, especially when it is as
242 // hard to read as it is. Help to fix all the cases where this is done
243 // would be greately appreciated.
247 #warning FIXME Convert this to ParagraphList::iterator
248 int LyXText::singleWidth(Paragraph * par,
251 if (pos >= par->size())
254 char const c = par->getChar(pos);
255 return singleWidth(par, pos, c);
259 #warning FIXME Convert this to ParagraphList::iterator
260 int LyXText::singleWidth(Paragraph * par,
261 pos_type pos, char c) const
263 if (pos >= par->size())
266 LyXFont const font = getFont(bv()->buffer(), par, pos);
268 // The most common case is handled first (Asger)
269 if (IsPrintable(c)) {
270 if (font.language()->RightToLeft()) {
271 if (font.language()->lang() == "arabic" &&
272 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
273 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
274 if (Encodings::IsComposeChar_arabic(c))
277 c = transformChar(c, par, pos);
278 } else if (font.language()->lang() == "hebrew" &&
279 Encodings::IsComposeChar_hebrew(c))
282 return font_metrics::width(c, font);
286 if (c == Paragraph::META_INSET) {
287 Inset * tmpinset = par->getInset(pos);
289 if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
290 // Because of the representation as vertical lines
294 #warning inset->update FIXME
295 // this IS needed otherwise on initialitation we don't get the fill
296 // of the row right (ONLY on initialization if we read a file!)
297 // should be changed! (Jug 20011204)
298 tmpinset->update(bv());
300 return tmpinset->width(bv(), font);
305 if (IsSeparatorChar(c))
307 return font_metrics::width(c, font);
311 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
313 if (bidi_start == -1)
316 return log2vis_list[pos - bidi_start];
320 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
322 if (bidi_start == -1)
325 return vis2log_list[pos - bidi_start];
329 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
331 if (bidi_start == -1)
334 return bidi_levels[pos - bidi_start];
338 bool LyXText::bidi_InRange(lyx::pos_type pos) const
340 return bidi_start == -1 ||
341 (bidi_start <= pos && pos <= bidi_end);
345 void LyXText::computeBidiTables(Buffer const * buf,
346 RowList::iterator row) const
348 bidi_same_direction = true;
349 if (!lyxrc.rtl_support) {
354 Inset * inset = row->par()->inInset();
355 if (inset && inset->owner() &&
356 inset->owner()->lyxCode() == Inset::ERT_CODE) {
361 bidi_start = row->pos();
362 bidi_end = lastPrintablePos(*this, row);
364 if (bidi_start > bidi_end) {
369 if (bidi_end + 2 - bidi_start >
370 static_cast<pos_type>(log2vis_list.size())) {
372 (bidi_end + 2 - bidi_start < 500) ?
373 500 : 2 * (bidi_end + 2 - bidi_start);
374 log2vis_list.resize(new_size);
375 vis2log_list.resize(new_size);
376 bidi_levels.resize(new_size);
379 vis2log_list[bidi_end + 1 - bidi_start] = -1;
380 log2vis_list[bidi_end + 1 - bidi_start] = -1;
384 row->par()->isRightToLeftPar(buf->params);
388 pos_type const body_pos = row->par()->beginningOfBody();
390 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
391 bool is_space = row->par()->isLineSeparator(lpos);
393 (is_space && lpos + 1 <= bidi_end &&
394 !row->par()->isLineSeparator(lpos + 1) &&
395 !row->par()->isNewline(lpos + 1))
397 LyXFont font = row->par()->getFontSettings(buf->params, pos);
398 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
399 font.number() == LyXFont::ON &&
400 row->par()->getFontSettings(buf->params, lpos - 1).number()
402 font = row->par()->getFontSettings(buf->params, lpos);
407 bool new_rtl = font.isVisibleRightToLeft();
408 bool new_rtl0 = font.isRightToLeft();
411 if (lpos == body_pos - 1
412 && row->pos() < body_pos - 1
414 new_level = (rtl_par) ? 1 : 0;
415 new_rtl = new_rtl0 = rtl_par;
417 new_level = (new_rtl) ? 1 : 2;
419 new_level = (rtl_par) ? 2 : 0;
421 if (is_space && new_level >= level) {
427 int new_level2 = new_level;
429 if (level == new_level && rtl0 != new_rtl0) {
431 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
432 } else if (level < new_level) {
433 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
434 if (new_level > rtl_par)
435 bidi_same_direction = false;
437 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
440 bidi_levels[lpos - bidi_start] = new_level;
442 while (level > new_level2) {
443 pos_type old_lpos = stack[--level];
444 int delta = lpos - old_lpos - 1;
447 log2vis_list[lpos - bidi_start] += delta;
448 log2vis_list[old_lpos - bidi_start] += delta;
450 while (level < new_level)
451 stack[level++] = lpos;
455 pos_type const old_lpos = stack[--level];
456 int delta = bidi_end - old_lpos;
459 log2vis_list[old_lpos - bidi_start] += delta;
462 pos_type vpos = bidi_start - 1;
463 for (pos_type lpos = bidi_start;
464 lpos <= bidi_end; ++lpos) {
465 vpos += log2vis_list[lpos - bidi_start];
466 vis2log_list[vpos - bidi_start] = lpos;
467 log2vis_list[lpos - bidi_start] = vpos;
472 // This method requires a previous call to ComputeBidiTables()
473 bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
476 if (!lyxrc.rtl_support || pos == 0)
479 if (!bidi_InRange(pos - 1)) {
480 /// This can happen if pos is the first char of a row.
481 /// Returning false in this case is incorrect!
485 bool const rtl = bidi_level(pos - 1) % 2;
486 bool const rtl2 = bidi_InRange(pos)
487 ? bidi_level(pos) % 2
488 : par->isRightToLeftPar(buf->params);
493 bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
494 pos_type pos, LyXFont const & font) const
496 if (!lyxrc.rtl_support)
497 return false; // This is just for speedup
499 bool const rtl = font.isVisibleRightToLeft();
500 bool const rtl2 = bidi_InRange(pos)
501 ? bidi_level(pos) % 2
502 : par->isRightToLeftPar(buf->params);
507 int LyXText::leftMargin(Row const & row) const
511 if (row.pos() < row.par()->size())
512 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
513 (ins = row.par()->getInset(row.pos())) &&
514 (ins->needFullRow() || ins->display()))
517 LyXTextClass const & tclass =
518 bv()->buffer()->params.getLyXTextClass();
519 LyXLayout_ptr const & layout = row.par()->layout();
521 string parindent = layout->parindent;
525 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
527 // this is the way, LyX handles the LaTeX-Environments.
528 // I have had this idea very late, so it seems to be a
529 // later added hack and this is true
530 if (!row.par()->getDepth()) {
531 if (row.par()->layout() == tclass.defaultLayout()) {
532 // find the previous same level paragraph
533 if (row.par()->previous()) {
534 Paragraph * newpar = row.par()
535 ->depthHook(row.par()->getDepth());
537 newpar->layout()->nextnoindent)
542 // find the next level paragraph
544 Paragraph * newpar = row.par()->outerHook();
546 // make a corresponding row. Needed to call leftMargin()
548 // check wether it is a sufficent paragraph
549 if (newpar && newpar->layout()->isEnvironment()) {
551 dummyrow.par(newpar);
552 dummyrow.pos(newpar->size());
553 x = leftMargin(dummyrow);
556 if (newpar && row.par()->layout() == tclass.defaultLayout()) {
557 if (newpar->params().noindent())
560 parindent = newpar->layout()->parindent;
566 LyXFont const labelfont = getLabelFont(bv()->buffer(), &*row.par());
567 switch (layout->margintype) {
569 if (!layout->leftmargin.empty()) {
570 x += font_metrics::signedWidth(layout->leftmargin,
571 tclass.defaultfont());
573 if (!row.par()->getLabelstring().empty()) {
574 x += font_metrics::signedWidth(layout->labelindent,
576 x += font_metrics::width(row.par()->getLabelstring(),
578 x += font_metrics::width(layout->labelsep, labelfont);
582 x += font_metrics::signedWidth(layout->labelindent, labelfont);
583 // The width of an empty par, even with manual label, should be 0
584 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
585 if (!row.par()->getLabelWidthString().empty()) {
586 x += font_metrics::width(row.par()->getLabelWidthString(),
588 x += font_metrics::width(layout->labelsep, labelfont);
593 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
594 / (row.par()->getDepth() + 4);
596 case MARGIN_FIRST_DYNAMIC:
597 if (layout->labeltype == LABEL_MANUAL) {
598 if (row.pos() >= row.par()->beginningOfBody()) {
599 x += font_metrics::signedWidth(layout->leftmargin,
602 x += font_metrics::signedWidth(layout->labelindent,
606 // Special case to fix problems with
608 || (layout->labeltype == LABEL_STATIC
609 && layout->latextype == LATEX_ENVIRONMENT
610 && ! row.par()->isFirstInSequence())) {
611 x += font_metrics::signedWidth(layout->leftmargin,
613 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
614 && layout->labeltype != LABEL_BIBLIO
615 && layout->labeltype !=
616 LABEL_CENTERED_TOP_ENVIRONMENT) {
617 x += font_metrics::signedWidth(layout->labelindent,
619 x += font_metrics::width(layout->labelsep, labelfont);
620 x += font_metrics::width(row.par()->getLabelstring(),
625 case MARGIN_RIGHT_ADDRESS_BOX:
627 // ok, a terrible hack. The left margin depends on the widest
628 // row in this paragraph. Do not care about footnotes, they
629 // are *NOT* allowed in the LaTeX realisation of this layout.
631 // find the first row of this paragraph
632 RowList::iterator tmprit = rowlist_.begin();
633 while (tmprit != rowlist_.end()
634 && tmprit->par() != row.par())
637 int minfill = tmprit->fill();
638 while (boost::next(tmprit) != rowlist_.end() &&
639 boost::next(tmprit)->par() == row.par()) {
641 if (tmprit->fill() < minfill)
642 minfill = tmprit->fill();
645 x += font_metrics::signedWidth(layout->leftmargin,
646 tclass.defaultfont());
652 if ((workWidth() > 0) &&
653 !row.par()->params().leftIndent().zero())
655 LyXLength const len = row.par()->params().leftIndent();
656 int const tw = inset_owner ?
657 inset_owner->latexTextWidth(bv()) : workWidth();
658 x += len.inPixels(tw);
661 LyXAlignment align; // wrong type
663 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
664 align = layout->align;
666 align = row.par()->params().align();
668 // set the correct parindent
669 if (row.pos() == 0) {
670 if ((layout->labeltype == LABEL_NO_LABEL
671 || layout->labeltype == LABEL_TOP_ENVIRONMENT
672 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
673 || (layout->labeltype == LABEL_STATIC
674 && layout->latextype == LATEX_ENVIRONMENT
675 && ! row.par()->isFirstInSequence()))
676 && align == LYX_ALIGN_BLOCK
677 && !row.par()->params().noindent()
678 // in tabulars and ert paragraphs are never indented!
679 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
680 (row.par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
681 row.par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
682 && (row.par()->layout() != tclass.defaultLayout() ||
683 bv()->buffer()->params.paragraph_separation ==
684 BufferParams::PARSEP_INDENT)) {
685 x += font_metrics::signedWidth(parindent,
686 tclass.defaultfont());
687 } else if (layout->labeltype == LABEL_BIBLIO) {
688 // ale970405 Right width for bibitems
689 x += bibitemMaxWidth(bv(), tclass.defaultfont());
697 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
701 if (row.pos() < row.par()->size())
702 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
703 (ins = row.par()->getInset(row.pos())) &&
704 (ins->needFullRow() || ins->display()))
707 LyXTextClass const & tclass = buf.params.getLyXTextClass();
708 LyXLayout_ptr const & layout = row.par()->layout();
711 + font_metrics::signedWidth(tclass.rightmargin(),
712 tclass.defaultfont());
714 x += font_metrics::signedWidth(layout->rightmargin,
715 tclass.defaultfont())
716 * 4 / (row.par()->getDepth() + 4);
721 int LyXText::labelEnd(Row const & row) const
723 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
725 tmprow.pos(row.par()->size());
726 // return the beginning of the body
727 return leftMargin(tmprow);
730 // LabelEnd is only needed if the layout
731 // fills a flushleft label.
738 // this needs special handling - only newlines count as a break point
739 pos_type addressBreakPoint(pos_type i, Paragraph * par)
741 for (; i < par->size(); ++i) {
742 if (par->isNewline(i))
753 LyXText::rowBreakPoint(Row const & row) const
755 ParagraphList::iterator pit = row.par();
757 // maximum pixel width of a row.
758 int width = workWidth() - rightMargin(*bv()->buffer(), row);
760 // inset->textWidth() returns -1 via workWidth(),
765 LyXLayout_ptr const & layout = pit->layout();
767 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
768 return addressBreakPoint(row.pos(), &*pit);
770 pos_type const pos = row.pos();
771 pos_type const body_pos = pit->beginningOfBody();
772 pos_type const last = pit->size();
773 pos_type point = last;
778 // Now we iterate through until we reach the right margin
779 // or the end of the par, then choose the possible break
782 int const left = leftMargin(const_cast<Row&>(row));
785 // pixel width since last breakpoint
789 for (; i < last; ++i) {
791 if (pit->isNewline(i)) {
796 char const c = pit->getChar(i);
798 int thiswidth = singleWidth(&*pit, i, c);
800 // add the auto-hfill from label end to the body
801 if (body_pos && i == body_pos) {
802 thiswidth += font_metrics::width(layout->labelsep,
803 getLabelFont(bv()->buffer(), &*pit));
804 if (pit->isLineSeparator(i - 1))
805 thiswidth -= singleWidth(&*pit, i - 1);
809 chunkwidth += thiswidth;
811 Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
812 bool fullrow = (in && (in->display() || in->needFullRow()));
814 // break before a character that will fall off
815 // the right of the row
817 // if no break before or we are at an inset
818 // that will take up a row, break here
819 if (point == last || fullrow || chunkwidth >= (width - left)) {
828 if (!in || in->isChar()) {
829 // some insets are line separators too
830 if (pit->isLineSeparator(i)) {
840 // full row insets start at a new row
842 if (pos < last - 1) {
844 if (pit->isLineSeparator(i + 1))
847 // to avoid extra rows
856 if (point == last && x >= width) {
857 // didn't find one, break at the point we reached the edge
859 } else if (i == last && x < width) {
860 // found one, but we fell off the end of the par, so prefer
865 // manual labels cannot be broken in LaTeX
866 if (body_pos && point < body_pos)
867 point = body_pos - 1;
873 // returns the minimum space a row needs on the screen in pixel
874 int LyXText::fill(RowList::iterator row, int paper_width) const
880 // get the pure distance
881 pos_type const last = lastPrintablePos(*this, row);
883 // special handling of the right address boxes
884 if (row->par()->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
885 int const tmpfill = row->fill();
886 row->fill(0); // the minfill in MarginLeft()
887 w = leftMargin(*row);
890 w = leftMargin(*row);
892 ParagraphList::iterator pit = row->par();
893 LyXLayout_ptr const & layout = pit->layout();
895 pos_type const body_pos = pit->beginningOfBody();
896 pos_type i = row->pos();
899 if (body_pos > 0 && i == body_pos) {
900 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), &*pit));
901 if (pit->isLineSeparator(i - 1))
902 w -= singleWidth(&*pit, i - 1);
903 int left_margin = labelEnd(*row);
907 w += singleWidth(&*pit, i);
910 if (body_pos > 0 && body_pos > last) {
911 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), &*pit));
912 if (last >= 0 && pit->isLineSeparator(last))
913 w -= singleWidth(&*pit, last);
914 int const left_margin = labelEnd(*row);
919 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
924 // returns the minimum space a manual label needs on the screen in pixel
925 int LyXText::labelFill(Row const & row) const
927 pos_type last = row.par()->beginningOfBody();
929 lyx::Assert(last > 0);
931 // -1 because a label ends either with a space that is in the label,
932 // or with the beginning of a footnote that is outside the label.
935 // a separator at this end does not count
936 if (row.par()->isLineSeparator(last))
940 pos_type i = row.pos();
942 w += singleWidth(&*row.par(), i);
947 string const & labwidstr = row.par()->params().labelWidthString();
948 if (!labwidstr.empty()) {
949 LyXFont const labfont = getLabelFont(bv()->buffer(), &*row.par());
950 int const labwidth = font_metrics::width(labwidstr, labfont);
951 fill = max(labwidth - w, 0);
958 LColor::color LyXText::backgroundColor() const
961 return inset_owner->backgroundColor();
963 return LColor::background;
967 void LyXText::setHeightOfRow(RowList::iterator rit)
969 // No need to do anything then...
970 if (rit == rows().end())
973 // get the maximum ascent and the maximum descent
977 float layoutdesc = 0;
980 Inset * tmpinset = 0;
982 // ok , let us initialize the maxasc and maxdesc value.
983 // This depends in LaTeX of the font of the last character
984 // in the paragraph. The hack below is necessary because
985 // of the possibility of open footnotes
987 // Correction: only the fontsize count. The other properties
988 // are taken from the layoutfont. Nicer on the screen :)
989 ParagraphList::iterator pit = rit->par();
990 ParagraphList::iterator firstpit = pit;
992 LyXLayout_ptr const & layout = firstpit->layout();
994 // as max get the first character of this row then it can increase but not
995 // decrease the height. Just some point to start with so we don't have to
996 // do the assignment below too often.
997 LyXFont font = getFont(bv()->buffer(), &*pit, rit->pos());
998 LyXFont::FONT_SIZE const tmpsize = font.size();
999 font = getLayoutFont(bv()->buffer(), &*pit);
1000 LyXFont::FONT_SIZE const size = font.size();
1001 font.setSize(tmpsize);
1003 LyXFont labelfont = getLabelFont(bv()->buffer(), &*pit);
1005 float spacing_val = 1.0;
1006 if (!rit->par()->params().spacing().isDefault()) {
1007 spacing_val = rit->par()->params().spacing().getValue();
1009 spacing_val = bv()->buffer()->params.spacing.getValue();
1011 //lyxerr << "spacing_val = " << spacing_val << endl;
1013 int maxasc = int(font_metrics::maxAscent(font) *
1014 layout->spacing.getValue() *
1016 int maxdesc = int(font_metrics::maxDescent(font) *
1017 layout->spacing.getValue() *
1020 pos_type const pos_end = lastPos(*this, rit);
1024 if (!rit->par()->empty()) {
1025 // Check if any insets are larger
1026 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1027 if (rit->par()->isInset(pos)) {
1028 tmpfont = getFont(bv()->buffer(), &*rit->par(), pos);
1029 tmpinset = rit->par()->getInset(pos);
1031 #if 1 // this is needed for deep update on initialitation
1032 #warning inset->update FIXME
1033 tmpinset->update(bv());
1035 asc = tmpinset->ascent(bv(), tmpfont);
1036 desc = tmpinset->descent(bv(), tmpfont);
1037 maxwidth += tmpinset->width(bv(), tmpfont);
1038 maxasc = max(maxasc, asc);
1039 maxdesc = max(maxdesc, desc);
1042 maxwidth += singleWidth(&*rit->par(), pos);
1047 // Check if any custom fonts are larger (Asger)
1048 // This is not completely correct, but we can live with the small,
1049 // cosmetic error for now.
1050 LyXFont::FONT_SIZE maxsize =
1051 rit->par()->highestFontInRange(rit->pos(), pos_end, size);
1052 if (maxsize > font.size()) {
1053 font.setSize(maxsize);
1055 asc = font_metrics::maxAscent(font);
1056 desc = font_metrics::maxDescent(font);
1063 // This is nicer with box insets:
1067 rit->ascent_of_text(maxasc);
1069 // is it a top line?
1070 if (!rit->pos() && (rit->par() == firstpit)) {
1072 // some parksips VERY EASY IMPLEMENTATION
1073 if (bv()->buffer()->params.paragraph_separation ==
1074 BufferParams::PARSEP_SKIP)
1076 if (layout->isParagraph()
1077 && firstpit->getDepth() == 0
1078 && firstpit->previous())
1080 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1081 } else if (firstpit->previous() &&
1082 firstpit->previous()->layout()->isParagraph() &&
1083 firstpit->previous()->getDepth() == 0)
1085 // is it right to use defskip here too? (AS)
1086 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1091 if (!rit->par()->previous() && !isInInset())
1092 maxasc += PAPER_MARGIN;
1094 // add the vertical spaces, that the user added
1095 maxasc += getLengthMarkerHeight(*bv(), firstpit->params().spaceTop());
1097 // do not forget the DTP-lines!
1098 // there height depends on the font of the nearest character
1099 if (firstpit->params().lineTop())
1101 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1103 // and now the pagebreaks
1104 if (firstpit->params().pagebreakTop())
1105 maxasc += 3 * defaultRowHeight();
1107 if (firstpit->params().startOfAppendix())
1108 maxasc += 3 * defaultRowHeight();
1110 // This is special code for the chapter, since the label of this
1111 // layout is printed in an extra row
1112 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1113 && bv()->buffer()->params.secnumdepth >= 0)
1115 float spacing_val = 1.0;
1116 if (!rit->par()->params().spacing().isDefault()) {
1117 spacing_val = rit->par()->params().spacing().getValue();
1119 spacing_val = bv()->buffer()->params.spacing.getValue();
1122 labeladdon = int(font_metrics::maxDescent(labelfont) *
1123 layout->spacing.getValue() *
1125 + int(font_metrics::maxAscent(labelfont) *
1126 layout->spacing.getValue() *
1130 // special code for the top label
1131 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1132 || layout->labeltype == LABEL_BIBLIO
1133 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1134 && rit->par()->isFirstInSequence()
1135 && !rit->par()->getLabelstring().empty())
1137 float spacing_val = 1.0;
1138 if (!rit->par()->params().spacing().isDefault()) {
1139 spacing_val = rit->par()->params().spacing().getValue();
1141 spacing_val = bv()->buffer()->params.spacing.getValue();
1145 (font_metrics::maxAscent(labelfont) *
1146 layout->spacing.getValue() *
1148 +(font_metrics::maxDescent(labelfont) *
1149 layout->spacing.getValue() *
1151 + layout->topsep * defaultRowHeight()
1152 + layout->labelbottomsep * defaultRowHeight());
1155 // and now the layout spaces, for example before and after a section,
1156 // or between the items of a itemize or enumerate environment
1158 if (!firstpit->params().pagebreakTop()) {
1159 Paragraph * prev = rit->par()->previous();
1161 prev = rit->par()->depthHook(rit->par()->getDepth());
1162 if (prev && prev->layout() == firstpit->layout() &&
1163 prev->getDepth() == firstpit->getDepth() &&
1164 prev->getLabelWidthString() == firstpit->getLabelWidthString())
1166 layoutasc = (layout->itemsep * defaultRowHeight());
1167 } else if (rit != rows().begin()) {
1168 tmptop = layout->topsep;
1170 if (boost::prior(rit)->par()->getDepth() >= rit->par()->getDepth())
1171 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1174 layoutasc = (tmptop * defaultRowHeight());
1175 } else if (rit->par()->params().lineTop()) {
1176 tmptop = layout->topsep;
1179 layoutasc = (tmptop * defaultRowHeight());
1182 prev = rit->par()->outerHook();
1184 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1186 if (firstpit->previous() &&
1187 firstpit->previous()->getDepth() == 0 &&
1188 firstpit->previous()->layout() !=
1192 } else if (firstpit->previous()) {
1193 maxasc += int(layout->parsep * defaultRowHeight());
1199 // is it a bottom line?
1200 if (rit->par() == pit
1201 && (boost::next(rit) == rows().end() ||
1202 boost::next(rit)->par() != rit->par())) {
1203 // the bottom margin
1204 if (boost::next(pit) == ownerParagraphs().end() &&
1206 maxdesc += PAPER_MARGIN;
1208 // add the vertical spaces, that the user added
1209 maxdesc += getLengthMarkerHeight(*bv(), firstpit->params().spaceBottom());
1211 // do not forget the DTP-lines!
1212 // there height depends on the font of the nearest character
1213 if (firstpit->params().lineBottom())
1214 maxdesc += 2 * font_metrics::ascent('x',
1215 getFont(bv()->buffer(),
1217 max(pos_type(0), pit->size() - 1)));
1219 // and now the pagebreaks
1220 if (firstpit->params().pagebreakBottom())
1221 maxdesc += 3 * defaultRowHeight();
1223 // and now the layout spaces, for example before and after
1224 // a section, or between the items of a itemize or enumerate
1226 if (!firstpit->params().pagebreakBottom()
1227 && rit->par()->next()) {
1228 ParagraphList::iterator nextpit = boost::next(rit->par());
1229 ParagraphList::iterator comparepit = rit->par();
1233 if (comparepit->getDepth() > nextpit->getDepth()) {
1234 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1235 comparepit = comparepit->depthHook(nextpit->getDepth());
1236 if (comparepit->layout()!= nextpit->layout()
1237 || nextpit->getLabelWidthString() !=
1238 comparepit->getLabelWidthString())
1240 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1242 if (unusual > usual)
1243 layoutdesc = unusual;
1246 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1248 if (comparepit->layout() != nextpit->layout()
1249 || nextpit->getLabelWidthString() !=
1250 comparepit->getLabelWidthString())
1251 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1256 // incalculate the layout spaces
1257 maxasc += int(layoutasc * 2 / (2 + firstpit->getDepth()));
1258 maxdesc += int(layoutdesc * 2 / (2 + firstpit->getDepth()));
1260 // calculate the new height of the text
1261 height -= rit->height();
1263 rit->height(maxasc + maxdesc + labeladdon);
1264 rit->baseline(maxasc + labeladdon);
1266 height += rit->height();
1268 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1271 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1274 rit->width(maxwidth);
1275 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1277 rit->width(int(maxwidth + x));
1279 width = max(0, workWidth());
1280 RowList::iterator it = rows().begin();
1281 RowList::iterator end = rows().end();
1282 for (; it != end; ++it) {
1283 if (it->width() > width)
1284 width = it->width();
1290 // Appends the implicit specified paragraph before the specified row,
1291 // start at the implicit given position
1292 void LyXText::appendParagraph(RowList::iterator rowit)
1294 lyx::Assert(rowit != rowlist_.end());
1296 pos_type const last = rowit->par()->size();
1300 pos_type z = rowBreakPoint(*rowit);
1302 RowList::iterator tmprow = rowit;
1306 Row newrow(rowit->par(), z);
1307 rowit = rowlist_.insert(boost::next(rowit), newrow);
1312 // Set the dimensions of the row
1313 // fixed fill setting now by calling inset->update() in
1314 // SingleWidth when needed!
1315 tmprow->fill(fill(tmprow, workWidth()));
1316 setHeightOfRow(tmprow);
1322 void LyXText::breakAgain(RowList::iterator rit)
1324 lyx::Assert(rit != rows().end());
1326 bool not_ready = true;
1329 pos_type z = rowBreakPoint(*rit);
1330 RowList::iterator tmprit = rit;
1331 RowList::iterator end = rows().end();
1333 if (z < rit->par()->size()) {
1334 if (boost::next(rit) == end ||
1335 (boost::next(rit) != end &&
1336 boost::next(rit)->par() != rit->par())) {
1339 Row newrow(rit->par(), z);
1340 rit = rowlist_.insert(boost::next(rit), newrow);
1344 if (rit->pos() == z)
1345 not_ready = false; // the rest will not change
1351 // if there are some rows too much, delete them
1352 // only if you broke the whole paragraph!
1353 RowList::iterator tmprit2 = rit;
1354 while (boost::next(tmprit2) != end
1355 && boost::next(tmprit2)->par() == rit->par()) {
1358 while (tmprit2 != rit) {
1360 removeRow(boost::next(tmprit2));
1365 // set the dimensions of the row
1366 tmprit->fill(fill(tmprit, workWidth()));
1367 setHeightOfRow(tmprit);
1368 } while (not_ready);
1372 // this is just a little changed version of break again
1373 void LyXText::breakAgainOneRow(RowList::iterator rit)
1375 lyx::Assert(rit != rows().end());
1377 pos_type z = rowBreakPoint(*rit);
1378 RowList::iterator tmprit = rit;
1379 RowList::iterator end = rows().end();
1381 if (z < rit->par()->size()) {
1382 if (boost::next(rit) == end ||
1383 (boost::next(rit) != end &&
1384 boost::next(rit)->par() != rit->par())) {
1387 Row newrow(rit->par(), z);
1388 rit = rowlist_.insert(boost::next(rit), newrow);
1392 if (rit->pos() != z)
1396 // if there are some rows too much, delete them
1397 // only if you broke the whole paragraph!
1398 RowList::iterator tmprit2 = rit;
1399 while (boost::next(tmprit2) != end
1400 && boost::next(tmprit2)->par() == rit->par()) {
1403 while (tmprit2 != rit) {
1405 removeRow(boost::next(tmprit2));
1409 // set the dimensions of the row
1410 tmprit->fill(fill(tmprit, workWidth()));
1411 setHeightOfRow(tmprit);
1415 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1417 // allow only if at start or end, or all previous is new text
1418 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1419 && cursor.par()->isChangeEdited(0, cursor.pos()))
1422 LyXTextClass const & tclass =
1423 bv()->buffer()->params.getLyXTextClass();
1424 LyXLayout_ptr const & layout = cursor.par()->layout();
1426 // this is only allowed, if the current paragraph is not empty or caption
1427 // and if it has not the keepempty flag aktive
1428 if (cursor.par()->empty()
1429 && layout->labeltype != LABEL_SENSITIVE
1430 && !layout->keepempty)
1433 setUndo(bv(), Undo::FINISH, cursor.par(), cursor.par()->next());
1435 // Always break behind a space
1437 // It is better to erase the space (Dekel)
1438 if (cursor.pos() < cursor.par()->size()
1439 && cursor.par()->isLineSeparator(cursor.pos()))
1440 cursor.par()->erase(cursor.pos());
1441 // cursor.pos(cursor.pos() + 1);
1443 // break the paragraph
1447 keep_layout = layout->isEnvironment();
1449 // we need to set this before we insert the paragraph. IMO the
1450 // breakParagraph call should return a bool if it inserts the
1451 // paragraph before or behind and we should react on that one
1452 // but we can fix this in 1.3.0 (Jug 20020509)
1453 bool const isempty = (layout->keepempty && cursor.par()->empty());
1454 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
1457 // well this is the caption hack since one caption is really enough
1458 if (layout->labeltype == LABEL_SENSITIVE) {
1460 // set to standard-layout
1461 cursor.par()->applyLayout(tclass.defaultLayout());
1463 // set to standard-layout
1464 cursor.par()->next()->applyLayout(tclass.defaultLayout());
1467 // if the cursor is at the beginning of a row without prior newline,
1469 // This touches only the screen-update. Otherwise we would may have
1470 // an empty row on the screen
1471 if (cursor.pos() && cursor.row()->pos() == cursor.pos()
1472 && !cursor.row()->par()->isNewline(cursor.pos() - 1))
1477 int y = cursor.y() - cursor.row()->baseline();
1479 // Do not forget the special right address boxes
1480 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1481 RowList::iterator r = cursor.row();
1482 while (r != rows().begin() && boost::prior(r)->par() == r->par()) {
1490 removeParagraph(cursor.row());
1492 // set the dimensions of the cursor row
1493 cursor.row()->fill(fill(cursor.row(), workWidth()));
1495 setHeightOfRow(cursor.row());
1497 #warning Trouble Point! (Lgb)
1498 // When ::breakParagraph is called from within an inset we must
1499 // ensure that the correct ParagraphList is used. Today that is not
1500 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1501 while (!cursor.par()->next()->empty()
1502 && cursor.par()->next()->isNewline(0))
1503 cursor.par()->next()->erase(0);
1505 insertParagraph(cursor.par()->next(), boost::next(cursor.row()));
1508 // This check is necessary. Otherwise the new empty paragraph will
1509 // be deleted automatically. And it is more friendly for the user!
1510 if (cursor.pos() || isempty)
1511 setCursor(cursor.par()->next(), 0);
1513 setCursor(cursor.par(), 0);
1515 if (boost::next(cursor.row()) != rows().end())
1516 breakAgain(boost::next(cursor.row()));
1518 need_break_row = rows().end();
1522 // Just a macro to make some thing easier.
1523 void LyXText::redoParagraph()
1526 redoParagraphs(cursor, cursor.par()->next());
1527 setCursorIntern(cursor.par(), cursor.pos());
1531 // insert a character, moves all the following breaks in the
1532 // same Paragraph one to the right and make a rebreak
1533 void LyXText::insertChar(char c)
1535 setUndo(bv(), Undo::INSERT, cursor.par(), cursor.par()->next());
1537 // When the free-spacing option is set for the current layout,
1538 // disable the double-space checking
1540 bool const freeSpacing = cursor.row()->par()->layout()->free_spacing ||
1541 cursor.row()->par()->isFreeSpacing();
1543 if (lyxrc.auto_number) {
1544 static string const number_operators = "+-/*";
1545 static string const number_unary_operators = "+-";
1546 static string const number_seperators = ".,:";
1548 if (current_font.number() == LyXFont::ON) {
1549 if (!IsDigit(c) && !contains(number_operators, c) &&
1550 !(contains(number_seperators, c) &&
1551 cursor.pos() >= 1 &&
1552 cursor.pos() < cursor.par()->size() &&
1553 getFont(bv()->buffer(),
1555 cursor.pos()).number() == LyXFont::ON &&
1556 getFont(bv()->buffer(),
1558 cursor.pos() - 1).number() == LyXFont::ON)
1560 number(bv()); // Set current_font.number to OFF
1561 } else if (IsDigit(c) &&
1562 real_current_font.isVisibleRightToLeft()) {
1563 number(bv()); // Set current_font.number to ON
1565 if (cursor.pos() > 0) {
1566 char const c = cursor.par()->getChar(cursor.pos() - 1);
1567 if (contains(number_unary_operators, c) &&
1568 (cursor.pos() == 1 ||
1569 cursor.par()->isSeparator(cursor.pos() - 2) ||
1570 cursor.par()->isNewline(cursor.pos() - 2))
1572 setCharFont(bv()->buffer(),
1576 } else if (contains(number_seperators, c) &&
1577 cursor.pos() >= 2 &&
1578 getFont(bv()->buffer(),
1580 cursor.pos() - 2).number() == LyXFont::ON) {
1581 setCharFont(bv()->buffer(),
1591 // First check, if there will be two blanks together or a blank at
1592 // the beginning of a paragraph.
1593 // I decided to handle blanks like normal characters, the main
1594 // difference are the special checks when calculating the row.fill
1595 // (blank does not count at the end of a row) and the check here
1597 // The bug is triggered when we type in a description environment:
1598 // The current_font is not changed when we go from label to main text
1599 // and it should (along with realtmpfont) when we type the space.
1600 // CHECK There is a bug here! (Asger)
1602 LyXFont realtmpfont = real_current_font;
1603 LyXFont rawtmpfont = current_font;
1604 // store the current font. This is because of the use of cursor
1605 // movements. The moving cursor would refresh the current font
1607 // Get the font that is used to calculate the baselineskip
1608 pos_type const lastpos = cursor.par()->size();
1609 LyXFont rawparfont =
1610 cursor.par()->getFontSettings(bv()->buffer()->params,
1613 bool jumped_over_space = false;
1615 if (!freeSpacing && IsLineSeparatorChar(c)) {
1616 if ((cursor.pos() > 0
1617 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1618 || (cursor.pos() > 0
1619 && cursor.par()->isNewline(cursor.pos() - 1))
1620 || (cursor.pos() == 0)) {
1621 static bool sent_space_message = false;
1622 if (!sent_space_message) {
1623 if (cursor.pos() == 0)
1624 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1626 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1627 sent_space_message = true;
1634 // the display inset stuff
1635 if (cursor.row()->pos() < cursor.row()->par()->size()
1636 && cursor.row()->par()->isInset(cursor.row()->pos())) {
1637 Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
1638 if (inset && (inset->display() || inset->needFullRow())) {
1639 // force a new break
1640 cursor.row()->fill(-1); // to force a new break
1644 // get the cursor row fist
1645 RowList::iterator row = cursor.row();
1646 int y = cursor.y() - row->baseline();
1647 if (c != Paragraph::META_INSET) {
1648 // Here case LyXText::InsertInset already insertet the character
1649 cursor.par()->insertChar(cursor.pos(), c);
1651 setCharFont(bv()->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
1653 if (!jumped_over_space) {
1654 // refresh the positions
1655 RowList::iterator tmprow = row;
1656 while (boost::next(tmprow) != rows().end() &&
1657 boost::next(tmprow)->par() == row->par()) {
1659 tmprow->pos(tmprow->pos() + 1);
1663 // Is there a break one row above
1664 if (row != rows().begin() &&
1665 boost::prior(row)->par() == row->par()
1666 && (cursor.par()->isLineSeparator(cursor.pos())
1667 || cursor.par()->isNewline(cursor.pos())
1668 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1669 cursor.par()->isInset(cursor.pos() + 1))
1670 || cursor.row()->fill() == -1))
1672 pos_type z = rowBreakPoint(*boost::prior(row));
1674 if (z >= row->pos()) {
1677 // set the dimensions of the row above
1678 boost::prior(row)->fill(fill(
1682 setHeightOfRow(boost::prior(row));
1684 y -= boost::prior(row)->height();
1688 breakAgainOneRow(row);
1690 current_font = rawtmpfont;
1691 real_current_font = realtmpfont;
1692 setCursor(cursor.par(), cursor.pos() + 1,
1693 false, cursor.boundary());
1694 // cursor MUST be in row now.
1696 if (boost::next(row) != rows().end() &&
1697 boost::next(row)->par() == row->par())
1698 need_break_row = boost::next(row);
1700 need_break_row = rows().end();
1702 // check, wether the last characters font has changed.
1703 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1704 && rawparfont != rawtmpfont)
1705 redoHeightOfParagraph();
1712 // recalculate the fill of the row
1713 if (row->fill() >= 0) {
1714 // needed because a newline will set fill to -1. Otherwise
1715 // we would not get a rebreak!
1716 row->fill(fill(row, workWidth()));
1719 if (c == Paragraph::META_INSET || row->fill() < 0) {
1721 breakAgainOneRow(row);
1722 // will the cursor be in another row now?
1723 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1724 boost::next(row) != rows().end()) {
1725 if (boost::next(row) != rows().end() &&
1726 boost::next(row)->par() == row->par())
1727 // this should always be true
1729 breakAgainOneRow(row);
1731 current_font = rawtmpfont;
1732 real_current_font = realtmpfont;
1734 setCursor(cursor.par(), cursor.pos() + 1, false,
1736 if (isBoundary(bv()->buffer(), cursor.par(), cursor.pos())
1737 != cursor.boundary())
1738 setCursor(cursor.par(), cursor.pos(), false,
1739 !cursor.boundary());
1740 if (boost::next(row) != rows().end() &&
1741 boost::next(row)->par() == row->par())
1742 need_break_row = boost::next(row);
1744 need_break_row = rows().end();
1746 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1747 int const tmpheight = row->height();
1749 setHeightOfRow(row);
1751 if (tmpheight == row->height()) {
1752 postRowPaint(row, y);
1757 current_font = rawtmpfont;
1758 real_current_font = realtmpfont;
1759 setCursor(cursor.par(), cursor.pos() + 1, false,
1763 // check, wether the last characters font has changed.
1764 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1765 && rawparfont != rawtmpfont) {
1766 redoHeightOfParagraph();
1768 // now the special right address boxes
1769 if (cursor.par()->layout()->margintype
1770 == MARGIN_RIGHT_ADDRESS_BOX) {
1771 redoDrawingOfParagraph(cursor);
1779 void LyXText::charInserted()
1781 // Here we could call FinishUndo for every 20 characters inserted.
1782 // This is from my experience how emacs does it.
1783 static unsigned int counter;
1793 void LyXText::prepareToPrint(RowList::iterator rit, float & x,
1794 float & fill_separator,
1796 float & fill_label_hfill,
1801 float w = rit->fill();
1803 fill_label_hfill = 0;
1805 fill_label_hfill = 0;
1808 rit->par()->isRightToLeftPar(bv()->buffer()->params);
1810 x = (workWidth() > 0)
1811 ? rightMargin(*bv()->buffer(), *rit) : 0;
1813 x = (workWidth() > 0)
1814 ? leftMargin(*rit) : 0;
1816 // is there a manual margin with a manual label
1817 LyXLayout_ptr const & layout = rit->par()->layout();
1819 if (layout->margintype == MARGIN_MANUAL
1820 && layout->labeltype == LABEL_MANUAL) {
1821 /// We might have real hfills in the label part
1822 nlh = numberOfLabelHfills(*this, rit);
1824 // A manual label par (e.g. List) has an auto-hfill
1825 // between the label text and the body of the
1827 // But we don't want to do this auto hfill if the par
1829 if (!rit->par()->empty())
1832 if (nlh && !rit->par()->getLabelWidthString().empty()) {
1833 fill_label_hfill = labelFill(*rit) / nlh;
1837 // are there any hfills in the row?
1838 float const nh = numberOfHfills(*this, rit);
1842 fill_hfill = w / nh;
1843 // we don't have to look at the alignment if it is ALIGN_LEFT and
1844 // if the row is already larger then the permitted width as then
1845 // we force the LEFT_ALIGN'edness!
1846 } else if (static_cast<int>(rit->width()) < workWidth()) {
1847 // is it block, flushleft or flushright?
1848 // set x how you need it
1850 if (rit->par()->params().align() == LYX_ALIGN_LAYOUT) {
1851 align = layout->align;
1853 align = rit->par()->params().align();
1856 // center displayed insets
1858 if (rit->pos() < rit->par()->size()
1859 && rit->par()->isInset(rit->pos())
1860 && (inset = rit->par()->getInset(rit->pos()))
1861 && (inset->display())) // || (inset->scroll() < 0)))
1862 align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
1863 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1864 // ERT insets should always be LEFT ALIGNED on screen
1865 inset = rit->par()->inInset();
1866 if (inset && inset->owner() &&
1867 inset->owner()->lyxCode() == Inset::ERT_CODE)
1869 align = LYX_ALIGN_LEFT;
1873 case LYX_ALIGN_BLOCK:
1875 float const ns = numberOfSeparators(*this, rit);
1876 RowList::iterator next_row = boost::next(rit);
1878 if (ns && next_row != rowlist_.end() &&
1879 next_row->par() == rit->par() &&
1880 !(next_row->par()->isNewline(next_row->pos() - 1))
1881 && !(next_row->par()->isInset(next_row->pos()) &&
1882 next_row->par()->getInset(next_row->pos()) &&
1883 next_row->par()->getInset(next_row->pos())->display())
1885 fill_separator = w / ns;
1886 } else if (is_rtl) {
1891 case LYX_ALIGN_RIGHT:
1894 case LYX_ALIGN_CENTER:
1902 computeBidiTables(bv()->buffer(), rit);
1904 pos_type body_pos = rit->par()->beginningOfBody();
1905 pos_type last = lastPos(*this, rit);
1908 (body_pos - 1 > last ||
1909 !rit->par()->isLineSeparator(body_pos - 1))) {
1910 x += font_metrics::width(layout->labelsep,
1911 getLabelFont(bv()->buffer(),
1913 if (body_pos - 1 <= last)
1914 x += fill_label_hfill;
1920 // important for the screen
1923 // the cursor set functions have a special mechanism. When they
1924 // realize, that you left an empty paragraph, they will delete it.
1925 // They also delete the corresponding row
1927 void LyXText::cursorRightOneWord()
1929 // treat floats, HFills and Insets as words
1930 LyXCursor tmpcursor = cursor;
1931 // CHECK See comment on top of text.C
1933 if (tmpcursor.pos() == tmpcursor.par()->size()
1934 && tmpcursor.par()->next()) {
1935 tmpcursor.par(tmpcursor.par()->next());
1940 // Skip through initial nonword stuff.
1941 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1942 ! tmpcursor.par()->isWord(tmpcursor.pos())) {
1943 // printf("Current pos1 %d", tmpcursor.pos()) ;
1944 tmpcursor.pos(tmpcursor.pos() + 1);
1947 // Advance through word.
1948 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1949 tmpcursor.par()->isWord(tmpcursor.pos())) {
1950 // printf("Current pos2 %d", tmpcursor.pos()) ;
1951 tmpcursor.pos(tmpcursor.pos() + 1);
1955 setCursor(tmpcursor.par(), tmpcursor.pos());
1959 // Skip initial whitespace at end of word and move cursor to *start*
1960 // of prior word, not to end of next prior word.
1961 void LyXText::cursorLeftOneWord()
1963 LyXCursor tmpcursor = cursor;
1964 cursorLeftOneWord(tmpcursor);
1965 setCursor(tmpcursor.par(), tmpcursor.pos());
1969 void LyXText::cursorLeftOneWord(LyXCursor & cur)
1971 // treat HFills, floats and Insets as words
1974 && (cur.par()->isSeparator(cur.pos() - 1)
1975 || cur.par()->isKomma(cur.pos() - 1)
1976 || cur.par()->isNewline(cur.pos() - 1))
1977 && !(cur.par()->isHfill(cur.pos() - 1)
1978 || cur.par()->isInset(cur.pos() - 1)))
1979 cur.pos(cur.pos() - 1);
1982 && (cur.par()->isInset(cur.pos() - 1)
1983 || cur.par()->isHfill(cur.pos() - 1))) {
1984 cur.pos(cur.pos() - 1);
1985 } else if (!cur.pos()) {
1986 if (cur.par()->previous()) {
1987 cur.par(cur.par()->previous());
1988 cur.pos(cur.par()->size());
1990 } else { // Here, cur != 0
1991 while (cur.pos() > 0 &&
1992 cur.par()->isWord(cur.pos() - 1))
1993 cur.pos(cur.pos() - 1);
1998 // Select current word. This depends on behaviour of
1999 // CursorLeftOneWord(), so it is patched as well.
2000 void LyXText::getWord(LyXCursor & from, LyXCursor & to,
2001 word_location const loc)
2003 // first put the cursor where we wana start to select the word
2006 case WHOLE_WORD_STRICT:
2007 if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
2008 || cursor.par()->isSeparator(cursor.pos())
2009 || cursor.par()->isKomma(cursor.pos())
2010 || cursor.par()->isNewline(cursor.pos())
2011 || cursor.par()->isSeparator(cursor.pos() - 1)
2012 || cursor.par()->isKomma(cursor.pos() - 1)
2013 || cursor.par()->isNewline(cursor.pos() - 1)) {
2017 // no break here, we go to the next
2020 // Move cursor to the beginning, when not already there.
2021 if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
2022 && !(from.par()->isKomma(from.pos() - 1)
2023 || from.par()->isNewline(from.pos() - 1)))
2024 cursorLeftOneWord(from);
2027 // always move the cursor to the beginning of previous word
2028 cursorLeftOneWord(from);
2031 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
2037 while (to.pos() < to.par()->size()
2038 && !to.par()->isSeparator(to.pos())
2039 && !to.par()->isKomma(to.pos())
2040 && !to.par()->isNewline(to.pos())
2041 && !to.par()->isHfill(to.pos())
2042 && !to.par()->isInset(to.pos()))
2044 to.pos(to.pos() + 1);
2049 void LyXText::selectWord(word_location loc)
2053 getWord(from, to, loc);
2055 setCursor(from.par(), from.pos());
2058 selection.cursor = cursor;
2059 setCursor(to.par(), to.pos());
2064 // Select the word currently under the cursor when no
2065 // selection is currently set
2066 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2068 if (!selection.set()) {
2070 return selection.set();
2076 void LyXText::acceptChange()
2078 if (!selection.set() && cursor.par()->size())
2083 if (selection.start.par() == selection.end.par()) {
2084 LyXCursor & startc = selection.start;
2085 LyXCursor & endc = selection.end;
2086 setUndo(bv(), Undo::INSERT, startc.par(), startc.par()->next());
2087 startc.par()->acceptChange(startc.pos(), endc.pos());
2090 redoParagraphs(startc, startc.par()->next());
2091 setCursorIntern(startc.par(), 0);
2093 #warning handle multi par selection
2097 void LyXText::rejectChange()
2099 if (!selection.set() && cursor.par()->size())
2104 if (selection.start.par() == selection.end.par()) {
2105 LyXCursor & startc = selection.start;
2106 LyXCursor & endc = selection.end;
2107 setUndo(bv(), Undo::INSERT, startc.par(), startc.par()->next());
2108 startc.par()->rejectChange(startc.pos(), endc.pos());
2111 redoParagraphs(startc, startc.par()->next());
2112 setCursorIntern(startc.par(), 0);
2114 #warning handle multi par selection
2118 // This function is only used by the spellchecker for NextWord().
2119 // It doesn't handle LYX_ACCENTs and probably never will.
2121 LyXText::selectNextWordToSpellcheck(float & value)
2123 if (the_locking_inset) {
2124 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2125 if (!word.word().empty()) {
2126 value += float(cursor.y());
2127 value /= float(height);
2130 // we have to go on checking so move cursor to the next char
2131 if (cursor.pos() == cursor.par()->size()) {
2132 if (!cursor.par()->next())
2134 cursor.par(cursor.par()->next());
2137 cursor.pos(cursor.pos() + 1);
2139 Paragraph * tmppar = cursor.par();
2141 // If this is not the very first word, skip rest of
2142 // current word because we are probably in the middle
2143 // of a word if there is text here.
2144 if (cursor.pos() || cursor.par()->previous()) {
2145 while (cursor.pos() < cursor.par()->size()
2146 && cursor.par()->isLetter(cursor.pos()))
2147 cursor.pos(cursor.pos() + 1);
2150 // Now, skip until we have real text (will jump paragraphs)
2152 Paragraph * cpar(cursor.par());
2153 pos_type const cpos(cursor.pos());
2155 if (cpos == cpar->size()) {
2157 cursor.par(cpar->next());
2164 bool const is_bad_inset(cpar->isInset(cpos)
2165 && !cpar->getInset(cpos)->allowSpellcheck());
2167 if (cpar->isLetter(cpos) && !isDeletedText(*cpar, cpos)
2171 cursor.pos(cpos + 1);
2174 // now check if we hit an inset so it has to be a inset containing text!
2175 if (cursor.pos() < cursor.par()->size() &&
2176 cursor.par()->isInset(cursor.pos())) {
2178 cursor.par()->getInset(cursor.pos())->edit(bv());
2179 // now call us again to do the above trick
2180 // but obviously we have to start from down below ;)
2181 return bv()->text->selectNextWordToSpellcheck(value);
2184 // Update the value if we changed paragraphs
2185 if (cursor.par() != tmppar) {
2186 setCursor(cursor.par(), cursor.pos());
2187 value = float(cursor.y())/float(height);
2190 // Start the selection from here
2191 selection.cursor = cursor;
2194 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2195 .language()->code());
2196 // and find the end of the word (insets like optional hyphens
2197 // and ligature break are part of a word)
2198 while (cursor.pos() < cursor.par()->size()
2199 && cursor.par()->isLetter(cursor.pos())
2200 && !isDeletedText(*cursor.par(), cursor.pos()))
2201 cursor.pos(cursor.pos() + 1);
2203 // Finally, we copy the word to a string and return it
2205 if (selection.cursor.pos() < cursor.pos()) {
2207 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2208 if (!cursor.par()->isInset(i))
2209 str += cursor.par()->getChar(i);
2212 return WordLangTuple(str, lang_code);
2216 // This one is also only for the spellchecker
2217 void LyXText::selectSelectedWord()
2219 if (the_locking_inset) {
2220 the_locking_inset->selectSelectedWord(bv());
2223 // move cursor to the beginning
2224 setCursor(selection.cursor.par(), selection.cursor.pos());
2226 // set the sel cursor
2227 selection.cursor = cursor;
2229 // now find the end of the word
2230 while (cursor.pos() < cursor.par()->size()
2231 && (cursor.par()->isLetter(cursor.pos())))
2232 cursor.pos(cursor.pos() + 1);
2234 setCursor(cursor.par(), cursor.pos());
2236 // finally set the selection
2241 // Delete from cursor up to the end of the current or next word.
2242 void LyXText::deleteWordForward()
2244 if (cursor.par()->empty())
2247 LyXCursor tmpcursor = cursor;
2248 tmpcursor.row(0); //Â ??
2249 selection.set(true); // to avoid deletion
2250 cursorRightOneWord();
2251 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2252 selection.cursor = cursor;
2256 // Great, CutSelection() gets rid of multiple spaces.
2257 cutSelection(true, false);
2262 // Delete from cursor to start of current or prior word.
2263 void LyXText::deleteWordBackward()
2265 if (cursor.par()->empty())
2268 LyXCursor tmpcursor = cursor;
2269 tmpcursor.row(0); // ??
2270 selection.set(true); // to avoid deletion
2271 cursorLeftOneWord();
2272 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2273 selection.cursor = cursor;
2276 cutSelection(true, false);
2281 // Kill to end of line.
2282 void LyXText::deleteLineForward()
2284 if (cursor.par()->empty())
2285 // Paragraph is empty, so we just go to the right
2288 LyXCursor tmpcursor = cursor;
2289 // We can't store the row over a regular setCursor
2290 // so we set it to 0 and reset it afterwards.
2291 tmpcursor.row(0); //Â ??
2292 selection.set(true); // to avoid deletion
2294 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2295 selection.cursor = cursor;
2298 // What is this test for ??? (JMarc)
2299 if (!selection.set()) {
2300 deleteWordForward();
2302 cutSelection(true, false);
2308 void LyXText::changeCase(LyXText::TextCase action)
2313 if (selection.set()) {
2314 from = selection.start;
2317 getWord(from, to, PARTIAL_WORD);
2318 setCursor(to.par(), to.pos() + 1);
2321 lyx::Assert(from <= to);
2323 setUndo(bv(), Undo::FINISH, from.par(), to.par()->next());
2325 pos_type pos = from.pos();
2326 Paragraph * par = from.par();
2328 while (par && (pos != to.pos() || par != to.par())) {
2329 if (pos == par->size()) {
2334 unsigned char c = par->getChar(pos);
2335 if (!IsInsetChar(c)) {
2337 case text_lowercase:
2340 case text_capitalization:
2342 action = text_lowercase;
2344 case text_uppercase:
2350 par->setChar(pos, c);
2351 checkParagraph(par, pos);
2356 if (to.row() != from.row())
2357 postPaint(from.y() - from.row()->baseline());
2361 void LyXText::Delete()
2363 // this is a very easy implementation
2365 LyXCursor old_cursor = cursor;
2366 int const old_cur_par_id = old_cursor.par()->id();
2367 int const old_cur_par_prev_id = old_cursor.par()->previous() ?
2368 old_cursor.par()->previous()->id() : -1;
2370 // just move to the right
2373 // CHECK Look at the comment here.
2374 // This check is not very good...
2375 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2376 // and that can very well delete the par or par->previous in
2377 // old_cursor. Will a solution where we compare paragraph id's
2379 if ((cursor.par()->previous() ? cursor.par()->previous()->id() : -1)
2380 == old_cur_par_prev_id
2381 && cursor.par()->id() != old_cur_par_id) {
2382 // delete-empty-paragraph-mechanism has done it
2386 // if you had success make a backspace
2387 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2388 LyXCursor tmpcursor = cursor;
2389 // to make sure undo gets the right cursor position
2390 cursor = old_cursor;
2391 setUndo(bv(), Undo::DELETE,
2392 cursor.par(), cursor.par()->next());
2399 void LyXText::backspace()
2401 // Get the font that is used to calculate the baselineskip
2402 pos_type lastpos = cursor.par()->size();
2403 LyXFont rawparfont =
2404 cursor.par()->getFontSettings(bv()->buffer()->params,
2407 if (cursor.pos() == 0) {
2408 // The cursor is at the beginning of a paragraph,
2409 // so the the backspace will collapse two paragraphs into one.
2411 // but it's not allowed unless it's new
2412 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2415 // we may paste some paragraphs
2417 // is it an empty paragraph?
2420 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2421 // This is an empty paragraph and we delete it just by moving the cursor one step
2422 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2423 // of the paragraph.
2425 if (cursor.par()->previous()) {
2426 Paragraph * tmppar = cursor.par()->previous();
2427 if (cursor.par()->layout() == tmppar->layout()
2428 && cursor.par()->getAlign() == tmppar->getAlign()) {
2429 // Inherit bottom DTD from the paragraph below.
2430 // (the one we are deleting)
2431 tmppar->params().lineBottom(cursor.par()->params().lineBottom());
2432 tmppar->params().spaceBottom(cursor.par()->params().spaceBottom());
2433 tmppar->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2438 // the layout things can change the height of a row !
2439 int const tmpheight = cursor.row()->height();
2440 setHeightOfRow(cursor.row());
2441 if (cursor.row()->height() != tmpheight) {
2442 postPaint(cursor.y() - cursor.row()->baseline());
2448 if (cursor.par()->previous()) {
2449 setUndo(bv(), Undo::DELETE,
2450 cursor.par()->previous(), cursor.par()->next());
2453 Paragraph * tmppar = cursor.par();
2454 RowList::iterator tmprow = cursor.row();
2456 // We used to do cursorLeftIntern() here, but it is
2457 // not a good idea since it triggers the auto-delete
2458 // mechanism. So we do a cursorLeftIntern()-lite,
2459 // without the dreaded mechanism. (JMarc)
2460 if (cursor.par()->previous()) {
2461 // steps into the above paragraph.
2462 setCursorIntern(cursor.par()->previous(),
2463 cursor.par()->previous()->size(),
2467 // Pasting is not allowed, if the paragraphs have different
2468 // layout. I think it is a real bug of all other
2469 // word processors to allow it. It confuses the user.
2470 // Even so with a footnote paragraph and a non-footnote
2471 // paragraph. I will not allow pasting in this case,
2472 // because the user would be confused if the footnote behaves
2473 // different wether it is open or closed.
2475 // Correction: Pasting is always allowed with standard-layout
2476 LyXTextClass const & tclass =
2477 bv()->buffer()->params.getLyXTextClass();
2479 if (cursor.par() != tmppar
2480 && (cursor.par()->layout() == tmppar->layout()
2481 || tmppar->layout() == tclass.defaultLayout())
2482 && cursor.par()->getAlign() == tmppar->getAlign()) {
2483 removeParagraph(tmprow);
2485 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2487 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2488 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2489 // strangely enough it seems that commenting out the line above removes
2490 // most or all of the segfaults. I will however also try to move the
2491 // two Remove... lines in front of the PasteParagraph too.
2494 cursor.pos(cursor.pos() - 1);
2496 postPaint(cursor.y() - cursor.row()->baseline());
2498 // remove the lost paragraph
2499 // This one is not safe, since the paragraph that the tmprow and the
2500 // following rows belong to has been deleted by the PasteParagraph
2501 // above. The question is... could this be moved in front of the
2503 //RemoveParagraph(tmprow);
2504 //RemoveRow(tmprow);
2506 // This rebuilds the rows.
2507 appendParagraph(cursor.row());
2510 // the row may have changed, block, hfills etc.
2511 setCursor(cursor.par(), cursor.pos(), false);
2514 // this is the code for a normal backspace, not pasting
2516 setUndo(bv(), Undo::DELETE,
2517 cursor.par(), cursor.par()->next());
2518 // We used to do cursorLeftIntern() here, but it is
2519 // not a good idea since it triggers the auto-delete
2520 // mechanism. So we do a cursorLeftIntern()-lite,
2521 // without the dreaded mechanism. (JMarc)
2522 setCursorIntern(cursor.par(), cursor.pos()- 1,
2523 false, cursor.boundary());
2525 if (cursor.par()->isInset(cursor.pos())) {
2526 // force complete redo when erasing display insets
2527 // this is a cruel method but safe..... Matthias
2528 if (cursor.par()->getInset(cursor.pos())->display() ||
2529 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2530 cursor.par()->erase(cursor.pos());
2536 RowList::iterator row = cursor.row();
2537 int y = cursor.y() - row->baseline();
2539 // remember that a space at the end of a row doesnt count
2540 // when calculating the fill
2541 if (cursor.pos() < lastPos(*this, row) ||
2542 !cursor.par()->isLineSeparator(cursor.pos())) {
2543 row->fill(row->fill() + singleWidth(
2548 // some special code when deleting a newline. This is similar
2549 // to the behavior when pasting paragraphs
2550 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2551 cursor.par()->erase(cursor.pos());
2552 // refresh the positions
2553 RowList::iterator tmprow = row;
2554 while (boost::next(tmprow) != rows().end() &&
2555 boost::next(tmprow)->par() == row->par()) {
2557 tmprow->pos(tmprow->pos() - 1);
2559 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2560 cursor.pos(cursor.pos() - 1);
2562 if (cursor.pos() < cursor.par()->size()
2563 && !cursor.par()->isSeparator(cursor.pos())) {
2564 cursor.par()->insertChar(cursor.pos(), ' ');
2565 setCharFont(bv()->buffer(), cursor.par(),
2566 cursor.pos(), current_font);
2567 // refresh the positions
2569 while (boost::next(tmprow) != rows().end() &&
2570 boost::next(tmprow)->par() == row->par()) {
2572 tmprow->pos(tmprow->pos() + 1);
2576 cursor.par()->erase(cursor.pos());
2578 // refresh the positions
2579 RowList::iterator tmprow = row;
2580 while (boost::next(tmprow) != rows().end() &&
2581 boost::next(tmprow)->par() == row->par()) {
2583 tmprow->pos(tmprow->pos() - 1);
2586 // delete newlines at the beginning of paragraphs
2587 while (!cursor.par()->empty() &&
2588 cursor.pos() < cursor.par()->size() &&
2589 cursor.par()->isNewline(cursor.pos()) &&
2590 cursor.pos() == cursor.par()->beginningOfBody()) {
2591 cursor.par()->erase(cursor.pos());
2592 // refresh the positions
2594 while (boost::next(tmprow) != rows().end() &&
2595 boost::next(tmprow)->par() == row->par()) {
2597 tmprow->pos(tmprow->pos() - 1);
2602 // is there a break one row above
2603 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2604 z = rowBreakPoint(*boost::prior(row));
2605 if (z >= row->pos()) {
2608 RowList::iterator tmprow = boost::prior(row);
2610 // maybe the current row is now empty
2611 if (row->pos() >= row->par()->size()) {
2614 need_break_row = rows().end();
2616 breakAgainOneRow(row);
2617 if (boost::next(row) != rows().end() &&
2618 boost::next(row)->par() == row->par())
2619 need_break_row = boost::next(row);
2621 need_break_row = rows().end();
2624 // set the dimensions of the row above
2625 y -= tmprow->height();
2626 tmprow->fill(fill(tmprow, workWidth()));
2627 setHeightOfRow(tmprow);
2631 setCursor(cursor.par(), cursor.pos(),
2632 false, cursor.boundary());
2633 //current_font = rawtmpfont;
2634 //real_current_font = realtmpfont;
2635 // check, whether the last character's font has changed.
2637 cursor.par()->getFontSettings(bv()->buffer()->params,
2638 cursor.par()->size() - 1))
2639 redoHeightOfParagraph();
2644 // break the cursor row again
2645 if (boost::next(row) != rows().end() &&
2646 boost::next(row)->par() == row->par() &&
2647 (lastPos(*this, row) == row->par()->size() - 1 ||
2648 rowBreakPoint(*row) != lastPos(*this, row))) {
2650 // it can happen that a paragraph loses one row
2651 // without a real breakup. This is when a word
2652 // is to long to be broken. Well, I don t care this
2654 if (lastPos(*this, row) == row->par()->size() - 1)
2655 removeRow(boost::next(row));
2659 breakAgainOneRow(row);
2660 // will the cursor be in another row now?
2661 if (boost::next(row) != rows().end() &&
2662 boost::next(row)->par() == row->par() &&
2663 lastPos(*this, row) <= cursor.pos()) {
2665 breakAgainOneRow(row);
2668 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2670 if (boost::next(row) != rows().end() &&
2671 boost::next(row)->par() == row->par())
2672 need_break_row = boost::next(row);
2674 need_break_row = rows().end();
2676 // set the dimensions of the row
2677 row->fill(fill(row, workWidth()));
2678 int const tmpheight = row->height();
2679 setHeightOfRow(row);
2680 if (tmpheight == row->height()) {
2681 postRowPaint(row, y);
2685 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2689 // current_font = rawtmpfont;
2690 // real_current_font = realtmpfont;
2692 if (isBoundary(bv()->buffer(), cursor.par(), cursor.pos())
2693 != cursor.boundary())
2694 setCursor(cursor.par(), cursor.pos(), false,
2695 !cursor.boundary());
2697 lastpos = cursor.par()->size();
2698 if (cursor.pos() == lastpos)
2701 // check, whether the last characters font has changed.
2703 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2704 redoHeightOfParagraph();
2706 // now the special right address boxes
2707 if (cursor.par()->layout()->margintype
2708 == MARGIN_RIGHT_ADDRESS_BOX) {
2709 redoDrawingOfParagraph(cursor);
2715 // returns pointer to a specified row
2717 LyXText::getRow(Paragraph * par, pos_type pos, int & y) const
2722 return rowlist_.end();
2724 // find the first row of the specified paragraph
2725 RowList::iterator rit = rowlist_.begin();
2726 RowList::iterator end = rowlist_.end();
2727 while (boost::next(rit) != end && rit->par() != par) {
2732 // now find the wanted row
2733 while (rit->pos() < pos
2734 && boost::next(rit) != end
2735 && boost::next(rit)->par() == par
2736 && boost::next(rit)->pos() <= pos) {
2745 RowList::iterator LyXText::getRowNearY(int & y) const
2747 // If possible we should optimize this method. (Lgb)
2750 RowList::iterator rit = rowlist_.begin();
2751 RowList::iterator end = rowlist_.end();
2753 while (rit != end && boost::next(rit) != end && tmpy + rit->height() <= y) {
2754 tmpy += rit->height();
2758 // return the real y
2765 int LyXText::getDepth() const
2767 return cursor.par()->getDepth();