3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
12 * \author Jürgen Vigna
14 * Full author contact details are available in file CREDITS.
22 #include "bufferparams.h"
23 #include "BufferView.h"
26 #include "dispatchresult.h"
28 #include "funcrequest.h"
32 #include "lyxlength.h"
36 #include "lyxrow_funcs.h"
37 #include "metricsinfo.h"
38 #include "paragraph.h"
39 #include "paragraph_funcs.h"
40 #include "ParagraphParameters.h"
41 #include "rowpainter.h"
44 #include "WordLangTuple.h"
46 #include "frontends/font_metrics.h"
47 #include "frontends/LyXView.h"
49 #include "insets/insettext.h"
51 #include "support/lstrings.h"
52 #include "support/textutils.h"
55 using lyx::word_location;
57 using lyx::support::contains;
58 using lyx::support::lowercase;
59 using lyx::support::uppercase;
66 /// some space for drawing the 'nested' markers (in pixel)
67 extern int const NEST_MARGIN = 20;
68 /// margin for changebar
69 extern int const CHANGEBAR_MARGIN = 10;
71 extern int const RIGHT_MARGIN = 10;
76 unsigned int maxParagraphWidth(ParagraphList const & plist)
78 unsigned int width = 0;
79 ParagraphList::const_iterator pit = plist.begin();
80 ParagraphList::const_iterator end = plist.end();
81 for (; pit != end; ++pit)
82 width = std::max(width, pit->width);
89 BufferView * LyXText::bv()
91 BOOST_ASSERT(bv_owner != 0);
96 double LyXText::spacing(Paragraph const & par) const
98 if (par.params().spacing().isDefault())
99 return bv()->buffer()->params().spacing().getValue();
100 return par.params().spacing().getValue();
104 BufferView * LyXText::bv() const
106 BOOST_ASSERT(bv_owner != 0);
111 void LyXText::updateParPositions()
113 ParagraphList::iterator pit = paragraphs().begin();
114 ParagraphList::iterator end = paragraphs().end();
115 for (height = 0; pit != end; ++pit) {
117 height += pit->height;
122 int LyXText::textWidth() const
128 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
130 if (pos >= pit->size())
133 char const c = pit->getChar(pos);
134 return singleWidth(pit, pos, c, getFont(pit, pos));
138 int LyXText::singleWidth(ParagraphList::iterator pit,
139 pos_type pos, char c, LyXFont const & font) const
141 if (pos >= pit->size()) {
142 lyxerr << "in singleWidth(), pos: " << pos << endl;
147 // The most common case is handled first (Asger)
148 if (IsPrintable(c)) {
149 if (!font.language()->RightToLeft()) {
150 if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
151 lyxrc.font_norm_type == LyXRC::ISO_10646_1)
152 && font.language()->lang() == "arabic") {
153 if (Encodings::IsComposeChar_arabic(c))
156 c = pit->transformChar(c, pos);
157 } else if (font.language()->lang() == "hebrew" &&
158 Encodings::IsComposeChar_hebrew(c))
161 return font_metrics::width(c, font);
164 if (c == Paragraph::META_INSET)
165 return pit->getInset(pos)->width();
167 if (IsSeparatorChar(c))
169 return font_metrics::width(c, font);
173 int LyXText::leftMargin(ParagraphList::iterator pit) const
175 return leftMargin(pit, pit->size());
179 int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
181 LyXTextClass const & tclass =
182 bv()->buffer()->params().getLyXTextClass();
183 LyXLayout_ptr const & layout = pit->layout();
185 string parindent = layout->parindent;
187 int x = NEST_MARGIN + CHANGEBAR_MARGIN;
189 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
191 // This is the way LyX handles LaTeX-Environments.
192 // I have had this idea very late, so it seems to be a
193 // later added hack and this is true
194 if (pit->getDepth() == 0) {
195 if (pit->layout() == tclass.defaultLayout()) {
196 // find the previous same level paragraph
197 if (pit != paragraphs().begin()) {
198 ParagraphList::iterator newpit =
199 depthHook(pit, paragraphs(), pit->getDepth());
200 if (newpit == pit && newpit->layout()->nextnoindent)
205 // find the next level paragraph
206 ParagraphList::iterator newpar =
207 outerHook(pit, paragraphs());
209 // Make a corresponding row. Need to call leftMargin()
210 // to check whether it is a sufficent paragraph.
211 if (newpar != paragraphs().end()
212 && newpar->layout()->isEnvironment()) {
213 x = leftMargin(newpar);
216 if (newpar != paragraphs().end()
217 && pit->layout() == tclass.defaultLayout()) {
218 if (newpar->params().noindent())
221 parindent = newpar->layout()->parindent;
225 LyXFont const labelfont = getLabelFont(pit);
226 switch (layout->margintype) {
228 if (!layout->leftmargin.empty())
229 x += font_metrics::signedWidth(layout->leftmargin,
230 tclass.defaultfont());
231 if (!pit->getLabelstring().empty()) {
232 x += font_metrics::signedWidth(layout->labelindent,
234 x += font_metrics::width(pit->getLabelstring(),
236 x += font_metrics::width(layout->labelsep, labelfont);
241 x += font_metrics::signedWidth(layout->labelindent, labelfont);
242 // The width of an empty par, even with manual label, should be 0
243 if (!pit->empty() && pos >= pit->beginOfBody()) {
244 if (!pit->getLabelWidthString().empty()) {
245 x += font_metrics::width(pit->getLabelWidthString(),
247 x += font_metrics::width(layout->labelsep, labelfont);
253 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
254 / (pit->getDepth() + 4);
257 case MARGIN_FIRST_DYNAMIC:
258 if (layout->labeltype == LABEL_MANUAL) {
259 if (pos >= pit->beginOfBody()) {
260 x += font_metrics::signedWidth(layout->leftmargin,
263 x += font_metrics::signedWidth(layout->labelindent,
267 // Special case to fix problems with
269 || (layout->labeltype == LABEL_STATIC
270 && layout->latextype == LATEX_ENVIRONMENT
271 && !isFirstInSequence(pit, paragraphs()))) {
272 x += font_metrics::signedWidth(layout->leftmargin,
274 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
275 && layout->labeltype != LABEL_BIBLIO
276 && layout->labeltype !=
277 LABEL_CENTERED_TOP_ENVIRONMENT) {
278 x += font_metrics::signedWidth(layout->labelindent,
280 x += font_metrics::width(layout->labelsep, labelfont);
281 x += font_metrics::width(pit->getLabelstring(),
286 case MARGIN_RIGHT_ADDRESS_BOX: {
288 // ok, a terrible hack. The left margin depends on the widest
289 // row in this paragraph.
290 RowList::iterator rit = pit->rows.begin();
291 RowList::iterator end = pit->rows.end();
292 #warning This is wrong.
293 int minfill = textwidth_;
294 for ( ; rit != end; ++rit)
295 if (rit->fill() < minfill)
296 minfill = rit->fill();
297 x += font_metrics::signedWidth(layout->leftmargin,
298 tclass.defaultfont());
301 // also wrong, but much shorter.
307 if (!pit->params().leftIndent().zero())
308 x += pit->params().leftIndent().inPixels(textWidth());
312 if (pit->params().align() == LYX_ALIGN_LAYOUT)
313 align = layout->align;
315 align = pit->params().align();
317 // set the correct parindent
319 && (layout->labeltype == LABEL_NO_LABEL
320 || layout->labeltype == LABEL_TOP_ENVIRONMENT
321 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
322 || (layout->labeltype == LABEL_STATIC
323 && layout->latextype == LATEX_ENVIRONMENT
324 && !isFirstInSequence(pit, paragraphs())))
325 && align == LYX_ALIGN_BLOCK
326 && !pit->params().noindent()
327 // in tabulars and ert paragraphs are never indented!
329 || !pit->inInset()->owner()
330 || (pit->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE
331 && pit->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
332 && (pit->layout() != tclass.defaultLayout()
333 || bv()->buffer()->params().paragraph_separation ==
334 BufferParams::PARSEP_INDENT))
336 x += font_metrics::signedWidth(parindent, tclass.defaultfont());
343 int LyXText::rightMargin(Paragraph const & par) const
345 LyXTextClass const & tclass = bv()->buffer()->params().getLyXTextClass();
349 + font_metrics::signedWidth(tclass.rightmargin(),
350 tclass.defaultfont())
351 + font_metrics::signedWidth(par.layout()->rightmargin,
352 tclass.defaultfont())
353 * 4 / (par.getDepth() + 4);
357 int LyXText::labelEnd(ParagraphList::iterator pit) const
359 // labelEnd is only needed if the layout fills a flushleft label.
360 if (pit->layout()->margintype != MARGIN_MANUAL)
362 // return the beginning of the body
363 return leftMargin(pit);
369 // this needs special handling - only newlines count as a break point
370 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
372 pos_type const end = par.size();
375 if (par.isNewline(i))
384 void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
386 pos_type const end = pit->size();
387 pos_type const pos = row.pos();
393 // maximum pixel width of a row
394 int width = textWidth() - rightMargin(*pit); // - leftMargin(pit, row);
400 LyXLayout_ptr const & layout = pit->layout();
402 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
403 row.endpos(addressBreakPoint(pos, *pit));
407 pos_type const body_pos = pit->beginOfBody();
410 // Now we iterate through until we reach the right margin
411 // or the end of the par, then choose the possible break
414 int const left = leftMargin(pit, pos);
417 // pixel width since last breakpoint
421 // We re-use the font resolution for the entire font span when possible
422 LyXFont font = getFont(pit, pos);
423 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(pos);
425 pos_type point = end;
427 for ( ; i < end; ++i) {
428 if (pit->isNewline(i)) {
434 if (pit->isInset(i + 1) && pit->getInset(i + 1)->display()) {
439 if (pit->isInset(i) && pit->getInset(i)->display()) {
445 char const c = pit->getChar(i);
447 if (i > endPosOfFontSpan) {
448 font = getFont(pit, i);
449 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
453 int thiswidth = singleWidth(pit, i, c, font);
455 // add the auto-hfill from label end to the body
456 if (body_pos && i == body_pos) {
457 int add = font_metrics::width(layout->labelsep, getLabelFont(pit));
458 if (pit->isLineSeparator(i - 1))
459 add -= singleWidth(pit, i - 1);
461 add = std::max(add, labelEnd(pit) - x);
466 //lyxerr << "i: " << i << " x: "
467 //<< x << " width: " << width << endl;
468 chunkwidth += thiswidth;
471 // break before a character that will fall off
472 // the right of the row
474 // if no break before, break here
475 if (point == end || chunkwidth >= width - left) {
481 // exit on last registered breakpoint:
485 if (!pit->isInset(i) || pit->getInset(i)->isChar()) {
486 // some insets are line separators too
487 if (pit->isLineSeparator(i)) {
488 // register breakpoint:
495 if (i == end && x < width) {
496 // maybe found one, but the par is short enough.
500 // manual labels cannot be broken in LaTeX. But we
501 // want to make our on-screen rendering of footnotes
503 if (body_pos && point < body_pos)
510 // returns the minimum space a row needs on the screen in pixel
511 void LyXText::fill(ParagraphList::iterator pit, Row & row, int workwidth) const
513 // get the pure distance
514 pos_type const end = row.endpos();
516 string labelsep = pit->layout()->labelsep;
517 int w = leftMargin(pit, row.pos());
519 pos_type const body_pos = pit->beginOfBody();
520 pos_type i = row.pos();
523 // We re-use the font resolution for the entire span when possible
524 LyXFont font = getFont(pit, i);
525 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
526 for ( ; i < end; ++i) {
527 if (body_pos > 0 && i == body_pos) {
528 w += font_metrics::width(labelsep, getLabelFont(pit));
529 if (pit->isLineSeparator(i - 1))
530 w -= singleWidth(pit, i - 1);
531 w = max(w, labelEnd(pit));
533 char const c = pit->getChar(i);
534 if (IsPrintable(c) && i > endPosOfFontSpan) {
535 // We need to get the next font
536 font = getFont(pit, i);
537 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
539 w += singleWidth(pit, i, c, font);
543 if (body_pos > 0 && body_pos >= end) {
544 w += font_metrics::width(labelsep, getLabelFont(pit));
545 if (end > 0 && pit->isLineSeparator(end - 1))
546 w -= singleWidth(pit, end - 1);
547 w = max(w, labelEnd(pit));
550 int const fill = workwidth - w - rightMargin(*pit);
552 row.width(workwidth - fill);
556 // returns the minimum space a manual label needs on the screen in pixel
557 int LyXText::labelFill(ParagraphList::iterator pit, Row const & row) const
559 pos_type last = pit->beginOfBody();
561 BOOST_ASSERT(last > 0);
563 // -1 because a label ends with a space that is in the label
566 // a separator at this end does not count
567 if (pit->isLineSeparator(last))
571 for (pos_type i = row.pos(); i <= last; ++i)
572 w += singleWidth(pit, i);
574 string const & label = pit->params().labelWidthString();
578 return max(0, font_metrics::width(label, getLabelFont(pit)) - w);
582 LColor_color LyXText::backgroundColor() const
584 return LColor_color(LColor::color(background_color_));
588 void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
590 // get the maximum ascent and the maximum descent
591 double layoutasc = 0;
592 double layoutdesc = 0;
593 double const dh = defaultRowHeight();
595 // ok, let us initialize the maxasc and maxdesc value.
596 // Only the fontsize count. The other properties
597 // are taken from the layoutfont. Nicer on the screen :)
598 LyXLayout_ptr const & layout = pit->layout();
600 // as max get the first character of this row then it can
601 // increase but not decrease the height. Just some point to
602 // start with so we don't have to do the assignment below too
604 LyXFont font = getFont(pit, row.pos());
605 LyXFont::FONT_SIZE const tmpsize = font.size();
606 font = getLayoutFont(pit);
607 LyXFont::FONT_SIZE const size = font.size();
608 font.setSize(tmpsize);
610 LyXFont labelfont = getLabelFont(pit);
612 // these are minimum values
613 double const spacing_val = layout->spacing.getValue() * spacing(*pit);
614 //lyxerr << "spacing_val = " << spacing_val << endl;
615 int maxasc = int(font_metrics::maxAscent(font) * spacing_val);
616 int maxdesc = int(font_metrics::maxDescent(font) * spacing_val);
618 // insets may be taller
619 InsetList::iterator ii = pit->insetlist.begin();
620 InsetList::iterator iend = pit->insetlist.end();
621 for ( ; ii != iend; ++ii) {
622 if (ii->pos >= row.pos() && ii->pos < row.endpos()) {
623 maxasc = max(maxasc, ii->inset->ascent());
624 maxdesc = max(maxdesc, ii->inset->descent());
628 // Check if any custom fonts are larger (Asger)
629 // This is not completely correct, but we can live with the small,
630 // cosmetic error for now.
632 pos_type const pos_end = row.endpos();
634 LyXFont::FONT_SIZE maxsize =
635 pit->highestFontInRange(row.pos(), pos_end, size);
636 if (maxsize > font.size()) {
637 font.setSize(maxsize);
638 maxasc = max(maxasc, font_metrics::maxAscent(font));
639 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
642 // This is nicer with box insets:
646 row.ascent_of_text(maxasc);
649 if (row.pos() == 0) {
650 BufferParams const & bufparams = bv()->buffer()->params();
651 // some parksips VERY EASY IMPLEMENTATION
652 if (bv()->buffer()->params().paragraph_separation
653 == BufferParams::PARSEP_SKIP
654 && pit != paragraphs().begin()
655 && ((layout->isParagraph() && pit->getDepth() == 0)
656 || (boost::prior(pit)->layout()->isParagraph()
657 && boost::prior(pit)->getDepth() == 0)))
659 maxasc += bufparams.getDefSkip().inPixels(*bv());
662 if (pit->params().startOfAppendix())
663 maxasc += int(3 * dh);
665 // This is special code for the chapter, since the label of this
666 // layout is printed in an extra row
667 if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) {
668 labeladdon = int(font_metrics::maxHeight(labelfont)
669 * layout->spacing.getValue() * spacing(*pit));
672 // special code for the top label
673 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
674 || layout->labeltype == LABEL_BIBLIO
675 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
676 && isFirstInSequence(pit, paragraphs())
677 && !pit->getLabelstring().empty())
680 font_metrics::maxHeight(labelfont)
681 * layout->spacing.getValue()
683 + (layout->topsep + layout->labelbottomsep) * dh);
686 // Add the layout spaces, for example before and after
687 // a section, or between the items of a itemize or enumerate
690 ParagraphList::iterator prev =
691 depthHook(pit, paragraphs(), pit->getDepth());
693 && prev->layout() == layout
694 && prev->getDepth() == pit->getDepth()
695 && prev->getLabelWidthString() == pit->getLabelWidthString())
697 layoutasc = layout->itemsep * dh;
698 } else if (pit != paragraphs().begin() || row.pos() != 0) {
699 if (layout->topsep > 0)
700 layoutasc = layout->topsep * dh;
703 prev = outerHook(pit, paragraphs());
704 if (prev != paragraphs().end()) {
705 maxasc += int(prev->layout()->parsep * dh);
706 } else if (pit != paragraphs().begin()) {
707 ParagraphList::iterator prior_pit = boost::prior(pit);
708 if (prior_pit->getDepth() != 0 ||
709 prior_pit->layout() == layout) {
710 maxasc += int(layout->parsep * dh);
715 // is it a bottom line?
716 if (row.endpos() >= pit->size()) {
717 // add the layout spaces, for example before and after
718 // a section, or between the items of a itemize or enumerate
720 ParagraphList::iterator nextpit = boost::next(pit);
721 if (nextpit != paragraphs().end()) {
722 ParagraphList::iterator cpit = pit;
726 if (cpit->getDepth() > nextpit->getDepth()) {
727 usual = cpit->layout()->bottomsep * dh;
728 cpit = depthHook(cpit, paragraphs(), nextpit->getDepth());
729 if (cpit->layout() != nextpit->layout()
730 || nextpit->getLabelWidthString() != cpit->getLabelWidthString())
732 unusual = cpit->layout()->bottomsep * dh;
734 layoutdesc = max(unusual, usual);
735 } else if (cpit->getDepth() == nextpit->getDepth()) {
736 if (cpit->layout() != nextpit->layout()
737 || nextpit->getLabelWidthString() != cpit->getLabelWidthString())
738 layoutdesc = int(cpit->layout()->bottomsep * dh);
743 // incalculate the layout spaces
744 maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
745 maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
747 row.height(maxasc + maxdesc + labeladdon);
748 row.baseline(maxasc + labeladdon);
749 row.top_of_text(row.baseline() - font_metrics::maxAscent(font));
753 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
755 // allow only if at start or end, or all previous is new text
756 ParagraphList::iterator cpit = cursorPar();
757 if (cursor().pos() && cursor().pos() != cpit->size()
758 && cpit->isChangeEdited(0, cursor().pos()))
761 LyXTextClass const & tclass =
762 bv()->buffer()->params().getLyXTextClass();
763 LyXLayout_ptr const & layout = cpit->layout();
765 // this is only allowed, if the current paragraph is not empty
766 // or caption and if it has not the keepempty flag active
767 if (cpit->empty() && !cpit->allowEmpty()
768 && layout->labeltype != LABEL_SENSITIVE)
771 // a layout change may affect also the following paragraph
772 recUndo(cursor().par(), parOffset(undoSpan(cpit)) - 1);
774 // Always break behind a space
775 // It is better to erase the space (Dekel)
776 if (cursor().pos() < cpit->size() && cpit->isLineSeparator(cursor().pos()))
777 cpit->erase(cursor().pos());
779 // break the paragraph
783 keep_layout = layout->isEnvironment();
785 // we need to set this before we insert the paragraph. IMO the
786 // breakParagraph call should return a bool if it inserts the
787 // paragraph before or behind and we should react on that one
788 // but we can fix this in 1.3.0 (Jug 20020509)
789 bool const isempty = cpit->allowEmpty() && cpit->empty();
790 ::breakParagraph(bv()->buffer()->params(), paragraphs, cpit,
791 cursor().pos(), keep_layout);
794 ParagraphList::iterator next_par = boost::next(cpit);
796 // well this is the caption hack since one caption is really enough
797 if (layout->labeltype == LABEL_SENSITIVE) {
799 // set to standard-layout
800 cpit->applyLayout(tclass.defaultLayout());
802 // set to standard-layout
803 next_par->applyLayout(tclass.defaultLayout());
806 // if the cursor is at the beginning of a row without prior newline,
808 // This touches only the screen-update. Otherwise we would may have
809 // an empty row on the screen
810 RowList::iterator crit = cpit->getRow(cursor().pos());
811 if (cursor().pos() && crit->pos() == cursor().pos()
812 && !cpit->isNewline(cursor().pos() - 1))
817 while (!next_par->empty() && next_par->isNewline(0))
822 redoParagraph(next_par);
824 // This check is necessary. Otherwise the new empty paragraph will
825 // be deleted automatically. And it is more friendly for the user!
826 if (cursor().pos() || isempty)
827 setCursor(next_par, 0);
833 // convenience function
834 void LyXText::redoParagraph()
836 bv()->cursor().clearSelection();
837 redoParagraph(cursorPar());
838 setCursorIntern(cursor().par(), cursor().pos());
842 // insert a character, moves all the following breaks in the
843 // same Paragraph one to the right and make a rebreak
844 void LyXText::insertChar(char c)
846 recordUndo(Undo::INSERT, this, cursor().par(), cursor().par());
848 // When the free-spacing option is set for the current layout,
849 // disable the double-space checking
851 bool const freeSpacing = cursorPar()->layout()->free_spacing ||
852 cursorPar()->isFreeSpacing();
854 if (lyxrc.auto_number) {
855 static string const number_operators = "+-/*";
856 static string const number_unary_operators = "+-";
857 static string const number_seperators = ".,:";
859 if (current_font.number() == LyXFont::ON) {
860 if (!IsDigit(c) && !contains(number_operators, c) &&
861 !(contains(number_seperators, c) &&
862 cursor().pos() >= 1 &&
863 cursor().pos() < cursorPar()->size() &&
864 getFont(cursorPar(), cursor().pos()).number() == LyXFont::ON &&
865 getFont(cursorPar(), cursor().pos() - 1).number() == LyXFont::ON)
867 number(); // Set current_font.number to OFF
868 } else if (IsDigit(c) &&
869 real_current_font.isVisibleRightToLeft()) {
870 number(); // Set current_font.number to ON
872 if (cursor().pos() > 0) {
873 char const c = cursorPar()->getChar(cursor().pos() - 1);
874 if (contains(number_unary_operators, c) &&
875 (cursor().pos() == 1 ||
876 cursorPar()->isSeparator(cursor().pos() - 2) ||
877 cursorPar()->isNewline(cursor().pos() - 2))
883 } else if (contains(number_seperators, c) &&
884 cursor().pos() >= 2 &&
887 cursor().pos() - 2).number() == LyXFont::ON) {
897 // First check, if there will be two blanks together or a blank at
898 // the beginning of a paragraph.
899 // I decided to handle blanks like normal characters, the main
900 // difference are the special checks when calculating the row.fill
901 // (blank does not count at the end of a row) and the check here
903 // The bug is triggered when we type in a description environment:
904 // The current_font is not changed when we go from label to main text
905 // and it should (along with realtmpfont) when we type the space.
906 // CHECK There is a bug here! (Asger)
908 // store the current font. This is because of the use of cursor
909 // movements. The moving cursor would refresh the current font
910 LyXFont realtmpfont = real_current_font;
911 LyXFont rawtmpfont = current_font;
913 if (!freeSpacing && IsLineSeparatorChar(c)) {
914 if ((cursor().pos() > 0
915 && cursorPar()->isLineSeparator(cursor().pos() - 1))
916 || (cursor().pos() > 0
917 && cursorPar()->isNewline(cursor().pos() - 1))
918 || (cursor().pos() == 0)) {
919 static bool sent_space_message = false;
920 if (!sent_space_message) {
921 if (cursor().pos() == 0)
922 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
924 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
925 sent_space_message = true;
932 // Here case LyXText::InsertInset already inserted the character
933 if (c != Paragraph::META_INSET)
934 cursorPar()->insertChar(cursor().pos(), c);
936 setCharFont(cursorPar(), cursor().pos(), rawtmpfont);
938 current_font = rawtmpfont;
939 real_current_font = realtmpfont;
940 redoParagraph(cursorPar());
941 setCursor(cursor().par(), cursor().pos() + 1, false, cursor().boundary());
947 void LyXText::charInserted()
949 // Here we call finishUndo for every 20 characters inserted.
950 // This is from my experience how emacs does it. (Lgb)
951 static unsigned int counter;
961 void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
963 double w = row.fill();
964 double fill_hfill = 0;
965 double fill_label_hfill = 0;
966 double fill_separator = 0;
970 pit->isRightToLeftPar(bv()->buffer()->params());
972 x = rightMargin(*pit);
974 x = leftMargin(pit, row.pos());
976 // is there a manual margin with a manual label
977 LyXLayout_ptr const & layout = pit->layout();
979 if (layout->margintype == MARGIN_MANUAL
980 && layout->labeltype == LABEL_MANUAL) {
981 /// We might have real hfills in the label part
982 int nlh = numberOfLabelHfills(*pit, row);
984 // A manual label par (e.g. List) has an auto-hfill
985 // between the label text and the body of the
987 // But we don't want to do this auto hfill if the par
992 if (nlh && !pit->getLabelWidthString().empty())
993 fill_label_hfill = labelFill(pit, row) / double(nlh);
996 // are there any hfills in the row?
997 int const nh = numberOfHfills(*pit, row);
1001 fill_hfill = w / nh;
1002 // we don't have to look at the alignment if it is ALIGN_LEFT and
1003 // if the row is already larger then the permitted width as then
1004 // we force the LEFT_ALIGN'edness!
1005 } else if (int(row.width()) < textWidth()) {
1006 // is it block, flushleft or flushright?
1007 // set x how you need it
1009 if (pit->params().align() == LYX_ALIGN_LAYOUT)
1010 align = layout->align;
1012 align = pit->params().align();
1014 // Display-style insets should always be on a centred row
1015 // The test on pit->size() is to catch zero-size pars, which
1016 // would trigger the assert in Paragraph::getInset().
1017 //inset = pit->size() ? pit->getInset(row.pos()) : 0;
1019 && pit->isInset(row.pos())
1020 && pit->getInset(row.pos())->display())
1022 align = LYX_ALIGN_CENTER;
1026 case LYX_ALIGN_BLOCK: {
1027 int const ns = numberOfSeparators(*pit, row);
1028 bool disp_inset = false;
1029 if (row.endpos() < pit->size()) {
1030 InsetOld * in = pit->getInset(row.endpos());
1032 disp_inset = in->display();
1034 // If we have separators, this is not the last row of a
1035 // par, does not end in newline, and is not row above a
1036 // display inset... then stretch it
1038 && row.endpos() < pit->size()
1039 && !pit->isNewline(row.endpos() - 1)
1042 fill_separator = w / ns;
1043 } else if (is_rtl) {
1048 case LYX_ALIGN_RIGHT:
1051 case LYX_ALIGN_CENTER:
1057 bidi.computeTables(*pit, *bv()->buffer(), row);
1059 pos_type body_pos = pit->beginOfBody();
1060 pos_type end = row.endpos();
1063 && (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
1065 x += font_metrics::width(layout->labelsep, getLabelFont(pit));
1066 if (body_pos <= end)
1067 x += fill_label_hfill;
1071 row.fill_hfill(fill_hfill);
1072 row.fill_label_hfill(fill_label_hfill);
1073 row.fill_separator(fill_separator);
1078 // the cursor set functions have a special mechanism. When they
1079 // realize, that you left an empty paragraph, they will delete it.
1081 void LyXText::cursorRightOneWord()
1083 cursorRightOneWord(cursor());
1084 setCursor(cursorPar(), cursor().pos());
1088 // Skip initial whitespace at end of word and move cursor to *start*
1089 // of prior word, not to end of next prior word.
1090 void LyXText::cursorLeftOneWord()
1092 CursorSlice tmpcursor = cursor();
1093 cursorLeftOneWord(tmpcursor);
1094 setCursor(getPar(tmpcursor), tmpcursor.pos());
1098 void LyXText::selectWord(word_location loc)
1100 CursorSlice from = cursor();
1101 CursorSlice to = cursor();
1102 getWord(from, to, loc);
1103 if (cursor() != from)
1104 setCursor(from.par(), from.pos());
1107 bv()->cursor().resetAnchor();
1108 setCursor(to.par(), to.pos());
1109 bv()->cursor().setSelection();
1113 // Select the word currently under the cursor when no
1114 // selection is currently set
1115 bool LyXText::selectWordWhenUnderCursor(word_location loc)
1117 if (bv()->cursor().selection())
1120 return bv()->cursor().selection();
1124 void LyXText::acceptChange()
1126 LCursor & cur = bv()->cursor();
1127 if (!cur.selection() && cursorPar()->size())
1130 if (cur.selStart().par() == cur.par()) {
1131 CursorSlice const & startc = cur.selStart();
1132 CursorSlice const & endc = cur.selEnd();
1133 recordUndo(Undo::INSERT, this, startc.par());
1134 getPar(startc)->acceptChange(startc.pos(), endc.pos());
1136 cur.clearSelection();
1137 redoParagraph(getPar(startc));
1138 setCursorIntern(startc.par(), 0);
1140 #warning handle multi par selection
1144 void LyXText::rejectChange()
1146 LCursor & cur = bv()->cursor();
1147 if (!cur.selection() && cursorPar()->size())
1150 if (cur.selStart().par() == cur.selEnd().par()) {
1151 CursorSlice const & startc = cur.selStart();
1152 CursorSlice const & endc = cur.selEnd();
1153 recordUndo(Undo::INSERT, this, startc.par());
1154 getPar(startc)->rejectChange(startc.pos(), endc.pos());
1156 cur.clearSelection();
1157 redoParagraph(getPar(startc));
1158 setCursorIntern(startc.par(), 0);
1160 #warning handle multi par selection
1164 // Delete from cursor up to the end of the current or next word.
1165 void LyXText::deleteWordForward()
1167 LCursor & cur = bv()->cursor();
1168 if (cursorPar()->empty())
1171 CursorSlice tmpcursor = cursor();
1172 cur.selection() = true; // to avoid deletion
1173 cursorRightOneWord();
1174 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
1176 cursor() = tmpcursor;
1178 cutSelection(true, false);
1183 // Delete from cursor to start of current or prior word.
1184 void LyXText::deleteWordBackward()
1186 LCursor & cur = bv()->cursor();
1187 if (cursorPar()->empty())
1190 CursorSlice tmpcursor = cursor();
1191 cur.selection() = true; // to avoid deletion
1192 cursorLeftOneWord();
1193 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
1195 cursor() = tmpcursor;
1197 cutSelection(true, false);
1202 // Kill to end of line.
1203 void LyXText::deleteLineForward()
1205 LCursor & cur = bv()->cursor();
1206 if (cursorPar()->empty()) {
1207 // Paragraph is empty, so we just go to the right
1210 CursorSlice tmpcursor = cursor();
1211 cur.selection() = true; // to avoid deletion
1213 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
1215 cursor() = tmpcursor;
1217 // What is this test for ??? (JMarc)
1218 if (!cur.selection())
1219 deleteWordForward();
1221 cutSelection(true, false);
1226 void LyXText::changeCase(LyXText::TextCase action)
1228 LCursor & cur = bv()->cursor();
1232 if (cur.selection()) {
1233 from = cur.selStart();
1237 getWord(from, to, lyx::PARTIAL_WORD);
1238 setCursor(to.par(), to.pos() + 1);
1241 recordUndo(Undo::ATOMIC, this, from.par(), to.par());
1243 pos_type pos = from.pos();
1244 int par = from.par();
1246 while (par != int(paragraphs().size()) &&
1247 (pos != to.pos() || par != to.par())) {
1248 ParagraphList::iterator pit = getPar(par);
1249 if (pos == pit->size()) {
1254 unsigned char c = pit->getChar(pos);
1255 if (c != Paragraph::META_INSET) {
1257 case text_lowercase:
1260 case text_capitalization:
1262 action = text_lowercase;
1264 case text_uppercase:
1270 pit->setChar(pos, c);
1276 void LyXText::Delete()
1278 // this is a very easy implementation
1279 CursorSlice old_cursor = cursor();
1281 // just move to the right
1284 // if you had success make a backspace
1285 if (old_cursor.par() != cursor().par() || old_cursor.pos() !=
1287 recordUndo(Undo::DELETE, this, old_cursor.par());
1293 void LyXText::backspace()
1295 // Get the font that is used to calculate the baselineskip
1296 ParagraphList::iterator pit = cursorPar();
1297 pos_type lastpos = pit->size();
1299 if (cursor().pos() == 0) {
1300 // The cursor is at the beginning of a paragraph, so
1301 // the the backspace will collapse two paragraphs into
1304 // but it's not allowed unless it's new
1305 if (pit->isChangeEdited(0, pit->size()))
1308 // we may paste some paragraphs
1310 // is it an empty paragraph?
1311 if (lastpos == 0 || (lastpos == 1 && pit->isSeparator(0))) {
1312 // This is an empty paragraph and we delete it just
1313 // by moving the cursor one step
1314 // left and let the DeleteEmptyParagraphMechanism
1315 // handle the actual deletion of the paragraph.
1317 if (cursor().par()) {
1319 // the layout things can change the height of a row !
1325 if (cursor().par() != 0)
1326 recordUndo(Undo::DELETE, this, cursor().par() - 1, cursor().par());
1328 ParagraphList::iterator tmppit = cursorPar();
1329 // We used to do cursorLeftIntern() here, but it is
1330 // not a good idea since it triggers the auto-delete
1331 // mechanism. So we do a cursorLeftIntern()-lite,
1332 // without the dreaded mechanism. (JMarc)
1333 if (cursor().par() != 0) {
1334 // steps into the above paragraph.
1335 setCursorIntern(cursor().par() - 1,
1336 getPar(cursor().par() - 1)->size(),
1340 // Pasting is not allowed, if the paragraphs have different
1341 // layout. I think it is a real bug of all other
1342 // word processors to allow it. It confuses the user.
1343 // Correction: Pasting is always allowed with standard-layout
1344 Buffer & buf = *bv()->buffer();
1345 BufferParams const & bufparams = buf.params();
1346 LyXTextClass const & tclass = bufparams.getLyXTextClass();
1347 ParagraphList::iterator const cpit = cursorPar();
1350 && (cpit->layout() == tmppit->layout()
1351 || tmppit->layout() == tclass.defaultLayout())
1352 && cpit->getAlign() == tmppit->getAlign()) {
1353 mergeParagraph(bufparams, buf.paragraphs(), cpit);
1355 if (cursor().pos() && cpit->isSeparator(cursor().pos() - 1))
1356 cursor().pos(cursor().pos() - 1);
1358 // the counters may have changed
1360 setCursor(cursor().par(), cursor().pos(), false);
1363 // this is the code for a normal backspace, not pasting
1365 recordUndo(Undo::DELETE, this, cursor().par());
1366 // We used to do cursorLeftIntern() here, but it is
1367 // not a good idea since it triggers the auto-delete
1368 // mechanism. So we do a cursorLeftIntern()-lite,
1369 // without the dreaded mechanism. (JMarc)
1370 setCursorIntern(cursor().par(), cursor().pos() - 1,
1371 false, cursor().boundary());
1372 cursorPar()->erase(cursor().pos());
1375 lastpos = cursorPar()->size();
1376 if (cursor().pos() == lastpos)
1380 setCursor(cursor().par(), cursor().pos(), false, cursor().boundary());
1384 ParagraphList::iterator LyXText::cursorPar() const
1386 return getPar(cursor().par());
1390 RowList::iterator LyXText::cursorRow() const
1392 return cursorPar()->getRow(cursor().pos());
1396 ParagraphList::iterator LyXText::getPar(CursorSlice const & cur) const
1398 return getPar(cur.par());
1402 ParagraphList::iterator LyXText::getPar(int par) const
1404 BOOST_ASSERT(par >= 0);
1405 BOOST_ASSERT(par < int(paragraphs().size()));
1406 ParagraphList::iterator pit = paragraphs().begin();
1407 std::advance(pit, par);
1413 LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const
1415 //lyxerr << "getRowNearY: y " << y << endl;
1417 ParagraphList::iterator const
1418 pend = boost::prior(paragraphs().end());
1419 pit = paragraphs().begin();
1420 while (int(pit->y + pit->height) < y && pit != pend)
1423 RowList::iterator rit = pit->rows.end();
1424 RowList::iterator const rbegin = pit->rows.begin();
1427 } while (rit != rbegin && int(pit->y + rit->y_offset()) > y);
1431 pit = boost::prior(paragraphs().end());
1433 RowList::iterator rit = lastRow();
1434 RowList::iterator rbegin = firstRow();
1436 while (rit != rbegin && int(pit->y + rit->y_offset()) > y)
1437 previousRow(pit, rit);
1444 int LyXText::getDepth() const
1446 return cursorPar()->getDepth();
1450 RowList::iterator LyXText::firstRow() const
1452 return paragraphs().front().rows.begin();
1456 ParagraphList::iterator LyXText::firstPar() const
1458 return paragraphs().begin();
1462 RowList::iterator LyXText::lastRow() const
1464 return boost::prior(endRow());
1468 ParagraphList::iterator LyXText::lastPar() const
1470 return boost::prior(endPar());
1474 RowList::iterator LyXText::endRow() const
1476 return paragraphs().back().rows.end();
1480 ParagraphList::iterator LyXText::endPar() const
1482 return paragraphs().end();
1486 void LyXText::nextRow(ParagraphList::iterator & pit,
1487 RowList::iterator & rit) const
1490 if (rit == pit->rows.end()) {
1492 if (pit == paragraphs().end())
1495 rit = pit->rows.begin();
1500 void LyXText::previousRow(ParagraphList::iterator & pit,
1501 RowList::iterator & rit) const
1503 if (rit != pit->rows.begin())
1506 BOOST_ASSERT(pit != paragraphs().begin());
1508 rit = boost::prior(pit->rows.end());
1513 string LyXText::selectionAsString(Buffer const & buffer, bool label) const
1515 LCursor & cur = bv()->cursor();
1516 if (!cur.selection())
1519 // should be const ...
1520 ParagraphList::iterator startpit = getPar(cur.selStart());
1521 ParagraphList::iterator endpit = getPar(cur.selEnd());
1522 size_t const startpos = cur.selStart().pos();
1523 size_t const endpos = cur.selEnd().pos();
1525 if (startpit == endpit)
1526 return startpit->asString(buffer, startpos, endpos, label);
1528 // First paragraph in selection
1530 startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
1532 // The paragraphs in between (if any)
1533 ParagraphList::iterator pit = startpit;
1534 for (++pit; pit != endpit; ++pit)
1535 result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
1537 // Last paragraph in selection
1538 result += endpit->asString(buffer, 0, endpos, label);
1544 int LyXText::parOffset(ParagraphList::iterator pit) const
1546 return std::distance(paragraphs().begin(), pit);
1550 void LyXText::redoParagraphInternal(ParagraphList::iterator pit)
1552 // remove rows of paragraph, keep track of height changes
1553 height -= pit->height;
1561 InsetList::iterator ii = pit->insetlist.begin();
1562 InsetList::iterator iend = pit->insetlist.end();
1563 for (; ii != iend; ++ii) {
1565 int const w = textWidth() - leftMargin(pit) - rightMargin(*pit);
1566 MetricsInfo mi(bv(), getFont(pit, ii->pos), w);
1567 ii->inset->metrics(mi, dim);
1570 // rebreak the paragraph
1571 pit->setBeginOfBody();
1575 rowBreakPoint(pit, row);
1577 fill(pit, row, textwidth_);
1578 prepareToPrint(pit, row);
1579 setHeightOfRow(pit, row);
1580 row.y_offset(pit->height);
1581 pit->rows.push_back(row);
1582 pit->width = std::max(pit->width, row.width());
1583 pit->height += row.height();
1584 } while (z < pit->size());
1586 height += pit->height;
1587 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
1591 void LyXText::redoParagraphs(ParagraphList::iterator pit,
1592 ParagraphList::iterator end)
1594 for ( ; pit != end; ++pit)
1595 redoParagraphInternal(pit);
1596 updateParPositions();
1600 void LyXText::redoParagraph(ParagraphList::iterator pit)
1602 redoParagraphInternal(pit);
1603 updateParPositions();
1607 void LyXText::fullRebreak()
1609 redoParagraphs(paragraphs().begin(), paragraphs().end());
1610 bv()->cursor().resetAnchor();
1614 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
1616 //BOOST_ASSERT(mi.base.textwidth);
1617 if (mi.base.textwidth)
1618 textwidth_ = mi.base.textwidth;
1619 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
1620 // << " textWidth: " << textWidth() << "\nfont: " << mi.base.font << endl;
1622 // Rebuild row cache. This recomputes height as well.
1623 redoParagraphs(paragraphs().begin(), paragraphs().end());
1625 width = maxParagraphWidth(paragraphs());
1628 dim.asc = firstRow()->ascent_of_text();
1629 dim.des = height - dim.asc;
1634 // only used for inset right now. should also be used for main text
1635 void LyXText::draw(PainterInfo & pi, int x, int y) const
1639 paintTextInset(*this, pi, x, y);
1643 bool LyXText::isLastRow(ParagraphList::iterator pit, Row const & row) const
1645 return row.endpos() >= pit->size()
1646 && boost::next(pit) == paragraphs().end();
1650 bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const
1652 return row.pos() == 0 && pit == paragraphs().begin();
1656 void LyXText::cursorLeftOneWord(CursorSlice & cur)
1658 // treat HFills, floats and Insets as words
1660 ParagraphList::iterator pit = cursorPar();
1661 size_t pos = cur.pos();
1664 (pit->isSeparator(pos - 1) ||
1665 pit->isKomma(pos - 1) ||
1666 pit->isNewline(pos - 1)) &&
1667 !(pit->isHfill(pos - 1) ||
1668 pit->isInset(pos - 1)))
1672 (pit->isInset(pos - 1) ||
1673 pit->isHfill(pos - 1))) {
1676 if (pit != paragraphs().begin()) {
1680 } else { // Here, cur != 0
1681 while (pos > 0 && pit->isWord(pos - 1))
1685 cur.par(parOffset(pit));
1690 void LyXText::cursorRightOneWord(CursorSlice & cur)
1692 // treat floats, HFills and Insets as words
1693 ParagraphList::iterator pit = cursorPar();
1694 pos_type pos = cur.pos();
1696 if (pos == pit->size() &&
1697 boost::next(pit) != paragraphs().end()) {
1701 // Skip through initial nonword stuff.
1702 while (pos < pit->size() && !pit->isWord(pos)) {
1705 // Advance through word.
1706 while (pos < pit->size() && pit->isWord(pos)) {
1711 cur.par(parOffset(pit));
1716 void LyXText::getWord(CursorSlice & from, CursorSlice & to, word_location const loc)
1718 ParagraphList::iterator from_par = getPar(from);
1720 case lyx::WHOLE_WORD_STRICT:
1721 if (from.pos() == 0 || from.pos() == from_par->size()
1722 || from_par->isSeparator(from.pos())
1723 || from_par->isKomma(from.pos())
1724 || from_par->isNewline(from.pos())
1725 || from_par->isSeparator(from.pos() - 1)
1726 || from_par->isKomma(from.pos() - 1)
1727 || from_par->isNewline(from.pos() - 1)) {
1731 // no break here, we go to the next
1733 case lyx::WHOLE_WORD:
1734 // Move cursor to the beginning, when not already there.
1735 if (from.pos() && !from_par->isSeparator(from.pos() - 1)
1736 && !(from_par->isKomma(from.pos() - 1)
1737 || from_par->isNewline(from.pos() - 1)))
1738 cursorLeftOneWord(from);
1740 case lyx::PREVIOUS_WORD:
1741 // always move the cursor to the beginning of previous word
1742 cursorLeftOneWord(from);
1744 case lyx::NEXT_WORD:
1745 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
1748 case lyx::PARTIAL_WORD:
1752 ParagraphList::iterator to_par = getPar(to);
1753 while (to.pos() < to_par->size()
1754 && !to_par->isSeparator(to.pos())
1755 && !to_par->isKomma(to.pos())
1756 && !to_par->isNewline(to.pos())
1757 && !to_par->isHfill(to.pos())
1758 && !to_par->isInset(to.pos()))
1760 to.pos(to.pos() + 1);
1765 void LyXText::write(Buffer const & buf, std::ostream & os) const
1767 ParagraphList::const_iterator pit = paragraphs().begin();
1768 ParagraphList::const_iterator end = paragraphs().end();
1769 Paragraph::depth_type dth = 0;
1770 for (; pit != end; ++pit)
1771 pit->write(buf, os, buf.params(), dth);
1775 bool LyXText::read(Buffer const & buf, LyXLex & lex)
1777 static Change current_change;
1779 bool the_end_read = false;
1780 ParagraphList::iterator pit = paragraphs().begin();
1781 Paragraph::depth_type depth = 0;
1783 while (lex.isOK()) {
1785 string token = lex.getString();
1792 if (token == "\\end_inset") {
1793 the_end_read = true;
1797 if (token == "\\end_document") {
1798 lex.printError("\\end_document read in inset! Error in document!");
1804 if (token == "\\end_document") {
1805 the_end_read = true;
1814 if (token == "\\begin_layout") {
1815 lex.pushToken(token);
1818 par.params().depth(depth);
1819 if (buf.params().tracking_changes)
1821 LyXFont f(LyXFont::ALL_INHERIT, buf.params().language);
1825 if (pit != paragraphs().end())
1828 pit = paragraphs().insert(pit, par);
1830 // FIXME: goddamn InsetTabular makes us pass a Buffer
1832 ::readParagraph(buf, *pit, lex);
1834 } else if (token == "\\begin_deeper") {
1836 } else if (token == "\\end_deeper") {
1838 lex.printError("\\end_deeper: " "depth is already null");
1847 return the_end_read;
1851 int LyXText::ascent() const
1853 return firstRow()->ascent_of_text();
1857 int LyXText::descent() const
1859 return height - firstRow()->ascent_of_text();
1863 int LyXText::cursorX() const
1865 return cursorX(cursor());
1869 int LyXText::cursorY() const
1871 return cursorY(cursor());
1875 int LyXText::cursorX(CursorSlice const & cur) const
1877 ParagraphList::iterator pit = getPar(cur);
1878 if (pit->rows.empty())
1880 Row const & row = *pit->getRow(cur.pos());
1881 pos_type pos = cur.pos();
1882 pos_type cursor_vpos = 0;
1884 double fill_separator = row.fill_separator();
1885 double fill_hfill = row.fill_hfill();
1886 double fill_label_hfill = row.fill_label_hfill();
1887 pos_type const row_pos = row.pos();
1888 pos_type const end = row.endpos();
1891 cursor_vpos = row_pos;
1892 else if (pos >= end)
1893 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
1895 else if (pos > row_pos && pos >= end)
1896 // Place cursor after char at (logical) position pos - 1
1897 cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
1898 ? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
1900 // Place cursor before char at (logical) position pos
1901 cursor_vpos = (bidi.level(pos) % 2 == 0)
1902 ? bidi.log2vis(pos) : bidi.log2vis(pos) + 1;
1904 pos_type body_pos = pit->beginOfBody();
1906 (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
1909 for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
1910 pos_type pos = bidi.vis2log(vpos);
1911 if (body_pos > 0 && pos == body_pos - 1) {
1912 x += fill_label_hfill
1913 + font_metrics::width(pit->layout()->labelsep,
1915 if (pit->isLineSeparator(body_pos - 1))
1916 x -= singleWidth(pit, body_pos - 1);
1919 if (hfillExpansion(*pit, row, pos)) {
1920 x += singleWidth(pit, pos);
1921 if (pos >= body_pos)
1924 x += fill_label_hfill;
1925 } else if (pit->isSeparator(pos)) {
1926 x += singleWidth(pit, pos);
1927 if (pos >= body_pos)
1928 x += fill_separator;
1930 x += singleWidth(pit, pos);
1936 int LyXText::cursorY(CursorSlice const & cur) const
1938 Paragraph & par = *getPar(cur);
1939 Row & row = *par.getRow(cur.pos());
1940 return par.y + row.y_offset() + row.baseline();
1944 CursorSlice & LyXText::cursor()
1946 return bv()->cursor().cursor_.back();
1950 CursorSlice const & LyXText::cursor() const
1952 return bv()->cursor().cursor_.back();
1956 CursorSlice & LyXText::anchor()
1958 return bv()->cursor().anchor_.back();
1962 CursorSlice const & LyXText::anchor() const
1964 return bv()->cursor().anchor_.back();