3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Alfredo Braunstein
9 * \author Jean-Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
15 * \author Jürgen Vigna
17 * Full author contact details are available in file CREDITS.
25 #include "paragraph.h"
26 #include "funcrequest.h"
27 #include "frontends/LyXView.h"
28 #include "undo_funcs.h"
30 #include "buffer_funcs.h"
31 #include "bufferparams.h"
32 #include "errorlist.h"
34 #include "BufferView.h"
35 #include "CutAndPaste.h"
36 #include "frontends/Painter.h"
37 #include "frontends/font_metrics.h"
41 #include "FloatList.h"
43 #include "ParagraphParameters.h"
45 #include "lyxrow_funcs.h"
46 #include "metricsinfo.h"
47 #include "paragraph_funcs.h"
49 #include "insets/insetbibitem.h"
50 #include "insets/insetenv.h"
51 #include "insets/insetfloat.h"
52 #include "insets/insetwrap.h"
54 #include "support/LAssert.h"
55 #include "support/textutils.h"
56 #include "support/lstrings.h"
58 #include <boost/tuple/tuple.hpp>
62 using namespace lyx::support;
72 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
73 ParagraphList & paragraphs)
74 : height(0), width(0), anchor_y_(0),
75 inset_owner(inset), the_locking_inset(0), bv_owner(bv),
76 in_inset_(ininset), paragraphs_(paragraphs)
81 void LyXText::init(BufferView * bview)
85 ParagraphList::iterator const beg = ownerParagraphs().begin();
86 ParagraphList::iterator const end = ownerParagraphs().end();
87 for (ParagraphList::iterator pit = beg; pit != end; ++pit)
95 current_font = getFont(beg, 0);
97 redoParagraphs(beg, end);
98 setCursorIntern(beg, 0);
99 selection.cursor = cursor;
105 // Gets the fully instantiated font at a given position in a paragraph
106 // Basically the same routine as Paragraph::getFont() in paragraph.C.
107 // The difference is that this one is used for displaying, and thus we
108 // are allowed to make cosmetic improvements. For instance make footnotes
110 LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
114 LyXLayout_ptr const & layout = pit->layout();
116 BufferParams const & params = bv()->buffer()->params;
118 // We specialize the 95% common case:
119 if (!pit->getDepth()) {
120 if (layout->labeltype == LABEL_MANUAL
121 && pos < pit->beginningOfBody()) {
123 LyXFont f = pit->getFontSettings(params, pos);
125 pit->inInset()->getDrawFont(f);
126 return f.realize(layout->reslabelfont);
128 LyXFont f = pit->getFontSettings(params, pos);
130 pit->inInset()->getDrawFont(f);
131 return f.realize(layout->resfont);
135 // The uncommon case need not be optimized as much
139 if (pos < pit->beginningOfBody()) {
141 layoutfont = layout->labelfont;
144 layoutfont = layout->font;
147 LyXFont tmpfont = pit->getFontSettings(params, pos);
148 tmpfont.realize(layoutfont);
151 pit->inInset()->getDrawFont(tmpfont);
153 // Realize with the fonts of lesser depth.
154 tmpfont.realize(outerFont(pit, ownerParagraphs()));
155 tmpfont.realize(defaultfont_);
161 LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const
163 LyXLayout_ptr const & layout = pit->layout();
165 if (!pit->getDepth())
166 return layout->resfont;
168 LyXFont font = layout->font;
169 // Realize with the fonts of lesser depth.
170 font.realize(outerFont(pit, ownerParagraphs()));
171 font.realize(defaultfont_);
177 LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
179 LyXLayout_ptr const & layout = pit->layout();
181 if (!pit->getDepth())
182 return layout->reslabelfont;
184 LyXFont font = layout->labelfont;
185 // Realize with the fonts of lesser depth.
186 font.realize(outerFont(pit, ownerParagraphs()));
187 font.realize(defaultfont_);
193 void LyXText::setCharFont(ParagraphList::iterator pit,
194 pos_type pos, LyXFont const & fnt,
197 BufferParams const & params = bv()->buffer()->params;
198 LyXFont font = getFont(pit, pos);
199 font.update(fnt, params.language, toggleall);
200 // Let the insets convert their font
201 if (pit->isInset(pos)) {
202 InsetOld * inset = pit->getInset(pos);
203 if (isEditableInset(inset)) {
204 static_cast<UpdatableInset *>(inset)
205 ->setFont(bv(), fnt, toggleall, true);
209 // Plug through to version below:
210 setCharFont(pit, pos, font);
214 void LyXText::setCharFont(
215 ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
218 LyXLayout_ptr const & layout = pit->layout();
220 // Get concrete layout font to reduce against
223 if (pos < pit->beginningOfBody())
224 layoutfont = layout->labelfont;
226 layoutfont = layout->font;
228 // Realize against environment font information
229 if (pit->getDepth()) {
230 ParagraphList::iterator tp = pit;
231 while (!layoutfont.resolved() &&
232 tp != ownerParagraphs().end() &&
234 tp = outerHook(tp, ownerParagraphs());
235 if (tp != ownerParagraphs().end())
236 layoutfont.realize(tp->layout()->font);
240 layoutfont.realize(defaultfont_);
242 // Now, reduce font against full layout font
243 font.reduce(layoutfont);
245 pit->setFont(pos, font);
249 InsetOld * LyXText::getInset() const
251 ParagraphList::iterator pit = cursor.par();
252 pos_type const pos = cursor.pos();
254 if (pos < pit->size() && pit->isInset(pos)) {
255 return pit->getInset(pos);
261 void LyXText::toggleInset()
263 InsetOld * inset = getInset();
264 // is there an editable inset at cursor position?
265 if (!isEditableInset(inset)) {
266 // No, try to see if we are inside a collapsable inset
267 if (inset_owner && inset_owner->owner()
268 && inset_owner->owner()->isOpen()) {
269 bv()->unlockInset(inset_owner->owner());
270 inset_owner->owner()->close(bv());
271 bv()->getLyXText()->cursorRight(bv());
275 //bv()->owner()->message(inset->editMessage());
277 // do we want to keep this?? (JMarc)
278 if (!isHighlyEditableInset(inset))
279 recordUndo(bv(), Undo::ATOMIC);
286 bv()->updateInset(inset);
290 /* used in setlayout */
291 // Asger is not sure we want to do this...
292 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
295 LyXLayout_ptr const & layout = par.layout();
296 pos_type const psize = par.size();
299 for (pos_type pos = 0; pos < psize; ++pos) {
300 if (pos < par.beginningOfBody())
301 layoutfont = layout->labelfont;
303 layoutfont = layout->font;
305 LyXFont tmpfont = par.getFontSettings(params, pos);
306 tmpfont.reduce(layoutfont);
307 par.setFont(pos, tmpfont);
312 ParagraphList::iterator
313 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
314 LyXCursor & send_cur,
315 string const & layout)
317 ParagraphList::iterator endpit = boost::next(send_cur.par());
318 ParagraphList::iterator undoendpit = endpit;
319 ParagraphList::iterator pars_end = ownerParagraphs().end();
321 if (endpit != pars_end && endpit->getDepth()) {
322 while (endpit != pars_end && endpit->getDepth()) {
326 } else if (endpit != pars_end) {
327 // because of parindents etc.
331 recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(undoendpit));
333 // ok we have a selection. This is always between sstart_cur
334 // and sel_end cursor
336 ParagraphList::iterator pit = sstart_cur.par();
337 ParagraphList::iterator epit = boost::next(send_cur.par());
339 LyXLayout_ptr const & lyxlayout =
340 bv()->buffer()->params.getLyXTextClass()[layout];
343 pit->applyLayout(lyxlayout);
344 makeFontEntriesLayoutSpecific(bv()->buffer()->params, *pit);
345 pit->params().spaceTop(lyxlayout->fill_top ?
346 VSpace(VSpace::VFILL)
347 : VSpace(VSpace::NONE));
348 pit->params().spaceBottom(lyxlayout->fill_bottom ?
349 VSpace(VSpace::VFILL)
350 : VSpace(VSpace::NONE));
351 if (lyxlayout->margintype == MARGIN_MANUAL)
352 pit->setLabelWidthString(lyxlayout->labelstring());
355 } while (pit != epit);
361 // set layout over selection and make a total rebreak of those paragraphs
362 void LyXText::setLayout(string const & layout)
364 LyXCursor tmpcursor = cursor; // store the current cursor
366 // if there is no selection just set the layout
367 // of the current paragraph
368 if (!selection.set()) {
369 selection.start = cursor; // dummy selection
370 selection.end = cursor;
373 // special handling of new environment insets
374 BufferParams const & params = bv()->buffer()->params;
375 LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
376 if (lyxlayout->is_environment) {
377 // move everything in a new environment inset
378 lyxerr << "setting layout " << layout << endl;
379 bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
380 bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
381 bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
382 InsetOld * inset = new InsetEnvironment(params, layout);
383 if (bv()->insertInset(inset)) {
385 //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
392 ParagraphList::iterator endpit = setLayout(cursor, selection.start,
393 selection.end, layout);
394 redoParagraphs(selection.start.par(), endpit);
396 // we have to reset the selection, because the
397 // geometry could have changed
398 setCursor(selection.start.par(), selection.start.pos(), false);
399 selection.cursor = cursor;
400 setCursor(selection.end.par(), selection.end.pos(), false);
404 setCursor(tmpcursor.par(), tmpcursor.pos(), true);
408 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
410 ParagraphList::iterator pit = cursor.par();
411 ParagraphList::iterator end = cursor.par();
412 ParagraphList::iterator start = pit;
414 if (selection.set()) {
415 pit = selection.start.par();
416 end = selection.end.par();
420 ParagraphList::iterator pastend = boost::next(end);
423 recordUndo(bv(), Undo::ATOMIC, start, end);
425 bool changed = false;
427 int prev_after_depth = 0;
428 #warning parlist ... could be nicer ?
429 if (start != ownerParagraphs().begin()) {
430 prev_after_depth = boost::prior(start)->getMaxDepthAfter();
434 int const depth = pit->params().depth();
435 if (type == bv_funcs::INC_DEPTH) {
436 if (depth < prev_after_depth
437 && pit->layout()->labeltype != LABEL_BIBLIO) {
440 pit->params().depth(depth + 1);
445 pit->params().depth(depth - 1);
448 prev_after_depth = pit->getMaxDepthAfter();
460 redoParagraphs(start, pastend);
462 // We need to actually move the text->cursor. I don't
463 // understand why ...
464 LyXCursor tmpcursor = cursor;
466 // we have to reset the visual selection because the
467 // geometry could have changed
468 if (selection.set()) {
469 setCursor(selection.start.par(), selection.start.pos());
470 selection.cursor = cursor;
471 setCursor(selection.end.par(), selection.end.pos());
474 // this handles the counter labels, and also fixes up
475 // depth values for follow-on (child) paragraphs
479 setCursor(tmpcursor.par(), tmpcursor.pos());
485 // set font over selection and make a total rebreak of those paragraphs
486 void LyXText::setFont(LyXFont const & font, bool toggleall)
488 // if there is no selection just set the current_font
489 if (!selection.set()) {
490 // Determine basis font
492 if (cursor.pos() < cursor.par()->beginningOfBody()) {
493 layoutfont = getLabelFont(cursor.par());
495 layoutfont = getLayoutFont(cursor.par());
497 // Update current font
498 real_current_font.update(font,
499 bv()->buffer()->params.language,
502 // Reduce to implicit settings
503 current_font = real_current_font;
504 current_font.reduce(layoutfont);
505 // And resolve it completely
506 real_current_font.realize(layoutfont);
511 LyXCursor tmpcursor = cursor; // store the current cursor
513 // ok we have a selection. This is always between sel_start_cursor
514 // and sel_end cursor
516 recordUndo(bv(), Undo::ATOMIC, selection.start.par(), selection.end.par());
518 cursor = selection.start;
519 while (cursor.par() != selection.end.par() ||
520 cursor.pos() < selection.end.pos())
522 if (cursor.pos() < cursor.par()->size()) {
523 // an open footnote should behave like a closed one
524 setCharFont(cursor.par(), cursor.pos(),
526 cursor.pos(cursor.pos() + 1);
529 cursor.par(boost::next(cursor.par()));
534 redoParagraph(selection.start.par());
536 // we have to reset the selection, because the
537 // geometry could have changed, but we keep
538 // it for user convenience
539 setCursor(selection.start.par(), selection.start.pos());
540 selection.cursor = cursor;
541 setCursor(selection.end.par(), selection.end.pos());
543 setCursor(tmpcursor.par(), tmpcursor.pos(), true,
544 tmpcursor.boundary());
548 int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
550 RowList::iterator rit = pit->rows.begin();
551 RowList::iterator end = pit->rows.end();
553 // remove rows of paragraph, keep track of height changes
554 for (int i = 0; rit != end; ++rit, ++i)
555 height -= rit->height();
559 InsetList::iterator ii = pit->insetlist.begin();
560 InsetList::iterator iend = pit->insetlist.end();
561 for (; ii != iend; ++ii) {
563 MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
564 ii->inset->metrics(mi, dim);
567 // rebreak the paragraph
568 for (pos_type z = 0; z < pit->size() + 1; ) {
570 z = rowBreakPoint(pit, row) + 1;
572 pit->rows.push_back(row);
576 // set height and fill and width of rows
577 int const ww = workWidth();
578 for (rit = pit->rows.begin(); rit != end; ++rit) {
579 int const f = fill(pit, rit, ww);
580 int const w = ww - f;
581 par_width = std::max(par_width, w);
584 prepareToPrint(pit, rit);
585 setHeightOfRow(pit, rit);
586 height += rit->height();
589 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
594 int LyXText::redoParagraphs(ParagraphList::iterator start,
595 ParagraphList::iterator end)
598 for ( ; start != end; ++start) {
599 int par_width = redoParagraphInternal(start);
600 pars_width = std::max(par_width, pars_width);
602 updateRowPositions();
607 void LyXText::redoParagraph(ParagraphList::iterator pit)
609 redoParagraphInternal(pit);
610 updateRowPositions();
614 void LyXText::fullRebreak()
616 redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
618 selection.cursor = cursor;
622 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
624 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
625 // << " workWidth: " << workWidth() << endl;
626 //Assert(mi.base.textwidth);
633 width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
636 dim.asc = firstRow()->ascent_of_text();
637 dim.des = height - dim.asc;
638 dim.wid = std::max(mi.base.textwidth, int(width));
642 // important for the screen
645 // the cursor set functions have a special mechanism. When they
646 // realize, that you left an empty paragraph, they will delete it.
647 // They also delete the corresponding row
649 // need the selection cursor:
650 void LyXText::setSelection()
652 TextCursor::setSelection();
657 void LyXText::clearSelection()
659 TextCursor::clearSelection();
661 // reset this in the bv_owner!
662 if (bv_owner && bv_owner->text)
663 bv_owner->text->xsel_cache.set(false);
667 void LyXText::cursorHome()
669 setCursor(cursor.par(), cursorRow()->pos());
673 void LyXText::cursorEnd()
675 setCursor(cursor.par(), cursorRow()->end() - 1);
679 void LyXText::cursorTop()
681 setCursor(ownerParagraphs().begin(), 0);
685 void LyXText::cursorBottom()
687 ParagraphList::iterator lastpit =
688 boost::prior(ownerParagraphs().end());
689 setCursor(lastpit, lastpit->size());
693 void LyXText::toggleFree(LyXFont const & font, bool toggleall)
695 // If the mask is completely neutral, tell user
696 if (font == LyXFont(LyXFont::ALL_IGNORE)) {
697 // Could only happen with user style
698 bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
702 // Try implicit word selection
703 // If there is a change in the language the implicit word selection
705 LyXCursor resetCursor = cursor;
706 bool implicitSelection = (font.language() == ignore_language
707 && font.number() == LyXFont::IGNORE)
708 ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
711 setFont(font, toggleall);
713 // Implicit selections are cleared afterwards
714 //and cursor is set to the original position.
715 if (implicitSelection) {
717 cursor = resetCursor;
718 setCursor(cursor.par(), cursor.pos());
719 selection.cursor = cursor;
724 string LyXText::getStringToIndex()
726 // Try implicit word selection
727 // If there is a change in the language the implicit word selection
729 LyXCursor const reset_cursor = cursor;
730 bool const implicitSelection =
731 selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
734 if (!selection.set())
735 bv()->owner()->message(_("Nothing to index!"));
736 else if (selection.start.par() != selection.end.par())
737 bv()->owner()->message(_("Cannot index more than one paragraph!"));
739 idxstring = selectionAsString(*bv()->buffer(), false);
741 // Reset cursors to their original position.
742 cursor = reset_cursor;
743 setCursor(cursor.par(), cursor.pos());
744 selection.cursor = cursor;
746 // Clear the implicit selection.
747 if (implicitSelection)
754 // the DTP switches for paragraphs. LyX will store them in the first
755 // physical paragraph. When a paragraph is broken, the top settings rest,
756 // the bottom settings are given to the new one. So I can make sure,
757 // they do not duplicate themself and you cannnot make dirty things with
760 void LyXText::setParagraph(bool line_top, bool line_bottom,
761 bool pagebreak_top, bool pagebreak_bottom,
762 VSpace const & space_top,
763 VSpace const & space_bottom,
764 Spacing const & spacing,
766 string const & labelwidthstring,
769 LyXCursor tmpcursor = cursor;
770 if (!selection.set()) {
771 selection.start = cursor;
772 selection.end = cursor;
775 // make sure that the depth behind the selection are restored, too
776 ParagraphList::iterator endpit = boost::next(selection.end.par());
777 ParagraphList::iterator undoendpit = endpit;
778 ParagraphList::iterator pars_end = ownerParagraphs().end();
780 if (endpit != pars_end && endpit->getDepth()) {
781 while (endpit != pars_end && endpit->getDepth()) {
785 } else if (endpit != pars_end) {
786 // because of parindents etc.
790 recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
791 boost::prior(undoendpit));
794 ParagraphList::iterator tmppit = selection.end.par();
796 while (tmppit != boost::prior(selection.start.par())) {
797 setCursor(tmppit, 0);
799 ParagraphList::iterator pit = cursor.par();
800 ParagraphParameters & params = pit->params();
802 params.lineTop(line_top);
803 params.lineBottom(line_bottom);
804 params.pagebreakTop(pagebreak_top);
805 params.pagebreakBottom(pagebreak_bottom);
806 params.spaceTop(space_top);
807 params.spaceBottom(space_bottom);
808 params.spacing(spacing);
809 // does the layout allow the new alignment?
810 LyXLayout_ptr const & layout = pit->layout();
812 if (align == LYX_ALIGN_LAYOUT)
813 align = layout->align;
814 if (align & layout->alignpossible) {
815 if (align == layout->align)
816 params.align(LYX_ALIGN_LAYOUT);
820 pit->setLabelWidthString(labelwidthstring);
821 params.noindent(noindent);
822 tmppit = boost::prior(pit);
825 redoParagraphs(selection.start.par(), endpit);
828 setCursor(selection.start.par(), selection.start.pos());
829 selection.cursor = cursor;
830 setCursor(selection.end.par(), selection.end.pos());
832 setCursor(tmpcursor.par(), tmpcursor.pos());
834 bv()->updateInset(inset_owner);
838 // set the counter of a paragraph. This includes the labels
839 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
841 LyXTextClass const & textclass = buf.params.getLyXTextClass();
842 LyXLayout_ptr const & layout = pit->layout();
844 if (pit != ownerParagraphs().begin()) {
846 pit->params().appendix(boost::prior(pit)->params().appendix());
847 if (!pit->params().appendix() &&
848 pit->params().startOfAppendix()) {
849 pit->params().appendix(true);
850 textclass.counters().reset();
852 pit->enumdepth = boost::prior(pit)->enumdepth;
853 pit->itemdepth = boost::prior(pit)->itemdepth;
855 pit->params().appendix(pit->params().startOfAppendix());
860 // Maybe we have to increment the enumeration depth.
861 // BUT, enumeration in a footnote is considered in isolation from its
862 // surrounding paragraph so don't increment if this is the
863 // first line of the footnote
864 // AND, bibliographies can't have their depth changed ie. they
865 // are always of depth 0
866 if (pit != ownerParagraphs().begin()
867 && boost::prior(pit)->getDepth() < pit->getDepth()
868 && boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI
869 && pit->enumdepth < 3
870 && layout->labeltype != LABEL_BIBLIO) {
874 // Maybe we have to decrement the enumeration depth, see note above
875 if (pit != ownerParagraphs().begin()
876 && boost::prior(pit)->getDepth() > pit->getDepth()
877 && layout->labeltype != LABEL_BIBLIO) {
878 pit->enumdepth = depthHook(pit, ownerParagraphs(),
879 pit->getDepth())->enumdepth;
882 if (!pit->params().labelString().empty()) {
883 pit->params().labelString(string());
886 if (layout->margintype == MARGIN_MANUAL) {
887 if (pit->params().labelWidthString().empty())
888 pit->setLabelWidthString(layout->labelstring());
890 pit->setLabelWidthString(string());
893 // is it a layout that has an automatic label?
894 if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
895 int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
899 if (i >= 0 && i <= buf.params.secnumdepth) {
903 textclass.counters().step(layout->latexname());
905 // Is there a label? Useful for Chapter layout
906 if (!pit->params().appendix()) {
907 s << buf.B_(layout->labelstring());
909 s << buf.B_(layout->labelstring_appendix());
912 // Use of an integer is here less than elegant. For now.
913 int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
914 if (!pit->params().appendix()) {
915 numbertype = "sectioning";
917 numbertype = "appendix";
918 if (pit->isRightToLeftPar(buf.params))
925 << textclass.counters()
926 .numberLabel(layout->latexname(),
927 numbertype, langtype, head);
929 pit->params().labelString(STRCONV(s.str()));
931 // reset enum counters
932 textclass.counters().reset("enum");
933 } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
934 textclass.counters().reset("enum");
935 } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
937 // Yes I know this is a really, really! bad solution
939 string enumcounter("enum");
941 switch (pit->enumdepth) {
953 // not a valid enumdepth...
957 textclass.counters().step(enumcounter);
959 s << textclass.counters()
960 .numberLabel(enumcounter, "enumeration");
961 pit->params().labelString(STRCONV(s.str()));
963 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
964 textclass.counters().step("bibitem");
965 int number = textclass.counters().value("bibitem");
966 if (pit->bibitem()) {
967 pit->bibitem()->setCounter(number);
968 pit->params().labelString(layout->labelstring());
970 // In biblio should't be following counters but...
972 string s = buf.B_(layout->labelstring());
975 if (layout->labeltype == LABEL_SENSITIVE) {
976 ParagraphList::iterator end = ownerParagraphs().end();
977 ParagraphList::iterator tmppit = pit;
980 while (tmppit != end && tmppit->inInset()
981 // the single '=' is intended below
982 && (in = tmppit->inInset()->owner()))
984 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
985 in->lyxCode() == InsetOld::WRAP_CODE) {
989 Paragraph const * owner = &ownerPar(buf, in);
990 tmppit = ownerParagraphs().begin();
991 for ( ; tmppit != end; ++tmppit)
992 if (&*tmppit == owner)
1000 if (in->lyxCode() == InsetOld::FLOAT_CODE)
1001 type = static_cast<InsetFloat*>(in)->params().type;
1002 else if (in->lyxCode() == InsetOld::WRAP_CODE)
1003 type = static_cast<InsetWrap*>(in)->params().type;
1007 Floating const & fl = textclass.floats().getType(type);
1009 textclass.counters().step(fl.type());
1011 // Doesn't work... yet.
1012 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1014 // par->SetLayout(0);
1015 // s = layout->labelstring;
1016 s = _("Senseless: ");
1019 pit->params().labelString(s);
1021 // reset the enumeration counter. They are always reset
1022 // when there is any other layout between
1023 // Just fall-through between the cases so that all
1024 // enum counters deeper than enumdepth is also reset.
1025 switch (pit->enumdepth) {
1027 textclass.counters().reset("enumi");
1029 textclass.counters().reset("enumii");
1031 textclass.counters().reset("enumiii");
1033 textclass.counters().reset("enumiv");
1039 // Updates all counters. Paragraphs with changed label string will be rebroken
1040 void LyXText::updateCounters()
1043 bv()->buffer()->params.getLyXTextClass().counters().reset();
1045 ParagraphList::iterator beg = ownerParagraphs().begin();
1046 ParagraphList::iterator end = ownerParagraphs().end();
1047 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1048 string const oldLabel = pit->params().labelString();
1050 size_t maxdepth = 0;
1052 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1054 if (pit->params().depth() > maxdepth)
1055 pit->params().depth(maxdepth);
1057 // setCounter can potentially change the labelString.
1058 setCounter(*bv()->buffer(), pit);
1060 string const & newLabel = pit->params().labelString();
1062 if (oldLabel != newLabel)
1068 void LyXText::insertInset(InsetOld * inset)
1070 if (!cursor.par()->insetAllowed(inset->lyxCode()))
1072 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1074 cursor.par()->insertInset(cursor.pos(), inset);
1075 // Just to rebreak and refresh correctly.
1076 // The character will not be inserted a second time
1077 insertChar(Paragraph::META_INSET);
1078 // If we enter a highly editable inset the cursor should be before
1079 // the inset. After an Undo LyX tries to call inset->edit(...)
1080 // and fails if the cursor is behind the inset and getInset
1081 // does not return the inset!
1082 if (isHighlyEditableInset(inset))
1088 void LyXText::cutSelection(bool doclear, bool realcut)
1090 // Stuff what we got on the clipboard. Even if there is no selection.
1092 // There is a problem with having the stuffing here in that the
1093 // larger the selection the slower LyX will get. This can be
1094 // solved by running the line below only when the selection has
1095 // finished. The solution used currently just works, to make it
1096 // faster we need to be more clever and probably also have more
1097 // calls to stuffClipboard. (Lgb)
1098 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1100 // This doesn't make sense, if there is no selection
1101 if (!selection.set())
1104 // OK, we have a selection. This is always between selection.start
1105 // and selection.end
1107 // make sure that the depth behind the selection are restored, too
1108 ParagraphList::iterator endpit = boost::next(selection.end.par());
1109 ParagraphList::iterator undoendpit = endpit;
1110 ParagraphList::iterator pars_end = ownerParagraphs().end();
1112 if (endpit != pars_end && endpit->getDepth()) {
1113 while (endpit != pars_end && endpit->getDepth()) {
1115 undoendpit = endpit;
1117 } else if (endpit != pars_end) {
1118 // because of parindents etc.
1122 recordUndo(bv(), Undo::DELETE, selection.start.par(),
1123 boost::prior(undoendpit));
1125 endpit = selection.end.par();
1126 int endpos = selection.end.pos();
1128 boost::tie(endpit, endpos) = realcut ?
1129 CutAndPaste::cutSelection(bv()->buffer()->params,
1131 selection.start.par(), endpit,
1132 selection.start.pos(), endpos,
1133 bv()->buffer()->params.textclass,
1135 : CutAndPaste::eraseSelection(bv()->buffer()->params,
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 current_font = pit->getFontSettings(bv()->buffer()->params, pos);
1465 real_current_font = getFont(pit, pos);
1467 if (cursor.pos() == pit->size() &&
1468 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1469 !cursor.boundary()) {
1470 Language const * lang =
1471 pit->getParLanguage(bv()->buffer()->params);
1472 current_font.setLanguage(lang);
1473 current_font.setNumber(LyXFont::OFF);
1474 real_current_font.setLanguage(lang);
1475 real_current_font.setNumber(LyXFont::OFF);
1480 // returns the column near the specified x-coordinate of the row
1481 // x is set to the real beginning of this column
1482 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1483 RowList::iterator rit, int & x, bool & boundary) const
1485 double tmpx = rit->x();
1486 double fill_separator = rit->fill_separator();
1487 double fill_hfill = rit->fill_hfill();
1488 double fill_label_hfill = rit->fill_label_hfill();
1490 pos_type vc = rit->pos();
1491 pos_type last = lastPos(*pit, rit);
1493 LyXLayout_ptr const & layout = pit->layout();
1495 bool left_side = false;
1497 pos_type body_pos = pit->beginningOfBody();
1498 double last_tmpx = tmpx;
1501 (body_pos - 1 > last ||
1502 !pit->isLineSeparator(body_pos - 1)))
1505 // check for empty row
1511 while (vc <= last && tmpx <= x) {
1514 if (body_pos > 0 && c == body_pos - 1) {
1515 tmpx += fill_label_hfill +
1516 font_metrics::width(layout->labelsep, getLabelFont(pit));
1517 if (pit->isLineSeparator(body_pos - 1))
1518 tmpx -= singleWidth(pit, body_pos - 1);
1521 if (hfillExpansion(*pit, rit, c)) {
1522 tmpx += singleWidth(pit, c);
1526 tmpx += fill_label_hfill;
1527 } else if (pit->isSeparator(c)) {
1528 tmpx += singleWidth(pit, c);
1530 tmpx += fill_separator;
1532 tmpx += singleWidth(pit, c);
1537 if ((tmpx + last_tmpx) / 2 > x) {
1542 if (vc > last + 1) // This shouldn't happen.
1546 // This (rtl_support test) is not needed, but gives
1547 // some speedup if rtl_support == false
1548 bool const lastrow = lyxrc.rtl_support
1549 && boost::next(rit) == pit->rows.end();
1551 // If lastrow is false, we don't need to compute
1552 // the value of rtl.
1553 bool const rtl = (lastrow)
1554 ? pit->isRightToLeftPar(bv()->buffer()->params)
1557 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1558 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1560 else if (vc == rit->pos()) {
1562 if (bidi_level(c) % 2 == 1)
1565 c = vis2log(vc - 1);
1566 bool const rtl = (bidi_level(c) % 2 == 1);
1567 if (left_side == rtl) {
1569 boundary = isBoundary(*bv()->buffer(), *pit, c);
1573 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1574 if (bidi_level(last) % 2 == 0)
1575 tmpx -= singleWidth(pit, last);
1577 tmpx += singleWidth(pit, last);
1587 void LyXText::setCursorFromCoordinates(int x, int y)
1589 LyXCursor old_cursor = cursor;
1590 setCursorFromCoordinates(cursor, x, y);
1592 deleteEmptyParagraphMechanism(old_cursor);
1596 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1598 // Get the row first.
1599 ParagraphList::iterator pit;
1600 RowList::iterator rit = getRowNearY(y, pit);
1604 pos_type const column = getColumnNearX(pit, rit, x, bound);
1606 cur.pos(rit->pos() + column);
1608 cur.y(y + rit->baseline());
1610 cur.boundary(bound);
1614 void LyXText::cursorLeft(bool internal)
1616 if (cursor.pos() > 0) {
1617 bool boundary = cursor.boundary();
1618 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1619 if (!internal && !boundary &&
1620 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
1621 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1622 } else if (cursor.par() != ownerParagraphs().begin()) {
1623 // steps into the paragraph above
1624 ParagraphList::iterator pit = boost::prior(cursor.par());
1625 setCursor(pit, pit->size());
1630 void LyXText::cursorRight(bool internal)
1632 bool const at_end = (cursor.pos() == cursor.par()->size());
1633 bool const at_newline = !at_end &&
1634 cursor.par()->isNewline(cursor.pos());
1636 if (!internal && cursor.boundary() && !at_newline)
1637 setCursor(cursor.par(), cursor.pos(), true, false);
1639 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1641 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
1642 setCursor(cursor.par(), cursor.pos(), true, true);
1643 } else if (boost::next(cursor.par()) != ownerParagraphs().end())
1644 setCursor(boost::next(cursor.par()), 0);
1648 void LyXText::cursorUp(bool selecting)
1651 int x = cursor.x_fix();
1652 int y = cursor.y() - cursorRow()->baseline() - 1;
1653 setCursorFromCoordinates(x, y);
1655 int topy = bv_owner->top_y();
1656 int y1 = cursor.y() - topy;
1659 InsetOld * inset_hit = checkInsetHit(x, y1);
1660 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1661 inset_hit->localDispatch(
1662 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1666 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1667 cursorRow()->baseline() << endl;
1668 setCursorFromCoordinates(cursor.x_fix(),
1669 cursor.y() - cursorRow()->baseline() - 1);
1674 void LyXText::cursorDown(bool selecting)
1677 int x = cursor.x_fix();
1678 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1679 setCursorFromCoordinates(x, y);
1680 if (!selecting && cursorRow() == cursorIRow()) {
1681 int topy = bv_owner->top_y();
1682 int y1 = cursor.y() - topy;
1685 InsetOld * inset_hit = checkInsetHit(x, y1);
1686 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1687 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1688 inset_hit->localDispatch(cmd);
1692 setCursorFromCoordinates(cursor.x_fix(),
1693 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1698 void LyXText::cursorUpParagraph()
1700 if (cursor.pos() > 0)
1701 setCursor(cursor.par(), 0);
1702 else if (cursor.par() != ownerParagraphs().begin())
1703 setCursor(boost::prior(cursor.par()), 0);
1707 void LyXText::cursorDownParagraph()
1709 ParagraphList::iterator par = cursor.par();
1710 ParagraphList::iterator next_par = boost::next(par);
1712 if (next_par != ownerParagraphs().end())
1713 setCursor(next_par, 0);
1715 setCursor(par, par->size());
1719 // fix the cursor `cur' after a characters has been deleted at `where'
1720 // position. Called by deleteEmptyParagraphMechanism
1721 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1723 // if cursor is not in the paragraph where the delete occured,
1725 if (cur.par() != where.par())
1728 // if cursor position is after the place where the delete occured,
1730 if (cur.pos() > where.pos())
1731 cur.pos(cur.pos()-1);
1733 // check also if we don't want to set the cursor on a spot behind the
1734 // pagragraph because we erased the last character.
1735 if (cur.pos() > cur.par()->size())
1736 cur.pos(cur.par()->size());
1738 // recompute row et al. for this cursor
1739 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1743 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1745 // Would be wrong to delete anything if we have a selection.
1746 if (selection.set())
1749 // We allow all kinds of "mumbo-jumbo" when freespacing.
1750 if (old_cursor.par()->isFreeSpacing())
1753 /* Ok I'll put some comments here about what is missing.
1754 I have fixed BackSpace (and thus Delete) to not delete
1755 double-spaces automagically. I have also changed Cut,
1756 Copy and Paste to hopefully do some sensible things.
1757 There are still some small problems that can lead to
1758 double spaces stored in the document file or space at
1759 the beginning of paragraphs. This happens if you have
1760 the cursor between to spaces and then save. Or if you
1761 cut and paste and the selection have a space at the
1762 beginning and then save right after the paste. I am
1763 sure none of these are very hard to fix, but I will
1764 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1765 that I can get some feedback. (Lgb)
1768 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1769 // delete the LineSeparator.
1772 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1773 // delete the LineSeparator.
1776 // If the pos around the old_cursor were spaces, delete one of them.
1777 if (old_cursor.par() != cursor.par()
1778 || old_cursor.pos() != cursor.pos()) {
1780 // Only if the cursor has really moved
1781 if (old_cursor.pos() > 0
1782 && old_cursor.pos() < old_cursor.par()->size()
1783 && old_cursor.par()->isLineSeparator(old_cursor.pos())
1784 && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
1785 bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
1786 redoParagraph(old_cursor.par());
1790 #ifdef WITH_WARNINGS
1791 #warning This will not work anymore when we have multiple views of the same buffer
1792 // In this case, we will have to correct also the cursors held by
1793 // other bufferviews. It will probably be easier to do that in a more
1794 // automated way in LyXCursor code. (JMarc 26/09/2001)
1796 // correct all cursors held by the LyXText
1797 fixCursorAfterDelete(cursor, old_cursor);
1798 fixCursorAfterDelete(selection.cursor, old_cursor);
1799 fixCursorAfterDelete(selection.start, old_cursor);
1800 fixCursorAfterDelete(selection.end, old_cursor);
1805 // don't delete anything if this is the ONLY paragraph!
1806 if (ownerParagraphs().size() == 1)
1809 // Do not delete empty paragraphs with keepempty set.
1810 if (old_cursor.par()->allowEmpty())
1813 // only do our magic if we changed paragraph
1814 if (old_cursor.par() == cursor.par())
1817 // record if we have deleted a paragraph
1818 // we can't possibly have deleted a paragraph before this point
1819 bool deleted = false;
1821 if (old_cursor.par()->empty() ||
1822 (old_cursor.par()->size() == 1 &&
1823 old_cursor.par()->isLineSeparator(0))) {
1824 // ok, we will delete something
1825 LyXCursor tmpcursor;
1829 bool selection_position_was_oldcursor_position = (
1830 selection.cursor.par() == old_cursor.par()
1831 && selection.cursor.pos() == old_cursor.pos());
1834 cursor = old_cursor; // that undo can restore the right cursor position
1836 ParagraphList::iterator endpit = boost::next(old_cursor.par());
1837 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1840 recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
1844 ownerParagraphs().erase(old_cursor.par());
1848 setCursorIntern(cursor.par(), cursor.pos());
1850 if (selection_position_was_oldcursor_position) {
1851 // correct selection
1852 selection.cursor = cursor;
1856 if (old_cursor.par()->stripLeadingSpaces()) {
1857 redoParagraph(old_cursor.par());
1859 setCursorIntern(cursor.par(), cursor.pos());
1860 selection.cursor = cursor;
1867 ParagraphList & LyXText::ownerParagraphs() const
1873 bool LyXText::isInInset() const
1875 // Sub-level has non-null bv owner and non-null inset owner.
1876 return inset_owner != 0;
1880 int defaultRowHeight()
1882 LyXFont const font(LyXFont::ALL_SANE);
1883 return int(font_metrics::maxAscent(font)
1884 + font_metrics::maxDescent(font) * 1.5);