1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
15 #include "paragraph.h"
17 #include "bufferparams.h"
23 #include "frontends/LyXView.h"
24 #include "frontends/Painter.h"
25 #include "frontends/font_metrics.h"
26 #include "frontends/screen.h"
27 #include "frontends/WorkArea.h"
28 #include "bufferview_funcs.h"
29 #include "BufferView.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "WordLangTuple.h"
34 #include "paragraph_funcs.h"
35 #include "rowpainter.h"
36 #include "lyxrow_funcs.h"
38 #include "insets/insettext.h"
40 #include "support/textutils.h"
41 #include "support/LAssert.h"
42 #include "support/lstrings.h"
51 using namespace bv_funcs;
53 /// top, right, bottom pixel margin
54 extern int const PAPER_MARGIN = 20;
55 /// margin for changebar
56 extern int const CHANGEBAR_MARGIN = 10;
58 extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
60 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
63 BufferView * LyXText::bv()
65 lyx::Assert(bv_owner != 0);
70 BufferView * LyXText::bv() const
72 lyx::Assert(bv_owner != 0);
77 int LyXText::top_y() const
79 if (anchor_row_ == rowlist_.end())
84 RowList::iterator rit = rowlist_.begin();
85 RowList::iterator end = rowlist_.end();
86 for (; rit != end && rit != anchor_row_; ++rit) {
89 return y + anchor_row_offset_;
93 void LyXText::top_y(int newy)
97 lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
100 RowList::iterator rit = getRowNearY(y);
102 if (rit == anchor_row_ && anchor_row_offset_ == newy - y) {
103 lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
108 anchor_row_offset_ = newy - y;
109 lyxerr[Debug::GUI] << "changing reference to row: " << &*anchor_row_
110 << " offset: " << anchor_row_offset_ << endl;
115 void LyXText::anchor_row(RowList::iterator rit)
118 anchor_row_offset_ = 0;
120 anchor_row_offset_ = old_y - top_y();
121 lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
122 << &*anchor_row_ << " offset: "
123 << anchor_row_offset_ << endl;
127 int LyXText::workWidth() const
130 // FIXME: pass (const ?) ref
131 return inset_owner->textWidth(bv());
133 return bv()->workWidth();
137 int LyXText::workWidth(Inset * inset) const
139 Paragraph * par = inset->parOwner();
142 pos_type pos = par->getPositionOfInset(inset);
143 lyx::Assert(pos != -1);
145 LyXLayout_ptr const & layout = par->layout();
147 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
148 // Optimization here: in most cases, the real row is
149 // not needed, but only the par/pos values. So we just
150 // construct a dummy row for leftMargin. (JMarc)
154 return workWidth() - leftMargin(dummyrow);
157 RowList::iterator row = getRow(par, pos, dummy_y);
158 RowList::iterator frow = row;
159 RowList::iterator beg = rowlist_.begin();
161 while (frow != beg && frow->par() == boost::prior(frow)->par())
164 // FIXME: I don't understand this code - jbl
166 unsigned int maxw = 0;
167 while (!isParEnd(*this, frow)) {
168 if ((frow != row) && (maxw < frow->width()))
169 maxw = frow->width();
180 int LyXText::getRealCursorX() const
183 if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
184 x = the_locking_inset->getLyXText(bv())->getRealCursorX();
189 #warning FIXME This function seems to belong outside of LyxText.
190 unsigned char LyXText::transformChar(unsigned char c, Paragraph const & par,
193 if (!Encodings::is_arabic(c))
194 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
195 return c + (0xb0 - '0');
199 unsigned char const prev_char = pos > 0 ? par.getChar(pos - 1) : ' ';
200 unsigned char next_char = ' ';
202 for (pos_type i = pos + 1; i < par.size(); ++i)
203 if (!Encodings::IsComposeChar_arabic(par.getChar(i))) {
204 next_char = par.getChar(i);
208 if (Encodings::is_arabic(next_char)) {
209 if (Encodings::is_arabic(prev_char) &&
210 !Encodings::is_arabic_special(prev_char))
211 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
213 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
215 if (Encodings::is_arabic(prev_char) &&
216 !Encodings::is_arabic_special(prev_char))
217 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
219 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
223 // This is the comments that some of the warnings below refers to.
224 // There are some issues in this file and I don't think they are
225 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
226 // this is a problem that has been here almost from day one and that a
227 // larger userbase with differenct access patters triggers the bad
228 // behaviour. (segfaults.) What I think happen is: In several places
229 // we store the paragraph in the current cursor and then moves the
230 // cursor. This movement of the cursor will delete paragraph at the
231 // old position if it is now empty. This will make the temporary
232 // pointer to the old cursor paragraph invalid and dangerous to use.
233 // And is some cases this will trigger a segfault. I have marked some
234 // of the cases where this happens with a warning, but I am sure there
235 // are others in this file and in text2.C. There is also a note in
236 // Delete() that you should read. In Delete I store the paragraph->id
237 // instead of a pointer to the paragraph. I am pretty sure this faulty
238 // use of temporary pointers to paragraphs that might have gotten
239 // invalidated (through a cursor movement) before they are used, are
240 // the cause of the strange crashes we get reported often.
242 // It is very tiresom to change this code, especially when it is as
243 // hard to read as it is. Help to fix all the cases where this is done
244 // would be greately appreciated.
248 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
250 if (pos >= pit->size())
253 char const c = pit->getChar(pos);
254 return singleWidth(pit, pos, c);
258 int LyXText::singleWidth(ParagraphList::iterator pit,
259 pos_type pos, char c) const
261 if (pos >= pit->size())
264 LyXFont const font = getFont(bv()->buffer(), pit, pos);
266 // The most common case is handled first (Asger)
267 if (IsPrintable(c)) {
268 if (font.language()->RightToLeft()) {
269 if (font.language()->lang() == "arabic" &&
270 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
271 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
272 if (Encodings::IsComposeChar_arabic(c))
275 c = transformChar(c, *pit, pos);
276 } else if (font.language()->lang() == "hebrew" &&
277 Encodings::IsComposeChar_hebrew(c))
280 return font_metrics::width(c, font);
284 if (c == Paragraph::META_INSET) {
285 Inset * tmpinset = pit->getInset(pos);
287 if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
288 // Because of the representation as vertical lines
292 #warning inset->update FIXME
293 // this IS needed otherwise on initialitation we don't get the fill
294 // of the row right (ONLY on initialization if we read a file!)
295 // should be changed! (Jug 20011204)
296 tmpinset->update(bv());
298 return tmpinset->width(bv(), font);
303 if (IsSeparatorChar(c))
305 return font_metrics::width(c, font);
309 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
311 if (bidi_start == -1)
314 return log2vis_list[pos - bidi_start];
318 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
320 if (bidi_start == -1)
323 return vis2log_list[pos - bidi_start];
327 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
329 if (bidi_start == -1)
332 return bidi_levels[pos - bidi_start];
336 bool LyXText::bidi_InRange(lyx::pos_type pos) const
338 return bidi_start == -1 ||
339 (bidi_start <= pos && pos <= bidi_end);
343 void LyXText::computeBidiTables(Buffer const * buf,
344 RowList::iterator row) const
346 bidi_same_direction = true;
347 if (!lyxrc.rtl_support) {
352 Inset * inset = row->par()->inInset();
353 if (inset && inset->owner() &&
354 inset->owner()->lyxCode() == Inset::ERT_CODE) {
359 bidi_start = row->pos();
360 bidi_end = lastPrintablePos(*this, row);
362 if (bidi_start > bidi_end) {
367 if (bidi_end + 2 - bidi_start >
368 static_cast<pos_type>(log2vis_list.size())) {
370 (bidi_end + 2 - bidi_start < 500) ?
371 500 : 2 * (bidi_end + 2 - bidi_start);
372 log2vis_list.resize(new_size);
373 vis2log_list.resize(new_size);
374 bidi_levels.resize(new_size);
377 vis2log_list[bidi_end + 1 - bidi_start] = -1;
378 log2vis_list[bidi_end + 1 - bidi_start] = -1;
382 row->par()->isRightToLeftPar(buf->params);
386 pos_type const body_pos = row->par()->beginningOfBody();
388 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
389 bool is_space = row->par()->isLineSeparator(lpos);
391 (is_space && lpos + 1 <= bidi_end &&
392 !row->par()->isLineSeparator(lpos + 1) &&
393 !row->par()->isNewline(lpos + 1))
395 LyXFont font = row->par()->getFontSettings(buf->params, pos);
396 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
397 font.number() == LyXFont::ON &&
398 row->par()->getFontSettings(buf->params, lpos - 1).number()
400 font = row->par()->getFontSettings(buf->params, lpos);
405 bool new_rtl = font.isVisibleRightToLeft();
406 bool new_rtl0 = font.isRightToLeft();
409 if (lpos == body_pos - 1
410 && row->pos() < body_pos - 1
412 new_level = (rtl_par) ? 1 : 0;
413 new_rtl = new_rtl0 = rtl_par;
415 new_level = (new_rtl) ? 1 : 2;
417 new_level = (rtl_par) ? 2 : 0;
419 if (is_space && new_level >= level) {
425 int new_level2 = new_level;
427 if (level == new_level && rtl0 != new_rtl0) {
429 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
430 } else if (level < new_level) {
431 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
432 if (new_level > rtl_par)
433 bidi_same_direction = false;
435 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
438 bidi_levels[lpos - bidi_start] = new_level;
440 while (level > new_level2) {
441 pos_type old_lpos = stack[--level];
442 int delta = lpos - old_lpos - 1;
445 log2vis_list[lpos - bidi_start] += delta;
446 log2vis_list[old_lpos - bidi_start] += delta;
448 while (level < new_level)
449 stack[level++] = lpos;
453 pos_type const old_lpos = stack[--level];
454 int delta = bidi_end - old_lpos;
457 log2vis_list[old_lpos - bidi_start] += delta;
460 pos_type vpos = bidi_start - 1;
461 for (pos_type lpos = bidi_start;
462 lpos <= bidi_end; ++lpos) {
463 vpos += log2vis_list[lpos - bidi_start];
464 vis2log_list[vpos - bidi_start] = lpos;
465 log2vis_list[lpos - bidi_start] = vpos;
470 // This method requires a previous call to ComputeBidiTables()
471 bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
474 if (!lyxrc.rtl_support || pos == 0)
477 if (!bidi_InRange(pos - 1)) {
478 /// This can happen if pos is the first char of a row.
479 /// Returning false in this case is incorrect!
483 bool const rtl = bidi_level(pos - 1) % 2;
484 bool const rtl2 = bidi_InRange(pos)
485 ? bidi_level(pos) % 2
486 : par->isRightToLeftPar(buf->params);
491 bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
492 pos_type pos, LyXFont const & font) const
494 if (!lyxrc.rtl_support)
495 return false; // This is just for speedup
497 bool const rtl = font.isVisibleRightToLeft();
498 bool const rtl2 = bidi_InRange(pos)
499 ? bidi_level(pos) % 2
500 : par->isRightToLeftPar(buf->params);
505 int LyXText::leftMargin(Row const & row) const
509 if (row.pos() < row.par()->size())
510 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
511 (ins = row.par()->getInset(row.pos())) &&
512 (ins->needFullRow() || ins->display()))
515 LyXTextClass const & tclass =
516 bv()->buffer()->params.getLyXTextClass();
517 LyXLayout_ptr const & layout = row.par()->layout();
519 string parindent = layout->parindent;
523 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
525 // this is the way, LyX handles the LaTeX-Environments.
526 // I have had this idea very late, so it seems to be a
527 // later added hack and this is true
528 if (!row.par()->getDepth()) {
529 if (row.par()->layout() == tclass.defaultLayout()) {
530 // find the previous same level paragraph
531 if (row.par()->previous()) {
532 Paragraph * newpar = row.par()
533 ->depthHook(row.par()->getDepth());
535 newpar->layout()->nextnoindent)
540 // find the next level paragraph
542 Paragraph * newpar = row.par()->outerHook();
544 // make a corresponding row. Needed to call leftMargin()
546 // check wether it is a sufficent paragraph
547 if (newpar && newpar->layout()->isEnvironment()) {
549 dummyrow.par(newpar);
550 dummyrow.pos(newpar->size());
551 x = leftMargin(dummyrow);
554 if (newpar && row.par()->layout() == tclass.defaultLayout()) {
555 if (newpar->params().noindent())
558 parindent = newpar->layout()->parindent;
564 LyXFont const labelfont = getLabelFont(bv()->buffer(), row.par());
565 switch (layout->margintype) {
567 if (!layout->leftmargin.empty()) {
568 x += font_metrics::signedWidth(layout->leftmargin,
569 tclass.defaultfont());
571 if (!row.par()->getLabelstring().empty()) {
572 x += font_metrics::signedWidth(layout->labelindent,
574 x += font_metrics::width(row.par()->getLabelstring(),
576 x += font_metrics::width(layout->labelsep, labelfont);
580 x += font_metrics::signedWidth(layout->labelindent, labelfont);
581 // The width of an empty par, even with manual label, should be 0
582 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
583 if (!row.par()->getLabelWidthString().empty()) {
584 x += font_metrics::width(row.par()->getLabelWidthString(),
586 x += font_metrics::width(layout->labelsep, labelfont);
591 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
592 / (row.par()->getDepth() + 4);
594 case MARGIN_FIRST_DYNAMIC:
595 if (layout->labeltype == LABEL_MANUAL) {
596 if (row.pos() >= row.par()->beginningOfBody()) {
597 x += font_metrics::signedWidth(layout->leftmargin,
600 x += font_metrics::signedWidth(layout->labelindent,
604 // Special case to fix problems with
606 || (layout->labeltype == LABEL_STATIC
607 && layout->latextype == LATEX_ENVIRONMENT
608 && ! row.par()->isFirstInSequence())) {
609 x += font_metrics::signedWidth(layout->leftmargin,
611 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
612 && layout->labeltype != LABEL_BIBLIO
613 && layout->labeltype !=
614 LABEL_CENTERED_TOP_ENVIRONMENT) {
615 x += font_metrics::signedWidth(layout->labelindent,
617 x += font_metrics::width(layout->labelsep, labelfont);
618 x += font_metrics::width(row.par()->getLabelstring(),
623 case MARGIN_RIGHT_ADDRESS_BOX:
625 // ok, a terrible hack. The left margin depends on the widest
626 // row in this paragraph. Do not care about footnotes, they
627 // are *NOT* allowed in the LaTeX realisation of this layout.
629 // find the first row of this paragraph
630 RowList::iterator tmprit = rowlist_.begin();
631 while (tmprit != rowlist_.end()
632 && tmprit->par() != row.par())
635 int minfill = tmprit->fill();
636 while (boost::next(tmprit) != rowlist_.end() &&
637 boost::next(tmprit)->par() == row.par()) {
639 if (tmprit->fill() < minfill)
640 minfill = tmprit->fill();
643 x += font_metrics::signedWidth(layout->leftmargin,
644 tclass.defaultfont());
650 if ((workWidth() > 0) &&
651 !row.par()->params().leftIndent().zero())
653 LyXLength const len = row.par()->params().leftIndent();
654 int const tw = inset_owner ?
655 inset_owner->latexTextWidth(bv()) : workWidth();
656 x += len.inPixels(tw);
659 LyXAlignment align; // wrong type
661 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
662 align = layout->align;
664 align = row.par()->params().align();
666 // set the correct parindent
667 if (row.pos() == 0) {
668 if ((layout->labeltype == LABEL_NO_LABEL
669 || layout->labeltype == LABEL_TOP_ENVIRONMENT
670 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
671 || (layout->labeltype == LABEL_STATIC
672 && layout->latextype == LATEX_ENVIRONMENT
673 && ! row.par()->isFirstInSequence()))
674 && align == LYX_ALIGN_BLOCK
675 && !row.par()->params().noindent()
676 // in tabulars and ert paragraphs are never indented!
677 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
678 (row.par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
679 row.par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
680 && (row.par()->layout() != tclass.defaultLayout() ||
681 bv()->buffer()->params.paragraph_separation ==
682 BufferParams::PARSEP_INDENT)) {
683 x += font_metrics::signedWidth(parindent,
684 tclass.defaultfont());
685 } else if (layout->labeltype == LABEL_BIBLIO) {
686 // ale970405 Right width for bibitems
687 x += bibitemMaxWidth(bv(), tclass.defaultfont());
695 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
699 if (row.pos() < row.par()->size())
700 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
701 (ins = row.par()->getInset(row.pos())) &&
702 (ins->needFullRow() || ins->display()))
705 LyXTextClass const & tclass = buf.params.getLyXTextClass();
706 LyXLayout_ptr const & layout = row.par()->layout();
709 + font_metrics::signedWidth(tclass.rightmargin(),
710 tclass.defaultfont());
712 x += font_metrics::signedWidth(layout->rightmargin,
713 tclass.defaultfont())
714 * 4 / (row.par()->getDepth() + 4);
719 int LyXText::labelEnd(Row const & row) const
721 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
723 tmprow.pos(row.par()->size());
724 // return the beginning of the body
725 return leftMargin(tmprow);
728 // LabelEnd is only needed if the layout
729 // fills a flushleft label.
736 // this needs special handling - only newlines count as a break point
737 pos_type addressBreakPoint(pos_type i, Paragraph * par)
739 for (; i < par->size(); ++i) {
740 if (par->isNewline(i))
751 LyXText::rowBreakPoint(Row const & row) const
753 ParagraphList::iterator pit = row.par();
755 // maximum pixel width of a row.
756 int width = workWidth() - rightMargin(*bv()->buffer(), row);
758 // inset->textWidth() returns -1 via workWidth(),
763 LyXLayout_ptr const & layout = pit->layout();
765 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
766 return addressBreakPoint(row.pos(), &*pit);
768 pos_type const pos = row.pos();
769 pos_type const body_pos = pit->beginningOfBody();
770 pos_type const last = pit->size();
771 pos_type point = last;
776 // Now we iterate through until we reach the right margin
777 // or the end of the par, then choose the possible break
780 int const left = leftMargin(const_cast<Row&>(row));
783 // pixel width since last breakpoint
785 bool fullrow = false;
788 for (; i < last; ++i) {
789 if (pit->isNewline(i)) {
794 char const c = pit->getChar(i);
796 int thiswidth = singleWidth(pit, i, c);
798 // add the auto-hfill from label end to the body
799 if (body_pos && i == body_pos) {
800 thiswidth += font_metrics::width(layout->labelsep,
801 getLabelFont(bv()->buffer(), pit));
802 if (pit->isLineSeparator(i - 1))
803 thiswidth -= singleWidth(pit, i - 1);
807 chunkwidth += thiswidth;
809 Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
810 fullrow = (in && (in->display() || in->needFullRow()));
812 // break before a character that will fall off
813 // the right of the row
815 // if no break before or we are at an inset
816 // that will take up a row, break here
817 if (point == last || fullrow || chunkwidth >= (width - left)) {
826 if (!in || in->isChar()) {
827 // some insets are line separators too
828 if (pit->isLineSeparator(i)) {
838 // full row insets start at a new row
840 if (pos < last - 1) {
842 if (pit->isLineSeparator(i + 1))
845 // to avoid extra rows
855 if (point == last && x >= width) {
856 // didn't find one, break at the point we reached the edge
858 } else if (i == last && x < width) {
859 // found one, but we fell off the end of the par, so prefer
864 // manual labels cannot be broken in LaTeX. But we
865 // want to make our on-screen rendering of footnotes
867 if (!fullrow && body_pos && point < body_pos)
868 point = body_pos - 1;
874 // returns the minimum space a row needs on the screen in pixel
875 int LyXText::fill(RowList::iterator row, int paper_width) const
881 // get the pure distance
882 pos_type const last = lastPrintablePos(*this, row);
884 // special handling of the right address boxes
885 if (row->par()->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
886 int const tmpfill = row->fill();
887 row->fill(0); // the minfill in MarginLeft()
888 w = leftMargin(*row);
891 w = leftMargin(*row);
893 ParagraphList::iterator pit = row->par();
894 LyXLayout_ptr const & layout = pit->layout();
896 pos_type const body_pos = pit->beginningOfBody();
897 pos_type i = row->pos();
900 if (body_pos > 0 && i == body_pos) {
901 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
902 if (pit->isLineSeparator(i - 1))
903 w -= singleWidth(pit, i - 1);
904 int left_margin = labelEnd(*row);
908 w += singleWidth(pit, i);
911 if (body_pos > 0 && body_pos > last) {
912 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
913 if (last >= 0 && pit->isLineSeparator(last))
914 w -= singleWidth(pit, last);
915 int const left_margin = labelEnd(*row);
920 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
925 // returns the minimum space a manual label needs on the screen in pixel
926 int LyXText::labelFill(Row const & row) const
928 pos_type last = row.par()->beginningOfBody();
930 lyx::Assert(last > 0);
932 // -1 because a label ends either with a space that is in the label,
933 // or with the beginning of a footnote that is outside the label.
936 // a separator at this end does not count
937 if (row.par()->isLineSeparator(last))
941 pos_type i = row.pos();
943 w += singleWidth(row.par(), i);
948 string const & labwidstr = row.par()->params().labelWidthString();
949 if (!labwidstr.empty()) {
950 LyXFont const labfont = getLabelFont(bv()->buffer(), row.par());
951 int const labwidth = font_metrics::width(labwidstr, labfont);
952 fill = max(labwidth - w, 0);
959 LColor::color LyXText::backgroundColor() const
962 return inset_owner->backgroundColor();
964 return LColor::background;
968 void LyXText::setHeightOfRow(RowList::iterator rit)
970 // No need to do anything then...
971 if (rit == rows().end())
974 // get the maximum ascent and the maximum descent
978 float layoutdesc = 0;
981 Inset * tmpinset = 0;
983 // ok , let us initialize the maxasc and maxdesc value.
984 // This depends in LaTeX of the font of the last character
985 // in the paragraph. The hack below is necessary because
986 // of the possibility of open footnotes
988 // Correction: only the fontsize count. The other properties
989 // are taken from the layoutfont. Nicer on the screen :)
990 ParagraphList::iterator pit = rit->par();
991 ParagraphList::iterator firstpit = pit;
993 LyXLayout_ptr const & layout = firstpit->layout();
995 // as max get the first character of this row then it can increase but not
996 // decrease the height. Just some point to start with so we don't have to
997 // do the assignment below too often.
998 LyXFont font = getFont(bv()->buffer(), pit, rit->pos());
999 LyXFont::FONT_SIZE const tmpsize = font.size();
1000 font = getLayoutFont(bv()->buffer(), pit);
1001 LyXFont::FONT_SIZE const size = font.size();
1002 font.setSize(tmpsize);
1004 LyXFont labelfont = getLabelFont(bv()->buffer(), pit);
1006 float spacing_val = 1.0;
1007 if (!rit->par()->params().spacing().isDefault()) {
1008 spacing_val = rit->par()->params().spacing().getValue();
1010 spacing_val = bv()->buffer()->params.spacing.getValue();
1012 //lyxerr << "spacing_val = " << spacing_val << endl;
1014 int maxasc = int(font_metrics::maxAscent(font) *
1015 layout->spacing.getValue() *
1017 int maxdesc = int(font_metrics::maxDescent(font) *
1018 layout->spacing.getValue() *
1021 pos_type const pos_end = lastPos(*this, rit);
1025 if (!rit->par()->empty()) {
1026 // Check if any insets are larger
1027 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1028 if (rit->par()->isInset(pos)) {
1029 tmpfont = getFont(bv()->buffer(), rit->par(), pos);
1030 tmpinset = rit->par()->getInset(pos);
1032 #if 1 // this is needed for deep update on initialitation
1033 #warning inset->update FIXME
1034 tmpinset->update(bv());
1036 asc = tmpinset->ascent(bv(), tmpfont);
1037 desc = tmpinset->descent(bv(), tmpfont);
1038 maxwidth += tmpinset->width(bv(), tmpfont);
1039 maxasc = max(maxasc, asc);
1040 maxdesc = max(maxdesc, desc);
1043 maxwidth += singleWidth(rit->par(), pos);
1048 // Check if any custom fonts are larger (Asger)
1049 // This is not completely correct, but we can live with the small,
1050 // cosmetic error for now.
1051 LyXFont::FONT_SIZE maxsize =
1052 rit->par()->highestFontInRange(rit->pos(), pos_end, size);
1053 if (maxsize > font.size()) {
1054 font.setSize(maxsize);
1056 asc = font_metrics::maxAscent(font);
1057 desc = font_metrics::maxDescent(font);
1064 // This is nicer with box insets:
1068 rit->ascent_of_text(maxasc);
1070 // is it a top line?
1071 if (!rit->pos() && (rit->par() == firstpit)) {
1073 // some parksips VERY EASY IMPLEMENTATION
1074 if (bv()->buffer()->params.paragraph_separation ==
1075 BufferParams::PARSEP_SKIP)
1077 if (layout->isParagraph()
1078 && firstpit->getDepth() == 0
1079 && firstpit->previous())
1081 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1082 } else if (firstpit->previous() &&
1083 firstpit->previous()->layout()->isParagraph() &&
1084 firstpit->previous()->getDepth() == 0)
1086 // is it right to use defskip here too? (AS)
1087 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1092 if (!rit->par()->previous() && !isInInset())
1093 maxasc += PAPER_MARGIN;
1095 // add the vertical spaces, that the user added
1096 maxasc += getLengthMarkerHeight(*bv(), firstpit->params().spaceTop());
1098 // do not forget the DTP-lines!
1099 // there height depends on the font of the nearest character
1100 if (firstpit->params().lineTop())
1102 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1104 // and now the pagebreaks
1105 if (firstpit->params().pagebreakTop())
1106 maxasc += 3 * defaultRowHeight();
1108 if (firstpit->params().startOfAppendix())
1109 maxasc += 3 * defaultRowHeight();
1111 // This is special code for the chapter, since the label of this
1112 // layout is printed in an extra row
1113 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1114 && bv()->buffer()->params.secnumdepth >= 0)
1116 float spacing_val = 1.0;
1117 if (!rit->par()->params().spacing().isDefault()) {
1118 spacing_val = rit->par()->params().spacing().getValue();
1120 spacing_val = bv()->buffer()->params.spacing.getValue();
1123 labeladdon = int(font_metrics::maxDescent(labelfont) *
1124 layout->spacing.getValue() *
1126 + int(font_metrics::maxAscent(labelfont) *
1127 layout->spacing.getValue() *
1131 // special code for the top label
1132 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1133 || layout->labeltype == LABEL_BIBLIO
1134 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1135 && rit->par()->isFirstInSequence()
1136 && !rit->par()->getLabelstring().empty())
1138 float spacing_val = 1.0;
1139 if (!rit->par()->params().spacing().isDefault()) {
1140 spacing_val = rit->par()->params().spacing().getValue();
1142 spacing_val = bv()->buffer()->params.spacing.getValue();
1146 (font_metrics::maxAscent(labelfont) *
1147 layout->spacing.getValue() *
1149 +(font_metrics::maxDescent(labelfont) *
1150 layout->spacing.getValue() *
1152 + layout->topsep * defaultRowHeight()
1153 + layout->labelbottomsep * defaultRowHeight());
1156 // and now the layout spaces, for example before and after a section,
1157 // or between the items of a itemize or enumerate environment
1159 if (!firstpit->params().pagebreakTop()) {
1160 Paragraph * prev = rit->par()->previous();
1162 prev = rit->par()->depthHook(rit->par()->getDepth());
1163 if (prev && prev->layout() == firstpit->layout() &&
1164 prev->getDepth() == firstpit->getDepth() &&
1165 prev->getLabelWidthString() == firstpit->getLabelWidthString())
1167 layoutasc = (layout->itemsep * defaultRowHeight());
1168 } else if (rit != rows().begin()) {
1169 tmptop = layout->topsep;
1171 if (boost::prior(rit)->par()->getDepth() >= rit->par()->getDepth())
1172 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1175 layoutasc = (tmptop * defaultRowHeight());
1176 } else if (rit->par()->params().lineTop()) {
1177 tmptop = layout->topsep;
1180 layoutasc = (tmptop * defaultRowHeight());
1183 prev = rit->par()->outerHook();
1185 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1187 if (firstpit->previous() &&
1188 firstpit->previous()->getDepth() == 0 &&
1189 firstpit->previous()->layout() !=
1193 } else if (firstpit->previous()) {
1194 maxasc += int(layout->parsep * defaultRowHeight());
1200 // is it a bottom line?
1201 if (rit->par() == pit
1202 && (boost::next(rit) == rows().end() ||
1203 boost::next(rit)->par() != rit->par())) {
1204 // the bottom margin
1205 if (boost::next(pit) == ownerParagraphs().end() &&
1207 maxdesc += PAPER_MARGIN;
1209 // add the vertical spaces, that the user added
1210 maxdesc += getLengthMarkerHeight(*bv(), firstpit->params().spaceBottom());
1212 // do not forget the DTP-lines!
1213 // there height depends on the font of the nearest character
1214 if (firstpit->params().lineBottom())
1215 maxdesc += 2 * font_metrics::ascent('x',
1216 getFont(bv()->buffer(),
1218 max(pos_type(0), pit->size() - 1)));
1220 // and now the pagebreaks
1221 if (firstpit->params().pagebreakBottom())
1222 maxdesc += 3 * defaultRowHeight();
1224 // and now the layout spaces, for example before and after
1225 // a section, or between the items of a itemize or enumerate
1227 if (!firstpit->params().pagebreakBottom()
1228 && rit->par()->next()) {
1229 ParagraphList::iterator nextpit = boost::next(rit->par());
1230 ParagraphList::iterator comparepit = rit->par();
1234 if (comparepit->getDepth() > nextpit->getDepth()) {
1235 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1236 comparepit = comparepit->depthHook(nextpit->getDepth());
1237 if (comparepit->layout()!= nextpit->layout()
1238 || nextpit->getLabelWidthString() !=
1239 comparepit->getLabelWidthString())
1241 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1243 if (unusual > usual)
1244 layoutdesc = unusual;
1247 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1249 if (comparepit->layout() != nextpit->layout()
1250 || nextpit->getLabelWidthString() !=
1251 comparepit->getLabelWidthString())
1252 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1257 // incalculate the layout spaces
1258 maxasc += int(layoutasc * 2 / (2 + firstpit->getDepth()));
1259 maxdesc += int(layoutdesc * 2 / (2 + firstpit->getDepth()));
1261 // calculate the new height of the text
1262 height -= rit->height();
1264 rit->height(maxasc + maxdesc + labeladdon);
1265 rit->baseline(maxasc + labeladdon);
1267 height += rit->height();
1269 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1272 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1275 rit->width(maxwidth);
1276 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1278 rit->width(int(maxwidth + x));
1280 width = max(0, workWidth());
1281 RowList::iterator it = rows().begin();
1282 RowList::iterator end = rows().end();
1283 for (; it != end; ++it) {
1284 if (it->width() > width)
1285 width = it->width();
1291 // Appends the implicit specified paragraph before the specified row,
1292 // start at the implicit given position
1293 void LyXText::appendParagraph(RowList::iterator rowit)
1295 lyx::Assert(rowit != rowlist_.end());
1297 pos_type const last = rowit->par()->size();
1301 pos_type z = rowBreakPoint(*rowit);
1303 RowList::iterator tmprow = rowit;
1307 Row newrow(rowit->par(), z);
1308 rowit = rowlist_.insert(boost::next(rowit), newrow);
1313 // Set the dimensions of the row
1314 // fixed fill setting now by calling inset->update() in
1315 // SingleWidth when needed!
1316 tmprow->fill(fill(tmprow, workWidth()));
1317 setHeightOfRow(tmprow);
1323 void LyXText::breakAgain(RowList::iterator rit)
1325 lyx::Assert(rit != rows().end());
1327 bool not_ready = true;
1330 pos_type z = rowBreakPoint(*rit);
1331 RowList::iterator tmprit = rit;
1332 RowList::iterator end = rows().end();
1334 if (z < rit->par()->size()) {
1335 if (boost::next(rit) == end ||
1336 (boost::next(rit) != end &&
1337 boost::next(rit)->par() != rit->par())) {
1340 Row newrow(rit->par(), z);
1341 rit = rowlist_.insert(boost::next(rit), newrow);
1345 if (rit->pos() == z)
1346 not_ready = false; // the rest will not change
1352 // if there are some rows too much, delete them
1353 // only if you broke the whole paragraph!
1354 RowList::iterator tmprit2 = rit;
1355 while (boost::next(tmprit2) != end
1356 && boost::next(tmprit2)->par() == rit->par()) {
1359 while (tmprit2 != rit) {
1361 removeRow(boost::next(tmprit2));
1366 // set the dimensions of the row
1367 tmprit->fill(fill(tmprit, workWidth()));
1368 setHeightOfRow(tmprit);
1369 } while (not_ready);
1373 // this is just a little changed version of break again
1374 void LyXText::breakAgainOneRow(RowList::iterator rit)
1376 lyx::Assert(rit != rows().end());
1378 pos_type z = rowBreakPoint(*rit);
1379 RowList::iterator tmprit = rit;
1380 RowList::iterator end = rows().end();
1382 if (z < rit->par()->size()) {
1383 if (boost::next(rit) == end ||
1384 (boost::next(rit) != end &&
1385 boost::next(rit)->par() != rit->par())) {
1388 Row newrow(rit->par(), z);
1389 rit = rowlist_.insert(boost::next(rit), newrow);
1393 if (rit->pos() != z)
1397 // if there are some rows too much, delete them
1398 // only if you broke the whole paragraph!
1399 RowList::iterator tmprit2 = rit;
1400 while (boost::next(tmprit2) != end
1401 && boost::next(tmprit2)->par() == rit->par()) {
1404 while (tmprit2 != rit) {
1406 removeRow(boost::next(tmprit2));
1410 // set the dimensions of the row
1411 tmprit->fill(fill(tmprit, workWidth()));
1412 setHeightOfRow(tmprit);
1416 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1418 // allow only if at start or end, or all previous is new text
1419 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1420 && cursor.par()->isChangeEdited(0, cursor.pos()))
1423 LyXTextClass const & tclass =
1424 bv()->buffer()->params.getLyXTextClass();
1425 LyXLayout_ptr const & layout = cursor.par()->layout();
1427 // this is only allowed, if the current paragraph is not empty or caption
1428 // and if it has not the keepempty flag aktive
1429 if (cursor.par()->empty()
1430 && layout->labeltype != LABEL_SENSITIVE
1431 && !layout->keepempty)
1434 setUndo(bv(), Undo::FINISH, &*cursor.par(), &*boost::next(cursor.par()));
1436 // Always break behind a space
1438 // It is better to erase the space (Dekel)
1439 if (cursor.pos() < cursor.par()->size()
1440 && cursor.par()->isLineSeparator(cursor.pos()))
1441 cursor.par()->erase(cursor.pos());
1442 // cursor.pos(cursor.pos() + 1);
1444 // break the paragraph
1448 keep_layout = layout->isEnvironment();
1450 // we need to set this before we insert the paragraph. IMO the
1451 // breakParagraph call should return a bool if it inserts the
1452 // paragraph before or behind and we should react on that one
1453 // but we can fix this in 1.3.0 (Jug 20020509)
1454 bool const isempty = (layout->keepempty && cursor.par()->empty());
1455 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
1458 // well this is the caption hack since one caption is really enough
1459 if (layout->labeltype == LABEL_SENSITIVE) {
1461 // set to standard-layout
1462 cursor.par()->applyLayout(tclass.defaultLayout());
1464 // set to standard-layout
1465 cursor.par()->next()->applyLayout(tclass.defaultLayout());
1468 // if the cursor is at the beginning of a row without prior newline,
1470 // This touches only the screen-update. Otherwise we would may have
1471 // an empty row on the screen
1472 if (cursor.pos() && cursor.row()->pos() == cursor.pos()
1473 && !cursor.row()->par()->isNewline(cursor.pos() - 1))
1478 int y = cursor.y() - cursor.row()->baseline();
1480 // Do not forget the special right address boxes
1481 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1482 RowList::iterator r = cursor.row();
1483 while (r != rows().begin() && boost::prior(r)->par() == r->par()) {
1491 removeParagraph(cursor.row());
1493 // set the dimensions of the cursor row
1494 cursor.row()->fill(fill(cursor.row(), workWidth()));
1496 setHeightOfRow(cursor.row());
1498 #warning Trouble Point! (Lgb)
1499 // When ::breakParagraph is called from within an inset we must
1500 // ensure that the correct ParagraphList is used. Today that is not
1501 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1502 while (!cursor.par()->next()->empty()
1503 && cursor.par()->next()->isNewline(0))
1504 cursor.par()->next()->erase(0);
1506 insertParagraph(cursor.par()->next(), boost::next(cursor.row()));
1509 // This check is necessary. Otherwise the new empty paragraph will
1510 // be deleted automatically. And it is more friendly for the user!
1511 if (cursor.pos() || isempty)
1512 setCursor(cursor.par()->next(), 0);
1514 setCursor(cursor.par(), 0);
1516 if (boost::next(cursor.row()) != rows().end())
1517 breakAgain(boost::next(cursor.row()));
1519 need_break_row = rows().end();
1523 // Just a macro to make some thing easier.
1524 void LyXText::redoParagraph()
1527 redoParagraphs(cursor, cursor.par()->next());
1528 setCursorIntern(cursor.par(), cursor.pos());
1532 // insert a character, moves all the following breaks in the
1533 // same Paragraph one to the right and make a rebreak
1534 void LyXText::insertChar(char c)
1536 setUndo(bv(), Undo::INSERT, &*cursor.par(), &*boost::next(cursor.par()));
1538 // When the free-spacing option is set for the current layout,
1539 // disable the double-space checking
1541 bool const freeSpacing = cursor.row()->par()->layout()->free_spacing ||
1542 cursor.row()->par()->isFreeSpacing();
1544 if (lyxrc.auto_number) {
1545 static string const number_operators = "+-/*";
1546 static string const number_unary_operators = "+-";
1547 static string const number_seperators = ".,:";
1549 if (current_font.number() == LyXFont::ON) {
1550 if (!IsDigit(c) && !contains(number_operators, c) &&
1551 !(contains(number_seperators, c) &&
1552 cursor.pos() >= 1 &&
1553 cursor.pos() < cursor.par()->size() &&
1554 getFont(bv()->buffer(),
1556 cursor.pos()).number() == LyXFont::ON &&
1557 getFont(bv()->buffer(),
1559 cursor.pos() - 1).number() == LyXFont::ON)
1561 number(bv()); // Set current_font.number to OFF
1562 } else if (IsDigit(c) &&
1563 real_current_font.isVisibleRightToLeft()) {
1564 number(bv()); // Set current_font.number to ON
1566 if (cursor.pos() > 0) {
1567 char const c = cursor.par()->getChar(cursor.pos() - 1);
1568 if (contains(number_unary_operators, c) &&
1569 (cursor.pos() == 1 ||
1570 cursor.par()->isSeparator(cursor.pos() - 2) ||
1571 cursor.par()->isNewline(cursor.pos() - 2))
1573 setCharFont(bv()->buffer(),
1577 } else if (contains(number_seperators, c) &&
1578 cursor.pos() >= 2 &&
1579 getFont(bv()->buffer(),
1581 cursor.pos() - 2).number() == LyXFont::ON) {
1582 setCharFont(bv()->buffer(),
1592 // First check, if there will be two blanks together or a blank at
1593 // the beginning of a paragraph.
1594 // I decided to handle blanks like normal characters, the main
1595 // difference are the special checks when calculating the row.fill
1596 // (blank does not count at the end of a row) and the check here
1598 // The bug is triggered when we type in a description environment:
1599 // The current_font is not changed when we go from label to main text
1600 // and it should (along with realtmpfont) when we type the space.
1601 // CHECK There is a bug here! (Asger)
1603 LyXFont realtmpfont = real_current_font;
1604 LyXFont rawtmpfont = current_font;
1605 // store the current font. This is because of the use of cursor
1606 // movements. The moving cursor would refresh the current font
1608 // Get the font that is used to calculate the baselineskip
1609 pos_type const lastpos = cursor.par()->size();
1610 LyXFont rawparfont =
1611 cursor.par()->getFontSettings(bv()->buffer()->params,
1614 bool jumped_over_space = false;
1616 if (!freeSpacing && IsLineSeparatorChar(c)) {
1617 if ((cursor.pos() > 0
1618 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1619 || (cursor.pos() > 0
1620 && cursor.par()->isNewline(cursor.pos() - 1))
1621 || (cursor.pos() == 0)) {
1622 static bool sent_space_message = false;
1623 if (!sent_space_message) {
1624 if (cursor.pos() == 0)
1625 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1627 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1628 sent_space_message = true;
1635 // the display inset stuff
1636 if (cursor.row()->pos() < cursor.row()->par()->size()
1637 && cursor.row()->par()->isInset(cursor.row()->pos())) {
1638 Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
1639 if (inset && (inset->display() || inset->needFullRow())) {
1640 // force a new break
1641 cursor.row()->fill(-1); // to force a new break
1645 // get the cursor row fist
1646 RowList::iterator row = cursor.row();
1647 int y = cursor.y() - row->baseline();
1648 if (c != Paragraph::META_INSET) {
1649 // Here case LyXText::InsertInset already insertet the character
1650 cursor.par()->insertChar(cursor.pos(), c);
1652 setCharFont(bv()->buffer(), &*cursor.par(), cursor.pos(), rawtmpfont);
1654 if (!jumped_over_space) {
1655 // refresh the positions
1656 RowList::iterator tmprow = row;
1657 while (boost::next(tmprow) != rows().end() &&
1658 boost::next(tmprow)->par() == row->par()) {
1660 tmprow->pos(tmprow->pos() + 1);
1664 // Is there a break one row above
1665 if (row != rows().begin() &&
1666 boost::prior(row)->par() == row->par()
1667 && (cursor.par()->isLineSeparator(cursor.pos())
1668 || cursor.par()->isNewline(cursor.pos())
1669 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1670 cursor.par()->isInset(cursor.pos() + 1))
1671 || cursor.row()->fill() == -1))
1673 pos_type z = rowBreakPoint(*boost::prior(row));
1675 if (z >= row->pos()) {
1678 // set the dimensions of the row above
1679 boost::prior(row)->fill(fill(
1683 setHeightOfRow(boost::prior(row));
1685 y -= boost::prior(row)->height();
1689 breakAgainOneRow(row);
1691 current_font = rawtmpfont;
1692 real_current_font = realtmpfont;
1693 setCursor(cursor.par(), cursor.pos() + 1,
1694 false, cursor.boundary());
1695 // cursor MUST be in row now.
1697 if (boost::next(row) != rows().end() &&
1698 boost::next(row)->par() == row->par())
1699 need_break_row = boost::next(row);
1701 need_break_row = rows().end();
1703 // check, wether the last characters font has changed.
1704 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1705 && rawparfont != rawtmpfont)
1706 redoHeightOfParagraph();
1713 // recalculate the fill of the row
1714 if (row->fill() >= 0) {
1715 // needed because a newline will set fill to -1. Otherwise
1716 // we would not get a rebreak!
1717 row->fill(fill(row, workWidth()));
1720 if (c == Paragraph::META_INSET || row->fill() < 0) {
1722 breakAgainOneRow(row);
1723 // will the cursor be in another row now?
1724 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1725 boost::next(row) != rows().end()) {
1726 if (boost::next(row) != rows().end() &&
1727 boost::next(row)->par() == row->par())
1728 // this should always be true
1730 breakAgainOneRow(row);
1732 current_font = rawtmpfont;
1733 real_current_font = realtmpfont;
1735 setCursor(cursor.par(), cursor.pos() + 1, false,
1737 if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
1738 != cursor.boundary())
1739 setCursor(cursor.par(), cursor.pos(), false,
1740 !cursor.boundary());
1741 if (boost::next(row) != rows().end() &&
1742 boost::next(row)->par() == row->par())
1743 need_break_row = boost::next(row);
1745 need_break_row = rows().end();
1747 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1748 int const tmpheight = row->height();
1750 setHeightOfRow(row);
1752 if (tmpheight == row->height()) {
1753 postRowPaint(row, y);
1758 current_font = rawtmpfont;
1759 real_current_font = realtmpfont;
1760 setCursor(cursor.par(), cursor.pos() + 1, false,
1764 // check, wether the last characters font has changed.
1765 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1766 && rawparfont != rawtmpfont) {
1767 redoHeightOfParagraph();
1769 // now the special right address boxes
1770 if (cursor.par()->layout()->margintype
1771 == MARGIN_RIGHT_ADDRESS_BOX) {
1772 redoDrawingOfParagraph(cursor);
1780 void LyXText::charInserted()
1782 // Here we could call FinishUndo for every 20 characters inserted.
1783 // This is from my experience how emacs does it.
1784 static unsigned int counter;
1794 void LyXText::prepareToPrint(RowList::iterator rit, float & x,
1795 float & fill_separator,
1797 float & fill_label_hfill,
1802 float w = rit->fill();
1804 fill_label_hfill = 0;
1806 fill_label_hfill = 0;
1809 rit->par()->isRightToLeftPar(bv()->buffer()->params);
1811 x = (workWidth() > 0)
1812 ? rightMargin(*bv()->buffer(), *rit) : 0;
1814 x = (workWidth() > 0)
1815 ? leftMargin(*rit) : 0;
1817 // is there a manual margin with a manual label
1818 LyXLayout_ptr const & layout = rit->par()->layout();
1820 if (layout->margintype == MARGIN_MANUAL
1821 && layout->labeltype == LABEL_MANUAL) {
1822 /// We might have real hfills in the label part
1823 nlh = numberOfLabelHfills(*this, rit);
1825 // A manual label par (e.g. List) has an auto-hfill
1826 // between the label text and the body of the
1828 // But we don't want to do this auto hfill if the par
1830 if (!rit->par()->empty())
1833 if (nlh && !rit->par()->getLabelWidthString().empty()) {
1834 fill_label_hfill = labelFill(*rit) / nlh;
1838 // are there any hfills in the row?
1839 float const nh = numberOfHfills(*this, rit);
1843 fill_hfill = w / nh;
1844 // we don't have to look at the alignment if it is ALIGN_LEFT and
1845 // if the row is already larger then the permitted width as then
1846 // we force the LEFT_ALIGN'edness!
1847 } else if (static_cast<int>(rit->width()) < workWidth()) {
1848 // is it block, flushleft or flushright?
1849 // set x how you need it
1851 if (rit->par()->params().align() == LYX_ALIGN_LAYOUT) {
1852 align = layout->align;
1854 align = rit->par()->params().align();
1857 // center displayed insets
1859 if (rit->pos() < rit->par()->size()
1860 && rit->par()->isInset(rit->pos())
1861 && (inset = rit->par()->getInset(rit->pos()))
1862 && (inset->display())) // || (inset->scroll() < 0)))
1863 align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
1864 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1865 // ERT insets should always be LEFT ALIGNED on screen
1866 inset = rit->par()->inInset();
1867 if (inset && inset->owner() &&
1868 inset->owner()->lyxCode() == Inset::ERT_CODE)
1870 align = LYX_ALIGN_LEFT;
1874 case LYX_ALIGN_BLOCK:
1876 float const ns = numberOfSeparators(*this, rit);
1877 RowList::iterator next_row = boost::next(rit);
1879 if (ns && next_row != rowlist_.end() &&
1880 next_row->par() == rit->par() &&
1881 !(next_row->par()->isNewline(next_row->pos() - 1))
1882 && !(next_row->par()->isInset(next_row->pos()) &&
1883 next_row->par()->getInset(next_row->pos()) &&
1884 next_row->par()->getInset(next_row->pos())->display())
1886 fill_separator = w / ns;
1887 } else if (is_rtl) {
1892 case LYX_ALIGN_RIGHT:
1895 case LYX_ALIGN_CENTER:
1903 computeBidiTables(bv()->buffer(), rit);
1905 pos_type body_pos = rit->par()->beginningOfBody();
1906 pos_type last = lastPos(*this, rit);
1909 (body_pos - 1 > last ||
1910 !rit->par()->isLineSeparator(body_pos - 1))) {
1911 x += font_metrics::width(layout->labelsep,
1912 getLabelFont(bv()->buffer(),
1914 if (body_pos - 1 <= last)
1915 x += fill_label_hfill;
1921 // important for the screen
1924 // the cursor set functions have a special mechanism. When they
1925 // realize, that you left an empty paragraph, they will delete it.
1926 // They also delete the corresponding row
1928 void LyXText::cursorRightOneWord()
1930 // treat floats, HFills and Insets as words
1931 LyXCursor tmpcursor = cursor;
1932 // CHECK See comment on top of text.C
1934 if (tmpcursor.pos() == tmpcursor.par()->size()
1935 && tmpcursor.par()->next()) {
1936 tmpcursor.par(tmpcursor.par()->next());
1941 // Skip through initial nonword stuff.
1942 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1943 ! tmpcursor.par()->isWord(tmpcursor.pos())) {
1944 // printf("Current pos1 %d", tmpcursor.pos()) ;
1945 tmpcursor.pos(tmpcursor.pos() + 1);
1948 // Advance through word.
1949 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1950 tmpcursor.par()->isWord(tmpcursor.pos())) {
1951 // printf("Current pos2 %d", tmpcursor.pos()) ;
1952 tmpcursor.pos(tmpcursor.pos() + 1);
1956 setCursor(tmpcursor.par(), tmpcursor.pos());
1960 // Skip initial whitespace at end of word and move cursor to *start*
1961 // of prior word, not to end of next prior word.
1962 void LyXText::cursorLeftOneWord()
1964 LyXCursor tmpcursor = cursor;
1965 cursorLeftOneWord(tmpcursor);
1966 setCursor(tmpcursor.par(), tmpcursor.pos());
1970 void LyXText::cursorLeftOneWord(LyXCursor & cur)
1972 // treat HFills, floats and Insets as words
1975 && (cur.par()->isSeparator(cur.pos() - 1)
1976 || cur.par()->isKomma(cur.pos() - 1)
1977 || cur.par()->isNewline(cur.pos() - 1))
1978 && !(cur.par()->isHfill(cur.pos() - 1)
1979 || cur.par()->isInset(cur.pos() - 1)))
1980 cur.pos(cur.pos() - 1);
1983 && (cur.par()->isInset(cur.pos() - 1)
1984 || cur.par()->isHfill(cur.pos() - 1))) {
1985 cur.pos(cur.pos() - 1);
1986 } else if (!cur.pos()) {
1987 if (cur.par()->previous()) {
1988 cur.par(cur.par()->previous());
1989 cur.pos(cur.par()->size());
1991 } else { // Here, cur != 0
1992 while (cur.pos() > 0 &&
1993 cur.par()->isWord(cur.pos() - 1))
1994 cur.pos(cur.pos() - 1);
1999 // Select current word. This depends on behaviour of
2000 // CursorLeftOneWord(), so it is patched as well.
2001 void LyXText::getWord(LyXCursor & from, LyXCursor & to,
2002 word_location const loc)
2004 // first put the cursor where we wana start to select the word
2007 case WHOLE_WORD_STRICT:
2008 if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
2009 || cursor.par()->isSeparator(cursor.pos())
2010 || cursor.par()->isKomma(cursor.pos())
2011 || cursor.par()->isNewline(cursor.pos())
2012 || cursor.par()->isSeparator(cursor.pos() - 1)
2013 || cursor.par()->isKomma(cursor.pos() - 1)
2014 || cursor.par()->isNewline(cursor.pos() - 1)) {
2018 // no break here, we go to the next
2021 // Move cursor to the beginning, when not already there.
2022 if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
2023 && !(from.par()->isKomma(from.pos() - 1)
2024 || from.par()->isNewline(from.pos() - 1)))
2025 cursorLeftOneWord(from);
2028 // always move the cursor to the beginning of previous word
2029 cursorLeftOneWord(from);
2032 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
2038 while (to.pos() < to.par()->size()
2039 && !to.par()->isSeparator(to.pos())
2040 && !to.par()->isKomma(to.pos())
2041 && !to.par()->isNewline(to.pos())
2042 && !to.par()->isHfill(to.pos())
2043 && !to.par()->isInset(to.pos()))
2045 to.pos(to.pos() + 1);
2050 void LyXText::selectWord(word_location loc)
2054 getWord(from, to, loc);
2056 setCursor(from.par(), from.pos());
2059 selection.cursor = cursor;
2060 setCursor(to.par(), to.pos());
2065 // Select the word currently under the cursor when no
2066 // selection is currently set
2067 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2069 if (!selection.set()) {
2071 return selection.set();
2077 void LyXText::acceptChange()
2079 if (!selection.set() && cursor.par()->size())
2084 if (selection.start.par() == selection.end.par()) {
2085 LyXCursor & startc = selection.start;
2086 LyXCursor & endc = selection.end;
2087 setUndo(bv(), Undo::INSERT, &*startc.par(), &*boost::next(startc.par()));
2088 startc.par()->acceptChange(startc.pos(), endc.pos());
2091 redoParagraphs(startc, startc.par()->next());
2092 setCursorIntern(startc.par(), 0);
2094 #warning handle multi par selection
2098 void LyXText::rejectChange()
2100 if (!selection.set() && cursor.par()->size())
2105 if (selection.start.par() == selection.end.par()) {
2106 LyXCursor & startc = selection.start;
2107 LyXCursor & endc = selection.end;
2108 setUndo(bv(), Undo::INSERT, &*startc.par(),
2109 &*boost::next(startc.par()));
2110 startc.par()->rejectChange(startc.pos(), endc.pos());
2113 redoParagraphs(startc, startc.par()->next());
2114 setCursorIntern(startc.par(), 0);
2116 #warning handle multi par selection
2120 // This function is only used by the spellchecker for NextWord().
2121 // It doesn't handle LYX_ACCENTs and probably never will.
2123 LyXText::selectNextWordToSpellcheck(float & value)
2125 if (the_locking_inset) {
2126 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2127 if (!word.word().empty()) {
2128 value += float(cursor.y());
2129 value /= float(height);
2132 // we have to go on checking so move cursor to the next char
2133 if (cursor.pos() == cursor.par()->size()) {
2134 if (!cursor.par()->next())
2136 cursor.par(cursor.par()->next());
2139 cursor.pos(cursor.pos() + 1);
2141 ParagraphList::iterator tmppit = cursor.par();
2143 // If this is not the very first word, skip rest of
2144 // current word because we are probably in the middle
2145 // of a word if there is text here.
2146 if (cursor.pos() || cursor.par()->previous()) {
2147 while (cursor.pos() < cursor.par()->size()
2148 && cursor.par()->isLetter(cursor.pos()))
2149 cursor.pos(cursor.pos() + 1);
2152 // Now, skip until we have real text (will jump paragraphs)
2154 ParagraphList::iterator cpit = cursor.par();
2155 pos_type const cpos(cursor.pos());
2157 if (cpos == cpit->size()) {
2158 if (boost::next(cpit) != ownerParagraphs().end()) {
2159 cursor.par(boost::next(cpit));
2166 bool const is_good_inset = cpit->isInset(cpos)
2167 && cpit->getInset(cpos)->allowSpellcheck();
2169 if (!isDeletedText(*cpit, cpos)
2170 && (is_good_inset || cpit->isLetter(cpos)))
2173 cursor.pos(cpos + 1);
2176 // now check if we hit an inset so it has to be a inset containing text!
2177 if (cursor.pos() < cursor.par()->size() &&
2178 cursor.par()->isInset(cursor.pos())) {
2180 cursor.par()->getInset(cursor.pos())->edit(bv());
2181 // now call us again to do the above trick
2182 // but obviously we have to start from down below ;)
2183 return bv()->text->selectNextWordToSpellcheck(value);
2186 // Update the value if we changed paragraphs
2187 if (cursor.par() != tmppit) {
2188 setCursor(cursor.par(), cursor.pos());
2189 value = float(cursor.y())/float(height);
2192 // Start the selection from here
2193 selection.cursor = cursor;
2196 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2197 .language()->code());
2198 // and find the end of the word (insets like optional hyphens
2199 // and ligature break are part of a word)
2200 while (cursor.pos() < cursor.par()->size()
2201 && cursor.par()->isLetter(cursor.pos())
2202 && !isDeletedText(*cursor.par(), cursor.pos()))
2203 cursor.pos(cursor.pos() + 1);
2205 // Finally, we copy the word to a string and return it
2207 if (selection.cursor.pos() < cursor.pos()) {
2209 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2210 if (!cursor.par()->isInset(i))
2211 str += cursor.par()->getChar(i);
2214 return WordLangTuple(str, lang_code);
2218 // This one is also only for the spellchecker
2219 void LyXText::selectSelectedWord()
2221 if (the_locking_inset) {
2222 the_locking_inset->selectSelectedWord(bv());
2225 // move cursor to the beginning
2226 setCursor(selection.cursor.par(), selection.cursor.pos());
2228 // set the sel cursor
2229 selection.cursor = cursor;
2231 // now find the end of the word
2232 while (cursor.pos() < cursor.par()->size()
2233 && (cursor.par()->isLetter(cursor.pos())))
2234 cursor.pos(cursor.pos() + 1);
2236 setCursor(cursor.par(), cursor.pos());
2238 // finally set the selection
2243 // Delete from cursor up to the end of the current or next word.
2244 void LyXText::deleteWordForward()
2246 if (cursor.par()->empty())
2249 LyXCursor tmpcursor = cursor;
2250 tmpcursor.row(0); //Â ??
2251 selection.set(true); // to avoid deletion
2252 cursorRightOneWord();
2253 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2254 selection.cursor = cursor;
2258 // Great, CutSelection() gets rid of multiple spaces.
2259 cutSelection(true, false);
2264 // Delete from cursor to start of current or prior word.
2265 void LyXText::deleteWordBackward()
2267 if (cursor.par()->empty())
2270 LyXCursor tmpcursor = cursor;
2271 tmpcursor.row(0); // ??
2272 selection.set(true); // to avoid deletion
2273 cursorLeftOneWord();
2274 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2275 selection.cursor = cursor;
2278 cutSelection(true, false);
2283 // Kill to end of line.
2284 void LyXText::deleteLineForward()
2286 if (cursor.par()->empty())
2287 // Paragraph is empty, so we just go to the right
2290 LyXCursor tmpcursor = cursor;
2291 // We can't store the row over a regular setCursor
2292 // so we set it to 0 and reset it afterwards.
2293 tmpcursor.row(0); //Â ??
2294 selection.set(true); // to avoid deletion
2296 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2297 selection.cursor = cursor;
2300 // What is this test for ??? (JMarc)
2301 if (!selection.set()) {
2302 deleteWordForward();
2304 cutSelection(true, false);
2310 void LyXText::changeCase(LyXText::TextCase action)
2315 if (selection.set()) {
2316 from = selection.start;
2319 getWord(from, to, PARTIAL_WORD);
2320 setCursor(to.par(), to.pos() + 1);
2323 lyx::Assert(from <= to);
2325 setUndo(bv(), Undo::FINISH, &*from.par(), &*boost::next(to.par()));
2327 pos_type pos = from.pos();
2328 ParagraphList::iterator pit = from.par();
2330 while (pit != ownerParagraphs().end() &&
2331 (pos != to.pos() || pit != to.par())) {
2332 if (pos == pit->size()) {
2337 unsigned char c = pit->getChar(pos);
2338 if (!IsInsetChar(c)) {
2340 case text_lowercase:
2343 case text_capitalization:
2345 action = text_lowercase;
2347 case text_uppercase:
2353 pit->setChar(pos, c);
2354 checkParagraph(&*pit, pos);
2359 if (to.row() != from.row())
2360 postPaint(from.y() - from.row()->baseline());
2364 void LyXText::Delete()
2366 // this is a very easy implementation
2368 LyXCursor old_cursor = cursor;
2369 int const old_cur_par_id = old_cursor.par()->id();
2370 int const old_cur_par_prev_id = old_cursor.par()->previous() ?
2371 old_cursor.par()->previous()->id() : -1;
2373 // just move to the right
2376 // CHECK Look at the comment here.
2377 // This check is not very good...
2378 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2379 // and that can very well delete the par or par->previous in
2380 // old_cursor. Will a solution where we compare paragraph id's
2382 if ((cursor.par()->previous() ? cursor.par()->previous()->id() : -1)
2383 == old_cur_par_prev_id
2384 && cursor.par()->id() != old_cur_par_id) {
2385 // delete-empty-paragraph-mechanism has done it
2389 // if you had success make a backspace
2390 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2391 LyXCursor tmpcursor = cursor;
2392 // to make sure undo gets the right cursor position
2393 cursor = old_cursor;
2394 setUndo(bv(), Undo::DELETE,
2395 &*cursor.par(), &*boost::next(cursor.par()));
2402 void LyXText::backspace()
2404 // Get the font that is used to calculate the baselineskip
2405 pos_type lastpos = cursor.par()->size();
2406 LyXFont rawparfont =
2407 cursor.par()->getFontSettings(bv()->buffer()->params,
2410 if (cursor.pos() == 0) {
2411 // The cursor is at the beginning of a paragraph,
2412 // so the the backspace will collapse two paragraphs into one.
2414 // but it's not allowed unless it's new
2415 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2418 // we may paste some paragraphs
2420 // is it an empty paragraph?
2423 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2424 // This is an empty paragraph and we delete it just by moving the cursor one step
2425 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2426 // of the paragraph.
2428 if (cursor.par()->previous()) {
2429 Paragraph * tmppar = cursor.par()->previous();
2430 if (cursor.par()->layout() == tmppar->layout()
2431 && cursor.par()->getAlign() == tmppar->getAlign()) {
2432 // Inherit bottom DTD from the paragraph below.
2433 // (the one we are deleting)
2434 tmppar->params().lineBottom(cursor.par()->params().lineBottom());
2435 tmppar->params().spaceBottom(cursor.par()->params().spaceBottom());
2436 tmppar->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2441 // the layout things can change the height of a row !
2442 int const tmpheight = cursor.row()->height();
2443 setHeightOfRow(cursor.row());
2444 if (cursor.row()->height() != tmpheight) {
2445 postPaint(cursor.y() - cursor.row()->baseline());
2451 if (cursor.par()->previous()) {
2452 setUndo(bv(), Undo::DELETE,
2453 cursor.par()->previous(), cursor.par()->next());
2456 ParagraphList::iterator tmppit = cursor.par();
2457 RowList::iterator tmprow = cursor.row();
2459 // We used to do cursorLeftIntern() here, but it is
2460 // not a good idea since it triggers the auto-delete
2461 // mechanism. So we do a cursorLeftIntern()-lite,
2462 // without the dreaded mechanism. (JMarc)
2463 if (cursor.par() != ownerParagraphs().begin()) {
2464 // steps into the above paragraph.
2465 setCursorIntern(boost::prior(cursor.par()),
2466 boost::prior(cursor.par())->size(),
2470 // Pasting is not allowed, if the paragraphs have different
2471 // layout. I think it is a real bug of all other
2472 // word processors to allow it. It confuses the user.
2473 // Even so with a footnote paragraph and a non-footnote
2474 // paragraph. I will not allow pasting in this case,
2475 // because the user would be confused if the footnote behaves
2476 // different wether it is open or closed.
2478 // Correction: Pasting is always allowed with standard-layout
2479 LyXTextClass const & tclass =
2480 bv()->buffer()->params.getLyXTextClass();
2482 if (cursor.par() != tmppit
2483 && (cursor.par()->layout() == tmppit->layout()
2484 || tmppit->layout() == tclass.defaultLayout())
2485 && cursor.par()->getAlign() == tmppit->getAlign()) {
2486 removeParagraph(tmprow);
2488 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2490 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2491 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2492 // strangely enough it seems that commenting out the line above removes
2493 // most or all of the segfaults. I will however also try to move the
2494 // two Remove... lines in front of the PasteParagraph too.
2497 cursor.pos(cursor.pos() - 1);
2499 postPaint(cursor.y() - cursor.row()->baseline());
2501 // remove the lost paragraph
2502 // This one is not safe, since the paragraph that the tmprow and the
2503 // following rows belong to has been deleted by the PasteParagraph
2504 // above. The question is... could this be moved in front of the
2506 //RemoveParagraph(tmprow);
2507 //RemoveRow(tmprow);
2509 // This rebuilds the rows.
2510 appendParagraph(cursor.row());
2513 // the row may have changed, block, hfills etc.
2514 setCursor(cursor.par(), cursor.pos(), false);
2517 // this is the code for a normal backspace, not pasting
2519 setUndo(bv(), Undo::DELETE,
2520 &*cursor.par(), &*boost::next(cursor.par()));
2521 // We used to do cursorLeftIntern() here, but it is
2522 // not a good idea since it triggers the auto-delete
2523 // mechanism. So we do a cursorLeftIntern()-lite,
2524 // without the dreaded mechanism. (JMarc)
2525 setCursorIntern(cursor.par(), cursor.pos()- 1,
2526 false, cursor.boundary());
2528 if (cursor.par()->isInset(cursor.pos())) {
2529 // force complete redo when erasing display insets
2530 // this is a cruel method but safe..... Matthias
2531 if (cursor.par()->getInset(cursor.pos())->display() ||
2532 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2533 cursor.par()->erase(cursor.pos());
2539 RowList::iterator row = cursor.row();
2540 int y = cursor.y() - row->baseline();
2542 // remember that a space at the end of a row doesnt count
2543 // when calculating the fill
2544 if (cursor.pos() < lastPos(*this, row) ||
2545 !cursor.par()->isLineSeparator(cursor.pos())) {
2546 row->fill(row->fill() + singleWidth(
2551 // some special code when deleting a newline. This is similar
2552 // to the behavior when pasting paragraphs
2553 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2554 cursor.par()->erase(cursor.pos());
2555 // refresh the positions
2556 RowList::iterator tmprow = row;
2557 while (boost::next(tmprow) != rows().end() &&
2558 boost::next(tmprow)->par() == row->par()) {
2560 tmprow->pos(tmprow->pos() - 1);
2562 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2563 cursor.pos(cursor.pos() - 1);
2565 if (cursor.pos() < cursor.par()->size()
2566 && !cursor.par()->isSeparator(cursor.pos())) {
2567 cursor.par()->insertChar(cursor.pos(), ' ');
2568 setCharFont(bv()->buffer(), &*cursor.par(),
2569 cursor.pos(), current_font);
2570 // refresh the positions
2572 while (boost::next(tmprow) != rows().end() &&
2573 boost::next(tmprow)->par() == row->par()) {
2575 tmprow->pos(tmprow->pos() + 1);
2579 cursor.par()->erase(cursor.pos());
2581 // refresh the positions
2582 RowList::iterator tmprow = row;
2583 while (boost::next(tmprow) != rows().end() &&
2584 boost::next(tmprow)->par() == row->par()) {
2586 tmprow->pos(tmprow->pos() - 1);
2589 // delete newlines at the beginning of paragraphs
2590 while (!cursor.par()->empty() &&
2591 cursor.pos() < cursor.par()->size() &&
2592 cursor.par()->isNewline(cursor.pos()) &&
2593 cursor.pos() == cursor.par()->beginningOfBody()) {
2594 cursor.par()->erase(cursor.pos());
2595 // refresh the positions
2597 while (boost::next(tmprow) != rows().end() &&
2598 boost::next(tmprow)->par() == row->par()) {
2600 tmprow->pos(tmprow->pos() - 1);
2605 // is there a break one row above
2606 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2607 z = rowBreakPoint(*boost::prior(row));
2608 if (z >= row->pos()) {
2611 RowList::iterator tmprow = boost::prior(row);
2613 // maybe the current row is now empty
2614 if (row->pos() >= row->par()->size()) {
2617 need_break_row = rows().end();
2619 breakAgainOneRow(row);
2620 if (boost::next(row) != rows().end() &&
2621 boost::next(row)->par() == row->par())
2622 need_break_row = boost::next(row);
2624 need_break_row = rows().end();
2627 // set the dimensions of the row above
2628 y -= tmprow->height();
2629 tmprow->fill(fill(tmprow, workWidth()));
2630 setHeightOfRow(tmprow);
2634 setCursor(cursor.par(), cursor.pos(),
2635 false, cursor.boundary());
2636 //current_font = rawtmpfont;
2637 //real_current_font = realtmpfont;
2638 // check, whether the last character's font has changed.
2640 cursor.par()->getFontSettings(bv()->buffer()->params,
2641 cursor.par()->size() - 1))
2642 redoHeightOfParagraph();
2647 // break the cursor row again
2648 if (boost::next(row) != rows().end() &&
2649 boost::next(row)->par() == row->par() &&
2650 (lastPos(*this, row) == row->par()->size() - 1 ||
2651 rowBreakPoint(*row) != lastPos(*this, row))) {
2653 // it can happen that a paragraph loses one row
2654 // without a real breakup. This is when a word
2655 // is to long to be broken. Well, I don t care this
2657 if (lastPos(*this, row) == row->par()->size() - 1)
2658 removeRow(boost::next(row));
2662 breakAgainOneRow(row);
2663 // will the cursor be in another row now?
2664 if (boost::next(row) != rows().end() &&
2665 boost::next(row)->par() == row->par() &&
2666 lastPos(*this, row) <= cursor.pos()) {
2668 breakAgainOneRow(row);
2671 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2673 if (boost::next(row) != rows().end() &&
2674 boost::next(row)->par() == row->par())
2675 need_break_row = boost::next(row);
2677 need_break_row = rows().end();
2679 // set the dimensions of the row
2680 row->fill(fill(row, workWidth()));
2681 int const tmpheight = row->height();
2682 setHeightOfRow(row);
2683 if (tmpheight == row->height()) {
2684 postRowPaint(row, y);
2688 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2692 // current_font = rawtmpfont;
2693 // real_current_font = realtmpfont;
2695 if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
2696 != cursor.boundary())
2697 setCursor(cursor.par(), cursor.pos(), false,
2698 !cursor.boundary());
2700 lastpos = cursor.par()->size();
2701 if (cursor.pos() == lastpos)
2704 // check, whether the last characters font has changed.
2706 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2707 redoHeightOfParagraph();
2709 // now the special right address boxes
2710 if (cursor.par()->layout()->margintype
2711 == MARGIN_RIGHT_ADDRESS_BOX) {
2712 redoDrawingOfParagraph(cursor);
2718 // returns pointer to a specified row
2720 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2725 return rowlist_.end();
2727 // find the first row of the specified paragraph
2728 RowList::iterator rit = rowlist_.begin();
2729 RowList::iterator end = rowlist_.end();
2730 while (boost::next(rit) != end && rit->par() != pit) {
2735 // now find the wanted row
2736 while (rit->pos() < pos
2737 && boost::next(rit) != end
2738 && boost::next(rit)->par() == pit
2739 && boost::next(rit)->pos() <= pos) {
2748 RowList::iterator LyXText::getRowNearY(int & y) const
2750 // If possible we should optimize this method. (Lgb)
2753 RowList::iterator rit = rowlist_.begin();
2754 RowList::iterator end = rowlist_.end();
2756 while (rit != end &&
2757 boost::next(rit) != end &&
2758 tmpy + rit->height() <= y) {
2759 tmpy += rit->height();
2763 // return the real y
2770 int LyXText::getDepth() const
2772 return cursor.par()->getDepth();