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"
43 #include "support/textutils.h"
44 #include "support/LAssert.h"
48 #include "trans_mgr.h"
49 #include "lyxscreen.h"
57 extern unsigned char getCurrentTextClass(Buffer *);
59 #define TEXT(a) getLyXText(a)
61 InsetText::InsetText()
63 par = new LyXParagraph();
68 InsetText::InsetText(InsetText const & ins)
73 autoBreakRows = ins.autoBreakRows;
77 InsetText & InsetText::operator=(InsetText const & it)
80 autoBreakRows = it.autoBreakRows;
84 void InsetText::init(InsetText const * ins)
86 insetAscent = insetDescent = insetWidth = 0;
87 the_locking_inset = 0;
88 cursor_visible = false;
92 drawTextXOffset = drawTextYOffset = 0;
93 autoBreakRows = drawLockedFrame = false;
96 SetParagraphData(ins->par);
97 autoBreakRows = ins->autoBreakRows;
98 drawLockedFrame = ins->drawLockedFrame;
100 par->SetInsetOwner(this);
101 frame_color = LColor::insetframe;
107 InsetText::~InsetText()
120 Inset * InsetText::Clone() const
122 InsetText * t = new InsetText(*this);
127 void InsetText::Write(Buffer const * buf, ostream & os) const
130 WriteParagraphData(buf, os);
134 void InsetText::WriteParagraphData(Buffer const * buf, ostream & os) const
136 par->writeFile(buf, os, buf->params, 0, 0);
140 void InsetText::Read(Buffer const * buf, LyXLex & lex)
142 string token, tmptok;
144 LyXParagraph * return_par = 0;
145 char depth = 0; // signed or unsigned?
146 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
147 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
148 LyXFont font(LyXFont::ALL_INHERIT);
158 par = new LyXParagraph;
161 token = lex.GetString();
164 if (token == "\\end_inset")
166 if (const_cast<Buffer*>(buf)->parseSingleLyXformat2Token(lex, par, return_par,
170 // the_end read this should NEVER happen
171 lex.printError("\\the_end read in inset! Error in document!");
179 return_par->SetInsetOwner(this);
180 return_par = return_par->next;
183 if (token != "\\end_inset") {
184 lex.printError("Missing \\end_inset at this point. "
191 int InsetText::ascent(Painter &, LyXFont const &) const
197 int InsetText::descent(Painter &, LyXFont const &) const
203 int InsetText::width(Painter &, LyXFont const &) const
209 void InsetText::draw(BufferView * bv, LyXFont const & f,
210 int baseline, float & x) const
212 Painter & pain = bv->painter();
215 UpdatableInset::draw(bv, f, baseline, x);
217 top_baseline = baseline;
220 if (the_locking_inset && (cpos(bv) == inset_pos)) {
221 inset_x = cx(bv) - top_x + drawTextXOffset;
222 inset_y = cy(bv) + drawTextYOffset;
224 x += TEXT_TO_INSET_OFFSET; // place for border
226 Row * row = TEXT(bv)->GetRowNearY(y);
227 y += baseline - row->ascent_of_text() + 1;
228 if (!locked || (need_update == FULL)) {
230 TEXT(bv)->GetVisibleRow(bv, y, x, row, y);
234 if (drawLockedFrame && locked) {
235 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
236 ascent(pain,f) + descent(pain, f), frame_color);
239 bv->screen()->Update(TEXT(bv));
241 x += width(pain, f) - TEXT_TO_INSET_OFFSET;
245 void InsetText::update(BufferView * bv, LyXFont const &, bool dodraw)
247 if (need_update == INIT) {
253 switch(need_update) {
254 case NONE: // most common first
263 TEXT(bv)->FullRebreak(bv);
271 TEXT(bv)->FullRebreak(bv);
274 Row * row = TEXT(bv)->GetRowNearY(y_temp);
275 insetAscent = row->ascent_of_text() + 2;
276 insetDescent = TEXT(bv)->height - row->ascent_of_text() + 2;
277 insetWidth = max(getMaxTextWidth(bv->painter(), this), TEXT(bv)->width);
281 char const * InsetText::EditMessage() const
283 return _("Opened Text Inset");
287 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
289 // par->SetInsetOwner(this);
290 UpdatableInset::Edit(bv, x, y, button);
292 if (!bv->lockInset(this)) {
293 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
297 the_locking_inset = 0;
298 inset_pos = inset_x = inset_y = 0;
299 // setPos(bv->painter(), x, y);
300 checkAndActivateInset(bv, x, y, button);
301 // selection_start_cursor = selection_end_cursor = cursor;
302 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
303 bv->text->FinishUndo();
304 UpdateLocal(bv, FULL, false);
308 void InsetText::InsetUnlock(BufferView * bv)
310 if (the_locking_inset) {
311 the_locking_inset->InsetUnlock(bv);
312 the_locking_inset = 0;
315 lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this <<
317 no_selection = false;
319 TEXT(bv)->selection = 0;
320 UpdateLocal(bv, FULL, false);
321 bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1);
325 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
327 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
330 if (inset == cpar(bv)->GetInset(cpos(bv))) {
331 lyxerr[Debug::INSETS] << "OK" << endl;
332 the_locking_inset = inset;
333 // resetPos(bv->painter());
334 inset_x = cx(bv) - top_x + drawTextXOffset;
335 inset_y = cy(bv) + drawTextYOffset;
336 inset_pos = cpos(bv);
338 } else if (the_locking_inset && (the_locking_inset == inset)) {
339 if (cpos(bv) == inset_pos) {
340 lyxerr[Debug::INSETS] << "OK" << endl;
341 // resetPos(bv->painter());
342 inset_x = cx(bv) - top_x + drawTextXOffset;
343 inset_y = cy(bv) + drawTextYOffset;
345 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
347 } else if (the_locking_inset) {
348 lyxerr[Debug::INSETS] << "MAYBE" << endl;
349 return the_locking_inset->LockInsetInInset(bv, inset);
351 lyxerr[Debug::INSETS] << "NOT OK" << endl;
356 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
359 if (!the_locking_inset)
361 if (the_locking_inset == inset) {
362 the_locking_inset->InsetUnlock(bv);
363 the_locking_inset = 0;
365 moveRight(bv, false);
368 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
372 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
374 if (!the_locking_inset)
376 if (the_locking_inset != inset)
377 return the_locking_inset->UpdateInsetInInset(bv, inset);
378 lyxerr[Debug::INSETS] << "InsetText::UpdateInsetInInset(" << inset <<
380 UpdateLocal(bv, FULL, false);
381 if (cpos(bv) == inset_pos) {
382 inset_x = cx(bv) - top_x + drawTextXOffset;
383 inset_y = cy(bv) + drawTextYOffset;
389 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
391 if (TEXT(bv)->selection) {
392 TEXT(bv)->selection = 0;
393 UpdateLocal(bv, FULL, false);
395 no_selection = false;
396 // setPos(bv->painter(), x, y);
398 TEXT(bv)->SetCursorFromCoordinates(bv, x, y+bv->screen()->first);
399 if (the_locking_inset) {
400 UpdatableInset * inset = 0;
401 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET)
402 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
403 if (the_locking_inset == inset) {
404 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
407 // otherwise unlock the_locking_inset and lock the new inset
408 the_locking_inset->InsetUnlock(bv);
409 inset_x = cx(bv) - top_x + drawTextXOffset;
410 inset_y = cy(bv) + drawTextYOffset;
411 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
412 inset->Edit(bv, x - inset_x, y - inset_y, button);
413 UpdateLocal(bv, FULL, false);
416 // otherwise only unlock the_locking_inset
417 the_locking_inset->InsetUnlock(bv);
418 the_locking_inset = 0;
420 if (bv->the_locking_inset) {
421 if ((cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) &&
422 cpar(bv)->GetInset(cpos(bv)) &&
423 (cpar(bv)->GetInset(cpos(bv))->Editable() == Inset::HIGHLY_EDITABLE)) {
424 UpdatableInset * inset =
425 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
426 inset_x = cx(bv) - top_x + drawTextXOffset;
427 inset_y = cy(bv) + drawTextYOffset;
428 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
429 inset->Edit(bv, x - inset_x, y - inset_y, 0);
430 UpdateLocal(bv, FULL, false);
433 // selection_start_cursor = selection_end_cursor = cursor;
437 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
439 UpdatableInset * inset = 0;
441 if (the_locking_inset) {
442 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
444 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
445 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
446 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
447 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
449 inset_x = cx(bv) - top_x + drawTextXOffset;
450 inset_y = cy(bv) + drawTextYOffset;
451 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
452 inset->Edit(bv, x - inset_x, y - inset_y, button);
456 no_selection = false;
460 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
462 if (the_locking_inset) {
463 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
467 #warning REDO this (Jug)
469 // LyXCursor old = selection_end_cursor;
471 // setPos(bv->painter(), x, y);
472 // selection_end_cursor = cursor;
473 // if (old != selection_end_cursor)
474 // UpdateLocal(bv, false, false);
477 no_selection = false;
481 void InsetText::InsetKeyPress(XKeyEvent * xke)
483 if (the_locking_inset) {
484 the_locking_inset->InsetKeyPress(xke);
490 UpdatableInset::RESULT
491 InsetText::LocalDispatch(BufferView * bv,
492 int action, string const & arg)
494 no_selection = false;
495 UpdatableInset::RESULT
496 result= UpdatableInset::LocalDispatch(bv, action, arg);
497 if (result != UNDISPATCHED) {
498 // resetPos(bv->painter());
503 if ((action < 0) && arg.empty())
506 if (the_locking_inset) {
507 result = the_locking_inset->LocalDispatch(bv, action, arg);
508 if (result == DISPATCHED_NOUPDATE)
510 else if (result == DISPATCHED) {
511 the_locking_inset->ToggleInsetCursor(bv);
512 UpdateLocal(bv, FULL, false);
513 the_locking_inset->ToggleInsetCursor(bv);
515 } else if (result == FINISHED) {
520 // TEXT(bv)->cursor.pos(inset_pos + 1);
521 // resetPos(bv->painter());
527 the_locking_inset = 0;
535 if (bv->buffer()->isReadonly()) {
537 // setErrorMessage(N_("Document is read only"));
541 /* Automatically delete the currently selected
542 * text and replace it with what is being
543 * typed in now. Depends on lyxrc settings
544 * "auto_region_delete", which defaults to
547 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
548 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
549 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
550 if (lyxrc.auto_region_delete) {
551 if (TEXT(bv)->selection){
552 TEXT(bv)->CutSelection(bv, false);
555 TEXT(bv)->ClearSelection();
556 for (string::size_type i = 0; i < arg.length(); ++i) {
557 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
560 UpdateLocal(bv, CURSOR_PAR, true);
562 // --- Cursor Movements ---------------------------------------------
564 bv->text->FinishUndo();
565 moveRight(bv, false);
566 TEXT(bv)->SetSelection();
567 UpdateLocal(bv, CURSOR_PAR, false);
570 bv->text->FinishUndo();
571 result = moveRight(bv);
572 TEXT(bv)->selection = 0;
573 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
574 UpdateLocal(bv, CURSOR_PAR, false);
577 bv->text->FinishUndo();
579 TEXT(bv)->SetSelection();
580 UpdateLocal(bv, CURSOR_PAR, false);
583 bv->text->FinishUndo();
584 result= moveLeft(bv);
585 TEXT(bv)->selection = 0;
586 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
587 UpdateLocal(bv, CURSOR_PAR, false);
590 bv->text->FinishUndo();
592 TEXT(bv)->SetSelection();
593 UpdateLocal(bv, CURSOR_PAR, false);
596 bv->text->FinishUndo();
597 result = moveDown(bv);
598 TEXT(bv)->selection = 0;
599 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
600 UpdateLocal(bv, CURSOR_PAR, false);
603 bv->text->FinishUndo();
605 TEXT(bv)->SetSelection();
606 UpdateLocal(bv, CURSOR_PAR, false);
609 bv->text->FinishUndo();
611 TEXT(bv)->selection = 0;
612 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
613 UpdateLocal(bv, CURSOR_PAR, false);
616 bv->text->FinishUndo();
617 TEXT(bv)->CursorHome(bv);
618 TEXT(bv)->selection = 0;
619 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
620 UpdateLocal(bv, CURSOR_PAR, false);
623 TEXT(bv)->CursorEnd(bv);
624 TEXT(bv)->selection = 0;
625 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
626 UpdateLocal(bv, CURSOR_PAR, false);
629 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
630 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
631 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
632 TEXT(bv)->Backspace(bv);
633 UpdateLocal(bv, CURSOR_PAR, true);
636 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
637 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
638 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
639 TEXT(bv)->Delete(bv);
640 UpdateLocal(bv, CURSOR_PAR, true);
643 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
644 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
645 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
646 TEXT(bv)->CutSelection(bv);
647 UpdateLocal(bv, CURSOR_PAR, true);
650 bv->text->FinishUndo();
651 TEXT(bv)->CopySelection(bv);
652 UpdateLocal(bv, CURSOR_PAR, false);
655 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
656 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
657 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
658 TEXT(bv)->PasteSelection(bv);
659 UpdateLocal(bv, CURSOR_PAR, true);
661 case LFUN_BREAKPARAGRAPH:
664 TEXT(bv)->BreakParagraph(bv, 0);
665 UpdateLocal(bv, CURSOR_PAR, true);
670 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
671 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
672 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
673 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
674 UpdateLocal(bv, CURSOR_PAR, true);
678 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
680 // Derive layout number from given argument (string)
681 // and current buffer's textclass (number). */
682 LyXTextClassList::ClassList::size_type tclass =
683 bv->buffer()->params.textclass;
684 std::pair <bool, LyXTextClass::size_type> layout =
685 textclasslist.NumberOfLayout(tclass, arg);
687 // If the entry is obsolete, use the new one instead.
689 string obs = textclasslist.Style(tclass,layout.second).
692 layout = textclasslist.NumberOfLayout(tclass, obs);
695 // see if we found the layout number:
697 string msg = string(N_("Layout ")) + arg + N_(" not known");
699 bv->owner()->getMiniBuffer()->Set(msg);
703 if (cur_layout != layout.second) {
704 cur_layout = layout.second;
705 TEXT(bv)->SetLayout(bv, layout.second);
706 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
707 UpdateLocal(bv, CURSOR_PAR, true);
712 result = UNDISPATCHED;
715 if (result != FINISHED) {
718 bv->unlockInset(this);
723 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
726 buf->latexParagraphs(os, par, 0, texrow);
727 return texrow.rows();
731 void InsetText::Validate(LaTeXFeatures & features) const
733 LyXParagraph * p = par;
735 p->validate(features);
741 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
743 if (textclasslist.Style(buf->params.textclass,
744 p->GetLayout()).labeltype != LABEL_MANUAL)
747 return p->BeginningOfMainBody();
751 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
758 int InsetText::InsetInInsetY()
760 if (!the_locking_inset)
763 return (inset_y + the_locking_inset->InsetInInsetY());
767 void InsetText::ToggleInsetCursor(BufferView * bv)
769 if (the_locking_inset) {
770 the_locking_inset->ToggleInsetCursor(bv);
774 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
776 int asc = lyxfont::maxAscent(font);
777 int desc = lyxfont::maxDescent(font);
780 bv->hideLockedInsetCursor();
782 bv->showLockedInsetCursor(cx(bv), cy(bv),
784 cursor_visible = !cursor_visible;
788 void InsetText::ShowInsetCursor(BufferView * bv)
790 if (the_locking_inset) {
791 the_locking_inset->ShowInsetCursor(bv);
794 if (!cursor_visible) {
795 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
797 int asc = lyxfont::maxAscent(font);
798 int desc = lyxfont::maxDescent(font);
800 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
801 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
802 cursor_visible = true;
807 void InsetText::HideInsetCursor(BufferView * bv)
809 if (cursor_visible) {
810 bv->hideLockedInsetCursor();
811 cursor_visible = false;
813 if (the_locking_inset)
814 the_locking_inset->HideInsetCursor(bv);
818 UpdatableInset::RESULT
819 InsetText::moveRight(BufferView * bv, bool activate_inset)
821 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
823 if (activate_inset && checkAndActivateInset(bv)) {
826 TEXT(bv)->CursorRight(bv);
827 // real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv));
828 return DISPATCHED_NOUPDATE;
832 UpdatableInset::RESULT
833 InsetText::moveLeft(BufferView * bv, bool activate_inset)
835 if (!cpar(bv)->previous && (cpos(bv) <= 0))
837 TEXT(bv)->CursorLeft(bv);
839 if (checkAndActivateInset(bv, -1, -1))
841 return DISPATCHED_NOUPDATE;
845 UpdatableInset::RESULT
846 InsetText::moveUp(BufferView * bv)
848 if (!crow(bv)->previous())
850 TEXT(bv)->CursorUp(bv);
851 return DISPATCHED_NOUPDATE;
855 UpdatableInset::RESULT
856 InsetText::moveDown(BufferView * bv)
858 if (!crow(bv)->next())
860 TEXT(bv)->CursorDown(bv);
861 return DISPATCHED_NOUPDATE;
865 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
867 if (the_locking_inset) {
868 if (the_locking_inset->InsertInsetAllowed(inset))
869 return the_locking_inset->InsertInset(bv, inset);
872 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
873 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
874 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
875 if (inset->Editable() == Inset::IS_EDITABLE) {
876 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
877 i->setOwner(static_cast<UpdatableInset *>(this));
879 cpar(bv)->InsertChar(cpos(bv), LyXParagraph::META_INSET);
880 cpar(bv)->InsertInset(cpos(bv), inset);
881 TEXT(bv)->selection = 0;
882 UpdateLocal(bv, CURSOR_PAR, true);
883 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
888 UpdatableInset * InsetText::GetLockingInset()
890 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
894 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
898 if (the_locking_inset)
899 return the_locking_inset->GetFirstLockingInsetOfType(c);
904 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
906 TEXT(bv)->SetFont(bv, font, toggleall);
910 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
913 bv->updateInset(this, mark_dirty);
914 if (old_par != cpar(bv)) {
915 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
921 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
924 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
925 UpdatableInset * inset =
926 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
927 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
929 x = inset->width(bv->painter(), font);
931 y = inset->descent(bv->painter(), font);
932 inset_x = cx(bv) - top_x + drawTextXOffset;
933 inset_y = cy(bv) + drawTextYOffset;
934 inset->Edit(bv, x - inset_x, y - inset_y, button);
935 if (!the_locking_inset)
937 UpdateLocal(bv, CURSOR_PAR, false);
944 int InsetText::getMaxTextWidth(Painter & pain, UpdatableInset const * inset) const
946 return getMaxWidth(pain, inset) - 4; // 2+2 width of eventual border
949 void InsetText::SetParagraphData(LyXParagraph *p)
963 par->SetInsetOwner(this);
967 np->next = p->Clone();
968 np->next->previous = np;
970 np->SetInsetOwner(this);
975 void InsetText::SetAutoBreakRows(bool flag)
977 if (flag != autoBreakRows) {
978 autoBreakRows = flag;
983 void InsetText::SetDrawLockedFrame(bool flag)
985 if (flag != drawLockedFrame)
986 drawLockedFrame = flag;
989 void InsetText::SetFrameColor(LColor::color col)
991 if (frame_color != col)
995 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
997 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1000 int InsetText::cx(BufferView * bv) const
1002 return TEXT(bv)->cursor.x() + top_x + 1;
1005 int InsetText::cy(BufferView * bv) const
1007 long int y_dummy = 0;
1008 Row * tmprow = TEXT(bv)->GetRowNearY(y_dummy);
1009 return TEXT(bv)->cursor.y() - tmprow->baseline();
1012 int InsetText::cpos(BufferView * bv) const
1014 return TEXT(bv)->cursor.pos();
1017 LyXParagraph * InsetText::cpar(BufferView * bv) const
1019 return TEXT(bv)->cursor.par();
1022 Row * InsetText::crow(BufferView * bv) const
1024 return TEXT(bv)->cursor.row();
1027 LyXText * InsetText::getLyXText(BufferView * bv) const
1029 if (cache.find(bv) != cache.end())
1031 LyXText *lt = new LyXText(const_cast<InsetText *>(this));
1037 void InsetText::deleteLyXText(BufferView * bv)