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
208 int InsetText::textWidth(Painter & pain) const
210 return getMaxTextWidth(pain, this) - drawTextXOffset;
214 void InsetText::draw(BufferView * bv, LyXFont const & f,
215 int baseline, float & x, bool cleared) const
217 Painter & pain = bv->painter();
220 UpdatableInset::draw(bv, f, baseline, x);
222 if (!cleared && locked && ((need_update==FULL) || (top_x!=int(x)) ||
223 (top_baseline!=baseline))) {
226 top_baseline = baseline;
228 bv->updateInset(const_cast<InsetText *>(this), false);
231 pain.rectangle(top_x, baseline - ascent(pain, f),
232 width(pain, f), ascent(pain,f)+descent(pain, f),
236 top_baseline = baseline;
239 if (the_locking_inset && (cpos(bv) == inset_pos)) {
240 inset_x = cx(bv) - top_x + drawTextXOffset;
241 inset_y = cy(bv) + drawTextYOffset;
243 if (need_update == CURSOR) {
248 x += TEXT_TO_INSET_OFFSET; // place for border
250 Row * row = TEXT(bv)->GetRowNearY(y);
251 y += baseline - row->ascent_of_text() + 1;
252 if (cleared || !locked || (need_update == FULL)) {
254 TEXT(bv)->GetVisibleRow(bv, y, x, row, y);
258 } else if (need_update == SELECTION) {
259 bv->screen()->ToggleToggle(getLyXText(bv), y, x);
262 bv->screen()->Update(TEXT(bv), y, x);
265 TEXT(bv)->refresh_y = 0;
266 TEXT(bv)->status = LyXText::UNCHANGED;
267 if (drawLockedFrame && locked) {
268 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
269 ascent(pain,f) + descent(pain, f), frame_color);
271 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
272 ascent(pain,f) + descent(pain, f),
275 x += width(pain, f) - TEXT_TO_INSET_OFFSET;
280 void InsetText::update(BufferView * bv, LyXFont const & font, bool dodraw)
282 if (the_locking_inset)
283 the_locking_inset->update(bv, font, dodraw);
284 if (need_update == INIT) {
288 if (dodraw && (need_update != CURSOR))
291 TEXT(bv)->FullRebreak(bv);
294 Row * row = TEXT(bv)->GetRowNearY(y_temp);
295 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
296 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
297 TEXT_TO_INSET_OFFSET;
298 insetWidth = max(textWidth(bv->painter()), TEXT(bv)->width) +
299 (2 * TEXT_TO_INSET_OFFSET);
303 char const * InsetText::EditMessage() const
305 return _("Opened Text Inset");
309 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
311 // par->SetInsetOwner(this);
312 UpdatableInset::Edit(bv, x, y, button);
314 if (!bv->lockInset(this)) {
315 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
319 the_locking_inset = 0;
320 inset_pos = inset_x = inset_y = 0;
321 #warning Fix cursor setting here!!! (Jug)
322 TEXT(bv)->SetCursor(bv, par, 0);
323 // setPos(bv->painter(), x, y);
324 checkAndActivateInset(bv, x, y, button);
325 // selection_start_cursor = selection_end_cursor = cursor;
326 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
327 bv->text->FinishUndo();
328 UpdateLocal(bv, FULL, false);
332 void InsetText::InsetUnlock(BufferView * bv)
334 if (the_locking_inset) {
335 the_locking_inset->InsetUnlock(bv);
336 the_locking_inset = 0;
339 lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this <<
341 no_selection = false;
343 TEXT(bv)->selection = 0;
344 UpdateLocal(bv, FULL, false);
345 bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1);
349 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
351 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
354 if (inset == cpar(bv)->GetInset(cpos(bv))) {
355 lyxerr[Debug::INSETS] << "OK" << endl;
356 the_locking_inset = inset;
357 // resetPos(bv->painter());
358 inset_x = cx(bv) - top_x + drawTextXOffset;
359 inset_y = cy(bv) + drawTextYOffset;
360 inset_pos = cpos(bv);
362 } else if (the_locking_inset && (the_locking_inset == inset)) {
363 if (cpos(bv) == inset_pos) {
364 lyxerr[Debug::INSETS] << "OK" << endl;
365 // resetPos(bv->painter());
366 inset_x = cx(bv) - top_x + drawTextXOffset;
367 inset_y = cy(bv) + drawTextYOffset;
369 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
371 } else if (the_locking_inset) {
372 lyxerr[Debug::INSETS] << "MAYBE" << endl;
373 return the_locking_inset->LockInsetInInset(bv, inset);
375 lyxerr[Debug::INSETS] << "NOT OK" << endl;
380 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
383 if (!the_locking_inset)
385 if (the_locking_inset == inset) {
386 the_locking_inset->InsetUnlock(bv);
387 the_locking_inset = 0;
389 moveRight(bv, false);
392 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
396 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
398 if (!the_locking_inset)
400 if (the_locking_inset != inset)
401 return the_locking_inset->UpdateInsetInInset(bv, inset);
402 lyxerr[Debug::INSETS] << "InsetText::UpdateInsetInInset(" << inset <<
404 UpdateLocal(bv, FULL, false);
405 if (cpos(bv) == inset_pos) {
406 inset_x = cx(bv) - top_x + drawTextXOffset;
407 inset_y = cy(bv) + drawTextYOffset;
413 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
415 if (TEXT(bv)->selection) {
416 TEXT(bv)->selection = 0;
417 UpdateLocal(bv, FULL, false);
419 no_selection = false;
420 TEXT(bv)->SetCursorFromCoordinates(bv, x, y+TEXT(bv)->first);
421 if (the_locking_inset) {
422 UpdatableInset * inset = 0;
423 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET)
424 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
425 if (the_locking_inset == inset) {
426 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
429 // otherwise unlock the_locking_inset and lock the new inset
430 the_locking_inset->InsetUnlock(bv);
431 inset_x = cx(bv) - top_x + drawTextXOffset;
432 inset_y = cy(bv) + drawTextYOffset;
433 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
434 inset->Edit(bv, x - inset_x, y - inset_y, button);
435 UpdateLocal(bv, FULL, false);
438 // otherwise only unlock the_locking_inset
439 the_locking_inset->InsetUnlock(bv);
440 the_locking_inset = 0;
442 if (bv->the_locking_inset) {
443 if ((cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) &&
444 cpar(bv)->GetInset(cpos(bv)) &&
445 (cpar(bv)->GetInset(cpos(bv))->Editable() == Inset::HIGHLY_EDITABLE)) {
446 UpdatableInset * inset =
447 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
448 inset_x = cx(bv) - top_x + drawTextXOffset;
449 inset_y = cy(bv) + drawTextYOffset;
450 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
451 inset->Edit(bv, x - inset_x, y - inset_y, 0);
452 UpdateLocal(bv, FULL, false);
455 // selection_start_cursor = selection_end_cursor = cursor;
459 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
461 UpdatableInset * inset = 0;
463 if (the_locking_inset) {
464 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
466 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
467 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
468 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
469 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
471 inset_x = cx(bv) - top_x + drawTextXOffset;
472 inset_y = cy(bv) + drawTextYOffset;
473 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
474 inset->Edit(bv, x - inset_x, y - inset_y, button);
478 no_selection = false;
482 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
484 if (the_locking_inset) {
485 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
489 #warning REDO this (Jug)
491 // LyXCursor old = selection_end_cursor;
493 // setPos(bv->painter(), x, y);
494 // selection_end_cursor = cursor;
495 // if (old != selection_end_cursor)
496 // UpdateLocal(bv, false, false);
499 no_selection = false;
503 void InsetText::InsetKeyPress(XKeyEvent * xke)
505 if (the_locking_inset) {
506 the_locking_inset->InsetKeyPress(xke);
512 UpdatableInset::RESULT
513 InsetText::LocalDispatch(BufferView * bv,
514 int action, string const & arg)
516 no_selection = false;
517 UpdatableInset::RESULT
518 result= UpdatableInset::LocalDispatch(bv, action, arg);
519 if (result != UNDISPATCHED) {
520 // resetPos(bv->painter());
525 if ((action < 0) && arg.empty())
528 if (the_locking_inset) {
529 result = the_locking_inset->LocalDispatch(bv, action, arg);
530 if (result == DISPATCHED_NOUPDATE)
532 else if (result == DISPATCHED) {
533 the_locking_inset->ToggleInsetCursor(bv);
534 UpdateLocal(bv, FULL, false);
535 the_locking_inset->ToggleInsetCursor(bv);
537 } else if (result == FINISHED) {
542 // TEXT(bv)->cursor.pos(inset_pos + 1);
543 // resetPos(bv->painter());
549 the_locking_inset = 0;
557 if (bv->buffer()->isReadonly()) {
559 // setErrorMessage(N_("Document is read only"));
563 /* Automatically delete the currently selected
564 * text and replace it with what is being
565 * typed in now. Depends on lyxrc settings
566 * "auto_region_delete", which defaults to
569 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
570 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
571 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
572 if (lyxrc.auto_region_delete) {
573 if (TEXT(bv)->selection){
574 TEXT(bv)->CutSelection(bv, false);
577 TEXT(bv)->ClearSelection();
578 for (string::size_type i = 0; i < arg.length(); ++i) {
579 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
582 UpdateLocal(bv, CURSOR_PAR, true);
584 // --- Cursor Movements ---------------------------------------------
586 bv->text->FinishUndo();
587 moveRight(bv, false);
588 TEXT(bv)->SetSelection();
589 UpdateLocal(bv, SELECTION, false);
592 bv->text->FinishUndo();
593 result = moveRight(bv);
594 TEXT(bv)->selection = 0;
595 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
596 UpdateLocal(bv, CURSOR, false);
599 bv->text->FinishUndo();
601 TEXT(bv)->SetSelection();
602 UpdateLocal(bv, SELECTION, false);
605 bv->text->FinishUndo();
606 result= moveLeft(bv);
607 TEXT(bv)->selection = 0;
608 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
609 UpdateLocal(bv, CURSOR, false);
612 bv->text->FinishUndo();
614 TEXT(bv)->SetSelection();
615 UpdateLocal(bv, SELECTION, false);
618 bv->text->FinishUndo();
619 result = moveDown(bv);
620 TEXT(bv)->selection = 0;
621 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
622 UpdateLocal(bv, CURSOR, false);
625 bv->text->FinishUndo();
627 TEXT(bv)->SetSelection();
628 UpdateLocal(bv, SELECTION, false);
631 bv->text->FinishUndo();
633 TEXT(bv)->selection = 0;
634 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
635 UpdateLocal(bv, CURSOR, false);
638 bv->text->FinishUndo();
639 TEXT(bv)->CursorHome(bv);
640 TEXT(bv)->selection = 0;
641 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
642 UpdateLocal(bv, CURSOR, false);
645 TEXT(bv)->CursorEnd(bv);
646 TEXT(bv)->selection = 0;
647 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
648 UpdateLocal(bv, CURSOR, false);
651 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
652 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
653 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
654 TEXT(bv)->Backspace(bv);
655 UpdateLocal(bv, CURSOR_PAR, true);
658 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
659 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
660 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
661 TEXT(bv)->Delete(bv);
662 UpdateLocal(bv, CURSOR_PAR, true);
665 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
666 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
667 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
668 TEXT(bv)->CutSelection(bv);
669 UpdateLocal(bv, CURSOR_PAR, true);
672 bv->text->FinishUndo();
673 TEXT(bv)->CopySelection(bv);
674 UpdateLocal(bv, CURSOR_PAR, false);
677 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
678 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
679 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
680 TEXT(bv)->PasteSelection(bv);
681 UpdateLocal(bv, CURSOR_PAR, true);
683 case LFUN_BREAKPARAGRAPH:
686 TEXT(bv)->BreakParagraph(bv, 0);
687 UpdateLocal(bv, CURSOR_PAR, true);
692 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
693 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
694 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
695 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
696 UpdateLocal(bv, CURSOR_PAR, true);
700 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
702 // Derive layout number from given argument (string)
703 // and current buffer's textclass (number). */
704 LyXTextClassList::ClassList::size_type tclass =
705 bv->buffer()->params.textclass;
706 std::pair <bool, LyXTextClass::size_type> layout =
707 textclasslist.NumberOfLayout(tclass, arg);
709 // If the entry is obsolete, use the new one instead.
711 string obs = textclasslist.Style(tclass,layout.second).
714 layout = textclasslist.NumberOfLayout(tclass, obs);
717 // see if we found the layout number:
719 string msg = string(N_("Layout ")) + arg + N_(" not known");
721 bv->owner()->getMiniBuffer()->Set(msg);
725 if (cur_layout != layout.second) {
726 cur_layout = layout.second;
727 TEXT(bv)->SetLayout(bv, layout.second);
728 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
729 UpdateLocal(bv, CURSOR_PAR, true);
734 result = UNDISPATCHED;
737 if (result != FINISHED) {
740 bv->unlockInset(this);
745 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
748 buf->latexParagraphs(os, par, 0, texrow);
749 return texrow.rows();
753 void InsetText::Validate(LaTeXFeatures & features) const
755 LyXParagraph * p = par;
757 p->validate(features);
763 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
765 if (textclasslist.Style(buf->params.textclass,
766 p->GetLayout()).labeltype != LABEL_MANUAL)
769 return p->BeginningOfMainBody();
773 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
780 int InsetText::InsetInInsetY()
782 if (!the_locking_inset)
785 return (inset_y + the_locking_inset->InsetInInsetY());
789 void InsetText::ToggleInsetCursor(BufferView * bv)
791 if (the_locking_inset) {
792 the_locking_inset->ToggleInsetCursor(bv);
796 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
798 int asc = lyxfont::maxAscent(font);
799 int desc = lyxfont::maxDescent(font);
802 bv->hideLockedInsetCursor();
804 bv->showLockedInsetCursor(cx(bv), cy(bv),
806 cursor_visible = !cursor_visible;
810 void InsetText::ShowInsetCursor(BufferView * bv)
812 if (the_locking_inset) {
813 the_locking_inset->ShowInsetCursor(bv);
816 if (!cursor_visible) {
817 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
819 int asc = lyxfont::maxAscent(font);
820 int desc = lyxfont::maxDescent(font);
822 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
823 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
824 cursor_visible = true;
829 void InsetText::HideInsetCursor(BufferView * bv)
831 if (cursor_visible) {
832 bv->hideLockedInsetCursor();
833 cursor_visible = false;
835 if (the_locking_inset)
836 the_locking_inset->HideInsetCursor(bv);
840 UpdatableInset::RESULT
841 InsetText::moveRight(BufferView * bv, bool activate_inset)
843 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
845 if (activate_inset && checkAndActivateInset(bv)) {
848 TEXT(bv)->CursorRight(bv);
849 // real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv));
850 return DISPATCHED_NOUPDATE;
854 UpdatableInset::RESULT
855 InsetText::moveLeft(BufferView * bv, bool activate_inset)
857 if (!cpar(bv)->previous && (cpos(bv) <= 0))
859 TEXT(bv)->CursorLeft(bv);
861 if (checkAndActivateInset(bv, -1, -1))
863 return DISPATCHED_NOUPDATE;
867 UpdatableInset::RESULT
868 InsetText::moveUp(BufferView * bv)
870 if (!crow(bv)->previous())
872 TEXT(bv)->CursorUp(bv);
873 return DISPATCHED_NOUPDATE;
877 UpdatableInset::RESULT
878 InsetText::moveDown(BufferView * bv)
880 if (!crow(bv)->next())
882 TEXT(bv)->CursorDown(bv);
883 return DISPATCHED_NOUPDATE;
887 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
889 if (the_locking_inset) {
890 if (the_locking_inset->InsertInsetAllowed(inset))
891 return the_locking_inset->InsertInset(bv, inset);
894 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
895 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
896 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
897 if (inset->Editable() == Inset::IS_EDITABLE) {
898 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
899 i->setOwner(static_cast<UpdatableInset *>(this));
901 cpar(bv)->InsertChar(cpos(bv), LyXParagraph::META_INSET);
902 cpar(bv)->InsertInset(cpos(bv), inset);
903 TEXT(bv)->selection = 0;
904 UpdateLocal(bv, CURSOR_PAR, true);
905 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
910 UpdatableInset * InsetText::GetLockingInset()
912 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
916 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
920 if (the_locking_inset)
921 return the_locking_inset->GetFirstLockingInsetOfType(c);
926 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
928 TEXT(bv)->SetFont(bv, font, toggleall);
932 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
934 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
938 if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED))
939 bv->updateInset(this, mark_dirty);
940 if (old_par != cpar(bv)) {
941 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
947 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
950 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
951 UpdatableInset * inset =
952 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
953 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
955 x = inset->width(bv->painter(), font);
957 y = inset->descent(bv->painter(), font);
958 inset_x = cx(bv) - top_x + drawTextXOffset;
959 inset_y = cy(bv) + drawTextYOffset;
960 inset->Edit(bv, x - inset_x, y - inset_y, button);
961 if (!the_locking_inset)
963 UpdateLocal(bv, CURSOR_PAR, false);
970 int InsetText::getMaxTextWidth(Painter & pain, UpdatableInset const * inset) const
972 return getMaxWidth(pain, inset) - 4; // 2+2 width of eventual border
975 void InsetText::SetParagraphData(LyXParagraph *p)
989 par->SetInsetOwner(this);
993 np->next = p->Clone();
994 np->next->previous = np;
996 np->SetInsetOwner(this);
1001 void InsetText::SetAutoBreakRows(bool flag)
1003 if (flag != autoBreakRows) {
1004 autoBreakRows = flag;
1009 void InsetText::SetDrawLockedFrame(bool flag)
1011 if (flag != drawLockedFrame)
1012 drawLockedFrame = flag;
1015 void InsetText::SetFrameColor(LColor::color col)
1017 if (frame_color != col)
1021 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
1023 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1026 int InsetText::cx(BufferView * bv) const
1028 return TEXT(bv)->cursor.x() + top_x + 1;
1031 int InsetText::cy(BufferView * bv) const
1033 long int y_dummy = 0;
1034 Row * tmprow = TEXT(bv)->GetRowNearY(y_dummy);
1035 return TEXT(bv)->cursor.y() - tmprow->baseline();
1038 int InsetText::cpos(BufferView * bv) const
1040 return TEXT(bv)->cursor.pos();
1043 LyXParagraph * InsetText::cpar(BufferView * bv) const
1045 return TEXT(bv)->cursor.par();
1048 Row * InsetText::crow(BufferView * bv) const
1050 return TEXT(bv)->cursor.row();
1053 LyXText * InsetText::getLyXText(BufferView * bv) const
1055 if (cache.find(bv) != cache.end())
1057 LyXText *lt = new LyXText(const_cast<InsetText *>(this));
1063 void InsetText::deleteLyXText(BufferView * bv)