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 "buffer_funcs.h"
26 #include "BufferView.h"
28 #include "CutAndPaste.h"
30 #include "errorlist.h"
32 #include "FloatList.h"
33 #include "funcrequest.h"
38 #include "lyxrow_funcs.h"
39 #include "metricsinfo.h"
40 #include "paragraph_funcs.h"
41 #include "ParagraphParameters.h"
42 #include "undo_funcs.h"
44 #include "frontends/font_metrics.h"
45 #include "frontends/LyXView.h"
47 #include "insets/insetbibitem.h"
48 #include "insets/insetenv.h"
49 #include "insets/insetfloat.h"
50 #include "insets/insetwrap.h"
52 #include "support/LAssert.h"
53 #include "support/lstrings.h"
54 #include "support/textutils.h"
56 #include <boost/tuple/tuple.hpp>
58 #include "support/std_sstream.h"
60 using namespace lyx::support;
64 using std::ostringstream;
69 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
70 ParagraphList & paragraphs)
71 : height(0), width(0), anchor_y_(0),
72 inset_owner(inset), the_locking_inset(0), bv_owner(bv),
73 in_inset_(ininset), paragraphs_(paragraphs)
78 void LyXText::init(BufferView * bview)
82 ParagraphList::iterator const beg = ownerParagraphs().begin();
83 ParagraphList::iterator const end = ownerParagraphs().end();
84 for (ParagraphList::iterator pit = beg; pit != end; ++pit)
92 current_font = getFont(beg, 0);
94 redoParagraphs(beg, end);
95 setCursorIntern(beg, 0);
96 selection.cursor = cursor;
102 // Gets the fully instantiated font at a given position in a paragraph
103 // Basically the same routine as Paragraph::getFont() in paragraph.C.
104 // The difference is that this one is used for displaying, and thus we
105 // are allowed to make cosmetic improvements. For instance make footnotes
107 LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
111 LyXLayout_ptr const & layout = pit->layout();
113 BufferParams const & params = bv()->buffer()->params();
115 // We specialize the 95% common case:
116 if (!pit->getDepth()) {
117 if (layout->labeltype == LABEL_MANUAL
118 && pos < pit->beginningOfBody()) {
120 LyXFont f = pit->getFontSettings(params, pos);
122 pit->inInset()->getDrawFont(f);
123 return f.realize(layout->reslabelfont);
125 LyXFont f = pit->getFontSettings(params, pos);
127 pit->inInset()->getDrawFont(f);
128 return f.realize(layout->resfont);
132 // The uncommon case need not be optimized as much
136 if (pos < pit->beginningOfBody()) {
138 layoutfont = layout->labelfont;
141 layoutfont = layout->font;
144 LyXFont tmpfont = pit->getFontSettings(params, pos);
145 tmpfont.realize(layoutfont);
148 pit->inInset()->getDrawFont(tmpfont);
150 // Realize with the fonts of lesser depth.
151 tmpfont.realize(outerFont(pit, ownerParagraphs()));
152 tmpfont.realize(defaultfont_);
158 LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const
160 LyXLayout_ptr const & layout = pit->layout();
162 if (!pit->getDepth())
163 return layout->resfont;
165 LyXFont font = layout->font;
166 // Realize with the fonts of lesser depth.
167 font.realize(outerFont(pit, ownerParagraphs()));
168 font.realize(defaultfont_);
174 LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
176 LyXLayout_ptr const & layout = pit->layout();
178 if (!pit->getDepth())
179 return layout->reslabelfont;
181 LyXFont font = layout->labelfont;
182 // Realize with the fonts of lesser depth.
183 font.realize(outerFont(pit, ownerParagraphs()));
184 font.realize(defaultfont_);
190 void LyXText::setCharFont(ParagraphList::iterator pit,
191 pos_type pos, LyXFont const & fnt,
194 BufferParams const & params = bv()->buffer()->params();
195 LyXFont font = getFont(pit, pos);
196 font.update(fnt, params.language, toggleall);
197 // Let the insets convert their font
198 if (pit->isInset(pos)) {
199 InsetOld * inset = pit->getInset(pos);
200 if (isEditableInset(inset)) {
201 static_cast<UpdatableInset *>(inset)
202 ->setFont(bv(), fnt, toggleall, true);
206 // Plug through to version below:
207 setCharFont(pit, pos, font);
211 void LyXText::setCharFont(
212 ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
215 LyXLayout_ptr const & layout = pit->layout();
217 // Get concrete layout font to reduce against
220 if (pos < pit->beginningOfBody())
221 layoutfont = layout->labelfont;
223 layoutfont = layout->font;
225 // Realize against environment font information
226 if (pit->getDepth()) {
227 ParagraphList::iterator tp = pit;
228 while (!layoutfont.resolved() &&
229 tp != ownerParagraphs().end() &&
231 tp = outerHook(tp, ownerParagraphs());
232 if (tp != ownerParagraphs().end())
233 layoutfont.realize(tp->layout()->font);
237 layoutfont.realize(defaultfont_);
239 // Now, reduce font against full layout font
240 font.reduce(layoutfont);
242 pit->setFont(pos, font);
246 InsetOld * LyXText::getInset() const
248 ParagraphList::iterator pit = cursor.par();
249 pos_type const pos = cursor.pos();
251 if (pos < pit->size() && pit->isInset(pos)) {
252 return pit->getInset(pos);
258 void LyXText::toggleInset()
260 InsetOld * inset = getInset();
261 // is there an editable inset at cursor position?
262 if (!isEditableInset(inset)) {
263 // No, try to see if we are inside a collapsable inset
264 if (inset_owner && inset_owner->owner()
265 && inset_owner->owner()->isOpen()) {
266 bv()->unlockInset(inset_owner->owner());
267 inset_owner->owner()->close(bv());
268 bv()->getLyXText()->cursorRight(bv());
272 //bv()->owner()->message(inset->editMessage());
274 // do we want to keep this?? (JMarc)
275 if (!isHighlyEditableInset(inset))
276 recordUndo(bv(), Undo::ATOMIC);
283 bv()->updateInset(inset);
287 /* used in setlayout */
288 // Asger is not sure we want to do this...
289 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
292 LyXLayout_ptr const & layout = par.layout();
293 pos_type const psize = par.size();
296 for (pos_type pos = 0; pos < psize; ++pos) {
297 if (pos < par.beginningOfBody())
298 layoutfont = layout->labelfont;
300 layoutfont = layout->font;
302 LyXFont tmpfont = par.getFontSettings(params, pos);
303 tmpfont.reduce(layoutfont);
304 par.setFont(pos, tmpfont);
309 ParagraphList::iterator
310 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
311 LyXCursor & send_cur,
312 string const & layout)
314 ParagraphList::iterator endpit = boost::next(send_cur.par());
315 ParagraphList::iterator undoendpit = endpit;
316 ParagraphList::iterator pars_end = ownerParagraphs().end();
318 if (endpit != pars_end && endpit->getDepth()) {
319 while (endpit != pars_end && endpit->getDepth()) {
323 } else if (endpit != pars_end) {
324 // because of parindents etc.
328 recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(undoendpit));
330 // ok we have a selection. This is always between sstart_cur
331 // and sel_end cursor
333 ParagraphList::iterator pit = sstart_cur.par();
334 ParagraphList::iterator epit = boost::next(send_cur.par());
336 BufferParams const & bufparams = bv()->buffer()->params();
337 LyXLayout_ptr const & lyxlayout =
338 bufparams.getLyXTextClass()[layout];
341 pit->applyLayout(lyxlayout);
342 makeFontEntriesLayoutSpecific(bufparams, *pit);
343 pit->params().spaceTop(lyxlayout->fill_top ?
344 VSpace(VSpace::VFILL)
345 : VSpace(VSpace::NONE));
346 pit->params().spaceBottom(lyxlayout->fill_bottom ?
347 VSpace(VSpace::VFILL)
348 : VSpace(VSpace::NONE));
349 if (lyxlayout->margintype == MARGIN_MANUAL)
350 pit->setLabelWidthString(lyxlayout->labelstring());
353 } while (pit != epit);
359 // set layout over selection and make a total rebreak of those paragraphs
360 void LyXText::setLayout(string const & layout)
362 LyXCursor tmpcursor = cursor; // store the current cursor
364 // if there is no selection just set the layout
365 // of the current paragraph
366 if (!selection.set()) {
367 selection.start = cursor; // dummy selection
368 selection.end = cursor;
371 // special handling of new environment insets
372 BufferParams const & params = bv()->buffer()->params();
373 LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
374 if (lyxlayout->is_environment) {
375 // move everything in a new environment inset
376 lyxerr << "setting layout " << layout << endl;
377 bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
378 bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
379 bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
380 InsetOld * inset = new InsetEnvironment(params, layout);
381 if (bv()->insertInset(inset)) {
383 //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
390 ParagraphList::iterator endpit = setLayout(cursor, selection.start,
391 selection.end, layout);
392 redoParagraphs(selection.start.par(), endpit);
394 // we have to reset the selection, because the
395 // geometry could have changed
396 setCursor(selection.start.par(), selection.start.pos(), false);
397 selection.cursor = cursor;
398 setCursor(selection.end.par(), selection.end.pos(), false);
402 setCursor(tmpcursor.par(), tmpcursor.pos(), true);
406 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
408 ParagraphList::iterator pit = cursor.par();
409 ParagraphList::iterator end = cursor.par();
410 ParagraphList::iterator start = pit;
412 if (selection.set()) {
413 pit = selection.start.par();
414 end = selection.end.par();
418 ParagraphList::iterator pastend = boost::next(end);
421 recordUndo(bv(), Undo::ATOMIC, start, end);
423 bool changed = false;
425 int prev_after_depth = 0;
426 #warning parlist ... could be nicer ?
427 if (start != ownerParagraphs().begin()) {
428 prev_after_depth = boost::prior(start)->getMaxDepthAfter();
432 int const depth = pit->params().depth();
433 if (type == bv_funcs::INC_DEPTH) {
434 if (depth < prev_after_depth
435 && pit->layout()->labeltype != LABEL_BIBLIO) {
438 pit->params().depth(depth + 1);
443 pit->params().depth(depth - 1);
446 prev_after_depth = pit->getMaxDepthAfter();
458 redoParagraphs(start, pastend);
460 // We need to actually move the text->cursor. I don't
461 // understand why ...
462 LyXCursor tmpcursor = cursor;
464 // we have to reset the visual selection because the
465 // geometry could have changed
466 if (selection.set()) {
467 setCursor(selection.start.par(), selection.start.pos());
468 selection.cursor = cursor;
469 setCursor(selection.end.par(), selection.end.pos());
472 // this handles the counter labels, and also fixes up
473 // depth values for follow-on (child) paragraphs
477 setCursor(tmpcursor.par(), tmpcursor.pos());
483 // set font over selection and make a total rebreak of those paragraphs
484 void LyXText::setFont(LyXFont const & font, bool toggleall)
486 // if there is no selection just set the current_font
487 if (!selection.set()) {
488 // Determine basis font
490 if (cursor.pos() < cursor.par()->beginningOfBody()) {
491 layoutfont = getLabelFont(cursor.par());
493 layoutfont = getLayoutFont(cursor.par());
495 // Update current font
496 real_current_font.update(font,
497 bv()->buffer()->params().language,
500 // Reduce to implicit settings
501 current_font = real_current_font;
502 current_font.reduce(layoutfont);
503 // And resolve it completely
504 real_current_font.realize(layoutfont);
509 LyXCursor tmpcursor = cursor; // store the current cursor
511 // ok we have a selection. This is always between sel_start_cursor
512 // and sel_end cursor
514 recordUndo(bv(), Undo::ATOMIC, selection.start.par(), selection.end.par());
516 cursor = selection.start;
517 while (cursor.par() != selection.end.par() ||
518 cursor.pos() < selection.end.pos())
520 if (cursor.pos() < cursor.par()->size()) {
521 // an open footnote should behave like a closed one
522 setCharFont(cursor.par(), cursor.pos(),
524 cursor.pos(cursor.pos() + 1);
527 cursor.par(boost::next(cursor.par()));
532 redoParagraph(selection.start.par());
534 // we have to reset the selection, because the
535 // geometry could have changed, but we keep
536 // it for user convenience
537 setCursor(selection.start.par(), selection.start.pos());
538 selection.cursor = cursor;
539 setCursor(selection.end.par(), selection.end.pos());
541 setCursor(tmpcursor.par(), tmpcursor.pos(), true,
542 tmpcursor.boundary());
546 int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
548 RowList::iterator rit = pit->rows.begin();
549 RowList::iterator end = pit->rows.end();
551 // remove rows of paragraph, keep track of height changes
552 for (int i = 0; rit != end; ++rit, ++i)
553 height -= rit->height();
557 InsetList::iterator ii = pit->insetlist.begin();
558 InsetList::iterator iend = pit->insetlist.end();
559 for (; ii != iend; ++ii) {
561 MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
562 ii->inset->metrics(mi, dim);
565 // rebreak the paragraph
566 for (pos_type z = 0; z < pit->size() + 1; ) {
568 z = rowBreakPoint(pit, row) + 1;
570 pit->rows.push_back(row);
574 // set height and fill and width of rows
575 int const ww = workWidth();
576 for (rit = pit->rows.begin(); rit != end; ++rit) {
577 int const f = fill(pit, rit, ww);
578 int const w = ww - f;
579 par_width = std::max(par_width, w);
582 prepareToPrint(pit, rit);
583 setHeightOfRow(pit, rit);
584 height += rit->height();
587 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
592 int LyXText::redoParagraphs(ParagraphList::iterator start,
593 ParagraphList::iterator end)
596 for ( ; start != end; ++start) {
597 int par_width = redoParagraphInternal(start);
598 pars_width = std::max(par_width, pars_width);
600 updateRowPositions();
605 void LyXText::redoParagraph(ParagraphList::iterator pit)
607 redoParagraphInternal(pit);
608 updateRowPositions();
612 void LyXText::fullRebreak()
614 redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
616 selection.cursor = cursor;
620 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
622 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
623 // << " workWidth: " << workWidth() << endl;
624 //Assert(mi.base.textwidth);
631 width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
634 dim.asc = firstRow()->ascent_of_text();
635 dim.des = height - dim.asc;
636 dim.wid = std::max(mi.base.textwidth, int(width));
640 // important for the screen
643 // the cursor set functions have a special mechanism. When they
644 // realize, that you left an empty paragraph, they will delete it.
645 // They also delete the corresponding row
647 // need the selection cursor:
648 void LyXText::setSelection()
650 TextCursor::setSelection();
655 void LyXText::clearSelection()
657 TextCursor::clearSelection();
659 // reset this in the bv_owner!
660 if (bv_owner && bv_owner->text)
661 bv_owner->text->xsel_cache.set(false);
665 void LyXText::cursorHome()
667 setCursor(cursor.par(), cursorRow()->pos());
671 void LyXText::cursorEnd()
673 setCursor(cursor.par(), cursorRow()->end() - 1);
677 void LyXText::cursorTop()
679 setCursor(ownerParagraphs().begin(), 0);
683 void LyXText::cursorBottom()
685 ParagraphList::iterator lastpit =
686 boost::prior(ownerParagraphs().end());
687 setCursor(lastpit, lastpit->size());
691 void LyXText::toggleFree(LyXFont const & font, bool toggleall)
693 // If the mask is completely neutral, tell user
694 if (font == LyXFont(LyXFont::ALL_IGNORE)) {
695 // Could only happen with user style
696 bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
700 // Try implicit word selection
701 // If there is a change in the language the implicit word selection
703 LyXCursor resetCursor = cursor;
704 bool implicitSelection = (font.language() == ignore_language
705 && font.number() == LyXFont::IGNORE)
706 ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
709 setFont(font, toggleall);
711 // Implicit selections are cleared afterwards
712 //and cursor is set to the original position.
713 if (implicitSelection) {
715 cursor = resetCursor;
716 setCursor(cursor.par(), cursor.pos());
717 selection.cursor = cursor;
722 string LyXText::getStringToIndex()
724 // Try implicit word selection
725 // If there is a change in the language the implicit word selection
727 LyXCursor const reset_cursor = cursor;
728 bool const implicitSelection =
729 selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
732 if (!selection.set())
733 bv()->owner()->message(_("Nothing to index!"));
734 else if (selection.start.par() != selection.end.par())
735 bv()->owner()->message(_("Cannot index more than one paragraph!"));
737 idxstring = selectionAsString(*bv()->buffer(), false);
739 // Reset cursors to their original position.
740 cursor = reset_cursor;
741 setCursor(cursor.par(), cursor.pos());
742 selection.cursor = cursor;
744 // Clear the implicit selection.
745 if (implicitSelection)
752 // the DTP switches for paragraphs. LyX will store them in the first
753 // physical paragraph. When a paragraph is broken, the top settings rest,
754 // the bottom settings are given to the new one. So I can make sure,
755 // they do not duplicate themself and you cannnot make dirty things with
758 void LyXText::setParagraph(bool line_top, bool line_bottom,
759 bool pagebreak_top, bool pagebreak_bottom,
760 VSpace const & space_top,
761 VSpace const & space_bottom,
762 Spacing const & spacing,
764 string const & labelwidthstring,
767 LyXCursor tmpcursor = cursor;
768 if (!selection.set()) {
769 selection.start = cursor;
770 selection.end = cursor;
773 // make sure that the depth behind the selection are restored, too
774 ParagraphList::iterator endpit = boost::next(selection.end.par());
775 ParagraphList::iterator undoendpit = endpit;
776 ParagraphList::iterator pars_end = ownerParagraphs().end();
778 if (endpit != pars_end && endpit->getDepth()) {
779 while (endpit != pars_end && endpit->getDepth()) {
783 } else if (endpit != pars_end) {
784 // because of parindents etc.
788 recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
789 boost::prior(undoendpit));
792 ParagraphList::iterator tmppit = selection.end.par();
794 while (tmppit != boost::prior(selection.start.par())) {
795 setCursor(tmppit, 0);
797 ParagraphList::iterator pit = cursor.par();
798 ParagraphParameters & params = pit->params();
800 params.lineTop(line_top);
801 params.lineBottom(line_bottom);
802 params.pagebreakTop(pagebreak_top);
803 params.pagebreakBottom(pagebreak_bottom);
804 params.spaceTop(space_top);
805 params.spaceBottom(space_bottom);
806 params.spacing(spacing);
807 // does the layout allow the new alignment?
808 LyXLayout_ptr const & layout = pit->layout();
810 if (align == LYX_ALIGN_LAYOUT)
811 align = layout->align;
812 if (align & layout->alignpossible) {
813 if (align == layout->align)
814 params.align(LYX_ALIGN_LAYOUT);
818 pit->setLabelWidthString(labelwidthstring);
819 params.noindent(noindent);
820 tmppit = boost::prior(pit);
823 redoParagraphs(selection.start.par(), endpit);
826 setCursor(selection.start.par(), selection.start.pos());
827 selection.cursor = cursor;
828 setCursor(selection.end.par(), selection.end.pos());
830 setCursor(tmpcursor.par(), tmpcursor.pos());
832 bv()->updateInset(inset_owner);
836 // set the counter of a paragraph. This includes the labels
837 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
839 BufferParams const & bufparams = buf.params();
840 LyXTextClass const & textclass = bufparams.getLyXTextClass();
841 LyXLayout_ptr const & layout = pit->layout();
843 if (pit != ownerParagraphs().begin()) {
845 pit->params().appendix(boost::prior(pit)->params().appendix());
846 if (!pit->params().appendix() &&
847 pit->params().startOfAppendix()) {
848 pit->params().appendix(true);
849 textclass.counters().reset();
851 pit->enumdepth = boost::prior(pit)->enumdepth;
852 pit->itemdepth = boost::prior(pit)->itemdepth;
854 pit->params().appendix(pit->params().startOfAppendix());
859 // Maybe we have to increment the enumeration depth.
860 // BUT, enumeration in a footnote is considered in isolation from its
861 // surrounding paragraph so don't increment if this is the
862 // first line of the footnote
863 // AND, bibliographies can't have their depth changed ie. they
864 // are always of depth 0
865 if (pit != ownerParagraphs().begin()
866 && boost::prior(pit)->getDepth() < pit->getDepth()
867 && boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI
868 && pit->enumdepth < 3
869 && layout->labeltype != LABEL_BIBLIO) {
873 // Maybe we have to decrement the enumeration depth, see note above
874 if (pit != ownerParagraphs().begin()
875 && boost::prior(pit)->getDepth() > pit->getDepth()
876 && layout->labeltype != LABEL_BIBLIO) {
877 pit->enumdepth = depthHook(pit, ownerParagraphs(),
878 pit->getDepth())->enumdepth;
881 if (!pit->params().labelString().empty()) {
882 pit->params().labelString(string());
885 if (layout->margintype == MARGIN_MANUAL) {
886 if (pit->params().labelWidthString().empty())
887 pit->setLabelWidthString(layout->labelstring());
889 pit->setLabelWidthString(string());
892 // is it a layout that has an automatic label?
893 if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
894 int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
898 if (i >= 0 && i <= bufparams.secnumdepth) {
902 textclass.counters().step(layout->latexname());
904 // Is there a label? Useful for Chapter layout
905 if (!pit->params().appendix()) {
906 s << buf.B_(layout->labelstring());
908 s << buf.B_(layout->labelstring_appendix());
911 // Use of an integer is here less than elegant. For now.
912 int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
913 if (!pit->params().appendix()) {
914 numbertype = "sectioning";
916 numbertype = "appendix";
917 if (pit->isRightToLeftPar(bufparams))
924 << textclass.counters()
925 .numberLabel(layout->latexname(),
926 numbertype, langtype, head);
928 pit->params().labelString(STRCONV(s.str()));
930 // reset enum counters
931 textclass.counters().reset("enum");
932 } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
933 textclass.counters().reset("enum");
934 } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
936 // Yes I know this is a really, really! bad solution
938 string enumcounter("enum");
940 switch (pit->enumdepth) {
952 // not a valid enumdepth...
956 textclass.counters().step(enumcounter);
958 s << textclass.counters()
959 .numberLabel(enumcounter, "enumeration");
960 pit->params().labelString(STRCONV(s.str()));
962 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
963 textclass.counters().step("bibitem");
964 int number = textclass.counters().value("bibitem");
965 if (pit->bibitem()) {
966 pit->bibitem()->setCounter(number);
967 pit->params().labelString(layout->labelstring());
969 // In biblio should't be following counters but...
971 string s = buf.B_(layout->labelstring());
974 if (layout->labeltype == LABEL_SENSITIVE) {
975 ParagraphList::iterator end = ownerParagraphs().end();
976 ParagraphList::iterator tmppit = pit;
979 while (tmppit != end && tmppit->inInset()
980 // the single '=' is intended below
981 && (in = tmppit->inInset()->owner()))
983 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
984 in->lyxCode() == InsetOld::WRAP_CODE) {
988 Paragraph const * owner = &ownerPar(buf, in);
989 tmppit = ownerParagraphs().begin();
990 for ( ; tmppit != end; ++tmppit)
991 if (&*tmppit == owner)
999 if (in->lyxCode() == InsetOld::FLOAT_CODE)
1000 type = static_cast<InsetFloat*>(in)->params().type;
1001 else if (in->lyxCode() == InsetOld::WRAP_CODE)
1002 type = static_cast<InsetWrap*>(in)->params().type;
1006 Floating const & fl = textclass.floats().getType(type);
1008 textclass.counters().step(fl.type());
1010 // Doesn't work... yet.
1011 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1013 // par->SetLayout(0);
1014 // s = layout->labelstring;
1015 s = _("Senseless: ");
1018 pit->params().labelString(s);
1020 // reset the enumeration counter. They are always reset
1021 // when there is any other layout between
1022 // Just fall-through between the cases so that all
1023 // enum counters deeper than enumdepth is also reset.
1024 switch (pit->enumdepth) {
1026 textclass.counters().reset("enumi");
1028 textclass.counters().reset("enumii");
1030 textclass.counters().reset("enumiii");
1032 textclass.counters().reset("enumiv");
1038 // Updates all counters. Paragraphs with changed label string will be rebroken
1039 void LyXText::updateCounters()
1042 bv()->buffer()->params().getLyXTextClass().counters().reset();
1044 ParagraphList::iterator beg = ownerParagraphs().begin();
1045 ParagraphList::iterator end = ownerParagraphs().end();
1046 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1047 string const oldLabel = pit->params().labelString();
1049 size_t maxdepth = 0;
1051 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1053 if (pit->params().depth() > maxdepth)
1054 pit->params().depth(maxdepth);
1056 // setCounter can potentially change the labelString.
1057 setCounter(*bv()->buffer(), pit);
1059 string const & newLabel = pit->params().labelString();
1061 if (oldLabel != newLabel)
1067 void LyXText::insertInset(InsetOld * inset)
1069 if (!cursor.par()->insetAllowed(inset->lyxCode()))
1071 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1073 cursor.par()->insertInset(cursor.pos(), inset);
1074 // Just to rebreak and refresh correctly.
1075 // The character will not be inserted a second time
1076 insertChar(Paragraph::META_INSET);
1077 // If we enter a highly editable inset the cursor should be before
1078 // the inset. After an Undo LyX tries to call inset->edit(...)
1079 // and fails if the cursor is behind the inset and getInset
1080 // does not return the inset!
1081 if (isHighlyEditableInset(inset))
1087 void LyXText::cutSelection(bool doclear, bool realcut)
1089 // Stuff what we got on the clipboard. Even if there is no selection.
1091 // There is a problem with having the stuffing here in that the
1092 // larger the selection the slower LyX will get. This can be
1093 // solved by running the line below only when the selection has
1094 // finished. The solution used currently just works, to make it
1095 // faster we need to be more clever and probably also have more
1096 // calls to stuffClipboard. (Lgb)
1097 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1099 // This doesn't make sense, if there is no selection
1100 if (!selection.set())
1103 // OK, we have a selection. This is always between selection.start
1104 // and selection.end
1106 // make sure that the depth behind the selection are restored, too
1107 ParagraphList::iterator endpit = boost::next(selection.end.par());
1108 ParagraphList::iterator undoendpit = endpit;
1109 ParagraphList::iterator pars_end = ownerParagraphs().end();
1111 if (endpit != pars_end && endpit->getDepth()) {
1112 while (endpit != pars_end && endpit->getDepth()) {
1114 undoendpit = endpit;
1116 } else if (endpit != pars_end) {
1117 // because of parindents etc.
1121 recordUndo(bv(), Undo::DELETE, selection.start.par(),
1122 boost::prior(undoendpit));
1124 endpit = selection.end.par();
1125 int endpos = selection.end.pos();
1127 BufferParams const & bufparams = bv()->buffer()->params();
1128 boost::tie(endpit, endpos) = realcut ?
1129 CutAndPaste::cutSelection(bufparams,
1131 selection.start.par(), endpit,
1132 selection.start.pos(), endpos,
1133 bufparams.textclass,
1135 : CutAndPaste::eraseSelection(bufparams,
1137 selection.start.par(), endpit,
1138 selection.start.pos(), endpos,
1140 // sometimes necessary
1142 selection.start.par()->stripLeadingSpaces();
1144 redoParagraphs(selection.start.par(), boost::next(endpit));
1145 // cutSelection can invalidate the cursor so we need to set
1147 // we prefer the end for when tracking changes
1151 // need a valid cursor. (Lgb)
1154 setCursor(cursor.par(), cursor.pos());
1155 selection.cursor = cursor;
1160 void LyXText::copySelection()
1162 // stuff the selection onto the X clipboard, from an explicit copy request
1163 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1165 // this doesnt make sense, if there is no selection
1166 if (!selection.set())
1169 // ok we have a selection. This is always between selection.start
1170 // and sel_end cursor
1172 // copy behind a space if there is one
1173 while (selection.start.par()->size() > selection.start.pos()
1174 && selection.start.par()->isLineSeparator(selection.start.pos())
1175 && (selection.start.par() != selection.end.par()
1176 || selection.start.pos() < selection.end.pos()))
1177 selection.start.pos(selection.start.pos() + 1);
1179 CutAndPaste::copySelection(selection.start.par(),
1180 selection.end.par(),
1181 selection.start.pos(), selection.end.pos(),
1182 bv()->buffer()->params().textclass);
1186 void LyXText::pasteSelection(size_t sel_index)
1188 // this does not make sense, if there is nothing to paste
1189 if (!CutAndPaste::checkPastePossible())
1192 recordUndo(bv(), Undo::INSERT, cursor.par());
1194 ParagraphList::iterator endpit;
1199 boost::tie(ppp, endpit) =
1200 CutAndPaste::pasteSelection(*bv()->buffer(),
1202 cursor.par(), cursor.pos(),
1203 bv()->buffer()->params().textclass,
1205 bufferErrors(*bv()->buffer(), el);
1206 bv()->showErrorList(_("Paste"));
1208 redoParagraphs(cursor.par(), endpit);
1210 setCursor(cursor.par(), cursor.pos());
1213 selection.cursor = cursor;
1214 setCursor(ppp.first, ppp.second);
1220 void LyXText::setSelectionRange(lyx::pos_type length)
1225 selection.cursor = cursor;
1232 // simple replacing. The font of the first selected character is used
1233 void LyXText::replaceSelectionWithString(string const & str)
1235 recordUndo(bv(), Undo::ATOMIC);
1238 if (!selection.set()) { // create a dummy selection
1239 selection.end = cursor;
1240 selection.start = cursor;
1243 // Get font setting before we cut
1244 pos_type pos = selection.end.pos();
1245 LyXFont const font = selection.start.par()
1246 ->getFontSettings(bv()->buffer()->params(),
1247 selection.start.pos());
1249 // Insert the new string
1250 string::const_iterator cit = str.begin();
1251 string::const_iterator end = str.end();
1252 for (; cit != end; ++cit) {
1253 selection.end.par()->insertChar(pos, (*cit), font);
1257 // Cut the selection
1258 cutSelection(true, false);
1264 // needed to insert the selection
1265 void LyXText::insertStringAsLines(string const & str)
1267 ParagraphList::iterator pit = cursor.par();
1268 pos_type pos = cursor.pos();
1269 ParagraphList::iterator endpit = boost::next(cursor.par());
1271 recordUndo(bv(), Undo::ATOMIC);
1273 // only to be sure, should not be neccessary
1276 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1278 redoParagraphs(cursor.par(), endpit);
1279 setCursor(cursor.par(), cursor.pos());
1280 selection.cursor = cursor;
1281 setCursor(pit, pos);
1286 // turns double-CR to single CR, others where converted into one
1287 // blank. Then InsertStringAsLines is called
1288 void LyXText::insertStringAsParagraphs(string const & str)
1290 string linestr(str);
1291 bool newline_inserted = false;
1292 string::size_type const siz = linestr.length();
1294 for (string::size_type i = 0; i < siz; ++i) {
1295 if (linestr[i] == '\n') {
1296 if (newline_inserted) {
1297 // we know that \r will be ignored by
1298 // InsertStringA. Of course, it is a dirty
1299 // trick, but it works...
1300 linestr[i - 1] = '\r';
1304 newline_inserted = true;
1306 } else if (IsPrintable(linestr[i])) {
1307 newline_inserted = false;
1310 insertStringAsLines(linestr);
1314 bool LyXText::setCursor(ParagraphList::iterator pit,
1316 bool setfont, bool boundary)
1318 LyXCursor old_cursor = cursor;
1319 setCursorIntern(pit, pos, setfont, boundary);
1320 return deleteEmptyParagraphMechanism(old_cursor);
1324 void LyXText::redoCursor()
1326 #warning maybe the same for selections?
1327 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1331 void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
1332 pos_type pos, bool boundary)
1334 Assert(pit != ownerParagraphs().end());
1338 cur.boundary(boundary);
1342 // get the cursor y position in text
1344 RowList::iterator row = getRow(pit, pos);
1347 // y is now the beginning of the cursor row
1348 y += row->baseline();
1349 // y is now the cursor baseline
1352 pos_type last = lastPos(*pit, row);
1354 // None of these should happen, but we're scaredy-cats
1355 if (pos > pit->size()) {
1356 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1359 } else if (pos > last + 1) {
1360 lyxerr << "dont like 2 please report" << endl;
1361 // This shouldn't happen.
1364 } else if (pos < row->pos()) {
1365 lyxerr << "dont like 3 please report" << endl;
1370 // now get the cursors x position
1371 float x = getCursorX(pit, row, pos, last, boundary);
1377 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1378 pos_type pos, pos_type last, bool boundary) const
1380 pos_type cursor_vpos = 0;
1381 double x = rit->x();
1382 double fill_separator = rit->fill_separator();
1383 double fill_hfill = rit->fill_hfill();
1384 double fill_label_hfill = rit->fill_label_hfill();
1385 pos_type const rit_pos = rit->pos();
1388 cursor_vpos = rit_pos;
1389 else if (pos > last && !boundary)
1390 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
1391 ? rit_pos : last + 1;
1392 else if (pos > rit_pos && (pos > last || boundary))
1393 // Place cursor after char at (logical) position pos - 1
1394 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1395 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1397 // Place cursor before char at (logical) position pos
1398 cursor_vpos = (bidi_level(pos) % 2 == 0)
1399 ? log2vis(pos) : log2vis(pos) + 1;
1401 pos_type body_pos = pit->beginningOfBody();
1403 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1406 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1407 pos_type pos = vis2log(vpos);
1408 if (body_pos > 0 && pos == body_pos - 1) {
1409 x += fill_label_hfill +
1410 font_metrics::width(
1411 pit->layout()->labelsep, getLabelFont(pit));
1412 if (pit->isLineSeparator(body_pos - 1))
1413 x -= singleWidth(pit, body_pos - 1);
1416 if (hfillExpansion(*pit, rit, pos)) {
1417 x += singleWidth(pit, pos);
1418 if (pos >= body_pos)
1421 x += fill_label_hfill;
1422 } else if (pit->isSeparator(pos)) {
1423 x += singleWidth(pit, pos);
1424 if (pos >= body_pos)
1425 x += fill_separator;
1427 x += singleWidth(pit, pos);
1433 void LyXText::setCursorIntern(ParagraphList::iterator pit,
1434 pos_type pos, bool setfont, bool boundary)
1436 setCursor(cursor, pit, pos, boundary);
1442 void LyXText::setCurrentFont()
1444 pos_type pos = cursor.pos();
1445 ParagraphList::iterator pit = cursor.par();
1447 if (cursor.boundary() && pos > 0)
1451 if (pos == pit->size())
1453 else // potentional bug... BUG (Lgb)
1454 if (pit->isSeparator(pos)) {
1455 if (pos > cursorRow()->pos() &&
1456 bidi_level(pos) % 2 ==
1457 bidi_level(pos - 1) % 2)
1459 else if (pos + 1 < pit->size())
1464 BufferParams const & bufparams = bv()->buffer()->params();
1465 current_font = pit->getFontSettings(bufparams, pos);
1466 real_current_font = getFont(pit, pos);
1468 if (cursor.pos() == pit->size() &&
1469 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1470 !cursor.boundary()) {
1471 Language const * lang =
1472 pit->getParLanguage(bufparams);
1473 current_font.setLanguage(lang);
1474 current_font.setNumber(LyXFont::OFF);
1475 real_current_font.setLanguage(lang);
1476 real_current_font.setNumber(LyXFont::OFF);
1481 // returns the column near the specified x-coordinate of the row
1482 // x is set to the real beginning of this column
1483 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1484 RowList::iterator rit, int & x, bool & boundary) const
1486 double tmpx = rit->x();
1487 double fill_separator = rit->fill_separator();
1488 double fill_hfill = rit->fill_hfill();
1489 double fill_label_hfill = rit->fill_label_hfill();
1491 pos_type vc = rit->pos();
1492 pos_type last = lastPos(*pit, rit);
1494 LyXLayout_ptr const & layout = pit->layout();
1496 bool left_side = false;
1498 pos_type body_pos = pit->beginningOfBody();
1499 double last_tmpx = tmpx;
1502 (body_pos - 1 > last ||
1503 !pit->isLineSeparator(body_pos - 1)))
1506 // check for empty row
1512 while (vc <= last && tmpx <= x) {
1515 if (body_pos > 0 && c == body_pos - 1) {
1516 tmpx += fill_label_hfill +
1517 font_metrics::width(layout->labelsep, getLabelFont(pit));
1518 if (pit->isLineSeparator(body_pos - 1))
1519 tmpx -= singleWidth(pit, body_pos - 1);
1522 if (hfillExpansion(*pit, rit, c)) {
1523 tmpx += singleWidth(pit, c);
1527 tmpx += fill_label_hfill;
1528 } else if (pit->isSeparator(c)) {
1529 tmpx += singleWidth(pit, c);
1531 tmpx += fill_separator;
1533 tmpx += singleWidth(pit, c);
1538 if ((tmpx + last_tmpx) / 2 > x) {
1543 if (vc > last + 1) // This shouldn't happen.
1547 // This (rtl_support test) is not needed, but gives
1548 // some speedup if rtl_support == false
1549 bool const lastrow = lyxrc.rtl_support
1550 && boost::next(rit) == pit->rows.end();
1552 // If lastrow is false, we don't need to compute
1553 // the value of rtl.
1554 bool const rtl = (lastrow)
1555 ? pit->isRightToLeftPar(bv()->buffer()->params())
1558 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1559 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1561 else if (vc == rit->pos()) {
1563 if (bidi_level(c) % 2 == 1)
1566 c = vis2log(vc - 1);
1567 bool const rtl = (bidi_level(c) % 2 == 1);
1568 if (left_side == rtl) {
1570 boundary = isBoundary(*bv()->buffer(), *pit, c);
1574 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1575 if (bidi_level(last) % 2 == 0)
1576 tmpx -= singleWidth(pit, last);
1578 tmpx += singleWidth(pit, last);
1588 void LyXText::setCursorFromCoordinates(int x, int y)
1590 LyXCursor old_cursor = cursor;
1591 setCursorFromCoordinates(cursor, x, y);
1593 deleteEmptyParagraphMechanism(old_cursor);
1597 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1599 // Get the row first.
1600 ParagraphList::iterator pit;
1601 RowList::iterator rit = getRowNearY(y, pit);
1605 pos_type const column = getColumnNearX(pit, rit, x, bound);
1607 cur.pos(rit->pos() + column);
1609 cur.y(y + rit->baseline());
1611 cur.boundary(bound);
1615 void LyXText::cursorLeft(bool internal)
1617 if (cursor.pos() > 0) {
1618 bool boundary = cursor.boundary();
1619 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1620 if (!internal && !boundary &&
1621 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
1622 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1623 } else if (cursor.par() != ownerParagraphs().begin()) {
1624 // steps into the paragraph above
1625 ParagraphList::iterator pit = boost::prior(cursor.par());
1626 setCursor(pit, pit->size());
1631 void LyXText::cursorRight(bool internal)
1633 bool const at_end = (cursor.pos() == cursor.par()->size());
1634 bool const at_newline = !at_end &&
1635 cursor.par()->isNewline(cursor.pos());
1637 if (!internal && cursor.boundary() && !at_newline)
1638 setCursor(cursor.par(), cursor.pos(), true, false);
1640 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1642 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
1643 setCursor(cursor.par(), cursor.pos(), true, true);
1644 } else if (boost::next(cursor.par()) != ownerParagraphs().end())
1645 setCursor(boost::next(cursor.par()), 0);
1649 void LyXText::cursorUp(bool selecting)
1652 int x = cursor.x_fix();
1653 int y = cursor.y() - cursorRow()->baseline() - 1;
1654 setCursorFromCoordinates(x, y);
1656 int topy = bv_owner->top_y();
1657 int y1 = cursor.y() - topy;
1660 InsetOld * inset_hit = checkInsetHit(x, y1);
1661 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1662 inset_hit->localDispatch(
1663 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1667 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1668 cursorRow()->baseline() << endl;
1669 setCursorFromCoordinates(cursor.x_fix(),
1670 cursor.y() - cursorRow()->baseline() - 1);
1675 void LyXText::cursorDown(bool selecting)
1678 int x = cursor.x_fix();
1679 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1680 setCursorFromCoordinates(x, y);
1681 if (!selecting && cursorRow() == cursorIRow()) {
1682 int topy = bv_owner->top_y();
1683 int y1 = cursor.y() - topy;
1686 InsetOld * inset_hit = checkInsetHit(x, y1);
1687 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1688 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1689 inset_hit->localDispatch(cmd);
1693 setCursorFromCoordinates(cursor.x_fix(),
1694 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1699 void LyXText::cursorUpParagraph()
1701 if (cursor.pos() > 0)
1702 setCursor(cursor.par(), 0);
1703 else if (cursor.par() != ownerParagraphs().begin())
1704 setCursor(boost::prior(cursor.par()), 0);
1708 void LyXText::cursorDownParagraph()
1710 ParagraphList::iterator par = cursor.par();
1711 ParagraphList::iterator next_par = boost::next(par);
1713 if (next_par != ownerParagraphs().end())
1714 setCursor(next_par, 0);
1716 setCursor(par, par->size());
1720 // fix the cursor `cur' after a characters has been deleted at `where'
1721 // position. Called by deleteEmptyParagraphMechanism
1722 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1724 // if cursor is not in the paragraph where the delete occured,
1726 if (cur.par() != where.par())
1729 // if cursor position is after the place where the delete occured,
1731 if (cur.pos() > where.pos())
1732 cur.pos(cur.pos()-1);
1734 // check also if we don't want to set the cursor on a spot behind the
1735 // pagragraph because we erased the last character.
1736 if (cur.pos() > cur.par()->size())
1737 cur.pos(cur.par()->size());
1739 // recompute row et al. for this cursor
1740 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1744 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1746 // Would be wrong to delete anything if we have a selection.
1747 if (selection.set())
1750 // We allow all kinds of "mumbo-jumbo" when freespacing.
1751 if (old_cursor.par()->isFreeSpacing())
1754 /* Ok I'll put some comments here about what is missing.
1755 I have fixed BackSpace (and thus Delete) to not delete
1756 double-spaces automagically. I have also changed Cut,
1757 Copy and Paste to hopefully do some sensible things.
1758 There are still some small problems that can lead to
1759 double spaces stored in the document file or space at
1760 the beginning of paragraphs. This happens if you have
1761 the cursor between to spaces and then save. Or if you
1762 cut and paste and the selection have a space at the
1763 beginning and then save right after the paste. I am
1764 sure none of these are very hard to fix, but I will
1765 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1766 that I can get some feedback. (Lgb)
1769 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1770 // delete the LineSeparator.
1773 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1774 // delete the LineSeparator.
1777 // If the pos around the old_cursor were spaces, delete one of them.
1778 if (old_cursor.par() != cursor.par()
1779 || old_cursor.pos() != cursor.pos()) {
1781 // Only if the cursor has really moved
1782 if (old_cursor.pos() > 0
1783 && old_cursor.pos() < old_cursor.par()->size()
1784 && old_cursor.par()->isLineSeparator(old_cursor.pos())
1785 && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
1786 bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
1787 redoParagraph(old_cursor.par());
1791 #ifdef WITH_WARNINGS
1792 #warning This will not work anymore when we have multiple views of the same buffer
1793 // In this case, we will have to correct also the cursors held by
1794 // other bufferviews. It will probably be easier to do that in a more
1795 // automated way in LyXCursor code. (JMarc 26/09/2001)
1797 // correct all cursors held by the LyXText
1798 fixCursorAfterDelete(cursor, old_cursor);
1799 fixCursorAfterDelete(selection.cursor, old_cursor);
1800 fixCursorAfterDelete(selection.start, old_cursor);
1801 fixCursorAfterDelete(selection.end, old_cursor);
1806 // don't delete anything if this is the ONLY paragraph!
1807 if (ownerParagraphs().size() == 1)
1810 // Do not delete empty paragraphs with keepempty set.
1811 if (old_cursor.par()->allowEmpty())
1814 // only do our magic if we changed paragraph
1815 if (old_cursor.par() == cursor.par())
1818 // record if we have deleted a paragraph
1819 // we can't possibly have deleted a paragraph before this point
1820 bool deleted = false;
1822 if (old_cursor.par()->empty() ||
1823 (old_cursor.par()->size() == 1 &&
1824 old_cursor.par()->isLineSeparator(0))) {
1825 // ok, we will delete something
1826 LyXCursor tmpcursor;
1830 bool selection_position_was_oldcursor_position = (
1831 selection.cursor.par() == old_cursor.par()
1832 && selection.cursor.pos() == old_cursor.pos());
1835 cursor = old_cursor; // that undo can restore the right cursor position
1837 ParagraphList::iterator endpit = boost::next(old_cursor.par());
1838 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1841 recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
1845 ownerParagraphs().erase(old_cursor.par());
1849 setCursorIntern(cursor.par(), cursor.pos());
1851 if (selection_position_was_oldcursor_position) {
1852 // correct selection
1853 selection.cursor = cursor;
1857 if (old_cursor.par()->stripLeadingSpaces()) {
1858 redoParagraph(old_cursor.par());
1860 setCursorIntern(cursor.par(), cursor.pos());
1861 selection.cursor = cursor;
1868 ParagraphList & LyXText::ownerParagraphs() const
1874 bool LyXText::isInInset() const
1876 // Sub-level has non-null bv owner and non-null inset owner.
1877 return inset_owner != 0;
1881 int defaultRowHeight()
1883 LyXFont const font(LyXFont::ALL_SANE);
1884 return int(font_metrics::maxAscent(font)
1885 + font_metrics::maxDescent(font) * 1.5);