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(InsetOld 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 ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
293 lyxrc.font_norm_type == LyXRC::ISO_10646_1)
294 && font.language()->lang() == "arabic") {
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);
306 if (c == Paragraph::META_INSET) {
307 InsetOld * tmpinset = pit->getInset(pos);
309 if (tmpinset->lyxCode() == InsetOld::HFILL_CODE) {
310 // Because of the representation as vertical lines
314 #warning inset->update FIXME
315 // this IS needed otherwise on initialitation we don't get the fill
316 // of the row right (ONLY on initialization if we read a file!)
317 // should be changed! (Jug 20011204)
318 //tmpinset->update(bv());
320 MetricsInfo mi(bv(), font, workWidth());
321 tmpinset->metrics(mi, dim);
324 return tmpinset->width();
330 if (IsSeparatorChar(c))
332 return font_metrics::width(c, font);
336 lyx::pos_type LyXText::log2vis(lyx::pos_type pos) const
338 if (bidi_start == -1)
341 return log2vis_list[pos - bidi_start];
345 lyx::pos_type LyXText::vis2log(lyx::pos_type pos) const
347 if (bidi_start == -1)
350 return vis2log_list[pos - bidi_start];
354 lyx::pos_type LyXText::bidi_level(lyx::pos_type pos) const
356 if (bidi_start == -1)
359 return bidi_levels[pos - bidi_start];
363 bool LyXText::bidi_InRange(lyx::pos_type pos) const
365 return bidi_start == -1 ||
366 (bidi_start <= pos && pos <= bidi_end);
370 void LyXText::computeBidiTables(Buffer const * buf,
371 RowList::iterator row) const
373 bidi_same_direction = true;
374 if (!lyxrc.rtl_support) {
379 ParagraphList::iterator row_par = row->par();
381 InsetOld * inset = row_par->inInset();
382 if (inset && inset->owner() &&
383 inset->owner()->lyxCode() == InsetOld::ERT_CODE) {
388 bidi_start = row->pos();
389 bidi_end = lastPrintablePos(*this, row);
391 if (bidi_start > bidi_end) {
396 if (bidi_end + 2 - bidi_start >
397 static_cast<pos_type>(log2vis_list.size())) {
399 (bidi_end + 2 - bidi_start < 500) ?
400 500 : 2 * (bidi_end + 2 - bidi_start);
401 log2vis_list.resize(new_size);
402 vis2log_list.resize(new_size);
403 bidi_levels.resize(new_size);
406 vis2log_list[bidi_end + 1 - bidi_start] = -1;
407 log2vis_list[bidi_end + 1 - bidi_start] = -1;
411 row_par->isRightToLeftPar(buf->params);
415 pos_type const body_pos = row_par->beginningOfBody();
417 for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
418 bool is_space = row_par->isLineSeparator(lpos);
420 (is_space && lpos + 1 <= bidi_end &&
421 !row_par->isLineSeparator(lpos + 1) &&
422 !row_par->isNewline(lpos + 1))
424 LyXFont font = row_par->getFontSettings(buf->params, pos);
425 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
426 font.number() == LyXFont::ON &&
427 row_par->getFontSettings(buf->params, lpos - 1).number()
429 font = row_par->getFontSettings(buf->params, lpos);
434 bool new_rtl = font.isVisibleRightToLeft();
435 bool new_rtl0 = font.isRightToLeft();
438 if (lpos == body_pos - 1
439 && row->pos() < body_pos - 1
441 new_level = (rtl_par) ? 1 : 0;
442 new_rtl = new_rtl0 = rtl_par;
444 new_level = (new_rtl) ? 1 : 2;
446 new_level = (rtl_par) ? 2 : 0;
448 if (is_space && new_level >= level) {
454 int new_level2 = new_level;
456 if (level == new_level && rtl0 != new_rtl0) {
458 log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1;
459 } else if (level < new_level) {
460 log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1;
461 if (new_level > rtl_par)
462 bidi_same_direction = false;
464 log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1;
467 bidi_levels[lpos - bidi_start] = new_level;
469 while (level > new_level2) {
470 pos_type old_lpos = stack[--level];
471 int delta = lpos - old_lpos - 1;
474 log2vis_list[lpos - bidi_start] += delta;
475 log2vis_list[old_lpos - bidi_start] += delta;
477 while (level < new_level)
478 stack[level++] = lpos;
482 pos_type const old_lpos = stack[--level];
483 int delta = bidi_end - old_lpos;
486 log2vis_list[old_lpos - bidi_start] += delta;
489 pos_type vpos = bidi_start - 1;
490 for (pos_type lpos = bidi_start;
491 lpos <= bidi_end; ++lpos) {
492 vpos += log2vis_list[lpos - bidi_start];
493 vis2log_list[vpos - bidi_start] = lpos;
494 log2vis_list[lpos - bidi_start] = vpos;
499 // This method requires a previous call to ComputeBidiTables()
500 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
503 if (!lyxrc.rtl_support || pos == 0)
506 if (!bidi_InRange(pos - 1)) {
507 /// This can happen if pos is the first char of a row.
508 /// Returning false in this case is incorrect!
512 bool const rtl = bidi_level(pos - 1) % 2;
513 bool const rtl2 = bidi_InRange(pos)
514 ? bidi_level(pos) % 2
515 : par.isRightToLeftPar(buf->params);
520 bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
521 pos_type pos, LyXFont const & font) const
523 if (!lyxrc.rtl_support)
524 return false; // This is just for speedup
526 bool const rtl = font.isVisibleRightToLeft();
527 bool const rtl2 = bidi_InRange(pos)
528 ? bidi_level(pos) % 2
529 : par.isRightToLeftPar(buf->params);
534 int LyXText::leftMargin(Row const & row) const
538 if (row.pos() < row.par()->size())
539 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
540 (ins = row.par()->getInset(row.pos())) &&
541 (ins->needFullRow() || ins->display()))
544 LyXTextClass const & tclass =
545 bv()->buffer()->params.getLyXTextClass();
546 LyXLayout_ptr const & layout = row.par()->layout();
548 string parindent = layout->parindent;
552 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
554 // this is the way, LyX handles the LaTeX-Environments.
555 // I have had this idea very late, so it seems to be a
556 // later added hack and this is true
557 if (!row.par()->getDepth()) {
558 if (row.par()->layout() == tclass.defaultLayout()) {
559 // find the previous same level paragraph
560 if (row.par() != ownerParagraphs().begin()) {
561 ParagraphList::iterator newpit =
562 depthHook(row.par(), ownerParagraphs(),
563 row.par()->getDepth());
564 if (newpit == row.par() &&
565 newpit->layout()->nextnoindent)
570 // find the next level paragraph
572 ParagraphList::iterator newpar = outerHook(row.par(),
575 // make a corresponding row. Needed to call leftMargin()
577 // check wether it is a sufficent paragraph
578 if (newpar != ownerParagraphs().end() &&
579 newpar->layout()->isEnvironment()) {
581 dummyrow.par(newpar);
582 dummyrow.pos(newpar->size());
583 x = leftMargin(dummyrow);
586 if (newpar != ownerParagraphs().end() &&
587 row.par()->layout() == tclass.defaultLayout()) {
588 if (newpar->params().noindent())
591 parindent = newpar->layout()->parindent;
597 LyXFont const labelfont = getLabelFont(bv()->buffer(), row.par());
598 switch (layout->margintype) {
600 if (!layout->leftmargin.empty()) {
601 x += font_metrics::signedWidth(layout->leftmargin,
602 tclass.defaultfont());
604 if (!row.par()->getLabelstring().empty()) {
605 x += font_metrics::signedWidth(layout->labelindent,
607 x += font_metrics::width(row.par()->getLabelstring(),
609 x += font_metrics::width(layout->labelsep, labelfont);
613 x += font_metrics::signedWidth(layout->labelindent, labelfont);
614 // The width of an empty par, even with manual label, should be 0
615 if (!row.par()->empty() && row.pos() >= row.par()->beginningOfBody()) {
616 if (!row.par()->getLabelWidthString().empty()) {
617 x += font_metrics::width(row.par()->getLabelWidthString(),
619 x += font_metrics::width(layout->labelsep, labelfont);
624 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
625 / (row.par()->getDepth() + 4);
627 case MARGIN_FIRST_DYNAMIC:
628 if (layout->labeltype == LABEL_MANUAL) {
629 if (row.pos() >= row.par()->beginningOfBody()) {
630 x += font_metrics::signedWidth(layout->leftmargin,
633 x += font_metrics::signedWidth(layout->labelindent,
637 // Special case to fix problems with
639 || (layout->labeltype == LABEL_STATIC
640 && layout->latextype == LATEX_ENVIRONMENT
641 && !isFirstInSequence(row.par(), ownerParagraphs()))) {
642 x += font_metrics::signedWidth(layout->leftmargin,
644 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
645 && layout->labeltype != LABEL_BIBLIO
646 && layout->labeltype !=
647 LABEL_CENTERED_TOP_ENVIRONMENT) {
648 x += font_metrics::signedWidth(layout->labelindent,
650 x += font_metrics::width(layout->labelsep, labelfont);
651 x += font_metrics::width(row.par()->getLabelstring(),
656 case MARGIN_RIGHT_ADDRESS_BOX:
658 // ok, a terrible hack. The left margin depends on the widest
659 // row in this paragraph. Do not care about footnotes, they
660 // are *NOT* allowed in the LaTeX realisation of this layout.
662 // find the first row of this paragraph
663 RowList::iterator tmprit = rowlist_.begin();
664 while (tmprit != rowlist_.end()
665 && tmprit->par() != row.par())
668 int minfill = tmprit->fill();
669 while (boost::next(tmprit) != rowlist_.end() &&
670 boost::next(tmprit)->par() == row.par()) {
672 if (tmprit->fill() < minfill)
673 minfill = tmprit->fill();
676 x += font_metrics::signedWidth(layout->leftmargin,
677 tclass.defaultfont());
683 if ((workWidth() > 0) &&
684 !row.par()->params().leftIndent().zero())
686 LyXLength const len = row.par()->params().leftIndent();
687 int const tw = inset_owner ?
688 inset_owner->latexTextWidth(bv()) : workWidth();
689 x += len.inPixels(tw);
694 if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
695 align = layout->align;
697 align = row.par()->params().align();
699 // set the correct parindent
700 if (row.pos() == 0) {
701 if ((layout->labeltype == LABEL_NO_LABEL
702 || layout->labeltype == LABEL_TOP_ENVIRONMENT
703 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
704 || (layout->labeltype == LABEL_STATIC
705 && layout->latextype == LATEX_ENVIRONMENT
706 && !isFirstInSequence(row.par(), ownerParagraphs())))
707 && align == LYX_ALIGN_BLOCK
708 && !row.par()->params().noindent()
709 // in tabulars and ert paragraphs are never indented!
710 && (!row.par()->inInset() || !row.par()->inInset()->owner() ||
711 (row.par()->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE &&
712 row.par()->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
713 && (row.par()->layout() != tclass.defaultLayout() ||
714 bv()->buffer()->params.paragraph_separation ==
715 BufferParams::PARSEP_INDENT)) {
716 x += font_metrics::signedWidth(parindent,
717 tclass.defaultfont());
718 } else if (layout->labeltype == LABEL_BIBLIO) {
719 // ale970405 Right width for bibitems
720 x += bibitemMaxWidth(bv(), tclass.defaultfont());
728 int LyXText::rightMargin(Buffer const & buf, Row const & row) const
732 if (row.pos() < row.par()->size())
733 if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
734 (ins = row.par()->getInset(row.pos())) &&
735 (ins->needFullRow() || ins->display()))
738 LyXTextClass const & tclass = buf.params.getLyXTextClass();
739 LyXLayout_ptr const & layout = row.par()->layout();
742 + font_metrics::signedWidth(tclass.rightmargin(),
743 tclass.defaultfont());
745 x += font_metrics::signedWidth(layout->rightmargin,
746 tclass.defaultfont())
747 * 4 / (row.par()->getDepth() + 4);
752 int LyXText::labelEnd(Row const & row) const
754 if (row.par()->layout()->margintype == MARGIN_MANUAL) {
756 tmprow.pos(row.par()->size());
757 // return the beginning of the body
758 return leftMargin(tmprow);
761 // LabelEnd is only needed if the layout
762 // fills a flushleft label.
769 // this needs special handling - only newlines count as a break point
770 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
772 for (; i < par.size(); ++i) {
773 if (par.isNewline(i))
783 pos_type LyXText::rowBreakPoint(Row const & row) const
785 ParagraphList::iterator pit = row.par();
787 // maximum pixel width of a row.
788 int width = workWidth() - rightMargin(*bv()->buffer(), row);
790 // inset->textWidth() returns -1 via workWidth(),
795 LyXLayout_ptr const & layout = pit->layout();
797 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
798 return addressBreakPoint(row.pos(), *pit);
800 pos_type const pos = row.pos();
801 pos_type const body_pos = pit->beginningOfBody();
802 pos_type const last = pit->size();
803 pos_type point = last;
808 // Now we iterate through until we reach the right margin
809 // or the end of the par, then choose the possible break
812 int const left = leftMargin(row);
815 // pixel width since last breakpoint
817 bool fullrow = false;
820 for (; i < last; ++i) {
821 if (pit->isNewline(i)) {
826 char const c = pit->getChar(i);
830 // add the auto-hfill from label end to the body
831 if (body_pos && i == body_pos) {
832 thiswidth = font_metrics::width(layout->labelsep,
833 getLabelFont(bv()->buffer(), pit));
834 if (pit->isLineSeparator(i - 1))
835 thiswidth -= singleWidth(pit, i - 1);
836 int left_margin = labelEnd(row);
837 if (thiswidth + x < left_margin)
838 thiswidth = left_margin - x;
839 thiswidth += singleWidth(pit, i, c);
841 thiswidth = singleWidth(pit, i, c);
845 chunkwidth += thiswidth;
847 InsetOld * in = pit->isInset(i) ? pit->getInset(i) : 0;
848 fullrow = (in && (in->display() || in->needFullRow()));
850 // break before a character that will fall off
851 // the right of the row
853 // if no break before or we are at an inset
854 // that will take up a row, break here
855 if (point == last || fullrow || chunkwidth >= (width - left)) {
864 if (!in || in->isChar()) {
865 // some insets are line separators too
866 if (pit->isLineSeparator(i)) {
876 // full row insets start at a new row
878 if (pos < last - 1) {
880 if (pit->isLineSeparator(i + 1))
883 // to avoid extra rows
893 if (point == last && x >= width) {
894 // didn't find one, break at the point we reached the edge
896 } else if (i == last && x < width) {
897 // found one, but we fell off the end of the par, so prefer
902 // manual labels cannot be broken in LaTeX. But we
903 // want to make our on-screen rendering of footnotes
905 if (!fullrow && body_pos && point < body_pos)
906 point = body_pos - 1;
912 // returns the minimum space a row needs on the screen in pixel
913 int LyXText::fill(RowList::iterator row, int paper_width) const
919 // get the pure distance
920 pos_type const last = lastPrintablePos(*this, row);
922 ParagraphList::iterator pit = row->par();
923 LyXLayout_ptr const & layout = pit->layout();
925 // special handling of the right address boxes
926 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
927 int const tmpfill = row->fill();
928 row->fill(0); // the minfill in MarginLeft()
929 w = leftMargin(*row);
932 w = leftMargin(*row);
934 pos_type const body_pos = pit->beginningOfBody();
935 pos_type i = row->pos();
937 if (! pit->empty() && i <= last) {
938 // We re-use the font resolution for the entire span when possible
939 LyXFont font = getFont(bv()->buffer(), pit, i);
940 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
942 if (body_pos > 0 && i == body_pos) {
943 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
944 if (pit->isLineSeparator(i - 1))
945 w -= singleWidth(pit, i - 1);
946 int left_margin = labelEnd(*row);
950 { // Manual inlined an optimised version of the common case of "w += singleWidth(pit, i);"
951 char const c = pit->getChar(i);
953 if (IsPrintable(c)) {
954 if (i > endPosOfFontSpan) {
955 // We need to get the next font
956 font = getFont(bv()->buffer(), pit, i);
957 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
959 if (! font.language()->RightToLeft()) {
960 w += font_metrics::width(c, font);
962 // Fall-back to the normal case
963 w += singleWidth(pit, i, c);
964 // And flush font cache
965 endPosOfFontSpan = 0;
968 // Fall-back to the normal case
969 w += singleWidth(pit, i, c);
970 // And flush font cache
971 endPosOfFontSpan = 0;
977 if (body_pos > 0 && body_pos > last) {
978 w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit));
979 if (last >= 0 && pit->isLineSeparator(last))
980 w -= singleWidth(pit, last);
981 int const left_margin = labelEnd(*row);
986 int const fill = paper_width - w - rightMargin(*bv()->buffer(), *row);
988 // If this case happens, it means that our calculation
989 // of the widths of the chars when we do rowBreakPoint()
990 // went wrong for some reason. Typically in list bodies.
991 // Things just about hobble on anyway, though you'll end
992 // up with a "fill_separator" less than zero, which corresponds
993 // to inter-word spacing being too small. Hopefully this problem
994 // will die when the label hacks die.
995 if (lyxerr.debugging() && fill < 0) {
996 lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
997 << " w " << w << " paper_width " << paper_width
998 << " right margin " << rightMargin(*bv()->buffer(), *row) << endl;
1005 // returns the minimum space a manual label needs on the screen in pixel
1006 int LyXText::labelFill(Row const & row) const
1008 ParagraphList::iterator pit = row.par();
1010 pos_type last = pit->beginningOfBody();
1014 // -1 because a label ends either with a space that is in the label,
1015 // or with the beginning of a footnote that is outside the label.
1018 // a separator at this end does not count
1019 if (pit->isLineSeparator(last))
1023 pos_type i = row.pos();
1025 w += singleWidth(pit, i);
1030 string const & labwidstr = pit->params().labelWidthString();
1031 if (!labwidstr.empty()) {
1032 LyXFont const labfont = getLabelFont(bv()->buffer(), pit);
1033 int const labwidth = font_metrics::width(labwidstr, labfont);
1034 fill = max(labwidth - w, 0);
1041 LColor::color LyXText::backgroundColor() const
1044 return inset_owner->backgroundColor();
1046 return LColor::background;
1050 void LyXText::setHeightOfRow(RowList::iterator rit)
1052 Assert(rit != rows().end());
1054 // get the maximum ascent and the maximum descent
1055 float layoutasc = 0;
1056 float layoutdesc = 0;
1059 InsetOld * tmpinset = 0;
1061 // ok, let us initialize the maxasc and maxdesc value.
1062 // This depends in LaTeX of the font of the last character
1063 // in the paragraph. The hack below is necessary because
1064 // of the possibility of open footnotes
1066 // Correction: only the fontsize count. The other properties
1067 // are taken from the layoutfont. Nicer on the screen :)
1068 ParagraphList::iterator pit = rit->par();
1070 LyXLayout_ptr const & layout = pit->layout();
1072 // as max get the first character of this row then it can increase but not
1073 // decrease the height. Just some point to start with so we don't have to
1074 // do the assignment below too often.
1075 LyXFont font = getFont(bv()->buffer(), pit, rit->pos());
1076 LyXFont::FONT_SIZE const tmpsize = font.size();
1077 font = getLayoutFont(bv()->buffer(), pit);
1078 LyXFont::FONT_SIZE const size = font.size();
1079 font.setSize(tmpsize);
1081 LyXFont labelfont = getLabelFont(bv()->buffer(), pit);
1083 float spacing_val = 1.0;
1084 if (!pit->params().spacing().isDefault()) {
1085 spacing_val = pit->params().spacing().getValue();
1087 spacing_val = bv()->buffer()->params.spacing.getValue();
1089 //lyxerr << "spacing_val = " << spacing_val << endl;
1091 int maxasc = int(font_metrics::maxAscent(font) *
1092 layout->spacing.getValue() *
1094 int maxdesc = int(font_metrics::maxDescent(font) *
1095 layout->spacing.getValue() *
1098 pos_type const pos_end = lastPos(*this, rit);
1102 if (!pit->empty()) {
1103 // Check if any insets are larger
1104 for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) {
1105 if (pit->isInset(pos)) {
1106 tmpfont = getFont(bv()->buffer(), pit, pos);
1107 tmpinset = pit->getInset(pos);
1109 #if 1 // this is needed for deep update on initialitation
1110 #warning inset->update FIXME
1111 //tmpinset->update(bv());
1113 MetricsInfo mi(bv(), tmpfont, workWidth());
1114 tmpinset->metrics(mi, dim);
1115 maxwidth += dim.wid;
1116 maxasc = max(maxasc, dim.asc);
1117 maxdesc = max(maxdesc, dim.des);
1119 maxwidth += tmpinset->width();
1120 maxasc = max(maxasc, tmpinset->ascent());
1121 maxdesc = max(maxdesc, tmpinset->descent());
1125 // Manual inlined optimised version of common case of "maxwidth += singleWidth(pit, pos);"
1126 char const c = pit->getChar(pos);
1127 maxwidth += singleWidth(pit, pos, c);
1133 // Check if any custom fonts are larger (Asger)
1134 // This is not completely correct, but we can live with the small,
1135 // cosmetic error for now.
1136 LyXFont::FONT_SIZE maxsize =
1137 pit->highestFontInRange(rit->pos(), pos_end, size);
1138 if (maxsize > font.size()) {
1139 font.setSize(maxsize);
1140 maxasc = max(maxasc, font_metrics::maxAscent(font));
1141 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
1144 // This is nicer with box insets:
1148 rit->ascent_of_text(maxasc);
1150 // is it a top line?
1153 // some parksips VERY EASY IMPLEMENTATION
1154 if (bv()->buffer()->params.paragraph_separation ==
1155 BufferParams::PARSEP_SKIP)
1157 if (layout->isParagraph()
1158 && pit->getDepth() == 0
1159 && pit != ownerParagraphs().begin())
1161 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1162 } else if (pit != ownerParagraphs().begin() &&
1163 boost::prior(pit)->layout()->isParagraph() &&
1164 boost::prior(pit)->getDepth() == 0)
1166 // is it right to use defskip here too? (AS)
1167 maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
1172 if (pit == ownerParagraphs().begin() && !isInInset())
1173 maxasc += PAPER_MARGIN;
1175 // add the vertical spaces, that the user added
1176 maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
1178 // do not forget the DTP-lines!
1179 // there height depends on the font of the nearest character
1180 if (pit->params().lineTop())
1182 maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(),
1184 // and now the pagebreaks
1185 if (pit->params().pagebreakTop())
1186 maxasc += 3 * defaultRowHeight();
1188 if (pit->params().startOfAppendix())
1189 maxasc += 3 * defaultRowHeight();
1191 // This is special code for the chapter, since the label of this
1192 // layout is printed in an extra row
1193 if (layout->labeltype == LABEL_COUNTER_CHAPTER
1194 && bv()->buffer()->params.secnumdepth >= 0)
1196 float spacing_val = 1.0;
1197 if (!pit->params().spacing().isDefault()) {
1198 spacing_val = pit->params().spacing().getValue();
1200 spacing_val = bv()->buffer()->params.spacing.getValue();
1203 labeladdon = int(font_metrics::maxDescent(labelfont) *
1204 layout->spacing.getValue() *
1206 + int(font_metrics::maxAscent(labelfont) *
1207 layout->spacing.getValue() *
1211 // special code for the top label
1212 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1213 || layout->labeltype == LABEL_BIBLIO
1214 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1215 && isFirstInSequence(pit, ownerParagraphs())
1216 && !pit->getLabelstring().empty())
1218 float spacing_val = 1.0;
1219 if (!pit->params().spacing().isDefault()) {
1220 spacing_val = pit->params().spacing().getValue();
1222 spacing_val = bv()->buffer()->params.spacing.getValue();
1226 (font_metrics::maxAscent(labelfont) *
1227 layout->spacing.getValue() *
1229 +(font_metrics::maxDescent(labelfont) *
1230 layout->spacing.getValue() *
1232 + layout->topsep * defaultRowHeight()
1233 + layout->labelbottomsep * defaultRowHeight());
1236 // And now the layout spaces, for example before and after
1237 // a section, or between the items of a itemize or enumerate
1240 if (!pit->params().pagebreakTop()) {
1241 ParagraphList::iterator prev =
1242 depthHook(pit, ownerParagraphs(),
1244 if (prev != pit && prev->layout() == layout &&
1245 prev->getDepth() == pit->getDepth() &&
1246 prev->getLabelWidthString() == pit->getLabelWidthString())
1248 layoutasc = (layout->itemsep * defaultRowHeight());
1249 } else if (rit != rows().begin()) {
1250 tmptop = layout->topsep;
1252 if (boost::prior(pit)->getDepth() >= pit->getDepth())
1253 tmptop -= boost::prior(rit)->par()->layout()->bottomsep;
1256 layoutasc = (tmptop * defaultRowHeight());
1257 } else if (pit->params().lineTop()) {
1258 tmptop = layout->topsep;
1261 layoutasc = (tmptop * defaultRowHeight());
1264 prev = outerHook(pit, ownerParagraphs());
1265 if (prev != ownerParagraphs().end()) {
1266 maxasc += int(prev->layout()->parsep * defaultRowHeight());
1267 } else if (pit != ownerParagraphs().begin()) {
1268 ParagraphList::iterator prior_pit = boost::prior(pit);
1269 if (prior_pit->getDepth() != 0 ||
1270 prior_pit->layout() == layout) {
1271 maxasc += int(layout->parsep * defaultRowHeight());
1277 // is it a bottom line?
1278 RowList::iterator next_rit = boost::next(rit);
1279 if (next_rit == rows().end() || next_rit->par() != pit) {
1280 // the bottom margin
1281 ParagraphList::iterator nextpit = boost::next(pit);
1282 if (nextpit == ownerParagraphs().end() &&
1284 maxdesc += PAPER_MARGIN;
1286 // add the vertical spaces, that the user added
1287 maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
1289 // do not forget the DTP-lines!
1290 // there height depends on the font of the nearest character
1291 if (pit->params().lineBottom())
1292 maxdesc += 2 * font_metrics::ascent('x',
1293 getFont(bv()->buffer(),
1295 max(pos_type(0), pit->size() - 1)));
1297 // and now the pagebreaks
1298 if (pit->params().pagebreakBottom())
1299 maxdesc += 3 * defaultRowHeight();
1301 // and now the layout spaces, for example before and after
1302 // a section, or between the items of a itemize or enumerate
1304 if (!pit->params().pagebreakBottom()
1305 && nextpit != ownerParagraphs().end()) {
1306 ParagraphList::iterator comparepit = pit;
1310 if (comparepit->getDepth() > nextpit->getDepth()) {
1311 usual = (comparepit->layout()->bottomsep * defaultRowHeight());
1312 comparepit = depthHook(comparepit, ownerParagraphs(), nextpit->getDepth());
1313 if (comparepit->layout()!= nextpit->layout()
1314 || nextpit->getLabelWidthString() !=
1315 comparepit->getLabelWidthString())
1317 unusual = (comparepit->layout()->bottomsep * defaultRowHeight());
1319 if (unusual > usual)
1320 layoutdesc = unusual;
1323 } else if (comparepit->getDepth() == nextpit->getDepth()) {
1325 if (comparepit->layout() != nextpit->layout()
1326 || nextpit->getLabelWidthString() !=
1327 comparepit->getLabelWidthString())
1328 layoutdesc = int(comparepit->layout()->bottomsep * defaultRowHeight());
1333 // incalculate the layout spaces
1334 maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
1335 maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
1337 // calculate the new height of the text
1338 height -= rit->height();
1340 rit->height(maxasc + maxdesc + labeladdon);
1341 rit->baseline(maxasc + labeladdon);
1343 height += rit->height();
1345 rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font));
1348 if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
1351 rit->width(maxwidth);
1352 prepareToPrint(rit, x, dummy, dummy, dummy, false);
1354 rit->width(int(maxwidth + x));
1356 width = max(0, workWidth());
1357 RowList::iterator it = rows().begin();
1358 RowList::iterator end = rows().end();
1359 for (; it != end; ++it) {
1360 if (it->width() > width)
1361 width = it->width();
1367 // Appends the implicit specified paragraph before the specified row,
1368 // start at the implicit given position
1369 void LyXText::appendParagraph(RowList::iterator rowit)
1371 Assert(rowit != rowlist_.end());
1373 pos_type const last = rowit->par()->size();
1377 pos_type z = rowBreakPoint(*rowit);
1379 RowList::iterator tmprow = rowit;
1383 Row newrow(rowit->par(), z);
1384 rowit = rowlist_.insert(boost::next(rowit), newrow);
1389 // Set the dimensions of the row
1390 // fixed fill setting now by calling inset->update() in
1391 // SingleWidth when needed!
1392 tmprow->fill(fill(tmprow, workWidth()));
1393 setHeightOfRow(tmprow);
1399 void LyXText::breakAgain(RowList::iterator rit)
1401 Assert(rit != rows().end());
1403 bool not_ready = true;
1406 pos_type z = rowBreakPoint(*rit);
1407 RowList::iterator tmprit = rit;
1408 RowList::iterator end = rows().end();
1410 if (z < rit->par()->size()) {
1411 RowList::iterator next_rit = boost::next(rit);
1413 if (next_rit == end ||
1415 next_rit->par() != rit->par())) {
1418 Row newrow(rit->par(), z);
1419 rit = rowlist_.insert(next_rit, newrow);
1423 if (rit->pos() == z)
1424 not_ready = false; // the rest will not change
1430 // if there are some rows too much, delete them
1431 // only if you broke the whole paragraph!
1432 RowList::iterator tmprit2 = rit;
1433 while (boost::next(tmprit2) != end
1434 && boost::next(tmprit2)->par() == rit->par()) {
1437 while (tmprit2 != rit) {
1439 removeRow(boost::next(tmprit2));
1444 // set the dimensions of the row
1445 tmprit->fill(fill(tmprit, workWidth()));
1446 setHeightOfRow(tmprit);
1447 } while (not_ready);
1451 // this is just a little changed version of break again
1452 void LyXText::breakAgainOneRow(RowList::iterator rit)
1454 Assert(rit != rows().end());
1456 pos_type z = rowBreakPoint(*rit);
1457 RowList::iterator tmprit = rit;
1458 RowList::iterator end = rows().end();
1460 if (z < rit->par()->size()) {
1461 RowList::iterator next_rit = boost::next(rit);
1463 if (next_rit == end ||
1465 next_rit->par() != rit->par())) {
1468 Row newrow(rit->par(), z);
1469 rit = rowlist_.insert(next_rit, newrow);
1473 if (rit->pos() != z)
1477 // if there are some rows too much, delete them
1478 // only if you broke the whole paragraph!
1479 RowList::iterator tmprit2 = rit;
1480 while (boost::next(tmprit2) != end
1481 && boost::next(tmprit2)->par() == rit->par()) {
1484 while (tmprit2 != rit) {
1486 removeRow(boost::next(tmprit2));
1490 // set the dimensions of the row
1491 tmprit->fill(fill(tmprit, workWidth()));
1492 setHeightOfRow(tmprit);
1496 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
1498 // allow only if at start or end, or all previous is new text
1499 if (cursor.pos() && cursor.pos() != cursor.par()->size()
1500 && cursor.par()->isChangeEdited(0, cursor.pos()))
1503 LyXTextClass const & tclass =
1504 bv()->buffer()->params.getLyXTextClass();
1505 LyXLayout_ptr const & layout = cursor.par()->layout();
1507 // this is only allowed, if the current paragraph is not empty or caption
1508 // and if it has not the keepempty flag active
1509 if (cursor.par()->empty() && !cursor.par()->allowEmpty()
1510 && layout->labeltype != LABEL_SENSITIVE)
1513 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1515 // Always break behind a space
1517 // It is better to erase the space (Dekel)
1518 if (cursor.pos() < cursor.par()->size()
1519 && cursor.par()->isLineSeparator(cursor.pos()))
1520 cursor.par()->erase(cursor.pos());
1521 // cursor.pos(cursor.pos() + 1);
1523 // break the paragraph
1527 keep_layout = layout->isEnvironment();
1529 // we need to set this before we insert the paragraph. IMO the
1530 // breakParagraph call should return a bool if it inserts the
1531 // paragraph before or behind and we should react on that one
1532 // but we can fix this in 1.3.0 (Jug 20020509)
1533 bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty());
1534 ::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(),
1535 cursor.pos(), keep_layout);
1537 // well this is the caption hack since one caption is really enough
1538 if (layout->labeltype == LABEL_SENSITIVE) {
1540 // set to standard-layout
1541 cursor.par()->applyLayout(tclass.defaultLayout());
1543 // set to standard-layout
1544 boost::next(cursor.par())->applyLayout(tclass.defaultLayout());
1547 // if the cursor is at the beginning of a row without prior newline,
1549 // This touches only the screen-update. Otherwise we would may have
1550 // an empty row on the screen
1551 if (cursor.pos() && cursorRow()->pos() == cursor.pos()
1552 && !cursorRow()->par()->isNewline(cursor.pos() - 1))
1559 removeParagraph(cursorRow());
1561 // set the dimensions of the cursor row
1562 cursorRow()->fill(fill(cursorRow(), workWidth()));
1564 setHeightOfRow(cursorRow());
1566 #warning Trouble Point! (Lgb)
1567 // When ::breakParagraph is called from within an inset we must
1568 // ensure that the correct ParagraphList is used. Today that is not
1569 // the case and the Buffer::paragraphs is used. Not good. (Lgb)
1570 ParagraphList::iterator next_par = boost::next(cursor.par());
1572 while (!next_par->empty() && next_par->isNewline(0))
1575 insertParagraph(next_par, boost::next(cursorRow()));
1578 // This check is necessary. Otherwise the new empty paragraph will
1579 // be deleted automatically. And it is more friendly for the user!
1580 if (cursor.pos() || isempty)
1581 setCursor(next_par, 0);
1583 setCursor(cursor.par(), 0);
1585 if (boost::next(cursorRow()) != rows().end())
1586 breakAgain(boost::next(cursorRow()));
1588 need_break_row = rows().end();
1592 // Just a macro to make some thing easier.
1593 void LyXText::redoParagraph()
1596 redoParagraphs(cursor, boost::next(cursor.par()));
1597 setCursorIntern(cursor.par(), cursor.pos());
1601 // insert a character, moves all the following breaks in the
1602 // same Paragraph one to the right and make a rebreak
1603 void LyXText::insertChar(char c)
1605 recordUndo(bv(), Undo::INSERT, cursor.par());
1607 // When the free-spacing option is set for the current layout,
1608 // disable the double-space checking
1610 bool const freeSpacing = cursorRow()->par()->layout()->free_spacing ||
1611 cursorRow()->par()->isFreeSpacing();
1613 if (lyxrc.auto_number) {
1614 static string const number_operators = "+-/*";
1615 static string const number_unary_operators = "+-";
1616 static string const number_seperators = ".,:";
1618 if (current_font.number() == LyXFont::ON) {
1619 if (!IsDigit(c) && !contains(number_operators, c) &&
1620 !(contains(number_seperators, c) &&
1621 cursor.pos() >= 1 &&
1622 cursor.pos() < cursor.par()->size() &&
1623 getFont(bv()->buffer(),
1625 cursor.pos()).number() == LyXFont::ON &&
1626 getFont(bv()->buffer(),
1628 cursor.pos() - 1).number() == LyXFont::ON)
1630 number(bv()); // Set current_font.number to OFF
1631 } else if (IsDigit(c) &&
1632 real_current_font.isVisibleRightToLeft()) {
1633 number(bv()); // Set current_font.number to ON
1635 if (cursor.pos() > 0) {
1636 char const c = cursor.par()->getChar(cursor.pos() - 1);
1637 if (contains(number_unary_operators, c) &&
1638 (cursor.pos() == 1 ||
1639 cursor.par()->isSeparator(cursor.pos() - 2) ||
1640 cursor.par()->isNewline(cursor.pos() - 2))
1642 setCharFont(bv()->buffer(),
1646 } else if (contains(number_seperators, c) &&
1647 cursor.pos() >= 2 &&
1648 getFont(bv()->buffer(),
1650 cursor.pos() - 2).number() == LyXFont::ON) {
1651 setCharFont(bv()->buffer(),
1661 // First check, if there will be two blanks together or a blank at
1662 // the beginning of a paragraph.
1663 // I decided to handle blanks like normal characters, the main
1664 // difference are the special checks when calculating the row.fill
1665 // (blank does not count at the end of a row) and the check here
1667 // The bug is triggered when we type in a description environment:
1668 // The current_font is not changed when we go from label to main text
1669 // and it should (along with realtmpfont) when we type the space.
1670 // CHECK There is a bug here! (Asger)
1672 LyXFont realtmpfont = real_current_font;
1673 LyXFont rawtmpfont = current_font;
1674 // store the current font. This is because of the use of cursor
1675 // movements. The moving cursor would refresh the current font
1677 // Get the font that is used to calculate the baselineskip
1678 pos_type const lastpos = cursor.par()->size();
1679 LyXFont rawparfont =
1680 cursor.par()->getFontSettings(bv()->buffer()->params,
1683 bool jumped_over_space = false;
1685 if (!freeSpacing && IsLineSeparatorChar(c)) {
1686 if ((cursor.pos() > 0
1687 && cursor.par()->isLineSeparator(cursor.pos() - 1))
1688 || (cursor.pos() > 0
1689 && cursor.par()->isNewline(cursor.pos() - 1))
1690 || (cursor.pos() == 0)) {
1691 static bool sent_space_message = false;
1692 if (!sent_space_message) {
1693 if (cursor.pos() == 0)
1694 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
1696 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
1697 sent_space_message = true;
1704 // the display inset stuff
1705 if (cursorRow()->pos() < cursorRow()->par()->size()
1706 && cursorRow()->par()->isInset(cursorRow()->pos())) {
1707 InsetOld * inset = cursorRow()->par()->getInset(cursorRow()->pos());
1708 if (inset && (inset->display() || inset->needFullRow())) {
1709 // force a new break
1710 cursorRow()->fill(-1); // to force a new break
1714 // get the cursor row fist
1715 RowList::iterator row = cursorRow();
1716 if (c != Paragraph::META_INSET) {
1717 // Here case LyXText::InsertInset already inserted the character
1718 cursor.par()->insertChar(cursor.pos(), c);
1720 setCharFont(bv()->buffer(), cursor.par(), cursor.pos(), rawtmpfont);
1722 if (!jumped_over_space) {
1723 // refresh the positions
1724 RowList::iterator tmprow = row;
1725 while (boost::next(tmprow) != rows().end() &&
1726 boost::next(tmprow)->par() == row->par()) {
1728 tmprow->pos(tmprow->pos() + 1);
1732 // Is there a break one row above
1733 if (row != rows().begin() &&
1734 boost::prior(row)->par() == row->par()
1735 && (cursor.par()->isLineSeparator(cursor.pos())
1736 || cursor.par()->isNewline(cursor.pos())
1737 || ((cursor.pos() + 1 < cursor.par()->size()) &&
1738 cursor.par()->isInset(cursor.pos() + 1))
1739 || cursorRow()->fill() == -1))
1741 pos_type z = rowBreakPoint(*boost::prior(row));
1743 if (z >= row->pos()) {
1746 // set the dimensions of the row above
1747 boost::prior(row)->fill(fill(
1751 setHeightOfRow(boost::prior(row));
1755 breakAgainOneRow(row);
1757 current_font = rawtmpfont;
1758 real_current_font = realtmpfont;
1759 setCursor(cursor.par(), cursor.pos() + 1,
1760 false, cursor.boundary());
1761 // cursor MUST be in row now.
1763 RowList::iterator next_row = boost::next(row);
1764 if (next_row != rows().end() &&
1765 next_row->par() == row->par())
1766 need_break_row = next_row;
1768 need_break_row = rows().end();
1770 // check, wether the last characters font has changed.
1771 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1772 && rawparfont != rawtmpfont)
1773 redoHeightOfParagraph();
1780 // recalculate the fill of the row
1781 if (row->fill() >= 0) {
1782 // needed because a newline will set fill to -1. Otherwise
1783 // we would not get a rebreak!
1784 row->fill(fill(row, workWidth()));
1787 if (c == Paragraph::META_INSET || row->fill() < 0) {
1789 breakAgainOneRow(row);
1791 RowList::iterator next_row = boost::next(row);
1793 // will the cursor be in another row now?
1794 if (lastPos(*this, row) <= cursor.pos() + 1 &&
1795 next_row != rows().end()) {
1796 if (next_row != rows().end() &&
1797 next_row->par() == row->par()) {
1798 // this should always be true
1802 breakAgainOneRow(row);
1804 current_font = rawtmpfont;
1805 real_current_font = realtmpfont;
1807 setCursor(cursor.par(), cursor.pos() + 1, false,
1809 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
1810 != cursor.boundary())
1811 setCursor(cursor.par(), cursor.pos(), false,
1812 !cursor.boundary());
1814 next_row = boost::next(row);
1816 if (next_row != rows().end() &&
1817 next_row->par() == row->par())
1818 need_break_row = next_row;
1820 need_break_row = rows().end();
1822 // FIXME: similar code is duplicated all over - make resetHeightOfRow
1823 setHeightOfRow(row);
1826 current_font = rawtmpfont;
1827 real_current_font = realtmpfont;
1828 setCursor(cursor.par(), cursor.pos() + 1, false,
1832 // check, wether the last characters font has changed.
1833 if (cursor.pos() && cursor.pos() == cursor.par()->size()
1834 && rawparfont != rawtmpfont) {
1835 redoHeightOfParagraph();
1842 void LyXText::charInserted()
1844 // Here we could call FinishUndo for every 20 characters inserted.
1845 // This is from my experience how emacs does it. (Lgb)
1846 static unsigned int counter;
1856 void LyXText::prepareToPrint(RowList::iterator rit, int & x,
1857 int & fill_separator,
1859 int & fill_label_hfill,
1862 int w = rit->fill();
1864 fill_label_hfill = 0;
1866 fill_label_hfill = 0;
1868 ParagraphList::iterator pit = rit->par();
1871 pit->isRightToLeftPar(bv()->buffer()->params);
1873 x = workWidth() > 0 ? rightMargin(*bv()->buffer(), *rit) : 0;
1875 x = workWidth() > 0 ? leftMargin(*rit) : 0;
1877 // is there a manual margin with a manual label
1878 LyXLayout_ptr const & layout = pit->layout();
1880 if (layout->margintype == MARGIN_MANUAL
1881 && layout->labeltype == LABEL_MANUAL) {
1882 /// We might have real hfills in the label part
1883 int nlh = numberOfLabelHfills(*this, rit);
1885 // A manual label par (e.g. List) has an auto-hfill
1886 // between the label text and the body of the
1888 // But we don't want to do this auto hfill if the par
1893 if (nlh && !pit->getLabelWidthString().empty()) {
1894 fill_label_hfill = int(labelFill(*rit) / nlh);
1898 // are there any hfills in the row?
1899 int const nh = numberOfHfills(*this, rit);
1903 fill_hfill = w / nh;
1904 // we don't have to look at the alignment if it is ALIGN_LEFT and
1905 // if the row is already larger then the permitted width as then
1906 // we force the LEFT_ALIGN'edness!
1907 } else if (int(rit->width()) < workWidth()) {
1908 // is it block, flushleft or flushright?
1909 // set x how you need it
1911 if (pit->params().align() == LYX_ALIGN_LAYOUT) {
1912 align = layout->align;
1914 align = pit->params().align();
1917 // center displayed insets
1918 InsetOld * inset = 0;
1919 if (rit->pos() < pit->size()
1920 && pit->isInset(rit->pos())
1921 && (inset = pit->getInset(rit->pos()))
1922 && (inset->display())) // || (inset->scroll() < 0)))
1923 align = (inset->lyxCode() == InsetOld::MATHMACRO_CODE)
1924 ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
1925 // ERT insets should always be LEFT ALIGNED on screen
1926 inset = pit->inInset();
1927 if (inset && inset->owner() &&
1928 inset->owner()->lyxCode() == InsetOld::ERT_CODE)
1930 align = LYX_ALIGN_LEFT;
1934 case LYX_ALIGN_BLOCK:
1936 int const ns = numberOfSeparators(*this, rit);
1937 RowList::iterator next_row = boost::next(rit);
1938 ParagraphList::iterator next_pit = next_row->par();
1940 if (ns && next_row != rowlist_.end() &&
1942 !(next_pit->isNewline(next_row->pos() - 1))
1943 && !(next_pit->isInset(next_row->pos()) &&
1944 next_pit->getInset(next_row->pos()) &&
1945 next_pit->getInset(next_row->pos())->display())
1947 fill_separator = w / ns;
1948 } else if (is_rtl) {
1953 case LYX_ALIGN_RIGHT:
1956 case LYX_ALIGN_CENTER:
1964 computeBidiTables(bv()->buffer(), rit);
1966 pos_type body_pos = pit->beginningOfBody();
1967 pos_type last = lastPos(*this, rit);
1970 (body_pos - 1 > last ||
1971 !pit->isLineSeparator(body_pos - 1))) {
1972 x += font_metrics::width(layout->labelsep,
1973 getLabelFont(bv()->buffer(),
1975 if (body_pos - 1 <= last)
1976 x += fill_label_hfill;
1982 // important for the screen
1985 // the cursor set functions have a special mechanism. When they
1986 // realize, that you left an empty paragraph, they will delete it.
1987 // They also delete the corresponding row
1989 void LyXText::cursorRightOneWord()
1991 ::cursorRightOneWord(cursor, ownerParagraphs());
1992 setCursor(cursor.par(), cursor.pos());
1996 // Skip initial whitespace at end of word and move cursor to *start*
1997 // of prior word, not to end of next prior word.
1998 void LyXText::cursorLeftOneWord()
2000 LyXCursor tmpcursor = cursor;
2001 ::cursorLeftOneWord(tmpcursor, ownerParagraphs());
2002 setCursor(tmpcursor.par(), tmpcursor.pos());
2006 void LyXText::selectWord(word_location loc)
2008 LyXCursor from = cursor;
2010 ::getWord(from, to, loc, ownerParagraphs());
2012 setCursor(from.par(), from.pos());
2015 selection.cursor = cursor;
2016 setCursor(to.par(), to.pos());
2021 // Select the word currently under the cursor when no
2022 // selection is currently set
2023 bool LyXText::selectWordWhenUnderCursor(word_location loc)
2025 if (!selection.set()) {
2027 return selection.set();
2033 void LyXText::acceptChange()
2035 if (!selection.set() && cursor.par()->size())
2038 if (selection.start.par() == selection.end.par()) {
2039 LyXCursor & startc = selection.start;
2040 LyXCursor & endc = selection.end;
2041 recordUndo(bv(), Undo::INSERT, startc.par());
2042 startc.par()->acceptChange(startc.pos(), endc.pos());
2045 redoParagraphs(startc, boost::next(startc.par()));
2046 setCursorIntern(startc.par(), 0);
2048 #warning handle multi par selection
2052 void LyXText::rejectChange()
2054 if (!selection.set() && cursor.par()->size())
2057 if (selection.start.par() == selection.end.par()) {
2058 LyXCursor & startc = selection.start;
2059 LyXCursor & endc = selection.end;
2060 recordUndo(bv(), Undo::INSERT, startc.par());
2061 startc.par()->rejectChange(startc.pos(), endc.pos());
2064 redoParagraphs(startc, boost::next(startc.par()));
2065 setCursorIntern(startc.par(), 0);
2067 #warning handle multi par selection
2071 // This function is only used by the spellchecker for NextWord().
2072 // It doesn't handle LYX_ACCENTs and probably never will.
2074 LyXText::selectNextWordToSpellcheck(float & value)
2076 if (the_locking_inset) {
2077 WordLangTuple word = the_locking_inset->selectNextWordToSpellcheck(bv(), value);
2078 if (!word.word().empty()) {
2079 value += float(cursor.y());
2080 value /= float(height);
2083 // we have to go on checking so move cursor to the next char
2084 if (cursor.pos() == cursor.par()->size()) {
2085 if (boost::next(cursor.par()) == ownerParagraphs().end())
2087 cursor.par(boost::next(cursor.par()));
2090 cursor.pos(cursor.pos() + 1);
2092 ParagraphList::iterator tmppit = cursor.par();
2094 // If this is not the very first word, skip rest of
2095 // current word because we are probably in the middle
2096 // of a word if there is text here.
2097 if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
2098 while (cursor.pos() < cursor.par()->size()
2099 && cursor.par()->isLetter(cursor.pos()))
2100 cursor.pos(cursor.pos() + 1);
2103 // Now, skip until we have real text (will jump paragraphs)
2105 ParagraphList::iterator cpit = cursor.par();
2106 pos_type const cpos(cursor.pos());
2108 if (cpos == cpit->size()) {
2109 if (boost::next(cpit) != ownerParagraphs().end()) {
2110 cursor.par(boost::next(cpit));
2117 bool const is_good_inset = cpit->isInset(cpos)
2118 && cpit->getInset(cpos)->allowSpellcheck();
2120 if (!isDeletedText(*cpit, cpos)
2121 && (is_good_inset || cpit->isLetter(cpos)))
2124 cursor.pos(cpos + 1);
2127 // now check if we hit an inset so it has to be a inset containing text!
2128 if (cursor.pos() < cursor.par()->size() &&
2129 cursor.par()->isInset(cursor.pos())) {
2131 FuncRequest cmd(bv(), LFUN_INSET_EDIT, "left");
2132 cursor.par()->getInset(cursor.pos())->localDispatch(cmd);
2133 // now call us again to do the above trick
2134 // but obviously we have to start from down below ;)
2135 return bv()->text->selectNextWordToSpellcheck(value);
2138 // Update the value if we changed paragraphs
2139 if (cursor.par() != tmppit) {
2140 setCursor(cursor.par(), cursor.pos());
2141 value = float(cursor.y())/float(height);
2144 // Start the selection from here
2145 selection.cursor = cursor;
2148 getFont(bv()->buffer(), cursor.par(), cursor.pos())
2149 .language()->code());
2150 // and find the end of the word (insets like optional hyphens
2151 // and ligature break are part of a word)
2152 while (cursor.pos() < cursor.par()->size()
2153 && cursor.par()->isLetter(cursor.pos())
2154 && !isDeletedText(*cursor.par(), cursor.pos()))
2155 cursor.pos(cursor.pos() + 1);
2157 // Finally, we copy the word to a string and return it
2159 if (selection.cursor.pos() < cursor.pos()) {
2161 for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
2162 if (!cursor.par()->isInset(i))
2163 str += cursor.par()->getChar(i);
2166 return WordLangTuple(str, lang_code);
2170 // This one is also only for the spellchecker
2171 void LyXText::selectSelectedWord()
2173 if (the_locking_inset) {
2174 the_locking_inset->selectSelectedWord(bv());
2177 // move cursor to the beginning
2178 setCursor(selection.cursor.par(), selection.cursor.pos());
2180 // set the sel cursor
2181 selection.cursor = cursor;
2183 // now find the end of the word
2184 while (cursor.pos() < cursor.par()->size()
2185 && (cursor.par()->isLetter(cursor.pos())))
2186 cursor.pos(cursor.pos() + 1);
2188 setCursor(cursor.par(), cursor.pos());
2190 // finally set the selection
2195 // Delete from cursor up to the end of the current or next word.
2196 void LyXText::deleteWordForward()
2198 if (cursor.par()->empty())
2201 LyXCursor tmpcursor = cursor;
2202 selection.set(true); // to avoid deletion
2203 cursorRightOneWord();
2204 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2205 selection.cursor = cursor;
2209 // Great, CutSelection() gets rid of multiple spaces.
2210 cutSelection(true, false);
2215 // Delete from cursor to start of current or prior word.
2216 void LyXText::deleteWordBackward()
2218 if (cursor.par()->empty())
2221 LyXCursor tmpcursor = cursor;
2222 selection.set(true); // to avoid deletion
2223 cursorLeftOneWord();
2224 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2225 selection.cursor = cursor;
2228 cutSelection(true, false);
2233 // Kill to end of line.
2234 void LyXText::deleteLineForward()
2236 if (cursor.par()->empty())
2237 // Paragraph is empty, so we just go to the right
2240 LyXCursor tmpcursor = cursor;
2241 // We can't store the row over a regular setCursor
2242 // so we set it to 0 and reset it afterwards.
2243 selection.set(true); // to avoid deletion
2245 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
2246 selection.cursor = cursor;
2249 // What is this test for ??? (JMarc)
2250 if (!selection.set()) {
2251 deleteWordForward();
2253 cutSelection(true, false);
2259 void LyXText::changeCase(LyXText::TextCase action)
2264 if (selection.set()) {
2265 from = selection.start;
2269 ::getWord(from, to, lyx::PARTIAL_WORD, ownerParagraphs());
2270 setCursor(to.par(), to.pos() + 1);
2273 recordUndo(bv(), Undo::ATOMIC, from.par(), to.par());
2275 pos_type pos = from.pos();
2276 ParagraphList::iterator pit = from.par();
2278 while (pit != ownerParagraphs().end() &&
2279 (pos != to.pos() || pit != to.par())) {
2280 if (pos == pit->size()) {
2285 unsigned char c = pit->getChar(pos);
2286 if (!IsInsetChar(c)) {
2288 case text_lowercase:
2291 case text_capitalization:
2293 action = text_lowercase;
2295 case text_uppercase:
2301 pit->setChar(pos, c);
2302 checkParagraph(pit, pos);
2307 if (getRow(to) != getRow(from))
2312 void LyXText::Delete()
2314 // this is a very easy implementation
2316 LyXCursor old_cursor = cursor;
2317 int const old_cur_par_id = old_cursor.par()->id();
2318 int const old_cur_par_prev_id =
2319 (old_cursor.par() != ownerParagraphs().begin() ?
2320 boost::prior(old_cursor.par())->id() : -1);
2322 // just move to the right
2325 // CHECK Look at the comment here.
2326 // This check is not very good...
2327 // The cursorRightIntern calls DeleteEmptyParagrapgMechanism
2328 // and that can very well delete the par or par->previous in
2329 // old_cursor. Will a solution where we compare paragraph id's
2331 if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
2332 == old_cur_par_prev_id
2333 && cursor.par()->id() != old_cur_par_id) {
2334 // delete-empty-paragraph-mechanism has done it
2338 // if you had success make a backspace
2339 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
2340 LyXCursor tmpcursor = cursor;
2341 // to make sure undo gets the right cursor position
2342 cursor = old_cursor;
2343 recordUndo(bv(), Undo::DELETE, cursor.par());
2350 void LyXText::backspace()
2352 // Get the font that is used to calculate the baselineskip
2353 pos_type lastpos = cursor.par()->size();
2354 LyXFont rawparfont =
2355 cursor.par()->getFontSettings(bv()->buffer()->params,
2358 if (cursor.pos() == 0) {
2359 // The cursor is at the beginning of a paragraph,
2360 // so the the backspace will collapse two paragraphs into one.
2362 // but it's not allowed unless it's new
2363 if (cursor.par()->isChangeEdited(0, cursor.par()->size()))
2366 // we may paste some paragraphs
2368 // is it an empty paragraph?
2371 || (lastpos == 1 && cursor.par()->isSeparator(0)))) {
2372 // This is an empty paragraph and we delete it just by moving the cursor one step
2373 // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
2374 // of the paragraph.
2376 if (cursor.par() != ownerParagraphs().begin()) {
2377 ParagraphList::iterator tmppit = boost::prior(cursor.par());
2378 if (cursor.par()->layout() == tmppit->layout()
2379 && cursor.par()->getAlign() == tmppit->getAlign()) {
2380 // Inherit bottom DTD from the paragraph below.
2381 // (the one we are deleting)
2382 tmppit->params().lineBottom(cursor.par()->params().lineBottom());
2383 tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
2384 tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
2389 // the layout things can change the height of a row !
2390 int const tmpheight = cursorRow()->height();
2391 setHeightOfRow(cursorRow());
2392 if (cursorRow()->height() != tmpheight)
2398 if (cursor.par() != ownerParagraphs().begin()) {
2399 recordUndo(bv(), Undo::DELETE,
2400 boost::prior(cursor.par()),
2404 ParagraphList::iterator tmppit = cursor.par();
2405 RowList::iterator tmprow = cursorRow();
2407 // We used to do cursorLeftIntern() here, but it is
2408 // not a good idea since it triggers the auto-delete
2409 // mechanism. So we do a cursorLeftIntern()-lite,
2410 // without the dreaded mechanism. (JMarc)
2411 if (cursor.par() != ownerParagraphs().begin()) {
2412 // steps into the above paragraph.
2413 setCursorIntern(boost::prior(cursor.par()),
2414 boost::prior(cursor.par())->size(),
2418 // Pasting is not allowed, if the paragraphs have different
2419 // layout. I think it is a real bug of all other
2420 // word processors to allow it. It confuses the user.
2421 // Even so with a footnote paragraph and a non-footnote
2422 // paragraph. I will not allow pasting in this case,
2423 // because the user would be confused if the footnote behaves
2424 // different wether it is open or closed.
2426 // Correction: Pasting is always allowed with standard-layout
2427 LyXTextClass const & tclass =
2428 bv()->buffer()->params.getLyXTextClass();
2430 if (cursor.par() != tmppit
2431 && (cursor.par()->layout() == tmppit->layout()
2432 || tmppit->layout() == tclass.defaultLayout())
2433 && cursor.par()->getAlign() == tmppit->getAlign()) {
2434 removeParagraph(tmprow);
2436 mergeParagraph(bv()->buffer()->params, bv()->buffer()->paragraphs, cursor.par());
2438 if (!cursor.pos() || !cursor.par()->isSeparator(cursor.pos() - 1))
2439 ; //cursor.par()->insertChar(cursor.pos(), ' ');
2440 // strangely enough it seems that commenting out the line above removes
2441 // most or all of the segfaults. I will however also try to move the
2442 // two Remove... lines in front of the PasteParagraph too.
2445 cursor.pos(cursor.pos() - 1);
2449 // remove the lost paragraph
2450 // This one is not safe, since the paragraph that the tmprow and the
2451 // following rows belong to has been deleted by the PasteParagraph
2452 // above. The question is... could this be moved in front of the
2454 //RemoveParagraph(tmprow);
2455 //RemoveRow(tmprow);
2457 // This rebuilds the rows.
2458 appendParagraph(cursorRow());
2461 // the row may have changed, block, hfills etc.
2462 setCursor(cursor.par(), cursor.pos(), false);
2465 // this is the code for a normal backspace, not pasting
2467 recordUndo(bv(), Undo::DELETE, cursor.par());
2468 // We used to do cursorLeftIntern() here, but it is
2469 // not a good idea since it triggers the auto-delete
2470 // mechanism. So we do a cursorLeftIntern()-lite,
2471 // without the dreaded mechanism. (JMarc)
2472 setCursorIntern(cursor.par(), cursor.pos()- 1,
2473 false, cursor.boundary());
2475 if (cursor.par()->isInset(cursor.pos())) {
2476 // force complete redo when erasing display insets
2477 // this is a cruel method but safe..... Matthias
2478 if (cursor.par()->getInset(cursor.pos())->display() ||
2479 cursor.par()->getInset(cursor.pos())->needFullRow()) {
2480 cursor.par()->erase(cursor.pos());
2486 RowList::iterator row = cursorRow();
2487 int y = cursor.y() - row->baseline();
2489 // remember that a space at the end of a row doesnt count
2490 // when calculating the fill
2491 if (cursor.pos() < lastPos(*this, row) ||
2492 !cursor.par()->isLineSeparator(cursor.pos())) {
2493 row->fill(row->fill() + singleWidth(
2498 // some special code when deleting a newline. This is similar
2499 // to the behavior when pasting paragraphs
2500 if (cursor.pos() && cursor.par()->isNewline(cursor.pos())) {
2501 cursor.par()->erase(cursor.pos());
2502 // refresh the positions
2503 RowList::iterator tmprow = row;
2504 while (boost::next(tmprow) != rows().end() &&
2505 boost::next(tmprow)->par() == row->par()) {
2507 tmprow->pos(tmprow->pos() - 1);
2509 if (cursor.par()->isLineSeparator(cursor.pos() - 1))
2510 cursor.pos(cursor.pos() - 1);
2512 if (cursor.pos() < cursor.par()->size()
2513 && !cursor.par()->isSeparator(cursor.pos())) {
2514 cursor.par()->insertChar(cursor.pos(), ' ');
2515 setCharFont(bv()->buffer(), cursor.par(),
2516 cursor.pos(), current_font);
2517 // refresh the positions
2519 while (boost::next(tmprow) != rows().end() &&
2520 boost::next(tmprow)->par() == row->par()) {
2522 tmprow->pos(tmprow->pos() + 1);
2526 cursor.par()->erase(cursor.pos());
2528 // refresh the positions
2529 RowList::iterator tmprow = row;
2530 while (boost::next(tmprow) != rows().end() &&
2531 boost::next(tmprow)->par() == row->par()) {
2533 tmprow->pos(tmprow->pos() - 1);
2536 // delete newlines at the beginning of paragraphs
2537 while (!cursor.par()->empty() &&
2538 cursor.pos() < cursor.par()->size() &&
2539 cursor.par()->isNewline(cursor.pos()) &&
2540 cursor.pos() == cursor.par()->beginningOfBody()) {
2541 cursor.par()->erase(cursor.pos());
2542 // refresh the positions
2544 while (boost::next(tmprow) != rows().end() &&
2545 boost::next(tmprow)->par() == row->par()) {
2547 tmprow->pos(tmprow->pos() - 1);
2552 // is there a break one row above
2553 if (row != rows().begin() && boost::prior(row)->par() == row->par()) {
2554 z = rowBreakPoint(*boost::prior(row));
2555 if (z >= row->pos()) {
2558 RowList::iterator tmprow = boost::prior(row);
2560 // maybe the current row is now empty
2561 if (row->pos() >= row->par()->size()) {
2564 need_break_row = rows().end();
2566 breakAgainOneRow(row);
2567 if (boost::next(row) != rows().end() &&
2568 boost::next(row)->par() == row->par())
2569 need_break_row = boost::next(row);
2571 need_break_row = rows().end();
2574 // set the dimensions of the row above
2575 y -= tmprow->height();
2576 tmprow->fill(fill(tmprow, workWidth()));
2577 setHeightOfRow(tmprow);
2580 setCursor(cursor.par(), cursor.pos(),
2581 false, cursor.boundary());
2582 //current_font = rawtmpfont;
2583 //real_current_font = realtmpfont;
2584 // check, whether the last character's font has changed.
2586 cursor.par()->getFontSettings(bv()->buffer()->params,
2587 cursor.par()->size() - 1))
2588 redoHeightOfParagraph();
2593 // break the cursor row again
2594 if (boost::next(row) != rows().end() &&
2595 boost::next(row)->par() == row->par() &&
2596 (lastPos(*this, row) == row->par()->size() - 1 ||
2597 rowBreakPoint(*row) != lastPos(*this, row))) {
2599 // it can happen that a paragraph loses one row
2600 // without a real breakup. This is when a word
2601 // is to long to be broken. Well, I don t care this
2603 if (lastPos(*this, row) == row->par()->size() - 1)
2604 removeRow(boost::next(row));
2608 breakAgainOneRow(row);
2609 // will the cursor be in another row now?
2610 if (boost::next(row) != rows().end() &&
2611 boost::next(row)->par() == row->par() &&
2612 lastPos(*this, row) <= cursor.pos()) {
2614 breakAgainOneRow(row);
2617 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2619 if (boost::next(row) != rows().end() &&
2620 boost::next(row)->par() == row->par())
2621 need_break_row = boost::next(row);
2623 need_break_row = rows().end();
2625 // set the dimensions of the row
2626 row->fill(fill(row, workWidth()));
2627 setHeightOfRow(row);
2629 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
2633 // current_font = rawtmpfont;
2634 // real_current_font = realtmpfont;
2636 if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
2637 != cursor.boundary())
2638 setCursor(cursor.par(), cursor.pos(), false,
2639 !cursor.boundary());
2641 lastpos = cursor.par()->size();
2642 if (cursor.pos() == lastpos)
2645 // check, whether the last characters font has changed.
2647 cursor.par()->getFontSettings(bv()->buffer()->params, lastpos - 1)) {
2648 redoHeightOfParagraph();
2653 RowList::iterator LyXText::cursorRow() const
2655 return getRow(cursor.par(), cursor.pos());
2659 RowList::iterator LyXText::getRow(LyXCursor const & cur) const
2661 return getRow(cur.par(), cur.pos());
2666 LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
2669 return rowlist_.end();
2671 // find the first row of the specified paragraph
2672 RowList::iterator rit = rowlist_.begin();
2673 RowList::iterator end = rowlist_.end();
2674 while (boost::next(rit) != end && rit->par() != pit) {
2678 // now find the wanted row
2679 while (rit->pos() < pos
2680 && boost::next(rit) != end
2681 && boost::next(rit)->par() == pit
2682 && boost::next(rit)->pos() <= pos) {
2690 // returns pointer to a specified row
2692 LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
2697 return rowlist_.end();
2699 // find the first row of the specified paragraph
2700 RowList::iterator rit = rowlist_.begin();
2701 RowList::iterator end = rowlist_.end();
2702 while (boost::next(rit) != end && rit->par() != pit) {
2707 // now find the wanted row
2708 while (rit->pos() < pos
2709 && boost::next(rit) != end
2710 && boost::next(rit)->par() == pit
2711 && boost::next(rit)->pos() <= pos) {
2720 // returns pointer to some fancy row 'below' specified row
2721 RowList::iterator LyXText::cursorIRow() const
2724 return getRow(cursor.par(), cursor.pos(), y);
2728 RowList::iterator LyXText::getRowNearY(int & y) const
2730 RowList::iterator rit = anchor_row_;
2731 RowList::iterator const beg = rows().begin();
2732 RowList::iterator const end = rows().end();
2734 if (rows().empty()) {
2741 int tmpy = rit->y();
2744 while (rit != end && tmpy <= y) {
2745 tmpy += rit->height();
2750 tmpy -= rit->height();
2753 while (rit != beg && tmpy > y) {
2755 tmpy -= rit->height();
2758 if (tmpy < 0 || rit == end) {
2770 int LyXText::getDepth() const
2772 return cursor.par()->getDepth();