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 void LyXText::updateRowPositions()
79 RowList::iterator rit = rows().begin();
80 RowList::iterator rend = rows().end();
81 for (int y = 0; rit != rend ; ++rit) {
88 int LyXText::top_y() const
90 if (isInInset() || anchor_row_ == rowlist_.end() )
92 return anchor_row_->y() + anchor_row_offset_;
96 void LyXText::top_y(int newy)
98 if (rows().empty() || isInInset())
100 lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
103 RowList::iterator rit = getRowNearY(y);
105 if (rit == anchor_row_ && anchor_row_offset_ == newy - y) {
106 lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
111 anchor_row_offset_ = newy - y;
112 lyxerr[Debug::GUI] << "changing reference to row: " << &*anchor_row_
113 << " offset: " << anchor_row_offset_ << endl;
118 void LyXText::anchor_row(RowList::iterator rit)
121 anchor_row_offset_ = 0;
123 anchor_row_offset_ = old_y - top_y();
124 lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
125 << &*anchor_row_ << " offset: "
126 << anchor_row_offset_ << endl;
130 int LyXText::workWidth() const
133 // FIXME: pass (const ?) ref
134 return inset_owner->textWidth(bv());
136 return bv()->workWidth();
140 int LyXText::workWidth(Inset * inset) const
142 Paragraph * par = inset->parOwner();
145 pos_type pos = par->getPositionOfInset(inset);
146 lyx::Assert(pos != -1);
148 LyXLayout_ptr const & layout = par->layout();
150 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
151 // Optimization here: in most cases, the real row is
152 // not needed, but only the par/pos values. So we just
153 // construct a dummy row for leftMargin. (JMarc)
157 return workWidth() - leftMargin(dummyrow);
160 RowList::iterator row = getRow(par, pos, dummy_y);
161 RowList::iterator frow = row;
162 RowList::iterator beg = rowlist_.begin();
164 while (frow != beg && frow->par() == boost::prior(frow)->par())
167 // FIXME: I don't understand this code - jbl
169 unsigned int maxw = 0;
170 while (!isParEnd(*this, frow)) {
171 if ((frow != row) && (maxw < frow->width()))
172 maxw = frow->width();
183 int LyXText::getRealCursorX() const
186 if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
187 x = the_locking_inset->getLyXText(bv())->getRealCursorX();
192 #warning FIXME This function seems to belong outside of LyxText.
193 unsigned char LyXText::transformChar(unsigned char c, Paragraph const & par,
196 if (!Encodings::is_arabic(c))
197 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
198 return c + (0xb0 - '0');
202 unsigned char const prev_char = pos > 0 ? par.getChar(pos - 1) : ' ';
203 unsigned char next_char = ' ';
205 for (pos_type i = pos + 1; i < par.size(); ++i)
206 if (!Encodings::IsComposeChar_arabic(par.getChar(i))) {
207 next_char = par.getChar(i);
211 if (Encodings::is_arabic(next_char)) {
212 if (Encodings::is_arabic(prev_char) &&
213 !Encodings::is_arabic_special(prev_char))
214 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
216 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
218 if (Encodings::is_arabic(prev_char) &&
219 !Encodings::is_arabic_special(prev_char))
220 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
222 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
226 // This is the comments that some of the warnings below refers to.
227 // There are some issues in this file and I don't think they are
228 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
229 // this is a problem that has been here almost from day one and that a
230 // larger userbase with differenct access patters triggers the bad
231 // behaviour. (segfaults.) What I think happen is: In several places
232 // we store the paragraph in the current cursor and then moves the
233 // cursor. This movement of the cursor will delete paragraph at the
234 // old position if it is now empty. This will make the temporary
235 // pointer to the old cursor paragraph invalid and dangerous to use.
236 // And is some cases this will trigger a segfault. I have marked some
237 // of the cases where this happens with a warning, but I am sure there
238 // are others in this file and in text2.C. There is also a note in
239 // Delete() that you should read. In Delete I store the paragraph->id
240 // instead of a pointer to the paragraph. I am pretty sure this faulty
241 // use of temporary pointers to paragraphs that might have gotten
242 // invalidated (through a cursor movement) before they are used, are
243 // the cause of the strange crashes we get reported often.
245 // It is very tiresom to change this code, especially when it is as
246 // hard to read as it is. Help to fix all the cases where this is done
247 // would be greately appreciated.
251 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
253 if (pos >= pit->size())
256 char const c = pit->getChar(pos);
257 return singleWidth(pit, pos, c);
261 int LyXText::singleWidth(ParagraphList::iterator pit,
262 pos_type pos, char c) const
264 if (pos >= pit->size())
267 LyXFont const font = getFont(bv()->buffer(), pit, pos);
269 // The most common case is handled first (Asger)
270 if (IsPrintable(c)) {
271 if (font.language()->RightToLeft()) {
272 if (font.language()->lang() == "arabic" &&
273 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
274 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
275 if (Encodings::IsComposeChar_arabic(c))
278 c = transformChar(c, *pit, pos);
279 } else if (font.language()->lang() == "hebrew" &&
280 Encodings::IsComposeChar_hebrew(c))
283 return font_metrics::width(c, font);
287 if (c == Paragraph::META_INSET) {
288 Inset * tmpinset = pit->getInset(pos);
290 if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
291 // Because of the representation as vertical lines
295 #warning inset->update FIXME
296 // this IS needed otherwise on initialitation we don't get the fill
297 // of the row right (ONLY on initialization if we read a file!)
298 // should be changed! (Jug 20011204)
299 tmpinset->update(bv());
301 return tmpinset->width(bv(), font);
306 if (IsSeparatorChar(c))
308 return font_metrics::width(c, font);
312 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
314 if (bidi_start == -1)
317 return log2vis_list[pos - bidi_start];
321 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
323 if (bidi_start == -1)
326 return vis2log_list[pos - bidi_start];
330 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
332 if (bidi_start == -1)
335 return bidi_levels[pos - bidi_start];
339 bool LyXText::bidi_InRange(lyx::pos_type pos) const
341 return bidi_start == -1 ||
342 (bidi_start <= pos && pos <= bidi_end);
346 void LyXText::computeBidiTables(Buffer const * buf,
347 RowList::iterator row) const
349 bidi_same_direction = true;
350 if (!lyxrc.rtl_support) {
355 Inset * inset = row->par()->inInset();
356 if (inset && inset->owner() &&
357 inset->owner()->lyxCode() == Inset::ERT_CODE) {
362 bidi_start = row->pos();
363 bidi_end = lastPrintablePos(*this, row);
365 if (bidi_start > bidi_end) {
370 if (bidi_end + 2 - bidi_start >
371 static_cast<pos_type>(log2vis_list.size())) {
373 (bidi_end + 2 - bidi_start < 500) ?
374 500 : 2 * (bidi_end + 2 - bidi_start);
375 log2vis_list.resize(new_size);
376 vis2log_list.resize(new_size);
377 bidi_levels.resize(new_size);
380 vis2log_list[bidi_end + 1 - bidi_start] = -1;
381 log2vis_list[bidi_end + 1 - bidi_start] = -1;
385 row->par()->isRightToLeftPar(buf->params);
389 pos_type const body_pos = row->par()->beginningOfBody();
391 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
392 bool is_space = row->par()->isLineSeparator(lpos);
394 (is_space && lpos + 1 <= bidi_end &&
395 !row->par()->isLineSeparator(lpos + 1) &&
396 !row->par()->isNewline(lpos + 1))
398 LyXFont font = row->par()->getFontSettings(buf->params, pos);
399 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
400 font.number() == LyXFont::ON &&
401 row->par()->getFontSettings(buf->params, lpos - 1).number()
403 font = row->par()->getFontSettings(buf->params, lpos);
408 bool new_rtl = font.isVisibleRightToLeft();
409 bool new_rtl0 = font.isRightToLeft();
412 if (lpos == body_pos - 1
413 && row->pos() < body_pos - 1
415 new_level = (rtl_par) ? 1 : 0;
416 new_rtl = new_rtl0 = rtl_par;
418 new_level = (new_rtl) ? 1 : 2;
420 new_level = (rtl_par) ? 2 : 0;
422 if (is_space && new_level >= level) {
428 int new_level2 = new_level;
430 if (level == new_level && rtl0 != new_rtl0) {
432 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
433 } else if (level < new_level) {
434 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
435 if (new_level > rtl_par)
436 bidi_same_direction = false;
438 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
441 bidi_levels[lpos - bidi_start] = new_level;
443 while (level > new_level2) {
444 pos_type old_lpos = stack[--level];
445 int delta = lpos - old_lpos - 1;
448 log2vis_list[lpos - bidi_start] += delta;
449 log2vis_list[old_lpos - bidi_start] += delta;
451 while (level < new_level)
452 stack[level++] = lpos;
456 pos_type const old_lpos = stack[--level];
457 int delta = bidi_end - old_lpos;
460 log2vis_list[old_lpos - bidi_start] += delta;
463 pos_type vpos = bidi_start - 1;
464 for (pos_type lpos = bidi_start;
465 lpos <= bidi_end; ++lpos) {
466 vpos += log2vis_list[lpos - bidi_start];
467 vis2log_list[vpos - bidi_start] = lpos;
468 log2vis_list[lpos - bidi_start] = vpos;
473 // This method requires a previous call to ComputeBidiTables()
474 bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
477 if (!lyxrc.rtl_support || pos == 0)
480 if (!bidi_InRange(pos - 1)) {
481 /// This can happen if pos is the first char of a row.
482 /// Returning false in this case is incorrect!
486 bool const rtl = bidi_level(pos - 1) % 2;
487 bool const rtl2 = bidi_InRange(pos)
488 ? bidi_level(pos) % 2
489 : par->isRightToLeftPar(buf->params);
494 bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
495 pos_type pos, LyXFont const & font) const
497 if (!lyxrc.rtl_support)
498 return false; // This is just for speedup
500 bool const rtl = font.isVisibleRightToLeft();
501 bool const rtl2 = bidi_InRange(pos)
502 ? bidi_level(pos) % 2
503 : par->isRightToLeftPar(buf->params);
508 int LyXText::leftMargin(Row const & row) const
512 if (row.pos() < row.par()->size())
513 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
514 (ins = row.par()->getInset(row.pos())) &&
515 (ins->needFullRow() || ins->display()))
518 LyXTextClass const & tclass =
519 bv()->buffer()->params.getLyXTextClass();
520 LyXLayout_ptr const & layout = row.par()->layout();
522 string parindent = layout->parindent;
526 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
528 // this is the way, LyX handles the LaTeX-Environments.
529 // I have had this idea very late, so it seems to be a
530 // later added hack and this is true
531 if (!row.par()->getDepth()) {
532 if (row.par()->layout() == tclass.defaultLayout()) {
533 // find the previous same level paragraph
534 if (row.par()->previous()) {
535 Paragraph * newpar = row.par()
536 ->depthHook(row.par()->getDepth());
538 newpar->layout()->nextnoindent)
543 // find the next level paragraph
545 Paragraph * newpar = row.par()->outerHook();
547 // make a corresponding row. Needed to call leftMargin()
549 // check wether it is a sufficent paragraph
550 if (newpar && newpar->layout()->isEnvironment()) {
552 dummyrow.par(newpar);
553 dummyrow.pos(newpar->size());
554 x = leftMargin(dummyrow);
557 if (newpar && row.par()->layout() == tclass.defaultLayout()) {
558 if (newpar->params().noindent())
561 parindent = newpar->layout()->parindent;
567 LyXFont const labelfont = getLabelFont(bv()->buffer(), row.par());
568 switch (layout->margintype) {
570 if (!layout->leftmargin.empty()) {
571 x += font_metrics::signedWidth(layout->leftmargin,
572 tclass.defaultfont());
574 if (!row.par()->getLabelstring().empty()) {
575 x += font_metrics::signedWidth(layout->labelindent,
577 x += font_metrics::width(row.par()->getLabelstring(),
579 x += font_metrics::width(layout->labelsep, labelfont);
583 x += font_metrics::signedWidth(layout->labelindent, labelfont);
584 // The width of an empty par, even with manual label, should be 0
585 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
586 if (!row.par()->getLabelWidthString().empty()) {
587 x += font_metrics::width(row.par()->getLabelWidthString(),
589 x += font_metrics::width(layout->labelsep, labelfont);
594 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
595 / (row.par()->getDepth() + 4);
597 case MARGIN_FIRST_DYNAMIC:
598 if (layout->labeltype == LABEL_MANUAL) {
599 if (row.pos() >= row.par()->beginningOfBody()) {
600 x += font_metrics::signedWidth(layout->leftmargin,
603 x += font_metrics::signedWidth(layout->labelindent,
607 // Special case to fix problems with
609 || (layout->labeltype == LABEL_STATIC
610 && layout->latextype == LATEX_ENVIRONMENT
611 && ! row.par()->isFirstInSequence())) {
612 x += font_metrics::signedWidth(layout->leftmargin,
614 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
615 && layout->labeltype != LABEL_BIBLIO
616 && layout->labeltype !=
617 LABEL_CENTERED_TOP_ENVIRONMENT) {
618 x += font_metrics::signedWidth(layout->labelindent,
620 x += font_metrics::width(layout->labelsep, labelfont);
621 x += font_metrics::width(row.par()->getLabelstring(),
626 case MARGIN_RIGHT_ADDRESS_BOX:
628 // ok, a terrible hack. The left margin depends on the widest
629 // row in this paragraph. Do not care about footnotes, they
630 // are *NOT* allowed in the LaTeX realisation of this layout.
632 // find the first row of this paragraph
633 RowList::iterator tmprit = rowlist_.begin();
634 while (tmprit != rowlist_.end()
635 && tmprit->par() != row.par())
638 int minfill = tmprit->fill();
639 while (boost::next(tmprit) != rowlist_.end() &&
640 boost::next(tmprit)->par() == row.par()) {
642 if (tmprit->fill() < minfill)
643 minfill = tmprit->fill();
646 x += font_metrics::signedWidth(layout->leftmargin,
647 tclass.defaultfont());
653 if ((workWidth() > 0) &&
654 !row.par()->params().leftIndent().zero())
656 LyXLength const len = row.par()->params().leftIndent();
657 int const tw = inset_owner ?
658 inset_owner->latexTextWidth(bv()) : workWidth();
659 x += len.inPixels(tw);
662 LyXAlignment align; // wrong type
664 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
665 align = layout->align;
667 align = row.par()->params().align();
669 // set the correct parindent
670 if (row.pos() == 0) {
671 if ((layout->labeltype == LABEL_NO_LABEL
672 || layout->labeltype == LABEL_TOP_ENVIRONMENT
673 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
674 || (layout->labeltype == LABEL_STATIC
675 && layout->latextype == LATEX_ENVIRONMENT
676 && ! row.par()->isFirstInSequence()))
677 && align == LYX_ALIGN_BLOCK
678 && !row.par()->params().noindent()
679 // in tabulars and ert paragraphs are never indented!
680 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
681 (row.par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
682 row.par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
683 && (row.par()->layout() != tclass.defaultLayout() ||
684 bv()->buffer()->params.paragraph_separation ==
685 BufferParams::PARSEP_INDENT)) {
686 x += font_metrics::signedWidth(parindent,
687 tclass.defaultfont());
688 } else if (layout->labeltype == LABEL_BIBLIO) {
689 // ale970405 Right width for bibitems
690 x += bibitemMaxWidth(bv(), tclass.defaultfont());
698 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
702 if (row.pos() < row.par()->size())
703 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
704 (ins = row.par()->getInset(row.pos())) &&
705 (ins->needFullRow() || ins->display()))
708 LyXTextClass const & tclass = buf.params.getLyXTextClass();
709 LyXLayout_ptr const & layout = row.par()->layout();
712 + font_metrics::signedWidth(tclass.rightmargin(),
713 tclass.defaultfont());
715 x += font_metrics::signedWidth(layout->rightmargin,
716 tclass.defaultfont())
717 * 4 / (row.par()->getDepth() + 4);
722 int LyXText::labelEnd(Row const & row) const
724 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
726 tmprow.pos(row.par()->size());
727 // return the beginning of the body
728 return leftMargin(tmprow);
731 // LabelEnd is only needed if the layout
732 // fills a flushleft label.
739 // this needs special handling - only newlines count as a break point
740 pos_type addressBreakPoint(pos_type i, Paragraph * par)
742 for (; i < par->size(); ++i) {
743 if (par->isNewline(i))
754 LyXText::rowBreakPoint(Row const & row) const
756 ParagraphList::iterator pit = row.par();
758 // maximum pixel width of a row.
759 int width = workWidth() - rightMargin(*bv()->buffer(), row);
761 // inset->textWidth() returns -1 via workWidth(),
766 LyXLayout_ptr const & layout = pit->layout();
768 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
769 return addressBreakPoint(row.pos(), &*pit);
771 pos_type const pos = row.pos();
772 pos_type const body_pos = pit->beginningOfBody();
773 pos_type const last = pit->size();
774 pos_type point = last;
779 // Now we iterate through until we reach the right margin
780 // or the end of the par, then choose the possible break
783 int const left = leftMargin(const_cast<Row&>(row));
786 // pixel width since last breakpoint
788 bool fullrow = false;
791 for (; i < last; ++i) {
792 if (pit->isNewline(i)) {
797 char const c = pit->getChar(i);
801 // add the auto-hfill from label end to the body
802 if (body_pos && i == body_pos) {
803 thiswidth = font_metrics::width(layout->labelsep,
804 getLabelFont(bv()->buffer(), pit));
805 if (pit->isLineSeparator(i - 1))
806 thiswidth -= singleWidth(pit, i - 1);
807 int left_margin = labelEnd(row);
808 if (thiswidth + x < left_margin)
809 thiswidth = left_margin - x;
810 thiswidth += singleWidth(pit, i, c);
812 thiswidth = singleWidth(pit, i, c);
816 chunkwidth += thiswidth;
818 Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
819 fullrow = (in && (in->display() || in->needFullRow()));
821 // break before a character that will fall off
822 // the right of the row
824 // if no break before or we are at an inset
825 // that will take up a row, break here
826 if (point == last || fullrow || chunkwidth >= (width - left)) {
835 if (!in || in->isChar()) {
836 // some insets are line separators too
837 if (pit->isLineSeparator(i)) {
847 // full row insets start at a new row
849 if (pos < last - 1) {
851 if (pit->isLineSeparator(i + 1))
854 // to avoid extra rows
864 if (point == last && x >= width) {
865 // didn't find one, break at the point we reached the edge
867 } else if (i == last && x < width) {
868 // found one, but we fell off the end of the par, so prefer
873 // manual labels cannot be broken in LaTeX. But we
874 // want to make our on-screen rendering of footnotes
876 if (!fullrow && body_pos && point < body_pos)
877 point = body_pos - 1;
883 // returns the minimum space a row needs on the screen in pixel
884 int LyXText::fill(RowList::iterator row, int paper_width) const
890 // get the pure distance
891 pos_type const last = lastPrintablePos(*this, row);
893 // special handling of the right address boxes
894 if (row->par()->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
895 int const tmpfill = row->fill();
896 row->fill(0); // the minfill in MarginLeft()
897 w = leftMargin(*row);
900 w = leftMargin(*row);
902 ParagraphList::iterator pit = row->par();
903 LyXLayout_ptr const & layout = pit->layout();
905 pos_type const body_pos = pit->beginningOfBody();
906 pos_type i = row->pos();
909 if (body_pos > 0 && i == body_pos) {
910 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
911 if (pit->isLineSeparator(i - 1))
912 w -= singleWidth(pit, i - 1);
913 int left_margin = labelEnd(*row);
917 w += singleWidth(pit, i);
920 if (body_pos > 0 && body_pos > last) {
921 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
922 if (last >= 0 && pit->isLineSeparator(last))
923 w -= singleWidth(pit, last);
924 int const left_margin = labelEnd(*row);
929 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
931 // If this case happens, it means that our calculation
932 // of the widths of the chars when we do rowBreakPoint()
933 // went wrong for some reason. Typically in list bodies.
934 // Things just about hobble on anyway, though you'll end
935 // up with a "fill_separator" less than zero, which corresponds
936 // to inter-word spacing being too small. Hopefully this problem
937 // will die when the label hacks die.
938 if (lyxerr.debugging() && fill < 0) {
939 lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
940 << " w " << w << " paper_width " << paper_width
941 << " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
948 // returns the minimum space a manual label needs on the screen in pixel
949 int LyXText::labelFill(Row const & row) const
951 pos_type last = row.par()->beginningOfBody();
953 lyx::Assert(last > 0);
955 // -1 because a label ends either with a space that is in the label,
956 // or with the beginning of a footnote that is outside the label.
959 // a separator at this end does not count
960 if (row.par()->isLineSeparator(last))
964 pos_type i = row.pos();
966 w += singleWidth(row.par(), i);
971 string const & labwidstr = row.par()->params().labelWidthString();
972 if (!labwidstr.empty()) {
973 LyXFont const labfont = getLabelFont(bv()->buffer(), row.par());
974 int const labwidth = font_metrics::width(labwidstr, labfont);
975 fill = max(labwidth - w, 0);
982 LColor::color LyXText::backgroundColor() const
985 return inset_owner->backgroundColor();
987 return LColor::background;
991 void LyXText::setHeightOfRow(RowList::iterator rit)
993 // No need to do anything then...
994 if (rit == rows().end())
997 // get the maximum ascent and the maximum descent
1000 float layoutasc = 0;
1001 float layoutdesc = 0;
1004 Inset * tmpinset = 0;
1006 // ok , let us initialize the maxasc and maxdesc value.
1007 // This depends in LaTeX of the font of the last character
1008 // in the paragraph. The hack below is necessary because
1009 // of the possibility of open footnotes
1011 // Correction: only the fontsize count. The other properties
1012 // are taken from the layoutfont. Nicer on the screen :)
1013 ParagraphList::iterator pit = rit->par();
1014 ParagraphList::iterator firstpit = pit;
1016 LyXLayout_ptr const & layout = firstpit->layout();
1018 // as max get the first character of this row then it can increase but not
1019 // decrease the height. Just some point to start with so we don't have to
1020 // do the assignment below too often.
1021 LyXFont font = getFont(bv()->buffer(), pit, rit->pos());
1022 LyXFont::FONT_SIZE const tmpsize = font.size();
1023 font = getLayoutFont(bv()->buffer(), pit);
1024 LyXFont::FONT_SIZE const size = font.size();
1025 font.setSize(tmpsize);
1027 LyXFont labelfont = getLabelFont(bv()->buffer(), pit);
1029 float spacing_val = 1.0;
1030 if (!rit->par()->params().spacing().isDefault()) {
1031 spacing_val = rit->par()->params().spacing().getValue();
1033 spacing_val = bv()->buffer()->params.spacing.getValue();
1035 //lyxerr << "spacing_val = " << spacing_val << endl;
1037 int maxasc = int(font_metrics::maxAscent(font) *
1038 layout->spacing.getValue() *
1040 int maxdesc = int(font_metrics::maxDescent(font) *
1041 layout->spacing.getValue() *
1044 pos_type const pos_end = lastPos(*this, rit);
1048 if (!rit->par()->empty()) {
1049 // Check if any insets are larger
1050 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1051 if (rit->par()->isInset(pos)) {
1052 tmpfont = getFont(bv()->buffer(), rit->par(), pos);
1053 tmpinset = rit->par()->getInset(pos);
1055 #if 1 // this is needed for deep update on initialitation
1056 #warning inset->update FIXME
1057 tmpinset->update(bv());
1059 asc = tmpinset->ascent(bv(), tmpfont);
1060 desc = tmpinset->descent(bv(), tmpfont);
1061 maxwidth += tmpinset->width(bv(), tmpfont);
1062 maxasc = max(maxasc, asc);
1063 maxdesc = max(maxdesc, desc);
1066 maxwidth += singleWidth(rit->par(), pos);
1071 // Check if any custom fonts are larger (Asger)
1072 // This is not completely correct, but we can live with the small,
1073 // cosmetic error for now.
1074 LyXFont::FONT_SIZE maxsize =
1075 rit->par()->highestFontInRange(rit->pos(), pos_end, size);
1076 if (maxsize > font.size()) {
1077 font.setSize(maxsize);
1079 asc = font_metrics::maxAscent(font);
1080 desc = font_metrics::maxDescent(font);
1087 // This is nicer with box insets:
1091 rit->ascent_of_text(maxasc);
1093 // is it a top line?
1094 if (!rit->pos() && (rit->par() == firstpit)) {
1096 // some parksips VERY EASY IMPLEMENTATION
1097 if (bv()->buffer()->params.paragraph_separation ==
1098 BufferParams::PARSEP_SKIP)
1100 if (layout->isParagraph()
1101 && firstpit->getDepth() == 0
1102 && firstpit->previous())
1104 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1105 } else if (firstpit->previous() &&
1106 firstpit->previous()->layout()->isParagraph() &&
1107 firstpit->previous()->getDepth() == 0)
1109 // is it right to use defskip here too? (AS)
1110 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1115 if (!rit->par()->previous() && !isInInset())
1116 maxasc += PAPER_MARGIN;
1118 // add the vertical spaces, that the user added
1119 maxasc += getLengthMarkerHeight(*bv(), firstpit->params().spaceTop());
1121 // do not forget the DTP-lines!
1122 // there height depends on the font of the nearest character
1123 if (firstpit->params().lineTop())
1125 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1127 // and now the pagebreaks
1128 if (firstpit->params().pagebreakTop())
1129 maxasc += 3 * defaultRowHeight();
1131 if (firstpit->params().startOfAppendix())
1132 maxasc += 3 * defaultRowHeight();
1134 // This is special code for the chapter, since the label of this
1135 // layout is printed in an extra row
1136 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1137 && bv()->buffer()->params.secnumdepth >= 0)
1139 float spacing_val = 1.0;
1140 if (!rit->par()->params().spacing().isDefault()) {
1141 spacing_val = rit->par()->params().spacing().getValue();
1143 spacing_val = bv()->buffer()->params.spacing.getValue();
1146 labeladdon = int(font_metrics::maxDescent(labelfont) *
1147 layout->spacing.getValue() *
1149 + int(font_metrics::maxAscent(labelfont) *
1150 layout->spacing.getValue() *
1154 // special code for the top label
1155 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1156 || layout->labeltype == LABEL_BIBLIO
1157 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1158 && rit->par()->isFirstInSequence()
1159 && !rit->par()->getLabelstring().empty())
1161 float spacing_val = 1.0;
1162 if (!rit->par()->params().spacing().isDefault()) {
1163 spacing_val = rit->par()->params().spacing().getValue();
1165 spacing_val = bv()->buffer()->params.spacing.getValue();
1169 (font_metrics::maxAscent(labelfont) *
1170 layout->spacing.getValue() *
1172 +(font_metrics::maxDescent(labelfont) *
1173 layout->spacing.getValue() *
1175 + layout->topsep * defaultRowHeight()
1176 + layout->labelbottomsep * defaultRowHeight());
1179 // and now the layout spaces, for example before and after a section,
1180 // or between the items of a itemize or enumerate environment
1182 if (!firstpit->params().pagebreakTop()) {
1183 Paragraph * prev = rit->par()->previous();
1185 prev = rit->par()->depthHook(rit->par()->getDepth());
1186 if (prev && prev->layout() == firstpit->layout() &&
1187 prev->getDepth() == firstpit->getDepth() &&
1188 prev->getLabelWidthString() == firstpit->getLabelWidthString())
1190 layoutasc = (layout->itemsep * defaultRowHeight());
1191 } else if (rit != rows().begin()) {
1192 tmptop = layout->topsep;
1194 if (boost::prior(rit)->par()->getDepth() >= rit->par()->getDepth())
1195 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1198 layoutasc = (tmptop * defaultRowHeight());
1199 } else if (rit->par()->params().lineTop()) {
1200 tmptop = layout->topsep;
1203 layoutasc = (tmptop * defaultRowHeight());
1206 prev = rit->par()->outerHook();
1208 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1210 if (firstpit->previous() &&
1211 firstpit->previous()->getDepth() == 0 &&
1212 firstpit->previous()->layout() !=
1216 } else if (firstpit->previous()) {
1217 maxasc += int(layout->parsep * defaultRowHeight());
1223 // is it a bottom line?
1224 if (rit->par() == pit
1225 && (boost::next(rit) == rows().end() ||
1226 boost::next(rit)->par() != rit->par())) {
1227 // the bottom margin
1228 if (boost::next(pit) == ownerParagraphs().end() &&
1230 maxdesc += PAPER_MARGIN;
1232 // add the vertical spaces, that the user added
1233 maxdesc += getLengthMarkerHeight(*bv(), firstpit->params().spaceBottom());
1235 // do not forget the DTP-lines!
1236 // there height depends on the font of the nearest character
1237 if (firstpit->params().lineBottom())
1238 maxdesc += 2 * font_metrics::ascent('x',
1239 getFont(bv()->buffer(),
1241 max(pos_type(0), pit->size() - 1)));
1243 // and now the pagebreaks
1244 if (firstpit->params().pagebreakBottom())
1245 maxdesc += 3 * defaultRowHeight();
1247 // and now the layout spaces, for example before and after
1248 // a section, or between the items of a itemize or enumerate
1250 if (!firstpit->params().pagebreakBottom()
1251 && rit->par()->next()) {
1252 ParagraphList::iterator nextpit = boost::next(rit->par());
1253 ParagraphList::iterator comparepit = rit->par();
1257 if (comparepit->getDepth() > nextpit->getDepth()) {
1258 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1259 comparepit = comparepit->depthHook(nextpit->getDepth());
1260 if (comparepit->layout()!= nextpit->layout()
1261 || nextpit->getLabelWidthString() !=
1262 comparepit->getLabelWidthString())
1264 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1266 if (unusual > usual)
1267 layoutdesc = unusual;
1270 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1272 if (comparepit->layout() != nextpit->layout()
1273 || nextpit->getLabelWidthString() !=
1274 comparepit->getLabelWidthString())
1275 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1280 // incalculate the layout spaces
1281 maxasc += int(layoutasc * 2 / (2 + firstpit->getDepth()));
1282 maxdesc += int(layoutdesc * 2 / (2 + firstpit->getDepth()));
1284 // calculate the new height of the text
1285 height -= rit->height();
1287 rit->height(maxasc + maxdesc + labeladdon);
1288 rit->baseline(maxasc + labeladdon);
1290 height += rit->height();
1292 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1295 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1298 rit->width(maxwidth);
1299 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1301 rit->width(int(maxwidth + x));
1303 width = max(0, workWidth());
1304 RowList::iterator it = rows().begin();
1305 RowList::iterator end = rows().end();
1306 for (; it != end; ++it) {
1307 if (it->width() > width)
1308 width = it->width();
1314 // Appends the implicit specified paragraph before the specified row,
1315 // start at the implicit given position
1316 void LyXText::appendParagraph(RowList::iterator rowit)
1318 lyx::Assert(rowit != rowlist_.end());
1320 pos_type const last = rowit->par()->size();
1324 pos_type z = rowBreakPoint(*rowit);
1326 RowList::iterator tmprow = rowit;
1330 Row newrow(rowit->par(), z);
1331 rowit = rowlist_.insert(boost::next(rowit), newrow);
1336 // Set the dimensions of the row
1337 // fixed fill setting now by calling inset->update() in
1338 // SingleWidth when needed!
1339 tmprow->fill(fill(tmprow, workWidth()));
1340 setHeightOfRow(tmprow);
1346 void LyXText::breakAgain(RowList::iterator rit)
1348 lyx::Assert(rit != rows().end());
1350 bool not_ready = true;
1353 pos_type z = rowBreakPoint(*rit);
1354 RowList::iterator tmprit = rit;
1355 RowList::iterator end = rows().end();
1357 if (z < rit->par()->size()) {
1358 if (boost::next(rit) == end ||
1359 (boost::next(rit) != end &&
1360 boost::next(rit)->par() != rit->par())) {
1363 Row newrow(rit->par(), z);
1364 rit = rowlist_.insert(boost::next(rit), newrow);
1368 if (rit->pos() == z)
1369 not_ready = false; // the rest will not change
1375 // if there are some rows too much, delete them
1376 // only if you broke the whole paragraph!
1377 RowList::iterator tmprit2 = rit;
1378 while (boost::next(tmprit2) != end
1379 && boost::next(tmprit2)->par() == rit->par()) {
1382 while (tmprit2 != rit) {
1384 removeRow(boost::next(tmprit2));
1389 // set the dimensions of the row
1390 tmprit->fill(fill(tmprit, workWidth()));
1391 setHeightOfRow(tmprit);
1392 } while (not_ready);
1396 // this is just a little changed version of break again
1397 void LyXText::breakAgainOneRow(RowList::iterator rit)
1399 lyx::Assert(rit != rows().end());
1401 pos_type z = rowBreakPoint(*rit);
1402 RowList::iterator tmprit = rit;
1403 RowList::iterator end = rows().end();
1405 if (z < rit->par()->size()) {
1406 if (boost::next(rit) == end ||
1407 (boost::next(rit) != end &&
1408 boost::next(rit)->par() != rit->par())) {
1411 Row newrow(rit->par(), z);
1412 rit = rowlist_.insert(boost::next(rit), newrow);
1416 if (rit->pos() != z)
1420 // if there are some rows too much, delete them
1421 // only if you broke the whole paragraph!
1422 RowList::iterator tmprit2 = rit;
1423 while (boost::next(tmprit2) != end
1424 && boost::next(tmprit2)->par() == rit->par()) {
1427 while (tmprit2 != rit) {
1429 removeRow(boost::next(tmprit2));
1433 // set the dimensions of the row
1434 tmprit->fill(fill(tmprit, workWidth()));
1435 setHeightOfRow(tmprit);
1439 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1441 // allow only if at start or end, or all previous is new text
1442 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1443 && cursor.par()->isChangeEdited(0, cursor.pos()))
1446 LyXTextClass const & tclass =
1447 bv()->buffer()->params.getLyXTextClass();
1448 LyXLayout_ptr const & layout = cursor.par()->layout();
1450 // this is only allowed, if the current paragraph is not empty or caption
1451 // and if it has not the keepempty flag aktive
1452 if (cursor.par()->empty()
1453 && layout->labeltype != LABEL_SENSITIVE
1454 && !layout->keepempty)
1457 setUndo(bv(), Undo::FINISH, &*cursor.par(), &*boost::next(cursor.par()));
1459 // Always break behind a space
1461 // It is better to erase the space (Dekel)
1462 if (cursor.pos() < cursor.par()->size()
1463 && cursor.par()->isLineSeparator(cursor.pos()))
1464 cursor.par()->erase(cursor.pos());
1465 // cursor.pos(cursor.pos() + 1);
1467 // break the paragraph
1471 keep_layout = layout->isEnvironment();
1473 // we need to set this before we insert the paragraph. IMO the
1474 // breakParagraph call should return a bool if it inserts the
1475 // paragraph before or behind and we should react on that one
1476 // but we can fix this in 1.3.0 (Jug 20020509)
1477 bool const isempty = (layout->keepempty && cursor.par()->empty());
1478 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
1481 // well this is the caption hack since one caption is really enough
1482 if (layout->labeltype == LABEL_SENSITIVE) {
1484 // set to standard-layout
1485 cursor.par()->applyLayout(tclass.defaultLayout());
1487 // set to standard-layout
1488 cursor.par()->next()->applyLayout(tclass.defaultLayout());
1491 // if the cursor is at the beginning of a row without prior newline,
1493 // This touches only the screen-update. Otherwise we would may have
1494 // an empty row on the screen
1495 if (cursor.pos() && cursor.row()->pos() == cursor.pos()
1496 && !cursor.row()->par()->isNewline(cursor.pos() - 1))
1501 int y = cursor.y() - cursor.row()->baseline();
1503 // Do not forget the special right address boxes
1504 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1505 RowList::iterator r = cursor.row();
1506 while (r != rows().begin() && boost::prior(r)->par() == r->par()) {
1514 removeParagraph(cursor.row());
1516 // set the dimensions of the cursor row
1517 cursor.row()->fill(fill(cursor.row(), workWidth()));
1519 setHeightOfRow(cursor.row());
1521 #warning Trouble Point! (Lgb)
1522 // When ::breakParagraph is called from within an inset we must
1523 // ensure that the correct ParagraphList is used. Today that is not
1524 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1525 while (!cursor.par()->next()->empty()
1526 && cursor.par()->next()->isNewline(0))
1527 cursor.par()->next()->erase(0);
1529 insertParagraph(cursor.par()->next(), boost::next(cursor.row()));
1532 // This check is necessary. Otherwise the new empty paragraph will
1533 // be deleted automatically. And it is more friendly for the user!
1534 if (cursor.pos() || isempty)
1535 setCursor(cursor.par()->next(), 0);
1537 setCursor(cursor.par(), 0);
1539 if (boost::next(cursor.row()) != rows().end())
1540 breakAgain(boost::next(cursor.row()));
1542 need_break_row = rows().end();
1546 // Just a macro to make some thing easier.
1547 void LyXText::redoParagraph()
1550 redoParagraphs(cursor, cursor.par()->next());
1551 setCursorIntern(cursor.par(), cursor.pos());
1555 // insert a character, moves all the following breaks in the
1556 // same Paragraph one to the right and make a rebreak
1557 void LyXText::insertChar(char c)
1559 setUndo(bv(), Undo::INSERT, &*cursor.par(), &*boost::next(cursor.par()));
1561 // When the free-spacing option is set for the current layout,
1562 // disable the double-space checking
1564 bool const freeSpacing = cursor.row()->par()->layout()->free_spacing ||
1565 cursor.row()->par()->isFreeSpacing();
1567 if (lyxrc.auto_number) {
1568 static string const number_operators = "+-/*";
1569 static string const number_unary_operators = "+-";
1570 static string const number_seperators = ".,:";
1572 if (current_font.number() == LyXFont::ON) {
1573 if (!IsDigit(c) && !contains(number_operators, c) &&
1574 !(contains(number_seperators, c) &&
1575 cursor.pos() >= 1 &&
1576 cursor.pos() < cursor.par()->size() &&
1577 getFont(bv()->buffer(),
1579 cursor.pos()).number() == LyXFont::ON &&
1580 getFont(bv()->buffer(),
1582 cursor.pos() - 1).number() == LyXFont::ON)
1584 number(bv()); // Set current_font.number to OFF
1585 } else if (IsDigit(c) &&
1586 real_current_font.isVisibleRightToLeft()) {
1587 number(bv()); // Set current_font.number to ON
1589 if (cursor.pos() > 0) {
1590 char const c = cursor.par()->getChar(cursor.pos() - 1);
1591 if (contains(number_unary_operators, c) &&
1592 (cursor.pos() == 1 ||
1593 cursor.par()->isSeparator(cursor.pos() - 2) ||
1594 cursor.par()->isNewline(cursor.pos() - 2))
1596 setCharFont(bv()->buffer(),
1600 } else if (contains(number_seperators, c) &&
1601 cursor.pos() >= 2 &&
1602 getFont(bv()->buffer(),
1604 cursor.pos() - 2).number() == LyXFont::ON) {
1605 setCharFont(bv()->buffer(),
1615 // First check, if there will be two blanks together or a blank at
1616 // the beginning of a paragraph.
1617 // I decided to handle blanks like normal characters, the main
1618 // difference are the special checks when calculating the row.fill
1619 // (blank does not count at the end of a row) and the check here
1621 // The bug is triggered when we type in a description environment:
1622 // The current_font is not changed when we go from label to main text
1623 // and it should (along with realtmpfont) when we type the space.
1624 // CHECK There is a bug here! (Asger)
1626 LyXFont realtmpfont = real_current_font;
1627 LyXFont rawtmpfont = current_font;
1628 // store the current font. This is because of the use of cursor
1629 // movements. The moving cursor would refresh the current font
1631 // Get the font that is used to calculate the baselineskip
1632 pos_type const lastpos = cursor.par()->size();
1633 LyXFont rawparfont =
1634 cursor.par()->getFontSettings(bv()->buffer()->params,
1637 bool jumped_over_space = false;
1639 if (!freeSpacing && IsLineSeparatorChar(c)) {
1640 if ((cursor.pos() > 0
1641 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1642 || (cursor.pos() > 0
1643 && cursor.par()->isNewline(cursor.pos() - 1))
1644 || (cursor.pos() == 0)) {
1645 static bool sent_space_message = false;
1646 if (!sent_space_message) {
1647 if (cursor.pos() == 0)
1648 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1650 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1651 sent_space_message = true;
1658 // the display inset stuff
1659 if (cursor.row()->pos() < cursor.row()->par()->size()
1660 && cursor.row()->par()->isInset(cursor.row()->pos())) {
1661 Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
1662 if (inset && (inset->display() || inset->needFullRow())) {
1663 // force a new break
1664 cursor.row()->fill(-1); // to force a new break
1668 // get the cursor row fist
1669 RowList::iterator row = cursor.row();
1670 int y = cursor.y() - row->baseline();
1671 if (c != Paragraph::META_INSET) {
1672 // Here case LyXText::InsertInset already insertet the character
1673 cursor.par()->insertChar(cursor.pos(), c);
1675 setCharFont(bv()->buffer(), &*cursor.par(), cursor.pos(), rawtmpfont);
1677 if (!jumped_over_space) {
1678 // refresh the positions
1679 RowList::iterator tmprow = row;
1680 while (boost::next(tmprow) != rows().end() &&
1681 boost::next(tmprow)->par() == row->par()) {
1683 tmprow->pos(tmprow->pos() + 1);
1687 // Is there a break one row above
1688 if (row != rows().begin() &&
1689 boost::prior(row)->par() == row->par()
1690 && (cursor.par()->isLineSeparator(cursor.pos())
1691 || cursor.par()->isNewline(cursor.pos())
1692 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1693 cursor.par()->isInset(cursor.pos() + 1))
1694 || cursor.row()->fill() == -1))
1696 pos_type z = rowBreakPoint(*boost::prior(row));
1698 if (z >= row->pos()) {
1701 // set the dimensions of the row above
1702 boost::prior(row)->fill(fill(
1706 setHeightOfRow(boost::prior(row));
1708 y -= boost::prior(row)->height();
1712 breakAgainOneRow(row);
1714 current_font = rawtmpfont;
1715 real_current_font = realtmpfont;
1716 setCursor(cursor.par(), cursor.pos() + 1,
1717 false, cursor.boundary());
1718 // cursor MUST be in row now.
1720 if (boost::next(row) != rows().end() &&
1721 boost::next(row)->par() == row->par())
1722 need_break_row = boost::next(row);
1724 need_break_row = rows().end();
1726 // check, wether the last characters font has changed.
1727 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1728 && rawparfont != rawtmpfont)
1729 redoHeightOfParagraph();
1736 // recalculate the fill of the row
1737 if (row->fill() >= 0) {
1738 // needed because a newline will set fill to -1. Otherwise
1739 // we would not get a rebreak!
1740 row->fill(fill(row, workWidth()));
1743 if (c == Paragraph::META_INSET || row->fill() < 0) {
1745 breakAgainOneRow(row);
1746 // will the cursor be in another row now?
1747 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1748 boost::next(row) != rows().end()) {
1749 if (boost::next(row) != rows().end() &&
1750 boost::next(row)->par() == row->par())
1751 // this should always be true
1753 breakAgainOneRow(row);
1755 current_font = rawtmpfont;
1756 real_current_font = realtmpfont;
1758 setCursor(cursor.par(), cursor.pos() + 1, false,
1760 if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
1761 != cursor.boundary())
1762 setCursor(cursor.par(), cursor.pos(), false,
1763 !cursor.boundary());
1764 if (boost::next(row) != rows().end() &&
1765 boost::next(row)->par() == row->par())
1766 need_break_row = boost::next(row);
1768 need_break_row = rows().end();
1770 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1771 int const tmpheight = row->height();
1773 setHeightOfRow(row);
1775 if (tmpheight == row->height()) {
1776 postRowPaint(row, y);
1781 current_font = rawtmpfont;
1782 real_current_font = realtmpfont;
1783 setCursor(cursor.par(), cursor.pos() + 1, false,
1787 // check, wether the last characters font has changed.
1788 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1789 && rawparfont != rawtmpfont) {
1790 redoHeightOfParagraph();
1792 // now the special right address boxes
1793 if (cursor.par()->layout()->margintype
1794 == MARGIN_RIGHT_ADDRESS_BOX) {
1795 redoDrawingOfParagraph(cursor);
1803 void LyXText::charInserted()
1805 // Here we could call FinishUndo for every 20 characters inserted.
1806 // This is from my experience how emacs does it.
1807 static unsigned int counter;
1817 void LyXText::prepareToPrint(RowList::iterator rit, float & x,
1818 float & fill_separator,
1820 float & fill_label_hfill,
1825 float w = rit->fill();
1827 fill_label_hfill = 0;
1829 fill_label_hfill = 0;
1832 rit->par()->isRightToLeftPar(bv()->buffer()->params);
1834 x = (workWidth() > 0)
1835 ? rightMargin(*bv()->buffer(), *rit) : 0;
1837 x = (workWidth() > 0)
1838 ? leftMargin(*rit) : 0;
1840 // is there a manual margin with a manual label
1841 LyXLayout_ptr const & layout = rit->par()->layout();
1843 if (layout->margintype == MARGIN_MANUAL
1844 && layout->labeltype == LABEL_MANUAL) {
1845 /// We might have real hfills in the label part
1846 nlh = numberOfLabelHfills(*this, rit);
1848 // A manual label par (e.g. List) has an auto-hfill
1849 // between the label text and the body of the
1851 // But we don't want to do this auto hfill if the par
1853 if (!rit->par()->empty())
1856 if (nlh && !rit->par()->getLabelWidthString().empty()) {
1857 fill_label_hfill = labelFill(*rit) / nlh;
1861 // are there any hfills in the row?
1862 float const nh = numberOfHfills(*this, rit);
1866 fill_hfill = w / nh;
1867 // we don't have to look at the alignment if it is ALIGN_LEFT and
1868 // if the row is already larger then the permitted width as then
1869 // we force the LEFT_ALIGN'edness!
1870 } else if (static_cast<int>(rit->width()) < workWidth()) {
1871 // is it block, flushleft or flushright?
1872 // set x how you need it
1874 if (rit->par()->params().align() == LYX_ALIGN_LAYOUT) {
1875 align = layout->align;
1877 align = rit->par()->params().align();
1880 // center displayed insets
1882 if (rit->pos() < rit->par()->size()
1883 && rit->par()->isInset(rit->pos())
1884 && (inset = rit->par()->getInset(rit->pos()))
1885 && (inset->display())) // || (inset->scroll() < 0)))
1886 align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
1887 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1888 // ERT insets should always be LEFT ALIGNED on screen
1889 inset = rit->par()->inInset();
1890 if (inset && inset->owner() &&
1891 inset->owner()->lyxCode() == Inset::ERT_CODE)
1893 align = LYX_ALIGN_LEFT;
1897 case LYX_ALIGN_BLOCK:
1899 float const ns = numberOfSeparators(*this, rit);
1900 RowList::iterator next_row = boost::next(rit);
1902 if (ns && next_row != rowlist_.end() &&
1903 next_row->par() == rit->par() &&
1904 !(next_row->par()->isNewline(next_row->pos() - 1))
1905 && !(next_row->par()->isInset(next_row->pos()) &&
1906 next_row->par()->getInset(next_row->pos()) &&
1907 next_row->par()->getInset(next_row->pos())->display())
1909 fill_separator = w / ns;
1910 } else if (is_rtl) {
1915 case LYX_ALIGN_RIGHT:
1918 case LYX_ALIGN_CENTER:
1926 computeBidiTables(bv()->buffer(), rit);
1928 pos_type body_pos = rit->par()->beginningOfBody();
1929 pos_type last = lastPos(*this, rit);
1932 (body_pos - 1 > last ||
1933 !rit->par()->isLineSeparator(body_pos - 1))) {
1934 x += font_metrics::width(layout->labelsep,
1935 getLabelFont(bv()->buffer(),
1937 if (body_pos - 1 <= last)
1938 x += fill_label_hfill;
1944 // important for the screen
1947 // the cursor set functions have a special mechanism. When they
1948 // realize, that you left an empty paragraph, they will delete it.
1949 // They also delete the corresponding row
1951 void LyXText::cursorRightOneWord()
1953 // treat floats, HFills and Insets as words
1954 LyXCursor tmpcursor = cursor;
1955 // CHECK See comment on top of text.C
1957 if (tmpcursor.pos() == tmpcursor.par()->size()
1958 && tmpcursor.par()->next()) {
1959 tmpcursor.par(tmpcursor.par()->next());
1964 // Skip through initial nonword stuff.
1965 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1966 ! tmpcursor.par()->isWord(tmpcursor.pos())) {
1967 // printf("Current pos1 %d", tmpcursor.pos()) ;
1968 tmpcursor.pos(tmpcursor.pos() + 1);
1971 // Advance through word.
1972 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1973 tmpcursor.par()->isWord(tmpcursor.pos())) {
1974 // printf("Current pos2 %d", tmpcursor.pos()) ;
1975 tmpcursor.pos(tmpcursor.pos() + 1);
1979 setCursor(tmpcursor.par(), tmpcursor.pos());
1983 // Skip initial whitespace at end of word and move cursor to *start*
1984 // of prior word, not to end of next prior word.
1985 void LyXText::cursorLeftOneWord()
1987 LyXCursor tmpcursor = cursor;
1988 cursorLeftOneWord(tmpcursor);
1989 setCursor(tmpcursor.par(), tmpcursor.pos());
1993 void LyXText::cursorLeftOneWord(LyXCursor & cur)
1995 // treat HFills, floats and Insets as words
1998 && (cur.par()->isSeparator(cur.pos() - 1)
1999 || cur.par()->isKomma(cur.pos() - 1)
2000 || cur.par()->isNewline(cur.pos() - 1))
2001 && !(cur.par()->isHfill(cur.pos() - 1)
2002 || cur.par()->isInset(cur.pos() - 1)))
2003 cur.pos(cur.pos() - 1);
2006 && (cur.par()->isInset(cur.pos() - 1)
2007 || cur.par()->isHfill(cur.pos() - 1))) {
2008 cur.pos(cur.pos() - 1);
2009 } else if (!cur.pos()) {
2010 if (cur.par()->previous()) {
2011 cur.par(cur.par()->previous());
2012 cur.pos(cur.par()->size());
2014 } else { // Here, cur != 0
2015 while (cur.pos() > 0 &&
2016 cur.par()->isWord(cur.pos() - 1))
2017 cur.pos(cur.pos() - 1);
2022 // Select current word. This depends on behaviour of
2023 // CursorLeftOneWord(), so it is patched as well.
2024 void LyXText::getWord(LyXCursor & from, LyXCursor & to,
2025 word_location const loc)
2027 // first put the cursor where we wana start to select the word
2030 case WHOLE_WORD_STRICT:
2031 if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
2032 || cursor.par()->isSeparator(cursor.pos())
2033 || cursor.par()->isKomma(cursor.pos())
2034 || cursor.par()->isNewline(cursor.pos())
2035 || cursor.par()->isSeparator(cursor.pos() - 1)
2036 || cursor.par()->isKomma(cursor.pos() - 1)
2037 || cursor.par()->isNewline(cursor.pos() - 1)) {
2041 // no break here, we go to the next
2044 // Move cursor to the beginning, when not already there.
2045 if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
2046 && !(from.par()->isKomma(from.pos() - 1)
2047 || from.par()->isNewline(from.pos() - 1)))
2048 cursorLeftOneWord(from);
2051 // always move the cursor to the beginning of previous word
2052 cursorLeftOneWord(from);
2055 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
2061 while (to.pos() < to.par()->size()
2062 && !to.par()->isSeparator(to.pos())
2063 && !to.par()->isKomma(to.pos())
2064 && !to.par()->isNewline(to.pos())
2065 && !to.par()->isHfill(to.pos())
2066 && !to.par()->isInset(to.pos()))
2068 to.pos(to.pos() + 1);
2073 void LyXText::selectWord(word_location loc)
2077 getWord(from, to, loc);
2079 setCursor(from.par(), from.pos());
2082 selection.cursor = cursor;
2083 setCursor(to.par(), to.pos());
2088 // Select the word currently under the cursor when no
2089 // selection is currently set
2090 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2092 if (!selection.set()) {
2094 return selection.set();
2100 void LyXText::acceptChange()
2102 if (!selection.set() && cursor.par()->size())
2107 if (selection.start.par() == selection.end.par()) {
2108 LyXCursor & startc = selection.start;
2109 LyXCursor & endc = selection.end;
2110 setUndo(bv(), Undo::INSERT, &*startc.par(), &*boost::next(startc.par()));
2111 startc.par()->acceptChange(startc.pos(), endc.pos());
2114 redoParagraphs(startc, startc.par()->next());
2115 setCursorIntern(startc.par(), 0);
2117 #warning handle multi par selection
2121 void LyXText::rejectChange()
2123 if (!selection.set() && cursor.par()->size())
2128 if (selection.start.par() == selection.end.par()) {
2129 LyXCursor & startc = selection.start;
2130 LyXCursor & endc = selection.end;
2131 setUndo(bv(), Undo::INSERT, &*startc.par(),
2132 &*boost::next(startc.par()));
2133 startc.par()->rejectChange(startc.pos(), endc.pos());
2136 redoParagraphs(startc, startc.par()->next());
2137 setCursorIntern(startc.par(), 0);
2139 #warning handle multi par selection
2143 // This function is only used by the spellchecker for NextWord().
2144 // It doesn't handle LYX_ACCENTs and probably never will.
2146 LyXText::selectNextWordToSpellcheck(float & value)
2148 if (the_locking_inset) {
2149 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2150 if (!word.word().empty()) {
2151 value += float(cursor.y());
2152 value /= float(height);
2155 // we have to go on checking so move cursor to the next char
2156 if (cursor.pos() == cursor.par()->size()) {
2157 if (!cursor.par()->next())
2159 cursor.par(cursor.par()->next());
2162 cursor.pos(cursor.pos() + 1);
2164 ParagraphList::iterator tmppit = cursor.par();
2166 // If this is not the very first word, skip rest of
2167 // current word because we are probably in the middle
2168 // of a word if there is text here.
2169 if (cursor.pos() || cursor.par()->previous()) {
2170 while (cursor.pos() < cursor.par()->size()
2171 && cursor.par()->isLetter(cursor.pos()))
2172 cursor.pos(cursor.pos() + 1);
2175 // Now, skip until we have real text (will jump paragraphs)
2177 ParagraphList::iterator cpit = cursor.par();
2178 pos_type const cpos(cursor.pos());
2180 if (cpos == cpit->size()) {
2181 if (boost::next(cpit) != ownerParagraphs().end()) {
2182 cursor.par(boost::next(cpit));
2189 bool const is_good_inset = cpit->isInset(cpos)
2190 && cpit->getInset(cpos)->allowSpellcheck();
2192 if (!isDeletedText(*cpit, cpos)
2193 && (is_good_inset || cpit->isLetter(cpos)))
2196 cursor.pos(cpos + 1);
2199 // now check if we hit an inset so it has to be a inset containing text!
2200 if (cursor.pos() < cursor.par()->size() &&
2201 cursor.par()->isInset(cursor.pos())) {
2203 cursor.par()->getInset(cursor.pos())->edit(bv());
2204 // now call us again to do the above trick
2205 // but obviously we have to start from down below ;)
2206 return bv()->text->selectNextWordToSpellcheck(value);
2209 // Update the value if we changed paragraphs
2210 if (cursor.par() != tmppit) {
2211 setCursor(cursor.par(), cursor.pos());
2212 value = float(cursor.y())/float(height);
2215 // Start the selection from here
2216 selection.cursor = cursor;
2219 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2220 .language()->code());
2221 // and find the end of the word (insets like optional hyphens
2222 // and ligature break are part of a word)
2223 while (cursor.pos() < cursor.par()->size()
2224 && cursor.par()->isLetter(cursor.pos())
2225 && !isDeletedText(*cursor.par(), cursor.pos()))
2226 cursor.pos(cursor.pos() + 1);
2228 // Finally, we copy the word to a string and return it
2230 if (selection.cursor.pos() < cursor.pos()) {
2232 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2233 if (!cursor.par()->isInset(i))
2234 str += cursor.par()->getChar(i);
2237 return WordLangTuple(str, lang_code);
2241 // This one is also only for the spellchecker
2242 void LyXText::selectSelectedWord()
2244 if (the_locking_inset) {
2245 the_locking_inset->selectSelectedWord(bv());
2248 // move cursor to the beginning
2249 setCursor(selection.cursor.par(), selection.cursor.pos());
2251 // set the sel cursor
2252 selection.cursor = cursor;
2254 // now find the end of the word
2255 while (cursor.pos() < cursor.par()->size()
2256 && (cursor.par()->isLetter(cursor.pos())))
2257 cursor.pos(cursor.pos() + 1);
2259 setCursor(cursor.par(), cursor.pos());
2261 // finally set the selection
2266 // Delete from cursor up to the end of the current or next word.
2267 void LyXText::deleteWordForward()
2269 if (cursor.par()->empty())
2272 LyXCursor tmpcursor = cursor;
2273 tmpcursor.row(0); //Â ??
2274 selection.set(true); // to avoid deletion
2275 cursorRightOneWord();
2276 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2277 selection.cursor = cursor;
2281 // Great, CutSelection() gets rid of multiple spaces.
2282 cutSelection(true, false);
2287 // Delete from cursor to start of current or prior word.
2288 void LyXText::deleteWordBackward()
2290 if (cursor.par()->empty())
2293 LyXCursor tmpcursor = cursor;
2294 tmpcursor.row(0); // ??
2295 selection.set(true); // to avoid deletion
2296 cursorLeftOneWord();
2297 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2298 selection.cursor = cursor;
2301 cutSelection(true, false);
2306 // Kill to end of line.
2307 void LyXText::deleteLineForward()
2309 if (cursor.par()->empty())
2310 // Paragraph is empty, so we just go to the right
2313 LyXCursor tmpcursor = cursor;
2314 // We can't store the row over a regular setCursor
2315 // so we set it to 0 and reset it afterwards.
2316 tmpcursor.row(0); //Â ??
2317 selection.set(true); // to avoid deletion
2319 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2320 selection.cursor = cursor;
2323 // What is this test for ??? (JMarc)
2324 if (!selection.set()) {
2325 deleteWordForward();
2327 cutSelection(true, false);
2333 void LyXText::changeCase(LyXText::TextCase action)
2338 if (selection.set()) {
2339 from = selection.start;
2342 getWord(from, to, PARTIAL_WORD);
2343 setCursor(to.par(), to.pos() + 1);
2346 lyx::Assert(from <= to);
2348 setUndo(bv(), Undo::FINISH, &*from.par(), &*boost::next(to.par()));
2350 pos_type pos = from.pos();
2351 ParagraphList::iterator pit = from.par();
2353 while (pit != ownerParagraphs().end() &&
2354 (pos != to.pos() || pit != to.par())) {
2355 if (pos == pit->size()) {
2360 unsigned char c = pit->getChar(pos);
2361 if (!IsInsetChar(c)) {
2363 case text_lowercase:
2366 case text_capitalization:
2368 action = text_lowercase;
2370 case text_uppercase:
2376 pit->setChar(pos, c);
2377 checkParagraph(&*pit, pos);
2382 if (to.row() != from.row())
2383 postPaint(from.y() - from.row()->baseline());
2387 void LyXText::Delete()
2389 // this is a very easy implementation
2391 LyXCursor old_cursor = cursor;
2392 int const old_cur_par_id = old_cursor.par()->id();
2393 int const old_cur_par_prev_id = old_cursor.par()->previous() ?
2394 old_cursor.par()->previous()->id() : -1;
2396 // just move to the right
2399 // CHECK Look at the comment here.
2400 // This check is not very good...
2401 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2402 // and that can very well delete the par or par->previous in
2403 // old_cursor. Will a solution where we compare paragraph id's
2405 if ((cursor.par()->previous() ? cursor.par()->previous()->id() : -1)
2406 == old_cur_par_prev_id
2407 && cursor.par()->id() != old_cur_par_id) {
2408 // delete-empty-paragraph-mechanism has done it
2412 // if you had success make a backspace
2413 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2414 LyXCursor tmpcursor = cursor;
2415 // to make sure undo gets the right cursor position
2416 cursor = old_cursor;
2417 setUndo(bv(), Undo::DELETE,
2418 &*cursor.par(), &*boost::next(cursor.par()));
2425 void LyXText::backspace()
2427 // Get the font that is used to calculate the baselineskip
2428 pos_type lastpos = cursor.par()->size();
2429 LyXFont rawparfont =
2430 cursor.par()->getFontSettings(bv()->buffer()->params,
2433 if (cursor.pos() == 0) {
2434 // The cursor is at the beginning of a paragraph,
2435 // so the the backspace will collapse two paragraphs into one.
2437 // but it's not allowed unless it's new
2438 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2441 // we may paste some paragraphs
2443 // is it an empty paragraph?
2446 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2447 // This is an empty paragraph and we delete it just by moving the cursor one step
2448 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2449 // of the paragraph.
2451 if (cursor.par()->previous()) {
2452 Paragraph * tmppar = cursor.par()->previous();
2453 if (cursor.par()->layout() == tmppar->layout()
2454 && cursor.par()->getAlign() == tmppar->getAlign()) {
2455 // Inherit bottom DTD from the paragraph below.
2456 // (the one we are deleting)
2457 tmppar->params().lineBottom(cursor.par()->params().lineBottom());
2458 tmppar->params().spaceBottom(cursor.par()->params().spaceBottom());
2459 tmppar->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2464 // the layout things can change the height of a row !
2465 int const tmpheight = cursor.row()->height();
2466 setHeightOfRow(cursor.row());
2467 if (cursor.row()->height() != tmpheight) {
2468 postPaint(cursor.y() - cursor.row()->baseline());
2474 if (cursor.par()->previous()) {
2475 setUndo(bv(), Undo::DELETE,
2476 cursor.par()->previous(), cursor.par()->next());
2479 ParagraphList::iterator tmppit = cursor.par();
2480 RowList::iterator tmprow = cursor.row();
2482 // We used to do cursorLeftIntern() here, but it is
2483 // not a good idea since it triggers the auto-delete
2484 // mechanism. So we do a cursorLeftIntern()-lite,
2485 // without the dreaded mechanism. (JMarc)
2486 if (cursor.par() != ownerParagraphs().begin()) {
2487 // steps into the above paragraph.
2488 setCursorIntern(boost::prior(cursor.par()),
2489 boost::prior(cursor.par())->size(),
2493 // Pasting is not allowed, if the paragraphs have different
2494 // layout. I think it is a real bug of all other
2495 // word processors to allow it. It confuses the user.
2496 // Even so with a footnote paragraph and a non-footnote
2497 // paragraph. I will not allow pasting in this case,
2498 // because the user would be confused if the footnote behaves
2499 // different wether it is open or closed.
2501 // Correction: Pasting is always allowed with standard-layout
2502 LyXTextClass const & tclass =
2503 bv()->buffer()->params.getLyXTextClass();
2505 if (cursor.par() != tmppit
2506 && (cursor.par()->layout() == tmppit->layout()
2507 || tmppit->layout() == tclass.defaultLayout())
2508 && cursor.par()->getAlign() == tmppit->getAlign()) {
2509 removeParagraph(tmprow);
2511 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2513 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2514 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2515 // strangely enough it seems that commenting out the line above removes
2516 // most or all of the segfaults. I will however also try to move the
2517 // two Remove... lines in front of the PasteParagraph too.
2520 cursor.pos(cursor.pos() - 1);
2522 postPaint(cursor.y() - cursor.row()->baseline());
2524 // remove the lost paragraph
2525 // This one is not safe, since the paragraph that the tmprow and the
2526 // following rows belong to has been deleted by the PasteParagraph
2527 // above. The question is... could this be moved in front of the
2529 //RemoveParagraph(tmprow);
2530 //RemoveRow(tmprow);
2532 // This rebuilds the rows.
2533 appendParagraph(cursor.row());
2536 // the row may have changed, block, hfills etc.
2537 setCursor(cursor.par(), cursor.pos(), false);
2540 // this is the code for a normal backspace, not pasting
2542 setUndo(bv(), Undo::DELETE,
2543 &*cursor.par(), &*boost::next(cursor.par()));
2544 // We used to do cursorLeftIntern() here, but it is
2545 // not a good idea since it triggers the auto-delete
2546 // mechanism. So we do a cursorLeftIntern()-lite,
2547 // without the dreaded mechanism. (JMarc)
2548 setCursorIntern(cursor.par(), cursor.pos()- 1,
2549 false, cursor.boundary());
2551 if (cursor.par()->isInset(cursor.pos())) {
2552 // force complete redo when erasing display insets
2553 // this is a cruel method but safe..... Matthias
2554 if (cursor.par()->getInset(cursor.pos())->display() ||
2555 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2556 cursor.par()->erase(cursor.pos());
2562 RowList::iterator row = cursor.row();
2563 int y = cursor.y() - row->baseline();
2565 // remember that a space at the end of a row doesnt count
2566 // when calculating the fill
2567 if (cursor.pos() < lastPos(*this, row) ||
2568 !cursor.par()->isLineSeparator(cursor.pos())) {
2569 row->fill(row->fill() + singleWidth(
2574 // some special code when deleting a newline. This is similar
2575 // to the behavior when pasting paragraphs
2576 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2577 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);
2585 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2586 cursor.pos(cursor.pos() - 1);
2588 if (cursor.pos() < cursor.par()->size()
2589 && !cursor.par()->isSeparator(cursor.pos())) {
2590 cursor.par()->insertChar(cursor.pos(), ' ');
2591 setCharFont(bv()->buffer(), &*cursor.par(),
2592 cursor.pos(), current_font);
2593 // refresh the positions
2595 while (boost::next(tmprow) != rows().end() &&
2596 boost::next(tmprow)->par() == row->par()) {
2598 tmprow->pos(tmprow->pos() + 1);
2602 cursor.par()->erase(cursor.pos());
2604 // refresh the positions
2605 RowList::iterator tmprow = row;
2606 while (boost::next(tmprow) != rows().end() &&
2607 boost::next(tmprow)->par() == row->par()) {
2609 tmprow->pos(tmprow->pos() - 1);
2612 // delete newlines at the beginning of paragraphs
2613 while (!cursor.par()->empty() &&
2614 cursor.pos() < cursor.par()->size() &&
2615 cursor.par()->isNewline(cursor.pos()) &&
2616 cursor.pos() == cursor.par()->beginningOfBody()) {
2617 cursor.par()->erase(cursor.pos());
2618 // refresh the positions
2620 while (boost::next(tmprow) != rows().end() &&
2621 boost::next(tmprow)->par() == row->par()) {
2623 tmprow->pos(tmprow->pos() - 1);
2628 // is there a break one row above
2629 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2630 z = rowBreakPoint(*boost::prior(row));
2631 if (z >= row->pos()) {
2634 RowList::iterator tmprow = boost::prior(row);
2636 // maybe the current row is now empty
2637 if (row->pos() >= row->par()->size()) {
2640 need_break_row = rows().end();
2642 breakAgainOneRow(row);
2643 if (boost::next(row) != rows().end() &&
2644 boost::next(row)->par() == row->par())
2645 need_break_row = boost::next(row);
2647 need_break_row = rows().end();
2650 // set the dimensions of the row above
2651 y -= tmprow->height();
2652 tmprow->fill(fill(tmprow, workWidth()));
2653 setHeightOfRow(tmprow);
2657 setCursor(cursor.par(), cursor.pos(),
2658 false, cursor.boundary());
2659 //current_font = rawtmpfont;
2660 //real_current_font = realtmpfont;
2661 // check, whether the last character's font has changed.
2663 cursor.par()->getFontSettings(bv()->buffer()->params,
2664 cursor.par()->size() - 1))
2665 redoHeightOfParagraph();
2670 // break the cursor row again
2671 if (boost::next(row) != rows().end() &&
2672 boost::next(row)->par() == row->par() &&
2673 (lastPos(*this, row) == row->par()->size() - 1 ||
2674 rowBreakPoint(*row) != lastPos(*this, row))) {
2676 // it can happen that a paragraph loses one row
2677 // without a real breakup. This is when a word
2678 // is to long to be broken. Well, I don t care this
2680 if (lastPos(*this, row) == row->par()->size() - 1)
2681 removeRow(boost::next(row));
2685 breakAgainOneRow(row);
2686 // will the cursor be in another row now?
2687 if (boost::next(row) != rows().end() &&
2688 boost::next(row)->par() == row->par() &&
2689 lastPos(*this, row) <= cursor.pos()) {
2691 breakAgainOneRow(row);
2694 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2696 if (boost::next(row) != rows().end() &&
2697 boost::next(row)->par() == row->par())
2698 need_break_row = boost::next(row);
2700 need_break_row = rows().end();
2702 // set the dimensions of the row
2703 row->fill(fill(row, workWidth()));
2704 int const tmpheight = row->height();
2705 setHeightOfRow(row);
2706 if (tmpheight == row->height()) {
2707 postRowPaint(row, y);
2711 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2715 // current_font = rawtmpfont;
2716 // real_current_font = realtmpfont;
2718 if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
2719 != cursor.boundary())
2720 setCursor(cursor.par(), cursor.pos(), false,
2721 !cursor.boundary());
2723 lastpos = cursor.par()->size();
2724 if (cursor.pos() == lastpos)
2727 // check, whether the last characters font has changed.
2729 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2730 redoHeightOfParagraph();
2732 // now the special right address boxes
2733 if (cursor.par()->layout()->margintype
2734 == MARGIN_RIGHT_ADDRESS_BOX) {
2735 redoDrawingOfParagraph(cursor);
2741 // returns pointer to a specified row
2743 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2748 return rowlist_.end();
2750 // find the first row of the specified paragraph
2751 RowList::iterator rit = rowlist_.begin();
2752 RowList::iterator end = rowlist_.end();
2753 while (boost::next(rit) != end && rit->par() != pit) {
2758 // now find the wanted row
2759 while (rit->pos() < pos
2760 && boost::next(rit) != end
2761 && boost::next(rit)->par() == pit
2762 && boost::next(rit)->pos() <= pos) {
2771 RowList::iterator LyXText::getRowNearY(int & y) const
2774 RowList::iterator rit = anchor_row_;
2775 RowList::iterator const beg = rows().begin();
2776 RowList::iterator const end = rows().end();
2778 if (rows().empty()) {
2785 int tmpy = rit->y();
2788 while (rit != end && tmpy <= y) {
2789 tmpy += rit->height();
2794 tmpy -= rit->height();
2797 while (rit != beg && tmpy > y) {
2799 tmpy -= rit->height();
2802 if (tmpy < 0 || rit == end) {
2814 int LyXText::getDepth() const
2816 return cursor.par()->getDepth();