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"
42 #include "support/textutils.h"
43 #include "support/LAssert.h"
47 #include "trans_mgr.h"
48 #include "lyxscreen.h"
56 extern unsigned char getCurrentTextClass(Buffer *);
58 InsetText::InsetText()
60 par = new LyXParagraph();
65 InsetText::InsetText(InsetText const & ins)
70 autoBreakRows = ins.autoBreakRows;
74 InsetText & InsetText::operator=(InsetText const & it)
77 autoBreakRows = it.autoBreakRows;
81 void InsetText::init(InsetText const * ins)
83 top_y = last_width = last_height = 0;
84 insetAscent = insetDescent = insetWidth = 0;
85 the_locking_inset = 0;
86 cursor_visible = false;
90 drawTextXOffset = drawTextYOffset = 0;
91 autoBreakRows = false;
95 SetParagraphData(ins->par);
96 autoBreakRows = ins->autoBreakRows;
97 drawFrame = ins->drawFrame;
99 par->SetInsetOwner(this);
100 frame_color = LColor::insetframe;
106 InsetText::~InsetText()
108 LyXParagraph * p = par->next;
118 void InsetText::clear()
120 LyXParagraph * p = par->next;
127 par = new LyXParagraph();
131 Inset * InsetText::Clone() const
133 InsetText * t = new InsetText(*this);
138 void InsetText::Write(Buffer const * buf, ostream & os) const
141 WriteParagraphData(buf, os);
145 void InsetText::WriteParagraphData(Buffer const * buf, ostream & os) const
147 par->writeFile(buf, os, buf->params, 0, 0);
151 void InsetText::Read(Buffer const * buf, LyXLex & lex)
155 LyXParagraph * return_par = 0;
156 char depth = 0; // signed or unsigned?
158 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
159 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
161 LyXFont font(LyXFont::ALL_INHERIT);
163 LyXParagraph * p = par->next;
170 par = new LyXParagraph;
173 token = lex.GetString();
176 if (token == "\\end_inset")
178 if (const_cast<Buffer*>(buf)->
179 parseSingleLyXformat2Token(lex, par, return_par,token, pos, depth,
182 , footnoteflag, footnotekind
186 // the_end read this should NEVER happen
187 lex.printError("\\the_end read in inset! Error in document!");
195 return_par->SetInsetOwner(this);
196 return_par = return_par->next;
199 if (token != "\\end_inset") {
200 lex.printError("Missing \\end_inset at this point. "
207 int InsetText::ascent(BufferView * bv, LyXFont const &) const
210 Row * row = TEXT(bv)->GetRowNearY(y_temp);
211 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
216 int InsetText::descent(BufferView * bv, LyXFont const &) const
219 Row * row = TEXT(bv)->GetRowNearY(y_temp);
220 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
221 TEXT_TO_INSET_OFFSET;
226 int InsetText::width(BufferView * bv, LyXFont const &) const
228 insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET);
233 int InsetText::textWidth(Painter & pain) const
235 int w = getMaxWidth(pain, this);
240 void InsetText::draw(BufferView * bv, LyXFont const & f,
241 int baseline, float & x, bool cleared) const
243 Painter & pain = bv->painter();
245 // no draw is necessary !!!
246 if ((drawFrame == LOCKED) && !locked && !par->size()) {
247 if (!cleared && (need_update == CLEAR_FRAME)) {
248 pain.rectangle(top_x, baseline - insetAscent, insetWidth,
249 insetAscent + insetDescent,
253 top_baseline = baseline;
260 UpdatableInset::draw(bv, f, baseline, x, cleared);
262 if (!cleared && ((need_update==FULL) || (top_x!=int(x)) ||
263 (top_baseline!=baseline))) {
265 int h = insetAscent + insetDescent;
266 int ty = baseline - insetAscent;
272 if ((ty + h) > pain.paperHeight())
273 h = pain.paperHeight();
274 if ((top_x + drawTextXOffset + w) > pain.paperWidth())
275 w = pain.paperWidth();
276 pain.fillRectangle(top_x+drawTextXOffset, ty, w, h);
280 if (!cleared && (need_update == NONE))
283 if (top_x != int(x)) {
286 // owner()->update(bv, f, true);
287 bv->text->status = LyXText::CHANGED_IN_DRAW;
291 top_baseline = baseline;
292 top_y = baseline - ascent(bv, f);
293 last_width = width(bv, f);
294 last_height = ascent(bv, f) + descent(bv, f);
296 if (the_locking_inset && (cpar(bv) == inset_par) && (cpos(bv) == inset_pos)) {
297 inset_x = cx(bv) - top_x + drawTextXOffset;
298 inset_y = cy(bv) + drawTextYOffset;
300 if (!cleared && (need_update == CURSOR) && !TEXT(bv)->selection) {
305 x += 1; // place for border
307 Row * row = TEXT(bv)->GetRowNearY(y);
308 y += baseline - row->ascent_of_text() + 1;
309 if (cleared || !locked || (need_update == FULL)) {
311 TEXT(bv)->GetVisibleRow(bv, y, int(x), row, y, cleared);
315 } else if (need_update == SELECTION) {
316 bv->screen()->ToggleToggle(TEXT(bv), y, int(x));
319 if (need_update == CURSOR) {
320 bv->screen()->ToggleSelection(TEXT(bv), true, y, int(x));
321 TEXT(bv)->ClearSelection();
322 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
324 bv->screen()->Update(TEXT(bv), y, int(x));
327 TEXT(bv)->refresh_y = 0;
328 TEXT(bv)->status = LyXText::UNCHANGED;
329 if ((drawFrame == ALWAYS) || ((drawFrame == LOCKED) && locked)) {
330 pain.rectangle(top_x, baseline - insetAscent, insetWidth,
331 insetAscent + insetDescent, frame_color);
332 } else if (need_update == CLEAR_FRAME) {
333 pain.rectangle(top_x, baseline - insetAscent, insetWidth,
334 insetAscent + insetDescent,
337 x += width(bv, f) - 1;
338 if (bv->text->status==LyXText::CHANGED_IN_DRAW)
340 else if (need_update != INIT)
345 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
347 if (reinit) { // && (need_update != CURSOR)) {
351 owner()->update(bv, font, true);
354 if (the_locking_inset) {
355 inset_x = cx(bv) - top_x + drawTextXOffset;
356 inset_y = cy(bv) + drawTextYOffset;
357 the_locking_inset->update(bv, font, reinit);
359 if (need_update == INIT) {
362 // if (!owner() && bv->text)
363 // bv->text->UpdateInset(bv, this);
365 int oldw = insetWidth;
367 insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET);
368 // max(textWidth(bv->painter()),
369 // static_cast<int>(TEXT(bv)->width) + drawTextXOffset) +
370 // (2 * TEXT_TO_INSET_OFFSET);
372 insetWidth = textWidth(bv->painter());
374 insetWidth = static_cast<int>(TEXT(bv)->width);
376 if (oldw != insetWidth) {
377 // printf("TW(%p): %d-%d-%d-%d\n",this,insetWidth, oldw,
378 // textWidth(bv->painter()),static_cast<int>(TEXT(bv)->width));
383 owner()->update(bv, font, reinit);
386 update(bv, font, reinit);
390 update(bv, font, reinit);
392 UpdateLocal(bv, INIT, false);
397 if ((need_update==CURSOR_PAR) && (TEXT(bv)->status==LyXText::UNCHANGED) &&
400 TEXT(bv)->UpdateInset(bv, the_locking_inset);
403 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
407 Row * row = TEXT(bv)->GetRowNearY(y_temp);
408 insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
409 insetDescent = TEXT(bv)->height - row->ascent_of_text() +
410 TEXT_TO_INSET_OFFSET;
414 void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
416 TEXT(bv)->FullRebreak(bv);
417 if (need_update != INIT) {
418 if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
420 else if (!the_locking_inset || (what != CURSOR))
423 if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED) ||
425 bv->updateInset(this, mark_dirty);
426 bv->owner()->showState();
427 if (old_par != cpar(bv)) {
428 bv->owner()->setLayout(cpar(bv)->GetLayout());
434 char const * InsetText::EditMessage() const
436 return _("Opened Text Inset");
440 void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
442 // par->SetInsetOwner(this);
443 UpdatableInset::Edit(bv, x, y, button);
445 if (!bv->lockInset(this)) {
446 lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
450 the_locking_inset = 0;
451 inset_pos = inset_x = inset_y = 0;
454 if (!checkAndActivateInset(bv, x, y, button))
455 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
456 y+TEXT(bv)->first+insetAscent);
457 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
458 bv->text->FinishUndo();
459 UpdateLocal(bv, FULL, false);
463 void InsetText::InsetUnlock(BufferView * bv)
465 if (the_locking_inset) {
466 the_locking_inset->InsetUnlock(bv);
467 the_locking_inset = 0;
470 no_selection = false;
472 TEXT(bv)->selection = 0;
473 UpdateLocal(bv, CLEAR_FRAME, false);
475 bv->owner()->setLayout(owner()->getLyXText(bv)
476 ->cursor.par()->GetLayout());
478 bv->owner()->setLayout(bv->text->cursor.par()->GetLayout());
482 bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
484 lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
487 if (inset == cpar(bv)->GetInset(cpos(bv))) {
488 lyxerr[Debug::INSETS] << "OK" << endl;
489 the_locking_inset = inset;
490 inset_x = cx(bv) - top_x + drawTextXOffset;
491 inset_y = cy(bv) + drawTextYOffset;
492 inset_pos = cpos(bv);
493 inset_par = cpar(bv);
494 TEXT(bv)->UpdateInset(bv, the_locking_inset);
496 } else if (the_locking_inset && (the_locking_inset == inset)) {
497 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
498 lyxerr[Debug::INSETS] << "OK" << endl;
499 inset_x = cx(bv) - top_x + drawTextXOffset;
500 inset_y = cy(bv) + drawTextYOffset;
502 lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
504 } else if (the_locking_inset) {
505 lyxerr[Debug::INSETS] << "MAYBE" << endl;
506 return the_locking_inset->LockInsetInInset(bv, inset);
508 lyxerr[Debug::INSETS] << "NOT OK" << endl;
513 bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
516 if (!the_locking_inset)
518 if (the_locking_inset == inset) {
519 the_locking_inset->InsetUnlock(bv);
520 TEXT(bv)->UpdateInset(bv, inset);
521 the_locking_inset = 0;
523 moveRight(bv, false);
524 old_par = 0; // force layout setting
525 UpdateLocal(bv, CURSOR_PAR, false);
528 return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
532 bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
534 if (!the_locking_inset)
536 if (the_locking_inset != inset) {
537 TEXT(bv)->UpdateInset(bv, the_locking_inset);
538 need_update = CURSOR_PAR;
539 return the_locking_inset->UpdateInsetInInset(bv, inset);
541 // UpdateLocal(bv, FULL, false);
542 if (TEXT(bv)->UpdateInset(bv, inset))
543 UpdateLocal(bv, CURSOR_PAR, false);
544 if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
545 inset_x = cx(bv) - top_x + drawTextXOffset;
546 inset_y = cy(bv) + drawTextYOffset;
552 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
554 no_selection = false;
556 int tmp_x = x - drawTextXOffset;
557 // int tmp_y = y + TEXT(bv)->first + insetAscent;
558 int tmp_y = y + insetAscent;
559 Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button);
561 if (the_locking_inset) {
562 if (the_locking_inset == inset) {
563 the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
566 // otherwise unlock the_locking_inset and lock the new inset
567 the_locking_inset->InsetUnlock(bv);
568 inset_x = cx(bv) - top_x + drawTextXOffset;
569 inset_y = cy(bv) + drawTextYOffset;
570 inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
571 inset->Edit(bv, x - inset_x, y - inset_y, button);
572 if (the_locking_inset) {
573 UpdateLocal(bv, CURSOR_PAR, false);
577 // otherwise only unlock the_locking_inset
578 the_locking_inset->InsetUnlock(bv);
579 the_locking_inset = 0;
581 if (bv->the_locking_inset) {
582 if (inset && inset->Editable() == Inset::HIGHLY_EDITABLE) {
583 UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
584 inset_x = cx(bv) - top_x + drawTextXOffset;
585 inset_y = cy(bv) + drawTextYOffset;
586 inset_pos = cpos(bv);
587 inset_par = cpar(bv);
588 uinset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
589 uinset->Edit(bv, x - inset_x, y - inset_y, 0);
590 if (the_locking_inset) {
591 UpdateLocal(bv, CURSOR_PAR, false);
597 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
598 y+TEXT(bv)->first+insetAscent);
599 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
600 UpdateLocal(bv, CURSOR, false);
601 bv->owner()->setLayout(cpar(bv)->GetLayout());
607 void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
609 UpdatableInset * inset = 0;
611 if (the_locking_inset) {
612 the_locking_inset->InsetButtonRelease(bv,
613 x - inset_x, y - inset_y,
616 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
617 inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
618 if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
619 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
621 inset_x = cx(bv) - top_x + drawTextXOffset;
622 inset_y = cy(bv) + drawTextYOffset;
623 inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
624 inset->Edit(bv, x - inset_x, y - inset_y, button);
626 UpdateLocal(bv, CURSOR_PAR, false);
629 no_selection = false;
633 void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
635 if (the_locking_inset) {
636 the_locking_inset->InsetMotionNotify(bv, x - inset_x,
642 TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
643 y+TEXT(bv)->first+insetAscent);
644 TEXT(bv)->SetSelection();
645 if (TEXT(bv)->toggle_cursor.par()!=TEXT(bv)->toggle_end_cursor.par() ||
646 TEXT(bv)->toggle_cursor.pos()!=TEXT(bv)->toggle_end_cursor.pos())
647 UpdateLocal(bv, SELECTION, false);
650 no_selection = false;
654 void InsetText::InsetKeyPress(XKeyEvent * xke)
656 if (the_locking_inset) {
657 the_locking_inset->InsetKeyPress(xke);
663 UpdatableInset::RESULT
664 InsetText::LocalDispatch(BufferView * bv,
665 int action, string const & arg)
667 no_selection = false;
668 UpdatableInset::RESULT
669 result= UpdatableInset::LocalDispatch(bv, action, arg);
670 if (result != UNDISPATCHED) {
671 // resetPos(bv->painter());
676 if ((action < 0) && arg.empty())
679 if (the_locking_inset) {
680 result = the_locking_inset->LocalDispatch(bv, action, arg);
681 if (result == DISPATCHED_NOUPDATE)
683 else if (result == DISPATCHED) {
684 UpdateLocal(bv, CURSOR_PAR, false);
686 } else if (result == FINISHED) {
690 moveRight(bv, false);
696 the_locking_inset = 0;
704 if (bv->buffer()->isReadonly()) {
706 // setErrorMessage(N_("Document is read only"));
710 /* Automatically delete the currently selected
711 * text and replace it with what is being
712 * typed in now. Depends on lyxrc settings
713 * "auto_region_delete", which defaults to
716 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
718 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
719 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
721 bv->text->cursor.par()->previous,
722 bv->text->cursor.par()->next
725 if (lyxrc.auto_region_delete) {
726 if (TEXT(bv)->selection){
727 TEXT(bv)->CutSelection(bv, false);
730 TEXT(bv)->ClearSelection();
731 for (string::size_type i = 0; i < arg.length(); ++i) {
732 bv->owner()->getIntl()->getTrans()->TranslateAndInsert(arg[i], TEXT(bv));
735 UpdateLocal(bv, CURSOR_PAR, true);
737 // --- Cursor Movements ---------------------------------------------
739 bv->text->FinishUndo();
740 moveRight(bv, false);
741 TEXT(bv)->SetSelection();
742 UpdateLocal(bv, SELECTION, false);
745 result = moveRight(bv);
746 bv->text->FinishUndo();
747 UpdateLocal(bv, CURSOR, false);
750 bv->text->FinishUndo();
752 TEXT(bv)->SetSelection();
753 UpdateLocal(bv, SELECTION, false);
756 bv->text->FinishUndo();
757 result= moveLeft(bv);
758 UpdateLocal(bv, CURSOR, false);
761 bv->text->FinishUndo();
763 TEXT(bv)->SetSelection();
764 UpdateLocal(bv, SELECTION, false);
767 bv->text->FinishUndo();
768 result = moveDown(bv);
769 UpdateLocal(bv, CURSOR, false);
772 bv->text->FinishUndo();
774 TEXT(bv)->SetSelection();
775 UpdateLocal(bv, SELECTION, false);
778 bv->text->FinishUndo();
780 UpdateLocal(bv, CURSOR, false);
783 bv->text->FinishUndo();
784 TEXT(bv)->CursorHome(bv);
785 UpdateLocal(bv, CURSOR, false);
788 TEXT(bv)->CursorEnd(bv);
789 UpdateLocal(bv, CURSOR, false);
792 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
794 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
795 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
797 bv->text->cursor.par()->previous,
798 bv->text->cursor.par()->next
801 TEXT(bv)->Backspace(bv);
802 UpdateLocal(bv, CURSOR_PAR, true);
805 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
807 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
808 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
810 bv->text->cursor.par()->previous,
811 bv->text->cursor.par()->next
814 TEXT(bv)->Delete(bv);
815 UpdateLocal(bv, CURSOR_PAR, true);
818 bv->text->SetUndo(bv->buffer(), Undo::DELETE,
820 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
821 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
823 bv->text->cursor.par()->previous,
824 bv->text->cursor.par()->next
827 TEXT(bv)->CutSelection(bv);
828 UpdateLocal(bv, CURSOR_PAR, true);
831 bv->text->FinishUndo();
832 TEXT(bv)->CopySelection(bv);
833 UpdateLocal(bv, CURSOR_PAR, false);
836 if (!autoBreakRows) {
839 if (cap.nrOfParagraphs() > 1) {
840 WriteAlert(_("Impossible operation"),
841 _("Cannot include more than one paragraph!"),
846 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
848 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
849 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
851 bv->text->cursor.par()->previous,
852 bv->text->cursor.par()->next
855 TEXT(bv)->PasteSelection(bv);
856 UpdateLocal(bv, CURSOR_PAR, true);
858 case LFUN_BREAKPARAGRAPH:
861 TEXT(bv)->BreakParagraph(bv, 0);
862 UpdateLocal(bv, FULL, true);
867 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
869 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
870 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
872 bv->text->cursor.par()->previous,
873 bv->text->cursor.par()->next
876 TEXT(bv)->InsertChar(bv, LyXParagraph::META_NEWLINE);
877 UpdateLocal(bv, CURSOR_PAR, true);
881 static LyXTextClass::size_type cur_layout = cpar(bv)->layout;
883 // Derive layout number from given argument (string)
884 // and current buffer's textclass (number). */
885 LyXTextClassList::ClassList::size_type tclass =
886 bv->buffer()->params.textclass;
887 std::pair <bool, LyXTextClass::size_type> layout =
888 textclasslist.NumberOfLayout(tclass, arg);
890 // If the entry is obsolete, use the new one instead.
892 string obs = textclasslist.Style(tclass,layout.second).
895 layout = textclasslist.NumberOfLayout(tclass, obs);
898 // see if we found the layout number:
900 string msg = string(N_("Layout ")) + arg + N_(" not known");
902 bv->owner()->getMiniBuffer()->Set(msg);
906 if (cur_layout != layout.second) {
907 cur_layout = layout.second;
908 TEXT(bv)->SetLayout(bv, layout.second);
909 bv->owner()->setLayout(cpar(bv)->GetLayout());
910 UpdateLocal(bv, CURSOR_PAR, true);
914 case LFUN_PARAGRAPH_SPACING:
915 // This one is absolutely not working. When fiddling with this
916 // it also seems to me that the paragraphs inside the insettext
917 // inherit bufferparams/paragraphparams in a strange way. (Lgb)
919 LyXParagraph * par = TEXT(bv)->cursor.par();
920 Spacing::Space cur_spacing = par->spacing.getSpace();
921 float cur_value = 1.0;
922 if (cur_spacing == Spacing::Other) {
923 cur_value = par->spacing.getValue();
927 std::istringstream istr(arg.c_str());
929 istrstream istr(arg.c_str());
933 Spacing::Space new_spacing = cur_spacing;
934 float new_value = cur_value;
936 lyxerr << "Missing argument to `paragraph-spacing'"
938 } else if (tmp == "single") {
939 new_spacing = Spacing::Single;
940 } else if (tmp == "onehalf") {
941 new_spacing = Spacing::Onehalf;
942 } else if (tmp == "double") {
943 new_spacing = Spacing::Double;
944 } else if (tmp == "other") {
945 new_spacing = Spacing::Other;
948 lyxerr << "new_value = " << tmpval << endl;
951 } else if (tmp == "default") {
952 new_spacing = Spacing::Default;
954 lyxerr << _("Unknown spacing argument: ")
957 if (cur_spacing != new_spacing || cur_value != new_value) {
958 par->spacing.set(new_spacing, new_value);
959 //TEXT(bv)->RedoParagraph(owner->view());
960 UpdateLocal(bv, CURSOR_PAR, true);
961 //bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
967 result = UNDISPATCHED;
970 if (result != FINISHED) {
973 bv->unlockInset(this);
978 int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
981 buf->latexParagraphs(os, par, 0, texrow);
982 return texrow.rows();
986 void InsetText::Validate(LaTeXFeatures & features) const
988 LyXParagraph * p = par;
990 p->validate(features);
996 int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
998 if (textclasslist.Style(buf->params.textclass,
999 p->GetLayout()).labeltype != LABEL_MANUAL)
1002 return p->BeginningOfMainBody();
1006 void InsetText::GetCursorPos(BufferView * bv, int & x, int & y) const
1013 int InsetText::InsetInInsetY()
1015 if (!the_locking_inset)
1018 return (inset_y + the_locking_inset->InsetInInsetY());
1022 void InsetText::ToggleInsetCursor(BufferView * bv)
1024 if (the_locking_inset) {
1025 the_locking_inset->ToggleInsetCursor(bv);
1029 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1031 int asc = lyxfont::maxAscent(font);
1032 int desc = lyxfont::maxDescent(font);
1035 bv->hideLockedInsetCursor();
1037 bv->showLockedInsetCursor(cx(bv)-1, cy(bv),
1039 cursor_visible = !cursor_visible;
1043 void InsetText::ShowInsetCursor(BufferView * bv)
1045 if (the_locking_inset) {
1046 the_locking_inset->ShowInsetCursor(bv);
1049 if (!cursor_visible) {
1050 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1052 int asc = lyxfont::maxAscent(font);
1053 int desc = lyxfont::maxDescent(font);
1055 bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1056 bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
1057 cursor_visible = true;
1062 void InsetText::HideInsetCursor(BufferView * bv)
1064 if (cursor_visible) {
1065 bv->hideLockedInsetCursor();
1066 cursor_visible = false;
1068 if (the_locking_inset)
1069 the_locking_inset->HideInsetCursor(bv);
1073 UpdatableInset::RESULT
1074 InsetText::moveRight(BufferView * bv, bool activate_inset)
1076 if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
1078 if (activate_inset && checkAndActivateInset(bv, false))
1080 TEXT(bv)->CursorRight(bv);
1081 return DISPATCHED_NOUPDATE;
1085 UpdatableInset::RESULT
1086 InsetText::moveLeft(BufferView * bv, bool activate_inset)
1088 if (!cpar(bv)->previous && (cpos(bv) <= 0))
1090 TEXT(bv)->CursorLeft(bv);
1091 if (activate_inset && checkAndActivateInset(bv, true))
1093 return DISPATCHED_NOUPDATE;
1097 UpdatableInset::RESULT
1098 InsetText::moveUp(BufferView * bv)
1100 if (!crow(bv)->previous())
1102 TEXT(bv)->CursorUp(bv);
1103 return DISPATCHED_NOUPDATE;
1107 UpdatableInset::RESULT
1108 InsetText::moveDown(BufferView * bv)
1110 if (!crow(bv)->next())
1112 TEXT(bv)->CursorDown(bv);
1113 return DISPATCHED_NOUPDATE;
1117 bool InsetText::InsertInset(BufferView * bv, Inset * inset)
1119 if (the_locking_inset) {
1120 if (the_locking_inset->InsertInsetAllowed(inset))
1121 return the_locking_inset->InsertInset(bv, inset);
1124 bv->text->SetUndo(bv->buffer(), Undo::INSERT,
1126 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1127 bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
1129 bv->text->cursor.par()->previous,
1130 bv->text->cursor.par()->next
1133 if (inset->Editable() == Inset::IS_EDITABLE) {
1134 UpdatableInset * i = static_cast<UpdatableInset *>(inset);
1135 i->setOwner(static_cast<UpdatableInset *>(this));
1137 TEXT(bv)->InsertInset(bv, inset);
1138 TEXT(bv)->selection = 0;
1139 UpdateLocal(bv, CURSOR_PAR, true);
1140 static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
1145 UpdatableInset * InsetText::GetLockingInset()
1147 return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
1151 UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
1155 if (the_locking_inset)
1156 return the_locking_inset->GetFirstLockingInsetOfType(c);
1161 void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
1163 TEXT(bv)->SetFont(bv, font, toggleall);
1167 bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
1169 if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
1172 static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
1173 if (!inset || inset->Editable() != Inset::HIGHLY_EDITABLE)
1175 LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
1177 x = inset->width(bv, font);
1178 y = inset->descent(bv, font);
1182 inset_x = cx(bv) - top_x + drawTextXOffset;
1183 inset_y = cy(bv) + drawTextYOffset;
1184 inset->Edit(bv, x-inset_x, y-inset_y, 0);
1185 if (!the_locking_inset)
1187 UpdateLocal(bv, CURSOR_PAR, false);
1194 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
1197 int tmp_x = x - drawTextXOffset;
1198 int tmp_y = y + insetAscent;
1199 Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button);
1206 inset_x = cx(bv) - top_x + drawTextXOffset;
1207 inset_y = cy(bv) + drawTextYOffset;
1208 inset->Edit(bv, x - inset_x, y - inset_y, button);
1209 if (!the_locking_inset)
1211 UpdateLocal(bv, CURSOR_PAR, false);
1218 int InsetText::getMaxWidth(Painter & pain, UpdatableInset const * inset) const
1220 int w = UpdatableInset::getMaxWidth(pain, inset);
1225 w = w - top_x + owner()->x();
1228 w -= (2 * TEXT_TO_INSET_OFFSET);
1230 // return w - (2*TEXT_TO_INSET_OFFSET);
1234 void InsetText::SetParagraphData(LyXParagraph *p)
1248 par->SetInsetOwner(this);
1252 np->next = p->Clone();
1253 np->next->previous = np;
1255 np->SetInsetOwner(this);
1261 void InsetText::SetAutoBreakRows(bool flag)
1263 if (flag != autoBreakRows) {
1264 autoBreakRows = flag;
1272 void InsetText::SetDrawFrame(BufferView * bv, DrawFrame how)
1274 if (how != drawFrame) {
1277 UpdateLocal(bv, DRAW_FRAME, false);
1282 void InsetText::SetFrameColor(BufferView * bv, LColor::color col)
1284 if (frame_color != col) {
1287 UpdateLocal(bv, DRAW_FRAME, false);
1292 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
1294 return TEXT(bv)->GetFont(bv->buffer(), p, pos);
1298 int InsetText::cx(BufferView * bv) const
1300 return TEXT(bv)->cursor.x() + top_x + 1;
1304 int InsetText::cy(BufferView * bv) const
1307 return TEXT(bv)->cursor.y() - ascent(bv, font);
1311 int InsetText::cpos(BufferView * bv) const
1313 return TEXT(bv)->cursor.pos();
1317 LyXParagraph * InsetText::cpar(BufferView * bv) const
1319 return TEXT(bv)->cursor.par();
1323 Row * InsetText::crow(BufferView * bv) const
1325 return TEXT(bv)->cursor.row();
1329 LyXText * InsetText::getLyXText(BufferView * bv) const
1331 if (cache.find(bv) != cache.end())
1333 LyXText * lt = new LyXText(const_cast<InsetText *>(this));
1336 if (the_locking_inset) {
1337 lt->SetCursor(bv, inset_par, inset_pos);
1343 void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
1347 /// then remove all LyXText in text-insets
1348 LyXParagraph * p = par;
1349 for(;p;p = p->next) {
1350 p->deleteInsetsLyXText(bv);
1355 void InsetText::resizeLyXText(BufferView * bv) const
1357 if (!par->next && !par->size()) // not neccessary!
1360 LyXParagraph * lpar = 0;
1361 LyXParagraph * selstartpar = 0;
1362 LyXParagraph * selendpar = 0;
1364 int selstartpos = 0;
1369 // ProhibitInput(bv);
1371 lpar = TEXT(bv)->cursor.par();
1372 pos = TEXT(bv)->cursor.pos();
1373 selstartpar = TEXT(bv)->sel_start_cursor.par();
1374 selstartpos = TEXT(bv)->sel_start_cursor.pos();
1375 selendpar = TEXT(bv)->sel_end_cursor.par();
1376 selendpos = TEXT(bv)->sel_end_cursor.pos();
1377 selection = TEXT(bv)->selection;
1378 mark_set = TEXT(bv)->mark_set;
1379 deleteLyXText(bv, (the_locking_inset == 0));
1382 TEXT(bv)->selection = true;
1383 /* at this point just to avoid the Delete-Empty-Paragraph
1384 * Mechanism when setting the cursor */
1385 TEXT(bv)->mark_set = mark_set;
1387 TEXT(bv)->SetCursor(bv, selstartpar, selstartpos);
1388 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
1389 TEXT(bv)->SetCursor(bv, selendpar, selendpos);
1390 TEXT(bv)->SetSelection();
1391 TEXT(bv)->SetCursor(bv, lpar, pos);
1393 TEXT(bv)->SetCursor(bv, lpar, pos);
1394 TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
1395 TEXT(bv)->selection = false;
1399 TEXT(bv)->first = bv->screen()->TopCursorVisible(TEXT(bv));
1400 // this will scroll the screen such that the cursor becomes visible
1401 bv->updateScrollbar();
1403 if (the_locking_inset) {
1404 /// then resize all LyXText in text-insets
1405 inset_x = cx(bv) - top_x + drawTextXOffset;
1406 inset_y = cy(bv) + drawTextYOffset;
1407 LyXParagraph * p = par;
1408 for(;p;p = p->next) {
1409 p->resizeInsetsLyXText(bv);
1416 void InsetText::removeNewlines()
1418 LyXParagraph * p = par;
1420 for(;p; p = p->next) {
1421 for(int i = 0; i < p->Last(); ++i) {
1422 if (p->GetChar(i) == LyXParagraph::META_NEWLINE)