1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
15 #include "paragraph.h"
17 #include "bufferparams.h"
23 #include "frontends/LyXView.h"
24 #include "frontends/Painter.h"
25 #include "frontends/font_metrics.h"
26 #include "frontends/screen.h"
27 #include "frontends/WorkArea.h"
28 #include "bufferview_funcs.h"
29 #include "BufferView.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "WordLangTuple.h"
34 #include "paragraph_funcs.h"
35 #include "rowpainter.h"
36 #include "lyxrow_funcs.h"
38 #include "insets/insettext.h"
40 #include "support/textutils.h"
41 #include "support/LAssert.h"
42 #include "support/lstrings.h"
51 using namespace bv_funcs;
53 /// top, right, bottom pixel margin
54 extern int const PAPER_MARGIN = 20;
55 /// margin for changebar
56 extern int const CHANGEBAR_MARGIN = 10;
58 extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
60 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
63 BufferView * LyXText::bv()
65 lyx::Assert(bv_owner != 0);
70 BufferView * LyXText::bv() const
72 lyx::Assert(bv_owner != 0);
77 void LyXText::updateRowPositions()
79 RowList::iterator rit = rows().begin();
80 RowList::iterator rend = rows().end();
81 for (int y = 0; rit != rend ; ++rit) {
88 int LyXText::top_y() const
90 if (isInInset() || anchor_row_ == rowlist_.end() )
92 return anchor_row_->y() + anchor_row_offset_;
96 void LyXText::top_y(int newy)
98 if (rows().empty() || isInInset())
100 lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
103 RowList::iterator rit = getRowNearY(y);
105 if (rit == anchor_row_ && anchor_row_offset_ == newy - y) {
106 lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
111 anchor_row_offset_ = newy - y;
112 lyxerr[Debug::GUI] << "changing reference to row: " << &*anchor_row_
113 << " offset: " << anchor_row_offset_ << endl;
118 void LyXText::anchor_row(RowList::iterator rit)
121 anchor_row_offset_ = 0;
123 anchor_row_offset_ = old_y - top_y();
124 lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
125 << &*anchor_row_ << " offset: "
126 << anchor_row_offset_ << endl;
130 int LyXText::workWidth() const
133 // FIXME: pass (const ?) ref
134 return inset_owner->textWidth(bv());
136 return bv()->workWidth();
140 int LyXText::workWidth(Inset * inset) const
142 Paragraph * par = inset->parOwner();
145 pos_type pos = par->getPositionOfInset(inset);
146 lyx::Assert(pos != -1);
148 LyXLayout_ptr const & layout = par->layout();
150 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
151 // Optimization here: in most cases, the real row is
152 // not needed, but only the par/pos values. So we just
153 // construct a dummy row for leftMargin. (JMarc)
157 return workWidth() - leftMargin(dummyrow);
160 RowList::iterator row = getRow(par, pos, dummy_y);
161 RowList::iterator frow = row;
162 RowList::iterator beg = rowlist_.begin();
164 while (frow != beg && frow->par() == boost::prior(frow)->par())
167 // FIXME: I don't understand this code - jbl
169 unsigned int maxw = 0;
170 while (!isParEnd(*this, frow)) {
171 if ((frow != row) && (maxw < frow->width()))
172 maxw = frow->width();
183 int LyXText::getRealCursorX() const
186 if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
187 x = the_locking_inset->getLyXText(bv())->getRealCursorX();
192 #warning FIXME This function seems to belong outside of LyxText.
193 unsigned char LyXText::transformChar(unsigned char c, Paragraph const & par,
196 if (!Encodings::is_arabic(c))
197 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
198 return c + (0xb0 - '0');
202 unsigned char const prev_char = pos > 0 ? par.getChar(pos - 1) : ' ';
203 unsigned char next_char = ' ';
205 pos_type const par_size = par.size();
207 for (pos_type i = pos + 1; i < par_size; ++i) {
208 unsigned char const par_char = par.getChar(i);
209 if (!Encodings::IsComposeChar_arabic(par_char)) {
210 next_char = par_char;
215 if (Encodings::is_arabic(next_char)) {
216 if (Encodings::is_arabic(prev_char) &&
217 !Encodings::is_arabic_special(prev_char))
218 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
220 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
222 if (Encodings::is_arabic(prev_char) &&
223 !Encodings::is_arabic_special(prev_char))
224 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
226 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
230 // This is the comments that some of the warnings below refers to.
231 // There are some issues in this file and I don't think they are
232 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
233 // this is a problem that has been here almost from day one and that a
234 // larger userbase with differenct access patters triggers the bad
235 // behaviour. (segfaults.) What I think happen is: In several places
236 // we store the paragraph in the current cursor and then moves the
237 // cursor. This movement of the cursor will delete paragraph at the
238 // old position if it is now empty. This will make the temporary
239 // pointer to the old cursor paragraph invalid and dangerous to use.
240 // And is some cases this will trigger a segfault. I have marked some
241 // of the cases where this happens with a warning, but I am sure there
242 // are others in this file and in text2.C. There is also a note in
243 // Delete() that you should read. In Delete I store the paragraph->id
244 // instead of a pointer to the paragraph. I am pretty sure this faulty
245 // use of temporary pointers to paragraphs that might have gotten
246 // invalidated (through a cursor movement) before they are used, are
247 // the cause of the strange crashes we get reported often.
249 // It is very tiresom to change this code, especially when it is as
250 // hard to read as it is. Help to fix all the cases where this is done
251 // would be greately appreciated.
255 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
257 if (pos >= pit->size())
260 char const c = pit->getChar(pos);
261 return singleWidth(pit, pos, c);
265 int LyXText::singleWidth(ParagraphList::iterator pit,
266 pos_type pos, char c) const
268 if (pos >= pit->size())
271 LyXFont const font = getFont(bv()->buffer(), pit, pos);
273 // The most common case is handled first (Asger)
274 if (IsPrintable(c)) {
275 if (font.language()->RightToLeft()) {
276 if (font.language()->lang() == "arabic" &&
277 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
278 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
279 if (Encodings::IsComposeChar_arabic(c))
282 c = transformChar(c, *pit, pos);
283 } else if (font.language()->lang() == "hebrew" &&
284 Encodings::IsComposeChar_hebrew(c))
287 return font_metrics::width(c, font);
291 if (c == Paragraph::META_INSET) {
292 Inset * tmpinset = pit->getInset(pos);
294 if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
295 // Because of the representation as vertical lines
299 #warning inset->update FIXME
300 // this IS needed otherwise on initialitation we don't get the fill
301 // of the row right (ONLY on initialization if we read a file!)
302 // should be changed! (Jug 20011204)
303 tmpinset->update(bv());
305 return tmpinset->width(bv(), font);
310 if (IsSeparatorChar(c))
312 return font_metrics::width(c, font);
316 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
318 if (bidi_start == -1)
321 return log2vis_list[pos - bidi_start];
325 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
327 if (bidi_start == -1)
330 return vis2log_list[pos - bidi_start];
334 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
336 if (bidi_start == -1)
339 return bidi_levels[pos - bidi_start];
343 bool LyXText::bidi_InRange(lyx::pos_type pos) const
345 return bidi_start == -1 ||
346 (bidi_start <= pos && pos <= bidi_end);
350 void LyXText::computeBidiTables(Buffer const * buf,
351 RowList::iterator row) const
353 bidi_same_direction = true;
354 if (!lyxrc.rtl_support) {
359 ParagraphList::iterator row_par = row->par();
361 Inset * inset = row_par->inInset();
362 if (inset && inset->owner() &&
363 inset->owner()->lyxCode() == Inset::ERT_CODE) {
368 bidi_start = row->pos();
369 bidi_end = lastPrintablePos(*this, row);
371 if (bidi_start > bidi_end) {
376 if (bidi_end + 2 - bidi_start >
377 static_cast<pos_type>(log2vis_list.size())) {
379 (bidi_end + 2 - bidi_start < 500) ?
380 500 : 2 * (bidi_end + 2 - bidi_start);
381 log2vis_list.resize(new_size);
382 vis2log_list.resize(new_size);
383 bidi_levels.resize(new_size);
386 vis2log_list[bidi_end + 1 - bidi_start] = -1;
387 log2vis_list[bidi_end + 1 - bidi_start] = -1;
391 row_par->isRightToLeftPar(buf->params);
395 pos_type const body_pos = row_par->beginningOfBody();
397 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
398 bool is_space = row_par->isLineSeparator(lpos);
400 (is_space && lpos + 1 <= bidi_end &&
401 !row_par->isLineSeparator(lpos + 1) &&
402 !row_par->isNewline(lpos + 1))
404 LyXFont font = row_par->getFontSettings(buf->params, pos);
405 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
406 font.number() == LyXFont::ON &&
407 row_par->getFontSettings(buf->params, lpos - 1).number()
409 font = row_par->getFontSettings(buf->params, lpos);
414 bool new_rtl = font.isVisibleRightToLeft();
415 bool new_rtl0 = font.isRightToLeft();
418 if (lpos == body_pos - 1
419 && row->pos() < body_pos - 1
421 new_level = (rtl_par) ? 1 : 0;
422 new_rtl = new_rtl0 = rtl_par;
424 new_level = (new_rtl) ? 1 : 2;
426 new_level = (rtl_par) ? 2 : 0;
428 if (is_space && new_level >= level) {
434 int new_level2 = new_level;
436 if (level == new_level && rtl0 != new_rtl0) {
438 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
439 } else if (level < new_level) {
440 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
441 if (new_level > rtl_par)
442 bidi_same_direction = false;
444 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
447 bidi_levels[lpos - bidi_start] = new_level;
449 while (level > new_level2) {
450 pos_type old_lpos = stack[--level];
451 int delta = lpos - old_lpos - 1;
454 log2vis_list[lpos - bidi_start] += delta;
455 log2vis_list[old_lpos - bidi_start] += delta;
457 while (level < new_level)
458 stack[level++] = lpos;
462 pos_type const old_lpos = stack[--level];
463 int delta = bidi_end - old_lpos;
466 log2vis_list[old_lpos - bidi_start] += delta;
469 pos_type vpos = bidi_start - 1;
470 for (pos_type lpos = bidi_start;
471 lpos <= bidi_end; ++lpos) {
472 vpos += log2vis_list[lpos - bidi_start];
473 vis2log_list[vpos - bidi_start] = lpos;
474 log2vis_list[lpos - bidi_start] = vpos;
479 // This method requires a previous call to ComputeBidiTables()
480 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
483 if (!lyxrc.rtl_support || pos == 0)
486 if (!bidi_InRange(pos - 1)) {
487 /// This can happen if pos is the first char of a row.
488 /// Returning false in this case is incorrect!
492 bool const rtl = bidi_level(pos - 1) % 2;
493 bool const rtl2 = bidi_InRange(pos)
494 ? bidi_level(pos) % 2
495 : par.isRightToLeftPar(buf->params);
500 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
501 pos_type pos, LyXFont const & font) const
503 if (!lyxrc.rtl_support)
504 return false; // This is just for speedup
506 bool const rtl = font.isVisibleRightToLeft();
507 bool const rtl2 = bidi_InRange(pos)
508 ? bidi_level(pos) % 2
509 : par.isRightToLeftPar(buf->params);
514 int LyXText::leftMargin(Row const & row) const
518 if (row.pos() < row.par()->size())
519 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
520 (ins = row.par()->getInset(row.pos())) &&
521 (ins->needFullRow() || ins->display()))
524 LyXTextClass const & tclass =
525 bv()->buffer()->params.getLyXTextClass();
526 LyXLayout_ptr const & layout = row.par()->layout();
528 string parindent = layout->parindent;
532 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
534 // this is the way, LyX handles the LaTeX-Environments.
535 // I have had this idea very late, so it seems to be a
536 // later added hack and this is true
537 if (!row.par()->getDepth()) {
538 if (row.par()->layout() == tclass.defaultLayout()) {
539 // find the previous same level paragraph
540 if (row.par() != ownerParagraphs().begin()) {
541 ParagraphList::iterator newpit =
542 depthHook(row.par(), ownerParagraphs(),
543 row.par()->getDepth());
544 if (newpit == row.par() &&
545 newpit->layout()->nextnoindent)
550 // find the next level paragraph
552 ParagraphList::iterator newpar = outerHook(row.par(),
555 // make a corresponding row. Needed to call leftMargin()
557 // check wether it is a sufficent paragraph
558 if (newpar != ownerParagraphs().end() &&
559 newpar->layout()->isEnvironment()) {
561 dummyrow.par(newpar);
562 dummyrow.pos(newpar->size());
563 x = leftMargin(dummyrow);
566 if (newpar != ownerParagraphs().end() &&
567 row.par()->layout() == tclass.defaultLayout()) {
568 if (newpar->params().noindent())
571 parindent = newpar->layout()->parindent;
577 LyXFont const labelfont = getLabelFont(bv()->buffer(), row.par());
578 switch (layout->margintype) {
580 if (!layout->leftmargin.empty()) {
581 x += font_metrics::signedWidth(layout->leftmargin,
582 tclass.defaultfont());
584 if (!row.par()->getLabelstring().empty()) {
585 x += font_metrics::signedWidth(layout->labelindent,
587 x += font_metrics::width(row.par()->getLabelstring(),
589 x += font_metrics::width(layout->labelsep, labelfont);
593 x += font_metrics::signedWidth(layout->labelindent, labelfont);
594 // The width of an empty par, even with manual label, should be 0
595 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
596 if (!row.par()->getLabelWidthString().empty()) {
597 x += font_metrics::width(row.par()->getLabelWidthString(),
599 x += font_metrics::width(layout->labelsep, labelfont);
604 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
605 / (row.par()->getDepth() + 4);
607 case MARGIN_FIRST_DYNAMIC:
608 if (layout->labeltype == LABEL_MANUAL) {
609 if (row.pos() >= row.par()->beginningOfBody()) {
610 x += font_metrics::signedWidth(layout->leftmargin,
613 x += font_metrics::signedWidth(layout->labelindent,
617 // Special case to fix problems with
619 || (layout->labeltype == LABEL_STATIC
620 && layout->latextype == LATEX_ENVIRONMENT
621 && !isFirstInSequence(row.par(), ownerParagraphs()))) {
622 x += font_metrics::signedWidth(layout->leftmargin,
624 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
625 && layout->labeltype != LABEL_BIBLIO
626 && layout->labeltype !=
627 LABEL_CENTERED_TOP_ENVIRONMENT) {
628 x += font_metrics::signedWidth(layout->labelindent,
630 x += font_metrics::width(layout->labelsep, labelfont);
631 x += font_metrics::width(row.par()->getLabelstring(),
636 case MARGIN_RIGHT_ADDRESS_BOX:
638 // ok, a terrible hack. The left margin depends on the widest
639 // row in this paragraph. Do not care about footnotes, they
640 // are *NOT* allowed in the LaTeX realisation of this layout.
642 // find the first row of this paragraph
643 RowList::iterator tmprit = rowlist_.begin();
644 while (tmprit != rowlist_.end()
645 && tmprit->par() != row.par())
648 int minfill = tmprit->fill();
649 while (boost::next(tmprit) != rowlist_.end() &&
650 boost::next(tmprit)->par() == row.par()) {
652 if (tmprit->fill() < minfill)
653 minfill = tmprit->fill();
656 x += font_metrics::signedWidth(layout->leftmargin,
657 tclass.defaultfont());
663 if ((workWidth() > 0) &&
664 !row.par()->params().leftIndent().zero())
666 LyXLength const len = row.par()->params().leftIndent();
667 int const tw = inset_owner ?
668 inset_owner->latexTextWidth(bv()) : workWidth();
669 x += len.inPixels(tw);
674 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
675 align = layout->align;
677 align = row.par()->params().align();
679 // set the correct parindent
680 if (row.pos() == 0) {
681 if ((layout->labeltype == LABEL_NO_LABEL
682 || layout->labeltype == LABEL_TOP_ENVIRONMENT
683 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
684 || (layout->labeltype == LABEL_STATIC
685 && layout->latextype == LATEX_ENVIRONMENT
686 && !isFirstInSequence(row.par(), ownerParagraphs())))
687 && align == LYX_ALIGN_BLOCK
688 && !row.par()->params().noindent()
689 // in tabulars and ert paragraphs are never indented!
690 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
691 (row.par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
692 row.par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
693 && (row.par()->layout() != tclass.defaultLayout() ||
694 bv()->buffer()->params.paragraph_separation ==
695 BufferParams::PARSEP_INDENT)) {
696 x += font_metrics::signedWidth(parindent,
697 tclass.defaultfont());
698 } else if (layout->labeltype == LABEL_BIBLIO) {
699 // ale970405 Right width for bibitems
700 x += bibitemMaxWidth(bv(), tclass.defaultfont());
708 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
712 if (row.pos() < row.par()->size())
713 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
714 (ins = row.par()->getInset(row.pos())) &&
715 (ins->needFullRow() || ins->display()))
718 LyXTextClass const & tclass = buf.params.getLyXTextClass();
719 LyXLayout_ptr const & layout = row.par()->layout();
722 + font_metrics::signedWidth(tclass.rightmargin(),
723 tclass.defaultfont());
725 x += font_metrics::signedWidth(layout->rightmargin,
726 tclass.defaultfont())
727 * 4 / (row.par()->getDepth() + 4);
732 int LyXText::labelEnd(Row const & row) const
734 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
736 tmprow.pos(row.par()->size());
737 // return the beginning of the body
738 return leftMargin(tmprow);
741 // LabelEnd is only needed if the layout
742 // fills a flushleft label.
749 // this needs special handling - only newlines count as a break point
750 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
752 for (; i < par.size(); ++i) {
753 if (par.isNewline(i))
764 LyXText::rowBreakPoint(Row const & row) const
766 ParagraphList::iterator pit = row.par();
768 // maximum pixel width of a row.
769 int width = workWidth() - rightMargin(*bv()->buffer(), row);
771 // inset->textWidth() returns -1 via workWidth(),
776 LyXLayout_ptr const & layout = pit->layout();
778 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
779 return addressBreakPoint(row.pos(), *pit);
781 pos_type const pos = row.pos();
782 pos_type const body_pos = pit->beginningOfBody();
783 pos_type const last = pit->size();
784 pos_type point = last;
789 // Now we iterate through until we reach the right margin
790 // or the end of the par, then choose the possible break
793 int const left = leftMargin(const_cast<Row&>(row));
796 // pixel width since last breakpoint
798 bool fullrow = false;
801 for (; i < last; ++i) {
802 if (pit->isNewline(i)) {
807 char const c = pit->getChar(i);
811 // add the auto-hfill from label end to the body
812 if (body_pos && i == body_pos) {
813 thiswidth = font_metrics::width(layout->labelsep,
814 getLabelFont(bv()->buffer(), pit));
815 if (pit->isLineSeparator(i - 1))
816 thiswidth -= singleWidth(pit, i - 1);
817 int left_margin = labelEnd(row);
818 if (thiswidth + x < left_margin)
819 thiswidth = left_margin - x;
820 thiswidth += singleWidth(pit, i, c);
822 thiswidth = singleWidth(pit, i, c);
826 chunkwidth += thiswidth;
828 Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
829 fullrow = (in && (in->display() || in->needFullRow()));
831 // break before a character that will fall off
832 // the right of the row
834 // if no break before or we are at an inset
835 // that will take up a row, break here
836 if (point == last || fullrow || chunkwidth >= (width - left)) {
845 if (!in || in->isChar()) {
846 // some insets are line separators too
847 if (pit->isLineSeparator(i)) {
857 // full row insets start at a new row
859 if (pos < last - 1) {
861 if (pit->isLineSeparator(i + 1))
864 // to avoid extra rows
874 if (point == last && x >= width) {
875 // didn't find one, break at the point we reached the edge
877 } else if (i == last && x < width) {
878 // found one, but we fell off the end of the par, so prefer
883 // manual labels cannot be broken in LaTeX. But we
884 // want to make our on-screen rendering of footnotes
886 if (!fullrow && body_pos && point < body_pos)
887 point = body_pos - 1;
893 // returns the minimum space a row needs on the screen in pixel
894 int LyXText::fill(RowList::iterator row, int paper_width) const
900 // get the pure distance
901 pos_type const last = lastPrintablePos(*this, row);
903 ParagraphList::iterator pit = row->par();
904 LyXLayout_ptr const & layout = pit->layout();
906 // special handling of the right address boxes
907 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
908 int const tmpfill = row->fill();
909 row->fill(0); // the minfill in MarginLeft()
910 w = leftMargin(*row);
913 w = leftMargin(*row);
915 pos_type const body_pos = pit->beginningOfBody();
916 pos_type i = row->pos();
919 if (body_pos > 0 && i == body_pos) {
920 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
921 if (pit->isLineSeparator(i - 1))
922 w -= singleWidth(pit, i - 1);
923 int left_margin = labelEnd(*row);
927 w += singleWidth(pit, i);
930 if (body_pos > 0 && body_pos > last) {
931 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
932 if (last >= 0 && pit->isLineSeparator(last))
933 w -= singleWidth(pit, last);
934 int const left_margin = labelEnd(*row);
939 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
941 // If this case happens, it means that our calculation
942 // of the widths of the chars when we do rowBreakPoint()
943 // went wrong for some reason. Typically in list bodies.
944 // Things just about hobble on anyway, though you'll end
945 // up with a "fill_separator" less than zero, which corresponds
946 // to inter-word spacing being too small. Hopefully this problem
947 // will die when the label hacks die.
948 if (lyxerr.debugging() && fill < 0) {
949 lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
950 << " w " << w << " paper_width " << paper_width
951 << " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
958 // returns the minimum space a manual label needs on the screen in pixel
959 int LyXText::labelFill(Row const & row) const
961 ParagraphList::iterator pit = row.par();
963 pos_type last = pit->beginningOfBody();
965 lyx::Assert(last > 0);
967 // -1 because a label ends either with a space that is in the label,
968 // or with the beginning of a footnote that is outside the label.
971 // a separator at this end does not count
972 if (pit->isLineSeparator(last))
976 pos_type i = row.pos();
978 w += singleWidth(pit, i);
983 string const & labwidstr = pit->params().labelWidthString();
984 if (!labwidstr.empty()) {
985 LyXFont const labfont = getLabelFont(bv()->buffer(), pit);
986 int const labwidth = font_metrics::width(labwidstr, labfont);
987 fill = max(labwidth - w, 0);
994 LColor::color LyXText::backgroundColor() const
997 return inset_owner->backgroundColor();
999 return LColor::background;
1003 void LyXText::setHeightOfRow(RowList::iterator rit)
1005 lyx::Assert(rit != rows().end());
1007 // get the maximum ascent and the maximum descent
1008 float layoutasc = 0;
1009 float layoutdesc = 0;
1012 Inset * tmpinset = 0;
1014 // ok , let us initialize the maxasc and maxdesc value.
1015 // This depends in LaTeX of the font of the last character
1016 // in the paragraph. The hack below is necessary because
1017 // of the possibility of open footnotes
1019 // Correction: only the fontsize count. The other properties
1020 // are taken from the layoutfont. Nicer on the screen :)
1021 ParagraphList::iterator pit = rit->par();
1023 LyXLayout_ptr const & layout = pit->layout();
1025 // as max get the first character of this row then it can increase but not
1026 // decrease the height. Just some point to start with so we don't have to
1027 // do the assignment below too often.
1028 LyXFont font = getFont(bv()->buffer(), pit, rit->pos());
1029 LyXFont::FONT_SIZE const tmpsize = font.size();
1030 font = getLayoutFont(bv()->buffer(), pit);
1031 LyXFont::FONT_SIZE const size = font.size();
1032 font.setSize(tmpsize);
1034 LyXFont labelfont = getLabelFont(bv()->buffer(), pit);
1036 float spacing_val = 1.0;
1037 if (!pit->params().spacing().isDefault()) {
1038 spacing_val = pit->params().spacing().getValue();
1040 spacing_val = bv()->buffer()->params.spacing.getValue();
1042 //lyxerr << "spacing_val = " << spacing_val << endl;
1044 int maxasc = int(font_metrics::maxAscent(font) *
1045 layout->spacing.getValue() *
1047 int maxdesc = int(font_metrics::maxDescent(font) *
1048 layout->spacing.getValue() *
1051 pos_type const pos_end = lastPos(*this, rit);
1055 if (!pit->empty()) {
1056 // Check if any insets are larger
1057 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1058 if (pit->isInset(pos)) {
1059 tmpfont = getFont(bv()->buffer(), pit, pos);
1060 tmpinset = pit->getInset(pos);
1062 #if 1 // this is needed for deep update on initialitation
1063 #warning inset->update FIXME
1064 tmpinset->update(bv());
1066 maxwidth += tmpinset->width(bv(), tmpfont);
1067 maxasc = max(maxasc,
1068 tmpinset->ascent(bv(), tmpfont));
1069 maxdesc = max(maxdesc,
1070 tmpinset->descent(bv(), tmpfont));
1073 maxwidth += singleWidth(pit, pos);
1078 // Check if any custom fonts are larger (Asger)
1079 // This is not completely correct, but we can live with the small,
1080 // cosmetic error for now.
1081 LyXFont::FONT_SIZE maxsize =
1082 pit->highestFontInRange(rit->pos(), pos_end, size);
1083 if (maxsize > font.size()) {
1084 font.setSize(maxsize);
1085 maxasc = max(maxasc, font_metrics::maxAscent(font));
1086 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
1089 // This is nicer with box insets:
1093 rit->ascent_of_text(maxasc);
1095 // is it a top line?
1098 // some parksips VERY EASY IMPLEMENTATION
1099 if (bv()->buffer()->params.paragraph_separation ==
1100 BufferParams::PARSEP_SKIP)
1102 if (layout->isParagraph()
1103 && pit->getDepth() == 0
1104 && pit != ownerParagraphs().begin())
1106 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1107 } else if (pit != ownerParagraphs().begin() &&
1108 boost::prior(pit)->layout()->isParagraph() &&
1109 boost::prior(pit)->getDepth() == 0)
1111 // is it right to use defskip here too? (AS)
1112 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1117 if (pit == ownerParagraphs().begin() && !isInInset())
1118 maxasc += PAPER_MARGIN;
1120 // add the vertical spaces, that the user added
1121 maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
1123 // do not forget the DTP-lines!
1124 // there height depends on the font of the nearest character
1125 if (pit->params().lineTop())
1127 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1129 // and now the pagebreaks
1130 if (pit->params().pagebreakTop())
1131 maxasc += 3 * defaultRowHeight();
1133 if (pit->params().startOfAppendix())
1134 maxasc += 3 * defaultRowHeight();
1136 // This is special code for the chapter, since the label of this
1137 // layout is printed in an extra row
1138 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1139 && bv()->buffer()->params.secnumdepth >= 0)
1141 float spacing_val = 1.0;
1142 if (!pit->params().spacing().isDefault()) {
1143 spacing_val = pit->params().spacing().getValue();
1145 spacing_val = bv()->buffer()->params.spacing.getValue();
1148 labeladdon = int(font_metrics::maxDescent(labelfont) *
1149 layout->spacing.getValue() *
1151 + int(font_metrics::maxAscent(labelfont) *
1152 layout->spacing.getValue() *
1156 // special code for the top label
1157 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1158 || layout->labeltype == LABEL_BIBLIO
1159 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1160 && isFirstInSequence(pit, ownerParagraphs())
1161 && !pit->getLabelstring().empty())
1163 float spacing_val = 1.0;
1164 if (!pit->params().spacing().isDefault()) {
1165 spacing_val = pit->params().spacing().getValue();
1167 spacing_val = bv()->buffer()->params.spacing.getValue();
1171 (font_metrics::maxAscent(labelfont) *
1172 layout->spacing.getValue() *
1174 +(font_metrics::maxDescent(labelfont) *
1175 layout->spacing.getValue() *
1177 + layout->topsep * defaultRowHeight()
1178 + layout->labelbottomsep * defaultRowHeight());
1181 // And now the layout spaces, for example before and after
1182 // a section, or between the items of a itemize or enumerate
1185 if (!pit->params().pagebreakTop()) {
1186 ParagraphList::iterator prev =
1187 depthHook(pit, ownerParagraphs(),
1189 if (prev != pit && prev->layout() == layout &&
1190 prev->getDepth() == pit->getDepth() &&
1191 prev->getLabelWidthString() == pit->getLabelWidthString())
1193 layoutasc = (layout->itemsep * defaultRowHeight());
1194 } else if (rit != rows().begin()) {
1195 tmptop = layout->topsep;
1197 if (boost::prior(pit)->getDepth() >= pit->getDepth())
1198 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1201 layoutasc = (tmptop * defaultRowHeight());
1202 } else if (pit->params().lineTop()) {
1203 tmptop = layout->topsep;
1206 layoutasc = (tmptop * defaultRowHeight());
1209 prev = outerHook(pit, ownerParagraphs());
1210 if (prev != ownerParagraphs().end()) {
1211 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1212 } else if (pit != ownerParagraphs().begin()) {
1213 ParagraphList::iterator prior_pit = boost::prior(pit);
1214 if (prior_pit->getDepth() != 0 ||
1215 prior_pit->layout() == layout) {
1216 maxasc += int(layout->parsep * defaultRowHeight());
1222 // is it a bottom line?
1223 RowList::iterator next_rit = boost::next(rit);
1224 if (next_rit == rows().end() ||
1225 next_rit->par() != pit) {
1226 // the bottom margin
1227 ParagraphList::iterator nextpit = boost::next(pit);
1228 if (nextpit == ownerParagraphs().end() &&
1230 maxdesc += PAPER_MARGIN;
1232 // add the vertical spaces, that the user added
1233 maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
1235 // do not forget the DTP-lines!
1236 // there height depends on the font of the nearest character
1237 if (pit->params().lineBottom())
1238 maxdesc += 2 * font_metrics::ascent('x',
1239 getFont(bv()->buffer(),
1241 max(pos_type(0), pit->size() - 1)));
1243 // and now the pagebreaks
1244 if (pit->params().pagebreakBottom())
1245 maxdesc += 3 * defaultRowHeight();
1247 // and now the layout spaces, for example before and after
1248 // a section, or between the items of a itemize or enumerate
1250 if (!pit->params().pagebreakBottom()
1251 && nextpit != ownerParagraphs().end()) {
1252 ParagraphList::iterator comparepit = pit;
1256 if (comparepit->getDepth() > nextpit->getDepth()) {
1257 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1258 comparepit = depthHook(comparepit, ownerParagraphs(), nextpit->getDepth());
1259 if (comparepit->layout()!= nextpit->layout()
1260 || nextpit->getLabelWidthString() !=
1261 comparepit->getLabelWidthString())
1263 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1265 if (unusual > usual)
1266 layoutdesc = unusual;
1269 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1271 if (comparepit->layout() != nextpit->layout()
1272 || nextpit->getLabelWidthString() !=
1273 comparepit->getLabelWidthString())
1274 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1279 // incalculate the layout spaces
1280 maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
1281 maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
1283 // calculate the new height of the text
1284 height -= rit->height();
1286 rit->height(maxasc + maxdesc + labeladdon);
1287 rit->baseline(maxasc + labeladdon);
1289 height += rit->height();
1291 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1294 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1297 rit->width(maxwidth);
1298 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1300 rit->width(int(maxwidth + x));
1302 width = max(0, workWidth());
1303 RowList::iterator it = rows().begin();
1304 RowList::iterator end = rows().end();
1305 for (; it != end; ++it) {
1306 if (it->width() > width)
1307 width = it->width();
1313 // Appends the implicit specified paragraph before the specified row,
1314 // start at the implicit given position
1315 void LyXText::appendParagraph(RowList::iterator rowit)
1317 lyx::Assert(rowit != rowlist_.end());
1319 pos_type const last = rowit->par()->size();
1323 pos_type z = rowBreakPoint(*rowit);
1325 RowList::iterator tmprow = rowit;
1329 Row newrow(rowit->par(), z);
1330 rowit = rowlist_.insert(boost::next(rowit), newrow);
1335 // Set the dimensions of the row
1336 // fixed fill setting now by calling inset->update() in
1337 // SingleWidth when needed!
1338 tmprow->fill(fill(tmprow, workWidth()));
1339 setHeightOfRow(tmprow);
1345 void LyXText::breakAgain(RowList::iterator rit)
1347 lyx::Assert(rit != rows().end());
1349 bool not_ready = true;
1352 pos_type z = rowBreakPoint(*rit);
1353 RowList::iterator tmprit = rit;
1354 RowList::iterator end = rows().end();
1356 if (z < rit->par()->size()) {
1357 RowList::iterator next_rit = boost::next(rit);
1359 if (next_rit == end ||
1361 next_rit->par() != rit->par())) {
1364 Row newrow(rit->par(), z);
1365 rit = rowlist_.insert(next_rit, newrow);
1369 if (rit->pos() == z)
1370 not_ready = false; // the rest will not change
1376 // if there are some rows too much, delete them
1377 // only if you broke the whole paragraph!
1378 RowList::iterator tmprit2 = rit;
1379 while (boost::next(tmprit2) != end
1380 && boost::next(tmprit2)->par() == rit->par()) {
1383 while (tmprit2 != rit) {
1385 removeRow(boost::next(tmprit2));
1390 // set the dimensions of the row
1391 tmprit->fill(fill(tmprit, workWidth()));
1392 setHeightOfRow(tmprit);
1393 } while (not_ready);
1397 // this is just a little changed version of break again
1398 void LyXText::breakAgainOneRow(RowList::iterator rit)
1400 lyx::Assert(rit != rows().end());
1402 pos_type z = rowBreakPoint(*rit);
1403 RowList::iterator tmprit = rit;
1404 RowList::iterator end = rows().end();
1406 if (z < rit->par()->size()) {
1407 RowList::iterator next_rit = boost::next(rit);
1409 if (next_rit == end ||
1411 next_rit->par() != rit->par())) {
1414 Row newrow(rit->par(), z);
1415 rit = rowlist_.insert(next_rit, newrow);
1419 if (rit->pos() != z)
1423 // if there are some rows too much, delete them
1424 // only if you broke the whole paragraph!
1425 RowList::iterator tmprit2 = rit;
1426 while (boost::next(tmprit2) != end
1427 && boost::next(tmprit2)->par() == rit->par()) {
1430 while (tmprit2 != rit) {
1432 removeRow(boost::next(tmprit2));
1436 // set the dimensions of the row
1437 tmprit->fill(fill(tmprit, workWidth()));
1438 setHeightOfRow(tmprit);
1442 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1444 // allow only if at start or end, or all previous is new text
1445 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1446 && cursor.par()->isChangeEdited(0, cursor.pos()))
1449 LyXTextClass const & tclass =
1450 bv()->buffer()->params.getLyXTextClass();
1451 LyXLayout_ptr const & layout = cursor.par()->layout();
1453 // this is only allowed, if the current paragraph is not empty or caption
1454 // and if it has not the keepempty flag aktive
1455 if (cursor.par()->empty()
1456 && layout->labeltype != LABEL_SENSITIVE
1457 && !layout->keepempty)
1460 setUndo(bv(), Undo::FINISH, cursor.par(), boost::next(cursor.par()));
1462 // Always break behind a space
1464 // It is better to erase the space (Dekel)
1465 if (cursor.pos() < cursor.par()->size()
1466 && cursor.par()->isLineSeparator(cursor.pos()))
1467 cursor.par()->erase(cursor.pos());
1468 // cursor.pos(cursor.pos() + 1);
1470 // break the paragraph
1474 keep_layout = layout->isEnvironment();
1476 // we need to set this before we insert the paragraph. IMO the
1477 // breakParagraph call should return a bool if it inserts the
1478 // paragraph before or behind and we should react on that one
1479 // but we can fix this in 1.3.0 (Jug 20020509)
1480 bool const isempty = (layout->keepempty && cursor.par()->empty());
1481 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
1484 // well this is the caption hack since one caption is really enough
1485 if (layout->labeltype == LABEL_SENSITIVE) {
1487 // set to standard-layout
1488 cursor.par()->applyLayout(tclass.defaultLayout());
1490 // set to standard-layout
1491 boost::next(cursor.par())->applyLayout(tclass.defaultLayout());
1494 // if the cursor is at the beginning of a row without prior newline,
1496 // This touches only the screen-update. Otherwise we would may have
1497 // an empty row on the screen
1498 if (cursor.pos() && cursor.row()->pos() == cursor.pos()
1499 && !cursor.row()->par()->isNewline(cursor.pos() - 1))
1504 int y = cursor.y() - cursor.row()->baseline();
1506 // Do not forget the special right address boxes
1507 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1508 RowList::iterator r = cursor.row();
1509 RowList::iterator beg = rows().begin();
1511 while (r != beg && boost::prior(r)->par() == r->par()) {
1519 removeParagraph(cursor.row());
1521 // set the dimensions of the cursor row
1522 cursor.row()->fill(fill(cursor.row(), workWidth()));
1524 setHeightOfRow(cursor.row());
1526 #warning Trouble Point! (Lgb)
1527 // When ::breakParagraph is called from within an inset we must
1528 // ensure that the correct ParagraphList is used. Today that is not
1529 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1530 ParagraphList::iterator next_par = boost::next(cursor.par());
1532 while (!next_par->empty() && next_par->isNewline(0))
1535 insertParagraph(next_par, boost::next(cursor.row()));
1538 // This check is necessary. Otherwise the new empty paragraph will
1539 // be deleted automatically. And it is more friendly for the user!
1540 if (cursor.pos() || isempty)
1541 setCursor(next_par, 0);
1543 setCursor(cursor.par(), 0);
1545 if (boost::next(cursor.row()) != rows().end())
1546 breakAgain(boost::next(cursor.row()));
1548 need_break_row = rows().end();
1552 // Just a macro to make some thing easier.
1553 void LyXText::redoParagraph()
1556 redoParagraphs(cursor, boost::next(cursor.par()));
1557 setCursorIntern(cursor.par(), cursor.pos());
1561 // insert a character, moves all the following breaks in the
1562 // same Paragraph one to the right and make a rebreak
1563 void LyXText::insertChar(char c)
1565 setUndo(bv(), Undo::INSERT, cursor.par(), boost::next(cursor.par()));
1567 // When the free-spacing option is set for the current layout,
1568 // disable the double-space checking
1570 bool const freeSpacing = cursor.row()->par()->layout()->free_spacing ||
1571 cursor.row()->par()->isFreeSpacing();
1573 if (lyxrc.auto_number) {
1574 static string const number_operators = "+-/*";
1575 static string const number_unary_operators = "+-";
1576 static string const number_seperators = ".,:";
1578 if (current_font.number() == LyXFont::ON) {
1579 if (!IsDigit(c) && !contains(number_operators, c) &&
1580 !(contains(number_seperators, c) &&
1581 cursor.pos() >= 1 &&
1582 cursor.pos() < cursor.par()->size() &&
1583 getFont(bv()->buffer(),
1585 cursor.pos()).number() == LyXFont::ON &&
1586 getFont(bv()->buffer(),
1588 cursor.pos() - 1).number() == LyXFont::ON)
1590 number(bv()); // Set current_font.number to OFF
1591 } else if (IsDigit(c) &&
1592 real_current_font.isVisibleRightToLeft()) {
1593 number(bv()); // Set current_font.number to ON
1595 if (cursor.pos() > 0) {
1596 char const c = cursor.par()->getChar(cursor.pos() - 1);
1597 if (contains(number_unary_operators, c) &&
1598 (cursor.pos() == 1 ||
1599 cursor.par()->isSeparator(cursor.pos() - 2) ||
1600 cursor.par()->isNewline(cursor.pos() - 2))
1602 setCharFont(bv()->buffer(),
1606 } else if (contains(number_seperators, c) &&
1607 cursor.pos() >= 2 &&
1608 getFont(bv()->buffer(),
1610 cursor.pos() - 2).number() == LyXFont::ON) {
1611 setCharFont(bv()->buffer(),
1621 // First check, if there will be two blanks together or a blank at
1622 // the beginning of a paragraph.
1623 // I decided to handle blanks like normal characters, the main
1624 // difference are the special checks when calculating the row.fill
1625 // (blank does not count at the end of a row) and the check here
1627 // The bug is triggered when we type in a description environment:
1628 // The current_font is not changed when we go from label to main text
1629 // and it should (along with realtmpfont) when we type the space.
1630 // CHECK There is a bug here! (Asger)
1632 LyXFont realtmpfont = real_current_font;
1633 LyXFont rawtmpfont = current_font;
1634 // store the current font. This is because of the use of cursor
1635 // movements. The moving cursor would refresh the current font
1637 // Get the font that is used to calculate the baselineskip
1638 pos_type const lastpos = cursor.par()->size();
1639 LyXFont rawparfont =
1640 cursor.par()->getFontSettings(bv()->buffer()->params,
1643 bool jumped_over_space = false;
1645 if (!freeSpacing && IsLineSeparatorChar(c)) {
1646 if ((cursor.pos() > 0
1647 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1648 || (cursor.pos() > 0
1649 && cursor.par()->isNewline(cursor.pos() - 1))
1650 || (cursor.pos() == 0)) {
1651 static bool sent_space_message = false;
1652 if (!sent_space_message) {
1653 if (cursor.pos() == 0)
1654 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1656 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1657 sent_space_message = true;
1664 // the display inset stuff
1665 if (cursor.row()->pos() < cursor.row()->par()->size()
1666 && cursor.row()->par()->isInset(cursor.row()->pos())) {
1667 Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
1668 if (inset && (inset->display() || inset->needFullRow())) {
1669 // force a new break
1670 cursor.row()->fill(-1); // to force a new break
1674 // get the cursor row fist
1675 RowList::iterator row = cursor.row();
1676 int y = cursor.y() - row->baseline();
1677 if (c != Paragraph::META_INSET) {
1678 // Here case LyXText::InsertInset already insertet the character
1679 cursor.par()->insertChar(cursor.pos(), c);
1681 setCharFont(bv()->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
1683 if (!jumped_over_space) {
1684 // refresh the positions
1685 RowList::iterator tmprow = row;
1686 while (boost::next(tmprow) != rows().end() &&
1687 boost::next(tmprow)->par() == row->par()) {
1689 tmprow->pos(tmprow->pos() + 1);
1693 // Is there a break one row above
1694 if (row != rows().begin() &&
1695 boost::prior(row)->par() == row->par()
1696 && (cursor.par()->isLineSeparator(cursor.pos())
1697 || cursor.par()->isNewline(cursor.pos())
1698 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1699 cursor.par()->isInset(cursor.pos() + 1))
1700 || cursor.row()->fill() == -1))
1702 pos_type z = rowBreakPoint(*boost::prior(row));
1704 if (z >= row->pos()) {
1707 // set the dimensions of the row above
1708 boost::prior(row)->fill(fill(
1712 setHeightOfRow(boost::prior(row));
1714 y -= boost::prior(row)->height();
1718 breakAgainOneRow(row);
1720 current_font = rawtmpfont;
1721 real_current_font = realtmpfont;
1722 setCursor(cursor.par(), cursor.pos() + 1,
1723 false, cursor.boundary());
1724 // cursor MUST be in row now.
1726 if (boost::next(row) != rows().end() &&
1727 boost::next(row)->par() == row->par())
1728 need_break_row = boost::next(row);
1730 need_break_row = rows().end();
1732 // check, wether the last characters font has changed.
1733 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1734 && rawparfont != rawtmpfont)
1735 redoHeightOfParagraph();
1742 // recalculate the fill of the row
1743 if (row->fill() >= 0) {
1744 // needed because a newline will set fill to -1. Otherwise
1745 // we would not get a rebreak!
1746 row->fill(fill(row, workWidth()));
1749 if (c == Paragraph::META_INSET || row->fill() < 0) {
1751 breakAgainOneRow(row);
1752 // will the cursor be in another row now?
1753 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1754 boost::next(row) != rows().end()) {
1755 if (boost::next(row) != rows().end() &&
1756 boost::next(row)->par() == row->par())
1757 // this should always be true
1759 breakAgainOneRow(row);
1761 current_font = rawtmpfont;
1762 real_current_font = realtmpfont;
1764 setCursor(cursor.par(), cursor.pos() + 1, false,
1766 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
1767 != cursor.boundary())
1768 setCursor(cursor.par(), cursor.pos(), false,
1769 !cursor.boundary());
1770 if (boost::next(row) != rows().end() &&
1771 boost::next(row)->par() == row->par())
1772 need_break_row = boost::next(row);
1774 need_break_row = rows().end();
1776 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1777 int const tmpheight = row->height();
1779 setHeightOfRow(row);
1781 if (tmpheight == row->height()) {
1782 postRowPaint(row, y);
1787 current_font = rawtmpfont;
1788 real_current_font = realtmpfont;
1789 setCursor(cursor.par(), cursor.pos() + 1, false,
1793 // check, wether the last characters font has changed.
1794 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1795 && rawparfont != rawtmpfont) {
1796 redoHeightOfParagraph();
1798 // now the special right address boxes
1799 if (cursor.par()->layout()->margintype
1800 == MARGIN_RIGHT_ADDRESS_BOX) {
1801 redoDrawingOfParagraph(cursor);
1809 void LyXText::charInserted()
1811 // Here we could call FinishUndo for every 20 characters inserted.
1812 // This is from my experience how emacs does it. (Lgb)
1813 static unsigned int counter;
1823 void LyXText::prepareToPrint(RowList::iterator rit, float & x,
1824 float & fill_separator,
1826 float & fill_label_hfill,
1829 float w = rit->fill();
1831 fill_label_hfill = 0;
1833 fill_label_hfill = 0;
1835 ParagraphList::iterator pit = rit->par();
1838 pit->isRightToLeftPar(bv()->buffer()->params);
1840 x = (workWidth() > 0)
1841 ? rightMargin(*bv()->buffer(), *rit) : 0;
1843 x = (workWidth() > 0)
1844 ? leftMargin(*rit) : 0;
1846 // is there a manual margin with a manual label
1847 LyXLayout_ptr const & layout = pit->layout();
1849 if (layout->margintype == MARGIN_MANUAL
1850 && layout->labeltype == LABEL_MANUAL) {
1851 /// We might have real hfills in the label part
1852 float nlh = numberOfLabelHfills(*this, rit);
1854 // A manual label par (e.g. List) has an auto-hfill
1855 // between the label text and the body of the
1857 // But we don't want to do this auto hfill if the par
1862 if (nlh && !pit->getLabelWidthString().empty()) {
1863 fill_label_hfill = labelFill(*rit) / nlh;
1867 // are there any hfills in the row?
1868 float const nh = numberOfHfills(*this, rit);
1872 fill_hfill = w / nh;
1873 // we don't have to look at the alignment if it is ALIGN_LEFT and
1874 // if the row is already larger then the permitted width as then
1875 // we force the LEFT_ALIGN'edness!
1876 } else if (static_cast<int>(rit->width()) < workWidth()) {
1877 // is it block, flushleft or flushright?
1878 // set x how you need it
1880 if (pit->params().align() == LYX_ALIGN_LAYOUT) {
1881 align = layout->align;
1883 align = pit->params().align();
1886 // center displayed insets
1888 if (rit->pos() < pit->size()
1889 && pit->isInset(rit->pos())
1890 && (inset = pit->getInset(rit->pos()))
1891 && (inset->display())) // || (inset->scroll() < 0)))
1892 align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
1893 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1894 // ERT insets should always be LEFT ALIGNED on screen
1895 inset = pit->inInset();
1896 if (inset && inset->owner() &&
1897 inset->owner()->lyxCode() == Inset::ERT_CODE)
1899 align = LYX_ALIGN_LEFT;
1903 case LYX_ALIGN_BLOCK:
1905 float const ns = numberOfSeparators(*this, rit);
1906 RowList::iterator next_row = boost::next(rit);
1907 ParagraphList::iterator next_pit = next_row->par();
1909 if (ns && next_row != rowlist_.end() &&
1911 !(next_pit->isNewline(next_row->pos() - 1))
1912 && !(next_pit->isInset(next_row->pos()) &&
1913 next_pit->getInset(next_row->pos()) &&
1914 next_pit->getInset(next_row->pos())->display())
1916 fill_separator = w / ns;
1917 } else if (is_rtl) {
1922 case LYX_ALIGN_RIGHT:
1925 case LYX_ALIGN_CENTER:
1933 computeBidiTables(bv()->buffer(), rit);
1935 pos_type body_pos = pit->beginningOfBody();
1936 pos_type last = lastPos(*this, rit);
1939 (body_pos - 1 > last ||
1940 !pit->isLineSeparator(body_pos - 1))) {
1941 x += font_metrics::width(layout->labelsep,
1942 getLabelFont(bv()->buffer(),
1944 if (body_pos - 1 <= last)
1945 x += fill_label_hfill;
1951 // important for the screen
1954 // the cursor set functions have a special mechanism. When they
1955 // realize, that you left an empty paragraph, they will delete it.
1956 // They also delete the corresponding row
1958 void LyXText::cursorRightOneWord()
1960 // treat floats, HFills and Insets as words
1961 ParagraphList::iterator pit = cursor.par();
1962 pos_type pos = cursor.pos();
1964 // CHECK See comment on top of text.C
1966 if (pos == pit->size()
1967 && boost::next(pit) != ownerParagraphs().end()) {
1971 // Skip through initial nonword stuff.
1972 while (pos < pit->size() && !pit->isWord(pos)) {
1975 // Advance through word.
1976 while (pos < pit->size() && pit->isWord(pos)) {
1980 setCursor(pit, pos);
1984 // Skip initial whitespace at end of word and move cursor to *start*
1985 // of prior word, not to end of next prior word.
1986 void LyXText::cursorLeftOneWord()
1988 LyXCursor tmpcursor = cursor;
1989 cursorLeftOneWord(tmpcursor);
1990 setCursor(tmpcursor.par(), tmpcursor.pos());
1994 void LyXText::cursorLeftOneWord(LyXCursor & cur)
1996 // treat HFills, floats and Insets as words
1998 ParagraphList::iterator pit = cursor.par();
1999 pos_type pos = cursor.pos();
2002 (pit->isSeparator(pos - 1) ||
2003 pit->isKomma(pos - 1) ||
2004 pit->isNewline(pos - 1)) &&
2005 !(pit->isHfill(pos - 1) ||
2006 pit->isInset(pos - 1)))
2010 (pit->isInset(pos - 1) ||
2011 pit->isHfill(pos - 1))) {
2014 if (pit != ownerParagraphs().begin()) {
2018 } else { // Here, cur != 0
2020 pit->isWord(pos - 1))
2029 // Select current word. This depends on behaviour of
2030 // CursorLeftOneWord(), so it is patched as well.
2031 void LyXText::getWord(LyXCursor & from, LyXCursor & to,
2032 word_location const loc)
2034 // first put the cursor where we wana start to select the word
2037 case WHOLE_WORD_STRICT:
2038 if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
2039 || cursor.par()->isSeparator(cursor.pos())
2040 || cursor.par()->isKomma(cursor.pos())
2041 || cursor.par()->isNewline(cursor.pos())
2042 || cursor.par()->isSeparator(cursor.pos() - 1)
2043 || cursor.par()->isKomma(cursor.pos() - 1)
2044 || cursor.par()->isNewline(cursor.pos() - 1)) {
2048 // no break here, we go to the next
2051 // Move cursor to the beginning, when not already there.
2052 if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
2053 && !(from.par()->isKomma(from.pos() - 1)
2054 || from.par()->isNewline(from.pos() - 1)))
2055 cursorLeftOneWord(from);
2058 // always move the cursor to the beginning of previous word
2059 cursorLeftOneWord(from);
2062 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
2068 while (to.pos() < to.par()->size()
2069 && !to.par()->isSeparator(to.pos())
2070 && !to.par()->isKomma(to.pos())
2071 && !to.par()->isNewline(to.pos())
2072 && !to.par()->isHfill(to.pos())
2073 && !to.par()->isInset(to.pos()))
2075 to.pos(to.pos() + 1);
2080 void LyXText::selectWord(word_location loc)
2084 getWord(from, to, loc);
2086 setCursor(from.par(), from.pos());
2089 selection.cursor = cursor;
2090 setCursor(to.par(), to.pos());
2095 // Select the word currently under the cursor when no
2096 // selection is currently set
2097 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2099 if (!selection.set()) {
2101 return selection.set();
2107 void LyXText::acceptChange()
2109 if (!selection.set() && cursor.par()->size())
2112 if (selection.start.par() == selection.end.par()) {
2113 LyXCursor & startc = selection.start;
2114 LyXCursor & endc = selection.end;
2115 setUndo(bv(), Undo::INSERT, startc.par(), boost::next(startc.par()));
2116 startc.par()->acceptChange(startc.pos(), endc.pos());
2119 redoParagraphs(startc, boost::next(startc.par()));
2120 setCursorIntern(startc.par(), 0);
2122 #warning handle multi par selection
2126 void LyXText::rejectChange()
2128 if (!selection.set() && cursor.par()->size())
2131 if (selection.start.par() == selection.end.par()) {
2132 LyXCursor & startc = selection.start;
2133 LyXCursor & endc = selection.end;
2134 setUndo(bv(), Undo::INSERT, startc.par(),
2135 boost::next(startc.par()));
2136 startc.par()->rejectChange(startc.pos(), endc.pos());
2139 redoParagraphs(startc, boost::next(startc.par()));
2140 setCursorIntern(startc.par(), 0);
2142 #warning handle multi par selection
2146 // This function is only used by the spellchecker for NextWord().
2147 // It doesn't handle LYX_ACCENTs and probably never will.
2149 LyXText::selectNextWordToSpellcheck(float & value)
2151 if (the_locking_inset) {
2152 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2153 if (!word.word().empty()) {
2154 value += float(cursor.y());
2155 value /= float(height);
2158 // we have to go on checking so move cursor to the next char
2159 if (cursor.pos() == cursor.par()->size()) {
2160 if (boost::next(cursor.par()) == ownerParagraphs().end())
2162 cursor.par(boost::next(cursor.par()));
2165 cursor.pos(cursor.pos() + 1);
2167 ParagraphList::iterator tmppit = cursor.par();
2169 // If this is not the very first word, skip rest of
2170 // current word because we are probably in the middle
2171 // of a word if there is text here.
2172 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
2173 while (cursor.pos() < cursor.par()->size()
2174 && cursor.par()->isLetter(cursor.pos()))
2175 cursor.pos(cursor.pos() + 1);
2178 // Now, skip until we have real text (will jump paragraphs)
2180 ParagraphList::iterator cpit = cursor.par();
2181 pos_type const cpos(cursor.pos());
2183 if (cpos == cpit->size()) {
2184 if (boost::next(cpit) != ownerParagraphs().end()) {
2185 cursor.par(boost::next(cpit));
2192 bool const is_good_inset = cpit->isInset(cpos)
2193 && cpit->getInset(cpos)->allowSpellcheck();
2195 if (!isDeletedText(*cpit, cpos)
2196 && (is_good_inset || cpit->isLetter(cpos)))
2199 cursor.pos(cpos + 1);
2202 // now check if we hit an inset so it has to be a inset containing text!
2203 if (cursor.pos() < cursor.par()->size() &&
2204 cursor.par()->isInset(cursor.pos())) {
2206 cursor.par()->getInset(cursor.pos())->edit(bv());
2207 // now call us again to do the above trick
2208 // but obviously we have to start from down below ;)
2209 return bv()->text->selectNextWordToSpellcheck(value);
2212 // Update the value if we changed paragraphs
2213 if (cursor.par() != tmppit) {
2214 setCursor(cursor.par(), cursor.pos());
2215 value = float(cursor.y())/float(height);
2218 // Start the selection from here
2219 selection.cursor = cursor;
2222 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2223 .language()->code());
2224 // and find the end of the word (insets like optional hyphens
2225 // and ligature break are part of a word)
2226 while (cursor.pos() < cursor.par()->size()
2227 && cursor.par()->isLetter(cursor.pos())
2228 && !isDeletedText(*cursor.par(), cursor.pos()))
2229 cursor.pos(cursor.pos() + 1);
2231 // Finally, we copy the word to a string and return it
2233 if (selection.cursor.pos() < cursor.pos()) {
2235 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2236 if (!cursor.par()->isInset(i))
2237 str += cursor.par()->getChar(i);
2240 return WordLangTuple(str, lang_code);
2244 // This one is also only for the spellchecker
2245 void LyXText::selectSelectedWord()
2247 if (the_locking_inset) {
2248 the_locking_inset->selectSelectedWord(bv());
2251 // move cursor to the beginning
2252 setCursor(selection.cursor.par(), selection.cursor.pos());
2254 // set the sel cursor
2255 selection.cursor = cursor;
2257 // now find the end of the word
2258 while (cursor.pos() < cursor.par()->size()
2259 && (cursor.par()->isLetter(cursor.pos())))
2260 cursor.pos(cursor.pos() + 1);
2262 setCursor(cursor.par(), cursor.pos());
2264 // finally set the selection
2269 // Delete from cursor up to the end of the current or next word.
2270 void LyXText::deleteWordForward()
2272 if (cursor.par()->empty())
2275 LyXCursor tmpcursor = cursor;
2276 tmpcursor.row(0); //Â ??
2277 selection.set(true); // to avoid deletion
2278 cursorRightOneWord();
2279 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2280 selection.cursor = cursor;
2284 // Great, CutSelection() gets rid of multiple spaces.
2285 cutSelection(true, false);
2290 // Delete from cursor to start of current or prior word.
2291 void LyXText::deleteWordBackward()
2293 if (cursor.par()->empty())
2296 LyXCursor tmpcursor = cursor;
2297 tmpcursor.row(0); // ??
2298 selection.set(true); // to avoid deletion
2299 cursorLeftOneWord();
2300 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2301 selection.cursor = cursor;
2304 cutSelection(true, false);
2309 // Kill to end of line.
2310 void LyXText::deleteLineForward()
2312 if (cursor.par()->empty())
2313 // Paragraph is empty, so we just go to the right
2316 LyXCursor tmpcursor = cursor;
2317 // We can't store the row over a regular setCursor
2318 // so we set it to 0 and reset it afterwards.
2319 tmpcursor.row(0); //Â ??
2320 selection.set(true); // to avoid deletion
2322 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2323 selection.cursor = cursor;
2326 // What is this test for ??? (JMarc)
2327 if (!selection.set()) {
2328 deleteWordForward();
2330 cutSelection(true, false);
2336 void LyXText::changeCase(LyXText::TextCase action)
2341 if (selection.set()) {
2342 from = selection.start;
2345 getWord(from, to, PARTIAL_WORD);
2346 setCursor(to.par(), to.pos() + 1);
2349 lyx::Assert(from <= to);
2351 setUndo(bv(), Undo::FINISH, from.par(), boost::next(to.par()));
2353 pos_type pos = from.pos();
2354 ParagraphList::iterator pit = from.par();
2356 while (pit != ownerParagraphs().end() &&
2357 (pos != to.pos() || pit != to.par())) {
2358 if (pos == pit->size()) {
2363 unsigned char c = pit->getChar(pos);
2364 if (!IsInsetChar(c)) {
2366 case text_lowercase:
2369 case text_capitalization:
2371 action = text_lowercase;
2373 case text_uppercase:
2379 pit->setChar(pos, c);
2380 checkParagraph(pit, pos);
2385 if (to.row() != from.row())
2386 postPaint(from.y() - from.row()->baseline());
2390 void LyXText::Delete()
2392 // this is a very easy implementation
2394 LyXCursor old_cursor = cursor;
2395 int const old_cur_par_id = old_cursor.par()->id();
2396 int const old_cur_par_prev_id =
2397 (old_cursor.par() != ownerParagraphs().begin() ?
2398 boost::prior(old_cursor.par())->id() : -1);
2400 // just move to the right
2403 // CHECK Look at the comment here.
2404 // This check is not very good...
2405 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2406 // and that can very well delete the par or par->previous in
2407 // old_cursor. Will a solution where we compare paragraph id's
2409 if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
2410 == old_cur_par_prev_id
2411 && cursor.par()->id() != old_cur_par_id) {
2412 // delete-empty-paragraph-mechanism has done it
2416 // if you had success make a backspace
2417 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2418 LyXCursor tmpcursor = cursor;
2419 // to make sure undo gets the right cursor position
2420 cursor = old_cursor;
2421 setUndo(bv(), Undo::DELETE,
2422 cursor.par(), boost::next(cursor.par()));
2429 void LyXText::backspace()
2431 // Get the font that is used to calculate the baselineskip
2432 pos_type lastpos = cursor.par()->size();
2433 LyXFont rawparfont =
2434 cursor.par()->getFontSettings(bv()->buffer()->params,
2437 if (cursor.pos() == 0) {
2438 // The cursor is at the beginning of a paragraph,
2439 // so the the backspace will collapse two paragraphs into one.
2441 // but it's not allowed unless it's new
2442 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2445 // we may paste some paragraphs
2447 // is it an empty paragraph?
2450 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2451 // This is an empty paragraph and we delete it just by moving the cursor one step
2452 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2453 // of the paragraph.
2455 if (cursor.par() != ownerParagraphs().begin()) {
2456 ParagraphList::iterator tmppit = boost::prior(cursor.par());
2457 if (cursor.par()->layout() == tmppit->layout()
2458 && cursor.par()->getAlign() == tmppit->getAlign()) {
2459 // Inherit bottom DTD from the paragraph below.
2460 // (the one we are deleting)
2461 tmppit->params().lineBottom(cursor.par()->params().lineBottom());
2462 tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
2463 tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2468 // the layout things can change the height of a row !
2469 int const tmpheight = cursor.row()->height();
2470 setHeightOfRow(cursor.row());
2471 if (cursor.row()->height() != tmpheight) {
2472 postPaint(cursor.y() - cursor.row()->baseline());
2478 if (cursor.par() != ownerParagraphs().begin()) {
2479 setUndo(bv(), Undo::DELETE,
2480 boost::prior(cursor.par()),
2481 boost::next(cursor.par()));
2484 ParagraphList::iterator tmppit = cursor.par();
2485 RowList::iterator tmprow = cursor.row();
2487 // We used to do cursorLeftIntern() here, but it is
2488 // not a good idea since it triggers the auto-delete
2489 // mechanism. So we do a cursorLeftIntern()-lite,
2490 // without the dreaded mechanism. (JMarc)
2491 if (cursor.par() != ownerParagraphs().begin()) {
2492 // steps into the above paragraph.
2493 setCursorIntern(boost::prior(cursor.par()),
2494 boost::prior(cursor.par())->size(),
2498 // Pasting is not allowed, if the paragraphs have different
2499 // layout. I think it is a real bug of all other
2500 // word processors to allow it. It confuses the user.
2501 // Even so with a footnote paragraph and a non-footnote
2502 // paragraph. I will not allow pasting in this case,
2503 // because the user would be confused if the footnote behaves
2504 // different wether it is open or closed.
2506 // Correction: Pasting is always allowed with standard-layout
2507 LyXTextClass const & tclass =
2508 bv()->buffer()->params.getLyXTextClass();
2510 if (cursor.par() != tmppit
2511 && (cursor.par()->layout() == tmppit->layout()
2512 || tmppit->layout() == tclass.defaultLayout())
2513 && cursor.par()->getAlign() == tmppit->getAlign()) {
2514 removeParagraph(tmprow);
2516 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2518 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2519 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2520 // strangely enough it seems that commenting out the line above removes
2521 // most or all of the segfaults. I will however also try to move the
2522 // two Remove... lines in front of the PasteParagraph too.
2525 cursor.pos(cursor.pos() - 1);
2527 postPaint(cursor.y() - cursor.row()->baseline());
2529 // remove the lost paragraph
2530 // This one is not safe, since the paragraph that the tmprow and the
2531 // following rows belong to has been deleted by the PasteParagraph
2532 // above. The question is... could this be moved in front of the
2534 //RemoveParagraph(tmprow);
2535 //RemoveRow(tmprow);
2537 // This rebuilds the rows.
2538 appendParagraph(cursor.row());
2541 // the row may have changed, block, hfills etc.
2542 setCursor(cursor.par(), cursor.pos(), false);
2545 // this is the code for a normal backspace, not pasting
2547 setUndo(bv(), Undo::DELETE,
2548 cursor.par(), boost::next(cursor.par()));
2549 // We used to do cursorLeftIntern() here, but it is
2550 // not a good idea since it triggers the auto-delete
2551 // mechanism. So we do a cursorLeftIntern()-lite,
2552 // without the dreaded mechanism. (JMarc)
2553 setCursorIntern(cursor.par(), cursor.pos()- 1,
2554 false, cursor.boundary());
2556 if (cursor.par()->isInset(cursor.pos())) {
2557 // force complete redo when erasing display insets
2558 // this is a cruel method but safe..... Matthias
2559 if (cursor.par()->getInset(cursor.pos())->display() ||
2560 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2561 cursor.par()->erase(cursor.pos());
2567 RowList::iterator row = cursor.row();
2568 int y = cursor.y() - row->baseline();
2570 // remember that a space at the end of a row doesnt count
2571 // when calculating the fill
2572 if (cursor.pos() < lastPos(*this, row) ||
2573 !cursor.par()->isLineSeparator(cursor.pos())) {
2574 row->fill(row->fill() + singleWidth(
2579 // some special code when deleting a newline. This is similar
2580 // to the behavior when pasting paragraphs
2581 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2582 cursor.par()->erase(cursor.pos());
2583 // refresh the positions
2584 RowList::iterator tmprow = row;
2585 while (boost::next(tmprow) != rows().end() &&
2586 boost::next(tmprow)->par() == row->par()) {
2588 tmprow->pos(tmprow->pos() - 1);
2590 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2591 cursor.pos(cursor.pos() - 1);
2593 if (cursor.pos() < cursor.par()->size()
2594 && !cursor.par()->isSeparator(cursor.pos())) {
2595 cursor.par()->insertChar(cursor.pos(), ' ');
2596 setCharFont(bv()->buffer(), cursor.par(),
2597 cursor.pos(), current_font);
2598 // refresh the positions
2600 while (boost::next(tmprow) != rows().end() &&
2601 boost::next(tmprow)->par() == row->par()) {
2603 tmprow->pos(tmprow->pos() + 1);
2607 cursor.par()->erase(cursor.pos());
2609 // refresh the positions
2610 RowList::iterator tmprow = row;
2611 while (boost::next(tmprow) != rows().end() &&
2612 boost::next(tmprow)->par() == row->par()) {
2614 tmprow->pos(tmprow->pos() - 1);
2617 // delete newlines at the beginning of paragraphs
2618 while (!cursor.par()->empty() &&
2619 cursor.pos() < cursor.par()->size() &&
2620 cursor.par()->isNewline(cursor.pos()) &&
2621 cursor.pos() == cursor.par()->beginningOfBody()) {
2622 cursor.par()->erase(cursor.pos());
2623 // refresh the positions
2625 while (boost::next(tmprow) != rows().end() &&
2626 boost::next(tmprow)->par() == row->par()) {
2628 tmprow->pos(tmprow->pos() - 1);
2633 // is there a break one row above
2634 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2635 z = rowBreakPoint(*boost::prior(row));
2636 if (z >= row->pos()) {
2639 RowList::iterator tmprow = boost::prior(row);
2641 // maybe the current row is now empty
2642 if (row->pos() >= row->par()->size()) {
2645 need_break_row = rows().end();
2647 breakAgainOneRow(row);
2648 if (boost::next(row) != rows().end() &&
2649 boost::next(row)->par() == row->par())
2650 need_break_row = boost::next(row);
2652 need_break_row = rows().end();
2655 // set the dimensions of the row above
2656 y -= tmprow->height();
2657 tmprow->fill(fill(tmprow, workWidth()));
2658 setHeightOfRow(tmprow);
2662 setCursor(cursor.par(), cursor.pos(),
2663 false, cursor.boundary());
2664 //current_font = rawtmpfont;
2665 //real_current_font = realtmpfont;
2666 // check, whether the last character's font has changed.
2668 cursor.par()->getFontSettings(bv()->buffer()->params,
2669 cursor.par()->size() - 1))
2670 redoHeightOfParagraph();
2675 // break the cursor row again
2676 if (boost::next(row) != rows().end() &&
2677 boost::next(row)->par() == row->par() &&
2678 (lastPos(*this, row) == row->par()->size() - 1 ||
2679 rowBreakPoint(*row) != lastPos(*this, row))) {
2681 // it can happen that a paragraph loses one row
2682 // without a real breakup. This is when a word
2683 // is to long to be broken. Well, I don t care this
2685 if (lastPos(*this, row) == row->par()->size() - 1)
2686 removeRow(boost::next(row));
2690 breakAgainOneRow(row);
2691 // will the cursor be in another row now?
2692 if (boost::next(row) != rows().end() &&
2693 boost::next(row)->par() == row->par() &&
2694 lastPos(*this, row) <= cursor.pos()) {
2696 breakAgainOneRow(row);
2699 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2701 if (boost::next(row) != rows().end() &&
2702 boost::next(row)->par() == row->par())
2703 need_break_row = boost::next(row);
2705 need_break_row = rows().end();
2707 // set the dimensions of the row
2708 row->fill(fill(row, workWidth()));
2709 int const tmpheight = row->height();
2710 setHeightOfRow(row);
2711 if (tmpheight == row->height()) {
2712 postRowPaint(row, y);
2716 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2720 // current_font = rawtmpfont;
2721 // real_current_font = realtmpfont;
2723 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
2724 != cursor.boundary())
2725 setCursor(cursor.par(), cursor.pos(), false,
2726 !cursor.boundary());
2728 lastpos = cursor.par()->size();
2729 if (cursor.pos() == lastpos)
2732 // check, whether the last characters font has changed.
2734 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2735 redoHeightOfParagraph();
2737 // now the special right address boxes
2738 if (cursor.par()->layout()->margintype
2739 == MARGIN_RIGHT_ADDRESS_BOX) {
2740 redoDrawingOfParagraph(cursor);
2746 // returns pointer to a specified row
2748 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2753 return rowlist_.end();
2755 // find the first row of the specified paragraph
2756 RowList::iterator rit = rowlist_.begin();
2757 RowList::iterator end = rowlist_.end();
2758 while (boost::next(rit) != end && rit->par() != pit) {
2763 // now find the wanted row
2764 while (rit->pos() < pos
2765 && boost::next(rit) != end
2766 && boost::next(rit)->par() == pit
2767 && boost::next(rit)->pos() <= pos) {
2776 RowList::iterator LyXText::getRowNearY(int & y) const
2779 RowList::iterator rit = anchor_row_;
2780 RowList::iterator const beg = rows().begin();
2781 RowList::iterator const end = rows().end();
2783 if (rows().empty()) {
2790 int tmpy = rit->y();
2793 while (rit != end && tmpy <= y) {
2794 tmpy += rit->height();
2799 tmpy -= rit->height();
2802 while (rit != beg && tmpy > y) {
2804 tmpy -= rit->height();
2807 if (tmpy < 0 || rit == end) {
2819 int LyXText::getDepth() const
2821 return cursor.par()->getDepth();