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"
30 #include "CutAndPaste.h"
32 #include "errorlist.h"
34 #include "FloatList.h"
35 #include "funcrequest.h"
40 #include "lyxrow_funcs.h"
41 #include "metricsinfo.h"
42 #include "paragraph_funcs.h"
43 #include "ParagraphParameters.h"
44 #include "undo_funcs.h"
47 #include "frontends/font_metrics.h"
48 #include "frontends/LyXView.h"
50 #include "insets/insetbibitem.h"
51 #include "insets/insetenv.h"
52 #include "insets/insetfloat.h"
53 #include "insets/insetwrap.h"
55 #include "support/lstrings.h"
56 #include "support/textutils.h"
57 #include "support/tostr.h"
58 #include "support/std_sstream.h"
60 #include <boost/tuple/tuple.hpp>
63 using lyx::support::bformat;
66 using std::ostringstream;
69 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
70 ParagraphList & paragraphs)
71 : height(0), width(0), anchor_y_(0),
72 inset_owner(inset), the_locking_inset(0), bv_owner(bv),
73 in_inset_(ininset), paragraphs_(paragraphs)
78 void LyXText::init(BufferView * bview)
82 ParagraphList::iterator const beg = ownerParagraphs().begin();
83 ParagraphList::iterator const end = ownerParagraphs().end();
84 for (ParagraphList::iterator pit = beg; pit != end; ++pit)
92 current_font = getFont(beg, 0);
94 redoParagraphs(beg, end);
95 setCursorIntern(beg, 0);
96 selection.cursor = cursor;
102 // Gets the fully instantiated font at a given position in a paragraph
103 // Basically the same routine as Paragraph::getFont() in paragraph.C.
104 // The difference is that this one is used for displaying, and thus we
105 // are allowed to make cosmetic improvements. For instance make footnotes
107 LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
109 BOOST_ASSERT(pos >= 0);
111 LyXLayout_ptr const & layout = pit->layout();
113 BufferParams const & params = bv()->buffer()->params();
115 // We specialize the 95% common case:
116 if (!pit->getDepth()) {
117 if (layout->labeltype == LABEL_MANUAL
118 && pos < pit->beginningOfBody()) {
120 LyXFont f = pit->getFontSettings(params, pos);
122 pit->inInset()->getDrawFont(f);
123 return f.realize(layout->reslabelfont);
125 LyXFont f = pit->getFontSettings(params, pos);
127 pit->inInset()->getDrawFont(f);
128 return f.realize(layout->resfont);
132 // The uncommon case need not be optimized as much
136 if (pos < pit->beginningOfBody()) {
138 layoutfont = layout->labelfont;
141 layoutfont = layout->font;
144 LyXFont tmpfont = pit->getFontSettings(params, pos);
145 tmpfont.realize(layoutfont);
148 pit->inInset()->getDrawFont(tmpfont);
150 // Realize with the fonts of lesser depth.
151 tmpfont.realize(outerFont(pit, ownerParagraphs()));
152 tmpfont.realize(defaultfont_);
158 LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const
160 LyXLayout_ptr const & layout = pit->layout();
162 if (!pit->getDepth())
163 return layout->resfont;
165 LyXFont font = layout->font;
166 // Realize with the fonts of lesser depth.
167 font.realize(outerFont(pit, ownerParagraphs()));
168 font.realize(defaultfont_);
174 LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
176 LyXLayout_ptr const & layout = pit->layout();
178 if (!pit->getDepth())
179 return layout->reslabelfont;
181 LyXFont font = layout->labelfont;
182 // Realize with the fonts of lesser depth.
183 font.realize(outerFont(pit, ownerParagraphs()));
184 font.realize(defaultfont_);
190 void LyXText::setCharFont(ParagraphList::iterator pit,
191 pos_type pos, LyXFont const & fnt,
194 BufferParams const & params = bv()->buffer()->params();
195 LyXFont font = getFont(pit, pos);
196 font.update(fnt, params.language, toggleall);
197 // Let the insets convert their font
198 if (pit->isInset(pos)) {
199 InsetOld * inset = pit->getInset(pos);
200 if (isEditableInset(inset)) {
201 static_cast<UpdatableInset *>(inset)
202 ->setFont(bv(), fnt, toggleall, true);
206 // Plug through to version below:
207 setCharFont(pit, pos, font);
211 void LyXText::setCharFont(
212 ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
215 LyXLayout_ptr const & layout = pit->layout();
217 // Get concrete layout font to reduce against
220 if (pos < pit->beginningOfBody())
221 layoutfont = layout->labelfont;
223 layoutfont = layout->font;
225 // Realize against environment font information
226 if (pit->getDepth()) {
227 ParagraphList::iterator tp = pit;
228 while (!layoutfont.resolved() &&
229 tp != ownerParagraphs().end() &&
231 tp = outerHook(tp, ownerParagraphs());
232 if (tp != ownerParagraphs().end())
233 layoutfont.realize(tp->layout()->font);
237 layoutfont.realize(defaultfont_);
239 // Now, reduce font against full layout font
240 font.reduce(layoutfont);
242 pit->setFont(pos, font);
246 InsetOld * LyXText::getInset() const
248 ParagraphList::iterator pit = cursor.par();
249 pos_type const pos = cursor.pos();
251 if (pos < pit->size() && pit->isInset(pos)) {
252 return pit->getInset(pos);
258 void LyXText::toggleInset()
260 InsetOld * inset = getInset();
261 // is there an editable inset at cursor position?
262 if (!isEditableInset(inset)) {
263 // No, try to see if we are inside a collapsable inset
264 if (inset_owner && inset_owner->owner()
265 && inset_owner->owner()->isOpen()) {
266 bv()->unlockInset(inset_owner->owner());
267 inset_owner->owner()->close(bv());
268 bv()->getLyXText()->cursorRight(bv());
272 //bv()->owner()->message(inset->editMessage());
274 // do we want to keep this?? (JMarc)
275 if (!isHighlyEditableInset(inset))
276 recordUndo(bv(), Undo::ATOMIC);
283 bv()->updateInset(inset);
287 /* used in setlayout */
288 // Asger is not sure we want to do this...
289 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
292 LyXLayout_ptr const & layout = par.layout();
293 pos_type const psize = par.size();
296 for (pos_type pos = 0; pos < psize; ++pos) {
297 if (pos < par.beginningOfBody())
298 layoutfont = layout->labelfont;
300 layoutfont = layout->font;
302 LyXFont tmpfont = par.getFontSettings(params, pos);
303 tmpfont.reduce(layoutfont);
304 par.setFont(pos, tmpfont);
309 ParagraphList::iterator
310 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
311 LyXCursor & send_cur,
312 string const & layout)
314 ParagraphList::iterator endpit = boost::next(send_cur.par());
315 ParagraphList::iterator undoendpit = endpit;
316 ParagraphList::iterator pars_end = ownerParagraphs().end();
318 if (endpit != pars_end && endpit->getDepth()) {
319 while (endpit != pars_end && endpit->getDepth()) {
323 } else if (endpit != pars_end) {
324 // because of parindents etc.
328 recordUndo(bv(), Undo::ATOMIC, sstart_cur.par(), boost::prior(undoendpit));
330 // ok we have a selection. This is always between sstart_cur
331 // and sel_end cursor
333 ParagraphList::iterator pit = sstart_cur.par();
334 ParagraphList::iterator epit = boost::next(send_cur.par());
336 BufferParams const & bufparams = bv()->buffer()->params();
337 LyXLayout_ptr const & lyxlayout =
338 bufparams.getLyXTextClass()[layout];
341 pit->applyLayout(lyxlayout);
342 makeFontEntriesLayoutSpecific(bufparams, *pit);
343 pit->params().spaceTop(lyxlayout->fill_top ?
344 VSpace(VSpace::VFILL)
345 : VSpace(VSpace::NONE));
346 pit->params().spaceBottom(lyxlayout->fill_bottom ?
347 VSpace(VSpace::VFILL)
348 : VSpace(VSpace::NONE));
349 if (lyxlayout->margintype == MARGIN_MANUAL)
350 pit->setLabelWidthString(lyxlayout->labelstring());
353 } while (pit != epit);
359 // set layout over selection and make a total rebreak of those paragraphs
360 void LyXText::setLayout(string const & layout)
362 LyXCursor tmpcursor = cursor; // store the current cursor
364 // if there is no selection just set the layout
365 // of the current paragraph
366 if (!selection.set()) {
367 selection.start = cursor; // dummy selection
368 selection.end = cursor;
371 // special handling of new environment insets
372 BufferParams const & params = bv()->buffer()->params();
373 LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
374 if (lyxlayout->is_environment) {
375 // move everything in a new environment inset
376 lyxerr << "setting layout " << layout << endl;
377 bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
378 bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
379 bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
380 InsetOld * inset = new InsetEnvironment(params, layout);
381 if (bv()->insertInset(inset)) {
383 //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
390 ParagraphList::iterator endpit = setLayout(cursor, selection.start,
391 selection.end, layout);
392 redoParagraphs(selection.start.par(), endpit);
394 // we have to reset the selection, because the
395 // geometry could have changed
396 setCursor(selection.start.par(), selection.start.pos(), false);
397 selection.cursor = cursor;
398 setCursor(selection.end.par(), selection.end.pos(), false);
402 setCursor(tmpcursor.par(), tmpcursor.pos(), true);
406 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
408 ParagraphList::iterator pit = cursor.par();
409 ParagraphList::iterator end = cursor.par();
410 ParagraphList::iterator start = pit;
412 if (selection.set()) {
413 pit = selection.start.par();
414 end = selection.end.par();
418 ParagraphList::iterator pastend = boost::next(end);
421 recordUndo(bv(), Undo::ATOMIC, start, end);
423 bool changed = false;
425 int prev_after_depth = 0;
426 #warning parlist ... could be nicer ?
427 if (start != ownerParagraphs().begin()) {
428 prev_after_depth = boost::prior(start)->getMaxDepthAfter();
432 int const depth = pit->params().depth();
433 if (type == bv_funcs::INC_DEPTH) {
434 if (depth < prev_after_depth
435 && pit->layout()->labeltype != LABEL_BIBLIO) {
438 pit->params().depth(depth + 1);
443 pit->params().depth(depth - 1);
446 prev_after_depth = pit->getMaxDepthAfter();
458 redoParagraphs(start, pastend);
460 // We need to actually move the text->cursor. I don't
461 // understand why ...
462 LyXCursor tmpcursor = cursor;
464 // we have to reset the visual selection because the
465 // geometry could have changed
466 if (selection.set()) {
467 setCursor(selection.start.par(), selection.start.pos());
468 selection.cursor = cursor;
469 setCursor(selection.end.par(), selection.end.pos());
472 // this handles the counter labels, and also fixes up
473 // depth values for follow-on (child) paragraphs
477 setCursor(tmpcursor.par(), tmpcursor.pos());
483 // set font over selection and make a total rebreak of those paragraphs
484 void LyXText::setFont(LyXFont const & font, bool toggleall)
486 // if there is no selection just set the current_font
487 if (!selection.set()) {
488 // Determine basis font
490 if (cursor.pos() < cursor.par()->beginningOfBody()) {
491 layoutfont = getLabelFont(cursor.par());
493 layoutfont = getLayoutFont(cursor.par());
495 // Update current font
496 real_current_font.update(font,
497 bv()->buffer()->params().language,
500 // Reduce to implicit settings
501 current_font = real_current_font;
502 current_font.reduce(layoutfont);
503 // And resolve it completely
504 real_current_font.realize(layoutfont);
509 LyXCursor tmpcursor = cursor; // store the current cursor
511 // ok we have a selection. This is always between sel_start_cursor
512 // and sel_end cursor
514 recordUndo(bv(), Undo::ATOMIC, selection.start.par(), selection.end.par());
516 cursor = selection.start;
517 while (cursor.par() != selection.end.par() ||
518 cursor.pos() < selection.end.pos())
520 if (cursor.pos() < cursor.par()->size()) {
521 // an open footnote should behave like a closed one
522 setCharFont(cursor.par(), cursor.pos(),
524 cursor.pos(cursor.pos() + 1);
527 cursor.par(boost::next(cursor.par()));
532 redoParagraph(selection.start.par());
534 // we have to reset the selection, because the
535 // geometry could have changed, but we keep
536 // it for user convenience
537 setCursor(selection.start.par(), selection.start.pos());
538 selection.cursor = cursor;
539 setCursor(selection.end.par(), selection.end.pos());
541 setCursor(tmpcursor.par(), tmpcursor.pos(), true,
542 tmpcursor.boundary());
546 int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
548 RowList::iterator rit = pit->rows.begin();
549 RowList::iterator end = pit->rows.end();
551 // remove rows of paragraph, keep track of height changes
552 for (int i = 0; rit != end; ++rit, ++i)
553 height -= rit->height();
557 InsetList::iterator ii = pit->insetlist.begin();
558 InsetList::iterator iend = pit->insetlist.end();
559 for (; ii != iend; ++ii) {
561 MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
562 ii->inset->metrics(mi, dim);
565 // rebreak the paragraph
566 for (pos_type z = 0; z < pit->size() + 1; ) {
568 z = rowBreakPoint(pit, row) + 1;
570 pit->rows.push_back(row);
574 // set height and fill and width of rows
575 int const ww = workWidth();
576 for (rit = pit->rows.begin(); rit != end; ++rit) {
577 int const f = fill(pit, rit, ww);
578 int const w = ww - f;
579 par_width = std::max(par_width, w);
582 prepareToPrint(pit, rit);
583 setHeightOfRow(pit, rit);
584 height += rit->height();
587 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
592 int LyXText::redoParagraphs(ParagraphList::iterator start,
593 ParagraphList::iterator end)
596 for ( ; start != end; ++start) {
597 int par_width = redoParagraphInternal(start);
598 pars_width = std::max(par_width, pars_width);
600 updateRowPositions();
605 void LyXText::redoParagraph(ParagraphList::iterator pit)
607 redoParagraphInternal(pit);
608 updateRowPositions();
612 void LyXText::fullRebreak()
614 redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
616 selection.cursor = cursor;
620 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
622 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
623 // << " workWidth: " << workWidth() << endl;
624 //BOOST_ASSERT(mi.base.textwidth);
631 width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
634 dim.asc = firstRow()->ascent_of_text();
635 dim.des = height - dim.asc;
636 dim.wid = std::max(mi.base.textwidth, int(width));
640 // important for the screen
643 // the cursor set functions have a special mechanism. When they
644 // realize, that you left an empty paragraph, they will delete it.
645 // They also delete the corresponding row
647 // need the selection cursor:
648 void LyXText::setSelection()
650 TextCursor::setSelection();
655 void LyXText::clearSelection()
657 TextCursor::clearSelection();
659 // reset this in the bv_owner!
660 if (bv_owner && bv_owner->text)
661 bv_owner->text->xsel_cache.set(false);
665 void LyXText::cursorHome()
667 setCursor(cursor.par(), cursorRow()->pos());
671 void LyXText::cursorEnd()
673 setCursor(cursor.par(), cursorRow()->end() - 1);
677 void LyXText::cursorTop()
679 setCursor(ownerParagraphs().begin(), 0);
683 void LyXText::cursorBottom()
685 ParagraphList::iterator lastpit =
686 boost::prior(ownerParagraphs().end());
687 setCursor(lastpit, lastpit->size());
691 void LyXText::toggleFree(LyXFont const & font, bool toggleall)
693 // If the mask is completely neutral, tell user
694 if (font == LyXFont(LyXFont::ALL_IGNORE)) {
695 // Could only happen with user style
696 bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
700 // Try implicit word selection
701 // If there is a change in the language the implicit word selection
703 LyXCursor resetCursor = cursor;
704 bool implicitSelection = (font.language() == ignore_language
705 && font.number() == LyXFont::IGNORE)
706 ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
709 setFont(font, toggleall);
711 // Implicit selections are cleared afterwards
712 //and cursor is set to the original position.
713 if (implicitSelection) {
715 cursor = resetCursor;
716 setCursor(cursor.par(), cursor.pos());
717 selection.cursor = cursor;
722 string LyXText::getStringToIndex()
724 // Try implicit word selection
725 // If there is a change in the language the implicit word selection
727 LyXCursor const reset_cursor = cursor;
728 bool const implicitSelection =
729 selectWordWhenUnderCursor(lyx::PREVIOUS_WORD);
732 if (!selection.set())
733 bv()->owner()->message(_("Nothing to index!"));
734 else if (selection.start.par() != selection.end.par())
735 bv()->owner()->message(_("Cannot index more than one paragraph!"));
737 idxstring = selectionAsString(*bv()->buffer(), false);
739 // Reset cursors to their original position.
740 cursor = reset_cursor;
741 setCursor(cursor.par(), cursor.pos());
742 selection.cursor = cursor;
744 // Clear the implicit selection.
745 if (implicitSelection)
752 // the DTP switches for paragraphs. LyX will store them in the first
753 // physical paragraph. When a paragraph is broken, the top settings rest,
754 // the bottom settings are given to the new one. So I can make sure,
755 // they do not duplicate themself and you cannnot make dirty things with
758 void LyXText::setParagraph(bool line_top, bool line_bottom,
759 bool pagebreak_top, bool pagebreak_bottom,
760 VSpace const & space_top,
761 VSpace const & space_bottom,
762 Spacing const & spacing,
764 string const & labelwidthstring,
767 LyXCursor tmpcursor = cursor;
768 if (!selection.set()) {
769 selection.start = cursor;
770 selection.end = cursor;
773 // make sure that the depth behind the selection are restored, too
774 ParagraphList::iterator endpit = boost::next(selection.end.par());
775 ParagraphList::iterator undoendpit = endpit;
776 ParagraphList::iterator pars_end = ownerParagraphs().end();
778 if (endpit != pars_end && endpit->getDepth()) {
779 while (endpit != pars_end && endpit->getDepth()) {
783 } else if (endpit != pars_end) {
784 // because of parindents etc.
788 recordUndo(bv(), Undo::ATOMIC, selection.start.par(),
789 boost::prior(undoendpit));
792 ParagraphList::iterator tmppit = selection.end.par();
794 while (tmppit != boost::prior(selection.start.par())) {
795 setCursor(tmppit, 0);
797 ParagraphList::iterator pit = cursor.par();
798 ParagraphParameters & params = pit->params();
800 params.lineTop(line_top);
801 params.lineBottom(line_bottom);
802 params.pagebreakTop(pagebreak_top);
803 params.pagebreakBottom(pagebreak_bottom);
804 params.spaceTop(space_top);
805 params.spaceBottom(space_bottom);
806 params.spacing(spacing);
807 // does the layout allow the new alignment?
808 LyXLayout_ptr const & layout = pit->layout();
810 if (align == LYX_ALIGN_LAYOUT)
811 align = layout->align;
812 if (align & layout->alignpossible) {
813 if (align == layout->align)
814 params.align(LYX_ALIGN_LAYOUT);
818 pit->setLabelWidthString(labelwidthstring);
819 params.noindent(noindent);
820 tmppit = boost::prior(pit);
823 redoParagraphs(selection.start.par(), endpit);
826 setCursor(selection.start.par(), selection.start.pos());
827 selection.cursor = cursor;
828 setCursor(selection.end.par(), selection.end.pos());
830 setCursor(tmpcursor.par(), tmpcursor.pos());
832 bv()->updateInset(inset_owner);
838 string expandLabel(LyXTextClass const & textclass,
839 LyXLayout_ptr const & layout, bool appendix)
841 string fmt = appendix ?
842 layout->labelstring_appendix() : layout->labelstring();
844 // handle 'inherited level parts' in 'fmt',
845 // i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
846 size_t const i = fmt.find('@', 0);
847 if (i != string::npos) {
848 size_t const j = fmt.find('@', i + 1);
849 if (j != string::npos) {
850 string parent(fmt, i + 1, j - i - 1);
851 string label = expandLabel(textclass, textclass[parent], appendix);
852 fmt = string(fmt, 0, i) + label + string(fmt, j + 1, string::npos);
856 return textclass.counters().counterLabel(fmt);
862 // set the counter of a paragraph. This includes the labels
863 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
865 BufferParams const & bufparams = buf.params();
866 LyXTextClass const & textclass = bufparams.getLyXTextClass();
867 LyXLayout_ptr const & layout = pit->layout();
869 if (pit != ownerParagraphs().begin()) {
870 pit->params().appendix(boost::prior(pit)->params().appendix());
871 if (!pit->params().appendix() &&
872 pit->params().startOfAppendix()) {
873 pit->params().appendix(true);
874 textclass.counters().reset();
876 pit->enumdepth = boost::prior(pit)->enumdepth;
877 pit->itemdepth = boost::prior(pit)->itemdepth;
879 pit->params().appendix(pit->params().startOfAppendix());
884 // Maybe we have to increment the enumeration depth.
885 // Bibliographies can't have their depth changed ie. they
886 // are always of depth 0
887 if (pit != ownerParagraphs().begin()
888 && boost::prior(pit)->getDepth() < pit->getDepth()
889 && boost::prior(pit)->layout()->labeltype == LABEL_ENUMERATE
890 && pit->enumdepth < 3
891 && layout->labeltype != LABEL_BIBLIO) {
895 // Maybe we have to increment the enumeration depth.
896 // Bibliographies can't have their depth changed ie. they
897 // are always of depth 0
898 if (pit != ownerParagraphs().begin()
899 && boost::prior(pit)->getDepth() < pit->getDepth()
900 && boost::prior(pit)->layout()->labeltype == LABEL_ITEMIZE
901 && pit->itemdepth < 3
902 && layout->labeltype != LABEL_BIBLIO) {
906 // Maybe we have to decrement the enumeration depth, see note above
907 if (pit != ownerParagraphs().begin()
908 && boost::prior(pit)->getDepth() > pit->getDepth()
909 && layout->labeltype != LABEL_BIBLIO) {
910 pit->enumdepth = depthHook(pit, ownerParagraphs(),
911 pit->getDepth())->enumdepth;
914 // erase what was there before
915 pit->params().labelString(string());
917 if (layout->margintype == MARGIN_MANUAL) {
918 if (pit->params().labelWidthString().empty())
919 pit->setLabelWidthString(layout->labelstring());
921 pit->setLabelWidthString(string());
924 // is it a layout that has an automatic label?
925 if (layout->labeltype == LABEL_COUNTER) {
926 BufferParams const & bufparams = buf.params();
927 LyXTextClass const & textclass = bufparams.getLyXTextClass();
928 textclass.counters().step(layout->counter);
929 string label = expandLabel(textclass, layout, pit->params().appendix());
930 pit->params().labelString(label);
931 textclass.counters().reset("enum");
932 } else if (layout->labeltype == LABEL_ITEMIZE) {
933 // At some point of time we should do something more clever here,
935 // pit->params().labelString(
936 // bufparams.user_defined_bullet(pit->itemdepth).getText());
937 // for now, use a static label
938 pit->params().labelString("*");
939 textclass.counters().reset("enum");
940 } else if (layout->labeltype == LABEL_ENUMERATE) {
942 // Yes I know this is a really, really! bad solution
944 string enumcounter = "enum";
946 switch (pit->enumdepth) {
958 // not a valid enumdepth...
962 textclass.counters().step(enumcounter);
964 pit->params().labelString(textclass.counters().enumLabel(enumcounter));
965 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
966 textclass.counters().step("bibitem");
967 int number = textclass.counters().value("bibitem");
968 if (pit->bibitem()) {
969 pit->bibitem()->setCounter(number);
970 pit->params().labelString(layout->labelstring());
972 // In biblio should't be following counters but...
974 string s = buf.B_(layout->labelstring());
977 if (layout->labeltype == LABEL_SENSITIVE) {
978 ParagraphList::iterator end = ownerParagraphs().end();
979 ParagraphList::iterator tmppit = pit;
982 while (tmppit != end && tmppit->inInset()
983 // the single '=' is intended below
984 && (in = tmppit->inInset()->owner()))
986 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
987 in->lyxCode() == InsetOld::WRAP_CODE) {
991 Paragraph const * owner = &ownerPar(buf, in);
992 tmppit = ownerParagraphs().begin();
993 for ( ; tmppit != end; ++tmppit)
994 if (&*tmppit == owner)
1002 if (in->lyxCode() == InsetOld::FLOAT_CODE)
1003 type = static_cast<InsetFloat*>(in)->params().type;
1004 else if (in->lyxCode() == InsetOld::WRAP_CODE)
1005 type = static_cast<InsetWrap*>(in)->params().type;
1007 BOOST_ASSERT(false);
1009 Floating const & fl = textclass.floats().getType(type);
1011 textclass.counters().step(fl.type());
1013 // Doesn't work... yet.
1014 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1016 // par->SetLayout(0);
1017 // s = layout->labelstring;
1018 s = _("Senseless: ");
1021 pit->params().labelString(s);
1023 // reset the enumeration counter. They are always reset
1024 // when there is any other layout between
1025 // Just fall-through between the cases so that all
1026 // enum counters deeper than enumdepth is also reset.
1027 switch (pit->enumdepth) {
1029 textclass.counters().reset("enumi");
1031 textclass.counters().reset("enumii");
1033 textclass.counters().reset("enumiii");
1035 textclass.counters().reset("enumiv");
1041 // Updates all counters. Paragraphs with changed label string will be rebroken
1042 void LyXText::updateCounters()
1045 bv()->buffer()->params().getLyXTextClass().counters().reset();
1047 ParagraphList::iterator beg = ownerParagraphs().begin();
1048 ParagraphList::iterator end = ownerParagraphs().end();
1049 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1050 string const oldLabel = pit->params().labelString();
1052 size_t maxdepth = 0;
1054 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1056 if (pit->params().depth() > maxdepth)
1057 pit->params().depth(maxdepth);
1059 // setCounter can potentially change the labelString.
1060 setCounter(*bv()->buffer(), pit);
1062 string const & newLabel = pit->params().labelString();
1064 if (oldLabel != newLabel)
1070 void LyXText::insertInset(InsetOld * inset)
1072 if (!cursor.par()->insetAllowed(inset->lyxCode()))
1074 recordUndo(bv(), Undo::ATOMIC, cursor.par());
1076 cursor.par()->insertInset(cursor.pos(), inset);
1077 // Just to rebreak and refresh correctly.
1078 // The character will not be inserted a second time
1079 insertChar(Paragraph::META_INSET);
1080 // If we enter a highly editable inset the cursor should be before
1081 // the inset. After an Undo LyX tries to call inset->edit(...)
1082 // and fails if the cursor is behind the inset and getInset
1083 // does not return the inset!
1084 if (isHighlyEditableInset(inset))
1090 void LyXText::cutSelection(bool doclear, bool realcut)
1092 // Stuff what we got on the clipboard. Even if there is no selection.
1094 // There is a problem with having the stuffing here in that the
1095 // larger the selection the slower LyX will get. This can be
1096 // solved by running the line below only when the selection has
1097 // finished. The solution used currently just works, to make it
1098 // faster we need to be more clever and probably also have more
1099 // calls to stuffClipboard. (Lgb)
1100 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1102 // This doesn't make sense, if there is no selection
1103 if (!selection.set())
1106 // OK, we have a selection. This is always between selection.start
1107 // and selection.end
1109 // make sure that the depth behind the selection are restored, too
1110 ParagraphList::iterator endpit = boost::next(selection.end.par());
1111 ParagraphList::iterator undoendpit = endpit;
1112 ParagraphList::iterator pars_end = ownerParagraphs().end();
1114 if (endpit != pars_end && endpit->getDepth()) {
1115 while (endpit != pars_end && endpit->getDepth()) {
1117 undoendpit = endpit;
1119 } else if (endpit != pars_end) {
1120 // because of parindents etc.
1124 recordUndo(bv(), Undo::DELETE, selection.start.par(),
1125 boost::prior(undoendpit));
1127 endpit = selection.end.par();
1128 int endpos = selection.end.pos();
1130 BufferParams const & bufparams = bv()->buffer()->params();
1131 boost::tie(endpit, endpos) = realcut ?
1132 CutAndPaste::cutSelection(bufparams,
1134 selection.start.par(), endpit,
1135 selection.start.pos(), endpos,
1136 bufparams.textclass,
1138 : CutAndPaste::eraseSelection(bufparams,
1140 selection.start.par(), endpit,
1141 selection.start.pos(), endpos,
1143 // sometimes necessary
1145 selection.start.par()->stripLeadingSpaces();
1147 redoParagraphs(selection.start.par(), boost::next(endpit));
1148 // cutSelection can invalidate the cursor so we need to set
1150 // we prefer the end for when tracking changes
1154 // need a valid cursor. (Lgb)
1157 setCursor(cursor.par(), cursor.pos());
1158 selection.cursor = cursor;
1163 void LyXText::copySelection()
1165 // stuff the selection onto the X clipboard, from an explicit copy request
1166 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1168 // this doesnt make sense, if there is no selection
1169 if (!selection.set())
1172 // ok we have a selection. This is always between selection.start
1173 // and sel_end cursor
1175 // copy behind a space if there is one
1176 while (selection.start.par()->size() > selection.start.pos()
1177 && selection.start.par()->isLineSeparator(selection.start.pos())
1178 && (selection.start.par() != selection.end.par()
1179 || selection.start.pos() < selection.end.pos()))
1180 selection.start.pos(selection.start.pos() + 1);
1182 CutAndPaste::copySelection(selection.start.par(),
1183 selection.end.par(),
1184 selection.start.pos(), selection.end.pos(),
1185 bv()->buffer()->params().textclass);
1189 void LyXText::pasteSelection(size_t sel_index)
1191 // this does not make sense, if there is nothing to paste
1192 if (!CutAndPaste::checkPastePossible())
1195 recordUndo(bv(), Undo::INSERT, cursor.par());
1197 ParagraphList::iterator endpit;
1202 boost::tie(ppp, endpit) =
1203 CutAndPaste::pasteSelection(*bv()->buffer(),
1205 cursor.par(), cursor.pos(),
1206 bv()->buffer()->params().textclass,
1208 bufferErrors(*bv()->buffer(), el);
1209 bv()->showErrorList(_("Paste"));
1211 redoParagraphs(cursor.par(), endpit);
1213 setCursor(cursor.par(), cursor.pos());
1216 selection.cursor = cursor;
1217 setCursor(ppp.first, ppp.second);
1223 void LyXText::setSelectionRange(lyx::pos_type length)
1228 selection.cursor = cursor;
1235 // simple replacing. The font of the first selected character is used
1236 void LyXText::replaceSelectionWithString(string const & str)
1238 recordUndo(bv(), Undo::ATOMIC);
1241 if (!selection.set()) { // create a dummy selection
1242 selection.end = cursor;
1243 selection.start = cursor;
1246 // Get font setting before we cut
1247 pos_type pos = selection.end.pos();
1248 LyXFont const font = selection.start.par()
1249 ->getFontSettings(bv()->buffer()->params(),
1250 selection.start.pos());
1252 // Insert the new string
1253 string::const_iterator cit = str.begin();
1254 string::const_iterator end = str.end();
1255 for (; cit != end; ++cit) {
1256 selection.end.par()->insertChar(pos, (*cit), font);
1260 // Cut the selection
1261 cutSelection(true, false);
1267 // needed to insert the selection
1268 void LyXText::insertStringAsLines(string const & str)
1270 ParagraphList::iterator pit = cursor.par();
1271 pos_type pos = cursor.pos();
1272 ParagraphList::iterator endpit = boost::next(cursor.par());
1274 recordUndo(bv(), Undo::ATOMIC);
1276 // only to be sure, should not be neccessary
1279 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1281 redoParagraphs(cursor.par(), endpit);
1282 setCursor(cursor.par(), cursor.pos());
1283 selection.cursor = cursor;
1284 setCursor(pit, pos);
1289 // turns double-CR to single CR, others where converted into one
1290 // blank. Then InsertStringAsLines is called
1291 void LyXText::insertStringAsParagraphs(string const & str)
1293 string linestr(str);
1294 bool newline_inserted = false;
1295 string::size_type const siz = linestr.length();
1297 for (string::size_type i = 0; i < siz; ++i) {
1298 if (linestr[i] == '\n') {
1299 if (newline_inserted) {
1300 // we know that \r will be ignored by
1301 // InsertStringA. Of course, it is a dirty
1302 // trick, but it works...
1303 linestr[i - 1] = '\r';
1307 newline_inserted = true;
1309 } else if (IsPrintable(linestr[i])) {
1310 newline_inserted = false;
1313 insertStringAsLines(linestr);
1317 bool LyXText::setCursor(ParagraphList::iterator pit,
1319 bool setfont, bool boundary)
1321 LyXCursor old_cursor = cursor;
1322 setCursorIntern(pit, pos, setfont, boundary);
1323 return deleteEmptyParagraphMechanism(old_cursor);
1327 void LyXText::redoCursor()
1329 #warning maybe the same for selections?
1330 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1334 void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
1335 pos_type pos, bool boundary)
1337 BOOST_ASSERT(pit != ownerParagraphs().end());
1341 cur.boundary(boundary);
1345 // get the cursor y position in text
1347 RowList::iterator row = getRow(pit, pos);
1350 // y is now the beginning of the cursor row
1351 y += row->baseline();
1352 // y is now the cursor baseline
1355 pos_type last = lastPos(*pit, row);
1357 // None of these should happen, but we're scaredy-cats
1358 if (pos > pit->size()) {
1359 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1362 } else if (pos > last + 1) {
1363 lyxerr << "dont like 2 please report" << endl;
1364 // This shouldn't happen.
1367 } else if (pos < row->pos()) {
1368 lyxerr << "dont like 3 please report" << endl;
1373 // now get the cursors x position
1374 float x = getCursorX(pit, row, pos, last, boundary);
1380 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1381 pos_type pos, pos_type last, bool boundary) const
1383 pos_type cursor_vpos = 0;
1384 double x = rit->x();
1385 double fill_separator = rit->fill_separator();
1386 double fill_hfill = rit->fill_hfill();
1387 double fill_label_hfill = rit->fill_label_hfill();
1388 pos_type const rit_pos = rit->pos();
1391 cursor_vpos = rit_pos;
1392 else if (pos > last && !boundary)
1393 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
1394 ? rit_pos : last + 1;
1395 else if (pos > rit_pos && (pos > last || boundary))
1396 // Place cursor after char at (logical) position pos - 1
1397 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1398 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1400 // Place cursor before char at (logical) position pos
1401 cursor_vpos = (bidi_level(pos) % 2 == 0)
1402 ? log2vis(pos) : log2vis(pos) + 1;
1404 pos_type body_pos = pit->beginningOfBody();
1406 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1409 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1410 pos_type pos = vis2log(vpos);
1411 if (body_pos > 0 && pos == body_pos - 1) {
1412 x += fill_label_hfill +
1413 font_metrics::width(
1414 pit->layout()->labelsep, getLabelFont(pit));
1415 if (pit->isLineSeparator(body_pos - 1))
1416 x -= singleWidth(pit, body_pos - 1);
1419 if (hfillExpansion(*pit, rit, pos)) {
1420 x += singleWidth(pit, pos);
1421 if (pos >= body_pos)
1424 x += fill_label_hfill;
1425 } else if (pit->isSeparator(pos)) {
1426 x += singleWidth(pit, pos);
1427 if (pos >= body_pos)
1428 x += fill_separator;
1430 x += singleWidth(pit, pos);
1436 void LyXText::setCursorIntern(ParagraphList::iterator pit,
1437 pos_type pos, bool setfont, bool boundary)
1439 setCursor(cursor, pit, pos, boundary);
1445 void LyXText::setCurrentFont()
1447 pos_type pos = cursor.pos();
1448 ParagraphList::iterator pit = cursor.par();
1450 if (cursor.boundary() && pos > 0)
1454 if (pos == pit->size())
1456 else // potentional bug... BUG (Lgb)
1457 if (pit->isSeparator(pos)) {
1458 if (pos > cursorRow()->pos() &&
1459 bidi_level(pos) % 2 ==
1460 bidi_level(pos - 1) % 2)
1462 else if (pos + 1 < pit->size())
1467 BufferParams const & bufparams = bv()->buffer()->params();
1468 current_font = pit->getFontSettings(bufparams, pos);
1469 real_current_font = getFont(pit, pos);
1471 if (cursor.pos() == pit->size() &&
1472 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1473 !cursor.boundary()) {
1474 Language const * lang =
1475 pit->getParLanguage(bufparams);
1476 current_font.setLanguage(lang);
1477 current_font.setNumber(LyXFont::OFF);
1478 real_current_font.setLanguage(lang);
1479 real_current_font.setNumber(LyXFont::OFF);
1484 // returns the column near the specified x-coordinate of the row
1485 // x is set to the real beginning of this column
1486 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1487 RowList::iterator rit, int & x, bool & boundary) const
1489 double tmpx = rit->x();
1490 double fill_separator = rit->fill_separator();
1491 double fill_hfill = rit->fill_hfill();
1492 double fill_label_hfill = rit->fill_label_hfill();
1494 pos_type vc = rit->pos();
1495 pos_type last = lastPos(*pit, rit);
1497 LyXLayout_ptr const & layout = pit->layout();
1499 bool left_side = false;
1501 pos_type body_pos = pit->beginningOfBody();
1502 double last_tmpx = tmpx;
1505 (body_pos - 1 > last ||
1506 !pit->isLineSeparator(body_pos - 1)))
1509 // check for empty row
1515 while (vc <= last && tmpx <= x) {
1518 if (body_pos > 0 && c == body_pos - 1) {
1519 tmpx += fill_label_hfill +
1520 font_metrics::width(layout->labelsep, getLabelFont(pit));
1521 if (pit->isLineSeparator(body_pos - 1))
1522 tmpx -= singleWidth(pit, body_pos - 1);
1525 if (hfillExpansion(*pit, rit, c)) {
1526 tmpx += singleWidth(pit, c);
1530 tmpx += fill_label_hfill;
1531 } else if (pit->isSeparator(c)) {
1532 tmpx += singleWidth(pit, c);
1534 tmpx += fill_separator;
1536 tmpx += singleWidth(pit, c);
1541 if ((tmpx + last_tmpx) / 2 > x) {
1546 if (vc > last + 1) // This shouldn't happen.
1550 // This (rtl_support test) is not needed, but gives
1551 // some speedup if rtl_support == false
1552 bool const lastrow = lyxrc.rtl_support
1553 && boost::next(rit) == pit->rows.end();
1555 // If lastrow is false, we don't need to compute
1556 // the value of rtl.
1557 bool const rtl = (lastrow)
1558 ? pit->isRightToLeftPar(bv()->buffer()->params())
1561 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1562 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1564 else if (vc == rit->pos()) {
1566 if (bidi_level(c) % 2 == 1)
1569 c = vis2log(vc - 1);
1570 bool const rtl = (bidi_level(c) % 2 == 1);
1571 if (left_side == rtl) {
1573 boundary = isBoundary(*bv()->buffer(), *pit, c);
1577 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1578 if (bidi_level(last) % 2 == 0)
1579 tmpx -= singleWidth(pit, last);
1581 tmpx += singleWidth(pit, last);
1591 void LyXText::setCursorFromCoordinates(int x, int y)
1593 LyXCursor old_cursor = cursor;
1594 setCursorFromCoordinates(cursor, x, y);
1596 deleteEmptyParagraphMechanism(old_cursor);
1600 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1602 // Get the row first.
1603 ParagraphList::iterator pit;
1604 RowList::iterator rit = getRowNearY(y, pit);
1608 pos_type const column = getColumnNearX(pit, rit, x, bound);
1610 cur.pos(rit->pos() + column);
1612 cur.y(y + rit->baseline());
1614 cur.boundary(bound);
1618 void LyXText::cursorLeft(bool internal)
1620 if (cursor.pos() > 0) {
1621 bool boundary = cursor.boundary();
1622 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1623 if (!internal && !boundary &&
1624 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos() + 1))
1625 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1626 } else if (cursor.par() != ownerParagraphs().begin()) {
1627 // steps into the paragraph above
1628 ParagraphList::iterator pit = boost::prior(cursor.par());
1629 setCursor(pit, pit->size());
1634 void LyXText::cursorRight(bool internal)
1636 bool const at_end = (cursor.pos() == cursor.par()->size());
1637 bool const at_newline = !at_end &&
1638 cursor.par()->isNewline(cursor.pos());
1640 if (!internal && cursor.boundary() && !at_newline)
1641 setCursor(cursor.par(), cursor.pos(), true, false);
1643 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1645 isBoundary(*bv()->buffer(), *cursor.par(), cursor.pos()))
1646 setCursor(cursor.par(), cursor.pos(), true, true);
1647 } else if (boost::next(cursor.par()) != ownerParagraphs().end())
1648 setCursor(boost::next(cursor.par()), 0);
1652 void LyXText::cursorUp(bool selecting)
1655 int x = cursor.x_fix();
1656 int y = cursor.y() - cursorRow()->baseline() - 1;
1657 setCursorFromCoordinates(x, y);
1659 int topy = bv_owner->top_y();
1660 int y1 = cursor.y() - topy;
1663 InsetOld * inset_hit = checkInsetHit(x, y1);
1664 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1665 inset_hit->localDispatch(
1666 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1670 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1671 cursorRow()->baseline() << endl;
1672 setCursorFromCoordinates(cursor.x_fix(),
1673 cursor.y() - cursorRow()->baseline() - 1);
1678 void LyXText::cursorDown(bool selecting)
1681 int x = cursor.x_fix();
1682 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1683 setCursorFromCoordinates(x, y);
1684 if (!selecting && cursorRow() == cursorIRow()) {
1685 int topy = bv_owner->top_y();
1686 int y1 = cursor.y() - topy;
1689 InsetOld * inset_hit = checkInsetHit(x, y1);
1690 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1691 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1692 inset_hit->localDispatch(cmd);
1696 setCursorFromCoordinates(cursor.x_fix(),
1697 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1702 void LyXText::cursorUpParagraph()
1704 if (cursor.pos() > 0)
1705 setCursor(cursor.par(), 0);
1706 else if (cursor.par() != ownerParagraphs().begin())
1707 setCursor(boost::prior(cursor.par()), 0);
1711 void LyXText::cursorDownParagraph()
1713 ParagraphList::iterator par = cursor.par();
1714 ParagraphList::iterator next_par = boost::next(par);
1716 if (next_par != ownerParagraphs().end())
1717 setCursor(next_par, 0);
1719 setCursor(par, par->size());
1723 // fix the cursor `cur' after a characters has been deleted at `where'
1724 // position. Called by deleteEmptyParagraphMechanism
1725 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1727 // if cursor is not in the paragraph where the delete occured,
1729 if (cur.par() != where.par())
1732 // if cursor position is after the place where the delete occured,
1734 if (cur.pos() > where.pos())
1735 cur.pos(cur.pos()-1);
1737 // check also if we don't want to set the cursor on a spot behind the
1738 // pagragraph because we erased the last character.
1739 if (cur.pos() > cur.par()->size())
1740 cur.pos(cur.par()->size());
1742 // recompute row et al. for this cursor
1743 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1747 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1749 // Would be wrong to delete anything if we have a selection.
1750 if (selection.set())
1753 // We allow all kinds of "mumbo-jumbo" when freespacing.
1754 if (old_cursor.par()->isFreeSpacing())
1757 /* Ok I'll put some comments here about what is missing.
1758 I have fixed BackSpace (and thus Delete) to not delete
1759 double-spaces automagically. I have also changed Cut,
1760 Copy and Paste to hopefully do some sensible things.
1761 There are still some small problems that can lead to
1762 double spaces stored in the document file or space at
1763 the beginning of paragraphs. This happens if you have
1764 the cursor between to spaces and then save. Or if you
1765 cut and paste and the selection have a space at the
1766 beginning and then save right after the paste. I am
1767 sure none of these are very hard to fix, but I will
1768 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1769 that I can get some feedback. (Lgb)
1772 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1773 // delete the LineSeparator.
1776 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1777 // delete the LineSeparator.
1780 // If the pos around the old_cursor were spaces, delete one of them.
1781 if (old_cursor.par() != cursor.par()
1782 || old_cursor.pos() != cursor.pos()) {
1784 // Only if the cursor has really moved
1785 if (old_cursor.pos() > 0
1786 && old_cursor.pos() < old_cursor.par()->size()
1787 && old_cursor.par()->isLineSeparator(old_cursor.pos())
1788 && old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
1789 bool erased = old_cursor.par()->erase(old_cursor.pos() - 1);
1790 redoParagraph(old_cursor.par());
1794 #ifdef WITH_WARNINGS
1795 #warning This will not work anymore when we have multiple views of the same buffer
1796 // In this case, we will have to correct also the cursors held by
1797 // other bufferviews. It will probably be easier to do that in a more
1798 // automated way in LyXCursor code. (JMarc 26/09/2001)
1800 // correct all cursors held by the LyXText
1801 fixCursorAfterDelete(cursor, old_cursor);
1802 fixCursorAfterDelete(selection.cursor, old_cursor);
1803 fixCursorAfterDelete(selection.start, old_cursor);
1804 fixCursorAfterDelete(selection.end, old_cursor);
1809 // don't delete anything if this is the ONLY paragraph!
1810 if (ownerParagraphs().size() == 1)
1813 // Do not delete empty paragraphs with keepempty set.
1814 if (old_cursor.par()->allowEmpty())
1817 // only do our magic if we changed paragraph
1818 if (old_cursor.par() == cursor.par())
1821 // record if we have deleted a paragraph
1822 // we can't possibly have deleted a paragraph before this point
1823 bool deleted = false;
1825 if (old_cursor.par()->empty() ||
1826 (old_cursor.par()->size() == 1 &&
1827 old_cursor.par()->isLineSeparator(0))) {
1828 // ok, we will delete something
1829 LyXCursor tmpcursor;
1833 bool selection_position_was_oldcursor_position = (
1834 selection.cursor.par() == old_cursor.par()
1835 && selection.cursor.pos() == old_cursor.pos());
1838 cursor = old_cursor; // that undo can restore the right cursor position
1840 ParagraphList::iterator endpit = boost::next(old_cursor.par());
1841 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1844 recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
1848 ownerParagraphs().erase(old_cursor.par());
1852 setCursorIntern(cursor.par(), cursor.pos());
1854 if (selection_position_was_oldcursor_position) {
1855 // correct selection
1856 selection.cursor = cursor;
1860 if (old_cursor.par()->stripLeadingSpaces()) {
1861 redoParagraph(old_cursor.par());
1863 setCursorIntern(cursor.par(), cursor.pos());
1864 selection.cursor = cursor;
1871 ParagraphList & LyXText::ownerParagraphs() const
1877 bool LyXText::isInInset() const
1879 // Sub-level has non-null bv owner and non-null inset owner.
1880 return inset_owner != 0;
1884 int defaultRowHeight()
1886 LyXFont const font(LyXFont::ALL_SANE);
1887 return int(font_metrics::maxAscent(font)
1888 + font_metrics::maxDescent(font) * 1.5);