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);
544 int oldw = insetWidth;
545 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
546 if (oldw != insetWidth) {
555 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
558 lt->updateInset(bv, the_locking_inset);
560 if (lt->status() == LyXText::NEED_MORE_REFRESH)
568 void InsetText::setUpdateStatus(BufferView * bv, int what) const
576 // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
577 // if we don't break row so that we only have one row to update!
578 if ((lt->status() == LyXText::NEED_MORE_REFRESH) ||
580 (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
583 } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
584 need_update |= CURSOR_PAR;
587 // this to not draw a selection when we redraw all of it!
588 if (need_update & CURSOR && !(need_update & SELECTION)) {
589 if (lt->selection.set())
591 lt->clearSelection();
598 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
606 setUpdateStatus(bv, what);
607 if (((need_update != CURSOR) && (need_update != NONE)) ||
608 (lt->status() != LyXText::UNCHANGED) || lt->selection.set())
610 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
612 if (need_update == CURSOR)
614 bv->owner()->showState();
615 if (old_par != cpar(bv)) {
616 bv->owner()->setLayout(cpar(bv)->getLayout());
624 string const InsetText::editMessage() const
626 return _("Opened Text Inset");
630 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
632 UpdatableInset::edit(bv, x, y, button);
634 if (!bv->lockInset(this)) {
635 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
639 the_locking_inset = 0;
640 inset_pos = inset_x = inset_y = 0;
641 inset_boundary = false;
644 int tmp_y = (y < 0) ? 0 : y;
651 if (!checkAndActivateInset(bv, x, tmp_y, button))
652 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
654 lt->clearSelection();
657 updateLocal(bv, CURSOR, false);
659 // If the inset is empty set the language of the current font to the
660 // language to the surronding text (if different).
661 if (par->size() == 0 && !par->next() &&
662 bv->getParentLanguage(this) != lt->current_font.language()) {
663 LyXFont font(LyXFont::ALL_IGNORE);
664 font.setLanguage(bv->getParentLanguage(this));
665 setFont(bv, font, false);
672 void InsetText::edit(BufferView * bv, bool front)
674 UpdatableInset::edit(bv, front);
676 if (!bv->lockInset(this)) {
677 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
681 the_locking_inset = 0;
682 inset_pos = inset_x = inset_y = 0;
683 inset_boundary = false;
692 lt->setCursor(bv, par, 0);
697 int const pos = (p->size() ? p->size()-1 : p->size());
698 lt->setCursor(bv, p, pos);
700 lt->clearSelection();
703 updateLocal(bv, CURSOR, false);
705 // If the inset is empty set the language of the current font to the
706 // language to the surronding text (if different).
707 if (par->size() == 0 && !par->next() &&
708 bv->getParentLanguage(this) != lt->current_font.language()) {
709 LyXFont font(LyXFont::ALL_IGNORE);
710 font.setLanguage(bv->getParentLanguage(this));
711 setFont(bv, font, false);
718 void InsetText::insetUnlock(BufferView * bv)
720 if (the_locking_inset) {
721 the_locking_inset->insetUnlock(bv);
722 the_locking_inset = 0;
725 no_selection = false;
728 if (drawFrame_ == LOCKED)
729 code = CURSOR|CLEAR_FRAME;
737 if (lt->selection.set()) {
738 lt->clearSelection();
740 } else if (owner()) {
741 bv->owner()->setLayout(owner()->getLyXText(bv)
742 ->cursor.par()->getLayout());
744 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
745 // hack for deleteEmptyParMech
746 lt->setCursor(bv, par, 0);
747 updateLocal(bv, code, false);
753 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
755 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
759 if (inset == cpar(bv)->getInset(cpos(bv))) {
760 lyxerr[Debug::INSETS] << "OK" << endl;
761 the_locking_inset = inset;
762 inset_x = cx(bv) - top_x + drawTextXOffset;
763 inset_y = cy(bv) + drawTextYOffset;
764 inset_pos = cpos(bv);
765 inset_par = cpar(bv);
766 inset_boundary = cboundary(bv);
767 updateLocal(bv, CURSOR, false);
769 } else if (the_locking_inset && (the_locking_inset == inset)) {
770 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
771 lyxerr[Debug::INSETS] << "OK" << endl;
772 inset_x = cx(bv) - top_x + drawTextXOffset;
773 inset_y = cy(bv) + drawTextYOffset;
775 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
777 } else if (the_locking_inset) {
778 lyxerr[Debug::INSETS] << "MAYBE" << endl;
779 return the_locking_inset->lockInsetInInset(bv, inset);
781 lyxerr[Debug::INSETS] << "NOT OK" << endl;
786 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
789 if (!the_locking_inset)
791 if (the_locking_inset == inset) {
792 the_locking_inset->insetUnlock(bv);
793 getLyXText(bv)->updateInset(bv, inset);
794 the_locking_inset = 0;
796 moveRight(bv, false);
797 old_par = 0; // force layout setting
801 updateLocal(bv, CURSOR, false);
804 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
808 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
810 if (!the_locking_inset)
812 if (the_locking_inset != inset) {
813 getLyXText(bv)->updateInset(bv, the_locking_inset);
814 setUpdateStatus(bv, CURSOR_PAR);
815 return the_locking_inset->updateInsetInInset(bv, inset);
817 if (getLyXText(bv)->updateInset(bv, inset))
818 updateLocal(bv, CURSOR_PAR, false);
819 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
820 inset_x = cx(bv) - top_x + drawTextXOffset;
821 inset_y = cy(bv) + drawTextYOffset;
827 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
831 int tmp_x = x - drawTextXOffset;
832 int tmp_y = y + insetAscent - getLyXText(bv)->first;
833 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
836 if (the_locking_inset) {
837 if (the_locking_inset == inset) {
838 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
839 no_selection = false;
842 // otherwise unlock the_locking_inset and lock the new inset
843 the_locking_inset->insetUnlock(bv);
844 inset_x = cx(bv) - top_x + drawTextXOffset;
845 inset_y = cy(bv) + drawTextYOffset;
846 the_locking_inset = static_cast<UpdatableInset*>(inset);
847 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
848 inset->edit(bv, x - inset_x, y - inset_y, button);
849 if (the_locking_inset)
850 updateLocal(bv, CURSOR, false);
851 no_selection = false;
854 // otherwise only unlock the_locking_inset
855 the_locking_inset->insetUnlock(bv);
856 the_locking_inset = 0;
858 if (bv->theLockingInset()) {
859 if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
860 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
861 inset_x = cx(bv) - top_x + drawTextXOffset;
862 inset_y = cy(bv) + drawTextYOffset;
863 inset_pos = cpos(bv);
864 inset_par = cpar(bv);
865 inset_boundary = cboundary(bv);
866 the_locking_inset = uinset;
867 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
869 uinset->edit(bv, x - inset_x, y - inset_y, 0);
870 if (the_locking_inset)
871 updateLocal(bv, CURSOR, false);
872 no_selection = false;
876 if (!inset) { // && (button == 2)) {
877 bool paste_internally = false;
878 if ((button == 2) && getLyXText(bv)->selection.set()) {
879 localDispatch(bv, LFUN_COPY, "");
880 paste_internally = true;
887 lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent);
888 if (lt->selection.set()) {
889 lt->clearSelection();
890 updateLocal(bv, FULL, false);
892 lt->clearSelection();
894 bv->owner()->setLayout(cpar(bv)->getLayout());
896 // Insert primary selection with middle mouse
897 // if there is a local selection in the current buffer,
900 if (paste_internally)
901 localDispatch(bv, LFUN_PASTE, "");
903 localDispatch(bv, LFUN_PASTESELECTION,
910 no_selection = false;
914 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
916 UpdatableInset * inset = 0;
918 if (the_locking_inset) {
919 the_locking_inset->insetButtonRelease(bv,
920 x - inset_x, y - inset_y,
923 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
924 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
925 if (inset->editable() == Inset::HIGHLY_EDITABLE) {
926 inset->insetButtonRelease(bv,
928 y - inset_y, button);
930 inset_x = cx(bv) - top_x + drawTextXOffset;
931 inset_y = cy(bv) + drawTextYOffset;
932 inset->insetButtonRelease(bv,
934 y - inset_y, button);
936 x - inset_x, y - inset_y, button);
938 updateLocal(bv, CURSOR_PAR, false);
941 no_selection = false;
945 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
949 if (the_locking_inset) {
950 the_locking_inset->insetMotionNotify(bv, x - inset_x,
954 LyXText * t = getLyXText(bv);
956 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
958 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
959 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
960 updateLocal(bv, SELECTION, false);
965 void InsetText::insetKeyPress(XKeyEvent * xke)
967 if (the_locking_inset) {
968 the_locking_inset->insetKeyPress(xke);
974 UpdatableInset::RESULT
975 InsetText::localDispatch(BufferView * bv,
976 kb_action action, string const & arg)
978 no_selection = false;
979 UpdatableInset::RESULT
980 result= UpdatableInset::localDispatch(bv, action, arg);
981 if (result != UNDISPATCHED) {
986 if ((action < 0) && arg.empty())
989 if (the_locking_inset) {
990 result = the_locking_inset->localDispatch(bv, action, arg);
991 if (result == DISPATCHED_NOUPDATE)
993 else if (result == DISPATCHED) {
994 updateLocal(bv, CURSOR_PAR, false);
996 } else if (result == FINISHED) {
997 bool dispatched = false;
999 case LFUN_UNKNOWN_ACTION:
1000 case LFUN_BREAKPARAGRAPH:
1001 case LFUN_BREAKLINE:
1002 moveRightIntern(bv, false, false);
1005 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1006 moveRightIntern(bv, false, false);
1010 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1011 moveRightIntern(bv, false, false);
1017 the_locking_inset = 0;
1022 hideInsetCursor(bv);
1025 lt = getLyXText(bv);
1030 case LFUN_SELFINSERT:
1031 if (bv->buffer()->isReadonly()) {
1032 // setErrorMessage(N_("Document is read only"));
1036 /* Automatically delete the currently selected
1037 * text and replace it with what is being
1038 * typed in now. Depends on lyxrc settings
1039 * "auto_region_delete", which defaults to
1042 setUndo(bv, Undo::INSERT,
1043 lt->cursor.par(), lt->cursor.par()->next());
1045 if (lyxrc.auto_region_delete) {
1046 if (lt->selection.set()) {
1047 lt->cutSelection(bv, false);
1050 lt->clearSelection();
1051 for (string::size_type i = 0; i < arg.length(); ++i) {
1052 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1055 lt->selection.cursor = lt->cursor;
1056 updateLocal(bv, CURSOR_PAR, true);
1057 result = DISPATCHED_NOUPDATE;
1059 // --- Cursor Movements -----------------------------------
1062 moveRight(bv, false, true);
1063 lt->setSelection(bv);
1064 updateLocal(bv, SELECTION, false);
1067 result = moveRight(bv);
1069 updateLocal(bv, CURSOR, false);
1073 moveLeft(bv, false, true);
1074 lt->setSelection(bv);
1075 updateLocal(bv, SELECTION, false);
1079 result = moveLeft(bv);
1080 updateLocal(bv, CURSOR, false);
1085 lt->setSelection(bv);
1086 updateLocal(bv, SELECTION, false);
1090 result = moveDown(bv);
1091 updateLocal(bv, CURSOR, false);
1096 lt->setSelection(bv);
1097 updateLocal(bv, SELECTION, false);
1101 result = moveUp(bv);
1102 updateLocal(bv, CURSOR, false);
1107 updateLocal(bv, CURSOR, false);
1111 updateLocal(bv, CURSOR, false);
1113 case LFUN_BACKSPACE: {
1114 setUndo(bv, Undo::DELETE,
1115 lt->cursor.par(), lt->cursor.par()->next());
1116 if (lt->selection.set())
1117 lt->cutSelection(bv);
1120 updateLocal(bv, CURSOR_PAR, true);
1125 setUndo(bv, Undo::DELETE,
1126 lt->cursor.par(), lt->cursor.par()->next());
1127 if (lt->selection.set()) {
1128 lt->cutSelection(bv);
1132 updateLocal(bv, CURSOR_PAR, true);
1137 setUndo(bv, Undo::DELETE,
1138 lt->cursor.par(), lt->cursor.par()->next());
1139 lt->cutSelection(bv);
1140 updateLocal(bv, CURSOR_PAR, true);
1146 lt->copySelection(bv);
1147 updateLocal(bv, CURSOR_PAR, false);
1149 case LFUN_PASTESELECTION:
1151 string const clip(bv->getClipboard());
1155 if (arg == "paragraph") {
1156 lt->insertStringAsParagraphs(bv, clip);
1158 lt->insertStringAsLines(bv, clip);
1160 updateLocal(bv, CURSOR_PAR, true);
1164 if (!autoBreakRows) {
1166 if (CutAndPaste::nrOfParagraphs() > 1) {
1167 WriteAlert(_("Impossible operation"),
1168 _("Cannot include more than one paragraph!"),
1173 setUndo(bv, Undo::INSERT,
1174 lt->cursor.par(), lt->cursor.par()->next());
1175 lt->pasteSelection(bv);
1176 updateLocal(bv, CURSOR_PAR, true);
1180 case LFUN_BREAKPARAGRAPH:
1181 if (!autoBreakRows) {
1182 result = DISPATCHED;
1185 lt->breakParagraph(bv, 0);
1186 updateLocal(bv, FULL, true);
1188 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1189 if (!autoBreakRows) {
1190 result = DISPATCHED;
1193 lt->breakParagraph(bv, 1);
1194 updateLocal(bv, FULL, true);
1197 case LFUN_BREAKLINE: {
1198 if (!autoBreakRows) {
1199 result = DISPATCHED;
1202 setUndo(bv, Undo::INSERT,
1203 lt->cursor.par(), lt->cursor.par()->next());
1204 lt->insertChar(bv, Paragraph::META_NEWLINE);
1205 updateLocal(bv, CURSOR_PAR, true);
1210 // do not set layouts on non breakable textinsets
1211 if (autoBreakRows) {
1212 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1214 // Derive layout number from given argument (string)
1215 // and current buffer's textclass (number). */
1216 LyXTextClassList::ClassList::size_type tclass =
1217 bv->buffer()->params.textclass;
1218 std::pair <bool, LyXTextClass::size_type> layout =
1219 textclasslist.NumberOfLayout(tclass, arg);
1221 // If the entry is obsolete, use the new one instead.
1223 string obs = textclasslist.Style(tclass,layout.second).
1226 layout = textclasslist.NumberOfLayout(tclass, obs);
1229 // see if we found the layout number:
1230 if (!layout.first) {
1231 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1232 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1236 if (cur_layout != layout.second) {
1237 cur_layout = layout.second;
1238 lt->setLayout(bv, layout.second);
1239 bv->owner()->setLayout(cpar(bv)->getLayout());
1240 updateLocal(bv, CURSOR_PAR, true);
1243 // reset the layout box
1244 bv->owner()->setLayout(cpar(bv)->getLayout());
1247 case LFUN_PARAGRAPH_SPACING:
1248 // This one is absolutely not working. When fiddling with this
1249 // it also seems to me that the paragraphs inside the insettext
1250 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1252 Paragraph * par = lt->cursor.par();
1253 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1254 float cur_value = 1.0;
1255 if (cur_spacing == Spacing::Other) {
1256 cur_value = par->params().spacing().getValue();
1259 istringstream istr(arg.c_str());
1262 Spacing::Space new_spacing = cur_spacing;
1263 float new_value = cur_value;
1265 lyxerr << "Missing argument to `paragraph-spacing'"
1267 } else if (tmp == "single") {
1268 new_spacing = Spacing::Single;
1269 } else if (tmp == "onehalf") {
1270 new_spacing = Spacing::Onehalf;
1271 } else if (tmp == "double") {
1272 new_spacing = Spacing::Double;
1273 } else if (tmp == "other") {
1274 new_spacing = Spacing::Other;
1277 lyxerr << "new_value = " << tmpval << endl;
1280 } else if (tmp == "default") {
1281 new_spacing = Spacing::Default;
1283 lyxerr << _("Unknown spacing argument: ")
1286 if (cur_spacing != new_spacing || cur_value != new_value) {
1287 par->params().spacing(Spacing(new_spacing, new_value));
1288 updateLocal(bv, CURSOR_PAR, true);
1294 if (!bv->Dispatch(action, arg))
1295 result = UNDISPATCHED;
1299 /// If the action has deleted all text in the inset, we need to change the
1300 // language to the language of the surronding text.
1301 if (par->size() == 0 && !par->next()) {
1302 LyXFont font(LyXFont::ALL_IGNORE);
1303 font.setLanguage(bv->getParentLanguage(this));
1304 setFont(bv, font, false);
1307 if (result != FINISHED) {
1308 showInsetCursor(bv);
1310 bv->unlockInset(this);
1317 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1320 buf->latexParagraphs(os, par, 0, texrow);
1321 return texrow.rows();
1325 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1327 Paragraph * p = par;
1328 unsigned int lines = 0;
1331 string const tmp = buf->asciiParagraph(p, linelen);
1332 lines += countChar(tmp, '\n');
1340 int InsetText::docBook(Buffer const * buf, ostream & os) const
1342 Paragraph * p = par;
1343 unsigned int lines = 0;
1348 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1356 void InsetText::validate(LaTeXFeatures & features) const
1358 Paragraph * p = par;
1360 p->validate(features);
1366 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1368 if (textclasslist.Style(buf->params.textclass,
1369 p->getLayout()).labeltype != LABEL_MANUAL)
1372 return p->beginningOfMainBody();
1376 void InsetText::getCursorPos(BufferView * bv,
1377 int & x, int & y) const
1379 if (the_locking_inset) {
1380 the_locking_inset->getCursorPos(bv, x, y);
1388 unsigned int InsetText::insetInInsetY()
1390 if (!the_locking_inset)
1393 return (inset_y + the_locking_inset->insetInInsetY());
1397 void InsetText::toggleInsetCursor(BufferView * bv)
1399 if (the_locking_inset) {
1400 the_locking_inset->toggleInsetCursor(bv);
1404 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1406 int const asc = lyxfont::maxAscent(font);
1407 int const desc = lyxfont::maxDescent(font);
1409 if (isCursorVisible())
1410 bv->hideLockedInsetCursor();
1412 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1413 toggleCursorVisible();
1417 void InsetText::showInsetCursor(BufferView * bv, bool show)
1419 if (the_locking_inset) {
1420 the_locking_inset->showInsetCursor(bv, show);
1423 if (!isCursorVisible()) {
1424 LyXFont const font =
1425 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1427 int const asc = lyxfont::maxAscent(font);
1428 int const desc = lyxfont::maxDescent(font);
1430 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1432 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1433 setCursorVisible(true);
1438 void InsetText::hideInsetCursor(BufferView * bv)
1440 if (isCursorVisible()) {
1441 bv->hideLockedInsetCursor();
1442 setCursorVisible(false);
1444 if (the_locking_inset)
1445 the_locking_inset->hideInsetCursor(bv);
1449 void InsetText::fitInsetCursor(BufferView * bv) const
1451 if (the_locking_inset) {
1452 the_locking_inset->fitInsetCursor(bv);
1455 LyXFont const font =
1456 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1458 int const asc = lyxfont::maxAscent(font);
1459 int const desc = lyxfont::maxDescent(font);
1461 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1465 UpdatableInset::RESULT
1466 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1468 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1469 return moveLeftIntern(bv, false, activate_inset, selecting);
1471 return moveRightIntern(bv, false, activate_inset, selecting);
1475 UpdatableInset::RESULT
1476 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1478 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1479 return moveRightIntern(bv, true, activate_inset, selecting);
1481 return moveLeftIntern(bv, true, activate_inset, selecting);
1485 UpdatableInset::RESULT
1486 InsetText::moveRightIntern(BufferView * bv, bool behind,
1487 bool activate_inset, bool selecting)
1489 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1491 if (activate_inset && checkAndActivateInset(bv, behind))
1493 getLyXText(bv)->cursorRight(bv);
1495 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1496 return DISPATCHED_NOUPDATE;
1500 UpdatableInset::RESULT
1501 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1502 bool activate_inset, bool selecting)
1504 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1506 getLyXText(bv)->cursorLeft(bv);
1508 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1509 if (activate_inset && checkAndActivateInset(bv, behind))
1511 return DISPATCHED_NOUPDATE;
1515 UpdatableInset::RESULT
1516 InsetText::moveUp(BufferView * bv)
1518 if (!crow(bv)->previous())
1520 getLyXText(bv)->cursorUp(bv);
1521 return DISPATCHED_NOUPDATE;
1525 UpdatableInset::RESULT
1526 InsetText::moveDown(BufferView * bv)
1528 if (!crow(bv)->next())
1530 getLyXText(bv)->cursorDown(bv);
1531 return DISPATCHED_NOUPDATE;
1535 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1537 if (the_locking_inset) {
1538 if (the_locking_inset->insetAllowed(inset))
1539 return the_locking_inset->insertInset(bv, inset);
1542 inset->setOwner(this);
1543 hideInsetCursor(bv);
1547 lt = getLyXText(bv);
1550 lt->insertInset(bv, inset);
1552 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1553 (cpar(bv)->getInset(cpos(bv)) != inset))
1557 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1558 showInsetCursor(bv);
1565 bool InsetText::insetAllowed(Inset::Code code) const
1567 if (the_locking_inset)
1568 return the_locking_inset->insetAllowed(code);
1573 UpdatableInset * InsetText::getLockingInset() const
1575 return the_locking_inset ? the_locking_inset->getLockingInset() :
1576 const_cast<InsetText *>(this);
1580 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1584 if (the_locking_inset)
1585 return the_locking_inset->getFirstLockingInsetOfType(c);
1590 bool InsetText::showInsetDialog(BufferView * bv) const
1592 if (the_locking_inset)
1593 return the_locking_inset->showInsetDialog(bv);
1598 std::vector<string> const InsetText::getLabelList() const
1600 std::vector<string> label_list;
1602 Paragraph * tpar = par;
1604 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1605 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1606 for (; beg != end; ++beg) {
1607 std::vector<string> const l = (*beg)->getLabelList();
1608 label_list.insert(label_list.end(), l.begin(), l.end());
1610 tpar = tpar->next();
1616 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1619 if (the_locking_inset) {
1620 the_locking_inset->setFont(bv, font, toggleall, selectall);
1623 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1624 getLyXText(bv)->setFont(bv, font, toggleall);
1629 lt = getLyXText(bv);
1632 if (lt->selection.set()) {
1633 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1637 lt->toggleFree(bv, font, toggleall);
1639 lt->clearSelection();
1641 if (selectall || lt->selection.set())
1642 updateLocal(bv, FULL, true);
1644 updateLocal(bv, CURSOR_PAR, true);
1650 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1652 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1656 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1657 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1659 LyXFont const font =
1660 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1662 x = inset->width(bv, font);
1663 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1666 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1668 //inset_x = cx(bv) - top_x + drawTextXOffset;
1669 //inset_y = cy(bv) + drawTextYOffset;
1670 inset->edit(bv, x, y, 0);
1671 if (!the_locking_inset)
1673 updateLocal(bv, CURSOR, false);
1680 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1683 x -= drawTextXOffset;
1685 int dummyy = y + insetAscent;
1686 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1693 inset_x = cx(bv) - top_x + drawTextXOffset;
1694 inset_y = cy(bv) + drawTextYOffset;
1695 inset->edit(bv, x - inset_x, y - inset_y, button);
1696 if (!the_locking_inset)
1698 updateLocal(bv, CURSOR, false);
1705 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1708 int w = UpdatableInset::getMaxWidth(bv, inset);
1713 w = w - top_x + owner()->x();
1716 w -= (2 * TEXT_TO_INSET_OFFSET);
1719 return UpdatableInset::getMaxWidth(bv, inset);
1724 void InsetText::setParagraphData(Paragraph * p)
1726 // we have to unlock any locked inset otherwise we're in troubles
1727 the_locking_inset = 0;
1729 Paragraph * tmp = par->next();
1734 par = new Paragraph(*p);
1735 par->setInsetOwner(this);
1736 Paragraph * np = par;
1739 np->next(new Paragraph(*p));
1740 np->next()->previous(np);
1742 np->setInsetOwner(this);
1748 void InsetText::setText(string const & data)
1751 LyXFont font(LyXFont::ALL_SANE);
1752 for (unsigned int i=0; i < data.length(); ++i)
1753 par->insertChar(i, data[i], font);
1757 void InsetText::setAutoBreakRows(bool flag)
1759 if (flag != autoBreakRows) {
1760 autoBreakRows = flag;
1768 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1770 if (how != drawFrame_) {
1773 updateLocal(bv, DRAW_FRAME, false);
1778 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1780 if (frame_color != col) {
1783 updateLocal(bv, DRAW_FRAME, false);
1788 int InsetText::cx(BufferView * bv) const
1792 lt = getLyXText(bv);
1795 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1796 if (the_locking_inset) {
1797 LyXFont font = lt->getFont(bv->buffer(),
1800 if (font.isVisibleRightToLeft())
1801 x -= the_locking_inset->width(bv, font);
1809 int InsetText::cy(BufferView * bv) const
1812 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1816 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1818 return getLyXText(bv)->cursor.pos();
1822 Paragraph * InsetText::cpar(BufferView * bv) const
1824 return getLyXText(bv)->cursor.par();
1828 bool InsetText::cboundary(BufferView * bv) const
1830 return getLyXText(bv)->cursor.boundary();
1834 Row * InsetText::crow(BufferView * bv) const
1836 return getLyXText(bv)->cursor.row();
1840 LyXText * InsetText::getLyXText(BufferView const * lbv,
1841 bool const recursive) const
1843 if (!recursive && (cached_bview == lbv))
1844 return cached_text.get();
1846 // Super UGLY! (Lgb)
1847 BufferView * bv = const_cast<BufferView *>(lbv);
1850 Cache::iterator it = cache.find(bv);
1852 if (it != cache.end()) {
1853 if (lt || !it->second.remove) {
1854 lyx::Assert(it->second.text.get());
1855 cached_text = it->second.text;
1856 if (recursive && the_locking_inset) {
1857 return the_locking_inset->getLyXText(bv, true);
1859 return cached_text.get();
1860 } else if (it->second.remove) {
1862 saveLyXTextState(it->second.text.get());
1869 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1870 cached_text->init(bv);
1871 restoreLyXTextState(bv, cached_text.get());
1873 cache.insert(make_pair(bv, cached_text));
1875 if (the_locking_inset && recursive) {
1876 return the_locking_inset->getLyXText(bv);
1878 return cached_text.get();
1882 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1886 Cache::iterator it = cache.find(bv);
1888 if (it == cache.end()) {
1892 lyx::Assert(it->second.text.get());
1894 it->second.remove = true;
1896 /// then remove all LyXText in text-insets
1897 Paragraph * p = par;
1898 for (; p; p = p->next()) {
1899 p->deleteInsetsLyXText(bv);
1905 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1907 // lyxerr << "InsetText::resizeLyXText\n";
1908 if (!par->next() && !par->size()) // no data, resize not neccessary!
1910 // one endless line, resize normally not necessary
1911 if (!force && getMaxWidth(bv, this) < 0)
1914 Cache::iterator it = cache.find(bv);
1915 if (it == cache.end()) {
1918 lyx::Assert(it->second.text.get());
1920 LyXText * t = it->second.text.get();
1921 saveLyXTextState(t);
1922 for (Paragraph * p = par; p; p = p->next()) {
1923 p->resizeInsetsLyXText(bv);
1926 restoreLyXTextState(bv, t);
1927 if (the_locking_inset) {
1928 inset_x = cx(bv) - top_x + drawTextXOffset;
1929 inset_y = cy(bv) + drawTextYOffset;
1933 t->first = bv->screen()->topCursorVisible(t);
1936 updateLocal(bv, FULL, false);
1937 // this will scroll the screen such that the cursor becomes visible
1938 bv->updateScrollbar();
1940 need_update |= FULL;
1945 void InsetText::reinitLyXText(bool wrong_cursor) const
1947 // lyxerr << "InsetText::reinitLyXText\n";
1948 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1949 lyx::Assert(it->second.text.get());
1951 LyXText * t = it->second.text.get();
1952 BufferView * bv = it->first;
1957 t->clearSelection();
1959 saveLyXTextState(t);
1960 for (Paragraph * p = par; p; p = p->next()) {
1961 p->resizeInsetsLyXText(bv);
1964 restoreLyXTextState(bv, t);
1965 if (the_locking_inset) {
1966 inset_x = cx(bv) - top_x + drawTextXOffset;
1967 inset_y = cy(bv) + drawTextYOffset;
1970 t->first = bv->screen()->topCursorVisible(t);
1973 updateLocal(bv, FULL, false);
1974 // this will scroll the screen such that the cursor becomes visible
1975 bv->updateScrollbar();
1983 void InsetText::removeNewlines()
1985 for (Paragraph * p = par; p; p = p->next()) {
1986 for (int i = 0; i < p->size(); ++i) {
1987 if (p->getChar(i) == Paragraph::META_NEWLINE)
1994 bool InsetText::nodraw() const
1996 if (the_locking_inset)
1997 return the_locking_inset->nodraw();
1998 return UpdatableInset::nodraw();
2002 int InsetText::scroll(bool recursive) const
2004 int sx = UpdatableInset::scroll(false);
2006 if (recursive && the_locking_inset)
2007 sx += the_locking_inset->scroll(recursive);
2013 bool InsetText::doClearArea() const
2015 return !locked || (need_update & (FULL|INIT));
2019 void InsetText::selectAll(BufferView * bv)
2021 getLyXText(bv)->cursorTop(bv);
2022 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2023 getLyXText(bv)->cursorBottom(bv);
2024 getLyXText(bv)->setSelection(bv);
2028 void InsetText::clearSelection(BufferView * bv)
2030 getLyXText(bv)->clearSelection();
2034 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2037 int h = insetAscent + insetDescent;
2038 int ty = baseline - insetAscent;
2044 if ((ty + h) > pain.paperHeight())
2045 h = pain.paperHeight();
2046 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2047 w = pain.paperWidth();
2048 // w -= TEXT_TO_INSET_OFFSET;
2049 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2052 frame_is_visible = false;
2056 Paragraph * InsetText::getParFromID(int id) const
2059 Paragraph * result = par;
2060 Paragraph * ires = 0;
2061 while (result && result->id() != id) {
2062 if ((ires = result->getParFromID(id)))
2064 result = result->next();
2068 Paragraph * tmp = par;
2070 int tmp_id = tmp->id();
2071 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2072 if (tmp->id() == id) {
2075 Paragraph * tmp2 = tmp->getParFromID(id);
2086 Paragraph * InsetText::firstParagraph() const
2089 if (the_locking_inset)
2090 if ((result = the_locking_inset->firstParagraph()))
2096 LyXCursor const & InsetText::cursor(BufferView * bv) const
2098 if (the_locking_inset)
2099 return the_locking_inset->cursor(bv);
2100 return getLyXText(bv)->cursor;
2104 Paragraph * InsetText::paragraph() const
2110 void InsetText::paragraph(Paragraph * p)
2114 // we now have to update/redraw all instances
2115 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2120 // redraw myself when asked for
2125 Inset * InsetText::getInsetFromID(int id_arg) const
2128 return const_cast<InsetText *>(this);
2130 Paragraph * lp = par;
2133 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2134 en = lp->inset_iterator_end();
2137 if ((*it)->id() == id_arg)
2139 Inset * in = (*it)->getInsetFromID(id_arg);
2149 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2155 lt = getLyXText(bv);
2158 if (the_locking_inset) {
2159 str = the_locking_inset->selectNextWord(bv, value);
2166 #warning Dekel please have a look on this one RTL? (Jug)
2167 // we have to go on checking so move cusor to the right
2168 lt->cursor.pos(lt->cursor.pos() + 1);
2170 str = lt->selectNextWord(bv, value);
2172 bv->unlockInset(const_cast<InsetText *>(this));
2181 void InsetText::selectSelectedWord(BufferView * bv)
2183 if (the_locking_inset) {
2184 the_locking_inset->selectSelectedWord(bv);
2187 getLyXText(bv)->selectSelectedWord(bv);
2188 updateLocal(bv, SELECTION, false);
2192 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2194 if (the_locking_inset) {
2195 the_locking_inset->toggleSelection(bv, kill_selection);
2199 lt = getLyXText(bv);
2203 int x = top_x + TEXT_TO_INSET_OFFSET;
2206 Row * row = lt->getRowNearY(y);
2207 int y_offset = top_baseline - row->ascent_of_text();
2209 while ((row != 0) && ((y+row->height()) <= 0)) {
2216 if (need_update & SELECTION)
2218 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2224 bool InsetText::searchForward(BufferView * bv, string const & str,
2225 bool const & cs, bool const & mw)
2227 if (the_locking_inset) {
2228 if (the_locking_inset->searchForward(bv, str, cs, mw))
2232 lt = getLyXText(bv);
2235 Paragraph * lpar = lt->cursor.par();
2236 Paragraph::size_type pos = lt->cursor.pos();
2237 if (pos < lpar->size() - 1)
2241 lpar = lpar->next();
2248 lt->setCursor(bv, lpar, pos);
2252 if (LyXFind(bv, str, true, true, cs , mw)) {
2255 // we have to unlock ourself in this function by default!
2256 bv->unlockInset(const_cast<InsetText *>(this));
2260 bool InsetText::searchBackward(BufferView * bv, string const & str,
2261 bool const & cs, bool const & mw)
2263 if (the_locking_inset)
2264 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2266 if (LyXFind(bv, str, false, true, cs, mw)) {
2269 // we have to unlock ourself in this function by default!
2270 bv->unlockInset(const_cast<InsetText *>(this));