1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
15 #include "paragraph.h"
17 #include "bufferparams.h"
23 #include "frontends/LyXView.h"
24 #include "frontends/Painter.h"
25 #include "frontends/font_metrics.h"
26 #include "frontends/screen.h"
27 #include "frontends/WorkArea.h"
28 #include "bufferview_funcs.h"
29 #include "BufferView.h"
31 #include "ParagraphParameters.h"
32 #include "undo_funcs.h"
33 #include "text_funcs.h"
34 #include "WordLangTuple.h"
35 #include "paragraph_funcs.h"
36 #include "rowpainter.h"
37 #include "lyxrow_funcs.h"
38 #include "metricsinfo.h"
40 #include "insets/insettext.h"
42 #include "support/textutils.h"
43 #include "support/LAssert.h"
44 #include "support/lstrings.h"
48 using namespace lyx::support;
56 using lyx::word_location;
58 using namespace bv_funcs;
60 /// top, right, bottom pixel margin
61 extern int const PAPER_MARGIN = 20;
62 /// margin for changebar
63 extern int const CHANGEBAR_MARGIN = 10;
65 extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
67 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
70 BufferView * LyXText::bv()
72 Assert(bv_owner != 0);
77 BufferView * LyXText::bv() const
79 Assert(bv_owner != 0);
84 void LyXText::updateRowPositions()
86 RowList::iterator rit = rows().begin();
87 RowList::iterator rend = rows().end();
88 for (int y = 0; rit != rend ; ++rit) {
95 int LyXText::top_y() const
97 if (anchor_row_ == rowlist_.end())
100 return anchor_row_->y() + anchor_row_offset_;
104 void LyXText::top_y(int newy)
110 anchor_row_ = rows().begin();
111 anchor_row_offset_ = newy;
115 lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
118 RowList::iterator rit = getRowNearY(y);
120 if (rit == anchor_row_ && anchor_row_offset_ == newy - y) {
121 lyxerr[Debug::GUI] << "top_y to same value, skipping update" << endl;
126 anchor_row_offset_ = newy - y;
127 lyxerr[Debug::GUI] << "changing reference to row: " << &*anchor_row_
128 << " offset: " << anchor_row_offset_ << endl;
133 void LyXText::anchor_row(RowList::iterator rit)
136 anchor_row_offset_ = 0;
138 anchor_row_offset_ = old_y - top_y();
139 lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
140 << &*anchor_row_ << " offset: "
141 << anchor_row_offset_ << endl;
145 int LyXText::workWidth() const
147 return inset_owner ? inset_owner->textWidth() : bv()->workWidth();
151 int LyXText::workWidth(Inset const * inset) const
153 ParagraphList::iterator par = std::find(ownerParagraphs().begin(),
154 ownerParagraphs().end(),
156 if (par == ownerParagraphs().end()) {
157 lyxerr[Debug::GUI] << "LyXText::workWidth: unexpected\n";
161 pos_type pos = par->getPositionOfInset(inset);
164 LyXLayout_ptr const & layout = par->layout();
166 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
167 // Optimization here: in most cases, the real row is
168 // not needed, but only the par/pos values. So we just
169 // construct a dummy row for leftMargin. (JMarc)
173 return workWidth() - leftMargin(dummyrow);
176 RowList::iterator row = getRow(par, pos, dummy_y);
177 RowList::iterator frow = row;
178 RowList::iterator beg = rowlist_.begin();
180 while (frow != beg && frow->par() == boost::prior(frow)->par())
183 // FIXME: I don't understand this code - jbl
185 unsigned int maxw = 0;
186 while (!isParEnd(*this, frow)) {
187 if ((frow != row) && (maxw < frow->width()))
188 maxw = frow->width();
199 int LyXText::getRealCursorX() const
202 if (the_locking_inset && (the_locking_inset->getLyXText(bv())!= this))
203 x = the_locking_inset->getLyXText(bv())->getRealCursorX();
208 #warning FIXME This function seems to belong outside of LyxText.
209 unsigned char LyXText::transformChar(unsigned char c, Paragraph const & par,
212 if (!Encodings::is_arabic(c))
213 if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && IsDigit(c))
214 return c + (0xb0 - '0');
218 unsigned char const prev_char = pos > 0 ? par.getChar(pos - 1) : ' ';
219 unsigned char next_char = ' ';
221 pos_type const par_size = par.size();
223 for (pos_type i = pos + 1; i < par_size; ++i) {
224 unsigned char const par_char = par.getChar(i);
225 if (!Encodings::IsComposeChar_arabic(par_char)) {
226 next_char = par_char;
231 if (Encodings::is_arabic(next_char)) {
232 if (Encodings::is_arabic(prev_char) &&
233 !Encodings::is_arabic_special(prev_char))
234 return Encodings::TransformChar(c, Encodings::FORM_MEDIAL);
236 return Encodings::TransformChar(c, Encodings::FORM_INITIAL);
238 if (Encodings::is_arabic(prev_char) &&
239 !Encodings::is_arabic_special(prev_char))
240 return Encodings::TransformChar(c, Encodings::FORM_FINAL);
242 return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
246 // This is the comments that some of the warnings below refers to.
247 // There are some issues in this file and I don't think they are
248 // really related to the FIX_DOUBLE_SPACE patch. I'd rather think that
249 // this is a problem that has been here almost from day one and that a
250 // larger userbase with differenct access patters triggers the bad
251 // behaviour. (segfaults.) What I think happen is: In several places
252 // we store the paragraph in the current cursor and then moves the
253 // cursor. This movement of the cursor will delete paragraph at the
254 // old position if it is now empty. This will make the temporary
255 // pointer to the old cursor paragraph invalid and dangerous to use.
256 // And is some cases this will trigger a segfault. I have marked some
257 // of the cases where this happens with a warning, but I am sure there
258 // are others in this file and in text2.C. There is also a note in
259 // Delete() that you should read. In Delete I store the paragraph->id
260 // instead of a pointer to the paragraph. I am pretty sure this faulty
261 // use of temporary pointers to paragraphs that might have gotten
262 // invalidated (through a cursor movement) before they are used, are
263 // the cause of the strange crashes we get reported often.
265 // It is very tiresom to change this code, especially when it is as
266 // hard to read as it is. Help to fix all the cases where this is done
267 // would be greately appreciated.
271 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
273 if (pos >= pit->size())
276 char const c = pit->getChar(pos);
277 return singleWidth(pit, pos, c);
281 int LyXText::singleWidth(ParagraphList::iterator pit,
282 pos_type pos, char c) const
284 if (pos >= pit->size())
287 LyXFont const font = getFont(bv()->buffer(), pit, pos);
289 // The most common case is handled first (Asger)
290 if (IsPrintable(c)) {
291 if (font.language()->RightToLeft()) {
292 if (font.language()->lang() == "arabic" &&
293 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
294 lyxrc.font_norm_type == LyXRC::ISO_10646_1)) {
295 if (Encodings::IsComposeChar_arabic(c))
298 c = transformChar(c, *pit, pos);
299 } else if (font.language()->lang() == "hebrew" &&
300 Encodings::IsComposeChar_hebrew(c))
303 return font_metrics::width(c, font);
307 if (c == Paragraph::META_INSET) {
308 Inset * tmpinset = pit->getInset(pos);
310 if (tmpinset->lyxCode() == Inset::HFILL_CODE) {
311 // Because of the representation as vertical lines
315 #warning inset->update FIXME
316 // this IS needed otherwise on initialitation we don't get the fill
317 // of the row right (ONLY on initialization if we read a file!)
318 // should be changed! (Jug 20011204)
319 //tmpinset->update(bv());
321 MetricsInfo mi(bv(), font, workWidth());
322 tmpinset->metrics(mi, dim);
325 return tmpinset->width();
331 if (IsSeparatorChar(c))
333 return font_metrics::width(c, font);
337 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
339 if (bidi_start == -1)
342 return log2vis_list[pos - bidi_start];
346 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
348 if (bidi_start == -1)
351 return vis2log_list[pos - bidi_start];
355 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
357 if (bidi_start == -1)
360 return bidi_levels[pos - bidi_start];
364 bool LyXText::bidi_InRange(lyx::pos_type pos) const
366 return bidi_start == -1 ||
367 (bidi_start <= pos && pos <= bidi_end);
371 void LyXText::computeBidiTables(Buffer const * buf,
372 RowList::iterator row) const
374 bidi_same_direction = true;
375 if (!lyxrc.rtl_support) {
380 ParagraphList::iterator row_par = row->par();
382 Inset * inset = row_par->inInset();
383 if (inset && inset->owner() &&
384 inset->owner()->lyxCode() == Inset::ERT_CODE) {
389 bidi_start = row->pos();
390 bidi_end = lastPrintablePos(*this, row);
392 if (bidi_start > bidi_end) {
397 if (bidi_end + 2 - bidi_start >
398 static_cast<pos_type>(log2vis_list.size())) {
400 (bidi_end + 2 - bidi_start < 500) ?
401 500 : 2 * (bidi_end + 2 - bidi_start);
402 log2vis_list.resize(new_size);
403 vis2log_list.resize(new_size);
404 bidi_levels.resize(new_size);
407 vis2log_list[bidi_end + 1 - bidi_start] = -1;
408 log2vis_list[bidi_end + 1 - bidi_start] = -1;
412 row_par->isRightToLeftPar(buf->params);
416 pos_type const body_pos = row_par->beginningOfBody();
418 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
419 bool is_space = row_par->isLineSeparator(lpos);
421 (is_space && lpos + 1 <= bidi_end &&
422 !row_par->isLineSeparator(lpos + 1) &&
423 !row_par->isNewline(lpos + 1))
425 LyXFont font = row_par->getFontSettings(buf->params, pos);
426 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
427 font.number() == LyXFont::ON &&
428 row_par->getFontSettings(buf->params, lpos - 1).number()
430 font = row_par->getFontSettings(buf->params, lpos);
435 bool new_rtl = font.isVisibleRightToLeft();
436 bool new_rtl0 = font.isRightToLeft();
439 if (lpos == body_pos - 1
440 && row->pos() < body_pos - 1
442 new_level = (rtl_par) ? 1 : 0;
443 new_rtl = new_rtl0 = rtl_par;
445 new_level = (new_rtl) ? 1 : 2;
447 new_level = (rtl_par) ? 2 : 0;
449 if (is_space && new_level >= level) {
455 int new_level2 = new_level;
457 if (level == new_level && rtl0 != new_rtl0) {
459 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
460 } else if (level < new_level) {
461 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
462 if (new_level > rtl_par)
463 bidi_same_direction = false;
465 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
468 bidi_levels[lpos - bidi_start] = new_level;
470 while (level > new_level2) {
471 pos_type old_lpos = stack[--level];
472 int delta = lpos - old_lpos - 1;
475 log2vis_list[lpos - bidi_start] += delta;
476 log2vis_list[old_lpos - bidi_start] += delta;
478 while (level < new_level)
479 stack[level++] = lpos;
483 pos_type const old_lpos = stack[--level];
484 int delta = bidi_end - old_lpos;
487 log2vis_list[old_lpos - bidi_start] += delta;
490 pos_type vpos = bidi_start - 1;
491 for (pos_type lpos = bidi_start;
492 lpos <= bidi_end; ++lpos) {
493 vpos += log2vis_list[lpos - bidi_start];
494 vis2log_list[vpos - bidi_start] = lpos;
495 log2vis_list[lpos - bidi_start] = vpos;
500 // This method requires a previous call to ComputeBidiTables()
501 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
504 if (!lyxrc.rtl_support || pos == 0)
507 if (!bidi_InRange(pos - 1)) {
508 /// This can happen if pos is the first char of a row.
509 /// Returning false in this case is incorrect!
513 bool const rtl = bidi_level(pos - 1) % 2;
514 bool const rtl2 = bidi_InRange(pos)
515 ? bidi_level(pos) % 2
516 : par.isRightToLeftPar(buf->params);
521 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
522 pos_type pos, LyXFont const & font) const
524 if (!lyxrc.rtl_support)
525 return false; // This is just for speedup
527 bool const rtl = font.isVisibleRightToLeft();
528 bool const rtl2 = bidi_InRange(pos)
529 ? bidi_level(pos) % 2
530 : par.isRightToLeftPar(buf->params);
535 int LyXText::leftMargin(Row const & row) const
539 if (row.pos() < row.par()->size())
540 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
541 (ins = row.par()->getInset(row.pos())) &&
542 (ins->needFullRow() || ins->display()))
545 LyXTextClass const & tclass =
546 bv()->buffer()->params.getLyXTextClass();
547 LyXLayout_ptr const & layout = row.par()->layout();
549 string parindent = layout->parindent;
553 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
555 // this is the way, LyX handles the LaTeX-Environments.
556 // I have had this idea very late, so it seems to be a
557 // later added hack and this is true
558 if (!row.par()->getDepth()) {
559 if (row.par()->layout() == tclass.defaultLayout()) {
560 // find the previous same level paragraph
561 if (row.par() != ownerParagraphs().begin()) {
562 ParagraphList::iterator newpit =
563 depthHook(row.par(), ownerParagraphs(),
564 row.par()->getDepth());
565 if (newpit == row.par() &&
566 newpit->layout()->nextnoindent)
571 // find the next level paragraph
573 ParagraphList::iterator newpar = outerHook(row.par(),
576 // make a corresponding row. Needed to call leftMargin()
578 // check wether it is a sufficent paragraph
579 if (newpar != ownerParagraphs().end() &&
580 newpar->layout()->isEnvironment()) {
582 dummyrow.par(newpar);
583 dummyrow.pos(newpar->size());
584 x = leftMargin(dummyrow);
587 if (newpar != ownerParagraphs().end() &&
588 row.par()->layout() == tclass.defaultLayout()) {
589 if (newpar->params().noindent())
592 parindent = newpar->layout()->parindent;
598 LyXFont const labelfont = getLabelFont(bv()->buffer(), row.par());
599 switch (layout->margintype) {
601 if (!layout->leftmargin.empty()) {
602 x += font_metrics::signedWidth(layout->leftmargin,
603 tclass.defaultfont());
605 if (!row.par()->getLabelstring().empty()) {
606 x += font_metrics::signedWidth(layout->labelindent,
608 x += font_metrics::width(row.par()->getLabelstring(),
610 x += font_metrics::width(layout->labelsep, labelfont);
614 x += font_metrics::signedWidth(layout->labelindent, labelfont);
615 // The width of an empty par, even with manual label, should be 0
616 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
617 if (!row.par()->getLabelWidthString().empty()) {
618 x += font_metrics::width(row.par()->getLabelWidthString(),
620 x += font_metrics::width(layout->labelsep, labelfont);
625 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
626 / (row.par()->getDepth() + 4);
628 case MARGIN_FIRST_DYNAMIC:
629 if (layout->labeltype == LABEL_MANUAL) {
630 if (row.pos() >= row.par()->beginningOfBody()) {
631 x += font_metrics::signedWidth(layout->leftmargin,
634 x += font_metrics::signedWidth(layout->labelindent,
638 // Special case to fix problems with
640 || (layout->labeltype == LABEL_STATIC
641 && layout->latextype == LATEX_ENVIRONMENT
642 && !isFirstInSequence(row.par(), ownerParagraphs()))) {
643 x += font_metrics::signedWidth(layout->leftmargin,
645 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
646 && layout->labeltype != LABEL_BIBLIO
647 && layout->labeltype !=
648 LABEL_CENTERED_TOP_ENVIRONMENT) {
649 x += font_metrics::signedWidth(layout->labelindent,
651 x += font_metrics::width(layout->labelsep, labelfont);
652 x += font_metrics::width(row.par()->getLabelstring(),
657 case MARGIN_RIGHT_ADDRESS_BOX:
659 // ok, a terrible hack. The left margin depends on the widest
660 // row in this paragraph. Do not care about footnotes, they
661 // are *NOT* allowed in the LaTeX realisation of this layout.
663 // find the first row of this paragraph
664 RowList::iterator tmprit = rowlist_.begin();
665 while (tmprit != rowlist_.end()
666 && tmprit->par() != row.par())
669 int minfill = tmprit->fill();
670 while (boost::next(tmprit) != rowlist_.end() &&
671 boost::next(tmprit)->par() == row.par()) {
673 if (tmprit->fill() < minfill)
674 minfill = tmprit->fill();
677 x += font_metrics::signedWidth(layout->leftmargin,
678 tclass.defaultfont());
684 if ((workWidth() > 0) &&
685 !row.par()->params().leftIndent().zero())
687 LyXLength const len = row.par()->params().leftIndent();
688 int const tw = inset_owner ?
689 inset_owner->latexTextWidth(bv()) : workWidth();
690 x += len.inPixels(tw);
695 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
696 align = layout->align;
698 align = row.par()->params().align();
700 // set the correct parindent
701 if (row.pos() == 0) {
702 if ((layout->labeltype == LABEL_NO_LABEL
703 || layout->labeltype == LABEL_TOP_ENVIRONMENT
704 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
705 || (layout->labeltype == LABEL_STATIC
706 && layout->latextype == LATEX_ENVIRONMENT
707 && !isFirstInSequence(row.par(), ownerParagraphs())))
708 && align == LYX_ALIGN_BLOCK
709 && !row.par()->params().noindent()
710 // in tabulars and ert paragraphs are never indented!
711 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
712 (row.par()->inInset()->owner()->lyxCode() != Inset::TABULAR_CODE &&
713 row.par()->inInset()->owner()->lyxCode() != Inset::ERT_CODE))
714 && (row.par()->layout() != tclass.defaultLayout() ||
715 bv()->buffer()->params.paragraph_separation ==
716 BufferParams::PARSEP_INDENT)) {
717 x += font_metrics::signedWidth(parindent,
718 tclass.defaultfont());
719 } else if (layout->labeltype == LABEL_BIBLIO) {
720 // ale970405 Right width for bibitems
721 x += bibitemMaxWidth(bv(), tclass.defaultfont());
729 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
733 if (row.pos() < row.par()->size())
734 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
735 (ins = row.par()->getInset(row.pos())) &&
736 (ins->needFullRow() || ins->display()))
739 LyXTextClass const & tclass = buf.params.getLyXTextClass();
740 LyXLayout_ptr const & layout = row.par()->layout();
743 + font_metrics::signedWidth(tclass.rightmargin(),
744 tclass.defaultfont());
746 x += font_metrics::signedWidth(layout->rightmargin,
747 tclass.defaultfont())
748 * 4 / (row.par()->getDepth() + 4);
753 int LyXText::labelEnd(Row const & row) const
755 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
757 tmprow.pos(row.par()->size());
758 // return the beginning of the body
759 return leftMargin(tmprow);
762 // LabelEnd is only needed if the layout
763 // fills a flushleft label.
770 // this needs special handling - only newlines count as a break point
771 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
773 for (; i < par.size(); ++i) {
774 if (par.isNewline(i))
784 pos_type LyXText::rowBreakPoint(Row const & row) const
786 ParagraphList::iterator pit = row.par();
788 // maximum pixel width of a row.
789 int width = workWidth() - rightMargin(*bv()->buffer(), row);
791 // inset->textWidth() returns -1 via workWidth(),
796 LyXLayout_ptr const & layout = pit->layout();
798 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
799 return addressBreakPoint(row.pos(), *pit);
801 pos_type const pos = row.pos();
802 pos_type const body_pos = pit->beginningOfBody();
803 pos_type const last = pit->size();
804 pos_type point = last;
809 // Now we iterate through until we reach the right margin
810 // or the end of the par, then choose the possible break
813 int const left = leftMargin(row);
816 // pixel width since last breakpoint
818 bool fullrow = false;
821 for (; i < last; ++i) {
822 if (pit->isNewline(i)) {
827 char const c = pit->getChar(i);
831 // add the auto-hfill from label end to the body
832 if (body_pos && i == body_pos) {
833 thiswidth = font_metrics::width(layout->labelsep,
834 getLabelFont(bv()->buffer(), pit));
835 if (pit->isLineSeparator(i - 1))
836 thiswidth -= singleWidth(pit, i - 1);
837 int left_margin = labelEnd(row);
838 if (thiswidth + x < left_margin)
839 thiswidth = left_margin - x;
840 thiswidth += singleWidth(pit, i, c);
842 thiswidth = singleWidth(pit, i, c);
846 chunkwidth += thiswidth;
848 Inset * in = pit->isInset(i) ? pit->getInset(i) : 0;
849 fullrow = (in && (in->display() || in->needFullRow()));
851 // break before a character that will fall off
852 // the right of the row
854 // if no break before or we are at an inset
855 // that will take up a row, break here
856 if (point == last || fullrow || chunkwidth >= (width - left)) {
865 if (!in || in->isChar()) {
866 // some insets are line separators too
867 if (pit->isLineSeparator(i)) {
877 // full row insets start at a new row
879 if (pos < last - 1) {
881 if (pit->isLineSeparator(i + 1))
884 // to avoid extra rows
894 if (point == last && x >= width) {
895 // didn't find one, break at the point we reached the edge
897 } else if (i == last && x < width) {
898 // found one, but we fell off the end of the par, so prefer
903 // manual labels cannot be broken in LaTeX. But we
904 // want to make our on-screen rendering of footnotes
906 if (!fullrow && body_pos && point < body_pos)
907 point = body_pos - 1;
913 // returns the minimum space a row needs on the screen in pixel
914 int LyXText::fill(RowList::iterator row, int paper_width) const
920 // get the pure distance
921 pos_type const last = lastPrintablePos(*this, row);
923 ParagraphList::iterator pit = row->par();
924 LyXLayout_ptr const & layout = pit->layout();
926 // special handling of the right address boxes
927 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
928 int const tmpfill = row->fill();
929 row->fill(0); // the minfill in MarginLeft()
930 w = leftMargin(*row);
933 w = leftMargin(*row);
935 pos_type const body_pos = pit->beginningOfBody();
936 pos_type i = row->pos();
939 if (body_pos > 0 && i == body_pos) {
940 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
941 if (pit->isLineSeparator(i - 1))
942 w -= singleWidth(pit, i - 1);
943 int left_margin = labelEnd(*row);
947 w += singleWidth(pit, i);
950 if (body_pos > 0 && body_pos > last) {
951 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
952 if (last >= 0 && pit->isLineSeparator(last))
953 w -= singleWidth(pit, last);
954 int const left_margin = labelEnd(*row);
959 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
961 // If this case happens, it means that our calculation
962 // of the widths of the chars when we do rowBreakPoint()
963 // went wrong for some reason. Typically in list bodies.
964 // Things just about hobble on anyway, though you'll end
965 // up with a "fill_separator" less than zero, which corresponds
966 // to inter-word spacing being too small. Hopefully this problem
967 // will die when the label hacks die.
968 if (lyxerr.debugging() && fill < 0) {
969 lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
970 << " w " << w << " paper_width " << paper_width
971 << " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
978 // returns the minimum space a manual label needs on the screen in pixel
979 int LyXText::labelFill(Row const & row) const
981 ParagraphList::iterator pit = row.par();
983 pos_type last = pit->beginningOfBody();
987 // -1 because a label ends either with a space that is in the label,
988 // or with the beginning of a footnote that is outside the label.
991 // a separator at this end does not count
992 if (pit->isLineSeparator(last))
996 pos_type i = row.pos();
998 w += singleWidth(pit, i);
1003 string const & labwidstr = pit->params().labelWidthString();
1004 if (!labwidstr.empty()) {
1005 LyXFont const labfont = getLabelFont(bv()->buffer(), pit);
1006 int const labwidth = font_metrics::width(labwidstr, labfont);
1007 fill = max(labwidth - w, 0);
1014 LColor::color LyXText::backgroundColor() const
1017 return inset_owner->backgroundColor();
1019 return LColor::background;
1023 void LyXText::setHeightOfRow(RowList::iterator rit)
1025 Assert(rit != rows().end());
1027 // get the maximum ascent and the maximum descent
1028 float layoutasc = 0;
1029 float layoutdesc = 0;
1032 Inset * tmpinset = 0;
1034 // ok, let us initialize the maxasc and maxdesc value.
1035 // This depends in LaTeX of the font of the last character
1036 // in the paragraph. The hack below is necessary because
1037 // of the possibility of open footnotes
1039 // Correction: only the fontsize count. The other properties
1040 // are taken from the layoutfont. Nicer on the screen :)
1041 ParagraphList::iterator pit = rit->par();
1043 LyXLayout_ptr const & layout = pit->layout();
1045 // as max get the first character of this row then it can increase but not
1046 // decrease the height. Just some point to start with so we don't have to
1047 // do the assignment below too often.
1048 LyXFont font = getFont(bv()->buffer(), pit, rit->pos());
1049 LyXFont::FONT_SIZE const tmpsize = font.size();
1050 font = getLayoutFont(bv()->buffer(), pit);
1051 LyXFont::FONT_SIZE const size = font.size();
1052 font.setSize(tmpsize);
1054 LyXFont labelfont = getLabelFont(bv()->buffer(), pit);
1056 float spacing_val = 1.0;
1057 if (!pit->params().spacing().isDefault()) {
1058 spacing_val = pit->params().spacing().getValue();
1060 spacing_val = bv()->buffer()->params.spacing.getValue();
1062 //lyxerr << "spacing_val = " << spacing_val << endl;
1064 int maxasc = int(font_metrics::maxAscent(font) *
1065 layout->spacing.getValue() *
1067 int maxdesc = int(font_metrics::maxDescent(font) *
1068 layout->spacing.getValue() *
1071 pos_type const pos_end = lastPos(*this, rit);
1075 if (!pit->empty()) {
1076 // Check if any insets are larger
1077 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1078 if (pit->isInset(pos)) {
1079 tmpfont = getFont(bv()->buffer(), pit, pos);
1080 tmpinset = pit->getInset(pos);
1082 #if 0 // this is needed for deep update on initialitation
1083 #warning inset->update FIXME
1084 //tmpinset->update(bv());
1086 MetricsInfo mi(bv(), tmpfont, workWidth());
1087 tmpinset->metrics(mi, dim);
1088 maxwidth += dim.wid;
1089 maxasc = max(maxasc, dim.asc);
1090 maxdesc = max(maxdesc, dim.des);
1092 maxwidth += tmpinset->width();
1093 maxasc = max(maxasc, tmpinset->ascent());
1094 maxdesc = max(maxdesc, tmpinset->descent());
1098 maxwidth += singleWidth(pit, pos);
1103 // Check if any custom fonts are larger (Asger)
1104 // This is not completely correct, but we can live with the small,
1105 // cosmetic error for now.
1106 LyXFont::FONT_SIZE maxsize =
1107 pit->highestFontInRange(rit->pos(), pos_end, size);
1108 if (maxsize > font.size()) {
1109 font.setSize(maxsize);
1110 maxasc = max(maxasc, font_metrics::maxAscent(font));
1111 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
1114 // This is nicer with box insets:
1118 rit->ascent_of_text(maxasc);
1120 // is it a top line?
1123 // some parksips VERY EASY IMPLEMENTATION
1124 if (bv()->buffer()->params.paragraph_separation ==
1125 BufferParams::PARSEP_SKIP)
1127 if (layout->isParagraph()
1128 && pit->getDepth() == 0
1129 && pit != ownerParagraphs().begin())
1131 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1132 } else if (pit != ownerParagraphs().begin() &&
1133 boost::prior(pit)->layout()->isParagraph() &&
1134 boost::prior(pit)->getDepth() == 0)
1136 // is it right to use defskip here too? (AS)
1137 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1142 if (pit == ownerParagraphs().begin() && !isInInset())
1143 maxasc += PAPER_MARGIN;
1145 // add the vertical spaces, that the user added
1146 maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
1148 // do not forget the DTP-lines!
1149 // there height depends on the font of the nearest character
1150 if (pit->params().lineTop())
1152 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1154 // and now the pagebreaks
1155 if (pit->params().pagebreakTop())
1156 maxasc += 3 * defaultRowHeight();
1158 if (pit->params().startOfAppendix())
1159 maxasc += 3 * defaultRowHeight();
1161 // This is special code for the chapter, since the label of this
1162 // layout is printed in an extra row
1163 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1164 && bv()->buffer()->params.secnumdepth >= 0)
1166 float spacing_val = 1.0;
1167 if (!pit->params().spacing().isDefault()) {
1168 spacing_val = pit->params().spacing().getValue();
1170 spacing_val = bv()->buffer()->params.spacing.getValue();
1173 labeladdon = int(font_metrics::maxDescent(labelfont) *
1174 layout->spacing.getValue() *
1176 + int(font_metrics::maxAscent(labelfont) *
1177 layout->spacing.getValue() *
1181 // special code for the top label
1182 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1183 || layout->labeltype == LABEL_BIBLIO
1184 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1185 && isFirstInSequence(pit, ownerParagraphs())
1186 && !pit->getLabelstring().empty())
1188 float spacing_val = 1.0;
1189 if (!pit->params().spacing().isDefault()) {
1190 spacing_val = pit->params().spacing().getValue();
1192 spacing_val = bv()->buffer()->params.spacing.getValue();
1196 (font_metrics::maxAscent(labelfont) *
1197 layout->spacing.getValue() *
1199 +(font_metrics::maxDescent(labelfont) *
1200 layout->spacing.getValue() *
1202 + layout->topsep * defaultRowHeight()
1203 + layout->labelbottomsep * defaultRowHeight());
1206 // And now the layout spaces, for example before and after
1207 // a section, or between the items of a itemize or enumerate
1210 if (!pit->params().pagebreakTop()) {
1211 ParagraphList::iterator prev =
1212 depthHook(pit, ownerParagraphs(),
1214 if (prev != pit && prev->layout() == layout &&
1215 prev->getDepth() == pit->getDepth() &&
1216 prev->getLabelWidthString() == pit->getLabelWidthString())
1218 layoutasc = (layout->itemsep * defaultRowHeight());
1219 } else if (rit != rows().begin()) {
1220 tmptop = layout->topsep;
1222 if (boost::prior(pit)->getDepth() >= pit->getDepth())
1223 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1226 layoutasc = (tmptop * defaultRowHeight());
1227 } else if (pit->params().lineTop()) {
1228 tmptop = layout->topsep;
1231 layoutasc = (tmptop * defaultRowHeight());
1234 prev = outerHook(pit, ownerParagraphs());
1235 if (prev != ownerParagraphs().end()) {
1236 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1237 } else if (pit != ownerParagraphs().begin()) {
1238 ParagraphList::iterator prior_pit = boost::prior(pit);
1239 if (prior_pit->getDepth() != 0 ||
1240 prior_pit->layout() == layout) {
1241 maxasc += int(layout->parsep * defaultRowHeight());
1247 // is it a bottom line?
1248 RowList::iterator next_rit = boost::next(rit);
1249 if (next_rit == rows().end() || next_rit->par() != pit) {
1250 // the bottom margin
1251 ParagraphList::iterator nextpit = boost::next(pit);
1252 if (nextpit == ownerParagraphs().end() &&
1254 maxdesc += PAPER_MARGIN;
1256 // add the vertical spaces, that the user added
1257 maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
1259 // do not forget the DTP-lines!
1260 // there height depends on the font of the nearest character
1261 if (pit->params().lineBottom())
1262 maxdesc += 2 * font_metrics::ascent('x',
1263 getFont(bv()->buffer(),
1265 max(pos_type(0), pit->size() - 1)));
1267 // and now the pagebreaks
1268 if (pit->params().pagebreakBottom())
1269 maxdesc += 3 * defaultRowHeight();
1271 // and now the layout spaces, for example before and after
1272 // a section, or between the items of a itemize or enumerate
1274 if (!pit->params().pagebreakBottom()
1275 && nextpit != ownerParagraphs().end()) {
1276 ParagraphList::iterator comparepit = pit;
1280 if (comparepit->getDepth() > nextpit->getDepth()) {
1281 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1282 comparepit = depthHook(comparepit, ownerParagraphs(), nextpit->getDepth());
1283 if (comparepit->layout()!= nextpit->layout()
1284 || nextpit->getLabelWidthString() !=
1285 comparepit->getLabelWidthString())
1287 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1289 if (unusual > usual)
1290 layoutdesc = unusual;
1293 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1295 if (comparepit->layout() != nextpit->layout()
1296 || nextpit->getLabelWidthString() !=
1297 comparepit->getLabelWidthString())
1298 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1303 // incalculate the layout spaces
1304 maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
1305 maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
1307 // calculate the new height of the text
1308 height -= rit->height();
1310 rit->height(maxasc + maxdesc + labeladdon);
1311 rit->baseline(maxasc + labeladdon);
1313 height += rit->height();
1315 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1318 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1321 rit->width(maxwidth);
1322 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1324 rit->width(int(maxwidth + x));
1326 width = max(0, workWidth());
1327 RowList::iterator it = rows().begin();
1328 RowList::iterator end = rows().end();
1329 for (; it != end; ++it) {
1330 if (it->width() > width)
1331 width = it->width();
1337 // Appends the implicit specified paragraph before the specified row,
1338 // start at the implicit given position
1339 void LyXText::appendParagraph(RowList::iterator rowit)
1341 Assert(rowit != rowlist_.end());
1343 pos_type const last = rowit->par()->size();
1347 pos_type z = rowBreakPoint(*rowit);
1349 RowList::iterator tmprow = rowit;
1353 Row newrow(rowit->par(), z);
1354 rowit = rowlist_.insert(boost::next(rowit), newrow);
1359 // Set the dimensions of the row
1360 // fixed fill setting now by calling inset->update() in
1361 // SingleWidth when needed!
1362 tmprow->fill(fill(tmprow, workWidth()));
1363 setHeightOfRow(tmprow);
1369 void LyXText::breakAgain(RowList::iterator rit)
1371 Assert(rit != rows().end());
1373 bool not_ready = true;
1376 pos_type z = rowBreakPoint(*rit);
1377 RowList::iterator tmprit = rit;
1378 RowList::iterator end = rows().end();
1380 if (z < rit->par()->size()) {
1381 RowList::iterator next_rit = boost::next(rit);
1383 if (next_rit == end ||
1385 next_rit->par() != rit->par())) {
1388 Row newrow(rit->par(), z);
1389 rit = rowlist_.insert(next_rit, newrow);
1393 if (rit->pos() == z)
1394 not_ready = false; // the rest will not change
1400 // if there are some rows too much, delete them
1401 // only if you broke the whole paragraph!
1402 RowList::iterator tmprit2 = rit;
1403 while (boost::next(tmprit2) != end
1404 && boost::next(tmprit2)->par() == rit->par()) {
1407 while (tmprit2 != rit) {
1409 removeRow(boost::next(tmprit2));
1414 // set the dimensions of the row
1415 tmprit->fill(fill(tmprit, workWidth()));
1416 setHeightOfRow(tmprit);
1417 } while (not_ready);
1421 // this is just a little changed version of break again
1422 void LyXText::breakAgainOneRow(RowList::iterator rit)
1424 Assert(rit != rows().end());
1426 pos_type z = rowBreakPoint(*rit);
1427 RowList::iterator tmprit = rit;
1428 RowList::iterator end = rows().end();
1430 if (z < rit->par()->size()) {
1431 RowList::iterator next_rit = boost::next(rit);
1433 if (next_rit == end ||
1435 next_rit->par() != rit->par())) {
1438 Row newrow(rit->par(), z);
1439 rit = rowlist_.insert(next_rit, newrow);
1443 if (rit->pos() != z)
1447 // if there are some rows too much, delete them
1448 // only if you broke the whole paragraph!
1449 RowList::iterator tmprit2 = rit;
1450 while (boost::next(tmprit2) != end
1451 && boost::next(tmprit2)->par() == rit->par()) {
1454 while (tmprit2 != rit) {
1456 removeRow(boost::next(tmprit2));
1460 // set the dimensions of the row
1461 tmprit->fill(fill(tmprit, workWidth()));
1462 setHeightOfRow(tmprit);
1466 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1468 // allow only if at start or end, or all previous is new text
1469 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1470 && cursor.par()->isChangeEdited(0, cursor.pos()))
1473 LyXTextClass const & tclass =
1474 bv()->buffer()->params.getLyXTextClass();
1475 LyXLayout_ptr const & layout = cursor.par()->layout();
1477 // this is only allowed, if the current paragraph is not empty or caption
1478 // and if it has not the keepempty flag active
1479 if (cursor.par()->empty() && !cursor.par()->allowEmpty()
1480 && layout->labeltype != LABEL_SENSITIVE)
1483 setUndo(bv(), Undo::FINISH, cursor.par());
1485 // Always break behind a space
1487 // It is better to erase the space (Dekel)
1488 if (cursor.pos() < cursor.par()->size()
1489 && cursor.par()->isLineSeparator(cursor.pos()))
1490 cursor.par()->erase(cursor.pos());
1491 // cursor.pos(cursor.pos() + 1);
1493 // break the paragraph
1497 keep_layout = layout->isEnvironment();
1499 // we need to set this before we insert the paragraph. IMO the
1500 // breakParagraph call should return a bool if it inserts the
1501 // paragraph before or behind and we should react on that one
1502 // but we can fix this in 1.3.0 (Jug 20020509)
1503 bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty());
1504 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(),
1505 cursor.pos(), keep_layout);
1507 // well this is the caption hack since one caption is really enough
1508 if (layout->labeltype == LABEL_SENSITIVE) {
1510 // set to standard-layout
1511 cursor.par()->applyLayout(tclass.defaultLayout());
1513 // set to standard-layout
1514 boost::next(cursor.par())->applyLayout(tclass.defaultLayout());
1517 // if the cursor is at the beginning of a row without prior newline,
1519 // This touches only the screen-update. Otherwise we would may have
1520 // an empty row on the screen
1521 if (cursor.pos() && cursorRow()->pos() == cursor.pos()
1522 && !cursorRow()->par()->isNewline(cursor.pos() - 1))
1529 removeParagraph(cursorRow());
1531 // set the dimensions of the cursor row
1532 cursorRow()->fill(fill(cursorRow(), workWidth()));
1534 setHeightOfRow(cursorRow());
1536 #warning Trouble Point! (Lgb)
1537 // When ::breakParagraph is called from within an inset we must
1538 // ensure that the correct ParagraphList is used. Today that is not
1539 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1540 ParagraphList::iterator next_par = boost::next(cursor.par());
1542 while (!next_par->empty() && next_par->isNewline(0))
1545 insertParagraph(next_par, boost::next(cursorRow()));
1548 // This check is necessary. Otherwise the new empty paragraph will
1549 // be deleted automatically. And it is more friendly for the user!
1550 if (cursor.pos() || isempty)
1551 setCursor(next_par, 0);
1553 setCursor(cursor.par(), 0);
1555 if (boost::next(cursorRow()) != rows().end())
1556 breakAgain(boost::next(cursorRow()));
1558 need_break_row = rows().end();
1562 // Just a macro to make some thing easier.
1563 void LyXText::redoParagraph()
1566 redoParagraphs(cursor, boost::next(cursor.par()));
1567 setCursorIntern(cursor.par(), cursor.pos());
1571 // insert a character, moves all the following breaks in the
1572 // same Paragraph one to the right and make a rebreak
1573 void LyXText::insertChar(char c)
1575 setUndo(bv(), Undo::INSERT, cursor.par());
1577 // When the free-spacing option is set for the current layout,
1578 // disable the double-space checking
1580 bool const freeSpacing = cursorRow()->par()->layout()->free_spacing ||
1581 cursorRow()->par()->isFreeSpacing();
1583 if (lyxrc.auto_number) {
1584 static string const number_operators = "+-/*";
1585 static string const number_unary_operators = "+-";
1586 static string const number_seperators = ".,:";
1588 if (current_font.number() == LyXFont::ON) {
1589 if (!IsDigit(c) && !contains(number_operators, c) &&
1590 !(contains(number_seperators, c) &&
1591 cursor.pos() >= 1 &&
1592 cursor.pos() < cursor.par()->size() &&
1593 getFont(bv()->buffer(),
1595 cursor.pos()).number() == LyXFont::ON &&
1596 getFont(bv()->buffer(),
1598 cursor.pos() - 1).number() == LyXFont::ON)
1600 number(bv()); // Set current_font.number to OFF
1601 } else if (IsDigit(c) &&
1602 real_current_font.isVisibleRightToLeft()) {
1603 number(bv()); // Set current_font.number to ON
1605 if (cursor.pos() > 0) {
1606 char const c = cursor.par()->getChar(cursor.pos() - 1);
1607 if (contains(number_unary_operators, c) &&
1608 (cursor.pos() == 1 ||
1609 cursor.par()->isSeparator(cursor.pos() - 2) ||
1610 cursor.par()->isNewline(cursor.pos() - 2))
1612 setCharFont(bv()->buffer(),
1616 } else if (contains(number_seperators, c) &&
1617 cursor.pos() >= 2 &&
1618 getFont(bv()->buffer(),
1620 cursor.pos() - 2).number() == LyXFont::ON) {
1621 setCharFont(bv()->buffer(),
1631 // First check, if there will be two blanks together or a blank at
1632 // the beginning of a paragraph.
1633 // I decided to handle blanks like normal characters, the main
1634 // difference are the special checks when calculating the row.fill
1635 // (blank does not count at the end of a row) and the check here
1637 // The bug is triggered when we type in a description environment:
1638 // The current_font is not changed when we go from label to main text
1639 // and it should (along with realtmpfont) when we type the space.
1640 // CHECK There is a bug here! (Asger)
1642 LyXFont realtmpfont = real_current_font;
1643 LyXFont rawtmpfont = current_font;
1644 // store the current font. This is because of the use of cursor
1645 // movements. The moving cursor would refresh the current font
1647 // Get the font that is used to calculate the baselineskip
1648 pos_type const lastpos = cursor.par()->size();
1649 LyXFont rawparfont =
1650 cursor.par()->getFontSettings(bv()->buffer()->params,
1653 bool jumped_over_space = false;
1655 if (!freeSpacing && IsLineSeparatorChar(c)) {
1656 if ((cursor.pos() > 0
1657 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1658 || (cursor.pos() > 0
1659 && cursor.par()->isNewline(cursor.pos() - 1))
1660 || (cursor.pos() == 0)) {
1661 static bool sent_space_message = false;
1662 if (!sent_space_message) {
1663 if (cursor.pos() == 0)
1664 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1666 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1667 sent_space_message = true;
1674 // the display inset stuff
1675 if (cursorRow()->pos() < cursorRow()->par()->size()
1676 && cursorRow()->par()->isInset(cursorRow()->pos())) {
1677 Inset * inset = cursorRow()->par()->getInset(cursorRow()->pos());
1678 if (inset && (inset->display() || inset->needFullRow())) {
1679 // force a new break
1680 cursorRow()->fill(-1); // to force a new break
1684 // get the cursor row fist
1685 RowList::iterator row = cursorRow();
1686 if (c != Paragraph::META_INSET) {
1687 // Here case LyXText::InsertInset already inserted the character
1688 cursor.par()->insertChar(cursor.pos(), c);
1690 setCharFont(bv()->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
1692 if (!jumped_over_space) {
1693 // refresh the positions
1694 RowList::iterator tmprow = row;
1695 while (boost::next(tmprow) != rows().end() &&
1696 boost::next(tmprow)->par() == row->par()) {
1698 tmprow->pos(tmprow->pos() + 1);
1702 // Is there a break one row above
1703 if (row != rows().begin() &&
1704 boost::prior(row)->par() == row->par()
1705 && (cursor.par()->isLineSeparator(cursor.pos())
1706 || cursor.par()->isNewline(cursor.pos())
1707 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1708 cursor.par()->isInset(cursor.pos() + 1))
1709 || cursorRow()->fill() == -1))
1711 pos_type z = rowBreakPoint(*boost::prior(row));
1713 if (z >= row->pos()) {
1716 // set the dimensions of the row above
1717 boost::prior(row)->fill(fill(
1721 setHeightOfRow(boost::prior(row));
1725 breakAgainOneRow(row);
1727 current_font = rawtmpfont;
1728 real_current_font = realtmpfont;
1729 setCursor(cursor.par(), cursor.pos() + 1,
1730 false, cursor.boundary());
1731 // cursor MUST be in row now.
1733 RowList::iterator next_row = boost::next(row);
1734 if (next_row != rows().end() &&
1735 next_row->par() == row->par())
1736 need_break_row = next_row;
1738 need_break_row = rows().end();
1740 // check, wether the last characters font has changed.
1741 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1742 && rawparfont != rawtmpfont)
1743 redoHeightOfParagraph();
1750 // recalculate the fill of the row
1751 if (row->fill() >= 0) {
1752 // needed because a newline will set fill to -1. Otherwise
1753 // we would not get a rebreak!
1754 row->fill(fill(row, workWidth()));
1757 if (c == Paragraph::META_INSET || row->fill() < 0) {
1759 breakAgainOneRow(row);
1761 RowList::iterator next_row = boost::next(row);
1763 // will the cursor be in another row now?
1764 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1765 next_row != rows().end()) {
1766 if (next_row != rows().end() &&
1767 next_row->par() == row->par()) {
1768 // this should always be true
1772 breakAgainOneRow(row);
1774 current_font = rawtmpfont;
1775 real_current_font = realtmpfont;
1777 setCursor(cursor.par(), cursor.pos() + 1, false,
1779 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
1780 != cursor.boundary())
1781 setCursor(cursor.par(), cursor.pos(), false,
1782 !cursor.boundary());
1784 next_row = boost::next(row);
1786 if (next_row != rows().end() &&
1787 next_row->par() == row->par())
1788 need_break_row = next_row;
1790 need_break_row = rows().end();
1792 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1793 setHeightOfRow(row);
1796 current_font = rawtmpfont;
1797 real_current_font = realtmpfont;
1798 setCursor(cursor.par(), cursor.pos() + 1, false,
1802 // check, wether the last characters font has changed.
1803 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1804 && rawparfont != rawtmpfont) {
1805 redoHeightOfParagraph();
1812 void LyXText::charInserted()
1814 // Here we could call FinishUndo for every 20 characters inserted.
1815 // This is from my experience how emacs does it. (Lgb)
1816 static unsigned int counter;
1826 void LyXText::prepareToPrint(RowList::iterator rit, int & x,
1827 int & fill_separator,
1829 int & fill_label_hfill,
1832 int w = rit->fill();
1834 fill_label_hfill = 0;
1836 fill_label_hfill = 0;
1838 ParagraphList::iterator pit = rit->par();
1841 pit->isRightToLeftPar(bv()->buffer()->params);
1843 x = workWidth() > 0 ? rightMargin(*bv()->buffer(), *rit) : 0;
1845 x = workWidth() > 0 ? leftMargin(*rit) : 0;
1847 // is there a manual margin with a manual label
1848 LyXLayout_ptr const & layout = pit->layout();
1850 if (layout->margintype == MARGIN_MANUAL
1851 && layout->labeltype == LABEL_MANUAL) {
1852 /// We might have real hfills in the label part
1853 int nlh = numberOfLabelHfills(*this, rit);
1855 // A manual label par (e.g. List) has an auto-hfill
1856 // between the label text and the body of the
1858 // But we don't want to do this auto hfill if the par
1863 if (nlh && !pit->getLabelWidthString().empty()) {
1864 fill_label_hfill = int(labelFill(*rit) / nlh);
1868 // are there any hfills in the row?
1869 int const nh = numberOfHfills(*this, rit);
1873 fill_hfill = w / nh;
1874 // we don't have to look at the alignment if it is ALIGN_LEFT and
1875 // if the row is already larger then the permitted width as then
1876 // we force the LEFT_ALIGN'edness!
1877 } else if (int(rit->width()) < workWidth()) {
1878 // is it block, flushleft or flushright?
1879 // set x how you need it
1881 if (pit->params().align() == LYX_ALIGN_LAYOUT) {
1882 align = layout->align;
1884 align = pit->params().align();
1887 // center displayed insets
1889 if (rit->pos() < pit->size()
1890 && pit->isInset(rit->pos())
1891 && (inset = pit->getInset(rit->pos()))
1892 && (inset->display())) // || (inset->scroll() < 0)))
1893 align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
1894 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1895 // ERT insets should always be LEFT ALIGNED on screen
1896 inset = pit->inInset();
1897 if (inset && inset->owner() &&
1898 inset->owner()->lyxCode() == Inset::ERT_CODE)
1900 align = LYX_ALIGN_LEFT;
1904 case LYX_ALIGN_BLOCK:
1906 int const ns = numberOfSeparators(*this, rit);
1907 RowList::iterator next_row = boost::next(rit);
1908 ParagraphList::iterator next_pit = next_row->par();
1910 if (ns && next_row != rowlist_.end() &&
1912 !(next_pit->isNewline(next_row->pos() - 1))
1913 && !(next_pit->isInset(next_row->pos()) &&
1914 next_pit->getInset(next_row->pos()) &&
1915 next_pit->getInset(next_row->pos())->display())
1917 fill_separator = w / ns;
1918 } else if (is_rtl) {
1923 case LYX_ALIGN_RIGHT:
1926 case LYX_ALIGN_CENTER:
1934 computeBidiTables(bv()->buffer(), rit);
1936 pos_type body_pos = pit->beginningOfBody();
1937 pos_type last = lastPos(*this, rit);
1940 (body_pos - 1 > last ||
1941 !pit->isLineSeparator(body_pos - 1))) {
1942 x += font_metrics::width(layout->labelsep,
1943 getLabelFont(bv()->buffer(),
1945 if (body_pos - 1 <= last)
1946 x += fill_label_hfill;
1952 // important for the screen
1955 // the cursor set functions have a special mechanism. When they
1956 // realize, that you left an empty paragraph, they will delete it.
1957 // They also delete the corresponding row
1959 void LyXText::cursorRightOneWord()
1961 ::cursorRightOneWord(cursor, ownerParagraphs());
1962 setCursor(cursor.par(), cursor.pos());
1966 // Skip initial whitespace at end of word and move cursor to *start*
1967 // of prior word, not to end of next prior word.
1968 void LyXText::cursorLeftOneWord()
1970 LyXCursor tmpcursor = cursor;
1971 ::cursorLeftOneWord(tmpcursor, ownerParagraphs());
1972 setCursor(tmpcursor.par(), tmpcursor.pos());
1976 void LyXText::selectWord(word_location loc)
1978 LyXCursor from = cursor;
1980 ::getWord(from, to, loc, ownerParagraphs());
1982 setCursor(from.par(), from.pos());
1985 selection.cursor = cursor;
1986 setCursor(to.par(), to.pos());
1991 // Select the word currently under the cursor when no
1992 // selection is currently set
1993 bool LyXText::selectWordWhenUnderCursor(word_location loc)
1995 if (!selection.set()) {
1997 return selection.set();
2003 void LyXText::acceptChange()
2005 if (!selection.set() && cursor.par()->size())
2008 if (selection.start.par() == selection.end.par()) {
2009 LyXCursor & startc = selection.start;
2010 LyXCursor & endc = selection.end;
2011 setUndo(bv(), Undo::INSERT, startc.par());
2012 startc.par()->acceptChange(startc.pos(), endc.pos());
2015 redoParagraphs(startc, boost::next(startc.par()));
2016 setCursorIntern(startc.par(), 0);
2018 #warning handle multi par selection
2022 void LyXText::rejectChange()
2024 if (!selection.set() && cursor.par()->size())
2027 if (selection.start.par() == selection.end.par()) {
2028 LyXCursor & startc = selection.start;
2029 LyXCursor & endc = selection.end;
2030 setUndo(bv(), Undo::INSERT, startc.par());
2031 startc.par()->rejectChange(startc.pos(), endc.pos());
2034 redoParagraphs(startc, boost::next(startc.par()));
2035 setCursorIntern(startc.par(), 0);
2037 #warning handle multi par selection
2041 // This function is only used by the spellchecker for NextWord().
2042 // It doesn't handle LYX_ACCENTs and probably never will.
2044 LyXText::selectNextWordToSpellcheck(float & value)
2046 if (the_locking_inset) {
2047 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2048 if (!word.word().empty()) {
2049 value += float(cursor.y());
2050 value /= float(height);
2053 // we have to go on checking so move cursor to the next char
2054 if (cursor.pos() == cursor.par()->size()) {
2055 if (boost::next(cursor.par()) == ownerParagraphs().end())
2057 cursor.par(boost::next(cursor.par()));
2060 cursor.pos(cursor.pos() + 1);
2062 ParagraphList::iterator tmppit = cursor.par();
2064 // If this is not the very first word, skip rest of
2065 // current word because we are probably in the middle
2066 // of a word if there is text here.
2067 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
2068 while (cursor.pos() < cursor.par()->size()
2069 && cursor.par()->isLetter(cursor.pos()))
2070 cursor.pos(cursor.pos() + 1);
2073 // Now, skip until we have real text (will jump paragraphs)
2075 ParagraphList::iterator cpit = cursor.par();
2076 pos_type const cpos(cursor.pos());
2078 if (cpos == cpit->size()) {
2079 if (boost::next(cpit) != ownerParagraphs().end()) {
2080 cursor.par(boost::next(cpit));
2087 bool const is_good_inset = cpit->isInset(cpos)
2088 && cpit->getInset(cpos)->allowSpellcheck();
2090 if (!isDeletedText(*cpit, cpos)
2091 && (is_good_inset || cpit->isLetter(cpos)))
2094 cursor.pos(cpos + 1);
2097 // now check if we hit an inset so it has to be a inset containing text!
2098 if (cursor.pos() < cursor.par()->size() &&
2099 cursor.par()->isInset(cursor.pos())) {
2101 FuncRequest cmd(bv(), LFUN_INSET_EDIT, "left");
2102 cursor.par()->getInset(cursor.pos())->localDispatch(cmd);
2103 // now call us again to do the above trick
2104 // but obviously we have to start from down below ;)
2105 return bv()->text->selectNextWordToSpellcheck(value);
2108 // Update the value if we changed paragraphs
2109 if (cursor.par() != tmppit) {
2110 setCursor(cursor.par(), cursor.pos());
2111 value = float(cursor.y())/float(height);
2114 // Start the selection from here
2115 selection.cursor = cursor;
2118 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2119 .language()->code());
2120 // and find the end of the word (insets like optional hyphens
2121 // and ligature break are part of a word)
2122 while (cursor.pos() < cursor.par()->size()
2123 && cursor.par()->isLetter(cursor.pos())
2124 && !isDeletedText(*cursor.par(), cursor.pos()))
2125 cursor.pos(cursor.pos() + 1);
2127 // Finally, we copy the word to a string and return it
2129 if (selection.cursor.pos() < cursor.pos()) {
2131 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2132 if (!cursor.par()->isInset(i))
2133 str += cursor.par()->getChar(i);
2136 return WordLangTuple(str, lang_code);
2140 // This one is also only for the spellchecker
2141 void LyXText::selectSelectedWord()
2143 if (the_locking_inset) {
2144 the_locking_inset->selectSelectedWord(bv());
2147 // move cursor to the beginning
2148 setCursor(selection.cursor.par(), selection.cursor.pos());
2150 // set the sel cursor
2151 selection.cursor = cursor;
2153 // now find the end of the word
2154 while (cursor.pos() < cursor.par()->size()
2155 && (cursor.par()->isLetter(cursor.pos())))
2156 cursor.pos(cursor.pos() + 1);
2158 setCursor(cursor.par(), cursor.pos());
2160 // finally set the selection
2165 // Delete from cursor up to the end of the current or next word.
2166 void LyXText::deleteWordForward()
2168 if (cursor.par()->empty())
2171 LyXCursor tmpcursor = cursor;
2172 selection.set(true); // to avoid deletion
2173 cursorRightOneWord();
2174 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2175 selection.cursor = cursor;
2179 // Great, CutSelection() gets rid of multiple spaces.
2180 cutSelection(true, false);
2185 // Delete from cursor to start of current or prior word.
2186 void LyXText::deleteWordBackward()
2188 if (cursor.par()->empty())
2191 LyXCursor tmpcursor = cursor;
2192 selection.set(true); // to avoid deletion
2193 cursorLeftOneWord();
2194 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2195 selection.cursor = cursor;
2198 cutSelection(true, false);
2203 // Kill to end of line.
2204 void LyXText::deleteLineForward()
2206 if (cursor.par()->empty())
2207 // Paragraph is empty, so we just go to the right
2210 LyXCursor tmpcursor = cursor;
2211 // We can't store the row over a regular setCursor
2212 // so we set it to 0 and reset it afterwards.
2213 selection.set(true); // to avoid deletion
2215 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2216 selection.cursor = cursor;
2219 // What is this test for ??? (JMarc)
2220 if (!selection.set()) {
2221 deleteWordForward();
2223 cutSelection(true, false);
2229 void LyXText::changeCase(LyXText::TextCase action)
2234 if (selection.set()) {
2235 from = selection.start;
2239 ::getWord(from, to, lyx::PARTIAL_WORD, ownerParagraphs());
2240 setCursor(to.par(), to.pos() + 1);
2243 setUndo(bv(), Undo::FINISH, from.par(), to.par());
2245 pos_type pos = from.pos();
2246 ParagraphList::iterator pit = from.par();
2248 while (pit != ownerParagraphs().end() &&
2249 (pos != to.pos() || pit != to.par())) {
2250 if (pos == pit->size()) {
2255 unsigned char c = pit->getChar(pos);
2256 if (!IsInsetChar(c)) {
2258 case text_lowercase:
2261 case text_capitalization:
2263 action = text_lowercase;
2265 case text_uppercase:
2271 pit->setChar(pos, c);
2272 checkParagraph(pit, pos);
2277 if (getRow(to) != getRow(from))
2282 void LyXText::Delete()
2284 // this is a very easy implementation
2286 LyXCursor old_cursor = cursor;
2287 int const old_cur_par_id = old_cursor.par()->id();
2288 int const old_cur_par_prev_id =
2289 (old_cursor.par() != ownerParagraphs().begin() ?
2290 boost::prior(old_cursor.par())->id() : -1);
2292 // just move to the right
2295 // CHECK Look at the comment here.
2296 // This check is not very good...
2297 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2298 // and that can very well delete the par or par->previous in
2299 // old_cursor. Will a solution where we compare paragraph id's
2301 if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
2302 == old_cur_par_prev_id
2303 && cursor.par()->id() != old_cur_par_id) {
2304 // delete-empty-paragraph-mechanism has done it
2308 // if you had success make a backspace
2309 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2310 LyXCursor tmpcursor = cursor;
2311 // to make sure undo gets the right cursor position
2312 cursor = old_cursor;
2313 setUndo(bv(), Undo::DELETE, cursor.par());
2320 void LyXText::backspace()
2322 // Get the font that is used to calculate the baselineskip
2323 pos_type lastpos = cursor.par()->size();
2324 LyXFont rawparfont =
2325 cursor.par()->getFontSettings(bv()->buffer()->params,
2328 if (cursor.pos() == 0) {
2329 // The cursor is at the beginning of a paragraph,
2330 // so the the backspace will collapse two paragraphs into one.
2332 // but it's not allowed unless it's new
2333 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2336 // we may paste some paragraphs
2338 // is it an empty paragraph?
2341 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2342 // This is an empty paragraph and we delete it just by moving the cursor one step
2343 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2344 // of the paragraph.
2346 if (cursor.par() != ownerParagraphs().begin()) {
2347 ParagraphList::iterator tmppit = boost::prior(cursor.par());
2348 if (cursor.par()->layout() == tmppit->layout()
2349 && cursor.par()->getAlign() == tmppit->getAlign()) {
2350 // Inherit bottom DTD from the paragraph below.
2351 // (the one we are deleting)
2352 tmppit->params().lineBottom(cursor.par()->params().lineBottom());
2353 tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
2354 tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2359 // the layout things can change the height of a row !
2360 int const tmpheight = cursorRow()->height();
2361 setHeightOfRow(cursorRow());
2362 if (cursorRow()->height() != tmpheight)
2368 if (cursor.par() != ownerParagraphs().begin()) {
2369 setUndo(bv(), Undo::DELETE,
2370 boost::prior(cursor.par()),
2374 ParagraphList::iterator tmppit = cursor.par();
2375 RowList::iterator tmprow = cursorRow();
2377 // We used to do cursorLeftIntern() here, but it is
2378 // not a good idea since it triggers the auto-delete
2379 // mechanism. So we do a cursorLeftIntern()-lite,
2380 // without the dreaded mechanism. (JMarc)
2381 if (cursor.par() != ownerParagraphs().begin()) {
2382 // steps into the above paragraph.
2383 setCursorIntern(boost::prior(cursor.par()),
2384 boost::prior(cursor.par())->size(),
2388 // Pasting is not allowed, if the paragraphs have different
2389 // layout. I think it is a real bug of all other
2390 // word processors to allow it. It confuses the user.
2391 // Even so with a footnote paragraph and a non-footnote
2392 // paragraph. I will not allow pasting in this case,
2393 // because the user would be confused if the footnote behaves
2394 // different wether it is open or closed.
2396 // Correction: Pasting is always allowed with standard-layout
2397 LyXTextClass const & tclass =
2398 bv()->buffer()->params.getLyXTextClass();
2400 if (cursor.par() != tmppit
2401 && (cursor.par()->layout() == tmppit->layout()
2402 || tmppit->layout() == tclass.defaultLayout())
2403 && cursor.par()->getAlign() == tmppit->getAlign()) {
2404 removeParagraph(tmprow);
2406 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2408 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2409 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2410 // strangely enough it seems that commenting out the line above removes
2411 // most or all of the segfaults. I will however also try to move the
2412 // two Remove... lines in front of the PasteParagraph too.
2415 cursor.pos(cursor.pos() - 1);
2419 // remove the lost paragraph
2420 // This one is not safe, since the paragraph that the tmprow and the
2421 // following rows belong to has been deleted by the PasteParagraph
2422 // above. The question is... could this be moved in front of the
2424 //RemoveParagraph(tmprow);
2425 //RemoveRow(tmprow);
2427 // This rebuilds the rows.
2428 appendParagraph(cursorRow());
2431 // the row may have changed, block, hfills etc.
2432 setCursor(cursor.par(), cursor.pos(), false);
2435 // this is the code for a normal backspace, not pasting
2437 setUndo(bv(), Undo::DELETE, cursor.par());
2438 // We used to do cursorLeftIntern() here, but it is
2439 // not a good idea since it triggers the auto-delete
2440 // mechanism. So we do a cursorLeftIntern()-lite,
2441 // without the dreaded mechanism. (JMarc)
2442 setCursorIntern(cursor.par(), cursor.pos()- 1,
2443 false, cursor.boundary());
2445 if (cursor.par()->isInset(cursor.pos())) {
2446 // force complete redo when erasing display insets
2447 // this is a cruel method but safe..... Matthias
2448 if (cursor.par()->getInset(cursor.pos())->display() ||
2449 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2450 cursor.par()->erase(cursor.pos());
2456 RowList::iterator row = cursorRow();
2457 int y = cursor.y() - row->baseline();
2459 // remember that a space at the end of a row doesnt count
2460 // when calculating the fill
2461 if (cursor.pos() < lastPos(*this, row) ||
2462 !cursor.par()->isLineSeparator(cursor.pos())) {
2463 row->fill(row->fill() + singleWidth(
2468 // some special code when deleting a newline. This is similar
2469 // to the behavior when pasting paragraphs
2470 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2471 cursor.par()->erase(cursor.pos());
2472 // refresh the positions
2473 RowList::iterator tmprow = row;
2474 while (boost::next(tmprow) != rows().end() &&
2475 boost::next(tmprow)->par() == row->par()) {
2477 tmprow->pos(tmprow->pos() - 1);
2479 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2480 cursor.pos(cursor.pos() - 1);
2482 if (cursor.pos() < cursor.par()->size()
2483 && !cursor.par()->isSeparator(cursor.pos())) {
2484 cursor.par()->insertChar(cursor.pos(), ' ');
2485 setCharFont(bv()->buffer(), cursor.par(),
2486 cursor.pos(), current_font);
2487 // refresh the positions
2489 while (boost::next(tmprow) != rows().end() &&
2490 boost::next(tmprow)->par() == row->par()) {
2492 tmprow->pos(tmprow->pos() + 1);
2496 cursor.par()->erase(cursor.pos());
2498 // refresh the positions
2499 RowList::iterator tmprow = row;
2500 while (boost::next(tmprow) != rows().end() &&
2501 boost::next(tmprow)->par() == row->par()) {
2503 tmprow->pos(tmprow->pos() - 1);
2506 // delete newlines at the beginning of paragraphs
2507 while (!cursor.par()->empty() &&
2508 cursor.pos() < cursor.par()->size() &&
2509 cursor.par()->isNewline(cursor.pos()) &&
2510 cursor.pos() == cursor.par()->beginningOfBody()) {
2511 cursor.par()->erase(cursor.pos());
2512 // refresh the positions
2514 while (boost::next(tmprow) != rows().end() &&
2515 boost::next(tmprow)->par() == row->par()) {
2517 tmprow->pos(tmprow->pos() - 1);
2522 // is there a break one row above
2523 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2524 z = rowBreakPoint(*boost::prior(row));
2525 if (z >= row->pos()) {
2528 RowList::iterator tmprow = boost::prior(row);
2530 // maybe the current row is now empty
2531 if (row->pos() >= row->par()->size()) {
2534 need_break_row = rows().end();
2536 breakAgainOneRow(row);
2537 if (boost::next(row) != rows().end() &&
2538 boost::next(row)->par() == row->par())
2539 need_break_row = boost::next(row);
2541 need_break_row = rows().end();
2544 // set the dimensions of the row above
2545 y -= tmprow->height();
2546 tmprow->fill(fill(tmprow, workWidth()));
2547 setHeightOfRow(tmprow);
2550 setCursor(cursor.par(), cursor.pos(),
2551 false, cursor.boundary());
2552 //current_font = rawtmpfont;
2553 //real_current_font = realtmpfont;
2554 // check, whether the last character's font has changed.
2556 cursor.par()->getFontSettings(bv()->buffer()->params,
2557 cursor.par()->size() - 1))
2558 redoHeightOfParagraph();
2563 // break the cursor row again
2564 if (boost::next(row) != rows().end() &&
2565 boost::next(row)->par() == row->par() &&
2566 (lastPos(*this, row) == row->par()->size() - 1 ||
2567 rowBreakPoint(*row) != lastPos(*this, row))) {
2569 // it can happen that a paragraph loses one row
2570 // without a real breakup. This is when a word
2571 // is to long to be broken. Well, I don t care this
2573 if (lastPos(*this, row) == row->par()->size() - 1)
2574 removeRow(boost::next(row));
2578 breakAgainOneRow(row);
2579 // will the cursor be in another row now?
2580 if (boost::next(row) != rows().end() &&
2581 boost::next(row)->par() == row->par() &&
2582 lastPos(*this, row) <= cursor.pos()) {
2584 breakAgainOneRow(row);
2587 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2589 if (boost::next(row) != rows().end() &&
2590 boost::next(row)->par() == row->par())
2591 need_break_row = boost::next(row);
2593 need_break_row = rows().end();
2595 // set the dimensions of the row
2596 row->fill(fill(row, workWidth()));
2597 setHeightOfRow(row);
2599 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2603 // current_font = rawtmpfont;
2604 // real_current_font = realtmpfont;
2606 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
2607 != cursor.boundary())
2608 setCursor(cursor.par(), cursor.pos(), false,
2609 !cursor.boundary());
2611 lastpos = cursor.par()->size();
2612 if (cursor.pos() == lastpos)
2615 // check, whether the last characters font has changed.
2617 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2618 redoHeightOfParagraph();
2623 RowList::iterator LyXText::cursorRow() const
2625 return getRow(cursor.par(), cursor.pos());
2629 RowList::iterator LyXText::getRow(LyXCursor const & cur) const
2631 return getRow(cur.par(), cur.pos());
2636 LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
2639 return rowlist_.end();
2641 // find the first row of the specified paragraph
2642 RowList::iterator rit = rowlist_.begin();
2643 RowList::iterator end = rowlist_.end();
2644 while (boost::next(rit) != end && rit->par() != pit) {
2648 // now find the wanted row
2649 while (rit->pos() < pos
2650 && boost::next(rit) != end
2651 && boost::next(rit)->par() == pit
2652 && boost::next(rit)->pos() <= pos) {
2660 // returns pointer to a specified row
2662 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2667 return rowlist_.end();
2669 // find the first row of the specified paragraph
2670 RowList::iterator rit = rowlist_.begin();
2671 RowList::iterator end = rowlist_.end();
2672 while (boost::next(rit) != end && rit->par() != pit) {
2677 // now find the wanted row
2678 while (rit->pos() < pos
2679 && boost::next(rit) != end
2680 && boost::next(rit)->par() == pit
2681 && boost::next(rit)->pos() <= pos) {
2690 // returns pointer to some fancy row 'below' specified row
2691 RowList::iterator LyXText::cursorIRow() const
2694 return getRow(cursor.par(), cursor.pos(), y);
2698 RowList::iterator LyXText::getRowNearY(int & y) const
2700 RowList::iterator rit = anchor_row_;
2701 RowList::iterator const beg = rows().begin();
2702 RowList::iterator const end = rows().end();
2704 if (rows().empty()) {
2711 int tmpy = rit->y();
2714 while (rit != end && tmpy <= y) {
2715 tmpy += rit->height();
2720 tmpy -= rit->height();
2723 while (rit != beg && tmpy > y) {
2725 tmpy -= rit->height();
2728 if (tmpy < 0 || rit == end) {
2740 int LyXText::getDepth() const
2742 return cursor.par()->getDepth();