3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
13 #include "insettext.h"
16 #include "BufferView.h"
17 #include "bufferview_funcs.h"
18 #include "CutAndPaste.h"
20 #include "dimension.h"
21 #include "funcrequest.h"
23 #include "errorlist.h"
25 #include "LaTeXFeatures.h"
29 #include "lyxcursor.h"
35 #include "paragraph.h"
36 #include "ParagraphParameters.h"
37 #include "trans_mgr.h"
38 #include "undo_funcs.h"
39 #include "WordLangTuple.h"
40 #include "paragraph_funcs.h"
42 #include "rowpainter.h"
43 #include "insetnewline.h"
44 #include "metricsinfo.h"
46 #include "frontends/Alert.h"
47 #include "frontends/Dialogs.h"
48 #include "frontends/font_metrics.h"
49 #include "frontends/LyXView.h"
50 #include "frontends/Painter.h"
51 #include "frontends/screen.h"
53 #include "support/textutils.h"
54 #include "support/LAssert.h"
55 #include "support/lstrings.h"
56 #include "support/lyxalgo.h" // lyx::count
58 #include <boost/bind.hpp>
75 using namespace lyx::support;
76 using namespace lyx::graphics;
77 using namespace bv_funcs;
80 using lyx::textclass_type;
83 // we should get rid of these (Andre')
85 void InsetText::saveLyXTextState() const
87 // check if my paragraphs are still valid
88 ParagraphList::iterator it = const_cast<ParagraphList&>(paragraphs).begin();
89 ParagraphList::iterator end = const_cast<ParagraphList&>(paragraphs).end();
90 for (; it != end; ++it)
91 if (it == text_.cursor.par())
94 if (it != end && text_.cursor.pos() <= it->size())
95 sstate = text_; // slicing intended
97 sstate.cursor.par(end);
101 void InsetText::restoreLyXTextState() const
103 if (sstate.cursor.par() == const_cast<ParagraphList&>(paragraphs).end())
106 text_.selection.set(true);
107 // at this point just to avoid the DEPM when setting the cursor
108 text_.selection.mark(sstate.selection.mark());
109 if (sstate.selection.set()) {
110 text_.setCursor(sstate.selection.start.par(),
111 sstate.selection.start.pos(),
112 true, sstate.selection.start.boundary());
113 text_.selection.cursor = text_.cursor;
114 text_.setCursor(sstate.selection.end.par(), sstate.selection.end.pos(),
115 true, sstate.selection.end.boundary());
116 text_.setSelection();
117 text_.setCursor(sstate.cursor.par(), sstate.cursor.pos());
119 text_.setCursor(sstate.cursor.par(), sstate.cursor.pos(),
120 true, sstate.cursor.boundary());
121 text_.selection.cursor = text_.cursor;
122 text_.selection.set(false);
127 InsetText::InsetText(BufferParams const & bp)
128 : UpdatableInset(), text_(0, this)
130 paragraphs.push_back(Paragraph());
131 paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
132 if (bp.tracking_changes)
133 paragraphs.begin()->trackChanges();
138 InsetText::InsetText(InsetText const & in)
139 : UpdatableInset(in), text_(0, this)
145 InsetText & InsetText::operator=(InsetText const & it)
152 void InsetText::init(InsetText const * ins)
155 textwidth_ = ins->textwidth_;
156 text_.bv_owner = ins->text_.bv_owner;
158 paragraphs = ins->paragraphs;
160 ParagraphList::iterator pit = paragraphs.begin();
161 ParagraphList::iterator end = paragraphs.end();
162 for (; pit != end; ++pit)
163 pit->setInsetOwner(this);
167 autoBreakRows = ins->autoBreakRows;
168 drawFrame_ = ins->drawFrame_;
169 frame_color = ins->frame_color;
171 textwidth_ = 0; // broken
173 frame_color = LColor::insetframe;
174 autoBreakRows = false;
176 the_locking_inset = 0;
177 for_each(paragraphs.begin(), paragraphs.end(),
178 boost::bind(&Paragraph::setInsetOwner, _1, this));
184 old_par = paragraphs.end();
185 sstate.cursor.par(paragraphs.end());
186 in_insetAllowed = false;
190 void InsetText::clear(bool just_mark_erased)
192 if (just_mark_erased) {
193 ParagraphList::iterator it = paragraphs.begin();
194 ParagraphList::iterator end = paragraphs.end();
195 for (; it != end; ++it) {
201 // This is a gross hack...
202 LyXLayout_ptr old_layout = paragraphs.begin()->layout();
205 paragraphs.push_back(Paragraph());
206 paragraphs.begin()->setInsetOwner(this);
207 paragraphs.begin()->layout(old_layout);
213 auto_ptr<InsetBase> InsetText::clone() const
215 return auto_ptr<InsetBase>(new InsetText(*this));
219 void InsetText::write(Buffer const * buf, ostream & os) const
222 writeParagraphData(buf, os);
226 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
228 ParagraphList::const_iterator it = paragraphs.begin();
229 ParagraphList::const_iterator end = paragraphs.end();
230 Paragraph::depth_type dth = 0;
231 for (; it != end; ++it) {
232 it->write(buf, os, buf->params, dth);
237 void InsetText::read(Buffer const * buf, LyXLex & lex)
240 Paragraph::depth_type depth = 0;
244 if (buf->params.tracking_changes)
245 paragraphs.begin()->trackChanges();
247 // delete the initial paragraph
249 ParagraphList::iterator pit = paragraphs.begin();
253 token = lex.getString();
256 if (token == "\\end_inset") {
260 if (token == "\\end_document") {
261 lex.printError("\\end_document read in inset! Error in document!");
266 const_cast<Buffer*>(buf)->readParagraph(lex, token, paragraphs, pit, depth);
269 pit = paragraphs.begin();
270 ParagraphList::iterator const end = paragraphs.end();
271 for (; pit != end; ++pit)
272 pit->setInsetOwner(this);
274 if (token != "\\end_inset") {
275 lex.printError("Missing \\end_inset at this point. "
281 void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
283 //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
285 textwidth_ = mi.base.textwidth;
286 BufferView * bv = mi.base.bv;
288 text_.metrics(mi, dim);
289 dim.asc += TEXT_TO_INSET_OFFSET;
290 dim.des += TEXT_TO_INSET_OFFSET;
291 dim.wid += 2 * TEXT_TO_INSET_OFFSET;
292 dim.wid = max(dim.wid, 10);
297 int InsetText::textWidth() const
303 void InsetText::draw(PainterInfo & pi, int x, int baseline) const
305 // update our idea of where we are. Clearly, we should
306 // not have to know this information.
309 int const start_x = x;
311 BufferView * bv = pi.base.bv;
312 Painter & pain = pi.pain;
314 // repaint the background if needed
315 if (backgroundColor() != LColor::background)
316 clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline);
318 // no draw is necessary !!!
319 if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) {
320 top_baseline = baseline;
329 top_baseline = baseline;
330 top_y = baseline - dim_.asc;
332 if (the_locking_inset && cpar() == inset_par && cpos() == inset_pos) {
333 inset_x = cix() - x + drawTextXOffset;
334 inset_y = ciy() + drawTextYOffset;
337 x += TEXT_TO_INSET_OFFSET;
339 RowList::iterator rit = text_.rows().begin();
340 RowList::iterator end = text_.rows().end();
342 int y_offset = baseline - rit->ascent_of_text();
343 int y2 = pain.paperHeight();
346 while (rit != end && y + rit->height() <= 0) {
348 first += rit->height();
352 text_.top_y(-y_offset);
360 int yo = y_offset + first;
362 paintRows(*bv, text_, rit, x, 0, yo, y2, yo);
364 if (drawFrame_ == ALWAYS || (drawFrame_ == LOCKED && locked))
365 drawFrame(pain, int(start_x));
369 void InsetText::drawFrame(Painter & pain, int x) const
371 int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
372 int const frame_x = x + ttoD2;
373 int const frame_y = top_baseline - dim_.asc + ttoD2;
374 int const frame_w = dim_.wid - TEXT_TO_INSET_OFFSET;
375 int const frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET;
376 pain.rectangle(frame_x, frame_y, frame_w, frame_h, frame_color);
380 void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/)
385 if (!autoBreakRows && paragraphs.size() > 1)
386 collapseParagraphs(bv);
388 text_.partialRebreak();
389 if (!text_.selection.set())
390 text_.selection.cursor = text_.cursor;
394 bv->owner()->view_state_changed();
395 bv->owner()->updateMenubar();
396 bv->owner()->updateToolbar();
397 if (old_par != cpar()) {
398 bv->owner()->setLayout(cpar()->layout()->name());
404 string const InsetText::editMessage() const
406 return _("Opened Text Inset");
410 void InsetText::insetUnlock(BufferView * bv)
412 if (the_locking_inset) {
413 the_locking_inset->insetUnlock(bv);
414 the_locking_inset = 0;
415 updateLocal(bv, false);
420 if (text_.selection.set()) {
421 text_.clearSelection();
422 } else if (owner()) {
423 bv->owner()->setLayout(owner()->getLyXText(bv)
424 ->cursor.par()->layout()->name());
426 bv->owner()->setLayout(bv->text->cursor.par()->layout()->name());
427 // hack for deleteEmptyParMech
428 ParagraphList::iterator first_par = paragraphs.begin();
429 if (!first_par->empty()) {
430 text_.setCursor(first_par, 0);
431 } else if (paragraphs.size() > 1) {
432 text_.setCursor(boost::next(first_par), 0);
437 void InsetText::lockInset(BufferView * bv)
440 the_locking_inset = 0;
441 inset_pos = inset_x = inset_y = 0;
442 inset_boundary = false;
443 inset_par = paragraphs.end();
444 old_par = paragraphs.end();
445 text_.setCursorIntern(paragraphs.begin(), 0);
446 text_.clearSelection();
448 // If the inset is empty set the language of the current font to the
449 // language to the surronding text (if different).
450 if (paragraphs.begin()->empty() && paragraphs.size() == 1 &&
451 bv->getParentLanguage(this) != text_.current_font.language()) {
452 LyXFont font(LyXFont::ALL_IGNORE);
453 font.setLanguage(bv->getParentLanguage(this));
454 setFont(bv, font, false);
459 void InsetText::lockInset(BufferView * /*bv*/, UpdatableInset * inset)
461 the_locking_inset = inset;
462 inset_x = cix() - top_x + drawTextXOffset;
463 inset_y = ciy() + drawTextYOffset;
466 inset_boundary = cboundary();
470 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
472 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
473 << inset << "): " << endl;
476 if (!the_locking_inset) {
477 ParagraphList::iterator pit = paragraphs.begin();
478 ParagraphList::iterator pend = paragraphs.end();
480 int const id = inset->id();
481 for (; pit != pend; ++pit) {
482 InsetList::iterator it = pit->insetlist.begin();
483 InsetList::iterator const end = pit->insetlist.end();
484 for (; it != end; ++it) {
485 if (it->inset == inset) {
486 lyxerr << "InsetText::lockInsetInInset: 1 a" << endl;
487 text_.setCursorIntern(pit, it->pos);
488 lyxerr << "InsetText::lockInsetInInset: 1 b" << endl;
489 lyxerr << "bv: " << bv << " inset: " << inset << endl;
490 lockInset(bv, inset);
491 lyxerr << "InsetText::lockInsetInInset: 1 c" << endl;
494 if (it->inset->getInsetFromID(id)) {
495 lyxerr << "InsetText::lockInsetInInset: 2" << endl;
496 text_.setCursorIntern(pit, it->pos);
497 it->inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
498 return the_locking_inset->lockInsetInInset(bv, inset);
502 lyxerr << "InsetText::lockInsetInInset: 3" << endl;
505 if (inset == cpar()->getInset(cpos())) {
506 lyxerr[Debug::INSETS] << "OK" << endl;
507 lockInset(bv, inset);
511 if (the_locking_inset && the_locking_inset == inset) {
512 if (cpar() == inset_par && cpos() == inset_pos) {
513 lyxerr[Debug::INSETS] << "OK" << endl;
514 inset_x = cix() - top_x + drawTextXOffset;
515 inset_y = ciy() + drawTextYOffset;
517 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
519 } else if (the_locking_inset) {
520 lyxerr[Debug::INSETS] << "MAYBE" << endl;
521 return the_locking_inset->lockInsetInInset(bv, inset);
523 lyxerr[Debug::INSETS] << "NOT OK" << endl;
528 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
531 if (!the_locking_inset)
533 if (the_locking_inset == inset) {
534 the_locking_inset->insetUnlock(bv);
535 getLyXText(bv)->updateInset(inset);
536 the_locking_inset = 0;
538 moveRightIntern(bv, true, false);
539 old_par = paragraphs.end(); // force layout setting
543 updateLocal(bv, false);
546 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
550 void InsetText::lfunMousePress(FuncRequest const & cmd)
554 // use this to check mouse motion for selection!
558 BufferView * bv = cmd.view();
559 FuncRequest cmd1 = cmd;
565 int tmp_x = cmd.x - drawTextXOffset;
566 int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
567 InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
569 if (the_locking_inset) {
570 if (the_locking_inset == inset) {
571 the_locking_inset->localDispatch(cmd1);
574 // otherwise only unlock the_locking_inset
575 the_locking_inset->insetUnlock(bv);
576 the_locking_inset = 0;
579 no_selection = false;
581 if (bv->theLockingInset()) {
582 if (isHighlyEditableInset(inset)) {
583 // We just have to lock the inset before calling a
585 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
586 if (!bv->lockInset(uinset)) {
587 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
589 inset->localDispatch(cmd1);
590 if (the_locking_inset)
591 updateLocal(bv, false);
596 bool paste_internally = false;
597 if (cmd.button() == mouse_button::button2 && getLyXText(bv)->selection.set()) {
598 localDispatch(FuncRequest(bv, LFUN_COPY));
599 paste_internally = true;
601 int old_top_y = text_.top_y();
603 text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
605 // set the selection cursor!
606 text_.selection.cursor = text_.cursor;
607 text_.cursor.x_fix(text_.cursor.x());
609 text_.clearSelection();
610 updateLocal(bv, false);
612 bv->owner()->setLayout(cpar()->layout()->name());
614 // we moved the view we cannot do mouse selection in this case!
615 if (getLyXText(bv)->top_y() != old_top_y)
618 // Insert primary selection with middle mouse
619 // if there is a local selection in the current buffer,
621 if (cmd.button() == mouse_button::button2) {
622 if (paste_internally)
623 localDispatch(FuncRequest(bv, LFUN_PASTE));
625 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
628 getLyXText(bv)->clearSelection();
633 bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
635 BufferView * bv = cmd.view();
636 FuncRequest cmd1 = cmd;
641 if (the_locking_inset)
642 return the_locking_inset->localDispatch(cmd1);
644 int tmp_x = cmd.x - drawTextXOffset;
645 int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
646 InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
649 // This code should probably be removed now. Simple insets
650 // (!highlyEditable) can actually take the localDispatch,
651 // and turn it into edit() if necessary. But we still
652 // need to deal properly with the whole relative vs.
653 // absolute mouse co-ords thing in a realiable, sensible way
655 if (isHighlyEditableInset(inset))
656 ret = inset->localDispatch(cmd1);
658 inset_x = cix(bv) - top_x + drawTextXOffset;
659 inset_y = ciy() + drawTextYOffset;
660 cmd1.x = cmd.x - inset_x;
661 cmd1.y = cmd.x - inset_y;
662 inset->edit(bv, cmd1.x, cmd1.y, cmd.button());
666 ret = inset->localDispatch(cmd1);
667 updateLocal(bv, false);
674 void InsetText::lfunMouseMotion(FuncRequest const & cmd)
676 FuncRequest cmd1 = cmd;
680 if (the_locking_inset) {
681 the_locking_inset->localDispatch(cmd1);
685 if (no_selection || (mouse_x == cmd.x && mouse_y == cmd.y))
688 BufferView * bv = cmd.view();
689 LyXCursor cur = text_.cursor;
690 text_.setCursorFromCoordinates
691 (cmd.x - drawTextXOffset, cmd.y + dim_.asc);
692 text_.cursor.x_fix(text_.cursor.x());
693 if (cur == text_.cursor)
695 text_.setSelection();
696 updateLocal(bv, false);
700 InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
702 BufferView * bv = cmd.view();
705 switch (cmd.action) {
706 case LFUN_INSET_EDIT: {
707 UpdatableInset::localDispatch(cmd);
709 if (!bv->lockInset(this)) {
710 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
715 the_locking_inset = 0;
719 inset_boundary = false;
720 inset_par = paragraphs.end();
721 old_par = paragraphs.end();
724 if (cmd.argument.size()) {
725 if (cmd.argument == "left")
726 text_.setCursorIntern(paragraphs.begin(), 0);
728 ParagraphList::iterator it = boost::prior(paragraphs.end());
729 text_.setCursor(it, it->size());
732 int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
733 // we put here -1 and not button as now the button in the
734 // edit call should not be needed we will fix this in 1.3.x
735 // cycle hopefully (Jug 20020509)
736 // FIXME: GUII I've changed this to none: probably WRONG
737 if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) {
738 text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
740 text_.cursor.x_fix(text_.cursor.x());
744 text_.clearSelection();
747 // If the inset is empty set the language of the current font to the
748 // language to the surronding text (if different).
749 if (paragraphs.begin()->empty() &&
750 paragraphs.size() == 1 &&
751 bv->getParentLanguage(this) != text_.current_font.language())
753 LyXFont font(LyXFont::ALL_IGNORE);
754 font.setLanguage(bv->getParentLanguage(this));
755 setFont(bv, font, false);
758 updateLocal(bv, false);
759 // Tell the paragraph dialog that we've entered an insettext.
760 bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
764 case LFUN_MOUSE_PRESS:
768 case LFUN_MOUSE_MOTION:
769 lfunMouseMotion(cmd);
772 case LFUN_MOUSE_RELEASE:
773 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
779 bool was_empty = paragraphs.begin()->empty() && paragraphs.size() == 1;
780 no_selection = false;
782 RESULT result = UpdatableInset::localDispatch(cmd);
783 if (result != UNDISPATCHED)
787 if (cmd.action < 0 && cmd.argument.empty())
790 if (the_locking_inset) {
791 result = the_locking_inset->localDispatch(cmd);
792 if (result == DISPATCHED_NOUPDATE)
794 if (result == DISPATCHED) {
795 updateLocal(bv, false);
798 if (result >= FINISHED) {
801 moveRightIntern(bv, false, false);
806 if (result >= FINISHED) {
807 updateLocal(bv, false);
808 bv->unlockInset(this);
812 result = moveDown(bv);
813 if (result >= FINISHED) {
814 updateLocal(bv, false);
815 bv->unlockInset(this);
822 the_locking_inset = 0;
823 updateLocal(bv, false);
824 // make sure status gets reset immediately
825 bv->owner()->clearMessage();
829 bool updflag = false;
831 switch (cmd.action) {
834 case LFUN_SELFINSERT:
835 if (bv->buffer()->isReadonly()) {
836 // setErrorMessage(N_("Document is read only"));
839 if (!cmd.argument.empty()) {
840 /* Automatically delete the currently selected
841 * text and replace it with what is being
842 * typed in now. Depends on lyxrc settings
843 * "auto_region_delete", which defaults to
846 // This should not be needed here and is also WRONG!
847 recordUndo(bv, Undo::INSERT, text_.cursor.par());
851 if (lyxrc.auto_region_delete && text_.selection.set())
852 text_.cutSelection(false, false);
853 text_.clearSelection();
855 for (string::size_type i = 0; i < cmd.argument.length(); ++i)
856 bv->owner()->getIntl().getTransManager().
857 TranslateAndInsert(cmd.argument[i], &text_);
859 text_.selection.cursor = text_.cursor;
861 result = DISPATCHED_NOUPDATE;
864 // cursor movements that need special handling
867 result = moveRight(bv);
872 result = moveLeft(bv);
876 result = moveDown(bv);
884 if (crow() == text_.rows().begin())
885 result = FINISHED_UP;
887 text_.cursorPrevious();
888 text_.clearSelection();
889 result = DISPATCHED_NOUPDATE;
894 if (boost::next(crow()) == text_.rows().end())
895 result = FINISHED_DOWN;
898 text_.clearSelection();
899 result = DISPATCHED_NOUPDATE;
904 if (text_.selection.set())
905 text_.cutSelection(true, false);
912 if (text_.selection.set())
913 text_.cutSelection(true, false);
920 if (!autoBreakRows) {
921 if (CutAndPaste::nrOfParagraphs() > 1) {
923 #warning FIXME horrendously bad UI
925 Alert::error(_("Paste failed"), _("Cannot include more than one paragraph."));
930 replaceSelection(bv->getLyXText());
931 size_t sel_index = 0;
932 string const & arg = cmd.argument;
933 if (isStrUnsignedInt(arg)) {
934 size_t const paste_arg = strToUnsignedInt(arg);
935 #warning FIXME Check if the arg is in the domain of available selections.
936 sel_index = paste_arg;
938 text_.pasteSelection(sel_index);
940 text_.clearSelection();
945 case LFUN_BREAKPARAGRAPH:
946 if (!autoBreakRows) {
950 replaceSelection(bv->getLyXText());
951 text_.breakParagraph(paragraphs, 0);
955 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
956 if (!autoBreakRows) {
960 replaceSelection(bv->getLyXText());
961 text_.breakParagraph(paragraphs, 1);
965 case LFUN_BREAKLINE: {
966 if (!autoBreakRows) {
971 replaceSelection(bv->getLyXText());
972 text_.insertInset(new InsetNewline);
978 // do not set layouts on non breakable textinsets
980 string cur_layout = cpar()->layout()->name();
982 // Derive layout number from given argument (string)
983 // and current buffer's textclass (number).
984 LyXTextClass const & tclass =
985 bv->buffer()->params.getLyXTextClass();
986 string layout = cmd.argument;
987 bool hasLayout = tclass.hasLayout(layout);
989 // If the entry is obsolete, use the new one instead.
991 string const & obs = tclass[layout]->obsoleted_by();
996 // see if we found the layout number:
998 FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
999 bv->owner()->dispatch(lf);
1003 if (cur_layout != layout) {
1004 cur_layout = layout;
1005 text_.setLayout(layout);
1006 bv->owner()->setLayout(cpar()->layout()->name());
1010 // reset the layout box
1011 bv->owner()->setLayout(cpar()->layout()->name());
1016 if (!bv->dispatch(cmd))
1017 result = UNDISPATCHED;
1021 updateLocal(bv, updflag);
1023 /// If the action has deleted all text in the inset, we need to change the
1024 // language to the language of the surronding text.
1025 if (!was_empty && paragraphs.begin()->empty() &&
1026 paragraphs.size() == 1) {
1027 LyXFont font(LyXFont::ALL_IGNORE);
1028 font.setLanguage(bv->getParentLanguage(this));
1029 setFont(bv, font, false);
1032 if (result >= FINISHED)
1033 bv->unlockInset(this);
1035 if (result == DISPATCHED_NOUPDATE)
1036 result = DISPATCHED;
1041 int InsetText::latex(Buffer const * buf, ostream & os,
1042 LatexRunParams const & runparams) const
1045 latexParagraphs(buf, paragraphs, os, texrow, runparams);
1046 return texrow.rows();
1050 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1052 unsigned int lines = 0;
1054 ParagraphList::const_iterator beg = paragraphs.begin();
1055 ParagraphList::const_iterator end = paragraphs.end();
1056 ParagraphList::const_iterator it = beg;
1057 for (; it != end; ++it) {
1058 string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
1059 lines += lyx::count(tmp.begin(), tmp.end(), '\n');
1066 int InsetText::linuxdoc(Buffer const * buf, ostream & os) const
1068 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1069 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1071 // There is a confusion between the empty paragraph and the default paragraph
1072 // The default paragraph is <p></p>, the empty paragraph is *empty*
1073 // Since none of the floats of linuxdoc accepts standard paragraphs
1074 // I disable them. I don't expect problems. (jamatos 2003/07/27)
1075 for (; pit != pend; ++pit) {
1076 const string name = pit->layout()->latexname();
1078 sgml::openTag(os, 1, 0, name);
1079 buf->simpleLinuxDocOnePar(os, pit, 0);
1081 sgml::closeTag(os, 1, 0, name);
1087 int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1089 unsigned int lines = 0;
1091 vector<string> environment_stack(10);
1092 vector<string> environment_inner(10);
1094 int const command_depth = 0;
1097 Paragraph::depth_type depth = 0; // paragraph depth
1099 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1100 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1102 for (; pit != pend; ++pit) {
1103 int desc_on = 0; // description mode
1105 LyXLayout_ptr const & style = pit->layout();
1107 // environment tag closing
1108 for (; depth > pit->params().depth(); --depth) {
1109 if (environment_inner[depth] != "!-- --") {
1110 item_name = "listitem";
1111 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1112 if (environment_inner[depth] == "varlistentry")
1113 lines += sgml::closeTag(os, depth+command_depth, mixcont, environment_inner[depth]);
1115 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1116 environment_stack[depth].erase();
1117 environment_inner[depth].erase();
1120 if (depth == pit->params().depth()
1121 && environment_stack[depth] != style->latexname()
1122 && !environment_stack[depth].empty()) {
1123 if (environment_inner[depth] != "!-- --") {
1124 item_name= "listitem";
1125 lines += sgml::closeTag(os, command_depth+depth, mixcont, item_name);
1126 if (environment_inner[depth] == "varlistentry")
1127 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1130 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1132 environment_stack[depth].erase();
1133 environment_inner[depth].erase();
1136 // Write opening SGML tags.
1137 switch (style->latextype) {
1138 case LATEX_PARAGRAPH:
1139 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1143 buf->error(ErrorItem(_("Error"), _("LatexType Command not allowed here.\n"), pit->id(), 0, pit->size()));
1147 case LATEX_ENVIRONMENT:
1148 case LATEX_ITEM_ENVIRONMENT:
1149 if (depth < pit->params().depth()) {
1150 depth = pit->params().depth();
1151 environment_stack[depth].erase();
1154 if (environment_stack[depth] != style->latexname()) {
1155 if (environment_stack.size() == depth + 1) {
1156 environment_stack.push_back("!-- --");
1157 environment_inner.push_back("!-- --");
1159 environment_stack[depth] = style->latexname();
1160 environment_inner[depth] = "!-- --";
1161 lines += sgml::openTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1163 if (environment_inner[depth] != "!-- --") {
1164 item_name= "listitem";
1165 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1166 if (environment_inner[depth] == "varlistentry")
1167 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1171 if (style->latextype == LATEX_ENVIRONMENT) {
1172 if (!style->latexparam().empty()) {
1173 if (style->latexparam() == "CDATA")
1176 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexparam());
1181 desc_on = (style->labeltype == LABEL_MANUAL);
1183 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1184 lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
1186 item_name = desc_on ? "term" : "para";
1187 lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, item_name);
1191 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1195 buf->simpleDocBookOnePar(os, pit, desc_on, depth + 1 + command_depth);
1198 // write closing SGML tags
1199 switch (style->latextype) {
1200 case LATEX_ENVIRONMENT:
1201 if (!style->latexparam().empty()) {
1202 if (style->latexparam() == "CDATA")
1205 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexparam());
1208 case LATEX_ITEM_ENVIRONMENT:
1212 lines += sgml::closeTag(os, depth + 1 + command_depth, mixcont, end_tag);
1214 case LATEX_PARAGRAPH:
1215 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1218 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1224 for (int d = depth; d >= 0; --d) {
1225 if (!environment_stack[depth].empty()) {
1226 if (environment_inner[depth] != "!-- --") {
1227 item_name = "listitem";
1228 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1229 if (environment_inner[depth] == "varlistentry")
1230 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1233 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1241 void InsetText::validate(LaTeXFeatures & features) const
1243 for_each(paragraphs.begin(), paragraphs.end(),
1244 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1248 void InsetText::getCursor(BufferView & bv, int & x, int & y) const
1250 if (the_locking_inset) {
1251 the_locking_inset->getCursor(bv, x, y);
1255 y = cy() + InsetText::y();
1259 void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
1261 if (the_locking_inset) {
1262 the_locking_inset->getCursorPos(bv, x, y);
1265 x = cx() - top_x - TEXT_TO_INSET_OFFSET;
1266 y = cy() - TEXT_TO_INSET_OFFSET;
1270 int InsetText::insetInInsetY() const
1272 if (!the_locking_inset)
1275 return inset_y + the_locking_inset->insetInInsetY();
1279 void InsetText::fitInsetCursor(BufferView * bv) const
1281 if (the_locking_inset) {
1282 the_locking_inset->fitInsetCursor(bv);
1286 LyXFont const font = text_.getFont(cpar(), cpos());
1288 int const asc = font_metrics::maxAscent(font);
1289 int const desc = font_metrics::maxDescent(font);
1291 bv->fitLockedInsetCursor(cx(), cy(), asc, desc);
1295 InsetOld::RESULT InsetText::moveRight(BufferView * bv)
1297 if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1298 return moveLeftIntern(bv, false, true, false);
1300 return moveRightIntern(bv, true, true, false);
1304 InsetOld::RESULT InsetText::moveLeft(BufferView * bv)
1306 if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1307 return moveRightIntern(bv, true, true, false);
1309 return moveLeftIntern(bv, false, true, false);
1314 InsetText::moveRightIntern(BufferView * bv, bool front,
1315 bool activate_inset, bool selecting)
1317 ParagraphList::iterator c_par = cpar();
1319 if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size())
1320 return FINISHED_RIGHT;
1321 if (activate_inset && checkAndActivateInset(bv, front))
1323 text_.cursorRight(bv);
1325 text_.clearSelection();
1326 return DISPATCHED_NOUPDATE;
1331 InsetText::moveLeftIntern(BufferView * bv, bool front,
1332 bool activate_inset, bool selecting)
1334 if (cpar() == paragraphs.begin() && cpos() <= 0)
1336 text_.cursorLeft(bv);
1338 text_.clearSelection();
1339 if (activate_inset && checkAndActivateInset(bv, front))
1341 return DISPATCHED_NOUPDATE;
1345 InsetOld::RESULT InsetText::moveUp(BufferView * bv)
1347 if (crow() == text_.rows().begin())
1350 text_.clearSelection();
1351 return DISPATCHED_NOUPDATE;
1355 InsetOld::RESULT InsetText::moveDown(BufferView * bv)
1357 if (boost::next(crow()) == text_.rows().end())
1358 return FINISHED_DOWN;
1359 text_.cursorDown(bv);
1360 text_.clearSelection();
1361 return DISPATCHED_NOUPDATE;
1365 bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
1367 if (the_locking_inset) {
1368 if (the_locking_inset->insetAllowed(inset))
1369 return the_locking_inset->insertInset(bv, inset);
1372 inset->setOwner(this);
1373 text_.insertInset(inset);
1375 updateLocal(bv, true);
1380 bool InsetText::insetAllowed(InsetOld::Code code) const
1382 // in_insetAllowed is a really gross hack,
1383 // to allow us to call the owner's insetAllowed
1384 // without stack overflow, which can happen
1385 // when the owner uses InsetCollapsable::insetAllowed()
1387 if (in_insetAllowed)
1389 in_insetAllowed = true;
1390 if (the_locking_inset)
1391 ret = the_locking_inset->insetAllowed(code);
1393 ret = owner()->insetAllowed(code);
1394 in_insetAllowed = false;
1399 UpdatableInset * InsetText::getLockingInset() const
1401 return the_locking_inset ? the_locking_inset->getLockingInset() :
1402 const_cast<InsetText *>(this);
1406 UpdatableInset * InsetText::getFirstLockingInsetOfType(InsetOld::Code c)
1410 if (the_locking_inset)
1411 return the_locking_inset->getFirstLockingInsetOfType(c);
1416 bool InsetText::showInsetDialog(BufferView * bv) const
1418 if (the_locking_inset)
1419 return the_locking_inset->showInsetDialog(bv);
1424 void InsetText::getLabelList(std::vector<string> & list) const
1426 ParagraphList::const_iterator pit = paragraphs.begin();
1427 ParagraphList::const_iterator pend = paragraphs.end();
1428 for (; pit != pend; ++pit) {
1429 InsetList::const_iterator beg = pit->insetlist.begin();
1430 InsetList::const_iterator end = pit->insetlist.end();
1431 for (; beg != end; ++beg)
1432 beg->inset->getLabelList(list);
1437 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1440 if (the_locking_inset) {
1441 the_locking_inset->setFont(bv, font, toggleall, selectall);
1445 if ((paragraphs.size() == 1 && paragraphs.begin()->empty())
1446 || cpar()->empty()) {
1447 text_.setFont(font, toggleall);
1452 if (text_.selection.set())
1453 recordUndo(bv, Undo::ATOMIC, text_.cursor.par());
1457 text_.selection.cursor = text_.cursor;
1458 text_.cursorBottom();
1459 text_.setSelection();
1462 text_.toggleFree(font, toggleall);
1465 text_.clearSelection();
1468 updateLocal(bv, true);
1472 bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
1474 InsetOld * inset = cpar()->getInset(cpos());
1475 if (!isHighlyEditableInset(inset))
1477 FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
1478 inset->localDispatch(cmd);
1479 if (!the_locking_inset)
1481 updateLocal(bv, false);
1486 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1487 mouse_button::state button)
1489 x -= drawTextXOffset;
1491 int dummyy = y + dim_.asc;
1492 InsetOld * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy);
1493 // we only do the edit() call if the inset was hit by the mouse
1494 // or if it is a highly editable inset. So we should call this
1495 // function from our own edit with button < 0.
1496 // FIXME: GUII jbl. I've changed this to ::none for now which is probably
1498 if (button == mouse_button::none && !isHighlyEditableInset(inset))
1507 inset_x = cix() - top_x + drawTextXOffset;
1508 inset_y = ciy() + drawTextYOffset;
1509 FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
1510 inset->localDispatch(cmd);
1511 if (!the_locking_inset)
1513 updateLocal(bv, false);
1518 void InsetText::markNew(bool track_changes)
1520 ParagraphList::iterator pit = paragraphs.begin();
1521 ParagraphList::iterator end = paragraphs.end();
1522 for (; pit != end; ++pit) {
1523 if (track_changes) {
1524 pit->trackChanges();
1526 // no-op when not tracking
1527 pit->cleanChanges();
1533 void InsetText::setText(string const & data, LyXFont const & font)
1536 for (unsigned int i = 0; i < data.length(); ++i)
1537 paragraphs.begin()->insertChar(i, data[i], font);
1542 void InsetText::setAutoBreakRows(bool flag)
1544 if (flag != autoBreakRows) {
1545 autoBreakRows = flag;
1552 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1554 if (how != drawFrame_) {
1556 updateLocal(bv, false);
1561 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1563 if (frame_color != col) {
1565 updateLocal(bv, false);
1570 int InsetText::cx() const
1572 int x = text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1573 if (the_locking_inset) {
1574 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1575 if (font.isVisibleRightToLeft())
1576 x -= the_locking_inset->width();
1582 int InsetText::cix() const
1584 int x = text_.cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
1585 if (the_locking_inset) {
1586 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1587 if (font.isVisibleRightToLeft())
1588 x -= the_locking_inset->width();
1594 int InsetText::cy() const
1596 return text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET;
1600 int InsetText::ciy() const
1602 return text_.cursor.iy() - dim_.asc + TEXT_TO_INSET_OFFSET;
1606 pos_type InsetText::cpos() const
1608 return text_.cursor.pos();
1612 ParagraphList::iterator InsetText::cpar() const
1614 return text_.cursor.par();
1618 bool InsetText::cboundary() const
1620 return text_.cursor.boundary();
1624 RowList::iterator InsetText::crow() const
1626 return text_.cursorRow();
1630 LyXText * InsetText::getLyXText(BufferView const * bv,
1631 bool const recursive) const
1634 if (recursive && the_locking_inset)
1635 return the_locking_inset->getLyXText(bv, true);
1640 void InsetText::setViewCache(BufferView const * bv) const
1643 text_.bv_owner = const_cast<BufferView *>(bv);
1647 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1650 /// then remove all LyXText in text-insets
1651 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1652 const_cast<ParagraphList&>(paragraphs).end(),
1653 boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv));
1658 void InsetText::resizeLyXText(BufferView * bv, bool /*force*/) const
1660 if (paragraphs.size() == 1 && paragraphs.begin()->empty())
1669 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1670 const_cast<ParagraphList&>(paragraphs).end(),
1671 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1675 restoreLyXTextState();
1677 // seems to be unneeded
1679 if (the_locking_inset) {
1680 inset_x = cix() - top_x + drawTextXOffset;
1681 inset_y = ciy() + drawTextYOffset;
1686 text_.top_y(bv->screen().topCursorVisible(&text_));
1688 const_cast<InsetText*>(this)->updateLocal(bv, false);
1689 // this will scroll the screen such that the cursor becomes visible
1690 bv->updateScrollbar();
1696 void InsetText::reinitLyXText() const
1698 BufferView * bv = text_.bv_owner;
1705 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1706 const_cast<ParagraphList&>(paragraphs).end(),
1707 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1710 restoreLyXTextState();
1711 if (the_locking_inset) {
1712 inset_x = cix() - top_x + drawTextXOffset;
1713 inset_y = ciy() + drawTextYOffset;
1715 text_.top_y(bv->screen().topCursorVisible(&text_));
1717 // this will scroll the screen such that the cursor becomes visible
1718 bv->updateScrollbar();
1723 void InsetText::removeNewlines()
1725 bool changed = false;
1727 ParagraphList::iterator it = paragraphs.begin();
1728 ParagraphList::iterator end = paragraphs.end();
1729 for (; it != end; ++it) {
1730 for (int i = 0; i < it->size(); ++i) {
1731 if (it->isNewline(i)) {
1742 int InsetText::scroll(bool recursive) const
1744 int sx = UpdatableInset::scroll(false);
1746 if (recursive && the_locking_inset)
1747 sx += the_locking_inset->scroll(recursive);
1753 void InsetText::clearSelection(BufferView * bv)
1755 getLyXText(bv)->clearSelection();
1759 void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
1761 Painter & pain = bv->painter();
1763 int h = dim_.asc + dim_.des;
1764 int ty = baseline - dim_.asc;
1770 if (ty + h > pain.paperHeight())
1771 h = pain.paperHeight();
1772 if (top_x + drawTextXOffset + w > pain.paperWidth())
1773 w = pain.paperWidth();
1774 pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor());
1778 ParagraphList * InsetText::getParagraphs(int i) const
1780 return (i == 0) ? const_cast<ParagraphList*>(¶graphs) : 0;
1784 LyXCursor const & InsetText::cursor(BufferView * bv) const
1786 if (the_locking_inset)
1787 return the_locking_inset->cursor(bv);
1788 return getLyXText(bv)->cursor;
1792 InsetOld * InsetText::getInsetFromID(int id_arg) const
1795 return const_cast<InsetText *>(this);
1797 ParagraphList::const_iterator pit = paragraphs.begin();
1798 ParagraphList::const_iterator pend = paragraphs.end();
1799 for (; pit != pend; ++pit) {
1800 InsetList::const_iterator it = pit->insetlist.begin();
1801 InsetList::const_iterator end = pit->insetlist.end();
1802 for (; it != end; ++it) {
1803 if (it->inset->id() == id_arg)
1805 InsetOld * in = it->inset->getInsetFromID(id_arg);
1815 InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
1818 if (the_locking_inset) {
1819 word = the_locking_inset->selectNextWordToSpellcheck(bv, value);
1820 if (!word.word().empty()) {
1824 // we have to go on checking so move cursor to the next char
1825 text_.cursor.pos(text_.cursor.pos() + 1);
1827 word = text_.selectNextWordToSpellcheck(value);
1828 if (word.word().empty())
1829 bv->unlockInset(const_cast<InsetText *>(this));
1836 void InsetText::selectSelectedWord(BufferView * bv)
1838 if (the_locking_inset) {
1839 the_locking_inset->selectSelectedWord(bv);
1842 getLyXText(bv)->selectSelectedWord();
1843 updateLocal(bv, false);
1847 bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length)
1849 if (the_locking_inset) {
1850 if (the_locking_inset->nextChange(bv, length))
1852 text_.cursorRight(true);
1854 lyx::find::SearchResult result =
1855 lyx::find::findNextChange(bv, &text_, length);
1857 if (result == lyx::find::SR_FOUND) {
1858 LyXCursor cur = text_.cursor;
1859 bv->unlockInset(bv->theLockingInset());
1860 if (bv->lockInset(this))
1863 text_.setSelectionRange(length);
1864 updateLocal(bv, false);
1866 return result != lyx::find::SR_NOT_FOUND;
1870 bool InsetText::searchForward(BufferView * bv, string const & str,
1873 if (the_locking_inset) {
1874 if (the_locking_inset->searchForward(bv, str, cs, mw))
1876 text_.cursorRight(true);
1878 lyx::find::SearchResult result =
1879 lyx::find::find(bv, &text_, str, true, cs, mw);
1881 if (result == lyx::find::SR_FOUND) {
1882 LyXCursor cur = text_.cursor;
1883 bv->unlockInset(bv->theLockingInset());
1884 if (bv->lockInset(this))
1887 text_.setSelectionRange(str.length());
1888 updateLocal(bv, false);
1890 return result != lyx::find::SR_NOT_FOUND;
1894 bool InsetText::searchBackward(BufferView * bv, string const & str,
1897 if (the_locking_inset) {
1898 if (the_locking_inset->searchBackward(bv, str, cs, mw))
1902 ParagraphList::iterator pit = paragraphs.begin();
1903 ParagraphList::iterator pend = paragraphs.end();
1905 while (boost::next(pit) != pend)
1908 text_.setCursor(pit, pit->size());
1910 lyx::find::SearchResult result =
1911 lyx::find::find(bv, &text_, str, false, cs, mw);
1913 if (result == lyx::find::SR_FOUND) {
1914 LyXCursor cur = text_.cursor;
1915 bv->unlockInset(bv->theLockingInset());
1916 if (bv->lockInset(this))
1919 text_.setSelectionRange(str.length());
1920 updateLocal(bv, false);
1922 return result != lyx::find::SR_NOT_FOUND;
1926 bool InsetText::checkInsertChar(LyXFont & font)
1928 return owner() ? owner()->checkInsertChar(font) : true;
1932 void InsetText::collapseParagraphs(BufferView * bv)
1934 while (paragraphs.size() > 1) {
1935 ParagraphList::iterator first_par = paragraphs.begin();
1936 ParagraphList::iterator next_par = boost::next(first_par);
1937 size_t const first_par_size = first_par->size();
1939 if (!first_par->empty() &&
1940 !next_par->empty() &&
1941 !first_par->isSeparator(first_par_size - 1)) {
1942 first_par->insertChar(first_par_size, ' ');
1945 if (text_.selection.set()) {
1946 if (text_.selection.start.par() == next_par) {
1947 text_.selection.start.par(first_par);
1948 text_.selection.start.pos(
1949 text_.selection.start.pos() + first_par_size);
1951 if (text_.selection.end.par() == next_par) {
1952 text_.selection.end.par(first_par);
1953 text_.selection.end.pos(
1954 text_.selection.end.pos() + first_par_size);
1958 mergeParagraph(bv->buffer()->params, paragraphs, first_par);
1964 void InsetText::getDrawFont(LyXFont & font) const
1968 owner()->getDrawFont(font);
1972 void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
1974 #warning FIXME Check if Changes stuff needs changing here. (Lgb)
1975 // And it probably does. You have to take a look at this John. (Lgb)
1976 #warning John, have a look here. (Lgb)
1977 ParagraphList::iterator pit = plist.begin();
1978 ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit);
1980 mergeParagraph(buffer->params, paragraphs, boost::prior(ins));
1982 ParagraphList::iterator pend = plist.end();
1983 for (; pit != pend; ++pit)
1984 paragraphs.push_back(*pit);
1990 void InsetText::addPreview(PreviewLoader & loader) const
1992 ParagraphList::const_iterator pit = paragraphs.begin();
1993 ParagraphList::const_iterator pend = paragraphs.end();
1995 for (; pit != pend; ++pit) {
1996 InsetList::const_iterator it = pit->insetlist.begin();
1997 InsetList::const_iterator end = pit->insetlist.end();
1998 for (; it != end; ++it)
1999 it->inset->addPreview(loader);