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"
46 #include "frontends/font_metrics.h"
47 #include "frontends/LyXView.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/lstrings.h"
56 #include "support/textutils.h"
58 #include <boost/tuple/tuple.hpp>
60 #include "support/std_sstream.h"
62 using namespace lyx::support;
66 using std::ostringstream;
71 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
72 ParagraphList & paragraphs)
73 : height(0), width(0), anchor_y_(0),
74 inset_owner(inset), the_locking_inset(0), bv_owner(bv),
75 in_inset_(ininset), paragraphs_(paragraphs)
80 void LyXText::init(BufferView * bview)
84 ParagraphList::iterator const beg = ownerParagraphs().begin();
85 ParagraphList::iterator const end = ownerParagraphs().end();
86 for (ParagraphList::iterator pit = beg; pit != end; ++pit)
94 current_font = getFont(beg, 0);
96 redoParagraphs(beg, end);
97 setCursorIntern(beg, 0);
98 selection.cursor = cursor;
104 // Gets the fully instantiated font at a given position in a paragraph
105 // Basically the same routine as Paragraph::getFont() in paragraph.C.
106 // The difference is that this one is used for displaying, and thus we
107 // are allowed to make cosmetic improvements. For instance make footnotes
109 LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
113 LyXLayout_ptr const & layout = pit->layout();
115 BufferParams const & params = bv()->buffer()->params();
117 // We specialize the 95% common case:
118 if (!pit->getDepth()) {
119 if (layout->labeltype == LABEL_MANUAL
120 && pos < pit->beginningOfBody()) {
122 LyXFont f = pit->getFontSettings(params, pos);
124 pit->inInset()->getDrawFont(f);
125 return f.realize(layout->reslabelfont);
127 LyXFont f = pit->getFontSettings(params, pos);
129 pit->inInset()->getDrawFont(f);
130 return f.realize(layout->resfont);
134 // The uncommon case need not be optimized as much
138 if (pos < pit->beginningOfBody()) {
140 layoutfont = layout->labelfont;
143 layoutfont = layout->font;
146 LyXFont tmpfont = pit->getFontSettings(params, pos);
147 tmpfont.realize(layoutfont);
150 pit->inInset()->getDrawFont(tmpfont);
152 // Realize with the fonts of lesser depth.
153 tmpfont.realize(outerFont(pit, ownerParagraphs()));
154 tmpfont.realize(defaultfont_);
160 LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const
162 LyXLayout_ptr const & layout = pit->layout();
164 if (!pit->getDepth())
165 return layout->resfont;
167 LyXFont font = layout->font;
168 // Realize with the fonts of lesser depth.
169 font.realize(outerFont(pit, ownerParagraphs()));
170 font.realize(defaultfont_);
176 LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
178 LyXLayout_ptr const & layout = pit->layout();
180 if (!pit->getDepth())
181 return layout->reslabelfont;
183 LyXFont font = layout->labelfont;
184 // Realize with the fonts of lesser depth.
185 font.realize(outerFont(pit, ownerParagraphs()));
186 font.realize(defaultfont_);
192 void LyXText::setCharFont(ParagraphList::iterator pit,
193 pos_type pos, LyXFont const & fnt,
196 BufferParams const & params = bv()->buffer()->params();
197 LyXFont font = getFont(pit, pos);
198 font.update(fnt, params.language, toggleall);
199 // Let the insets convert their font
200 if (pit->isInset(pos)) {
201 InsetOld * inset = pit->getInset(pos);
202 if (isEditableInset(inset)) {
203 static_cast<UpdatableInset *>(inset)
204 ->setFont(bv(), fnt, toggleall, true);
208 // Plug through to version below:
209 setCharFont(pit, pos, font);
213 void LyXText::setCharFont(
214 ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
217 LyXLayout_ptr const & layout = pit->layout();
219 // Get concrete layout font to reduce against
222 if (pos < pit->beginningOfBody())
223 layoutfont = layout->labelfont;
225 layoutfont = layout->font;
227 // Realize against environment font information
228 if (pit->getDepth()) {
229 ParagraphList::iterator tp = pit;
230 while (!layoutfont.resolved() &&
231 tp != ownerParagraphs().end() &&
233 tp = outerHook(tp, ownerParagraphs());
234 if (tp != ownerParagraphs().end())
235 layoutfont.realize(tp->layout()->font);
239 layoutfont.realize(defaultfont_);
241 // Now, reduce font against full layout font
242 font.reduce(layoutfont);
244 pit->setFont(pos, font);
248 InsetOld * LyXText::getInset() const
250 ParagraphList::iterator pit = cursor.par();
251 pos_type const pos = cursor.pos();
253 if (pos < pit->size() && pit->isInset(pos)) {
254 return pit->getInset(pos);
260 void LyXText::toggleInset()
262 InsetOld * inset = getInset();
263 // is there an editable inset at cursor position?
264 if (!isEditableInset(inset)) {
265 // No, try to see if we are inside a collapsable inset
266 if (inset_owner && inset_owner->owner()
267 && inset_owner->owner()->isOpen()) {
268 bv()->unlockInset(inset_owner->owner());
269 inset_owner->owner()->close(bv());
270 bv()->getLyXText()->cursorRight(bv());
274 //bv()->owner()->message(inset->editMessage());
276 // do we want to keep this?? (JMarc)
277 if (!isHighlyEditableInset(inset))
278 recordUndo(bv(), Undo::ATOMIC);
285 bv()->updateInset(inset);
289 /* used in setlayout */
290 // Asger is not sure we want to do this...
291 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
294 LyXLayout_ptr const & layout = par.layout();
295 pos_type const psize = par.size();
298 for (pos_type pos = 0; pos < psize; ++pos) {
299 if (pos < par.beginningOfBody())
300 layoutfont = layout->labelfont;
302 layoutfont = layout->font;
304 LyXFont tmpfont = par.getFontSettings(params, pos);
305 tmpfont.reduce(layoutfont);
306 par.setFont(pos, tmpfont);
311 ParagraphList::iterator
312 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
313 LyXCursor & send_cur,
314 string const & layout)
316 ParagraphList::iterator endpit = boost::next(send_cur.par());
317 ParagraphList::iterator undoendpit = endpit;
318 ParagraphList::iterator pars_end = ownerParagraphs().end();
320 if (endpit != pars_end && endpit->getDepth()) {
321 while (endpit != pars_end && endpit->getDepth()) {
325 } else if (endpit != pars_end) {
326 // because of parindents etc.
330 recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(undoendpit));
332 // ok we have a selection. This is always between sstart_cur
333 // and sel_end cursor
335 ParagraphList::iterator pit = sstart_cur.par();
336 ParagraphList::iterator epit = boost::next(send_cur.par());
338 BufferParams const & bufparams = bv()->buffer()->params();
339 LyXLayout_ptr const & lyxlayout =
340 bufparams.getLyXTextClass()[layout];
343 pit->applyLayout(lyxlayout);
344 makeFontEntriesLayoutSpecific(bufparams, *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 BufferParams const & bufparams = buf.params();
842 LyXTextClass const & textclass = bufparams.getLyXTextClass();
843 LyXLayout_ptr const & layout = pit->layout();
845 if (pit != ownerParagraphs().begin()) {
847 pit->params().appendix(boost::prior(pit)->params().appendix());
848 if (!pit->params().appendix() &&
849 pit->params().startOfAppendix()) {
850 pit->params().appendix(true);
851 textclass.counters().reset();
853 pit->enumdepth = boost::prior(pit)->enumdepth;
854 pit->itemdepth = boost::prior(pit)->itemdepth;
856 pit->params().appendix(pit->params().startOfAppendix());
861 // Maybe we have to increment the enumeration depth.
862 // BUT, enumeration in a footnote is considered in isolation from its
863 // surrounding paragraph so don't increment if this is the
864 // first line of the footnote
865 // AND, bibliographies can't have their depth changed ie. they
866 // are always of depth 0
867 if (pit != ownerParagraphs().begin()
868 && boost::prior(pit)->getDepth() < pit->getDepth()
869 && boost::prior(pit)->layout()->labeltype == LABEL_COUNTER_ENUMI
870 && pit->enumdepth < 3
871 && layout->labeltype != LABEL_BIBLIO) {
875 // Maybe we have to decrement the enumeration depth, see note above
876 if (pit != ownerParagraphs().begin()
877 && boost::prior(pit)->getDepth() > pit->getDepth()
878 && layout->labeltype != LABEL_BIBLIO) {
879 pit->enumdepth = depthHook(pit, ownerParagraphs(),
880 pit->getDepth())->enumdepth;
883 if (!pit->params().labelString().empty()) {
884 pit->params().labelString(string());
887 if (layout->margintype == MARGIN_MANUAL) {
888 if (pit->params().labelWidthString().empty())
889 pit->setLabelWidthString(layout->labelstring());
891 pit->setLabelWidthString(string());
894 // is it a layout that has an automatic label?
895 if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
896 int const i = layout->labeltype - LABEL_COUNTER_CHAPTER;
900 if (i >= 0 && i <= bufparams.secnumdepth) {
904 textclass.counters().step(layout->latexname());
906 // Is there a label? Useful for Chapter layout
907 if (!pit->params().appendix()) {
908 s << buf.B_(layout->labelstring());
910 s << buf.B_(layout->labelstring_appendix());
913 // Use of an integer is here less than elegant. For now.
914 int head = textclass.maxcounter() - LABEL_COUNTER_CHAPTER;
915 if (!pit->params().appendix()) {
916 numbertype = "sectioning";
918 numbertype = "appendix";
919 if (pit->isRightToLeftPar(bufparams))
926 << textclass.counters()
927 .numberLabel(layout->latexname(),
928 numbertype, langtype, head);
930 pit->params().labelString(STRCONV(s.str()));
932 // reset enum counters
933 textclass.counters().reset("enum");
934 } else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
935 textclass.counters().reset("enum");
936 } else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
938 // Yes I know this is a really, really! bad solution
940 string enumcounter("enum");
942 switch (pit->enumdepth) {
954 // not a valid enumdepth...
958 textclass.counters().step(enumcounter);
960 s << textclass.counters()
961 .numberLabel(enumcounter, "enumeration");
962 pit->params().labelString(STRCONV(s.str()));
964 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
965 textclass.counters().step("bibitem");
966 int number = textclass.counters().value("bibitem");
967 if (pit->bibitem()) {
968 pit->bibitem()->setCounter(number);
969 pit->params().labelString(layout->labelstring());
971 // In biblio should't be following counters but...
973 string s = buf.B_(layout->labelstring());
976 if (layout->labeltype == LABEL_SENSITIVE) {
977 ParagraphList::iterator end = ownerParagraphs().end();
978 ParagraphList::iterator tmppit = pit;
981 while (tmppit != end && tmppit->inInset()
982 // the single '=' is intended below
983 && (in = tmppit->inInset()->owner()))
985 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
986 in->lyxCode() == InsetOld::WRAP_CODE) {
990 Paragraph const * owner = &ownerPar(buf, in);
991 tmppit = ownerParagraphs().begin();
992 for ( ; tmppit != end; ++tmppit)
993 if (&*tmppit == owner)
1001 if (in->lyxCode() == InsetOld::FLOAT_CODE)
1002 type = static_cast<InsetFloat*>(in)->params().type;
1003 else if (in->lyxCode() == InsetOld::WRAP_CODE)
1004 type = static_cast<InsetWrap*>(in)->params().type;
1008 Floating const & fl = textclass.floats().getType(type);
1010 textclass.counters().step(fl.type());
1012 // Doesn't work... yet.
1013 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1015 // par->SetLayout(0);
1016 // s = layout->labelstring;
1017 s = _("Senseless: ");
1020 pit->params().labelString(s);
1022 // reset the enumeration counter. They are always reset
1023 // when there is any other layout between
1024 // Just fall-through between the cases so that all
1025 // enum counters deeper than enumdepth is also reset.
1026 switch (pit->enumdepth) {
1028 textclass.counters().reset("enumi");
1030 textclass.counters().reset("enumii");
1032 textclass.counters().reset("enumiii");
1034 textclass.counters().reset("enumiv");
1040 // Updates all counters. Paragraphs with changed label string will be rebroken
1041 void LyXText::updateCounters()
1044 bv()->buffer()->params().getLyXTextClass().counters().reset();
1046 ParagraphList::iterator beg = ownerParagraphs().begin();
1047 ParagraphList::iterator end = ownerParagraphs().end();
1048 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1049 string const oldLabel = pit->params().labelString();
1051 size_t maxdepth = 0;
1053 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1055 if (pit->params().depth() > maxdepth)
1056 pit->params().depth(maxdepth);
1058 // setCounter can potentially change the labelString.
1059 setCounter(*bv()->buffer(), pit);
1061 string const & newLabel = pit->params().labelString();
1063 if (oldLabel != newLabel)
1069 void LyXText::insertInset(InsetOld * inset)
1071 if (!cursor.par()->insetAllowed(inset->lyxCode()))
1073 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1075 cursor.par()->insertInset(cursor.pos(), inset);
1076 // Just to rebreak and refresh correctly.
1077 // The character will not be inserted a second time
1078 insertChar(Paragraph::META_INSET);
1079 // If we enter a highly editable inset the cursor should be before
1080 // the inset. After an Undo LyX tries to call inset->edit(...)
1081 // and fails if the cursor is behind the inset and getInset
1082 // does not return the inset!
1083 if (isHighlyEditableInset(inset))
1089 void LyXText::cutSelection(bool doclear, bool realcut)
1091 // Stuff what we got on the clipboard. Even if there is no selection.
1093 // There is a problem with having the stuffing here in that the
1094 // larger the selection the slower LyX will get. This can be
1095 // solved by running the line below only when the selection has
1096 // finished. The solution used currently just works, to make it
1097 // faster we need to be more clever and probably also have more
1098 // calls to stuffClipboard. (Lgb)
1099 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1101 // This doesn't make sense, if there is no selection
1102 if (!selection.set())
1105 // OK, we have a selection. This is always between selection.start
1106 // and selection.end
1108 // make sure that the depth behind the selection are restored, too
1109 ParagraphList::iterator endpit = boost::next(selection.end.par());
1110 ParagraphList::iterator undoendpit = endpit;
1111 ParagraphList::iterator pars_end = ownerParagraphs().end();
1113 if (endpit != pars_end && endpit->getDepth()) {
1114 while (endpit != pars_end && endpit->getDepth()) {
1116 undoendpit = endpit;
1118 } else if (endpit != pars_end) {
1119 // because of parindents etc.
1123 recordUndo(bv(), Undo::DELETE, selection.start.par(),
1124 boost::prior(undoendpit));
1126 endpit = selection.end.par();
1127 int endpos = selection.end.pos();
1129 BufferParams const & bufparams = bv()->buffer()->params();
1130 boost::tie(endpit, endpos) = realcut ?
1131 CutAndPaste::cutSelection(bufparams,
1133 selection.start.par(), endpit,
1134 selection.start.pos(), endpos,
1135 bufparams.textclass,
1137 : CutAndPaste::eraseSelection(bufparams,
1139 selection.start.par(), endpit,
1140 selection.start.pos(), endpos,
1142 // sometimes necessary
1144 selection.start.par()->stripLeadingSpaces();
1146 redoParagraphs(selection.start.par(), boost::next(endpit));
1147 // cutSelection can invalidate the cursor so we need to set
1149 // we prefer the end for when tracking changes
1153 // need a valid cursor. (Lgb)
1156 setCursor(cursor.par(), cursor.pos());
1157 selection.cursor = cursor;
1162 void LyXText::copySelection()
1164 // stuff the selection onto the X clipboard, from an explicit copy request
1165 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1167 // this doesnt make sense, if there is no selection
1168 if (!selection.set())
1171 // ok we have a selection. This is always between selection.start
1172 // and sel_end cursor
1174 // copy behind a space if there is one
1175 while (selection.start.par()->size() > selection.start.pos()
1176 && selection.start.par()->isLineSeparator(selection.start.pos())
1177 && (selection.start.par() != selection.end.par()
1178 || selection.start.pos() < selection.end.pos()))
1179 selection.start.pos(selection.start.pos() + 1);
1181 CutAndPaste::copySelection(selection.start.par(),
1182 selection.end.par(),
1183 selection.start.pos(), selection.end.pos(),
1184 bv()->buffer()->params().textclass);
1188 void LyXText::pasteSelection(size_t sel_index)
1190 // this does not make sense, if there is nothing to paste
1191 if (!CutAndPaste::checkPastePossible())
1194 recordUndo(bv(), Undo::INSERT, cursor.par());
1196 ParagraphList::iterator endpit;
1201 boost::tie(ppp, endpit) =
1202 CutAndPaste::pasteSelection(*bv()->buffer(),
1204 cursor.par(), cursor.pos(),
1205 bv()->buffer()->params().textclass,
1207 bufferErrors(*bv()->buffer(), el);
1208 bv()->showErrorList(_("Paste"));
1210 redoParagraphs(cursor.par(), endpit);
1212 setCursor(cursor.par(), cursor.pos());
1215 selection.cursor = cursor;
1216 setCursor(ppp.first, ppp.second);
1222 void LyXText::setSelectionRange(lyx::pos_type length)
1227 selection.cursor = cursor;
1234 // simple replacing. The font of the first selected character is used
1235 void LyXText::replaceSelectionWithString(string const & str)
1237 recordUndo(bv(), Undo::ATOMIC);
1240 if (!selection.set()) { // create a dummy selection
1241 selection.end = cursor;
1242 selection.start = cursor;
1245 // Get font setting before we cut
1246 pos_type pos = selection.end.pos();
1247 LyXFont const font = selection.start.par()
1248 ->getFontSettings(bv()->buffer()->params(),
1249 selection.start.pos());
1251 // Insert the new string
1252 string::const_iterator cit = str.begin();
1253 string::const_iterator end = str.end();
1254 for (; cit != end; ++cit) {
1255 selection.end.par()->insertChar(pos, (*cit), font);
1259 // Cut the selection
1260 cutSelection(true, false);
1266 // needed to insert the selection
1267 void LyXText::insertStringAsLines(string const & str)
1269 ParagraphList::iterator pit = cursor.par();
1270 pos_type pos = cursor.pos();
1271 ParagraphList::iterator endpit = boost::next(cursor.par());
1273 recordUndo(bv(), Undo::ATOMIC);
1275 // only to be sure, should not be neccessary
1278 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1280 redoParagraphs(cursor.par(), endpit);
1281 setCursor(cursor.par(), cursor.pos());
1282 selection.cursor = cursor;
1283 setCursor(pit, pos);
1288 // turns double-CR to single CR, others where converted into one
1289 // blank. Then InsertStringAsLines is called
1290 void LyXText::insertStringAsParagraphs(string const & str)
1292 string linestr(str);
1293 bool newline_inserted = false;
1294 string::size_type const siz = linestr.length();
1296 for (string::size_type i = 0; i < siz; ++i) {
1297 if (linestr[i] == '\n') {
1298 if (newline_inserted) {
1299 // we know that \r will be ignored by
1300 // InsertStringA. Of course, it is a dirty
1301 // trick, but it works...
1302 linestr[i - 1] = '\r';
1306 newline_inserted = true;
1308 } else if (IsPrintable(linestr[i])) {
1309 newline_inserted = false;
1312 insertStringAsLines(linestr);
1316 bool LyXText::setCursor(ParagraphList::iterator pit,
1318 bool setfont, bool boundary)
1320 LyXCursor old_cursor = cursor;
1321 setCursorIntern(pit, pos, setfont, boundary);
1322 return deleteEmptyParagraphMechanism(old_cursor);
1326 void LyXText::redoCursor()
1328 #warning maybe the same for selections?
1329 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1333 void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
1334 pos_type pos, bool boundary)
1336 Assert(pit != ownerParagraphs().end());
1340 cur.boundary(boundary);
1344 // get the cursor y position in text
1346 RowList::iterator row = getRow(pit, pos);
1349 // y is now the beginning of the cursor row
1350 y += row->baseline();
1351 // y is now the cursor baseline
1354 pos_type last = lastPos(*pit, row);
1356 // None of these should happen, but we're scaredy-cats
1357 if (pos > pit->size()) {
1358 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1361 } else if (pos > last + 1) {
1362 lyxerr << "dont like 2 please report" << endl;
1363 // This shouldn't happen.
1366 } else if (pos < row->pos()) {
1367 lyxerr << "dont like 3 please report" << endl;
1372 // now get the cursors x position
1373 float x = getCursorX(pit, row, pos, last, boundary);
1379 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1380 pos_type pos, pos_type last, bool boundary) const
1382 pos_type cursor_vpos = 0;
1383 double x = rit->x();
1384 double fill_separator = rit->fill_separator();
1385 double fill_hfill = rit->fill_hfill();
1386 double fill_label_hfill = rit->fill_label_hfill();
1387 pos_type const rit_pos = rit->pos();
1390 cursor_vpos = rit_pos;
1391 else if (pos > last && !boundary)
1392 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
1393 ? rit_pos : last + 1;
1394 else if (pos > rit_pos && (pos > last || boundary))
1395 // Place cursor after char at (logical) position pos - 1
1396 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1397 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1399 // Place cursor before char at (logical) position pos
1400 cursor_vpos = (bidi_level(pos) % 2 == 0)
1401 ? log2vis(pos) : log2vis(pos) + 1;
1403 pos_type body_pos = pit->beginningOfBody();
1405 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1408 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1409 pos_type pos = vis2log(vpos);
1410 if (body_pos > 0 && pos == body_pos - 1) {
1411 x += fill_label_hfill +
1412 font_metrics::width(
1413 pit->layout()->labelsep, getLabelFont(pit));
1414 if (pit->isLineSeparator(body_pos - 1))
1415 x -= singleWidth(pit, body_pos - 1);
1418 if (hfillExpansion(*pit, rit, pos)) {
1419 x += singleWidth(pit, pos);
1420 if (pos >= body_pos)
1423 x += fill_label_hfill;
1424 } else if (pit->isSeparator(pos)) {
1425 x += singleWidth(pit, pos);
1426 if (pos >= body_pos)
1427 x += fill_separator;
1429 x += singleWidth(pit, pos);
1435 void LyXText::setCursorIntern(ParagraphList::iterator pit,
1436 pos_type pos, bool setfont, bool boundary)
1438 setCursor(cursor, pit, pos, boundary);
1444 void LyXText::setCurrentFont()
1446 pos_type pos = cursor.pos();
1447 ParagraphList::iterator pit = cursor.par();
1449 if (cursor.boundary() && pos > 0)
1453 if (pos == pit->size())
1455 else // potentional bug... BUG (Lgb)
1456 if (pit->isSeparator(pos)) {
1457 if (pos > cursorRow()->pos() &&
1458 bidi_level(pos) % 2 ==
1459 bidi_level(pos - 1) % 2)
1461 else if (pos + 1 < pit->size())
1466 BufferParams const & bufparams = bv()->buffer()->params();
1467 current_font = pit->getFontSettings(bufparams, pos);
1468 real_current_font = getFont(pit, pos);
1470 if (cursor.pos() == pit->size() &&
1471 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1472 !cursor.boundary()) {
1473 Language const * lang =
1474 pit->getParLanguage(bufparams);
1475 current_font.setLanguage(lang);
1476 current_font.setNumber(LyXFont::OFF);
1477 real_current_font.setLanguage(lang);
1478 real_current_font.setNumber(LyXFont::OFF);
1483 // returns the column near the specified x-coordinate of the row
1484 // x is set to the real beginning of this column
1485 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1486 RowList::iterator rit, int & x, bool & boundary) const
1488 double tmpx = rit->x();
1489 double fill_separator = rit->fill_separator();
1490 double fill_hfill = rit->fill_hfill();
1491 double fill_label_hfill = rit->fill_label_hfill();
1493 pos_type vc = rit->pos();
1494 pos_type last = lastPos(*pit, rit);
1496 LyXLayout_ptr const & layout = pit->layout();
1498 bool left_side = false;
1500 pos_type body_pos = pit->beginningOfBody();
1501 double last_tmpx = tmpx;
1504 (body_pos - 1 > last ||
1505 !pit->isLineSeparator(body_pos - 1)))
1508 // check for empty row
1514 while (vc <= last && tmpx <= x) {
1517 if (body_pos > 0 && c == body_pos - 1) {
1518 tmpx += fill_label_hfill +
1519 font_metrics::width(layout->labelsep, getLabelFont(pit));
1520 if (pit->isLineSeparator(body_pos - 1))
1521 tmpx -= singleWidth(pit, body_pos - 1);
1524 if (hfillExpansion(*pit, rit, c)) {
1525 tmpx += singleWidth(pit, c);
1529 tmpx += fill_label_hfill;
1530 } else if (pit->isSeparator(c)) {
1531 tmpx += singleWidth(pit, c);
1533 tmpx += fill_separator;
1535 tmpx += singleWidth(pit, c);
1540 if ((tmpx + last_tmpx) / 2 > x) {
1545 if (vc > last + 1) // This shouldn't happen.
1549 // This (rtl_support test) is not needed, but gives
1550 // some speedup if rtl_support == false
1551 bool const lastrow = lyxrc.rtl_support
1552 && boost::next(rit) == pit->rows.end();
1554 // If lastrow is false, we don't need to compute
1555 // the value of rtl.
1556 bool const rtl = (lastrow)
1557 ? pit->isRightToLeftPar(bv()->buffer()->params())
1560 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1561 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1563 else if (vc == rit->pos()) {
1565 if (bidi_level(c) % 2 == 1)
1568 c = vis2log(vc - 1);
1569 bool const rtl = (bidi_level(c) % 2 == 1);
1570 if (left_side == rtl) {
1572 boundary = isBoundary(*bv()->buffer(), *pit, c);
1576 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1577 if (bidi_level(last) % 2 == 0)
1578 tmpx -= singleWidth(pit, last);
1580 tmpx += singleWidth(pit, last);
1590 void LyXText::setCursorFromCoordinates(int x, int y)
1592 LyXCursor old_cursor = cursor;
1593 setCursorFromCoordinates(cursor, x, y);
1595 deleteEmptyParagraphMechanism(old_cursor);
1599 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1601 // Get the row first.
1602 ParagraphList::iterator pit;
1603 RowList::iterator rit = getRowNearY(y, pit);
1607 pos_type const column = getColumnNearX(pit, rit, x, bound);
1609 cur.pos(rit->pos() + column);
1611 cur.y(y + rit->baseline());
1613 cur.boundary(bound);
1617 void LyXText::cursorLeft(bool internal)
1619 if (cursor.pos() > 0) {
1620 bool boundary = cursor.boundary();
1621 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1622 if (!internal && !boundary &&
1623 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
1624 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1625 } else if (cursor.par() != ownerParagraphs().begin()) {
1626 // steps into the paragraph above
1627 ParagraphList::iterator pit = boost::prior(cursor.par());
1628 setCursor(pit, pit->size());
1633 void LyXText::cursorRight(bool internal)
1635 bool const at_end = (cursor.pos() == cursor.par()->size());
1636 bool const at_newline = !at_end &&
1637 cursor.par()->isNewline(cursor.pos());
1639 if (!internal && cursor.boundary() && !at_newline)
1640 setCursor(cursor.par(), cursor.pos(), true, false);
1642 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1644 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
1645 setCursor(cursor.par(), cursor.pos(), true, true);
1646 } else if (boost::next(cursor.par()) != ownerParagraphs().end())
1647 setCursor(boost::next(cursor.par()), 0);
1651 void LyXText::cursorUp(bool selecting)
1654 int x = cursor.x_fix();
1655 int y = cursor.y() - cursorRow()->baseline() - 1;
1656 setCursorFromCoordinates(x, y);
1658 int topy = bv_owner->top_y();
1659 int y1 = cursor.y() - topy;
1662 InsetOld * inset_hit = checkInsetHit(x, y1);
1663 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1664 inset_hit->localDispatch(
1665 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1669 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1670 cursorRow()->baseline() << endl;
1671 setCursorFromCoordinates(cursor.x_fix(),
1672 cursor.y() - cursorRow()->baseline() - 1);
1677 void LyXText::cursorDown(bool selecting)
1680 int x = cursor.x_fix();
1681 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1682 setCursorFromCoordinates(x, y);
1683 if (!selecting && cursorRow() == cursorIRow()) {
1684 int topy = bv_owner->top_y();
1685 int y1 = cursor.y() - topy;
1688 InsetOld * inset_hit = checkInsetHit(x, y1);
1689 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1690 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1691 inset_hit->localDispatch(cmd);
1695 setCursorFromCoordinates(cursor.x_fix(),
1696 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1701 void LyXText::cursorUpParagraph()
1703 if (cursor.pos() > 0)
1704 setCursor(cursor.par(), 0);
1705 else if (cursor.par() != ownerParagraphs().begin())
1706 setCursor(boost::prior(cursor.par()), 0);
1710 void LyXText::cursorDownParagraph()
1712 ParagraphList::iterator par = cursor.par();
1713 ParagraphList::iterator next_par = boost::next(par);
1715 if (next_par != ownerParagraphs().end())
1716 setCursor(next_par, 0);
1718 setCursor(par, par->size());
1722 // fix the cursor `cur' after a characters has been deleted at `where'
1723 // position. Called by deleteEmptyParagraphMechanism
1724 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1726 // if cursor is not in the paragraph where the delete occured,
1728 if (cur.par() != where.par())
1731 // if cursor position is after the place where the delete occured,
1733 if (cur.pos() > where.pos())
1734 cur.pos(cur.pos()-1);
1736 // check also if we don't want to set the cursor on a spot behind the
1737 // pagragraph because we erased the last character.
1738 if (cur.pos() > cur.par()->size())
1739 cur.pos(cur.par()->size());
1741 // recompute row et al. for this cursor
1742 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1746 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1748 // Would be wrong to delete anything if we have a selection.
1749 if (selection.set())
1752 // We allow all kinds of "mumbo-jumbo" when freespacing.
1753 if (old_cursor.par()->isFreeSpacing())
1756 /* Ok I'll put some comments here about what is missing.
1757 I have fixed BackSpace (and thus Delete) to not delete
1758 double-spaces automagically. I have also changed Cut,
1759 Copy and Paste to hopefully do some sensible things.
1760 There are still some small problems that can lead to
1761 double spaces stored in the document file or space at
1762 the beginning of paragraphs. This happens if you have
1763 the cursor between to spaces and then save. Or if you
1764 cut and paste and the selection have a space at the
1765 beginning and then save right after the paste. I am
1766 sure none of these are very hard to fix, but I will
1767 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1768 that I can get some feedback. (Lgb)
1771 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1772 // delete the LineSeparator.
1775 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1776 // delete the LineSeparator.
1779 // If the pos around the old_cursor were spaces, delete one of them.
1780 if (old_cursor.par() != cursor.par()
1781 || old_cursor.pos() != cursor.pos()) {
1783 // Only if the cursor has really moved
1784 if (old_cursor.pos() > 0
1785 && old_cursor.pos() < old_cursor.par()->size()
1786 && old_cursor.par()->isLineSeparator(old_cursor.pos())
1787 && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
1788 bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
1789 redoParagraph(old_cursor.par());
1793 #ifdef WITH_WARNINGS
1794 #warning This will not work anymore when we have multiple views of the same buffer
1795 // In this case, we will have to correct also the cursors held by
1796 // other bufferviews. It will probably be easier to do that in a more
1797 // automated way in LyXCursor code. (JMarc 26/09/2001)
1799 // correct all cursors held by the LyXText
1800 fixCursorAfterDelete(cursor, old_cursor);
1801 fixCursorAfterDelete(selection.cursor, old_cursor);
1802 fixCursorAfterDelete(selection.start, old_cursor);
1803 fixCursorAfterDelete(selection.end, old_cursor);
1808 // don't delete anything if this is the ONLY paragraph!
1809 if (ownerParagraphs().size() == 1)
1812 // Do not delete empty paragraphs with keepempty set.
1813 if (old_cursor.par()->allowEmpty())
1816 // only do our magic if we changed paragraph
1817 if (old_cursor.par() == cursor.par())
1820 // record if we have deleted a paragraph
1821 // we can't possibly have deleted a paragraph before this point
1822 bool deleted = false;
1824 if (old_cursor.par()->empty() ||
1825 (old_cursor.par()->size() == 1 &&
1826 old_cursor.par()->isLineSeparator(0))) {
1827 // ok, we will delete something
1828 LyXCursor tmpcursor;
1832 bool selection_position_was_oldcursor_position = (
1833 selection.cursor.par() == old_cursor.par()
1834 && selection.cursor.pos() == old_cursor.pos());
1837 cursor = old_cursor; // that undo can restore the right cursor position
1839 ParagraphList::iterator endpit = boost::next(old_cursor.par());
1840 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1843 recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
1847 ownerParagraphs().erase(old_cursor.par());
1851 setCursorIntern(cursor.par(), cursor.pos());
1853 if (selection_position_was_oldcursor_position) {
1854 // correct selection
1855 selection.cursor = cursor;
1859 if (old_cursor.par()->stripLeadingSpaces()) {
1860 redoParagraph(old_cursor.par());
1862 setCursorIntern(cursor.par(), cursor.pos());
1863 selection.cursor = cursor;
1870 ParagraphList & LyXText::ownerParagraphs() const
1876 bool LyXText::isInInset() const
1878 // Sub-level has non-null bv owner and non-null inset owner.
1879 return inset_owner != 0;
1883 int defaultRowHeight()
1885 LyXFont const font(LyXFont::ALL_SANE);
1886 return int(font_metrics::maxAscent(font)
1887 + font_metrics::maxDescent(font) * 1.5);