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/FontMetrics.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;
92 using lyx::frontend::FontMetrics;
105 int numberOfSeparators(Paragraph const & par, Row const & row)
107 pos_type const first = max(row.pos(), par.beginOfBody());
108 pos_type const last = row.endpos() - 1;
110 for (pos_type p = first; p < last; ++p) {
111 if (par.isSeparator(p))
118 int numberOfLabelHfills(Paragraph const & par, Row const & row)
120 pos_type last = row.endpos() - 1;
121 pos_type first = row.pos();
123 // hfill *DO* count at the beginning of paragraphs!
125 while (first < last && par.isHfill(first))
129 last = min(last, par.beginOfBody());
131 for (pos_type p = first; p < last; ++p) {
139 int numberOfHfills(Paragraph const & par, Row const & row)
141 pos_type const last = row.endpos();
142 pos_type first = row.pos();
144 // hfill *DO* count at the beginning of paragraphs!
146 while (first < last && par.isHfill(first))
150 first = max(first, par.beginOfBody());
153 for (pos_type p = first; p < last; ++p) {
161 void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
162 string const & token, LyXFont & font, Change & change, ErrorList & errorList)
164 BufferParams const & bp = buf.params();
166 if (token[0] != '\\') {
168 string::const_iterator cit = token.begin();
169 for (; cit != token.end(); ++cit)
170 par.insertChar(par.size(), (*cit), font, change);
172 lyx::docstring dstr = lex.getDocString();
173 lyx::docstring::const_iterator cit = dstr.begin();
174 lyx::docstring::const_iterator cend = dstr.end();
175 for (; cit != cend; ++cit)
176 par.insertChar(par.size(), *cit, font, change);
178 } else if (token == "\\begin_layout") {
180 string layoutname = lex.getString();
182 font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
183 change = Change(Change::UNCHANGED);
185 LyXTextClass const & tclass = bp.getLyXTextClass();
187 if (layoutname.empty()) {
188 layoutname = tclass.defaultLayoutName();
191 bool hasLayout = tclass.hasLayout(layoutname);
194 errorList.push_back(ErrorItem(_("Unknown layout"),
195 bformat(_("Layout '%1$s' does not exist in textclass '%2$s'\nTrying to use the default instead.\n"),
196 lyx::from_utf8(layoutname), lyx::from_utf8(tclass.name())), par.id(), 0, par.size()));
197 layoutname = tclass.defaultLayoutName();
200 par.layout(bp.getLyXTextClass()[layoutname]);
202 // Test whether the layout is obsolete.
203 LyXLayout_ptr const & layout = par.layout();
204 if (!layout->obsoleted_by().empty())
205 par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
207 par.params().read(lex);
209 } else if (token == "\\end_layout") {
210 lyxerr << BOOST_CURRENT_FUNCTION
211 << ": Solitary \\end_layout in line "
212 << lex.getLineNo() << "\n"
213 << "Missing \\begin_layout?.\n";
214 } else if (token == "\\end_inset") {
215 lyxerr << BOOST_CURRENT_FUNCTION
216 << ": Solitary \\end_inset in line "
217 << lex.getLineNo() << "\n"
218 << "Missing \\begin_inset?.\n";
219 } else if (token == "\\begin_inset") {
220 InsetBase * inset = readInset(lex, buf);
222 par.insertInset(par.size(), inset, font, change);
225 docstring line = lyx::from_utf8(lex.getString());
226 errorList.push_back(ErrorItem(_("Unknown Inset"), line,
227 par.id(), 0, par.size()));
229 } else if (token == "\\family") {
231 font.setLyXFamily(lex.getString());
232 } else if (token == "\\series") {
234 font.setLyXSeries(lex.getString());
235 } else if (token == "\\shape") {
237 font.setLyXShape(lex.getString());
238 } else if (token == "\\size") {
240 font.setLyXSize(lex.getString());
241 } else if (token == "\\lang") {
243 string const tok = lex.getString();
244 Language const * lang = languages.getLanguage(tok);
246 font.setLanguage(lang);
248 font.setLanguage(bp.language);
249 lex.printError("Unknown language `$$Token'");
251 } else if (token == "\\numeric") {
253 font.setNumber(font.setLyXMisc(lex.getString()));
254 } else if (token == "\\emph") {
256 font.setEmph(font.setLyXMisc(lex.getString()));
257 } else if (token == "\\bar") {
259 string const tok = lex.getString();
262 font.setUnderbar(LyXFont::ON);
263 else if (tok == "no")
264 font.setUnderbar(LyXFont::OFF);
265 else if (tok == "default")
266 font.setUnderbar(LyXFont::INHERIT);
268 lex.printError("Unknown bar font flag "
270 } else if (token == "\\noun") {
272 font.setNoun(font.setLyXMisc(lex.getString()));
273 } else if (token == "\\color") {
275 font.setLyXColor(lex.getString());
276 } else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
278 // Insets don't make sense in a free-spacing context! ---Kayvan
279 if (par.isFreeSpacing()) {
280 if (token == "\\InsetSpace")
281 par.insertChar(par.size(), ' ', font, change);
282 else if (lex.isOK()) {
284 string const next_token = lex.getString();
285 if (next_token == "\\-")
286 par.insertChar(par.size(), '-', font, change);
288 lex.printError("Token `$$Token' "
290 "paragraph layout!");
294 auto_ptr<InsetBase> inset;
295 if (token == "\\SpecialChar" )
296 inset.reset(new InsetSpecialChar);
298 inset.reset(new InsetSpace);
299 inset->read(buf, lex);
300 par.insertInset(par.size(), inset.release(),
303 } else if (token == "\\i") {
304 auto_ptr<InsetBase> inset(new InsetLatexAccent);
305 inset->read(buf, lex);
306 par.insertInset(par.size(), inset.release(), font, change);
307 } else if (token == "\\backslash") {
308 par.insertChar(par.size(), '\\', font, change);
309 } else if (token == "\\newline") {
310 auto_ptr<InsetBase> inset(new InsetNewline);
311 inset->read(buf, lex);
312 par.insertInset(par.size(), inset.release(), font, change);
313 } else if (token == "\\LyXTable") {
314 auto_ptr<InsetBase> inset(new InsetTabular(buf));
315 inset->read(buf, lex);
316 par.insertInset(par.size(), inset.release(), font, change);
317 } else if (token == "\\hfill") {
318 par.insertInset(par.size(), new InsetHFill, font, change);
319 } else if (token == "\\lyxline") {
320 par.insertInset(par.size(), new InsetLine, font, change);
321 } else if (token == "\\newpage") {
322 par.insertInset(par.size(), new InsetPagebreak, font, change);
323 } else if (token == "\\change_unchanged") {
324 // Hack ! Needed for empty paragraphs :/
325 // FIXME: change tracking (MG)
326 // set empty 'par' to INSERTED???
327 change = Change(Change::UNCHANGED);
328 } else if (token == "\\change_inserted") {
330 std::istringstream is(lex.getString());
334 if (aid >= bp.author_map.size()) {
335 errorList.push_back(ErrorItem(_("Change tracking error"),
336 bformat(_("Unknown author index for insertion: %1$d\n"), aid),
337 par.id(), 0, par.size()));
339 change = Change(Change::UNCHANGED);
341 change = Change(Change::INSERTED, bp.author_map[aid], ct);
342 } else if (token == "\\change_deleted") {
344 std::istringstream is(lex.getString());
348 if (aid >= bp.author_map.size()) {
349 errorList.push_back(ErrorItem(_("Change tracking error"),
350 bformat(_("Unknown author index for deletion: %1$d\n"), aid),
351 par.id(), 0, par.size()));
353 change = Change(Change::UNCHANGED);
355 change = Change(Change::DELETED, bp.author_map[aid], ct);
358 errorList.push_back(ErrorItem(_("Unknown token"),
359 bformat(_("Unknown token: %1$s %2$s\n"), lyx::from_utf8(token),
360 lyx::from_utf8(lex.getString())),
361 par.id(), 0, par.size()));
366 void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex, ErrorList & errorList)
369 string token = lex.getString();
371 Change change(Change::UNCHANGED);
375 readParToken(buf, par, lex, token, font, change, errorList);
378 token = lex.getString();
383 if (token == "\\end_layout") {
384 //Ok, paragraph finished
388 lyxerr[Debug::PARSER] << "Handling paragraph token: `"
389 << token << '\'' << endl;
390 if (token == "\\begin_layout" || token == "\\end_document"
391 || token == "\\end_inset" || token == "\\begin_deeper"
392 || token == "\\end_deeper") {
393 lex.pushToken(token);
394 lyxerr << "Paragraph ended in line "
395 << lex.getLineNo() << "\n"
396 << "Missing \\end_layout.\n";
400 // Final change goes to paragraph break:
401 par.setChange(par.size(), change);
403 // Initialize begin_of_body_ on load; redoParagraph maintains
404 par.setBeginOfBody();
412 BufferView * LyXText::bv() const
414 BOOST_ASSERT(bv_owner != 0);
419 double LyXText::spacing(Paragraph const & par) const
421 if (par.params().spacing().isDefault())
422 return bv()->buffer()->params().spacing().getValue();
423 return par.params().spacing().getValue();
427 int LyXText::width() const
433 int LyXText::height() const
435 return dim_.height();
439 int LyXText::singleWidth(Paragraph const & par, pos_type pos) const
441 return singleWidth(par, pos, par.getChar(pos), getFont(par, pos));
445 int LyXText::singleWidth(Paragraph const & par,
446 pos_type pos, char_type c, LyXFont const & font) const
448 // The most common case is handled first (Asger)
449 if (isPrintable(c)) {
450 Language const * language = font.language();
451 if (language->rightToLeft()) {
452 if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
453 lyxrc.font_norm_type == LyXRC::ISO_10646_1)
454 && language->lang() == "arabic") {
455 if (Encodings::isComposeChar_arabic(c))
457 c = par.transformChar(c, pos);
458 } else if (language->lang() == "hebrew" &&
459 Encodings::isComposeChar_hebrew(c))
462 return theFontMetrics(font).width(c);
465 if (c == Paragraph::META_INSET)
466 return par.getInset(pos)->width();
468 return theFontMetrics(font).width(c);
472 int LyXText::leftMargin(pit_type pit) const
474 BOOST_ASSERT(pit >= 0);
475 BOOST_ASSERT(pit < int(pars_.size()));
476 return leftMargin(pit, pars_[pit].size());
480 int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
482 BOOST_ASSERT(pit >= 0);
483 BOOST_ASSERT(pit < int(pars_.size()));
484 Paragraph const & par = pars_[pit];
485 BOOST_ASSERT(pos >= 0);
486 BOOST_ASSERT(pos <= par.size());
487 //lyxerr << "LyXText::leftMargin: pit: " << pit << " pos: " << pos << endl;
488 BufferParams const & params = bv()->buffer()->params();
489 LyXTextClass const & tclass = params.getLyXTextClass();
490 LyXLayout_ptr const & layout = par.layout();
492 string parindent = layout->parindent;
497 l_margin += changebarMargin();
500 docstring leftm = lyx::from_utf8(tclass.leftmargin());
501 l_margin += theFontMetrics(params.getFont()).signedWidth(leftm);
503 if (par.getDepth() != 0) {
504 // find the next level paragraph
505 pit_type newpar = outerHook(pit, pars_);
506 if (newpar != pit_type(pars_.size())) {
507 if (pars_[newpar].layout()->isEnvironment()) {
508 l_margin = leftMargin(newpar);
510 if (par.layout() == tclass.defaultLayout()) {
511 if (pars_[newpar].params().noindent())
514 parindent = pars_[newpar].layout()->parindent;
519 // This happens after sections in standard classes. The 1.3.x
520 // code compared depths too, but it does not seem necessary
522 if (par.layout() == tclass.defaultLayout()
523 && pit > 0 && pars_[pit - 1].layout()->nextnoindent)
526 LyXFont const labelfont = getLabelFont(par);
527 FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
529 switch (layout->margintype) {
531 if (!layout->leftmargin.empty()) {
533 docstring leftm = lyx::from_utf8(layout->leftmargin);
534 l_margin += theFontMetrics(params.getFont()).signedWidth(leftm);
536 if (!par.getLabelstring().empty()) {
538 docstring labin = lyx::from_utf8(layout->labelindent);
539 l_margin += labelfont_metrics.signedWidth(labin);
540 docstring labstr = lyx::from_utf8(par.getLabelstring());
541 l_margin += labelfont_metrics.width(labstr);
542 docstring labsep = lyx::from_utf8(layout->labelsep);
543 l_margin += labelfont_metrics.width(labsep);
547 case MARGIN_MANUAL: {
549 docstring labin = lyx::from_utf8(layout->labelindent);
550 l_margin += labelfont_metrics.signedWidth(labin);
551 // The width of an empty par, even with manual label, should be 0
552 if (!par.empty() && pos >= par.beginOfBody()) {
553 if (!par.getLabelWidthString().empty()) {
554 docstring labstr = lyx::from_utf8(par.getLabelWidthString());
555 l_margin += labelfont_metrics.width(labstr);
556 docstring labsep = lyx::from_utf8(layout->labelsep);
557 l_margin += labelfont_metrics.width(labsep);
563 case MARGIN_STATIC: {
565 docstring leftm = lyx::from_utf8(layout->leftmargin);
566 l_margin += theFontMetrics(params.getFont()).signedWidth(leftm)
567 * 4 / (par.getDepth() + 4);
571 case MARGIN_FIRST_DYNAMIC:
572 if (layout->labeltype == LABEL_MANUAL) {
573 if (pos >= par.beginOfBody()) {
575 l_margin += labelfont_metrics.signedWidth(
576 lyx::from_utf8(layout->leftmargin));
579 l_margin += labelfont_metrics.signedWidth(
580 lyx::from_utf8(layout->labelindent));
583 // Special case to fix problems with
585 || (layout->labeltype == LABEL_STATIC
586 && layout->latextype == LATEX_ENVIRONMENT
587 && !isFirstInSequence(pit, pars_))) {
589 l_margin += labelfont_metrics.signedWidth(lyx::from_utf8(layout->leftmargin));
590 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
591 && layout->labeltype != LABEL_BIBLIO
592 && layout->labeltype !=
593 LABEL_CENTERED_TOP_ENVIRONMENT) {
594 l_margin += labelfont_metrics.signedWidth(lyx::from_utf8(layout->labelindent));
595 l_margin += labelfont_metrics.width(lyx::from_utf8(layout->labelsep));
596 l_margin += labelfont_metrics.width(lyx::from_utf8(par.getLabelstring()));
600 case MARGIN_RIGHT_ADDRESS_BOX: {
602 // ok, a terrible hack. The left margin depends on the widest
603 // row in this paragraph.
604 RowList::iterator rit = par.rows().begin();
605 RowList::iterator end = par.rows().end();
607 #warning This is wrong.
609 int minfill = maxwidth_;
610 for ( ; rit != end; ++rit)
611 if (rit->fill() < minfill)
612 minfill = rit->fill();
613 l_margin += theFontMetrics(params.getFont()).signedWidth(layout->leftmargin);
616 // also wrong, but much shorter.
617 l_margin += maxwidth_ / 2;
622 if (!par.params().leftIndent().zero())
623 l_margin += par.params().leftIndent().inPixels(maxwidth_);
627 if (par.params().align() == LYX_ALIGN_LAYOUT)
628 align = layout->align;
630 align = par.params().align();
632 // set the correct parindent
634 && (layout->labeltype == LABEL_NO_LABEL
635 || layout->labeltype == LABEL_TOP_ENVIRONMENT
636 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
637 || (layout->labeltype == LABEL_STATIC
638 && layout->latextype == LATEX_ENVIRONMENT
639 && !isFirstInSequence(pit, pars_)))
640 && align == LYX_ALIGN_BLOCK
641 && !par.params().noindent()
642 // in some insets, paragraphs are never indented
643 && !(par.inInset() && par.inInset()->neverIndent())
644 // display style insets are always centered, omit indentation
647 && par.getInset(pos)->display())
648 && (par.layout() != tclass.defaultLayout()
649 || bv()->buffer()->params().paragraph_separation ==
650 BufferParams::PARSEP_INDENT))
652 docstring din = lyx::from_utf8(parindent);
653 l_margin += theFontMetrics(params.getFont()).signedWidth(din);
660 int LyXText::rightMargin(Paragraph const & par) const
662 // FIXME: the correct way is to only call rightMargin() only
663 // within the main LyXText. The following test is thus bogus.
664 LyXText const & text = bv()->buffer()->text();
665 // We do not want rightmargins on inner texts.
669 BufferParams const & params = bv()->buffer()->params();
670 LyXTextClass const & tclass = params.getLyXTextClass();
671 docstring trmarg = lyx::from_utf8(tclass.rightmargin());
672 docstring lrmarg = lyx::from_utf8(par.layout()->rightmargin);
673 FontMetrics const & fm = theFontMetrics(params.getFont());
676 + fm.signedWidth(trmarg)
677 + fm.signedWidth(lrmarg)
678 * 4 / (par.getDepth() + 4);
684 int LyXText::labelEnd(pit_type const pit) const
686 // labelEnd is only needed if the layout fills a flushleft label.
687 if (pars_[pit].layout()->margintype != MARGIN_MANUAL)
689 // return the beginning of the body
690 return leftMargin(pit);
696 // this needs special handling - only newlines count as a break point
697 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
699 pos_type const end = par.size();
702 if (par.isNewline(i))
711 void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
713 Paragraph const & par = pars_[pit];
714 pos_type const end = par.size();
715 pos_type const pos = row.pos();
721 // maximum pixel width of a row
722 int width = maxwidth_ - rightMargin(par); // - leftMargin(pit, row);
728 LyXLayout_ptr const & layout = par.layout();
730 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
731 row.endpos(addressBreakPoint(pos, par));
735 pos_type const body_pos = par.beginOfBody();
738 // Now we iterate through until we reach the right margin
739 // or the end of the par, then choose the possible break
742 int const left = leftMargin(pit, pos);
745 // pixel width since last breakpoint
748 FontIterator fi = FontIterator(*this, par, pos);
749 pos_type point = end;
751 FontMetrics const & fm = theFontMetrics(getLabelFont(par));
752 for ( ; i < end; ++i, ++fi) {
753 char_type const c = par.getChar(i);
754 int thiswidth = singleWidth(par, i, c, *fi);
756 // add the auto-hfill from label end to the body
757 if (body_pos && i == body_pos) {
758 docstring lsep = lyx::from_utf8(layout->labelsep);
759 int add = fm.width(lsep);
760 if (par.isLineSeparator(i - 1))
761 add -= singleWidth(par, i - 1);
763 add = std::max(add, labelEnd(pit) - x);
768 chunkwidth += thiswidth;
770 // break before a character that will fall off
771 // the right of the row
773 // if no break before, break here
774 if (point == end || chunkwidth >= width - left) {
781 // exit on last registered breakpoint:
785 if (par.isNewline(i)) {
791 if (par.isInset(i + 1) && par.getInset(i + 1)->display()) {
796 if (par.isInset(i) && par.getInset(i)->display()) {
802 if (!par.isInset(i) || par.getInset(i)->isChar()) {
803 // some insets are line separators too
804 if (par.isLineSeparator(i)) {
805 // register breakpoint:
812 // maybe found one, but the par is short enough.
813 if (i == end && x < width)
816 // manual labels cannot be broken in LaTeX. But we
817 // want to make our on-screen rendering of footnotes
819 if (body_pos && point < body_pos)
826 void LyXText::setRowWidth(pit_type const pit, Row & row) const
828 // get the pure distance
829 pos_type const end = row.endpos();
831 Paragraph const & par = pars_[pit];
832 docstring const labelsep = lyx::from_utf8(par.layout()->labelsep);
833 int w = leftMargin(pit, row.pos());
835 pos_type const body_pos = par.beginOfBody();
836 pos_type i = row.pos();
838 FontMetrics const & fm = theFontMetrics(getLabelFont(par));
841 FontIterator fi = FontIterator(*this, par, i);
842 for ( ; i < end; ++i, ++fi) {
843 if (body_pos > 0 && i == body_pos) {
844 w += fm.width(labelsep);
845 if (par.isLineSeparator(i - 1))
846 w -= singleWidth(par, i - 1);
847 w = max(w, labelEnd(pit));
849 char_type const c = par.getChar(i);
850 w += singleWidth(par, i, c, *fi);
854 if (body_pos > 0 && body_pos >= end) {
855 w += fm.width(labelsep);
856 if (end > 0 && par.isLineSeparator(end - 1))
857 w -= singleWidth(par, end - 1);
858 w = max(w, labelEnd(pit));
861 row.width(w + rightMargin(par));
865 // returns the minimum space a manual label needs on the screen in pixel
866 int LyXText::labelFill(Paragraph const & par, Row const & row) const
868 pos_type last = par.beginOfBody();
870 BOOST_ASSERT(last > 0);
872 // -1 because a label ends with a space that is in the label
875 // a separator at this end does not count
876 if (par.isLineSeparator(last))
880 for (pos_type i = row.pos(); i <= last; ++i)
881 w += singleWidth(par, i);
883 string const & label = par.params().labelWidthString();
887 FontMetrics const & fm = theFontMetrics(getLabelFont(par));
890 return max(0, fm.width(lyx::from_utf8(label)) - w);
894 LColor_color LyXText::backgroundColor() const
896 return LColor_color(LColor::color(background_color_));
900 void LyXText::setHeightOfRow(pit_type const pit, Row & row)
902 Paragraph const & par = pars_[pit];
903 // get the maximum ascent and the maximum descent
904 double layoutasc = 0;
905 double layoutdesc = 0;
906 double const dh = defaultRowHeight();
908 // ok, let us initialize the maxasc and maxdesc value.
909 // Only the fontsize count. The other properties
910 // are taken from the layoutfont. Nicer on the screen :)
911 LyXLayout_ptr const & layout = par.layout();
913 // as max get the first character of this row then it can
914 // increase but not decrease the height. Just some point to
915 // start with so we don't have to do the assignment below too
917 LyXFont font = getFont(par, row.pos());
918 LyXFont::FONT_SIZE const tmpsize = font.size();
919 font = getLayoutFont(pit);
920 LyXFont::FONT_SIZE const size = font.size();
921 font.setSize(tmpsize);
923 LyXFont labelfont = getLabelFont(par);
925 FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
926 FontMetrics const & fontmetrics = theFontMetrics(font);
928 // these are minimum values
929 double const spacing_val = layout->spacing.getValue() * spacing(par);
930 //lyxerr << "spacing_val = " << spacing_val << endl;
931 int maxasc = int(fontmetrics.maxAscent() * spacing_val);
932 int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
934 // insets may be taller
935 InsetList::const_iterator ii = par.insetlist.begin();
936 InsetList::const_iterator iend = par.insetlist.end();
937 for ( ; ii != iend; ++ii) {
938 if (ii->pos >= row.pos() && ii->pos < row.endpos()) {
939 maxasc = max(maxasc, ii->inset->ascent());
940 maxdesc = max(maxdesc, ii->inset->descent());
944 // Check if any custom fonts are larger (Asger)
945 // This is not completely correct, but we can live with the small,
946 // cosmetic error for now.
948 pos_type const pos_end = row.endpos();
950 LyXFont::FONT_SIZE maxsize =
951 par.highestFontInRange(row.pos(), pos_end, size);
952 if (maxsize > font.size()) {
953 font.setSize(maxsize);
954 maxasc = max(maxasc, fontmetrics.maxAscent());
955 maxdesc = max(maxdesc, fontmetrics.maxDescent());
958 // This is nicer with box insets:
965 if (row.pos() == 0) {
966 BufferParams const & bufparams = bv()->buffer()->params();
967 // some parksips VERY EASY IMPLEMENTATION
968 if (bv()->buffer()->params().paragraph_separation
969 == BufferParams::PARSEP_SKIP
971 && ((layout->isParagraph() && par.getDepth() == 0)
972 || (pars_[pit - 1].layout()->isParagraph()
973 && pars_[pit - 1].getDepth() == 0)))
975 maxasc += bufparams.getDefSkip().inPixels(*bv());
978 if (par.params().startOfAppendix())
979 maxasc += int(3 * dh);
981 // This is special code for the chapter, since the label of this
982 // layout is printed in an extra row
983 if (layout->counter == "chapter"
984 && !par.params().labelString().empty()) {
985 labeladdon = int(labelfont_metrics.maxHeight()
986 * layout->spacing.getValue()
990 // special code for the top label
991 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
992 || layout->labeltype == LABEL_BIBLIO
993 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
994 && isFirstInSequence(pit, paragraphs())
995 && !par.getLabelstring().empty())
998 labelfont_metrics.maxHeight()
999 * layout->spacing.getValue()
1001 + (layout->topsep + layout->labelbottomsep) * dh);
1004 // Add the layout spaces, for example before and after
1005 // a section, or between the items of a itemize or enumerate
1008 pit_type prev = depthHook(pit, pars_, par.getDepth());
1010 && pars_[prev].layout() == layout
1011 && pars_[prev].getDepth() == par.getDepth()
1012 && pars_[prev].getLabelWidthString() == par.getLabelWidthString())
1014 layoutasc = layout->itemsep * dh;
1015 } else if (pit != 0 || row.pos() != 0) {
1016 if (layout->topsep > 0)
1017 layoutasc = layout->topsep * dh;
1020 prev = outerHook(pit, pars_);
1021 if (prev != pit_type(pars_.size())) {
1022 maxasc += int(pars_[prev].layout()->parsep * dh);
1023 } else if (pit != 0) {
1024 if (pars_[pit - 1].getDepth() != 0 ||
1025 pars_[pit - 1].layout() == layout) {
1026 maxasc += int(layout->parsep * dh);
1031 // is it a bottom line?
1032 if (row.endpos() >= par.size()) {
1033 // add the layout spaces, for example before and after
1034 // a section, or between the items of a itemize or enumerate
1036 pit_type nextpit = pit + 1;
1037 if (nextpit != pit_type(pars_.size())) {
1038 pit_type cpit = pit;
1042 if (pars_[cpit].getDepth() > pars_[nextpit].getDepth()) {
1043 usual = pars_[cpit].layout()->bottomsep * dh;
1044 cpit = depthHook(cpit, paragraphs(), pars_[nextpit].getDepth());
1045 if (pars_[cpit].layout() != pars_[nextpit].layout()
1046 || pars_[nextpit].getLabelWidthString() != pars_[cpit].getLabelWidthString())
1048 unusual = pars_[cpit].layout()->bottomsep * dh;
1050 layoutdesc = max(unusual, usual);
1051 } else if (pars_[cpit].getDepth() == pars_[nextpit].getDepth()) {
1052 if (pars_[cpit].layout() != pars_[nextpit].layout()
1053 || pars_[nextpit].getLabelWidthString() != pars_[cpit].getLabelWidthString())
1054 layoutdesc = int(pars_[cpit].layout()->bottomsep * dh);
1059 // incalculate the layout spaces
1060 maxasc += int(layoutasc * 2 / (2 + pars_[pit].getDepth()));
1061 maxdesc += int(layoutdesc * 2 / (2 + pars_[pit].getDepth()));
1063 // FIXME: the correct way is to do the following is to move the
1064 // following code in another method specially tailored for the
1065 // main LyXText. The following test is thus bogus.
1066 LyXText const & text = bv_owner->buffer()->text();
1067 // Top and bottom margin of the document (only at top-level)
1068 if (&text == this) {
1069 if (pit == 0 && row.pos() == 0)
1071 if (pit + 1 == pit_type(pars_.size()) &&
1072 row.endpos() == par.size())
1076 row.ascent(maxasc + labeladdon);
1077 row.descent(maxdesc);
1085 void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
1087 BOOST_ASSERT(this == cur.text());
1089 Paragraph & cpar = cur.paragraph();
1090 pit_type cpit = cur.pit();
1092 LyXTextClass const & tclass = cur.buffer().params().getLyXTextClass();
1093 LyXLayout_ptr const & layout = cpar.layout();
1095 // this is only allowed, if the current paragraph is not empty
1096 // or caption and if it has not the keepempty flag active
1097 if (cur.lastpos() == 0 && !cpar.allowEmpty()
1098 && layout->labeltype != LABEL_SENSITIVE)
1101 // a layout change may affect also the following paragraph
1102 recUndo(cur.pit(), undoSpan(cur.pit()) - 1);
1104 // Always break behind a space
1105 // It is better to erase the space (Dekel)
1106 if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos()))
1107 cpar.erase(cur.pos());
1109 // How should the layout for the new paragraph be?
1110 int preserve_layout = 0;
1112 preserve_layout = 2;
1114 preserve_layout = layout->isEnvironment();
1116 // We need to remember this before we break the paragraph, because
1117 // that invalidates the layout variable
1118 bool sensitive = layout->labeltype == LABEL_SENSITIVE;
1120 // we need to set this before we insert the paragraph.
1121 bool const isempty = cpar.allowEmpty() && cpar.empty();
1123 ::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
1124 cur.pos(), preserve_layout);
1126 // After this, neither paragraph contains any rows!
1129 pit_type next_par = cpit + 1;
1131 // well this is the caption hack since one caption is really enough
1134 // set to standard-layout
1135 pars_[cpit].applyLayout(tclass.defaultLayout());
1137 // set to standard-layout
1138 pars_[next_par].applyLayout(tclass.defaultLayout());
1141 while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
1142 pars_[next_par].erase(0);
1144 ParIterator current_it(cur);
1145 ParIterator last_it(cur);
1149 updateLabels(cur.buffer(), current_it, last_it);
1151 // Mark "carriage return" as inserted if change tracking:
1152 if (cur.buffer().params().trackChanges) {
1153 // FIXME: Change tracking (MG)
1154 cur.paragraph().setChange(cur.paragraph().size(),
1155 Change(Change::INSERTED));
1158 // This check is necessary. Otherwise the new empty paragraph will
1159 // be deleted automatically. And it is more friendly for the user!
1160 if (cur.pos() != 0 || isempty)
1161 setCursor(cur, cur.pit() + 1, 0);
1163 setCursor(cur, cur.pit(), 0);
1167 // insert a character, moves all the following breaks in the
1168 // same Paragraph one to the right and make a rebreak
1169 void LyXText::insertChar(LCursor & cur, char_type c)
1171 BOOST_ASSERT(this == cur.text());
1172 BOOST_ASSERT(c != Paragraph::META_INSET);
1174 recordUndo(cur, Undo::INSERT);
1176 Paragraph & par = cur.paragraph();
1177 // try to remove this
1178 pit_type const pit = cur.pit();
1180 bool const freeSpacing = par.layout()->free_spacing ||
1181 par.isFreeSpacing();
1183 if (lyxrc.auto_number) {
1184 static docstring const number_operators = lyx::from_ascii("+-/*");
1185 static docstring const number_unary_operators = lyx::from_ascii("+-");
1186 static docstring const number_seperators = lyx::from_ascii(".,:");
1188 if (current_font.number() == LyXFont::ON) {
1189 if (!isDigit(c) && !contains(number_operators, c) &&
1190 !(contains(number_seperators, c) &&
1192 cur.pos() != cur.lastpos() &&
1193 getFont(par, cur.pos()).number() == LyXFont::ON &&
1194 getFont(par, cur.pos() - 1).number() == LyXFont::ON)
1196 number(cur); // Set current_font.number to OFF
1197 } else if (isDigit(c) &&
1198 real_current_font.isVisibleRightToLeft()) {
1199 number(cur); // Set current_font.number to ON
1201 if (cur.pos() != 0) {
1202 char_type const c = par.getChar(cur.pos() - 1);
1203 if (contains(number_unary_operators, c) &&
1205 || par.isSeparator(cur.pos() - 2)
1206 || par.isNewline(cur.pos() - 2))
1208 setCharFont(pit, cur.pos() - 1, current_font);
1209 } else if (contains(number_seperators, c)
1211 && getFont(par, cur.pos() - 2).number() == LyXFont::ON) {
1212 setCharFont(pit, cur.pos() - 1, current_font);
1218 // First check, if there will be two blanks together or a blank at
1219 // the beginning of a paragraph.
1220 // I decided to handle blanks like normal characters, the main
1221 // difference are the special checks when calculating the row.fill
1222 // (blank does not count at the end of a row) and the check here
1224 // When the free-spacing option is set for the current layout,
1225 // disable the double-space checking
1226 if (!freeSpacing && isLineSeparatorChar(c)) {
1227 if (cur.pos() == 0) {
1228 static bool sent_space_message = false;
1229 if (!sent_space_message) {
1230 cur.message(_("You cannot insert a space at the "
1231 "beginning of a paragraph. Please read the Tutorial."));
1232 sent_space_message = true;
1236 BOOST_ASSERT(cur.pos() > 0);
1237 if ((par.isLineSeparator(cur.pos() - 1)
1238 || par.isNewline(cur.pos() - 1))
1239 // FIXME: change tracking (MG)
1240 && par.lookupChange(cur.pos() - 1) != Change(Change::DELETED)) {
1241 static bool sent_space_message = false;
1242 if (!sent_space_message) {
1243 cur.message(_("You cannot type two spaces this way. "
1244 "Please read the Tutorial."));
1245 sent_space_message = true;
1251 // FIXME: change tracking (MG)
1252 par.insertChar(cur.pos(), c, current_font, Change(Change::INSERTED));
1253 setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
1258 void LyXText::charInserted()
1260 // Here we call finishUndo for every 20 characters inserted.
1261 // This is from my experience how emacs does it. (Lgb)
1262 static unsigned int counter;
1273 LyXText::computeRowMetrics(pit_type const pit, Row const & row) const
1276 Paragraph const & par = pars_[pit];
1278 double w = dim_.wid - row.width();
1280 bool const is_rtl = isRTL(par);
1282 result.x = rightMargin(par);
1284 result.x = leftMargin(pit, row.pos());
1286 // is there a manual margin with a manual label
1287 LyXLayout_ptr const & layout = par.layout();
1289 if (layout->margintype == MARGIN_MANUAL
1290 && layout->labeltype == LABEL_MANUAL) {
1291 /// We might have real hfills in the label part
1292 int nlh = numberOfLabelHfills(par, row);
1294 // A manual label par (e.g. List) has an auto-hfill
1295 // between the label text and the body of the
1297 // But we don't want to do this auto hfill if the par
1302 if (nlh && !par.getLabelWidthString().empty())
1303 result.label_hfill = labelFill(par, row) / double(nlh);
1306 // are there any hfills in the row?
1307 int const nh = numberOfHfills(par, row);
1311 result.hfill = w / nh;
1312 // we don't have to look at the alignment if it is ALIGN_LEFT and
1313 // if the row is already larger then the permitted width as then
1314 // we force the LEFT_ALIGN'edness!
1315 } else if (int(row.width()) < maxwidth_) {
1316 // is it block, flushleft or flushright?
1317 // set x how you need it
1319 if (par.params().align() == LYX_ALIGN_LAYOUT)
1320 align = layout->align;
1322 align = par.params().align();
1324 // Display-style insets should always be on a centred row
1325 // The test on par.size() is to catch zero-size pars, which
1326 // would trigger the assert in Paragraph::getInset().
1327 //inset = par.size() ? par.getInset(row.pos()) : 0;
1329 && par.isInset(row.pos())
1330 && par.getInset(row.pos())->display())
1332 align = LYX_ALIGN_CENTER;
1336 case LYX_ALIGN_BLOCK: {
1337 int const ns = numberOfSeparators(par, row);
1338 bool disp_inset = false;
1339 if (row.endpos() < par.size()) {
1340 InsetBase const * in = par.getInset(row.endpos());
1342 disp_inset = in->display();
1344 // If we have separators, this is not the last row of a
1345 // par, does not end in newline, and is not row above a
1346 // display inset... then stretch it
1348 && row.endpos() < par.size()
1349 && !par.isNewline(row.endpos() - 1)
1352 result.separator = w / ns;
1353 } else if (is_rtl) {
1358 case LYX_ALIGN_RIGHT:
1361 case LYX_ALIGN_CENTER:
1367 bidi.computeTables(par, *bv()->buffer(), row);
1369 pos_type body_pos = par.beginOfBody();
1370 pos_type end = row.endpos();
1373 && (body_pos > end || !par.isLineSeparator(body_pos - 1)))
1375 docstring const lsep = lyx::from_utf8(layout->labelsep);
1376 result.x += theFontMetrics(getLabelFont(par)).width(lsep);
1377 if (body_pos <= end)
1378 result.x += result.label_hfill;
1386 // the cursor set functions have a special mechanism. When they
1387 // realize, that you left an empty paragraph, they will delete it.
1389 bool LyXText::cursorRightOneWord(LCursor & cur)
1391 BOOST_ASSERT(this == cur.text());
1395 if (old.pos() == old.lastpos() && old.pit() != old.lastpit()) {
1399 // Advance through word.
1400 while (old.pos() != old.lastpos() && old.paragraph().isLetter(old.pos()))
1402 // Skip through trailing nonword stuff.
1403 while (old.pos() != old.lastpos() && !old.paragraph().isLetter(old.pos()))
1406 return setCursor(cur, old.pit(), old.pos());
1410 bool LyXText::cursorLeftOneWord(LCursor & cur)
1412 BOOST_ASSERT(this == cur.text());
1416 if (old.pos() == 0 && old.pit() != 0) {
1418 old.pos() = old.lastpos();
1420 // Skip through initial nonword stuff.
1421 while (old.pos() != 0 && !old.paragraph().isLetter(old.pos() - 1))
1423 // Advance through word.
1424 while (old.pos() != 0 && old.paragraph().isLetter(old.pos() - 1))
1427 return setCursor(cur, old.pit(), old.pos());
1431 void LyXText::selectWord(LCursor & cur, word_location loc)
1433 BOOST_ASSERT(this == cur.text());
1434 CursorSlice from = cur.top();
1435 CursorSlice to = cur.top();
1436 getWord(from, to, loc);
1437 if (cur.top() != from)
1438 setCursor(cur, from.pit(), from.pos());
1442 setCursor(cur, to.pit(), to.pos());
1447 // Select the word currently under the cursor when no
1448 // selection is currently set
1449 bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
1451 BOOST_ASSERT(this == cur.text());
1452 if (cur.selection())
1454 selectWord(cur, loc);
1455 return cur.selection();
1459 void LyXText::acceptChange(LCursor & cur)
1461 BOOST_ASSERT(this == cur.text());
1462 if (!cur.selection() && cur.lastpos() != 0)
1465 recordUndoSelection(cur, Undo::INSERT);
1467 DocIterator it = cur.selectionBegin();
1468 DocIterator et = cur.selectionEnd();
1469 pit_type pit = it.pit();
1470 Change::Type const type = pars_[pit].lookupChange(it.pos()).type;
1471 for (; pit <= et.pit(); ++pit) {
1472 pos_type left = ( pit == it.pit() ? it.pos() : 0 );
1474 ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
1475 pars_[pit].acceptChange(left, right);
1477 if (type == Change::DELETED) {
1478 ParagraphList & plist = paragraphs();
1479 if (it.pit() + 1 < et.pit())
1480 pars_.erase(boost::next(plist.begin(), it.pit() + 1),
1481 boost::next(plist.begin(), et.pit()));
1483 // Paragraph merge if appropriate:
1484 // FIXME: change tracking (MG)
1485 if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
1486 == Change(Change::DELETED)) {
1487 setCursorIntern(cur, it.pit() + 1, 0);
1492 cur.clearSelection();
1493 setCursorIntern(cur, it.pit(), 0);
1497 void LyXText::rejectChange(LCursor & cur)
1499 BOOST_ASSERT(this == cur.text());
1500 if (!cur.selection() && cur.lastpos() != 0)
1503 recordUndoSelection(cur, Undo::INSERT);
1505 DocIterator it = cur.selectionBegin();
1506 DocIterator et = cur.selectionEnd();
1507 pit_type pit = it.pit();
1508 Change::Type const type = pars_[pit].lookupChange(it.pos()).type;
1509 for (; pit <= et.pit(); ++pit) {
1510 pos_type left = ( pit == it.pit() ? it.pos() : 0 );
1512 ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
1513 pars_[pit].rejectChange(left, right);
1515 if (type == Change::INSERTED) {
1516 ParagraphList & plist = paragraphs();
1517 if (it.pit() + 1 < et.pit())
1518 pars_.erase(boost::next(plist.begin(), it.pit() + 1),
1519 boost::next(plist.begin(), et.pit()));
1520 // Paragraph merge if appropriate:
1521 // FIXME: change tracking (MG)
1522 if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
1523 == Change(Change::INSERTED)) {
1524 setCursorIntern(cur, it.pit() + 1, 0);
1529 cur.clearSelection();
1530 setCursorIntern(cur, it.pit(), 0);
1534 // Delete from cursor up to the end of the current or next word.
1535 void LyXText::deleteWordForward(LCursor & cur)
1537 BOOST_ASSERT(this == cur.text());
1538 if (cur.lastpos() == 0)
1542 cur.selection() = true;
1543 cursorRightOneWord(cur);
1545 cutSelection(cur, true, false);
1550 // Delete from cursor to start of current or prior word.
1551 void LyXText::deleteWordBackward(LCursor & cur)
1553 BOOST_ASSERT(this == cur.text());
1554 if (cur.lastpos() == 0)
1558 cur.selection() = true;
1559 cursorLeftOneWord(cur);
1561 cutSelection(cur, true, false);
1566 // Kill to end of line.
1567 void LyXText::deleteLineForward(LCursor & cur)
1569 BOOST_ASSERT(this == cur.text());
1570 if (cur.lastpos() == 0) {
1571 // Paragraph is empty, so we just go to the right
1575 cur.selection() = true; // to avoid deletion
1578 // What is this test for ??? (JMarc)
1579 if (!cur.selection())
1580 deleteWordForward(cur);
1582 cutSelection(cur, true, false);
1587 void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
1589 BOOST_ASSERT(this == cur.text());
1593 if (cur.selection()) {
1594 from = cur.selBegin();
1598 getWord(from, to, lyx::PARTIAL_WORD);
1599 cursorRightOneWord(cur);
1602 recordUndoSelection(cur);
1604 pos_type pos = from.pos();
1605 int par = from.pit();
1607 while (par != int(pars_.size()) && (pos != to.pos() || par != to.pit())) {
1609 if (pos == pars_[pit].size()) {
1614 char_type c = pars_[pit].getChar(pos);
1615 if (c != Paragraph::META_INSET) {
1617 case text_lowercase:
1620 case text_capitalization:
1622 action = text_lowercase;
1624 case text_uppercase:
1629 #ifdef WITH_WARNINGS
1632 pars_[pit].setChar(pos, c);
1638 bool LyXText::erase(LCursor & cur)
1640 BOOST_ASSERT(this == cur.text());
1641 bool needsUpdate = false;
1643 if (cur.pos() != cur.lastpos()) {
1644 recordUndo(cur, Undo::DELETE, cur.pit());
1645 setCursorIntern(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
1646 needsUpdate = backspace(cur);
1647 // FIXME: change tracking (MG)
1648 if (cur.paragraph().lookupChange(cur.pos()) == Change(Change::DELETED))
1650 } else if (cur.pit() != cur.lastpit()) {
1653 setCursorIntern(cur, cur.pit() + 1, 0, false, false);
1654 if (pars_[cur.pit()].layout() == pars_[scur.pit()].layout()) {
1655 recordUndo(scur, Undo::DELETE, scur.pit());
1656 needsUpdate = backspace(cur);
1657 if (cur.buffer().params().trackChanges) {
1658 // FIXME: Change tracking (MG)
1659 // move forward after the paragraph break is DELETED
1660 Paragraph & par = cur.paragraph();
1661 // FIXME: change tracking (MG)
1662 if (par.lookupChange(par.size()) == Change(Change::DELETED))
1663 setCursorIntern(cur, cur.pit() + 1, 0);
1666 setCursorIntern(scur, scur.pit(), scur.pos(), false, scur.boundary());
1669 needsUpdate = dissolveInset(cur);
1675 bool LyXText::backspacePos0(LCursor & cur)
1677 BOOST_ASSERT(this == cur.text());
1678 bool needsUpdate = false;
1680 Paragraph & par = cur.paragraph();
1681 // is it an empty paragraph?
1682 pos_type lastpos = cur.lastpos();
1683 if (lastpos == 0 || (lastpos == 1 && par.isSeparator(0))) {
1684 // This is an empty paragraph and we delete it just
1685 // by moving the cursor one step
1686 // left and let the DeleteEmptyParagraphMechanism
1687 // handle the actual deletion of the paragraph.
1689 if (cur.pit() != 0) {
1690 // For KeepEmpty layouts we need to get
1691 // rid of the keepEmpty setting first.
1692 // And the only way to do this is to
1693 // reset the layout to something
1694 // else: f.ex. the default layout.
1695 if (par.allowEmpty()) {
1696 Buffer & buf = cur.buffer();
1697 BufferParams const & bparams = buf.params();
1698 par.layout(bparams.getLyXTextClass().defaultLayout());
1707 recordUndo(cur, Undo::DELETE, cur.pit() - 1);
1709 pit_type tmppit = cur.pit();
1710 // We used to do cursorLeftIntern() here, but it is
1711 // not a good idea since it triggers the auto-delete
1712 // mechanism. So we do a cursorLeftIntern()-lite,
1713 // without the dreaded mechanism. (JMarc)
1714 if (cur.pit() != 0) {
1715 // steps into the above paragraph.
1716 setCursorIntern(cur, cur.pit() - 1,
1717 pars_[cur.pit() - 1].size(),
1721 // Pasting is not allowed, if the paragraphs have different
1722 // layout. I think it is a real bug of all other
1723 // word processors to allow it. It confuses the user.
1724 // Correction: Pasting is always allowed with standard-layout
1725 // Correction (Jug 20050717): Remove check about alignment!
1726 Buffer & buf = cur.buffer();
1727 BufferParams const & bufparams = buf.params();
1728 LyXTextClass const & tclass = bufparams.getLyXTextClass();
1729 pit_type const cpit = cur.pit();
1732 && (pars_[cpit].layout() == pars_[tmppit].layout()
1733 || pars_[tmppit].layout() == tclass.defaultLayout()))
1735 mergeParagraph(bufparams, pars_, cpit);
1738 if (cur.pos() != 0 && pars_[cpit].isSeparator(cur.pos() - 1))
1741 // the counters may have changed
1742 ParIterator par_it(cur);
1743 updateLabels(cur.buffer(), par_it);
1745 setCursor(cur, cur.pit(), cur.pos(), false);
1751 bool LyXText::backspace(LCursor & cur)
1753 BOOST_ASSERT(this == cur.text());
1754 bool needsUpdate = false;
1755 if (cur.pos() == 0) {
1757 return dissolveInset(cur);
1759 // The cursor is at the beginning of a paragraph, so
1760 // the the backspace will collapse two paragraphs into
1763 if (cur.pit() != 0 && cur.buffer().params().trackChanges) {
1764 // FIXME: Change tracking (MG)
1765 // Previous paragraph, mark "carriage return" as
1767 Paragraph & par = pars_[cur.pit() - 1];
1768 // Take care of a just inserted para break:
1769 // FIXME: change tracking (MG)
1770 if (par.lookupChange(par.size()) != Change(Change::INSERTED)) {
1771 // FIXME: change tracking (MG)
1772 par.setChange(par.size(), Change(Change::DELETED));
1773 setCursorIntern(cur, cur.pit() - 1, par.size());
1778 needsUpdate = backspacePos0(cur);
1781 // this is the code for a normal backspace, not pasting
1783 recordUndo(cur, Undo::DELETE);
1784 // We used to do cursorLeftIntern() here, but it is
1785 // not a good idea since it triggers the auto-delete
1786 // mechanism. So we do a cursorLeftIntern()-lite,
1787 // without the dreaded mechanism. (JMarc)
1788 setCursorIntern(cur, cur.pit(), cur.pos() - 1,
1789 false, cur.boundary());
1790 cur.paragraph().erase(cur.pos());
1793 if (cur.pos() == cur.lastpos())
1794 setCurrentFont(cur);
1796 setCursor(cur, cur.pit(), cur.pos(), false, cur.boundary());
1802 bool LyXText::dissolveInset(LCursor & cur) {
1803 BOOST_ASSERT(this == cur.text());
1805 if (isMainText() || cur.inset().nargs() != 1)
1808 recordUndoInset(cur);
1809 cur.selHandle(false);
1811 lyx::pos_type spos = cur.pos();
1812 lyx::pit_type spit = cur.pit();
1813 ParagraphList plist;
1814 if (cur.lastpit() != 0 || cur.lastpos() != 0)
1815 plist = paragraphs();
1817 // store cursor offset
1821 cur.paragraph().erase(cur.pos());
1822 if (!plist.empty()) {
1823 Buffer & b = cur.buffer();
1824 pasteParagraphList(cur, plist, b.params().textclass,
1825 b.errorList("Paste"));
1827 cur.pit() = std::min(cur.lastpit(), spit);
1828 cur.pos() = std::min(cur.lastpos(), spos);
1830 cur.clearSelection();
1836 Row const & LyXText::firstRow() const
1838 return *paragraphs().front().rows().begin();
1842 bool LyXText::redoParagraph(pit_type const pit)
1844 // remove rows of paragraph, keep track of height changes
1845 Paragraph & par = pars_[pit];
1847 // Add bibitem insets if necessary
1848 if (par.layout()->labeltype == LABEL_BIBLIO) {
1849 bool hasbibitem(false);
1850 if (!par.insetlist.empty()
1851 // Insist on it being in pos 0
1852 && par.getChar(0) == Paragraph::META_INSET) {
1853 InsetBase * inset = par.insetlist.begin()->inset;
1854 if (inset->lyxCode() == InsetBase::BIBITEM_CODE)
1858 InsetBibitem * inset(new
1859 InsetBibitem(InsetCommandParams("bibitem")));
1860 // FIXME: change tracking (MG)
1861 par.insertInset(0, static_cast<InsetBase *>(inset), Change(Change::INSERTED));
1862 bv()->cursor().posRight();
1867 // FIXME: We should always use getFont(), see documentation of
1868 // noFontChange() in insetbase.h.
1869 LyXFont const bufferfont = bv()->buffer()->params().getFont();
1870 InsetList::iterator ii = par.insetlist.begin();
1871 InsetList::iterator iend = par.insetlist.end();
1872 for (; ii != iend; ++ii) {
1874 int const w = maxwidth_ - leftMargin(pit, ii->pos) - rightMargin(par);
1875 LyXFont const & font = ii->inset->noFontChange() ?
1877 getFont(par, ii->pos);
1878 MetricsInfo mi(bv(), font, w);
1879 ii->inset->metrics(mi, dim);
1882 // rebreak the paragraph
1886 par.setBeginOfBody();
1890 rowBreakPoint(pit, row);
1891 setRowWidth(pit, row);
1892 setHeightOfRow(pit, row);
1893 par.rows().push_back(row);
1894 dim.wid = std::max(dim.wid, row.width());
1895 dim.des += row.height();
1897 } while (z < par.size());
1899 // Make sure that if a par ends in newline, there is one more row
1901 // FIXME this is a dirty trick. Now the _same_ position in the
1902 // paragraph occurs in _two_ different rows, and has two different
1903 // display positions, leading to weird behaviour when moving up/down.
1904 if (z > 0 && par.isNewline(z - 1)) {
1907 setRowWidth(pit, row);
1908 setHeightOfRow(pit, row);
1909 par.rows().push_back(row);
1910 dim.des += row.height();
1913 dim.asc += par.rows()[0].ascent();
1914 dim.des -= par.rows()[0].ascent();
1916 bool const same = dim == par.dim();
1919 //lyxerr << "redoParagraph: " << par.rows().size() << " rows\n";
1925 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
1927 //BOOST_ASSERT(mi.base.textwidth);
1928 if (mi.base.textwidth)
1929 maxwidth_ = mi.base.textwidth;
1930 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
1931 // << " maxWidth: " << maxwidth_ << "\nfont: " << mi.base.font << endl;
1932 // save the caller's font locally:
1933 font_ = mi.base.font;
1937 for (pit_type pit = 0, n = paragraphs().size(); pit != n; ++pit) {
1939 Paragraph & par = paragraphs()[pit];
1941 if (w < par.width())
1946 dim.asc = pars_[0].ascent();
1947 dim.des = h - dim.asc;
1953 // only used for inset right now. should also be used for main text
1954 void LyXText::draw(PainterInfo & pi, int x, int y) const
1956 paintTextInset(*this, pi, x, y);
1961 // only used for inset right now. should also be used for main text
1962 void LyXText::drawSelection(PainterInfo & pi, int x , int) const
1964 LCursor & cur = pi.base.bv->cursor();
1965 if (!cur.selection())
1967 if (!ptr_cmp(cur.text(), this))
1970 lyxerr << "draw selection at " << x << endl;
1972 DocIterator beg = cur.selectionBegin();
1973 DocIterator end = cur.selectionEnd();
1975 // the selection doesn't touch the visible screen
1976 if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW
1977 || bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE)
1980 Paragraph const & par1 = pars_[beg.pit()];
1981 Paragraph const & par2 = pars_[end.pit()];
1983 Row const & row1 = par1.getRow(beg.pos(), beg.boundary());
1984 Row const & row2 = par2.getRow(end.pos(), end.boundary());
1987 if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_ABOVE) {
1992 y1 = bv_funcs::getPos(beg).y_ - row1.ascent();
1993 int const startx = cursorX(beg.top(), begin.boundary());
1994 x1 = isRTL(par1) ? startx : 0;
1995 x2 = isRTL(par1) ? 0 + dim_.wid : startx;
1999 if (bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_BELOW) {
2000 y2 = pi.base.bv->workHeight();
2004 y2 = bv_funcs::getPos(end).y_ + row2.descent();
2005 int const endx = cursorX(end.top(), end.boundary());
2006 X1 = isRTL(par2) ? 0 : endx;
2007 X2 = isRTL(par2) ? endx : 0 + dim_.wid;
2010 lyxerr << " y1: " << y1 << " y2: " << y2
2011 << " xo: " << xo_ << " wid: " << dim_.wid
2014 // paint big rectangle in one go
2015 pi.pain.fillRectangle(x, y1, dim_.wid, y2 - y1, LColor::selection);
2017 // reset background at begin of first selected line
2018 pi.pain.fillRectangle(x + x1, y1, x2 - x1, row1.height(),
2019 LColor::background);
2021 // reset background at end of last selected line
2022 pi.pain.fillRectangle(x + X1, y2 - row2.height(),
2023 X2 - X1, row2.height(), LColor::background);
2028 void LyXText::drawSelection(PainterInfo & pi, int x, int) const
2030 LCursor & cur = pi.base.bv->cursor();
2031 if (!cur.selection())
2033 if (!ptr_cmp(cur.text(), this))
2036 lyxerr[Debug::DEBUG]
2037 << BOOST_CURRENT_FUNCTION
2038 << "draw selection at " << x
2041 DocIterator beg = cur.selectionBegin();
2042 DocIterator end = cur.selectionEnd();
2044 BufferView * bv = pi.base.bv;
2046 // the selection doesn't touch the visible screen
2047 if (bv_funcs::status(bv, beg) == bv_funcs::CUR_BELOW
2048 || bv_funcs::status(bv, end) == bv_funcs::CUR_ABOVE)
2051 Paragraph const & par1 = pars_[beg.pit()];
2052 Paragraph const & par2 = pars_[end.pit()];
2054 bool const above = (bv_funcs::status(bv, beg)
2055 == bv_funcs::CUR_ABOVE);
2056 bool const below = (bv_funcs::status(bv, end)
2057 == bv_funcs::CUR_BELOW);
2065 Row const & row1 = par1.getRow(beg.pos(), beg.boundary());
2066 y1 = bv_funcs::getPos(*bv, beg, beg.boundary()).y_ - row1.ascent();
2067 y2 = y1 + row1.height();
2068 int const startx = cursorX(beg.top(), beg.boundary());
2069 x1 = !isRTL(par1) ? startx : 0;
2070 x2 = !isRTL(par1) ? 0 + dim_.wid : startx;
2075 Y1 = bv->workHeight();
2076 Y2 = bv->workHeight();
2080 Row const & row2 = par2.getRow(end.pos(), end.boundary());
2081 Y1 = bv_funcs::getPos(*bv, end, end.boundary()).y_ - row2.ascent();
2082 Y2 = Y1 + row2.height();
2083 int const endx = cursorX(end.top(), end.boundary());
2084 X1 = !isRTL(par2) ? 0 : endx;
2085 X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
2088 if (!above && !below && &par1.getRow(beg.pos(), beg.boundary())
2089 == &par2.getRow(end.pos(), end.boundary()))
2091 // paint only one rectangle
2092 int const b( !isRTL(par1) ? x + x1 : x + X1 );
2093 int const w( !isRTL(par1) ? X2 - x1 : x2 - X1 );
2094 pi.pain.fillRectangle(b, y1, w, y2 - y1, LColor::selection);
2098 lyxerr[Debug::DEBUG] << " y1: " << y1 << " y2: " << y2
2099 << "X1:" << X1 << " x2: " << X2 << " wid: " << dim_.wid
2102 // paint upper rectangle
2103 pi.pain.fillRectangle(x + x1, y1, x2 - x1, y2 - y1,
2105 // paint bottom rectangle
2106 pi.pain.fillRectangle(x + X1, Y1, X2 - X1, Y2 - Y1,
2108 // paint center rectangle
2109 pi.pain.fillRectangle(x, y2, dim_.wid,
2110 Y1 - y2, LColor::selection);
2114 bool LyXText::isLastRow(pit_type pit, Row const & row) const
2116 return row.endpos() >= pars_[pit].size()
2117 && pit + 1 == pit_type(paragraphs().size());
2121 bool LyXText::isFirstRow(pit_type pit, Row const & row) const
2123 return row.pos() == 0 && pit == 0;
2127 void LyXText::getWord(CursorSlice & from, CursorSlice & to,
2128 word_location const loc)
2130 Paragraph const & from_par = pars_[from.pit()];
2132 case lyx::WHOLE_WORD_STRICT:
2133 if (from.pos() == 0 || from.pos() == from_par.size()
2134 || !from_par.isLetter(from.pos())
2135 || !from_par.isLetter(from.pos() - 1)) {
2139 // no break here, we go to the next
2141 case lyx::WHOLE_WORD:
2142 // If we are already at the beginning of a word, do nothing
2143 if (!from.pos() || !from_par.isLetter(from.pos() - 1))
2145 // no break here, we go to the next
2147 case lyx::PREVIOUS_WORD:
2148 // always move the cursor to the beginning of previous word
2149 while (from.pos() && from_par.isLetter(from.pos() - 1))
2152 case lyx::NEXT_WORD:
2153 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
2156 case lyx::PARTIAL_WORD:
2157 // no need to move the 'from' cursor
2161 Paragraph & to_par = pars_[to.pit()];
2162 while (to.pos() < to_par.size() && to_par.isLetter(to.pos()))
2167 void LyXText::write(Buffer const & buf, std::ostream & os) const
2169 ParagraphList::const_iterator pit = paragraphs().begin();
2170 ParagraphList::const_iterator end = paragraphs().end();
2171 Paragraph::depth_type dth = 0;
2172 for (; pit != end; ++pit)
2173 pit->write(buf, os, buf.params(), dth);
2177 bool LyXText::read(Buffer const & buf, LyXLex & lex, ErrorList & errorList)
2179 Paragraph::depth_type depth = 0;
2181 while (lex.isOK()) {
2183 string const token = lex.getString();
2188 if (token == "\\end_inset") {
2192 if (token == "\\end_body") {
2196 if (token == "\\begin_body") {
2200 if (token == "\\end_document") {
2204 if (token == "\\begin_layout") {
2205 lex.pushToken(token);
2208 par.params().depth(depth);
2209 par.setFont(0, LyXFont(LyXFont::ALL_INHERIT, buf.params().language));
2210 pars_.push_back(par);
2212 // FIXME: goddamn InsetTabular makes us pass a Buffer
2214 ::readParagraph(buf, pars_.back(), lex, errorList);
2216 } else if (token == "\\begin_deeper") {
2218 } else if (token == "\\end_deeper") {
2220 lex.printError("\\end_deeper: " "depth is already null");
2225 lyxerr << "Handling unknown body token: `"
2226 << token << '\'' << endl;
2233 int LyXText::ascent() const
2239 int LyXText::descent() const
2245 int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
2247 pit_type const pit = sl.pit();
2248 Paragraph const & par = pars_[pit];
2249 if (par.rows().empty())
2252 pos_type ppos = sl.pos();
2253 // Correct position in front of big insets
2254 bool const boundary_correction = ppos != 0 && boundary;
2255 if (boundary_correction)
2258 Row const & row = par.getRow(sl.pos(), boundary);
2260 pos_type cursor_vpos = 0;
2262 RowMetrics const m = computeRowMetrics(pit, row);
2265 pos_type const row_pos = row.pos();
2266 pos_type const end = row.endpos();
2269 cursor_vpos = row_pos;
2270 else if (ppos >= end)
2271 cursor_vpos = isRTL(par) ? row_pos : end;
2272 else if (ppos > row_pos && ppos >= end)
2273 // Place cursor after char at (logical) position pos - 1
2274 cursor_vpos = (bidi.level(ppos - 1) % 2 == 0)
2275 ? bidi.log2vis(ppos - 1) + 1 : bidi.log2vis(ppos - 1);
2277 // Place cursor before char at (logical) position ppos
2278 cursor_vpos = (bidi.level(ppos) % 2 == 0)
2279 ? bidi.log2vis(ppos) : bidi.log2vis(ppos) + 1;
2281 pos_type body_pos = par.beginOfBody();
2283 (body_pos > end || !par.isLineSeparator(body_pos - 1)))
2286 // Use font span to speed things up, see below
2289 FontMetrics const & labelfm = theFontMetrics(getLabelFont(par));
2291 for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
2292 pos_type pos = bidi.vis2log(vpos);
2293 if (body_pos > 0 && pos == body_pos - 1) {
2295 docstring const lsep = lyx::from_utf8(par.layout()->labelsep);
2296 x += m.label_hfill + labelfm.width(lsep);
2297 if (par.isLineSeparator(body_pos - 1))
2298 x -= singleWidth(par, body_pos - 1);
2301 // Use font span to speed things up, see above
2302 if (pos < font_span.first || pos > font_span.last) {
2303 font_span = par.fontSpan(pos);
2304 font = getFont(par, pos);
2307 x += singleWidth(par, pos, par.getChar(pos), font);
2309 if (hfillExpansion(par, row, pos))
2310 x += (pos >= body_pos) ? m.hfill : m.label_hfill;
2311 else if (par.isSeparator(pos) && pos >= body_pos)
2315 // see correction above
2316 if (boundary_correction)
2317 if (getFont(par, ppos).isVisibleRightToLeft())
2318 x -= singleWidth(par, ppos);
2320 x += singleWidth(par, ppos);
2322 // Make sure inside an inset we always count from the left
2323 // edge (bidi!) -- MV
2324 if (sl.pos() < par.size()) {
2325 font = getFont(par, sl.pos());
2326 if (!boundary && font.isVisibleRightToLeft()
2327 && par.isInset(sl.pos()))
2328 x -= par.getInset(sl.pos())->width();
2334 int LyXText::cursorY(CursorSlice const & sl, bool boundary) const
2336 //lyxerr << "LyXText::cursorY: boundary: " << boundary << std::endl;
2337 Paragraph const & par = getPar(sl.pit());
2338 if (par.rows().empty())
2342 h -= pars_[0].rows()[0].ascent();
2343 for (pit_type pit = 0; pit < sl.pit(); ++pit)
2344 h += pars_[pit].height();
2346 if (pos && boundary)
2348 size_t const rend = par.pos2row(pos);
2349 for (size_t rit = 0; rit != rend; ++rit)
2350 h += par.rows()[rit].height();
2351 h += par.rows()[rend].ascent();
2356 // Returns the current font and depth as a message.
2357 string LyXText::currentState(LCursor & cur)
2359 BOOST_ASSERT(this == cur.text());
2360 Buffer & buf = cur.buffer();
2361 Paragraph const & par = cur.paragraph();
2362 std::ostringstream os;
2364 // FIXME: change tracking (MG)
2365 bool const show_change = par.lookupChange(cur.pos()) != Change(Change::UNCHANGED);
2367 if (buf.params().trackChanges)
2371 Change change = par.lookupChange(cur.pos());
2372 Author const & a = buf.params().authors().get(change.author);
2373 os << lyx::to_utf8(_("Change: ")) << a.name();
2374 if (!a.email().empty())
2375 os << " (" << a.email() << ")";
2376 if (change.changetime)
2377 os << lyx::to_utf8(_(" at ")) << ctime(&change.changetime);
2381 // I think we should only show changes from the default
2383 // No, from the document font (MV)
2384 LyXFont font = real_current_font;
2385 font.reduce(buf.params().getFont());
2387 // avoid lyx::to_utf8(_(...)) re-entrance problem
2388 string const s = font.stateText(&buf.params());
2389 os << lyx::to_utf8(bformat(_("Font: %1$s"), lyx::from_utf8(s)));
2391 // os << lyx::to_utf8(bformat(_("Font: %1$s"), font.stateText(&buf.params)));
2393 // The paragraph depth
2394 int depth = cur.paragraph().getDepth();
2396 os << lyx::to_utf8(bformat(_(", Depth: %1$d"), depth));
2398 // The paragraph spacing, but only if different from
2400 Spacing const & spacing = par.params().spacing();
2401 if (!spacing.isDefault()) {
2402 os << lyx::to_utf8(_(", Spacing: "));
2403 switch (spacing.getSpace()) {
2404 case Spacing::Single:
2405 os << lyx::to_utf8(_("Single"));
2407 case Spacing::Onehalf:
2408 os << lyx::to_utf8(_("OneHalf"));
2410 case Spacing::Double:
2411 os << lyx::to_utf8(_("Double"));
2413 case Spacing::Other:
2414 os << lyx::to_utf8(_("Other (")) << spacing.getValueAsString() << ')';
2416 case Spacing::Default:
2417 // should never happen, do nothing
2422 #ifdef DEVEL_VERSION
2423 os << lyx::to_utf8(_(", Inset: ")) << &cur.inset();
2424 os << lyx::to_utf8(_(", Paragraph: ")) << cur.pit();
2425 os << lyx::to_utf8(_(", Id: ")) << par.id();
2426 os << lyx::to_utf8(_(", Position: ")) << cur.pos();
2427 os << lyx::to_utf8(_(", Boundary: ")) << cur.boundary();
2428 // Row & row = cur.textRow();
2429 // os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
2435 string LyXText::getPossibleLabel(LCursor & cur) const
2437 pit_type pit = cur.pit();
2439 LyXLayout_ptr layout = pars_[pit].layout();
2441 if (layout->latextype == LATEX_PARAGRAPH && pit != 0) {
2442 LyXLayout_ptr const & layout2 = pars_[pit - 1].layout();
2443 if (layout2->latextype != LATEX_PARAGRAPH) {
2449 string name = layout->latexname();
2451 // for captions, we want the abbreviation of the float type
2452 if (layout->labeltype == LABEL_SENSITIVE) {
2453 // Search for the first float or wrap inset in the iterator
2454 size_t i = cur.depth();
2457 InsetBase * const in = &cur[i].inset();
2458 if (in->lyxCode() == InsetBase::FLOAT_CODE
2459 || in->lyxCode() == InsetBase::WRAP_CODE) {
2460 name = in->getInsetName();
2466 string text = name.substr(0, 3);
2467 if (name == "theorem")
2468 text = "thm"; // Create a correct prefix for prettyref
2471 if (layout->latextype == LATEX_PARAGRAPH || lyxrc.label_init_length < 0)
2475 string par_text = lyx::to_utf8(pars_[pit].asString(cur.buffer(), false));
2476 for (int i = 0; i < lyxrc.label_init_length; ++i) {
2477 if (par_text.empty())
2480 par_text = split(par_text, head, ' ');
2481 // Is it legal to use spaces in labels ?
2491 //pos_type LyXText::x2pos(pit_type pit, int row, int x) const
2495 // Paragraph const & par = pars_[pit];
2496 // Row const & r = par.rows()[row];
2497 // int pos = r.pos();
2498 // for (; currx < x && pos < r.endpos(); ++pos) {
2500 // currx += singleWidth(par, pos);
2502 // if (abs(lastx - x) < abs(currx - x) && pos != r.pos())
2508 pos_type LyXText::x2pos(pit_type pit, int row, int x) const
2510 BOOST_ASSERT(row < int(pars_[pit].rows().size()));
2512 Row const & r = pars_[pit].rows()[row];
2513 return r.pos() + getColumnNearX(pit, r, x, bound);
2517 //int LyXText::pos2x(pit_type pit, pos_type pos) const
2519 // Paragraph const & par = pars_[pit];
2520 // Row const & r = par.rows()[row];
2526 // x,y are screen coordinates
2527 // sets cursor only within this LyXText
2528 bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
2530 BOOST_ASSERT(this == cur.text());
2531 pit_type pit = getPitNearY(y);
2532 int yy = cur.bv().coordCache().get(this, pit).y_ - pars_[pit].ascent();
2533 lyxerr[Debug::DEBUG]
2534 << BOOST_CURRENT_FUNCTION
2538 << " yy: " << yy << endl;
2540 Paragraph const & par = pars_[pit];
2542 BOOST_ASSERT(par.rows().size());
2543 for (; r < int(par.rows().size()) - 1; ++r) {
2544 Row const & row = par.rows()[r];
2545 if (int(yy + row.height()) > y)
2550 Row const & row = par.rows()[r];
2552 lyxerr[Debug::DEBUG]
2553 << BOOST_CURRENT_FUNCTION
2555 << " from pos: " << row.pos()
2560 pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
2562 lyxerr[Debug::DEBUG]
2563 << BOOST_CURRENT_FUNCTION
2564 << ": setting cursor pit: " << pit
2568 return setCursor(cur, pit, pos, true, bound);