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 // These 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), do_resize(0),
140 InsetText::InsetText(InsetText const & in, bool same_id)
141 : UpdatableInset(in, same_id), lt(0), in_update(false), do_resize(0),
149 InsetText & InsetText::operator=(InsetText const & it)
156 void InsetText::init(InsetText const * ins, bool same_id)
159 setParagraphData(ins->par);
160 autoBreakRows = ins->autoBreakRows;
161 drawFrame_ = ins->drawFrame_;
162 frame_color = ins->frame_color;
168 p->setInsetOwner(this);
171 the_locking_inset = 0;
173 frame_color = LColor::insetframe;
174 autoBreakRows = false;
183 no_selection = false;
190 last_drawn_width = -1;
191 frame_is_visible = false;
197 InsetText::~InsetText()
204 Paragraph * tmp = par->next();
211 void InsetText::clear()
214 Paragraph * tmp = par->next();
223 Inset * InsetText::clone(Buffer const &, bool same_id) const
225 return new InsetText(*this, same_id);
229 void InsetText::write(Buffer const * buf, ostream & os) const
232 writeParagraphData(buf, os);
236 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
238 par->writeFile(buf, os, buf->params, 0);
242 void InsetText::read(Buffer const * buf, LyXLex & lex)
246 Paragraph * return_par = 0;
247 Paragraph::depth_type depth = 0;
248 LyXFont font(LyXFont::ALL_INHERIT);
254 token = lex.getString();
257 if (token == "\\end_inset") {
258 #ifndef NO_COMPABILITY
259 const_cast<Buffer*>(buf)->insertErtContents(par, pos, font, false);
264 if (const_cast<Buffer*>(buf)->
265 parseSingleLyXformat2Token(lex, par, return_par,
266 token, pos, depth, font)) {
267 // the_end read this should NEVER happen
268 lex.printError("\\the_end read in inset! Error in document!");
276 return_par->setInsetOwner(this);
277 return_par = return_par->next();
280 if (token != "\\end_inset") {
281 lex.printError("Missing \\end_inset at this point. "
288 int InsetText::ascent(BufferView * bv, LyXFont const &) const
291 Row * row = getLyXText(bv)->getRowNearY(y_temp);
292 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
297 int InsetText::descent(BufferView * bv, LyXFont const &) const
305 Row * row = lt->getRowNearY(y_temp);
306 insetDescent = lt->height - row->ascent_of_text() +
307 TEXT_TO_INSET_OFFSET;
314 int InsetText::width(BufferView * bv, LyXFont const &) const
316 insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
317 (2 * TEXT_TO_INSET_OFFSET);
318 insetWidth = max(insetWidth, 10);
323 int InsetText::textWidth(BufferView * bv, bool fordraw) const
326 if (!autoBreakRows) {
329 w = getMaxWidth(bv, this);
332 return max(w - (2 * TEXT_TO_INSET_OFFSET),
333 (int)getLyXText(bv)->width);
337 return w - (2 * TEXT_TO_INSET_OFFSET);
341 void InsetText::draw(BufferView * bv, LyXFont const & f,
342 int baseline, float & x, bool cleared) const
347 Painter & pain = bv->painter();
349 // this is the first thing we have to ask because if the x pos
350 // changed we have to do a complete rebreak of the text as we
351 // may have few space to draw in. Well we should check on this too
353 if (top_x != int(x)) {
355 int nw = getMaxWidth(bv, this);
356 if (nw > 0 && old_max_width != nw) {
359 bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
367 // repaint the background if needed
368 if (cleared && backgroundColor() != LColor::background) {
370 clearInset(pain, baseline, cleared);
374 // no draw is necessary !!!
375 if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
378 top_baseline = baseline;
380 if (need_update & CLEAR_FRAME)
381 clearFrame(pain, cleared);
388 x += static_cast<float>(scroll());
390 // if top_x differs we did it already
391 if (!cleared && (top_x == int(x)) &&
392 ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
393 (last_drawn_width!=insetWidth))) {
394 clearInset(pain, baseline, cleared);
400 frame_is_visible = false;
402 if (!cleared && (need_update == NONE)) {
404 drawFrame(pain, cleared);
408 top_baseline = baseline;
409 top_y = baseline - ascent(bv, f);
410 last_width = width(bv, f);
411 last_height = ascent(bv, f) + descent(bv, f);
413 if (cleared || (last_drawn_width != insetWidth)) {
415 clearInset(pain, baseline, cleared);
417 last_drawn_width = insetWidth;
420 if (the_locking_inset && (cpar(bv) == inset_par)
421 && (cpos(bv) == inset_pos)) {
422 inset_x = cx(bv) - top_x + drawTextXOffset;
423 inset_y = cy(bv) + drawTextYOffset;
425 if (!cleared && (need_update == CURSOR)
426 && !getLyXText(bv)->selection.set())
428 drawFrame(pain, cleared);
429 x += last_width; // was width(bv, f);
438 x += TEXT_TO_INSET_OFFSET;
441 Row * row = lt->getRowNearY(y);
442 int y_offset = baseline - row->ascent_of_text();
443 int ph = pain.paperHeight();
446 while ((row != 0) && ((y+row->height()) <= 0)) {
448 first += row->height();
454 if (cleared || (need_update&(INIT|FULL))) {
457 while ((row != 0) && (yf < ph)) {
458 lt->getVisibleRow(bv, y+y_offset, int(x), row,
464 } else if (!locked) {
465 if (need_update & CURSOR) {
466 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
467 lt->clearSelection();
468 lt->selection.cursor = lt->cursor;
470 bv->screen()->update(lt, bv, y_offset, int(x));
473 if (need_update & SELECTION)
474 bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
475 else if (need_update & CURSOR) {
476 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
477 lt->clearSelection();
478 lt->selection.cursor = lt->cursor;
480 bv->screen()->update(lt, bv, y_offset, int(x));
485 lt->status(bv, LyXText::UNCHANGED);
486 if ((need_update != CURSOR_PAR) &&
487 ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
488 drawFrame(pain, cleared);
489 else if (need_update & CLEAR_FRAME)
490 clearFrame(pain, cleared);
491 x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
492 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
494 } else if (need_update != INIT)
501 void InsetText::drawFrame(Painter & pain, bool cleared) const
503 static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
504 if (!frame_is_visible || cleared) {
505 frame_x = top_x + ttoD2;
506 frame_y = top_baseline - insetAscent + ttoD2;
507 frame_w = last_width - TEXT_TO_INSET_OFFSET;
508 frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
509 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
511 frame_is_visible = true;
516 void InsetText::clearFrame(Painter & pain, bool cleared) const
518 if (frame_is_visible) {
520 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
523 frame_is_visible = false;
528 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
531 if (reinit && owner()) {
533 owner()->update(bv, font, true);
538 if (reinit || need_update == INIT) {
542 owner()->update(bv, font, true);
546 if (the_locking_inset) {
547 inset_x = cx(bv) - top_x + drawTextXOffset;
548 inset_y = cy(bv) + drawTextYOffset;
549 the_locking_inset->update(bv, font, reinit);
558 int oldw = insetWidth;
559 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
560 if (oldw != insetWidth) {
569 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
572 lt->updateInset(bv, the_locking_inset);
574 if (lt->status() == LyXText::NEED_MORE_REFRESH)
582 void InsetText::setUpdateStatus(BufferView * bv, int what) const
590 // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
591 // if we don't break row so that we only have one row to update!
592 if ((lt->status() == LyXText::NEED_MORE_REFRESH) ||
594 (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
597 } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
598 need_update |= CURSOR_PAR;
601 // this to not draw a selection when we redraw all of it!
602 if (need_update & CURSOR && !(need_update & SELECTION)) {
603 if (lt->selection.set())
605 lt->clearSelection();
612 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
620 setUpdateStatus(bv, what);
621 if (((need_update != CURSOR) && (need_update != NONE)) ||
622 (lt->status() != LyXText::UNCHANGED) || lt->selection.set())
624 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
626 if (need_update == CURSOR)
628 bv->owner()->showState();
629 if (old_par != cpar(bv)) {
630 bv->owner()->setLayout(cpar(bv)->getLayout());
638 string const InsetText::editMessage() const
640 return _("Opened Text Inset");
644 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
646 UpdatableInset::edit(bv, x, y, button);
648 if (!bv->lockInset(this)) {
649 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
653 the_locking_inset = 0;
654 inset_pos = inset_x = inset_y = 0;
655 inset_boundary = false;
658 int tmp_y = (y < 0) ? 0 : y;
665 if (!checkAndActivateInset(bv, x, tmp_y, button))
666 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
668 lt->clearSelection();
671 updateLocal(bv, CURSOR, false);
673 // If the inset is empty set the language of the current font to the
674 // language to the surronding text (if different).
675 if (par->size() == 0 && !par->next() &&
676 bv->getParentLanguage(this) != lt->current_font.language()) {
677 LyXFont font(LyXFont::ALL_IGNORE);
678 font.setLanguage(bv->getParentLanguage(this));
679 setFont(bv, font, false);
686 void InsetText::edit(BufferView * bv, bool front)
688 UpdatableInset::edit(bv, front);
690 if (!bv->lockInset(this)) {
691 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
695 the_locking_inset = 0;
696 inset_pos = inset_x = inset_y = 0;
697 inset_boundary = false;
706 lt->setCursor(bv, par, 0);
711 // int const pos = (p->size() ? p->size()-1 : p->size());
712 lt->setCursor(bv, p, p->size());
714 lt->clearSelection();
717 updateLocal(bv, CURSOR, false);
719 // If the inset is empty set the language of the current font to the
720 // language to the surronding text (if different).
721 if (par->size() == 0 && !par->next() &&
722 bv->getParentLanguage(this) != lt->current_font.language()) {
723 LyXFont font(LyXFont::ALL_IGNORE);
724 font.setLanguage(bv->getParentLanguage(this));
725 setFont(bv, font, false);
732 void InsetText::insetUnlock(BufferView * bv)
734 if (the_locking_inset) {
735 the_locking_inset->insetUnlock(bv);
736 the_locking_inset = 0;
739 no_selection = false;
742 if (drawFrame_ == LOCKED)
743 code = CURSOR|CLEAR_FRAME;
751 if (lt->selection.set()) {
752 lt->clearSelection();
754 } else if (owner()) {
755 bv->owner()->setLayout(owner()->getLyXText(bv)
756 ->cursor.par()->getLayout());
758 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
759 // hack for deleteEmptyParMech
760 lt->setCursor(bv, par, 0);
761 updateLocal(bv, code, false);
767 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
769 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
773 if (inset == cpar(bv)->getInset(cpos(bv))) {
774 lyxerr[Debug::INSETS] << "OK" << endl;
775 the_locking_inset = inset;
776 inset_x = cx(bv) - top_x + drawTextXOffset;
777 inset_y = cy(bv) + drawTextYOffset;
778 inset_pos = cpos(bv);
779 inset_par = cpar(bv);
780 inset_boundary = cboundary(bv);
781 updateLocal(bv, CURSOR, false);
783 } else if (the_locking_inset && (the_locking_inset == inset)) {
784 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
785 lyxerr[Debug::INSETS] << "OK" << endl;
786 inset_x = cx(bv) - top_x + drawTextXOffset;
787 inset_y = cy(bv) + drawTextYOffset;
789 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
791 } else if (the_locking_inset) {
792 lyxerr[Debug::INSETS] << "MAYBE" << endl;
793 return the_locking_inset->lockInsetInInset(bv, inset);
795 lyxerr[Debug::INSETS] << "NOT OK" << endl;
800 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
803 if (!the_locking_inset)
805 if (the_locking_inset == inset) {
806 the_locking_inset->insetUnlock(bv);
807 getLyXText(bv)->updateInset(bv, inset);
808 the_locking_inset = 0;
810 moveRight(bv, false);
811 old_par = 0; // force layout setting
815 updateLocal(bv, CURSOR, false);
818 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
822 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
824 if (!the_locking_inset)
826 if (the_locking_inset != inset) {
827 getLyXText(bv)->updateInset(bv, the_locking_inset);
828 setUpdateStatus(bv, CURSOR_PAR);
829 return the_locking_inset->updateInsetInInset(bv, inset);
831 if (getLyXText(bv)->updateInset(bv, inset))
832 updateLocal(bv, CURSOR_PAR, false);
833 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
834 inset_x = cx(bv) - top_x + drawTextXOffset;
835 inset_y = cy(bv) + drawTextYOffset;
841 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
845 int tmp_x = x - drawTextXOffset;
846 int tmp_y = y + insetAscent - getLyXText(bv)->first;
847 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
850 if (the_locking_inset) {
851 if (the_locking_inset == inset) {
852 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
853 no_selection = false;
856 // otherwise unlock the_locking_inset and lock the new inset
857 the_locking_inset->insetUnlock(bv);
858 inset_x = cx(bv) - top_x + drawTextXOffset;
859 inset_y = cy(bv) + drawTextYOffset;
860 the_locking_inset = static_cast<UpdatableInset*>(inset);
861 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
862 inset->edit(bv, x - inset_x, y - inset_y, button);
863 if (the_locking_inset)
864 updateLocal(bv, CURSOR, false);
865 no_selection = false;
868 // otherwise only unlock the_locking_inset
869 the_locking_inset->insetUnlock(bv);
870 the_locking_inset = 0;
872 if (bv->theLockingInset()) {
873 if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
874 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
875 inset_x = cx(bv) - top_x + drawTextXOffset;
876 inset_y = cy(bv) + drawTextYOffset;
877 inset_pos = cpos(bv);
878 inset_par = cpar(bv);
879 inset_boundary = cboundary(bv);
880 the_locking_inset = uinset;
881 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
883 uinset->edit(bv, x - inset_x, y - inset_y, 0);
884 if (the_locking_inset)
885 updateLocal(bv, CURSOR, false);
886 no_selection = false;
890 if (!inset) { // && (button == 2)) {
891 bool paste_internally = false;
892 if ((button == 2) && getLyXText(bv)->selection.set()) {
893 localDispatch(bv, LFUN_COPY, "");
894 paste_internally = true;
901 lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent);
902 if (lt->selection.set()) {
903 lt->clearSelection();
904 updateLocal(bv, FULL, false);
906 lt->clearSelection();
908 bv->owner()->setLayout(cpar(bv)->getLayout());
910 // Insert primary selection with middle mouse
911 // if there is a local selection in the current buffer,
914 if (paste_internally)
915 localDispatch(bv, LFUN_PASTE, "");
917 localDispatch(bv, LFUN_PASTESELECTION,
924 no_selection = false;
928 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
930 UpdatableInset * inset = 0;
932 if (the_locking_inset) {
933 the_locking_inset->insetButtonRelease(bv,
934 x - inset_x, y - inset_y,
937 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
938 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
939 if (inset->editable() == Inset::HIGHLY_EDITABLE) {
940 inset->insetButtonRelease(bv,
942 y - inset_y, button);
944 inset_x = cx(bv) - top_x + drawTextXOffset;
945 inset_y = cy(bv) + drawTextYOffset;
946 inset->insetButtonRelease(bv,
948 y - inset_y, button);
950 x - inset_x, y - inset_y, button);
952 updateLocal(bv, CURSOR_PAR, false);
955 no_selection = false;
959 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
963 if (the_locking_inset) {
964 the_locking_inset->insetMotionNotify(bv, x - inset_x,
968 LyXText * t = getLyXText(bv);
970 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
972 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
973 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
974 updateLocal(bv, SELECTION, false);
979 void InsetText::insetKeyPress(XKeyEvent * xke)
981 if (the_locking_inset) {
982 the_locking_inset->insetKeyPress(xke);
988 UpdatableInset::RESULT
989 InsetText::localDispatch(BufferView * bv,
990 kb_action action, string const & arg)
992 bool was_empty = par->size() == 0 && !par->next();
993 no_selection = false;
994 UpdatableInset::RESULT
995 result= UpdatableInset::localDispatch(bv, action, arg);
996 if (result != UNDISPATCHED) {
1000 result = DISPATCHED;
1001 if ((action < 0) && arg.empty())
1004 if (the_locking_inset) {
1005 result = the_locking_inset->localDispatch(bv, action, arg);
1006 if (result == DISPATCHED_NOUPDATE)
1008 else if (result == DISPATCHED) {
1009 updateLocal(bv, CURSOR_PAR, false);
1011 } else if (result == FINISHED) {
1012 bool dispatched = false;
1014 case LFUN_UNKNOWN_ACTION:
1015 case LFUN_BREAKPARAGRAPH:
1016 case LFUN_BREAKLINE:
1017 moveRightIntern(bv, false, false);
1020 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1021 moveRightIntern(bv, false, false);
1025 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1026 moveRightIntern(bv, false, false);
1032 the_locking_inset = 0;
1037 hideInsetCursor(bv);
1040 lt = getLyXText(bv);
1045 case LFUN_SELFINSERT:
1046 if (bv->buffer()->isReadonly()) {
1047 // setErrorMessage(N_("Document is read only"));
1051 /* Automatically delete the currently selected
1052 * text and replace it with what is being
1053 * typed in now. Depends on lyxrc settings
1054 * "auto_region_delete", which defaults to
1057 setUndo(bv, Undo::INSERT,
1058 lt->cursor.par(), lt->cursor.par()->next());
1060 if (lyxrc.auto_region_delete) {
1061 if (lt->selection.set()) {
1062 lt->cutSelection(bv, false);
1065 lt->clearSelection();
1066 for (string::size_type i = 0; i < arg.length(); ++i) {
1067 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1070 lt->selection.cursor = lt->cursor;
1071 updateLocal(bv, CURSOR_PAR, true);
1072 result = DISPATCHED_NOUPDATE;
1074 // --- Cursor Movements -----------------------------------
1077 moveRight(bv, false, true);
1078 lt->setSelection(bv);
1079 updateLocal(bv, SELECTION, false);
1082 result = moveRight(bv);
1084 updateLocal(bv, CURSOR, false);
1088 moveLeft(bv, false, true);
1089 lt->setSelection(bv);
1090 updateLocal(bv, SELECTION, false);
1094 result = moveLeft(bv);
1095 updateLocal(bv, CURSOR, false);
1100 lt->setSelection(bv);
1101 updateLocal(bv, SELECTION, false);
1105 result = moveDown(bv);
1106 updateLocal(bv, CURSOR, false);
1111 lt->setSelection(bv);
1112 updateLocal(bv, SELECTION, false);
1116 result = moveUp(bv);
1117 updateLocal(bv, CURSOR, false);
1122 updateLocal(bv, CURSOR, false);
1126 updateLocal(bv, CURSOR, false);
1128 case LFUN_BACKSPACE: {
1129 setUndo(bv, Undo::DELETE,
1130 lt->cursor.par(), lt->cursor.par()->next());
1131 if (lt->selection.set())
1132 lt->cutSelection(bv);
1135 updateLocal(bv, CURSOR_PAR, true);
1140 setUndo(bv, Undo::DELETE,
1141 lt->cursor.par(), lt->cursor.par()->next());
1142 if (lt->selection.set()) {
1143 lt->cutSelection(bv);
1147 updateLocal(bv, CURSOR_PAR, true);
1152 setUndo(bv, Undo::DELETE,
1153 lt->cursor.par(), lt->cursor.par()->next());
1154 lt->cutSelection(bv);
1155 updateLocal(bv, CURSOR_PAR, true);
1161 lt->copySelection(bv);
1162 updateLocal(bv, CURSOR_PAR, false);
1164 case LFUN_PASTESELECTION:
1166 string const clip(bv->getClipboard());
1170 if (arg == "paragraph") {
1171 lt->insertStringAsParagraphs(bv, clip);
1173 lt->insertStringAsLines(bv, clip);
1175 updateLocal(bv, CURSOR_PAR, true);
1179 if (!autoBreakRows) {
1181 if (CutAndPaste::nrOfParagraphs() > 1) {
1182 WriteAlert(_("Impossible operation"),
1183 _("Cannot include more than one paragraph!"),
1188 setUndo(bv, Undo::INSERT,
1189 lt->cursor.par(), lt->cursor.par()->next());
1190 lt->pasteSelection(bv);
1191 updateLocal(bv, CURSOR_PAR, true);
1195 case LFUN_BREAKPARAGRAPH:
1196 if (!autoBreakRows) {
1197 result = DISPATCHED;
1200 lt->breakParagraph(bv, 0);
1201 updateLocal(bv, FULL, true);
1203 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1204 if (!autoBreakRows) {
1205 result = DISPATCHED;
1208 lt->breakParagraph(bv, 1);
1209 updateLocal(bv, FULL, true);
1212 case LFUN_BREAKLINE: {
1213 if (!autoBreakRows) {
1214 result = DISPATCHED;
1217 setUndo(bv, Undo::INSERT,
1218 lt->cursor.par(), lt->cursor.par()->next());
1219 lt->insertChar(bv, Paragraph::META_NEWLINE);
1220 updateLocal(bv, CURSOR_PAR, true);
1225 // do not set layouts on non breakable textinsets
1226 if (autoBreakRows) {
1227 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1229 // Derive layout number from given argument (string)
1230 // and current buffer's textclass (number). */
1231 LyXTextClassList::ClassList::size_type tclass =
1232 bv->buffer()->params.textclass;
1233 std::pair <bool, LyXTextClass::size_type> layout =
1234 textclasslist.NumberOfLayout(tclass, arg);
1236 // If the entry is obsolete, use the new one instead.
1238 string obs = textclasslist.Style(tclass,layout.second).
1241 layout = textclasslist.NumberOfLayout(tclass, obs);
1244 // see if we found the layout number:
1245 if (!layout.first) {
1246 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1247 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1251 if (cur_layout != layout.second) {
1252 cur_layout = layout.second;
1253 lt->setLayout(bv, layout.second);
1254 bv->owner()->setLayout(cpar(bv)->getLayout());
1255 updateLocal(bv, CURSOR_PAR, true);
1258 // reset the layout box
1259 bv->owner()->setLayout(cpar(bv)->getLayout());
1262 case LFUN_PARAGRAPH_SPACING:
1263 // This one is absolutely not working. When fiddling with this
1264 // it also seems to me that the paragraphs inside the insettext
1265 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1267 Paragraph * par = lt->cursor.par();
1268 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1269 float cur_value = 1.0;
1270 if (cur_spacing == Spacing::Other) {
1271 cur_value = par->params().spacing().getValue();
1274 istringstream istr(arg.c_str());
1277 Spacing::Space new_spacing = cur_spacing;
1278 float new_value = cur_value;
1280 lyxerr << "Missing argument to `paragraph-spacing'"
1282 } else if (tmp == "single") {
1283 new_spacing = Spacing::Single;
1284 } else if (tmp == "onehalf") {
1285 new_spacing = Spacing::Onehalf;
1286 } else if (tmp == "double") {
1287 new_spacing = Spacing::Double;
1288 } else if (tmp == "other") {
1289 new_spacing = Spacing::Other;
1292 lyxerr << "new_value = " << tmpval << endl;
1295 } else if (tmp == "default") {
1296 new_spacing = Spacing::Default;
1298 lyxerr << _("Unknown spacing argument: ")
1301 if (cur_spacing != new_spacing || cur_value != new_value) {
1302 par->params().spacing(Spacing(new_spacing, new_value));
1303 updateLocal(bv, CURSOR_PAR, true);
1309 if (!bv->Dispatch(action, arg))
1310 result = UNDISPATCHED;
1314 /// If the action has deleted all text in the inset, we need to change the
1315 // language to the language of the surronding text.
1316 if (!was_empty && par->size() == 0 && !par->next()) {
1317 LyXFont font(LyXFont::ALL_IGNORE);
1318 font.setLanguage(bv->getParentLanguage(this));
1319 setFont(bv, font, false);
1322 if (result < FINISHED) {
1323 showInsetCursor(bv);
1325 bv->unlockInset(this);
1332 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1335 buf->latexParagraphs(os, par, 0, texrow);
1336 return texrow.rows();
1340 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1342 Paragraph * p = par;
1343 unsigned int lines = 0;
1346 string const tmp = buf->asciiParagraph(p, linelen);
1347 lines += countChar(tmp, '\n');
1355 int InsetText::docbook(Buffer const * buf, ostream & os) const
1357 Paragraph * p = par;
1358 unsigned int lines = 0;
1363 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1371 void InsetText::validate(LaTeXFeatures & features) const
1373 Paragraph * p = par;
1375 p->validate(features);
1381 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1383 if (textclasslist.Style(buf->params.textclass,
1384 p->getLayout()).labeltype != LABEL_MANUAL)
1387 return p->beginningOfMainBody();
1391 void InsetText::getCursorPos(BufferView * bv,
1392 int & x, int & y) const
1394 if (the_locking_inset) {
1395 the_locking_inset->getCursorPos(bv, x, y);
1403 unsigned int InsetText::insetInInsetY()
1405 if (!the_locking_inset)
1408 return (inset_y + the_locking_inset->insetInInsetY());
1412 void InsetText::toggleInsetCursor(BufferView * bv)
1414 if (the_locking_inset) {
1415 the_locking_inset->toggleInsetCursor(bv);
1419 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1421 int const asc = lyxfont::maxAscent(font);
1422 int const desc = lyxfont::maxDescent(font);
1424 if (isCursorVisible())
1425 bv->hideLockedInsetCursor();
1427 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1428 toggleCursorVisible();
1432 void InsetText::showInsetCursor(BufferView * bv, bool show)
1434 if (the_locking_inset) {
1435 the_locking_inset->showInsetCursor(bv, show);
1438 if (!isCursorVisible()) {
1439 LyXFont const font =
1440 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1442 int const asc = lyxfont::maxAscent(font);
1443 int const desc = lyxfont::maxDescent(font);
1445 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1447 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1448 setCursorVisible(true);
1453 void InsetText::hideInsetCursor(BufferView * bv)
1455 if (isCursorVisible()) {
1456 bv->hideLockedInsetCursor();
1457 setCursorVisible(false);
1459 if (the_locking_inset)
1460 the_locking_inset->hideInsetCursor(bv);
1464 void InsetText::fitInsetCursor(BufferView * bv) const
1466 if (the_locking_inset) {
1467 the_locking_inset->fitInsetCursor(bv);
1470 LyXFont const font =
1471 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1473 int const asc = lyxfont::maxAscent(font);
1474 int const desc = lyxfont::maxDescent(font);
1476 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1480 UpdatableInset::RESULT
1481 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1483 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1484 return moveLeftIntern(bv, false, activate_inset, selecting);
1486 return moveRightIntern(bv, false, activate_inset, selecting);
1490 UpdatableInset::RESULT
1491 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1493 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1494 return moveRightIntern(bv, true, activate_inset, selecting);
1496 return moveLeftIntern(bv, true, activate_inset, selecting);
1500 UpdatableInset::RESULT
1501 InsetText::moveRightIntern(BufferView * bv, bool behind,
1502 bool activate_inset, bool selecting)
1504 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1505 return FINISHED_RIGHT;
1506 if (activate_inset && checkAndActivateInset(bv, behind))
1508 getLyXText(bv)->cursorRight(bv);
1510 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1511 return DISPATCHED_NOUPDATE;
1515 UpdatableInset::RESULT
1516 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1517 bool activate_inset, bool selecting)
1519 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1521 getLyXText(bv)->cursorLeft(bv);
1523 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1524 if (activate_inset && checkAndActivateInset(bv, behind))
1526 return DISPATCHED_NOUPDATE;
1530 UpdatableInset::RESULT
1531 InsetText::moveUp(BufferView * bv)
1533 if (!crow(bv)->previous())
1535 getLyXText(bv)->cursorUp(bv);
1536 return DISPATCHED_NOUPDATE;
1540 UpdatableInset::RESULT
1541 InsetText::moveDown(BufferView * bv)
1543 if (!crow(bv)->next())
1544 return FINISHED_DOWN;
1545 getLyXText(bv)->cursorDown(bv);
1546 return DISPATCHED_NOUPDATE;
1550 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1552 if (the_locking_inset) {
1553 if (the_locking_inset->insetAllowed(inset))
1554 return the_locking_inset->insertInset(bv, inset);
1557 inset->setOwner(this);
1558 hideInsetCursor(bv);
1562 lt = getLyXText(bv);
1565 lt->insertInset(bv, inset);
1567 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1568 (cpar(bv)->getInset(cpos(bv)) != inset))
1572 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1573 showInsetCursor(bv);
1580 bool InsetText::insetAllowed(Inset::Code code) const
1582 if (the_locking_inset)
1583 return the_locking_inset->insetAllowed(code);
1588 UpdatableInset * InsetText::getLockingInset() const
1590 return the_locking_inset ? the_locking_inset->getLockingInset() :
1591 const_cast<InsetText *>(this);
1595 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1599 if (the_locking_inset)
1600 return the_locking_inset->getFirstLockingInsetOfType(c);
1605 bool InsetText::showInsetDialog(BufferView * bv) const
1607 if (the_locking_inset)
1608 return the_locking_inset->showInsetDialog(bv);
1613 std::vector<string> const InsetText::getLabelList() const
1615 std::vector<string> label_list;
1617 Paragraph * tpar = par;
1619 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1620 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1621 for (; beg != end; ++beg) {
1622 std::vector<string> const l = (*beg)->getLabelList();
1623 label_list.insert(label_list.end(), l.begin(), l.end());
1625 tpar = tpar->next();
1631 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1634 if (the_locking_inset) {
1635 the_locking_inset->setFont(bv, font, toggleall, selectall);
1638 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1639 getLyXText(bv)->setFont(bv, font, toggleall);
1644 lt = getLyXText(bv);
1647 if (lt->selection.set()) {
1648 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1652 lt->toggleFree(bv, font, toggleall);
1654 lt->clearSelection();
1656 if (selectall || lt->selection.set())
1657 updateLocal(bv, FULL, true);
1659 updateLocal(bv, CURSOR_PAR, true);
1665 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1667 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1671 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1672 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1674 LyXFont const font =
1675 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1677 x = inset->width(bv, font);
1678 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1681 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1683 //inset_x = cx(bv) - top_x + drawTextXOffset;
1684 //inset_y = cy(bv) + drawTextYOffset;
1685 inset->edit(bv, x, y, 0);
1686 if (!the_locking_inset)
1688 updateLocal(bv, CURSOR, false);
1695 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1698 x -= drawTextXOffset;
1700 int dummyy = y + insetAscent;
1701 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1708 inset_x = cx(bv) - top_x + drawTextXOffset;
1709 inset_y = cy(bv) + drawTextYOffset;
1710 inset->edit(bv, x - inset_x, y - inset_y, button);
1711 if (!the_locking_inset)
1713 updateLocal(bv, CURSOR, false);
1720 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1723 int w = UpdatableInset::getMaxWidth(bv, inset);
1728 w = w - top_x + owner()->x();
1731 w -= (2 * TEXT_TO_INSET_OFFSET);
1734 return UpdatableInset::getMaxWidth(bv, inset);
1739 void InsetText::setParagraphData(Paragraph * p)
1741 // we have to unlock any locked inset otherwise we're in troubles
1742 the_locking_inset = 0;
1744 Paragraph * tmp = par->next();
1749 par = new Paragraph(*p, false);
1750 par->setInsetOwner(this);
1751 Paragraph * np = par;
1754 np->next(new Paragraph(*p, false));
1755 np->next()->previous(np);
1757 np->setInsetOwner(this);
1763 void InsetText::setText(string const & data)
1766 LyXFont font(LyXFont::ALL_SANE);
1767 for (unsigned int i=0; i < data.length(); ++i)
1768 par->insertChar(i, data[i], font);
1772 void InsetText::setAutoBreakRows(bool flag)
1774 if (flag != autoBreakRows) {
1775 autoBreakRows = flag;
1783 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1785 if (how != drawFrame_) {
1788 updateLocal(bv, DRAW_FRAME, false);
1793 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1795 if (frame_color != col) {
1798 updateLocal(bv, DRAW_FRAME, false);
1803 int InsetText::cx(BufferView * bv) const
1807 lt = getLyXText(bv);
1810 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1811 if (the_locking_inset) {
1812 LyXFont font = lt->getFont(bv->buffer(),
1815 if (font.isVisibleRightToLeft())
1816 x -= the_locking_inset->width(bv, font);
1824 int InsetText::cy(BufferView * bv) const
1827 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1831 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1833 return getLyXText(bv)->cursor.pos();
1837 Paragraph * InsetText::cpar(BufferView * bv) const
1839 return getLyXText(bv)->cursor.par();
1843 bool InsetText::cboundary(BufferView * bv) const
1845 return getLyXText(bv)->cursor.boundary();
1849 Row * InsetText::crow(BufferView * bv) const
1851 return getLyXText(bv)->cursor.row();
1855 LyXText * InsetText::getLyXText(BufferView const * lbv,
1856 bool const recursive) const
1858 if (!recursive && (cached_bview == lbv))
1859 return cached_text.get();
1861 // Super UGLY! (Lgb)
1862 BufferView * bv = const_cast<BufferView *>(lbv);
1865 Cache::iterator it = cache.find(bv);
1867 if (it != cache.end()) {
1871 resizeLyXText(do_resize);
1872 if (lt || !it->second.remove) {
1873 lyx::Assert(it->second.text.get());
1874 cached_text = it->second.text;
1875 if (recursive && the_locking_inset) {
1876 return the_locking_inset->getLyXText(bv, true);
1878 return cached_text.get();
1879 } else if (it->second.remove) {
1881 saveLyXTextState(it->second.text.get());
1888 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1889 cached_text->init(bv);
1890 restoreLyXTextState(bv, cached_text.get());
1892 cache.insert(make_pair(bv, cached_text));
1894 if (the_locking_inset && recursive) {
1895 return the_locking_inset->getLyXText(bv);
1897 return cached_text.get();
1901 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1905 Cache::iterator it = cache.find(bv);
1907 if (it == cache.end()) {
1911 lyx::Assert(it->second.text.get());
1913 it->second.remove = true;
1915 /// then remove all LyXText in text-insets
1916 Paragraph * p = par;
1917 for (; p; p = p->next()) {
1918 p->deleteInsetsLyXText(bv);
1924 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1927 // we cannot resize this because we are in use!
1928 // so do this on the next possible getLyXText()
1933 // lyxerr << "InsetText::resizeLyXText\n";
1934 if (!par->next() && !par->size()) // no data, resize not neccessary!
1936 // one endless line, resize normally not necessary
1937 if (!force && getMaxWidth(bv, this) < 0)
1940 Cache::iterator it = cache.find(bv);
1941 if (it == cache.end()) {
1944 lyx::Assert(it->second.text.get());
1946 LyXText * t = it->second.text.get();
1947 saveLyXTextState(t);
1948 for (Paragraph * p = par; p; p = p->next()) {
1949 p->resizeInsetsLyXText(bv);
1952 restoreLyXTextState(bv, t);
1953 if (the_locking_inset) {
1954 inset_x = cx(bv) - top_x + drawTextXOffset;
1955 inset_y = cy(bv) + drawTextYOffset;
1959 t->first = bv->screen()->topCursorVisible(t);
1962 updateLocal(bv, FULL, false);
1963 // this will scroll the screen such that the cursor becomes visible
1964 bv->updateScrollbar();
1966 need_update |= FULL;
1971 void InsetText::reinitLyXText() const
1974 // we cannot resize this because we are in use!
1975 // so do this on the next possible getLyXText()
1981 // lyxerr << "InsetText::reinitLyXText\n";
1982 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1983 lyx::Assert(it->second.text.get());
1985 LyXText * t = it->second.text.get();
1986 BufferView * bv = it->first;
1988 saveLyXTextState(t);
1989 for (Paragraph * p = par; p; p = p->next()) {
1990 p->resizeInsetsLyXText(bv);
1993 restoreLyXTextState(bv, t);
1994 if (the_locking_inset) {
1995 inset_x = cx(bv) - top_x + drawTextXOffset;
1996 inset_y = cy(bv) + drawTextYOffset;
1999 t->first = bv->screen()->topCursorVisible(t);
2002 updateLocal(bv, FULL, false);
2003 // this will scroll the screen such that the cursor becomes visible
2004 bv->updateScrollbar();
2012 void InsetText::removeNewlines()
2014 for (Paragraph * p = par; p; p = p->next()) {
2015 for (int i = 0; i < p->size(); ++i) {
2016 if (p->getChar(i) == Paragraph::META_NEWLINE)
2023 bool InsetText::nodraw() const
2025 if (the_locking_inset)
2026 return the_locking_inset->nodraw();
2027 return UpdatableInset::nodraw();
2031 int InsetText::scroll(bool recursive) const
2033 int sx = UpdatableInset::scroll(false);
2035 if (recursive && the_locking_inset)
2036 sx += the_locking_inset->scroll(recursive);
2042 bool InsetText::doClearArea() const
2044 return !locked || (need_update & (FULL|INIT));
2048 void InsetText::selectAll(BufferView * bv)
2050 getLyXText(bv)->cursorTop(bv);
2051 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2052 getLyXText(bv)->cursorBottom(bv);
2053 getLyXText(bv)->setSelection(bv);
2057 void InsetText::clearSelection(BufferView * bv)
2059 getLyXText(bv)->clearSelection();
2063 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2066 int h = insetAscent + insetDescent;
2067 int ty = baseline - insetAscent;
2073 if ((ty + h) > pain.paperHeight())
2074 h = pain.paperHeight();
2075 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2076 w = pain.paperWidth();
2077 // w -= TEXT_TO_INSET_OFFSET;
2078 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2081 frame_is_visible = false;
2085 Paragraph * InsetText::getParFromID(int id) const
2088 Paragraph * result = par;
2089 Paragraph * ires = 0;
2090 while (result && result->id() != id) {
2091 if ((ires = result->getParFromID(id)))
2093 result = result->next();
2097 Paragraph * tmp = par;
2099 int tmp_id = tmp->id();
2100 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2101 if (tmp->id() == id) {
2104 Paragraph * tmp2 = tmp->getParFromID(id);
2115 Paragraph * InsetText::firstParagraph() const
2118 if (the_locking_inset)
2119 if ((result = the_locking_inset->firstParagraph()))
2125 Paragraph * InsetText::getFirstParagraph(int i) const
2127 return (i == 0) ? par : 0;
2131 LyXCursor const & InsetText::cursor(BufferView * bv) const
2133 if (the_locking_inset)
2134 return the_locking_inset->cursor(bv);
2135 return getLyXText(bv)->cursor;
2139 Paragraph * InsetText::paragraph() const
2145 void InsetText::paragraph(Paragraph * p)
2149 // we now have to update/redraw all instances
2150 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2155 // redraw myself when asked for
2160 Inset * InsetText::getInsetFromID(int id_arg) const
2163 return const_cast<InsetText *>(this);
2165 Paragraph * lp = par;
2168 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2169 en = lp->inset_iterator_end();
2172 if ((*it)->id() == id_arg)
2174 Inset * in = (*it)->getInsetFromID(id_arg);
2184 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2190 lt = getLyXText(bv);
2193 if (the_locking_inset) {
2194 str = the_locking_inset->selectNextWord(bv, value);
2201 #warning Dekel please have a look on this one RTL? (Jug)
2203 // we have to go on checking so move cusor to the right
2204 lt->cursor.pos(lt->cursor.pos() + 1);
2206 str = lt->selectNextWord(bv, value);
2208 bv->unlockInset(const_cast<InsetText *>(this));
2217 void InsetText::selectSelectedWord(BufferView * bv)
2219 if (the_locking_inset) {
2220 the_locking_inset->selectSelectedWord(bv);
2223 getLyXText(bv)->selectSelectedWord(bv);
2224 updateLocal(bv, SELECTION, false);
2228 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2230 if (the_locking_inset) {
2231 the_locking_inset->toggleSelection(bv, kill_selection);
2235 lt = getLyXText(bv);
2239 int x = top_x + TEXT_TO_INSET_OFFSET;
2242 Row * row = lt->getRowNearY(y);
2243 int y_offset = top_baseline - row->ascent_of_text();
2245 while ((row != 0) && ((y+row->height()) <= 0)) {
2252 if (need_update & SELECTION)
2254 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2260 bool InsetText::searchForward(BufferView * bv, string const & str,
2261 bool const & cs, bool const & mw)
2263 if (the_locking_inset) {
2264 if (the_locking_inset->searchForward(bv, str, cs, mw))
2268 lt = getLyXText(bv);
2271 Paragraph * lpar = lt->cursor.par();
2272 Paragraph::size_type pos = lt->cursor.pos();
2273 if (pos < lpar->size() - 1)
2277 lpar = lpar->next();
2282 // we have to unlock ourself in this function by default!
2283 bv->unlockInset(const_cast<InsetText *>(this));
2286 lt->setCursor(bv, lpar, pos);
2290 if (LyXFind(bv, str, true, true, cs , mw)) {
2293 // we have to unlock ourself in this function by default!
2294 bv->unlockInset(const_cast<InsetText *>(this));
2298 bool InsetText::searchBackward(BufferView * bv, string const & str,
2299 bool const & cs, bool const & mw)
2301 if (the_locking_inset)
2302 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2304 if (LyXFind(bv, str, false, true, cs, mw)) {
2307 // we have to unlock ourself in this function by default!
2308 bv->unlockInset(const_cast<InsetText *>(this));