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) {
1017 bool dispatched = false;
1019 case LFUN_UNKNOWN_ACTION:
1020 case LFUN_BREAKPARAGRAPH:
1021 case LFUN_BREAKLINE:
1022 moveRightIntern(bv, false, false);
1025 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1026 moveRightIntern(bv, false, false);
1030 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1031 moveRightIntern(bv, false, false);
1037 the_locking_inset = 0;
1042 hideInsetCursor(bv);
1045 lt = getLyXText(bv);
1050 case LFUN_SELFINSERT:
1051 if (bv->buffer()->isReadonly()) {
1052 // setErrorMessage(N_("Document is read only"));
1056 /* Automatically delete the currently selected
1057 * text and replace it with what is being
1058 * typed in now. Depends on lyxrc settings
1059 * "auto_region_delete", which defaults to
1062 setUndo(bv, Undo::INSERT,
1063 lt->cursor.par(), lt->cursor.par()->next());
1065 if (lyxrc.auto_region_delete) {
1066 if (lt->selection.set()) {
1067 lt->cutSelection(bv, false);
1070 lt->clearSelection();
1071 for (string::size_type i = 0; i < arg.length(); ++i) {
1072 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1075 lt->selection.cursor = lt->cursor;
1076 updateLocal(bv, CURSOR_PAR, true);
1077 result = DISPATCHED_NOUPDATE;
1079 // --- Cursor Movements -----------------------------------
1082 moveRight(bv, false, true);
1083 lt->setSelection(bv);
1084 updateLocal(bv, SELECTION, false);
1087 result = moveRight(bv);
1089 updateLocal(bv, CURSOR, false);
1093 moveLeft(bv, false, true);
1094 lt->setSelection(bv);
1095 updateLocal(bv, SELECTION, false);
1099 result = moveLeft(bv);
1100 updateLocal(bv, CURSOR, false);
1105 lt->setSelection(bv);
1106 updateLocal(bv, SELECTION, false);
1110 result = moveDown(bv);
1111 updateLocal(bv, CURSOR, false);
1116 lt->setSelection(bv);
1117 updateLocal(bv, SELECTION, false);
1121 result = moveUp(bv);
1122 updateLocal(bv, CURSOR, false);
1127 updateLocal(bv, CURSOR, false);
1131 updateLocal(bv, CURSOR, false);
1133 case LFUN_BACKSPACE: {
1134 setUndo(bv, Undo::DELETE,
1135 lt->cursor.par(), lt->cursor.par()->next());
1136 if (lt->selection.set())
1137 lt->cutSelection(bv);
1140 updateLocal(bv, CURSOR_PAR, true);
1145 setUndo(bv, Undo::DELETE,
1146 lt->cursor.par(), lt->cursor.par()->next());
1147 if (lt->selection.set()) {
1148 lt->cutSelection(bv);
1152 updateLocal(bv, CURSOR_PAR, true);
1157 setUndo(bv, Undo::DELETE,
1158 lt->cursor.par(), lt->cursor.par()->next());
1159 lt->cutSelection(bv);
1160 updateLocal(bv, CURSOR_PAR, true);
1166 lt->copySelection(bv);
1167 updateLocal(bv, CURSOR_PAR, false);
1169 case LFUN_PASTESELECTION:
1171 string const clip(bv->getClipboard());
1175 if (arg == "paragraph") {
1176 lt->insertStringAsParagraphs(bv, clip);
1178 lt->insertStringAsLines(bv, clip);
1180 updateLocal(bv, CURSOR_PAR, true);
1184 if (!autoBreakRows) {
1186 if (CutAndPaste::nrOfParagraphs() > 1) {
1187 WriteAlert(_("Impossible operation"),
1188 _("Cannot include more than one paragraph!"),
1193 setUndo(bv, Undo::INSERT,
1194 lt->cursor.par(), lt->cursor.par()->next());
1195 lt->pasteSelection(bv);
1196 updateLocal(bv, CURSOR_PAR, true);
1200 case LFUN_BREAKPARAGRAPH:
1201 if (!autoBreakRows) {
1202 result = DISPATCHED;
1205 lt->breakParagraph(bv, 0);
1206 updateLocal(bv, FULL, true);
1208 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1209 if (!autoBreakRows) {
1210 result = DISPATCHED;
1213 lt->breakParagraph(bv, 1);
1214 updateLocal(bv, FULL, true);
1217 case LFUN_BREAKLINE: {
1218 if (!autoBreakRows) {
1219 result = DISPATCHED;
1222 setUndo(bv, Undo::INSERT,
1223 lt->cursor.par(), lt->cursor.par()->next());
1224 lt->insertChar(bv, Paragraph::META_NEWLINE);
1225 updateLocal(bv, CURSOR_PAR, true);
1230 // do not set layouts on non breakable textinsets
1231 if (autoBreakRows) {
1232 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1234 // Derive layout number from given argument (string)
1235 // and current buffer's textclass (number). */
1236 LyXTextClassList::ClassList::size_type tclass =
1237 bv->buffer()->params.textclass;
1238 std::pair <bool, LyXTextClass::size_type> layout =
1239 textclasslist.NumberOfLayout(tclass, arg);
1241 // If the entry is obsolete, use the new one instead.
1243 string obs = textclasslist.Style(tclass,layout.second).
1246 layout = textclasslist.NumberOfLayout(tclass, obs);
1249 // see if we found the layout number:
1250 if (!layout.first) {
1251 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1252 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1256 if (cur_layout != layout.second) {
1257 cur_layout = layout.second;
1258 lt->setLayout(bv, layout.second);
1259 bv->owner()->setLayout(cpar(bv)->getLayout());
1260 updateLocal(bv, CURSOR_PAR, true);
1263 // reset the layout box
1264 bv->owner()->setLayout(cpar(bv)->getLayout());
1267 case LFUN_PARAGRAPH_SPACING:
1268 // This one is absolutely not working. When fiddling with this
1269 // it also seems to me that the paragraphs inside the insettext
1270 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1272 Paragraph * par = lt->cursor.par();
1273 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1274 float cur_value = 1.0;
1275 if (cur_spacing == Spacing::Other) {
1276 cur_value = par->params().spacing().getValue();
1279 istringstream istr(arg.c_str());
1282 Spacing::Space new_spacing = cur_spacing;
1283 float new_value = cur_value;
1285 lyxerr << "Missing argument to `paragraph-spacing'"
1287 } else if (tmp == "single") {
1288 new_spacing = Spacing::Single;
1289 } else if (tmp == "onehalf") {
1290 new_spacing = Spacing::Onehalf;
1291 } else if (tmp == "double") {
1292 new_spacing = Spacing::Double;
1293 } else if (tmp == "other") {
1294 new_spacing = Spacing::Other;
1297 lyxerr << "new_value = " << tmpval << endl;
1300 } else if (tmp == "default") {
1301 new_spacing = Spacing::Default;
1303 lyxerr << _("Unknown spacing argument: ")
1306 if (cur_spacing != new_spacing || cur_value != new_value) {
1307 par->params().spacing(Spacing(new_spacing, new_value));
1308 updateLocal(bv, CURSOR_PAR, true);
1314 if (!bv->Dispatch(action, arg))
1315 result = UNDISPATCHED;
1319 /// If the action has deleted all text in the inset, we need to change the
1320 // language to the language of the surronding text.
1321 if (!was_empty && par->size() == 0 && !par->next()) {
1322 LyXFont font(LyXFont::ALL_IGNORE);
1323 font.setLanguage(bv->getParentLanguage(this));
1324 setFont(bv, font, false);
1327 if (result < FINISHED) {
1328 showInsetCursor(bv);
1330 bv->unlockInset(this);
1337 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1340 buf->latexParagraphs(os, par, 0, texrow);
1341 return texrow.rows();
1345 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1347 Paragraph * p = par;
1348 unsigned int lines = 0;
1351 string const tmp = buf->asciiParagraph(p, linelen);
1352 lines += countChar(tmp, '\n');
1360 int InsetText::docbook(Buffer const * buf, ostream & os) const
1362 Paragraph * p = par;
1363 unsigned int lines = 0;
1368 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1376 void InsetText::validate(LaTeXFeatures & features) const
1378 Paragraph * p = par;
1380 p->validate(features);
1386 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1388 if (textclasslist.Style(buf->params.textclass,
1389 p->getLayout()).labeltype != LABEL_MANUAL)
1392 return p->beginningOfMainBody();
1396 void InsetText::getCursorPos(BufferView * bv,
1397 int & x, int & y) const
1399 if (the_locking_inset) {
1400 the_locking_inset->getCursorPos(bv, x, y);
1408 unsigned int InsetText::insetInInsetY()
1410 if (!the_locking_inset)
1413 return (inset_y + the_locking_inset->insetInInsetY());
1417 void InsetText::toggleInsetCursor(BufferView * bv)
1419 if (the_locking_inset) {
1420 the_locking_inset->toggleInsetCursor(bv);
1424 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1426 int const asc = lyxfont::maxAscent(font);
1427 int const desc = lyxfont::maxDescent(font);
1429 if (isCursorVisible())
1430 bv->hideLockedInsetCursor();
1432 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1433 toggleCursorVisible();
1437 void InsetText::showInsetCursor(BufferView * bv, bool show)
1439 if (the_locking_inset) {
1440 the_locking_inset->showInsetCursor(bv, show);
1443 if (!isCursorVisible()) {
1444 LyXFont const font =
1445 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1447 int const asc = lyxfont::maxAscent(font);
1448 int const desc = lyxfont::maxDescent(font);
1450 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1452 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1453 setCursorVisible(true);
1458 void InsetText::hideInsetCursor(BufferView * bv)
1460 if (isCursorVisible()) {
1461 bv->hideLockedInsetCursor();
1462 setCursorVisible(false);
1464 if (the_locking_inset)
1465 the_locking_inset->hideInsetCursor(bv);
1469 void InsetText::fitInsetCursor(BufferView * bv) const
1471 if (the_locking_inset) {
1472 the_locking_inset->fitInsetCursor(bv);
1475 LyXFont const font =
1476 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1478 int const asc = lyxfont::maxAscent(font);
1479 int const desc = lyxfont::maxDescent(font);
1481 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1485 UpdatableInset::RESULT
1486 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1488 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1489 return moveLeftIntern(bv, false, activate_inset, selecting);
1491 return moveRightIntern(bv, false, activate_inset, selecting);
1495 UpdatableInset::RESULT
1496 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1498 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1499 return moveRightIntern(bv, true, activate_inset, selecting);
1501 return moveLeftIntern(bv, true, activate_inset, selecting);
1505 UpdatableInset::RESULT
1506 InsetText::moveRightIntern(BufferView * bv, bool behind,
1507 bool activate_inset, bool selecting)
1509 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1510 return FINISHED_RIGHT;
1511 if (activate_inset && checkAndActivateInset(bv, behind))
1513 getLyXText(bv)->cursorRight(bv);
1515 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1516 return DISPATCHED_NOUPDATE;
1520 UpdatableInset::RESULT
1521 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1522 bool activate_inset, bool selecting)
1524 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1526 getLyXText(bv)->cursorLeft(bv);
1528 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1529 if (activate_inset && checkAndActivateInset(bv, behind))
1531 return DISPATCHED_NOUPDATE;
1535 UpdatableInset::RESULT
1536 InsetText::moveUp(BufferView * bv)
1538 if (!crow(bv)->previous())
1540 getLyXText(bv)->cursorUp(bv);
1541 return DISPATCHED_NOUPDATE;
1545 UpdatableInset::RESULT
1546 InsetText::moveDown(BufferView * bv)
1548 if (!crow(bv)->next())
1549 return FINISHED_DOWN;
1550 getLyXText(bv)->cursorDown(bv);
1551 return DISPATCHED_NOUPDATE;
1555 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1557 if (the_locking_inset) {
1558 if (the_locking_inset->insetAllowed(inset))
1559 return the_locking_inset->insertInset(bv, inset);
1562 inset->setOwner(this);
1563 hideInsetCursor(bv);
1567 lt = getLyXText(bv);
1570 lt->insertInset(bv, inset);
1572 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1573 (cpar(bv)->getInset(cpos(bv)) != inset))
1577 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1578 showInsetCursor(bv);
1585 bool InsetText::insetAllowed(Inset::Code code) const
1587 if (the_locking_inset)
1588 return the_locking_inset->insetAllowed(code);
1593 UpdatableInset * InsetText::getLockingInset() const
1595 return the_locking_inset ? the_locking_inset->getLockingInset() :
1596 const_cast<InsetText *>(this);
1600 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1604 if (the_locking_inset)
1605 return the_locking_inset->getFirstLockingInsetOfType(c);
1610 bool InsetText::showInsetDialog(BufferView * bv) const
1612 if (the_locking_inset)
1613 return the_locking_inset->showInsetDialog(bv);
1618 std::vector<string> const InsetText::getLabelList() const
1620 std::vector<string> label_list;
1622 Paragraph * tpar = par;
1624 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1625 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1626 for (; beg != end; ++beg) {
1627 std::vector<string> const l = (*beg)->getLabelList();
1628 label_list.insert(label_list.end(), l.begin(), l.end());
1630 tpar = tpar->next();
1636 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1639 if (the_locking_inset) {
1640 the_locking_inset->setFont(bv, font, toggleall, selectall);
1643 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1644 getLyXText(bv)->setFont(bv, font, toggleall);
1649 lt = getLyXText(bv);
1652 if (lt->selection.set()) {
1653 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1657 lt->toggleFree(bv, font, toggleall);
1659 lt->clearSelection();
1661 if (selectall || lt->selection.set())
1662 updateLocal(bv, FULL, true);
1664 updateLocal(bv, CURSOR_PAR, true);
1670 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1672 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1676 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1677 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1679 LyXFont const font =
1680 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1682 x = inset->width(bv, font);
1683 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1686 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1688 //inset_x = cx(bv) - top_x + drawTextXOffset;
1689 //inset_y = cy(bv) + drawTextYOffset;
1690 inset->edit(bv, x, y, 0);
1691 if (!the_locking_inset)
1693 updateLocal(bv, CURSOR, false);
1700 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1703 x -= drawTextXOffset;
1705 int dummyy = y + insetAscent;
1706 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1713 inset_x = cx(bv) - top_x + drawTextXOffset;
1714 inset_y = cy(bv) + drawTextYOffset;
1715 inset->edit(bv, x - inset_x, y - inset_y, button);
1716 if (!the_locking_inset)
1718 updateLocal(bv, CURSOR, false);
1725 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1728 int w = UpdatableInset::getMaxWidth(bv, inset);
1733 w = w - top_x + owner()->x();
1736 w -= (2 * TEXT_TO_INSET_OFFSET);
1739 return UpdatableInset::getMaxWidth(bv, inset);
1744 void InsetText::setParagraphData(Paragraph * p)
1746 // we have to unlock any locked inset otherwise we're in troubles
1747 the_locking_inset = 0;
1749 Paragraph * tmp = par->next();
1754 par = new Paragraph(*p, false);
1755 par->setInsetOwner(this);
1756 Paragraph * np = par;
1759 np->next(new Paragraph(*p, false));
1760 np->next()->previous(np);
1762 np->setInsetOwner(this);
1768 void InsetText::setText(string const & data)
1771 LyXFont font(LyXFont::ALL_SANE);
1772 for (unsigned int i=0; i < data.length(); ++i)
1773 par->insertChar(i, data[i], font);
1777 void InsetText::setAutoBreakRows(bool flag)
1779 if (flag != autoBreakRows) {
1780 autoBreakRows = flag;
1788 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1790 if (how != drawFrame_) {
1793 updateLocal(bv, DRAW_FRAME, false);
1798 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1800 if (frame_color != col) {
1803 updateLocal(bv, DRAW_FRAME, false);
1808 int InsetText::cx(BufferView * bv) const
1812 lt = getLyXText(bv);
1815 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1816 if (the_locking_inset) {
1817 LyXFont font = lt->getFont(bv->buffer(),
1820 if (font.isVisibleRightToLeft())
1821 x -= the_locking_inset->width(bv, font);
1829 int InsetText::cy(BufferView * bv) const
1832 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1836 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1838 return getLyXText(bv)->cursor.pos();
1842 Paragraph * InsetText::cpar(BufferView * bv) const
1844 return getLyXText(bv)->cursor.par();
1848 bool InsetText::cboundary(BufferView * bv) const
1850 return getLyXText(bv)->cursor.boundary();
1854 Row * InsetText::crow(BufferView * bv) const
1856 return getLyXText(bv)->cursor.row();
1860 LyXText * InsetText::getLyXText(BufferView const * lbv,
1861 bool const recursive) const
1863 if (!recursive && (cached_bview == lbv))
1864 return cached_text.get();
1866 // Super UGLY! (Lgb)
1867 BufferView * bv = const_cast<BufferView *>(lbv);
1870 Cache::iterator it = cache.find(bv);
1872 if (it != cache.end()) {
1876 resizeLyXText(do_resize);
1877 if (lt || !it->second.remove) {
1878 lyx::Assert(it->second.text.get());
1879 cached_text = it->second.text;
1880 if (recursive && the_locking_inset) {
1881 return the_locking_inset->getLyXText(bv, true);
1883 return cached_text.get();
1884 } else if (it->second.remove) {
1886 saveLyXTextState(it->second.text.get());
1893 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1894 cached_text->init(bv);
1895 restoreLyXTextState(bv, cached_text.get());
1897 cache.insert(make_pair(bv, cached_text));
1899 if (the_locking_inset && recursive) {
1900 return the_locking_inset->getLyXText(bv);
1902 return cached_text.get();
1906 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1910 Cache::iterator it = cache.find(bv);
1912 if (it == cache.end()) {
1916 lyx::Assert(it->second.text.get());
1918 it->second.remove = true;
1920 /// then remove all LyXText in text-insets
1921 Paragraph * p = par;
1922 for (; p; p = p->next()) {
1923 p->deleteInsetsLyXText(bv);
1929 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1932 // we cannot resize this because we are in use!
1933 // so do this on the next possible getLyXText()
1938 // lyxerr << "InsetText::resizeLyXText\n";
1939 if (!par->next() && !par->size()) // no data, resize not neccessary!
1941 // one endless line, resize normally not necessary
1942 if (!force && getMaxWidth(bv, this) < 0)
1945 Cache::iterator it = cache.find(bv);
1946 if (it == cache.end()) {
1949 lyx::Assert(it->second.text.get());
1951 LyXText * t = it->second.text.get();
1952 saveLyXTextState(t);
1953 for (Paragraph * p = par; p; p = p->next()) {
1954 p->resizeInsetsLyXText(bv);
1957 restoreLyXTextState(bv, t);
1958 if (the_locking_inset) {
1959 inset_x = cx(bv) - top_x + drawTextXOffset;
1960 inset_y = cy(bv) + drawTextYOffset;
1964 t->first = bv->screen()->topCursorVisible(t);
1967 updateLocal(bv, FULL, false);
1968 // this will scroll the screen such that the cursor becomes visible
1969 bv->updateScrollbar();
1971 need_update |= FULL;
1976 void InsetText::reinitLyXText() const
1979 // we cannot resize this because we are in use!
1980 // so do this on the next possible getLyXText()
1986 // lyxerr << "InsetText::reinitLyXText\n";
1987 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1988 lyx::Assert(it->second.text.get());
1990 LyXText * t = it->second.text.get();
1991 BufferView * bv = it->first;
1993 saveLyXTextState(t);
1994 for (Paragraph * p = par; p; p = p->next()) {
1995 p->resizeInsetsLyXText(bv);
1998 restoreLyXTextState(bv, t);
1999 if (the_locking_inset) {
2000 inset_x = cx(bv) - top_x + drawTextXOffset;
2001 inset_y = cy(bv) + drawTextYOffset;
2004 t->first = bv->screen()->topCursorVisible(t);
2007 updateLocal(bv, FULL, false);
2008 // this will scroll the screen such that the cursor becomes visible
2009 bv->updateScrollbar();
2017 void InsetText::removeNewlines()
2019 for (Paragraph * p = par; p; p = p->next()) {
2020 for (int i = 0; i < p->size(); ++i) {
2021 if (p->getChar(i) == Paragraph::META_NEWLINE)
2028 bool InsetText::nodraw() const
2030 if (the_locking_inset)
2031 return the_locking_inset->nodraw();
2032 return UpdatableInset::nodraw();
2036 int InsetText::scroll(bool recursive) const
2038 int sx = UpdatableInset::scroll(false);
2040 if (recursive && the_locking_inset)
2041 sx += the_locking_inset->scroll(recursive);
2047 bool InsetText::doClearArea() const
2049 return !locked || (need_update & (FULL|INIT));
2053 void InsetText::selectAll(BufferView * bv)
2055 getLyXText(bv)->cursorTop(bv);
2056 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2057 getLyXText(bv)->cursorBottom(bv);
2058 getLyXText(bv)->setSelection(bv);
2062 void InsetText::clearSelection(BufferView * bv)
2064 getLyXText(bv)->clearSelection();
2068 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2071 int h = insetAscent + insetDescent;
2072 int ty = baseline - insetAscent;
2078 if ((ty + h) > pain.paperHeight())
2079 h = pain.paperHeight();
2080 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2081 w = pain.paperWidth();
2082 // w -= TEXT_TO_INSET_OFFSET;
2083 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2086 frame_is_visible = false;
2090 Paragraph * InsetText::getParFromID(int id) const
2093 Paragraph * result = par;
2094 Paragraph * ires = 0;
2095 while (result && result->id() != id) {
2096 if ((ires = result->getParFromID(id)))
2098 result = result->next();
2102 Paragraph * tmp = par;
2104 int tmp_id = tmp->id();
2105 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2106 if (tmp->id() == id) {
2109 Paragraph * tmp2 = tmp->getParFromID(id);
2120 Paragraph * InsetText::firstParagraph() const
2123 if (the_locking_inset)
2124 if ((result = the_locking_inset->firstParagraph()))
2130 Paragraph * InsetText::getFirstParagraph(int i) const
2132 return (i == 0) ? par : 0;
2136 LyXCursor const & InsetText::cursor(BufferView * bv) const
2138 if (the_locking_inset)
2139 return the_locking_inset->cursor(bv);
2140 return getLyXText(bv)->cursor;
2144 Paragraph * InsetText::paragraph() const
2150 void InsetText::paragraph(Paragraph * p)
2154 // we now have to update/redraw all instances
2155 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2160 // redraw myself when asked for
2165 Inset * InsetText::getInsetFromID(int id_arg) const
2168 return const_cast<InsetText *>(this);
2170 Paragraph * lp = par;
2173 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2174 en = lp->inset_iterator_end();
2177 if ((*it)->id() == id_arg)
2179 Inset * in = (*it)->getInsetFromID(id_arg);
2189 string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2195 lt = getLyXText(bv);
2198 if (the_locking_inset) {
2199 str = the_locking_inset->selectNextWordToSpellcheck(bv, value);
2206 #warning Dekel please have a look on this one RTL? (Jug)
2208 // we have to go on checking so move cusor to the right
2209 lt->cursor.pos(lt->cursor.pos() + 1);
2211 str = lt->selectNextWordToSpellcheck(bv, value);
2213 bv->unlockInset(const_cast<InsetText *>(this));
2222 void InsetText::selectSelectedWord(BufferView * bv)
2224 if (the_locking_inset) {
2225 the_locking_inset->selectSelectedWord(bv);
2228 getLyXText(bv)->selectSelectedWord(bv);
2229 updateLocal(bv, SELECTION, false);
2233 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2235 if (the_locking_inset) {
2236 the_locking_inset->toggleSelection(bv, kill_selection);
2240 lt = getLyXText(bv);
2244 int x = top_x + TEXT_TO_INSET_OFFSET;
2247 Row * row = lt->getRowNearY(y);
2248 int y_offset = top_baseline - row->ascent_of_text();
2250 while ((row != 0) && ((y+row->height()) <= 0)) {
2257 if (need_update & SELECTION)
2259 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2265 bool InsetText::searchForward(BufferView * bv, string const & str,
2266 bool const & cs, bool const & mw)
2268 if (the_locking_inset) {
2269 if (the_locking_inset->searchForward(bv, str, cs, mw))
2273 lt = getLyXText(bv);
2276 Paragraph * lpar = lt->cursor.par();
2277 Paragraph::size_type pos = lt->cursor.pos();
2278 if (pos < lpar->size() - 1)
2282 lpar = lpar->next();
2287 // we have to unlock ourself in this function by default!
2288 bv->unlockInset(const_cast<InsetText *>(this));
2291 lt->setCursor(bv, lpar, pos);
2295 if (LyXFind(bv, str, true, true, cs , mw)) {
2298 // we have to unlock ourself in this function by default!
2299 bv->unlockInset(const_cast<InsetText *>(this));
2303 bool InsetText::searchBackward(BufferView * bv, string const & str,
2304 bool const & cs, bool const & mw)
2306 if (the_locking_inset)
2307 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2309 if (LyXFind(bv, str, false, true, cs, mw)) {
2312 // we have to unlock ourself in this function by default!
2313 bv->unlockInset(const_cast<InsetText *>(this));