1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998-2001 The LyX Team.
8 * ======================================================
20 #pragma implementation
23 #include "insettext.h"
24 #include "paragraph.h"
28 #include "commandtags.h"
31 #include "BufferView.h"
33 #include "LaTeXFeatures.h"
35 #include "lyx_gui_misc.h"
37 #include "lyxcursor.h"
38 #include "CutAndPaste.h"
41 #include "support/textutils.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
47 #include "trans_mgr.h"
48 #include "lyxscreen.h"
52 #include "ParagraphParameters.h"
53 #include "undo_funcs.h"
63 extern unsigned char getCurrentTextClass(Buffer *);
64 extern bool math_insert_greek(BufferView *, char);
65 extern int greek_kb_flag;
68 #warning this functions should probably go into bufferview_funcs somehow (Jug)
70 void InsetText::saveLyXTextState(LyXText * t) const
72 sstate.lpar = t->cursor.par();
73 sstate.pos = t->cursor.pos();
74 sstate.boundary = t->cursor.boundary();
75 sstate.selstartpar = t->selection.start.par();
76 sstate.selstartpos = t->selection.start.pos();
77 sstate.selstartboundary = t->selection.start.boundary();
78 sstate.selendpar = t->selection.end.par();
79 sstate.selendpos = t->selection.end.pos();
80 sstate.selendboundary = t->selection.end.boundary();
81 sstate.selection = t->selection.set();
82 sstate.mark_set = t->selection.mark();
83 sstate.refresh = t->refresh_row != 0;
86 void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const
89 t->selection.set(true);
90 /* at this point just to avoid the Delete-Empty-Paragraph
91 * Mechanism when setting the cursor */
92 t->selection.mark(sstate.mark_set);
93 if (sstate.selection) {
94 t->setCursor(bv, sstate.selstartpar, sstate.selstartpos,
95 true, sstate.selstartboundary);
96 t->selection.cursor = t->cursor;
97 t->setCursor(bv, sstate.selendpar, sstate.selendpos,
98 true, sstate.selendboundary);
100 t->setCursor(bv, sstate.lpar, sstate.pos);
102 t->setCursor(bv, sstate.lpar, sstate.pos, true, sstate.boundary);
103 t->selection.cursor = t->cursor;
104 t->selection.set(false);
106 if (sstate.refresh) {
112 InsetText::InnerCache::InnerCache(boost::shared_ptr<LyXText> t)
119 InsetText::InsetText()
127 InsetText::InsetText(InsetText const & ins, bool same_id)
133 autoBreakRows = ins.autoBreakRows;
137 InsetText & InsetText::operator=(InsetText const & it)
140 autoBreakRows = it.autoBreakRows;
145 void InsetText::init(InsetText const * ins, bool same_id)
153 the_locking_inset = 0;
155 no_selection = false;
159 autoBreakRows = false;
162 frame_color = LColor::insetframe;
164 setParagraphData(ins->par);
165 autoBreakRows = ins->autoBreakRows;
166 drawFrame_ = ins->drawFrame_;
167 frame_color = ins->frame_color;
171 par->setInsetOwner(this);
174 last_drawn_width = -1;
175 frame_is_visible = false;
182 InsetText::~InsetText()
189 Paragraph * tmp = par->next();
196 void InsetText::clear()
199 Paragraph * tmp = par->next();
208 Inset * InsetText::clone(Buffer const &, bool same_id) const
210 return new InsetText(*this, same_id);
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 par->writeFile(buf, os, buf->params, 0);
227 void InsetText::read(Buffer const * buf, LyXLex & lex)
231 Paragraph * return_par = 0;
232 Paragraph::depth_type depth = 0;
233 LyXFont font(LyXFont::ALL_INHERIT);
239 token = lex.GetString();
242 if (token == "\\end_inset") {
243 #ifndef NO_COMPABILITY
244 const_cast<Buffer*>(buf)->insertErtContents(par, pos, font, false);
249 if (const_cast<Buffer*>(buf)->
250 parseSingleLyXformat2Token(lex, par, return_par,
251 token, pos, depth, font)) {
252 // the_end read this should NEVER happen
253 lex.printError("\\the_end read in inset! Error in document!");
261 return_par->setInsetOwner(this);
262 return_par = return_par->next();
265 if (token != "\\end_inset") {
266 lex.printError("Missing \\end_inset at this point. "
273 int InsetText::ascent(BufferView * bv, LyXFont const &) const
276 Row * row = getLyXText(bv)->getRowNearY(y_temp);
277 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
282 int InsetText::descent(BufferView * bv, LyXFont const &) const
290 Row * row = lt->getRowNearY(y_temp);
291 insetDescent = lt->height - row->ascent_of_text() +
292 TEXT_TO_INSET_OFFSET;
299 int InsetText::width(BufferView * bv, LyXFont const &) const
301 insetWidth = max(textWidth(bv),
302 (int)getLyXText(bv)->width + (2 * TEXT_TO_INSET_OFFSET));
307 int InsetText::textWidth(BufferView * bv) const
311 int const w = getMaxWidth(bv, this);
316 void InsetText::draw(BufferView * bv, LyXFont const & f,
317 int baseline, float & x, bool cleared) const
322 Painter & pain = bv->painter();
324 // this is the first thing we have to ask because if the x pos
325 // changed we have to do a complete rebreak of the text as we
326 // may have few space to draw in. Well we should check on this too
327 if (top_x != int(x)) {
330 int nw = getMaxWidth(bv, this);
331 if (nw > 0 && old_max_width != nw) {
334 bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
339 // dummy calls so that the values are again right
341 (void)descent(bv, f);
345 // repaint the background if needed
346 if (cleared && backgroundColor() != LColor::background) {
347 clearInset(pain, baseline, cleared);
350 // no draw is necessary !!!
351 if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
353 top_baseline = baseline;
355 if (!cleared && (need_update & CLEAR_FRAME))
356 clearFrame(pain, cleared);
358 frame_is_visible = false;
365 x += static_cast<float>(scroll());
367 // if top_x differs we have a rule down and we don't have to clear anything
368 if (!cleared && (top_x == int(x)) &&
369 ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
370 (last_drawn_width!=insetWidth))) {
371 clearInset(pain, baseline, cleared);
375 frame_is_visible = false;
377 if (!cleared && (need_update == NONE))
380 // lyxerr << "InsetText::draw[" << this << "](" << need_update << ":" << int(x) << ":" << top_x << ")\n";
382 if (cleared || (last_drawn_width != insetWidth)) {
384 last_drawn_width = insetWidth;
387 top_baseline = baseline;
388 top_y = baseline - ascent(bv, f);
389 last_width = width(bv, f);
390 last_height = ascent(bv, f) + descent(bv, f);
392 if (the_locking_inset && (cpar(bv) == inset_par)
393 && (cpos(bv) == inset_pos)) {
394 inset_x = cx(bv) - top_x + drawTextXOffset;
395 inset_y = cy(bv) + drawTextYOffset;
397 if (!cleared && (need_update == CURSOR)
398 && !getLyXText(bv)->selection.set())
400 drawFrame(pain, cleared);
401 x += last_width; // was width(bv, f);
410 x += TEXT_TO_INSET_OFFSET;
413 Row * row = lt->getRowNearY(y);
414 int y_offset = baseline - row->ascent_of_text();
415 int ph = pain.paperHeight();
418 while ((row != 0) && ((y+row->height()) <= 0)) {
420 first += row->height();
426 if (cleared || (need_update&=(INIT|FULL))) {
429 while ((row != 0) && (yf < ph)) {
430 lt->getVisibleRow(bv, y+y_offset, int(x), row,
436 } else if (!locked) {
437 if (need_update & CURSOR) {
438 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
439 lt->clearSelection();
440 lt->selection.cursor = lt->cursor;
442 bv->screen()->update(lt, bv, y_offset, int(x));
445 if (need_update & SELECTION)
446 bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
447 else if (need_update & CURSOR) {
448 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
449 lt->clearSelection();
450 lt->selection.cursor = lt->cursor;
452 bv->screen()->update(lt, bv, y_offset, int(x));
457 lt->status(bv, LyXText::UNCHANGED);
458 if ((need_update != CURSOR_PAR) &&
459 ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
460 drawFrame(pain, cleared);
461 else if (need_update & CLEAR_FRAME)
462 clearFrame(pain, cleared);
463 x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
464 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
466 } else if (need_update != INIT)
473 void InsetText::drawFrame(Painter & pain, bool cleared) const
475 if (!frame_is_visible || cleared) {
476 frame_x = top_x; // + 1;
477 frame_y = top_baseline - insetAscent; // + 1;
478 frame_w = last_width; // - 2;
479 frame_h = insetAscent + insetDescent; // - 2;
480 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
482 frame_is_visible = true;
487 void InsetText::clearFrame(Painter & pain, bool cleared) const
489 if (frame_is_visible) {
491 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
494 frame_is_visible = false;
499 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
508 owner()->update(bv, font, true);
512 if (the_locking_inset) {
513 inset_x = cx(bv) - top_x + drawTextXOffset;
514 inset_y = cy(bv) + drawTextYOffset;
515 the_locking_inset->update(bv, font, reinit);
523 int oldw = insetWidth;
524 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
525 if (oldw != insetWidth) {
533 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
536 lt->updateInset(bv, the_locking_inset);
538 if (lt->status() == LyXText::NEED_MORE_REFRESH)
546 void InsetText::setUpdateStatus(BufferView * bv, int what) const
554 if (lt->status() == LyXText::NEED_MORE_REFRESH)
556 else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)
557 need_update |= CURSOR_PAR;
559 // this to not draw a selection when we redraw all of it!
560 if (need_update & CURSOR) {
561 if (lt->selection.set())
563 lt->clearSelection();
570 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
578 setUpdateStatus(bv, what);
579 if ((need_update != CURSOR) || (lt->status() != LyXText::UNCHANGED) ||
582 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
584 bv->owner()->showState();
585 if (old_par != cpar(bv)) {
586 bv->owner()->setLayout(cpar(bv)->getLayout());
594 string const InsetText::editMessage() const
596 return _("Opened Text Inset");
600 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
602 UpdatableInset::edit(bv, x, y, button);
604 if (!bv->lockInset(this)) {
605 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
609 the_locking_inset = 0;
610 inset_pos = inset_x = inset_y = 0;
611 inset_boundary = false;
614 int tmp_y = (y < 0) ? 0 : y;
621 if (!checkAndActivateInset(bv, x, tmp_y, button))
622 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
624 lt->clearSelection();
627 updateLocal(bv, CURSOR, false);
629 // If the inset is empty set the language of the current font to the
630 // language to the surronding text (if different).
631 if (par->size() == 0 && !par->next() &&
632 bv->getParentLanguage(this) != lt->current_font.language()) {
633 LyXFont font(LyXFont::ALL_IGNORE);
634 font.setLanguage(bv->getParentLanguage(this));
635 setFont(bv, font, false);
642 void InsetText::edit(BufferView * bv, bool front)
644 UpdatableInset::edit(bv, front);
646 if (!bv->lockInset(this)) {
647 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
651 the_locking_inset = 0;
652 inset_pos = inset_x = inset_y = 0;
653 inset_boundary = false;
662 lt->setCursor(bv, par, 0);
667 lt->setCursor(bv, p, p->size()-1);
669 lt->clearSelection();
672 updateLocal(bv, CURSOR, false);
674 // If the inset is empty set the language of the current font to the
675 // language to the surronding text (if different).
676 if (par->size() == 0 && !par->next() &&
677 bv->getParentLanguage(this) != lt->current_font.language()) {
678 LyXFont font(LyXFont::ALL_IGNORE);
679 font.setLanguage(bv->getParentLanguage(this));
680 setFont(bv, font, false);
687 void InsetText::insetUnlock(BufferView * bv)
689 if (the_locking_inset) {
690 the_locking_inset->insetUnlock(bv);
691 the_locking_inset = 0;
694 no_selection = false;
697 if (drawFrame_ == LOCKED)
698 code = CURSOR|CLEAR_FRAME;
706 if (lt->selection.set()) {
707 lt->clearSelection();
709 } else if (owner()) {
710 bv->owner()->setLayout(owner()->getLyXText(bv)
711 ->cursor.par()->getLayout());
713 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
714 updateLocal(bv, code, false);
720 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
722 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
726 if (inset == cpar(bv)->getInset(cpos(bv))) {
727 lyxerr[Debug::INSETS] << "OK" << endl;
728 the_locking_inset = inset;
729 inset_x = cx(bv) - top_x + drawTextXOffset;
730 inset_y = cy(bv) + drawTextYOffset;
731 inset_pos = cpos(bv);
732 inset_par = cpar(bv);
733 inset_boundary = cboundary(bv);
734 updateLocal(bv, CURSOR, false);
736 } else if (the_locking_inset && (the_locking_inset == inset)) {
737 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
738 lyxerr[Debug::INSETS] << "OK" << endl;
739 inset_x = cx(bv) - top_x + drawTextXOffset;
740 inset_y = cy(bv) + drawTextYOffset;
742 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
744 } else if (the_locking_inset) {
745 lyxerr[Debug::INSETS] << "MAYBE" << endl;
746 return the_locking_inset->lockInsetInInset(bv, inset);
748 lyxerr[Debug::INSETS] << "NOT OK" << endl;
753 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
756 if (!the_locking_inset)
758 if (the_locking_inset == inset) {
759 the_locking_inset->insetUnlock(bv);
760 getLyXText(bv)->updateInset(bv, inset);
761 the_locking_inset = 0;
763 moveRight(bv, false);
764 old_par = 0; // force layout setting
768 updateLocal(bv, CURSOR, false);
771 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
775 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
777 if (!the_locking_inset)
779 if (the_locking_inset != inset) {
780 getLyXText(bv)->updateInset(bv, the_locking_inset);
781 setUpdateStatus(bv, CURSOR_PAR);
782 return the_locking_inset->updateInsetInInset(bv, inset);
784 // updateLocal(bv, FULL, false);
785 if (getLyXText(bv)->updateInset(bv, inset))
786 updateLocal(bv, CURSOR_PAR, false);
787 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
788 inset_x = cx(bv) - top_x + drawTextXOffset;
789 inset_y = cy(bv) + drawTextYOffset;
795 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
799 int tmp_x = x - drawTextXOffset;
800 int tmp_y = y + insetAscent - getLyXText(bv)->first;
801 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
804 if (the_locking_inset) {
805 if (the_locking_inset == inset) {
806 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
807 no_selection = false;
810 // otherwise unlock the_locking_inset and lock the new inset
811 the_locking_inset->insetUnlock(bv);
812 inset_x = cx(bv) - top_x + drawTextXOffset;
813 inset_y = cy(bv) + drawTextYOffset;
814 the_locking_inset = static_cast<UpdatableInset*>(inset);
815 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
816 inset->edit(bv, x - inset_x, y - inset_y, button);
817 if (the_locking_inset)
818 updateLocal(bv, CURSOR, false);
819 no_selection = false;
822 // otherwise only unlock the_locking_inset
823 the_locking_inset->insetUnlock(bv);
824 the_locking_inset = 0;
826 if (bv->theLockingInset()) {
827 if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
828 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
829 inset_x = cx(bv) - top_x + drawTextXOffset;
830 inset_y = cy(bv) + drawTextYOffset;
831 inset_pos = cpos(bv);
832 inset_par = cpar(bv);
833 inset_boundary = cboundary(bv);
834 the_locking_inset = uinset;
835 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
837 uinset->edit(bv, x - inset_x, y - inset_y, 0);
838 if (the_locking_inset)
839 updateLocal(bv, CURSOR, false);
840 no_selection = false;
844 if (!inset) { // && (button == 2)) {
845 bool paste_internally = false;
846 if ((button == 2) && getLyXText(bv)->selection.set()) {
847 localDispatch(bv, LFUN_COPY, "");
848 paste_internally = true;
850 getLyXText(bv)->setCursorFromCoordinates(bv, x-drawTextXOffset,
852 getLyXText(bv)->clearSelection();
853 updateLocal(bv, FULL, false);
854 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
855 bv->owner()->setLayout(cpar(bv)->getLayout());
857 // Insert primary selection with middle mouse
858 // if there is a local selection in the current buffer,
861 if (paste_internally)
862 localDispatch(bv, LFUN_PASTE, "");
864 localDispatch(bv, LFUN_PASTESELECTION,
869 no_selection = false;
873 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
875 UpdatableInset * inset = 0;
877 if (the_locking_inset) {
878 the_locking_inset->insetButtonRelease(bv,
879 x - inset_x, y - inset_y,
882 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
883 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
884 if (inset->editable() == Inset::HIGHLY_EDITABLE) {
885 inset->insetButtonRelease(bv,
887 y - inset_y, button);
889 inset_x = cx(bv) - top_x + drawTextXOffset;
890 inset_y = cy(bv) + drawTextYOffset;
891 inset->insetButtonRelease(bv,
893 y - inset_y, button);
895 x - inset_x, y - inset_y, button);
897 updateLocal(bv, CURSOR_PAR, false);
900 no_selection = false;
904 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
908 if (the_locking_inset) {
909 the_locking_inset->insetMotionNotify(bv, x - inset_x,
913 LyXText * t = getLyXText(bv);
915 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
917 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
918 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
919 updateLocal(bv, SELECTION, false);
924 void InsetText::insetKeyPress(XKeyEvent * xke)
926 if (the_locking_inset) {
927 the_locking_inset->insetKeyPress(xke);
933 UpdatableInset::RESULT
934 InsetText::localDispatch(BufferView * bv,
935 kb_action action, string const & arg)
937 no_selection = false;
938 UpdatableInset::RESULT
939 result= UpdatableInset::localDispatch(bv, action, arg);
940 if (result != UNDISPATCHED) {
945 if ((action < 0) && arg.empty())
948 if (the_locking_inset) {
949 result = the_locking_inset->localDispatch(bv, action, arg);
950 if (result == DISPATCHED_NOUPDATE)
952 else if (result == DISPATCHED) {
953 updateLocal(bv, CURSOR_PAR, false);
955 } else if (result == FINISHED) {
956 bool dispatched = false;
958 case LFUN_UNKNOWN_ACTION:
959 case LFUN_BREAKPARAGRAPH:
961 moveRightIntern(bv, false, false);
964 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
965 moveRightIntern(bv, false, false);
969 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
970 moveRightIntern(bv, false, false);
976 the_locking_inset = 0;
989 case LFUN_SELFINSERT:
990 if (bv->buffer()->isReadonly()) {
991 // setErrorMessage(N_("Document is read only"));
995 /* Automatically delete the currently selected
996 * text and replace it with what is being
997 * typed in now. Depends on lyxrc settings
998 * "auto_region_delete", which defaults to
1001 setUndo(bv, Undo::INSERT,
1002 lt->cursor.par(), lt->cursor.par()->next());
1004 if (lyxrc.auto_region_delete) {
1005 if (lt->selection.set()) {
1006 lt->cutSelection(bv, false);
1009 lt->clearSelection();
1010 for (string::size_type i = 0; i < arg.length(); ++i) {
1011 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1014 lt->selection.cursor = lt->cursor;
1015 updateLocal(bv, CURSOR_PAR, true);
1016 result = DISPATCHED_NOUPDATE;
1018 // --- Cursor Movements -----------------------------------
1021 moveRight(bv, false, true);
1022 lt->setSelection(bv);
1023 updateLocal(bv, SELECTION, false);
1026 result = moveRight(bv);
1028 updateLocal(bv, CURSOR, false);
1032 moveLeft(bv, false, true);
1033 lt->setSelection(bv);
1034 updateLocal(bv, SELECTION, false);
1038 result = moveLeft(bv);
1039 updateLocal(bv, CURSOR, false);
1044 lt->setSelection(bv);
1045 updateLocal(bv, SELECTION, false);
1049 result = moveDown(bv);
1050 updateLocal(bv, CURSOR, false);
1055 lt->setSelection(bv);
1056 updateLocal(bv, SELECTION, false);
1060 result = moveUp(bv);
1061 updateLocal(bv, CURSOR, false);
1066 updateLocal(bv, CURSOR, false);
1070 updateLocal(bv, CURSOR, false);
1072 case LFUN_BACKSPACE: {
1073 setUndo(bv, Undo::DELETE,
1074 lt->cursor.par(), lt->cursor.par()->next());
1075 if (lt->selection.set())
1076 lt->cutSelection(bv);
1079 updateLocal(bv, CURSOR_PAR, true);
1084 setUndo(bv, Undo::DELETE,
1085 lt->cursor.par(), lt->cursor.par()->next());
1086 if (lt->selection.set()) {
1087 lt->cutSelection(bv);
1091 updateLocal(bv, CURSOR_PAR, true);
1096 setUndo(bv, Undo::DELETE,
1097 lt->cursor.par(), lt->cursor.par()->next());
1098 lt->cutSelection(bv);
1099 updateLocal(bv, CURSOR_PAR, true);
1105 lt->copySelection(bv);
1106 updateLocal(bv, CURSOR_PAR, false);
1108 case LFUN_PASTESELECTION:
1110 string const clip(bv->getClipboard());
1114 if (arg == "paragraph") {
1115 lt->insertStringAsParagraphs(bv, clip);
1117 lt->insertStringAsLines(bv, clip);
1119 updateLocal(bv, CURSOR_PAR, true);
1123 if (!autoBreakRows) {
1125 if (CutAndPaste::nrOfParagraphs() > 1) {
1126 WriteAlert(_("Impossible operation"),
1127 _("Cannot include more than one paragraph!"),
1132 setUndo(bv, Undo::INSERT,
1133 lt->cursor.par(), lt->cursor.par()->next());
1134 lt->pasteSelection(bv);
1135 updateLocal(bv, CURSOR_PAR, true);
1139 case LFUN_BREAKPARAGRAPH:
1140 if (!autoBreakRows) {
1141 result = DISPATCHED;
1144 lt->breakParagraph(bv, 0);
1145 updateLocal(bv, FULL, true);
1147 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1148 if (!autoBreakRows) {
1149 result = DISPATCHED;
1152 lt->breakParagraph(bv, 1);
1153 updateLocal(bv, FULL, true);
1156 case LFUN_BREAKLINE: {
1157 if (!autoBreakRows) {
1158 result = DISPATCHED;
1161 setUndo(bv, Undo::INSERT,
1162 lt->cursor.par(), lt->cursor.par()->next());
1163 lt->insertChar(bv, Paragraph::META_NEWLINE);
1164 updateLocal(bv, CURSOR_PAR, true);
1169 // do not set layouts on non breakable textinsets
1170 if (autoBreakRows) {
1171 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1173 // Derive layout number from given argument (string)
1174 // and current buffer's textclass (number). */
1175 LyXTextClassList::ClassList::size_type tclass =
1176 bv->buffer()->params.textclass;
1177 std::pair <bool, LyXTextClass::size_type> layout =
1178 textclasslist.NumberOfLayout(tclass, arg);
1180 // If the entry is obsolete, use the new one instead.
1182 string obs = textclasslist.Style(tclass,layout.second).
1185 layout = textclasslist.NumberOfLayout(tclass, obs);
1188 // see if we found the layout number:
1189 if (!layout.first) {
1190 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1191 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1195 if (cur_layout != layout.second) {
1196 cur_layout = layout.second;
1197 lt->setLayout(bv, layout.second);
1198 bv->owner()->setLayout(cpar(bv)->getLayout());
1199 updateLocal(bv, CURSOR_PAR, true);
1202 // reset the layout box
1203 bv->owner()->setLayout(cpar(bv)->getLayout());
1206 case LFUN_PARAGRAPH_SPACING:
1207 // This one is absolutely not working. When fiddling with this
1208 // it also seems to me that the paragraphs inside the insettext
1209 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1211 Paragraph * par = lt->cursor.par();
1212 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1213 float cur_value = 1.0;
1214 if (cur_spacing == Spacing::Other) {
1215 cur_value = par->params().spacing().getValue();
1218 istringstream istr(arg.c_str());
1221 Spacing::Space new_spacing = cur_spacing;
1222 float new_value = cur_value;
1224 lyxerr << "Missing argument to `paragraph-spacing'"
1226 } else if (tmp == "single") {
1227 new_spacing = Spacing::Single;
1228 } else if (tmp == "onehalf") {
1229 new_spacing = Spacing::Onehalf;
1230 } else if (tmp == "double") {
1231 new_spacing = Spacing::Double;
1232 } else if (tmp == "other") {
1233 new_spacing = Spacing::Other;
1236 lyxerr << "new_value = " << tmpval << endl;
1239 } else if (tmp == "default") {
1240 new_spacing = Spacing::Default;
1242 lyxerr << _("Unknown spacing argument: ")
1245 if (cur_spacing != new_spacing || cur_value != new_value) {
1246 par->params().spacing(Spacing(new_spacing, new_value));
1247 updateLocal(bv, CURSOR_PAR, true);
1253 if (!bv->Dispatch(action, arg))
1254 result = UNDISPATCHED;
1258 /// If the action has deleted all text in the inset, we need to change the
1259 // language to the language of the surronding text.
1260 if (par->size() == 0 && !par->next()) {
1261 LyXFont font(LyXFont::ALL_IGNORE);
1262 font.setLanguage(bv->getParentLanguage(this));
1263 setFont(bv, font, false);
1266 if (result != FINISHED) {
1267 showInsetCursor(bv);
1269 bv->unlockInset(this);
1276 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1279 buf->latexParagraphs(os, par, 0, texrow);
1280 return texrow.rows();
1284 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1286 Paragraph * p = par;
1287 unsigned int lines = 0;
1290 string const tmp = buf->asciiParagraph(p, linelen);
1291 lines += countChar(tmp, '\n');
1299 int InsetText::docBook(Buffer const * buf, ostream & os) const
1301 Paragraph * p = par;
1302 unsigned int lines = 0;
1307 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1315 void InsetText::validate(LaTeXFeatures & features) const
1317 Paragraph * p = par;
1319 p->validate(features);
1325 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1327 if (textclasslist.Style(buf->params.textclass,
1328 p->getLayout()).labeltype != LABEL_MANUAL)
1331 return p->beginningOfMainBody();
1335 void InsetText::getCursorPos(BufferView * bv,
1336 int & x, int & y) const
1338 if (the_locking_inset) {
1339 the_locking_inset->getCursorPos(bv, x, y);
1347 unsigned int InsetText::insetInInsetY()
1349 if (!the_locking_inset)
1352 return (inset_y + the_locking_inset->insetInInsetY());
1356 void InsetText::toggleInsetCursor(BufferView * bv)
1358 if (the_locking_inset) {
1359 the_locking_inset->toggleInsetCursor(bv);
1363 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1365 int const asc = lyxfont::maxAscent(font);
1366 int const desc = lyxfont::maxDescent(font);
1368 if (isCursorVisible())
1369 bv->hideLockedInsetCursor();
1371 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1372 toggleCursorVisible();
1376 void InsetText::showInsetCursor(BufferView * bv, bool show)
1378 if (the_locking_inset) {
1379 the_locking_inset->showInsetCursor(bv, show);
1382 if (!isCursorVisible()) {
1383 LyXFont const font =
1384 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1386 int const asc = lyxfont::maxAscent(font);
1387 int const desc = lyxfont::maxDescent(font);
1389 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1391 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1392 setCursorVisible(true);
1397 void InsetText::hideInsetCursor(BufferView * bv)
1399 if (isCursorVisible()) {
1400 bv->hideLockedInsetCursor();
1401 setCursorVisible(false);
1403 if (the_locking_inset)
1404 the_locking_inset->hideInsetCursor(bv);
1408 void InsetText::fitInsetCursor(BufferView * bv) const
1410 if (the_locking_inset) {
1411 the_locking_inset->fitInsetCursor(bv);
1414 LyXFont const font =
1415 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1417 int const asc = lyxfont::maxAscent(font);
1418 int const desc = lyxfont::maxDescent(font);
1420 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1424 UpdatableInset::RESULT
1425 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1427 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1428 return moveLeftIntern(bv, false, activate_inset, selecting);
1430 return moveRightIntern(bv, false, activate_inset, selecting);
1434 UpdatableInset::RESULT
1435 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1437 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1438 return moveRightIntern(bv, true, activate_inset, selecting);
1440 return moveLeftIntern(bv, true, activate_inset, selecting);
1444 UpdatableInset::RESULT
1445 InsetText::moveRightIntern(BufferView * bv, bool behind,
1446 bool activate_inset, bool selecting)
1448 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1450 if (activate_inset && checkAndActivateInset(bv, behind))
1452 getLyXText(bv)->cursorRight(bv);
1454 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1455 return DISPATCHED_NOUPDATE;
1459 UpdatableInset::RESULT
1460 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1461 bool activate_inset, bool selecting)
1463 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1465 getLyXText(bv)->cursorLeft(bv);
1467 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1468 if (activate_inset && checkAndActivateInset(bv, behind))
1470 return DISPATCHED_NOUPDATE;
1474 UpdatableInset::RESULT
1475 InsetText::moveUp(BufferView * bv)
1477 if (!crow(bv)->previous())
1479 getLyXText(bv)->cursorUp(bv);
1480 return DISPATCHED_NOUPDATE;
1484 UpdatableInset::RESULT
1485 InsetText::moveDown(BufferView * bv)
1487 if (!crow(bv)->next())
1489 getLyXText(bv)->cursorDown(bv);
1490 return DISPATCHED_NOUPDATE;
1494 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1496 if (the_locking_inset) {
1497 if (the_locking_inset->insetAllowed(inset))
1498 return the_locking_inset->insertInset(bv, inset);
1501 inset->setOwner(this);
1502 hideInsetCursor(bv);
1506 lt = getLyXText(bv);
1509 lt->insertInset(bv, inset);
1511 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1512 (cpar(bv)->getInset(cpos(bv)) != inset))
1516 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1517 showInsetCursor(bv);
1524 bool InsetText::insetAllowed(Inset::Code code) const
1526 if (the_locking_inset)
1527 return the_locking_inset->insetAllowed(code);
1532 UpdatableInset * InsetText::getLockingInset() const
1534 return the_locking_inset ? the_locking_inset->getLockingInset() :
1535 const_cast<InsetText *>(this);
1539 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1543 if (the_locking_inset)
1544 return the_locking_inset->getFirstLockingInsetOfType(c);
1549 bool InsetText::showInsetDialog(BufferView * bv) const
1551 if (the_locking_inset)
1552 return the_locking_inset->showInsetDialog(bv);
1557 std::vector<string> const InsetText::getLabelList() const
1559 std::vector<string> label_list;
1561 Paragraph * tpar = par;
1563 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1564 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1565 for (; beg != end; ++beg) {
1566 std::vector<string> const l = (*beg)->getLabelList();
1567 label_list.insert(label_list.end(), l.begin(), l.end());
1569 tpar = tpar->next();
1575 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1578 if (the_locking_inset) {
1579 the_locking_inset->setFont(bv, font, toggleall, selectall);
1582 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1583 getLyXText(bv)->setFont(bv, font, toggleall);
1588 lt = getLyXText(bv);
1591 if (lt->selection.set()) {
1592 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1596 lt->toggleFree(bv, font, toggleall);
1598 lt->clearSelection();
1600 if (selectall || lt->selection.set())
1601 updateLocal(bv, FULL, true);
1603 updateLocal(bv, CURSOR_PAR, true);
1609 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1611 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1615 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1616 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1618 LyXFont const font =
1619 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1621 x = inset->width(bv, font);
1622 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1625 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1627 //inset_x = cx(bv) - top_x + drawTextXOffset;
1628 //inset_y = cy(bv) + drawTextYOffset;
1629 inset->edit(bv, x, y, 0);
1630 if (!the_locking_inset)
1632 updateLocal(bv, CURSOR, false);
1639 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1642 x -= drawTextXOffset;
1644 int dummyy = y + insetAscent;
1645 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1652 inset_x = cx(bv) - top_x + drawTextXOffset;
1653 inset_y = cy(bv) + drawTextYOffset;
1654 inset->edit(bv, x - inset_x, y - inset_y, button);
1655 if (!the_locking_inset)
1657 updateLocal(bv, CURSOR, false);
1664 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1666 int w = UpdatableInset::getMaxWidth(bv, inset);
1671 w = w - top_x + owner()->x();
1674 w -= (2 * TEXT_TO_INSET_OFFSET);
1679 void InsetText::setParagraphData(Paragraph * p)
1682 Paragraph * tmp = par->next();
1687 par = new Paragraph(*p);
1688 par->setInsetOwner(this);
1689 Paragraph * np = par;
1692 np->next(new Paragraph(*p));
1693 np->next()->previous(np);
1695 np->setInsetOwner(this);
1701 void InsetText::setText(string const & data)
1704 LyXFont font(LyXFont::ALL_SANE);
1705 for (unsigned int i=0; i < data.length(); ++i)
1706 par->insertChar(i, data[i], font);
1710 void InsetText::setAutoBreakRows(bool flag)
1712 if (flag != autoBreakRows) {
1713 autoBreakRows = flag;
1722 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1724 if (how != drawFrame_) {
1727 updateLocal(bv, DRAW_FRAME, false);
1732 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1734 if (frame_color != col) {
1737 updateLocal(bv, DRAW_FRAME, false);
1742 int InsetText::cx(BufferView * bv) const
1746 lt = getLyXText(bv);
1749 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1750 if (the_locking_inset) {
1751 LyXFont font = lt->getFont(bv->buffer(),
1754 if (font.isVisibleRightToLeft())
1755 x -= the_locking_inset->width(bv, font);
1763 int InsetText::cy(BufferView * bv) const
1766 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1770 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1772 return getLyXText(bv)->cursor.pos();
1776 Paragraph * InsetText::cpar(BufferView * bv) const
1778 return getLyXText(bv)->cursor.par();
1782 bool InsetText::cboundary(BufferView * bv) const
1784 return getLyXText(bv)->cursor.boundary();
1788 Row * InsetText::crow(BufferView * bv) const
1790 return getLyXText(bv)->cursor.row();
1794 LyXText * InsetText::getLyXText(BufferView const * lbv,
1795 bool const recursive) const
1797 if (!recursive && (cached_bview == lbv))
1798 return cached_text.get();
1800 // Super UGLY! (Lgb)
1801 BufferView * bv = const_cast<BufferView *>(lbv);
1804 Cache::iterator it = cache.find(bv);
1806 if (it != cache.end()) {
1807 if (lt || !it->second.remove) {
1808 lyx::Assert(it->second.text.get());
1809 cached_text = it->second.text;
1810 if (recursive && the_locking_inset) {
1811 return the_locking_inset->getLyXText(bv, true);
1813 return cached_text.get();
1814 } else if (it->second.remove) {
1816 saveLyXTextState(it->second.text.get());
1823 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1824 cached_text->init(bv);
1825 restoreLyXTextState(bv, cached_text.get());
1827 cache.insert(make_pair(bv, cached_text));
1829 if (the_locking_inset && recursive) {
1830 return the_locking_inset->getLyXText(bv);
1832 return cached_text.get();
1836 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1840 Cache::iterator it = cache.find(bv);
1842 if (it == cache.end()) {
1846 lyx::Assert(it->second.text.get());
1848 it->second.remove = true;
1850 /// then remove all LyXText in text-insets
1851 Paragraph * p = par;
1852 for (; p; p = p->next()) {
1853 p->deleteInsetsLyXText(bv);
1859 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1861 if (!par->next() && !par->size()) // no data, resize not neccessary!
1863 // one endless line, resize normally not necessary
1864 if (!force && getMaxWidth(bv, this) < 0)
1867 Cache::iterator it = cache.find(bv);
1868 if (it == cache.end()) {
1871 lyx::Assert(it->second.text.get());
1873 LyXText * t = it->second.text.get();
1874 saveLyXTextState(t);
1875 for (Paragraph * p = par; p; p = p->next()) {
1876 p->resizeInsetsLyXText(bv);
1879 restoreLyXTextState(bv, t);
1880 if (the_locking_inset) {
1881 inset_x = cx(bv) - top_x + drawTextXOffset;
1882 inset_y = cy(bv) + drawTextYOffset;
1886 t->first = bv->screen()->topCursorVisible(t);
1889 updateLocal(bv, FULL, false);
1891 need_update |= FULL;
1892 // this will scroll the screen such that the cursor becomes visible
1893 bv->updateScrollbar();
1897 void InsetText::reinitLyXText() const
1899 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1900 lyx::Assert(it->second.text.get());
1902 LyXText * t = it->second.text.get();
1903 BufferView * bv = it->first;
1905 saveLyXTextState(t);
1906 for (Paragraph * p = par; p; p = p->next()) {
1907 p->resizeInsetsLyXText(bv);
1910 restoreLyXTextState(bv, t);
1911 if (the_locking_inset) {
1912 inset_x = cx(bv) - top_x + drawTextXOffset;
1913 inset_y = cy(bv) + drawTextYOffset;
1916 t->first = bv->screen()->topCursorVisible(t);
1919 updateLocal(bv, FULL, false);
1922 // this will scroll the screen such that the cursor becomes visible
1923 bv->updateScrollbar();
1928 void InsetText::removeNewlines()
1930 for (Paragraph * p = par; p; p = p->next()) {
1931 for (int i = 0; i < p->size(); ++i) {
1932 if (p->getChar(i) == Paragraph::META_NEWLINE)
1939 bool InsetText::nodraw() const
1941 if (the_locking_inset)
1942 return the_locking_inset->nodraw();
1943 return UpdatableInset::nodraw();
1947 int InsetText::scroll(bool recursive) const
1949 int sx = UpdatableInset::scroll(false);
1951 if (recursive && the_locking_inset)
1952 sx += the_locking_inset->scroll(recursive);
1958 bool InsetText::doClearArea() const
1960 return !locked || (need_update & (FULL|INIT));
1964 void InsetText::selectAll(BufferView * bv)
1966 getLyXText(bv)->cursorTop(bv);
1967 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1968 getLyXText(bv)->cursorBottom(bv);
1969 getLyXText(bv)->setSelection(bv);
1973 void InsetText::clearSelection(BufferView * bv)
1975 getLyXText(bv)->clearSelection();
1979 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
1982 int h = insetAscent + insetDescent;
1983 int ty = baseline - insetAscent;
1989 if ((ty + h) > pain.paperHeight())
1990 h = pain.paperHeight();
1991 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
1992 w = pain.paperWidth();
1993 pain.fillRectangle(top_x+drawTextXOffset, ty, w, h, backgroundColor());
1999 Paragraph * InsetText::getParFromID(int id) const
2001 Paragraph * result = par;
2002 Paragraph * ires = 0;
2003 while (result && result->id() != id) {
2004 if ((ires = result->getParFromID(id)))
2006 result = result->next();
2012 Paragraph * InsetText::firstParagraph() const
2015 if (the_locking_inset)
2016 if ((result = the_locking_inset->firstParagraph()))
2022 LyXCursor const & InsetText::cursor(BufferView * bv) const
2024 if (the_locking_inset)
2025 return the_locking_inset->cursor(bv);
2026 return getLyXText(bv)->cursor;
2030 Paragraph * InsetText::paragraph() const
2036 void InsetText::paragraph(Paragraph * p)
2040 // we now have to update/redraw all instances
2041 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2046 // redraw myself when asked for
2047 need_update |= INIT;
2051 Inset * InsetText::getInsetFromID(int id_arg) const
2054 return const_cast<InsetText *>(this);
2056 Paragraph * lp = par;
2059 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2060 en = lp->inset_iterator_end();
2063 if ((*it)->id() == id_arg)
2065 Inset * in = (*it)->getInsetFromID(id_arg);
2075 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2081 lt = getLyXText(bv);
2084 if (the_locking_inset) {
2085 str = the_locking_inset->selectNextWord(bv, value);
2092 #warning Dekel please have a look on this one RTL? (Jug)
2093 // we have to go on checking so move cusor to the right
2094 lt->cursor.pos(lt->cursor.pos() + 1);
2096 str = lt->selectNextWord(bv, value);
2098 bv->unlockInset(const_cast<InsetText *>(this));
2107 void InsetText::selectSelectedWord(BufferView * bv)
2109 if (the_locking_inset) {
2110 the_locking_inset->selectSelectedWord(bv);
2113 getLyXText(bv)->selectSelectedWord(bv);
2114 updateLocal(bv, SELECTION, false);
2118 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2120 if (the_locking_inset) {
2121 the_locking_inset->toggleSelection(bv, kill_selection);
2125 lt = getLyXText(bv);
2129 int x = top_x + TEXT_TO_INSET_OFFSET;
2132 Row * row = lt->getRowNearY(y);
2133 int y_offset = top_baseline - row->ascent_of_text();
2135 while ((row != 0) && ((y+row->height()) <= 0)) {
2142 if (need_update & SELECTION)
2144 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2150 bool InsetText::searchForward(BufferView * bv, string const & str,
2151 bool const & cs, bool const & mw)
2153 if (the_locking_inset) {
2154 if (the_locking_inset->searchForward(bv, str, cs, mw))
2158 lt = getLyXText(bv);
2161 Paragraph * lpar = lt->cursor.par();
2162 Paragraph::size_type pos = lt->cursor.pos();
2163 if (pos < lpar->size() - 1)
2167 lpar = lpar->next();
2174 lt->setCursor(bv, lpar, pos);
2178 if (LyXFind(bv, str, true, true, cs , mw)) {
2181 // we have to unlock ourself in this function by default!
2182 bv->unlockInset(const_cast<InsetText *>(this));
2186 bool InsetText::searchBackward(BufferView * bv, string const & str,
2187 bool const & cs, bool const & mw)
2189 if (the_locking_inset)
2190 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2192 if (LyXFind(bv, str, false, true, cs, mw)) {
2195 // we have to unlock ourself in this function by default!
2196 bv->unlockInset(const_cast<InsetText *>(this));