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()) {
427 drawFrame(pain, cleared);
428 x += last_width; // was width(bv, f);
437 x += TEXT_TO_INSET_OFFSET;
440 Row * row = lt->getRowNearY(y);
441 int y_offset = baseline - row->ascent_of_text();
442 int ph = pain.paperHeight();
445 while ((row != 0) && ((y+row->height()) <= 0)) {
447 first += row->height();
453 if (cleared || (need_update&(INIT|FULL))) {
456 while ((row != 0) && (yf < ph)) {
457 lt->getVisibleRow(bv, y+y_offset, int(x), row,
463 } else if (!locked) {
464 if (need_update & CURSOR) {
465 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
466 lt->clearSelection();
467 lt->selection.cursor = lt->cursor;
469 bv->screen()->update(lt, bv, y_offset, int(x));
472 if (need_update & SELECTION) {
473 bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
474 } else if (need_update & CURSOR) {
475 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
476 lt->clearSelection();
477 lt->selection.cursor = lt->cursor;
479 bv->screen()->update(lt, bv, y_offset, int(x));
484 lt->status(bv, LyXText::UNCHANGED);
485 if ((need_update != CURSOR_PAR) &&
486 ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked))) {
487 drawFrame(pain, cleared);
488 } else if (need_update & CLEAR_FRAME) {
489 clearFrame(pain, cleared);
492 x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
494 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
496 } else if (need_update != INIT) {
505 void InsetText::drawFrame(Painter & pain, bool cleared) const
507 static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
508 if (!frame_is_visible || cleared) {
509 frame_x = top_x + ttoD2;
510 frame_y = top_baseline - insetAscent + ttoD2;
511 frame_w = last_width - TEXT_TO_INSET_OFFSET;
512 frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
513 pain.rectangle(frame_x, frame_y,
516 frame_is_visible = true;
521 void InsetText::clearFrame(Painter & pain, bool cleared) const
523 if (frame_is_visible) {
525 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
528 frame_is_visible = false;
533 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
536 if (reinit && owner()) {
538 owner()->update(bv, font, true);
543 if (reinit || need_update == INIT) {
547 owner()->update(bv, font, true);
551 if (the_locking_inset) {
552 inset_x = cx(bv) - top_x + drawTextXOffset;
553 inset_y = cy(bv) + drawTextYOffset;
554 the_locking_inset->update(bv, font, reinit);
563 int oldw = insetWidth;
564 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
565 if (oldw != insetWidth) {
574 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
577 lt->updateInset(bv, the_locking_inset);
579 if (lt->status() == LyXText::NEED_MORE_REFRESH)
587 void InsetText::setUpdateStatus(BufferView * bv, int what) const
595 // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
596 // if we don't break row so that we only have one row to update!
597 if ((lt->status() == LyXText::NEED_MORE_REFRESH) ||
599 (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
602 } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
603 need_update |= CURSOR_PAR;
606 // this to not draw a selection when we redraw all of it!
607 if (need_update & CURSOR && !(need_update & SELECTION)) {
608 if (lt->selection.set())
610 lt->clearSelection();
617 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
625 setUpdateStatus(bv, what);
626 if (((need_update != CURSOR) && (need_update != NONE)) ||
627 (lt->status() != LyXText::UNCHANGED) || lt->selection.set())
629 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
631 if (need_update == CURSOR)
633 bv->owner()->showState();
634 if (old_par != cpar(bv)) {
635 bv->owner()->setLayout(cpar(bv)->getLayout());
643 string const InsetText::editMessage() const
645 return _("Opened Text Inset");
649 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
651 UpdatableInset::edit(bv, x, y, button);
653 if (!bv->lockInset(this)) {
654 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
658 the_locking_inset = 0;
659 inset_pos = inset_x = inset_y = 0;
660 inset_boundary = false;
663 int tmp_y = (y < 0) ? 0 : y;
670 if (!checkAndActivateInset(bv, x, tmp_y, button))
671 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
673 lt->clearSelection();
676 updateLocal(bv, CURSOR, false);
678 // If the inset is empty set the language of the current font to the
679 // language to the surronding text (if different).
680 if (par->size() == 0 && !par->next() &&
681 bv->getParentLanguage(this) != lt->current_font.language()) {
682 LyXFont font(LyXFont::ALL_IGNORE);
683 font.setLanguage(bv->getParentLanguage(this));
684 setFont(bv, font, false);
691 void InsetText::edit(BufferView * bv, bool front)
693 UpdatableInset::edit(bv, front);
695 if (!bv->lockInset(this)) {
696 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
700 the_locking_inset = 0;
701 inset_pos = inset_x = inset_y = 0;
702 inset_boundary = false;
711 lt->setCursor(bv, par, 0);
716 // int const pos = (p->size() ? p->size()-1 : p->size());
717 lt->setCursor(bv, p, p->size());
719 lt->clearSelection();
722 updateLocal(bv, CURSOR, false);
724 // If the inset is empty set the language of the current font to the
725 // language to the surronding text (if different).
726 if (par->size() == 0 && !par->next() &&
727 bv->getParentLanguage(this) != lt->current_font.language()) {
728 LyXFont font(LyXFont::ALL_IGNORE);
729 font.setLanguage(bv->getParentLanguage(this));
730 setFont(bv, font, false);
737 void InsetText::insetUnlock(BufferView * bv)
739 if (the_locking_inset) {
740 the_locking_inset->insetUnlock(bv);
741 the_locking_inset = 0;
744 no_selection = false;
747 if (drawFrame_ == LOCKED)
748 code = CURSOR|CLEAR_FRAME;
756 if (lt->selection.set()) {
757 lt->clearSelection();
759 } else if (owner()) {
760 bv->owner()->setLayout(owner()->getLyXText(bv)
761 ->cursor.par()->getLayout());
763 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
764 // hack for deleteEmptyParMech
765 lt->setCursor(bv, par, 0);
766 updateLocal(bv, code, false);
772 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
774 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
778 if (inset == cpar(bv)->getInset(cpos(bv))) {
779 lyxerr[Debug::INSETS] << "OK" << endl;
780 the_locking_inset = inset;
781 inset_x = cx(bv) - top_x + drawTextXOffset;
782 inset_y = cy(bv) + drawTextYOffset;
783 inset_pos = cpos(bv);
784 inset_par = cpar(bv);
785 inset_boundary = cboundary(bv);
786 updateLocal(bv, CURSOR, false);
788 } else if (the_locking_inset && (the_locking_inset == inset)) {
789 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
790 lyxerr[Debug::INSETS] << "OK" << endl;
791 inset_x = cx(bv) - top_x + drawTextXOffset;
792 inset_y = cy(bv) + drawTextYOffset;
794 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
796 } else if (the_locking_inset) {
797 lyxerr[Debug::INSETS] << "MAYBE" << endl;
798 return the_locking_inset->lockInsetInInset(bv, inset);
800 lyxerr[Debug::INSETS] << "NOT OK" << endl;
805 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
808 if (!the_locking_inset)
810 if (the_locking_inset == inset) {
811 the_locking_inset->insetUnlock(bv);
812 getLyXText(bv)->updateInset(bv, inset);
813 the_locking_inset = 0;
815 moveRight(bv, false);
816 old_par = 0; // force layout setting
820 updateLocal(bv, CURSOR, false);
823 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
827 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
829 if (!the_locking_inset)
831 if (the_locking_inset != inset) {
832 getLyXText(bv)->updateInset(bv, the_locking_inset);
833 setUpdateStatus(bv, CURSOR_PAR);
834 return the_locking_inset->updateInsetInInset(bv, inset);
836 if (getLyXText(bv)->updateInset(bv, inset))
837 updateLocal(bv, CURSOR_PAR, false);
838 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
839 inset_x = cx(bv) - top_x + drawTextXOffset;
840 inset_y = cy(bv) + drawTextYOffset;
846 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
850 int tmp_x = x - drawTextXOffset;
851 int tmp_y = y + insetAscent - getLyXText(bv)->first;
852 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
855 if (the_locking_inset) {
856 if (the_locking_inset == inset) {
857 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
858 no_selection = false;
861 // otherwise unlock the_locking_inset and lock the new inset
862 the_locking_inset->insetUnlock(bv);
863 inset_x = cx(bv) - top_x + drawTextXOffset;
864 inset_y = cy(bv) + drawTextYOffset;
865 the_locking_inset = static_cast<UpdatableInset*>(inset);
866 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
867 inset->edit(bv, x - inset_x, y - inset_y, button);
868 if (the_locking_inset)
869 updateLocal(bv, CURSOR, false);
870 no_selection = false;
873 // otherwise only unlock the_locking_inset
874 the_locking_inset->insetUnlock(bv);
875 the_locking_inset = 0;
877 if (bv->theLockingInset()) {
878 if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
879 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
880 inset_x = cx(bv) - top_x + drawTextXOffset;
881 inset_y = cy(bv) + drawTextYOffset;
882 inset_pos = cpos(bv);
883 inset_par = cpar(bv);
884 inset_boundary = cboundary(bv);
885 the_locking_inset = uinset;
886 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
888 uinset->edit(bv, x - inset_x, y - inset_y, 0);
889 if (the_locking_inset)
890 updateLocal(bv, CURSOR, false);
891 no_selection = false;
895 if (!inset) { // && (button == 2)) {
896 bool paste_internally = false;
897 if ((button == 2) && getLyXText(bv)->selection.set()) {
898 localDispatch(bv, LFUN_COPY, "");
899 paste_internally = true;
906 lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent);
907 if (lt->selection.set()) {
908 lt->clearSelection();
909 updateLocal(bv, FULL, false);
911 lt->clearSelection();
913 bv->owner()->setLayout(cpar(bv)->getLayout());
915 // Insert primary selection with middle mouse
916 // if there is a local selection in the current buffer,
919 if (paste_internally)
920 localDispatch(bv, LFUN_PASTE, "");
922 localDispatch(bv, LFUN_PASTESELECTION,
929 no_selection = false;
933 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
935 UpdatableInset * inset = 0;
937 if (the_locking_inset) {
938 the_locking_inset->insetButtonRelease(bv,
939 x - inset_x, y - inset_y,
942 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
943 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
944 if (inset->editable() == Inset::HIGHLY_EDITABLE) {
945 inset->insetButtonRelease(bv,
947 y - inset_y, button);
949 inset_x = cx(bv) - top_x + drawTextXOffset;
950 inset_y = cy(bv) + drawTextYOffset;
951 inset->insetButtonRelease(bv,
953 y - inset_y, button);
955 x - inset_x, y - inset_y, button);
957 updateLocal(bv, CURSOR_PAR, false);
960 no_selection = false;
964 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
968 if (the_locking_inset) {
969 the_locking_inset->insetMotionNotify(bv, x - inset_x,
973 LyXText * t = getLyXText(bv);
975 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
977 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
978 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
979 updateLocal(bv, SELECTION, false);
984 void InsetText::insetKeyPress(XKeyEvent * xke)
986 if (the_locking_inset) {
987 the_locking_inset->insetKeyPress(xke);
993 UpdatableInset::RESULT
994 InsetText::localDispatch(BufferView * bv,
995 kb_action action, string const & arg)
997 bool was_empty = par->size() == 0 && !par->next();
998 no_selection = false;
999 UpdatableInset::RESULT
1000 result= UpdatableInset::localDispatch(bv, action, arg);
1001 if (result != UNDISPATCHED) {
1005 result = DISPATCHED;
1006 if ((action < 0) && arg.empty())
1009 if (the_locking_inset) {
1010 result = the_locking_inset->localDispatch(bv, action, arg);
1011 if (result == DISPATCHED_NOUPDATE)
1013 else if (result == DISPATCHED) {
1014 updateLocal(bv, CURSOR_PAR, false);
1016 } else if (result >= FINISHED) {
1018 case FINISHED_RIGHT:
1019 moveRightIntern(bv, false, false);
1020 result = DISPATCHED;
1023 if ((result = moveUp(bv)) >= FINISHED) {
1024 updateLocal(bv, CURSOR, false);
1025 bv->unlockInset(this);
1029 if ((result = moveDown(bv)) >= FINISHED) {
1030 updateLocal(bv, CURSOR, false);
1031 bv->unlockInset(this);
1035 result = DISPATCHED;
1038 the_locking_inset = 0;
1039 #ifdef WITH_WARNINGS
1040 #warning I changed this to always return Dispatched maybe it is wrong (20011001 Jug)
1045 hideInsetCursor(bv);
1048 lt = getLyXText(bv);
1053 case LFUN_SELFINSERT:
1054 if (bv->buffer()->isReadonly()) {
1055 // setErrorMessage(N_("Document is read only"));
1059 /* Automatically delete the currently selected
1060 * text and replace it with what is being
1061 * typed in now. Depends on lyxrc settings
1062 * "auto_region_delete", which defaults to
1065 setUndo(bv, Undo::INSERT,
1066 lt->cursor.par(), lt->cursor.par()->next());
1068 if (lyxrc.auto_region_delete) {
1069 if (lt->selection.set()) {
1070 lt->cutSelection(bv, false);
1073 lt->clearSelection();
1074 for (string::size_type i = 0; i < arg.length(); ++i) {
1075 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1078 lt->selection.cursor = lt->cursor;
1079 updateLocal(bv, CURSOR_PAR, true);
1080 result = DISPATCHED_NOUPDATE;
1082 // --- Cursor Movements -----------------------------------
1085 moveRight(bv, false, true);
1086 lt->setSelection(bv);
1087 updateLocal(bv, SELECTION, false);
1090 result = moveRight(bv);
1092 updateLocal(bv, CURSOR, false);
1096 moveLeft(bv, false, true);
1097 lt->setSelection(bv);
1098 updateLocal(bv, SELECTION, false);
1102 result = moveLeft(bv);
1103 updateLocal(bv, CURSOR, false);
1108 lt->setSelection(bv);
1109 updateLocal(bv, SELECTION, false);
1113 result = moveDown(bv);
1114 updateLocal(bv, CURSOR, false);
1119 lt->setSelection(bv);
1120 updateLocal(bv, SELECTION, false);
1124 result = moveUp(bv);
1125 updateLocal(bv, CURSOR, false);
1130 updateLocal(bv, CURSOR, false);
1134 updateLocal(bv, CURSOR, false);
1136 case LFUN_BACKSPACE: {
1137 setUndo(bv, Undo::DELETE,
1138 lt->cursor.par(), lt->cursor.par()->next());
1139 if (lt->selection.set())
1140 lt->cutSelection(bv);
1143 updateLocal(bv, CURSOR_PAR, true);
1148 setUndo(bv, Undo::DELETE,
1149 lt->cursor.par(), lt->cursor.par()->next());
1150 if (lt->selection.set()) {
1151 lt->cutSelection(bv);
1155 updateLocal(bv, CURSOR_PAR, true);
1160 setUndo(bv, Undo::DELETE,
1161 lt->cursor.par(), lt->cursor.par()->next());
1162 lt->cutSelection(bv);
1163 updateLocal(bv, CURSOR_PAR, true);
1169 lt->copySelection(bv);
1170 updateLocal(bv, CURSOR_PAR, false);
1172 case LFUN_PASTESELECTION:
1174 string const clip(bv->getClipboard());
1178 if (arg == "paragraph") {
1179 lt->insertStringAsParagraphs(bv, clip);
1181 lt->insertStringAsLines(bv, clip);
1183 updateLocal(bv, CURSOR_PAR, true);
1187 if (!autoBreakRows) {
1189 if (CutAndPaste::nrOfParagraphs() > 1) {
1190 WriteAlert(_("Impossible operation"),
1191 _("Cannot include more than one paragraph!"),
1196 setUndo(bv, Undo::INSERT,
1197 lt->cursor.par(), lt->cursor.par()->next());
1198 lt->pasteSelection(bv);
1199 updateLocal(bv, CURSOR_PAR, true);
1203 case LFUN_BREAKPARAGRAPH:
1204 if (!autoBreakRows) {
1205 result = DISPATCHED;
1208 lt->breakParagraph(bv, 0);
1209 updateLocal(bv, FULL, true);
1211 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1212 if (!autoBreakRows) {
1213 result = DISPATCHED;
1216 lt->breakParagraph(bv, 1);
1217 updateLocal(bv, FULL, true);
1220 case LFUN_BREAKLINE: {
1221 if (!autoBreakRows) {
1222 result = DISPATCHED;
1225 setUndo(bv, Undo::INSERT,
1226 lt->cursor.par(), lt->cursor.par()->next());
1227 lt->insertChar(bv, Paragraph::META_NEWLINE);
1228 updateLocal(bv, CURSOR_PAR, true);
1233 // do not set layouts on non breakable textinsets
1234 if (autoBreakRows) {
1235 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1237 // Derive layout number from given argument (string)
1238 // and current buffer's textclass (number). */
1239 LyXTextClassList::ClassList::size_type tclass =
1240 bv->buffer()->params.textclass;
1241 std::pair <bool, LyXTextClass::size_type> layout =
1242 textclasslist.NumberOfLayout(tclass, arg);
1244 // If the entry is obsolete, use the new one instead.
1246 string obs = textclasslist.Style(tclass,layout.second).
1249 layout = textclasslist.NumberOfLayout(tclass, obs);
1252 // see if we found the layout number:
1253 if (!layout.first) {
1254 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1255 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1259 if (cur_layout != layout.second) {
1260 cur_layout = layout.second;
1261 lt->setLayout(bv, layout.second);
1262 bv->owner()->setLayout(cpar(bv)->getLayout());
1263 updateLocal(bv, CURSOR_PAR, true);
1266 // reset the layout box
1267 bv->owner()->setLayout(cpar(bv)->getLayout());
1270 case LFUN_PARAGRAPH_SPACING:
1271 // This one is absolutely not working. When fiddling with this
1272 // it also seems to me that the paragraphs inside the insettext
1273 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1275 Paragraph * par = lt->cursor.par();
1276 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1277 float cur_value = 1.0;
1278 if (cur_spacing == Spacing::Other) {
1279 cur_value = par->params().spacing().getValue();
1282 istringstream istr(arg.c_str());
1285 Spacing::Space new_spacing = cur_spacing;
1286 float new_value = cur_value;
1288 lyxerr << "Missing argument to `paragraph-spacing'"
1290 } else if (tmp == "single") {
1291 new_spacing = Spacing::Single;
1292 } else if (tmp == "onehalf") {
1293 new_spacing = Spacing::Onehalf;
1294 } else if (tmp == "double") {
1295 new_spacing = Spacing::Double;
1296 } else if (tmp == "other") {
1297 new_spacing = Spacing::Other;
1300 lyxerr << "new_value = " << tmpval << endl;
1303 } else if (tmp == "default") {
1304 new_spacing = Spacing::Default;
1306 lyxerr << _("Unknown spacing argument: ")
1309 if (cur_spacing != new_spacing || cur_value != new_value) {
1310 par->params().spacing(Spacing(new_spacing, new_value));
1311 updateLocal(bv, CURSOR_PAR, true);
1317 if (!bv->Dispatch(action, arg))
1318 result = UNDISPATCHED;
1322 /// If the action has deleted all text in the inset, we need to change the
1323 // language to the language of the surronding text.
1324 if (!was_empty && par->size() == 0 && !par->next()) {
1325 LyXFont font(LyXFont::ALL_IGNORE);
1326 font.setLanguage(bv->getParentLanguage(this));
1327 setFont(bv, font, false);
1330 if (result < FINISHED) {
1331 showInsetCursor(bv);
1333 bv->unlockInset(this);
1340 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1343 buf->latexParagraphs(os, par, 0, texrow);
1344 return texrow.rows();
1348 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1350 Paragraph * p = par;
1351 unsigned int lines = 0;
1354 string const tmp = buf->asciiParagraph(p, linelen);
1355 lines += countChar(tmp, '\n');
1363 int InsetText::docbook(Buffer const * buf, ostream & os) const
1365 Paragraph * p = par;
1366 unsigned int lines = 0;
1371 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1379 void InsetText::validate(LaTeXFeatures & features) const
1381 Paragraph * p = par;
1383 p->validate(features);
1389 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1391 if (textclasslist.Style(buf->params.textclass,
1392 p->getLayout()).labeltype != LABEL_MANUAL)
1395 return p->beginningOfMainBody();
1399 void InsetText::getCursorPos(BufferView * bv,
1400 int & x, int & y) const
1402 if (the_locking_inset) {
1403 the_locking_inset->getCursorPos(bv, x, y);
1411 unsigned int InsetText::insetInInsetY()
1413 if (!the_locking_inset)
1416 return (inset_y + the_locking_inset->insetInInsetY());
1420 void InsetText::toggleInsetCursor(BufferView * bv)
1422 if (the_locking_inset) {
1423 the_locking_inset->toggleInsetCursor(bv);
1427 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1429 int const asc = lyxfont::maxAscent(font);
1430 int const desc = lyxfont::maxDescent(font);
1432 if (isCursorVisible())
1433 bv->hideLockedInsetCursor();
1435 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1436 toggleCursorVisible();
1440 void InsetText::showInsetCursor(BufferView * bv, bool show)
1442 if (the_locking_inset) {
1443 the_locking_inset->showInsetCursor(bv, show);
1446 if (!isCursorVisible()) {
1447 LyXFont const font =
1448 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1450 int const asc = lyxfont::maxAscent(font);
1451 int const desc = lyxfont::maxDescent(font);
1453 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1455 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1456 setCursorVisible(true);
1461 void InsetText::hideInsetCursor(BufferView * bv)
1463 if (isCursorVisible()) {
1464 bv->hideLockedInsetCursor();
1465 setCursorVisible(false);
1467 if (the_locking_inset)
1468 the_locking_inset->hideInsetCursor(bv);
1472 void InsetText::fitInsetCursor(BufferView * bv) const
1474 if (the_locking_inset) {
1475 the_locking_inset->fitInsetCursor(bv);
1478 LyXFont const font =
1479 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1481 int const asc = lyxfont::maxAscent(font);
1482 int const desc = lyxfont::maxDescent(font);
1484 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1488 UpdatableInset::RESULT
1489 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1491 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1492 return moveLeftIntern(bv, false, activate_inset, selecting);
1494 return moveRightIntern(bv, false, activate_inset, selecting);
1498 UpdatableInset::RESULT
1499 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1501 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1502 return moveRightIntern(bv, true, activate_inset, selecting);
1504 return moveLeftIntern(bv, true, activate_inset, selecting);
1508 UpdatableInset::RESULT
1509 InsetText::moveRightIntern(BufferView * bv, bool behind,
1510 bool activate_inset, bool selecting)
1512 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1513 return FINISHED_RIGHT;
1514 if (activate_inset && checkAndActivateInset(bv, behind))
1516 getLyXText(bv)->cursorRight(bv);
1518 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1519 return DISPATCHED_NOUPDATE;
1523 UpdatableInset::RESULT
1524 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1525 bool activate_inset, bool selecting)
1527 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1529 getLyXText(bv)->cursorLeft(bv);
1531 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1532 if (activate_inset && checkAndActivateInset(bv, behind))
1534 return DISPATCHED_NOUPDATE;
1538 UpdatableInset::RESULT
1539 InsetText::moveUp(BufferView * bv)
1541 if (!crow(bv)->previous())
1543 getLyXText(bv)->cursorUp(bv);
1544 return DISPATCHED_NOUPDATE;
1548 UpdatableInset::RESULT
1549 InsetText::moveDown(BufferView * bv)
1551 if (!crow(bv)->next())
1552 return FINISHED_DOWN;
1553 getLyXText(bv)->cursorDown(bv);
1554 return DISPATCHED_NOUPDATE;
1558 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1560 if (the_locking_inset) {
1561 if (the_locking_inset->insetAllowed(inset))
1562 return the_locking_inset->insertInset(bv, inset);
1565 inset->setOwner(this);
1566 hideInsetCursor(bv);
1570 lt = getLyXText(bv);
1573 lt->insertInset(bv, inset);
1575 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1576 (cpar(bv)->getInset(cpos(bv)) != inset))
1580 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1581 showInsetCursor(bv);
1588 bool InsetText::insetAllowed(Inset::Code code) const
1590 if (the_locking_inset)
1591 return the_locking_inset->insetAllowed(code);
1596 UpdatableInset * InsetText::getLockingInset() const
1598 return the_locking_inset ? the_locking_inset->getLockingInset() :
1599 const_cast<InsetText *>(this);
1603 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1607 if (the_locking_inset)
1608 return the_locking_inset->getFirstLockingInsetOfType(c);
1613 bool InsetText::showInsetDialog(BufferView * bv) const
1615 if (the_locking_inset)
1616 return the_locking_inset->showInsetDialog(bv);
1621 std::vector<string> const InsetText::getLabelList() const
1623 std::vector<string> label_list;
1625 Paragraph * tpar = par;
1627 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1628 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1629 for (; beg != end; ++beg) {
1630 std::vector<string> const l = (*beg)->getLabelList();
1631 label_list.insert(label_list.end(), l.begin(), l.end());
1633 tpar = tpar->next();
1639 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1642 if (the_locking_inset) {
1643 the_locking_inset->setFont(bv, font, toggleall, selectall);
1646 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1647 getLyXText(bv)->setFont(bv, font, toggleall);
1652 lt = getLyXText(bv);
1655 if (lt->selection.set()) {
1656 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1660 lt->toggleFree(bv, font, toggleall);
1662 lt->clearSelection();
1664 if (selectall || lt->selection.set())
1665 updateLocal(bv, FULL, true);
1667 updateLocal(bv, CURSOR_PAR, true);
1673 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1675 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1679 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1680 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1682 LyXFont const font =
1683 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1685 x = inset->width(bv, font);
1686 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1689 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1691 //inset_x = cx(bv) - top_x + drawTextXOffset;
1692 //inset_y = cy(bv) + drawTextYOffset;
1693 inset->edit(bv, x, y, 0);
1694 if (!the_locking_inset)
1696 updateLocal(bv, CURSOR, false);
1703 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1706 x -= drawTextXOffset;
1708 int dummyy = y + insetAscent;
1709 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1716 inset_x = cx(bv) - top_x + drawTextXOffset;
1717 inset_y = cy(bv) + drawTextYOffset;
1718 inset->edit(bv, x - inset_x, y - inset_y, button);
1719 if (!the_locking_inset)
1721 updateLocal(bv, CURSOR, false);
1728 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1731 int w = UpdatableInset::getMaxWidth(bv, inset);
1736 w = w - top_x + owner()->x();
1739 w -= (2 * TEXT_TO_INSET_OFFSET);
1742 return UpdatableInset::getMaxWidth(bv, inset);
1747 void InsetText::setParagraphData(Paragraph * p)
1749 // we have to unlock any locked inset otherwise we're in troubles
1750 the_locking_inset = 0;
1752 Paragraph * tmp = par->next();
1757 par = new Paragraph(*p, false);
1758 par->setInsetOwner(this);
1759 Paragraph * np = par;
1762 np->next(new Paragraph(*p, false));
1763 np->next()->previous(np);
1765 np->setInsetOwner(this);
1771 void InsetText::setText(string const & data)
1774 LyXFont font(LyXFont::ALL_SANE);
1775 for (unsigned int i=0; i < data.length(); ++i)
1776 par->insertChar(i, data[i], font);
1780 void InsetText::setAutoBreakRows(bool flag)
1782 if (flag != autoBreakRows) {
1783 autoBreakRows = flag;
1791 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1793 if (how != drawFrame_) {
1796 updateLocal(bv, DRAW_FRAME, false);
1801 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1803 if (frame_color != col) {
1806 updateLocal(bv, DRAW_FRAME, false);
1811 int InsetText::cx(BufferView * bv) const
1815 lt = getLyXText(bv);
1818 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1819 if (the_locking_inset) {
1820 LyXFont font = lt->getFont(bv->buffer(),
1823 if (font.isVisibleRightToLeft())
1824 x -= the_locking_inset->width(bv, font);
1832 int InsetText::cy(BufferView * bv) const
1835 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1839 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1841 return getLyXText(bv)->cursor.pos();
1845 Paragraph * InsetText::cpar(BufferView * bv) const
1847 return getLyXText(bv)->cursor.par();
1851 bool InsetText::cboundary(BufferView * bv) const
1853 return getLyXText(bv)->cursor.boundary();
1857 Row * InsetText::crow(BufferView * bv) const
1859 return getLyXText(bv)->cursor.row();
1863 LyXText * InsetText::getLyXText(BufferView const * lbv,
1864 bool const recursive) const
1866 if (!recursive && (cached_bview == lbv))
1867 return cached_text.get();
1869 // Super UGLY! (Lgb)
1870 BufferView * bv = const_cast<BufferView *>(lbv);
1873 Cache::iterator it = cache.find(bv);
1875 if (it != cache.end()) {
1879 resizeLyXText(do_resize);
1880 if (lt || !it->second.remove) {
1881 lyx::Assert(it->second.text.get());
1882 cached_text = it->second.text;
1883 if (recursive && the_locking_inset) {
1884 return the_locking_inset->getLyXText(bv, true);
1886 return cached_text.get();
1887 } else if (it->second.remove) {
1889 saveLyXTextState(it->second.text.get());
1896 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1897 cached_text->init(bv);
1898 restoreLyXTextState(bv, cached_text.get());
1900 cache.insert(make_pair(bv, cached_text));
1902 if (the_locking_inset && recursive) {
1903 return the_locking_inset->getLyXText(bv);
1905 return cached_text.get();
1909 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1913 Cache::iterator it = cache.find(bv);
1915 if (it == cache.end()) {
1919 lyx::Assert(it->second.text.get());
1921 it->second.remove = true;
1923 /// then remove all LyXText in text-insets
1924 Paragraph * p = par;
1925 for (; p; p = p->next()) {
1926 p->deleteInsetsLyXText(bv);
1932 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1935 // we cannot resize this because we are in use!
1936 // so do this on the next possible getLyXText()
1941 // lyxerr << "InsetText::resizeLyXText\n";
1942 if (!par->next() && !par->size()) // no data, resize not neccessary!
1944 // one endless line, resize normally not necessary
1945 if (!force && getMaxWidth(bv, this) < 0)
1948 Cache::iterator it = cache.find(bv);
1949 if (it == cache.end()) {
1952 lyx::Assert(it->second.text.get());
1954 LyXText * t = it->second.text.get();
1955 saveLyXTextState(t);
1956 for (Paragraph * p = par; p; p = p->next()) {
1957 p->resizeInsetsLyXText(bv);
1960 restoreLyXTextState(bv, t);
1961 if (the_locking_inset) {
1962 inset_x = cx(bv) - top_x + drawTextXOffset;
1963 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();
1974 need_update |= FULL;
1979 void InsetText::reinitLyXText() const
1982 // we cannot resize this because we are in use!
1983 // so do this on the next possible getLyXText()
1989 // lyxerr << "InsetText::reinitLyXText\n";
1990 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1991 lyx::Assert(it->second.text.get());
1993 LyXText * t = it->second.text.get();
1994 BufferView * bv = it->first;
1996 saveLyXTextState(t);
1997 for (Paragraph * p = par; p; p = p->next()) {
1998 p->resizeInsetsLyXText(bv);
2001 restoreLyXTextState(bv, t);
2002 if (the_locking_inset) {
2003 inset_x = cx(bv) - top_x + drawTextXOffset;
2004 inset_y = cy(bv) + drawTextYOffset;
2007 t->first = bv->screen()->topCursorVisible(t);
2010 updateLocal(bv, FULL, false);
2011 // this will scroll the screen such that the cursor becomes visible
2012 bv->updateScrollbar();
2020 void InsetText::removeNewlines()
2022 for (Paragraph * p = par; p; p = p->next()) {
2023 for (int i = 0; i < p->size(); ++i) {
2024 if (p->getChar(i) == Paragraph::META_NEWLINE)
2031 bool InsetText::nodraw() const
2033 if (the_locking_inset)
2034 return the_locking_inset->nodraw();
2035 return UpdatableInset::nodraw();
2039 int InsetText::scroll(bool recursive) const
2041 int sx = UpdatableInset::scroll(false);
2043 if (recursive && the_locking_inset)
2044 sx += the_locking_inset->scroll(recursive);
2050 bool InsetText::doClearArea() const
2052 return !locked || (need_update & (FULL|INIT));
2056 void InsetText::selectAll(BufferView * bv)
2058 getLyXText(bv)->cursorTop(bv);
2059 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2060 getLyXText(bv)->cursorBottom(bv);
2061 getLyXText(bv)->setSelection(bv);
2065 void InsetText::clearSelection(BufferView * bv)
2067 getLyXText(bv)->clearSelection();
2071 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2074 int h = insetAscent + insetDescent;
2075 int ty = baseline - insetAscent;
2081 if ((ty + h) > pain.paperHeight())
2082 h = pain.paperHeight();
2083 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2084 w = pain.paperWidth();
2085 // w -= TEXT_TO_INSET_OFFSET;
2086 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2089 frame_is_visible = false;
2093 Paragraph * InsetText::getParFromID(int id) const
2096 Paragraph * result = par;
2097 Paragraph * ires = 0;
2098 while (result && result->id() != id) {
2099 if ((ires = result->getParFromID(id)))
2101 result = result->next();
2105 Paragraph * tmp = par;
2107 int tmp_id = tmp->id();
2108 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2109 if (tmp->id() == id) {
2112 Paragraph * tmp2 = tmp->getParFromID(id);
2123 Paragraph * InsetText::firstParagraph() const
2126 if (the_locking_inset)
2127 if ((result = the_locking_inset->firstParagraph()))
2133 Paragraph * InsetText::getFirstParagraph(int i) const
2135 return (i == 0) ? par : 0;
2139 LyXCursor const & InsetText::cursor(BufferView * bv) const
2141 if (the_locking_inset)
2142 return the_locking_inset->cursor(bv);
2143 return getLyXText(bv)->cursor;
2147 Paragraph * InsetText::paragraph() const
2153 void InsetText::paragraph(Paragraph * p)
2157 // we now have to update/redraw all instances
2158 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2163 // redraw myself when asked for
2168 Inset * InsetText::getInsetFromID(int id_arg) const
2171 return const_cast<InsetText *>(this);
2173 Paragraph * lp = par;
2176 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2177 en = lp->inset_iterator_end();
2180 if ((*it)->id() == id_arg)
2182 Inset * in = (*it)->getInsetFromID(id_arg);
2192 string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2198 lt = getLyXText(bv);
2201 if (the_locking_inset) {
2202 str = the_locking_inset->selectNextWordToSpellcheck(bv, value);
2209 #warning Dekel please have a look on this one RTL? (Jug)
2211 // we have to go on checking so move cusor to the right
2212 lt->cursor.pos(lt->cursor.pos() + 1);
2214 str = lt->selectNextWordToSpellcheck(bv, value);
2216 bv->unlockInset(const_cast<InsetText *>(this));
2225 void InsetText::selectSelectedWord(BufferView * bv)
2227 if (the_locking_inset) {
2228 the_locking_inset->selectSelectedWord(bv);
2231 getLyXText(bv)->selectSelectedWord(bv);
2232 updateLocal(bv, SELECTION, false);
2236 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2238 if (the_locking_inset) {
2239 the_locking_inset->toggleSelection(bv, kill_selection);
2243 lt = getLyXText(bv);
2247 int x = top_x + TEXT_TO_INSET_OFFSET;
2250 Row * row = lt->getRowNearY(y);
2251 int y_offset = top_baseline - row->ascent_of_text();
2253 while ((row != 0) && ((y+row->height()) <= 0)) {
2260 if (need_update & SELECTION)
2262 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2268 bool InsetText::searchForward(BufferView * bv, string const & str,
2269 bool const & cs, bool const & mw)
2271 if (the_locking_inset) {
2272 if (the_locking_inset->searchForward(bv, str, cs, mw))
2276 lt = getLyXText(bv);
2279 Paragraph * lpar = lt->cursor.par();
2280 Paragraph::size_type pos = lt->cursor.pos();
2281 if (pos < lpar->size() - 1)
2285 lpar = lpar->next();
2290 // we have to unlock ourself in this function by default!
2291 bv->unlockInset(const_cast<InsetText *>(this));
2294 lt->setCursor(bv, lpar, pos);
2298 if (LyXFind(bv, str, true, true, cs , mw)) {
2301 // we have to unlock ourself in this function by default!
2302 bv->unlockInset(const_cast<InsetText *>(this));
2306 bool InsetText::searchBackward(BufferView * bv, string const & str,
2307 bool const & cs, bool const & mw)
2309 if (the_locking_inset)
2310 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2312 if (LyXFind(bv, str, false, true, cs, mw)) {
2315 // we have to unlock ourself in this function by default!
2316 bv->unlockInset(const_cast<InsetText *>(this));