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.
23 #include "support/std_sstream.h"
24 #include "funcrequest.h"
25 #include "frontends/LyXView.h"
26 #include "undo_funcs.h"
28 #include "buffer_funcs.h"
30 #include "BufferView.h"
31 #include "CutAndPaste.h"
32 #include "frontends/font_metrics.h"
36 #include "FloatList.h"
38 #include "ParagraphParameters.h"
40 #include "lyxrow_funcs.h"
41 #include "metricsinfo.h"
42 #include "paragraph_funcs.h"
45 #include "insets/insetbibitem.h"
46 #include "insets/insetenv.h"
47 #include "insets/insetfloat.h"
48 #include "insets/insetwrap.h"
50 #include "support/LAssert.h"
51 #include "support/textutils.h"
52 #include "support/lstrings.h"
54 #include <boost/tuple/tuple.hpp>
57 using namespace lyx::support;
59 using std::ostringstream;
68 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
69 ParagraphList & paragraphs)
70 : height(0), width(0), anchor_y_(0),
71 inset_owner(inset), the_locking_inset(0), bv_owner(bv),
72 in_inset_(ininset), paragraphs_(paragraphs)
77 void LyXText::init(BufferView * bview)
81 ParagraphList::iterator const beg = ownerParagraphs().begin();
82 ParagraphList::iterator const end = ownerParagraphs().end();
83 for (ParagraphList::iterator pit = beg; pit != end; ++pit)
91 current_font = getFont(beg, 0);
93 redoParagraphs(beg, end);
94 setCursorIntern(beg, 0);
95 selection.cursor = cursor;
101 // Gets the fully instantiated font at a given position in a paragraph
102 // Basically the same routine as Paragraph::getFont() in paragraph.C.
103 // The difference is that this one is used for displaying, and thus we
104 // are allowed to make cosmetic improvements. For instance make footnotes
106 LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
110 LyXLayout_ptr const & layout = pit->layout();
112 BufferParams const & params = bv()->buffer()->params;
114 // We specialize the 95% common case:
115 if (!pit->getDepth()) {
116 if (layout->labeltype == LABEL_MANUAL
117 && pos < pit->beginningOfBody()) {
119 LyXFont f = pit->getFontSettings(params, pos);
121 pit->inInset()->getDrawFont(f);
122 return f.realize(layout->reslabelfont);
124 LyXFont f = pit->getFontSettings(params, pos);
126 pit->inInset()->getDrawFont(f);
127 return f.realize(layout->resfont);
131 // The uncommon case need not be optimized as much
135 if (pos < pit->beginningOfBody()) {
137 layoutfont = layout->labelfont;
140 layoutfont = layout->font;
143 LyXFont tmpfont = pit->getFontSettings(params, pos);
144 tmpfont.realize(layoutfont);
147 pit->inInset()->getDrawFont(tmpfont);
149 // Realize with the fonts of lesser depth.
150 tmpfont.realize(outerFont(pit, ownerParagraphs()));
151 tmpfont.realize(defaultfont_);
157 LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const
159 LyXLayout_ptr const & layout = pit->layout();
161 if (!pit->getDepth())
162 return layout->resfont;
164 LyXFont font = layout->font;
165 // Realize with the fonts of lesser depth.
166 font.realize(outerFont(pit, ownerParagraphs()));
167 font.realize(defaultfont_);
173 LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
175 LyXLayout_ptr const & layout = pit->layout();
177 if (!pit->getDepth())
178 return layout->reslabelfont;
180 LyXFont font = layout->labelfont;
181 // Realize with the fonts of lesser depth.
182 font.realize(outerFont(pit, ownerParagraphs()));
183 font.realize(defaultfont_);
189 void LyXText::setCharFont(ParagraphList::iterator pit,
190 pos_type pos, LyXFont const & fnt,
193 BufferParams const & params = bv()->buffer()->params;
194 LyXFont font = getFont(pit, pos);
195 font.update(fnt, params.language, toggleall);
196 // Let the insets convert their font
197 if (pit->isInset(pos)) {
198 InsetOld * inset = pit->getInset(pos);
199 if (isEditableInset(inset)) {
200 static_cast<UpdatableInset *>(inset)
201 ->setFont(bv(), fnt, toggleall, true);
205 // Plug through to version below:
206 setCharFont(pit, pos, font);
210 void LyXText::setCharFont(
211 ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
214 LyXLayout_ptr const & layout = pit->layout();
216 // Get concrete layout font to reduce against
219 if (pos < pit->beginningOfBody())
220 layoutfont = layout->labelfont;
222 layoutfont = layout->font;
224 // Realize against environment font information
225 if (pit->getDepth()) {
226 ParagraphList::iterator tp = pit;
227 while (!layoutfont.resolved() &&
228 tp != ownerParagraphs().end() &&
230 tp = outerHook(tp, ownerParagraphs());
231 if (tp != ownerParagraphs().end())
232 layoutfont.realize(tp->layout()->font);
236 layoutfont.realize(defaultfont_);
238 // Now, reduce font against full layout font
239 font.reduce(layoutfont);
241 pit->setFont(pos, font);
245 InsetOld * LyXText::getInset() const
247 ParagraphList::iterator pit = cursor.par();
248 pos_type const pos = cursor.pos();
250 if (pos < pit->size() && pit->isInset(pos)) {
251 return pit->getInset(pos);
257 void LyXText::toggleInset()
259 InsetOld * inset = getInset();
260 // is there an editable inset at cursor position?
261 if (!isEditableInset(inset)) {
262 // No, try to see if we are inside a collapsable inset
263 if (inset_owner && inset_owner->owner()
264 && inset_owner->owner()->isOpen()) {
265 bv()->unlockInset(inset_owner->owner());
266 inset_owner->owner()->close(bv());
267 bv()->getLyXText()->cursorRight(bv());
271 //bv()->owner()->message(inset->editMessage());
273 // do we want to keep this?? (JMarc)
274 if (!isHighlyEditableInset(inset))
275 recordUndo(bv(), Undo::ATOMIC);
282 bv()->updateInset(inset);
286 /* used in setlayout */
287 // Asger is not sure we want to do this...
288 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
291 LyXLayout_ptr const & layout = par.layout();
292 pos_type const psize = par.size();
295 for (pos_type pos = 0; pos < psize; ++pos) {
296 if (pos < par.beginningOfBody())
297 layoutfont = layout->labelfont;
299 layoutfont = layout->font;
301 LyXFont tmpfont = par.getFontSettings(params, pos);
302 tmpfont.reduce(layoutfont);
303 par.setFont(pos, tmpfont);
308 ParagraphList::iterator
309 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
310 LyXCursor & send_cur,
311 string const & layout)
313 ParagraphList::iterator endpit = boost::next(send_cur.par());
314 ParagraphList::iterator undoendpit = endpit;
315 ParagraphList::iterator pars_end = ownerParagraphs().end();
317 if (endpit != pars_end && endpit->getDepth()) {
318 while (endpit != pars_end && endpit->getDepth()) {
322 } else if (endpit != pars_end) {
323 // because of parindents etc.
327 recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(undoendpit));
329 // ok we have a selection. This is always between sstart_cur
330 // and sel_end cursor
332 ParagraphList::iterator pit = sstart_cur.par();
333 ParagraphList::iterator epit = boost::next(send_cur.par());
335 LyXLayout_ptr const & lyxlayout =
336 bv()->buffer()->params.getLyXTextClass()[layout];
339 pit->applyLayout(lyxlayout);
340 makeFontEntriesLayoutSpecific(bv()->buffer()->params, *pit);
341 pit->params().spaceTop(lyxlayout->fill_top ?
342 VSpace(VSpace::VFILL)
343 : VSpace(VSpace::NONE));
344 pit->params().spaceBottom(lyxlayout->fill_bottom ?
345 VSpace(VSpace::VFILL)
346 : VSpace(VSpace::NONE));
347 if (lyxlayout->margintype == MARGIN_MANUAL)
348 pit->setLabelWidthString(lyxlayout->labelstring());
351 } while (pit != epit);
357 // set layout over selection and make a total rebreak of those paragraphs
358 void LyXText::setLayout(string const & layout)
360 LyXCursor tmpcursor = cursor; // store the current cursor
362 // if there is no selection just set the layout
363 // of the current paragraph
364 if (!selection.set()) {
365 selection.start = cursor; // dummy selection
366 selection.end = cursor;
369 // special handling of new environment insets
370 BufferParams const & params = bv()->buffer()->params;
371 LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
372 if (lyxlayout->is_environment) {
373 // move everything in a new environment inset
374 lyxerr << "setting layout " << layout << endl;
375 bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
376 bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
377 bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
378 InsetOld * inset = new InsetEnvironment(params, layout);
379 if (bv()->insertInset(inset)) {
381 //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
388 ParagraphList::iterator endpit = setLayout(cursor, selection.start,
389 selection.end, layout);
390 redoParagraphs(selection.start.par(), endpit);
392 // we have to reset the selection, because the
393 // geometry could have changed
394 setCursor(selection.start.par(), selection.start.pos(), false);
395 selection.cursor = cursor;
396 setCursor(selection.end.par(), selection.end.pos(), false);
400 setCursor(tmpcursor.par(), tmpcursor.pos(), true);
404 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
406 ParagraphList::iterator pit = cursor.par();
407 ParagraphList::iterator end = cursor.par();
408 ParagraphList::iterator start = pit;
410 if (selection.set()) {
411 pit = selection.start.par();
412 end = selection.end.par();
416 ParagraphList::iterator pastend = boost::next(end);
419 recordUndo(bv(), Undo::ATOMIC, start, end);
421 bool changed = false;
423 int prev_after_depth = 0;
424 #warning parlist ... could be nicer ?
425 if (start != ownerParagraphs().begin()) {
426 prev_after_depth = boost::prior(start)->getMaxDepthAfter();
430 int const depth = pit->params().depth();
431 if (type == bv_funcs::INC_DEPTH) {
432 if (depth < prev_after_depth
433 && pit->layout()->labeltype != LABEL_BIBLIO) {
436 pit->params().depth(depth + 1);
441 pit->params().depth(depth - 1);
444 prev_after_depth = pit->getMaxDepthAfter();
456 redoParagraphs(start, pastend);
458 // We need to actually move the text->cursor. I don't
459 // understand why ...
460 LyXCursor tmpcursor = cursor;
462 // we have to reset the visual selection because the
463 // geometry could have changed
464 if (selection.set()) {
465 setCursor(selection.start.par(), selection.start.pos());
466 selection.cursor = cursor;
467 setCursor(selection.end.par(), selection.end.pos());
470 // this handles the counter labels, and also fixes up
471 // depth values for follow-on (child) paragraphs
475 setCursor(tmpcursor.par(), tmpcursor.pos());
481 // set font over selection and make a total rebreak of those paragraphs
482 void LyXText::setFont(LyXFont const & font, bool toggleall)
484 // if there is no selection just set the current_font
485 if (!selection.set()) {
486 // Determine basis font
488 if (cursor.pos() < cursor.par()->beginningOfBody()) {
489 layoutfont = getLabelFont(cursor.par());
491 layoutfont = getLayoutFont(cursor.par());
493 // Update current font
494 real_current_font.update(font,
495 bv()->buffer()->params.language,
498 // Reduce to implicit settings
499 current_font = real_current_font;
500 current_font.reduce(layoutfont);
501 // And resolve it completely
502 real_current_font.realize(layoutfont);
507 LyXCursor tmpcursor = cursor; // store the current cursor
509 // ok we have a selection. This is always between sel_start_cursor
510 // and sel_end cursor
512 recordUndo(bv(), Undo::ATOMIC, selection.start.par(), selection.end.par());
514 cursor = selection.start;
515 while (cursor.par() != selection.end.par() ||
516 cursor.pos() < selection.end.pos())
518 if (cursor.pos() < cursor.par()->size()) {
519 // an open footnote should behave like a closed one
520 setCharFont(cursor.par(), cursor.pos(),
522 cursor.pos(cursor.pos() + 1);
525 cursor.par(boost::next(cursor.par()));
530 redoParagraph(selection.start.par());
532 // we have to reset the selection, because the
533 // geometry could have changed, but we keep
534 // it for user convenience
535 setCursor(selection.start.par(), selection.start.pos());
536 selection.cursor = cursor;
537 setCursor(selection.end.par(), selection.end.pos());
539 setCursor(tmpcursor.par(), tmpcursor.pos(), true,
540 tmpcursor.boundary());
544 int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
546 RowList::iterator rit = pit->rows.begin();
547 RowList::iterator end = pit->rows.end();
549 // remove rows of paragraph, keep track of height changes
550 for (int i = 0; rit != end; ++rit, ++i)
551 height -= rit->height();
555 InsetList::iterator ii = pit->insetlist.begin();
556 InsetList::iterator iend = pit->insetlist.end();
557 for (; ii != iend; ++ii) {
559 MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
560 ii->inset->metrics(mi, dim);
563 // rebreak the paragraph
564 for (pos_type z = 0; z < pit->size() + 1; ) {
566 z = rowBreakPoint(pit, row) + 1;
568 pit->rows.push_back(row);
572 // set height and fill and width of rows
573 int const ww = workWidth();
574 for (rit = pit->rows.begin(); rit != end; ++rit) {
575 int const f = fill(pit, rit, ww);
576 int const w = ww - f;
577 par_width = std::max(par_width, w);
580 prepareToPrint(pit, rit);
581 setHeightOfRow(pit, rit);
582 height += rit->height();
585 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
590 int LyXText::redoParagraphs(ParagraphList::iterator start,
591 ParagraphList::iterator end)
594 for ( ; start != end; ++start) {
595 int par_width = redoParagraphInternal(start);
596 pars_width = std::max(par_width, pars_width);
598 updateRowPositions();
603 void LyXText::redoParagraph(ParagraphList::iterator pit)
605 redoParagraphInternal(pit);
606 updateRowPositions();
610 void LyXText::fullRebreak()
612 redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
614 selection.cursor = cursor;
618 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
620 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
621 // << " workWidth: " << workWidth() << endl;
622 //Assert(mi.base.textwidth);
629 width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
632 dim.asc = firstRow()->ascent_of_text();
633 dim.des = height - dim.asc;
634 dim.wid = std::max(mi.base.textwidth, int(width));
638 // important for the screen
641 // the cursor set functions have a special mechanism. When they
642 // realize, that you left an empty paragraph, they will delete it.
643 // They also delete the corresponding row
645 // need the selection cursor:
646 void LyXText::setSelection()
648 TextCursor::setSelection();
653 void LyXText::clearSelection()
655 TextCursor::clearSelection();
657 // reset this in the bv_owner!
658 if (bv_owner && bv_owner->text)
659 bv_owner->text->xsel_cache.set(false);
663 void LyXText::cursorHome()
665 setCursor(cursor.par(), cursorRow()->pos());
669 void LyXText::cursorEnd()
671 setCursor(cursor.par(), cursorRow()->end() - 1);
675 void LyXText::cursorTop()
677 setCursor(ownerParagraphs().begin(), 0);
681 void LyXText::cursorBottom()
683 ParagraphList::iterator lastpit =
684 boost::prior(ownerParagraphs().end());
685 setCursor(lastpit, lastpit->size());
689 void LyXText::toggleFree(LyXFont const & font, bool toggleall)
691 // If the mask is completely neutral, tell user
692 if (font == LyXFont(LyXFont::ALL_IGNORE)) {
693 // Could only happen with user style
694 bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
698 // Try implicit word selection
699 // If there is a change in the language the implicit word selection
701 LyXCursor resetCursor = cursor;
702 bool implicitSelection = (font.language() == ignore_language
703 && font.number() == LyXFont::IGNORE)
704 ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
707 setFont(font, toggleall);
709 // Implicit selections are cleared afterwards
710 //and cursor is set to the original position.
711 if (implicitSelection) {
713 cursor = resetCursor;
714 setCursor(cursor.par(), cursor.pos());
715 selection.cursor = cursor;
720 string LyXText::getStringToIndex()
722 // Try implicit word selection
723 // If there is a change in the language the implicit word selection
725 LyXCursor const reset_cursor = cursor;
726 bool const implicitSelection =
727 selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
730 if (!selection.set())
731 bv()->owner()->message(_("Nothing to index!"));
732 else if (selection.start.par() != selection.end.par())
733 bv()->owner()->message(_("Cannot index more than one paragraph!"));
735 idxstring = selectionAsString(*bv()->buffer(), false);
737 // Reset cursors to their original position.
738 cursor = reset_cursor;
739 setCursor(cursor.par(), cursor.pos());
740 selection.cursor = cursor;
742 // Clear the implicit selection.
743 if (implicitSelection)
750 // the DTP switches for paragraphs. LyX will store them in the first
751 // physical paragraph. When a paragraph is broken, the top settings rest,
752 // the bottom settings are given to the new one. So I can make sure,
753 // they do not duplicate themself and you cannnot make dirty things with
756 void LyXText::setParagraph(bool line_top, bool line_bottom,
757 bool pagebreak_top, bool pagebreak_bottom,
758 VSpace const & space_top,
759 VSpace const & space_bottom,
760 Spacing const & spacing,
762 string const & labelwidthstring,
765 LyXCursor tmpcursor = cursor;
766 if (!selection.set()) {
767 selection.start = cursor;
768 selection.end = cursor;
771 // make sure that the depth behind the selection are restored, too
772 ParagraphList::iterator endpit = boost::next(selection.end.par());
773 ParagraphList::iterator undoendpit = endpit;
774 ParagraphList::iterator pars_end = ownerParagraphs().end();
776 if (endpit != pars_end && endpit->getDepth()) {
777 while (endpit != pars_end && endpit->getDepth()) {
781 } else if (endpit != pars_end) {
782 // because of parindents etc.
786 recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
787 boost::prior(undoendpit));
790 ParagraphList::iterator tmppit = selection.end.par();
792 while (tmppit != boost::prior(selection.start.par())) {
793 setCursor(tmppit, 0);
795 ParagraphList::iterator pit = cursor.par();
796 ParagraphParameters & params = pit->params();
798 params.lineTop(line_top);
799 params.lineBottom(line_bottom);
800 params.pagebreakTop(pagebreak_top);
801 params.pagebreakBottom(pagebreak_bottom);
802 params.spaceTop(space_top);
803 params.spaceBottom(space_bottom);
804 params.spacing(spacing);
805 // does the layout allow the new alignment?
806 LyXLayout_ptr const & layout = pit->layout();
808 if (align == LYX_ALIGN_LAYOUT)
809 align = layout->align;
810 if (align & layout->alignpossible) {
811 if (align == layout->align)
812 params.align(LYX_ALIGN_LAYOUT);
816 pit->setLabelWidthString(labelwidthstring);
817 params.noindent(noindent);
818 tmppit = boost::prior(pit);
821 redoParagraphs(selection.start.par(), endpit);
824 setCursor(selection.start.par(), selection.start.pos());
825 selection.cursor = cursor;
826 setCursor(selection.end.par(), selection.end.pos());
828 setCursor(tmpcursor.par(), tmpcursor.pos());
830 bv()->updateInset(inset_owner);
834 // set the counter of a paragraph. This includes the labels
835 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
837 LyXTextClass const & textclass = buf.params.getLyXTextClass();
838 LyXLayout_ptr const & layout = pit->layout();
840 if (pit != ownerParagraphs().begin()) {
842 pit->params().appendix(boost::prior(pit)->params().appendix());
843 if (!pit->params().appendix() &&
844 pit->params().startOfAppendix()) {
845 pit->params().appendix(true);
846 textclass.counters().reset();
848 pit->enumdepth = boost::prior(pit)->enumdepth;
849 pit->itemdepth = boost::prior(pit)->itemdepth;
851 pit->params().appendix(pit->params().startOfAppendix());
856 // Maybe we have to increment the enumeration depth.
857 // BUT, enumeration in a footnote is considered in isolation from its
858 // surrounding paragraph so don't increment if this is the
859 // first line of the footnote
860 // AND, bibliographies can't have their depth changed ie. they
861 // are always of depth 0
862 if (pit != ownerParagraphs().begin()
863 && boost::prior(pit)->getDepth() < pit->getDepth()
864 && boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI
865 && pit->enumdepth < 3
866 && layout->labeltype != LABEL_BIBLIO) {
870 // Maybe we have to decrement the enumeration depth, see note above
871 if (pit != ownerParagraphs().begin()
872 && boost::prior(pit)->getDepth() > pit->getDepth()
873 && layout->labeltype != LABEL_BIBLIO) {
874 pit->enumdepth = depthHook(pit, ownerParagraphs(),
875 pit->getDepth())->enumdepth;
878 if (!pit->params().labelString().empty()) {
879 pit->params().labelString(string());
882 if (layout->margintype == MARGIN_MANUAL) {
883 if (pit->params().labelWidthString().empty())
884 pit->setLabelWidthString(layout->labelstring());
886 pit->setLabelWidthString(string());
889 // is it a layout that has an automatic label?
890 if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
891 int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
895 if (i >= 0 && i <= buf.params.secnumdepth) {
899 textclass.counters().step(layout->latexname());
901 // Is there a label? Useful for Chapter layout
902 if (!pit->params().appendix()) {
903 s << buf.B_(layout->labelstring());
905 s << buf.B_(layout->labelstring_appendix());
908 // Use of an integer is here less than elegant. For now.
909 int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
910 if (!pit->params().appendix()) {
911 numbertype = "sectioning";
913 numbertype = "appendix";
914 if (pit->isRightToLeftPar(buf.params))
921 << textclass.counters()
922 .numberLabel(layout->latexname(),
923 numbertype, langtype, head);
925 pit->params().labelString(STRCONV(s.str()));
927 // reset enum counters
928 textclass.counters().reset("enum");
929 } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
930 textclass.counters().reset("enum");
931 } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
933 // Yes I know this is a really, really! bad solution
935 string enumcounter("enum");
937 switch (pit->enumdepth) {
949 // not a valid enumdepth...
953 textclass.counters().step(enumcounter);
955 s << textclass.counters()
956 .numberLabel(enumcounter, "enumeration");
957 pit->params().labelString(STRCONV(s.str()));
959 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
960 textclass.counters().step("bibitem");
961 int number = textclass.counters().value("bibitem");
962 if (pit->bibitem()) {
963 pit->bibitem()->setCounter(number);
964 pit->params().labelString(layout->labelstring());
966 // In biblio should't be following counters but...
968 string s = buf.B_(layout->labelstring());
971 if (layout->labeltype == LABEL_SENSITIVE) {
972 ParagraphList::iterator end = ownerParagraphs().end();
973 ParagraphList::iterator tmppit = pit;
976 while (tmppit != end && tmppit->inInset()
977 // the single '=' is intended below
978 && (in = tmppit->inInset()->owner()))
980 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
981 in->lyxCode() == InsetOld::WRAP_CODE) {
985 Paragraph const * owner = &ownerPar(buf, in);
986 tmppit = ownerParagraphs().begin();
987 for ( ; tmppit != end; ++tmppit)
988 if (&*tmppit == owner)
996 if (in->lyxCode() == InsetOld::FLOAT_CODE)
997 type = static_cast<InsetFloat*>(in)->params().type;
998 else if (in->lyxCode() == InsetOld::WRAP_CODE)
999 type = static_cast<InsetWrap*>(in)->params().type;
1003 Floating const & fl = textclass.floats().getType(type);
1005 textclass.counters().step(fl.type());
1007 // Doesn't work... yet.
1008 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1010 // par->SetLayout(0);
1011 // s = layout->labelstring;
1012 s = _("Senseless: ");
1015 pit->params().labelString(s);
1017 // reset the enumeration counter. They are always reset
1018 // when there is any other layout between
1019 // Just fall-through between the cases so that all
1020 // enum counters deeper than enumdepth is also reset.
1021 switch (pit->enumdepth) {
1023 textclass.counters().reset("enumi");
1025 textclass.counters().reset("enumii");
1027 textclass.counters().reset("enumiii");
1029 textclass.counters().reset("enumiv");
1035 // Updates all counters. Paragraphs with changed label string will be rebroken
1036 void LyXText::updateCounters()
1039 bv()->buffer()->params.getLyXTextClass().counters().reset();
1041 ParagraphList::iterator beg = ownerParagraphs().begin();
1042 ParagraphList::iterator end = ownerParagraphs().end();
1043 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1044 string const oldLabel = pit->params().labelString();
1046 size_t maxdepth = 0;
1048 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1050 if (pit->params().depth() > maxdepth)
1051 pit->params().depth(maxdepth);
1053 // setCounter can potentially change the labelString.
1054 setCounter(*bv()->buffer(), pit);
1056 string const & newLabel = pit->params().labelString();
1058 if (oldLabel != newLabel)
1064 void LyXText::insertInset(InsetOld * inset)
1066 if (!cursor.par()->insetAllowed(inset->lyxCode()))
1068 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1070 cursor.par()->insertInset(cursor.pos(), inset);
1071 // Just to rebreak and refresh correctly.
1072 // The character will not be inserted a second time
1073 insertChar(Paragraph::META_INSET);
1074 // If we enter a highly editable inset the cursor should be before
1075 // the inset. After an Undo LyX tries to call inset->edit(...)
1076 // and fails if the cursor is behind the inset and getInset
1077 // does not return the inset!
1078 if (isHighlyEditableInset(inset))
1084 void LyXText::cutSelection(bool doclear, bool realcut)
1086 // Stuff what we got on the clipboard. Even if there is no selection.
1088 // There is a problem with having the stuffing here in that the
1089 // larger the selection the slower LyX will get. This can be
1090 // solved by running the line below only when the selection has
1091 // finished. The solution used currently just works, to make it
1092 // faster we need to be more clever and probably also have more
1093 // calls to stuffClipboard. (Lgb)
1094 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1096 // This doesn't make sense, if there is no selection
1097 if (!selection.set())
1100 // OK, we have a selection. This is always between selection.start
1101 // and selection.end
1103 // make sure that the depth behind the selection are restored, too
1104 ParagraphList::iterator endpit = boost::next(selection.end.par());
1105 ParagraphList::iterator undoendpit = endpit;
1106 ParagraphList::iterator pars_end = ownerParagraphs().end();
1108 if (endpit != pars_end && endpit->getDepth()) {
1109 while (endpit != pars_end && endpit->getDepth()) {
1111 undoendpit = endpit;
1113 } else if (endpit != pars_end) {
1114 // because of parindents etc.
1118 recordUndo(bv(), Undo::DELETE, selection.start.par(),
1119 boost::prior(undoendpit));
1121 endpit = selection.end.par();
1122 int endpos = selection.end.pos();
1124 boost::tie(endpit, endpos) = realcut ?
1125 CutAndPaste::cutSelection(bv()->buffer()->params,
1127 selection.start.par(), endpit,
1128 selection.start.pos(), endpos,
1129 bv()->buffer()->params.textclass,
1131 : CutAndPaste::eraseSelection(bv()->buffer()->params,
1133 selection.start.par(), endpit,
1134 selection.start.pos(), endpos,
1136 // sometimes necessary
1138 selection.start.par()->stripLeadingSpaces();
1140 redoParagraphs(selection.start.par(), boost::next(endpit));
1141 // cutSelection can invalidate the cursor so we need to set
1143 // we prefer the end for when tracking changes
1147 // need a valid cursor. (Lgb)
1150 setCursor(cursor.par(), cursor.pos());
1151 selection.cursor = cursor;
1156 void LyXText::copySelection()
1158 // stuff the selection onto the X clipboard, from an explicit copy request
1159 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1161 // this doesnt make sense, if there is no selection
1162 if (!selection.set())
1165 // ok we have a selection. This is always between selection.start
1166 // and sel_end cursor
1168 // copy behind a space if there is one
1169 while (selection.start.par()->size() > selection.start.pos()
1170 && selection.start.par()->isLineSeparator(selection.start.pos())
1171 && (selection.start.par() != selection.end.par()
1172 || selection.start.pos() < selection.end.pos()))
1173 selection.start.pos(selection.start.pos() + 1);
1175 CutAndPaste::copySelection(selection.start.par(),
1176 selection.end.par(),
1177 selection.start.pos(), selection.end.pos(),
1178 bv()->buffer()->params.textclass);
1182 void LyXText::pasteSelection(size_t sel_index)
1184 // this does not make sense, if there is nothing to paste
1185 if (!CutAndPaste::checkPastePossible())
1188 recordUndo(bv(), Undo::INSERT, cursor.par());
1190 ParagraphList::iterator endpit;
1195 boost::tie(ppp, endpit) =
1196 CutAndPaste::pasteSelection(*bv()->buffer(),
1198 cursor.par(), cursor.pos(),
1199 bv()->buffer()->params.textclass,
1201 bufferErrors(*bv()->buffer(), el);
1202 bv()->showErrorList(_("Paste"));
1204 redoParagraphs(cursor.par(), endpit);
1206 setCursor(cursor.par(), cursor.pos());
1209 selection.cursor = cursor;
1210 setCursor(ppp.first, ppp.second);
1216 void LyXText::setSelectionRange(lyx::pos_type length)
1221 selection.cursor = cursor;
1228 // simple replacing. The font of the first selected character is used
1229 void LyXText::replaceSelectionWithString(string const & str)
1231 recordUndo(bv(), Undo::ATOMIC);
1234 if (!selection.set()) { // create a dummy selection
1235 selection.end = cursor;
1236 selection.start = cursor;
1239 // Get font setting before we cut
1240 pos_type pos = selection.end.pos();
1241 LyXFont const font = selection.start.par()
1242 ->getFontSettings(bv()->buffer()->params,
1243 selection.start.pos());
1245 // Insert the new string
1246 string::const_iterator cit = str.begin();
1247 string::const_iterator end = str.end();
1248 for (; cit != end; ++cit) {
1249 selection.end.par()->insertChar(pos, (*cit), font);
1253 // Cut the selection
1254 cutSelection(true, false);
1260 // needed to insert the selection
1261 void LyXText::insertStringAsLines(string const & str)
1263 ParagraphList::iterator pit = cursor.par();
1264 pos_type pos = cursor.pos();
1265 ParagraphList::iterator endpit = boost::next(cursor.par());
1267 recordUndo(bv(), Undo::ATOMIC);
1269 // only to be sure, should not be neccessary
1272 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1274 redoParagraphs(cursor.par(), endpit);
1275 setCursor(cursor.par(), cursor.pos());
1276 selection.cursor = cursor;
1277 setCursor(pit, pos);
1282 // turns double-CR to single CR, others where converted into one
1283 // blank. Then InsertStringAsLines is called
1284 void LyXText::insertStringAsParagraphs(string const & str)
1286 string linestr(str);
1287 bool newline_inserted = false;
1288 string::size_type const siz = linestr.length();
1290 for (string::size_type i = 0; i < siz; ++i) {
1291 if (linestr[i] == '\n') {
1292 if (newline_inserted) {
1293 // we know that \r will be ignored by
1294 // InsertStringA. Of course, it is a dirty
1295 // trick, but it works...
1296 linestr[i - 1] = '\r';
1300 newline_inserted = true;
1302 } else if (IsPrintable(linestr[i])) {
1303 newline_inserted = false;
1306 insertStringAsLines(linestr);
1310 bool LyXText::setCursor(ParagraphList::iterator pit,
1312 bool setfont, bool boundary)
1314 LyXCursor old_cursor = cursor;
1315 setCursorIntern(pit, pos, setfont, boundary);
1316 return deleteEmptyParagraphMechanism(old_cursor);
1320 void LyXText::redoCursor()
1322 #warning maybe the same for selections?
1323 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1327 void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
1328 pos_type pos, bool boundary)
1330 Assert(pit != ownerParagraphs().end());
1334 cur.boundary(boundary);
1338 // get the cursor y position in text
1340 RowList::iterator row = getRow(pit, pos);
1343 // y is now the beginning of the cursor row
1344 y += row->baseline();
1345 // y is now the cursor baseline
1348 pos_type last = lastPos(*pit, row);
1350 // None of these should happen, but we're scaredy-cats
1351 if (pos > pit->size()) {
1352 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1355 } else if (pos > last + 1) {
1356 lyxerr << "dont like 2 please report" << endl;
1357 // This shouldn't happen.
1360 } else if (pos < row->pos()) {
1361 lyxerr << "dont like 3 please report" << endl;
1366 // now get the cursors x position
1367 float x = getCursorX(pit, row, pos, last, boundary);
1373 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1374 pos_type pos, pos_type last, bool boundary) const
1376 pos_type cursor_vpos = 0;
1377 double x = rit->x();
1378 double fill_separator = rit->fill_separator();
1379 double fill_hfill = rit->fill_hfill();
1380 double fill_label_hfill = rit->fill_label_hfill();
1381 pos_type const rit_pos = rit->pos();
1384 cursor_vpos = rit_pos;
1385 else if (pos > last && !boundary)
1386 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params))
1387 ? rit_pos : last + 1;
1388 else if (pos > rit_pos && (pos > last || boundary))
1389 // Place cursor after char at (logical) position pos - 1
1390 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1391 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1393 // Place cursor before char at (logical) position pos
1394 cursor_vpos = (bidi_level(pos) % 2 == 0)
1395 ? log2vis(pos) : log2vis(pos) + 1;
1397 pos_type body_pos = pit->beginningOfBody();
1399 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1402 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1403 pos_type pos = vis2log(vpos);
1404 if (body_pos > 0 && pos == body_pos - 1) {
1405 x += fill_label_hfill +
1406 font_metrics::width(
1407 pit->layout()->labelsep, getLabelFont(pit));
1408 if (pit->isLineSeparator(body_pos - 1))
1409 x -= singleWidth(pit, body_pos - 1);
1412 if (hfillExpansion(*pit, rit, pos)) {
1413 x += singleWidth(pit, pos);
1414 if (pos >= body_pos)
1417 x += fill_label_hfill;
1418 } else if (pit->isSeparator(pos)) {
1419 x += singleWidth(pit, pos);
1420 if (pos >= body_pos)
1421 x += fill_separator;
1423 x += singleWidth(pit, pos);
1429 void LyXText::setCursorIntern(ParagraphList::iterator pit,
1430 pos_type pos, bool setfont, bool boundary)
1432 setCursor(cursor, pit, pos, boundary);
1438 void LyXText::setCurrentFont()
1440 pos_type pos = cursor.pos();
1441 ParagraphList::iterator pit = cursor.par();
1443 if (cursor.boundary() && pos > 0)
1447 if (pos == pit->size())
1449 else // potentional bug... BUG (Lgb)
1450 if (pit->isSeparator(pos)) {
1451 if (pos > cursorRow()->pos() &&
1452 bidi_level(pos) % 2 ==
1453 bidi_level(pos - 1) % 2)
1455 else if (pos + 1 < pit->size())
1460 current_font = pit->getFontSettings(bv()->buffer()->params, pos);
1461 real_current_font = getFont(pit, pos);
1463 if (cursor.pos() == pit->size() &&
1464 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1465 !cursor.boundary()) {
1466 Language const * lang =
1467 pit->getParLanguage(bv()->buffer()->params);
1468 current_font.setLanguage(lang);
1469 current_font.setNumber(LyXFont::OFF);
1470 real_current_font.setLanguage(lang);
1471 real_current_font.setNumber(LyXFont::OFF);
1476 // returns the column near the specified x-coordinate of the row
1477 // x is set to the real beginning of this column
1478 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1479 RowList::iterator rit, int & x, bool & boundary) const
1481 double tmpx = rit->x();
1482 double fill_separator = rit->fill_separator();
1483 double fill_hfill = rit->fill_hfill();
1484 double fill_label_hfill = rit->fill_label_hfill();
1486 pos_type vc = rit->pos();
1487 pos_type last = lastPos(*pit, rit);
1489 LyXLayout_ptr const & layout = pit->layout();
1491 bool left_side = false;
1493 pos_type body_pos = pit->beginningOfBody();
1494 double last_tmpx = tmpx;
1497 (body_pos - 1 > last ||
1498 !pit->isLineSeparator(body_pos - 1)))
1501 // check for empty row
1507 while (vc <= last && tmpx <= x) {
1510 if (body_pos > 0 && c == body_pos - 1) {
1511 tmpx += fill_label_hfill +
1512 font_metrics::width(layout->labelsep, getLabelFont(pit));
1513 if (pit->isLineSeparator(body_pos - 1))
1514 tmpx -= singleWidth(pit, body_pos - 1);
1517 if (hfillExpansion(*pit, rit, c)) {
1518 tmpx += singleWidth(pit, c);
1522 tmpx += fill_label_hfill;
1523 } else if (pit->isSeparator(c)) {
1524 tmpx += singleWidth(pit, c);
1526 tmpx += fill_separator;
1528 tmpx += singleWidth(pit, c);
1533 if ((tmpx + last_tmpx) / 2 > x) {
1538 if (vc > last + 1) // This shouldn't happen.
1542 // This (rtl_support test) is not needed, but gives
1543 // some speedup if rtl_support == false
1544 bool const lastrow = lyxrc.rtl_support
1545 && boost::next(rit) == pit->rows.end();
1547 // If lastrow is false, we don't need to compute
1548 // the value of rtl.
1549 bool const rtl = (lastrow)
1550 ? pit->isRightToLeftPar(bv()->buffer()->params)
1553 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1554 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1556 else if (vc == rit->pos()) {
1558 if (bidi_level(c) % 2 == 1)
1561 c = vis2log(vc - 1);
1562 bool const rtl = (bidi_level(c) % 2 == 1);
1563 if (left_side == rtl) {
1565 boundary = isBoundary(*bv()->buffer(), *pit, c);
1569 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1570 if (bidi_level(last) % 2 == 0)
1571 tmpx -= singleWidth(pit, last);
1573 tmpx += singleWidth(pit, last);
1583 void LyXText::setCursorFromCoordinates(int x, int y)
1585 LyXCursor old_cursor = cursor;
1586 setCursorFromCoordinates(cursor, x, y);
1588 deleteEmptyParagraphMechanism(old_cursor);
1592 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1594 // Get the row first.
1595 ParagraphList::iterator pit;
1596 RowList::iterator rit = getRowNearY(y, pit);
1600 pos_type const column = getColumnNearX(pit, rit, x, bound);
1602 cur.pos(rit->pos() + column);
1604 cur.y(y + rit->baseline());
1606 cur.boundary(bound);
1610 void LyXText::cursorLeft(bool internal)
1612 if (cursor.pos() > 0) {
1613 bool boundary = cursor.boundary();
1614 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1615 if (!internal && !boundary &&
1616 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
1617 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1618 } else if (cursor.par() != ownerParagraphs().begin()) {
1619 // steps into the paragraph above
1620 ParagraphList::iterator pit = boost::prior(cursor.par());
1621 setCursor(pit, pit->size());
1626 void LyXText::cursorRight(bool internal)
1628 bool const at_end = (cursor.pos() == cursor.par()->size());
1629 bool const at_newline = !at_end &&
1630 cursor.par()->isNewline(cursor.pos());
1632 if (!internal && cursor.boundary() && !at_newline)
1633 setCursor(cursor.par(), cursor.pos(), true, false);
1635 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1637 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
1638 setCursor(cursor.par(), cursor.pos(), true, true);
1639 } else if (boost::next(cursor.par()) != ownerParagraphs().end())
1640 setCursor(boost::next(cursor.par()), 0);
1644 void LyXText::cursorUp(bool selecting)
1647 int x = cursor.x_fix();
1648 int y = cursor.y() - cursorRow()->baseline() - 1;
1649 setCursorFromCoordinates(x, y);
1651 int topy = bv_owner->top_y();
1652 int y1 = cursor.y() - topy;
1655 InsetOld * inset_hit = checkInsetHit(x, y1);
1656 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1657 inset_hit->localDispatch(
1658 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1662 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1663 cursorRow()->baseline() << endl;
1664 setCursorFromCoordinates(cursor.x_fix(),
1665 cursor.y() - cursorRow()->baseline() - 1);
1670 void LyXText::cursorDown(bool selecting)
1673 int x = cursor.x_fix();
1674 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1675 setCursorFromCoordinates(x, y);
1676 if (!selecting && cursorRow() == cursorIRow()) {
1677 int topy = bv_owner->top_y();
1678 int y1 = cursor.y() - topy;
1681 InsetOld * inset_hit = checkInsetHit(x, y1);
1682 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1683 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1684 inset_hit->localDispatch(cmd);
1688 setCursorFromCoordinates(cursor.x_fix(),
1689 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1694 void LyXText::cursorUpParagraph()
1696 if (cursor.pos() > 0)
1697 setCursor(cursor.par(), 0);
1698 else if (cursor.par() != ownerParagraphs().begin())
1699 setCursor(boost::prior(cursor.par()), 0);
1703 void LyXText::cursorDownParagraph()
1705 ParagraphList::iterator par = cursor.par();
1706 ParagraphList::iterator next_par = boost::next(par);
1708 if (next_par != ownerParagraphs().end())
1709 setCursor(next_par, 0);
1711 setCursor(par, par->size());
1715 // fix the cursor `cur' after a characters has been deleted at `where'
1716 // position. Called by deleteEmptyParagraphMechanism
1717 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1719 // if cursor is not in the paragraph where the delete occured,
1721 if (cur.par() != where.par())
1724 // if cursor position is after the place where the delete occured,
1726 if (cur.pos() > where.pos())
1727 cur.pos(cur.pos()-1);
1729 // check also if we don't want to set the cursor on a spot behind the
1730 // pagragraph because we erased the last character.
1731 if (cur.pos() > cur.par()->size())
1732 cur.pos(cur.par()->size());
1734 // recompute row et al. for this cursor
1735 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1739 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1741 // Would be wrong to delete anything if we have a selection.
1742 if (selection.set())
1745 // We allow all kinds of "mumbo-jumbo" when freespacing.
1746 if (old_cursor.par()->isFreeSpacing())
1749 /* Ok I'll put some comments here about what is missing.
1750 I have fixed BackSpace (and thus Delete) to not delete
1751 double-spaces automagically. I have also changed Cut,
1752 Copy and Paste to hopefully do some sensible things.
1753 There are still some small problems that can lead to
1754 double spaces stored in the document file or space at
1755 the beginning of paragraphs. This happens if you have
1756 the cursor between to spaces and then save. Or if you
1757 cut and paste and the selection have a space at the
1758 beginning and then save right after the paste. I am
1759 sure none of these are very hard to fix, but I will
1760 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1761 that I can get some feedback. (Lgb)
1764 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1765 // delete the LineSeparator.
1768 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1769 // delete the LineSeparator.
1772 // If the pos around the old_cursor were spaces, delete one of them.
1773 if (old_cursor.par() != cursor.par()
1774 || old_cursor.pos() != cursor.pos()) {
1776 // Only if the cursor has really moved
1777 if (old_cursor.pos() > 0
1778 && old_cursor.pos() < old_cursor.par()->size()
1779 && old_cursor.par()->isLineSeparator(old_cursor.pos())
1780 && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
1781 bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
1782 redoParagraph(old_cursor.par());
1786 #ifdef WITH_WARNINGS
1787 #warning This will not work anymore when we have multiple views of the same buffer
1788 // In this case, we will have to correct also the cursors held by
1789 // other bufferviews. It will probably be easier to do that in a more
1790 // automated way in LyXCursor code. (JMarc 26/09/2001)
1792 // correct all cursors held by the LyXText
1793 fixCursorAfterDelete(cursor, old_cursor);
1794 fixCursorAfterDelete(selection.cursor, old_cursor);
1795 fixCursorAfterDelete(selection.start, old_cursor);
1796 fixCursorAfterDelete(selection.end, old_cursor);
1801 // don't delete anything if this is the ONLY paragraph!
1802 if (ownerParagraphs().size() == 1)
1805 // Do not delete empty paragraphs with keepempty set.
1806 if (old_cursor.par()->allowEmpty())
1809 // only do our magic if we changed paragraph
1810 if (old_cursor.par() == cursor.par())
1813 // record if we have deleted a paragraph
1814 // we can't possibly have deleted a paragraph before this point
1815 bool deleted = false;
1817 if (old_cursor.par()->empty() ||
1818 (old_cursor.par()->size() == 1 &&
1819 old_cursor.par()->isLineSeparator(0))) {
1820 // ok, we will delete something
1821 LyXCursor tmpcursor;
1825 bool selection_position_was_oldcursor_position = (
1826 selection.cursor.par() == old_cursor.par()
1827 && selection.cursor.pos() == old_cursor.pos());
1830 cursor = old_cursor; // that undo can restore the right cursor position
1832 ParagraphList::iterator endpit = boost::next(old_cursor.par());
1833 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1836 recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
1840 ownerParagraphs().erase(old_cursor.par());
1844 setCursorIntern(cursor.par(), cursor.pos());
1846 if (selection_position_was_oldcursor_position) {
1847 // correct selection
1848 selection.cursor = cursor;
1852 if (old_cursor.par()->stripLeadingSpaces()) {
1853 redoParagraph(old_cursor.par());
1855 setCursorIntern(cursor.par(), cursor.pos());
1856 selection.cursor = cursor;
1863 ParagraphList & LyXText::ownerParagraphs() const
1869 bool LyXText::isInInset() const
1871 // Sub-level has non-null bv owner and non-null inset owner.
1872 return inset_owner != 0;
1876 int defaultRowHeight()
1878 LyXFont const font(LyXFont::ALL_SANE);
1879 return int(font_metrics::maxAscent(font)
1880 + font_metrics::maxDescent(font) * 1.5);