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()
120 : UpdatableInset(), lt(0), in_update(false)
127 InsetText::InsetText(InsetText const & in, bool same_id)
128 : UpdatableInset(in, same_id), lt(0), in_update(false)
135 InsetText & InsetText::operator=(InsetText const & it)
142 void InsetText::init(InsetText const * ins, bool same_id)
145 setParagraphData(ins->par);
146 autoBreakRows = ins->autoBreakRows;
147 drawFrame_ = ins->drawFrame_;
148 frame_color = ins->frame_color;
154 p->setInsetOwner(this);
157 the_locking_inset = 0;
159 frame_color = LColor::insetframe;
160 autoBreakRows = false;
169 no_selection = false;
176 last_drawn_width = -1;
177 frame_is_visible = false;
183 InsetText::~InsetText()
190 Paragraph * tmp = par->next();
197 void InsetText::clear()
200 Paragraph * tmp = par->next();
209 Inset * InsetText::clone(Buffer const &, bool same_id) const
211 return new InsetText(*this, same_id);
215 void InsetText::write(Buffer const * buf, ostream & os) const
218 writeParagraphData(buf, os);
222 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
224 par->writeFile(buf, os, buf->params, 0);
228 void InsetText::read(Buffer const * buf, LyXLex & lex)
232 Paragraph * return_par = 0;
233 Paragraph::depth_type depth = 0;
234 LyXFont font(LyXFont::ALL_INHERIT);
240 token = lex.getString();
243 if (token == "\\end_inset") {
244 #ifndef NO_COMPABILITY
245 const_cast<Buffer*>(buf)->insertErtContents(par, pos, font, false);
250 if (const_cast<Buffer*>(buf)->
251 parseSingleLyXformat2Token(lex, par, return_par,
252 token, pos, depth, font)) {
253 // the_end read this should NEVER happen
254 lex.printError("\\the_end read in inset! Error in document!");
262 return_par->setInsetOwner(this);
263 return_par = return_par->next();
266 if (token != "\\end_inset") {
267 lex.printError("Missing \\end_inset at this point. "
274 int InsetText::ascent(BufferView * bv, LyXFont const &) const
277 Row * row = getLyXText(bv)->getRowNearY(y_temp);
278 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
283 int InsetText::descent(BufferView * bv, LyXFont const &) const
291 Row * row = lt->getRowNearY(y_temp);
292 insetDescent = lt->height - row->ascent_of_text() +
293 TEXT_TO_INSET_OFFSET;
300 int InsetText::width(BufferView * bv, LyXFont const &) const
302 insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
303 (2 * TEXT_TO_INSET_OFFSET);
304 insetWidth = max(insetWidth, 10);
309 int InsetText::textWidth(BufferView * bv, bool fordraw) const
312 if (!autoBreakRows) {
315 w = getMaxWidth(bv, this);
318 return max(w - (2 * TEXT_TO_INSET_OFFSET),
319 (int)getLyXText(bv)->width);
323 return w - (2 * TEXT_TO_INSET_OFFSET);
327 void InsetText::draw(BufferView * bv, LyXFont const & f,
328 int baseline, float & x, bool cleared) const
333 Painter & pain = bv->painter();
335 // this is the first thing we have to ask because if the x pos
336 // changed we have to do a complete rebreak of the text as we
337 // may have few space to draw in. Well we should check on this too
339 if (top_x != int(x)) {
341 int nw = getMaxWidth(bv, this);
342 if (nw > 0 && old_max_width != nw) {
345 bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
353 // repaint the background if needed
354 if (cleared && backgroundColor() != LColor::background) {
356 clearInset(pain, baseline, cleared);
360 // no draw is necessary !!!
361 if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
364 top_baseline = baseline;
366 if (need_update & CLEAR_FRAME)
367 clearFrame(pain, cleared);
374 x += static_cast<float>(scroll());
376 // if top_x differs we did it already
377 if (!cleared && (top_x == int(x)) &&
378 ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
379 (last_drawn_width!=insetWidth))) {
380 clearInset(pain, baseline, cleared);
386 frame_is_visible = false;
388 if (!cleared && (need_update == NONE)) {
390 drawFrame(pain, cleared);
394 top_baseline = baseline;
395 top_y = baseline - ascent(bv, f);
396 last_width = width(bv, f);
397 last_height = ascent(bv, f) + descent(bv, f);
399 if (cleared || (last_drawn_width != insetWidth)) {
401 clearInset(pain, baseline, cleared);
403 last_drawn_width = insetWidth;
406 if (the_locking_inset && (cpar(bv) == inset_par)
407 && (cpos(bv) == inset_pos)) {
408 inset_x = cx(bv) - top_x + drawTextXOffset;
409 inset_y = cy(bv) + drawTextYOffset;
411 if (!cleared && (need_update == CURSOR)
412 && !getLyXText(bv)->selection.set())
414 drawFrame(pain, cleared);
415 x += last_width; // was width(bv, f);
424 x += TEXT_TO_INSET_OFFSET;
427 Row * row = lt->getRowNearY(y);
428 int y_offset = baseline - row->ascent_of_text();
429 int ph = pain.paperHeight();
432 while ((row != 0) && ((y+row->height()) <= 0)) {
434 first += row->height();
440 if (cleared || (need_update&(INIT|FULL))) {
443 while ((row != 0) && (yf < ph)) {
444 lt->getVisibleRow(bv, y+y_offset, int(x), row,
450 } else if (!locked) {
451 if (need_update & CURSOR) {
452 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
453 lt->clearSelection();
454 lt->selection.cursor = lt->cursor;
456 bv->screen()->update(lt, bv, y_offset, int(x));
459 if (need_update & SELECTION)
460 bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
461 else if (need_update & CURSOR) {
462 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
463 lt->clearSelection();
464 lt->selection.cursor = lt->cursor;
466 bv->screen()->update(lt, bv, y_offset, int(x));
471 lt->status(bv, LyXText::UNCHANGED);
472 if ((need_update != CURSOR_PAR) &&
473 ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
474 drawFrame(pain, cleared);
475 else if (need_update & CLEAR_FRAME)
476 clearFrame(pain, cleared);
477 x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
478 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
480 } else if (need_update != INIT)
487 void InsetText::drawFrame(Painter & pain, bool cleared) const
489 static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
490 if (!frame_is_visible || cleared) {
491 frame_x = top_x + ttoD2;
492 frame_y = top_baseline - insetAscent + ttoD2;
493 frame_w = last_width - TEXT_TO_INSET_OFFSET;
494 frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
495 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
497 frame_is_visible = true;
502 void InsetText::clearFrame(Painter & pain, bool cleared) const
504 if (frame_is_visible) {
506 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
509 frame_is_visible = false;
514 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
517 if (reinit && owner()) {
519 owner()->update(bv, font, true);
524 if (reinit || need_update == INIT) {
528 owner()->update(bv, font, true);
532 if (the_locking_inset) {
533 inset_x = cx(bv) - top_x + drawTextXOffset;
534 inset_y = cy(bv) + drawTextYOffset;
535 the_locking_inset->update(bv, font, reinit);
543 int oldw = insetWidth;
544 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
545 if (oldw != insetWidth) {
553 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
556 lt->updateInset(bv, the_locking_inset);
558 if (lt->status() == LyXText::NEED_MORE_REFRESH)
566 void InsetText::setUpdateStatus(BufferView * bv, int what) const
574 // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
575 // if we don't break row so that we only have one row to update!
576 if ((lt->status() == LyXText::NEED_MORE_REFRESH) ||
578 (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
581 } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
582 need_update |= CURSOR_PAR;
585 // this to not draw a selection when we redraw all of it!
586 if (need_update & CURSOR && !(need_update & SELECTION)) {
587 if (lt->selection.set())
589 lt->clearSelection();
596 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
604 setUpdateStatus(bv, what);
605 if (((need_update != CURSOR) && (need_update != NONE)) ||
606 (lt->status() != LyXText::UNCHANGED) || lt->selection.set())
608 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
610 if (need_update == CURSOR)
612 bv->owner()->showState();
613 if (old_par != cpar(bv)) {
614 bv->owner()->setLayout(cpar(bv)->getLayout());
622 string const InsetText::editMessage() const
624 return _("Opened Text Inset");
628 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
630 UpdatableInset::edit(bv, x, y, button);
632 if (!bv->lockInset(this)) {
633 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
637 the_locking_inset = 0;
638 inset_pos = inset_x = inset_y = 0;
639 inset_boundary = false;
642 int tmp_y = (y < 0) ? 0 : y;
649 if (!checkAndActivateInset(bv, x, tmp_y, button))
650 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
652 lt->clearSelection();
655 updateLocal(bv, CURSOR, false);
657 // If the inset is empty set the language of the current font to the
658 // language to the surronding text (if different).
659 if (par->size() == 0 && !par->next() &&
660 bv->getParentLanguage(this) != lt->current_font.language()) {
661 LyXFont font(LyXFont::ALL_IGNORE);
662 font.setLanguage(bv->getParentLanguage(this));
663 setFont(bv, font, false);
670 void InsetText::edit(BufferView * bv, bool front)
672 UpdatableInset::edit(bv, front);
674 if (!bv->lockInset(this)) {
675 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
679 the_locking_inset = 0;
680 inset_pos = inset_x = inset_y = 0;
681 inset_boundary = false;
690 lt->setCursor(bv, par, 0);
695 int const pos = (p->size() ? p->size()-1 : p->size());
696 lt->setCursor(bv, p, pos);
698 lt->clearSelection();
701 updateLocal(bv, CURSOR, false);
703 // If the inset is empty set the language of the current font to the
704 // language to the surronding text (if different).
705 if (par->size() == 0 && !par->next() &&
706 bv->getParentLanguage(this) != lt->current_font.language()) {
707 LyXFont font(LyXFont::ALL_IGNORE);
708 font.setLanguage(bv->getParentLanguage(this));
709 setFont(bv, font, false);
716 void InsetText::insetUnlock(BufferView * bv)
718 if (the_locking_inset) {
719 the_locking_inset->insetUnlock(bv);
720 the_locking_inset = 0;
723 no_selection = false;
726 if (drawFrame_ == LOCKED)
727 code = CURSOR|CLEAR_FRAME;
735 if (lt->selection.set()) {
736 lt->clearSelection();
738 } else if (owner()) {
739 bv->owner()->setLayout(owner()->getLyXText(bv)
740 ->cursor.par()->getLayout());
742 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
743 // hack for deleteEmptyParMech
744 lt->setCursor(bv, par, 0);
745 updateLocal(bv, code, false);
751 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
753 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
757 if (inset == cpar(bv)->getInset(cpos(bv))) {
758 lyxerr[Debug::INSETS] << "OK" << endl;
759 the_locking_inset = inset;
760 inset_x = cx(bv) - top_x + drawTextXOffset;
761 inset_y = cy(bv) + drawTextYOffset;
762 inset_pos = cpos(bv);
763 inset_par = cpar(bv);
764 inset_boundary = cboundary(bv);
765 updateLocal(bv, CURSOR, false);
767 } else if (the_locking_inset && (the_locking_inset == inset)) {
768 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
769 lyxerr[Debug::INSETS] << "OK" << endl;
770 inset_x = cx(bv) - top_x + drawTextXOffset;
771 inset_y = cy(bv) + drawTextYOffset;
773 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
775 } else if (the_locking_inset) {
776 lyxerr[Debug::INSETS] << "MAYBE" << endl;
777 return the_locking_inset->lockInsetInInset(bv, inset);
779 lyxerr[Debug::INSETS] << "NOT OK" << endl;
784 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
787 if (!the_locking_inset)
789 if (the_locking_inset == inset) {
790 the_locking_inset->insetUnlock(bv);
791 getLyXText(bv)->updateInset(bv, inset);
792 the_locking_inset = 0;
794 moveRight(bv, false);
795 old_par = 0; // force layout setting
799 updateLocal(bv, CURSOR, false);
802 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
806 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
808 if (!the_locking_inset)
810 if (the_locking_inset != inset) {
811 getLyXText(bv)->updateInset(bv, the_locking_inset);
812 setUpdateStatus(bv, CURSOR_PAR);
813 return the_locking_inset->updateInsetInInset(bv, inset);
815 if (getLyXText(bv)->updateInset(bv, inset))
816 updateLocal(bv, CURSOR_PAR, false);
817 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
818 inset_x = cx(bv) - top_x + drawTextXOffset;
819 inset_y = cy(bv) + drawTextYOffset;
825 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
829 int tmp_x = x - drawTextXOffset;
830 int tmp_y = y + insetAscent - getLyXText(bv)->first;
831 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
834 if (the_locking_inset) {
835 if (the_locking_inset == inset) {
836 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
837 no_selection = false;
840 // otherwise unlock the_locking_inset and lock the new inset
841 the_locking_inset->insetUnlock(bv);
842 inset_x = cx(bv) - top_x + drawTextXOffset;
843 inset_y = cy(bv) + drawTextYOffset;
844 the_locking_inset = static_cast<UpdatableInset*>(inset);
845 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
846 inset->edit(bv, x - inset_x, y - inset_y, button);
847 if (the_locking_inset)
848 updateLocal(bv, CURSOR, false);
849 no_selection = false;
852 // otherwise only unlock the_locking_inset
853 the_locking_inset->insetUnlock(bv);
854 the_locking_inset = 0;
856 if (bv->theLockingInset()) {
857 if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
858 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
859 inset_x = cx(bv) - top_x + drawTextXOffset;
860 inset_y = cy(bv) + drawTextYOffset;
861 inset_pos = cpos(bv);
862 inset_par = cpar(bv);
863 inset_boundary = cboundary(bv);
864 the_locking_inset = uinset;
865 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
867 uinset->edit(bv, x - inset_x, y - inset_y, 0);
868 if (the_locking_inset)
869 updateLocal(bv, CURSOR, false);
870 no_selection = false;
874 if (!inset) { // && (button == 2)) {
875 bool paste_internally = false;
876 if ((button == 2) && getLyXText(bv)->selection.set()) {
877 localDispatch(bv, LFUN_COPY, "");
878 paste_internally = true;
885 lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent);
886 if (lt->selection.set()) {
887 lt->clearSelection();
888 updateLocal(bv, FULL, false);
890 lt->clearSelection();
892 bv->owner()->setLayout(cpar(bv)->getLayout());
894 // Insert primary selection with middle mouse
895 // if there is a local selection in the current buffer,
898 if (paste_internally)
899 localDispatch(bv, LFUN_PASTE, "");
901 localDispatch(bv, LFUN_PASTESELECTION,
908 no_selection = false;
912 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
914 UpdatableInset * inset = 0;
916 if (the_locking_inset) {
917 the_locking_inset->insetButtonRelease(bv,
918 x - inset_x, y - inset_y,
921 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
922 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
923 if (inset->editable() == Inset::HIGHLY_EDITABLE) {
924 inset->insetButtonRelease(bv,
926 y - inset_y, button);
928 inset_x = cx(bv) - top_x + drawTextXOffset;
929 inset_y = cy(bv) + drawTextYOffset;
930 inset->insetButtonRelease(bv,
932 y - inset_y, button);
934 x - inset_x, y - inset_y, button);
936 updateLocal(bv, CURSOR_PAR, false);
939 no_selection = false;
943 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
947 if (the_locking_inset) {
948 the_locking_inset->insetMotionNotify(bv, x - inset_x,
952 LyXText * t = getLyXText(bv);
954 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
956 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
957 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
958 updateLocal(bv, SELECTION, false);
963 void InsetText::insetKeyPress(XKeyEvent * xke)
965 if (the_locking_inset) {
966 the_locking_inset->insetKeyPress(xke);
972 UpdatableInset::RESULT
973 InsetText::localDispatch(BufferView * bv,
974 kb_action action, string const & arg)
976 no_selection = false;
977 UpdatableInset::RESULT
978 result= UpdatableInset::localDispatch(bv, action, arg);
979 if (result != UNDISPATCHED) {
984 if ((action < 0) && arg.empty())
987 if (the_locking_inset) {
988 result = the_locking_inset->localDispatch(bv, action, arg);
989 if (result == DISPATCHED_NOUPDATE)
991 else if (result == DISPATCHED) {
992 updateLocal(bv, CURSOR_PAR, false);
994 } else if (result == FINISHED) {
995 bool dispatched = false;
997 case LFUN_UNKNOWN_ACTION:
998 case LFUN_BREAKPARAGRAPH:
1000 moveRightIntern(bv, false, false);
1003 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1004 moveRightIntern(bv, false, false);
1008 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1009 moveRightIntern(bv, false, false);
1015 the_locking_inset = 0;
1020 hideInsetCursor(bv);
1023 lt = getLyXText(bv);
1028 case LFUN_SELFINSERT:
1029 if (bv->buffer()->isReadonly()) {
1030 // setErrorMessage(N_("Document is read only"));
1034 /* Automatically delete the currently selected
1035 * text and replace it with what is being
1036 * typed in now. Depends on lyxrc settings
1037 * "auto_region_delete", which defaults to
1040 setUndo(bv, Undo::INSERT,
1041 lt->cursor.par(), lt->cursor.par()->next());
1043 if (lyxrc.auto_region_delete) {
1044 if (lt->selection.set()) {
1045 lt->cutSelection(bv, false);
1048 lt->clearSelection();
1049 for (string::size_type i = 0; i < arg.length(); ++i) {
1050 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1053 lt->selection.cursor = lt->cursor;
1054 updateLocal(bv, CURSOR_PAR, true);
1055 result = DISPATCHED_NOUPDATE;
1057 // --- Cursor Movements -----------------------------------
1060 moveRight(bv, false, true);
1061 lt->setSelection(bv);
1062 updateLocal(bv, SELECTION, false);
1065 result = moveRight(bv);
1067 updateLocal(bv, CURSOR, false);
1071 moveLeft(bv, false, true);
1072 lt->setSelection(bv);
1073 updateLocal(bv, SELECTION, false);
1077 result = moveLeft(bv);
1078 updateLocal(bv, CURSOR, false);
1083 lt->setSelection(bv);
1084 updateLocal(bv, SELECTION, false);
1088 result = moveDown(bv);
1089 updateLocal(bv, CURSOR, false);
1094 lt->setSelection(bv);
1095 updateLocal(bv, SELECTION, false);
1099 result = moveUp(bv);
1100 updateLocal(bv, CURSOR, false);
1105 updateLocal(bv, CURSOR, false);
1109 updateLocal(bv, CURSOR, false);
1111 case LFUN_BACKSPACE: {
1112 setUndo(bv, Undo::DELETE,
1113 lt->cursor.par(), lt->cursor.par()->next());
1114 if (lt->selection.set())
1115 lt->cutSelection(bv);
1118 updateLocal(bv, CURSOR_PAR, true);
1123 setUndo(bv, Undo::DELETE,
1124 lt->cursor.par(), lt->cursor.par()->next());
1125 if (lt->selection.set()) {
1126 lt->cutSelection(bv);
1130 updateLocal(bv, CURSOR_PAR, true);
1135 setUndo(bv, Undo::DELETE,
1136 lt->cursor.par(), lt->cursor.par()->next());
1137 lt->cutSelection(bv);
1138 updateLocal(bv, CURSOR_PAR, true);
1144 lt->copySelection(bv);
1145 updateLocal(bv, CURSOR_PAR, false);
1147 case LFUN_PASTESELECTION:
1149 string const clip(bv->getClipboard());
1153 if (arg == "paragraph") {
1154 lt->insertStringAsParagraphs(bv, clip);
1156 lt->insertStringAsLines(bv, clip);
1158 updateLocal(bv, CURSOR_PAR, true);
1162 if (!autoBreakRows) {
1164 if (CutAndPaste::nrOfParagraphs() > 1) {
1165 WriteAlert(_("Impossible operation"),
1166 _("Cannot include more than one paragraph!"),
1171 setUndo(bv, Undo::INSERT,
1172 lt->cursor.par(), lt->cursor.par()->next());
1173 lt->pasteSelection(bv);
1174 updateLocal(bv, CURSOR_PAR, true);
1178 case LFUN_BREAKPARAGRAPH:
1179 if (!autoBreakRows) {
1180 result = DISPATCHED;
1183 lt->breakParagraph(bv, 0);
1184 updateLocal(bv, FULL, true);
1186 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1187 if (!autoBreakRows) {
1188 result = DISPATCHED;
1191 lt->breakParagraph(bv, 1);
1192 updateLocal(bv, FULL, true);
1195 case LFUN_BREAKLINE: {
1196 if (!autoBreakRows) {
1197 result = DISPATCHED;
1200 setUndo(bv, Undo::INSERT,
1201 lt->cursor.par(), lt->cursor.par()->next());
1202 lt->insertChar(bv, Paragraph::META_NEWLINE);
1203 updateLocal(bv, CURSOR_PAR, true);
1208 // do not set layouts on non breakable textinsets
1209 if (autoBreakRows) {
1210 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1212 // Derive layout number from given argument (string)
1213 // and current buffer's textclass (number). */
1214 LyXTextClassList::ClassList::size_type tclass =
1215 bv->buffer()->params.textclass;
1216 std::pair <bool, LyXTextClass::size_type> layout =
1217 textclasslist.NumberOfLayout(tclass, arg);
1219 // If the entry is obsolete, use the new one instead.
1221 string obs = textclasslist.Style(tclass,layout.second).
1224 layout = textclasslist.NumberOfLayout(tclass, obs);
1227 // see if we found the layout number:
1228 if (!layout.first) {
1229 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1230 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1234 if (cur_layout != layout.second) {
1235 cur_layout = layout.second;
1236 lt->setLayout(bv, layout.second);
1237 bv->owner()->setLayout(cpar(bv)->getLayout());
1238 updateLocal(bv, CURSOR_PAR, true);
1241 // reset the layout box
1242 bv->owner()->setLayout(cpar(bv)->getLayout());
1245 case LFUN_PARAGRAPH_SPACING:
1246 // This one is absolutely not working. When fiddling with this
1247 // it also seems to me that the paragraphs inside the insettext
1248 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1250 Paragraph * par = lt->cursor.par();
1251 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1252 float cur_value = 1.0;
1253 if (cur_spacing == Spacing::Other) {
1254 cur_value = par->params().spacing().getValue();
1257 istringstream istr(arg.c_str());
1260 Spacing::Space new_spacing = cur_spacing;
1261 float new_value = cur_value;
1263 lyxerr << "Missing argument to `paragraph-spacing'"
1265 } else if (tmp == "single") {
1266 new_spacing = Spacing::Single;
1267 } else if (tmp == "onehalf") {
1268 new_spacing = Spacing::Onehalf;
1269 } else if (tmp == "double") {
1270 new_spacing = Spacing::Double;
1271 } else if (tmp == "other") {
1272 new_spacing = Spacing::Other;
1275 lyxerr << "new_value = " << tmpval << endl;
1278 } else if (tmp == "default") {
1279 new_spacing = Spacing::Default;
1281 lyxerr << _("Unknown spacing argument: ")
1284 if (cur_spacing != new_spacing || cur_value != new_value) {
1285 par->params().spacing(Spacing(new_spacing, new_value));
1286 updateLocal(bv, CURSOR_PAR, true);
1292 if (!bv->Dispatch(action, arg))
1293 result = UNDISPATCHED;
1297 /// If the action has deleted all text in the inset, we need to change the
1298 // language to the language of the surronding text.
1299 if (par->size() == 0 && !par->next()) {
1300 LyXFont font(LyXFont::ALL_IGNORE);
1301 font.setLanguage(bv->getParentLanguage(this));
1302 setFont(bv, font, false);
1305 if (result != FINISHED) {
1306 showInsetCursor(bv);
1308 bv->unlockInset(this);
1315 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1318 buf->latexParagraphs(os, par, 0, texrow);
1319 return texrow.rows();
1323 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1325 Paragraph * p = par;
1326 unsigned int lines = 0;
1329 string const tmp = buf->asciiParagraph(p, linelen);
1330 lines += countChar(tmp, '\n');
1338 int InsetText::docBook(Buffer const * buf, ostream & os) const
1340 Paragraph * p = par;
1341 unsigned int lines = 0;
1346 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1354 void InsetText::validate(LaTeXFeatures & features) const
1356 Paragraph * p = par;
1358 p->validate(features);
1364 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1366 if (textclasslist.Style(buf->params.textclass,
1367 p->getLayout()).labeltype != LABEL_MANUAL)
1370 return p->beginningOfMainBody();
1374 void InsetText::getCursorPos(BufferView * bv,
1375 int & x, int & y) const
1377 if (the_locking_inset) {
1378 the_locking_inset->getCursorPos(bv, x, y);
1386 unsigned int InsetText::insetInInsetY()
1388 if (!the_locking_inset)
1391 return (inset_y + the_locking_inset->insetInInsetY());
1395 void InsetText::toggleInsetCursor(BufferView * bv)
1397 if (the_locking_inset) {
1398 the_locking_inset->toggleInsetCursor(bv);
1402 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1404 int const asc = lyxfont::maxAscent(font);
1405 int const desc = lyxfont::maxDescent(font);
1407 if (isCursorVisible())
1408 bv->hideLockedInsetCursor();
1410 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1411 toggleCursorVisible();
1415 void InsetText::showInsetCursor(BufferView * bv, bool show)
1417 if (the_locking_inset) {
1418 the_locking_inset->showInsetCursor(bv, show);
1421 if (!isCursorVisible()) {
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);
1430 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1431 setCursorVisible(true);
1436 void InsetText::hideInsetCursor(BufferView * bv)
1438 if (isCursorVisible()) {
1439 bv->hideLockedInsetCursor();
1440 setCursorVisible(false);
1442 if (the_locking_inset)
1443 the_locking_inset->hideInsetCursor(bv);
1447 void InsetText::fitInsetCursor(BufferView * bv) const
1449 if (the_locking_inset) {
1450 the_locking_inset->fitInsetCursor(bv);
1453 LyXFont const font =
1454 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1456 int const asc = lyxfont::maxAscent(font);
1457 int const desc = lyxfont::maxDescent(font);
1459 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1463 UpdatableInset::RESULT
1464 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1466 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1467 return moveLeftIntern(bv, false, activate_inset, selecting);
1469 return moveRightIntern(bv, false, activate_inset, selecting);
1473 UpdatableInset::RESULT
1474 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1476 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1477 return moveRightIntern(bv, true, activate_inset, selecting);
1479 return moveLeftIntern(bv, true, activate_inset, selecting);
1483 UpdatableInset::RESULT
1484 InsetText::moveRightIntern(BufferView * bv, bool behind,
1485 bool activate_inset, bool selecting)
1487 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1489 if (activate_inset && checkAndActivateInset(bv, behind))
1491 getLyXText(bv)->cursorRight(bv);
1493 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1494 return DISPATCHED_NOUPDATE;
1498 UpdatableInset::RESULT
1499 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1500 bool activate_inset, bool selecting)
1502 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1504 getLyXText(bv)->cursorLeft(bv);
1506 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1507 if (activate_inset && checkAndActivateInset(bv, behind))
1509 return DISPATCHED_NOUPDATE;
1513 UpdatableInset::RESULT
1514 InsetText::moveUp(BufferView * bv)
1516 if (!crow(bv)->previous())
1518 getLyXText(bv)->cursorUp(bv);
1519 return DISPATCHED_NOUPDATE;
1523 UpdatableInset::RESULT
1524 InsetText::moveDown(BufferView * bv)
1526 if (!crow(bv)->next())
1528 getLyXText(bv)->cursorDown(bv);
1529 return DISPATCHED_NOUPDATE;
1533 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1535 if (the_locking_inset) {
1536 if (the_locking_inset->insetAllowed(inset))
1537 return the_locking_inset->insertInset(bv, inset);
1540 inset->setOwner(this);
1541 hideInsetCursor(bv);
1545 lt = getLyXText(bv);
1548 lt->insertInset(bv, inset);
1550 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1551 (cpar(bv)->getInset(cpos(bv)) != inset))
1555 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1556 showInsetCursor(bv);
1563 bool InsetText::insetAllowed(Inset::Code code) const
1565 if (the_locking_inset)
1566 return the_locking_inset->insetAllowed(code);
1571 UpdatableInset * InsetText::getLockingInset() const
1573 return the_locking_inset ? the_locking_inset->getLockingInset() :
1574 const_cast<InsetText *>(this);
1578 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1582 if (the_locking_inset)
1583 return the_locking_inset->getFirstLockingInsetOfType(c);
1588 bool InsetText::showInsetDialog(BufferView * bv) const
1590 if (the_locking_inset)
1591 return the_locking_inset->showInsetDialog(bv);
1596 std::vector<string> const InsetText::getLabelList() const
1598 std::vector<string> label_list;
1600 Paragraph * tpar = par;
1602 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1603 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1604 for (; beg != end; ++beg) {
1605 std::vector<string> const l = (*beg)->getLabelList();
1606 label_list.insert(label_list.end(), l.begin(), l.end());
1608 tpar = tpar->next();
1614 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1617 if (the_locking_inset) {
1618 the_locking_inset->setFont(bv, font, toggleall, selectall);
1621 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1622 getLyXText(bv)->setFont(bv, font, toggleall);
1627 lt = getLyXText(bv);
1630 if (lt->selection.set()) {
1631 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1635 lt->toggleFree(bv, font, toggleall);
1637 lt->clearSelection();
1639 if (selectall || lt->selection.set())
1640 updateLocal(bv, FULL, true);
1642 updateLocal(bv, CURSOR_PAR, true);
1648 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1650 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1654 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1655 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1657 LyXFont const font =
1658 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1660 x = inset->width(bv, font);
1661 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1664 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1666 //inset_x = cx(bv) - top_x + drawTextXOffset;
1667 //inset_y = cy(bv) + drawTextYOffset;
1668 inset->edit(bv, x, y, 0);
1669 if (!the_locking_inset)
1671 updateLocal(bv, CURSOR, false);
1678 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1681 x -= drawTextXOffset;
1683 int dummyy = y + insetAscent;
1684 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1691 inset_x = cx(bv) - top_x + drawTextXOffset;
1692 inset_y = cy(bv) + drawTextYOffset;
1693 inset->edit(bv, x - inset_x, y - inset_y, button);
1694 if (!the_locking_inset)
1696 updateLocal(bv, CURSOR, false);
1703 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1706 int w = UpdatableInset::getMaxWidth(bv, inset);
1711 w = w - top_x + owner()->x();
1714 w -= (2 * TEXT_TO_INSET_OFFSET);
1717 return UpdatableInset::getMaxWidth(bv, inset);
1722 void InsetText::setParagraphData(Paragraph * p)
1724 // we have to unlock any locked inset otherwise we're in troubles
1725 the_locking_inset = 0;
1727 Paragraph * tmp = par->next();
1732 par = new Paragraph(*p);
1733 par->setInsetOwner(this);
1734 Paragraph * np = par;
1737 np->next(new Paragraph(*p));
1738 np->next()->previous(np);
1740 np->setInsetOwner(this);
1742 reinitLyXText(true);
1746 void InsetText::setText(string const & data)
1749 LyXFont font(LyXFont::ALL_SANE);
1750 for (unsigned int i=0; i < data.length(); ++i)
1751 par->insertChar(i, data[i], font);
1755 void InsetText::setAutoBreakRows(bool flag)
1757 if (flag != autoBreakRows) {
1758 autoBreakRows = flag;
1762 reinitLyXText(true);
1767 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1769 if (how != drawFrame_) {
1772 updateLocal(bv, DRAW_FRAME, false);
1777 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1779 if (frame_color != col) {
1782 updateLocal(bv, DRAW_FRAME, false);
1787 int InsetText::cx(BufferView * bv) const
1791 lt = getLyXText(bv);
1794 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1795 if (the_locking_inset) {
1796 LyXFont font = lt->getFont(bv->buffer(),
1799 if (font.isVisibleRightToLeft())
1800 x -= the_locking_inset->width(bv, font);
1808 int InsetText::cy(BufferView * bv) const
1811 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1815 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1817 return getLyXText(bv)->cursor.pos();
1821 Paragraph * InsetText::cpar(BufferView * bv) const
1823 return getLyXText(bv)->cursor.par();
1827 bool InsetText::cboundary(BufferView * bv) const
1829 return getLyXText(bv)->cursor.boundary();
1833 Row * InsetText::crow(BufferView * bv) const
1835 return getLyXText(bv)->cursor.row();
1839 LyXText * InsetText::getLyXText(BufferView const * lbv,
1840 bool const recursive) const
1842 if (!recursive && (cached_bview == lbv))
1843 return cached_text.get();
1845 // Super UGLY! (Lgb)
1846 BufferView * bv = const_cast<BufferView *>(lbv);
1849 Cache::iterator it = cache.find(bv);
1851 if (it != cache.end()) {
1852 if (lt || !it->second.remove) {
1853 lyx::Assert(it->second.text.get());
1854 cached_text = it->second.text;
1855 if (recursive && the_locking_inset) {
1856 return the_locking_inset->getLyXText(bv, true);
1858 return cached_text.get();
1859 } else if (it->second.remove) {
1861 saveLyXTextState(it->second.text.get());
1868 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1869 cached_text->init(bv);
1870 restoreLyXTextState(bv, cached_text.get());
1872 cache.insert(make_pair(bv, cached_text));
1874 if (the_locking_inset && recursive) {
1875 return the_locking_inset->getLyXText(bv);
1877 return cached_text.get();
1881 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1885 Cache::iterator it = cache.find(bv);
1887 if (it == cache.end()) {
1891 lyx::Assert(it->second.text.get());
1893 it->second.remove = true;
1895 /// then remove all LyXText in text-insets
1896 Paragraph * p = par;
1897 for (; p; p = p->next()) {
1898 p->deleteInsetsLyXText(bv);
1904 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1906 if (!par->next() && !par->size()) // no data, resize not neccessary!
1908 // one endless line, resize normally not necessary
1909 if (!force && getMaxWidth(bv, this) < 0)
1912 Cache::iterator it = cache.find(bv);
1913 if (it == cache.end()) {
1916 lyx::Assert(it->second.text.get());
1918 LyXText * t = it->second.text.get();
1919 saveLyXTextState(t);
1920 for (Paragraph * p = par; p; p = p->next()) {
1921 p->resizeInsetsLyXText(bv);
1924 restoreLyXTextState(bv, t);
1925 if (the_locking_inset) {
1926 inset_x = cx(bv) - top_x + drawTextXOffset;
1927 inset_y = cy(bv) + drawTextYOffset;
1931 t->first = bv->screen()->topCursorVisible(t);
1934 updateLocal(bv, FULL, false);
1935 // this will scroll the screen such that the cursor becomes visible
1936 bv->updateScrollbar();
1938 need_update |= FULL;
1943 void InsetText::reinitLyXText(bool wrong_cursor) const
1945 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1946 lyx::Assert(it->second.text.get());
1948 LyXText * t = it->second.text.get();
1949 BufferView * bv = it->first;
1954 t->clearSelection();
1956 saveLyXTextState(t);
1957 for (Paragraph * p = par; p; p = p->next()) {
1958 p->resizeInsetsLyXText(bv);
1961 restoreLyXTextState(bv, t);
1962 if (the_locking_inset) {
1963 inset_x = cx(bv) - top_x + drawTextXOffset;
1964 inset_y = cy(bv) + drawTextYOffset;
1967 t->first = bv->screen()->topCursorVisible(t);
1970 updateLocal(bv, FULL, false);
1971 // this will scroll the screen such that the cursor becomes visible
1972 bv->updateScrollbar();
1980 void InsetText::removeNewlines()
1982 for (Paragraph * p = par; p; p = p->next()) {
1983 for (int i = 0; i < p->size(); ++i) {
1984 if (p->getChar(i) == Paragraph::META_NEWLINE)
1991 bool InsetText::nodraw() const
1993 if (the_locking_inset)
1994 return the_locking_inset->nodraw();
1995 return UpdatableInset::nodraw();
1999 int InsetText::scroll(bool recursive) const
2001 int sx = UpdatableInset::scroll(false);
2003 if (recursive && the_locking_inset)
2004 sx += the_locking_inset->scroll(recursive);
2010 bool InsetText::doClearArea() const
2012 return !locked || (need_update & (FULL|INIT));
2016 void InsetText::selectAll(BufferView * bv)
2018 getLyXText(bv)->cursorTop(bv);
2019 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2020 getLyXText(bv)->cursorBottom(bv);
2021 getLyXText(bv)->setSelection(bv);
2025 void InsetText::clearSelection(BufferView * bv)
2027 getLyXText(bv)->clearSelection();
2031 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2034 int h = insetAscent + insetDescent;
2035 int ty = baseline - insetAscent;
2041 if ((ty + h) > pain.paperHeight())
2042 h = pain.paperHeight();
2043 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2044 w = pain.paperWidth();
2045 // w -= TEXT_TO_INSET_OFFSET;
2046 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2049 frame_is_visible = false;
2053 Paragraph * InsetText::getParFromID(int id) const
2056 Paragraph * result = par;
2057 Paragraph * ires = 0;
2058 while (result && result->id() != id) {
2059 if ((ires = result->getParFromID(id)))
2061 result = result->next();
2065 Paragraph * tmp = par;
2067 int tmp_id = tmp->id();
2068 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2069 if (tmp->id() == id) {
2072 Paragraph * tmp2 = tmp->getParFromID(id);
2083 Paragraph * InsetText::firstParagraph() const
2086 if (the_locking_inset)
2087 if ((result = the_locking_inset->firstParagraph()))
2093 LyXCursor const & InsetText::cursor(BufferView * bv) const
2095 if (the_locking_inset)
2096 return the_locking_inset->cursor(bv);
2097 return getLyXText(bv)->cursor;
2101 Paragraph * InsetText::paragraph() const
2107 void InsetText::paragraph(Paragraph * p)
2111 // we now have to update/redraw all instances
2112 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2117 // redraw myself when asked for
2118 need_update |= INIT;
2122 Inset * InsetText::getInsetFromID(int id_arg) const
2125 return const_cast<InsetText *>(this);
2127 Paragraph * lp = par;
2130 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2131 en = lp->inset_iterator_end();
2134 if ((*it)->id() == id_arg)
2136 Inset * in = (*it)->getInsetFromID(id_arg);
2146 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2152 lt = getLyXText(bv);
2155 if (the_locking_inset) {
2156 str = the_locking_inset->selectNextWord(bv, value);
2163 #warning Dekel please have a look on this one RTL? (Jug)
2164 // we have to go on checking so move cusor to the right
2165 lt->cursor.pos(lt->cursor.pos() + 1);
2167 str = lt->selectNextWord(bv, value);
2169 bv->unlockInset(const_cast<InsetText *>(this));
2178 void InsetText::selectSelectedWord(BufferView * bv)
2180 if (the_locking_inset) {
2181 the_locking_inset->selectSelectedWord(bv);
2184 getLyXText(bv)->selectSelectedWord(bv);
2185 updateLocal(bv, SELECTION, false);
2189 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2191 if (the_locking_inset) {
2192 the_locking_inset->toggleSelection(bv, kill_selection);
2196 lt = getLyXText(bv);
2200 int x = top_x + TEXT_TO_INSET_OFFSET;
2203 Row * row = lt->getRowNearY(y);
2204 int y_offset = top_baseline - row->ascent_of_text();
2206 while ((row != 0) && ((y+row->height()) <= 0)) {
2213 if (need_update & SELECTION)
2215 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2221 bool InsetText::searchForward(BufferView * bv, string const & str,
2222 bool const & cs, bool const & mw)
2224 if (the_locking_inset) {
2225 if (the_locking_inset->searchForward(bv, str, cs, mw))
2229 lt = getLyXText(bv);
2232 Paragraph * lpar = lt->cursor.par();
2233 Paragraph::size_type pos = lt->cursor.pos();
2234 if (pos < lpar->size() - 1)
2238 lpar = lpar->next();
2245 lt->setCursor(bv, lpar, pos);
2249 if (LyXFind(bv, str, true, true, cs , mw)) {
2252 // we have to unlock ourself in this function by default!
2253 bv->unlockInset(const_cast<InsetText *>(this));
2257 bool InsetText::searchBackward(BufferView * bv, string const & str,
2258 bool const & cs, bool const & mw)
2260 if (the_locking_inset)
2261 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2263 if (LyXFind(bv, str, false, true, cs, mw)) {
2266 // we have to unlock ourself in this function by default!
2267 bv->unlockInset(const_cast<InsetText *>(this));