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 int h = insetAscent + insetDescent;
226 int ty = baseline - insetAscent;
230 if ((ty + h) > pain.paperHeight())
231 h = pain.paperHeight();
232 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
233 w = pain.paperWidth();
234 pain.fillRectangle(top_x+drawTextXOffset, ty, w, h);
239 if (!cleared && (need_update == NONE))
243 UpdatableInset::draw(bv, f, baseline, x, cleared);
245 top_baseline = baseline;
247 top_y = baseline - ascent(pain, f);
248 last_width = width(pain, f);
249 last_height = ascent(pain, f) + descent(pain, f);
251 if (the_locking_inset && (cpos(bv) == inset_pos)) {
252 inset_x = cx(bv) - top_x + drawTextXOffset;
253 inset_y = cy(bv) + drawTextYOffset;
255 if (!cleared && (need_update == CURSOR)) {
260 x += TEXT_TO_INSET_OFFSET; // place for border
262 Row * row = TEXT(bv)->GetRowNearY(y);
263 y += baseline - row->ascent_of_text() + 1;
264 if (cleared || !locked || (need_update == FULL)) {
266 TEXT(bv)->GetVisibleRow(bv, y, x, row, y);
270 } else if (need_update == SELECTION) {
271 bv->screen()->ToggleToggle(getLyXText(bv), y, x);
274 bv->screen()->Update(TEXT(bv), y, x);
277 TEXT(bv)->refresh_y = 0;
278 TEXT(bv)->status = LyXText::UNCHANGED;
279 if (drawLockedFrame && locked) {
280 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
281 ascent(pain,f) + descent(pain, f), frame_color);
283 pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
284 ascent(pain,f) + descent(pain, f),
287 x += width(pain, f) - TEXT_TO_INSET_OFFSET;
292 void InsetText::update(BufferView * bv, LyXFont const & font, bool dodraw)
294 if (the_locking_inset)
295 the_locking_inset->update(bv, font, dodraw);
296 if (need_update == INIT) {
300 if (dodraw && (need_update != CURSOR))
303 TEXT(bv)->FullRebreak(bv);
306 Row * row = TEXT(bv)->GetRowNearY(y_temp);
307 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
308 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
309 TEXT_TO_INSET_OFFSET;
310 insetWidth = max(textWidth(bv->painter()),
311 static_cast<int>(TEXT(bv)->width)) +
312 (2 * TEXT_TO_INSET_OFFSET);
316 char const * InsetText::EditMessage() const
318 return _("Opened Text Inset");
322 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
324 // par->SetInsetOwner(this);
325 UpdatableInset::Edit(bv, x, y, button);
327 if (!bv->lockInset(this)) {
328 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
332 the_locking_inset = 0;
333 inset_pos = inset_x = inset_y = 0;
334 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
335 y+TEXT(bv)->first-drawTextYOffset+
337 checkAndActivateInset(bv, x, y, button);
338 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
339 bv->text->FinishUndo();
340 UpdateLocal(bv, FULL, false);
344 void InsetText::InsetUnlock(BufferView * bv)
346 if (the_locking_inset) {
347 the_locking_inset->InsetUnlock(bv);
348 the_locking_inset = 0;
351 no_selection = false;
353 TEXT(bv)->selection = 0;
354 UpdateLocal(bv, CURSOR_PAR, false);
355 bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1);
359 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
361 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
364 if (inset == cpar(bv)->GetInset(cpos(bv))) {
365 lyxerr[Debug::INSETS] << "OK" << endl;
366 the_locking_inset = inset;
367 // resetPos(bv->painter());
368 inset_x = cx(bv) - top_x + drawTextXOffset;
369 inset_y = cy(bv) + drawTextYOffset;
370 inset_pos = cpos(bv);
372 } else if (the_locking_inset && (the_locking_inset == inset)) {
373 if (cpos(bv) == inset_pos) {
374 lyxerr[Debug::INSETS] << "OK" << endl;
375 // resetPos(bv->painter());
376 inset_x = cx(bv) - top_x + drawTextXOffset;
377 inset_y = cy(bv) + drawTextYOffset;
379 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
381 } else if (the_locking_inset) {
382 lyxerr[Debug::INSETS] << "MAYBE" << endl;
383 return the_locking_inset->LockInsetInInset(bv, inset);
385 lyxerr[Debug::INSETS] << "NOT OK" << endl;
390 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
393 if (!the_locking_inset)
395 if (the_locking_inset == inset) {
396 the_locking_inset->InsetUnlock(bv);
397 TEXT(bv)->UpdateInset(bv, inset);
398 the_locking_inset = 0;
400 moveRight(bv, false);
401 UpdateLocal(bv, FULL, false);
404 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
408 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
410 if (!the_locking_inset)
412 if (the_locking_inset != inset)
413 return the_locking_inset->UpdateInsetInInset(bv, inset);
414 // UpdateLocal(bv, FULL, false);
415 TEXT(bv)->UpdateInset(bv, inset);
416 if (cpos(bv) == inset_pos) {
417 inset_x = cx(bv) - top_x + drawTextXOffset;
418 inset_y = cy(bv) + drawTextYOffset;
424 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
426 if (TEXT(bv)->selection) {
427 TEXT(bv)->selection = 0;
428 UpdateLocal(bv, FULL, false);
430 no_selection = false;
431 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
432 y+TEXT(bv)->first-drawTextYOffset+
434 if (the_locking_inset) {
435 UpdatableInset * inset = 0;
436 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET)
437 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
438 if (the_locking_inset == inset) {
439 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
442 // otherwise unlock the_locking_inset and lock the new inset
443 the_locking_inset->InsetUnlock(bv);
444 inset_x = cx(bv) - top_x + drawTextXOffset;
445 inset_y = cy(bv) + drawTextYOffset;
446 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
447 inset->Edit(bv, x - inset_x, y - inset_y, button);
448 UpdateLocal(bv, FULL, false);
451 // otherwise only unlock the_locking_inset
452 the_locking_inset->InsetUnlock(bv);
453 the_locking_inset = 0;
455 if (bv->the_locking_inset) {
456 if ((cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) &&
457 cpar(bv)->GetInset(cpos(bv)) &&
458 (cpar(bv)->GetInset(cpos(bv))->Editable() == Inset::HIGHLY_EDITABLE)) {
459 UpdatableInset * inset =
460 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
461 inset_x = cx(bv) - top_x + drawTextXOffset;
462 inset_y = cy(bv) + drawTextYOffset;
463 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
464 inset->Edit(bv, x - inset_x, y - inset_y, 0);
465 UpdateLocal(bv, FULL, false);
468 // selection_start_cursor = selection_end_cursor = cursor;
472 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
474 UpdatableInset * inset = 0;
476 if (the_locking_inset) {
477 the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
479 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
480 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
481 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
482 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
484 inset_x = cx(bv) - top_x + drawTextXOffset;
485 inset_y = cy(bv) + drawTextYOffset;
486 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
487 inset->Edit(bv, x - inset_x, y - inset_y, button);
491 no_selection = false;
495 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
497 if (the_locking_inset) {
498 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
502 #warning REDO this (Jug)
504 // LyXCursor old = selection_end_cursor;
506 // setPos(bv->painter(), x, y);
507 // selection_end_cursor = cursor;
508 // if (old != selection_end_cursor)
509 // UpdateLocal(bv, false, false);
512 no_selection = false;
516 void InsetText::InsetKeyPress(XKeyEvent * xke)
518 if (the_locking_inset) {
519 the_locking_inset->InsetKeyPress(xke);
525 UpdatableInset::RESULT
526 InsetText::LocalDispatch(BufferView * bv,
527 int action, string const & arg)
529 no_selection = false;
530 UpdatableInset::RESULT
531 result= UpdatableInset::LocalDispatch(bv, action, arg);
532 if (result != UNDISPATCHED) {
533 // resetPos(bv->painter());
538 if ((action < 0) && arg.empty())
541 if (the_locking_inset) {
542 result = the_locking_inset->LocalDispatch(bv, action, arg);
543 if (result == DISPATCHED_NOUPDATE)
545 else if (result == DISPATCHED) {
546 UpdateLocal(bv, CURSOR_PAR, false);
548 } else if (result == FINISHED) {
552 moveRight(bv, false);
558 the_locking_inset = 0;
566 if (bv->buffer()->isReadonly()) {
568 // setErrorMessage(N_("Document is read only"));
572 /* Automatically delete the currently selected
573 * text and replace it with what is being
574 * typed in now. Depends on lyxrc settings
575 * "auto_region_delete", which defaults to
578 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
579 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
580 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
581 if (lyxrc.auto_region_delete) {
582 if (TEXT(bv)->selection){
583 TEXT(bv)->CutSelection(bv, false);
586 TEXT(bv)->ClearSelection();
587 for (string::size_type i = 0; i < arg.length(); ++i) {
588 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
591 UpdateLocal(bv, CURSOR_PAR, true);
593 // --- Cursor Movements ---------------------------------------------
595 bv->text->FinishUndo();
596 moveRight(bv, false);
597 TEXT(bv)->SetSelection();
598 UpdateLocal(bv, SELECTION, false);
601 bv->text->FinishUndo();
602 result = moveRight(bv);
603 TEXT(bv)->selection = 0;
604 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
605 UpdateLocal(bv, CURSOR, false);
608 bv->text->FinishUndo();
610 TEXT(bv)->SetSelection();
611 UpdateLocal(bv, SELECTION, false);
614 bv->text->FinishUndo();
615 result= moveLeft(bv);
616 TEXT(bv)->selection = 0;
617 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
618 UpdateLocal(bv, CURSOR, false);
621 bv->text->FinishUndo();
623 TEXT(bv)->SetSelection();
624 UpdateLocal(bv, SELECTION, false);
627 bv->text->FinishUndo();
628 result = moveDown(bv);
629 TEXT(bv)->selection = 0;
630 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
631 UpdateLocal(bv, CURSOR, false);
634 bv->text->FinishUndo();
636 TEXT(bv)->SetSelection();
637 UpdateLocal(bv, SELECTION, false);
640 bv->text->FinishUndo();
642 TEXT(bv)->selection = 0;
643 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
644 UpdateLocal(bv, CURSOR, false);
647 bv->text->FinishUndo();
648 TEXT(bv)->CursorHome(bv);
649 TEXT(bv)->selection = 0;
650 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
651 UpdateLocal(bv, CURSOR, false);
654 TEXT(bv)->CursorEnd(bv);
655 TEXT(bv)->selection = 0;
656 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
657 UpdateLocal(bv, CURSOR, false);
660 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
661 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
662 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
663 TEXT(bv)->Backspace(bv);
664 UpdateLocal(bv, CURSOR_PAR, true);
667 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
668 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
669 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
670 TEXT(bv)->Delete(bv);
671 UpdateLocal(bv, CURSOR_PAR, true);
674 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
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)->CutSelection(bv);
678 UpdateLocal(bv, CURSOR_PAR, true);
681 bv->text->FinishUndo();
682 TEXT(bv)->CopySelection(bv);
683 UpdateLocal(bv, CURSOR_PAR, false);
686 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
687 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
688 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
689 TEXT(bv)->PasteSelection(bv);
690 UpdateLocal(bv, CURSOR_PAR, true);
692 case LFUN_BREAKPARAGRAPH:
695 TEXT(bv)->BreakParagraph(bv, 0);
696 UpdateLocal(bv, FULL, true);
701 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
702 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
703 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
704 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
705 UpdateLocal(bv, CURSOR_PAR, true);
709 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
711 // Derive layout number from given argument (string)
712 // and current buffer's textclass (number). */
713 LyXTextClassList::ClassList::size_type tclass =
714 bv->buffer()->params.textclass;
715 std::pair <bool, LyXTextClass::size_type> layout =
716 textclasslist.NumberOfLayout(tclass, arg);
718 // If the entry is obsolete, use the new one instead.
720 string obs = textclasslist.Style(tclass,layout.second).
723 layout = textclasslist.NumberOfLayout(tclass, obs);
726 // see if we found the layout number:
728 string msg = string(N_("Layout ")) + arg + N_(" not known");
730 bv->owner()->getMiniBuffer()->Set(msg);
734 if (cur_layout != layout.second) {
735 cur_layout = layout.second;
736 TEXT(bv)->SetLayout(bv, layout.second);
737 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
738 UpdateLocal(bv, CURSOR_PAR, true);
742 case LFUN_PARAGRAPH_SPACING:
743 // This one is absolutely not working. When fiddling with this
744 // it also seems to me that the paragraphs inside the insettext
745 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
747 LyXParagraph * par = TEXT(bv)->cursor.par();
748 Spacing::Space cur_spacing = par->spacing.getSpace();
749 float cur_value = 1.0;
750 if (cur_spacing == Spacing::Other) {
751 cur_value = par->spacing.getValue();
755 std::istringstream istr(arg);
757 istrstream istr(arg.c_str());
761 Spacing::Space new_spacing = cur_spacing;
762 float new_value = cur_value;
764 lyxerr << "Missing argument to `paragraph-spacing'"
766 } else if (tmp == "single") {
767 new_spacing = Spacing::Single;
768 } else if (tmp == "onehalf") {
769 new_spacing = Spacing::Onehalf;
770 } else if (tmp == "double") {
771 new_spacing = Spacing::Double;
772 } else if (tmp == "other") {
773 new_spacing = Spacing::Other;
776 lyxerr << "new_value = " << tmpval << endl;
779 } else if (tmp == "default") {
780 new_spacing = Spacing::Default;
782 lyxerr << _("Unknown spacing argument: ")
785 if (cur_spacing != new_spacing || cur_value != new_value) {
786 par->spacing.set(new_spacing, new_value);
787 //TEXT(bv)->RedoParagraph(owner->view());
788 UpdateLocal(bv, CURSOR_PAR, true);
789 //bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
795 result = UNDISPATCHED;
798 if (result != FINISHED) {
801 bv->unlockInset(this);
806 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
809 buf->latexParagraphs(os, par, 0, texrow);
810 return texrow.rows();
814 void InsetText::Validate(LaTeXFeatures & features) const
816 LyXParagraph * p = par;
818 p->validate(features);
824 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
826 if (textclasslist.Style(buf->params.textclass,
827 p->GetLayout()).labeltype != LABEL_MANUAL)
830 return p->BeginningOfMainBody();
834 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
841 int InsetText::InsetInInsetY()
843 if (!the_locking_inset)
846 return (inset_y + the_locking_inset->InsetInInsetY());
850 void InsetText::ToggleInsetCursor(BufferView * bv)
852 if (the_locking_inset) {
853 the_locking_inset->ToggleInsetCursor(bv);
857 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
859 int asc = lyxfont::maxAscent(font);
860 int desc = lyxfont::maxDescent(font);
863 bv->hideLockedInsetCursor();
865 bv->showLockedInsetCursor(cx(bv), cy(bv),
867 cursor_visible = !cursor_visible;
871 void InsetText::ShowInsetCursor(BufferView * bv)
873 if (the_locking_inset) {
874 the_locking_inset->ShowInsetCursor(bv);
877 if (!cursor_visible) {
878 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
880 int asc = lyxfont::maxAscent(font);
881 int desc = lyxfont::maxDescent(font);
883 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
884 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
885 cursor_visible = true;
890 void InsetText::HideInsetCursor(BufferView * bv)
892 if (cursor_visible) {
893 bv->hideLockedInsetCursor();
894 cursor_visible = false;
896 if (the_locking_inset)
897 the_locking_inset->HideInsetCursor(bv);
901 UpdatableInset::RESULT
902 InsetText::moveRight(BufferView * bv, bool activate_inset)
904 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
906 if (activate_inset && checkAndActivateInset(bv)) {
909 TEXT(bv)->CursorRight(bv);
910 // real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv));
911 return DISPATCHED_NOUPDATE;
915 UpdatableInset::RESULT
916 InsetText::moveLeft(BufferView * bv, bool activate_inset)
918 if (!cpar(bv)->previous && (cpos(bv) <= 0))
920 TEXT(bv)->CursorLeft(bv);
922 if (checkAndActivateInset(bv, -1, -1))
924 return DISPATCHED_NOUPDATE;
928 UpdatableInset::RESULT
929 InsetText::moveUp(BufferView * bv)
931 if (!crow(bv)->previous())
933 TEXT(bv)->CursorUp(bv);
934 return DISPATCHED_NOUPDATE;
938 UpdatableInset::RESULT
939 InsetText::moveDown(BufferView * bv)
941 if (!crow(bv)->next())
943 TEXT(bv)->CursorDown(bv);
944 return DISPATCHED_NOUPDATE;
948 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
950 if (the_locking_inset) {
951 if (the_locking_inset->InsertInsetAllowed(inset))
952 return the_locking_inset->InsertInset(bv, inset);
955 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
956 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
957 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
958 if (inset->Editable() == Inset::IS_EDITABLE) {
959 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
960 i->setOwner(static_cast<UpdatableInset *>(this));
962 cpar(bv)->InsertInset(cpos(bv), inset);
963 TEXT(bv)->selection = 0;
964 UpdateLocal(bv, CURSOR_PAR, true);
965 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
970 UpdatableInset * InsetText::GetLockingInset()
972 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
976 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
980 if (the_locking_inset)
981 return the_locking_inset->GetFirstLockingInsetOfType(c);
986 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
988 TEXT(bv)->SetFont(bv, font, toggleall);
992 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
994 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
998 if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED))
999 bv->updateInset(this, mark_dirty);
1000 if (old_par != cpar(bv)) {
1001 bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
1007 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1010 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
1011 UpdatableInset * inset =
1012 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
1013 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1015 x = inset->width(bv->painter(), font);
1017 y = inset->descent(bv->painter(), font);
1018 inset_x = cx(bv) - top_x + drawTextXOffset;
1019 inset_y = cy(bv) + drawTextYOffset;
1020 inset->Edit(bv, x - inset_x, y - inset_y, button);
1021 if (!the_locking_inset)
1023 UpdateLocal(bv, CURSOR_PAR, false);
1030 int InsetText::getMaxTextWidth(Painter & pain,
1031 UpdatableInset const * inset) const
1033 return getMaxWidth(pain, inset) - (2 * TEXT_TO_INSET_OFFSET);
1037 void InsetText::SetParagraphData(LyXParagraph *p)
1051 par->SetInsetOwner(this);
1055 np->next = p->Clone();
1056 np->next->previous = np;
1058 np->SetInsetOwner(this);
1064 void InsetText::SetAutoBreakRows(bool flag)
1066 if (flag != autoBreakRows) {
1067 autoBreakRows = flag;
1073 void InsetText::SetDrawLockedFrame(bool flag)
1075 if (flag != drawLockedFrame)
1076 drawLockedFrame = flag;
1080 void InsetText::SetFrameColor(LColor::color col)
1082 if (frame_color != col)
1087 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
1089 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1093 int InsetText::cx(BufferView * bv) const
1095 return TEXT(bv)->cursor.x() + top_x + 1;
1099 int InsetText::cy(BufferView * bv) const
1101 long int y_dummy = 0;
1102 Row * tmprow = TEXT(bv)->GetRowNearY(y_dummy);
1103 return TEXT(bv)->cursor.y() - tmprow->baseline();
1107 int InsetText::cpos(BufferView * bv) const
1109 return TEXT(bv)->cursor.pos();
1113 LyXParagraph * InsetText::cpar(BufferView * bv) const
1115 return TEXT(bv)->cursor.par();
1119 Row * InsetText::crow(BufferView * bv) const
1121 return TEXT(bv)->cursor.row();
1125 LyXText * InsetText::getLyXText(BufferView * bv) const
1127 if (cache.find(bv) != cache.end())
1129 LyXText * lt = new LyXText(const_cast<InsetText *>(this));
1136 void InsetText::deleteLyXText(BufferView * bv)