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 top_y = last_width = last_height = 0;
87 insetAscent = insetDescent = insetWidth = 0;
88 the_locking_inset = 0;
89 cursor_visible = false;
93 drawTextXOffset = drawTextYOffset = 0;
94 autoBreakRows = drawLockedFrame = false;
97 SetParagraphData(ins->par);
98 autoBreakRows = ins->autoBreakRows;
99 drawLockedFrame = ins->drawLockedFrame;
101 par->SetInsetOwner(this);
102 frame_color = LColor::insetframe;
108 InsetText::~InsetText()
121 Inset * InsetText::Clone() const
123 InsetText * t = new InsetText(*this);
128 void InsetText::Write(Buffer const * buf, ostream & os) const
131 WriteParagraphData(buf, os);
135 void InsetText::WriteParagraphData(Buffer const * buf, ostream & os) const
137 par->writeFile(buf, os, buf->params, 0, 0);
141 void InsetText::Read(Buffer const * buf, LyXLex & lex)
143 string token, tmptok;
145 LyXParagraph * return_par = 0;
146 char depth = 0; // signed or unsigned?
147 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
148 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
149 LyXFont font(LyXFont::ALL_INHERIT);
159 par = new LyXParagraph;
162 token = lex.GetString();
165 if (token == "\\end_inset")
167 if (const_cast<Buffer*>(buf)->parseSingleLyXformat2Token(lex, par, return_par,
171 // the_end read this should NEVER happen
172 lex.printError("\\the_end read in inset! Error in document!");
180 return_par->SetInsetOwner(this);
181 return_par = return_par->next;
184 if (token != "\\end_inset") {
185 lex.printError("Missing \\end_inset at this point. "
192 int InsetText::ascent(Painter &, LyXFont const &) const
198 int InsetText::descent(Painter &, LyXFont const &) const
204 int InsetText::width(Painter &, LyXFont const &) const
209 int InsetText::textWidth(Painter & pain) const
211 return getMaxTextWidth(pain, this) - drawTextXOffset;
215 void InsetText::draw(BufferView * bv, LyXFont const & f,
216 int baseline, float & x, bool cleared) const
218 Painter & pain = bv->painter();
220 if (!cleared && ((need_update==FULL) || (top_x!=int(x)) ||
221 (top_baseline!=baseline))) {
223 // && locked && ((need_update==FULL) || (top_x!=int(x)) ||
224 // (top_baseline!=baseline))) {
227 top_baseline = baseline;
229 bv->updateInset(const_cast<InsetText *>(this), false);
232 pain.rectangle(top_x, baseline - ascent(pain, f),
233 width(pain, f), ascent(pain,f)+descent(pain, f),
237 pain.fillRectangle(top_x+drawTextXOffset, top_y, last_width,
243 if (!cleared && (need_update == NONE))
247 UpdatableInset::draw(bv, f, baseline, x, cleared);
249 top_baseline = baseline;
251 top_y = baseline - ascent(pain, f);
252 last_width = width(pain, f);
253 last_height = ascent(pain, f) + descent(pain, f);
255 if (the_locking_inset && (cpos(bv) == inset_pos)) {
256 inset_x = cx(bv) - top_x + drawTextXOffset;
257 inset_y = cy(bv) + drawTextYOffset;
259 if (need_update == CURSOR) {
264 x += TEXT_TO_INSET_OFFSET; // place for border
266 Row * row = TEXT(bv)->GetRowNearY(y);
267 y += baseline - row->ascent_of_text() + 1;
268 if (cleared || !locked || (need_update == FULL)) {
270 TEXT(bv)->GetVisibleRow(bv, y, x, row, y);
274 } else if (need_update == SELECTION) {
275 bv->screen()->ToggleToggle(getLyXText(bv), y, x);
278 bv->screen()->Update(TEXT(bv), y, x);
281 TEXT(bv)->refresh_y = 0;
282 TEXT(bv)->status = LyXText::UNCHANGED;
283 if (drawLockedFrame && locked) {
284 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
285 ascent(pain,f) + descent(pain, f), frame_color);
287 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
288 ascent(pain,f) + descent(pain, f),
291 x += width(pain, f) - TEXT_TO_INSET_OFFSET;
296 void InsetText::update(BufferView * bv, LyXFont const & font, bool dodraw)
298 if (the_locking_inset)
299 the_locking_inset->update(bv, font, dodraw);
300 if (need_update == INIT) {
304 if (dodraw && (need_update != CURSOR))
307 TEXT(bv)->FullRebreak(bv);
310 Row * row = TEXT(bv)->GetRowNearY(y_temp);
311 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
312 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
313 TEXT_TO_INSET_OFFSET;
314 insetWidth = max(textWidth(bv->painter()),
315 static_cast<int>(TEXT(bv)->width)) +
316 (2 * TEXT_TO_INSET_OFFSET);
320 char const * InsetText::EditMessage() const
322 return _("Opened Text Inset");
326 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
328 // par->SetInsetOwner(this);
329 UpdatableInset::Edit(bv, x, y, button);
331 if (!bv->lockInset(this)) {
332 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
336 the_locking_inset = 0;
337 inset_pos = inset_x = inset_y = 0;
338 #warning Fix cursor setting here!!! (Jug)
339 TEXT(bv)->SetCursor(bv, par, 0);
340 // setPos(bv->painter(), x, y);
341 checkAndActivateInset(bv, x, y, button);
342 // selection_start_cursor = selection_end_cursor = cursor;
343 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
344 bv->text->FinishUndo();
345 UpdateLocal(bv, FULL, false);
349 void InsetText::InsetUnlock(BufferView * bv)
351 if (the_locking_inset) {
352 the_locking_inset->InsetUnlock(bv);
353 the_locking_inset = 0;
356 no_selection = false;
358 TEXT(bv)->selection = 0;
359 UpdateLocal(bv, CURSOR_PAR, false);
360 bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1);
364 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
366 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
369 if (inset == cpar(bv)->GetInset(cpos(bv))) {
370 lyxerr[Debug::INSETS] << "OK" << endl;
371 the_locking_inset = inset;
372 // resetPos(bv->painter());
373 inset_x = cx(bv) - top_x + drawTextXOffset;
374 inset_y = cy(bv) + drawTextYOffset;
375 inset_pos = cpos(bv);
377 } else if (the_locking_inset && (the_locking_inset == inset)) {
378 if (cpos(bv) == inset_pos) {
379 lyxerr[Debug::INSETS] << "OK" << endl;
380 // resetPos(bv->painter());
381 inset_x = cx(bv) - top_x + drawTextXOffset;
382 inset_y = cy(bv) + drawTextYOffset;
384 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
386 } else if (the_locking_inset) {
387 lyxerr[Debug::INSETS] << "MAYBE" << endl;
388 return the_locking_inset->LockInsetInInset(bv, inset);
390 lyxerr[Debug::INSETS] << "NOT OK" << endl;
395 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
398 if (!the_locking_inset)
400 if (the_locking_inset == inset) {
401 the_locking_inset->InsetUnlock(bv);
402 TEXT(bv)->UpdateInset(bv, inset);
403 the_locking_inset = 0;
405 moveRight(bv, false);
406 UpdateLocal(bv, FULL, false);
409 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
413 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
415 if (!the_locking_inset)
417 if (the_locking_inset != inset)
418 return the_locking_inset->UpdateInsetInInset(bv, inset);
419 // UpdateLocal(bv, FULL, false);
420 TEXT(bv)->UpdateInset(bv, inset);
421 if (cpos(bv) == inset_pos) {
422 inset_x = cx(bv) - top_x + drawTextXOffset;
423 inset_y = cy(bv) + drawTextYOffset;
429 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
431 if (TEXT(bv)->selection) {
432 TEXT(bv)->selection = 0;
433 UpdateLocal(bv, FULL, false);
435 no_selection = false;
436 TEXT(bv)->SetCursorFromCoordinates(bv, x, y+TEXT(bv)->first);
437 if (the_locking_inset) {
438 UpdatableInset * inset = 0;
439 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET)
440 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
441 if (the_locking_inset == inset) {
442 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
445 // otherwise unlock the_locking_inset and lock the new inset
446 the_locking_inset->InsetUnlock(bv);
447 inset_x = cx(bv) - top_x + drawTextXOffset;
448 inset_y = cy(bv) + drawTextYOffset;
449 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
450 inset->Edit(bv, x - inset_x, y - inset_y, button);
451 UpdateLocal(bv, FULL, false);
454 // otherwise only unlock the_locking_inset
455 the_locking_inset->InsetUnlock(bv);
456 the_locking_inset = 0;
458 if (bv->the_locking_inset) {
459 if ((cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) &&
460 cpar(bv)->GetInset(cpos(bv)) &&
461 (cpar(bv)->GetInset(cpos(bv))->Editable() == Inset::HIGHLY_EDITABLE)) {
462 UpdatableInset * inset =
463 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
464 inset_x = cx(bv) - top_x + drawTextXOffset;
465 inset_y = cy(bv) + drawTextYOffset;
466 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
467 inset->Edit(bv, x - inset_x, y - inset_y, 0);
468 UpdateLocal(bv, FULL, false);
471 // selection_start_cursor = selection_end_cursor = cursor;
475 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
477 UpdatableInset * inset = 0;
479 if (the_locking_inset) {
480 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
482 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
483 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
484 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
485 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
487 inset_x = cx(bv) - top_x + drawTextXOffset;
488 inset_y = cy(bv) + drawTextYOffset;
489 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
490 inset->Edit(bv, x - inset_x, y - inset_y, button);
494 no_selection = false;
498 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
500 if (the_locking_inset) {
501 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
505 #warning REDO this (Jug)
507 // LyXCursor old = selection_end_cursor;
509 // setPos(bv->painter(), x, y);
510 // selection_end_cursor = cursor;
511 // if (old != selection_end_cursor)
512 // UpdateLocal(bv, false, false);
515 no_selection = false;
519 void InsetText::InsetKeyPress(XKeyEvent * xke)
521 if (the_locking_inset) {
522 the_locking_inset->InsetKeyPress(xke);
528 UpdatableInset::RESULT
529 InsetText::LocalDispatch(BufferView * bv,
530 int action, string const & arg)
532 no_selection = false;
533 UpdatableInset::RESULT
534 result= UpdatableInset::LocalDispatch(bv, action, arg);
535 if (result != UNDISPATCHED) {
536 // resetPos(bv->painter());
541 if ((action < 0) && arg.empty())
544 if (the_locking_inset) {
545 result = the_locking_inset->LocalDispatch(bv, action, arg);
546 if (result == DISPATCHED_NOUPDATE)
548 else if (result == DISPATCHED) {
549 UpdateLocal(bv, CURSOR_PAR, false);
551 } else if (result == FINISHED) {
555 moveRight(bv, false);
561 the_locking_inset = 0;
569 if (bv->buffer()->isReadonly()) {
571 // setErrorMessage(N_("Document is read only"));
575 /* Automatically delete the currently selected
576 * text and replace it with what is being
577 * typed in now. Depends on lyxrc settings
578 * "auto_region_delete", which defaults to
581 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
582 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
583 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
584 if (lyxrc.auto_region_delete) {
585 if (TEXT(bv)->selection){
586 TEXT(bv)->CutSelection(bv, false);
589 TEXT(bv)->ClearSelection();
590 for (string::size_type i = 0; i < arg.length(); ++i) {
591 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
594 UpdateLocal(bv, CURSOR_PAR, true);
596 // --- Cursor Movements ---------------------------------------------
598 bv->text->FinishUndo();
599 moveRight(bv, false);
600 TEXT(bv)->SetSelection();
601 UpdateLocal(bv, SELECTION, false);
604 bv->text->FinishUndo();
605 result = moveRight(bv);
606 TEXT(bv)->selection = 0;
607 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
608 UpdateLocal(bv, CURSOR, false);
611 bv->text->FinishUndo();
613 TEXT(bv)->SetSelection();
614 UpdateLocal(bv, SELECTION, false);
617 bv->text->FinishUndo();
618 result= moveLeft(bv);
619 TEXT(bv)->selection = 0;
620 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
621 UpdateLocal(bv, CURSOR, false);
624 bv->text->FinishUndo();
626 TEXT(bv)->SetSelection();
627 UpdateLocal(bv, SELECTION, false);
630 bv->text->FinishUndo();
631 result = moveDown(bv);
632 TEXT(bv)->selection = 0;
633 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
634 UpdateLocal(bv, CURSOR, false);
637 bv->text->FinishUndo();
639 TEXT(bv)->SetSelection();
640 UpdateLocal(bv, SELECTION, false);
643 bv->text->FinishUndo();
645 TEXT(bv)->selection = 0;
646 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
647 UpdateLocal(bv, CURSOR, false);
650 bv->text->FinishUndo();
651 TEXT(bv)->CursorHome(bv);
652 TEXT(bv)->selection = 0;
653 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
654 UpdateLocal(bv, CURSOR, false);
657 TEXT(bv)->CursorEnd(bv);
658 TEXT(bv)->selection = 0;
659 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
660 UpdateLocal(bv, CURSOR, false);
663 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
664 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
665 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
666 TEXT(bv)->Backspace(bv);
667 UpdateLocal(bv, CURSOR_PAR, true);
670 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
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)->Delete(bv);
674 UpdateLocal(bv, CURSOR_PAR, true);
677 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
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)->CutSelection(bv);
681 UpdateLocal(bv, CURSOR_PAR, true);
684 bv->text->FinishUndo();
685 TEXT(bv)->CopySelection(bv);
686 UpdateLocal(bv, CURSOR_PAR, false);
689 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
690 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
691 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
692 TEXT(bv)->PasteSelection(bv);
693 UpdateLocal(bv, CURSOR_PAR, true);
695 case LFUN_BREAKPARAGRAPH:
698 TEXT(bv)->BreakParagraph(bv, 0);
699 UpdateLocal(bv, CURSOR_PAR, true);
704 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
705 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
706 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
707 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
708 UpdateLocal(bv, CURSOR_PAR, true);
712 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
714 // Derive layout number from given argument (string)
715 // and current buffer's textclass (number). */
716 LyXTextClassList::ClassList::size_type tclass =
717 bv->buffer()->params.textclass;
718 std::pair <bool, LyXTextClass::size_type> layout =
719 textclasslist.NumberOfLayout(tclass, arg);
721 // If the entry is obsolete, use the new one instead.
723 string obs = textclasslist.Style(tclass,layout.second).
726 layout = textclasslist.NumberOfLayout(tclass, obs);
729 // see if we found the layout number:
731 string msg = string(N_("Layout ")) + arg + N_(" not known");
733 bv->owner()->getMiniBuffer()->Set(msg);
737 if (cur_layout != layout.second) {
738 cur_layout = layout.second;
739 TEXT(bv)->SetLayout(bv, layout.second);
740 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
741 UpdateLocal(bv, CURSOR_PAR, true);
746 result = UNDISPATCHED;
749 if (result != FINISHED) {
752 bv->unlockInset(this);
757 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
760 buf->latexParagraphs(os, par, 0, texrow);
761 return texrow.rows();
765 void InsetText::Validate(LaTeXFeatures & features) const
767 LyXParagraph * p = par;
769 p->validate(features);
775 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
777 if (textclasslist.Style(buf->params.textclass,
778 p->GetLayout()).labeltype != LABEL_MANUAL)
781 return p->BeginningOfMainBody();
785 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
792 int InsetText::InsetInInsetY()
794 if (!the_locking_inset)
797 return (inset_y + the_locking_inset->InsetInInsetY());
801 void InsetText::ToggleInsetCursor(BufferView * bv)
803 if (the_locking_inset) {
804 the_locking_inset->ToggleInsetCursor(bv);
808 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
810 int asc = lyxfont::maxAscent(font);
811 int desc = lyxfont::maxDescent(font);
814 bv->hideLockedInsetCursor();
816 bv->showLockedInsetCursor(cx(bv), cy(bv),
818 cursor_visible = !cursor_visible;
822 void InsetText::ShowInsetCursor(BufferView * bv)
824 if (the_locking_inset) {
825 the_locking_inset->ShowInsetCursor(bv);
828 if (!cursor_visible) {
829 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
831 int asc = lyxfont::maxAscent(font);
832 int desc = lyxfont::maxDescent(font);
834 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
835 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
836 cursor_visible = true;
841 void InsetText::HideInsetCursor(BufferView * bv)
843 if (cursor_visible) {
844 bv->hideLockedInsetCursor();
845 cursor_visible = false;
847 if (the_locking_inset)
848 the_locking_inset->HideInsetCursor(bv);
852 UpdatableInset::RESULT
853 InsetText::moveRight(BufferView * bv, bool activate_inset)
855 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
857 if (activate_inset && checkAndActivateInset(bv)) {
860 TEXT(bv)->CursorRight(bv);
861 // real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv));
862 return DISPATCHED_NOUPDATE;
866 UpdatableInset::RESULT
867 InsetText::moveLeft(BufferView * bv, bool activate_inset)
869 if (!cpar(bv)->previous && (cpos(bv) <= 0))
871 TEXT(bv)->CursorLeft(bv);
873 if (checkAndActivateInset(bv, -1, -1))
875 return DISPATCHED_NOUPDATE;
879 UpdatableInset::RESULT
880 InsetText::moveUp(BufferView * bv)
882 if (!crow(bv)->previous())
884 TEXT(bv)->CursorUp(bv);
885 return DISPATCHED_NOUPDATE;
889 UpdatableInset::RESULT
890 InsetText::moveDown(BufferView * bv)
892 if (!crow(bv)->next())
894 TEXT(bv)->CursorDown(bv);
895 return DISPATCHED_NOUPDATE;
899 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
901 if (the_locking_inset) {
902 if (the_locking_inset->InsertInsetAllowed(inset))
903 return the_locking_inset->InsertInset(bv, inset);
906 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
907 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
908 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
909 if (inset->Editable() == Inset::IS_EDITABLE) {
910 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
911 i->setOwner(static_cast<UpdatableInset *>(this));
913 cpar(bv)->InsertChar(cpos(bv), LyXParagraph::META_INSET);
914 cpar(bv)->InsertInset(cpos(bv), inset);
915 TEXT(bv)->selection = 0;
916 UpdateLocal(bv, CURSOR_PAR, true);
917 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
922 UpdatableInset * InsetText::GetLockingInset()
924 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
928 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
932 if (the_locking_inset)
933 return the_locking_inset->GetFirstLockingInsetOfType(c);
938 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
940 TEXT(bv)->SetFont(bv, font, toggleall);
944 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
946 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
950 if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED))
951 bv->updateInset(this, mark_dirty);
952 if (old_par != cpar(bv)) {
953 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
959 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
962 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
963 UpdatableInset * inset =
964 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
965 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
967 x = inset->width(bv->painter(), font);
969 y = inset->descent(bv->painter(), font);
970 inset_x = cx(bv) - top_x + drawTextXOffset;
971 inset_y = cy(bv) + drawTextYOffset;
972 inset->Edit(bv, x - inset_x, y - inset_y, button);
973 if (!the_locking_inset)
975 UpdateLocal(bv, CURSOR_PAR, false);
982 int InsetText::getMaxTextWidth(Painter & pain, UpdatableInset const * inset) const
984 return getMaxWidth(pain, inset) - (2 * TEXT_TO_INSET_OFFSET);
987 void InsetText::SetParagraphData(LyXParagraph *p)
1001 par->SetInsetOwner(this);
1005 np->next = p->Clone();
1006 np->next->previous = np;
1008 np->SetInsetOwner(this);
1013 void InsetText::SetAutoBreakRows(bool flag)
1015 if (flag != autoBreakRows) {
1016 autoBreakRows = flag;
1021 void InsetText::SetDrawLockedFrame(bool flag)
1023 if (flag != drawLockedFrame)
1024 drawLockedFrame = flag;
1027 void InsetText::SetFrameColor(LColor::color col)
1029 if (frame_color != col)
1033 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
1035 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1038 int InsetText::cx(BufferView * bv) const
1040 return TEXT(bv)->cursor.x() + top_x + 1;
1043 int InsetText::cy(BufferView * bv) const
1045 long int y_dummy = 0;
1046 Row * tmprow = TEXT(bv)->GetRowNearY(y_dummy);
1047 return TEXT(bv)->cursor.y() - tmprow->baseline();
1050 int InsetText::cpos(BufferView * bv) const
1052 return TEXT(bv)->cursor.pos();
1055 LyXParagraph * InsetText::cpar(BufferView * bv) const
1057 return TEXT(bv)->cursor.par();
1060 Row * InsetText::crow(BufferView * bv) const
1062 return TEXT(bv)->cursor.row();
1065 LyXText * InsetText::getLyXText(BufferView * bv) const
1067 if (cache.find(bv) != cache.end())
1069 LyXText *lt = new LyXText(const_cast<InsetText *>(this));
1075 void InsetText::deleteLyXText(BufferView * bv)