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 "frontends/Alert.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"
66 extern unsigned char getCurrentTextClass(Buffer *);
67 extern bool math_insert_greek(BufferView *, char);
68 extern int greek_kb_flag;
71 // These functions should probably go into bufferview_funcs somehow (Jug)
73 void InsetText::saveLyXTextState(LyXText * t) const
75 // check if my paragraphs are still valid
78 if (p == t->cursor.par())
83 if (p && t->cursor.pos() <= p->size()) {
84 sstate.lpar = t->cursor.par();
85 sstate.pos = t->cursor.pos();
86 sstate.boundary = t->cursor.boundary();
87 sstate.selstartpar = t->selection.start.par();
88 sstate.selstartpos = t->selection.start.pos();
89 sstate.selstartboundary = t->selection.start.boundary();
90 sstate.selendpar = t->selection.end.par();
91 sstate.selendpos = t->selection.end.pos();
92 sstate.selendboundary = t->selection.end.boundary();
93 sstate.selection = t->selection.set();
94 sstate.mark_set = t->selection.mark();
95 sstate.refresh = t->refresh_row != 0;
101 void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const
104 t->selection.set(true);
105 /* at this point just to avoid the Delete-Empty-Paragraph
106 * Mechanism when setting the cursor */
107 t->selection.mark(sstate.mark_set);
108 if (sstate.selection) {
109 t->setCursor(bv, sstate.selstartpar, sstate.selstartpos,
110 true, sstate.selstartboundary);
111 t->selection.cursor = t->cursor;
112 t->setCursor(bv, sstate.selendpar, sstate.selendpos,
113 true, sstate.selendboundary);
115 t->setCursor(bv, sstate.lpar, sstate.pos);
117 t->setCursor(bv, sstate.lpar, sstate.pos, true, sstate.boundary);
118 t->selection.cursor = t->cursor;
119 t->selection.set(false);
121 if (sstate.refresh) {
127 InsetText::InnerCache::InnerCache(boost::shared_ptr<LyXText> t)
134 InsetText::InsetText()
135 : UpdatableInset(), lt(0), in_update(false), do_resize(0),
143 InsetText::InsetText(InsetText const & in, bool same_id)
144 : UpdatableInset(in, same_id), lt(0), in_update(false), do_resize(0),
152 InsetText & InsetText::operator=(InsetText const & it)
159 void InsetText::init(InsetText const * ins, bool same_id)
162 setParagraphData(ins->par);
163 autoBreakRows = ins->autoBreakRows;
164 drawFrame_ = ins->drawFrame_;
165 frame_color = ins->frame_color;
171 p->setInsetOwner(this);
174 the_locking_inset = 0;
176 frame_color = LColor::insetframe;
177 autoBreakRows = false;
186 no_selection = false;
193 last_drawn_width = -1;
194 frame_is_visible = false;
200 InsetText::~InsetText()
207 Paragraph * tmp = par->next();
214 void InsetText::clear()
217 Paragraph * tmp = par->next();
227 Inset * InsetText::clone(Buffer const &, bool same_id) const
229 return new InsetText(*this, same_id);
233 void InsetText::write(Buffer const * buf, ostream & os) const
236 writeParagraphData(buf, os);
240 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
242 par->writeFile(buf, os, buf->params, 0);
246 void InsetText::read(Buffer const * buf, LyXLex & lex)
250 Paragraph * return_par = 0;
251 Paragraph::depth_type depth = 0;
252 LyXFont font(LyXFont::ALL_INHERIT);
258 token = lex.getString();
261 if (token == "\\end_inset") {
262 #ifndef NO_COMPABILITY
263 const_cast<Buffer*>(buf)->insertErtContents(par, pos, font, false);
268 if (const_cast<Buffer*>(buf)->
269 parseSingleLyXformat2Token(lex, par, return_par,
270 token, pos, depth, font)) {
271 // the_end read this should NEVER happen
272 lex.printError("\\the_end read in inset! Error in document!");
280 return_par->setInsetOwner(this);
281 return_par = return_par->next();
284 if (token != "\\end_inset") {
285 lex.printError("Missing \\end_inset at this point. "
292 int InsetText::ascent(BufferView * bv, LyXFont const &) const
295 Row * row = getLyXText(bv)->getRowNearY(y_temp);
296 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
301 int InsetText::descent(BufferView * bv, LyXFont const &) const
309 Row * row = lt->getRowNearY(y_temp);
310 insetDescent = lt->height - row->ascent_of_text() +
311 TEXT_TO_INSET_OFFSET;
318 int InsetText::width(BufferView * bv, LyXFont const &) const
320 insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
321 (2 * TEXT_TO_INSET_OFFSET);
322 insetWidth = max(insetWidth, 10);
327 int InsetText::textWidth(BufferView * bv, bool fordraw) const
330 if (!autoBreakRows) {
333 w = getMaxWidth(bv, this);
336 return max(w - (2 * TEXT_TO_INSET_OFFSET),
337 (int)getLyXText(bv)->width);
341 return w - (2 * TEXT_TO_INSET_OFFSET);
345 void InsetText::draw(BufferView * bv, LyXFont const & f,
346 int baseline, float & x, bool cleared) const
351 Painter & pain = bv->painter();
353 // this is the first thing we have to ask because if the x pos
354 // changed we have to do a complete rebreak of the text as we
355 // may have few space to draw in. Well we should check on this too
357 if (top_x != int(x)) {
359 int nw = getMaxWidth(bv, this);
360 if (nw > 0 && old_max_width != nw) {
363 bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
371 // repaint the background if needed
372 if (cleared && backgroundColor() != LColor::background) {
374 clearInset(pain, baseline, cleared);
378 // no draw is necessary !!!
379 if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
382 top_baseline = baseline;
384 if (need_update & CLEAR_FRAME)
385 clearFrame(pain, cleared);
392 x += static_cast<float>(scroll());
394 // if top_x differs we did it already
395 if (!cleared && (top_x == int(x)) &&
396 ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
397 (last_drawn_width!=insetWidth))) {
398 clearInset(pain, baseline, cleared);
404 frame_is_visible = false;
406 if (!cleared && (need_update == NONE)) {
408 drawFrame(pain, cleared);
412 top_baseline = baseline;
413 top_y = baseline - ascent(bv, f);
414 last_width = width(bv, f);
415 last_height = ascent(bv, f) + descent(bv, f);
417 if (cleared || (last_drawn_width != insetWidth)) {
419 clearInset(pain, baseline, cleared);
421 last_drawn_width = insetWidth;
424 if (the_locking_inset && (cpar(bv) == inset_par)
425 && (cpos(bv) == inset_pos)) {
426 inset_x = cx(bv) - top_x + drawTextXOffset;
427 inset_y = cy(bv) + drawTextYOffset;
429 if (!cleared && (need_update == CURSOR)
430 && !getLyXText(bv)->selection.set()) {
431 drawFrame(pain, cleared);
432 x += last_width; // was width(bv, f);
441 x += TEXT_TO_INSET_OFFSET;
444 Row * row = lt->getRowNearY(y);
445 int y_offset = baseline - row->ascent_of_text();
446 int ph = pain.paperHeight();
449 while ((row != 0) && ((y+row->height()) <= 0)) {
451 first += row->height();
457 if (cleared || (need_update&(INIT|FULL))) {
460 while ((row != 0) && (yf < ph)) {
461 lt->getVisibleRow(bv, y+y_offset, int(x), row,
467 } else if (!locked) {
468 if (need_update & CURSOR) {
469 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
470 lt->clearSelection();
471 lt->selection.cursor = lt->cursor;
473 bv->screen()->update(lt, bv, y_offset, int(x));
476 if (need_update & SELECTION) {
477 bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
478 } else if (need_update & CURSOR) {
479 bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
480 lt->clearSelection();
481 lt->selection.cursor = lt->cursor;
483 bv->screen()->update(lt, bv, y_offset, int(x));
488 lt->status(bv, LyXText::UNCHANGED);
489 if ((need_update != CURSOR_PAR) &&
490 ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked))) {
491 drawFrame(pain, cleared);
492 } else if (need_update & CLEAR_FRAME) {
493 clearFrame(pain, cleared);
496 x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
498 if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
500 } else if (need_update != INIT) {
509 void InsetText::drawFrame(Painter & pain, bool cleared) const
511 static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
512 if (!frame_is_visible || cleared) {
513 frame_x = top_x + ttoD2;
514 frame_y = top_baseline - insetAscent + ttoD2;
515 frame_w = last_width - TEXT_TO_INSET_OFFSET;
516 frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
517 pain.rectangle(frame_x, frame_y,
520 frame_is_visible = true;
525 void InsetText::clearFrame(Painter & pain, bool cleared) const
527 if (frame_is_visible) {
529 pain.rectangle(frame_x, frame_y, frame_w, frame_h,
532 frame_is_visible = false;
537 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
540 if (reinit && owner()) {
542 owner()->update(bv, font, true);
547 if (reinit || need_update == INIT) {
549 // we should put this call where we set need_update to INIT!
552 owner()->update(bv, font, true);
556 if (the_locking_inset) {
557 inset_x = cx(bv) - top_x + drawTextXOffset;
558 inset_y = cy(bv) + drawTextYOffset;
559 the_locking_inset->update(bv, font, reinit);
568 int oldw = insetWidth;
569 insetWidth = lt->width + (2 * TEXT_TO_INSET_OFFSET);
570 if (oldw != insetWidth) {
579 if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
582 lt->updateInset(bv, the_locking_inset);
584 if (lt->status() == LyXText::NEED_MORE_REFRESH)
592 void InsetText::setUpdateStatus(BufferView * bv, int what) const
600 // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
601 // if we don't break row so that we only have one row to update!
602 if ((lt->status() == LyXText::NEED_MORE_REFRESH) ||
604 (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
607 } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
608 need_update |= CURSOR_PAR;
611 // this to not draw a selection when we redraw all of it!
612 if (need_update & CURSOR && !(need_update & SELECTION)) {
613 if (lt->selection.set())
615 lt->clearSelection();
622 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
630 setUpdateStatus(bv, what);
631 if (((need_update != CURSOR) && (need_update != NONE)) ||
632 (lt->status() != LyXText::UNCHANGED) || lt->selection.set())
634 bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
636 if (need_update == CURSOR)
638 bv->owner()->showState();
639 if (old_par != cpar(bv)) {
640 bv->owner()->setLayout(cpar(bv)->getLayout());
648 string const InsetText::editMessage() const
650 return _("Opened Text Inset");
654 void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
656 UpdatableInset::edit(bv, x, y, button);
658 if (!bv->lockInset(this)) {
659 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
663 the_locking_inset = 0;
664 inset_pos = inset_x = inset_y = 0;
665 inset_boundary = false;
668 int tmp_y = (y < 0) ? 0 : y;
675 if (!checkAndActivateInset(bv, x, tmp_y, button))
676 lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
678 lt->clearSelection();
681 updateLocal(bv, CURSOR, false);
683 // If the inset is empty set the language of the current font to the
684 // language to the surronding text (if different).
685 if (par->size() == 0 && !par->next() &&
686 bv->getParentLanguage(this) != lt->current_font.language()) {
687 LyXFont font(LyXFont::ALL_IGNORE);
688 font.setLanguage(bv->getParentLanguage(this));
689 setFont(bv, font, false);
696 void InsetText::edit(BufferView * bv, bool front)
698 UpdatableInset::edit(bv, front);
700 if (!bv->lockInset(this)) {
701 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
705 the_locking_inset = 0;
706 inset_pos = inset_x = inset_y = 0;
707 inset_boundary = false;
716 lt->setCursor(bv, par, 0);
721 // int const pos = (p->size() ? p->size()-1 : p->size());
722 lt->setCursor(bv, p, p->size());
724 lt->clearSelection();
727 updateLocal(bv, CURSOR, false);
729 // If the inset is empty set the language of the current font to the
730 // language to the surronding text (if different).
731 if (par->size() == 0 && !par->next() &&
732 bv->getParentLanguage(this) != lt->current_font.language()) {
733 LyXFont font(LyXFont::ALL_IGNORE);
734 font.setLanguage(bv->getParentLanguage(this));
735 setFont(bv, font, false);
742 void InsetText::insetUnlock(BufferView * bv)
744 if (the_locking_inset) {
745 the_locking_inset->insetUnlock(bv);
746 the_locking_inset = 0;
749 no_selection = false;
752 if (drawFrame_ == LOCKED)
753 code = CURSOR|CLEAR_FRAME;
761 if (lt->selection.set()) {
762 lt->clearSelection();
764 } else if (owner()) {
765 bv->owner()->setLayout(owner()->getLyXText(bv)
766 ->cursor.par()->getLayout());
768 bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
769 // hack for deleteEmptyParMech
770 lt->setCursor(bv, par, 0);
771 updateLocal(bv, code, false);
777 bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
779 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
783 if (inset == cpar(bv)->getInset(cpos(bv))) {
784 lyxerr[Debug::INSETS] << "OK" << endl;
785 the_locking_inset = inset;
786 inset_x = cx(bv) - top_x + drawTextXOffset;
787 inset_y = cy(bv) + drawTextYOffset;
788 inset_pos = cpos(bv);
789 inset_par = cpar(bv);
790 inset_boundary = cboundary(bv);
791 updateLocal(bv, CURSOR, false);
793 } else if (the_locking_inset && (the_locking_inset == inset)) {
794 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
795 lyxerr[Debug::INSETS] << "OK" << endl;
796 inset_x = cx(bv) - top_x + drawTextXOffset;
797 inset_y = cy(bv) + drawTextYOffset;
799 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
801 } else if (the_locking_inset) {
802 lyxerr[Debug::INSETS] << "MAYBE" << endl;
803 return the_locking_inset->lockInsetInInset(bv, inset);
805 lyxerr[Debug::INSETS] << "NOT OK" << endl;
810 bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
813 if (!the_locking_inset)
815 if (the_locking_inset == inset) {
816 the_locking_inset->insetUnlock(bv);
817 getLyXText(bv)->updateInset(bv, inset);
818 the_locking_inset = 0;
820 moveRight(bv, false);
821 old_par = 0; // force layout setting
825 updateLocal(bv, CURSOR, false);
828 return the_locking_inset->unlockInsetInInset(bv, inset, lr);
832 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
834 if (!the_locking_inset)
836 if (the_locking_inset != inset) {
837 getLyXText(bv)->updateInset(bv, the_locking_inset);
838 setUpdateStatus(bv, CURSOR_PAR);
839 return the_locking_inset->updateInsetInInset(bv, inset);
841 if (getLyXText(bv)->updateInset(bv, inset))
842 updateLocal(bv, CURSOR_PAR, false);
843 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
844 inset_x = cx(bv) - top_x + drawTextXOffset;
845 inset_y = cy(bv) + drawTextYOffset;
851 void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
855 int tmp_x = x - drawTextXOffset;
856 int tmp_y = y + insetAscent - getLyXText(bv)->first;
857 Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y, button);
860 if (the_locking_inset) {
861 if (the_locking_inset == inset) {
862 the_locking_inset->insetButtonPress(bv,x-inset_x,y-inset_y,button);
863 no_selection = false;
866 // otherwise unlock the_locking_inset and lock the new inset
867 the_locking_inset->insetUnlock(bv);
868 inset_x = cx(bv) - top_x + drawTextXOffset;
869 inset_y = cy(bv) + drawTextYOffset;
870 the_locking_inset = static_cast<UpdatableInset*>(inset);
871 inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
872 inset->edit(bv, x - inset_x, y - inset_y, button);
873 if (the_locking_inset)
874 updateLocal(bv, CURSOR, false);
875 no_selection = false;
878 // otherwise only unlock the_locking_inset
879 the_locking_inset->insetUnlock(bv);
880 the_locking_inset = 0;
882 if (bv->theLockingInset()) {
883 if (isHighlyEditableInset(inset)) {
884 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
885 inset_x = cx(bv) - top_x + drawTextXOffset;
886 inset_y = cy(bv) + drawTextYOffset;
887 inset_pos = cpos(bv);
888 inset_par = cpar(bv);
889 inset_boundary = cboundary(bv);
890 the_locking_inset = uinset;
891 uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
893 uinset->edit(bv, x - inset_x, y - inset_y, 0);
894 if (the_locking_inset)
895 updateLocal(bv, CURSOR, false);
896 no_selection = false;
900 if (!inset) { // && (button == 2)) {
901 bool paste_internally = false;
902 if ((button == 2) && getLyXText(bv)->selection.set()) {
903 localDispatch(bv, LFUN_COPY, "");
904 paste_internally = true;
911 lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent);
912 if (lt->selection.set()) {
913 lt->clearSelection();
914 updateLocal(bv, FULL, false);
916 lt->clearSelection();
918 bv->owner()->setLayout(cpar(bv)->getLayout());
920 // Insert primary selection with middle mouse
921 // if there is a local selection in the current buffer,
924 if (paste_internally)
925 localDispatch(bv, LFUN_PASTE, "");
927 localDispatch(bv, LFUN_PASTESELECTION,
934 no_selection = false;
938 void InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
940 UpdatableInset * inset = 0;
942 if (the_locking_inset) {
943 the_locking_inset->insetButtonRelease(bv,
944 x - inset_x, y - inset_y,
947 if (cpar(bv)->isInset(cpos(bv))) {
948 inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
949 if (isHighlyEditableInset(inset)) {
950 inset->insetButtonRelease(bv,
952 y - inset_y, button);
954 inset_x = cx(bv) - top_x + drawTextXOffset;
955 inset_y = cy(bv) + drawTextYOffset;
956 inset->insetButtonRelease(bv,
958 y - inset_y, button);
960 x - inset_x, y - inset_y, button);
962 updateLocal(bv, CURSOR_PAR, false);
965 no_selection = false;
969 void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
973 if (the_locking_inset) {
974 the_locking_inset->insetMotionNotify(bv, x - inset_x,
978 LyXText * t = getLyXText(bv);
980 t->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
982 if (t->toggle_cursor.par() != t->toggle_end_cursor.par() ||
983 t->toggle_cursor.pos() != t->toggle_end_cursor.pos())
984 updateLocal(bv, SELECTION, false);
989 void InsetText::insetKeyPress(XKeyEvent * xke)
991 if (the_locking_inset) {
992 the_locking_inset->insetKeyPress(xke);
998 UpdatableInset::RESULT
999 InsetText::localDispatch(BufferView * bv,
1000 kb_action action, string const & arg)
1002 bool was_empty = par->size() == 0 && !par->next();
1003 no_selection = false;
1004 UpdatableInset::RESULT
1005 result= UpdatableInset::localDispatch(bv, action, arg);
1006 if (result != UNDISPATCHED) {
1010 result = DISPATCHED;
1011 if ((action < 0) && arg.empty())
1014 if (the_locking_inset) {
1015 result = the_locking_inset->localDispatch(bv, action, arg);
1016 if (result == DISPATCHED_NOUPDATE)
1018 else if (result == DISPATCHED) {
1019 updateLocal(bv, CURSOR_PAR, false);
1021 } else if (result >= FINISHED) {
1023 case FINISHED_RIGHT:
1024 moveRightIntern(bv, false, false);
1025 result = DISPATCHED;
1028 if ((result = moveUp(bv)) >= FINISHED) {
1029 updateLocal(bv, CURSOR, false);
1030 bv->unlockInset(this);
1034 if ((result = moveDown(bv)) >= FINISHED) {
1035 updateLocal(bv, CURSOR, false);
1036 bv->unlockInset(this);
1040 result = DISPATCHED;
1043 the_locking_inset = 0;
1044 #ifdef WITH_WARNINGS
1045 #warning I changed this to always return Dispatched maybe it is wrong (20011001 Jug)
1050 hideInsetCursor(bv);
1053 lt = getLyXText(bv);
1058 case LFUN_SELFINSERT:
1059 if (bv->buffer()->isReadonly()) {
1060 // setErrorMessage(N_("Document is read only"));
1064 /* Automatically delete the currently selected
1065 * text and replace it with what is being
1066 * typed in now. Depends on lyxrc settings
1067 * "auto_region_delete", which defaults to
1070 setUndo(bv, Undo::INSERT,
1071 lt->cursor.par(), lt->cursor.par()->next());
1073 if (lyxrc.auto_region_delete) {
1074 if (lt->selection.set()) {
1075 lt->cutSelection(bv, false);
1078 lt->clearSelection();
1079 for (string::size_type i = 0; i < arg.length(); ++i) {
1080 bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
1083 lt->selection.cursor = lt->cursor;
1084 updateLocal(bv, CURSOR_PAR, true);
1085 result = DISPATCHED_NOUPDATE;
1087 // --- Cursor Movements -----------------------------------
1090 moveRight(bv, false, true);
1091 lt->setSelection(bv);
1092 updateLocal(bv, SELECTION, false);
1095 result = moveRight(bv);
1097 updateLocal(bv, CURSOR, false);
1101 moveLeft(bv, false, true);
1102 lt->setSelection(bv);
1103 updateLocal(bv, SELECTION, false);
1107 result = moveLeft(bv);
1108 updateLocal(bv, CURSOR, false);
1113 lt->setSelection(bv);
1114 updateLocal(bv, SELECTION, false);
1118 result = moveDown(bv);
1119 updateLocal(bv, CURSOR, false);
1124 lt->setSelection(bv);
1125 updateLocal(bv, SELECTION, false);
1129 result = moveUp(bv);
1130 updateLocal(bv, CURSOR, false);
1135 updateLocal(bv, CURSOR, false);
1139 updateLocal(bv, CURSOR, false);
1141 case LFUN_BACKSPACE: {
1142 setUndo(bv, Undo::DELETE,
1143 lt->cursor.par(), lt->cursor.par()->next());
1144 if (lt->selection.set())
1145 lt->cutSelection(bv);
1148 updateLocal(bv, CURSOR_PAR, true);
1153 setUndo(bv, Undo::DELETE,
1154 lt->cursor.par(), lt->cursor.par()->next());
1155 if (lt->selection.set()) {
1156 lt->cutSelection(bv);
1160 updateLocal(bv, CURSOR_PAR, true);
1165 setUndo(bv, Undo::DELETE,
1166 lt->cursor.par(), lt->cursor.par()->next());
1167 lt->cutSelection(bv);
1168 updateLocal(bv, CURSOR_PAR, true);
1174 lt->copySelection(bv);
1175 updateLocal(bv, CURSOR_PAR, false);
1177 case LFUN_PASTESELECTION:
1179 string const clip(bv->getClipboard());
1183 if (arg == "paragraph") {
1184 lt->insertStringAsParagraphs(bv, clip);
1186 lt->insertStringAsLines(bv, clip);
1188 updateLocal(bv, CURSOR_PAR, true);
1192 if (!autoBreakRows) {
1194 if (CutAndPaste::nrOfParagraphs() > 1) {
1195 Alert::alert(_("Impossible operation"),
1196 _("Cannot include more than one paragraph!"),
1201 setUndo(bv, Undo::INSERT,
1202 lt->cursor.par(), lt->cursor.par()->next());
1203 lt->pasteSelection(bv);
1204 updateLocal(bv, CURSOR_PAR, true);
1208 case LFUN_BREAKPARAGRAPH:
1209 if (!autoBreakRows) {
1210 result = DISPATCHED;
1213 lt->breakParagraph(bv, 0);
1214 updateLocal(bv, FULL, true);
1216 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
1217 if (!autoBreakRows) {
1218 result = DISPATCHED;
1221 lt->breakParagraph(bv, 1);
1222 updateLocal(bv, FULL, true);
1225 case LFUN_BREAKLINE: {
1226 if (!autoBreakRows) {
1227 result = DISPATCHED;
1230 setUndo(bv, Undo::INSERT,
1231 lt->cursor.par(), lt->cursor.par()->next());
1232 lt->insertChar(bv, Paragraph::META_NEWLINE);
1233 updateLocal(bv, CURSOR_PAR, true);
1238 // do not set layouts on non breakable textinsets
1239 if (autoBreakRows) {
1240 LyXTextClass::size_type cur_layout = cpar(bv)->layout;
1242 // Derive layout number from given argument (string)
1243 // and current buffer's textclass (number). */
1244 LyXTextClassList::ClassList::size_type tclass =
1245 bv->buffer()->params.textclass;
1246 std::pair <bool, LyXTextClass::size_type> layout =
1247 textclasslist.NumberOfLayout(tclass, arg);
1249 // If the entry is obsolete, use the new one instead.
1251 string obs = textclasslist.Style(tclass,layout.second).
1254 layout = textclasslist.NumberOfLayout(tclass, obs);
1257 // see if we found the layout number:
1258 if (!layout.first) {
1259 string const msg = string(N_("Layout ")) + arg + N_(" not known");
1260 bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
1264 if (cur_layout != layout.second) {
1265 cur_layout = layout.second;
1266 lt->setLayout(bv, layout.second);
1267 bv->owner()->setLayout(cpar(bv)->getLayout());
1268 updateLocal(bv, CURSOR_PAR, true);
1271 // reset the layout box
1272 bv->owner()->setLayout(cpar(bv)->getLayout());
1275 case LFUN_PARAGRAPH_SPACING:
1276 // This one is absolutely not working. When fiddling with this
1277 // it also seems to me that the paragraphs inside the insettext
1278 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
1280 Paragraph * par = lt->cursor.par();
1281 Spacing::Space cur_spacing = par->params().spacing().getSpace();
1282 float cur_value = 1.0;
1283 if (cur_spacing == Spacing::Other) {
1284 cur_value = par->params().spacing().getValue();
1287 istringstream istr(arg.c_str());
1290 Spacing::Space new_spacing = cur_spacing;
1291 float new_value = cur_value;
1293 lyxerr << "Missing argument to `paragraph-spacing'"
1295 } else if (tmp == "single") {
1296 new_spacing = Spacing::Single;
1297 } else if (tmp == "onehalf") {
1298 new_spacing = Spacing::Onehalf;
1299 } else if (tmp == "double") {
1300 new_spacing = Spacing::Double;
1301 } else if (tmp == "other") {
1302 new_spacing = Spacing::Other;
1305 lyxerr << "new_value = " << tmpval << endl;
1308 } else if (tmp == "default") {
1309 new_spacing = Spacing::Default;
1311 lyxerr << _("Unknown spacing argument: ")
1314 if (cur_spacing != new_spacing || cur_value != new_value) {
1315 par->params().spacing(Spacing(new_spacing, new_value));
1316 updateLocal(bv, CURSOR_PAR, true);
1322 if (!bv->Dispatch(action, arg))
1323 result = UNDISPATCHED;
1327 /// If the action has deleted all text in the inset, we need to change the
1328 // language to the language of the surronding text.
1329 if (!was_empty && par->size() == 0 && !par->next()) {
1330 LyXFont font(LyXFont::ALL_IGNORE);
1331 font.setLanguage(bv->getParentLanguage(this));
1332 setFont(bv, font, false);
1335 if (result < FINISHED) {
1336 showInsetCursor(bv);
1338 bv->unlockInset(this);
1345 int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
1348 buf->latexParagraphs(os, par, 0, texrow);
1349 return texrow.rows();
1353 int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
1355 Paragraph * p = par;
1356 unsigned int lines = 0;
1359 string const tmp = buf->asciiParagraph(p, linelen);
1360 lines += countChar(tmp, '\n');
1368 int InsetText::docbook(Buffer const * buf, ostream & os) const
1370 Paragraph * p = par;
1371 unsigned int lines = 0;
1373 vector<string> environment_stack(10);
1374 vector<string> environment_inner(10);
1376 int const command_depth = 0;
1379 Paragraph::depth_type depth = 0; // paragraph depth
1383 int desc_on = 0; // description mode
1385 LyXLayout const & style =
1386 textclasslist.Style(buf->params.textclass,
1389 // environment tag closing
1390 for (; depth > p->params().depth(); --depth) {
1391 if (environment_inner[depth] != "!-- --") {
1392 item_name = "listitem";
1393 buf->sgmlCloseTag(os, command_depth + depth,
1395 if (environment_inner[depth] == "varlistentry")
1396 buf->sgmlCloseTag(os, depth+command_depth,
1397 environment_inner[depth]);
1399 buf->sgmlCloseTag(os, depth + command_depth,
1400 environment_stack[depth]);
1401 environment_stack[depth].erase();
1402 environment_inner[depth].erase();
1405 if (depth == p->params().depth()
1406 && environment_stack[depth] != style.latexname()
1407 && !environment_stack[depth].empty()) {
1408 if (environment_inner[depth] != "!-- --") {
1409 item_name= "listitem";
1410 buf->sgmlCloseTag(os, command_depth+depth,
1412 if (environment_inner[depth] == "varlistentry")
1413 buf->sgmlCloseTag(os,
1414 depth + command_depth,
1415 environment_inner[depth]);
1418 buf->sgmlCloseTag(os, depth + command_depth,
1419 environment_stack[depth]);
1421 environment_stack[depth].erase();
1422 environment_inner[depth].erase();
1425 // Write opening SGML tags.
1426 switch (style.latextype) {
1427 case LATEX_PARAGRAPH:
1428 buf->sgmlOpenTag(os, depth + command_depth,
1433 buf->sgmlError(p, 0,
1434 _("Error : LatexType Command not allowed here.\n"));
1438 case LATEX_ENVIRONMENT:
1439 case LATEX_ITEM_ENVIRONMENT:
1440 if (depth < p->params().depth()) {
1441 depth = p->params().depth();
1442 environment_stack[depth].erase();
1445 if (environment_stack[depth] != style.latexname()) {
1446 if(environment_stack.size() == depth + 1) {
1447 environment_stack.push_back("!-- --");
1448 environment_inner.push_back("!-- --");
1450 environment_stack[depth] = style.latexname();
1451 environment_inner[depth] = "!-- --";
1452 buf->sgmlOpenTag(os, depth + command_depth,
1453 environment_stack[depth]);
1455 if (environment_inner[depth] != "!-- --") {
1456 item_name= "listitem";
1457 buf->sgmlCloseTag(os,
1458 command_depth + depth,
1460 if (environment_inner[depth] == "varlistentry")
1461 buf->sgmlCloseTag(os,
1462 depth + command_depth,
1463 environment_inner[depth]);
1467 if (style.latextype == LATEX_ENVIRONMENT) {
1468 if (!style.latexparam().empty()) {
1469 if(style.latexparam() == "CDATA")
1472 buf->sgmlOpenTag(os, depth + command_depth,
1473 style.latexparam());
1478 desc_on = (style.labeltype == LABEL_MANUAL);
1481 environment_inner[depth]= "varlistentry";
1483 environment_inner[depth]= "listitem";
1485 buf->sgmlOpenTag(os, depth + 1 + command_depth,
1486 environment_inner[depth]);
1490 buf->sgmlOpenTag(os, depth + 1 + command_depth,
1494 buf->sgmlOpenTag(os, depth + 1 + command_depth,
1499 buf->sgmlOpenTag(os, depth + command_depth,
1504 buf->simpleDocBookOnePar(os, p, desc_on,
1505 depth + 1 + command_depth);
1509 // write closing SGML tags
1510 switch (style.latextype) {
1511 case LATEX_ENVIRONMENT:
1512 if (!style.latexparam().empty()) {
1513 if(style.latexparam() == "CDATA")
1516 buf->sgmlCloseTag(os, depth + command_depth,
1517 style.latexparam());
1520 case LATEX_ITEM_ENVIRONMENT:
1521 if (desc_on == 1) break;
1523 buf->sgmlCloseTag(os, depth + 1 + command_depth, end_tag);
1525 case LATEX_PARAGRAPH:
1526 buf->sgmlCloseTag(os, depth + command_depth, style.latexname());
1529 buf->sgmlCloseTag(os, depth + command_depth, style.latexname());
1535 for (int d = depth; d >= 0; --d) {
1536 if (!environment_stack[depth].empty()) {
1537 if (environment_inner[depth] != "!-- --") {
1538 item_name = "listitem";
1539 buf->sgmlCloseTag(os, command_depth + depth,
1541 if (environment_inner[depth] == "varlistentry")
1542 buf->sgmlCloseTag(os, depth + command_depth,
1543 environment_inner[depth]);
1546 buf->sgmlCloseTag(os, depth + command_depth,
1547 environment_stack[depth]);
1555 void InsetText::validate(LaTeXFeatures & features) const
1557 Paragraph * p = par;
1559 p->validate(features);
1565 int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
1567 if (textclasslist.Style(buf->params.textclass,
1568 p->getLayout()).labeltype != LABEL_MANUAL)
1571 return p->beginningOfMainBody();
1575 void InsetText::getCursorPos(BufferView * bv,
1576 int & x, int & y) const
1578 if (the_locking_inset) {
1579 the_locking_inset->getCursorPos(bv, x, y);
1587 unsigned int InsetText::insetInInsetY()
1589 if (!the_locking_inset)
1592 return (inset_y + the_locking_inset->insetInInsetY());
1596 void InsetText::toggleInsetCursor(BufferView * bv)
1598 if (the_locking_inset) {
1599 the_locking_inset->toggleInsetCursor(bv);
1603 LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
1605 int const asc = lyxfont::maxAscent(font);
1606 int const desc = lyxfont::maxDescent(font);
1608 if (isCursorVisible())
1609 bv->hideLockedInsetCursor();
1611 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1612 toggleCursorVisible();
1616 void InsetText::showInsetCursor(BufferView * bv, bool show)
1618 if (the_locking_inset) {
1619 the_locking_inset->showInsetCursor(bv, show);
1622 if (!isCursorVisible()) {
1623 LyXFont const font =
1624 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1626 int const asc = lyxfont::maxAscent(font);
1627 int const desc = lyxfont::maxDescent(font);
1629 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1631 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1632 setCursorVisible(true);
1637 void InsetText::hideInsetCursor(BufferView * bv)
1639 if (isCursorVisible()) {
1640 bv->hideLockedInsetCursor();
1641 setCursorVisible(false);
1643 if (the_locking_inset)
1644 the_locking_inset->hideInsetCursor(bv);
1648 void InsetText::fitInsetCursor(BufferView * bv) const
1650 if (the_locking_inset) {
1651 the_locking_inset->fitInsetCursor(bv);
1654 LyXFont const font =
1655 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1657 int const asc = lyxfont::maxAscent(font);
1658 int const desc = lyxfont::maxDescent(font);
1660 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1664 UpdatableInset::RESULT
1665 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
1667 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1668 return moveLeftIntern(bv, false, activate_inset, selecting);
1670 return moveRightIntern(bv, false, activate_inset, selecting);
1674 UpdatableInset::RESULT
1675 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
1677 if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
1678 return moveRightIntern(bv, true, activate_inset, selecting);
1680 return moveLeftIntern(bv, true, activate_inset, selecting);
1684 UpdatableInset::RESULT
1685 InsetText::moveRightIntern(BufferView * bv, bool behind,
1686 bool activate_inset, bool selecting)
1688 if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
1689 return FINISHED_RIGHT;
1690 if (activate_inset && checkAndActivateInset(bv, behind))
1692 getLyXText(bv)->cursorRight(bv);
1694 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1695 return DISPATCHED_NOUPDATE;
1699 UpdatableInset::RESULT
1700 InsetText::moveLeftIntern(BufferView * bv, bool behind,
1701 bool activate_inset, bool selecting)
1703 if (!cpar(bv)->previous() && (cpos(bv) <= 0))
1705 getLyXText(bv)->cursorLeft(bv);
1707 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
1708 if (activate_inset && checkAndActivateInset(bv, behind))
1710 return DISPATCHED_NOUPDATE;
1714 UpdatableInset::RESULT
1715 InsetText::moveUp(BufferView * bv)
1717 if (!crow(bv)->previous())
1719 getLyXText(bv)->cursorUp(bv);
1720 return DISPATCHED_NOUPDATE;
1724 UpdatableInset::RESULT
1725 InsetText::moveDown(BufferView * bv)
1727 if (!crow(bv)->next())
1728 return FINISHED_DOWN;
1729 getLyXText(bv)->cursorDown(bv);
1730 return DISPATCHED_NOUPDATE;
1734 bool InsetText::insertInset(BufferView * bv, Inset * inset)
1736 if (the_locking_inset) {
1737 if (the_locking_inset->insetAllowed(inset))
1738 return the_locking_inset->insertInset(bv, inset);
1741 inset->setOwner(this);
1742 hideInsetCursor(bv);
1746 lt = getLyXText(bv);
1749 lt->insertInset(bv, inset);
1751 if ((!cpar(bv)->isInset(cpos(bv))) ||
1752 (cpar(bv)->getInset(cpos(bv)) != inset))
1756 updateLocal(bv, CURSOR_PAR|CURSOR, true);
1757 showInsetCursor(bv);
1764 bool InsetText::insetAllowed(Inset::Code code) const
1766 if (the_locking_inset)
1767 return the_locking_inset->insetAllowed(code);
1772 UpdatableInset * InsetText::getLockingInset() const
1774 return the_locking_inset ? the_locking_inset->getLockingInset() :
1775 const_cast<InsetText *>(this);
1779 UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
1783 if (the_locking_inset)
1784 return the_locking_inset->getFirstLockingInsetOfType(c);
1789 bool InsetText::showInsetDialog(BufferView * bv) const
1791 if (the_locking_inset)
1792 return the_locking_inset->showInsetDialog(bv);
1797 std::vector<string> const InsetText::getLabelList() const
1799 std::vector<string> label_list;
1801 Paragraph * tpar = par;
1803 Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
1804 Paragraph::inset_iterator end = tpar->inset_iterator_end();
1805 for (; beg != end; ++beg) {
1806 std::vector<string> const l = (*beg)->getLabelList();
1807 label_list.insert(label_list.end(), l.begin(), l.end());
1809 tpar = tpar->next();
1815 void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
1818 if (the_locking_inset) {
1819 the_locking_inset->setFont(bv, font, toggleall, selectall);
1822 if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
1823 getLyXText(bv)->setFont(bv, font, toggleall);
1828 lt = getLyXText(bv);
1831 if (lt->selection.set()) {
1832 setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
1836 lt->toggleFree(bv, font, toggleall);
1838 lt->clearSelection();
1840 if (selectall || lt->selection.set())
1841 updateLocal(bv, FULL, true);
1843 updateLocal(bv, CURSOR_PAR, true);
1849 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1851 if (cpar(bv)->isInset(cpos(bv))) {
1855 static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
1856 if (!isHighlyEditableInset(inset))
1858 LyXFont const font =
1859 getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
1861 x = inset->width(bv, font);
1862 y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
1865 y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
1867 //inset_x = cx(bv) - top_x + drawTextXOffset;
1868 //inset_y = cy(bv) + drawTextYOffset;
1869 inset->edit(bv, x, y, 0);
1870 if (!the_locking_inset)
1872 updateLocal(bv, CURSOR, false);
1879 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1882 x -= drawTextXOffset;
1884 int dummyy = y + insetAscent;
1885 Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy, button);
1892 inset_x = cx(bv) - top_x + drawTextXOffset;
1893 inset_y = cy(bv) + drawTextYOffset;
1894 inset->edit(bv, x - inset_x, y - inset_y, button);
1895 if (!the_locking_inset)
1897 updateLocal(bv, CURSOR, false);
1904 int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
1907 int w = UpdatableInset::getMaxWidth(bv, inset);
1912 w = w - top_x + owner()->x();
1915 w -= (2 * TEXT_TO_INSET_OFFSET);
1918 return UpdatableInset::getMaxWidth(bv, inset);
1923 void InsetText::setParagraphData(Paragraph * p)
1925 // we have to unlock any locked inset otherwise we're in troubles
1926 the_locking_inset = 0;
1928 Paragraph * tmp = par->next();
1933 par = new Paragraph(*p, false);
1934 par->setInsetOwner(this);
1935 Paragraph * np = par;
1938 np->next(new Paragraph(*p, false));
1939 np->next()->previous(np);
1941 np->setInsetOwner(this);
1948 void InsetText::setText(string const & data)
1951 LyXFont font(LyXFont::ALL_SANE);
1952 for (unsigned int i=0; i < data.length(); ++i)
1953 par->insertChar(i, data[i], font);
1957 void InsetText::setAutoBreakRows(bool flag)
1959 if (flag != autoBreakRows) {
1960 autoBreakRows = flag;
1968 void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
1970 if (how != drawFrame_) {
1973 updateLocal(bv, DRAW_FRAME, false);
1978 void InsetText::setFrameColor(BufferView * bv, LColor::color col)
1980 if (frame_color != col) {
1983 updateLocal(bv, DRAW_FRAME, false);
1988 int InsetText::cx(BufferView * bv) const
1992 lt = getLyXText(bv);
1995 int x = lt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1996 if (the_locking_inset) {
1997 LyXFont font = lt->getFont(bv->buffer(),
2000 if (font.isVisibleRightToLeft())
2001 x -= the_locking_inset->width(bv, font);
2009 int InsetText::cy(BufferView * bv) const
2012 return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
2016 pos_type InsetText::cpos(BufferView * bv) const
2018 return getLyXText(bv)->cursor.pos();
2022 Paragraph * InsetText::cpar(BufferView * bv) const
2024 return getLyXText(bv)->cursor.par();
2028 bool InsetText::cboundary(BufferView * bv) const
2030 return getLyXText(bv)->cursor.boundary();
2034 Row * InsetText::crow(BufferView * bv) const
2036 return getLyXText(bv)->cursor.row();
2040 LyXText * InsetText::getLyXText(BufferView const * lbv,
2041 bool const recursive) const
2043 if (!recursive && (cached_bview == lbv)) {
2044 LyXText * lt = cached_text.get();
2045 lyx::Assert(lt && lt->firstrow->par() == par);
2046 return cached_text.get();
2049 // Super UGLY! (Lgb)
2050 BufferView * bv = const_cast<BufferView *>(lbv);
2053 Cache::iterator it = cache.find(bv);
2055 if (it != cache.end()) {
2059 resizeLyXText(do_resize);
2060 if (lt || !it->second.remove) {
2061 lyx::Assert(it->second.text.get());
2062 cached_text = it->second.text;
2063 if (recursive && the_locking_inset) {
2064 return the_locking_inset->getLyXText(bv, true);
2066 return cached_text.get();
2067 } else if (it->second.remove) {
2069 saveLyXTextState(it->second.text.get());
2076 cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
2077 cached_text->init(bv);
2078 restoreLyXTextState(bv, cached_text.get());
2080 cache.insert(make_pair(bv, cached_text));
2082 if (the_locking_inset && recursive) {
2083 return the_locking_inset->getLyXText(bv);
2085 return cached_text.get();
2089 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
2093 Cache::iterator it = cache.find(bv);
2095 if (it == cache.end()) {
2099 lyx::Assert(it->second.text.get());
2101 it->second.remove = true;
2103 /// then remove all LyXText in text-insets
2104 Paragraph * p = par;
2105 for (; p; p = p->next()) {
2106 p->deleteInsetsLyXText(bv);
2112 void InsetText::resizeLyXText(BufferView * bv, bool force) const
2115 // we cannot resize this because we are in use!
2116 // so do this on the next possible getLyXText()
2121 // lyxerr << "InsetText::resizeLyXText\n";
2122 if (!par->next() && !par->size()) // no data, resize not neccessary!
2124 // one endless line, resize normally not necessary
2125 if (!force && getMaxWidth(bv, this) < 0)
2128 Cache::iterator it = cache.find(bv);
2129 if (it == cache.end()) {
2132 lyx::Assert(it->second.text.get());
2134 LyXText * t = it->second.text.get();
2135 saveLyXTextState(t);
2136 for (Paragraph * p = par; p; p = p->next()) {
2137 p->resizeInsetsLyXText(bv);
2140 restoreLyXTextState(bv, t);
2141 if (the_locking_inset) {
2142 inset_x = cx(bv) - top_x + drawTextXOffset;
2143 inset_y = cy(bv) + drawTextYOffset;
2147 t->first = bv->screen()->topCursorVisible(t);
2150 updateLocal(bv, FULL, false);
2151 // this will scroll the screen such that the cursor becomes visible
2152 bv->updateScrollbar();
2154 need_update |= FULL;
2159 void InsetText::reinitLyXText() const
2162 // we cannot resize this because we are in use!
2163 // so do this on the next possible getLyXText()
2169 // lyxerr << "InsetText::reinitLyXText\n";
2170 for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
2171 lyx::Assert(it->second.text.get());
2173 LyXText * t = it->second.text.get();
2174 BufferView * bv = it->first;
2176 saveLyXTextState(t);
2177 for (Paragraph * p = par; p; p = p->next()) {
2178 p->resizeInsetsLyXText(bv);
2181 restoreLyXTextState(bv, t);
2182 if (the_locking_inset) {
2183 inset_x = cx(bv) - top_x + drawTextXOffset;
2184 inset_y = cy(bv) + drawTextYOffset;
2187 t->first = bv->screen()->topCursorVisible(t);
2190 updateLocal(bv, FULL, false);
2191 // this will scroll the screen such that the cursor becomes visible
2192 bv->updateScrollbar();
2200 void InsetText::removeNewlines()
2202 for (Paragraph * p = par; p; p = p->next()) {
2203 for (int i = 0; i < p->size(); ++i) {
2204 if (p->getChar(i) == Paragraph::META_NEWLINE)
2211 bool InsetText::nodraw() const
2213 if (the_locking_inset)
2214 return the_locking_inset->nodraw();
2215 return UpdatableInset::nodraw();
2219 int InsetText::scroll(bool recursive) const
2221 int sx = UpdatableInset::scroll(false);
2223 if (recursive && the_locking_inset)
2224 sx += the_locking_inset->scroll(recursive);
2230 bool InsetText::doClearArea() const
2232 return !locked || (need_update & (FULL|INIT));
2236 void InsetText::selectAll(BufferView * bv)
2238 getLyXText(bv)->cursorTop(bv);
2239 getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
2240 getLyXText(bv)->cursorBottom(bv);
2241 getLyXText(bv)->setSelection(bv);
2245 void InsetText::clearSelection(BufferView * bv)
2247 getLyXText(bv)->clearSelection();
2251 void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
2254 int h = insetAscent + insetDescent;
2255 int ty = baseline - insetAscent;
2261 if ((ty + h) > pain.paperHeight())
2262 h = pain.paperHeight();
2263 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
2264 w = pain.paperWidth();
2265 // w -= TEXT_TO_INSET_OFFSET;
2266 pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
2269 frame_is_visible = false;
2273 Paragraph * InsetText::getParFromID(int id) const
2276 Paragraph * result = par;
2277 Paragraph * ires = 0;
2278 while (result && result->id() != id) {
2279 if ((ires = result->getParFromID(id)))
2281 result = result->next();
2285 Paragraph * tmp = par;
2287 int tmp_id = tmp->id();
2288 lyxerr << "Looking at paragraph: " << tmp_id << endl;
2289 if (tmp->id() == id) {
2292 Paragraph * tmp2 = tmp->getParFromID(id);
2303 Paragraph * InsetText::firstParagraph() const
2306 if (the_locking_inset)
2307 if ((result = the_locking_inset->firstParagraph()))
2313 Paragraph * InsetText::getFirstParagraph(int i) const
2315 return (i == 0) ? par : 0;
2319 LyXCursor const & InsetText::cursor(BufferView * bv) const
2321 if (the_locking_inset)
2322 return the_locking_inset->cursor(bv);
2323 return getLyXText(bv)->cursor;
2327 Paragraph * InsetText::paragraph() const
2333 void InsetText::paragraph(Paragraph * p)
2337 // redraw myself when asked for
2342 Inset * InsetText::getInsetFromID(int id_arg) const
2345 return const_cast<InsetText *>(this);
2347 Paragraph * lp = par;
2350 for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
2351 en = lp->inset_iterator_end();
2354 if ((*it)->id() == id_arg)
2356 Inset * in = (*it)->getInsetFromID(id_arg);
2366 string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
2372 lt = getLyXText(bv);
2375 if (the_locking_inset) {
2376 str = the_locking_inset->selectNextWordToSpellcheck(bv, value);
2383 #warning Dekel please have a look on this one RTL? (Jug)
2385 // we have to go on checking so move cusor to the right
2386 lt->cursor.pos(lt->cursor.pos() + 1);
2388 str = lt->selectNextWordToSpellcheck(bv, value);
2390 bv->unlockInset(const_cast<InsetText *>(this));
2399 void InsetText::selectSelectedWord(BufferView * bv)
2401 if (the_locking_inset) {
2402 the_locking_inset->selectSelectedWord(bv);
2405 getLyXText(bv)->selectSelectedWord(bv);
2406 updateLocal(bv, SELECTION, false);
2410 void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
2412 if (the_locking_inset) {
2413 the_locking_inset->toggleSelection(bv, kill_selection);
2417 lt = getLyXText(bv);
2421 int x = top_x + TEXT_TO_INSET_OFFSET;
2424 Row * row = lt->getRowNearY(y);
2425 int y_offset = top_baseline - row->ascent_of_text();
2427 while ((row != 0) && ((y+row->height()) <= 0)) {
2434 if (need_update & SELECTION)
2436 bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
2442 bool InsetText::searchForward(BufferView * bv, string const & str,
2443 bool const & cs, bool const & mw)
2445 if (the_locking_inset) {
2446 if (the_locking_inset->searchForward(bv, str, cs, mw))
2450 lt = getLyXText(bv);
2453 Paragraph * lpar = lt->cursor.par();
2454 pos_type pos = lt->cursor.pos();
2455 if (pos < lpar->size() - 1)
2459 lpar = lpar->next();
2464 // we have to unlock ourself in this function by default!
2465 bv->unlockInset(const_cast<InsetText *>(this));
2468 lt->setCursor(bv, lpar, pos);
2472 if (LyXFind(bv, str, true, true, cs , mw)) {
2475 // we have to unlock ourself in this function by default!
2476 bv->unlockInset(const_cast<InsetText *>(this));
2480 bool InsetText::searchBackward(BufferView * bv, string const & str,
2481 bool const & cs, bool const & mw)
2483 if (the_locking_inset)
2484 if (the_locking_inset->searchBackward(bv, str, cs, mw))
2486 if (LyXFind(bv, str, false, true, cs, mw)) {
2489 // we have to unlock ourself in this function by default!
2490 bv->unlockInset(const_cast<InsetText *>(this));
2495 bool InsetText::checkInsertChar(LyXFont & font)
2498 return owner()->checkInsertChar(font);