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.h"
43 #include "paragraph_funcs.h"
44 #include "ParagraphParameters.h"
48 #include "frontends/font_metrics.h"
49 #include "frontends/LyXView.h"
51 #include "insets/insetbibitem.h"
52 #include "insets/insetenv.h"
53 #include "insets/insetfloat.h"
54 #include "insets/insetwrap.h"
56 #include "support/lstrings.h"
57 #include "support/textutils.h"
58 #include "support/tostr.h"
59 #include "support/std_sstream.h"
61 #include <boost/tuple/tuple.hpp>
64 using lyx::paroffset_type;
65 using lyx::support::bformat;
68 using std::ostringstream;
72 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
73 ParagraphList & paragraphs)
74 : height(0), width(0), anchor_y_(0),
75 inset_owner(inset), the_locking_inset(0), bv_owner(bv),
76 in_inset_(ininset), paragraphs_(¶graphs)
81 void LyXText::init(BufferView * bview)
85 ParagraphList::iterator const beg = ownerParagraphs().begin();
86 ParagraphList::iterator const end = ownerParagraphs().end();
87 for (ParagraphList::iterator pit = beg; pit != end; ++pit)
95 current_font = getFont(beg, 0);
97 redoParagraphs(beg, end);
98 setCursorIntern(0, 0);
99 selection.cursor = cursor;
105 // Gets the fully instantiated font at a given position in a paragraph
106 // Basically the same routine as Paragraph::getFont() in paragraph.C.
107 // The difference is that this one is used for displaying, and thus we
108 // are allowed to make cosmetic improvements. For instance make footnotes
110 LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const
112 BOOST_ASSERT(pos >= 0);
114 LyXLayout_ptr const & layout = pit->layout();
116 BufferParams const & params = bv()->buffer()->params();
118 // We specialize the 95% common case:
119 if (!pit->getDepth()) {
120 if (layout->labeltype == LABEL_MANUAL
121 && pos < pit->beginningOfBody()) {
123 LyXFont f = pit->getFontSettings(params, pos);
125 pit->inInset()->getDrawFont(f);
126 return f.realize(layout->reslabelfont);
128 LyXFont f = pit->getFontSettings(params, pos);
130 pit->inInset()->getDrawFont(f);
131 return f.realize(layout->resfont);
135 // The uncommon case need not be optimized as much
139 if (pos < pit->beginningOfBody()) {
141 layoutfont = layout->labelfont;
144 layoutfont = layout->font;
147 LyXFont tmpfont = pit->getFontSettings(params, pos);
148 tmpfont.realize(layoutfont);
151 pit->inInset()->getDrawFont(tmpfont);
153 // Realize with the fonts of lesser depth.
154 tmpfont.realize(outerFont(pit, ownerParagraphs()));
155 tmpfont.realize(defaultfont_);
161 LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const
163 LyXLayout_ptr const & layout = pit->layout();
165 if (!pit->getDepth())
166 return layout->resfont;
168 LyXFont font = layout->font;
169 // Realize with the fonts of lesser depth.
170 font.realize(outerFont(pit, ownerParagraphs()));
171 font.realize(defaultfont_);
177 LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
179 LyXLayout_ptr const & layout = pit->layout();
181 if (!pit->getDepth())
182 return layout->reslabelfont;
184 LyXFont font = layout->labelfont;
185 // Realize with the fonts of lesser depth.
186 font.realize(outerFont(pit, ownerParagraphs()));
187 font.realize(defaultfont_);
193 void LyXText::setCharFont(ParagraphList::iterator pit,
194 pos_type pos, LyXFont const & fnt,
197 BufferParams const & params = bv()->buffer()->params();
198 LyXFont font = getFont(pit, pos);
199 font.update(fnt, params.language, toggleall);
200 // Let the insets convert their font
201 if (pit->isInset(pos)) {
202 InsetOld * inset = pit->getInset(pos);
203 if (isEditableInset(inset)) {
204 static_cast<UpdatableInset *>(inset)
205 ->setFont(bv(), fnt, toggleall, true);
209 // Plug through to version below:
210 setCharFont(pit, pos, font);
214 void LyXText::setCharFont(
215 ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
218 LyXLayout_ptr const & layout = pit->layout();
220 // Get concrete layout font to reduce against
223 if (pos < pit->beginningOfBody())
224 layoutfont = layout->labelfont;
226 layoutfont = layout->font;
228 // Realize against environment font information
229 if (pit->getDepth()) {
230 ParagraphList::iterator tp = pit;
231 while (!layoutfont.resolved() &&
232 tp != ownerParagraphs().end() &&
234 tp = outerHook(tp, ownerParagraphs());
235 if (tp != ownerParagraphs().end())
236 layoutfont.realize(tp->layout()->font);
240 layoutfont.realize(defaultfont_);
242 // Now, reduce font against full layout font
243 font.reduce(layoutfont);
245 pit->setFont(pos, font);
249 InsetOld * LyXText::getInset() const
251 ParagraphList::iterator pit = cursorPar();
252 pos_type const pos = cursor.pos();
254 if (pos < pit->size() && pit->isInset(pos)) {
255 return pit->getInset(pos);
261 void LyXText::toggleInset()
263 InsetOld * inset = getInset();
264 // is there an editable inset at cursor position?
265 if (!isEditableInset(inset)) {
266 // No, try to see if we are inside a collapsable inset
267 if (inset_owner && inset_owner->owner()
268 && inset_owner->owner()->isOpen()) {
269 bv()->unlockInset(inset_owner->owner());
270 inset_owner->owner()->close(bv());
271 bv()->getLyXText()->cursorRight(bv());
275 //bv()->owner()->message(inset->editMessage());
277 // do we want to keep this?? (JMarc)
278 if (!isHighlyEditableInset(inset))
279 recUndo(cursor.par());
286 bv()->updateInset(inset);
290 /* used in setlayout */
291 // Asger is not sure we want to do this...
292 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
295 LyXLayout_ptr const & layout = par.layout();
296 pos_type const psize = par.size();
299 for (pos_type pos = 0; pos < psize; ++pos) {
300 if (pos < par.beginningOfBody())
301 layoutfont = layout->labelfont;
303 layoutfont = layout->font;
305 LyXFont tmpfont = par.getFontSettings(params, pos);
306 tmpfont.reduce(layoutfont);
307 par.setFont(pos, tmpfont);
312 ParagraphList::iterator
313 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
314 LyXCursor & send_cur,
315 string const & layout)
317 ParagraphList::iterator endpit = boost::next(getPar(send_cur));
318 ParagraphList::iterator undoendpit = endpit;
319 ParagraphList::iterator pars_end = ownerParagraphs().end();
321 if (endpit != pars_end && endpit->getDepth()) {
322 while (endpit != pars_end && endpit->getDepth()) {
326 } else if (endpit != pars_end) {
327 // because of parindents etc.
331 recUndo(sstart_cur.par(), parOffset(undoendpit) - 1);
333 // ok we have a selection. This is always between sstart_cur
334 // and sel_end cursor
336 ParagraphList::iterator pit = getPar(sstart_cur);
337 ParagraphList::iterator epit = boost::next(getPar(send_cur));
339 BufferParams const & bufparams = bv()->buffer()->params();
340 LyXLayout_ptr const & lyxlayout =
341 bufparams.getLyXTextClass()[layout];
344 pit->applyLayout(lyxlayout);
345 makeFontEntriesLayoutSpecific(bufparams, *pit);
346 pit->params().spaceTop(lyxlayout->fill_top ?
347 VSpace(VSpace::VFILL)
348 : VSpace(VSpace::NONE));
349 pit->params().spaceBottom(lyxlayout->fill_bottom ?
350 VSpace(VSpace::VFILL)
351 : VSpace(VSpace::NONE));
352 if (lyxlayout->margintype == MARGIN_MANUAL)
353 pit->setLabelWidthString(lyxlayout->labelstring());
354 cur.par(std::distance(ownerParagraphs().begin(), pit));
356 } while (pit != epit);
362 // set layout over selection and make a total rebreak of those paragraphs
363 void LyXText::setLayout(string const & layout)
365 LyXCursor tmpcursor = cursor; // store the current cursor
367 // if there is no selection just set the layout
368 // of the current paragraph
369 if (!selection.set()) {
370 selection.start = cursor; // dummy selection
371 selection.end = cursor;
374 // special handling of new environment insets
375 BufferParams const & params = bv()->buffer()->params();
376 LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
377 if (lyxlayout->is_environment) {
378 // move everything in a new environment inset
379 lyxerr << "setting layout " << layout << endl;
380 bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
381 bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
382 bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
383 InsetOld * inset = new InsetEnvironment(params, layout);
384 if (bv()->insertInset(inset)) {
386 //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
393 ParagraphList::iterator endpit = setLayout(cursor, selection.start,
394 selection.end, layout);
395 redoParagraphs(getPar(selection.start), endpit);
397 // we have to reset the selection, because the
398 // geometry could have changed
399 setCursor(selection.start.par(), selection.start.pos(), false);
400 selection.cursor = cursor;
401 setCursor(selection.end.par(), selection.end.pos(), false);
405 setCursor(tmpcursor.par(), tmpcursor.pos(), true);
409 bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
411 ParagraphList::iterator pit = cursorPar();
412 ParagraphList::iterator end = cursorPar();
413 ParagraphList::iterator start = pit;
415 if (selection.set()) {
416 pit = getPar(selection.start);
417 end = getPar(selection.end);
421 ParagraphList::iterator pastend = boost::next(end);
424 recUndo(parOffset(start), parOffset(end));
426 bool changed = false;
428 int prev_after_depth = 0;
429 #warning parlist ... could be nicer ?
430 if (start != ownerParagraphs().begin()) {
431 prev_after_depth = boost::prior(start)->getMaxDepthAfter();
435 int const depth = pit->params().depth();
436 if (type == bv_funcs::INC_DEPTH) {
437 if (depth < prev_after_depth
438 && pit->layout()->labeltype != LABEL_BIBLIO) {
441 pit->params().depth(depth + 1);
446 pit->params().depth(depth - 1);
449 prev_after_depth = pit->getMaxDepthAfter();
461 redoParagraphs(start, pastend);
463 // We need to actually move the text->cursor. I don't
464 // understand why ...
465 LyXCursor tmpcursor = cursor;
467 // we have to reset the visual selection because the
468 // geometry could have changed
469 if (selection.set()) {
470 setCursor(selection.start.par(), selection.start.pos());
471 selection.cursor = cursor;
472 setCursor(selection.end.par(), selection.end.pos());
475 // this handles the counter labels, and also fixes up
476 // depth values for follow-on (child) paragraphs
480 setCursor(tmpcursor.par(), tmpcursor.pos());
486 // set font over selection and make a total rebreak of those paragraphs
487 void LyXText::setFont(LyXFont const & font, bool toggleall)
489 // if there is no selection just set the current_font
490 if (!selection.set()) {
491 // Determine basis font
493 if (cursor.pos() < cursorPar()->beginningOfBody()) {
494 layoutfont = getLabelFont(cursorPar());
496 layoutfont = getLayoutFont(cursorPar());
498 // Update current font
499 real_current_font.update(font,
500 bv()->buffer()->params().language,
503 // Reduce to implicit settings
504 current_font = real_current_font;
505 current_font.reduce(layoutfont);
506 // And resolve it completely
507 real_current_font.realize(layoutfont);
512 LyXCursor tmpcursor = cursor; // store the current cursor
514 // ok we have a selection. This is always between sel_start_cursor
515 // and sel_end cursor
517 recUndo(selection.start.par(), selection.end.par());
519 cursor = selection.start;
520 while (cursor.par() != selection.end.par() ||
521 cursor.pos() < selection.end.pos())
523 if (cursor.pos() < cursorPar()->size()) {
524 // an open footnote should behave like a closed one
525 setCharFont(cursorPar(), cursor.pos(), font, toggleall);
526 cursor.pos(cursor.pos() + 1);
529 cursor.par(cursor.par() + 1);
534 redoParagraph(getPar(selection.start));
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 //BOOST_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(cursorPar(), cursorRow()->pos());
673 void LyXText::cursorEnd()
675 setCursor(cursorPar(), 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(cursorPar(), 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(cursorPar(), 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(getPar(selection.end));
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 recUndo(selection.start.par(), parOffset(undoendpit) - 1);
793 int tmppit = selection.end.par();
795 while (tmppit != selection.start.par() - 1) {
796 setCursor(tmppit, 0);
798 ParagraphList::iterator const pit = cursorPar();
799 ParagraphParameters & params = pit->params();
801 params.lineTop(line_top);
802 params.lineBottom(line_bottom);
803 params.pagebreakTop(pagebreak_top);
804 params.pagebreakBottom(pagebreak_bottom);
805 params.spaceTop(space_top);
806 params.spaceBottom(space_bottom);
807 params.spacing(spacing);
808 // does the layout allow the new alignment?
809 LyXLayout_ptr const & layout = pit->layout();
811 if (align == LYX_ALIGN_LAYOUT)
812 align = layout->align;
813 if (align & layout->alignpossible) {
814 if (align == layout->align)
815 params.align(LYX_ALIGN_LAYOUT);
819 pit->setLabelWidthString(labelwidthstring);
820 params.noindent(noindent);
824 redoParagraphs(getPar(selection.start), endpit);
827 setCursor(selection.start.par(), selection.start.pos());
828 selection.cursor = cursor;
829 setCursor(selection.end.par(), selection.end.pos());
831 setCursor(tmpcursor.par(), tmpcursor.pos());
833 bv()->updateInset(inset_owner);
839 string expandLabel(LyXTextClass const & textclass,
840 LyXLayout_ptr const & layout, bool appendix)
842 string fmt = appendix ?
843 layout->labelstring_appendix() : layout->labelstring();
845 // handle 'inherited level parts' in 'fmt',
846 // i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
847 size_t const i = fmt.find('@', 0);
848 if (i != string::npos) {
849 size_t const j = fmt.find('@', i + 1);
850 if (j != string::npos) {
851 string parent(fmt, i + 1, j - i - 1);
852 string label = expandLabel(textclass, textclass[parent], appendix);
853 fmt = string(fmt, 0, i) + label + string(fmt, j + 1, string::npos);
857 return textclass.counters().counterLabel(fmt);
861 void incrementItemDepth(ParagraphList::iterator pit,
862 ParagraphList::iterator first_pit)
864 int const cur_labeltype = pit->layout()->labeltype;
866 if (cur_labeltype != LABEL_ENUMERATE &&
867 cur_labeltype != LABEL_ITEMIZE)
870 int const cur_depth = pit->getDepth();
872 ParagraphList::iterator prev_pit = boost::prior(pit);
874 int const prev_depth = prev_pit->getDepth();
875 int const prev_labeltype = prev_pit->layout()->labeltype;
876 if (prev_depth == 0 && cur_depth > 0) {
877 if (prev_labeltype == cur_labeltype) {
878 pit->itemdepth = prev_pit->itemdepth + 1;
881 } else if (prev_depth < cur_depth) {
882 if (prev_labeltype == cur_labeltype) {
883 pit->itemdepth = prev_pit->itemdepth + 1;
886 } else if (prev_depth == cur_depth) {
887 if (prev_labeltype == cur_labeltype) {
888 pit->itemdepth = prev_pit->itemdepth;
892 if (prev_pit == first_pit)
900 void resetEnumCounterIfNeeded(ParagraphList::iterator pit,
901 ParagraphList::iterator firstpit,
907 int const cur_depth = pit->getDepth();
908 ParagraphList::iterator prev_pit = boost::prior(pit);
910 int const prev_depth = prev_pit->getDepth();
911 int const prev_labeltype = prev_pit->layout()->labeltype;
912 if (prev_depth <= cur_depth) {
913 if (prev_labeltype != LABEL_ENUMERATE) {
914 switch (pit->itemdepth) {
916 counters.reset("enumi");
918 counters.reset("enumii");
920 counters.reset("enumiii");
922 counters.reset("enumiv");
928 if (prev_pit == firstpit)
938 // set the counter of a paragraph. This includes the labels
939 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
941 BufferParams const & bufparams = buf.params();
942 LyXTextClass const & textclass = bufparams.getLyXTextClass();
943 LyXLayout_ptr const & layout = pit->layout();
944 ParagraphList::iterator first_pit = ownerParagraphs().begin();
945 Counters & counters = textclass.counters();
950 if (pit == first_pit) {
951 pit->params().appendix(pit->params().startOfAppendix());
953 pit->params().appendix(boost::prior(pit)->params().appendix());
954 if (!pit->params().appendix() &&
955 pit->params().startOfAppendix()) {
956 pit->params().appendix(true);
957 textclass.counters().reset();
960 // Maybe we have to increment the item depth.
961 incrementItemDepth(pit, first_pit);
964 // erase what was there before
965 pit->params().labelString(string());
967 if (layout->margintype == MARGIN_MANUAL) {
968 if (pit->params().labelWidthString().empty())
969 pit->setLabelWidthString(layout->labelstring());
971 pit->setLabelWidthString(string());
974 // is it a layout that has an automatic label?
975 if (layout->labeltype == LABEL_COUNTER) {
976 BufferParams const & bufparams = buf.params();
977 LyXTextClass const & textclass = bufparams.getLyXTextClass();
978 counters.step(layout->counter);
979 string label = expandLabel(textclass, layout, pit->params().appendix());
980 pit->params().labelString(label);
981 } else if (layout->labeltype == LABEL_ITEMIZE) {
982 // At some point of time we should do something more
983 // clever here, like:
984 // pit->params().labelString(
985 // bufparams.user_defined_bullet(pit->itemdepth).getText());
986 // for now, use a simple hardcoded label
988 switch (pit->itemdepth) {
1003 pit->params().labelString(itemlabel);
1004 } else if (layout->labeltype == LABEL_ENUMERATE) {
1005 // Maybe we have to reset the enumeration counter.
1006 resetEnumCounterIfNeeded(pit, first_pit, counters);
1009 // Yes I know this is a really, really! bad solution
1011 string enumcounter = "enum";
1013 switch (pit->itemdepth) {
1022 enumcounter += "iv";
1025 // not a valid enumdepth...
1029 counters.step(enumcounter);
1031 pit->params().labelString(counters.enumLabel(enumcounter));
1032 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
1033 counters.step("bibitem");
1034 int number = counters.value("bibitem");
1035 if (pit->bibitem()) {
1036 pit->bibitem()->setCounter(number);
1037 pit->params().labelString(layout->labelstring());
1039 // In biblio should't be following counters but...
1041 string s = buf.B_(layout->labelstring());
1043 // the caption hack:
1044 if (layout->labeltype == LABEL_SENSITIVE) {
1045 ParagraphList::iterator end = ownerParagraphs().end();
1046 ParagraphList::iterator tmppit = pit;
1049 while (tmppit != end && tmppit->inInset()
1050 // the single '=' is intended below
1051 && (in = tmppit->inInset()->owner()))
1053 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
1054 in->lyxCode() == InsetOld::WRAP_CODE) {
1058 Paragraph const * owner = &ownerPar(buf, in);
1060 for ( ; tmppit != end; ++tmppit)
1061 if (&*tmppit == owner)
1069 if (in->lyxCode() == InsetOld::FLOAT_CODE)
1070 type = static_cast<InsetFloat*>(in)->params().type;
1071 else if (in->lyxCode() == InsetOld::WRAP_CODE)
1072 type = static_cast<InsetWrap*>(in)->params().type;
1074 BOOST_ASSERT(false);
1076 Floating const & fl = textclass.floats().getType(type);
1078 counters.step(fl.type());
1080 // Doesn't work... yet.
1081 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1083 // par->SetLayout(0);
1084 // s = layout->labelstring;
1085 s = _("Senseless: ");
1088 pit->params().labelString(s);
1094 // Updates all counters. Paragraphs with changed label string will be rebroken
1095 void LyXText::updateCounters()
1098 bv()->buffer()->params().getLyXTextClass().counters().reset();
1100 ParagraphList::iterator beg = ownerParagraphs().begin();
1101 ParagraphList::iterator end = ownerParagraphs().end();
1102 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1103 string const oldLabel = pit->params().labelString();
1105 size_t maxdepth = 0;
1107 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1109 if (pit->params().depth() > maxdepth)
1110 pit->params().depth(maxdepth);
1112 // setCounter can potentially change the labelString.
1113 setCounter(*bv()->buffer(), pit);
1115 string const & newLabel = pit->params().labelString();
1117 if (oldLabel != newLabel)
1123 void LyXText::insertInset(InsetOld * inset)
1125 if (!cursorPar()->insetAllowed(inset->lyxCode()))
1127 recUndo(cursor.par());
1129 cursorPar()->insertInset(cursor.pos(), inset);
1130 // Just to rebreak and refresh correctly.
1131 // The character will not be inserted a second time
1132 insertChar(Paragraph::META_INSET);
1133 // If we enter a highly editable inset the cursor should be before
1134 // the inset. After an Undo LyX tries to call inset->edit(...)
1135 // and fails if the cursor is behind the inset and getInset
1136 // does not return the inset!
1137 if (isHighlyEditableInset(inset))
1143 void LyXText::cutSelection(bool doclear, bool realcut)
1145 // Stuff what we got on the clipboard. Even if there is no selection.
1147 // There is a problem with having the stuffing here in that the
1148 // larger the selection the slower LyX will get. This can be
1149 // solved by running the line below only when the selection has
1150 // finished. The solution used currently just works, to make it
1151 // faster we need to be more clever and probably also have more
1152 // calls to stuffClipboard. (Lgb)
1153 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1155 // This doesn't make sense, if there is no selection
1156 if (!selection.set())
1159 // OK, we have a selection. This is always between selection.start
1160 // and selection.end
1162 // make sure that the depth behind the selection are restored, too
1163 ParagraphList::iterator endpit = boost::next(getPar(selection.end.par()));
1164 ParagraphList::iterator undoendpit = endpit;
1165 ParagraphList::iterator pars_end = ownerParagraphs().end();
1167 if (endpit != pars_end && endpit->getDepth()) {
1168 while (endpit != pars_end && endpit->getDepth()) {
1170 undoendpit = endpit;
1172 } else if (endpit != pars_end) {
1173 // because of parindents etc.
1177 recUndo(selection.start.par(), parOffset(undoendpit) - 1);
1179 endpit = getPar(selection.end.par());
1180 int endpos = selection.end.pos();
1182 BufferParams const & bufparams = bv()->buffer()->params();
1183 boost::tie(endpit, endpos) = realcut ?
1184 CutAndPaste::cutSelection(bufparams,
1186 getPar(selection.start.par()), endpit,
1187 selection.start.pos(), endpos,
1188 bufparams.textclass,
1190 : CutAndPaste::eraseSelection(bufparams,
1192 getPar(selection.start.par()), endpit,
1193 selection.start.pos(), endpos,
1195 // sometimes necessary
1197 getPar(selection.start.par())->stripLeadingSpaces();
1199 redoParagraphs(getPar(selection.start.par()), boost::next(endpit));
1200 // cutSelection can invalidate the cursor so we need to set
1202 // we prefer the end for when tracking changes
1204 cursor.par(parOffset(endpit));
1206 // need a valid cursor. (Lgb)
1209 setCursor(cursorPar(), cursor.pos());
1210 selection.cursor = cursor;
1215 void LyXText::copySelection()
1217 // stuff the selection onto the X clipboard, from an explicit copy request
1218 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1220 // this doesnt make sense, if there is no selection
1221 if (!selection.set())
1224 // ok we have a selection. This is always between selection.start
1225 // and sel_end cursor
1227 // copy behind a space if there is one
1228 while (getPar(selection.start)->size() > selection.start.pos()
1229 && getPar(selection.start)->isLineSeparator(selection.start.pos())
1230 && (selection.start.par() != selection.end.par()
1231 || selection.start.pos() < selection.end.pos()))
1232 selection.start.pos(selection.start.pos() + 1);
1234 CutAndPaste::copySelection(getPar(selection.start.par()),
1235 getPar(selection.end.par()),
1236 selection.start.pos(), selection.end.pos(),
1237 bv()->buffer()->params().textclass);
1241 void LyXText::pasteSelection(size_t sel_index)
1243 // this does not make sense, if there is nothing to paste
1244 if (!CutAndPaste::checkPastePossible())
1247 recUndo(cursor.par());
1249 ParagraphList::iterator endpit;
1254 boost::tie(ppp, endpit) =
1255 CutAndPaste::pasteSelection(*bv()->buffer(),
1257 cursorPar(), cursor.pos(),
1258 bv()->buffer()->params().textclass,
1260 bufferErrors(*bv()->buffer(), el);
1261 bv()->showErrorList(_("Paste"));
1263 redoParagraphs(cursorPar(), endpit);
1265 setCursor(cursor.par(), cursor.pos());
1268 selection.cursor = cursor;
1269 setCursor(ppp.first, ppp.second);
1275 void LyXText::setSelectionRange(lyx::pos_type length)
1280 selection.cursor = cursor;
1287 // simple replacing. The font of the first selected character is used
1288 void LyXText::replaceSelectionWithString(string const & str)
1290 recUndo(cursor.par());
1293 if (!selection.set()) { // create a dummy selection
1294 selection.end = cursor;
1295 selection.start = cursor;
1298 // Get font setting before we cut
1299 pos_type pos = selection.end.pos();
1300 LyXFont const font = getPar(selection.start)
1301 ->getFontSettings(bv()->buffer()->params(),
1302 selection.start.pos());
1304 // Insert the new string
1305 string::const_iterator cit = str.begin();
1306 string::const_iterator end = str.end();
1307 for (; cit != end; ++cit) {
1308 getPar(selection.end)->insertChar(pos, (*cit), font);
1312 // Cut the selection
1313 cutSelection(true, false);
1319 // needed to insert the selection
1320 void LyXText::insertStringAsLines(string const & str)
1322 ParagraphList::iterator pit = cursorPar();
1323 pos_type pos = cursor.pos();
1324 ParagraphList::iterator endpit = boost::next(cursorPar());
1326 recUndo(cursor.par());
1328 // only to be sure, should not be neccessary
1331 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1333 redoParagraphs(cursorPar(), endpit);
1334 setCursor(cursorPar(), cursor.pos());
1335 selection.cursor = cursor;
1336 setCursor(pit, pos);
1341 // turns double-CR to single CR, others where converted into one
1342 // blank. Then InsertStringAsLines is called
1343 void LyXText::insertStringAsParagraphs(string const & str)
1345 string linestr(str);
1346 bool newline_inserted = false;
1347 string::size_type const siz = linestr.length();
1349 for (string::size_type i = 0; i < siz; ++i) {
1350 if (linestr[i] == '\n') {
1351 if (newline_inserted) {
1352 // we know that \r will be ignored by
1353 // InsertStringA. Of course, it is a dirty
1354 // trick, but it works...
1355 linestr[i - 1] = '\r';
1359 newline_inserted = true;
1361 } else if (IsPrintable(linestr[i])) {
1362 newline_inserted = false;
1365 insertStringAsLines(linestr);
1369 void LyXText::setCursor(ParagraphList::iterator pit, pos_type pos)
1371 setCursor(parOffset(pit), pos);
1375 bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont, bool boundary)
1377 LyXCursor old_cursor = cursor;
1378 setCursorIntern(par, pos, setfont, boundary);
1379 return deleteEmptyParagraphMechanism(old_cursor);
1383 void LyXText::redoCursor()
1385 #warning maybe the same for selections?
1386 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1390 void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
1391 pos_type pos, bool boundary)
1393 BOOST_ASSERT(par != int(ownerParagraphs().size()));
1397 cur.boundary(boundary);
1399 // no rows, no fun...
1400 if (ownerParagraphs().begin()->rows.empty())
1403 // get the cursor y position in text
1405 ParagraphList::iterator pit = getPar(par);
1406 RowList::iterator row = getRow(pit, pos);
1409 // y is now the beginning of the cursor row
1410 y += row->baseline();
1411 // y is now the cursor baseline
1414 pos_type last = lastPos(*pit, row);
1416 // None of these should happen, but we're scaredy-cats
1417 if (pos > pit->size()) {
1418 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1421 } else if (pos > last + 1) {
1422 lyxerr << "dont like 2 please report" << endl;
1423 // This shouldn't happen.
1426 } else if (pos < row->pos()) {
1427 lyxerr << "dont like 3 please report" << endl;
1432 // now get the cursors x position
1433 float x = getCursorX(pit, row, pos, last, boundary);
1439 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1440 pos_type pos, pos_type last, bool boundary) const
1442 pos_type cursor_vpos = 0;
1443 double x = rit->x();
1444 double fill_separator = rit->fill_separator();
1445 double fill_hfill = rit->fill_hfill();
1446 double fill_label_hfill = rit->fill_label_hfill();
1447 pos_type const rit_pos = rit->pos();
1450 cursor_vpos = rit_pos;
1451 else if (pos > last && !boundary)
1452 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
1453 ? rit_pos : last + 1;
1454 else if (pos > rit_pos && (pos > last || boundary))
1455 // Place cursor after char at (logical) position pos - 1
1456 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1457 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1459 // Place cursor before char at (logical) position pos
1460 cursor_vpos = (bidi_level(pos) % 2 == 0)
1461 ? log2vis(pos) : log2vis(pos) + 1;
1463 pos_type body_pos = pit->beginningOfBody();
1465 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1468 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1469 pos_type pos = vis2log(vpos);
1470 if (body_pos > 0 && pos == body_pos - 1) {
1471 x += fill_label_hfill +
1472 font_metrics::width(
1473 pit->layout()->labelsep, getLabelFont(pit));
1474 if (pit->isLineSeparator(body_pos - 1))
1475 x -= singleWidth(pit, body_pos - 1);
1478 if (hfillExpansion(*pit, rit, pos)) {
1479 x += singleWidth(pit, pos);
1480 if (pos >= body_pos)
1483 x += fill_label_hfill;
1484 } else if (pit->isSeparator(pos)) {
1485 x += singleWidth(pit, pos);
1486 if (pos >= body_pos)
1487 x += fill_separator;
1489 x += singleWidth(pit, pos);
1495 void LyXText::setCursorIntern(paroffset_type par,
1496 pos_type pos, bool setfont, bool boundary)
1498 setCursor(cursor, par, pos, boundary);
1504 void LyXText::setCurrentFont()
1506 pos_type pos = cursor.pos();
1507 ParagraphList::iterator pit = cursorPar();
1509 if (cursor.boundary() && pos > 0)
1513 if (pos == pit->size())
1515 else // potentional bug... BUG (Lgb)
1516 if (pit->isSeparator(pos)) {
1517 if (pos > cursorRow()->pos() &&
1518 bidi_level(pos) % 2 ==
1519 bidi_level(pos - 1) % 2)
1521 else if (pos + 1 < pit->size())
1526 BufferParams const & bufparams = bv()->buffer()->params();
1527 current_font = pit->getFontSettings(bufparams, pos);
1528 real_current_font = getFont(pit, pos);
1530 if (cursor.pos() == pit->size() &&
1531 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1532 !cursor.boundary()) {
1533 Language const * lang =
1534 pit->getParLanguage(bufparams);
1535 current_font.setLanguage(lang);
1536 current_font.setNumber(LyXFont::OFF);
1537 real_current_font.setLanguage(lang);
1538 real_current_font.setNumber(LyXFont::OFF);
1543 // returns the column near the specified x-coordinate of the row
1544 // x is set to the real beginning of this column
1545 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1546 RowList::iterator rit, int & x, bool & boundary) const
1548 double tmpx = rit->x();
1549 double fill_separator = rit->fill_separator();
1550 double fill_hfill = rit->fill_hfill();
1551 double fill_label_hfill = rit->fill_label_hfill();
1553 pos_type vc = rit->pos();
1554 pos_type last = lastPos(*pit, rit);
1556 LyXLayout_ptr const & layout = pit->layout();
1558 bool left_side = false;
1560 pos_type body_pos = pit->beginningOfBody();
1561 double last_tmpx = tmpx;
1564 (body_pos - 1 > last ||
1565 !pit->isLineSeparator(body_pos - 1)))
1568 // check for empty row
1574 while (vc <= last && tmpx <= x) {
1577 if (body_pos > 0 && c == body_pos - 1) {
1578 tmpx += fill_label_hfill +
1579 font_metrics::width(layout->labelsep, getLabelFont(pit));
1580 if (pit->isLineSeparator(body_pos - 1))
1581 tmpx -= singleWidth(pit, body_pos - 1);
1584 if (hfillExpansion(*pit, rit, c)) {
1585 tmpx += singleWidth(pit, c);
1589 tmpx += fill_label_hfill;
1590 } else if (pit->isSeparator(c)) {
1591 tmpx += singleWidth(pit, c);
1593 tmpx += fill_separator;
1595 tmpx += singleWidth(pit, c);
1600 if ((tmpx + last_tmpx) / 2 > x) {
1605 if (vc > last + 1) // This shouldn't happen.
1609 // This (rtl_support test) is not needed, but gives
1610 // some speedup if rtl_support == false
1611 bool const lastrow = lyxrc.rtl_support
1612 && boost::next(rit) == pit->rows.end();
1614 // If lastrow is false, we don't need to compute
1615 // the value of rtl.
1616 bool const rtl = (lastrow)
1617 ? pit->isRightToLeftPar(bv()->buffer()->params())
1620 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1621 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1623 else if (vc == rit->pos()) {
1625 if (bidi_level(c) % 2 == 1)
1628 c = vis2log(vc - 1);
1629 bool const rtl = (bidi_level(c) % 2 == 1);
1630 if (left_side == rtl) {
1632 boundary = isBoundary(*bv()->buffer(), *pit, c);
1636 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1637 if (bidi_level(last) % 2 == 0)
1638 tmpx -= singleWidth(pit, last);
1640 tmpx += singleWidth(pit, last);
1650 void LyXText::setCursorFromCoordinates(int x, int y)
1652 LyXCursor old_cursor = cursor;
1653 setCursorFromCoordinates(cursor, x, y);
1655 deleteEmptyParagraphMechanism(old_cursor);
1659 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1661 // Get the row first.
1662 ParagraphList::iterator pit;
1663 RowList::iterator rit = getRowNearY(y, pit);
1667 pos_type const column = getColumnNearX(pit, rit, x, bound);
1668 cur.par(parOffset(pit));
1669 cur.pos(rit->pos() + column);
1671 cur.y(y + rit->baseline());
1673 cur.boundary(bound);
1677 void LyXText::cursorLeft(bool internal)
1679 if (cursor.pos() > 0) {
1680 bool boundary = cursor.boundary();
1681 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1682 if (!internal && !boundary &&
1683 isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos() + 1))
1684 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1685 } else if (cursor.par() != 0) {
1686 // steps into the paragraph above
1687 setCursor(cursor.par() - 1, boost::prior(cursorPar())->size());
1692 void LyXText::cursorRight(bool internal)
1694 bool const at_end = (cursor.pos() == cursorPar()->size());
1695 bool const at_newline = !at_end &&
1696 cursorPar()->isNewline(cursor.pos());
1698 if (!internal && cursor.boundary() && !at_newline)
1699 setCursor(cursor.par(), cursor.pos(), true, false);
1701 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1703 isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos()))
1704 setCursor(cursor.par(), cursor.pos(), true, true);
1705 } else if (cursor.par() + 1 != int(ownerParagraphs().size()))
1706 setCursor(cursor.par() + 1, 0);
1710 void LyXText::cursorUp(bool selecting)
1713 int x = cursor.x_fix();
1714 int y = cursor.y() - cursorRow()->baseline() - 1;
1715 setCursorFromCoordinates(x, y);
1717 int topy = bv_owner->top_y();
1718 int y1 = cursor.y() - topy;
1721 InsetOld * inset_hit = checkInsetHit(x, y1);
1722 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1723 inset_hit->localDispatch(
1724 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1728 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1729 cursorRow()->baseline() << endl;
1730 setCursorFromCoordinates(cursor.x_fix(),
1731 cursor.y() - cursorRow()->baseline() - 1);
1736 void LyXText::cursorDown(bool selecting)
1739 int x = cursor.x_fix();
1740 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1741 setCursorFromCoordinates(x, y);
1742 if (!selecting && cursorRow() == cursorIRow()) {
1743 int topy = bv_owner->top_y();
1744 int y1 = cursor.y() - topy;
1747 InsetOld * inset_hit = checkInsetHit(x, y1);
1748 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1749 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1750 inset_hit->localDispatch(cmd);
1754 setCursorFromCoordinates(cursor.x_fix(),
1755 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1760 void LyXText::cursorUpParagraph()
1762 if (cursor.pos() > 0)
1763 setCursor(cursorPar(), 0);
1764 else if (cursorPar() != ownerParagraphs().begin())
1765 setCursor(boost::prior(cursorPar()), 0);
1769 void LyXText::cursorDownParagraph()
1771 ParagraphList::iterator par = cursorPar();
1772 ParagraphList::iterator next_par = boost::next(par);
1774 if (next_par != ownerParagraphs().end())
1775 setCursor(next_par, 0);
1777 setCursor(par, par->size());
1781 // fix the cursor `cur' after a characters has been deleted at `where'
1782 // position. Called by deleteEmptyParagraphMechanism
1783 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1785 // if cursor is not in the paragraph where the delete occured,
1787 if (cur.par() != where.par())
1790 // if cursor position is after the place where the delete occured,
1792 if (cur.pos() > where.pos())
1793 cur.pos(cur.pos()-1);
1795 // check also if we don't want to set the cursor on a spot behind the
1796 // pagragraph because we erased the last character.
1797 if (cur.pos() > getPar(cur)->size())
1798 cur.pos(getPar(cur)->size());
1800 // recompute row et al. for this cursor
1801 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1805 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1807 // Would be wrong to delete anything if we have a selection.
1808 if (selection.set())
1811 // Don't do anything if the cursor is invalid
1812 if (old_cursor.par() == -1)
1815 // We allow all kinds of "mumbo-jumbo" when freespacing.
1816 ParagraphList::iterator const old_pit = getPar(old_cursor);
1817 if (old_pit->isFreeSpacing())
1820 /* Ok I'll put some comments here about what is missing.
1821 I have fixed BackSpace (and thus Delete) to not delete
1822 double-spaces automagically. I have also changed Cut,
1823 Copy and Paste to hopefully do some sensible things.
1824 There are still some small problems that can lead to
1825 double spaces stored in the document file or space at
1826 the beginning of paragraphs. This happens if you have
1827 the cursor between to spaces and then save. Or if you
1828 cut and paste and the selection have a space at the
1829 beginning and then save right after the paste. I am
1830 sure none of these are very hard to fix, but I will
1831 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1832 that I can get some feedback. (Lgb)
1835 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1836 // delete the LineSeparator.
1839 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1840 // delete the LineSeparator.
1843 // If the pos around the old_cursor were spaces, delete one of them.
1844 if (old_cursor.par() != cursor.par()
1845 || old_cursor.pos() != cursor.pos()) {
1847 // Only if the cursor has really moved
1848 if (old_cursor.pos() > 0
1849 && old_cursor.pos() < old_pit->size()
1850 && old_pit->isLineSeparator(old_cursor.pos())
1851 && old_pit->isLineSeparator(old_cursor.pos() - 1)) {
1852 bool erased = old_pit->erase(old_cursor.pos() - 1);
1853 redoParagraph(old_pit);
1857 #ifdef WITH_WARNINGS
1858 #warning This will not work anymore when we have multiple views of the same buffer
1859 // In this case, we will have to correct also the cursors held by
1860 // other bufferviews. It will probably be easier to do that in a more
1861 // automated way in LyXCursor code. (JMarc 26/09/2001)
1863 // correct all cursors held by the LyXText
1864 fixCursorAfterDelete(cursor, old_cursor);
1865 fixCursorAfterDelete(selection.cursor, old_cursor);
1866 fixCursorAfterDelete(selection.start, old_cursor);
1867 fixCursorAfterDelete(selection.end, old_cursor);
1872 // don't delete anything if this is the ONLY paragraph!
1873 if (ownerParagraphs().size() == 1)
1876 // Do not delete empty paragraphs with keepempty set.
1877 if (old_pit->allowEmpty())
1880 // only do our magic if we changed paragraph
1881 if (old_cursor.par() == cursor.par())
1884 // record if we have deleted a paragraph
1885 // we can't possibly have deleted a paragraph before this point
1886 bool deleted = false;
1888 if (old_pit->empty() ||
1889 (old_pit->size() == 1 && old_pit->isLineSeparator(0))) {
1890 // ok, we will delete something
1891 LyXCursor tmpcursor;
1895 bool selection_position_was_oldcursor_position =
1896 selection.cursor.par() == old_cursor.par()
1897 && selection.cursor.pos() == old_cursor.pos();
1900 cursor = old_cursor; // that undo can restore the right cursor position
1902 ParagraphList::iterator endpit = boost::next(old_pit);
1903 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1906 recUndo(parOffset(old_pit), parOffset(endpit) - 1);
1910 ownerParagraphs().erase(old_pit);
1914 setCursorIntern(cursor.par(), cursor.pos());
1916 if (selection_position_was_oldcursor_position) {
1917 // correct selection
1918 selection.cursor = cursor;
1922 if (old_pit->stripLeadingSpaces()) {
1923 redoParagraph(old_pit);
1925 setCursorIntern(cursor.par(), cursor.pos());
1926 selection.cursor = cursor;
1933 ParagraphList & LyXText::ownerParagraphs() const
1935 return *paragraphs_;
1939 void LyXText::recUndo(paroffset_type first, paroffset_type last) const
1941 recordUndo(Undo::ATOMIC, this, first, last);
1945 void LyXText::recUndo(lyx::paroffset_type par) const
1947 recordUndo(Undo::ATOMIC, this, par, par);
1951 bool LyXText::isInInset() const
1953 // Sub-level has non-null bv owner and non-null inset owner.
1954 return inset_owner != 0;
1958 int defaultRowHeight()
1960 LyXFont const font(LyXFont::ALL_SANE);
1961 return int(font_metrics::maxAscent(font)
1962 + font_metrics::maxDescent(font) * 1.5);