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 // Jürgen, we don't like macros, even small ones like this. (Lgb)
60 //#define TEXT(a) getLyXText(a)
61 // I created a inline function in insettext.h instead. (Lgb)
63 InsetText::InsetText()
65 par = new LyXParagraph();
70 InsetText::InsetText(InsetText const & ins)
75 autoBreakRows = ins.autoBreakRows;
79 InsetText & InsetText::operator=(InsetText const & it)
82 autoBreakRows = it.autoBreakRows;
86 void InsetText::init(InsetText const * ins)
88 top_y = last_width = last_height = 0;
89 insetAscent = insetDescent = insetWidth = 0;
90 the_locking_inset = 0;
91 cursor_visible = false;
95 drawTextXOffset = drawTextYOffset = 0;
96 autoBreakRows = drawLockedFrame = false;
99 SetParagraphData(ins->par);
100 autoBreakRows = ins->autoBreakRows;
101 drawLockedFrame = ins->drawLockedFrame;
103 par->SetInsetOwner(this);
104 frame_color = LColor::insetframe;
110 InsetText::~InsetText()
123 Inset * InsetText::Clone() const
125 InsetText * t = new InsetText(*this);
130 void InsetText::Write(Buffer const * buf, ostream & os) const
133 WriteParagraphData(buf, os);
137 void InsetText::WriteParagraphData(Buffer const * buf, ostream & os) const
139 par->writeFile(buf, os, buf->params, 0, 0);
143 void InsetText::Read(Buffer const * buf, LyXLex & lex)
147 LyXParagraph * return_par = 0;
148 char depth = 0; // signed or unsigned?
149 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
150 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
151 LyXFont font(LyXFont::ALL_INHERIT);
153 LyXParagraph * p = par->next;
160 par = new LyXParagraph;
163 token = lex.GetString();
166 if (token == "\\end_inset")
168 if (const_cast<Buffer*>(buf)->parseSingleLyXformat2Token(lex, par, return_par,
172 // the_end read this should NEVER happen
173 lex.printError("\\the_end read in inset! Error in document!");
181 return_par->SetInsetOwner(this);
182 return_par = return_par->next;
185 if (token != "\\end_inset") {
186 lex.printError("Missing \\end_inset at this point. "
193 int InsetText::ascent(Painter &, LyXFont const &) const
199 int InsetText::descent(Painter &, LyXFont const &) const
205 int InsetText::width(Painter &, LyXFont const &) const
211 int InsetText::textWidth(Painter & pain) const
213 return getMaxTextWidth(pain, this) - drawTextXOffset;
217 void InsetText::draw(BufferView * bv, LyXFont const & f,
218 int baseline, float & x, bool cleared) const
220 Painter & pain = bv->painter();
222 if (!cleared && ((need_update==FULL) || (top_x!=int(x)) ||
223 (top_baseline!=baseline))) {
225 // && locked && ((need_update==FULL) || (top_x!=int(x)) ||
226 // (top_baseline!=baseline))) {
229 top_baseline = baseline;
231 bv->updateInset(const_cast<InsetText *>(this), false);
234 pain.rectangle(top_x, baseline - ascent(pain, f),
235 width(pain, f), ascent(pain,f)+descent(pain, f),
239 pain.fillRectangle(top_x+drawTextXOffset, top_y, last_width,
245 if (!cleared && (need_update == NONE))
249 UpdatableInset::draw(bv, f, baseline, x, cleared);
251 top_baseline = baseline;
253 top_y = baseline - ascent(pain, f);
254 last_width = width(pain, f);
255 last_height = ascent(pain, f) + descent(pain, f);
257 if (the_locking_inset && (cpos(bv) == inset_pos)) {
258 inset_x = cx(bv) - top_x + drawTextXOffset;
259 inset_y = cy(bv) + drawTextYOffset;
261 if (need_update == CURSOR) {
266 x += TEXT_TO_INSET_OFFSET; // place for border
268 Row * row = TEXT(bv)->GetRowNearY(y);
269 y += baseline - row->ascent_of_text() + 1;
270 if (cleared || !locked || (need_update == FULL)) {
272 TEXT(bv)->GetVisibleRow(bv, y, x, row, y);
276 } else if (need_update == SELECTION) {
277 bv->screen()->ToggleToggle(getLyXText(bv), y, x);
280 bv->screen()->Update(TEXT(bv), y, x);
283 TEXT(bv)->refresh_y = 0;
284 TEXT(bv)->status = LyXText::UNCHANGED;
285 if (drawLockedFrame && locked) {
286 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
287 ascent(pain,f) + descent(pain, f), frame_color);
289 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
290 ascent(pain,f) + descent(pain, f),
293 x += width(pain, f) - TEXT_TO_INSET_OFFSET;
298 void InsetText::update(BufferView * bv, LyXFont const & font, bool dodraw)
300 if (the_locking_inset)
301 the_locking_inset->update(bv, font, dodraw);
302 if (need_update == INIT) {
306 if (dodraw && (need_update != CURSOR))
309 TEXT(bv)->FullRebreak(bv);
312 Row * row = TEXT(bv)->GetRowNearY(y_temp);
313 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
314 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
315 TEXT_TO_INSET_OFFSET;
316 insetWidth = max(textWidth(bv->painter()),
317 static_cast<int>(TEXT(bv)->width)) +
318 (2 * TEXT_TO_INSET_OFFSET);
322 char const * InsetText::EditMessage() const
324 return _("Opened Text Inset");
328 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
330 // par->SetInsetOwner(this);
331 UpdatableInset::Edit(bv, x, y, button);
333 if (!bv->lockInset(this)) {
334 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
338 the_locking_inset = 0;
339 inset_pos = inset_x = inset_y = 0;
340 #warning Fix cursor setting here!!! (Jug)
341 TEXT(bv)->SetCursor(bv, par, 0);
342 // setPos(bv->painter(), x, y);
343 checkAndActivateInset(bv, x, y, button);
344 // selection_start_cursor = selection_end_cursor = cursor;
345 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
346 bv->text->FinishUndo();
347 UpdateLocal(bv, FULL, false);
351 void InsetText::InsetUnlock(BufferView * bv)
353 if (the_locking_inset) {
354 the_locking_inset->InsetUnlock(bv);
355 the_locking_inset = 0;
358 no_selection = false;
360 TEXT(bv)->selection = 0;
361 UpdateLocal(bv, CURSOR_PAR, false);
362 bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1);
366 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
368 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
371 if (inset == cpar(bv)->GetInset(cpos(bv))) {
372 lyxerr[Debug::INSETS] << "OK" << endl;
373 the_locking_inset = inset;
374 // resetPos(bv->painter());
375 inset_x = cx(bv) - top_x + drawTextXOffset;
376 inset_y = cy(bv) + drawTextYOffset;
377 inset_pos = cpos(bv);
379 } else if (the_locking_inset && (the_locking_inset == inset)) {
380 if (cpos(bv) == inset_pos) {
381 lyxerr[Debug::INSETS] << "OK" << endl;
382 // resetPos(bv->painter());
383 inset_x = cx(bv) - top_x + drawTextXOffset;
384 inset_y = cy(bv) + drawTextYOffset;
386 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
388 } else if (the_locking_inset) {
389 lyxerr[Debug::INSETS] << "MAYBE" << endl;
390 return the_locking_inset->LockInsetInInset(bv, inset);
392 lyxerr[Debug::INSETS] << "NOT OK" << endl;
397 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
400 if (!the_locking_inset)
402 if (the_locking_inset == inset) {
403 the_locking_inset->InsetUnlock(bv);
404 TEXT(bv)->UpdateInset(bv, inset);
405 the_locking_inset = 0;
407 moveRight(bv, false);
408 UpdateLocal(bv, FULL, false);
411 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
415 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
417 if (!the_locking_inset)
419 if (the_locking_inset != inset)
420 return the_locking_inset->UpdateInsetInInset(bv, inset);
421 // UpdateLocal(bv, FULL, false);
422 TEXT(bv)->UpdateInset(bv, inset);
423 if (cpos(bv) == inset_pos) {
424 inset_x = cx(bv) - top_x + drawTextXOffset;
425 inset_y = cy(bv) + drawTextYOffset;
431 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
433 if (TEXT(bv)->selection) {
434 TEXT(bv)->selection = 0;
435 UpdateLocal(bv, FULL, false);
437 no_selection = false;
438 TEXT(bv)->SetCursorFromCoordinates(bv, x, y+TEXT(bv)->first);
439 if (the_locking_inset) {
440 UpdatableInset * inset = 0;
441 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET)
442 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
443 if (the_locking_inset == inset) {
444 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
447 // otherwise unlock the_locking_inset and lock the new inset
448 the_locking_inset->InsetUnlock(bv);
449 inset_x = cx(bv) - top_x + drawTextXOffset;
450 inset_y = cy(bv) + drawTextYOffset;
451 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
452 inset->Edit(bv, x - inset_x, y - inset_y, button);
453 UpdateLocal(bv, FULL, false);
456 // otherwise only unlock the_locking_inset
457 the_locking_inset->InsetUnlock(bv);
458 the_locking_inset = 0;
460 if (bv->the_locking_inset) {
461 if ((cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) &&
462 cpar(bv)->GetInset(cpos(bv)) &&
463 (cpar(bv)->GetInset(cpos(bv))->Editable() == Inset::HIGHLY_EDITABLE)) {
464 UpdatableInset * inset =
465 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
466 inset_x = cx(bv) - top_x + drawTextXOffset;
467 inset_y = cy(bv) + drawTextYOffset;
468 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
469 inset->Edit(bv, x - inset_x, y - inset_y, 0);
470 UpdateLocal(bv, FULL, false);
473 // selection_start_cursor = selection_end_cursor = cursor;
477 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
479 UpdatableInset * inset = 0;
481 if (the_locking_inset) {
482 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
484 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
485 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
486 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
487 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
489 inset_x = cx(bv) - top_x + drawTextXOffset;
490 inset_y = cy(bv) + drawTextYOffset;
491 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
492 inset->Edit(bv, x - inset_x, y - inset_y, button);
496 no_selection = false;
500 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
502 if (the_locking_inset) {
503 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
507 #warning REDO this (Jug)
509 // LyXCursor old = selection_end_cursor;
511 // setPos(bv->painter(), x, y);
512 // selection_end_cursor = cursor;
513 // if (old != selection_end_cursor)
514 // UpdateLocal(bv, false, false);
517 no_selection = false;
521 void InsetText::InsetKeyPress(XKeyEvent * xke)
523 if (the_locking_inset) {
524 the_locking_inset->InsetKeyPress(xke);
530 UpdatableInset::RESULT
531 InsetText::LocalDispatch(BufferView * bv,
532 int action, string const & arg)
534 no_selection = false;
535 UpdatableInset::RESULT
536 result= UpdatableInset::LocalDispatch(bv, action, arg);
537 if (result != UNDISPATCHED) {
538 // resetPos(bv->painter());
543 if ((action < 0) && arg.empty())
546 if (the_locking_inset) {
547 result = the_locking_inset->LocalDispatch(bv, action, arg);
548 if (result == DISPATCHED_NOUPDATE)
550 else if (result == DISPATCHED) {
551 UpdateLocal(bv, CURSOR_PAR, false);
553 } else if (result == FINISHED) {
557 moveRight(bv, false);
563 the_locking_inset = 0;
571 if (bv->buffer()->isReadonly()) {
573 // setErrorMessage(N_("Document is read only"));
577 /* Automatically delete the currently selected
578 * text and replace it with what is being
579 * typed in now. Depends on lyxrc settings
580 * "auto_region_delete", which defaults to
583 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
584 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
585 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
586 if (lyxrc.auto_region_delete) {
587 if (TEXT(bv)->selection){
588 TEXT(bv)->CutSelection(bv, false);
591 TEXT(bv)->ClearSelection();
592 for (string::size_type i = 0; i < arg.length(); ++i) {
593 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
596 UpdateLocal(bv, CURSOR_PAR, true);
598 // --- Cursor Movements ---------------------------------------------
600 bv->text->FinishUndo();
601 moveRight(bv, false);
602 TEXT(bv)->SetSelection();
603 UpdateLocal(bv, SELECTION, false);
606 bv->text->FinishUndo();
607 result = moveRight(bv);
608 TEXT(bv)->selection = 0;
609 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
610 UpdateLocal(bv, CURSOR, false);
613 bv->text->FinishUndo();
615 TEXT(bv)->SetSelection();
616 UpdateLocal(bv, SELECTION, false);
619 bv->text->FinishUndo();
620 result= moveLeft(bv);
621 TEXT(bv)->selection = 0;
622 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
623 UpdateLocal(bv, CURSOR, false);
626 bv->text->FinishUndo();
628 TEXT(bv)->SetSelection();
629 UpdateLocal(bv, SELECTION, false);
632 bv->text->FinishUndo();
633 result = moveDown(bv);
634 TEXT(bv)->selection = 0;
635 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
636 UpdateLocal(bv, CURSOR, false);
639 bv->text->FinishUndo();
641 TEXT(bv)->SetSelection();
642 UpdateLocal(bv, SELECTION, false);
645 bv->text->FinishUndo();
647 TEXT(bv)->selection = 0;
648 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
649 UpdateLocal(bv, CURSOR, false);
652 bv->text->FinishUndo();
653 TEXT(bv)->CursorHome(bv);
654 TEXT(bv)->selection = 0;
655 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
656 UpdateLocal(bv, CURSOR, false);
659 TEXT(bv)->CursorEnd(bv);
660 TEXT(bv)->selection = 0;
661 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
662 UpdateLocal(bv, CURSOR, false);
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)->Backspace(bv);
669 UpdateLocal(bv, CURSOR_PAR, true);
672 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
673 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
674 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
675 TEXT(bv)->Delete(bv);
676 UpdateLocal(bv, CURSOR_PAR, true);
679 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
680 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
681 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
682 TEXT(bv)->CutSelection(bv);
683 UpdateLocal(bv, CURSOR_PAR, true);
686 bv->text->FinishUndo();
687 TEXT(bv)->CopySelection(bv);
688 UpdateLocal(bv, CURSOR_PAR, false);
691 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
692 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
693 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
694 TEXT(bv)->PasteSelection(bv);
695 UpdateLocal(bv, CURSOR_PAR, true);
697 case LFUN_BREAKPARAGRAPH:
700 TEXT(bv)->BreakParagraph(bv, 0);
701 UpdateLocal(bv, CURSOR_PAR, true);
706 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
707 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
708 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
709 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
710 UpdateLocal(bv, CURSOR_PAR, true);
714 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
716 // Derive layout number from given argument (string)
717 // and current buffer's textclass (number). */
718 LyXTextClassList::ClassList::size_type tclass =
719 bv->buffer()->params.textclass;
720 std::pair <bool, LyXTextClass::size_type> layout =
721 textclasslist.NumberOfLayout(tclass, arg);
723 // If the entry is obsolete, use the new one instead.
725 string obs = textclasslist.Style(tclass,layout.second).
728 layout = textclasslist.NumberOfLayout(tclass, obs);
731 // see if we found the layout number:
733 string msg = string(N_("Layout ")) + arg + N_(" not known");
735 bv->owner()->getMiniBuffer()->Set(msg);
739 if (cur_layout != layout.second) {
740 cur_layout = layout.second;
741 TEXT(bv)->SetLayout(bv, layout.second);
742 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
743 UpdateLocal(bv, CURSOR_PAR, true);
747 case LFUN_PARAGRAPH_SPACING:
748 // This one is absolutely not working. When fiddling with this
749 // it also seems to me that the paragraphs inside the insettext
750 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
752 LyXParagraph * par = TEXT(bv)->cursor.par();
753 Spacing::Space cur_spacing = par->spacing.getSpace();
754 float cur_value = 1.0;
755 if (cur_spacing == Spacing::Other) {
756 cur_value = par->spacing.getValue();
760 std::istringstream istr(arg);
762 istrstream istr(arg.c_str());
766 Spacing::Space new_spacing = cur_spacing;
767 float new_value = cur_value;
769 lyxerr << "Missing argument to `paragraph-spacing'"
771 } else if (tmp == "single") {
772 new_spacing = Spacing::Single;
773 } else if (tmp == "onehalf") {
774 new_spacing = Spacing::Onehalf;
775 } else if (tmp == "double") {
776 new_spacing = Spacing::Double;
777 } else if (tmp == "other") {
778 new_spacing = Spacing::Other;
781 lyxerr << "new_value = " << tmpval << endl;
784 } else if (tmp == "default") {
785 new_spacing = Spacing::Default;
787 lyxerr << _("Unknown spacing argument: ")
790 if (cur_spacing != new_spacing || cur_value != new_value) {
791 par->spacing.set(new_spacing, new_value);
792 //TEXT(bv)->RedoParagraph(owner->view());
793 UpdateLocal(bv, CURSOR_PAR, true);
794 //bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
800 result = UNDISPATCHED;
803 if (result != FINISHED) {
806 bv->unlockInset(this);
811 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
814 buf->latexParagraphs(os, par, 0, texrow);
815 return texrow.rows();
819 void InsetText::Validate(LaTeXFeatures & features) const
821 LyXParagraph * p = par;
823 p->validate(features);
829 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
831 if (textclasslist.Style(buf->params.textclass,
832 p->GetLayout()).labeltype != LABEL_MANUAL)
835 return p->BeginningOfMainBody();
839 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
846 int InsetText::InsetInInsetY()
848 if (!the_locking_inset)
851 return (inset_y + the_locking_inset->InsetInInsetY());
855 void InsetText::ToggleInsetCursor(BufferView * bv)
857 if (the_locking_inset) {
858 the_locking_inset->ToggleInsetCursor(bv);
862 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
864 int asc = lyxfont::maxAscent(font);
865 int desc = lyxfont::maxDescent(font);
868 bv->hideLockedInsetCursor();
870 bv->showLockedInsetCursor(cx(bv), cy(bv),
872 cursor_visible = !cursor_visible;
876 void InsetText::ShowInsetCursor(BufferView * bv)
878 if (the_locking_inset) {
879 the_locking_inset->ShowInsetCursor(bv);
882 if (!cursor_visible) {
883 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
885 int asc = lyxfont::maxAscent(font);
886 int desc = lyxfont::maxDescent(font);
888 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
889 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
890 cursor_visible = true;
895 void InsetText::HideInsetCursor(BufferView * bv)
897 if (cursor_visible) {
898 bv->hideLockedInsetCursor();
899 cursor_visible = false;
901 if (the_locking_inset)
902 the_locking_inset->HideInsetCursor(bv);
906 UpdatableInset::RESULT
907 InsetText::moveRight(BufferView * bv, bool activate_inset)
909 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
911 if (activate_inset && checkAndActivateInset(bv)) {
914 TEXT(bv)->CursorRight(bv);
915 // real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv));
916 return DISPATCHED_NOUPDATE;
920 UpdatableInset::RESULT
921 InsetText::moveLeft(BufferView * bv, bool activate_inset)
923 if (!cpar(bv)->previous && (cpos(bv) <= 0))
925 TEXT(bv)->CursorLeft(bv);
927 if (checkAndActivateInset(bv, -1, -1))
929 return DISPATCHED_NOUPDATE;
933 UpdatableInset::RESULT
934 InsetText::moveUp(BufferView * bv)
936 if (!crow(bv)->previous())
938 TEXT(bv)->CursorUp(bv);
939 return DISPATCHED_NOUPDATE;
943 UpdatableInset::RESULT
944 InsetText::moveDown(BufferView * bv)
946 if (!crow(bv)->next())
948 TEXT(bv)->CursorDown(bv);
949 return DISPATCHED_NOUPDATE;
953 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
955 if (the_locking_inset) {
956 if (the_locking_inset->InsertInsetAllowed(inset))
957 return the_locking_inset->InsertInset(bv, inset);
960 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
961 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
962 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
963 if (inset->Editable() == Inset::IS_EDITABLE) {
964 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
965 i->setOwner(static_cast<UpdatableInset *>(this));
968 cpar(bv)->InsertInset(cpos(bv), inset);
970 cpar(bv)->InsertChar(cpos(bv), LyXParagraph::META_INSET);
971 cpar(bv)->InsertInset(cpos(bv), inset);
973 TEXT(bv)->selection = 0;
974 UpdateLocal(bv, CURSOR_PAR, true);
975 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
980 UpdatableInset * InsetText::GetLockingInset()
982 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
986 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
990 if (the_locking_inset)
991 return the_locking_inset->GetFirstLockingInsetOfType(c);
996 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
998 TEXT(bv)->SetFont(bv, font, toggleall);
1002 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
1004 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
1008 if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED))
1009 bv->updateInset(this, mark_dirty);
1010 if (old_par != cpar(bv)) {
1011 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
1017 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1020 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
1021 UpdatableInset * inset =
1022 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
1023 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1025 x = inset->width(bv->painter(), font);
1027 y = inset->descent(bv->painter(), font);
1028 inset_x = cx(bv) - top_x + drawTextXOffset;
1029 inset_y = cy(bv) + drawTextYOffset;
1030 inset->Edit(bv, x - inset_x, y - inset_y, button);
1031 if (!the_locking_inset)
1033 UpdateLocal(bv, CURSOR_PAR, false);
1040 int InsetText::getMaxTextWidth(Painter & pain,
1041 UpdatableInset const * inset) const
1043 return getMaxWidth(pain, inset) - (2 * TEXT_TO_INSET_OFFSET);
1047 void InsetText::SetParagraphData(LyXParagraph *p)
1061 par->SetInsetOwner(this);
1065 np->next = p->Clone();
1066 np->next->previous = np;
1068 np->SetInsetOwner(this);
1074 void InsetText::SetAutoBreakRows(bool flag)
1076 if (flag != autoBreakRows) {
1077 autoBreakRows = flag;
1083 void InsetText::SetDrawLockedFrame(bool flag)
1085 if (flag != drawLockedFrame)
1086 drawLockedFrame = flag;
1090 void InsetText::SetFrameColor(LColor::color col)
1092 if (frame_color != col)
1097 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
1099 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1103 int InsetText::cx(BufferView * bv) const
1105 return TEXT(bv)->cursor.x() + top_x + 1;
1109 int InsetText::cy(BufferView * bv) const
1111 long int y_dummy = 0;
1112 Row * tmprow = TEXT(bv)->GetRowNearY(y_dummy);
1113 return TEXT(bv)->cursor.y() - tmprow->baseline();
1117 int InsetText::cpos(BufferView * bv) const
1119 return TEXT(bv)->cursor.pos();
1123 LyXParagraph * InsetText::cpar(BufferView * bv) const
1125 return TEXT(bv)->cursor.par();
1129 Row * InsetText::crow(BufferView * bv) const
1131 return TEXT(bv)->cursor.row();
1135 LyXText * InsetText::getLyXText(BufferView * bv) const
1137 if (cache.find(bv) != cache.end())
1139 LyXText * lt = new LyXText(const_cast<InsetText *>(this));
1146 void InsetText::deleteLyXText(BufferView * bv)