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;
157 setParagraphData(ins->paragraphs);
158 autoBreakRows = ins->autoBreakRows;
159 drawFrame_ = ins->drawFrame_;
160 frame_color = ins->frame_color;
162 textwidth_ = 0; // broken
164 frame_color = LColor::insetframe;
165 autoBreakRows = false;
167 the_locking_inset = 0;
168 for_each(paragraphs.begin(), paragraphs.end(),
169 boost::bind(&Paragraph::setInsetOwner, _1, this));
175 old_par = paragraphs.end();
176 sstate.cursor.par(paragraphs.end());
177 in_insetAllowed = false;
181 void InsetText::clear(bool just_mark_erased)
183 if (just_mark_erased) {
184 ParagraphList::iterator it = paragraphs.begin();
185 ParagraphList::iterator end = paragraphs.end();
186 for (; it != end; ++it) {
192 // This is a gross hack...
193 LyXLayout_ptr old_layout = paragraphs.begin()->layout();
196 paragraphs.push_back(Paragraph());
197 paragraphs.begin()->setInsetOwner(this);
198 paragraphs.begin()->layout(old_layout);
204 auto_ptr<InsetBase> InsetText::clone() const
206 return auto_ptr<InsetBase>(new InsetText(*this));
210 void InsetText::write(Buffer const * buf, ostream & os) const
213 writeParagraphData(buf, os);
217 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
219 ParagraphList::const_iterator it = paragraphs.begin();
220 ParagraphList::const_iterator end = paragraphs.end();
221 Paragraph::depth_type dth = 0;
222 for (; it != end; ++it) {
223 it->write(buf, os, buf->params, dth);
228 void InsetText::read(Buffer const * buf, LyXLex & lex)
231 Paragraph::depth_type depth = 0;
235 if (buf->params.tracking_changes)
236 paragraphs.begin()->trackChanges();
238 // delete the initial paragraph
240 ParagraphList::iterator pit = paragraphs.begin();
244 token = lex.getString();
247 if (token == "\\end_inset") {
251 if (token == "\\end_document") {
252 lex.printError("\\end_document read in inset! Error in document!");
257 const_cast<Buffer*>(buf)->readParagraph(lex, token, paragraphs, pit, depth);
260 pit = paragraphs.begin();
261 ParagraphList::iterator const end = paragraphs.end();
262 for (; pit != end; ++pit)
263 pit->setInsetOwner(this);
265 if (token != "\\end_inset") {
266 lex.printError("Missing \\end_inset at this point. "
272 void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
274 //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
276 textwidth_ = mi.base.textwidth;
277 BufferView * bv = mi.base.bv;
279 text_.metrics(mi, dim);
280 dim.asc += TEXT_TO_INSET_OFFSET;
281 dim.des += TEXT_TO_INSET_OFFSET;
282 dim.wid += 2 * TEXT_TO_INSET_OFFSET;
283 dim.wid = max(dim.wid, 10);
288 int InsetText::textWidth() const
294 void InsetText::draw(PainterInfo & pi, int x, int baseline) const
296 // update our idea of where we are. Clearly, we should
297 // not have to know this information.
300 int const start_x = x;
302 BufferView * bv = pi.base.bv;
303 Painter & pain = pi.pain;
305 // repaint the background if needed
306 if (backgroundColor() != LColor::background)
307 clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline);
309 // no draw is necessary !!!
310 if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) {
311 top_baseline = baseline;
320 top_baseline = baseline;
321 top_y = baseline - dim_.asc;
323 if (the_locking_inset && cpar() == inset_par && cpos() == inset_pos) {
324 inset_x = cix() - x + drawTextXOffset;
325 inset_y = ciy() + drawTextYOffset;
328 x += TEXT_TO_INSET_OFFSET;
330 RowList::iterator rit = text_.rows().begin();
331 RowList::iterator end = text_.rows().end();
333 int y_offset = baseline - rit->ascent_of_text();
334 int y2 = pain.paperHeight();
337 while (rit != end && y + rit->height() <= 0) {
339 first += rit->height();
343 text_.top_y(-y_offset);
351 int yo = y_offset + first;
353 paintRows(*bv, text_, rit, x, 0, yo, y2, yo);
355 if (drawFrame_ == ALWAYS || (drawFrame_ == LOCKED && locked))
356 drawFrame(pain, int(start_x));
360 void InsetText::drawFrame(Painter & pain, int x) const
362 int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
363 int const frame_x = x + ttoD2;
364 int const frame_y = top_baseline - dim_.asc + ttoD2;
365 int const frame_w = dim_.wid - TEXT_TO_INSET_OFFSET;
366 int const frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET;
367 pain.rectangle(frame_x, frame_y, frame_w, frame_h, frame_color);
371 void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/)
376 if (!autoBreakRows && paragraphs.size() > 1)
377 collapseParagraphs(bv);
379 text_.partialRebreak();
380 if (!text_.selection.set())
381 text_.selection.cursor = text_.cursor;
385 bv->owner()->view_state_changed();
386 bv->owner()->updateMenubar();
387 bv->owner()->updateToolbar();
388 if (old_par != cpar()) {
389 bv->owner()->setLayout(cpar()->layout()->name());
395 string const InsetText::editMessage() const
397 return _("Opened Text Inset");
401 void InsetText::insetUnlock(BufferView * bv)
403 if (the_locking_inset) {
404 the_locking_inset->insetUnlock(bv);
405 the_locking_inset = 0;
406 updateLocal(bv, false);
411 if (text_.selection.set()) {
412 text_.clearSelection();
413 } else if (owner()) {
414 bv->owner()->setLayout(owner()->getLyXText(bv)
415 ->cursor.par()->layout()->name());
417 bv->owner()->setLayout(bv->text->cursor.par()->layout()->name());
418 // hack for deleteEmptyParMech
419 ParagraphList::iterator first_par = paragraphs.begin();
420 if (!first_par->empty()) {
421 text_.setCursor(first_par, 0);
422 } else if (paragraphs.size() > 1) {
423 text_.setCursor(boost::next(first_par), 0);
428 void InsetText::lockInset(BufferView * bv)
431 the_locking_inset = 0;
432 inset_pos = inset_x = inset_y = 0;
433 inset_boundary = false;
434 inset_par = paragraphs.end();
435 old_par = paragraphs.end();
436 text_.setCursorIntern(paragraphs.begin(), 0);
437 text_.clearSelection();
439 // If the inset is empty set the language of the current font to the
440 // language to the surronding text (if different).
441 if (paragraphs.begin()->empty() && paragraphs.size() == 1 &&
442 bv->getParentLanguage(this) != text_.current_font.language()) {
443 LyXFont font(LyXFont::ALL_IGNORE);
444 font.setLanguage(bv->getParentLanguage(this));
445 setFont(bv, font, false);
450 void InsetText::lockInset(BufferView * /*bv*/, UpdatableInset * inset)
452 the_locking_inset = inset;
453 inset_x = cix() - top_x + drawTextXOffset;
454 inset_y = ciy() + drawTextYOffset;
457 inset_boundary = cboundary();
461 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
463 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
464 << inset << "): " << endl;
467 if (!the_locking_inset) {
468 ParagraphList::iterator pit = paragraphs.begin();
469 ParagraphList::iterator pend = paragraphs.end();
471 int const id = inset->id();
472 for (; pit != pend; ++pit) {
473 InsetList::iterator it = pit->insetlist.begin();
474 InsetList::iterator const end = pit->insetlist.end();
475 for (; it != end; ++it) {
476 if (it->inset == inset) {
477 lyxerr << "InsetText::lockInsetInInset: 1 a" << endl;
478 text_.setCursorIntern(pit, it->pos);
479 lyxerr << "InsetText::lockInsetInInset: 1 b" << endl;
480 lyxerr << "bv: " << bv << " inset: " << inset << endl;
481 lockInset(bv, inset);
482 lyxerr << "InsetText::lockInsetInInset: 1 c" << endl;
485 if (it->inset->getInsetFromID(id)) {
486 lyxerr << "InsetText::lockInsetInInset: 2" << endl;
487 text_.setCursorIntern(pit, it->pos);
488 it->inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
489 return the_locking_inset->lockInsetInInset(bv, inset);
493 lyxerr << "InsetText::lockInsetInInset: 3" << endl;
496 if (inset == cpar()->getInset(cpos())) {
497 lyxerr[Debug::INSETS] << "OK" << endl;
498 lockInset(bv, inset);
502 if (the_locking_inset && the_locking_inset == inset) {
503 if (cpar() == inset_par && cpos() == inset_pos) {
504 lyxerr[Debug::INSETS] << "OK" << endl;
505 inset_x = cix() - top_x + drawTextXOffset;
506 inset_y = ciy() + drawTextYOffset;
508 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
510 } else if (the_locking_inset) {
511 lyxerr[Debug::INSETS] << "MAYBE" << endl;
512 return the_locking_inset->lockInsetInInset(bv, inset);
514 lyxerr[Debug::INSETS] << "NOT OK" << endl;
519 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
522 if (!the_locking_inset)
524 if (the_locking_inset == inset) {
525 the_locking_inset->insetUnlock(bv);
526 getLyXText(bv)->updateInset(inset);
527 the_locking_inset = 0;
529 moveRightIntern(bv, true, false);
530 old_par = paragraphs.end(); // force layout setting
534 updateLocal(bv, false);
537 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
541 void InsetText::lfunMousePress(FuncRequest const & cmd)
545 // use this to check mouse motion for selection!
549 BufferView * bv = cmd.view();
550 FuncRequest cmd1 = cmd;
556 int tmp_x = cmd.x - drawTextXOffset;
557 int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
558 InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
560 if (the_locking_inset) {
561 if (the_locking_inset == inset) {
562 the_locking_inset->localDispatch(cmd1);
565 // otherwise only unlock the_locking_inset
566 the_locking_inset->insetUnlock(bv);
567 the_locking_inset = 0;
570 no_selection = false;
572 if (bv->theLockingInset()) {
573 if (isHighlyEditableInset(inset)) {
574 // We just have to lock the inset before calling a
576 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
577 if (!bv->lockInset(uinset)) {
578 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
580 inset->localDispatch(cmd1);
581 if (the_locking_inset)
582 updateLocal(bv, false);
587 bool paste_internally = false;
588 if (cmd.button() == mouse_button::button2 && getLyXText(bv)->selection.set()) {
589 localDispatch(FuncRequest(bv, LFUN_COPY));
590 paste_internally = true;
592 int old_top_y = text_.top_y();
594 text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
596 // set the selection cursor!
597 text_.selection.cursor = text_.cursor;
598 text_.cursor.x_fix(text_.cursor.x());
600 text_.clearSelection();
601 updateLocal(bv, false);
603 bv->owner()->setLayout(cpar()->layout()->name());
605 // we moved the view we cannot do mouse selection in this case!
606 if (getLyXText(bv)->top_y() != old_top_y)
609 // Insert primary selection with middle mouse
610 // if there is a local selection in the current buffer,
612 if (cmd.button() == mouse_button::button2) {
613 if (paste_internally)
614 localDispatch(FuncRequest(bv, LFUN_PASTE));
616 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
619 getLyXText(bv)->clearSelection();
624 bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
626 BufferView * bv = cmd.view();
627 FuncRequest cmd1 = cmd;
632 if (the_locking_inset)
633 return the_locking_inset->localDispatch(cmd1);
635 int tmp_x = cmd.x - drawTextXOffset;
636 int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
637 InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
640 // This code should probably be removed now. Simple insets
641 // (!highlyEditable) can actually take the localDispatch,
642 // and turn it into edit() if necessary. But we still
643 // need to deal properly with the whole relative vs.
644 // absolute mouse co-ords thing in a realiable, sensible way
646 if (isHighlyEditableInset(inset))
647 ret = inset->localDispatch(cmd1);
649 inset_x = cix(bv) - top_x + drawTextXOffset;
650 inset_y = ciy() + drawTextYOffset;
651 cmd1.x = cmd.x - inset_x;
652 cmd1.y = cmd.x - inset_y;
653 inset->edit(bv, cmd1.x, cmd1.y, cmd.button());
657 ret = inset->localDispatch(cmd1);
658 updateLocal(bv, false);
665 void InsetText::lfunMouseMotion(FuncRequest const & cmd)
667 FuncRequest cmd1 = cmd;
671 if (the_locking_inset) {
672 the_locking_inset->localDispatch(cmd1);
676 if (no_selection || (mouse_x == cmd.x && mouse_y == cmd.y))
679 BufferView * bv = cmd.view();
680 LyXCursor cur = text_.cursor;
681 text_.setCursorFromCoordinates
682 (cmd.x - drawTextXOffset, cmd.y + dim_.asc);
683 text_.cursor.x_fix(text_.cursor.x());
684 if (cur == text_.cursor)
686 text_.setSelection();
687 updateLocal(bv, false);
691 InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
693 BufferView * bv = cmd.view();
696 switch (cmd.action) {
697 case LFUN_INSET_EDIT: {
698 UpdatableInset::localDispatch(cmd);
700 if (!bv->lockInset(this)) {
701 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
706 the_locking_inset = 0;
710 inset_boundary = false;
711 inset_par = paragraphs.end();
712 old_par = paragraphs.end();
715 if (cmd.argument.size()) {
716 if (cmd.argument == "left")
717 text_.setCursorIntern(paragraphs.begin(), 0);
719 ParagraphList::iterator it = boost::prior(paragraphs.end());
720 text_.setCursor(it, it->size());
723 int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
724 // we put here -1 and not button as now the button in the
725 // edit call should not be needed we will fix this in 1.3.x
726 // cycle hopefully (Jug 20020509)
727 // FIXME: GUII I've changed this to none: probably WRONG
728 if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) {
729 text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
731 text_.cursor.x_fix(text_.cursor.x());
735 text_.clearSelection();
738 // If the inset is empty set the language of the current font to the
739 // language to the surronding text (if different).
740 if (paragraphs.begin()->empty() &&
741 paragraphs.size() == 1 &&
742 bv->getParentLanguage(this) != text_.current_font.language())
744 LyXFont font(LyXFont::ALL_IGNORE);
745 font.setLanguage(bv->getParentLanguage(this));
746 setFont(bv, font, false);
749 updateLocal(bv, false);
750 // Tell the paragraph dialog that we've entered an insettext.
751 bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
755 case LFUN_MOUSE_PRESS:
759 case LFUN_MOUSE_MOTION:
760 lfunMouseMotion(cmd);
763 case LFUN_MOUSE_RELEASE:
764 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
770 bool was_empty = (paragraphs.begin()->empty() &&
771 paragraphs.size() == 1);
773 no_selection = false;
774 RESULT result = UpdatableInset::localDispatch(cmd);
775 if (result != UNDISPATCHED)
779 if (cmd.action < 0 && cmd.argument.empty())
782 if (the_locking_inset) {
783 result = the_locking_inset->localDispatch(cmd);
784 if (result == DISPATCHED_NOUPDATE)
786 if (result == DISPATCHED) {
787 updateLocal(bv, false);
790 if (result >= FINISHED) {
793 moveRightIntern(bv, false, false);
798 if (result >= FINISHED) {
799 updateLocal(bv, false);
800 bv->unlockInset(this);
804 result = moveDown(bv);
805 if (result >= FINISHED) {
806 updateLocal(bv, false);
807 bv->unlockInset(this);
814 the_locking_inset = 0;
815 updateLocal(bv, false);
816 // make sure status gets reset immediately
817 bv->owner()->clearMessage();
821 bool updflag = false;
823 switch (cmd.action) {
826 case LFUN_SELFINSERT:
827 if (bv->buffer()->isReadonly()) {
828 // setErrorMessage(N_("Document is read only"));
831 if (!cmd.argument.empty()) {
832 /* Automatically delete the currently selected
833 * text and replace it with what is being
834 * typed in now. Depends on lyxrc settings
835 * "auto_region_delete", which defaults to
838 // This should not be needed here and is also WRONG!
839 recordUndo(bv, Undo::INSERT, text_.cursor.par());
842 if (lyxrc.auto_region_delete) {
843 if (text_.selection.set()) {
844 text_.cutSelection(false, false);
847 text_.clearSelection();
848 for (string::size_type i = 0; i < cmd.argument.length(); ++i) {
849 bv->owner()->getIntl().getTransManager().
850 TranslateAndInsert(cmd.argument[i], &text_);
853 text_.selection.cursor = text_.cursor;
855 result = DISPATCHED_NOUPDATE;
858 // cursor movements that need special handling
861 result = moveRight(bv);
866 result = moveLeft(bv);
870 result = moveDown(bv);
878 if (crow() == text_.rows().begin())
879 result = FINISHED_UP;
881 text_.cursorPrevious();
882 text_.clearSelection();
883 result = DISPATCHED_NOUPDATE;
888 if (boost::next(crow()) == text_.rows().end())
889 result = FINISHED_DOWN;
892 text_.clearSelection();
893 result = DISPATCHED_NOUPDATE;
897 case LFUN_BACKSPACE: {
898 if (text_.selection.set())
899 text_.cutSelection(true, false);
907 if (text_.selection.set()) {
908 text_.cutSelection(true, false);
917 text_.cutSelection(true, true);
924 text_.copySelection();
927 case LFUN_PASTESELECTION:
929 string const clip(bv->getClipboard());
933 if (cmd.argument == "paragraph") {
934 text_.insertStringAsParagraphs(clip);
936 text_.insertStringAsLines(clip);
939 text_.clearSelection();
946 if (!autoBreakRows) {
947 if (CutAndPaste::nrOfParagraphs() > 1) {
949 #warning FIXME horrendously bad UI
951 Alert::error(_("Paste failed"), _("Cannot include more than one paragraph."));
956 replaceSelection(bv->getLyXText());
957 size_t sel_index = 0;
958 string const & arg = cmd.argument;
959 if (isStrUnsignedInt(arg)) {
960 size_t const paste_arg = strToUnsignedInt(arg);
961 #warning FIXME Check if the arg is in the domain of available selections.
962 sel_index = paste_arg;
964 text_.pasteSelection(sel_index);
966 text_.clearSelection();
971 case LFUN_BREAKPARAGRAPH:
972 if (!autoBreakRows) {
976 replaceSelection(bv->getLyXText());
977 text_.breakParagraph(paragraphs, 0);
981 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
982 if (!autoBreakRows) {
986 replaceSelection(bv->getLyXText());
987 text_.breakParagraph(paragraphs, 1);
991 case LFUN_BREAKLINE: {
992 if (!autoBreakRows) {
997 replaceSelection(bv->getLyXText());
998 text_.insertInset(new InsetNewline);
1004 // do not set layouts on non breakable textinsets
1005 if (autoBreakRows) {
1006 string cur_layout = cpar()->layout()->name();
1008 // Derive layout number from given argument (string)
1009 // and current buffer's textclass (number). */
1010 LyXTextClass const & tclass =
1011 bv->buffer()->params.getLyXTextClass();
1012 string layout = cmd.argument;
1013 bool hasLayout = tclass.hasLayout(layout);
1015 // If the entry is obsolete, use the new one instead.
1017 string const & obs =
1018 tclass[layout]->obsoleted_by();
1023 // see if we found the layout number:
1025 FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
1026 bv->owner()->dispatch(lf);
1030 if (cur_layout != layout) {
1031 cur_layout = layout;
1032 text_.setLayout(layout);
1033 bv->owner()->setLayout(cpar()->layout()->name());
1037 // reset the layout box
1038 bv->owner()->setLayout(cpar()->layout()->name());
1041 case LFUN_PARAGRAPH_SPACING:
1042 // This one is absolutely not working. When fiddling with this
1043 // it also seems to me that the paragraphs inside the insettext
1044 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1045 // FIXME: how old is this comment ? ...
1047 ParagraphList::iterator pit = text_.cursor.par();
1048 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
1049 float cur_value = 1.0;
1050 if (cur_spacing == Spacing::Other) {
1051 cur_value = pit->params().spacing().getValue();
1054 istringstream istr(STRCONV(cmd.argument));
1057 Spacing::Space new_spacing = cur_spacing;
1058 float new_value = cur_value;
1060 lyxerr << "Missing argument to `paragraph-spacing'"
1062 } else if (tmp == "single") {
1063 new_spacing = Spacing::Single;
1064 } else if (tmp == "onehalf") {
1065 new_spacing = Spacing::Onehalf;
1066 } else if (tmp == "double") {
1067 new_spacing = Spacing::Double;
1068 } else if (tmp == "other") {
1069 new_spacing = Spacing::Other;
1072 lyxerr << "new_value = " << tmpval << endl;
1075 } else if (tmp == "default") {
1076 new_spacing = Spacing::Default;
1078 lyxerr << _("Unknown spacing argument: ")
1079 << cmd.argument << endl;
1081 if (cur_spacing != new_spacing || cur_value != new_value) {
1082 pit->params().spacing(Spacing(new_spacing, new_value));
1089 if (!bv->dispatch(cmd))
1090 result = UNDISPATCHED;
1094 updateLocal(bv, updflag);
1096 /// If the action has deleted all text in the inset, we need to change the
1097 // language to the language of the surronding text.
1098 if (!was_empty && paragraphs.begin()->empty() &&
1099 paragraphs.size() == 1) {
1100 LyXFont font(LyXFont::ALL_IGNORE);
1101 font.setLanguage(bv->getParentLanguage(this));
1102 setFont(bv, font, false);
1105 if (result >= FINISHED)
1106 bv->unlockInset(this);
1108 if (result == DISPATCHED_NOUPDATE)
1109 result = DISPATCHED;
1114 int InsetText::latex(Buffer const * buf, ostream & os,
1115 LatexRunParams const & runparams) const
1118 latexParagraphs(buf, paragraphs, os, texrow, runparams);
1119 return texrow.rows();
1123 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1125 unsigned int lines = 0;
1127 ParagraphList::const_iterator beg = paragraphs.begin();
1128 ParagraphList::const_iterator end = paragraphs.end();
1129 ParagraphList::const_iterator it = beg;
1130 for (; it != end; ++it) {
1131 string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
1132 lines += lyx::count(tmp.begin(), tmp.end(), '\n');
1139 int InsetText::linuxdoc(Buffer const * buf, ostream & os) const
1141 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1142 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1144 // There is a confusion between the empty paragraph and the default paragraph
1145 // The default paragraph is <p></p>, the empty paragraph is *empty*
1146 // Since none of the floats of linuxdoc accepts standard paragraphs
1147 // I disable them. I don't expect problems. (jamatos 2003/07/27)
1148 for (; pit != pend; ++pit) {
1149 const string name = pit->layout()->latexname();
1151 sgml::openTag(os, 1, 0, name);
1152 buf->simpleLinuxDocOnePar(os, pit, 0);
1154 sgml::closeTag(os, 1, 0, name);
1160 int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1162 unsigned int lines = 0;
1164 vector<string> environment_stack(10);
1165 vector<string> environment_inner(10);
1167 int const command_depth = 0;
1170 Paragraph::depth_type depth = 0; // paragraph depth
1172 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1173 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1175 for (; pit != pend; ++pit) {
1177 int desc_on = 0; // description mode
1179 LyXLayout_ptr const & style = pit->layout();
1181 // environment tag closing
1182 for (; depth > pit->params().depth(); --depth) {
1183 if (environment_inner[depth] != "!-- --") {
1184 item_name = "listitem";
1185 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1186 if (environment_inner[depth] == "varlistentry")
1187 lines += sgml::closeTag(os, depth+command_depth, mixcont, environment_inner[depth]);
1189 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1190 environment_stack[depth].erase();
1191 environment_inner[depth].erase();
1194 if (depth == pit->params().depth()
1195 && environment_stack[depth] != style->latexname()
1196 && !environment_stack[depth].empty()) {
1197 if (environment_inner[depth] != "!-- --") {
1198 item_name= "listitem";
1199 lines += sgml::closeTag(os, command_depth+depth, mixcont, item_name);
1200 if (environment_inner[depth] == "varlistentry")
1201 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1204 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1206 environment_stack[depth].erase();
1207 environment_inner[depth].erase();
1210 // Write opening SGML tags.
1211 switch (style->latextype) {
1212 case LATEX_PARAGRAPH:
1213 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1217 buf->error(ErrorItem(_("Error"), _("LatexType Command not allowed here.\n"), pit->id(), 0, pit->size()));
1221 case LATEX_ENVIRONMENT:
1222 case LATEX_ITEM_ENVIRONMENT:
1223 if (depth < pit->params().depth()) {
1224 depth = pit->params().depth();
1225 environment_stack[depth].erase();
1228 if (environment_stack[depth] != style->latexname()) {
1229 if (environment_stack.size() == depth + 1) {
1230 environment_stack.push_back("!-- --");
1231 environment_inner.push_back("!-- --");
1233 environment_stack[depth] = style->latexname();
1234 environment_inner[depth] = "!-- --";
1235 lines += sgml::openTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1237 if (environment_inner[depth] != "!-- --") {
1238 item_name= "listitem";
1239 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1240 if (environment_inner[depth] == "varlistentry")
1241 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1245 if (style->latextype == LATEX_ENVIRONMENT) {
1246 if (!style->latexparam().empty()) {
1247 if (style->latexparam() == "CDATA")
1250 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexparam());
1255 desc_on = (style->labeltype == LABEL_MANUAL);
1257 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1258 lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
1260 item_name = desc_on ? "term" : "para";
1261 lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, item_name);
1265 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1269 buf->simpleDocBookOnePar(os, pit, desc_on, depth + 1 + command_depth);
1272 // write closing SGML tags
1273 switch (style->latextype) {
1274 case LATEX_ENVIRONMENT:
1275 if (!style->latexparam().empty()) {
1276 if (style->latexparam() == "CDATA")
1279 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexparam());
1282 case LATEX_ITEM_ENVIRONMENT:
1283 if (desc_on == 1) break;
1285 lines += sgml::closeTag(os, depth + 1 + command_depth, mixcont, end_tag);
1287 case LATEX_PARAGRAPH:
1288 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1291 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1297 for (int d = depth; d >= 0; --d) {
1298 if (!environment_stack[depth].empty()) {
1299 if (environment_inner[depth] != "!-- --") {
1300 item_name = "listitem";
1301 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1302 if (environment_inner[depth] == "varlistentry")
1303 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1306 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1314 void InsetText::validate(LaTeXFeatures & features) const
1316 for_each(paragraphs.begin(), paragraphs.end(),
1317 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1321 void InsetText::getCursor(BufferView & bv, int & x, int & y) const
1323 if (the_locking_inset) {
1324 the_locking_inset->getCursor(bv, x, y);
1328 y = cy() + InsetText::y();
1332 void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
1334 if (the_locking_inset) {
1335 the_locking_inset->getCursorPos(bv, x, y);
1338 x = cx() - top_x - TEXT_TO_INSET_OFFSET;
1339 y = cy() - TEXT_TO_INSET_OFFSET;
1343 int InsetText::insetInInsetY() const
1345 if (!the_locking_inset)
1348 return inset_y + the_locking_inset->insetInInsetY();
1352 void InsetText::fitInsetCursor(BufferView * bv) const
1354 if (the_locking_inset) {
1355 the_locking_inset->fitInsetCursor(bv);
1359 LyXFont const font = text_.getFont(cpar(), cpos());
1361 int const asc = font_metrics::maxAscent(font);
1362 int const desc = font_metrics::maxDescent(font);
1364 bv->fitLockedInsetCursor(cx(), cy(), asc, desc);
1368 InsetOld::RESULT InsetText::moveRight(BufferView * bv)
1370 if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1371 return moveLeftIntern(bv, false, true, false);
1373 return moveRightIntern(bv, true, true, false);
1377 InsetOld::RESULT InsetText::moveLeft(BufferView * bv)
1379 if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1380 return moveRightIntern(bv, true, true, false);
1382 return moveLeftIntern(bv, false, true, false);
1387 InsetText::moveRightIntern(BufferView * bv, bool front,
1388 bool activate_inset, bool selecting)
1390 ParagraphList::iterator c_par = cpar();
1392 if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size())
1393 return FINISHED_RIGHT;
1394 if (activate_inset && checkAndActivateInset(bv, front))
1396 text_.cursorRight(bv);
1398 text_.clearSelection();
1399 return DISPATCHED_NOUPDATE;
1404 InsetText::moveLeftIntern(BufferView * bv, bool front,
1405 bool activate_inset, bool selecting)
1407 if (cpar() == paragraphs.begin() && cpos() <= 0)
1409 text_.cursorLeft(bv);
1411 text_.clearSelection();
1412 if (activate_inset && checkAndActivateInset(bv, front))
1414 return DISPATCHED_NOUPDATE;
1418 InsetOld::RESULT InsetText::moveUp(BufferView * bv)
1420 if (crow() == text_.rows().begin())
1423 text_.clearSelection();
1424 return DISPATCHED_NOUPDATE;
1428 InsetOld::RESULT InsetText::moveDown(BufferView * bv)
1430 if (boost::next(crow()) == text_.rows().end())
1431 return FINISHED_DOWN;
1432 text_.cursorDown(bv);
1433 text_.clearSelection();
1434 return DISPATCHED_NOUPDATE;
1438 bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
1440 if (the_locking_inset) {
1441 if (the_locking_inset->insetAllowed(inset))
1442 return the_locking_inset->insertInset(bv, inset);
1445 inset->setOwner(this);
1446 text_.insertInset(inset);
1448 updateLocal(bv, true);
1453 bool InsetText::insetAllowed(InsetOld::Code code) const
1455 // in_insetAllowed is a really gross hack,
1456 // to allow us to call the owner's insetAllowed
1457 // without stack overflow, which can happen
1458 // when the owner uses InsetCollapsable::insetAllowed()
1460 if (in_insetAllowed)
1462 in_insetAllowed = true;
1463 if (the_locking_inset)
1464 ret = the_locking_inset->insetAllowed(code);
1466 ret = owner()->insetAllowed(code);
1467 in_insetAllowed = false;
1472 UpdatableInset * InsetText::getLockingInset() const
1474 return the_locking_inset ? the_locking_inset->getLockingInset() :
1475 const_cast<InsetText *>(this);
1479 UpdatableInset * InsetText::getFirstLockingInsetOfType(InsetOld::Code c)
1483 if (the_locking_inset)
1484 return the_locking_inset->getFirstLockingInsetOfType(c);
1489 bool InsetText::showInsetDialog(BufferView * bv) const
1491 if (the_locking_inset)
1492 return the_locking_inset->showInsetDialog(bv);
1497 void InsetText::getLabelList(std::vector<string> & list) const
1499 ParagraphList::const_iterator pit = paragraphs.begin();
1500 ParagraphList::const_iterator pend = paragraphs.end();
1501 for (; pit != pend; ++pit) {
1502 InsetList::const_iterator beg = pit->insetlist.begin();
1503 InsetList::const_iterator end = pit->insetlist.end();
1504 for (; beg != end; ++beg)
1505 beg->inset->getLabelList(list);
1510 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1513 if (the_locking_inset) {
1514 the_locking_inset->setFont(bv, font, toggleall, selectall);
1518 if ((paragraphs.size() == 1 && paragraphs.begin()->empty())
1519 || cpar()->empty()) {
1520 text_.setFont(font, toggleall);
1525 if (text_.selection.set())
1526 recordUndo(bv, Undo::ATOMIC, text_.cursor.par());
1530 text_.selection.cursor = text_.cursor;
1531 text_.cursorBottom();
1532 text_.setSelection();
1535 text_.toggleFree(font, toggleall);
1538 text_.clearSelection();
1541 updateLocal(bv, true);
1545 bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
1547 InsetOld * inset = cpar()->getInset(cpos());
1548 if (!isHighlyEditableInset(inset))
1550 FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
1551 inset->localDispatch(cmd);
1552 if (!the_locking_inset)
1554 updateLocal(bv, false);
1559 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1560 mouse_button::state button)
1562 x -= drawTextXOffset;
1564 int dummyy = y + dim_.asc;
1565 InsetOld * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy);
1566 // we only do the edit() call if the inset was hit by the mouse
1567 // or if it is a highly editable inset. So we should call this
1568 // function from our own edit with button < 0.
1569 // FIXME: GUII jbl. I've changed this to ::none for now which is probably
1571 if (button == mouse_button::none && !isHighlyEditableInset(inset))
1580 inset_x = cix() - top_x + drawTextXOffset;
1581 inset_y = ciy() + drawTextYOffset;
1582 FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
1583 inset->localDispatch(cmd);
1584 if (!the_locking_inset)
1586 updateLocal(bv, false);
1591 void InsetText::setParagraphData(ParagraphList const & plist)
1593 // we have to unlock any locked inset otherwise we're in troubles
1594 the_locking_inset = 0;
1596 // But it it makes no difference that is a lot better.
1598 // See if this can be simplified when std::list is in effect.
1601 ParagraphList::const_iterator it = plist.begin();
1602 ParagraphList::const_iterator end = plist.end();
1603 for (; it != end; ++it) {
1604 paragraphs.push_back(*it);
1605 paragraphs.back().setInsetOwner(this);
1612 void InsetText::markNew(bool track_changes)
1614 ParagraphList::iterator pit = paragraphs.begin();
1615 ParagraphList::iterator pend = paragraphs.end();
1616 for (; pit != pend; ++pit) {
1617 if (track_changes) {
1618 pit->trackChanges();
1620 // no-op when not tracking
1621 pit->cleanChanges();
1627 void InsetText::setText(string const & data, LyXFont const & font)
1630 for (unsigned int i = 0; i < data.length(); ++i)
1631 paragraphs.begin()->insertChar(i, data[i], font);
1636 void InsetText::setAutoBreakRows(bool flag)
1638 if (flag != autoBreakRows) {
1639 autoBreakRows = flag;
1646 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1648 if (how != drawFrame_) {
1650 updateLocal(bv, false);
1655 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1657 if (frame_color != col) {
1659 updateLocal(bv, false);
1664 int InsetText::cx() const
1666 int x = text_.cursor.x() + 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::cix() const
1678 int x = text_.cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
1679 if (the_locking_inset) {
1680 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1681 if (font.isVisibleRightToLeft())
1682 x -= the_locking_inset->width();
1688 int InsetText::cy() const
1690 return text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET;
1694 int InsetText::ciy() const
1696 return text_.cursor.iy() - dim_.asc + TEXT_TO_INSET_OFFSET;
1700 pos_type InsetText::cpos() const
1702 return text_.cursor.pos();
1706 ParagraphList::iterator InsetText::cpar() const
1708 return text_.cursor.par();
1712 bool InsetText::cboundary() const
1714 return text_.cursor.boundary();
1718 RowList::iterator InsetText::crow() const
1720 return text_.cursorRow();
1724 LyXText * InsetText::getLyXText(BufferView const * bv,
1725 bool const recursive) const
1728 if (recursive && the_locking_inset)
1729 return the_locking_inset->getLyXText(bv, true);
1734 void InsetText::setViewCache(BufferView const * bv) const
1737 text_.bv_owner = const_cast<BufferView *>(bv);
1741 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1744 /// then remove all LyXText in text-insets
1745 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1746 const_cast<ParagraphList&>(paragraphs).end(),
1747 boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv));
1752 void InsetText::resizeLyXText(BufferView * bv, bool /*force*/) const
1754 if (paragraphs.size() == 1 && paragraphs.begin()->empty())
1763 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1764 const_cast<ParagraphList&>(paragraphs).end(),
1765 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1769 restoreLyXTextState();
1771 // seems to be unneeded
1773 if (the_locking_inset) {
1774 inset_x = cix() - top_x + drawTextXOffset;
1775 inset_y = ciy() + drawTextYOffset;
1778 text_.top_y(bv->screen().topCursorVisible(&text_));
1780 const_cast<InsetText*>(this)->updateLocal(bv, false);
1781 // this will scroll the screen such that the cursor becomes visible
1782 bv->updateScrollbar();
1788 void InsetText::reinitLyXText() const
1790 BufferView * bv = text_.bv_owner;
1797 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1798 const_cast<ParagraphList&>(paragraphs).end(),
1799 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1802 restoreLyXTextState();
1803 if (the_locking_inset) {
1804 inset_x = cix() - top_x + drawTextXOffset;
1805 inset_y = ciy() + drawTextYOffset;
1807 text_.top_y(bv->screen().topCursorVisible(&text_));
1809 // this will scroll the screen such that the cursor becomes visible
1810 bv->updateScrollbar();
1815 void InsetText::removeNewlines()
1817 bool changed = false;
1819 ParagraphList::iterator it = paragraphs.begin();
1820 ParagraphList::iterator end = paragraphs.end();
1821 for (; it != end; ++it) {
1822 for (int i = 0; i < it->size(); ++i) {
1823 if (it->isNewline(i)) {
1834 int InsetText::scroll(bool recursive) const
1836 int sx = UpdatableInset::scroll(false);
1838 if (recursive && the_locking_inset)
1839 sx += the_locking_inset->scroll(recursive);
1845 void InsetText::clearSelection(BufferView * bv)
1847 getLyXText(bv)->clearSelection();
1851 void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
1853 Painter & pain = bv->painter();
1855 int h = dim_.asc + dim_.des;
1856 int ty = baseline - dim_.asc;
1862 if (ty + h > pain.paperHeight())
1863 h = pain.paperHeight();
1864 if (top_x + drawTextXOffset + w > pain.paperWidth())
1865 w = pain.paperWidth();
1866 pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor());
1870 ParagraphList * InsetText::getParagraphs(int i) const
1872 return (i == 0) ? const_cast<ParagraphList*>(¶graphs) : 0;
1876 LyXCursor const & InsetText::cursor(BufferView * bv) const
1878 if (the_locking_inset)
1879 return the_locking_inset->cursor(bv);
1880 return getLyXText(bv)->cursor;
1884 InsetOld * InsetText::getInsetFromID(int id_arg) const
1887 return const_cast<InsetText *>(this);
1889 ParagraphList::const_iterator pit = paragraphs.begin();
1890 ParagraphList::const_iterator pend = paragraphs.end();
1891 for (; pit != pend; ++pit) {
1892 InsetList::const_iterator it = pit->insetlist.begin();
1893 InsetList::const_iterator end = pit->insetlist.end();
1894 for (; it != end; ++it) {
1895 if (it->inset->id() == id_arg)
1897 InsetOld * in = it->inset->getInsetFromID(id_arg);
1907 InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
1910 if (the_locking_inset) {
1911 word = the_locking_inset->selectNextWordToSpellcheck(bv, value);
1912 if (!word.word().empty()) {
1916 // we have to go on checking so move cursor to the next char
1917 text_.cursor.pos(text_.cursor.pos() + 1);
1919 word = text_.selectNextWordToSpellcheck(value);
1920 if (word.word().empty())
1921 bv->unlockInset(const_cast<InsetText *>(this));
1928 void InsetText::selectSelectedWord(BufferView * bv)
1930 if (the_locking_inset) {
1931 the_locking_inset->selectSelectedWord(bv);
1934 getLyXText(bv)->selectSelectedWord();
1935 updateLocal(bv, false);
1939 bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length)
1941 if (the_locking_inset) {
1942 if (the_locking_inset->nextChange(bv, length))
1944 text_.cursorRight(true);
1946 lyx::find::SearchResult result =
1947 lyx::find::findNextChange(bv, &text_, length);
1949 if (result == lyx::find::SR_FOUND) {
1950 LyXCursor cur = text_.cursor;
1951 bv->unlockInset(bv->theLockingInset());
1952 if (bv->lockInset(this))
1955 text_.setSelectionRange(length);
1956 updateLocal(bv, false);
1958 return result != lyx::find::SR_NOT_FOUND;
1962 bool InsetText::searchForward(BufferView * bv, string const & str,
1965 if (the_locking_inset) {
1966 if (the_locking_inset->searchForward(bv, str, cs, mw))
1968 text_.cursorRight(true);
1970 lyx::find::SearchResult result =
1971 lyx::find::find(bv, &text_, str, true, cs, mw);
1973 if (result == lyx::find::SR_FOUND) {
1974 LyXCursor cur = text_.cursor;
1975 bv->unlockInset(bv->theLockingInset());
1976 if (bv->lockInset(this))
1979 text_.setSelectionRange(str.length());
1980 updateLocal(bv, false);
1982 return result != lyx::find::SR_NOT_FOUND;
1986 bool InsetText::searchBackward(BufferView * bv, string const & str,
1989 if (the_locking_inset) {
1990 if (the_locking_inset->searchBackward(bv, str, cs, mw))
1994 ParagraphList::iterator pit = paragraphs.begin();
1995 ParagraphList::iterator pend = paragraphs.end();
1997 while (boost::next(pit) != pend)
2000 text_.setCursor(pit, pit->size());
2002 lyx::find::SearchResult result =
2003 lyx::find::find(bv, &text_, str, false, cs, mw);
2005 if (result == lyx::find::SR_FOUND) {
2006 LyXCursor cur = text_.cursor;
2007 bv->unlockInset(bv->theLockingInset());
2008 if (bv->lockInset(this))
2011 text_.setSelectionRange(str.length());
2012 updateLocal(bv, false);
2014 return result != lyx::find::SR_NOT_FOUND;
2018 bool InsetText::checkInsertChar(LyXFont & font)
2020 return owner() ? owner()->checkInsertChar(font) : true;
2024 void InsetText::collapseParagraphs(BufferView * bv)
2026 while (paragraphs.size() > 1) {
2027 ParagraphList::iterator first_par = paragraphs.begin();
2028 ParagraphList::iterator next_par = boost::next(first_par);
2029 size_t const first_par_size = first_par->size();
2031 if (!first_par->empty() &&
2032 !next_par->empty() &&
2033 !first_par->isSeparator(first_par_size - 1)) {
2034 first_par->insertChar(first_par_size, ' ');
2037 if (text_.selection.set()) {
2038 if (text_.selection.start.par() == next_par) {
2039 text_.selection.start.par(first_par);
2040 text_.selection.start.pos(
2041 text_.selection.start.pos() + first_par_size);
2043 if (text_.selection.end.par() == next_par) {
2044 text_.selection.end.par(first_par);
2045 text_.selection.end.pos(
2046 text_.selection.end.pos() + first_par_size);
2050 mergeParagraph(bv->buffer()->params, paragraphs, first_par);
2056 void InsetText::getDrawFont(LyXFont & font) const
2060 owner()->getDrawFont(font);
2064 void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
2066 #warning FIXME Check if Changes stuff needs changing here. (Lgb)
2067 // And it probably does. You have to take a look at this John. (Lgb)
2068 #warning John, have a look here. (Lgb)
2069 ParagraphList::iterator pit = plist.begin();
2070 ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit);
2072 mergeParagraph(buffer->params, paragraphs, boost::prior(ins));
2074 ParagraphList::iterator pend = plist.end();
2075 for (; pit != pend; ++pit)
2076 paragraphs.push_back(*pit);
2082 void InsetText::addPreview(PreviewLoader & loader) const
2084 ParagraphList::const_iterator pit = paragraphs.begin();
2085 ParagraphList::const_iterator pend = paragraphs.end();
2087 for (; pit != pend; ++pit) {
2088 InsetList::const_iterator it = pit->insetlist.begin();
2089 InsetList::const_iterator end = pit->insetlist.end();
2090 for (; it != end; ++it)
2091 it->inset->addPreview(loader);