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 pos_type const par_size = par.size();
207 for (pos_type i = pos + 1; i < par_size; ++i) {
208 unsigned char const par_char = par.getChar(i);
209 if (!Encodings::IsComposeChar_arabic(par_char)) {
210 next_char = par_char;
215 if (Encodings::is_arabic(next_char)) {
216 if (Encodings::is_arabic(prev_char) &&
217 !Encodings::is_arabic_special(prev_char))
218 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
220 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
222 if (Encodings::is_arabic(prev_char) &&
223 !Encodings::is_arabic_special(prev_char))
224 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
226 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
230 // This is the comments that some of the warnings below refers to.
231 // There are some issues in this file and I don't think they are
232 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
233 // this is a problem that has been here almost from day one and that a
234 // larger userbase with differenct access patters triggers the bad
235 // behaviour. (segfaults.) What I think happen is: In several places
236 // we store the paragraph in the current cursor and then moves the
237 // cursor. This movement of the cursor will delete paragraph at the
238 // old position if it is now empty. This will make the temporary
239 // pointer to the old cursor paragraph invalid and dangerous to use.
240 // And is some cases this will trigger a segfault. I have marked some
241 // of the cases where this happens with a warning, but I am sure there
242 // are others in this file and in text2.C. There is also a note in
243 // Delete() that you should read. In Delete I store the paragraph->id
244 // instead of a pointer to the paragraph. I am pretty sure this faulty
245 // use of temporary pointers to paragraphs that might have gotten
246 // invalidated (through a cursor movement) before they are used, are
247 // the cause of the strange crashes we get reported often.
249 // It is very tiresom to change this code, especially when it is as
250 // hard to read as it is. Help to fix all the cases where this is done
251 // would be greately appreciated.
255 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
257 if (pos >= pit->size())
260 char const c = pit->getChar(pos);
261 return singleWidth(pit, pos, c);
265 int LyXText::singleWidth(ParagraphList::iterator pit,
266 pos_type pos, char c) const
268 if (pos >= pit->size())
271 LyXFont const font = getFont(bv()->buffer(), pit, pos);
273 // The most common case is handled first (Asger)
274 if (IsPrintable(c)) {
275 if (font.language()->RightToLeft()) {
276 if (font.language()->lang() == "arabic" &&
277 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
278 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
279 if (Encodings::IsComposeChar_arabic(c))
282 c = transformChar(c, *pit, pos);
283 } else if (font.language()->lang() == "hebrew" &&
284 Encodings::IsComposeChar_hebrew(c))
287 return font_metrics::width(c, font);
291 if (c == Paragraph::META_INSET) {
292 Inset * tmpinset = pit->getInset(pos);
294 if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
295 // Because of the representation as vertical lines
299 #warning inset->update FIXME
300 // this IS needed otherwise on initialitation we don't get the fill
301 // of the row right (ONLY on initialization if we read a file!)
302 // should be changed! (Jug 20011204)
303 tmpinset->update(bv());
305 return tmpinset->width(bv(), font);
310 if (IsSeparatorChar(c))
312 return font_metrics::width(c, font);
316 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
318 if (bidi_start == -1)
321 return log2vis_list[pos - bidi_start];
325 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
327 if (bidi_start == -1)
330 return vis2log_list[pos - bidi_start];
334 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
336 if (bidi_start == -1)
339 return bidi_levels[pos - bidi_start];
343 bool LyXText::bidi_InRange(lyx::pos_type pos) const
345 return bidi_start == -1 ||
346 (bidi_start <= pos && pos <= bidi_end);
350 void LyXText::computeBidiTables(Buffer const * buf,
351 RowList::iterator row) const
353 bidi_same_direction = true;
354 if (!lyxrc.rtl_support) {
359 ParagraphList::iterator row_par = row->par();
361 Inset * inset = row_par->inInset();
362 if (inset && inset->owner() &&
363 inset->owner()->lyxCode() == Inset::ERT_CODE) {
368 bidi_start = row->pos();
369 bidi_end = lastPrintablePos(*this, row);
371 if (bidi_start > bidi_end) {
376 if (bidi_end + 2 - bidi_start >
377 static_cast<pos_type>(log2vis_list.size())) {
379 (bidi_end + 2 - bidi_start < 500) ?
380 500 : 2 * (bidi_end + 2 - bidi_start);
381 log2vis_list.resize(new_size);
382 vis2log_list.resize(new_size);
383 bidi_levels.resize(new_size);
386 vis2log_list[bidi_end + 1 - bidi_start] = -1;
387 log2vis_list[bidi_end + 1 - bidi_start] = -1;
391 row_par->isRightToLeftPar(buf->params);
395 pos_type const body_pos = row_par->beginningOfBody();
397 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
398 bool is_space = row_par->isLineSeparator(lpos);
400 (is_space && lpos + 1 <= bidi_end &&
401 !row_par->isLineSeparator(lpos + 1) &&
402 !row_par->isNewline(lpos + 1))
404 LyXFont font = row_par->getFontSettings(buf->params, pos);
405 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
406 font.number() == LyXFont::ON &&
407 row_par->getFontSettings(buf->params, lpos - 1).number()
409 font = row_par->getFontSettings(buf->params, lpos);
414 bool new_rtl = font.isVisibleRightToLeft();
415 bool new_rtl0 = font.isRightToLeft();
418 if (lpos == body_pos - 1
419 && row->pos() < body_pos - 1
421 new_level = (rtl_par) ? 1 : 0;
422 new_rtl = new_rtl0 = rtl_par;
424 new_level = (new_rtl) ? 1 : 2;
426 new_level = (rtl_par) ? 2 : 0;
428 if (is_space && new_level >= level) {
434 int new_level2 = new_level;
436 if (level == new_level && rtl0 != new_rtl0) {
438 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
439 } else if (level < new_level) {
440 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
441 if (new_level > rtl_par)
442 bidi_same_direction = false;
444 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
447 bidi_levels[lpos - bidi_start] = new_level;
449 while (level > new_level2) {
450 pos_type old_lpos = stack[--level];
451 int delta = lpos - old_lpos - 1;
454 log2vis_list[lpos - bidi_start] += delta;
455 log2vis_list[old_lpos - bidi_start] += delta;
457 while (level < new_level)
458 stack[level++] = lpos;
462 pos_type const old_lpos = stack[--level];
463 int delta = bidi_end - old_lpos;
466 log2vis_list[old_lpos - bidi_start] += delta;
469 pos_type vpos = bidi_start - 1;
470 for (pos_type lpos = bidi_start;
471 lpos <= bidi_end; ++lpos) {
472 vpos += log2vis_list[lpos - bidi_start];
473 vis2log_list[vpos - bidi_start] = lpos;
474 log2vis_list[lpos - bidi_start] = vpos;
479 // This method requires a previous call to ComputeBidiTables()
480 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
483 if (!lyxrc.rtl_support || pos == 0)
486 if (!bidi_InRange(pos - 1)) {
487 /// This can happen if pos is the first char of a row.
488 /// Returning false in this case is incorrect!
492 bool const rtl = bidi_level(pos - 1) % 2;
493 bool const rtl2 = bidi_InRange(pos)
494 ? bidi_level(pos) % 2
495 : par.isRightToLeftPar(buf->params);
500 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
501 pos_type pos, LyXFont const & font) const
503 if (!lyxrc.rtl_support)
504 return false; // This is just for speedup
506 bool const rtl = font.isVisibleRightToLeft();
507 bool const rtl2 = bidi_InRange(pos)
508 ? bidi_level(pos) % 2
509 : par.isRightToLeftPar(buf->params);
514 int LyXText::leftMargin(Row const & row) const
518 if (row.pos() < row.par()->size())
519 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
520 (ins = row.par()->getInset(row.pos())) &&
521 (ins->needFullRow() || ins->display()))
524 LyXTextClass const & tclass =
525 bv()->buffer()->params.getLyXTextClass();
526 LyXLayout_ptr const & layout = row.par()->layout();
528 string parindent = layout->parindent;
532 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
534 // this is the way, LyX handles the LaTeX-Environments.
535 // I have had this idea very late, so it seems to be a
536 // later added hack and this is true
537 if (!row.par()->getDepth()) {
538 if (row.par()->layout() == tclass.defaultLayout()) {
539 // find the previous same level paragraph
540 if (row.par() != ownerParagraphs().begin()) {
541 Paragraph * newpar = row.par()
542 ->depthHook(row.par()->getDepth());
544 newpar->layout()->nextnoindent)
549 // find the next level paragraph
551 Paragraph * newpar = row.par()->outerHook();
553 // make a corresponding row. Needed to call leftMargin()
555 // check wether it is a sufficent paragraph
556 if (newpar && newpar->layout()->isEnvironment()) {
558 dummyrow.par(newpar);
559 dummyrow.pos(newpar->size());
560 x = leftMargin(dummyrow);
563 if (newpar && row.par()->layout() == tclass.defaultLayout()) {
564 if (newpar->params().noindent())
567 parindent = newpar->layout()->parindent;
573 LyXFont const labelfont = getLabelFont(bv()->buffer(), row.par());
574 switch (layout->margintype) {
576 if (!layout->leftmargin.empty()) {
577 x += font_metrics::signedWidth(layout->leftmargin,
578 tclass.defaultfont());
580 if (!row.par()->getLabelstring().empty()) {
581 x += font_metrics::signedWidth(layout->labelindent,
583 x += font_metrics::width(row.par()->getLabelstring(),
585 x += font_metrics::width(layout->labelsep, labelfont);
589 x += font_metrics::signedWidth(layout->labelindent, labelfont);
590 // The width of an empty par, even with manual label, should be 0
591 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
592 if (!row.par()->getLabelWidthString().empty()) {
593 x += font_metrics::width(row.par()->getLabelWidthString(),
595 x += font_metrics::width(layout->labelsep, labelfont);
600 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
601 / (row.par()->getDepth() + 4);
603 case MARGIN_FIRST_DYNAMIC:
604 if (layout->labeltype == LABEL_MANUAL) {
605 if (row.pos() >= row.par()->beginningOfBody()) {
606 x += font_metrics::signedWidth(layout->leftmargin,
609 x += font_metrics::signedWidth(layout->labelindent,
613 // Special case to fix problems with
615 || (layout->labeltype == LABEL_STATIC
616 && layout->latextype == LATEX_ENVIRONMENT
617 && ! row.par()->isFirstInSequence())) {
618 x += font_metrics::signedWidth(layout->leftmargin,
620 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
621 && layout->labeltype != LABEL_BIBLIO
622 && layout->labeltype !=
623 LABEL_CENTERED_TOP_ENVIRONMENT) {
624 x += font_metrics::signedWidth(layout->labelindent,
626 x += font_metrics::width(layout->labelsep, labelfont);
627 x += font_metrics::width(row.par()->getLabelstring(),
632 case MARGIN_RIGHT_ADDRESS_BOX:
634 // ok, a terrible hack. The left margin depends on the widest
635 // row in this paragraph. Do not care about footnotes, they
636 // are *NOT* allowed in the LaTeX realisation of this layout.
638 // find the first row of this paragraph
639 RowList::iterator tmprit = rowlist_.begin();
640 while (tmprit != rowlist_.end()
641 && tmprit->par() != row.par())
644 int minfill = tmprit->fill();
645 while (boost::next(tmprit) != rowlist_.end() &&
646 boost::next(tmprit)->par() == row.par()) {
648 if (tmprit->fill() < minfill)
649 minfill = tmprit->fill();
652 x += font_metrics::signedWidth(layout->leftmargin,
653 tclass.defaultfont());
659 if ((workWidth() > 0) &&
660 !row.par()->params().leftIndent().zero())
662 LyXLength const len = row.par()->params().leftIndent();
663 int const tw = inset_owner ?
664 inset_owner->latexTextWidth(bv()) : workWidth();
665 x += len.inPixels(tw);
670 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
671 align = layout->align;
673 align = row.par()->params().align();
675 // set the correct parindent
676 if (row.pos() == 0) {
677 if ((layout->labeltype == LABEL_NO_LABEL
678 || layout->labeltype == LABEL_TOP_ENVIRONMENT
679 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
680 || (layout->labeltype == LABEL_STATIC
681 && layout->latextype == LATEX_ENVIRONMENT
682 && ! row.par()->isFirstInSequence()))
683 && align == LYX_ALIGN_BLOCK
684 && !row.par()->params().noindent()
685 // in tabulars and ert paragraphs are never indented!
686 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
687 (row.par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
688 row.par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
689 && (row.par()->layout() != tclass.defaultLayout() ||
690 bv()->buffer()->params.paragraph_separation ==
691 BufferParams::PARSEP_INDENT)) {
692 x += font_metrics::signedWidth(parindent,
693 tclass.defaultfont());
694 } else if (layout->labeltype == LABEL_BIBLIO) {
695 // ale970405 Right width for bibitems
696 x += bibitemMaxWidth(bv(), tclass.defaultfont());
704 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
708 if (row.pos() < row.par()->size())
709 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
710 (ins = row.par()->getInset(row.pos())) &&
711 (ins->needFullRow() || ins->display()))
714 LyXTextClass const & tclass = buf.params.getLyXTextClass();
715 LyXLayout_ptr const & layout = row.par()->layout();
718 + font_metrics::signedWidth(tclass.rightmargin(),
719 tclass.defaultfont());
721 x += font_metrics::signedWidth(layout->rightmargin,
722 tclass.defaultfont())
723 * 4 / (row.par()->getDepth() + 4);
728 int LyXText::labelEnd(Row const & row) const
730 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
732 tmprow.pos(row.par()->size());
733 // return the beginning of the body
734 return leftMargin(tmprow);
737 // LabelEnd is only needed if the layout
738 // fills a flushleft label.
745 // this needs special handling - only newlines count as a break point
746 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
748 for (; i < par.size(); ++i) {
749 if (par.isNewline(i))
760 LyXText::rowBreakPoint(Row const & row) const
762 ParagraphList::iterator pit = row.par();
764 // maximum pixel width of a row.
765 int width = workWidth() - rightMargin(*bv()->buffer(), row);
767 // inset->textWidth() returns -1 via workWidth(),
772 LyXLayout_ptr const & layout = pit->layout();
774 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
775 return addressBreakPoint(row.pos(), *pit);
777 pos_type const pos = row.pos();
778 pos_type const body_pos = pit->beginningOfBody();
779 pos_type const last = pit->size();
780 pos_type point = last;
785 // Now we iterate through until we reach the right margin
786 // or the end of the par, then choose the possible break
789 int const left = leftMargin(const_cast<Row&>(row));
792 // pixel width since last breakpoint
794 bool fullrow = false;
797 for (; i < last; ++i) {
798 if (pit->isNewline(i)) {
803 char const c = pit->getChar(i);
807 // add the auto-hfill from label end to the body
808 if (body_pos && i == body_pos) {
809 thiswidth = font_metrics::width(layout->labelsep,
810 getLabelFont(bv()->buffer(), pit));
811 if (pit->isLineSeparator(i - 1))
812 thiswidth -= singleWidth(pit, i - 1);
813 int left_margin = labelEnd(row);
814 if (thiswidth + x < left_margin)
815 thiswidth = left_margin - x;
816 thiswidth += singleWidth(pit, i, c);
818 thiswidth = singleWidth(pit, i, c);
822 chunkwidth += thiswidth;
824 Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
825 fullrow = (in && (in->display() || in->needFullRow()));
827 // break before a character that will fall off
828 // the right of the row
830 // if no break before or we are at an inset
831 // that will take up a row, break here
832 if (point == last || fullrow || chunkwidth >= (width - left)) {
841 if (!in || in->isChar()) {
842 // some insets are line separators too
843 if (pit->isLineSeparator(i)) {
853 // full row insets start at a new row
855 if (pos < last - 1) {
857 if (pit->isLineSeparator(i + 1))
860 // to avoid extra rows
870 if (point == last && x >= width) {
871 // didn't find one, break at the point we reached the edge
873 } else if (i == last && x < width) {
874 // found one, but we fell off the end of the par, so prefer
879 // manual labels cannot be broken in LaTeX. But we
880 // want to make our on-screen rendering of footnotes
882 if (!fullrow && body_pos && point < body_pos)
883 point = body_pos - 1;
889 // returns the minimum space a row needs on the screen in pixel
890 int LyXText::fill(RowList::iterator row, int paper_width) const
896 // get the pure distance
897 pos_type const last = lastPrintablePos(*this, row);
899 ParagraphList::iterator pit = row->par();
900 LyXLayout_ptr const & layout = pit->layout();
902 // special handling of the right address boxes
903 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
904 int const tmpfill = row->fill();
905 row->fill(0); // the minfill in MarginLeft()
906 w = leftMargin(*row);
909 w = leftMargin(*row);
911 pos_type const body_pos = pit->beginningOfBody();
912 pos_type i = row->pos();
915 if (body_pos > 0 && i == body_pos) {
916 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
917 if (pit->isLineSeparator(i - 1))
918 w -= singleWidth(pit, i - 1);
919 int left_margin = labelEnd(*row);
923 w += singleWidth(pit, i);
926 if (body_pos > 0 && body_pos > last) {
927 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
928 if (last >= 0 && pit->isLineSeparator(last))
929 w -= singleWidth(pit, last);
930 int const left_margin = labelEnd(*row);
935 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
937 // If this case happens, it means that our calculation
938 // of the widths of the chars when we do rowBreakPoint()
939 // went wrong for some reason. Typically in list bodies.
940 // Things just about hobble on anyway, though you'll end
941 // up with a "fill_separator" less than zero, which corresponds
942 // to inter-word spacing being too small. Hopefully this problem
943 // will die when the label hacks die.
944 if (lyxerr.debugging() && fill < 0) {
945 lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
946 << " w " << w << " paper_width " << paper_width
947 << " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
954 // returns the minimum space a manual label needs on the screen in pixel
955 int LyXText::labelFill(Row const & row) const
957 ParagraphList::iterator pit = row.par();
959 pos_type last = pit->beginningOfBody();
961 lyx::Assert(last > 0);
963 // -1 because a label ends either with a space that is in the label,
964 // or with the beginning of a footnote that is outside the label.
967 // a separator at this end does not count
968 if (pit->isLineSeparator(last))
972 pos_type i = row.pos();
974 w += singleWidth(pit, i);
979 string const & labwidstr = pit->params().labelWidthString();
980 if (!labwidstr.empty()) {
981 LyXFont const labfont = getLabelFont(bv()->buffer(), pit);
982 int const labwidth = font_metrics::width(labwidstr, labfont);
983 fill = max(labwidth - w, 0);
990 LColor::color LyXText::backgroundColor() const
993 return inset_owner->backgroundColor();
995 return LColor::background;
999 void LyXText::setHeightOfRow(RowList::iterator rit)
1001 lyx::Assert(rit != rows().end());
1003 // get the maximum ascent and the maximum descent
1004 float layoutasc = 0;
1005 float layoutdesc = 0;
1008 Inset * tmpinset = 0;
1010 // ok , let us initialize the maxasc and maxdesc value.
1011 // This depends in LaTeX of the font of the last character
1012 // in the paragraph. The hack below is necessary because
1013 // of the possibility of open footnotes
1015 // Correction: only the fontsize count. The other properties
1016 // are taken from the layoutfont. Nicer on the screen :)
1017 ParagraphList::iterator pit = rit->par();
1019 LyXLayout_ptr const & layout = pit->layout();
1021 // as max get the first character of this row then it can increase but not
1022 // decrease the height. Just some point to start with so we don't have to
1023 // do the assignment below too often.
1024 LyXFont font = getFont(bv()->buffer(), pit, rit->pos());
1025 LyXFont::FONT_SIZE const tmpsize = font.size();
1026 font = getLayoutFont(bv()->buffer(), pit);
1027 LyXFont::FONT_SIZE const size = font.size();
1028 font.setSize(tmpsize);
1030 LyXFont labelfont = getLabelFont(bv()->buffer(), pit);
1032 float spacing_val = 1.0;
1033 if (!pit->params().spacing().isDefault()) {
1034 spacing_val = pit->params().spacing().getValue();
1036 spacing_val = bv()->buffer()->params.spacing.getValue();
1038 //lyxerr << "spacing_val = " << spacing_val << endl;
1040 int maxasc = int(font_metrics::maxAscent(font) *
1041 layout->spacing.getValue() *
1043 int maxdesc = int(font_metrics::maxDescent(font) *
1044 layout->spacing.getValue() *
1047 pos_type const pos_end = lastPos(*this, rit);
1051 if (!pit->empty()) {
1052 // Check if any insets are larger
1053 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1054 if (pit->isInset(pos)) {
1055 tmpfont = getFont(bv()->buffer(), pit, pos);
1056 tmpinset = pit->getInset(pos);
1058 #if 1 // this is needed for deep update on initialitation
1059 #warning inset->update FIXME
1060 tmpinset->update(bv());
1062 maxwidth += tmpinset->width(bv(), tmpfont);
1063 maxasc = max(maxasc,
1064 tmpinset->ascent(bv(), tmpfont));
1065 maxdesc = max(maxdesc,
1066 tmpinset->descent(bv(), tmpfont));
1069 maxwidth += singleWidth(pit, pos);
1074 // Check if any custom fonts are larger (Asger)
1075 // This is not completely correct, but we can live with the small,
1076 // cosmetic error for now.
1077 LyXFont::FONT_SIZE maxsize =
1078 pit->highestFontInRange(rit->pos(), pos_end, size);
1079 if (maxsize > font.size()) {
1080 font.setSize(maxsize);
1081 maxasc = max(maxasc, font_metrics::maxAscent(font));
1082 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
1085 // This is nicer with box insets:
1089 rit->ascent_of_text(maxasc);
1091 // is it a top line?
1094 // some parksips VERY EASY IMPLEMENTATION
1095 if (bv()->buffer()->params.paragraph_separation ==
1096 BufferParams::PARSEP_SKIP)
1098 if (layout->isParagraph()
1099 && pit->getDepth() == 0
1100 && pit != ownerParagraphs().begin())
1102 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1103 } else if (pit != ownerParagraphs().begin() &&
1104 boost::prior(pit)->layout()->isParagraph() &&
1105 boost::prior(pit)->getDepth() == 0)
1107 // is it right to use defskip here too? (AS)
1108 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1113 if (pit == ownerParagraphs().begin() && !isInInset())
1114 maxasc += PAPER_MARGIN;
1116 // add the vertical spaces, that the user added
1117 maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
1119 // do not forget the DTP-lines!
1120 // there height depends on the font of the nearest character
1121 if (pit->params().lineTop())
1123 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1125 // and now the pagebreaks
1126 if (pit->params().pagebreakTop())
1127 maxasc += 3 * defaultRowHeight();
1129 if (pit->params().startOfAppendix())
1130 maxasc += 3 * defaultRowHeight();
1132 // This is special code for the chapter, since the label of this
1133 // layout is printed in an extra row
1134 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1135 && bv()->buffer()->params.secnumdepth >= 0)
1137 float spacing_val = 1.0;
1138 if (!pit->params().spacing().isDefault()) {
1139 spacing_val = pit->params().spacing().getValue();
1141 spacing_val = bv()->buffer()->params.spacing.getValue();
1144 labeladdon = int(font_metrics::maxDescent(labelfont) *
1145 layout->spacing.getValue() *
1147 + int(font_metrics::maxAscent(labelfont) *
1148 layout->spacing.getValue() *
1152 // special code for the top label
1153 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1154 || layout->labeltype == LABEL_BIBLIO
1155 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1156 && pit->isFirstInSequence()
1157 && !pit->getLabelstring().empty())
1159 float spacing_val = 1.0;
1160 if (!pit->params().spacing().isDefault()) {
1161 spacing_val = pit->params().spacing().getValue();
1163 spacing_val = bv()->buffer()->params.spacing.getValue();
1167 (font_metrics::maxAscent(labelfont) *
1168 layout->spacing.getValue() *
1170 +(font_metrics::maxDescent(labelfont) *
1171 layout->spacing.getValue() *
1173 + layout->topsep * defaultRowHeight()
1174 + layout->labelbottomsep * defaultRowHeight());
1177 // and now the layout spaces, for example before and after a section,
1178 // or between the items of a itemize or enumerate environment
1180 if (!pit->params().pagebreakTop()) {
1181 Paragraph * prev = pit->previous();
1183 prev = pit->depthHook(pit->getDepth());
1184 if (prev && prev->layout() == layout &&
1185 prev->getDepth() == pit->getDepth() &&
1186 prev->getLabelWidthString() == pit->getLabelWidthString())
1188 layoutasc = (layout->itemsep * defaultRowHeight());
1189 } else if (rit != rows().begin()) {
1190 tmptop = layout->topsep;
1192 if (boost::prior(pit)->getDepth() >= pit->getDepth())
1193 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1196 layoutasc = (tmptop * defaultRowHeight());
1197 } else if (pit->params().lineTop()) {
1198 tmptop = layout->topsep;
1201 layoutasc = (tmptop * defaultRowHeight());
1204 prev = pit->outerHook();
1206 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1207 } else if (pit != ownerParagraphs().begin()) {
1208 ParagraphList::iterator prior_pit = boost::prior(pit);
1209 if (prior_pit->getDepth() != 0 ||
1210 prior_pit->layout() == layout) {
1211 maxasc += int(layout->parsep * defaultRowHeight());
1217 // is it a bottom line?
1218 RowList::iterator next_rit = boost::next(rit);
1219 if (next_rit == rows().end() ||
1220 next_rit->par() != pit) {
1221 // the bottom margin
1222 ParagraphList::iterator nextpit = boost::next(pit);
1223 if (nextpit == ownerParagraphs().end() &&
1225 maxdesc += PAPER_MARGIN;
1227 // add the vertical spaces, that the user added
1228 maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
1230 // do not forget the DTP-lines!
1231 // there height depends on the font of the nearest character
1232 if (pit->params().lineBottom())
1233 maxdesc += 2 * font_metrics::ascent('x',
1234 getFont(bv()->buffer(),
1236 max(pos_type(0), pit->size() - 1)));
1238 // and now the pagebreaks
1239 if (pit->params().pagebreakBottom())
1240 maxdesc += 3 * defaultRowHeight();
1242 // and now the layout spaces, for example before and after
1243 // a section, or between the items of a itemize or enumerate
1245 if (!pit->params().pagebreakBottom()
1246 && nextpit != ownerParagraphs().end()) {
1247 ParagraphList::iterator comparepit = pit;
1251 if (comparepit->getDepth() > nextpit->getDepth()) {
1252 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1253 comparepit = comparepit->depthHook(nextpit->getDepth());
1254 if (comparepit->layout()!= nextpit->layout()
1255 || nextpit->getLabelWidthString() !=
1256 comparepit->getLabelWidthString())
1258 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1260 if (unusual > usual)
1261 layoutdesc = unusual;
1264 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1266 if (comparepit->layout() != nextpit->layout()
1267 || nextpit->getLabelWidthString() !=
1268 comparepit->getLabelWidthString())
1269 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1274 // incalculate the layout spaces
1275 maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
1276 maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
1278 // calculate the new height of the text
1279 height -= rit->height();
1281 rit->height(maxasc + maxdesc + labeladdon);
1282 rit->baseline(maxasc + labeladdon);
1284 height += rit->height();
1286 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1289 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1292 rit->width(maxwidth);
1293 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1295 rit->width(int(maxwidth + x));
1297 width = max(0, workWidth());
1298 RowList::iterator it = rows().begin();
1299 RowList::iterator end = rows().end();
1300 for (; it != end; ++it) {
1301 if (it->width() > width)
1302 width = it->width();
1308 // Appends the implicit specified paragraph before the specified row,
1309 // start at the implicit given position
1310 void LyXText::appendParagraph(RowList::iterator rowit)
1312 lyx::Assert(rowit != rowlist_.end());
1314 pos_type const last = rowit->par()->size();
1318 pos_type z = rowBreakPoint(*rowit);
1320 RowList::iterator tmprow = rowit;
1324 Row newrow(rowit->par(), z);
1325 rowit = rowlist_.insert(boost::next(rowit), newrow);
1330 // Set the dimensions of the row
1331 // fixed fill setting now by calling inset->update() in
1332 // SingleWidth when needed!
1333 tmprow->fill(fill(tmprow, workWidth()));
1334 setHeightOfRow(tmprow);
1340 void LyXText::breakAgain(RowList::iterator rit)
1342 lyx::Assert(rit != rows().end());
1344 bool not_ready = true;
1347 pos_type z = rowBreakPoint(*rit);
1348 RowList::iterator tmprit = rit;
1349 RowList::iterator end = rows().end();
1351 if (z < rit->par()->size()) {
1352 RowList::iterator next_rit = boost::next(rit);
1354 if (next_rit == end ||
1356 next_rit->par() != rit->par())) {
1359 Row newrow(rit->par(), z);
1360 rit = rowlist_.insert(next_rit, newrow);
1364 if (rit->pos() == z)
1365 not_ready = false; // the rest will not change
1371 // if there are some rows too much, delete them
1372 // only if you broke the whole paragraph!
1373 RowList::iterator tmprit2 = rit;
1374 while (boost::next(tmprit2) != end
1375 && boost::next(tmprit2)->par() == rit->par()) {
1378 while (tmprit2 != rit) {
1380 removeRow(boost::next(tmprit2));
1385 // set the dimensions of the row
1386 tmprit->fill(fill(tmprit, workWidth()));
1387 setHeightOfRow(tmprit);
1388 } while (not_ready);
1392 // this is just a little changed version of break again
1393 void LyXText::breakAgainOneRow(RowList::iterator rit)
1395 lyx::Assert(rit != rows().end());
1397 pos_type z = rowBreakPoint(*rit);
1398 RowList::iterator tmprit = rit;
1399 RowList::iterator end = rows().end();
1401 if (z < rit->par()->size()) {
1402 RowList::iterator next_rit = boost::next(rit);
1404 if (next_rit == end ||
1406 next_rit->par() != rit->par())) {
1409 Row newrow(rit->par(), z);
1410 rit = rowlist_.insert(next_rit, newrow);
1414 if (rit->pos() != z)
1418 // if there are some rows too much, delete them
1419 // only if you broke the whole paragraph!
1420 RowList::iterator tmprit2 = rit;
1421 while (boost::next(tmprit2) != end
1422 && boost::next(tmprit2)->par() == rit->par()) {
1425 while (tmprit2 != rit) {
1427 removeRow(boost::next(tmprit2));
1431 // set the dimensions of the row
1432 tmprit->fill(fill(tmprit, workWidth()));
1433 setHeightOfRow(tmprit);
1437 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1439 // allow only if at start or end, or all previous is new text
1440 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1441 && cursor.par()->isChangeEdited(0, cursor.pos()))
1444 LyXTextClass const & tclass =
1445 bv()->buffer()->params.getLyXTextClass();
1446 LyXLayout_ptr const & layout = cursor.par()->layout();
1448 // this is only allowed, if the current paragraph is not empty or caption
1449 // and if it has not the keepempty flag aktive
1450 if (cursor.par()->empty()
1451 && layout->labeltype != LABEL_SENSITIVE
1452 && !layout->keepempty)
1455 setUndo(bv(), Undo::FINISH, &*cursor.par(), &*boost::next(cursor.par()));
1457 // Always break behind a space
1459 // It is better to erase the space (Dekel)
1460 if (cursor.pos() < cursor.par()->size()
1461 && cursor.par()->isLineSeparator(cursor.pos()))
1462 cursor.par()->erase(cursor.pos());
1463 // cursor.pos(cursor.pos() + 1);
1465 // break the paragraph
1469 keep_layout = layout->isEnvironment();
1471 // we need to set this before we insert the paragraph. IMO the
1472 // breakParagraph call should return a bool if it inserts the
1473 // paragraph before or behind and we should react on that one
1474 // but we can fix this in 1.3.0 (Jug 20020509)
1475 bool const isempty = (layout->keepempty && cursor.par()->empty());
1476 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
1479 // well this is the caption hack since one caption is really enough
1480 if (layout->labeltype == LABEL_SENSITIVE) {
1482 // set to standard-layout
1483 cursor.par()->applyLayout(tclass.defaultLayout());
1485 // set to standard-layout
1486 boost::next(cursor.par())->applyLayout(tclass.defaultLayout());
1489 // if the cursor is at the beginning of a row without prior newline,
1491 // This touches only the screen-update. Otherwise we would may have
1492 // an empty row on the screen
1493 if (cursor.pos() && cursor.row()->pos() == cursor.pos()
1494 && !cursor.row()->par()->isNewline(cursor.pos() - 1))
1499 int y = cursor.y() - cursor.row()->baseline();
1501 // Do not forget the special right address boxes
1502 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1503 RowList::iterator r = cursor.row();
1504 RowList::iterator beg = rows().begin();
1506 while (r != beg && 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 ParagraphList::iterator next_par = boost::next(cursor.par());
1527 while (!next_par->empty() && next_par->isNewline(0))
1530 insertParagraph(next_par, boost::next(cursor.row()));
1533 // This check is necessary. Otherwise the new empty paragraph will
1534 // be deleted automatically. And it is more friendly for the user!
1535 if (cursor.pos() || isempty)
1536 setCursor(next_par, 0);
1538 setCursor(cursor.par(), 0);
1540 if (boost::next(cursor.row()) != rows().end())
1541 breakAgain(boost::next(cursor.row()));
1543 need_break_row = rows().end();
1547 // Just a macro to make some thing easier.
1548 void LyXText::redoParagraph()
1551 redoParagraphs(cursor, boost::next(cursor.par()));
1552 setCursorIntern(cursor.par(), cursor.pos());
1556 // insert a character, moves all the following breaks in the
1557 // same Paragraph one to the right and make a rebreak
1558 void LyXText::insertChar(char c)
1560 setUndo(bv(), Undo::INSERT, &*cursor.par(), &*boost::next(cursor.par()));
1562 // When the free-spacing option is set for the current layout,
1563 // disable the double-space checking
1565 bool const freeSpacing = cursor.row()->par()->layout()->free_spacing ||
1566 cursor.row()->par()->isFreeSpacing();
1568 if (lyxrc.auto_number) {
1569 static string const number_operators = "+-/*";
1570 static string const number_unary_operators = "+-";
1571 static string const number_seperators = ".,:";
1573 if (current_font.number() == LyXFont::ON) {
1574 if (!IsDigit(c) && !contains(number_operators, c) &&
1575 !(contains(number_seperators, c) &&
1576 cursor.pos() >= 1 &&
1577 cursor.pos() < cursor.par()->size() &&
1578 getFont(bv()->buffer(),
1580 cursor.pos()).number() == LyXFont::ON &&
1581 getFont(bv()->buffer(),
1583 cursor.pos() - 1).number() == LyXFont::ON)
1585 number(bv()); // Set current_font.number to OFF
1586 } else if (IsDigit(c) &&
1587 real_current_font.isVisibleRightToLeft()) {
1588 number(bv()); // Set current_font.number to ON
1590 if (cursor.pos() > 0) {
1591 char const c = cursor.par()->getChar(cursor.pos() - 1);
1592 if (contains(number_unary_operators, c) &&
1593 (cursor.pos() == 1 ||
1594 cursor.par()->isSeparator(cursor.pos() - 2) ||
1595 cursor.par()->isNewline(cursor.pos() - 2))
1597 setCharFont(bv()->buffer(),
1601 } else if (contains(number_seperators, c) &&
1602 cursor.pos() >= 2 &&
1603 getFont(bv()->buffer(),
1605 cursor.pos() - 2).number() == LyXFont::ON) {
1606 setCharFont(bv()->buffer(),
1616 // First check, if there will be two blanks together or a blank at
1617 // the beginning of a paragraph.
1618 // I decided to handle blanks like normal characters, the main
1619 // difference are the special checks when calculating the row.fill
1620 // (blank does not count at the end of a row) and the check here
1622 // The bug is triggered when we type in a description environment:
1623 // The current_font is not changed when we go from label to main text
1624 // and it should (along with realtmpfont) when we type the space.
1625 // CHECK There is a bug here! (Asger)
1627 LyXFont realtmpfont = real_current_font;
1628 LyXFont rawtmpfont = current_font;
1629 // store the current font. This is because of the use of cursor
1630 // movements. The moving cursor would refresh the current font
1632 // Get the font that is used to calculate the baselineskip
1633 pos_type const lastpos = cursor.par()->size();
1634 LyXFont rawparfont =
1635 cursor.par()->getFontSettings(bv()->buffer()->params,
1638 bool jumped_over_space = false;
1640 if (!freeSpacing && IsLineSeparatorChar(c)) {
1641 if ((cursor.pos() > 0
1642 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1643 || (cursor.pos() > 0
1644 && cursor.par()->isNewline(cursor.pos() - 1))
1645 || (cursor.pos() == 0)) {
1646 static bool sent_space_message = false;
1647 if (!sent_space_message) {
1648 if (cursor.pos() == 0)
1649 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1651 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1652 sent_space_message = true;
1659 // the display inset stuff
1660 if (cursor.row()->pos() < cursor.row()->par()->size()
1661 && cursor.row()->par()->isInset(cursor.row()->pos())) {
1662 Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
1663 if (inset && (inset->display() || inset->needFullRow())) {
1664 // force a new break
1665 cursor.row()->fill(-1); // to force a new break
1669 // get the cursor row fist
1670 RowList::iterator row = cursor.row();
1671 int y = cursor.y() - row->baseline();
1672 if (c != Paragraph::META_INSET) {
1673 // Here case LyXText::InsertInset already insertet the character
1674 cursor.par()->insertChar(cursor.pos(), c);
1676 setCharFont(bv()->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
1678 if (!jumped_over_space) {
1679 // refresh the positions
1680 RowList::iterator tmprow = row;
1681 while (boost::next(tmprow) != rows().end() &&
1682 boost::next(tmprow)->par() == row->par()) {
1684 tmprow->pos(tmprow->pos() + 1);
1688 // Is there a break one row above
1689 if (row != rows().begin() &&
1690 boost::prior(row)->par() == row->par()
1691 && (cursor.par()->isLineSeparator(cursor.pos())
1692 || cursor.par()->isNewline(cursor.pos())
1693 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1694 cursor.par()->isInset(cursor.pos() + 1))
1695 || cursor.row()->fill() == -1))
1697 pos_type z = rowBreakPoint(*boost::prior(row));
1699 if (z >= row->pos()) {
1702 // set the dimensions of the row above
1703 boost::prior(row)->fill(fill(
1707 setHeightOfRow(boost::prior(row));
1709 y -= boost::prior(row)->height();
1713 breakAgainOneRow(row);
1715 current_font = rawtmpfont;
1716 real_current_font = realtmpfont;
1717 setCursor(cursor.par(), cursor.pos() + 1,
1718 false, cursor.boundary());
1719 // cursor MUST be in row now.
1721 if (boost::next(row) != rows().end() &&
1722 boost::next(row)->par() == row->par())
1723 need_break_row = boost::next(row);
1725 need_break_row = rows().end();
1727 // check, wether the last characters font has changed.
1728 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1729 && rawparfont != rawtmpfont)
1730 redoHeightOfParagraph();
1737 // recalculate the fill of the row
1738 if (row->fill() >= 0) {
1739 // needed because a newline will set fill to -1. Otherwise
1740 // we would not get a rebreak!
1741 row->fill(fill(row, workWidth()));
1744 if (c == Paragraph::META_INSET || row->fill() < 0) {
1746 breakAgainOneRow(row);
1747 // will the cursor be in another row now?
1748 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1749 boost::next(row) != rows().end()) {
1750 if (boost::next(row) != rows().end() &&
1751 boost::next(row)->par() == row->par())
1752 // this should always be true
1754 breakAgainOneRow(row);
1756 current_font = rawtmpfont;
1757 real_current_font = realtmpfont;
1759 setCursor(cursor.par(), cursor.pos() + 1, false,
1761 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
1762 != cursor.boundary())
1763 setCursor(cursor.par(), cursor.pos(), false,
1764 !cursor.boundary());
1765 if (boost::next(row) != rows().end() &&
1766 boost::next(row)->par() == row->par())
1767 need_break_row = boost::next(row);
1769 need_break_row = rows().end();
1771 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1772 int const tmpheight = row->height();
1774 setHeightOfRow(row);
1776 if (tmpheight == row->height()) {
1777 postRowPaint(row, y);
1782 current_font = rawtmpfont;
1783 real_current_font = realtmpfont;
1784 setCursor(cursor.par(), cursor.pos() + 1, false,
1788 // check, wether the last characters font has changed.
1789 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1790 && rawparfont != rawtmpfont) {
1791 redoHeightOfParagraph();
1793 // now the special right address boxes
1794 if (cursor.par()->layout()->margintype
1795 == MARGIN_RIGHT_ADDRESS_BOX) {
1796 redoDrawingOfParagraph(cursor);
1804 void LyXText::charInserted()
1806 // Here we could call FinishUndo for every 20 characters inserted.
1807 // This is from my experience how emacs does it. (Lgb)
1808 static unsigned int counter;
1818 void LyXText::prepareToPrint(RowList::iterator rit, float & x,
1819 float & fill_separator,
1821 float & fill_label_hfill,
1824 float w = rit->fill();
1826 fill_label_hfill = 0;
1828 fill_label_hfill = 0;
1830 ParagraphList::iterator pit = rit->par();
1833 pit->isRightToLeftPar(bv()->buffer()->params);
1835 x = (workWidth() > 0)
1836 ? rightMargin(*bv()->buffer(), *rit) : 0;
1838 x = (workWidth() > 0)
1839 ? leftMargin(*rit) : 0;
1841 // is there a manual margin with a manual label
1842 LyXLayout_ptr const & layout = pit->layout();
1844 if (layout->margintype == MARGIN_MANUAL
1845 && layout->labeltype == LABEL_MANUAL) {
1846 /// We might have real hfills in the label part
1847 float nlh = numberOfLabelHfills(*this, rit);
1849 // A manual label par (e.g. List) has an auto-hfill
1850 // between the label text and the body of the
1852 // But we don't want to do this auto hfill if the par
1857 if (nlh && !pit->getLabelWidthString().empty()) {
1858 fill_label_hfill = labelFill(*rit) / nlh;
1862 // are there any hfills in the row?
1863 float const nh = numberOfHfills(*this, rit);
1867 fill_hfill = w / nh;
1868 // we don't have to look at the alignment if it is ALIGN_LEFT and
1869 // if the row is already larger then the permitted width as then
1870 // we force the LEFT_ALIGN'edness!
1871 } else if (static_cast<int>(rit->width()) < workWidth()) {
1872 // is it block, flushleft or flushright?
1873 // set x how you need it
1875 if (pit->params().align() == LYX_ALIGN_LAYOUT) {
1876 align = layout->align;
1878 align = pit->params().align();
1881 // center displayed insets
1883 if (rit->pos() < pit->size()
1884 && pit->isInset(rit->pos())
1885 && (inset = pit->getInset(rit->pos()))
1886 && (inset->display())) // || (inset->scroll() < 0)))
1887 align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
1888 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1889 // ERT insets should always be LEFT ALIGNED on screen
1890 inset = pit->inInset();
1891 if (inset && inset->owner() &&
1892 inset->owner()->lyxCode() == Inset::ERT_CODE)
1894 align = LYX_ALIGN_LEFT;
1898 case LYX_ALIGN_BLOCK:
1900 float const ns = numberOfSeparators(*this, rit);
1901 RowList::iterator next_row = boost::next(rit);
1902 ParagraphList::iterator next_pit = next_row->par();
1904 if (ns && next_row != rowlist_.end() &&
1906 !(next_pit->isNewline(next_row->pos() - 1))
1907 && !(next_pit->isInset(next_row->pos()) &&
1908 next_pit->getInset(next_row->pos()) &&
1909 next_pit->getInset(next_row->pos())->display())
1911 fill_separator = w / ns;
1912 } else if (is_rtl) {
1917 case LYX_ALIGN_RIGHT:
1920 case LYX_ALIGN_CENTER:
1928 computeBidiTables(bv()->buffer(), rit);
1930 pos_type body_pos = pit->beginningOfBody();
1931 pos_type last = lastPos(*this, rit);
1934 (body_pos - 1 > last ||
1935 !pit->isLineSeparator(body_pos - 1))) {
1936 x += font_metrics::width(layout->labelsep,
1937 getLabelFont(bv()->buffer(),
1939 if (body_pos - 1 <= last)
1940 x += fill_label_hfill;
1946 // important for the screen
1949 // the cursor set functions have a special mechanism. When they
1950 // realize, that you left an empty paragraph, they will delete it.
1951 // They also delete the corresponding row
1953 void LyXText::cursorRightOneWord()
1955 // treat floats, HFills and Insets as words
1956 ParagraphList::iterator pit = cursor.par();
1957 pos_type pos = cursor.pos();
1959 // CHECK See comment on top of text.C
1961 if (pos == pit->size()
1962 && boost::next(pit) != ownerParagraphs().end()) {
1966 // Skip through initial nonword stuff.
1967 while (pos < pit->size() && !pit->isWord(pos)) {
1970 // Advance through word.
1971 while (pos < pit->size() && pit->isWord(pos)) {
1975 setCursor(pit, pos);
1979 // Skip initial whitespace at end of word and move cursor to *start*
1980 // of prior word, not to end of next prior word.
1981 void LyXText::cursorLeftOneWord()
1983 LyXCursor tmpcursor = cursor;
1984 cursorLeftOneWord(tmpcursor);
1985 setCursor(tmpcursor.par(), tmpcursor.pos());
1989 void LyXText::cursorLeftOneWord(LyXCursor & cur)
1991 // treat HFills, floats and Insets as words
1993 ParagraphList::iterator pit = cursor.par();
1994 pos_type pos = cursor.pos();
1997 (pit->isSeparator(pos - 1) ||
1998 pit->isKomma(pos - 1) ||
1999 pit->isNewline(pos - 1)) &&
2000 !(pit->isHfill(pos - 1) ||
2001 pit->isInset(pos - 1)))
2005 (pit->isInset(pos - 1) ||
2006 pit->isHfill(pos - 1))) {
2009 if (pit != ownerParagraphs().begin()) {
2013 } else { // Here, cur != 0
2015 pit->isWord(pos - 1))
2024 // Select current word. This depends on behaviour of
2025 // CursorLeftOneWord(), so it is patched as well.
2026 void LyXText::getWord(LyXCursor & from, LyXCursor & to,
2027 word_location const loc)
2029 // first put the cursor where we wana start to select the word
2032 case WHOLE_WORD_STRICT:
2033 if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
2034 || cursor.par()->isSeparator(cursor.pos())
2035 || cursor.par()->isKomma(cursor.pos())
2036 || cursor.par()->isNewline(cursor.pos())
2037 || cursor.par()->isSeparator(cursor.pos() - 1)
2038 || cursor.par()->isKomma(cursor.pos() - 1)
2039 || cursor.par()->isNewline(cursor.pos() - 1)) {
2043 // no break here, we go to the next
2046 // Move cursor to the beginning, when not already there.
2047 if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
2048 && !(from.par()->isKomma(from.pos() - 1)
2049 || from.par()->isNewline(from.pos() - 1)))
2050 cursorLeftOneWord(from);
2053 // always move the cursor to the beginning of previous word
2054 cursorLeftOneWord(from);
2057 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
2063 while (to.pos() < to.par()->size()
2064 && !to.par()->isSeparator(to.pos())
2065 && !to.par()->isKomma(to.pos())
2066 && !to.par()->isNewline(to.pos())
2067 && !to.par()->isHfill(to.pos())
2068 && !to.par()->isInset(to.pos()))
2070 to.pos(to.pos() + 1);
2075 void LyXText::selectWord(word_location loc)
2079 getWord(from, to, loc);
2081 setCursor(from.par(), from.pos());
2084 selection.cursor = cursor;
2085 setCursor(to.par(), to.pos());
2090 // Select the word currently under the cursor when no
2091 // selection is currently set
2092 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2094 if (!selection.set()) {
2096 return selection.set();
2102 void LyXText::acceptChange()
2104 if (!selection.set() && cursor.par()->size())
2109 if (selection.start.par() == selection.end.par()) {
2110 LyXCursor & startc = selection.start;
2111 LyXCursor & endc = selection.end;
2112 setUndo(bv(), Undo::INSERT, &*startc.par(), &*boost::next(startc.par()));
2113 startc.par()->acceptChange(startc.pos(), endc.pos());
2116 redoParagraphs(startc, boost::next(startc.par()));
2117 setCursorIntern(startc.par(), 0);
2119 #warning handle multi par selection
2123 void LyXText::rejectChange()
2125 if (!selection.set() && cursor.par()->size())
2130 if (selection.start.par() == selection.end.par()) {
2131 LyXCursor & startc = selection.start;
2132 LyXCursor & endc = selection.end;
2133 setUndo(bv(), Undo::INSERT, &*startc.par(),
2134 &*boost::next(startc.par()));
2135 startc.par()->rejectChange(startc.pos(), endc.pos());
2138 redoParagraphs(startc, boost::next(startc.par()));
2139 setCursorIntern(startc.par(), 0);
2141 #warning handle multi par selection
2145 // This function is only used by the spellchecker for NextWord().
2146 // It doesn't handle LYX_ACCENTs and probably never will.
2148 LyXText::selectNextWordToSpellcheck(float & value)
2150 if (the_locking_inset) {
2151 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2152 if (!word.word().empty()) {
2153 value += float(cursor.y());
2154 value /= float(height);
2157 // we have to go on checking so move cursor to the next char
2158 if (cursor.pos() == cursor.par()->size()) {
2159 if (boost::next(cursor.par()) == ownerParagraphs().end())
2161 cursor.par(boost::next(cursor.par()));
2164 cursor.pos(cursor.pos() + 1);
2166 ParagraphList::iterator tmppit = cursor.par();
2168 // If this is not the very first word, skip rest of
2169 // current word because we are probably in the middle
2170 // of a word if there is text here.
2171 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
2172 while (cursor.pos() < cursor.par()->size()
2173 && cursor.par()->isLetter(cursor.pos()))
2174 cursor.pos(cursor.pos() + 1);
2177 // Now, skip until we have real text (will jump paragraphs)
2179 ParagraphList::iterator cpit = cursor.par();
2180 pos_type const cpos(cursor.pos());
2182 if (cpos == cpit->size()) {
2183 if (boost::next(cpit) != ownerParagraphs().end()) {
2184 cursor.par(boost::next(cpit));
2191 bool const is_good_inset = cpit->isInset(cpos)
2192 && cpit->getInset(cpos)->allowSpellcheck();
2194 if (!isDeletedText(*cpit, cpos)
2195 && (is_good_inset || cpit->isLetter(cpos)))
2198 cursor.pos(cpos + 1);
2201 // now check if we hit an inset so it has to be a inset containing text!
2202 if (cursor.pos() < cursor.par()->size() &&
2203 cursor.par()->isInset(cursor.pos())) {
2205 cursor.par()->getInset(cursor.pos())->edit(bv());
2206 // now call us again to do the above trick
2207 // but obviously we have to start from down below ;)
2208 return bv()->text->selectNextWordToSpellcheck(value);
2211 // Update the value if we changed paragraphs
2212 if (cursor.par() != tmppit) {
2213 setCursor(cursor.par(), cursor.pos());
2214 value = float(cursor.y())/float(height);
2217 // Start the selection from here
2218 selection.cursor = cursor;
2221 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2222 .language()->code());
2223 // and find the end of the word (insets like optional hyphens
2224 // and ligature break are part of a word)
2225 while (cursor.pos() < cursor.par()->size()
2226 && cursor.par()->isLetter(cursor.pos())
2227 && !isDeletedText(*cursor.par(), cursor.pos()))
2228 cursor.pos(cursor.pos() + 1);
2230 // Finally, we copy the word to a string and return it
2232 if (selection.cursor.pos() < cursor.pos()) {
2234 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2235 if (!cursor.par()->isInset(i))
2236 str += cursor.par()->getChar(i);
2239 return WordLangTuple(str, lang_code);
2243 // This one is also only for the spellchecker
2244 void LyXText::selectSelectedWord()
2246 if (the_locking_inset) {
2247 the_locking_inset->selectSelectedWord(bv());
2250 // move cursor to the beginning
2251 setCursor(selection.cursor.par(), selection.cursor.pos());
2253 // set the sel cursor
2254 selection.cursor = cursor;
2256 // now find the end of the word
2257 while (cursor.pos() < cursor.par()->size()
2258 && (cursor.par()->isLetter(cursor.pos())))
2259 cursor.pos(cursor.pos() + 1);
2261 setCursor(cursor.par(), cursor.pos());
2263 // finally set the selection
2268 // Delete from cursor up to the end of the current or next word.
2269 void LyXText::deleteWordForward()
2271 if (cursor.par()->empty())
2274 LyXCursor tmpcursor = cursor;
2275 tmpcursor.row(0); //Â ??
2276 selection.set(true); // to avoid deletion
2277 cursorRightOneWord();
2278 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2279 selection.cursor = cursor;
2283 // Great, CutSelection() gets rid of multiple spaces.
2284 cutSelection(true, false);
2289 // Delete from cursor to start of current or prior word.
2290 void LyXText::deleteWordBackward()
2292 if (cursor.par()->empty())
2295 LyXCursor tmpcursor = cursor;
2296 tmpcursor.row(0); // ??
2297 selection.set(true); // to avoid deletion
2298 cursorLeftOneWord();
2299 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2300 selection.cursor = cursor;
2303 cutSelection(true, false);
2308 // Kill to end of line.
2309 void LyXText::deleteLineForward()
2311 if (cursor.par()->empty())
2312 // Paragraph is empty, so we just go to the right
2315 LyXCursor tmpcursor = cursor;
2316 // We can't store the row over a regular setCursor
2317 // so we set it to 0 and reset it afterwards.
2318 tmpcursor.row(0); //Â ??
2319 selection.set(true); // to avoid deletion
2321 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2322 selection.cursor = cursor;
2325 // What is this test for ??? (JMarc)
2326 if (!selection.set()) {
2327 deleteWordForward();
2329 cutSelection(true, false);
2335 void LyXText::changeCase(LyXText::TextCase action)
2340 if (selection.set()) {
2341 from = selection.start;
2344 getWord(from, to, PARTIAL_WORD);
2345 setCursor(to.par(), to.pos() + 1);
2348 lyx::Assert(from <= to);
2350 setUndo(bv(), Undo::FINISH, &*from.par(), &*boost::next(to.par()));
2352 pos_type pos = from.pos();
2353 ParagraphList::iterator pit = from.par();
2355 while (pit != ownerParagraphs().end() &&
2356 (pos != to.pos() || pit != to.par())) {
2357 if (pos == pit->size()) {
2362 unsigned char c = pit->getChar(pos);
2363 if (!IsInsetChar(c)) {
2365 case text_lowercase:
2368 case text_capitalization:
2370 action = text_lowercase;
2372 case text_uppercase:
2378 pit->setChar(pos, c);
2379 checkParagraph(pit, pos);
2384 if (to.row() != from.row())
2385 postPaint(from.y() - from.row()->baseline());
2389 void LyXText::Delete()
2391 // this is a very easy implementation
2393 LyXCursor old_cursor = cursor;
2394 int const old_cur_par_id = old_cursor.par()->id();
2395 int const old_cur_par_prev_id =
2396 (old_cursor.par() != ownerParagraphs().begin() ?
2397 boost::prior(old_cursor.par())->id() : -1);
2399 // just move to the right
2402 // CHECK Look at the comment here.
2403 // This check is not very good...
2404 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2405 // and that can very well delete the par or par->previous in
2406 // old_cursor. Will a solution where we compare paragraph id's
2408 if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
2409 == old_cur_par_prev_id
2410 && cursor.par()->id() != old_cur_par_id) {
2411 // delete-empty-paragraph-mechanism has done it
2415 // if you had success make a backspace
2416 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2417 LyXCursor tmpcursor = cursor;
2418 // to make sure undo gets the right cursor position
2419 cursor = old_cursor;
2420 setUndo(bv(), Undo::DELETE,
2421 &*cursor.par(), &*boost::next(cursor.par()));
2428 void LyXText::backspace()
2430 // Get the font that is used to calculate the baselineskip
2431 pos_type lastpos = cursor.par()->size();
2432 LyXFont rawparfont =
2433 cursor.par()->getFontSettings(bv()->buffer()->params,
2436 if (cursor.pos() == 0) {
2437 // The cursor is at the beginning of a paragraph,
2438 // so the the backspace will collapse two paragraphs into one.
2440 // but it's not allowed unless it's new
2441 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2444 // we may paste some paragraphs
2446 // is it an empty paragraph?
2449 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2450 // This is an empty paragraph and we delete it just by moving the cursor one step
2451 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2452 // of the paragraph.
2454 if (cursor.par() != ownerParagraphs().begin()) {
2455 ParagraphList::iterator tmppit = boost::prior(cursor.par());
2456 if (cursor.par()->layout() == tmppit->layout()
2457 && cursor.par()->getAlign() == tmppit->getAlign()) {
2458 // Inherit bottom DTD from the paragraph below.
2459 // (the one we are deleting)
2460 tmppit->params().lineBottom(cursor.par()->params().lineBottom());
2461 tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
2462 tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2467 // the layout things can change the height of a row !
2468 int const tmpheight = cursor.row()->height();
2469 setHeightOfRow(cursor.row());
2470 if (cursor.row()->height() != tmpheight) {
2471 postPaint(cursor.y() - cursor.row()->baseline());
2477 if (cursor.par() != ownerParagraphs().begin()) {
2478 setUndo(bv(), Undo::DELETE,
2479 &*boost::prior(cursor.par()),
2480 &*boost::next(cursor.par()));
2483 ParagraphList::iterator tmppit = cursor.par();
2484 RowList::iterator tmprow = cursor.row();
2486 // We used to do cursorLeftIntern() here, but it is
2487 // not a good idea since it triggers the auto-delete
2488 // mechanism. So we do a cursorLeftIntern()-lite,
2489 // without the dreaded mechanism. (JMarc)
2490 if (cursor.par() != ownerParagraphs().begin()) {
2491 // steps into the above paragraph.
2492 setCursorIntern(boost::prior(cursor.par()),
2493 boost::prior(cursor.par())->size(),
2497 // Pasting is not allowed, if the paragraphs have different
2498 // layout. I think it is a real bug of all other
2499 // word processors to allow it. It confuses the user.
2500 // Even so with a footnote paragraph and a non-footnote
2501 // paragraph. I will not allow pasting in this case,
2502 // because the user would be confused if the footnote behaves
2503 // different wether it is open or closed.
2505 // Correction: Pasting is always allowed with standard-layout
2506 LyXTextClass const & tclass =
2507 bv()->buffer()->params.getLyXTextClass();
2509 if (cursor.par() != tmppit
2510 && (cursor.par()->layout() == tmppit->layout()
2511 || tmppit->layout() == tclass.defaultLayout())
2512 && cursor.par()->getAlign() == tmppit->getAlign()) {
2513 removeParagraph(tmprow);
2515 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2517 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2518 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2519 // strangely enough it seems that commenting out the line above removes
2520 // most or all of the segfaults. I will however also try to move the
2521 // two Remove... lines in front of the PasteParagraph too.
2524 cursor.pos(cursor.pos() - 1);
2526 postPaint(cursor.y() - cursor.row()->baseline());
2528 // remove the lost paragraph
2529 // This one is not safe, since the paragraph that the tmprow and the
2530 // following rows belong to has been deleted by the PasteParagraph
2531 // above. The question is... could this be moved in front of the
2533 //RemoveParagraph(tmprow);
2534 //RemoveRow(tmprow);
2536 // This rebuilds the rows.
2537 appendParagraph(cursor.row());
2540 // the row may have changed, block, hfills etc.
2541 setCursor(cursor.par(), cursor.pos(), false);
2544 // this is the code for a normal backspace, not pasting
2546 setUndo(bv(), Undo::DELETE,
2547 &*cursor.par(), &*boost::next(cursor.par()));
2548 // We used to do cursorLeftIntern() here, but it is
2549 // not a good idea since it triggers the auto-delete
2550 // mechanism. So we do a cursorLeftIntern()-lite,
2551 // without the dreaded mechanism. (JMarc)
2552 setCursorIntern(cursor.par(), cursor.pos()- 1,
2553 false, cursor.boundary());
2555 if (cursor.par()->isInset(cursor.pos())) {
2556 // force complete redo when erasing display insets
2557 // this is a cruel method but safe..... Matthias
2558 if (cursor.par()->getInset(cursor.pos())->display() ||
2559 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2560 cursor.par()->erase(cursor.pos());
2566 RowList::iterator row = cursor.row();
2567 int y = cursor.y() - row->baseline();
2569 // remember that a space at the end of a row doesnt count
2570 // when calculating the fill
2571 if (cursor.pos() < lastPos(*this, row) ||
2572 !cursor.par()->isLineSeparator(cursor.pos())) {
2573 row->fill(row->fill() + singleWidth(
2578 // some special code when deleting a newline. This is similar
2579 // to the behavior when pasting paragraphs
2580 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2581 cursor.par()->erase(cursor.pos());
2582 // refresh the positions
2583 RowList::iterator tmprow = row;
2584 while (boost::next(tmprow) != rows().end() &&
2585 boost::next(tmprow)->par() == row->par()) {
2587 tmprow->pos(tmprow->pos() - 1);
2589 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2590 cursor.pos(cursor.pos() - 1);
2592 if (cursor.pos() < cursor.par()->size()
2593 && !cursor.par()->isSeparator(cursor.pos())) {
2594 cursor.par()->insertChar(cursor.pos(), ' ');
2595 setCharFont(bv()->buffer(), cursor.par(),
2596 cursor.pos(), current_font);
2597 // refresh the positions
2599 while (boost::next(tmprow) != rows().end() &&
2600 boost::next(tmprow)->par() == row->par()) {
2602 tmprow->pos(tmprow->pos() + 1);
2606 cursor.par()->erase(cursor.pos());
2608 // refresh the positions
2609 RowList::iterator tmprow = row;
2610 while (boost::next(tmprow) != rows().end() &&
2611 boost::next(tmprow)->par() == row->par()) {
2613 tmprow->pos(tmprow->pos() - 1);
2616 // delete newlines at the beginning of paragraphs
2617 while (!cursor.par()->empty() &&
2618 cursor.pos() < cursor.par()->size() &&
2619 cursor.par()->isNewline(cursor.pos()) &&
2620 cursor.pos() == cursor.par()->beginningOfBody()) {
2621 cursor.par()->erase(cursor.pos());
2622 // refresh the positions
2624 while (boost::next(tmprow) != rows().end() &&
2625 boost::next(tmprow)->par() == row->par()) {
2627 tmprow->pos(tmprow->pos() - 1);
2632 // is there a break one row above
2633 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2634 z = rowBreakPoint(*boost::prior(row));
2635 if (z >= row->pos()) {
2638 RowList::iterator tmprow = boost::prior(row);
2640 // maybe the current row is now empty
2641 if (row->pos() >= row->par()->size()) {
2644 need_break_row = rows().end();
2646 breakAgainOneRow(row);
2647 if (boost::next(row) != rows().end() &&
2648 boost::next(row)->par() == row->par())
2649 need_break_row = boost::next(row);
2651 need_break_row = rows().end();
2654 // set the dimensions of the row above
2655 y -= tmprow->height();
2656 tmprow->fill(fill(tmprow, workWidth()));
2657 setHeightOfRow(tmprow);
2661 setCursor(cursor.par(), cursor.pos(),
2662 false, cursor.boundary());
2663 //current_font = rawtmpfont;
2664 //real_current_font = realtmpfont;
2665 // check, whether the last character's font has changed.
2667 cursor.par()->getFontSettings(bv()->buffer()->params,
2668 cursor.par()->size() - 1))
2669 redoHeightOfParagraph();
2674 // break the cursor row again
2675 if (boost::next(row) != rows().end() &&
2676 boost::next(row)->par() == row->par() &&
2677 (lastPos(*this, row) == row->par()->size() - 1 ||
2678 rowBreakPoint(*row) != lastPos(*this, row))) {
2680 // it can happen that a paragraph loses one row
2681 // without a real breakup. This is when a word
2682 // is to long to be broken. Well, I don t care this
2684 if (lastPos(*this, row) == row->par()->size() - 1)
2685 removeRow(boost::next(row));
2689 breakAgainOneRow(row);
2690 // will the cursor be in another row now?
2691 if (boost::next(row) != rows().end() &&
2692 boost::next(row)->par() == row->par() &&
2693 lastPos(*this, row) <= cursor.pos()) {
2695 breakAgainOneRow(row);
2698 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2700 if (boost::next(row) != rows().end() &&
2701 boost::next(row)->par() == row->par())
2702 need_break_row = boost::next(row);
2704 need_break_row = rows().end();
2706 // set the dimensions of the row
2707 row->fill(fill(row, workWidth()));
2708 int const tmpheight = row->height();
2709 setHeightOfRow(row);
2710 if (tmpheight == row->height()) {
2711 postRowPaint(row, y);
2715 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2719 // current_font = rawtmpfont;
2720 // real_current_font = realtmpfont;
2722 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
2723 != cursor.boundary())
2724 setCursor(cursor.par(), cursor.pos(), false,
2725 !cursor.boundary());
2727 lastpos = cursor.par()->size();
2728 if (cursor.pos() == lastpos)
2731 // check, whether the last characters font has changed.
2733 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2734 redoHeightOfParagraph();
2736 // now the special right address boxes
2737 if (cursor.par()->layout()->margintype
2738 == MARGIN_RIGHT_ADDRESS_BOX) {
2739 redoDrawingOfParagraph(cursor);
2745 // returns pointer to a specified row
2747 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2752 return rowlist_.end();
2754 // find the first row of the specified paragraph
2755 RowList::iterator rit = rowlist_.begin();
2756 RowList::iterator end = rowlist_.end();
2757 while (boost::next(rit) != end && rit->par() != pit) {
2762 // now find the wanted row
2763 while (rit->pos() < pos
2764 && boost::next(rit) != end
2765 && boost::next(rit)->par() == pit
2766 && boost::next(rit)->pos() <= pos) {
2775 RowList::iterator LyXText::getRowNearY(int & y) const
2778 RowList::iterator rit = anchor_row_;
2779 RowList::iterator const beg = rows().begin();
2780 RowList::iterator const end = rows().end();
2782 if (rows().empty()) {
2789 int tmpy = rit->y();
2792 while (rit != end && tmpy <= y) {
2793 tmpy += rit->height();
2798 tmpy -= rit->height();
2801 while (rit != beg && tmpy > y) {
2803 tmpy -= rit->height();
2806 if (tmpy < 0 || rit == end) {
2818 int LyXText::getDepth() const
2820 return cursor.par()->getDepth();