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 Alfredo Braunstein
9 * \author Jean-Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
15 * \author Jürgen Vigna
17 * Full author contact details are available in file CREDITS.
25 #include "paragraph.h"
26 #include "funcrequest.h"
27 #include "frontends/LyXView.h"
28 #include "undo_funcs.h"
30 #include "buffer_funcs.h"
31 #include "bufferparams.h"
32 #include "errorlist.h"
34 #include "BufferView.h"
35 #include "CutAndPaste.h"
36 #include "frontends/Painter.h"
37 #include "frontends/font_metrics.h"
40 #include "FloatList.h"
42 #include "ParagraphParameters.h"
44 #include "lyxrow_funcs.h"
45 #include "metricsinfo.h"
46 #include "paragraph_funcs.h"
48 #include "insets/insetbibitem.h"
49 #include "insets/insetenv.h"
50 #include "insets/insetfloat.h"
51 #include "insets/insetwrap.h"
53 #include "support/LAssert.h"
54 #include "support/textutils.h"
55 #include "support/lstrings.h"
57 #include <boost/tuple/tuple.hpp>
61 using namespace lyx::support;
71 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
72 ParagraphList & paragraphs)
73 : height(0), width(0), anchor_y_(0),
74 inset_owner(inset), the_locking_inset(0), bv_owner(bv),
75 in_inset_(ininset), paragraphs_(paragraphs)
80 void LyXText::init(BufferView * bview)
84 ParagraphList::iterator const beg = ownerParagraphs().begin();
85 ParagraphList::iterator const end = ownerParagraphs().end();
86 for (ParagraphList::iterator pit = beg; pit != end; ++pit)
94 current_font = getFont(beg, 0);
96 redoParagraphs(beg, end);
97 setCursorIntern(beg, 0);
98 selection.cursor = cursor;
104 // Gets the fully instantiated font at a given position in a paragraph
105 // Basically the same routine as Paragraph::getFont() in paragraph.C.
106 // The difference is that this one is used for displaying, and thus we
107 // are allowed to make cosmetic improvements. For instance make footnotes
109 LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
113 LyXLayout_ptr const & layout = pit->layout();
115 BufferParams const & params = bv()->buffer()->params;
117 // We specialize the 95% common case:
118 if (!pit->getDepth()) {
119 if (layout->labeltype == LABEL_MANUAL
120 && pos < pit->beginningOfBody()) {
122 LyXFont f = pit->getFontSettings(params, pos);
124 pit->inInset()->getDrawFont(f);
125 return f.realize(layout->reslabelfont);
127 LyXFont f = pit->getFontSettings(params, pos);
129 pit->inInset()->getDrawFont(f);
130 return f.realize(layout->resfont);
134 // The uncommon case need not be optimized as much
138 if (pos < pit->beginningOfBody()) {
140 layoutfont = layout->labelfont;
143 layoutfont = layout->font;
146 LyXFont tmpfont = pit->getFontSettings(params, pos);
147 tmpfont.realize(layoutfont);
150 pit->inInset()->getDrawFont(tmpfont);
152 // Realize with the fonts of lesser depth.
153 tmpfont.realize(outerFont(pit, ownerParagraphs()));
154 tmpfont.realize(defaultfont_);
160 LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const
162 LyXLayout_ptr const & layout = pit->layout();
164 if (!pit->getDepth())
165 return layout->resfont;
167 LyXFont font = layout->font;
168 // Realize with the fonts of lesser depth.
169 font.realize(outerFont(pit, ownerParagraphs()));
170 font.realize(defaultfont_);
176 LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
178 LyXLayout_ptr const & layout = pit->layout();
180 if (!pit->getDepth())
181 return layout->reslabelfont;
183 LyXFont font = layout->labelfont;
184 // Realize with the fonts of lesser depth.
185 font.realize(outerFont(pit, ownerParagraphs()));
186 font.realize(defaultfont_);
192 void LyXText::setCharFont(ParagraphList::iterator pit,
193 pos_type pos, LyXFont const & fnt,
196 BufferParams const & params = bv()->buffer()->params;
197 LyXFont font = getFont(pit, pos);
198 font.update(fnt, params.language, toggleall);
199 // Let the insets convert their font
200 if (pit->isInset(pos)) {
201 InsetOld * inset = pit->getInset(pos);
202 if (isEditableInset(inset)) {
203 static_cast<UpdatableInset *>(inset)
204 ->setFont(bv(), fnt, toggleall, true);
208 // Plug through to version below:
209 setCharFont(pit, pos, font);
213 void LyXText::setCharFont(
214 ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
217 LyXLayout_ptr const & layout = pit->layout();
219 // Get concrete layout font to reduce against
222 if (pos < pit->beginningOfBody())
223 layoutfont = layout->labelfont;
225 layoutfont = layout->font;
227 // Realize against environment font information
228 if (pit->getDepth()) {
229 ParagraphList::iterator tp = pit;
230 while (!layoutfont.resolved() &&
231 tp != ownerParagraphs().end() &&
233 tp = outerHook(tp, ownerParagraphs());
234 if (tp != ownerParagraphs().end())
235 layoutfont.realize(tp->layout()->font);
239 layoutfont.realize(defaultfont_);
241 // Now, reduce font against full layout font
242 font.reduce(layoutfont);
244 pit->setFont(pos, font);
248 InsetOld * LyXText::getInset() const
250 ParagraphList::iterator pit = cursor.par();
251 pos_type const pos = cursor.pos();
253 if (pos < pit->size() && pit->isInset(pos)) {
254 return pit->getInset(pos);
260 void LyXText::toggleInset()
262 InsetOld * inset = getInset();
263 // is there an editable inset at cursor position?
264 if (!isEditableInset(inset)) {
265 // No, try to see if we are inside a collapsable inset
266 if (inset_owner && inset_owner->owner()
267 && inset_owner->owner()->isOpen()) {
268 bv()->unlockInset(inset_owner->owner());
269 inset_owner->owner()->close(bv());
270 bv()->getLyXText()->cursorRight(bv());
274 //bv()->owner()->message(inset->editMessage());
276 // do we want to keep this?? (JMarc)
277 if (!isHighlyEditableInset(inset))
278 recordUndo(bv(), Undo::ATOMIC);
285 bv()->updateInset(inset);
289 /* used in setlayout */
290 // Asger is not sure we want to do this...
291 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
294 LyXLayout_ptr const & layout = par.layout();
295 pos_type const psize = par.size();
298 for (pos_type pos = 0; pos < psize; ++pos) {
299 if (pos < par.beginningOfBody())
300 layoutfont = layout->labelfont;
302 layoutfont = layout->font;
304 LyXFont tmpfont = par.getFontSettings(params, pos);
305 tmpfont.reduce(layoutfont);
306 par.setFont(pos, tmpfont);
311 ParagraphList::iterator
312 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
313 LyXCursor & send_cur,
314 string const & layout)
316 ParagraphList::iterator endpit = boost::next(send_cur.par());
317 ParagraphList::iterator undoendpit = endpit;
318 ParagraphList::iterator pars_end = ownerParagraphs().end();
320 if (endpit != pars_end && endpit->getDepth()) {
321 while (endpit != pars_end && endpit->getDepth()) {
325 } else if (endpit != pars_end) {
326 // because of parindents etc.
330 recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(undoendpit));
332 // ok we have a selection. This is always between sstart_cur
333 // and sel_end cursor
335 ParagraphList::iterator pit = sstart_cur.par();
336 ParagraphList::iterator epit = boost::next(send_cur.par());
338 LyXLayout_ptr const & lyxlayout =
339 bv()->buffer()->params.getLyXTextClass()[layout];
342 pit->applyLayout(lyxlayout);
343 makeFontEntriesLayoutSpecific(bv()->buffer()->params, *pit);
344 pit->params().spaceTop(lyxlayout->fill_top ?
345 VSpace(VSpace::VFILL)
346 : VSpace(VSpace::NONE));
347 pit->params().spaceBottom(lyxlayout->fill_bottom ?
348 VSpace(VSpace::VFILL)
349 : VSpace(VSpace::NONE));
350 if (lyxlayout->margintype == MARGIN_MANUAL)
351 pit->setLabelWidthString(lyxlayout->labelstring());
354 } while (pit != epit);
360 // set layout over selection and make a total rebreak of those paragraphs
361 void LyXText::setLayout(string const & layout)
363 LyXCursor tmpcursor = cursor; // store the current cursor
365 // if there is no selection just set the layout
366 // of the current paragraph
367 if (!selection.set()) {
368 selection.start = cursor; // dummy selection
369 selection.end = cursor;
372 // special handling of new environment insets
373 BufferParams const & params = bv()->buffer()->params;
374 LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
375 if (lyxlayout->is_environment) {
376 // move everything in a new environment inset
377 lyxerr << "setting layout " << layout << endl;
378 bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
379 bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
380 bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
381 InsetOld * inset = new InsetEnvironment(params, layout);
382 if (bv()->insertInset(inset)) {
384 //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
391 ParagraphList::iterator endpit = setLayout(cursor, selection.start,
392 selection.end, layout);
393 redoParagraphs(selection.start.par(), endpit);
395 // we have to reset the selection, because the
396 // geometry could have changed
397 setCursor(selection.start.par(), selection.start.pos(), false);
398 selection.cursor = cursor;
399 setCursor(selection.end.par(), selection.end.pos(), false);
403 setCursor(tmpcursor.par(), tmpcursor.pos(), true);
407 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
409 ParagraphList::iterator pit = cursor.par();
410 ParagraphList::iterator end = cursor.par();
411 ParagraphList::iterator start = pit;
413 if (selection.set()) {
414 pit = selection.start.par();
415 end = selection.end.par();
419 ParagraphList::iterator pastend = boost::next(end);
422 recordUndo(bv(), Undo::ATOMIC, start, end);
424 bool changed = false;
426 int prev_after_depth = 0;
427 #warning parlist ... could be nicer ?
428 if (start != ownerParagraphs().begin()) {
429 prev_after_depth = boost::prior(start)->getMaxDepthAfter();
433 int const depth = pit->params().depth();
434 if (type == bv_funcs::INC_DEPTH) {
435 if (depth < prev_after_depth
436 && pit->layout()->labeltype != LABEL_BIBLIO) {
439 pit->params().depth(depth + 1);
444 pit->params().depth(depth - 1);
447 prev_after_depth = pit->getMaxDepthAfter();
459 redoParagraphs(start, pastend);
461 // We need to actually move the text->cursor. I don't
462 // understand why ...
463 LyXCursor tmpcursor = cursor;
465 // we have to reset the visual selection because the
466 // geometry could have changed
467 if (selection.set()) {
468 setCursor(selection.start.par(), selection.start.pos());
469 selection.cursor = cursor;
470 setCursor(selection.end.par(), selection.end.pos());
473 // this handles the counter labels, and also fixes up
474 // depth values for follow-on (child) paragraphs
478 setCursor(tmpcursor.par(), tmpcursor.pos());
484 // set font over selection and make a total rebreak of those paragraphs
485 void LyXText::setFont(LyXFont const & font, bool toggleall)
487 // if there is no selection just set the current_font
488 if (!selection.set()) {
489 // Determine basis font
491 if (cursor.pos() < cursor.par()->beginningOfBody()) {
492 layoutfont = getLabelFont(cursor.par());
494 layoutfont = getLayoutFont(cursor.par());
496 // Update current font
497 real_current_font.update(font,
498 bv()->buffer()->params.language,
501 // Reduce to implicit settings
502 current_font = real_current_font;
503 current_font.reduce(layoutfont);
504 // And resolve it completely
505 real_current_font.realize(layoutfont);
510 LyXCursor tmpcursor = cursor; // store the current cursor
512 // ok we have a selection. This is always between sel_start_cursor
513 // and sel_end cursor
515 recordUndo(bv(), Undo::ATOMIC, selection.start.par(), selection.end.par());
517 cursor = selection.start;
518 while (cursor.par() != selection.end.par() ||
519 cursor.pos() < selection.end.pos())
521 if (cursor.pos() < cursor.par()->size()) {
522 // an open footnote should behave like a closed one
523 setCharFont(cursor.par(), cursor.pos(),
525 cursor.pos(cursor.pos() + 1);
528 cursor.par(boost::next(cursor.par()));
533 redoParagraph(selection.start.par());
535 // we have to reset the selection, because the
536 // geometry could have changed, but we keep
537 // it for user convenience
538 setCursor(selection.start.par(), selection.start.pos());
539 selection.cursor = cursor;
540 setCursor(selection.end.par(), selection.end.pos());
542 setCursor(tmpcursor.par(), tmpcursor.pos(), true,
543 tmpcursor.boundary());
547 int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
549 RowList::iterator rit = pit->rows.begin();
550 RowList::iterator end = pit->rows.end();
552 // remove rows of paragraph, keep track of height changes
553 for (int i = 0; rit != end; ++rit, ++i)
554 height -= rit->height();
558 InsetList::iterator ii = pit->insetlist.begin();
559 InsetList::iterator iend = pit->insetlist.end();
560 for (; ii != iend; ++ii) {
562 MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
563 ii->inset->metrics(mi, dim);
566 // rebreak the paragraph
567 for (pos_type z = 0; z < pit->size() + 1; ) {
569 z = rowBreakPoint(pit, row) + 1;
571 pit->rows.push_back(row);
575 // set height and fill and width of rows
576 int const ww = workWidth();
577 for (rit = pit->rows.begin(); rit != end; ++rit) {
578 int const f = fill(pit, rit, ww);
579 int const w = ww - f;
580 par_width = std::max(par_width, w);
583 prepareToPrint(pit, rit);
584 setHeightOfRow(pit, rit);
585 height += rit->height();
588 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
593 int LyXText::redoParagraphs(ParagraphList::iterator start,
594 ParagraphList::iterator end)
597 for ( ; start != end; ++start) {
598 int par_width = redoParagraphInternal(start);
599 pars_width = std::max(par_width, pars_width);
601 updateRowPositions();
606 void LyXText::redoParagraph(ParagraphList::iterator pit)
608 redoParagraphInternal(pit);
609 updateRowPositions();
613 void LyXText::fullRebreak()
615 redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
617 selection.cursor = cursor;
621 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
623 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
624 // << " workWidth: " << workWidth() << endl;
625 //Assert(mi.base.textwidth);
632 width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
635 dim.asc = firstRow()->ascent_of_text();
636 dim.des = height - dim.asc;
637 dim.wid = std::max(mi.base.textwidth, int(width));
641 // important for the screen
644 // the cursor set functions have a special mechanism. When they
645 // realize, that you left an empty paragraph, they will delete it.
646 // They also delete the corresponding row
648 // need the selection cursor:
649 void LyXText::setSelection()
651 TextCursor::setSelection();
656 void LyXText::clearSelection()
658 TextCursor::clearSelection();
660 // reset this in the bv_owner!
661 if (bv_owner && bv_owner->text)
662 bv_owner->text->xsel_cache.set(false);
666 void LyXText::cursorHome()
668 setCursor(cursor.par(), cursorRow()->pos());
672 void LyXText::cursorEnd()
674 if (cursor.par()->empty())
677 RowList::iterator rit = cursorRow();
678 RowList::iterator next_rit = boost::next(rit);
679 RowList::iterator end = boost::next(rit);
680 ParagraphList::iterator pit = cursor.par();
681 pos_type last_pos = lastPos(*pit, rit);
683 if (next_rit == end) {
687 (pit->getChar(last_pos) != ' ' && !pit->isNewline(last_pos))) {
692 setCursor(pit, last_pos);
696 void LyXText::cursorTop()
698 setCursor(ownerParagraphs().begin(), 0);
702 void LyXText::cursorBottom()
704 ParagraphList::iterator lastpit =
705 boost::prior(ownerParagraphs().end());
706 setCursor(lastpit, lastpit->size());
710 void LyXText::toggleFree(LyXFont const & font, bool toggleall)
712 // If the mask is completely neutral, tell user
713 if (font == LyXFont(LyXFont::ALL_IGNORE)) {
714 // Could only happen with user style
715 bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
719 // Try implicit word selection
720 // If there is a change in the language the implicit word selection
722 LyXCursor resetCursor = cursor;
723 bool implicitSelection = (font.language() == ignore_language
724 && font.number() == LyXFont::IGNORE)
725 ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
728 setFont(font, toggleall);
730 // Implicit selections are cleared afterwards
731 //and cursor is set to the original position.
732 if (implicitSelection) {
734 cursor = resetCursor;
735 setCursor(cursor.par(), cursor.pos());
736 selection.cursor = cursor;
741 string LyXText::getStringToIndex()
743 // Try implicit word selection
744 // If there is a change in the language the implicit word selection
746 LyXCursor const reset_cursor = cursor;
747 bool const implicitSelection =
748 selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
751 if (!selection.set())
752 bv()->owner()->message(_("Nothing to index!"));
753 else if (selection.start.par() != selection.end.par())
754 bv()->owner()->message(_("Cannot index more than one paragraph!"));
756 idxstring = selectionAsString(*bv()->buffer(), false);
758 // Reset cursors to their original position.
759 cursor = reset_cursor;
760 setCursor(cursor.par(), cursor.pos());
761 selection.cursor = cursor;
763 // Clear the implicit selection.
764 if (implicitSelection)
771 // the DTP switches for paragraphs. LyX will store them in the first
772 // physical paragraph. When a paragraph is broken, the top settings rest,
773 // the bottom settings are given to the new one. So I can make sure,
774 // they do not duplicate themself and you cannnot make dirty things with
777 void LyXText::setParagraph(bool line_top, bool line_bottom,
778 bool pagebreak_top, bool pagebreak_bottom,
779 VSpace const & space_top,
780 VSpace const & space_bottom,
781 Spacing const & spacing,
783 string const & labelwidthstring,
786 LyXCursor tmpcursor = cursor;
787 if (!selection.set()) {
788 selection.start = cursor;
789 selection.end = cursor;
792 // make sure that the depth behind the selection are restored, too
793 ParagraphList::iterator endpit = boost::next(selection.end.par());
794 ParagraphList::iterator undoendpit = endpit;
795 ParagraphList::iterator pars_end = ownerParagraphs().end();
797 if (endpit != pars_end && endpit->getDepth()) {
798 while (endpit != pars_end && endpit->getDepth()) {
802 } else if (endpit != pars_end) {
803 // because of parindents etc.
807 recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
808 boost::prior(undoendpit));
811 ParagraphList::iterator tmppit = selection.end.par();
813 while (tmppit != boost::prior(selection.start.par())) {
814 setCursor(tmppit, 0);
816 ParagraphList::iterator pit = cursor.par();
817 ParagraphParameters & params = pit->params();
819 params.lineTop(line_top);
820 params.lineBottom(line_bottom);
821 params.pagebreakTop(pagebreak_top);
822 params.pagebreakBottom(pagebreak_bottom);
823 params.spaceTop(space_top);
824 params.spaceBottom(space_bottom);
825 params.spacing(spacing);
826 // does the layout allow the new alignment?
827 LyXLayout_ptr const & layout = pit->layout();
829 if (align == LYX_ALIGN_LAYOUT)
830 align = layout->align;
831 if (align & layout->alignpossible) {
832 if (align == layout->align)
833 params.align(LYX_ALIGN_LAYOUT);
837 pit->setLabelWidthString(labelwidthstring);
838 params.noindent(noindent);
839 tmppit = boost::prior(pit);
842 redoParagraphs(selection.start.par(), endpit);
845 setCursor(selection.start.par(), selection.start.pos());
846 selection.cursor = cursor;
847 setCursor(selection.end.par(), selection.end.pos());
849 setCursor(tmpcursor.par(), tmpcursor.pos());
851 bv()->updateInset(inset_owner);
855 // set the counter of a paragraph. This includes the labels
856 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
858 LyXTextClass const & textclass = buf.params.getLyXTextClass();
859 LyXLayout_ptr const & layout = pit->layout();
861 if (pit != ownerParagraphs().begin()) {
863 pit->params().appendix(boost::prior(pit)->params().appendix());
864 if (!pit->params().appendix() &&
865 pit->params().startOfAppendix()) {
866 pit->params().appendix(true);
867 textclass.counters().reset();
869 pit->enumdepth = boost::prior(pit)->enumdepth;
870 pit->itemdepth = boost::prior(pit)->itemdepth;
872 pit->params().appendix(pit->params().startOfAppendix());
877 // Maybe we have to increment the enumeration depth.
878 // BUT, enumeration in a footnote is considered in isolation from its
879 // surrounding paragraph so don't increment if this is the
880 // first line of the footnote
881 // AND, bibliographies can't have their depth changed ie. they
882 // are always of depth 0
883 if (pit != ownerParagraphs().begin()
884 && boost::prior(pit)->getDepth() < pit->getDepth()
885 && boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI
886 && pit->enumdepth < 3
887 && layout->labeltype != LABEL_BIBLIO) {
891 // Maybe we have to decrement the enumeration depth, see note above
892 if (pit != ownerParagraphs().begin()
893 && boost::prior(pit)->getDepth() > pit->getDepth()
894 && layout->labeltype != LABEL_BIBLIO) {
895 pit->enumdepth = depthHook(pit, ownerParagraphs(),
896 pit->getDepth())->enumdepth;
899 if (!pit->params().labelString().empty()) {
900 pit->params().labelString(string());
903 if (layout->margintype == MARGIN_MANUAL) {
904 if (pit->params().labelWidthString().empty())
905 pit->setLabelWidthString(layout->labelstring());
907 pit->setLabelWidthString(string());
910 // is it a layout that has an automatic label?
911 if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
912 int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
916 if (i >= 0 && i <= buf.params.secnumdepth) {
920 textclass.counters().step(layout->latexname());
922 // Is there a label? Useful for Chapter layout
923 if (!pit->params().appendix()) {
924 s << buf.B_(layout->labelstring());
926 s << buf.B_(layout->labelstring_appendix());
929 // Use of an integer is here less than elegant. For now.
930 int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
931 if (!pit->params().appendix()) {
932 numbertype = "sectioning";
934 numbertype = "appendix";
935 if (pit->isRightToLeftPar(buf.params))
942 << textclass.counters()
943 .numberLabel(layout->latexname(),
944 numbertype, langtype, head);
946 pit->params().labelString(STRCONV(s.str()));
948 // reset enum counters
949 textclass.counters().reset("enum");
950 } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
951 textclass.counters().reset("enum");
952 } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
954 // Yes I know this is a really, really! bad solution
956 string enumcounter("enum");
958 switch (pit->enumdepth) {
970 // not a valid enumdepth...
974 textclass.counters().step(enumcounter);
976 s << textclass.counters()
977 .numberLabel(enumcounter, "enumeration");
978 pit->params().labelString(STRCONV(s.str()));
980 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
981 textclass.counters().step("bibitem");
982 int number = textclass.counters().value("bibitem");
983 if (pit->bibitem()) {
984 pit->bibitem()->setCounter(number);
985 pit->params().labelString(layout->labelstring());
987 // In biblio should't be following counters but...
989 string s = buf.B_(layout->labelstring());
992 if (layout->labeltype == LABEL_SENSITIVE) {
993 ParagraphList::iterator end = ownerParagraphs().end();
994 ParagraphList::iterator tmppit = pit;
997 while (tmppit != end && tmppit->inInset()
998 // the single '=' is intended below
999 && (in = tmppit->inInset()->owner()))
1001 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
1002 in->lyxCode() == InsetOld::WRAP_CODE) {
1006 Paragraph const * owner = &ownerPar(buf, in);
1007 tmppit = ownerParagraphs().begin();
1008 for ( ; tmppit != end; ++tmppit)
1009 if (&*tmppit == owner)
1017 if (in->lyxCode() == InsetOld::FLOAT_CODE)
1018 type = static_cast<InsetFloat*>(in)->params().type;
1019 else if (in->lyxCode() == InsetOld::WRAP_CODE)
1020 type = static_cast<InsetWrap*>(in)->params().type;
1024 Floating const & fl = textclass.floats().getType(type);
1026 textclass.counters().step(fl.type());
1028 // Doesn't work... yet.
1029 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1031 // par->SetLayout(0);
1032 // s = layout->labelstring;
1033 s = _("Senseless: ");
1036 pit->params().labelString(s);
1038 // reset the enumeration counter. They are always reset
1039 // when there is any other layout between
1040 // Just fall-through between the cases so that all
1041 // enum counters deeper than enumdepth is also reset.
1042 switch (pit->enumdepth) {
1044 textclass.counters().reset("enumi");
1046 textclass.counters().reset("enumii");
1048 textclass.counters().reset("enumiii");
1050 textclass.counters().reset("enumiv");
1056 // Updates all counters. Paragraphs with changed label string will be rebroken
1057 void LyXText::updateCounters()
1060 bv()->buffer()->params.getLyXTextClass().counters().reset();
1062 ParagraphList::iterator beg = ownerParagraphs().begin();
1063 ParagraphList::iterator end = ownerParagraphs().end();
1064 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1065 string const oldLabel = pit->params().labelString();
1067 size_t maxdepth = 0;
1069 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1071 if (pit->params().depth() > maxdepth)
1072 pit->params().depth(maxdepth);
1074 // setCounter can potentially change the labelString.
1075 setCounter(*bv()->buffer(), pit);
1077 string const & newLabel = pit->params().labelString();
1079 if (oldLabel != newLabel)
1085 void LyXText::insertInset(InsetOld * inset)
1087 if (!cursor.par()->insetAllowed(inset->lyxCode()))
1089 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1091 cursor.par()->insertInset(cursor.pos(), inset);
1092 // Just to rebreak and refresh correctly.
1093 // The character will not be inserted a second time
1094 insertChar(Paragraph::META_INSET);
1095 // If we enter a highly editable inset the cursor should be before
1096 // the inset. After an Undo LyX tries to call inset->edit(...)
1097 // and fails if the cursor is behind the inset and getInset
1098 // does not return the inset!
1099 if (isHighlyEditableInset(inset))
1105 void LyXText::cutSelection(bool doclear, bool realcut)
1107 // Stuff what we got on the clipboard. Even if there is no selection.
1109 // There is a problem with having the stuffing here in that the
1110 // larger the selection the slower LyX will get. This can be
1111 // solved by running the line below only when the selection has
1112 // finished. The solution used currently just works, to make it
1113 // faster we need to be more clever and probably also have more
1114 // calls to stuffClipboard. (Lgb)
1115 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1117 // This doesn't make sense, if there is no selection
1118 if (!selection.set())
1121 // OK, we have a selection. This is always between selection.start
1122 // and selection.end
1124 // make sure that the depth behind the selection are restored, too
1125 ParagraphList::iterator endpit = boost::next(selection.end.par());
1126 ParagraphList::iterator undoendpit = endpit;
1127 ParagraphList::iterator pars_end = ownerParagraphs().end();
1129 if (endpit != pars_end && endpit->getDepth()) {
1130 while (endpit != pars_end && endpit->getDepth()) {
1132 undoendpit = endpit;
1134 } else if (endpit != pars_end) {
1135 // because of parindents etc.
1139 recordUndo(bv(), Undo::DELETE, selection.start.par(),
1140 boost::prior(undoendpit));
1142 endpit = selection.end.par();
1143 int endpos = selection.end.pos();
1145 boost::tie(endpit, endpos) = realcut ?
1146 CutAndPaste::cutSelection(bv()->buffer()->params,
1148 selection.start.par(), endpit,
1149 selection.start.pos(), endpos,
1150 bv()->buffer()->params.textclass,
1152 : CutAndPaste::eraseSelection(bv()->buffer()->params,
1154 selection.start.par(), endpit,
1155 selection.start.pos(), endpos,
1157 // sometimes necessary
1159 selection.start.par()->stripLeadingSpaces();
1161 redoParagraphs(selection.start.par(), boost::next(endpit));
1162 // cutSelection can invalidate the cursor so we need to set
1164 // we prefer the end for when tracking changes
1168 // need a valid cursor. (Lgb)
1171 setCursor(cursor.par(), cursor.pos());
1172 selection.cursor = cursor;
1177 void LyXText::copySelection()
1179 // stuff the selection onto the X clipboard, from an explicit copy request
1180 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1182 // this doesnt make sense, if there is no selection
1183 if (!selection.set())
1186 // ok we have a selection. This is always between selection.start
1187 // and sel_end cursor
1189 // copy behind a space if there is one
1190 while (selection.start.par()->size() > selection.start.pos()
1191 && selection.start.par()->isLineSeparator(selection.start.pos())
1192 && (selection.start.par() != selection.end.par()
1193 || selection.start.pos() < selection.end.pos()))
1194 selection.start.pos(selection.start.pos() + 1);
1196 CutAndPaste::copySelection(selection.start.par(),
1197 selection.end.par(),
1198 selection.start.pos(), selection.end.pos(),
1199 bv()->buffer()->params.textclass);
1203 void LyXText::pasteSelection(size_t sel_index)
1205 // this does not make sense, if there is nothing to paste
1206 if (!CutAndPaste::checkPastePossible())
1209 recordUndo(bv(), Undo::INSERT, cursor.par());
1211 ParagraphList::iterator endpit;
1216 boost::tie(ppp, endpit) =
1217 CutAndPaste::pasteSelection(*bv()->buffer(),
1219 cursor.par(), cursor.pos(),
1220 bv()->buffer()->params.textclass,
1222 bufferErrors(*bv()->buffer(), el);
1223 bv()->showErrorList(_("Paste"));
1225 redoParagraphs(cursor.par(), endpit);
1227 setCursor(cursor.par(), cursor.pos());
1230 selection.cursor = cursor;
1231 setCursor(ppp.first, ppp.second);
1237 void LyXText::setSelectionRange(lyx::pos_type length)
1242 selection.cursor = cursor;
1249 // simple replacing. The font of the first selected character is used
1250 void LyXText::replaceSelectionWithString(string const & str)
1252 recordUndo(bv(), Undo::ATOMIC);
1255 if (!selection.set()) { // create a dummy selection
1256 selection.end = cursor;
1257 selection.start = cursor;
1260 // Get font setting before we cut
1261 pos_type pos = selection.end.pos();
1262 LyXFont const font = selection.start.par()
1263 ->getFontSettings(bv()->buffer()->params,
1264 selection.start.pos());
1266 // Insert the new string
1267 string::const_iterator cit = str.begin();
1268 string::const_iterator end = str.end();
1269 for (; cit != end; ++cit) {
1270 selection.end.par()->insertChar(pos, (*cit), font);
1274 // Cut the selection
1275 cutSelection(true, false);
1281 // needed to insert the selection
1282 void LyXText::insertStringAsLines(string const & str)
1284 ParagraphList::iterator pit = cursor.par();
1285 pos_type pos = cursor.pos();
1286 ParagraphList::iterator endpit = boost::next(cursor.par());
1288 recordUndo(bv(), Undo::ATOMIC);
1290 // only to be sure, should not be neccessary
1293 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1295 redoParagraphs(cursor.par(), endpit);
1296 setCursor(cursor.par(), cursor.pos());
1297 selection.cursor = cursor;
1298 setCursor(pit, pos);
1303 // turns double-CR to single CR, others where converted into one
1304 // blank. Then InsertStringAsLines is called
1305 void LyXText::insertStringAsParagraphs(string const & str)
1307 string linestr(str);
1308 bool newline_inserted = false;
1309 string::size_type const siz = linestr.length();
1311 for (string::size_type i = 0; i < siz; ++i) {
1312 if (linestr[i] == '\n') {
1313 if (newline_inserted) {
1314 // we know that \r will be ignored by
1315 // InsertStringA. Of course, it is a dirty
1316 // trick, but it works...
1317 linestr[i - 1] = '\r';
1321 newline_inserted = true;
1323 } else if (IsPrintable(linestr[i])) {
1324 newline_inserted = false;
1327 insertStringAsLines(linestr);
1331 bool LyXText::setCursor(ParagraphList::iterator pit,
1333 bool setfont, bool boundary)
1335 LyXCursor old_cursor = cursor;
1336 setCursorIntern(pit, pos, setfont, boundary);
1337 return deleteEmptyParagraphMechanism(old_cursor);
1341 void LyXText::redoCursor()
1343 #warning maybe the same for selections?
1344 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1348 void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
1349 pos_type pos, bool boundary)
1351 Assert(pit != ownerParagraphs().end());
1355 cur.boundary(boundary);
1359 // get the cursor y position in text
1361 RowList::iterator row = getRow(pit, pos);
1364 RowList::iterator old_row = row;
1365 // if we are before the first char of this row and are still in the
1366 // same paragraph and there is a previous row then put the cursor on
1367 // the end of the previous row
1368 cur.iy(y + row->baseline());
1370 // y is now the beginning of the cursor row
1371 y += row->baseline();
1372 // y is now the cursor baseline
1375 pos_type last = lastPrintablePos(*pit, old_row);
1377 // None of these should happen, but we're scaredy-cats
1378 if (pos > pit->size()) {
1379 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1382 } else if (pos > last + 1) {
1383 lyxerr << "dont like 2 please report" << endl;
1384 // This shouldn't happen.
1387 } else if (pos < row->pos()) {
1388 lyxerr << "dont like 3 please report" << endl;
1393 // now get the cursors x position
1394 float x = getCursorX(pit, row, pos, last, boundary);
1397 if (old_row != row) {
1398 x = getCursorX(pit, old_row, pos, last, boundary);
1405 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1406 pos_type pos, pos_type last, bool boundary) const
1408 pos_type cursor_vpos = 0;
1409 double x = rit->x();
1410 double fill_separator = rit->fill_separator();
1411 double fill_hfill = rit->fill_hfill();
1412 double fill_label_hfill = rit->fill_label_hfill();
1413 pos_type const rit_pos = rit->pos();
1416 cursor_vpos = rit_pos;
1417 else if (pos > last && !boundary)
1418 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params))
1419 ? rit_pos : last + 1;
1420 else if (pos > rit_pos && (pos > last || boundary))
1421 // Place cursor after char at (logical) position pos - 1
1422 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1423 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1425 // Place cursor before char at (logical) position pos
1426 cursor_vpos = (bidi_level(pos) % 2 == 0)
1427 ? log2vis(pos) : log2vis(pos) + 1;
1429 pos_type body_pos = pit->beginningOfBody();
1431 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1434 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1435 pos_type pos = vis2log(vpos);
1436 if (body_pos > 0 && pos == body_pos - 1) {
1437 x += fill_label_hfill +
1438 font_metrics::width(
1439 pit->layout()->labelsep, getLabelFont(pit));
1440 if (pit->isLineSeparator(body_pos - 1))
1441 x -= singleWidth(pit, body_pos - 1);
1444 if (hfillExpansion(*pit, rit, pos)) {
1445 x += singleWidth(pit, pos);
1446 if (pos >= body_pos)
1449 x += fill_label_hfill;
1450 } else if (pit->isSeparator(pos)) {
1451 x += singleWidth(pit, pos);
1452 if (pos >= body_pos)
1453 x += fill_separator;
1455 x += singleWidth(pit, pos);
1461 void LyXText::setCursorIntern(ParagraphList::iterator pit,
1462 pos_type pos, bool setfont, bool boundary)
1464 setCursor(cursor, pit, pos, boundary);
1470 void LyXText::setCurrentFont()
1472 pos_type pos = cursor.pos();
1473 ParagraphList::iterator pit = cursor.par();
1475 if (cursor.boundary() && pos > 0)
1479 if (pos == pit->size())
1481 else // potentional bug... BUG (Lgb)
1482 if (pit->isSeparator(pos)) {
1483 if (pos > cursorRow()->pos() &&
1484 bidi_level(pos) % 2 ==
1485 bidi_level(pos - 1) % 2)
1487 else if (pos + 1 < pit->size())
1492 current_font = pit->getFontSettings(bv()->buffer()->params, pos);
1493 real_current_font = getFont(pit, pos);
1495 if (cursor.pos() == pit->size() &&
1496 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1497 !cursor.boundary()) {
1498 Language const * lang =
1499 pit->getParLanguage(bv()->buffer()->params);
1500 current_font.setLanguage(lang);
1501 current_font.setNumber(LyXFont::OFF);
1502 real_current_font.setLanguage(lang);
1503 real_current_font.setNumber(LyXFont::OFF);
1508 // returns the column near the specified x-coordinate of the row
1509 // x is set to the real beginning of this column
1510 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1511 RowList::iterator rit, int & x, bool & boundary) const
1513 double tmpx = rit->x();
1514 double fill_separator = rit->fill_separator();
1515 double fill_hfill = rit->fill_hfill();
1516 double fill_label_hfill = rit->fill_label_hfill();
1518 pos_type vc = rit->pos();
1519 pos_type last = lastPrintablePos(*pit, rit);
1521 LyXLayout_ptr const & layout = pit->layout();
1523 bool left_side = false;
1525 pos_type body_pos = pit->beginningOfBody();
1526 double last_tmpx = tmpx;
1529 (body_pos - 1 > last ||
1530 !pit->isLineSeparator(body_pos - 1)))
1533 // check for empty row
1539 while (vc <= last && tmpx <= x) {
1542 if (body_pos > 0 && c == body_pos - 1) {
1543 tmpx += fill_label_hfill +
1544 font_metrics::width(layout->labelsep, getLabelFont(pit));
1545 if (pit->isLineSeparator(body_pos - 1))
1546 tmpx -= singleWidth(pit, body_pos - 1);
1549 if (hfillExpansion(*pit, rit, c)) {
1550 tmpx += singleWidth(pit, c);
1554 tmpx += fill_label_hfill;
1555 } else if (pit->isSeparator(c)) {
1556 tmpx += singleWidth(pit, c);
1558 tmpx += fill_separator;
1560 tmpx += singleWidth(pit, c);
1565 if ((tmpx + last_tmpx) / 2 > x) {
1570 if (vc > last + 1) // This shouldn't happen.
1574 // This (rtl_support test) is not needed, but gives
1575 // some speedup if rtl_support == false
1576 bool const lastrow = lyxrc.rtl_support
1577 && boost::next(rit) == pit->rows.end();
1579 // If lastrow is false, we don't need to compute
1580 // the value of rtl.
1581 bool const rtl = (lastrow)
1582 ? pit->isRightToLeftPar(bv()->buffer()->params)
1585 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1586 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1588 else if (vc == rit->pos()) {
1590 if (bidi_level(c) % 2 == 1)
1593 c = vis2log(vc - 1);
1594 bool const rtl = (bidi_level(c) % 2 == 1);
1595 if (left_side == rtl) {
1597 boundary = isBoundary(*bv()->buffer(), *pit, c);
1601 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1602 if (bidi_level(last) % 2 == 0)
1603 tmpx -= singleWidth(pit, last);
1605 tmpx += singleWidth(pit, last);
1615 void LyXText::setCursorFromCoordinates(int x, int y)
1617 LyXCursor old_cursor = cursor;
1618 setCursorFromCoordinates(cursor, x, y);
1620 deleteEmptyParagraphMechanism(old_cursor);
1624 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1626 // Get the row first.
1627 ParagraphList::iterator pit;
1628 RowList::iterator rit = getRowNearY(y, pit);
1632 pos_type const column = getColumnNearX(pit, rit, x, bound);
1634 cur.pos(rit->pos() + column);
1636 cur.y(y + rit->baseline());
1641 cur.boundary(bound);
1645 void LyXText::cursorLeft(bool internal)
1647 if (cursor.pos() > 0) {
1648 bool boundary = cursor.boundary();
1649 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1650 if (!internal && !boundary &&
1651 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
1652 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1653 } else if (cursor.par() != ownerParagraphs().begin()) {
1654 // steps into the paragraph above
1655 ParagraphList::iterator pit = boost::prior(cursor.par());
1656 setCursor(pit, pit->size());
1661 void LyXText::cursorRight(bool internal)
1663 bool const at_end = (cursor.pos() == cursor.par()->size());
1664 bool const at_newline = !at_end &&
1665 cursor.par()->isNewline(cursor.pos());
1667 if (!internal && cursor.boundary() && !at_newline)
1668 setCursor(cursor.par(), cursor.pos(), true, false);
1670 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1672 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
1673 setCursor(cursor.par(), cursor.pos(), true, true);
1674 } else if (boost::next(cursor.par()) != ownerParagraphs().end())
1675 setCursor(boost::next(cursor.par()), 0);
1679 void LyXText::cursorUp(bool selecting)
1682 int x = cursor.x_fix();
1683 int y = cursor.y() - cursorRow()->baseline() - 1;
1684 setCursorFromCoordinates(x, y);
1686 int topy = bv_owner->top_y();
1687 int y1 = cursor.iy() - topy;
1690 InsetOld * inset_hit = checkInsetHit(x, y1);
1691 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1692 inset_hit->localDispatch(
1693 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1697 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1698 cursorRow()->baseline() << endl;
1699 setCursorFromCoordinates(cursor.x_fix(),
1700 cursor.y() - cursorRow()->baseline() - 1);
1705 void LyXText::cursorDown(bool selecting)
1708 int x = cursor.x_fix();
1709 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1710 setCursorFromCoordinates(x, y);
1711 if (!selecting && cursorRow() == cursorIRow()) {
1712 int topy = bv_owner->top_y();
1713 int y1 = cursor.iy() - topy;
1716 InsetOld * inset_hit = checkInsetHit(x, y1);
1717 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1718 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1719 inset_hit->localDispatch(cmd);
1723 setCursorFromCoordinates(cursor.x_fix(),
1724 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1729 void LyXText::cursorUpParagraph()
1731 if (cursor.pos() > 0)
1732 setCursor(cursor.par(), 0);
1733 else if (cursor.par() != ownerParagraphs().begin())
1734 setCursor(boost::prior(cursor.par()), 0);
1738 void LyXText::cursorDownParagraph()
1740 ParagraphList::iterator par = cursor.par();
1741 ParagraphList::iterator next_par = boost::next(par);
1743 if (next_par != ownerParagraphs().end())
1744 setCursor(next_par, 0);
1746 setCursor(par, par->size());
1750 // fix the cursor `cur' after a characters has been deleted at `where'
1751 // position. Called by deleteEmptyParagraphMechanism
1752 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1754 // if cursor is not in the paragraph where the delete occured,
1756 if (cur.par() != where.par())
1759 // if cursor position is after the place where the delete occured,
1761 if (cur.pos() > where.pos())
1762 cur.pos(cur.pos()-1);
1764 // check also if we don't want to set the cursor on a spot behind the
1765 // pagragraph because we erased the last character.
1766 if (cur.pos() > cur.par()->size())
1767 cur.pos(cur.par()->size());
1769 // recompute row et al. for this cursor
1770 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1774 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1776 // Would be wrong to delete anything if we have a selection.
1777 if (selection.set())
1780 // We allow all kinds of "mumbo-jumbo" when freespacing.
1781 if (old_cursor.par()->isFreeSpacing())
1784 /* Ok I'll put some comments here about what is missing.
1785 I have fixed BackSpace (and thus Delete) to not delete
1786 double-spaces automagically. I have also changed Cut,
1787 Copy and Paste to hopefully do some sensible things.
1788 There are still some small problems that can lead to
1789 double spaces stored in the document file or space at
1790 the beginning of paragraphs. This happens if you have
1791 the cursor between to spaces and then save. Or if you
1792 cut and paste and the selection have a space at the
1793 beginning and then save right after the paste. I am
1794 sure none of these are very hard to fix, but I will
1795 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1796 that I can get some feedback. (Lgb)
1799 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1800 // delete the LineSeparator.
1803 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1804 // delete the LineSeparator.
1807 // If the pos around the old_cursor were spaces, delete one of them.
1808 if (old_cursor.par() != cursor.par()
1809 || old_cursor.pos() != cursor.pos()) {
1811 // Only if the cursor has really moved
1812 if (old_cursor.pos() > 0
1813 && old_cursor.pos() < old_cursor.par()->size()
1814 && old_cursor.par()->isLineSeparator(old_cursor.pos())
1815 && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
1816 bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
1817 redoParagraph(old_cursor.par());
1821 #ifdef WITH_WARNINGS
1822 #warning This will not work anymore when we have multiple views of the same buffer
1823 // In this case, we will have to correct also the cursors held by
1824 // other bufferviews. It will probably be easier to do that in a more
1825 // automated way in LyXCursor code. (JMarc 26/09/2001)
1827 // correct all cursors held by the LyXText
1828 fixCursorAfterDelete(cursor, old_cursor);
1829 fixCursorAfterDelete(selection.cursor, old_cursor);
1830 fixCursorAfterDelete(selection.start, old_cursor);
1831 fixCursorAfterDelete(selection.end, old_cursor);
1836 // don't delete anything if this is the ONLY paragraph!
1837 if (ownerParagraphs().size() == 1)
1840 // Do not delete empty paragraphs with keepempty set.
1841 if (old_cursor.par()->allowEmpty())
1844 // only do our magic if we changed paragraph
1845 if (old_cursor.par() == cursor.par())
1848 // record if we have deleted a paragraph
1849 // we can't possibly have deleted a paragraph before this point
1850 bool deleted = false;
1852 if (old_cursor.par()->empty() ||
1853 (old_cursor.par()->size() == 1 &&
1854 old_cursor.par()->isLineSeparator(0))) {
1855 // ok, we will delete something
1856 LyXCursor tmpcursor;
1860 bool selection_position_was_oldcursor_position = (
1861 selection.cursor.par() == old_cursor.par()
1862 && selection.cursor.pos() == old_cursor.pos());
1865 cursor = old_cursor; // that undo can restore the right cursor position
1867 ParagraphList::iterator endpit = boost::next(old_cursor.par());
1868 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1871 recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
1875 ownerParagraphs().erase(old_cursor.par());
1879 setCursorIntern(cursor.par(), cursor.pos());
1881 if (selection_position_was_oldcursor_position) {
1882 // correct selection
1883 selection.cursor = cursor;
1887 if (old_cursor.par()->stripLeadingSpaces()) {
1888 redoParagraph(old_cursor.par());
1890 setCursorIntern(cursor.par(), cursor.pos());
1891 selection.cursor = cursor;
1898 ParagraphList & LyXText::ownerParagraphs() const
1904 bool LyXText::isInInset() const
1906 // Sub-level has non-null bv owner and non-null inset owner.
1907 return inset_owner != 0;
1911 int defaultRowHeight()
1913 LyXFont const font(LyXFont::ALL_SANE);
1914 return int(font_metrics::maxAscent(font)
1915 + font_metrics::maxDescent(font) * 1.5);