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()
127 InsetText::InsetText(InsetText const & ins, bool same_id)
133 autoBreakRows = ins.autoBreakRows;
137 InsetText & InsetText::operator=(InsetText const & it)
140 autoBreakRows = it.autoBreakRows;
145 void InsetText::init(InsetText const * ins, bool same_id)
153 the_locking_inset = 0;
155 no_selection = false;
159 autoBreakRows = false;
162 frame_color = LColor::insetframe;
164 setParagraphData(ins->par);
165 autoBreakRows = ins->autoBreakRows;
166 drawFrame_ = ins->drawFrame_;
167 frame_color = ins->frame_color;
171 par->setInsetOwner(this);
174 last_drawn_width = -1;
175 frame_is_visible = false;
182 InsetText::~InsetText()
189 Paragraph * tmp = par->next();
196 void InsetText::clear()
199 Paragraph * tmp = par->next();
208 Inset * InsetText::clone(Buffer const &, bool same_id) const
210 return new InsetText(*this, same_id);
214 void InsetText::write(Buffer const * buf, ostream & os) const
217 writeParagraphData(buf, os);
221 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
223 par->writeFile(buf, os, buf->params, 0);
227 void InsetText::read(Buffer const * buf, LyXLex & lex)
231 Paragraph * return_par = 0;
232 Paragraph::depth_type depth = 0;
233 LyXFont font(LyXFont::ALL_INHERIT);
239 token = lex.GetString();
242 if (token == "\\end_inset") {
243 #ifndef NO_COMPABILITY
244 const_cast<Buffer*>(buf)->insertErtContents(par, pos, font, false);
249 if (const_cast<Buffer*>(buf)->
250 parseSingleLyXformat2Token(lex, par, return_par,
251 token, pos, depth, font)) {
252 // the_end read this should NEVER happen
253 lex.printError("\\the_end read in inset! Error in document!");
261 return_par->setInsetOwner(this);
262 return_par = return_par->next();
265 if (token != "\\end_inset") {
266 lex.printError("Missing \\end_inset at this point. "
273 int InsetText::ascent(BufferView * bv, LyXFont const &) const
276 Row * row = getLyXText(bv)->getRowNearY(y_temp);
277 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
282 int InsetText::descent(BufferView * bv, LyXFont const &) const
290 Row * row = lt->getRowNearY(y_temp);
291 insetDescent = lt->height - row->ascent_of_text() +
292 TEXT_TO_INSET_OFFSET;
299 int InsetText::width(BufferView * bv, LyXFont const &) const
301 insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
302 (2 * TEXT_TO_INSET_OFFSET);
303 insetWidth = max(insetWidth, 10);
308 int InsetText::textWidth(BufferView * bv, bool fordraw) const
311 if (!autoBreakRows) {
314 w = getMaxWidth(bv, this);
317 return max(w - (2 * TEXT_TO_INSET_OFFSET),
318 (int)getLyXText(bv)->width);
322 return w - (2 * TEXT_TO_INSET_OFFSET);
326 void InsetText::draw(BufferView * bv, LyXFont const & f,
327 int baseline, float & x, bool cleared) const
332 Painter & pain = bv->painter();
334 // this is the first thing we have to ask because if the x pos
335 // changed we have to do a complete rebreak of the text as we
336 // may have few space to draw in. Well we should check on this too
338 if (top_x != int(x)) {
340 int nw = getMaxWidth(bv, this);
341 if (nw > 0 && old_max_width != nw) {
344 bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
351 // repaint the background if needed
352 if (cleared && backgroundColor() != LColor::background) {
354 clearInset(pain, baseline, cleared);
358 // no draw is necessary !!!
359 if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
361 top_baseline = baseline;
363 if (need_update & CLEAR_FRAME)
364 clearFrame(pain, cleared);
371 x += static_cast<float>(scroll());
373 // if top_x differs we have a rule down and we don't have to clear anything
374 if (!cleared && (top_x == int(x)) &&
375 ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
376 (last_drawn_width!=insetWidth))) {
377 clearInset(pain, baseline, cleared);
382 frame_is_visible = false;
384 if (!cleared && (need_update == NONE)) {
386 drawFrame(pain, cleared);
390 top_baseline = baseline;
391 top_y = baseline - ascent(bv, f);
392 last_width = width(bv, f);
393 last_height = ascent(bv, f) + descent(bv, f);
395 if (cleared || (last_drawn_width != insetWidth)) {
397 clearInset(pain, baseline, cleared);
399 last_drawn_width = insetWidth;
402 if (the_locking_inset && (cpar(bv) == inset_par)
403 && (cpos(bv) == inset_pos)) {
404 inset_x = cx(bv) - top_x + drawTextXOffset;
405 inset_y = cy(bv) + drawTextYOffset;
407 if (!cleared && (need_update == CURSOR)
408 && !getLyXText(bv)->selection.set())
410 drawFrame(pain, cleared);
411 x += last_width; // was width(bv, f);
420 x += TEXT_TO_INSET_OFFSET;
423 Row * row = lt->getRowNearY(y);
424 int y_offset = baseline - row->ascent_of_text();
425 int ph = pain.paperHeight();
428 while ((row != 0) && ((y+row->height()) <= 0)) {
430 first += row->height();
436 if (cleared || (need_update&(INIT|FULL))) {
439 while ((row != 0) && (yf < ph)) {
440 lt->getVisibleRow(bv, y+y_offset, int(x), row,
446 } else if (!locked) {
447 if (need_update & CURSOR) {
448 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
449 lt->clearSelection();
450 lt->selection.cursor = lt->cursor;
452 bv->screen()->update(lt, bv, y_offset, int(x));
455 if (need_update & SELECTION)
456 bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
457 else if (need_update & CURSOR) {
458 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
459 lt->clearSelection();
460 lt->selection.cursor = lt->cursor;
462 bv->screen()->update(lt, bv, y_offset, int(x));
467 lt->status(bv, LyXText::UNCHANGED);
468 if ((need_update != CURSOR_PAR) &&
469 ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
470 drawFrame(pain, cleared);
471 else if (need_update & CLEAR_FRAME)
472 clearFrame(pain, cleared);
473 x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
474 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
476 } else if (need_update != INIT)
483 void InsetText::drawFrame(Painter & pain, bool cleared) const
485 static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
486 if (!frame_is_visible || cleared) {
487 frame_x = top_x + ttoD2;
488 frame_y = top_baseline - insetAscent + ttoD2;
489 frame_w = last_width - TEXT_TO_INSET_OFFSET;
490 frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
491 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
493 frame_is_visible = true;
498 void InsetText::clearFrame(Painter & pain, bool cleared) const
500 if (frame_is_visible) {
502 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
505 frame_is_visible = false;
510 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
519 owner()->update(bv, font, true);
523 if (the_locking_inset) {
524 inset_x = cx(bv) - top_x + drawTextXOffset;
525 inset_y = cy(bv) + drawTextYOffset;
526 the_locking_inset->update(bv, font, reinit);
534 int oldw = insetWidth;
535 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
536 if (oldw != insetWidth) {
544 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
547 lt->updateInset(bv, the_locking_inset);
549 if (lt->status() == LyXText::NEED_MORE_REFRESH)
557 void InsetText::setUpdateStatus(BufferView * bv, int what) const
565 // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
566 // if we don't break row so that we only have one row to update!
567 if ((lt->status() == LyXText::NEED_MORE_REFRESH) ||
569 (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
572 } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
573 need_update |= CURSOR_PAR;
576 // this to not draw a selection when we redraw all of it!
577 if (need_update & CURSOR && !(need_update & SELECTION)) {
578 if (lt->selection.set())
580 lt->clearSelection();
587 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
595 setUpdateStatus(bv, what);
596 if (((need_update != CURSOR) && (need_update != NONE)) ||
597 (lt->status() != LyXText::UNCHANGED) || lt->selection.set())
599 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
601 if (need_update == CURSOR)
603 bv->owner()->showState();
604 if (old_par != cpar(bv)) {
605 bv->owner()->setLayout(cpar(bv)->getLayout());
613 string const InsetText::editMessage() const
615 return _("Opened Text Inset");
619 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
621 UpdatableInset::edit(bv, x, y, button);
623 if (!bv->lockInset(this)) {
624 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
628 the_locking_inset = 0;
629 inset_pos = inset_x = inset_y = 0;
630 inset_boundary = false;
633 int tmp_y = (y < 0) ? 0 : y;
640 if (!checkAndActivateInset(bv, x, tmp_y, button))
641 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
643 lt->clearSelection();
646 updateLocal(bv, CURSOR, false);
648 // If the inset is empty set the language of the current font to the
649 // language to the surronding text (if different).
650 if (par->size() == 0 && !par->next() &&
651 bv->getParentLanguage(this) != lt->current_font.language()) {
652 LyXFont font(LyXFont::ALL_IGNORE);
653 font.setLanguage(bv->getParentLanguage(this));
654 setFont(bv, font, false);
661 void InsetText::edit(BufferView * bv, bool front)
663 UpdatableInset::edit(bv, front);
665 if (!bv->lockInset(this)) {
666 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
670 the_locking_inset = 0;
671 inset_pos = inset_x = inset_y = 0;
672 inset_boundary = false;
681 lt->setCursor(bv, par, 0);
686 int const pos = (p->size() ? p->size()-1 : p->size());
687 lt->setCursor(bv, p, pos);
689 lt->clearSelection();
692 updateLocal(bv, CURSOR, false);
694 // If the inset is empty set the language of the current font to the
695 // language to the surronding text (if different).
696 if (par->size() == 0 && !par->next() &&
697 bv->getParentLanguage(this) != lt->current_font.language()) {
698 LyXFont font(LyXFont::ALL_IGNORE);
699 font.setLanguage(bv->getParentLanguage(this));
700 setFont(bv, font, false);
707 void InsetText::insetUnlock(BufferView * bv)
709 if (the_locking_inset) {
710 the_locking_inset->insetUnlock(bv);
711 the_locking_inset = 0;
714 no_selection = false;
717 if (drawFrame_ == LOCKED)
718 code = CURSOR|CLEAR_FRAME;
726 if (lt->selection.set()) {
727 lt->clearSelection();
729 } else if (owner()) {
730 bv->owner()->setLayout(owner()->getLyXText(bv)
731 ->cursor.par()->getLayout());
733 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
734 updateLocal(bv, code, false);
740 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
742 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
746 if (inset == cpar(bv)->getInset(cpos(bv))) {
747 lyxerr[Debug::INSETS] << "OK" << endl;
748 the_locking_inset = inset;
749 inset_x = cx(bv) - top_x + drawTextXOffset;
750 inset_y = cy(bv) + drawTextYOffset;
751 inset_pos = cpos(bv);
752 inset_par = cpar(bv);
753 inset_boundary = cboundary(bv);
754 updateLocal(bv, CURSOR, false);
756 } else if (the_locking_inset && (the_locking_inset == inset)) {
757 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
758 lyxerr[Debug::INSETS] << "OK" << endl;
759 inset_x = cx(bv) - top_x + drawTextXOffset;
760 inset_y = cy(bv) + drawTextYOffset;
762 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
764 } else if (the_locking_inset) {
765 lyxerr[Debug::INSETS] << "MAYBE" << endl;
766 return the_locking_inset->lockInsetInInset(bv, inset);
768 lyxerr[Debug::INSETS] << "NOT OK" << endl;
773 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
776 if (!the_locking_inset)
778 if (the_locking_inset == inset) {
779 the_locking_inset->insetUnlock(bv);
780 getLyXText(bv)->updateInset(bv, inset);
781 the_locking_inset = 0;
783 moveRight(bv, false);
784 old_par = 0; // force layout setting
788 updateLocal(bv, CURSOR, false);
791 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
795 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
797 if (!the_locking_inset)
799 if (the_locking_inset != inset) {
800 getLyXText(bv)->updateInset(bv, the_locking_inset);
801 setUpdateStatus(bv, CURSOR_PAR);
802 return the_locking_inset->updateInsetInInset(bv, inset);
804 if (getLyXText(bv)->updateInset(bv, inset))
805 updateLocal(bv, CURSOR_PAR, false);
806 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
807 inset_x = cx(bv) - top_x + drawTextXOffset;
808 inset_y = cy(bv) + drawTextYOffset;
814 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
818 int tmp_x = x - drawTextXOffset;
819 int tmp_y = y + insetAscent - getLyXText(bv)->first;
820 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
823 if (the_locking_inset) {
824 if (the_locking_inset == inset) {
825 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
826 no_selection = false;
829 // otherwise unlock the_locking_inset and lock the new inset
830 the_locking_inset->insetUnlock(bv);
831 inset_x = cx(bv) - top_x + drawTextXOffset;
832 inset_y = cy(bv) + drawTextYOffset;
833 the_locking_inset = static_cast<UpdatableInset*>(inset);
834 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
835 inset->edit(bv, x - inset_x, y - inset_y, button);
836 if (the_locking_inset)
837 updateLocal(bv, CURSOR, false);
838 no_selection = false;
841 // otherwise only unlock the_locking_inset
842 the_locking_inset->insetUnlock(bv);
843 the_locking_inset = 0;
845 if (bv->theLockingInset()) {
846 if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
847 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
848 inset_x = cx(bv) - top_x + drawTextXOffset;
849 inset_y = cy(bv) + drawTextYOffset;
850 inset_pos = cpos(bv);
851 inset_par = cpar(bv);
852 inset_boundary = cboundary(bv);
853 the_locking_inset = uinset;
854 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
856 uinset->edit(bv, x - inset_x, y - inset_y, 0);
857 if (the_locking_inset)
858 updateLocal(bv, CURSOR, false);
859 no_selection = false;
863 if (!inset) { // && (button == 2)) {
864 bool paste_internally = false;
865 if ((button == 2) && getLyXText(bv)->selection.set()) {
866 localDispatch(bv, LFUN_COPY, "");
867 paste_internally = true;
874 lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent);
875 if (lt->selection.set()) {
876 lt->clearSelection();
877 updateLocal(bv, FULL, false);
879 lt->clearSelection();
881 bv->owner()->setLayout(cpar(bv)->getLayout());
883 // Insert primary selection with middle mouse
884 // if there is a local selection in the current buffer,
887 if (paste_internally)
888 localDispatch(bv, LFUN_PASTE, "");
890 localDispatch(bv, LFUN_PASTESELECTION,
897 no_selection = false;
901 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
903 UpdatableInset * inset = 0;
905 if (the_locking_inset) {
906 the_locking_inset->insetButtonRelease(bv,
907 x - inset_x, y - inset_y,
910 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
911 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
912 if (inset->editable() == Inset::HIGHLY_EDITABLE) {
913 inset->insetButtonRelease(bv,
915 y - inset_y, button);
917 inset_x = cx(bv) - top_x + drawTextXOffset;
918 inset_y = cy(bv) + drawTextYOffset;
919 inset->insetButtonRelease(bv,
921 y - inset_y, button);
923 x - inset_x, y - inset_y, button);
925 updateLocal(bv, CURSOR_PAR, false);
928 no_selection = false;
932 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
936 if (the_locking_inset) {
937 the_locking_inset->insetMotionNotify(bv, x - inset_x,
941 LyXText * t = getLyXText(bv);
943 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
945 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
946 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
947 updateLocal(bv, SELECTION, false);
952 void InsetText::insetKeyPress(XKeyEvent * xke)
954 if (the_locking_inset) {
955 the_locking_inset->insetKeyPress(xke);
961 UpdatableInset::RESULT
962 InsetText::localDispatch(BufferView * bv,
963 kb_action action, string const & arg)
965 no_selection = false;
966 UpdatableInset::RESULT
967 result= UpdatableInset::localDispatch(bv, action, arg);
968 if (result != UNDISPATCHED) {
973 if ((action < 0) && arg.empty())
976 if (the_locking_inset) {
977 result = the_locking_inset->localDispatch(bv, action, arg);
978 if (result == DISPATCHED_NOUPDATE)
980 else if (result == DISPATCHED) {
981 updateLocal(bv, CURSOR_PAR, false);
983 } else if (result == FINISHED) {
984 bool dispatched = false;
986 case LFUN_UNKNOWN_ACTION:
987 case LFUN_BREAKPARAGRAPH:
989 moveRightIntern(bv, false, false);
992 if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
993 moveRightIntern(bv, false, false);
997 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
998 moveRightIntern(bv, false, false);
1004 the_locking_inset = 0;
1009 hideInsetCursor(bv);
1012 lt = getLyXText(bv);
1017 case LFUN_SELFINSERT:
1018 if (bv->buffer()->isReadonly()) {
1019 // setErrorMessage(N_("Document is read only"));
1023 /* Automatically delete the currently selected
1024 * text and replace it with what is being
1025 * typed in now. Depends on lyxrc settings
1026 * "auto_region_delete", which defaults to
1029 setUndo(bv, Undo::INSERT,
1030 lt->cursor.par(), lt->cursor.par()->next());
1032 if (lyxrc.auto_region_delete) {
1033 if (lt->selection.set()) {
1034 lt->cutSelection(bv, false);
1037 lt->clearSelection();
1038 for (string::size_type i = 0; i < arg.length(); ++i) {
1039 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1042 lt->selection.cursor = lt->cursor;
1043 updateLocal(bv, CURSOR_PAR, true);
1044 result = DISPATCHED_NOUPDATE;
1046 // --- Cursor Movements -----------------------------------
1049 moveRight(bv, false, true);
1050 lt->setSelection(bv);
1051 updateLocal(bv, SELECTION, false);
1054 result = moveRight(bv);
1056 updateLocal(bv, CURSOR, false);
1060 moveLeft(bv, false, true);
1061 lt->setSelection(bv);
1062 updateLocal(bv, SELECTION, false);
1066 result = moveLeft(bv);
1067 updateLocal(bv, CURSOR, false);
1072 lt->setSelection(bv);
1073 updateLocal(bv, SELECTION, false);
1077 result = moveDown(bv);
1078 updateLocal(bv, CURSOR, false);
1083 lt->setSelection(bv);
1084 updateLocal(bv, SELECTION, false);
1088 result = moveUp(bv);
1089 updateLocal(bv, CURSOR, false);
1094 updateLocal(bv, CURSOR, false);
1098 updateLocal(bv, CURSOR, false);
1100 case LFUN_BACKSPACE: {
1101 setUndo(bv, Undo::DELETE,
1102 lt->cursor.par(), lt->cursor.par()->next());
1103 if (lt->selection.set())
1104 lt->cutSelection(bv);
1107 updateLocal(bv, CURSOR_PAR, true);
1112 setUndo(bv, Undo::DELETE,
1113 lt->cursor.par(), lt->cursor.par()->next());
1114 if (lt->selection.set()) {
1115 lt->cutSelection(bv);
1119 updateLocal(bv, CURSOR_PAR, true);
1124 setUndo(bv, Undo::DELETE,
1125 lt->cursor.par(), lt->cursor.par()->next());
1126 lt->cutSelection(bv);
1127 updateLocal(bv, CURSOR_PAR, true);
1133 lt->copySelection(bv);
1134 updateLocal(bv, CURSOR_PAR, false);
1136 case LFUN_PASTESELECTION:
1138 string const clip(bv->getClipboard());
1142 if (arg == "paragraph") {
1143 lt->insertStringAsParagraphs(bv, clip);
1145 lt->insertStringAsLines(bv, clip);
1147 updateLocal(bv, CURSOR_PAR, true);
1151 if (!autoBreakRows) {
1153 if (CutAndPaste::nrOfParagraphs() > 1) {
1154 WriteAlert(_("Impossible operation"),
1155 _("Cannot include more than one paragraph!"),
1160 setUndo(bv, Undo::INSERT,
1161 lt->cursor.par(), lt->cursor.par()->next());
1162 lt->pasteSelection(bv);
1163 updateLocal(bv, CURSOR_PAR, true);
1167 case LFUN_BREAKPARAGRAPH:
1168 if (!autoBreakRows) {
1169 result = DISPATCHED;
1172 lt->breakParagraph(bv, 0);
1173 updateLocal(bv, FULL, true);
1175 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1176 if (!autoBreakRows) {
1177 result = DISPATCHED;
1180 lt->breakParagraph(bv, 1);
1181 updateLocal(bv, FULL, true);
1184 case LFUN_BREAKLINE: {
1185 if (!autoBreakRows) {
1186 result = DISPATCHED;
1189 setUndo(bv, Undo::INSERT,
1190 lt->cursor.par(), lt->cursor.par()->next());
1191 lt->insertChar(bv, Paragraph::META_NEWLINE);
1192 updateLocal(bv, CURSOR_PAR, true);
1197 // do not set layouts on non breakable textinsets
1198 if (autoBreakRows) {
1199 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1201 // Derive layout number from given argument (string)
1202 // and current buffer's textclass (number). */
1203 LyXTextClassList::ClassList::size_type tclass =
1204 bv->buffer()->params.textclass;
1205 std::pair <bool, LyXTextClass::size_type> layout =
1206 textclasslist.NumberOfLayout(tclass, arg);
1208 // If the entry is obsolete, use the new one instead.
1210 string obs = textclasslist.Style(tclass,layout.second).
1213 layout = textclasslist.NumberOfLayout(tclass, obs);
1216 // see if we found the layout number:
1217 if (!layout.first) {
1218 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1219 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1223 if (cur_layout != layout.second) {
1224 cur_layout = layout.second;
1225 lt->setLayout(bv, layout.second);
1226 bv->owner()->setLayout(cpar(bv)->getLayout());
1227 updateLocal(bv, CURSOR_PAR, true);
1230 // reset the layout box
1231 bv->owner()->setLayout(cpar(bv)->getLayout());
1234 case LFUN_PARAGRAPH_SPACING:
1235 // This one is absolutely not working. When fiddling with this
1236 // it also seems to me that the paragraphs inside the insettext
1237 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1239 Paragraph * par = lt->cursor.par();
1240 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1241 float cur_value = 1.0;
1242 if (cur_spacing == Spacing::Other) {
1243 cur_value = par->params().spacing().getValue();
1246 istringstream istr(arg.c_str());
1249 Spacing::Space new_spacing = cur_spacing;
1250 float new_value = cur_value;
1252 lyxerr << "Missing argument to `paragraph-spacing'"
1254 } else if (tmp == "single") {
1255 new_spacing = Spacing::Single;
1256 } else if (tmp == "onehalf") {
1257 new_spacing = Spacing::Onehalf;
1258 } else if (tmp == "double") {
1259 new_spacing = Spacing::Double;
1260 } else if (tmp == "other") {
1261 new_spacing = Spacing::Other;
1264 lyxerr << "new_value = " << tmpval << endl;
1267 } else if (tmp == "default") {
1268 new_spacing = Spacing::Default;
1270 lyxerr << _("Unknown spacing argument: ")
1273 if (cur_spacing != new_spacing || cur_value != new_value) {
1274 par->params().spacing(Spacing(new_spacing, new_value));
1275 updateLocal(bv, CURSOR_PAR, true);
1281 if (!bv->Dispatch(action, arg))
1282 result = UNDISPATCHED;
1286 /// If the action has deleted all text in the inset, we need to change the
1287 // language to the language of the surronding text.
1288 if (par->size() == 0 && !par->next()) {
1289 LyXFont font(LyXFont::ALL_IGNORE);
1290 font.setLanguage(bv->getParentLanguage(this));
1291 setFont(bv, font, false);
1294 if (result != FINISHED) {
1295 showInsetCursor(bv);
1297 bv->unlockInset(this);
1304 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1307 buf->latexParagraphs(os, par, 0, texrow);
1308 return texrow.rows();
1312 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1314 Paragraph * p = par;
1315 unsigned int lines = 0;
1318 string const tmp = buf->asciiParagraph(p, linelen);
1319 lines += countChar(tmp, '\n');
1327 int InsetText::docBook(Buffer const * buf, ostream & os) const
1329 Paragraph * p = par;
1330 unsigned int lines = 0;
1335 buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
1343 void InsetText::validate(LaTeXFeatures & features) const
1345 Paragraph * p = par;
1347 p->validate(features);
1353 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1355 if (textclasslist.Style(buf->params.textclass,
1356 p->getLayout()).labeltype != LABEL_MANUAL)
1359 return p->beginningOfMainBody();
1363 void InsetText::getCursorPos(BufferView * bv,
1364 int & x, int & y) const
1366 if (the_locking_inset) {
1367 the_locking_inset->getCursorPos(bv, x, y);
1375 unsigned int InsetText::insetInInsetY()
1377 if (!the_locking_inset)
1380 return (inset_y + the_locking_inset->insetInInsetY());
1384 void InsetText::toggleInsetCursor(BufferView * bv)
1386 if (the_locking_inset) {
1387 the_locking_inset->toggleInsetCursor(bv);
1391 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1393 int const asc = lyxfont::maxAscent(font);
1394 int const desc = lyxfont::maxDescent(font);
1396 if (isCursorVisible())
1397 bv->hideLockedInsetCursor();
1399 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1400 toggleCursorVisible();
1404 void InsetText::showInsetCursor(BufferView * bv, bool show)
1406 if (the_locking_inset) {
1407 the_locking_inset->showInsetCursor(bv, show);
1410 if (!isCursorVisible()) {
1411 LyXFont const font =
1412 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1414 int const asc = lyxfont::maxAscent(font);
1415 int const desc = lyxfont::maxDescent(font);
1417 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1419 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1420 setCursorVisible(true);
1425 void InsetText::hideInsetCursor(BufferView * bv)
1427 if (isCursorVisible()) {
1428 bv->hideLockedInsetCursor();
1429 setCursorVisible(false);
1431 if (the_locking_inset)
1432 the_locking_inset->hideInsetCursor(bv);
1436 void InsetText::fitInsetCursor(BufferView * bv) const
1438 if (the_locking_inset) {
1439 the_locking_inset->fitInsetCursor(bv);
1442 LyXFont const font =
1443 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1445 int const asc = lyxfont::maxAscent(font);
1446 int const desc = lyxfont::maxDescent(font);
1448 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1452 UpdatableInset::RESULT
1453 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1455 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1456 return moveLeftIntern(bv, false, activate_inset, selecting);
1458 return moveRightIntern(bv, false, activate_inset, selecting);
1462 UpdatableInset::RESULT
1463 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1465 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1466 return moveRightIntern(bv, true, activate_inset, selecting);
1468 return moveLeftIntern(bv, true, activate_inset, selecting);
1472 UpdatableInset::RESULT
1473 InsetText::moveRightIntern(BufferView * bv, bool behind,
1474 bool activate_inset, bool selecting)
1476 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1478 if (activate_inset && checkAndActivateInset(bv, behind))
1480 getLyXText(bv)->cursorRight(bv);
1482 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1483 return DISPATCHED_NOUPDATE;
1487 UpdatableInset::RESULT
1488 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1489 bool activate_inset, bool selecting)
1491 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1493 getLyXText(bv)->cursorLeft(bv);
1495 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1496 if (activate_inset && checkAndActivateInset(bv, behind))
1498 return DISPATCHED_NOUPDATE;
1502 UpdatableInset::RESULT
1503 InsetText::moveUp(BufferView * bv)
1505 if (!crow(bv)->previous())
1507 getLyXText(bv)->cursorUp(bv);
1508 return DISPATCHED_NOUPDATE;
1512 UpdatableInset::RESULT
1513 InsetText::moveDown(BufferView * bv)
1515 if (!crow(bv)->next())
1517 getLyXText(bv)->cursorDown(bv);
1518 return DISPATCHED_NOUPDATE;
1522 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1524 if (the_locking_inset) {
1525 if (the_locking_inset->insetAllowed(inset))
1526 return the_locking_inset->insertInset(bv, inset);
1529 inset->setOwner(this);
1530 hideInsetCursor(bv);
1534 lt = getLyXText(bv);
1537 lt->insertInset(bv, inset);
1539 if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
1540 (cpar(bv)->getInset(cpos(bv)) != inset))
1544 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1545 showInsetCursor(bv);
1552 bool InsetText::insetAllowed(Inset::Code code) const
1554 if (the_locking_inset)
1555 return the_locking_inset->insetAllowed(code);
1560 UpdatableInset * InsetText::getLockingInset() const
1562 return the_locking_inset ? the_locking_inset->getLockingInset() :
1563 const_cast<InsetText *>(this);
1567 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1571 if (the_locking_inset)
1572 return the_locking_inset->getFirstLockingInsetOfType(c);
1577 bool InsetText::showInsetDialog(BufferView * bv) const
1579 if (the_locking_inset)
1580 return the_locking_inset->showInsetDialog(bv);
1585 std::vector<string> const InsetText::getLabelList() const
1587 std::vector<string> label_list;
1589 Paragraph * tpar = par;
1591 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1592 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1593 for (; beg != end; ++beg) {
1594 std::vector<string> const l = (*beg)->getLabelList();
1595 label_list.insert(label_list.end(), l.begin(), l.end());
1597 tpar = tpar->next();
1603 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1606 if (the_locking_inset) {
1607 the_locking_inset->setFont(bv, font, toggleall, selectall);
1610 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1611 getLyXText(bv)->setFont(bv, font, toggleall);
1616 lt = getLyXText(bv);
1619 if (lt->selection.set()) {
1620 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1624 lt->toggleFree(bv, font, toggleall);
1626 lt->clearSelection();
1628 if (selectall || lt->selection.set())
1629 updateLocal(bv, FULL, true);
1631 updateLocal(bv, CURSOR_PAR, true);
1637 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1639 if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
1643 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1644 if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
1646 LyXFont const font =
1647 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1649 x = inset->width(bv, font);
1650 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1653 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1655 //inset_x = cx(bv) - top_x + drawTextXOffset;
1656 //inset_y = cy(bv) + drawTextYOffset;
1657 inset->edit(bv, x, y, 0);
1658 if (!the_locking_inset)
1660 updateLocal(bv, CURSOR, false);
1667 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1670 x -= drawTextXOffset;
1672 int dummyy = y + insetAscent;
1673 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1680 inset_x = cx(bv) - top_x + drawTextXOffset;
1681 inset_y = cy(bv) + drawTextYOffset;
1682 inset->edit(bv, x - inset_x, y - inset_y, button);
1683 if (!the_locking_inset)
1685 updateLocal(bv, CURSOR, false);
1692 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1694 int w = UpdatableInset::getMaxWidth(bv, inset);
1699 w = w - top_x + owner()->x();
1702 w -= (2 * TEXT_TO_INSET_OFFSET);
1707 void InsetText::setParagraphData(Paragraph * p)
1710 Paragraph * tmp = par->next();
1715 par = new Paragraph(*p);
1716 par->setInsetOwner(this);
1717 Paragraph * np = par;
1720 np->next(new Paragraph(*p));
1721 np->next()->previous(np);
1723 np->setInsetOwner(this);
1729 void InsetText::setText(string const & data)
1732 LyXFont font(LyXFont::ALL_SANE);
1733 for (unsigned int i=0; i < data.length(); ++i)
1734 par->insertChar(i, data[i], font);
1738 void InsetText::setAutoBreakRows(bool flag)
1740 if (flag != autoBreakRows) {
1741 autoBreakRows = flag;
1750 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1752 if (how != drawFrame_) {
1755 updateLocal(bv, DRAW_FRAME, false);
1760 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1762 if (frame_color != col) {
1765 updateLocal(bv, DRAW_FRAME, false);
1770 int InsetText::cx(BufferView * bv) const
1774 lt = getLyXText(bv);
1777 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1778 if (the_locking_inset) {
1779 LyXFont font = lt->getFont(bv->buffer(),
1782 if (font.isVisibleRightToLeft())
1783 x -= the_locking_inset->width(bv, font);
1791 int InsetText::cy(BufferView * bv) const
1794 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1798 Paragraph::size_type InsetText::cpos(BufferView * bv) const
1800 return getLyXText(bv)->cursor.pos();
1804 Paragraph * InsetText::cpar(BufferView * bv) const
1806 return getLyXText(bv)->cursor.par();
1810 bool InsetText::cboundary(BufferView * bv) const
1812 return getLyXText(bv)->cursor.boundary();
1816 Row * InsetText::crow(BufferView * bv) const
1818 return getLyXText(bv)->cursor.row();
1822 LyXText * InsetText::getLyXText(BufferView const * lbv,
1823 bool const recursive) const
1825 if (!recursive && (cached_bview == lbv))
1826 return cached_text.get();
1828 // Super UGLY! (Lgb)
1829 BufferView * bv = const_cast<BufferView *>(lbv);
1832 Cache::iterator it = cache.find(bv);
1834 if (it != cache.end()) {
1835 if (lt || !it->second.remove) {
1836 lyx::Assert(it->second.text.get());
1837 cached_text = it->second.text;
1838 if (recursive && the_locking_inset) {
1839 return the_locking_inset->getLyXText(bv, true);
1841 return cached_text.get();
1842 } else if (it->second.remove) {
1844 saveLyXTextState(it->second.text.get());
1851 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
1852 cached_text->init(bv);
1853 restoreLyXTextState(bv, cached_text.get());
1855 cache.insert(make_pair(bv, cached_text));
1857 if (the_locking_inset && recursive) {
1858 return the_locking_inset->getLyXText(bv);
1860 return cached_text.get();
1864 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1868 Cache::iterator it = cache.find(bv);
1870 if (it == cache.end()) {
1874 lyx::Assert(it->second.text.get());
1876 it->second.remove = true;
1878 /// then remove all LyXText in text-insets
1879 Paragraph * p = par;
1880 for (; p; p = p->next()) {
1881 p->deleteInsetsLyXText(bv);
1887 void InsetText::resizeLyXText(BufferView * bv, bool force) const
1889 if (!par->next() && !par->size()) // no data, resize not neccessary!
1891 // one endless line, resize normally not necessary
1892 if (!force && getMaxWidth(bv, this) < 0)
1895 Cache::iterator it = cache.find(bv);
1896 if (it == cache.end()) {
1899 lyx::Assert(it->second.text.get());
1901 LyXText * t = it->second.text.get();
1902 saveLyXTextState(t);
1903 for (Paragraph * p = par; p; p = p->next()) {
1904 p->resizeInsetsLyXText(bv);
1907 restoreLyXTextState(bv, t);
1908 if (the_locking_inset) {
1909 inset_x = cx(bv) - top_x + drawTextXOffset;
1910 inset_y = cy(bv) + drawTextYOffset;
1914 t->first = bv->screen()->topCursorVisible(t);
1917 updateLocal(bv, FULL, false);
1919 need_update |= FULL;
1920 // this will scroll the screen such that the cursor becomes visible
1921 bv->updateScrollbar();
1925 void InsetText::reinitLyXText() const
1927 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
1928 lyx::Assert(it->second.text.get());
1930 LyXText * t = it->second.text.get();
1931 BufferView * bv = it->first;
1933 saveLyXTextState(t);
1934 for (Paragraph * p = par; p; p = p->next()) {
1935 p->resizeInsetsLyXText(bv);
1938 restoreLyXTextState(bv, t);
1939 if (the_locking_inset) {
1940 inset_x = cx(bv) - top_x + drawTextXOffset;
1941 inset_y = cy(bv) + drawTextYOffset;
1944 t->first = bv->screen()->topCursorVisible(t);
1947 updateLocal(bv, FULL, false);
1950 // this will scroll the screen such that the cursor becomes visible
1951 bv->updateScrollbar();
1956 void InsetText::removeNewlines()
1958 for (Paragraph * p = par; p; p = p->next()) {
1959 for (int i = 0; i < p->size(); ++i) {
1960 if (p->getChar(i) == Paragraph::META_NEWLINE)
1967 bool InsetText::nodraw() const
1969 if (the_locking_inset)
1970 return the_locking_inset->nodraw();
1971 return UpdatableInset::nodraw();
1975 int InsetText::scroll(bool recursive) const
1977 int sx = UpdatableInset::scroll(false);
1979 if (recursive && the_locking_inset)
1980 sx += the_locking_inset->scroll(recursive);
1986 bool InsetText::doClearArea() const
1988 return !locked || (need_update & (FULL|INIT));
1992 void InsetText::selectAll(BufferView * bv)
1994 getLyXText(bv)->cursorTop(bv);
1995 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1996 getLyXText(bv)->cursorBottom(bv);
1997 getLyXText(bv)->setSelection(bv);
2001 void InsetText::clearSelection(BufferView * bv)
2003 getLyXText(bv)->clearSelection();
2007 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2010 int h = insetAscent + insetDescent;
2011 int ty = baseline - insetAscent;
2017 if ((ty + h) > pain.paperHeight())
2018 h = pain.paperHeight();
2019 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2020 w = pain.paperWidth();
2021 // w -= TEXT_TO_INSET_OFFSET;
2022 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2025 frame_is_visible = false;
2029 Paragraph * InsetText::getParFromID(int id) const
2032 Paragraph * result = par;
2033 Paragraph * ires = 0;
2034 while (result && result->id() != id) {
2035 if ((ires = result->getParFromID(id)))
2037 result = result->next();
2041 Paragraph * tmp = par;
2043 int tmp_id = tmp->id();
2044 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2045 if (tmp->id() == id) {
2048 Paragraph * tmp2 = tmp->getParFromID(id);
2059 Paragraph * InsetText::firstParagraph() const
2062 if (the_locking_inset)
2063 if ((result = the_locking_inset->firstParagraph()))
2069 LyXCursor const & InsetText::cursor(BufferView * bv) const
2071 if (the_locking_inset)
2072 return the_locking_inset->cursor(bv);
2073 return getLyXText(bv)->cursor;
2077 Paragraph * InsetText::paragraph() const
2083 void InsetText::paragraph(Paragraph * p)
2087 // we now have to update/redraw all instances
2088 for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
2093 // redraw myself when asked for
2094 need_update |= INIT;
2098 Inset * InsetText::getInsetFromID(int id_arg) const
2101 return const_cast<InsetText *>(this);
2103 Paragraph * lp = par;
2106 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2107 en = lp->inset_iterator_end();
2110 if ((*it)->id() == id_arg)
2112 Inset * in = (*it)->getInsetFromID(id_arg);
2122 string const InsetText::selectNextWord(BufferView * bv, float & value) const
2128 lt = getLyXText(bv);
2131 if (the_locking_inset) {
2132 str = the_locking_inset->selectNextWord(bv, value);
2139 #warning Dekel please have a look on this one RTL? (Jug)
2140 // we have to go on checking so move cusor to the right
2141 lt->cursor.pos(lt->cursor.pos() + 1);
2143 str = lt->selectNextWord(bv, value);
2145 bv->unlockInset(const_cast<InsetText *>(this));
2154 void InsetText::selectSelectedWord(BufferView * bv)
2156 if (the_locking_inset) {
2157 the_locking_inset->selectSelectedWord(bv);
2160 getLyXText(bv)->selectSelectedWord(bv);
2161 updateLocal(bv, SELECTION, false);
2165 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2167 if (the_locking_inset) {
2168 the_locking_inset->toggleSelection(bv, kill_selection);
2172 lt = getLyXText(bv);
2176 int x = top_x + TEXT_TO_INSET_OFFSET;
2179 Row * row = lt->getRowNearY(y);
2180 int y_offset = top_baseline - row->ascent_of_text();
2182 while ((row != 0) && ((y+row->height()) <= 0)) {
2189 if (need_update & SELECTION)
2191 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2197 bool InsetText::searchForward(BufferView * bv, string const & str,
2198 bool const & cs, bool const & mw)
2200 if (the_locking_inset) {
2201 if (the_locking_inset->searchForward(bv, str, cs, mw))
2205 lt = getLyXText(bv);
2208 Paragraph * lpar = lt->cursor.par();
2209 Paragraph::size_type pos = lt->cursor.pos();
2210 if (pos < lpar->size() - 1)
2214 lpar = lpar->next();
2221 lt->setCursor(bv, lpar, pos);
2225 if (LyXFind(bv, str, true, true, cs , mw)) {
2228 // we have to unlock ourself in this function by default!
2229 bv->unlockInset(const_cast<InsetText *>(this));
2233 bool InsetText::searchBackward(BufferView * bv, string const & str,
2234 bool const & cs, bool const & mw)
2236 if (the_locking_inset)
2237 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2239 if (LyXFind(bv, str, false, true, cs, mw)) {
2242 // we have to unlock ourself in this function by default!
2243 bv->unlockInset(const_cast<InsetText *>(this));