2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998-2000 The LyX Team.
9 * ======================================================
20 #pragma implementation
23 #include "insettext.h"
24 #include "lyxparagraph.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"
40 #include "minibuffer.h"
42 #include "support/textutils.h"
43 #include "support/LAssert.h"
47 #include "trans_mgr.h"
48 #include "lyxscreen.h"
57 extern unsigned char getCurrentTextClass(Buffer *);
59 InsetText::InsetText()
61 par = new LyXParagraph();
66 InsetText::InsetText(InsetText const & ins)
71 autoBreakRows = ins.autoBreakRows;
75 InsetText & InsetText::operator=(InsetText const & it)
78 autoBreakRows = it.autoBreakRows;
83 void InsetText::init(InsetText const * ins)
85 top_y = last_width = last_height = 0;
86 insetAscent = insetDescent = insetWidth = 0;
87 the_locking_inset = 0;
88 cursor_visible = false;
92 drawTextXOffset = drawTextYOffset = 0;
93 autoBreakRows = false;
97 SetParagraphData(ins->par);
98 autoBreakRows = ins->autoBreakRows;
99 drawFrame = ins->drawFrame;
101 par->SetInsetOwner(this);
102 frame_color = LColor::insetframe;
108 InsetText::~InsetText()
110 for(Cache::const_iterator cit=cache.begin(); cit != cache.end(); ++cit)
111 deleteLyXText((*cit).first);
112 LyXParagraph * p = par->next;
122 void InsetText::clear()
124 LyXParagraph * p = par->next;
131 par = new LyXParagraph();
135 Inset * InsetText::Clone() const
137 InsetText * t = new InsetText(*this);
142 void InsetText::Write(Buffer const * buf, ostream & os) const
145 WriteParagraphData(buf, os);
149 void InsetText::WriteParagraphData(Buffer const * buf, ostream & os) const
151 par->writeFile(buf, os, buf->params, 0, 0);
155 void InsetText::Read(Buffer const * buf, LyXLex & lex)
159 LyXParagraph * return_par = 0;
160 char depth = 0; // signed or unsigned?
162 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
163 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
165 LyXFont font(LyXFont::ALL_INHERIT);
167 LyXParagraph * p = par->next;
174 par = new LyXParagraph;
177 token = lex.GetString();
180 if (token == "\\end_inset")
182 if (const_cast<Buffer*>(buf)->
183 parseSingleLyXformat2Token(lex, par, return_par,token, pos, depth,
186 , footnoteflag, footnotekind
190 // the_end read this should NEVER happen
191 lex.printError("\\the_end read in inset! Error in document!");
199 return_par->SetInsetOwner(this);
200 return_par = return_par->next;
203 if (token != "\\end_inset") {
204 lex.printError("Missing \\end_inset at this point. "
211 int InsetText::ascent(BufferView * bv, LyXFont const &) const
214 Row * row = TEXT(bv)->GetRowNearY(y_temp);
215 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
220 int InsetText::descent(BufferView * bv, LyXFont const &) const
223 Row * row = TEXT(bv)->GetRowNearY(y_temp);
224 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
225 TEXT_TO_INSET_OFFSET;
230 int InsetText::width(BufferView * bv, LyXFont const &) const
232 insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET);
237 int InsetText::textWidth(Painter & pain) const
239 int w = getMaxWidth(pain, this);
244 void InsetText::draw(BufferView * bv, LyXFont const & f,
245 int baseline, float & x, bool cleared) const
247 Painter & pain = bv->painter();
249 // no draw is necessary !!!
250 if ((drawFrame == LOCKED) && !locked && !par->size()) {
251 if (!cleared && (need_update == CLEAR_FRAME)) {
252 pain.rectangle(top_x + 1, baseline - insetAscent + 1,
254 insetAscent + insetDescent - 1,
258 top_baseline = baseline;
265 UpdatableInset::draw(bv, f, baseline, x, cleared);
267 if (!cleared && ((need_update==FULL) || (top_x!=int(x)) ||
268 (top_baseline!=baseline))) {
270 int h = insetAscent + insetDescent;
271 int ty = baseline - insetAscent;
277 if ((ty + h) > pain.paperHeight())
278 h = pain.paperHeight();
279 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
280 w = pain.paperWidth();
281 pain.fillRectangle(top_x+drawTextXOffset, ty, w, h);
285 if (!cleared && (need_update == NONE))
288 if (top_x != int(x)) {
291 bv->text->status = LyXText::CHANGED_IN_DRAW;
295 top_baseline = baseline;
296 top_y = baseline - ascent(bv, f);
297 last_width = width(bv, f);
298 last_height = ascent(bv, f) + descent(bv, f);
300 if (the_locking_inset && (cpar(bv) == inset_par) && (cpos(bv) == inset_pos)) {
301 inset_x = cx(bv) - top_x + drawTextXOffset;
302 inset_y = cy(bv) + drawTextYOffset;
304 if (!cleared && (need_update == CURSOR) && !TEXT(bv)->selection) {
309 x += TEXT_TO_INSET_OFFSET;
311 Row * row = TEXT(bv)->GetRowNearY(y);
312 y += baseline - row->ascent_of_text();
313 if (cleared || !locked || (need_update == FULL)) {
315 TEXT(bv)->GetVisibleRow(bv, y, int(x), row, y, cleared);
319 } else if (need_update == SELECTION) {
320 bv->screen()->ToggleToggle(TEXT(bv), y, int(x));
323 if (need_update == CURSOR) {
324 bv->screen()->ToggleSelection(TEXT(bv), true, y, int(x));
325 TEXT(bv)->ClearSelection();
326 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
328 bv->screen()->Update(TEXT(bv), y, int(x));
331 TEXT(bv)->refresh_y = 0;
332 TEXT(bv)->status = LyXText::UNCHANGED;
333 if ((drawFrame == ALWAYS) || ((drawFrame == LOCKED) && locked)) {
334 pain.rectangle(top_x + 1, baseline - insetAscent + 1,
335 width(bv, f) - 1, insetAscent + insetDescent - 1,
337 } else if (need_update == CLEAR_FRAME) {
338 pain.rectangle(top_x + 1, baseline - insetAscent + 1,
339 width(bv, f) - 1, insetAscent + insetDescent - 1,
342 x += width(bv, f) - TEXT_TO_INSET_OFFSET;
343 if (bv->text->status==LyXText::CHANGED_IN_DRAW)
345 else if (need_update != INIT)
350 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
352 if (reinit) { // && (need_update != CURSOR)) {
356 owner()->update(bv, font, true);
359 if (the_locking_inset) {
360 inset_x = cx(bv) - top_x + drawTextXOffset;
361 inset_y = cy(bv) + drawTextYOffset;
362 the_locking_inset->update(bv, font, reinit);
364 if (need_update == INIT) {
367 // if (!owner() && bv->text)
368 // bv->text->UpdateInset(bv, this);
370 int oldw = insetWidth;
372 insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET);
373 // max(textWidth(bv->painter()),
374 // static_cast<int>(TEXT(bv)->width) + drawTextXOffset) +
375 // (2 * TEXT_TO_INSET_OFFSET);
377 insetWidth = textWidth(bv->painter());
379 insetWidth = static_cast<int>(TEXT(bv)->width);
381 if (oldw != insetWidth) {
382 // printf("TW(%p): %d-%d-%d-%d\n",this,insetWidth, oldw,
383 // textWidth(bv->painter()),static_cast<int>(TEXT(bv)->width));
388 owner()->update(bv, font, reinit);
391 update(bv, font, reinit);
395 update(bv, font, reinit);
397 UpdateLocal(bv, INIT, false);
402 if ((need_update==CURSOR_PAR) && (TEXT(bv)->status==LyXText::UNCHANGED) &&
405 TEXT(bv)->UpdateInset(bv, the_locking_inset);
408 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
412 Row * row = TEXT(bv)->GetRowNearY(y_temp);
413 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
414 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
415 TEXT_TO_INSET_OFFSET;
419 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
421 TEXT(bv)->FullRebreak(bv);
422 if (need_update != INIT) {
423 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
425 else if (!the_locking_inset || (what != CURSOR))
428 if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED) ||
430 bv->updateInset(this, mark_dirty);
431 bv->owner()->showState();
432 if (old_par != cpar(bv)) {
433 bv->owner()->setLayout(cpar(bv)->GetLayout());
439 string const InsetText::EditMessage() const
441 return _("Opened Text Inset");
445 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
447 // par->SetInsetOwner(this);
448 UpdatableInset::Edit(bv, x, y, button);
450 if (!bv->lockInset(this)) {
451 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
455 the_locking_inset = 0;
456 inset_pos = inset_x = inset_y = 0;
459 if (!checkAndActivateInset(bv, x, y, button))
460 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
461 y+TEXT(bv)->first+insetAscent);
462 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
463 bv->text->FinishUndo();
464 UpdateLocal(bv, FULL, false);
468 void InsetText::InsetUnlock(BufferView * bv)
470 if (the_locking_inset) {
471 the_locking_inset->InsetUnlock(bv);
472 the_locking_inset = 0;
475 no_selection = false;
477 TEXT(bv)->selection = 0;
478 UpdateLocal(bv, CLEAR_FRAME, false);
480 bv->owner()->setLayout(owner()->getLyXText(bv)
481 ->cursor.par()->GetLayout());
483 bv->owner()->setLayout(bv->text->cursor.par()->GetLayout());
487 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
489 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
492 if (inset == cpar(bv)->GetInset(cpos(bv))) {
493 lyxerr[Debug::INSETS] << "OK" << endl;
494 the_locking_inset = inset;
495 inset_x = cx(bv) - top_x + drawTextXOffset;
496 inset_y = cy(bv) + drawTextYOffset;
497 inset_pos = cpos(bv);
498 inset_par = cpar(bv);
499 TEXT(bv)->UpdateInset(bv, the_locking_inset);
501 } else if (the_locking_inset && (the_locking_inset == inset)) {
502 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
503 lyxerr[Debug::INSETS] << "OK" << endl;
504 inset_x = cx(bv) - top_x + drawTextXOffset;
505 inset_y = cy(bv) + drawTextYOffset;
507 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
509 } else if (the_locking_inset) {
510 lyxerr[Debug::INSETS] << "MAYBE" << endl;
511 return the_locking_inset->LockInsetInInset(bv, inset);
513 lyxerr[Debug::INSETS] << "NOT OK" << endl;
518 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
521 if (!the_locking_inset)
523 if (the_locking_inset == inset) {
524 the_locking_inset->InsetUnlock(bv);
525 TEXT(bv)->UpdateInset(bv, inset);
526 the_locking_inset = 0;
528 moveRight(bv, false);
529 old_par = 0; // force layout setting
530 UpdateLocal(bv, CURSOR_PAR, false);
533 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
537 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
539 if (!the_locking_inset)
541 if (the_locking_inset != inset) {
542 TEXT(bv)->UpdateInset(bv, the_locking_inset);
543 need_update = CURSOR_PAR;
544 return the_locking_inset->UpdateInsetInInset(bv, inset);
546 // UpdateLocal(bv, FULL, false);
547 if (TEXT(bv)->UpdateInset(bv, inset))
548 UpdateLocal(bv, CURSOR_PAR, false);
549 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
550 inset_x = cx(bv) - top_x + drawTextXOffset;
551 inset_y = cy(bv) + drawTextYOffset;
557 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
559 no_selection = false;
561 int tmp_x = x - drawTextXOffset;
562 int tmp_y = y + insetAscent;
563 Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button);
566 if (the_locking_inset) {
567 if (the_locking_inset == inset) {
568 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
571 // otherwise unlock the_locking_inset and lock the new inset
572 the_locking_inset->InsetUnlock(bv);
573 inset_x = cx(bv) - top_x + drawTextXOffset;
574 inset_y = cy(bv) + drawTextYOffset;
575 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
576 inset->Edit(bv, x - inset_x, y - inset_y, button);
577 if (the_locking_inset) {
578 UpdateLocal(bv, CURSOR_PAR, false);
582 // otherwise only unlock the_locking_inset
583 the_locking_inset->InsetUnlock(bv);
584 the_locking_inset = 0;
586 if (bv->the_locking_inset) {
587 if (inset && inset->Editable() == Inset::HIGHLY_EDITABLE) {
588 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
589 inset_x = cx(bv) - top_x + drawTextXOffset;
590 inset_y = cy(bv) + drawTextYOffset;
591 inset_pos = cpos(bv);
592 inset_par = cpar(bv);
593 uinset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
594 uinset->Edit(bv, x - inset_x, y - inset_y, 0);
595 if (the_locking_inset) {
596 UpdateLocal(bv, CURSOR_PAR, false);
602 bool paste_internally = false;
603 if ((button == 2) && TEXT(bv)->selection) {
604 LocalDispatch(bv, LFUN_COPY, "");
605 paste_internally = true;
607 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
608 y+TEXT(bv)->first+insetAscent);
609 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
610 UpdateLocal(bv, CURSOR, false);
611 bv->owner()->setLayout(cpar(bv)->GetLayout());
613 // Insert primary selection with middle mouse
614 // if there is a local selection in the current buffer,
617 if (paste_internally)
618 LocalDispatch(bv, LFUN_PASTE, "");
620 LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
627 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
629 UpdatableInset * inset = 0;
631 if (the_locking_inset) {
632 the_locking_inset->InsetButtonRelease(bv,
633 x - inset_x, y - inset_y,
636 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
637 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
638 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
639 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
641 inset_x = cx(bv) - top_x + drawTextXOffset;
642 inset_y = cy(bv) + drawTextYOffset;
643 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
644 inset->Edit(bv, x - inset_x, y - inset_y, button);
646 UpdateLocal(bv, CURSOR_PAR, false);
649 no_selection = false;
653 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
655 if (the_locking_inset) {
656 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
662 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
663 y+TEXT(bv)->first+insetAscent);
664 TEXT(bv)->SetSelection();
665 if (TEXT(bv)->toggle_cursor.par()!=TEXT(bv)->toggle_end_cursor.par() ||
666 TEXT(bv)->toggle_cursor.pos()!=TEXT(bv)->toggle_end_cursor.pos())
667 UpdateLocal(bv, SELECTION, false);
670 no_selection = false;
674 void InsetText::InsetKeyPress(XKeyEvent * xke)
676 if (the_locking_inset) {
677 the_locking_inset->InsetKeyPress(xke);
683 UpdatableInset::RESULT
684 InsetText::LocalDispatch(BufferView * bv,
685 int action, string const & arg)
687 no_selection = false;
688 UpdatableInset::RESULT
689 result= UpdatableInset::LocalDispatch(bv, action, arg);
690 if (result != UNDISPATCHED) {
695 if ((action < 0) && arg.empty())
698 if (the_locking_inset) {
699 result = the_locking_inset->LocalDispatch(bv, action, arg);
700 if (result == DISPATCHED_NOUPDATE)
702 else if (result == DISPATCHED) {
703 UpdateLocal(bv, CURSOR_PAR, false);
705 } else if (result == FINISHED) {
709 moveRight(bv, false);
715 the_locking_inset = 0;
723 if (bv->buffer()->isReadonly()) {
725 // setErrorMessage(N_("Document is read only"));
729 /* Automatically delete the currently selected
730 * text and replace it with what is being
731 * typed in now. Depends on lyxrc settings
732 * "auto_region_delete", which defaults to
735 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
737 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
738 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
740 bv->text->cursor.par()->previous,
741 bv->text->cursor.par()->next
744 if (lyxrc.auto_region_delete) {
745 if (TEXT(bv)->selection){
746 TEXT(bv)->CutSelection(bv, false);
749 TEXT(bv)->ClearSelection();
750 for (string::size_type i = 0; i < arg.length(); ++i) {
751 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
754 UpdateLocal(bv, CURSOR_PAR, true);
756 // --- Cursor Movements ---------------------------------------------
758 bv->text->FinishUndo();
759 moveRight(bv, false);
760 TEXT(bv)->SetSelection();
761 UpdateLocal(bv, SELECTION, false);
764 result = moveRight(bv);
765 bv->text->FinishUndo();
766 UpdateLocal(bv, CURSOR, false);
769 bv->text->FinishUndo();
771 TEXT(bv)->SetSelection();
772 UpdateLocal(bv, SELECTION, false);
775 bv->text->FinishUndo();
776 result= moveLeft(bv);
777 UpdateLocal(bv, CURSOR, false);
780 bv->text->FinishUndo();
782 TEXT(bv)->SetSelection();
783 UpdateLocal(bv, SELECTION, false);
786 bv->text->FinishUndo();
787 result = moveDown(bv);
788 UpdateLocal(bv, CURSOR, false);
791 bv->text->FinishUndo();
793 TEXT(bv)->SetSelection();
794 UpdateLocal(bv, SELECTION, false);
797 bv->text->FinishUndo();
799 UpdateLocal(bv, CURSOR, false);
802 bv->text->FinishUndo();
803 TEXT(bv)->CursorHome(bv);
804 UpdateLocal(bv, CURSOR, false);
807 TEXT(bv)->CursorEnd(bv);
808 UpdateLocal(bv, CURSOR, false);
811 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
813 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
814 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
816 bv->text->cursor.par()->previous,
817 bv->text->cursor.par()->next
820 if (TEXT(bv)->selection)
821 TEXT(bv)->CutSelection(bv);
823 TEXT(bv)->Backspace(bv);
824 UpdateLocal(bv, CURSOR_PAR, true);
827 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
829 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
830 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
832 bv->text->cursor.par()->previous,
833 bv->text->cursor.par()->next
836 if (TEXT(bv)->selection)
837 TEXT(bv)->CutSelection(bv);
839 TEXT(bv)->Delete(bv);
840 UpdateLocal(bv, CURSOR_PAR, true);
843 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
845 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
846 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
848 bv->text->cursor.par()->previous,
849 bv->text->cursor.par()->next
852 TEXT(bv)->CutSelection(bv);
853 UpdateLocal(bv, CURSOR_PAR, true);
856 bv->text->FinishUndo();
857 TEXT(bv)->CopySelection(bv);
858 UpdateLocal(bv, CURSOR_PAR, false);
860 case LFUN_PASTESELECTION:
862 string clip(bv->workarea()->getClipboard());
866 if (arg == "paragraph") {
867 TEXT(bv)->InsertStringB(bv, clip);
869 TEXT(bv)->InsertStringA(bv, clip);
871 UpdateLocal(bv, CURSOR_PAR, true);
875 if (!autoBreakRows) {
878 if (cap.nrOfParagraphs() > 1) {
879 WriteAlert(_("Impossible operation"),
880 _("Cannot include more than one paragraph!"),
885 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
887 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
888 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
890 bv->text->cursor.par()->previous,
891 bv->text->cursor.par()->next
894 TEXT(bv)->PasteSelection(bv);
895 UpdateLocal(bv, CURSOR_PAR, true);
897 case LFUN_BREAKPARAGRAPH:
900 TEXT(bv)->BreakParagraph(bv, 0);
901 UpdateLocal(bv, FULL, true);
906 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
908 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
909 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
911 bv->text->cursor.par()->previous,
912 bv->text->cursor.par()->next
915 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
916 UpdateLocal(bv, CURSOR_PAR, true);
919 // do not set layouts on non breakable textinsets
921 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
923 // Derive layout number from given argument (string)
924 // and current buffer's textclass (number). */
925 LyXTextClassList::ClassList::size_type tclass =
926 bv->buffer()->params.textclass;
927 std::pair <bool, LyXTextClass::size_type> layout =
928 textclasslist.NumberOfLayout(tclass, arg);
930 // If the entry is obsolete, use the new one instead.
932 string obs = textclasslist.Style(tclass,layout.second).
935 layout = textclasslist.NumberOfLayout(tclass, obs);
938 // see if we found the layout number:
940 string msg = string(N_("Layout ")) + arg + N_(" not known");
942 bv->owner()->getMiniBuffer()->Set(msg);
946 if (cur_layout != layout.second) {
947 cur_layout = layout.second;
948 TEXT(bv)->SetLayout(bv, layout.second);
949 bv->owner()->setLayout(cpar(bv)->GetLayout());
950 UpdateLocal(bv, CURSOR_PAR, true);
953 // reset the layout box
954 bv->owner()->setLayout(cpar(bv)->GetLayout());
957 case LFUN_PARAGRAPH_SPACING:
958 // This one is absolutely not working. When fiddling with this
959 // it also seems to me that the paragraphs inside the insettext
960 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
962 LyXParagraph * par = TEXT(bv)->cursor.par();
963 Spacing::Space cur_spacing = par->spacing.getSpace();
964 float cur_value = 1.0;
965 if (cur_spacing == Spacing::Other) {
966 cur_value = par->spacing.getValue();
969 std::istringstream istr(arg.c_str());
972 Spacing::Space new_spacing = cur_spacing;
973 float new_value = cur_value;
975 lyxerr << "Missing argument to `paragraph-spacing'"
977 } else if (tmp == "single") {
978 new_spacing = Spacing::Single;
979 } else if (tmp == "onehalf") {
980 new_spacing = Spacing::Onehalf;
981 } else if (tmp == "double") {
982 new_spacing = Spacing::Double;
983 } else if (tmp == "other") {
984 new_spacing = Spacing::Other;
987 lyxerr << "new_value = " << tmpval << endl;
990 } else if (tmp == "default") {
991 new_spacing = Spacing::Default;
993 lyxerr << _("Unknown spacing argument: ")
996 if (cur_spacing != new_spacing || cur_value != new_value) {
997 par->spacing.set(new_spacing, new_value);
998 //TEXT(bv)->RedoParagraph(owner->view());
999 UpdateLocal(bv, CURSOR_PAR, true);
1000 //bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1006 result = UNDISPATCHED;
1009 if (result != FINISHED) {
1010 ShowInsetCursor(bv);
1012 bv->unlockInset(this);
1017 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
1020 buf->latexParagraphs(os, par, 0, texrow);
1021 return texrow.rows();
1025 void InsetText::Validate(LaTeXFeatures & features) const
1027 LyXParagraph * p = par;
1029 p->validate(features);
1035 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
1037 if (textclasslist.Style(buf->params.textclass,
1038 p->GetLayout()).labeltype != LABEL_MANUAL)
1041 return p->BeginningOfMainBody();
1045 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
1052 int InsetText::InsetInInsetY()
1054 if (!the_locking_inset)
1057 return (inset_y + the_locking_inset->InsetInInsetY());
1061 void InsetText::ToggleInsetCursor(BufferView * bv)
1063 if (the_locking_inset) {
1064 the_locking_inset->ToggleInsetCursor(bv);
1068 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1070 int asc = lyxfont::maxAscent(font);
1071 int desc = lyxfont::maxDescent(font);
1074 bv->hideLockedInsetCursor();
1076 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1077 cursor_visible = !cursor_visible;
1081 void InsetText::ShowInsetCursor(BufferView * bv)
1083 if (the_locking_inset) {
1084 the_locking_inset->ShowInsetCursor(bv);
1087 if (!cursor_visible) {
1088 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1090 int asc = lyxfont::maxAscent(font);
1091 int desc = lyxfont::maxDescent(font);
1093 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1094 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1095 cursor_visible = true;
1100 void InsetText::HideInsetCursor(BufferView * bv)
1102 if (cursor_visible) {
1103 bv->hideLockedInsetCursor();
1104 cursor_visible = false;
1106 if (the_locking_inset)
1107 the_locking_inset->HideInsetCursor(bv);
1111 UpdatableInset::RESULT
1112 InsetText::moveRight(BufferView * bv, bool activate_inset)
1114 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
1116 if (activate_inset && checkAndActivateInset(bv, false))
1118 TEXT(bv)->CursorRight(bv);
1119 return DISPATCHED_NOUPDATE;
1123 UpdatableInset::RESULT
1124 InsetText::moveLeft(BufferView * bv, bool activate_inset)
1126 if (!cpar(bv)->previous && (cpos(bv) <= 0))
1128 TEXT(bv)->CursorLeft(bv);
1129 if (activate_inset && checkAndActivateInset(bv, true))
1131 return DISPATCHED_NOUPDATE;
1135 UpdatableInset::RESULT
1136 InsetText::moveUp(BufferView * bv)
1138 if (!crow(bv)->previous())
1140 TEXT(bv)->CursorUp(bv);
1141 return DISPATCHED_NOUPDATE;
1145 UpdatableInset::RESULT
1146 InsetText::moveDown(BufferView * bv)
1148 if (!crow(bv)->next())
1150 TEXT(bv)->CursorDown(bv);
1151 return DISPATCHED_NOUPDATE;
1155 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
1157 if (the_locking_inset) {
1158 if (the_locking_inset->InsertInsetAllowed(inset))
1159 return the_locking_inset->InsertInset(bv, inset);
1162 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
1164 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1165 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1167 bv->text->cursor.par()->previous,
1168 bv->text->cursor.par()->next
1171 if (inset->Editable() == Inset::IS_EDITABLE) {
1172 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
1173 i->setOwner(static_cast<UpdatableInset *>(this));
1175 TEXT(bv)->InsertInset(bv, inset);
1176 TEXT(bv)->selection = 0;
1177 UpdateLocal(bv, CURSOR_PAR, true);
1178 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
1183 UpdatableInset * InsetText::GetLockingInset()
1185 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
1189 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
1193 if (the_locking_inset)
1194 return the_locking_inset->GetFirstLockingInsetOfType(c);
1199 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
1201 TEXT(bv)->SetFont(bv, font, toggleall);
1205 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1207 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
1210 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
1211 if (!inset || inset->Editable() != Inset::HIGHLY_EDITABLE)
1213 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1215 x = inset->width(bv, font);
1216 y = inset->descent(bv, font);
1220 inset_x = cx(bv) - top_x + drawTextXOffset;
1221 inset_y = cy(bv) + drawTextYOffset;
1222 inset->Edit(bv, x-inset_x, y-inset_y, 0);
1223 if (!the_locking_inset)
1225 UpdateLocal(bv, CURSOR_PAR, false);
1232 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1235 int tmp_x = x - drawTextXOffset;
1236 int tmp_y = y + insetAscent;
1237 Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button);
1244 inset_x = cx(bv) - top_x + drawTextXOffset;
1245 inset_y = cy(bv) + drawTextYOffset;
1246 inset->Edit(bv, x - inset_x, y - inset_y, button);
1247 if (!the_locking_inset)
1249 UpdateLocal(bv, CURSOR_PAR, false);
1256 int InsetText::getMaxWidth(Painter & pain, UpdatableInset const * inset) const
1258 int w = UpdatableInset::getMaxWidth(pain, inset);
1263 w = w - top_x + owner()->x();
1266 w -= (2 * TEXT_TO_INSET_OFFSET);
1268 // return w - (2*TEXT_TO_INSET_OFFSET);
1272 void InsetText::SetParagraphData(LyXParagraph *p)
1286 par->SetInsetOwner(this);
1290 np->next = p->Clone();
1291 np->next->previous = np;
1293 np->SetInsetOwner(this);
1299 void InsetText::SetAutoBreakRows(bool flag)
1301 if (flag != autoBreakRows) {
1302 autoBreakRows = flag;
1310 void InsetText::SetDrawFrame(BufferView * bv, DrawFrame how)
1312 if (how != drawFrame) {
1315 UpdateLocal(bv, DRAW_FRAME, false);
1320 void InsetText::SetFrameColor(BufferView * bv, LColor::color col)
1322 if (frame_color != col) {
1325 UpdateLocal(bv, DRAW_FRAME, false);
1330 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
1332 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1336 int InsetText::cx(BufferView * bv) const
1338 return TEXT(bv)->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1342 int InsetText::cy(BufferView * bv) const
1345 return TEXT(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1349 int InsetText::cpos(BufferView * bv) const
1351 return TEXT(bv)->cursor.pos();
1355 LyXParagraph * InsetText::cpar(BufferView * bv) const
1357 return TEXT(bv)->cursor.par();
1361 Row * InsetText::crow(BufferView * bv) const
1363 return TEXT(bv)->cursor.row();
1367 LyXText * InsetText::getLyXText(BufferView * bv) const
1369 if (cache.find(bv) != cache.end())
1371 LyXText * lt = new LyXText(const_cast<InsetText *>(this));
1374 if (the_locking_inset) {
1375 lt->SetCursor(bv, inset_par, inset_pos);
1381 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1383 if (cache.find(bv) == cache.end())
1388 /// then remove all LyXText in text-insets
1389 LyXParagraph * p = par;
1390 for(;p;p = p->next) {
1391 p->deleteInsetsLyXText(bv);
1397 void InsetText::resizeLyXText(BufferView * bv) const
1399 if (!par->next && !par->size()) // resize not neccessary!
1401 if (cache.find(bv) == cache.end())
1404 LyXParagraph * lpar = 0;
1405 LyXParagraph * selstartpar = 0;
1406 LyXParagraph * selendpar = 0;
1408 int selstartpos = 0;
1413 // ProhibitInput(bv);
1416 lpar = TEXT(bv)->cursor.par();
1417 pos = TEXT(bv)->cursor.pos();
1418 selstartpar = TEXT(bv)->sel_start_cursor.par();
1419 selstartpos = TEXT(bv)->sel_start_cursor.pos();
1420 selendpar = TEXT(bv)->sel_end_cursor.par();
1421 selendpos = TEXT(bv)->sel_end_cursor.pos();
1422 selection = TEXT(bv)->selection;
1423 mark_set = TEXT(bv)->mark_set;
1425 deleteLyXText(bv, (the_locking_inset == 0));
1428 TEXT(bv)->selection = true;
1429 /* at this point just to avoid the Delete-Empty-Paragraph
1430 * Mechanism when setting the cursor */
1431 TEXT(bv)->mark_set = mark_set;
1433 TEXT(bv)->SetCursor(bv, selstartpar, selstartpos);
1434 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
1435 TEXT(bv)->SetCursor(bv, selendpar, selendpos);
1436 TEXT(bv)->SetSelection();
1437 TEXT(bv)->SetCursor(bv, lpar, pos);
1439 TEXT(bv)->SetCursor(bv, lpar, pos);
1440 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
1441 TEXT(bv)->selection = false;
1445 TEXT(bv)->first = bv->screen()->TopCursorVisible(TEXT(bv));
1446 // this will scroll the screen such that the cursor becomes visible
1447 bv->updateScrollbar();
1449 if (the_locking_inset) {
1450 /// then resize all LyXText in text-insets
1451 inset_x = cx(bv) - top_x + drawTextXOffset;
1452 inset_y = cy(bv) + drawTextYOffset;
1453 for(LyXParagraph * p = par; p; p = p->next) {
1454 p->resizeInsetsLyXText(bv);
1461 void InsetText::removeNewlines()
1463 for(LyXParagraph * p = par; p; p = p->next) {
1464 for(int i = 0; i < p->Last(); ++i) {
1465 if (p->GetChar(i) == LyXParagraph::META_NEWLINE)