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 "bufferparams.h"
27 #include "BufferView.h"
29 #include "CutAndPaste.h"
31 #include "errorlist.h"
33 #include "FloatList.h"
34 #include "funcrequest.h"
39 #include "lyxrow_funcs.h"
40 #include "metricsinfo.h"
41 #include "paragraph_funcs.h"
42 #include "ParagraphParameters.h"
43 #include "undo_funcs.h"
45 #include "frontends/font_metrics.h"
46 #include "frontends/LyXView.h"
48 #include "insets/insetbibitem.h"
49 #include "insets/insetenv.h"
50 #include "insets/insetfloat.h"
51 #include "insets/insetwrap.h"
53 #include "support/LAssert.h"
54 #include "support/lstrings.h"
55 #include "support/textutils.h"
57 #include <boost/tuple/tuple.hpp>
59 #include "support/std_sstream.h"
61 using namespace lyx::support;
65 using std::ostringstream;
70 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
71 ParagraphList & paragraphs)
72 : height(0), width(0), anchor_y_(0),
73 inset_owner(inset), the_locking_inset(0), bv_owner(bv),
74 in_inset_(ininset), paragraphs_(paragraphs)
79 void LyXText::init(BufferView * bview)
83 ParagraphList::iterator const beg = ownerParagraphs().begin();
84 ParagraphList::iterator const end = ownerParagraphs().end();
85 for (ParagraphList::iterator pit = beg; pit != end; ++pit)
93 current_font = getFont(beg, 0);
95 redoParagraphs(beg, end);
96 setCursorIntern(beg, 0);
97 selection.cursor = cursor;
103 // Gets the fully instantiated font at a given position in a paragraph
104 // Basically the same routine as Paragraph::getFont() in paragraph.C.
105 // The difference is that this one is used for displaying, and thus we
106 // are allowed to make cosmetic improvements. For instance make footnotes
108 LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
112 LyXLayout_ptr const & layout = pit->layout();
114 BufferParams const & params = bv()->buffer()->params();
116 // We specialize the 95% common case:
117 if (!pit->getDepth()) {
118 if (layout->labeltype == LABEL_MANUAL
119 && pos < pit->beginningOfBody()) {
121 LyXFont f = pit->getFontSettings(params, pos);
123 pit->inInset()->getDrawFont(f);
124 return f.realize(layout->reslabelfont);
126 LyXFont f = pit->getFontSettings(params, pos);
128 pit->inInset()->getDrawFont(f);
129 return f.realize(layout->resfont);
133 // The uncommon case need not be optimized as much
137 if (pos < pit->beginningOfBody()) {
139 layoutfont = layout->labelfont;
142 layoutfont = layout->font;
145 LyXFont tmpfont = pit->getFontSettings(params, pos);
146 tmpfont.realize(layoutfont);
149 pit->inInset()->getDrawFont(tmpfont);
151 // Realize with the fonts of lesser depth.
152 tmpfont.realize(outerFont(pit, ownerParagraphs()));
153 tmpfont.realize(defaultfont_);
159 LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const
161 LyXLayout_ptr const & layout = pit->layout();
163 if (!pit->getDepth())
164 return layout->resfont;
166 LyXFont font = layout->font;
167 // Realize with the fonts of lesser depth.
168 font.realize(outerFont(pit, ownerParagraphs()));
169 font.realize(defaultfont_);
175 LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
177 LyXLayout_ptr const & layout = pit->layout();
179 if (!pit->getDepth())
180 return layout->reslabelfont;
182 LyXFont font = layout->labelfont;
183 // Realize with the fonts of lesser depth.
184 font.realize(outerFont(pit, ownerParagraphs()));
185 font.realize(defaultfont_);
191 void LyXText::setCharFont(ParagraphList::iterator pit,
192 pos_type pos, LyXFont const & fnt,
195 BufferParams const & params = bv()->buffer()->params();
196 LyXFont font = getFont(pit, pos);
197 font.update(fnt, params.language, toggleall);
198 // Let the insets convert their font
199 if (pit->isInset(pos)) {
200 InsetOld * inset = pit->getInset(pos);
201 if (isEditableInset(inset)) {
202 static_cast<UpdatableInset *>(inset)
203 ->setFont(bv(), fnt, toggleall, true);
207 // Plug through to version below:
208 setCharFont(pit, pos, font);
212 void LyXText::setCharFont(
213 ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
216 LyXLayout_ptr const & layout = pit->layout();
218 // Get concrete layout font to reduce against
221 if (pos < pit->beginningOfBody())
222 layoutfont = layout->labelfont;
224 layoutfont = layout->font;
226 // Realize against environment font information
227 if (pit->getDepth()) {
228 ParagraphList::iterator tp = pit;
229 while (!layoutfont.resolved() &&
230 tp != ownerParagraphs().end() &&
232 tp = outerHook(tp, ownerParagraphs());
233 if (tp != ownerParagraphs().end())
234 layoutfont.realize(tp->layout()->font);
238 layoutfont.realize(defaultfont_);
240 // Now, reduce font against full layout font
241 font.reduce(layoutfont);
243 pit->setFont(pos, font);
247 InsetOld * LyXText::getInset() const
249 ParagraphList::iterator pit = cursor.par();
250 pos_type const pos = cursor.pos();
252 if (pos < pit->size() && pit->isInset(pos)) {
253 return pit->getInset(pos);
259 void LyXText::toggleInset()
261 InsetOld * inset = getInset();
262 // is there an editable inset at cursor position?
263 if (!isEditableInset(inset)) {
264 // No, try to see if we are inside a collapsable inset
265 if (inset_owner && inset_owner->owner()
266 && inset_owner->owner()->isOpen()) {
267 bv()->unlockInset(inset_owner->owner());
268 inset_owner->owner()->close(bv());
269 bv()->getLyXText()->cursorRight(bv());
273 //bv()->owner()->message(inset->editMessage());
275 // do we want to keep this?? (JMarc)
276 if (!isHighlyEditableInset(inset))
277 recordUndo(bv(), Undo::ATOMIC);
284 bv()->updateInset(inset);
288 /* used in setlayout */
289 // Asger is not sure we want to do this...
290 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
293 LyXLayout_ptr const & layout = par.layout();
294 pos_type const psize = par.size();
297 for (pos_type pos = 0; pos < psize; ++pos) {
298 if (pos < par.beginningOfBody())
299 layoutfont = layout->labelfont;
301 layoutfont = layout->font;
303 LyXFont tmpfont = par.getFontSettings(params, pos);
304 tmpfont.reduce(layoutfont);
305 par.setFont(pos, tmpfont);
310 ParagraphList::iterator
311 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
312 LyXCursor & send_cur,
313 string const & layout)
315 ParagraphList::iterator endpit = boost::next(send_cur.par());
316 ParagraphList::iterator undoendpit = endpit;
317 ParagraphList::iterator pars_end = ownerParagraphs().end();
319 if (endpit != pars_end && endpit->getDepth()) {
320 while (endpit != pars_end && endpit->getDepth()) {
324 } else if (endpit != pars_end) {
325 // because of parindents etc.
329 recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(undoendpit));
331 // ok we have a selection. This is always between sstart_cur
332 // and sel_end cursor
334 ParagraphList::iterator pit = sstart_cur.par();
335 ParagraphList::iterator epit = boost::next(send_cur.par());
337 BufferParams const & bufparams = bv()->buffer()->params();
338 LyXLayout_ptr const & lyxlayout =
339 bufparams.getLyXTextClass()[layout];
342 pit->applyLayout(lyxlayout);
343 makeFontEntriesLayoutSpecific(bufparams, *pit);
344 pit->params().spaceTop(lyxlayout->fill_top ?
345 VSpace(VSpace::VFILL)
346 : VSpace(VSpace::NONE));
347 pit->params().spaceBottom(lyxlayout->fill_bottom ?
348 VSpace(VSpace::VFILL)
349 : VSpace(VSpace::NONE));
350 if (lyxlayout->margintype == MARGIN_MANUAL)
351 pit->setLabelWidthString(lyxlayout->labelstring());
354 } while (pit != epit);
360 // set layout over selection and make a total rebreak of those paragraphs
361 void LyXText::setLayout(string const & layout)
363 LyXCursor tmpcursor = cursor; // store the current cursor
365 // if there is no selection just set the layout
366 // of the current paragraph
367 if (!selection.set()) {
368 selection.start = cursor; // dummy selection
369 selection.end = cursor;
372 // special handling of new environment insets
373 BufferParams const & params = bv()->buffer()->params();
374 LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
375 if (lyxlayout->is_environment) {
376 // move everything in a new environment inset
377 lyxerr << "setting layout " << layout << endl;
378 bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
379 bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
380 bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
381 InsetOld * inset = new InsetEnvironment(params, layout);
382 if (bv()->insertInset(inset)) {
384 //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
391 ParagraphList::iterator endpit = setLayout(cursor, selection.start,
392 selection.end, layout);
393 redoParagraphs(selection.start.par(), endpit);
395 // we have to reset the selection, because the
396 // geometry could have changed
397 setCursor(selection.start.par(), selection.start.pos(), false);
398 selection.cursor = cursor;
399 setCursor(selection.end.par(), selection.end.pos(), false);
403 setCursor(tmpcursor.par(), tmpcursor.pos(), true);
407 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
409 ParagraphList::iterator pit = cursor.par();
410 ParagraphList::iterator end = cursor.par();
411 ParagraphList::iterator start = pit;
413 if (selection.set()) {
414 pit = selection.start.par();
415 end = selection.end.par();
419 ParagraphList::iterator pastend = boost::next(end);
422 recordUndo(bv(), Undo::ATOMIC, start, end);
424 bool changed = false;
426 int prev_after_depth = 0;
427 #warning parlist ... could be nicer ?
428 if (start != ownerParagraphs().begin()) {
429 prev_after_depth = boost::prior(start)->getMaxDepthAfter();
433 int const depth = pit->params().depth();
434 if (type == bv_funcs::INC_DEPTH) {
435 if (depth < prev_after_depth
436 && pit->layout()->labeltype != LABEL_BIBLIO) {
439 pit->params().depth(depth + 1);
444 pit->params().depth(depth - 1);
447 prev_after_depth = pit->getMaxDepthAfter();
459 redoParagraphs(start, pastend);
461 // We need to actually move the text->cursor. I don't
462 // understand why ...
463 LyXCursor tmpcursor = cursor;
465 // we have to reset the visual selection because the
466 // geometry could have changed
467 if (selection.set()) {
468 setCursor(selection.start.par(), selection.start.pos());
469 selection.cursor = cursor;
470 setCursor(selection.end.par(), selection.end.pos());
473 // this handles the counter labels, and also fixes up
474 // depth values for follow-on (child) paragraphs
478 setCursor(tmpcursor.par(), tmpcursor.pos());
484 // set font over selection and make a total rebreak of those paragraphs
485 void LyXText::setFont(LyXFont const & font, bool toggleall)
487 // if there is no selection just set the current_font
488 if (!selection.set()) {
489 // Determine basis font
491 if (cursor.pos() < cursor.par()->beginningOfBody()) {
492 layoutfont = getLabelFont(cursor.par());
494 layoutfont = getLayoutFont(cursor.par());
496 // Update current font
497 real_current_font.update(font,
498 bv()->buffer()->params().language,
501 // Reduce to implicit settings
502 current_font = real_current_font;
503 current_font.reduce(layoutfont);
504 // And resolve it completely
505 real_current_font.realize(layoutfont);
510 LyXCursor tmpcursor = cursor; // store the current cursor
512 // ok we have a selection. This is always between sel_start_cursor
513 // and sel_end cursor
515 recordUndo(bv(), Undo::ATOMIC, selection.start.par(), selection.end.par());
517 cursor = selection.start;
518 while (cursor.par() != selection.end.par() ||
519 cursor.pos() < selection.end.pos())
521 if (cursor.pos() < cursor.par()->size()) {
522 // an open footnote should behave like a closed one
523 setCharFont(cursor.par(), cursor.pos(),
525 cursor.pos(cursor.pos() + 1);
528 cursor.par(boost::next(cursor.par()));
533 redoParagraph(selection.start.par());
535 // we have to reset the selection, because the
536 // geometry could have changed, but we keep
537 // it for user convenience
538 setCursor(selection.start.par(), selection.start.pos());
539 selection.cursor = cursor;
540 setCursor(selection.end.par(), selection.end.pos());
542 setCursor(tmpcursor.par(), tmpcursor.pos(), true,
543 tmpcursor.boundary());
547 int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
549 RowList::iterator rit = pit->rows.begin();
550 RowList::iterator end = pit->rows.end();
552 // remove rows of paragraph, keep track of height changes
553 for (int i = 0; rit != end; ++rit, ++i)
554 height -= rit->height();
558 InsetList::iterator ii = pit->insetlist.begin();
559 InsetList::iterator iend = pit->insetlist.end();
560 for (; ii != iend; ++ii) {
562 MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
563 ii->inset->metrics(mi, dim);
566 // rebreak the paragraph
567 for (pos_type z = 0; z < pit->size() + 1; ) {
569 z = rowBreakPoint(pit, row) + 1;
571 pit->rows.push_back(row);
575 // set height and fill and width of rows
576 int const ww = workWidth();
577 for (rit = pit->rows.begin(); rit != end; ++rit) {
578 int const f = fill(pit, rit, ww);
579 int const w = ww - f;
580 par_width = std::max(par_width, w);
583 prepareToPrint(pit, rit);
584 setHeightOfRow(pit, rit);
585 height += rit->height();
588 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
593 int LyXText::redoParagraphs(ParagraphList::iterator start,
594 ParagraphList::iterator end)
597 for ( ; start != end; ++start) {
598 int par_width = redoParagraphInternal(start);
599 pars_width = std::max(par_width, pars_width);
601 updateRowPositions();
606 void LyXText::redoParagraph(ParagraphList::iterator pit)
608 redoParagraphInternal(pit);
609 updateRowPositions();
613 void LyXText::fullRebreak()
615 redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
617 selection.cursor = cursor;
621 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
623 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
624 // << " workWidth: " << workWidth() << endl;
625 //Assert(mi.base.textwidth);
632 width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
635 dim.asc = firstRow()->ascent_of_text();
636 dim.des = height - dim.asc;
637 dim.wid = std::max(mi.base.textwidth, int(width));
641 // important for the screen
644 // the cursor set functions have a special mechanism. When they
645 // realize, that you left an empty paragraph, they will delete it.
646 // They also delete the corresponding row
648 // need the selection cursor:
649 void LyXText::setSelection()
651 TextCursor::setSelection();
656 void LyXText::clearSelection()
658 TextCursor::clearSelection();
660 // reset this in the bv_owner!
661 if (bv_owner && bv_owner->text)
662 bv_owner->text->xsel_cache.set(false);
666 void LyXText::cursorHome()
668 setCursor(cursor.par(), cursorRow()->pos());
672 void LyXText::cursorEnd()
674 setCursor(cursor.par(), cursorRow()->end() - 1);
678 void LyXText::cursorTop()
680 setCursor(ownerParagraphs().begin(), 0);
684 void LyXText::cursorBottom()
686 ParagraphList::iterator lastpit =
687 boost::prior(ownerParagraphs().end());
688 setCursor(lastpit, lastpit->size());
692 void LyXText::toggleFree(LyXFont const & font, bool toggleall)
694 // If the mask is completely neutral, tell user
695 if (font == LyXFont(LyXFont::ALL_IGNORE)) {
696 // Could only happen with user style
697 bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
701 // Try implicit word selection
702 // If there is a change in the language the implicit word selection
704 LyXCursor resetCursor = cursor;
705 bool implicitSelection = (font.language() == ignore_language
706 && font.number() == LyXFont::IGNORE)
707 ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
710 setFont(font, toggleall);
712 // Implicit selections are cleared afterwards
713 //and cursor is set to the original position.
714 if (implicitSelection) {
716 cursor = resetCursor;
717 setCursor(cursor.par(), cursor.pos());
718 selection.cursor = cursor;
723 string LyXText::getStringToIndex()
725 // Try implicit word selection
726 // If there is a change in the language the implicit word selection
728 LyXCursor const reset_cursor = cursor;
729 bool const implicitSelection =
730 selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
733 if (!selection.set())
734 bv()->owner()->message(_("Nothing to index!"));
735 else if (selection.start.par() != selection.end.par())
736 bv()->owner()->message(_("Cannot index more than one paragraph!"));
738 idxstring = selectionAsString(*bv()->buffer(), false);
740 // Reset cursors to their original position.
741 cursor = reset_cursor;
742 setCursor(cursor.par(), cursor.pos());
743 selection.cursor = cursor;
745 // Clear the implicit selection.
746 if (implicitSelection)
753 // the DTP switches for paragraphs. LyX will store them in the first
754 // physical paragraph. When a paragraph is broken, the top settings rest,
755 // the bottom settings are given to the new one. So I can make sure,
756 // they do not duplicate themself and you cannnot make dirty things with
759 void LyXText::setParagraph(bool line_top, bool line_bottom,
760 bool pagebreak_top, bool pagebreak_bottom,
761 VSpace const & space_top,
762 VSpace const & space_bottom,
763 Spacing const & spacing,
765 string const & labelwidthstring,
768 LyXCursor tmpcursor = cursor;
769 if (!selection.set()) {
770 selection.start = cursor;
771 selection.end = cursor;
774 // make sure that the depth behind the selection are restored, too
775 ParagraphList::iterator endpit = boost::next(selection.end.par());
776 ParagraphList::iterator undoendpit = endpit;
777 ParagraphList::iterator pars_end = ownerParagraphs().end();
779 if (endpit != pars_end && endpit->getDepth()) {
780 while (endpit != pars_end && endpit->getDepth()) {
784 } else if (endpit != pars_end) {
785 // because of parindents etc.
789 recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
790 boost::prior(undoendpit));
793 ParagraphList::iterator tmppit = selection.end.par();
795 while (tmppit != boost::prior(selection.start.par())) {
796 setCursor(tmppit, 0);
798 ParagraphList::iterator pit = cursor.par();
799 ParagraphParameters & params = pit->params();
801 params.lineTop(line_top);
802 params.lineBottom(line_bottom);
803 params.pagebreakTop(pagebreak_top);
804 params.pagebreakBottom(pagebreak_bottom);
805 params.spaceTop(space_top);
806 params.spaceBottom(space_bottom);
807 params.spacing(spacing);
808 // does the layout allow the new alignment?
809 LyXLayout_ptr const & layout = pit->layout();
811 if (align == LYX_ALIGN_LAYOUT)
812 align = layout->align;
813 if (align & layout->alignpossible) {
814 if (align == layout->align)
815 params.align(LYX_ALIGN_LAYOUT);
819 pit->setLabelWidthString(labelwidthstring);
820 params.noindent(noindent);
821 tmppit = boost::prior(pit);
824 redoParagraphs(selection.start.par(), endpit);
827 setCursor(selection.start.par(), selection.start.pos());
828 selection.cursor = cursor;
829 setCursor(selection.end.par(), selection.end.pos());
831 setCursor(tmpcursor.par(), tmpcursor.pos());
833 bv()->updateInset(inset_owner);
837 // set the counter of a paragraph. This includes the labels
838 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
840 BufferParams const & bufparams = buf.params();
841 LyXTextClass const & textclass = bufparams.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 <= bufparams.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(bufparams))
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 BufferParams const & bufparams = bv()->buffer()->params();
1129 boost::tie(endpit, endpos) = realcut ?
1130 CutAndPaste::cutSelection(bufparams,
1132 selection.start.par(), endpit,
1133 selection.start.pos(), endpos,
1134 bufparams.textclass,
1136 : CutAndPaste::eraseSelection(bufparams,
1138 selection.start.par(), endpit,
1139 selection.start.pos(), endpos,
1141 // sometimes necessary
1143 selection.start.par()->stripLeadingSpaces();
1145 redoParagraphs(selection.start.par(), boost::next(endpit));
1146 // cutSelection can invalidate the cursor so we need to set
1148 // we prefer the end for when tracking changes
1152 // need a valid cursor. (Lgb)
1155 setCursor(cursor.par(), cursor.pos());
1156 selection.cursor = cursor;
1161 void LyXText::copySelection()
1163 // stuff the selection onto the X clipboard, from an explicit copy request
1164 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1166 // this doesnt make sense, if there is no selection
1167 if (!selection.set())
1170 // ok we have a selection. This is always between selection.start
1171 // and sel_end cursor
1173 // copy behind a space if there is one
1174 while (selection.start.par()->size() > selection.start.pos()
1175 && selection.start.par()->isLineSeparator(selection.start.pos())
1176 && (selection.start.par() != selection.end.par()
1177 || selection.start.pos() < selection.end.pos()))
1178 selection.start.pos(selection.start.pos() + 1);
1180 CutAndPaste::copySelection(selection.start.par(),
1181 selection.end.par(),
1182 selection.start.pos(), selection.end.pos(),
1183 bv()->buffer()->params().textclass);
1187 void LyXText::pasteSelection(size_t sel_index)
1189 // this does not make sense, if there is nothing to paste
1190 if (!CutAndPaste::checkPastePossible())
1193 recordUndo(bv(), Undo::INSERT, cursor.par());
1195 ParagraphList::iterator endpit;
1200 boost::tie(ppp, endpit) =
1201 CutAndPaste::pasteSelection(*bv()->buffer(),
1203 cursor.par(), cursor.pos(),
1204 bv()->buffer()->params().textclass,
1206 bufferErrors(*bv()->buffer(), el);
1207 bv()->showErrorList(_("Paste"));
1209 redoParagraphs(cursor.par(), endpit);
1211 setCursor(cursor.par(), cursor.pos());
1214 selection.cursor = cursor;
1215 setCursor(ppp.first, ppp.second);
1221 void LyXText::setSelectionRange(lyx::pos_type length)
1226 selection.cursor = cursor;
1233 // simple replacing. The font of the first selected character is used
1234 void LyXText::replaceSelectionWithString(string const & str)
1236 recordUndo(bv(), Undo::ATOMIC);
1239 if (!selection.set()) { // create a dummy selection
1240 selection.end = cursor;
1241 selection.start = cursor;
1244 // Get font setting before we cut
1245 pos_type pos = selection.end.pos();
1246 LyXFont const font = selection.start.par()
1247 ->getFontSettings(bv()->buffer()->params(),
1248 selection.start.pos());
1250 // Insert the new string
1251 string::const_iterator cit = str.begin();
1252 string::const_iterator end = str.end();
1253 for (; cit != end; ++cit) {
1254 selection.end.par()->insertChar(pos, (*cit), font);
1258 // Cut the selection
1259 cutSelection(true, false);
1265 // needed to insert the selection
1266 void LyXText::insertStringAsLines(string const & str)
1268 ParagraphList::iterator pit = cursor.par();
1269 pos_type pos = cursor.pos();
1270 ParagraphList::iterator endpit = boost::next(cursor.par());
1272 recordUndo(bv(), Undo::ATOMIC);
1274 // only to be sure, should not be neccessary
1277 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1279 redoParagraphs(cursor.par(), endpit);
1280 setCursor(cursor.par(), cursor.pos());
1281 selection.cursor = cursor;
1282 setCursor(pit, pos);
1287 // turns double-CR to single CR, others where converted into one
1288 // blank. Then InsertStringAsLines is called
1289 void LyXText::insertStringAsParagraphs(string const & str)
1291 string linestr(str);
1292 bool newline_inserted = false;
1293 string::size_type const siz = linestr.length();
1295 for (string::size_type i = 0; i < siz; ++i) {
1296 if (linestr[i] == '\n') {
1297 if (newline_inserted) {
1298 // we know that \r will be ignored by
1299 // InsertStringA. Of course, it is a dirty
1300 // trick, but it works...
1301 linestr[i - 1] = '\r';
1305 newline_inserted = true;
1307 } else if (IsPrintable(linestr[i])) {
1308 newline_inserted = false;
1311 insertStringAsLines(linestr);
1315 bool LyXText::setCursor(ParagraphList::iterator pit,
1317 bool setfont, bool boundary)
1319 LyXCursor old_cursor = cursor;
1320 setCursorIntern(pit, pos, setfont, boundary);
1321 return deleteEmptyParagraphMechanism(old_cursor);
1325 void LyXText::redoCursor()
1327 #warning maybe the same for selections?
1328 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1332 void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
1333 pos_type pos, bool boundary)
1335 Assert(pit != ownerParagraphs().end());
1339 cur.boundary(boundary);
1343 // get the cursor y position in text
1345 RowList::iterator row = getRow(pit, pos);
1348 // y is now the beginning of the cursor row
1349 y += row->baseline();
1350 // y is now the cursor baseline
1353 pos_type last = lastPos(*pit, row);
1355 // None of these should happen, but we're scaredy-cats
1356 if (pos > pit->size()) {
1357 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1360 } else if (pos > last + 1) {
1361 lyxerr << "dont like 2 please report" << endl;
1362 // This shouldn't happen.
1365 } else if (pos < row->pos()) {
1366 lyxerr << "dont like 3 please report" << endl;
1371 // now get the cursors x position
1372 float x = getCursorX(pit, row, pos, last, boundary);
1378 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1379 pos_type pos, pos_type last, bool boundary) const
1381 pos_type cursor_vpos = 0;
1382 double x = rit->x();
1383 double fill_separator = rit->fill_separator();
1384 double fill_hfill = rit->fill_hfill();
1385 double fill_label_hfill = rit->fill_label_hfill();
1386 pos_type const rit_pos = rit->pos();
1389 cursor_vpos = rit_pos;
1390 else if (pos > last && !boundary)
1391 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
1392 ? rit_pos : last + 1;
1393 else if (pos > rit_pos && (pos > last || boundary))
1394 // Place cursor after char at (logical) position pos - 1
1395 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1396 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1398 // Place cursor before char at (logical) position pos
1399 cursor_vpos = (bidi_level(pos) % 2 == 0)
1400 ? log2vis(pos) : log2vis(pos) + 1;
1402 pos_type body_pos = pit->beginningOfBody();
1404 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1407 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1408 pos_type pos = vis2log(vpos);
1409 if (body_pos > 0 && pos == body_pos - 1) {
1410 x += fill_label_hfill +
1411 font_metrics::width(
1412 pit->layout()->labelsep, getLabelFont(pit));
1413 if (pit->isLineSeparator(body_pos - 1))
1414 x -= singleWidth(pit, body_pos - 1);
1417 if (hfillExpansion(*pit, rit, pos)) {
1418 x += singleWidth(pit, pos);
1419 if (pos >= body_pos)
1422 x += fill_label_hfill;
1423 } else if (pit->isSeparator(pos)) {
1424 x += singleWidth(pit, pos);
1425 if (pos >= body_pos)
1426 x += fill_separator;
1428 x += singleWidth(pit, pos);
1434 void LyXText::setCursorIntern(ParagraphList::iterator pit,
1435 pos_type pos, bool setfont, bool boundary)
1437 setCursor(cursor, pit, pos, boundary);
1443 void LyXText::setCurrentFont()
1445 pos_type pos = cursor.pos();
1446 ParagraphList::iterator pit = cursor.par();
1448 if (cursor.boundary() && pos > 0)
1452 if (pos == pit->size())
1454 else // potentional bug... BUG (Lgb)
1455 if (pit->isSeparator(pos)) {
1456 if (pos > cursorRow()->pos() &&
1457 bidi_level(pos) % 2 ==
1458 bidi_level(pos - 1) % 2)
1460 else if (pos + 1 < pit->size())
1465 BufferParams const & bufparams = bv()->buffer()->params();
1466 current_font = pit->getFontSettings(bufparams, pos);
1467 real_current_font = getFont(pit, pos);
1469 if (cursor.pos() == pit->size() &&
1470 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1471 !cursor.boundary()) {
1472 Language const * lang =
1473 pit->getParLanguage(bufparams);
1474 current_font.setLanguage(lang);
1475 current_font.setNumber(LyXFont::OFF);
1476 real_current_font.setLanguage(lang);
1477 real_current_font.setNumber(LyXFont::OFF);
1482 // returns the column near the specified x-coordinate of the row
1483 // x is set to the real beginning of this column
1484 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1485 RowList::iterator rit, int & x, bool & boundary) const
1487 double tmpx = rit->x();
1488 double fill_separator = rit->fill_separator();
1489 double fill_hfill = rit->fill_hfill();
1490 double fill_label_hfill = rit->fill_label_hfill();
1492 pos_type vc = rit->pos();
1493 pos_type last = lastPos(*pit, rit);
1495 LyXLayout_ptr const & layout = pit->layout();
1497 bool left_side = false;
1499 pos_type body_pos = pit->beginningOfBody();
1500 double last_tmpx = tmpx;
1503 (body_pos - 1 > last ||
1504 !pit->isLineSeparator(body_pos - 1)))
1507 // check for empty row
1513 while (vc <= last && tmpx <= x) {
1516 if (body_pos > 0 && c == body_pos - 1) {
1517 tmpx += fill_label_hfill +
1518 font_metrics::width(layout->labelsep, getLabelFont(pit));
1519 if (pit->isLineSeparator(body_pos - 1))
1520 tmpx -= singleWidth(pit, body_pos - 1);
1523 if (hfillExpansion(*pit, rit, c)) {
1524 tmpx += singleWidth(pit, c);
1528 tmpx += fill_label_hfill;
1529 } else if (pit->isSeparator(c)) {
1530 tmpx += singleWidth(pit, c);
1532 tmpx += fill_separator;
1534 tmpx += singleWidth(pit, c);
1539 if ((tmpx + last_tmpx) / 2 > x) {
1544 if (vc > last + 1) // This shouldn't happen.
1548 // This (rtl_support test) is not needed, but gives
1549 // some speedup if rtl_support == false
1550 bool const lastrow = lyxrc.rtl_support
1551 && boost::next(rit) == pit->rows.end();
1553 // If lastrow is false, we don't need to compute
1554 // the value of rtl.
1555 bool const rtl = (lastrow)
1556 ? pit->isRightToLeftPar(bv()->buffer()->params())
1559 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1560 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1562 else if (vc == rit->pos()) {
1564 if (bidi_level(c) % 2 == 1)
1567 c = vis2log(vc - 1);
1568 bool const rtl = (bidi_level(c) % 2 == 1);
1569 if (left_side == rtl) {
1571 boundary = isBoundary(*bv()->buffer(), *pit, c);
1575 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1576 if (bidi_level(last) % 2 == 0)
1577 tmpx -= singleWidth(pit, last);
1579 tmpx += singleWidth(pit, last);
1589 void LyXText::setCursorFromCoordinates(int x, int y)
1591 LyXCursor old_cursor = cursor;
1592 setCursorFromCoordinates(cursor, x, y);
1594 deleteEmptyParagraphMechanism(old_cursor);
1598 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1600 // Get the row first.
1601 ParagraphList::iterator pit;
1602 RowList::iterator rit = getRowNearY(y, pit);
1606 pos_type const column = getColumnNearX(pit, rit, x, bound);
1608 cur.pos(rit->pos() + column);
1610 cur.y(y + rit->baseline());
1612 cur.boundary(bound);
1616 void LyXText::cursorLeft(bool internal)
1618 if (cursor.pos() > 0) {
1619 bool boundary = cursor.boundary();
1620 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1621 if (!internal && !boundary &&
1622 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
1623 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1624 } else if (cursor.par() != ownerParagraphs().begin()) {
1625 // steps into the paragraph above
1626 ParagraphList::iterator pit = boost::prior(cursor.par());
1627 setCursor(pit, pit->size());
1632 void LyXText::cursorRight(bool internal)
1634 bool const at_end = (cursor.pos() == cursor.par()->size());
1635 bool const at_newline = !at_end &&
1636 cursor.par()->isNewline(cursor.pos());
1638 if (!internal && cursor.boundary() && !at_newline)
1639 setCursor(cursor.par(), cursor.pos(), true, false);
1641 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1643 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
1644 setCursor(cursor.par(), cursor.pos(), true, true);
1645 } else if (boost::next(cursor.par()) != ownerParagraphs().end())
1646 setCursor(boost::next(cursor.par()), 0);
1650 void LyXText::cursorUp(bool selecting)
1653 int x = cursor.x_fix();
1654 int y = cursor.y() - cursorRow()->baseline() - 1;
1655 setCursorFromCoordinates(x, y);
1657 int topy = bv_owner->top_y();
1658 int y1 = cursor.y() - topy;
1661 InsetOld * inset_hit = checkInsetHit(x, y1);
1662 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1663 inset_hit->localDispatch(
1664 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1668 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1669 cursorRow()->baseline() << endl;
1670 setCursorFromCoordinates(cursor.x_fix(),
1671 cursor.y() - cursorRow()->baseline() - 1);
1676 void LyXText::cursorDown(bool selecting)
1679 int x = cursor.x_fix();
1680 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1681 setCursorFromCoordinates(x, y);
1682 if (!selecting && cursorRow() == cursorIRow()) {
1683 int topy = bv_owner->top_y();
1684 int y1 = cursor.y() - topy;
1687 InsetOld * inset_hit = checkInsetHit(x, y1);
1688 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1689 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1690 inset_hit->localDispatch(cmd);
1694 setCursorFromCoordinates(cursor.x_fix(),
1695 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1700 void LyXText::cursorUpParagraph()
1702 if (cursor.pos() > 0)
1703 setCursor(cursor.par(), 0);
1704 else if (cursor.par() != ownerParagraphs().begin())
1705 setCursor(boost::prior(cursor.par()), 0);
1709 void LyXText::cursorDownParagraph()
1711 ParagraphList::iterator par = cursor.par();
1712 ParagraphList::iterator next_par = boost::next(par);
1714 if (next_par != ownerParagraphs().end())
1715 setCursor(next_par, 0);
1717 setCursor(par, par->size());
1721 // fix the cursor `cur' after a characters has been deleted at `where'
1722 // position. Called by deleteEmptyParagraphMechanism
1723 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1725 // if cursor is not in the paragraph where the delete occured,
1727 if (cur.par() != where.par())
1730 // if cursor position is after the place where the delete occured,
1732 if (cur.pos() > where.pos())
1733 cur.pos(cur.pos()-1);
1735 // check also if we don't want to set the cursor on a spot behind the
1736 // pagragraph because we erased the last character.
1737 if (cur.pos() > cur.par()->size())
1738 cur.pos(cur.par()->size());
1740 // recompute row et al. for this cursor
1741 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1745 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1747 // Would be wrong to delete anything if we have a selection.
1748 if (selection.set())
1751 // We allow all kinds of "mumbo-jumbo" when freespacing.
1752 if (old_cursor.par()->isFreeSpacing())
1755 /* Ok I'll put some comments here about what is missing.
1756 I have fixed BackSpace (and thus Delete) to not delete
1757 double-spaces automagically. I have also changed Cut,
1758 Copy and Paste to hopefully do some sensible things.
1759 There are still some small problems that can lead to
1760 double spaces stored in the document file or space at
1761 the beginning of paragraphs. This happens if you have
1762 the cursor between to spaces and then save. Or if you
1763 cut and paste and the selection have a space at the
1764 beginning and then save right after the paste. I am
1765 sure none of these are very hard to fix, but I will
1766 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1767 that I can get some feedback. (Lgb)
1770 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1771 // delete the LineSeparator.
1774 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1775 // delete the LineSeparator.
1778 // If the pos around the old_cursor were spaces, delete one of them.
1779 if (old_cursor.par() != cursor.par()
1780 || old_cursor.pos() != cursor.pos()) {
1782 // Only if the cursor has really moved
1783 if (old_cursor.pos() > 0
1784 && old_cursor.pos() < old_cursor.par()->size()
1785 && old_cursor.par()->isLineSeparator(old_cursor.pos())
1786 && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
1787 bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
1788 redoParagraph(old_cursor.par());
1792 #ifdef WITH_WARNINGS
1793 #warning This will not work anymore when we have multiple views of the same buffer
1794 // In this case, we will have to correct also the cursors held by
1795 // other bufferviews. It will probably be easier to do that in a more
1796 // automated way in LyXCursor code. (JMarc 26/09/2001)
1798 // correct all cursors held by the LyXText
1799 fixCursorAfterDelete(cursor, old_cursor);
1800 fixCursorAfterDelete(selection.cursor, old_cursor);
1801 fixCursorAfterDelete(selection.start, old_cursor);
1802 fixCursorAfterDelete(selection.end, old_cursor);
1807 // don't delete anything if this is the ONLY paragraph!
1808 if (ownerParagraphs().size() == 1)
1811 // Do not delete empty paragraphs with keepempty set.
1812 if (old_cursor.par()->allowEmpty())
1815 // only do our magic if we changed paragraph
1816 if (old_cursor.par() == cursor.par())
1819 // record if we have deleted a paragraph
1820 // we can't possibly have deleted a paragraph before this point
1821 bool deleted = false;
1823 if (old_cursor.par()->empty() ||
1824 (old_cursor.par()->size() == 1 &&
1825 old_cursor.par()->isLineSeparator(0))) {
1826 // ok, we will delete something
1827 LyXCursor tmpcursor;
1831 bool selection_position_was_oldcursor_position = (
1832 selection.cursor.par() == old_cursor.par()
1833 && selection.cursor.pos() == old_cursor.pos());
1836 cursor = old_cursor; // that undo can restore the right cursor position
1838 ParagraphList::iterator endpit = boost::next(old_cursor.par());
1839 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1842 recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
1846 ownerParagraphs().erase(old_cursor.par());
1850 setCursorIntern(cursor.par(), cursor.pos());
1852 if (selection_position_was_oldcursor_position) {
1853 // correct selection
1854 selection.cursor = cursor;
1858 if (old_cursor.par()->stripLeadingSpaces()) {
1859 redoParagraph(old_cursor.par());
1861 setCursorIntern(cursor.par(), cursor.pos());
1862 selection.cursor = cursor;
1869 ParagraphList & LyXText::ownerParagraphs() const
1875 bool LyXText::isInInset() const
1877 // Sub-level has non-null bv owner and non-null inset owner.
1878 return inset_owner != 0;
1882 int defaultRowHeight()
1884 LyXFont const font(LyXFont::ALL_SANE);
1885 return int(font_metrics::maxAscent(font)
1886 + font_metrics::maxDescent(font) * 1.5);