1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998-2001 The LyX Team.
8 * ======================================================
20 #pragma implementation
23 #include "insettext.h"
24 #include "paragraph.h"
28 #include "commandtags.h"
31 #include "BufferView.h"
33 #include "LaTeXFeatures.h"
35 #include "lyx_gui_misc.h"
37 #include "lyxcursor.h"
38 #include "CutAndPaste.h"
41 #include "support/textutils.h"
42 #include "support/LAssert.h"
43 #include "support/lstrings.h"
47 #include "trans_mgr.h"
48 #include "lyxscreen.h"
52 #include "ParagraphParameters.h"
53 #include "undo_funcs.h"
63 extern unsigned char getCurrentTextClass(Buffer *);
64 extern bool math_insert_greek(BufferView *, char);
65 extern int greek_kb_flag;
68 #warning this functions should probably go into bufferview_funcs somehow (Jug)
70 void InsetText::saveLyXTextState(LyXText * t) const
72 sstate.lpar = t->cursor.par();
73 sstate.pos = t->cursor.pos();
74 sstate.boundary = t->cursor.boundary();
75 sstate.selstartpar = t->selection.start.par();
76 sstate.selstartpos = t->selection.start.pos();
77 sstate.selstartboundary = t->selection.start.boundary();
78 sstate.selendpar = t->selection.end.par();
79 sstate.selendpos = t->selection.end.pos();
80 sstate.selendboundary = t->selection.end.boundary();
81 sstate.selection = t->selection.set();
82 sstate.mark_set = t->selection.mark();
83 sstate.refresh = t->refresh_row != 0;
86 void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const
89 t->selection.set(true);
90 /* at this point just to avoid the Delete-Empty-Paragraph
91 * Mechanism when setting the cursor */
92 t->selection.mark(sstate.mark_set);
93 if (sstate.selection) {
94 t->setCursor(bv, sstate.selstartpar, sstate.selstartpos,
95 true, sstate.selstartboundary);
96 t->selection.cursor = t->cursor;
97 t->setCursor(bv, sstate.selendpar, sstate.selendpos,
98 true, sstate.selendboundary);
100 t->setCursor(bv, sstate.lpar, sstate.pos);
102 t->setCursor(bv, sstate.lpar, sstate.pos, true, sstate.boundary);
103 t->selection.cursor = t->cursor;
104 t->selection.set(false);
106 if (sstate.refresh) {
112 InsetText::InnerCache::InnerCache(boost::shared_ptr<LyXText> t)
119 InsetText::InsetText()
120 : UpdatableInset(), lt(0), in_update(false)
127 InsetText::InsetText(InsetText const & in, bool same_id)
128 : UpdatableInset(in, same_id), lt(0), in_update(false)
135 InsetText & InsetText::operator=(InsetText const & it)
142 void InsetText::init(InsetText const * ins, bool same_id)
145 setParagraphData(ins->par);
146 autoBreakRows = ins->autoBreakRows;
147 drawFrame_ = ins->drawFrame_;
148 frame_color = ins->frame_color;
154 p->setInsetOwner(this);
157 the_locking_inset = 0;
159 frame_color = LColor::insetframe;
160 autoBreakRows = false;
169 no_selection = false;
176 last_drawn_width = -1;
177 frame_is_visible = false;
183 InsetText::~InsetText()
190 Paragraph * tmp = par->next();
197 void InsetText::clear()
200 Paragraph * tmp = par->next();
209 Inset * InsetText::clone(Buffer const &, bool same_id) const
211 return new InsetText(*this, same_id);
215 void InsetText::write(Buffer const * buf, ostream & os) const
218 writeParagraphData(buf, os);
222 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
224 par->writeFile(buf, os, buf->params, 0);
228 void InsetText::read(Buffer const * buf, LyXLex & lex)
232 Paragraph * return_par = 0;
233 Paragraph::depth_type depth = 0;
234 LyXFont font(LyXFont::ALL_INHERIT);
240 token = lex.getString();
243 if (token == "\\end_inset") {
244 #ifndef NO_COMPABILITY
245 const_cast<Buffer*>(buf)->insertErtContents(par, pos, font, false);
250 if (const_cast<Buffer*>(buf)->
251 parseSingleLyXformat2Token(lex, par, return_par,
252 token, pos, depth, font)) {
253 // the_end read this should NEVER happen
254 lex.printError("\\the_end read in inset! Error in document!");
262 return_par->setInsetOwner(this);
263 return_par = return_par->next();
266 if (token != "\\end_inset") {
267 lex.printError("Missing \\end_inset at this point. "
274 int InsetText::ascent(BufferView * bv, LyXFont const &) const
277 Row * row = getLyXText(bv)->getRowNearY(y_temp);
278 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
283 int InsetText::descent(BufferView * bv, LyXFont const &) const
291 Row * row = lt->getRowNearY(y_temp);
292 insetDescent = lt->height - row->ascent_of_text() +
293 TEXT_TO_INSET_OFFSET;
300 int InsetText::width(BufferView * bv, LyXFont const &) const
302 insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
303 (2 * TEXT_TO_INSET_OFFSET);
304 insetWidth = max(insetWidth, 10);
309 int InsetText::textWidth(BufferView * bv, bool fordraw) const
312 if (!autoBreakRows) {
315 w = getMaxWidth(bv, this);
318 return max(w - (2 * TEXT_TO_INSET_OFFSET),
319 (int)getLyXText(bv)->width);
323 return w - (2 * TEXT_TO_INSET_OFFSET);
327 void InsetText::draw(BufferView * bv, LyXFont const & f,
328 int baseline, float & x, bool cleared) const
333 Painter & pain = bv->painter();
335 // this is the first thing we have to ask because if the x pos
336 // changed we have to do a complete rebreak of the text as we
337 // may have few space to draw in. Well we should check on this too
339 if (top_x != int(x)) {
341 int nw = getMaxWidth(bv, this);
342 if (nw > 0 && old_max_width != nw) {
345 bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
353 // repaint the background if needed
354 if (cleared && backgroundColor() != LColor::background) {
356 clearInset(pain, baseline, cleared);
360 // no draw is necessary !!!
361 if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
364 top_baseline = baseline;
366 if (need_update & CLEAR_FRAME)
367 clearFrame(pain, cleared);
374 x += static_cast<float>(scroll());
376 // if top_x differs we did it already
377 if (!cleared && (top_x == int(x)) &&
378 ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
379 (last_drawn_width!=insetWidth))) {
380 clearInset(pain, baseline, cleared);
386 frame_is_visible = false;
388 if (!cleared && (need_update == NONE)) {
390 drawFrame(pain, cleared);
394 top_baseline = baseline;
395 top_y = baseline - ascent(bv, f);
396 last_width = width(bv, f);
397 last_height = ascent(bv, f) + descent(bv, f);
399 if (cleared || (last_drawn_width != insetWidth)) {
401 clearInset(pain, baseline, cleared);
403 last_drawn_width = insetWidth;
406 if (the_locking_inset && (cpar(bv) == inset_par)
407 && (cpos(bv) == inset_pos)) {
408 inset_x = cx(bv) - top_x + drawTextXOffset;
409 inset_y = cy(bv) + drawTextYOffset;
411 if (!cleared && (need_update == CURSOR)
412 && !getLyXText(bv)->selection.set())
414 drawFrame(pain, cleared);
415 x += last_width; // was width(bv, f);
424 x += TEXT_TO_INSET_OFFSET;
427 Row * row = lt->getRowNearY(y);
428 int y_offset = baseline - row->ascent_of_text();
429 int ph = pain.paperHeight();
432 while ((row != 0) && ((y+row->height()) <= 0)) {
434 first += row->height();
440 if (cleared || (need_update&(INIT|FULL))) {
443 while ((row != 0) && (yf < ph)) {
444 lt->getVisibleRow(bv, y+y_offset, int(x), row,
450 } else if (!locked) {
451 if (need_update & CURSOR) {
452 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
453 lt->clearSelection();
454 lt->selection.cursor = lt->cursor;
456 bv->screen()->update(lt, bv, y_offset, int(x));
459 if (need_update & SELECTION)
460 bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
461 else if (need_update & CURSOR) {
462 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
463 lt->clearSelection();
464 lt->selection.cursor = lt->cursor;
466 bv->screen()->update(lt, bv, y_offset, int(x));
471 lt->status(bv, LyXText::UNCHANGED);
472 if ((need_update != CURSOR_PAR) &&
473 ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
474 drawFrame(pain, cleared);
475 else if (need_update & CLEAR_FRAME)
476 clearFrame(pain, cleared);
477 x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
478 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
480 } else if (need_update != INIT)
487 void InsetText::drawFrame(Painter & pain, bool cleared) const
489 static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
490 if (!frame_is_visible || cleared) {
491 frame_x = top_x + ttoD2;
492 frame_y = top_baseline - insetAscent + ttoD2;
493 frame_w = last_width - TEXT_TO_INSET_OFFSET;
494 frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
495 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
497 frame_is_visible = true;
502 void InsetText::clearFrame(Painter & pain, bool cleared) const
504 if (frame_is_visible) {
506 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
509 frame_is_visible = false;
514 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
517 if (reinit && owner()) {
518 owner()->update(bv, font, true);
523 if (reinit || need_update == INIT) {
531 owner()->update(bv, font, true);
535 if (the_locking_inset) {
536 inset_x = cx(bv) - top_x + drawTextXOffset;
537 inset_y = cy(bv) + drawTextYOffset;
538 the_locking_inset->update(bv, font, reinit);
546 int oldw = insetWidth;
547 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
548 if (oldw != insetWidth) {
556 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
559 lt->updateInset(bv, the_locking_inset);
561 if (lt->status() == LyXText::NEED_MORE_REFRESH)
569 void InsetText::setUpdateStatus(BufferView * bv, int what) const
577 // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
578 // if we don't break row so that we only have one row to update!
579 if ((lt->status() == LyXText::NEED_MORE_REFRESH) ||
581 (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
584 } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
585 need_update |= CURSOR_PAR;
588 // this to not draw a selection when we redraw all of it!
589 if (need_update & CURSOR && !(need_update & SELECTION)) {
590 if (lt->selection.set())
592 lt->clearSelection();
599 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
607 setUpdateStatus(bv, what);
608 if (((need_update != CURSOR) && (need_update != NONE)) ||
609 (lt->status() != LyXText::UNCHANGED) || lt->selection.set())
611 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
613 if (need_update == CURSOR)
615 bv->owner()->showState();
616 if (old_par != cpar(bv)) {
617 bv->owner()->setLayout(cpar(bv)->getLayout());
625 string const InsetText::editMessage() const
627 return _("Opened Text Inset");
631 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
633 UpdatableInset::edit(bv, x, y, button);
635 if (!bv->lockInset(this)) {
636 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
640 the_locking_inset = 0;
641 inset_pos = inset_x = inset_y = 0;
642 inset_boundary = false;
645 int tmp_y = (y < 0) ? 0 : y;
652 if (!checkAndActivateInset(bv, x, tmp_y, button))
653 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
655 lt->clearSelection();
658 updateLocal(bv, CURSOR, false);
660 // If the inset is empty set the language of the current font to the
661 // language to the surronding text (if different).
662 if (par->size() == 0 && !par->next() &&
663 bv->getParentLanguage(this) != lt->current_font.language()) {
664 LyXFont font(LyXFont::ALL_IGNORE);
665 font.setLanguage(bv->getParentLanguage(this));
666 setFont(bv, font, false);
673 void InsetText::edit(BufferView * bv, bool front)
675 UpdatableInset::edit(bv, front);
677 if (!bv->lockInset(this)) {
678 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
682 the_locking_inset = 0;
683 inset_pos = inset_x = inset_y = 0;
684 inset_boundary = false;
693 lt->setCursor(bv, par, 0);
698 int const pos = (p->size() ? p->size()-1 : p->size());
699 lt->setCursor(bv, p, pos);
701 lt->clearSelection();
704 updateLocal(bv, CURSOR, false);
706 // If the inset is empty set the language of the current font to the
707 // language to the surronding text (if different).
708 if (par->size() == 0 && !par->next() &&
709 bv->getParentLanguage(this) != lt->current_font.language()) {
710 LyXFont font(LyXFont::ALL_IGNORE);
711 font.setLanguage(bv->getParentLanguage(this));
712 setFont(bv, font, false);
719 void InsetText::insetUnlock(BufferView * bv)
721 if (the_locking_inset) {
722 the_locking_inset->insetUnlock(bv);
723 the_locking_inset = 0;
726 no_selection = false;
729 if (drawFrame_ == LOCKED)
730 code = CURSOR|CLEAR_FRAME;
738 if (lt->selection.set()) {
739 lt->clearSelection();
741 } else if (owner()) {
742 bv->owner()->setLayout(owner()->getLyXText(bv)
743 ->cursor.par()->getLayout());
745 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
746 updateLocal(bv, code, false);
752 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
754 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
758 if (inset == cpar(bv)->getInset(cpos(bv))) {
759 lyxerr[Debug::INSETS] << "OK" << endl;
760 the_locking_inset = inset;
761 inset_x = cx(bv) - top_x + drawTextXOffset;
762 inset_y = cy(bv) + drawTextYOffset;
763 inset_pos = cpos(bv);
764 inset_par = cpar(bv);
765 inset_boundary = cboundary(bv);
766 updateLocal(bv, CURSOR, false);
768 } else if (the_locking_inset && (the_locking_inset == inset)) {
769 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
770 lyxerr[Debug::INSETS] << "OK" << endl;
771 inset_x = cx(bv) - top_x + drawTextXOffset;
772 inset_y = cy(bv) + drawTextYOffset;
774 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
776 } else if (the_locking_inset) {
777 lyxerr[Debug::INSETS] << "MAYBE" << endl;
778 return the_locking_inset->lockInsetInInset(bv, inset);
780 lyxerr[Debug::INSETS] << "NOT OK" << endl;
785 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
788 if (!the_locking_inset)
790 if (the_locking_inset == inset) {
791 the_locking_inset->insetUnlock(bv);
792 getLyXText(bv)->updateInset(bv, inset);
793 the_locking_inset = 0;
795 moveRight(bv, false);
796 old_par = 0; // force layout setting
800 updateLocal(bv, CURSOR, false);
803 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
807 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
809 if (!the_locking_inset)
811 if (the_locking_inset != inset) {
812 getLyXText(bv)->updateInset(bv, the_locking_inset);
813 setUpdateStatus(bv, CURSOR_PAR);
814 return the_locking_inset->updateInsetInInset(bv, inset);
816 if (getLyXText(bv)->updateInset(bv, inset))
817 updateLocal(bv, CURSOR_PAR, false);
818 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
819 inset_x = cx(bv) - top_x + drawTextXOffset;
820 inset_y = cy(bv) + drawTextYOffset;
826 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
830 int tmp_x = x - drawTextXOffset;
831 int tmp_y = y + insetAscent - getLyXText(bv)->first;
832 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
835 if (the_locking_inset) {
836 if (the_locking_inset == inset) {
837 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
838 no_selection = false;
841 // otherwise unlock the_locking_inset and lock the new inset
842 the_locking_inset->insetUnlock(bv);
843 inset_x = cx(bv) - top_x + drawTextXOffset;
844 inset_y = cy(bv) + drawTextYOffset;
845 the_locking_inset = static_cast<UpdatableInset*>(inset);
846 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
847 inset->edit(bv, x - inset_x, y - inset_y, button);
848 if (the_locking_inset)
849 updateLocal(bv, CURSOR, false);
850 no_selection = false;
853 // otherwise only unlock the_locking_inset
854 the_locking_inset->insetUnlock(bv);
855 the_locking_inset = 0;
857 if (bv->theLockingInset()) {
858 if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
859 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
860 inset_x = cx(bv) - top_x + drawTextXOffset;
861 inset_y = cy(bv) + drawTextYOffset;
862 inset_pos = cpos(bv);
863 inset_par = cpar(bv);
864 inset_boundary = cboundary(bv);
865 the_locking_inset = uinset;
866 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
868 uinset->edit(bv, x - inset_x, y - inset_y, 0);
869 if (the_locking_inset)
870 updateLocal(bv, CURSOR, false);
871 no_selection = false;
875 if (!inset) { // && (button == 2)) {
876 bool paste_internally = false;
877 if ((button == 2) && getLyXText(bv)->selection.set()) {
878 localDispatch(bv, LFUN_COPY, "");
879 paste_internally = true;
886 lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent);
887 if (lt->selection.set()) {
888 lt->clearSelection();
889 updateLocal(bv, FULL, false);
891 lt->clearSelection();
893 bv->owner()->setLayout(cpar(bv)->getLayout());
895 // Insert primary selection with middle mouse
896 // if there is a local selection in the current buffer,
899 if (paste_internally)
900 localDispatch(bv, LFUN_PASTE, "");
902 localDispatch(bv, LFUN_PASTESELECTION,
909 no_selection = false;
913 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
915 UpdatableInset * inset = 0;
917 if (the_locking_inset) {
918 the_locking_inset->insetButtonRelease(bv,
919 x - inset_x, y - inset_y,
922 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
923 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
924 if (inset->editable() == Inset::HIGHLY_EDITABLE) {
925 inset->insetButtonRelease(bv,
927 y - inset_y, button);
929 inset_x = cx(bv) - top_x + drawTextXOffset;
930 inset_y = cy(bv) + drawTextYOffset;
931 inset->insetButtonRelease(bv,
933 y - inset_y, button);
935 x - inset_x, y - inset_y, button);
937 updateLocal(bv, CURSOR_PAR, false);
940 no_selection = false;
944 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
948 if (the_locking_inset) {
949 the_locking_inset->insetMotionNotify(bv, x - inset_x,
953 LyXText * t = getLyXText(bv);
955 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
957 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
958 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
959 updateLocal(bv, SELECTION, false);
964 void InsetText::insetKeyPress(XKeyEvent * xke)
966 if (the_locking_inset) {
967 the_locking_inset->insetKeyPress(xke);
973 UpdatableInset::RESULT
974 InsetText::localDispatch(BufferView * bv,
975 kb_action action, string const & arg)
977 no_selection = false;
978 UpdatableInset::RESULT
979 result= UpdatableInset::localDispatch(bv, action, arg);
980 if (result != UNDISPATCHED) {
985 if ((action < 0) && arg.empty())
988 if (the_locking_inset) {
989 result = the_locking_inset->localDispatch(bv, action, arg);
990 if (result == DISPATCHED_NOUPDATE)
992 else if (result == DISPATCHED) {
993 updateLocal(bv, CURSOR_PAR, false);
995 } else if (result == FINISHED) {
996 bool dispatched = false;
998 case LFUN_UNKNOWN_ACTION:
999 case LFUN_BREAKPARAGRAPH:
1000 case LFUN_BREAKLINE:
1001 moveRightIntern(bv, false, false);
1004 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1005 moveRightIntern(bv, false, false);
1009 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1010 moveRightIntern(bv, false, false);
1016 the_locking_inset = 0;
1021 hideInsetCursor(bv);
1024 lt = getLyXText(bv);
1029 case LFUN_SELFINSERT:
1030 if (bv->buffer()->isReadonly()) {
1031 // setErrorMessage(N_("Document is read only"));
1035 /* Automatically delete the currently selected
1036 * text and replace it with what is being
1037 * typed in now. Depends on lyxrc settings
1038 * "auto_region_delete", which defaults to
1041 setUndo(bv, Undo::INSERT,
1042 lt->cursor.par(), lt->cursor.par()->next());
1044 if (lyxrc.auto_region_delete) {
1045 if (lt->selection.set()) {
1046 lt->cutSelection(bv, false);
1049 lt->clearSelection();
1050 for (string::size_type i = 0; i < arg.length(); ++i) {
1051 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1054 lt->selection.cursor = lt->cursor;
1055 updateLocal(bv, CURSOR_PAR, true);
1056 result = DISPATCHED_NOUPDATE;
1058 // --- Cursor Movements -----------------------------------
1061 moveRight(bv, false, true);
1062 lt->setSelection(bv);
1063 updateLocal(bv, SELECTION, false);
1066 result = moveRight(bv);
1068 updateLocal(bv, CURSOR, false);
1072 moveLeft(bv, false, true);
1073 lt->setSelection(bv);
1074 updateLocal(bv, SELECTION, false);
1078 result = moveLeft(bv);
1079 updateLocal(bv, CURSOR, false);
1084 lt->setSelection(bv);
1085 updateLocal(bv, SELECTION, false);
1089 result = moveDown(bv);
1090 updateLocal(bv, CURSOR, false);
1095 lt->setSelection(bv);
1096 updateLocal(bv, SELECTION, false);
1100 result = moveUp(bv);
1101 updateLocal(bv, CURSOR, false);
1106 updateLocal(bv, CURSOR, false);
1110 updateLocal(bv, CURSOR, false);
1112 case LFUN_BACKSPACE: {
1113 setUndo(bv, Undo::DELETE,
1114 lt->cursor.par(), lt->cursor.par()->next());
1115 if (lt->selection.set())
1116 lt->cutSelection(bv);
1119 updateLocal(bv, CURSOR_PAR, true);
1124 setUndo(bv, Undo::DELETE,
1125 lt->cursor.par(), lt->cursor.par()->next());
1126 if (lt->selection.set()) {
1127 lt->cutSelection(bv);
1131 updateLocal(bv, CURSOR_PAR, true);
1136 setUndo(bv, Undo::DELETE,
1137 lt->cursor.par(), lt->cursor.par()->next());
1138 lt->cutSelection(bv);
1139 updateLocal(bv, CURSOR_PAR, true);
1145 lt->copySelection(bv);
1146 updateLocal(bv, CURSOR_PAR, false);
1148 case LFUN_PASTESELECTION:
1150 string const clip(bv->getClipboard());
1154 if (arg == "paragraph") {
1155 lt->insertStringAsParagraphs(bv, clip);
1157 lt->insertStringAsLines(bv, clip);
1159 updateLocal(bv, CURSOR_PAR, true);
1163 if (!autoBreakRows) {
1165 if (CutAndPaste::nrOfParagraphs() > 1) {
1166 WriteAlert(_("Impossible operation"),
1167 _("Cannot include more than one paragraph!"),
1172 setUndo(bv, Undo::INSERT,
1173 lt->cursor.par(), lt->cursor.par()->next());
1174 lt->pasteSelection(bv);
1175 updateLocal(bv, CURSOR_PAR, true);
1179 case LFUN_BREAKPARAGRAPH:
1180 if (!autoBreakRows) {
1181 result = DISPATCHED;
1184 lt->breakParagraph(bv, 0);
1185 updateLocal(bv, FULL, true);
1187 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1188 if (!autoBreakRows) {
1189 result = DISPATCHED;
1192 lt->breakParagraph(bv, 1);
1193 updateLocal(bv, FULL, true);
1196 case LFUN_BREAKLINE: {
1197 if (!autoBreakRows) {
1198 result = DISPATCHED;
1201 setUndo(bv, Undo::INSERT,
1202 lt->cursor.par(), lt->cursor.par()->next());
1203 lt->insertChar(bv, Paragraph::META_NEWLINE);
1204 updateLocal(bv, CURSOR_PAR, true);
1209 // do not set layouts on non breakable textinsets
1210 if (autoBreakRows) {
1211 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1213 // Derive layout number from given argument (string)
1214 // and current buffer's textclass (number). */
1215 LyXTextClassList::ClassList::size_type tclass =
1216 bv->buffer()->params.textclass;
1217 std::pair <bool, LyXTextClass::size_type> layout =
1218 textclasslist.NumberOfLayout(tclass, arg);
1220 // If the entry is obsolete, use the new one instead.
1222 string obs = textclasslist.Style(tclass,layout.second).
1225 layout = textclasslist.NumberOfLayout(tclass, obs);
1228 // see if we found the layout number:
1229 if (!layout.first) {
1230 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1231 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1235 if (cur_layout != layout.second) {
1236 cur_layout = layout.second;
1237 lt->setLayout(bv, layout.second);
1238 bv->owner()->setLayout(cpar(bv)->getLayout());
1239 updateLocal(bv, CURSOR_PAR, true);
1242 // reset the layout box
1243 bv->owner()->setLayout(cpar(bv)->getLayout());
1246 case LFUN_PARAGRAPH_SPACING:
1247 // This one is absolutely not working. When fiddling with this
1248 // it also seems to me that the paragraphs inside the insettext
1249 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1251 Paragraph * par = lt->cursor.par();
1252 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1253 float cur_value = 1.0;
1254 if (cur_spacing == Spacing::Other) {
1255 cur_value = par->params().spacing().getValue();
1258 istringstream istr(arg.c_str());
1261 Spacing::Space new_spacing = cur_spacing;
1262 float new_value = cur_value;
1264 lyxerr << "Missing argument to `paragraph-spacing'"
1266 } else if (tmp == "single") {
1267 new_spacing = Spacing::Single;
1268 } else if (tmp == "onehalf") {
1269 new_spacing = Spacing::Onehalf;
1270 } else if (tmp == "double") {
1271 new_spacing = Spacing::Double;
1272 } else if (tmp == "other") {
1273 new_spacing = Spacing::Other;
1276 lyxerr << "new_value = " << tmpval << endl;
1279 } else if (tmp == "default") {
1280 new_spacing = Spacing::Default;
1282 lyxerr << _("Unknown spacing argument: ")
1285 if (cur_spacing != new_spacing || cur_value != new_value) {
1286 par->params().spacing(Spacing(new_spacing, new_value));
1287 updateLocal(bv, CURSOR_PAR, true);
1293 if (!bv->Dispatch(action, arg))
1294 result = UNDISPATCHED;
1298 /// If the action has deleted all text in the inset, we need to change the
1299 // language to the language of the surronding text.
1300 if (par->size() == 0 && !par->next()) {
1301 LyXFont font(LyXFont::ALL_IGNORE);
1302 font.setLanguage(bv->getParentLanguage(this));
1303 setFont(bv, font, false);
1306 if (result != FINISHED) {
1307 showInsetCursor(bv);
1309 bv->unlockInset(this);
1316 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1319 buf->latexParagraphs(os, par, 0, texrow);
1320 return texrow.rows();
1324 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1326 Paragraph * p = par;
1327 unsigned int lines = 0;
1330 string const tmp = buf->asciiParagraph(p, linelen);
1331 lines += countChar(tmp, '\n');
1339 int InsetText::docBook(Buffer const * buf, ostream & os) const
1341 Paragraph * p = par;
1342 unsigned int lines = 0;
1347 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1355 void InsetText::validate(LaTeXFeatures & features) const
1357 Paragraph * p = par;
1359 p->validate(features);
1365 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1367 if (textclasslist.Style(buf->params.textclass,
1368 p->getLayout()).labeltype != LABEL_MANUAL)
1371 return p->beginningOfMainBody();
1375 void InsetText::getCursorPos(BufferView * bv,
1376 int & x, int & y) const
1378 if (the_locking_inset) {
1379 the_locking_inset->getCursorPos(bv, x, y);
1387 unsigned int InsetText::insetInInsetY()
1389 if (!the_locking_inset)
1392 return (inset_y + the_locking_inset->insetInInsetY());
1396 void InsetText::toggleInsetCursor(BufferView * bv)
1398 if (the_locking_inset) {
1399 the_locking_inset->toggleInsetCursor(bv);
1403 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1405 int const asc = lyxfont::maxAscent(font);
1406 int const desc = lyxfont::maxDescent(font);
1408 if (isCursorVisible())
1409 bv->hideLockedInsetCursor();
1411 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1412 toggleCursorVisible();
1416 void InsetText::showInsetCursor(BufferView * bv, bool show)
1418 if (the_locking_inset) {
1419 the_locking_inset->showInsetCursor(bv, show);
1422 if (!isCursorVisible()) {
1423 LyXFont const font =
1424 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1426 int const asc = lyxfont::maxAscent(font);
1427 int const desc = lyxfont::maxDescent(font);
1429 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1431 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1432 setCursorVisible(true);
1437 void InsetText::hideInsetCursor(BufferView * bv)
1439 if (isCursorVisible()) {
1440 bv->hideLockedInsetCursor();
1441 setCursorVisible(false);
1443 if (the_locking_inset)
1444 the_locking_inset->hideInsetCursor(bv);
1448 void InsetText::fitInsetCursor(BufferView * bv) const
1450 if (the_locking_inset) {
1451 the_locking_inset->fitInsetCursor(bv);
1454 LyXFont const font =
1455 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1457 int const asc = lyxfont::maxAscent(font);
1458 int const desc = lyxfont::maxDescent(font);
1460 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1464 UpdatableInset::RESULT
1465 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1467 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1468 return moveLeftIntern(bv, false, activate_inset, selecting);
1470 return moveRightIntern(bv, false, activate_inset, selecting);
1474 UpdatableInset::RESULT
1475 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1477 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1478 return moveRightIntern(bv, true, activate_inset, selecting);
1480 return moveLeftIntern(bv, true, activate_inset, selecting);
1484 UpdatableInset::RESULT
1485 InsetText::moveRightIntern(BufferView * bv, bool behind,
1486 bool activate_inset, bool selecting)
1488 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1490 if (activate_inset && checkAndActivateInset(bv, behind))
1492 getLyXText(bv)->cursorRight(bv);
1494 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1495 return DISPATCHED_NOUPDATE;
1499 UpdatableInset::RESULT
1500 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1501 bool activate_inset, bool selecting)
1503 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1505 getLyXText(bv)->cursorLeft(bv);
1507 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1508 if (activate_inset && checkAndActivateInset(bv, behind))
1510 return DISPATCHED_NOUPDATE;
1514 UpdatableInset::RESULT
1515 InsetText::moveUp(BufferView * bv)
1517 if (!crow(bv)->previous())
1519 getLyXText(bv)->cursorUp(bv);
1520 return DISPATCHED_NOUPDATE;
1524 UpdatableInset::RESULT
1525 InsetText::moveDown(BufferView * bv)
1527 if (!crow(bv)->next())
1529 getLyXText(bv)->cursorDown(bv);
1530 return DISPATCHED_NOUPDATE;
1534 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1536 if (the_locking_inset) {
1537 if (the_locking_inset->insetAllowed(inset))
1538 return the_locking_inset->insertInset(bv, inset);
1541 inset->setOwner(this);
1542 hideInsetCursor(bv);
1546 lt = getLyXText(bv);
1549 lt->insertInset(bv, inset);
1551 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1552 (cpar(bv)->getInset(cpos(bv)) != inset))
1556 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1557 showInsetCursor(bv);
1564 bool InsetText::insetAllowed(Inset::Code code) const
1566 if (the_locking_inset)
1567 return the_locking_inset->insetAllowed(code);
1572 UpdatableInset * InsetText::getLockingInset() const
1574 return the_locking_inset ? the_locking_inset->getLockingInset() :
1575 const_cast<InsetText *>(this);
1579 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1583 if (the_locking_inset)
1584 return the_locking_inset->getFirstLockingInsetOfType(c);
1589 bool InsetText::showInsetDialog(BufferView * bv) const
1591 if (the_locking_inset)
1592 return the_locking_inset->showInsetDialog(bv);
1597 std::vector<string> const InsetText::getLabelList() const
1599 std::vector<string> label_list;
1601 Paragraph * tpar = par;
1603 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1604 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1605 for (; beg != end; ++beg) {
1606 std::vector<string> const l = (*beg)->getLabelList();
1607 label_list.insert(label_list.end(), l.begin(), l.end());
1609 tpar = tpar->next();
1615 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1618 if (the_locking_inset) {
1619 the_locking_inset->setFont(bv, font, toggleall, selectall);
1622 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1623 getLyXText(bv)->setFont(bv, font, toggleall);
1628 lt = getLyXText(bv);
1631 if (lt->selection.set()) {
1632 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1636 lt->toggleFree(bv, font, toggleall);
1638 lt->clearSelection();
1640 if (selectall || lt->selection.set())
1641 updateLocal(bv, FULL, true);
1643 updateLocal(bv, CURSOR_PAR, true);
1649 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1651 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1655 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1656 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1658 LyXFont const font =
1659 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1661 x = inset->width(bv, font);
1662 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1665 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1667 //inset_x = cx(bv) - top_x + drawTextXOffset;
1668 //inset_y = cy(bv) + drawTextYOffset;
1669 inset->edit(bv, x, y, 0);
1670 if (!the_locking_inset)
1672 updateLocal(bv, CURSOR, false);
1679 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1682 x -= drawTextXOffset;
1684 int dummyy = y + insetAscent;
1685 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1692 inset_x = cx(bv) - top_x + drawTextXOffset;
1693 inset_y = cy(bv) + drawTextYOffset;
1694 inset->edit(bv, x - inset_x, y - inset_y, button);
1695 if (!the_locking_inset)
1697 updateLocal(bv, CURSOR, false);
1704 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1707 int w = UpdatableInset::getMaxWidth(bv, inset);
1712 w = w - top_x + owner()->x();
1715 w -= (2 * TEXT_TO_INSET_OFFSET);
1718 return UpdatableInset::getMaxWidth(bv, inset);
1723 void InsetText::setParagraphData(Paragraph * p)
1725 // we have to unlock any locked inset otherwise we're in troubles
1726 the_locking_inset = 0;
1728 Paragraph * tmp = par->next();
1733 par = new Paragraph(*p);
1734 par->setInsetOwner(this);
1735 Paragraph * np = par;
1738 np->next(new Paragraph(*p));
1739 np->next()->previous(np);
1741 np->setInsetOwner(this);
1743 reinitLyXText(true);
1747 void InsetText::setText(string const & data)
1750 LyXFont font(LyXFont::ALL_SANE);
1751 for (unsigned int i=0; i < data.length(); ++i)
1752 par->insertChar(i, data[i], font);
1756 void InsetText::setAutoBreakRows(bool flag)
1758 if (flag != autoBreakRows) {
1759 autoBreakRows = flag;
1763 reinitLyXText(true);
1768 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1770 if (how != drawFrame_) {
1773 updateLocal(bv, DRAW_FRAME, false);
1778 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1780 if (frame_color != col) {
1783 updateLocal(bv, DRAW_FRAME, false);
1788 int InsetText::cx(BufferView * bv) const
1792 lt = getLyXText(bv);
1795 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1796 if (the_locking_inset) {
1797 LyXFont font = lt->getFont(bv->buffer(),
1800 if (font.isVisibleRightToLeft())
1801 x -= the_locking_inset->width(bv, font);
1809 int InsetText::cy(BufferView * bv) const
1812 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1816 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1818 return getLyXText(bv)->cursor.pos();
1822 Paragraph * InsetText::cpar(BufferView * bv) const
1824 return getLyXText(bv)->cursor.par();
1828 bool InsetText::cboundary(BufferView * bv) const
1830 return getLyXText(bv)->cursor.boundary();
1834 Row * InsetText::crow(BufferView * bv) const
1836 return getLyXText(bv)->cursor.row();
1840 LyXText * InsetText::getLyXText(BufferView const * lbv,
1841 bool const recursive) const
1843 if (!recursive && (cached_bview == lbv))
1844 return cached_text.get();
1846 // Super UGLY! (Lgb)
1847 BufferView * bv = const_cast<BufferView *>(lbv);
1850 Cache::iterator it = cache.find(bv);
1852 if (it != cache.end()) {
1853 if (lt || !it->second.remove) {
1854 lyx::Assert(it->second.text.get());
1855 cached_text = it->second.text;
1856 if (recursive && the_locking_inset) {
1857 return the_locking_inset->getLyXText(bv, true);
1859 return cached_text.get();
1860 } else if (it->second.remove) {
1862 saveLyXTextState(it->second.text.get());
1869 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1870 cached_text->init(bv);
1871 restoreLyXTextState(bv, cached_text.get());
1873 cache.insert(make_pair(bv, cached_text));
1875 if (the_locking_inset && recursive) {
1876 return the_locking_inset->getLyXText(bv);
1878 return cached_text.get();
1882 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1886 Cache::iterator it = cache.find(bv);
1888 if (it == cache.end()) {
1892 lyx::Assert(it->second.text.get());
1894 it->second.remove = true;
1896 /// then remove all LyXText in text-insets
1897 Paragraph * p = par;
1898 for (; p; p = p->next()) {
1899 p->deleteInsetsLyXText(bv);
1905 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1907 if (!par->next() && !par->size()) // no data, resize not neccessary!
1909 // one endless line, resize normally not necessary
1910 if (!force && getMaxWidth(bv, this) < 0)
1913 Cache::iterator it = cache.find(bv);
1914 if (it == cache.end()) {
1917 lyx::Assert(it->second.text.get());
1919 LyXText * t = it->second.text.get();
1920 saveLyXTextState(t);
1921 for (Paragraph * p = par; p; p = p->next()) {
1922 p->resizeInsetsLyXText(bv);
1925 restoreLyXTextState(bv, t);
1926 if (the_locking_inset) {
1927 inset_x = cx(bv) - top_x + drawTextXOffset;
1928 inset_y = cy(bv) + drawTextYOffset;
1932 t->first = bv->screen()->topCursorVisible(t);
1935 updateLocal(bv, FULL, false);
1936 // this will scroll the screen such that the cursor becomes visible
1937 bv->updateScrollbar();
1939 need_update |= FULL;
1944 void InsetText::reinitLyXText(bool wrong_cursor) const
1946 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1947 lyx::Assert(it->second.text.get());
1949 LyXText * t = it->second.text.get();
1950 BufferView * bv = it->first;
1955 t->clearSelection();
1957 saveLyXTextState(t);
1958 for (Paragraph * p = par; p; p = p->next()) {
1959 p->resizeInsetsLyXText(bv);
1962 restoreLyXTextState(bv, t);
1963 if (the_locking_inset) {
1964 inset_x = cx(bv) - top_x + drawTextXOffset;
1965 inset_y = cy(bv) + drawTextYOffset;
1968 t->first = bv->screen()->topCursorVisible(t);
1971 updateLocal(bv, FULL, false);
1972 // this will scroll the screen such that the cursor becomes visible
1973 bv->updateScrollbar();
1981 void InsetText::removeNewlines()
1983 for (Paragraph * p = par; p; p = p->next()) {
1984 for (int i = 0; i < p->size(); ++i) {
1985 if (p->getChar(i) == Paragraph::META_NEWLINE)
1992 bool InsetText::nodraw() const
1994 if (the_locking_inset)
1995 return the_locking_inset->nodraw();
1996 return UpdatableInset::nodraw();
2000 int InsetText::scroll(bool recursive) const
2002 int sx = UpdatableInset::scroll(false);
2004 if (recursive && the_locking_inset)
2005 sx += the_locking_inset->scroll(recursive);
2011 bool InsetText::doClearArea() const
2013 return !locked || (need_update & (FULL|INIT));
2017 void InsetText::selectAll(BufferView * bv)
2019 getLyXText(bv)->cursorTop(bv);
2020 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2021 getLyXText(bv)->cursorBottom(bv);
2022 getLyXText(bv)->setSelection(bv);
2026 void InsetText::clearSelection(BufferView * bv)
2028 getLyXText(bv)->clearSelection();
2032 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2035 int h = insetAscent + insetDescent;
2036 int ty = baseline - insetAscent;
2042 if ((ty + h) > pain.paperHeight())
2043 h = pain.paperHeight();
2044 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2045 w = pain.paperWidth();
2046 // w -= TEXT_TO_INSET_OFFSET;
2047 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2050 frame_is_visible = false;
2054 Paragraph * InsetText::getParFromID(int id) const
2057 Paragraph * result = par;
2058 Paragraph * ires = 0;
2059 while (result && result->id() != id) {
2060 if ((ires = result->getParFromID(id)))
2062 result = result->next();
2066 Paragraph * tmp = par;
2068 int tmp_id = tmp->id();
2069 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2070 if (tmp->id() == id) {
2073 Paragraph * tmp2 = tmp->getParFromID(id);
2084 Paragraph * InsetText::firstParagraph() const
2087 if (the_locking_inset)
2088 if ((result = the_locking_inset->firstParagraph()))
2094 LyXCursor const & InsetText::cursor(BufferView * bv) const
2096 if (the_locking_inset)
2097 return the_locking_inset->cursor(bv);
2098 return getLyXText(bv)->cursor;
2102 Paragraph * InsetText::paragraph() const
2108 void InsetText::paragraph(Paragraph * p)
2112 // we now have to update/redraw all instances
2113 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2118 // redraw myself when asked for
2119 need_update |= INIT;
2123 Inset * InsetText::getInsetFromID(int id_arg) const
2126 return const_cast<InsetText *>(this);
2128 Paragraph * lp = par;
2131 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2132 en = lp->inset_iterator_end();
2135 if ((*it)->id() == id_arg)
2137 Inset * in = (*it)->getInsetFromID(id_arg);
2147 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2153 lt = getLyXText(bv);
2156 if (the_locking_inset) {
2157 str = the_locking_inset->selectNextWord(bv, value);
2164 #warning Dekel please have a look on this one RTL? (Jug)
2165 // we have to go on checking so move cusor to the right
2166 lt->cursor.pos(lt->cursor.pos() + 1);
2168 str = lt->selectNextWord(bv, value);
2170 bv->unlockInset(const_cast<InsetText *>(this));
2179 void InsetText::selectSelectedWord(BufferView * bv)
2181 if (the_locking_inset) {
2182 the_locking_inset->selectSelectedWord(bv);
2185 getLyXText(bv)->selectSelectedWord(bv);
2186 updateLocal(bv, SELECTION, false);
2190 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2192 if (the_locking_inset) {
2193 the_locking_inset->toggleSelection(bv, kill_selection);
2197 lt = getLyXText(bv);
2201 int x = top_x + TEXT_TO_INSET_OFFSET;
2204 Row * row = lt->getRowNearY(y);
2205 int y_offset = top_baseline - row->ascent_of_text();
2207 while ((row != 0) && ((y+row->height()) <= 0)) {
2214 if (need_update & SELECTION)
2216 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2222 bool InsetText::searchForward(BufferView * bv, string const & str,
2223 bool const & cs, bool const & mw)
2225 if (the_locking_inset) {
2226 if (the_locking_inset->searchForward(bv, str, cs, mw))
2230 lt = getLyXText(bv);
2233 Paragraph * lpar = lt->cursor.par();
2234 Paragraph::size_type pos = lt->cursor.pos();
2235 if (pos < lpar->size() - 1)
2239 lpar = lpar->next();
2246 lt->setCursor(bv, lpar, pos);
2250 if (LyXFind(bv, str, true, true, cs , mw)) {
2253 // we have to unlock ourself in this function by default!
2254 bv->unlockInset(const_cast<InsetText *>(this));
2258 bool InsetText::searchBackward(BufferView * bv, string const & str,
2259 bool const & cs, bool const & mw)
2261 if (the_locking_inset)
2262 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2264 if (LyXFind(bv, str, false, true, cs, mw)) {
2267 // we have to unlock ourself in this function by default!
2268 bv->unlockInset(const_cast<InsetText *>(this));