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 LyXLayout_ptr const & lyxlayout =
337 bv()->buffer()->params.getLyXTextClass()[layout];
340 pit->applyLayout(lyxlayout);
341 makeFontEntriesLayoutSpecific(bv()->buffer()->params, *pit);
342 pit->params().spaceTop(lyxlayout->fill_top ?
343 VSpace(VSpace::VFILL)
344 : VSpace(VSpace::NONE));
345 pit->params().spaceBottom(lyxlayout->fill_bottom ?
346 VSpace(VSpace::VFILL)
347 : VSpace(VSpace::NONE));
348 if (lyxlayout->margintype == MARGIN_MANUAL)
349 pit->setLabelWidthString(lyxlayout->labelstring());
352 } while (pit != epit);
358 // set layout over selection and make a total rebreak of those paragraphs
359 void LyXText::setLayout(string const & layout)
361 LyXCursor tmpcursor = cursor; // store the current cursor
363 // if there is no selection just set the layout
364 // of the current paragraph
365 if (!selection.set()) {
366 selection.start = cursor; // dummy selection
367 selection.end = cursor;
370 // special handling of new environment insets
371 BufferParams const & params = bv()->buffer()->params;
372 LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
373 if (lyxlayout->is_environment) {
374 // move everything in a new environment inset
375 lyxerr << "setting layout " << layout << endl;
376 bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
377 bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
378 bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
379 InsetOld * inset = new InsetEnvironment(params, layout);
380 if (bv()->insertInset(inset)) {
382 //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
389 ParagraphList::iterator endpit = setLayout(cursor, selection.start,
390 selection.end, layout);
391 redoParagraphs(selection.start.par(), endpit);
393 // we have to reset the selection, because the
394 // geometry could have changed
395 setCursor(selection.start.par(), selection.start.pos(), false);
396 selection.cursor = cursor;
397 setCursor(selection.end.par(), selection.end.pos(), false);
401 setCursor(tmpcursor.par(), tmpcursor.pos(), true);
405 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
407 ParagraphList::iterator pit = cursor.par();
408 ParagraphList::iterator end = cursor.par();
409 ParagraphList::iterator start = pit;
411 if (selection.set()) {
412 pit = selection.start.par();
413 end = selection.end.par();
417 ParagraphList::iterator pastend = boost::next(end);
420 recordUndo(bv(), Undo::ATOMIC, start, end);
422 bool changed = false;
424 int prev_after_depth = 0;
425 #warning parlist ... could be nicer ?
426 if (start != ownerParagraphs().begin()) {
427 prev_after_depth = boost::prior(start)->getMaxDepthAfter();
431 int const depth = pit->params().depth();
432 if (type == bv_funcs::INC_DEPTH) {
433 if (depth < prev_after_depth
434 && pit->layout()->labeltype != LABEL_BIBLIO) {
437 pit->params().depth(depth + 1);
442 pit->params().depth(depth - 1);
445 prev_after_depth = pit->getMaxDepthAfter();
457 redoParagraphs(start, pastend);
459 // We need to actually move the text->cursor. I don't
460 // understand why ...
461 LyXCursor tmpcursor = cursor;
463 // we have to reset the visual selection because the
464 // geometry could have changed
465 if (selection.set()) {
466 setCursor(selection.start.par(), selection.start.pos());
467 selection.cursor = cursor;
468 setCursor(selection.end.par(), selection.end.pos());
471 // this handles the counter labels, and also fixes up
472 // depth values for follow-on (child) paragraphs
476 setCursor(tmpcursor.par(), tmpcursor.pos());
482 // set font over selection and make a total rebreak of those paragraphs
483 void LyXText::setFont(LyXFont const & font, bool toggleall)
485 // if there is no selection just set the current_font
486 if (!selection.set()) {
487 // Determine basis font
489 if (cursor.pos() < cursor.par()->beginningOfBody()) {
490 layoutfont = getLabelFont(cursor.par());
492 layoutfont = getLayoutFont(cursor.par());
494 // Update current font
495 real_current_font.update(font,
496 bv()->buffer()->params.language,
499 // Reduce to implicit settings
500 current_font = real_current_font;
501 current_font.reduce(layoutfont);
502 // And resolve it completely
503 real_current_font.realize(layoutfont);
508 LyXCursor tmpcursor = cursor; // store the current cursor
510 // ok we have a selection. This is always between sel_start_cursor
511 // and sel_end cursor
513 recordUndo(bv(), Undo::ATOMIC, selection.start.par(), selection.end.par());
515 cursor = selection.start;
516 while (cursor.par() != selection.end.par() ||
517 cursor.pos() < selection.end.pos())
519 if (cursor.pos() < cursor.par()->size()) {
520 // an open footnote should behave like a closed one
521 setCharFont(cursor.par(), cursor.pos(),
523 cursor.pos(cursor.pos() + 1);
526 cursor.par(boost::next(cursor.par()));
531 redoParagraph(selection.start.par());
533 // we have to reset the selection, because the
534 // geometry could have changed, but we keep
535 // it for user convenience
536 setCursor(selection.start.par(), selection.start.pos());
537 selection.cursor = cursor;
538 setCursor(selection.end.par(), selection.end.pos());
540 setCursor(tmpcursor.par(), tmpcursor.pos(), true,
541 tmpcursor.boundary());
545 int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
547 RowList::iterator rit = pit->rows.begin();
548 RowList::iterator end = pit->rows.end();
550 // remove rows of paragraph, keep track of height changes
551 for (int i = 0; rit != end; ++rit, ++i)
552 height -= rit->height();
556 InsetList::iterator ii = pit->insetlist.begin();
557 InsetList::iterator iend = pit->insetlist.end();
558 for (; ii != iend; ++ii) {
560 MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
561 ii->inset->metrics(mi, dim);
564 // rebreak the paragraph
565 for (pos_type z = 0; z < pit->size() + 1; ) {
567 z = rowBreakPoint(pit, row) + 1;
569 pit->rows.push_back(row);
573 // set height and fill and width of rows
574 int const ww = workWidth();
575 for (rit = pit->rows.begin(); rit != end; ++rit) {
576 int const f = fill(pit, rit, ww);
577 int const w = ww - f;
578 par_width = std::max(par_width, w);
581 prepareToPrint(pit, rit);
582 setHeightOfRow(pit, rit);
583 height += rit->height();
586 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
591 int LyXText::redoParagraphs(ParagraphList::iterator start,
592 ParagraphList::iterator end)
595 for ( ; start != end; ++start) {
596 int par_width = redoParagraphInternal(start);
597 pars_width = std::max(par_width, pars_width);
599 updateRowPositions();
604 void LyXText::redoParagraph(ParagraphList::iterator pit)
606 redoParagraphInternal(pit);
607 updateRowPositions();
611 void LyXText::fullRebreak()
613 redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
615 selection.cursor = cursor;
619 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
621 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
622 // << " workWidth: " << workWidth() << endl;
623 //Assert(mi.base.textwidth);
630 width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
633 dim.asc = firstRow()->ascent_of_text();
634 dim.des = height - dim.asc;
635 dim.wid = std::max(mi.base.textwidth, int(width));
639 // important for the screen
642 // the cursor set functions have a special mechanism. When they
643 // realize, that you left an empty paragraph, they will delete it.
644 // They also delete the corresponding row
646 // need the selection cursor:
647 void LyXText::setSelection()
649 TextCursor::setSelection();
654 void LyXText::clearSelection()
656 TextCursor::clearSelection();
658 // reset this in the bv_owner!
659 if (bv_owner && bv_owner->text)
660 bv_owner->text->xsel_cache.set(false);
664 void LyXText::cursorHome()
666 setCursor(cursor.par(), cursorRow()->pos());
670 void LyXText::cursorEnd()
672 setCursor(cursor.par(), cursorRow()->end() - 1);
676 void LyXText::cursorTop()
678 setCursor(ownerParagraphs().begin(), 0);
682 void LyXText::cursorBottom()
684 ParagraphList::iterator lastpit =
685 boost::prior(ownerParagraphs().end());
686 setCursor(lastpit, lastpit->size());
690 void LyXText::toggleFree(LyXFont const & font, bool toggleall)
692 // If the mask is completely neutral, tell user
693 if (font == LyXFont(LyXFont::ALL_IGNORE)) {
694 // Could only happen with user style
695 bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
699 // Try implicit word selection
700 // If there is a change in the language the implicit word selection
702 LyXCursor resetCursor = cursor;
703 bool implicitSelection = (font.language() == ignore_language
704 && font.number() == LyXFont::IGNORE)
705 ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
708 setFont(font, toggleall);
710 // Implicit selections are cleared afterwards
711 //and cursor is set to the original position.
712 if (implicitSelection) {
714 cursor = resetCursor;
715 setCursor(cursor.par(), cursor.pos());
716 selection.cursor = cursor;
721 string LyXText::getStringToIndex()
723 // Try implicit word selection
724 // If there is a change in the language the implicit word selection
726 LyXCursor const reset_cursor = cursor;
727 bool const implicitSelection =
728 selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
731 if (!selection.set())
732 bv()->owner()->message(_("Nothing to index!"));
733 else if (selection.start.par() != selection.end.par())
734 bv()->owner()->message(_("Cannot index more than one paragraph!"));
736 idxstring = selectionAsString(*bv()->buffer(), false);
738 // Reset cursors to their original position.
739 cursor = reset_cursor;
740 setCursor(cursor.par(), cursor.pos());
741 selection.cursor = cursor;
743 // Clear the implicit selection.
744 if (implicitSelection)
751 // the DTP switches for paragraphs. LyX will store them in the first
752 // physical paragraph. When a paragraph is broken, the top settings rest,
753 // the bottom settings are given to the new one. So I can make sure,
754 // they do not duplicate themself and you cannnot make dirty things with
757 void LyXText::setParagraph(bool line_top, bool line_bottom,
758 bool pagebreak_top, bool pagebreak_bottom,
759 VSpace const & space_top,
760 VSpace const & space_bottom,
761 Spacing const & spacing,
763 string const & labelwidthstring,
766 LyXCursor tmpcursor = cursor;
767 if (!selection.set()) {
768 selection.start = cursor;
769 selection.end = cursor;
772 // make sure that the depth behind the selection are restored, too
773 ParagraphList::iterator endpit = boost::next(selection.end.par());
774 ParagraphList::iterator undoendpit = endpit;
775 ParagraphList::iterator pars_end = ownerParagraphs().end();
777 if (endpit != pars_end && endpit->getDepth()) {
778 while (endpit != pars_end && endpit->getDepth()) {
782 } else if (endpit != pars_end) {
783 // because of parindents etc.
787 recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
788 boost::prior(undoendpit));
791 ParagraphList::iterator tmppit = selection.end.par();
793 while (tmppit != boost::prior(selection.start.par())) {
794 setCursor(tmppit, 0);
796 ParagraphList::iterator pit = cursor.par();
797 ParagraphParameters & params = pit->params();
799 params.lineTop(line_top);
800 params.lineBottom(line_bottom);
801 params.pagebreakTop(pagebreak_top);
802 params.pagebreakBottom(pagebreak_bottom);
803 params.spaceTop(space_top);
804 params.spaceBottom(space_bottom);
805 params.spacing(spacing);
806 // does the layout allow the new alignment?
807 LyXLayout_ptr const & layout = pit->layout();
809 if (align == LYX_ALIGN_LAYOUT)
810 align = layout->align;
811 if (align & layout->alignpossible) {
812 if (align == layout->align)
813 params.align(LYX_ALIGN_LAYOUT);
817 pit->setLabelWidthString(labelwidthstring);
818 params.noindent(noindent);
819 tmppit = boost::prior(pit);
822 redoParagraphs(selection.start.par(), endpit);
825 setCursor(selection.start.par(), selection.start.pos());
826 selection.cursor = cursor;
827 setCursor(selection.end.par(), selection.end.pos());
829 setCursor(tmpcursor.par(), tmpcursor.pos());
831 bv()->updateInset(inset_owner);
835 // set the counter of a paragraph. This includes the labels
836 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
838 LyXTextClass const & textclass = buf.params.getLyXTextClass();
839 LyXLayout_ptr const & layout = pit->layout();
841 if (pit != ownerParagraphs().begin()) {
843 pit->params().appendix(boost::prior(pit)->params().appendix());
844 if (!pit->params().appendix() &&
845 pit->params().startOfAppendix()) {
846 pit->params().appendix(true);
847 textclass.counters().reset();
849 pit->enumdepth = boost::prior(pit)->enumdepth;
850 pit->itemdepth = boost::prior(pit)->itemdepth;
852 pit->params().appendix(pit->params().startOfAppendix());
857 // Maybe we have to increment the enumeration depth.
858 // BUT, enumeration in a footnote is considered in isolation from its
859 // surrounding paragraph so don't increment if this is the
860 // first line of the footnote
861 // AND, bibliographies can't have their depth changed ie. they
862 // are always of depth 0
863 if (pit != ownerParagraphs().begin()
864 && boost::prior(pit)->getDepth() < pit->getDepth()
865 && boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI
866 && pit->enumdepth < 3
867 && layout->labeltype != LABEL_BIBLIO) {
871 // Maybe we have to decrement the enumeration depth, see note above
872 if (pit != ownerParagraphs().begin()
873 && boost::prior(pit)->getDepth() > pit->getDepth()
874 && layout->labeltype != LABEL_BIBLIO) {
875 pit->enumdepth = depthHook(pit, ownerParagraphs(),
876 pit->getDepth())->enumdepth;
879 if (!pit->params().labelString().empty()) {
880 pit->params().labelString(string());
883 if (layout->margintype == MARGIN_MANUAL) {
884 if (pit->params().labelWidthString().empty())
885 pit->setLabelWidthString(layout->labelstring());
887 pit->setLabelWidthString(string());
890 // is it a layout that has an automatic label?
891 if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
892 int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
896 if (i >= 0 && i <= buf.params.secnumdepth) {
900 textclass.counters().step(layout->latexname());
902 // Is there a label? Useful for Chapter layout
903 if (!pit->params().appendix()) {
904 s << buf.B_(layout->labelstring());
906 s << buf.B_(layout->labelstring_appendix());
909 // Use of an integer is here less than elegant. For now.
910 int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
911 if (!pit->params().appendix()) {
912 numbertype = "sectioning";
914 numbertype = "appendix";
915 if (pit->isRightToLeftPar(buf.params))
922 << textclass.counters()
923 .numberLabel(layout->latexname(),
924 numbertype, langtype, head);
926 pit->params().labelString(STRCONV(s.str()));
928 // reset enum counters
929 textclass.counters().reset("enum");
930 } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
931 textclass.counters().reset("enum");
932 } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
934 // Yes I know this is a really, really! bad solution
936 string enumcounter("enum");
938 switch (pit->enumdepth) {
950 // not a valid enumdepth...
954 textclass.counters().step(enumcounter);
956 s << textclass.counters()
957 .numberLabel(enumcounter, "enumeration");
958 pit->params().labelString(STRCONV(s.str()));
960 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
961 textclass.counters().step("bibitem");
962 int number = textclass.counters().value("bibitem");
963 if (pit->bibitem()) {
964 pit->bibitem()->setCounter(number);
965 pit->params().labelString(layout->labelstring());
967 // In biblio should't be following counters but...
969 string s = buf.B_(layout->labelstring());
972 if (layout->labeltype == LABEL_SENSITIVE) {
973 ParagraphList::iterator end = ownerParagraphs().end();
974 ParagraphList::iterator tmppit = pit;
977 while (tmppit != end && tmppit->inInset()
978 // the single '=' is intended below
979 && (in = tmppit->inInset()->owner()))
981 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
982 in->lyxCode() == InsetOld::WRAP_CODE) {
986 Paragraph const * owner = &ownerPar(buf, in);
987 tmppit = ownerParagraphs().begin();
988 for ( ; tmppit != end; ++tmppit)
989 if (&*tmppit == owner)
997 if (in->lyxCode() == InsetOld::FLOAT_CODE)
998 type = static_cast<InsetFloat*>(in)->params().type;
999 else if (in->lyxCode() == InsetOld::WRAP_CODE)
1000 type = static_cast<InsetWrap*>(in)->params().type;
1004 Floating const & fl = textclass.floats().getType(type);
1006 textclass.counters().step(fl.type());
1008 // Doesn't work... yet.
1009 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1011 // par->SetLayout(0);
1012 // s = layout->labelstring;
1013 s = _("Senseless: ");
1016 pit->params().labelString(s);
1018 // reset the enumeration counter. They are always reset
1019 // when there is any other layout between
1020 // Just fall-through between the cases so that all
1021 // enum counters deeper than enumdepth is also reset.
1022 switch (pit->enumdepth) {
1024 textclass.counters().reset("enumi");
1026 textclass.counters().reset("enumii");
1028 textclass.counters().reset("enumiii");
1030 textclass.counters().reset("enumiv");
1036 // Updates all counters. Paragraphs with changed label string will be rebroken
1037 void LyXText::updateCounters()
1040 bv()->buffer()->params.getLyXTextClass().counters().reset();
1042 ParagraphList::iterator beg = ownerParagraphs().begin();
1043 ParagraphList::iterator end = ownerParagraphs().end();
1044 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1045 string const oldLabel = pit->params().labelString();
1047 size_t maxdepth = 0;
1049 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1051 if (pit->params().depth() > maxdepth)
1052 pit->params().depth(maxdepth);
1054 // setCounter can potentially change the labelString.
1055 setCounter(*bv()->buffer(), pit);
1057 string const & newLabel = pit->params().labelString();
1059 if (oldLabel != newLabel)
1065 void LyXText::insertInset(InsetOld * inset)
1067 if (!cursor.par()->insetAllowed(inset->lyxCode()))
1069 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1071 cursor.par()->insertInset(cursor.pos(), inset);
1072 // Just to rebreak and refresh correctly.
1073 // The character will not be inserted a second time
1074 insertChar(Paragraph::META_INSET);
1075 // If we enter a highly editable inset the cursor should be before
1076 // the inset. After an Undo LyX tries to call inset->edit(...)
1077 // and fails if the cursor is behind the inset and getInset
1078 // does not return the inset!
1079 if (isHighlyEditableInset(inset))
1085 void LyXText::cutSelection(bool doclear, bool realcut)
1087 // Stuff what we got on the clipboard. Even if there is no selection.
1089 // There is a problem with having the stuffing here in that the
1090 // larger the selection the slower LyX will get. This can be
1091 // solved by running the line below only when the selection has
1092 // finished. The solution used currently just works, to make it
1093 // faster we need to be more clever and probably also have more
1094 // calls to stuffClipboard. (Lgb)
1095 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1097 // This doesn't make sense, if there is no selection
1098 if (!selection.set())
1101 // OK, we have a selection. This is always between selection.start
1102 // and selection.end
1104 // make sure that the depth behind the selection are restored, too
1105 ParagraphList::iterator endpit = boost::next(selection.end.par());
1106 ParagraphList::iterator undoendpit = endpit;
1107 ParagraphList::iterator pars_end = ownerParagraphs().end();
1109 if (endpit != pars_end && endpit->getDepth()) {
1110 while (endpit != pars_end && endpit->getDepth()) {
1112 undoendpit = endpit;
1114 } else if (endpit != pars_end) {
1115 // because of parindents etc.
1119 recordUndo(bv(), Undo::DELETE, selection.start.par(),
1120 boost::prior(undoendpit));
1122 endpit = selection.end.par();
1123 int endpos = selection.end.pos();
1125 boost::tie(endpit, endpos) = realcut ?
1126 CutAndPaste::cutSelection(bv()->buffer()->params,
1128 selection.start.par(), endpit,
1129 selection.start.pos(), endpos,
1130 bv()->buffer()->params.textclass,
1132 : CutAndPaste::eraseSelection(bv()->buffer()->params,
1134 selection.start.par(), endpit,
1135 selection.start.pos(), endpos,
1137 // sometimes necessary
1139 selection.start.par()->stripLeadingSpaces();
1141 redoParagraphs(selection.start.par(), boost::next(endpit));
1142 // cutSelection can invalidate the cursor so we need to set
1144 // we prefer the end for when tracking changes
1148 // need a valid cursor. (Lgb)
1151 setCursor(cursor.par(), cursor.pos());
1152 selection.cursor = cursor;
1157 void LyXText::copySelection()
1159 // stuff the selection onto the X clipboard, from an explicit copy request
1160 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1162 // this doesnt make sense, if there is no selection
1163 if (!selection.set())
1166 // ok we have a selection. This is always between selection.start
1167 // and sel_end cursor
1169 // copy behind a space if there is one
1170 while (selection.start.par()->size() > selection.start.pos()
1171 && selection.start.par()->isLineSeparator(selection.start.pos())
1172 && (selection.start.par() != selection.end.par()
1173 || selection.start.pos() < selection.end.pos()))
1174 selection.start.pos(selection.start.pos() + 1);
1176 CutAndPaste::copySelection(selection.start.par(),
1177 selection.end.par(),
1178 selection.start.pos(), selection.end.pos(),
1179 bv()->buffer()->params.textclass);
1183 void LyXText::pasteSelection(size_t sel_index)
1185 // this does not make sense, if there is nothing to paste
1186 if (!CutAndPaste::checkPastePossible())
1189 recordUndo(bv(), Undo::INSERT, cursor.par());
1191 ParagraphList::iterator endpit;
1196 boost::tie(ppp, endpit) =
1197 CutAndPaste::pasteSelection(*bv()->buffer(),
1199 cursor.par(), cursor.pos(),
1200 bv()->buffer()->params.textclass,
1202 bufferErrors(*bv()->buffer(), el);
1203 bv()->showErrorList(_("Paste"));
1205 redoParagraphs(cursor.par(), endpit);
1207 setCursor(cursor.par(), cursor.pos());
1210 selection.cursor = cursor;
1211 setCursor(ppp.first, ppp.second);
1217 void LyXText::setSelectionRange(lyx::pos_type length)
1222 selection.cursor = cursor;
1229 // simple replacing. The font of the first selected character is used
1230 void LyXText::replaceSelectionWithString(string const & str)
1232 recordUndo(bv(), Undo::ATOMIC);
1235 if (!selection.set()) { // create a dummy selection
1236 selection.end = cursor;
1237 selection.start = cursor;
1240 // Get font setting before we cut
1241 pos_type pos = selection.end.pos();
1242 LyXFont const font = selection.start.par()
1243 ->getFontSettings(bv()->buffer()->params,
1244 selection.start.pos());
1246 // Insert the new string
1247 string::const_iterator cit = str.begin();
1248 string::const_iterator end = str.end();
1249 for (; cit != end; ++cit) {
1250 selection.end.par()->insertChar(pos, (*cit), font);
1254 // Cut the selection
1255 cutSelection(true, false);
1261 // needed to insert the selection
1262 void LyXText::insertStringAsLines(string const & str)
1264 ParagraphList::iterator pit = cursor.par();
1265 pos_type pos = cursor.pos();
1266 ParagraphList::iterator endpit = boost::next(cursor.par());
1268 recordUndo(bv(), Undo::ATOMIC);
1270 // only to be sure, should not be neccessary
1273 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1275 redoParagraphs(cursor.par(), endpit);
1276 setCursor(cursor.par(), cursor.pos());
1277 selection.cursor = cursor;
1278 setCursor(pit, pos);
1283 // turns double-CR to single CR, others where converted into one
1284 // blank. Then InsertStringAsLines is called
1285 void LyXText::insertStringAsParagraphs(string const & str)
1287 string linestr(str);
1288 bool newline_inserted = false;
1289 string::size_type const siz = linestr.length();
1291 for (string::size_type i = 0; i < siz; ++i) {
1292 if (linestr[i] == '\n') {
1293 if (newline_inserted) {
1294 // we know that \r will be ignored by
1295 // InsertStringA. Of course, it is a dirty
1296 // trick, but it works...
1297 linestr[i - 1] = '\r';
1301 newline_inserted = true;
1303 } else if (IsPrintable(linestr[i])) {
1304 newline_inserted = false;
1307 insertStringAsLines(linestr);
1311 bool LyXText::setCursor(ParagraphList::iterator pit,
1313 bool setfont, bool boundary)
1315 LyXCursor old_cursor = cursor;
1316 setCursorIntern(pit, pos, setfont, boundary);
1317 return deleteEmptyParagraphMechanism(old_cursor);
1321 void LyXText::redoCursor()
1323 #warning maybe the same for selections?
1324 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1328 void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
1329 pos_type pos, bool boundary)
1331 Assert(pit != ownerParagraphs().end());
1335 cur.boundary(boundary);
1339 // get the cursor y position in text
1341 RowList::iterator row = getRow(pit, pos);
1344 // y is now the beginning of the cursor row
1345 y += row->baseline();
1346 // y is now the cursor baseline
1349 pos_type last = lastPos(*pit, row);
1351 // None of these should happen, but we're scaredy-cats
1352 if (pos > pit->size()) {
1353 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1356 } else if (pos > last + 1) {
1357 lyxerr << "dont like 2 please report" << endl;
1358 // This shouldn't happen.
1361 } else if (pos < row->pos()) {
1362 lyxerr << "dont like 3 please report" << endl;
1367 // now get the cursors x position
1368 float x = getCursorX(pit, row, pos, last, boundary);
1374 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1375 pos_type pos, pos_type last, bool boundary) const
1377 pos_type cursor_vpos = 0;
1378 double x = rit->x();
1379 double fill_separator = rit->fill_separator();
1380 double fill_hfill = rit->fill_hfill();
1381 double fill_label_hfill = rit->fill_label_hfill();
1382 pos_type const rit_pos = rit->pos();
1385 cursor_vpos = rit_pos;
1386 else if (pos > last && !boundary)
1387 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params))
1388 ? rit_pos : last + 1;
1389 else if (pos > rit_pos && (pos > last || boundary))
1390 // Place cursor after char at (logical) position pos - 1
1391 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1392 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1394 // Place cursor before char at (logical) position pos
1395 cursor_vpos = (bidi_level(pos) % 2 == 0)
1396 ? log2vis(pos) : log2vis(pos) + 1;
1398 pos_type body_pos = pit->beginningOfBody();
1400 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1403 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1404 pos_type pos = vis2log(vpos);
1405 if (body_pos > 0 && pos == body_pos - 1) {
1406 x += fill_label_hfill +
1407 font_metrics::width(
1408 pit->layout()->labelsep, getLabelFont(pit));
1409 if (pit->isLineSeparator(body_pos - 1))
1410 x -= singleWidth(pit, body_pos - 1);
1413 if (hfillExpansion(*pit, rit, pos)) {
1414 x += singleWidth(pit, pos);
1415 if (pos >= body_pos)
1418 x += fill_label_hfill;
1419 } else if (pit->isSeparator(pos)) {
1420 x += singleWidth(pit, pos);
1421 if (pos >= body_pos)
1422 x += fill_separator;
1424 x += singleWidth(pit, pos);
1430 void LyXText::setCursorIntern(ParagraphList::iterator pit,
1431 pos_type pos, bool setfont, bool boundary)
1433 setCursor(cursor, pit, pos, boundary);
1439 void LyXText::setCurrentFont()
1441 pos_type pos = cursor.pos();
1442 ParagraphList::iterator pit = cursor.par();
1444 if (cursor.boundary() && pos > 0)
1448 if (pos == pit->size())
1450 else // potentional bug... BUG (Lgb)
1451 if (pit->isSeparator(pos)) {
1452 if (pos > cursorRow()->pos() &&
1453 bidi_level(pos) % 2 ==
1454 bidi_level(pos - 1) % 2)
1456 else if (pos + 1 < pit->size())
1461 current_font = pit->getFontSettings(bv()->buffer()->params, pos);
1462 real_current_font = getFont(pit, pos);
1464 if (cursor.pos() == pit->size() &&
1465 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1466 !cursor.boundary()) {
1467 Language const * lang =
1468 pit->getParLanguage(bv()->buffer()->params);
1469 current_font.setLanguage(lang);
1470 current_font.setNumber(LyXFont::OFF);
1471 real_current_font.setLanguage(lang);
1472 real_current_font.setNumber(LyXFont::OFF);
1477 // returns the column near the specified x-coordinate of the row
1478 // x is set to the real beginning of this column
1479 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1480 RowList::iterator rit, int & x, bool & boundary) const
1482 double tmpx = rit->x();
1483 double fill_separator = rit->fill_separator();
1484 double fill_hfill = rit->fill_hfill();
1485 double fill_label_hfill = rit->fill_label_hfill();
1487 pos_type vc = rit->pos();
1488 pos_type last = lastPos(*pit, rit);
1490 LyXLayout_ptr const & layout = pit->layout();
1492 bool left_side = false;
1494 pos_type body_pos = pit->beginningOfBody();
1495 double last_tmpx = tmpx;
1498 (body_pos - 1 > last ||
1499 !pit->isLineSeparator(body_pos - 1)))
1502 // check for empty row
1508 while (vc <= last && tmpx <= x) {
1511 if (body_pos > 0 && c == body_pos - 1) {
1512 tmpx += fill_label_hfill +
1513 font_metrics::width(layout->labelsep, getLabelFont(pit));
1514 if (pit->isLineSeparator(body_pos - 1))
1515 tmpx -= singleWidth(pit, body_pos - 1);
1518 if (hfillExpansion(*pit, rit, c)) {
1519 tmpx += singleWidth(pit, c);
1523 tmpx += fill_label_hfill;
1524 } else if (pit->isSeparator(c)) {
1525 tmpx += singleWidth(pit, c);
1527 tmpx += fill_separator;
1529 tmpx += singleWidth(pit, c);
1534 if ((tmpx + last_tmpx) / 2 > x) {
1539 if (vc > last + 1) // This shouldn't happen.
1543 // This (rtl_support test) is not needed, but gives
1544 // some speedup if rtl_support == false
1545 bool const lastrow = lyxrc.rtl_support
1546 && boost::next(rit) == pit->rows.end();
1548 // If lastrow is false, we don't need to compute
1549 // the value of rtl.
1550 bool const rtl = (lastrow)
1551 ? pit->isRightToLeftPar(bv()->buffer()->params)
1554 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1555 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1557 else if (vc == rit->pos()) {
1559 if (bidi_level(c) % 2 == 1)
1562 c = vis2log(vc - 1);
1563 bool const rtl = (bidi_level(c) % 2 == 1);
1564 if (left_side == rtl) {
1566 boundary = isBoundary(*bv()->buffer(), *pit, c);
1570 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1571 if (bidi_level(last) % 2 == 0)
1572 tmpx -= singleWidth(pit, last);
1574 tmpx += singleWidth(pit, last);
1584 void LyXText::setCursorFromCoordinates(int x, int y)
1586 LyXCursor old_cursor = cursor;
1587 setCursorFromCoordinates(cursor, x, y);
1589 deleteEmptyParagraphMechanism(old_cursor);
1593 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1595 // Get the row first.
1596 ParagraphList::iterator pit;
1597 RowList::iterator rit = getRowNearY(y, pit);
1601 pos_type const column = getColumnNearX(pit, rit, x, bound);
1603 cur.pos(rit->pos() + column);
1605 cur.y(y + rit->baseline());
1607 cur.boundary(bound);
1611 void LyXText::cursorLeft(bool internal)
1613 if (cursor.pos() > 0) {
1614 bool boundary = cursor.boundary();
1615 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1616 if (!internal && !boundary &&
1617 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
1618 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1619 } else if (cursor.par() != ownerParagraphs().begin()) {
1620 // steps into the paragraph above
1621 ParagraphList::iterator pit = boost::prior(cursor.par());
1622 setCursor(pit, pit->size());
1627 void LyXText::cursorRight(bool internal)
1629 bool const at_end = (cursor.pos() == cursor.par()->size());
1630 bool const at_newline = !at_end &&
1631 cursor.par()->isNewline(cursor.pos());
1633 if (!internal && cursor.boundary() && !at_newline)
1634 setCursor(cursor.par(), cursor.pos(), true, false);
1636 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1638 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
1639 setCursor(cursor.par(), cursor.pos(), true, true);
1640 } else if (boost::next(cursor.par()) != ownerParagraphs().end())
1641 setCursor(boost::next(cursor.par()), 0);
1645 void LyXText::cursorUp(bool selecting)
1648 int x = cursor.x_fix();
1649 int y = cursor.y() - cursorRow()->baseline() - 1;
1650 setCursorFromCoordinates(x, y);
1652 int topy = bv_owner->top_y();
1653 int y1 = cursor.y() - topy;
1656 InsetOld * inset_hit = checkInsetHit(x, y1);
1657 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1658 inset_hit->localDispatch(
1659 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1663 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1664 cursorRow()->baseline() << endl;
1665 setCursorFromCoordinates(cursor.x_fix(),
1666 cursor.y() - cursorRow()->baseline() - 1);
1671 void LyXText::cursorDown(bool selecting)
1674 int x = cursor.x_fix();
1675 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1676 setCursorFromCoordinates(x, y);
1677 if (!selecting && cursorRow() == cursorIRow()) {
1678 int topy = bv_owner->top_y();
1679 int y1 = cursor.y() - topy;
1682 InsetOld * inset_hit = checkInsetHit(x, y1);
1683 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1684 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1685 inset_hit->localDispatch(cmd);
1689 setCursorFromCoordinates(cursor.x_fix(),
1690 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1695 void LyXText::cursorUpParagraph()
1697 if (cursor.pos() > 0)
1698 setCursor(cursor.par(), 0);
1699 else if (cursor.par() != ownerParagraphs().begin())
1700 setCursor(boost::prior(cursor.par()), 0);
1704 void LyXText::cursorDownParagraph()
1706 ParagraphList::iterator par = cursor.par();
1707 ParagraphList::iterator next_par = boost::next(par);
1709 if (next_par != ownerParagraphs().end())
1710 setCursor(next_par, 0);
1712 setCursor(par, par->size());
1716 // fix the cursor `cur' after a characters has been deleted at `where'
1717 // position. Called by deleteEmptyParagraphMechanism
1718 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1720 // if cursor is not in the paragraph where the delete occured,
1722 if (cur.par() != where.par())
1725 // if cursor position is after the place where the delete occured,
1727 if (cur.pos() > where.pos())
1728 cur.pos(cur.pos()-1);
1730 // check also if we don't want to set the cursor on a spot behind the
1731 // pagragraph because we erased the last character.
1732 if (cur.pos() > cur.par()->size())
1733 cur.pos(cur.par()->size());
1735 // recompute row et al. for this cursor
1736 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1740 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1742 // Would be wrong to delete anything if we have a selection.
1743 if (selection.set())
1746 // We allow all kinds of "mumbo-jumbo" when freespacing.
1747 if (old_cursor.par()->isFreeSpacing())
1750 /* Ok I'll put some comments here about what is missing.
1751 I have fixed BackSpace (and thus Delete) to not delete
1752 double-spaces automagically. I have also changed Cut,
1753 Copy and Paste to hopefully do some sensible things.
1754 There are still some small problems that can lead to
1755 double spaces stored in the document file or space at
1756 the beginning of paragraphs. This happens if you have
1757 the cursor between to spaces and then save. Or if you
1758 cut and paste and the selection have a space at the
1759 beginning and then save right after the paste. I am
1760 sure none of these are very hard to fix, but I will
1761 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1762 that I can get some feedback. (Lgb)
1765 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1766 // delete the LineSeparator.
1769 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1770 // delete the LineSeparator.
1773 // If the pos around the old_cursor were spaces, delete one of them.
1774 if (old_cursor.par() != cursor.par()
1775 || old_cursor.pos() != cursor.pos()) {
1777 // Only if the cursor has really moved
1778 if (old_cursor.pos() > 0
1779 && old_cursor.pos() < old_cursor.par()->size()
1780 && old_cursor.par()->isLineSeparator(old_cursor.pos())
1781 && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
1782 bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
1783 redoParagraph(old_cursor.par());
1787 #ifdef WITH_WARNINGS
1788 #warning This will not work anymore when we have multiple views of the same buffer
1789 // In this case, we will have to correct also the cursors held by
1790 // other bufferviews. It will probably be easier to do that in a more
1791 // automated way in LyXCursor code. (JMarc 26/09/2001)
1793 // correct all cursors held by the LyXText
1794 fixCursorAfterDelete(cursor, old_cursor);
1795 fixCursorAfterDelete(selection.cursor, old_cursor);
1796 fixCursorAfterDelete(selection.start, old_cursor);
1797 fixCursorAfterDelete(selection.end, old_cursor);
1802 // don't delete anything if this is the ONLY paragraph!
1803 if (ownerParagraphs().size() == 1)
1806 // Do not delete empty paragraphs with keepempty set.
1807 if (old_cursor.par()->allowEmpty())
1810 // only do our magic if we changed paragraph
1811 if (old_cursor.par() == cursor.par())
1814 // record if we have deleted a paragraph
1815 // we can't possibly have deleted a paragraph before this point
1816 bool deleted = false;
1818 if (old_cursor.par()->empty() ||
1819 (old_cursor.par()->size() == 1 &&
1820 old_cursor.par()->isLineSeparator(0))) {
1821 // ok, we will delete something
1822 LyXCursor tmpcursor;
1826 bool selection_position_was_oldcursor_position = (
1827 selection.cursor.par() == old_cursor.par()
1828 && selection.cursor.pos() == old_cursor.pos());
1831 cursor = old_cursor; // that undo can restore the right cursor position
1833 ParagraphList::iterator endpit = boost::next(old_cursor.par());
1834 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1837 recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
1841 ownerParagraphs().erase(old_cursor.par());
1845 setCursorIntern(cursor.par(), cursor.pos());
1847 if (selection_position_was_oldcursor_position) {
1848 // correct selection
1849 selection.cursor = cursor;
1853 if (old_cursor.par()->stripLeadingSpaces()) {
1854 redoParagraph(old_cursor.par());
1856 setCursorIntern(cursor.par(), cursor.pos());
1857 selection.cursor = cursor;
1864 ParagraphList & LyXText::ownerParagraphs() const
1870 bool LyXText::isInInset() const
1872 // Sub-level has non-null bv owner and non-null inset owner.
1873 return inset_owner != 0;
1877 int defaultRowHeight()
1879 LyXFont const font(LyXFont::ALL_SANE);
1880 return int(font_metrics::maxAscent(font)
1881 + font_metrics::maxDescent(font) * 1.5);