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.
23 #include "buffer_funcs.h"
24 #include "bufferparams.h"
25 #include "BufferView.h"
27 #include "pariterator.h"
28 #include "coordcache.h"
29 #include "CutAndPaste.h"
31 #include "dispatchresult.h"
33 #include "errorlist.h"
34 #include "funcrequest.h"
36 #include "FontIterator.h"
40 #include "lyxlength.h"
44 #include "lyxrow_funcs.h"
45 #include "metricsinfo.h"
46 #include "paragraph.h"
47 #include "paragraph_funcs.h"
48 #include "ParagraphParameters.h"
49 #include "rowpainter.h"
52 #include "WordLangTuple.h"
54 #include "frontends/font_metrics.h"
55 #include "frontends/Painter.h"
57 #include "insets/insettext.h"
58 #include "insets/insetbibitem.h"
59 #include "insets/insethfill.h"
60 #include "insets/insetlatexaccent.h"
61 #include "insets/insetline.h"
62 #include "insets/insetnewline.h"
63 #include "insets/insetpagebreak.h"
64 #include "insets/insetoptarg.h"
65 #include "insets/insetspace.h"
66 #include "insets/insetspecialchar.h"
67 #include "insets/insettabular.h"
69 #include "support/lstrings.h"
70 #include "support/textutils.h"
71 #include "support/convert.h"
73 #include <boost/current_function.hpp>
81 using lyx::word_location;
83 using lyx::support::bformat;
84 using lyx::support::contains;
85 using lyx::support::lowercase;
86 using lyx::support::split;
87 using lyx::support::uppercase;
89 using lyx::cap::cutSelection;
90 using lyx::cap::pasteParagraphList;
103 int numberOfSeparators(Paragraph const & par, Row const & row)
105 pos_type const first = max(row.pos(), par.beginOfBody());
106 pos_type const last = row.endpos() - 1;
108 for (pos_type p = first; p < last; ++p) {
109 if (par.isSeparator(p))
116 int numberOfLabelHfills(Paragraph const & par, Row const & row)
118 pos_type last = row.endpos() - 1;
119 pos_type first = row.pos();
121 // hfill *DO* count at the beginning of paragraphs!
123 while (first < last && par.isHfill(first))
127 last = min(last, par.beginOfBody());
129 for (pos_type p = first; p < last; ++p) {
137 int numberOfHfills(Paragraph const & par, Row const & row)
139 pos_type const last = row.endpos();
140 pos_type first = row.pos();
142 // hfill *DO* count at the beginning of paragraphs!
144 while (first < last && par.isHfill(first))
148 first = max(first, par.beginOfBody());
151 for (pos_type p = first; p < last; ++p) {
159 void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
160 string const & token, LyXFont & font, Change & change, ErrorList & errorList)
162 BufferParams const & bp = buf.params();
164 if (token[0] != '\\') {
166 string::const_iterator cit = token.begin();
167 for (; cit != token.end(); ++cit)
168 par.insertChar(par.size(), (*cit), font, change);
170 lyx::docstring dstr = lex.getDocString();
171 lyx::docstring::const_iterator cit = dstr.begin();
172 lyx::docstring::const_iterator cend = dstr.end();
173 for (; cit != cend; ++cit)
174 par.insertChar(par.size(), *cit, font, change);
176 } else if (token == "\\begin_layout") {
178 string layoutname = lex.getString();
180 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
183 LyXTextClass const & tclass = bp.getLyXTextClass();
185 if (layoutname.empty()) {
186 layoutname = tclass.defaultLayoutName();
189 bool hasLayout = tclass.hasLayout(layoutname);
192 errorList.push_back(ErrorItem(_("Unknown layout"),
193 bformat(_("Layout '%1$s' does not exist in textclass '%2$s'\nTrying to use the default instead.\n"),
194 lyx::from_utf8(layoutname), lyx::from_utf8(tclass.name())), par.id(), 0, par.size()));
195 layoutname = tclass.defaultLayoutName();
198 par.layout(bp.getLyXTextClass()[layoutname]);
200 // Test whether the layout is obsolete.
201 LyXLayout_ptr const & layout = par.layout();
202 if (!layout->obsoleted_by().empty())
203 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
205 par.params().read(lex);
207 } else if (token == "\\end_layout") {
208 lyxerr << BOOST_CURRENT_FUNCTION
209 << ": Solitary \\end_layout in line "
210 << lex.getLineNo() << "\n"
211 << "Missing \\begin_layout?.\n";
212 } else if (token == "\\end_inset") {
213 lyxerr << BOOST_CURRENT_FUNCTION
214 << ": Solitary \\end_inset in line "
215 << lex.getLineNo() << "\n"
216 << "Missing \\begin_inset?.\n";
217 } else if (token == "\\begin_inset") {
218 InsetBase * inset = readInset(lex, buf);
220 par.insertInset(par.size(), inset, font, change);
223 docstring line = lyx::from_utf8(lex.getString());
224 errorList.push_back(ErrorItem(_("Unknown Inset"), line,
225 par.id(), 0, par.size()));
227 } else if (token == "\\family") {
229 font.setLyXFamily(lex.getString());
230 } else if (token == "\\series") {
232 font.setLyXSeries(lex.getString());
233 } else if (token == "\\shape") {
235 font.setLyXShape(lex.getString());
236 } else if (token == "\\size") {
238 font.setLyXSize(lex.getString());
239 } else if (token == "\\lang") {
241 string const tok = lex.getString();
242 Language const * lang = languages.getLanguage(tok);
244 font.setLanguage(lang);
246 font.setLanguage(bp.language);
247 lex.printError("Unknown language `$$Token'");
249 } else if (token == "\\numeric") {
251 font.setNumber(font.setLyXMisc(lex.getString()));
252 } else if (token == "\\emph") {
254 font.setEmph(font.setLyXMisc(lex.getString()));
255 } else if (token == "\\bar") {
257 string const tok = lex.getString();
260 font.setUnderbar(LyXFont::ON);
261 else if (tok == "no")
262 font.setUnderbar(LyXFont::OFF);
263 else if (tok == "default")
264 font.setUnderbar(LyXFont::INHERIT);
266 lex.printError("Unknown bar font flag "
268 } else if (token == "\\noun") {
270 font.setNoun(font.setLyXMisc(lex.getString()));
271 } else if (token == "\\color") {
273 font.setLyXColor(lex.getString());
274 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
276 // Insets don't make sense in a free-spacing context! ---Kayvan
277 if (par.isFreeSpacing()) {
278 if (token == "\\InsetSpace")
279 par.insertChar(par.size(), ' ', font, change);
280 else if (lex.isOK()) {
282 string const next_token = lex.getString();
283 if (next_token == "\\-")
284 par.insertChar(par.size(), '-', font, change);
286 lex.printError("Token `$$Token' "
288 "paragraph layout!");
292 auto_ptr<InsetBase> inset;
293 if (token == "\\SpecialChar" )
294 inset.reset(new InsetSpecialChar);
296 inset.reset(new InsetSpace);
297 inset->read(buf, lex);
298 par.insertInset(par.size(), inset.release(),
301 } else if (token == "\\i") {
302 auto_ptr<InsetBase> inset(new InsetLatexAccent);
303 inset->read(buf, lex);
304 par.insertInset(par.size(), inset.release(), font, change);
305 } else if (token == "\\backslash") {
306 par.insertChar(par.size(), '\\', font, change);
307 } else if (token == "\\newline") {
308 auto_ptr<InsetBase> inset(new InsetNewline);
309 inset->read(buf, lex);
310 par.insertInset(par.size(), inset.release(), font, change);
311 } else if (token == "\\LyXTable") {
312 auto_ptr<InsetBase> inset(new InsetTabular(buf));
313 inset->read(buf, lex);
314 par.insertInset(par.size(), inset.release(), font, change);
315 } else if (token == "\\bibitem") {
316 InsetCommandParams p("bibitem", "dummy");
317 auto_ptr<InsetBibitem> inset(new InsetBibitem(p));
318 inset->read(buf, lex);
319 par.insertInset(par.size(), inset.release(), font, change);
320 } else if (token == "\\hfill") {
321 par.insertInset(par.size(), new InsetHFill, font, change);
322 } else if (token == "\\lyxline") {
323 par.insertInset(par.size(), new InsetLine, font, change);
324 } else if (token == "\\newpage") {
325 par.insertInset(par.size(), new InsetPagebreak, font, change);
326 } else if (token == "\\change_unchanged") {
327 // Hack ! Needed for empty paragraphs :/
328 // FIXME: is it still ??
333 change = Change(Change::UNCHANGED);
334 } else if (token == "\\change_inserted") {
336 std::istringstream is(lex.getString());
340 if (aid >= bp.author_map.size()) {
341 errorList.push_back(ErrorItem(_("Change tracking error"),
342 bformat(_("Unknown author index for insertion: %1$d\n"), aid),
343 par.id(), 0, par.size()));
345 change = Change(Change::UNCHANGED);
347 change = Change(Change::INSERTED, bp.author_map[aid], ct);
348 } else if (token == "\\change_deleted") {
350 std::istringstream is(lex.getString());
354 if (aid >= bp.author_map.size()) {
355 errorList.push_back(ErrorItem(_("Change tracking error"),
356 bformat(_("Unknown author index for deletion: %1$d\n"), aid),
357 par.id(), 0, par.size()));
359 change = Change(Change::UNCHANGED);
361 change = Change(Change::DELETED, bp.author_map[aid], ct);
364 errorList.push_back(ErrorItem(_("Unknown token"),
365 bformat(_("Unknown token: %1$s %2$s\n"), lyx::from_utf8(token),
366 lyx::from_utf8(lex.getString())),
367 par.id(), 0, par.size()));
372 void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex, ErrorList & errorList)
375 string token = lex.getString();
381 readParToken(buf, par, lex, token, font, change, errorList);
384 token = lex.getString();
389 if (token == "\\end_layout") {
390 //Ok, paragraph finished
394 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
395 << token << '\'' << endl;
396 if (token == "\\begin_layout" || token == "\\end_document"
397 || token == "\\end_inset" || token == "\\begin_deeper"
398 || token == "\\end_deeper") {
399 lex.pushToken(token);
400 lyxerr << "Paragraph ended in line "
401 << lex.getLineNo() << "\n"
402 << "Missing \\end_layout.\n";
406 // Final change goes to paragraph break:
407 par.setChange(par.size(), change);
409 // Initialize begin_of_body_ on load; redoParagraph maintains
410 par.setBeginOfBody();
418 BufferView * LyXText::bv() const
420 BOOST_ASSERT(bv_owner != 0);
425 double LyXText::spacing(Paragraph const & par) const
427 if (par.params().spacing().isDefault())
428 return bv()->buffer()->params().spacing().getValue();
429 return par.params().spacing().getValue();
433 int LyXText::width() const
439 int LyXText::height() const
441 return dim_.height();
445 int LyXText::singleWidth(Paragraph const & par, pos_type pos) const
447 return singleWidth(par, pos, par.getChar(pos), getFont(par, pos));
451 int LyXText::singleWidth(Paragraph const & par,
452 pos_type pos, char_type c, LyXFont const & font) const
454 // The most common case is handled first (Asger)
455 if (isPrintable(c)) {
456 Language const * language = font.language();
457 if (language->rightToLeft()) {
458 if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
459 lyxrc.font_norm_type == LyXRC::ISO_10646_1)
460 && language->lang() == "arabic") {
461 if (Encodings::isComposeChar_arabic(c))
463 c = par.transformChar(c, pos);
464 } else if (language->lang() == "hebrew" &&
465 Encodings::isComposeChar_hebrew(c))
468 return font_metrics::width(c, font);
471 if (c == Paragraph::META_INSET)
472 return par.getInset(pos)->width();
474 return font_metrics::width(c, font);
478 int LyXText::leftMargin(pit_type pit) const
480 BOOST_ASSERT(pit >= 0);
481 BOOST_ASSERT(pit < int(pars_.size()));
482 return leftMargin(pit, pars_[pit].size());
486 int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
488 BOOST_ASSERT(pit >= 0);
489 BOOST_ASSERT(pit < int(pars_.size()));
490 Paragraph const & par = pars_[pit];
491 BOOST_ASSERT(pos >= 0);
492 BOOST_ASSERT(pos <= par.size());
493 //lyxerr << "LyXText::leftMargin: pit: " << pit << " pos: " << pos << endl;
494 BufferParams const & params = bv()->buffer()->params();
495 LyXTextClass const & tclass = params.getLyXTextClass();
496 LyXLayout_ptr const & layout = par.layout();
498 string parindent = layout->parindent;
503 l_margin += changebarMargin();
505 string leftm = tclass.leftmargin();
506 docstring dleft(leftm.begin(), leftm.end());
507 l_margin += font_metrics::signedWidth(dleft, params.getFont());
509 if (par.getDepth() != 0) {
510 // find the next level paragraph
511 pit_type newpar = outerHook(pit, pars_);
512 if (newpar != pit_type(pars_.size())) {
513 if (pars_[newpar].layout()->isEnvironment()) {
514 l_margin = leftMargin(newpar);
516 if (par.layout() == tclass.defaultLayout()) {
517 if (pars_[newpar].params().noindent())
520 parindent = pars_[newpar].layout()->parindent;
525 // This happens after sections in standard classes. The 1.3.x
526 // code compared depths too, but it does not seem necessary
528 if (par.layout() == tclass.defaultLayout()
529 && pit > 0 && pars_[pit - 1].layout()->nextnoindent)
532 LyXFont const labelfont = getLabelFont(par);
533 switch (layout->margintype) {
535 if (!layout->leftmargin.empty()) {
536 string leftm = layout->leftmargin;
537 docstring dleft(leftm.begin(), leftm.end());
538 l_margin += font_metrics::signedWidth(dleft,
541 if (!par.getLabelstring().empty()) {
542 string labin = layout->labelindent;
543 docstring dlabin(labin.begin(), labin.end());
544 l_margin += font_metrics::signedWidth(dlabin,
546 string labstr = par.getLabelstring();
547 docstring dlabstr(labstr.begin(), labstr.end());
548 l_margin += font_metrics::width(dlabstr,
550 string labsep = layout->labelsep;
551 docstring dlabsep(labsep.begin(), labsep.end());
552 l_margin += font_metrics::width(dlabsep, labelfont);
556 case MARGIN_MANUAL: {
557 string labin = layout->labelindent;
558 docstring dlabin(labin.begin(), labin.end());
559 l_margin += font_metrics::signedWidth(dlabin, labelfont);
560 // The width of an empty par, even with manual label, should be 0
561 if (!par.empty() && pos >= par.beginOfBody()) {
562 if (!par.getLabelWidthString().empty()) {
563 string labstr = par.getLabelWidthString();
564 docstring dlabstr(labstr.begin(), labstr.end());
565 l_margin += font_metrics::width(dlabstr,
567 string labsep = layout->labelsep;
568 docstring dlabsep(labsep.begin(), labsep.end());
569 l_margin += font_metrics::width(dlabsep, labelfont);
575 case MARGIN_STATIC: {
576 string leftm = layout->leftmargin;
577 docstring dleft(leftm.begin(), leftm.end());
578 l_margin += font_metrics::signedWidth(dleft, params.getFont()) * 4
579 / (par.getDepth() + 4);
583 case MARGIN_FIRST_DYNAMIC:
584 if (layout->labeltype == LABEL_MANUAL) {
585 if (pos >= par.beginOfBody()) {
586 string leftm = layout->leftmargin;
587 docstring dleft(leftm.begin(), leftm.end());
588 l_margin += font_metrics::signedWidth(dleft,
591 string labin = layout->labelindent;
592 docstring dlabin(labin.begin(), labin.end());
593 l_margin += font_metrics::signedWidth(dlabin,
597 // Special case to fix problems with
599 || (layout->labeltype == LABEL_STATIC
600 && layout->latextype == LATEX_ENVIRONMENT
601 && !isFirstInSequence(pit, pars_))) {
602 string leftm = layout->leftmargin;
603 docstring dleft(leftm.begin(), leftm.end());
604 l_margin += font_metrics::signedWidth(dleft,
606 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
607 && layout->labeltype != LABEL_BIBLIO
608 && layout->labeltype !=
609 LABEL_CENTERED_TOP_ENVIRONMENT) {
610 string labin = layout->labelindent;
611 docstring dlabin(labin.begin(), labin.end());
612 l_margin += font_metrics::signedWidth(dlabin,
614 string labsep = layout->labelsep;
615 docstring dlabsep(labsep.begin(), labsep.end());
616 l_margin += font_metrics::width(dlabsep, labelfont);
617 string labstr = par.getLabelstring();
618 docstring dlabstr(labstr.begin(), labstr.end());
619 l_margin += font_metrics::width(dlabstr, labelfont);
623 case MARGIN_RIGHT_ADDRESS_BOX: {
625 // ok, a terrible hack. The left margin depends on the widest
626 // row in this paragraph.
627 RowList::iterator rit = par.rows().begin();
628 RowList::iterator end = par.rows().end();
630 #warning This is wrong.
632 int minfill = maxwidth_;
633 for ( ; rit != end; ++rit)
634 if (rit->fill() < minfill)
635 minfill = rit->fill();
636 l_margin += font_metrics::signedWidth(layout->leftmargin,
640 // also wrong, but much shorter.
641 l_margin += maxwidth_ / 2;
646 if (!par.params().leftIndent().zero())
647 l_margin += par.params().leftIndent().inPixels(maxwidth_);
651 if (par.params().align() == LYX_ALIGN_LAYOUT)
652 align = layout->align;
654 align = par.params().align();
656 // set the correct parindent
658 && (layout->labeltype == LABEL_NO_LABEL
659 || layout->labeltype == LABEL_TOP_ENVIRONMENT
660 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
661 || (layout->labeltype == LABEL_STATIC
662 && layout->latextype == LATEX_ENVIRONMENT
663 && !isFirstInSequence(pit, pars_)))
664 && align == LYX_ALIGN_BLOCK
665 && !par.params().noindent()
666 // in some insets, paragraphs are never indented
667 && !(par.inInset() && par.inInset()->neverIndent())
668 // display style insets are always centered, omit indentation
671 && par.getInset(pos)->display())
672 && (par.layout() != tclass.defaultLayout()
673 || bv()->buffer()->params().paragraph_separation ==
674 BufferParams::PARSEP_INDENT))
676 docstring din(parindent.begin(), parindent.end());
677 l_margin += font_metrics::signedWidth(din, params.getFont());
684 int LyXText::rightMargin(Paragraph const & par) const
686 // FIXME: the correct way is to only call rightMargin() only
687 // within the main LyXText. The following test is thus bogus.
688 LyXText const & text = bv()->buffer()->text();
689 // We do not want rightmargins on inner texts.
693 BufferParams const & params = bv()->buffer()->params();
694 LyXTextClass const & tclass = params.getLyXTextClass();
695 string trmarg = tclass.rightmargin();
696 docstring dtrmarg(trmarg.begin(), trmarg.end());
697 string lrmarg = par.layout()->rightmargin;
698 docstring dlrmarg(lrmarg.begin(), lrmarg.end());
701 + font_metrics::signedWidth(dtrmarg,
703 + font_metrics::signedWidth(dlrmarg,
705 * 4 / (par.getDepth() + 4);
711 int LyXText::labelEnd(pit_type const pit) const
713 // labelEnd is only needed if the layout fills a flushleft label.
714 if (pars_[pit].layout()->margintype != MARGIN_MANUAL)
716 // return the beginning of the body
717 return leftMargin(pit);
723 // this needs special handling - only newlines count as a break point
724 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
726 pos_type const end = par.size();
729 if (par.isNewline(i))
738 void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
740 Paragraph const & par = pars_[pit];
741 pos_type const end = par.size();
742 pos_type const pos = row.pos();
748 // maximum pixel width of a row
749 int width = maxwidth_ - rightMargin(par); // - leftMargin(pit, row);
755 LyXLayout_ptr const & layout = par.layout();
757 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
758 row.endpos(addressBreakPoint(pos, par));
762 pos_type const body_pos = par.beginOfBody();
765 // Now we iterate through until we reach the right margin
766 // or the end of the par, then choose the possible break
769 int const left = leftMargin(pit, pos);
772 // pixel width since last breakpoint
775 FontIterator fi = FontIterator(*this, par, pos);
776 pos_type point = end;
778 for ( ; i < end; ++i, ++fi) {
779 char_type const c = par.getChar(i);
780 int thiswidth = singleWidth(par, i, c, *fi);
782 // add the auto-hfill from label end to the body
783 if (body_pos && i == body_pos) {
784 string lsep = layout->labelsep;
785 docstring dlsep(lsep.begin(), lsep.end());
786 int add = font_metrics::width(dlsep, getLabelFont(par));
787 if (par.isLineSeparator(i - 1))
788 add -= singleWidth(par, i - 1);
790 add = std::max(add, labelEnd(pit) - x);
795 chunkwidth += thiswidth;
797 // break before a character that will fall off
798 // the right of the row
800 // if no break before, break here
801 if (point == end || chunkwidth >= width - left) {
808 // exit on last registered breakpoint:
812 if (par.isNewline(i)) {
818 if (par.isInset(i + 1) && par.getInset(i + 1)->display()) {
823 if (par.isInset(i) && par.getInset(i)->display()) {
829 if (!par.isInset(i) || par.getInset(i)->isChar()) {
830 // some insets are line separators too
831 if (par.isLineSeparator(i)) {
832 // register breakpoint:
839 // maybe found one, but the par is short enough.
840 if (i == end && x < width)
843 // manual labels cannot be broken in LaTeX. But we
844 // want to make our on-screen rendering of footnotes
846 if (body_pos && point < body_pos)
853 void LyXText::setRowWidth(pit_type const pit, Row & row) const
855 // get the pure distance
856 pos_type const end = row.endpos();
858 Paragraph const & par = pars_[pit];
859 string const & labelsep = par.layout()->labelsep;
860 docstring dlsep(labelsep.begin(), labelsep.end());
861 int w = leftMargin(pit, row.pos());
863 pos_type const body_pos = par.beginOfBody();
864 pos_type i = row.pos();
867 FontIterator fi = FontIterator(*this, par, i);
868 for ( ; i < end; ++i, ++fi) {
869 if (body_pos > 0 && i == body_pos) {
870 w += font_metrics::width(dlsep, getLabelFont(par));
871 if (par.isLineSeparator(i - 1))
872 w -= singleWidth(par, i - 1);
873 w = max(w, labelEnd(pit));
875 char_type const c = par.getChar(i);
876 w += singleWidth(par, i, c, *fi);
880 if (body_pos > 0 && body_pos >= end) {
881 w += font_metrics::width(dlsep, getLabelFont(par));
882 if (end > 0 && par.isLineSeparator(end - 1))
883 w -= singleWidth(par, end - 1);
884 w = max(w, labelEnd(pit));
887 row.width(w + rightMargin(par));
891 // returns the minimum space a manual label needs on the screen in pixel
892 int LyXText::labelFill(Paragraph const & par, Row const & row) const
894 pos_type last = par.beginOfBody();
896 BOOST_ASSERT(last > 0);
898 // -1 because a label ends with a space that is in the label
901 // a separator at this end does not count
902 if (par.isLineSeparator(last))
906 for (pos_type i = row.pos(); i <= last; ++i)
907 w += singleWidth(par, i);
909 string const & label = par.params().labelWidthString();
913 docstring dlab(label.begin(), label.end());
914 return max(0, font_metrics::width(dlab, getLabelFont(par)) - w);
918 LColor_color LyXText::backgroundColor() const
920 return LColor_color(LColor::color(background_color_));
924 void LyXText::setHeightOfRow(pit_type const pit, Row & row)
926 Paragraph const & par = pars_[pit];
927 // get the maximum ascent and the maximum descent
928 double layoutasc = 0;
929 double layoutdesc = 0;
930 double const dh = defaultRowHeight();
932 // ok, let us initialize the maxasc and maxdesc value.
933 // Only the fontsize count. The other properties
934 // are taken from the layoutfont. Nicer on the screen :)
935 LyXLayout_ptr const & layout = par.layout();
937 // as max get the first character of this row then it can
938 // increase but not decrease the height. Just some point to
939 // start with so we don't have to do the assignment below too
941 LyXFont font = getFont(par, row.pos());
942 LyXFont::FONT_SIZE const tmpsize = font.size();
943 font = getLayoutFont(pit);
944 LyXFont::FONT_SIZE const size = font.size();
945 font.setSize(tmpsize);
947 LyXFont labelfont = getLabelFont(par);
949 // these are minimum values
950 double const spacing_val = layout->spacing.getValue() * spacing(par);
951 //lyxerr << "spacing_val = " << spacing_val << endl;
952 int maxasc = int(font_metrics::maxAscent(font) * spacing_val);
953 int maxdesc = int(font_metrics::maxDescent(font) * spacing_val);
955 // insets may be taller
956 InsetList::const_iterator ii = par.insetlist.begin();
957 InsetList::const_iterator iend = par.insetlist.end();
958 for ( ; ii != iend; ++ii) {
959 if (ii->pos >= row.pos() && ii->pos < row.endpos()) {
960 maxasc = max(maxasc, ii->inset->ascent());
961 maxdesc = max(maxdesc, ii->inset->descent());
965 // Check if any custom fonts are larger (Asger)
966 // This is not completely correct, but we can live with the small,
967 // cosmetic error for now.
969 pos_type const pos_end = row.endpos();
971 LyXFont::FONT_SIZE maxsize =
972 par.highestFontInRange(row.pos(), pos_end, size);
973 if (maxsize > font.size()) {
974 font.setSize(maxsize);
975 maxasc = max(maxasc, font_metrics::maxAscent(font));
976 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
979 // This is nicer with box insets:
986 if (row.pos() == 0) {
987 BufferParams const & bufparams = bv()->buffer()->params();
988 // some parksips VERY EASY IMPLEMENTATION
989 if (bv()->buffer()->params().paragraph_separation
990 == BufferParams::PARSEP_SKIP
992 && ((layout->isParagraph() && par.getDepth() == 0)
993 || (pars_[pit - 1].layout()->isParagraph()
994 && pars_[pit - 1].getDepth() == 0)))
996 maxasc += bufparams.getDefSkip().inPixels(*bv());
999 if (par.params().startOfAppendix())
1000 maxasc += int(3 * dh);
1002 // This is special code for the chapter, since the label of this
1003 // layout is printed in an extra row
1004 if (layout->counter == "chapter"
1005 && !par.params().labelString().empty()) {
1006 labeladdon = int(font_metrics::maxHeight(labelfont)
1007 * layout->spacing.getValue()
1011 // special code for the top label
1012 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
1013 || layout->labeltype == LABEL_BIBLIO
1014 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
1015 && isFirstInSequence(pit, paragraphs())
1016 && !par.getLabelstring().empty())
1019 font_metrics::maxHeight(labelfont)
1020 * layout->spacing.getValue()
1022 + (layout->topsep + layout->labelbottomsep) * dh);
1025 // Add the layout spaces, for example before and after
1026 // a section, or between the items of a itemize or enumerate
1029 pit_type prev = depthHook(pit, pars_, par.getDepth());
1031 && pars_[prev].layout() == layout
1032 && pars_[prev].getDepth() == par.getDepth()
1033 && pars_[prev].getLabelWidthString() == par.getLabelWidthString())
1035 layoutasc = layout->itemsep * dh;
1036 } else if (pit != 0 || row.pos() != 0) {
1037 if (layout->topsep > 0)
1038 layoutasc = layout->topsep * dh;
1041 prev = outerHook(pit, pars_);
1042 if (prev != pit_type(pars_.size())) {
1043 maxasc += int(pars_[prev].layout()->parsep * dh);
1044 } else if (pit != 0) {
1045 if (pars_[pit - 1].getDepth() != 0 ||
1046 pars_[pit - 1].layout() == layout) {
1047 maxasc += int(layout->parsep * dh);
1052 // is it a bottom line?
1053 if (row.endpos() >= par.size()) {
1054 // add the layout spaces, for example before and after
1055 // a section, or between the items of a itemize or enumerate
1057 pit_type nextpit = pit + 1;
1058 if (nextpit != pit_type(pars_.size())) {
1059 pit_type cpit = pit;
1063 if (pars_[cpit].getDepth() > pars_[nextpit].getDepth()) {
1064 usual = pars_[cpit].layout()->bottomsep * dh;
1065 cpit = depthHook(cpit, paragraphs(), pars_[nextpit].getDepth());
1066 if (pars_[cpit].layout() != pars_[nextpit].layout()
1067 || pars_[nextpit].getLabelWidthString() != pars_[cpit].getLabelWidthString())
1069 unusual = pars_[cpit].layout()->bottomsep * dh;
1071 layoutdesc = max(unusual, usual);
1072 } else if (pars_[cpit].getDepth() == pars_[nextpit].getDepth()) {
1073 if (pars_[cpit].layout() != pars_[nextpit].layout()
1074 || pars_[nextpit].getLabelWidthString() != pars_[cpit].getLabelWidthString())
1075 layoutdesc = int(pars_[cpit].layout()->bottomsep * dh);
1080 // incalculate the layout spaces
1081 maxasc += int(layoutasc * 2 / (2 + pars_[pit].getDepth()));
1082 maxdesc += int(layoutdesc * 2 / (2 + pars_[pit].getDepth()));
1084 // FIXME: the correct way is to do the following is to move the
1085 // following code in another method specially tailored for the
1086 // main LyXText. The following test is thus bogus.
1087 LyXText const & text = bv_owner->buffer()->text();
1088 // Top and bottom margin of the document (only at top-level)
1089 if (&text == this) {
1090 if (pit == 0 && row.pos() == 0)
1092 if (pit + 1 == pit_type(pars_.size()) &&
1093 row.endpos() == par.size())
1097 row.ascent(maxasc + labeladdon);
1098 row.descent(maxdesc);
1106 void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
1108 BOOST_ASSERT(this == cur.text());
1110 Paragraph & cpar = cur.paragraph();
1111 pit_type cpit = cur.pit();
1113 LyXTextClass const & tclass = cur.buffer().params().getLyXTextClass();
1114 LyXLayout_ptr const & layout = cpar.layout();
1116 // this is only allowed, if the current paragraph is not empty
1117 // or caption and if it has not the keepempty flag active
1118 if (cur.lastpos() == 0 && !cpar.allowEmpty()
1119 && layout->labeltype != LABEL_SENSITIVE)
1122 // a layout change may affect also the following paragraph
1123 recUndo(cur.pit(), undoSpan(cur.pit()) - 1);
1125 // Always break behind a space
1126 // It is better to erase the space (Dekel)
1127 if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos()))
1128 cpar.erase(cur.pos());
1130 // How should the layout for the new paragraph be?
1131 int preserve_layout = 0;
1133 preserve_layout = 2;
1135 preserve_layout = layout->isEnvironment();
1137 // We need to remember this before we break the paragraph, because
1138 // that invalidates the layout variable
1139 bool sensitive = layout->labeltype == LABEL_SENSITIVE;
1141 // we need to set this before we insert the paragraph.
1142 bool const isempty = cpar.allowEmpty() && cpar.empty();
1144 ::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
1145 cur.pos(), preserve_layout);
1147 // After this, neither paragraph contains any rows!
1150 pit_type next_par = cpit + 1;
1152 // well this is the caption hack since one caption is really enough
1155 // set to standard-layout
1156 pars_[cpit].applyLayout(tclass.defaultLayout());
1158 // set to standard-layout
1159 pars_[next_par].applyLayout(tclass.defaultLayout());
1162 while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
1163 pars_[next_par].erase(0);
1165 ParIterator current_it(cur);
1166 ParIterator last_it(cur);
1170 updateLabels(cur.buffer(), current_it, last_it);
1172 // Mark "carriage return" as inserted if change tracking:
1173 if (cur.buffer().params().tracking_changes) {
1174 cur.paragraph().setChange(cur.paragraph().size(),
1178 // This check is necessary. Otherwise the new empty paragraph will
1179 // be deleted automatically. And it is more friendly for the user!
1180 if (cur.pos() != 0 || isempty)
1181 setCursor(cur, cur.pit() + 1, 0);
1183 setCursor(cur, cur.pit(), 0);
1187 // insert a character, moves all the following breaks in the
1188 // same Paragraph one to the right and make a rebreak
1189 void LyXText::insertChar(LCursor & cur, char_type c)
1191 BOOST_ASSERT(this == cur.text());
1192 BOOST_ASSERT(c != Paragraph::META_INSET);
1194 recordUndo(cur, Undo::INSERT);
1196 Paragraph & par = cur.paragraph();
1197 // try to remove this
1198 pit_type const pit = cur.pit();
1200 bool const freeSpacing = par.layout()->free_spacing ||
1201 par.isFreeSpacing();
1203 if (lyxrc.auto_number) {
1204 static docstring const number_operators = lyx::from_ascii("+-/*");
1205 static docstring const number_unary_operators = lyx::from_ascii("+-");
1206 static docstring const number_seperators = lyx::from_ascii(".,:");
1208 if (current_font.number() == LyXFont::ON) {
1209 if (!isDigit(c) && !contains(number_operators, c) &&
1210 !(contains(number_seperators, c) &&
1212 cur.pos() != cur.lastpos() &&
1213 getFont(par, cur.pos()).number() == LyXFont::ON &&
1214 getFont(par, cur.pos() - 1).number() == LyXFont::ON)
1216 number(cur); // Set current_font.number to OFF
1217 } else if (isDigit(c) &&
1218 real_current_font.isVisibleRightToLeft()) {
1219 number(cur); // Set current_font.number to ON
1221 if (cur.pos() != 0) {
1222 char_type const c = par.getChar(cur.pos() - 1);
1223 if (contains(number_unary_operators, c) &&
1225 || par.isSeparator(cur.pos() - 2)
1226 || par.isNewline(cur.pos() - 2))
1228 setCharFont(pit, cur.pos() - 1, current_font);
1229 } else if (contains(number_seperators, c)
1231 && getFont(par, cur.pos() - 2).number() == LyXFont::ON) {
1232 setCharFont(pit, cur.pos() - 1, current_font);
1238 // First check, if there will be two blanks together or a blank at
1239 // the beginning of a paragraph.
1240 // I decided to handle blanks like normal characters, the main
1241 // difference are the special checks when calculating the row.fill
1242 // (blank does not count at the end of a row) and the check here
1244 // When the free-spacing option is set for the current layout,
1245 // disable the double-space checking
1246 if (!freeSpacing && isLineSeparatorChar(c)) {
1247 if (cur.pos() == 0) {
1248 static bool sent_space_message = false;
1249 if (!sent_space_message) {
1250 cur.message(_("You cannot insert a space at the "
1251 "beginning of a paragraph. Please read the Tutorial."));
1252 sent_space_message = true;
1256 BOOST_ASSERT(cur.pos() > 0);
1257 if ((par.isLineSeparator(cur.pos() - 1)
1258 || par.isNewline(cur.pos() - 1))
1259 && par.lookupChange(cur.pos() - 1) != Change::DELETED) {
1260 static bool sent_space_message = false;
1261 if (!sent_space_message) {
1262 cur.message(_("You cannot type two spaces this way. "
1263 "Please read the Tutorial."));
1264 sent_space_message = true;
1270 par.insertChar(cur.pos(), c, current_font);
1271 setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
1276 void LyXText::charInserted()
1278 // Here we call finishUndo for every 20 characters inserted.
1279 // This is from my experience how emacs does it. (Lgb)
1280 static unsigned int counter;
1291 LyXText::computeRowMetrics(pit_type const pit, Row const & row) const
1294 Paragraph const & par = pars_[pit];
1296 double w = dim_.wid - row.width();
1298 bool const is_rtl = isRTL(par);
1300 result.x = rightMargin(par);
1302 result.x = leftMargin(pit, row.pos());
1304 // is there a manual margin with a manual label
1305 LyXLayout_ptr const & layout = par.layout();
1307 if (layout->margintype == MARGIN_MANUAL
1308 && layout->labeltype == LABEL_MANUAL) {
1309 /// We might have real hfills in the label part
1310 int nlh = numberOfLabelHfills(par, row);
1312 // A manual label par (e.g. List) has an auto-hfill
1313 // between the label text and the body of the
1315 // But we don't want to do this auto hfill if the par
1320 if (nlh && !par.getLabelWidthString().empty())
1321 result.label_hfill = labelFill(par, row) / double(nlh);
1324 // are there any hfills in the row?
1325 int const nh = numberOfHfills(par, row);
1329 result.hfill = w / nh;
1330 // we don't have to look at the alignment if it is ALIGN_LEFT and
1331 // if the row is already larger then the permitted width as then
1332 // we force the LEFT_ALIGN'edness!
1333 } else if (int(row.width()) < maxwidth_) {
1334 // is it block, flushleft or flushright?
1335 // set x how you need it
1337 if (par.params().align() == LYX_ALIGN_LAYOUT)
1338 align = layout->align;
1340 align = par.params().align();
1342 // Display-style insets should always be on a centred row
1343 // The test on par.size() is to catch zero-size pars, which
1344 // would trigger the assert in Paragraph::getInset().
1345 //inset = par.size() ? par.getInset(row.pos()) : 0;
1347 && par.isInset(row.pos())
1348 && par.getInset(row.pos())->display())
1350 align = LYX_ALIGN_CENTER;
1354 case LYX_ALIGN_BLOCK: {
1355 int const ns = numberOfSeparators(par, row);
1356 bool disp_inset = false;
1357 if (row.endpos() < par.size()) {
1358 InsetBase const * in = par.getInset(row.endpos());
1360 disp_inset = in->display();
1362 // If we have separators, this is not the last row of a
1363 // par, does not end in newline, and is not row above a
1364 // display inset... then stretch it
1366 && row.endpos() < par.size()
1367 && !par.isNewline(row.endpos() - 1)
1370 result.separator = w / ns;
1371 } else if (is_rtl) {
1376 case LYX_ALIGN_RIGHT:
1379 case LYX_ALIGN_CENTER:
1385 bidi.computeTables(par, *bv()->buffer(), row);
1387 pos_type body_pos = par.beginOfBody();
1388 pos_type end = row.endpos();
1391 && (body_pos > end || !par.isLineSeparator(body_pos - 1)))
1393 string lsep = layout->labelsep;
1394 docstring dlsep(lsep.begin(), lsep.end());
1395 result.x += font_metrics::width(dlsep, getLabelFont(par));
1396 if (body_pos <= end)
1397 result.x += result.label_hfill;
1405 // the cursor set functions have a special mechanism. When they
1406 // realize, that you left an empty paragraph, they will delete it.
1408 bool LyXText::cursorRightOneWord(LCursor & cur)
1410 BOOST_ASSERT(this == cur.text());
1414 if (old.pos() == old.lastpos() && old.pit() != old.lastpit()) {
1418 // Advance through word.
1419 while (old.pos() != old.lastpos() && old.paragraph().isLetter(old.pos()))
1421 // Skip through trailing nonword stuff.
1422 while (old.pos() != old.lastpos() && !old.paragraph().isLetter(old.pos()))
1425 return setCursor(cur, old.pit(), old.pos());
1429 bool LyXText::cursorLeftOneWord(LCursor & cur)
1431 BOOST_ASSERT(this == cur.text());
1435 if (old.pos() == 0 && old.pit() != 0) {
1437 old.pos() = old.lastpos();
1439 // Skip through initial nonword stuff.
1440 while (old.pos() != 0 && !old.paragraph().isLetter(old.pos() - 1))
1442 // Advance through word.
1443 while (old.pos() != 0 && old.paragraph().isLetter(old.pos() - 1))
1446 return setCursor(cur, old.pit(), old.pos());
1450 void LyXText::selectWord(LCursor & cur, word_location loc)
1452 BOOST_ASSERT(this == cur.text());
1453 CursorSlice from = cur.top();
1454 CursorSlice to = cur.top();
1455 getWord(from, to, loc);
1456 if (cur.top() != from)
1457 setCursor(cur, from.pit(), from.pos());
1461 setCursor(cur, to.pit(), to.pos());
1466 // Select the word currently under the cursor when no
1467 // selection is currently set
1468 bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
1470 BOOST_ASSERT(this == cur.text());
1471 if (cur.selection())
1473 selectWord(cur, loc);
1474 return cur.selection();
1478 void LyXText::acceptChange(LCursor & cur)
1480 BOOST_ASSERT(this == cur.text());
1481 if (!cur.selection() && cur.lastpos() != 0)
1484 recordUndoSelection(cur, Undo::INSERT);
1486 DocIterator it = cur.selectionBegin();
1487 DocIterator et = cur.selectionEnd();
1488 pit_type pit = it.pit();
1489 Change::Type const type = pars_[pit].lookupChange(it.pos()).type;
1490 for (; pit <= et.pit(); ++pit) {
1491 pos_type left = ( pit == it.pit() ? it.pos() : 0 );
1493 ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
1494 pars_[pit].acceptChange(left, right);
1496 if (type == Change::DELETED) {
1497 ParagraphList & plist = paragraphs();
1498 if (it.pit() + 1 < et.pit())
1499 pars_.erase(boost::next(plist.begin(), it.pit() + 1),
1500 boost::next(plist.begin(), et.pit()));
1502 // Paragraph merge if appropriate:
1503 if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
1504 == Change::DELETED) {
1505 setCursorIntern(cur, it.pit() + 1, 0);
1510 cur.clearSelection();
1511 setCursorIntern(cur, it.pit(), 0);
1515 void LyXText::rejectChange(LCursor & cur)
1517 BOOST_ASSERT(this == cur.text());
1518 if (!cur.selection() && cur.lastpos() != 0)
1521 recordUndoSelection(cur, Undo::INSERT);
1523 DocIterator it = cur.selectionBegin();
1524 DocIterator et = cur.selectionEnd();
1525 pit_type pit = it.pit();
1526 Change::Type const type = pars_[pit].lookupChange(it.pos()).type;
1527 for (; pit <= et.pit(); ++pit) {
1528 pos_type left = ( pit == it.pit() ? it.pos() : 0 );
1530 ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
1531 pars_[pit].rejectChange(left, right);
1533 if (type == Change::INSERTED) {
1534 ParagraphList & plist = paragraphs();
1535 if (it.pit() + 1 < et.pit())
1536 pars_.erase(boost::next(plist.begin(), it.pit() + 1),
1537 boost::next(plist.begin(), et.pit()));
1538 // Paragraph merge if appropriate:
1539 if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
1540 == Change::INSERTED) {
1541 setCursorIntern(cur, it.pit() + 1, 0);
1546 cur.clearSelection();
1547 setCursorIntern(cur, it.pit(), 0);
1551 // Delete from cursor up to the end of the current or next word.
1552 void LyXText::deleteWordForward(LCursor & cur)
1554 BOOST_ASSERT(this == cur.text());
1555 if (cur.lastpos() == 0)
1559 cur.selection() = true;
1560 cursorRightOneWord(cur);
1562 cutSelection(cur, true, false);
1567 // Delete from cursor to start of current or prior word.
1568 void LyXText::deleteWordBackward(LCursor & cur)
1570 BOOST_ASSERT(this == cur.text());
1571 if (cur.lastpos() == 0)
1575 cur.selection() = true;
1576 cursorLeftOneWord(cur);
1578 cutSelection(cur, true, false);
1583 // Kill to end of line.
1584 void LyXText::deleteLineForward(LCursor & cur)
1586 BOOST_ASSERT(this == cur.text());
1587 if (cur.lastpos() == 0) {
1588 // Paragraph is empty, so we just go to the right
1592 cur.selection() = true; // to avoid deletion
1595 // What is this test for ??? (JMarc)
1596 if (!cur.selection())
1597 deleteWordForward(cur);
1599 cutSelection(cur, true, false);
1604 void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
1606 BOOST_ASSERT(this == cur.text());
1610 if (cur.selection()) {
1611 from = cur.selBegin();
1615 getWord(from, to, lyx::PARTIAL_WORD);
1616 cursorRightOneWord(cur);
1619 recordUndoSelection(cur);
1621 pos_type pos = from.pos();
1622 int par = from.pit();
1624 while (par != int(pars_.size()) && (pos != to.pos() || par != to.pit())) {
1626 if (pos == pars_[pit].size()) {
1631 char_type c = pars_[pit].getChar(pos);
1632 if (c != Paragraph::META_INSET) {
1634 case text_lowercase:
1637 case text_capitalization:
1639 action = text_lowercase;
1641 case text_uppercase:
1646 #ifdef WITH_WARNINGS
1649 pars_[pit].setChar(pos, c);
1655 bool LyXText::erase(LCursor & cur)
1657 BOOST_ASSERT(this == cur.text());
1658 bool needsUpdate = false;
1660 if (cur.pos() != cur.lastpos()) {
1661 recordUndo(cur, Undo::DELETE, cur.pit());
1662 setCursorIntern(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
1663 needsUpdate = backspace(cur);
1664 if (cur.paragraph().lookupChange(cur.pos()) == Change::DELETED)
1666 } else if (cur.pit() != cur.lastpit()) {
1669 setCursorIntern(cur, cur.pit() + 1, 0, false, false);
1670 if (pars_[cur.pit()].layout() == pars_[scur.pit()].layout()) {
1671 recordUndo(scur, Undo::DELETE, scur.pit());
1672 needsUpdate = backspace(cur);
1673 if (cur.buffer().params().tracking_changes) {
1674 // move forward after the paragraph break is DELETED
1675 Paragraph & par = cur.paragraph();
1676 if (par.lookupChange(par.size()) == Change::DELETED)
1677 setCursorIntern(cur, cur.pit() + 1, 0);
1680 setCursorIntern(scur, scur.pit(), scur.pos(), false, scur.boundary());
1683 needsUpdate = dissolveInset(cur);
1689 bool LyXText::backspacePos0(LCursor & cur)
1691 BOOST_ASSERT(this == cur.text());
1692 bool needsUpdate = false;
1694 Paragraph & par = cur.paragraph();
1695 // is it an empty paragraph?
1696 pos_type lastpos = cur.lastpos();
1697 if (lastpos == 0 || (lastpos == 1 && par.isSeparator(0))) {
1698 // This is an empty paragraph and we delete it just
1699 // by moving the cursor one step
1700 // left and let the DeleteEmptyParagraphMechanism
1701 // handle the actual deletion of the paragraph.
1703 if (cur.pit() != 0) {
1704 // For KeepEmpty layouts we need to get
1705 // rid of the keepEmpty setting first.
1706 // And the only way to do this is to
1707 // reset the layout to something
1708 // else: f.ex. the default layout.
1709 if (par.allowEmpty()) {
1710 Buffer & buf = cur.buffer();
1711 BufferParams const & bparams = buf.params();
1712 par.layout(bparams.getLyXTextClass().defaultLayout());
1721 recordUndo(cur, Undo::DELETE, cur.pit() - 1);
1723 pit_type tmppit = cur.pit();
1724 // We used to do cursorLeftIntern() here, but it is
1725 // not a good idea since it triggers the auto-delete
1726 // mechanism. So we do a cursorLeftIntern()-lite,
1727 // without the dreaded mechanism. (JMarc)
1728 if (cur.pit() != 0) {
1729 // steps into the above paragraph.
1730 setCursorIntern(cur, cur.pit() - 1,
1731 pars_[cur.pit() - 1].size(),
1735 // Pasting is not allowed, if the paragraphs have different
1736 // layout. I think it is a real bug of all other
1737 // word processors to allow it. It confuses the user.
1738 // Correction: Pasting is always allowed with standard-layout
1739 // Correction (Jug 20050717): Remove check about alignment!
1740 Buffer & buf = cur.buffer();
1741 BufferParams const & bufparams = buf.params();
1742 LyXTextClass const & tclass = bufparams.getLyXTextClass();
1743 pit_type const cpit = cur.pit();
1746 && (pars_[cpit].layout() == pars_[tmppit].layout()
1747 || pars_[tmppit].layout() == tclass.defaultLayout()))
1749 mergeParagraph(bufparams, pars_, cpit);
1752 if (cur.pos() != 0 && pars_[cpit].isSeparator(cur.pos() - 1))
1755 // the counters may have changed
1756 ParIterator par_it(cur);
1757 updateLabels(cur.buffer(), par_it);
1759 setCursor(cur, cur.pit(), cur.pos(), false);
1765 bool LyXText::backspace(LCursor & cur)
1767 BOOST_ASSERT(this == cur.text());
1768 bool needsUpdate = false;
1769 if (cur.pos() == 0) {
1771 return dissolveInset(cur);
1773 // The cursor is at the beginning of a paragraph, so
1774 // the the backspace will collapse two paragraphs into
1777 if (cur.pit() != 0 && cur.buffer().params().tracking_changes) {
1778 // Previous paragraph, mark "carriage return" as
1780 Paragraph & par = pars_[cur.pit() - 1];
1781 // Take care of a just inserted para break:
1782 if (par.lookupChange(par.size()) != Change::INSERTED) {
1783 par.setChange(par.size(), Change::DELETED);
1784 setCursorIntern(cur, cur.pit() - 1, par.size());
1789 needsUpdate = backspacePos0(cur);
1792 // this is the code for a normal backspace, not pasting
1794 recordUndo(cur, Undo::DELETE);
1795 // We used to do cursorLeftIntern() here, but it is
1796 // not a good idea since it triggers the auto-delete
1797 // mechanism. So we do a cursorLeftIntern()-lite,
1798 // without the dreaded mechanism. (JMarc)
1799 setCursorIntern(cur, cur.pit(), cur.pos() - 1,
1800 false, cur.boundary());
1801 cur.paragraph().erase(cur.pos());
1804 if (cur.pos() == cur.lastpos())
1805 setCurrentFont(cur);
1807 setCursor(cur, cur.pit(), cur.pos(), false, cur.boundary());
1813 bool LyXText::dissolveInset(LCursor & cur) {
1814 BOOST_ASSERT(this == cur.text());
1816 if (isMainText() || cur.inset().nargs() != 1)
1819 recordUndoInset(cur);
1820 cur.selHandle(false);
1822 lyx::pos_type spos = cur.pos();
1823 lyx::pit_type spit = cur.pit();
1824 ParagraphList plist;
1825 if (cur.lastpit() != 0 || cur.lastpos() != 0)
1826 plist = paragraphs();
1828 // store cursor offset
1832 cur.paragraph().erase(cur.pos());
1833 if (!plist.empty()) {
1834 Buffer & b = cur.buffer();
1835 pasteParagraphList(cur, plist, b.params().textclass,
1836 b.errorList("Paste"));
1838 cur.pit() = std::min(cur.lastpit(), spit);
1839 cur.pos() = std::min(cur.lastpos(), spos);
1841 cur.clearSelection();
1847 Row const & LyXText::firstRow() const
1849 return *paragraphs().front().rows().begin();
1853 bool LyXText::redoParagraph(pit_type const pit)
1855 // remove rows of paragraph, keep track of height changes
1856 Paragraph & par = pars_[pit];
1858 // Add bibitem insets if necessary
1859 if (par.layout()->labeltype == LABEL_BIBLIO) {
1860 bool hasbibitem(false);
1861 if (!par.insetlist.empty()
1862 // Insist on it being in pos 0
1863 && par.getChar(0) == Paragraph::META_INSET) {
1864 InsetBase * inset = par.insetlist.begin()->inset;
1865 if (inset->lyxCode() == InsetBase::BIBITEM_CODE)
1869 InsetBibitem * inset(new
1870 InsetBibitem(InsetCommandParams("bibitem")));
1871 par.insertInset(0, static_cast<InsetBase *>(inset));
1872 bv()->cursor().posRight();
1877 // FIXME: We should always use getFont(), see documentation of
1878 // noFontChange() in insetbase.h.
1879 LyXFont const bufferfont = bv()->buffer()->params().getFont();
1880 InsetList::iterator ii = par.insetlist.begin();
1881 InsetList::iterator iend = par.insetlist.end();
1882 for (; ii != iend; ++ii) {
1884 int const w = maxwidth_ - leftMargin(pit, ii->pos) - rightMargin(par);
1885 LyXFont const & font = ii->inset->noFontChange() ?
1887 getFont(par, ii->pos);
1888 MetricsInfo mi(bv(), font, w);
1889 ii->inset->metrics(mi, dim);
1892 // rebreak the paragraph
1896 par.setBeginOfBody();
1900 rowBreakPoint(pit, row);
1901 setRowWidth(pit, row);
1902 setHeightOfRow(pit, row);
1903 par.rows().push_back(row);
1904 dim.wid = std::max(dim.wid, row.width());
1905 dim.des += row.height();
1907 } while (z < par.size());
1909 // Make sure that if a par ends in newline, there is one more row
1911 // FIXME this is a dirty trick. Now the _same_ position in the
1912 // paragraph occurs in _two_ different rows, and has two different
1913 // display positions, leading to weird behaviour when moving up/down.
1914 if (z > 0 && par.isNewline(z - 1)) {
1917 setRowWidth(pit, row);
1918 setHeightOfRow(pit, row);
1919 par.rows().push_back(row);
1920 dim.des += row.height();
1923 dim.asc += par.rows()[0].ascent();
1924 dim.des -= par.rows()[0].ascent();
1926 bool const same = dim == par.dim();
1929 //lyxerr << "redoParagraph: " << par.rows().size() << " rows\n";
1935 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
1937 //BOOST_ASSERT(mi.base.textwidth);
1938 if (mi.base.textwidth)
1939 maxwidth_ = mi.base.textwidth;
1940 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
1941 // << " maxWidth: " << maxwidth_ << "\nfont: " << mi.base.font << endl;
1942 // save the caller's font locally:
1943 font_ = mi.base.font;
1947 for (pit_type pit = 0, n = paragraphs().size(); pit != n; ++pit) {
1949 Paragraph & par = paragraphs()[pit];
1951 if (w < par.width())
1956 dim.asc = pars_[0].ascent();
1957 dim.des = h - dim.asc;
1963 // only used for inset right now. should also be used for main text
1964 void LyXText::draw(PainterInfo & pi, int x, int y) const
1966 paintTextInset(*this, pi, x, y);
1971 // only used for inset right now. should also be used for main text
1972 void LyXText::drawSelection(PainterInfo & pi, int x , int) const
1974 LCursor & cur = pi.base.bv->cursor();
1975 if (!cur.selection())
1977 if (!ptr_cmp(cur.text(), this))
1980 lyxerr << "draw selection at " << x << endl;
1982 DocIterator beg = cur.selectionBegin();
1983 DocIterator end = cur.selectionEnd();
1985 // the selection doesn't touch the visible screen
1986 if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW
1987 || bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE)
1990 Paragraph const & par1 = pars_[beg.pit()];
1991 Paragraph const & par2 = pars_[end.pit()];
1993 Row const & row1 = par1.getRow(beg.pos(), beg.boundary());
1994 Row const & row2 = par2.getRow(end.pos(), end.boundary());
1997 if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_ABOVE) {
2002 y1 = bv_funcs::getPos(beg).y_ - row1.ascent();
2003 int const startx = cursorX(beg.top(), begin.boundary());
2004 x1 = isRTL(par1) ? startx : 0;
2005 x2 = isRTL(par1) ? 0 + dim_.wid : startx;
2009 if (bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_BELOW) {
2010 y2 = pi.base.bv->workHeight();
2014 y2 = bv_funcs::getPos(end).y_ + row2.descent();
2015 int const endx = cursorX(end.top(), end.boundary());
2016 X1 = isRTL(par2) ? 0 : endx;
2017 X2 = isRTL(par2) ? endx : 0 + dim_.wid;
2020 lyxerr << " y1: " << y1 << " y2: " << y2
2021 << " xo: " << xo_ << " wid: " << dim_.wid
2024 // paint big rectangle in one go
2025 pi.pain.fillRectangle(x, y1, dim_.wid, y2 - y1, LColor::selection);
2027 // reset background at begin of first selected line
2028 pi.pain.fillRectangle(x + x1, y1, x2 - x1, row1.height(),
2029 LColor::background);
2031 // reset background at end of last selected line
2032 pi.pain.fillRectangle(x + X1, y2 - row2.height(),
2033 X2 - X1, row2.height(), LColor::background);
2038 void LyXText::drawSelection(PainterInfo & pi, int x, int) const
2040 LCursor & cur = pi.base.bv->cursor();
2041 if (!cur.selection())
2043 if (!ptr_cmp(cur.text(), this))
2046 lyxerr[Debug::DEBUG]
2047 << BOOST_CURRENT_FUNCTION
2048 << "draw selection at " << x
2051 DocIterator beg = cur.selectionBegin();
2052 DocIterator end = cur.selectionEnd();
2054 // the selection doesn't touch the visible screen
2055 if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW
2056 || bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE)
2059 Paragraph const & par1 = pars_[beg.pit()];
2060 Paragraph const & par2 = pars_[end.pit()];
2062 bool const above = (bv_funcs::status(pi.base.bv, beg)
2063 == bv_funcs::CUR_ABOVE);
2064 bool const below = (bv_funcs::status(pi.base.bv, end)
2065 == bv_funcs::CUR_BELOW);
2073 Row const & row1 = par1.getRow(beg.pos(), beg.boundary());
2074 y1 = bv_funcs::getPos(beg, beg.boundary()).y_ - row1.ascent();
2075 y2 = y1 + row1.height();
2076 int const startx = cursorX(beg.top(), beg.boundary());
2077 x1 = !isRTL(par1) ? startx : 0;
2078 x2 = !isRTL(par1) ? 0 + dim_.wid : startx;
2083 Y1 = pi.base.bv->workHeight();
2084 Y2 = pi.base.bv->workHeight();
2088 Row const & row2 = par2.getRow(end.pos(), end.boundary());
2089 Y1 = bv_funcs::getPos(end, end.boundary()).y_ - row2.ascent();
2090 Y2 = Y1 + row2.height();
2091 int const endx = cursorX(end.top(), end.boundary());
2092 X1 = !isRTL(par2) ? 0 : endx;
2093 X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
2096 if (!above && !below && &par1.getRow(beg.pos(), beg.boundary())
2097 == &par2.getRow(end.pos(), end.boundary()))
2099 // paint only one rectangle
2100 int const b( !isRTL(par1) ? x + x1 : x + X1 );
2101 int const w( !isRTL(par1) ? X2 - x1 : x2 - X1 );
2102 pi.pain.fillRectangle(b, y1, w, y2 - y1, LColor::selection);
2106 lyxerr[Debug::DEBUG] << " y1: " << y1 << " y2: " << y2
2107 << "X1:" << X1 << " x2: " << X2 << " wid: " << dim_.wid
2110 // paint upper rectangle
2111 pi.pain.fillRectangle(x + x1, y1, x2 - x1, y2 - y1,
2113 // paint bottom rectangle
2114 pi.pain.fillRectangle(x + X1, Y1, X2 - X1, Y2 - Y1,
2116 // paint center rectangle
2117 pi.pain.fillRectangle(x, y2, dim_.wid,
2118 Y1 - y2, LColor::selection);
2122 bool LyXText::isLastRow(pit_type pit, Row const & row) const
2124 return row.endpos() >= pars_[pit].size()
2125 && pit + 1 == pit_type(paragraphs().size());
2129 bool LyXText::isFirstRow(pit_type pit, Row const & row) const
2131 return row.pos() == 0 && pit == 0;
2135 void LyXText::getWord(CursorSlice & from, CursorSlice & to,
2136 word_location const loc)
2138 Paragraph const & from_par = pars_[from.pit()];
2140 case lyx::WHOLE_WORD_STRICT:
2141 if (from.pos() == 0 || from.pos() == from_par.size()
2142 || !from_par.isLetter(from.pos())
2143 || !from_par.isLetter(from.pos() - 1)) {
2147 // no break here, we go to the next
2149 case lyx::WHOLE_WORD:
2150 // If we are already at the beginning of a word, do nothing
2151 if (!from.pos() || !from_par.isLetter(from.pos() - 1))
2153 // no break here, we go to the next
2155 case lyx::PREVIOUS_WORD:
2156 // always move the cursor to the beginning of previous word
2157 while (from.pos() && from_par.isLetter(from.pos() - 1))
2160 case lyx::NEXT_WORD:
2161 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
2164 case lyx::PARTIAL_WORD:
2165 // no need to move the 'from' cursor
2169 Paragraph & to_par = pars_[to.pit()];
2170 while (to.pos() < to_par.size() && to_par.isLetter(to.pos()))
2175 void LyXText::write(Buffer const & buf, std::ostream & os) const
2177 ParagraphList::const_iterator pit = paragraphs().begin();
2178 ParagraphList::const_iterator end = paragraphs().end();
2179 Paragraph::depth_type dth = 0;
2180 for (; pit != end; ++pit)
2181 pit->write(buf, os, buf.params(), dth);
2185 bool LyXText::read(Buffer const & buf, LyXLex & lex, ErrorList & errorList)
2187 Paragraph::depth_type depth = 0;
2189 while (lex.isOK()) {
2191 string const token = lex.getString();
2196 if (token == "\\end_inset") {
2200 if (token == "\\end_body") {
2204 if (token == "\\begin_body") {
2208 if (token == "\\end_document") {
2212 if (token == "\\begin_layout") {
2213 lex.pushToken(token);
2216 par.params().depth(depth);
2217 if (buf.params().tracking_changes)
2219 par.setFont(0, LyXFont(LyXFont::ALL_INHERIT, buf.params().language));
2220 pars_.push_back(par);
2222 // FIXME: goddamn InsetTabular makes us pass a Buffer
2224 ::readParagraph(buf, pars_.back(), lex, errorList);
2226 } else if (token == "\\begin_deeper") {
2228 } else if (token == "\\end_deeper") {
2230 lex.printError("\\end_deeper: " "depth is already null");
2235 lyxerr << "Handling unknown body token: `"
2236 << token << '\'' << endl;
2243 int LyXText::ascent() const
2249 int LyXText::descent() const
2255 int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
2257 pit_type const pit = sl.pit();
2258 Paragraph const & par = pars_[pit];
2259 if (par.rows().empty())
2262 pos_type ppos = sl.pos();
2263 // Correct position in front of big insets
2264 bool const boundary_correction = ppos != 0 && boundary;
2265 if (boundary_correction)
2268 Row const & row = par.getRow(sl.pos(), boundary);
2270 pos_type cursor_vpos = 0;
2272 RowMetrics const m = computeRowMetrics(pit, row);
2275 pos_type const row_pos = row.pos();
2276 pos_type const end = row.endpos();
2279 cursor_vpos = row_pos;
2280 else if (ppos >= end)
2281 cursor_vpos = isRTL(par) ? row_pos : end;
2282 else if (ppos > row_pos && ppos >= end)
2283 // Place cursor after char at (logical) position pos - 1
2284 cursor_vpos = (bidi.level(ppos - 1) % 2 == 0)
2285 ? bidi.log2vis(ppos - 1) + 1 : bidi.log2vis(ppos - 1);
2287 // Place cursor before char at (logical) position ppos
2288 cursor_vpos = (bidi.level(ppos) % 2 == 0)
2289 ? bidi.log2vis(ppos) : bidi.log2vis(ppos) + 1;
2291 pos_type body_pos = par.beginOfBody();
2293 (body_pos > end || !par.isLineSeparator(body_pos - 1)))
2296 // Use font span to speed things up, see below
2300 for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
2301 pos_type pos = bidi.vis2log(vpos);
2302 if (body_pos > 0 && pos == body_pos - 1) {
2303 string lsep = par.layout()->labelsep;
2304 docstring dlsep(lsep.begin(), lsep.end());
2306 + font_metrics::width(dlsep,
2308 if (par.isLineSeparator(body_pos - 1))
2309 x -= singleWidth(par, body_pos - 1);
2312 // Use font span to speed things up, see above
2313 if (pos < font_span.first || pos > font_span.last) {
2314 font_span = par.fontSpan(pos);
2315 font = getFont(par, pos);
2318 x += singleWidth(par, pos, par.getChar(pos), font);
2320 if (hfillExpansion(par, row, pos))
2321 x += (pos >= body_pos) ? m.hfill : m.label_hfill;
2322 else if (par.isSeparator(pos) && pos >= body_pos)
2326 // see correction above
2327 if (boundary_correction)
2328 if (getFont(par, ppos).isVisibleRightToLeft())
2329 x -= singleWidth(par, ppos);
2331 x += singleWidth(par, ppos);
2333 // Make sure inside an inset we always count from the left
2334 // edge (bidi!) -- MV
2335 if (sl.pos() < par.size()) {
2336 font = getFont(par, sl.pos());
2337 if (!boundary && font.isVisibleRightToLeft()
2338 && par.isInset(sl.pos()))
2339 x -= par.getInset(sl.pos())->width();
2345 int LyXText::cursorY(CursorSlice const & sl, bool boundary) const
2347 //lyxerr << "LyXText::cursorY: boundary: " << boundary << std::endl;
2348 Paragraph const & par = getPar(sl.pit());
2349 if (par.rows().empty())
2353 h -= pars_[0].rows()[0].ascent();
2354 for (pit_type pit = 0; pit < sl.pit(); ++pit)
2355 h += pars_[pit].height();
2357 if (pos && boundary)
2359 size_t const rend = par.pos2row(pos);
2360 for (size_t rit = 0; rit != rend; ++rit)
2361 h += par.rows()[rit].height();
2362 h += par.rows()[rend].ascent();
2367 // Returns the current font and depth as a message.
2368 string LyXText::currentState(LCursor & cur)
2370 BOOST_ASSERT(this == cur.text());
2371 Buffer & buf = cur.buffer();
2372 Paragraph const & par = cur.paragraph();
2373 std::ostringstream os;
2375 bool const show_change = buf.params().tracking_changes
2376 && par.lookupChange(cur.pos()) != Change::UNCHANGED;
2378 if (buf.params().tracking_changes)
2382 Change change = par.lookupChange(cur.pos());
2383 Author const & a = buf.params().authors().get(change.author);
2384 os << lyx::to_utf8(_("Change: ")) << a.name();
2385 if (!a.email().empty())
2386 os << " (" << a.email() << ")";
2387 if (change.changetime)
2388 os << lyx::to_utf8(_(" at ")) << ctime(&change.changetime);
2392 // I think we should only show changes from the default
2394 // No, from the document font (MV)
2395 LyXFont font = real_current_font;
2396 font.reduce(buf.params().getFont());
2398 // avoid lyx::to_utf8(_(...)) re-entrance problem
2399 string const s = font.stateText(&buf.params());
2400 os << lyx::to_utf8(bformat(_("Font: %1$s"), lyx::from_utf8(s)));
2402 // os << lyx::to_utf8(bformat(_("Font: %1$s"), font.stateText(&buf.params)));
2404 // The paragraph depth
2405 int depth = cur.paragraph().getDepth();
2407 os << lyx::to_utf8(bformat(_(", Depth: %1$d"), depth));
2409 // The paragraph spacing, but only if different from
2411 Spacing const & spacing = par.params().spacing();
2412 if (!spacing.isDefault()) {
2413 os << lyx::to_utf8(_(", Spacing: "));
2414 switch (spacing.getSpace()) {
2415 case Spacing::Single:
2416 os << lyx::to_utf8(_("Single"));
2418 case Spacing::Onehalf:
2419 os << lyx::to_utf8(_("OneHalf"));
2421 case Spacing::Double:
2422 os << lyx::to_utf8(_("Double"));
2424 case Spacing::Other:
2425 os << lyx::to_utf8(_("Other (")) << spacing.getValueAsString() << ')';
2427 case Spacing::Default:
2428 // should never happen, do nothing
2433 #ifdef DEVEL_VERSION
2434 os << lyx::to_utf8(_(", Inset: ")) << &cur.inset();
2435 os << lyx::to_utf8(_(", Paragraph: ")) << cur.pit();
2436 os << lyx::to_utf8(_(", Id: ")) << par.id();
2437 os << lyx::to_utf8(_(", Position: ")) << cur.pos();
2438 os << lyx::to_utf8(_(", Boundary: ")) << cur.boundary();
2439 // Row & row = cur.textRow();
2440 // os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
2446 string LyXText::getPossibleLabel(LCursor & cur) const
2448 pit_type pit = cur.pit();
2450 LyXLayout_ptr layout = pars_[pit].layout();
2452 if (layout->latextype == LATEX_PARAGRAPH && pit != 0) {
2453 LyXLayout_ptr const & layout2 = pars_[pit - 1].layout();
2454 if (layout2->latextype != LATEX_PARAGRAPH) {
2460 string name = layout->latexname();
2462 // for captions, we want the abbreviation of the float type
2463 if (layout->labeltype == LABEL_SENSITIVE) {
2464 // Search for the first float or wrap inset in the iterator
2465 size_t i = cur.depth();
2468 InsetBase * const in = &cur[i].inset();
2469 if (in->lyxCode() == InsetBase::FLOAT_CODE
2470 || in->lyxCode() == InsetBase::WRAP_CODE) {
2471 name = in->getInsetName();
2477 string text = name.substr(0, 3);
2478 if (name == "theorem")
2479 text = "thm"; // Create a correct prefix for prettyref
2482 if (layout->latextype == LATEX_PARAGRAPH || lyxrc.label_init_length < 0)
2485 string par_text = pars_[pit].asString(cur.buffer(), false);
2486 for (int i = 0; i < lyxrc.label_init_length; ++i) {
2487 if (par_text.empty())
2490 par_text = split(par_text, head, ' ');
2491 // Is it legal to use spaces in labels ?
2501 //pos_type LyXText::x2pos(pit_type pit, int row, int x) const
2505 // Paragraph const & par = pars_[pit];
2506 // Row const & r = par.rows()[row];
2507 // int pos = r.pos();
2508 // for (; currx < x && pos < r.endpos(); ++pos) {
2510 // currx += singleWidth(par, pos);
2512 // if (abs(lastx - x) < abs(currx - x) && pos != r.pos())
2518 pos_type LyXText::x2pos(pit_type pit, int row, int x) const
2520 BOOST_ASSERT(row < int(pars_[pit].rows().size()));
2522 Row const & r = pars_[pit].rows()[row];
2523 return r.pos() + getColumnNearX(pit, r, x, bound);
2527 //int LyXText::pos2x(pit_type pit, pos_type pos) const
2529 // Paragraph const & par = pars_[pit];
2530 // Row const & r = par.rows()[row];
2536 // x,y are screen coordinates
2537 // sets cursor only within this LyXText
2538 bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
2540 BOOST_ASSERT(this == cur.text());
2541 pit_type pit = getPitNearY(y);
2542 int yy = theCoords.get(this, pit).y_ - pars_[pit].ascent();
2543 lyxerr[Debug::DEBUG]
2544 << BOOST_CURRENT_FUNCTION
2548 << " yy: " << yy << endl;
2550 Paragraph const & par = pars_[pit];
2552 BOOST_ASSERT(par.rows().size());
2553 for (; r < int(par.rows().size()) - 1; ++r) {
2554 Row const & row = par.rows()[r];
2555 if (int(yy + row.height()) > y)
2560 Row const & row = par.rows()[r];
2562 lyxerr[Debug::DEBUG]
2563 << BOOST_CURRENT_FUNCTION
2565 << " from pos: " << row.pos()
2570 pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
2572 lyxerr[Debug::DEBUG]
2573 << BOOST_CURRENT_FUNCTION
2574 << ": setting cursor pit: " << pit
2578 return setCursor(cur, pit, pos, true, bound);