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"
45 #include "undo_funcs.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 recordUndo(bv(), Undo::ATOMIC);
286 bv()->updateInset(inset);
290 /* used in setlayout */
291 // Asger is not sure we want to do this...
292 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
295 LyXLayout_ptr const & layout = par.layout();
296 pos_type const psize = par.size();
299 for (pos_type pos = 0; pos < psize; ++pos) {
300 if (pos < par.beginningOfBody())
301 layoutfont = layout->labelfont;
303 layoutfont = layout->font;
305 LyXFont tmpfont = par.getFontSettings(params, pos);
306 tmpfont.reduce(layoutfont);
307 par.setFont(pos, tmpfont);
312 ParagraphList::iterator
313 LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
314 LyXCursor & send_cur,
315 string const & layout)
317 ParagraphList::iterator endpit = boost::next(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 recordUndo(bv(), Undo::ATOMIC, getPar(sstart_cur), boost::prior(undoendpit));
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 recordUndo(bv(), Undo::ATOMIC, start, 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 recordUndo(bv(), Undo::ATOMIC, getPar(selection.start), getPar(selection.end));
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 recordUndo(bv(), Undo::ATOMIC, getPar(selection.start),
791 boost::prior(undoendpit));
794 int tmppit = selection.end.par();
796 while (tmppit != selection.start.par() - 1) {
797 setCursor(tmppit, 0);
799 ParagraphList::iterator const pit = cursorPar();
800 ParagraphParameters & params = pit->params();
802 params.lineTop(line_top);
803 params.lineBottom(line_bottom);
804 params.pagebreakTop(pagebreak_top);
805 params.pagebreakBottom(pagebreak_bottom);
806 params.spaceTop(space_top);
807 params.spaceBottom(space_bottom);
808 params.spacing(spacing);
809 // does the layout allow the new alignment?
810 LyXLayout_ptr const & layout = pit->layout();
812 if (align == LYX_ALIGN_LAYOUT)
813 align = layout->align;
814 if (align & layout->alignpossible) {
815 if (align == layout->align)
816 params.align(LYX_ALIGN_LAYOUT);
820 pit->setLabelWidthString(labelwidthstring);
821 params.noindent(noindent);
825 redoParagraphs(getPar(selection.start), endpit);
828 setCursor(selection.start.par(), selection.start.pos());
829 selection.cursor = cursor;
830 setCursor(selection.end.par(), selection.end.pos());
832 setCursor(tmpcursor.par(), tmpcursor.pos());
834 bv()->updateInset(inset_owner);
840 string expandLabel(LyXTextClass const & textclass,
841 LyXLayout_ptr const & layout, bool appendix)
843 string fmt = appendix ?
844 layout->labelstring_appendix() : layout->labelstring();
846 // handle 'inherited level parts' in 'fmt',
847 // i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
848 size_t const i = fmt.find('@', 0);
849 if (i != string::npos) {
850 size_t const j = fmt.find('@', i + 1);
851 if (j != string::npos) {
852 string parent(fmt, i + 1, j - i - 1);
853 string label = expandLabel(textclass, textclass[parent], appendix);
854 fmt = string(fmt, 0, i) + label + string(fmt, j + 1, string::npos);
858 return textclass.counters().counterLabel(fmt);
862 void incrementItemDepth(ParagraphList::iterator pit,
863 ParagraphList::iterator first_pit)
865 int const cur_labeltype = pit->layout()->labeltype;
867 if (cur_labeltype != LABEL_ENUMERATE &&
868 cur_labeltype != LABEL_ITEMIZE)
871 int const cur_depth = pit->getDepth();
873 ParagraphList::iterator prev_pit = boost::prior(pit);
875 int const prev_depth = prev_pit->getDepth();
876 int const prev_labeltype = prev_pit->layout()->labeltype;
877 if (prev_depth == 0 && cur_depth > 0) {
878 if (prev_labeltype == cur_labeltype) {
879 pit->itemdepth = prev_pit->itemdepth + 1;
882 } else if (prev_depth < cur_depth) {
883 if (prev_labeltype == cur_labeltype) {
884 pit->itemdepth = prev_pit->itemdepth + 1;
887 } else if (prev_depth == cur_depth) {
888 if (prev_labeltype == cur_labeltype) {
889 pit->itemdepth = prev_pit->itemdepth;
893 if (prev_pit == first_pit)
901 void resetEnumCounterIfNeeded(ParagraphList::iterator pit,
902 ParagraphList::iterator firstpit,
908 int const cur_depth = pit->getDepth();
909 ParagraphList::iterator prev_pit = boost::prior(pit);
911 int const prev_depth = prev_pit->getDepth();
912 int const prev_labeltype = prev_pit->layout()->labeltype;
913 if (prev_depth <= cur_depth) {
914 if (prev_labeltype != LABEL_ENUMERATE) {
915 switch (pit->itemdepth) {
917 counters.reset("enumi");
919 counters.reset("enumii");
921 counters.reset("enumiii");
923 counters.reset("enumiv");
929 if (prev_pit == firstpit)
939 // set the counter of a paragraph. This includes the labels
940 void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit)
942 BufferParams const & bufparams = buf.params();
943 LyXTextClass const & textclass = bufparams.getLyXTextClass();
944 LyXLayout_ptr const & layout = pit->layout();
945 ParagraphList::iterator first_pit = ownerParagraphs().begin();
946 Counters & counters = textclass.counters();
951 if (pit == first_pit) {
952 pit->params().appendix(pit->params().startOfAppendix());
954 pit->params().appendix(boost::prior(pit)->params().appendix());
955 if (!pit->params().appendix() &&
956 pit->params().startOfAppendix()) {
957 pit->params().appendix(true);
958 textclass.counters().reset();
961 // Maybe we have to increment the item depth.
962 incrementItemDepth(pit, first_pit);
965 // erase what was there before
966 pit->params().labelString(string());
968 if (layout->margintype == MARGIN_MANUAL) {
969 if (pit->params().labelWidthString().empty())
970 pit->setLabelWidthString(layout->labelstring());
972 pit->setLabelWidthString(string());
975 // is it a layout that has an automatic label?
976 if (layout->labeltype == LABEL_COUNTER) {
977 BufferParams const & bufparams = buf.params();
978 LyXTextClass const & textclass = bufparams.getLyXTextClass();
979 counters.step(layout->counter);
980 string label = expandLabel(textclass, layout, pit->params().appendix());
981 pit->params().labelString(label);
982 } else if (layout->labeltype == LABEL_ITEMIZE) {
983 // At some point of time we should do something more
984 // clever here, like:
985 // pit->params().labelString(
986 // bufparams.user_defined_bullet(pit->itemdepth).getText());
987 // for now, use a simple hardcoded label
989 switch (pit->itemdepth) {
1004 pit->params().labelString(itemlabel);
1005 } else if (layout->labeltype == LABEL_ENUMERATE) {
1006 // Maybe we have to reset the enumeration counter.
1007 resetEnumCounterIfNeeded(pit, first_pit, counters);
1010 // Yes I know this is a really, really! bad solution
1012 string enumcounter = "enum";
1014 switch (pit->itemdepth) {
1023 enumcounter += "iv";
1026 // not a valid enumdepth...
1030 counters.step(enumcounter);
1032 pit->params().labelString(counters.enumLabel(enumcounter));
1033 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
1034 counters.step("bibitem");
1035 int number = counters.value("bibitem");
1036 if (pit->bibitem()) {
1037 pit->bibitem()->setCounter(number);
1038 pit->params().labelString(layout->labelstring());
1040 // In biblio should't be following counters but...
1042 string s = buf.B_(layout->labelstring());
1044 // the caption hack:
1045 if (layout->labeltype == LABEL_SENSITIVE) {
1046 ParagraphList::iterator end = ownerParagraphs().end();
1047 ParagraphList::iterator tmppit = pit;
1050 while (tmppit != end && tmppit->inInset()
1051 // the single '=' is intended below
1052 && (in = tmppit->inInset()->owner()))
1054 if (in->lyxCode() == InsetOld::FLOAT_CODE ||
1055 in->lyxCode() == InsetOld::WRAP_CODE) {
1059 Paragraph const * owner = &ownerPar(buf, in);
1061 for ( ; tmppit != end; ++tmppit)
1062 if (&*tmppit == owner)
1070 if (in->lyxCode() == InsetOld::FLOAT_CODE)
1071 type = static_cast<InsetFloat*>(in)->params().type;
1072 else if (in->lyxCode() == InsetOld::WRAP_CODE)
1073 type = static_cast<InsetWrap*>(in)->params().type;
1075 BOOST_ASSERT(false);
1077 Floating const & fl = textclass.floats().getType(type);
1079 counters.step(fl.type());
1081 // Doesn't work... yet.
1082 s = bformat(_("%1$s #:"), buf.B_(fl.name()));
1084 // par->SetLayout(0);
1085 // s = layout->labelstring;
1086 s = _("Senseless: ");
1089 pit->params().labelString(s);
1095 // Updates all counters. Paragraphs with changed label string will be rebroken
1096 void LyXText::updateCounters()
1099 bv()->buffer()->params().getLyXTextClass().counters().reset();
1101 ParagraphList::iterator beg = ownerParagraphs().begin();
1102 ParagraphList::iterator end = ownerParagraphs().end();
1103 for (ParagraphList::iterator pit = beg; pit != end; ++pit) {
1104 string const oldLabel = pit->params().labelString();
1106 size_t maxdepth = 0;
1108 maxdepth = boost::prior(pit)->getMaxDepthAfter();
1110 if (pit->params().depth() > maxdepth)
1111 pit->params().depth(maxdepth);
1113 // setCounter can potentially change the labelString.
1114 setCounter(*bv()->buffer(), pit);
1116 string const & newLabel = pit->params().labelString();
1118 if (oldLabel != newLabel)
1124 void LyXText::insertInset(InsetOld * inset)
1126 if (!cursorPar()->insetAllowed(inset->lyxCode()))
1128 recordUndo(bv(), Undo::ATOMIC, cursorPar());
1130 cursorPar()->insertInset(cursor.pos(), inset);
1131 // Just to rebreak and refresh correctly.
1132 // The character will not be inserted a second time
1133 insertChar(Paragraph::META_INSET);
1134 // If we enter a highly editable inset the cursor should be before
1135 // the inset. After an Undo LyX tries to call inset->edit(...)
1136 // and fails if the cursor is behind the inset and getInset
1137 // does not return the inset!
1138 if (isHighlyEditableInset(inset))
1144 void LyXText::cutSelection(bool doclear, bool realcut)
1146 // Stuff what we got on the clipboard. Even if there is no selection.
1148 // There is a problem with having the stuffing here in that the
1149 // larger the selection the slower LyX will get. This can be
1150 // solved by running the line below only when the selection has
1151 // finished. The solution used currently just works, to make it
1152 // faster we need to be more clever and probably also have more
1153 // calls to stuffClipboard. (Lgb)
1154 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1156 // This doesn't make sense, if there is no selection
1157 if (!selection.set())
1160 // OK, we have a selection. This is always between selection.start
1161 // and selection.end
1163 // make sure that the depth behind the selection are restored, too
1164 ParagraphList::iterator endpit = boost::next(getPar(selection.end.par()));
1165 ParagraphList::iterator undoendpit = endpit;
1166 ParagraphList::iterator pars_end = ownerParagraphs().end();
1168 if (endpit != pars_end && endpit->getDepth()) {
1169 while (endpit != pars_end && endpit->getDepth()) {
1171 undoendpit = endpit;
1173 } else if (endpit != pars_end) {
1174 // because of parindents etc.
1178 recordUndo(bv(), Undo::DELETE, getPar(selection.start),
1179 boost::prior(undoendpit));
1181 endpit = getPar(selection.end.par());
1182 int endpos = selection.end.pos();
1184 BufferParams const & bufparams = bv()->buffer()->params();
1185 boost::tie(endpit, endpos) = realcut ?
1186 CutAndPaste::cutSelection(bufparams,
1188 getPar(selection.start.par()), endpit,
1189 selection.start.pos(), endpos,
1190 bufparams.textclass,
1192 : CutAndPaste::eraseSelection(bufparams,
1194 getPar(selection.start.par()), endpit,
1195 selection.start.pos(), endpos,
1197 // sometimes necessary
1199 getPar(selection.start.par())->stripLeadingSpaces();
1201 redoParagraphs(getPar(selection.start.par()), boost::next(endpit));
1202 // cutSelection can invalidate the cursor so we need to set
1204 // we prefer the end for when tracking changes
1206 cursor.par(parOffset(endpit));
1208 // need a valid cursor. (Lgb)
1211 setCursor(cursorPar(), cursor.pos());
1212 selection.cursor = cursor;
1217 void LyXText::copySelection()
1219 // stuff the selection onto the X clipboard, from an explicit copy request
1220 bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
1222 // this doesnt make sense, if there is no selection
1223 if (!selection.set())
1226 // ok we have a selection. This is always between selection.start
1227 // and sel_end cursor
1229 // copy behind a space if there is one
1230 while (getPar(selection.start)->size() > selection.start.pos()
1231 && getPar(selection.start)->isLineSeparator(selection.start.pos())
1232 && (selection.start.par() != selection.end.par()
1233 || selection.start.pos() < selection.end.pos()))
1234 selection.start.pos(selection.start.pos() + 1);
1236 CutAndPaste::copySelection(getPar(selection.start.par()),
1237 getPar(selection.end.par()),
1238 selection.start.pos(), selection.end.pos(),
1239 bv()->buffer()->params().textclass);
1243 void LyXText::pasteSelection(size_t sel_index)
1245 // this does not make sense, if there is nothing to paste
1246 if (!CutAndPaste::checkPastePossible())
1249 recordUndo(bv(), Undo::INSERT, cursorPar());
1251 ParagraphList::iterator endpit;
1256 boost::tie(ppp, endpit) =
1257 CutAndPaste::pasteSelection(*bv()->buffer(),
1259 cursorPar(), cursor.pos(),
1260 bv()->buffer()->params().textclass,
1262 bufferErrors(*bv()->buffer(), el);
1263 bv()->showErrorList(_("Paste"));
1265 redoParagraphs(cursorPar(), endpit);
1267 setCursor(cursor.par(), cursor.pos());
1270 selection.cursor = cursor;
1271 setCursor(ppp.first, ppp.second);
1277 void LyXText::setSelectionRange(lyx::pos_type length)
1282 selection.cursor = cursor;
1289 // simple replacing. The font of the first selected character is used
1290 void LyXText::replaceSelectionWithString(string const & str)
1292 recordUndo(bv(), Undo::ATOMIC);
1295 if (!selection.set()) { // create a dummy selection
1296 selection.end = cursor;
1297 selection.start = cursor;
1300 // Get font setting before we cut
1301 pos_type pos = selection.end.pos();
1302 LyXFont const font = getPar(selection.start)
1303 ->getFontSettings(bv()->buffer()->params(),
1304 selection.start.pos());
1306 // Insert the new string
1307 string::const_iterator cit = str.begin();
1308 string::const_iterator end = str.end();
1309 for (; cit != end; ++cit) {
1310 getPar(selection.end)->insertChar(pos, (*cit), font);
1314 // Cut the selection
1315 cutSelection(true, false);
1321 // needed to insert the selection
1322 void LyXText::insertStringAsLines(string const & str)
1324 ParagraphList::iterator pit = cursorPar();
1325 pos_type pos = cursor.pos();
1326 ParagraphList::iterator endpit = boost::next(cursorPar());
1328 recordUndo(bv(), Undo::ATOMIC);
1330 // only to be sure, should not be neccessary
1333 bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
1335 redoParagraphs(cursorPar(), endpit);
1336 setCursor(cursorPar(), cursor.pos());
1337 selection.cursor = cursor;
1338 setCursor(pit, pos);
1343 // turns double-CR to single CR, others where converted into one
1344 // blank. Then InsertStringAsLines is called
1345 void LyXText::insertStringAsParagraphs(string const & str)
1347 string linestr(str);
1348 bool newline_inserted = false;
1349 string::size_type const siz = linestr.length();
1351 for (string::size_type i = 0; i < siz; ++i) {
1352 if (linestr[i] == '\n') {
1353 if (newline_inserted) {
1354 // we know that \r will be ignored by
1355 // InsertStringA. Of course, it is a dirty
1356 // trick, but it works...
1357 linestr[i - 1] = '\r';
1361 newline_inserted = true;
1363 } else if (IsPrintable(linestr[i])) {
1364 newline_inserted = false;
1367 insertStringAsLines(linestr);
1371 void LyXText::setCursor(ParagraphList::iterator pit, pos_type pos)
1373 setCursor(parOffset(pit), pos);
1377 bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont, bool boundary)
1379 LyXCursor old_cursor = cursor;
1380 setCursorIntern(par, pos, setfont, boundary);
1381 return deleteEmptyParagraphMechanism(old_cursor);
1385 void LyXText::redoCursor()
1387 #warning maybe the same for selections?
1388 setCursor(cursor, cursor.par(), cursor.pos(), cursor.boundary());
1392 void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
1393 pos_type pos, bool boundary)
1395 BOOST_ASSERT(par != int(ownerParagraphs().size()));
1399 cur.boundary(boundary);
1401 // no rows, no fun...
1402 if (ownerParagraphs().begin()->rows.empty())
1405 // get the cursor y position in text
1407 ParagraphList::iterator pit = getPar(par);
1408 RowList::iterator row = getRow(pit, pos);
1411 // y is now the beginning of the cursor row
1412 y += row->baseline();
1413 // y is now the cursor baseline
1416 pos_type last = lastPos(*pit, row);
1418 // None of these should happen, but we're scaredy-cats
1419 if (pos > pit->size()) {
1420 lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
1423 } else if (pos > last + 1) {
1424 lyxerr << "dont like 2 please report" << endl;
1425 // This shouldn't happen.
1428 } else if (pos < row->pos()) {
1429 lyxerr << "dont like 3 please report" << endl;
1434 // now get the cursors x position
1435 float x = getCursorX(pit, row, pos, last, boundary);
1441 float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
1442 pos_type pos, pos_type last, bool boundary) const
1444 pos_type cursor_vpos = 0;
1445 double x = rit->x();
1446 double fill_separator = rit->fill_separator();
1447 double fill_hfill = rit->fill_hfill();
1448 double fill_label_hfill = rit->fill_label_hfill();
1449 pos_type const rit_pos = rit->pos();
1452 cursor_vpos = rit_pos;
1453 else if (pos > last && !boundary)
1454 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
1455 ? rit_pos : last + 1;
1456 else if (pos > rit_pos && (pos > last || boundary))
1457 // Place cursor after char at (logical) position pos - 1
1458 cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
1459 ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
1461 // Place cursor before char at (logical) position pos
1462 cursor_vpos = (bidi_level(pos) % 2 == 0)
1463 ? log2vis(pos) : log2vis(pos) + 1;
1465 pos_type body_pos = pit->beginningOfBody();
1467 (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
1470 for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) {
1471 pos_type pos = vis2log(vpos);
1472 if (body_pos > 0 && pos == body_pos - 1) {
1473 x += fill_label_hfill +
1474 font_metrics::width(
1475 pit->layout()->labelsep, getLabelFont(pit));
1476 if (pit->isLineSeparator(body_pos - 1))
1477 x -= singleWidth(pit, body_pos - 1);
1480 if (hfillExpansion(*pit, rit, pos)) {
1481 x += singleWidth(pit, pos);
1482 if (pos >= body_pos)
1485 x += fill_label_hfill;
1486 } else if (pit->isSeparator(pos)) {
1487 x += singleWidth(pit, pos);
1488 if (pos >= body_pos)
1489 x += fill_separator;
1491 x += singleWidth(pit, pos);
1497 void LyXText::setCursorIntern(paroffset_type par,
1498 pos_type pos, bool setfont, bool boundary)
1500 setCursor(cursor, par, pos, boundary);
1506 void LyXText::setCurrentFont()
1508 pos_type pos = cursor.pos();
1509 ParagraphList::iterator pit = cursorPar();
1511 if (cursor.boundary() && pos > 0)
1515 if (pos == pit->size())
1517 else // potentional bug... BUG (Lgb)
1518 if (pit->isSeparator(pos)) {
1519 if (pos > cursorRow()->pos() &&
1520 bidi_level(pos) % 2 ==
1521 bidi_level(pos - 1) % 2)
1523 else if (pos + 1 < pit->size())
1528 BufferParams const & bufparams = bv()->buffer()->params();
1529 current_font = pit->getFontSettings(bufparams, pos);
1530 real_current_font = getFont(pit, pos);
1532 if (cursor.pos() == pit->size() &&
1533 isBoundary(*bv()->buffer(), *pit, cursor.pos()) &&
1534 !cursor.boundary()) {
1535 Language const * lang =
1536 pit->getParLanguage(bufparams);
1537 current_font.setLanguage(lang);
1538 current_font.setNumber(LyXFont::OFF);
1539 real_current_font.setLanguage(lang);
1540 real_current_font.setNumber(LyXFont::OFF);
1545 // returns the column near the specified x-coordinate of the row
1546 // x is set to the real beginning of this column
1547 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
1548 RowList::iterator rit, int & x, bool & boundary) const
1550 double tmpx = rit->x();
1551 double fill_separator = rit->fill_separator();
1552 double fill_hfill = rit->fill_hfill();
1553 double fill_label_hfill = rit->fill_label_hfill();
1555 pos_type vc = rit->pos();
1556 pos_type last = lastPos(*pit, rit);
1558 LyXLayout_ptr const & layout = pit->layout();
1560 bool left_side = false;
1562 pos_type body_pos = pit->beginningOfBody();
1563 double last_tmpx = tmpx;
1566 (body_pos - 1 > last ||
1567 !pit->isLineSeparator(body_pos - 1)))
1570 // check for empty row
1576 while (vc <= last && tmpx <= x) {
1579 if (body_pos > 0 && c == body_pos - 1) {
1580 tmpx += fill_label_hfill +
1581 font_metrics::width(layout->labelsep, getLabelFont(pit));
1582 if (pit->isLineSeparator(body_pos - 1))
1583 tmpx -= singleWidth(pit, body_pos - 1);
1586 if (hfillExpansion(*pit, rit, c)) {
1587 tmpx += singleWidth(pit, c);
1591 tmpx += fill_label_hfill;
1592 } else if (pit->isSeparator(c)) {
1593 tmpx += singleWidth(pit, c);
1595 tmpx += fill_separator;
1597 tmpx += singleWidth(pit, c);
1602 if ((tmpx + last_tmpx) / 2 > x) {
1607 if (vc > last + 1) // This shouldn't happen.
1611 // This (rtl_support test) is not needed, but gives
1612 // some speedup if rtl_support == false
1613 bool const lastrow = lyxrc.rtl_support
1614 && boost::next(rit) == pit->rows.end();
1616 // If lastrow is false, we don't need to compute
1617 // the value of rtl.
1618 bool const rtl = (lastrow)
1619 ? pit->isRightToLeftPar(bv()->buffer()->params())
1622 ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
1623 (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
1625 else if (vc == rit->pos()) {
1627 if (bidi_level(c) % 2 == 1)
1630 c = vis2log(vc - 1);
1631 bool const rtl = (bidi_level(c) % 2 == 1);
1632 if (left_side == rtl) {
1634 boundary = isBoundary(*bv()->buffer(), *pit, c);
1638 if (rit->pos() <= last && c > last && pit->isNewline(last)) {
1639 if (bidi_level(last) % 2 == 0)
1640 tmpx -= singleWidth(pit, last);
1642 tmpx += singleWidth(pit, last);
1652 void LyXText::setCursorFromCoordinates(int x, int y)
1654 LyXCursor old_cursor = cursor;
1655 setCursorFromCoordinates(cursor, x, y);
1657 deleteEmptyParagraphMechanism(old_cursor);
1661 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
1663 // Get the row first.
1664 ParagraphList::iterator pit;
1665 RowList::iterator rit = getRowNearY(y, pit);
1669 pos_type const column = getColumnNearX(pit, rit, x, bound);
1670 cur.par(parOffset(pit));
1671 cur.pos(rit->pos() + column);
1673 cur.y(y + rit->baseline());
1675 cur.boundary(bound);
1679 void LyXText::cursorLeft(bool internal)
1681 if (cursor.pos() > 0) {
1682 bool boundary = cursor.boundary();
1683 setCursor(cursor.par(), cursor.pos() - 1, true, false);
1684 if (!internal && !boundary &&
1685 isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos() + 1))
1686 setCursor(cursor.par(), cursor.pos() + 1, true, true);
1687 } else if (cursor.par() != 0) {
1688 // steps into the paragraph above
1689 setCursor(cursor.par() - 1, boost::prior(cursorPar())->size());
1694 void LyXText::cursorRight(bool internal)
1696 bool const at_end = (cursor.pos() == cursorPar()->size());
1697 bool const at_newline = !at_end &&
1698 cursorPar()->isNewline(cursor.pos());
1700 if (!internal && cursor.boundary() && !at_newline)
1701 setCursor(cursor.par(), cursor.pos(), true, false);
1703 setCursor(cursor.par(), cursor.pos() + 1, true, false);
1705 isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos()))
1706 setCursor(cursor.par(), cursor.pos(), true, true);
1707 } else if (cursor.par() + 1 != int(ownerParagraphs().size()))
1708 setCursor(cursor.par() + 1, 0);
1712 void LyXText::cursorUp(bool selecting)
1715 int x = cursor.x_fix();
1716 int y = cursor.y() - cursorRow()->baseline() - 1;
1717 setCursorFromCoordinates(x, y);
1719 int topy = bv_owner->top_y();
1720 int y1 = cursor.y() - topy;
1723 InsetOld * inset_hit = checkInsetHit(x, y1);
1724 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1725 inset_hit->localDispatch(
1726 FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
1730 lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
1731 cursorRow()->baseline() << endl;
1732 setCursorFromCoordinates(cursor.x_fix(),
1733 cursor.y() - cursorRow()->baseline() - 1);
1738 void LyXText::cursorDown(bool selecting)
1741 int x = cursor.x_fix();
1742 int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
1743 setCursorFromCoordinates(x, y);
1744 if (!selecting && cursorRow() == cursorIRow()) {
1745 int topy = bv_owner->top_y();
1746 int y1 = cursor.y() - topy;
1749 InsetOld * inset_hit = checkInsetHit(x, y1);
1750 if (inset_hit && isHighlyEditableInset(inset_hit)) {
1751 FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
1752 inset_hit->localDispatch(cmd);
1756 setCursorFromCoordinates(cursor.x_fix(),
1757 cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
1762 void LyXText::cursorUpParagraph()
1764 if (cursor.pos() > 0)
1765 setCursor(cursorPar(), 0);
1766 else if (cursorPar() != ownerParagraphs().begin())
1767 setCursor(boost::prior(cursorPar()), 0);
1771 void LyXText::cursorDownParagraph()
1773 ParagraphList::iterator par = cursorPar();
1774 ParagraphList::iterator next_par = boost::next(par);
1776 if (next_par != ownerParagraphs().end())
1777 setCursor(next_par, 0);
1779 setCursor(par, par->size());
1783 // fix the cursor `cur' after a characters has been deleted at `where'
1784 // position. Called by deleteEmptyParagraphMechanism
1785 void LyXText::fixCursorAfterDelete(LyXCursor & cur, LyXCursor const & where)
1787 // if cursor is not in the paragraph where the delete occured,
1789 if (cur.par() != where.par())
1792 // if cursor position is after the place where the delete occured,
1794 if (cur.pos() > where.pos())
1795 cur.pos(cur.pos()-1);
1797 // check also if we don't want to set the cursor on a spot behind the
1798 // pagragraph because we erased the last character.
1799 if (cur.pos() > getPar(cur)->size())
1800 cur.pos(getPar(cur)->size());
1802 // recompute row et al. for this cursor
1803 setCursor(cur, cur.par(), cur.pos(), cur.boundary());
1807 bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
1809 // Would be wrong to delete anything if we have a selection.
1810 if (selection.set())
1813 // Don't do anything if the cursor is invalid
1814 if (old_cursor.par() == -1)
1817 // We allow all kinds of "mumbo-jumbo" when freespacing.
1818 ParagraphList::iterator const old_pit = getPar(old_cursor);
1819 if (old_pit->isFreeSpacing())
1822 /* Ok I'll put some comments here about what is missing.
1823 I have fixed BackSpace (and thus Delete) to not delete
1824 double-spaces automagically. I have also changed Cut,
1825 Copy and Paste to hopefully do some sensible things.
1826 There are still some small problems that can lead to
1827 double spaces stored in the document file or space at
1828 the beginning of paragraphs. This happens if you have
1829 the cursor between to spaces and then save. Or if you
1830 cut and paste and the selection have a space at the
1831 beginning and then save right after the paste. I am
1832 sure none of these are very hard to fix, but I will
1833 put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
1834 that I can get some feedback. (Lgb)
1837 // If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
1838 // delete the LineSeparator.
1841 // If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
1842 // delete the LineSeparator.
1845 // If the pos around the old_cursor were spaces, delete one of them.
1846 if (old_cursor.par() != cursor.par()
1847 || old_cursor.pos() != cursor.pos()) {
1849 // Only if the cursor has really moved
1850 if (old_cursor.pos() > 0
1851 && old_cursor.pos() < old_pit->size()
1852 && old_pit->isLineSeparator(old_cursor.pos())
1853 && old_pit->isLineSeparator(old_cursor.pos() - 1)) {
1854 bool erased = old_pit->erase(old_cursor.pos() - 1);
1855 redoParagraph(old_pit);
1859 #ifdef WITH_WARNINGS
1860 #warning This will not work anymore when we have multiple views of the same buffer
1861 // In this case, we will have to correct also the cursors held by
1862 // other bufferviews. It will probably be easier to do that in a more
1863 // automated way in LyXCursor code. (JMarc 26/09/2001)
1865 // correct all cursors held by the LyXText
1866 fixCursorAfterDelete(cursor, old_cursor);
1867 fixCursorAfterDelete(selection.cursor, old_cursor);
1868 fixCursorAfterDelete(selection.start, old_cursor);
1869 fixCursorAfterDelete(selection.end, old_cursor);
1874 // don't delete anything if this is the ONLY paragraph!
1875 if (ownerParagraphs().size() == 1)
1878 // Do not delete empty paragraphs with keepempty set.
1879 if (old_pit->allowEmpty())
1882 // only do our magic if we changed paragraph
1883 if (old_cursor.par() == cursor.par())
1886 // record if we have deleted a paragraph
1887 // we can't possibly have deleted a paragraph before this point
1888 bool deleted = false;
1890 if (old_pit->empty() ||
1891 (old_pit->size() == 1 && old_pit->isLineSeparator(0))) {
1892 // ok, we will delete something
1893 LyXCursor tmpcursor;
1897 bool selection_position_was_oldcursor_position =
1898 selection.cursor.par() == old_cursor.par()
1899 && selection.cursor.pos() == old_cursor.pos();
1902 cursor = old_cursor; // that undo can restore the right cursor position
1904 ParagraphList::iterator endpit = boost::next(old_pit);
1905 while (endpit != ownerParagraphs().end() && endpit->getDepth())
1908 recordUndo(bv(), Undo::DELETE, old_pit, boost::prior(endpit));
1912 ownerParagraphs().erase(old_pit);
1916 setCursorIntern(cursor.par(), cursor.pos());
1918 if (selection_position_was_oldcursor_position) {
1919 // correct selection
1920 selection.cursor = cursor;
1924 if (old_pit->stripLeadingSpaces()) {
1925 redoParagraph(old_pit);
1927 setCursorIntern(cursor.par(), cursor.pos());
1928 selection.cursor = cursor;
1935 ParagraphList & LyXText::ownerParagraphs() const
1937 return *paragraphs_;
1941 bool LyXText::isInInset() const
1943 // Sub-level has non-null bv owner and non-null inset owner.
1944 return inset_owner != 0;
1948 int defaultRowHeight()
1950 LyXFont const font(LyXFont::ALL_SANE);
1951 return int(font_metrics::maxAscent(font)
1952 + font_metrics::maxDescent(font) * 1.5);