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") {
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 if (greek_kb_flag) {
1012 if (!math_insert_greek(bv, arg[i])) {
1013 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1014 } else if (!the_locking_inset) {
1015 (void)moveRight(bv, false);
1018 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1022 lt->selection.cursor = lt->cursor;
1023 updateLocal(bv, CURSOR_PAR, true);
1024 result = DISPATCHED_NOUPDATE;
1026 // --- Cursor Movements -----------------------------------
1029 moveRight(bv, false, true);
1030 lt->setSelection(bv);
1031 updateLocal(bv, SELECTION, false);
1034 result = moveRight(bv);
1036 updateLocal(bv, CURSOR, false);
1040 moveLeft(bv, false, true);
1041 lt->setSelection(bv);
1042 updateLocal(bv, SELECTION, false);
1046 result = moveLeft(bv);
1047 updateLocal(bv, CURSOR, false);
1052 lt->setSelection(bv);
1053 updateLocal(bv, SELECTION, false);
1057 result = moveDown(bv);
1058 updateLocal(bv, CURSOR, false);
1063 lt->setSelection(bv);
1064 updateLocal(bv, SELECTION, false);
1068 result = moveUp(bv);
1069 updateLocal(bv, CURSOR, false);
1074 updateLocal(bv, CURSOR, false);
1078 updateLocal(bv, CURSOR, false);
1080 case LFUN_BACKSPACE: {
1081 setUndo(bv, Undo::DELETE,
1082 lt->cursor.par(), lt->cursor.par()->next());
1083 if (lt->selection.set())
1084 lt->cutSelection(bv);
1087 updateLocal(bv, CURSOR_PAR, true);
1092 setUndo(bv, Undo::DELETE,
1093 lt->cursor.par(), lt->cursor.par()->next());
1094 if (lt->selection.set()) {
1095 lt->cutSelection(bv);
1099 updateLocal(bv, CURSOR_PAR, true);
1104 setUndo(bv, Undo::DELETE,
1105 lt->cursor.par(), lt->cursor.par()->next());
1106 lt->cutSelection(bv);
1107 updateLocal(bv, CURSOR_PAR, true);
1113 lt->copySelection(bv);
1114 updateLocal(bv, CURSOR_PAR, false);
1116 case LFUN_PASTESELECTION:
1118 string const clip(bv->getClipboard());
1122 if (arg == "paragraph") {
1123 lt->insertStringAsParagraphs(bv, clip);
1125 lt->insertStringAsLines(bv, clip);
1127 updateLocal(bv, CURSOR_PAR, true);
1131 if (!autoBreakRows) {
1133 if (CutAndPaste::nrOfParagraphs() > 1) {
1134 WriteAlert(_("Impossible operation"),
1135 _("Cannot include more than one paragraph!"),
1140 setUndo(bv, Undo::INSERT,
1141 lt->cursor.par(), lt->cursor.par()->next());
1142 lt->pasteSelection(bv);
1143 updateLocal(bv, CURSOR_PAR, true);
1147 case LFUN_BREAKPARAGRAPH:
1148 if (!autoBreakRows) {
1149 result = DISPATCHED;
1152 lt->breakParagraph(bv, 0);
1153 updateLocal(bv, FULL, true);
1155 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1156 if (!autoBreakRows) {
1157 result = DISPATCHED;
1160 lt->breakParagraph(bv, 1);
1161 updateLocal(bv, FULL, true);
1164 case LFUN_BREAKLINE: {
1165 if (!autoBreakRows) {
1166 result = DISPATCHED;
1169 setUndo(bv, Undo::INSERT,
1170 lt->cursor.par(), lt->cursor.par()->next());
1171 lt->insertChar(bv, Paragraph::META_NEWLINE);
1172 updateLocal(bv, CURSOR_PAR, true);
1177 // do not set layouts on non breakable textinsets
1178 if (autoBreakRows) {
1179 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1181 // Derive layout number from given argument (string)
1182 // and current buffer's textclass (number). */
1183 LyXTextClassList::ClassList::size_type tclass =
1184 bv->buffer()->params.textclass;
1185 std::pair <bool, LyXTextClass::size_type> layout =
1186 textclasslist.NumberOfLayout(tclass, arg);
1188 // If the entry is obsolete, use the new one instead.
1190 string obs = textclasslist.Style(tclass,layout.second).
1193 layout = textclasslist.NumberOfLayout(tclass, obs);
1196 // see if we found the layout number:
1197 if (!layout.first) {
1198 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1199 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1203 if (cur_layout != layout.second) {
1204 cur_layout = layout.second;
1205 lt->setLayout(bv, layout.second);
1206 bv->owner()->setLayout(cpar(bv)->getLayout());
1207 updateLocal(bv, CURSOR_PAR, true);
1210 // reset the layout box
1211 bv->owner()->setLayout(cpar(bv)->getLayout());
1214 case LFUN_PARAGRAPH_SPACING:
1215 // This one is absolutely not working. When fiddling with this
1216 // it also seems to me that the paragraphs inside the insettext
1217 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1219 Paragraph * par = lt->cursor.par();
1220 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1221 float cur_value = 1.0;
1222 if (cur_spacing == Spacing::Other) {
1223 cur_value = par->params().spacing().getValue();
1226 istringstream istr(arg.c_str());
1229 Spacing::Space new_spacing = cur_spacing;
1230 float new_value = cur_value;
1232 lyxerr << "Missing argument to `paragraph-spacing'"
1234 } else if (tmp == "single") {
1235 new_spacing = Spacing::Single;
1236 } else if (tmp == "onehalf") {
1237 new_spacing = Spacing::Onehalf;
1238 } else if (tmp == "double") {
1239 new_spacing = Spacing::Double;
1240 } else if (tmp == "other") {
1241 new_spacing = Spacing::Other;
1244 lyxerr << "new_value = " << tmpval << endl;
1247 } else if (tmp == "default") {
1248 new_spacing = Spacing::Default;
1250 lyxerr << _("Unknown spacing argument: ")
1253 if (cur_spacing != new_spacing || cur_value != new_value) {
1254 par->params().spacing(Spacing(new_spacing, new_value));
1255 updateLocal(bv, CURSOR_PAR, true);
1261 if (!bv->Dispatch(action, arg))
1262 result = UNDISPATCHED;
1266 /// If the action has deleted all text in the inset, we need to change the
1267 // language to the language of the surronding text.
1268 if (par->size() == 0 && !par->next()) {
1269 LyXFont font(LyXFont::ALL_IGNORE);
1270 font.setLanguage(bv->getParentLanguage(this));
1271 setFont(bv, font, false);
1274 if (result != FINISHED) {
1275 showInsetCursor(bv);
1277 bv->unlockInset(this);
1284 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1287 buf->latexParagraphs(os, par, 0, texrow);
1288 return texrow.rows();
1292 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1294 Paragraph * p = par;
1295 unsigned int lines = 0;
1298 string const tmp = buf->asciiParagraph(p, linelen);
1299 lines += countChar(tmp, '\n');
1307 int InsetText::docBook(Buffer const * buf, ostream & os) const
1309 Paragraph * p = par;
1310 unsigned int lines = 0;
1315 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1323 void InsetText::validate(LaTeXFeatures & features) const
1325 Paragraph * p = par;
1327 p->validate(features);
1333 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1335 if (textclasslist.Style(buf->params.textclass,
1336 p->getLayout()).labeltype != LABEL_MANUAL)
1339 return p->beginningOfMainBody();
1343 void InsetText::getCursorPos(BufferView * bv,
1344 int & x, int & y) const
1346 if (the_locking_inset) {
1347 the_locking_inset->getCursorPos(bv, x, y);
1355 unsigned int InsetText::insetInInsetY()
1357 if (!the_locking_inset)
1360 return (inset_y + the_locking_inset->insetInInsetY());
1364 void InsetText::toggleInsetCursor(BufferView * bv)
1366 if (the_locking_inset) {
1367 the_locking_inset->toggleInsetCursor(bv);
1371 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1373 int const asc = lyxfont::maxAscent(font);
1374 int const desc = lyxfont::maxDescent(font);
1376 if (isCursorVisible())
1377 bv->hideLockedInsetCursor();
1379 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1380 toggleCursorVisible();
1384 void InsetText::showInsetCursor(BufferView * bv, bool show)
1386 if (the_locking_inset) {
1387 the_locking_inset->showInsetCursor(bv, show);
1390 if (!isCursorVisible()) {
1391 LyXFont const font =
1392 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1394 int const asc = lyxfont::maxAscent(font);
1395 int const desc = lyxfont::maxDescent(font);
1397 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1399 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1400 setCursorVisible(true);
1405 void InsetText::hideInsetCursor(BufferView * bv)
1407 if (isCursorVisible()) {
1408 bv->hideLockedInsetCursor();
1409 setCursorVisible(false);
1411 if (the_locking_inset)
1412 the_locking_inset->hideInsetCursor(bv);
1416 void InsetText::fitInsetCursor(BufferView * bv) const
1418 if (the_locking_inset) {
1419 the_locking_inset->fitInsetCursor(bv);
1422 LyXFont const font =
1423 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1425 int const asc = lyxfont::maxAscent(font);
1426 int const desc = lyxfont::maxDescent(font);
1428 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1432 UpdatableInset::RESULT
1433 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1435 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1436 return moveLeftIntern(bv, false, activate_inset, selecting);
1438 return moveRightIntern(bv, false, activate_inset, selecting);
1442 UpdatableInset::RESULT
1443 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1445 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1446 return moveRightIntern(bv, true, activate_inset, selecting);
1448 return moveLeftIntern(bv, true, activate_inset, selecting);
1452 UpdatableInset::RESULT
1453 InsetText::moveRightIntern(BufferView * bv, bool behind,
1454 bool activate_inset, bool selecting)
1456 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1458 if (activate_inset && checkAndActivateInset(bv, behind))
1460 getLyXText(bv)->cursorRight(bv);
1462 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1463 return DISPATCHED_NOUPDATE;
1467 UpdatableInset::RESULT
1468 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1469 bool activate_inset, bool selecting)
1471 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1473 getLyXText(bv)->cursorLeft(bv);
1475 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1476 if (activate_inset && checkAndActivateInset(bv, behind))
1478 return DISPATCHED_NOUPDATE;
1482 UpdatableInset::RESULT
1483 InsetText::moveUp(BufferView * bv)
1485 if (!crow(bv)->previous())
1487 getLyXText(bv)->cursorUp(bv);
1488 return DISPATCHED_NOUPDATE;
1492 UpdatableInset::RESULT
1493 InsetText::moveDown(BufferView * bv)
1495 if (!crow(bv)->next())
1497 getLyXText(bv)->cursorDown(bv);
1498 return DISPATCHED_NOUPDATE;
1502 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1504 if (the_locking_inset) {
1505 if (the_locking_inset->insetAllowed(inset))
1506 return the_locking_inset->insertInset(bv, inset);
1509 inset->setOwner(this);
1510 hideInsetCursor(bv);
1514 lt = getLyXText(bv);
1517 lt->insertInset(bv, inset);
1519 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1520 (cpar(bv)->getInset(cpos(bv)) != inset))
1524 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1525 showInsetCursor(bv);
1532 bool InsetText::insetAllowed(Inset::Code code) const
1534 if (the_locking_inset)
1535 return the_locking_inset->insetAllowed(code);
1540 UpdatableInset * InsetText::getLockingInset() const
1542 return the_locking_inset ? the_locking_inset->getLockingInset() :
1543 const_cast<InsetText *>(this);
1547 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1551 if (the_locking_inset)
1552 return the_locking_inset->getFirstLockingInsetOfType(c);
1557 bool InsetText::showInsetDialog(BufferView * bv) const
1559 if (the_locking_inset)
1560 return the_locking_inset->showInsetDialog(bv);
1565 std::vector<string> const InsetText::getLabelList() const
1567 std::vector<string> label_list;
1569 Paragraph * tpar = par;
1571 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1572 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1573 for (; beg != end; ++beg) {
1574 std::vector<string> const l = (*beg)->getLabelList();
1575 label_list.insert(label_list.end(), l.begin(), l.end());
1577 tpar = tpar->next();
1583 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1586 if (the_locking_inset) {
1587 the_locking_inset->setFont(bv, font, toggleall, selectall);
1592 lt = getLyXText(bv);
1595 if (lt->selection.set()) {
1596 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1600 lt->toggleFree(bv, font, toggleall);
1602 lt->clearSelection();
1604 if (selectall || lt->selection.set())
1605 updateLocal(bv, FULL, true);
1607 updateLocal(bv, CURSOR_PAR, true);
1613 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1615 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1619 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1620 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1622 LyXFont const font =
1623 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1625 x = inset->width(bv, font);
1626 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1629 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1631 //inset_x = cx(bv) - top_x + drawTextXOffset;
1632 //inset_y = cy(bv) + drawTextYOffset;
1633 inset->edit(bv, x, y, 0);
1634 if (!the_locking_inset)
1636 updateLocal(bv, CURSOR, false);
1643 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1646 x -= drawTextXOffset;
1648 int dummyy = y + insetAscent;
1649 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1656 inset_x = cx(bv) - top_x + drawTextXOffset;
1657 inset_y = cy(bv) + drawTextYOffset;
1658 inset->edit(bv, x - inset_x, y - inset_y, button);
1659 if (!the_locking_inset)
1661 updateLocal(bv, CURSOR, false);
1668 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1670 int w = UpdatableInset::getMaxWidth(bv, inset);
1675 w = w - top_x + owner()->x();
1678 w -= (2 * TEXT_TO_INSET_OFFSET);
1683 void InsetText::setParagraphData(Paragraph * p)
1686 Paragraph * tmp = par->next();
1691 par = new Paragraph(*p);
1692 par->setInsetOwner(this);
1693 Paragraph * np = par;
1696 np->next(new Paragraph(*p));
1697 np->next()->previous(np);
1699 np->setInsetOwner(this);
1705 void InsetText::setText(string const & data)
1708 LyXFont font(LyXFont::ALL_SANE);
1709 for (unsigned int i=0; i < data.length(); ++i)
1710 par->insertChar(i, data[i], font);
1714 void InsetText::setAutoBreakRows(bool flag)
1716 if (flag != autoBreakRows) {
1717 autoBreakRows = flag;
1726 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1728 if (how != drawFrame_) {
1731 updateLocal(bv, DRAW_FRAME, false);
1736 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1738 if (frame_color != col) {
1741 updateLocal(bv, DRAW_FRAME, false);
1746 int InsetText::cx(BufferView * bv) const
1750 lt = getLyXText(bv);
1753 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1754 if (the_locking_inset) {
1755 LyXFont font = lt->getFont(bv->buffer(),
1758 if (font.isVisibleRightToLeft())
1759 x -= the_locking_inset->width(bv, font);
1767 int InsetText::cy(BufferView * bv) const
1770 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1774 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1776 return getLyXText(bv)->cursor.pos();
1780 Paragraph * InsetText::cpar(BufferView * bv) const
1782 return getLyXText(bv)->cursor.par();
1786 bool InsetText::cboundary(BufferView * bv) const
1788 return getLyXText(bv)->cursor.boundary();
1792 Row * InsetText::crow(BufferView * bv) const
1794 return getLyXText(bv)->cursor.row();
1798 LyXText * InsetText::getLyXText(BufferView const * lbv,
1799 bool const recursive) const
1801 if (!recursive && (cached_bview == lbv))
1802 return cached_text.get();
1804 // Super UGLY! (Lgb)
1805 BufferView * bv = const_cast<BufferView *>(lbv);
1808 Cache::iterator it = cache.find(bv);
1810 if (it != cache.end()) {
1811 if (lt || !it->second.remove) {
1812 lyx::Assert(it->second.text.get());
1813 cached_text = it->second.text;
1814 if (recursive && the_locking_inset) {
1815 return the_locking_inset->getLyXText(bv, true);
1817 return cached_text.get();
1818 } else if (it->second.remove) {
1820 saveLyXTextState(it->second.text.get());
1827 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1828 cached_text->init(bv);
1829 restoreLyXTextState(bv, cached_text.get());
1831 cache.insert(make_pair(bv, cached_text));
1833 if (the_locking_inset && recursive) {
1834 return the_locking_inset->getLyXText(bv);
1836 return cached_text.get();
1840 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1844 Cache::iterator it = cache.find(bv);
1846 if (it == cache.end()) {
1850 lyx::Assert(it->second.text.get());
1852 it->second.remove = true;
1854 /// then remove all LyXText in text-insets
1855 Paragraph * p = par;
1856 for (; p; p = p->next()) {
1857 p->deleteInsetsLyXText(bv);
1863 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1865 if (!par->next() && !par->size()) // no data, resize not neccessary!
1867 // one endless line, resize normally not necessary
1868 if (!force && getMaxWidth(bv, this) < 0)
1871 Cache::iterator it = cache.find(bv);
1872 if (it == cache.end()) {
1875 lyx::Assert(it->second.text.get());
1877 LyXText * t = it->second.text.get();
1878 saveLyXTextState(t);
1879 for (Paragraph * p = par; p; p = p->next()) {
1880 p->resizeInsetsLyXText(bv);
1883 restoreLyXTextState(bv, t);
1884 if (the_locking_inset) {
1885 inset_x = cx(bv) - top_x + drawTextXOffset;
1886 inset_y = cy(bv) + drawTextYOffset;
1890 t->first = bv->screen()->topCursorVisible(t);
1893 updateLocal(bv, FULL, false);
1895 need_update |= FULL;
1896 // this will scroll the screen such that the cursor becomes visible
1897 bv->updateScrollbar();
1901 void InsetText::reinitLyXText() const
1903 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1904 lyx::Assert(it->second.text.get());
1906 LyXText * t = it->second.text.get();
1907 BufferView * bv = it->first;
1909 saveLyXTextState(t);
1910 for (Paragraph * p = par; p; p = p->next()) {
1911 p->resizeInsetsLyXText(bv);
1914 restoreLyXTextState(bv, t);
1915 if (the_locking_inset) {
1916 inset_x = cx(bv) - top_x + drawTextXOffset;
1917 inset_y = cy(bv) + drawTextYOffset;
1920 t->first = bv->screen()->topCursorVisible(t);
1923 updateLocal(bv, FULL, false);
1926 // this will scroll the screen such that the cursor becomes visible
1927 bv->updateScrollbar();
1932 void InsetText::removeNewlines()
1934 for (Paragraph * p = par; p; p = p->next()) {
1935 for (int i = 0; i < p->size(); ++i) {
1936 if (p->getChar(i) == Paragraph::META_NEWLINE)
1943 bool InsetText::nodraw() const
1945 if (the_locking_inset)
1946 return the_locking_inset->nodraw();
1947 return UpdatableInset::nodraw();
1951 int InsetText::scroll(bool recursive) const
1953 int sx = UpdatableInset::scroll(false);
1955 if (recursive && the_locking_inset)
1956 sx += the_locking_inset->scroll(recursive);
1962 bool InsetText::doClearArea() const
1964 return !locked || (need_update & (FULL|INIT));
1968 void InsetText::selectAll(BufferView * bv)
1970 getLyXText(bv)->cursorTop(bv);
1971 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1972 getLyXText(bv)->cursorBottom(bv);
1973 getLyXText(bv)->setSelection(bv);
1977 void InsetText::clearSelection(BufferView * bv)
1979 getLyXText(bv)->clearSelection();
1983 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
1986 int h = insetAscent + insetDescent;
1987 int ty = baseline - insetAscent;
1993 if ((ty + h) > pain.paperHeight())
1994 h = pain.paperHeight();
1995 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
1996 w = pain.paperWidth();
1997 pain.fillRectangle(top_x+drawTextXOffset, ty, w, h, backgroundColor());
2003 Paragraph * InsetText::getParFromID(int id) const
2005 Paragraph * result = par;
2006 Paragraph * ires = 0;
2007 while (result && result->id() != id) {
2008 if ((ires = result->getParFromID(id)))
2010 result = result->next();
2016 Paragraph * InsetText::firstParagraph() const
2019 if (the_locking_inset)
2020 if ((result = the_locking_inset->firstParagraph()))
2026 LyXCursor const & InsetText::cursor(BufferView * bv) const
2028 if (the_locking_inset)
2029 return the_locking_inset->cursor(bv);
2030 return getLyXText(bv)->cursor;
2034 Paragraph * InsetText::paragraph() const
2040 void InsetText::paragraph(Paragraph * p)
2044 // we now have to update/redraw all instances
2045 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2050 // redraw myself when asked for
2051 need_update |= INIT;
2055 Inset * InsetText::getInsetFromID(int id_arg) const
2058 return const_cast<InsetText *>(this);
2060 Paragraph * lp = par;
2063 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2064 en = lp->inset_iterator_end();
2067 if ((*it)->id() == id_arg)
2069 Inset * in = (*it)->getInsetFromID(id_arg);
2079 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2085 lt = getLyXText(bv);
2088 if (the_locking_inset) {
2089 str = the_locking_inset->selectNextWord(bv, value);
2096 #warning Dekel please have a look on this one RTL? (Jug)
2097 // we have to go on checking so move cusor to the right
2098 lt->cursor.pos(lt->cursor.pos() + 1);
2100 str = lt->selectNextWord(bv, value);
2102 bv->unlockInset(const_cast<InsetText *>(this));
2111 void InsetText::selectSelectedWord(BufferView * bv)
2113 if (the_locking_inset) {
2114 the_locking_inset->selectSelectedWord(bv);
2117 getLyXText(bv)->selectSelectedWord(bv);
2118 updateLocal(bv, SELECTION, false);
2122 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2124 if (the_locking_inset) {
2125 the_locking_inset->toggleSelection(bv, kill_selection);
2129 lt = getLyXText(bv);
2133 int x = top_x + TEXT_TO_INSET_OFFSET;
2136 Row * row = lt->getRowNearY(y);
2137 int y_offset = top_baseline - row->ascent_of_text();
2139 while ((row != 0) && ((y+row->height()) <= 0)) {
2146 if (need_update & SELECTION)
2148 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2154 bool InsetText::searchForward(BufferView * bv, string const & str,
2155 bool const & cs, bool const & mw)
2157 if (the_locking_inset) {
2158 if (the_locking_inset->searchForward(bv, str, cs, mw))
2162 lt = getLyXText(bv);
2165 Paragraph * lpar = lt->cursor.par();
2166 Paragraph::size_type pos = lt->cursor.pos();
2167 if (pos < lpar->size() - 1)
2171 lpar = lpar->next();
2178 lt->setCursor(bv, lpar, pos);
2182 if (LyXFind(bv, str, true, true, cs , mw)) {
2185 // we have to unlock ourself in this function by default!
2186 bv->unlockInset(const_cast<InsetText *>(this));
2190 bool InsetText::searchBackward(BufferView * bv, string const & str,
2191 bool const & cs, bool const & mw)
2193 if (the_locking_inset)
2194 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2196 if (LyXFind(bv, str, false, true, cs, mw)) {
2199 // we have to unlock ourself in this function by default!
2200 bv->unlockInset(const_cast<InsetText *>(this));