2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998-2000 The LyX Team.
9 * @author: Jürgen Vigna
11 * ======================================================
22 #pragma implementation
25 #include "insettext.h"
26 #include "lyxparagraph.h"
30 #include "commandtags.h"
33 #include "BufferView.h"
35 #include "LaTeXFeatures.h"
37 #include "lyx_gui_misc.h"
39 #include "lyxcursor.h"
40 #include "CutAndPaste.h"
42 #include "minibuffer.h"
44 #include "support/textutils.h"
45 #include "support/LAssert.h"
49 #include "trans_mgr.h"
50 #include "lyxscreen.h"
58 extern unsigned char getCurrentTextClass(Buffer *);
60 InsetText::InsetText()
62 par = new LyXParagraph();
67 InsetText::InsetText(InsetText const & ins)
72 autoBreakRows = ins.autoBreakRows;
76 InsetText & InsetText::operator=(InsetText const & it)
79 autoBreakRows = it.autoBreakRows;
83 void InsetText::init(InsetText const * ins)
85 top_y = last_width = last_height = 0;
86 insetAscent = insetDescent = insetWidth = 0;
87 the_locking_inset = 0;
88 cursor_visible = false;
92 drawTextXOffset = drawTextYOffset = 0;
93 autoBreakRows = false;
97 SetParagraphData(ins->par);
98 autoBreakRows = ins->autoBreakRows;
99 drawFrame = ins->drawFrame;
101 par->SetInsetOwner(this);
102 frame_color = LColor::insetframe;
108 InsetText::~InsetText()
110 LyXParagraph * p = par->next;
120 void InsetText::clear()
122 LyXParagraph * p = par->next;
129 par = new LyXParagraph();
133 Inset * InsetText::Clone() const
135 InsetText * t = new InsetText(*this);
140 void InsetText::Write(Buffer const * buf, ostream & os) const
143 WriteParagraphData(buf, os);
147 void InsetText::WriteParagraphData(Buffer const * buf, ostream & os) const
149 par->writeFile(buf, os, buf->params, 0, 0);
153 void InsetText::Read(Buffer const * buf, LyXLex & lex)
157 LyXParagraph * return_par = 0;
158 char depth = 0; // signed or unsigned?
160 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
161 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
163 LyXFont font(LyXFont::ALL_INHERIT);
165 LyXParagraph * p = par->next;
172 par = new LyXParagraph;
175 token = lex.GetString();
178 if (token == "\\end_inset")
180 if (const_cast<Buffer*>(buf)->
181 parseSingleLyXformat2Token(lex, par, return_par,token, pos, depth,
184 , footnoteflag, footnotekind
188 // the_end read this should NEVER happen
189 lex.printError("\\the_end read in inset! Error in document!");
197 return_par->SetInsetOwner(this);
198 return_par = return_par->next;
201 if (token != "\\end_inset") {
202 lex.printError("Missing \\end_inset at this point. "
209 int InsetText::ascent(BufferView * bv, LyXFont const &) const
212 Row * row = TEXT(bv)->GetRowNearY(y_temp);
213 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
218 int InsetText::descent(BufferView * bv, LyXFont const &) const
221 Row * row = TEXT(bv)->GetRowNearY(y_temp);
222 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
223 TEXT_TO_INSET_OFFSET;
228 int InsetText::width(BufferView * bv, LyXFont const &) const
230 insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET);
235 int InsetText::textWidth(Painter & pain) const
237 int w = getMaxWidth(pain, this);
242 void InsetText::draw(BufferView * bv, LyXFont const & f,
243 int baseline, float & x, bool cleared) const
245 Painter & pain = bv->painter();
247 // no draw is necessary !!!
248 if ((drawFrame == LOCKED) && !locked && !par->size()) {
249 if (!cleared && (need_update == CLEAR_FRAME)) {
250 pain.rectangle(top_x + 1, baseline - insetAscent + 1,
252 insetAscent + insetDescent - 1,
256 top_baseline = baseline;
263 UpdatableInset::draw(bv, f, baseline, x, cleared);
265 if (!cleared && ((need_update==FULL) || (top_x!=int(x)) ||
266 (top_baseline!=baseline))) {
268 int h = insetAscent + insetDescent;
269 int ty = baseline - insetAscent;
275 if ((ty + h) > pain.paperHeight())
276 h = pain.paperHeight();
277 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
278 w = pain.paperWidth();
279 pain.fillRectangle(top_x+drawTextXOffset, ty, w, h);
283 if (!cleared && (need_update == NONE))
286 if (top_x != int(x)) {
289 bv->text->status = LyXText::CHANGED_IN_DRAW;
293 top_baseline = baseline;
294 top_y = baseline - ascent(bv, f);
295 last_width = width(bv, f);
296 last_height = ascent(bv, f) + descent(bv, f);
298 if (the_locking_inset && (cpar(bv) == inset_par) && (cpos(bv) == inset_pos)) {
299 inset_x = cx(bv) - top_x + drawTextXOffset;
300 inset_y = cy(bv) + drawTextYOffset;
302 if (!cleared && (need_update == CURSOR) && !TEXT(bv)->selection) {
307 x += TEXT_TO_INSET_OFFSET;
309 Row * row = TEXT(bv)->GetRowNearY(y);
310 y += baseline - row->ascent_of_text();
311 if (cleared || !locked || (need_update == FULL)) {
313 TEXT(bv)->GetVisibleRow(bv, y, int(x), row, y, cleared);
317 } else if (need_update == SELECTION) {
318 bv->screen()->ToggleToggle(TEXT(bv), y, int(x));
321 if (need_update == CURSOR) {
322 bv->screen()->ToggleSelection(TEXT(bv), true, y, int(x));
323 TEXT(bv)->ClearSelection();
324 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
326 bv->screen()->Update(TEXT(bv), y, int(x));
329 TEXT(bv)->refresh_y = 0;
330 TEXT(bv)->status = LyXText::UNCHANGED;
331 if ((drawFrame == ALWAYS) || ((drawFrame == LOCKED) && locked)) {
332 pain.rectangle(top_x + 1, baseline - insetAscent + 1,
333 width(bv, f) - 1, insetAscent + insetDescent - 1,
335 } else if (need_update == CLEAR_FRAME) {
336 pain.rectangle(top_x + 1, baseline - insetAscent + 1,
337 width(bv, f) - 1, insetAscent + insetDescent - 1,
340 x += width(bv, f) - TEXT_TO_INSET_OFFSET;
341 if (bv->text->status==LyXText::CHANGED_IN_DRAW)
343 else if (need_update != INIT)
348 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
350 if (reinit) { // && (need_update != CURSOR)) {
354 owner()->update(bv, font, true);
357 if (the_locking_inset) {
358 inset_x = cx(bv) - top_x + drawTextXOffset;
359 inset_y = cy(bv) + drawTextYOffset;
360 the_locking_inset->update(bv, font, reinit);
362 if (need_update == INIT) {
365 // if (!owner() && bv->text)
366 // bv->text->UpdateInset(bv, this);
368 int oldw = insetWidth;
370 insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET);
371 // max(textWidth(bv->painter()),
372 // static_cast<int>(TEXT(bv)->width) + drawTextXOffset) +
373 // (2 * TEXT_TO_INSET_OFFSET);
375 insetWidth = textWidth(bv->painter());
377 insetWidth = static_cast<int>(TEXT(bv)->width);
379 if (oldw != insetWidth) {
380 // printf("TW(%p): %d-%d-%d-%d\n",this,insetWidth, oldw,
381 // textWidth(bv->painter()),static_cast<int>(TEXT(bv)->width));
386 owner()->update(bv, font, reinit);
389 update(bv, font, reinit);
393 update(bv, font, reinit);
395 UpdateLocal(bv, INIT, false);
400 if ((need_update==CURSOR_PAR) && (TEXT(bv)->status==LyXText::UNCHANGED) &&
403 TEXT(bv)->UpdateInset(bv, the_locking_inset);
406 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
410 Row * row = TEXT(bv)->GetRowNearY(y_temp);
411 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
412 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
413 TEXT_TO_INSET_OFFSET;
417 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
419 TEXT(bv)->FullRebreak(bv);
420 if (need_update != INIT) {
421 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
423 else if (!the_locking_inset || (what != CURSOR))
426 if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED) ||
428 bv->updateInset(this, mark_dirty);
429 bv->owner()->showState();
430 if (old_par != cpar(bv)) {
431 bv->owner()->setLayout(cpar(bv)->GetLayout());
437 char const * InsetText::EditMessage() const
439 return _("Opened Text Inset");
443 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
445 // par->SetInsetOwner(this);
446 UpdatableInset::Edit(bv, x, y, button);
448 if (!bv->lockInset(this)) {
449 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
453 the_locking_inset = 0;
454 inset_pos = inset_x = inset_y = 0;
457 if (!checkAndActivateInset(bv, x, y, button))
458 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
459 y+TEXT(bv)->first+insetAscent);
460 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
461 bv->text->FinishUndo();
462 UpdateLocal(bv, FULL, false);
466 void InsetText::InsetUnlock(BufferView * bv)
468 if (the_locking_inset) {
469 the_locking_inset->InsetUnlock(bv);
470 the_locking_inset = 0;
473 no_selection = false;
475 TEXT(bv)->selection = 0;
476 UpdateLocal(bv, CLEAR_FRAME, false);
478 bv->owner()->setLayout(owner()->getLyXText(bv)
479 ->cursor.par()->GetLayout());
481 bv->owner()->setLayout(bv->text->cursor.par()->GetLayout());
485 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
487 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
490 if (inset == cpar(bv)->GetInset(cpos(bv))) {
491 lyxerr[Debug::INSETS] << "OK" << endl;
492 the_locking_inset = inset;
493 inset_x = cx(bv) - top_x + drawTextXOffset;
494 inset_y = cy(bv) + drawTextYOffset;
495 inset_pos = cpos(bv);
496 inset_par = cpar(bv);
497 TEXT(bv)->UpdateInset(bv, the_locking_inset);
499 } else if (the_locking_inset && (the_locking_inset == inset)) {
500 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
501 lyxerr[Debug::INSETS] << "OK" << endl;
502 inset_x = cx(bv) - top_x + drawTextXOffset;
503 inset_y = cy(bv) + drawTextYOffset;
505 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
507 } else if (the_locking_inset) {
508 lyxerr[Debug::INSETS] << "MAYBE" << endl;
509 return the_locking_inset->LockInsetInInset(bv, inset);
511 lyxerr[Debug::INSETS] << "NOT OK" << endl;
516 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
519 if (!the_locking_inset)
521 if (the_locking_inset == inset) {
522 the_locking_inset->InsetUnlock(bv);
523 TEXT(bv)->UpdateInset(bv, inset);
524 the_locking_inset = 0;
526 moveRight(bv, false);
527 old_par = 0; // force layout setting
528 UpdateLocal(bv, CURSOR_PAR, false);
531 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
535 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
537 if (!the_locking_inset)
539 if (the_locking_inset != inset) {
540 TEXT(bv)->UpdateInset(bv, the_locking_inset);
541 need_update = CURSOR_PAR;
542 return the_locking_inset->UpdateInsetInInset(bv, inset);
544 // UpdateLocal(bv, FULL, false);
545 if (TEXT(bv)->UpdateInset(bv, inset))
546 UpdateLocal(bv, CURSOR_PAR, false);
547 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
548 inset_x = cx(bv) - top_x + drawTextXOffset;
549 inset_y = cy(bv) + drawTextYOffset;
555 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
557 no_selection = false;
559 int tmp_x = x - drawTextXOffset;
560 int tmp_y = y + insetAscent;
561 Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button);
564 if (the_locking_inset) {
565 if (the_locking_inset == inset) {
566 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
569 // otherwise unlock the_locking_inset and lock the new inset
570 the_locking_inset->InsetUnlock(bv);
571 inset_x = cx(bv) - top_x + drawTextXOffset;
572 inset_y = cy(bv) + drawTextYOffset;
573 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
574 inset->Edit(bv, x - inset_x, y - inset_y, button);
575 if (the_locking_inset) {
576 UpdateLocal(bv, CURSOR_PAR, false);
580 // otherwise only unlock the_locking_inset
581 the_locking_inset->InsetUnlock(bv);
582 the_locking_inset = 0;
584 if (bv->the_locking_inset) {
585 if (inset && inset->Editable() == Inset::HIGHLY_EDITABLE) {
586 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
587 inset_x = cx(bv) - top_x + drawTextXOffset;
588 inset_y = cy(bv) + drawTextYOffset;
589 inset_pos = cpos(bv);
590 inset_par = cpar(bv);
591 uinset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
592 uinset->Edit(bv, x - inset_x, y - inset_y, 0);
593 if (the_locking_inset) {
594 UpdateLocal(bv, CURSOR_PAR, false);
600 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
601 y+TEXT(bv)->first+insetAscent);
602 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
603 UpdateLocal(bv, CURSOR, false);
604 bv->owner()->setLayout(cpar(bv)->GetLayout());
611 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
613 UpdatableInset * inset = 0;
615 if (the_locking_inset) {
616 the_locking_inset->InsetButtonRelease(bv,
617 x - inset_x, y - inset_y,
620 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
621 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
622 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
623 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
625 inset_x = cx(bv) - top_x + drawTextXOffset;
626 inset_y = cy(bv) + drawTextYOffset;
627 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
628 inset->Edit(bv, x - inset_x, y - inset_y, button);
630 UpdateLocal(bv, CURSOR_PAR, false);
633 no_selection = false;
637 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
639 if (the_locking_inset) {
640 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
646 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
647 y+TEXT(bv)->first+insetAscent);
648 TEXT(bv)->SetSelection();
649 if (TEXT(bv)->toggle_cursor.par()!=TEXT(bv)->toggle_end_cursor.par() ||
650 TEXT(bv)->toggle_cursor.pos()!=TEXT(bv)->toggle_end_cursor.pos())
651 UpdateLocal(bv, SELECTION, false);
654 no_selection = false;
658 void InsetText::InsetKeyPress(XKeyEvent * xke)
660 if (the_locking_inset) {
661 the_locking_inset->InsetKeyPress(xke);
667 UpdatableInset::RESULT
668 InsetText::LocalDispatch(BufferView * bv,
669 int action, string const & arg)
671 no_selection = false;
672 UpdatableInset::RESULT
673 result= UpdatableInset::LocalDispatch(bv, action, arg);
674 if (result != UNDISPATCHED) {
679 if ((action < 0) && arg.empty())
682 if (the_locking_inset) {
683 result = the_locking_inset->LocalDispatch(bv, action, arg);
684 if (result == DISPATCHED_NOUPDATE)
686 else if (result == DISPATCHED) {
687 UpdateLocal(bv, CURSOR_PAR, false);
689 } else if (result == FINISHED) {
693 moveRight(bv, false);
699 the_locking_inset = 0;
707 if (bv->buffer()->isReadonly()) {
709 // setErrorMessage(N_("Document is read only"));
713 /* Automatically delete the currently selected
714 * text and replace it with what is being
715 * typed in now. Depends on lyxrc settings
716 * "auto_region_delete", which defaults to
719 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
721 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
722 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
724 bv->text->cursor.par()->previous,
725 bv->text->cursor.par()->next
728 if (lyxrc.auto_region_delete) {
729 if (TEXT(bv)->selection){
730 TEXT(bv)->CutSelection(bv, false);
733 TEXT(bv)->ClearSelection();
734 for (string::size_type i = 0; i < arg.length(); ++i) {
735 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
738 UpdateLocal(bv, CURSOR_PAR, true);
740 // --- Cursor Movements ---------------------------------------------
742 bv->text->FinishUndo();
743 moveRight(bv, false);
744 TEXT(bv)->SetSelection();
745 UpdateLocal(bv, SELECTION, false);
748 result = moveRight(bv);
749 bv->text->FinishUndo();
750 UpdateLocal(bv, CURSOR, false);
753 bv->text->FinishUndo();
755 TEXT(bv)->SetSelection();
756 UpdateLocal(bv, SELECTION, false);
759 bv->text->FinishUndo();
760 result= moveLeft(bv);
761 UpdateLocal(bv, CURSOR, false);
764 bv->text->FinishUndo();
766 TEXT(bv)->SetSelection();
767 UpdateLocal(bv, SELECTION, false);
770 bv->text->FinishUndo();
771 result = moveDown(bv);
772 UpdateLocal(bv, CURSOR, false);
775 bv->text->FinishUndo();
777 TEXT(bv)->SetSelection();
778 UpdateLocal(bv, SELECTION, false);
781 bv->text->FinishUndo();
783 UpdateLocal(bv, CURSOR, false);
786 bv->text->FinishUndo();
787 TEXT(bv)->CursorHome(bv);
788 UpdateLocal(bv, CURSOR, false);
791 TEXT(bv)->CursorEnd(bv);
792 UpdateLocal(bv, CURSOR, false);
795 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
797 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
798 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
800 bv->text->cursor.par()->previous,
801 bv->text->cursor.par()->next
804 TEXT(bv)->Backspace(bv);
805 UpdateLocal(bv, CURSOR_PAR, true);
808 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
810 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
811 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
813 bv->text->cursor.par()->previous,
814 bv->text->cursor.par()->next
817 TEXT(bv)->Delete(bv);
818 UpdateLocal(bv, CURSOR_PAR, true);
821 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
823 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
824 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
826 bv->text->cursor.par()->previous,
827 bv->text->cursor.par()->next
830 TEXT(bv)->CutSelection(bv);
831 UpdateLocal(bv, CURSOR_PAR, true);
834 bv->text->FinishUndo();
835 TEXT(bv)->CopySelection(bv);
836 UpdateLocal(bv, CURSOR_PAR, false);
839 if (!autoBreakRows) {
842 if (cap.nrOfParagraphs() > 1) {
843 WriteAlert(_("Impossible operation"),
844 _("Cannot include more than one paragraph!"),
849 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
851 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
852 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
854 bv->text->cursor.par()->previous,
855 bv->text->cursor.par()->next
858 TEXT(bv)->PasteSelection(bv);
859 UpdateLocal(bv, CURSOR_PAR, true);
861 case LFUN_BREAKPARAGRAPH:
864 TEXT(bv)->BreakParagraph(bv, 0);
865 UpdateLocal(bv, FULL, true);
870 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
872 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
873 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
875 bv->text->cursor.par()->previous,
876 bv->text->cursor.par()->next
879 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
880 UpdateLocal(bv, CURSOR_PAR, true);
884 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
886 // Derive layout number from given argument (string)
887 // and current buffer's textclass (number). */
888 LyXTextClassList::ClassList::size_type tclass =
889 bv->buffer()->params.textclass;
890 std::pair <bool, LyXTextClass::size_type> layout =
891 textclasslist.NumberOfLayout(tclass, arg);
893 // If the entry is obsolete, use the new one instead.
895 string obs = textclasslist.Style(tclass,layout.second).
898 layout = textclasslist.NumberOfLayout(tclass, obs);
901 // see if we found the layout number:
903 string msg = string(N_("Layout ")) + arg + N_(" not known");
905 bv->owner()->getMiniBuffer()->Set(msg);
909 if (cur_layout != layout.second) {
910 cur_layout = layout.second;
911 TEXT(bv)->SetLayout(bv, layout.second);
912 bv->owner()->setLayout(cpar(bv)->GetLayout());
913 UpdateLocal(bv, CURSOR_PAR, true);
917 case LFUN_PARAGRAPH_SPACING:
918 // This one is absolutely not working. When fiddling with this
919 // it also seems to me that the paragraphs inside the insettext
920 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
922 LyXParagraph * par = TEXT(bv)->cursor.par();
923 Spacing::Space cur_spacing = par->spacing.getSpace();
924 float cur_value = 1.0;
925 if (cur_spacing == Spacing::Other) {
926 cur_value = par->spacing.getValue();
930 std::istringstream istr(arg.c_str());
932 istrstream istr(arg.c_str());
936 Spacing::Space new_spacing = cur_spacing;
937 float new_value = cur_value;
939 lyxerr << "Missing argument to `paragraph-spacing'"
941 } else if (tmp == "single") {
942 new_spacing = Spacing::Single;
943 } else if (tmp == "onehalf") {
944 new_spacing = Spacing::Onehalf;
945 } else if (tmp == "double") {
946 new_spacing = Spacing::Double;
947 } else if (tmp == "other") {
948 new_spacing = Spacing::Other;
951 lyxerr << "new_value = " << tmpval << endl;
954 } else if (tmp == "default") {
955 new_spacing = Spacing::Default;
957 lyxerr << _("Unknown spacing argument: ")
960 if (cur_spacing != new_spacing || cur_value != new_value) {
961 par->spacing.set(new_spacing, new_value);
962 //TEXT(bv)->RedoParagraph(owner->view());
963 UpdateLocal(bv, CURSOR_PAR, true);
964 //bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
970 result = UNDISPATCHED;
973 if (result != FINISHED) {
976 bv->unlockInset(this);
981 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
984 buf->latexParagraphs(os, par, 0, texrow);
985 return texrow.rows();
989 void InsetText::Validate(LaTeXFeatures & features) const
991 LyXParagraph * p = par;
993 p->validate(features);
999 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
1001 if (textclasslist.Style(buf->params.textclass,
1002 p->GetLayout()).labeltype != LABEL_MANUAL)
1005 return p->BeginningOfMainBody();
1009 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
1016 int InsetText::InsetInInsetY()
1018 if (!the_locking_inset)
1021 return (inset_y + the_locking_inset->InsetInInsetY());
1025 void InsetText::ToggleInsetCursor(BufferView * bv)
1027 if (the_locking_inset) {
1028 the_locking_inset->ToggleInsetCursor(bv);
1032 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1034 int asc = lyxfont::maxAscent(font);
1035 int desc = lyxfont::maxDescent(font);
1038 bv->hideLockedInsetCursor();
1040 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1041 cursor_visible = !cursor_visible;
1045 void InsetText::ShowInsetCursor(BufferView * bv)
1047 if (the_locking_inset) {
1048 the_locking_inset->ShowInsetCursor(bv);
1051 if (!cursor_visible) {
1052 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1054 int asc = lyxfont::maxAscent(font);
1055 int desc = lyxfont::maxDescent(font);
1057 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1058 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1059 cursor_visible = true;
1064 void InsetText::HideInsetCursor(BufferView * bv)
1066 if (cursor_visible) {
1067 bv->hideLockedInsetCursor();
1068 cursor_visible = false;
1070 if (the_locking_inset)
1071 the_locking_inset->HideInsetCursor(bv);
1075 UpdatableInset::RESULT
1076 InsetText::moveRight(BufferView * bv, bool activate_inset)
1078 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
1080 if (activate_inset && checkAndActivateInset(bv, false))
1082 TEXT(bv)->CursorRight(bv);
1083 return DISPATCHED_NOUPDATE;
1087 UpdatableInset::RESULT
1088 InsetText::moveLeft(BufferView * bv, bool activate_inset)
1090 if (!cpar(bv)->previous && (cpos(bv) <= 0))
1092 TEXT(bv)->CursorLeft(bv);
1093 if (activate_inset && checkAndActivateInset(bv, true))
1095 return DISPATCHED_NOUPDATE;
1099 UpdatableInset::RESULT
1100 InsetText::moveUp(BufferView * bv)
1102 if (!crow(bv)->previous())
1104 TEXT(bv)->CursorUp(bv);
1105 return DISPATCHED_NOUPDATE;
1109 UpdatableInset::RESULT
1110 InsetText::moveDown(BufferView * bv)
1112 if (!crow(bv)->next())
1114 TEXT(bv)->CursorDown(bv);
1115 return DISPATCHED_NOUPDATE;
1119 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
1121 if (the_locking_inset) {
1122 if (the_locking_inset->InsertInsetAllowed(inset))
1123 return the_locking_inset->InsertInset(bv, inset);
1126 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
1128 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1129 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1131 bv->text->cursor.par()->previous,
1132 bv->text->cursor.par()->next
1135 if (inset->Editable() == Inset::IS_EDITABLE) {
1136 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
1137 i->setOwner(static_cast<UpdatableInset *>(this));
1139 TEXT(bv)->InsertInset(bv, inset);
1140 TEXT(bv)->selection = 0;
1141 UpdateLocal(bv, CURSOR_PAR, true);
1142 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
1147 UpdatableInset * InsetText::GetLockingInset()
1149 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
1153 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
1157 if (the_locking_inset)
1158 return the_locking_inset->GetFirstLockingInsetOfType(c);
1163 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
1165 TEXT(bv)->SetFont(bv, font, toggleall);
1169 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1171 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
1174 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
1175 if (!inset || inset->Editable() != Inset::HIGHLY_EDITABLE)
1177 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1179 x = inset->width(bv, font);
1180 y = inset->descent(bv, font);
1184 inset_x = cx(bv) - top_x + drawTextXOffset;
1185 inset_y = cy(bv) + drawTextYOffset;
1186 inset->Edit(bv, x-inset_x, y-inset_y, 0);
1187 if (!the_locking_inset)
1189 UpdateLocal(bv, CURSOR_PAR, false);
1196 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1199 int tmp_x = x - drawTextXOffset;
1200 int tmp_y = y + insetAscent;
1201 Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button);
1208 inset_x = cx(bv) - top_x + drawTextXOffset;
1209 inset_y = cy(bv) + drawTextYOffset;
1210 inset->Edit(bv, x - inset_x, y - inset_y, button);
1211 if (!the_locking_inset)
1213 UpdateLocal(bv, CURSOR_PAR, false);
1220 int InsetText::getMaxWidth(Painter & pain, UpdatableInset const * inset) const
1222 int w = UpdatableInset::getMaxWidth(pain, inset);
1227 w = w - top_x + owner()->x();
1230 w -= (2 * TEXT_TO_INSET_OFFSET);
1232 // return w - (2*TEXT_TO_INSET_OFFSET);
1236 void InsetText::SetParagraphData(LyXParagraph *p)
1250 par->SetInsetOwner(this);
1254 np->next = p->Clone();
1255 np->next->previous = np;
1257 np->SetInsetOwner(this);
1263 void InsetText::SetAutoBreakRows(bool flag)
1265 if (flag != autoBreakRows) {
1266 autoBreakRows = flag;
1274 void InsetText::SetDrawFrame(BufferView * bv, DrawFrame how)
1276 if (how != drawFrame) {
1279 UpdateLocal(bv, DRAW_FRAME, false);
1284 void InsetText::SetFrameColor(BufferView * bv, LColor::color col)
1286 if (frame_color != col) {
1289 UpdateLocal(bv, DRAW_FRAME, false);
1294 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
1296 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1300 int InsetText::cx(BufferView * bv) const
1302 return TEXT(bv)->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
1306 int InsetText::cy(BufferView * bv) const
1309 return TEXT(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
1313 int InsetText::cpos(BufferView * bv) const
1315 return TEXT(bv)->cursor.pos();
1319 LyXParagraph * InsetText::cpar(BufferView * bv) const
1321 return TEXT(bv)->cursor.par();
1325 Row * InsetText::crow(BufferView * bv) const
1327 return TEXT(bv)->cursor.row();
1331 LyXText * InsetText::getLyXText(BufferView * bv) const
1333 if (cache.find(bv) != cache.end())
1335 LyXText * lt = new LyXText(const_cast<InsetText *>(this));
1338 if (the_locking_inset) {
1339 lt->SetCursor(bv, inset_par, inset_pos);
1345 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1349 /// then remove all LyXText in text-insets
1350 LyXParagraph * p = par;
1351 for(;p;p = p->next) {
1352 p->deleteInsetsLyXText(bv);
1357 void InsetText::resizeLyXText(BufferView * bv) const
1359 if (!par->next && !par->size()) // resize not neccessary!
1361 if (cache.find(bv) == cache.end())
1364 LyXParagraph * lpar = 0;
1365 LyXParagraph * selstartpar = 0;
1366 LyXParagraph * selendpar = 0;
1368 int selstartpos = 0;
1373 // ProhibitInput(bv);
1375 lpar = TEXT(bv)->cursor.par();
1376 pos = TEXT(bv)->cursor.pos();
1377 selstartpar = TEXT(bv)->sel_start_cursor.par();
1378 selstartpos = TEXT(bv)->sel_start_cursor.pos();
1379 selendpar = TEXT(bv)->sel_end_cursor.par();
1380 selendpos = TEXT(bv)->sel_end_cursor.pos();
1381 selection = TEXT(bv)->selection;
1382 mark_set = TEXT(bv)->mark_set;
1383 deleteLyXText(bv, (the_locking_inset == 0));
1386 TEXT(bv)->selection = true;
1387 /* at this point just to avoid the Delete-Empty-Paragraph
1388 * Mechanism when setting the cursor */
1389 TEXT(bv)->mark_set = mark_set;
1391 TEXT(bv)->SetCursor(bv, selstartpar, selstartpos);
1392 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
1393 TEXT(bv)->SetCursor(bv, selendpar, selendpos);
1394 TEXT(bv)->SetSelection();
1395 TEXT(bv)->SetCursor(bv, lpar, pos);
1397 TEXT(bv)->SetCursor(bv, lpar, pos);
1398 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
1399 TEXT(bv)->selection = false;
1403 TEXT(bv)->first = bv->screen()->TopCursorVisible(TEXT(bv));
1404 // this will scroll the screen such that the cursor becomes visible
1405 bv->updateScrollbar();
1407 if (the_locking_inset) {
1408 /// then resize all LyXText in text-insets
1409 inset_x = cx(bv) - top_x + drawTextXOffset;
1410 inset_y = cy(bv) + drawTextYOffset;
1411 LyXParagraph * p = par;
1412 for(;p;p = p->next) {
1413 p->resizeInsetsLyXText(bv);
1420 void InsetText::removeNewlines()
1422 LyXParagraph * p = par;
1424 for(;p; p = p->next) {
1425 for(int i = 0; i < p->Last(); ++i) {
1426 if (p->GetChar(i) == LyXParagraph::META_NEWLINE)