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::workWidth(InsetOld const * inset) const
153 ParagraphList::iterator par = ownerParagraphs().begin();
154 ParagraphList::iterator end = ownerParagraphs().end();
155 for ( ; par != end; ++par)
156 if (&*par == inset->parOwner())
159 if (par == ownerParagraphs().end()) {
160 lyxerr << "LyXText::workWidth: unexpected\n";
164 pos_type pos = par->getPositionOfInset(inset);
167 LyXLayout_ptr const & layout = par->layout();
169 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
170 // Optimization here: in most cases, the real row is
171 // not needed, but only the par/pos values. So we just
172 // construct a dummy row for leftMargin. (JMarc)
173 return workWidth() - leftMargin(Row(par, pos));
176 RowList::iterator row = getRow(par, pos);
177 RowList::iterator frow = row;
178 RowList::iterator beg = rowlist_.begin();
180 while (frow != beg && frow->par() == boost::prior(frow)->par())
183 // FIXME: I don't understand this code - jbl
185 unsigned int maxw = 0;
186 while (!isParEnd(*this, frow)) {
187 if (frow != row && maxw < frow->width())
188 maxw = frow->width();
191 return maxw ? maxw : workWidth();
195 int LyXText::getRealCursorX() const
198 if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
199 x = the_locking_inset->getLyXText(bv())->getRealCursorX();
204 #warning FIXME This function seems to belong outside of LyxText.
205 unsigned char LyXText::transformChar(unsigned char c, Paragraph const & par,
208 if (!Encodings::is_arabic(c))
209 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
210 return c + (0xb0 - '0');
214 unsigned char const prev_char = pos > 0 ? par.getChar(pos - 1) : ' ';
215 unsigned char next_char = ' ';
217 pos_type const par_size = par.size();
219 for (pos_type i = pos + 1; i < par_size; ++i) {
220 unsigned char const par_char = par.getChar(i);
221 if (!Encodings::IsComposeChar_arabic(par_char)) {
222 next_char = par_char;
227 if (Encodings::is_arabic(next_char)) {
228 if (Encodings::is_arabic(prev_char) &&
229 !Encodings::is_arabic_special(prev_char))
230 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
232 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
234 if (Encodings::is_arabic(prev_char) &&
235 !Encodings::is_arabic_special(prev_char))
236 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
238 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
242 // This is the comments that some of the warnings below refers to.
243 // There are some issues in this file and I don't think they are
244 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
245 // this is a problem that has been here almost from day one and that a
246 // larger userbase with differenct access patters triggers the bad
247 // behaviour. (segfaults.) What I think happen is: In several places
248 // we store the paragraph in the current cursor and then moves the
249 // cursor. This movement of the cursor will delete paragraph at the
250 // old position if it is now empty. This will make the temporary
251 // pointer to the old cursor paragraph invalid and dangerous to use.
252 // And is some cases this will trigger a segfault. I have marked some
253 // of the cases where this happens with a warning, but I am sure there
254 // are others in this file and in text2.C. There is also a note in
255 // Delete() that you should read. In Delete I store the paragraph->id
256 // instead of a pointer to the paragraph. I am pretty sure this faulty
257 // use of temporary pointers to paragraphs that might have gotten
258 // invalidated (through a cursor movement) before they are used, are
259 // the cause of the strange crashes we get reported often.
261 // It is very tiresom to change this code, especially when it is as
262 // hard to read as it is. Help to fix all the cases where this is done
263 // would be greately appreciated.
267 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
269 if (pos >= pit->size())
272 char const c = pit->getChar(pos);
273 return singleWidth(pit, pos, c);
277 int LyXText::singleWidth(ParagraphList::iterator pit,
278 pos_type pos, char c) const
280 if (pos >= pit->size())
283 LyXFont const & font = getFont(pit, pos);
285 // The most common case is handled first (Asger)
286 if (IsPrintable(c)) {
287 if (font.language()->RightToLeft()) {
288 if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
289 lyxrc.font_norm_type == LyXRC::ISO_10646_1)
290 && font.language()->lang() == "arabic") {
291 if (Encodings::IsComposeChar_arabic(c))
294 c = transformChar(c, *pit, pos);
295 } else if (font.language()->lang() == "hebrew" &&
296 Encodings::IsComposeChar_hebrew(c))
299 return font_metrics::width(c, font);
302 if (c == Paragraph::META_INSET) {
303 InsetOld * tmpinset = pit->getInset(pos);
305 if (tmpinset->lyxCode() == InsetOld::HFILL_CODE) {
306 // Because of the representation as vertical lines
310 #warning enabling this fixes the 'insets of width 0 on load' problem
311 // this IS needed otherwise on initialitation we don't get the fill
312 // of the row right (ONLY on initialization if we read a file!)
313 // should be changed! (Jug 20011204)
314 //tmpinset->update(bv());
316 MetricsInfo mi(bv(), font, workWidth());
317 tmpinset->metrics(mi, dim);
320 return tmpinset->width();
326 if (IsSeparatorChar(c))
328 return font_metrics::width(c, font);
332 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
334 if (bidi_start == -1)
337 return log2vis_list[pos - bidi_start];
341 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
343 if (bidi_start == -1)
346 return vis2log_list[pos - bidi_start];
350 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
352 if (bidi_start == -1)
355 return bidi_levels[pos - bidi_start];
359 bool LyXText::bidi_InRange(lyx::pos_type pos) const
361 return bidi_start == -1 ||
362 (bidi_start <= pos && pos <= bidi_end);
366 void LyXText::computeBidiTables(Buffer const * buf,
367 RowList::iterator row) const
369 bidi_same_direction = true;
370 if (!lyxrc.rtl_support) {
375 ParagraphList::iterator row_par = row->par();
377 InsetOld * inset = row_par->inInset();
378 if (inset && inset->owner() &&
379 inset->owner()->lyxCode() == InsetOld::ERT_CODE) {
384 bidi_start = row->pos();
385 bidi_end = lastPrintablePos(*this, row);
387 if (bidi_start > bidi_end) {
392 if (bidi_end + 2 - bidi_start >
393 static_cast<pos_type>(log2vis_list.size())) {
395 (bidi_end + 2 - bidi_start < 500) ?
396 500 : 2 * (bidi_end + 2 - bidi_start);
397 log2vis_list.resize(new_size);
398 vis2log_list.resize(new_size);
399 bidi_levels.resize(new_size);
402 vis2log_list[bidi_end + 1 - bidi_start] = -1;
403 log2vis_list[bidi_end + 1 - bidi_start] = -1;
407 row_par->isRightToLeftPar(buf->params);
411 pos_type const body_pos = row_par->beginningOfBody();
413 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
414 bool is_space = row_par->isLineSeparator(lpos);
416 (is_space && lpos + 1 <= bidi_end &&
417 !row_par->isLineSeparator(lpos + 1) &&
418 !row_par->isNewline(lpos + 1))
420 LyXFont font = row_par->getFontSettings(buf->params, pos);
421 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
422 font.number() == LyXFont::ON &&
423 row_par->getFontSettings(buf->params, lpos - 1).number()
425 font = row_par->getFontSettings(buf->params, lpos);
430 bool new_rtl = font.isVisibleRightToLeft();
431 bool new_rtl0 = font.isRightToLeft();
434 if (lpos == body_pos - 1
435 && row->pos() < body_pos - 1
437 new_level = (rtl_par) ? 1 : 0;
438 new_rtl = new_rtl0 = rtl_par;
440 new_level = (new_rtl) ? 1 : 2;
442 new_level = (rtl_par) ? 2 : 0;
444 if (is_space && new_level >= level) {
450 int new_level2 = new_level;
452 if (level == new_level && rtl0 != new_rtl0) {
454 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
455 } else if (level < new_level) {
456 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
457 if (new_level > rtl_par)
458 bidi_same_direction = false;
460 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
463 bidi_levels[lpos - bidi_start] = new_level;
465 while (level > new_level2) {
466 pos_type old_lpos = stack[--level];
467 int delta = lpos - old_lpos - 1;
470 log2vis_list[lpos - bidi_start] += delta;
471 log2vis_list[old_lpos - bidi_start] += delta;
473 while (level < new_level)
474 stack[level++] = lpos;
478 pos_type const old_lpos = stack[--level];
479 int delta = bidi_end - old_lpos;
482 log2vis_list[old_lpos - bidi_start] += delta;
485 pos_type vpos = bidi_start - 1;
486 for (pos_type lpos = bidi_start;
487 lpos <= bidi_end; ++lpos) {
488 vpos += log2vis_list[lpos - bidi_start];
489 vis2log_list[vpos - bidi_start] = lpos;
490 log2vis_list[lpos - bidi_start] = vpos;
495 // This method requires a previous call to ComputeBidiTables()
496 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
499 if (!lyxrc.rtl_support || pos == 0)
502 if (!bidi_InRange(pos - 1)) {
503 /// This can happen if pos is the first char of a row.
504 /// Returning false in this case is incorrect!
508 bool const rtl = bidi_level(pos - 1) % 2;
509 bool const rtl2 = bidi_InRange(pos)
510 ? bidi_level(pos) % 2
511 : par.isRightToLeftPar(buf->params);
516 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
517 pos_type pos, LyXFont const & font) const
519 if (!lyxrc.rtl_support)
520 return false; // This is just for speedup
522 bool const rtl = font.isVisibleRightToLeft();
523 bool const rtl2 = bidi_InRange(pos)
524 ? bidi_level(pos) % 2
525 : par.isRightToLeftPar(buf->params);
530 int LyXText::leftMargin(Row const & row) const
534 if (row.pos() < row.par()->size())
535 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
536 (ins = row.par()->getInset(row.pos())) &&
537 (ins->needFullRow() || ins->display()))
540 LyXTextClass const & tclass =
541 bv()->buffer()->params.getLyXTextClass();
542 LyXLayout_ptr const & layout = row.par()->layout();
544 string parindent = layout->parindent;
548 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
550 // this is the way, LyX handles the LaTeX-Environments.
551 // I have had this idea very late, so it seems to be a
552 // later added hack and this is true
553 if (!row.par()->getDepth()) {
554 if (row.par()->layout() == tclass.defaultLayout()) {
555 // find the previous same level paragraph
556 if (row.par() != ownerParagraphs().begin()) {
557 ParagraphList::iterator newpit =
558 depthHook(row.par(), ownerParagraphs(),
559 row.par()->getDepth());
560 if (newpit == row.par() &&
561 newpit->layout()->nextnoindent)
566 // find the next level paragraph
568 ParagraphList::iterator newpar = outerHook(row.par(),
571 // make a corresponding row. Needed to call leftMargin()
573 // check wether it is a sufficent paragraph
574 if (newpar != ownerParagraphs().end() &&
575 newpar->layout()->isEnvironment()) {
577 dummyrow.par(newpar);
578 dummyrow.pos(newpar->size());
579 x = leftMargin(dummyrow);
582 if (newpar != ownerParagraphs().end() &&
583 row.par()->layout() == tclass.defaultLayout()) {
584 if (newpar->params().noindent())
587 parindent = newpar->layout()->parindent;
593 LyXFont const labelfont = getLabelFont(row.par());
594 switch (layout->margintype) {
596 if (!layout->leftmargin.empty()) {
597 x += font_metrics::signedWidth(layout->leftmargin,
598 tclass.defaultfont());
600 if (!row.par()->getLabelstring().empty()) {
601 x += font_metrics::signedWidth(layout->labelindent,
603 x += font_metrics::width(row.par()->getLabelstring(),
605 x += font_metrics::width(layout->labelsep, labelfont);
609 x += font_metrics::signedWidth(layout->labelindent, labelfont);
610 // The width of an empty par, even with manual label, should be 0
611 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
612 if (!row.par()->getLabelWidthString().empty()) {
613 x += font_metrics::width(row.par()->getLabelWidthString(),
615 x += font_metrics::width(layout->labelsep, labelfont);
620 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
621 / (row.par()->getDepth() + 4);
623 case MARGIN_FIRST_DYNAMIC:
624 if (layout->labeltype == LABEL_MANUAL) {
625 if (row.pos() >= row.par()->beginningOfBody()) {
626 x += font_metrics::signedWidth(layout->leftmargin,
629 x += font_metrics::signedWidth(layout->labelindent,
633 // Special case to fix problems with
635 || (layout->labeltype == LABEL_STATIC
636 && layout->latextype == LATEX_ENVIRONMENT
637 && !isFirstInSequence(row.par(), ownerParagraphs()))) {
638 x += font_metrics::signedWidth(layout->leftmargin,
640 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
641 && layout->labeltype != LABEL_BIBLIO
642 && layout->labeltype !=
643 LABEL_CENTERED_TOP_ENVIRONMENT) {
644 x += font_metrics::signedWidth(layout->labelindent,
646 x += font_metrics::width(layout->labelsep, labelfont);
647 x += font_metrics::width(row.par()->getLabelstring(),
652 case MARGIN_RIGHT_ADDRESS_BOX:
654 // ok, a terrible hack. The left margin depends on the widest
655 // row in this paragraph. Do not care about footnotes, they
656 // are *NOT* allowed in the LaTeX realisation of this layout.
658 // find the first row of this paragraph
659 RowList::iterator tmprit = rowlist_.begin();
660 while (tmprit != rowlist_.end()
661 && tmprit->par() != row.par())
664 int minfill = tmprit->fill();
665 while (boost::next(tmprit) != rowlist_.end() &&
666 boost::next(tmprit)->par() == row.par()) {
668 if (tmprit->fill() < minfill)
669 minfill = tmprit->fill();
672 x += font_metrics::signedWidth(layout->leftmargin,
673 tclass.defaultfont());
679 if ((workWidth() > 0) &&
680 !row.par()->params().leftIndent().zero())
682 LyXLength const len = row.par()->params().leftIndent();
683 int const tw = inset_owner ?
684 inset_owner->latexTextWidth(bv()) : workWidth();
685 x += len.inPixels(tw);
690 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
691 align = layout->align;
693 align = row.par()->params().align();
695 // set the correct parindent
696 if (row.pos() == 0) {
697 if ((layout->labeltype == LABEL_NO_LABEL
698 || layout->labeltype == LABEL_TOP_ENVIRONMENT
699 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
700 || (layout->labeltype == LABEL_STATIC
701 && layout->latextype == LATEX_ENVIRONMENT
702 && !isFirstInSequence(row.par(), ownerParagraphs())))
703 && align == LYX_ALIGN_BLOCK
704 && !row.par()->params().noindent()
705 // in tabulars and ert paragraphs are never indented!
706 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
707 (row.par()->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE &&
708 row.par()->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
709 && (row.par()->layout() != tclass.defaultLayout() ||
710 bv()->buffer()->params.paragraph_separation ==
711 BufferParams::PARSEP_INDENT)) {
712 x += font_metrics::signedWidth(parindent,
713 tclass.defaultfont());
714 } else if (layout->labeltype == LABEL_BIBLIO) {
715 // ale970405 Right width for bibitems
716 x += bibitemMaxWidth(bv(), tclass.defaultfont());
724 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
728 if (row.pos() < row.par()->size())
729 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
730 (ins = row.par()->getInset(row.pos())) &&
731 (ins->needFullRow() || ins->display()))
734 LyXTextClass const & tclass = buf.params.getLyXTextClass();
735 LyXLayout_ptr const & layout = row.par()->layout();
738 + font_metrics::signedWidth(tclass.rightmargin(),
739 tclass.defaultfont());
740 + font_metrics::signedWidth(layout->rightmargin,
741 tclass.defaultfont())
742 * 4 / (row.par()->getDepth() + 4);
746 int LyXText::labelEnd(Row const & row) const
748 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
750 tmprow.pos(row.par()->size());
751 // return the beginning of the body
752 return leftMargin(tmprow);
755 // LabelEnd is only needed if the layout
756 // fills a flushleft label.
763 // this needs special handling - only newlines count as a break point
764 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
766 for (; i < par.size(); ++i) {
767 if (par.isNewline(i))
777 pos_type LyXText::rowBreakPoint(Row const & row) const
779 ParagraphList::iterator pit = row.par();
781 // maximum pixel width of a row.
782 int width = workWidth() - rightMargin(*bv()->buffer(), row);
784 // inset->textWidth() returns -1 via workWidth(),
789 LyXLayout_ptr const & layout = pit->layout();
791 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
792 return addressBreakPoint(row.pos(), *pit);
794 pos_type const pos = row.pos();
795 pos_type const body_pos = pit->beginningOfBody();
796 pos_type const last = pit->size();
797 pos_type point = last;
802 // Now we iterate through until we reach the right margin
803 // or the end of the par, then choose the possible break
806 int const left = leftMargin(row);
809 // pixel width since last breakpoint
811 bool fullrow = false;
815 // We re-use the font resolution for the entire font span when possible
816 LyXFont font = getFont(pit, i);
817 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
819 for (; i < last; ++i) {
820 if (pit->isNewline(i)) {
825 char const c = pit->getChar(i);
829 // add the auto-hfill from label end to the body
830 if (body_pos && i == body_pos) {
831 thiswidth = font_metrics::width(layout->labelsep, getLabelFont(pit));
832 if (pit->isLineSeparator(i - 1))
833 thiswidth -= singleWidth(pit, i - 1);
834 int left_margin = labelEnd(row);
835 if (thiswidth + x < left_margin)
836 thiswidth = left_margin - x;
837 thiswidth += singleWidth(pit, i, c);
839 // Manual inlined optimised version of common case of "thiswidth = singleWidth(pit, i, c);"
840 if (IsPrintable(c)) {
841 if (pos > endPosOfFontSpan) {
842 // We need to get the next font
843 font = getFont(pit, i);
844 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
846 if (! font.language()->RightToLeft()) {
847 thiswidth = font_metrics::width(c, font);
849 // Fall-back to normal case
850 thiswidth = singleWidth(pit, i, c);
851 // And flush font cache
852 endPosOfFontSpan = 0;
855 // Fall-back to normal case
856 thiswidth = singleWidth(pit, i, c);
857 // And flush font cache
858 endPosOfFontSpan = 0;
863 chunkwidth += thiswidth;
865 InsetOld * in = pit->isInset(i) ? pit->getInset(i) : 0;
866 fullrow = in && (in->display() || in->needFullRow());
868 // break before a character that will fall off
869 // the right of the row
871 // if no break before or we are at an inset
872 // that will take up a row, break here
873 if (point == last || fullrow || chunkwidth >= (width - left)) {
882 if (!in || in->isChar()) {
883 // some insets are line separators too
884 if (pit->isLineSeparator(i)) {
894 // full row insets start at a new row
896 if (pos < last - 1) {
898 if (pit->isLineSeparator(i + 1))
901 // to avoid extra rows
911 if (point == last && x >= width) {
912 // didn't find one, break at the point we reached the edge
914 } else if (i == last && x < width) {
915 // found one, but we fell off the end of the par, so prefer
920 // manual labels cannot be broken in LaTeX. But we
921 // want to make our on-screen rendering of footnotes
923 if (!fullrow && body_pos && point < body_pos)
924 point = body_pos - 1;
930 // returns the minimum space a row needs on the screen in pixel
931 int LyXText::fill(RowList::iterator row, int paper_width) const
937 // get the pure distance
938 pos_type const last = lastPrintablePos(*this, row);
940 ParagraphList::iterator pit = row->par();
941 LyXLayout_ptr const & layout = pit->layout();
943 // special handling of the right address boxes
944 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
945 int const tmpfill = row->fill();
946 row->fill(0); // the minfill in MarginLeft()
947 w = leftMargin(*row);
950 w = leftMargin(*row);
952 pos_type const body_pos = pit->beginningOfBody();
953 pos_type i = row->pos();
955 if (! pit->empty() && i <= last) {
956 // We re-use the font resolution for the entire span when possible
957 LyXFont font = getFont(pit, i);
958 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
960 if (body_pos > 0 && i == body_pos) {
961 w += font_metrics::width(layout->labelsep, getLabelFont(pit));
962 if (pit->isLineSeparator(i - 1))
963 w -= singleWidth(pit, i - 1);
964 int left_margin = labelEnd(*row);
968 { // Manual inlined an optimised version of the common case of "w += singleWidth(pit, i);"
969 char const c = pit->getChar(i);
971 if (IsPrintable(c)) {
972 if (i > endPosOfFontSpan) {
973 // We need to get the next font
974 font = getFont(pit, i);
975 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
977 if (!font.language()->RightToLeft()) {
978 w += font_metrics::width(c, font);
980 // Fall-back to the normal case
981 w += singleWidth(pit, i, c);
982 // And flush font cache
983 endPosOfFontSpan = 0;
986 // Fall-back to the normal case
987 w += singleWidth(pit, i, c);
988 // And flush font cache
989 endPosOfFontSpan = 0;
995 if (body_pos > 0 && body_pos > last) {
996 w += font_metrics::width(layout->labelsep, getLabelFont(pit));
997 if (last >= 0 && pit->isLineSeparator(last))
998 w -= singleWidth(pit, last);
999 int const left_margin = labelEnd(*row);
1000 if (w < left_margin)
1004 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
1006 // If this case happens, it means that our calculation
1007 // of the widths of the chars when we do rowBreakPoint()
1008 // went wrong for some reason. Typically in list bodies.
1009 // Things just about hobble on anyway, though you'll end
1010 // up with a "fill_separator" less than zero, which corresponds
1011 // to inter-word spacing being too small. Hopefully this problem
1012 // will die when the label hacks die.
1013 if (lyxerr.debugging() && fill < 0) {
1014 lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
1015 << " w " << w << " paper_width " << paper_width
1016 << " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
1022 // returns the minimum space a manual label needs on the screen in pixel
1023 int LyXText::labelFill(Row const & row) const
1025 ParagraphList::iterator pit = row.par();
1027 pos_type last = pit->beginningOfBody();
1031 // -1 because a label ends either with a space that is in the label,
1032 // or with the beginning of a footnote that is outside the label.
1035 // a separator at this end does not count
1036 if (pit->isLineSeparator(last))
1040 pos_type i = row.pos();
1042 w += singleWidth(pit, i);
1047 string const & labwidstr = pit->params().labelWidthString();
1048 if (!labwidstr.empty()) {
1049 LyXFont const labfont = getLabelFont(pit);
1050 int const labwidth = font_metrics::width(labwidstr, labfont);
1051 fill = max(labwidth - w, 0);
1058 LColor::color LyXText::backgroundColor() const
1061 return inset_owner->backgroundColor();
1063 return LColor::background;
1067 void LyXText::setHeightOfRow(RowList::iterator rit)
1069 Assert(rit != rows().end());
1071 // get the maximum ascent and the maximum descent
1072 double layoutasc = 0;
1073 double layoutdesc = 0;
1076 // ok, let us initialize the maxasc and maxdesc value.
1077 // Only the fontsize count. The other properties
1078 // are taken from the layoutfont. Nicer on the screen :)
1079 ParagraphList::iterator pit = rit->par();
1081 LyXLayout_ptr const & layout = pit->layout();
1083 // as max get the first character of this row then it can increase but not
1084 // decrease the height. Just some point to start with so we don't have to
1085 // do the assignment below too often.
1086 LyXFont font = getFont(pit, rit->pos());
1087 LyXFont::FONT_SIZE const tmpsize = font.size();
1088 font = getLayoutFont(pit);
1089 LyXFont::FONT_SIZE const size = font.size();
1090 font.setSize(tmpsize);
1092 LyXFont labelfont = getLabelFont(pit);
1094 double spacing_val = 1.0;
1095 if (!pit->params().spacing().isDefault())
1096 spacing_val = pit->params().spacing().getValue();
1098 spacing_val = bv()->buffer()->params.spacing.getValue();
1099 //lyxerr << "spacing_val = " << spacing_val << endl;
1101 int maxasc = int(font_metrics::maxAscent(font) *
1102 layout->spacing.getValue() * spacing_val);
1103 int maxdesc = int(font_metrics::maxDescent(font) *
1104 layout->spacing.getValue() * spacing_val);
1106 pos_type const pos_end = lastPos(*this, rit);
1110 if (!pit->empty()) {
1111 // We re-use the font resolution for the entire font span when possible
1112 LyXFont font = getFont(pit, rit->pos());
1113 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(rit->pos());
1116 Paragraph const & par = *pit;
1118 // Check if any insets are larger
1119 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1120 // Manual inlined optimised version of common case of
1121 // "maxwidth += singleWidth(pit, pos);"
1122 char const c = par.getChar(pos);
1124 if (IsPrintable(c)) {
1125 if (pos > endPosOfFontSpan) {
1126 // We need to get the next font
1127 font = getFont(pit, pos);
1128 endPosOfFontSpan = par.getEndPosOfFontSpan(pos);
1130 if (! font.language()->RightToLeft()) {
1131 maxwidth += font_metrics::width(c, font);
1133 // Fall-back to normal case
1134 maxwidth += singleWidth(pit, pos, c);
1135 // And flush font cache
1136 endPosOfFontSpan = 0;
1139 // Special handling of insets - are any larger?
1140 if (par.isInset(pos)) {
1141 LyXFont const tmpfont = getFont(pit, pos);
1142 InsetOld const * tmpinset = par.getInset(pos);
1144 #if 1 // this is needed for deep update on initialitation
1145 #warning inset->update FIXME
1146 //tmpinset->update(bv());
1148 MetricsInfo mi(bv(), tmpfont, workWidth());
1149 tmpinset->metrics(mi, dim);
1150 maxwidth += dim.wid;
1151 maxasc = max(maxasc, dim.asc);
1152 maxdesc = max(maxdesc, dim.des);
1154 maxwidth += tmpinset->width();
1155 maxasc = max(maxasc, tmpinset->ascent());
1156 maxdesc = max(maxdesc, tmpinset->descent());
1160 // Fall-back to normal case
1161 maxwidth += singleWidth(pit, pos, c);
1162 // And flush font cache
1163 endPosOfFontSpan = 0;
1169 // Check if any custom fonts are larger (Asger)
1170 // This is not completely correct, but we can live with the small,
1171 // cosmetic error for now.
1172 LyXFont::FONT_SIZE maxsize =
1173 pit->highestFontInRange(rit->pos(), pos_end, size);
1174 if (maxsize > font.size()) {
1175 font.setSize(maxsize);
1176 maxasc = max(maxasc, font_metrics::maxAscent(font));
1177 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
1180 // This is nicer with box insets:
1184 rit->ascent_of_text(maxasc);
1186 // is it a top line?
1189 // some parksips VERY EASY IMPLEMENTATION
1190 if (bv()->buffer()->params.paragraph_separation ==
1191 BufferParams::PARSEP_SKIP)
1193 if (layout->isParagraph()
1194 && pit->getDepth() == 0
1195 && pit != ownerParagraphs().begin())
1197 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1198 } else if (pit != ownerParagraphs().begin() &&
1199 boost::prior(pit)->layout()->isParagraph() &&
1200 boost::prior(pit)->getDepth() == 0)
1202 // is it right to use defskip here too? (AS)
1203 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1208 if (pit == ownerParagraphs().begin() && !isInInset())
1209 maxasc += PAPER_MARGIN;
1211 // add the vertical spaces, that the user added
1212 maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
1214 // do not forget the DTP-lines!
1215 // there height depends on the font of the nearest character
1216 if (pit->params().lineTop())
1218 maxasc += 2 * font_metrics::ascent('x', getFont(pit, 0));
1219 // and now the pagebreaks
1220 if (pit->params().pagebreakTop())
1221 maxasc += 3 * defaultRowHeight();
1223 if (pit->params().startOfAppendix())
1224 maxasc += 3 * defaultRowHeight();
1226 // This is special code for the chapter, since the label of this
1227 // layout is printed in an extra row
1228 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1229 && bv()->buffer()->params.secnumdepth >= 0)
1231 float spacing_val = 1.0;
1232 if (!pit->params().spacing().isDefault()) {
1233 spacing_val = pit->params().spacing().getValue();
1235 spacing_val = bv()->buffer()->params.spacing.getValue();
1238 labeladdon = int(font_metrics::maxDescent(labelfont) *
1239 layout->spacing.getValue() *
1241 + int(font_metrics::maxAscent(labelfont) *
1242 layout->spacing.getValue() *
1246 // special code for the top label
1247 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1248 || layout->labeltype == LABEL_BIBLIO
1249 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1250 && isFirstInSequence(pit, ownerParagraphs())
1251 && !pit->getLabelstring().empty())
1253 float spacing_val = 1.0;
1254 if (!pit->params().spacing().isDefault()) {
1255 spacing_val = pit->params().spacing().getValue();
1257 spacing_val = bv()->buffer()->params.spacing.getValue();
1261 (font_metrics::maxAscent(labelfont) *
1262 layout->spacing.getValue() *
1264 +(font_metrics::maxDescent(labelfont) *
1265 layout->spacing.getValue() *
1267 + layout->topsep * defaultRowHeight()
1268 + layout->labelbottomsep * defaultRowHeight());
1271 // And now the layout spaces, for example before and after
1272 // a section, or between the items of a itemize or enumerate
1275 if (!pit->params().pagebreakTop()) {
1276 ParagraphList::iterator prev =
1277 depthHook(pit, ownerParagraphs(),
1279 if (prev != pit && prev->layout() == layout &&
1280 prev->getDepth() == pit->getDepth() &&
1281 prev->getLabelWidthString() == pit->getLabelWidthString())
1283 layoutasc = (layout->itemsep * defaultRowHeight());
1284 } else if (rit != rows().begin()) {
1285 tmptop = layout->topsep;
1287 if (boost::prior(pit)->getDepth() >= pit->getDepth())
1288 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1291 layoutasc = (tmptop * defaultRowHeight());
1292 } else if (pit->params().lineTop()) {
1293 tmptop = layout->topsep;
1296 layoutasc = (tmptop * defaultRowHeight());
1299 prev = outerHook(pit, ownerParagraphs());
1300 if (prev != ownerParagraphs().end()) {
1301 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1302 } else if (pit != ownerParagraphs().begin()) {
1303 ParagraphList::iterator prior_pit = boost::prior(pit);
1304 if (prior_pit->getDepth() != 0 ||
1305 prior_pit->layout() == layout) {
1306 maxasc += int(layout->parsep * defaultRowHeight());
1312 // is it a bottom line?
1313 RowList::iterator next_rit = boost::next(rit);
1314 if (next_rit == rows().end() || next_rit->par() != pit) {
1315 // the bottom margin
1316 ParagraphList::iterator nextpit = boost::next(pit);
1317 if (nextpit == ownerParagraphs().end() &&
1319 maxdesc += PAPER_MARGIN;
1321 // add the vertical spaces, that the user added
1322 maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
1324 // do not forget the DTP-lines!
1325 // there height depends on the font of the nearest character
1326 if (pit->params().lineBottom())
1327 maxdesc += 2 * font_metrics::ascent('x',
1328 getFont(pit, max(pos_type(0), pit->size() - 1)));
1330 // and now the pagebreaks
1331 if (pit->params().pagebreakBottom())
1332 maxdesc += 3 * defaultRowHeight();
1334 // and now the layout spaces, for example before and after
1335 // a section, or between the items of a itemize or enumerate
1337 if (!pit->params().pagebreakBottom()
1338 && nextpit != ownerParagraphs().end()) {
1339 ParagraphList::iterator comparepit = pit;
1343 if (comparepit->getDepth() > nextpit->getDepth()) {
1344 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1345 comparepit = depthHook(comparepit, ownerParagraphs(), nextpit->getDepth());
1346 if (comparepit->layout()!= nextpit->layout()
1347 || nextpit->getLabelWidthString() !=
1348 comparepit->getLabelWidthString())
1350 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1352 if (unusual > usual)
1353 layoutdesc = unusual;
1356 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1358 if (comparepit->layout() != nextpit->layout()
1359 || nextpit->getLabelWidthString() !=
1360 comparepit->getLabelWidthString())
1361 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1366 // incalculate the layout spaces
1367 maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
1368 maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
1370 // calculate the new height of the text
1371 height -= rit->height();
1373 rit->height(maxasc + maxdesc + labeladdon);
1374 rit->baseline(maxasc + labeladdon);
1376 height += rit->height();
1378 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1381 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1383 rit->width(maxwidth);
1385 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1387 rit->width(int(maxwidth + x));
1389 width = max(0, workWidth());
1390 RowList::iterator it = rows().begin();
1391 RowList::iterator end = rows().end();
1392 for (; it != end; ++it)
1393 if (it->width() > width)
1394 width = it->width();
1399 // Appends the implicit specified paragraph before the specified row,
1400 // start at the implicit given position
1401 void LyXText::appendParagraph(RowList::iterator rowit)
1403 Assert(rowit != rowlist_.end());
1405 pos_type const last = rowit->par()->size();
1409 pos_type z = rowBreakPoint(*rowit);
1411 RowList::iterator tmprow = rowit;
1415 Row newrow(rowit->par(), z);
1416 rowit = rowlist_.insert(boost::next(rowit), newrow);
1421 // Set the dimensions of the row
1422 // fixed fill setting now by calling inset->update() in
1423 // SingleWidth when needed!
1424 tmprow->fill(fill(tmprow, workWidth()));
1425 setHeightOfRow(tmprow);
1431 void LyXText::breakAgain(RowList::iterator rit)
1433 Assert(rit != rows().end());
1435 bool not_ready = true;
1438 pos_type z = rowBreakPoint(*rit);
1439 RowList::iterator tmprit = rit;
1440 RowList::iterator end = rows().end();
1442 if (z < rit->par()->size()) {
1443 RowList::iterator next_rit = boost::next(rit);
1445 if (next_rit == end ||
1447 next_rit->par() != rit->par())) {
1450 Row newrow(rit->par(), z);
1451 rit = rowlist_.insert(next_rit, newrow);
1455 if (rit->pos() == z)
1456 not_ready = false; // the rest will not change
1462 // if there are some rows too much, delete them
1463 // only if you broke the whole paragraph!
1464 RowList::iterator tmprit2 = rit;
1465 while (boost::next(tmprit2) != end
1466 && boost::next(tmprit2)->par() == rit->par()) {
1469 while (tmprit2 != rit) {
1471 removeRow(boost::next(tmprit2));
1476 // set the dimensions of the row
1477 tmprit->fill(fill(tmprit, workWidth()));
1478 setHeightOfRow(tmprit);
1479 } while (not_ready);
1483 // this is just a little changed version of break again
1484 void LyXText::breakAgainOneRow(RowList::iterator rit)
1486 Assert(rit != rows().end());
1488 pos_type z = rowBreakPoint(*rit);
1489 RowList::iterator tmprit = rit;
1490 RowList::iterator end = rows().end();
1492 if (z < rit->par()->size()) {
1493 RowList::iterator next_rit = boost::next(rit);
1495 if (next_rit == end ||
1497 next_rit->par() != rit->par())) {
1500 Row newrow(rit->par(), z);
1501 rit = rowlist_.insert(next_rit, newrow);
1505 if (rit->pos() != z)
1509 // if there are some rows too much, delete them
1510 // only if you broke the whole paragraph!
1511 RowList::iterator tmprit2 = rit;
1512 while (boost::next(tmprit2) != end
1513 && boost::next(tmprit2)->par() == rit->par()) {
1516 while (tmprit2 != rit) {
1518 removeRow(boost::next(tmprit2));
1522 // set the dimensions of the row
1523 tmprit->fill(fill(tmprit, workWidth()));
1524 setHeightOfRow(tmprit);
1528 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1530 // allow only if at start or end, or all previous is new text
1531 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1532 && cursor.par()->isChangeEdited(0, cursor.pos()))
1535 LyXTextClass const & tclass =
1536 bv()->buffer()->params.getLyXTextClass();
1537 LyXLayout_ptr const & layout = cursor.par()->layout();
1539 // this is only allowed, if the current paragraph is not empty or caption
1540 // and if it has not the keepempty flag active
1541 if (cursor.par()->empty() && !cursor.par()->allowEmpty()
1542 && layout->labeltype != LABEL_SENSITIVE)
1545 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1547 // Always break behind a space
1549 // It is better to erase the space (Dekel)
1550 if (cursor.pos() < cursor.par()->size()
1551 && cursor.par()->isLineSeparator(cursor.pos()))
1552 cursor.par()->erase(cursor.pos());
1553 // cursor.pos(cursor.pos() + 1);
1555 // break the paragraph
1559 keep_layout = layout->isEnvironment();
1561 // we need to set this before we insert the paragraph. IMO the
1562 // breakParagraph call should return a bool if it inserts the
1563 // paragraph before or behind and we should react on that one
1564 // but we can fix this in 1.3.0 (Jug 20020509)
1565 bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty());
1566 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(),
1567 cursor.pos(), keep_layout);
1569 // well this is the caption hack since one caption is really enough
1570 if (layout->labeltype == LABEL_SENSITIVE) {
1572 // set to standard-layout
1573 cursor.par()->applyLayout(tclass.defaultLayout());
1575 // set to standard-layout
1576 boost::next(cursor.par())->applyLayout(tclass.defaultLayout());
1579 // if the cursor is at the beginning of a row without prior newline,
1581 // This touches only the screen-update. Otherwise we would may have
1582 // an empty row on the screen
1583 if (cursor.pos() && cursorRow()->pos() == cursor.pos()
1584 && !cursorRow()->par()->isNewline(cursor.pos() - 1))
1591 removeParagraph(cursorRow());
1593 // set the dimensions of the cursor row
1594 cursorRow()->fill(fill(cursorRow(), workWidth()));
1596 setHeightOfRow(cursorRow());
1598 #warning Trouble Point! (Lgb)
1599 // When ::breakParagraph is called from within an inset we must
1600 // ensure that the correct ParagraphList is used. Today that is not
1601 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1602 ParagraphList::iterator next_par = boost::next(cursor.par());
1604 while (!next_par->empty() && next_par->isNewline(0))
1607 insertParagraph(next_par, boost::next(cursorRow()));
1610 // This check is necessary. Otherwise the new empty paragraph will
1611 // be deleted automatically. And it is more friendly for the user!
1612 if (cursor.pos() || isempty)
1613 setCursor(next_par, 0);
1615 setCursor(cursor.par(), 0);
1617 if (boost::next(cursorRow()) != rows().end())
1618 breakAgain(boost::next(cursorRow()));
1622 // Just a macro to make some thing easier.
1623 void LyXText::redoParagraph()
1626 redoParagraphs(cursor, boost::next(cursor.par()));
1627 setCursorIntern(cursor.par(), cursor.pos());
1631 // insert a character, moves all the following breaks in the
1632 // same Paragraph one to the right and make a rebreak
1633 void LyXText::insertChar(char c)
1635 recordUndo(bv(), Undo::INSERT, cursor.par());
1637 // When the free-spacing option is set for the current layout,
1638 // disable the double-space checking
1640 bool const freeSpacing = cursorRow()->par()->layout()->free_spacing ||
1641 cursorRow()->par()->isFreeSpacing();
1643 if (lyxrc.auto_number) {
1644 static string const number_operators = "+-/*";
1645 static string const number_unary_operators = "+-";
1646 static string const number_seperators = ".,:";
1648 if (current_font.number() == LyXFont::ON) {
1649 if (!IsDigit(c) && !contains(number_operators, c) &&
1650 !(contains(number_seperators, c) &&
1651 cursor.pos() >= 1 &&
1652 cursor.pos() < cursor.par()->size() &&
1653 getFont(cursor.par(), cursor.pos()).number() == LyXFont::ON &&
1654 getFont(cursor.par(), cursor.pos() - 1).number() == LyXFont::ON)
1656 number(bv()); // Set current_font.number to OFF
1657 } else if (IsDigit(c) &&
1658 real_current_font.isVisibleRightToLeft()) {
1659 number(bv()); // Set current_font.number to ON
1661 if (cursor.pos() > 0) {
1662 char const c = cursor.par()->getChar(cursor.pos() - 1);
1663 if (contains(number_unary_operators, c) &&
1664 (cursor.pos() == 1 ||
1665 cursor.par()->isSeparator(cursor.pos() - 2) ||
1666 cursor.par()->isNewline(cursor.pos() - 2))
1672 } else if (contains(number_seperators, c) &&
1673 cursor.pos() >= 2 &&
1676 cursor.pos() - 2).number() == LyXFont::ON) {
1687 // First check, if there will be two blanks together or a blank at
1688 // the beginning of a paragraph.
1689 // I decided to handle blanks like normal characters, the main
1690 // difference are the special checks when calculating the row.fill
1691 // (blank does not count at the end of a row) and the check here
1693 // The bug is triggered when we type in a description environment:
1694 // The current_font is not changed when we go from label to main text
1695 // and it should (along with realtmpfont) when we type the space.
1696 // CHECK There is a bug here! (Asger)
1698 LyXFont realtmpfont = real_current_font;
1699 LyXFont rawtmpfont = current_font;
1700 // store the current font. This is because of the use of cursor
1701 // movements. The moving cursor would refresh the current font
1703 // Get the font that is used to calculate the baselineskip
1704 pos_type const lastpos = cursor.par()->size();
1705 LyXFont rawparfont =
1706 cursor.par()->getFontSettings(bv()->buffer()->params,
1709 bool jumped_over_space = false;
1711 if (!freeSpacing && IsLineSeparatorChar(c)) {
1712 if ((cursor.pos() > 0
1713 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1714 || (cursor.pos() > 0
1715 && cursor.par()->isNewline(cursor.pos() - 1))
1716 || (cursor.pos() == 0)) {
1717 static bool sent_space_message = false;
1718 if (!sent_space_message) {
1719 if (cursor.pos() == 0)
1720 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1722 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1723 sent_space_message = true;
1730 // the display inset stuff
1731 if (cursorRow()->pos() < cursorRow()->par()->size()
1732 && cursorRow()->par()->isInset(cursorRow()->pos())) {
1733 InsetOld * inset = cursorRow()->par()->getInset(cursorRow()->pos());
1734 if (inset && (inset->display() || inset->needFullRow())) {
1735 // force a new break
1736 cursorRow()->fill(-1); // to force a new break
1740 // get the cursor row fist
1741 RowList::iterator row = cursorRow();
1742 if (c != Paragraph::META_INSET) {
1743 // Here case LyXText::InsertInset already inserted the character
1744 cursor.par()->insertChar(cursor.pos(), c);
1746 setCharFont(cursor.par(), cursor.pos(), rawtmpfont);
1748 if (!jumped_over_space) {
1749 // refresh the positions
1750 RowList::iterator tmprow = row;
1751 while (boost::next(tmprow) != rows().end() &&
1752 boost::next(tmprow)->par() == row->par()) {
1754 tmprow->pos(tmprow->pos() + 1);
1758 // Is there a break one row above
1759 if (row != rows().begin() &&
1760 boost::prior(row)->par() == row->par()
1761 && (cursor.par()->isLineSeparator(cursor.pos())
1762 || cursor.par()->isNewline(cursor.pos())
1763 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1764 cursor.par()->isInset(cursor.pos() + 1))
1765 || cursorRow()->fill() == -1))
1767 pos_type z = rowBreakPoint(*boost::prior(row));
1769 if (z >= row->pos()) {
1772 // set the dimensions of the row above
1773 boost::prior(row)->fill(fill(
1777 setHeightOfRow(boost::prior(row));
1781 breakAgainOneRow(row);
1783 current_font = rawtmpfont;
1784 real_current_font = realtmpfont;
1785 setCursor(cursor.par(), cursor.pos() + 1,
1786 false, cursor.boundary());
1788 // cursor MUST be in row now.
1789 // check, wether the last characters font has changed.
1790 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1791 && rawparfont != rawtmpfont)
1792 redoHeightOfParagraph();
1799 // recalculate the fill of the row
1800 if (row->fill() >= 0) {
1801 // needed because a newline will set fill to -1. Otherwise
1802 // we would not get a rebreak!
1803 row->fill(fill(row, workWidth()));
1806 if (c == Paragraph::META_INSET || row->fill() < 0) {
1808 breakAgainOneRow(row);
1810 RowList::iterator next_row = boost::next(row);
1812 // will the cursor be in another row now?
1813 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1814 next_row != rows().end()) {
1815 if (next_row != rows().end() &&
1816 next_row->par() == row->par()) {
1817 // this should always be true
1821 breakAgainOneRow(row);
1823 current_font = rawtmpfont;
1824 real_current_font = realtmpfont;
1826 setCursor(cursor.par(), cursor.pos() + 1, false,
1828 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
1829 != cursor.boundary())
1830 setCursor(cursor.par(), cursor.pos(), false,
1831 !cursor.boundary());
1833 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1834 setHeightOfRow(row);
1837 current_font = rawtmpfont;
1838 real_current_font = realtmpfont;
1839 setCursor(cursor.par(), cursor.pos() + 1, false,
1843 // check, wether the last characters font has changed.
1844 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1845 && rawparfont != rawtmpfont) {
1846 redoHeightOfParagraph();
1853 void LyXText::charInserted()
1855 // Here we could call FinishUndo for every 20 characters inserted.
1856 // This is from my experience how emacs does it. (Lgb)
1857 static unsigned int counter;
1867 void LyXText::prepareToPrint(RowList::iterator rit, double & x,
1868 double & fill_separator,
1869 double & fill_hfill,
1870 double & fill_label_hfill,
1873 double w = rit->fill();
1875 fill_label_hfill = 0;
1877 fill_label_hfill = 0;
1879 ParagraphList::iterator pit = rit->par();
1882 pit->isRightToLeftPar(bv()->buffer()->params);
1884 x = workWidth() > 0 ? rightMargin(*bv()->buffer(), *rit) : 0;
1886 x = workWidth() > 0 ? leftMargin(*rit) : 0;
1888 // is there a manual margin with a manual label
1889 LyXLayout_ptr const & layout = pit->layout();
1891 if (layout->margintype == MARGIN_MANUAL
1892 && layout->labeltype == LABEL_MANUAL) {
1893 /// We might have real hfills in the label part
1894 int nlh = numberOfLabelHfills(*this, rit);
1896 // A manual label par (e.g. List) has an auto-hfill
1897 // between the label text and the body of the
1899 // But we don't want to do this auto hfill if the par
1904 if (nlh && !pit->getLabelWidthString().empty()) {
1905 fill_label_hfill = labelFill(*rit) / double(nlh);
1909 // are there any hfills in the row?
1910 int const nh = numberOfHfills(*this, rit);
1914 fill_hfill = w / nh;
1915 // we don't have to look at the alignment if it is ALIGN_LEFT and
1916 // if the row is already larger then the permitted width as then
1917 // we force the LEFT_ALIGN'edness!
1918 } else if (int(rit->width()) < workWidth()) {
1919 // is it block, flushleft or flushright?
1920 // set x how you need it
1922 if (pit->params().align() == LYX_ALIGN_LAYOUT) {
1923 align = layout->align;
1925 align = pit->params().align();
1928 // center displayed insets
1929 InsetOld * inset = 0;
1930 if (rit->pos() < pit->size()
1931 && pit->isInset(rit->pos())
1932 && (inset = pit->getInset(rit->pos()))
1933 && (inset->display())) // || (inset->scroll() < 0)))
1934 align = (inset->lyxCode() == InsetOld::MATHMACRO_CODE)
1935 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1936 // ERT insets should always be LEFT ALIGNED on screen
1937 inset = pit->inInset();
1938 if (inset && inset->owner() &&
1939 inset->owner()->lyxCode() == InsetOld::ERT_CODE)
1941 align = LYX_ALIGN_LEFT;
1945 case LYX_ALIGN_BLOCK:
1947 int const ns = numberOfSeparators(*this, rit);
1948 RowList::iterator next_row = boost::next(rit);
1949 ParagraphList::iterator next_pit = next_row->par();
1951 if (ns && next_row != rowlist_.end() &&
1953 !(next_pit->isNewline(next_row->pos() - 1))
1954 && !(next_pit->isInset(next_row->pos()) &&
1955 next_pit->getInset(next_row->pos()) &&
1956 next_pit->getInset(next_row->pos())->display())
1958 fill_separator = w / ns;
1959 } else if (is_rtl) {
1964 case LYX_ALIGN_RIGHT:
1967 case LYX_ALIGN_CENTER:
1975 computeBidiTables(bv()->buffer(), rit);
1977 pos_type body_pos = pit->beginningOfBody();
1978 pos_type last = lastPos(*this, rit);
1981 (body_pos - 1 > last ||
1982 !pit->isLineSeparator(body_pos - 1))) {
1983 x += font_metrics::width(layout->labelsep, getLabelFont(pit));
1984 if (body_pos - 1 <= last)
1985 x += fill_label_hfill;
1991 // important for the screen
1994 // the cursor set functions have a special mechanism. When they
1995 // realize, that you left an empty paragraph, they will delete it.
1996 // They also delete the corresponding row
1998 void LyXText::cursorRightOneWord()
2000 ::cursorRightOneWord(cursor, ownerParagraphs());
2001 setCursor(cursor.par(), cursor.pos());
2005 // Skip initial whitespace at end of word and move cursor to *start*
2006 // of prior word, not to end of next prior word.
2007 void LyXText::cursorLeftOneWord()
2009 LyXCursor tmpcursor = cursor;
2010 ::cursorLeftOneWord(tmpcursor, ownerParagraphs());
2011 setCursor(tmpcursor.par(), tmpcursor.pos());
2015 void LyXText::selectWord(word_location loc)
2017 LyXCursor from = cursor;
2019 ::getWord(from, to, loc, ownerParagraphs());
2021 setCursor(from.par(), from.pos());
2024 selection.cursor = cursor;
2025 setCursor(to.par(), to.pos());
2030 // Select the word currently under the cursor when no
2031 // selection is currently set
2032 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2034 if (!selection.set()) {
2036 return selection.set();
2042 void LyXText::acceptChange()
2044 if (!selection.set() && cursor.par()->size())
2047 if (selection.start.par() == selection.end.par()) {
2048 LyXCursor & startc = selection.start;
2049 LyXCursor & endc = selection.end;
2050 recordUndo(bv(), Undo::INSERT, startc.par());
2051 startc.par()->acceptChange(startc.pos(), endc.pos());
2054 redoParagraphs(startc, boost::next(startc.par()));
2055 setCursorIntern(startc.par(), 0);
2057 #warning handle multi par selection
2061 void LyXText::rejectChange()
2063 if (!selection.set() && cursor.par()->size())
2066 if (selection.start.par() == selection.end.par()) {
2067 LyXCursor & startc = selection.start;
2068 LyXCursor & endc = selection.end;
2069 recordUndo(bv(), Undo::INSERT, startc.par());
2070 startc.par()->rejectChange(startc.pos(), endc.pos());
2073 redoParagraphs(startc, boost::next(startc.par()));
2074 setCursorIntern(startc.par(), 0);
2076 #warning handle multi par selection
2080 // This function is only used by the spellchecker for NextWord().
2081 // It doesn't handle LYX_ACCENTs and probably never will.
2083 LyXText::selectNextWordToSpellcheck(float & value)
2085 if (the_locking_inset) {
2086 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2087 if (!word.word().empty()) {
2088 value += float(cursor.y());
2089 value /= float(height);
2092 // we have to go on checking so move cursor to the next char
2093 if (cursor.pos() == cursor.par()->size()) {
2094 if (boost::next(cursor.par()) == ownerParagraphs().end())
2096 cursor.par(boost::next(cursor.par()));
2099 cursor.pos(cursor.pos() + 1);
2101 ParagraphList::iterator tmppit = cursor.par();
2103 // If this is not the very first word, skip rest of
2104 // current word because we are probably in the middle
2105 // of a word if there is text here.
2106 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
2107 while (cursor.pos() < cursor.par()->size()
2108 && cursor.par()->isLetter(cursor.pos()))
2109 cursor.pos(cursor.pos() + 1);
2112 // Now, skip until we have real text (will jump paragraphs)
2114 ParagraphList::iterator cpit = cursor.par();
2115 pos_type const cpos(cursor.pos());
2117 if (cpos == cpit->size()) {
2118 if (boost::next(cpit) != ownerParagraphs().end()) {
2119 cursor.par(boost::next(cpit));
2126 bool const is_good_inset = cpit->isInset(cpos)
2127 && cpit->getInset(cpos)->allowSpellcheck();
2129 if (!isDeletedText(*cpit, cpos)
2130 && (is_good_inset || cpit->isLetter(cpos)))
2133 cursor.pos(cpos + 1);
2136 // now check if we hit an inset so it has to be a inset containing text!
2137 if (cursor.pos() < cursor.par()->size() &&
2138 cursor.par()->isInset(cursor.pos())) {
2140 FuncRequest cmd(bv(), LFUN_INSET_EDIT, "left");
2141 cursor.par()->getInset(cursor.pos())->localDispatch(cmd);
2142 // now call us again to do the above trick
2143 // but obviously we have to start from down below ;)
2144 return bv()->text->selectNextWordToSpellcheck(value);
2147 // Update the value if we changed paragraphs
2148 if (cursor.par() != tmppit) {
2149 setCursor(cursor.par(), cursor.pos());
2150 value = float(cursor.y())/float(height);
2153 // Start the selection from here
2154 selection.cursor = cursor;
2156 string lang_code = getFont(cursor.par(), cursor.pos()).language()->code();
2157 // and find the end of the word (insets like optional hyphens
2158 // and ligature break are part of a word)
2159 while (cursor.pos() < cursor.par()->size()
2160 && cursor.par()->isLetter(cursor.pos())
2161 && !isDeletedText(*cursor.par(), cursor.pos()))
2162 cursor.pos(cursor.pos() + 1);
2164 // Finally, we copy the word to a string and return it
2166 if (selection.cursor.pos() < cursor.pos()) {
2168 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2169 if (!cursor.par()->isInset(i))
2170 str += cursor.par()->getChar(i);
2173 return WordLangTuple(str, lang_code);
2177 // This one is also only for the spellchecker
2178 void LyXText::selectSelectedWord()
2180 if (the_locking_inset) {
2181 the_locking_inset->selectSelectedWord(bv());
2184 // move cursor to the beginning
2185 setCursor(selection.cursor.par(), selection.cursor.pos());
2187 // set the sel cursor
2188 selection.cursor = cursor;
2190 // now find the end of the word
2191 while (cursor.pos() < cursor.par()->size()
2192 && (cursor.par()->isLetter(cursor.pos())))
2193 cursor.pos(cursor.pos() + 1);
2195 setCursor(cursor.par(), cursor.pos());
2197 // finally set the selection
2202 // Delete from cursor up to the end of the current or next word.
2203 void LyXText::deleteWordForward()
2205 if (cursor.par()->empty())
2208 LyXCursor tmpcursor = cursor;
2209 selection.set(true); // to avoid deletion
2210 cursorRightOneWord();
2211 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2212 selection.cursor = cursor;
2216 // Great, CutSelection() gets rid of multiple spaces.
2217 cutSelection(true, false);
2222 // Delete from cursor to start of current or prior word.
2223 void LyXText::deleteWordBackward()
2225 if (cursor.par()->empty())
2228 LyXCursor tmpcursor = cursor;
2229 selection.set(true); // to avoid deletion
2230 cursorLeftOneWord();
2231 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2232 selection.cursor = cursor;
2235 cutSelection(true, false);
2240 // Kill to end of line.
2241 void LyXText::deleteLineForward()
2243 if (cursor.par()->empty())
2244 // Paragraph is empty, so we just go to the right
2247 LyXCursor tmpcursor = cursor;
2248 // We can't store the row over a regular setCursor
2249 // so we set it to 0 and reset it afterwards.
2250 selection.set(true); // to avoid deletion
2252 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2253 selection.cursor = cursor;
2256 // What is this test for ??? (JMarc)
2257 if (!selection.set()) {
2258 deleteWordForward();
2260 cutSelection(true, false);
2266 void LyXText::changeCase(LyXText::TextCase action)
2271 if (selection.set()) {
2272 from = selection.start;
2276 ::getWord(from, to, lyx::PARTIAL_WORD, ownerParagraphs());
2277 setCursor(to.par(), to.pos() + 1);
2280 recordUndo(bv(), Undo::ATOMIC, from.par(), to.par());
2282 pos_type pos = from.pos();
2283 ParagraphList::iterator pit = from.par();
2285 while (pit != ownerParagraphs().end() &&
2286 (pos != to.pos() || pit != to.par())) {
2287 if (pos == pit->size()) {
2292 unsigned char c = pit->getChar(pos);
2293 if (!IsInsetChar(c)) {
2295 case text_lowercase:
2298 case text_capitalization:
2300 action = text_lowercase;
2302 case text_uppercase:
2308 pit->setChar(pos, c);
2309 checkParagraph(pit, pos);
2314 if (getRow(to) != getRow(from))
2319 void LyXText::Delete()
2321 // this is a very easy implementation
2323 LyXCursor old_cursor = cursor;
2324 int const old_cur_par_id = old_cursor.par()->id();
2325 int const old_cur_par_prev_id =
2326 (old_cursor.par() != ownerParagraphs().begin() ?
2327 boost::prior(old_cursor.par())->id() : -1);
2329 // just move to the right
2332 // CHECK Look at the comment here.
2333 // This check is not very good...
2334 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2335 // and that can very well delete the par or par->previous in
2336 // old_cursor. Will a solution where we compare paragraph id's
2338 if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
2339 == old_cur_par_prev_id
2340 && cursor.par()->id() != old_cur_par_id) {
2341 // delete-empty-paragraph-mechanism has done it
2345 // if you had success make a backspace
2346 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2347 LyXCursor tmpcursor = cursor;
2348 // to make sure undo gets the right cursor position
2349 cursor = old_cursor;
2350 recordUndo(bv(), Undo::DELETE, cursor.par());
2357 void LyXText::backspace()
2359 // Get the font that is used to calculate the baselineskip
2360 pos_type lastpos = cursor.par()->size();
2361 LyXFont rawparfont =
2362 cursor.par()->getFontSettings(bv()->buffer()->params,
2365 if (cursor.pos() == 0) {
2366 // The cursor is at the beginning of a paragraph,
2367 // so the the backspace will collapse two paragraphs into one.
2369 // but it's not allowed unless it's new
2370 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2373 // we may paste some paragraphs
2375 // is it an empty paragraph?
2378 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2379 // This is an empty paragraph and we delete it just by moving the cursor one step
2380 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2381 // of the paragraph.
2383 if (cursor.par() != ownerParagraphs().begin()) {
2384 ParagraphList::iterator tmppit = boost::prior(cursor.par());
2385 if (cursor.par()->layout() == tmppit->layout()
2386 && cursor.par()->getAlign() == tmppit->getAlign()) {
2387 // Inherit bottom DTD from the paragraph below.
2388 // (the one we are deleting)
2389 tmppit->params().lineBottom(cursor.par()->params().lineBottom());
2390 tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
2391 tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2396 // the layout things can change the height of a row !
2397 int const tmpheight = cursorRow()->height();
2398 setHeightOfRow(cursorRow());
2399 if (cursorRow()->height() != tmpheight)
2405 if (cursor.par() != ownerParagraphs().begin()) {
2406 recordUndo(bv(), Undo::DELETE,
2407 boost::prior(cursor.par()),
2411 ParagraphList::iterator tmppit = cursor.par();
2412 RowList::iterator tmprow = cursorRow();
2414 // We used to do cursorLeftIntern() here, but it is
2415 // not a good idea since it triggers the auto-delete
2416 // mechanism. So we do a cursorLeftIntern()-lite,
2417 // without the dreaded mechanism. (JMarc)
2418 if (cursor.par() != ownerParagraphs().begin()) {
2419 // steps into the above paragraph.
2420 setCursorIntern(boost::prior(cursor.par()),
2421 boost::prior(cursor.par())->size(),
2425 // Pasting is not allowed, if the paragraphs have different
2426 // layout. I think it is a real bug of all other
2427 // word processors to allow it. It confuses the user.
2428 // Even so with a footnote paragraph and a non-footnote
2429 // paragraph. I will not allow pasting in this case,
2430 // because the user would be confused if the footnote behaves
2431 // different wether it is open or closed.
2433 // Correction: Pasting is always allowed with standard-layout
2434 LyXTextClass const & tclass =
2435 bv()->buffer()->params.getLyXTextClass();
2437 if (cursor.par() != tmppit
2438 && (cursor.par()->layout() == tmppit->layout()
2439 || tmppit->layout() == tclass.defaultLayout())
2440 && cursor.par()->getAlign() == tmppit->getAlign()) {
2441 removeParagraph(tmprow);
2443 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2445 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2446 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2447 // strangely enough it seems that commenting out the line above removes
2448 // most or all of the segfaults. I will however also try to move the
2449 // two Remove... lines in front of the PasteParagraph too.
2452 cursor.pos(cursor.pos() - 1);
2456 // remove the lost paragraph
2457 // This one is not safe, since the paragraph that the tmprow and the
2458 // following rows belong to has been deleted by the PasteParagraph
2459 // above. The question is... could this be moved in front of the
2461 //RemoveParagraph(tmprow);
2462 //RemoveRow(tmprow);
2464 // This rebuilds the rows.
2465 appendParagraph(cursorRow());
2468 // the row may have changed, block, hfills etc.
2469 setCursor(cursor.par(), cursor.pos(), false);
2472 // this is the code for a normal backspace, not pasting
2474 recordUndo(bv(), Undo::DELETE, cursor.par());
2475 // We used to do cursorLeftIntern() here, but it is
2476 // not a good idea since it triggers the auto-delete
2477 // mechanism. So we do a cursorLeftIntern()-lite,
2478 // without the dreaded mechanism. (JMarc)
2479 setCursorIntern(cursor.par(), cursor.pos()- 1,
2480 false, cursor.boundary());
2482 if (cursor.par()->isInset(cursor.pos())) {
2483 // force complete redo when erasing display insets
2484 // this is a cruel method but safe..... Matthias
2485 if (cursor.par()->getInset(cursor.pos())->display() ||
2486 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2487 cursor.par()->erase(cursor.pos());
2493 RowList::iterator row = cursorRow();
2494 int y = cursor.y() - row->baseline();
2496 // remember that a space at the end of a row doesnt count
2497 // when calculating the fill
2498 if (cursor.pos() < lastPos(*this, row) ||
2499 !cursor.par()->isLineSeparator(cursor.pos())) {
2500 row->fill(row->fill() + singleWidth(
2505 // some special code when deleting a newline. This is similar
2506 // to the behavior when pasting paragraphs
2507 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2508 cursor.par()->erase(cursor.pos());
2509 // refresh the positions
2510 RowList::iterator tmprow = row;
2511 while (boost::next(tmprow) != rows().end() &&
2512 boost::next(tmprow)->par() == row->par()) {
2514 tmprow->pos(tmprow->pos() - 1);
2516 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2517 cursor.pos(cursor.pos() - 1);
2519 if (cursor.pos() < cursor.par()->size()
2520 && !cursor.par()->isSeparator(cursor.pos())) {
2521 cursor.par()->insertChar(cursor.pos(), ' ');
2522 setCharFont(cursor.par(), cursor.pos(), current_font);
2523 // refresh the positions
2525 while (boost::next(tmprow) != rows().end() &&
2526 boost::next(tmprow)->par() == row->par()) {
2528 tmprow->pos(tmprow->pos() + 1);
2532 cursor.par()->erase(cursor.pos());
2534 // refresh the positions
2535 RowList::iterator tmprow = row;
2536 while (boost::next(tmprow) != rows().end() &&
2537 boost::next(tmprow)->par() == row->par()) {
2539 tmprow->pos(tmprow->pos() - 1);
2542 // delete newlines at the beginning of paragraphs
2543 while (!cursor.par()->empty() &&
2544 cursor.pos() < cursor.par()->size() &&
2545 cursor.par()->isNewline(cursor.pos()) &&
2546 cursor.pos() == cursor.par()->beginningOfBody()) {
2547 cursor.par()->erase(cursor.pos());
2548 // refresh the positions
2550 while (boost::next(tmprow) != rows().end() &&
2551 boost::next(tmprow)->par() == row->par()) {
2553 tmprow->pos(tmprow->pos() - 1);
2558 // is there a break one row above
2559 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2560 z = rowBreakPoint(*boost::prior(row));
2561 if (z >= row->pos()) {
2564 RowList::iterator tmprow = boost::prior(row);
2566 // maybe the current row is now empty
2567 if (row->pos() >= row->par()->size()) {
2571 breakAgainOneRow(row);
2574 // set the dimensions of the row above
2575 y -= tmprow->height();
2576 tmprow->fill(fill(tmprow, workWidth()));
2577 setHeightOfRow(tmprow);
2580 setCursor(cursor.par(), cursor.pos(),
2581 false, cursor.boundary());
2582 //current_font = rawtmpfont;
2583 //real_current_font = realtmpfont;
2584 // check, whether the last character's font has changed.
2586 cursor.par()->getFontSettings(bv()->buffer()->params,
2587 cursor.par()->size() - 1))
2588 redoHeightOfParagraph();
2593 // break the cursor row again
2594 if (boost::next(row) != rows().end() &&
2595 boost::next(row)->par() == row->par() &&
2596 (lastPos(*this, row) == row->par()->size() - 1 ||
2597 rowBreakPoint(*row) != lastPos(*this, row))) {
2599 // it can happen that a paragraph loses one row
2600 // without a real breakup. This is when a word
2601 // is to long to be broken. Well, I don t care this
2603 if (lastPos(*this, row) == row->par()->size() - 1)
2604 removeRow(boost::next(row));
2608 breakAgainOneRow(row);
2609 // will the cursor be in another row now?
2610 if (boost::next(row) != rows().end() &&
2611 boost::next(row)->par() == row->par() &&
2612 lastPos(*this, row) <= cursor.pos()) {
2614 breakAgainOneRow(row);
2617 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2619 // set the dimensions of the row
2620 row->fill(fill(row, workWidth()));
2621 setHeightOfRow(row);
2623 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2627 // current_font = rawtmpfont;
2628 // real_current_font = realtmpfont;
2630 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
2631 != cursor.boundary())
2632 setCursor(cursor.par(), cursor.pos(), false, !cursor.boundary());
2634 lastpos = cursor.par()->size();
2635 if (cursor.pos() == lastpos)
2638 // check, whether the last characters font has changed.
2640 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2641 redoHeightOfParagraph();
2646 RowList::iterator LyXText::cursorRow() const
2648 return getRow(cursor.par(), cursor.pos());
2652 RowList::iterator LyXText::getRow(LyXCursor const & cur) const
2654 return getRow(cur.par(), cur.pos());
2659 LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
2662 return rowlist_.end();
2664 // find the first row of the specified paragraph
2665 RowList::iterator rit = rowlist_.begin();
2666 RowList::iterator end = rowlist_.end();
2667 while (boost::next(rit) != end && rit->par() != pit) {
2671 // now find the wanted row
2672 while (rit->pos() < pos
2673 && boost::next(rit) != end
2674 && boost::next(rit)->par() == pit
2675 && boost::next(rit)->pos() <= pos) {
2683 // returns pointer to a specified row
2685 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2690 return rowlist_.end();
2692 // find the first row of the specified paragraph
2693 RowList::iterator rit = rowlist_.begin();
2694 RowList::iterator end = rowlist_.end();
2695 while (boost::next(rit) != end && rit->par() != pit) {
2700 // now find the wanted row
2701 while (rit->pos() < pos
2702 && boost::next(rit) != end
2703 && boost::next(rit)->par() == pit
2704 && boost::next(rit)->pos() <= pos) {
2713 // returns pointer to some fancy row 'below' specified row
2714 RowList::iterator LyXText::cursorIRow() const
2717 return getRow(cursor.par(), cursor.pos(), y);
2721 RowList::iterator LyXText::getRowNearY(int & y) const
2723 RowList::iterator rit = anchor_row_;
2724 RowList::iterator const beg = rows().begin();
2725 RowList::iterator const end = rows().end();
2727 if (rows().empty()) {
2734 int tmpy = rit->y();
2737 while (rit != end && tmpy <= y) {
2738 tmpy += rit->height();
2743 tmpy -= rit->height();
2746 while (rit != beg && tmpy > y) {
2748 tmpy -= rit->height();
2751 if (tmpy < 0 || rit == end) {
2763 int LyXText::getDepth() const
2765 return cursor.par()->getDepth();