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 // check if my paragraphs are still valid
75 if (p == t->cursor.par())
80 if (p && t->cursor.pos() <= p->size()) {
81 sstate.lpar = t->cursor.par();
82 sstate.pos = t->cursor.pos();
83 sstate.boundary = t->cursor.boundary();
84 sstate.selstartpar = t->selection.start.par();
85 sstate.selstartpos = t->selection.start.pos();
86 sstate.selstartboundary = t->selection.start.boundary();
87 sstate.selendpar = t->selection.end.par();
88 sstate.selendpos = t->selection.end.pos();
89 sstate.selendboundary = t->selection.end.boundary();
90 sstate.selection = t->selection.set();
91 sstate.mark_set = t->selection.mark();
92 sstate.refresh = t->refresh_row != 0;
98 void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const
101 t->selection.set(true);
102 /* at this point just to avoid the Delete-Empty-Paragraph
103 * Mechanism when setting the cursor */
104 t->selection.mark(sstate.mark_set);
105 if (sstate.selection) {
106 t->setCursor(bv, sstate.selstartpar, sstate.selstartpos,
107 true, sstate.selstartboundary);
108 t->selection.cursor = t->cursor;
109 t->setCursor(bv, sstate.selendpar, sstate.selendpos,
110 true, sstate.selendboundary);
112 t->setCursor(bv, sstate.lpar, sstate.pos);
114 t->setCursor(bv, sstate.lpar, sstate.pos, true, sstate.boundary);
115 t->selection.cursor = t->cursor;
116 t->selection.set(false);
118 if (sstate.refresh) {
124 InsetText::InnerCache::InnerCache(boost::shared_ptr<LyXText> t)
131 InsetText::InsetText()
132 : UpdatableInset(), lt(0), in_update(false)
139 InsetText::InsetText(InsetText const & in, bool same_id)
140 : UpdatableInset(in, same_id), lt(0), in_update(false)
147 InsetText & InsetText::operator=(InsetText const & it)
154 void InsetText::init(InsetText const * ins, bool same_id)
157 setParagraphData(ins->par);
158 autoBreakRows = ins->autoBreakRows;
159 drawFrame_ = ins->drawFrame_;
160 frame_color = ins->frame_color;
166 p->setInsetOwner(this);
169 the_locking_inset = 0;
171 frame_color = LColor::insetframe;
172 autoBreakRows = false;
181 no_selection = false;
188 last_drawn_width = -1;
189 frame_is_visible = false;
195 InsetText::~InsetText()
202 Paragraph * tmp = par->next();
209 void InsetText::clear()
212 Paragraph * tmp = par->next();
221 Inset * InsetText::clone(Buffer const &, bool same_id) const
223 return new InsetText(*this, same_id);
227 void InsetText::write(Buffer const * buf, ostream & os) const
230 writeParagraphData(buf, os);
234 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
236 par->writeFile(buf, os, buf->params, 0);
240 void InsetText::read(Buffer const * buf, LyXLex & lex)
244 Paragraph * return_par = 0;
245 Paragraph::depth_type depth = 0;
246 LyXFont font(LyXFont::ALL_INHERIT);
252 token = lex.getString();
255 if (token == "\\end_inset") {
256 #ifndef NO_COMPABILITY
257 const_cast<Buffer*>(buf)->insertErtContents(par, pos, font, false);
262 if (const_cast<Buffer*>(buf)->
263 parseSingleLyXformat2Token(lex, par, return_par,
264 token, pos, depth, font)) {
265 // the_end read this should NEVER happen
266 lex.printError("\\the_end read in inset! Error in document!");
274 return_par->setInsetOwner(this);
275 return_par = return_par->next();
278 if (token != "\\end_inset") {
279 lex.printError("Missing \\end_inset at this point. "
286 int InsetText::ascent(BufferView * bv, LyXFont const &) const
289 Row * row = getLyXText(bv)->getRowNearY(y_temp);
290 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
295 int InsetText::descent(BufferView * bv, LyXFont const &) const
303 Row * row = lt->getRowNearY(y_temp);
304 insetDescent = lt->height - row->ascent_of_text() +
305 TEXT_TO_INSET_OFFSET;
312 int InsetText::width(BufferView * bv, LyXFont const &) const
314 insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
315 (2 * TEXT_TO_INSET_OFFSET);
316 insetWidth = max(insetWidth, 10);
321 int InsetText::textWidth(BufferView * bv, bool fordraw) const
324 if (!autoBreakRows) {
327 w = getMaxWidth(bv, this);
330 return max(w - (2 * TEXT_TO_INSET_OFFSET),
331 (int)getLyXText(bv)->width);
335 return w - (2 * TEXT_TO_INSET_OFFSET);
339 void InsetText::draw(BufferView * bv, LyXFont const & f,
340 int baseline, float & x, bool cleared) const
345 Painter & pain = bv->painter();
347 // this is the first thing we have to ask because if the x pos
348 // changed we have to do a complete rebreak of the text as we
349 // may have few space to draw in. Well we should check on this too
351 if (top_x != int(x)) {
353 int nw = getMaxWidth(bv, this);
354 if (nw > 0 && old_max_width != nw) {
357 bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
365 // repaint the background if needed
366 if (cleared && backgroundColor() != LColor::background) {
368 clearInset(pain, baseline, cleared);
372 // no draw is necessary !!!
373 if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
376 top_baseline = baseline;
378 if (need_update & CLEAR_FRAME)
379 clearFrame(pain, cleared);
386 x += static_cast<float>(scroll());
388 // if top_x differs we did it already
389 if (!cleared && (top_x == int(x)) &&
390 ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
391 (last_drawn_width!=insetWidth))) {
392 clearInset(pain, baseline, cleared);
398 frame_is_visible = false;
400 if (!cleared && (need_update == NONE)) {
402 drawFrame(pain, cleared);
406 top_baseline = baseline;
407 top_y = baseline - ascent(bv, f);
408 last_width = width(bv, f);
409 last_height = ascent(bv, f) + descent(bv, f);
411 if (cleared || (last_drawn_width != insetWidth)) {
413 clearInset(pain, baseline, cleared);
415 last_drawn_width = insetWidth;
418 if (the_locking_inset && (cpar(bv) == inset_par)
419 && (cpos(bv) == inset_pos)) {
420 inset_x = cx(bv) - top_x + drawTextXOffset;
421 inset_y = cy(bv) + drawTextYOffset;
423 if (!cleared && (need_update == CURSOR)
424 && !getLyXText(bv)->selection.set())
426 drawFrame(pain, cleared);
427 x += last_width; // was width(bv, f);
436 x += TEXT_TO_INSET_OFFSET;
439 Row * row = lt->getRowNearY(y);
440 int y_offset = baseline - row->ascent_of_text();
441 int ph = pain.paperHeight();
444 while ((row != 0) && ((y+row->height()) <= 0)) {
446 first += row->height();
452 if (cleared || (need_update&(INIT|FULL))) {
455 while ((row != 0) && (yf < ph)) {
456 lt->getVisibleRow(bv, y+y_offset, int(x), row,
462 } else if (!locked) {
463 if (need_update & CURSOR) {
464 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
465 lt->clearSelection();
466 lt->selection.cursor = lt->cursor;
468 bv->screen()->update(lt, bv, y_offset, int(x));
471 if (need_update & SELECTION)
472 bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
473 else if (need_update & CURSOR) {
474 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
475 lt->clearSelection();
476 lt->selection.cursor = lt->cursor;
478 bv->screen()->update(lt, bv, y_offset, int(x));
483 lt->status(bv, LyXText::UNCHANGED);
484 if ((need_update != CURSOR_PAR) &&
485 ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
486 drawFrame(pain, cleared);
487 else if (need_update & CLEAR_FRAME)
488 clearFrame(pain, cleared);
489 x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
490 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
492 } else if (need_update != INIT)
499 void InsetText::drawFrame(Painter & pain, bool cleared) const
501 static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
502 if (!frame_is_visible || cleared) {
503 frame_x = top_x + ttoD2;
504 frame_y = top_baseline - insetAscent + ttoD2;
505 frame_w = last_width - TEXT_TO_INSET_OFFSET;
506 frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
507 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
509 frame_is_visible = true;
514 void InsetText::clearFrame(Painter & pain, bool cleared) const
516 if (frame_is_visible) {
518 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
521 frame_is_visible = false;
526 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
529 if (reinit && owner()) {
531 owner()->update(bv, font, true);
536 if (reinit || need_update == INIT) {
540 owner()->update(bv, font, true);
544 if (the_locking_inset) {
545 inset_x = cx(bv) - top_x + drawTextXOffset;
546 inset_y = cy(bv) + drawTextYOffset;
547 the_locking_inset->update(bv, font, reinit);
556 int oldw = insetWidth;
557 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
558 if (oldw != insetWidth) {
567 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
570 lt->updateInset(bv, the_locking_inset);
572 if (lt->status() == LyXText::NEED_MORE_REFRESH)
580 void InsetText::setUpdateStatus(BufferView * bv, int what) const
588 // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
589 // if we don't break row so that we only have one row to update!
590 if ((lt->status() == LyXText::NEED_MORE_REFRESH) ||
592 (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
595 } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
596 need_update |= CURSOR_PAR;
599 // this to not draw a selection when we redraw all of it!
600 if (need_update & CURSOR && !(need_update & SELECTION)) {
601 if (lt->selection.set())
603 lt->clearSelection();
610 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
618 setUpdateStatus(bv, what);
619 if (((need_update != CURSOR) && (need_update != NONE)) ||
620 (lt->status() != LyXText::UNCHANGED) || lt->selection.set())
622 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
624 if (need_update == CURSOR)
626 bv->owner()->showState();
627 if (old_par != cpar(bv)) {
628 bv->owner()->setLayout(cpar(bv)->getLayout());
636 string const InsetText::editMessage() const
638 return _("Opened Text Inset");
642 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
644 UpdatableInset::edit(bv, x, y, button);
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;
656 int tmp_y = (y < 0) ? 0 : y;
663 if (!checkAndActivateInset(bv, x, tmp_y, button))
664 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
666 lt->clearSelection();
669 updateLocal(bv, CURSOR, false);
671 // If the inset is empty set the language of the current font to the
672 // language to the surronding text (if different).
673 if (par->size() == 0 && !par->next() &&
674 bv->getParentLanguage(this) != lt->current_font.language()) {
675 LyXFont font(LyXFont::ALL_IGNORE);
676 font.setLanguage(bv->getParentLanguage(this));
677 setFont(bv, font, false);
684 void InsetText::edit(BufferView * bv, bool front)
686 UpdatableInset::edit(bv, front);
688 if (!bv->lockInset(this)) {
689 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
693 the_locking_inset = 0;
694 inset_pos = inset_x = inset_y = 0;
695 inset_boundary = false;
704 lt->setCursor(bv, par, 0);
709 int const pos = (p->size() ? p->size()-1 : p->size());
710 lt->setCursor(bv, p, pos);
712 lt->clearSelection();
715 updateLocal(bv, CURSOR, false);
717 // If the inset is empty set the language of the current font to the
718 // language to the surronding text (if different).
719 if (par->size() == 0 && !par->next() &&
720 bv->getParentLanguage(this) != lt->current_font.language()) {
721 LyXFont font(LyXFont::ALL_IGNORE);
722 font.setLanguage(bv->getParentLanguage(this));
723 setFont(bv, font, false);
730 void InsetText::insetUnlock(BufferView * bv)
732 if (the_locking_inset) {
733 the_locking_inset->insetUnlock(bv);
734 the_locking_inset = 0;
737 no_selection = false;
740 if (drawFrame_ == LOCKED)
741 code = CURSOR|CLEAR_FRAME;
749 if (lt->selection.set()) {
750 lt->clearSelection();
752 } else if (owner()) {
753 bv->owner()->setLayout(owner()->getLyXText(bv)
754 ->cursor.par()->getLayout());
756 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
757 // hack for deleteEmptyParMech
758 lt->setCursor(bv, par, 0);
759 updateLocal(bv, code, false);
765 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
767 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
771 if (inset == cpar(bv)->getInset(cpos(bv))) {
772 lyxerr[Debug::INSETS] << "OK" << endl;
773 the_locking_inset = inset;
774 inset_x = cx(bv) - top_x + drawTextXOffset;
775 inset_y = cy(bv) + drawTextYOffset;
776 inset_pos = cpos(bv);
777 inset_par = cpar(bv);
778 inset_boundary = cboundary(bv);
779 updateLocal(bv, CURSOR, false);
781 } else if (the_locking_inset && (the_locking_inset == inset)) {
782 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
783 lyxerr[Debug::INSETS] << "OK" << endl;
784 inset_x = cx(bv) - top_x + drawTextXOffset;
785 inset_y = cy(bv) + drawTextYOffset;
787 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
789 } else if (the_locking_inset) {
790 lyxerr[Debug::INSETS] << "MAYBE" << endl;
791 return the_locking_inset->lockInsetInInset(bv, inset);
793 lyxerr[Debug::INSETS] << "NOT OK" << endl;
798 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
801 if (!the_locking_inset)
803 if (the_locking_inset == inset) {
804 the_locking_inset->insetUnlock(bv);
805 getLyXText(bv)->updateInset(bv, inset);
806 the_locking_inset = 0;
808 moveRight(bv, false);
809 old_par = 0; // force layout setting
813 updateLocal(bv, CURSOR, false);
816 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
820 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
822 if (!the_locking_inset)
824 if (the_locking_inset != inset) {
825 getLyXText(bv)->updateInset(bv, the_locking_inset);
826 setUpdateStatus(bv, CURSOR_PAR);
827 return the_locking_inset->updateInsetInInset(bv, inset);
829 if (getLyXText(bv)->updateInset(bv, inset))
830 updateLocal(bv, CURSOR_PAR, false);
831 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
832 inset_x = cx(bv) - top_x + drawTextXOffset;
833 inset_y = cy(bv) + drawTextYOffset;
839 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
843 int tmp_x = x - drawTextXOffset;
844 int tmp_y = y + insetAscent - getLyXText(bv)->first;
845 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
848 if (the_locking_inset) {
849 if (the_locking_inset == inset) {
850 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
851 no_selection = false;
854 // otherwise unlock the_locking_inset and lock the new inset
855 the_locking_inset->insetUnlock(bv);
856 inset_x = cx(bv) - top_x + drawTextXOffset;
857 inset_y = cy(bv) + drawTextYOffset;
858 the_locking_inset = static_cast<UpdatableInset*>(inset);
859 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
860 inset->edit(bv, x - inset_x, y - inset_y, button);
861 if (the_locking_inset)
862 updateLocal(bv, CURSOR, false);
863 no_selection = false;
866 // otherwise only unlock the_locking_inset
867 the_locking_inset->insetUnlock(bv);
868 the_locking_inset = 0;
870 if (bv->theLockingInset()) {
871 if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
872 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
873 inset_x = cx(bv) - top_x + drawTextXOffset;
874 inset_y = cy(bv) + drawTextYOffset;
875 inset_pos = cpos(bv);
876 inset_par = cpar(bv);
877 inset_boundary = cboundary(bv);
878 the_locking_inset = uinset;
879 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
881 uinset->edit(bv, x - inset_x, y - inset_y, 0);
882 if (the_locking_inset)
883 updateLocal(bv, CURSOR, false);
884 no_selection = false;
888 if (!inset) { // && (button == 2)) {
889 bool paste_internally = false;
890 if ((button == 2) && getLyXText(bv)->selection.set()) {
891 localDispatch(bv, LFUN_COPY, "");
892 paste_internally = true;
899 lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent);
900 if (lt->selection.set()) {
901 lt->clearSelection();
902 updateLocal(bv, FULL, false);
904 lt->clearSelection();
906 bv->owner()->setLayout(cpar(bv)->getLayout());
908 // Insert primary selection with middle mouse
909 // if there is a local selection in the current buffer,
912 if (paste_internally)
913 localDispatch(bv, LFUN_PASTE, "");
915 localDispatch(bv, LFUN_PASTESELECTION,
922 no_selection = false;
926 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
928 UpdatableInset * inset = 0;
930 if (the_locking_inset) {
931 the_locking_inset->insetButtonRelease(bv,
932 x - inset_x, y - inset_y,
935 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
936 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
937 if (inset->editable() == Inset::HIGHLY_EDITABLE) {
938 inset->insetButtonRelease(bv,
940 y - inset_y, button);
942 inset_x = cx(bv) - top_x + drawTextXOffset;
943 inset_y = cy(bv) + drawTextYOffset;
944 inset->insetButtonRelease(bv,
946 y - inset_y, button);
948 x - inset_x, y - inset_y, button);
950 updateLocal(bv, CURSOR_PAR, false);
953 no_selection = false;
957 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
961 if (the_locking_inset) {
962 the_locking_inset->insetMotionNotify(bv, x - inset_x,
966 LyXText * t = getLyXText(bv);
968 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
970 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
971 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
972 updateLocal(bv, SELECTION, false);
977 void InsetText::insetKeyPress(XKeyEvent * xke)
979 if (the_locking_inset) {
980 the_locking_inset->insetKeyPress(xke);
986 UpdatableInset::RESULT
987 InsetText::localDispatch(BufferView * bv,
988 kb_action action, string const & arg)
990 no_selection = false;
991 UpdatableInset::RESULT
992 result= UpdatableInset::localDispatch(bv, action, arg);
993 if (result != UNDISPATCHED) {
998 if ((action < 0) && arg.empty())
1001 if (the_locking_inset) {
1002 result = the_locking_inset->localDispatch(bv, action, arg);
1003 if (result == DISPATCHED_NOUPDATE)
1005 else if (result == DISPATCHED) {
1006 updateLocal(bv, CURSOR_PAR, false);
1008 } else if (result == FINISHED) {
1009 bool dispatched = false;
1011 case LFUN_UNKNOWN_ACTION:
1012 case LFUN_BREAKPARAGRAPH:
1013 case LFUN_BREAKLINE:
1014 moveRightIntern(bv, false, false);
1017 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1018 moveRightIntern(bv, false, false);
1022 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1023 moveRightIntern(bv, false, false);
1029 the_locking_inset = 0;
1034 hideInsetCursor(bv);
1037 lt = getLyXText(bv);
1042 case LFUN_SELFINSERT:
1043 if (bv->buffer()->isReadonly()) {
1044 // setErrorMessage(N_("Document is read only"));
1048 /* Automatically delete the currently selected
1049 * text and replace it with what is being
1050 * typed in now. Depends on lyxrc settings
1051 * "auto_region_delete", which defaults to
1054 setUndo(bv, Undo::INSERT,
1055 lt->cursor.par(), lt->cursor.par()->next());
1057 if (lyxrc.auto_region_delete) {
1058 if (lt->selection.set()) {
1059 lt->cutSelection(bv, false);
1062 lt->clearSelection();
1063 for (string::size_type i = 0; i < arg.length(); ++i) {
1064 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1067 lt->selection.cursor = lt->cursor;
1068 updateLocal(bv, CURSOR_PAR, true);
1069 result = DISPATCHED_NOUPDATE;
1071 // --- Cursor Movements -----------------------------------
1074 moveRight(bv, false, true);
1075 lt->setSelection(bv);
1076 updateLocal(bv, SELECTION, false);
1079 result = moveRight(bv);
1081 updateLocal(bv, CURSOR, false);
1085 moveLeft(bv, false, true);
1086 lt->setSelection(bv);
1087 updateLocal(bv, SELECTION, false);
1091 result = moveLeft(bv);
1092 updateLocal(bv, CURSOR, false);
1097 lt->setSelection(bv);
1098 updateLocal(bv, SELECTION, false);
1102 result = moveDown(bv);
1103 updateLocal(bv, CURSOR, false);
1108 lt->setSelection(bv);
1109 updateLocal(bv, SELECTION, false);
1113 result = moveUp(bv);
1114 updateLocal(bv, CURSOR, false);
1119 updateLocal(bv, CURSOR, false);
1123 updateLocal(bv, CURSOR, false);
1125 case LFUN_BACKSPACE: {
1126 setUndo(bv, Undo::DELETE,
1127 lt->cursor.par(), lt->cursor.par()->next());
1128 if (lt->selection.set())
1129 lt->cutSelection(bv);
1132 updateLocal(bv, CURSOR_PAR, true);
1137 setUndo(bv, Undo::DELETE,
1138 lt->cursor.par(), lt->cursor.par()->next());
1139 if (lt->selection.set()) {
1140 lt->cutSelection(bv);
1144 updateLocal(bv, CURSOR_PAR, true);
1149 setUndo(bv, Undo::DELETE,
1150 lt->cursor.par(), lt->cursor.par()->next());
1151 lt->cutSelection(bv);
1152 updateLocal(bv, CURSOR_PAR, true);
1158 lt->copySelection(bv);
1159 updateLocal(bv, CURSOR_PAR, false);
1161 case LFUN_PASTESELECTION:
1163 string const clip(bv->getClipboard());
1167 if (arg == "paragraph") {
1168 lt->insertStringAsParagraphs(bv, clip);
1170 lt->insertStringAsLines(bv, clip);
1172 updateLocal(bv, CURSOR_PAR, true);
1176 if (!autoBreakRows) {
1178 if (CutAndPaste::nrOfParagraphs() > 1) {
1179 WriteAlert(_("Impossible operation"),
1180 _("Cannot include more than one paragraph!"),
1185 setUndo(bv, Undo::INSERT,
1186 lt->cursor.par(), lt->cursor.par()->next());
1187 lt->pasteSelection(bv);
1188 updateLocal(bv, CURSOR_PAR, true);
1192 case LFUN_BREAKPARAGRAPH:
1193 if (!autoBreakRows) {
1194 result = DISPATCHED;
1197 lt->breakParagraph(bv, 0);
1198 updateLocal(bv, FULL, true);
1200 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1201 if (!autoBreakRows) {
1202 result = DISPATCHED;
1205 lt->breakParagraph(bv, 1);
1206 updateLocal(bv, FULL, true);
1209 case LFUN_BREAKLINE: {
1210 if (!autoBreakRows) {
1211 result = DISPATCHED;
1214 setUndo(bv, Undo::INSERT,
1215 lt->cursor.par(), lt->cursor.par()->next());
1216 lt->insertChar(bv, Paragraph::META_NEWLINE);
1217 updateLocal(bv, CURSOR_PAR, true);
1222 // do not set layouts on non breakable textinsets
1223 if (autoBreakRows) {
1224 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1226 // Derive layout number from given argument (string)
1227 // and current buffer's textclass (number). */
1228 LyXTextClassList::ClassList::size_type tclass =
1229 bv->buffer()->params.textclass;
1230 std::pair <bool, LyXTextClass::size_type> layout =
1231 textclasslist.NumberOfLayout(tclass, arg);
1233 // If the entry is obsolete, use the new one instead.
1235 string obs = textclasslist.Style(tclass,layout.second).
1238 layout = textclasslist.NumberOfLayout(tclass, obs);
1241 // see if we found the layout number:
1242 if (!layout.first) {
1243 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1244 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1248 if (cur_layout != layout.second) {
1249 cur_layout = layout.second;
1250 lt->setLayout(bv, layout.second);
1251 bv->owner()->setLayout(cpar(bv)->getLayout());
1252 updateLocal(bv, CURSOR_PAR, true);
1255 // reset the layout box
1256 bv->owner()->setLayout(cpar(bv)->getLayout());
1259 case LFUN_PARAGRAPH_SPACING:
1260 // This one is absolutely not working. When fiddling with this
1261 // it also seems to me that the paragraphs inside the insettext
1262 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1264 Paragraph * par = lt->cursor.par();
1265 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1266 float cur_value = 1.0;
1267 if (cur_spacing == Spacing::Other) {
1268 cur_value = par->params().spacing().getValue();
1271 istringstream istr(arg.c_str());
1274 Spacing::Space new_spacing = cur_spacing;
1275 float new_value = cur_value;
1277 lyxerr << "Missing argument to `paragraph-spacing'"
1279 } else if (tmp == "single") {
1280 new_spacing = Spacing::Single;
1281 } else if (tmp == "onehalf") {
1282 new_spacing = Spacing::Onehalf;
1283 } else if (tmp == "double") {
1284 new_spacing = Spacing::Double;
1285 } else if (tmp == "other") {
1286 new_spacing = Spacing::Other;
1289 lyxerr << "new_value = " << tmpval << endl;
1292 } else if (tmp == "default") {
1293 new_spacing = Spacing::Default;
1295 lyxerr << _("Unknown spacing argument: ")
1298 if (cur_spacing != new_spacing || cur_value != new_value) {
1299 par->params().spacing(Spacing(new_spacing, new_value));
1300 updateLocal(bv, CURSOR_PAR, true);
1306 if (!bv->Dispatch(action, arg))
1307 result = UNDISPATCHED;
1311 /// If the action has deleted all text in the inset, we need to change the
1312 // language to the language of the surronding text.
1313 if (par->size() == 0 && !par->next()) {
1314 LyXFont font(LyXFont::ALL_IGNORE);
1315 font.setLanguage(bv->getParentLanguage(this));
1316 setFont(bv, font, false);
1319 if (result != FINISHED) {
1320 showInsetCursor(bv);
1322 bv->unlockInset(this);
1329 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1332 buf->latexParagraphs(os, par, 0, texrow);
1333 return texrow.rows();
1337 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1339 Paragraph * p = par;
1340 unsigned int lines = 0;
1343 string const tmp = buf->asciiParagraph(p, linelen);
1344 lines += countChar(tmp, '\n');
1352 int InsetText::docBook(Buffer const * buf, ostream & os) const
1354 Paragraph * p = par;
1355 unsigned int lines = 0;
1360 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1368 void InsetText::validate(LaTeXFeatures & features) const
1370 Paragraph * p = par;
1372 p->validate(features);
1378 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1380 if (textclasslist.Style(buf->params.textclass,
1381 p->getLayout()).labeltype != LABEL_MANUAL)
1384 return p->beginningOfMainBody();
1388 void InsetText::getCursorPos(BufferView * bv,
1389 int & x, int & y) const
1391 if (the_locking_inset) {
1392 the_locking_inset->getCursorPos(bv, x, y);
1400 unsigned int InsetText::insetInInsetY()
1402 if (!the_locking_inset)
1405 return (inset_y + the_locking_inset->insetInInsetY());
1409 void InsetText::toggleInsetCursor(BufferView * bv)
1411 if (the_locking_inset) {
1412 the_locking_inset->toggleInsetCursor(bv);
1416 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1418 int const asc = lyxfont::maxAscent(font);
1419 int const desc = lyxfont::maxDescent(font);
1421 if (isCursorVisible())
1422 bv->hideLockedInsetCursor();
1424 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1425 toggleCursorVisible();
1429 void InsetText::showInsetCursor(BufferView * bv, bool show)
1431 if (the_locking_inset) {
1432 the_locking_inset->showInsetCursor(bv, show);
1435 if (!isCursorVisible()) {
1436 LyXFont const font =
1437 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1439 int const asc = lyxfont::maxAscent(font);
1440 int const desc = lyxfont::maxDescent(font);
1442 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1444 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1445 setCursorVisible(true);
1450 void InsetText::hideInsetCursor(BufferView * bv)
1452 if (isCursorVisible()) {
1453 bv->hideLockedInsetCursor();
1454 setCursorVisible(false);
1456 if (the_locking_inset)
1457 the_locking_inset->hideInsetCursor(bv);
1461 void InsetText::fitInsetCursor(BufferView * bv) const
1463 if (the_locking_inset) {
1464 the_locking_inset->fitInsetCursor(bv);
1467 LyXFont const font =
1468 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1470 int const asc = lyxfont::maxAscent(font);
1471 int const desc = lyxfont::maxDescent(font);
1473 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1477 UpdatableInset::RESULT
1478 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1480 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1481 return moveLeftIntern(bv, false, activate_inset, selecting);
1483 return moveRightIntern(bv, false, activate_inset, selecting);
1487 UpdatableInset::RESULT
1488 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1490 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1491 return moveRightIntern(bv, true, activate_inset, selecting);
1493 return moveLeftIntern(bv, true, activate_inset, selecting);
1497 UpdatableInset::RESULT
1498 InsetText::moveRightIntern(BufferView * bv, bool behind,
1499 bool activate_inset, bool selecting)
1501 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1503 if (activate_inset && checkAndActivateInset(bv, behind))
1505 getLyXText(bv)->cursorRight(bv);
1507 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1508 return DISPATCHED_NOUPDATE;
1512 UpdatableInset::RESULT
1513 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1514 bool activate_inset, bool selecting)
1516 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1518 getLyXText(bv)->cursorLeft(bv);
1520 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1521 if (activate_inset && checkAndActivateInset(bv, behind))
1523 return DISPATCHED_NOUPDATE;
1527 UpdatableInset::RESULT
1528 InsetText::moveUp(BufferView * bv)
1530 if (!crow(bv)->previous())
1532 getLyXText(bv)->cursorUp(bv);
1533 return DISPATCHED_NOUPDATE;
1537 UpdatableInset::RESULT
1538 InsetText::moveDown(BufferView * bv)
1540 if (!crow(bv)->next())
1542 getLyXText(bv)->cursorDown(bv);
1543 return DISPATCHED_NOUPDATE;
1547 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1549 if (the_locking_inset) {
1550 if (the_locking_inset->insetAllowed(inset))
1551 return the_locking_inset->insertInset(bv, inset);
1554 inset->setOwner(this);
1555 hideInsetCursor(bv);
1559 lt = getLyXText(bv);
1562 lt->insertInset(bv, inset);
1564 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1565 (cpar(bv)->getInset(cpos(bv)) != inset))
1569 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1570 showInsetCursor(bv);
1577 bool InsetText::insetAllowed(Inset::Code code) const
1579 if (the_locking_inset)
1580 return the_locking_inset->insetAllowed(code);
1585 UpdatableInset * InsetText::getLockingInset() const
1587 return the_locking_inset ? the_locking_inset->getLockingInset() :
1588 const_cast<InsetText *>(this);
1592 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1596 if (the_locking_inset)
1597 return the_locking_inset->getFirstLockingInsetOfType(c);
1602 bool InsetText::showInsetDialog(BufferView * bv) const
1604 if (the_locking_inset)
1605 return the_locking_inset->showInsetDialog(bv);
1610 std::vector<string> const InsetText::getLabelList() const
1612 std::vector<string> label_list;
1614 Paragraph * tpar = par;
1616 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1617 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1618 for (; beg != end; ++beg) {
1619 std::vector<string> const l = (*beg)->getLabelList();
1620 label_list.insert(label_list.end(), l.begin(), l.end());
1622 tpar = tpar->next();
1628 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1631 if (the_locking_inset) {
1632 the_locking_inset->setFont(bv, font, toggleall, selectall);
1635 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1636 getLyXText(bv)->setFont(bv, font, toggleall);
1641 lt = getLyXText(bv);
1644 if (lt->selection.set()) {
1645 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1649 lt->toggleFree(bv, font, toggleall);
1651 lt->clearSelection();
1653 if (selectall || lt->selection.set())
1654 updateLocal(bv, FULL, true);
1656 updateLocal(bv, CURSOR_PAR, true);
1662 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1664 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1668 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1669 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1671 LyXFont const font =
1672 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1674 x = inset->width(bv, font);
1675 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1678 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1680 //inset_x = cx(bv) - top_x + drawTextXOffset;
1681 //inset_y = cy(bv) + drawTextYOffset;
1682 inset->edit(bv, x, y, 0);
1683 if (!the_locking_inset)
1685 updateLocal(bv, CURSOR, false);
1692 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1695 x -= drawTextXOffset;
1697 int dummyy = y + insetAscent;
1698 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1705 inset_x = cx(bv) - top_x + drawTextXOffset;
1706 inset_y = cy(bv) + drawTextYOffset;
1707 inset->edit(bv, x - inset_x, y - inset_y, button);
1708 if (!the_locking_inset)
1710 updateLocal(bv, CURSOR, false);
1717 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1720 int w = UpdatableInset::getMaxWidth(bv, inset);
1725 w = w - top_x + owner()->x();
1728 w -= (2 * TEXT_TO_INSET_OFFSET);
1731 return UpdatableInset::getMaxWidth(bv, inset);
1736 void InsetText::setParagraphData(Paragraph * p)
1738 // we have to unlock any locked inset otherwise we're in troubles
1739 the_locking_inset = 0;
1741 Paragraph * tmp = par->next();
1746 par = new Paragraph(*p);
1747 par->setInsetOwner(this);
1748 Paragraph * np = par;
1751 np->next(new Paragraph(*p));
1752 np->next()->previous(np);
1754 np->setInsetOwner(this);
1760 void InsetText::setText(string const & data)
1763 LyXFont font(LyXFont::ALL_SANE);
1764 for (unsigned int i=0; i < data.length(); ++i)
1765 par->insertChar(i, data[i], font);
1769 void InsetText::setAutoBreakRows(bool flag)
1771 if (flag != autoBreakRows) {
1772 autoBreakRows = flag;
1780 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1782 if (how != drawFrame_) {
1785 updateLocal(bv, DRAW_FRAME, false);
1790 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1792 if (frame_color != col) {
1795 updateLocal(bv, DRAW_FRAME, false);
1800 int InsetText::cx(BufferView * bv) const
1804 lt = getLyXText(bv);
1807 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1808 if (the_locking_inset) {
1809 LyXFont font = lt->getFont(bv->buffer(),
1812 if (font.isVisibleRightToLeft())
1813 x -= the_locking_inset->width(bv, font);
1821 int InsetText::cy(BufferView * bv) const
1824 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1828 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1830 return getLyXText(bv)->cursor.pos();
1834 Paragraph * InsetText::cpar(BufferView * bv) const
1836 return getLyXText(bv)->cursor.par();
1840 bool InsetText::cboundary(BufferView * bv) const
1842 return getLyXText(bv)->cursor.boundary();
1846 Row * InsetText::crow(BufferView * bv) const
1848 return getLyXText(bv)->cursor.row();
1852 LyXText * InsetText::getLyXText(BufferView const * lbv,
1853 bool const recursive) const
1855 if (!recursive && (cached_bview == lbv))
1856 return cached_text.get();
1858 // Super UGLY! (Lgb)
1859 BufferView * bv = const_cast<BufferView *>(lbv);
1862 Cache::iterator it = cache.find(bv);
1864 if (it != cache.end()) {
1865 if (lt || !it->second.remove) {
1866 lyx::Assert(it->second.text.get());
1867 cached_text = it->second.text;
1868 if (recursive && the_locking_inset) {
1869 return the_locking_inset->getLyXText(bv, true);
1871 return cached_text.get();
1872 } else if (it->second.remove) {
1874 saveLyXTextState(it->second.text.get());
1881 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1882 cached_text->init(bv);
1883 restoreLyXTextState(bv, cached_text.get());
1885 cache.insert(make_pair(bv, cached_text));
1887 if (the_locking_inset && recursive) {
1888 return the_locking_inset->getLyXText(bv);
1890 return cached_text.get();
1894 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1898 Cache::iterator it = cache.find(bv);
1900 if (it == cache.end()) {
1904 lyx::Assert(it->second.text.get());
1906 it->second.remove = true;
1908 /// then remove all LyXText in text-insets
1909 Paragraph * p = par;
1910 for (; p; p = p->next()) {
1911 p->deleteInsetsLyXText(bv);
1917 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1919 // lyxerr << "InsetText::resizeLyXText\n";
1920 if (!par->next() && !par->size()) // no data, resize not neccessary!
1922 // one endless line, resize normally not necessary
1923 if (!force && getMaxWidth(bv, this) < 0)
1926 Cache::iterator it = cache.find(bv);
1927 if (it == cache.end()) {
1930 lyx::Assert(it->second.text.get());
1932 LyXText * t = it->second.text.get();
1933 saveLyXTextState(t);
1934 for (Paragraph * p = par; p; p = p->next()) {
1935 p->resizeInsetsLyXText(bv);
1938 restoreLyXTextState(bv, t);
1939 if (the_locking_inset) {
1940 inset_x = cx(bv) - top_x + drawTextXOffset;
1941 inset_y = cy(bv) + drawTextYOffset;
1945 t->first = bv->screen()->topCursorVisible(t);
1948 updateLocal(bv, FULL, false);
1949 // this will scroll the screen such that the cursor becomes visible
1950 bv->updateScrollbar();
1952 need_update |= FULL;
1957 void InsetText::reinitLyXText() const
1959 // lyxerr << "InsetText::reinitLyXText\n";
1960 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1961 lyx::Assert(it->second.text.get());
1963 LyXText * t = it->second.text.get();
1964 BufferView * bv = it->first;
1966 saveLyXTextState(t);
1967 for (Paragraph * p = par; p; p = p->next()) {
1968 p->resizeInsetsLyXText(bv);
1971 restoreLyXTextState(bv, t);
1972 if (the_locking_inset) {
1973 inset_x = cx(bv) - top_x + drawTextXOffset;
1974 inset_y = cy(bv) + drawTextYOffset;
1977 t->first = bv->screen()->topCursorVisible(t);
1980 updateLocal(bv, FULL, false);
1981 // this will scroll the screen such that the cursor becomes visible
1982 bv->updateScrollbar();
1990 void InsetText::removeNewlines()
1992 for (Paragraph * p = par; p; p = p->next()) {
1993 for (int i = 0; i < p->size(); ++i) {
1994 if (p->getChar(i) == Paragraph::META_NEWLINE)
2001 bool InsetText::nodraw() const
2003 if (the_locking_inset)
2004 return the_locking_inset->nodraw();
2005 return UpdatableInset::nodraw();
2009 int InsetText::scroll(bool recursive) const
2011 int sx = UpdatableInset::scroll(false);
2013 if (recursive && the_locking_inset)
2014 sx += the_locking_inset->scroll(recursive);
2020 bool InsetText::doClearArea() const
2022 return !locked || (need_update & (FULL|INIT));
2026 void InsetText::selectAll(BufferView * bv)
2028 getLyXText(bv)->cursorTop(bv);
2029 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2030 getLyXText(bv)->cursorBottom(bv);
2031 getLyXText(bv)->setSelection(bv);
2035 void InsetText::clearSelection(BufferView * bv)
2037 getLyXText(bv)->clearSelection();
2041 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2044 int h = insetAscent + insetDescent;
2045 int ty = baseline - insetAscent;
2051 if ((ty + h) > pain.paperHeight())
2052 h = pain.paperHeight();
2053 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2054 w = pain.paperWidth();
2055 // w -= TEXT_TO_INSET_OFFSET;
2056 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2059 frame_is_visible = false;
2063 Paragraph * InsetText::getParFromID(int id) const
2066 Paragraph * result = par;
2067 Paragraph * ires = 0;
2068 while (result && result->id() != id) {
2069 if ((ires = result->getParFromID(id)))
2071 result = result->next();
2075 Paragraph * tmp = par;
2077 int tmp_id = tmp->id();
2078 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2079 if (tmp->id() == id) {
2082 Paragraph * tmp2 = tmp->getParFromID(id);
2093 Paragraph * InsetText::firstParagraph() const
2096 if (the_locking_inset)
2097 if ((result = the_locking_inset->firstParagraph()))
2103 LyXCursor const & InsetText::cursor(BufferView * bv) const
2105 if (the_locking_inset)
2106 return the_locking_inset->cursor(bv);
2107 return getLyXText(bv)->cursor;
2111 Paragraph * InsetText::paragraph() const
2117 void InsetText::paragraph(Paragraph * p)
2121 // we now have to update/redraw all instances
2122 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2127 // redraw myself when asked for
2132 Inset * InsetText::getInsetFromID(int id_arg) const
2135 return const_cast<InsetText *>(this);
2137 Paragraph * lp = par;
2140 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2141 en = lp->inset_iterator_end();
2144 if ((*it)->id() == id_arg)
2146 Inset * in = (*it)->getInsetFromID(id_arg);
2156 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2162 lt = getLyXText(bv);
2165 if (the_locking_inset) {
2166 str = the_locking_inset->selectNextWord(bv, value);
2173 #warning Dekel please have a look on this one RTL? (Jug)
2174 // we have to go on checking so move cusor to the right
2175 lt->cursor.pos(lt->cursor.pos() + 1);
2177 str = lt->selectNextWord(bv, value);
2179 bv->unlockInset(const_cast<InsetText *>(this));
2188 void InsetText::selectSelectedWord(BufferView * bv)
2190 if (the_locking_inset) {
2191 the_locking_inset->selectSelectedWord(bv);
2194 getLyXText(bv)->selectSelectedWord(bv);
2195 updateLocal(bv, SELECTION, false);
2199 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2201 if (the_locking_inset) {
2202 the_locking_inset->toggleSelection(bv, kill_selection);
2206 lt = getLyXText(bv);
2210 int x = top_x + TEXT_TO_INSET_OFFSET;
2213 Row * row = lt->getRowNearY(y);
2214 int y_offset = top_baseline - row->ascent_of_text();
2216 while ((row != 0) && ((y+row->height()) <= 0)) {
2223 if (need_update & SELECTION)
2225 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2231 bool InsetText::searchForward(BufferView * bv, string const & str,
2232 bool const & cs, bool const & mw)
2234 if (the_locking_inset) {
2235 if (the_locking_inset->searchForward(bv, str, cs, mw))
2239 lt = getLyXText(bv);
2242 Paragraph * lpar = lt->cursor.par();
2243 Paragraph::size_type pos = lt->cursor.pos();
2244 if (pos < lpar->size() - 1)
2248 lpar = lpar->next();
2255 lt->setCursor(bv, lpar, pos);
2259 if (LyXFind(bv, str, true, true, cs , mw)) {
2262 // we have to unlock ourself in this function by default!
2263 bv->unlockInset(const_cast<InsetText *>(this));
2267 bool InsetText::searchBackward(BufferView * bv, string const & str,
2268 bool const & cs, bool const & mw)
2270 if (the_locking_inset)
2271 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2273 if (LyXFind(bv, str, false, true, cs, mw)) {
2276 // we have to unlock ourself in this function by default!
2277 bv->unlockInset(const_cast<InsetText *>(this));