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 bool was_empty = par->size() == 0 && !par->next();
991 no_selection = false;
992 UpdatableInset::RESULT
993 result= UpdatableInset::localDispatch(bv, action, arg);
994 if (result != UNDISPATCHED) {
999 if ((action < 0) && arg.empty())
1002 if (the_locking_inset) {
1003 result = the_locking_inset->localDispatch(bv, action, arg);
1004 if (result == DISPATCHED_NOUPDATE)
1006 else if (result == DISPATCHED) {
1007 updateLocal(bv, CURSOR_PAR, false);
1009 } else if (result == FINISHED) {
1010 bool dispatched = false;
1012 case LFUN_UNKNOWN_ACTION:
1013 case LFUN_BREAKPARAGRAPH:
1014 case LFUN_BREAKLINE:
1015 moveRightIntern(bv, false, false);
1018 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1019 moveRightIntern(bv, false, false);
1023 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1024 moveRightIntern(bv, false, false);
1030 the_locking_inset = 0;
1035 hideInsetCursor(bv);
1038 lt = getLyXText(bv);
1043 case LFUN_SELFINSERT:
1044 if (bv->buffer()->isReadonly()) {
1045 // setErrorMessage(N_("Document is read only"));
1049 /* Automatically delete the currently selected
1050 * text and replace it with what is being
1051 * typed in now. Depends on lyxrc settings
1052 * "auto_region_delete", which defaults to
1055 setUndo(bv, Undo::INSERT,
1056 lt->cursor.par(), lt->cursor.par()->next());
1058 if (lyxrc.auto_region_delete) {
1059 if (lt->selection.set()) {
1060 lt->cutSelection(bv, false);
1063 lt->clearSelection();
1064 for (string::size_type i = 0; i < arg.length(); ++i) {
1065 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1068 lt->selection.cursor = lt->cursor;
1069 updateLocal(bv, CURSOR_PAR, true);
1070 result = DISPATCHED_NOUPDATE;
1072 // --- Cursor Movements -----------------------------------
1075 moveRight(bv, false, true);
1076 lt->setSelection(bv);
1077 updateLocal(bv, SELECTION, false);
1080 result = moveRight(bv);
1082 updateLocal(bv, CURSOR, false);
1086 moveLeft(bv, false, true);
1087 lt->setSelection(bv);
1088 updateLocal(bv, SELECTION, false);
1092 result = moveLeft(bv);
1093 updateLocal(bv, CURSOR, false);
1098 lt->setSelection(bv);
1099 updateLocal(bv, SELECTION, false);
1103 result = moveDown(bv);
1104 updateLocal(bv, CURSOR, false);
1109 lt->setSelection(bv);
1110 updateLocal(bv, SELECTION, false);
1114 result = moveUp(bv);
1115 updateLocal(bv, CURSOR, false);
1120 updateLocal(bv, CURSOR, false);
1124 updateLocal(bv, CURSOR, false);
1126 case LFUN_BACKSPACE: {
1127 setUndo(bv, Undo::DELETE,
1128 lt->cursor.par(), lt->cursor.par()->next());
1129 if (lt->selection.set())
1130 lt->cutSelection(bv);
1133 updateLocal(bv, CURSOR_PAR, true);
1138 setUndo(bv, Undo::DELETE,
1139 lt->cursor.par(), lt->cursor.par()->next());
1140 if (lt->selection.set()) {
1141 lt->cutSelection(bv);
1145 updateLocal(bv, CURSOR_PAR, true);
1150 setUndo(bv, Undo::DELETE,
1151 lt->cursor.par(), lt->cursor.par()->next());
1152 lt->cutSelection(bv);
1153 updateLocal(bv, CURSOR_PAR, true);
1159 lt->copySelection(bv);
1160 updateLocal(bv, CURSOR_PAR, false);
1162 case LFUN_PASTESELECTION:
1164 string const clip(bv->getClipboard());
1168 if (arg == "paragraph") {
1169 lt->insertStringAsParagraphs(bv, clip);
1171 lt->insertStringAsLines(bv, clip);
1173 updateLocal(bv, CURSOR_PAR, true);
1177 if (!autoBreakRows) {
1179 if (CutAndPaste::nrOfParagraphs() > 1) {
1180 WriteAlert(_("Impossible operation"),
1181 _("Cannot include more than one paragraph!"),
1186 setUndo(bv, Undo::INSERT,
1187 lt->cursor.par(), lt->cursor.par()->next());
1188 lt->pasteSelection(bv);
1189 updateLocal(bv, CURSOR_PAR, true);
1193 case LFUN_BREAKPARAGRAPH:
1194 if (!autoBreakRows) {
1195 result = DISPATCHED;
1198 lt->breakParagraph(bv, 0);
1199 updateLocal(bv, FULL, true);
1201 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1202 if (!autoBreakRows) {
1203 result = DISPATCHED;
1206 lt->breakParagraph(bv, 1);
1207 updateLocal(bv, FULL, true);
1210 case LFUN_BREAKLINE: {
1211 if (!autoBreakRows) {
1212 result = DISPATCHED;
1215 setUndo(bv, Undo::INSERT,
1216 lt->cursor.par(), lt->cursor.par()->next());
1217 lt->insertChar(bv, Paragraph::META_NEWLINE);
1218 updateLocal(bv, CURSOR_PAR, true);
1223 // do not set layouts on non breakable textinsets
1224 if (autoBreakRows) {
1225 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1227 // Derive layout number from given argument (string)
1228 // and current buffer's textclass (number). */
1229 LyXTextClassList::ClassList::size_type tclass =
1230 bv->buffer()->params.textclass;
1231 std::pair <bool, LyXTextClass::size_type> layout =
1232 textclasslist.NumberOfLayout(tclass, arg);
1234 // If the entry is obsolete, use the new one instead.
1236 string obs = textclasslist.Style(tclass,layout.second).
1239 layout = textclasslist.NumberOfLayout(tclass, obs);
1242 // see if we found the layout number:
1243 if (!layout.first) {
1244 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1245 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1249 if (cur_layout != layout.second) {
1250 cur_layout = layout.second;
1251 lt->setLayout(bv, layout.second);
1252 bv->owner()->setLayout(cpar(bv)->getLayout());
1253 updateLocal(bv, CURSOR_PAR, true);
1256 // reset the layout box
1257 bv->owner()->setLayout(cpar(bv)->getLayout());
1260 case LFUN_PARAGRAPH_SPACING:
1261 // This one is absolutely not working. When fiddling with this
1262 // it also seems to me that the paragraphs inside the insettext
1263 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1265 Paragraph * par = lt->cursor.par();
1266 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1267 float cur_value = 1.0;
1268 if (cur_spacing == Spacing::Other) {
1269 cur_value = par->params().spacing().getValue();
1272 istringstream istr(arg.c_str());
1275 Spacing::Space new_spacing = cur_spacing;
1276 float new_value = cur_value;
1278 lyxerr << "Missing argument to `paragraph-spacing'"
1280 } else if (tmp == "single") {
1281 new_spacing = Spacing::Single;
1282 } else if (tmp == "onehalf") {
1283 new_spacing = Spacing::Onehalf;
1284 } else if (tmp == "double") {
1285 new_spacing = Spacing::Double;
1286 } else if (tmp == "other") {
1287 new_spacing = Spacing::Other;
1290 lyxerr << "new_value = " << tmpval << endl;
1293 } else if (tmp == "default") {
1294 new_spacing = Spacing::Default;
1296 lyxerr << _("Unknown spacing argument: ")
1299 if (cur_spacing != new_spacing || cur_value != new_value) {
1300 par->params().spacing(Spacing(new_spacing, new_value));
1301 updateLocal(bv, CURSOR_PAR, true);
1307 if (!bv->Dispatch(action, arg))
1308 result = UNDISPATCHED;
1312 /// If the action has deleted all text in the inset, we need to change the
1313 // language to the language of the surronding text.
1314 if (!was_empty && par->size() == 0 && !par->next()) {
1315 LyXFont font(LyXFont::ALL_IGNORE);
1316 font.setLanguage(bv->getParentLanguage(this));
1317 setFont(bv, font, false);
1320 if (result != FINISHED) {
1321 showInsetCursor(bv);
1323 bv->unlockInset(this);
1330 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1333 buf->latexParagraphs(os, par, 0, texrow);
1334 return texrow.rows();
1338 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1340 Paragraph * p = par;
1341 unsigned int lines = 0;
1344 string const tmp = buf->asciiParagraph(p, linelen);
1345 lines += countChar(tmp, '\n');
1353 int InsetText::docBook(Buffer const * buf, ostream & os) const
1355 Paragraph * p = par;
1356 unsigned int lines = 0;
1361 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1369 void InsetText::validate(LaTeXFeatures & features) const
1371 Paragraph * p = par;
1373 p->validate(features);
1379 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1381 if (textclasslist.Style(buf->params.textclass,
1382 p->getLayout()).labeltype != LABEL_MANUAL)
1385 return p->beginningOfMainBody();
1389 void InsetText::getCursorPos(BufferView * bv,
1390 int & x, int & y) const
1392 if (the_locking_inset) {
1393 the_locking_inset->getCursorPos(bv, x, y);
1401 unsigned int InsetText::insetInInsetY()
1403 if (!the_locking_inset)
1406 return (inset_y + the_locking_inset->insetInInsetY());
1410 void InsetText::toggleInsetCursor(BufferView * bv)
1412 if (the_locking_inset) {
1413 the_locking_inset->toggleInsetCursor(bv);
1417 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1419 int const asc = lyxfont::maxAscent(font);
1420 int const desc = lyxfont::maxDescent(font);
1422 if (isCursorVisible())
1423 bv->hideLockedInsetCursor();
1425 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1426 toggleCursorVisible();
1430 void InsetText::showInsetCursor(BufferView * bv, bool show)
1432 if (the_locking_inset) {
1433 the_locking_inset->showInsetCursor(bv, show);
1436 if (!isCursorVisible()) {
1437 LyXFont const font =
1438 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1440 int const asc = lyxfont::maxAscent(font);
1441 int const desc = lyxfont::maxDescent(font);
1443 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1445 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1446 setCursorVisible(true);
1451 void InsetText::hideInsetCursor(BufferView * bv)
1453 if (isCursorVisible()) {
1454 bv->hideLockedInsetCursor();
1455 setCursorVisible(false);
1457 if (the_locking_inset)
1458 the_locking_inset->hideInsetCursor(bv);
1462 void InsetText::fitInsetCursor(BufferView * bv) const
1464 if (the_locking_inset) {
1465 the_locking_inset->fitInsetCursor(bv);
1468 LyXFont const font =
1469 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1471 int const asc = lyxfont::maxAscent(font);
1472 int const desc = lyxfont::maxDescent(font);
1474 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1478 UpdatableInset::RESULT
1479 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1481 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1482 return moveLeftIntern(bv, false, activate_inset, selecting);
1484 return moveRightIntern(bv, false, activate_inset, selecting);
1488 UpdatableInset::RESULT
1489 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1491 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1492 return moveRightIntern(bv, true, activate_inset, selecting);
1494 return moveLeftIntern(bv, true, activate_inset, selecting);
1498 UpdatableInset::RESULT
1499 InsetText::moveRightIntern(BufferView * bv, bool behind,
1500 bool activate_inset, bool selecting)
1502 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1504 if (activate_inset && checkAndActivateInset(bv, behind))
1506 getLyXText(bv)->cursorRight(bv);
1508 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1509 return DISPATCHED_NOUPDATE;
1513 UpdatableInset::RESULT
1514 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1515 bool activate_inset, bool selecting)
1517 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1519 getLyXText(bv)->cursorLeft(bv);
1521 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1522 if (activate_inset && checkAndActivateInset(bv, behind))
1524 return DISPATCHED_NOUPDATE;
1528 UpdatableInset::RESULT
1529 InsetText::moveUp(BufferView * bv)
1531 if (!crow(bv)->previous())
1533 getLyXText(bv)->cursorUp(bv);
1534 return DISPATCHED_NOUPDATE;
1538 UpdatableInset::RESULT
1539 InsetText::moveDown(BufferView * bv)
1541 if (!crow(bv)->next())
1543 getLyXText(bv)->cursorDown(bv);
1544 return DISPATCHED_NOUPDATE;
1548 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1550 if (the_locking_inset) {
1551 if (the_locking_inset->insetAllowed(inset))
1552 return the_locking_inset->insertInset(bv, inset);
1555 inset->setOwner(this);
1556 hideInsetCursor(bv);
1560 lt = getLyXText(bv);
1563 lt->insertInset(bv, inset);
1565 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1566 (cpar(bv)->getInset(cpos(bv)) != inset))
1570 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1571 showInsetCursor(bv);
1578 bool InsetText::insetAllowed(Inset::Code code) const
1580 if (the_locking_inset)
1581 return the_locking_inset->insetAllowed(code);
1586 UpdatableInset * InsetText::getLockingInset() const
1588 return the_locking_inset ? the_locking_inset->getLockingInset() :
1589 const_cast<InsetText *>(this);
1593 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1597 if (the_locking_inset)
1598 return the_locking_inset->getFirstLockingInsetOfType(c);
1603 bool InsetText::showInsetDialog(BufferView * bv) const
1605 if (the_locking_inset)
1606 return the_locking_inset->showInsetDialog(bv);
1611 std::vector<string> const InsetText::getLabelList() const
1613 std::vector<string> label_list;
1615 Paragraph * tpar = par;
1617 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1618 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1619 for (; beg != end; ++beg) {
1620 std::vector<string> const l = (*beg)->getLabelList();
1621 label_list.insert(label_list.end(), l.begin(), l.end());
1623 tpar = tpar->next();
1629 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1632 if (the_locking_inset) {
1633 the_locking_inset->setFont(bv, font, toggleall, selectall);
1636 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1637 getLyXText(bv)->setFont(bv, font, toggleall);
1642 lt = getLyXText(bv);
1645 if (lt->selection.set()) {
1646 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1650 lt->toggleFree(bv, font, toggleall);
1652 lt->clearSelection();
1654 if (selectall || lt->selection.set())
1655 updateLocal(bv, FULL, true);
1657 updateLocal(bv, CURSOR_PAR, true);
1663 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1665 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1669 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1670 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1672 LyXFont const font =
1673 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1675 x = inset->width(bv, font);
1676 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1679 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1681 //inset_x = cx(bv) - top_x + drawTextXOffset;
1682 //inset_y = cy(bv) + drawTextYOffset;
1683 inset->edit(bv, x, y, 0);
1684 if (!the_locking_inset)
1686 updateLocal(bv, CURSOR, false);
1693 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1696 x -= drawTextXOffset;
1698 int dummyy = y + insetAscent;
1699 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1706 inset_x = cx(bv) - top_x + drawTextXOffset;
1707 inset_y = cy(bv) + drawTextYOffset;
1708 inset->edit(bv, x - inset_x, y - inset_y, button);
1709 if (!the_locking_inset)
1711 updateLocal(bv, CURSOR, false);
1718 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1721 int w = UpdatableInset::getMaxWidth(bv, inset);
1726 w = w - top_x + owner()->x();
1729 w -= (2 * TEXT_TO_INSET_OFFSET);
1732 return UpdatableInset::getMaxWidth(bv, inset);
1737 void InsetText::setParagraphData(Paragraph * p)
1739 // we have to unlock any locked inset otherwise we're in troubles
1740 the_locking_inset = 0;
1742 Paragraph * tmp = par->next();
1747 par = new Paragraph(*p);
1748 par->setInsetOwner(this);
1749 Paragraph * np = par;
1752 np->next(new Paragraph(*p));
1753 np->next()->previous(np);
1755 np->setInsetOwner(this);
1761 void InsetText::setText(string const & data)
1764 LyXFont font(LyXFont::ALL_SANE);
1765 for (unsigned int i=0; i < data.length(); ++i)
1766 par->insertChar(i, data[i], font);
1770 void InsetText::setAutoBreakRows(bool flag)
1772 if (flag != autoBreakRows) {
1773 autoBreakRows = flag;
1781 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1783 if (how != drawFrame_) {
1786 updateLocal(bv, DRAW_FRAME, false);
1791 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1793 if (frame_color != col) {
1796 updateLocal(bv, DRAW_FRAME, false);
1801 int InsetText::cx(BufferView * bv) const
1805 lt = getLyXText(bv);
1808 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1809 if (the_locking_inset) {
1810 LyXFont font = lt->getFont(bv->buffer(),
1813 if (font.isVisibleRightToLeft())
1814 x -= the_locking_inset->width(bv, font);
1822 int InsetText::cy(BufferView * bv) const
1825 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1829 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1831 return getLyXText(bv)->cursor.pos();
1835 Paragraph * InsetText::cpar(BufferView * bv) const
1837 return getLyXText(bv)->cursor.par();
1841 bool InsetText::cboundary(BufferView * bv) const
1843 return getLyXText(bv)->cursor.boundary();
1847 Row * InsetText::crow(BufferView * bv) const
1849 return getLyXText(bv)->cursor.row();
1853 LyXText * InsetText::getLyXText(BufferView const * lbv,
1854 bool const recursive) const
1856 if (!recursive && (cached_bview == lbv))
1857 return cached_text.get();
1859 // Super UGLY! (Lgb)
1860 BufferView * bv = const_cast<BufferView *>(lbv);
1863 Cache::iterator it = cache.find(bv);
1865 if (it != cache.end()) {
1866 if (lt || !it->second.remove) {
1867 lyx::Assert(it->second.text.get());
1868 cached_text = it->second.text;
1869 if (recursive && the_locking_inset) {
1870 return the_locking_inset->getLyXText(bv, true);
1872 return cached_text.get();
1873 } else if (it->second.remove) {
1875 saveLyXTextState(it->second.text.get());
1882 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1883 cached_text->init(bv);
1884 restoreLyXTextState(bv, cached_text.get());
1886 cache.insert(make_pair(bv, cached_text));
1888 if (the_locking_inset && recursive) {
1889 return the_locking_inset->getLyXText(bv);
1891 return cached_text.get();
1895 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1899 Cache::iterator it = cache.find(bv);
1901 if (it == cache.end()) {
1905 lyx::Assert(it->second.text.get());
1907 it->second.remove = true;
1909 /// then remove all LyXText in text-insets
1910 Paragraph * p = par;
1911 for (; p; p = p->next()) {
1912 p->deleteInsetsLyXText(bv);
1918 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1920 // lyxerr << "InsetText::resizeLyXText\n";
1921 if (!par->next() && !par->size()) // no data, resize not neccessary!
1923 // one endless line, resize normally not necessary
1924 if (!force && getMaxWidth(bv, this) < 0)
1927 Cache::iterator it = cache.find(bv);
1928 if (it == cache.end()) {
1931 lyx::Assert(it->second.text.get());
1933 LyXText * t = it->second.text.get();
1934 saveLyXTextState(t);
1935 for (Paragraph * p = par; p; p = p->next()) {
1936 p->resizeInsetsLyXText(bv);
1939 restoreLyXTextState(bv, t);
1940 if (the_locking_inset) {
1941 inset_x = cx(bv) - top_x + drawTextXOffset;
1942 inset_y = cy(bv) + drawTextYOffset;
1946 t->first = bv->screen()->topCursorVisible(t);
1949 updateLocal(bv, FULL, false);
1950 // this will scroll the screen such that the cursor becomes visible
1951 bv->updateScrollbar();
1953 need_update |= FULL;
1958 void InsetText::reinitLyXText() const
1960 // lyxerr << "InsetText::reinitLyXText\n";
1961 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1962 lyx::Assert(it->second.text.get());
1964 LyXText * t = it->second.text.get();
1965 BufferView * bv = it->first;
1967 saveLyXTextState(t);
1968 for (Paragraph * p = par; p; p = p->next()) {
1969 p->resizeInsetsLyXText(bv);
1972 restoreLyXTextState(bv, t);
1973 if (the_locking_inset) {
1974 inset_x = cx(bv) - top_x + drawTextXOffset;
1975 inset_y = cy(bv) + drawTextYOffset;
1978 t->first = bv->screen()->topCursorVisible(t);
1981 updateLocal(bv, FULL, false);
1982 // this will scroll the screen such that the cursor becomes visible
1983 bv->updateScrollbar();
1991 void InsetText::removeNewlines()
1993 for (Paragraph * p = par; p; p = p->next()) {
1994 for (int i = 0; i < p->size(); ++i) {
1995 if (p->getChar(i) == Paragraph::META_NEWLINE)
2002 bool InsetText::nodraw() const
2004 if (the_locking_inset)
2005 return the_locking_inset->nodraw();
2006 return UpdatableInset::nodraw();
2010 int InsetText::scroll(bool recursive) const
2012 int sx = UpdatableInset::scroll(false);
2014 if (recursive && the_locking_inset)
2015 sx += the_locking_inset->scroll(recursive);
2021 bool InsetText::doClearArea() const
2023 return !locked || (need_update & (FULL|INIT));
2027 void InsetText::selectAll(BufferView * bv)
2029 getLyXText(bv)->cursorTop(bv);
2030 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2031 getLyXText(bv)->cursorBottom(bv);
2032 getLyXText(bv)->setSelection(bv);
2036 void InsetText::clearSelection(BufferView * bv)
2038 getLyXText(bv)->clearSelection();
2042 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2045 int h = insetAscent + insetDescent;
2046 int ty = baseline - insetAscent;
2052 if ((ty + h) > pain.paperHeight())
2053 h = pain.paperHeight();
2054 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2055 w = pain.paperWidth();
2056 // w -= TEXT_TO_INSET_OFFSET;
2057 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2060 frame_is_visible = false;
2064 Paragraph * InsetText::getParFromID(int id) const
2067 Paragraph * result = par;
2068 Paragraph * ires = 0;
2069 while (result && result->id() != id) {
2070 if ((ires = result->getParFromID(id)))
2072 result = result->next();
2076 Paragraph * tmp = par;
2078 int tmp_id = tmp->id();
2079 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2080 if (tmp->id() == id) {
2083 Paragraph * tmp2 = tmp->getParFromID(id);
2094 Paragraph * InsetText::firstParagraph() const
2097 if (the_locking_inset)
2098 if ((result = the_locking_inset->firstParagraph()))
2104 LyXCursor const & InsetText::cursor(BufferView * bv) const
2106 if (the_locking_inset)
2107 return the_locking_inset->cursor(bv);
2108 return getLyXText(bv)->cursor;
2112 Paragraph * InsetText::paragraph() const
2118 void InsetText::paragraph(Paragraph * p)
2122 // we now have to update/redraw all instances
2123 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2128 // redraw myself when asked for
2133 Inset * InsetText::getInsetFromID(int id_arg) const
2136 return const_cast<InsetText *>(this);
2138 Paragraph * lp = par;
2141 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2142 en = lp->inset_iterator_end();
2145 if ((*it)->id() == id_arg)
2147 Inset * in = (*it)->getInsetFromID(id_arg);
2157 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2163 lt = getLyXText(bv);
2166 if (the_locking_inset) {
2167 str = the_locking_inset->selectNextWord(bv, value);
2174 #warning Dekel please have a look on this one RTL? (Jug)
2175 // we have to go on checking so move cusor to the right
2176 lt->cursor.pos(lt->cursor.pos() + 1);
2178 str = lt->selectNextWord(bv, value);
2180 bv->unlockInset(const_cast<InsetText *>(this));
2189 void InsetText::selectSelectedWord(BufferView * bv)
2191 if (the_locking_inset) {
2192 the_locking_inset->selectSelectedWord(bv);
2195 getLyXText(bv)->selectSelectedWord(bv);
2196 updateLocal(bv, SELECTION, false);
2200 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2202 if (the_locking_inset) {
2203 the_locking_inset->toggleSelection(bv, kill_selection);
2207 lt = getLyXText(bv);
2211 int x = top_x + TEXT_TO_INSET_OFFSET;
2214 Row * row = lt->getRowNearY(y);
2215 int y_offset = top_baseline - row->ascent_of_text();
2217 while ((row != 0) && ((y+row->height()) <= 0)) {
2224 if (need_update & SELECTION)
2226 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2232 bool InsetText::searchForward(BufferView * bv, string const & str,
2233 bool const & cs, bool const & mw)
2235 if (the_locking_inset) {
2236 if (the_locking_inset->searchForward(bv, str, cs, mw))
2240 lt = getLyXText(bv);
2243 Paragraph * lpar = lt->cursor.par();
2244 Paragraph::size_type pos = lt->cursor.pos();
2245 if (pos < lpar->size() - 1)
2249 lpar = lpar->next();
2256 lt->setCursor(bv, lpar, pos);
2260 if (LyXFind(bv, str, true, true, cs , mw)) {
2263 // we have to unlock ourself in this function by default!
2264 bv->unlockInset(const_cast<InsetText *>(this));
2268 bool InsetText::searchBackward(BufferView * bv, string const & str,
2269 bool const & cs, bool const & mw)
2271 if (the_locking_inset)
2272 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2274 if (LyXFind(bv, str, false, true, cs, mw)) {
2277 // we have to unlock ourself in this function by default!
2278 bv->unlockInset(const_cast<InsetText *>(this));