#include "support/lyxfunctional.h" //equal_1st_in_pair
#include "language.h"
#include "gettext.h"
+#include "undo_funcs.h"
extern BufferList bufferlist;
hideCursor();
beforeChange(text);
update(text, BufferView::SELECT|BufferView::FITCUR);
- if (!text->textUndo(this))
+ if (!textUndo(this))
owner()->message(_("No forther undo information"));
else
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
hideCursor();
beforeChange(text);
update(text, BufferView::SELECT|BufferView::FITCUR);
- if (!text->textRedo(this))
+ if (!textRedo(this))
owner()->message(_("No further redo information"));
else
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
if (inset && theLockingInset() == inset) {
inset->insetUnlock(this);
theLockingInset(0);
- text->finishUndo();
+ finishUndo();
return 0;
} else if (inset && theLockingInset() &&
theLockingInset()->unlockInsetInInset(this, inset)) {
- text->finishUndo();
+ finishUndo();
return 0;
}
return bufferlist.unlockInset(inset);
return; // shouldn't happen
if (kind == Undo::EDIT) // in this case insets would not be stored!
kind = Undo::FINISH;
- text->setUndo(buffer(), kind,
- text->cursor.par()->previous(),
- text->cursor.par()->next());
+ setUndo(this, kind,
+ text->cursor.par(),
+ text->cursor.par()->next());
}
#include "insets/insetspecialchar.h"
#include "gettext.h"
#include "ParagraphParameters.h"
+#include "undo_funcs.h"
#include "mathed/formulabase.h"
extern LyXTextClass::size_type current_layout;
if (!inset_hit) // otherwise it was already set in checkInsetHit(...)
bv_->text->setCursorFromCoordinates(bv_, xpos, ypos + screen_first);
- bv_->text->finishUndo();
+ finishUndo();
bv_->text->selection.cursor = bv_->text->cursor;
bv_->text->cursor.x_fix(bv_->text->cursor.x());
// ...or maybe the SetCursorParUndo()
// below isn't necessary at all anylonger?
if (inset_hit->lyxCode() == Inset::REF_CODE) {
- bv_->text->setCursorParUndo(buffer_);
+ setCursorParUndo(bv_);
}
owner_->message(inset_hit->editMessage());
y += bv_->text->first;
Row * cursorrow = text->cursor.row();
text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
- bv_->text->finishUndo();
+ finishUndo();
// This is to allow jumping over large insets
if ((cursorrow == text->cursor.row()))
text->cursorUp(bv_);
Row * cursorrow = text->cursor.row();
text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y); // + workarea_->height());
- bv_->text->finishUndo();
+ finishUndo();
// This is to allow jumping over large insets
if ((cursorrow == bv_->text->cursor.row()))
text->cursorDown(bv_);
if (!inset_slept)
bv_->theLockingInset()->insetUnlock(bv_);
bv_->theLockingInset(0);
- bv_->text->finishUndo();
+ finishUndo();
inset_slept = false;
}
}
}
if (!is_rtl)
lt->cursorRight(bv_, false);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
if (is_rtl)
lt->cursorRight(bv_, false);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
beforeChange(lt);
update(lt, BufferView::UPDATE);
lt->cursorUp(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
beforeChange(lt);
update(lt, BufferView::UPDATE);
lt->cursorDown(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
beforeChange(lt);
update(lt, BufferView::UPDATE);
lt->cursorUpParagraph(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
beforeChange(lt);
update(lt, BufferView::UPDATE);
lt->cursorDownParagraph(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
beforeChange(lt);
update(lt, BufferView::UPDATE);
cursorPrevious(lt);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
beforeChange(lt);
update(lt, BufferView::UPDATE);
cursorNext(lt);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
beforeChange(lt);
update(lt, BufferView::SELECT|BufferView::FITCUR);
lt->cursorHome(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorEnd(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorTab(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
lt->cursorLeftOneWord(bv_);
else
lt->cursorRightOneWord(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
lt->cursorRightOneWord(bv_);
else
lt->cursorLeftOneWord(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorTop(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorBottom(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(false);
owner_->showState();
}
lt->cursorLeft(bv_);
else
lt->cursorRight(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
lt->cursorRight(bv_);
else
lt->cursorLeft(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorUp(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorDown(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorUpParagraph(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorDownParagraph(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt, BufferView::SELECT|BufferView::FITCUR);
cursorPrevious(lt);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt, BufferView::SELECT|BufferView::FITCUR);
cursorNext(lt);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt, BufferView::SELECT|BufferView::FITCUR);
lt->cursorHome(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt, BufferView::SELECT|BufferView::FITCUR);
lt->cursorEnd(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
lt->cursorLeftOneWord(bv_);
else
lt->cursorRightOneWord(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
lt->cursorRightOneWord(bv_);
else
lt->cursorLeftOneWord(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
break;
update(lt, BufferView::SELECT|BufferView::FITCUR);
lt->cursorTop(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
update(lt,
BufferView::SELECT|BufferView::FITCUR);
lt->cursorBottom(bv_);
- lt->finishUndo();
+ finishUndo();
moveCursorUpdate(true);
owner_->showState();
}
LyXText * lt = bv_->getLyXText();
beforeChange(lt);
- lt->finishUndo();
+ finishUndo();
if (!insertInset(new_inset)) {
delete new_inset;
return false;
}
// not quite sure if we want this...
- bv_->text->setCursorParUndo(buffer_);
- bv_->text->freezeUndo();
+ setCursorParUndo(bv_);
+ freezeUndo();
beforeChange(bv_->text);
if (!lout.empty()) {
bv_->text->insertInset(bv_, inset);
update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
- bv_->text->unFreezeUndo();
+ unFreezeUndo();
return true;
}
+2001-07-06 Juergen Vigna <jug@sad.it>
+
+ * a lot of files: changed the access to LyXText::status and the
+ call of undo-functions.
+
+ * undo.[Ch]: added a inset_id to the undo informations.
+
+ * undo_funcs.[Ch]: added and moved here all undo functions.
+
+ * lyxtext.h: give the status enum a weight, made status_ a private
+ variable and made accessor functions for it, removed the whole bunch
+ of undo-functions as they are now in their own file, make some
+ functions publically available. Added function ownerParagraph with
+ int parameter.
+
+ * paragraph.[Ch]: added "bool same_ids" to the constructor,
+ made InInset() a const function, added getParFromID() function.
+
+ * buffer.[Ch]: added const version for inset_iterator functions,
+ added getInsetFromID() function.
+
+ * BufferView2.C, BufferView_pimpl.C, text.C, text2.C, lyxfunc.C:
+ changed undo functions for new version.
+
+2001-07-05 Juergen Vigna <jug@sad.it>
+
+ * paragraph_pimpl.C (Pimpl): set id_ also here (this is because some
+ unknow mechanism does not call the proper consturctor but only this
+ one also if I request the other!?
+
2001-07-06 Lars Gullik Bjønnes <larsbj@birdstep.com>
* BufferView_pimpl.C (resizeCurrentBuffer): init the new LyXText
trans_mgr.h \
undo.C \
undo.h \
+ undo_funcs.C \
+ undo_funcs.h \
undostack.C \
undostack.h \
vc-backend.C \
lyxerr << "WP:" << mini->width() << endl;
mini->width(tostr(par->params().pextraWidthp())+"%");
}
- mini->inset.par = par;
+ mini->inset.paragraph(par);
// Insert the minipage last in the
// previous paragraph.
if (par->params().pextraHfill()) {
lyxerr << "WP:" << mini->width() << endl;
mini->width(tostr(par->params().pextraWidthp())+"%");
}
- mini->inset.par = minipar;
+ mini->inset.paragraph(minipar);
// Insert the minipage last in the
// previous paragraph.
// Now find the caption in the float...
// We now tranverse the paragraphs of
// the inset...
- Paragraph * tmp = il->inset.par;
+ Paragraph * tmp = il->inset.paragraph();
while (tmp) {
if (tmp->layout == cap) {
SingleList & item = l[type];
//it = 0;
// We maintain an invariant that whenever par = 0 then it = 0
}
+
+
+Inset * Buffer::getInsetFromID(int id_arg) const
+{
+ for (inset_iterator it = inset_const_iterator_begin();
+ it != inset_const_iterator_end(); ++it)
+ {
+ if ((*it)->id() == id_arg)
+ return *it;
+ Inset * in = (*it)->getInsetFromID(id_arg);
+ if (in)
+ return in;
+ }
+ return 0;
+}
inset_iterator inset_iterator_end() {
return inset_iterator();
}
+ ///
+ inset_iterator inset_const_iterator_begin() const {
+ return inset_iterator(paragraph);
+ }
+ ///
+ inset_iterator inset_const_iterator_end() const {
+ return inset_iterator();
+ }
+ ///
+ Inset * getInsetFromID(int id_arg) const;
};
#include "BufferView.h"
#include "lyxtext.h"
#include "LyXView.h"
+#include "undo_funcs.h"
#include "gettext.h"
extern FD_form_figure * fd_form_figure;
current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR);
current_view->beforeChange(current_view->text);
- current_view->text->setCursorParUndo(current_view->buffer());
- current_view->text->freezeUndo();
+ setCursorParUndo(current_view);
+ freezeUndo();
current_view->text->breakParagraph(current_view);
current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
new_inset->edit(current_view, 0, 0, 0);
current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR);
current_view->owner()->message(_("Figure inserted"));
- current_view->text->unFreezeUndo();
+ unFreezeUndo();
current_view->setState();
}
+2001-07-06 Juergen Vigna <jug@sad.it>
+
+ * a lot of files: added implementation of the below new functions
+ and the change to clone(). Also the call of the new undo-functions
+ where needed.
+
+ * inset.h: added an inset_id, added functions getParFromID,
+ getInsetFromID, firstParagraph, cursor and id functions, added
+ bool same_ids to clone function.
+
2001-07-05 Lars Gullik Bjønnes <larsbj@birdstep.com>
* insettext.[hC]: make cached_text a shared_ptr, make Cache be a map
* inseturl.C: fix method names in these to begin
with small char too, so they inherit
+2001-06-28 Juergen Vigna <jug@sad.it>
+
+ * insettext.C (setFont): fixed font settings using toggleFree()
+ instead of setFont().
+
2001-06-28 Lars Gullik Bjønnes <larsbj@birdstep.com>
* Change a lot of method names to begin with a small char.
}
-Inset * InsetFig::clone(Buffer const & buffer) const
+Inset * InsetFig::clone(Buffer const & buffer, bool) const
{
InsetFig * tmp = new InsetFig(100, 100, buffer);
///
Inset::Code lyxCode() const;
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
///
void callbackFig(long arg);
///
#include "support/lstrings.h"
#include "gettext.h"
#include "lyxfont.h"
+#include "lyxcursor.h"
+#include "lyxtext.h"
using std::endl;
// Insets default methods
+// Initialization of the counter for the inset id's,
+unsigned int Inset::inset_id = 0;
+
bool Inset::deletable() const
{
return true;
}
+int Inset::id() const
+{
+ return id_;
+}
+
+void Inset::id(int id_arg)
+{
+ id_ = id_arg;
+}
+
// some stuff for inset locking
void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
(owner())->getMaxWidth(bv, this);
return bv->workWidth();
}
+
+LyXCursor const & Inset::cursor(BufferView * bv) const
+{
+ return bv->text->cursor;
+}
class Painter;
class LyXText;
class LyXLex;
+class Paragraph;
+class LyXCursor;
struct LaTeXFeatures;
};
///
- Inset() : top_x(0), top_baseline(0), scx(0), owner_(0) {}
+ Inset() : top_x(0), top_baseline(0), scx(0), id_(inset_id++), owner_(0) {}
/// Virtual base destructor
virtual ~Inset() {}
///
}
///
- virtual Inset * clone(Buffer const &) const = 0;
+ virtual Inset * clone(Buffer const &, bool same_ids = false) const = 0;
/// returns true to override begin and end inset in file
virtual bool directWrite() const;
return scx;
return 0;
}
+ /// try to get a paragraph pointer from it's id if we have a
+ /// paragraph to give back!
+ virtual Paragraph * getParFromID(int /* id */) const {
+ return 0;
+ }
+ /// try to get a inset pointer from it's id if we have
+ /// an inset to give back!
+ virtual Inset * getInsetFromID(int /* id */) const {
+ return 0;
+ }
+ /// if this insets owns paragraphs (f.ex. InsetText) then it
+ /// should return it's very first one!
+ virtual Paragraph * firstParagraph() const {
+ return 0;
+ }
+ /// return the cursor if we own one otherwise giv'em just the
+ /// BufferView cursor to work with.
+ virtual LyXCursor const & cursor(BufferView * bview) const;
+ /// id functions
+ int id() const;
+ void id(int id_arg);
protected:
///
mutable int top_baseline;
///
mutable int scx;
+ ///
+ unsigned int id_;
+ ///
+ static unsigned int inset_id;
+
private:
///
Inset * owner_;
}
-Inset * InsetBibKey::clone(Buffer const &) const
+Inset * InsetBibKey::clone(Buffer const &, bool) const
{
InsetBibKey * b = new InsetBibKey(params());
b->setCounter(counter);
}
-InsetBibtex::InsetBibtex(InsetCommandParams const & p)
+InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool)
: InsetCommand(p)
{}
///
~InsetBibKey();
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
/** Currently \bibitem is used as a LyX2.x command,
so we need this method.
*/
- void write(Buffer const *, std::ostream &) const;
+ void write(Buffer const *, std::ostream &) const;
///
void read(Buffer const *, LyXLex & lex);
///
class InsetBibtex : public InsetCommand {
public:
///
- InsetBibtex(InsetCommandParams const &);
+ InsetBibtex(InsetCommandParams const &, bool same_id = false);
///
~InsetBibtex();
///
- Inset * clone(Buffer const &) const {
- return new InsetBibtex(params());
+ Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetBibtex(params(), same_id);
}
///
string const getScreenLabel() const;
#include "frontends/Dialogs.h"
#include "support/lstrings.h"
-InsetCitation::InsetCitation(InsetCommandParams const & p)
+InsetCitation::InsetCitation(InsetCommandParams const & p, bool)
: InsetCommand(p)
{}
class InsetCitation : public InsetCommand {
public:
///
- InsetCitation(InsetCommandParams const &);
+ InsetCitation(InsetCommandParams const &, bool same_id = false);
///
- Inset * clone(Buffer const &) const {
- return new InsetCitation(params());
+ Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetCitation(params(), same_id);
}
///
string const getScreenLabel() const;
// we don't need anymore to clear here we just have to tell
// the underlying LyXText that it should do the RowClear!
inset.setUpdateStatus(bv, InsetText::FULL);
- bv->text->status = LyXText::CHANGED_IN_DRAW;
+ bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
return;
#else
int w = owner() ? width(bv, f) : pain.paperWidth();
return sx;
}
+
+Paragraph * InsetCollapsable::getParFromID(int id) const
+{
+ return inset.getParFromID(id);
+}
+
+Paragraph * InsetCollapsable::firstParagraph() const
+{
+ return inset.firstParagraph();
+}
+
+LyXCursor const & InsetCollapsable::cursor(BufferView * bv) const
+{
+ return inset.cursor(bv);
+}
+
+Inset * InsetCollapsable::getInsetFromID(int id_arg) const
+{
+ if (id_arg == id())
+ return const_cast<InsetCollapsable *>(this);
+ return inset.getInsetFromID(id_arg);
+}
class Painter;
class LyXText;
+class Paragraph;
+class LyXCursor;
/** A colapsable text inset
void scroll(BufferView *bv, int offset) const {
UpdatableInset::scroll(bv, offset);
}
+ ///
+ Paragraph * getParFromID(int id) const;
+ ///
+ Inset * getInsetFromID(int id) const;
+ ///
+ Paragraph * firstParagraph() const;
+ ///
+ LyXCursor const & cursor(BufferView *) const;
protected:
///
}
-InsetCommand::InsetCommand( InsetCommandParams const & p )
+InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
: p_( p.getCmdName(), p.getContents(), p.getOptions() )
-{}
+{
+}
void InsetCommand::setParams(InsetCommandParams const & p )
public:
///
explicit
- InsetCommand(InsetCommandParams const &);
+ InsetCommand(InsetCommandParams const &, bool same_id = false);
///
virtual ~InsetCommand() { hideDialog(); }
///
/* Error, used for the LaTeX-Error Messages */
-InsetError::InsetError(string const & str)
+InsetError::InsetError(string const & str, bool)
: contents(str)
{}
public:
///
explicit
- InsetError(string const &);
+ InsetError(string const &, bool same_id = false);
///
~InsetError() { hideDialog(); }
///
///
EDITABLE editable() const { return IS_EDITABLE; }
///
- Inset * clone(Buffer const &) const { return new InsetError(contents); }
+ Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetError(contents, same_id);
+ }
///
Inset::Code lyxCode() const { return Inset::ERROR_CODE; }
/// We don't want "begin" and "end inset" in lyx-file
}
-Inset * InsetERT::clone(Buffer const &) const
+Inset * InsetERT::clone(Buffer const &, bool same_id) const
{
InsetERT * result = new InsetERT;
- result->inset.init(&inset);
+ result->inset.init(&inset, same_id);
result->collapsed = collapsed;
+ if (same_id)
+ result->id_ = id_;
return result;
}
int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
bool /*free_spc*/) const
{
- Paragraph::size_type siz = inset.par->size();
+ Paragraph::size_type siz = inset.paragraph()->size();
for (Paragraph::size_type i = 0; i != siz; ++i) {
- os << inset.par->getChar(i);
+ os << inset.paragraph()->getChar(i);
}
return 1;
}
///
virtual void write(Buffer const * buf, std::ostream & os) const;
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
virtual string const editMessage() const;
///
}
-Inset * InsetExternal::clone(Buffer const &) const
+Inset * InsetExternal::clone(Buffer const &, bool same_id) const
{
InsetExternal * inset = new InsetExternal();
inset->params_ = params_;
inset->view_ = view_;
+ if (same_id)
+ inset->id_ = id_;
return inset;
}
virtual Inset::Code lyxCode() const { return EXTERNAL_CODE; }
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
/// returns the text of the button
virtual string const getScreenLabel() const;
}
-Inset * InsetFloat::clone(Buffer const &) const
+Inset * InsetFloat::clone(Buffer const &, bool same_id) const
{
InsetFloat * result = new InsetFloat(floatType_);
- result->inset.init(&inset);
+ result->inset.init(&inset, same_id);
result->collapsed = collapsed;
+ if (same_id)
+ result->id_ = id_;
return result;
}
///
void validate(LaTeXFeatures & features) const;
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const { return Inset::FLOAT_CODE; }
///
InsetFloatList(string const & type)
: float_type(type) {}
///
- Inset * clone(Buffer const &) const {
+ Inset * clone(Buffer const &, bool same_id = false) const {
return new InsetFloatList(*this);
}
///
}
-Inset * InsetFoot::clone(Buffer const &) const
+Inset * InsetFoot::clone(Buffer const &, bool same_id) const
{
InsetFoot * result = new InsetFoot;
- result->inset.init(&inset);
+ result->inset.init(&inset, same_id);
result->collapsed = collapsed;
+ if (same_id)
+ result->id_ = id_;
return result;
}
///
InsetFoot();
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const { return Inset::FOOT_CODE; }
///
imageLoaded = true;
// Tell BufferView we need to be updated!
- bv->text->status = LyXText::CHANGED_IN_DRAW;
+ bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
return;
}
}
-Inset * InsetGraphics::clone(Buffer const &) const
+Inset * InsetGraphics::clone(Buffer const &, bool) const
{
#ifdef WITH_WARNINGS
#warning use the copy constructor instead. (Lgb)
+#warning and then please honor the same_id flag (Jug)
#endif
InsetGraphics * newInset = new InsetGraphics;
Inset::Code lyxCode() const { return Inset::GRAPHICS_CODE; }
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
/** Set the inset parameters, used by the GUIndependent dialog.
Return true of new params are different from what was so far.
}
-Inset * InsetInclude::clone(Buffer const & buffer) const
+Inset * InsetInclude::clone(Buffer const & buffer, bool) const
{
Params p(params_);
p.masterFilename_ = buffer.fileName();
void set(Params const & params);
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
/// This returns the list of labels on the child buffer
#include "LaTeXFeatures.h"
#include "gettext.h"
-InsetIndex::InsetIndex(InsetCommandParams const & p)
+InsetIndex::InsetIndex(InsetCommandParams const & p, bool)
: InsetCommand(p)
{}
}
-InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
+InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p, bool)
: InsetCommand(p)
{}
class InsetIndex : public InsetCommand {
public:
///
- InsetIndex(InsetCommandParams const &);
+ InsetIndex(InsetCommandParams const &, bool same_id = false);
///
- virtual Inset * clone(Buffer const &) const {
- return new InsetIndex(params());
+ virtual Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetIndex(params(), same_id);
}
///
string const getScreenLabel() const;
class InsetPrintIndex : public InsetCommand {
public:
///
- InsetPrintIndex(InsetCommandParams const &);
+ InsetPrintIndex(InsetCommandParams const &, bool same_id = false);
///
- virtual Inset * clone(Buffer const &) const {
- return new InsetPrintIndex(params());
+ virtual Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetPrintIndex(params(), same_id);
}
/// Updates needed features for this inset.
void validate(LaTeXFeatures & features) const;
}
-Inset * InsetInfo::clone(Buffer const &) const
+Inset * InsetInfo::clone(Buffer const &, bool) const
{
return new InsetInfo(contents);
}
///
Inset::Code lyxCode() const;
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
static void closeInfoCB(FL_OBJECT *, long data);
private:
/* Label. Used to insert a label automatically */
-InsetLabel::InsetLabel(InsetCommandParams const & p)
+InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
: InsetCommand(p)
{}
class InsetLabel : public InsetCommand {
public:
///
- InsetLabel(InsetCommandParams const &);
+ InsetLabel(InsetCommandParams const &, bool same_id = false);
///
- virtual Inset * clone(Buffer const &) const {
- return new InsetLabel(params());
+ virtual Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetLabel(params(), same_id);
}
///
string const getScreenLabel() const { return getContents(); }
}
-Inset * InsetLatexAccent::clone(Buffer const &) const
+Inset * InsetLatexAccent::clone(Buffer const &, bool) const
{
return new InsetLatexAccent(contents);
}
///
bool directWrite() const;
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode()const;
///
}
-Inset * InsetList::clone(Buffer const &) const
+Inset * InsetList::clone(Buffer const &, bool same_id) const
{
InsetList * result = new InsetList;
- result->inset.init(&inset);
+ result->inset.init(&inset, same_id);
result->collapsed = collapsed;
+ if (same_id)
+ result->id_ = id_;
return result;
}
///
void write(Buffer const * buf, std::ostream & os) const;
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const { return Inset::FOOT_CODE; }
///
}
-Inset * InsetMarginal::clone(Buffer const &) const
+Inset * InsetMarginal::clone(Buffer const &, bool same_id) const
{
InsetMarginal * result = new InsetMarginal;
- result->inset.init(&inset);
+ result->inset.init(&inset, same_id);
result->collapsed = collapsed;
+ if (same_id)
+ result->id_ = id_;
return result;
}
///
InsetMarginal();
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const { return Inset::MARGIN_CODE; }
///
}
-Inset * InsetMinipage::clone(Buffer const &) const
+Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
{
InsetMinipage * result = new InsetMinipage;
- result->inset.init(&inset);
+ result->inset.init(&inset, same_id);
result->collapsed = collapsed;
result->pos_ = pos_;
result->inner_pos_ = inner_pos_;
result->height_ = height_;
result->width_ = width_;
+ if (same_id)
+ result->id_ = id_;
return result;
}
///
void read(Buffer const * buf, LyXLex & lex);
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
int ascent(BufferView *, LyXFont const &) const;
///
using std::ostream;
-InsetParent::InsetParent(InsetCommandParams const & p, Buffer const & bf)
+InsetParent::InsetParent(InsetCommandParams const & p, Buffer const & bf, bool)
: InsetCommand(p)
{
string const fn = p.getContents();
class InsetParent : public InsetCommand {
public:
///
- InsetParent(InsetCommandParams const &, Buffer const &);
+ InsetParent(InsetCommandParams const &, Buffer const &, bool same_id = false);
///
- virtual Inset * clone(Buffer const & buffer) const {
- return new InsetParent(params(), buffer);
+ virtual Inset * clone(Buffer const & buffer, bool same_id = false) const {
+ return new InsetParent(params(), buffer, same_id);
}
///
string const getScreenLabel() const;
}
-Inset * InsetQuotes::clone(Buffer const &) const
+Inset * InsetQuotes::clone(Buffer const &, bool) const
{
return new InsetQuotes(language, side, times);
}
///
void validate(LaTeXFeatures &) const;
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const;
private:
using std::ostream;
-InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
+InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf, bool)
: InsetCommand(p), isLatex(buf.isLatex())
{}
static string const & getName(int type);
///
- InsetRef(InsetCommandParams const &, Buffer const &);
+ InsetRef(InsetCommandParams const &, Buffer const &, bool same_id = false);
///
- virtual Inset * clone(Buffer const & buffer) const {
- return new InsetRef(params(), buffer);
+ virtual Inset * clone(Buffer const & buffer, bool same_id = false) const {
+ return new InsetRef(params(), buffer, same_id);
}
///
string const getScreenLabel() const;
}
-Inset * InsetSpecialChar::clone(Buffer const &) const
+Inset * InsetSpecialChar::clone(Buffer const &, bool) const
{
return new InsetSpecialChar(kind);
}
///
int docBook(Buffer const *, std::ostream &) const;
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const
{
#include "gettext.h"
#include "language.h"
#include "BufferView.h"
+#include "undo_funcs.h"
using std::ostream;
using std::ifstream;
rows = 1;
if (columns <= 0)
columns = 1;
- tabular.reset(new LyXTabular(this, rows,columns));
+ tabular.reset(new LyXTabular(this, rows, columns));
// for now make it always display as display() inset
// just for test!!!
the_locking_inset = 0;
}
-InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf)
+InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
+ bool same_id)
: buffer(&buf)
{
tabular.reset(new LyXTabular(this, *(tab.tabular)));
actrow = actcell = 0;
sel_cell_start = sel_cell_end = 0;
need_update = INIT;
+ if (same_id)
+ id_ = tab.id_;
}
}
-Inset * InsetTabular::clone(Buffer const & buf) const
+Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
{
- return new InsetTabular(*this, buf);
+ return new InsetTabular(*this, buf, same_id);
}
if (the_locking_inset &&
tabular->GetCellInset(actcell) != the_locking_inset)
{
-#warning Jürgen, why is this?
Inset * inset = tabular->GetCellInset(cell);
for (i = 0;
inset != the_locking_inset && i < tabular->rows();
}
}
} else {
- // copute baseline for actual row
+ // compute baseline for actual row
for (i = 0; i < actrow; ++i) {
baseline += tabular->GetDescentOfRow(i) +
tabular->GetAscentOfRow(i + 1) +
}
x -= ADD_TO_TABULAR_WIDTH;
x += width(bv, font);
- if (bv->text->status == LyXText::CHANGED_IN_DRAW) {
+ if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
int i = 0;
for(Inset * inset=owner(); inset; ++i)
inset = inset->owner();
}
if (the_locking_inset)
the_locking_inset->update(bv, font, reinit);
+ if (need_update < FULL &&
+ bv->text->status() == LyXText::NEED_MORE_REFRESH)
+ {
+ need_update = FULL;
+ }
switch (need_update) {
case INIT:
inset_y = 0;
setPos(bv, x, y);
sel_cell_start = sel_cell_end = actcell;
- bv->text->finishUndo();
+ finishUndo();
if (insetHit(bv, x, y) && (button != 3)) {
activateCellInsetAbs(bv, x, y, button);
}
lyxerr[Debug::INSETS] << "OK" << endl;
the_locking_inset = tabular->GetCellInset(actcell);
resetPos(bv);
- inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
- inset_y = cursor.y();
+ inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
+ inset_y = cursor_.y();
return true;
} else if (the_locking_inset && (the_locking_inset == inset)) {
lyxerr[Debug::INSETS] << "OK" << endl;
resetPos(bv);
- inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
- inset_y = cursor.y();
+ inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
+ inset_y = cursor_.y();
} else if (the_locking_inset) {
lyxerr[Debug::INSETS] << "MAYBE" << endl;
return the_locking_inset->lockInsetInInset(bv, inset);
case LFUN_CUT:
if (!copySelection(bv))
break;
- bv->text->setUndo(bv->buffer(), Undo::DELETE,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ setUndo(bv, Undo::DELETE,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
cutSelection();
updateLocal(bv, INIT, true);
break;
case LFUN_COPY:
if (!hasSelection())
break;
- bv->text->finishUndo();
+ finishUndo();
copySelection(bv);
break;
case LFUN_PASTESELECTION:
}
case LFUN_PASTE:
if (hasPasteBuffer()) {
- bv->text->setUndo(bv->buffer(), Undo::INSERT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ setUndo(bv, Undo::INSERT,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
pasteSelection(bv);
updateLocal(bv, INIT, true);
break;
void InsetTabular::getCursorPos(BufferView *,
int & x, int & y) const
{
- x = cursor.x() - top_x;
- y = cursor.y();
+ x = cursor_.x() - top_x;
+ y = cursor_.y();
}
if (isCursorVisible())
bv->hideLockedInsetCursor();
else
- bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+ bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
toggleCursorVisible();
}
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
- bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+ bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
if (show)
- bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
+ bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
setCursorVisible(true);
}
}
void InsetTabular::setPos(BufferView * bv, int x, int y) const
{
- cursor.y(0);
+ cursor_.y(0);
actcell = actrow = actcol = 0;
int ly = tabular->GetDescentOfRow(actrow);
// first search the right row
while((ly < y) && (actrow < tabular->rows())) {
- cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+ cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
tabular->GetAscentOfRow(actrow + 1) +
tabular->GetAdditionalHeight(actrow + 1));
++actrow;
- ly = cursor.y() + tabular->GetDescentOfRow(actrow);
+ ly = cursor_.y() + tabular->GetDescentOfRow(actrow);
}
actcell = tabular->GetCellNumber(actrow, actcol);
}
#endif
- cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
+ cursor_.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
resetPos(bv);
}
int cell = 0;
actrow = 0;
- cursor.y(0);
+ cursor_.y(0);
for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
if (tabular->IsLastCellInRow(cell)) {
- cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
+ cursor_.y(cursor_.y() + tabular->GetDescentOfRow(actrow) +
tabular->GetAscentOfRow(actrow + 1) +
tabular->GetAdditionalHeight(actrow + 1));
++actrow;
}
static int const offset = ADD_TO_TABULAR_WIDTH + 2;
int new_x = getCellXPos(actcell);
- int old_x = cursor.x();
+ int old_x = cursor_.x();
new_x += offset;
- cursor.x(new_x);
+ cursor_.x(new_x);
// cursor.x(getCellXPos(actcell) + offset);
if ((actcol < tabular->columns()-1) && scroll(false) &&
(tabular->GetWidthOfTabular() < bv->workWidth()-20))
} else if (the_locking_inset &&
(tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
{
- int xx = cursor.x() - offset + bv->text->getRealCursorX(bv);
+ int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
if (xx > (bv->workWidth()-20)) {
scroll(bv, -(xx - bv->workWidth() + 60));
updateLocal(bv, FULL, false);
scroll(bv, xx);
updateLocal(bv, FULL, false);
}
- } else if ((cursor.x() - offset) > 20 &&
- (cursor.x() - offset + tabular->GetWidthOfColumn(actcell))
+ } else if ((cursor_.x() - offset) > 20 &&
+ (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
> (bv->workWidth() - 20)) {
scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
updateLocal(bv, FULL, false);
- } else if ((cursor.x() - offset) < 20) {
- scroll(bv, 20 - cursor.x() + offset);
+ } else if ((cursor_.x() - offset) < 20) {
+ scroll(bv, 20 - cursor_.x() + offset);
updateLocal(bv, FULL, false);
} else if (scroll(false) && top_x > 20 &&
(top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
- scroll(bv, old_x - cursor.x());
+ scroll(bv, old_x - cursor_.x());
updateLocal(bv, FULL, false);
}
if ((!the_locking_inset ||
int y = 0;
if (old_locking_inset) {
old_locking_inset->getCursorPos(bv, x, y);
- x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
+ x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
}
if (activateCellInset(bv, x, 0))
return DISPATCHED;
int y = 0;
if (old_locking_inset) {
old_locking_inset->getCursorPos(bv, x, y);
- x -= cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
+ x -= cursor_.x() + tabular->GetBeginningOfTextInCell(actcell);
}
if (activateCellInset(bv, x, 0))
return DISPATCHED;
++actcell;
}
if (lock) {
- bool rtl = tabular->GetCellInset(actcell)->par->
+ bool rtl = tabular->GetCellInset(actcell)->paragraph()->
isRightToLeftPar(bv->buffer()->params);
activateCellInset(bv, 0, 0, 0, !rtl);
}
--actcell;
}
if (lock) {
- bool rtl = tabular->GetCellInset(actcell)->par->
+ bool rtl = tabular->GetCellInset(actcell)->paragraph()->
isRightToLeftPar(bv->buffer()->params);
activateCellInset(bv, 0, 0, 0, !rtl);
}
bool InsetTabular::Delete()
{
-#warning Is this func correctly named? Or should it be "deletable"?
+#warning Is this func correctly named? Or should it be "deletable"? (Lgb?)
+#warning I guess this could be 'deletable'! (Jug)
return true;
}
}
if (hasSelection()) {
bool frozen;
- bv->text->setUndo(bv->buffer(), Undo::EDIT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
- frozen = bv->text->undo_frozen;
+ setUndo(bv, Undo::EDIT,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
+ frozen = undo_frozen;
if (!frozen)
- bv->text->freezeUndo();
+ freezeUndo();
// apply the fontchange on the whole selection
int sel_row_start;
int sel_row_end;
}
}
if (!frozen)
- bv->text->unFreezeUndo();
+ unFreezeUndo();
updateLocal(bv, INIT, true);
}
if (the_locking_inset)
sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
}
- bv->text->setUndo(bv->buffer(), Undo::FINISH,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ setUndo(bv, Undo::FINISH,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
int row = tabular->row_of_cell(actcell);
int column = tabular->column_of_cell(actcell);
bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
int button)
{
- inset_x = cursor.x()
+ inset_x = cursor_.x()
- top_x + tabular->GetBeginningOfTextInCell(actcell);
- inset_y = cursor.y();
+ inset_y = cursor_.y();
return activateCellInset(bv, x - inset_x, y - inset_y, button);
}
bool InsetTabular::insetHit(BufferView *, int x, int) const
{
return (x + top_x)
- > (cursor.x() + tabular->GetBeginningOfTextInCell(actcell));
+ > (cursor_.x() + tabular->GetBeginningOfTextInCell(actcell));
}
int InsetTabular::getMaxWidth(BufferView * bv,
- UpdatableInset const * inset) const
+ UpdatableInset const * inset) const
{
int cell = tabular->cur_cell;
if (tabular->GetCellInset(cell) != inset) {
- cell = actcell;
- if (tabular->GetCellInset(cell) != inset) {
- lyxerr << "Actcell not equal to actual cell!" << std::endl;
- //raise(SIGSTOP);
- cell = -1;
- }
+ cell = actcell;
+ if (tabular->GetCellInset(cell) != inset) {
+
+ lyxerr << "Actcell not equal to actual cell!\n";
+ cell = -1;
+ }
}
int const n = tabular->GetNumberOfCells();
if (cell == -1) {
- cell = 0;
- for (; cell < n; ++cell) {
+ for (cell = 0; cell < n; ++cell) {
if (tabular->GetCellInset(cell) == inset)
break;
}
}
if (cell >= n) {
- return -1;
+ lyxerr << "Own inset not found, shouldn't really happen!\n";
+ return -1;
}
int w = getMaxWidthOfCell(bv, cell);
ecol = tabular->right_column_of_cell(sel_cell_end);
}
-/* Emacs:
- * Local variables:
- * tab-width: 4
- * End:
- * vi:set tabstop=4:
- */
+Paragraph * InsetTabular::getParFromID(int id) const
+{
+ Paragraph * result;
+ for(int i=0; i < tabular->rows(); ++i) {
+ for(int j=0; j < tabular->columns(); ++j) {
+ if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
+ return result;
+ }
+ }
+ return 0;
+}
+
+Paragraph * InsetTabular::firstParagraph() const
+{
+ if (the_locking_inset)
+ return the_locking_inset->firstParagraph();
+ return 0;
+}
+
+LyXCursor const & InsetTabular::cursor(BufferView * bv) const
+{
+ if (the_locking_inset)
+ return the_locking_inset->cursor(bv);
+ return Inset::cursor(bv);
+}
+
+
+Inset * InsetTabular::getInsetFromID(int id_arg) const
+{
+ if (id_arg == id())
+ return const_cast<InsetTabular *>(this);
+
+ Inset * result;
+ for(int i=0; i < tabular->rows(); ++i) {
+ for(int j=0; j < tabular->columns(); ++j) {
+ if ((result = tabular->GetCellInset(i, j)->getInsetFromID(id_arg)))
+ return result;
+ }
+ }
+ return 0;
+}
class Painter;
class BufferView;
class Buffer;
+class Paragraph;
class InsetTabular : public UpdatableInset {
public:
///
InsetTabular(Buffer const &, int rows = 1, int columns = 1);
///
- InsetTabular(InsetTabular const &, Buffer const &);
+ InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
///
~InsetTabular();
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
///
void read(Buffer const *, LyXLex &);
///
void scroll(BufferView *bv, int offset) const {
UpdatableInset::scroll(bv, offset);
}
+ ///
+ Paragraph * getParFromID(int id) const;
+ ///
+ Inset * getInsetFromID(int id) const;
+ ///
+ Paragraph * firstParagraph() const;
+ ///
+ LyXCursor const & cursor(BufferView *) const;
//
// Public structures and variables
///
Buffer const * buffer;
///
- mutable LyXCursor cursor;
+ mutable LyXCursor cursor_;
///
mutable unsigned int inset_x;
///
#include "gettext.h"
#include "lyxfunc.h"
#include "ParagraphParameters.h"
+#include "undo_funcs.h"
using std::ostream;
using std::ifstream;
}
-InsetText::InsetText(InsetText const & ins)
+InsetText::InsetText(InsetText const & ins, bool same_id)
: UpdatableInset()
{
par = 0;
- init(&ins);
+ init(&ins, same_id);
autoBreakRows = ins.autoBreakRows;
}
}
-void InsetText::init(InsetText const * ins)
+void InsetText::init(InsetText const * ins, bool same_id)
{
top_y = 0;
last_width = 0;
setParagraphData(ins->par);
autoBreakRows = ins->autoBreakRows;
drawFrame_ = ins->drawFrame_;
+ if (same_id)
+ id_ = ins->id_;
}
par->setInsetOwner(this);
frame_color = LColor::insetframe;
}
-Inset * InsetText::clone(Buffer const &) const
+Inset * InsetText::clone(Buffer const &, bool same_id) const
{
- InsetText * t = new InsetText(*this);
+ InsetText * t = new InsetText(*this, same_id);
return t;
}
resizeLyXText(bv);
need_update |= FULL;
old_max_width = getLyXText(bv)->width;
- bv->text->status = LyXText::CHANGED_IN_DRAW;
+ bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
}
top_x = int(x);
#if 1
}
getLyXText(bv)->refresh_y = 0;
- getLyXText(bv)->status = LyXText::UNCHANGED;
+ getLyXText(bv)->status(bv, LyXText::UNCHANGED);
if ((need_update != CURSOR_PAR) &&
((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
drawFrame(pain, cleared);
else if (need_update & CLEAR_FRAME)
clearFrame(pain, cleared);
x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
- if (bv->text->status==LyXText::CHANGED_IN_DRAW) {
+ if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
need_update |= INIT;
} else if (need_update != INIT)
need_update = NONE;
// update(bv, font, reinit);
return;
}
- if ((need_update & CURSOR_PAR) && t->status == LyXText::UNCHANGED &&
- the_locking_inset) {
+ if ((need_update & CURSOR_PAR) && (t->status() == LyXText::UNCHANGED) &&
+ the_locking_inset)
+ {
t->updateInset(bv, the_locking_inset);
}
- if (t->status == LyXText::NEED_MORE_REFRESH)
+ if (t->status() == LyXText::NEED_MORE_REFRESH)
need_update |= FULL;
#if 0
int y_temp = 0;
{
LyXText * t = getLyXText(bv);
need_update |= what;
- if (t->status == LyXText::NEED_MORE_REFRESH)
+ if (t->status() == LyXText::NEED_MORE_REFRESH)
need_update |= FULL;
- else if (t->status == LyXText::NEED_VERY_LITTLE_REFRESH)
+ else if (t->status() == LyXText::NEED_VERY_LITTLE_REFRESH)
need_update |= CURSOR_PAR;
// this to not draw a selection when we redraw all of it!
LyXText * t = getLyXText(bv);
t->fullRebreak(bv);
setUpdateStatus(bv, what);
- if (need_update != CURSOR || t->status != LyXText::UNCHANGED ||
+ if ((need_update != CURSOR) || (t->status() != LyXText::UNCHANGED) ||
t->selection.set())
+ {
bv->updateInset(this, mark_dirty);
+ }
bv->owner()->showState();
if (old_par != cpar(bv)) {
bv->owner()->setLayout(cpar(bv)->getLayout());
int tmp_y = (y < 0) ? 0 : y;
LyXText * t = getLyXText(bv);
- if (!checkAndActivateInset(bv, x, tmp_y, button)) {
+ if (!checkAndActivateInset(bv, x, tmp_y, button))
t->setCursorFromCoordinates(bv, x - drawTextXOffset,
- y + insetAscent);
- }
-
+ y + insetAscent);
t->selection.cursor = t->cursor;
- bv->text->finishUndo();
+ finishUndo();
showInsetCursor(bv);
updateLocal(bv, CURSOR, false);
* "auto_region_delete", which defaults to
* true (on). */
- bv->text->setUndo(bv->buffer(), Undo::INSERT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ LyXText * t = getLyXText(bv);
+ setUndo(bv, Undo::INSERT,
+ t->cursor.par(), t->cursor.par()->next());
bv->setState();
if (lyxrc.auto_region_delete) {
- if (getLyXText(bv)->selection.set()) {
- getLyXText(bv)->cutSelection(bv, false);
+ if (t->selection.set()) {
+ t->cutSelection(bv, false);
}
}
- getLyXText(bv)->clearSelection(bv);
+ t->clearSelection(bv);
for (string::size_type i = 0; i < arg.length(); ++i) {
if (greek_kb_flag) {
if (!math_insert_greek(bv, arg[i])) {
break;
// --- Cursor Movements -----------------------------------
case LFUN_RIGHTSEL:
- bv->text->finishUndo();
+ finishUndo();
moveRight(bv, false, true);
getLyXText(bv)->setSelection(bv);
updateLocal(bv, SELECTION, false);
break;
case LFUN_RIGHT:
result = moveRight(bv);
- bv->text->finishUndo();
+ finishUndo();
updateLocal(bv, CURSOR, false);
break;
case LFUN_LEFTSEL:
- bv->text->finishUndo();
+ finishUndo();
moveLeft(bv, false, true);
getLyXText(bv)->setSelection(bv);
updateLocal(bv, SELECTION, false);
break;
case LFUN_LEFT:
- bv->text->finishUndo();
+ finishUndo();
result = moveLeft(bv);
updateLocal(bv, CURSOR, false);
break;
case LFUN_DOWNSEL:
- bv->text->finishUndo();
+ finishUndo();
moveDown(bv);
getLyXText(bv)->setSelection(bv);
updateLocal(bv, SELECTION, false);
break;
case LFUN_DOWN:
- bv->text->finishUndo();
+ finishUndo();
result = moveDown(bv);
updateLocal(bv, CURSOR, false);
break;
case LFUN_UPSEL:
- bv->text->finishUndo();
+ finishUndo();
moveUp(bv);
getLyXText(bv)->setSelection(bv);
updateLocal(bv, SELECTION, false);
break;
case LFUN_UP:
- bv->text->finishUndo();
+ finishUndo();
result = moveUp(bv);
updateLocal(bv, CURSOR, false);
break;
case LFUN_HOME:
- bv->text->finishUndo();
+ finishUndo();
getLyXText(bv)->cursorHome(bv);
updateLocal(bv, CURSOR, false);
break;
updateLocal(bv, CURSOR, false);
break;
case LFUN_BACKSPACE: {
- bv->text->setUndo(bv->buffer(), Undo::DELETE,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
LyXText * t = getLyXText(bv);
-
- if (t->selection.set()) {
+ setUndo(bv, Undo::DELETE,
+ t->cursor.par(), t->cursor.par()->next());
+ if (t->selection.set())
t->cutSelection(bv);
- } else {
+ else
t->backspace(bv);
- }
-
updateLocal(bv, CURSOR_PAR, true);
}
break;
- case LFUN_DELETE:
- {
- bv->text->setUndo(bv->buffer(), Undo::DELETE,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ case LFUN_DELETE: {
LyXText * t = getLyXText(bv);
-
+ setUndo(bv, Undo::DELETE,
+ t->cursor.par(), t->cursor.par()->next());
if (t->selection.set()) {
t->cutSelection(bv);
} else {
}
break;
- case LFUN_CUT:
- bv->text->setUndo(bv->buffer(), Undo::DELETE,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
- getLyXText(bv)->cutSelection(bv);
+ case LFUN_CUT: {
+ LyXText * t = getLyXText(bv);
+ setUndo(bv, Undo::DELETE,
+ t->cursor.par(), t->cursor.par()->next());
+ t->cutSelection(bv);
updateLocal(bv, CURSOR_PAR, true);
- break;
+ }
+ break;
+
case LFUN_COPY:
- bv->text->finishUndo();
+ finishUndo();
getLyXText(bv)->copySelection(bv);
updateLocal(bv, CURSOR_PAR, false);
break;
updateLocal(bv, CURSOR_PAR, true);
break;
}
- case LFUN_PASTE:
+ case LFUN_PASTE: {
if (!autoBreakRows) {
if (CutAndPaste::nrOfParagraphs() > 1) {
break;
}
}
- bv->text->setUndo(bv->buffer(), Undo::INSERT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
- getLyXText(bv)->pasteSelection(bv);
+ LyXText * t = getLyXText(bv);
+ setUndo(bv, Undo::INSERT,
+ t->cursor.par(), t->cursor.par()->next());
+ t->pasteSelection(bv);
updateLocal(bv, CURSOR_PAR, true);
- break;
+ }
+ break;
+
case LFUN_BREAKPARAGRAPH:
if (!autoBreakRows)
return DISPATCHED;
getLyXText(bv)->breakParagraph(bv, 1);
updateLocal(bv, FULL, true);
break;
- case LFUN_BREAKLINE:
+
+ case LFUN_BREAKLINE: {
if (!autoBreakRows)
return DISPATCHED;
- bv->text->setUndo(bv->buffer(), Undo::INSERT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
- getLyXText(bv)->insertChar(bv, Paragraph::META_NEWLINE);
+ LyXText * t = getLyXText(bv);
+ setUndo(bv, Undo::INSERT,
+ t->cursor.par(), t->cursor.par()->next());
+ t->insertChar(bv, Paragraph::META_NEWLINE);
updateLocal(bv, CURSOR_PAR, true);
- break;
+ }
+ break;
+
case LFUN_LAYOUT:
// do not set layouts on non breakable textinsets
if (autoBreakRows) {
return the_locking_inset->insertInset(bv, inset);
return false;
}
- bv->text->setUndo(bv->buffer(), Undo::INSERT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ LyXText * t = getLyXText(bv);
+ setUndo(bv, Undo::INSERT,
+ t->cursor.par(), t->cursor.par()->next());
inset->setOwner(this);
hideInsetCursor(bv);
- getLyXText(bv)->insertInset(bv, inset);
+ t = getLyXText(bv);
+ t->insertInset(bv, inset);
#if 0
if ((cpar(bv)->GetChar(cpos(bv)) != Paragraph::META_INSET) ||
(cpar(bv)->GetInset(cpos(bv)) != inset))
- getLyXText(bv)->CursorLeft(bv);
+ t->CursorLeft(bv);
#endif
- bv->fitCursor(getLyXText(bv));
+ bv->fitCursor(t);
updateLocal(bv, CURSOR_PAR|CURSOR, true);
showInsetCursor(bv);
return true;
the_locking_inset->setFont(bv, font, toggleall, selectall);
return;
}
- if (getLyXText(bv)->selection.set()) {
- bv->text->setUndo(bv->buffer(), Undo::EDIT,
- bv->text->cursor.par()->previous(),
- bv->text->cursor.par()->next());
+ LyXText * t = getLyXText(bv);
+ if (t->selection.set()) {
+ setUndo(bv, Undo::EDIT,
+ t->cursor.par(), t->cursor.par()->next());
}
if (selectall)
selectAll(bv);
- getLyXText(bv)->setFont(bv, font, toggleall);
+#if 1
+ t->toggleFree(bv, font, toggleall);
+#else
+ t->setFont(bv, font, toggleall);
+#endif
if (selectall)
- getLyXText(bv)->clearSelection(bv);
- bv->fitCursor(getLyXText(bv));
- if (selectall || getLyXText(bv)->selection.set())
+ t->clearSelection(bv);
+ bv->fitCursor(t);
+ if (selectall || t->selection.set())
updateLocal(bv, FULL, true);
else
updateLocal(bv, CURSOR_PAR, true);
cleared = true;
need_update = FULL;
}
-/* Emacs:
- * Local variables:
- * tab-width: 4
- * End:
- * vi:set tabstop=4:
- */
+
+Paragraph * InsetText::getParFromID(int id) const
+{
+ Paragraph * result = par;
+ Paragraph * ires = 0;
+ while (result && result->id() != id) {
+ if ((ires = result->getParFromID(id)))
+ return ires;
+ result = result->next();
+ }
+ return result;
+}
+
+Paragraph * InsetText::firstParagraph() const
+{
+ Paragraph * result;
+ if (the_locking_inset)
+ if ((result = the_locking_inset->firstParagraph()))
+ return result;
+ return par;
+}
+
+LyXCursor const & InsetText::cursor(BufferView * bv) const
+{
+ if (the_locking_inset)
+ return the_locking_inset->cursor(bv);
+ return getLyXText(bv)->cursor;
+}
+
+Paragraph * InsetText::paragraph() const
+{
+ return par;
+}
+
+void InsetText::paragraph(Paragraph * p)
+{
+ par = p;
+#if 0
+ // we now have to update/redraw all instances
+ for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
+ delete (*cit).second;
+ (*cit).second = 0;
+ }
+#endif
+ // redraw myself when asked for
+ need_update |= INIT;
+}
+
+Inset * InsetText::getInsetFromID(int id_arg) const
+{
+ if (id_arg == id())
+ return const_cast<InsetText *>(this);
+
+ Paragraph * lp = par;
+
+ while(lp) {
+ for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
+ en = lp->inset_iterator_end();
+ it != en; ++it)
+ {
+ if ((*it)->id() == id_arg)
+ return *it;
+ Inset * in = (*it)->getInsetFromID(id_arg);
+ if (in)
+ return in;
+ }
+ lp = lp->next();
+ }
+ return 0;
+}
#include "inset.h"
#include "LString.h"
+#include "LColor.h"
+#include "paragraph.h"
#include "lyxcursor.h"
#include <boost/smart_ptr.hpp>
class BufferView;
class Buffer;
class LyXCursor;
-class Paragraph;
-class LColor;
class LyXText;
class LyXScreen;
+class Row;
/**
A text inset is like a TeX box to write full text
InsetText();
///
explicit
- InsetText(InsetText const &);
+ InsetText(InsetText const &, bool same_id = false);
///
~InsetText();
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
///
InsetText & operator=(InsetText const & it);
///
///
int getMaxWidth(BufferView *, UpdatableInset const *) const;
///
- void init(InsetText const * ins = 0);
+ void init(InsetText const * ins = 0, bool same_id = false);
///
void writeParagraphData(Buffer const *, std::ostream &) const;
///
void selectAll(BufferView *bv);
///
void clearSelection(BufferView *bv);
-
- Paragraph * par;
+ ///
+ Paragraph * getParFromID(int id) const;
+ ///
+ Inset * getInsetFromID(int id) const;
+ ///
+ Paragraph * firstParagraph() const;
+ ///
+ LyXCursor const & cursor(BufferView *) const;
+ ///
+ Paragraph * paragraph() const;
+ ///
+ void paragraph(Paragraph *);
///
mutable int need_update;
/* Private structures and variables */
///
+ Paragraph * par;
+ ///
mutable bool locked;
///
mutable int insetAscent;
}
-Inset * InsetTheorem::clone(Buffer const &) const
+Inset * InsetTheorem::clone(Buffer const &, bool) const
{
+#warning Is this inset used? If YES this is WRONG!!! (Jug)
InsetTheorem * result = new InsetTheorem;
result->collapsed = collapsed;
///
void write(Buffer const * buf, std::ostream & os) const;
///
- virtual Inset * clone(Buffer const &) const;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const { return Inset::THEOREM_CODE; }
///
class InsetTOC : public InsetCommand {
public:
///
- InsetTOC(InsetCommandParams const & p) : InsetCommand(p) {}
+ InsetTOC(InsetCommandParams const & p, bool same_id = false)
+ : InsetCommand(p, same_id) {}
///
- virtual Inset * clone(Buffer const &) const {
- return new InsetTOC(params());
+ virtual Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetTOC(params(), same_id);
}
///
string const getScreenLabel() const;
using std::ostream;
-InsetUrl::InsetUrl(InsetCommandParams const & p)
+InsetUrl::InsetUrl(InsetCommandParams const & p, bool)
: InsetCommand(p)
{}
public:
///
explicit
- InsetUrl(InsetCommandParams const &);
+ InsetUrl(InsetCommandParams const &, bool same_id = false);
///
- virtual Inset * clone(Buffer const &) const {
- return new InsetUrl(params());
+ virtual Inset * clone(Buffer const &, bool same_id = false) const {
+ return new InsetUrl(params(), same_id);
}
///
Inset::Code lyxCode() const { return Inset::URL_CODE; }
#include "FontLoader.h"
#include "TextCache.h"
#include "lyxfind.h"
+#include "undo_funcs.h"
using std::pair;
using std::make_pair;
argument = keyseq.getiso();
}
// Undo/Redo is a bit tricky for insets.
- if (action == LFUN_UNDO) {
+ if (action == LFUN_UNDO) {
+#ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
int slx;
int sly;
UpdatableInset * inset =
- owner->view()->theLockingInset();
+ owner->view()->theLockingInset()->getLockingInset();
+ int inset_id = inset->id();
inset->getCursorPos(owner->view(), slx, sly);
owner->view()->unlockInset(inset);
+#else
+ owner->view()->unlockInset(owner->view()->theLockingInset());
+#endif
owner->view()->menuUndo();
+#ifdef RETHINK_THIS_FOR_NOW_WE_LEAVE_ALL_UNLOCKED
+#if 0
if (TEXT()->cursor.par()->
isInset(TEXT()->cursor.pos())) {
inset = static_cast<UpdatableInset*>(
} else {
inset = 0;
}
+#else
+ inset = static_cast<UpdatableInset *>(owner->view()->buffer()->getInsetFromID(inset_id));
+#endif
if (inset)
inset->edit(owner->view(),slx,sly,0);
+#endif
return string();
} else if (action == LFUN_REDO) {
int slx;
// Move cursor so that successive C-s 's will not stand in place.
if (action == LFUN_WORDFINDFORWARD )
TEXT()->cursorRightOneWord(owner->view());
- TEXT()->finishUndo();
+ finishUndo();
moveCursorUpdate(true, false);
// ??? Needed ???
#endif
#include "lyxfont.h"
-#include "undo.h"
#include "lyxcursor.h"
#include "paragraph.h"
#include "layout.h"
///
enum text_status {
///
- UNCHANGED,
+ UNCHANGED = 0,
///
- NEED_MORE_REFRESH,
+ CHANGED_IN_DRAW = 1,
///
- NEED_VERY_LITTLE_REFRESH,
+ NEED_VERY_LITTLE_REFRESH = 2,
///
- CHANGED_IN_DRAW
+ NEED_MORE_REFRESH = 3
};
///
enum word_location {
mutable Row * refresh_row;
///
int refresh_pos;
-
+
+ /// give and set the LyXText status
+ text_status status() const;
+ void status(BufferView *, text_status) const;
+
+private:
/** wether the screen needs a refresh,
starting with refresh_y
*/
- mutable text_status status;
+ mutable text_status status_;
+public:
/** returns a pointer to the row near the specified y-coordinate
(relative to the whole text). y is set to the real beginning
of this row
LyXCursor const & to,
LyXText::TextCase action);
///
- void transposeChars(BufferView const &);
+ void transposeChars(BufferView &);
/** returns a printed row in a pixmap. The y value is needed to
decide, wether it is selected text or not. This is a strange
int numberOfCell(Paragraph * par,
Paragraph::size_type pos) const;
///
- Paragraph * getParFromID(int id);
-
- // undo functions
- /// returns false if no undo possible
- bool textUndo(BufferView *);
- /// returns false if no redo possible
- bool textRedo(BufferView *);
- /// used by TextUndo/TextRedo
- bool textHandleUndo(BufferView *, Undo * undo);
- /// makes sure the next operation will be stored
- void finishUndo();
- /// this is dangerous and for internal use only
- void freezeUndo();
- /// this is dangerous and for internal use only
- void unFreezeUndo();
- /// the flag used by FinishUndo();
- mutable bool undo_finished;
- /// a flag
- bool undo_frozen;
- ///
- void setUndo(Buffer *, Undo::undo_kind kind,
- Paragraph const * before,
- Paragraph const * end) const;
- ///
- void setRedo(Buffer *, Undo::undo_kind kind,
- Paragraph const * before,
- Paragraph const * end);
- ///
- Undo * createUndo(Buffer *, Undo::undo_kind kind,
- Paragraph const * before,
- Paragraph const * end) const;
- /// for external use in lyx_cb.C
- void setCursorParUndo(Buffer *);
+ Paragraph * getParFromID(int id) const;
+
///
void removeTableRow(LyXCursor & cursor) const;
///
void deleteEmptyParagraphMechanism(BufferView *,
LyXCursor const & old_cursor) const;
+public:
/** Updates all counters starting BEHIND the row. Changed paragraphs
* with a dynamic left margin will be rebroken. */
void updateCounters(BufferView *, Row * row) const;
+private:
///
void setCounter(Buffer const *, Paragraph * par) const;
///
void charInserted();
+public:
//
// special owner functions
///
Paragraph * ownerParagraph() const;
//
Paragraph * ownerParagraph(Paragraph *) const;
+ // set it searching first for the right owner using the paragraph id
+ Paragraph * ownerParagraph(int id, Paragraph *) const;
};
}
-Inset * InsetFormula::clone(Buffer const &) const
+Inset * InsetFormula::clone(Buffer const &, bool) const
{
return new InsetFormula(*this);
}
int docBook(std::ostream &) const;
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
///
void validate(LaTeXFeatures & features) const;
///
#include "math_deliminset.h"
#include "support/lyxlib.h"
#include "mathed/support.h"
+#include "undo_funcs.h"
using std::endl;
using std::ostream;
LyXText * lt = bv->getLyXText();
bv->beforeChange(lt);
- lt->finishUndo();
+ finishUndo();
if (!bv->insertInset(new_inset)) {
delete new_inset;
return false;
///
virtual void validate(LaTeXFeatures &) const;
///
- virtual Inset * clone(Buffer const &) const = 0;
+ virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
///
virtual Inset::Code lyxCode() const;
///
}
-Inset * InsetFormulaMacro::clone(Buffer const &) const
+Inset * InsetFormulaMacro::clone(Buffer const &, bool) const
{
return new InsetFormulaMacro(*this);
}
int docBook(std::ostream &) const;
///
- Inset * clone(Buffer const &) const;
+ Inset * clone(Buffer const &, bool same_id = false) const;
///
Inset::Code lyxCode() const;
///
}
-Paragraph::Paragraph(Paragraph const & lp)
- : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
+Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
+ : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
{
- for (int i = 0; i < 10; ++i) setCounter(i , 0);
+ for (int i = 0; i < 10; ++i)
+ setCounter(i , 0);
enumdepth = 0;
itemdepth = 0;
next_ = 0;
insetlist = lp.insetlist;
for (InsetList::iterator it = insetlist.begin();
- it != insetlist.end(); ++it) {
- it->inset = it->inset->clone(*current_view->buffer());
+ it != insetlist.end(); ++it)
+ {
+ it->inset = it->inset->clone(*current_view->buffer(), same_ids);
}
}
}
-Inset * Paragraph::InInset()
+Inset * Paragraph::InInset() const
{
return pimpl_->inset_owner;
}
return pimpl_->params;
}
+Paragraph * Paragraph::getParFromID(int id) const
+{
+ return pimpl_->getParFromID(id);
+}
explicit
Paragraph(Paragraph * par);
///
- Paragraph(Paragraph const &);
+ Paragraph(Paragraph const &, bool same_ids = false);
/// the destructor removes the new paragraph from the list
~Paragraph();
proof environment */
int getEndLabel(BufferParams const &) const;
///
- Inset * InInset();
+ Inset * InInset() const;
///
void setInsetOwner(Inset * i);
///
/// returns -1 if inset not found
int getPositionOfInset(Inset * inset) const;
+ /// some good comment here John?
+ Paragraph * getParFromID(int id) const;
+
///
int stripLeadingSpaces(LyXTextClassList::size_type tclass);
}
-Paragraph::Pimpl::Pimpl(Paragraph::Pimpl const & p, Paragraph * owner)
+Paragraph::Pimpl::Pimpl(Paragraph::Pimpl const & p, Paragraph * owner,
+ bool same_ids)
: params(p.params), owner_(owner)
{
inset_owner = p.inset_owner;
text = p.text;
fontlist = p.fontlist;
+ if (same_ids)
+ id_ = p.id_;
+ else
+ id_ = paragraph_id++;
}
}
+Paragraph * Paragraph::Pimpl::getParFromID(int id) const
+{
+ InsetList::const_iterator lend = owner_->insetlist.end();
+ Paragraph * result;
+ for (InsetList::const_iterator cit = owner_->insetlist.begin();
+ cit != lend; ++cit)
+ {
+ if ((result = cit->inset->getParFromID(id)))
+ return result;
+ }
+ return 0;
+}
+
///
Pimpl(Paragraph * owner);
/// Copy constructor
- Pimpl(Pimpl const &, Paragraph * owner);
+ Pimpl(Pimpl const &, Paragraph * owner, bool same_ids = false);
///
Paragraph::size_type size() const {
return text.size();
size_type & i,
int & column, value_type const c);
///
+ Paragraph * getParFromID(int id) const;
+ ///
unsigned int id_;
///
static unsigned int paragraph_id;
// y1 is now the real beginning of row on the screen
while (row != 0 && y < y2) {
- LyXText::text_status st = bv->text->status;
+ LyXText::text_status st = bv->text->status();
do {
- bv->text->status = st;
+ bv->text->status(bv, st);
text->getVisibleRow(bv, y + y_offset,
x_offset, row, y + text->first);
- } while (bv->text->status == LyXText::CHANGED_IN_DRAW);
- bv->text->status = st;
+ } while (bv->text->status() == LyXText::CHANGED_IN_DRAW);
+ bv->text->status(bv, st);
y += row->height();
row = row->next();
}
if (((y + row->height()) > 0) &&
((y - row->height()) <= static_cast<int>(owner.height()))) {
// ok there is something visible
- LyXText::text_status st = bv->text->status;
+ LyXText::text_status st = bv->text->status();
do {
- bv->text->status = st;
+ bv->text->status(bv, st);
text->getVisibleRow(bv, y, x_offset, row,
y + text->first);
- } while (bv->text->status == LyXText::CHANGED_IN_DRAW);
- bv->text->status = st;
+ } while (bv->text->status() == LyXText::CHANGED_IN_DRAW);
+ bv->text->status(bv, st);
}
force_clear = false;
}
void LyXScreen::update(LyXText * text, BufferView * bv,
int y_offset, int x_offset)
{
- switch (text->status) {
+ switch (text->status()) {
case LyXText::NEED_MORE_REFRESH:
{
int const y = max(int(text->refresh_y - text->first), 0);
drawFromTo(text, bv, y, owner.height(), y_offset, x_offset);
text->refresh_y = 0;
- text->status = LyXText::UNCHANGED;
+ text->status(bv, LyXText::UNCHANGED);
expose(0, y, owner.workWidth(), owner.height() - y);
}
break;
// ok I will update the current cursor row
drawOneRow(text, bv, text->refresh_row, text->refresh_y,
y_offset, x_offset);
- text->status = LyXText::UNCHANGED;
+ text->status(bv, LyXText::UNCHANGED);
expose(0, text->refresh_y - text->first + y_offset,
owner.workWidth(), text->refresh_row->height());
}
}
}
par->copyIntoMinibuffer(*owner_->bufferOwner(), i);
- inset->par->insertFromMinibuffer(inset->par->size());
+ inset->paragraph()->insertFromMinibuffer(inset->paragraph()->size());
}
delete par;
Reinit();
ret += TeXCellPreamble(os, cell);
InsetText * inset = GetCellInset(cell);
- bool rtl = inset->par->isRightToLeftPar(buf->params) &&
- inset->par->size() > 0 && GetPWidth(cell).empty();
+ bool rtl = inset->paragraph()->isRightToLeftPar(buf->params) &&
+ inset->paragraph()->size() > 0 && GetPWidth(cell).empty();
if (rtl)
os << "\\R{";
LyXTabular::BoxType LyXTabular::UseParbox(int cell) const
{
- Paragraph * par = GetCellInset(cell)->par;
+ Paragraph * par = GetCellInset(cell)->paragraph();
for (; par; par = par->next()) {
for (int i = 0; i < par->size(); ++i) {
#include "BufferView.h"
#include "language.h"
#include "ParagraphParameters.h"
+#include "undo_funcs.h"
using std::max;
using std::min;
tmpinset->draw(bview, font, offset+row->baseline(), x,
cleared);
#ifdef SEEMS_TO_BE_NOT_NEEDED
- if (status == CHANGED_IN_DRAW) {
+ if (status_ == CHANGED_IN_DRAW) {
UpdateInset(bview, tmpinset);
- status = CHANGED_IN_DRAW;
+ status(bview, CHANGED_IN_DRAW);
}
#endif
}
&& layout.labeltype!= LABEL_SENSITIVE)
return;
- setUndo(bview->buffer(), Undo::INSERT,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::INSERT,cursor.par(),cursor.par()->next());
// Always break behind a space
//
cursorLeft(bview);
}
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_row = cursor.row();
refresh_y = cursor.y() - cursor.row()->baseline();
* same Paragraph one to the right and make a rebreak */
void LyXText::insertChar(BufferView * bview, char c)
{
- setUndo(bview->buffer(), Undo::INSERT,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::INSERT,
+ cursor.par(), cursor.par()->next());
// When the free-spacing option is set for the current layout,
// disable the double-space checking
y -= row->previous()->height();
refresh_y = y;
refresh_row = row->previous();
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
breakAgainOneRow(bview, row);
refresh_row = row;
refresh_x = cursor.x();
refresh_pos = cursor.pos();
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
breakAgainOneRow(bview, row);
// will the cursor be in another row now?
if (rowLast(row) <= cursor.pos() + 1 && row->next()) {
int const tmpheight = row->height();
setHeightOfRow(bview, row);
if (tmpheight == row->height())
- status = LyXText::NEED_VERY_LITTLE_REFRESH;
+ status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
else
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
current_font = rawtmpfont;
real_current_font = realtmpfont;
{
lyx::Assert(from <= to);
- setUndo(bview->buffer(), Undo::FINISH,
- from.par()->previous(), to.par()->next());
+ setUndo(bview, Undo::FINISH,
+ from.par(), to.par()->next());
Paragraph::size_type pos = from.pos();
Paragraph * par = from.par();
if (to.row() != from.row()) {
refresh_y = from.y() - from.row()->baseline();
refresh_row = from.row();
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
}
}
-void LyXText::transposeChars(BufferView const & bview)
+void LyXText::transposeChars(BufferView & bview)
{
Paragraph * tmppar = cursor.par();
- setUndo(bview.buffer(), Undo::FINISH,
- tmppar->previous(), tmppar->next());
+ setUndo(&bview, Undo::FINISH,
+ tmppar, tmppar->next());
Paragraph::size_type tmppos = cursor.pos();
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
LyXCursor tmpcursor = cursor;
cursor = old_cursor; // to make sure undo gets the right cursor position
- setUndo(bview->buffer(), Undo::DELETE,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::DELETE,
+ cursor.par(), cursor.par()->next());
cursor = tmpcursor;
backspace(bview);
}
if (cursor.row()->height() != tmpheight) {
refresh_y = cursor.y() - cursor.row()->baseline();
refresh_row = cursor.row();
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
}
return;
}
}
if (cursor.par()->previous()) {
- setUndo(bview->buffer(), Undo::DELETE,
- cursor.par()->previous()->previous(),
+ setUndo(bview, Undo::DELETE,
+ cursor.par()->previous(),
cursor.par()->next());
}
if (cursor.pos())
cursor.pos(cursor.pos() - 1);
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_row = cursor.row();
refresh_y = cursor.y() - cursor.row()->baseline();
} else {
/* this is the code for a normal backspace, not pasting
* any paragraphs */
- setUndo(bview->buffer(), Undo::DELETE,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::DELETE,
+ cursor.par(), cursor.par()->next());
// We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite,
refresh_y = y;
refresh_row = tmprow;
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
setCursor(bview, cursor.par(), cursor.pos(),
false, cursor.boundary());
//current_font = rawtmpfont;
refresh_y = y;
refresh_row = row;
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
breakAgainOneRow(bview, row);
// will the cursor be in another row now?
int const tmpheight = row->height();
setHeightOfRow(bview, row);
if (tmpheight == row->height())
- status = LyXText::NEED_VERY_LITTLE_REFRESH;
+ status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
else
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_y = y;
refresh_row = row;
setCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
#include "layout.h"
#include "LyXView.h"
#include "support/textutils.h"
-#include "undo.h"
+#include "undo_funcs.h"
#include "buffer.h"
#include "bufferparams.h"
#include "lyx_gui_misc.h"
LyXText::LyXText(BufferView * bv)
: number_of_rows(0), height(0), width(0), first(0),
bv_owner(bv), inset_owner(0), the_locking_inset(0),
- need_break_row(0), refresh_y(0), status(LyXText::UNCHANGED),
- undo_finished(true), undo_frozen(false), firstrow(0), lastrow(0),
- copylayouttype(0)
+ need_break_row(0), refresh_y(0), status_(LyXText::UNCHANGED),
+ firstrow(0), lastrow(0), copylayouttype(0)
{}
LyXText::LyXText(InsetText * inset)
: number_of_rows(0), height(0), width(0), first(0),
bv_owner(0), inset_owner(inset), the_locking_inset(0),
- need_break_row(0), refresh_y(0), status(LyXText::UNCHANGED),
- undo_finished(true), undo_frozen(false), firstrow(0), lastrow(0),
- copylayouttype(0)
+ need_break_row(0), refresh_y(0), status_(LyXText::UNCHANGED),
+ firstrow(0), lastrow(0), copylayouttype(0)
{}
-
void LyXText::init(BufferView * bview)
{
if (firstrow)
endpar = endpar->next(); // because of parindents etc.
}
- setUndo(bview->buffer(), Undo::EDIT,
- sstart_cur.par()->previous(),
- undoendpar);
+ setUndo(bview, Undo::EDIT,
+ sstart_cur.par(), undoendpar);
/* ok we have a selection. This is always between sstart_cur
* and sel_end cursor */
endpar = endpar->next(); // because of parindents etc.
}
- setUndo(bview->buffer(), Undo::EDIT,
- selection.start.par()->previous(),
- undoendpar);
+ setUndo(bview, Undo::EDIT,
+ selection.start.par(), undoendpar);
LyXCursor tmpcursor = cursor; // store the current cursor
endpar = endpar->next(); // because of parindents etc.
}
- setUndo(bview->buffer(), Undo::EDIT,
- selection.start.par()->previous(),
- undoendpar);
+ setUndo(bview, Undo::EDIT,
+ selection.start.par(), undoendpar);
LyXCursor tmpcursor = cursor; // store the current cursor
// ok we have a selection. This is always between sel_start_cursor
// and sel_end cursor
- setUndo(bview->buffer(), Undo::EDIT,
- selection.start.par()->previous(),
+ setUndo(bview, Undo::EDIT,
+ selection.start.par(),
selection.end.par()->next());
freezeUndo();
cursor = selection.start;
#endif
// we can set the refreshing parameters now
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_y = y;
refresh_row = tmprow;
setCursor(bview, cur.par(), cur.pos(), false, cursor.boundary());
}
#endif
// we can set the refreshing parameters now
- if (status == LyXText::UNCHANGED || y < refresh_y) {
+ if (status_ == LyXText::UNCHANGED || y < refresh_y) {
refresh_y = y;
refresh_row = tmprow;
}
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
setCursor(bview, cur.par(), cur.pos());
}
#endif
// we can set the refreshing parameters now
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_y = y;
refresh_row = tmprow->previous(); /* the real refresh row will
be deleted, so I store
tmprow = tmprow->next();
tmppar = tmppar->next();
}
- } while (tmppar != endpar);
+ } while (tmppar && tmppar != endpar);
// this is because of layout changes
if (refresh_row) {
endpar = endpar->next(); // because of parindents etc.
}
- setUndo(bview->buffer(), Undo::EDIT,
- selection.start.par()->previous(),
- undoendpar);
+ setUndo(bview, Undo::EDIT, selection.start.par(), undoendpar);
Paragraph * tmppar = selection.end.par();
while (tmppar != selection.start.par()->previous()) {
setCursor(bview, tmppar, 0);
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_row = cursor.row();
refresh_y = cursor.y() - cursor.row()->baseline();
cursor.par()->params().lineTop(line_top);
{
if (!cursor.par()->insertInsetAllowed(inset))
return;
- setUndo(bview->buffer(), Undo::INSERT,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::INSERT,
+ cursor.par(), cursor.par()->next());
cursor.par()->insertInset(cursor.pos(), inset);
insertChar(bview, Paragraph::META_INSET); /* just to rebreak and refresh correctly.
* The character will not be inserted a
endpar = endpar->next(); // because of parindents etc.
}
- setUndo(bview->buffer(), Undo::DELETE,
- selection.start.par()->previous(),
- undoendpar);
+ setUndo(bview, Undo::DELETE,
+ selection.start.par(), undoendpar);
// there are two cases: cut only within one paragraph or
// more than one paragraph
selection.start.pos(selection.start.pos() + 1);
CutAndPaste::copySelection(selection.start.par(), selection.end.par(),
- selection.start.pos(), selection.end.pos(),
- bview->buffer()->params.textclass);
+ selection.start.pos(), selection.end.pos(),
+ bview->buffer()->params.textclass);
}
if (!CutAndPaste::checkPastePossible(cursor.par()))
return;
- setUndo(bview->buffer(), Undo::INSERT,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::INSERT,
+ cursor.par(), cursor.par()->next());
Paragraph * endpar;
Paragraph * actpar = cursor.par();
void LyXText::replaceSelectionWithString(BufferView * bview,
string const & str)
{
- setCursorParUndo(bview->buffer());
+ setCursorParUndo(bview);
freezeUndo();
if (!selection.set()) { // create a dummy selection
Paragraph::size_type pos = cursor.pos();
Paragraph * endpar = cursor.par()->next();
- setCursorParUndo(bview->buffer());
+ setCursorParUndo(bview);
bool isEnvironment =
textclasslist.Style(bview->buffer()->params.textclass,
y -= row->previous()->height();
refresh_y = y;
refresh_row = row->previous();
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
breakAgain(bview, row->previous());
breakAgain(bview, row);
if (row->height() == tmpheight && rowLast(row) == tmplast)
- status = LyXText::NEED_VERY_LITTLE_REFRESH;
+ status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
else
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
// check the special right address boxes
if (textclasslist.Style(bview->buffer()->params.textclass,
Paragraph::size_type pos,
bool setfont, bool boundary) const
{
- setCursor(bview, cursor, par, pos, boundary);
- if (setfont)
- setCurrentFont(bview);
+ InsetText * it = static_cast<InsetText *>(par->InInset());
+ if (it && (it != inset_owner)) {
+ it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont,
+ boundary);
+ } else {
+ setCursor(bview, cursor, par, pos, boundary);
+ if (setfont)
+ setCurrentFont(bview);
+ }
}
// ok, we will delete anything
// make sure that you do not delete any environments
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
deleted = true;
if (old_cursor.row()->previous()) {
endpar = endpar->next();
}
}
- setUndo(bview->buffer(), Undo::DELETE,
- old_cursor.par()->previous(),
+ setUndo(bview, Undo::DELETE,
+ old_cursor.par(),
endpar);
cursor = tmpcursor;
endpar = endpar->next();
}
}
- setUndo(bview->buffer(), Undo::DELETE,
- old_cursor.par()->previous(),
+ setUndo(bview, Undo::DELETE,
+ old_cursor.par(),
endpar);
cursor = tmpcursor;
}
-Paragraph * LyXText::getParFromID(int id)
+Paragraph * LyXText::getParFromID(int id) const
{
+ if (id < 0)
+ return 0;
Paragraph * result = firstParagraph();
- while (result && result->id() != id)
+ Paragraph * ires = 0;
+ while (result && result->id() != id) {
+ if ((ires = result->getParFromID(id)))
+ return ires;
result = result->next();
- return result;
-}
-
-
-// undo functions
-bool LyXText::textUndo(BufferView * bview)
-{
- if (inset_owner)
- return false;
- // returns false if no undo possible
- Undo * undo = bview->buffer()->undostack.pop();
- if (undo) {
- finishUndo();
- if (!undo_frozen)
- bview->buffer()->redostack
- .push(createUndo(bview->buffer(), undo->kind,
- getParFromID(undo->number_of_before_par),
- getParFromID(undo->number_of_behind_par)));
- }
- return textHandleUndo(bview, undo);
-}
-
-
-bool LyXText::textRedo(BufferView * bview)
-{
- if (inset_owner)
- return false;
- // returns false if no redo possible
- Undo * undo = bview->buffer()->redostack.pop();
- if (undo) {
- finishUndo();
- if (!undo_frozen)
- bview->buffer()->undostack
- .push(createUndo(bview->buffer(), undo->kind,
- getParFromID(undo->number_of_before_par),
- getParFromID(undo->number_of_behind_par)));
- }
- return textHandleUndo(bview, undo);
-}
-
-
-bool LyXText::textHandleUndo(BufferView * bview, Undo * undo)
-{
- if (inset_owner)
- return false;
- // returns false if no undo possible
- bool result = false;
- if (undo) {
- Paragraph * before =
- getParFromID(undo->number_of_before_par);
- Paragraph * behind =
- getParFromID(undo->number_of_behind_par);
- Paragraph * tmppar;
- Paragraph * tmppar2;
- Paragraph * endpar;
- Paragraph * tmppar5;
-
- // if there's no before take the beginning
- // of the document for redoing
- if (!before)
- setCursorIntern(bview, firstParagraph(), 0);
-
- // replace the paragraphs with the undo informations
-
- Paragraph * tmppar3 = undo->par;
- undo->par = 0; // otherwise the undo destructor would delete the paragraph
- Paragraph * tmppar4 = tmppar3;
-
- if (tmppar4) {
- while (tmppar4->next())
- tmppar4 = tmppar4->next();
- } // get last undo par
-
- // now remove the old text if there is any
- if (before != behind || (!behind && !before)) {
- if (before)
- tmppar5 = before->next();
- else
- tmppar5 = ownerParagraph();
- tmppar2 = tmppar3;
- while (tmppar5 && tmppar5 != behind) {
- tmppar = tmppar5;
- tmppar5 = tmppar5->next();
- // a memory optimization for edit: Only layout information
- // is stored in the undo. So restore the text informations.
- if (undo->kind == Undo::EDIT) {
- tmppar2->setContentsFromPar(tmppar);
- tmppar->clearContents();
- tmppar2 = tmppar2->next();
- }
- }
- }
-
- // put the new stuff in the list if there is one
- if (tmppar3){
- if (before)
- before->next(tmppar3);
- else
- ownerParagraph(tmppar3);
- tmppar3->previous(before);
- } else {
- if (!before)
- ownerParagraph(behind);
- }
- if (tmppar4) {
- tmppar4->next(behind);
- if (behind)
- behind->previous(tmppar4);
- }
-
-
- // Set the cursor for redoing
- if (before) {
- setCursorIntern(bview, before, 0);
- }
-
- // calculate the endpar for redoing the paragraphs.
- if (behind) {
- endpar = behind->next();
- } else
- endpar = behind;
-
- tmppar = getParFromID(undo->number_of_cursor_par);
- redoParagraphs(bview, cursor, endpar);
- if (tmppar){
- setCursorIntern(bview, tmppar, undo->cursor_pos);
- updateCounters(bview, cursor.row());
- }
- result = true;
- delete undo;
}
- finishUndo();
return result;
}
-
-void LyXText::finishUndo()
-{
- if (inset_owner)
- return;
- // makes sure the next operation will be stored
- undo_finished = true;
-}
-
-
-void LyXText::freezeUndo()
-{
- if (inset_owner)
- return;
- // this is dangerous and for internal use only
- undo_frozen = true;
-}
-
-
-void LyXText::unFreezeUndo()
-{
- if (inset_owner)
- return;
- // this is dangerous and for internal use only
- undo_frozen = false;
-}
-
-
-void LyXText::setUndo(Buffer * buf, Undo::undo_kind kind,
- Paragraph const * before,
- Paragraph const * behind) const
-{
- if (inset_owner)
- return;
- if (!undo_frozen)
- buf->undostack.push(createUndo(buf, kind, before, behind));
- buf->redostack.clear();
-}
-
-
-void LyXText::setRedo(Buffer * buf, Undo::undo_kind kind,
- Paragraph const * before, Paragraph const * behind)
-{
- if (inset_owner)
- return;
- buf->redostack.push(createUndo(buf, kind, before, behind));
-}
-
-
-Undo * LyXText::createUndo(Buffer * buf, Undo::undo_kind kind,
- Paragraph const * before,
- Paragraph const * behind) const
-{
- if (inset_owner)
- return 0;
-
- int before_number = -1;
- int behind_number = -1;
- if (before)
- before_number = before->id();
- if (behind)
- behind_number = behind->id();
- // Undo::EDIT and Undo::FINISH are
- // always finished. (no overlapping there)
- // overlapping only with insert and delete inside one paragraph:
- // Nobody wants all removed character
- // appear one by one when undoing.
- // EDIT is special since only layout information, not the
- // contents of a paragaph are stored.
- if (!undo_finished && (kind != Undo::EDIT) && (kind != Undo::FINISH)){
- // check wether storing is needed
- if (!buf->undostack.empty() &&
- buf->undostack.top()->kind == kind &&
- buf->undostack.top()->number_of_before_par == before_number &&
- buf->undostack.top()->number_of_behind_par == behind_number ){
- // no undo needed
- return 0;
- }
- }
- // create a new Undo
- Paragraph * undopar;
-
- Paragraph * start = 0;
- Paragraph * end = 0;
-
- if (before)
- start = const_cast<Paragraph*>(before->next());
- else
- start = firstParagraph();
- if (behind)
- end = const_cast<Paragraph*>(behind->previous());
- else {
- end = firstParagraph();
- while (end->next())
- end = end->next();
- }
- if (start && end && (start != end->next()) &&
- ((before != behind) || (!before && !behind))) {
- Paragraph * tmppar = start;
- Paragraph * tmppar2 = new Paragraph(*tmppar);
- tmppar2->id(tmppar->id());
-
- // a memory optimization: Just store the layout information
- // when only edit
- if (kind == Undo::EDIT){
- //tmppar2->text.clear();
- tmppar2->clearContents();
- }
-
- undopar = tmppar2;
-
- while (tmppar != end && tmppar->next()) {
- tmppar = tmppar->next();
- tmppar2->next(new Paragraph(*tmppar));
- tmppar2->next()->id(tmppar->id());
- // a memory optimization: Just store the layout
- // information when only edit
- if (kind == Undo::EDIT){
- //tmppar2->next->text.clear();
- tmppar2->clearContents();
- }
- tmppar2->next()->previous(tmppar2);
- tmppar2 = tmppar2->next();
- }
- tmppar2->next(0);
- } else
- undopar = 0; // nothing to replace (undo of delete maybe)
-
- int cursor_par = cursor.par()->id();
- int cursor_pos = cursor.pos();
-
- Undo * undo = new Undo(kind,
- before_number, behind_number,
- cursor_par, cursor_pos,
- undopar);
-
- undo_finished = false;
- return undo;
-}
-
-
-void LyXText::setCursorParUndo(Buffer * buf)
-{
- if (inset_owner)
- return;
- setUndo(buf, Undo::FINISH,
- cursor.par()->previous(),
- cursor.par()->next());
-}
-
-
void LyXText::toggleAppendix(BufferView * bview)
{
Paragraph * par = cursor.par();
par->params().startOfAppendix(start);
// we can set the refreshing parameters now
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_y = 0;
refresh_row = 0; // not needed for full update
updateCounters(bview, 0);
Paragraph * LyXText::ownerParagraph() const
{
if (inset_owner)
- return inset_owner->par;
+ return inset_owner->paragraph();
return bv_owner->buffer()->paragraph;
}
Paragraph * LyXText::ownerParagraph(Paragraph * p) const
{
if (inset_owner)
- inset_owner->par = p;
+ inset_owner->paragraph(p);
else
bv_owner->buffer()->paragraph = p;
return 0;
}
+
+Paragraph * LyXText::ownerParagraph(int id, Paragraph * p) const
+{
+ Paragraph * op = getParFromID(id);
+ if (op && op->InInset()) {
+ static_cast<InsetText *>(op->InInset())->paragraph(p);
+ } else {
+ if (inset_owner)
+ inset_owner->paragraph(p);
+ else
+ bv_owner->buffer()->paragraph = p;
+ }
+ return 0;
+}
+
+
+LyXText::text_status LyXText::status() const
+{
+ return status_;
+}
+
+
+void LyXText::status(BufferView * bview, LyXText::text_status st) const
+{
+ if ((status_ != NEED_MORE_REFRESH) ||
+ (status_ == NEED_MORE_REFRESH) && (st != NEED_VERY_LITTLE_REFRESH))
+ {
+ status_ = st;
+ if (inset_owner && st != UNCHANGED)
+ bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);
+ }
+}
#include "paragraph.h"
-Undo::Undo(undo_kind kind_arg,
+Undo::Undo(undo_kind kind_arg, int id_inset_arg,
int number_before_arg, int number_behind_arg,
int cursor_par_arg, int cursor_pos_arg,
Paragraph * par_arg)
{
kind = kind_arg;
+ number_of_inset_id = id_inset_arg;
number_of_before_par = number_before_arg;
number_of_behind_par = number_behind_arg;
number_of_cursor_par = cursor_par_arg;
///
int number_of_cursor_par;
///
+ int number_of_inset_id; // valid if >= 0, if < 0 then not in inset
+ ///
int cursor_pos; // valid if >= 0
///
Paragraph * par;
///
- Undo(undo_kind kind_arg,
+ Undo(undo_kind kind_arg, int id_inset_arg,
int number_before_arg, int number_behind_arg,
int cursor_par_arg, int cursor_pos_arg,
Paragraph * par_arg);
--- /dev/null
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright 1995-2001 The LyX Team.
+ *
+ * ====================================================== */
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "undo_funcs.h"
+#include "lyxtext.h"
+#include "BufferView.h"
+#include "buffer.h"
+#include "insets/inset.h"
+#include "debug.h"
+
+/// the flag used by FinishUndo();
+bool undo_finished;
+/// a flag
+bool undo_frozen;
+
+bool textUndo(BufferView * bv)
+{
+ // returns false if no undo possible
+ Undo * undo = bv->buffer()->undostack.pop();
+ if (undo) {
+ finishUndo();
+ if (!undo_frozen) {
+ Paragraph * first = bv->text->getParFromID(undo->number_of_before_par);
+ if (!first)
+ first = firstUndoParagraph(bv, undo->number_of_inset_id);
+ if (first) {
+ bv->buffer()->redostack.push(
+ createUndo(bv, undo->kind, first,
+ bv->text->getParFromID(undo->number_of_behind_par)));
+ }
+ }
+ }
+ return textHandleUndo(bv, undo);
+}
+
+
+bool textRedo(BufferView * bv)
+{
+ // returns false if no redo possible
+ Undo * undo = bv->buffer()->redostack.pop();
+ if (undo) {
+ finishUndo();
+ if (!undo_frozen) {
+ Paragraph * first = bv->text->getParFromID(undo->number_of_before_par);
+ if (!first)
+ first = firstUndoParagraph(bv, undo->number_of_inset_id);
+ if (first) {
+ bv->buffer()->undostack.push(
+ createUndo(bv, undo->kind, first,
+ bv->text->getParFromID(undo->number_of_behind_par)));
+ }
+ }
+ }
+ return textHandleUndo(bv, undo);
+}
+
+
+bool textHandleUndo(BufferView * bv, Undo * undo)
+{
+ // returns false if no undo possible
+ bool result = false;
+ if (undo) {
+ Paragraph * before =
+ bv->text->getParFromID(undo->number_of_before_par);
+ Paragraph * behind =
+ bv->text->getParFromID(undo->number_of_behind_par);
+ Paragraph * tmppar;
+ Paragraph * tmppar2;
+ Paragraph * endpar;
+ Paragraph * tmppar5;
+
+ // if there's no before take the beginning
+ // of the document for redoing
+ if (!before) {
+ LyXText * t = bv->text;
+ int num = undo->number_of_inset_id;
+ if (undo->number_of_inset_id >= 0) {
+ Inset * in = bv->buffer()->getInsetFromID(num);
+ if (in) {
+ t = in->getLyXText(bv);
+ } else {
+ num = -1;
+ }
+ }
+ t->setCursorIntern(bv, firstUndoParagraph(bv, num), 0);
+ }
+
+ // replace the paragraphs with the undo informations
+
+ Paragraph * tmppar3 = undo->par;
+ undo->par = 0; // otherwise the undo destructor would delete the paragraph
+ Paragraph * tmppar4 = tmppar3;
+
+ if (tmppar4) {
+ while (tmppar4->next())
+ tmppar4 = tmppar4->next();
+ } // get last undo par
+
+ // now remove the old text if there is any
+ if (before != behind || (!behind && !before)) {
+ if (before)
+ tmppar5 = before->next();
+ else
+ tmppar5 = firstUndoParagraph(bv, undo->number_of_inset_id);
+ tmppar2 = tmppar3;
+ while (tmppar5 && tmppar5 != behind) {
+ tmppar = tmppar5;
+ tmppar5 = tmppar5->next();
+ // a memory optimization for edit: Only layout information
+ // is stored in the undo. So restore the text informations.
+ if (undo->kind == Undo::EDIT) {
+ tmppar2->setContentsFromPar(tmppar);
+ tmppar->clearContents();
+ tmppar2 = tmppar2->next();
+ }
+ }
+ }
+
+ // put the new stuff in the list if there is one
+ if (tmppar3){
+ if (before)
+ before->next(tmppar3);
+ else
+ bv->text->ownerParagraph(tmppar3->id(), tmppar3);
+ tmppar3->previous(before);
+ } else {
+ // Do we really enter here ??? (Jug)
+ if (!before)
+ bv->text->ownerParagraph(behind);
+ }
+ if (tmppar4) {
+ tmppar4->next(behind);
+ if (behind)
+ behind->previous(tmppar4);
+ }
+
+
+ // Set the cursor for redoing
+ if (before) {
+ bv->text->setCursorIntern(bv, before, 0);
+ }
+
+ // calculate the endpar for redoing the paragraphs.
+ if (behind) {
+ endpar = behind->next();
+ } else
+ endpar = behind;
+
+ tmppar = bv->text->getParFromID(undo->number_of_cursor_par);
+ UpdatableInset* it = static_cast<UpdatableInset*>(tmppar3->InInset());
+ if (it) {
+ it->getLyXText(bv)->redoParagraphs(bv, it->getLyXText(bv)->cursor,
+ endpar);
+ if (tmppar){
+ it->getLyXText(bv)->setCursorIntern(bv, tmppar, undo->cursor_pos);
+ it->getLyXText(bv)->updateCounters(bv, it->getLyXText(bv)->cursor.row());
+ }
+#ifdef THIS_DOES_NOT_WORK
+ // we need this anyway as also if the undo was inside an inset
+ // we have to redo the paragraph breaking
+ bv->text->redoParagraphs(bv, bv->text->cursor,
+ bv->text->cursor.par());
+#endif
+ } else {
+ bv->text->redoParagraphs(bv, bv->text->cursor, endpar);
+ if (tmppar) {
+ bv->text->setCursorIntern(bv, tmppar, undo->cursor_pos);
+ bv->text->updateCounters(bv, bv->text->cursor.row());
+ }
+ }
+ result = true;
+ delete undo;
+ }
+ finishUndo();
+ bv->text->status(bv, LyXText::NEED_MORE_REFRESH);
+ return result;
+}
+
+
+void finishUndo()
+{
+ // makes sure the next operation will be stored
+ undo_finished = true;
+}
+
+
+void freezeUndo()
+{
+ // this is dangerous and for internal use only
+ undo_frozen = true;
+}
+
+
+void unFreezeUndo()
+{
+ // this is dangerous and for internal use only
+ undo_frozen = false;
+}
+
+
+void setUndo(BufferView * bv, Undo::undo_kind kind,
+ Paragraph const * first, Paragraph const * behind)
+{
+ if (!undo_frozen)
+ bv->buffer()->undostack.push(createUndo(bv, kind, first, behind));
+ bv->buffer()->redostack.clear();
+}
+
+
+void setRedo(BufferView * bv, Undo::undo_kind kind,
+ Paragraph const * first, Paragraph const * behind)
+{
+ bv->buffer()->redostack.push(createUndo(bv, kind, first, behind));
+}
+
+
+Undo * createUndo(BufferView * bv, Undo::undo_kind kind,
+ Paragraph const * first, Paragraph const * behind)
+{
+ lyx::Assert(first);
+
+ int before_number = -1;
+ int behind_number = -1;
+ int inset_id = -1;
+
+ if (first->previous())
+ before_number = first->previous()->id();
+ if (behind)
+ behind_number = behind->id();
+ if (first->InInset())
+ inset_id = first->InInset()->id();
+
+ // Undo::EDIT and Undo::FINISH are
+ // always finished. (no overlapping there)
+ // overlapping only with insert and delete inside one paragraph:
+ // Nobody wants all removed character
+ // appear one by one when undoing.
+ // EDIT is special since only layout information, not the
+ // contents of a paragaph are stored.
+ if (!undo_finished && (kind != Undo::EDIT) && (kind != Undo::FINISH)){
+ // check wether storing is needed
+ if (!bv->buffer()->undostack.empty() &&
+ bv->buffer()->undostack.top()->kind == kind &&
+ bv->buffer()->undostack.top()->number_of_before_par == before_number &&
+ bv->buffer()->undostack.top()->number_of_behind_par == behind_number ){
+ // no undo needed
+ return 0;
+ }
+ }
+ // create a new Undo
+ Paragraph * undopar;
+
+ Paragraph * start = const_cast<Paragraph *>(first);
+ Paragraph * end = 0;
+
+#if 0
+ if (first)
+ start = const_cast<Paragraph*>(before->next());
+ else
+ start = firstUndoParagraph(bv);
+#endif
+ if (behind)
+ end = const_cast<Paragraph*>(behind->previous());
+ else {
+ end = start;
+ while (end->next())
+ end = end->next();
+ }
+ if (start && end && (start != end->next()) &&
+ ((before_number != behind_number) ||
+ ((before_number < 0) && (behind_number < 0)))) {
+ Paragraph * tmppar = start;
+ Paragraph * tmppar2 = new Paragraph(*tmppar, true);
+ tmppar2->id(tmppar->id());
+
+ // a memory optimization: Just store the layout information
+ // when only edit
+ if (kind == Undo::EDIT) {
+ tmppar2->clearContents();
+ }
+
+ undopar = tmppar2;
+
+ while (tmppar != end && tmppar->next()) {
+ tmppar = tmppar->next();
+ tmppar2->next(new Paragraph(*tmppar));
+ tmppar2->next()->id(tmppar->id());
+ // a memory optimization: Just store the layout
+ // information when only edit
+ if (kind == Undo::EDIT) {
+ tmppar2->clearContents();
+ }
+ tmppar2->next()->previous(tmppar2);
+ tmppar2 = tmppar2->next();
+ }
+ tmppar2->next(0);
+ } else
+ undopar = 0; // nothing to replace (undo of delete maybe)
+
+ int cursor_par = undoCursor(bv).par()->id();
+ int cursor_pos = undoCursor(bv).pos();
+
+ Undo * undo = new Undo(kind, inset_id,
+ before_number, behind_number,
+ cursor_par, cursor_pos, undopar);
+
+ undo_finished = false;
+ return undo;
+}
+
+
+void setCursorParUndo(BufferView * bv)
+{
+ setUndo(bv, Undo::FINISH,
+ bv->text->cursor.par(),
+ bv->text->cursor.par()->next());
+}
+
+Paragraph * firstUndoParagraph(BufferView * bv, int inset_id)
+{
+ Inset * inset = bv->buffer()->getInsetFromID(inset_id);
+ if (inset) {
+ Paragraph * result = inset->firstParagraph();
+ if (result)
+ return result;
+ }
+ return bv->text->ownerParagraph();
+}
+
+LyXCursor const & undoCursor(BufferView * bv)
+{
+ if (bv->theLockingInset())
+ return bv->theLockingInset()->cursor(bv);
+ return bv->text->cursor;
+}
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright 1995-2001 The LyX Team.
+ *
+ * ====================================================== */
+
+#ifndef UNDO_FUNCS_H
+#define UNDO_FUNCS_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "undo.h"
+
+class BufferView;
+class Paragraph;
+class LyXCursor;
+
+/// returns false if no undo possible
+extern bool textUndo(BufferView *);
+/// returns false if no redo possible
+extern bool textRedo(BufferView *);
+/// used by TextUndo/TextRedo
+extern bool textHandleUndo(BufferView *, Undo * undo);
+/// makes sure the next operation will be stored
+extern void finishUndo();
+/// this is dangerous and for internal use only
+extern void freezeUndo();
+/// this is dangerous and for internal use only
+extern void unFreezeUndo();
+///
+extern void setUndo(BufferView *, Undo::undo_kind kind,
+ Paragraph const * first, Paragraph const * behind);
+///
+extern void setRedo(BufferView *, Undo::undo_kind kind,
+ Paragraph const * first, Paragraph const * behind);
+///
+extern Undo * createUndo(BufferView *, Undo::undo_kind kind,
+ Paragraph const * first, Paragraph const * behind);
+/// for external use in lyx_cb.C
+extern void setCursorParUndo(BufferView *);
+
+// returns a pointer to the very first Paragraph depending of where we are
+// so it will return the first paragraph of the buffer or the first paragraph
+// of the textinset we're in.
+extern Paragraph * firstUndoParagraph(BufferView *, int inset_arg);
+
+///
+extern LyXCursor const & undoCursor(BufferView * bv);
+
+/// the flag used by FinishUndo();
+extern bool undo_finished;
+/// a flag
+extern bool undo_frozen;
+
+#endif