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() &&
780 paragraphs.size() == 1);
782 no_selection = false;
783 RESULT result = UpdatableInset::localDispatch(cmd);
784 if (result != UNDISPATCHED)
788 if (cmd.action < 0 && cmd.argument.empty())
791 if (the_locking_inset) {
792 result = the_locking_inset->localDispatch(cmd);
793 if (result == DISPATCHED_NOUPDATE)
795 if (result == DISPATCHED) {
796 updateLocal(bv, false);
799 if (result >= FINISHED) {
802 moveRightIntern(bv, false, false);
807 if (result >= FINISHED) {
808 updateLocal(bv, false);
809 bv->unlockInset(this);
813 result = moveDown(bv);
814 if (result >= FINISHED) {
815 updateLocal(bv, false);
816 bv->unlockInset(this);
823 the_locking_inset = 0;
824 updateLocal(bv, false);
825 // make sure status gets reset immediately
826 bv->owner()->clearMessage();
830 bool updflag = false;
832 switch (cmd.action) {
835 case LFUN_SELFINSERT:
836 if (bv->buffer()->isReadonly()) {
837 // setErrorMessage(N_("Document is read only"));
840 if (!cmd.argument.empty()) {
841 /* Automatically delete the currently selected
842 * text and replace it with what is being
843 * typed in now. Depends on lyxrc settings
844 * "auto_region_delete", which defaults to
847 // This should not be needed here and is also WRONG!
848 recordUndo(bv, Undo::INSERT, text_.cursor.par());
851 if (lyxrc.auto_region_delete) {
852 if (text_.selection.set()) {
853 text_.cutSelection(false, false);
856 text_.clearSelection();
857 for (string::size_type i = 0; i < cmd.argument.length(); ++i) {
858 bv->owner()->getIntl().getTransManager().
859 TranslateAndInsert(cmd.argument[i], &text_);
862 text_.selection.cursor = text_.cursor;
864 result = DISPATCHED_NOUPDATE;
867 // cursor movements that need special handling
870 result = moveRight(bv);
875 result = moveLeft(bv);
879 result = moveDown(bv);
887 if (crow() == text_.rows().begin())
888 result = FINISHED_UP;
890 text_.cursorPrevious();
891 text_.clearSelection();
892 result = DISPATCHED_NOUPDATE;
897 if (boost::next(crow()) == text_.rows().end())
898 result = FINISHED_DOWN;
901 text_.clearSelection();
902 result = DISPATCHED_NOUPDATE;
906 case LFUN_BACKSPACE: {
907 if (text_.selection.set())
908 text_.cutSelection(true, false);
916 if (text_.selection.set()) {
917 text_.cutSelection(true, false);
926 text_.cutSelection(true, true);
933 text_.copySelection();
936 case LFUN_PASTESELECTION:
938 string const clip(bv->getClipboard());
942 if (cmd.argument == "paragraph") {
943 text_.insertStringAsParagraphs(clip);
945 text_.insertStringAsLines(clip);
948 text_.clearSelection();
955 if (!autoBreakRows) {
956 if (CutAndPaste::nrOfParagraphs() > 1) {
958 #warning FIXME horrendously bad UI
960 Alert::error(_("Paste failed"), _("Cannot include more than one paragraph."));
965 replaceSelection(bv->getLyXText());
966 size_t sel_index = 0;
967 string const & arg = cmd.argument;
968 if (isStrUnsignedInt(arg)) {
969 size_t const paste_arg = strToUnsignedInt(arg);
970 #warning FIXME Check if the arg is in the domain of available selections.
971 sel_index = paste_arg;
973 text_.pasteSelection(sel_index);
975 text_.clearSelection();
980 case LFUN_BREAKPARAGRAPH:
981 if (!autoBreakRows) {
985 replaceSelection(bv->getLyXText());
986 text_.breakParagraph(paragraphs, 0);
990 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
991 if (!autoBreakRows) {
995 replaceSelection(bv->getLyXText());
996 text_.breakParagraph(paragraphs, 1);
1000 case LFUN_BREAKLINE: {
1001 if (!autoBreakRows) {
1002 result = DISPATCHED;
1006 replaceSelection(bv->getLyXText());
1007 text_.insertInset(new InsetNewline);
1013 // do not set layouts on non breakable textinsets
1014 if (autoBreakRows) {
1015 string cur_layout = cpar()->layout()->name();
1017 // Derive layout number from given argument (string)
1018 // and current buffer's textclass (number). */
1019 LyXTextClass const & tclass =
1020 bv->buffer()->params.getLyXTextClass();
1021 string layout = cmd.argument;
1022 bool hasLayout = tclass.hasLayout(layout);
1024 // If the entry is obsolete, use the new one instead.
1026 string const & obs =
1027 tclass[layout]->obsoleted_by();
1032 // see if we found the layout number:
1034 FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
1035 bv->owner()->dispatch(lf);
1039 if (cur_layout != layout) {
1040 cur_layout = layout;
1041 text_.setLayout(layout);
1042 bv->owner()->setLayout(cpar()->layout()->name());
1046 // reset the layout box
1047 bv->owner()->setLayout(cpar()->layout()->name());
1050 case LFUN_PARAGRAPH_SPACING:
1051 // This one is absolutely not working. When fiddling with this
1052 // it also seems to me that the paragraphs inside the insettext
1053 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1054 // FIXME: how old is this comment ? ...
1056 ParagraphList::iterator pit = text_.cursor.par();
1057 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
1058 float cur_value = 1.0;
1059 if (cur_spacing == Spacing::Other) {
1060 cur_value = pit->params().spacing().getValue();
1063 istringstream istr(STRCONV(cmd.argument));
1066 Spacing::Space new_spacing = cur_spacing;
1067 float new_value = cur_value;
1069 lyxerr << "Missing argument to `paragraph-spacing'"
1071 } else if (tmp == "single") {
1072 new_spacing = Spacing::Single;
1073 } else if (tmp == "onehalf") {
1074 new_spacing = Spacing::Onehalf;
1075 } else if (tmp == "double") {
1076 new_spacing = Spacing::Double;
1077 } else if (tmp == "other") {
1078 new_spacing = Spacing::Other;
1081 lyxerr << "new_value = " << tmpval << endl;
1084 } else if (tmp == "default") {
1085 new_spacing = Spacing::Default;
1087 lyxerr << _("Unknown spacing argument: ")
1088 << cmd.argument << endl;
1090 if (cur_spacing != new_spacing || cur_value != new_value) {
1091 pit->params().spacing(Spacing(new_spacing, new_value));
1098 if (!bv->dispatch(cmd))
1099 result = UNDISPATCHED;
1103 updateLocal(bv, updflag);
1105 /// If the action has deleted all text in the inset, we need to change the
1106 // language to the language of the surronding text.
1107 if (!was_empty && paragraphs.begin()->empty() &&
1108 paragraphs.size() == 1) {
1109 LyXFont font(LyXFont::ALL_IGNORE);
1110 font.setLanguage(bv->getParentLanguage(this));
1111 setFont(bv, font, false);
1114 if (result >= FINISHED)
1115 bv->unlockInset(this);
1117 if (result == DISPATCHED_NOUPDATE)
1118 result = DISPATCHED;
1123 int InsetText::latex(Buffer const * buf, ostream & os,
1124 LatexRunParams const & runparams) const
1127 latexParagraphs(buf, paragraphs, os, texrow, runparams);
1128 return texrow.rows();
1132 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1134 unsigned int lines = 0;
1136 ParagraphList::const_iterator beg = paragraphs.begin();
1137 ParagraphList::const_iterator end = paragraphs.end();
1138 ParagraphList::const_iterator it = beg;
1139 for (; it != end; ++it) {
1140 string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
1141 lines += lyx::count(tmp.begin(), tmp.end(), '\n');
1148 int InsetText::linuxdoc(Buffer const * buf, ostream & os) const
1150 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1151 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1153 // There is a confusion between the empty paragraph and the default paragraph
1154 // The default paragraph is <p></p>, the empty paragraph is *empty*
1155 // Since none of the floats of linuxdoc accepts standard paragraphs
1156 // I disable them. I don't expect problems. (jamatos 2003/07/27)
1157 for (; pit != pend; ++pit) {
1158 const string name = pit->layout()->latexname();
1160 sgml::openTag(os, 1, 0, name);
1161 buf->simpleLinuxDocOnePar(os, pit, 0);
1163 sgml::closeTag(os, 1, 0, name);
1169 int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1171 unsigned int lines = 0;
1173 vector<string> environment_stack(10);
1174 vector<string> environment_inner(10);
1176 int const command_depth = 0;
1179 Paragraph::depth_type depth = 0; // paragraph depth
1181 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1182 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1184 for (; pit != pend; ++pit) {
1186 int desc_on = 0; // description mode
1188 LyXLayout_ptr const & style = pit->layout();
1190 // environment tag closing
1191 for (; depth > pit->params().depth(); --depth) {
1192 if (environment_inner[depth] != "!-- --") {
1193 item_name = "listitem";
1194 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1195 if (environment_inner[depth] == "varlistentry")
1196 lines += sgml::closeTag(os, depth+command_depth, mixcont, environment_inner[depth]);
1198 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1199 environment_stack[depth].erase();
1200 environment_inner[depth].erase();
1203 if (depth == pit->params().depth()
1204 && environment_stack[depth] != style->latexname()
1205 && !environment_stack[depth].empty()) {
1206 if (environment_inner[depth] != "!-- --") {
1207 item_name= "listitem";
1208 lines += sgml::closeTag(os, command_depth+depth, mixcont, item_name);
1209 if (environment_inner[depth] == "varlistentry")
1210 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1213 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1215 environment_stack[depth].erase();
1216 environment_inner[depth].erase();
1219 // Write opening SGML tags.
1220 switch (style->latextype) {
1221 case LATEX_PARAGRAPH:
1222 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1226 buf->error(ErrorItem(_("Error"), _("LatexType Command not allowed here.\n"), pit->id(), 0, pit->size()));
1230 case LATEX_ENVIRONMENT:
1231 case LATEX_ITEM_ENVIRONMENT:
1232 if (depth < pit->params().depth()) {
1233 depth = pit->params().depth();
1234 environment_stack[depth].erase();
1237 if (environment_stack[depth] != style->latexname()) {
1238 if (environment_stack.size() == depth + 1) {
1239 environment_stack.push_back("!-- --");
1240 environment_inner.push_back("!-- --");
1242 environment_stack[depth] = style->latexname();
1243 environment_inner[depth] = "!-- --";
1244 lines += sgml::openTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1246 if (environment_inner[depth] != "!-- --") {
1247 item_name= "listitem";
1248 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1249 if (environment_inner[depth] == "varlistentry")
1250 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1254 if (style->latextype == LATEX_ENVIRONMENT) {
1255 if (!style->latexparam().empty()) {
1256 if (style->latexparam() == "CDATA")
1259 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexparam());
1264 desc_on = (style->labeltype == LABEL_MANUAL);
1266 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1267 lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
1269 item_name = desc_on ? "term" : "para";
1270 lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, item_name);
1274 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1278 buf->simpleDocBookOnePar(os, pit, desc_on, depth + 1 + command_depth);
1281 // write closing SGML tags
1282 switch (style->latextype) {
1283 case LATEX_ENVIRONMENT:
1284 if (!style->latexparam().empty()) {
1285 if (style->latexparam() == "CDATA")
1288 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexparam());
1291 case LATEX_ITEM_ENVIRONMENT:
1292 if (desc_on == 1) break;
1294 lines += sgml::closeTag(os, depth + 1 + command_depth, mixcont, end_tag);
1296 case LATEX_PARAGRAPH:
1297 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1300 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1306 for (int d = depth; d >= 0; --d) {
1307 if (!environment_stack[depth].empty()) {
1308 if (environment_inner[depth] != "!-- --") {
1309 item_name = "listitem";
1310 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1311 if (environment_inner[depth] == "varlistentry")
1312 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1315 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1323 void InsetText::validate(LaTeXFeatures & features) const
1325 for_each(paragraphs.begin(), paragraphs.end(),
1326 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1330 void InsetText::getCursor(BufferView & bv, int & x, int & y) const
1332 if (the_locking_inset) {
1333 the_locking_inset->getCursor(bv, x, y);
1337 y = cy() + InsetText::y();
1341 void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
1343 if (the_locking_inset) {
1344 the_locking_inset->getCursorPos(bv, x, y);
1347 x = cx() - top_x - TEXT_TO_INSET_OFFSET;
1348 y = cy() - TEXT_TO_INSET_OFFSET;
1352 int InsetText::insetInInsetY() const
1354 if (!the_locking_inset)
1357 return inset_y + the_locking_inset->insetInInsetY();
1361 void InsetText::fitInsetCursor(BufferView * bv) const
1363 if (the_locking_inset) {
1364 the_locking_inset->fitInsetCursor(bv);
1368 LyXFont const font = text_.getFont(cpar(), cpos());
1370 int const asc = font_metrics::maxAscent(font);
1371 int const desc = font_metrics::maxDescent(font);
1373 bv->fitLockedInsetCursor(cx(), cy(), asc, desc);
1377 InsetOld::RESULT InsetText::moveRight(BufferView * bv)
1379 if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1380 return moveLeftIntern(bv, false, true, false);
1382 return moveRightIntern(bv, true, true, false);
1386 InsetOld::RESULT InsetText::moveLeft(BufferView * bv)
1388 if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1389 return moveRightIntern(bv, true, true, false);
1391 return moveLeftIntern(bv, false, true, false);
1396 InsetText::moveRightIntern(BufferView * bv, bool front,
1397 bool activate_inset, bool selecting)
1399 ParagraphList::iterator c_par = cpar();
1401 if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size())
1402 return FINISHED_RIGHT;
1403 if (activate_inset && checkAndActivateInset(bv, front))
1405 text_.cursorRight(bv);
1407 text_.clearSelection();
1408 return DISPATCHED_NOUPDATE;
1413 InsetText::moveLeftIntern(BufferView * bv, bool front,
1414 bool activate_inset, bool selecting)
1416 if (cpar() == paragraphs.begin() && cpos() <= 0)
1418 text_.cursorLeft(bv);
1420 text_.clearSelection();
1421 if (activate_inset && checkAndActivateInset(bv, front))
1423 return DISPATCHED_NOUPDATE;
1427 InsetOld::RESULT InsetText::moveUp(BufferView * bv)
1429 if (crow() == text_.rows().begin())
1432 text_.clearSelection();
1433 return DISPATCHED_NOUPDATE;
1437 InsetOld::RESULT InsetText::moveDown(BufferView * bv)
1439 if (boost::next(crow()) == text_.rows().end())
1440 return FINISHED_DOWN;
1441 text_.cursorDown(bv);
1442 text_.clearSelection();
1443 return DISPATCHED_NOUPDATE;
1447 bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
1449 if (the_locking_inset) {
1450 if (the_locking_inset->insetAllowed(inset))
1451 return the_locking_inset->insertInset(bv, inset);
1454 inset->setOwner(this);
1455 text_.insertInset(inset);
1457 updateLocal(bv, true);
1462 bool InsetText::insetAllowed(InsetOld::Code code) const
1464 // in_insetAllowed is a really gross hack,
1465 // to allow us to call the owner's insetAllowed
1466 // without stack overflow, which can happen
1467 // when the owner uses InsetCollapsable::insetAllowed()
1469 if (in_insetAllowed)
1471 in_insetAllowed = true;
1472 if (the_locking_inset)
1473 ret = the_locking_inset->insetAllowed(code);
1475 ret = owner()->insetAllowed(code);
1476 in_insetAllowed = false;
1481 UpdatableInset * InsetText::getLockingInset() const
1483 return the_locking_inset ? the_locking_inset->getLockingInset() :
1484 const_cast<InsetText *>(this);
1488 UpdatableInset * InsetText::getFirstLockingInsetOfType(InsetOld::Code c)
1492 if (the_locking_inset)
1493 return the_locking_inset->getFirstLockingInsetOfType(c);
1498 bool InsetText::showInsetDialog(BufferView * bv) const
1500 if (the_locking_inset)
1501 return the_locking_inset->showInsetDialog(bv);
1506 void InsetText::getLabelList(std::vector<string> & list) const
1508 ParagraphList::const_iterator pit = paragraphs.begin();
1509 ParagraphList::const_iterator pend = paragraphs.end();
1510 for (; pit != pend; ++pit) {
1511 InsetList::const_iterator beg = pit->insetlist.begin();
1512 InsetList::const_iterator end = pit->insetlist.end();
1513 for (; beg != end; ++beg)
1514 beg->inset->getLabelList(list);
1519 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1522 if (the_locking_inset) {
1523 the_locking_inset->setFont(bv, font, toggleall, selectall);
1527 if ((paragraphs.size() == 1 && paragraphs.begin()->empty())
1528 || cpar()->empty()) {
1529 text_.setFont(font, toggleall);
1534 if (text_.selection.set())
1535 recordUndo(bv, Undo::ATOMIC, text_.cursor.par());
1539 text_.selection.cursor = text_.cursor;
1540 text_.cursorBottom();
1541 text_.setSelection();
1544 text_.toggleFree(font, toggleall);
1547 text_.clearSelection();
1550 updateLocal(bv, true);
1554 bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
1556 InsetOld * inset = cpar()->getInset(cpos());
1557 if (!isHighlyEditableInset(inset))
1559 FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
1560 inset->localDispatch(cmd);
1561 if (!the_locking_inset)
1563 updateLocal(bv, false);
1568 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1569 mouse_button::state button)
1571 x -= drawTextXOffset;
1573 int dummyy = y + dim_.asc;
1574 InsetOld * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy);
1575 // we only do the edit() call if the inset was hit by the mouse
1576 // or if it is a highly editable inset. So we should call this
1577 // function from our own edit with button < 0.
1578 // FIXME: GUII jbl. I've changed this to ::none for now which is probably
1580 if (button == mouse_button::none && !isHighlyEditableInset(inset))
1589 inset_x = cix() - top_x + drawTextXOffset;
1590 inset_y = ciy() + drawTextYOffset;
1591 FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
1592 inset->localDispatch(cmd);
1593 if (!the_locking_inset)
1595 updateLocal(bv, false);
1600 void InsetText::markNew(bool track_changes)
1602 ParagraphList::iterator pit = paragraphs.begin();
1603 ParagraphList::iterator end = paragraphs.end();
1604 for (; pit != end; ++pit) {
1605 if (track_changes) {
1606 pit->trackChanges();
1608 // no-op when not tracking
1609 pit->cleanChanges();
1615 void InsetText::setText(string const & data, LyXFont const & font)
1618 for (unsigned int i = 0; i < data.length(); ++i)
1619 paragraphs.begin()->insertChar(i, data[i], font);
1624 void InsetText::setAutoBreakRows(bool flag)
1626 if (flag != autoBreakRows) {
1627 autoBreakRows = flag;
1634 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1636 if (how != drawFrame_) {
1638 updateLocal(bv, false);
1643 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1645 if (frame_color != col) {
1647 updateLocal(bv, false);
1652 int InsetText::cx() const
1654 int x = text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1655 if (the_locking_inset) {
1656 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1657 if (font.isVisibleRightToLeft())
1658 x -= the_locking_inset->width();
1664 int InsetText::cix() const
1666 int x = text_.cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
1667 if (the_locking_inset) {
1668 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1669 if (font.isVisibleRightToLeft())
1670 x -= the_locking_inset->width();
1676 int InsetText::cy() const
1678 return text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET;
1682 int InsetText::ciy() const
1684 return text_.cursor.iy() - dim_.asc + TEXT_TO_INSET_OFFSET;
1688 pos_type InsetText::cpos() const
1690 return text_.cursor.pos();
1694 ParagraphList::iterator InsetText::cpar() const
1696 return text_.cursor.par();
1700 bool InsetText::cboundary() const
1702 return text_.cursor.boundary();
1706 RowList::iterator InsetText::crow() const
1708 return text_.cursorRow();
1712 LyXText * InsetText::getLyXText(BufferView const * bv,
1713 bool const recursive) const
1716 if (recursive && the_locking_inset)
1717 return the_locking_inset->getLyXText(bv, true);
1722 void InsetText::setViewCache(BufferView const * bv) const
1725 text_.bv_owner = const_cast<BufferView *>(bv);
1729 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1732 /// then remove all LyXText in text-insets
1733 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1734 const_cast<ParagraphList&>(paragraphs).end(),
1735 boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv));
1740 void InsetText::resizeLyXText(BufferView * bv, bool /*force*/) const
1742 if (paragraphs.size() == 1 && paragraphs.begin()->empty())
1751 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1752 const_cast<ParagraphList&>(paragraphs).end(),
1753 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1757 restoreLyXTextState();
1759 // seems to be unneeded
1761 if (the_locking_inset) {
1762 inset_x = cix() - top_x + drawTextXOffset;
1763 inset_y = ciy() + drawTextYOffset;
1768 text_.top_y(bv->screen().topCursorVisible(&text_));
1770 const_cast<InsetText*>(this)->updateLocal(bv, false);
1771 // this will scroll the screen such that the cursor becomes visible
1772 bv->updateScrollbar();
1778 void InsetText::reinitLyXText() const
1780 BufferView * bv = text_.bv_owner;
1787 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1788 const_cast<ParagraphList&>(paragraphs).end(),
1789 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1792 restoreLyXTextState();
1793 if (the_locking_inset) {
1794 inset_x = cix() - top_x + drawTextXOffset;
1795 inset_y = ciy() + drawTextYOffset;
1797 text_.top_y(bv->screen().topCursorVisible(&text_));
1799 // this will scroll the screen such that the cursor becomes visible
1800 bv->updateScrollbar();
1805 void InsetText::removeNewlines()
1807 bool changed = false;
1809 ParagraphList::iterator it = paragraphs.begin();
1810 ParagraphList::iterator end = paragraphs.end();
1811 for (; it != end; ++it) {
1812 for (int i = 0; i < it->size(); ++i) {
1813 if (it->isNewline(i)) {
1824 int InsetText::scroll(bool recursive) const
1826 int sx = UpdatableInset::scroll(false);
1828 if (recursive && the_locking_inset)
1829 sx += the_locking_inset->scroll(recursive);
1835 void InsetText::clearSelection(BufferView * bv)
1837 getLyXText(bv)->clearSelection();
1841 void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
1843 Painter & pain = bv->painter();
1845 int h = dim_.asc + dim_.des;
1846 int ty = baseline - dim_.asc;
1852 if (ty + h > pain.paperHeight())
1853 h = pain.paperHeight();
1854 if (top_x + drawTextXOffset + w > pain.paperWidth())
1855 w = pain.paperWidth();
1856 pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor());
1860 ParagraphList * InsetText::getParagraphs(int i) const
1862 return (i == 0) ? const_cast<ParagraphList*>(¶graphs) : 0;
1866 LyXCursor const & InsetText::cursor(BufferView * bv) const
1868 if (the_locking_inset)
1869 return the_locking_inset->cursor(bv);
1870 return getLyXText(bv)->cursor;
1874 InsetOld * InsetText::getInsetFromID(int id_arg) const
1877 return const_cast<InsetText *>(this);
1879 ParagraphList::const_iterator pit = paragraphs.begin();
1880 ParagraphList::const_iterator pend = paragraphs.end();
1881 for (; pit != pend; ++pit) {
1882 InsetList::const_iterator it = pit->insetlist.begin();
1883 InsetList::const_iterator end = pit->insetlist.end();
1884 for (; it != end; ++it) {
1885 if (it->inset->id() == id_arg)
1887 InsetOld * in = it->inset->getInsetFromID(id_arg);
1897 InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
1900 if (the_locking_inset) {
1901 word = the_locking_inset->selectNextWordToSpellcheck(bv, value);
1902 if (!word.word().empty()) {
1906 // we have to go on checking so move cursor to the next char
1907 text_.cursor.pos(text_.cursor.pos() + 1);
1909 word = text_.selectNextWordToSpellcheck(value);
1910 if (word.word().empty())
1911 bv->unlockInset(const_cast<InsetText *>(this));
1918 void InsetText::selectSelectedWord(BufferView * bv)
1920 if (the_locking_inset) {
1921 the_locking_inset->selectSelectedWord(bv);
1924 getLyXText(bv)->selectSelectedWord();
1925 updateLocal(bv, false);
1929 bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length)
1931 if (the_locking_inset) {
1932 if (the_locking_inset->nextChange(bv, length))
1934 text_.cursorRight(true);
1936 lyx::find::SearchResult result =
1937 lyx::find::findNextChange(bv, &text_, length);
1939 if (result == lyx::find::SR_FOUND) {
1940 LyXCursor cur = text_.cursor;
1941 bv->unlockInset(bv->theLockingInset());
1942 if (bv->lockInset(this))
1945 text_.setSelectionRange(length);
1946 updateLocal(bv, false);
1948 return result != lyx::find::SR_NOT_FOUND;
1952 bool InsetText::searchForward(BufferView * bv, string const & str,
1955 if (the_locking_inset) {
1956 if (the_locking_inset->searchForward(bv, str, cs, mw))
1958 text_.cursorRight(true);
1960 lyx::find::SearchResult result =
1961 lyx::find::find(bv, &text_, str, true, cs, mw);
1963 if (result == lyx::find::SR_FOUND) {
1964 LyXCursor cur = text_.cursor;
1965 bv->unlockInset(bv->theLockingInset());
1966 if (bv->lockInset(this))
1969 text_.setSelectionRange(str.length());
1970 updateLocal(bv, false);
1972 return result != lyx::find::SR_NOT_FOUND;
1976 bool InsetText::searchBackward(BufferView * bv, string const & str,
1979 if (the_locking_inset) {
1980 if (the_locking_inset->searchBackward(bv, str, cs, mw))
1984 ParagraphList::iterator pit = paragraphs.begin();
1985 ParagraphList::iterator pend = paragraphs.end();
1987 while (boost::next(pit) != pend)
1990 text_.setCursor(pit, pit->size());
1992 lyx::find::SearchResult result =
1993 lyx::find::find(bv, &text_, str, false, cs, mw);
1995 if (result == lyx::find::SR_FOUND) {
1996 LyXCursor cur = text_.cursor;
1997 bv->unlockInset(bv->theLockingInset());
1998 if (bv->lockInset(this))
2001 text_.setSelectionRange(str.length());
2002 updateLocal(bv, false);
2004 return result != lyx::find::SR_NOT_FOUND;
2008 bool InsetText::checkInsertChar(LyXFont & font)
2010 return owner() ? owner()->checkInsertChar(font) : true;
2014 void InsetText::collapseParagraphs(BufferView * bv)
2016 while (paragraphs.size() > 1) {
2017 ParagraphList::iterator first_par = paragraphs.begin();
2018 ParagraphList::iterator next_par = boost::next(first_par);
2019 size_t const first_par_size = first_par->size();
2021 if (!first_par->empty() &&
2022 !next_par->empty() &&
2023 !first_par->isSeparator(first_par_size - 1)) {
2024 first_par->insertChar(first_par_size, ' ');
2027 if (text_.selection.set()) {
2028 if (text_.selection.start.par() == next_par) {
2029 text_.selection.start.par(first_par);
2030 text_.selection.start.pos(
2031 text_.selection.start.pos() + first_par_size);
2033 if (text_.selection.end.par() == next_par) {
2034 text_.selection.end.par(first_par);
2035 text_.selection.end.pos(
2036 text_.selection.end.pos() + first_par_size);
2040 mergeParagraph(bv->buffer()->params, paragraphs, first_par);
2046 void InsetText::getDrawFont(LyXFont & font) const
2050 owner()->getDrawFont(font);
2054 void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
2056 #warning FIXME Check if Changes stuff needs changing here. (Lgb)
2057 // And it probably does. You have to take a look at this John. (Lgb)
2058 #warning John, have a look here. (Lgb)
2059 ParagraphList::iterator pit = plist.begin();
2060 ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit);
2062 mergeParagraph(buffer->params, paragraphs, boost::prior(ins));
2064 ParagraphList::iterator pend = plist.end();
2065 for (; pit != pend; ++pit)
2066 paragraphs.push_back(*pit);
2072 void InsetText::addPreview(PreviewLoader & loader) const
2074 ParagraphList::const_iterator pit = paragraphs.begin();
2075 ParagraphList::const_iterator pend = paragraphs.end();
2077 for (; pit != pend; ++pit) {
2078 InsetList::const_iterator it = pit->insetlist.begin();
2079 InsetList::const_iterator end = pit->insetlist.end();
2080 for (; it != end; ++it)
2081 it->inset->addPreview(loader);