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 if (locked && ((need_update==FULL) || (top_x!=int(x)) ||
218 (top_baseline!=baseline))) {
221 top_baseline = baseline;
223 bv->updateInset(const_cast<InsetText *>(this), false);
226 pain.rectangle(top_x, baseline - ascent(pain, f),
227 width(pain, f), ascent(pain,f)+descent(pain, f),
231 top_baseline = baseline;
234 if (the_locking_inset && (cpos(bv) == inset_pos)) {
235 inset_x = cx(bv) - top_x + drawTextXOffset;
236 inset_y = cy(bv) + drawTextYOffset;
238 x += TEXT_TO_INSET_OFFSET; // place for border
240 Row * row = TEXT(bv)->GetRowNearY(y);
241 y += baseline - row->ascent_of_text() + 1;
242 if (!locked || (need_update == FULL)) {
244 TEXT(bv)->GetVisibleRow(bv, y, x, row, y);
248 } else if (need_update == SELECTION) {
249 bv->screen()->ToggleToggle(getLyXText(bv), y, x);
252 bv->screen()->Update(TEXT(bv), y, x);
255 if (drawLockedFrame && locked) {
256 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
257 ascent(pain,f) + descent(pain, f), frame_color);
259 x += width(pain, f) - TEXT_TO_INSET_OFFSET;
264 void InsetText::update(BufferView * bv, LyXFont const & font, bool dodraw)
266 if (the_locking_inset)
267 the_locking_inset->update(bv, font, dodraw);
268 if (need_update == INIT) {
275 TEXT(bv)->FullRebreak(bv);
278 Row * row = TEXT(bv)->GetRowNearY(y_temp);
279 insetAscent = row->ascent_of_text() + 2;
280 insetDescent = TEXT(bv)->height - row->ascent_of_text() + 2;
281 insetWidth = max(getMaxTextWidth(bv->painter(), this), TEXT(bv)->width);
285 char const * InsetText::EditMessage() const
287 return _("Opened Text Inset");
291 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
293 // par->SetInsetOwner(this);
294 UpdatableInset::Edit(bv, x, y, button);
296 if (!bv->lockInset(this)) {
297 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
301 the_locking_inset = 0;
302 inset_pos = inset_x = inset_y = 0;
303 // setPos(bv->painter(), x, y);
304 checkAndActivateInset(bv, x, y, button);
305 // selection_start_cursor = selection_end_cursor = cursor;
306 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
307 bv->text->FinishUndo();
308 UpdateLocal(bv, FULL, false);
312 void InsetText::InsetUnlock(BufferView * bv)
314 if (the_locking_inset) {
315 the_locking_inset->InsetUnlock(bv);
316 the_locking_inset = 0;
319 lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this <<
321 no_selection = false;
323 TEXT(bv)->selection = 0;
324 UpdateLocal(bv, FULL, false);
325 bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1);
329 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
331 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
334 if (inset == cpar(bv)->GetInset(cpos(bv))) {
335 lyxerr[Debug::INSETS] << "OK" << endl;
336 the_locking_inset = inset;
337 // resetPos(bv->painter());
338 inset_x = cx(bv) - top_x + drawTextXOffset;
339 inset_y = cy(bv) + drawTextYOffset;
340 inset_pos = cpos(bv);
342 } else if (the_locking_inset && (the_locking_inset == inset)) {
343 if (cpos(bv) == inset_pos) {
344 lyxerr[Debug::INSETS] << "OK" << endl;
345 // resetPos(bv->painter());
346 inset_x = cx(bv) - top_x + drawTextXOffset;
347 inset_y = cy(bv) + drawTextYOffset;
349 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
351 } else if (the_locking_inset) {
352 lyxerr[Debug::INSETS] << "MAYBE" << endl;
353 return the_locking_inset->LockInsetInInset(bv, inset);
355 lyxerr[Debug::INSETS] << "NOT OK" << endl;
360 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
363 if (!the_locking_inset)
365 if (the_locking_inset == inset) {
366 the_locking_inset->InsetUnlock(bv);
367 the_locking_inset = 0;
369 moveRight(bv, false);
372 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
376 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
378 if (!the_locking_inset)
380 if (the_locking_inset != inset)
381 return the_locking_inset->UpdateInsetInInset(bv, inset);
382 lyxerr[Debug::INSETS] << "InsetText::UpdateInsetInInset(" << inset <<
384 UpdateLocal(bv, FULL, false);
385 if (cpos(bv) == inset_pos) {
386 inset_x = cx(bv) - top_x + drawTextXOffset;
387 inset_y = cy(bv) + drawTextYOffset;
393 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
395 if (TEXT(bv)->selection) {
396 TEXT(bv)->selection = 0;
397 UpdateLocal(bv, FULL, false);
399 no_selection = false;
400 // setPos(bv->painter(), x, y);
402 TEXT(bv)->SetCursorFromCoordinates(bv, x, y+TEXT(bv)->first);
403 if (the_locking_inset) {
404 UpdatableInset * inset = 0;
405 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET)
406 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
407 if (the_locking_inset == inset) {
408 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
411 // otherwise unlock the_locking_inset and lock the new inset
412 the_locking_inset->InsetUnlock(bv);
413 inset_x = cx(bv) - top_x + drawTextXOffset;
414 inset_y = cy(bv) + drawTextYOffset;
415 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
416 inset->Edit(bv, x - inset_x, y - inset_y, button);
417 UpdateLocal(bv, FULL, false);
420 // otherwise only unlock the_locking_inset
421 the_locking_inset->InsetUnlock(bv);
422 the_locking_inset = 0;
424 if (bv->the_locking_inset) {
425 if ((cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) &&
426 cpar(bv)->GetInset(cpos(bv)) &&
427 (cpar(bv)->GetInset(cpos(bv))->Editable() == Inset::HIGHLY_EDITABLE)) {
428 UpdatableInset * inset =
429 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
430 inset_x = cx(bv) - top_x + drawTextXOffset;
431 inset_y = cy(bv) + drawTextYOffset;
432 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
433 inset->Edit(bv, x - inset_x, y - inset_y, 0);
434 UpdateLocal(bv, FULL, false);
437 // selection_start_cursor = selection_end_cursor = cursor;
441 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
443 UpdatableInset * inset = 0;
445 if (the_locking_inset) {
446 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
448 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
449 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
450 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
451 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
453 inset_x = cx(bv) - top_x + drawTextXOffset;
454 inset_y = cy(bv) + drawTextYOffset;
455 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
456 inset->Edit(bv, x - inset_x, y - inset_y, button);
460 no_selection = false;
464 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
466 if (the_locking_inset) {
467 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
471 #warning REDO this (Jug)
473 // LyXCursor old = selection_end_cursor;
475 // setPos(bv->painter(), x, y);
476 // selection_end_cursor = cursor;
477 // if (old != selection_end_cursor)
478 // UpdateLocal(bv, false, false);
481 no_selection = false;
485 void InsetText::InsetKeyPress(XKeyEvent * xke)
487 if (the_locking_inset) {
488 the_locking_inset->InsetKeyPress(xke);
494 UpdatableInset::RESULT
495 InsetText::LocalDispatch(BufferView * bv,
496 int action, string const & arg)
498 no_selection = false;
499 UpdatableInset::RESULT
500 result= UpdatableInset::LocalDispatch(bv, action, arg);
501 if (result != UNDISPATCHED) {
502 // resetPos(bv->painter());
507 if ((action < 0) && arg.empty())
510 if (the_locking_inset) {
511 result = the_locking_inset->LocalDispatch(bv, action, arg);
512 if (result == DISPATCHED_NOUPDATE)
514 else if (result == DISPATCHED) {
515 the_locking_inset->ToggleInsetCursor(bv);
516 UpdateLocal(bv, FULL, false);
517 the_locking_inset->ToggleInsetCursor(bv);
519 } else if (result == FINISHED) {
524 // TEXT(bv)->cursor.pos(inset_pos + 1);
525 // resetPos(bv->painter());
531 the_locking_inset = 0;
539 if (bv->buffer()->isReadonly()) {
541 // setErrorMessage(N_("Document is read only"));
545 /* Automatically delete the currently selected
546 * text and replace it with what is being
547 * typed in now. Depends on lyxrc settings
548 * "auto_region_delete", which defaults to
551 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
552 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
553 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
554 if (lyxrc.auto_region_delete) {
555 if (TEXT(bv)->selection){
556 TEXT(bv)->CutSelection(bv, false);
559 TEXT(bv)->ClearSelection();
560 for (string::size_type i = 0; i < arg.length(); ++i) {
561 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
564 UpdateLocal(bv, CURSOR_PAR, true);
566 // --- Cursor Movements ---------------------------------------------
568 bv->text->FinishUndo();
569 moveRight(bv, false);
570 TEXT(bv)->SetSelection();
571 UpdateLocal(bv, SELECTION, false);
574 bv->text->FinishUndo();
575 result = moveRight(bv);
576 TEXT(bv)->selection = 0;
577 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
578 UpdateLocal(bv, CURSOR_PAR, false);
581 bv->text->FinishUndo();
583 TEXT(bv)->SetSelection();
584 UpdateLocal(bv, SELECTION, false);
587 bv->text->FinishUndo();
588 result= moveLeft(bv);
589 TEXT(bv)->selection = 0;
590 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
591 UpdateLocal(bv, CURSOR_PAR, false);
594 bv->text->FinishUndo();
596 TEXT(bv)->SetSelection();
597 UpdateLocal(bv, SELECTION, false);
600 bv->text->FinishUndo();
601 result = moveDown(bv);
602 TEXT(bv)->selection = 0;
603 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
604 UpdateLocal(bv, CURSOR_PAR, false);
607 bv->text->FinishUndo();
609 TEXT(bv)->SetSelection();
610 UpdateLocal(bv, SELECTION, false);
613 bv->text->FinishUndo();
615 TEXT(bv)->selection = 0;
616 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
617 UpdateLocal(bv, CURSOR_PAR, false);
620 bv->text->FinishUndo();
621 TEXT(bv)->CursorHome(bv);
622 TEXT(bv)->selection = 0;
623 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
624 UpdateLocal(bv, CURSOR_PAR, false);
627 TEXT(bv)->CursorEnd(bv);
628 TEXT(bv)->selection = 0;
629 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
630 UpdateLocal(bv, CURSOR_PAR, false);
633 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
634 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
635 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
636 TEXT(bv)->Backspace(bv);
637 UpdateLocal(bv, CURSOR_PAR, true);
640 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
641 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
642 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
643 TEXT(bv)->Delete(bv);
644 UpdateLocal(bv, CURSOR_PAR, true);
647 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
648 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
649 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
650 TEXT(bv)->CutSelection(bv);
651 UpdateLocal(bv, CURSOR_PAR, true);
654 bv->text->FinishUndo();
655 TEXT(bv)->CopySelection(bv);
656 UpdateLocal(bv, CURSOR_PAR, false);
659 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
660 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
661 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
662 TEXT(bv)->PasteSelection(bv);
663 UpdateLocal(bv, CURSOR_PAR, true);
665 case LFUN_BREAKPARAGRAPH:
668 TEXT(bv)->BreakParagraph(bv, 0);
669 UpdateLocal(bv, CURSOR_PAR, true);
674 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
675 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
676 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
677 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
678 UpdateLocal(bv, CURSOR_PAR, true);
682 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
684 // Derive layout number from given argument (string)
685 // and current buffer's textclass (number). */
686 LyXTextClassList::ClassList::size_type tclass =
687 bv->buffer()->params.textclass;
688 std::pair <bool, LyXTextClass::size_type> layout =
689 textclasslist.NumberOfLayout(tclass, arg);
691 // If the entry is obsolete, use the new one instead.
693 string obs = textclasslist.Style(tclass,layout.second).
696 layout = textclasslist.NumberOfLayout(tclass, obs);
699 // see if we found the layout number:
701 string msg = string(N_("Layout ")) + arg + N_(" not known");
703 bv->owner()->getMiniBuffer()->Set(msg);
707 if (cur_layout != layout.second) {
708 cur_layout = layout.second;
709 TEXT(bv)->SetLayout(bv, layout.second);
710 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
711 UpdateLocal(bv, CURSOR_PAR, true);
716 result = UNDISPATCHED;
719 if (result != FINISHED) {
722 bv->unlockInset(this);
727 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
730 buf->latexParagraphs(os, par, 0, texrow);
731 return texrow.rows();
735 void InsetText::Validate(LaTeXFeatures & features) const
737 LyXParagraph * p = par;
739 p->validate(features);
745 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
747 if (textclasslist.Style(buf->params.textclass,
748 p->GetLayout()).labeltype != LABEL_MANUAL)
751 return p->BeginningOfMainBody();
755 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
762 int InsetText::InsetInInsetY()
764 if (!the_locking_inset)
767 return (inset_y + the_locking_inset->InsetInInsetY());
771 void InsetText::ToggleInsetCursor(BufferView * bv)
773 if (the_locking_inset) {
774 the_locking_inset->ToggleInsetCursor(bv);
778 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
780 int asc = lyxfont::maxAscent(font);
781 int desc = lyxfont::maxDescent(font);
784 bv->hideLockedInsetCursor();
786 bv->showLockedInsetCursor(cx(bv), cy(bv),
788 cursor_visible = !cursor_visible;
792 void InsetText::ShowInsetCursor(BufferView * bv)
794 if (the_locking_inset) {
795 the_locking_inset->ShowInsetCursor(bv);
798 if (!cursor_visible) {
799 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
801 int asc = lyxfont::maxAscent(font);
802 int desc = lyxfont::maxDescent(font);
804 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
805 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
806 cursor_visible = true;
811 void InsetText::HideInsetCursor(BufferView * bv)
813 if (cursor_visible) {
814 bv->hideLockedInsetCursor();
815 cursor_visible = false;
817 if (the_locking_inset)
818 the_locking_inset->HideInsetCursor(bv);
822 UpdatableInset::RESULT
823 InsetText::moveRight(BufferView * bv, bool activate_inset)
825 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
827 if (activate_inset && checkAndActivateInset(bv)) {
830 TEXT(bv)->CursorRight(bv);
831 // real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv));
832 return DISPATCHED_NOUPDATE;
836 UpdatableInset::RESULT
837 InsetText::moveLeft(BufferView * bv, bool activate_inset)
839 if (!cpar(bv)->previous && (cpos(bv) <= 0))
841 TEXT(bv)->CursorLeft(bv);
843 if (checkAndActivateInset(bv, -1, -1))
845 return DISPATCHED_NOUPDATE;
849 UpdatableInset::RESULT
850 InsetText::moveUp(BufferView * bv)
852 if (!crow(bv)->previous())
854 TEXT(bv)->CursorUp(bv);
855 return DISPATCHED_NOUPDATE;
859 UpdatableInset::RESULT
860 InsetText::moveDown(BufferView * bv)
862 if (!crow(bv)->next())
864 TEXT(bv)->CursorDown(bv);
865 return DISPATCHED_NOUPDATE;
869 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
871 if (the_locking_inset) {
872 if (the_locking_inset->InsertInsetAllowed(inset))
873 return the_locking_inset->InsertInset(bv, inset);
876 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
877 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
878 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
879 if (inset->Editable() == Inset::IS_EDITABLE) {
880 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
881 i->setOwner(static_cast<UpdatableInset *>(this));
883 cpar(bv)->InsertChar(cpos(bv), LyXParagraph::META_INSET);
884 cpar(bv)->InsertInset(cpos(bv), inset);
885 TEXT(bv)->selection = 0;
886 UpdateLocal(bv, CURSOR_PAR, true);
887 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
892 UpdatableInset * InsetText::GetLockingInset()
894 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
898 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
902 if (the_locking_inset)
903 return the_locking_inset->GetFirstLockingInsetOfType(c);
908 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
910 TEXT(bv)->SetFont(bv, font, toggleall);
914 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
917 bv->updateInset(this, mark_dirty);
918 if (old_par != cpar(bv)) {
919 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
925 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
928 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
929 UpdatableInset * inset =
930 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
931 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
933 x = inset->width(bv->painter(), font);
935 y = inset->descent(bv->painter(), font);
936 inset_x = cx(bv) - top_x + drawTextXOffset;
937 inset_y = cy(bv) + drawTextYOffset;
938 inset->Edit(bv, x - inset_x, y - inset_y, button);
939 if (!the_locking_inset)
941 UpdateLocal(bv, CURSOR_PAR, false);
948 int InsetText::getMaxTextWidth(Painter & pain, UpdatableInset const * inset) const
950 return getMaxWidth(pain, inset) - 4; // 2+2 width of eventual border
953 void InsetText::SetParagraphData(LyXParagraph *p)
967 par->SetInsetOwner(this);
971 np->next = p->Clone();
972 np->next->previous = np;
974 np->SetInsetOwner(this);
979 void InsetText::SetAutoBreakRows(bool flag)
981 if (flag != autoBreakRows) {
982 autoBreakRows = flag;
987 void InsetText::SetDrawLockedFrame(bool flag)
989 if (flag != drawLockedFrame)
990 drawLockedFrame = flag;
993 void InsetText::SetFrameColor(LColor::color col)
995 if (frame_color != col)
999 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
1001 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1004 int InsetText::cx(BufferView * bv) const
1006 return TEXT(bv)->cursor.x() + top_x + 1;
1009 int InsetText::cy(BufferView * bv) const
1011 long int y_dummy = 0;
1012 Row * tmprow = TEXT(bv)->GetRowNearY(y_dummy);
1013 return TEXT(bv)->cursor.y() - tmprow->baseline();
1016 int InsetText::cpos(BufferView * bv) const
1018 return TEXT(bv)->cursor.pos();
1021 LyXParagraph * InsetText::cpar(BufferView * bv) const
1023 return TEXT(bv)->cursor.par();
1026 Row * InsetText::crow(BufferView * bv) const
1028 return TEXT(bv)->cursor.row();
1031 LyXText * InsetText::getLyXText(BufferView * bv) const
1033 if (cache.find(bv) != cache.end())
1035 LyXText *lt = new LyXText(const_cast<InsetText *>(this));
1041 void InsetText::deleteLyXText(BufferView * bv)