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 "text_funcs.h"
34 #include "WordLangTuple.h"
35 #include "paragraph_funcs.h"
36 #include "rowpainter.h"
37 #include "lyxrow_funcs.h"
38 #include "metricsinfo.h"
40 #include "insets/insettext.h"
42 #include "support/textutils.h"
43 #include "support/LAssert.h"
44 #include "support/lstrings.h"
48 using namespace lyx::support;
56 using lyx::word_location;
58 using namespace bv_funcs;
60 /// top, right, bottom pixel margin
61 extern int const PAPER_MARGIN = 20;
62 /// margin for changebar
63 extern int const CHANGEBAR_MARGIN = 10;
65 extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
67 int bibitemMaxWidth(BufferView *, LyXFont const &);
70 BufferView * LyXText::bv()
72 Assert(bv_owner != 0);
77 BufferView * LyXText::bv() const
79 Assert(bv_owner != 0);
84 void LyXText::updateRowPositions()
86 RowList::iterator rit = rows().begin();
87 RowList::iterator rend = rows().end();
88 for (int y = 0; rit != rend ; ++rit) {
95 int LyXText::top_y() const
97 if (anchor_row_ == rowlist_.end())
100 return anchor_row_->y() + anchor_row_offset_;
104 void LyXText::top_y(int newy)
110 anchor_row_ = rows().begin();
111 anchor_row_offset_ = newy;
115 lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
118 RowList::iterator rit = getRowNearY(y);
120 if (rit == anchor_row_ && anchor_row_offset_ == newy - y) {
121 lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
126 anchor_row_offset_ = newy - y;
127 lyxerr[Debug::GUI] << "changing reference to row: " << &*anchor_row_
128 << " offset: " << anchor_row_offset_ << endl;
133 void LyXText::anchor_row(RowList::iterator rit)
136 anchor_row_offset_ = 0;
138 anchor_row_offset_ = old_y - top_y();
139 lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
140 << &*anchor_row_ << " offset: "
141 << anchor_row_offset_ << endl;
145 int LyXText::workWidth() const
147 return inset_owner ? inset_owner->textWidth() : bv()->workWidth();
151 int LyXText::getRealCursorX() const
154 if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
155 x = the_locking_inset->getLyXText(bv())->getRealCursorX();
160 #warning FIXME This function seems to belong outside of LyxText.
161 unsigned char LyXText::transformChar(unsigned char c, Paragraph const & par,
164 if (!Encodings::is_arabic(c))
165 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
166 return c + (0xb0 - '0');
170 unsigned char const prev_char = pos > 0 ? par.getChar(pos - 1) : ' ';
171 unsigned char next_char = ' ';
173 pos_type const par_size = par.size();
175 for (pos_type i = pos + 1; i < par_size; ++i) {
176 unsigned char const par_char = par.getChar(i);
177 if (!Encodings::IsComposeChar_arabic(par_char)) {
178 next_char = par_char;
183 if (Encodings::is_arabic(next_char)) {
184 if (Encodings::is_arabic(prev_char) &&
185 !Encodings::is_arabic_special(prev_char))
186 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
188 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
190 if (Encodings::is_arabic(prev_char) &&
191 !Encodings::is_arabic_special(prev_char))
192 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
194 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
198 // This is the comments that some of the warnings below refers to.
199 // There are some issues in this file and I don't think they are
200 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
201 // this is a problem that has been here almost from day one and that a
202 // larger userbase with differenct access patters triggers the bad
203 // behaviour. (segfaults.) What I think happen is: In several places
204 // we store the paragraph in the current cursor and then moves the
205 // cursor. This movement of the cursor will delete paragraph at the
206 // old position if it is now empty. This will make the temporary
207 // pointer to the old cursor paragraph invalid and dangerous to use.
208 // And is some cases this will trigger a segfault. I have marked some
209 // of the cases where this happens with a warning, but I am sure there
210 // are others in this file and in text2.C. There is also a note in
211 // Delete() that you should read. In Delete I store the paragraph->id
212 // instead of a pointer to the paragraph. I am pretty sure this faulty
213 // use of temporary pointers to paragraphs that might have gotten
214 // invalidated (through a cursor movement) before they are used, are
215 // the cause of the strange crashes we get reported often.
217 // It is very tiresom to change this code, especially when it is as
218 // hard to read as it is. Help to fix all the cases where this is done
219 // would be greately appreciated.
223 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
225 if (pos >= pit->size())
228 char const c = pit->getChar(pos);
229 return singleWidth(pit, pos, c);
233 int LyXText::singleWidth(ParagraphList::iterator pit,
234 pos_type pos, char c) const
236 if (pos >= pit->size())
239 LyXFont const & font = getFont(pit, pos);
241 // The most common case is handled first (Asger)
242 if (IsPrintable(c)) {
243 if (font.language()->RightToLeft()) {
244 if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
245 lyxrc.font_norm_type == LyXRC::ISO_10646_1)
246 && font.language()->lang() == "arabic") {
247 if (Encodings::IsComposeChar_arabic(c))
250 c = transformChar(c, *pit, pos);
251 } else if (font.language()->lang() == "hebrew" &&
252 Encodings::IsComposeChar_hebrew(c))
255 return font_metrics::width(c, font);
258 if (c == Paragraph::META_INSET) {
259 InsetOld * tmpinset = pit->getInset(pos);
261 if (tmpinset->lyxCode() == InsetOld::HFILL_CODE) {
262 // Because of the representation as vertical lines
266 #warning enabling this fixes the 'insets of width 0 on load' problem
267 // this IS needed otherwise on initialitation we don't get the fill
268 // of the row right (ONLY on initialization if we read a file!)
269 // should be changed! (Jug 20011204)
270 //tmpinset->update(bv());
272 MetricsInfo mi(bv(), font, workWidth());
273 tmpinset->metrics(mi, dim);
276 return tmpinset->width();
282 if (IsSeparatorChar(c))
284 return font_metrics::width(c, font);
288 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
290 if (bidi_start == -1)
293 return log2vis_list[pos - bidi_start];
297 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
299 if (bidi_start == -1)
302 return vis2log_list[pos - bidi_start];
306 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
308 if (bidi_start == -1)
311 return bidi_levels[pos - bidi_start];
315 bool LyXText::bidi_InRange(lyx::pos_type pos) const
317 return bidi_start == -1 ||
318 (bidi_start <= pos && pos <= bidi_end);
322 void LyXText::computeBidiTables(Buffer const * buf,
323 RowList::iterator row) const
325 bidi_same_direction = true;
326 if (!lyxrc.rtl_support) {
331 ParagraphList::iterator row_par = row->par();
333 InsetOld * inset = row_par->inInset();
334 if (inset && inset->owner() &&
335 inset->owner()->lyxCode() == InsetOld::ERT_CODE) {
340 bidi_start = row->pos();
341 bidi_end = lastPrintablePos(*this, row);
343 if (bidi_start > bidi_end) {
348 if (bidi_end + 2 - bidi_start >
349 static_cast<pos_type>(log2vis_list.size())) {
351 (bidi_end + 2 - bidi_start < 500) ?
352 500 : 2 * (bidi_end + 2 - bidi_start);
353 log2vis_list.resize(new_size);
354 vis2log_list.resize(new_size);
355 bidi_levels.resize(new_size);
358 vis2log_list[bidi_end + 1 - bidi_start] = -1;
359 log2vis_list[bidi_end + 1 - bidi_start] = -1;
363 row_par->isRightToLeftPar(buf->params);
367 pos_type const body_pos = row_par->beginningOfBody();
369 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
370 bool is_space = row_par->isLineSeparator(lpos);
372 (is_space && lpos + 1 <= bidi_end &&
373 !row_par->isLineSeparator(lpos + 1) &&
374 !row_par->isNewline(lpos + 1))
376 LyXFont font = row_par->getFontSettings(buf->params, pos);
377 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
378 font.number() == LyXFont::ON &&
379 row_par->getFontSettings(buf->params, lpos - 1).number()
381 font = row_par->getFontSettings(buf->params, lpos);
386 bool new_rtl = font.isVisibleRightToLeft();
387 bool new_rtl0 = font.isRightToLeft();
390 if (lpos == body_pos - 1
391 && row->pos() < body_pos - 1
393 new_level = (rtl_par) ? 1 : 0;
394 new_rtl = new_rtl0 = rtl_par;
396 new_level = (new_rtl) ? 1 : 2;
398 new_level = (rtl_par) ? 2 : 0;
400 if (is_space && new_level >= level) {
406 int new_level2 = new_level;
408 if (level == new_level && rtl0 != new_rtl0) {
410 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
411 } else if (level < new_level) {
412 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
413 if (new_level > rtl_par)
414 bidi_same_direction = false;
416 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
419 bidi_levels[lpos - bidi_start] = new_level;
421 while (level > new_level2) {
422 pos_type old_lpos = stack[--level];
423 int delta = lpos - old_lpos - 1;
426 log2vis_list[lpos - bidi_start] += delta;
427 log2vis_list[old_lpos - bidi_start] += delta;
429 while (level < new_level)
430 stack[level++] = lpos;
434 pos_type const old_lpos = stack[--level];
435 int delta = bidi_end - old_lpos;
438 log2vis_list[old_lpos - bidi_start] += delta;
441 pos_type vpos = bidi_start - 1;
442 for (pos_type lpos = bidi_start;
443 lpos <= bidi_end; ++lpos) {
444 vpos += log2vis_list[lpos - bidi_start];
445 vis2log_list[vpos - bidi_start] = lpos;
446 log2vis_list[lpos - bidi_start] = vpos;
451 // This method requires a previous call to ComputeBidiTables()
452 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
455 if (!lyxrc.rtl_support || pos == 0)
458 if (!bidi_InRange(pos - 1)) {
459 /// This can happen if pos is the first char of a row.
460 /// Returning false in this case is incorrect!
464 bool const rtl = bidi_level(pos - 1) % 2;
465 bool const rtl2 = bidi_InRange(pos)
466 ? bidi_level(pos) % 2
467 : par.isRightToLeftPar(buf->params);
472 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
473 pos_type pos, LyXFont const & font) const
475 if (!lyxrc.rtl_support)
476 return false; // This is just for speedup
478 bool const rtl = font.isVisibleRightToLeft();
479 bool const rtl2 = bidi_InRange(pos)
480 ? bidi_level(pos) % 2
481 : par.isRightToLeftPar(buf->params);
486 int LyXText::leftMargin(Row const & row) const
490 if (row.pos() < row.par()->size())
491 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
492 (ins = row.par()->getInset(row.pos())) &&
493 (ins->needFullRow() || ins->display()))
496 LyXTextClass const & tclass =
497 bv()->buffer()->params.getLyXTextClass();
498 LyXLayout_ptr const & layout = row.par()->layout();
500 string parindent = layout->parindent;
504 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
506 // this is the way, LyX handles the LaTeX-Environments.
507 // I have had this idea very late, so it seems to be a
508 // later added hack and this is true
509 if (!row.par()->getDepth()) {
510 if (row.par()->layout() == tclass.defaultLayout()) {
511 // find the previous same level paragraph
512 if (row.par() != ownerParagraphs().begin()) {
513 ParagraphList::iterator newpit =
514 depthHook(row.par(), ownerParagraphs(),
515 row.par()->getDepth());
516 if (newpit == row.par() &&
517 newpit->layout()->nextnoindent)
522 // find the next level paragraph
524 ParagraphList::iterator newpar = outerHook(row.par(),
527 // make a corresponding row. Needed to call leftMargin()
529 // check wether it is a sufficent paragraph
530 if (newpar != ownerParagraphs().end() &&
531 newpar->layout()->isEnvironment()) {
533 dummyrow.par(newpar);
534 dummyrow.pos(newpar->size());
535 x = leftMargin(dummyrow);
538 if (newpar != ownerParagraphs().end() &&
539 row.par()->layout() == tclass.defaultLayout()) {
540 if (newpar->params().noindent())
543 parindent = newpar->layout()->parindent;
549 LyXFont const labelfont = getLabelFont(row.par());
550 switch (layout->margintype) {
552 if (!layout->leftmargin.empty()) {
553 x += font_metrics::signedWidth(layout->leftmargin,
554 tclass.defaultfont());
556 if (!row.par()->getLabelstring().empty()) {
557 x += font_metrics::signedWidth(layout->labelindent,
559 x += font_metrics::width(row.par()->getLabelstring(),
561 x += font_metrics::width(layout->labelsep, labelfont);
565 x += font_metrics::signedWidth(layout->labelindent, labelfont);
566 // The width of an empty par, even with manual label, should be 0
567 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
568 if (!row.par()->getLabelWidthString().empty()) {
569 x += font_metrics::width(row.par()->getLabelWidthString(),
571 x += font_metrics::width(layout->labelsep, labelfont);
576 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
577 / (row.par()->getDepth() + 4);
579 case MARGIN_FIRST_DYNAMIC:
580 if (layout->labeltype == LABEL_MANUAL) {
581 if (row.pos() >= row.par()->beginningOfBody()) {
582 x += font_metrics::signedWidth(layout->leftmargin,
585 x += font_metrics::signedWidth(layout->labelindent,
589 // Special case to fix problems with
591 || (layout->labeltype == LABEL_STATIC
592 && layout->latextype == LATEX_ENVIRONMENT
593 && !isFirstInSequence(row.par(), ownerParagraphs()))) {
594 x += font_metrics::signedWidth(layout->leftmargin,
596 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
597 && layout->labeltype != LABEL_BIBLIO
598 && layout->labeltype !=
599 LABEL_CENTERED_TOP_ENVIRONMENT) {
600 x += font_metrics::signedWidth(layout->labelindent,
602 x += font_metrics::width(layout->labelsep, labelfont);
603 x += font_metrics::width(row.par()->getLabelstring(),
608 case MARGIN_RIGHT_ADDRESS_BOX:
610 // ok, a terrible hack. The left margin depends on the widest
611 // row in this paragraph. Do not care about footnotes, they
612 // are *NOT* allowed in the LaTeX realisation of this layout.
614 // find the first row of this paragraph
615 RowList::iterator tmprit = rowlist_.begin();
616 while (tmprit != rowlist_.end()
617 && tmprit->par() != row.par())
620 int minfill = tmprit->fill();
621 while (boost::next(tmprit) != rowlist_.end() &&
622 boost::next(tmprit)->par() == row.par()) {
624 if (tmprit->fill() < minfill)
625 minfill = tmprit->fill();
628 x += font_metrics::signedWidth(layout->leftmargin,
629 tclass.defaultfont());
635 if ((workWidth() > 0) &&
636 !row.par()->params().leftIndent().zero())
638 LyXLength const len = row.par()->params().leftIndent();
639 int const tw = inset_owner ?
640 inset_owner->latexTextWidth(bv()) : workWidth();
641 x += len.inPixels(tw);
646 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
647 align = layout->align;
649 align = row.par()->params().align();
651 // set the correct parindent
652 if (row.pos() == 0) {
653 if ((layout->labeltype == LABEL_NO_LABEL
654 || layout->labeltype == LABEL_TOP_ENVIRONMENT
655 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
656 || (layout->labeltype == LABEL_STATIC
657 && layout->latextype == LATEX_ENVIRONMENT
658 && !isFirstInSequence(row.par(), ownerParagraphs())))
659 && align == LYX_ALIGN_BLOCK
660 && !row.par()->params().noindent()
661 // in tabulars and ert paragraphs are never indented!
662 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
663 (row.par()->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE &&
664 row.par()->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
665 && (row.par()->layout() != tclass.defaultLayout() ||
666 bv()->buffer()->params.paragraph_separation ==
667 BufferParams::PARSEP_INDENT)) {
668 x += font_metrics::signedWidth(parindent,
669 tclass.defaultfont());
670 } else if (layout->labeltype == LABEL_BIBLIO) {
671 // ale970405 Right width for bibitems
672 x += bibitemMaxWidth(bv(), tclass.defaultfont());
680 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
684 if (row.pos() < row.par()->size())
685 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
686 (ins = row.par()->getInset(row.pos())) &&
687 (ins->needFullRow() || ins->display()))
690 LyXTextClass const & tclass = buf.params.getLyXTextClass();
691 LyXLayout_ptr const & layout = row.par()->layout();
694 + font_metrics::signedWidth(tclass.rightmargin(),
695 tclass.defaultfont());
696 + font_metrics::signedWidth(layout->rightmargin,
697 tclass.defaultfont())
698 * 4 / (row.par()->getDepth() + 4);
702 int LyXText::labelEnd(Row const & row) const
704 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
706 tmprow.pos(row.par()->size());
707 // return the beginning of the body
708 return leftMargin(tmprow);
711 // LabelEnd is only needed if the layout
712 // fills a flushleft label.
719 // this needs special handling - only newlines count as a break point
720 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
722 for (; i < par.size(); ++i) {
723 if (par.isNewline(i))
733 pos_type LyXText::rowBreakPoint(Row const & row) const
735 ParagraphList::iterator pit = row.par();
737 // maximum pixel width of a row.
738 int width = workWidth() - rightMargin(*bv()->buffer(), row);
740 // inset->textWidth() returns -1 via workWidth(),
745 LyXLayout_ptr const & layout = pit->layout();
747 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
748 return addressBreakPoint(row.pos(), *pit);
750 pos_type const pos = row.pos();
751 pos_type const body_pos = pit->beginningOfBody();
752 pos_type const last = pit->size();
753 pos_type point = last;
758 // Now we iterate through until we reach the right margin
759 // or the end of the par, then choose the possible break
762 int const left = leftMargin(row);
765 // pixel width since last breakpoint
767 bool fullrow = false;
771 // We re-use the font resolution for the entire font span when possible
772 LyXFont font = getFont(pit, i);
773 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
775 for (; i < last; ++i) {
776 if (pit->isNewline(i)) {
781 char const c = pit->getChar(i);
785 // add the auto-hfill from label end to the body
786 if (body_pos && i == body_pos) {
787 thiswidth = font_metrics::width(layout->labelsep, getLabelFont(pit));
788 if (pit->isLineSeparator(i - 1))
789 thiswidth -= singleWidth(pit, i - 1);
790 int left_margin = labelEnd(row);
791 if (thiswidth + x < left_margin)
792 thiswidth = left_margin - x;
793 thiswidth += singleWidth(pit, i, c);
795 // Manual inlined optimised version of common case of "thiswidth = singleWidth(pit, i, c);"
796 if (IsPrintable(c)) {
797 if (pos > endPosOfFontSpan) {
798 // We need to get the next font
799 font = getFont(pit, i);
800 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
802 if (! font.language()->RightToLeft()) {
803 thiswidth = font_metrics::width(c, font);
805 // Fall-back to normal case
806 thiswidth = singleWidth(pit, i, c);
807 // And flush font cache
808 endPosOfFontSpan = 0;
811 // Fall-back to normal case
812 thiswidth = singleWidth(pit, i, c);
813 // And flush font cache
814 endPosOfFontSpan = 0;
819 chunkwidth += thiswidth;
821 InsetOld * in = pit->isInset(i) ? pit->getInset(i) : 0;
822 fullrow = in && (in->display() || in->needFullRow());
824 // break before a character that will fall off
825 // the right of the row
827 // if no break before or we are at an inset
828 // that will take up a row, break here
829 if (point == last || fullrow || chunkwidth >= (width - left)) {
838 if (!in || in->isChar()) {
839 // some insets are line separators too
840 if (pit->isLineSeparator(i)) {
850 // full row insets start at a new row
852 if (pos < last - 1) {
854 if (pit->isLineSeparator(i + 1))
857 // to avoid extra rows
867 if (point == last && x >= width) {
868 // didn't find one, break at the point we reached the edge
870 } else if (i == last && x < width) {
871 // found one, but we fell off the end of the par, so prefer
876 // manual labels cannot be broken in LaTeX. But we
877 // want to make our on-screen rendering of footnotes
879 if (!fullrow && body_pos && point < body_pos)
880 point = body_pos - 1;
886 // returns the minimum space a row needs on the screen in pixel
887 int LyXText::fill(RowList::iterator row, int paper_width) const
893 // get the pure distance
894 pos_type const last = lastPrintablePos(*this, row);
896 ParagraphList::iterator pit = row->par();
897 LyXLayout_ptr const & layout = pit->layout();
899 // special handling of the right address boxes
900 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
901 int const tmpfill = row->fill();
902 row->fill(0); // the minfill in MarginLeft()
903 w = leftMargin(*row);
906 w = leftMargin(*row);
908 pos_type const body_pos = pit->beginningOfBody();
909 pos_type i = row->pos();
911 if (! pit->empty() && i <= last) {
912 // We re-use the font resolution for the entire span when possible
913 LyXFont font = getFont(pit, i);
914 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
916 if (body_pos > 0 && i == body_pos) {
917 w += font_metrics::width(layout->labelsep, getLabelFont(pit));
918 if (pit->isLineSeparator(i - 1))
919 w -= singleWidth(pit, i - 1);
920 int left_margin = labelEnd(*row);
924 { // Manual inlined an optimised version of the common case of "w += singleWidth(pit, i);"
925 char const c = pit->getChar(i);
927 if (IsPrintable(c)) {
928 if (i > endPosOfFontSpan) {
929 // We need to get the next font
930 font = getFont(pit, i);
931 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
933 if (!font.language()->RightToLeft()) {
934 w += font_metrics::width(c, font);
936 // Fall-back to the normal case
937 w += singleWidth(pit, i, c);
938 // And flush font cache
939 endPosOfFontSpan = 0;
942 // Fall-back to the normal case
943 w += singleWidth(pit, i, c);
944 // And flush font cache
945 endPosOfFontSpan = 0;
951 if (body_pos > 0 && body_pos > last) {
952 w += font_metrics::width(layout->labelsep, getLabelFont(pit));
953 if (last >= 0 && pit->isLineSeparator(last))
954 w -= singleWidth(pit, last);
955 int const left_margin = labelEnd(*row);
960 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
962 // If this case happens, it means that our calculation
963 // of the widths of the chars when we do rowBreakPoint()
964 // went wrong for some reason. Typically in list bodies.
965 // Things just about hobble on anyway, though you'll end
966 // up with a "fill_separator" less than zero, which corresponds
967 // to inter-word spacing being too small. Hopefully this problem
968 // will die when the label hacks die.
969 if (lyxerr.debugging() && fill < 0) {
970 lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
971 << " w " << w << " paper_width " << paper_width
972 << " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
978 // returns the minimum space a manual label needs on the screen in pixel
979 int LyXText::labelFill(Row const & row) const
981 ParagraphList::iterator pit = row.par();
983 pos_type last = pit->beginningOfBody();
987 // -1 because a label ends either with a space that is in the label,
988 // or with the beginning of a footnote that is outside the label.
991 // a separator at this end does not count
992 if (pit->isLineSeparator(last))
996 pos_type i = row.pos();
998 w += singleWidth(pit, i);
1003 string const & labwidstr = pit->params().labelWidthString();
1004 if (!labwidstr.empty()) {
1005 LyXFont const labfont = getLabelFont(pit);
1006 int const labwidth = font_metrics::width(labwidstr, labfont);
1007 fill = max(labwidth - w, 0);
1014 LColor::color LyXText::backgroundColor() const
1017 return inset_owner->backgroundColor();
1019 return LColor::background;
1023 void LyXText::setHeightOfRow(RowList::iterator rit)
1025 Assert(rit != rows().end());
1027 // get the maximum ascent and the maximum descent
1028 double layoutasc = 0;
1029 double layoutdesc = 0;
1032 // ok, let us initialize the maxasc and maxdesc value.
1033 // Only the fontsize count. The other properties
1034 // are taken from the layoutfont. Nicer on the screen :)
1035 ParagraphList::iterator pit = rit->par();
1037 LyXLayout_ptr const & layout = pit->layout();
1039 // as max get the first character of this row then it can increase but not
1040 // decrease the height. Just some point to start with so we don't have to
1041 // do the assignment below too often.
1042 LyXFont font = getFont(pit, rit->pos());
1043 LyXFont::FONT_SIZE const tmpsize = font.size();
1044 font = getLayoutFont(pit);
1045 LyXFont::FONT_SIZE const size = font.size();
1046 font.setSize(tmpsize);
1048 LyXFont labelfont = getLabelFont(pit);
1050 double spacing_val = 1.0;
1051 if (!pit->params().spacing().isDefault())
1052 spacing_val = pit->params().spacing().getValue();
1054 spacing_val = bv()->buffer()->params.spacing.getValue();
1055 //lyxerr << "spacing_val = " << spacing_val << endl;
1057 int maxasc = int(font_metrics::maxAscent(font) *
1058 layout->spacing.getValue() * spacing_val);
1059 int maxdesc = int(font_metrics::maxDescent(font) *
1060 layout->spacing.getValue() * spacing_val);
1062 pos_type const pos_end = lastPos(*this, rit);
1066 if (!pit->empty()) {
1067 // We re-use the font resolution for the entire font span when possible
1068 LyXFont font = getFont(pit, rit->pos());
1069 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(rit->pos());
1072 Paragraph const & par = *pit;
1074 // Check if any insets are larger
1075 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1076 // Manual inlined optimised version of common case of
1077 // "maxwidth += singleWidth(pit, pos);"
1078 char const c = par.getChar(pos);
1080 if (IsPrintable(c)) {
1081 if (pos > endPosOfFontSpan) {
1082 // We need to get the next font
1083 font = getFont(pit, pos);
1084 endPosOfFontSpan = par.getEndPosOfFontSpan(pos);
1086 if (! font.language()->RightToLeft()) {
1087 maxwidth += font_metrics::width(c, font);
1089 // Fall-back to normal case
1090 maxwidth += singleWidth(pit, pos, c);
1091 // And flush font cache
1092 endPosOfFontSpan = 0;
1095 // Special handling of insets - are any larger?
1096 if (par.isInset(pos)) {
1097 LyXFont const tmpfont = getFont(pit, pos);
1098 InsetOld const * tmpinset = par.getInset(pos);
1100 #if 1 // this is needed for deep update on initialitation
1101 #warning inset->update FIXME
1102 //tmpinset->update(bv());
1104 MetricsInfo mi(bv(), tmpfont, workWidth());
1105 tmpinset->metrics(mi, dim);
1106 maxwidth += dim.wid;
1107 maxasc = max(maxasc, dim.asc);
1108 maxdesc = max(maxdesc, dim.des);
1110 maxwidth += tmpinset->width();
1111 maxasc = max(maxasc, tmpinset->ascent());
1112 maxdesc = max(maxdesc, tmpinset->descent());
1116 // Fall-back to normal case
1117 maxwidth += singleWidth(pit, pos, c);
1118 // And flush font cache
1119 endPosOfFontSpan = 0;
1125 // Check if any custom fonts are larger (Asger)
1126 // This is not completely correct, but we can live with the small,
1127 // cosmetic error for now.
1128 LyXFont::FONT_SIZE maxsize =
1129 pit->highestFontInRange(rit->pos(), pos_end, size);
1130 if (maxsize > font.size()) {
1131 font.setSize(maxsize);
1132 maxasc = max(maxasc, font_metrics::maxAscent(font));
1133 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
1136 // This is nicer with box insets:
1140 rit->ascent_of_text(maxasc);
1142 // is it a top line?
1145 // some parksips VERY EASY IMPLEMENTATION
1146 if (bv()->buffer()->params.paragraph_separation ==
1147 BufferParams::PARSEP_SKIP)
1149 if (layout->isParagraph()
1150 && pit->getDepth() == 0
1151 && pit != ownerParagraphs().begin())
1153 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1154 } else if (pit != ownerParagraphs().begin() &&
1155 boost::prior(pit)->layout()->isParagraph() &&
1156 boost::prior(pit)->getDepth() == 0)
1158 // is it right to use defskip here too? (AS)
1159 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1164 if (pit == ownerParagraphs().begin() && !isInInset())
1165 maxasc += PAPER_MARGIN;
1167 // add the vertical spaces, that the user added
1168 maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
1170 // do not forget the DTP-lines!
1171 // there height depends on the font of the nearest character
1172 if (pit->params().lineTop())
1174 maxasc += 2 * font_metrics::ascent('x', getFont(pit, 0));
1175 // and now the pagebreaks
1176 if (pit->params().pagebreakTop())
1177 maxasc += 3 * defaultRowHeight();
1179 if (pit->params().startOfAppendix())
1180 maxasc += 3 * defaultRowHeight();
1182 // This is special code for the chapter, since the label of this
1183 // layout is printed in an extra row
1184 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1185 && bv()->buffer()->params.secnumdepth >= 0)
1187 float spacing_val = 1.0;
1188 if (!pit->params().spacing().isDefault()) {
1189 spacing_val = pit->params().spacing().getValue();
1191 spacing_val = bv()->buffer()->params.spacing.getValue();
1194 labeladdon = int(font_metrics::maxDescent(labelfont) *
1195 layout->spacing.getValue() *
1197 + int(font_metrics::maxAscent(labelfont) *
1198 layout->spacing.getValue() *
1202 // special code for the top label
1203 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1204 || layout->labeltype == LABEL_BIBLIO
1205 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1206 && isFirstInSequence(pit, ownerParagraphs())
1207 && !pit->getLabelstring().empty())
1209 float spacing_val = 1.0;
1210 if (!pit->params().spacing().isDefault()) {
1211 spacing_val = pit->params().spacing().getValue();
1213 spacing_val = bv()->buffer()->params.spacing.getValue();
1217 (font_metrics::maxAscent(labelfont) *
1218 layout->spacing.getValue() *
1220 +(font_metrics::maxDescent(labelfont) *
1221 layout->spacing.getValue() *
1223 + layout->topsep * defaultRowHeight()
1224 + layout->labelbottomsep * defaultRowHeight());
1227 // And now the layout spaces, for example before and after
1228 // a section, or between the items of a itemize or enumerate
1231 if (!pit->params().pagebreakTop()) {
1232 ParagraphList::iterator prev =
1233 depthHook(pit, ownerParagraphs(),
1235 if (prev != pit && prev->layout() == layout &&
1236 prev->getDepth() == pit->getDepth() &&
1237 prev->getLabelWidthString() == pit->getLabelWidthString())
1239 layoutasc = (layout->itemsep * defaultRowHeight());
1240 } else if (rit != rows().begin()) {
1241 tmptop = layout->topsep;
1243 if (boost::prior(pit)->getDepth() >= pit->getDepth())
1244 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1247 layoutasc = (tmptop * defaultRowHeight());
1248 } else if (pit->params().lineTop()) {
1249 tmptop = layout->topsep;
1252 layoutasc = (tmptop * defaultRowHeight());
1255 prev = outerHook(pit, ownerParagraphs());
1256 if (prev != ownerParagraphs().end()) {
1257 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1258 } else if (pit != ownerParagraphs().begin()) {
1259 ParagraphList::iterator prior_pit = boost::prior(pit);
1260 if (prior_pit->getDepth() != 0 ||
1261 prior_pit->layout() == layout) {
1262 maxasc += int(layout->parsep * defaultRowHeight());
1268 // is it a bottom line?
1269 RowList::iterator next_rit = boost::next(rit);
1270 if (next_rit == rows().end() || next_rit->par() != pit) {
1271 // the bottom margin
1272 ParagraphList::iterator nextpit = boost::next(pit);
1273 if (nextpit == ownerParagraphs().end() &&
1275 maxdesc += PAPER_MARGIN;
1277 // add the vertical spaces, that the user added
1278 maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
1280 // do not forget the DTP-lines!
1281 // there height depends on the font of the nearest character
1282 if (pit->params().lineBottom())
1283 maxdesc += 2 * font_metrics::ascent('x',
1284 getFont(pit, max(pos_type(0), pit->size() - 1)));
1286 // and now the pagebreaks
1287 if (pit->params().pagebreakBottom())
1288 maxdesc += 3 * defaultRowHeight();
1290 // and now the layout spaces, for example before and after
1291 // a section, or between the items of a itemize or enumerate
1293 if (!pit->params().pagebreakBottom()
1294 && nextpit != ownerParagraphs().end()) {
1295 ParagraphList::iterator comparepit = pit;
1299 if (comparepit->getDepth() > nextpit->getDepth()) {
1300 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1301 comparepit = depthHook(comparepit, ownerParagraphs(), nextpit->getDepth());
1302 if (comparepit->layout()!= nextpit->layout()
1303 || nextpit->getLabelWidthString() !=
1304 comparepit->getLabelWidthString())
1306 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1308 if (unusual > usual)
1309 layoutdesc = unusual;
1312 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1314 if (comparepit->layout() != nextpit->layout()
1315 || nextpit->getLabelWidthString() !=
1316 comparepit->getLabelWidthString())
1317 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1322 // incalculate the layout spaces
1323 maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
1324 maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
1326 // calculate the new height of the text
1327 height -= rit->height();
1329 rit->height(maxasc + maxdesc + labeladdon);
1330 rit->baseline(maxasc + labeladdon);
1332 height += rit->height();
1334 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1337 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1339 rit->width(maxwidth);
1341 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1343 rit->width(int(maxwidth + x));
1345 width = max(0, workWidth());
1346 RowList::iterator it = rows().begin();
1347 RowList::iterator end = rows().end();
1348 for (; it != end; ++it)
1349 if (it->width() > width)
1350 width = it->width();
1355 // Appends the implicit specified paragraph before the specified row,
1356 // start at the implicit given position
1357 void LyXText::appendParagraph(RowList::iterator rowit)
1359 Assert(rowit != rowlist_.end());
1361 pos_type const last = rowit->par()->size();
1365 pos_type z = rowBreakPoint(*rowit);
1367 RowList::iterator tmprow = rowit;
1371 Row newrow(rowit->par(), z);
1372 rowit = rowlist_.insert(boost::next(rowit), newrow);
1377 // Set the dimensions of the row
1378 // fixed fill setting now by calling inset->update() in
1379 // SingleWidth when needed!
1380 tmprow->fill(fill(tmprow, workWidth()));
1381 setHeightOfRow(tmprow);
1387 void LyXText::breakAgain(RowList::iterator rit)
1389 Assert(rit != rows().end());
1391 bool not_ready = true;
1394 pos_type z = rowBreakPoint(*rit);
1395 RowList::iterator tmprit = rit;
1396 RowList::iterator end = rows().end();
1398 if (z < rit->par()->size()) {
1399 RowList::iterator next_rit = boost::next(rit);
1401 if (next_rit == end ||
1403 next_rit->par() != rit->par())) {
1406 Row newrow(rit->par(), z);
1407 rit = rowlist_.insert(next_rit, newrow);
1411 if (rit->pos() == z)
1412 not_ready = false; // the rest will not change
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));
1432 // set the dimensions of the row
1433 tmprit->fill(fill(tmprit, workWidth()));
1434 setHeightOfRow(tmprit);
1435 } while (not_ready);
1439 // this is just a little changed version of break again
1440 void LyXText::breakAgainOneRow(RowList::iterator rit)
1442 Assert(rit != rows().end());
1444 pos_type z = rowBreakPoint(*rit);
1445 RowList::iterator tmprit = rit;
1446 RowList::iterator end = rows().end();
1448 if (z < rit->par()->size()) {
1449 RowList::iterator next_rit = boost::next(rit);
1451 if (next_rit == end ||
1453 next_rit->par() != rit->par())) {
1456 Row newrow(rit->par(), z);
1457 rit = rowlist_.insert(next_rit, newrow);
1461 if (rit->pos() != z)
1465 // if there are some rows too much, delete them
1466 // only if you broke the whole paragraph!
1467 RowList::iterator tmprit2 = rit;
1468 while (boost::next(tmprit2) != end
1469 && boost::next(tmprit2)->par() == rit->par()) {
1472 while (tmprit2 != rit) {
1474 removeRow(boost::next(tmprit2));
1478 // set the dimensions of the row
1479 tmprit->fill(fill(tmprit, workWidth()));
1480 setHeightOfRow(tmprit);
1484 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1486 // allow only if at start or end, or all previous is new text
1487 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1488 && cursor.par()->isChangeEdited(0, cursor.pos()))
1491 LyXTextClass const & tclass =
1492 bv()->buffer()->params.getLyXTextClass();
1493 LyXLayout_ptr const & layout = cursor.par()->layout();
1495 // this is only allowed, if the current paragraph is not empty or caption
1496 // and if it has not the keepempty flag active
1497 if (cursor.par()->empty() && !cursor.par()->allowEmpty()
1498 && layout->labeltype != LABEL_SENSITIVE)
1501 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1503 // Always break behind a space
1505 // It is better to erase the space (Dekel)
1506 if (cursor.pos() < cursor.par()->size()
1507 && cursor.par()->isLineSeparator(cursor.pos()))
1508 cursor.par()->erase(cursor.pos());
1509 // cursor.pos(cursor.pos() + 1);
1511 // break the paragraph
1515 keep_layout = layout->isEnvironment();
1517 // we need to set this before we insert the paragraph. IMO the
1518 // breakParagraph call should return a bool if it inserts the
1519 // paragraph before or behind and we should react on that one
1520 // but we can fix this in 1.3.0 (Jug 20020509)
1521 bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty());
1522 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(),
1523 cursor.pos(), keep_layout);
1525 // well this is the caption hack since one caption is really enough
1526 if (layout->labeltype == LABEL_SENSITIVE) {
1528 // set to standard-layout
1529 cursor.par()->applyLayout(tclass.defaultLayout());
1531 // set to standard-layout
1532 boost::next(cursor.par())->applyLayout(tclass.defaultLayout());
1535 // if the cursor is at the beginning of a row without prior newline,
1537 // This touches only the screen-update. Otherwise we would may have
1538 // an empty row on the screen
1539 if (cursor.pos() && cursorRow()->pos() == cursor.pos()
1540 && !cursorRow()->par()->isNewline(cursor.pos() - 1))
1547 removeParagraph(cursorRow());
1549 // set the dimensions of the cursor row
1550 cursorRow()->fill(fill(cursorRow(), workWidth()));
1552 setHeightOfRow(cursorRow());
1554 #warning Trouble Point! (Lgb)
1555 // When ::breakParagraph is called from within an inset we must
1556 // ensure that the correct ParagraphList is used. Today that is not
1557 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1558 ParagraphList::iterator next_par = boost::next(cursor.par());
1560 while (!next_par->empty() && next_par->isNewline(0))
1563 insertParagraph(next_par, boost::next(cursorRow()));
1566 // This check is necessary. Otherwise the new empty paragraph will
1567 // be deleted automatically. And it is more friendly for the user!
1568 if (cursor.pos() || isempty)
1569 setCursor(next_par, 0);
1571 setCursor(cursor.par(), 0);
1573 if (boost::next(cursorRow()) != rows().end())
1574 breakAgain(boost::next(cursorRow()));
1578 // Just a macro to make some thing easier.
1579 void LyXText::redoParagraph()
1582 redoParagraphs(cursor, boost::next(cursor.par()));
1583 setCursorIntern(cursor.par(), cursor.pos());
1587 // insert a character, moves all the following breaks in the
1588 // same Paragraph one to the right and make a rebreak
1589 void LyXText::insertChar(char c)
1591 recordUndo(bv(), Undo::INSERT, cursor.par());
1593 // When the free-spacing option is set for the current layout,
1594 // disable the double-space checking
1596 bool const freeSpacing = cursorRow()->par()->layout()->free_spacing ||
1597 cursorRow()->par()->isFreeSpacing();
1599 if (lyxrc.auto_number) {
1600 static string const number_operators = "+-/*";
1601 static string const number_unary_operators = "+-";
1602 static string const number_seperators = ".,:";
1604 if (current_font.number() == LyXFont::ON) {
1605 if (!IsDigit(c) && !contains(number_operators, c) &&
1606 !(contains(number_seperators, c) &&
1607 cursor.pos() >= 1 &&
1608 cursor.pos() < cursor.par()->size() &&
1609 getFont(cursor.par(), cursor.pos()).number() == LyXFont::ON &&
1610 getFont(cursor.par(), cursor.pos() - 1).number() == LyXFont::ON)
1612 number(bv()); // Set current_font.number to OFF
1613 } else if (IsDigit(c) &&
1614 real_current_font.isVisibleRightToLeft()) {
1615 number(bv()); // Set current_font.number to ON
1617 if (cursor.pos() > 0) {
1618 char const c = cursor.par()->getChar(cursor.pos() - 1);
1619 if (contains(number_unary_operators, c) &&
1620 (cursor.pos() == 1 ||
1621 cursor.par()->isSeparator(cursor.pos() - 2) ||
1622 cursor.par()->isNewline(cursor.pos() - 2))
1628 } else if (contains(number_seperators, c) &&
1629 cursor.pos() >= 2 &&
1632 cursor.pos() - 2).number() == LyXFont::ON) {
1643 // First check, if there will be two blanks together or a blank at
1644 // the beginning of a paragraph.
1645 // I decided to handle blanks like normal characters, the main
1646 // difference are the special checks when calculating the row.fill
1647 // (blank does not count at the end of a row) and the check here
1649 // The bug is triggered when we type in a description environment:
1650 // The current_font is not changed when we go from label to main text
1651 // and it should (along with realtmpfont) when we type the space.
1652 // CHECK There is a bug here! (Asger)
1654 LyXFont realtmpfont = real_current_font;
1655 LyXFont rawtmpfont = current_font;
1656 // store the current font. This is because of the use of cursor
1657 // movements. The moving cursor would refresh the current font
1659 // Get the font that is used to calculate the baselineskip
1660 pos_type const lastpos = cursor.par()->size();
1661 LyXFont rawparfont =
1662 cursor.par()->getFontSettings(bv()->buffer()->params,
1665 bool jumped_over_space = false;
1667 if (!freeSpacing && IsLineSeparatorChar(c)) {
1668 if ((cursor.pos() > 0
1669 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1670 || (cursor.pos() > 0
1671 && cursor.par()->isNewline(cursor.pos() - 1))
1672 || (cursor.pos() == 0)) {
1673 static bool sent_space_message = false;
1674 if (!sent_space_message) {
1675 if (cursor.pos() == 0)
1676 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1678 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1679 sent_space_message = true;
1686 // the display inset stuff
1687 if (cursorRow()->pos() < cursorRow()->par()->size()
1688 && cursorRow()->par()->isInset(cursorRow()->pos())) {
1689 InsetOld * inset = cursorRow()->par()->getInset(cursorRow()->pos());
1690 if (inset && (inset->display() || inset->needFullRow())) {
1691 // force a new break
1692 cursorRow()->fill(-1); // to force a new break
1696 // get the cursor row fist
1697 RowList::iterator row = cursorRow();
1698 if (c != Paragraph::META_INSET) {
1699 // Here case LyXText::InsertInset already inserted the character
1700 cursor.par()->insertChar(cursor.pos(), c);
1702 setCharFont(cursor.par(), cursor.pos(), rawtmpfont);
1704 if (!jumped_over_space) {
1705 // refresh the positions
1706 RowList::iterator tmprow = row;
1707 while (boost::next(tmprow) != rows().end() &&
1708 boost::next(tmprow)->par() == row->par()) {
1710 tmprow->pos(tmprow->pos() + 1);
1714 // Is there a break one row above
1715 if (row != rows().begin() &&
1716 boost::prior(row)->par() == row->par()
1717 && (cursor.par()->isLineSeparator(cursor.pos())
1718 || cursor.par()->isNewline(cursor.pos())
1719 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1720 cursor.par()->isInset(cursor.pos() + 1))
1721 || cursorRow()->fill() == -1))
1723 pos_type z = rowBreakPoint(*boost::prior(row));
1725 if (z >= row->pos()) {
1728 // set the dimensions of the row above
1729 boost::prior(row)->fill(fill(
1733 setHeightOfRow(boost::prior(row));
1737 breakAgainOneRow(row);
1739 current_font = rawtmpfont;
1740 real_current_font = realtmpfont;
1741 setCursor(cursor.par(), cursor.pos() + 1,
1742 false, cursor.boundary());
1744 // cursor MUST be in row now.
1745 // check, wether the last characters font has changed.
1746 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1747 && rawparfont != rawtmpfont)
1748 redoHeightOfParagraph();
1755 // recalculate the fill of the row
1756 if (row->fill() >= 0) {
1757 // needed because a newline will set fill to -1. Otherwise
1758 // we would not get a rebreak!
1759 row->fill(fill(row, workWidth()));
1762 if (c == Paragraph::META_INSET || row->fill() < 0) {
1764 breakAgainOneRow(row);
1766 RowList::iterator next_row = boost::next(row);
1768 // will the cursor be in another row now?
1769 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1770 next_row != rows().end()) {
1771 if (next_row != rows().end() &&
1772 next_row->par() == row->par()) {
1773 // this should always be true
1777 breakAgainOneRow(row);
1779 current_font = rawtmpfont;
1780 real_current_font = realtmpfont;
1782 setCursor(cursor.par(), cursor.pos() + 1, false,
1784 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
1785 != cursor.boundary())
1786 setCursor(cursor.par(), cursor.pos(), false,
1787 !cursor.boundary());
1789 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1790 setHeightOfRow(row);
1793 current_font = rawtmpfont;
1794 real_current_font = realtmpfont;
1795 setCursor(cursor.par(), cursor.pos() + 1, false,
1799 // check, wether the last characters font has changed.
1800 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1801 && rawparfont != rawtmpfont) {
1802 redoHeightOfParagraph();
1809 void LyXText::charInserted()
1811 // Here we could call FinishUndo for every 20 characters inserted.
1812 // This is from my experience how emacs does it. (Lgb)
1813 static unsigned int counter;
1823 void LyXText::prepareToPrint(RowList::iterator rit, double & x,
1824 double & fill_separator,
1825 double & fill_hfill,
1826 double & fill_label_hfill,
1829 double w = rit->fill();
1831 fill_label_hfill = 0;
1833 fill_label_hfill = 0;
1835 ParagraphList::iterator pit = rit->par();
1838 pit->isRightToLeftPar(bv()->buffer()->params);
1840 x = workWidth() > 0 ? rightMargin(*bv()->buffer(), *rit) : 0;
1842 x = workWidth() > 0 ? leftMargin(*rit) : 0;
1844 // is there a manual margin with a manual label
1845 LyXLayout_ptr const & layout = pit->layout();
1847 if (layout->margintype == MARGIN_MANUAL
1848 && layout->labeltype == LABEL_MANUAL) {
1849 /// We might have real hfills in the label part
1850 int nlh = numberOfLabelHfills(*this, rit);
1852 // A manual label par (e.g. List) has an auto-hfill
1853 // between the label text and the body of the
1855 // But we don't want to do this auto hfill if the par
1860 if (nlh && !pit->getLabelWidthString().empty()) {
1861 fill_label_hfill = labelFill(*rit) / double(nlh);
1865 // are there any hfills in the row?
1866 int const nh = numberOfHfills(*this, rit);
1870 fill_hfill = w / nh;
1871 // we don't have to look at the alignment if it is ALIGN_LEFT and
1872 // if the row is already larger then the permitted width as then
1873 // we force the LEFT_ALIGN'edness!
1874 } else if (int(rit->width()) < workWidth()) {
1875 // is it block, flushleft or flushright?
1876 // set x how you need it
1878 if (pit->params().align() == LYX_ALIGN_LAYOUT) {
1879 align = layout->align;
1881 align = pit->params().align();
1884 // center displayed insets
1885 InsetOld * inset = 0;
1886 if (rit->pos() < pit->size()
1887 && pit->isInset(rit->pos())
1888 && (inset = pit->getInset(rit->pos()))
1889 && (inset->display())) // || (inset->scroll() < 0)))
1890 align = (inset->lyxCode() == InsetOld::MATHMACRO_CODE)
1891 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1892 // ERT insets should always be LEFT ALIGNED on screen
1893 inset = pit->inInset();
1894 if (inset && inset->owner() &&
1895 inset->owner()->lyxCode() == InsetOld::ERT_CODE)
1897 align = LYX_ALIGN_LEFT;
1901 case LYX_ALIGN_BLOCK:
1903 int const ns = numberOfSeparators(*this, rit);
1904 RowList::iterator next_row = boost::next(rit);
1905 ParagraphList::iterator next_pit = next_row->par();
1907 if (ns && next_row != rowlist_.end() &&
1909 !(next_pit->isNewline(next_row->pos() - 1))
1910 && !(next_pit->isInset(next_row->pos()) &&
1911 next_pit->getInset(next_row->pos()) &&
1912 next_pit->getInset(next_row->pos())->display())
1914 fill_separator = w / ns;
1915 } else if (is_rtl) {
1920 case LYX_ALIGN_RIGHT:
1923 case LYX_ALIGN_CENTER:
1931 computeBidiTables(bv()->buffer(), rit);
1933 pos_type body_pos = pit->beginningOfBody();
1934 pos_type last = lastPos(*this, rit);
1937 (body_pos - 1 > last ||
1938 !pit->isLineSeparator(body_pos - 1))) {
1939 x += font_metrics::width(layout->labelsep, getLabelFont(pit));
1940 if (body_pos - 1 <= last)
1941 x += fill_label_hfill;
1947 // important for the screen
1950 // the cursor set functions have a special mechanism. When they
1951 // realize, that you left an empty paragraph, they will delete it.
1952 // They also delete the corresponding row
1954 void LyXText::cursorRightOneWord()
1956 ::cursorRightOneWord(cursor, ownerParagraphs());
1957 setCursor(cursor.par(), cursor.pos());
1961 // Skip initial whitespace at end of word and move cursor to *start*
1962 // of prior word, not to end of next prior word.
1963 void LyXText::cursorLeftOneWord()
1965 LyXCursor tmpcursor = cursor;
1966 ::cursorLeftOneWord(tmpcursor, ownerParagraphs());
1967 setCursor(tmpcursor.par(), tmpcursor.pos());
1971 void LyXText::selectWord(word_location loc)
1973 LyXCursor from = cursor;
1975 ::getWord(from, to, loc, ownerParagraphs());
1977 setCursor(from.par(), from.pos());
1980 selection.cursor = cursor;
1981 setCursor(to.par(), to.pos());
1986 // Select the word currently under the cursor when no
1987 // selection is currently set
1988 bool LyXText::selectWordWhenUnderCursor(word_location loc)
1990 if (!selection.set()) {
1992 return selection.set();
1998 void LyXText::acceptChange()
2000 if (!selection.set() && cursor.par()->size())
2003 if (selection.start.par() == selection.end.par()) {
2004 LyXCursor & startc = selection.start;
2005 LyXCursor & endc = selection.end;
2006 recordUndo(bv(), Undo::INSERT, startc.par());
2007 startc.par()->acceptChange(startc.pos(), endc.pos());
2010 redoParagraphs(startc, boost::next(startc.par()));
2011 setCursorIntern(startc.par(), 0);
2013 #warning handle multi par selection
2017 void LyXText::rejectChange()
2019 if (!selection.set() && cursor.par()->size())
2022 if (selection.start.par() == selection.end.par()) {
2023 LyXCursor & startc = selection.start;
2024 LyXCursor & endc = selection.end;
2025 recordUndo(bv(), Undo::INSERT, startc.par());
2026 startc.par()->rejectChange(startc.pos(), endc.pos());
2029 redoParagraphs(startc, boost::next(startc.par()));
2030 setCursorIntern(startc.par(), 0);
2032 #warning handle multi par selection
2036 // This function is only used by the spellchecker for NextWord().
2037 // It doesn't handle LYX_ACCENTs and probably never will.
2039 LyXText::selectNextWordToSpellcheck(float & value)
2041 if (the_locking_inset) {
2042 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2043 if (!word.word().empty()) {
2044 value += float(cursor.y());
2045 value /= float(height);
2048 // we have to go on checking so move cursor to the next char
2049 if (cursor.pos() == cursor.par()->size()) {
2050 if (boost::next(cursor.par()) == ownerParagraphs().end())
2052 cursor.par(boost::next(cursor.par()));
2055 cursor.pos(cursor.pos() + 1);
2057 ParagraphList::iterator tmppit = cursor.par();
2059 // If this is not the very first word, skip rest of
2060 // current word because we are probably in the middle
2061 // of a word if there is text here.
2062 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
2063 while (cursor.pos() < cursor.par()->size()
2064 && cursor.par()->isLetter(cursor.pos()))
2065 cursor.pos(cursor.pos() + 1);
2068 // Now, skip until we have real text (will jump paragraphs)
2070 ParagraphList::iterator cpit = cursor.par();
2071 pos_type const cpos(cursor.pos());
2073 if (cpos == cpit->size()) {
2074 if (boost::next(cpit) != ownerParagraphs().end()) {
2075 cursor.par(boost::next(cpit));
2082 bool const is_good_inset = cpit->isInset(cpos)
2083 && cpit->getInset(cpos)->allowSpellcheck();
2085 if (!isDeletedText(*cpit, cpos)
2086 && (is_good_inset || cpit->isLetter(cpos)))
2089 cursor.pos(cpos + 1);
2092 // now check if we hit an inset so it has to be a inset containing text!
2093 if (cursor.pos() < cursor.par()->size() &&
2094 cursor.par()->isInset(cursor.pos())) {
2096 FuncRequest cmd(bv(), LFUN_INSET_EDIT, "left");
2097 cursor.par()->getInset(cursor.pos())->localDispatch(cmd);
2098 // now call us again to do the above trick
2099 // but obviously we have to start from down below ;)
2100 return bv()->text->selectNextWordToSpellcheck(value);
2103 // Update the value if we changed paragraphs
2104 if (cursor.par() != tmppit) {
2105 setCursor(cursor.par(), cursor.pos());
2106 value = float(cursor.y())/float(height);
2109 // Start the selection from here
2110 selection.cursor = cursor;
2112 string lang_code = getFont(cursor.par(), cursor.pos()).language()->code();
2113 // and find the end of the word (insets like optional hyphens
2114 // and ligature break are part of a word)
2115 while (cursor.pos() < cursor.par()->size()
2116 && cursor.par()->isLetter(cursor.pos())
2117 && !isDeletedText(*cursor.par(), cursor.pos()))
2118 cursor.pos(cursor.pos() + 1);
2120 // Finally, we copy the word to a string and return it
2122 if (selection.cursor.pos() < cursor.pos()) {
2124 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2125 if (!cursor.par()->isInset(i))
2126 str += cursor.par()->getChar(i);
2129 return WordLangTuple(str, lang_code);
2133 // This one is also only for the spellchecker
2134 void LyXText::selectSelectedWord()
2136 if (the_locking_inset) {
2137 the_locking_inset->selectSelectedWord(bv());
2140 // move cursor to the beginning
2141 setCursor(selection.cursor.par(), selection.cursor.pos());
2143 // set the sel cursor
2144 selection.cursor = cursor;
2146 // now find the end of the word
2147 while (cursor.pos() < cursor.par()->size()
2148 && (cursor.par()->isLetter(cursor.pos())))
2149 cursor.pos(cursor.pos() + 1);
2151 setCursor(cursor.par(), cursor.pos());
2153 // finally set the selection
2158 // Delete from cursor up to the end of the current or next word.
2159 void LyXText::deleteWordForward()
2161 if (cursor.par()->empty())
2164 LyXCursor tmpcursor = cursor;
2165 selection.set(true); // to avoid deletion
2166 cursorRightOneWord();
2167 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2168 selection.cursor = cursor;
2172 // Great, CutSelection() gets rid of multiple spaces.
2173 cutSelection(true, false);
2178 // Delete from cursor to start of current or prior word.
2179 void LyXText::deleteWordBackward()
2181 if (cursor.par()->empty())
2184 LyXCursor tmpcursor = cursor;
2185 selection.set(true); // to avoid deletion
2186 cursorLeftOneWord();
2187 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2188 selection.cursor = cursor;
2191 cutSelection(true, false);
2196 // Kill to end of line.
2197 void LyXText::deleteLineForward()
2199 if (cursor.par()->empty())
2200 // Paragraph is empty, so we just go to the right
2203 LyXCursor tmpcursor = cursor;
2204 // We can't store the row over a regular setCursor
2205 // so we set it to 0 and reset it afterwards.
2206 selection.set(true); // to avoid deletion
2208 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2209 selection.cursor = cursor;
2212 // What is this test for ??? (JMarc)
2213 if (!selection.set()) {
2214 deleteWordForward();
2216 cutSelection(true, false);
2222 void LyXText::changeCase(LyXText::TextCase action)
2227 if (selection.set()) {
2228 from = selection.start;
2232 ::getWord(from, to, lyx::PARTIAL_WORD, ownerParagraphs());
2233 setCursor(to.par(), to.pos() + 1);
2236 recordUndo(bv(), Undo::ATOMIC, from.par(), to.par());
2238 pos_type pos = from.pos();
2239 ParagraphList::iterator pit = from.par();
2241 while (pit != ownerParagraphs().end() &&
2242 (pos != to.pos() || pit != to.par())) {
2243 if (pos == pit->size()) {
2248 unsigned char c = pit->getChar(pos);
2249 if (!IsInsetChar(c)) {
2251 case text_lowercase:
2254 case text_capitalization:
2256 action = text_lowercase;
2258 case text_uppercase:
2264 pit->setChar(pos, c);
2265 checkParagraph(pit, pos);
2270 if (getRow(to) != getRow(from))
2275 void LyXText::Delete()
2277 // this is a very easy implementation
2279 LyXCursor old_cursor = cursor;
2280 int const old_cur_par_id = old_cursor.par()->id();
2281 int const old_cur_par_prev_id =
2282 (old_cursor.par() != ownerParagraphs().begin() ?
2283 boost::prior(old_cursor.par())->id() : -1);
2285 // just move to the right
2288 // CHECK Look at the comment here.
2289 // This check is not very good...
2290 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2291 // and that can very well delete the par or par->previous in
2292 // old_cursor. Will a solution where we compare paragraph id's
2294 if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
2295 == old_cur_par_prev_id
2296 && cursor.par()->id() != old_cur_par_id) {
2297 // delete-empty-paragraph-mechanism has done it
2301 // if you had success make a backspace
2302 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2303 LyXCursor tmpcursor = cursor;
2304 // to make sure undo gets the right cursor position
2305 cursor = old_cursor;
2306 recordUndo(bv(), Undo::DELETE, cursor.par());
2313 void LyXText::backspace()
2315 // Get the font that is used to calculate the baselineskip
2316 pos_type lastpos = cursor.par()->size();
2317 LyXFont rawparfont =
2318 cursor.par()->getFontSettings(bv()->buffer()->params,
2321 if (cursor.pos() == 0) {
2322 // The cursor is at the beginning of a paragraph,
2323 // so the the backspace will collapse two paragraphs into one.
2325 // but it's not allowed unless it's new
2326 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2329 // we may paste some paragraphs
2331 // is it an empty paragraph?
2334 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2335 // This is an empty paragraph and we delete it just by moving the cursor one step
2336 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2337 // of the paragraph.
2339 if (cursor.par() != ownerParagraphs().begin()) {
2340 ParagraphList::iterator tmppit = boost::prior(cursor.par());
2341 if (cursor.par()->layout() == tmppit->layout()
2342 && cursor.par()->getAlign() == tmppit->getAlign()) {
2343 // Inherit bottom DTD from the paragraph below.
2344 // (the one we are deleting)
2345 tmppit->params().lineBottom(cursor.par()->params().lineBottom());
2346 tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
2347 tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2352 // the layout things can change the height of a row !
2353 int const tmpheight = cursorRow()->height();
2354 setHeightOfRow(cursorRow());
2355 if (cursorRow()->height() != tmpheight)
2361 if (cursor.par() != ownerParagraphs().begin()) {
2362 recordUndo(bv(), Undo::DELETE,
2363 boost::prior(cursor.par()),
2367 ParagraphList::iterator tmppit = cursor.par();
2368 RowList::iterator tmprow = cursorRow();
2370 // We used to do cursorLeftIntern() here, but it is
2371 // not a good idea since it triggers the auto-delete
2372 // mechanism. So we do a cursorLeftIntern()-lite,
2373 // without the dreaded mechanism. (JMarc)
2374 if (cursor.par() != ownerParagraphs().begin()) {
2375 // steps into the above paragraph.
2376 setCursorIntern(boost::prior(cursor.par()),
2377 boost::prior(cursor.par())->size(),
2381 // Pasting is not allowed, if the paragraphs have different
2382 // layout. I think it is a real bug of all other
2383 // word processors to allow it. It confuses the user.
2384 // Even so with a footnote paragraph and a non-footnote
2385 // paragraph. I will not allow pasting in this case,
2386 // because the user would be confused if the footnote behaves
2387 // different wether it is open or closed.
2389 // Correction: Pasting is always allowed with standard-layout
2390 LyXTextClass const & tclass =
2391 bv()->buffer()->params.getLyXTextClass();
2393 if (cursor.par() != tmppit
2394 && (cursor.par()->layout() == tmppit->layout()
2395 || tmppit->layout() == tclass.defaultLayout())
2396 && cursor.par()->getAlign() == tmppit->getAlign()) {
2397 removeParagraph(tmprow);
2399 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2401 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2402 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2403 // strangely enough it seems that commenting out the line above removes
2404 // most or all of the segfaults. I will however also try to move the
2405 // two Remove... lines in front of the PasteParagraph too.
2408 cursor.pos(cursor.pos() - 1);
2412 // remove the lost paragraph
2413 // This one is not safe, since the paragraph that the tmprow and the
2414 // following rows belong to has been deleted by the PasteParagraph
2415 // above. The question is... could this be moved in front of the
2417 //RemoveParagraph(tmprow);
2418 //RemoveRow(tmprow);
2420 // This rebuilds the rows.
2421 appendParagraph(cursorRow());
2424 // the row may have changed, block, hfills etc.
2425 setCursor(cursor.par(), cursor.pos(), false);
2428 // this is the code for a normal backspace, not pasting
2430 recordUndo(bv(), Undo::DELETE, cursor.par());
2431 // We used to do cursorLeftIntern() here, but it is
2432 // not a good idea since it triggers the auto-delete
2433 // mechanism. So we do a cursorLeftIntern()-lite,
2434 // without the dreaded mechanism. (JMarc)
2435 setCursorIntern(cursor.par(), cursor.pos()- 1,
2436 false, cursor.boundary());
2438 if (cursor.par()->isInset(cursor.pos())) {
2439 // force complete redo when erasing display insets
2440 // this is a cruel method but safe..... Matthias
2441 if (cursor.par()->getInset(cursor.pos())->display() ||
2442 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2443 cursor.par()->erase(cursor.pos());
2449 RowList::iterator row = cursorRow();
2450 int y = cursor.y() - row->baseline();
2452 // remember that a space at the end of a row doesnt count
2453 // when calculating the fill
2454 if (cursor.pos() < lastPos(*this, row) ||
2455 !cursor.par()->isLineSeparator(cursor.pos())) {
2456 row->fill(row->fill() + singleWidth(
2461 // some special code when deleting a newline. This is similar
2462 // to the behavior when pasting paragraphs
2463 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2464 cursor.par()->erase(cursor.pos());
2465 // refresh the positions
2466 RowList::iterator tmprow = row;
2467 while (boost::next(tmprow) != rows().end() &&
2468 boost::next(tmprow)->par() == row->par()) {
2470 tmprow->pos(tmprow->pos() - 1);
2472 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2473 cursor.pos(cursor.pos() - 1);
2475 if (cursor.pos() < cursor.par()->size()
2476 && !cursor.par()->isSeparator(cursor.pos())) {
2477 cursor.par()->insertChar(cursor.pos(), ' ');
2478 setCharFont(cursor.par(), cursor.pos(), current_font);
2479 // refresh the positions
2481 while (boost::next(tmprow) != rows().end() &&
2482 boost::next(tmprow)->par() == row->par()) {
2484 tmprow->pos(tmprow->pos() + 1);
2488 cursor.par()->erase(cursor.pos());
2490 // refresh the positions
2491 RowList::iterator tmprow = row;
2492 while (boost::next(tmprow) != rows().end() &&
2493 boost::next(tmprow)->par() == row->par()) {
2495 tmprow->pos(tmprow->pos() - 1);
2498 // delete newlines at the beginning of paragraphs
2499 while (!cursor.par()->empty() &&
2500 cursor.pos() < cursor.par()->size() &&
2501 cursor.par()->isNewline(cursor.pos()) &&
2502 cursor.pos() == cursor.par()->beginningOfBody()) {
2503 cursor.par()->erase(cursor.pos());
2504 // refresh the positions
2506 while (boost::next(tmprow) != rows().end() &&
2507 boost::next(tmprow)->par() == row->par()) {
2509 tmprow->pos(tmprow->pos() - 1);
2514 // is there a break one row above
2515 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2516 z = rowBreakPoint(*boost::prior(row));
2517 if (z >= row->pos()) {
2520 RowList::iterator tmprow = boost::prior(row);
2522 // maybe the current row is now empty
2523 if (row->pos() >= row->par()->size()) {
2527 breakAgainOneRow(row);
2530 // set the dimensions of the row above
2531 y -= tmprow->height();
2532 tmprow->fill(fill(tmprow, workWidth()));
2533 setHeightOfRow(tmprow);
2536 setCursor(cursor.par(), cursor.pos(),
2537 false, cursor.boundary());
2538 //current_font = rawtmpfont;
2539 //real_current_font = realtmpfont;
2540 // check, whether the last character's font has changed.
2542 cursor.par()->getFontSettings(bv()->buffer()->params,
2543 cursor.par()->size() - 1))
2544 redoHeightOfParagraph();
2549 // break the cursor row again
2550 if (boost::next(row) != rows().end() &&
2551 boost::next(row)->par() == row->par() &&
2552 (lastPos(*this, row) == row->par()->size() - 1 ||
2553 rowBreakPoint(*row) != lastPos(*this, row))) {
2555 // it can happen that a paragraph loses one row
2556 // without a real breakup. This is when a word
2557 // is to long to be broken. Well, I don t care this
2559 if (lastPos(*this, row) == row->par()->size() - 1)
2560 removeRow(boost::next(row));
2564 breakAgainOneRow(row);
2565 // will the cursor be in another row now?
2566 if (boost::next(row) != rows().end() &&
2567 boost::next(row)->par() == row->par() &&
2568 lastPos(*this, row) <= cursor.pos()) {
2570 breakAgainOneRow(row);
2573 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2575 // set the dimensions of the row
2576 row->fill(fill(row, workWidth()));
2577 setHeightOfRow(row);
2579 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2583 // current_font = rawtmpfont;
2584 // real_current_font = realtmpfont;
2586 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
2587 != cursor.boundary())
2588 setCursor(cursor.par(), cursor.pos(), false, !cursor.boundary());
2590 lastpos = cursor.par()->size();
2591 if (cursor.pos() == lastpos)
2594 // check, whether the last characters font has changed.
2596 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2597 redoHeightOfParagraph();
2602 RowList::iterator LyXText::cursorRow() const
2604 return getRow(cursor.par(), cursor.pos());
2608 RowList::iterator LyXText::getRow(LyXCursor const & cur) const
2610 return getRow(cur.par(), cur.pos());
2615 LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
2618 return rowlist_.end();
2620 // find the first row of the specified paragraph
2621 RowList::iterator rit = rowlist_.begin();
2622 RowList::iterator end = rowlist_.end();
2623 while (boost::next(rit) != end && rit->par() != pit) {
2627 // now find the wanted row
2628 while (rit->pos() < pos
2629 && boost::next(rit) != end
2630 && boost::next(rit)->par() == pit
2631 && boost::next(rit)->pos() <= pos) {
2639 // returns pointer to a specified row
2641 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2646 return rowlist_.end();
2648 // find the first row of the specified paragraph
2649 RowList::iterator rit = rowlist_.begin();
2650 RowList::iterator end = rowlist_.end();
2651 while (boost::next(rit) != end && rit->par() != pit) {
2656 // now find the wanted row
2657 while (rit->pos() < pos
2658 && boost::next(rit) != end
2659 && boost::next(rit)->par() == pit
2660 && boost::next(rit)->pos() <= pos) {
2669 // returns pointer to some fancy row 'below' specified row
2670 RowList::iterator LyXText::cursorIRow() const
2673 return getRow(cursor.par(), cursor.pos(), y);
2677 RowList::iterator LyXText::getRowNearY(int & y) const
2679 RowList::iterator rit = anchor_row_;
2680 RowList::iterator const beg = rows().begin();
2681 RowList::iterator const end = rows().end();
2683 if (rows().empty()) {
2690 int tmpy = rit->y();
2693 while (rit != end && tmpy <= y) {
2694 tmpy += rit->height();
2699 tmpy -= rit->height();
2702 while (rit != beg && tmpy > y) {
2704 tmpy -= rit->height();
2707 if (tmpy < 0 || rit == end) {
2719 int LyXText::getDepth() const
2721 return cursor.par()->getDepth();