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 for (pos_type i = pos + 1; i < par.size(); ++i)
206 if (!Encodings::IsComposeChar_arabic(par.getChar(i))) {
207 next_char = par.getChar(i);
211 if (Encodings::is_arabic(next_char)) {
212 if (Encodings::is_arabic(prev_char) &&
213 !Encodings::is_arabic_special(prev_char))
214 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
216 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
218 if (Encodings::is_arabic(prev_char) &&
219 !Encodings::is_arabic_special(prev_char))
220 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
222 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
226 // This is the comments that some of the warnings below refers to.
227 // There are some issues in this file and I don't think they are
228 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
229 // this is a problem that has been here almost from day one and that a
230 // larger userbase with differenct access patters triggers the bad
231 // behaviour. (segfaults.) What I think happen is: In several places
232 // we store the paragraph in the current cursor and then moves the
233 // cursor. This movement of the cursor will delete paragraph at the
234 // old position if it is now empty. This will make the temporary
235 // pointer to the old cursor paragraph invalid and dangerous to use.
236 // And is some cases this will trigger a segfault. I have marked some
237 // of the cases where this happens with a warning, but I am sure there
238 // are others in this file and in text2.C. There is also a note in
239 // Delete() that you should read. In Delete I store the paragraph->id
240 // instead of a pointer to the paragraph. I am pretty sure this faulty
241 // use of temporary pointers to paragraphs that might have gotten
242 // invalidated (through a cursor movement) before they are used, are
243 // the cause of the strange crashes we get reported often.
245 // It is very tiresom to change this code, especially when it is as
246 // hard to read as it is. Help to fix all the cases where this is done
247 // would be greately appreciated.
251 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
253 if (pos >= pit->size())
256 char const c = pit->getChar(pos);
257 return singleWidth(pit, pos, c);
261 int LyXText::singleWidth(ParagraphList::iterator pit,
262 pos_type pos, char c) const
264 if (pos >= pit->size())
267 LyXFont const font = getFont(bv()->buffer(), pit, pos);
269 // The most common case is handled first (Asger)
270 if (IsPrintable(c)) {
271 if (font.language()->RightToLeft()) {
272 if (font.language()->lang() == "arabic" &&
273 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
274 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
275 if (Encodings::IsComposeChar_arabic(c))
278 c = transformChar(c, *pit, pos);
279 } else if (font.language()->lang() == "hebrew" &&
280 Encodings::IsComposeChar_hebrew(c))
283 return font_metrics::width(c, font);
287 if (c == Paragraph::META_INSET) {
288 Inset * tmpinset = pit->getInset(pos);
290 if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
291 // Because of the representation as vertical lines
295 #warning inset->update FIXME
296 // this IS needed otherwise on initialitation we don't get the fill
297 // of the row right (ONLY on initialization if we read a file!)
298 // should be changed! (Jug 20011204)
299 tmpinset->update(bv());
301 return tmpinset->width(bv(), font);
306 if (IsSeparatorChar(c))
308 return font_metrics::width(c, font);
312 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
314 if (bidi_start == -1)
317 return log2vis_list[pos - bidi_start];
321 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
323 if (bidi_start == -1)
326 return vis2log_list[pos - bidi_start];
330 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
332 if (bidi_start == -1)
335 return bidi_levels[pos - bidi_start];
339 bool LyXText::bidi_InRange(lyx::pos_type pos) const
341 return bidi_start == -1 ||
342 (bidi_start <= pos && pos <= bidi_end);
346 void LyXText::computeBidiTables(Buffer const * buf,
347 RowList::iterator row) const
349 bidi_same_direction = true;
350 if (!lyxrc.rtl_support) {
355 Inset * inset = row->par()->inInset();
356 if (inset && inset->owner() &&
357 inset->owner()->lyxCode() == Inset::ERT_CODE) {
362 bidi_start = row->pos();
363 bidi_end = lastPrintablePos(*this, row);
365 if (bidi_start > bidi_end) {
370 if (bidi_end + 2 - bidi_start >
371 static_cast<pos_type>(log2vis_list.size())) {
373 (bidi_end + 2 - bidi_start < 500) ?
374 500 : 2 * (bidi_end + 2 - bidi_start);
375 log2vis_list.resize(new_size);
376 vis2log_list.resize(new_size);
377 bidi_levels.resize(new_size);
380 vis2log_list[bidi_end + 1 - bidi_start] = -1;
381 log2vis_list[bidi_end + 1 - bidi_start] = -1;
385 row->par()->isRightToLeftPar(buf->params);
389 pos_type const body_pos = row->par()->beginningOfBody();
391 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
392 bool is_space = row->par()->isLineSeparator(lpos);
394 (is_space && lpos + 1 <= bidi_end &&
395 !row->par()->isLineSeparator(lpos + 1) &&
396 !row->par()->isNewline(lpos + 1))
398 LyXFont font = row->par()->getFontSettings(buf->params, pos);
399 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
400 font.number() == LyXFont::ON &&
401 row->par()->getFontSettings(buf->params, lpos - 1).number()
403 font = row->par()->getFontSettings(buf->params, lpos);
408 bool new_rtl = font.isVisibleRightToLeft();
409 bool new_rtl0 = font.isRightToLeft();
412 if (lpos == body_pos - 1
413 && row->pos() < body_pos - 1
415 new_level = (rtl_par) ? 1 : 0;
416 new_rtl = new_rtl0 = rtl_par;
418 new_level = (new_rtl) ? 1 : 2;
420 new_level = (rtl_par) ? 2 : 0;
422 if (is_space && new_level >= level) {
428 int new_level2 = new_level;
430 if (level == new_level && rtl0 != new_rtl0) {
432 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
433 } else if (level < new_level) {
434 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
435 if (new_level > rtl_par)
436 bidi_same_direction = false;
438 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
441 bidi_levels[lpos - bidi_start] = new_level;
443 while (level > new_level2) {
444 pos_type old_lpos = stack[--level];
445 int delta = lpos - old_lpos - 1;
448 log2vis_list[lpos - bidi_start] += delta;
449 log2vis_list[old_lpos - bidi_start] += delta;
451 while (level < new_level)
452 stack[level++] = lpos;
456 pos_type const old_lpos = stack[--level];
457 int delta = bidi_end - old_lpos;
460 log2vis_list[old_lpos - bidi_start] += delta;
463 pos_type vpos = bidi_start - 1;
464 for (pos_type lpos = bidi_start;
465 lpos <= bidi_end; ++lpos) {
466 vpos += log2vis_list[lpos - bidi_start];
467 vis2log_list[vpos - bidi_start] = lpos;
468 log2vis_list[lpos - bidi_start] = vpos;
473 // This method requires a previous call to ComputeBidiTables()
474 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
477 if (!lyxrc.rtl_support || pos == 0)
480 if (!bidi_InRange(pos - 1)) {
481 /// This can happen if pos is the first char of a row.
482 /// Returning false in this case is incorrect!
486 bool const rtl = bidi_level(pos - 1) % 2;
487 bool const rtl2 = bidi_InRange(pos)
488 ? bidi_level(pos) % 2
489 : par.isRightToLeftPar(buf->params);
494 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
495 pos_type pos, LyXFont const & font) const
497 if (!lyxrc.rtl_support)
498 return false; // This is just for speedup
500 bool const rtl = font.isVisibleRightToLeft();
501 bool const rtl2 = bidi_InRange(pos)
502 ? bidi_level(pos) % 2
503 : par.isRightToLeftPar(buf->params);
508 int LyXText::leftMargin(Row const & row) const
512 if (row.pos() < row.par()->size())
513 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
514 (ins = row.par()->getInset(row.pos())) &&
515 (ins->needFullRow() || ins->display()))
518 LyXTextClass const & tclass =
519 bv()->buffer()->params.getLyXTextClass();
520 LyXLayout_ptr const & layout = row.par()->layout();
522 string parindent = layout->parindent;
526 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
528 // this is the way, LyX handles the LaTeX-Environments.
529 // I have had this idea very late, so it seems to be a
530 // later added hack and this is true
531 if (!row.par()->getDepth()) {
532 if (row.par()->layout() == tclass.defaultLayout()) {
533 // find the previous same level paragraph
534 if (row.par() != ownerParagraphs().begin()) {
535 Paragraph * newpar = row.par()
536 ->depthHook(row.par()->getDepth());
538 newpar->layout()->nextnoindent)
543 // find the next level paragraph
545 Paragraph * newpar = row.par()->outerHook();
547 // make a corresponding row. Needed to call leftMargin()
549 // check wether it is a sufficent paragraph
550 if (newpar && newpar->layout()->isEnvironment()) {
552 dummyrow.par(newpar);
553 dummyrow.pos(newpar->size());
554 x = leftMargin(dummyrow);
557 if (newpar && row.par()->layout() == tclass.defaultLayout()) {
558 if (newpar->params().noindent())
561 parindent = newpar->layout()->parindent;
567 LyXFont const labelfont = getLabelFont(bv()->buffer(), row.par());
568 switch (layout->margintype) {
570 if (!layout->leftmargin.empty()) {
571 x += font_metrics::signedWidth(layout->leftmargin,
572 tclass.defaultfont());
574 if (!row.par()->getLabelstring().empty()) {
575 x += font_metrics::signedWidth(layout->labelindent,
577 x += font_metrics::width(row.par()->getLabelstring(),
579 x += font_metrics::width(layout->labelsep, labelfont);
583 x += font_metrics::signedWidth(layout->labelindent, labelfont);
584 // The width of an empty par, even with manual label, should be 0
585 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
586 if (!row.par()->getLabelWidthString().empty()) {
587 x += font_metrics::width(row.par()->getLabelWidthString(),
589 x += font_metrics::width(layout->labelsep, labelfont);
594 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
595 / (row.par()->getDepth() + 4);
597 case MARGIN_FIRST_DYNAMIC:
598 if (layout->labeltype == LABEL_MANUAL) {
599 if (row.pos() >= row.par()->beginningOfBody()) {
600 x += font_metrics::signedWidth(layout->leftmargin,
603 x += font_metrics::signedWidth(layout->labelindent,
607 // Special case to fix problems with
609 || (layout->labeltype == LABEL_STATIC
610 && layout->latextype == LATEX_ENVIRONMENT
611 && ! row.par()->isFirstInSequence())) {
612 x += font_metrics::signedWidth(layout->leftmargin,
614 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
615 && layout->labeltype != LABEL_BIBLIO
616 && layout->labeltype !=
617 LABEL_CENTERED_TOP_ENVIRONMENT) {
618 x += font_metrics::signedWidth(layout->labelindent,
620 x += font_metrics::width(layout->labelsep, labelfont);
621 x += font_metrics::width(row.par()->getLabelstring(),
626 case MARGIN_RIGHT_ADDRESS_BOX:
628 // ok, a terrible hack. The left margin depends on the widest
629 // row in this paragraph. Do not care about footnotes, they
630 // are *NOT* allowed in the LaTeX realisation of this layout.
632 // find the first row of this paragraph
633 RowList::iterator tmprit = rowlist_.begin();
634 while (tmprit != rowlist_.end()
635 && tmprit->par() != row.par())
638 int minfill = tmprit->fill();
639 while (boost::next(tmprit) != rowlist_.end() &&
640 boost::next(tmprit)->par() == row.par()) {
642 if (tmprit->fill() < minfill)
643 minfill = tmprit->fill();
646 x += font_metrics::signedWidth(layout->leftmargin,
647 tclass.defaultfont());
653 if ((workWidth() > 0) &&
654 !row.par()->params().leftIndent().zero())
656 LyXLength const len = row.par()->params().leftIndent();
657 int const tw = inset_owner ?
658 inset_owner->latexTextWidth(bv()) : workWidth();
659 x += len.inPixels(tw);
664 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
665 align = layout->align;
667 align = row.par()->params().align();
669 // set the correct parindent
670 if (row.pos() == 0) {
671 if ((layout->labeltype == LABEL_NO_LABEL
672 || layout->labeltype == LABEL_TOP_ENVIRONMENT
673 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
674 || (layout->labeltype == LABEL_STATIC
675 && layout->latextype == LATEX_ENVIRONMENT
676 && ! row.par()->isFirstInSequence()))
677 && align == LYX_ALIGN_BLOCK
678 && !row.par()->params().noindent()
679 // in tabulars and ert paragraphs are never indented!
680 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
681 (row.par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
682 row.par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
683 && (row.par()->layout() != tclass.defaultLayout() ||
684 bv()->buffer()->params.paragraph_separation ==
685 BufferParams::PARSEP_INDENT)) {
686 x += font_metrics::signedWidth(parindent,
687 tclass.defaultfont());
688 } else if (layout->labeltype == LABEL_BIBLIO) {
689 // ale970405 Right width for bibitems
690 x += bibitemMaxWidth(bv(), tclass.defaultfont());
698 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
702 if (row.pos() < row.par()->size())
703 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
704 (ins = row.par()->getInset(row.pos())) &&
705 (ins->needFullRow() || ins->display()))
708 LyXTextClass const & tclass = buf.params.getLyXTextClass();
709 LyXLayout_ptr const & layout = row.par()->layout();
712 + font_metrics::signedWidth(tclass.rightmargin(),
713 tclass.defaultfont());
715 x += font_metrics::signedWidth(layout->rightmargin,
716 tclass.defaultfont())
717 * 4 / (row.par()->getDepth() + 4);
722 int LyXText::labelEnd(Row const & row) const
724 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
726 tmprow.pos(row.par()->size());
727 // return the beginning of the body
728 return leftMargin(tmprow);
731 // LabelEnd is only needed if the layout
732 // fills a flushleft label.
739 // this needs special handling - only newlines count as a break point
740 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
742 for (; i < par.size(); ++i) {
743 if (par.isNewline(i))
754 LyXText::rowBreakPoint(Row const & row) const
756 ParagraphList::iterator pit = row.par();
758 // maximum pixel width of a row.
759 int width = workWidth() - rightMargin(*bv()->buffer(), row);
761 // inset->textWidth() returns -1 via workWidth(),
766 LyXLayout_ptr const & layout = pit->layout();
768 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
769 return addressBreakPoint(row.pos(), *pit);
771 pos_type const pos = row.pos();
772 pos_type const body_pos = pit->beginningOfBody();
773 pos_type const last = pit->size();
774 pos_type point = last;
779 // Now we iterate through until we reach the right margin
780 // or the end of the par, then choose the possible break
783 int const left = leftMargin(const_cast<Row&>(row));
786 // pixel width since last breakpoint
788 bool fullrow = false;
791 for (; i < last; ++i) {
792 if (pit->isNewline(i)) {
797 char const c = pit->getChar(i);
801 // add the auto-hfill from label end to the body
802 if (body_pos && i == body_pos) {
803 thiswidth = font_metrics::width(layout->labelsep,
804 getLabelFont(bv()->buffer(), pit));
805 if (pit->isLineSeparator(i - 1))
806 thiswidth -= singleWidth(pit, i - 1);
807 int left_margin = labelEnd(row);
808 if (thiswidth + x < left_margin)
809 thiswidth = left_margin - x;
810 thiswidth += singleWidth(pit, i, c);
812 thiswidth = singleWidth(pit, i, c);
816 chunkwidth += thiswidth;
818 Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
819 fullrow = (in && (in->display() || in->needFullRow()));
821 // break before a character that will fall off
822 // the right of the row
824 // if no break before or we are at an inset
825 // that will take up a row, break here
826 if (point == last || fullrow || chunkwidth >= (width - left)) {
835 if (!in || in->isChar()) {
836 // some insets are line separators too
837 if (pit->isLineSeparator(i)) {
847 // full row insets start at a new row
849 if (pos < last - 1) {
851 if (pit->isLineSeparator(i + 1))
854 // to avoid extra rows
864 if (point == last && x >= width) {
865 // didn't find one, break at the point we reached the edge
867 } else if (i == last && x < width) {
868 // found one, but we fell off the end of the par, so prefer
873 // manual labels cannot be broken in LaTeX. But we
874 // want to make our on-screen rendering of footnotes
876 if (!fullrow && body_pos && point < body_pos)
877 point = body_pos - 1;
883 // returns the minimum space a row needs on the screen in pixel
884 int LyXText::fill(RowList::iterator row, int paper_width) const
890 // get the pure distance
891 pos_type const last = lastPrintablePos(*this, row);
893 // special handling of the right address boxes
894 if (row->par()->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
895 int const tmpfill = row->fill();
896 row->fill(0); // the minfill in MarginLeft()
897 w = leftMargin(*row);
900 w = leftMargin(*row);
902 ParagraphList::iterator pit = row->par();
903 LyXLayout_ptr const & layout = pit->layout();
905 pos_type const body_pos = pit->beginningOfBody();
906 pos_type i = row->pos();
909 if (body_pos > 0 && i == body_pos) {
910 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
911 if (pit->isLineSeparator(i - 1))
912 w -= singleWidth(pit, i - 1);
913 int left_margin = labelEnd(*row);
917 w += singleWidth(pit, i);
920 if (body_pos > 0 && body_pos > last) {
921 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
922 if (last >= 0 && pit->isLineSeparator(last))
923 w -= singleWidth(pit, last);
924 int const left_margin = labelEnd(*row);
929 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
931 // If this case happens, it means that our calculation
932 // of the widths of the chars when we do rowBreakPoint()
933 // went wrong for some reason. Typically in list bodies.
934 // Things just about hobble on anyway, though you'll end
935 // up with a "fill_separator" less than zero, which corresponds
936 // to inter-word spacing being too small. Hopefully this problem
937 // will die when the label hacks die.
938 if (lyxerr.debugging() && fill < 0) {
939 lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
940 << " w " << w << " paper_width " << paper_width
941 << " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
948 // returns the minimum space a manual label needs on the screen in pixel
949 int LyXText::labelFill(Row const & row) const
951 pos_type last = row.par()->beginningOfBody();
953 lyx::Assert(last > 0);
955 // -1 because a label ends either with a space that is in the label,
956 // or with the beginning of a footnote that is outside the label.
959 // a separator at this end does not count
960 if (row.par()->isLineSeparator(last))
964 pos_type i = row.pos();
966 w += singleWidth(row.par(), i);
971 string const & labwidstr = row.par()->params().labelWidthString();
972 if (!labwidstr.empty()) {
973 LyXFont const labfont = getLabelFont(bv()->buffer(), row.par());
974 int const labwidth = font_metrics::width(labwidstr, labfont);
975 fill = max(labwidth - w, 0);
982 LColor::color LyXText::backgroundColor() const
985 return inset_owner->backgroundColor();
987 return LColor::background;
991 void LyXText::setHeightOfRow(RowList::iterator rit)
993 // No need to do anything then...
994 if (rit == rows().end())
997 // get the maximum ascent and the maximum descent
1000 float layoutasc = 0;
1001 float layoutdesc = 0;
1004 Inset * tmpinset = 0;
1006 // ok , let us initialize the maxasc and maxdesc value.
1007 // This depends in LaTeX of the font of the last character
1008 // in the paragraph. The hack below is necessary because
1009 // of the possibility of open footnotes
1011 // Correction: only the fontsize count. The other properties
1012 // are taken from the layoutfont. Nicer on the screen :)
1013 ParagraphList::iterator pit = rit->par();
1014 ParagraphList::iterator firstpit = pit;
1016 LyXLayout_ptr const & layout = firstpit->layout();
1018 // as max get the first character of this row then it can increase but not
1019 // decrease the height. Just some point to start with so we don't have to
1020 // do the assignment below too often.
1021 LyXFont font = getFont(bv()->buffer(), pit, rit->pos());
1022 LyXFont::FONT_SIZE const tmpsize = font.size();
1023 font = getLayoutFont(bv()->buffer(), pit);
1024 LyXFont::FONT_SIZE const size = font.size();
1025 font.setSize(tmpsize);
1027 LyXFont labelfont = getLabelFont(bv()->buffer(), pit);
1029 float spacing_val = 1.0;
1030 if (!rit->par()->params().spacing().isDefault()) {
1031 spacing_val = rit->par()->params().spacing().getValue();
1033 spacing_val = bv()->buffer()->params.spacing.getValue();
1035 //lyxerr << "spacing_val = " << spacing_val << endl;
1037 int maxasc = int(font_metrics::maxAscent(font) *
1038 layout->spacing.getValue() *
1040 int maxdesc = int(font_metrics::maxDescent(font) *
1041 layout->spacing.getValue() *
1044 pos_type const pos_end = lastPos(*this, rit);
1048 if (!rit->par()->empty()) {
1049 // Check if any insets are larger
1050 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1051 if (rit->par()->isInset(pos)) {
1052 tmpfont = getFont(bv()->buffer(), rit->par(), pos);
1053 tmpinset = rit->par()->getInset(pos);
1055 #if 1 // this is needed for deep update on initialitation
1056 #warning inset->update FIXME
1057 tmpinset->update(bv());
1059 asc = tmpinset->ascent(bv(), tmpfont);
1060 desc = tmpinset->descent(bv(), tmpfont);
1061 maxwidth += tmpinset->width(bv(), tmpfont);
1062 maxasc = max(maxasc, asc);
1063 maxdesc = max(maxdesc, desc);
1066 maxwidth += singleWidth(rit->par(), pos);
1071 // Check if any custom fonts are larger (Asger)
1072 // This is not completely correct, but we can live with the small,
1073 // cosmetic error for now.
1074 LyXFont::FONT_SIZE maxsize =
1075 rit->par()->highestFontInRange(rit->pos(), pos_end, size);
1076 if (maxsize > font.size()) {
1077 font.setSize(maxsize);
1079 asc = font_metrics::maxAscent(font);
1080 desc = font_metrics::maxDescent(font);
1087 // This is nicer with box insets:
1091 rit->ascent_of_text(maxasc);
1093 // is it a top line?
1094 if (!rit->pos() && (rit->par() == firstpit)) {
1096 // some parksips VERY EASY IMPLEMENTATION
1097 if (bv()->buffer()->params.paragraph_separation ==
1098 BufferParams::PARSEP_SKIP)
1100 if (layout->isParagraph()
1101 && firstpit->getDepth() == 0
1102 && firstpit != ownerParagraphs().begin())
1104 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1105 } else if (firstpit != ownerParagraphs().begin() &&
1106 boost::prior(firstpit)->layout()->isParagraph() &&
1107 boost::prior(firstpit)->getDepth() == 0)
1109 // is it right to use defskip here too? (AS)
1110 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1115 if (rit->par() == ownerParagraphs().begin() && !isInInset())
1116 maxasc += PAPER_MARGIN;
1118 // add the vertical spaces, that the user added
1119 maxasc += getLengthMarkerHeight(*bv(), firstpit->params().spaceTop());
1121 // do not forget the DTP-lines!
1122 // there height depends on the font of the nearest character
1123 if (firstpit->params().lineTop())
1125 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1127 // and now the pagebreaks
1128 if (firstpit->params().pagebreakTop())
1129 maxasc += 3 * defaultRowHeight();
1131 if (firstpit->params().startOfAppendix())
1132 maxasc += 3 * defaultRowHeight();
1134 // This is special code for the chapter, since the label of this
1135 // layout is printed in an extra row
1136 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1137 && bv()->buffer()->params.secnumdepth >= 0)
1139 float spacing_val = 1.0;
1140 if (!rit->par()->params().spacing().isDefault()) {
1141 spacing_val = rit->par()->params().spacing().getValue();
1143 spacing_val = bv()->buffer()->params.spacing.getValue();
1146 labeladdon = int(font_metrics::maxDescent(labelfont) *
1147 layout->spacing.getValue() *
1149 + int(font_metrics::maxAscent(labelfont) *
1150 layout->spacing.getValue() *
1154 // special code for the top label
1155 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1156 || layout->labeltype == LABEL_BIBLIO
1157 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1158 && rit->par()->isFirstInSequence()
1159 && !rit->par()->getLabelstring().empty())
1161 float spacing_val = 1.0;
1162 if (!rit->par()->params().spacing().isDefault()) {
1163 spacing_val = rit->par()->params().spacing().getValue();
1165 spacing_val = bv()->buffer()->params.spacing.getValue();
1169 (font_metrics::maxAscent(labelfont) *
1170 layout->spacing.getValue() *
1172 +(font_metrics::maxDescent(labelfont) *
1173 layout->spacing.getValue() *
1175 + layout->topsep * defaultRowHeight()
1176 + layout->labelbottomsep * defaultRowHeight());
1179 // and now the layout spaces, for example before and after a section,
1180 // or between the items of a itemize or enumerate environment
1182 if (!firstpit->params().pagebreakTop()) {
1183 Paragraph * prev = rit->par()->previous();
1185 prev = rit->par()->depthHook(rit->par()->getDepth());
1186 if (prev && prev->layout() == firstpit->layout() &&
1187 prev->getDepth() == firstpit->getDepth() &&
1188 prev->getLabelWidthString() == firstpit->getLabelWidthString())
1190 layoutasc = (layout->itemsep * defaultRowHeight());
1191 } else if (rit != rows().begin()) {
1192 tmptop = layout->topsep;
1194 if (boost::prior(rit)->par()->getDepth() >= rit->par()->getDepth())
1195 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1198 layoutasc = (tmptop * defaultRowHeight());
1199 } else if (rit->par()->params().lineTop()) {
1200 tmptop = layout->topsep;
1203 layoutasc = (tmptop * defaultRowHeight());
1206 prev = rit->par()->outerHook();
1208 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1210 if (firstpit != ownerParagraphs().begin() &&
1211 boost::prior(firstpit)->getDepth() == 0 &&
1212 boost::prior(firstpit)->layout() !=
1216 } else if (firstpit != ownerParagraphs().begin()) {
1217 maxasc += int(layout->parsep * defaultRowHeight());
1223 // is it a bottom line?
1224 if (rit->par() == pit
1225 && (boost::next(rit) == rows().end() ||
1226 boost::next(rit)->par() != rit->par())) {
1227 // the bottom margin
1228 if (boost::next(pit) == ownerParagraphs().end() &&
1230 maxdesc += PAPER_MARGIN;
1232 // add the vertical spaces, that the user added
1233 maxdesc += getLengthMarkerHeight(*bv(), firstpit->params().spaceBottom());
1235 // do not forget the DTP-lines!
1236 // there height depends on the font of the nearest character
1237 if (firstpit->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 (firstpit->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 (!firstpit->params().pagebreakBottom()
1251 && boost::next(rit->par()) != ownerParagraphs().end()) {
1252 ParagraphList::iterator nextpit = boost::next(rit->par());
1253 ParagraphList::iterator comparepit = rit->par();
1257 if (comparepit->getDepth() > nextpit->getDepth()) {
1258 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1259 comparepit = comparepit->depthHook(nextpit->getDepth());
1260 if (comparepit->layout()!= nextpit->layout()
1261 || nextpit->getLabelWidthString() !=
1262 comparepit->getLabelWidthString())
1264 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1266 if (unusual > usual)
1267 layoutdesc = unusual;
1270 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1272 if (comparepit->layout() != nextpit->layout()
1273 || nextpit->getLabelWidthString() !=
1274 comparepit->getLabelWidthString())
1275 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1280 // incalculate the layout spaces
1281 maxasc += int(layoutasc * 2 / (2 + firstpit->getDepth()));
1282 maxdesc += int(layoutdesc * 2 / (2 + firstpit->getDepth()));
1284 // calculate the new height of the text
1285 height -= rit->height();
1287 rit->height(maxasc + maxdesc + labeladdon);
1288 rit->baseline(maxasc + labeladdon);
1290 height += rit->height();
1292 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1295 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1298 rit->width(maxwidth);
1299 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1301 rit->width(int(maxwidth + x));
1303 width = max(0, workWidth());
1304 RowList::iterator it = rows().begin();
1305 RowList::iterator end = rows().end();
1306 for (; it != end; ++it) {
1307 if (it->width() > width)
1308 width = it->width();
1314 // Appends the implicit specified paragraph before the specified row,
1315 // start at the implicit given position
1316 void LyXText::appendParagraph(RowList::iterator rowit)
1318 lyx::Assert(rowit != rowlist_.end());
1320 pos_type const last = rowit->par()->size();
1324 pos_type z = rowBreakPoint(*rowit);
1326 RowList::iterator tmprow = rowit;
1330 Row newrow(rowit->par(), z);
1331 rowit = rowlist_.insert(boost::next(rowit), newrow);
1336 // Set the dimensions of the row
1337 // fixed fill setting now by calling inset->update() in
1338 // SingleWidth when needed!
1339 tmprow->fill(fill(tmprow, workWidth()));
1340 setHeightOfRow(tmprow);
1346 void LyXText::breakAgain(RowList::iterator rit)
1348 lyx::Assert(rit != rows().end());
1350 bool not_ready = true;
1353 pos_type z = rowBreakPoint(*rit);
1354 RowList::iterator tmprit = rit;
1355 RowList::iterator end = rows().end();
1357 if (z < rit->par()->size()) {
1358 if (boost::next(rit) == end ||
1359 (boost::next(rit) != end &&
1360 boost::next(rit)->par() != rit->par())) {
1363 Row newrow(rit->par(), z);
1364 rit = rowlist_.insert(boost::next(rit), newrow);
1368 if (rit->pos() == z)
1369 not_ready = false; // the rest will not change
1375 // if there are some rows too much, delete them
1376 // only if you broke the whole paragraph!
1377 RowList::iterator tmprit2 = rit;
1378 while (boost::next(tmprit2) != end
1379 && boost::next(tmprit2)->par() == rit->par()) {
1382 while (tmprit2 != rit) {
1384 removeRow(boost::next(tmprit2));
1389 // set the dimensions of the row
1390 tmprit->fill(fill(tmprit, workWidth()));
1391 setHeightOfRow(tmprit);
1392 } while (not_ready);
1396 // this is just a little changed version of break again
1397 void LyXText::breakAgainOneRow(RowList::iterator rit)
1399 lyx::Assert(rit != rows().end());
1401 pos_type z = rowBreakPoint(*rit);
1402 RowList::iterator tmprit = rit;
1403 RowList::iterator end = rows().end();
1405 if (z < rit->par()->size()) {
1406 if (boost::next(rit) == end ||
1407 (boost::next(rit) != end &&
1408 boost::next(rit)->par() != rit->par())) {
1411 Row newrow(rit->par(), z);
1412 rit = rowlist_.insert(boost::next(rit), newrow);
1416 if (rit->pos() != z)
1420 // if there are some rows too much, delete them
1421 // only if you broke the whole paragraph!
1422 RowList::iterator tmprit2 = rit;
1423 while (boost::next(tmprit2) != end
1424 && boost::next(tmprit2)->par() == rit->par()) {
1427 while (tmprit2 != rit) {
1429 removeRow(boost::next(tmprit2));
1433 // set the dimensions of the row
1434 tmprit->fill(fill(tmprit, workWidth()));
1435 setHeightOfRow(tmprit);
1439 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1441 // allow only if at start or end, or all previous is new text
1442 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1443 && cursor.par()->isChangeEdited(0, cursor.pos()))
1446 LyXTextClass const & tclass =
1447 bv()->buffer()->params.getLyXTextClass();
1448 LyXLayout_ptr const & layout = cursor.par()->layout();
1450 // this is only allowed, if the current paragraph is not empty or caption
1451 // and if it has not the keepempty flag aktive
1452 if (cursor.par()->empty()
1453 && layout->labeltype != LABEL_SENSITIVE
1454 && !layout->keepempty)
1457 setUndo(bv(), Undo::FINISH, &*cursor.par(), &*boost::next(cursor.par()));
1459 // Always break behind a space
1461 // It is better to erase the space (Dekel)
1462 if (cursor.pos() < cursor.par()->size()
1463 && cursor.par()->isLineSeparator(cursor.pos()))
1464 cursor.par()->erase(cursor.pos());
1465 // cursor.pos(cursor.pos() + 1);
1467 // break the paragraph
1471 keep_layout = layout->isEnvironment();
1473 // we need to set this before we insert the paragraph. IMO the
1474 // breakParagraph call should return a bool if it inserts the
1475 // paragraph before or behind and we should react on that one
1476 // but we can fix this in 1.3.0 (Jug 20020509)
1477 bool const isempty = (layout->keepempty && cursor.par()->empty());
1478 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
1481 // well this is the caption hack since one caption is really enough
1482 if (layout->labeltype == LABEL_SENSITIVE) {
1484 // set to standard-layout
1485 cursor.par()->applyLayout(tclass.defaultLayout());
1487 // set to standard-layout
1488 boost::next(cursor.par())->applyLayout(tclass.defaultLayout());
1491 // if the cursor is at the beginning of a row without prior newline,
1493 // This touches only the screen-update. Otherwise we would may have
1494 // an empty row on the screen
1495 if (cursor.pos() && cursor.row()->pos() == cursor.pos()
1496 && !cursor.row()->par()->isNewline(cursor.pos() - 1))
1501 int y = cursor.y() - cursor.row()->baseline();
1503 // Do not forget the special right address boxes
1504 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
1505 RowList::iterator r = cursor.row();
1506 while (r != rows().begin() && boost::prior(r)->par() == r->par()) {
1514 removeParagraph(cursor.row());
1516 // set the dimensions of the cursor row
1517 cursor.row()->fill(fill(cursor.row(), workWidth()));
1519 setHeightOfRow(cursor.row());
1521 #warning Trouble Point! (Lgb)
1522 // When ::breakParagraph is called from within an inset we must
1523 // ensure that the correct ParagraphList is used. Today that is not
1524 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1525 ParagraphList::iterator next_par = boost::next(cursor.par());
1527 while (!next_par->empty() && next_par->isNewline(0))
1530 insertParagraph(next_par, boost::next(cursor.row()));
1533 // This check is necessary. Otherwise the new empty paragraph will
1534 // be deleted automatically. And it is more friendly for the user!
1535 if (cursor.pos() || isempty)
1536 setCursor(next_par, 0);
1538 setCursor(cursor.par(), 0);
1540 if (boost::next(cursor.row()) != rows().end())
1541 breakAgain(boost::next(cursor.row()));
1543 need_break_row = rows().end();
1547 // Just a macro to make some thing easier.
1548 void LyXText::redoParagraph()
1551 redoParagraphs(cursor, boost::next(cursor.par()));
1552 setCursorIntern(cursor.par(), cursor.pos());
1556 // insert a character, moves all the following breaks in the
1557 // same Paragraph one to the right and make a rebreak
1558 void LyXText::insertChar(char c)
1560 setUndo(bv(), Undo::INSERT, &*cursor.par(), &*boost::next(cursor.par()));
1562 // When the free-spacing option is set for the current layout,
1563 // disable the double-space checking
1565 bool const freeSpacing = cursor.row()->par()->layout()->free_spacing ||
1566 cursor.row()->par()->isFreeSpacing();
1568 if (lyxrc.auto_number) {
1569 static string const number_operators = "+-/*";
1570 static string const number_unary_operators = "+-";
1571 static string const number_seperators = ".,:";
1573 if (current_font.number() == LyXFont::ON) {
1574 if (!IsDigit(c) && !contains(number_operators, c) &&
1575 !(contains(number_seperators, c) &&
1576 cursor.pos() >= 1 &&
1577 cursor.pos() < cursor.par()->size() &&
1578 getFont(bv()->buffer(),
1580 cursor.pos()).number() == LyXFont::ON &&
1581 getFont(bv()->buffer(),
1583 cursor.pos() - 1).number() == LyXFont::ON)
1585 number(bv()); // Set current_font.number to OFF
1586 } else if (IsDigit(c) &&
1587 real_current_font.isVisibleRightToLeft()) {
1588 number(bv()); // Set current_font.number to ON
1590 if (cursor.pos() > 0) {
1591 char const c = cursor.par()->getChar(cursor.pos() - 1);
1592 if (contains(number_unary_operators, c) &&
1593 (cursor.pos() == 1 ||
1594 cursor.par()->isSeparator(cursor.pos() - 2) ||
1595 cursor.par()->isNewline(cursor.pos() - 2))
1597 setCharFont(bv()->buffer(),
1601 } else if (contains(number_seperators, c) &&
1602 cursor.pos() >= 2 &&
1603 getFont(bv()->buffer(),
1605 cursor.pos() - 2).number() == LyXFont::ON) {
1606 setCharFont(bv()->buffer(),
1616 // First check, if there will be two blanks together or a blank at
1617 // the beginning of a paragraph.
1618 // I decided to handle blanks like normal characters, the main
1619 // difference are the special checks when calculating the row.fill
1620 // (blank does not count at the end of a row) and the check here
1622 // The bug is triggered when we type in a description environment:
1623 // The current_font is not changed when we go from label to main text
1624 // and it should (along with realtmpfont) when we type the space.
1625 // CHECK There is a bug here! (Asger)
1627 LyXFont realtmpfont = real_current_font;
1628 LyXFont rawtmpfont = current_font;
1629 // store the current font. This is because of the use of cursor
1630 // movements. The moving cursor would refresh the current font
1632 // Get the font that is used to calculate the baselineskip
1633 pos_type const lastpos = cursor.par()->size();
1634 LyXFont rawparfont =
1635 cursor.par()->getFontSettings(bv()->buffer()->params,
1638 bool jumped_over_space = false;
1640 if (!freeSpacing && IsLineSeparatorChar(c)) {
1641 if ((cursor.pos() > 0
1642 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1643 || (cursor.pos() > 0
1644 && cursor.par()->isNewline(cursor.pos() - 1))
1645 || (cursor.pos() == 0)) {
1646 static bool sent_space_message = false;
1647 if (!sent_space_message) {
1648 if (cursor.pos() == 0)
1649 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1651 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1652 sent_space_message = true;
1659 // the display inset stuff
1660 if (cursor.row()->pos() < cursor.row()->par()->size()
1661 && cursor.row()->par()->isInset(cursor.row()->pos())) {
1662 Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
1663 if (inset && (inset->display() || inset->needFullRow())) {
1664 // force a new break
1665 cursor.row()->fill(-1); // to force a new break
1669 // get the cursor row fist
1670 RowList::iterator row = cursor.row();
1671 int y = cursor.y() - row->baseline();
1672 if (c != Paragraph::META_INSET) {
1673 // Here case LyXText::InsertInset already insertet the character
1674 cursor.par()->insertChar(cursor.pos(), c);
1676 setCharFont(bv()->buffer(), &*cursor.par(), cursor.pos(), rawtmpfont);
1678 if (!jumped_over_space) {
1679 // refresh the positions
1680 RowList::iterator tmprow = row;
1681 while (boost::next(tmprow) != rows().end() &&
1682 boost::next(tmprow)->par() == row->par()) {
1684 tmprow->pos(tmprow->pos() + 1);
1688 // Is there a break one row above
1689 if (row != rows().begin() &&
1690 boost::prior(row)->par() == row->par()
1691 && (cursor.par()->isLineSeparator(cursor.pos())
1692 || cursor.par()->isNewline(cursor.pos())
1693 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1694 cursor.par()->isInset(cursor.pos() + 1))
1695 || cursor.row()->fill() == -1))
1697 pos_type z = rowBreakPoint(*boost::prior(row));
1699 if (z >= row->pos()) {
1702 // set the dimensions of the row above
1703 boost::prior(row)->fill(fill(
1707 setHeightOfRow(boost::prior(row));
1709 y -= boost::prior(row)->height();
1713 breakAgainOneRow(row);
1715 current_font = rawtmpfont;
1716 real_current_font = realtmpfont;
1717 setCursor(cursor.par(), cursor.pos() + 1,
1718 false, cursor.boundary());
1719 // cursor MUST be in row now.
1721 if (boost::next(row) != rows().end() &&
1722 boost::next(row)->par() == row->par())
1723 need_break_row = boost::next(row);
1725 need_break_row = rows().end();
1727 // check, wether the last characters font has changed.
1728 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1729 && rawparfont != rawtmpfont)
1730 redoHeightOfParagraph();
1737 // recalculate the fill of the row
1738 if (row->fill() >= 0) {
1739 // needed because a newline will set fill to -1. Otherwise
1740 // we would not get a rebreak!
1741 row->fill(fill(row, workWidth()));
1744 if (c == Paragraph::META_INSET || row->fill() < 0) {
1746 breakAgainOneRow(row);
1747 // will the cursor be in another row now?
1748 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1749 boost::next(row) != rows().end()) {
1750 if (boost::next(row) != rows().end() &&
1751 boost::next(row)->par() == row->par())
1752 // this should always be true
1754 breakAgainOneRow(row);
1756 current_font = rawtmpfont;
1757 real_current_font = realtmpfont;
1759 setCursor(cursor.par(), cursor.pos() + 1, false,
1761 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
1762 != cursor.boundary())
1763 setCursor(cursor.par(), cursor.pos(), false,
1764 !cursor.boundary());
1765 if (boost::next(row) != rows().end() &&
1766 boost::next(row)->par() == row->par())
1767 need_break_row = boost::next(row);
1769 need_break_row = rows().end();
1771 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1772 int const tmpheight = row->height();
1774 setHeightOfRow(row);
1776 if (tmpheight == row->height()) {
1777 postRowPaint(row, y);
1782 current_font = rawtmpfont;
1783 real_current_font = realtmpfont;
1784 setCursor(cursor.par(), cursor.pos() + 1, false,
1788 // check, wether the last characters font has changed.
1789 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1790 && rawparfont != rawtmpfont) {
1791 redoHeightOfParagraph();
1793 // now the special right address boxes
1794 if (cursor.par()->layout()->margintype
1795 == MARGIN_RIGHT_ADDRESS_BOX) {
1796 redoDrawingOfParagraph(cursor);
1804 void LyXText::charInserted()
1806 // Here we could call FinishUndo for every 20 characters inserted.
1807 // This is from my experience how emacs does it.
1808 static unsigned int counter;
1818 void LyXText::prepareToPrint(RowList::iterator rit, float & x,
1819 float & fill_separator,
1821 float & fill_label_hfill,
1826 float w = rit->fill();
1828 fill_label_hfill = 0;
1830 fill_label_hfill = 0;
1833 rit->par()->isRightToLeftPar(bv()->buffer()->params);
1835 x = (workWidth() > 0)
1836 ? rightMargin(*bv()->buffer(), *rit) : 0;
1838 x = (workWidth() > 0)
1839 ? leftMargin(*rit) : 0;
1841 // is there a manual margin with a manual label
1842 LyXLayout_ptr const & layout = rit->par()->layout();
1844 if (layout->margintype == MARGIN_MANUAL
1845 && layout->labeltype == LABEL_MANUAL) {
1846 /// We might have real hfills in the label part
1847 nlh = numberOfLabelHfills(*this, rit);
1849 // A manual label par (e.g. List) has an auto-hfill
1850 // between the label text and the body of the
1852 // But we don't want to do this auto hfill if the par
1854 if (!rit->par()->empty())
1857 if (nlh && !rit->par()->getLabelWidthString().empty()) {
1858 fill_label_hfill = labelFill(*rit) / nlh;
1862 // are there any hfills in the row?
1863 float const nh = numberOfHfills(*this, rit);
1867 fill_hfill = w / nh;
1868 // we don't have to look at the alignment if it is ALIGN_LEFT and
1869 // if the row is already larger then the permitted width as then
1870 // we force the LEFT_ALIGN'edness!
1871 } else if (static_cast<int>(rit->width()) < workWidth()) {
1872 // is it block, flushleft or flushright?
1873 // set x how you need it
1875 if (rit->par()->params().align() == LYX_ALIGN_LAYOUT) {
1876 align = layout->align;
1878 align = rit->par()->params().align();
1881 // center displayed insets
1883 if (rit->pos() < rit->par()->size()
1884 && rit->par()->isInset(rit->pos())
1885 && (inset = rit->par()->getInset(rit->pos()))
1886 && (inset->display())) // || (inset->scroll() < 0)))
1887 align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
1888 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1889 // ERT insets should always be LEFT ALIGNED on screen
1890 inset = rit->par()->inInset();
1891 if (inset && inset->owner() &&
1892 inset->owner()->lyxCode() == Inset::ERT_CODE)
1894 align = LYX_ALIGN_LEFT;
1898 case LYX_ALIGN_BLOCK:
1900 float const ns = numberOfSeparators(*this, rit);
1901 RowList::iterator next_row = boost::next(rit);
1903 if (ns && next_row != rowlist_.end() &&
1904 next_row->par() == rit->par() &&
1905 !(next_row->par()->isNewline(next_row->pos() - 1))
1906 && !(next_row->par()->isInset(next_row->pos()) &&
1907 next_row->par()->getInset(next_row->pos()) &&
1908 next_row->par()->getInset(next_row->pos())->display())
1910 fill_separator = w / ns;
1911 } else if (is_rtl) {
1916 case LYX_ALIGN_RIGHT:
1919 case LYX_ALIGN_CENTER:
1927 computeBidiTables(bv()->buffer(), rit);
1929 pos_type body_pos = rit->par()->beginningOfBody();
1930 pos_type last = lastPos(*this, rit);
1933 (body_pos - 1 > last ||
1934 !rit->par()->isLineSeparator(body_pos - 1))) {
1935 x += font_metrics::width(layout->labelsep,
1936 getLabelFont(bv()->buffer(),
1938 if (body_pos - 1 <= last)
1939 x += fill_label_hfill;
1945 // important for the screen
1948 // the cursor set functions have a special mechanism. When they
1949 // realize, that you left an empty paragraph, they will delete it.
1950 // They also delete the corresponding row
1952 void LyXText::cursorRightOneWord()
1954 // treat floats, HFills and Insets as words
1955 LyXCursor tmpcursor = cursor;
1956 // CHECK See comment on top of text.C
1958 if (tmpcursor.pos() == tmpcursor.par()->size()
1959 && boost::next(tmpcursor.par()) != ownerParagraphs().end()) {
1960 tmpcursor.par(boost::next(tmpcursor.par()));
1965 // Skip through initial nonword stuff.
1966 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1967 ! tmpcursor.par()->isWord(tmpcursor.pos())) {
1968 // printf("Current pos1 %d", tmpcursor.pos()) ;
1969 tmpcursor.pos(tmpcursor.pos() + 1);
1972 // Advance through word.
1973 while (tmpcursor.pos() < tmpcursor.par()->size() &&
1974 tmpcursor.par()->isWord(tmpcursor.pos())) {
1975 // printf("Current pos2 %d", tmpcursor.pos()) ;
1976 tmpcursor.pos(tmpcursor.pos() + 1);
1980 setCursor(tmpcursor.par(), tmpcursor.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
1999 && (cur.par()->isSeparator(cur.pos() - 1)
2000 || cur.par()->isKomma(cur.pos() - 1)
2001 || cur.par()->isNewline(cur.pos() - 1))
2002 && !(cur.par()->isHfill(cur.pos() - 1)
2003 || cur.par()->isInset(cur.pos() - 1)))
2004 cur.pos(cur.pos() - 1);
2007 && (cur.par()->isInset(cur.pos() - 1)
2008 || cur.par()->isHfill(cur.pos() - 1))) {
2009 cur.pos(cur.pos() - 1);
2010 } else if (!cur.pos()) {
2011 if (cur.par() != ownerParagraphs().begin()) {
2012 cur.par(boost::prior(cur.par()));
2013 cur.pos(cur.par()->size());
2015 } else { // Here, cur != 0
2016 while (cur.pos() > 0 &&
2017 cur.par()->isWord(cur.pos() - 1))
2018 cur.pos(cur.pos() - 1);
2023 // Select current word. This depends on behaviour of
2024 // CursorLeftOneWord(), so it is patched as well.
2025 void LyXText::getWord(LyXCursor & from, LyXCursor & to,
2026 word_location const loc)
2028 // first put the cursor where we wana start to select the word
2031 case WHOLE_WORD_STRICT:
2032 if (cursor.pos() == 0 || cursor.pos() == cursor.par()->size()
2033 || cursor.par()->isSeparator(cursor.pos())
2034 || cursor.par()->isKomma(cursor.pos())
2035 || cursor.par()->isNewline(cursor.pos())
2036 || cursor.par()->isSeparator(cursor.pos() - 1)
2037 || cursor.par()->isKomma(cursor.pos() - 1)
2038 || cursor.par()->isNewline(cursor.pos() - 1)) {
2042 // no break here, we go to the next
2045 // Move cursor to the beginning, when not already there.
2046 if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
2047 && !(from.par()->isKomma(from.pos() - 1)
2048 || from.par()->isNewline(from.pos() - 1)))
2049 cursorLeftOneWord(from);
2052 // always move the cursor to the beginning of previous word
2053 cursorLeftOneWord(from);
2056 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
2062 while (to.pos() < to.par()->size()
2063 && !to.par()->isSeparator(to.pos())
2064 && !to.par()->isKomma(to.pos())
2065 && !to.par()->isNewline(to.pos())
2066 && !to.par()->isHfill(to.pos())
2067 && !to.par()->isInset(to.pos()))
2069 to.pos(to.pos() + 1);
2074 void LyXText::selectWord(word_location loc)
2078 getWord(from, to, loc);
2080 setCursor(from.par(), from.pos());
2083 selection.cursor = cursor;
2084 setCursor(to.par(), to.pos());
2089 // Select the word currently under the cursor when no
2090 // selection is currently set
2091 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2093 if (!selection.set()) {
2095 return selection.set();
2101 void LyXText::acceptChange()
2103 if (!selection.set() && cursor.par()->size())
2108 if (selection.start.par() == selection.end.par()) {
2109 LyXCursor & startc = selection.start;
2110 LyXCursor & endc = selection.end;
2111 setUndo(bv(), Undo::INSERT, &*startc.par(), &*boost::next(startc.par()));
2112 startc.par()->acceptChange(startc.pos(), endc.pos());
2115 redoParagraphs(startc, boost::next(startc.par()));
2116 setCursorIntern(startc.par(), 0);
2118 #warning handle multi par selection
2122 void LyXText::rejectChange()
2124 if (!selection.set() && cursor.par()->size())
2129 if (selection.start.par() == selection.end.par()) {
2130 LyXCursor & startc = selection.start;
2131 LyXCursor & endc = selection.end;
2132 setUndo(bv(), Undo::INSERT, &*startc.par(),
2133 &*boost::next(startc.par()));
2134 startc.par()->rejectChange(startc.pos(), endc.pos());
2137 redoParagraphs(startc, boost::next(startc.par()));
2138 setCursorIntern(startc.par(), 0);
2140 #warning handle multi par selection
2144 // This function is only used by the spellchecker for NextWord().
2145 // It doesn't handle LYX_ACCENTs and probably never will.
2147 LyXText::selectNextWordToSpellcheck(float & value)
2149 if (the_locking_inset) {
2150 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2151 if (!word.word().empty()) {
2152 value += float(cursor.y());
2153 value /= float(height);
2156 // we have to go on checking so move cursor to the next char
2157 if (cursor.pos() == cursor.par()->size()) {
2158 if (boost::next(cursor.par()) == ownerParagraphs().end())
2160 cursor.par(boost::next(cursor.par()));
2163 cursor.pos(cursor.pos() + 1);
2165 ParagraphList::iterator tmppit = cursor.par();
2167 // If this is not the very first word, skip rest of
2168 // current word because we are probably in the middle
2169 // of a word if there is text here.
2170 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
2171 while (cursor.pos() < cursor.par()->size()
2172 && cursor.par()->isLetter(cursor.pos()))
2173 cursor.pos(cursor.pos() + 1);
2176 // Now, skip until we have real text (will jump paragraphs)
2178 ParagraphList::iterator cpit = cursor.par();
2179 pos_type const cpos(cursor.pos());
2181 if (cpos == cpit->size()) {
2182 if (boost::next(cpit) != ownerParagraphs().end()) {
2183 cursor.par(boost::next(cpit));
2190 bool const is_good_inset = cpit->isInset(cpos)
2191 && cpit->getInset(cpos)->allowSpellcheck();
2193 if (!isDeletedText(*cpit, cpos)
2194 && (is_good_inset || cpit->isLetter(cpos)))
2197 cursor.pos(cpos + 1);
2200 // now check if we hit an inset so it has to be a inset containing text!
2201 if (cursor.pos() < cursor.par()->size() &&
2202 cursor.par()->isInset(cursor.pos())) {
2204 cursor.par()->getInset(cursor.pos())->edit(bv());
2205 // now call us again to do the above trick
2206 // but obviously we have to start from down below ;)
2207 return bv()->text->selectNextWordToSpellcheck(value);
2210 // Update the value if we changed paragraphs
2211 if (cursor.par() != tmppit) {
2212 setCursor(cursor.par(), cursor.pos());
2213 value = float(cursor.y())/float(height);
2216 // Start the selection from here
2217 selection.cursor = cursor;
2220 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2221 .language()->code());
2222 // and find the end of the word (insets like optional hyphens
2223 // and ligature break are part of a word)
2224 while (cursor.pos() < cursor.par()->size()
2225 && cursor.par()->isLetter(cursor.pos())
2226 && !isDeletedText(*cursor.par(), cursor.pos()))
2227 cursor.pos(cursor.pos() + 1);
2229 // Finally, we copy the word to a string and return it
2231 if (selection.cursor.pos() < cursor.pos()) {
2233 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2234 if (!cursor.par()->isInset(i))
2235 str += cursor.par()->getChar(i);
2238 return WordLangTuple(str, lang_code);
2242 // This one is also only for the spellchecker
2243 void LyXText::selectSelectedWord()
2245 if (the_locking_inset) {
2246 the_locking_inset->selectSelectedWord(bv());
2249 // move cursor to the beginning
2250 setCursor(selection.cursor.par(), selection.cursor.pos());
2252 // set the sel cursor
2253 selection.cursor = cursor;
2255 // now find the end of the word
2256 while (cursor.pos() < cursor.par()->size()
2257 && (cursor.par()->isLetter(cursor.pos())))
2258 cursor.pos(cursor.pos() + 1);
2260 setCursor(cursor.par(), cursor.pos());
2262 // finally set the selection
2267 // Delete from cursor up to the end of the current or next word.
2268 void LyXText::deleteWordForward()
2270 if (cursor.par()->empty())
2273 LyXCursor tmpcursor = cursor;
2274 tmpcursor.row(0); //Â ??
2275 selection.set(true); // to avoid deletion
2276 cursorRightOneWord();
2277 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2278 selection.cursor = cursor;
2282 // Great, CutSelection() gets rid of multiple spaces.
2283 cutSelection(true, false);
2288 // Delete from cursor to start of current or prior word.
2289 void LyXText::deleteWordBackward()
2291 if (cursor.par()->empty())
2294 LyXCursor tmpcursor = cursor;
2295 tmpcursor.row(0); // ??
2296 selection.set(true); // to avoid deletion
2297 cursorLeftOneWord();
2298 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2299 selection.cursor = cursor;
2302 cutSelection(true, false);
2307 // Kill to end of line.
2308 void LyXText::deleteLineForward()
2310 if (cursor.par()->empty())
2311 // Paragraph is empty, so we just go to the right
2314 LyXCursor tmpcursor = cursor;
2315 // We can't store the row over a regular setCursor
2316 // so we set it to 0 and reset it afterwards.
2317 tmpcursor.row(0); //Â ??
2318 selection.set(true); // to avoid deletion
2320 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2321 selection.cursor = cursor;
2324 // What is this test for ??? (JMarc)
2325 if (!selection.set()) {
2326 deleteWordForward();
2328 cutSelection(true, false);
2334 void LyXText::changeCase(LyXText::TextCase action)
2339 if (selection.set()) {
2340 from = selection.start;
2343 getWord(from, to, PARTIAL_WORD);
2344 setCursor(to.par(), to.pos() + 1);
2347 lyx::Assert(from <= to);
2349 setUndo(bv(), Undo::FINISH, &*from.par(), &*boost::next(to.par()));
2351 pos_type pos = from.pos();
2352 ParagraphList::iterator pit = from.par();
2354 while (pit != ownerParagraphs().end() &&
2355 (pos != to.pos() || pit != to.par())) {
2356 if (pos == pit->size()) {
2361 unsigned char c = pit->getChar(pos);
2362 if (!IsInsetChar(c)) {
2364 case text_lowercase:
2367 case text_capitalization:
2369 action = text_lowercase;
2371 case text_uppercase:
2377 pit->setChar(pos, c);
2378 checkParagraph(&*pit, pos);
2383 if (to.row() != from.row())
2384 postPaint(from.y() - from.row()->baseline());
2388 void LyXText::Delete()
2390 // this is a very easy implementation
2392 LyXCursor old_cursor = cursor;
2393 int const old_cur_par_id = old_cursor.par()->id();
2394 int const old_cur_par_prev_id =
2395 (old_cursor.par() != ownerParagraphs().begin() ?
2396 boost::prior(old_cursor.par())->id() : -1);
2398 // just move to the right
2401 // CHECK Look at the comment here.
2402 // This check is not very good...
2403 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2404 // and that can very well delete the par or par->previous in
2405 // old_cursor. Will a solution where we compare paragraph id's
2407 if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
2408 == old_cur_par_prev_id
2409 && cursor.par()->id() != old_cur_par_id) {
2410 // delete-empty-paragraph-mechanism has done it
2414 // if you had success make a backspace
2415 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2416 LyXCursor tmpcursor = cursor;
2417 // to make sure undo gets the right cursor position
2418 cursor = old_cursor;
2419 setUndo(bv(), Undo::DELETE,
2420 &*cursor.par(), &*boost::next(cursor.par()));
2427 void LyXText::backspace()
2429 // Get the font that is used to calculate the baselineskip
2430 pos_type lastpos = cursor.par()->size();
2431 LyXFont rawparfont =
2432 cursor.par()->getFontSettings(bv()->buffer()->params,
2435 if (cursor.pos() == 0) {
2436 // The cursor is at the beginning of a paragraph,
2437 // so the the backspace will collapse two paragraphs into one.
2439 // but it's not allowed unless it's new
2440 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2443 // we may paste some paragraphs
2445 // is it an empty paragraph?
2448 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2449 // This is an empty paragraph and we delete it just by moving the cursor one step
2450 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2451 // of the paragraph.
2453 if (cursor.par() != ownerParagraphs().begin()) {
2454 ParagraphList::iterator tmppit = boost::prior(cursor.par());
2455 if (cursor.par()->layout() == tmppit->layout()
2456 && cursor.par()->getAlign() == tmppit->getAlign()) {
2457 // Inherit bottom DTD from the paragraph below.
2458 // (the one we are deleting)
2459 tmppit->params().lineBottom(cursor.par()->params().lineBottom());
2460 tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
2461 tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2466 // the layout things can change the height of a row !
2467 int const tmpheight = cursor.row()->height();
2468 setHeightOfRow(cursor.row());
2469 if (cursor.row()->height() != tmpheight) {
2470 postPaint(cursor.y() - cursor.row()->baseline());
2476 if (cursor.par() != ownerParagraphs().begin()) {
2477 setUndo(bv(), Undo::DELETE,
2478 &*boost::prior(cursor.par()),
2479 &*boost::next(cursor.par()));
2482 ParagraphList::iterator tmppit = cursor.par();
2483 RowList::iterator tmprow = cursor.row();
2485 // We used to do cursorLeftIntern() here, but it is
2486 // not a good idea since it triggers the auto-delete
2487 // mechanism. So we do a cursorLeftIntern()-lite,
2488 // without the dreaded mechanism. (JMarc)
2489 if (cursor.par() != ownerParagraphs().begin()) {
2490 // steps into the above paragraph.
2491 setCursorIntern(boost::prior(cursor.par()),
2492 boost::prior(cursor.par())->size(),
2496 // Pasting is not allowed, if the paragraphs have different
2497 // layout. I think it is a real bug of all other
2498 // word processors to allow it. It confuses the user.
2499 // Even so with a footnote paragraph and a non-footnote
2500 // paragraph. I will not allow pasting in this case,
2501 // because the user would be confused if the footnote behaves
2502 // different wether it is open or closed.
2504 // Correction: Pasting is always allowed with standard-layout
2505 LyXTextClass const & tclass =
2506 bv()->buffer()->params.getLyXTextClass();
2508 if (cursor.par() != tmppit
2509 && (cursor.par()->layout() == tmppit->layout()
2510 || tmppit->layout() == tclass.defaultLayout())
2511 && cursor.par()->getAlign() == tmppit->getAlign()) {
2512 removeParagraph(tmprow);
2514 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2516 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2517 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2518 // strangely enough it seems that commenting out the line above removes
2519 // most or all of the segfaults. I will however also try to move the
2520 // two Remove... lines in front of the PasteParagraph too.
2523 cursor.pos(cursor.pos() - 1);
2525 postPaint(cursor.y() - cursor.row()->baseline());
2527 // remove the lost paragraph
2528 // This one is not safe, since the paragraph that the tmprow and the
2529 // following rows belong to has been deleted by the PasteParagraph
2530 // above. The question is... could this be moved in front of the
2532 //RemoveParagraph(tmprow);
2533 //RemoveRow(tmprow);
2535 // This rebuilds the rows.
2536 appendParagraph(cursor.row());
2539 // the row may have changed, block, hfills etc.
2540 setCursor(cursor.par(), cursor.pos(), false);
2543 // this is the code for a normal backspace, not pasting
2545 setUndo(bv(), Undo::DELETE,
2546 &*cursor.par(), &*boost::next(cursor.par()));
2547 // We used to do cursorLeftIntern() here, but it is
2548 // not a good idea since it triggers the auto-delete
2549 // mechanism. So we do a cursorLeftIntern()-lite,
2550 // without the dreaded mechanism. (JMarc)
2551 setCursorIntern(cursor.par(), cursor.pos()- 1,
2552 false, cursor.boundary());
2554 if (cursor.par()->isInset(cursor.pos())) {
2555 // force complete redo when erasing display insets
2556 // this is a cruel method but safe..... Matthias
2557 if (cursor.par()->getInset(cursor.pos())->display() ||
2558 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2559 cursor.par()->erase(cursor.pos());
2565 RowList::iterator row = cursor.row();
2566 int y = cursor.y() - row->baseline();
2568 // remember that a space at the end of a row doesnt count
2569 // when calculating the fill
2570 if (cursor.pos() < lastPos(*this, row) ||
2571 !cursor.par()->isLineSeparator(cursor.pos())) {
2572 row->fill(row->fill() + singleWidth(
2577 // some special code when deleting a newline. This is similar
2578 // to the behavior when pasting paragraphs
2579 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2580 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);
2588 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2589 cursor.pos(cursor.pos() - 1);
2591 if (cursor.pos() < cursor.par()->size()
2592 && !cursor.par()->isSeparator(cursor.pos())) {
2593 cursor.par()->insertChar(cursor.pos(), ' ');
2594 setCharFont(bv()->buffer(), &*cursor.par(),
2595 cursor.pos(), current_font);
2596 // refresh the positions
2598 while (boost::next(tmprow) != rows().end() &&
2599 boost::next(tmprow)->par() == row->par()) {
2601 tmprow->pos(tmprow->pos() + 1);
2605 cursor.par()->erase(cursor.pos());
2607 // refresh the positions
2608 RowList::iterator tmprow = row;
2609 while (boost::next(tmprow) != rows().end() &&
2610 boost::next(tmprow)->par() == row->par()) {
2612 tmprow->pos(tmprow->pos() - 1);
2615 // delete newlines at the beginning of paragraphs
2616 while (!cursor.par()->empty() &&
2617 cursor.pos() < cursor.par()->size() &&
2618 cursor.par()->isNewline(cursor.pos()) &&
2619 cursor.pos() == cursor.par()->beginningOfBody()) {
2620 cursor.par()->erase(cursor.pos());
2621 // refresh the positions
2623 while (boost::next(tmprow) != rows().end() &&
2624 boost::next(tmprow)->par() == row->par()) {
2626 tmprow->pos(tmprow->pos() - 1);
2631 // is there a break one row above
2632 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2633 z = rowBreakPoint(*boost::prior(row));
2634 if (z >= row->pos()) {
2637 RowList::iterator tmprow = boost::prior(row);
2639 // maybe the current row is now empty
2640 if (row->pos() >= row->par()->size()) {
2643 need_break_row = rows().end();
2645 breakAgainOneRow(row);
2646 if (boost::next(row) != rows().end() &&
2647 boost::next(row)->par() == row->par())
2648 need_break_row = boost::next(row);
2650 need_break_row = rows().end();
2653 // set the dimensions of the row above
2654 y -= tmprow->height();
2655 tmprow->fill(fill(tmprow, workWidth()));
2656 setHeightOfRow(tmprow);
2660 setCursor(cursor.par(), cursor.pos(),
2661 false, cursor.boundary());
2662 //current_font = rawtmpfont;
2663 //real_current_font = realtmpfont;
2664 // check, whether the last character's font has changed.
2666 cursor.par()->getFontSettings(bv()->buffer()->params,
2667 cursor.par()->size() - 1))
2668 redoHeightOfParagraph();
2673 // break the cursor row again
2674 if (boost::next(row) != rows().end() &&
2675 boost::next(row)->par() == row->par() &&
2676 (lastPos(*this, row) == row->par()->size() - 1 ||
2677 rowBreakPoint(*row) != lastPos(*this, row))) {
2679 // it can happen that a paragraph loses one row
2680 // without a real breakup. This is when a word
2681 // is to long to be broken. Well, I don t care this
2683 if (lastPos(*this, row) == row->par()->size() - 1)
2684 removeRow(boost::next(row));
2688 breakAgainOneRow(row);
2689 // will the cursor be in another row now?
2690 if (boost::next(row) != rows().end() &&
2691 boost::next(row)->par() == row->par() &&
2692 lastPos(*this, row) <= cursor.pos()) {
2694 breakAgainOneRow(row);
2697 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2699 if (boost::next(row) != rows().end() &&
2700 boost::next(row)->par() == row->par())
2701 need_break_row = boost::next(row);
2703 need_break_row = rows().end();
2705 // set the dimensions of the row
2706 row->fill(fill(row, workWidth()));
2707 int const tmpheight = row->height();
2708 setHeightOfRow(row);
2709 if (tmpheight == row->height()) {
2710 postRowPaint(row, y);
2714 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2718 // current_font = rawtmpfont;
2719 // real_current_font = realtmpfont;
2721 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
2722 != cursor.boundary())
2723 setCursor(cursor.par(), cursor.pos(), false,
2724 !cursor.boundary());
2726 lastpos = cursor.par()->size();
2727 if (cursor.pos() == lastpos)
2730 // check, whether the last characters font has changed.
2732 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2733 redoHeightOfParagraph();
2735 // now the special right address boxes
2736 if (cursor.par()->layout()->margintype
2737 == MARGIN_RIGHT_ADDRESS_BOX) {
2738 redoDrawingOfParagraph(cursor);
2744 // returns pointer to a specified row
2746 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2751 return rowlist_.end();
2753 // find the first row of the specified paragraph
2754 RowList::iterator rit = rowlist_.begin();
2755 RowList::iterator end = rowlist_.end();
2756 while (boost::next(rit) != end && rit->par() != pit) {
2761 // now find the wanted row
2762 while (rit->pos() < pos
2763 && boost::next(rit) != end
2764 && boost::next(rit)->par() == pit
2765 && boost::next(rit)->pos() <= pos) {
2774 RowList::iterator LyXText::getRowNearY(int & y) const
2777 RowList::iterator rit = anchor_row_;
2778 RowList::iterator const beg = rows().begin();
2779 RowList::iterator const end = rows().end();
2781 if (rows().empty()) {
2788 int tmpy = rit->y();
2791 while (rit != end && tmpy <= y) {
2792 tmpy += rit->height();
2797 tmpy -= rit->height();
2800 while (rit != beg && tmpy > y) {
2802 tmpy -= rit->height();
2805 if (tmpy < 0 || rit == end) {
2817 int LyXText::getDepth() const
2819 return cursor.par()->getDepth();