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));
176 old_par = paragraphs.end();
177 last_drawn_width = -1;
178 sstate.cursor.par(paragraphs.end());
179 in_insetAllowed = false;
183 void InsetText::clear(bool just_mark_erased)
185 if (just_mark_erased) {
186 ParagraphList::iterator it = paragraphs.begin();
187 ParagraphList::iterator end = paragraphs.end();
188 for (; it != end; ++it) {
195 // This is a gross hack...
196 LyXLayout_ptr old_layout = paragraphs.begin()->layout();
199 paragraphs.push_back(Paragraph());
200 paragraphs.begin()->setInsetOwner(this);
201 paragraphs.begin()->layout(old_layout);
208 auto_ptr<InsetBase> InsetText::clone() const
210 return auto_ptr<InsetBase>(new InsetText(*this));
214 void InsetText::write(Buffer const * buf, ostream & os) const
217 writeParagraphData(buf, os);
221 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
223 ParagraphList::const_iterator it = paragraphs.begin();
224 ParagraphList::const_iterator end = paragraphs.end();
225 Paragraph::depth_type dth = 0;
226 for (; it != end; ++it) {
227 it->write(buf, os, buf->params, dth);
232 void InsetText::read(Buffer const * buf, LyXLex & lex)
235 Paragraph::depth_type depth = 0;
239 if (buf->params.tracking_changes)
240 paragraphs.begin()->trackChanges();
242 // delete the initial paragraph
244 ParagraphList::iterator pit = paragraphs.begin();
248 token = lex.getString();
251 if (token == "\\end_inset") {
255 if (token == "\\end_document") {
256 lex.printError("\\end_document read in inset! Error in document!");
261 const_cast<Buffer*>(buf)->readParagraph(lex, token, paragraphs, pit, depth);
264 pit = paragraphs.begin();
265 ParagraphList::iterator const end = paragraphs.end();
266 for (; pit != end; ++pit)
267 pit->setInsetOwner(this);
269 if (token != "\\end_inset") {
270 lex.printError("Missing \\end_inset at this point. "
277 void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
279 //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
281 textwidth_ = mi.base.textwidth;
282 BufferView * bv = mi.base.bv;
284 text_.metrics(mi, dim);
285 dim.asc += TEXT_TO_INSET_OFFSET;
286 dim.des += TEXT_TO_INSET_OFFSET;
287 dim.wid += 2 * TEXT_TO_INSET_OFFSET;
288 dim.wid = max(dim.wid, 10);
293 int InsetText::textWidth() const
299 void InsetText::draw(PainterInfo & pi, int x, int baseline) const
301 // update our idea of where we are. Clearly, we should
302 // not have to know this information.
305 int const start_x = x;
307 BufferView * bv = pi.base.bv;
308 Painter & pain = pi.pain;
310 // repaint the background if needed
311 if (backgroundColor() != LColor::background)
312 clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline);
314 // no draw is necessary !!!
315 if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) {
316 top_baseline = baseline;
326 top_baseline = baseline;
327 top_y = baseline - dim_.asc;
329 if (last_drawn_width != dim_.wid) {
331 last_drawn_width = dim_.wid;
334 if (the_locking_inset && cpar() == inset_par && cpos() == inset_pos) {
335 inset_x = cix() - x + drawTextXOffset;
336 inset_y = ciy() + drawTextYOffset;
339 x += TEXT_TO_INSET_OFFSET;
341 RowList::iterator rit = text_.rows().begin();
342 RowList::iterator end = text_.rows().end();
344 int y_offset = baseline - rit->ascent_of_text();
345 int y2 = pain.paperHeight();
348 while (rit != end && y + rit->height() <= 0) {
350 first += rit->height();
354 text_.top_y(-y_offset);
362 int yo = y_offset + first;
364 paintRows(*bv, text_, rit, x, 0, yo, y2, yo);
366 if (drawFrame_ == ALWAYS || (drawFrame_ == LOCKED && locked))
367 drawFrame(pain, int(start_x));
369 if (need_update != INIT)
374 void InsetText::drawFrame(Painter & pain, int x) const
376 static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
378 frame_y = top_baseline - dim_.asc + ttoD2;
379 frame_w = dim_.wid - TEXT_TO_INSET_OFFSET;
380 frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET;
381 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
386 void InsetText::setUpdateStatus(int what) const
392 void InsetText::updateLocal(BufferView * bv, bool mark_dirty)
397 if (!autoBreakRows && paragraphs.size() > 1)
398 collapseParagraphs(bv);
400 text_.partialRebreak();
401 setUpdateStatus(FULL);
402 bool flag = mark_dirty || need_update != NONE || text_.selection.set();
403 if (!text_.selection.set())
404 text_.selection.cursor = text_.cursor;
409 bv->updateInset(const_cast<InsetText *>(this));
411 bv->owner()->view_state_changed();
412 bv->owner()->updateMenubar();
413 bv->owner()->updateToolbar();
414 if (old_par != cpar()) {
415 bv->owner()->setLayout(cpar()->layout()->name());
421 string const InsetText::editMessage() const
423 return _("Opened Text Inset");
427 void InsetText::insetUnlock(BufferView * bv)
429 if (the_locking_inset) {
430 the_locking_inset->insetUnlock(bv);
431 the_locking_inset = 0;
432 updateLocal(bv, false);
438 if (text_.selection.set()) {
439 text_.clearSelection();
441 } else if (owner()) {
442 bv->owner()->setLayout(owner()->getLyXText(bv)
443 ->cursor.par()->layout()->name());
445 bv->owner()->setLayout(bv->text->cursor.par()->layout()->name());
446 // hack for deleteEmptyParMech
447 ParagraphList::iterator first_par = paragraphs.begin();
448 if (!first_par->empty()) {
449 text_.setCursor(first_par, 0);
450 } else if (paragraphs.size() > 1) {
451 text_.setCursor(boost::next(first_par), 0);
454 setUpdateStatus(code);
458 void InsetText::lockInset(BufferView * bv)
461 the_locking_inset = 0;
462 inset_pos = inset_x = inset_y = 0;
463 inset_boundary = false;
464 inset_par = paragraphs.end();
465 old_par = paragraphs.end();
466 text_.setCursorIntern(paragraphs.begin(), 0);
467 text_.clearSelection();
469 // If the inset is empty set the language of the current font to the
470 // language to the surronding text (if different).
471 if (paragraphs.begin()->empty() && paragraphs.size() == 1 &&
472 bv->getParentLanguage(this) != text_.current_font.language()) {
473 LyXFont font(LyXFont::ALL_IGNORE);
474 font.setLanguage(bv->getParentLanguage(this));
475 setFont(bv, font, false);
477 setUpdateStatus(FULL);
481 void InsetText::lockInset(BufferView * /*bv*/, UpdatableInset * inset)
483 the_locking_inset = inset;
484 inset_x = cix() - top_x + drawTextXOffset;
485 inset_y = ciy() + drawTextYOffset;
488 inset_boundary = cboundary();
492 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
494 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
495 << inset << "): " << endl;
498 if (!the_locking_inset) {
499 ParagraphList::iterator pit = paragraphs.begin();
500 ParagraphList::iterator pend = paragraphs.end();
502 int const id = inset->id();
503 for (; pit != pend; ++pit) {
504 InsetList::iterator it = pit->insetlist.begin();
505 InsetList::iterator const end = pit->insetlist.end();
506 for (; it != end; ++it) {
507 if (it->inset == inset) {
508 lyxerr << "InsetText::lockInsetInInset: 1 a" << endl;
509 text_.setCursorIntern(pit, it->pos);
510 lyxerr << "InsetText::lockInsetInInset: 1 b" << endl;
511 lyxerr << "bv: " << bv << " inset: " << inset << endl;
512 lockInset(bv, inset);
513 lyxerr << "InsetText::lockInsetInInset: 1 c" << endl;
516 if (it->inset->getInsetFromID(id)) {
517 lyxerr << "InsetText::lockInsetInInset: 2" << endl;
518 text_.setCursorIntern(pit, it->pos);
519 it->inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
520 return the_locking_inset->lockInsetInInset(bv, inset);
524 lyxerr << "InsetText::lockInsetInInset: 3" << endl;
527 if (inset == cpar()->getInset(cpos())) {
528 lyxerr[Debug::INSETS] << "OK" << endl;
529 lockInset(bv, inset);
533 if (the_locking_inset && the_locking_inset == inset) {
534 if (cpar() == inset_par && cpos() == inset_pos) {
535 lyxerr[Debug::INSETS] << "OK" << endl;
536 inset_x = cix() - top_x + drawTextXOffset;
537 inset_y = ciy() + drawTextYOffset;
539 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
541 } else if (the_locking_inset) {
542 lyxerr[Debug::INSETS] << "MAYBE" << endl;
543 return the_locking_inset->lockInsetInInset(bv, inset);
545 lyxerr[Debug::INSETS] << "NOT OK" << endl;
550 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
553 if (!the_locking_inset)
555 if (the_locking_inset == inset) {
556 the_locking_inset->insetUnlock(bv);
557 getLyXText(bv)->updateInset(inset);
558 the_locking_inset = 0;
560 moveRightIntern(bv, true, false);
561 old_par = paragraphs.end(); // force layout setting
565 updateLocal(bv, false);
568 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
572 bool InsetText::updateInsetInInset(BufferView * bv, InsetOld * inset)
574 if (!autoBreakRows && paragraphs.size() > 1)
575 collapseParagraphs(bv);
580 if (inset->owner() != this) {
582 UpdatableInset * tl_inset = the_locking_inset;
584 found = tl_inset->updateInsetInInset(bv, inset);
586 tl_inset = static_cast<UpdatableInset *>(inset);
587 while(tl_inset->owner() && tl_inset->owner() != this)
588 tl_inset = static_cast<UpdatableInset *>(tl_inset->owner());
589 if (!tl_inset->owner())
591 found = tl_inset->updateInsetInInset(bv, inset);
593 text_.updateInset(tl_inset);
594 setUpdateStatus(FULL);
598 bool found = text_.updateInset(inset);
600 setUpdateStatus(FULL);
601 if (the_locking_inset &&
602 cpar() == inset_par && cpos() == inset_pos)
604 inset_x = cix() - top_x + drawTextXOffset;
605 inset_y = ciy() + drawTextYOffset;
612 void InsetText::lfunMousePress(FuncRequest const & cmd)
616 // use this to check mouse motion for selection!
620 BufferView * bv = cmd.view();
621 FuncRequest cmd1 = cmd;
627 int tmp_x = cmd.x - drawTextXOffset;
628 int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
629 InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
631 if (the_locking_inset) {
632 if (the_locking_inset == inset) {
633 the_locking_inset->localDispatch(cmd1);
636 // otherwise only unlock the_locking_inset
637 the_locking_inset->insetUnlock(bv);
638 the_locking_inset = 0;
641 no_selection = false;
643 if (bv->theLockingInset()) {
644 if (isHighlyEditableInset(inset)) {
645 // We just have to lock the inset before calling a
647 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
648 if (!bv->lockInset(uinset)) {
649 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
651 inset->localDispatch(cmd1);
652 if (the_locking_inset)
653 updateLocal(bv, false);
658 bool paste_internally = false;
659 if (cmd.button() == mouse_button::button2 && getLyXText(bv)->selection.set()) {
660 localDispatch(FuncRequest(bv, LFUN_COPY));
661 paste_internally = true;
663 int old_top_y = text_.top_y();
665 text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
667 // set the selection cursor!
668 text_.selection.cursor = text_.cursor;
669 text_.cursor.x_fix(text_.cursor.x());
671 text_.clearSelection();
672 updateLocal(bv, false);
674 bv->owner()->setLayout(cpar()->layout()->name());
676 // we moved the view we cannot do mouse selection in this case!
677 if (getLyXText(bv)->top_y() != old_top_y)
680 // Insert primary selection with middle mouse
681 // if there is a local selection in the current buffer,
683 if (cmd.button() == mouse_button::button2) {
684 if (paste_internally)
685 localDispatch(FuncRequest(bv, LFUN_PASTE));
687 localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
690 getLyXText(bv)->clearSelection();
695 bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
697 BufferView * bv = cmd.view();
698 FuncRequest cmd1 = cmd;
703 if (the_locking_inset)
704 return the_locking_inset->localDispatch(cmd1);
706 int tmp_x = cmd.x - drawTextXOffset;
707 int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
708 InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
711 // This code should probably be removed now. Simple insets
712 // (!highlyEditable) can actually take the localDispatch,
713 // and turn it into edit() if necessary. But we still
714 // need to deal properly with the whole relative vs.
715 // absolute mouse co-ords thing in a realiable, sensible way
717 if (isHighlyEditableInset(inset))
718 ret = inset->localDispatch(cmd1);
720 inset_x = cix(bv) - top_x + drawTextXOffset;
721 inset_y = ciy() + drawTextYOffset;
722 cmd1.x = cmd.x - inset_x;
723 cmd1.y = cmd.x - inset_y;
724 inset->edit(bv, cmd1.x, cmd1.y, cmd.button());
728 ret = inset->localDispatch(cmd1);
729 updateLocal(bv, false);
736 void InsetText::lfunMouseMotion(FuncRequest const & cmd)
738 FuncRequest cmd1 = cmd;
742 if (the_locking_inset) {
743 the_locking_inset->localDispatch(cmd1);
747 if (no_selection || (mouse_x == cmd.x && mouse_y == cmd.y))
750 BufferView * bv = cmd.view();
751 LyXCursor cur = text_.cursor;
752 text_.setCursorFromCoordinates
753 (cmd.x - drawTextXOffset, cmd.y + dim_.asc);
754 text_.cursor.x_fix(text_.cursor.x());
755 if (cur == text_.cursor)
757 text_.setSelection();
758 updateLocal(bv, false);
762 InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
764 BufferView * bv = cmd.view();
767 switch (cmd.action) {
768 case LFUN_INSET_EDIT: {
769 UpdatableInset::localDispatch(cmd);
771 if (!bv->lockInset(this)) {
772 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
777 the_locking_inset = 0;
781 inset_boundary = false;
782 inset_par = paragraphs.end();
783 old_par = paragraphs.end();
786 if (cmd.argument.size()) {
787 if (cmd.argument == "left")
788 text_.setCursorIntern(paragraphs.begin(), 0);
790 ParagraphList::iterator it = boost::prior(paragraphs.end());
791 text_.setCursor(it, it->size());
794 int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
795 // we put here -1 and not button as now the button in the
796 // edit call should not be needed we will fix this in 1.3.x
797 // cycle hopefully (Jug 20020509)
798 // FIXME: GUII I've changed this to none: probably WRONG
799 if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) {
800 text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
802 text_.cursor.x_fix(text_.cursor.x());
806 text_.clearSelection();
809 // If the inset is empty set the language of the current font to the
810 // language to the surronding text (if different).
811 if (paragraphs.begin()->empty() &&
812 paragraphs.size() == 1 &&
813 bv->getParentLanguage(this) != text_.current_font.language())
815 LyXFont font(LyXFont::ALL_IGNORE);
816 font.setLanguage(bv->getParentLanguage(this));
817 setFont(bv, font, false);
820 updateLocal(bv, false);
821 // Tell the paragraph dialog that we've entered an insettext.
822 bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
826 case LFUN_MOUSE_PRESS:
830 case LFUN_MOUSE_MOTION:
831 lfunMouseMotion(cmd);
834 case LFUN_MOUSE_RELEASE:
835 return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
841 bool was_empty = (paragraphs.begin()->empty() &&
842 paragraphs.size() == 1);
844 no_selection = false;
845 RESULT result = UpdatableInset::localDispatch(cmd);
846 if (result != UNDISPATCHED)
850 if (cmd.action < 0 && cmd.argument.empty())
853 if (the_locking_inset) {
854 result = the_locking_inset->localDispatch(cmd);
855 if (result == DISPATCHED_NOUPDATE)
857 if (result == DISPATCHED) {
858 updateLocal(bv, false);
861 if (result >= FINISHED) {
864 moveRightIntern(bv, false, false);
869 if (result >= FINISHED) {
870 updateLocal(bv, false);
871 bv->unlockInset(this);
875 result = moveDown(bv);
876 if (result >= FINISHED) {
877 updateLocal(bv, false);
878 bv->unlockInset(this);
885 the_locking_inset = 0;
886 updateLocal(bv, false);
887 // make sure status gets reset immediately
888 bv->owner()->clearMessage();
892 bool updwhat = false;
893 bool updflag = false;
895 switch (cmd.action) {
898 case LFUN_SELFINSERT:
899 if (bv->buffer()->isReadonly()) {
900 // setErrorMessage(N_("Document is read only"));
903 if (!cmd.argument.empty()) {
904 /* Automatically delete the currently selected
905 * text and replace it with what is being
906 * typed in now. Depends on lyxrc settings
907 * "auto_region_delete", which defaults to
910 // This should not be needed here and is also WRONG!
911 recordUndo(bv, Undo::INSERT, text_.cursor.par());
914 if (lyxrc.auto_region_delete) {
915 if (text_.selection.set()) {
916 text_.cutSelection(false, false);
919 text_.clearSelection();
920 for (string::size_type i = 0; i < cmd.argument.length(); ++i) {
921 bv->owner()->getIntl().getTransManager().
922 TranslateAndInsert(cmd.argument[i], &text_);
925 text_.selection.cursor = text_.cursor;
928 result = DISPATCHED_NOUPDATE;
931 // cursor movements that need special handling
934 result = moveRight(bv);
940 result = moveLeft(bv);
945 result = moveDown(bv);
955 if (crow() == text_.rows().begin())
956 result = FINISHED_UP;
958 text_.cursorPrevious();
959 text_.clearSelection();
960 result = DISPATCHED_NOUPDATE;
966 if (boost::next(crow()) == text_.rows().end())
967 result = FINISHED_DOWN;
970 text_.clearSelection();
971 result = DISPATCHED_NOUPDATE;
976 case LFUN_BACKSPACE: {
977 if (text_.selection.set())
978 text_.cutSelection(true, false);
987 if (text_.selection.set()) {
988 text_.cutSelection(true, false);
998 text_.cutSelection(true, true);
1006 text_.copySelection();
1010 case LFUN_PASTESELECTION:
1012 string const clip(bv->getClipboard());
1016 if (cmd.argument == "paragraph") {
1017 text_.insertStringAsParagraphs(clip);
1019 text_.insertStringAsLines(clip);
1022 text_.clearSelection();
1030 if (!autoBreakRows) {
1031 if (CutAndPaste::nrOfParagraphs() > 1) {
1032 #ifdef WITH_WARNINGS
1033 #warning FIXME horrendously bad UI
1035 Alert::error(_("Paste failed"), _("Cannot include more than one paragraph."));
1040 replaceSelection(bv->getLyXText());
1041 size_t sel_index = 0;
1042 string const & arg = cmd.argument;
1043 if (isStrUnsignedInt(arg)) {
1044 size_t const paste_arg = strToUnsignedInt(arg);
1045 #warning FIXME Check if the arg is in the domain of available selections.
1046 sel_index = paste_arg;
1048 text_.pasteSelection(sel_index);
1050 text_.clearSelection();
1056 case LFUN_BREAKPARAGRAPH:
1057 if (!autoBreakRows) {
1058 result = DISPATCHED;
1061 replaceSelection(bv->getLyXText());
1062 text_.breakParagraph(paragraphs, 0);
1067 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1068 if (!autoBreakRows) {
1069 result = DISPATCHED;
1072 replaceSelection(bv->getLyXText());
1073 text_.breakParagraph(paragraphs, 1);
1078 case LFUN_BREAKLINE: {
1079 if (!autoBreakRows) {
1080 result = DISPATCHED;
1084 replaceSelection(bv->getLyXText());
1085 text_.insertInset(new InsetNewline);
1092 // do not set layouts on non breakable textinsets
1093 if (autoBreakRows) {
1094 string cur_layout = cpar()->layout()->name();
1096 // Derive layout number from given argument (string)
1097 // and current buffer's textclass (number). */
1098 LyXTextClass const & tclass =
1099 bv->buffer()->params.getLyXTextClass();
1100 string layout = cmd.argument;
1101 bool hasLayout = tclass.hasLayout(layout);
1103 // If the entry is obsolete, use the new one instead.
1105 string const & obs =
1106 tclass[layout]->obsoleted_by();
1111 // see if we found the layout number:
1113 FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
1114 bv->owner()->dispatch(lf);
1118 if (cur_layout != layout) {
1119 cur_layout = layout;
1120 text_.setLayout(layout);
1121 bv->owner()->setLayout(cpar()->layout()->name());
1126 // reset the layout box
1127 bv->owner()->setLayout(cpar()->layout()->name());
1130 case LFUN_PARAGRAPH_SPACING:
1131 // This one is absolutely not working. When fiddling with this
1132 // it also seems to me that the paragraphs inside the insettext
1133 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1134 // FIXME: how old is this comment ? ...
1136 ParagraphList::iterator pit = text_.cursor.par();
1137 Spacing::Space cur_spacing = pit->params().spacing().getSpace();
1138 float cur_value = 1.0;
1139 if (cur_spacing == Spacing::Other) {
1140 cur_value = pit->params().spacing().getValue();
1143 istringstream istr(STRCONV(cmd.argument));
1146 Spacing::Space new_spacing = cur_spacing;
1147 float new_value = cur_value;
1149 lyxerr << "Missing argument to `paragraph-spacing'"
1151 } else if (tmp == "single") {
1152 new_spacing = Spacing::Single;
1153 } else if (tmp == "onehalf") {
1154 new_spacing = Spacing::Onehalf;
1155 } else if (tmp == "double") {
1156 new_spacing = Spacing::Double;
1157 } else if (tmp == "other") {
1158 new_spacing = Spacing::Other;
1161 lyxerr << "new_value = " << tmpval << endl;
1164 } else if (tmp == "default") {
1165 new_spacing = Spacing::Default;
1167 lyxerr << _("Unknown spacing argument: ")
1168 << cmd.argument << endl;
1170 if (cur_spacing != new_spacing || cur_value != new_value) {
1171 pit->params().spacing(Spacing(new_spacing, new_value));
1178 // These need to do repaints but don't require
1179 // special handling otherwise. A *lot* of the
1180 // above could probably be done similarly ...
1185 case LFUN_WORDRIGHT:
1186 // these two are really unhandled ...
1188 case LFUN_BEGINNINGBUF:
1190 if (!bv->dispatch(cmd))
1191 result = UNDISPATCHED;
1200 case LFUN_WORDLEFTSEL:
1201 case LFUN_WORDRIGHTSEL:
1207 if (!bv->dispatch(cmd))
1208 result = UNDISPATCHED;
1213 updateLocal(bv, updflag);
1214 /// If the action has deleted all text in the inset, we need to change the
1215 // language to the language of the surronding text.
1216 if (!was_empty && paragraphs.begin()->empty() &&
1217 paragraphs.size() == 1) {
1218 LyXFont font(LyXFont::ALL_IGNORE);
1219 font.setLanguage(bv->getParentLanguage(this));
1220 setFont(bv, font, false);
1223 if (result >= FINISHED)
1224 bv->unlockInset(this);
1226 if (result == DISPATCHED_NOUPDATE && (need_update & FULL))
1227 result = DISPATCHED;
1232 int InsetText::latex(Buffer const * buf, ostream & os,
1233 LatexRunParams const & runparams) const
1236 latexParagraphs(buf, paragraphs, os, texrow, runparams);
1237 return texrow.rows();
1241 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1243 unsigned int lines = 0;
1245 ParagraphList::const_iterator beg = paragraphs.begin();
1246 ParagraphList::const_iterator end = paragraphs.end();
1247 ParagraphList::const_iterator it = beg;
1248 for (; it != end; ++it) {
1249 string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
1250 lines += lyx::count(tmp.begin(), tmp.end(), '\n');
1257 int InsetText::linuxdoc(Buffer const * buf, ostream & os) const
1259 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1260 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1262 // There is a confusion between the empty paragraph and the default paragraph
1263 // The default paragraph is <p></p>, the empty paragraph is *empty*
1264 // Since none of the floats of linuxdoc accepts standard paragraphs
1265 // I disable them. I don't expect problems. (jamatos 2003/07/27)
1266 for (; pit != pend; ++pit) {
1267 const string name = pit->layout()->latexname();
1269 sgml::openTag(os, 1, 0, name);
1270 buf->simpleLinuxDocOnePar(os, pit, 0);
1272 sgml::closeTag(os, 1, 0, name);
1278 int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
1280 unsigned int lines = 0;
1282 vector<string> environment_stack(10);
1283 vector<string> environment_inner(10);
1285 int const command_depth = 0;
1288 Paragraph::depth_type depth = 0; // paragraph depth
1290 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
1291 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
1293 for (; pit != pend; ++pit) {
1295 int desc_on = 0; // description mode
1297 LyXLayout_ptr const & style = pit->layout();
1299 // environment tag closing
1300 for (; depth > pit->params().depth(); --depth) {
1301 if (environment_inner[depth] != "!-- --") {
1302 item_name = "listitem";
1303 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1304 if (environment_inner[depth] == "varlistentry")
1305 lines += sgml::closeTag(os, depth+command_depth, mixcont, environment_inner[depth]);
1307 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1308 environment_stack[depth].erase();
1309 environment_inner[depth].erase();
1312 if (depth == pit->params().depth()
1313 && environment_stack[depth] != style->latexname()
1314 && !environment_stack[depth].empty()) {
1315 if (environment_inner[depth] != "!-- --") {
1316 item_name= "listitem";
1317 lines += sgml::closeTag(os, command_depth+depth, mixcont, item_name);
1318 if (environment_inner[depth] == "varlistentry")
1319 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1322 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1324 environment_stack[depth].erase();
1325 environment_inner[depth].erase();
1328 // Write opening SGML tags.
1329 switch (style->latextype) {
1330 case LATEX_PARAGRAPH:
1331 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1335 buf->error(ErrorItem(_("Error"), _("LatexType Command not allowed here.\n"), pit->id(), 0, pit->size()));
1339 case LATEX_ENVIRONMENT:
1340 case LATEX_ITEM_ENVIRONMENT:
1341 if (depth < pit->params().depth()) {
1342 depth = pit->params().depth();
1343 environment_stack[depth].erase();
1346 if (environment_stack[depth] != style->latexname()) {
1347 if (environment_stack.size() == depth + 1) {
1348 environment_stack.push_back("!-- --");
1349 environment_inner.push_back("!-- --");
1351 environment_stack[depth] = style->latexname();
1352 environment_inner[depth] = "!-- --";
1353 lines += sgml::openTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1355 if (environment_inner[depth] != "!-- --") {
1356 item_name= "listitem";
1357 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1358 if (environment_inner[depth] == "varlistentry")
1359 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1363 if (style->latextype == LATEX_ENVIRONMENT) {
1364 if (!style->latexparam().empty()) {
1365 if (style->latexparam() == "CDATA")
1368 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexparam());
1373 desc_on = (style->labeltype == LABEL_MANUAL);
1375 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1376 lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
1378 item_name = desc_on ? "term" : "para";
1379 lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, item_name);
1383 lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
1387 buf->simpleDocBookOnePar(os, pit, desc_on, depth + 1 + command_depth);
1390 // write closing SGML tags
1391 switch (style->latextype) {
1392 case LATEX_ENVIRONMENT:
1393 if (!style->latexparam().empty()) {
1394 if (style->latexparam() == "CDATA")
1397 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexparam());
1400 case LATEX_ITEM_ENVIRONMENT:
1401 if (desc_on == 1) break;
1403 lines += sgml::closeTag(os, depth + 1 + command_depth, mixcont, end_tag);
1405 case LATEX_PARAGRAPH:
1406 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1409 lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
1415 for (int d = depth; d >= 0; --d) {
1416 if (!environment_stack[depth].empty()) {
1417 if (environment_inner[depth] != "!-- --") {
1418 item_name = "listitem";
1419 lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
1420 if (environment_inner[depth] == "varlistentry")
1421 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
1424 lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
1432 void InsetText::validate(LaTeXFeatures & features) const
1434 for_each(paragraphs.begin(), paragraphs.end(),
1435 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1439 void InsetText::getCursor(BufferView & bv, int & x, int & y) const
1441 if (the_locking_inset) {
1442 the_locking_inset->getCursor(bv, x, y);
1446 y = cy() + InsetText::y();
1450 void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
1452 if (the_locking_inset) {
1453 the_locking_inset->getCursorPos(bv, x, y);
1456 x = cx() - top_x - TEXT_TO_INSET_OFFSET;
1457 y = cy() - TEXT_TO_INSET_OFFSET;
1461 int InsetText::insetInInsetY() const
1463 if (!the_locking_inset)
1466 return inset_y + the_locking_inset->insetInInsetY();
1470 void InsetText::fitInsetCursor(BufferView * bv) const
1472 if (the_locking_inset) {
1473 the_locking_inset->fitInsetCursor(bv);
1477 LyXFont const font = text_.getFont(cpar(), cpos());
1479 int const asc = font_metrics::maxAscent(font);
1480 int const desc = font_metrics::maxDescent(font);
1482 if (bv->fitLockedInsetCursor(cx(), cy(), asc, desc))
1483 need_update |= FULL;
1488 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1490 if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1491 return moveLeftIntern(bv, false, activate_inset, selecting);
1493 return moveRightIntern(bv, true, activate_inset, selecting);
1498 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1500 if (text_.cursor.par()->isRightToLeftPar(bv->buffer()->params))
1501 return moveRightIntern(bv, true, activate_inset, selecting);
1503 return moveLeftIntern(bv, false, activate_inset, selecting);
1508 InsetText::moveRightIntern(BufferView * bv, bool front,
1509 bool activate_inset, bool selecting)
1511 ParagraphList::iterator c_par = cpar();
1513 if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size())
1514 return FINISHED_RIGHT;
1515 if (activate_inset && checkAndActivateInset(bv, front))
1517 text_.cursorRight(bv);
1519 text_.clearSelection();
1520 return DISPATCHED_NOUPDATE;
1525 InsetText::moveLeftIntern(BufferView * bv, bool front,
1526 bool activate_inset, bool selecting)
1528 if (cpar() == paragraphs.begin() && cpos() <= 0)
1530 text_.cursorLeft(bv);
1532 text_.clearSelection();
1533 if (activate_inset && checkAndActivateInset(bv, front))
1535 return DISPATCHED_NOUPDATE;
1539 InsetOld::RESULT InsetText::moveUp(BufferView * bv)
1541 if (crow() == text_.rows().begin())
1544 text_.clearSelection();
1545 return DISPATCHED_NOUPDATE;
1549 InsetOld::RESULT InsetText::moveDown(BufferView * bv)
1551 if (boost::next(crow()) == text_.rows().end())
1552 return FINISHED_DOWN;
1553 text_.cursorDown(bv);
1554 text_.clearSelection();
1555 return DISPATCHED_NOUPDATE;
1559 bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
1561 if (the_locking_inset) {
1562 if (the_locking_inset->insetAllowed(inset))
1563 return the_locking_inset->insertInset(bv, inset);
1566 inset->setOwner(this);
1567 text_.insertInset(inset);
1569 updateLocal(bv, true);
1574 bool InsetText::insetAllowed(InsetOld::Code code) const
1576 // in_insetAllowed is a really gross hack,
1577 // to allow us to call the owner's insetAllowed
1578 // without stack overflow, which can happen
1579 // when the owner uses InsetCollapsable::insetAllowed()
1581 if (in_insetAllowed)
1583 in_insetAllowed = true;
1584 if (the_locking_inset)
1585 ret = the_locking_inset->insetAllowed(code);
1587 ret = owner()->insetAllowed(code);
1588 in_insetAllowed = false;
1593 UpdatableInset * InsetText::getLockingInset() const
1595 return the_locking_inset ? the_locking_inset->getLockingInset() :
1596 const_cast<InsetText *>(this);
1600 UpdatableInset * InsetText::getFirstLockingInsetOfType(InsetOld::Code c)
1604 if (the_locking_inset)
1605 return the_locking_inset->getFirstLockingInsetOfType(c);
1610 bool InsetText::showInsetDialog(BufferView * bv) const
1612 if (the_locking_inset)
1613 return the_locking_inset->showInsetDialog(bv);
1618 void InsetText::getLabelList(std::vector<string> & list) const
1620 ParagraphList::const_iterator pit = paragraphs.begin();
1621 ParagraphList::const_iterator pend = paragraphs.end();
1622 for (; pit != pend; ++pit) {
1623 InsetList::const_iterator beg = pit->insetlist.begin();
1624 InsetList::const_iterator end = pit->insetlist.end();
1625 for (; beg != end; ++beg)
1626 beg->inset->getLabelList(list);
1631 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1634 if (the_locking_inset) {
1635 the_locking_inset->setFont(bv, font, toggleall, selectall);
1639 if ((paragraphs.size() == 1 && paragraphs.begin()->empty())
1640 || cpar()->empty()) {
1641 text_.setFont(font, toggleall);
1646 if (text_.selection.set())
1647 recordUndo(bv, Undo::ATOMIC, text_.cursor.par());
1651 text_.selection.cursor = text_.cursor;
1652 text_.cursorBottom();
1653 text_.setSelection();
1656 text_.toggleFree(font, toggleall);
1659 text_.clearSelection();
1662 updateLocal(bv, true);
1666 bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
1668 InsetOld * inset = cpar()->getInset(cpos());
1669 if (!isHighlyEditableInset(inset))
1671 FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
1672 inset->localDispatch(cmd);
1673 if (!the_locking_inset)
1675 updateLocal(bv, false);
1680 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1681 mouse_button::state button)
1683 x -= drawTextXOffset;
1685 int dummyy = y + dim_.asc;
1686 InsetOld * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy);
1687 // we only do the edit() call if the inset was hit by the mouse
1688 // or if it is a highly editable inset. So we should call this
1689 // function from our own edit with button < 0.
1690 // FIXME: GUII jbl. I've changed this to ::none for now which is probably
1692 if (button == mouse_button::none && !isHighlyEditableInset(inset))
1701 inset_x = cix() - top_x + drawTextXOffset;
1702 inset_y = ciy() + drawTextYOffset;
1703 FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
1704 inset->localDispatch(cmd);
1705 if (!the_locking_inset)
1707 updateLocal(bv, false);
1712 void InsetText::setParagraphData(ParagraphList const & plist)
1714 // we have to unlock any locked inset otherwise we're in troubles
1715 the_locking_inset = 0;
1717 // But it it makes no difference that is a lot better.
1719 // See if this can be simplified when std::list is in effect.
1722 ParagraphList::const_iterator it = plist.begin();
1723 ParagraphList::const_iterator end = plist.end();
1724 for (; it != end; ++it) {
1725 paragraphs.push_back(*it);
1726 paragraphs.back().setInsetOwner(this);
1734 void InsetText::markNew(bool track_changes)
1736 ParagraphList::iterator pit = paragraphs.begin();
1737 ParagraphList::iterator pend = paragraphs.end();
1738 for (; pit != pend; ++pit) {
1739 if (track_changes) {
1740 pit->trackChanges();
1742 // no-op when not tracking
1743 pit->cleanChanges();
1749 void InsetText::setText(string const & data, LyXFont const & font)
1752 for (unsigned int i = 0; i < data.length(); ++i)
1753 paragraphs.begin()->insertChar(i, data[i], font);
1758 void InsetText::setAutoBreakRows(bool flag)
1760 if (flag != autoBreakRows) {
1761 autoBreakRows = flag;
1769 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1771 if (how != drawFrame_) {
1774 updateLocal(bv, false);
1779 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1781 if (frame_color != col) {
1784 updateLocal(bv, false);
1789 int InsetText::cx() const
1791 int x = text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1792 if (the_locking_inset) {
1793 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1794 if (font.isVisibleRightToLeft())
1795 x -= the_locking_inset->width();
1801 int InsetText::cix() const
1803 int x = text_.cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
1804 if (the_locking_inset) {
1805 LyXFont font = text_.getFont(text_.cursor.par(), text_.cursor.pos());
1806 if (font.isVisibleRightToLeft())
1807 x -= the_locking_inset->width();
1813 int InsetText::cy() const
1815 return text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET;
1819 int InsetText::ciy() const
1821 return text_.cursor.iy() - dim_.asc + TEXT_TO_INSET_OFFSET;
1825 pos_type InsetText::cpos() const
1827 return text_.cursor.pos();
1831 ParagraphList::iterator InsetText::cpar() const
1833 return text_.cursor.par();
1837 bool InsetText::cboundary() const
1839 return text_.cursor.boundary();
1843 RowList::iterator InsetText::crow() const
1845 return text_.cursorRow();
1849 LyXText * InsetText::getLyXText(BufferView const * bv,
1850 bool const recursive) const
1853 if (recursive && the_locking_inset)
1854 return the_locking_inset->getLyXText(bv, true);
1859 void InsetText::setViewCache(BufferView const * bv) const
1862 text_.bv_owner = const_cast<BufferView *>(bv);
1866 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1869 /// then remove all LyXText in text-insets
1870 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1871 const_cast<ParagraphList&>(paragraphs).end(),
1872 boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv));
1877 void InsetText::resizeLyXText(BufferView * bv, bool /*force*/) const
1879 if (paragraphs.size() == 1 && paragraphs.begin()->empty())
1888 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1889 const_cast<ParagraphList&>(paragraphs).end(),
1890 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1894 restoreLyXTextState();
1896 // seems to be unneeded
1898 if (the_locking_inset) {
1899 inset_x = cix() - top_x + drawTextXOffset;
1900 inset_y = ciy() + drawTextYOffset;
1903 text_.top_y(bv->screen().topCursorVisible(&text_));
1905 const_cast<InsetText*>(this)->updateLocal(bv, false);
1906 // this will scroll the screen such that the cursor becomes visible
1907 bv->updateScrollbar();
1909 need_update |= FULL;
1915 void InsetText::reinitLyXText() const
1917 BufferView * bv = text_.bv_owner;
1924 for_each(const_cast<ParagraphList&>(paragraphs).begin(),
1925 const_cast<ParagraphList&>(paragraphs).end(),
1926 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
1929 restoreLyXTextState();
1930 if (the_locking_inset) {
1931 inset_x = cix() - top_x + drawTextXOffset;
1932 inset_y = ciy() + drawTextYOffset;
1934 text_.top_y(bv->screen().topCursorVisible(&text_));
1936 // this will scroll the screen such that the cursor becomes visible
1937 bv->updateScrollbar();
1944 void InsetText::removeNewlines()
1946 bool changed = false;
1948 ParagraphList::iterator it = paragraphs.begin();
1949 ParagraphList::iterator end = paragraphs.end();
1950 for (; it != end; ++it) {
1951 for (int i = 0; i < it->size(); ++i) {
1952 if (it->isNewline(i)) {
1963 int InsetText::scroll(bool recursive) const
1965 int sx = UpdatableInset::scroll(false);
1967 if (recursive && the_locking_inset)
1968 sx += the_locking_inset->scroll(recursive);
1974 void InsetText::clearSelection(BufferView * bv)
1976 getLyXText(bv)->clearSelection();
1980 void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
1982 Painter & pain = bv->painter();
1984 int h = dim_.asc + dim_.des;
1985 int ty = baseline - dim_.asc;
1991 if (ty + h > pain.paperHeight())
1992 h = pain.paperHeight();
1993 if (top_x + drawTextXOffset + w > pain.paperWidth())
1994 w = pain.paperWidth();
1995 pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor());
2000 ParagraphList * InsetText::getParagraphs(int i) const
2002 return (i == 0) ? const_cast<ParagraphList*>(¶graphs) : 0;
2006 LyXCursor const & InsetText::cursor(BufferView * bv) const
2008 if (the_locking_inset)
2009 return the_locking_inset->cursor(bv);
2010 return getLyXText(bv)->cursor;
2014 InsetOld * InsetText::getInsetFromID(int id_arg) const
2017 return const_cast<InsetText *>(this);
2019 ParagraphList::const_iterator pit = paragraphs.begin();
2020 ParagraphList::const_iterator pend = paragraphs.end();
2021 for (; pit != pend; ++pit) {
2022 InsetList::const_iterator it = pit->insetlist.begin();
2023 InsetList::const_iterator end = pit->insetlist.end();
2024 for (; it != end; ++it) {
2025 if (it->inset->id() == id_arg)
2027 InsetOld * in = it->inset->getInsetFromID(id_arg);
2037 InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2040 if (the_locking_inset) {
2041 word = the_locking_inset->selectNextWordToSpellcheck(bv, value);
2042 if (!word.word().empty()) {
2046 // we have to go on checking so move cursor to the next char
2047 text_.cursor.pos(text_.cursor.pos() + 1);
2049 word = text_.selectNextWordToSpellcheck(value);
2050 if (word.word().empty())
2051 bv->unlockInset(const_cast<InsetText *>(this));
2058 void InsetText::selectSelectedWord(BufferView * bv)
2060 if (the_locking_inset) {
2061 the_locking_inset->selectSelectedWord(bv);
2064 getLyXText(bv)->selectSelectedWord();
2065 updateLocal(bv, false);
2069 bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length)
2071 if (the_locking_inset) {
2072 if (the_locking_inset->nextChange(bv, length))
2074 text_.cursorRight(true);
2076 lyx::find::SearchResult result =
2077 lyx::find::findNextChange(bv, &text_, length);
2079 if (result == lyx::find::SR_FOUND) {
2080 LyXCursor cur = text_.cursor;
2081 bv->unlockInset(bv->theLockingInset());
2082 if (bv->lockInset(this))
2085 text_.setSelectionRange(length);
2086 updateLocal(bv, false);
2088 return result != lyx::find::SR_NOT_FOUND;
2092 bool InsetText::searchForward(BufferView * bv, string const & str,
2095 if (the_locking_inset) {
2096 if (the_locking_inset->searchForward(bv, str, cs, mw))
2098 text_.cursorRight(true);
2100 lyx::find::SearchResult result =
2101 lyx::find::find(bv, &text_, str, true, cs, mw);
2103 if (result == lyx::find::SR_FOUND) {
2104 LyXCursor cur = text_.cursor;
2105 bv->unlockInset(bv->theLockingInset());
2106 if (bv->lockInset(this))
2109 text_.setSelectionRange(str.length());
2110 updateLocal(bv, false);
2112 return result != lyx::find::SR_NOT_FOUND;
2116 bool InsetText::searchBackward(BufferView * bv, string const & str,
2119 if (the_locking_inset) {
2120 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2124 ParagraphList::iterator pit = paragraphs.begin();
2125 ParagraphList::iterator pend = paragraphs.end();
2127 while (boost::next(pit) != pend)
2130 text_.setCursor(pit, pit->size());
2132 lyx::find::SearchResult result =
2133 lyx::find::find(bv, &text_, str, false, cs, mw);
2135 if (result == lyx::find::SR_FOUND) {
2136 LyXCursor cur = text_.cursor;
2137 bv->unlockInset(bv->theLockingInset());
2138 if (bv->lockInset(this))
2141 text_.setSelectionRange(str.length());
2142 updateLocal(bv, false);
2144 return result != lyx::find::SR_NOT_FOUND;
2148 bool InsetText::checkInsertChar(LyXFont & font)
2151 return owner()->checkInsertChar(font);
2156 void InsetText::collapseParagraphs(BufferView * bv)
2158 while (paragraphs.size() > 1) {
2159 ParagraphList::iterator first_par = paragraphs.begin();
2160 ParagraphList::iterator next_par = boost::next(first_par);
2161 size_t const first_par_size = first_par->size();
2163 if (!first_par->empty() &&
2164 !next_par->empty() &&
2165 !first_par->isSeparator(first_par_size - 1)) {
2166 first_par->insertChar(first_par_size, ' ');
2169 if (text_.selection.set()) {
2170 if (text_.selection.start.par() == next_par) {
2171 text_.selection.start.par(first_par);
2172 text_.selection.start.pos(
2173 text_.selection.start.pos() + first_par_size);
2175 if (text_.selection.end.par() == next_par) {
2176 text_.selection.end.par(first_par);
2177 text_.selection.end.pos(
2178 text_.selection.end.pos() + first_par_size);
2182 mergeParagraph(bv->buffer()->params, paragraphs, first_par);
2188 void InsetText::getDrawFont(LyXFont & font) const
2192 owner()->getDrawFont(font);
2196 void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
2198 #warning FIXME Check if Changes stuff needs changing here. (Lgb)
2199 // And it probably does. You have to take a look at this John. (Lgb)
2200 #warning John, have a look here. (Lgb)
2201 ParagraphList::iterator pit = plist.begin();
2202 ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit);
2204 mergeParagraph(buffer->params, paragraphs, boost::prior(ins));
2206 ParagraphList::iterator pend = plist.end();
2207 for (; pit != pend; ++pit) {
2208 paragraphs.push_back(*pit);
2215 void InsetText::addPreview(PreviewLoader & loader) const
2217 ParagraphList::const_iterator pit = paragraphs.begin();
2218 ParagraphList::const_iterator pend = paragraphs.end();
2220 for (; pit != pend; ++pit) {
2221 InsetList::const_iterator it = pit->insetlist.begin();
2222 InsetList::const_iterator end = pit->insetlist.end();
2223 for (; it != end; ++it) {
2224 it->inset->addPreview(loader);